Skip to content

Commit 7cc7de9

Browse files
committed
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>
1 parent b57e1d4 commit 7cc7de9

File tree

1 file changed

+66
-40
lines changed

1 file changed

+66
-40
lines changed

drivers/hwmon/ntc_thermistor.c

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#include <linux/iio/consumer.h>
3838

3939
#include <linux/hwmon.h>
40-
#include <linux/hwmon-sysfs.h>
41-
#include <linux/thermal.h>
4240

4341
struct ntc_compensation {
4442
int temp_c;
@@ -588,55 +586,87 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
588586
return -EINVAL;
589587
}
590588

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)
592591
{
592+
struct ntc_data *data = dev_get_drvdata(dev);
593593
int ohm;
594594

595-
ohm = ntc_thermistor_get_ohm(data);
596-
if (ohm < 0)
597-
return ohm;
598-
599-
*temp = get_temp_mc(data, ohm);
600-
601-
return 0;
595+
switch (type) {
596+
case hwmon_temp:
597+
switch (attr) {
598+
case hwmon_temp_input:
599+
ohm = ntc_thermistor_get_ohm(data);
600+
if (ohm < 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;
602615
}
603616

604-
static ssize_t ntc_type_show(struct device *dev,
605-
struct device_attribute *attr, char *buf)
617+
static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type,
618+
u32 attr, int channel)
606619
{
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;
608630
}
609631

610-
static ssize_t ntc_temp_show(struct device *dev,
611-
struct device_attribute *attr, char *buf)
612-
{
613-
struct ntc_data *data = dev_get_drvdata(dev);
614-
int ohm;
632+
static const u32 ntc_chip_config[] = {
633+
HWMON_C_REGISTER_TZ,
634+
0
635+
};
615636

616-
ohm = ntc_thermistor_get_ohm(data);
617-
if (ohm < 0)
618-
return ohm;
637+
static const struct hwmon_channel_info ntc_chip = {
638+
.type = hwmon_chip,
639+
.config = ntc_chip_config,
640+
};
619641

620-
return sprintf(buf, "%d\n", get_temp_mc(data, ohm));
621-
}
642+
static const u32 ntc_temp_config[] = {
643+
HWMON_T_INPUT, HWMON_T_TYPE,
644+
0
645+
};
622646

623-
static SENSOR_DEVICE_ATTR_RO(temp1_type, ntc_type, 0);
624-
static SENSOR_DEVICE_ATTR_RO(temp1_input, ntc_temp, 0);
647+
static const struct hwmon_channel_info ntc_temp = {
648+
.type = hwmon_temp,
649+
.config = ntc_temp_config,
650+
};
625651

626-
static struct attribute *ntc_attrs[] = {
627-
&sensor_dev_attr_temp1_type.dev_attr.attr,
628-
&sensor_dev_attr_temp1_input.dev_attr.attr,
629-
NULL,
652+
static const struct hwmon_channel_info *ntc_info[] = {
653+
&ntc_chip,
654+
&ntc_temp,
655+
NULL
630656
};
631-
ATTRIBUTE_GROUPS(ntc);
632657

633-
static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = {
634-
.get_temp = ntc_read_temp,
658+
static const struct hwmon_ops ntc_hwmon_ops = {
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,
635666
};
636667

637668
static int ntc_thermistor_probe(struct platform_device *pdev)
638669
{
639-
struct thermal_zone_device *tz;
640670
struct device *dev = &pdev->dev;
641671
const struct of_device_id *of_id =
642672
of_match_device(of_match_ptr(ntc_match), dev);
@@ -697,8 +727,9 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
697727
data->comp = ntc_type[pdev_id->driver_data].comp;
698728
data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
699729

700-
hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name,
701-
data, ntc_groups);
730+
hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name,
731+
data, &ntc_chip_info,
732+
NULL);
702733
if (IS_ERR(hwmon_dev)) {
703734
dev_err(dev, "unable to register as hwmon device.\n");
704735
return PTR_ERR(hwmon_dev);
@@ -707,11 +738,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
707738
dev_info(dev, "Thermistor type: %s successfully probed.\n",
708739
pdev_id->name);
709740

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-
715741
return 0;
716742
}
717743

0 commit comments

Comments
 (0)