Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

eeprom: at24: add support for at24mac series

Add a new read function to the at24 driver allowing to retrieve the
factory-programmed mac address embedded in chips from the at24mac
family.

These chips can be instantiated similarily to the at24cs family,
except that there's no way of having access to both the serial number
and the mac address at the same time - the user must instantiate
either an at24cs or at24mac device as both special memory areas are
accessible on the same slave address.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Bartosz Golaszewski and committed by
Wolfram Sang
0b813658 818d0220

+43
+42
drivers/misc/eeprom/at24.c
··· 139 139 { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) }, 140 140 { "24cs02", AT24_DEVICE_MAGIC(16, 141 141 AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 142 + { "24mac402", AT24_DEVICE_MAGIC(48 / 8, 143 + AT24_FLAG_MAC | AT24_FLAG_READONLY) }, 144 + { "24mac602", AT24_DEVICE_MAGIC(64 / 8, 145 + AT24_FLAG_MAC | AT24_FLAG_READONLY) }, 142 146 /* spd is a 24c02 in memory DIMMs */ 143 147 { "spd", AT24_DEVICE_MAGIC(2048 / 8, 144 148 AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, ··· 337 333 msg[0].len = 1; 338 334 } 339 335 336 + msg[1].addr = client->addr; 337 + msg[1].flags = I2C_M_RD; 338 + msg[1].buf = buf; 339 + msg[1].len = count; 340 + 341 + loop_until_timeout(timeout, read_time) { 342 + status = i2c_transfer(client->adapter, msg, 2); 343 + if (status == 2) 344 + return count; 345 + } 346 + 347 + return -ETIMEDOUT; 348 + } 349 + 350 + static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, 351 + unsigned int offset, size_t count) 352 + { 353 + unsigned long timeout, read_time; 354 + struct i2c_client *client; 355 + struct i2c_msg msg[2]; 356 + u8 addrbuf[2]; 357 + int status; 358 + 359 + client = at24_translate_offset(at24, &offset); 360 + 361 + memset(msg, 0, sizeof(msg)); 362 + msg[0].addr = client->addr; 363 + msg[0].buf = addrbuf; 364 + addrbuf[0] = 0x90 + offset; 365 + msg[0].len = 1; 340 366 msg[1].addr = client->addr; 341 367 msg[1].flags = I2C_M_RD; 342 368 msg[1].buf = buf; ··· 682 648 at24->chip = chip; 683 649 at24->num_addresses = num_addresses; 684 650 651 + if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { 652 + dev_err(&client->dev, 653 + "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); 654 + return -EINVAL; 655 + } 656 + 685 657 if (chip.flags & AT24_FLAG_SERIAL) { 686 658 at24->read_func = at24_eeprom_read_serial; 659 + } else if (chip.flags & AT24_FLAG_MAC) { 660 + at24->read_func = at24_eeprom_read_mac; 687 661 } else { 688 662 at24->read_func = at24->use_smbus ? at24_eeprom_read_smbus 689 663 : at24_eeprom_read_i2c;
+1
include/linux/platform_data/at24.h
··· 49 49 #define AT24_FLAG_IRUGO BIT(5) /* sysfs-entry will be world-readable */ 50 50 #define AT24_FLAG_TAKE8ADDR BIT(4) /* take always 8 addresses (24c00) */ 51 51 #define AT24_FLAG_SERIAL BIT(3) /* factory-programmed serial number */ 52 + #define AT24_FLAG_MAC BIT(2) /* factory-programmed mac address */ 52 53 53 54 void (*setup)(struct nvmem_device *nvmem, void *context); 54 55 void *context;