diff options
author | David Daney <david.daney@cavium.com> | 2012-08-22 15:03:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-05 17:10:29 -0400 |
commit | d6ae0d578d24303941c1424b049d2cae28277666 (patch) | |
tree | 408e4d6d19acc44353761517731c5ce486e4882e /drivers/misc/eeprom | |
parent | 9af514232e9e74cbcd24700fc321b7c71a536568 (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>
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r-- | drivers/misc/eeprom/at25.c | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 25003d6ceb56..4ed93dd54116 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 | ||
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 | static int at25_probe(struct spi_device *spi) | 360 | static 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 | } |