diff options
author | Alexandre Pereira da Silva <aletes.xgr@gmail.com> | 2012-06-14 08:59:23 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-06-14 20:23:04 -0400 |
commit | 002176db8113c92d0bda02a47e3d2a4b8f9f55ea (patch) | |
tree | 62e5aabaa54c7fe486363873fd85cfe2487a9963 /drivers/misc/eeprom | |
parent | 98dcd59dd063dd8099d8dbccd84a40e927dc7138 (diff) |
misc: at25: Parse dt settings
This adds dt support to the at25 eeprom driver.
Signed-off-by: Alexandre Pereira da Silva <aletes.xgr@gmail.com>
Tested-by: Roland Stigge <stigge@antcom.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r-- | drivers/misc/eeprom/at25.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 0842c2994ee2..25003d6ceb56 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c | |||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | #include <linux/spi/spi.h> | 20 | #include <linux/spi/spi.h> |
21 | #include <linux/spi/eeprom.h> | 21 | #include <linux/spi/eeprom.h> |
22 | 22 | #include <linux/of.h> | |
23 | 23 | ||
24 | /* | 24 | /* |
25 | * NOTE: this is an *EEPROM* driver. The vagaries of product naming | 25 | * NOTE: this is an *EEPROM* driver. The vagaries of product naming |
@@ -305,25 +305,54 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf, | |||
305 | static int at25_probe(struct spi_device *spi) | 305 | static int at25_probe(struct spi_device *spi) |
306 | { | 306 | { |
307 | struct at25_data *at25 = NULL; | 307 | struct at25_data *at25 = NULL; |
308 | const struct spi_eeprom *chip; | 308 | struct spi_eeprom chip; |
309 | struct device_node *np = spi->dev.of_node; | ||
309 | int err; | 310 | int err; |
310 | int sr; | 311 | int sr; |
311 | int addrlen; | 312 | int addrlen; |
312 | 313 | ||
313 | /* Chip description */ | 314 | /* Chip description */ |
314 | chip = spi->dev.platform_data; | 315 | if (!spi->dev.platform_data) { |
315 | if (!chip) { | 316 | if (np) { |
316 | dev_dbg(&spi->dev, "no chip description\n"); | 317 | u32 val; |
317 | err = -ENODEV; | 318 | |
318 | goto fail; | 319 | memset(&chip, 0, sizeof(chip)); |
319 | } | 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; | ||
340 | } | ||
341 | chip.page_size = (u16)val; | ||
342 | } else { | ||
343 | dev_dbg(&spi->dev, "no chip description\n"); | ||
344 | err = -ENODEV; | ||
345 | goto fail; | ||
346 | } | ||
347 | } else | ||
348 | chip = *(struct spi_eeprom *)spi->dev.platform_data; | ||
320 | 349 | ||
321 | /* For now we only support 8/16/24 bit addressing */ | 350 | /* For now we only support 8/16/24 bit addressing */ |
322 | if (chip->flags & EE_ADDR1) | 351 | if (chip.flags & EE_ADDR1) |
323 | addrlen = 1; | 352 | addrlen = 1; |
324 | else if (chip->flags & EE_ADDR2) | 353 | else if (chip.flags & EE_ADDR2) |
325 | addrlen = 2; | 354 | addrlen = 2; |
326 | else if (chip->flags & EE_ADDR3) | 355 | else if (chip.flags & EE_ADDR3) |
327 | addrlen = 3; | 356 | addrlen = 3; |
328 | else { | 357 | else { |
329 | dev_dbg(&spi->dev, "unsupported address type\n"); | 358 | dev_dbg(&spi->dev, "unsupported address type\n"); |
@@ -348,7 +377,7 @@ static int at25_probe(struct spi_device *spi) | |||
348 | } | 377 | } |
349 | 378 | ||
350 | mutex_init(&at25->lock); | 379 | mutex_init(&at25->lock); |
351 | at25->chip = *chip; | 380 | at25->chip = chip; |
352 | at25->spi = spi_dev_get(spi); | 381 | at25->spi = spi_dev_get(spi); |
353 | dev_set_drvdata(&spi->dev, at25); | 382 | dev_set_drvdata(&spi->dev, at25); |
354 | at25->addrlen = addrlen; | 383 | at25->addrlen = addrlen; |
@@ -369,7 +398,7 @@ static int at25_probe(struct spi_device *spi) | |||
369 | at25->mem.read = at25_mem_read; | 398 | at25->mem.read = at25_mem_read; |
370 | 399 | ||
371 | at25->bin.size = at25->chip.byte_len; | 400 | at25->bin.size = at25->chip.byte_len; |
372 | if (!(chip->flags & EE_READONLY)) { | 401 | if (!(chip.flags & EE_READONLY)) { |
373 | at25->bin.write = at25_bin_write; | 402 | at25->bin.write = at25_bin_write; |
374 | at25->bin.attr.mode |= S_IWUSR; | 403 | at25->bin.attr.mode |= S_IWUSR; |
375 | at25->mem.write = at25_mem_write; | 404 | at25->mem.write = at25_mem_write; |
@@ -379,8 +408,8 @@ static int at25_probe(struct spi_device *spi) | |||
379 | if (err) | 408 | if (err) |
380 | goto fail; | 409 | goto fail; |
381 | 410 | ||
382 | if (chip->setup) | 411 | if (chip.setup) |
383 | chip->setup(&at25->mem, chip->context); | 412 | chip.setup(&at25->mem, chip.context); |
384 | 413 | ||
385 | dev_info(&spi->dev, "%Zd %s %s eeprom%s, pagesize %u\n", | 414 | dev_info(&spi->dev, "%Zd %s %s eeprom%s, pagesize %u\n", |
386 | (at25->bin.size < 1024) | 415 | (at25->bin.size < 1024) |
@@ -388,7 +417,7 @@ static int at25_probe(struct spi_device *spi) | |||
388 | : (at25->bin.size / 1024), | 417 | : (at25->bin.size / 1024), |
389 | (at25->bin.size < 1024) ? "Byte" : "KByte", | 418 | (at25->bin.size < 1024) ? "Byte" : "KByte", |
390 | at25->chip.name, | 419 | at25->chip.name, |
391 | (chip->flags & EE_READONLY) ? " (readonly)" : "", | 420 | (chip.flags & EE_READONLY) ? " (readonly)" : "", |
392 | at25->chip.page_size); | 421 | at25->chip.page_size); |
393 | return 0; | 422 | return 0; |
394 | fail: | 423 | fail: |