blob: be830b141d83cedde7751b1e8441c357d2c48cbb [file] [log] [blame]
Wolfram Sang64eac232012-02-24 07:41:06 +01001/*
2 * at24.h - platform_data for the at24 (generic eeprom) driver
3 * (C) Copyright 2008 by Pengutronix
4 * (C) Copyright 2012 by Wolfram Sang
5 * same license as the driver
6 */
7
Wolfram Sang2b7a5052008-07-14 22:38:35 +02008#ifndef _LINUX_AT24_H
9#define _LINUX_AT24_H
10
11#include <linux/types.h>
Andrew Lunnbec3c112016-02-26 20:59:24 +010012#include <linux/nvmem-consumer.h>
Wolfram Sang2b7a5052008-07-14 22:38:35 +020013
Wolfram Sang64eac232012-02-24 07:41:06 +010014/**
15 * struct at24_platform_data - data to set up at24 (generic eeprom) driver
16 * @byte_len: size of eeprom in byte
17 * @page_size: number of byte which can be written in one go
18 * @flags: tunable options, check AT24_FLAG_* defines
19 * @setup: an optional callback invoked after eeprom is probed; enables kernel
Andrew Lunnbec3c112016-02-26 20:59:24 +010020 code to access eeprom via nvmem, see example
Wolfram Sang64eac232012-02-24 07:41:06 +010021 * @context: optional parameter passed to setup()
Wolfram Sang2b7a5052008-07-14 22:38:35 +020022 *
23 * If you set up a custom eeprom type, please double-check the parameters.
24 * Especially page_size needs extra care, as you risk data loss if your value
25 * is bigger than what the chip actually supports!
Wolfram Sang64eac232012-02-24 07:41:06 +010026 *
27 * An example in pseudo code for a setup() callback:
28 *
Moritz Fischer868b2072016-05-23 11:44:39 -070029 * void get_mac_addr(struct nvmem_device *nvmem, void *context)
Wolfram Sang64eac232012-02-24 07:41:06 +010030 * {
Vivien Didelot25f73ed2013-09-27 15:06:28 -040031 * u8 *mac_addr = ethernet_pdata->mac_addr;
Wolfram Sang64eac232012-02-24 07:41:06 +010032 * off_t offset = context;
33 *
34 * // Read MAC addr from EEPROM
Andrew Lunnbec3c112016-02-26 20:59:24 +010035 * if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN)
Wolfram Sang64eac232012-02-24 07:41:06 +010036 * pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
37 * }
38 *
39 * This function pointer and context can now be set up in at24_platform_data.
Wolfram Sang2b7a5052008-07-14 22:38:35 +020040 */
41
42struct at24_platform_data {
43 u32 byte_len; /* size (sum of all addr) */
44 u16 page_size; /* for writes */
45 u8 flags;
46#define AT24_FLAG_ADDR16 0x80 /* address pointer is 16 bit */
47#define AT24_FLAG_READONLY 0x40 /* sysfs-entry will be read-only */
48#define AT24_FLAG_IRUGO 0x20 /* sysfs-entry will be world-readable */
49#define AT24_FLAG_TAKE8ADDR 0x10 /* take always 8 addresses (24c00) */
Kevin Hilman7274ec82009-04-02 16:56:57 -070050
Andrew Lunnbec3c112016-02-26 20:59:24 +010051 void (*setup)(struct nvmem_device *nvmem, void *context);
Kevin Hilman7274ec82009-04-02 16:56:57 -070052 void *context;
Wolfram Sang2b7a5052008-07-14 22:38:35 +020053};
54
55#endif /* _LINUX_AT24_H */