diff options
author | Mark M. Hoffman <mhoffman@lightlink.com> | 2005-07-15 21:39:18 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-05 12:14:08 -0400 |
commit | 943b0830cebe4711354945ed3cb44e84152aaca0 (patch) | |
tree | 1963da8d8867069617404a8f92739035c6faca02 /drivers/hwmon/via686a.c | |
parent | 1236441f38b6a98caf4c7983e7efdecc2d1527b5 (diff) |
[PATCH] I2C hwmon: add hwmon sysfs class to drivers
This patch modifies sensors chip drivers to make use of the new
sysfs class "hwmon".
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon/via686a.c')
-rw-r--r-- | drivers/hwmon/via686a.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 164d47948390..8eb9d084149d 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <linux/jiffies.h> | 36 | #include <linux/jiffies.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/i2c.h> |
38 | #include <linux/i2c-sensor.h> | 38 | #include <linux/i2c-sensor.h> |
39 | #include <linux/hwmon.h> | ||
40 | #include <linux/err.h> | ||
39 | #include <linux/init.h> | 41 | #include <linux/init.h> |
40 | #include <asm/io.h> | 42 | #include <asm/io.h> |
41 | 43 | ||
@@ -297,6 +299,7 @@ static inline long TEMP_FROM_REG10(u16 val) | |||
297 | via686a client is allocated. */ | 299 | via686a client is allocated. */ |
298 | struct via686a_data { | 300 | struct via686a_data { |
299 | struct i2c_client client; | 301 | struct i2c_client client; |
302 | struct class_device *class_dev; | ||
300 | struct semaphore update_lock; | 303 | struct semaphore update_lock; |
301 | char valid; /* !=0 if following fields are valid */ | 304 | char valid; /* !=0 if following fields are valid */ |
302 | unsigned long last_updated; /* In jiffies */ | 305 | unsigned long last_updated; /* In jiffies */ |
@@ -637,7 +640,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
637 | 640 | ||
638 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { | 641 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { |
639 | err = -ENOMEM; | 642 | err = -ENOMEM; |
640 | goto ERROR0; | 643 | goto exit_release; |
641 | } | 644 | } |
642 | memset(data, 0, sizeof(struct via686a_data)); | 645 | memset(data, 0, sizeof(struct via686a_data)); |
643 | 646 | ||
@@ -655,12 +658,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
655 | init_MUTEX(&data->update_lock); | 658 | init_MUTEX(&data->update_lock); |
656 | /* Tell the I2C layer a new client has arrived */ | 659 | /* Tell the I2C layer a new client has arrived */ |
657 | if ((err = i2c_attach_client(new_client))) | 660 | if ((err = i2c_attach_client(new_client))) |
658 | goto ERROR3; | 661 | goto exit_free; |
659 | 662 | ||
660 | /* Initialize the VIA686A chip */ | 663 | /* Initialize the VIA686A chip */ |
661 | via686a_init_client(new_client); | 664 | via686a_init_client(new_client); |
662 | 665 | ||
663 | /* Register sysfs hooks */ | 666 | /* Register sysfs hooks */ |
667 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
668 | if (IS_ERR(data->class_dev)) { | ||
669 | err = PTR_ERR(data->class_dev); | ||
670 | goto exit_detach; | ||
671 | } | ||
672 | |||
664 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 673 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
665 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 674 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
666 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 675 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
@@ -695,17 +704,22 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
695 | 704 | ||
696 | return 0; | 705 | return 0; |
697 | 706 | ||
698 | ERROR3: | 707 | exit_detach: |
708 | i2c_detach_client(new_client); | ||
709 | exit_free: | ||
699 | kfree(data); | 710 | kfree(data); |
700 | ERROR0: | 711 | exit_release: |
701 | release_region(address, VIA686A_EXTENT); | 712 | release_region(address, VIA686A_EXTENT); |
702 | return err; | 713 | return err; |
703 | } | 714 | } |
704 | 715 | ||
705 | static int via686a_detach_client(struct i2c_client *client) | 716 | static int via686a_detach_client(struct i2c_client *client) |
706 | { | 717 | { |
718 | struct via686a_data *data = i2c_get_clientdata(client); | ||
707 | int err; | 719 | int err; |
708 | 720 | ||
721 | hwmon_device_unregister(data->class_dev); | ||
722 | |||
709 | if ((err = i2c_detach_client(client))) { | 723 | if ((err = i2c_detach_client(client))) { |
710 | dev_err(&client->dev, | 724 | dev_err(&client->dev, |
711 | "Client deregistration failed, client not detached.\n"); | 725 | "Client deregistration failed, client not detached.\n"); |
@@ -713,7 +727,7 @@ static int via686a_detach_client(struct i2c_client *client) | |||
713 | } | 727 | } |
714 | 728 | ||
715 | release_region(client->addr, VIA686A_EXTENT); | 729 | release_region(client->addr, VIA686A_EXTENT); |
716 | kfree(i2c_get_clientdata(client)); | 730 | kfree(data); |
717 | 731 | ||
718 | return 0; | 732 | return 0; |
719 | } | 733 | } |