Skip to contentSkip to conversation

Documentation: EEPROM: add kernel side usage description

PATCH In review Yegor Yefremov 2 participants 2 messages Jan 25, 2012 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: EEPROM: add kernel side usage description

add EEPROM usage instructions and example for kernel side. dm644x-evm was taken as example.

---
 Documentation/misc-devices/eeprom |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/misc-devices/eeprom +34 -0
Index: b/Documentation/misc-devices/eeprom
===================================================================
@@ -90,7 +90,41 @@
 
 Use:
 
+1. Userland
+
 After inserting the module (and any other required SMBus/i2c modules), you
 should have some EEPROM directories in /sys/bus/i2c/devices/* of names such
 as "0-0050". Inside each of these is a series of files, the eeprom file
 contains the binary data from EEPROM.
+
+2. Kernel
+
+It is also possible to read/write EEPROM from kernel side. at24.c provides two
+routines at24_macc_read() and at24_macc_write(). Those routines can be used
+as part of setup() routine, when configuring platform data for i2c EEPROM.
+
+Example:
+
+arch/arm/mach-davinci/board-dm644x-evm.c uses EEPROM to store MAC address.
+This is how EEPROM platform data will be set up:
+
+static struct at24_platform_data eeprom_info = {
+	.byte_len	= (256*1024) / 8,
+	.page_size	= 64,
+	.flags		= AT24_FLAG_ADDR16,
+	.setup          = davinci_get_mac_addr,
+	.context	= (void *)0x7f00,
+};
+
+davinci_get_mac_addr() will be called from at24_probe() and fetches the MAC
+address from specified offset:
+
+void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
+{
+	char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
+	off_t offset = (off_t)context;
+
+	/* Read MAC addr from EEPROM */
+	if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
+		pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
+}

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 4 lines · Yegor Yefremov

add EEPROM usage instructions and example for kernel side. dm644x-evm was taken as example.

Good idea, only this file describes eeprom.c not at24.c. eeprom.c is deprecated. I'd suggest to add the usage example for macc to the at24 source code, after the comment I pointed you to.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |