diff options
author | Guenter Roeck <linux@roeck-us.net> | 2019-02-12 12:55:16 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2019-02-23 12:04:47 -0500 |
commit | 7cc7de93fad46623e2600f74988c715d568e5ad8 (patch) | |
tree | 14a37639adf70e4ef9684b4fac75c2ee774ad02e /drivers/hwmon | |
parent | b57e1d429397217870595c80219b825d7a6db0c6 (diff) |
hwmon: (ntc_thermistor) Convert to new hwmon API
Use devm_hwmon_device_register_with_info() instead of
devm_hwmon_device_register_with_groups() to register the hwmon
device to simplify the code and make it easier to maintain.
As part of this change, thermal device registration is moved into
the hwmon core.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/ntc_thermistor.c | 106 |
1 files changed, 66 insertions, 40 deletions
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index 2823aff82c82..e4f9f7ce92fa 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c | |||
@@ -37,8 +37,6 @@ | |||
37 | #include <linux/iio/consumer.h> | 37 | #include <linux/iio/consumer.h> |
38 | 38 | ||
39 | #include <linux/hwmon.h> | 39 | #include <linux/hwmon.h> |
40 | #include <linux/hwmon-sysfs.h> | ||
41 | #include <linux/thermal.h> | ||
42 | 40 | ||
43 | struct ntc_compensation { | 41 | struct ntc_compensation { |
44 | int temp_c; | 42 | int temp_c; |
@@ -588,55 +586,87 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data) | |||
588 | return -EINVAL; | 586 | return -EINVAL; |
589 | } | 587 | } |
590 | 588 | ||
591 | static int ntc_read_temp(void *data, int *temp) | 589 | static int ntc_read(struct device *dev, enum hwmon_sensor_types type, |
590 | u32 attr, int channel, long *val) | ||
592 | { | 591 | { |
592 | struct ntc_data *data = dev_get_drvdata(dev); | ||
593 | int ohm; | 593 | int ohm; |
594 | 594 | ||
595 | ohm = ntc_thermistor_get_ohm(data); | 595 | switch (type) { |
596 | if (ohm < 0) | 596 | case hwmon_temp: |
597 | return ohm; | 597 | switch (attr) { |
598 | 598 | case hwmon_temp_input: | |
599 | *temp = get_temp_mc(data, ohm); | 599 | ohm = ntc_thermistor_get_ohm(data); |
600 | 600 | if (ohm < 0) | |
601 | return 0; | 601 | return ohm; |
602 | *val = get_temp_mc(data, ohm); | ||
603 | return 0; | ||
604 | case hwmon_temp_type: | ||
605 | *val = 4; | ||
606 | return 0; | ||
607 | default: | ||
608 | break; | ||
609 | } | ||
610 | break; | ||
611 | default: | ||
612 | break; | ||
613 | } | ||
614 | return -EINVAL; | ||
602 | } | 615 | } |
603 | 616 | ||
604 | static ssize_t ntc_type_show(struct device *dev, | 617 | static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type, |
605 | struct device_attribute *attr, char *buf) | 618 | u32 attr, int channel) |
606 | { | 619 | { |
607 | return sprintf(buf, "4\n"); | 620 | if (type == hwmon_temp) { |
621 | switch (attr) { | ||
622 | case hwmon_temp_input: | ||
623 | case hwmon_temp_type: | ||
624 | return 0444; | ||
625 | default: | ||
626 | break; | ||
627 | } | ||
628 | } | ||
629 | return 0; | ||
608 | } | 630 | } |
609 | 631 | ||
610 | static ssize_t ntc_temp_show(struct device *dev, | 632 | static const u32 ntc_chip_config[] = { |
611 | struct device_attribute *attr, char *buf) | 633 | HWMON_C_REGISTER_TZ, |
612 | { | 634 | 0 |
613 | struct ntc_data *data = dev_get_drvdata(dev); | 635 | }; |
614 | int ohm; | ||
615 | 636 | ||
616 | ohm = ntc_thermistor_get_ohm(data); | 637 | static const struct hwmon_channel_info ntc_chip = { |
617 | if (ohm < 0) | 638 | .type = hwmon_chip, |
618 | return ohm; | 639 | .config = ntc_chip_config, |
640 | }; | ||
619 | 641 | ||
620 | return sprintf(buf, "%d\n", get_temp_mc(data, ohm)); | 642 | static const u32 ntc_temp_config[] = { |
621 | } | 643 | HWMON_T_INPUT, HWMON_T_TYPE, |
644 | 0 | ||
645 | }; | ||
622 | 646 | ||
623 | static SENSOR_DEVICE_ATTR_RO(temp1_type, ntc_type, 0); | 647 | static const struct hwmon_channel_info ntc_temp = { |
624 | static SENSOR_DEVICE_ATTR_RO(temp1_input, ntc_temp, 0); | 648 | .type = hwmon_temp, |
649 | .config = ntc_temp_config, | ||
650 | }; | ||
625 | 651 | ||
626 | static struct attribute *ntc_attrs[] = { | 652 | static const struct hwmon_channel_info *ntc_info[] = { |
627 | &sensor_dev_attr_temp1_type.dev_attr.attr, | 653 | &ntc_chip, |
628 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 654 | &ntc_temp, |
629 | NULL, | 655 | NULL |
630 | }; | 656 | }; |
631 | ATTRIBUTE_GROUPS(ntc); | ||
632 | 657 | ||
633 | static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = { | 658 | static const struct hwmon_ops ntc_hwmon_ops = { |
634 | .get_temp = ntc_read_temp, | 659 | .is_visible = ntc_is_visible, |
660 | .read = ntc_read, | ||
661 | }; | ||
662 | |||
663 | static const struct hwmon_chip_info ntc_chip_info = { | ||
664 | .ops = &ntc_hwmon_ops, | ||
665 | .info = ntc_info, | ||
635 | }; | 666 | }; |
636 | 667 | ||
637 | static int ntc_thermistor_probe(struct platform_device *pdev) | 668 | static int ntc_thermistor_probe(struct platform_device *pdev) |
638 | { | 669 | { |
639 | struct thermal_zone_device *tz; | ||
640 | struct device *dev = &pdev->dev; | 670 | struct device *dev = &pdev->dev; |
641 | const struct of_device_id *of_id = | 671 | const struct of_device_id *of_id = |
642 | of_match_device(of_match_ptr(ntc_match), dev); | 672 | of_match_device(of_match_ptr(ntc_match), dev); |
@@ -697,8 +727,9 @@ static int ntc_thermistor_probe(struct platform_device *pdev) | |||
697 | data->comp = ntc_type[pdev_id->driver_data].comp; | 727 | data->comp = ntc_type[pdev_id->driver_data].comp; |
698 | data->n_comp = ntc_type[pdev_id->driver_data].n_comp; | 728 | data->n_comp = ntc_type[pdev_id->driver_data].n_comp; |
699 | 729 | ||
700 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name, | 730 | hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name, |
701 | data, ntc_groups); | 731 | data, &ntc_chip_info, |
732 | NULL); | ||
702 | if (IS_ERR(hwmon_dev)) { | 733 | if (IS_ERR(hwmon_dev)) { |
703 | dev_err(dev, "unable to register as hwmon device.\n"); | 734 | dev_err(dev, "unable to register as hwmon device.\n"); |
704 | return PTR_ERR(hwmon_dev); | 735 | return PTR_ERR(hwmon_dev); |
@@ -707,11 +738,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev) | |||
707 | dev_info(dev, "Thermistor type: %s successfully probed.\n", | 738 | dev_info(dev, "Thermistor type: %s successfully probed.\n", |
708 | pdev_id->name); | 739 | pdev_id->name); |
709 | 740 | ||
710 | tz = devm_thermal_zone_of_sensor_register(dev, 0, data, | ||
711 | &ntc_of_thermal_ops); | ||
712 | if (IS_ERR(tz)) | ||
713 | dev_dbg(dev, "Failed to register to thermal fw.\n"); | ||
714 | |||
715 | return 0; | 741 | return 0; |
716 | } | 742 | } |
717 | 743 | ||