Commit 7cc7de93 authored by Guenter Roeck's avatar Guenter Roeck

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: default avatarGuenter Roeck <linux@roeck-us.net>
parent b57e1d42
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
#include <linux/iio/consumer.h> #include <linux/iio/consumer.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/thermal.h>
struct ntc_compensation { struct ntc_compensation {
int temp_c; int temp_c;
...@@ -588,55 +586,87 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data) ...@@ -588,55 +586,87 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
return -EINVAL; return -EINVAL;
} }
static int ntc_read_temp(void *data, int *temp) static int ntc_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{ {
struct ntc_data *data = dev_get_drvdata(dev);
int ohm; int ohm;
ohm = ntc_thermistor_get_ohm(data); switch (type) {
if (ohm < 0) case hwmon_temp:
return ohm; switch (attr) {
case hwmon_temp_input:
*temp = get_temp_mc(data, ohm); ohm = ntc_thermistor_get_ohm(data);
if (ohm < 0)
return 0; return ohm;
*val = get_temp_mc(data, ohm);
return 0;
case hwmon_temp_type:
*val = 4;
return 0;
default:
break;
}
break;
default:
break;
}
return -EINVAL;
} }
static ssize_t ntc_type_show(struct device *dev, static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type,
struct device_attribute *attr, char *buf) u32 attr, int channel)
{ {
return sprintf(buf, "4\n"); if (type == hwmon_temp) {
switch (attr) {
case hwmon_temp_input:
case hwmon_temp_type:
return 0444;
default:
break;
}
}
return 0;
} }
static ssize_t ntc_temp_show(struct device *dev, static const u32 ntc_chip_config[] = {
struct device_attribute *attr, char *buf) HWMON_C_REGISTER_TZ,
{ 0
struct ntc_data *data = dev_get_drvdata(dev); };
int ohm;
ohm = ntc_thermistor_get_ohm(data); static const struct hwmon_channel_info ntc_chip = {
if (ohm < 0) .type = hwmon_chip,
return ohm; .config = ntc_chip_config,
};
return sprintf(buf, "%d\n", get_temp_mc(data, ohm)); static const u32 ntc_temp_config[] = {
} HWMON_T_INPUT, HWMON_T_TYPE,
0
};
static SENSOR_DEVICE_ATTR_RO(temp1_type, ntc_type, 0); static const struct hwmon_channel_info ntc_temp = {
static SENSOR_DEVICE_ATTR_RO(temp1_input, ntc_temp, 0); .type = hwmon_temp,
.config = ntc_temp_config,
};
static struct attribute *ntc_attrs[] = { static const struct hwmon_channel_info *ntc_info[] = {
&sensor_dev_attr_temp1_type.dev_attr.attr, &ntc_chip,
&sensor_dev_attr_temp1_input.dev_attr.attr, &ntc_temp,
NULL, NULL
}; };
ATTRIBUTE_GROUPS(ntc);
static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = { static const struct hwmon_ops ntc_hwmon_ops = {
.get_temp = ntc_read_temp, .is_visible = ntc_is_visible,
.read = ntc_read,
};
static const struct hwmon_chip_info ntc_chip_info = {
.ops = &ntc_hwmon_ops,
.info = ntc_info,
}; };
static int ntc_thermistor_probe(struct platform_device *pdev) static int ntc_thermistor_probe(struct platform_device *pdev)
{ {
struct thermal_zone_device *tz;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
const struct of_device_id *of_id = const struct of_device_id *of_id =
of_match_device(of_match_ptr(ntc_match), dev); of_match_device(of_match_ptr(ntc_match), dev);
...@@ -697,8 +727,9 @@ static int ntc_thermistor_probe(struct platform_device *pdev) ...@@ -697,8 +727,9 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
data->comp = ntc_type[pdev_id->driver_data].comp; data->comp = ntc_type[pdev_id->driver_data].comp;
data->n_comp = ntc_type[pdev_id->driver_data].n_comp; data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name, hwmon_dev = devm_hwmon_device_register_with_info(dev, pdev_id->name,
data, ntc_groups); data, &ntc_chip_info,
NULL);
if (IS_ERR(hwmon_dev)) { if (IS_ERR(hwmon_dev)) {
dev_err(dev, "unable to register as hwmon device.\n"); dev_err(dev, "unable to register as hwmon device.\n");
return PTR_ERR(hwmon_dev); return PTR_ERR(hwmon_dev);
...@@ -707,11 +738,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev) ...@@ -707,11 +738,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
dev_info(dev, "Thermistor type: %s successfully probed.\n", dev_info(dev, "Thermistor type: %s successfully probed.\n",
pdev_id->name); pdev_id->name);
tz = devm_thermal_zone_of_sensor_register(dev, 0, data,
&ntc_of_thermal_ops);
if (IS_ERR(tz))
dev_dbg(dev, "Failed to register to thermal fw.\n");
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment