diff options
-rw-r--r-- | Documentation/powerpc/dts-bindings/eeprom.txt | 28 | ||||
-rw-r--r-- | drivers/misc/eeprom/at24.c | 33 |
2 files changed, 55 insertions, 6 deletions
diff --git a/Documentation/powerpc/dts-bindings/eeprom.txt b/Documentation/powerpc/dts-bindings/eeprom.txt new file mode 100644 index 000000000000..4342c10de1bf --- /dev/null +++ b/Documentation/powerpc/dts-bindings/eeprom.txt | |||
@@ -0,0 +1,28 @@ | |||
1 | EEPROMs (I2C) | ||
2 | |||
3 | Required properties: | ||
4 | |||
5 | - compatible : should be "<manufacturer>,<type>" | ||
6 | If there is no specific driver for <manufacturer>, a generic | ||
7 | driver based on <type> is selected. Possible types are: | ||
8 | 24c00, 24c01, 24c02, 24c04, 24c08, 24c16, 24c32, 24c64, | ||
9 | 24c128, 24c256, 24c512, 24c1024, spd | ||
10 | |||
11 | - reg : the I2C address of the EEPROM | ||
12 | |||
13 | Optional properties: | ||
14 | |||
15 | - pagesize : the length of the pagesize for writing. Please consult the | ||
16 | manual of your device, that value varies a lot. A wrong value | ||
17 | may result in data loss! If not specified, a safety value of | ||
18 | '1' is used which will be very slow. | ||
19 | |||
20 | - read-only: this parameterless property disables writes to the eeprom | ||
21 | |||
22 | Example: | ||
23 | |||
24 | eeprom@52 { | ||
25 | compatible = "atmel,24c32"; | ||
26 | reg = <0x52>; | ||
27 | pagesize = <32>; | ||
28 | }; | ||
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 559b0b3c16c3..3a53efc28821 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/log2.h> | 20 | #include <linux/log2.h> |
21 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
22 | #include <linux/jiffies.h> | 22 | #include <linux/jiffies.h> |
23 | #include <linux/of.h> | ||
23 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
24 | #include <linux/i2c/at24.h> | 25 | #include <linux/i2c/at24.h> |
25 | 26 | ||
@@ -457,6 +458,27 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf, | |||
457 | 458 | ||
458 | /*-------------------------------------------------------------------------*/ | 459 | /*-------------------------------------------------------------------------*/ |
459 | 460 | ||
461 | #ifdef CONFIG_OF | ||
462 | static void at24_get_ofdata(struct i2c_client *client, | ||
463 | struct at24_platform_data *chip) | ||
464 | { | ||
465 | const __be32 *val; | ||
466 | struct device_node *node = client->dev.of_node; | ||
467 | |||
468 | if (node) { | ||
469 | if (of_get_property(node, "read-only", NULL)) | ||
470 | chip->flags |= AT24_FLAG_READONLY; | ||
471 | val = of_get_property(node, "pagesize", NULL); | ||
472 | if (val) | ||
473 | chip->page_size = be32_to_cpup(val); | ||
474 | } | ||
475 | } | ||
476 | #else | ||
477 | static void at24_get_ofdata(struct i2c_client *client, | ||
478 | struct at24_platform_data *chip) | ||
479 | { } | ||
480 | #endif /* CONFIG_OF */ | ||
481 | |||
460 | static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | 482 | static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) |
461 | { | 483 | { |
462 | struct at24_platform_data chip; | 484 | struct at24_platform_data chip; |
@@ -485,6 +507,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
485 | */ | 507 | */ |
486 | chip.page_size = 1; | 508 | chip.page_size = 1; |
487 | 509 | ||
510 | /* update chipdata if OF is present */ | ||
511 | at24_get_ofdata(client, &chip); | ||
512 | |||
488 | chip.setup = NULL; | 513 | chip.setup = NULL; |
489 | chip.context = NULL; | 514 | chip.context = NULL; |
490 | } | 515 | } |
@@ -597,19 +622,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
597 | 622 | ||
598 | i2c_set_clientdata(client, at24); | 623 | i2c_set_clientdata(client, at24); |
599 | 624 | ||
600 | dev_info(&client->dev, "%zu byte %s EEPROM %s\n", | 625 | dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n", |
601 | at24->bin.size, client->name, | 626 | at24->bin.size, client->name, |
602 | writable ? "(writable)" : "(read-only)"); | 627 | writable ? "writable" : "read-only", at24->write_max); |
603 | if (use_smbus == I2C_SMBUS_WORD_DATA || | 628 | if (use_smbus == I2C_SMBUS_WORD_DATA || |
604 | use_smbus == I2C_SMBUS_BYTE_DATA) { | 629 | use_smbus == I2C_SMBUS_BYTE_DATA) { |
605 | dev_notice(&client->dev, "Falling back to %s reads, " | 630 | dev_notice(&client->dev, "Falling back to %s reads, " |
606 | "performance will suffer\n", use_smbus == | 631 | "performance will suffer\n", use_smbus == |
607 | I2C_SMBUS_WORD_DATA ? "word" : "byte"); | 632 | I2C_SMBUS_WORD_DATA ? "word" : "byte"); |
608 | } | 633 | } |
609 | dev_dbg(&client->dev, | ||
610 | "page_size %d, num_addresses %d, write_max %d, use_smbus %d\n", | ||
611 | chip.page_size, num_addresses, | ||
612 | at24->write_max, use_smbus); | ||
613 | 634 | ||
614 | /* export data to kernel code */ | 635 | /* export data to kernel code */ |
615 | if (chip.setup) | 636 | if (chip.setup) |