aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Daney <david.daney@cavium.com>2012-08-22 15:03:57 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-05 17:10:29 -0400
commitd6ae0d578d24303941c1424b049d2cae28277666 (patch)
tree408e4d6d19acc44353761517731c5ce486e4882e
parent9af514232e9e74cbcd24700fc321b7c71a536568 (diff)
misc/at25, dt: Improve at25 SPI eeprom device tree bindings.
Commit 002176db (misc: at25: Parse dt settings) added device tree bindings the differ significantly in style from the I2C EEPROM bindings and don't seem well vetted. Here I deprecate (but still support) the "at25,*" properties, and add what I hope is a better alternative. These new bindings also happen to be deployed in the field and were previously submitted for consideration here: https://lists.ozlabs.org/pipermail/devicetree-discuss/2012-May/015556.html The advantages of the new bindings are that they are similar to the I2C EEPROMs and they don't conflate read-only and the address width modes in a binary encoded blob. Signed-off-by: David Daney <david.daney@cavium.com> Cc: Alexandre Pereira da Silva <aletes.xgr@gmail.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Michael Hennerich <michael.hennerich@analog.com> Cc: Axel Lin <axel.lin@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/devicetree/bindings/misc/at25.txt34
-rw-r--r--drivers/misc/eeprom/at25.c83
2 files changed, 82 insertions, 35 deletions
diff --git a/Documentation/devicetree/bindings/misc/at25.txt b/Documentation/devicetree/bindings/misc/at25.txt
index ab3c327929d..1d3447165c3 100644
--- a/Documentation/devicetree/bindings/misc/at25.txt
+++ b/Documentation/devicetree/bindings/misc/at25.txt
@@ -1,21 +1,35 @@
1Atmel AT25 eeprom 1EEPROMs (SPI) compatible with Atmel at25.
2 2
3Required properties: 3Required properties:
4- compatible : "atmel,at25". 4- compatible : "atmel,at25".
5- reg : chip select number 5- reg : chip select number
6- spi-max-frequency : max spi frequency to use 6- spi-max-frequency : max spi frequency to use
7- pagesize : size of the eeprom page
8- size : total eeprom size in bytes
9- address-width : number of address bits (one of 8, 16, or 24)
7 10
11Optional properties:
12- spi-cpha : SPI shifted clock phase, as per spi-bus bindings.
13- spi-cpol : SPI inverse clock polarity, as per spi-bus bindings.
14- read-only : this parameter-less property disables writes to the eeprom
15
16Obsolete legacy properties are can be used in place of "size", "pagesize",
17"address-width", and "read-only":
8- at25,byte-len : total eeprom size in bytes 18- at25,byte-len : total eeprom size in bytes
9- at25,addr-mode : addr-mode flags, as defined in include/linux/spi/eeprom.h 19- at25,addr-mode : addr-mode flags, as defined in include/linux/spi/eeprom.h
10- at25,page-size : size of the eeprom page 20- at25,page-size : size of the eeprom page
11 21
12Examples: 22Additional compatible properties are also allowed.
13at25@0 { 23
14 compatible = "atmel,at25"; 24Example:
15 reg = <0> 25 at25@0 {
16 spi-max-frequency = <5000000>; 26 compatible = "atmel,at25", "st,m95256";
27 reg = <0>
28 spi-max-frequency = <5000000>;
29 spi-cpha;
30 spi-cpol;
17 31
18 at25,byte-len = <0x8000>; 32 pagesize = <64>;
19 at25,addr-mode = <2>; 33 size = <32768>;
20 at25,page-size = <64>; 34 address-width = <16>;
21}; 35 };
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 25003d6ceb5..4ed93dd5411 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -302,6 +302,61 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
302 302
303/*-------------------------------------------------------------------------*/ 303/*-------------------------------------------------------------------------*/
304 304
305static int at25_np_to_chip(struct device *dev,
306 struct device_node *np,
307 struct spi_eeprom *chip)
308{
309 u32 val;
310
311 memset(chip, 0, sizeof(*chip));
312 strncpy(chip->name, np->name, sizeof(chip->name));
313
314 if (of_property_read_u32(np, "size", &val) == 0 ||
315 of_property_read_u32(np, "at25,byte-len", &val) == 0) {
316 chip->byte_len = val;
317 } else {
318 dev_err(dev, "Error: missing \"size\" property\n");
319 return -ENODEV;
320 }
321
322 if (of_property_read_u32(np, "pagesize", &val) == 0 ||
323 of_property_read_u32(np, "at25,page-size", &val) == 0) {
324 chip->page_size = (u16)val;
325 } else {
326 dev_err(dev, "Error: missing \"pagesize\" property\n");
327 return -ENODEV;
328 }
329
330 if (of_property_read_u32(np, "at25,addr-mode", &val) == 0) {
331 chip->flags = (u16)val;
332 } else {
333 if (of_property_read_u32(np, "address-width", &val)) {
334 dev_err(dev,
335 "Error: missing \"address-width\" property\n");
336 return -ENODEV;
337 }
338 switch (val) {
339 case 8:
340 chip->flags |= EE_ADDR1;
341 break;
342 case 16:
343 chip->flags |= EE_ADDR2;
344 break;
345 case 24:
346 chip->flags |= EE_ADDR3;
347 break;
348 default:
349 dev_err(dev,
350 "Error: bad \"address-width\" property: %u\n",
351 val);
352 return -ENODEV;
353 }
354 if (of_find_property(np, "read-only", NULL))
355 chip->flags |= EE_READONLY;
356 }
357 return 0;
358}
359
305static int at25_probe(struct spi_device *spi) 360static int at25_probe(struct spi_device *spi)
306{ 361{
307 struct at25_data *at25 = NULL; 362 struct at25_data *at25 = NULL;
@@ -314,33 +369,11 @@ static int at25_probe(struct spi_device *spi)
314 /* Chip description */ 369 /* Chip description */
315 if (!spi->dev.platform_data) { 370 if (!spi->dev.platform_data) {
316 if (np) { 371 if (np) {
317 u32 val; 372 err = at25_np_to_chip(&spi->dev, np, &chip);
318 373 if (err)
319 memset(&chip, 0, sizeof(chip));
320 strncpy(chip.name, np->name, 10);
321
322 err = of_property_read_u32(np, "at25,byte-len", &val);
323 if (err) {
324 dev_dbg(&spi->dev, "invalid chip dt description\n");
325 goto fail;
326 }
327 chip.byte_len = val;
328
329 err = of_property_read_u32(np, "at25,addr-mode", &val);
330 if (err) {
331 dev_dbg(&spi->dev, "invalid chip dt description\n");
332 goto fail;
333 }
334 chip.flags = (u16)val;
335
336 err = of_property_read_u32(np, "at25,page-size", &val);
337 if (err) {
338 dev_dbg(&spi->dev, "invalid chip dt description\n");
339 goto fail; 374 goto fail;
340 }
341 chip.page_size = (u16)val;
342 } else { 375 } else {
343 dev_dbg(&spi->dev, "no chip description\n"); 376 dev_err(&spi->dev, "Error: no chip description\n");
344 err = -ENODEV; 377 err = -ENODEV;
345 goto fail; 378 goto fail;
346 } 379 }