aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javierm@redhat.com>2017-10-01 06:49:48 -0400
committerWolfram Sang <wsa@the-dreams.de>2017-11-05 16:21:28 -0500
commit7f2a2f0d0d66b2d834c793df45af3277bb5f10f4 (patch)
tree82a18f55093e7cee26b86b8a09f6df066f537b5a /drivers/misc
parent8aee55759643676c46d120c2bae821f2669969c6 (diff)
eeprom: at24: Add OF device ID table
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. To maintain backward compatibility with old Device Trees, only use the OF device ID table .data if the device was registered via OF and the OF node compatible matches an entry in the OF device ID table. Suggested-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/eeprom/at24.c71
1 files changed, 70 insertions, 1 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index a466e40acb2c..e0b4b36ef010 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -12,6 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of_device.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/delay.h> 17#include <linux/delay.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
@@ -176,6 +177,64 @@ static const struct i2c_device_id at24_ids[] = {
176}; 177};
177MODULE_DEVICE_TABLE(i2c, at24_ids); 178MODULE_DEVICE_TABLE(i2c, at24_ids);
178 179
180static const struct of_device_id at24_of_match[] = {
181 {
182 .compatible = "atmel,24c00",
183 .data = (void *)AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR)
184 },
185 {
186 .compatible = "atmel,24c01",
187 .data = (void *)AT24_DEVICE_MAGIC(1024 / 8, 0)
188 },
189 {
190 .compatible = "atmel,24c02",
191 .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 0)
192 },
193 {
194 .compatible = "atmel,spd",
195 .data = (void *)AT24_DEVICE_MAGIC(2048 / 8,
196 AT24_FLAG_READONLY | AT24_FLAG_IRUGO)
197 },
198 {
199 .compatible = "atmel,24c04",
200 .data = (void *)AT24_DEVICE_MAGIC(4096 / 8, 0)
201 },
202 {
203 .compatible = "atmel,24c08",
204 .data = (void *)AT24_DEVICE_MAGIC(8192 / 8, 0)
205 },
206 {
207 .compatible = "atmel,24c16",
208 .data = (void *)AT24_DEVICE_MAGIC(16384 / 8, 0)
209 },
210 {
211 .compatible = "atmel,24c32",
212 .data = (void *)AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16)
213 },
214 {
215 .compatible = "atmel,24c64",
216 .data = (void *)AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16)
217 },
218 {
219 .compatible = "atmel,24c128",
220 .data = (void *)AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16)
221 },
222 {
223 .compatible = "atmel,24c256",
224 .data = (void *)AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16)
225 },
226 {
227 .compatible = "atmel,24c512",
228 .data = (void *)AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16)
229 },
230 {
231 .compatible = "atmel,24c1024",
232 .data = (void *)AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16)
233 },
234 { },
235};
236MODULE_DEVICE_TABLE(of, at24_of_match);
237
179static const struct acpi_device_id at24_acpi_ids[] = { 238static const struct acpi_device_id at24_acpi_ids[] = {
180 { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) }, 239 { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) },
181 { } 240 { }
@@ -629,7 +688,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
629 if (client->dev.platform_data) { 688 if (client->dev.platform_data) {
630 chip = *(struct at24_platform_data *)client->dev.platform_data; 689 chip = *(struct at24_platform_data *)client->dev.platform_data;
631 } else { 690 } else {
632 if (id) { 691 /*
692 * The I2C core allows OF nodes compatibles to match against the
693 * I2C device ID table as a fallback, so check not only if an OF
694 * node is present but also if it matches an OF device ID entry.
695 */
696 if (client->dev.of_node &&
697 of_match_device(at24_of_match, &client->dev)) {
698 magic = (kernel_ulong_t)
699 of_device_get_match_data(&client->dev);
700 } else if (id) {
633 magic = id->driver_data; 701 magic = id->driver_data;
634 } else { 702 } else {
635 const struct acpi_device_id *aid; 703 const struct acpi_device_id *aid;
@@ -855,6 +923,7 @@ static int at24_remove(struct i2c_client *client)
855static struct i2c_driver at24_driver = { 923static struct i2c_driver at24_driver = {
856 .driver = { 924 .driver = {
857 .name = "at24", 925 .name = "at24",
926 .of_match_table = at24_of_match,
858 .acpi_match_table = ACPI_PTR(at24_acpi_ids), 927 .acpi_match_table = ACPI_PTR(at24_acpi_ids),
859 }, 928 },
860 .probe = at24_probe, 929 .probe = at24_probe,