Commit d6ae0d578d24303941c1424b049d2cae28277666
Committed by
Greg Kroah-Hartman
1 parent
9af514232e
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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>
Showing 2 changed files with 82 additions and 35 deletions Side-by-side Diff
Documentation/devicetree/bindings/misc/at25.txt
1 | -Atmel AT25 eeprom | |
1 | +EEPROMs (SPI) compatible with Atmel at25. | |
2 | 2 | |
3 | 3 | Required properties: |
4 | 4 | - compatible : "atmel,at25". |
5 | 5 | - reg : chip select number |
6 | 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 | |
11 | +Optional 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 | + | |
16 | +Obsolete legacy properties are can be used in place of "size", "pagesize", | |
17 | +"address-width", and "read-only": | |
8 | 18 | - at25,byte-len : total eeprom size in bytes |
9 | 19 | - at25,addr-mode : addr-mode flags, as defined in include/linux/spi/eeprom.h |
10 | 20 | - at25,page-size : size of the eeprom page |
11 | 21 | |
12 | -Examples: | |
13 | -at25@0 { | |
14 | - compatible = "atmel,at25"; | |
15 | - reg = <0> | |
16 | - spi-max-frequency = <5000000>; | |
22 | +Additional compatible properties are also allowed. | |
17 | 23 | |
18 | - at25,byte-len = <0x8000>; | |
19 | - at25,addr-mode = <2>; | |
20 | - at25,page-size = <64>; | |
21 | -}; | |
24 | +Example: | |
25 | + at25@0 { | |
26 | + compatible = "atmel,at25", "st,m95256"; | |
27 | + reg = <0> | |
28 | + spi-max-frequency = <5000000>; | |
29 | + spi-cpha; | |
30 | + spi-cpol; | |
31 | + | |
32 | + pagesize = <64>; | |
33 | + size = <32768>; | |
34 | + address-width = <16>; | |
35 | + }; |
drivers/misc/eeprom/at25.c
... | ... | @@ -302,6 +302,61 @@ |
302 | 302 | |
303 | 303 | /*-------------------------------------------------------------------------*/ |
304 | 304 | |
305 | +static 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 | + | |
305 | 360 | static int at25_probe(struct spi_device *spi) |
306 | 361 | { |
307 | 362 | struct at25_data *at25 = NULL; |
308 | 363 | |
309 | 364 | |
... | ... | @@ -314,33 +369,11 @@ |
314 | 369 | /* Chip description */ |
315 | 370 | if (!spi->dev.platform_data) { |
316 | 371 | if (np) { |
317 | - u32 val; | |
318 | - | |
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"); | |
372 | + err = at25_np_to_chip(&spi->dev, np, &chip); | |
373 | + if (err) | |
325 | 374 | 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; | |
340 | - } | |
341 | - chip.page_size = (u16)val; | |
342 | 375 | } else { |
343 | - dev_dbg(&spi->dev, "no chip description\n"); | |
376 | + dev_err(&spi->dev, "Error: no chip description\n"); | |
344 | 377 | err = -ENODEV; |
345 | 378 | goto fail; |
346 | 379 | } |