summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ads7828.c
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javier@osg.samsung.com>2017-02-24 08:12:57 -0500
committerGuenter Roeck <linux@roeck-us.net>2017-04-02 10:01:53 -0400
commit2d688f1413aba35b3861a1d709a98693a5b0b58f (patch)
tree3e042320f08804249c8a571bbadd983f16d096ae /drivers/hwmon/ads7828.c
parenta140986fd0708607dbbd6321386964e44fef59a2 (diff)
hwmon: (ads7828) 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>
Diffstat (limited to 'drivers/hwmon/ads7828.c')
-rw-r--r--drivers/hwmon/ads7828.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index ee396ff167d9..b0ef66687816 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -31,6 +31,7 @@
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/of_device.h>
34#include <linux/platform_data/ads7828.h> 35#include <linux/platform_data/ads7828.h>
35#include <linux/regmap.h> 36#include <linux/regmap.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
@@ -121,6 +122,7 @@ static int ads7828_probe(struct i2c_client *client,
121 bool diff_input = false; 122 bool diff_input = false;
122 bool ext_vref = false; 123 bool ext_vref = false;
123 unsigned int regval; 124 unsigned int regval;
125 enum ads7828_chips chip;
124 126
125 data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); 127 data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
126 if (!data) 128 if (!data)
@@ -133,12 +135,18 @@ static int ads7828_probe(struct i2c_client *client,
133 vref_mv = pdata->vref_mv; 135 vref_mv = pdata->vref_mv;
134 } 136 }
135 137
138 if (client->dev.of_node)
139 chip = (enum ads7828_chips)
140 of_device_get_match_data(&client->dev);
141 else
142 chip = id->driver_data;
143
136 /* Bound Vref with min/max values */ 144 /* Bound Vref with min/max values */
137 vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN, 145 vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN,
138 ADS7828_EXT_VREF_MV_MAX); 146 ADS7828_EXT_VREF_MV_MAX);
139 147
140 /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ 148 /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */
141 if (id->driver_data == ads7828) { 149 if (chip == ads7828) {
142 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 4096); 150 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 4096);
143 data->regmap = devm_regmap_init_i2c(client, 151 data->regmap = devm_regmap_init_i2c(client,
144 &ads2828_regmap_config); 152 &ads2828_regmap_config);
@@ -177,9 +185,23 @@ static const struct i2c_device_id ads7828_device_ids[] = {
177}; 185};
178MODULE_DEVICE_TABLE(i2c, ads7828_device_ids); 186MODULE_DEVICE_TABLE(i2c, ads7828_device_ids);
179 187
188static const struct of_device_id ads7828_of_match[] = {
189 {
190 .compatible = "ti,ads7828",
191 .data = (void *)ads7828
192 },
193 {
194 .compatible = "ti,ads7830",
195 .data = (void *)ads7830
196 },
197 { },
198};
199MODULE_DEVICE_TABLE(of, ads7828_of_match);
200
180static struct i2c_driver ads7828_driver = { 201static struct i2c_driver ads7828_driver = {
181 .driver = { 202 .driver = {
182 .name = "ads7828", 203 .name = "ads7828",
204 .of_match_table = of_match_ptr(ads7828_of_match),
183 }, 205 },
184 206
185 .id_table = ads7828_device_ids, 207 .id_table = ads7828_device_ids,