aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-01-20 12:17:16 -0500
committerGuenter Roeck <linux@roeck-us.net>2014-03-03 11:01:06 -0500
commit7276d55e62f79f2b81d2c414e48de43edea5aa78 (patch)
tree0ff3ac068c385fc90ff818e29fa28773ceb30a16
parentce50e7faf115b292725b73d7dfb8188b2d577887 (diff)
hwmon: (lm95245) Convert to use devm_hwmon_device_register_with_groups
Simplify code, reduce code size, and attach hwmon attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r--drivers/hwmon/lm95245.c80
1 files changed, 26 insertions, 54 deletions
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
index 07d69dc8d44e..acf36794e7e3 100644
--- a/drivers/hwmon/lm95245.c
+++ b/drivers/hwmon/lm95245.c
@@ -115,7 +115,7 @@ static const u8 lm95245_reg_address[] = {
115 115
116/* Client data (each client gets its own) */ 116/* Client data (each client gets its own) */
117struct lm95245_data { 117struct lm95245_data {
118 struct device *hwmon_dev; 118 struct i2c_client *client;
119 struct mutex update_lock; 119 struct mutex update_lock;
120 unsigned long last_updated; /* in jiffies */ 120 unsigned long last_updated; /* in jiffies */
121 unsigned long interval; /* in msecs */ 121 unsigned long interval; /* in msecs */
@@ -140,8 +140,8 @@ static int temp_from_reg_signed(u8 val_h, u8 val_l)
140 140
141static struct lm95245_data *lm95245_update_device(struct device *dev) 141static struct lm95245_data *lm95245_update_device(struct device *dev)
142{ 142{
143 struct i2c_client *client = to_i2c_client(dev); 143 struct lm95245_data *data = dev_get_drvdata(dev);
144 struct lm95245_data *data = i2c_get_clientdata(client); 144 struct i2c_client *client = data->client;
145 145
146 mutex_lock(&data->update_lock); 146 mutex_lock(&data->update_lock);
147 147
@@ -248,9 +248,9 @@ static ssize_t show_limit(struct device *dev, struct device_attribute *attr,
248static ssize_t set_limit(struct device *dev, struct device_attribute *attr, 248static ssize_t set_limit(struct device *dev, struct device_attribute *attr,
249 const char *buf, size_t count) 249 const char *buf, size_t count)
250{ 250{
251 struct i2c_client *client = to_i2c_client(dev); 251 struct lm95245_data *data = dev_get_drvdata(dev);
252 struct lm95245_data *data = i2c_get_clientdata(client);
253 int index = to_sensor_dev_attr(attr)->index; 252 int index = to_sensor_dev_attr(attr)->index;
253 struct i2c_client *client = data->client;
254 unsigned long val; 254 unsigned long val;
255 255
256 if (kstrtoul(buf, 10, &val) < 0) 256 if (kstrtoul(buf, 10, &val) < 0)
@@ -284,9 +284,9 @@ static ssize_t show_crit_hyst(struct device *dev, struct device_attribute *attr,
284static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, 284static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
285 const char *buf, size_t count) 285 const char *buf, size_t count)
286{ 286{
287 struct i2c_client *client = to_i2c_client(dev); 287 struct lm95245_data *data = dev_get_drvdata(dev);
288 struct lm95245_data *data = i2c_get_clientdata(client);
289 int index = to_sensor_dev_attr(attr)->index; 288 int index = to_sensor_dev_attr(attr)->index;
289 struct i2c_client *client = data->client;
290 unsigned long val; 290 unsigned long val;
291 int hyst, limit; 291 int hyst, limit;
292 292
@@ -312,8 +312,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
312static ssize_t show_type(struct device *dev, struct device_attribute *attr, 312static ssize_t show_type(struct device *dev, struct device_attribute *attr,
313 char *buf) 313 char *buf)
314{ 314{
315 struct i2c_client *client = to_i2c_client(dev); 315 struct lm95245_data *data = dev_get_drvdata(dev);
316 struct lm95245_data *data = i2c_get_clientdata(client);
317 316
318 return snprintf(buf, PAGE_SIZE - 1, 317 return snprintf(buf, PAGE_SIZE - 1,
319 data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n"); 318 data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n");
@@ -322,8 +321,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr,
322static ssize_t set_type(struct device *dev, struct device_attribute *attr, 321static ssize_t set_type(struct device *dev, struct device_attribute *attr,
323 const char *buf, size_t count) 322 const char *buf, size_t count)
324{ 323{
325 struct i2c_client *client = to_i2c_client(dev); 324 struct lm95245_data *data = dev_get_drvdata(dev);
326 struct lm95245_data *data = i2c_get_clientdata(client); 325 struct i2c_client *client = data->client;
327 unsigned long val; 326 unsigned long val;
328 327
329 if (kstrtoul(buf, 10, &val) < 0) 328 if (kstrtoul(buf, 10, &val) < 0)
@@ -369,8 +368,8 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
369static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 368static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
370 const char *buf, size_t count) 369 const char *buf, size_t count)
371{ 370{
372 struct i2c_client *client = to_i2c_client(dev); 371 struct lm95245_data *data = dev_get_drvdata(dev);
373 struct lm95245_data *data = i2c_get_clientdata(client); 372 struct i2c_client *client = data->client;
374 unsigned long val; 373 unsigned long val;
375 374
376 if (kstrtoul(buf, 10, &val) < 0) 375 if (kstrtoul(buf, 10, &val) < 0)
@@ -408,7 +407,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL,
408static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 407static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
409 set_interval); 408 set_interval);
410 409
411static struct attribute *lm95245_attributes[] = { 410static struct attribute *lm95245_attrs[] = {
412 &sensor_dev_attr_temp1_input.dev_attr.attr, 411 &sensor_dev_attr_temp1_input.dev_attr.attr,
413 &sensor_dev_attr_temp1_crit.dev_attr.attr, 412 &sensor_dev_attr_temp1_crit.dev_attr.attr,
414 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, 413 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
@@ -422,10 +421,7 @@ static struct attribute *lm95245_attributes[] = {
422 &dev_attr_update_interval.attr, 421 &dev_attr_update_interval.attr,
423 NULL 422 NULL
424}; 423};
425 424ATTRIBUTE_GROUPS(lm95245);
426static const struct attribute_group lm95245_group = {
427 .attrs = lm95245_attributes,
428};
429 425
430/* Return 0 if detection is successful, -ENODEV otherwise */ 426/* Return 0 if detection is successful, -ENODEV otherwise */
431static int lm95245_detect(struct i2c_client *new_client, 427static int lm95245_detect(struct i2c_client *new_client,
@@ -446,10 +442,9 @@ static int lm95245_detect(struct i2c_client *new_client,
446 return 0; 442 return 0;
447} 443}
448 444
449static void lm95245_init_client(struct i2c_client *client) 445static void lm95245_init_client(struct i2c_client *client,
446 struct lm95245_data *data)
450{ 447{
451 struct lm95245_data *data = i2c_get_clientdata(client);
452
453 data->interval = lm95245_read_conversion_rate(client); 448 data->interval = lm95245_read_conversion_rate(client);
454 449
455 data->config1 = i2c_smbus_read_byte_data(client, 450 data->config1 = i2c_smbus_read_byte_data(client,
@@ -465,49 +460,27 @@ static void lm95245_init_client(struct i2c_client *client)
465 } 460 }
466} 461}
467 462
468static int lm95245_probe(struct i2c_client *new_client, 463static int lm95245_probe(struct i2c_client *client,
469 const struct i2c_device_id *id) 464 const struct i2c_device_id *id)
470{ 465{
466 struct device *dev = &client->dev;
471 struct lm95245_data *data; 467 struct lm95245_data *data;
472 int err; 468 struct device *hwmon_dev;
473 469
474 data = devm_kzalloc(&new_client->dev, sizeof(struct lm95245_data), 470 data = devm_kzalloc(dev, sizeof(struct lm95245_data), GFP_KERNEL);
475 GFP_KERNEL);
476 if (!data) 471 if (!data)
477 return -ENOMEM; 472 return -ENOMEM;
478 473
479 i2c_set_clientdata(new_client, data); 474 data->client = client;
480 mutex_init(&data->update_lock); 475 mutex_init(&data->update_lock);
481 476
482 /* Initialize the LM95245 chip */ 477 /* Initialize the LM95245 chip */
483 lm95245_init_client(new_client); 478 lm95245_init_client(client, data);
484
485 /* Register sysfs hooks */
486 err = sysfs_create_group(&new_client->dev.kobj, &lm95245_group);
487 if (err)
488 return err;
489
490 data->hwmon_dev = hwmon_device_register(&new_client->dev);
491 if (IS_ERR(data->hwmon_dev)) {
492 err = PTR_ERR(data->hwmon_dev);
493 goto exit_remove_files;
494 }
495 479
496 return 0; 480 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
497 481 data,
498exit_remove_files: 482 lm95245_groups);
499 sysfs_remove_group(&new_client->dev.kobj, &lm95245_group); 483 return PTR_ERR_OR_ZERO(hwmon_dev);
500 return err;
501}
502
503static int lm95245_remove(struct i2c_client *client)
504{
505 struct lm95245_data *data = i2c_get_clientdata(client);
506
507 hwmon_device_unregister(data->hwmon_dev);
508 sysfs_remove_group(&client->dev.kobj, &lm95245_group);
509
510 return 0;
511} 484}
512 485
513/* Driver data (common to all clients) */ 486/* Driver data (common to all clients) */
@@ -523,7 +496,6 @@ static struct i2c_driver lm95245_driver = {
523 .name = DEVNAME, 496 .name = DEVNAME,
524 }, 497 },
525 .probe = lm95245_probe, 498 .probe = lm95245_probe,
526 .remove = lm95245_remove,
527 .id_table = lm95245_id, 499 .id_table = lm95245_id,
528 .detect = lm95245_detect, 500 .detect = lm95245_detect,
529 .address_list = normal_i2c, 501 .address_list = normal_i2c,