diff options
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r-- | drivers/hwmon/lm90.c | 90 |
1 files changed, 63 insertions, 27 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index d9eeaf7585bd..6882ce75feee 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | 3 | * monitoring |
4 | * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Based on the lm83 driver. The LM90 is a sensor chip made by National | 6 | * Based on the lm83 driver. The LM90 is a sensor chip made by National |
7 | * Semiconductor. It reports up to two temperatures (its own plus up to | 7 | * Semiconductor. It reports up to two temperatures (its own plus up to |
@@ -79,6 +79,7 @@ | |||
79 | #include <linux/hwmon.h> | 79 | #include <linux/hwmon.h> |
80 | #include <linux/err.h> | 80 | #include <linux/err.h> |
81 | #include <linux/mutex.h> | 81 | #include <linux/mutex.h> |
82 | #include <linux/sysfs.h> | ||
82 | 83 | ||
83 | /* | 84 | /* |
84 | * Addresses to scan | 85 | * Addresses to scan |
@@ -327,6 +328,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, | |||
327 | return sprintf(buf, "%d\n", data->alarms); | 328 | return sprintf(buf, "%d\n", data->alarms); |
328 | } | 329 | } |
329 | 330 | ||
331 | static ssize_t show_alarm(struct device *dev, struct device_attribute | ||
332 | *devattr, char *buf) | ||
333 | { | ||
334 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
335 | struct lm90_data *data = lm90_update_device(dev); | ||
336 | int bitnr = attr->index; | ||
337 | |||
338 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | ||
339 | } | ||
340 | |||
330 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); | 341 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); |
331 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); | 342 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
332 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, | 343 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, |
@@ -344,8 +355,45 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, | |||
344 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, | 355 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, |
345 | set_temphyst, 3); | 356 | set_temphyst, 3); |
346 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); | 357 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); |
358 | |||
359 | /* Individual alarm files */ | ||
360 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); | ||
361 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | ||
362 | static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2); | ||
363 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | ||
364 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | ||
365 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); | ||
366 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | ||
367 | /* Raw alarm file for compatibility */ | ||
347 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 368 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
348 | 369 | ||
370 | static struct attribute *lm90_attributes[] = { | ||
371 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
372 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
373 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
374 | &sensor_dev_attr_temp2_min.dev_attr.attr, | ||
375 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
376 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
377 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | ||
378 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | ||
379 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, | ||
380 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, | ||
381 | |||
382 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | ||
383 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | ||
384 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | ||
385 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | ||
386 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | ||
387 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | ||
388 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | ||
389 | &dev_attr_alarms.attr, | ||
390 | NULL | ||
391 | }; | ||
392 | |||
393 | static const struct attribute_group lm90_group = { | ||
394 | .attrs = lm90_attributes, | ||
395 | }; | ||
396 | |||
349 | /* pec used for ADM1032 only */ | 397 | /* pec used for ADM1032 only */ |
350 | static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, | 398 | static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, |
351 | char *buf) | 399 | char *buf) |
@@ -569,39 +617,25 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
569 | lm90_init_client(new_client); | 617 | lm90_init_client(new_client); |
570 | 618 | ||
571 | /* Register sysfs hooks */ | 619 | /* Register sysfs hooks */ |
620 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) | ||
621 | goto exit_detach; | ||
622 | if (new_client->flags & I2C_CLIENT_PEC) { | ||
623 | if ((err = device_create_file(&new_client->dev, | ||
624 | &dev_attr_pec))) | ||
625 | goto exit_remove_files; | ||
626 | } | ||
627 | |||
572 | data->class_dev = hwmon_device_register(&new_client->dev); | 628 | data->class_dev = hwmon_device_register(&new_client->dev); |
573 | if (IS_ERR(data->class_dev)) { | 629 | if (IS_ERR(data->class_dev)) { |
574 | err = PTR_ERR(data->class_dev); | 630 | err = PTR_ERR(data->class_dev); |
575 | goto exit_detach; | 631 | goto exit_remove_files; |
576 | } | 632 | } |
577 | 633 | ||
578 | device_create_file(&new_client->dev, | ||
579 | &sensor_dev_attr_temp1_input.dev_attr); | ||
580 | device_create_file(&new_client->dev, | ||
581 | &sensor_dev_attr_temp2_input.dev_attr); | ||
582 | device_create_file(&new_client->dev, | ||
583 | &sensor_dev_attr_temp1_min.dev_attr); | ||
584 | device_create_file(&new_client->dev, | ||
585 | &sensor_dev_attr_temp2_min.dev_attr); | ||
586 | device_create_file(&new_client->dev, | ||
587 | &sensor_dev_attr_temp1_max.dev_attr); | ||
588 | device_create_file(&new_client->dev, | ||
589 | &sensor_dev_attr_temp2_max.dev_attr); | ||
590 | device_create_file(&new_client->dev, | ||
591 | &sensor_dev_attr_temp1_crit.dev_attr); | ||
592 | device_create_file(&new_client->dev, | ||
593 | &sensor_dev_attr_temp2_crit.dev_attr); | ||
594 | device_create_file(&new_client->dev, | ||
595 | &sensor_dev_attr_temp1_crit_hyst.dev_attr); | ||
596 | device_create_file(&new_client->dev, | ||
597 | &sensor_dev_attr_temp2_crit_hyst.dev_attr); | ||
598 | device_create_file(&new_client->dev, &dev_attr_alarms); | ||
599 | |||
600 | if (new_client->flags & I2C_CLIENT_PEC) | ||
601 | device_create_file(&new_client->dev, &dev_attr_pec); | ||
602 | |||
603 | return 0; | 634 | return 0; |
604 | 635 | ||
636 | exit_remove_files: | ||
637 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); | ||
638 | device_remove_file(&new_client->dev, &dev_attr_pec); | ||
605 | exit_detach: | 639 | exit_detach: |
606 | i2c_detach_client(new_client); | 640 | i2c_detach_client(new_client); |
607 | exit_free: | 641 | exit_free: |
@@ -634,6 +668,8 @@ static int lm90_detach_client(struct i2c_client *client) | |||
634 | int err; | 668 | int err; |
635 | 669 | ||
636 | hwmon_device_unregister(data->class_dev); | 670 | hwmon_device_unregister(data->class_dev); |
671 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | ||
672 | device_remove_file(&client->dev, &dev_attr_pec); | ||
637 | 673 | ||
638 | if ((err = i2c_detach_client(client))) | 674 | if ((err = i2c_detach_client(client))) |
639 | return err; | 675 | return err; |