aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/smsc47m1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/smsc47m1.c')
-rw-r--r--drivers/hwmon/smsc47m1.c81
1 files changed, 62 insertions, 19 deletions
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 6c81b843d831..47132fd26b1b 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38#include <linux/sysfs.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40/* Address is autodetected, there is no default value */ 41/* Address is autodetected, there is no default value */
@@ -347,6 +348,30 @@ fan_present(2);
347 348
348static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); 349static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
349 350
351/* Almost all sysfs files may or may not be created depending on the chip
352 setup so we create them individually. It is still convenient to define a
353 group to remove them all at once. */
354static struct attribute *smsc47m1_attributes[] = {
355 &dev_attr_fan1_input.attr,
356 &dev_attr_fan1_min.attr,
357 &dev_attr_fan1_div.attr,
358 &dev_attr_fan2_input.attr,
359 &dev_attr_fan2_min.attr,
360 &dev_attr_fan2_div.attr,
361
362 &dev_attr_pwm1.attr,
363 &dev_attr_pwm1_enable.attr,
364 &dev_attr_pwm2.attr,
365 &dev_attr_pwm2_enable.attr,
366
367 &dev_attr_alarms.attr,
368 NULL
369};
370
371static const struct attribute_group smsc47m1_group = {
372 .attrs = smsc47m1_attributes,
373};
374
350static int __init smsc47m1_find(unsigned short *addr) 375static int __init smsc47m1_find(unsigned short *addr)
351{ 376{
352 u8 val; 377 u8 val;
@@ -429,7 +454,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
429 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05) 454 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05)
430 == 0x04; 455 == 0x04;
431 if (!(fan1 || fan2 || pwm1 || pwm2)) { 456 if (!(fan1 || fan2 || pwm1 || pwm2)) {
432 dev_warn(&new_client->dev, "Device is not configured, will not use\n"); 457 dev_warn(&adapter->dev, "Device at 0x%x is not configured, "
458 "will not use\n", new_client->addr);
433 err = -ENODEV; 459 err = -ENODEV;
434 goto error_free; 460 goto error_free;
435 } 461 }
@@ -446,46 +472,62 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
446 smsc47m1_update_device(&new_client->dev, 1); 472 smsc47m1_update_device(&new_client->dev, 1);
447 473
448 /* Register sysfs hooks */ 474 /* Register sysfs hooks */
449 data->class_dev = hwmon_device_register(&new_client->dev);
450 if (IS_ERR(data->class_dev)) {
451 err = PTR_ERR(data->class_dev);
452 goto error_detach;
453 }
454
455 if (fan1) { 475 if (fan1) {
456 device_create_file(&new_client->dev, &dev_attr_fan1_input); 476 if ((err = device_create_file(&new_client->dev,
457 device_create_file(&new_client->dev, &dev_attr_fan1_min); 477 &dev_attr_fan1_input))
458 device_create_file(&new_client->dev, &dev_attr_fan1_div); 478 || (err = device_create_file(&new_client->dev,
479 &dev_attr_fan1_min))
480 || (err = device_create_file(&new_client->dev,
481 &dev_attr_fan1_div)))
482 goto error_remove_files;
459 } else 483 } else
460 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, " 484 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, "
461 "skipping\n"); 485 "skipping\n");
462 486
463 if (fan2) { 487 if (fan2) {
464 device_create_file(&new_client->dev, &dev_attr_fan2_input); 488 if ((err = device_create_file(&new_client->dev,
465 device_create_file(&new_client->dev, &dev_attr_fan2_min); 489 &dev_attr_fan2_input))
466 device_create_file(&new_client->dev, &dev_attr_fan2_div); 490 || (err = device_create_file(&new_client->dev,
491 &dev_attr_fan2_min))
492 || (err = device_create_file(&new_client->dev,
493 &dev_attr_fan2_div)))
494 goto error_remove_files;
467 } else 495 } else
468 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, " 496 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, "
469 "skipping\n"); 497 "skipping\n");
470 498
471 if (pwm1) { 499 if (pwm1) {
472 device_create_file(&new_client->dev, &dev_attr_pwm1); 500 if ((err = device_create_file(&new_client->dev,
473 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); 501 &dev_attr_pwm1))
502 || (err = device_create_file(&new_client->dev,
503 &dev_attr_pwm1_enable)))
504 goto error_remove_files;
474 } else 505 } else
475 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, " 506 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, "
476 "skipping\n"); 507 "skipping\n");
477 if (pwm2) { 508 if (pwm2) {
478 device_create_file(&new_client->dev, &dev_attr_pwm2); 509 if ((err = device_create_file(&new_client->dev,
479 device_create_file(&new_client->dev, &dev_attr_pwm2_enable); 510 &dev_attr_pwm2))
511 || (err = device_create_file(&new_client->dev,
512 &dev_attr_pwm2_enable)))
513 goto error_remove_files;
480 } else 514 } else
481 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, " 515 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, "
482 "skipping\n"); 516 "skipping\n");
483 517
484 device_create_file(&new_client->dev, &dev_attr_alarms); 518 if ((err = device_create_file(&new_client->dev, &dev_attr_alarms)))
519 goto error_remove_files;
520
521 data->class_dev = hwmon_device_register(&new_client->dev);
522 if (IS_ERR(data->class_dev)) {
523 err = PTR_ERR(data->class_dev);
524 goto error_remove_files;
525 }
485 526
486 return 0; 527 return 0;
487 528
488error_detach: 529error_remove_files:
530 sysfs_remove_group(&new_client->dev.kobj, &smsc47m1_group);
489 i2c_detach_client(new_client); 531 i2c_detach_client(new_client);
490error_free: 532error_free:
491 kfree(data); 533 kfree(data);
@@ -500,6 +542,7 @@ static int smsc47m1_detach_client(struct i2c_client *client)
500 int err; 542 int err;
501 543
502 hwmon_device_unregister(data->class_dev); 544 hwmon_device_unregister(data->class_dev);
545 sysfs_remove_group(&client->dev.kobj, &smsc47m1_group);
503 546
504 if ((err = i2c_detach_client(client))) 547 if ((err = i2c_detach_client(client)))
505 return err; 548 return err;