aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/atxp1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/atxp1.c')
-rw-r--r--drivers/hwmon/atxp1.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index fca3fc1cef72..5f79f07a4ab8 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -25,6 +25,8 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-sensor.h> 26#include <linux/i2c-sensor.h>
27#include <linux/i2c-vid.h> 27#include <linux/i2c-vid.h>
28#include <linux/hwmon.h>
29#include <linux/err.h>
28 30
29MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
30MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 32MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -59,6 +61,7 @@ static struct i2c_driver atxp1_driver = {
59 61
60struct atxp1_data { 62struct atxp1_data {
61 struct i2c_client client; 63 struct i2c_client client;
64 struct class_device *class_dev;
62 struct semaphore update_lock; 65 struct semaphore update_lock;
63 unsigned long last_updated; 66 unsigned long last_updated;
64 u8 valid; 67 u8 valid;
@@ -317,6 +320,12 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
317 goto exit_free; 320 goto exit_free;
318 } 321 }
319 322
323 data->class_dev = hwmon_device_register(&new_client->dev);
324 if (IS_ERR(data->class_dev)) {
325 err = PTR_ERR(data->class_dev);
326 goto exit_detach;
327 }
328
320 device_create_file(&new_client->dev, &dev_attr_gpio1); 329 device_create_file(&new_client->dev, &dev_attr_gpio1);
321 device_create_file(&new_client->dev, &dev_attr_gpio2); 330 device_create_file(&new_client->dev, &dev_attr_gpio2);
322 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 331 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
@@ -326,6 +335,8 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
326 335
327 return 0; 336 return 0;
328 337
338exit_detach:
339 i2c_detach_client(new_client);
329exit_free: 340exit_free:
330 kfree(data); 341 kfree(data);
331exit: 342exit:
@@ -334,14 +345,17 @@ exit:
334 345
335static int atxp1_detach_client(struct i2c_client * client) 346static int atxp1_detach_client(struct i2c_client * client)
336{ 347{
348 struct atxp1_data * data = i2c_get_clientdata(client);
337 int err; 349 int err;
338 350
351 hwmon_device_unregister(data->class_dev);
352
339 err = i2c_detach_client(client); 353 err = i2c_detach_client(client);
340 354
341 if (err) 355 if (err)
342 dev_err(&client->dev, "Failed to detach client.\n"); 356 dev_err(&client->dev, "Failed to detach client.\n");
343 else 357 else
344 kfree(i2c_get_clientdata(client)); 358 kfree(data);
345 359
346 return err; 360 return err;
347}; 361};