diff options
-rw-r--r-- | drivers/hwmon/ina2xx.c | 64 |
1 files changed, 21 insertions, 43 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 70a39a8ac016..93d26e8af3e2 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c | |||
@@ -78,7 +78,7 @@ struct ina2xx_config { | |||
78 | }; | 78 | }; |
79 | 79 | ||
80 | struct ina2xx_data { | 80 | struct ina2xx_data { |
81 | struct device *hwmon_dev; | 81 | struct i2c_client *client; |
82 | const struct ina2xx_config *config; | 82 | const struct ina2xx_config *config; |
83 | 83 | ||
84 | struct mutex update_lock; | 84 | struct mutex update_lock; |
@@ -112,8 +112,8 @@ static const struct ina2xx_config ina2xx_config[] = { | |||
112 | 112 | ||
113 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) | 113 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) |
114 | { | 114 | { |
115 | struct i2c_client *client = to_i2c_client(dev); | 115 | struct ina2xx_data *data = dev_get_drvdata(dev); |
116 | struct ina2xx_data *data = i2c_get_clientdata(client); | 116 | struct i2c_client *client = data->client; |
117 | struct ina2xx_data *ret = data; | 117 | struct ina2xx_data *ret = data; |
118 | 118 | ||
119 | mutex_lock(&data->update_lock); | 119 | mutex_lock(&data->update_lock); |
@@ -203,41 +203,39 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL, | |||
203 | INA2XX_POWER); | 203 | INA2XX_POWER); |
204 | 204 | ||
205 | /* pointers to created device attributes */ | 205 | /* pointers to created device attributes */ |
206 | static struct attribute *ina2xx_attributes[] = { | 206 | static struct attribute *ina2xx_attrs[] = { |
207 | &sensor_dev_attr_in0_input.dev_attr.attr, | 207 | &sensor_dev_attr_in0_input.dev_attr.attr, |
208 | &sensor_dev_attr_in1_input.dev_attr.attr, | 208 | &sensor_dev_attr_in1_input.dev_attr.attr, |
209 | &sensor_dev_attr_curr1_input.dev_attr.attr, | 209 | &sensor_dev_attr_curr1_input.dev_attr.attr, |
210 | &sensor_dev_attr_power1_input.dev_attr.attr, | 210 | &sensor_dev_attr_power1_input.dev_attr.attr, |
211 | NULL, | 211 | NULL, |
212 | }; | 212 | }; |
213 | 213 | ATTRIBUTE_GROUPS(ina2xx); | |
214 | static const struct attribute_group ina2xx_group = { | ||
215 | .attrs = ina2xx_attributes, | ||
216 | }; | ||
217 | 214 | ||
218 | static int ina2xx_probe(struct i2c_client *client, | 215 | static int ina2xx_probe(struct i2c_client *client, |
219 | const struct i2c_device_id *id) | 216 | const struct i2c_device_id *id) |
220 | { | 217 | { |
221 | struct i2c_adapter *adapter = client->adapter; | 218 | struct i2c_adapter *adapter = client->adapter; |
222 | struct ina2xx_data *data; | ||
223 | struct ina2xx_platform_data *pdata; | 219 | struct ina2xx_platform_data *pdata; |
224 | int ret; | 220 | struct device *dev = &client->dev; |
225 | u32 val; | 221 | struct ina2xx_data *data; |
222 | struct device *hwmon_dev; | ||
226 | long shunt = 10000; /* default shunt value 10mOhms */ | 223 | long shunt = 10000; /* default shunt value 10mOhms */ |
224 | u32 val; | ||
227 | 225 | ||
228 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) | 226 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) |
229 | return -ENODEV; | 227 | return -ENODEV; |
230 | 228 | ||
231 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 229 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
232 | if (!data) | 230 | if (!data) |
233 | return -ENOMEM; | 231 | return -ENOMEM; |
234 | 232 | ||
235 | if (dev_get_platdata(&client->dev)) { | 233 | if (dev_get_platdata(dev)) { |
236 | pdata = dev_get_platdata(&client->dev); | 234 | pdata = dev_get_platdata(dev); |
237 | shunt = pdata->shunt_uohms; | 235 | shunt = pdata->shunt_uohms; |
238 | } else if (!of_property_read_u32(client->dev.of_node, | 236 | } else if (!of_property_read_u32(dev->of_node, |
239 | "shunt-resistor", &val)) { | 237 | "shunt-resistor", &val)) { |
240 | shunt = val; | 238 | shunt = val; |
241 | } | 239 | } |
242 | 240 | ||
243 | if (shunt <= 0) | 241 | if (shunt <= 0) |
@@ -255,37 +253,18 @@ static int ina2xx_probe(struct i2c_client *client, | |||
255 | i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, | 253 | i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, |
256 | data->config->calibration_factor / shunt); | 254 | data->config->calibration_factor / shunt); |
257 | 255 | ||
258 | i2c_set_clientdata(client, data); | 256 | data->client = client; |
259 | mutex_init(&data->update_lock); | 257 | mutex_init(&data->update_lock); |
260 | 258 | ||
261 | ret = sysfs_create_group(&client->dev.kobj, &ina2xx_group); | 259 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
262 | if (ret) | 260 | data, ina2xx_groups); |
263 | return ret; | 261 | if (IS_ERR(hwmon_dev)) |
264 | 262 | return PTR_ERR(hwmon_dev); | |
265 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
266 | if (IS_ERR(data->hwmon_dev)) { | ||
267 | ret = PTR_ERR(data->hwmon_dev); | ||
268 | goto out_err_hwmon; | ||
269 | } | ||
270 | 263 | ||
271 | dev_info(&client->dev, "power monitor %s (Rshunt = %li uOhm)\n", | 264 | dev_info(dev, "power monitor %s (Rshunt = %li uOhm)\n", |
272 | id->name, shunt); | 265 | id->name, shunt); |
273 | 266 | ||
274 | return 0; | 267 | return 0; |
275 | |||
276 | out_err_hwmon: | ||
277 | sysfs_remove_group(&client->dev.kobj, &ina2xx_group); | ||
278 | return ret; | ||
279 | } | ||
280 | |||
281 | static int ina2xx_remove(struct i2c_client *client) | ||
282 | { | ||
283 | struct ina2xx_data *data = i2c_get_clientdata(client); | ||
284 | |||
285 | hwmon_device_unregister(data->hwmon_dev); | ||
286 | sysfs_remove_group(&client->dev.kobj, &ina2xx_group); | ||
287 | |||
288 | return 0; | ||
289 | } | 268 | } |
290 | 269 | ||
291 | static const struct i2c_device_id ina2xx_id[] = { | 270 | static const struct i2c_device_id ina2xx_id[] = { |
@@ -302,7 +281,6 @@ static struct i2c_driver ina2xx_driver = { | |||
302 | .name = "ina2xx", | 281 | .name = "ina2xx", |
303 | }, | 282 | }, |
304 | .probe = ina2xx_probe, | 283 | .probe = ina2xx_probe, |
305 | .remove = ina2xx_remove, | ||
306 | .id_table = ina2xx_id, | 284 | .id_table = ina2xx_id, |
307 | }; | 285 | }; |
308 | 286 | ||