hwmon: Add OF device table to I2C drivers that are missing it
cover hwmon: Add OF device table to I2C drivers that are missing it
Hello,
This series add OF device ID tables to hwmon I2C drivers whose devices are either used in Device Tree source files or are listed in binding docs as a compatible string.
That's done because the plan is to change the I2C core to report proper OF modaliases instead of always reporting a MODALIAS=i2c:<foo> regardless if a device was registered via DT or using the legacy platform data.
So these patches will make sure that hwmon I2C drivers will continue to be able to module auto-load once the I2C core is changed.
Best regards,
Javier
Javier Martinez Canillas (19):
hwmon: (ad7414) Add OF device ID table
hwmon: (adc128d818) Add OF device ID table
hwmon: (ads1015) Add OF device ID table
hwmon: (ads7828) Add OF device ID table
hwmon: (adt7475) Add OF device ID table
hwmon: (ina209) Add OF device ID table
hwmon: (ina2xx) Add OF device ID table
hwmon: (lm63) Add OF device ID table
hwmon: (lm75) Add OF device ID table
hwmon: (lm85) Add OF device ID table
hwmon: (lm90) Add OF device ID table
hwmon: (lm95245) Add OF device ID table
hwmon: (max6697) Add OF device ID table
hwmon: (ucd9000) Add OF device ID table
hwmon: (ucd9200) Add OF device ID table
hwmon: (stts751) Add OF device ID table
hwmon: (tmp102) Add OF device ID table
hwmon: (tmp103) Add OF device ID table
hwmon: (tmp421) Add OF device ID table
drivers/hwmon/ad7414.c | 7 +++ drivers/hwmon/adc128d818.c | 7 +++ drivers/hwmon/ads1015.c | 22 +++++++++- drivers/hwmon/ads7828.c | 24 +++++++++- drivers/hwmon/adt7475.c | 31 ++++++++++++- drivers/hwmon/ina209.c | 7 +++ drivers/hwmon/ina2xx.c | 35 ++++++++++++++- drivers/hwmon/lm63.c | 23 ++++++++++ drivers/hwmon/lm75.c | 98 ++++++++++++++++++++++++++++++++++++++++- drivers/hwmon/lm85.c | 56 ++++++++++++++++++++++- drivers/hwmon/lm90.c | 100 +++++++++++++++++++++++++++++++++++++++++- drivers/hwmon/lm95245.c | 8 ++++ drivers/hwmon/max6697.c | 52 +++++++++++++++++++++- drivers/hwmon/pmbus/ucd9000.c | 39 +++++++++++++++- drivers/hwmon/pmbus/ucd9200.c | 48 +++++++++++++++++++- drivers/hwmon/stts751.c | 7 +++ drivers/hwmon/tmp102.c | 7 +++ drivers/hwmon/tmp103.c | 7 +++ drivers/hwmon/tmp421.c | 35 ++++++++++++++- 19 files changed, 601 insertions(+), 12 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/19 hwmon: (ad7414) 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.
---
drivers/hwmon/ad7414.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/ad7414.c +7 -0
@@ -217,9 +217,16 @@ static const struct i2c_device_id ad7414_id[] = { };MODULE_DEVICE_TABLE (i2c, ad7414_id); +static const struct of_device_id ad7414_of_match[] = { + { .compatible ="ad,ad7414" }, + { }, +}; +MODULE_DEVICE_TABLE (of, ad7414_of_match); +static struct i2c_driver ad7414_driver = { .driver = { .name ="ad7414" , + .of_match_table =of_match_ptr (ad7414_of_match), }, .probe = ad7414_probe, .id_table = ad7414_id,
Signature · 1 line
2.9.3
PATCH 2/19 hwmon: (adc128d818) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/adc128d818.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/adc128d818.c +7 -0
@@ -546,10 +546,17 @@ static const struct i2c_device_id adc128_id[] = { };MODULE_DEVICE_TABLE (i2c, adc128_id); +static const struct of_device_id adc128_of_match[] = { + { .compatible ="ti,adc128d818" }, + { }, +}; +MODULE_DEVICE_TABLE (of, adc128_of_match); +static struct i2c_driver adc128_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="adc128d818" , + .of_match_table =of_match_ptr (adc128_of_match), }, .probe = adc128_probe, .remove = adc128_remove,
Signature · 1 line
2.9.3
PATCH 3/19 hwmon: (ads1015) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/ads1015.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/hwmon/ads1015.c +21 -1
@@ -31,6 +31,7 @@#include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/of.h> #include <linux/i2c/ads1015.h>
@@ -268,7 +269,12 @@ static int ads1015_probe(struct i2c_client *client, GFP_KERNEL);if (!data)return -ENOMEM ; - data->id = id->driver_data; + +if (client->dev.of_node) + data->id = (enum ads1015_chips ) +of_device_get_match_data (&client->dev); +else + data->id = id->driver_data;i2c_set_clientdata (client, data);mutex_init (&data->update_lock);
@@ -303,9 +309,23 @@ static const struct i2c_device_id ads1015_id[] = { };MODULE_DEVICE_TABLE (i2c, ads1015_id); +static const struct of_device_id ads1015_of_match[] = { + { + .compatible ="ti,ads1015" , + .data = (void *)ads1015 + }, + { + .compatible ="ti,ads1115" , + .data = (void *)ads1115 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, ads1015_of_match); +static struct i2c_driver ads1015_driver = { .driver = { .name ="ads1015" , + .of_match_table =of_match_ptr (ads1015_of_match), }, .probe = ads1015_probe, .remove = ads1015_remove,
Signature · 1 line
2.9.3
PATCH 4/19 hwmon: (ads7828) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/ads7828.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/hwmon/ads7828.c +23 -1
@@ -31,6 +31,7 @@#include <linux/i2c.h> #include <linux/init.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/platform_data/ads7828.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -121,6 +122,7 @@ static int ads7828_probe(struct i2c_client *client,bool diff_input = false;bool ext_vref = false;unsigned int regval; +enum ads7828_chips chip; data =devm_kzalloc (dev,sizeof (struct ads7828_data ),GFP_KERNEL );if (!data)
@@ -133,12 +135,18 @@ static int ads7828_probe(struct i2c_client *client, vref_mv = pdata->vref_mv; } +if (client->dev.of_node) + chip = (enum ads7828_chips ) +of_device_get_match_data (&client->dev); +else + chip = id->driver_data; +/* Bound Vref with min/max values */ vref_mv =clamp_val (vref_mv,ADS7828_EXT_VREF_MV_MIN ,ADS7828_EXT_VREF_MV_MAX );/* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ -if (id->driver_data == ads7828) { +if (chip == ads7828) { data->lsb_resol =DIV_ROUND_CLOSEST (vref_mv *1000 ,4096 ); data->regmap =devm_regmap_init_i2c (client, &ads2828_regmap_config);
@@ -177,9 +185,23 @@ static const struct i2c_device_id ads7828_device_ids[] = { };MODULE_DEVICE_TABLE (i2c, ads7828_device_ids); +static const struct of_device_id ads7828_of_match[] = { + { + .compatible ="ti,ads7828" , + .data = (void *)ads7828 + }, + { + .compatible ="ti,ads7830" , + .data = (void *)ads7830 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, ads7828_of_match); +static struct i2c_driver ads7828_driver = { .driver = { .name ="ads7828" , + .of_match_table =of_match_ptr (ads7828_of_match), }, .id_table = ads7828_device_ids,
Signature · 1 line
2.9.3
PATCH 5/19 hwmon: (adt7475) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/adt7475.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/hwmon/adt7475.c +30 -1
@@ -13,6 +13,7 @@*/ #include <linux/module.h> +#include <linux/of_device.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h>
@@ -161,6 +162,27 @@ static const struct i2c_device_id adt7475_id[] = { };MODULE_DEVICE_TABLE (i2c, adt7475_id); +static const struct of_device_id adt7475_of_match[] = { + { + .compatible ="adi,adt7473" , + .data = (void *)adt7473 + }, + { + .compatible ="adi,adt7475" , + .data = (void *)adt7475 + }, + { + .compatible ="adi,adt7476" , + .data = (void *)adt7476 + }, + { + .compatible ="adi,adt7490" , + .data = (void *)adt7490 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, adt7475_of_match); +struct adt7475_data {struct device *hwmon_dev;struct mutex lock;
@@ -1250,6 +1272,7 @@ static void adt7475_remove_files(struct i2c_client *client,static int adt7475_probe (struct i2c_client *client,const struct i2c_device_id *id) { +enum chips chip;static const char *const names[] = { [adt7473] ="ADT7473" , [adt7475] ="ADT7475" ,
@@ -1268,8 +1291,13 @@ static int adt7475_probe(struct i2c_client *client,mutex_init (&data->lock);i2c_set_clientdata (client, data); +if (client->dev.of_node) + chip = (enum chips )of_device_get_match_data (&client->dev); +else + chip = id->driver_data; +/* Initialize device-specific values */ -switch (id->driver_data) { +switch (chip) {case adt7476: data->has_voltage =0x0e ;/* in1 to in3 */ revision =adt7475_read (REG_DEVID2 ) &0x07 ;
@@ -1428,6 +1456,7 @@ static struct i2c_driver adt7475_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "adt7475", + .of_match_table = of_match_ptr(adt7475_of_match), }, .probe = adt7475_probe, .remove = adt7475_remove,
Signature · 1 line
2.9.3
PATCH 6/19 hwmon: (ina209) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/ina209.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/ina209.c +7 -0
@@ -608,11 +608,18 @@ static const struct i2c_device_id ina209_id[] = { };MODULE_DEVICE_TABLE (i2c, ina209_id); +static const struct of_device_id ina209_of_match[] = { + { .compatible ="ti,ina209" }, + { }, +}; +MODULE_DEVICE_TABLE (of, ina209_of_match); +/* This is the driver that will be inserted */ static struct i2c_driver ina209_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="ina209" , + .of_match_table =of_match_ptr (ina209_of_match), }, .probe = ina209_probe, .remove = ina209_remove,
Signature · 1 line
2.9.3
PATCH 7/19 hwmon: (ina2xx) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/ina2xx.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/hwmon/ina2xx.c +34 -1
@@ -34,6 +34,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/jiffies.h> +#include <linux/of_device.h> #include <linux/of.h> #include <linux/delay.h> #include <linux/util_macros.h>
@@ -424,13 +425,19 @@ static int ina2xx_probe(struct i2c_client *client,struct device *hwmon_dev;u32 val;int ret, group =0 ; +enum ina2xx_ids chip; + +if (client->dev.of_node) + chip = (enum ina2xx_ids )of_device_get_match_data (&client->dev); +else + chip = id->driver_data; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;/* set the device type */ - data->config = &ina2xx_config[id->driver_data]; + data->config = &ina2xx_config[chip];if (of_property_read_u32 (dev->of_node,"shunt-resistor" , &val) <0 ) {struct ina2xx_platform_data *pdata =dev_get_platdata (dev);
@@ -487,9 +494,35 @@ static const struct i2c_device_id ina2xx_id[] = { };MODULE_DEVICE_TABLE (i2c, ina2xx_id); +static const struct of_device_id ina2xx_of_match[] = { + { + .compatible ="ti,ina219" , + .data = (void *)ina219 + }, + { + .compatible ="ti,ina220" , + .data = (void *)ina219 + }, + { + .compatible ="ti,ina226" , + .data = (void *)ina226 + }, + { + .compatible ="ti,ina230" , + .data = (void *)ina226 + }, + { + .compatible ="ti,ina231" , + .data = (void *)ina226 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, ina2xx_of_match); +static struct i2c_driver ina2xx_driver = { .driver = { .name ="ina2xx" , + .of_match_table =of_match_ptr (ina2xx_of_match), }, .probe = ina2xx_probe, .id_table = ina2xx_id,
Signature · 1 line
2.9.3
PATCH 8/19 hwmon: (lm63) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/lm63.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/hwmon/lm63.c +23 -0
@@ -46,6 +46,7 @@#include <linux/hwmon.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/sysfs.h> #include <linux/types.h>
@@ -1115,6 +1116,10 @@ static int lm63_probe(struct i2c_client *client,mutex_init (&data->update_lock);/* Set the device type */ +if (client->dev.of_node) + data->kind = (enum chips )of_device_get_match_data (&client->dev); +else + data->kind = id->driver_data; data->kind = id->driver_data;if (data->kind == lm64) data->temp2_offset =16000 ;
@@ -1149,10 +1154,28 @@ static const struct i2c_device_id lm63_id[] = { };MODULE_DEVICE_TABLE (i2c, lm63_id); +static const struct of_device_id lm63_of_match[] = { + { + .compatible ="national,lm63" , + .data = (void *)lm63 + }, + { + .compatible ="national,lm64" , + .data = (void *)lm64 + }, + { + .compatible ="national,lm96163" , + .data = (void *)lm96163 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, lm63_of_match); +static struct i2c_driver lm63_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="lm63" , + .of_match_table =of_match_ptr (lm63_of_match), }, .probe = lm63_probe, .id_table = lm63_id,
Signature · 1 line
2.9.3
PATCH 9/19 hwmon: (lm75) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/lm75.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)
drivers/hwmon/lm75.c +97 -1
@@ -26,6 +26,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> #include <linux/of.h> #include <linux/regmap.h> #include "lm75.h"
@@ -273,7 +274,12 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)int status, err;u8 set_mask, clr_mask;int new; -enum lm75_type kind = id->driver_data; +enum lm75_type kind; + +if (client->dev.of_node) + kind = (enum lm75_type )of_device_get_match_data (&client->dev); +else + kind = id->driver_data;if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_WORD_DATA ))
@@ -424,6 +430,95 @@ static const struct i2c_device_id lm75_ids[] = { };MODULE_DEVICE_TABLE (i2c, lm75_ids); +static const struct of_device_id lm75_of_match[] = { + { + .compatible ="adi,adt75" , + .data = (void *)adt75 + }, + { + .compatible ="dallas,ds1775" , + .data = (void *)ds1775 + }, + { + .compatible ="dallas,ds75" , + .data = (void *)ds75 + }, + { + .compatible ="dallas,ds7505" , + .data = (void *)ds7505 + }, + { + .compatible ="gmt,g751" , + .data = (void *)g751 + }, + { + .compatible ="national,lm75" , + .data = (void *)lm75 + }, + { + .compatible ="national,lm75a" , + .data = (void *)lm75a + }, + { + .compatible ="national,lm75b" , + .data = (void *)lm75b + }, + { + .compatible ="maxim,max6625" , + .data = (void *)max6625 + }, + { + .compatible ="maxim,max6626" , + .data = (void *)max6626 + }, + { + .compatible ="maxim,mcp980x" , + .data = (void *)mcp980x + }, + { + .compatible ="st,stds75" , + .data = (void *)stds75 + }, + { + .compatible ="microchip,tcn75" , + .data = (void *)tcn75 + }, + { + .compatible ="ti,tmp100" , + .data = (void *)tmp100 + }, + { + .compatible ="ti,tmp101" , + .data = (void *)tmp101 + }, + { + .compatible ="ti,tmp105" , + .data = (void *)tmp105 + }, + { + .compatible ="ti,tmp112" , + .data = (void *)tmp112 + }, + { + .compatible ="ti,tmp175" , + .data = (void *)tmp175 + }, + { + .compatible ="ti,tmp275" , + .data = (void *)tmp275 + }, + { + .compatible ="ti,tmp75" , + .data = (void *)tmp75 + }, + { + .compatible ="ti,tmp75c" , + .data = (void *)tmp75c + }, + { }, +}; +MODULE_DEVICE_TABLE (of, lm75_of_match); +#define LM75A_ID 0xA1/* Return 0 if detection is successful, -ENODEV otherwise */
@@ -560,6 +655,7 @@ static struct i2c_driver lm75_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "lm75", + .of_match_table = of_match_ptr(lm75_of_match), .pm = LM75_DEV_PM_OPS, }, .probe = lm75_probe,
Signature · 1 line
2.9.3
PATCH 10/19 hwmon: (lm85) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/lm85.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-)
drivers/hwmon/lm85.c +55 -1
@@ -25,6 +25,7 @@*/ #include <linux/module.h> +#include <linux/of_device.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/jiffies.h>
@@ -1552,7 +1553,10 @@ static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id)return -ENOMEM ; data->client = client; - data->type = id->driver_data; +if (client->dev.of_node) + data->type = (enum chips )of_device_get_match_data (&client->dev); +else + data->type = id->driver_data;mutex_init (&data->update_lock);/* Fill in the chip specific driver values */
@@ -1623,10 +1627,60 @@ static const struct i2c_device_id lm85_id[] = { };MODULE_DEVICE_TABLE (i2c, lm85_id); +static const struct of_device_id lm85_of_match[] = { + { + .compatible ="adi,adm1027" , + .data = (void *)adm1027 + }, + { + .compatible ="adi,adt7463" , + .data = (void *)adt7463 + }, + { + .compatible ="adi,adt7468" , + .data = (void *)adt7468 + }, + { + .compatible ="national,lm85" , + .data = (void *)lm85 + }, + { + .compatible ="national,lm85b" , + .data = (void *)lm85 + }, + { + .compatible ="national,lm85c" , + .data = (void *)lm85 + }, + { + .compatible ="smsc,emc6d100" , + .data = (void *)emc6d100 + }, + { + .compatible ="smsc,emc6d101" , + .data = (void *)emc6d100 + }, + { + .compatible ="smsc,emc6d102" , + .data = (void *)emc6d102 + }, + { + .compatible ="smsc,emc6d103" , + .data = (void *)emc6d103 + }, + { + .compatible ="smsc,emc6d103s" , + .data = (void *)emc6d103s + }, + { }, +}; +MODULE_DEVICE_TABLE (of, lm85_of_match); +static struct i2c_driver lm85_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="lm85" , + .of_match_table =of_match_ptr (lm85_of_match), }, .probe = lm85_probe, .id_table = lm85_id,
Signature · 1 line
2.9.3
PATCH 11/19 hwmon: (lm90) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/lm90.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-)
drivers/hwmon/lm90.c +99 -1
@@ -92,6 +92,7 @@#include <linux/hwmon.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/sysfs.h> #include <linux/interrupt.h> #include <linux/regulator/consumer.h>
@@ -235,6 +236,99 @@ static const struct i2c_device_id lm90_id[] = { };MODULE_DEVICE_TABLE (i2c, lm90_id); +static const struct of_device_id lm90_of_match[] = { + { + .compatible ="adi,adm1032" , + .data = (void *)adm1032 + }, + { + .compatible ="adi,adt7461" , + .data = (void *)adt7461 + }, + { + .compatible ="adi,adt7461a" , + .data = (void *)adt7461 + }, + { + .compatible ="gmt,g781" , + .data = (void *)g781 + }, + { + .compatible ="national,lm90" , + .data = (void *)lm90 + }, + { + .compatible ="national,lm86" , + .data = (void *)lm86 + }, + { + .compatible ="national,lm89" , + .data = (void *)lm86 + }, + { + .compatible ="national,lm99" , + .data = (void *)lm99 + }, + { + .compatible ="dallas,max6646" , + .data = (void *)max6646 + }, + { + .compatible ="dallas,max6647" , + .data = (void *)max6646 + }, + { + .compatible ="dallas,max6649" , + .data = (void *)max6646 + }, + { + .compatible ="dallas,max6657" , + .data = (void *)max6657 + }, + { + .compatible ="dallas,max6658" , + .data = (void *)max6657 + }, + { + .compatible ="dallas,max6659" , + .data = (void *)max6659 + }, + { + .compatible ="dallas,max6680" , + .data = (void *)max6680 + }, + { + .compatible ="dallas,max6681" , + .data = (void *)max6680 + }, + { + .compatible ="dallas,max6695" , + .data = (void *)max6696 + }, + { + .compatible ="dallas,max6696" , + .data = (void *)max6696 + }, + { + .compatible ="onnn,nct1008" , + .data = (void *)adt7461 + }, + { + .compatible ="winbond,w83l771" , + .data = (void *)w83l771 + }, + { + .compatible ="nxp,sa56004" , + .data = (void *)sa56004 + }, + { + .compatible ="ti,tmp451" , + .data = (void *)tmp451 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, lm90_of_match); +/* * chip type specific parameters */
@@ -1677,7 +1771,10 @@ static int lm90_probe(struct i2c_client *client,mutex_init (&data->update_lock);/* Set the device type */ - data->kind = id->driver_data; +if (client->dev.of_node) + data->kind = (enum chips )of_device_get_match_data (&client->dev); +else + data->kind = id->driver_data;if (data->kind == adm1032) {if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE )) client->flags &= ~I2C_CLIENT_PEC ;
@@ -1816,6 +1913,7 @@ static struct i2c_driver lm90_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "lm90", + .of_match_table = of_match_ptr(lm90_of_match), }, .probe = lm90_probe, .alert = lm90_alert,
Signature · 1 line
2.9.3
PATCH 12/19 hwmon: (lm95245) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/lm95245.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/hwmon/lm95245.c +8 -0
@@ -622,10 +622,18 @@ static const struct i2c_device_id lm95245_id[] = { };MODULE_DEVICE_TABLE (i2c, lm95245_id); +static const struct of_device_id lm95245_of_match[] = { + { .compatible ="national,lm95235" }, + { .compatible ="national,lm95245" }, + { }, +}; +MODULE_DEVICE_TABLE (of, lm95245_of_match); +static struct i2c_driver lm95245_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="lm95245" , + .of_match_table =of_match_ptr (lm95245_of_match), }, .probe = lm95245_probe, .id_table = lm95245_id,
Signature · 1 line
2.9.3
PATCH 13/19 hwmon: (max6697) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/max6697.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
drivers/hwmon/max6697.c +51 -1
@@ -24,6 +24,7 @@#include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/of.h> #include <linux/platform_data/max6697.h>
@@ -632,7 +633,10 @@ static int max6697_probe(struct i2c_client *client,if (!data)return -ENOMEM ; - data->type = id->driver_data; +if (client->dev.of_node) + data->type = (enum chips )of_device_get_match_data (&client->dev); +else + data->type = id->driver_data; data->chip = &max6697_chip_data[data->type]; data->client = client;mutex_init (&data->update_lock);
@@ -662,10 +666,56 @@ static const struct i2c_device_id max6697_id[] = { };MODULE_DEVICE_TABLE (i2c, max6697_id); +static const struct of_device_id max6697_of_match[] = { + { + .compatible ="maxim,max6581" , + .data = (void *)max6581 + }, + { + .compatible ="maxim,max6602" , + .data = (void *)max6602 + }, + { + .compatible ="maxim,max6622" , + .data = (void *)max6622 + }, + { + .compatible ="maxim,max6636" , + .data = (void *)max6636 + }, + { + .compatible ="maxim,max6689" , + .data = (void *)max6689 + }, + { + .compatible ="maxim,max6693" , + .data = (void *)max6693 + }, + { + .compatible ="maxim,max6694" , + .data = (void *)max6694 + }, + { + .compatible ="maxim,max6697" , + .data = (void *)max6697 + }, + { + .compatible ="maxim,max6698" , + .data = (void *)max6698 + }, + { + .compatible ="maxim,max6699" , + .data = (void *)max6699 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6697_of_match); +static struct i2c_driver max6697_driver = { .class =I2C_CLASS_HWMON , .driver = { .name ="max6697" , + .of_match_table =of_match_ptr (max6697_of_match), }, .probe = max6697_probe, .id_table = max6697_id,
Signature · 1 line
2.9.3
PATCH 14/19 hwmon: (ucd9000) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/pmbus/ucd9000.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/ucd9000.c +38 -1
@@ -21,6 +21,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/init.h> #include <linux/err.h> #include <linux/slab.h>
@@ -119,6 +120,35 @@ static const struct i2c_device_id ucd9000_id[] = { };MODULE_DEVICE_TABLE (i2c, ucd9000_id); +static const struct of_device_id ucd9000_of_match[] = { + { + .compatible ="ti,ucd9000" , + .data = (void *)ucd9000 + }, + { + .compatible ="ti,ucd90120" , + .data = (void *)ucd90120 + }, + { + .compatible ="ti,ucd90124" , + .data = (void *)ucd90124 + }, + { + .compatible ="ti,ucd90160" , + .data = (void *)ucd90160 + }, + { + .compatible ="ti,ucd9090" , + .data = (void *)ucd9090 + }, + { + .compatible ="ti,ucd90910" , + .data = (void *)ucd90910 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, ucd9000_of_match); +static int ucd9000_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -126,6 +156,7 @@ static int ucd9000_probe(struct i2c_client *client,struct ucd9000_data *data;struct pmbus_driver_info *info;const struct i2c_device_id *mid; +enum chips chip;int i, ret; if (!i2c_check_functionality(client->adapter,
@@ -151,7 +182,12 @@ static int ucd9000_probe(struct i2c_client *client,return -ENODEV ; } -if (id->driver_data != ucd9000 && id->driver_data != mid->driver_data) +if (client->dev.of_node) + chip = (enum chips )of_device_get_match_data (&client->dev); +else + chip = id->driver_data; + +if (chip != ucd9000 && chip != mid->driver_data)dev_notice (&client->dev,"Device mismatch: Configured %s, detected %s\n" , id->name, mid->name);
@@ -234,6 +270,7 @@ static int ucd9000_probe(struct i2c_client *client,static struct i2c_driver ucd9000_driver = { .driver = { .name ="ucd9000" , + .of_match_table =of_match_ptr (ucd9000_of_match), }, .probe = ucd9000_probe, .remove = pmbus_do_remove,
Signature · 1 line
2.9.3
PATCH 15/19 hwmon: (ucd9200) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/pmbus/ucd9200.c | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/ucd9200.c +47 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/init.h> #include <linux/err.h> #include <linux/slab.h>
@@ -46,12 +47,50 @@ static const struct i2c_device_id ucd9200_id[] = { };MODULE_DEVICE_TABLE (i2c, ucd9200_id); +static const struct of_device_id ucd9200_of_match[] = { + { + .compatible ="ti,cd9200" , + .data = (void *)ucd9200 + }, + { + .compatible ="ti,cd9220" , + .data = (void *)ucd9220 + }, + { + .compatible ="ti,cd9222" , + .data = (void *)ucd9222 + }, + { + .compatible ="ti,cd9224" , + .data = (void *)ucd9224 + }, + { + .compatible ="ti,cd9240" , + .data = (void *)ucd9240 + }, + { + .compatible ="ti,cd9244" , + .data = (void *)ucd9244 + }, + { + .compatible ="ti,cd9246" , + .data = (void *)ucd9246 + }, + { + .compatible ="ti,cd9248" , + .data = (void *)ucd9248 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, ucd9200_of_match); + static int ucd9200_probe(struct i2c_client *client, const struct i2c_device_id *id) { u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; struct pmbus_driver_info *info; const struct i2c_device_id *mid; + enum chips chip; int i, j, ret; if (!i2c_check_functionality(client->adapter,
@@ -76,7 +115,13 @@ static int ucd9200_probe(struct i2c_client *client,dev_err (&client->dev,"Unsupported device\n" );return -ENODEV ; } -if (id->driver_data != ucd9200 && id->driver_data != mid->driver_data) + +if (client->dev.of_node) + chip = (enum chips )of_device_get_match_data (&client->dev); +else + chip = id->driver_data; + +if (chip != ucd9200 && chip != mid->driver_data)dev_notice (&client->dev,"Device mismatch: Configured %s, detected %s\n" , id->name, mid->name);
@@ -167,6 +212,7 @@ static int ucd9200_probe(struct i2c_client *client,static struct i2c_driver ucd9200_driver = { .driver = { .name ="ucd9200" , + .of_match_table =of_match_ptr (ucd9200_of_match), }, .probe = ucd9200_probe, .remove = pmbus_do_remove,
Signature · 1 line
2.9.3
PATCH 16/19 hwmon: (stts751) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/stts751.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/stts751.c +7 -0
@@ -85,6 +85,12 @@ static const struct i2c_device_id stts751_id[] = { { } }; +static const struct of_device_id stts751_of_match[] = { + { .compatible ="stts751" }, + { }, +}; +MODULE_DEVICE_TABLE (of, stts751_of_match); +struct stts751_priv {struct device *dev;struct i2c_client *client;
@@ -819,6 +825,7 @@ static struct i2c_driver stts751_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = DEVNAME, + .of_match_table = of_match_ptr(stts751_of_match), }, .probe = stts751_probe, .id_table = stts751_id,
Signature · 1 line
2.9.3
PATCH 17/19 hwmon: (tmp102) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/tmp102.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/tmp102.c +7 -0
@@ -323,8 +323,15 @@ static const struct i2c_device_id tmp102_id[] = { };MODULE_DEVICE_TABLE (i2c, tmp102_id); +static const struct of_device_id tmp102_of_match[] = { + { .compatible ="ti,tmp102" }, + { }, +}; +MODULE_DEVICE_TABLE (of, tmp102_of_match); +static struct i2c_driver tmp102_driver = { .driver.name =DRIVER_NAME , + .driver.of_match_table =of_match_ptr (tmp102_of_match), .driver.pm = &tmp102_dev_pm_ops, .probe = tmp102_probe, .id_table = tmp102_id,
Signature · 1 line
2.9.3
PATCH 18/19 hwmon: (tmp103) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/tmp103.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwmon/tmp103.c +7 -0
@@ -183,9 +183,16 @@ static const struct i2c_device_id tmp103_id[] = { };MODULE_DEVICE_TABLE (i2c, tmp103_id); +static const struct of_device_id tmp103_of_match[] = { + { .compatible ="ti,tmp103" }, + { }, +}; +MODULE_DEVICE_TABLE (of, tmp103_of_match); +static struct i2c_driver tmp103_driver = { .driver = { .name ="tmp103" , + .of_match_table =of_match_ptr (tmp103_of_match), .pm =TMP103_DEV_PM_OPS , }, .probe = tmp103_probe,
Signature · 1 line
2.9.3
PATCH 19/19 hwmon: (tmp421) Add OF device ID table
In reply to Javier Martinez CanillasThe 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.
---
drivers/hwmon/tmp421.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/hwmon/tmp421.c +33 -2
@@ -29,6 +29,7 @@#include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/sysfs.h> /* Addresses to scan */
@@ -69,6 +70,31 @@ static const struct i2c_device_id tmp421_id[] = { };MODULE_DEVICE_TABLE (i2c, tmp421_id); +static const struct of_device_id tmp421_of_match[] = { + { + .compatible ="ti,tmp421" , + .data = (void *)2 + }, + { + .compatible ="ti,tmp422" , + .data = (void *)3 + }, + { + .compatible ="ti,tmp423" , + .data = (void *)4 + }, + { + .compatible ="ti,tmp441" , + .data = (void *)2 + }, + { + .compatible ="ti,tmp422" , + .data = (void *)3 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, tmp421_of_match); +struct tmp421_data {struct i2c_client *client;struct mutex update_lock;
@@ -78,7 +104,7 @@ struct tmp421_data {struct hwmon_chip_info chip;char valid;unsigned long last_updated; -int channels; +unsigned long channels;u8 config;s16 temp[4 ]; };
@@ -272,7 +298,11 @@ static int tmp421_probe(struct i2c_client *client,return -ENOMEM ;mutex_init (&data->update_lock); - data->channels = id->driver_data; +if (client->dev.of_node) + data->channels = (unsigned long ) +of_device_get_match_data (&client->dev); +else + data->channels = id->driver_data; data->client = client; err =tmp421_init_client (client);
@@ -301,6 +331,7 @@ static struct i2c_driver tmp421_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "tmp421", + .of_match_table = of_match_ptr(tmp421_of_match), }, .probe = tmp421_probe, .id_table = tmp421_id,
Signature · 1 line
2.9.3
Guenter Roeck
maintainerQuoted 6 lines · Javier Martinez Canillas
Hello,
This series add OF device ID tables to hwmon I2C drivers whose devices are either used in Device Tree source files or are listed in binding docs as a compatible string.
Quoted 6 lines
That's done because the plan is to change the I2C core to report proper OF modaliases instead of always reporting a MODALIAS=i2c:<foo> regardless if a device was registered via DT or using the legacy platform data.
So these patches will make sure that hwmon I2C drivers will continue to be able to module auto-load oncethe I2C core is changed.
Series applied to hwmon-next.
Thanks,
Guenter