aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/eeprom
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r--drivers/misc/eeprom/at25.c83
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
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 }