eeprom: at24: platform_data: use BIT() macro
[cascardo/linux.git] / include / linux / platform_data / at24.h
1 /*
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
8 #ifndef _LINUX_AT24_H
9 #define _LINUX_AT24_H
10
11 #include <linux/types.h>
12 #include <linux/nvmem-consumer.h>
13 #include <linux/bitops.h>
14
15 /**
16  * struct at24_platform_data - data to set up at24 (generic eeprom) driver
17  * @byte_len: size of eeprom in byte
18  * @page_size: number of byte which can be written in one go
19  * @flags: tunable options, check AT24_FLAG_* defines
20  * @setup: an optional callback invoked after eeprom is probed; enables kernel
21         code to access eeprom via nvmem, see example
22  * @context: optional parameter passed to setup()
23  *
24  * If you set up a custom eeprom type, please double-check the parameters.
25  * Especially page_size needs extra care, as you risk data loss if your value
26  * is bigger than what the chip actually supports!
27  *
28  * An example in pseudo code for a setup() callback:
29  *
30  * void get_mac_addr(struct nvmem_device *nvmem, void *context)
31  * {
32  *      u8 *mac_addr = ethernet_pdata->mac_addr;
33  *      off_t offset = context;
34  *
35  *      // Read MAC addr from EEPROM
36  *      if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN)
37  *              pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
38  * }
39  *
40  * This function pointer and context can now be set up in at24_platform_data.
41  */
42
43 struct at24_platform_data {
44         u32             byte_len;               /* size (sum of all addr) */
45         u16             page_size;              /* for writes */
46         u8              flags;
47 #define AT24_FLAG_ADDR16        BIT(7)  /* address pointer is 16 bit */
48 #define AT24_FLAG_READONLY      BIT(6)  /* sysfs-entry will be read-only */
49 #define AT24_FLAG_IRUGO         BIT(5)  /* sysfs-entry will be world-readable */
50 #define AT24_FLAG_TAKE8ADDR     BIT(4)  /* take always 8 addresses (24c00) */
51
52         void            (*setup)(struct nvmem_device *nvmem, void *context);
53         void            *context;
54 };
55
56 #endif /* _LINUX_AT24_H */