Commit 9ed030d728f3bd03b6e869357da02725afda19a7
Committed by
Grant Likely
1 parent
1945886047
Exists in
master
and in
7 other branches
misc/at24: parse device tree data
Information about the pagesize and read-only-status may also come from the devicetree. Parse this data, too, and act accordingly. While we are here, change the initialization printout a bit. write_max is useful to know to detect performance bottlenecks, the rest is superfluous. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Showing 2 changed files with 55 additions and 6 deletions Side-by-side Diff
Documentation/powerpc/dts-bindings/eeprom.txt
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 | +}; |
drivers/misc/eeprom/at24.c
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | #include <linux/log2.h> |
21 | 21 | #include <linux/bitops.h> |
22 | 22 | #include <linux/jiffies.h> |
23 | +#include <linux/of.h> | |
23 | 24 | #include <linux/i2c.h> |
24 | 25 | #include <linux/i2c/at24.h> |
25 | 26 | |
... | ... | @@ -457,6 +458,27 @@ |
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 | 482 | static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) |
461 | 483 | { |
462 | 484 | struct at24_platform_data chip; |
... | ... | @@ -485,6 +507,9 @@ |
485 | 507 | */ |
486 | 508 | chip.page_size = 1; |
487 | 509 | |
510 | + /* update chipdata if OF is present */ | |
511 | + at24_get_ofdata(client, &chip); | |
512 | + | |
488 | 513 | chip.setup = NULL; |
489 | 514 | chip.context = NULL; |
490 | 515 | } |
491 | 516 | |
492 | 517 | |
... | ... | @@ -597,19 +622,15 @@ |
597 | 622 | |
598 | 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 | 626 | at24->bin.size, client->name, |
602 | - writable ? "(writable)" : "(read-only)"); | |
627 | + writable ? "writable" : "read-only", at24->write_max); | |
603 | 628 | if (use_smbus == I2C_SMBUS_WORD_DATA || |
604 | 629 | use_smbus == I2C_SMBUS_BYTE_DATA) { |
605 | 630 | dev_notice(&client->dev, "Falling back to %s reads, " |
606 | 631 | "performance will suffer\n", use_smbus == |
607 | 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 | 635 | /* export data to kernel code */ |
615 | 636 | if (chip.setup) |