New-style I2C and SMBus EEPROM driver (with device_ids)
PATCH 1/1 New-style I2C and SMBus EEPROM driver (with device_ids)
In reply to a message not in the archiveAdd a new-style driver for most I2C EEPROMs, giving sysfs read/write access to their data. Tested with various chips and clock rates.
---
Note: I am not in my office this week, so I can't do all the tests I usually do. Please check carefully! David: I hope it is OK with you that I added myself as another author of this module.
Updates since last version:
- added device_ids for common eeprom types (parameters encoded in a 'magic' driver_data value)
- removed platform_data entry 'i2c_addr_mask' and calculated its value from other parameters
- added 24c00-quirk flag (it covers 8 addresses)
- added a flag to make eeproms world-readable (used for spd)
- rewrote code that adds an i2c-address to an i2c-message
- rewrote code which truncates to page_size
- removed 'addr'-variable from eeprom-functions; i2c-address is now taken from the corresponding client-structure
- write buffer now allocated once in probe
- removed some sanity checks for file offsets as they are handled at the sysfs-layer already.
- fixed typos and corrected spellings in comments and Kconfig
- renamed some functions to be more self-explanatory
- added includes
- further cleanups and simplifications
- added myself as another author
Updates since last version:
- revisited includes
- made write-timeout a module parameter
- array of clients is allocated dynamically
- removed unnecessary indentation within code
- formatted comments
- replaced at24_ee_address with a simpler function
- at24_ee_write now really waits till timeout
- added simple checks of provided eeprom chip data in at24_probe
- added comment in at24.h about double-checking custom data
- minor fixes
Updates in this version:
- move chip data out of the driver into a seperate .h-file
- prefix defined constants with AT24_
- make bin file readonly if requested by flags
- introduce AT24_MAX_CLIENTS
- bugfix: check correct retval in at24_ee_write
drivers/i2c/chips/Kconfig | 26 ++ drivers/i2c/chips/Makefile | 1 drivers/i2c/chips/at24.c | 574 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/at24.h | 104 ++++++++ 4 files changed, 705 insertions(+) create mode 100644 drivers/i2c/chips/at24.c create mode 100644 include/linux/i2c/at24.h
drivers/i2c/chips/Kconfig +26 -0
@@ -14,6 +14,32 @@ This driver can also be built as a module. If so, the module will be called ds1682. +config I2C_AT24 + tristate "EEPROMs from most vendors" + depends on SYSFS && EXPERIMENTAL + help + Enable this driver to get read/write support to most I2C EEPROMs, + after you configure the driver to know about each EEPROM on + your target board. Use these generic chip names, instead of + vendor-specific ones like at24c64 or 24lc02: + + 24c00, 24c01, 24c02, spd (readonly 24c02), 24c04, 24c08, + 24c16, 24c32, 24c64, 24c128, 24c256, 24c512, 24c1024 + + Unless you like data loss puzzles, always be sure that any chip + you configure as a 24c32 (32 kbit) or larger is NOT really a + 24c16 (16 kbit) or smaller, and vice versa. Marking the chip + as read-only won't help recover from this. Also, if your chip + has any software write-protect mechanism you may want to review the + code to make sure this driver won't turn it on by accident. + + If you use this with an SMBus adapter instead of an I2C adapter, + full functionality is not availble. Only smaller devices are + supported (24c16 and below, max 4 kByte). + + This driver can also be built as a module. If so, the module + will be called at24. + config SENSORS_EEPROM tristate "EEPROM reader" depends on EXPERIMENTAL
drivers/i2c/chips/Makefile +1 -0
@@ -10,6 +10,7 @@ # obj-$(CONFIG_DS1682) += ds1682.o +obj-$(CONFIG_I2C_AT24) += at24.o obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o obj-$(CONFIG_SENSORS_MAX6875) += max6875.o obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
drivers/i2c/chips/at24.c new file +574 -0
574 lines not on this page · raw message
include/linux/i2c/at24.h new file +104 -0
104 lines not on this page · raw message
Signature · 7 lines
Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de Pengutronix - Linux Solutions for Science and Industry _______________________________________________ i2c mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/i2c