diff options
Diffstat (limited to 'drivers/hwmon/pcf8591.c')
-rw-r--r-- | drivers/hwmon/pcf8591.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c index d44787949851..731b09af76b9 100644 --- a/drivers/hwmon/pcf8591.c +++ b/drivers/hwmon/pcf8591.c | |||
@@ -18,15 +18,15 @@ | |||
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
22 | |||
21 | #include <linux/module.h> | 23 | #include <linux/module.h> |
22 | #include <linux/init.h> | 24 | #include <linux/init.h> |
23 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
24 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
25 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
26 | 28 | #include <linux/err.h> | |
27 | /* Addresses to scan */ | 29 | #include <linux/hwmon.h> |
28 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, | ||
29 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; | ||
30 | 30 | ||
31 | /* Insmod parameters */ | 31 | /* Insmod parameters */ |
32 | 32 | ||
@@ -71,6 +71,7 @@ MODULE_PARM_DESC(input_mode, | |||
71 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) | 71 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) |
72 | 72 | ||
73 | struct pcf8591_data { | 73 | struct pcf8591_data { |
74 | struct device *hwmon_dev; | ||
74 | struct mutex update_lock; | 75 | struct mutex update_lock; |
75 | 76 | ||
76 | u8 control; | 77 | u8 control; |
@@ -167,24 +168,6 @@ static const struct attribute_group pcf8591_attr_group_opt = { | |||
167 | * Real code | 168 | * Real code |
168 | */ | 169 | */ |
169 | 170 | ||
170 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
171 | static int pcf8591_detect(struct i2c_client *client, | ||
172 | struct i2c_board_info *info) | ||
173 | { | ||
174 | struct i2c_adapter *adapter = client->adapter; | ||
175 | |||
176 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | ||
177 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | ||
178 | return -ENODEV; | ||
179 | |||
180 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
181 | impossible to detect! Stupid chip. */ | ||
182 | |||
183 | strlcpy(info->type, "pcf8591", I2C_NAME_SIZE); | ||
184 | |||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | static int pcf8591_probe(struct i2c_client *client, | 171 | static int pcf8591_probe(struct i2c_client *client, |
189 | const struct i2c_device_id *id) | 172 | const struct i2c_device_id *id) |
190 | { | 173 | { |
@@ -221,6 +204,12 @@ static int pcf8591_probe(struct i2c_client *client, | |||
221 | goto exit_sysfs_remove; | 204 | goto exit_sysfs_remove; |
222 | } | 205 | } |
223 | 206 | ||
207 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
208 | if (IS_ERR(data->hwmon_dev)) { | ||
209 | err = PTR_ERR(data->hwmon_dev); | ||
210 | goto exit_sysfs_remove; | ||
211 | } | ||
212 | |||
224 | return 0; | 213 | return 0; |
225 | 214 | ||
226 | exit_sysfs_remove: | 215 | exit_sysfs_remove: |
@@ -234,6 +223,9 @@ exit: | |||
234 | 223 | ||
235 | static int pcf8591_remove(struct i2c_client *client) | 224 | static int pcf8591_remove(struct i2c_client *client) |
236 | { | 225 | { |
226 | struct pcf8591_data *data = i2c_get_clientdata(client); | ||
227 | |||
228 | hwmon_device_unregister(data->hwmon_dev); | ||
237 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 229 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
238 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 230 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
239 | kfree(i2c_get_clientdata(client)); | 231 | kfree(i2c_get_clientdata(client)); |
@@ -295,17 +287,12 @@ static struct i2c_driver pcf8591_driver = { | |||
295 | .probe = pcf8591_probe, | 287 | .probe = pcf8591_probe, |
296 | .remove = pcf8591_remove, | 288 | .remove = pcf8591_remove, |
297 | .id_table = pcf8591_id, | 289 | .id_table = pcf8591_id, |
298 | |||
299 | .class = I2C_CLASS_HWMON, /* Nearest choice */ | ||
300 | .detect = pcf8591_detect, | ||
301 | .address_list = normal_i2c, | ||
302 | }; | 290 | }; |
303 | 291 | ||
304 | static int __init pcf8591_init(void) | 292 | static int __init pcf8591_init(void) |
305 | { | 293 | { |
306 | if (input_mode < 0 || input_mode > 3) { | 294 | if (input_mode < 0 || input_mode > 3) { |
307 | printk(KERN_WARNING "pcf8591: invalid input_mode (%d)\n", | 295 | pr_warn("invalid input_mode (%d)\n", input_mode); |
308 | input_mode); | ||
309 | input_mode = 0; | 296 | input_mode = 0; |
310 | } | 297 | } |
311 | return i2c_add_driver(&pcf8591_driver); | 298 | return i2c_add_driver(&pcf8591_driver); |