at25.c (f01387d2693813eb5271a3448e6a082322c7d75d) | at25.c (f60e7074902a66d9a132a971ecda63ee5b8bc154) |
---|---|
1/* 2 * at25.c -- support most SPI EEPROMs, such as Atmel AT25 models 3 * 4 * Copyright (C) 2006 David Brownell 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 4 unchanged lines hidden (view full) --- 13#include <linux/module.h> 14#include <linux/slab.h> 15#include <linux/delay.h> 16#include <linux/device.h> 17#include <linux/sched.h> 18 19#include <linux/spi/spi.h> 20#include <linux/spi/eeprom.h> | 1/* 2 * at25.c -- support most SPI EEPROMs, such as Atmel AT25 models 3 * 4 * Copyright (C) 2006 David Brownell 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 4 unchanged lines hidden (view full) --- 13#include <linux/module.h> 14#include <linux/slab.h> 15#include <linux/delay.h> 16#include <linux/device.h> 17#include <linux/sched.h> 18 19#include <linux/spi/spi.h> 20#include <linux/spi/eeprom.h> |
21#include <linux/of.h> | 21#include <linux/property.h> |
22 23/* 24 * NOTE: this is an *EEPROM* driver. The vagaries of product naming 25 * mean that some AT25 products are EEPROMs, and others are FLASH. 26 * Handle FLASH chips with the drivers/mtd/devices/m25p80.c driver, 27 * not this one! 28 */ 29 --- 266 unchanged lines hidden (view full) --- 296{ 297 struct at25_data *at25 = container_of(mem, struct at25_data, mem); 298 299 return at25_ee_write(at25, buf, offset, count); 300} 301 302/*-------------------------------------------------------------------------*/ 303 | 22 23/* 24 * NOTE: this is an *EEPROM* driver. The vagaries of product naming 25 * mean that some AT25 products are EEPROMs, and others are FLASH. 26 * Handle FLASH chips with the drivers/mtd/devices/m25p80.c driver, 27 * not this one! 28 */ 29 --- 266 unchanged lines hidden (view full) --- 296{ 297 struct at25_data *at25 = container_of(mem, struct at25_data, mem); 298 299 return at25_ee_write(at25, buf, offset, count); 300} 301 302/*-------------------------------------------------------------------------*/ 303 |
304static int at25_np_to_chip(struct device *dev, 305 struct device_node *np, 306 struct spi_eeprom *chip) | 304static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip) |
307{ 308 u32 val; 309 310 memset(chip, 0, sizeof(*chip)); | 305{ 306 u32 val; 307 308 memset(chip, 0, sizeof(*chip)); |
311 strncpy(chip->name, np->name, sizeof(chip->name)); | 309 strncpy(chip->name, "at25", sizeof(chip->name)); |
312 | 310 |
313 if (of_property_read_u32(np, "size", &val) == 0 || 314 of_property_read_u32(np, "at25,byte-len", &val) == 0) { | 311 if (device_property_read_u32(dev, "size", &val) == 0 || 312 device_property_read_u32(dev, "at25,byte-len", &val) == 0) { |
315 chip->byte_len = val; 316 } else { 317 dev_err(dev, "Error: missing \"size\" property\n"); 318 return -ENODEV; 319 } 320 | 313 chip->byte_len = val; 314 } else { 315 dev_err(dev, "Error: missing \"size\" property\n"); 316 return -ENODEV; 317 } 318 |
321 if (of_property_read_u32(np, "pagesize", &val) == 0 || 322 of_property_read_u32(np, "at25,page-size", &val) == 0) { | 319 if (device_property_read_u32(dev, "pagesize", &val) == 0 || 320 device_property_read_u32(dev, "at25,page-size", &val) == 0) { |
323 chip->page_size = (u16)val; 324 } else { 325 dev_err(dev, "Error: missing \"pagesize\" property\n"); 326 return -ENODEV; 327 } 328 | 321 chip->page_size = (u16)val; 322 } else { 323 dev_err(dev, "Error: missing \"pagesize\" property\n"); 324 return -ENODEV; 325 } 326 |
329 if (of_property_read_u32(np, "at25,addr-mode", &val) == 0) { | 327 if (device_property_read_u32(dev, "at25,addr-mode", &val) == 0) { |
330 chip->flags = (u16)val; 331 } else { | 328 chip->flags = (u16)val; 329 } else { |
332 if (of_property_read_u32(np, "address-width", &val)) { | 330 if (device_property_read_u32(dev, "address-width", &val)) { |
333 dev_err(dev, 334 "Error: missing \"address-width\" property\n"); 335 return -ENODEV; 336 } 337 switch (val) { 338 case 8: 339 chip->flags |= EE_ADDR1; 340 break; --- 4 unchanged lines hidden (view full) --- 345 chip->flags |= EE_ADDR3; 346 break; 347 default: 348 dev_err(dev, 349 "Error: bad \"address-width\" property: %u\n", 350 val); 351 return -ENODEV; 352 } | 331 dev_err(dev, 332 "Error: missing \"address-width\" property\n"); 333 return -ENODEV; 334 } 335 switch (val) { 336 case 8: 337 chip->flags |= EE_ADDR1; 338 break; --- 4 unchanged lines hidden (view full) --- 343 chip->flags |= EE_ADDR3; 344 break; 345 default: 346 dev_err(dev, 347 "Error: bad \"address-width\" property: %u\n", 348 val); 349 return -ENODEV; 350 } |
353 if (of_find_property(np, "read-only", NULL)) | 351 if (device_property_present(dev, "read-only")) |
354 chip->flags |= EE_READONLY; 355 } 356 return 0; 357} 358 359static int at25_probe(struct spi_device *spi) 360{ 361 struct at25_data *at25 = NULL; 362 struct spi_eeprom chip; | 352 chip->flags |= EE_READONLY; 353 } 354 return 0; 355} 356 357static int at25_probe(struct spi_device *spi) 358{ 359 struct at25_data *at25 = NULL; 360 struct spi_eeprom chip; |
363 struct device_node *np = spi->dev.of_node; | |
364 int err; 365 int sr; 366 int addrlen; 367 368 /* Chip description */ 369 if (!spi->dev.platform_data) { | 361 int err; 362 int sr; 363 int addrlen; 364 365 /* Chip description */ 366 if (!spi->dev.platform_data) { |
370 if (np) { 371 err = at25_np_to_chip(&spi->dev, np, &chip); 372 if (err) 373 return err; 374 } else { 375 dev_err(&spi->dev, "Error: no chip description\n"); 376 return -ENODEV; 377 } | 367 err = at25_fw_to_chip(&spi->dev, &chip); 368 if (err) 369 return err; |
378 } else 379 chip = *(struct spi_eeprom *)spi->dev.platform_data; 380 381 /* For now we only support 8/16/24 bit addressing */ 382 if (chip.flags & EE_ADDR1) 383 addrlen = 1; 384 else if (chip.flags & EE_ADDR2) 385 addrlen = 2; --- 100 unchanged lines hidden --- | 370 } else 371 chip = *(struct spi_eeprom *)spi->dev.platform_data; 372 373 /* For now we only support 8/16/24 bit addressing */ 374 if (chip.flags & EE_ADDR1) 375 addrlen = 1; 376 else if (chip.flags & EE_ADDR2) 377 addrlen = 2; --- 100 unchanged lines hidden --- |