diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-19 10:42:33 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:40 -0400 |
commit | eac83cd9dca6ba2e5a8ba8b823daf8fdbbeae109 (patch) | |
tree | 9a9776af866f229547ce74f3dc94092295a9019b | |
parent | 398e16db62620dd80a237c5043bec5c9335ac92c (diff) |
hwmon: (adt7411) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/adt7411.c | 59 |
1 files changed, 20 insertions, 39 deletions
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index d9299dee37d1..827c03703128 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c | |||
@@ -51,7 +51,7 @@ struct adt7411_data { | |||
51 | struct mutex update_lock; | 51 | struct mutex update_lock; |
52 | unsigned long next_update; | 52 | unsigned long next_update; |
53 | int vref_cached; | 53 | int vref_cached; |
54 | struct device *hwmon_dev; | 54 | struct i2c_client *client; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | /* | 57 | /* |
@@ -111,7 +111,8 @@ static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit, | |||
111 | static ssize_t adt7411_show_vdd(struct device *dev, | 111 | static ssize_t adt7411_show_vdd(struct device *dev, |
112 | struct device_attribute *attr, char *buf) | 112 | struct device_attribute *attr, char *buf) |
113 | { | 113 | { |
114 | struct i2c_client *client = to_i2c_client(dev); | 114 | struct adt7411_data *data = dev_get_drvdata(dev); |
115 | struct i2c_client *client = data->client; | ||
115 | int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, | 116 | int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, |
116 | ADT7411_REG_VDD_MSB, 2); | 117 | ADT7411_REG_VDD_MSB, 2); |
117 | 118 | ||
@@ -121,7 +122,8 @@ static ssize_t adt7411_show_vdd(struct device *dev, | |||
121 | static ssize_t adt7411_show_temp(struct device *dev, | 122 | static ssize_t adt7411_show_temp(struct device *dev, |
122 | struct device_attribute *attr, char *buf) | 123 | struct device_attribute *attr, char *buf) |
123 | { | 124 | { |
124 | struct i2c_client *client = to_i2c_client(dev); | 125 | struct adt7411_data *data = dev_get_drvdata(dev); |
126 | struct i2c_client *client = data->client; | ||
125 | int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, | 127 | int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, |
126 | ADT7411_REG_INT_TEMP_MSB, 0); | 128 | ADT7411_REG_INT_TEMP_MSB, 0); |
127 | 129 | ||
@@ -137,8 +139,8 @@ static ssize_t adt7411_show_input(struct device *dev, | |||
137 | struct device_attribute *attr, char *buf) | 139 | struct device_attribute *attr, char *buf) |
138 | { | 140 | { |
139 | int nr = to_sensor_dev_attr(attr)->index; | 141 | int nr = to_sensor_dev_attr(attr)->index; |
140 | struct i2c_client *client = to_i2c_client(dev); | 142 | struct adt7411_data *data = dev_get_drvdata(dev); |
141 | struct adt7411_data *data = i2c_get_clientdata(client); | 143 | struct i2c_client *client = data->client; |
142 | int val; | 144 | int val; |
143 | u8 lsb_reg, lsb_shift; | 145 | u8 lsb_reg, lsb_shift; |
144 | 146 | ||
@@ -180,7 +182,8 @@ static ssize_t adt7411_show_bit(struct device *dev, | |||
180 | struct device_attribute *attr, char *buf) | 182 | struct device_attribute *attr, char *buf) |
181 | { | 183 | { |
182 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | 184 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); |
183 | struct i2c_client *client = to_i2c_client(dev); | 185 | struct adt7411_data *data = dev_get_drvdata(dev); |
186 | struct i2c_client *client = data->client; | ||
184 | int ret = i2c_smbus_read_byte_data(client, attr2->index); | 187 | int ret = i2c_smbus_read_byte_data(client, attr2->index); |
185 | 188 | ||
186 | return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); | 189 | return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); |
@@ -191,8 +194,8 @@ static ssize_t adt7411_set_bit(struct device *dev, | |||
191 | size_t count) | 194 | size_t count) |
192 | { | 195 | { |
193 | struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); | 196 | struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); |
194 | struct i2c_client *client = to_i2c_client(dev); | 197 | struct adt7411_data *data = dev_get_drvdata(dev); |
195 | struct adt7411_data *data = i2c_get_clientdata(client); | 198 | struct i2c_client *client = data->client; |
196 | int ret; | 199 | int ret; |
197 | unsigned long flag; | 200 | unsigned long flag; |
198 | 201 | ||
@@ -245,9 +248,7 @@ static struct attribute *adt7411_attrs[] = { | |||
245 | NULL | 248 | NULL |
246 | }; | 249 | }; |
247 | 250 | ||
248 | static const struct attribute_group adt7411_attr_grp = { | 251 | ATTRIBUTE_GROUPS(adt7411); |
249 | .attrs = adt7411_attrs, | ||
250 | }; | ||
251 | 252 | ||
252 | static int adt7411_detect(struct i2c_client *client, | 253 | static int adt7411_detect(struct i2c_client *client, |
253 | struct i2c_board_info *info) | 254 | struct i2c_board_info *info) |
@@ -281,14 +282,17 @@ static int adt7411_detect(struct i2c_client *client, | |||
281 | static int adt7411_probe(struct i2c_client *client, | 282 | static int adt7411_probe(struct i2c_client *client, |
282 | const struct i2c_device_id *id) | 283 | const struct i2c_device_id *id) |
283 | { | 284 | { |
285 | struct device *dev = &client->dev; | ||
284 | struct adt7411_data *data; | 286 | struct adt7411_data *data; |
287 | struct device *hwmon_dev; | ||
285 | int ret; | 288 | int ret; |
286 | 289 | ||
287 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 290 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
288 | if (!data) | 291 | if (!data) |
289 | return -ENOMEM; | 292 | return -ENOMEM; |
290 | 293 | ||
291 | i2c_set_clientdata(client, data); | 294 | i2c_set_clientdata(client, data); |
295 | data->client = client; | ||
292 | mutex_init(&data->device_lock); | 296 | mutex_init(&data->device_lock); |
293 | mutex_init(&data->update_lock); | 297 | mutex_init(&data->update_lock); |
294 | 298 | ||
@@ -300,32 +304,10 @@ static int adt7411_probe(struct i2c_client *client, | |||
300 | /* force update on first occasion */ | 304 | /* force update on first occasion */ |
301 | data->next_update = jiffies; | 305 | data->next_update = jiffies; |
302 | 306 | ||
303 | ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp); | 307 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
304 | if (ret) | 308 | data, |
305 | return ret; | 309 | adt7411_groups); |
306 | 310 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
307 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
308 | if (IS_ERR(data->hwmon_dev)) { | ||
309 | ret = PTR_ERR(data->hwmon_dev); | ||
310 | goto exit_remove; | ||
311 | } | ||
312 | |||
313 | dev_info(&client->dev, "successfully registered\n"); | ||
314 | |||
315 | return 0; | ||
316 | |||
317 | exit_remove: | ||
318 | sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); | ||
319 | return ret; | ||
320 | } | ||
321 | |||
322 | static int adt7411_remove(struct i2c_client *client) | ||
323 | { | ||
324 | struct adt7411_data *data = i2c_get_clientdata(client); | ||
325 | |||
326 | hwmon_device_unregister(data->hwmon_dev); | ||
327 | sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); | ||
328 | return 0; | ||
329 | } | 311 | } |
330 | 312 | ||
331 | static const struct i2c_device_id adt7411_id[] = { | 313 | static const struct i2c_device_id adt7411_id[] = { |
@@ -339,7 +321,6 @@ static struct i2c_driver adt7411_driver = { | |||
339 | .name = "adt7411", | 321 | .name = "adt7411", |
340 | }, | 322 | }, |
341 | .probe = adt7411_probe, | 323 | .probe = adt7411_probe, |
342 | .remove = adt7411_remove, | ||
343 | .id_table = adt7411_id, | 324 | .id_table = adt7411_id, |
344 | .detect = adt7411_detect, | 325 | .detect = adt7411_detect, |
345 | .address_list = normal_i2c, | 326 | .address_list = normal_i2c, |