Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 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 | |
Wolfram Sang | 2b7a505 | 2008-07-14 22:38:35 +0200 | [diff] [blame] | 8 | #ifndef _LINUX_AT24_H |
| 9 | #define _LINUX_AT24_H |
| 10 | |
| 11 | #include <linux/types.h> |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 12 | #include <linux/nvmem-consumer.h> |
Bartosz Golaszewski | a7284a8 | 2016-06-06 10:48:50 +0200 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Wolfram Sang | 2b7a505 | 2008-07-14 22:38:35 +0200 | [diff] [blame] | 14 | |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 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 |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 21 | code to access eeprom via nvmem, see example |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 22 | * @context: optional parameter passed to setup() |
Wolfram Sang | 2b7a505 | 2008-07-14 22:38:35 +0200 | [diff] [blame] | 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! |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 27 | * |
| 28 | * An example in pseudo code for a setup() callback: |
| 29 | * |
Moritz Fischer | 868b207 | 2016-05-23 11:44:39 -0700 | [diff] [blame] | 30 | * void get_mac_addr(struct nvmem_device *nvmem, void *context) |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 31 | * { |
Vivien Didelot | 25f73ed | 2013-09-27 15:06:28 -0400 | [diff] [blame] | 32 | * u8 *mac_addr = ethernet_pdata->mac_addr; |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 33 | * off_t offset = context; |
| 34 | * |
| 35 | * // Read MAC addr from EEPROM |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 36 | * if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN) |
Wolfram Sang | 64eac23 | 2012-02-24 07:41:06 +0100 | [diff] [blame] | 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. |
Wolfram Sang | 2b7a505 | 2008-07-14 22:38:35 +0200 | [diff] [blame] | 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; |
Bartosz Golaszewski | a7284a8 | 2016-06-06 10:48:50 +0200 | [diff] [blame] | 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) */ |
Bartosz Golaszewski | 818d022 | 2016-06-06 10:48:51 +0200 | [diff] [blame] | 51 | #define AT24_FLAG_SERIAL BIT(3) /* factory-programmed serial number */ |
Bartosz Golaszewski | 0b81365 | 2016-06-06 10:48:54 +0200 | [diff] [blame] | 52 | #define AT24_FLAG_MAC BIT(2) /* factory-programmed mac address */ |
Kevin Hilman | 7274ec8 | 2009-04-02 16:56:57 -0700 | [diff] [blame] | 53 | |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 54 | void (*setup)(struct nvmem_device *nvmem, void *context); |
Kevin Hilman | 7274ec8 | 2009-04-02 16:56:57 -0700 | [diff] [blame] | 55 | void *context; |
Wolfram Sang | 2b7a505 | 2008-07-14 22:38:35 +0200 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #endif /* _LINUX_AT24_H */ |