Commit e585c40b authored by Guenter Roeck's avatar Guenter Roeck Committed by Dmitry Torokhov

Input: ads7846 - convert to hwmon_device_register_with_groups()

Simplify the code and create mandatory 'name' attribute by using
new hwmon API.

Also use is_visible to determine visible attributes instead of creating
several different attribute groups.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 961794a0
...@@ -102,7 +102,6 @@ struct ads7846 { ...@@ -102,7 +102,6 @@ struct ads7846 {
struct regulator *reg; struct regulator *reg;
#if IS_ENABLED(CONFIG_HWMON) #if IS_ENABLED(CONFIG_HWMON)
struct attribute_group *attr_group;
struct device *hwmon; struct device *hwmon;
#endif #endif
...@@ -479,42 +478,36 @@ static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) ...@@ -479,42 +478,36 @@ static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v)
SHOW(in0_input, vaux, vaux_adjust) SHOW(in0_input, vaux, vaux_adjust)
SHOW(in1_input, vbatt, vbatt_adjust) SHOW(in1_input, vbatt, vbatt_adjust)
static struct attribute *ads7846_attributes[] = { static umode_t ads7846_is_visible(struct kobject *kobj, struct attribute *attr,
&dev_attr_temp0.attr, int index)
&dev_attr_temp1.attr, {
&dev_attr_in0_input.attr, struct device *dev = container_of(kobj, struct device, kobj);
&dev_attr_in1_input.attr, struct ads7846 *ts = dev_get_drvdata(dev);
NULL,
};
static struct attribute_group ads7846_attr_group = {
.attrs = ads7846_attributes,
};
static struct attribute *ads7843_attributes[] = { if (ts->model == 7843 && index < 2) /* in0, in1 */
&dev_attr_in0_input.attr, return 0;
&dev_attr_in1_input.attr, if (ts->model == 7845 && index != 2) /* in0 */
NULL, return 0;
};
static struct attribute_group ads7843_attr_group = { return attr->mode;
.attrs = ads7843_attributes, }
};
static struct attribute *ads7845_attributes[] = { static struct attribute *ads7846_attributes[] = {
&dev_attr_in0_input.attr, &dev_attr_temp0.attr, /* 0 */
&dev_attr_temp1.attr, /* 1 */
&dev_attr_in0_input.attr, /* 2 */
&dev_attr_in1_input.attr, /* 3 */
NULL, NULL,
}; };
static struct attribute_group ads7845_attr_group = { static struct attribute_group ads7846_attr_group = {
.attrs = ads7845_attributes, .attrs = ads7846_attributes,
.is_visible = ads7846_is_visible,
}; };
__ATTRIBUTE_GROUPS(ads7846_attr);
static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
{ {
struct device *hwmon;
int err;
/* hwmon sensors need a reference voltage */ /* hwmon sensors need a reference voltage */
switch (ts->model) { switch (ts->model) {
case 7846: case 7846:
...@@ -535,43 +528,19 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) ...@@ -535,43 +528,19 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
break; break;
} }
/* different chips have different sensor groups */ ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias,
switch (ts->model) { ts, ads7846_attr_groups);
case 7846: if (IS_ERR(ts->hwmon))
ts->attr_group = &ads7846_attr_group; return PTR_ERR(ts->hwmon);
break;
case 7845:
ts->attr_group = &ads7845_attr_group;
break;
case 7843:
ts->attr_group = &ads7843_attr_group;
break;
default:
dev_dbg(&spi->dev, "ADS%d not recognized\n", ts->model);
return 0;
}
err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
if (err)
return err;
hwmon = hwmon_device_register(&spi->dev);
if (IS_ERR(hwmon)) {
sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
return PTR_ERR(hwmon);
}
ts->hwmon = hwmon;
return 0; return 0;
} }
static void ads784x_hwmon_unregister(struct spi_device *spi, static void ads784x_hwmon_unregister(struct spi_device *spi,
struct ads7846 *ts) struct ads7846 *ts)
{ {
if (ts->hwmon) { if (ts->hwmon)
sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
hwmon_device_unregister(ts->hwmon); hwmon_device_unregister(ts->hwmon);
}
} }
#else #else
......
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