diff options
Diffstat (limited to 'drivers/hwmon/w83627hf.c')
-rw-r--r-- | drivers/hwmon/w83627hf.c | 80 |
1 files changed, 33 insertions, 47 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index bd87a42e068a..02bd5c0239a2 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -42,8 +42,10 @@ | |||
42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
43 | #include <linux/jiffies.h> | 43 | #include <linux/jiffies.h> |
44 | #include <linux/i2c.h> | 44 | #include <linux/i2c.h> |
45 | #include <linux/i2c-sensor.h> | 45 | #include <linux/i2c-isa.h> |
46 | #include <linux/i2c-vid.h> | 46 | #include <linux/hwmon.h> |
47 | #include <linux/hwmon-vid.h> | ||
48 | #include <linux/err.h> | ||
47 | #include <asm/io.h> | 49 | #include <asm/io.h> |
48 | #include "lm75.h" | 50 | #include "lm75.h" |
49 | 51 | ||
@@ -56,12 +58,11 @@ module_param(force_i2c, byte, 0); | |||
56 | MODULE_PARM_DESC(force_i2c, | 58 | MODULE_PARM_DESC(force_i2c, |
57 | "Initialize the i2c address of the sensors"); | 59 | "Initialize the i2c address of the sensors"); |
58 | 60 | ||
59 | /* Addresses to scan */ | 61 | /* The actual ISA address is read from Super-I/O configuration space */ |
60 | static unsigned short normal_i2c[] = { I2C_CLIENT_END }; | 62 | static unsigned short address; |
61 | static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END }; | ||
62 | 63 | ||
63 | /* Insmod parameters */ | 64 | /* Insmod parameters */ |
64 | SENSORS_INSMOD_4(w83627hf, w83627thf, w83697hf, w83637hf); | 65 | enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf }; |
65 | 66 | ||
66 | static int init = 1; | 67 | static int init = 1; |
67 | module_param(init, bool, 0); | 68 | module_param(init, bool, 0); |
@@ -277,6 +278,7 @@ static inline u8 DIV_TO_REG(long val) | |||
277 | dynamically allocated, at the same time when a new client is allocated. */ | 278 | dynamically allocated, at the same time when a new client is allocated. */ |
278 | struct w83627hf_data { | 279 | struct w83627hf_data { |
279 | struct i2c_client client; | 280 | struct i2c_client client; |
281 | struct class_device *class_dev; | ||
280 | struct semaphore lock; | 282 | struct semaphore lock; |
281 | enum chips type; | 283 | enum chips type; |
282 | 284 | ||
@@ -314,9 +316,7 @@ struct w83627hf_data { | |||
314 | }; | 316 | }; |
315 | 317 | ||
316 | 318 | ||
317 | static int w83627hf_attach_adapter(struct i2c_adapter *adapter); | 319 | static int w83627hf_detect(struct i2c_adapter *adapter); |
318 | static int w83627hf_detect(struct i2c_adapter *adapter, int address, | ||
319 | int kind); | ||
320 | static int w83627hf_detach_client(struct i2c_client *client); | 320 | static int w83627hf_detach_client(struct i2c_client *client); |
321 | 321 | ||
322 | static int w83627hf_read_value(struct i2c_client *client, u16 register); | 322 | static int w83627hf_read_value(struct i2c_client *client, u16 register); |
@@ -328,9 +328,7 @@ static void w83627hf_init_client(struct i2c_client *client); | |||
328 | static struct i2c_driver w83627hf_driver = { | 328 | static struct i2c_driver w83627hf_driver = { |
329 | .owner = THIS_MODULE, | 329 | .owner = THIS_MODULE, |
330 | .name = "w83627hf", | 330 | .name = "w83627hf", |
331 | .id = I2C_DRIVERID_W83627HF, | 331 | .attach_adapter = w83627hf_detect, |
332 | .flags = I2C_DF_NOTIFY, | ||
333 | .attach_adapter = w83627hf_attach_adapter, | ||
334 | .detach_client = w83627hf_detach_client, | 332 | .detach_client = w83627hf_detach_client, |
335 | }; | 333 | }; |
336 | 334 | ||
@@ -959,16 +957,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_type); \ | |||
959 | } while (0) | 957 | } while (0) |
960 | 958 | ||
961 | 959 | ||
962 | /* This function is called when: | 960 | static int __init w83627hf_find(int sioaddr, unsigned short *addr) |
963 | * w83627hf_driver is inserted (when this module is loaded), for each | ||
964 | available adapter | ||
965 | * when a new adapter is inserted (and w83627hf_driver is still present) */ | ||
966 | static int w83627hf_attach_adapter(struct i2c_adapter *adapter) | ||
967 | { | ||
968 | return i2c_detect(adapter, &addr_data, w83627hf_detect); | ||
969 | } | ||
970 | |||
971 | static int w83627hf_find(int sioaddr, int *address) | ||
972 | { | 961 | { |
973 | u16 val; | 962 | u16 val; |
974 | 963 | ||
@@ -988,32 +977,24 @@ static int w83627hf_find(int sioaddr, int *address) | |||
988 | superio_select(W83627HF_LD_HWM); | 977 | superio_select(W83627HF_LD_HWM); |
989 | val = (superio_inb(WINB_BASE_REG) << 8) | | 978 | val = (superio_inb(WINB_BASE_REG) << 8) | |
990 | superio_inb(WINB_BASE_REG + 1); | 979 | superio_inb(WINB_BASE_REG + 1); |
991 | *address = val & ~(WINB_EXTENT - 1); | 980 | *addr = val & ~(WINB_EXTENT - 1); |
992 | if (*address == 0 && force_addr == 0) { | 981 | if (*addr == 0 && force_addr == 0) { |
993 | superio_exit(); | 982 | superio_exit(); |
994 | return -ENODEV; | 983 | return -ENODEV; |
995 | } | 984 | } |
996 | if (force_addr) | ||
997 | *address = force_addr; /* so detect will get called */ | ||
998 | 985 | ||
999 | superio_exit(); | 986 | superio_exit(); |
1000 | return 0; | 987 | return 0; |
1001 | } | 988 | } |
1002 | 989 | ||
1003 | int w83627hf_detect(struct i2c_adapter *adapter, int address, | 990 | static int w83627hf_detect(struct i2c_adapter *adapter) |
1004 | int kind) | ||
1005 | { | 991 | { |
1006 | int val; | 992 | int val, kind; |
1007 | struct i2c_client *new_client; | 993 | struct i2c_client *new_client; |
1008 | struct w83627hf_data *data; | 994 | struct w83627hf_data *data; |
1009 | int err = 0; | 995 | int err = 0; |
1010 | const char *client_name = ""; | 996 | const char *client_name = ""; |
1011 | 997 | ||
1012 | if (!i2c_is_isa_adapter(adapter)) { | ||
1013 | err = -ENODEV; | ||
1014 | goto ERROR0; | ||
1015 | } | ||
1016 | |||
1017 | if(force_addr) | 998 | if(force_addr) |
1018 | address = force_addr & ~(WINB_EXTENT - 1); | 999 | address = force_addr & ~(WINB_EXTENT - 1); |
1019 | 1000 | ||
@@ -1102,6 +1083,12 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1102 | data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); | 1083 | data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); |
1103 | 1084 | ||
1104 | /* Register sysfs hooks */ | 1085 | /* Register sysfs hooks */ |
1086 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1087 | if (IS_ERR(data->class_dev)) { | ||
1088 | err = PTR_ERR(data->class_dev); | ||
1089 | goto ERROR3; | ||
1090 | } | ||
1091 | |||
1105 | device_create_file_in(new_client, 0); | 1092 | device_create_file_in(new_client, 0); |
1106 | if (kind != w83697hf) | 1093 | if (kind != w83697hf) |
1107 | device_create_file_in(new_client, 1); | 1094 | device_create_file_in(new_client, 1); |
@@ -1152,6 +1139,8 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1152 | 1139 | ||
1153 | return 0; | 1140 | return 0; |
1154 | 1141 | ||
1142 | ERROR3: | ||
1143 | i2c_detach_client(new_client); | ||
1155 | ERROR2: | 1144 | ERROR2: |
1156 | kfree(data); | 1145 | kfree(data); |
1157 | ERROR1: | 1146 | ERROR1: |
@@ -1162,16 +1151,16 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1162 | 1151 | ||
1163 | static int w83627hf_detach_client(struct i2c_client *client) | 1152 | static int w83627hf_detach_client(struct i2c_client *client) |
1164 | { | 1153 | { |
1154 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
1165 | int err; | 1155 | int err; |
1166 | 1156 | ||
1167 | if ((err = i2c_detach_client(client))) { | 1157 | hwmon_device_unregister(data->class_dev); |
1168 | dev_err(&client->dev, | 1158 | |
1169 | "Client deregistration failed, client not detached.\n"); | 1159 | if ((err = i2c_detach_client(client))) |
1170 | return err; | 1160 | return err; |
1171 | } | ||
1172 | 1161 | ||
1173 | release_region(client->addr, WINB_EXTENT); | 1162 | release_region(client->addr, WINB_EXTENT); |
1174 | kfree(i2c_get_clientdata(client)); | 1163 | kfree(data); |
1175 | 1164 | ||
1176 | return 0; | 1165 | return 0; |
1177 | } | 1166 | } |
@@ -1327,7 +1316,7 @@ static void w83627hf_init_client(struct i2c_client *client) | |||
1327 | data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82; | 1316 | data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82; |
1328 | } else { | 1317 | } else { |
1329 | /* Convert VID to voltage based on default VRM */ | 1318 | /* Convert VID to voltage based on default VRM */ |
1330 | data->vrm = i2c_which_vrm(); | 1319 | data->vrm = vid_which_vrm(); |
1331 | } | 1320 | } |
1332 | 1321 | ||
1333 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); | 1322 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); |
@@ -1485,20 +1474,17 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1485 | 1474 | ||
1486 | static int __init sensors_w83627hf_init(void) | 1475 | static int __init sensors_w83627hf_init(void) |
1487 | { | 1476 | { |
1488 | int addr; | 1477 | if (w83627hf_find(0x2e, &address) |
1489 | 1478 | && w83627hf_find(0x4e, &address)) { | |
1490 | if (w83627hf_find(0x2e, &addr) | ||
1491 | && w83627hf_find(0x4e, &addr)) { | ||
1492 | return -ENODEV; | 1479 | return -ENODEV; |
1493 | } | 1480 | } |
1494 | normal_isa[0] = addr; | ||
1495 | 1481 | ||
1496 | return i2c_add_driver(&w83627hf_driver); | 1482 | return i2c_isa_add_driver(&w83627hf_driver); |
1497 | } | 1483 | } |
1498 | 1484 | ||
1499 | static void __exit sensors_w83627hf_exit(void) | 1485 | static void __exit sensors_w83627hf_exit(void) |
1500 | { | 1486 | { |
1501 | i2c_del_driver(&w83627hf_driver); | 1487 | i2c_isa_del_driver(&w83627hf_driver); |
1502 | } | 1488 | } |
1503 | 1489 | ||
1504 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " | 1490 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " |