Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (tmp421) 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.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Javier Martinez Canillas and committed by
Guenter Roeck
a1253027 72fc64c6

+33 -2
+33 -2
drivers/hwmon/tmp421.c
··· 29 29 #include <linux/hwmon-sysfs.h> 30 30 #include <linux/err.h> 31 31 #include <linux/mutex.h> 32 + #include <linux/of_device.h> 32 33 #include <linux/sysfs.h> 33 34 34 35 /* Addresses to scan */ ··· 70 69 }; 71 70 MODULE_DEVICE_TABLE(i2c, tmp421_id); 72 71 72 + static const struct of_device_id tmp421_of_match[] = { 73 + { 74 + .compatible = "ti,tmp421", 75 + .data = (void *)2 76 + }, 77 + { 78 + .compatible = "ti,tmp422", 79 + .data = (void *)3 80 + }, 81 + { 82 + .compatible = "ti,tmp423", 83 + .data = (void *)4 84 + }, 85 + { 86 + .compatible = "ti,tmp441", 87 + .data = (void *)2 88 + }, 89 + { 90 + .compatible = "ti,tmp422", 91 + .data = (void *)3 92 + }, 93 + { }, 94 + }; 95 + MODULE_DEVICE_TABLE(of, tmp421_of_match); 96 + 73 97 struct tmp421_data { 74 98 struct i2c_client *client; 75 99 struct mutex update_lock; ··· 104 78 struct hwmon_chip_info chip; 105 79 char valid; 106 80 unsigned long last_updated; 107 - int channels; 81 + unsigned long channels; 108 82 u8 config; 109 83 s16 temp[4]; 110 84 }; ··· 298 272 return -ENOMEM; 299 273 300 274 mutex_init(&data->update_lock); 301 - data->channels = id->driver_data; 275 + if (client->dev.of_node) 276 + data->channels = (unsigned long) 277 + of_device_get_match_data(&client->dev); 278 + else 279 + data->channels = id->driver_data; 302 280 data->client = client; 303 281 304 282 err = tmp421_init_client(client); ··· 331 301 .class = I2C_CLASS_HWMON, 332 302 .driver = { 333 303 .name = "tmp421", 304 + .of_match_table = of_match_ptr(tmp421_of_match), 334 305 }, 335 306 .probe = tmp421_probe, 336 307 .id_table = tmp421_id,