Commit f60e7074 authored by Mika Westerberg's avatar Mika Westerberg Committed by Rafael J. Wysocki

misc: at25: Make use of device property API

Make use of device property API in this driver so that both DT and ACPI
based systems can use this driver.

In addition we hard-code the name of the chip to be "at25" for the
reason that there is no common mechanism to fetch name of the firmware
node. The only existing user (arch/arm/boot/dts/phy3250.dts) uses the
same name so it should continue to work.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: default avatarGrant Likely <grant.likely@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 733e6251
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/eeprom.h> #include <linux/spi/eeprom.h>
#include <linux/of.h> #include <linux/property.h>
/* /*
* NOTE: this is an *EEPROM* driver. The vagaries of product naming * NOTE: this is an *EEPROM* driver. The vagaries of product naming
...@@ -301,35 +301,33 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf, ...@@ -301,35 +301,33 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static int at25_np_to_chip(struct device *dev, static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
struct device_node *np,
struct spi_eeprom *chip)
{ {
u32 val; u32 val;
memset(chip, 0, sizeof(*chip)); memset(chip, 0, sizeof(*chip));
strncpy(chip->name, np->name, sizeof(chip->name)); strncpy(chip->name, "at25", sizeof(chip->name));
if (of_property_read_u32(np, "size", &val) == 0 || if (device_property_read_u32(dev, "size", &val) == 0 ||
of_property_read_u32(np, "at25,byte-len", &val) == 0) { device_property_read_u32(dev, "at25,byte-len", &val) == 0) {
chip->byte_len = val; chip->byte_len = val;
} else { } else {
dev_err(dev, "Error: missing \"size\" property\n"); dev_err(dev, "Error: missing \"size\" property\n");
return -ENODEV; return -ENODEV;
} }
if (of_property_read_u32(np, "pagesize", &val) == 0 || if (device_property_read_u32(dev, "pagesize", &val) == 0 ||
of_property_read_u32(np, "at25,page-size", &val) == 0) { device_property_read_u32(dev, "at25,page-size", &val) == 0) {
chip->page_size = (u16)val; chip->page_size = (u16)val;
} else { } else {
dev_err(dev, "Error: missing \"pagesize\" property\n"); dev_err(dev, "Error: missing \"pagesize\" property\n");
return -ENODEV; return -ENODEV;
} }
if (of_property_read_u32(np, "at25,addr-mode", &val) == 0) { if (device_property_read_u32(dev, "at25,addr-mode", &val) == 0) {
chip->flags = (u16)val; chip->flags = (u16)val;
} else { } else {
if (of_property_read_u32(np, "address-width", &val)) { if (device_property_read_u32(dev, "address-width", &val)) {
dev_err(dev, dev_err(dev,
"Error: missing \"address-width\" property\n"); "Error: missing \"address-width\" property\n");
return -ENODEV; return -ENODEV;
...@@ -350,7 +348,7 @@ static int at25_np_to_chip(struct device *dev, ...@@ -350,7 +348,7 @@ static int at25_np_to_chip(struct device *dev,
val); val);
return -ENODEV; return -ENODEV;
} }
if (of_find_property(np, "read-only", NULL)) if (device_property_present(dev, "read-only"))
chip->flags |= EE_READONLY; chip->flags |= EE_READONLY;
} }
return 0; return 0;
...@@ -360,21 +358,15 @@ static int at25_probe(struct spi_device *spi) ...@@ -360,21 +358,15 @@ static int at25_probe(struct spi_device *spi)
{ {
struct at25_data *at25 = NULL; struct at25_data *at25 = NULL;
struct spi_eeprom chip; struct spi_eeprom chip;
struct device_node *np = spi->dev.of_node;
int err; int err;
int sr; int sr;
int addrlen; int addrlen;
/* Chip description */ /* Chip description */
if (!spi->dev.platform_data) { if (!spi->dev.platform_data) {
if (np) { err = at25_fw_to_chip(&spi->dev, &chip);
err = at25_np_to_chip(&spi->dev, np, &chip); if (err)
if (err) return err;
return err;
} else {
dev_err(&spi->dev, "Error: no chip description\n");
return -ENODEV;
}
} else } else
chip = *(struct spi_eeprom *)spi->dev.platform_data; chip = *(struct spi_eeprom *)spi->dev.platform_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment