aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-12 12:25:25 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:21 -0400
commit5975dfbf40bfb342db1b25a9b1e2c3b867773612 (patch)
tree098dad4c3dc2db4f21f6ac8610ae38cb5a93484d
parent48dbd6ff142d518e01888d2addfab731ff65460e (diff)
hwmon: (lm77) Convert to use devm_hwmon_device_register_with_groups
Use devm_hwmon_device_register_with_groups API to attach attributes to hwmon device, simplify code, and reduce code size. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/lm77.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index ab1752a5b46f..5ceb443b938d 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -62,7 +62,7 @@ static const u8 temp_regs[t_num_temp] = {
62 62
63/* Each client has this additional data */ 63/* Each client has this additional data */
64struct lm77_data { 64struct lm77_data {
65 struct device *hwmon_dev; 65 struct i2c_client *client;
66 struct mutex update_lock; 66 struct mutex update_lock;
67 char valid; 67 char valid;
68 unsigned long last_updated; /* In jiffies */ 68 unsigned long last_updated; /* In jiffies */
@@ -111,8 +111,8 @@ static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
111 111
112static struct lm77_data *lm77_update_device(struct device *dev) 112static struct lm77_data *lm77_update_device(struct device *dev)
113{ 113{
114 struct i2c_client *client = to_i2c_client(dev); 114 struct lm77_data *data = dev_get_drvdata(dev);
115 struct lm77_data *data = i2c_get_clientdata(client); 115 struct i2c_client *client = data->client;
116 int i; 116 int i;
117 117
118 mutex_lock(&data->update_lock); 118 mutex_lock(&data->update_lock);
@@ -165,8 +165,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
165 const char *buf, size_t count) 165 const char *buf, size_t count)
166{ 166{
167 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 167 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
168 struct i2c_client *client = to_i2c_client(dev); 168 struct lm77_data *data = dev_get_drvdata(dev);
169 struct lm77_data *data = i2c_get_clientdata(client); 169 struct i2c_client *client = data->client;
170 int nr = attr->index; 170 int nr = attr->index;
171 long val; 171 long val;
172 int err; 172 int err;
@@ -190,8 +190,8 @@ static ssize_t set_temp_hyst(struct device *dev,
190 struct device_attribute *devattr, 190 struct device_attribute *devattr,
191 const char *buf, size_t count) 191 const char *buf, size_t count)
192{ 192{
193 struct i2c_client *client = to_i2c_client(dev); 193 struct lm77_data *data = dev_get_drvdata(dev);
194 struct lm77_data *data = i2c_get_clientdata(client); 194 struct i2c_client *client = data->client;
195 unsigned long val; 195 unsigned long val;
196 int err; 196 int err;
197 197
@@ -232,7 +232,7 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
232static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 232static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
233static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); 233static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
234 234
235static struct attribute *lm77_attributes[] = { 235static struct attribute *lm77_attrs[] = {
236 &sensor_dev_attr_temp1_input.dev_attr.attr, 236 &sensor_dev_attr_temp1_input.dev_attr.attr,
237 &sensor_dev_attr_temp1_crit.dev_attr.attr, 237 &sensor_dev_attr_temp1_crit.dev_attr.attr,
238 &sensor_dev_attr_temp1_min.dev_attr.attr, 238 &sensor_dev_attr_temp1_min.dev_attr.attr,
@@ -245,10 +245,7 @@ static struct attribute *lm77_attributes[] = {
245 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 245 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
246 NULL 246 NULL
247}; 247};
248 248ATTRIBUTE_GROUPS(lm77);
249static const struct attribute_group lm77_group = {
250 .attrs = lm77_attributes,
251};
252 249
253/* Return 0 if detection is successful, -ENODEV otherwise */ 250/* Return 0 if detection is successful, -ENODEV otherwise */
254static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info) 251static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info)
@@ -332,43 +329,22 @@ static void lm77_init_client(struct i2c_client *client)
332static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id) 329static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id)
333{ 330{
334 struct device *dev = &client->dev; 331 struct device *dev = &client->dev;
332 struct device *hwmon_dev;
335 struct lm77_data *data; 333 struct lm77_data *data;
336 int err;
337 334
338 data = devm_kzalloc(dev, sizeof(struct lm77_data), GFP_KERNEL); 335 data = devm_kzalloc(dev, sizeof(struct lm77_data), GFP_KERNEL);
339 if (!data) 336 if (!data)
340 return -ENOMEM; 337 return -ENOMEM;
341 338
342 i2c_set_clientdata(client, data); 339 data->client = client;
343 mutex_init(&data->update_lock); 340 mutex_init(&data->update_lock);
344 341
345 /* Initialize the LM77 chip */ 342 /* Initialize the LM77 chip */
346 lm77_init_client(client); 343 lm77_init_client(client);
347 344
348 /* Register sysfs hooks */ 345 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
349 err = sysfs_create_group(&dev->kobj, &lm77_group); 346 data, lm77_groups);
350 if (err) 347 return PTR_ERR_OR_ZERO(hwmon_dev);
351 return err;
352
353 data->hwmon_dev = hwmon_device_register(dev);
354 if (IS_ERR(data->hwmon_dev)) {
355 err = PTR_ERR(data->hwmon_dev);
356 goto exit_remove;
357 }
358
359 return 0;
360
361exit_remove:
362 sysfs_remove_group(&dev->kobj, &lm77_group);
363 return err;
364}
365
366static int lm77_remove(struct i2c_client *client)
367{
368 struct lm77_data *data = i2c_get_clientdata(client);
369 hwmon_device_unregister(data->hwmon_dev);
370 sysfs_remove_group(&client->dev.kobj, &lm77_group);
371 return 0;
372} 348}
373 349
374static const struct i2c_device_id lm77_id[] = { 350static const struct i2c_device_id lm77_id[] = {
@@ -384,7 +360,6 @@ static struct i2c_driver lm77_driver = {
384 .name = "lm77", 360 .name = "lm77",
385 }, 361 },
386 .probe = lm77_probe, 362 .probe = lm77_probe,
387 .remove = lm77_remove,
388 .id_table = lm77_id, 363 .id_table = lm77_id,
389 .detect = lm77_detect, 364 .detect = lm77_detect,
390 .address_list = normal_i2c, 365 .address_list = normal_i2c,