aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-06-06 19:55:10 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:33 -0400
commit11f7e494fd726c119c6f576b4cf1dc09e9f665b8 (patch)
tree823eb3a97ee42ce96ad4a325a2e899d569b66b3a
parentd17a7dca04b23586f6c284f98196fbe0ac7607a8 (diff)
hwmon: (atxp1) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups. This simplifies 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/atxp1.c76
1 files changed, 21 insertions, 55 deletions
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index 2ae8a304b5ef..4c829bb2f9db 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -46,7 +46,7 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
46static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; 46static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
47 47
48struct atxp1_data { 48struct atxp1_data {
49 struct device *hwmon_dev; 49 struct i2c_client *client;
50 struct mutex update_lock; 50 struct mutex update_lock;
51 unsigned long last_updated; 51 unsigned long last_updated;
52 u8 valid; 52 u8 valid;
@@ -61,11 +61,8 @@ struct atxp1_data {
61 61
62static struct atxp1_data *atxp1_update_device(struct device *dev) 62static struct atxp1_data *atxp1_update_device(struct device *dev)
63{ 63{
64 struct i2c_client *client; 64 struct atxp1_data *data = dev_get_drvdata(dev);
65 struct atxp1_data *data; 65 struct i2c_client *client = data->client;
66
67 client = to_i2c_client(dev);
68 data = i2c_get_clientdata(client);
69 66
70 mutex_lock(&data->update_lock); 67 mutex_lock(&data->update_lock);
71 68
@@ -105,15 +102,12 @@ static ssize_t atxp1_storevcore(struct device *dev,
105 struct device_attribute *attr, 102 struct device_attribute *attr,
106 const char *buf, size_t count) 103 const char *buf, size_t count)
107{ 104{
108 struct atxp1_data *data; 105 struct atxp1_data *data = atxp1_update_device(dev);
109 struct i2c_client *client; 106 struct i2c_client *client = data->client;
110 int vid, cvid; 107 int vid, cvid;
111 unsigned long vcore; 108 unsigned long vcore;
112 int err; 109 int err;
113 110
114 client = to_i2c_client(dev);
115 data = atxp1_update_device(dev);
116
117 err = kstrtoul(buf, 10, &vcore); 111 err = kstrtoul(buf, 10, &vcore);
118 if (err) 112 if (err)
119 return err; 113 return err;
@@ -184,14 +178,11 @@ static ssize_t atxp1_storegpio1(struct device *dev,
184 struct device_attribute *attr, const char *buf, 178 struct device_attribute *attr, const char *buf,
185 size_t count) 179 size_t count)
186{ 180{
187 struct atxp1_data *data; 181 struct atxp1_data *data = atxp1_update_device(dev);
188 struct i2c_client *client; 182 struct i2c_client *client = data->client;
189 unsigned long value; 183 unsigned long value;
190 int err; 184 int err;
191 185
192 client = to_i2c_client(dev);
193 data = atxp1_update_device(dev);
194
195 err = kstrtoul(buf, 16, &value); 186 err = kstrtoul(buf, 16, &value);
196 if (err) 187 if (err)
197 return err; 188 return err;
@@ -234,7 +225,7 @@ static ssize_t atxp1_storegpio2(struct device *dev,
234 const char *buf, size_t count) 225 const char *buf, size_t count)
235{ 226{
236 struct atxp1_data *data = atxp1_update_device(dev); 227 struct atxp1_data *data = atxp1_update_device(dev);
237 struct i2c_client *client = to_i2c_client(dev); 228 struct i2c_client *client = data->client;
238 unsigned long value; 229 unsigned long value;
239 int err; 230 int err;
240 231
@@ -260,17 +251,13 @@ static ssize_t atxp1_storegpio2(struct device *dev,
260 */ 251 */
261static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); 252static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
262 253
263static struct attribute *atxp1_attributes[] = { 254static struct attribute *atxp1_attrs[] = {
264 &dev_attr_gpio1.attr, 255 &dev_attr_gpio1.attr,
265 &dev_attr_gpio2.attr, 256 &dev_attr_gpio2.attr,
266 &dev_attr_cpu0_vid.attr, 257 &dev_attr_cpu0_vid.attr,
267 NULL 258 NULL
268}; 259};
269 260ATTRIBUTE_GROUPS(atxp1);
270static const struct attribute_group atxp1_group = {
271 .attrs = atxp1_attributes,
272};
273
274 261
275/* Return 0 if detection is successful, -ENODEV otherwise */ 262/* Return 0 if detection is successful, -ENODEV otherwise */
276static int atxp1_detect(struct i2c_client *new_client, 263static int atxp1_detect(struct i2c_client *new_client,
@@ -314,50 +301,30 @@ static int atxp1_detect(struct i2c_client *new_client,
314 return 0; 301 return 0;
315} 302}
316 303
317static int atxp1_probe(struct i2c_client *new_client, 304static int atxp1_probe(struct i2c_client *client,
318 const struct i2c_device_id *id) 305 const struct i2c_device_id *id)
319{ 306{
307 struct device *dev = &client->dev;
320 struct atxp1_data *data; 308 struct atxp1_data *data;
321 int err; 309 struct device *hwmon_dev;
322 310
323 data = devm_kzalloc(&new_client->dev, sizeof(struct atxp1_data), 311 data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL);
324 GFP_KERNEL);
325 if (!data) 312 if (!data)
326 return -ENOMEM; 313 return -ENOMEM;
327 314
328 /* Get VRM */ 315 /* Get VRM */
329 data->vrm = vid_which_vrm(); 316 data->vrm = vid_which_vrm();
330 317
331 i2c_set_clientdata(new_client, data); 318 data->client = client;
332 mutex_init(&data->update_lock); 319 mutex_init(&data->update_lock);
333 320
334 /* Register sysfs hooks */ 321 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
335 err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group); 322 data,
336 if (err) 323 atxp1_groups);
337 return err; 324 if (IS_ERR(hwmon_dev))
338 325 return PTR_ERR(hwmon_dev);
339 data->hwmon_dev = hwmon_device_register(&new_client->dev);
340 if (IS_ERR(data->hwmon_dev)) {
341 err = PTR_ERR(data->hwmon_dev);
342 goto exit_remove_files;
343 }
344
345 dev_info(&new_client->dev, "Using VRM: %d.%d\n",
346 data->vrm / 10, data->vrm % 10);
347
348 return 0;
349
350exit_remove_files:
351 sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
352 return err;
353};
354
355static int atxp1_remove(struct i2c_client *client)
356{
357 struct atxp1_data *data = i2c_get_clientdata(client);
358 326
359 hwmon_device_unregister(data->hwmon_dev); 327 dev_info(dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10);
360 sysfs_remove_group(&client->dev.kobj, &atxp1_group);
361 328
362 return 0; 329 return 0;
363}; 330};
@@ -374,7 +341,6 @@ static struct i2c_driver atxp1_driver = {
374 .name = "atxp1", 341 .name = "atxp1",
375 }, 342 },
376 .probe = atxp1_probe, 343 .probe = atxp1_probe,
377 .remove = atxp1_remove,
378 .id_table = atxp1_id, 344 .id_table = atxp1_id,
379 .detect = atxp1_detect, 345 .detect = atxp1_detect,
380 .address_list = normal_i2c, 346 .address_list = normal_i2c,