aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/ad7418.c109
-rw-r--r--drivers/hwmon/adm1021.c105
-rw-r--r--drivers/hwmon/adm1025.c101
-rw-r--r--drivers/hwmon/adm1026.c109
-rw-r--r--drivers/hwmon/adm1029.c97
-rw-r--r--drivers/hwmon/adm1031.c96
-rw-r--r--drivers/hwmon/adm9240.c93
-rw-r--r--drivers/hwmon/ads7828.c89
-rw-r--r--drivers/hwmon/adt7470.c100
-rw-r--r--drivers/hwmon/adt7473.c102
-rw-r--r--drivers/hwmon/asb100.c207
-rw-r--r--drivers/hwmon/atxp1.c109
-rw-r--r--drivers/hwmon/ds1621.c99
-rw-r--r--drivers/hwmon/f75375s.c89
-rw-r--r--drivers/hwmon/fscher.c93
-rw-r--r--drivers/hwmon/fschmd.c112
-rw-r--r--drivers/hwmon/fscpos.c94
-rw-r--r--drivers/hwmon/gl518sm.c99
-rw-r--r--drivers/hwmon/gl520sm.c91
-rw-r--r--drivers/hwmon/lm63.c99
-rw-r--r--drivers/hwmon/lm77.c102
-rw-r--r--drivers/hwmon/lm80.c94
-rw-r--r--drivers/hwmon/lm83.c104
-rw-r--r--drivers/hwmon/lm87.c99
-rw-r--r--drivers/hwmon/lm90.c119
-rw-r--r--drivers/hwmon/lm92.c98
-rw-r--r--drivers/hwmon/lm93.c126
-rw-r--r--drivers/hwmon/max1619.c101
-rw-r--r--drivers/hwmon/max6650.c102
-rw-r--r--drivers/hwmon/smsc47m192.c102
-rw-r--r--drivers/hwmon/thmc50.c107
-rw-r--r--drivers/hwmon/w83791d.c205
-rw-r--r--drivers/hwmon/w83792d.c214
-rw-r--r--drivers/hwmon/w83793.c227
-rw-r--r--drivers/hwmon/w83l785ts.c117
-rw-r--r--drivers/hwmon/w83l786ng.c98
36 files changed, 1787 insertions, 2321 deletions
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 */ 28enum chips { ad7416, ad7417, ad7418 };
29static const unsigned short normal_i2c[] = { 0x28, I2C_CLIENT_END };
30/* Insmod parameters */
31I2C_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
48struct ad7418_data { 45struct 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
61static int ad7418_attach_adapter(struct i2c_adapter *adapter); 57static int ad7418_probe(struct i2c_client *client,
62static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind); 58 const struct i2c_device_id *id);
63static int ad7418_detach_client(struct i2c_client *client); 59static int ad7418_remove(struct i2c_client *client);
60
61static const struct i2c_device_id ad7418_id[] = {
62 { "ad7416", ad7416 },
63 { "ad7417", ad7417 },
64 { "ad7418", ad7418 },
65 { }
66};
67MODULE_DEVICE_TABLE(i2c, ad7418_id);
64 68
65static struct i2c_driver ad7418_driver = { 69static 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);
192static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); 197static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2);
193static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); 198static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3);
194 199
195static 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
202static struct attribute *ad7416_attributes[] = { 200static 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
228static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) 226static 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
337exit_remove: 283exit_remove:
338 sysfs_remove_group(&client->dev.kobj, &data->attrs); 284 sysfs_remove_group(&client->dev.kobj, &data->attrs);
339exit_detach:
340 i2c_detach_client(client);
341exit_free: 285exit_free:
342 kfree(data); 286 kfree(data);
343exit: 287exit:
344 return err; 288 return err;
345} 289}
346 290
347static int ad7418_detach_client(struct i2c_client *client) 291static 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 */
80struct adm1021_data { 80struct 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
101static int adm1021_attach_adapter(struct i2c_adapter *adapter); 100static int adm1021_probe(struct i2c_client *client,
102static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind); 101 const struct i2c_device_id *id);
102static int adm1021_detect(struct i2c_client *client, int kind,
103 struct i2c_board_info *info);
103static void adm1021_init_client(struct i2c_client *client); 104static void adm1021_init_client(struct i2c_client *client);
104static int adm1021_detach_client(struct i2c_client *client); 105static int adm1021_remove(struct i2c_client *client);
105static struct adm1021_data *adm1021_update_device(struct device *dev); 106static 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 */
108static int read_only; 109static int read_only;
109 110
110 111
112static 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};
123MODULE_DEVICE_TABLE(i2c, adm1021_id);
124
111/* This is the driver that will be inserted */ 125/* This is the driver that will be inserted */
112static struct i2c_driver adm1021_driver = { 126static 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
120static ssize_t show_temp(struct device *dev, 138static 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
217static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 235static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
218 236
219static 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
226static struct attribute *adm1021_attributes[] = { 237static 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
246static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) 257/* Return 0 if detection is successful, -ENODEV otherwise */
258static 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 */ 340static 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
366error3: 373error3:
367 sysfs_remove_group(&client->dev.kobj, &adm1021_group); 374 sysfs_remove_group(&client->dev.kobj, &adm1021_group);
368error2:
369 i2c_detach_client(client);
370error1: 375error1:
371 kfree(data); 376 kfree(data);
372error0: 377error0:
@@ -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
385static int adm1021_detach_client(struct i2c_client *client) 390static 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
112static int adm1025_attach_adapter(struct i2c_adapter *adapter); 112static int adm1025_probe(struct i2c_client *client,
113static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind); 113 const struct i2c_device_id *id);
114static int adm1025_detect(struct i2c_client *client, int kind,
115 struct i2c_board_info *info);
114static void adm1025_init_client(struct i2c_client *client); 116static void adm1025_init_client(struct i2c_client *client);
115static int adm1025_detach_client(struct i2c_client *client); 117static int adm1025_remove(struct i2c_client *client);
116static struct adm1025_data *adm1025_update_device(struct device *dev); 118static 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
124static const struct i2c_device_id adm1025_id[] = {
125 { "adm1025", adm1025 },
126 { "ne1619", ne1619 },
127 { }
128};
129MODULE_DEVICE_TABLE(i2c, adm1025_id);
130
122static struct i2c_driver adm1025_driver = { 131static 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
134struct adm1025_data { 147struct 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
347static 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
354static struct attribute *adm1025_attributes[] = { 359static 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 412static int adm1025_detect(struct i2c_client *client, int kind,
408 * succeeds, it also registers the new chip. 413 struct i2c_board_info *info)
409 */
410static 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 */ 482static 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)
518exit_remove: 521exit_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);
521exit_detach:
522 i2c_detach_client(client);
523exit_free: 524exit_free:
524 kfree(data); 525 kfree(data);
525exit: 526exit:
@@ -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
571static int adm1025_detach_client(struct i2c_client *client) 572static 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
261struct adm1026_data { 261struct 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
296static int adm1026_attach_adapter(struct i2c_adapter *adapter); 295static int adm1026_probe(struct i2c_client *client,
297static int adm1026_detect(struct i2c_adapter *adapter, int address, 296 const struct i2c_device_id *id);
298 int kind); 297static int adm1026_detect(struct i2c_client *client, int kind,
299static int adm1026_detach_client(struct i2c_client *client); 298 struct i2c_board_info *info);
299static int adm1026_remove(struct i2c_client *client);
300static int adm1026_read_value(struct i2c_client *client, u8 reg); 300static int adm1026_read_value(struct i2c_client *client, u8 reg);
301static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); 301static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
302static void adm1026_print_gpio(struct i2c_client *client); 302static void adm1026_print_gpio(struct i2c_client *client);
@@ -305,22 +305,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev);
305static void adm1026_init_client(struct i2c_client *client); 305static void adm1026_init_client(struct i2c_client *client);
306 306
307 307
308static const struct i2c_device_id adm1026_id[] = {
309 { "adm1026", adm1026 },
310 { }
311};
312MODULE_DEVICE_TABLE(i2c, adm1026_id);
313
308static struct i2c_driver adm1026_driver = { 314static 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
316static 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
324static int adm1026_read_value(struct i2c_client *client, u8 reg) 326static 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
1650static int adm1026_detect(struct i2c_adapter *adapter, int address, 1652/* Return 0 if detection is successful, -ENODEV otherwise */
1651 int kind) 1653static 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"; 1710static 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);
1776exitdetach:
1777 i2c_detach_client(client);
1778exitfree: 1758exitfree:
1779 kfree(data); 1759 kfree(data);
1780exit: 1760exit:
1781 return err; 1761 return err;
1782} 1762}
1783 1763
1784static int adm1026_detach_client(struct i2c_client *client) 1764static 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
118static int adm1029_attach_adapter(struct i2c_adapter *adapter); 118static int adm1029_probe(struct i2c_client *client,
119static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind); 119 const struct i2c_device_id *id);
120static int adm1029_detach_client(struct i2c_client *client); 120static int adm1029_detect(struct i2c_client *client, int kind,
121 struct i2c_board_info *info);
122static int adm1029_remove(struct i2c_client *client);
121static struct adm1029_data *adm1029_update_device(struct device *dev); 123static struct adm1029_data *adm1029_update_device(struct device *dev);
122static int adm1029_init_client(struct i2c_client *client); 124static 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
130static const struct i2c_device_id adm1029_id[] = {
131 { "adm1029", adm1029 },
132 { }
133};
134MODULE_DEVICE_TABLE(i2c, adm1029_id);
135
128static struct i2c_driver adm1029_driver = { 136static 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
140struct adm1029_data { 152struct 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
287static int adm1029_attach_adapter(struct i2c_adapter *adapter) 298/* Return 0 if detection is successful, -ENODEV otherwise */
299static 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
299static 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
361static 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
427static int adm1029_detach_client(struct i2c_client *client) 422static 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 */
72struct adm1031_data { 72struct 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
102static int adm1031_attach_adapter(struct i2c_adapter *adapter); 101static int adm1031_probe(struct i2c_client *client,
103static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind); 102 const struct i2c_device_id *id);
103static int adm1031_detect(struct i2c_client *client, int kind,
104 struct i2c_board_info *info);
104static void adm1031_init_client(struct i2c_client *client); 105static void adm1031_init_client(struct i2c_client *client);
105static int adm1031_detach_client(struct i2c_client *client); 106static int adm1031_remove(struct i2c_client *client);
106static struct adm1031_data *adm1031_update_device(struct device *dev); 107static struct adm1031_data *adm1031_update_device(struct device *dev);
107 108
109static const struct i2c_device_id adm1031_id[] = {
110 { "adm1030", adm1030 },
111 { "adm1031", adm1031 },
112 { }
113};
114MODULE_DEVICE_TABLE(i2c, adm1031_id);
115
108/* This is the driver that will be inserted */ 116/* This is the driver that will be inserted */
109static struct i2c_driver adm1031_driver = { 117static 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
117static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) 129static 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);
693static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); 705static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
694static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); 706static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
695 707
696static 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
703static struct attribute *adm1031_attributes[] = { 708static 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 */
774static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 779static 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
813static 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)
847exit_remove: 855exit_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);
850exit_detach:
851 i2c_detach_client(client);
852exit_free: 858exit_free:
853 kfree(data); 859 kfree(data);
854exit: 860exit:
855 return err; 861 return err;
856} 862}
857 863
858static int adm1031_detach_client(struct i2c_client *client) 864static 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
133static int adm9240_attach_adapter(struct i2c_adapter *adapter); 133static int adm9240_probe(struct i2c_client *client,
134static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind); 134 const struct i2c_device_id *id);
135static int adm9240_detect(struct i2c_client *client, int kind,
136 struct i2c_board_info *info);
135static void adm9240_init_client(struct i2c_client *client); 137static void adm9240_init_client(struct i2c_client *client);
136static int adm9240_detach_client(struct i2c_client *client); 138static int adm9240_remove(struct i2c_client *client);
137static struct adm9240_data *adm9240_update_device(struct device *dev); 139static struct adm9240_data *adm9240_update_device(struct device *dev);
138 140
139/* driver data */ 141/* driver data */
142static const struct i2c_device_id adm9240_id[] = {
143 { "adm9240", adm9240 },
144 { "ds1780", ds1780 },
145 { "lm81", lm81 },
146 { }
147};
148MODULE_DEVICE_TABLE(i2c, adm9240_id);
149
140static struct i2c_driver adm9240_driver = { 150static 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 */
149struct adm9240_data { 163struct 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
535static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) 547/* Return 0 if detection is successful, -ENODEV otherwise */
548static 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))) 609static 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
626exit_remove: 638exit_remove:
627 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); 639 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
628exit_detach:
629 i2c_detach_client(new_client);
630exit_free: 640exit_free:
631 kfree(data); 641 kfree(data);
632exit: 642exit:
633 return err; 643 return err;
634} 644}
635 645
636static int adm9240_attach_adapter(struct i2c_adapter *adapter) 646static 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
643static 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 */
66struct ads7828_data { 66struct 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 */
76static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind); 75static int ads7828_detect(struct i2c_client *client, int kind,
76 struct i2c_board_info *info);
77static 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
159static int ads7828_attach_adapter(struct i2c_adapter *adapter) 161static 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
166static 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
170static const struct i2c_device_id ads7828_id[] = {
171 { "ads7828", ads7828 },
172 { }
173};
174MODULE_DEVICE_TABLE(i2c, ads7828_id);
175
176/* This is the driver that will be inserted */ 176/* This is the driver that will be inserted */
177static struct i2c_driver ads7828_driver = { 177static 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 */
186static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) 190static 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) 224static 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
263exit_remove: 252exit_remove:
264 sysfs_remove_group(&client->dev.kobj, &ads7828_group); 253 sysfs_remove_group(&client->dev.kobj, &ads7828_group);
265exit_detach:
266 i2c_detach_client(client);
267exit_free: 254exit_free:
268 kfree(data); 255 kfree(data);
269exit: 256exit:
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
140struct adt7470_data { 140struct 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
167static int adt7470_attach_adapter(struct i2c_adapter *adapter); 166static int adt7470_probe(struct i2c_client *client,
168static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind); 167 const struct i2c_device_id *id);
169static int adt7470_detach_client(struct i2c_client *client); 168static int adt7470_detect(struct i2c_client *client, int kind,
169 struct i2c_board_info *info);
170static int adt7470_remove(struct i2c_client *client);
171
172static const struct i2c_device_id adt7470_id[] = {
173 { "adt7470", adt7470 },
174 { }
175};
176MODULE_DEVICE_TABLE(i2c, adt7470_id);
170 177
171static struct i2c_driver adt7470_driver = { 178static 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
1007static int adt7470_attach_adapter(struct i2c_adapter *adapter) 1018/* Return 0 if detection is successful, -ENODEV otherwise */
1008{ 1019static 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
1014static 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
1050static 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
1084exit_remove: 1083exit_remove:
1085 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1084 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1086exit_detach:
1087 i2c_detach_client(client);
1088exit_free: 1085exit_free:
1089 kfree(data); 1086 kfree(data);
1090exit: 1087exit:
1091 return err; 1088 return err;
1092} 1089}
1093 1090
1094static int adt7470_detach_client(struct i2c_client *client) 1091static 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 93dbf5e7ff8a..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
145struct adt7473_data { 145struct 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
181static int adt7473_attach_adapter(struct i2c_adapter *adapter); 180static int adt7473_probe(struct i2c_client *client,
182static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind); 181 const struct i2c_device_id *id);
183static int adt7473_detach_client(struct i2c_client *client); 182static int adt7473_detect(struct i2c_client *client, int kind,
183 struct i2c_board_info *info);
184static int adt7473_remove(struct i2c_client *client);
185
186static const struct i2c_device_id adt7473_id[] = {
187 { "adt7473", adt7473 },
188 { }
189};
190MODULE_DEVICE_TABLE(i2c, adt7473_id);
184 191
185static struct i2c_driver adt7473_driver = { 192static 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/*
@@ -1042,66 +1053,52 @@ static struct attribute *adt7473_attr[] =
1042 NULL 1053 NULL
1043}; 1054};
1044 1055
1045static int adt7473_attach_adapter(struct i2c_adapter *adapter) 1056/* Return 0 if detection is successful, -ENODEV otherwise */
1057static int adt7473_detect(struct i2c_client *client, int kind,
1058 struct i2c_board_info *info)
1046{ 1059{
1047 if (!(adapter->class & I2C_CLASS_HWMON)) 1060 struct i2c_adapter *adapter = client->adapter;
1048 return 0;
1049 return i2c_probe(adapter, &addr_data, adt7473_detect);
1050}
1051
1052static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1053{
1054 struct i2c_client *client;
1055 struct adt7473_data *data;
1056 int err = 0;
1057 1061
1058 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1062 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1059 goto exit; 1063 return -ENODEV;
1060
1061 data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL);
1062 if (!data) {
1063 err = -ENOMEM;
1064 goto exit;
1065 }
1066
1067 client = &data->client;
1068 client->addr = address;
1069 client->adapter = adapter;
1070 client->driver = &adt7473_driver;
1071
1072 i2c_set_clientdata(client, data);
1073
1074 mutex_init(&data->lock);
1075 1064
1076 if (kind <= 0) { 1065 if (kind <= 0) {
1077 int vendor, device, revision; 1066 int vendor, device, revision;
1078 1067
1079 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); 1068 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
1080 if (vendor != ADT7473_VENDOR) { 1069 if (vendor != ADT7473_VENDOR)
1081 err = -ENODEV; 1070 return -ENODEV;
1082 goto exit_free;
1083 }
1084 1071
1085 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); 1072 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE);
1086 if (device != ADT7473_DEVICE) { 1073 if (device != ADT7473_DEVICE)
1087 err = -ENODEV; 1074 return -ENODEV;
1088 goto exit_free;
1089 }
1090 1075
1091 revision = i2c_smbus_read_byte_data(client, 1076 revision = i2c_smbus_read_byte_data(client,
1092 ADT7473_REG_REVISION); 1077 ADT7473_REG_REVISION);
1093 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) { 1078 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69)
1094 err = -ENODEV; 1079 return -ENODEV;
1095 goto exit_free;
1096 }
1097 } else 1080 } else
1098 dev_dbg(&adapter->dev, "detection forced\n"); 1081 dev_dbg(&adapter->dev, "detection forced\n");
1099 1082
1100 strlcpy(client->name, "adt7473", I2C_NAME_SIZE); 1083 strlcpy(info->type, "adt7473", I2C_NAME_SIZE);
1101 1084
1102 err = i2c_attach_client(client); 1085 return 0;
1103 if (err) 1086}
1104 goto exit_free; 1087
1088static 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);
1105 1102
1106 dev_info(&client->dev, "%s chip found\n", client->name); 1103 dev_info(&client->dev, "%s chip found\n", client->name);
1107 1104
@@ -1112,7 +1109,7 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1112 data->attrs.attrs = adt7473_attr; 1109 data->attrs.attrs = adt7473_attr;
1113 err = sysfs_create_group(&client->dev.kobj, &data->attrs); 1110 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1114 if (err) 1111 if (err)
1115 goto exit_detach; 1112 goto exit_free;
1116 1113
1117 data->hwmon_dev = hwmon_device_register(&client->dev); 1114 data->hwmon_dev = hwmon_device_register(&client->dev);
1118 if (IS_ERR(data->hwmon_dev)) { 1115 if (IS_ERR(data->hwmon_dev)) {
@@ -1124,21 +1121,18 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1124 1121
1125exit_remove: 1122exit_remove:
1126 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1123 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1127exit_detach:
1128 i2c_detach_client(client);
1129exit_free: 1124exit_free:
1130 kfree(data); 1125 kfree(data);
1131exit: 1126exit:
1132 return err; 1127 return err;
1133} 1128}
1134 1129
1135static int adt7473_detach_client(struct i2c_client *client) 1130static int adt7473_remove(struct i2c_client *client)
1136{ 1131{
1137 struct adt7473_data *data = i2c_get_clientdata(client); 1132 struct adt7473_data *data = i2c_get_clientdata(client);
1138 1133
1139 hwmon_device_unregister(data->hwmon_dev); 1134 hwmon_device_unregister(data->hwmon_dev);
1140 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1135 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1141 i2c_detach_client(client);
1142 kfree(data); 1136 kfree(data);
1143 return 0; 1137 return 0;
1144} 1138}
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. */
178struct asb100_data { 178struct 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 {
206static int asb100_read_value(struct i2c_client *client, u16 reg); 204static int asb100_read_value(struct i2c_client *client, u16 reg);
207static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); 205static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);
208 206
209static int asb100_attach_adapter(struct i2c_adapter *adapter); 207static int asb100_probe(struct i2c_client *client,
210static int asb100_detect(struct i2c_adapter *adapter, int address, int kind); 208 const struct i2c_device_id *id);
211static int asb100_detach_client(struct i2c_client *client); 209static int asb100_detect(struct i2c_client *client, int kind,
210 struct i2c_board_info *info);
211static int asb100_remove(struct i2c_client *client);
212static struct asb100_data *asb100_update_device(struct device *dev); 212static struct asb100_data *asb100_update_device(struct device *dev);
213static void asb100_init_client(struct i2c_client *client); 213static void asb100_init_client(struct i2c_client *client);
214 214
215static const struct i2c_device_id asb100_id[] = {
216 { "asb100", asb100 },
217 { }
218};
219MODULE_DEVICE_TABLE(i2c, asb100_id);
220
215static struct i2c_driver asb100_driver = { 221static 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: 632static 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 */
627static 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
634static 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 */
705ERROR_SC_3: 690ERROR_SC_3:
706 i2c_detach_client(data->lm75[0]); 691 i2c_unregister_device(data->lm75[0]);
707ERROR_SC_2: 692ERROR_SC_2:
708 kfree(data->lm75[1]);
709ERROR_SC_1:
710 kfree(data->lm75[0]);
711ERROR_SC_0:
712 return err; 693 return err;
713} 694}
714 695
715static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) 696/* Return 0 if detection is successful, -ENODEV otherwise */
697static 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
758static 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)
827ERROR4: 800ERROR4:
828 sysfs_remove_group(&client->dev.kobj, &asb100_group); 801 sysfs_remove_group(&client->dev.kobj, &asb100_group);
829ERROR3: 802ERROR3:
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]);
834ERROR2:
835 i2c_detach_client(client);
836ERROR1: 805ERROR1:
837 kfree(data); 806 kfree(data);
838ERROR0: 807ERROR0:
839 return err; 808 return err;
840} 809}
841 810
842static int asb100_detach_client(struct i2c_client *client) 811static 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
47I2C_CLIENT_INSMOD_1(atxp1); 47I2C_CLIENT_INSMOD_1(atxp1);
48 48
49static int atxp1_attach_adapter(struct i2c_adapter * adapter); 49static int atxp1_probe(struct i2c_client *client,
50static int atxp1_detach_client(struct i2c_client * client); 50 const struct i2c_device_id *id);
51static int atxp1_remove(struct i2c_client *client);
51static struct atxp1_data * atxp1_update_device(struct device *dev); 52static struct atxp1_data * atxp1_update_device(struct device *dev);
52static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind); 53static int atxp1_detect(struct i2c_client *client, int kind,
54 struct i2c_board_info *info);
55
56static const struct i2c_device_id atxp1_id[] = {
57 { "atxp1", atxp1 },
58 { }
59};
60MODULE_DEVICE_TABLE(i2c, atxp1_id);
53 61
54static struct i2c_driver atxp1_driver = { 62static 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
62struct atxp1_data { 74struct 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
266static int atxp1_attach_adapter(struct i2c_adapter *adapter) 277/* Return 0 if detection is successful, -ENODEV otherwise */
278static 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
273static 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); 317static 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
349exit_remove_files: 352exit_remove_files:
350 sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); 353 sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
351exit_detach:
352 i2c_detach_client(new_client);
353exit_free: 354exit_free:
354 kfree(data); 355 kfree(data);
355exit: 356exit:
356 return err; 357 return err;
357}; 358};
358 359
359static int atxp1_detach_client(struct i2c_client * client) 360static 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
377static int __init atxp1_init(void) 372static 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 */
74struct ds1621_data { 74struct 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
85static int ds1621_attach_adapter(struct i2c_adapter *adapter); 84static int ds1621_probe(struct i2c_client *client,
86static int ds1621_detect(struct i2c_adapter *adapter, int address, 85 const struct i2c_device_id *id);
87 int kind); 86static int ds1621_detect(struct i2c_client *client, int kind,
87 struct i2c_board_info *info);
88static void ds1621_init_client(struct i2c_client *client); 88static void ds1621_init_client(struct i2c_client *client);
89static int ds1621_detach_client(struct i2c_client *client); 89static int ds1621_remove(struct i2c_client *client);
90static struct ds1621_data *ds1621_update_client(struct device *dev); 90static struct ds1621_data *ds1621_update_client(struct device *dev);
91 91
92static const struct i2c_device_id ds1621_id[] = {
93 { "ds1621", ds1621 },
94 { "ds1625", ds1621 },
95 { }
96};
97MODULE_DEVICE_TABLE(i2c, ds1621_id);
98
92/* This is the driver that will be inserted */ 99/* This is the driver that will be inserted */
93static struct i2c_driver ds1621_driver = { 100static 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
202static int ds1621_attach_adapter(struct i2c_adapter *adapter) 213/* Return 0 if detection is successful, -ENODEV otherwise */
203{ 214static 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 */
210static 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
247static 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
286static int ds1621_detach_client(struct i2c_client *client) 285static 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
88struct f75375_data { 88struct 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
117static int f75375_attach_adapter(struct i2c_adapter *adapter); 116static int f75375_detect(struct i2c_client *client, int kind,
118static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); 117 struct i2c_board_info *info);
119static int f75375_detach_client(struct i2c_client *client);
120static int f75375_probe(struct i2c_client *client, 118static int f75375_probe(struct i2c_client *client,
121 const struct i2c_device_id *id); 119 const struct i2c_device_id *id);
122static int f75375_remove(struct i2c_client *client); 120static int f75375_remove(struct i2c_client *client);
123 121
124static 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
132static const struct i2c_device_id f75375_id[] = { 122static 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[] = {
137MODULE_DEVICE_TABLE(i2c, f75375_id); 127MODULE_DEVICE_TABLE(i2c, f75375_id);
138 128
139static struct i2c_driver f75375_driver = { 129static 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
148static inline int f75375_read8(struct i2c_client *client, u8 reg) 141static 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
610static 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
626static void f75375_init(struct i2c_client *client, struct f75375_data *data, 603static 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
703static int f75375_attach_adapter(struct i2c_adapter *adapter) 679/* Return 0 if detection is successful, -ENODEV otherwise */
704{ 680static 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 */
711static 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
761exit_detach:
762 i2c_detach_client(client);
763exit_free:
764 kfree(client);
765exit:
766 return err;
767} 712}
768 713
769static int __init sensors_f75375_init(void) 714static 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
783static void __exit sensors_f75375_exit(void) 719static 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
109static int fscher_attach_adapter(struct i2c_adapter *adapter); 109static int fscher_probe(struct i2c_client *client,
110static int fscher_detect(struct i2c_adapter *adapter, int address, int kind); 110 const struct i2c_device_id *id);
111static int fscher_detach_client(struct i2c_client *client); 111static int fscher_detect(struct i2c_client *client, int kind,
112 struct i2c_board_info *info);
113static int fscher_remove(struct i2c_client *client);
112static struct fscher_data *fscher_update_device(struct device *dev); 114static struct fscher_data *fscher_update_device(struct device *dev);
113static void fscher_init_client(struct i2c_client *client); 115static 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
124static const struct i2c_device_id fscher_id[] = {
125 { "fscher", fscher },
126 { }
127};
128
122static struct i2c_driver fscher_driver = { 129static 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
134struct fscher_data { 145struct 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
286static int fscher_attach_adapter(struct i2c_adapter *adapter) 296/* Return 0 if detection is successful, -ENODEV otherwise */
287{ 297static 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
293static 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
321static 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
354exit_remove_files: 351exit_remove_files:
355 sysfs_remove_group(&new_client->dev.kobj, &fscher_group); 352 sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
356exit_detach:
357 i2c_detach_client(new_client);
358exit_free: 353exit_free:
359 kfree(data); 354 kfree(data);
360exit: 355exit:
361 return err; 356 return err;
362} 357}
363 358
364static int fscher_detach_client(struct i2c_client *client) 359static 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
174static int fschmd_attach_adapter(struct i2c_adapter *adapter); 174static int fschmd_probe(struct i2c_client *client,
175static int fschmd_detach_client(struct i2c_client *client); 175 const struct i2c_device_id *id);
176static int fschmd_detect(struct i2c_client *client, int kind,
177 struct i2c_board_info *info);
178static int fschmd_remove(struct i2c_client *client);
176static struct fschmd_data *fschmd_update_device(struct device *dev); 179static 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
185static const struct i2c_device_id fschmd_id[] = {
186 { "fscpos", fscpos },
187 { "fscher", fscher },
188 { "fscscy", fscscy },
189 { "fschrc", fschrc },
190 { "fschmd", fschmd },
191 { }
192};
193MODULE_DEVICE_TABLE(i2c, fschmd_id);
194
182static struct i2c_driver fschmd_driver = { 195static 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
194struct fschmd_data { 211struct 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
603static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) 619static 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
660static 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
728exit_detach: 744exit_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
732exit_free:
733 kfree(data);
734 return err; 746 return err;
735} 747}
736 748
737static int fschmd_attach_adapter(struct i2c_adapter *adapter) 749static 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
744static 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 */
90static int fscpos_attach_adapter(struct i2c_adapter *adapter); 90static int fscpos_probe(struct i2c_client *client,
91static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); 91 const struct i2c_device_id *id);
92static int fscpos_detach_client(struct i2c_client *client); 92static int fscpos_detect(struct i2c_client *client, int kind,
93 struct i2c_board_info *info);
94static int fscpos_remove(struct i2c_client *client);
93 95
94static int fscpos_read_value(struct i2c_client *client, u8 reg); 96static int fscpos_read_value(struct i2c_client *client, u8 reg);
95static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); 97static 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 */
106static const struct i2c_device_id fscpos_id[] = {
107 { "fscpos", fscpos },
108 { }
109};
110
104static struct i2c_driver fscpos_driver = { 111static 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 */
115struct fscpos_data { 126struct 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
473static int fscpos_attach_adapter(struct i2c_adapter *adapter) 483/* Return 0 if detection is successful, -ENODEV otherwise */
474{ 484static 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
480static 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
508static 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
549exit_remove_files: 542exit_remove_files:
550 sysfs_remove_group(&new_client->dev.kobj, &fscpos_group); 543 sysfs_remove_group(&new_client->dev.kobj, &fscpos_group);
551exit_detach:
552 i2c_detach_client(new_client);
553exit_free: 544exit_free:
554 kfree(data); 545 kfree(data);
555exit: 546exit:
556 return err; 547 return err;
557} 548}
558 549
559static int fscpos_detach_client(struct i2c_client *client) 550static 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 */
116struct gl518_data { 116struct 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
141static int gl518_attach_adapter(struct i2c_adapter *adapter); 140static int gl518_probe(struct i2c_client *client,
142static int gl518_detect(struct i2c_adapter *adapter, int address, int kind); 141 const struct i2c_device_id *id);
142static int gl518_detect(struct i2c_client *client, int kind,
143 struct i2c_board_info *info);
143static void gl518_init_client(struct i2c_client *client); 144static void gl518_init_client(struct i2c_client *client);
144static int gl518_detach_client(struct i2c_client *client); 145static int gl518_remove(struct i2c_client *client);
145static int gl518_read_value(struct i2c_client *client, u8 reg); 146static int gl518_read_value(struct i2c_client *client, u8 reg);
146static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); 147static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value);
147static struct gl518_data *gl518_update_device(struct device *dev); 148static struct gl518_data *gl518_update_device(struct device *dev);
148 149
150static const struct i2c_device_id gl518_id[] = {
151 { "gl518sm", 0 },
152 { }
153};
154MODULE_DEVICE_TABLE(i2c, gl518_id);
155
149/* This is the driver that will be inserted */ 156/* This is the driver that will be inserted */
150static struct i2c_driver gl518_driver = { 157static 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
475static int gl518_attach_adapter(struct i2c_adapter *adapter) 486/* Return 0 if detection is successful, -ENODEV otherwise */
476{ 487static 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
482static 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
527static 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);
567exit_detach:
568 i2c_detach_client(client);
569exit_free: 568exit_free:
570 kfree(data); 569 kfree(data);
571exit: 570exit:
@@ -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
594static int gl518_detach_client(struct i2c_client *client) 593static 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
82static int gl520_attach_adapter(struct i2c_adapter *adapter); 82static int gl520_probe(struct i2c_client *client,
83static int gl520_detect(struct i2c_adapter *adapter, int address, int kind); 83 const struct i2c_device_id *id);
84static int gl520_detect(struct i2c_client *client, int kind,
85 struct i2c_board_info *info);
84static void gl520_init_client(struct i2c_client *client); 86static void gl520_init_client(struct i2c_client *client);
85static int gl520_detach_client(struct i2c_client *client); 87static int gl520_remove(struct i2c_client *client);
86static int gl520_read_value(struct i2c_client *client, u8 reg); 88static int gl520_read_value(struct i2c_client *client, u8 reg);
87static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); 89static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value);
88static struct gl520_data *gl520_update_device(struct device *dev); 90static struct gl520_data *gl520_update_device(struct device *dev);
89 91
90/* Driver data */ 92/* Driver data */
93static const struct i2c_device_id gl520_id[] = {
94 { "gl520sm", gl520sm },
95 { }
96};
97MODULE_DEVICE_TABLE(i2c, gl520_id);
98
91static struct i2c_driver gl520_driver = { 99static 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 */
100struct gl520_data { 112struct 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
672static int gl520_attach_adapter(struct i2c_adapter *adapter) 683/* Return 0 if detection is successful, -ENODEV otherwise */
673{ 684static 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
679static 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
708static 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)
764exit_remove_files: 765exit_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);
767exit_detach:
768 i2c_detach_client(client);
769exit_free: 768exit_free:
770 kfree(data); 769 kfree(data);
771exit: 770exit:
@@ -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
814static int gl520_detach_client(struct i2c_client *client) 813static 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/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
131static int lm63_attach_adapter(struct i2c_adapter *adapter); 131static int lm63_probe(struct i2c_client *client,
132static int lm63_detach_client(struct i2c_client *client); 132 const struct i2c_device_id *id);
133static int lm63_remove(struct i2c_client *client);
133 134
134static struct lm63_data *lm63_update_device(struct device *dev); 135static struct lm63_data *lm63_update_device(struct device *dev);
135 136
136static int lm63_detect(struct i2c_adapter *adapter, int address, int kind); 137static int lm63_detect(struct i2c_client *client, int kind,
138 struct i2c_board_info *info);
137static void lm63_init_client(struct i2c_client *client); 139static 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
145static const struct i2c_device_id lm63_id[] = {
146 { "lm63", lm63 },
147 { }
148};
149MODULE_DEVICE_TABLE(i2c, lm63_id);
150
143static struct i2c_driver lm63_driver = { 151static 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
155struct lm63_data { 167struct 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
414static int lm63_attach_adapter(struct i2c_adapter *adapter) 425/* Return 0 if detection is successful, -ENODEV otherwise */
426static 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 */
425static 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
471static 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)
513exit_remove_files: 508exit_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);
516exit_detach:
517 i2c_detach_client(new_client);
518exit_free: 511exit_free:
519 kfree(data); 512 kfree(data);
520exit: 513exit:
@@ -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
559static int lm63_detach_client(struct i2c_client *client) 552static 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/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 */
54struct lm77_data { 54struct 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
68static int lm77_attach_adapter(struct i2c_adapter *adapter); 67static int lm77_probe(struct i2c_client *client,
69static int lm77_detect(struct i2c_adapter *adapter, int address, int kind); 68 const struct i2c_device_id *id);
69static int lm77_detect(struct i2c_client *client, int kind,
70 struct i2c_board_info *info);
70static void lm77_init_client(struct i2c_client *client); 71static void lm77_init_client(struct i2c_client *client);
71static int lm77_detach_client(struct i2c_client *client); 72static int lm77_remove(struct i2c_client *client);
72static u16 lm77_read_value(struct i2c_client *client, u8 reg); 73static u16 lm77_read_value(struct i2c_client *client, u8 reg);
73static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value); 74static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value);
74 75
75static struct lm77_data *lm77_update_device(struct device *dev); 76static struct lm77_data *lm77_update_device(struct device *dev);
76 77
77 78
79static const struct i2c_device_id lm77_id[] = {
80 { "lm77", lm77 },
81 { }
82};
83MODULE_DEVICE_TABLE(i2c, lm77_id);
84
78/* This is the driver that will be inserted */ 85/* This is the driver that will be inserted */
79static struct i2c_driver lm77_driver = { 86static 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);
215static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 226static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
216static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); 227static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
217 228
218static 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
225static struct attribute *lm77_attributes[] = { 229static 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 */
244static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) 248static 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
319static 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
359exit_remove: 350exit_remove:
360 sysfs_remove_group(&new_client->dev.kobj, &lm77_group); 351 sysfs_remove_group(&new_client->dev.kobj, &lm77_group);
361exit_detach:
362 i2c_detach_client(new_client);
363exit_free: 352exit_free:
364 kfree(data); 353 kfree(data);
365exit: 354exit:
366 return err; 355 return err;
367} 356}
368 357
369static int lm77_detach_client(struct i2c_client *client) 358static 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
110struct lm80_data { 110struct 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
135static int lm80_attach_adapter(struct i2c_adapter *adapter); 134static int lm80_probe(struct i2c_client *client,
136static int lm80_detect(struct i2c_adapter *adapter, int address, int kind); 135 const struct i2c_device_id *id);
136static int lm80_detect(struct i2c_client *client, int kind,
137 struct i2c_board_info *info);
137static void lm80_init_client(struct i2c_client *client); 138static void lm80_init_client(struct i2c_client *client);
138static int lm80_detach_client(struct i2c_client *client); 139static int lm80_remove(struct i2c_client *client);
139static struct lm80_data *lm80_update_device(struct device *dev); 140static struct lm80_data *lm80_update_device(struct device *dev);
140static int lm80_read_value(struct i2c_client *client, u8 reg); 141static int lm80_read_value(struct i2c_client *client, u8 reg);
141static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); 142static 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
148static const struct i2c_device_id lm80_id[] = {
149 { "lm80", lm80 },
150 { }
151};
152MODULE_DEVICE_TABLE(i2c, lm80_id);
153
147static struct i2c_driver lm80_driver = { 154static 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
386static 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
393static struct attribute *lm80_attributes[] = { 397static 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
445static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 449/* Return 0 if detection is successful, -ENODEV otherwise */
450static 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 */ 475static 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
512error_remove: 509error_remove:
513 sysfs_remove_group(&client->dev.kobj, &lm80_group); 510 sysfs_remove_group(&client->dev.kobj, &lm80_group);
514error_detach:
515 i2c_detach_client(client);
516error_free: 511error_free:
517 kfree(data); 512 kfree(data);
518exit: 513exit:
519 return err; 514 return err;
520} 515}
521 516
522static int lm80_detach_client(struct i2c_client *client) 517static 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
121static int lm83_attach_adapter(struct i2c_adapter *adapter); 121static int lm83_detect(struct i2c_client *new_client, int kind,
122static int lm83_detect(struct i2c_adapter *adapter, int address, int kind); 122 struct i2c_board_info *info);
123static int lm83_detach_client(struct i2c_client *client); 123static int lm83_probe(struct i2c_client *client,
124 const struct i2c_device_id *id);
125static int lm83_remove(struct i2c_client *client);
124static struct lm83_data *lm83_update_device(struct device *dev); 126static 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
132static const struct i2c_device_id lm83_id[] = {
133 { "lm83", lm83 },
134 { "lm82", lm82 },
135 { }
136};
137MODULE_DEVICE_TABLE(i2c, lm83_id);
138
130static struct i2c_driver lm83_driver = { 139static 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
142struct lm83_data { 155struct 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
281static int lm83_attach_adapter(struct i2c_adapter *adapter) 293/* Return 0 if detection is successful, -ENODEV otherwise */
294static 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 */
292static 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
368static 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)
408exit_remove_files: 408exit_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);
411exit_detach:
412 i2c_detach_client(new_client);
413exit_free: 411exit_free:
414 kfree(data); 412 kfree(data);
415exit: 413exit:
416 return err; 414 return err;
417} 415}
418 416
419static int lm83_detach_client(struct i2c_client *client) 417static 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/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
160static int lm87_attach_adapter(struct i2c_adapter *adapter); 160static int lm87_probe(struct i2c_client *client,
161static int lm87_detect(struct i2c_adapter *adapter, int address, int kind); 161 const struct i2c_device_id *id);
162static int lm87_detect(struct i2c_client *new_client, int kind,
163 struct i2c_board_info *info);
162static void lm87_init_client(struct i2c_client *client); 164static void lm87_init_client(struct i2c_client *client);
163static int lm87_detach_client(struct i2c_client *client); 165static int lm87_remove(struct i2c_client *client);
164static struct lm87_data *lm87_update_device(struct device *dev); 166static 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
172static const struct i2c_device_id lm87_id[] = {
173 { "lm87", lm87 },
174 { "adm1024", adm1024 },
175 { }
176};
177MODULE_DEVICE_TABLE(i2c, lm87_id);
178
170static struct i2c_driver lm87_driver = { 179static 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
182struct lm87_data { 195struct 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
565static 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
572static struct attribute *lm87_attributes[] = { 577static 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 665static 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 */
663static 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
704static 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)
832exit_remove: 831exit_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);
835exit_detach:
836 i2c_detach_client(new_client);
837exit_free: 834exit_free:
838 kfree(data); 835 kfree(data);
839exit: 836exit:
@@ -877,18 +874,14 @@ static void lm87_init_client(struct i2c_client *client)
877 } 874 }
878} 875}
879 876
880static int lm87_detach_client(struct i2c_client *client) 877static 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
190static int lm90_attach_adapter(struct i2c_adapter *adapter); 190static int lm90_detect(struct i2c_client *client, int kind,
191static int lm90_detect(struct i2c_adapter *adapter, int address, 191 struct i2c_board_info *info);
192 int kind); 192static int lm90_probe(struct i2c_client *client,
193 const struct i2c_device_id *id);
193static void lm90_init_client(struct i2c_client *client); 194static void lm90_init_client(struct i2c_client *client);
194static int lm90_detach_client(struct i2c_client *client); 195static int lm90_remove(struct i2c_client *client);
195static struct lm90_data *lm90_update_device(struct device *dev); 196static 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
202static 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};
216MODULE_DEVICE_TABLE(i2c, lm90_id);
217
201static struct i2c_driver lm90_driver = { 218static 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
213struct lm90_data { 234struct 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
480static int lm90_attach_adapter(struct i2c_adapter *adapter) 500/* Return 0 if detection is successful, -ENODEV otherwise */
481{ 501static 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 */
491static 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
638static 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)
672exit_remove_files: 685exit_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);
675exit_detach:
676 i2c_detach_client(new_client);
677exit_free: 688exit_free:
678 kfree(data); 689 kfree(data);
679exit: 690exit:
@@ -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
713static int lm90_detach_client(struct i2c_client *client) 724static 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) */
98struct lm92_data { 98struct 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. */ 322static int lm92_detect(struct i2c_client *new_client, int kind,
324static 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
357static 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
404exit_remove: 388exit_remove:
405 sysfs_remove_group(&new_client->dev.kobj, &lm92_group); 389 sysfs_remove_group(&new_client->dev.kobj, &lm92_group);
406exit_detach:
407 i2c_detach_client(new_client);
408exit_free: 390exit_free:
409 kfree(data); 391 kfree(data);
410exit: 392exit:
411 return err; 393 return err;
412} 394}
413 395
414static int lm92_attach_adapter(struct i2c_adapter *adapter) 396static 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
421static 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
412static const struct i2c_device_id lm92_id[] = {
413 { "lm92", lm92 },
414 /* max6635 could be added here */
415 { }
416};
417MODULE_DEVICE_TABLE(i2c, lm92_id);
418
441static struct i2c_driver lm92_driver = { 419static 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
449static int __init sensors_lm92_init(void) 431static 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 */
202struct lm93_data { 202struct 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
2504static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) 2503/* Return 0 if detection is successful, -ENODEV otherwise */
2504static 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
2546static 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);
2600err_detach:
2601 i2c_detach_client(client);
2602err_free: 2598err_free:
2603 kfree(data); 2599 kfree(data);
2604err_out: 2600err_out:
2605 return err; 2601 return err;
2606} 2602}
2607 2603
2608/* This function is called when: 2604static 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) */
2612static int lm93_attach_adapter(struct i2c_adapter *adapter)
2613{
2614 return i2c_probe(adapter, &addr_data, lm93_detect);
2615}
2616
2617static 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
2615static const struct i2c_device_id lm93_id[] = {
2616 { "lm93", lm93 },
2617 { }
2618};
2619MODULE_DEVICE_TABLE(i2c, lm93_id);
2620
2631static struct i2c_driver lm93_driver = { 2621static 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
2639static int __init lm93_init(void) 2633static 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
82static int max1619_attach_adapter(struct i2c_adapter *adapter); 82static int max1619_probe(struct i2c_client *client,
83static int max1619_detect(struct i2c_adapter *adapter, int address, 83 const struct i2c_device_id *id);
84 int kind); 84static int max1619_detect(struct i2c_client *client, int kind,
85 struct i2c_board_info *info);
85static void max1619_init_client(struct i2c_client *client); 86static void max1619_init_client(struct i2c_client *client);
86static int max1619_detach_client(struct i2c_client *client); 87static int max1619_remove(struct i2c_client *client);
87static struct max1619_data *max1619_update_device(struct device *dev); 88static 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
94static const struct i2c_device_id max1619_id[] = {
95 { "max1619", max1619 },
96 { }
97};
98MODULE_DEVICE_TABLE(i2c, max1619_id);
99
93static struct i2c_driver max1619_driver = { 100static 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
105struct max1619_data { 116struct 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
211static int max1619_attach_adapter(struct i2c_adapter *adapter) 221/* Return 0 if detection is successful, -ENODEV otherwise */
212{ 222static 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 */
222static 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
281static 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
319exit_remove_files: 312exit_remove_files:
320 sysfs_remove_group(&new_client->dev.kobj, &max1619_group); 313 sysfs_remove_group(&new_client->dev.kobj, &max1619_group);
321exit_detach:
322 i2c_detach_client(new_client);
323exit_free: 314exit_free:
324 kfree(data); 315 kfree(data);
325exit: 316exit:
@@ -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
344static int max1619_detach_client(struct i2c_client *client) 335static 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
107static int max6650_attach_adapter(struct i2c_adapter *adapter); 107static int max6650_probe(struct i2c_client *client,
108static int max6650_detect(struct i2c_adapter *adapter, int address, int kind); 108 const struct i2c_device_id *id);
109static int max6650_detect(struct i2c_client *client, int kind,
110 struct i2c_board_info *info);
109static int max6650_init_client(struct i2c_client *client); 111static int max6650_init_client(struct i2c_client *client);
110static int max6650_detach_client(struct i2c_client *client); 112static int max6650_remove(struct i2c_client *client);
111static struct max6650_data *max6650_update_device(struct device *dev); 113static 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
119static const struct i2c_device_id max6650_id[] = {
120 { "max6650", max6650 },
121 { }
122};
123MODULE_DEVICE_TABLE(i2c, max6650_id);
124
117static struct i2c_driver max6650_driver = { 125static 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
129struct max6650_data 141struct 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
440static int max6650_attach_adapter(struct i2c_adapter *adapter) 451/* Return 0 if detection is successful, -ENODEV otherwise */
452static 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
456static 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
499static 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);
534err_detach:
535 i2c_detach_client(client);
536err_free: 531err_free:
537 kfree(data); 532 kfree(data);
538 return err; 533 return err;
539} 534}
540 535
541static int max6650_detach_client(struct i2c_client *client) 536static 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
554static int max6650_init_client(struct i2c_client *client) 546static 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
98struct smsc47m192_data { 98struct 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
117static int smsc47m192_attach_adapter(struct i2c_adapter *adapter); 116static int smsc47m192_probe(struct i2c_client *client,
118static int smsc47m192_detect(struct i2c_adapter *adapter, int address, 117 const struct i2c_device_id *id);
119 int kind); 118static int smsc47m192_detect(struct i2c_client *client, int kind,
120static int smsc47m192_detach_client(struct i2c_client *client); 119 struct i2c_board_info *info);
120static int smsc47m192_remove(struct i2c_client *client);
121static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); 121static struct smsc47m192_data *smsc47m192_update_device(struct device *dev);
122 122
123static const struct i2c_device_id smsc47m192_id[] = {
124 { "smsc47m192", smsc47m192 },
125 { }
126};
127MODULE_DEVICE_TABLE(i2c, smsc47m192_id);
128
123static struct i2c_driver smsc47m192_driver = { 129static 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) */
447static 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
454static void smsc47m192_init_client(struct i2c_client *client) 453static 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 */
485static int smsc47m192_detect(struct i2c_adapter *adapter, int address, 484static 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
519static 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,
563exit_remove_files: 559exit_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);
566exit_detach:
567 i2c_detach_client(client);
568exit_free: 562exit_free:
569 kfree(data); 563 kfree(data);
570exit: 564exit:
571 return err; 565 return err;
572} 566}
573 567
574static int smsc47m192_detach_client(struct i2c_client *client) 568static 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 */
62struct thmc50_data { 62struct 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
80static int thmc50_attach_adapter(struct i2c_adapter *adapter); 79static int thmc50_detect(struct i2c_client *client, int kind,
81static int thmc50_detach_client(struct i2c_client *client); 80 struct i2c_board_info *info);
81static int thmc50_probe(struct i2c_client *client,
82 const struct i2c_device_id *id);
83static int thmc50_remove(struct i2c_client *client);
82static void thmc50_init_client(struct i2c_client *client); 84static void thmc50_init_client(struct i2c_client *client);
83static struct thmc50_data *thmc50_update_device(struct device *dev); 85static struct thmc50_data *thmc50_update_device(struct device *dev);
84 86
87static const struct i2c_device_id thmc50_id[] = {
88 { "adm1022", adm1022 },
89 { "thmc50", thmc50 },
90 { }
91};
92MODULE_DEVICE_TABLE(i2c, thmc50_id);
93
85static struct i2c_driver thmc50_driver = { 94static 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
93static ssize_t show_analog_out(struct device *dev, 106static 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
253static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) 266/* Return 0 if detection is successful, -ENODEV otherwise */
267static 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
336static 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);
365exit_remove_sysfs_thmc50: 377exit_remove_sysfs_thmc50:
366 sysfs_remove_group(&client->dev.kobj, &thmc50_group); 378 sysfs_remove_group(&client->dev.kobj, &thmc50_group);
367exit_detach:
368 i2c_detach_client(client);
369exit_free: 379exit_free:
370 kfree(data); 380 kfree(data);
371exit: 381exit:
372 return err; 382 return err;
373} 383}
374 384
375static int thmc50_attach_adapter(struct i2c_adapter *adapter) 385static 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
382static 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
249struct w83791d_data { 249struct 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
289static int w83791d_attach_adapter(struct i2c_adapter *adapter); 288static int w83791d_probe(struct i2c_client *client,
290static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind); 289 const struct i2c_device_id *id);
291static int w83791d_detach_client(struct i2c_client *client); 290static int w83791d_detect(struct i2c_client *client, int kind,
291 struct i2c_board_info *info);
292static int w83791d_remove(struct i2c_client *client);
292 293
293static int w83791d_read(struct i2c_client *client, u8 register); 294static int w83791d_read(struct i2c_client *client, u8 register);
294static int w83791d_write(struct i2c_client *client, u8 register, u8 value); 295static 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
301static void w83791d_init_client(struct i2c_client *client); 302static void w83791d_init_client(struct i2c_client *client);
302 303
304static const struct i2c_device_id w83791d_id[] = {
305 { "w83791d", w83791d },
306 { }
307};
308MODULE_DEVICE_TABLE(i2c, w83791d_id);
309
303static struct i2c_driver w83791d_driver = { 310static 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) */
912static 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
920static int w83791d_create_subclient(struct i2c_adapter *adapter, 920static 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
947static 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
999error_sc_1: 968error_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 }
1004error_sc_0: 971error_sc_0:
1005 return err; 972 return err;
1006} 973}
1007 974
1008 975
1009static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) 976/* Return 0 if detection is successful, -ENODEV otherwise */
977static 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; 1044static 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)
1141error4: 1092error4:
1142 sysfs_remove_group(&client->dev.kobj, &w83791d_group); 1093 sysfs_remove_group(&client->dev.kobj, &w83791d_group);
1143error3: 1094error3:
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 }
1152error2:
1153 i2c_detach_client(client);
1154error1: 1099error1:
1155 kfree(data); 1100 kfree(data);
1156error0: 1101error0:
1157 return err; 1102 return err;
1158} 1103}
1159 1104
1160static int w83791d_detach_client(struct i2c_client *client) 1105static 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
269struct w83792d_data { 269struct 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
302static int w83792d_attach_adapter(struct i2c_adapter *adapter); 300static int w83792d_probe(struct i2c_client *client,
303static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind); 301 const struct i2c_device_id *id);
304static int w83792d_detach_client(struct i2c_client *client); 302static int w83792d_detect(struct i2c_client *client, int kind,
303 struct i2c_board_info *info);
304static int w83792d_remove(struct i2c_client *client);
305static struct w83792d_data *w83792d_update_device(struct device *dev); 305static 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
311static void w83792d_init_client(struct i2c_client *client); 311static void w83792d_init_client(struct i2c_client *client);
312 312
313static const struct i2c_device_id w83792d_id[] = {
314 { "w83792d", w83792d },
315 { }
316};
317MODULE_DEVICE_TABLE(i2c, w83792d_id);
318
313static struct i2c_driver w83792d_driver = { 319static 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
321static inline long in_count_from_reg(int nr, struct w83792d_data *data) 331static 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) */
871static int
872w83792d_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
880static int
881w83792d_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
908static int 878static int
909w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, 879w83792d_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
958ERROR_SC_1: 924ERROR_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 }
963ERROR_SC_0: 927ERROR_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 */
1297static int 1262static int
1298w83792d_detect(struct i2c_adapter *adapter, int address, int kind) 1263w83792d_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; 1331static int
1392 } 1332w83792d_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]);
1459ERROR3: 1402ERROR3:
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 }
1468ERROR2:
1469 i2c_detach_client(client);
1470ERROR1: 1407ERROR1:
1471 kfree(data); 1408 kfree(data);
1472ERROR0: 1409ERROR0:
@@ -1474,30 +1411,23 @@ ERROR0:
1474} 1411}
1475 1412
1476static int 1413static int
1477w83792d_detach_client(struct i2c_client *client) 1414w83792d_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
181struct w83793_data { 181struct 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
227static u8 w83793_read_value(struct i2c_client *client, u16 reg); 226static u8 w83793_read_value(struct i2c_client *client, u16 reg);
228static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); 227static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
229static int w83793_attach_adapter(struct i2c_adapter *adapter); 228static int w83793_probe(struct i2c_client *client,
230static int w83793_detect(struct i2c_adapter *adapter, int address, int kind); 229 const struct i2c_device_id *id);
231static int w83793_detach_client(struct i2c_client *client); 230static int w83793_detect(struct i2c_client *client, int kind,
231 struct i2c_board_info *info);
232static int w83793_remove(struct i2c_client *client);
232static void w83793_init_client(struct i2c_client *client); 233static void w83793_init_client(struct i2c_client *client);
233static void w83793_update_nonvolatile(struct device *dev); 234static void w83793_update_nonvolatile(struct device *dev);
234static struct w83793_data *w83793_update_device(struct device *dev); 235static struct w83793_data *w83793_update_device(struct device *dev);
235 236
237static const struct i2c_device_id w83793_id[] = {
238 { "w83793", w83793 },
239 { }
240};
241MODULE_DEVICE_TABLE(i2c, w83793_id);
242
236static struct i2c_driver w83793_driver = { 243static 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
244static ssize_t 255static ssize_t
@@ -1053,89 +1064,51 @@ static void w83793_init_client(struct i2c_client *client)
1053 1064
1054} 1065}
1055 1066
1056static int w83793_attach_adapter(struct i2c_adapter *adapter) 1067static 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
1063static 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
1107static int 1105static int
1108w83793_create_subclient(struct i2c_adapter *adapter, 1106w83793_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
1133static int
1134w83793_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
1186ERROR_SC_1: 1153ERROR_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 }
1191ERROR_SC_0: 1156ERROR_SC_0:
1192 return err; 1157 return err;
1193} 1158}
1194 1159
1195static int w83793_detect(struct i2c_adapter *adapter, int address, int kind) 1160/* Return 0 if detection is successful, -ENODEV otherwise */
1161static 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
1217static 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 }
1470detach_client:
1471 i2c_detach_client(client);
1472free_mem: 1425free_mem:
1473 kfree(data); 1426 kfree(data);
1474exit: 1427exit:
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
84static int w83l785ts_attach_adapter(struct i2c_adapter *adapter); 84static int w83l785ts_probe(struct i2c_client *client,
85static int w83l785ts_detect(struct i2c_adapter *adapter, int address, 85 const struct i2c_device_id *id);
86 int kind); 86static int w83l785ts_detect(struct i2c_client *client, int kind,
87static int w83l785ts_detach_client(struct i2c_client *client); 87 struct i2c_board_info *info);
88static int w83l785ts_remove(struct i2c_client *client);
88static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); 89static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval);
89static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); 90static 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
96static const struct i2c_device_id w83l785ts_id[] = {
97 { "w83l785ts", w83l785ts },
98 { }
99};
100MODULE_DEVICE_TABLE(i2c, w83l785ts_id);
101
95static struct i2c_driver w83l785ts_driver = { 102static 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
107struct w83l785ts_data { 118struct 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
138static int w83l785ts_attach_adapter(struct i2c_adapter *adapter) 148/* Return 0 if detection is successful, -ENODEV otherwise */
139{ 149static 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 */
149static 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
210static 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);
263exit_free:
264 kfree(data); 258 kfree(data);
265exit: 259exit:
266 return err; 260 return err;
267} 261}
268 262
269static int w83l785ts_detach_client(struct i2c_client *client) 263static 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)
286static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) 277static 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
123struct w83l786ng_data { 123struct 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
149static int w83l786ng_attach_adapter(struct i2c_adapter *adapter); 148static int w83l786ng_probe(struct i2c_client *client,
150static int w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind); 149 const struct i2c_device_id *id);
151static int w83l786ng_detach_client(struct i2c_client *client); 150static int w83l786ng_detect(struct i2c_client *client, int kind,
151 struct i2c_board_info *info);
152static int w83l786ng_remove(struct i2c_client *client);
152static void w83l786ng_init_client(struct i2c_client *client); 153static void w83l786ng_init_client(struct i2c_client *client);
153static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); 154static struct w83l786ng_data *w83l786ng_update_device(struct device *dev);
154 155
156static const struct i2c_device_id w83l786ng_id[] = {
157 { "w83l786ng", w83l786ng },
158 { }
159};
160MODULE_DEVICE_TABLE(i2c, w83l786ng_id);
161
155static struct i2c_driver w83l786ng_driver = { 162static 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
163static u8 174static u8
@@ -575,42 +586,15 @@ static const struct attribute_group w83l786ng_group = {
575}; 586};
576 587
577static int 588static int
578w83l786ng_attach_adapter(struct i2c_adapter *adapter) 589w83l786ng_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
585static int
586w83l786ng_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
647static int
648w83l786ng_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
694exit_remove: 692exit_remove:
695 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); 693 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
696 i2c_detach_client(client);
697exit_free:
698 kfree(data); 694 kfree(data);
699exit: 695exit:
700 return err; 696 return err;
701} 697}
702 698
703static int 699static int
704w83l786ng_detach_client(struct i2c_client *client) 700w83l786ng_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;