提交 b4e665c7 编写于 作者: G Guenter Roeck

hwmon: (tmp401) Use sysfs_create_group / sysfs_remove_group

instead of creating and removing sysfs attribute files individually.
Acked-by: NJean Delvare <khali@linux-fr.org>
Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
上级 947e9271
...@@ -465,38 +465,64 @@ static ssize_t reset_temp_history(struct device *dev, ...@@ -465,38 +465,64 @@ static ssize_t reset_temp_history(struct device *dev,
return count; return count;
} }
static struct sensor_device_attribute tmp401_attr[] = { static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0);
SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0), static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
SENSOR_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, store_temp_min, 0);
store_temp_min, 0), static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
SENSOR_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, store_temp_max, 0);
store_temp_max, 0), static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit,
SENSOR_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit, store_temp_crit, 0);
store_temp_crit, 0), static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
SENSOR_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_crit_hyst, show_temp_crit_hyst, store_temp_crit_hyst, 0);
store_temp_crit_hyst, 0), static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL,
SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, TMP401_STATUS_LOCAL_LOW);
TMP401_STATUS_LOCAL_LOW), static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL,
SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL, TMP401_STATUS_LOCAL_HIGH);
TMP401_STATUS_LOCAL_HIGH), static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL,
SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, TMP401_STATUS_LOCAL_CRIT);
TMP401_STATUS_LOCAL_CRIT), static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1);
SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1), static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
SENSOR_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, store_temp_min, 1);
store_temp_min, 1), static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
SENSOR_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, store_temp_max, 1);
store_temp_max, 1), static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit,
SENSOR_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit, store_temp_crit, 1);
store_temp_crit, 1), static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst,
SENSOR_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, 1), NULL, 1);
SENSOR_ATTR(temp2_fault, S_IRUGO, show_status, NULL, static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_status, NULL,
TMP401_STATUS_REMOTE_OPEN), TMP401_STATUS_REMOTE_OPEN);
SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL, static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL,
TMP401_STATUS_REMOTE_LOW), TMP401_STATUS_REMOTE_LOW);
SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL, static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL,
TMP401_STATUS_REMOTE_HIGH), TMP401_STATUS_REMOTE_HIGH);
SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL, static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL,
TMP401_STATUS_REMOTE_CRIT), TMP401_STATUS_REMOTE_CRIT);
static struct attribute *tmp401_attributes[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_min.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr,
&sensor_dev_attr_temp1_crit.dev_attr.attr,
&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_input.dev_attr.attr,
&sensor_dev_attr_temp2_min.dev_attr.attr,
&sensor_dev_attr_temp2_max.dev_attr.attr,
&sensor_dev_attr_temp2_crit.dev_attr.attr,
&sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
&sensor_dev_attr_temp2_fault.dev_attr.attr,
&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
NULL
};
static const struct attribute_group tmp401_group = {
.attrs = tmp401_attributes,
}; };
/* /*
...@@ -506,12 +532,24 @@ static struct sensor_device_attribute tmp401_attr[] = { ...@@ -506,12 +532,24 @@ static struct sensor_device_attribute tmp401_attr[] = {
* minimum and maximum register reset for both the local * minimum and maximum register reset for both the local
* and remote channels. * and remote channels.
*/ */
static struct sensor_device_attribute tmp411_attr[] = { static SENSOR_DEVICE_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0);
SENSOR_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0), static SENSOR_DEVICE_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0);
SENSOR_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0), static SENSOR_DEVICE_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1);
SENSOR_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1), static SENSOR_DEVICE_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1);
SENSOR_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1), static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history,
SENSOR_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, 0), 0);
static struct attribute *tmp411_attributes[] = {
&sensor_dev_attr_temp1_highest.dev_attr.attr,
&sensor_dev_attr_temp1_lowest.dev_attr.attr,
&sensor_dev_attr_temp2_highest.dev_attr.attr,
&sensor_dev_attr_temp2_lowest.dev_attr.attr,
&sensor_dev_attr_temp_reset_history.dev_attr.attr,
NULL
};
static const struct attribute_group tmp411_group = {
.attrs = tmp411_attributes,
}; };
/* /*
...@@ -602,20 +640,16 @@ static int tmp401_detect(struct i2c_client *client, ...@@ -602,20 +640,16 @@ static int tmp401_detect(struct i2c_client *client,
static int tmp401_remove(struct i2c_client *client) static int tmp401_remove(struct i2c_client *client)
{ {
struct device *dev = &client->dev;
struct tmp401_data *data = i2c_get_clientdata(client); struct tmp401_data *data = i2c_get_clientdata(client);
int i;
if (data->hwmon_dev) if (data->hwmon_dev)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) sysfs_remove_group(&dev->kobj, &tmp401_group);
device_remove_file(&client->dev, &tmp401_attr[i].dev_attr);
if (data->kind == tmp411) { if (data->kind == tmp411)
for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) sysfs_remove_group(&dev->kobj, &tmp411_group);
device_remove_file(&client->dev,
&tmp411_attr[i].dev_attr);
}
return 0; return 0;
} }
...@@ -623,12 +657,12 @@ static int tmp401_remove(struct i2c_client *client) ...@@ -623,12 +657,12 @@ static int tmp401_remove(struct i2c_client *client)
static int tmp401_probe(struct i2c_client *client, static int tmp401_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int i, err = 0; struct device *dev = &client->dev;
int err;
struct tmp401_data *data; struct tmp401_data *data;
const char *names[] = { "TMP401", "TMP411", "TMP431" }; const char *names[] = { "TMP401", "TMP411", "TMP431" };
data = devm_kzalloc(&client->dev, sizeof(struct tmp401_data), data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -640,31 +674,25 @@ static int tmp401_probe(struct i2c_client *client, ...@@ -640,31 +674,25 @@ static int tmp401_probe(struct i2c_client *client,
tmp401_init_client(client); tmp401_init_client(client);
/* Register sysfs hooks */ /* Register sysfs hooks */
for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) { err = sysfs_create_group(&dev->kobj, &tmp401_group);
err = device_create_file(&client->dev, if (err)
&tmp401_attr[i].dev_attr); return err;
if (err)
goto exit_remove;
}
/* Register additional tmp411 sysfs hooks */ /* Register additional tmp411 sysfs hooks */
if (data->kind == tmp411) { if (data->kind == tmp411) {
for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) { err = sysfs_create_group(&dev->kobj, &tmp411_group);
err = device_create_file(&client->dev, if (err)
&tmp411_attr[i].dev_attr); goto exit_remove;
if (err)
goto exit_remove;
}
} }
data->hwmon_dev = hwmon_device_register(&client->dev); data->hwmon_dev = hwmon_device_register(dev);
if (IS_ERR(data->hwmon_dev)) { if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev); err = PTR_ERR(data->hwmon_dev);
data->hwmon_dev = NULL; data->hwmon_dev = NULL;
goto exit_remove; goto exit_remove;
} }
dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]); dev_info(dev, "Detected TI %s chip\n", names[data->kind]);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册