diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2008-07-21 00:55:14 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2008-07-21 00:55:14 -0400 |
commit | 908cf4b925e419bc74f3297b2f0e51d6f8a81da2 (patch) | |
tree | 6c2da79366d4695a9c2560ab18259eca8a2a25b4 /drivers/hwmon | |
parent | 92c49890922d54cba4b1eadeb0b185773c2c9570 (diff) | |
parent | 14b395e35d1afdd8019d11b92e28041fad591b71 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into next
Diffstat (limited to 'drivers/hwmon')
45 files changed, 3000 insertions, 2349 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 4dc76bc45c9d..00ff53348491 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -330,6 +330,20 @@ config SENSORS_CORETEMP | |||
330 | sensor inside your CPU. Supported all are all known variants | 330 | sensor inside your CPU. Supported all are all known variants |
331 | of Intel Core family. | 331 | of Intel Core family. |
332 | 332 | ||
333 | config SENSORS_IBMAEM | ||
334 | tristate "IBM Active Energy Manager temperature/power sensors and control" | ||
335 | select IPMI_SI | ||
336 | depends on IPMI_HANDLER | ||
337 | help | ||
338 | If you say yes here you get support for the temperature and | ||
339 | power sensors and capping hardware in various IBM System X | ||
340 | servers that support Active Energy Manager. This includes | ||
341 | the x3350, x3550, x3650, x3655, x3755, x3850 M2, x3950 M2, | ||
342 | and certain HS2x/LS2x/QS2x blades. | ||
343 | |||
344 | This driver can also be built as a module. If so, the module | ||
345 | will be called ibmaem. | ||
346 | |||
333 | config SENSORS_IBMPEX | 347 | config SENSORS_IBMPEX |
334 | tristate "IBM PowerExecutive temperature/power sensors" | 348 | tristate "IBM PowerExecutive temperature/power sensors" |
335 | select IPMI_SI | 349 | select IPMI_SI |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 3bdb05a5cbd7..d098677e08de 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o | |||
41 | obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o | 41 | obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o |
42 | obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o | 42 | obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o |
43 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o | 43 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o |
44 | obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o | ||
44 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o | 45 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o |
45 | obj-$(CONFIG_SENSORS_IT87) += it87.o | 46 | obj-$(CONFIG_SENSORS_IT87) += it87.o |
46 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o | 47 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o |
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c index ed33fddc4dee..f00f497b9ca9 100644 --- a/drivers/hwmon/abituguru3.c +++ b/drivers/hwmon/abituguru3.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/hwmon.h> | 31 | #include <linux/hwmon.h> |
32 | #include <linux/hwmon-sysfs.h> | 32 | #include <linux/hwmon-sysfs.h> |
33 | #include <linux/dmi.h> | ||
33 | #include <asm/io.h> | 34 | #include <asm/io.h> |
34 | 35 | ||
35 | /* uGuru3 bank addresses */ | 36 | /* uGuru3 bank addresses */ |
@@ -323,7 +324,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { | |||
323 | { "AUX1 Fan", 36, 2, 60, 1, 0 }, | 324 | { "AUX1 Fan", 36, 2, 60, 1, 0 }, |
324 | { NULL, 0, 0, 0, 0, 0 } } | 325 | { NULL, 0, 0, 0, 0, 0 } } |
325 | }, | 326 | }, |
326 | { 0x0013, "unknown", { | 327 | { 0x0013, "Abit AW8D", { |
327 | { "CPU Core", 0, 0, 10, 1, 0 }, | 328 | { "CPU Core", 0, 0, 10, 1, 0 }, |
328 | { "DDR", 1, 0, 10, 1, 0 }, | 329 | { "DDR", 1, 0, 10, 1, 0 }, |
329 | { "DDR VTT", 2, 0, 10, 1, 0 }, | 330 | { "DDR VTT", 2, 0, 10, 1, 0 }, |
@@ -349,6 +350,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { | |||
349 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | 350 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, |
350 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, | 351 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, |
351 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, | 352 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, |
353 | { "AUX5 Fan", 39, 2, 60, 1, 0 }, | ||
352 | { NULL, 0, 0, 0, 0, 0 } } | 354 | { NULL, 0, 0, 0, 0, 0 } } |
353 | }, | 355 | }, |
354 | { 0x0014, "Abit AB9 Pro", { | 356 | { 0x0014, "Abit AB9 Pro", { |
@@ -1111,11 +1113,12 @@ static int __init abituguru3_detect(void) | |||
1111 | { | 1113 | { |
1112 | /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or | 1114 | /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or |
1113 | 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 | 1115 | 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 |
1114 | at CMD instead, why is unknown. So we test for 0x05 too. */ | 1116 | or 0x55 at CMD instead, why is unknown. */ |
1115 | u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); | 1117 | u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); |
1116 | u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); | 1118 | u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); |
1117 | if (((data_val == 0x00) || (data_val == 0x08)) && | 1119 | if (((data_val == 0x00) || (data_val == 0x08)) && |
1118 | ((cmd_val == 0xAC) || (cmd_val == 0x05))) | 1120 | ((cmd_val == 0xAC) || (cmd_val == 0x05) || |
1121 | (cmd_val == 0x55))) | ||
1119 | return ABIT_UGURU3_BASE; | 1122 | return ABIT_UGURU3_BASE; |
1120 | 1123 | ||
1121 | ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " | 1124 | ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " |
@@ -1138,6 +1141,15 @@ static int __init abituguru3_init(void) | |||
1138 | int address, err; | 1141 | int address, err; |
1139 | struct resource res = { .flags = IORESOURCE_IO }; | 1142 | struct resource res = { .flags = IORESOURCE_IO }; |
1140 | 1143 | ||
1144 | #ifdef CONFIG_DMI | ||
1145 | const char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); | ||
1146 | |||
1147 | /* safety check, refuse to load on non Abit motherboards */ | ||
1148 | if (!force && (!board_vendor || | ||
1149 | strcmp(board_vendor, "http://www.abit.com.tw/"))) | ||
1150 | return -ENODEV; | ||
1151 | #endif | ||
1152 | |||
1141 | address = abituguru3_detect(); | 1153 | address = abituguru3_detect(); |
1142 | if (address < 0) | 1154 | if (address < 0) |
1143 | return address; | 1155 | return address; |
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c index 466b9ee92797..f97b5b356875 100644 --- a/drivers/hwmon/ad7418.c +++ b/drivers/hwmon/ad7418.c | |||
@@ -23,12 +23,9 @@ | |||
23 | 23 | ||
24 | #include "lm75.h" | 24 | #include "lm75.h" |
25 | 25 | ||
26 | #define DRV_VERSION "0.3" | 26 | #define DRV_VERSION "0.4" |
27 | 27 | ||
28 | /* Addresses to scan */ | 28 | enum chips { ad7416, ad7417, ad7418 }; |
29 | static const unsigned short normal_i2c[] = { 0x28, I2C_CLIENT_END }; | ||
30 | /* Insmod parameters */ | ||
31 | I2C_CLIENT_INSMOD_3(ad7416, ad7417, ad7418); | ||
32 | 29 | ||
33 | /* AD7418 registers */ | 30 | /* AD7418 registers */ |
34 | #define AD7418_REG_TEMP_IN 0x00 | 31 | #define AD7418_REG_TEMP_IN 0x00 |
@@ -46,7 +43,6 @@ static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN, | |||
46 | AD7418_REG_TEMP_OS }; | 43 | AD7418_REG_TEMP_OS }; |
47 | 44 | ||
48 | struct ad7418_data { | 45 | struct ad7418_data { |
49 | struct i2c_client client; | ||
50 | struct device *hwmon_dev; | 46 | struct device *hwmon_dev; |
51 | struct attribute_group attrs; | 47 | struct attribute_group attrs; |
52 | enum chips type; | 48 | enum chips type; |
@@ -58,16 +54,25 @@ struct ad7418_data { | |||
58 | u16 in[4]; | 54 | u16 in[4]; |
59 | }; | 55 | }; |
60 | 56 | ||
61 | static int ad7418_attach_adapter(struct i2c_adapter *adapter); | 57 | static int ad7418_probe(struct i2c_client *client, |
62 | static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind); | 58 | const struct i2c_device_id *id); |
63 | static int ad7418_detach_client(struct i2c_client *client); | 59 | static int ad7418_remove(struct i2c_client *client); |
60 | |||
61 | static const struct i2c_device_id ad7418_id[] = { | ||
62 | { "ad7416", ad7416 }, | ||
63 | { "ad7417", ad7417 }, | ||
64 | { "ad7418", ad7418 }, | ||
65 | { } | ||
66 | }; | ||
67 | MODULE_DEVICE_TABLE(i2c, ad7418_id); | ||
64 | 68 | ||
65 | static struct i2c_driver ad7418_driver = { | 69 | static struct i2c_driver ad7418_driver = { |
66 | .driver = { | 70 | .driver = { |
67 | .name = "ad7418", | 71 | .name = "ad7418", |
68 | }, | 72 | }, |
69 | .attach_adapter = ad7418_attach_adapter, | 73 | .probe = ad7418_probe, |
70 | .detach_client = ad7418_detach_client, | 74 | .remove = ad7418_remove, |
75 | .id_table = ad7418_id, | ||
71 | }; | 76 | }; |
72 | 77 | ||
73 | /* All registers are word-sized, except for the configuration registers. | 78 | /* All registers are word-sized, except for the configuration registers. |
@@ -192,13 +197,6 @@ static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 1); | |||
192 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); | 197 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); |
193 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); | 198 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); |
194 | 199 | ||
195 | static int ad7418_attach_adapter(struct i2c_adapter *adapter) | ||
196 | { | ||
197 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
198 | return 0; | ||
199 | return i2c_probe(adapter, &addr_data, ad7418_detect); | ||
200 | } | ||
201 | |||
202 | static struct attribute *ad7416_attributes[] = { | 200 | static struct attribute *ad7416_attributes[] = { |
203 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 201 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
204 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 202 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
@@ -225,98 +223,46 @@ static struct attribute *ad7418_attributes[] = { | |||
225 | NULL | 223 | NULL |
226 | }; | 224 | }; |
227 | 225 | ||
228 | static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | 226 | static int ad7418_probe(struct i2c_client *client, |
227 | const struct i2c_device_id *id) | ||
229 | { | 228 | { |
230 | struct i2c_client *client; | 229 | struct i2c_adapter *adapter = client->adapter; |
231 | struct ad7418_data *data; | 230 | struct ad7418_data *data; |
232 | int err = 0; | 231 | int err; |
233 | 232 | ||
234 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 233 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
235 | I2C_FUNC_SMBUS_WORD_DATA)) | 234 | I2C_FUNC_SMBUS_WORD_DATA)) { |
235 | err = -EOPNOTSUPP; | ||
236 | goto exit; | 236 | goto exit; |
237 | } | ||
237 | 238 | ||
238 | if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) { | 239 | if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) { |
239 | err = -ENOMEM; | 240 | err = -ENOMEM; |
240 | goto exit; | 241 | goto exit; |
241 | } | 242 | } |
242 | 243 | ||
243 | client = &data->client; | ||
244 | client->addr = address; | ||
245 | client->adapter = adapter; | ||
246 | client->driver = &ad7418_driver; | ||
247 | |||
248 | i2c_set_clientdata(client, data); | 244 | i2c_set_clientdata(client, data); |
249 | 245 | ||
250 | mutex_init(&data->lock); | 246 | mutex_init(&data->lock); |
251 | 247 | data->type = id->driver_data; | |
252 | /* AD7418 has a curious behaviour on registers 6 and 7. They | ||
253 | * both always read 0xC071 and are not documented on the datasheet. | ||
254 | * We use them to detect the chip. | ||
255 | */ | ||
256 | if (kind <= 0) { | ||
257 | int reg, reg6, reg7; | ||
258 | |||
259 | /* the AD7416 lies within this address range, but I have | ||
260 | * no means to check. | ||
261 | */ | ||
262 | if (address >= 0x48 && address <= 0x4f) { | ||
263 | /* XXX add tests for AD7416 here */ | ||
264 | /* data->type = ad7416; */ | ||
265 | } | ||
266 | /* here we might have AD7417 or AD7418 */ | ||
267 | else if (address >= 0x28 && address <= 0x2f) { | ||
268 | reg6 = i2c_smbus_read_word_data(client, 0x06); | ||
269 | reg7 = i2c_smbus_read_word_data(client, 0x07); | ||
270 | |||
271 | if (address == 0x28 && reg6 == 0xC071 && reg7 == 0xC071) | ||
272 | data->type = ad7418; | ||
273 | |||
274 | /* XXX add tests for AD7417 here */ | ||
275 | |||
276 | |||
277 | /* both AD7417 and AD7418 have bits 0-5 of | ||
278 | * the CONF2 register at 0 | ||
279 | */ | ||
280 | reg = i2c_smbus_read_byte_data(client, | ||
281 | AD7418_REG_CONF2); | ||
282 | if (reg & 0x3F) | ||
283 | data->type = any_chip; /* detection failed */ | ||
284 | } | ||
285 | } else { | ||
286 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
287 | } | ||
288 | |||
289 | if (kind > 0) | ||
290 | data->type = kind; | ||
291 | else if (kind < 0 && data->type == any_chip) { | ||
292 | err = -ENODEV; | ||
293 | goto exit_free; | ||
294 | } | ||
295 | 248 | ||
296 | switch (data->type) { | 249 | switch (data->type) { |
297 | case any_chip: | ||
298 | case ad7416: | 250 | case ad7416: |
299 | data->adc_max = 0; | 251 | data->adc_max = 0; |
300 | data->attrs.attrs = ad7416_attributes; | 252 | data->attrs.attrs = ad7416_attributes; |
301 | strlcpy(client->name, "ad7416", I2C_NAME_SIZE); | ||
302 | break; | 253 | break; |
303 | 254 | ||
304 | case ad7417: | 255 | case ad7417: |
305 | data->adc_max = 4; | 256 | data->adc_max = 4; |
306 | data->attrs.attrs = ad7417_attributes; | 257 | data->attrs.attrs = ad7417_attributes; |
307 | strlcpy(client->name, "ad7417", I2C_NAME_SIZE); | ||
308 | break; | 258 | break; |
309 | 259 | ||
310 | case ad7418: | 260 | case ad7418: |
311 | data->adc_max = 1; | 261 | data->adc_max = 1; |
312 | data->attrs.attrs = ad7418_attributes; | 262 | data->attrs.attrs = ad7418_attributes; |
313 | strlcpy(client->name, "ad7418", I2C_NAME_SIZE); | ||
314 | break; | 263 | break; |
315 | } | 264 | } |
316 | 265 | ||
317 | if ((err = i2c_attach_client(client))) | ||
318 | goto exit_free; | ||
319 | |||
320 | dev_info(&client->dev, "%s chip found\n", client->name); | 266 | dev_info(&client->dev, "%s chip found\n", client->name); |
321 | 267 | ||
322 | /* Initialize the AD7418 chip */ | 268 | /* Initialize the AD7418 chip */ |
@@ -324,7 +270,7 @@ static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | |||
324 | 270 | ||
325 | /* Register sysfs hooks */ | 271 | /* Register sysfs hooks */ |
326 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) | 272 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) |
327 | goto exit_detach; | 273 | goto exit_free; |
328 | 274 | ||
329 | data->hwmon_dev = hwmon_device_register(&client->dev); | 275 | data->hwmon_dev = hwmon_device_register(&client->dev); |
330 | if (IS_ERR(data->hwmon_dev)) { | 276 | if (IS_ERR(data->hwmon_dev)) { |
@@ -336,20 +282,17 @@ static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | |||
336 | 282 | ||
337 | exit_remove: | 283 | exit_remove: |
338 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 284 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
339 | exit_detach: | ||
340 | i2c_detach_client(client); | ||
341 | exit_free: | 285 | exit_free: |
342 | kfree(data); | 286 | kfree(data); |
343 | exit: | 287 | exit: |
344 | return err; | 288 | return err; |
345 | } | 289 | } |
346 | 290 | ||
347 | static int ad7418_detach_client(struct i2c_client *client) | 291 | static int ad7418_remove(struct i2c_client *client) |
348 | { | 292 | { |
349 | struct ad7418_data *data = i2c_get_clientdata(client); | 293 | struct ad7418_data *data = i2c_get_clientdata(client); |
350 | hwmon_device_unregister(data->hwmon_dev); | 294 | hwmon_device_unregister(data->hwmon_dev); |
351 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 295 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
352 | i2c_detach_client(client); | ||
353 | kfree(data); | 296 | kfree(data); |
354 | return 0; | 297 | return 0; |
355 | } | 298 | } |
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index ecbf69484bf5..b11e06f644b1 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -78,7 +78,6 @@ clearing it. Weird, ey? --Phil */ | |||
78 | 78 | ||
79 | /* Each client has this additional data */ | 79 | /* Each client has this additional data */ |
80 | struct adm1021_data { | 80 | struct adm1021_data { |
81 | struct i2c_client client; | ||
82 | struct device *hwmon_dev; | 81 | struct device *hwmon_dev; |
83 | enum chips type; | 82 | enum chips type; |
84 | 83 | ||
@@ -98,23 +97,42 @@ struct adm1021_data { | |||
98 | u8 remote_temp_offset_prec; | 97 | u8 remote_temp_offset_prec; |
99 | }; | 98 | }; |
100 | 99 | ||
101 | static int adm1021_attach_adapter(struct i2c_adapter *adapter); | 100 | static int adm1021_probe(struct i2c_client *client, |
102 | static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind); | 101 | const struct i2c_device_id *id); |
102 | static int adm1021_detect(struct i2c_client *client, int kind, | ||
103 | struct i2c_board_info *info); | ||
103 | static void adm1021_init_client(struct i2c_client *client); | 104 | static void adm1021_init_client(struct i2c_client *client); |
104 | static int adm1021_detach_client(struct i2c_client *client); | 105 | static int adm1021_remove(struct i2c_client *client); |
105 | static struct adm1021_data *adm1021_update_device(struct device *dev); | 106 | static struct adm1021_data *adm1021_update_device(struct device *dev); |
106 | 107 | ||
107 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ | 108 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ |
108 | static int read_only; | 109 | static int read_only; |
109 | 110 | ||
110 | 111 | ||
112 | static const struct i2c_device_id adm1021_id[] = { | ||
113 | { "adm1021", adm1021 }, | ||
114 | { "adm1023", adm1023 }, | ||
115 | { "max1617", max1617 }, | ||
116 | { "max1617a", max1617a }, | ||
117 | { "thmc10", thmc10 }, | ||
118 | { "lm84", lm84 }, | ||
119 | { "gl523sm", gl523sm }, | ||
120 | { "mc1066", mc1066 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, adm1021_id); | ||
124 | |||
111 | /* This is the driver that will be inserted */ | 125 | /* This is the driver that will be inserted */ |
112 | static struct i2c_driver adm1021_driver = { | 126 | static struct i2c_driver adm1021_driver = { |
127 | .class = I2C_CLASS_HWMON, | ||
113 | .driver = { | 128 | .driver = { |
114 | .name = "adm1021", | 129 | .name = "adm1021", |
115 | }, | 130 | }, |
116 | .attach_adapter = adm1021_attach_adapter, | 131 | .probe = adm1021_probe, |
117 | .detach_client = adm1021_detach_client, | 132 | .remove = adm1021_remove, |
133 | .id_table = adm1021_id, | ||
134 | .detect = adm1021_detect, | ||
135 | .address_data = &addr_data, | ||
118 | }; | 136 | }; |
119 | 137 | ||
120 | static ssize_t show_temp(struct device *dev, | 138 | static ssize_t show_temp(struct device *dev, |
@@ -216,13 +234,6 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | |||
216 | 234 | ||
217 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 235 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
218 | 236 | ||
219 | static int adm1021_attach_adapter(struct i2c_adapter *adapter) | ||
220 | { | ||
221 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
222 | return 0; | ||
223 | return i2c_probe(adapter, &addr_data, adm1021_detect); | ||
224 | } | ||
225 | |||
226 | static struct attribute *adm1021_attributes[] = { | 237 | static struct attribute *adm1021_attributes[] = { |
227 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 238 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
228 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 239 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -243,36 +254,21 @@ static const struct attribute_group adm1021_group = { | |||
243 | .attrs = adm1021_attributes, | 254 | .attrs = adm1021_attributes, |
244 | }; | 255 | }; |
245 | 256 | ||
246 | static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | 257 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
258 | static int adm1021_detect(struct i2c_client *client, int kind, | ||
259 | struct i2c_board_info *info) | ||
247 | { | 260 | { |
261 | struct i2c_adapter *adapter = client->adapter; | ||
248 | int i; | 262 | int i; |
249 | struct i2c_client *client; | ||
250 | struct adm1021_data *data; | ||
251 | int err = 0; | ||
252 | const char *type_name = ""; | 263 | const char *type_name = ""; |
253 | int conv_rate, status, config; | 264 | int conv_rate, status, config; |
254 | 265 | ||
255 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 266 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
256 | pr_debug("adm1021: detect failed, " | 267 | pr_debug("adm1021: detect failed, " |
257 | "smbus byte data not supported!\n"); | 268 | "smbus byte data not supported!\n"); |
258 | goto error0; | 269 | return -ENODEV; |
259 | } | ||
260 | |||
261 | /* OK. For now, we presume we have a valid client. We now create the | ||
262 | client structure, even though we cannot fill it completely yet. | ||
263 | But it allows us to access adm1021 register values. */ | ||
264 | |||
265 | if (!(data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL))) { | ||
266 | pr_debug("adm1021: detect failed, kzalloc failed!\n"); | ||
267 | err = -ENOMEM; | ||
268 | goto error0; | ||
269 | } | 270 | } |
270 | 271 | ||
271 | client = &data->client; | ||
272 | i2c_set_clientdata(client, data); | ||
273 | client->addr = address; | ||
274 | client->adapter = adapter; | ||
275 | client->driver = &adm1021_driver; | ||
276 | status = i2c_smbus_read_byte_data(client, ADM1021_REG_STATUS); | 272 | status = i2c_smbus_read_byte_data(client, ADM1021_REG_STATUS); |
277 | conv_rate = i2c_smbus_read_byte_data(client, | 273 | conv_rate = i2c_smbus_read_byte_data(client, |
278 | ADM1021_REG_CONV_RATE_R); | 274 | ADM1021_REG_CONV_RATE_R); |
@@ -284,8 +280,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
284 | || (conv_rate & 0xF8) != 0x00) { | 280 | || (conv_rate & 0xF8) != 0x00) { |
285 | pr_debug("adm1021: detect failed, " | 281 | pr_debug("adm1021: detect failed, " |
286 | "chip not detected!\n"); | 282 | "chip not detected!\n"); |
287 | err = -ENODEV; | 283 | return -ENODEV; |
288 | goto error1; | ||
289 | } | 284 | } |
290 | } | 285 | } |
291 | 286 | ||
@@ -336,24 +331,36 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
336 | type_name = "mc1066"; | 331 | type_name = "mc1066"; |
337 | } | 332 | } |
338 | pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n", | 333 | pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n", |
339 | type_name, i2c_adapter_id(adapter), address); | 334 | type_name, i2c_adapter_id(adapter), client->addr); |
335 | strlcpy(info->type, type_name, I2C_NAME_SIZE); | ||
340 | 336 | ||
341 | /* Fill in the remaining client fields */ | 337 | return 0; |
342 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | 338 | } |
343 | data->type = kind; | ||
344 | mutex_init(&data->update_lock); | ||
345 | 339 | ||
346 | /* Tell the I2C layer a new client has arrived */ | 340 | static int adm1021_probe(struct i2c_client *client, |
347 | if ((err = i2c_attach_client(client))) | 341 | const struct i2c_device_id *id) |
348 | goto error1; | 342 | { |
343 | struct adm1021_data *data; | ||
344 | int err; | ||
345 | |||
346 | data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL); | ||
347 | if (!data) { | ||
348 | pr_debug("adm1021: detect failed, kzalloc failed!\n"); | ||
349 | err = -ENOMEM; | ||
350 | goto error0; | ||
351 | } | ||
352 | |||
353 | i2c_set_clientdata(client, data); | ||
354 | data->type = id->driver_data; | ||
355 | mutex_init(&data->update_lock); | ||
349 | 356 | ||
350 | /* Initialize the ADM1021 chip */ | 357 | /* Initialize the ADM1021 chip */ |
351 | if (kind != lm84 && !read_only) | 358 | if (data->type != lm84 && !read_only) |
352 | adm1021_init_client(client); | 359 | adm1021_init_client(client); |
353 | 360 | ||
354 | /* Register sysfs hooks */ | 361 | /* Register sysfs hooks */ |
355 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1021_group))) | 362 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1021_group))) |
356 | goto error2; | 363 | goto error1; |
357 | 364 | ||
358 | data->hwmon_dev = hwmon_device_register(&client->dev); | 365 | data->hwmon_dev = hwmon_device_register(&client->dev); |
359 | if (IS_ERR(data->hwmon_dev)) { | 366 | if (IS_ERR(data->hwmon_dev)) { |
@@ -365,8 +372,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
365 | 372 | ||
366 | error3: | 373 | error3: |
367 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | 374 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); |
368 | error2: | ||
369 | i2c_detach_client(client); | ||
370 | error1: | 375 | error1: |
371 | kfree(data); | 376 | kfree(data); |
372 | error0: | 377 | error0: |
@@ -382,17 +387,13 @@ static void adm1021_init_client(struct i2c_client *client) | |||
382 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); | 387 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); |
383 | } | 388 | } |
384 | 389 | ||
385 | static int adm1021_detach_client(struct i2c_client *client) | 390 | static int adm1021_remove(struct i2c_client *client) |
386 | { | 391 | { |
387 | struct adm1021_data *data = i2c_get_clientdata(client); | 392 | struct adm1021_data *data = i2c_get_clientdata(client); |
388 | int err; | ||
389 | 393 | ||
390 | hwmon_device_unregister(data->hwmon_dev); | 394 | hwmon_device_unregister(data->hwmon_dev); |
391 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | 395 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); |
392 | 396 | ||
393 | if ((err = i2c_detach_client(client))) | ||
394 | return err; | ||
395 | |||
396 | kfree(data); | 397 | kfree(data); |
397 | return 0; | 398 | return 0; |
398 | } | 399 | } |
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index 1d76de7d75c7..4db04d603ec9 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * adm1025.c | 2 | * adm1025.c |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> | 4 | * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> |
5 | * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> | 5 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> |
6 | * | 6 | * |
7 | * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 | 7 | * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 |
8 | * voltages (including its own power source) and up to two temperatures | 8 | * voltages (including its own power source) and up to two temperatures |
@@ -109,22 +109,35 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; | |||
109 | * Functions declaration | 109 | * Functions declaration |
110 | */ | 110 | */ |
111 | 111 | ||
112 | static int adm1025_attach_adapter(struct i2c_adapter *adapter); | 112 | static int adm1025_probe(struct i2c_client *client, |
113 | static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind); | 113 | const struct i2c_device_id *id); |
114 | static int adm1025_detect(struct i2c_client *client, int kind, | ||
115 | struct i2c_board_info *info); | ||
114 | static void adm1025_init_client(struct i2c_client *client); | 116 | static void adm1025_init_client(struct i2c_client *client); |
115 | static int adm1025_detach_client(struct i2c_client *client); | 117 | static int adm1025_remove(struct i2c_client *client); |
116 | static struct adm1025_data *adm1025_update_device(struct device *dev); | 118 | static struct adm1025_data *adm1025_update_device(struct device *dev); |
117 | 119 | ||
118 | /* | 120 | /* |
119 | * Driver data (common to all clients) | 121 | * Driver data (common to all clients) |
120 | */ | 122 | */ |
121 | 123 | ||
124 | static const struct i2c_device_id adm1025_id[] = { | ||
125 | { "adm1025", adm1025 }, | ||
126 | { "ne1619", ne1619 }, | ||
127 | { } | ||
128 | }; | ||
129 | MODULE_DEVICE_TABLE(i2c, adm1025_id); | ||
130 | |||
122 | static struct i2c_driver adm1025_driver = { | 131 | static struct i2c_driver adm1025_driver = { |
132 | .class = I2C_CLASS_HWMON, | ||
123 | .driver = { | 133 | .driver = { |
124 | .name = "adm1025", | 134 | .name = "adm1025", |
125 | }, | 135 | }, |
126 | .attach_adapter = adm1025_attach_adapter, | 136 | .probe = adm1025_probe, |
127 | .detach_client = adm1025_detach_client, | 137 | .remove = adm1025_remove, |
138 | .id_table = adm1025_id, | ||
139 | .detect = adm1025_detect, | ||
140 | .address_data = &addr_data, | ||
128 | }; | 141 | }; |
129 | 142 | ||
130 | /* | 143 | /* |
@@ -132,7 +145,6 @@ static struct i2c_driver adm1025_driver = { | |||
132 | */ | 145 | */ |
133 | 146 | ||
134 | struct adm1025_data { | 147 | struct adm1025_data { |
135 | struct i2c_client client; | ||
136 | struct device *hwmon_dev; | 148 | struct device *hwmon_dev; |
137 | struct mutex update_lock; | 149 | struct mutex update_lock; |
138 | char valid; /* zero until following fields are valid */ | 150 | char valid; /* zero until following fields are valid */ |
@@ -344,13 +356,6 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); | |||
344 | * Real code | 356 | * Real code |
345 | */ | 357 | */ |
346 | 358 | ||
347 | static int adm1025_attach_adapter(struct i2c_adapter *adapter) | ||
348 | { | ||
349 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
350 | return 0; | ||
351 | return i2c_probe(adapter, &addr_data, adm1025_detect); | ||
352 | } | ||
353 | |||
354 | static struct attribute *adm1025_attributes[] = { | 359 | static struct attribute *adm1025_attributes[] = { |
355 | &sensor_dev_attr_in0_input.dev_attr.attr, | 360 | &sensor_dev_attr_in0_input.dev_attr.attr, |
356 | &sensor_dev_attr_in1_input.dev_attr.attr, | 361 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -403,31 +408,16 @@ static const struct attribute_group adm1025_group_in4 = { | |||
403 | .attrs = adm1025_attributes_in4, | 408 | .attrs = adm1025_attributes_in4, |
404 | }; | 409 | }; |
405 | 410 | ||
406 | /* | 411 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
407 | * The following function does more than just detection. If detection | 412 | static int adm1025_detect(struct i2c_client *client, int kind, |
408 | * succeeds, it also registers the new chip. | 413 | struct i2c_board_info *info) |
409 | */ | ||
410 | static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | ||
411 | { | 414 | { |
412 | struct i2c_client *client; | 415 | struct i2c_adapter *adapter = client->adapter; |
413 | struct adm1025_data *data; | ||
414 | int err = 0; | ||
415 | const char *name = ""; | 416 | const char *name = ""; |
416 | u8 config; | 417 | u8 config; |
417 | 418 | ||
418 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 419 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
419 | goto exit; | 420 | return -ENODEV; |
420 | |||
421 | if (!(data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL))) { | ||
422 | err = -ENOMEM; | ||
423 | goto exit; | ||
424 | } | ||
425 | |||
426 | client = &data->client; | ||
427 | i2c_set_clientdata(client, data); | ||
428 | client->addr = address; | ||
429 | client->adapter = adapter; | ||
430 | client->driver = &adm1025_driver; | ||
431 | 421 | ||
432 | /* | 422 | /* |
433 | * Now we do the remaining detection. A negative kind means that | 423 | * Now we do the remaining detection. A negative kind means that |
@@ -448,8 +438,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
448 | ADM1025_REG_STATUS2) & 0xBC) != 0x00) { | 438 | ADM1025_REG_STATUS2) & 0xBC) != 0x00) { |
449 | dev_dbg(&adapter->dev, | 439 | dev_dbg(&adapter->dev, |
450 | "ADM1025 detection failed at 0x%02x.\n", | 440 | "ADM1025 detection failed at 0x%02x.\n", |
451 | address); | 441 | client->addr); |
452 | goto exit_free; | 442 | return -ENODEV; |
453 | } | 443 | } |
454 | } | 444 | } |
455 | 445 | ||
@@ -465,7 +455,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
465 | } | 455 | } |
466 | } else | 456 | } else |
467 | if (man_id == 0xA1) { /* Philips */ | 457 | if (man_id == 0xA1) { /* Philips */ |
468 | if (address != 0x2E | 458 | if (client->addr != 0x2E |
469 | && (chip_id & 0xF0) == 0x20) { /* NE1619 */ | 459 | && (chip_id & 0xF0) == 0x20) { /* NE1619 */ |
470 | kind = ne1619; | 460 | kind = ne1619; |
471 | } | 461 | } |
@@ -475,7 +465,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
475 | dev_info(&adapter->dev, | 465 | dev_info(&adapter->dev, |
476 | "Unsupported chip (man_id=0x%02X, " | 466 | "Unsupported chip (man_id=0x%02X, " |
477 | "chip_id=0x%02X).\n", man_id, chip_id); | 467 | "chip_id=0x%02X).\n", man_id, chip_id); |
478 | goto exit_free; | 468 | return -ENODEV; |
479 | } | 469 | } |
480 | } | 470 | } |
481 | 471 | ||
@@ -484,23 +474,36 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
484 | } else if (kind == ne1619) { | 474 | } else if (kind == ne1619) { |
485 | name = "ne1619"; | 475 | name = "ne1619"; |
486 | } | 476 | } |
477 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
487 | 478 | ||
488 | /* We can fill in the remaining client fields */ | 479 | return 0; |
489 | strlcpy(client->name, name, I2C_NAME_SIZE); | 480 | } |
490 | mutex_init(&data->update_lock); | ||
491 | 481 | ||
492 | /* Tell the I2C layer a new client has arrived */ | 482 | static int adm1025_probe(struct i2c_client *client, |
493 | if ((err = i2c_attach_client(client))) | 483 | const struct i2c_device_id *id) |
494 | goto exit_free; | 484 | { |
485 | struct adm1025_data *data; | ||
486 | int err; | ||
487 | u8 config; | ||
488 | |||
489 | data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL); | ||
490 | if (!data) { | ||
491 | err = -ENOMEM; | ||
492 | goto exit; | ||
493 | } | ||
494 | |||
495 | i2c_set_clientdata(client, data); | ||
496 | mutex_init(&data->update_lock); | ||
495 | 497 | ||
496 | /* Initialize the ADM1025 chip */ | 498 | /* Initialize the ADM1025 chip */ |
497 | adm1025_init_client(client); | 499 | adm1025_init_client(client); |
498 | 500 | ||
499 | /* Register sysfs hooks */ | 501 | /* Register sysfs hooks */ |
500 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group))) | 502 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group))) |
501 | goto exit_detach; | 503 | goto exit_free; |
502 | 504 | ||
503 | /* Pin 11 is either in4 (+12V) or VID4 */ | 505 | /* Pin 11 is either in4 (+12V) or VID4 */ |
506 | config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); | ||
504 | if (!(config & 0x20)) { | 507 | if (!(config & 0x20)) { |
505 | if ((err = sysfs_create_group(&client->dev.kobj, | 508 | if ((err = sysfs_create_group(&client->dev.kobj, |
506 | &adm1025_group_in4))) | 509 | &adm1025_group_in4))) |
@@ -518,8 +521,6 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
518 | exit_remove: | 521 | exit_remove: |
519 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | 522 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); |
520 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | 523 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); |
521 | exit_detach: | ||
522 | i2c_detach_client(client); | ||
523 | exit_free: | 524 | exit_free: |
524 | kfree(data); | 525 | kfree(data); |
525 | exit: | 526 | exit: |
@@ -568,18 +569,14 @@ static void adm1025_init_client(struct i2c_client *client) | |||
568 | (reg&0x7E)|0x01); | 569 | (reg&0x7E)|0x01); |
569 | } | 570 | } |
570 | 571 | ||
571 | static int adm1025_detach_client(struct i2c_client *client) | 572 | static int adm1025_remove(struct i2c_client *client) |
572 | { | 573 | { |
573 | struct adm1025_data *data = i2c_get_clientdata(client); | 574 | struct adm1025_data *data = i2c_get_clientdata(client); |
574 | int err; | ||
575 | 575 | ||
576 | hwmon_device_unregister(data->hwmon_dev); | 576 | hwmon_device_unregister(data->hwmon_dev); |
577 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | 577 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); |
578 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | 578 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); |
579 | 579 | ||
580 | if ((err = i2c_detach_client(client))) | ||
581 | return err; | ||
582 | |||
583 | kfree(data); | 580 | kfree(data); |
584 | return 0; | 581 | return 0; |
585 | } | 582 | } |
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index 904c6ce9d83f..7fe2441fc845 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -259,7 +259,6 @@ struct pwm_data { | |||
259 | }; | 259 | }; |
260 | 260 | ||
261 | struct adm1026_data { | 261 | struct adm1026_data { |
262 | struct i2c_client client; | ||
263 | struct device *hwmon_dev; | 262 | struct device *hwmon_dev; |
264 | 263 | ||
265 | struct mutex update_lock; | 264 | struct mutex update_lock; |
@@ -293,10 +292,11 @@ struct adm1026_data { | |||
293 | u8 config3; /* Register value */ | 292 | u8 config3; /* Register value */ |
294 | }; | 293 | }; |
295 | 294 | ||
296 | static int adm1026_attach_adapter(struct i2c_adapter *adapter); | 295 | static int adm1026_probe(struct i2c_client *client, |
297 | static int adm1026_detect(struct i2c_adapter *adapter, int address, | 296 | const struct i2c_device_id *id); |
298 | int kind); | 297 | static int adm1026_detect(struct i2c_client *client, int kind, |
299 | static int adm1026_detach_client(struct i2c_client *client); | 298 | struct i2c_board_info *info); |
299 | static int adm1026_remove(struct i2c_client *client); | ||
300 | static int adm1026_read_value(struct i2c_client *client, u8 reg); | 300 | static int adm1026_read_value(struct i2c_client *client, u8 reg); |
301 | static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); | 301 | static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); |
302 | static void adm1026_print_gpio(struct i2c_client *client); | 302 | static void adm1026_print_gpio(struct i2c_client *client); |
@@ -305,22 +305,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev); | |||
305 | static void adm1026_init_client(struct i2c_client *client); | 305 | static void adm1026_init_client(struct i2c_client *client); |
306 | 306 | ||
307 | 307 | ||
308 | static const struct i2c_device_id adm1026_id[] = { | ||
309 | { "adm1026", adm1026 }, | ||
310 | { } | ||
311 | }; | ||
312 | MODULE_DEVICE_TABLE(i2c, adm1026_id); | ||
313 | |||
308 | static struct i2c_driver adm1026_driver = { | 314 | static struct i2c_driver adm1026_driver = { |
315 | .class = I2C_CLASS_HWMON, | ||
309 | .driver = { | 316 | .driver = { |
310 | .name = "adm1026", | 317 | .name = "adm1026", |
311 | }, | 318 | }, |
312 | .attach_adapter = adm1026_attach_adapter, | 319 | .probe = adm1026_probe, |
313 | .detach_client = adm1026_detach_client, | 320 | .remove = adm1026_remove, |
321 | .id_table = adm1026_id, | ||
322 | .detect = adm1026_detect, | ||
323 | .address_data = &addr_data, | ||
314 | }; | 324 | }; |
315 | 325 | ||
316 | static int adm1026_attach_adapter(struct i2c_adapter *adapter) | ||
317 | { | ||
318 | if (!(adapter->class & I2C_CLASS_HWMON)) { | ||
319 | return 0; | ||
320 | } | ||
321 | return i2c_probe(adapter, &addr_data, adm1026_detect); | ||
322 | } | ||
323 | |||
324 | static int adm1026_read_value(struct i2c_client *client, u8 reg) | 326 | static int adm1026_read_value(struct i2c_client *client, u8 reg) |
325 | { | 327 | { |
326 | int res; | 328 | int res; |
@@ -1647,48 +1649,32 @@ static const struct attribute_group adm1026_group_in8_9 = { | |||
1647 | .attrs = adm1026_attributes_in8_9, | 1649 | .attrs = adm1026_attributes_in8_9, |
1648 | }; | 1650 | }; |
1649 | 1651 | ||
1650 | static int adm1026_detect(struct i2c_adapter *adapter, int address, | 1652 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1651 | int kind) | 1653 | static int adm1026_detect(struct i2c_client *client, int kind, |
1654 | struct i2c_board_info *info) | ||
1652 | { | 1655 | { |
1656 | struct i2c_adapter *adapter = client->adapter; | ||
1657 | int address = client->addr; | ||
1653 | int company, verstep; | 1658 | int company, verstep; |
1654 | struct i2c_client *client; | ||
1655 | struct adm1026_data *data; | ||
1656 | int err = 0; | ||
1657 | const char *type_name = ""; | ||
1658 | 1659 | ||
1659 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1660 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1660 | /* We need to be able to do byte I/O */ | 1661 | /* We need to be able to do byte I/O */ |
1661 | goto exit; | 1662 | return -ENODEV; |
1662 | }; | 1663 | }; |
1663 | 1664 | ||
1664 | /* OK. For now, we presume we have a valid client. We now create the | ||
1665 | client structure, even though we cannot fill it completely yet. | ||
1666 | But it allows us to access adm1026_{read,write}_value. */ | ||
1667 | |||
1668 | if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) { | ||
1669 | err = -ENOMEM; | ||
1670 | goto exit; | ||
1671 | } | ||
1672 | |||
1673 | client = &data->client; | ||
1674 | i2c_set_clientdata(client, data); | ||
1675 | client->addr = address; | ||
1676 | client->adapter = adapter; | ||
1677 | client->driver = &adm1026_driver; | ||
1678 | |||
1679 | /* Now, we do the remaining detection. */ | 1665 | /* Now, we do the remaining detection. */ |
1680 | 1666 | ||
1681 | company = adm1026_read_value(client, ADM1026_REG_COMPANY); | 1667 | company = adm1026_read_value(client, ADM1026_REG_COMPANY); |
1682 | verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP); | 1668 | verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP); |
1683 | 1669 | ||
1684 | dev_dbg(&client->dev, "Detecting device at %d,0x%02x with" | 1670 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" |
1685 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", | 1671 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
1686 | i2c_adapter_id(client->adapter), client->addr, | 1672 | i2c_adapter_id(client->adapter), client->addr, |
1687 | company, verstep); | 1673 | company, verstep); |
1688 | 1674 | ||
1689 | /* If auto-detecting, Determine the chip type. */ | 1675 | /* If auto-detecting, Determine the chip type. */ |
1690 | if (kind <= 0) { | 1676 | if (kind <= 0) { |
1691 | dev_dbg(&client->dev, "Autodetecting device at %d,0x%02x " | 1677 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x " |
1692 | "...\n", i2c_adapter_id(adapter), address); | 1678 | "...\n", i2c_adapter_id(adapter), address); |
1693 | if (company == ADM1026_COMPANY_ANALOG_DEV | 1679 | if (company == ADM1026_COMPANY_ANALOG_DEV |
1694 | && verstep == ADM1026_VERSTEP_ADM1026) { | 1680 | && verstep == ADM1026_VERSTEP_ADM1026) { |
@@ -1704,7 +1690,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1704 | verstep); | 1690 | verstep); |
1705 | kind = any_chip; | 1691 | kind = any_chip; |
1706 | } else { | 1692 | } else { |
1707 | dev_dbg(&client->dev, ": Autodetection " | 1693 | dev_dbg(&adapter->dev, ": Autodetection " |
1708 | "failed\n"); | 1694 | "failed\n"); |
1709 | /* Not an ADM1026 ... */ | 1695 | /* Not an ADM1026 ... */ |
1710 | if (kind == 0) { /* User used force=x,y */ | 1696 | if (kind == 0) { /* User used force=x,y */ |
@@ -1713,33 +1699,29 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1713 | "force_adm1026.\n", | 1699 | "force_adm1026.\n", |
1714 | i2c_adapter_id(adapter), address); | 1700 | i2c_adapter_id(adapter), address); |
1715 | } | 1701 | } |
1716 | goto exitfree; | 1702 | return -ENODEV; |
1717 | } | 1703 | } |
1718 | } | 1704 | } |
1705 | strlcpy(info->type, "adm1026", I2C_NAME_SIZE); | ||
1719 | 1706 | ||
1720 | /* Fill in the chip specific driver values */ | 1707 | return 0; |
1721 | switch (kind) { | 1708 | } |
1722 | case any_chip : | 1709 | |
1723 | type_name = "adm1026"; | 1710 | static int adm1026_probe(struct i2c_client *client, |
1724 | break; | 1711 | const struct i2c_device_id *id) |
1725 | case adm1026 : | 1712 | { |
1726 | type_name = "adm1026"; | 1713 | struct adm1026_data *data; |
1727 | break; | 1714 | int err; |
1728 | default : | 1715 | |
1729 | dev_err(&adapter->dev, ": Internal error, invalid " | 1716 | data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL); |
1730 | "kind (%d)!\n", kind); | 1717 | if (!data) { |
1731 | err = -EFAULT; | 1718 | err = -ENOMEM; |
1732 | goto exitfree; | 1719 | goto exit; |
1733 | } | 1720 | } |
1734 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | ||
1735 | 1721 | ||
1736 | /* Fill in the remaining client fields */ | 1722 | i2c_set_clientdata(client, data); |
1737 | mutex_init(&data->update_lock); | 1723 | mutex_init(&data->update_lock); |
1738 | 1724 | ||
1739 | /* Tell the I2C layer a new client has arrived */ | ||
1740 | if ((err = i2c_attach_client(client))) | ||
1741 | goto exitfree; | ||
1742 | |||
1743 | /* Set the VRM version */ | 1725 | /* Set the VRM version */ |
1744 | data->vrm = vid_which_vrm(); | 1726 | data->vrm = vid_which_vrm(); |
1745 | 1727 | ||
@@ -1748,7 +1730,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1748 | 1730 | ||
1749 | /* Register sysfs hooks */ | 1731 | /* Register sysfs hooks */ |
1750 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) | 1732 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) |
1751 | goto exitdetach; | 1733 | goto exitfree; |
1752 | if (data->config1 & CFG1_AIN8_9) | 1734 | if (data->config1 & CFG1_AIN8_9) |
1753 | err = sysfs_create_group(&client->dev.kobj, | 1735 | err = sysfs_create_group(&client->dev.kobj, |
1754 | &adm1026_group_in8_9); | 1736 | &adm1026_group_in8_9); |
@@ -1773,15 +1755,13 @@ exitremove: | |||
1773 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | 1755 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); |
1774 | else | 1756 | else |
1775 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | 1757 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); |
1776 | exitdetach: | ||
1777 | i2c_detach_client(client); | ||
1778 | exitfree: | 1758 | exitfree: |
1779 | kfree(data); | 1759 | kfree(data); |
1780 | exit: | 1760 | exit: |
1781 | return err; | 1761 | return err; |
1782 | } | 1762 | } |
1783 | 1763 | ||
1784 | static int adm1026_detach_client(struct i2c_client *client) | 1764 | static int adm1026_remove(struct i2c_client *client) |
1785 | { | 1765 | { |
1786 | struct adm1026_data *data = i2c_get_clientdata(client); | 1766 | struct adm1026_data *data = i2c_get_clientdata(client); |
1787 | hwmon_device_unregister(data->hwmon_dev); | 1767 | hwmon_device_unregister(data->hwmon_dev); |
@@ -1790,7 +1770,6 @@ static int adm1026_detach_client(struct i2c_client *client) | |||
1790 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | 1770 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); |
1791 | else | 1771 | else |
1792 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | 1772 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); |
1793 | i2c_detach_client(client); | ||
1794 | kfree(data); | 1773 | kfree(data); |
1795 | return 0; | 1774 | return 0; |
1796 | } | 1775 | } |
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 2c6608d453c2..ba84ca5923f9 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c | |||
@@ -115,9 +115,11 @@ static const u8 ADM1029_REG_FAN_DIV[] = { | |||
115 | * Functions declaration | 115 | * Functions declaration |
116 | */ | 116 | */ |
117 | 117 | ||
118 | static int adm1029_attach_adapter(struct i2c_adapter *adapter); | 118 | static int adm1029_probe(struct i2c_client *client, |
119 | static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind); | 119 | const struct i2c_device_id *id); |
120 | static int adm1029_detach_client(struct i2c_client *client); | 120 | static int adm1029_detect(struct i2c_client *client, int kind, |
121 | struct i2c_board_info *info); | ||
122 | static int adm1029_remove(struct i2c_client *client); | ||
121 | static struct adm1029_data *adm1029_update_device(struct device *dev); | 123 | static struct adm1029_data *adm1029_update_device(struct device *dev); |
122 | static int adm1029_init_client(struct i2c_client *client); | 124 | static int adm1029_init_client(struct i2c_client *client); |
123 | 125 | ||
@@ -125,12 +127,22 @@ static int adm1029_init_client(struct i2c_client *client); | |||
125 | * Driver data (common to all clients) | 127 | * Driver data (common to all clients) |
126 | */ | 128 | */ |
127 | 129 | ||
130 | static const struct i2c_device_id adm1029_id[] = { | ||
131 | { "adm1029", adm1029 }, | ||
132 | { } | ||
133 | }; | ||
134 | MODULE_DEVICE_TABLE(i2c, adm1029_id); | ||
135 | |||
128 | static struct i2c_driver adm1029_driver = { | 136 | static struct i2c_driver adm1029_driver = { |
137 | .class = I2C_CLASS_HWMON, | ||
129 | .driver = { | 138 | .driver = { |
130 | .name = "adm1029", | 139 | .name = "adm1029", |
131 | }, | 140 | }, |
132 | .attach_adapter = adm1029_attach_adapter, | 141 | .probe = adm1029_probe, |
133 | .detach_client = adm1029_detach_client, | 142 | .remove = adm1029_remove, |
143 | .id_table = adm1029_id, | ||
144 | .detect = adm1029_detect, | ||
145 | .address_data = &addr_data, | ||
134 | }; | 146 | }; |
135 | 147 | ||
136 | /* | 148 | /* |
@@ -138,7 +150,6 @@ static struct i2c_driver adm1029_driver = { | |||
138 | */ | 150 | */ |
139 | 151 | ||
140 | struct adm1029_data { | 152 | struct adm1029_data { |
141 | struct i2c_client client; | ||
142 | struct device *hwmon_dev; | 153 | struct device *hwmon_dev; |
143 | struct mutex update_lock; | 154 | struct mutex update_lock; |
144 | char valid; /* zero until following fields are valid */ | 155 | char valid; /* zero until following fields are valid */ |
@@ -284,37 +295,14 @@ static const struct attribute_group adm1029_group = { | |||
284 | * Real code | 295 | * Real code |
285 | */ | 296 | */ |
286 | 297 | ||
287 | static int adm1029_attach_adapter(struct i2c_adapter *adapter) | 298 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
299 | static int adm1029_detect(struct i2c_client *client, int kind, | ||
300 | struct i2c_board_info *info) | ||
288 | { | 301 | { |
289 | if (!(adapter->class & I2C_CLASS_HWMON)) | 302 | struct i2c_adapter *adapter = client->adapter; |
290 | return 0; | ||
291 | return i2c_probe(adapter, &addr_data, adm1029_detect); | ||
292 | } | ||
293 | 303 | ||
294 | /* | ||
295 | * The following function does more than just detection. If detection | ||
296 | * succeeds, it also registers the new chip. | ||
297 | */ | ||
298 | |||
299 | static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | ||
300 | { | ||
301 | struct i2c_client *client; | ||
302 | struct adm1029_data *data; | ||
303 | int err = 0; | ||
304 | const char *name = ""; | ||
305 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 304 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
306 | goto exit; | 305 | return -ENODEV; |
307 | |||
308 | if (!(data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL))) { | ||
309 | err = -ENOMEM; | ||
310 | goto exit; | ||
311 | } | ||
312 | |||
313 | client = &data->client; | ||
314 | i2c_set_clientdata(client, data); | ||
315 | client->addr = address; | ||
316 | client->adapter = adapter; | ||
317 | client->driver = &adm1029_driver; | ||
318 | 306 | ||
319 | /* Now we do the detection and identification. A negative kind | 307 | /* Now we do the detection and identification. A negative kind |
320 | * means that the driver was loaded with no force parameter | 308 | * means that the driver was loaded with no force parameter |
@@ -362,32 +350,41 @@ static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | |||
362 | if (kind <= 0) { /* identification failed */ | 350 | if (kind <= 0) { /* identification failed */ |
363 | pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " | 351 | pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " |
364 | "chip_id=0x%02X)\n", man_id, chip_id); | 352 | "chip_id=0x%02X)\n", man_id, chip_id); |
365 | goto exit_free; | 353 | return -ENODEV; |
366 | } | 354 | } |
367 | } | 355 | } |
356 | strlcpy(info->type, "adm1029", I2C_NAME_SIZE); | ||
368 | 357 | ||
369 | if (kind == adm1029) { | 358 | return 0; |
370 | name = "adm1029"; | 359 | } |
360 | |||
361 | static int adm1029_probe(struct i2c_client *client, | ||
362 | const struct i2c_device_id *id) | ||
363 | { | ||
364 | struct adm1029_data *data; | ||
365 | int err; | ||
366 | |||
367 | data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL); | ||
368 | if (!data) { | ||
369 | err = -ENOMEM; | ||
370 | goto exit; | ||
371 | } | 371 | } |
372 | 372 | ||
373 | /* We can fill in the remaining client fields */ | 373 | i2c_set_clientdata(client, data); |
374 | strlcpy(client->name, name, I2C_NAME_SIZE); | ||
375 | mutex_init(&data->update_lock); | 374 | mutex_init(&data->update_lock); |
376 | 375 | ||
377 | /* Tell the I2C layer a new client has arrived */ | ||
378 | if ((err = i2c_attach_client(client))) | ||
379 | goto exit_free; | ||
380 | |||
381 | /* | 376 | /* |
382 | * Initialize the ADM1029 chip | 377 | * Initialize the ADM1029 chip |
383 | * Check config register | 378 | * Check config register |
384 | */ | 379 | */ |
385 | if (adm1029_init_client(client) == 0) | 380 | if (adm1029_init_client(client) == 0) { |
386 | goto exit_detach; | 381 | err = -ENODEV; |
382 | goto exit_free; | ||
383 | } | ||
387 | 384 | ||
388 | /* Register sysfs hooks */ | 385 | /* Register sysfs hooks */ |
389 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) | 386 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) |
390 | goto exit_detach; | 387 | goto exit_free; |
391 | 388 | ||
392 | data->hwmon_dev = hwmon_device_register(&client->dev); | 389 | data->hwmon_dev = hwmon_device_register(&client->dev); |
393 | if (IS_ERR(data->hwmon_dev)) { | 390 | if (IS_ERR(data->hwmon_dev)) { |
@@ -399,8 +396,6 @@ static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | |||
399 | 396 | ||
400 | exit_remove_files: | 397 | exit_remove_files: |
401 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | 398 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); |
402 | exit_detach: | ||
403 | i2c_detach_client(client); | ||
404 | exit_free: | 399 | exit_free: |
405 | kfree(data); | 400 | kfree(data); |
406 | exit: | 401 | exit: |
@@ -424,17 +419,13 @@ static int adm1029_init_client(struct i2c_client *client) | |||
424 | return 1; | 419 | return 1; |
425 | } | 420 | } |
426 | 421 | ||
427 | static int adm1029_detach_client(struct i2c_client *client) | 422 | static int adm1029_remove(struct i2c_client *client) |
428 | { | 423 | { |
429 | struct adm1029_data *data = i2c_get_clientdata(client); | 424 | struct adm1029_data *data = i2c_get_clientdata(client); |
430 | int err; | ||
431 | 425 | ||
432 | hwmon_device_unregister(data->hwmon_dev); | 426 | hwmon_device_unregister(data->hwmon_dev); |
433 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | 427 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); |
434 | 428 | ||
435 | if ((err = i2c_detach_client(client))) | ||
436 | return err; | ||
437 | |||
438 | kfree(data); | 429 | kfree(data); |
439 | return 0; | 430 | return 0; |
440 | } | 431 | } |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 2bffcab7dc9f..789441830cd8 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -70,7 +70,6 @@ typedef u8 auto_chan_table_t[8][2]; | |||
70 | 70 | ||
71 | /* Each client has this additional data */ | 71 | /* Each client has this additional data */ |
72 | struct adm1031_data { | 72 | struct adm1031_data { |
73 | struct i2c_client client; | ||
74 | struct device *hwmon_dev; | 73 | struct device *hwmon_dev; |
75 | struct mutex update_lock; | 74 | struct mutex update_lock; |
76 | int chip_type; | 75 | int chip_type; |
@@ -99,19 +98,32 @@ struct adm1031_data { | |||
99 | s8 temp_crit[3]; | 98 | s8 temp_crit[3]; |
100 | }; | 99 | }; |
101 | 100 | ||
102 | static int adm1031_attach_adapter(struct i2c_adapter *adapter); | 101 | static int adm1031_probe(struct i2c_client *client, |
103 | static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind); | 102 | const struct i2c_device_id *id); |
103 | static int adm1031_detect(struct i2c_client *client, int kind, | ||
104 | struct i2c_board_info *info); | ||
104 | static void adm1031_init_client(struct i2c_client *client); | 105 | static void adm1031_init_client(struct i2c_client *client); |
105 | static int adm1031_detach_client(struct i2c_client *client); | 106 | static int adm1031_remove(struct i2c_client *client); |
106 | static struct adm1031_data *adm1031_update_device(struct device *dev); | 107 | static struct adm1031_data *adm1031_update_device(struct device *dev); |
107 | 108 | ||
109 | static const struct i2c_device_id adm1031_id[] = { | ||
110 | { "adm1030", adm1030 }, | ||
111 | { "adm1031", adm1031 }, | ||
112 | { } | ||
113 | }; | ||
114 | MODULE_DEVICE_TABLE(i2c, adm1031_id); | ||
115 | |||
108 | /* This is the driver that will be inserted */ | 116 | /* This is the driver that will be inserted */ |
109 | static struct i2c_driver adm1031_driver = { | 117 | static struct i2c_driver adm1031_driver = { |
118 | .class = I2C_CLASS_HWMON, | ||
110 | .driver = { | 119 | .driver = { |
111 | .name = "adm1031", | 120 | .name = "adm1031", |
112 | }, | 121 | }, |
113 | .attach_adapter = adm1031_attach_adapter, | 122 | .probe = adm1031_probe, |
114 | .detach_client = adm1031_detach_client, | 123 | .remove = adm1031_remove, |
124 | .id_table = adm1031_id, | ||
125 | .detect = adm1031_detect, | ||
126 | .address_data = &addr_data, | ||
115 | }; | 127 | }; |
116 | 128 | ||
117 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) | 129 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) |
@@ -693,13 +705,6 @@ static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12); | |||
693 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); | 705 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); |
694 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); | 706 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); |
695 | 707 | ||
696 | static int adm1031_attach_adapter(struct i2c_adapter *adapter) | ||
697 | { | ||
698 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
699 | return 0; | ||
700 | return i2c_probe(adapter, &addr_data, adm1031_detect); | ||
701 | } | ||
702 | |||
703 | static struct attribute *adm1031_attributes[] = { | 708 | static struct attribute *adm1031_attributes[] = { |
704 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 709 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
705 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 710 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
@@ -770,27 +775,15 @@ static const struct attribute_group adm1031_group_opt = { | |||
770 | .attrs = adm1031_attributes_opt, | 775 | .attrs = adm1031_attributes_opt, |
771 | }; | 776 | }; |
772 | 777 | ||
773 | /* This function is called by i2c_probe */ | 778 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
774 | static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | 779 | static int adm1031_detect(struct i2c_client *client, int kind, |
780 | struct i2c_board_info *info) | ||
775 | { | 781 | { |
776 | struct i2c_client *client; | 782 | struct i2c_adapter *adapter = client->adapter; |
777 | struct adm1031_data *data; | ||
778 | int err = 0; | ||
779 | const char *name = ""; | 783 | const char *name = ""; |
780 | 784 | ||
781 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 785 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
782 | goto exit; | 786 | return -ENODEV; |
783 | |||
784 | if (!(data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL))) { | ||
785 | err = -ENOMEM; | ||
786 | goto exit; | ||
787 | } | ||
788 | |||
789 | client = &data->client; | ||
790 | i2c_set_clientdata(client, data); | ||
791 | client->addr = address; | ||
792 | client->adapter = adapter; | ||
793 | client->driver = &adm1031_driver; | ||
794 | 787 | ||
795 | if (kind < 0) { | 788 | if (kind < 0) { |
796 | int id, co; | 789 | int id, co; |
@@ -798,7 +791,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
798 | co = i2c_smbus_read_byte_data(client, 0x3e); | 791 | co = i2c_smbus_read_byte_data(client, 0x3e); |
799 | 792 | ||
800 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) | 793 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) |
801 | goto exit_free; | 794 | return -ENODEV; |
802 | kind = (id == 0x30) ? adm1030 : adm1031; | 795 | kind = (id == 0x30) ? adm1030 : adm1031; |
803 | } | 796 | } |
804 | 797 | ||
@@ -809,28 +802,43 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
809 | * auto fan control helper table. */ | 802 | * auto fan control helper table. */ |
810 | if (kind == adm1030) { | 803 | if (kind == adm1030) { |
811 | name = "adm1030"; | 804 | name = "adm1030"; |
812 | data->chan_select_table = &auto_channel_select_table_adm1030; | ||
813 | } else if (kind == adm1031) { | 805 | } else if (kind == adm1031) { |
814 | name = "adm1031"; | 806 | name = "adm1031"; |
815 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
816 | } | 807 | } |
817 | data->chip_type = kind; | 808 | strlcpy(info->type, name, I2C_NAME_SIZE); |
818 | 809 | ||
819 | strlcpy(client->name, name, I2C_NAME_SIZE); | 810 | return 0; |
811 | } | ||
812 | |||
813 | static int adm1031_probe(struct i2c_client *client, | ||
814 | const struct i2c_device_id *id) | ||
815 | { | ||
816 | struct adm1031_data *data; | ||
817 | int err; | ||
818 | |||
819 | data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL); | ||
820 | if (!data) { | ||
821 | err = -ENOMEM; | ||
822 | goto exit; | ||
823 | } | ||
824 | |||
825 | i2c_set_clientdata(client, data); | ||
826 | data->chip_type = id->driver_data; | ||
820 | mutex_init(&data->update_lock); | 827 | mutex_init(&data->update_lock); |
821 | 828 | ||
822 | /* Tell the I2C layer a new client has arrived */ | 829 | if (data->chip_type == adm1030) |
823 | if ((err = i2c_attach_client(client))) | 830 | data->chan_select_table = &auto_channel_select_table_adm1030; |
824 | goto exit_free; | 831 | else |
832 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
825 | 833 | ||
826 | /* Initialize the ADM1031 chip */ | 834 | /* Initialize the ADM1031 chip */ |
827 | adm1031_init_client(client); | 835 | adm1031_init_client(client); |
828 | 836 | ||
829 | /* Register sysfs hooks */ | 837 | /* Register sysfs hooks */ |
830 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) | 838 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) |
831 | goto exit_detach; | 839 | goto exit_free; |
832 | 840 | ||
833 | if (kind == adm1031) { | 841 | if (data->chip_type == adm1031) { |
834 | if ((err = sysfs_create_group(&client->dev.kobj, | 842 | if ((err = sysfs_create_group(&client->dev.kobj, |
835 | &adm1031_group_opt))) | 843 | &adm1031_group_opt))) |
836 | goto exit_remove; | 844 | goto exit_remove; |
@@ -847,25 +855,19 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
847 | exit_remove: | 855 | exit_remove: |
848 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | 856 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
849 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | 857 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
850 | exit_detach: | ||
851 | i2c_detach_client(client); | ||
852 | exit_free: | 858 | exit_free: |
853 | kfree(data); | 859 | kfree(data); |
854 | exit: | 860 | exit: |
855 | return err; | 861 | return err; |
856 | } | 862 | } |
857 | 863 | ||
858 | static int adm1031_detach_client(struct i2c_client *client) | 864 | static int adm1031_remove(struct i2c_client *client) |
859 | { | 865 | { |
860 | struct adm1031_data *data = i2c_get_clientdata(client); | 866 | struct adm1031_data *data = i2c_get_clientdata(client); |
861 | int ret; | ||
862 | 867 | ||
863 | hwmon_device_unregister(data->hwmon_dev); | 868 | hwmon_device_unregister(data->hwmon_dev); |
864 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | 869 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
865 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | 870 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
866 | if ((ret = i2c_detach_client(client)) != 0) { | ||
867 | return ret; | ||
868 | } | ||
869 | kfree(data); | 871 | kfree(data); |
870 | return 0; | 872 | return 0; |
871 | } | 873 | } |
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 149ef25252e7..2444b15f2e9d 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -130,25 +130,37 @@ static inline unsigned int AOUT_FROM_REG(u8 reg) | |||
130 | return SCALE(reg, 1250, 255); | 130 | return SCALE(reg, 1250, 255); |
131 | } | 131 | } |
132 | 132 | ||
133 | static int adm9240_attach_adapter(struct i2c_adapter *adapter); | 133 | static int adm9240_probe(struct i2c_client *client, |
134 | static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind); | 134 | const struct i2c_device_id *id); |
135 | static int adm9240_detect(struct i2c_client *client, int kind, | ||
136 | struct i2c_board_info *info); | ||
135 | static void adm9240_init_client(struct i2c_client *client); | 137 | static void adm9240_init_client(struct i2c_client *client); |
136 | static int adm9240_detach_client(struct i2c_client *client); | 138 | static int adm9240_remove(struct i2c_client *client); |
137 | static struct adm9240_data *adm9240_update_device(struct device *dev); | 139 | static struct adm9240_data *adm9240_update_device(struct device *dev); |
138 | 140 | ||
139 | /* driver data */ | 141 | /* driver data */ |
142 | static const struct i2c_device_id adm9240_id[] = { | ||
143 | { "adm9240", adm9240 }, | ||
144 | { "ds1780", ds1780 }, | ||
145 | { "lm81", lm81 }, | ||
146 | { } | ||
147 | }; | ||
148 | MODULE_DEVICE_TABLE(i2c, adm9240_id); | ||
149 | |||
140 | static struct i2c_driver adm9240_driver = { | 150 | static struct i2c_driver adm9240_driver = { |
151 | .class = I2C_CLASS_HWMON, | ||
141 | .driver = { | 152 | .driver = { |
142 | .name = "adm9240", | 153 | .name = "adm9240", |
143 | }, | 154 | }, |
144 | .attach_adapter = adm9240_attach_adapter, | 155 | .probe = adm9240_probe, |
145 | .detach_client = adm9240_detach_client, | 156 | .remove = adm9240_remove, |
157 | .id_table = adm9240_id, | ||
158 | .detect = adm9240_detect, | ||
159 | .address_data = &addr_data, | ||
146 | }; | 160 | }; |
147 | 161 | ||
148 | /* per client data */ | 162 | /* per client data */ |
149 | struct adm9240_data { | 163 | struct adm9240_data { |
150 | enum chips type; | ||
151 | struct i2c_client client; | ||
152 | struct device *hwmon_dev; | 164 | struct device *hwmon_dev; |
153 | struct mutex update_lock; | 165 | struct mutex update_lock; |
154 | char valid; | 166 | char valid; |
@@ -532,28 +544,17 @@ static const struct attribute_group adm9240_group = { | |||
532 | 544 | ||
533 | /*** sensor chip detect and driver install ***/ | 545 | /*** sensor chip detect and driver install ***/ |
534 | 546 | ||
535 | static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | 547 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
548 | static int adm9240_detect(struct i2c_client *new_client, int kind, | ||
549 | struct i2c_board_info *info) | ||
536 | { | 550 | { |
537 | struct i2c_client *new_client; | 551 | struct i2c_adapter *adapter = new_client->adapter; |
538 | struct adm9240_data *data; | ||
539 | int err = 0; | ||
540 | const char *name = ""; | 552 | const char *name = ""; |
553 | int address = new_client->addr; | ||
541 | u8 man_id, die_rev; | 554 | u8 man_id, die_rev; |
542 | 555 | ||
543 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 556 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
544 | goto exit; | 557 | return -ENODEV; |
545 | |||
546 | if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) { | ||
547 | err = -ENOMEM; | ||
548 | goto exit; | ||
549 | } | ||
550 | |||
551 | new_client = &data->client; | ||
552 | i2c_set_clientdata(new_client, data); | ||
553 | new_client->addr = address; | ||
554 | new_client->adapter = adapter; | ||
555 | new_client->driver = &adm9240_driver; | ||
556 | new_client->flags = 0; | ||
557 | 558 | ||
558 | if (kind == 0) { | 559 | if (kind == 0) { |
559 | kind = adm9240; | 560 | kind = adm9240; |
@@ -566,7 +567,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
566 | != address) { | 567 | != address) { |
567 | dev_err(&adapter->dev, "detect fail: address match, " | 568 | dev_err(&adapter->dev, "detect fail: address match, " |
568 | "0x%02x\n", address); | 569 | "0x%02x\n", address); |
569 | goto exit_free; | 570 | return -ENODEV; |
570 | } | 571 | } |
571 | 572 | ||
572 | /* check known chip manufacturer */ | 573 | /* check known chip manufacturer */ |
@@ -581,7 +582,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
581 | } else { | 582 | } else { |
582 | dev_err(&adapter->dev, "detect fail: unknown manuf, " | 583 | dev_err(&adapter->dev, "detect fail: unknown manuf, " |
583 | "0x%02x\n", man_id); | 584 | "0x%02x\n", man_id); |
584 | goto exit_free; | 585 | return -ENODEV; |
585 | } | 586 | } |
586 | 587 | ||
587 | /* successful detect, print chip info */ | 588 | /* successful detect, print chip info */ |
@@ -600,20 +601,31 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
600 | } else if (kind == lm81) { | 601 | } else if (kind == lm81) { |
601 | name = "lm81"; | 602 | name = "lm81"; |
602 | } | 603 | } |
604 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
603 | 605 | ||
604 | /* fill in the remaining client fields and attach */ | 606 | return 0; |
605 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 607 | } |
606 | data->type = kind; | ||
607 | mutex_init(&data->update_lock); | ||
608 | 608 | ||
609 | if ((err = i2c_attach_client(new_client))) | 609 | static int adm9240_probe(struct i2c_client *new_client, |
610 | goto exit_free; | 610 | const struct i2c_device_id *id) |
611 | { | ||
612 | struct adm9240_data *data; | ||
613 | int err; | ||
614 | |||
615 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
616 | if (!data) { | ||
617 | err = -ENOMEM; | ||
618 | goto exit; | ||
619 | } | ||
620 | |||
621 | i2c_set_clientdata(new_client, data); | ||
622 | mutex_init(&data->update_lock); | ||
611 | 623 | ||
612 | adm9240_init_client(new_client); | 624 | adm9240_init_client(new_client); |
613 | 625 | ||
614 | /* populate sysfs filesystem */ | 626 | /* populate sysfs filesystem */ |
615 | if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) | 627 | if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) |
616 | goto exit_detach; | 628 | goto exit_free; |
617 | 629 | ||
618 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 630 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
619 | if (IS_ERR(data->hwmon_dev)) { | 631 | if (IS_ERR(data->hwmon_dev)) { |
@@ -625,32 +637,19 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
625 | 637 | ||
626 | exit_remove: | 638 | exit_remove: |
627 | sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); | 639 | sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); |
628 | exit_detach: | ||
629 | i2c_detach_client(new_client); | ||
630 | exit_free: | 640 | exit_free: |
631 | kfree(data); | 641 | kfree(data); |
632 | exit: | 642 | exit: |
633 | return err; | 643 | return err; |
634 | } | 644 | } |
635 | 645 | ||
636 | static int adm9240_attach_adapter(struct i2c_adapter *adapter) | 646 | static int adm9240_remove(struct i2c_client *client) |
637 | { | ||
638 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
639 | return 0; | ||
640 | return i2c_probe(adapter, &addr_data, adm9240_detect); | ||
641 | } | ||
642 | |||
643 | static int adm9240_detach_client(struct i2c_client *client) | ||
644 | { | 647 | { |
645 | struct adm9240_data *data = i2c_get_clientdata(client); | 648 | struct adm9240_data *data = i2c_get_clientdata(client); |
646 | int err; | ||
647 | 649 | ||
648 | hwmon_device_unregister(data->hwmon_dev); | 650 | hwmon_device_unregister(data->hwmon_dev); |
649 | sysfs_remove_group(&client->dev.kobj, &adm9240_group); | 651 | sysfs_remove_group(&client->dev.kobj, &adm9240_group); |
650 | 652 | ||
651 | if ((err = i2c_detach_client(client))) | ||
652 | return err; | ||
653 | |||
654 | kfree(data); | 653 | kfree(data); |
655 | return 0; | 654 | return 0; |
656 | } | 655 | } |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 5c8b6e0ff47c..5c39b4af1b23 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -64,7 +64,6 @@ static unsigned int ads7828_lsb_resol; /* resolution of the ADC sample lsb */ | |||
64 | 64 | ||
65 | /* Each client has this additional data */ | 65 | /* Each client has this additional data */ |
66 | struct ads7828_data { | 66 | struct ads7828_data { |
67 | struct i2c_client client; | ||
68 | struct device *hwmon_dev; | 67 | struct device *hwmon_dev; |
69 | struct mutex update_lock; /* mutex protect updates */ | 68 | struct mutex update_lock; /* mutex protect updates */ |
70 | char valid; /* !=0 if following fields are valid */ | 69 | char valid; /* !=0 if following fields are valid */ |
@@ -73,7 +72,10 @@ struct ads7828_data { | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | /* Function declaration - necessary due to function dependencies */ | 74 | /* Function declaration - necessary due to function dependencies */ |
76 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind); | 75 | static int ads7828_detect(struct i2c_client *client, int kind, |
76 | struct i2c_board_info *info); | ||
77 | static int ads7828_probe(struct i2c_client *client, | ||
78 | const struct i2c_device_id *id); | ||
77 | 79 | ||
78 | /* The ADS7828 returns the 12-bit sample in two bytes, | 80 | /* The ADS7828 returns the 12-bit sample in two bytes, |
79 | these are read as a word then byte-swapped */ | 81 | these are read as a word then byte-swapped */ |
@@ -156,58 +158,43 @@ static const struct attribute_group ads7828_group = { | |||
156 | .attrs = ads7828_attributes, | 158 | .attrs = ads7828_attributes, |
157 | }; | 159 | }; |
158 | 160 | ||
159 | static int ads7828_attach_adapter(struct i2c_adapter *adapter) | 161 | static int ads7828_remove(struct i2c_client *client) |
160 | { | ||
161 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
162 | return 0; | ||
163 | return i2c_probe(adapter, &addr_data, ads7828_detect); | ||
164 | } | ||
165 | |||
166 | static int ads7828_detach_client(struct i2c_client *client) | ||
167 | { | 162 | { |
168 | struct ads7828_data *data = i2c_get_clientdata(client); | 163 | struct ads7828_data *data = i2c_get_clientdata(client); |
169 | hwmon_device_unregister(data->hwmon_dev); | 164 | hwmon_device_unregister(data->hwmon_dev); |
170 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 165 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
171 | i2c_detach_client(client); | ||
172 | kfree(i2c_get_clientdata(client)); | 166 | kfree(i2c_get_clientdata(client)); |
173 | return 0; | 167 | return 0; |
174 | } | 168 | } |
175 | 169 | ||
170 | static const struct i2c_device_id ads7828_id[] = { | ||
171 | { "ads7828", ads7828 }, | ||
172 | { } | ||
173 | }; | ||
174 | MODULE_DEVICE_TABLE(i2c, ads7828_id); | ||
175 | |||
176 | /* This is the driver that will be inserted */ | 176 | /* This is the driver that will be inserted */ |
177 | static struct i2c_driver ads7828_driver = { | 177 | static struct i2c_driver ads7828_driver = { |
178 | .class = I2C_CLASS_HWMON, | ||
178 | .driver = { | 179 | .driver = { |
179 | .name = "ads7828", | 180 | .name = "ads7828", |
180 | }, | 181 | }, |
181 | .attach_adapter = ads7828_attach_adapter, | 182 | .probe = ads7828_probe, |
182 | .detach_client = ads7828_detach_client, | 183 | .remove = ads7828_remove, |
184 | .id_table = ads7828_id, | ||
185 | .detect = ads7828_detect, | ||
186 | .address_data = &addr_data, | ||
183 | }; | 187 | }; |
184 | 188 | ||
185 | /* This function is called by i2c_probe */ | 189 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
186 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | 190 | static int ads7828_detect(struct i2c_client *client, int kind, |
191 | struct i2c_board_info *info) | ||
187 | { | 192 | { |
188 | struct i2c_client *client; | 193 | struct i2c_adapter *adapter = client->adapter; |
189 | struct ads7828_data *data; | ||
190 | int err = 0; | ||
191 | const char *name = ""; | ||
192 | 194 | ||
193 | /* Check we have a valid client */ | 195 | /* Check we have a valid client */ |
194 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) | 196 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) |
195 | goto exit; | 197 | return -ENODEV; |
196 | |||
197 | /* OK. For now, we presume we have a valid client. We now create the | ||
198 | client structure, even though we cannot fill it completely yet. | ||
199 | But it allows us to access ads7828_read_value. */ | ||
200 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); | ||
201 | if (!data) { | ||
202 | err = -ENOMEM; | ||
203 | goto exit; | ||
204 | } | ||
205 | |||
206 | client = &data->client; | ||
207 | i2c_set_clientdata(client, data); | ||
208 | client->addr = address; | ||
209 | client->adapter = adapter; | ||
210 | client->driver = &ads7828_driver; | ||
211 | 198 | ||
212 | /* Now, we do the remaining detection. There is no identification | 199 | /* Now, we do the remaining detection. There is no identification |
213 | dedicated register so attempt to sanity check using knowledge of | 200 | dedicated register so attempt to sanity check using knowledge of |
@@ -225,32 +212,34 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
225 | printk(KERN_DEBUG | 212 | printk(KERN_DEBUG |
226 | "%s : Doesn't look like an ads7828 device\n", | 213 | "%s : Doesn't look like an ads7828 device\n", |
227 | __func__); | 214 | __func__); |
228 | goto exit_free; | 215 | return -ENODEV; |
229 | } | 216 | } |
230 | } | 217 | } |
231 | } | 218 | } |
219 | strlcpy(info->type, "ads7828", I2C_NAME_SIZE); | ||
232 | 220 | ||
233 | /* Determine the chip type - only one kind supported! */ | 221 | return 0; |
234 | if (kind <= 0) | 222 | } |
235 | kind = ads7828; | ||
236 | 223 | ||
237 | if (kind == ads7828) | 224 | static int ads7828_probe(struct i2c_client *client, |
238 | name = "ads7828"; | 225 | const struct i2c_device_id *id) |
226 | { | ||
227 | struct ads7828_data *data; | ||
228 | int err; | ||
239 | 229 | ||
240 | /* Fill in the remaining client fields, put it into the global list */ | 230 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); |
241 | strlcpy(client->name, name, I2C_NAME_SIZE); | 231 | if (!data) { |
232 | err = -ENOMEM; | ||
233 | goto exit; | ||
234 | } | ||
242 | 235 | ||
236 | i2c_set_clientdata(client, data); | ||
243 | mutex_init(&data->update_lock); | 237 | mutex_init(&data->update_lock); |
244 | 238 | ||
245 | /* Tell the I2C layer a new client has arrived */ | ||
246 | err = i2c_attach_client(client); | ||
247 | if (err) | ||
248 | goto exit_free; | ||
249 | |||
250 | /* Register sysfs hooks */ | 239 | /* Register sysfs hooks */ |
251 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); | 240 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); |
252 | if (err) | 241 | if (err) |
253 | goto exit_detach; | 242 | goto exit_free; |
254 | 243 | ||
255 | data->hwmon_dev = hwmon_device_register(&client->dev); | 244 | data->hwmon_dev = hwmon_device_register(&client->dev); |
256 | if (IS_ERR(data->hwmon_dev)) { | 245 | if (IS_ERR(data->hwmon_dev)) { |
@@ -262,8 +251,6 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
262 | 251 | ||
263 | exit_remove: | 252 | exit_remove: |
264 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 253 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
265 | exit_detach: | ||
266 | i2c_detach_client(client); | ||
267 | exit_free: | 254 | exit_free: |
268 | kfree(data); | 255 | kfree(data); |
269 | exit: | 256 | exit: |
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 6b5325f33a2c..d368d8f845e1 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -138,7 +138,6 @@ I2C_CLIENT_INSMOD_1(adt7470); | |||
138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
139 | 139 | ||
140 | struct adt7470_data { | 140 | struct adt7470_data { |
141 | struct i2c_client client; | ||
142 | struct device *hwmon_dev; | 141 | struct device *hwmon_dev; |
143 | struct attribute_group attrs; | 142 | struct attribute_group attrs; |
144 | struct mutex lock; | 143 | struct mutex lock; |
@@ -164,16 +163,28 @@ struct adt7470_data { | |||
164 | u8 pwm_auto_temp[ADT7470_PWM_COUNT]; | 163 | u8 pwm_auto_temp[ADT7470_PWM_COUNT]; |
165 | }; | 164 | }; |
166 | 165 | ||
167 | static int adt7470_attach_adapter(struct i2c_adapter *adapter); | 166 | static int adt7470_probe(struct i2c_client *client, |
168 | static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind); | 167 | const struct i2c_device_id *id); |
169 | static int adt7470_detach_client(struct i2c_client *client); | 168 | static int adt7470_detect(struct i2c_client *client, int kind, |
169 | struct i2c_board_info *info); | ||
170 | static int adt7470_remove(struct i2c_client *client); | ||
171 | |||
172 | static const struct i2c_device_id adt7470_id[] = { | ||
173 | { "adt7470", adt7470 }, | ||
174 | { } | ||
175 | }; | ||
176 | MODULE_DEVICE_TABLE(i2c, adt7470_id); | ||
170 | 177 | ||
171 | static struct i2c_driver adt7470_driver = { | 178 | static struct i2c_driver adt7470_driver = { |
179 | .class = I2C_CLASS_HWMON, | ||
172 | .driver = { | 180 | .driver = { |
173 | .name = "adt7470", | 181 | .name = "adt7470", |
174 | }, | 182 | }, |
175 | .attach_adapter = adt7470_attach_adapter, | 183 | .probe = adt7470_probe, |
176 | .detach_client = adt7470_detach_client, | 184 | .remove = adt7470_remove, |
185 | .id_table = adt7470_id, | ||
186 | .detect = adt7470_detect, | ||
187 | .address_data = &addr_data, | ||
177 | }; | 188 | }; |
178 | 189 | ||
179 | /* | 190 | /* |
@@ -1004,64 +1015,52 @@ static struct attribute *adt7470_attr[] = | |||
1004 | NULL | 1015 | NULL |
1005 | }; | 1016 | }; |
1006 | 1017 | ||
1007 | static int adt7470_attach_adapter(struct i2c_adapter *adapter) | 1018 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1008 | { | 1019 | static int adt7470_detect(struct i2c_client *client, int kind, |
1009 | if (!(adapter->class & I2C_CLASS_HWMON)) | 1020 | struct i2c_board_info *info) |
1010 | return 0; | ||
1011 | return i2c_probe(adapter, &addr_data, adt7470_detect); | ||
1012 | } | ||
1013 | |||
1014 | static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | ||
1015 | { | 1021 | { |
1016 | struct i2c_client *client; | 1022 | struct i2c_adapter *adapter = client->adapter; |
1017 | struct adt7470_data *data; | ||
1018 | int err = 0; | ||
1019 | 1023 | ||
1020 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1024 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1021 | goto exit; | 1025 | return -ENODEV; |
1022 | |||
1023 | if (!(data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL))) { | ||
1024 | err = -ENOMEM; | ||
1025 | goto exit; | ||
1026 | } | ||
1027 | |||
1028 | client = &data->client; | ||
1029 | client->addr = address; | ||
1030 | client->adapter = adapter; | ||
1031 | client->driver = &adt7470_driver; | ||
1032 | |||
1033 | i2c_set_clientdata(client, data); | ||
1034 | |||
1035 | mutex_init(&data->lock); | ||
1036 | 1026 | ||
1037 | if (kind <= 0) { | 1027 | if (kind <= 0) { |
1038 | int vendor, device, revision; | 1028 | int vendor, device, revision; |
1039 | 1029 | ||
1040 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); | 1030 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); |
1041 | if (vendor != ADT7470_VENDOR) { | 1031 | if (vendor != ADT7470_VENDOR) |
1042 | err = -ENODEV; | 1032 | return -ENODEV; |
1043 | goto exit_free; | ||
1044 | } | ||
1045 | 1033 | ||
1046 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); | 1034 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); |
1047 | if (device != ADT7470_DEVICE) { | 1035 | if (device != ADT7470_DEVICE) |
1048 | err = -ENODEV; | 1036 | return -ENODEV; |
1049 | goto exit_free; | ||
1050 | } | ||
1051 | 1037 | ||
1052 | revision = i2c_smbus_read_byte_data(client, | 1038 | revision = i2c_smbus_read_byte_data(client, |
1053 | ADT7470_REG_REVISION); | 1039 | ADT7470_REG_REVISION); |
1054 | if (revision != ADT7470_REVISION) { | 1040 | if (revision != ADT7470_REVISION) |
1055 | err = -ENODEV; | 1041 | return -ENODEV; |
1056 | goto exit_free; | ||
1057 | } | ||
1058 | } else | 1042 | } else |
1059 | dev_dbg(&adapter->dev, "detection forced\n"); | 1043 | dev_dbg(&adapter->dev, "detection forced\n"); |
1060 | 1044 | ||
1061 | strlcpy(client->name, "adt7470", I2C_NAME_SIZE); | 1045 | strlcpy(info->type, "adt7470", I2C_NAME_SIZE); |
1062 | 1046 | ||
1063 | if ((err = i2c_attach_client(client))) | 1047 | return 0; |
1064 | goto exit_free; | 1048 | } |
1049 | |||
1050 | static int adt7470_probe(struct i2c_client *client, | ||
1051 | const struct i2c_device_id *id) | ||
1052 | { | ||
1053 | struct adt7470_data *data; | ||
1054 | int err; | ||
1055 | |||
1056 | data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL); | ||
1057 | if (!data) { | ||
1058 | err = -ENOMEM; | ||
1059 | goto exit; | ||
1060 | } | ||
1061 | |||
1062 | i2c_set_clientdata(client, data); | ||
1063 | mutex_init(&data->lock); | ||
1065 | 1064 | ||
1066 | dev_info(&client->dev, "%s chip found\n", client->name); | 1065 | dev_info(&client->dev, "%s chip found\n", client->name); |
1067 | 1066 | ||
@@ -1071,7 +1070,7 @@ static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1071 | /* Register sysfs hooks */ | 1070 | /* Register sysfs hooks */ |
1072 | data->attrs.attrs = adt7470_attr; | 1071 | data->attrs.attrs = adt7470_attr; |
1073 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) | 1072 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) |
1074 | goto exit_detach; | 1073 | goto exit_free; |
1075 | 1074 | ||
1076 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1075 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1077 | if (IS_ERR(data->hwmon_dev)) { | 1076 | if (IS_ERR(data->hwmon_dev)) { |
@@ -1083,21 +1082,18 @@ static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1083 | 1082 | ||
1084 | exit_remove: | 1083 | exit_remove: |
1085 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1084 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1086 | exit_detach: | ||
1087 | i2c_detach_client(client); | ||
1088 | exit_free: | 1085 | exit_free: |
1089 | kfree(data); | 1086 | kfree(data); |
1090 | exit: | 1087 | exit: |
1091 | return err; | 1088 | return err; |
1092 | } | 1089 | } |
1093 | 1090 | ||
1094 | static int adt7470_detach_client(struct i2c_client *client) | 1091 | static int adt7470_remove(struct i2c_client *client) |
1095 | { | 1092 | { |
1096 | struct adt7470_data *data = i2c_get_clientdata(client); | 1093 | struct adt7470_data *data = i2c_get_clientdata(client); |
1097 | 1094 | ||
1098 | hwmon_device_unregister(data->hwmon_dev); | 1095 | hwmon_device_unregister(data->hwmon_dev); |
1099 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1096 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1100 | i2c_detach_client(client); | ||
1101 | kfree(data); | 1097 | kfree(data); |
1102 | return 0; | 1098 | return 0; |
1103 | } | 1099 | } |
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index c1009d6f9796..ce4a7cb5a116 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
@@ -143,7 +143,6 @@ I2C_CLIENT_INSMOD_1(adt7473); | |||
143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
144 | 144 | ||
145 | struct adt7473_data { | 145 | struct adt7473_data { |
146 | struct i2c_client client; | ||
147 | struct device *hwmon_dev; | 146 | struct device *hwmon_dev; |
148 | struct attribute_group attrs; | 147 | struct attribute_group attrs; |
149 | struct mutex lock; | 148 | struct mutex lock; |
@@ -178,16 +177,28 @@ struct adt7473_data { | |||
178 | u8 max_duty_at_overheat; | 177 | u8 max_duty_at_overheat; |
179 | }; | 178 | }; |
180 | 179 | ||
181 | static int adt7473_attach_adapter(struct i2c_adapter *adapter); | 180 | static int adt7473_probe(struct i2c_client *client, |
182 | static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind); | 181 | const struct i2c_device_id *id); |
183 | static int adt7473_detach_client(struct i2c_client *client); | 182 | static int adt7473_detect(struct i2c_client *client, int kind, |
183 | struct i2c_board_info *info); | ||
184 | static int adt7473_remove(struct i2c_client *client); | ||
185 | |||
186 | static const struct i2c_device_id adt7473_id[] = { | ||
187 | { "adt7473", adt7473 }, | ||
188 | { } | ||
189 | }; | ||
190 | MODULE_DEVICE_TABLE(i2c, adt7473_id); | ||
184 | 191 | ||
185 | static struct i2c_driver adt7473_driver = { | 192 | static struct i2c_driver adt7473_driver = { |
193 | .class = I2C_CLASS_HWMON, | ||
186 | .driver = { | 194 | .driver = { |
187 | .name = "adt7473", | 195 | .name = "adt7473", |
188 | }, | 196 | }, |
189 | .attach_adapter = adt7473_attach_adapter, | 197 | .probe = adt7473_probe, |
190 | .detach_client = adt7473_detach_client, | 198 | .remove = adt7473_remove, |
199 | .id_table = adt7473_id, | ||
200 | .detect = adt7473_detect, | ||
201 | .address_data = &addr_data, | ||
191 | }; | 202 | }; |
192 | 203 | ||
193 | /* | 204 | /* |
@@ -309,6 +320,9 @@ no_sensor_update: | |||
309 | ADT7473_REG_PWM_BHVR(i)); | 320 | ADT7473_REG_PWM_BHVR(i)); |
310 | } | 321 | } |
311 | 322 | ||
323 | i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); | ||
324 | data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT); | ||
325 | |||
312 | data->limits_last_updated = local_jiffies; | 326 | data->limits_last_updated = local_jiffies; |
313 | data->limits_valid = 1; | 327 | data->limits_valid = 1; |
314 | 328 | ||
@@ -1039,66 +1053,52 @@ static struct attribute *adt7473_attr[] = | |||
1039 | NULL | 1053 | NULL |
1040 | }; | 1054 | }; |
1041 | 1055 | ||
1042 | static int adt7473_attach_adapter(struct i2c_adapter *adapter) | 1056 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1057 | static int adt7473_detect(struct i2c_client *client, int kind, | ||
1058 | struct i2c_board_info *info) | ||
1043 | { | 1059 | { |
1044 | if (!(adapter->class & I2C_CLASS_HWMON)) | 1060 | struct i2c_adapter *adapter = client->adapter; |
1045 | return 0; | ||
1046 | return i2c_probe(adapter, &addr_data, adt7473_detect); | ||
1047 | } | ||
1048 | |||
1049 | static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind) | ||
1050 | { | ||
1051 | struct i2c_client *client; | ||
1052 | struct adt7473_data *data; | ||
1053 | int err = 0; | ||
1054 | 1061 | ||
1055 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1062 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1056 | goto exit; | 1063 | return -ENODEV; |
1057 | |||
1058 | data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); | ||
1059 | if (!data) { | ||
1060 | err = -ENOMEM; | ||
1061 | goto exit; | ||
1062 | } | ||
1063 | |||
1064 | client = &data->client; | ||
1065 | client->addr = address; | ||
1066 | client->adapter = adapter; | ||
1067 | client->driver = &adt7473_driver; | ||
1068 | |||
1069 | i2c_set_clientdata(client, data); | ||
1070 | |||
1071 | mutex_init(&data->lock); | ||
1072 | 1064 | ||
1073 | if (kind <= 0) { | 1065 | if (kind <= 0) { |
1074 | int vendor, device, revision; | 1066 | int vendor, device, revision; |
1075 | 1067 | ||
1076 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); | 1068 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); |
1077 | if (vendor != ADT7473_VENDOR) { | 1069 | if (vendor != ADT7473_VENDOR) |
1078 | err = -ENODEV; | 1070 | return -ENODEV; |
1079 | goto exit_free; | ||
1080 | } | ||
1081 | 1071 | ||
1082 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); | 1072 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); |
1083 | if (device != ADT7473_DEVICE) { | 1073 | if (device != ADT7473_DEVICE) |
1084 | err = -ENODEV; | 1074 | return -ENODEV; |
1085 | goto exit_free; | ||
1086 | } | ||
1087 | 1075 | ||
1088 | revision = i2c_smbus_read_byte_data(client, | 1076 | revision = i2c_smbus_read_byte_data(client, |
1089 | ADT7473_REG_REVISION); | 1077 | ADT7473_REG_REVISION); |
1090 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) { | 1078 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) |
1091 | err = -ENODEV; | 1079 | return -ENODEV; |
1092 | goto exit_free; | ||
1093 | } | ||
1094 | } else | 1080 | } else |
1095 | dev_dbg(&adapter->dev, "detection forced\n"); | 1081 | dev_dbg(&adapter->dev, "detection forced\n"); |
1096 | 1082 | ||
1097 | strlcpy(client->name, "adt7473", I2C_NAME_SIZE); | 1083 | strlcpy(info->type, "adt7473", I2C_NAME_SIZE); |
1098 | 1084 | ||
1099 | err = i2c_attach_client(client); | 1085 | return 0; |
1100 | if (err) | 1086 | } |
1101 | goto exit_free; | 1087 | |
1088 | static int adt7473_probe(struct i2c_client *client, | ||
1089 | const struct i2c_device_id *id) | ||
1090 | { | ||
1091 | struct adt7473_data *data; | ||
1092 | int err; | ||
1093 | |||
1094 | data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); | ||
1095 | if (!data) { | ||
1096 | err = -ENOMEM; | ||
1097 | goto exit; | ||
1098 | } | ||
1099 | |||
1100 | i2c_set_clientdata(client, data); | ||
1101 | mutex_init(&data->lock); | ||
1102 | 1102 | ||
1103 | dev_info(&client->dev, "%s chip found\n", client->name); | 1103 | dev_info(&client->dev, "%s chip found\n", client->name); |
1104 | 1104 | ||
@@ -1109,7 +1109,7 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1109 | data->attrs.attrs = adt7473_attr; | 1109 | data->attrs.attrs = adt7473_attr; |
1110 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | 1110 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); |
1111 | if (err) | 1111 | if (err) |
1112 | goto exit_detach; | 1112 | goto exit_free; |
1113 | 1113 | ||
1114 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1114 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1115 | if (IS_ERR(data->hwmon_dev)) { | 1115 | if (IS_ERR(data->hwmon_dev)) { |
@@ -1121,21 +1121,18 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1121 | 1121 | ||
1122 | exit_remove: | 1122 | exit_remove: |
1123 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1123 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1124 | exit_detach: | ||
1125 | i2c_detach_client(client); | ||
1126 | exit_free: | 1124 | exit_free: |
1127 | kfree(data); | 1125 | kfree(data); |
1128 | exit: | 1126 | exit: |
1129 | return err; | 1127 | return err; |
1130 | } | 1128 | } |
1131 | 1129 | ||
1132 | static int adt7473_detach_client(struct i2c_client *client) | 1130 | static int adt7473_remove(struct i2c_client *client) |
1133 | { | 1131 | { |
1134 | struct adt7473_data *data = i2c_get_clientdata(client); | 1132 | struct adt7473_data *data = i2c_get_clientdata(client); |
1135 | 1133 | ||
1136 | hwmon_device_unregister(data->hwmon_dev); | 1134 | hwmon_device_unregister(data->hwmon_dev); |
1137 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1135 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1138 | i2c_detach_client(client); | ||
1139 | kfree(data); | 1136 | kfree(data); |
1140 | return 0; | 1137 | return 0; |
1141 | } | 1138 | } |
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c index a112a03e8f29..fbefa82a015c 100644 --- a/drivers/hwmon/ams/ams-core.c +++ b/drivers/hwmon/ams/ams-core.c | |||
@@ -23,8 +23,8 @@ | |||
23 | #include <linux/types.h> | 23 | #include <linux/types.h> |
24 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/of_platform.h> | ||
26 | #include <asm/pmac_pfunc.h> | 27 | #include <asm/pmac_pfunc.h> |
27 | #include <asm/of_platform.h> | ||
28 | 28 | ||
29 | #include "ams.h" | 29 | #include "ams.h" |
30 | 30 | ||
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index fe2eea4d799b..8a45a2e6ba8a 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c | |||
@@ -176,10 +176,8 @@ static u8 DIV_TO_REG(long val) | |||
176 | data is pointed to by client->data. The structure itself is | 176 | data is pointed to by client->data. The structure itself is |
177 | dynamically allocated, at the same time the client itself is allocated. */ | 177 | dynamically allocated, at the same time the client itself is allocated. */ |
178 | struct asb100_data { | 178 | struct asb100_data { |
179 | struct i2c_client client; | ||
180 | struct device *hwmon_dev; | 179 | struct device *hwmon_dev; |
181 | struct mutex lock; | 180 | struct mutex lock; |
182 | enum chips type; | ||
183 | 181 | ||
184 | struct mutex update_lock; | 182 | struct mutex update_lock; |
185 | unsigned long last_updated; /* In jiffies */ | 183 | unsigned long last_updated; /* In jiffies */ |
@@ -206,18 +204,30 @@ struct asb100_data { | |||
206 | static int asb100_read_value(struct i2c_client *client, u16 reg); | 204 | static int asb100_read_value(struct i2c_client *client, u16 reg); |
207 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); | 205 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); |
208 | 206 | ||
209 | static int asb100_attach_adapter(struct i2c_adapter *adapter); | 207 | static int asb100_probe(struct i2c_client *client, |
210 | static int asb100_detect(struct i2c_adapter *adapter, int address, int kind); | 208 | const struct i2c_device_id *id); |
211 | static int asb100_detach_client(struct i2c_client *client); | 209 | static int asb100_detect(struct i2c_client *client, int kind, |
210 | struct i2c_board_info *info); | ||
211 | static int asb100_remove(struct i2c_client *client); | ||
212 | static struct asb100_data *asb100_update_device(struct device *dev); | 212 | static struct asb100_data *asb100_update_device(struct device *dev); |
213 | static void asb100_init_client(struct i2c_client *client); | 213 | static void asb100_init_client(struct i2c_client *client); |
214 | 214 | ||
215 | static const struct i2c_device_id asb100_id[] = { | ||
216 | { "asb100", asb100 }, | ||
217 | { } | ||
218 | }; | ||
219 | MODULE_DEVICE_TABLE(i2c, asb100_id); | ||
220 | |||
215 | static struct i2c_driver asb100_driver = { | 221 | static struct i2c_driver asb100_driver = { |
222 | .class = I2C_CLASS_HWMON, | ||
216 | .driver = { | 223 | .driver = { |
217 | .name = "asb100", | 224 | .name = "asb100", |
218 | }, | 225 | }, |
219 | .attach_adapter = asb100_attach_adapter, | 226 | .probe = asb100_probe, |
220 | .detach_client = asb100_detach_client, | 227 | .remove = asb100_remove, |
228 | .id_table = asb100_id, | ||
229 | .detect = asb100_detect, | ||
230 | .address_data = &addr_data, | ||
221 | }; | 231 | }; |
222 | 232 | ||
223 | /* 7 Voltages */ | 233 | /* 7 Voltages */ |
@@ -619,35 +629,13 @@ static const struct attribute_group asb100_group = { | |||
619 | .attrs = asb100_attributes, | 629 | .attrs = asb100_attributes, |
620 | }; | 630 | }; |
621 | 631 | ||
622 | /* This function is called when: | 632 | static int asb100_detect_subclients(struct i2c_client *client) |
623 | asb100_driver is inserted (when this module is loaded), for each | ||
624 | available adapter | ||
625 | when a new adapter is inserted (and asb100_driver is still present) | ||
626 | */ | ||
627 | static int asb100_attach_adapter(struct i2c_adapter *adapter) | ||
628 | { | ||
629 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
630 | return 0; | ||
631 | return i2c_probe(adapter, &addr_data, asb100_detect); | ||
632 | } | ||
633 | |||
634 | static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | ||
635 | int kind, struct i2c_client *client) | ||
636 | { | 633 | { |
637 | int i, id, err; | 634 | int i, id, err; |
635 | int address = client->addr; | ||
636 | unsigned short sc_addr[2]; | ||
638 | struct asb100_data *data = i2c_get_clientdata(client); | 637 | struct asb100_data *data = i2c_get_clientdata(client); |
639 | 638 | struct i2c_adapter *adapter = client->adapter; | |
640 | data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
641 | if (!(data->lm75[0])) { | ||
642 | err = -ENOMEM; | ||
643 | goto ERROR_SC_0; | ||
644 | } | ||
645 | |||
646 | data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
647 | if (!(data->lm75[1])) { | ||
648 | err = -ENOMEM; | ||
649 | goto ERROR_SC_1; | ||
650 | } | ||
651 | 639 | ||
652 | id = i2c_adapter_id(adapter); | 640 | id = i2c_adapter_id(adapter); |
653 | 641 | ||
@@ -665,37 +653,34 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | |||
665 | asb100_write_value(client, ASB100_REG_I2C_SUBADDR, | 653 | asb100_write_value(client, ASB100_REG_I2C_SUBADDR, |
666 | (force_subclients[2] & 0x07) | | 654 | (force_subclients[2] & 0x07) | |
667 | ((force_subclients[3] & 0x07) << 4)); | 655 | ((force_subclients[3] & 0x07) << 4)); |
668 | data->lm75[0]->addr = force_subclients[2]; | 656 | sc_addr[0] = force_subclients[2]; |
669 | data->lm75[1]->addr = force_subclients[3]; | 657 | sc_addr[1] = force_subclients[3]; |
670 | } else { | 658 | } else { |
671 | int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR); | 659 | int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR); |
672 | data->lm75[0]->addr = 0x48 + (val & 0x07); | 660 | sc_addr[0] = 0x48 + (val & 0x07); |
673 | data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07); | 661 | sc_addr[1] = 0x48 + ((val >> 4) & 0x07); |
674 | } | 662 | } |
675 | 663 | ||
676 | if (data->lm75[0]->addr == data->lm75[1]->addr) { | 664 | if (sc_addr[0] == sc_addr[1]) { |
677 | dev_err(&client->dev, "duplicate addresses 0x%x " | 665 | dev_err(&client->dev, "duplicate addresses 0x%x " |
678 | "for subclients\n", data->lm75[0]->addr); | 666 | "for subclients\n", sc_addr[0]); |
679 | err = -ENODEV; | 667 | err = -ENODEV; |
680 | goto ERROR_SC_2; | 668 | goto ERROR_SC_2; |
681 | } | 669 | } |
682 | 670 | ||
683 | for (i = 0; i <= 1; i++) { | 671 | data->lm75[0] = i2c_new_dummy(adapter, sc_addr[0]); |
684 | i2c_set_clientdata(data->lm75[i], NULL); | 672 | if (!data->lm75[0]) { |
685 | data->lm75[i]->adapter = adapter; | ||
686 | data->lm75[i]->driver = &asb100_driver; | ||
687 | strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE); | ||
688 | } | ||
689 | |||
690 | if ((err = i2c_attach_client(data->lm75[0]))) { | ||
691 | dev_err(&client->dev, "subclient %d registration " | 673 | dev_err(&client->dev, "subclient %d registration " |
692 | "at address 0x%x failed.\n", i, data->lm75[0]->addr); | 674 | "at address 0x%x failed.\n", 1, sc_addr[0]); |
675 | err = -ENOMEM; | ||
693 | goto ERROR_SC_2; | 676 | goto ERROR_SC_2; |
694 | } | 677 | } |
695 | 678 | ||
696 | if ((err = i2c_attach_client(data->lm75[1]))) { | 679 | data->lm75[1] = i2c_new_dummy(adapter, sc_addr[1]); |
680 | if (!data->lm75[1]) { | ||
697 | dev_err(&client->dev, "subclient %d registration " | 681 | dev_err(&client->dev, "subclient %d registration " |
698 | "at address 0x%x failed.\n", i, data->lm75[1]->addr); | 682 | "at address 0x%x failed.\n", 2, sc_addr[1]); |
683 | err = -ENOMEM; | ||
699 | goto ERROR_SC_3; | 684 | goto ERROR_SC_3; |
700 | } | 685 | } |
701 | 686 | ||
@@ -703,55 +688,31 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | |||
703 | 688 | ||
704 | /* Undo inits in case of errors */ | 689 | /* Undo inits in case of errors */ |
705 | ERROR_SC_3: | 690 | ERROR_SC_3: |
706 | i2c_detach_client(data->lm75[0]); | 691 | i2c_unregister_device(data->lm75[0]); |
707 | ERROR_SC_2: | 692 | ERROR_SC_2: |
708 | kfree(data->lm75[1]); | ||
709 | ERROR_SC_1: | ||
710 | kfree(data->lm75[0]); | ||
711 | ERROR_SC_0: | ||
712 | return err; | 693 | return err; |
713 | } | 694 | } |
714 | 695 | ||
715 | static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | 696 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
697 | static int asb100_detect(struct i2c_client *client, int kind, | ||
698 | struct i2c_board_info *info) | ||
716 | { | 699 | { |
717 | int err; | 700 | struct i2c_adapter *adapter = client->adapter; |
718 | struct i2c_client *client; | ||
719 | struct asb100_data *data; | ||
720 | 701 | ||
721 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 702 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
722 | pr_debug("asb100.o: detect failed, " | 703 | pr_debug("asb100.o: detect failed, " |
723 | "smbus byte data not supported!\n"); | 704 | "smbus byte data not supported!\n"); |
724 | err = -ENODEV; | 705 | return -ENODEV; |
725 | goto ERROR0; | ||
726 | } | 706 | } |
727 | 707 | ||
728 | /* OK. For now, we presume we have a valid client. We now create the | ||
729 | client structure, even though we cannot fill it completely yet. | ||
730 | But it allows us to access asb100_{read,write}_value. */ | ||
731 | |||
732 | if (!(data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL))) { | ||
733 | pr_debug("asb100.o: detect failed, kzalloc failed!\n"); | ||
734 | err = -ENOMEM; | ||
735 | goto ERROR0; | ||
736 | } | ||
737 | |||
738 | client = &data->client; | ||
739 | mutex_init(&data->lock); | ||
740 | i2c_set_clientdata(client, data); | ||
741 | client->addr = address; | ||
742 | client->adapter = adapter; | ||
743 | client->driver = &asb100_driver; | ||
744 | |||
745 | /* Now, we do the remaining detection. */ | ||
746 | |||
747 | /* The chip may be stuck in some other bank than bank 0. This may | 708 | /* The chip may be stuck in some other bank than bank 0. This may |
748 | make reading other information impossible. Specify a force=... or | 709 | make reading other information impossible. Specify a force=... or |
749 | force_*=... parameter, and the chip will be reset to the right | 710 | force_*=... parameter, and the chip will be reset to the right |
750 | bank. */ | 711 | bank. */ |
751 | if (kind < 0) { | 712 | if (kind < 0) { |
752 | 713 | ||
753 | int val1 = asb100_read_value(client, ASB100_REG_BANK); | 714 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK); |
754 | int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN); | 715 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
755 | 716 | ||
756 | /* If we're in bank 0 */ | 717 | /* If we're in bank 0 */ |
757 | if ((!(val1 & 0x07)) && | 718 | if ((!(val1 & 0x07)) && |
@@ -761,48 +722,60 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
761 | ((val1 & 0x80) && (val2 != 0x06)))) { | 722 | ((val1 & 0x80) && (val2 != 0x06)))) { |
762 | pr_debug("asb100.o: detect failed, " | 723 | pr_debug("asb100.o: detect failed, " |
763 | "bad chip id 0x%02x!\n", val2); | 724 | "bad chip id 0x%02x!\n", val2); |
764 | err = -ENODEV; | 725 | return -ENODEV; |
765 | goto ERROR1; | ||
766 | } | 726 | } |
767 | 727 | ||
768 | } /* kind < 0 */ | 728 | } /* kind < 0 */ |
769 | 729 | ||
770 | /* We have either had a force parameter, or we have already detected | 730 | /* We have either had a force parameter, or we have already detected |
771 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ | 731 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ |
772 | asb100_write_value(client, ASB100_REG_BANK, | 732 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, |
773 | (asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80); | 733 | (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) |
734 | | 0x80); | ||
774 | 735 | ||
775 | /* Determine the chip type. */ | 736 | /* Determine the chip type. */ |
776 | if (kind <= 0) { | 737 | if (kind <= 0) { |
777 | int val1 = asb100_read_value(client, ASB100_REG_WCHIPID); | 738 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); |
778 | int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN); | 739 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
779 | 740 | ||
780 | if ((val1 == 0x31) && (val2 == 0x06)) | 741 | if ((val1 == 0x31) && (val2 == 0x06)) |
781 | kind = asb100; | 742 | kind = asb100; |
782 | else { | 743 | else { |
783 | if (kind == 0) | 744 | if (kind == 0) |
784 | dev_warn(&client->dev, "ignoring " | 745 | dev_warn(&adapter->dev, "ignoring " |
785 | "'force' parameter for unknown chip " | 746 | "'force' parameter for unknown chip " |
786 | "at adapter %d, address 0x%02x.\n", | 747 | "at adapter %d, address 0x%02x.\n", |
787 | i2c_adapter_id(adapter), address); | 748 | i2c_adapter_id(adapter), client->addr); |
788 | err = -ENODEV; | 749 | return -ENODEV; |
789 | goto ERROR1; | ||
790 | } | 750 | } |
791 | } | 751 | } |
792 | 752 | ||
793 | /* Fill in remaining client fields and put it into the global list */ | 753 | strlcpy(info->type, "asb100", I2C_NAME_SIZE); |
794 | strlcpy(client->name, "asb100", I2C_NAME_SIZE); | ||
795 | data->type = kind; | ||
796 | mutex_init(&data->update_lock); | ||
797 | 754 | ||
798 | /* Tell the I2C layer a new client has arrived */ | 755 | return 0; |
799 | if ((err = i2c_attach_client(client))) | 756 | } |
800 | goto ERROR1; | 757 | |
758 | static int asb100_probe(struct i2c_client *client, | ||
759 | const struct i2c_device_id *id) | ||
760 | { | ||
761 | int err; | ||
762 | struct asb100_data *data; | ||
763 | |||
764 | data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL); | ||
765 | if (!data) { | ||
766 | pr_debug("asb100.o: probe failed, kzalloc failed!\n"); | ||
767 | err = -ENOMEM; | ||
768 | goto ERROR0; | ||
769 | } | ||
770 | |||
771 | i2c_set_clientdata(client, data); | ||
772 | mutex_init(&data->lock); | ||
773 | mutex_init(&data->update_lock); | ||
801 | 774 | ||
802 | /* Attach secondary lm75 clients */ | 775 | /* Attach secondary lm75 clients */ |
803 | if ((err = asb100_detect_subclients(adapter, address, kind, | 776 | err = asb100_detect_subclients(client); |
804 | client))) | 777 | if (err) |
805 | goto ERROR2; | 778 | goto ERROR1; |
806 | 779 | ||
807 | /* Initialize the chip */ | 780 | /* Initialize the chip */ |
808 | asb100_init_client(client); | 781 | asb100_init_client(client); |
@@ -827,39 +800,25 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
827 | ERROR4: | 800 | ERROR4: |
828 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | 801 | sysfs_remove_group(&client->dev.kobj, &asb100_group); |
829 | ERROR3: | 802 | ERROR3: |
830 | i2c_detach_client(data->lm75[1]); | 803 | i2c_unregister_device(data->lm75[1]); |
831 | i2c_detach_client(data->lm75[0]); | 804 | i2c_unregister_device(data->lm75[0]); |
832 | kfree(data->lm75[1]); | ||
833 | kfree(data->lm75[0]); | ||
834 | ERROR2: | ||
835 | i2c_detach_client(client); | ||
836 | ERROR1: | 805 | ERROR1: |
837 | kfree(data); | 806 | kfree(data); |
838 | ERROR0: | 807 | ERROR0: |
839 | return err; | 808 | return err; |
840 | } | 809 | } |
841 | 810 | ||
842 | static int asb100_detach_client(struct i2c_client *client) | 811 | static int asb100_remove(struct i2c_client *client) |
843 | { | 812 | { |
844 | struct asb100_data *data = i2c_get_clientdata(client); | 813 | struct asb100_data *data = i2c_get_clientdata(client); |
845 | int err; | ||
846 | |||
847 | /* main client */ | ||
848 | if (data) { | ||
849 | hwmon_device_unregister(data->hwmon_dev); | ||
850 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | ||
851 | } | ||
852 | 814 | ||
853 | if ((err = i2c_detach_client(client))) | 815 | hwmon_device_unregister(data->hwmon_dev); |
854 | return err; | 816 | sysfs_remove_group(&client->dev.kobj, &asb100_group); |
855 | 817 | ||
856 | /* main client */ | 818 | i2c_unregister_device(data->lm75[1]); |
857 | if (data) | 819 | i2c_unregister_device(data->lm75[0]); |
858 | kfree(data); | ||
859 | 820 | ||
860 | /* subclient */ | 821 | kfree(data); |
861 | else | ||
862 | kfree(client); | ||
863 | 822 | ||
864 | return 0; | 823 | return 0; |
865 | } | 824 | } |
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index 01c17e387f03..d191118ba0cb 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -46,21 +46,32 @@ static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; | |||
46 | 46 | ||
47 | I2C_CLIENT_INSMOD_1(atxp1); | 47 | I2C_CLIENT_INSMOD_1(atxp1); |
48 | 48 | ||
49 | static int atxp1_attach_adapter(struct i2c_adapter * adapter); | 49 | static int atxp1_probe(struct i2c_client *client, |
50 | static int atxp1_detach_client(struct i2c_client * client); | 50 | const struct i2c_device_id *id); |
51 | static int atxp1_remove(struct i2c_client *client); | ||
51 | static struct atxp1_data * atxp1_update_device(struct device *dev); | 52 | static struct atxp1_data * atxp1_update_device(struct device *dev); |
52 | static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind); | 53 | static int atxp1_detect(struct i2c_client *client, int kind, |
54 | struct i2c_board_info *info); | ||
55 | |||
56 | static const struct i2c_device_id atxp1_id[] = { | ||
57 | { "atxp1", atxp1 }, | ||
58 | { } | ||
59 | }; | ||
60 | MODULE_DEVICE_TABLE(i2c, atxp1_id); | ||
53 | 61 | ||
54 | static struct i2c_driver atxp1_driver = { | 62 | static struct i2c_driver atxp1_driver = { |
63 | .class = I2C_CLASS_HWMON, | ||
55 | .driver = { | 64 | .driver = { |
56 | .name = "atxp1", | 65 | .name = "atxp1", |
57 | }, | 66 | }, |
58 | .attach_adapter = atxp1_attach_adapter, | 67 | .probe = atxp1_probe, |
59 | .detach_client = atxp1_detach_client, | 68 | .remove = atxp1_remove, |
69 | .id_table = atxp1_id, | ||
70 | .detect = atxp1_detect, | ||
71 | .address_data = &addr_data, | ||
60 | }; | 72 | }; |
61 | 73 | ||
62 | struct atxp1_data { | 74 | struct atxp1_data { |
63 | struct i2c_client client; | ||
64 | struct device *hwmon_dev; | 75 | struct device *hwmon_dev; |
65 | struct mutex update_lock; | 76 | struct mutex update_lock; |
66 | unsigned long last_updated; | 77 | unsigned long last_updated; |
@@ -263,35 +274,16 @@ static const struct attribute_group atxp1_group = { | |||
263 | }; | 274 | }; |
264 | 275 | ||
265 | 276 | ||
266 | static int atxp1_attach_adapter(struct i2c_adapter *adapter) | 277 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
278 | static int atxp1_detect(struct i2c_client *new_client, int kind, | ||
279 | struct i2c_board_info *info) | ||
267 | { | 280 | { |
268 | if (!(adapter->class & I2C_CLASS_HWMON)) | 281 | struct i2c_adapter *adapter = new_client->adapter; |
269 | return 0; | ||
270 | return i2c_probe(adapter, &addr_data, &atxp1_detect); | ||
271 | }; | ||
272 | 282 | ||
273 | static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | ||
274 | { | ||
275 | struct i2c_client * new_client; | ||
276 | struct atxp1_data * data; | ||
277 | int err = 0; | ||
278 | u8 temp; | 283 | u8 temp; |
279 | 284 | ||
280 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 285 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
281 | goto exit; | 286 | return -ENODEV; |
282 | |||
283 | if (!(data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL))) { | ||
284 | err = -ENOMEM; | ||
285 | goto exit; | ||
286 | } | ||
287 | |||
288 | new_client = &data->client; | ||
289 | i2c_set_clientdata(new_client, data); | ||
290 | |||
291 | new_client->addr = address; | ||
292 | new_client->adapter = adapter; | ||
293 | new_client->driver = &atxp1_driver; | ||
294 | new_client->flags = 0; | ||
295 | 287 | ||
296 | /* Detect ATXP1, checking if vendor ID registers are all zero */ | 288 | /* Detect ATXP1, checking if vendor ID registers are all zero */ |
297 | if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) && | 289 | if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) && |
@@ -305,35 +297,46 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
305 | 297 | ||
306 | if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && | 298 | if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && |
307 | (i2c_smbus_read_byte_data(new_client, 0x11) == temp) )) | 299 | (i2c_smbus_read_byte_data(new_client, 0x11) == temp) )) |
308 | goto exit_free; | 300 | return -ENODEV; |
309 | } | 301 | } |
310 | 302 | ||
311 | /* Get VRM */ | 303 | /* Get VRM */ |
312 | data->vrm = vid_which_vrm(); | 304 | temp = vid_which_vrm(); |
313 | 305 | ||
314 | if ((data->vrm != 90) && (data->vrm != 91)) { | 306 | if ((temp != 90) && (temp != 91)) { |
315 | dev_err(&new_client->dev, "Not supporting VRM %d.%d\n", | 307 | dev_err(&adapter->dev, "atxp1: Not supporting VRM %d.%d\n", |
316 | data->vrm / 10, data->vrm % 10); | 308 | temp / 10, temp % 10); |
317 | goto exit_free; | 309 | return -ENODEV; |
318 | } | 310 | } |
319 | 311 | ||
320 | strncpy(new_client->name, "atxp1", I2C_NAME_SIZE); | 312 | strlcpy(info->type, "atxp1", I2C_NAME_SIZE); |
321 | |||
322 | data->valid = 0; | ||
323 | 313 | ||
324 | mutex_init(&data->update_lock); | 314 | return 0; |
315 | } | ||
325 | 316 | ||
326 | err = i2c_attach_client(new_client); | 317 | static int atxp1_probe(struct i2c_client *new_client, |
318 | const struct i2c_device_id *id) | ||
319 | { | ||
320 | struct atxp1_data *data; | ||
321 | int err; | ||
327 | 322 | ||
328 | if (err) | 323 | data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL); |
329 | { | 324 | if (!data) { |
330 | dev_err(&new_client->dev, "Attach client error.\n"); | 325 | err = -ENOMEM; |
331 | goto exit_free; | 326 | goto exit; |
332 | } | 327 | } |
333 | 328 | ||
329 | /* Get VRM */ | ||
330 | data->vrm = vid_which_vrm(); | ||
331 | |||
332 | i2c_set_clientdata(new_client, data); | ||
333 | data->valid = 0; | ||
334 | |||
335 | mutex_init(&data->update_lock); | ||
336 | |||
334 | /* Register sysfs hooks */ | 337 | /* Register sysfs hooks */ |
335 | if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) | 338 | if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) |
336 | goto exit_detach; | 339 | goto exit_free; |
337 | 340 | ||
338 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 341 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
339 | if (IS_ERR(data->hwmon_dev)) { | 342 | if (IS_ERR(data->hwmon_dev)) { |
@@ -348,30 +351,22 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
348 | 351 | ||
349 | exit_remove_files: | 352 | exit_remove_files: |
350 | sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); | 353 | sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); |
351 | exit_detach: | ||
352 | i2c_detach_client(new_client); | ||
353 | exit_free: | 354 | exit_free: |
354 | kfree(data); | 355 | kfree(data); |
355 | exit: | 356 | exit: |
356 | return err; | 357 | return err; |
357 | }; | 358 | }; |
358 | 359 | ||
359 | static int atxp1_detach_client(struct i2c_client * client) | 360 | static int atxp1_remove(struct i2c_client *client) |
360 | { | 361 | { |
361 | struct atxp1_data * data = i2c_get_clientdata(client); | 362 | struct atxp1_data * data = i2c_get_clientdata(client); |
362 | int err; | ||
363 | 363 | ||
364 | hwmon_device_unregister(data->hwmon_dev); | 364 | hwmon_device_unregister(data->hwmon_dev); |
365 | sysfs_remove_group(&client->dev.kobj, &atxp1_group); | 365 | sysfs_remove_group(&client->dev.kobj, &atxp1_group); |
366 | 366 | ||
367 | err = i2c_detach_client(client); | 367 | kfree(data); |
368 | |||
369 | if (err) | ||
370 | dev_err(&client->dev, "Failed to detach client.\n"); | ||
371 | else | ||
372 | kfree(data); | ||
373 | 368 | ||
374 | return err; | 369 | return 0; |
375 | }; | 370 | }; |
376 | 371 | ||
377 | static int __init atxp1_init(void) | 372 | static int __init atxp1_init(void) |
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 5f300ffed657..7415381601c3 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -72,7 +72,6 @@ static const u8 DS1621_REG_TEMP[3] = { | |||
72 | 72 | ||
73 | /* Each client has this additional data */ | 73 | /* Each client has this additional data */ |
74 | struct ds1621_data { | 74 | struct ds1621_data { |
75 | struct i2c_client client; | ||
76 | struct device *hwmon_dev; | 75 | struct device *hwmon_dev; |
77 | struct mutex update_lock; | 76 | struct mutex update_lock; |
78 | char valid; /* !=0 if following fields are valid */ | 77 | char valid; /* !=0 if following fields are valid */ |
@@ -82,20 +81,32 @@ struct ds1621_data { | |||
82 | u8 conf; /* Register encoding, combined */ | 81 | u8 conf; /* Register encoding, combined */ |
83 | }; | 82 | }; |
84 | 83 | ||
85 | static int ds1621_attach_adapter(struct i2c_adapter *adapter); | 84 | static int ds1621_probe(struct i2c_client *client, |
86 | static int ds1621_detect(struct i2c_adapter *adapter, int address, | 85 | const struct i2c_device_id *id); |
87 | int kind); | 86 | static int ds1621_detect(struct i2c_client *client, int kind, |
87 | struct i2c_board_info *info); | ||
88 | static void ds1621_init_client(struct i2c_client *client); | 88 | static void ds1621_init_client(struct i2c_client *client); |
89 | static int ds1621_detach_client(struct i2c_client *client); | 89 | static int ds1621_remove(struct i2c_client *client); |
90 | static struct ds1621_data *ds1621_update_client(struct device *dev); | 90 | static struct ds1621_data *ds1621_update_client(struct device *dev); |
91 | 91 | ||
92 | static const struct i2c_device_id ds1621_id[] = { | ||
93 | { "ds1621", ds1621 }, | ||
94 | { "ds1625", ds1621 }, | ||
95 | { } | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(i2c, ds1621_id); | ||
98 | |||
92 | /* This is the driver that will be inserted */ | 99 | /* This is the driver that will be inserted */ |
93 | static struct i2c_driver ds1621_driver = { | 100 | static struct i2c_driver ds1621_driver = { |
101 | .class = I2C_CLASS_HWMON, | ||
94 | .driver = { | 102 | .driver = { |
95 | .name = "ds1621", | 103 | .name = "ds1621", |
96 | }, | 104 | }, |
97 | .attach_adapter = ds1621_attach_adapter, | 105 | .probe = ds1621_probe, |
98 | .detach_client = ds1621_detach_client, | 106 | .remove = ds1621_remove, |
107 | .id_table = ds1621_id, | ||
108 | .detect = ds1621_detect, | ||
109 | .address_data = &addr_data, | ||
99 | }; | 110 | }; |
100 | 111 | ||
101 | /* All registers are word-sized, except for the configuration register. | 112 | /* All registers are word-sized, except for the configuration register. |
@@ -199,40 +210,18 @@ static const struct attribute_group ds1621_group = { | |||
199 | }; | 210 | }; |
200 | 211 | ||
201 | 212 | ||
202 | static int ds1621_attach_adapter(struct i2c_adapter *adapter) | 213 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
203 | { | 214 | static int ds1621_detect(struct i2c_client *client, int kind, |
204 | if (!(adapter->class & I2C_CLASS_HWMON)) | 215 | struct i2c_board_info *info) |
205 | return 0; | ||
206 | return i2c_probe(adapter, &addr_data, ds1621_detect); | ||
207 | } | ||
208 | |||
209 | /* This function is called by i2c_probe */ | ||
210 | static int ds1621_detect(struct i2c_adapter *adapter, int address, | ||
211 | int kind) | ||
212 | { | 216 | { |
217 | struct i2c_adapter *adapter = client->adapter; | ||
213 | int conf, temp; | 218 | int conf, temp; |
214 | struct i2c_client *client; | 219 | int i; |
215 | struct ds1621_data *data; | ||
216 | int i, err = 0; | ||
217 | 220 | ||
218 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 221 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
219 | | I2C_FUNC_SMBUS_WORD_DATA | 222 | | I2C_FUNC_SMBUS_WORD_DATA |
220 | | I2C_FUNC_SMBUS_WRITE_BYTE)) | 223 | | I2C_FUNC_SMBUS_WRITE_BYTE)) |
221 | goto exit; | 224 | return -ENODEV; |
222 | |||
223 | /* OK. For now, we presume we have a valid client. We now create the | ||
224 | client structure, even though we cannot fill it completely yet. | ||
225 | But it allows us to access ds1621_{read,write}_value. */ | ||
226 | if (!(data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL))) { | ||
227 | err = -ENOMEM; | ||
228 | goto exit; | ||
229 | } | ||
230 | |||
231 | client = &data->client; | ||
232 | i2c_set_clientdata(client, data); | ||
233 | client->addr = address; | ||
234 | client->adapter = adapter; | ||
235 | client->driver = &ds1621_driver; | ||
236 | 225 | ||
237 | /* Now, we do the remaining detection. It is lousy. */ | 226 | /* Now, we do the remaining detection. It is lousy. */ |
238 | if (kind < 0) { | 227 | if (kind < 0) { |
@@ -241,29 +230,41 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
241 | improbable in our case. */ | 230 | improbable in our case. */ |
242 | conf = ds1621_read_value(client, DS1621_REG_CONF); | 231 | conf = ds1621_read_value(client, DS1621_REG_CONF); |
243 | if (conf & DS1621_REG_CONFIG_NVB) | 232 | if (conf & DS1621_REG_CONFIG_NVB) |
244 | goto exit_free; | 233 | return -ENODEV; |
245 | /* The 7 lowest bits of a temperature should always be 0. */ | 234 | /* The 7 lowest bits of a temperature should always be 0. */ |
246 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { | 235 | for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) { |
247 | temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); | 236 | temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); |
248 | if (temp & 0x007f) | 237 | if (temp & 0x007f) |
249 | goto exit_free; | 238 | return -ENODEV; |
250 | } | 239 | } |
251 | } | 240 | } |
252 | 241 | ||
253 | /* Fill in remaining client fields and put it into the global list */ | 242 | strlcpy(info->type, "ds1621", I2C_NAME_SIZE); |
254 | strlcpy(client->name, "ds1621", I2C_NAME_SIZE); | ||
255 | mutex_init(&data->update_lock); | ||
256 | 243 | ||
257 | /* Tell the I2C layer a new client has arrived */ | 244 | return 0; |
258 | if ((err = i2c_attach_client(client))) | 245 | } |
259 | goto exit_free; | 246 | |
247 | static int ds1621_probe(struct i2c_client *client, | ||
248 | const struct i2c_device_id *id) | ||
249 | { | ||
250 | struct ds1621_data *data; | ||
251 | int err; | ||
252 | |||
253 | data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL); | ||
254 | if (!data) { | ||
255 | err = -ENOMEM; | ||
256 | goto exit; | ||
257 | } | ||
258 | |||
259 | i2c_set_clientdata(client, data); | ||
260 | mutex_init(&data->update_lock); | ||
260 | 261 | ||
261 | /* Initialize the DS1621 chip */ | 262 | /* Initialize the DS1621 chip */ |
262 | ds1621_init_client(client); | 263 | ds1621_init_client(client); |
263 | 264 | ||
264 | /* Register sysfs hooks */ | 265 | /* Register sysfs hooks */ |
265 | if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) | 266 | if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) |
266 | goto exit_detach; | 267 | goto exit_free; |
267 | 268 | ||
268 | data->hwmon_dev = hwmon_device_register(&client->dev); | 269 | data->hwmon_dev = hwmon_device_register(&client->dev); |
269 | if (IS_ERR(data->hwmon_dev)) { | 270 | if (IS_ERR(data->hwmon_dev)) { |
@@ -275,25 +276,19 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
275 | 276 | ||
276 | exit_remove_files: | 277 | exit_remove_files: |
277 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | 278 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); |
278 | exit_detach: | ||
279 | i2c_detach_client(client); | ||
280 | exit_free: | 279 | exit_free: |
281 | kfree(data); | 280 | kfree(data); |
282 | exit: | 281 | exit: |
283 | return err; | 282 | return err; |
284 | } | 283 | } |
285 | 284 | ||
286 | static int ds1621_detach_client(struct i2c_client *client) | 285 | static int ds1621_remove(struct i2c_client *client) |
287 | { | 286 | { |
288 | struct ds1621_data *data = i2c_get_clientdata(client); | 287 | struct ds1621_data *data = i2c_get_clientdata(client); |
289 | int err; | ||
290 | 288 | ||
291 | hwmon_device_unregister(data->hwmon_dev); | 289 | hwmon_device_unregister(data->hwmon_dev); |
292 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | 290 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); |
293 | 291 | ||
294 | if ((err = i2c_detach_client(client))) | ||
295 | return err; | ||
296 | |||
297 | kfree(data); | 292 | kfree(data); |
298 | 293 | ||
299 | return 0; | 294 | return 0; |
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index dc1f30e432ea..1692de369969 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -87,7 +87,6 @@ I2C_CLIENT_INSMOD_2(f75373, f75375); | |||
87 | 87 | ||
88 | struct f75375_data { | 88 | struct f75375_data { |
89 | unsigned short addr; | 89 | unsigned short addr; |
90 | struct i2c_client *client; | ||
91 | struct device *hwmon_dev; | 90 | struct device *hwmon_dev; |
92 | 91 | ||
93 | const char *name; | 92 | const char *name; |
@@ -114,21 +113,12 @@ struct f75375_data { | |||
114 | s8 temp_max_hyst[2]; | 113 | s8 temp_max_hyst[2]; |
115 | }; | 114 | }; |
116 | 115 | ||
117 | static int f75375_attach_adapter(struct i2c_adapter *adapter); | 116 | static int f75375_detect(struct i2c_client *client, int kind, |
118 | static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); | 117 | struct i2c_board_info *info); |
119 | static int f75375_detach_client(struct i2c_client *client); | ||
120 | static int f75375_probe(struct i2c_client *client, | 118 | static int f75375_probe(struct i2c_client *client, |
121 | const struct i2c_device_id *id); | 119 | const struct i2c_device_id *id); |
122 | static int f75375_remove(struct i2c_client *client); | 120 | static int f75375_remove(struct i2c_client *client); |
123 | 121 | ||
124 | static struct i2c_driver f75375_legacy_driver = { | ||
125 | .driver = { | ||
126 | .name = "f75375_legacy", | ||
127 | }, | ||
128 | .attach_adapter = f75375_attach_adapter, | ||
129 | .detach_client = f75375_detach_client, | ||
130 | }; | ||
131 | |||
132 | static const struct i2c_device_id f75375_id[] = { | 122 | static const struct i2c_device_id f75375_id[] = { |
133 | { "f75373", f75373 }, | 123 | { "f75373", f75373 }, |
134 | { "f75375", f75375 }, | 124 | { "f75375", f75375 }, |
@@ -137,12 +127,15 @@ static const struct i2c_device_id f75375_id[] = { | |||
137 | MODULE_DEVICE_TABLE(i2c, f75375_id); | 127 | MODULE_DEVICE_TABLE(i2c, f75375_id); |
138 | 128 | ||
139 | static struct i2c_driver f75375_driver = { | 129 | static struct i2c_driver f75375_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
140 | .driver = { | 131 | .driver = { |
141 | .name = "f75375", | 132 | .name = "f75375", |
142 | }, | 133 | }, |
143 | .probe = f75375_probe, | 134 | .probe = f75375_probe, |
144 | .remove = f75375_remove, | 135 | .remove = f75375_remove, |
145 | .id_table = f75375_id, | 136 | .id_table = f75375_id, |
137 | .detect = f75375_detect, | ||
138 | .address_data = &addr_data, | ||
146 | }; | 139 | }; |
147 | 140 | ||
148 | static inline int f75375_read8(struct i2c_client *client, u8 reg) | 141 | static inline int f75375_read8(struct i2c_client *client, u8 reg) |
@@ -607,22 +600,6 @@ static const struct attribute_group f75375_group = { | |||
607 | .attrs = f75375_attributes, | 600 | .attrs = f75375_attributes, |
608 | }; | 601 | }; |
609 | 602 | ||
610 | static int f75375_detach_client(struct i2c_client *client) | ||
611 | { | ||
612 | int err; | ||
613 | |||
614 | f75375_remove(client); | ||
615 | err = i2c_detach_client(client); | ||
616 | if (err) { | ||
617 | dev_err(&client->dev, | ||
618 | "Client deregistration failed, " | ||
619 | "client not detached.\n"); | ||
620 | return err; | ||
621 | } | ||
622 | kfree(client); | ||
623 | return 0; | ||
624 | } | ||
625 | |||
626 | static void f75375_init(struct i2c_client *client, struct f75375_data *data, | 603 | static void f75375_init(struct i2c_client *client, struct f75375_data *data, |
627 | struct f75375s_platform_data *f75375s_pdata) | 604 | struct f75375s_platform_data *f75375s_pdata) |
628 | { | 605 | { |
@@ -651,7 +628,6 @@ static int f75375_probe(struct i2c_client *client, | |||
651 | return -ENOMEM; | 628 | return -ENOMEM; |
652 | 629 | ||
653 | i2c_set_clientdata(client, data); | 630 | i2c_set_clientdata(client, data); |
654 | data->client = client; | ||
655 | mutex_init(&data->update_lock); | 631 | mutex_init(&data->update_lock); |
656 | data->kind = id->driver_data; | 632 | data->kind = id->driver_data; |
657 | 633 | ||
@@ -700,29 +676,13 @@ static int f75375_remove(struct i2c_client *client) | |||
700 | return 0; | 676 | return 0; |
701 | } | 677 | } |
702 | 678 | ||
703 | static int f75375_attach_adapter(struct i2c_adapter *adapter) | 679 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
704 | { | 680 | static int f75375_detect(struct i2c_client *client, int kind, |
705 | if (!(adapter->class & I2C_CLASS_HWMON)) | 681 | struct i2c_board_info *info) |
706 | return 0; | ||
707 | return i2c_probe(adapter, &addr_data, f75375_detect); | ||
708 | } | ||
709 | |||
710 | /* This function is called by i2c_probe */ | ||
711 | static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | ||
712 | { | 682 | { |
713 | struct i2c_client *client; | 683 | struct i2c_adapter *adapter = client->adapter; |
714 | u8 version = 0; | 684 | u8 version = 0; |
715 | int err = 0; | ||
716 | const char *name = ""; | 685 | const char *name = ""; |
717 | struct i2c_device_id id; | ||
718 | |||
719 | if (!(client = kzalloc(sizeof(*client), GFP_KERNEL))) { | ||
720 | err = -ENOMEM; | ||
721 | goto exit; | ||
722 | } | ||
723 | client->addr = address; | ||
724 | client->adapter = adapter; | ||
725 | client->driver = &f75375_legacy_driver; | ||
726 | 686 | ||
727 | if (kind < 0) { | 687 | if (kind < 0) { |
728 | u16 vendid = f75375_read16(client, F75375_REG_VENDOR); | 688 | u16 vendid = f75375_read16(client, F75375_REG_VENDOR); |
@@ -736,7 +696,7 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | |||
736 | dev_err(&adapter->dev, | 696 | dev_err(&adapter->dev, |
737 | "failed,%02X,%02X,%02X\n", | 697 | "failed,%02X,%02X,%02X\n", |
738 | chipid, version, vendid); | 698 | chipid, version, vendid); |
739 | goto exit_free; | 699 | return -ENODEV; |
740 | } | 700 | } |
741 | } | 701 | } |
742 | 702 | ||
@@ -746,43 +706,18 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | |||
746 | name = "f75373"; | 706 | name = "f75373"; |
747 | } | 707 | } |
748 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); | 708 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); |
749 | strlcpy(client->name, name, I2C_NAME_SIZE); | 709 | strlcpy(info->type, name, I2C_NAME_SIZE); |
750 | |||
751 | if ((err = i2c_attach_client(client))) | ||
752 | goto exit_free; | ||
753 | |||
754 | strlcpy(id.name, name, I2C_NAME_SIZE); | ||
755 | id.driver_data = kind; | ||
756 | if ((err = f75375_probe(client, &id)) < 0) | ||
757 | goto exit_detach; | ||
758 | 710 | ||
759 | return 0; | 711 | return 0; |
760 | |||
761 | exit_detach: | ||
762 | i2c_detach_client(client); | ||
763 | exit_free: | ||
764 | kfree(client); | ||
765 | exit: | ||
766 | return err; | ||
767 | } | 712 | } |
768 | 713 | ||
769 | static int __init sensors_f75375_init(void) | 714 | static int __init sensors_f75375_init(void) |
770 | { | 715 | { |
771 | int status; | 716 | return i2c_add_driver(&f75375_driver); |
772 | status = i2c_add_driver(&f75375_driver); | ||
773 | if (status) | ||
774 | return status; | ||
775 | |||
776 | status = i2c_add_driver(&f75375_legacy_driver); | ||
777 | if (status) | ||
778 | i2c_del_driver(&f75375_driver); | ||
779 | |||
780 | return status; | ||
781 | } | 717 | } |
782 | 718 | ||
783 | static void __exit sensors_f75375_exit(void) | 719 | static void __exit sensors_f75375_exit(void) |
784 | { | 720 | { |
785 | i2c_del_driver(&f75375_legacy_driver); | ||
786 | i2c_del_driver(&f75375_driver); | 721 | i2c_del_driver(&f75375_driver); |
787 | } | 722 | } |
788 | 723 | ||
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c index ed26b66e0831..12c70e402cb2 100644 --- a/drivers/hwmon/fscher.c +++ b/drivers/hwmon/fscher.c | |||
@@ -106,9 +106,11 @@ I2C_CLIENT_INSMOD_1(fscher); | |||
106 | * Functions declaration | 106 | * Functions declaration |
107 | */ | 107 | */ |
108 | 108 | ||
109 | static int fscher_attach_adapter(struct i2c_adapter *adapter); | 109 | static int fscher_probe(struct i2c_client *client, |
110 | static int fscher_detect(struct i2c_adapter *adapter, int address, int kind); | 110 | const struct i2c_device_id *id); |
111 | static int fscher_detach_client(struct i2c_client *client); | 111 | static int fscher_detect(struct i2c_client *client, int kind, |
112 | struct i2c_board_info *info); | ||
113 | static int fscher_remove(struct i2c_client *client); | ||
112 | static struct fscher_data *fscher_update_device(struct device *dev); | 114 | static struct fscher_data *fscher_update_device(struct device *dev); |
113 | static void fscher_init_client(struct i2c_client *client); | 115 | static void fscher_init_client(struct i2c_client *client); |
114 | 116 | ||
@@ -119,12 +121,21 @@ static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value); | |||
119 | * Driver data (common to all clients) | 121 | * Driver data (common to all clients) |
120 | */ | 122 | */ |
121 | 123 | ||
124 | static const struct i2c_device_id fscher_id[] = { | ||
125 | { "fscher", fscher }, | ||
126 | { } | ||
127 | }; | ||
128 | |||
122 | static struct i2c_driver fscher_driver = { | 129 | static struct i2c_driver fscher_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
123 | .driver = { | 131 | .driver = { |
124 | .name = "fscher", | 132 | .name = "fscher", |
125 | }, | 133 | }, |
126 | .attach_adapter = fscher_attach_adapter, | 134 | .probe = fscher_probe, |
127 | .detach_client = fscher_detach_client, | 135 | .remove = fscher_remove, |
136 | .id_table = fscher_id, | ||
137 | .detect = fscher_detect, | ||
138 | .address_data = &addr_data, | ||
128 | }; | 139 | }; |
129 | 140 | ||
130 | /* | 141 | /* |
@@ -132,7 +143,6 @@ static struct i2c_driver fscher_driver = { | |||
132 | */ | 143 | */ |
133 | 144 | ||
134 | struct fscher_data { | 145 | struct fscher_data { |
135 | struct i2c_client client; | ||
136 | struct device *hwmon_dev; | 146 | struct device *hwmon_dev; |
137 | struct mutex update_lock; | 147 | struct mutex update_lock; |
138 | char valid; /* zero until following fields are valid */ | 148 | char valid; /* zero until following fields are valid */ |
@@ -283,38 +293,14 @@ static const struct attribute_group fscher_group = { | |||
283 | * Real code | 293 | * Real code |
284 | */ | 294 | */ |
285 | 295 | ||
286 | static int fscher_attach_adapter(struct i2c_adapter *adapter) | 296 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
287 | { | 297 | static int fscher_detect(struct i2c_client *new_client, int kind, |
288 | if (!(adapter->class & I2C_CLASS_HWMON)) | 298 | struct i2c_board_info *info) |
289 | return 0; | ||
290 | return i2c_probe(adapter, &addr_data, fscher_detect); | ||
291 | } | ||
292 | |||
293 | static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | ||
294 | { | 299 | { |
295 | struct i2c_client *new_client; | 300 | struct i2c_adapter *adapter = new_client->adapter; |
296 | struct fscher_data *data; | ||
297 | int err = 0; | ||
298 | 301 | ||
299 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 302 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
300 | goto exit; | 303 | return -ENODEV; |
301 | |||
302 | /* OK. For now, we presume we have a valid client. We now create the | ||
303 | * client structure, even though we cannot fill it completely yet. | ||
304 | * But it allows us to access i2c_smbus_read_byte_data. */ | ||
305 | if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) { | ||
306 | err = -ENOMEM; | ||
307 | goto exit; | ||
308 | } | ||
309 | |||
310 | /* The common I2C client data is placed right before the | ||
311 | * Hermes-specific data. */ | ||
312 | new_client = &data->client; | ||
313 | i2c_set_clientdata(new_client, data); | ||
314 | new_client->addr = address; | ||
315 | new_client->adapter = adapter; | ||
316 | new_client->driver = &fscher_driver; | ||
317 | new_client->flags = 0; | ||
318 | 304 | ||
319 | /* Do the remaining detection unless force or force_fscher parameter */ | 305 | /* Do the remaining detection unless force or force_fscher parameter */ |
320 | if (kind < 0) { | 306 | if (kind < 0) { |
@@ -324,24 +310,35 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
324 | FSCHER_REG_IDENT_1) != 0x45) /* 'E' */ | 310 | FSCHER_REG_IDENT_1) != 0x45) /* 'E' */ |
325 | || (i2c_smbus_read_byte_data(new_client, | 311 | || (i2c_smbus_read_byte_data(new_client, |
326 | FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */ | 312 | FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */ |
327 | goto exit_free; | 313 | return -ENODEV; |
314 | } | ||
315 | |||
316 | strlcpy(info->type, "fscher", I2C_NAME_SIZE); | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | static int fscher_probe(struct i2c_client *new_client, | ||
322 | const struct i2c_device_id *id) | ||
323 | { | ||
324 | struct fscher_data *data; | ||
325 | int err; | ||
326 | |||
327 | data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL); | ||
328 | if (!data) { | ||
329 | err = -ENOMEM; | ||
330 | goto exit; | ||
328 | } | 331 | } |
329 | 332 | ||
330 | /* Fill in the remaining client fields and put it into the | 333 | i2c_set_clientdata(new_client, data); |
331 | * global list */ | ||
332 | strlcpy(new_client->name, "fscher", I2C_NAME_SIZE); | ||
333 | data->valid = 0; | 334 | data->valid = 0; |
334 | mutex_init(&data->update_lock); | 335 | mutex_init(&data->update_lock); |
335 | 336 | ||
336 | /* Tell the I2C layer a new client has arrived */ | ||
337 | if ((err = i2c_attach_client(new_client))) | ||
338 | goto exit_free; | ||
339 | |||
340 | fscher_init_client(new_client); | 337 | fscher_init_client(new_client); |
341 | 338 | ||
342 | /* Register sysfs hooks */ | 339 | /* Register sysfs hooks */ |
343 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group))) | 340 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group))) |
344 | goto exit_detach; | 341 | goto exit_free; |
345 | 342 | ||
346 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 343 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
347 | if (IS_ERR(data->hwmon_dev)) { | 344 | if (IS_ERR(data->hwmon_dev)) { |
@@ -353,25 +350,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
353 | 350 | ||
354 | exit_remove_files: | 351 | exit_remove_files: |
355 | sysfs_remove_group(&new_client->dev.kobj, &fscher_group); | 352 | sysfs_remove_group(&new_client->dev.kobj, &fscher_group); |
356 | exit_detach: | ||
357 | i2c_detach_client(new_client); | ||
358 | exit_free: | 353 | exit_free: |
359 | kfree(data); | 354 | kfree(data); |
360 | exit: | 355 | exit: |
361 | return err; | 356 | return err; |
362 | } | 357 | } |
363 | 358 | ||
364 | static int fscher_detach_client(struct i2c_client *client) | 359 | static int fscher_remove(struct i2c_client *client) |
365 | { | 360 | { |
366 | struct fscher_data *data = i2c_get_clientdata(client); | 361 | struct fscher_data *data = i2c_get_clientdata(client); |
367 | int err; | ||
368 | 362 | ||
369 | hwmon_device_unregister(data->hwmon_dev); | 363 | hwmon_device_unregister(data->hwmon_dev); |
370 | sysfs_remove_group(&client->dev.kobj, &fscher_group); | 364 | sysfs_remove_group(&client->dev.kobj, &fscher_group); |
371 | 365 | ||
372 | if ((err = i2c_detach_client(client))) | ||
373 | return err; | ||
374 | |||
375 | kfree(data); | 366 | kfree(data); |
376 | return 0; | 367 | return 0; |
377 | } | 368 | } |
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index bd89d270a5ed..967170368933 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c | |||
@@ -171,20 +171,37 @@ static const int FSCHMD_NO_TEMP_SENSORS[5] = { 3, 3, 4, 3, 5 }; | |||
171 | * Functions declarations | 171 | * Functions declarations |
172 | */ | 172 | */ |
173 | 173 | ||
174 | static int fschmd_attach_adapter(struct i2c_adapter *adapter); | 174 | static int fschmd_probe(struct i2c_client *client, |
175 | static int fschmd_detach_client(struct i2c_client *client); | 175 | const struct i2c_device_id *id); |
176 | static int fschmd_detect(struct i2c_client *client, int kind, | ||
177 | struct i2c_board_info *info); | ||
178 | static int fschmd_remove(struct i2c_client *client); | ||
176 | static struct fschmd_data *fschmd_update_device(struct device *dev); | 179 | static struct fschmd_data *fschmd_update_device(struct device *dev); |
177 | 180 | ||
178 | /* | 181 | /* |
179 | * Driver data (common to all clients) | 182 | * Driver data (common to all clients) |
180 | */ | 183 | */ |
181 | 184 | ||
185 | static const struct i2c_device_id fschmd_id[] = { | ||
186 | { "fscpos", fscpos }, | ||
187 | { "fscher", fscher }, | ||
188 | { "fscscy", fscscy }, | ||
189 | { "fschrc", fschrc }, | ||
190 | { "fschmd", fschmd }, | ||
191 | { } | ||
192 | }; | ||
193 | MODULE_DEVICE_TABLE(i2c, fschmd_id); | ||
194 | |||
182 | static struct i2c_driver fschmd_driver = { | 195 | static struct i2c_driver fschmd_driver = { |
196 | .class = I2C_CLASS_HWMON, | ||
183 | .driver = { | 197 | .driver = { |
184 | .name = FSCHMD_NAME, | 198 | .name = FSCHMD_NAME, |
185 | }, | 199 | }, |
186 | .attach_adapter = fschmd_attach_adapter, | 200 | .probe = fschmd_probe, |
187 | .detach_client = fschmd_detach_client, | 201 | .remove = fschmd_remove, |
202 | .id_table = fschmd_id, | ||
203 | .detect = fschmd_detect, | ||
204 | .address_data = &addr_data, | ||
188 | }; | 205 | }; |
189 | 206 | ||
190 | /* | 207 | /* |
@@ -192,7 +209,6 @@ static struct i2c_driver fschmd_driver = { | |||
192 | */ | 209 | */ |
193 | 210 | ||
194 | struct fschmd_data { | 211 | struct fschmd_data { |
195 | struct i2c_client client; | ||
196 | struct device *hwmon_dev; | 212 | struct device *hwmon_dev; |
197 | struct mutex update_lock; | 213 | struct mutex update_lock; |
198 | int kind; | 214 | int kind; |
@@ -269,7 +285,7 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
269 | v = SENSORS_LIMIT(v, -128, 127) + 128; | 285 | v = SENSORS_LIMIT(v, -128, 127) + 128; |
270 | 286 | ||
271 | mutex_lock(&data->update_lock); | 287 | mutex_lock(&data->update_lock); |
272 | i2c_smbus_write_byte_data(&data->client, | 288 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
273 | FSCHMD_REG_TEMP_LIMIT[data->kind][index], v); | 289 | FSCHMD_REG_TEMP_LIMIT[data->kind][index], v); |
274 | data->temp_max[index] = v; | 290 | data->temp_max[index] = v; |
275 | mutex_unlock(&data->update_lock); | 291 | mutex_unlock(&data->update_lock); |
@@ -346,14 +362,14 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute | |||
346 | 362 | ||
347 | mutex_lock(&data->update_lock); | 363 | mutex_lock(&data->update_lock); |
348 | 364 | ||
349 | reg = i2c_smbus_read_byte_data(&data->client, | 365 | reg = i2c_smbus_read_byte_data(to_i2c_client(dev), |
350 | FSCHMD_REG_FAN_RIPPLE[data->kind][index]); | 366 | FSCHMD_REG_FAN_RIPPLE[data->kind][index]); |
351 | 367 | ||
352 | /* bits 2..7 reserved => mask with 0x03 */ | 368 | /* bits 2..7 reserved => mask with 0x03 */ |
353 | reg &= ~0x03; | 369 | reg &= ~0x03; |
354 | reg |= v; | 370 | reg |= v; |
355 | 371 | ||
356 | i2c_smbus_write_byte_data(&data->client, | 372 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
357 | FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg); | 373 | FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg); |
358 | 374 | ||
359 | data->fan_ripple[index] = reg; | 375 | data->fan_ripple[index] = reg; |
@@ -416,7 +432,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev, | |||
416 | 432 | ||
417 | mutex_lock(&data->update_lock); | 433 | mutex_lock(&data->update_lock); |
418 | 434 | ||
419 | i2c_smbus_write_byte_data(&data->client, | 435 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
420 | FSCHMD_REG_FAN_MIN[data->kind][index], v); | 436 | FSCHMD_REG_FAN_MIN[data->kind][index], v); |
421 | data->fan_min[index] = v; | 437 | data->fan_min[index] = v; |
422 | 438 | ||
@@ -448,14 +464,14 @@ static ssize_t store_alert_led(struct device *dev, | |||
448 | 464 | ||
449 | mutex_lock(&data->update_lock); | 465 | mutex_lock(&data->update_lock); |
450 | 466 | ||
451 | reg = i2c_smbus_read_byte_data(&data->client, FSCHMD_REG_CONTROL); | 467 | reg = i2c_smbus_read_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL); |
452 | 468 | ||
453 | if (v) | 469 | if (v) |
454 | reg |= FSCHMD_CONTROL_ALERT_LED_MASK; | 470 | reg |= FSCHMD_CONTROL_ALERT_LED_MASK; |
455 | else | 471 | else |
456 | reg &= ~FSCHMD_CONTROL_ALERT_LED_MASK; | 472 | reg &= ~FSCHMD_CONTROL_ALERT_LED_MASK; |
457 | 473 | ||
458 | i2c_smbus_write_byte_data(&data->client, FSCHMD_REG_CONTROL, reg); | 474 | i2c_smbus_write_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL, reg); |
459 | 475 | ||
460 | data->global_control = reg; | 476 | data->global_control = reg; |
461 | 477 | ||
@@ -600,32 +616,15 @@ static void fschmd_dmi_decode(const struct dmi_header *header) | |||
600 | } | 616 | } |
601 | } | 617 | } |
602 | 618 | ||
603 | static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | 619 | static int fschmd_detect(struct i2c_client *client, int kind, |
620 | struct i2c_board_info *info) | ||
604 | { | 621 | { |
605 | struct i2c_client *client; | 622 | struct i2c_adapter *adapter = client->adapter; |
606 | struct fschmd_data *data; | ||
607 | u8 revision; | ||
608 | const char * const names[5] = { "Poseidon", "Hermes", "Scylla", | ||
609 | "Heracles", "Heimdall" }; | ||
610 | const char * const client_names[5] = { "fscpos", "fscher", "fscscy", | 623 | const char * const client_names[5] = { "fscpos", "fscher", "fscscy", |
611 | "fschrc", "fschmd" }; | 624 | "fschrc", "fschmd" }; |
612 | int i, err = 0; | ||
613 | 625 | ||
614 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 626 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
615 | return 0; | 627 | return -ENODEV; |
616 | |||
617 | /* OK. For now, we presume we have a valid client. We now create the | ||
618 | * client structure, even though we cannot fill it completely yet. | ||
619 | * But it allows us to access i2c_smbus_read_byte_data. */ | ||
620 | if (!(data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL))) | ||
621 | return -ENOMEM; | ||
622 | |||
623 | client = &data->client; | ||
624 | i2c_set_clientdata(client, data); | ||
625 | client->addr = address; | ||
626 | client->adapter = adapter; | ||
627 | client->driver = &fschmd_driver; | ||
628 | mutex_init(&data->update_lock); | ||
629 | 628 | ||
630 | /* Detect & Identify the chip */ | 629 | /* Detect & Identify the chip */ |
631 | if (kind <= 0) { | 630 | if (kind <= 0) { |
@@ -650,9 +649,31 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
650 | else if (!strcmp(id, "HMD")) | 649 | else if (!strcmp(id, "HMD")) |
651 | kind = fschmd; | 650 | kind = fschmd; |
652 | else | 651 | else |
653 | goto exit_free; | 652 | return -ENODEV; |
654 | } | 653 | } |
655 | 654 | ||
655 | strlcpy(info->type, client_names[kind - 1], I2C_NAME_SIZE); | ||
656 | |||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static int fschmd_probe(struct i2c_client *client, | ||
661 | const struct i2c_device_id *id) | ||
662 | { | ||
663 | struct fschmd_data *data; | ||
664 | u8 revision; | ||
665 | const char * const names[5] = { "Poseidon", "Hermes", "Scylla", | ||
666 | "Heracles", "Heimdall" }; | ||
667 | int i, err; | ||
668 | enum chips kind = id->driver_data; | ||
669 | |||
670 | data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL); | ||
671 | if (!data) | ||
672 | return -ENOMEM; | ||
673 | |||
674 | i2c_set_clientdata(client, data); | ||
675 | mutex_init(&data->update_lock); | ||
676 | |||
656 | if (kind == fscpos) { | 677 | if (kind == fscpos) { |
657 | /* The Poseidon has hardwired temp limits, fill these | 678 | /* The Poseidon has hardwired temp limits, fill these |
658 | in for the alarm resetting code */ | 679 | in for the alarm resetting code */ |
@@ -674,11 +695,6 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
674 | 695 | ||
675 | /* i2c kind goes from 1-5, we want from 0-4 to address arrays */ | 696 | /* i2c kind goes from 1-5, we want from 0-4 to address arrays */ |
676 | data->kind = kind - 1; | 697 | data->kind = kind - 1; |
677 | strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE); | ||
678 | |||
679 | /* Tell the I2C layer a new client has arrived */ | ||
680 | if ((err = i2c_attach_client(client))) | ||
681 | goto exit_free; | ||
682 | 698 | ||
683 | for (i = 0; i < ARRAY_SIZE(fschmd_attr); i++) { | 699 | for (i = 0; i < ARRAY_SIZE(fschmd_attr); i++) { |
684 | err = device_create_file(&client->dev, | 700 | err = device_create_file(&client->dev, |
@@ -726,25 +742,14 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
726 | return 0; | 742 | return 0; |
727 | 743 | ||
728 | exit_detach: | 744 | exit_detach: |
729 | fschmd_detach_client(client); /* will also free data for us */ | 745 | fschmd_remove(client); /* will also free data for us */ |
730 | return err; | ||
731 | |||
732 | exit_free: | ||
733 | kfree(data); | ||
734 | return err; | 746 | return err; |
735 | } | 747 | } |
736 | 748 | ||
737 | static int fschmd_attach_adapter(struct i2c_adapter *adapter) | 749 | static int fschmd_remove(struct i2c_client *client) |
738 | { | ||
739 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
740 | return 0; | ||
741 | return i2c_probe(adapter, &addr_data, fschmd_detect); | ||
742 | } | ||
743 | |||
744 | static int fschmd_detach_client(struct i2c_client *client) | ||
745 | { | 750 | { |
746 | struct fschmd_data *data = i2c_get_clientdata(client); | 751 | struct fschmd_data *data = i2c_get_clientdata(client); |
747 | int i, err; | 752 | int i; |
748 | 753 | ||
749 | /* Check if registered in case we're called from fschmd_detect | 754 | /* Check if registered in case we're called from fschmd_detect |
750 | to cleanup after an error */ | 755 | to cleanup after an error */ |
@@ -760,9 +765,6 @@ static int fschmd_detach_client(struct i2c_client *client) | |||
760 | device_remove_file(&client->dev, | 765 | device_remove_file(&client->dev, |
761 | &fschmd_fan_attr[i].dev_attr); | 766 | &fschmd_fan_attr[i].dev_attr); |
762 | 767 | ||
763 | if ((err = i2c_detach_client(client))) | ||
764 | return err; | ||
765 | |||
766 | kfree(data); | 768 | kfree(data); |
767 | return 0; | 769 | return 0; |
768 | } | 770 | } |
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c index 00f48484e54b..8a7bcf500b4e 100644 --- a/drivers/hwmon/fscpos.c +++ b/drivers/hwmon/fscpos.c | |||
@@ -87,9 +87,11 @@ static u8 FSCPOS_REG_TEMP_STATE[] = { 0x71, 0x81, 0x91 }; | |||
87 | /* | 87 | /* |
88 | * Functions declaration | 88 | * Functions declaration |
89 | */ | 89 | */ |
90 | static int fscpos_attach_adapter(struct i2c_adapter *adapter); | 90 | static int fscpos_probe(struct i2c_client *client, |
91 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); | 91 | const struct i2c_device_id *id); |
92 | static int fscpos_detach_client(struct i2c_client *client); | 92 | static int fscpos_detect(struct i2c_client *client, int kind, |
93 | struct i2c_board_info *info); | ||
94 | static int fscpos_remove(struct i2c_client *client); | ||
93 | 95 | ||
94 | static int fscpos_read_value(struct i2c_client *client, u8 reg); | 96 | static int fscpos_read_value(struct i2c_client *client, u8 reg); |
95 | static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); | 97 | static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); |
@@ -101,19 +103,27 @@ static void reset_fan_alarm(struct i2c_client *client, int nr); | |||
101 | /* | 103 | /* |
102 | * Driver data (common to all clients) | 104 | * Driver data (common to all clients) |
103 | */ | 105 | */ |
106 | static const struct i2c_device_id fscpos_id[] = { | ||
107 | { "fscpos", fscpos }, | ||
108 | { } | ||
109 | }; | ||
110 | |||
104 | static struct i2c_driver fscpos_driver = { | 111 | static struct i2c_driver fscpos_driver = { |
112 | .class = I2C_CLASS_HWMON, | ||
105 | .driver = { | 113 | .driver = { |
106 | .name = "fscpos", | 114 | .name = "fscpos", |
107 | }, | 115 | }, |
108 | .attach_adapter = fscpos_attach_adapter, | 116 | .probe = fscpos_probe, |
109 | .detach_client = fscpos_detach_client, | 117 | .remove = fscpos_remove, |
118 | .id_table = fscpos_id, | ||
119 | .detect = fscpos_detect, | ||
120 | .address_data = &addr_data, | ||
110 | }; | 121 | }; |
111 | 122 | ||
112 | /* | 123 | /* |
113 | * Client data (each client gets its own) | 124 | * Client data (each client gets its own) |
114 | */ | 125 | */ |
115 | struct fscpos_data { | 126 | struct fscpos_data { |
116 | struct i2c_client client; | ||
117 | struct device *hwmon_dev; | 127 | struct device *hwmon_dev; |
118 | struct mutex update_lock; | 128 | struct mutex update_lock; |
119 | char valid; /* 0 until following fields are valid */ | 129 | char valid; /* 0 until following fields are valid */ |
@@ -470,39 +480,14 @@ static const struct attribute_group fscpos_group = { | |||
470 | .attrs = fscpos_attributes, | 480 | .attrs = fscpos_attributes, |
471 | }; | 481 | }; |
472 | 482 | ||
473 | static int fscpos_attach_adapter(struct i2c_adapter *adapter) | 483 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
474 | { | 484 | static int fscpos_detect(struct i2c_client *new_client, int kind, |
475 | if (!(adapter->class & I2C_CLASS_HWMON)) | 485 | struct i2c_board_info *info) |
476 | return 0; | ||
477 | return i2c_probe(adapter, &addr_data, fscpos_detect); | ||
478 | } | ||
479 | |||
480 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | ||
481 | { | 486 | { |
482 | struct i2c_client *new_client; | 487 | struct i2c_adapter *adapter = new_client->adapter; |
483 | struct fscpos_data *data; | ||
484 | int err = 0; | ||
485 | 488 | ||
486 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 489 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
487 | goto exit; | 490 | return -ENODEV; |
488 | |||
489 | /* | ||
490 | * OK. For now, we presume we have a valid client. We now create the | ||
491 | * client structure, even though we cannot fill it completely yet. | ||
492 | * But it allows us to access fscpos_{read,write}_value. | ||
493 | */ | ||
494 | |||
495 | if (!(data = kzalloc(sizeof(struct fscpos_data), GFP_KERNEL))) { | ||
496 | err = -ENOMEM; | ||
497 | goto exit; | ||
498 | } | ||
499 | |||
500 | new_client = &data->client; | ||
501 | i2c_set_clientdata(new_client, data); | ||
502 | new_client->addr = address; | ||
503 | new_client->adapter = adapter; | ||
504 | new_client->driver = &fscpos_driver; | ||
505 | new_client->flags = 0; | ||
506 | 491 | ||
507 | /* Do the remaining detection unless force or force_fscpos parameter */ | 492 | /* Do the remaining detection unless force or force_fscpos parameter */ |
508 | if (kind < 0) { | 493 | if (kind < 0) { |
@@ -512,22 +497,30 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
512 | != 0x45) /* 'E' */ | 497 | != 0x45) /* 'E' */ |
513 | || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_2) | 498 | || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_2) |
514 | != 0x47))/* 'G' */ | 499 | != 0x47))/* 'G' */ |
515 | { | 500 | return -ENODEV; |
516 | dev_dbg(&new_client->dev, "fscpos detection failed\n"); | ||
517 | goto exit_free; | ||
518 | } | ||
519 | } | 501 | } |
520 | 502 | ||
521 | /* Fill in the remaining client fields and put it in the global list */ | 503 | strlcpy(info->type, "fscpos", I2C_NAME_SIZE); |
522 | strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); | ||
523 | 504 | ||
505 | return 0; | ||
506 | } | ||
507 | |||
508 | static int fscpos_probe(struct i2c_client *new_client, | ||
509 | const struct i2c_device_id *id) | ||
510 | { | ||
511 | struct fscpos_data *data; | ||
512 | int err; | ||
513 | |||
514 | data = kzalloc(sizeof(struct fscpos_data), GFP_KERNEL); | ||
515 | if (!data) { | ||
516 | err = -ENOMEM; | ||
517 | goto exit; | ||
518 | } | ||
519 | |||
520 | i2c_set_clientdata(new_client, data); | ||
524 | data->valid = 0; | 521 | data->valid = 0; |
525 | mutex_init(&data->update_lock); | 522 | mutex_init(&data->update_lock); |
526 | 523 | ||
527 | /* Tell the I2C layer a new client has arrived */ | ||
528 | if ((err = i2c_attach_client(new_client))) | ||
529 | goto exit_free; | ||
530 | |||
531 | /* Inizialize the fscpos chip */ | 524 | /* Inizialize the fscpos chip */ |
532 | fscpos_init_client(new_client); | 525 | fscpos_init_client(new_client); |
533 | 526 | ||
@@ -536,7 +529,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
536 | 529 | ||
537 | /* Register sysfs hooks */ | 530 | /* Register sysfs hooks */ |
538 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group))) | 531 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group))) |
539 | goto exit_detach; | 532 | goto exit_free; |
540 | 533 | ||
541 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 534 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
542 | if (IS_ERR(data->hwmon_dev)) { | 535 | if (IS_ERR(data->hwmon_dev)) { |
@@ -548,24 +541,19 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
548 | 541 | ||
549 | exit_remove_files: | 542 | exit_remove_files: |
550 | sysfs_remove_group(&new_client->dev.kobj, &fscpos_group); | 543 | sysfs_remove_group(&new_client->dev.kobj, &fscpos_group); |
551 | exit_detach: | ||
552 | i2c_detach_client(new_client); | ||
553 | exit_free: | 544 | exit_free: |
554 | kfree(data); | 545 | kfree(data); |
555 | exit: | 546 | exit: |
556 | return err; | 547 | return err; |
557 | } | 548 | } |
558 | 549 | ||
559 | static int fscpos_detach_client(struct i2c_client *client) | 550 | static int fscpos_remove(struct i2c_client *client) |
560 | { | 551 | { |
561 | struct fscpos_data *data = i2c_get_clientdata(client); | 552 | struct fscpos_data *data = i2c_get_clientdata(client); |
562 | int err; | ||
563 | 553 | ||
564 | hwmon_device_unregister(data->hwmon_dev); | 554 | hwmon_device_unregister(data->hwmon_dev); |
565 | sysfs_remove_group(&client->dev.kobj, &fscpos_group); | 555 | sysfs_remove_group(&client->dev.kobj, &fscpos_group); |
566 | 556 | ||
567 | if ((err = i2c_detach_client(client))) | ||
568 | return err; | ||
569 | kfree(data); | 557 | kfree(data); |
570 | return 0; | 558 | return 0; |
571 | } | 559 | } |
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 33e9e8a8d1ce..7820df45d77a 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -114,7 +114,6 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
114 | 114 | ||
115 | /* Each client has this additional data */ | 115 | /* Each client has this additional data */ |
116 | struct gl518_data { | 116 | struct gl518_data { |
117 | struct i2c_client client; | ||
118 | struct device *hwmon_dev; | 117 | struct device *hwmon_dev; |
119 | enum chips type; | 118 | enum chips type; |
120 | 119 | ||
@@ -138,21 +137,33 @@ struct gl518_data { | |||
138 | u8 beep_enable; /* Boolean */ | 137 | u8 beep_enable; /* Boolean */ |
139 | }; | 138 | }; |
140 | 139 | ||
141 | static int gl518_attach_adapter(struct i2c_adapter *adapter); | 140 | static int gl518_probe(struct i2c_client *client, |
142 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind); | 141 | const struct i2c_device_id *id); |
142 | static int gl518_detect(struct i2c_client *client, int kind, | ||
143 | struct i2c_board_info *info); | ||
143 | static void gl518_init_client(struct i2c_client *client); | 144 | static void gl518_init_client(struct i2c_client *client); |
144 | static int gl518_detach_client(struct i2c_client *client); | 145 | static int gl518_remove(struct i2c_client *client); |
145 | static int gl518_read_value(struct i2c_client *client, u8 reg); | 146 | static int gl518_read_value(struct i2c_client *client, u8 reg); |
146 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); | 147 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); |
147 | static struct gl518_data *gl518_update_device(struct device *dev); | 148 | static struct gl518_data *gl518_update_device(struct device *dev); |
148 | 149 | ||
150 | static const struct i2c_device_id gl518_id[] = { | ||
151 | { "gl518sm", 0 }, | ||
152 | { } | ||
153 | }; | ||
154 | MODULE_DEVICE_TABLE(i2c, gl518_id); | ||
155 | |||
149 | /* This is the driver that will be inserted */ | 156 | /* This is the driver that will be inserted */ |
150 | static struct i2c_driver gl518_driver = { | 157 | static struct i2c_driver gl518_driver = { |
158 | .class = I2C_CLASS_HWMON, | ||
151 | .driver = { | 159 | .driver = { |
152 | .name = "gl518sm", | 160 | .name = "gl518sm", |
153 | }, | 161 | }, |
154 | .attach_adapter = gl518_attach_adapter, | 162 | .probe = gl518_probe, |
155 | .detach_client = gl518_detach_client, | 163 | .remove = gl518_remove, |
164 | .id_table = gl518_id, | ||
165 | .detect = gl518_detect, | ||
166 | .address_data = &addr_data, | ||
156 | }; | 167 | }; |
157 | 168 | ||
158 | /* | 169 | /* |
@@ -472,46 +483,23 @@ static const struct attribute_group gl518_group_r80 = { | |||
472 | * Real code | 483 | * Real code |
473 | */ | 484 | */ |
474 | 485 | ||
475 | static int gl518_attach_adapter(struct i2c_adapter *adapter) | 486 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
476 | { | 487 | static int gl518_detect(struct i2c_client *client, int kind, |
477 | if (!(adapter->class & I2C_CLASS_HWMON)) | 488 | struct i2c_board_info *info) |
478 | return 0; | ||
479 | return i2c_probe(adapter, &addr_data, gl518_detect); | ||
480 | } | ||
481 | |||
482 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | ||
483 | { | 489 | { |
490 | struct i2c_adapter *adapter = client->adapter; | ||
484 | int i; | 491 | int i; |
485 | struct i2c_client *client; | ||
486 | struct gl518_data *data; | ||
487 | int err = 0; | ||
488 | 492 | ||
489 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
490 | I2C_FUNC_SMBUS_WORD_DATA)) | 494 | I2C_FUNC_SMBUS_WORD_DATA)) |
491 | goto exit; | 495 | return -ENODEV; |
492 | |||
493 | /* OK. For now, we presume we have a valid client. We now create the | ||
494 | client structure, even though we cannot fill it completely yet. | ||
495 | But it allows us to access gl518_{read,write}_value. */ | ||
496 | |||
497 | if (!(data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL))) { | ||
498 | err = -ENOMEM; | ||
499 | goto exit; | ||
500 | } | ||
501 | |||
502 | client = &data->client; | ||
503 | i2c_set_clientdata(client, data); | ||
504 | |||
505 | client->addr = address; | ||
506 | client->adapter = adapter; | ||
507 | client->driver = &gl518_driver; | ||
508 | 496 | ||
509 | /* Now, we do the remaining detection. */ | 497 | /* Now, we do the remaining detection. */ |
510 | 498 | ||
511 | if (kind < 0) { | 499 | if (kind < 0) { |
512 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) | 500 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) |
513 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) | 501 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) |
514 | goto exit_free; | 502 | return -ENODEV; |
515 | } | 503 | } |
516 | 504 | ||
517 | /* Determine the chip type. */ | 505 | /* Determine the chip type. */ |
@@ -526,19 +514,32 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
526 | dev_info(&adapter->dev, | 514 | dev_info(&adapter->dev, |
527 | "Ignoring 'force' parameter for unknown " | 515 | "Ignoring 'force' parameter for unknown " |
528 | "chip at adapter %d, address 0x%02x\n", | 516 | "chip at adapter %d, address 0x%02x\n", |
529 | i2c_adapter_id(adapter), address); | 517 | i2c_adapter_id(adapter), client->addr); |
530 | goto exit_free; | 518 | return -ENODEV; |
531 | } | 519 | } |
532 | } | 520 | } |
533 | 521 | ||
534 | /* Fill in the remaining client fields */ | 522 | strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); |
535 | strlcpy(client->name, "gl518sm", I2C_NAME_SIZE); | ||
536 | data->type = kind; | ||
537 | mutex_init(&data->update_lock); | ||
538 | 523 | ||
539 | /* Tell the I2C layer a new client has arrived */ | 524 | return 0; |
540 | if ((err = i2c_attach_client(client))) | 525 | } |
541 | goto exit_free; | 526 | |
527 | static int gl518_probe(struct i2c_client *client, | ||
528 | const struct i2c_device_id *id) | ||
529 | { | ||
530 | struct gl518_data *data; | ||
531 | int err, revision; | ||
532 | |||
533 | data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL); | ||
534 | if (!data) { | ||
535 | err = -ENOMEM; | ||
536 | goto exit; | ||
537 | } | ||
538 | |||
539 | i2c_set_clientdata(client, data); | ||
540 | revision = gl518_read_value(client, GL518_REG_REVISION); | ||
541 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; | ||
542 | mutex_init(&data->update_lock); | ||
542 | 543 | ||
543 | /* Initialize the GL518SM chip */ | 544 | /* Initialize the GL518SM chip */ |
544 | data->alarm_mask = 0xff; | 545 | data->alarm_mask = 0xff; |
@@ -546,7 +547,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
546 | 547 | ||
547 | /* Register sysfs hooks */ | 548 | /* Register sysfs hooks */ |
548 | if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) | 549 | if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) |
549 | goto exit_detach; | 550 | goto exit_free; |
550 | if (data->type == gl518sm_r80) | 551 | if (data->type == gl518sm_r80) |
551 | if ((err = sysfs_create_group(&client->dev.kobj, | 552 | if ((err = sysfs_create_group(&client->dev.kobj, |
552 | &gl518_group_r80))) | 553 | &gl518_group_r80))) |
@@ -564,8 +565,6 @@ exit_remove_files: | |||
564 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | 565 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
565 | if (data->type == gl518sm_r80) | 566 | if (data->type == gl518sm_r80) |
566 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | 567 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); |
567 | exit_detach: | ||
568 | i2c_detach_client(client); | ||
569 | exit_free: | 568 | exit_free: |
570 | kfree(data); | 569 | kfree(data); |
571 | exit: | 570 | exit: |
@@ -591,19 +590,15 @@ static void gl518_init_client(struct i2c_client *client) | |||
591 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); | 590 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); |
592 | } | 591 | } |
593 | 592 | ||
594 | static int gl518_detach_client(struct i2c_client *client) | 593 | static int gl518_remove(struct i2c_client *client) |
595 | { | 594 | { |
596 | struct gl518_data *data = i2c_get_clientdata(client); | 595 | struct gl518_data *data = i2c_get_clientdata(client); |
597 | int err; | ||
598 | 596 | ||
599 | hwmon_device_unregister(data->hwmon_dev); | 597 | hwmon_device_unregister(data->hwmon_dev); |
600 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | 598 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
601 | if (data->type == gl518sm_r80) | 599 | if (data->type == gl518sm_r80) |
602 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | 600 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); |
603 | 601 | ||
604 | if ((err = i2c_detach_client(client))) | ||
605 | return err; | ||
606 | |||
607 | kfree(data); | 602 | kfree(data); |
608 | return 0; | 603 | return 0; |
609 | } | 604 | } |
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 8984ef141627..19616f2242b0 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -79,26 +79,37 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 }; | |||
79 | * Function declarations | 79 | * Function declarations |
80 | */ | 80 | */ |
81 | 81 | ||
82 | static int gl520_attach_adapter(struct i2c_adapter *adapter); | 82 | static int gl520_probe(struct i2c_client *client, |
83 | static int gl520_detect(struct i2c_adapter *adapter, int address, int kind); | 83 | const struct i2c_device_id *id); |
84 | static int gl520_detect(struct i2c_client *client, int kind, | ||
85 | struct i2c_board_info *info); | ||
84 | static void gl520_init_client(struct i2c_client *client); | 86 | static void gl520_init_client(struct i2c_client *client); |
85 | static int gl520_detach_client(struct i2c_client *client); | 87 | static int gl520_remove(struct i2c_client *client); |
86 | static int gl520_read_value(struct i2c_client *client, u8 reg); | 88 | static int gl520_read_value(struct i2c_client *client, u8 reg); |
87 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); | 89 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); |
88 | static struct gl520_data *gl520_update_device(struct device *dev); | 90 | static struct gl520_data *gl520_update_device(struct device *dev); |
89 | 91 | ||
90 | /* Driver data */ | 92 | /* Driver data */ |
93 | static const struct i2c_device_id gl520_id[] = { | ||
94 | { "gl520sm", gl520sm }, | ||
95 | { } | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(i2c, gl520_id); | ||
98 | |||
91 | static struct i2c_driver gl520_driver = { | 99 | static struct i2c_driver gl520_driver = { |
100 | .class = I2C_CLASS_HWMON, | ||
92 | .driver = { | 101 | .driver = { |
93 | .name = "gl520sm", | 102 | .name = "gl520sm", |
94 | }, | 103 | }, |
95 | .attach_adapter = gl520_attach_adapter, | 104 | .probe = gl520_probe, |
96 | .detach_client = gl520_detach_client, | 105 | .remove = gl520_remove, |
106 | .id_table = gl520_id, | ||
107 | .detect = gl520_detect, | ||
108 | .address_data = &addr_data, | ||
97 | }; | 109 | }; |
98 | 110 | ||
99 | /* Client data */ | 111 | /* Client data */ |
100 | struct gl520_data { | 112 | struct gl520_data { |
101 | struct i2c_client client; | ||
102 | struct device *hwmon_dev; | 113 | struct device *hwmon_dev; |
103 | struct mutex update_lock; | 114 | struct mutex update_lock; |
104 | char valid; /* zero until the following fields are valid */ | 115 | char valid; /* zero until the following fields are valid */ |
@@ -669,37 +680,15 @@ static const struct attribute_group gl520_group_opt = { | |||
669 | * Real code | 680 | * Real code |
670 | */ | 681 | */ |
671 | 682 | ||
672 | static int gl520_attach_adapter(struct i2c_adapter *adapter) | 683 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
673 | { | 684 | static int gl520_detect(struct i2c_client *client, int kind, |
674 | if (!(adapter->class & I2C_CLASS_HWMON)) | 685 | struct i2c_board_info *info) |
675 | return 0; | ||
676 | return i2c_probe(adapter, &addr_data, gl520_detect); | ||
677 | } | ||
678 | |||
679 | static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | ||
680 | { | 686 | { |
681 | struct i2c_client *client; | 687 | struct i2c_adapter *adapter = client->adapter; |
682 | struct gl520_data *data; | ||
683 | int err = 0; | ||
684 | 688 | ||
685 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 689 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
686 | I2C_FUNC_SMBUS_WORD_DATA)) | 690 | I2C_FUNC_SMBUS_WORD_DATA)) |
687 | goto exit; | 691 | return -ENODEV; |
688 | |||
689 | /* OK. For now, we presume we have a valid client. We now create the | ||
690 | client structure, even though we cannot fill it completely yet. | ||
691 | But it allows us to access gl520_{read,write}_value. */ | ||
692 | |||
693 | if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) { | ||
694 | err = -ENOMEM; | ||
695 | goto exit; | ||
696 | } | ||
697 | |||
698 | client = &data->client; | ||
699 | i2c_set_clientdata(client, data); | ||
700 | client->addr = address; | ||
701 | client->adapter = adapter; | ||
702 | client->driver = &gl520_driver; | ||
703 | 692 | ||
704 | /* Determine the chip type. */ | 693 | /* Determine the chip type. */ |
705 | if (kind < 0) { | 694 | if (kind < 0) { |
@@ -707,24 +696,36 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
707 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || | 696 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || |
708 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { | 697 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { |
709 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); | 698 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); |
710 | goto exit_free; | 699 | return -ENODEV; |
711 | } | 700 | } |
712 | } | 701 | } |
713 | 702 | ||
714 | /* Fill in the remaining client fields */ | 703 | strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); |
715 | strlcpy(client->name, "gl520sm", I2C_NAME_SIZE); | ||
716 | mutex_init(&data->update_lock); | ||
717 | 704 | ||
718 | /* Tell the I2C layer a new client has arrived */ | 705 | return 0; |
719 | if ((err = i2c_attach_client(client))) | 706 | } |
720 | goto exit_free; | 707 | |
708 | static int gl520_probe(struct i2c_client *client, | ||
709 | const struct i2c_device_id *id) | ||
710 | { | ||
711 | struct gl520_data *data; | ||
712 | int err; | ||
713 | |||
714 | data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL); | ||
715 | if (!data) { | ||
716 | err = -ENOMEM; | ||
717 | goto exit; | ||
718 | } | ||
719 | |||
720 | i2c_set_clientdata(client, data); | ||
721 | mutex_init(&data->update_lock); | ||
721 | 722 | ||
722 | /* Initialize the GL520SM chip */ | 723 | /* Initialize the GL520SM chip */ |
723 | gl520_init_client(client); | 724 | gl520_init_client(client); |
724 | 725 | ||
725 | /* Register sysfs hooks */ | 726 | /* Register sysfs hooks */ |
726 | if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group))) | 727 | if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group))) |
727 | goto exit_detach; | 728 | goto exit_free; |
728 | 729 | ||
729 | if (data->two_temps) { | 730 | if (data->two_temps) { |
730 | if ((err = device_create_file(&client->dev, | 731 | if ((err = device_create_file(&client->dev, |
@@ -764,8 +765,6 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
764 | exit_remove_files: | 765 | exit_remove_files: |
765 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 766 | sysfs_remove_group(&client->dev.kobj, &gl520_group); |
766 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); | 767 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); |
767 | exit_detach: | ||
768 | i2c_detach_client(client); | ||
769 | exit_free: | 768 | exit_free: |
770 | kfree(data); | 769 | kfree(data); |
771 | exit: | 770 | exit: |
@@ -811,18 +810,14 @@ static void gl520_init_client(struct i2c_client *client) | |||
811 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | 810 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); |
812 | } | 811 | } |
813 | 812 | ||
814 | static int gl520_detach_client(struct i2c_client *client) | 813 | static int gl520_remove(struct i2c_client *client) |
815 | { | 814 | { |
816 | struct gl520_data *data = i2c_get_clientdata(client); | 815 | struct gl520_data *data = i2c_get_clientdata(client); |
817 | int err; | ||
818 | 816 | ||
819 | hwmon_device_unregister(data->hwmon_dev); | 817 | hwmon_device_unregister(data->hwmon_dev); |
820 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 818 | sysfs_remove_group(&client->dev.kobj, &gl520_group); |
821 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); | 819 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); |
822 | 820 | ||
823 | if ((err = i2c_detach_client(client))) | ||
824 | return err; | ||
825 | |||
826 | kfree(data); | 821 | kfree(data); |
827 | return 0; | 822 | return 0; |
828 | } | 823 | } |
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c index ea4fc6577593..a4d92d246d52 100644 --- a/drivers/hwmon/hdaps.c +++ b/drivers/hwmon/hdaps.c | |||
@@ -515,16 +515,24 @@ static struct dmi_system_id __initdata hdaps_whitelist[] = { | |||
515 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"), | 515 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"), |
516 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"), | 516 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"), |
517 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"), | 517 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"), |
518 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61i"), | ||
519 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61"), | ||
518 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"), | 520 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"), |
519 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"), | 521 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"), |
520 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"), | 522 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"), |
521 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), | 523 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), |
522 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), | 524 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), |
523 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"), | 525 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"), |
526 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p"), | ||
527 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61"), | ||
524 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"), | 528 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"), |
525 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"), | 529 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"), |
526 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"), | 530 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"), |
531 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61s"), | ||
532 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61"), | ||
527 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"), | 533 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"), |
534 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61m"), | ||
535 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61p"), | ||
528 | { .ident = NULL } | 536 | { .ident = NULL } |
529 | }; | 537 | }; |
530 | 538 | ||
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c index 6ac5c6f53585..f9e2ed621f7b 100644 --- a/drivers/hwmon/i5k_amb.c +++ b/drivers/hwmon/i5k_amb.c | |||
@@ -111,6 +111,7 @@ struct i5k_amb_data { | |||
111 | void __iomem *amb_mmio; | 111 | void __iomem *amb_mmio; |
112 | struct i5k_device_attribute *attrs; | 112 | struct i5k_device_attribute *attrs; |
113 | unsigned int num_attrs; | 113 | unsigned int num_attrs; |
114 | unsigned long chipset_id; | ||
114 | }; | 115 | }; |
115 | 116 | ||
116 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | 117 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, |
@@ -382,7 +383,8 @@ err: | |||
382 | return res; | 383 | return res; |
383 | } | 384 | } |
384 | 385 | ||
385 | static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | 386 | static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data, |
387 | unsigned long devid) | ||
386 | { | 388 | { |
387 | struct pci_dev *pcidev; | 389 | struct pci_dev *pcidev; |
388 | u32 val32; | 390 | u32 val32; |
@@ -390,7 +392,7 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | |||
390 | 392 | ||
391 | /* Find AMB register memory space */ | 393 | /* Find AMB register memory space */ |
392 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 394 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
393 | PCI_DEVICE_ID_INTEL_5000_ERR, | 395 | devid, |
394 | NULL); | 396 | NULL); |
395 | if (!pcidev) | 397 | if (!pcidev) |
396 | return -ENODEV; | 398 | return -ENODEV; |
@@ -409,6 +411,8 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | |||
409 | goto out; | 411 | goto out; |
410 | } | 412 | } |
411 | 413 | ||
414 | data->chipset_id = devid; | ||
415 | |||
412 | res = 0; | 416 | res = 0; |
413 | out: | 417 | out: |
414 | pci_dev_put(pcidev); | 418 | pci_dev_put(pcidev); |
@@ -441,10 +445,30 @@ out: | |||
441 | return res; | 445 | return res; |
442 | } | 446 | } |
443 | 447 | ||
448 | static unsigned long i5k_channel_pci_id(struct i5k_amb_data *data, | ||
449 | unsigned long channel) | ||
450 | { | ||
451 | switch (data->chipset_id) { | ||
452 | case PCI_DEVICE_ID_INTEL_5000_ERR: | ||
453 | return PCI_DEVICE_ID_INTEL_5000_FBD0 + channel; | ||
454 | case PCI_DEVICE_ID_INTEL_5400_ERR: | ||
455 | return PCI_DEVICE_ID_INTEL_5400_FBD0 + channel; | ||
456 | default: | ||
457 | BUG(); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | static unsigned long chipset_ids[] = { | ||
462 | PCI_DEVICE_ID_INTEL_5000_ERR, | ||
463 | PCI_DEVICE_ID_INTEL_5400_ERR, | ||
464 | 0 | ||
465 | }; | ||
466 | |||
444 | static int __devinit i5k_amb_probe(struct platform_device *pdev) | 467 | static int __devinit i5k_amb_probe(struct platform_device *pdev) |
445 | { | 468 | { |
446 | struct i5k_amb_data *data; | 469 | struct i5k_amb_data *data; |
447 | struct resource *reso; | 470 | struct resource *reso; |
471 | int i; | ||
448 | int res = -ENODEV; | 472 | int res = -ENODEV; |
449 | 473 | ||
450 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 474 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
@@ -452,19 +476,24 @@ static int __devinit i5k_amb_probe(struct platform_device *pdev) | |||
452 | return -ENOMEM; | 476 | return -ENOMEM; |
453 | 477 | ||
454 | /* Figure out where the AMB registers live */ | 478 | /* Figure out where the AMB registers live */ |
455 | res = i5k_find_amb_registers(data); | 479 | i = 0; |
480 | do { | ||
481 | res = i5k_find_amb_registers(data, chipset_ids[i]); | ||
482 | i++; | ||
483 | } while (res && chipset_ids[i]); | ||
484 | |||
456 | if (res) | 485 | if (res) |
457 | goto err; | 486 | goto err; |
458 | 487 | ||
459 | /* Copy the DIMM presence map for the first two channels */ | 488 | /* Copy the DIMM presence map for the first two channels */ |
460 | res = i5k_channel_probe(&data->amb_present[0], | 489 | res = i5k_channel_probe(&data->amb_present[0], |
461 | PCI_DEVICE_ID_INTEL_5000_FBD0); | 490 | i5k_channel_pci_id(data, 0)); |
462 | if (res) | 491 | if (res) |
463 | goto err; | 492 | goto err; |
464 | 493 | ||
465 | /* Copy the DIMM presence map for the optional second two channels */ | 494 | /* Copy the DIMM presence map for the optional second two channels */ |
466 | i5k_channel_probe(&data->amb_present[2], | 495 | i5k_channel_probe(&data->amb_present[2], |
467 | PCI_DEVICE_ID_INTEL_5000_FBD1); | 496 | i5k_channel_pci_id(data, 1)); |
468 | 497 | ||
469 | /* Set up resource regions */ | 498 | /* Set up resource regions */ |
470 | reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME); | 499 | reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME); |
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c new file mode 100644 index 000000000000..c9416e657487 --- /dev/null +++ b/drivers/hwmon/ibmaem.c | |||
@@ -0,0 +1,1111 @@ | |||
1 | /* | ||
2 | * A hwmon driver for the IBM Active Energy Manager temperature/power sensors | ||
3 | * and capping functionality. | ||
4 | * Copyright (C) 2008 IBM | ||
5 | * | ||
6 | * Author: Darrick J. Wong <djwong@us.ibm.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #include <linux/ipmi.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/jiffies.h> | ||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/kdev_t.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/idr.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/platform_device.h> | ||
34 | #include <linux/math64.h> | ||
35 | #include <linux/time.h> | ||
36 | |||
37 | #define REFRESH_INTERVAL (HZ) | ||
38 | #define IPMI_TIMEOUT (30 * HZ) | ||
39 | #define DRVNAME "aem" | ||
40 | |||
41 | #define AEM_NETFN 0x2E | ||
42 | |||
43 | #define AEM_FIND_FW_CMD 0x80 | ||
44 | #define AEM_ELEMENT_CMD 0x81 | ||
45 | #define AEM_FW_INSTANCE_CMD 0x82 | ||
46 | |||
47 | #define AEM_READ_ELEMENT_CFG 0x80 | ||
48 | #define AEM_READ_BUFFER 0x81 | ||
49 | #define AEM_READ_REGISTER 0x82 | ||
50 | #define AEM_WRITE_REGISTER 0x83 | ||
51 | #define AEM_SET_REG_MASK 0x84 | ||
52 | #define AEM_CLEAR_REG_MASK 0x85 | ||
53 | #define AEM_READ_ELEMENT_CFG2 0x86 | ||
54 | |||
55 | #define AEM_CONTROL_ELEMENT 0 | ||
56 | #define AEM_ENERGY_ELEMENT 1 | ||
57 | #define AEM_CLOCK_ELEMENT 4 | ||
58 | #define AEM_POWER_CAP_ELEMENT 7 | ||
59 | #define AEM_EXHAUST_ELEMENT 9 | ||
60 | #define AEM_POWER_ELEMENT 10 | ||
61 | |||
62 | #define AEM_MODULE_TYPE_ID 0x0001 | ||
63 | |||
64 | #define AEM2_NUM_ENERGY_REGS 2 | ||
65 | #define AEM2_NUM_PCAP_REGS 6 | ||
66 | #define AEM2_NUM_TEMP_REGS 2 | ||
67 | #define AEM2_NUM_SENSORS 14 | ||
68 | |||
69 | #define AEM1_NUM_ENERGY_REGS 1 | ||
70 | #define AEM1_NUM_SENSORS 3 | ||
71 | |||
72 | /* AEM 2.x has more energy registers */ | ||
73 | #define AEM_NUM_ENERGY_REGS AEM2_NUM_ENERGY_REGS | ||
74 | /* AEM 2.x needs more sensor files */ | ||
75 | #define AEM_NUM_SENSORS AEM2_NUM_SENSORS | ||
76 | |||
77 | #define POWER_CAP 0 | ||
78 | #define POWER_CAP_MAX_HOTPLUG 1 | ||
79 | #define POWER_CAP_MAX 2 | ||
80 | #define POWER_CAP_MIN_WARNING 3 | ||
81 | #define POWER_CAP_MIN 4 | ||
82 | #define POWER_AUX 5 | ||
83 | |||
84 | #define AEM_DEFAULT_POWER_INTERVAL 1000 | ||
85 | #define AEM_MIN_POWER_INTERVAL 200 | ||
86 | #define UJ_PER_MJ 1000L | ||
87 | |||
88 | static DEFINE_IDR(aem_idr); | ||
89 | static DEFINE_SPINLOCK(aem_idr_lock); | ||
90 | |||
91 | static struct device_driver aem_driver = { | ||
92 | .name = DRVNAME, | ||
93 | .bus = &platform_bus_type, | ||
94 | }; | ||
95 | |||
96 | struct aem_ipmi_data { | ||
97 | struct completion read_complete; | ||
98 | struct ipmi_addr address; | ||
99 | ipmi_user_t user; | ||
100 | int interface; | ||
101 | |||
102 | struct kernel_ipmi_msg tx_message; | ||
103 | long tx_msgid; | ||
104 | |||
105 | void *rx_msg_data; | ||
106 | unsigned short rx_msg_len; | ||
107 | unsigned char rx_result; | ||
108 | int rx_recv_type; | ||
109 | |||
110 | struct device *bmc_device; | ||
111 | }; | ||
112 | |||
113 | struct aem_ro_sensor_template { | ||
114 | char *label; | ||
115 | ssize_t (*show)(struct device *dev, | ||
116 | struct device_attribute *devattr, | ||
117 | char *buf); | ||
118 | int index; | ||
119 | }; | ||
120 | |||
121 | struct aem_rw_sensor_template { | ||
122 | char *label; | ||
123 | ssize_t (*show)(struct device *dev, | ||
124 | struct device_attribute *devattr, | ||
125 | char *buf); | ||
126 | ssize_t (*set)(struct device *dev, | ||
127 | struct device_attribute *devattr, | ||
128 | const char *buf, size_t count); | ||
129 | int index; | ||
130 | }; | ||
131 | |||
132 | struct aem_data { | ||
133 | struct list_head list; | ||
134 | |||
135 | struct device *hwmon_dev; | ||
136 | struct platform_device *pdev; | ||
137 | struct mutex lock; | ||
138 | char valid; | ||
139 | unsigned long last_updated; /* In jiffies */ | ||
140 | u8 ver_major; | ||
141 | u8 ver_minor; | ||
142 | u8 module_handle; | ||
143 | int id; | ||
144 | struct aem_ipmi_data ipmi; | ||
145 | |||
146 | /* Function to update sensors */ | ||
147 | void (*update)(struct aem_data *data); | ||
148 | |||
149 | /* | ||
150 | * AEM 1.x sensors: | ||
151 | * Available sensors: | ||
152 | * Energy meter | ||
153 | * Power meter | ||
154 | * | ||
155 | * AEM 2.x sensors: | ||
156 | * Two energy meters | ||
157 | * Two power meters | ||
158 | * Two temperature sensors | ||
159 | * Six power cap registers | ||
160 | */ | ||
161 | |||
162 | /* sysfs attrs */ | ||
163 | struct sensor_device_attribute sensors[AEM_NUM_SENSORS]; | ||
164 | |||
165 | /* energy use in mJ */ | ||
166 | u64 energy[AEM_NUM_ENERGY_REGS]; | ||
167 | |||
168 | /* power sampling interval in ms */ | ||
169 | unsigned long power_period[AEM_NUM_ENERGY_REGS]; | ||
170 | |||
171 | /* Everything past here is for AEM2 only */ | ||
172 | |||
173 | /* power caps in dW */ | ||
174 | u16 pcap[AEM2_NUM_PCAP_REGS]; | ||
175 | |||
176 | /* exhaust temperature in C */ | ||
177 | u8 temp[AEM2_NUM_TEMP_REGS]; | ||
178 | }; | ||
179 | |||
180 | /* Data structures returned by the AEM firmware */ | ||
181 | struct aem_iana_id { | ||
182 | u8 bytes[3]; | ||
183 | }; | ||
184 | static struct aem_iana_id system_x_id = { | ||
185 | .bytes = {0x4D, 0x4F, 0x00} | ||
186 | }; | ||
187 | |||
188 | /* These are used to find AEM1 instances */ | ||
189 | struct aem_find_firmware_req { | ||
190 | struct aem_iana_id id; | ||
191 | u8 rsvd; | ||
192 | __be16 index; | ||
193 | __be16 module_type_id; | ||
194 | } __packed; | ||
195 | |||
196 | struct aem_find_firmware_resp { | ||
197 | struct aem_iana_id id; | ||
198 | u8 num_instances; | ||
199 | } __packed; | ||
200 | |||
201 | /* These are used to find AEM2 instances */ | ||
202 | struct aem_find_instance_req { | ||
203 | struct aem_iana_id id; | ||
204 | u8 instance_number; | ||
205 | __be16 module_type_id; | ||
206 | } __packed; | ||
207 | |||
208 | struct aem_find_instance_resp { | ||
209 | struct aem_iana_id id; | ||
210 | u8 num_instances; | ||
211 | u8 major; | ||
212 | u8 minor; | ||
213 | u8 module_handle; | ||
214 | u16 record_id; | ||
215 | } __packed; | ||
216 | |||
217 | /* These are used to query sensors */ | ||
218 | struct aem_read_sensor_req { | ||
219 | struct aem_iana_id id; | ||
220 | u8 module_handle; | ||
221 | u8 element; | ||
222 | u8 subcommand; | ||
223 | u8 reg; | ||
224 | u8 rx_buf_size; | ||
225 | } __packed; | ||
226 | |||
227 | struct aem_read_sensor_resp { | ||
228 | struct aem_iana_id id; | ||
229 | u8 bytes[0]; | ||
230 | } __packed; | ||
231 | |||
232 | /* Data structures to talk to the IPMI layer */ | ||
233 | struct aem_driver_data { | ||
234 | struct list_head aem_devices; | ||
235 | struct ipmi_smi_watcher bmc_events; | ||
236 | struct ipmi_user_hndl ipmi_hndlrs; | ||
237 | }; | ||
238 | |||
239 | static void aem_register_bmc(int iface, struct device *dev); | ||
240 | static void aem_bmc_gone(int iface); | ||
241 | static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data); | ||
242 | |||
243 | static void aem_remove_sensors(struct aem_data *data); | ||
244 | static int aem_init_aem1(struct aem_ipmi_data *probe); | ||
245 | static int aem_init_aem2(struct aem_ipmi_data *probe); | ||
246 | static int aem1_find_sensors(struct aem_data *data); | ||
247 | static int aem2_find_sensors(struct aem_data *data); | ||
248 | static void update_aem1_sensors(struct aem_data *data); | ||
249 | static void update_aem2_sensors(struct aem_data *data); | ||
250 | |||
251 | static struct aem_driver_data driver_data = { | ||
252 | .aem_devices = LIST_HEAD_INIT(driver_data.aem_devices), | ||
253 | .bmc_events = { | ||
254 | .owner = THIS_MODULE, | ||
255 | .new_smi = aem_register_bmc, | ||
256 | .smi_gone = aem_bmc_gone, | ||
257 | }, | ||
258 | .ipmi_hndlrs = { | ||
259 | .ipmi_recv_hndl = aem_msg_handler, | ||
260 | }, | ||
261 | }; | ||
262 | |||
263 | /* Functions to talk to the IPMI layer */ | ||
264 | |||
265 | /* Initialize IPMI address, message buffers and user data */ | ||
266 | static int aem_init_ipmi_data(struct aem_ipmi_data *data, int iface, | ||
267 | struct device *bmc) | ||
268 | { | ||
269 | int err; | ||
270 | |||
271 | init_completion(&data->read_complete); | ||
272 | data->bmc_device = bmc; | ||
273 | |||
274 | /* Initialize IPMI address */ | ||
275 | data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | ||
276 | data->address.channel = IPMI_BMC_CHANNEL; | ||
277 | data->address.data[0] = 0; | ||
278 | data->interface = iface; | ||
279 | |||
280 | /* Initialize message buffers */ | ||
281 | data->tx_msgid = 0; | ||
282 | data->tx_message.netfn = AEM_NETFN; | ||
283 | |||
284 | /* Create IPMI messaging interface user */ | ||
285 | err = ipmi_create_user(data->interface, &driver_data.ipmi_hndlrs, | ||
286 | data, &data->user); | ||
287 | if (err < 0) { | ||
288 | dev_err(bmc, "Unable to register user with IPMI " | ||
289 | "interface %d\n", data->interface); | ||
290 | return -EACCES; | ||
291 | } | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /* Send an IPMI command */ | ||
297 | static int aem_send_message(struct aem_ipmi_data *data) | ||
298 | { | ||
299 | int err; | ||
300 | |||
301 | err = ipmi_validate_addr(&data->address, sizeof(data->address)); | ||
302 | if (err) | ||
303 | goto out; | ||
304 | |||
305 | data->tx_msgid++; | ||
306 | err = ipmi_request_settime(data->user, &data->address, data->tx_msgid, | ||
307 | &data->tx_message, data, 0, 0, 0); | ||
308 | if (err) | ||
309 | goto out1; | ||
310 | |||
311 | return 0; | ||
312 | out1: | ||
313 | dev_err(data->bmc_device, "request_settime=%x\n", err); | ||
314 | return err; | ||
315 | out: | ||
316 | dev_err(data->bmc_device, "validate_addr=%x\n", err); | ||
317 | return err; | ||
318 | } | ||
319 | |||
320 | /* Dispatch IPMI messages to callers */ | ||
321 | static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data) | ||
322 | { | ||
323 | unsigned short rx_len; | ||
324 | struct aem_ipmi_data *data = user_msg_data; | ||
325 | |||
326 | if (msg->msgid != data->tx_msgid) { | ||
327 | dev_err(data->bmc_device, "Mismatch between received msgid " | ||
328 | "(%02x) and transmitted msgid (%02x)!\n", | ||
329 | (int)msg->msgid, | ||
330 | (int)data->tx_msgid); | ||
331 | ipmi_free_recv_msg(msg); | ||
332 | return; | ||
333 | } | ||
334 | |||
335 | data->rx_recv_type = msg->recv_type; | ||
336 | if (msg->msg.data_len > 0) | ||
337 | data->rx_result = msg->msg.data[0]; | ||
338 | else | ||
339 | data->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE; | ||
340 | |||
341 | if (msg->msg.data_len > 1) { | ||
342 | rx_len = msg->msg.data_len - 1; | ||
343 | if (data->rx_msg_len < rx_len) | ||
344 | rx_len = data->rx_msg_len; | ||
345 | data->rx_msg_len = rx_len; | ||
346 | memcpy(data->rx_msg_data, msg->msg.data + 1, data->rx_msg_len); | ||
347 | } else | ||
348 | data->rx_msg_len = 0; | ||
349 | |||
350 | ipmi_free_recv_msg(msg); | ||
351 | complete(&data->read_complete); | ||
352 | } | ||
353 | |||
354 | /* ID functions */ | ||
355 | |||
356 | /* Obtain an id */ | ||
357 | static int aem_idr_get(int *id) | ||
358 | { | ||
359 | int i, err; | ||
360 | |||
361 | again: | ||
362 | if (unlikely(!idr_pre_get(&aem_idr, GFP_KERNEL))) | ||
363 | return -ENOMEM; | ||
364 | |||
365 | spin_lock(&aem_idr_lock); | ||
366 | err = idr_get_new(&aem_idr, NULL, &i); | ||
367 | spin_unlock(&aem_idr_lock); | ||
368 | |||
369 | if (unlikely(err == -EAGAIN)) | ||
370 | goto again; | ||
371 | else if (unlikely(err)) | ||
372 | return err; | ||
373 | |||
374 | *id = i & MAX_ID_MASK; | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | /* Release an object ID */ | ||
379 | static void aem_idr_put(int id) | ||
380 | { | ||
381 | spin_lock(&aem_idr_lock); | ||
382 | idr_remove(&aem_idr, id); | ||
383 | spin_unlock(&aem_idr_lock); | ||
384 | } | ||
385 | |||
386 | /* Sensor support functions */ | ||
387 | |||
388 | /* Read a sensor value */ | ||
389 | static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg, | ||
390 | void *buf, size_t size) | ||
391 | { | ||
392 | int rs_size, res; | ||
393 | struct aem_read_sensor_req rs_req; | ||
394 | struct aem_read_sensor_resp *rs_resp; | ||
395 | struct aem_ipmi_data *ipmi = &data->ipmi; | ||
396 | |||
397 | /* AEM registers are 1, 2, 4 or 8 bytes */ | ||
398 | switch (size) { | ||
399 | case 1: | ||
400 | case 2: | ||
401 | case 4: | ||
402 | case 8: | ||
403 | break; | ||
404 | default: | ||
405 | return -EINVAL; | ||
406 | } | ||
407 | |||
408 | rs_req.id = system_x_id; | ||
409 | rs_req.module_handle = data->module_handle; | ||
410 | rs_req.element = elt; | ||
411 | rs_req.subcommand = AEM_READ_REGISTER; | ||
412 | rs_req.reg = reg; | ||
413 | rs_req.rx_buf_size = size; | ||
414 | |||
415 | ipmi->tx_message.cmd = AEM_ELEMENT_CMD; | ||
416 | ipmi->tx_message.data = (char *)&rs_req; | ||
417 | ipmi->tx_message.data_len = sizeof(rs_req); | ||
418 | |||
419 | rs_size = sizeof(*rs_resp) + size; | ||
420 | rs_resp = kzalloc(rs_size, GFP_KERNEL); | ||
421 | if (!rs_resp) | ||
422 | return -ENOMEM; | ||
423 | |||
424 | ipmi->rx_msg_data = rs_resp; | ||
425 | ipmi->rx_msg_len = rs_size; | ||
426 | |||
427 | aem_send_message(ipmi); | ||
428 | |||
429 | res = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT); | ||
430 | if (!res) | ||
431 | return -ETIMEDOUT; | ||
432 | |||
433 | if (ipmi->rx_result || ipmi->rx_msg_len != rs_size || | ||
434 | memcmp(&rs_resp->id, &system_x_id, sizeof(system_x_id))) { | ||
435 | kfree(rs_resp); | ||
436 | return -ENOENT; | ||
437 | } | ||
438 | |||
439 | switch (size) { | ||
440 | case 1: { | ||
441 | u8 *x = buf; | ||
442 | *x = rs_resp->bytes[0]; | ||
443 | break; | ||
444 | } | ||
445 | case 2: { | ||
446 | u16 *x = buf; | ||
447 | *x = be16_to_cpup((__be16 *)rs_resp->bytes); | ||
448 | break; | ||
449 | } | ||
450 | case 4: { | ||
451 | u32 *x = buf; | ||
452 | *x = be32_to_cpup((__be32 *)rs_resp->bytes); | ||
453 | break; | ||
454 | } | ||
455 | case 8: { | ||
456 | u64 *x = buf; | ||
457 | *x = be64_to_cpup((__be64 *)rs_resp->bytes); | ||
458 | break; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | /* Update AEM energy registers */ | ||
466 | static void update_aem_energy(struct aem_data *data) | ||
467 | { | ||
468 | aem_read_sensor(data, AEM_ENERGY_ELEMENT, 0, &data->energy[0], 8); | ||
469 | if (data->ver_major < 2) | ||
470 | return; | ||
471 | aem_read_sensor(data, AEM_ENERGY_ELEMENT, 1, &data->energy[1], 8); | ||
472 | } | ||
473 | |||
474 | /* Update all AEM1 sensors */ | ||
475 | static void update_aem1_sensors(struct aem_data *data) | ||
476 | { | ||
477 | mutex_lock(&data->lock); | ||
478 | if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && | ||
479 | data->valid) | ||
480 | goto out; | ||
481 | |||
482 | update_aem_energy(data); | ||
483 | out: | ||
484 | mutex_unlock(&data->lock); | ||
485 | } | ||
486 | |||
487 | /* Update all AEM2 sensors */ | ||
488 | static void update_aem2_sensors(struct aem_data *data) | ||
489 | { | ||
490 | int i; | ||
491 | |||
492 | mutex_lock(&data->lock); | ||
493 | if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && | ||
494 | data->valid) | ||
495 | goto out; | ||
496 | |||
497 | update_aem_energy(data); | ||
498 | aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 0, &data->temp[0], 1); | ||
499 | aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 1, &data->temp[1], 1); | ||
500 | |||
501 | for (i = POWER_CAP; i <= POWER_AUX; i++) | ||
502 | aem_read_sensor(data, AEM_POWER_CAP_ELEMENT, i, | ||
503 | &data->pcap[i], 2); | ||
504 | out: | ||
505 | mutex_unlock(&data->lock); | ||
506 | } | ||
507 | |||
508 | /* Delete an AEM instance */ | ||
509 | static void aem_delete(struct aem_data *data) | ||
510 | { | ||
511 | list_del(&data->list); | ||
512 | aem_remove_sensors(data); | ||
513 | hwmon_device_unregister(data->hwmon_dev); | ||
514 | ipmi_destroy_user(data->ipmi.user); | ||
515 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
516 | platform_device_unregister(data->pdev); | ||
517 | aem_idr_put(data->id); | ||
518 | kfree(data); | ||
519 | } | ||
520 | |||
521 | /* Probe functions for AEM1 devices */ | ||
522 | |||
523 | /* Retrieve version and module handle for an AEM1 instance */ | ||
524 | static int aem_find_aem1_count(struct aem_ipmi_data *data) | ||
525 | { | ||
526 | int res; | ||
527 | struct aem_find_firmware_req ff_req; | ||
528 | struct aem_find_firmware_resp ff_resp; | ||
529 | |||
530 | ff_req.id = system_x_id; | ||
531 | ff_req.index = 0; | ||
532 | ff_req.module_type_id = cpu_to_be16(AEM_MODULE_TYPE_ID); | ||
533 | |||
534 | data->tx_message.cmd = AEM_FIND_FW_CMD; | ||
535 | data->tx_message.data = (char *)&ff_req; | ||
536 | data->tx_message.data_len = sizeof(ff_req); | ||
537 | |||
538 | data->rx_msg_data = &ff_resp; | ||
539 | data->rx_msg_len = sizeof(ff_resp); | ||
540 | |||
541 | aem_send_message(data); | ||
542 | |||
543 | res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); | ||
544 | if (!res) | ||
545 | return -ETIMEDOUT; | ||
546 | |||
547 | if (data->rx_result || data->rx_msg_len != sizeof(ff_resp) || | ||
548 | memcmp(&ff_resp.id, &system_x_id, sizeof(system_x_id))) | ||
549 | return -ENOENT; | ||
550 | |||
551 | return ff_resp.num_instances; | ||
552 | } | ||
553 | |||
554 | /* Find and initialize one AEM1 instance */ | ||
555 | static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle) | ||
556 | { | ||
557 | struct aem_data *data; | ||
558 | int i; | ||
559 | int res = -ENOMEM; | ||
560 | |||
561 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
562 | if (!data) | ||
563 | return res; | ||
564 | mutex_init(&data->lock); | ||
565 | |||
566 | /* Copy instance data */ | ||
567 | data->ver_major = 1; | ||
568 | data->ver_minor = 0; | ||
569 | data->module_handle = module_handle; | ||
570 | for (i = 0; i < AEM1_NUM_ENERGY_REGS; i++) | ||
571 | data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; | ||
572 | |||
573 | /* Create sub-device for this fw instance */ | ||
574 | if (aem_idr_get(&data->id)) | ||
575 | goto id_err; | ||
576 | |||
577 | data->pdev = platform_device_alloc(DRVNAME, data->id); | ||
578 | if (!data->pdev) | ||
579 | goto dev_err; | ||
580 | data->pdev->dev.driver = &aem_driver; | ||
581 | |||
582 | res = platform_device_add(data->pdev); | ||
583 | if (res) | ||
584 | goto ipmi_err; | ||
585 | |||
586 | dev_set_drvdata(&data->pdev->dev, data); | ||
587 | |||
588 | /* Set up IPMI interface */ | ||
589 | if (aem_init_ipmi_data(&data->ipmi, probe->interface, | ||
590 | probe->bmc_device)) | ||
591 | goto ipmi_err; | ||
592 | |||
593 | /* Register with hwmon */ | ||
594 | data->hwmon_dev = hwmon_device_register(&data->pdev->dev); | ||
595 | |||
596 | if (IS_ERR(data->hwmon_dev)) { | ||
597 | dev_err(&data->pdev->dev, "Unable to register hwmon " | ||
598 | "device for IPMI interface %d\n", | ||
599 | probe->interface); | ||
600 | goto hwmon_reg_err; | ||
601 | } | ||
602 | |||
603 | data->update = update_aem1_sensors; | ||
604 | |||
605 | /* Find sensors */ | ||
606 | if (aem1_find_sensors(data)) | ||
607 | goto sensor_err; | ||
608 | |||
609 | /* Add to our list of AEM devices */ | ||
610 | list_add_tail(&data->list, &driver_data.aem_devices); | ||
611 | |||
612 | dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", | ||
613 | data->ver_major, data->ver_minor, | ||
614 | data->module_handle); | ||
615 | return 0; | ||
616 | |||
617 | sensor_err: | ||
618 | hwmon_device_unregister(data->hwmon_dev); | ||
619 | hwmon_reg_err: | ||
620 | ipmi_destroy_user(data->ipmi.user); | ||
621 | ipmi_err: | ||
622 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
623 | platform_device_unregister(data->pdev); | ||
624 | dev_err: | ||
625 | aem_idr_put(data->id); | ||
626 | id_err: | ||
627 | kfree(data); | ||
628 | |||
629 | return res; | ||
630 | } | ||
631 | |||
632 | /* Find and initialize all AEM1 instances */ | ||
633 | static int aem_init_aem1(struct aem_ipmi_data *probe) | ||
634 | { | ||
635 | int num, i, err; | ||
636 | |||
637 | num = aem_find_aem1_count(probe); | ||
638 | for (i = 0; i < num; i++) { | ||
639 | err = aem_init_aem1_inst(probe, i); | ||
640 | if (err) { | ||
641 | dev_err(probe->bmc_device, | ||
642 | "Error %d initializing AEM1 0x%X\n", | ||
643 | err, i); | ||
644 | return err; | ||
645 | } | ||
646 | } | ||
647 | |||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | /* Probe functions for AEM2 devices */ | ||
652 | |||
653 | /* Retrieve version and module handle for an AEM2 instance */ | ||
654 | static int aem_find_aem2(struct aem_ipmi_data *data, | ||
655 | struct aem_find_instance_resp *fi_resp, | ||
656 | int instance_num) | ||
657 | { | ||
658 | int res; | ||
659 | struct aem_find_instance_req fi_req; | ||
660 | |||
661 | fi_req.id = system_x_id; | ||
662 | fi_req.instance_number = instance_num; | ||
663 | fi_req.module_type_id = cpu_to_be16(AEM_MODULE_TYPE_ID); | ||
664 | |||
665 | data->tx_message.cmd = AEM_FW_INSTANCE_CMD; | ||
666 | data->tx_message.data = (char *)&fi_req; | ||
667 | data->tx_message.data_len = sizeof(fi_req); | ||
668 | |||
669 | data->rx_msg_data = fi_resp; | ||
670 | data->rx_msg_len = sizeof(*fi_resp); | ||
671 | |||
672 | aem_send_message(data); | ||
673 | |||
674 | res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); | ||
675 | if (!res) | ||
676 | return -ETIMEDOUT; | ||
677 | |||
678 | if (data->rx_result || data->rx_msg_len != sizeof(*fi_resp) || | ||
679 | memcmp(&fi_resp->id, &system_x_id, sizeof(system_x_id))) | ||
680 | return -ENOENT; | ||
681 | |||
682 | return 0; | ||
683 | } | ||
684 | |||
685 | /* Find and initialize one AEM2 instance */ | ||
686 | static int aem_init_aem2_inst(struct aem_ipmi_data *probe, | ||
687 | struct aem_find_instance_resp *fi_resp) | ||
688 | { | ||
689 | struct aem_data *data; | ||
690 | int i; | ||
691 | int res = -ENOMEM; | ||
692 | |||
693 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
694 | if (!data) | ||
695 | return res; | ||
696 | mutex_init(&data->lock); | ||
697 | |||
698 | /* Copy instance data */ | ||
699 | data->ver_major = fi_resp->major; | ||
700 | data->ver_minor = fi_resp->minor; | ||
701 | data->module_handle = fi_resp->module_handle; | ||
702 | for (i = 0; i < AEM2_NUM_ENERGY_REGS; i++) | ||
703 | data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; | ||
704 | |||
705 | /* Create sub-device for this fw instance */ | ||
706 | if (aem_idr_get(&data->id)) | ||
707 | goto id_err; | ||
708 | |||
709 | data->pdev = platform_device_alloc(DRVNAME, data->id); | ||
710 | if (!data->pdev) | ||
711 | goto dev_err; | ||
712 | data->pdev->dev.driver = &aem_driver; | ||
713 | |||
714 | res = platform_device_add(data->pdev); | ||
715 | if (res) | ||
716 | goto ipmi_err; | ||
717 | |||
718 | dev_set_drvdata(&data->pdev->dev, data); | ||
719 | |||
720 | /* Set up IPMI interface */ | ||
721 | if (aem_init_ipmi_data(&data->ipmi, probe->interface, | ||
722 | probe->bmc_device)) | ||
723 | goto ipmi_err; | ||
724 | |||
725 | /* Register with hwmon */ | ||
726 | data->hwmon_dev = hwmon_device_register(&data->pdev->dev); | ||
727 | |||
728 | if (IS_ERR(data->hwmon_dev)) { | ||
729 | dev_err(&data->pdev->dev, "Unable to register hwmon " | ||
730 | "device for IPMI interface %d\n", | ||
731 | probe->interface); | ||
732 | goto hwmon_reg_err; | ||
733 | } | ||
734 | |||
735 | data->update = update_aem2_sensors; | ||
736 | |||
737 | /* Find sensors */ | ||
738 | if (aem2_find_sensors(data)) | ||
739 | goto sensor_err; | ||
740 | |||
741 | /* Add to our list of AEM devices */ | ||
742 | list_add_tail(&data->list, &driver_data.aem_devices); | ||
743 | |||
744 | dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", | ||
745 | data->ver_major, data->ver_minor, | ||
746 | data->module_handle); | ||
747 | return 0; | ||
748 | |||
749 | sensor_err: | ||
750 | hwmon_device_unregister(data->hwmon_dev); | ||
751 | hwmon_reg_err: | ||
752 | ipmi_destroy_user(data->ipmi.user); | ||
753 | ipmi_err: | ||
754 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
755 | platform_device_unregister(data->pdev); | ||
756 | dev_err: | ||
757 | aem_idr_put(data->id); | ||
758 | id_err: | ||
759 | kfree(data); | ||
760 | |||
761 | return res; | ||
762 | } | ||
763 | |||
764 | /* Find and initialize all AEM2 instances */ | ||
765 | static int aem_init_aem2(struct aem_ipmi_data *probe) | ||
766 | { | ||
767 | struct aem_find_instance_resp fi_resp; | ||
768 | int err; | ||
769 | int i = 0; | ||
770 | |||
771 | while (!aem_find_aem2(probe, &fi_resp, i)) { | ||
772 | if (fi_resp.major != 2) { | ||
773 | dev_err(probe->bmc_device, "Unknown AEM v%d; please " | ||
774 | "report this to the maintainer.\n", | ||
775 | fi_resp.major); | ||
776 | i++; | ||
777 | continue; | ||
778 | } | ||
779 | err = aem_init_aem2_inst(probe, &fi_resp); | ||
780 | if (err) { | ||
781 | dev_err(probe->bmc_device, | ||
782 | "Error %d initializing AEM2 0x%X\n", | ||
783 | err, fi_resp.module_handle); | ||
784 | return err; | ||
785 | } | ||
786 | i++; | ||
787 | } | ||
788 | |||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | /* Probe a BMC for AEM firmware instances */ | ||
793 | static void aem_register_bmc(int iface, struct device *dev) | ||
794 | { | ||
795 | struct aem_ipmi_data probe; | ||
796 | |||
797 | if (aem_init_ipmi_data(&probe, iface, dev)) | ||
798 | return; | ||
799 | |||
800 | /* Ignore probe errors; they won't cause problems */ | ||
801 | aem_init_aem1(&probe); | ||
802 | aem_init_aem2(&probe); | ||
803 | |||
804 | ipmi_destroy_user(probe.user); | ||
805 | } | ||
806 | |||
807 | /* Handle BMC deletion */ | ||
808 | static void aem_bmc_gone(int iface) | ||
809 | { | ||
810 | struct aem_data *p1, *next1; | ||
811 | |||
812 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) | ||
813 | if (p1->ipmi.interface == iface) | ||
814 | aem_delete(p1); | ||
815 | } | ||
816 | |||
817 | /* sysfs support functions */ | ||
818 | |||
819 | /* AEM device name */ | ||
820 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | ||
821 | char *buf) | ||
822 | { | ||
823 | struct aem_data *data = dev_get_drvdata(dev); | ||
824 | |||
825 | return sprintf(buf, "%s%d\n", DRVNAME, data->ver_major); | ||
826 | } | ||
827 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0); | ||
828 | |||
829 | /* AEM device version */ | ||
830 | static ssize_t show_version(struct device *dev, | ||
831 | struct device_attribute *devattr, | ||
832 | char *buf) | ||
833 | { | ||
834 | struct aem_data *data = dev_get_drvdata(dev); | ||
835 | |||
836 | return sprintf(buf, "%d.%d\n", data->ver_major, data->ver_minor); | ||
837 | } | ||
838 | static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, 0); | ||
839 | |||
840 | /* Display power use */ | ||
841 | static ssize_t aem_show_power(struct device *dev, | ||
842 | struct device_attribute *devattr, | ||
843 | char *buf) | ||
844 | { | ||
845 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
846 | struct aem_data *data = dev_get_drvdata(dev); | ||
847 | u64 before, after, delta, time; | ||
848 | signed long leftover; | ||
849 | struct timespec b, a; | ||
850 | |||
851 | mutex_lock(&data->lock); | ||
852 | update_aem_energy(data); | ||
853 | getnstimeofday(&b); | ||
854 | before = data->energy[attr->index]; | ||
855 | |||
856 | leftover = schedule_timeout_interruptible( | ||
857 | msecs_to_jiffies(data->power_period[attr->index]) | ||
858 | ); | ||
859 | if (leftover) { | ||
860 | mutex_unlock(&data->lock); | ||
861 | return 0; | ||
862 | } | ||
863 | |||
864 | update_aem_energy(data); | ||
865 | getnstimeofday(&a); | ||
866 | after = data->energy[attr->index]; | ||
867 | mutex_unlock(&data->lock); | ||
868 | |||
869 | time = timespec_to_ns(&a) - timespec_to_ns(&b); | ||
870 | delta = (after - before) * UJ_PER_MJ; | ||
871 | |||
872 | return sprintf(buf, "%llu\n", | ||
873 | (unsigned long long)div64_u64(delta * NSEC_PER_SEC, time)); | ||
874 | } | ||
875 | |||
876 | /* Display energy use */ | ||
877 | static ssize_t aem_show_energy(struct device *dev, | ||
878 | struct device_attribute *devattr, | ||
879 | char *buf) | ||
880 | { | ||
881 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
882 | struct aem_data *a = dev_get_drvdata(dev); | ||
883 | a->update(a); | ||
884 | |||
885 | return sprintf(buf, "%llu\n", | ||
886 | (unsigned long long)a->energy[attr->index] * 1000); | ||
887 | } | ||
888 | |||
889 | /* Display power interval registers */ | ||
890 | static ssize_t aem_show_power_period(struct device *dev, | ||
891 | struct device_attribute *devattr, | ||
892 | char *buf) | ||
893 | { | ||
894 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
895 | struct aem_data *a = dev_get_drvdata(dev); | ||
896 | a->update(a); | ||
897 | |||
898 | return sprintf(buf, "%lu\n", a->power_period[attr->index]); | ||
899 | } | ||
900 | |||
901 | /* Set power interval registers */ | ||
902 | static ssize_t aem_set_power_period(struct device *dev, | ||
903 | struct device_attribute *devattr, | ||
904 | const char *buf, size_t count) | ||
905 | { | ||
906 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
907 | struct aem_data *a = dev_get_drvdata(dev); | ||
908 | unsigned long temp; | ||
909 | int res; | ||
910 | |||
911 | res = strict_strtoul(buf, 10, &temp); | ||
912 | if (res) | ||
913 | return res; | ||
914 | |||
915 | if (temp < AEM_MIN_POWER_INTERVAL) | ||
916 | return -EINVAL; | ||
917 | |||
918 | mutex_lock(&a->lock); | ||
919 | a->power_period[attr->index] = temp; | ||
920 | mutex_unlock(&a->lock); | ||
921 | |||
922 | return count; | ||
923 | } | ||
924 | |||
925 | /* Discover sensors on an AEM device */ | ||
926 | static int aem_register_sensors(struct aem_data *data, | ||
927 | struct aem_ro_sensor_template *ro, | ||
928 | struct aem_rw_sensor_template *rw) | ||
929 | { | ||
930 | struct device *dev = &data->pdev->dev; | ||
931 | struct sensor_device_attribute *sensors = data->sensors; | ||
932 | int err; | ||
933 | |||
934 | /* Set up read-only sensors */ | ||
935 | while (ro->label) { | ||
936 | sensors->dev_attr.attr.name = ro->label; | ||
937 | sensors->dev_attr.attr.mode = S_IRUGO; | ||
938 | sensors->dev_attr.show = ro->show; | ||
939 | sensors->index = ro->index; | ||
940 | |||
941 | err = device_create_file(dev, &sensors->dev_attr); | ||
942 | if (err) { | ||
943 | sensors->dev_attr.attr.name = NULL; | ||
944 | goto error; | ||
945 | } | ||
946 | sensors++; | ||
947 | ro++; | ||
948 | } | ||
949 | |||
950 | /* Set up read-write sensors */ | ||
951 | while (rw->label) { | ||
952 | sensors->dev_attr.attr.name = rw->label; | ||
953 | sensors->dev_attr.attr.mode = S_IRUGO | S_IWUSR; | ||
954 | sensors->dev_attr.show = rw->show; | ||
955 | sensors->dev_attr.store = rw->set; | ||
956 | sensors->index = rw->index; | ||
957 | |||
958 | err = device_create_file(dev, &sensors->dev_attr); | ||
959 | if (err) { | ||
960 | sensors->dev_attr.attr.name = NULL; | ||
961 | goto error; | ||
962 | } | ||
963 | sensors++; | ||
964 | rw++; | ||
965 | } | ||
966 | |||
967 | err = device_create_file(dev, &sensor_dev_attr_name.dev_attr); | ||
968 | if (err) | ||
969 | goto error; | ||
970 | err = device_create_file(dev, &sensor_dev_attr_version.dev_attr); | ||
971 | return err; | ||
972 | |||
973 | error: | ||
974 | aem_remove_sensors(data); | ||
975 | return err; | ||
976 | } | ||
977 | |||
978 | /* sysfs support functions for AEM2 sensors */ | ||
979 | |||
980 | /* Display temperature use */ | ||
981 | static ssize_t aem2_show_temp(struct device *dev, | ||
982 | struct device_attribute *devattr, | ||
983 | char *buf) | ||
984 | { | ||
985 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
986 | struct aem_data *a = dev_get_drvdata(dev); | ||
987 | a->update(a); | ||
988 | |||
989 | return sprintf(buf, "%u\n", a->temp[attr->index] * 1000); | ||
990 | } | ||
991 | |||
992 | /* Display power-capping registers */ | ||
993 | static ssize_t aem2_show_pcap_value(struct device *dev, | ||
994 | struct device_attribute *devattr, | ||
995 | char *buf) | ||
996 | { | ||
997 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
998 | struct aem_data *a = dev_get_drvdata(dev); | ||
999 | a->update(a); | ||
1000 | |||
1001 | return sprintf(buf, "%u\n", a->pcap[attr->index] * 100000); | ||
1002 | } | ||
1003 | |||
1004 | /* Remove sensors attached to an AEM device */ | ||
1005 | static void aem_remove_sensors(struct aem_data *data) | ||
1006 | { | ||
1007 | int i; | ||
1008 | |||
1009 | for (i = 0; i < AEM_NUM_SENSORS; i++) { | ||
1010 | if (!data->sensors[i].dev_attr.attr.name) | ||
1011 | continue; | ||
1012 | device_remove_file(&data->pdev->dev, | ||
1013 | &data->sensors[i].dev_attr); | ||
1014 | } | ||
1015 | |||
1016 | device_remove_file(&data->pdev->dev, | ||
1017 | &sensor_dev_attr_name.dev_attr); | ||
1018 | device_remove_file(&data->pdev->dev, | ||
1019 | &sensor_dev_attr_version.dev_attr); | ||
1020 | } | ||
1021 | |||
1022 | /* Sensor probe functions */ | ||
1023 | |||
1024 | /* Description of AEM1 sensors */ | ||
1025 | static struct aem_ro_sensor_template aem1_ro_sensors[] = { | ||
1026 | {"energy1_input", aem_show_energy, 0}, | ||
1027 | {"power1_average", aem_show_power, 0}, | ||
1028 | {NULL, NULL, 0}, | ||
1029 | }; | ||
1030 | |||
1031 | static struct aem_rw_sensor_template aem1_rw_sensors[] = { | ||
1032 | {"power1_average_interval", aem_show_power_period, aem_set_power_period, 0}, | ||
1033 | {NULL, NULL, NULL, 0}, | ||
1034 | }; | ||
1035 | |||
1036 | /* Description of AEM2 sensors */ | ||
1037 | static struct aem_ro_sensor_template aem2_ro_sensors[] = { | ||
1038 | {"energy1_input", aem_show_energy, 0}, | ||
1039 | {"energy2_input", aem_show_energy, 1}, | ||
1040 | {"power1_average", aem_show_power, 0}, | ||
1041 | {"power2_average", aem_show_power, 1}, | ||
1042 | {"temp1_input", aem2_show_temp, 0}, | ||
1043 | {"temp2_input", aem2_show_temp, 1}, | ||
1044 | |||
1045 | {"power4_average", aem2_show_pcap_value, POWER_CAP_MAX_HOTPLUG}, | ||
1046 | {"power5_average", aem2_show_pcap_value, POWER_CAP_MAX}, | ||
1047 | {"power6_average", aem2_show_pcap_value, POWER_CAP_MIN_WARNING}, | ||
1048 | {"power7_average", aem2_show_pcap_value, POWER_CAP_MIN}, | ||
1049 | |||
1050 | {"power3_average", aem2_show_pcap_value, POWER_AUX}, | ||
1051 | {"power_cap", aem2_show_pcap_value, POWER_CAP}, | ||
1052 | {NULL, NULL, 0}, | ||
1053 | }; | ||
1054 | |||
1055 | static struct aem_rw_sensor_template aem2_rw_sensors[] = { | ||
1056 | {"power1_average_interval", aem_show_power_period, aem_set_power_period, 0}, | ||
1057 | {"power2_average_interval", aem_show_power_period, aem_set_power_period, 1}, | ||
1058 | {NULL, NULL, NULL, 0}, | ||
1059 | }; | ||
1060 | |||
1061 | /* Set up AEM1 sensor attrs */ | ||
1062 | static int aem1_find_sensors(struct aem_data *data) | ||
1063 | { | ||
1064 | return aem_register_sensors(data, aem1_ro_sensors, aem1_rw_sensors); | ||
1065 | } | ||
1066 | |||
1067 | /* Set up AEM2 sensor attrs */ | ||
1068 | static int aem2_find_sensors(struct aem_data *data) | ||
1069 | { | ||
1070 | return aem_register_sensors(data, aem2_ro_sensors, aem2_rw_sensors); | ||
1071 | } | ||
1072 | |||
1073 | /* Module init/exit routines */ | ||
1074 | |||
1075 | static int __init aem_init(void) | ||
1076 | { | ||
1077 | int res; | ||
1078 | |||
1079 | res = driver_register(&aem_driver); | ||
1080 | if (res) { | ||
1081 | printk(KERN_ERR "Can't register aem driver\n"); | ||
1082 | return res; | ||
1083 | } | ||
1084 | |||
1085 | res = ipmi_smi_watcher_register(&driver_data.bmc_events); | ||
1086 | if (res) | ||
1087 | goto ipmi_reg_err; | ||
1088 | return 0; | ||
1089 | |||
1090 | ipmi_reg_err: | ||
1091 | driver_unregister(&aem_driver); | ||
1092 | return res; | ||
1093 | |||
1094 | } | ||
1095 | |||
1096 | static void __exit aem_exit(void) | ||
1097 | { | ||
1098 | struct aem_data *p1, *next1; | ||
1099 | |||
1100 | ipmi_smi_watcher_unregister(&driver_data.bmc_events); | ||
1101 | driver_unregister(&aem_driver); | ||
1102 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) | ||
1103 | aem_delete(p1); | ||
1104 | } | ||
1105 | |||
1106 | MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); | ||
1107 | MODULE_DESCRIPTION("IBM Active Energy Manager power/temp sensor driver"); | ||
1108 | MODULE_LICENSE("GPL"); | ||
1109 | |||
1110 | module_init(aem_init); | ||
1111 | module_exit(aem_exit); | ||
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 116287008083..3195a265f0e9 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor | 2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor |
3 | * with integrated fan control | 3 | * with integrated fan control |
4 | * Copyright (C) 2004-2006 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
5 | * Based on the lm90 driver. | 5 | * Based on the lm90 driver. |
6 | * | 6 | * |
7 | * The LM63 is a sensor chip made by National Semiconductor. It measures | 7 | * The LM63 is a sensor chip made by National Semiconductor. It measures |
@@ -128,24 +128,36 @@ I2C_CLIENT_INSMOD_1(lm63); | |||
128 | * Functions declaration | 128 | * Functions declaration |
129 | */ | 129 | */ |
130 | 130 | ||
131 | static int lm63_attach_adapter(struct i2c_adapter *adapter); | 131 | static int lm63_probe(struct i2c_client *client, |
132 | static int lm63_detach_client(struct i2c_client *client); | 132 | const struct i2c_device_id *id); |
133 | static int lm63_remove(struct i2c_client *client); | ||
133 | 134 | ||
134 | static struct lm63_data *lm63_update_device(struct device *dev); | 135 | static struct lm63_data *lm63_update_device(struct device *dev); |
135 | 136 | ||
136 | static int lm63_detect(struct i2c_adapter *adapter, int address, int kind); | 137 | static int lm63_detect(struct i2c_client *client, int kind, |
138 | struct i2c_board_info *info); | ||
137 | static void lm63_init_client(struct i2c_client *client); | 139 | static void lm63_init_client(struct i2c_client *client); |
138 | 140 | ||
139 | /* | 141 | /* |
140 | * Driver data (common to all clients) | 142 | * Driver data (common to all clients) |
141 | */ | 143 | */ |
142 | 144 | ||
145 | static const struct i2c_device_id lm63_id[] = { | ||
146 | { "lm63", lm63 }, | ||
147 | { } | ||
148 | }; | ||
149 | MODULE_DEVICE_TABLE(i2c, lm63_id); | ||
150 | |||
143 | static struct i2c_driver lm63_driver = { | 151 | static struct i2c_driver lm63_driver = { |
152 | .class = I2C_CLASS_HWMON, | ||
144 | .driver = { | 153 | .driver = { |
145 | .name = "lm63", | 154 | .name = "lm63", |
146 | }, | 155 | }, |
147 | .attach_adapter = lm63_attach_adapter, | 156 | .probe = lm63_probe, |
148 | .detach_client = lm63_detach_client, | 157 | .remove = lm63_remove, |
158 | .id_table = lm63_id, | ||
159 | .detect = lm63_detect, | ||
160 | .address_data = &addr_data, | ||
149 | }; | 161 | }; |
150 | 162 | ||
151 | /* | 163 | /* |
@@ -153,7 +165,6 @@ static struct i2c_driver lm63_driver = { | |||
153 | */ | 165 | */ |
154 | 166 | ||
155 | struct lm63_data { | 167 | struct lm63_data { |
156 | struct i2c_client client; | ||
157 | struct device *hwmon_dev; | 168 | struct device *hwmon_dev; |
158 | struct mutex update_lock; | 169 | struct mutex update_lock; |
159 | char valid; /* zero until following fields are valid */ | 170 | char valid; /* zero until following fields are valid */ |
@@ -411,43 +422,14 @@ static const struct attribute_group lm63_group_fan1 = { | |||
411 | * Real code | 422 | * Real code |
412 | */ | 423 | */ |
413 | 424 | ||
414 | static int lm63_attach_adapter(struct i2c_adapter *adapter) | 425 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
426 | static int lm63_detect(struct i2c_client *new_client, int kind, | ||
427 | struct i2c_board_info *info) | ||
415 | { | 428 | { |
416 | if (!(adapter->class & I2C_CLASS_HWMON)) | 429 | struct i2c_adapter *adapter = new_client->adapter; |
417 | return 0; | ||
418 | return i2c_probe(adapter, &addr_data, lm63_detect); | ||
419 | } | ||
420 | |||
421 | /* | ||
422 | * The following function does more than just detection. If detection | ||
423 | * succeeds, it also registers the new chip. | ||
424 | */ | ||
425 | static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | ||
426 | { | ||
427 | struct i2c_client *new_client; | ||
428 | struct lm63_data *data; | ||
429 | int err = 0; | ||
430 | 430 | ||
431 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 431 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
432 | goto exit; | 432 | return -ENODEV; |
433 | |||
434 | if (!(data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL))) { | ||
435 | err = -ENOMEM; | ||
436 | goto exit; | ||
437 | } | ||
438 | |||
439 | /* The common I2C client data is placed right before the | ||
440 | LM63-specific data. */ | ||
441 | new_client = &data->client; | ||
442 | i2c_set_clientdata(new_client, data); | ||
443 | new_client->addr = address; | ||
444 | new_client->adapter = adapter; | ||
445 | new_client->driver = &lm63_driver; | ||
446 | new_client->flags = 0; | ||
447 | |||
448 | /* Default to an LM63 if forced */ | ||
449 | if (kind == 0) | ||
450 | kind = lm63; | ||
451 | 433 | ||
452 | if (kind < 0) { /* must identify */ | 434 | if (kind < 0) { /* must identify */ |
453 | u8 man_id, chip_id, reg_config1, reg_config2; | 435 | u8 man_id, chip_id, reg_config1, reg_config2; |
@@ -477,25 +459,38 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
477 | dev_dbg(&adapter->dev, "Unsupported chip " | 459 | dev_dbg(&adapter->dev, "Unsupported chip " |
478 | "(man_id=0x%02X, chip_id=0x%02X).\n", | 460 | "(man_id=0x%02X, chip_id=0x%02X).\n", |
479 | man_id, chip_id); | 461 | man_id, chip_id); |
480 | goto exit_free; | 462 | return -ENODEV; |
481 | } | 463 | } |
482 | } | 464 | } |
483 | 465 | ||
484 | strlcpy(new_client->name, "lm63", I2C_NAME_SIZE); | 466 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static int lm63_probe(struct i2c_client *new_client, | ||
472 | const struct i2c_device_id *id) | ||
473 | { | ||
474 | struct lm63_data *data; | ||
475 | int err; | ||
476 | |||
477 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); | ||
478 | if (!data) { | ||
479 | err = -ENOMEM; | ||
480 | goto exit; | ||
481 | } | ||
482 | |||
483 | i2c_set_clientdata(new_client, data); | ||
485 | data->valid = 0; | 484 | data->valid = 0; |
486 | mutex_init(&data->update_lock); | 485 | mutex_init(&data->update_lock); |
487 | 486 | ||
488 | /* Tell the I2C layer a new client has arrived */ | ||
489 | if ((err = i2c_attach_client(new_client))) | ||
490 | goto exit_free; | ||
491 | |||
492 | /* Initialize the LM63 chip */ | 487 | /* Initialize the LM63 chip */ |
493 | lm63_init_client(new_client); | 488 | lm63_init_client(new_client); |
494 | 489 | ||
495 | /* Register sysfs hooks */ | 490 | /* Register sysfs hooks */ |
496 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 491 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
497 | &lm63_group))) | 492 | &lm63_group))) |
498 | goto exit_detach; | 493 | goto exit_free; |
499 | if (data->config & 0x04) { /* tachometer enabled */ | 494 | if (data->config & 0x04) { /* tachometer enabled */ |
500 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 495 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
501 | &lm63_group_fan1))) | 496 | &lm63_group_fan1))) |
@@ -513,8 +508,6 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
513 | exit_remove_files: | 508 | exit_remove_files: |
514 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); | 509 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
515 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); | 510 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
516 | exit_detach: | ||
517 | i2c_detach_client(new_client); | ||
518 | exit_free: | 511 | exit_free: |
519 | kfree(data); | 512 | kfree(data); |
520 | exit: | 513 | exit: |
@@ -556,18 +549,14 @@ static void lm63_init_client(struct i2c_client *client) | |||
556 | (data->config_fan & 0x20) ? "manual" : "auto"); | 549 | (data->config_fan & 0x20) ? "manual" : "auto"); |
557 | } | 550 | } |
558 | 551 | ||
559 | static int lm63_detach_client(struct i2c_client *client) | 552 | static int lm63_remove(struct i2c_client *client) |
560 | { | 553 | { |
561 | struct lm63_data *data = i2c_get_clientdata(client); | 554 | struct lm63_data *data = i2c_get_clientdata(client); |
562 | int err; | ||
563 | 555 | ||
564 | hwmon_device_unregister(data->hwmon_dev); | 556 | hwmon_device_unregister(data->hwmon_dev); |
565 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | 557 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
566 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | 558 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
567 | 559 | ||
568 | if ((err = i2c_detach_client(client))) | ||
569 | return err; | ||
570 | |||
571 | kfree(data); | 560 | kfree(data); |
572 | return 0; | 561 | return 0; |
573 | } | 562 | } |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index fa7696905154..de698dc73020 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -251,10 +251,13 @@ static int lm75_detach_client(struct i2c_client *client) | |||
251 | the SMBus standard. */ | 251 | the SMBus standard. */ |
252 | static int lm75_read_value(struct i2c_client *client, u8 reg) | 252 | static int lm75_read_value(struct i2c_client *client, u8 reg) |
253 | { | 253 | { |
254 | int value; | ||
255 | |||
254 | if (reg == LM75_REG_CONF) | 256 | if (reg == LM75_REG_CONF) |
255 | return i2c_smbus_read_byte_data(client, reg); | 257 | return i2c_smbus_read_byte_data(client, reg); |
256 | else | 258 | |
257 | return swab16(i2c_smbus_read_word_data(client, reg)); | 259 | value = i2c_smbus_read_word_data(client, reg); |
260 | return (value < 0) ? value : swab16(value); | ||
258 | } | 261 | } |
259 | 262 | ||
260 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) | 263 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) |
@@ -287,9 +290,16 @@ static struct lm75_data *lm75_update_device(struct device *dev) | |||
287 | int i; | 290 | int i; |
288 | dev_dbg(&client->dev, "Starting lm75 update\n"); | 291 | dev_dbg(&client->dev, "Starting lm75 update\n"); |
289 | 292 | ||
290 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) | 293 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { |
291 | data->temp[i] = lm75_read_value(client, | 294 | int status; |
292 | LM75_REG_TEMP[i]); | 295 | |
296 | status = lm75_read_value(client, LM75_REG_TEMP[i]); | ||
297 | if (status < 0) | ||
298 | dev_dbg(&client->dev, "reg %d, err %d\n", | ||
299 | LM75_REG_TEMP[i], status); | ||
300 | else | ||
301 | data->temp[i] = status; | ||
302 | } | ||
293 | data->last_updated = jiffies; | 303 | data->last_updated = jiffies; |
294 | data->valid = 1; | 304 | data->valid = 1; |
295 | } | 305 | } |
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 36d5a8c3ad8c..866b401ab6e8 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -52,7 +52,6 @@ I2C_CLIENT_INSMOD_1(lm77); | |||
52 | 52 | ||
53 | /* Each client has this additional data */ | 53 | /* Each client has this additional data */ |
54 | struct lm77_data { | 54 | struct lm77_data { |
55 | struct i2c_client client; | ||
56 | struct device *hwmon_dev; | 55 | struct device *hwmon_dev; |
57 | struct mutex update_lock; | 56 | struct mutex update_lock; |
58 | char valid; | 57 | char valid; |
@@ -65,23 +64,35 @@ struct lm77_data { | |||
65 | u8 alarms; | 64 | u8 alarms; |
66 | }; | 65 | }; |
67 | 66 | ||
68 | static int lm77_attach_adapter(struct i2c_adapter *adapter); | 67 | static int lm77_probe(struct i2c_client *client, |
69 | static int lm77_detect(struct i2c_adapter *adapter, int address, int kind); | 68 | const struct i2c_device_id *id); |
69 | static int lm77_detect(struct i2c_client *client, int kind, | ||
70 | struct i2c_board_info *info); | ||
70 | static void lm77_init_client(struct i2c_client *client); | 71 | static void lm77_init_client(struct i2c_client *client); |
71 | static int lm77_detach_client(struct i2c_client *client); | 72 | static int lm77_remove(struct i2c_client *client); |
72 | static u16 lm77_read_value(struct i2c_client *client, u8 reg); | 73 | static u16 lm77_read_value(struct i2c_client *client, u8 reg); |
73 | static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value); | 74 | static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value); |
74 | 75 | ||
75 | static struct lm77_data *lm77_update_device(struct device *dev); | 76 | static struct lm77_data *lm77_update_device(struct device *dev); |
76 | 77 | ||
77 | 78 | ||
79 | static const struct i2c_device_id lm77_id[] = { | ||
80 | { "lm77", lm77 }, | ||
81 | { } | ||
82 | }; | ||
83 | MODULE_DEVICE_TABLE(i2c, lm77_id); | ||
84 | |||
78 | /* This is the driver that will be inserted */ | 85 | /* This is the driver that will be inserted */ |
79 | static struct i2c_driver lm77_driver = { | 86 | static struct i2c_driver lm77_driver = { |
87 | .class = I2C_CLASS_HWMON, | ||
80 | .driver = { | 88 | .driver = { |
81 | .name = "lm77", | 89 | .name = "lm77", |
82 | }, | 90 | }, |
83 | .attach_adapter = lm77_attach_adapter, | 91 | .probe = lm77_probe, |
84 | .detach_client = lm77_detach_client, | 92 | .remove = lm77_remove, |
93 | .id_table = lm77_id, | ||
94 | .detect = lm77_detect, | ||
95 | .address_data = &addr_data, | ||
85 | }; | 96 | }; |
86 | 97 | ||
87 | /* straight from the datasheet */ | 98 | /* straight from the datasheet */ |
@@ -215,13 +226,6 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); | |||
215 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 226 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
216 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); | 227 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); |
217 | 228 | ||
218 | static int lm77_attach_adapter(struct i2c_adapter *adapter) | ||
219 | { | ||
220 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
221 | return 0; | ||
222 | return i2c_probe(adapter, &addr_data, lm77_detect); | ||
223 | } | ||
224 | |||
225 | static struct attribute *lm77_attributes[] = { | 229 | static struct attribute *lm77_attributes[] = { |
226 | &dev_attr_temp1_input.attr, | 230 | &dev_attr_temp1_input.attr, |
227 | &dev_attr_temp1_crit.attr, | 231 | &dev_attr_temp1_crit.attr, |
@@ -240,32 +244,15 @@ static const struct attribute_group lm77_group = { | |||
240 | .attrs = lm77_attributes, | 244 | .attrs = lm77_attributes, |
241 | }; | 245 | }; |
242 | 246 | ||
243 | /* This function is called by i2c_probe */ | 247 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
244 | static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | 248 | static int lm77_detect(struct i2c_client *new_client, int kind, |
249 | struct i2c_board_info *info) | ||
245 | { | 250 | { |
246 | struct i2c_client *new_client; | 251 | struct i2c_adapter *adapter = new_client->adapter; |
247 | struct lm77_data *data; | ||
248 | int err = 0; | ||
249 | const char *name = ""; | ||
250 | 252 | ||
251 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 253 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
252 | I2C_FUNC_SMBUS_WORD_DATA)) | 254 | I2C_FUNC_SMBUS_WORD_DATA)) |
253 | goto exit; | 255 | return -ENODEV; |
254 | |||
255 | /* OK. For now, we presume we have a valid client. We now create the | ||
256 | client structure, even though we cannot fill it completely yet. | ||
257 | But it allows us to access lm77_{read,write}_value. */ | ||
258 | if (!(data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL))) { | ||
259 | err = -ENOMEM; | ||
260 | goto exit; | ||
261 | } | ||
262 | |||
263 | new_client = &data->client; | ||
264 | i2c_set_clientdata(new_client, data); | ||
265 | new_client->addr = address; | ||
266 | new_client->adapter = adapter; | ||
267 | new_client->driver = &lm77_driver; | ||
268 | new_client->flags = 0; | ||
269 | 256 | ||
270 | /* Here comes the remaining detection. Since the LM77 has no | 257 | /* Here comes the remaining detection. Since the LM77 has no |
271 | register dedicated to identification, we have to rely on the | 258 | register dedicated to identification, we have to rely on the |
@@ -294,7 +281,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
294 | || i2c_smbus_read_word_data(new_client, i + 3) != crit | 281 | || i2c_smbus_read_word_data(new_client, i + 3) != crit |
295 | || i2c_smbus_read_word_data(new_client, i + 4) != min | 282 | || i2c_smbus_read_word_data(new_client, i + 4) != min |
296 | || i2c_smbus_read_word_data(new_client, i + 5) != max) | 283 | || i2c_smbus_read_word_data(new_client, i + 5) != max) |
297 | goto exit_free; | 284 | return -ENODEV; |
298 | 285 | ||
299 | /* sign bits */ | 286 | /* sign bits */ |
300 | if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0) | 287 | if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0) |
@@ -302,51 +289,55 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
302 | || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0) | 289 | || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0) |
303 | || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0) | 290 | || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0) |
304 | || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0)) | 291 | || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0)) |
305 | goto exit_free; | 292 | return -ENODEV; |
306 | 293 | ||
307 | /* unused bits */ | 294 | /* unused bits */ |
308 | if (conf & 0xe0) | 295 | if (conf & 0xe0) |
309 | goto exit_free; | 296 | return -ENODEV; |
310 | 297 | ||
311 | /* 0x06 and 0x07 return the last read value */ | 298 | /* 0x06 and 0x07 return the last read value */ |
312 | cur = i2c_smbus_read_word_data(new_client, 0); | 299 | cur = i2c_smbus_read_word_data(new_client, 0); |
313 | if (i2c_smbus_read_word_data(new_client, 6) != cur | 300 | if (i2c_smbus_read_word_data(new_client, 6) != cur |
314 | || i2c_smbus_read_word_data(new_client, 7) != cur) | 301 | || i2c_smbus_read_word_data(new_client, 7) != cur) |
315 | goto exit_free; | 302 | return -ENODEV; |
316 | hyst = i2c_smbus_read_word_data(new_client, 2); | 303 | hyst = i2c_smbus_read_word_data(new_client, 2); |
317 | if (i2c_smbus_read_word_data(new_client, 6) != hyst | 304 | if (i2c_smbus_read_word_data(new_client, 6) != hyst |
318 | || i2c_smbus_read_word_data(new_client, 7) != hyst) | 305 | || i2c_smbus_read_word_data(new_client, 7) != hyst) |
319 | goto exit_free; | 306 | return -ENODEV; |
320 | min = i2c_smbus_read_word_data(new_client, 4); | 307 | min = i2c_smbus_read_word_data(new_client, 4); |
321 | if (i2c_smbus_read_word_data(new_client, 6) != min | 308 | if (i2c_smbus_read_word_data(new_client, 6) != min |
322 | || i2c_smbus_read_word_data(new_client, 7) != min) | 309 | || i2c_smbus_read_word_data(new_client, 7) != min) |
323 | goto exit_free; | 310 | return -ENODEV; |
324 | 311 | ||
325 | } | 312 | } |
326 | 313 | ||
327 | /* Determine the chip type - only one kind supported! */ | 314 | strlcpy(info->type, "lm77", I2C_NAME_SIZE); |
328 | if (kind <= 0) | ||
329 | kind = lm77; | ||
330 | 315 | ||
331 | if (kind == lm77) { | 316 | return 0; |
332 | name = "lm77"; | 317 | } |
318 | |||
319 | static int lm77_probe(struct i2c_client *new_client, | ||
320 | const struct i2c_device_id *id) | ||
321 | { | ||
322 | struct lm77_data *data; | ||
323 | int err; | ||
324 | |||
325 | data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL); | ||
326 | if (!data) { | ||
327 | err = -ENOMEM; | ||
328 | goto exit; | ||
333 | } | 329 | } |
334 | 330 | ||
335 | /* Fill in the remaining client fields and put it into the global list */ | 331 | i2c_set_clientdata(new_client, data); |
336 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
337 | data->valid = 0; | 332 | data->valid = 0; |
338 | mutex_init(&data->update_lock); | 333 | mutex_init(&data->update_lock); |
339 | 334 | ||
340 | /* Tell the I2C layer a new client has arrived */ | ||
341 | if ((err = i2c_attach_client(new_client))) | ||
342 | goto exit_free; | ||
343 | |||
344 | /* Initialize the LM77 chip */ | 335 | /* Initialize the LM77 chip */ |
345 | lm77_init_client(new_client); | 336 | lm77_init_client(new_client); |
346 | 337 | ||
347 | /* Register sysfs hooks */ | 338 | /* Register sysfs hooks */ |
348 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) | 339 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) |
349 | goto exit_detach; | 340 | goto exit_free; |
350 | 341 | ||
351 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 342 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
352 | if (IS_ERR(data->hwmon_dev)) { | 343 | if (IS_ERR(data->hwmon_dev)) { |
@@ -358,20 +349,17 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
358 | 349 | ||
359 | exit_remove: | 350 | exit_remove: |
360 | sysfs_remove_group(&new_client->dev.kobj, &lm77_group); | 351 | sysfs_remove_group(&new_client->dev.kobj, &lm77_group); |
361 | exit_detach: | ||
362 | i2c_detach_client(new_client); | ||
363 | exit_free: | 352 | exit_free: |
364 | kfree(data); | 353 | kfree(data); |
365 | exit: | 354 | exit: |
366 | return err; | 355 | return err; |
367 | } | 356 | } |
368 | 357 | ||
369 | static int lm77_detach_client(struct i2c_client *client) | 358 | static int lm77_remove(struct i2c_client *client) |
370 | { | 359 | { |
371 | struct lm77_data *data = i2c_get_clientdata(client); | 360 | struct lm77_data *data = i2c_get_clientdata(client); |
372 | hwmon_device_unregister(data->hwmon_dev); | 361 | hwmon_device_unregister(data->hwmon_dev); |
373 | sysfs_remove_group(&client->dev.kobj, &lm77_group); | 362 | sysfs_remove_group(&client->dev.kobj, &lm77_group); |
374 | i2c_detach_client(client); | ||
375 | kfree(data); | 363 | kfree(data); |
376 | return 0; | 364 | return 0; |
377 | } | 365 | } |
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 26c91c9d4769..bcffc1899403 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -108,7 +108,6 @@ static inline long TEMP_FROM_REG(u16 temp) | |||
108 | */ | 108 | */ |
109 | 109 | ||
110 | struct lm80_data { | 110 | struct lm80_data { |
111 | struct i2c_client client; | ||
112 | struct device *hwmon_dev; | 111 | struct device *hwmon_dev; |
113 | struct mutex update_lock; | 112 | struct mutex update_lock; |
114 | char valid; /* !=0 if following fields are valid */ | 113 | char valid; /* !=0 if following fields are valid */ |
@@ -132,10 +131,12 @@ struct lm80_data { | |||
132 | * Functions declaration | 131 | * Functions declaration |
133 | */ | 132 | */ |
134 | 133 | ||
135 | static int lm80_attach_adapter(struct i2c_adapter *adapter); | 134 | static int lm80_probe(struct i2c_client *client, |
136 | static int lm80_detect(struct i2c_adapter *adapter, int address, int kind); | 135 | const struct i2c_device_id *id); |
136 | static int lm80_detect(struct i2c_client *client, int kind, | ||
137 | struct i2c_board_info *info); | ||
137 | static void lm80_init_client(struct i2c_client *client); | 138 | static void lm80_init_client(struct i2c_client *client); |
138 | static int lm80_detach_client(struct i2c_client *client); | 139 | static int lm80_remove(struct i2c_client *client); |
139 | static struct lm80_data *lm80_update_device(struct device *dev); | 140 | static struct lm80_data *lm80_update_device(struct device *dev); |
140 | static int lm80_read_value(struct i2c_client *client, u8 reg); | 141 | static int lm80_read_value(struct i2c_client *client, u8 reg); |
141 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); | 142 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); |
@@ -144,12 +145,22 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); | |||
144 | * Driver data (common to all clients) | 145 | * Driver data (common to all clients) |
145 | */ | 146 | */ |
146 | 147 | ||
148 | static const struct i2c_device_id lm80_id[] = { | ||
149 | { "lm80", lm80 }, | ||
150 | { } | ||
151 | }; | ||
152 | MODULE_DEVICE_TABLE(i2c, lm80_id); | ||
153 | |||
147 | static struct i2c_driver lm80_driver = { | 154 | static struct i2c_driver lm80_driver = { |
155 | .class = I2C_CLASS_HWMON, | ||
148 | .driver = { | 156 | .driver = { |
149 | .name = "lm80", | 157 | .name = "lm80", |
150 | }, | 158 | }, |
151 | .attach_adapter = lm80_attach_adapter, | 159 | .probe = lm80_probe, |
152 | .detach_client = lm80_detach_client, | 160 | .remove = lm80_remove, |
161 | .id_table = lm80_id, | ||
162 | .detect = lm80_detect, | ||
163 | .address_data = &addr_data, | ||
153 | }; | 164 | }; |
154 | 165 | ||
155 | /* | 166 | /* |
@@ -383,13 +394,6 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13); | |||
383 | * Real code | 394 | * Real code |
384 | */ | 395 | */ |
385 | 396 | ||
386 | static int lm80_attach_adapter(struct i2c_adapter *adapter) | ||
387 | { | ||
388 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
389 | return 0; | ||
390 | return i2c_probe(adapter, &addr_data, lm80_detect); | ||
391 | } | ||
392 | |||
393 | static struct attribute *lm80_attributes[] = { | 397 | static struct attribute *lm80_attributes[] = { |
394 | &sensor_dev_attr_in0_min.dev_attr.attr, | 398 | &sensor_dev_attr_in0_min.dev_attr.attr, |
395 | &sensor_dev_attr_in1_min.dev_attr.attr, | 399 | &sensor_dev_attr_in1_min.dev_attr.attr, |
@@ -442,53 +446,46 @@ static const struct attribute_group lm80_group = { | |||
442 | .attrs = lm80_attributes, | 446 | .attrs = lm80_attributes, |
443 | }; | 447 | }; |
444 | 448 | ||
445 | static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | 449 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
450 | static int lm80_detect(struct i2c_client *client, int kind, | ||
451 | struct i2c_board_info *info) | ||
446 | { | 452 | { |
453 | struct i2c_adapter *adapter = client->adapter; | ||
447 | int i, cur; | 454 | int i, cur; |
448 | struct i2c_client *client; | ||
449 | struct lm80_data *data; | ||
450 | int err = 0; | ||
451 | const char *name; | ||
452 | 455 | ||
453 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 456 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
454 | goto exit; | 457 | return -ENODEV; |
455 | |||
456 | /* OK. For now, we presume we have a valid client. We now create the | ||
457 | client structure, even though we cannot fill it completely yet. | ||
458 | But it allows us to access lm80_{read,write}_value. */ | ||
459 | if (!(data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL))) { | ||
460 | err = -ENOMEM; | ||
461 | goto exit; | ||
462 | } | ||
463 | |||
464 | client = &data->client; | ||
465 | i2c_set_clientdata(client, data); | ||
466 | client->addr = address; | ||
467 | client->adapter = adapter; | ||
468 | client->driver = &lm80_driver; | ||
469 | 458 | ||
470 | /* Now, we do the remaining detection. It is lousy. */ | 459 | /* Now, we do the remaining detection. It is lousy. */ |
471 | if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0) | 460 | if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0) |
472 | goto error_free; | 461 | return -ENODEV; |
473 | for (i = 0x2a; i <= 0x3d; i++) { | 462 | for (i = 0x2a; i <= 0x3d; i++) { |
474 | cur = i2c_smbus_read_byte_data(client, i); | 463 | cur = i2c_smbus_read_byte_data(client, i); |
475 | if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur) | 464 | if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur) |
476 | || (i2c_smbus_read_byte_data(client, i + 0x80) != cur) | 465 | || (i2c_smbus_read_byte_data(client, i + 0x80) != cur) |
477 | || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur)) | 466 | || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur)) |
478 | goto error_free; | 467 | return -ENODEV; |
479 | } | 468 | } |
480 | 469 | ||
481 | /* Determine the chip type - only one kind supported! */ | 470 | strlcpy(info->type, "lm80", I2C_NAME_SIZE); |
482 | kind = lm80; | ||
483 | name = "lm80"; | ||
484 | 471 | ||
485 | /* Fill in the remaining client fields */ | 472 | return 0; |
486 | strlcpy(client->name, name, I2C_NAME_SIZE); | 473 | } |
487 | mutex_init(&data->update_lock); | ||
488 | 474 | ||
489 | /* Tell the I2C layer a new client has arrived */ | 475 | static int lm80_probe(struct i2c_client *client, |
490 | if ((err = i2c_attach_client(client))) | 476 | const struct i2c_device_id *id) |
491 | goto error_free; | 477 | { |
478 | struct lm80_data *data; | ||
479 | int err; | ||
480 | |||
481 | data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL); | ||
482 | if (!data) { | ||
483 | err = -ENOMEM; | ||
484 | goto exit; | ||
485 | } | ||
486 | |||
487 | i2c_set_clientdata(client, data); | ||
488 | mutex_init(&data->update_lock); | ||
492 | 489 | ||
493 | /* Initialize the LM80 chip */ | 490 | /* Initialize the LM80 chip */ |
494 | lm80_init_client(client); | 491 | lm80_init_client(client); |
@@ -499,7 +496,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
499 | 496 | ||
500 | /* Register sysfs hooks */ | 497 | /* Register sysfs hooks */ |
501 | if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group))) | 498 | if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group))) |
502 | goto error_detach; | 499 | goto error_free; |
503 | 500 | ||
504 | data->hwmon_dev = hwmon_device_register(&client->dev); | 501 | data->hwmon_dev = hwmon_device_register(&client->dev); |
505 | if (IS_ERR(data->hwmon_dev)) { | 502 | if (IS_ERR(data->hwmon_dev)) { |
@@ -511,23 +508,18 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
511 | 508 | ||
512 | error_remove: | 509 | error_remove: |
513 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | 510 | sysfs_remove_group(&client->dev.kobj, &lm80_group); |
514 | error_detach: | ||
515 | i2c_detach_client(client); | ||
516 | error_free: | 511 | error_free: |
517 | kfree(data); | 512 | kfree(data); |
518 | exit: | 513 | exit: |
519 | return err; | 514 | return err; |
520 | } | 515 | } |
521 | 516 | ||
522 | static int lm80_detach_client(struct i2c_client *client) | 517 | static int lm80_remove(struct i2c_client *client) |
523 | { | 518 | { |
524 | struct lm80_data *data = i2c_get_clientdata(client); | 519 | struct lm80_data *data = i2c_get_clientdata(client); |
525 | int err; | ||
526 | 520 | ||
527 | hwmon_device_unregister(data->hwmon_dev); | 521 | hwmon_device_unregister(data->hwmon_dev); |
528 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | 522 | sysfs_remove_group(&client->dev.kobj, &lm80_group); |
529 | if ((err = i2c_detach_client(client))) | ||
530 | return err; | ||
531 | 523 | ||
532 | kfree(data); | 524 | kfree(data); |
533 | return 0; | 525 | return 0; |
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index 6a8642fa25fb..e59e2d1f080c 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | 3 | * monitoring |
4 | * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is | 6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is |
7 | * a sensor chip made by National Semiconductor. It reports up to four | 7 | * a sensor chip made by National Semiconductor. It reports up to four |
@@ -118,21 +118,34 @@ static const u8 LM83_REG_W_HIGH[] = { | |||
118 | * Functions declaration | 118 | * Functions declaration |
119 | */ | 119 | */ |
120 | 120 | ||
121 | static int lm83_attach_adapter(struct i2c_adapter *adapter); | 121 | static int lm83_detect(struct i2c_client *new_client, int kind, |
122 | static int lm83_detect(struct i2c_adapter *adapter, int address, int kind); | 122 | struct i2c_board_info *info); |
123 | static int lm83_detach_client(struct i2c_client *client); | 123 | static int lm83_probe(struct i2c_client *client, |
124 | const struct i2c_device_id *id); | ||
125 | static int lm83_remove(struct i2c_client *client); | ||
124 | static struct lm83_data *lm83_update_device(struct device *dev); | 126 | static struct lm83_data *lm83_update_device(struct device *dev); |
125 | 127 | ||
126 | /* | 128 | /* |
127 | * Driver data (common to all clients) | 129 | * Driver data (common to all clients) |
128 | */ | 130 | */ |
129 | 131 | ||
132 | static const struct i2c_device_id lm83_id[] = { | ||
133 | { "lm83", lm83 }, | ||
134 | { "lm82", lm82 }, | ||
135 | { } | ||
136 | }; | ||
137 | MODULE_DEVICE_TABLE(i2c, lm83_id); | ||
138 | |||
130 | static struct i2c_driver lm83_driver = { | 139 | static struct i2c_driver lm83_driver = { |
140 | .class = I2C_CLASS_HWMON, | ||
131 | .driver = { | 141 | .driver = { |
132 | .name = "lm83", | 142 | .name = "lm83", |
133 | }, | 143 | }, |
134 | .attach_adapter = lm83_attach_adapter, | 144 | .probe = lm83_probe, |
135 | .detach_client = lm83_detach_client, | 145 | .remove = lm83_remove, |
146 | .id_table = lm83_id, | ||
147 | .detect = lm83_detect, | ||
148 | .address_data = &addr_data, | ||
136 | }; | 149 | }; |
137 | 150 | ||
138 | /* | 151 | /* |
@@ -140,7 +153,6 @@ static struct i2c_driver lm83_driver = { | |||
140 | */ | 153 | */ |
141 | 154 | ||
142 | struct lm83_data { | 155 | struct lm83_data { |
143 | struct i2c_client client; | ||
144 | struct device *hwmon_dev; | 156 | struct device *hwmon_dev; |
145 | struct mutex update_lock; | 157 | struct mutex update_lock; |
146 | char valid; /* zero until following fields are valid */ | 158 | char valid; /* zero until following fields are valid */ |
@@ -278,40 +290,15 @@ static const struct attribute_group lm83_group_opt = { | |||
278 | * Real code | 290 | * Real code |
279 | */ | 291 | */ |
280 | 292 | ||
281 | static int lm83_attach_adapter(struct i2c_adapter *adapter) | 293 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
294 | static int lm83_detect(struct i2c_client *new_client, int kind, | ||
295 | struct i2c_board_info *info) | ||
282 | { | 296 | { |
283 | if (!(adapter->class & I2C_CLASS_HWMON)) | 297 | struct i2c_adapter *adapter = new_client->adapter; |
284 | return 0; | ||
285 | return i2c_probe(adapter, &addr_data, lm83_detect); | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * The following function does more than just detection. If detection | ||
290 | * succeeds, it also registers the new chip. | ||
291 | */ | ||
292 | static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | ||
293 | { | ||
294 | struct i2c_client *new_client; | ||
295 | struct lm83_data *data; | ||
296 | int err = 0; | ||
297 | const char *name = ""; | 298 | const char *name = ""; |
298 | 299 | ||
299 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 300 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
300 | goto exit; | 301 | return -ENODEV; |
301 | |||
302 | if (!(data = kzalloc(sizeof(struct lm83_data), GFP_KERNEL))) { | ||
303 | err = -ENOMEM; | ||
304 | goto exit; | ||
305 | } | ||
306 | |||
307 | /* The common I2C client data is placed right after the | ||
308 | * LM83-specific data. */ | ||
309 | new_client = &data->client; | ||
310 | i2c_set_clientdata(new_client, data); | ||
311 | new_client->addr = address; | ||
312 | new_client->adapter = adapter; | ||
313 | new_client->driver = &lm83_driver; | ||
314 | new_client->flags = 0; | ||
315 | 302 | ||
316 | /* Now we do the detection and identification. A negative kind | 303 | /* Now we do the detection and identification. A negative kind |
317 | * means that the driver was loaded with no force parameter | 304 | * means that the driver was loaded with no force parameter |
@@ -335,8 +322,9 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
335 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) | 322 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) |
336 | & 0x41) != 0x00)) { | 323 | & 0x41) != 0x00)) { |
337 | dev_dbg(&adapter->dev, | 324 | dev_dbg(&adapter->dev, |
338 | "LM83 detection failed at 0x%02x.\n", address); | 325 | "LM83 detection failed at 0x%02x.\n", |
339 | goto exit_free; | 326 | new_client->addr); |
327 | return -ENODEV; | ||
340 | } | 328 | } |
341 | } | 329 | } |
342 | 330 | ||
@@ -361,7 +349,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
361 | dev_info(&adapter->dev, | 349 | dev_info(&adapter->dev, |
362 | "Unsupported chip (man_id=0x%02X, " | 350 | "Unsupported chip (man_id=0x%02X, " |
363 | "chip_id=0x%02X).\n", man_id, chip_id); | 351 | "chip_id=0x%02X).\n", man_id, chip_id); |
364 | goto exit_free; | 352 | return -ENODEV; |
365 | } | 353 | } |
366 | } | 354 | } |
367 | 355 | ||
@@ -372,15 +360,27 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
372 | name = "lm82"; | 360 | name = "lm82"; |
373 | } | 361 | } |
374 | 362 | ||
375 | /* We can fill in the remaining client fields */ | 363 | strlcpy(info->type, name, I2C_NAME_SIZE); |
376 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 364 | |
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static int lm83_probe(struct i2c_client *new_client, | ||
369 | const struct i2c_device_id *id) | ||
370 | { | ||
371 | struct lm83_data *data; | ||
372 | int err; | ||
373 | |||
374 | data = kzalloc(sizeof(struct lm83_data), GFP_KERNEL); | ||
375 | if (!data) { | ||
376 | err = -ENOMEM; | ||
377 | goto exit; | ||
378 | } | ||
379 | |||
380 | i2c_set_clientdata(new_client, data); | ||
377 | data->valid = 0; | 381 | data->valid = 0; |
378 | mutex_init(&data->update_lock); | 382 | mutex_init(&data->update_lock); |
379 | 383 | ||
380 | /* Tell the I2C layer a new client has arrived */ | ||
381 | if ((err = i2c_attach_client(new_client))) | ||
382 | goto exit_free; | ||
383 | |||
384 | /* | 384 | /* |
385 | * Register sysfs hooks | 385 | * Register sysfs hooks |
386 | * The LM82 can only monitor one external diode which is | 386 | * The LM82 can only monitor one external diode which is |
@@ -389,9 +389,9 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
389 | */ | 389 | */ |
390 | 390 | ||
391 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) | 391 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) |
392 | goto exit_detach; | 392 | goto exit_free; |
393 | 393 | ||
394 | if (kind == lm83) { | 394 | if (id->driver_data == lm83) { |
395 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 395 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
396 | &lm83_group_opt))) | 396 | &lm83_group_opt))) |
397 | goto exit_remove_files; | 397 | goto exit_remove_files; |
@@ -408,26 +408,20 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
408 | exit_remove_files: | 408 | exit_remove_files: |
409 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); | 409 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); |
410 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); | 410 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); |
411 | exit_detach: | ||
412 | i2c_detach_client(new_client); | ||
413 | exit_free: | 411 | exit_free: |
414 | kfree(data); | 412 | kfree(data); |
415 | exit: | 413 | exit: |
416 | return err; | 414 | return err; |
417 | } | 415 | } |
418 | 416 | ||
419 | static int lm83_detach_client(struct i2c_client *client) | 417 | static int lm83_remove(struct i2c_client *client) |
420 | { | 418 | { |
421 | struct lm83_data *data = i2c_get_clientdata(client); | 419 | struct lm83_data *data = i2c_get_clientdata(client); |
422 | int err; | ||
423 | 420 | ||
424 | hwmon_device_unregister(data->hwmon_dev); | 421 | hwmon_device_unregister(data->hwmon_dev); |
425 | sysfs_remove_group(&client->dev.kobj, &lm83_group); | 422 | sysfs_remove_group(&client->dev.kobj, &lm83_group); |
426 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); | 423 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); |
427 | 424 | ||
428 | if ((err = i2c_detach_client(client))) | ||
429 | return err; | ||
430 | |||
431 | kfree(data); | 425 | kfree(data); |
432 | return 0; | 426 | return 0; |
433 | } | 427 | } |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 182fe6a5605f..ee5eca1c1921 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -192,23 +192,20 @@ static int RANGE_TO_REG( int range ) | |||
192 | { | 192 | { |
193 | int i; | 193 | int i; |
194 | 194 | ||
195 | if ( range < lm85_range_map[0] ) { | 195 | if (range >= lm85_range_map[15]) |
196 | return 0 ; | ||
197 | } else if ( range > lm85_range_map[15] ) { | ||
198 | return 15 ; | 196 | return 15 ; |
199 | } else { /* find closest match */ | 197 | |
200 | for ( i = 14 ; i >= 0 ; --i ) { | 198 | /* Find the closest match */ |
201 | if ( range > lm85_range_map[i] ) { /* range bracketed */ | 199 | for (i = 14; i >= 0; --i) { |
202 | if ((lm85_range_map[i+1] - range) < | 200 | if (range >= lm85_range_map[i]) { |
203 | (range - lm85_range_map[i])) { | 201 | if ((lm85_range_map[i + 1] - range) < |
204 | i++; | 202 | (range - lm85_range_map[i])) |
205 | break; | 203 | return i + 1; |
206 | } | 204 | return i; |
207 | break; | ||
208 | } | ||
209 | } | 205 | } |
210 | } | 206 | } |
211 | return( i & 0x0f ); | 207 | |
208 | return 0; | ||
212 | } | 209 | } |
213 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) | 210 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) |
214 | 211 | ||
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index e1c183f0aae0..21970f0d53a1 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * Philip Edelbrock <phil@netroedge.com> | 5 | * Philip Edelbrock <phil@netroedge.com> |
6 | * Stephen Rousset <stephen.rousset@rocketlogix.com> | 6 | * Stephen Rousset <stephen.rousset@rocketlogix.com> |
7 | * Dan Eaton <dan.eaton@rocketlogix.com> | 7 | * Dan Eaton <dan.eaton@rocketlogix.com> |
8 | * Copyright (C) 2004,2007 Jean Delvare <khali@linux-fr.org> | 8 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
9 | * | 9 | * |
10 | * Original port to Linux 2.6 by Jeff Oliver. | 10 | * Original port to Linux 2.6 by Jeff Oliver. |
11 | * | 11 | * |
@@ -157,22 +157,35 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C }; | |||
157 | * Functions declaration | 157 | * Functions declaration |
158 | */ | 158 | */ |
159 | 159 | ||
160 | static int lm87_attach_adapter(struct i2c_adapter *adapter); | 160 | static int lm87_probe(struct i2c_client *client, |
161 | static int lm87_detect(struct i2c_adapter *adapter, int address, int kind); | 161 | const struct i2c_device_id *id); |
162 | static int lm87_detect(struct i2c_client *new_client, int kind, | ||
163 | struct i2c_board_info *info); | ||
162 | static void lm87_init_client(struct i2c_client *client); | 164 | static void lm87_init_client(struct i2c_client *client); |
163 | static int lm87_detach_client(struct i2c_client *client); | 165 | static int lm87_remove(struct i2c_client *client); |
164 | static struct lm87_data *lm87_update_device(struct device *dev); | 166 | static struct lm87_data *lm87_update_device(struct device *dev); |
165 | 167 | ||
166 | /* | 168 | /* |
167 | * Driver data (common to all clients) | 169 | * Driver data (common to all clients) |
168 | */ | 170 | */ |
169 | 171 | ||
172 | static const struct i2c_device_id lm87_id[] = { | ||
173 | { "lm87", lm87 }, | ||
174 | { "adm1024", adm1024 }, | ||
175 | { } | ||
176 | }; | ||
177 | MODULE_DEVICE_TABLE(i2c, lm87_id); | ||
178 | |||
170 | static struct i2c_driver lm87_driver = { | 179 | static struct i2c_driver lm87_driver = { |
180 | .class = I2C_CLASS_HWMON, | ||
171 | .driver = { | 181 | .driver = { |
172 | .name = "lm87", | 182 | .name = "lm87", |
173 | }, | 183 | }, |
174 | .attach_adapter = lm87_attach_adapter, | 184 | .probe = lm87_probe, |
175 | .detach_client = lm87_detach_client, | 185 | .remove = lm87_remove, |
186 | .id_table = lm87_id, | ||
187 | .detect = lm87_detect, | ||
188 | .address_data = &addr_data, | ||
176 | }; | 189 | }; |
177 | 190 | ||
178 | /* | 191 | /* |
@@ -180,7 +193,6 @@ static struct i2c_driver lm87_driver = { | |||
180 | */ | 193 | */ |
181 | 194 | ||
182 | struct lm87_data { | 195 | struct lm87_data { |
183 | struct i2c_client client; | ||
184 | struct device *hwmon_dev; | 196 | struct device *hwmon_dev; |
185 | struct mutex update_lock; | 197 | struct mutex update_lock; |
186 | char valid; /* zero until following fields are valid */ | 198 | char valid; /* zero until following fields are valid */ |
@@ -562,13 +574,6 @@ static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); | |||
562 | * Real code | 574 | * Real code |
563 | */ | 575 | */ |
564 | 576 | ||
565 | static int lm87_attach_adapter(struct i2c_adapter *adapter) | ||
566 | { | ||
567 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
568 | return 0; | ||
569 | return i2c_probe(adapter, &addr_data, lm87_detect); | ||
570 | } | ||
571 | |||
572 | static struct attribute *lm87_attributes[] = { | 577 | static struct attribute *lm87_attributes[] = { |
573 | &dev_attr_in1_input.attr, | 578 | &dev_attr_in1_input.attr, |
574 | &dev_attr_in1_min.attr, | 579 | &dev_attr_in1_min.attr, |
@@ -656,33 +661,15 @@ static const struct attribute_group lm87_group_opt = { | |||
656 | .attrs = lm87_attributes_opt, | 661 | .attrs = lm87_attributes_opt, |
657 | }; | 662 | }; |
658 | 663 | ||
659 | /* | 664 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
660 | * The following function does more than just detection. If detection | 665 | static int lm87_detect(struct i2c_client *new_client, int kind, |
661 | * succeeds, it also registers the new chip. | 666 | struct i2c_board_info *info) |
662 | */ | ||
663 | static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | ||
664 | { | 667 | { |
665 | struct i2c_client *new_client; | 668 | struct i2c_adapter *adapter = new_client->adapter; |
666 | struct lm87_data *data; | ||
667 | int err = 0; | ||
668 | static const char *names[] = { "lm87", "adm1024" }; | 669 | static const char *names[] = { "lm87", "adm1024" }; |
669 | 670 | ||
670 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 671 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
671 | goto exit; | 672 | return -ENODEV; |
672 | |||
673 | if (!(data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL))) { | ||
674 | err = -ENOMEM; | ||
675 | goto exit; | ||
676 | } | ||
677 | |||
678 | /* The common I2C client data is placed right before the | ||
679 | LM87-specific data. */ | ||
680 | new_client = &data->client; | ||
681 | i2c_set_clientdata(new_client, data); | ||
682 | new_client->addr = address; | ||
683 | new_client->adapter = adapter; | ||
684 | new_client->driver = &lm87_driver; | ||
685 | new_client->flags = 0; | ||
686 | 673 | ||
687 | /* Default to an LM87 if forced */ | 674 | /* Default to an LM87 if forced */ |
688 | if (kind == 0) | 675 | if (kind == 0) |
@@ -704,20 +691,32 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
704 | || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { | 691 | || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { |
705 | dev_dbg(&adapter->dev, | 692 | dev_dbg(&adapter->dev, |
706 | "LM87 detection failed at 0x%02x.\n", | 693 | "LM87 detection failed at 0x%02x.\n", |
707 | address); | 694 | new_client->addr); |
708 | goto exit_free; | 695 | return -ENODEV; |
709 | } | 696 | } |
710 | } | 697 | } |
711 | 698 | ||
712 | /* We can fill in the remaining client fields */ | 699 | strlcpy(info->type, names[kind - 1], I2C_NAME_SIZE); |
713 | strlcpy(new_client->name, names[kind - 1], I2C_NAME_SIZE); | 700 | |
701 | return 0; | ||
702 | } | ||
703 | |||
704 | static int lm87_probe(struct i2c_client *new_client, | ||
705 | const struct i2c_device_id *id) | ||
706 | { | ||
707 | struct lm87_data *data; | ||
708 | int err; | ||
709 | |||
710 | data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL); | ||
711 | if (!data) { | ||
712 | err = -ENOMEM; | ||
713 | goto exit; | ||
714 | } | ||
715 | |||
716 | i2c_set_clientdata(new_client, data); | ||
714 | data->valid = 0; | 717 | data->valid = 0; |
715 | mutex_init(&data->update_lock); | 718 | mutex_init(&data->update_lock); |
716 | 719 | ||
717 | /* Tell the I2C layer a new client has arrived */ | ||
718 | if ((err = i2c_attach_client(new_client))) | ||
719 | goto exit_free; | ||
720 | |||
721 | /* Initialize the LM87 chip */ | 720 | /* Initialize the LM87 chip */ |
722 | lm87_init_client(new_client); | 721 | lm87_init_client(new_client); |
723 | 722 | ||
@@ -732,7 +731,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
732 | 731 | ||
733 | /* Register sysfs hooks */ | 732 | /* Register sysfs hooks */ |
734 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) | 733 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) |
735 | goto exit_detach; | 734 | goto exit_free; |
736 | 735 | ||
737 | if (data->channel & CHAN_NO_FAN(0)) { | 736 | if (data->channel & CHAN_NO_FAN(0)) { |
738 | if ((err = device_create_file(&new_client->dev, | 737 | if ((err = device_create_file(&new_client->dev, |
@@ -832,8 +831,6 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
832 | exit_remove: | 831 | exit_remove: |
833 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group); | 832 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group); |
834 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); | 833 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); |
835 | exit_detach: | ||
836 | i2c_detach_client(new_client); | ||
837 | exit_free: | 834 | exit_free: |
838 | kfree(data); | 835 | kfree(data); |
839 | exit: | 836 | exit: |
@@ -877,18 +874,14 @@ static void lm87_init_client(struct i2c_client *client) | |||
877 | } | 874 | } |
878 | } | 875 | } |
879 | 876 | ||
880 | static int lm87_detach_client(struct i2c_client *client) | 877 | static int lm87_remove(struct i2c_client *client) |
881 | { | 878 | { |
882 | struct lm87_data *data = i2c_get_clientdata(client); | 879 | struct lm87_data *data = i2c_get_clientdata(client); |
883 | int err; | ||
884 | 880 | ||
885 | hwmon_device_unregister(data->hwmon_dev); | 881 | hwmon_device_unregister(data->hwmon_dev); |
886 | sysfs_remove_group(&client->dev.kobj, &lm87_group); | 882 | sysfs_remove_group(&client->dev.kobj, &lm87_group); |
887 | sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); | 883 | sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); |
888 | 884 | ||
889 | if ((err = i2c_detach_client(client))) | ||
890 | return err; | ||
891 | |||
892 | kfree(data); | 885 | kfree(data); |
893 | return 0; | 886 | return 0; |
894 | } | 887 | } |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index d1a3da3dd8e0..c24fe36ac787 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -187,23 +187,44 @@ I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680); | |||
187 | * Functions declaration | 187 | * Functions declaration |
188 | */ | 188 | */ |
189 | 189 | ||
190 | static int lm90_attach_adapter(struct i2c_adapter *adapter); | 190 | static int lm90_detect(struct i2c_client *client, int kind, |
191 | static int lm90_detect(struct i2c_adapter *adapter, int address, | 191 | struct i2c_board_info *info); |
192 | int kind); | 192 | static int lm90_probe(struct i2c_client *client, |
193 | const struct i2c_device_id *id); | ||
193 | static void lm90_init_client(struct i2c_client *client); | 194 | static void lm90_init_client(struct i2c_client *client); |
194 | static int lm90_detach_client(struct i2c_client *client); | 195 | static int lm90_remove(struct i2c_client *client); |
195 | static struct lm90_data *lm90_update_device(struct device *dev); | 196 | static struct lm90_data *lm90_update_device(struct device *dev); |
196 | 197 | ||
197 | /* | 198 | /* |
198 | * Driver data (common to all clients) | 199 | * Driver data (common to all clients) |
199 | */ | 200 | */ |
200 | 201 | ||
202 | static const struct i2c_device_id lm90_id[] = { | ||
203 | { "adm1032", adm1032 }, | ||
204 | { "adt7461", adt7461 }, | ||
205 | { "lm90", lm90 }, | ||
206 | { "lm86", lm86 }, | ||
207 | { "lm89", lm99 }, | ||
208 | { "lm99", lm99 }, /* Missing temperature offset */ | ||
209 | { "max6657", max6657 }, | ||
210 | { "max6658", max6657 }, | ||
211 | { "max6659", max6657 }, | ||
212 | { "max6680", max6680 }, | ||
213 | { "max6681", max6680 }, | ||
214 | { } | ||
215 | }; | ||
216 | MODULE_DEVICE_TABLE(i2c, lm90_id); | ||
217 | |||
201 | static struct i2c_driver lm90_driver = { | 218 | static struct i2c_driver lm90_driver = { |
219 | .class = I2C_CLASS_HWMON, | ||
202 | .driver = { | 220 | .driver = { |
203 | .name = "lm90", | 221 | .name = "lm90", |
204 | }, | 222 | }, |
205 | .attach_adapter = lm90_attach_adapter, | 223 | .probe = lm90_probe, |
206 | .detach_client = lm90_detach_client, | 224 | .remove = lm90_remove, |
225 | .id_table = lm90_id, | ||
226 | .detect = lm90_detect, | ||
227 | .address_data = &addr_data, | ||
207 | }; | 228 | }; |
208 | 229 | ||
209 | /* | 230 | /* |
@@ -211,7 +232,6 @@ static struct i2c_driver lm90_driver = { | |||
211 | */ | 232 | */ |
212 | 233 | ||
213 | struct lm90_data { | 234 | struct lm90_data { |
214 | struct i2c_client client; | ||
215 | struct device *hwmon_dev; | 235 | struct device *hwmon_dev; |
216 | struct mutex update_lock; | 236 | struct mutex update_lock; |
217 | char valid; /* zero until following fields are valid */ | 237 | char valid; /* zero until following fields are valid */ |
@@ -477,40 +497,16 @@ static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value) | |||
477 | return 0; | 497 | return 0; |
478 | } | 498 | } |
479 | 499 | ||
480 | static int lm90_attach_adapter(struct i2c_adapter *adapter) | 500 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
481 | { | 501 | static int lm90_detect(struct i2c_client *new_client, int kind, |
482 | if (!(adapter->class & I2C_CLASS_HWMON)) | 502 | struct i2c_board_info *info) |
483 | return 0; | ||
484 | return i2c_probe(adapter, &addr_data, lm90_detect); | ||
485 | } | ||
486 | |||
487 | /* | ||
488 | * The following function does more than just detection. If detection | ||
489 | * succeeds, it also registers the new chip. | ||
490 | */ | ||
491 | static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | ||
492 | { | 503 | { |
493 | struct i2c_client *new_client; | 504 | struct i2c_adapter *adapter = new_client->adapter; |
494 | struct lm90_data *data; | 505 | int address = new_client->addr; |
495 | int err = 0; | ||
496 | const char *name = ""; | 506 | const char *name = ""; |
497 | 507 | ||
498 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 508 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
499 | goto exit; | 509 | return -ENODEV; |
500 | |||
501 | if (!(data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL))) { | ||
502 | err = -ENOMEM; | ||
503 | goto exit; | ||
504 | } | ||
505 | |||
506 | /* The common I2C client data is placed right before the | ||
507 | LM90-specific data. */ | ||
508 | new_client = &data->client; | ||
509 | i2c_set_clientdata(new_client, data); | ||
510 | new_client->addr = address; | ||
511 | new_client->adapter = adapter; | ||
512 | new_client->driver = &lm90_driver; | ||
513 | new_client->flags = 0; | ||
514 | 510 | ||
515 | /* | 511 | /* |
516 | * Now we do the remaining detection. A negative kind means that | 512 | * Now we do the remaining detection. A negative kind means that |
@@ -538,7 +534,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
538 | LM90_REG_R_CONFIG1)) < 0 | 534 | LM90_REG_R_CONFIG1)) < 0 |
539 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, | 535 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, |
540 | LM90_REG_R_CONVRATE)) < 0) | 536 | LM90_REG_R_CONVRATE)) < 0) |
541 | goto exit_free; | 537 | return -ENODEV; |
542 | 538 | ||
543 | if ((address == 0x4C || address == 0x4D) | 539 | if ((address == 0x4C || address == 0x4D) |
544 | && man_id == 0x01) { /* National Semiconductor */ | 540 | && man_id == 0x01) { /* National Semiconductor */ |
@@ -546,7 +542,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
546 | 542 | ||
547 | if ((reg_config2 = i2c_smbus_read_byte_data(new_client, | 543 | if ((reg_config2 = i2c_smbus_read_byte_data(new_client, |
548 | LM90_REG_R_CONFIG2)) < 0) | 544 | LM90_REG_R_CONFIG2)) < 0) |
549 | goto exit_free; | 545 | return -ENODEV; |
550 | 546 | ||
551 | if ((reg_config1 & 0x2A) == 0x00 | 547 | if ((reg_config1 & 0x2A) == 0x00 |
552 | && (reg_config2 & 0xF8) == 0x00 | 548 | && (reg_config2 & 0xF8) == 0x00 |
@@ -610,10 +606,11 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
610 | dev_info(&adapter->dev, | 606 | dev_info(&adapter->dev, |
611 | "Unsupported chip (man_id=0x%02X, " | 607 | "Unsupported chip (man_id=0x%02X, " |
612 | "chip_id=0x%02X).\n", man_id, chip_id); | 608 | "chip_id=0x%02X).\n", man_id, chip_id); |
613 | goto exit_free; | 609 | return -ENODEV; |
614 | } | 610 | } |
615 | } | 611 | } |
616 | 612 | ||
613 | /* Fill the i2c board info */ | ||
617 | if (kind == lm90) { | 614 | if (kind == lm90) { |
618 | name = "lm90"; | 615 | name = "lm90"; |
619 | } else if (kind == adm1032) { | 616 | } else if (kind == adm1032) { |
@@ -621,7 +618,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
621 | /* The ADM1032 supports PEC, but only if combined | 618 | /* The ADM1032 supports PEC, but only if combined |
622 | transactions are not used. */ | 619 | transactions are not used. */ |
623 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 620 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
624 | new_client->flags |= I2C_CLIENT_PEC; | 621 | info->flags |= I2C_CLIENT_PEC; |
625 | } else if (kind == lm99) { | 622 | } else if (kind == lm99) { |
626 | name = "lm99"; | 623 | name = "lm99"; |
627 | } else if (kind == lm86) { | 624 | } else if (kind == lm86) { |
@@ -633,23 +630,39 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
633 | } else if (kind == adt7461) { | 630 | } else if (kind == adt7461) { |
634 | name = "adt7461"; | 631 | name = "adt7461"; |
635 | } | 632 | } |
633 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
634 | |||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static int lm90_probe(struct i2c_client *new_client, | ||
639 | const struct i2c_device_id *id) | ||
640 | { | ||
641 | struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent); | ||
642 | struct lm90_data *data; | ||
643 | int err; | ||
636 | 644 | ||
637 | /* We can fill in the remaining client fields */ | 645 | data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL); |
638 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 646 | if (!data) { |
639 | data->valid = 0; | 647 | err = -ENOMEM; |
640 | data->kind = kind; | 648 | goto exit; |
649 | } | ||
650 | i2c_set_clientdata(new_client, data); | ||
641 | mutex_init(&data->update_lock); | 651 | mutex_init(&data->update_lock); |
642 | 652 | ||
643 | /* Tell the I2C layer a new client has arrived */ | 653 | /* Set the device type */ |
644 | if ((err = i2c_attach_client(new_client))) | 654 | data->kind = id->driver_data; |
645 | goto exit_free; | 655 | if (data->kind == adm1032) { |
656 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | ||
657 | new_client->flags &= ~I2C_CLIENT_PEC; | ||
658 | } | ||
646 | 659 | ||
647 | /* Initialize the LM90 chip */ | 660 | /* Initialize the LM90 chip */ |
648 | lm90_init_client(new_client); | 661 | lm90_init_client(new_client); |
649 | 662 | ||
650 | /* Register sysfs hooks */ | 663 | /* Register sysfs hooks */ |
651 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) | 664 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) |
652 | goto exit_detach; | 665 | goto exit_free; |
653 | if (new_client->flags & I2C_CLIENT_PEC) { | 666 | if (new_client->flags & I2C_CLIENT_PEC) { |
654 | if ((err = device_create_file(&new_client->dev, | 667 | if ((err = device_create_file(&new_client->dev, |
655 | &dev_attr_pec))) | 668 | &dev_attr_pec))) |
@@ -672,8 +685,6 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
672 | exit_remove_files: | 685 | exit_remove_files: |
673 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); | 686 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); |
674 | device_remove_file(&new_client->dev, &dev_attr_pec); | 687 | device_remove_file(&new_client->dev, &dev_attr_pec); |
675 | exit_detach: | ||
676 | i2c_detach_client(new_client); | ||
677 | exit_free: | 688 | exit_free: |
678 | kfree(data); | 689 | kfree(data); |
679 | exit: | 690 | exit: |
@@ -710,10 +721,9 @@ static void lm90_init_client(struct i2c_client *client) | |||
710 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | 721 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
711 | } | 722 | } |
712 | 723 | ||
713 | static int lm90_detach_client(struct i2c_client *client) | 724 | static int lm90_remove(struct i2c_client *client) |
714 | { | 725 | { |
715 | struct lm90_data *data = i2c_get_clientdata(client); | 726 | struct lm90_data *data = i2c_get_clientdata(client); |
716 | int err; | ||
717 | 727 | ||
718 | hwmon_device_unregister(data->hwmon_dev); | 728 | hwmon_device_unregister(data->hwmon_dev); |
719 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | 729 | sysfs_remove_group(&client->dev.kobj, &lm90_group); |
@@ -722,9 +732,6 @@ static int lm90_detach_client(struct i2c_client *client) | |||
722 | device_remove_file(&client->dev, | 732 | device_remove_file(&client->dev, |
723 | &sensor_dev_attr_temp2_offset.dev_attr); | 733 | &sensor_dev_attr_temp2_offset.dev_attr); |
724 | 734 | ||
725 | if ((err = i2c_detach_client(client))) | ||
726 | return err; | ||
727 | |||
728 | kfree(data); | 735 | kfree(data); |
729 | return 0; | 736 | return 0; |
730 | } | 737 | } |
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index c31942e08246..b2e00c5a7eec 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * lm92 - Hardware monitoring driver | 2 | * lm92 - Hardware monitoring driver |
3 | * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> | 3 | * Copyright (C) 2005-2008 Jean Delvare <khali@linux-fr.org> |
4 | * | 4 | * |
5 | * Based on the lm90 driver, with some ideas taken from the lm_sensors | 5 | * Based on the lm90 driver, with some ideas taken from the lm_sensors |
6 | * lm92 driver as well. | 6 | * lm92 driver as well. |
@@ -96,7 +96,6 @@ static struct i2c_driver lm92_driver; | |||
96 | 96 | ||
97 | /* Client data (each client gets its own) */ | 97 | /* Client data (each client gets its own) */ |
98 | struct lm92_data { | 98 | struct lm92_data { |
99 | struct i2c_client client; | ||
100 | struct device *hwmon_dev; | 99 | struct device *hwmon_dev; |
101 | struct mutex update_lock; | 100 | struct mutex update_lock; |
102 | char valid; /* zero until following fields are valid */ | 101 | char valid; /* zero until following fields are valid */ |
@@ -319,32 +318,15 @@ static const struct attribute_group lm92_group = { | |||
319 | .attrs = lm92_attributes, | 318 | .attrs = lm92_attributes, |
320 | }; | 319 | }; |
321 | 320 | ||
322 | /* The following function does more than just detection. If detection | 321 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
323 | succeeds, it also registers the new chip. */ | 322 | static int lm92_detect(struct i2c_client *new_client, int kind, |
324 | static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | 323 | struct i2c_board_info *info) |
325 | { | 324 | { |
326 | struct i2c_client *new_client; | 325 | struct i2c_adapter *adapter = new_client->adapter; |
327 | struct lm92_data *data; | ||
328 | int err = 0; | ||
329 | char *name; | ||
330 | 326 | ||
331 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 327 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
332 | | I2C_FUNC_SMBUS_WORD_DATA)) | 328 | | I2C_FUNC_SMBUS_WORD_DATA)) |
333 | goto exit; | 329 | return -ENODEV; |
334 | |||
335 | if (!(data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL))) { | ||
336 | err = -ENOMEM; | ||
337 | goto exit; | ||
338 | } | ||
339 | |||
340 | /* Fill in enough client fields so that we can read from the chip, | ||
341 | which is required for identication */ | ||
342 | new_client = &data->client; | ||
343 | i2c_set_clientdata(new_client, data); | ||
344 | new_client->addr = address; | ||
345 | new_client->adapter = adapter; | ||
346 | new_client->driver = &lm92_driver; | ||
347 | new_client->flags = 0; | ||
348 | 330 | ||
349 | /* A negative kind means that the driver was loaded with no force | 331 | /* A negative kind means that the driver was loaded with no force |
350 | parameter (default), so we must identify the chip. */ | 332 | parameter (default), so we must identify the chip. */ |
@@ -364,34 +346,36 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
364 | kind = lm92; /* No separate prefix */ | 346 | kind = lm92; /* No separate prefix */ |
365 | } | 347 | } |
366 | else | 348 | else |
367 | goto exit_free; | 349 | return -ENODEV; |
368 | } else | ||
369 | if (kind == 0) /* Default to an LM92 if forced */ | ||
370 | kind = lm92; | ||
371 | |||
372 | /* Give it the proper name */ | ||
373 | if (kind == lm92) { | ||
374 | name = "lm92"; | ||
375 | } else { /* Supposedly cannot happen */ | ||
376 | dev_dbg(&new_client->dev, "Kind out of range?\n"); | ||
377 | goto exit_free; | ||
378 | } | 350 | } |
379 | 351 | ||
380 | /* Fill in the remaining client fields */ | 352 | strlcpy(info->type, "lm92", I2C_NAME_SIZE); |
381 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 353 | |
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static int lm92_probe(struct i2c_client *new_client, | ||
358 | const struct i2c_device_id *id) | ||
359 | { | ||
360 | struct lm92_data *data; | ||
361 | int err; | ||
362 | |||
363 | data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL); | ||
364 | if (!data) { | ||
365 | err = -ENOMEM; | ||
366 | goto exit; | ||
367 | } | ||
368 | |||
369 | i2c_set_clientdata(new_client, data); | ||
382 | data->valid = 0; | 370 | data->valid = 0; |
383 | mutex_init(&data->update_lock); | 371 | mutex_init(&data->update_lock); |
384 | 372 | ||
385 | /* Tell the i2c subsystem a new client has arrived */ | ||
386 | if ((err = i2c_attach_client(new_client))) | ||
387 | goto exit_free; | ||
388 | |||
389 | /* Initialize the chipset */ | 373 | /* Initialize the chipset */ |
390 | lm92_init_client(new_client); | 374 | lm92_init_client(new_client); |
391 | 375 | ||
392 | /* Register sysfs hooks */ | 376 | /* Register sysfs hooks */ |
393 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) | 377 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) |
394 | goto exit_detach; | 378 | goto exit_free; |
395 | 379 | ||
396 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 380 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
397 | if (IS_ERR(data->hwmon_dev)) { | 381 | if (IS_ERR(data->hwmon_dev)) { |
@@ -403,32 +387,19 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
403 | 387 | ||
404 | exit_remove: | 388 | exit_remove: |
405 | sysfs_remove_group(&new_client->dev.kobj, &lm92_group); | 389 | sysfs_remove_group(&new_client->dev.kobj, &lm92_group); |
406 | exit_detach: | ||
407 | i2c_detach_client(new_client); | ||
408 | exit_free: | 390 | exit_free: |
409 | kfree(data); | 391 | kfree(data); |
410 | exit: | 392 | exit: |
411 | return err; | 393 | return err; |
412 | } | 394 | } |
413 | 395 | ||
414 | static int lm92_attach_adapter(struct i2c_adapter *adapter) | 396 | static int lm92_remove(struct i2c_client *client) |
415 | { | ||
416 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
417 | return 0; | ||
418 | return i2c_probe(adapter, &addr_data, lm92_detect); | ||
419 | } | ||
420 | |||
421 | static int lm92_detach_client(struct i2c_client *client) | ||
422 | { | 397 | { |
423 | struct lm92_data *data = i2c_get_clientdata(client); | 398 | struct lm92_data *data = i2c_get_clientdata(client); |
424 | int err; | ||
425 | 399 | ||
426 | hwmon_device_unregister(data->hwmon_dev); | 400 | hwmon_device_unregister(data->hwmon_dev); |
427 | sysfs_remove_group(&client->dev.kobj, &lm92_group); | 401 | sysfs_remove_group(&client->dev.kobj, &lm92_group); |
428 | 402 | ||
429 | if ((err = i2c_detach_client(client))) | ||
430 | return err; | ||
431 | |||
432 | kfree(data); | 403 | kfree(data); |
433 | return 0; | 404 | return 0; |
434 | } | 405 | } |
@@ -438,12 +409,23 @@ static int lm92_detach_client(struct i2c_client *client) | |||
438 | * Module and driver stuff | 409 | * Module and driver stuff |
439 | */ | 410 | */ |
440 | 411 | ||
412 | static const struct i2c_device_id lm92_id[] = { | ||
413 | { "lm92", lm92 }, | ||
414 | /* max6635 could be added here */ | ||
415 | { } | ||
416 | }; | ||
417 | MODULE_DEVICE_TABLE(i2c, lm92_id); | ||
418 | |||
441 | static struct i2c_driver lm92_driver = { | 419 | static struct i2c_driver lm92_driver = { |
420 | .class = I2C_CLASS_HWMON, | ||
442 | .driver = { | 421 | .driver = { |
443 | .name = "lm92", | 422 | .name = "lm92", |
444 | }, | 423 | }, |
445 | .attach_adapter = lm92_attach_adapter, | 424 | .probe = lm92_probe, |
446 | .detach_client = lm92_detach_client, | 425 | .remove = lm92_remove, |
426 | .id_table = lm92_id, | ||
427 | .detect = lm92_detect, | ||
428 | .address_data = &addr_data, | ||
447 | }; | 429 | }; |
448 | 430 | ||
449 | static int __init sensors_lm92_init(void) | 431 | static int __init sensors_lm92_init(void) |
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index 5e678f5c883d..fc36cadf36fb 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -200,7 +200,6 @@ struct block1_t { | |||
200 | * Client-specific data | 200 | * Client-specific data |
201 | */ | 201 | */ |
202 | struct lm93_data { | 202 | struct lm93_data { |
203 | struct i2c_client client; | ||
204 | struct device *hwmon_dev; | 203 | struct device *hwmon_dev; |
205 | 204 | ||
206 | struct mutex update_lock; | 205 | struct mutex update_lock; |
@@ -2501,45 +2500,14 @@ static void lm93_init_client(struct i2c_client *client) | |||
2501 | "chip to signal ready!\n"); | 2500 | "chip to signal ready!\n"); |
2502 | } | 2501 | } |
2503 | 2502 | ||
2504 | static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | 2503 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
2504 | static int lm93_detect(struct i2c_client *client, int kind, | ||
2505 | struct i2c_board_info *info) | ||
2505 | { | 2506 | { |
2506 | struct lm93_data *data; | 2507 | struct i2c_adapter *adapter = client->adapter; |
2507 | struct i2c_client *client; | ||
2508 | |||
2509 | int err = -ENODEV, func; | ||
2510 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
2511 | |||
2512 | /* choose update routine based on bus capabilities */ | ||
2513 | func = i2c_get_functionality(adapter); | ||
2514 | if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | ||
2515 | (!disable_block) ) { | ||
2516 | dev_dbg(&adapter->dev,"using SMBus block data transactions\n"); | ||
2517 | update = lm93_update_client_full; | ||
2518 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | ||
2519 | dev_dbg(&adapter->dev,"disabled SMBus block data " | ||
2520 | "transactions\n"); | ||
2521 | update = lm93_update_client_min; | ||
2522 | } else { | ||
2523 | dev_dbg(&adapter->dev,"detect failed, " | ||
2524 | "smbus byte and/or word data not supported!\n"); | ||
2525 | goto err_out; | ||
2526 | } | ||
2527 | 2508 | ||
2528 | /* OK. For now, we presume we have a valid client. We now create the | 2509 | if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) |
2529 | client structure, even though we cannot fill it completely yet. | 2510 | return -ENODEV; |
2530 | But it allows us to access lm78_{read,write}_value. */ | ||
2531 | |||
2532 | if ( !(data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL))) { | ||
2533 | dev_dbg(&adapter->dev,"out of memory!\n"); | ||
2534 | err = -ENOMEM; | ||
2535 | goto err_out; | ||
2536 | } | ||
2537 | |||
2538 | client = &data->client; | ||
2539 | i2c_set_clientdata(client, data); | ||
2540 | client->addr = address; | ||
2541 | client->adapter = adapter; | ||
2542 | client->driver = &lm93_driver; | ||
2543 | 2511 | ||
2544 | /* detection */ | 2512 | /* detection */ |
2545 | if (kind < 0) { | 2513 | if (kind < 0) { |
@@ -2548,7 +2516,7 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2548 | if (mfr != 0x01) { | 2516 | if (mfr != 0x01) { |
2549 | dev_dbg(&adapter->dev,"detect failed, " | 2517 | dev_dbg(&adapter->dev,"detect failed, " |
2550 | "bad manufacturer id 0x%02x!\n", mfr); | 2518 | "bad manufacturer id 0x%02x!\n", mfr); |
2551 | goto err_free; | 2519 | return -ENODEV; |
2552 | } | 2520 | } |
2553 | } | 2521 | } |
2554 | 2522 | ||
@@ -2563,31 +2531,61 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2563 | if (kind == 0) | 2531 | if (kind == 0) |
2564 | dev_dbg(&adapter->dev, | 2532 | dev_dbg(&adapter->dev, |
2565 | "(ignored 'force' parameter)\n"); | 2533 | "(ignored 'force' parameter)\n"); |
2566 | goto err_free; | 2534 | return -ENODEV; |
2567 | } | 2535 | } |
2568 | } | 2536 | } |
2569 | 2537 | ||
2570 | /* fill in remaining client fields */ | 2538 | strlcpy(info->type, "lm93", I2C_NAME_SIZE); |
2571 | strlcpy(client->name, "lm93", I2C_NAME_SIZE); | ||
2572 | dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", | 2539 | dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", |
2573 | client->name, i2c_adapter_id(client->adapter), | 2540 | client->name, i2c_adapter_id(client->adapter), |
2574 | client->addr); | 2541 | client->addr); |
2575 | 2542 | ||
2543 | return 0; | ||
2544 | } | ||
2545 | |||
2546 | static int lm93_probe(struct i2c_client *client, | ||
2547 | const struct i2c_device_id *id) | ||
2548 | { | ||
2549 | struct lm93_data *data; | ||
2550 | int err, func; | ||
2551 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
2552 | |||
2553 | /* choose update routine based on bus capabilities */ | ||
2554 | func = i2c_get_functionality(client->adapter); | ||
2555 | if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | ||
2556 | (!disable_block)) { | ||
2557 | dev_dbg(&client->dev, "using SMBus block data transactions\n"); | ||
2558 | update = lm93_update_client_full; | ||
2559 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | ||
2560 | dev_dbg(&client->dev, "disabled SMBus block data " | ||
2561 | "transactions\n"); | ||
2562 | update = lm93_update_client_min; | ||
2563 | } else { | ||
2564 | dev_dbg(&client->dev, "detect failed, " | ||
2565 | "smbus byte and/or word data not supported!\n"); | ||
2566 | err = -ENODEV; | ||
2567 | goto err_out; | ||
2568 | } | ||
2569 | |||
2570 | data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL); | ||
2571 | if (!data) { | ||
2572 | dev_dbg(&client->dev, "out of memory!\n"); | ||
2573 | err = -ENOMEM; | ||
2574 | goto err_out; | ||
2575 | } | ||
2576 | i2c_set_clientdata(client, data); | ||
2577 | |||
2576 | /* housekeeping */ | 2578 | /* housekeeping */ |
2577 | data->valid = 0; | 2579 | data->valid = 0; |
2578 | data->update = update; | 2580 | data->update = update; |
2579 | mutex_init(&data->update_lock); | 2581 | mutex_init(&data->update_lock); |
2580 | 2582 | ||
2581 | /* tell the I2C layer a new client has arrived */ | ||
2582 | if ((err = i2c_attach_client(client))) | ||
2583 | goto err_free; | ||
2584 | |||
2585 | /* initialize the chip */ | 2583 | /* initialize the chip */ |
2586 | lm93_init_client(client); | 2584 | lm93_init_client(client); |
2587 | 2585 | ||
2588 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); | 2586 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); |
2589 | if (err) | 2587 | if (err) |
2590 | goto err_detach; | 2588 | goto err_free; |
2591 | 2589 | ||
2592 | /* Register hwmon driver class */ | 2590 | /* Register hwmon driver class */ |
2593 | data->hwmon_dev = hwmon_device_register(&client->dev); | 2591 | data->hwmon_dev = hwmon_device_register(&client->dev); |
@@ -2597,43 +2595,39 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2597 | err = PTR_ERR(data->hwmon_dev); | 2595 | err = PTR_ERR(data->hwmon_dev); |
2598 | dev_err(&client->dev, "error registering hwmon device.\n"); | 2596 | dev_err(&client->dev, "error registering hwmon device.\n"); |
2599 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | 2597 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); |
2600 | err_detach: | ||
2601 | i2c_detach_client(client); | ||
2602 | err_free: | 2598 | err_free: |
2603 | kfree(data); | 2599 | kfree(data); |
2604 | err_out: | 2600 | err_out: |
2605 | return err; | 2601 | return err; |
2606 | } | 2602 | } |
2607 | 2603 | ||
2608 | /* This function is called when: | 2604 | static int lm93_remove(struct i2c_client *client) |
2609 | * lm93_driver is inserted (when this module is loaded), for each | ||
2610 | available adapter | ||
2611 | * when a new adapter is inserted (and lm93_driver is still present) */ | ||
2612 | static int lm93_attach_adapter(struct i2c_adapter *adapter) | ||
2613 | { | ||
2614 | return i2c_probe(adapter, &addr_data, lm93_detect); | ||
2615 | } | ||
2616 | |||
2617 | static int lm93_detach_client(struct i2c_client *client) | ||
2618 | { | 2605 | { |
2619 | struct lm93_data *data = i2c_get_clientdata(client); | 2606 | struct lm93_data *data = i2c_get_clientdata(client); |
2620 | int err = 0; | ||
2621 | 2607 | ||
2622 | hwmon_device_unregister(data->hwmon_dev); | 2608 | hwmon_device_unregister(data->hwmon_dev); |
2623 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | 2609 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); |
2624 | 2610 | ||
2625 | err = i2c_detach_client(client); | 2611 | kfree(data); |
2626 | if (!err) | 2612 | return 0; |
2627 | kfree(data); | ||
2628 | return err; | ||
2629 | } | 2613 | } |
2630 | 2614 | ||
2615 | static const struct i2c_device_id lm93_id[] = { | ||
2616 | { "lm93", lm93 }, | ||
2617 | { } | ||
2618 | }; | ||
2619 | MODULE_DEVICE_TABLE(i2c, lm93_id); | ||
2620 | |||
2631 | static struct i2c_driver lm93_driver = { | 2621 | static struct i2c_driver lm93_driver = { |
2622 | .class = I2C_CLASS_HWMON, | ||
2632 | .driver = { | 2623 | .driver = { |
2633 | .name = "lm93", | 2624 | .name = "lm93", |
2634 | }, | 2625 | }, |
2635 | .attach_adapter = lm93_attach_adapter, | 2626 | .probe = lm93_probe, |
2636 | .detach_client = lm93_detach_client, | 2627 | .remove = lm93_remove, |
2628 | .id_table = lm93_id, | ||
2629 | .detect = lm93_detect, | ||
2630 | .address_data = &addr_data, | ||
2637 | }; | 2631 | }; |
2638 | 2632 | ||
2639 | static int __init lm93_init(void) | 2633 | static int __init lm93_init(void) |
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 7e7267a04544..1ab1cacad598 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -79,23 +79,34 @@ I2C_CLIENT_INSMOD_1(max1619); | |||
79 | * Functions declaration | 79 | * Functions declaration |
80 | */ | 80 | */ |
81 | 81 | ||
82 | static int max1619_attach_adapter(struct i2c_adapter *adapter); | 82 | static int max1619_probe(struct i2c_client *client, |
83 | static int max1619_detect(struct i2c_adapter *adapter, int address, | 83 | const struct i2c_device_id *id); |
84 | int kind); | 84 | static int max1619_detect(struct i2c_client *client, int kind, |
85 | struct i2c_board_info *info); | ||
85 | static void max1619_init_client(struct i2c_client *client); | 86 | static void max1619_init_client(struct i2c_client *client); |
86 | static int max1619_detach_client(struct i2c_client *client); | 87 | static int max1619_remove(struct i2c_client *client); |
87 | static struct max1619_data *max1619_update_device(struct device *dev); | 88 | static struct max1619_data *max1619_update_device(struct device *dev); |
88 | 89 | ||
89 | /* | 90 | /* |
90 | * Driver data (common to all clients) | 91 | * Driver data (common to all clients) |
91 | */ | 92 | */ |
92 | 93 | ||
94 | static const struct i2c_device_id max1619_id[] = { | ||
95 | { "max1619", max1619 }, | ||
96 | { } | ||
97 | }; | ||
98 | MODULE_DEVICE_TABLE(i2c, max1619_id); | ||
99 | |||
93 | static struct i2c_driver max1619_driver = { | 100 | static struct i2c_driver max1619_driver = { |
101 | .class = I2C_CLASS_HWMON, | ||
94 | .driver = { | 102 | .driver = { |
95 | .name = "max1619", | 103 | .name = "max1619", |
96 | }, | 104 | }, |
97 | .attach_adapter = max1619_attach_adapter, | 105 | .probe = max1619_probe, |
98 | .detach_client = max1619_detach_client, | 106 | .remove = max1619_remove, |
107 | .id_table = max1619_id, | ||
108 | .detect = max1619_detect, | ||
109 | .address_data = &addr_data, | ||
99 | }; | 110 | }; |
100 | 111 | ||
101 | /* | 112 | /* |
@@ -103,7 +114,6 @@ static struct i2c_driver max1619_driver = { | |||
103 | */ | 114 | */ |
104 | 115 | ||
105 | struct max1619_data { | 116 | struct max1619_data { |
106 | struct i2c_client client; | ||
107 | struct device *hwmon_dev; | 117 | struct device *hwmon_dev; |
108 | struct mutex update_lock; | 118 | struct mutex update_lock; |
109 | char valid; /* zero until following fields are valid */ | 119 | char valid; /* zero until following fields are valid */ |
@@ -208,41 +218,15 @@ static const struct attribute_group max1619_group = { | |||
208 | * Real code | 218 | * Real code |
209 | */ | 219 | */ |
210 | 220 | ||
211 | static int max1619_attach_adapter(struct i2c_adapter *adapter) | 221 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
212 | { | 222 | static int max1619_detect(struct i2c_client *new_client, int kind, |
213 | if (!(adapter->class & I2C_CLASS_HWMON)) | 223 | struct i2c_board_info *info) |
214 | return 0; | ||
215 | return i2c_probe(adapter, &addr_data, max1619_detect); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * The following function does more than just detection. If detection | ||
220 | * succeeds, it also registers the new chip. | ||
221 | */ | ||
222 | static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | ||
223 | { | 224 | { |
224 | struct i2c_client *new_client; | 225 | struct i2c_adapter *adapter = new_client->adapter; |
225 | struct max1619_data *data; | ||
226 | int err = 0; | ||
227 | const char *name = ""; | ||
228 | u8 reg_config=0, reg_convrate=0, reg_status=0; | 226 | u8 reg_config=0, reg_convrate=0, reg_status=0; |
229 | 227 | ||
230 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 228 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
231 | goto exit; | 229 | return -ENODEV; |
232 | |||
233 | if (!(data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL))) { | ||
234 | err = -ENOMEM; | ||
235 | goto exit; | ||
236 | } | ||
237 | |||
238 | /* The common I2C client data is placed right before the | ||
239 | MAX1619-specific data. */ | ||
240 | new_client = &data->client; | ||
241 | i2c_set_clientdata(new_client, data); | ||
242 | new_client->addr = address; | ||
243 | new_client->adapter = adapter; | ||
244 | new_client->driver = &max1619_driver; | ||
245 | new_client->flags = 0; | ||
246 | 230 | ||
247 | /* | 231 | /* |
248 | * Now we do the remaining detection. A negative kind means that | 232 | * Now we do the remaining detection. A negative kind means that |
@@ -265,8 +249,8 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
265 | || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) { | 249 | || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) { |
266 | dev_dbg(&adapter->dev, | 250 | dev_dbg(&adapter->dev, |
267 | "MAX1619 detection failed at 0x%02x.\n", | 251 | "MAX1619 detection failed at 0x%02x.\n", |
268 | address); | 252 | new_client->addr); |
269 | goto exit_free; | 253 | return -ENODEV; |
270 | } | 254 | } |
271 | } | 255 | } |
272 | 256 | ||
@@ -285,28 +269,37 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
285 | dev_info(&adapter->dev, | 269 | dev_info(&adapter->dev, |
286 | "Unsupported chip (man_id=0x%02X, " | 270 | "Unsupported chip (man_id=0x%02X, " |
287 | "chip_id=0x%02X).\n", man_id, chip_id); | 271 | "chip_id=0x%02X).\n", man_id, chip_id); |
288 | goto exit_free; | 272 | return -ENODEV; |
289 | } | 273 | } |
290 | } | 274 | } |
291 | 275 | ||
292 | if (kind == max1619) | 276 | strlcpy(info->type, "max1619", I2C_NAME_SIZE); |
293 | name = "max1619"; | 277 | |
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int max1619_probe(struct i2c_client *new_client, | ||
282 | const struct i2c_device_id *id) | ||
283 | { | ||
284 | struct max1619_data *data; | ||
285 | int err; | ||
286 | |||
287 | data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL); | ||
288 | if (!data) { | ||
289 | err = -ENOMEM; | ||
290 | goto exit; | ||
291 | } | ||
294 | 292 | ||
295 | /* We can fill in the remaining client fields */ | 293 | i2c_set_clientdata(new_client, data); |
296 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
297 | data->valid = 0; | 294 | data->valid = 0; |
298 | mutex_init(&data->update_lock); | 295 | mutex_init(&data->update_lock); |
299 | 296 | ||
300 | /* Tell the I2C layer a new client has arrived */ | ||
301 | if ((err = i2c_attach_client(new_client))) | ||
302 | goto exit_free; | ||
303 | |||
304 | /* Initialize the MAX1619 chip */ | 297 | /* Initialize the MAX1619 chip */ |
305 | max1619_init_client(new_client); | 298 | max1619_init_client(new_client); |
306 | 299 | ||
307 | /* Register sysfs hooks */ | 300 | /* Register sysfs hooks */ |
308 | if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group))) | 301 | if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group))) |
309 | goto exit_detach; | 302 | goto exit_free; |
310 | 303 | ||
311 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 304 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
312 | if (IS_ERR(data->hwmon_dev)) { | 305 | if (IS_ERR(data->hwmon_dev)) { |
@@ -318,8 +311,6 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
318 | 311 | ||
319 | exit_remove_files: | 312 | exit_remove_files: |
320 | sysfs_remove_group(&new_client->dev.kobj, &max1619_group); | 313 | sysfs_remove_group(&new_client->dev.kobj, &max1619_group); |
321 | exit_detach: | ||
322 | i2c_detach_client(new_client); | ||
323 | exit_free: | 314 | exit_free: |
324 | kfree(data); | 315 | kfree(data); |
325 | exit: | 316 | exit: |
@@ -341,17 +332,13 @@ static void max1619_init_client(struct i2c_client *client) | |||
341 | config & 0xBF); /* run */ | 332 | config & 0xBF); /* run */ |
342 | } | 333 | } |
343 | 334 | ||
344 | static int max1619_detach_client(struct i2c_client *client) | 335 | static int max1619_remove(struct i2c_client *client) |
345 | { | 336 | { |
346 | struct max1619_data *data = i2c_get_clientdata(client); | 337 | struct max1619_data *data = i2c_get_clientdata(client); |
347 | int err; | ||
348 | 338 | ||
349 | hwmon_device_unregister(data->hwmon_dev); | 339 | hwmon_device_unregister(data->hwmon_dev); |
350 | sysfs_remove_group(&client->dev.kobj, &max1619_group); | 340 | sysfs_remove_group(&client->dev.kobj, &max1619_group); |
351 | 341 | ||
352 | if ((err = i2c_detach_client(client))) | ||
353 | return err; | ||
354 | |||
355 | kfree(data); | 342 | kfree(data); |
356 | return 0; | 343 | return 0; |
357 | } | 344 | } |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 52d528b76cc3..f27af6a9da41 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -104,22 +104,34 @@ I2C_CLIENT_INSMOD_1(max6650); | |||
104 | 104 | ||
105 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) | 105 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) |
106 | 106 | ||
107 | static int max6650_attach_adapter(struct i2c_adapter *adapter); | 107 | static int max6650_probe(struct i2c_client *client, |
108 | static int max6650_detect(struct i2c_adapter *adapter, int address, int kind); | 108 | const struct i2c_device_id *id); |
109 | static int max6650_detect(struct i2c_client *client, int kind, | ||
110 | struct i2c_board_info *info); | ||
109 | static int max6650_init_client(struct i2c_client *client); | 111 | static int max6650_init_client(struct i2c_client *client); |
110 | static int max6650_detach_client(struct i2c_client *client); | 112 | static int max6650_remove(struct i2c_client *client); |
111 | static struct max6650_data *max6650_update_device(struct device *dev); | 113 | static struct max6650_data *max6650_update_device(struct device *dev); |
112 | 114 | ||
113 | /* | 115 | /* |
114 | * Driver data (common to all clients) | 116 | * Driver data (common to all clients) |
115 | */ | 117 | */ |
116 | 118 | ||
119 | static const struct i2c_device_id max6650_id[] = { | ||
120 | { "max6650", max6650 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, max6650_id); | ||
124 | |||
117 | static struct i2c_driver max6650_driver = { | 125 | static struct i2c_driver max6650_driver = { |
126 | .class = I2C_CLASS_HWMON, | ||
118 | .driver = { | 127 | .driver = { |
119 | .name = "max6650", | 128 | .name = "max6650", |
120 | }, | 129 | }, |
121 | .attach_adapter = max6650_attach_adapter, | 130 | .probe = max6650_probe, |
122 | .detach_client = max6650_detach_client, | 131 | .remove = max6650_remove, |
132 | .id_table = max6650_id, | ||
133 | .detect = max6650_detect, | ||
134 | .address_data = &addr_data, | ||
123 | }; | 135 | }; |
124 | 136 | ||
125 | /* | 137 | /* |
@@ -128,7 +140,6 @@ static struct i2c_driver max6650_driver = { | |||
128 | 140 | ||
129 | struct max6650_data | 141 | struct max6650_data |
130 | { | 142 | { |
131 | struct i2c_client client; | ||
132 | struct device *hwmon_dev; | 143 | struct device *hwmon_dev; |
133 | struct mutex update_lock; | 144 | struct mutex update_lock; |
134 | char valid; /* zero until following fields are valid */ | 145 | char valid; /* zero until following fields are valid */ |
@@ -437,47 +448,21 @@ static struct attribute_group max6650_attr_grp = { | |||
437 | * Real code | 448 | * Real code |
438 | */ | 449 | */ |
439 | 450 | ||
440 | static int max6650_attach_adapter(struct i2c_adapter *adapter) | 451 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
452 | static int max6650_detect(struct i2c_client *client, int kind, | ||
453 | struct i2c_board_info *info) | ||
441 | { | 454 | { |
442 | if (!(adapter->class & I2C_CLASS_HWMON)) { | 455 | struct i2c_adapter *adapter = client->adapter; |
443 | dev_dbg(&adapter->dev, | 456 | int address = client->addr; |
444 | "FATAL: max6650_attach_adapter class HWMON not set\n"); | ||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | return i2c_probe(adapter, &addr_data, max6650_detect); | ||
449 | } | ||
450 | |||
451 | /* | ||
452 | * The following function does more than just detection. If detection | ||
453 | * succeeds, it also registers the new chip. | ||
454 | */ | ||
455 | |||
456 | static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | ||
457 | { | ||
458 | struct i2c_client *client; | ||
459 | struct max6650_data *data; | ||
460 | int err = -ENODEV; | ||
461 | 457 | ||
462 | dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); | 458 | dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); |
463 | 459 | ||
464 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 460 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
465 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " | 461 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " |
466 | "byte read mode, skipping.\n"); | 462 | "byte read mode, skipping.\n"); |
467 | return 0; | 463 | return -ENODEV; |
468 | } | ||
469 | |||
470 | if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) { | ||
471 | dev_err(&adapter->dev, "max6650: out of memory.\n"); | ||
472 | return -ENOMEM; | ||
473 | } | 464 | } |
474 | 465 | ||
475 | client = &data->client; | ||
476 | i2c_set_clientdata(client, data); | ||
477 | client->addr = address; | ||
478 | client->adapter = adapter; | ||
479 | client->driver = &max6650_driver; | ||
480 | |||
481 | /* | 466 | /* |
482 | * Now we do the remaining detection. A negative kind means that | 467 | * Now we do the remaining detection. A negative kind means that |
483 | * the driver was loaded with no force parameter (default), so we | 468 | * the driver was loaded with no force parameter (default), so we |
@@ -501,28 +486,40 @@ static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | |||
501 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) { | 486 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) { |
502 | dev_dbg(&adapter->dev, | 487 | dev_dbg(&adapter->dev, |
503 | "max6650: detection failed at 0x%02x.\n", address); | 488 | "max6650: detection failed at 0x%02x.\n", address); |
504 | goto err_free; | 489 | return -ENODEV; |
505 | } | 490 | } |
506 | 491 | ||
507 | dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address); | 492 | dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address); |
508 | 493 | ||
509 | strlcpy(client->name, "max6650", I2C_NAME_SIZE); | 494 | strlcpy(info->type, "max6650", I2C_NAME_SIZE); |
510 | mutex_init(&data->update_lock); | ||
511 | 495 | ||
512 | if ((err = i2c_attach_client(client))) { | 496 | return 0; |
513 | dev_err(&adapter->dev, "max6650: failed to attach client.\n"); | 497 | } |
514 | goto err_free; | 498 | |
499 | static int max6650_probe(struct i2c_client *client, | ||
500 | const struct i2c_device_id *id) | ||
501 | { | ||
502 | struct max6650_data *data; | ||
503 | int err; | ||
504 | |||
505 | if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) { | ||
506 | dev_err(&client->dev, "out of memory.\n"); | ||
507 | return -ENOMEM; | ||
515 | } | 508 | } |
516 | 509 | ||
510 | i2c_set_clientdata(client, data); | ||
511 | mutex_init(&data->update_lock); | ||
512 | |||
517 | /* | 513 | /* |
518 | * Initialize the max6650 chip | 514 | * Initialize the max6650 chip |
519 | */ | 515 | */ |
520 | if (max6650_init_client(client)) | 516 | err = max6650_init_client(client); |
521 | goto err_detach; | 517 | if (err) |
518 | goto err_free; | ||
522 | 519 | ||
523 | err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); | 520 | err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); |
524 | if (err) | 521 | if (err) |
525 | goto err_detach; | 522 | goto err_free; |
526 | 523 | ||
527 | data->hwmon_dev = hwmon_device_register(&client->dev); | 524 | data->hwmon_dev = hwmon_device_register(&client->dev); |
528 | if (!IS_ERR(data->hwmon_dev)) | 525 | if (!IS_ERR(data->hwmon_dev)) |
@@ -531,24 +528,19 @@ static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | |||
531 | err = PTR_ERR(data->hwmon_dev); | 528 | err = PTR_ERR(data->hwmon_dev); |
532 | dev_err(&client->dev, "error registering hwmon device.\n"); | 529 | dev_err(&client->dev, "error registering hwmon device.\n"); |
533 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | 530 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); |
534 | err_detach: | ||
535 | i2c_detach_client(client); | ||
536 | err_free: | 531 | err_free: |
537 | kfree(data); | 532 | kfree(data); |
538 | return err; | 533 | return err; |
539 | } | 534 | } |
540 | 535 | ||
541 | static int max6650_detach_client(struct i2c_client *client) | 536 | static int max6650_remove(struct i2c_client *client) |
542 | { | 537 | { |
543 | struct max6650_data *data = i2c_get_clientdata(client); | 538 | struct max6650_data *data = i2c_get_clientdata(client); |
544 | int err; | ||
545 | 539 | ||
546 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | 540 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); |
547 | hwmon_device_unregister(data->hwmon_dev); | 541 | hwmon_device_unregister(data->hwmon_dev); |
548 | err = i2c_detach_client(client); | 542 | kfree(data); |
549 | if (!err) | 543 | return 0; |
550 | kfree(data); | ||
551 | return err; | ||
552 | } | 544 | } |
553 | 545 | ||
554 | static int max6650_init_client(struct i2c_client *client) | 546 | static int max6650_init_client(struct i2c_client *client) |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 3c9db6598ba7..8bb5cb532d4d 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -96,7 +96,6 @@ static inline int TEMP_FROM_REG(s8 val) | |||
96 | } | 96 | } |
97 | 97 | ||
98 | struct smsc47m192_data { | 98 | struct smsc47m192_data { |
99 | struct i2c_client client; | ||
100 | struct device *hwmon_dev; | 99 | struct device *hwmon_dev; |
101 | struct mutex update_lock; | 100 | struct mutex update_lock; |
102 | char valid; /* !=0 if following fields are valid */ | 101 | char valid; /* !=0 if following fields are valid */ |
@@ -114,18 +113,29 @@ struct smsc47m192_data { | |||
114 | u8 vrm; | 113 | u8 vrm; |
115 | }; | 114 | }; |
116 | 115 | ||
117 | static int smsc47m192_attach_adapter(struct i2c_adapter *adapter); | 116 | static int smsc47m192_probe(struct i2c_client *client, |
118 | static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | 117 | const struct i2c_device_id *id); |
119 | int kind); | 118 | static int smsc47m192_detect(struct i2c_client *client, int kind, |
120 | static int smsc47m192_detach_client(struct i2c_client *client); | 119 | struct i2c_board_info *info); |
120 | static int smsc47m192_remove(struct i2c_client *client); | ||
121 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); | 121 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); |
122 | 122 | ||
123 | static const struct i2c_device_id smsc47m192_id[] = { | ||
124 | { "smsc47m192", smsc47m192 }, | ||
125 | { } | ||
126 | }; | ||
127 | MODULE_DEVICE_TABLE(i2c, smsc47m192_id); | ||
128 | |||
123 | static struct i2c_driver smsc47m192_driver = { | 129 | static struct i2c_driver smsc47m192_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
124 | .driver = { | 131 | .driver = { |
125 | .name = "smsc47m192", | 132 | .name = "smsc47m192", |
126 | }, | 133 | }, |
127 | .attach_adapter = smsc47m192_attach_adapter, | 134 | .probe = smsc47m192_probe, |
128 | .detach_client = smsc47m192_detach_client, | 135 | .remove = smsc47m192_remove, |
136 | .id_table = smsc47m192_id, | ||
137 | .detect = smsc47m192_detect, | ||
138 | .address_data = &addr_data, | ||
129 | }; | 139 | }; |
130 | 140 | ||
131 | /* Voltages */ | 141 | /* Voltages */ |
@@ -440,17 +450,6 @@ static const struct attribute_group smsc47m192_group_in4 = { | |||
440 | .attrs = smsc47m192_attributes_in4, | 450 | .attrs = smsc47m192_attributes_in4, |
441 | }; | 451 | }; |
442 | 452 | ||
443 | /* This function is called when: | ||
444 | * smsc47m192_driver is inserted (when this module is loaded), for each | ||
445 | available adapter | ||
446 | * when a new adapter is inserted (and smsc47m192_driver is still present) */ | ||
447 | static int smsc47m192_attach_adapter(struct i2c_adapter *adapter) | ||
448 | { | ||
449 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
450 | return 0; | ||
451 | return i2c_probe(adapter, &addr_data, smsc47m192_detect); | ||
452 | } | ||
453 | |||
454 | static void smsc47m192_init_client(struct i2c_client *client) | 453 | static void smsc47m192_init_client(struct i2c_client *client) |
455 | { | 454 | { |
456 | int i; | 455 | int i; |
@@ -481,31 +480,15 @@ static void smsc47m192_init_client(struct i2c_client *client) | |||
481 | } | 480 | } |
482 | } | 481 | } |
483 | 482 | ||
484 | /* This function is called by i2c_probe */ | 483 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
485 | static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | 484 | static int smsc47m192_detect(struct i2c_client *client, int kind, |
486 | int kind) | 485 | struct i2c_board_info *info) |
487 | { | 486 | { |
488 | struct i2c_client *client; | 487 | struct i2c_adapter *adapter = client->adapter; |
489 | struct smsc47m192_data *data; | 488 | int version; |
490 | int err = 0; | ||
491 | int version, config; | ||
492 | 489 | ||
493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 490 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
494 | goto exit; | 491 | return -ENODEV; |
495 | |||
496 | if (!(data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL))) { | ||
497 | err = -ENOMEM; | ||
498 | goto exit; | ||
499 | } | ||
500 | |||
501 | client = &data->client; | ||
502 | i2c_set_clientdata(client, data); | ||
503 | client->addr = address; | ||
504 | client->adapter = adapter; | ||
505 | client->driver = &smsc47m192_driver; | ||
506 | |||
507 | if (kind == 0) | ||
508 | kind = smsc47m192; | ||
509 | 492 | ||
510 | /* Detection criteria from sensors_detect script */ | 493 | /* Detection criteria from sensors_detect script */ |
511 | if (kind < 0) { | 494 | if (kind < 0) { |
@@ -523,26 +506,39 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | |||
523 | } else { | 506 | } else { |
524 | dev_dbg(&adapter->dev, | 507 | dev_dbg(&adapter->dev, |
525 | "SMSC47M192 detection failed at 0x%02x\n", | 508 | "SMSC47M192 detection failed at 0x%02x\n", |
526 | address); | 509 | client->addr); |
527 | goto exit_free; | 510 | return -ENODEV; |
528 | } | 511 | } |
529 | } | 512 | } |
530 | 513 | ||
531 | /* Fill in the remaining client fields and put into the global list */ | 514 | strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); |
532 | strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); | 515 | |
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static int smsc47m192_probe(struct i2c_client *client, | ||
520 | const struct i2c_device_id *id) | ||
521 | { | ||
522 | struct smsc47m192_data *data; | ||
523 | int config; | ||
524 | int err; | ||
525 | |||
526 | data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL); | ||
527 | if (!data) { | ||
528 | err = -ENOMEM; | ||
529 | goto exit; | ||
530 | } | ||
531 | |||
532 | i2c_set_clientdata(client, data); | ||
533 | data->vrm = vid_which_vrm(); | 533 | data->vrm = vid_which_vrm(); |
534 | mutex_init(&data->update_lock); | 534 | mutex_init(&data->update_lock); |
535 | 535 | ||
536 | /* Tell the I2C layer a new client has arrived */ | ||
537 | if ((err = i2c_attach_client(client))) | ||
538 | goto exit_free; | ||
539 | |||
540 | /* Initialize the SMSC47M192 chip */ | 536 | /* Initialize the SMSC47M192 chip */ |
541 | smsc47m192_init_client(client); | 537 | smsc47m192_init_client(client); |
542 | 538 | ||
543 | /* Register sysfs hooks */ | 539 | /* Register sysfs hooks */ |
544 | if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) | 540 | if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) |
545 | goto exit_detach; | 541 | goto exit_free; |
546 | 542 | ||
547 | /* Pin 110 is either in4 (+12V) or VID4 */ | 543 | /* Pin 110 is either in4 (+12V) or VID4 */ |
548 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); | 544 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); |
@@ -563,26 +559,20 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | |||
563 | exit_remove_files: | 559 | exit_remove_files: |
564 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | 560 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); |
565 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | 561 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); |
566 | exit_detach: | ||
567 | i2c_detach_client(client); | ||
568 | exit_free: | 562 | exit_free: |
569 | kfree(data); | 563 | kfree(data); |
570 | exit: | 564 | exit: |
571 | return err; | 565 | return err; |
572 | } | 566 | } |
573 | 567 | ||
574 | static int smsc47m192_detach_client(struct i2c_client *client) | 568 | static int smsc47m192_remove(struct i2c_client *client) |
575 | { | 569 | { |
576 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 570 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
577 | int err; | ||
578 | 571 | ||
579 | hwmon_device_unregister(data->hwmon_dev); | 572 | hwmon_device_unregister(data->hwmon_dev); |
580 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | 573 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); |
581 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | 574 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); |
582 | 575 | ||
583 | if ((err = i2c_detach_client(client))) | ||
584 | return err; | ||
585 | |||
586 | kfree(data); | 576 | kfree(data); |
587 | 577 | ||
588 | return 0; | 578 | return 0; |
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index 76a3859c3fbe..3b01001108c1 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -60,7 +60,6 @@ static const u8 THMC50_REG_TEMP_MAX[] = { 0x39, 0x37, 0x2B }; | |||
60 | 60 | ||
61 | /* Each client has this additional data */ | 61 | /* Each client has this additional data */ |
62 | struct thmc50_data { | 62 | struct thmc50_data { |
63 | struct i2c_client client; | ||
64 | struct device *hwmon_dev; | 63 | struct device *hwmon_dev; |
65 | 64 | ||
66 | struct mutex update_lock; | 65 | struct mutex update_lock; |
@@ -77,17 +76,31 @@ struct thmc50_data { | |||
77 | u8 alarms; | 76 | u8 alarms; |
78 | }; | 77 | }; |
79 | 78 | ||
80 | static int thmc50_attach_adapter(struct i2c_adapter *adapter); | 79 | static int thmc50_detect(struct i2c_client *client, int kind, |
81 | static int thmc50_detach_client(struct i2c_client *client); | 80 | struct i2c_board_info *info); |
81 | static int thmc50_probe(struct i2c_client *client, | ||
82 | const struct i2c_device_id *id); | ||
83 | static int thmc50_remove(struct i2c_client *client); | ||
82 | static void thmc50_init_client(struct i2c_client *client); | 84 | static void thmc50_init_client(struct i2c_client *client); |
83 | static struct thmc50_data *thmc50_update_device(struct device *dev); | 85 | static struct thmc50_data *thmc50_update_device(struct device *dev); |
84 | 86 | ||
87 | static const struct i2c_device_id thmc50_id[] = { | ||
88 | { "adm1022", adm1022 }, | ||
89 | { "thmc50", thmc50 }, | ||
90 | { } | ||
91 | }; | ||
92 | MODULE_DEVICE_TABLE(i2c, thmc50_id); | ||
93 | |||
85 | static struct i2c_driver thmc50_driver = { | 94 | static struct i2c_driver thmc50_driver = { |
95 | .class = I2C_CLASS_HWMON, | ||
86 | .driver = { | 96 | .driver = { |
87 | .name = "thmc50", | 97 | .name = "thmc50", |
88 | }, | 98 | }, |
89 | .attach_adapter = thmc50_attach_adapter, | 99 | .probe = thmc50_probe, |
90 | .detach_client = thmc50_detach_client, | 100 | .remove = thmc50_remove, |
101 | .id_table = thmc50_id, | ||
102 | .detect = thmc50_detect, | ||
103 | .address_data = &addr_data, | ||
91 | }; | 104 | }; |
92 | 105 | ||
93 | static ssize_t show_analog_out(struct device *dev, | 106 | static ssize_t show_analog_out(struct device *dev, |
@@ -250,39 +263,23 @@ static const struct attribute_group temp3_group = { | |||
250 | .attrs = temp3_attributes, | 263 | .attrs = temp3_attributes, |
251 | }; | 264 | }; |
252 | 265 | ||
253 | static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | 266 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
267 | static int thmc50_detect(struct i2c_client *client, int kind, | ||
268 | struct i2c_board_info *info) | ||
254 | { | 269 | { |
255 | unsigned company; | 270 | unsigned company; |
256 | unsigned revision; | 271 | unsigned revision; |
257 | unsigned config; | 272 | unsigned config; |
258 | struct i2c_client *client; | 273 | struct i2c_adapter *adapter = client->adapter; |
259 | struct thmc50_data *data; | ||
260 | struct device *dev; | ||
261 | int err = 0; | 274 | int err = 0; |
262 | const char *type_name; | 275 | const char *type_name; |
263 | 276 | ||
264 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 277 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
265 | pr_debug("thmc50: detect failed, " | 278 | pr_debug("thmc50: detect failed, " |
266 | "smbus byte data not supported!\n"); | 279 | "smbus byte data not supported!\n"); |
267 | goto exit; | 280 | return -ENODEV; |
268 | } | ||
269 | |||
270 | /* OK. For now, we presume we have a valid client. We now create the | ||
271 | client structure, even though we cannot fill it completely yet. | ||
272 | But it allows us to access thmc50 registers. */ | ||
273 | if (!(data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL))) { | ||
274 | pr_debug("thmc50: detect failed, kzalloc failed!\n"); | ||
275 | err = -ENOMEM; | ||
276 | goto exit; | ||
277 | } | 281 | } |
278 | 282 | ||
279 | client = &data->client; | ||
280 | i2c_set_clientdata(client, data); | ||
281 | client->addr = address; | ||
282 | client->adapter = adapter; | ||
283 | client->driver = &thmc50_driver; | ||
284 | dev = &client->dev; | ||
285 | |||
286 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", | 283 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", |
287 | client->addr, i2c_adapter_id(client->adapter)); | 284 | client->addr, i2c_adapter_id(client->adapter)); |
288 | 285 | ||
@@ -307,21 +304,22 @@ static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | |||
307 | } | 304 | } |
308 | if (err == -ENODEV) { | 305 | if (err == -ENODEV) { |
309 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); | 306 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); |
310 | goto exit_free; | 307 | return err; |
311 | } | 308 | } |
312 | data->type = kind; | ||
313 | 309 | ||
314 | if (kind == adm1022) { | 310 | if (kind == adm1022) { |
315 | int id = i2c_adapter_id(client->adapter); | 311 | int id = i2c_adapter_id(client->adapter); |
316 | int i; | 312 | int i; |
317 | 313 | ||
318 | type_name = "adm1022"; | 314 | type_name = "adm1022"; |
319 | data->has_temp3 = (config >> 7) & 1; /* config MSB */ | ||
320 | for (i = 0; i + 1 < adm1022_temp3_num; i += 2) | 315 | for (i = 0; i + 1 < adm1022_temp3_num; i += 2) |
321 | if (adm1022_temp3[i] == id && | 316 | if (adm1022_temp3[i] == id && |
322 | adm1022_temp3[i + 1] == address) { | 317 | adm1022_temp3[i + 1] == client->addr) { |
323 | /* enable 2nd remote temp */ | 318 | /* enable 2nd remote temp */ |
324 | data->has_temp3 = 1; | 319 | config |= (1 << 7); |
320 | i2c_smbus_write_byte_data(client, | ||
321 | THMC50_REG_CONF, | ||
322 | config); | ||
325 | break; | 323 | break; |
326 | } | 324 | } |
327 | } else { | 325 | } else { |
@@ -330,19 +328,33 @@ static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | |||
330 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", | 328 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", |
331 | type_name, (revision >> 4) - 0xc, revision & 0xf); | 329 | type_name, (revision >> 4) - 0xc, revision & 0xf); |
332 | 330 | ||
333 | /* Fill in the remaining client fields & put it into the global list */ | 331 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
334 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | ||
335 | mutex_init(&data->update_lock); | ||
336 | 332 | ||
337 | /* Tell the I2C layer a new client has arrived */ | 333 | return 0; |
338 | if ((err = i2c_attach_client(client))) | 334 | } |
339 | goto exit_free; | 335 | |
336 | static int thmc50_probe(struct i2c_client *client, | ||
337 | const struct i2c_device_id *id) | ||
338 | { | ||
339 | struct thmc50_data *data; | ||
340 | int err; | ||
341 | |||
342 | data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL); | ||
343 | if (!data) { | ||
344 | pr_debug("thmc50: detect failed, kzalloc failed!\n"); | ||
345 | err = -ENOMEM; | ||
346 | goto exit; | ||
347 | } | ||
348 | |||
349 | i2c_set_clientdata(client, data); | ||
350 | data->type = id->driver_data; | ||
351 | mutex_init(&data->update_lock); | ||
340 | 352 | ||
341 | thmc50_init_client(client); | 353 | thmc50_init_client(client); |
342 | 354 | ||
343 | /* Register sysfs hooks */ | 355 | /* Register sysfs hooks */ |
344 | if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) | 356 | if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) |
345 | goto exit_detach; | 357 | goto exit_free; |
346 | 358 | ||
347 | /* Register ADM1022 sysfs hooks */ | 359 | /* Register ADM1022 sysfs hooks */ |
348 | if (data->has_temp3) | 360 | if (data->has_temp3) |
@@ -364,34 +376,21 @@ exit_remove_sysfs: | |||
364 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | 376 | sysfs_remove_group(&client->dev.kobj, &temp3_group); |
365 | exit_remove_sysfs_thmc50: | 377 | exit_remove_sysfs_thmc50: |
366 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | 378 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); |
367 | exit_detach: | ||
368 | i2c_detach_client(client); | ||
369 | exit_free: | 379 | exit_free: |
370 | kfree(data); | 380 | kfree(data); |
371 | exit: | 381 | exit: |
372 | return err; | 382 | return err; |
373 | } | 383 | } |
374 | 384 | ||
375 | static int thmc50_attach_adapter(struct i2c_adapter *adapter) | 385 | static int thmc50_remove(struct i2c_client *client) |
376 | { | ||
377 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
378 | return 0; | ||
379 | return i2c_probe(adapter, &addr_data, thmc50_detect); | ||
380 | } | ||
381 | |||
382 | static int thmc50_detach_client(struct i2c_client *client) | ||
383 | { | 386 | { |
384 | struct thmc50_data *data = i2c_get_clientdata(client); | 387 | struct thmc50_data *data = i2c_get_clientdata(client); |
385 | int err; | ||
386 | 388 | ||
387 | hwmon_device_unregister(data->hwmon_dev); | 389 | hwmon_device_unregister(data->hwmon_dev); |
388 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | 390 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); |
389 | if (data->has_temp3) | 391 | if (data->has_temp3) |
390 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | 392 | sysfs_remove_group(&client->dev.kobj, &temp3_group); |
391 | 393 | ||
392 | if ((err = i2c_detach_client(client))) | ||
393 | return err; | ||
394 | |||
395 | kfree(data); | 394 | kfree(data); |
396 | 395 | ||
397 | return 0; | 396 | return 0; |
@@ -412,8 +411,8 @@ static void thmc50_init_client(struct i2c_client *client) | |||
412 | } | 411 | } |
413 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); | 412 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); |
414 | config |= 0x1; /* start the chip if it is in standby mode */ | 413 | config |= 0x1; /* start the chip if it is in standby mode */ |
415 | if (data->has_temp3) | 414 | if (data->type == adm1022 && (config & (1 << 7))) |
416 | config |= 0x80; /* enable 2nd remote temp */ | 415 | data->has_temp3 = 1; |
417 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); | 416 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); |
418 | } | 417 | } |
419 | 418 | ||
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 85077c4c8039..e4e91c9d480a 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -247,7 +247,6 @@ static u8 div_to_reg(int nr, long val) | |||
247 | } | 247 | } |
248 | 248 | ||
249 | struct w83791d_data { | 249 | struct w83791d_data { |
250 | struct i2c_client client; | ||
251 | struct device *hwmon_dev; | 250 | struct device *hwmon_dev; |
252 | struct mutex update_lock; | 251 | struct mutex update_lock; |
253 | 252 | ||
@@ -286,9 +285,11 @@ struct w83791d_data { | |||
286 | u8 vrm; /* hwmon-vid */ | 285 | u8 vrm; /* hwmon-vid */ |
287 | }; | 286 | }; |
288 | 287 | ||
289 | static int w83791d_attach_adapter(struct i2c_adapter *adapter); | 288 | static int w83791d_probe(struct i2c_client *client, |
290 | static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind); | 289 | const struct i2c_device_id *id); |
291 | static int w83791d_detach_client(struct i2c_client *client); | 290 | static int w83791d_detect(struct i2c_client *client, int kind, |
291 | struct i2c_board_info *info); | ||
292 | static int w83791d_remove(struct i2c_client *client); | ||
292 | 293 | ||
293 | static int w83791d_read(struct i2c_client *client, u8 register); | 294 | static int w83791d_read(struct i2c_client *client, u8 register); |
294 | static int w83791d_write(struct i2c_client *client, u8 register, u8 value); | 295 | static int w83791d_write(struct i2c_client *client, u8 register, u8 value); |
@@ -300,12 +301,22 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev); | |||
300 | 301 | ||
301 | static void w83791d_init_client(struct i2c_client *client); | 302 | static void w83791d_init_client(struct i2c_client *client); |
302 | 303 | ||
304 | static const struct i2c_device_id w83791d_id[] = { | ||
305 | { "w83791d", w83791d }, | ||
306 | { } | ||
307 | }; | ||
308 | MODULE_DEVICE_TABLE(i2c, w83791d_id); | ||
309 | |||
303 | static struct i2c_driver w83791d_driver = { | 310 | static struct i2c_driver w83791d_driver = { |
311 | .class = I2C_CLASS_HWMON, | ||
304 | .driver = { | 312 | .driver = { |
305 | .name = "w83791d", | 313 | .name = "w83791d", |
306 | }, | 314 | }, |
307 | .attach_adapter = w83791d_attach_adapter, | 315 | .probe = w83791d_probe, |
308 | .detach_client = w83791d_detach_client, | 316 | .remove = w83791d_remove, |
317 | .id_table = w83791d_id, | ||
318 | .detect = w83791d_detect, | ||
319 | .address_data = &addr_data, | ||
309 | }; | 320 | }; |
310 | 321 | ||
311 | /* following are the sysfs callback functions */ | 322 | /* following are the sysfs callback functions */ |
@@ -905,49 +916,12 @@ static const struct attribute_group w83791d_group = { | |||
905 | .attrs = w83791d_attributes, | 916 | .attrs = w83791d_attributes, |
906 | }; | 917 | }; |
907 | 918 | ||
908 | /* This function is called when: | ||
909 | * w83791d_driver is inserted (when this module is loaded), for each | ||
910 | available adapter | ||
911 | * when a new adapter is inserted (and w83791d_driver is still present) */ | ||
912 | static int w83791d_attach_adapter(struct i2c_adapter *adapter) | ||
913 | { | ||
914 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
915 | return 0; | ||
916 | return i2c_probe(adapter, &addr_data, w83791d_detect); | ||
917 | } | ||
918 | |||
919 | 919 | ||
920 | static int w83791d_create_subclient(struct i2c_adapter *adapter, | 920 | static int w83791d_detect_subclients(struct i2c_client *client) |
921 | struct i2c_client *client, int addr, | ||
922 | struct i2c_client **sub_cli) | ||
923 | { | ||
924 | int err; | ||
925 | struct i2c_client *sub_client; | ||
926 | |||
927 | (*sub_cli) = sub_client = | ||
928 | kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
929 | if (!(sub_client)) { | ||
930 | return -ENOMEM; | ||
931 | } | ||
932 | sub_client->addr = 0x48 + addr; | ||
933 | i2c_set_clientdata(sub_client, NULL); | ||
934 | sub_client->adapter = adapter; | ||
935 | sub_client->driver = &w83791d_driver; | ||
936 | strlcpy(sub_client->name, "w83791d subclient", I2C_NAME_SIZE); | ||
937 | if ((err = i2c_attach_client(sub_client))) { | ||
938 | dev_err(&client->dev, "subclient registration " | ||
939 | "at address 0x%x failed\n", sub_client->addr); | ||
940 | kfree(sub_client); | ||
941 | return err; | ||
942 | } | ||
943 | return 0; | ||
944 | } | ||
945 | |||
946 | |||
947 | static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | ||
948 | int kind, struct i2c_client *client) | ||
949 | { | 921 | { |
922 | struct i2c_adapter *adapter = client->adapter; | ||
950 | struct w83791d_data *data = i2c_get_clientdata(client); | 923 | struct w83791d_data *data = i2c_get_clientdata(client); |
924 | int address = client->addr; | ||
951 | int i, id, err; | 925 | int i, id, err; |
952 | u8 val; | 926 | u8 val; |
953 | 927 | ||
@@ -971,10 +945,7 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
971 | 945 | ||
972 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); | 946 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); |
973 | if (!(val & 0x08)) { | 947 | if (!(val & 0x08)) { |
974 | err = w83791d_create_subclient(adapter, client, | 948 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); |
975 | val & 0x7, &data->lm75[0]); | ||
976 | if (err < 0) | ||
977 | goto error_sc_0; | ||
978 | } | 949 | } |
979 | if (!(val & 0x80)) { | 950 | if (!(val & 0x80)) { |
980 | if ((data->lm75[0] != NULL) && | 951 | if ((data->lm75[0] != NULL) && |
@@ -986,10 +957,8 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
986 | err = -ENODEV; | 957 | err = -ENODEV; |
987 | goto error_sc_1; | 958 | goto error_sc_1; |
988 | } | 959 | } |
989 | err = w83791d_create_subclient(adapter, client, | 960 | data->lm75[1] = i2c_new_dummy(adapter, |
990 | (val >> 4) & 0x7, &data->lm75[1]); | 961 | 0x48 + ((val >> 4) & 0x7)); |
991 | if (err < 0) | ||
992 | goto error_sc_1; | ||
993 | } | 962 | } |
994 | 963 | ||
995 | return 0; | 964 | return 0; |
@@ -997,53 +966,31 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
997 | /* Undo inits in case of errors */ | 966 | /* Undo inits in case of errors */ |
998 | 967 | ||
999 | error_sc_1: | 968 | error_sc_1: |
1000 | if (data->lm75[0] != NULL) { | 969 | if (data->lm75[0] != NULL) |
1001 | i2c_detach_client(data->lm75[0]); | 970 | i2c_unregister_device(data->lm75[0]); |
1002 | kfree(data->lm75[0]); | ||
1003 | } | ||
1004 | error_sc_0: | 971 | error_sc_0: |
1005 | return err; | 972 | return err; |
1006 | } | 973 | } |
1007 | 974 | ||
1008 | 975 | ||
1009 | static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | 976 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
977 | static int w83791d_detect(struct i2c_client *client, int kind, | ||
978 | struct i2c_board_info *info) | ||
1010 | { | 979 | { |
1011 | struct i2c_client *client; | 980 | struct i2c_adapter *adapter = client->adapter; |
1012 | struct device *dev; | 981 | int val1, val2; |
1013 | struct w83791d_data *data; | 982 | unsigned short address = client->addr; |
1014 | int i, val1, val2; | ||
1015 | int err = 0; | ||
1016 | const char *client_name = ""; | ||
1017 | 983 | ||
1018 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 984 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1019 | goto error0; | 985 | return -ENODEV; |
1020 | } | 986 | } |
1021 | 987 | ||
1022 | /* OK. For now, we presume we have a valid client. We now create the | ||
1023 | client structure, even though we cannot fill it completely yet. | ||
1024 | But it allows us to access w83791d_{read,write}_value. */ | ||
1025 | if (!(data = kzalloc(sizeof(struct w83791d_data), GFP_KERNEL))) { | ||
1026 | err = -ENOMEM; | ||
1027 | goto error0; | ||
1028 | } | ||
1029 | |||
1030 | client = &data->client; | ||
1031 | dev = &client->dev; | ||
1032 | i2c_set_clientdata(client, data); | ||
1033 | client->addr = address; | ||
1034 | client->adapter = adapter; | ||
1035 | client->driver = &w83791d_driver; | ||
1036 | mutex_init(&data->update_lock); | ||
1037 | |||
1038 | /* Now, we do the remaining detection. */ | ||
1039 | |||
1040 | /* The w83791d may be stuck in some other bank than bank 0. This may | 988 | /* The w83791d may be stuck in some other bank than bank 0. This may |
1041 | make reading other information impossible. Specify a force=... | 989 | make reading other information impossible. Specify a force=... |
1042 | parameter, and the Winbond will be reset to the right bank. */ | 990 | parameter, and the Winbond will be reset to the right bank. */ |
1043 | if (kind < 0) { | 991 | if (kind < 0) { |
1044 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { | 992 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { |
1045 | dev_dbg(dev, "Detection failed at step 1\n"); | 993 | return -ENODEV; |
1046 | goto error1; | ||
1047 | } | 994 | } |
1048 | val1 = w83791d_read(client, W83791D_REG_BANK); | 995 | val1 = w83791d_read(client, W83791D_REG_BANK); |
1049 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 996 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
@@ -1052,15 +999,13 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1052 | /* yes it is Bank0 */ | 999 | /* yes it is Bank0 */ |
1053 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | 1000 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || |
1054 | ((val1 & 0x80) && (val2 != 0x5c))) { | 1001 | ((val1 & 0x80) && (val2 != 0x5c))) { |
1055 | dev_dbg(dev, "Detection failed at step 2\n"); | 1002 | return -ENODEV; |
1056 | goto error1; | ||
1057 | } | 1003 | } |
1058 | } | 1004 | } |
1059 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR | 1005 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR |
1060 | should match */ | 1006 | should match */ |
1061 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { | 1007 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { |
1062 | dev_dbg(dev, "Detection failed at step 3\n"); | 1008 | return -ENODEV; |
1063 | goto error1; | ||
1064 | } | 1009 | } |
1065 | } | 1010 | } |
1066 | 1011 | ||
@@ -1075,30 +1020,33 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1075 | /* get vendor ID */ | 1020 | /* get vendor ID */ |
1076 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 1021 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
1077 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1022 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ |
1078 | dev_dbg(dev, "Detection failed at step 4\n"); | 1023 | return -ENODEV; |
1079 | goto error1; | ||
1080 | } | 1024 | } |
1081 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); | 1025 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); |
1082 | if (val1 == 0x71) { | 1026 | if (val1 == 0x71) { |
1083 | kind = w83791d; | 1027 | kind = w83791d; |
1084 | } else { | 1028 | } else { |
1085 | if (kind == 0) | 1029 | if (kind == 0) |
1086 | dev_warn(dev, | 1030 | dev_warn(&adapter->dev, |
1087 | "w83791d: Ignoring 'force' parameter " | 1031 | "w83791d: Ignoring 'force' parameter " |
1088 | "for unknown chip at adapter %d, " | 1032 | "for unknown chip at adapter %d, " |
1089 | "address 0x%02x\n", | 1033 | "address 0x%02x\n", |
1090 | i2c_adapter_id(adapter), address); | 1034 | i2c_adapter_id(adapter), address); |
1091 | goto error1; | 1035 | return -ENODEV; |
1092 | } | 1036 | } |
1093 | } | 1037 | } |
1094 | 1038 | ||
1095 | if (kind == w83791d) { | 1039 | strlcpy(info->type, "w83791d", I2C_NAME_SIZE); |
1096 | client_name = "w83791d"; | 1040 | |
1097 | } else { | 1041 | return 0; |
1098 | dev_err(dev, "w83791d: Internal error: unknown kind (%d)?!?\n", | 1042 | } |
1099 | kind); | 1043 | |
1100 | goto error1; | 1044 | static int w83791d_probe(struct i2c_client *client, |
1101 | } | 1045 | const struct i2c_device_id *id) |
1046 | { | ||
1047 | struct w83791d_data *data; | ||
1048 | struct device *dev = &client->dev; | ||
1049 | int i, val1, err; | ||
1102 | 1050 | ||
1103 | #ifdef DEBUG | 1051 | #ifdef DEBUG |
1104 | val1 = w83791d_read(client, W83791D_REG_DID_VID4); | 1052 | val1 = w83791d_read(client, W83791D_REG_DID_VID4); |
@@ -1106,15 +1054,18 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1106 | (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); | 1054 | (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); |
1107 | #endif | 1055 | #endif |
1108 | 1056 | ||
1109 | /* Fill in the remaining client fields and put into the global list */ | 1057 | data = kzalloc(sizeof(struct w83791d_data), GFP_KERNEL); |
1110 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 1058 | if (!data) { |
1059 | err = -ENOMEM; | ||
1060 | goto error0; | ||
1061 | } | ||
1111 | 1062 | ||
1112 | /* Tell the I2C layer a new client has arrived */ | 1063 | i2c_set_clientdata(client, data); |
1113 | if ((err = i2c_attach_client(client))) | 1064 | mutex_init(&data->update_lock); |
1114 | goto error1; | ||
1115 | 1065 | ||
1116 | if ((err = w83791d_detect_subclients(adapter, address, kind, client))) | 1066 | err = w83791d_detect_subclients(client); |
1117 | goto error2; | 1067 | if (err) |
1068 | goto error1; | ||
1118 | 1069 | ||
1119 | /* Initialize the chip */ | 1070 | /* Initialize the chip */ |
1120 | w83791d_init_client(client); | 1071 | w83791d_init_client(client); |
@@ -1141,43 +1092,29 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1141 | error4: | 1092 | error4: |
1142 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); | 1093 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
1143 | error3: | 1094 | error3: |
1144 | if (data->lm75[0] != NULL) { | 1095 | if (data->lm75[0] != NULL) |
1145 | i2c_detach_client(data->lm75[0]); | 1096 | i2c_unregister_device(data->lm75[0]); |
1146 | kfree(data->lm75[0]); | 1097 | if (data->lm75[1] != NULL) |
1147 | } | 1098 | i2c_unregister_device(data->lm75[1]); |
1148 | if (data->lm75[1] != NULL) { | ||
1149 | i2c_detach_client(data->lm75[1]); | ||
1150 | kfree(data->lm75[1]); | ||
1151 | } | ||
1152 | error2: | ||
1153 | i2c_detach_client(client); | ||
1154 | error1: | 1099 | error1: |
1155 | kfree(data); | 1100 | kfree(data); |
1156 | error0: | 1101 | error0: |
1157 | return err; | 1102 | return err; |
1158 | } | 1103 | } |
1159 | 1104 | ||
1160 | static int w83791d_detach_client(struct i2c_client *client) | 1105 | static int w83791d_remove(struct i2c_client *client) |
1161 | { | 1106 | { |
1162 | struct w83791d_data *data = i2c_get_clientdata(client); | 1107 | struct w83791d_data *data = i2c_get_clientdata(client); |
1163 | int err; | ||
1164 | |||
1165 | /* main client */ | ||
1166 | if (data) { | ||
1167 | hwmon_device_unregister(data->hwmon_dev); | ||
1168 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); | ||
1169 | } | ||
1170 | 1108 | ||
1171 | if ((err = i2c_detach_client(client))) | 1109 | hwmon_device_unregister(data->hwmon_dev); |
1172 | return err; | 1110 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
1173 | 1111 | ||
1174 | /* main client */ | 1112 | if (data->lm75[0] != NULL) |
1175 | if (data) | 1113 | i2c_unregister_device(data->lm75[0]); |
1176 | kfree(data); | 1114 | if (data->lm75[1] != NULL) |
1177 | /* subclient */ | 1115 | i2c_unregister_device(data->lm75[1]); |
1178 | else | ||
1179 | kfree(client); | ||
1180 | 1116 | ||
1117 | kfree(data); | ||
1181 | return 0; | 1118 | return 0; |
1182 | } | 1119 | } |
1183 | 1120 | ||
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 299629d47ed6..cf94c5b0c879 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -267,9 +267,7 @@ DIV_TO_REG(long val) | |||
267 | } | 267 | } |
268 | 268 | ||
269 | struct w83792d_data { | 269 | struct w83792d_data { |
270 | struct i2c_client client; | ||
271 | struct device *hwmon_dev; | 270 | struct device *hwmon_dev; |
272 | enum chips type; | ||
273 | 271 | ||
274 | struct mutex update_lock; | 272 | struct mutex update_lock; |
275 | char valid; /* !=0 if following fields are valid */ | 273 | char valid; /* !=0 if following fields are valid */ |
@@ -299,9 +297,11 @@ struct w83792d_data { | |||
299 | u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ | 297 | u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ |
300 | }; | 298 | }; |
301 | 299 | ||
302 | static int w83792d_attach_adapter(struct i2c_adapter *adapter); | 300 | static int w83792d_probe(struct i2c_client *client, |
303 | static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind); | 301 | const struct i2c_device_id *id); |
304 | static int w83792d_detach_client(struct i2c_client *client); | 302 | static int w83792d_detect(struct i2c_client *client, int kind, |
303 | struct i2c_board_info *info); | ||
304 | static int w83792d_remove(struct i2c_client *client); | ||
305 | static struct w83792d_data *w83792d_update_device(struct device *dev); | 305 | static struct w83792d_data *w83792d_update_device(struct device *dev); |
306 | 306 | ||
307 | #ifdef DEBUG | 307 | #ifdef DEBUG |
@@ -310,12 +310,22 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev); | |||
310 | 310 | ||
311 | static void w83792d_init_client(struct i2c_client *client); | 311 | static void w83792d_init_client(struct i2c_client *client); |
312 | 312 | ||
313 | static const struct i2c_device_id w83792d_id[] = { | ||
314 | { "w83792d", w83792d }, | ||
315 | { } | ||
316 | }; | ||
317 | MODULE_DEVICE_TABLE(i2c, w83792d_id); | ||
318 | |||
313 | static struct i2c_driver w83792d_driver = { | 319 | static struct i2c_driver w83792d_driver = { |
320 | .class = I2C_CLASS_HWMON, | ||
314 | .driver = { | 321 | .driver = { |
315 | .name = "w83792d", | 322 | .name = "w83792d", |
316 | }, | 323 | }, |
317 | .attach_adapter = w83792d_attach_adapter, | 324 | .probe = w83792d_probe, |
318 | .detach_client = w83792d_detach_client, | 325 | .remove = w83792d_remove, |
326 | .id_table = w83792d_id, | ||
327 | .detect = w83792d_detect, | ||
328 | .address_data = &addr_data, | ||
319 | }; | 329 | }; |
320 | 330 | ||
321 | static inline long in_count_from_reg(int nr, struct w83792d_data *data) | 331 | static inline long in_count_from_reg(int nr, struct w83792d_data *data) |
@@ -864,53 +874,14 @@ store_sf2_level(struct device *dev, struct device_attribute *attr, | |||
864 | return count; | 874 | return count; |
865 | } | 875 | } |
866 | 876 | ||
867 | /* This function is called when: | ||
868 | * w83792d_driver is inserted (when this module is loaded), for each | ||
869 | available adapter | ||
870 | * when a new adapter is inserted (and w83792d_driver is still present) */ | ||
871 | static int | ||
872 | w83792d_attach_adapter(struct i2c_adapter *adapter) | ||
873 | { | ||
874 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
875 | return 0; | ||
876 | return i2c_probe(adapter, &addr_data, w83792d_detect); | ||
877 | } | ||
878 | |||
879 | |||
880 | static int | ||
881 | w83792d_create_subclient(struct i2c_adapter *adapter, | ||
882 | struct i2c_client *new_client, int addr, | ||
883 | struct i2c_client **sub_cli) | ||
884 | { | ||
885 | int err; | ||
886 | struct i2c_client *sub_client; | ||
887 | |||
888 | (*sub_cli) = sub_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
889 | if (!(sub_client)) { | ||
890 | return -ENOMEM; | ||
891 | } | ||
892 | sub_client->addr = 0x48 + addr; | ||
893 | i2c_set_clientdata(sub_client, NULL); | ||
894 | sub_client->adapter = adapter; | ||
895 | sub_client->driver = &w83792d_driver; | ||
896 | sub_client->flags = 0; | ||
897 | strlcpy(sub_client->name, "w83792d subclient", I2C_NAME_SIZE); | ||
898 | if ((err = i2c_attach_client(sub_client))) { | ||
899 | dev_err(&new_client->dev, "subclient registration " | ||
900 | "at address 0x%x failed\n", sub_client->addr); | ||
901 | kfree(sub_client); | ||
902 | return err; | ||
903 | } | ||
904 | return 0; | ||
905 | } | ||
906 | |||
907 | 877 | ||
908 | static int | 878 | static int |
909 | w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | 879 | w83792d_detect_subclients(struct i2c_client *new_client) |
910 | struct i2c_client *new_client) | ||
911 | { | 880 | { |
912 | int i, id, err; | 881 | int i, id, err; |
882 | int address = new_client->addr; | ||
913 | u8 val; | 883 | u8 val; |
884 | struct i2c_adapter *adapter = new_client->adapter; | ||
914 | struct w83792d_data *data = i2c_get_clientdata(new_client); | 885 | struct w83792d_data *data = i2c_get_clientdata(new_client); |
915 | 886 | ||
916 | id = i2c_adapter_id(adapter); | 887 | id = i2c_adapter_id(adapter); |
@@ -932,10 +903,7 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
932 | 903 | ||
933 | val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); | 904 | val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); |
934 | if (!(val & 0x08)) { | 905 | if (!(val & 0x08)) { |
935 | err = w83792d_create_subclient(adapter, new_client, val & 0x7, | 906 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); |
936 | &data->lm75[0]); | ||
937 | if (err < 0) | ||
938 | goto ERROR_SC_0; | ||
939 | } | 907 | } |
940 | if (!(val & 0x80)) { | 908 | if (!(val & 0x80)) { |
941 | if ((data->lm75[0] != NULL) && | 909 | if ((data->lm75[0] != NULL) && |
@@ -945,10 +913,8 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
945 | err = -ENODEV; | 913 | err = -ENODEV; |
946 | goto ERROR_SC_1; | 914 | goto ERROR_SC_1; |
947 | } | 915 | } |
948 | err = w83792d_create_subclient(adapter, new_client, | 916 | data->lm75[1] = i2c_new_dummy(adapter, |
949 | (val >> 4) & 0x7, &data->lm75[1]); | 917 | 0x48 + ((val >> 4) & 0x7)); |
950 | if (err < 0) | ||
951 | goto ERROR_SC_1; | ||
952 | } | 918 | } |
953 | 919 | ||
954 | return 0; | 920 | return 0; |
@@ -956,10 +922,8 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
956 | /* Undo inits in case of errors */ | 922 | /* Undo inits in case of errors */ |
957 | 923 | ||
958 | ERROR_SC_1: | 924 | ERROR_SC_1: |
959 | if (data->lm75[0] != NULL) { | 925 | if (data->lm75[0] != NULL) |
960 | i2c_detach_client(data->lm75[0]); | 926 | i2c_unregister_device(data->lm75[0]); |
961 | kfree(data->lm75[0]); | ||
962 | } | ||
963 | ERROR_SC_0: | 927 | ERROR_SC_0: |
964 | return err; | 928 | return err; |
965 | } | 929 | } |
@@ -1294,47 +1258,25 @@ static const struct attribute_group w83792d_group = { | |||
1294 | .attrs = w83792d_attributes, | 1258 | .attrs = w83792d_attributes, |
1295 | }; | 1259 | }; |
1296 | 1260 | ||
1261 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
1297 | static int | 1262 | static int |
1298 | w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | 1263 | w83792d_detect(struct i2c_client *client, int kind, struct i2c_board_info *info) |
1299 | { | 1264 | { |
1300 | int i = 0, val1 = 0, val2; | 1265 | struct i2c_adapter *adapter = client->adapter; |
1301 | struct i2c_client *client; | 1266 | int val1, val2; |
1302 | struct device *dev; | 1267 | unsigned short address = client->addr; |
1303 | struct w83792d_data *data; | ||
1304 | int err = 0; | ||
1305 | const char *client_name = ""; | ||
1306 | 1268 | ||
1307 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1269 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1308 | goto ERROR0; | 1270 | return -ENODEV; |
1309 | } | ||
1310 | |||
1311 | /* OK. For now, we presume we have a valid client. We now create the | ||
1312 | client structure, even though we cannot fill it completely yet. | ||
1313 | But it allows us to access w83792d_{read,write}_value. */ | ||
1314 | |||
1315 | if (!(data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL))) { | ||
1316 | err = -ENOMEM; | ||
1317 | goto ERROR0; | ||
1318 | } | 1271 | } |
1319 | 1272 | ||
1320 | client = &data->client; | ||
1321 | dev = &client->dev; | ||
1322 | i2c_set_clientdata(client, data); | ||
1323 | client->addr = address; | ||
1324 | client->adapter = adapter; | ||
1325 | client->driver = &w83792d_driver; | ||
1326 | client->flags = 0; | ||
1327 | |||
1328 | /* Now, we do the remaining detection. */ | ||
1329 | |||
1330 | /* The w83792d may be stuck in some other bank than bank 0. This may | 1273 | /* The w83792d may be stuck in some other bank than bank 0. This may |
1331 | make reading other information impossible. Specify a force=... or | 1274 | make reading other information impossible. Specify a force=... or |
1332 | force_*=... parameter, and the Winbond will be reset to the right | 1275 | force_*=... parameter, and the Winbond will be reset to the right |
1333 | bank. */ | 1276 | bank. */ |
1334 | if (kind < 0) { | 1277 | if (kind < 0) { |
1335 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { | 1278 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { |
1336 | dev_dbg(dev, "Detection failed at step 1\n"); | 1279 | return -ENODEV; |
1337 | goto ERROR1; | ||
1338 | } | 1280 | } |
1339 | val1 = w83792d_read_value(client, W83792D_REG_BANK); | 1281 | val1 = w83792d_read_value(client, W83792D_REG_BANK); |
1340 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | 1282 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
@@ -1342,16 +1284,14 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1342 | if (!(val1 & 0x07)) { /* is Bank0 */ | 1284 | if (!(val1 & 0x07)) { /* is Bank0 */ |
1343 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | 1285 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || |
1344 | ((val1 & 0x80) && (val2 != 0x5c))) { | 1286 | ((val1 & 0x80) && (val2 != 0x5c))) { |
1345 | dev_dbg(dev, "Detection failed at step 2\n"); | 1287 | return -ENODEV; |
1346 | goto ERROR1; | ||
1347 | } | 1288 | } |
1348 | } | 1289 | } |
1349 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR | 1290 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR |
1350 | should match */ | 1291 | should match */ |
1351 | if (w83792d_read_value(client, | 1292 | if (w83792d_read_value(client, |
1352 | W83792D_REG_I2C_ADDR) != address) { | 1293 | W83792D_REG_I2C_ADDR) != address) { |
1353 | dev_dbg(dev, "Detection failed at step 3\n"); | 1294 | return -ENODEV; |
1354 | goto ERROR1; | ||
1355 | } | 1295 | } |
1356 | } | 1296 | } |
1357 | 1297 | ||
@@ -1367,45 +1307,48 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1367 | /* get vendor ID */ | 1307 | /* get vendor ID */ |
1368 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | 1308 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
1369 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1309 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ |
1370 | goto ERROR1; | 1310 | return -ENODEV; |
1371 | } | 1311 | } |
1372 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); | 1312 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); |
1373 | if (val1 == 0x7a) { | 1313 | if (val1 == 0x7a) { |
1374 | kind = w83792d; | 1314 | kind = w83792d; |
1375 | } else { | 1315 | } else { |
1376 | if (kind == 0) | 1316 | if (kind == 0) |
1377 | dev_warn(dev, | 1317 | dev_warn(&adapter->dev, |
1378 | "w83792d: Ignoring 'force' parameter for" | 1318 | "w83792d: Ignoring 'force' parameter for" |
1379 | " unknown chip at adapter %d, address" | 1319 | " unknown chip at adapter %d, address" |
1380 | " 0x%02x\n", i2c_adapter_id(adapter), | 1320 | " 0x%02x\n", i2c_adapter_id(adapter), |
1381 | address); | 1321 | address); |
1382 | goto ERROR1; | 1322 | return -ENODEV; |
1383 | } | 1323 | } |
1384 | } | 1324 | } |
1385 | 1325 | ||
1386 | if (kind == w83792d) { | 1326 | strlcpy(info->type, "w83792d", I2C_NAME_SIZE); |
1387 | client_name = "w83792d"; | 1327 | |
1388 | } else { | 1328 | return 0; |
1389 | dev_err(dev, "w83792d: Internal error: unknown kind (%d)?!?\n", | 1329 | } |
1390 | kind); | 1330 | |
1391 | goto ERROR1; | 1331 | static int |
1392 | } | 1332 | w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id) |
1333 | { | ||
1334 | struct w83792d_data *data; | ||
1335 | struct device *dev = &client->dev; | ||
1336 | int i, val1, err; | ||
1393 | 1337 | ||
1394 | /* Fill in the remaining client fields and put into the global list */ | 1338 | data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL); |
1395 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 1339 | if (!data) { |
1396 | data->type = kind; | 1340 | err = -ENOMEM; |
1341 | goto ERROR0; | ||
1342 | } | ||
1397 | 1343 | ||
1344 | i2c_set_clientdata(client, data); | ||
1398 | data->valid = 0; | 1345 | data->valid = 0; |
1399 | mutex_init(&data->update_lock); | 1346 | mutex_init(&data->update_lock); |
1400 | 1347 | ||
1401 | /* Tell the I2C layer a new client has arrived */ | 1348 | err = w83792d_detect_subclients(client); |
1402 | if ((err = i2c_attach_client(client))) | 1349 | if (err) |
1403 | goto ERROR1; | 1350 | goto ERROR1; |
1404 | 1351 | ||
1405 | if ((err = w83792d_detect_subclients(adapter, address, | ||
1406 | kind, client))) | ||
1407 | goto ERROR2; | ||
1408 | |||
1409 | /* Initialize the chip */ | 1352 | /* Initialize the chip */ |
1410 | w83792d_init_client(client); | 1353 | w83792d_init_client(client); |
1411 | 1354 | ||
@@ -1457,16 +1400,10 @@ exit_remove_files: | |||
1457 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | 1400 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) |
1458 | sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); | 1401 | sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); |
1459 | ERROR3: | 1402 | ERROR3: |
1460 | if (data->lm75[0] != NULL) { | 1403 | if (data->lm75[0] != NULL) |
1461 | i2c_detach_client(data->lm75[0]); | 1404 | i2c_unregister_device(data->lm75[0]); |
1462 | kfree(data->lm75[0]); | 1405 | if (data->lm75[1] != NULL) |
1463 | } | 1406 | i2c_unregister_device(data->lm75[1]); |
1464 | if (data->lm75[1] != NULL) { | ||
1465 | i2c_detach_client(data->lm75[1]); | ||
1466 | kfree(data->lm75[1]); | ||
1467 | } | ||
1468 | ERROR2: | ||
1469 | i2c_detach_client(client); | ||
1470 | ERROR1: | 1407 | ERROR1: |
1471 | kfree(data); | 1408 | kfree(data); |
1472 | ERROR0: | 1409 | ERROR0: |
@@ -1474,30 +1411,23 @@ ERROR0: | |||
1474 | } | 1411 | } |
1475 | 1412 | ||
1476 | static int | 1413 | static int |
1477 | w83792d_detach_client(struct i2c_client *client) | 1414 | w83792d_remove(struct i2c_client *client) |
1478 | { | 1415 | { |
1479 | struct w83792d_data *data = i2c_get_clientdata(client); | 1416 | struct w83792d_data *data = i2c_get_clientdata(client); |
1480 | int err, i; | 1417 | int i; |
1481 | |||
1482 | /* main client */ | ||
1483 | if (data) { | ||
1484 | hwmon_device_unregister(data->hwmon_dev); | ||
1485 | sysfs_remove_group(&client->dev.kobj, &w83792d_group); | ||
1486 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | ||
1487 | sysfs_remove_group(&client->dev.kobj, | ||
1488 | &w83792d_group_fan[i]); | ||
1489 | } | ||
1490 | 1418 | ||
1491 | if ((err = i2c_detach_client(client))) | 1419 | hwmon_device_unregister(data->hwmon_dev); |
1492 | return err; | 1420 | sysfs_remove_group(&client->dev.kobj, &w83792d_group); |
1421 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | ||
1422 | sysfs_remove_group(&client->dev.kobj, | ||
1423 | &w83792d_group_fan[i]); | ||
1493 | 1424 | ||
1494 | /* main client */ | 1425 | if (data->lm75[0] != NULL) |
1495 | if (data) | 1426 | i2c_unregister_device(data->lm75[0]); |
1496 | kfree(data); | 1427 | if (data->lm75[1] != NULL) |
1497 | /* subclient */ | 1428 | i2c_unregister_device(data->lm75[1]); |
1498 | else | ||
1499 | kfree(client); | ||
1500 | 1429 | ||
1430 | kfree(data); | ||
1501 | return 0; | 1431 | return 0; |
1502 | } | 1432 | } |
1503 | 1433 | ||
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index ed3c019b78c7..0a739f1c69be 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c | |||
@@ -179,7 +179,6 @@ static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) | |||
179 | } | 179 | } |
180 | 180 | ||
181 | struct w83793_data { | 181 | struct w83793_data { |
182 | struct i2c_client client; | ||
183 | struct i2c_client *lm75[2]; | 182 | struct i2c_client *lm75[2]; |
184 | struct device *hwmon_dev; | 183 | struct device *hwmon_dev; |
185 | struct mutex update_lock; | 184 | struct mutex update_lock; |
@@ -226,19 +225,31 @@ struct w83793_data { | |||
226 | 225 | ||
227 | static u8 w83793_read_value(struct i2c_client *client, u16 reg); | 226 | static u8 w83793_read_value(struct i2c_client *client, u16 reg); |
228 | static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); | 227 | static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); |
229 | static int w83793_attach_adapter(struct i2c_adapter *adapter); | 228 | static int w83793_probe(struct i2c_client *client, |
230 | static int w83793_detect(struct i2c_adapter *adapter, int address, int kind); | 229 | const struct i2c_device_id *id); |
231 | static int w83793_detach_client(struct i2c_client *client); | 230 | static int w83793_detect(struct i2c_client *client, int kind, |
231 | struct i2c_board_info *info); | ||
232 | static int w83793_remove(struct i2c_client *client); | ||
232 | static void w83793_init_client(struct i2c_client *client); | 233 | static void w83793_init_client(struct i2c_client *client); |
233 | static void w83793_update_nonvolatile(struct device *dev); | 234 | static void w83793_update_nonvolatile(struct device *dev); |
234 | static struct w83793_data *w83793_update_device(struct device *dev); | 235 | static struct w83793_data *w83793_update_device(struct device *dev); |
235 | 236 | ||
237 | static const struct i2c_device_id w83793_id[] = { | ||
238 | { "w83793", w83793 }, | ||
239 | { } | ||
240 | }; | ||
241 | MODULE_DEVICE_TABLE(i2c, w83793_id); | ||
242 | |||
236 | static struct i2c_driver w83793_driver = { | 243 | static struct i2c_driver w83793_driver = { |
244 | .class = I2C_CLASS_HWMON, | ||
237 | .driver = { | 245 | .driver = { |
238 | .name = "w83793", | 246 | .name = "w83793", |
239 | }, | 247 | }, |
240 | .attach_adapter = w83793_attach_adapter, | 248 | .probe = w83793_probe, |
241 | .detach_client = w83793_detach_client, | 249 | .remove = w83793_remove, |
250 | .id_table = w83793_id, | ||
251 | .detect = w83793_detect, | ||
252 | .address_data = &addr_data, | ||
242 | }; | 253 | }; |
243 | 254 | ||
244 | static ssize_t | 255 | static ssize_t |
@@ -1053,89 +1064,51 @@ static void w83793_init_client(struct i2c_client *client) | |||
1053 | 1064 | ||
1054 | } | 1065 | } |
1055 | 1066 | ||
1056 | static int w83793_attach_adapter(struct i2c_adapter *adapter) | 1067 | static int w83793_remove(struct i2c_client *client) |
1057 | { | ||
1058 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
1059 | return 0; | ||
1060 | return i2c_probe(adapter, &addr_data, w83793_detect); | ||
1061 | } | ||
1062 | |||
1063 | static int w83793_detach_client(struct i2c_client *client) | ||
1064 | { | 1068 | { |
1065 | struct w83793_data *data = i2c_get_clientdata(client); | 1069 | struct w83793_data *data = i2c_get_clientdata(client); |
1066 | struct device *dev = &client->dev; | 1070 | struct device *dev = &client->dev; |
1067 | int err, i; | 1071 | int i; |
1068 | 1072 | ||
1069 | /* main client */ | 1073 | hwmon_device_unregister(data->hwmon_dev); |
1070 | if (data) { | ||
1071 | hwmon_device_unregister(data->hwmon_dev); | ||
1072 | 1074 | ||
1073 | for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) | 1075 | for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) |
1074 | device_remove_file(dev, | 1076 | device_remove_file(dev, |
1075 | &w83793_sensor_attr_2[i].dev_attr); | 1077 | &w83793_sensor_attr_2[i].dev_attr); |
1076 | 1078 | ||
1077 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | 1079 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) |
1078 | device_remove_file(dev, &sda_single_files[i].dev_attr); | 1080 | device_remove_file(dev, &sda_single_files[i].dev_attr); |
1079 | 1081 | ||
1080 | for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) | 1082 | for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) |
1081 | device_remove_file(dev, &w83793_vid[i].dev_attr); | 1083 | device_remove_file(dev, &w83793_vid[i].dev_attr); |
1082 | device_remove_file(dev, &dev_attr_vrm); | 1084 | device_remove_file(dev, &dev_attr_vrm); |
1083 | 1085 | ||
1084 | for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) | 1086 | for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) |
1085 | device_remove_file(dev, &w83793_left_fan[i].dev_attr); | 1087 | device_remove_file(dev, &w83793_left_fan[i].dev_attr); |
1086 | 1088 | ||
1087 | for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) | 1089 | for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) |
1088 | device_remove_file(dev, &w83793_left_pwm[i].dev_attr); | 1090 | device_remove_file(dev, &w83793_left_pwm[i].dev_attr); |
1089 | 1091 | ||
1090 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) | 1092 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
1091 | device_remove_file(dev, &w83793_temp[i].dev_attr); | 1093 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
1092 | } | ||
1093 | 1094 | ||
1094 | if ((err = i2c_detach_client(client))) | 1095 | if (data->lm75[0] != NULL) |
1095 | return err; | 1096 | i2c_unregister_device(data->lm75[0]); |
1097 | if (data->lm75[1] != NULL) | ||
1098 | i2c_unregister_device(data->lm75[1]); | ||
1096 | 1099 | ||
1097 | /* main client */ | 1100 | kfree(data); |
1098 | if (data) | ||
1099 | kfree(data); | ||
1100 | /* subclient */ | ||
1101 | else | ||
1102 | kfree(client); | ||
1103 | 1101 | ||
1104 | return 0; | 1102 | return 0; |
1105 | } | 1103 | } |
1106 | 1104 | ||
1107 | static int | 1105 | static int |
1108 | w83793_create_subclient(struct i2c_adapter *adapter, | 1106 | w83793_detect_subclients(struct i2c_client *client) |
1109 | struct i2c_client *client, int addr, | ||
1110 | struct i2c_client **sub_cli) | ||
1111 | { | ||
1112 | int err = 0; | ||
1113 | struct i2c_client *sub_client; | ||
1114 | |||
1115 | (*sub_cli) = sub_client = | ||
1116 | kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
1117 | if (!(sub_client)) { | ||
1118 | return -ENOMEM; | ||
1119 | } | ||
1120 | sub_client->addr = 0x48 + addr; | ||
1121 | i2c_set_clientdata(sub_client, NULL); | ||
1122 | sub_client->adapter = adapter; | ||
1123 | sub_client->driver = &w83793_driver; | ||
1124 | strlcpy(sub_client->name, "w83793 subclient", I2C_NAME_SIZE); | ||
1125 | if ((err = i2c_attach_client(sub_client))) { | ||
1126 | dev_err(&client->dev, "subclient registration " | ||
1127 | "at address 0x%x failed\n", sub_client->addr); | ||
1128 | kfree(sub_client); | ||
1129 | } | ||
1130 | return err; | ||
1131 | } | ||
1132 | |||
1133 | static int | ||
1134 | w83793_detect_subclients(struct i2c_adapter *adapter, int address, | ||
1135 | int kind, struct i2c_client *client) | ||
1136 | { | 1107 | { |
1137 | int i, id, err; | 1108 | int i, id, err; |
1109 | int address = client->addr; | ||
1138 | u8 tmp; | 1110 | u8 tmp; |
1111 | struct i2c_adapter *adapter = client->adapter; | ||
1139 | struct w83793_data *data = i2c_get_clientdata(client); | 1112 | struct w83793_data *data = i2c_get_clientdata(client); |
1140 | 1113 | ||
1141 | id = i2c_adapter_id(adapter); | 1114 | id = i2c_adapter_id(adapter); |
@@ -1158,11 +1131,7 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1158 | 1131 | ||
1159 | tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); | 1132 | tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); |
1160 | if (!(tmp & 0x08)) { | 1133 | if (!(tmp & 0x08)) { |
1161 | err = | 1134 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); |
1162 | w83793_create_subclient(adapter, client, tmp & 0x7, | ||
1163 | &data->lm75[0]); | ||
1164 | if (err < 0) | ||
1165 | goto ERROR_SC_0; | ||
1166 | } | 1135 | } |
1167 | if (!(tmp & 0x80)) { | 1136 | if (!(tmp & 0x80)) { |
1168 | if ((data->lm75[0] != NULL) | 1137 | if ((data->lm75[0] != NULL) |
@@ -1173,10 +1142,8 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1173 | err = -ENODEV; | 1142 | err = -ENODEV; |
1174 | goto ERROR_SC_1; | 1143 | goto ERROR_SC_1; |
1175 | } | 1144 | } |
1176 | err = w83793_create_subclient(adapter, client, | 1145 | data->lm75[1] = i2c_new_dummy(adapter, |
1177 | (tmp >> 4) & 0x7, &data->lm75[1]); | 1146 | 0x48 + ((tmp >> 4) & 0x7)); |
1178 | if (err < 0) | ||
1179 | goto ERROR_SC_1; | ||
1180 | } | 1147 | } |
1181 | 1148 | ||
1182 | return 0; | 1149 | return 0; |
@@ -1184,69 +1151,44 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1184 | /* Undo inits in case of errors */ | 1151 | /* Undo inits in case of errors */ |
1185 | 1152 | ||
1186 | ERROR_SC_1: | 1153 | ERROR_SC_1: |
1187 | if (data->lm75[0] != NULL) { | 1154 | if (data->lm75[0] != NULL) |
1188 | i2c_detach_client(data->lm75[0]); | 1155 | i2c_unregister_device(data->lm75[0]); |
1189 | kfree(data->lm75[0]); | ||
1190 | } | ||
1191 | ERROR_SC_0: | 1156 | ERROR_SC_0: |
1192 | return err; | 1157 | return err; |
1193 | } | 1158 | } |
1194 | 1159 | ||
1195 | static int w83793_detect(struct i2c_adapter *adapter, int address, int kind) | 1160 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1161 | static int w83793_detect(struct i2c_client *client, int kind, | ||
1162 | struct i2c_board_info *info) | ||
1196 | { | 1163 | { |
1197 | int i; | 1164 | u8 tmp, bank; |
1198 | u8 tmp, val; | 1165 | struct i2c_adapter *adapter = client->adapter; |
1199 | struct i2c_client *client; | 1166 | unsigned short address = client->addr; |
1200 | struct device *dev; | ||
1201 | struct w83793_data *data; | ||
1202 | int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; | ||
1203 | int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; | ||
1204 | int files_temp = ARRAY_SIZE(w83793_temp) / 6; | ||
1205 | int err = 0; | ||
1206 | 1167 | ||
1207 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1168 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1208 | goto exit; | 1169 | return -ENODEV; |
1209 | } | 1170 | } |
1210 | 1171 | ||
1211 | /* OK. For now, we presume we have a valid client. We now create the | 1172 | bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); |
1212 | client structure, even though we cannot fill it completely yet. | ||
1213 | But it allows us to access w83793_{read,write}_value. */ | ||
1214 | |||
1215 | if (!(data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL))) { | ||
1216 | err = -ENOMEM; | ||
1217 | goto exit; | ||
1218 | } | ||
1219 | |||
1220 | client = &data->client; | ||
1221 | dev = &client->dev; | ||
1222 | i2c_set_clientdata(client, data); | ||
1223 | client->addr = address; | ||
1224 | client->adapter = adapter; | ||
1225 | client->driver = &w83793_driver; | ||
1226 | 1173 | ||
1227 | data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); | ||
1228 | |||
1229 | /* Now, we do the remaining detection. */ | ||
1230 | if (kind < 0) { | 1174 | if (kind < 0) { |
1231 | tmp = data->bank & 0x80 ? 0x5c : 0xa3; | 1175 | tmp = bank & 0x80 ? 0x5c : 0xa3; |
1232 | /* Check Winbond vendor ID */ | 1176 | /* Check Winbond vendor ID */ |
1233 | if (tmp != i2c_smbus_read_byte_data(client, | 1177 | if (tmp != i2c_smbus_read_byte_data(client, |
1234 | W83793_REG_VENDORID)) { | 1178 | W83793_REG_VENDORID)) { |
1235 | pr_debug("w83793: Detection failed at check " | 1179 | pr_debug("w83793: Detection failed at check " |
1236 | "vendor id\n"); | 1180 | "vendor id\n"); |
1237 | err = -ENODEV; | 1181 | return -ENODEV; |
1238 | goto free_mem; | ||
1239 | } | 1182 | } |
1240 | 1183 | ||
1241 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR | 1184 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR |
1242 | should match */ | 1185 | should match */ |
1243 | if ((data->bank & 0x07) == 0 | 1186 | if ((bank & 0x07) == 0 |
1244 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != | 1187 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != |
1245 | (address << 1)) { | 1188 | (address << 1)) { |
1246 | pr_debug("w83793: Detection failed at check " | 1189 | pr_debug("w83793: Detection failed at check " |
1247 | "i2c addr\n"); | 1190 | "i2c addr\n"); |
1248 | err = -ENODEV; | 1191 | return -ENODEV; |
1249 | goto free_mem; | ||
1250 | } | 1192 | } |
1251 | 1193 | ||
1252 | } | 1194 | } |
@@ -1255,30 +1197,47 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1255 | Winbond. Determine the chip type now */ | 1197 | Winbond. Determine the chip type now */ |
1256 | 1198 | ||
1257 | if (kind <= 0) { | 1199 | if (kind <= 0) { |
1258 | if (0x7b == w83793_read_value(client, W83793_REG_CHIPID)) { | 1200 | if (0x7b == i2c_smbus_read_byte_data(client, |
1201 | W83793_REG_CHIPID)) { | ||
1259 | kind = w83793; | 1202 | kind = w83793; |
1260 | } else { | 1203 | } else { |
1261 | if (kind == 0) | 1204 | if (kind == 0) |
1262 | dev_warn(&adapter->dev, "w83793: Ignoring " | 1205 | dev_warn(&adapter->dev, "w83793: Ignoring " |
1263 | "'force' parameter for unknown chip " | 1206 | "'force' parameter for unknown chip " |
1264 | "at address 0x%02x\n", address); | 1207 | "at address 0x%02x\n", address); |
1265 | err = -ENODEV; | 1208 | return -ENODEV; |
1266 | goto free_mem; | ||
1267 | } | 1209 | } |
1268 | } | 1210 | } |
1269 | 1211 | ||
1270 | /* Fill in the remaining client fields and put into the global list */ | 1212 | strlcpy(info->type, "w83793", I2C_NAME_SIZE); |
1271 | strlcpy(client->name, "w83793", I2C_NAME_SIZE); | 1213 | |
1214 | return 0; | ||
1215 | } | ||
1272 | 1216 | ||
1217 | static int w83793_probe(struct i2c_client *client, | ||
1218 | const struct i2c_device_id *id) | ||
1219 | { | ||
1220 | struct device *dev = &client->dev; | ||
1221 | struct w83793_data *data; | ||
1222 | int i, tmp, val, err; | ||
1223 | int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; | ||
1224 | int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; | ||
1225 | int files_temp = ARRAY_SIZE(w83793_temp) / 6; | ||
1226 | |||
1227 | data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL); | ||
1228 | if (!data) { | ||
1229 | err = -ENOMEM; | ||
1230 | goto exit; | ||
1231 | } | ||
1232 | |||
1233 | i2c_set_clientdata(client, data); | ||
1234 | data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); | ||
1273 | mutex_init(&data->update_lock); | 1235 | mutex_init(&data->update_lock); |
1274 | 1236 | ||
1275 | /* Tell the I2C layer a new client has arrived */ | 1237 | err = w83793_detect_subclients(client); |
1276 | if ((err = i2c_attach_client(client))) | 1238 | if (err) |
1277 | goto free_mem; | 1239 | goto free_mem; |
1278 | 1240 | ||
1279 | if ((err = w83793_detect_subclients(adapter, address, kind, client))) | ||
1280 | goto detach_client; | ||
1281 | |||
1282 | /* Initialize the chip */ | 1241 | /* Initialize the chip */ |
1283 | w83793_init_client(client); | 1242 | w83793_init_client(client); |
1284 | 1243 | ||
@@ -1459,16 +1418,10 @@ exit_remove: | |||
1459 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) | 1418 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
1460 | device_remove_file(dev, &w83793_temp[i].dev_attr); | 1419 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
1461 | 1420 | ||
1462 | if (data->lm75[0] != NULL) { | 1421 | if (data->lm75[0] != NULL) |
1463 | i2c_detach_client(data->lm75[0]); | 1422 | i2c_unregister_device(data->lm75[0]); |
1464 | kfree(data->lm75[0]); | 1423 | if (data->lm75[1] != NULL) |
1465 | } | 1424 | i2c_unregister_device(data->lm75[1]); |
1466 | if (data->lm75[1] != NULL) { | ||
1467 | i2c_detach_client(data->lm75[1]); | ||
1468 | kfree(data->lm75[1]); | ||
1469 | } | ||
1470 | detach_client: | ||
1471 | i2c_detach_client(client); | ||
1472 | free_mem: | 1425 | free_mem: |
1473 | kfree(data); | 1426 | kfree(data); |
1474 | exit: | 1427 | exit: |
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 52e268e25dab..ea295b9fc4f4 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c | |||
@@ -81,10 +81,11 @@ I2C_CLIENT_INSMOD_1(w83l785ts); | |||
81 | * Functions declaration | 81 | * Functions declaration |
82 | */ | 82 | */ |
83 | 83 | ||
84 | static int w83l785ts_attach_adapter(struct i2c_adapter *adapter); | 84 | static int w83l785ts_probe(struct i2c_client *client, |
85 | static int w83l785ts_detect(struct i2c_adapter *adapter, int address, | 85 | const struct i2c_device_id *id); |
86 | int kind); | 86 | static int w83l785ts_detect(struct i2c_client *client, int kind, |
87 | static int w83l785ts_detach_client(struct i2c_client *client); | 87 | struct i2c_board_info *info); |
88 | static int w83l785ts_remove(struct i2c_client *client); | ||
88 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); | 89 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); |
89 | static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); | 90 | static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); |
90 | 91 | ||
@@ -92,12 +93,22 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); | |||
92 | * Driver data (common to all clients) | 93 | * Driver data (common to all clients) |
93 | */ | 94 | */ |
94 | 95 | ||
96 | static const struct i2c_device_id w83l785ts_id[] = { | ||
97 | { "w83l785ts", w83l785ts }, | ||
98 | { } | ||
99 | }; | ||
100 | MODULE_DEVICE_TABLE(i2c, w83l785ts_id); | ||
101 | |||
95 | static struct i2c_driver w83l785ts_driver = { | 102 | static struct i2c_driver w83l785ts_driver = { |
103 | .class = I2C_CLASS_HWMON, | ||
96 | .driver = { | 104 | .driver = { |
97 | .name = "w83l785ts", | 105 | .name = "w83l785ts", |
98 | }, | 106 | }, |
99 | .attach_adapter = w83l785ts_attach_adapter, | 107 | .probe = w83l785ts_probe, |
100 | .detach_client = w83l785ts_detach_client, | 108 | .remove = w83l785ts_remove, |
109 | .id_table = w83l785ts_id, | ||
110 | .detect = w83l785ts_detect, | ||
111 | .address_data = &addr_data, | ||
101 | }; | 112 | }; |
102 | 113 | ||
103 | /* | 114 | /* |
@@ -105,7 +116,6 @@ static struct i2c_driver w83l785ts_driver = { | |||
105 | */ | 116 | */ |
106 | 117 | ||
107 | struct w83l785ts_data { | 118 | struct w83l785ts_data { |
108 | struct i2c_client client; | ||
109 | struct device *hwmon_dev; | 119 | struct device *hwmon_dev; |
110 | struct mutex update_lock; | 120 | struct mutex update_lock; |
111 | char valid; /* zero until following fields are valid */ | 121 | char valid; /* zero until following fields are valid */ |
@@ -135,40 +145,14 @@ static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1); | |||
135 | * Real code | 145 | * Real code |
136 | */ | 146 | */ |
137 | 147 | ||
138 | static int w83l785ts_attach_adapter(struct i2c_adapter *adapter) | 148 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
139 | { | 149 | static int w83l785ts_detect(struct i2c_client *new_client, int kind, |
140 | if (!(adapter->class & I2C_CLASS_HWMON)) | 150 | struct i2c_board_info *info) |
141 | return 0; | ||
142 | return i2c_probe(adapter, &addr_data, w83l785ts_detect); | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * The following function does more than just detection. If detection | ||
147 | * succeeds, it also registers the new chip. | ||
148 | */ | ||
149 | static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | ||
150 | { | 151 | { |
151 | struct i2c_client *new_client; | 152 | struct i2c_adapter *adapter = new_client->adapter; |
152 | struct w83l785ts_data *data; | ||
153 | int err = 0; | ||
154 | |||
155 | 153 | ||
156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 154 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
157 | goto exit; | 155 | return -ENODEV; |
158 | |||
159 | if (!(data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) { | ||
160 | err = -ENOMEM; | ||
161 | goto exit; | ||
162 | } | ||
163 | |||
164 | /* The common I2C client data is placed right before the | ||
165 | * W83L785TS-specific data. */ | ||
166 | new_client = &data->client; | ||
167 | i2c_set_clientdata(new_client, data); | ||
168 | new_client->addr = address; | ||
169 | new_client->adapter = adapter; | ||
170 | new_client->driver = &w83l785ts_driver; | ||
171 | new_client->flags = 0; | ||
172 | 156 | ||
173 | /* | 157 | /* |
174 | * Now we do the remaining detection. A negative kind means that | 158 | * Now we do the remaining detection. A negative kind means that |
@@ -188,8 +172,8 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
188 | W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) { | 172 | W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) { |
189 | dev_dbg(&adapter->dev, | 173 | dev_dbg(&adapter->dev, |
190 | "W83L785TS-S detection failed at 0x%02x.\n", | 174 | "W83L785TS-S detection failed at 0x%02x.\n", |
191 | address); | 175 | new_client->addr); |
192 | goto exit_free; | 176 | return -ENODEV; |
193 | } | 177 | } |
194 | } | 178 | } |
195 | 179 | ||
@@ -214,22 +198,34 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
214 | dev_info(&adapter->dev, | 198 | dev_info(&adapter->dev, |
215 | "Unsupported chip (man_id=0x%04X, " | 199 | "Unsupported chip (man_id=0x%04X, " |
216 | "chip_id=0x%02X).\n", man_id, chip_id); | 200 | "chip_id=0x%02X).\n", man_id, chip_id); |
217 | goto exit_free; | 201 | return -ENODEV; |
218 | } | 202 | } |
219 | } | 203 | } |
220 | 204 | ||
221 | /* We can fill in the remaining client fields. */ | 205 | strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE); |
222 | strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE); | 206 | |
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int w83l785ts_probe(struct i2c_client *new_client, | ||
211 | const struct i2c_device_id *id) | ||
212 | { | ||
213 | struct w83l785ts_data *data; | ||
214 | int err = 0; | ||
215 | |||
216 | data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL); | ||
217 | if (!data) { | ||
218 | err = -ENOMEM; | ||
219 | goto exit; | ||
220 | } | ||
221 | |||
222 | i2c_set_clientdata(new_client, data); | ||
223 | data->valid = 0; | 223 | data->valid = 0; |
224 | mutex_init(&data->update_lock); | 224 | mutex_init(&data->update_lock); |
225 | 225 | ||
226 | /* Default values in case the first read fails (unlikely). */ | 226 | /* Default values in case the first read fails (unlikely). */ |
227 | data->temp[1] = data->temp[0] = 0; | 227 | data->temp[1] = data->temp[0] = 0; |
228 | 228 | ||
229 | /* Tell the I2C layer a new client has arrived. */ | ||
230 | if ((err = i2c_attach_client(new_client))) | ||
231 | goto exit_free; | ||
232 | |||
233 | /* | 229 | /* |
234 | * Initialize the W83L785TS chip | 230 | * Initialize the W83L785TS chip |
235 | * Nothing yet, assume it is already started. | 231 | * Nothing yet, assume it is already started. |
@@ -259,25 +255,20 @@ exit_remove: | |||
259 | &sensor_dev_attr_temp1_input.dev_attr); | 255 | &sensor_dev_attr_temp1_input.dev_attr); |
260 | device_remove_file(&new_client->dev, | 256 | device_remove_file(&new_client->dev, |
261 | &sensor_dev_attr_temp1_max.dev_attr); | 257 | &sensor_dev_attr_temp1_max.dev_attr); |
262 | i2c_detach_client(new_client); | ||
263 | exit_free: | ||
264 | kfree(data); | 258 | kfree(data); |
265 | exit: | 259 | exit: |
266 | return err; | 260 | return err; |
267 | } | 261 | } |
268 | 262 | ||
269 | static int w83l785ts_detach_client(struct i2c_client *client) | 263 | static int w83l785ts_remove(struct i2c_client *client) |
270 | { | 264 | { |
271 | struct w83l785ts_data *data = i2c_get_clientdata(client); | 265 | struct w83l785ts_data *data = i2c_get_clientdata(client); |
272 | int err; | ||
273 | 266 | ||
274 | hwmon_device_unregister(data->hwmon_dev); | 267 | hwmon_device_unregister(data->hwmon_dev); |
275 | device_remove_file(&client->dev, | 268 | device_remove_file(&client->dev, |
276 | &sensor_dev_attr_temp1_input.dev_attr); | 269 | &sensor_dev_attr_temp1_input.dev_attr); |
277 | device_remove_file(&client->dev, | 270 | device_remove_file(&client->dev, |
278 | &sensor_dev_attr_temp1_max.dev_attr); | 271 | &sensor_dev_attr_temp1_max.dev_attr); |
279 | if ((err = i2c_detach_client(client))) | ||
280 | return err; | ||
281 | 272 | ||
282 | kfree(data); | 273 | kfree(data); |
283 | return 0; | 274 | return 0; |
@@ -286,6 +277,18 @@ static int w83l785ts_detach_client(struct i2c_client *client) | |||
286 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) | 277 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) |
287 | { | 278 | { |
288 | int value, i; | 279 | int value, i; |
280 | struct device *dev; | ||
281 | const char *prefix; | ||
282 | |||
283 | /* We might be called during detection, at which point the client | ||
284 | isn't yet fully initialized, so we can't use dev_dbg on it */ | ||
285 | if (i2c_get_clientdata(client)) { | ||
286 | dev = &client->dev; | ||
287 | prefix = ""; | ||
288 | } else { | ||
289 | dev = &client->adapter->dev; | ||
290 | prefix = "w83l785ts: "; | ||
291 | } | ||
289 | 292 | ||
290 | /* Frequent read errors have been reported on Asus boards, so we | 293 | /* Frequent read errors have been reported on Asus boards, so we |
291 | * retry on read errors. If it still fails (unlikely), return the | 294 | * retry on read errors. If it still fails (unlikely), return the |
@@ -293,15 +296,15 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) | |||
293 | for (i = 1; i <= MAX_RETRIES; i++) { | 296 | for (i = 1; i <= MAX_RETRIES; i++) { |
294 | value = i2c_smbus_read_byte_data(client, reg); | 297 | value = i2c_smbus_read_byte_data(client, reg); |
295 | if (value >= 0) { | 298 | if (value >= 0) { |
296 | dev_dbg(&client->dev, "Read 0x%02x from register " | 299 | dev_dbg(dev, "%sRead 0x%02x from register 0x%02x.\n", |
297 | "0x%02x.\n", value, reg); | 300 | prefix, value, reg); |
298 | return value; | 301 | return value; |
299 | } | 302 | } |
300 | dev_dbg(&client->dev, "Read failed, will retry in %d.\n", i); | 303 | dev_dbg(dev, "%sRead failed, will retry in %d.\n", prefix, i); |
301 | msleep(i); | 304 | msleep(i); |
302 | } | 305 | } |
303 | 306 | ||
304 | dev_err(&client->dev, "Couldn't read value from register 0x%02x.\n", | 307 | dev_err(dev, "%sCouldn't read value from register 0x%02x.\n", prefix, |
305 | reg); | 308 | reg); |
306 | return defval; | 309 | return defval; |
307 | } | 310 | } |
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index 41e22ddb568a..badca769f350 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -121,7 +121,6 @@ DIV_TO_REG(long val) | |||
121 | } | 121 | } |
122 | 122 | ||
123 | struct w83l786ng_data { | 123 | struct w83l786ng_data { |
124 | struct i2c_client client; | ||
125 | struct device *hwmon_dev; | 124 | struct device *hwmon_dev; |
126 | struct mutex update_lock; | 125 | struct mutex update_lock; |
127 | char valid; /* !=0 if following fields are valid */ | 126 | char valid; /* !=0 if following fields are valid */ |
@@ -146,18 +145,30 @@ struct w83l786ng_data { | |||
146 | u8 tolerance[2]; | 145 | u8 tolerance[2]; |
147 | }; | 146 | }; |
148 | 147 | ||
149 | static int w83l786ng_attach_adapter(struct i2c_adapter *adapter); | 148 | static int w83l786ng_probe(struct i2c_client *client, |
150 | static int w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind); | 149 | const struct i2c_device_id *id); |
151 | static int w83l786ng_detach_client(struct i2c_client *client); | 150 | static int w83l786ng_detect(struct i2c_client *client, int kind, |
151 | struct i2c_board_info *info); | ||
152 | static int w83l786ng_remove(struct i2c_client *client); | ||
152 | static void w83l786ng_init_client(struct i2c_client *client); | 153 | static void w83l786ng_init_client(struct i2c_client *client); |
153 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); | 154 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); |
154 | 155 | ||
156 | static const struct i2c_device_id w83l786ng_id[] = { | ||
157 | { "w83l786ng", w83l786ng }, | ||
158 | { } | ||
159 | }; | ||
160 | MODULE_DEVICE_TABLE(i2c, w83l786ng_id); | ||
161 | |||
155 | static struct i2c_driver w83l786ng_driver = { | 162 | static struct i2c_driver w83l786ng_driver = { |
163 | .class = I2C_CLASS_HWMON, | ||
156 | .driver = { | 164 | .driver = { |
157 | .name = "w83l786ng", | 165 | .name = "w83l786ng", |
158 | }, | 166 | }, |
159 | .attach_adapter = w83l786ng_attach_adapter, | 167 | .probe = w83l786ng_probe, |
160 | .detach_client = w83l786ng_detach_client, | 168 | .remove = w83l786ng_remove, |
169 | .id_table = w83l786ng_id, | ||
170 | .detect = w83l786ng_detect, | ||
171 | .address_data = &addr_data, | ||
161 | }; | 172 | }; |
162 | 173 | ||
163 | static u8 | 174 | static u8 |
@@ -575,42 +586,15 @@ static const struct attribute_group w83l786ng_group = { | |||
575 | }; | 586 | }; |
576 | 587 | ||
577 | static int | 588 | static int |
578 | w83l786ng_attach_adapter(struct i2c_adapter *adapter) | 589 | w83l786ng_detect(struct i2c_client *client, int kind, |
590 | struct i2c_board_info *info) | ||
579 | { | 591 | { |
580 | if (!(adapter->class & I2C_CLASS_HWMON)) | 592 | struct i2c_adapter *adapter = client->adapter; |
581 | return 0; | ||
582 | return i2c_probe(adapter, &addr_data, w83l786ng_detect); | ||
583 | } | ||
584 | |||
585 | static int | ||
586 | w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | ||
587 | { | ||
588 | struct i2c_client *client; | ||
589 | struct device *dev; | ||
590 | struct w83l786ng_data *data; | ||
591 | int i, err = 0; | ||
592 | u8 reg_tmp; | ||
593 | 593 | ||
594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
595 | goto exit; | 595 | return -ENODEV; |
596 | } | ||
597 | |||
598 | /* OK. For now, we presume we have a valid client. We now create the | ||
599 | client structure, even though we cannot fill it completely yet. | ||
600 | But it allows us to access w83l786ng_{read,write}_value. */ | ||
601 | |||
602 | if (!(data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL))) { | ||
603 | err = -ENOMEM; | ||
604 | goto exit; | ||
605 | } | 596 | } |
606 | 597 | ||
607 | client = &data->client; | ||
608 | dev = &client->dev; | ||
609 | i2c_set_clientdata(client, data); | ||
610 | client->addr = address; | ||
611 | client->adapter = adapter; | ||
612 | client->driver = &w83l786ng_driver; | ||
613 | |||
614 | /* | 598 | /* |
615 | * Now we do the remaining detection. A negative kind means that | 599 | * Now we do the remaining detection. A negative kind means that |
616 | * the driver was loaded with no force parameter (default), so we | 600 | * the driver was loaded with no force parameter (default), so we |
@@ -627,8 +611,8 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
627 | W83L786NG_REG_CONFIG) & 0x80) != 0x00)) { | 611 | W83L786NG_REG_CONFIG) & 0x80) != 0x00)) { |
628 | dev_dbg(&adapter->dev, | 612 | dev_dbg(&adapter->dev, |
629 | "W83L786NG detection failed at 0x%02x.\n", | 613 | "W83L786NG detection failed at 0x%02x.\n", |
630 | address); | 614 | client->addr); |
631 | goto exit_free; | 615 | return -ENODEV; |
632 | } | 616 | } |
633 | } | 617 | } |
634 | 618 | ||
@@ -651,17 +635,31 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
651 | dev_info(&adapter->dev, | 635 | dev_info(&adapter->dev, |
652 | "Unsupported chip (man_id=0x%04X, " | 636 | "Unsupported chip (man_id=0x%04X, " |
653 | "chip_id=0x%02X).\n", man_id, chip_id); | 637 | "chip_id=0x%02X).\n", man_id, chip_id); |
654 | goto exit_free; | 638 | return -ENODEV; |
655 | } | 639 | } |
656 | } | 640 | } |
657 | 641 | ||
658 | /* Fill in the remaining client fields and put into the global list */ | 642 | strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); |
659 | strlcpy(client->name, "w83l786ng", I2C_NAME_SIZE); | ||
660 | mutex_init(&data->update_lock); | ||
661 | 643 | ||
662 | /* Tell the I2C layer a new client has arrived */ | 644 | return 0; |
663 | if ((err = i2c_attach_client(client))) | 645 | } |
664 | goto exit_free; | 646 | |
647 | static int | ||
648 | w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
649 | { | ||
650 | struct device *dev = &client->dev; | ||
651 | struct w83l786ng_data *data; | ||
652 | int i, err = 0; | ||
653 | u8 reg_tmp; | ||
654 | |||
655 | data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL); | ||
656 | if (!data) { | ||
657 | err = -ENOMEM; | ||
658 | goto exit; | ||
659 | } | ||
660 | |||
661 | i2c_set_clientdata(client, data); | ||
662 | mutex_init(&data->update_lock); | ||
665 | 663 | ||
666 | /* Initialize the chip */ | 664 | /* Initialize the chip */ |
667 | w83l786ng_init_client(client); | 665 | w83l786ng_init_client(client); |
@@ -693,25 +691,19 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
693 | 691 | ||
694 | exit_remove: | 692 | exit_remove: |
695 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | 693 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); |
696 | i2c_detach_client(client); | ||
697 | exit_free: | ||
698 | kfree(data); | 694 | kfree(data); |
699 | exit: | 695 | exit: |
700 | return err; | 696 | return err; |
701 | } | 697 | } |
702 | 698 | ||
703 | static int | 699 | static int |
704 | w83l786ng_detach_client(struct i2c_client *client) | 700 | w83l786ng_remove(struct i2c_client *client) |
705 | { | 701 | { |
706 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 702 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
707 | int err; | ||
708 | 703 | ||
709 | hwmon_device_unregister(data->hwmon_dev); | 704 | hwmon_device_unregister(data->hwmon_dev); |
710 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | 705 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); |
711 | 706 | ||
712 | if ((err = i2c_detach_client(client))) | ||
713 | return err; | ||
714 | |||
715 | kfree(data); | 707 | kfree(data); |
716 | 708 | ||
717 | return 0; | 709 | return 0; |