>From 78792d4e759f023975700222caffa7a20f77fcf9 Mon Sep 17 00:00:00 2001 From: Mika Westerberg Date: Mon, 29 Sep 2014 13:11:07 +0300 Subject: [PATCH] misc/at24: Make use of device property API Not-Signed-off-by: Mika Westerberg --- drivers/misc/eeprom/at24.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index c6cb7f8f325e..d2963b5632d4 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -20,9 +20,9 @@ #include #include #include -#include #include #include +#include /* * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. @@ -443,26 +443,24 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf, /*-------------------------------------------------------------------------*/ -#ifdef CONFIG_OF -static void at24_get_ofdata(struct i2c_client *client, +static int at24_get_fwdata(struct i2c_client *client, struct at24_platform_data *chip) { - const __be32 *val; - struct device_node *node = client->dev.of_node; - - if (node) { - if (of_get_property(node, "read-only", NULL)) - chip->flags |= AT24_FLAG_READONLY; - val = of_get_property(node, "pagesize", NULL); - if (val) - chip->page_size = be32_to_cpup(val); - } + if (device_property_present(&client->dev, "read-only")) + chip->flags |= AT24_FLAG_READONLY; + if (device_property_read_u16(&client->dev, "pagesize", &chip->page_size)) + return -ENODEV; + if (device_property_read_u32(&client->dev, "size", &chip->byte_len)) + return -ENODEV; + + return 0; } -#else -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ } -#endif /* CONFIG_OF */ + +static const struct of_device_id at24_of_match[] = { + { .compatible = "atmel,24c02" }, + { }, +}; +MODULE_DEVICE_TABLE(of, at24_of_match); static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -477,7 +475,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (client->dev.platform_data) { chip = *(struct at24_platform_data *)client->dev.platform_data; - } else { + } else if (id) { if (!id->driver_data) return -ENODEV; @@ -493,10 +491,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.page_size = 1; /* update chipdata if OF is present */ - at24_get_ofdata(client, &chip); + at24_get_fwdata(client, &chip); chip.setup = NULL; chip.context = NULL; + } else { + memset(&chip, 0, sizeof(chip)); + err = at24_get_fwdata(client, &chip); + if (err) + return err; } if (!is_power_of_2(chip.byte_len)) @@ -661,6 +664,7 @@ static int at24_remove(struct i2c_client *client) static struct i2c_driver at24_driver = { .driver = { .name = "at24", + .of_match_table = at24_of_match, }, .probe = at24_probe, .remove = at24_remove, -- 2.6.1