Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e7f5994 authored by Guenter Roeck's avatar Guenter Roeck
Browse files

hwmon: (ntc_thermistor) Use devm_hwmon_device_register_with_groups



Simplify code, reduce code size, and drop remove function as no longer
needed.

Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 48001525
Loading
Loading
Loading
Loading
+9 −48
Original line number Original line Diff line number Diff line
@@ -253,11 +253,9 @@ static const struct ntc_compensation b57330v2103[] = {
};
};


struct ntc_data {
struct ntc_data {
	struct device *hwmon_dev;
	struct ntc_thermistor_platform_data *pdata;
	struct ntc_thermistor_platform_data *pdata;
	const struct ntc_compensation *comp;
	const struct ntc_compensation *comp;
	int n_comp;
	int n_comp;
	char name[PLATFORM_NAME_SIZE];
};
};


#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
@@ -508,9 +506,8 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
	return -EINVAL;
	return -EINVAL;
}
}


static int ntc_read_temp(void *dev, int *temp)
static int ntc_read_temp(void *data, int *temp)
{
{
	struct ntc_data *data = dev_get_drvdata(dev);
	int ohm;
	int ohm;


	ohm = ntc_thermistor_get_ohm(data);
	ohm = ntc_thermistor_get_ohm(data);
@@ -522,14 +519,6 @@ static int ntc_read_temp(void *dev, int *temp)
	return 0;
	return 0;
}
}


static ssize_t ntc_show_name(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct ntc_data *data = dev_get_drvdata(dev);

	return sprintf(buf, "%s\n", data->name);
}

static ssize_t ntc_show_type(struct device *dev,
static ssize_t ntc_show_type(struct device *dev,
		struct device_attribute *attr, char *buf)
		struct device_attribute *attr, char *buf)
{
{
@@ -551,18 +540,13 @@ static ssize_t ntc_show_temp(struct device *dev,


static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, ntc_show_type, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, ntc_show_type, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ntc_show_temp, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ntc_show_temp, NULL, 0);
static DEVICE_ATTR(name, S_IRUGO, ntc_show_name, NULL);


static struct attribute *ntc_attributes[] = {
static struct attribute *ntc_attrs[] = {
	&dev_attr_name.attr,
	&sensor_dev_attr_temp1_type.dev_attr.attr,
	&sensor_dev_attr_temp1_type.dev_attr.attr,
	&sensor_dev_attr_temp1_input.dev_attr.attr,
	&sensor_dev_attr_temp1_input.dev_attr.attr,
	NULL,
	NULL,
};
};

ATTRIBUTE_GROUPS(ntc);
static const struct attribute_group ntc_attr_group = {
	.attrs = ntc_attributes,
};


static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = {
static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = {
	.get_temp = ntc_read_temp,
	.get_temp = ntc_read_temp,
@@ -576,8 +560,8 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
			of_match_device(of_match_ptr(ntc_match), dev);
			of_match_device(of_match_ptr(ntc_match), dev);
	const struct platform_device_id *pdev_id;
	const struct platform_device_id *pdev_id;
	struct ntc_thermistor_platform_data *pdata;
	struct ntc_thermistor_platform_data *pdata;
	struct device *hwmon_dev;
	struct ntc_data *data;
	struct ntc_data *data;
	int ret;


	pdata = ntc_thermistor_parse_dt(dev);
	pdata = ntc_thermistor_parse_dt(dev);
	if (IS_ERR(pdata))
	if (IS_ERR(pdata))
@@ -621,7 +605,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
	pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
	pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);


	data->pdata = pdata;
	data->pdata = pdata;
	strlcpy(data->name, pdev_id->name, sizeof(data->name));


	switch (pdev_id->driver_data) {
	switch (pdev_id->driver_data) {
	case TYPE_NCPXXWB473:
	case TYPE_NCPXXWB473:
@@ -650,42 +633,21 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
		return -EINVAL;
		return -EINVAL;
	}
	}


	platform_set_drvdata(pdev, data);
	hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name,

							   data, ntc_groups);
	ret = sysfs_create_group(&dev->kobj, &ntc_attr_group);
	if (IS_ERR(hwmon_dev)) {
	if (ret) {
		dev_err(dev, "unable to create sysfs files\n");
		return ret;
	}

	data->hwmon_dev = hwmon_device_register(dev);
	if (IS_ERR(data->hwmon_dev)) {
		dev_err(dev, "unable to register as hwmon device.\n");
		dev_err(dev, "unable to register as hwmon device.\n");
		ret = PTR_ERR(data->hwmon_dev);
		return PTR_ERR(hwmon_dev);
		goto err_after_sysfs;
	}
	}


	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, dev,
	tz = devm_thermal_zone_of_sensor_register(dev, 0, data,
						  &ntc_of_thermal_ops);
						  &ntc_of_thermal_ops);
	if (IS_ERR(tz))
	if (IS_ERR(tz))
		dev_dbg(dev, "Failed to register to thermal fw.\n");
		dev_dbg(dev, "Failed to register to thermal fw.\n");


	return 0;
err_after_sysfs:
	sysfs_remove_group(&dev->kobj, &ntc_attr_group);
	return ret;
}

static int ntc_thermistor_remove(struct platform_device *pdev)
{
	struct ntc_data *data = platform_get_drvdata(pdev);

	hwmon_device_unregister(data->hwmon_dev);
	sysfs_remove_group(&pdev->dev.kobj, &ntc_attr_group);

	return 0;
	return 0;
}
}


@@ -695,7 +657,6 @@ static struct platform_driver ntc_thermistor_driver = {
		.of_match_table = of_match_ptr(ntc_match),
		.of_match_table = of_match_ptr(ntc_match),
	},
	},
	.probe = ntc_thermistor_probe,
	.probe = ntc_thermistor_probe,
	.remove = ntc_thermistor_remove,
	.id_table = ntc_thermistor_id,
	.id_table = ntc_thermistor_id,
};
};