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

hwmon: (tmp401) Convert to use devm_hwmon_device_register_with_groups

Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
上级 468bf0e3
...@@ -155,7 +155,8 @@ MODULE_DEVICE_TABLE(i2c, tmp401_id); ...@@ -155,7 +155,8 @@ MODULE_DEVICE_TABLE(i2c, tmp401_id);
*/ */
struct tmp401_data { struct tmp401_data {
struct device *hwmon_dev; struct i2c_client *client;
const struct attribute_group *groups[3];
struct mutex update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -231,8 +232,8 @@ static int tmp401_update_device_reg16(struct i2c_client *client, ...@@ -231,8 +232,8 @@ static int tmp401_update_device_reg16(struct i2c_client *client,
static struct tmp401_data *tmp401_update_device(struct device *dev) static struct tmp401_data *tmp401_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct tmp401_data *data = dev_get_drvdata(dev);
struct tmp401_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
struct tmp401_data *ret = data; struct tmp401_data *ret = data;
int i, val; int i, val;
unsigned long next_update; unsigned long next_update;
...@@ -350,15 +351,12 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, ...@@ -350,15 +351,12 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr,
{ {
int nr = to_sensor_dev_attr_2(devattr)->nr; int nr = to_sensor_dev_attr_2(devattr)->nr;
int index = to_sensor_dev_attr_2(devattr)->index; int index = to_sensor_dev_attr_2(devattr)->index;
struct i2c_client *client = to_i2c_client(dev); struct tmp401_data *data = dev_get_drvdata(dev);
struct tmp401_data *data = tmp401_update_device(dev); struct i2c_client *client = data->client;
long val; long val;
u16 reg; u16 reg;
u8 regaddr; u8 regaddr;
if (IS_ERR(data))
return PTR_ERR(data);
if (kstrtol(buf, 10, &val)) if (kstrtol(buf, 10, &val))
return -EINVAL; return -EINVAL;
...@@ -405,7 +403,7 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute ...@@ -405,7 +403,7 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
val = clamp_val(val, temp - 255000, temp); val = clamp_val(val, temp - 255000, temp);
reg = ((temp - val) + 500) / 1000; reg = ((temp - val) + 500) / 1000;
i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_HYST, i2c_smbus_write_byte_data(data->client, TMP401_TEMP_CRIT_HYST,
reg); reg);
data->temp_crit_hyst = reg; data->temp_crit_hyst = reg;
...@@ -423,8 +421,8 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute ...@@ -423,8 +421,8 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
static ssize_t reset_temp_history(struct device *dev, static ssize_t reset_temp_history(struct device *dev,
struct device_attribute *devattr, const char *buf, size_t count) struct device_attribute *devattr, const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct tmp401_data *data = dev_get_drvdata(dev);
struct tmp401_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
long val; long val;
if (kstrtol(buf, 10, &val)) if (kstrtol(buf, 10, &val))
...@@ -447,8 +445,7 @@ static ssize_t reset_temp_history(struct device *dev, ...@@ -447,8 +445,7 @@ static ssize_t reset_temp_history(struct device *dev,
static ssize_t show_update_interval(struct device *dev, static ssize_t show_update_interval(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct tmp401_data *data = dev_get_drvdata(dev);
struct tmp401_data *data = i2c_get_clientdata(client);
return sprintf(buf, "%u\n", data->update_interval); return sprintf(buf, "%u\n", data->update_interval);
} }
...@@ -457,8 +454,8 @@ static ssize_t set_update_interval(struct device *dev, ...@@ -457,8 +454,8 @@ static ssize_t set_update_interval(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct tmp401_data *data = dev_get_drvdata(dev);
struct tmp401_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
unsigned long val; unsigned long val;
int err, rate; int err, rate;
...@@ -616,10 +613,10 @@ static const struct attribute_group tmp432_group = { ...@@ -616,10 +613,10 @@ static const struct attribute_group tmp432_group = {
* Begin non sysfs callback code (aka Real code) * Begin non sysfs callback code (aka Real code)
*/ */
static void tmp401_init_client(struct i2c_client *client) static void tmp401_init_client(struct tmp401_data *data,
struct i2c_client *client)
{ {
int config, config_orig; int config, config_orig;
struct tmp401_data *data = i2c_get_clientdata(client);
/* Set the conversion rate to 2 Hz */ /* Set the conversion rate to 2 Hz */
i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
...@@ -705,77 +702,45 @@ static int tmp401_detect(struct i2c_client *client, ...@@ -705,77 +702,45 @@ static int tmp401_detect(struct i2c_client *client,
return 0; return 0;
} }
static int tmp401_remove(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct tmp401_data *data = i2c_get_clientdata(client);
if (data->hwmon_dev)
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&dev->kobj, &tmp401_group);
if (data->kind == tmp411)
sysfs_remove_group(&dev->kobj, &tmp411_group);
if (data->kind == tmp432)
sysfs_remove_group(&dev->kobj, &tmp432_group);
return 0;
}
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)
{ {
const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" };
struct device *dev = &client->dev; struct device *dev = &client->dev;
int err; struct device *hwmon_dev;
struct tmp401_data *data; struct tmp401_data *data;
const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" }; int groups = 0;
data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); data->client = client;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
data->kind = id->driver_data; data->kind = id->driver_data;
/* Initialize the TMP401 chip */ /* Initialize the TMP401 chip */
tmp401_init_client(client); tmp401_init_client(data, client);
/* Register sysfs hooks */ /* Register sysfs hooks */
err = sysfs_create_group(&dev->kobj, &tmp401_group); data->groups[groups++] = &tmp401_group;
if (err)
return err;
/* Register additional tmp411 sysfs hooks */ /* Register additional tmp411 sysfs hooks */
if (data->kind == tmp411) { if (data->kind == tmp411)
err = sysfs_create_group(&dev->kobj, &tmp411_group); data->groups[groups++] = &tmp411_group;
if (err)
goto exit_remove;
}
/* Register additional tmp432 sysfs hooks */ /* Register additional tmp432 sysfs hooks */
if (data->kind == tmp432) { if (data->kind == tmp432)
err = sysfs_create_group(&dev->kobj, &tmp432_group); data->groups[groups++] = &tmp432_group;
if (err)
goto exit_remove;
}
data->hwmon_dev = hwmon_device_register(dev); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
if (IS_ERR(data->hwmon_dev)) { data, data->groups);
err = PTR_ERR(data->hwmon_dev); if (IS_ERR(hwmon_dev))
data->hwmon_dev = NULL; return PTR_ERR(hwmon_dev);
goto exit_remove;
}
dev_info(dev, "Detected TI %s chip\n", names[data->kind]); dev_info(dev, "Detected TI %s chip\n", names[data->kind]);
return 0; return 0;
exit_remove:
tmp401_remove(client);
return err;
} }
static struct i2c_driver tmp401_driver = { static struct i2c_driver tmp401_driver = {
...@@ -784,7 +749,6 @@ static struct i2c_driver tmp401_driver = { ...@@ -784,7 +749,6 @@ static struct i2c_driver tmp401_driver = {
.name = "tmp401", .name = "tmp401",
}, },
.probe = tmp401_probe, .probe = tmp401_probe,
.remove = tmp401_remove,
.id_table = tmp401_id, .id_table = tmp401_id,
.detect = tmp401_detect, .detect = tmp401_detect,
.address_list = normal_i2c, .address_list = normal_i2c,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册