aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ltc4215.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-02-16 01:05:17 -0500
committerGuenter Roeck <linux@roeck-us.net>2014-03-03 11:01:05 -0500
commit6c588b45b0d4005814cd3188f47db621b929c922 (patch)
tree4ac6d535f58dad555f2bf9ae29811fbdc8068cbb /drivers/hwmon/ltc4215.c
parentd72d19c26c417d514787ae85b197af34de286c0a (diff)
hwmon: (ltc4215) Convert to devm_hwmon_device_register_with_groups
Simplify code, reduce code size, and attach sysfs attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'drivers/hwmon/ltc4215.c')
-rw-r--r--drivers/hwmon/ltc4215.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c
index 8a142960d69e..c8a9bd9b050f 100644
--- a/drivers/hwmon/ltc4215.c
+++ b/drivers/hwmon/ltc4215.c
@@ -33,7 +33,7 @@ enum ltc4215_cmd {
33}; 33};
34 34
35struct ltc4215_data { 35struct ltc4215_data {
36 struct device *hwmon_dev; 36 struct i2c_client *client;
37 37
38 struct mutex update_lock; 38 struct mutex update_lock;
39 bool valid; 39 bool valid;
@@ -45,8 +45,8 @@ struct ltc4215_data {
45 45
46static struct ltc4215_data *ltc4215_update_device(struct device *dev) 46static struct ltc4215_data *ltc4215_update_device(struct device *dev)
47{ 47{
48 struct i2c_client *client = to_i2c_client(dev); 48 struct ltc4215_data *data = dev_get_drvdata(dev);
49 struct ltc4215_data *data = i2c_get_clientdata(client); 49 struct i2c_client *client = data->client;
50 s32 val; 50 s32 val;
51 int i; 51 int i;
52 52
@@ -214,7 +214,7 @@ static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
214 * Finally, construct an array of pointers to members of the above objects, 214 * Finally, construct an array of pointers to members of the above objects,
215 * as required for sysfs_create_group() 215 * as required for sysfs_create_group()
216 */ 216 */
217static struct attribute *ltc4215_attributes[] = { 217static struct attribute *ltc4215_attrs[] = {
218 &sensor_dev_attr_curr1_input.dev_attr.attr, 218 &sensor_dev_attr_curr1_input.dev_attr.attr,
219 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, 219 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
220 220
@@ -229,57 +229,33 @@ static struct attribute *ltc4215_attributes[] = {
229 229
230 NULL, 230 NULL,
231}; 231};
232 232ATTRIBUTE_GROUPS(ltc4215);
233static const struct attribute_group ltc4215_group = {
234 .attrs = ltc4215_attributes,
235};
236 233
237static int ltc4215_probe(struct i2c_client *client, 234static int ltc4215_probe(struct i2c_client *client,
238 const struct i2c_device_id *id) 235 const struct i2c_device_id *id)
239{ 236{
240 struct i2c_adapter *adapter = client->adapter; 237 struct i2c_adapter *adapter = client->adapter;
238 struct device *dev = &client->dev;
241 struct ltc4215_data *data; 239 struct ltc4215_data *data;
242 int ret; 240 struct device *hwmon_dev;
243 241
244 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 242 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
245 return -ENODEV; 243 return -ENODEV;
246 244
247 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 245 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
248 if (!data) 246 if (!data)
249 return -ENOMEM; 247 return -ENOMEM;
250 248
251 i2c_set_clientdata(client, data); 249 data->client = client;
252 mutex_init(&data->update_lock); 250 mutex_init(&data->update_lock);
253 251
254 /* Initialize the LTC4215 chip */ 252 /* Initialize the LTC4215 chip */
255 i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00); 253 i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00);
256 254
257 /* Register sysfs hooks */ 255 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
258 ret = sysfs_create_group(&client->dev.kobj, &ltc4215_group); 256 data,
259 if (ret) 257 ltc4215_groups);
260 return ret; 258 return PTR_ERR_OR_ZERO(hwmon_dev);
261
262 data->hwmon_dev = hwmon_device_register(&client->dev);
263 if (IS_ERR(data->hwmon_dev)) {
264 ret = PTR_ERR(data->hwmon_dev);
265 goto out_hwmon_device_register;
266 }
267
268 return 0;
269
270out_hwmon_device_register:
271 sysfs_remove_group(&client->dev.kobj, &ltc4215_group);
272 return ret;
273}
274
275static int ltc4215_remove(struct i2c_client *client)
276{
277 struct ltc4215_data *data = i2c_get_clientdata(client);
278
279 hwmon_device_unregister(data->hwmon_dev);
280 sysfs_remove_group(&client->dev.kobj, &ltc4215_group);
281
282 return 0;
283} 259}
284 260
285static const struct i2c_device_id ltc4215_id[] = { 261static const struct i2c_device_id ltc4215_id[] = {
@@ -294,7 +270,6 @@ static struct i2c_driver ltc4215_driver = {
294 .name = "ltc4215", 270 .name = "ltc4215",
295 }, 271 },
296 .probe = ltc4215_probe, 272 .probe = ltc4215_probe,
297 .remove = ltc4215_remove,
298 .id_table = ltc4215_id, 273 .id_table = ltc4215_id,
299}; 274};
300 275