diff options
50 files changed, 2129 insertions, 2797 deletions
diff --git a/Documentation/i2c/chips/max6875 b/Documentation/i2c/chips/max6875 index a0cd8af2f408..10ca43cd1a72 100644 --- a/Documentation/i2c/chips/max6875 +++ b/Documentation/i2c/chips/max6875 | |||
@@ -49,7 +49,7 @@ $ modprobe max6875 force=0,0x50 | |||
49 | 49 | ||
50 | The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple | 50 | The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple |
51 | addresses. For example, for address 0x50, it also reserves 0x51. | 51 | addresses. For example, for address 0x50, it also reserves 0x51. |
52 | The even-address instance is called 'max6875', the odd one is 'max6875 subclient'. | 52 | The even-address instance is called 'max6875', the odd one is 'dummy'. |
53 | 53 | ||
54 | 54 | ||
55 | Programming the chip using i2c-dev | 55 | Programming the chip using i2c-dev |
diff --git a/Documentation/i2c/chips/pca9539 b/Documentation/i2c/chips/pca9539 index 1d81c530c4a5..6aff890088b1 100644 --- a/Documentation/i2c/chips/pca9539 +++ b/Documentation/i2c/chips/pca9539 | |||
@@ -7,7 +7,7 @@ drivers/gpio/pca9539.c instead. | |||
7 | Supported chips: | 7 | Supported chips: |
8 | * Philips PCA9539 | 8 | * Philips PCA9539 |
9 | Prefix: 'pca9539' | 9 | Prefix: 'pca9539' |
10 | Addresses scanned: 0x74 - 0x77 | 10 | Addresses scanned: none |
11 | Datasheet: | 11 | Datasheet: |
12 | http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf | 12 | http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf |
13 | 13 | ||
@@ -23,6 +23,14 @@ The input sense can also be inverted. | |||
23 | The 16 lines are split between two bytes. | 23 | The 16 lines are split between two bytes. |
24 | 24 | ||
25 | 25 | ||
26 | Detection | ||
27 | --------- | ||
28 | |||
29 | The PCA9539 is difficult to detect and not commonly found in PC machines, | ||
30 | so you have to pass the I2C bus and address of the installed PCA9539 | ||
31 | devices explicitly to the driver at load time via the force=... parameter. | ||
32 | |||
33 | |||
26 | Sysfs entries | 34 | Sysfs entries |
27 | ------------- | 35 | ------------- |
28 | 36 | ||
diff --git a/Documentation/i2c/chips/pcf8574 b/Documentation/i2c/chips/pcf8574 index 5c1ad1376b62..235815c075ff 100644 --- a/Documentation/i2c/chips/pcf8574 +++ b/Documentation/i2c/chips/pcf8574 | |||
@@ -4,13 +4,13 @@ Kernel driver pcf8574 | |||
4 | Supported chips: | 4 | Supported chips: |
5 | * Philips PCF8574 | 5 | * Philips PCF8574 |
6 | Prefix: 'pcf8574' | 6 | Prefix: 'pcf8574' |
7 | Addresses scanned: I2C 0x20 - 0x27 | 7 | Addresses scanned: none |
8 | Datasheet: Publicly available at the Philips Semiconductors website | 8 | Datasheet: Publicly available at the Philips Semiconductors website |
9 | http://www.semiconductors.philips.com/pip/PCF8574P.html | 9 | http://www.semiconductors.philips.com/pip/PCF8574P.html |
10 | 10 | ||
11 | * Philips PCF8574A | 11 | * Philips PCF8574A |
12 | Prefix: 'pcf8574a' | 12 | Prefix: 'pcf8574a' |
13 | Addresses scanned: I2C 0x38 - 0x3f | 13 | Addresses scanned: none |
14 | Datasheet: Publicly available at the Philips Semiconductors website | 14 | Datasheet: Publicly available at the Philips Semiconductors website |
15 | http://www.semiconductors.philips.com/pip/PCF8574P.html | 15 | http://www.semiconductors.philips.com/pip/PCF8574P.html |
16 | 16 | ||
@@ -38,12 +38,10 @@ For more informations see the datasheet. | |||
38 | Accessing PCF8574(A) via /sys interface | 38 | Accessing PCF8574(A) via /sys interface |
39 | ------------------------------------- | 39 | ------------------------------------- |
40 | 40 | ||
41 | ! Be careful ! | ||
42 | The PCF8574(A) is plainly impossible to detect ! Stupid chip. | 41 | The PCF8574(A) is plainly impossible to detect ! Stupid chip. |
43 | So every chip with address in the interval [20..27] and [38..3f] are | 42 | So, you have to pass the I2C bus and address of the installed PCF857A |
44 | detected as PCF8574(A). If you have other chips in this address | 43 | and PCF8574A devices explicitly to the driver at load time via the |
45 | range, the workaround is to load this module after the one | 44 | force=... parameter. |
46 | for your others chips. | ||
47 | 45 | ||
48 | On detection (i.e. insmod, modprobe et al.), directories are being | 46 | On detection (i.e. insmod, modprobe et al.), directories are being |
49 | created for each detected PCF8574(A): | 47 | created for each detected PCF8574(A): |
diff --git a/Documentation/i2c/chips/pcf8575 b/Documentation/i2c/chips/pcf8575 index 25f5698a61cf..40b268eb276f 100644 --- a/Documentation/i2c/chips/pcf8575 +++ b/Documentation/i2c/chips/pcf8575 | |||
@@ -40,12 +40,9 @@ Detection | |||
40 | --------- | 40 | --------- |
41 | 41 | ||
42 | There is no method known to detect whether a chip on a given I2C address is | 42 | There is no method known to detect whether a chip on a given I2C address is |
43 | a PCF8575 or whether it is any other I2C device. So there are two alternatives | 43 | a PCF8575 or whether it is any other I2C device, so you have to pass the I2C |
44 | to let the driver find the installed PCF8575 devices: | 44 | bus and address of the installed PCF8575 devices explicitly to the driver at |
45 | - Load this driver after any other I2C driver for I2C devices with addresses | 45 | load time via the force=... parameter. |
46 | in the range 0x20 .. 0x27. | ||
47 | - Pass the I2C bus and address of the installed PCF8575 devices explicitly to | ||
48 | the driver at load time via the probe=... or force=... parameters. | ||
49 | 46 | ||
50 | /sys interface | 47 | /sys interface |
51 | -------------- | 48 | -------------- |
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c index 466b9ee92797..f97b5b356875 100644 --- a/drivers/hwmon/ad7418.c +++ b/drivers/hwmon/ad7418.c | |||
@@ -23,12 +23,9 @@ | |||
23 | 23 | ||
24 | #include "lm75.h" | 24 | #include "lm75.h" |
25 | 25 | ||
26 | #define DRV_VERSION "0.3" | 26 | #define DRV_VERSION "0.4" |
27 | 27 | ||
28 | /* Addresses to scan */ | 28 | enum chips { ad7416, ad7417, ad7418 }; |
29 | static const unsigned short normal_i2c[] = { 0x28, I2C_CLIENT_END }; | ||
30 | /* Insmod parameters */ | ||
31 | I2C_CLIENT_INSMOD_3(ad7416, ad7417, ad7418); | ||
32 | 29 | ||
33 | /* AD7418 registers */ | 30 | /* AD7418 registers */ |
34 | #define AD7418_REG_TEMP_IN 0x00 | 31 | #define AD7418_REG_TEMP_IN 0x00 |
@@ -46,7 +43,6 @@ static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN, | |||
46 | AD7418_REG_TEMP_OS }; | 43 | AD7418_REG_TEMP_OS }; |
47 | 44 | ||
48 | struct ad7418_data { | 45 | struct ad7418_data { |
49 | struct i2c_client client; | ||
50 | struct device *hwmon_dev; | 46 | struct device *hwmon_dev; |
51 | struct attribute_group attrs; | 47 | struct attribute_group attrs; |
52 | enum chips type; | 48 | enum chips type; |
@@ -58,16 +54,25 @@ struct ad7418_data { | |||
58 | u16 in[4]; | 54 | u16 in[4]; |
59 | }; | 55 | }; |
60 | 56 | ||
61 | static int ad7418_attach_adapter(struct i2c_adapter *adapter); | 57 | static int ad7418_probe(struct i2c_client *client, |
62 | static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind); | 58 | const struct i2c_device_id *id); |
63 | static int ad7418_detach_client(struct i2c_client *client); | 59 | static int ad7418_remove(struct i2c_client *client); |
60 | |||
61 | static const struct i2c_device_id ad7418_id[] = { | ||
62 | { "ad7416", ad7416 }, | ||
63 | { "ad7417", ad7417 }, | ||
64 | { "ad7418", ad7418 }, | ||
65 | { } | ||
66 | }; | ||
67 | MODULE_DEVICE_TABLE(i2c, ad7418_id); | ||
64 | 68 | ||
65 | static struct i2c_driver ad7418_driver = { | 69 | static struct i2c_driver ad7418_driver = { |
66 | .driver = { | 70 | .driver = { |
67 | .name = "ad7418", | 71 | .name = "ad7418", |
68 | }, | 72 | }, |
69 | .attach_adapter = ad7418_attach_adapter, | 73 | .probe = ad7418_probe, |
70 | .detach_client = ad7418_detach_client, | 74 | .remove = ad7418_remove, |
75 | .id_table = ad7418_id, | ||
71 | }; | 76 | }; |
72 | 77 | ||
73 | /* All registers are word-sized, except for the configuration registers. | 78 | /* All registers are word-sized, except for the configuration registers. |
@@ -192,13 +197,6 @@ static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 1); | |||
192 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); | 197 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); |
193 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); | 198 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); |
194 | 199 | ||
195 | static int ad7418_attach_adapter(struct i2c_adapter *adapter) | ||
196 | { | ||
197 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
198 | return 0; | ||
199 | return i2c_probe(adapter, &addr_data, ad7418_detect); | ||
200 | } | ||
201 | |||
202 | static struct attribute *ad7416_attributes[] = { | 200 | static struct attribute *ad7416_attributes[] = { |
203 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 201 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
204 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 202 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
@@ -225,98 +223,46 @@ static struct attribute *ad7418_attributes[] = { | |||
225 | NULL | 223 | NULL |
226 | }; | 224 | }; |
227 | 225 | ||
228 | static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | 226 | static int ad7418_probe(struct i2c_client *client, |
227 | const struct i2c_device_id *id) | ||
229 | { | 228 | { |
230 | struct i2c_client *client; | 229 | struct i2c_adapter *adapter = client->adapter; |
231 | struct ad7418_data *data; | 230 | struct ad7418_data *data; |
232 | int err = 0; | 231 | int err; |
233 | 232 | ||
234 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 233 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
235 | I2C_FUNC_SMBUS_WORD_DATA)) | 234 | I2C_FUNC_SMBUS_WORD_DATA)) { |
235 | err = -EOPNOTSUPP; | ||
236 | goto exit; | 236 | goto exit; |
237 | } | ||
237 | 238 | ||
238 | if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) { | 239 | if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) { |
239 | err = -ENOMEM; | 240 | err = -ENOMEM; |
240 | goto exit; | 241 | goto exit; |
241 | } | 242 | } |
242 | 243 | ||
243 | client = &data->client; | ||
244 | client->addr = address; | ||
245 | client->adapter = adapter; | ||
246 | client->driver = &ad7418_driver; | ||
247 | |||
248 | i2c_set_clientdata(client, data); | 244 | i2c_set_clientdata(client, data); |
249 | 245 | ||
250 | mutex_init(&data->lock); | 246 | mutex_init(&data->lock); |
251 | 247 | data->type = id->driver_data; | |
252 | /* AD7418 has a curious behaviour on registers 6 and 7. They | ||
253 | * both always read 0xC071 and are not documented on the datasheet. | ||
254 | * We use them to detect the chip. | ||
255 | */ | ||
256 | if (kind <= 0) { | ||
257 | int reg, reg6, reg7; | ||
258 | |||
259 | /* the AD7416 lies within this address range, but I have | ||
260 | * no means to check. | ||
261 | */ | ||
262 | if (address >= 0x48 && address <= 0x4f) { | ||
263 | /* XXX add tests for AD7416 here */ | ||
264 | /* data->type = ad7416; */ | ||
265 | } | ||
266 | /* here we might have AD7417 or AD7418 */ | ||
267 | else if (address >= 0x28 && address <= 0x2f) { | ||
268 | reg6 = i2c_smbus_read_word_data(client, 0x06); | ||
269 | reg7 = i2c_smbus_read_word_data(client, 0x07); | ||
270 | |||
271 | if (address == 0x28 && reg6 == 0xC071 && reg7 == 0xC071) | ||
272 | data->type = ad7418; | ||
273 | |||
274 | /* XXX add tests for AD7417 here */ | ||
275 | |||
276 | |||
277 | /* both AD7417 and AD7418 have bits 0-5 of | ||
278 | * the CONF2 register at 0 | ||
279 | */ | ||
280 | reg = i2c_smbus_read_byte_data(client, | ||
281 | AD7418_REG_CONF2); | ||
282 | if (reg & 0x3F) | ||
283 | data->type = any_chip; /* detection failed */ | ||
284 | } | ||
285 | } else { | ||
286 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
287 | } | ||
288 | |||
289 | if (kind > 0) | ||
290 | data->type = kind; | ||
291 | else if (kind < 0 && data->type == any_chip) { | ||
292 | err = -ENODEV; | ||
293 | goto exit_free; | ||
294 | } | ||
295 | 248 | ||
296 | switch (data->type) { | 249 | switch (data->type) { |
297 | case any_chip: | ||
298 | case ad7416: | 250 | case ad7416: |
299 | data->adc_max = 0; | 251 | data->adc_max = 0; |
300 | data->attrs.attrs = ad7416_attributes; | 252 | data->attrs.attrs = ad7416_attributes; |
301 | strlcpy(client->name, "ad7416", I2C_NAME_SIZE); | ||
302 | break; | 253 | break; |
303 | 254 | ||
304 | case ad7417: | 255 | case ad7417: |
305 | data->adc_max = 4; | 256 | data->adc_max = 4; |
306 | data->attrs.attrs = ad7417_attributes; | 257 | data->attrs.attrs = ad7417_attributes; |
307 | strlcpy(client->name, "ad7417", I2C_NAME_SIZE); | ||
308 | break; | 258 | break; |
309 | 259 | ||
310 | case ad7418: | 260 | case ad7418: |
311 | data->adc_max = 1; | 261 | data->adc_max = 1; |
312 | data->attrs.attrs = ad7418_attributes; | 262 | data->attrs.attrs = ad7418_attributes; |
313 | strlcpy(client->name, "ad7418", I2C_NAME_SIZE); | ||
314 | break; | 263 | break; |
315 | } | 264 | } |
316 | 265 | ||
317 | if ((err = i2c_attach_client(client))) | ||
318 | goto exit_free; | ||
319 | |||
320 | dev_info(&client->dev, "%s chip found\n", client->name); | 266 | dev_info(&client->dev, "%s chip found\n", client->name); |
321 | 267 | ||
322 | /* Initialize the AD7418 chip */ | 268 | /* Initialize the AD7418 chip */ |
@@ -324,7 +270,7 @@ static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | |||
324 | 270 | ||
325 | /* Register sysfs hooks */ | 271 | /* Register sysfs hooks */ |
326 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) | 272 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) |
327 | goto exit_detach; | 273 | goto exit_free; |
328 | 274 | ||
329 | data->hwmon_dev = hwmon_device_register(&client->dev); | 275 | data->hwmon_dev = hwmon_device_register(&client->dev); |
330 | if (IS_ERR(data->hwmon_dev)) { | 276 | if (IS_ERR(data->hwmon_dev)) { |
@@ -336,20 +282,17 @@ static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind) | |||
336 | 282 | ||
337 | exit_remove: | 283 | exit_remove: |
338 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 284 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
339 | exit_detach: | ||
340 | i2c_detach_client(client); | ||
341 | exit_free: | 285 | exit_free: |
342 | kfree(data); | 286 | kfree(data); |
343 | exit: | 287 | exit: |
344 | return err; | 288 | return err; |
345 | } | 289 | } |
346 | 290 | ||
347 | static int ad7418_detach_client(struct i2c_client *client) | 291 | static int ad7418_remove(struct i2c_client *client) |
348 | { | 292 | { |
349 | struct ad7418_data *data = i2c_get_clientdata(client); | 293 | struct ad7418_data *data = i2c_get_clientdata(client); |
350 | hwmon_device_unregister(data->hwmon_dev); | 294 | hwmon_device_unregister(data->hwmon_dev); |
351 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 295 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
352 | i2c_detach_client(client); | ||
353 | kfree(data); | 296 | kfree(data); |
354 | return 0; | 297 | return 0; |
355 | } | 298 | } |
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index ecbf69484bf5..b11e06f644b1 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -78,7 +78,6 @@ clearing it. Weird, ey? --Phil */ | |||
78 | 78 | ||
79 | /* Each client has this additional data */ | 79 | /* Each client has this additional data */ |
80 | struct adm1021_data { | 80 | struct adm1021_data { |
81 | struct i2c_client client; | ||
82 | struct device *hwmon_dev; | 81 | struct device *hwmon_dev; |
83 | enum chips type; | 82 | enum chips type; |
84 | 83 | ||
@@ -98,23 +97,42 @@ struct adm1021_data { | |||
98 | u8 remote_temp_offset_prec; | 97 | u8 remote_temp_offset_prec; |
99 | }; | 98 | }; |
100 | 99 | ||
101 | static int adm1021_attach_adapter(struct i2c_adapter *adapter); | 100 | static int adm1021_probe(struct i2c_client *client, |
102 | static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind); | 101 | const struct i2c_device_id *id); |
102 | static int adm1021_detect(struct i2c_client *client, int kind, | ||
103 | struct i2c_board_info *info); | ||
103 | static void adm1021_init_client(struct i2c_client *client); | 104 | static void adm1021_init_client(struct i2c_client *client); |
104 | static int adm1021_detach_client(struct i2c_client *client); | 105 | static int adm1021_remove(struct i2c_client *client); |
105 | static struct adm1021_data *adm1021_update_device(struct device *dev); | 106 | static struct adm1021_data *adm1021_update_device(struct device *dev); |
106 | 107 | ||
107 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ | 108 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ |
108 | static int read_only; | 109 | static int read_only; |
109 | 110 | ||
110 | 111 | ||
112 | static const struct i2c_device_id adm1021_id[] = { | ||
113 | { "adm1021", adm1021 }, | ||
114 | { "adm1023", adm1023 }, | ||
115 | { "max1617", max1617 }, | ||
116 | { "max1617a", max1617a }, | ||
117 | { "thmc10", thmc10 }, | ||
118 | { "lm84", lm84 }, | ||
119 | { "gl523sm", gl523sm }, | ||
120 | { "mc1066", mc1066 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, adm1021_id); | ||
124 | |||
111 | /* This is the driver that will be inserted */ | 125 | /* This is the driver that will be inserted */ |
112 | static struct i2c_driver adm1021_driver = { | 126 | static struct i2c_driver adm1021_driver = { |
127 | .class = I2C_CLASS_HWMON, | ||
113 | .driver = { | 128 | .driver = { |
114 | .name = "adm1021", | 129 | .name = "adm1021", |
115 | }, | 130 | }, |
116 | .attach_adapter = adm1021_attach_adapter, | 131 | .probe = adm1021_probe, |
117 | .detach_client = adm1021_detach_client, | 132 | .remove = adm1021_remove, |
133 | .id_table = adm1021_id, | ||
134 | .detect = adm1021_detect, | ||
135 | .address_data = &addr_data, | ||
118 | }; | 136 | }; |
119 | 137 | ||
120 | static ssize_t show_temp(struct device *dev, | 138 | static ssize_t show_temp(struct device *dev, |
@@ -216,13 +234,6 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | |||
216 | 234 | ||
217 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 235 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
218 | 236 | ||
219 | static int adm1021_attach_adapter(struct i2c_adapter *adapter) | ||
220 | { | ||
221 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
222 | return 0; | ||
223 | return i2c_probe(adapter, &addr_data, adm1021_detect); | ||
224 | } | ||
225 | |||
226 | static struct attribute *adm1021_attributes[] = { | 237 | static struct attribute *adm1021_attributes[] = { |
227 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 238 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
228 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 239 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -243,36 +254,21 @@ static const struct attribute_group adm1021_group = { | |||
243 | .attrs = adm1021_attributes, | 254 | .attrs = adm1021_attributes, |
244 | }; | 255 | }; |
245 | 256 | ||
246 | static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | 257 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
258 | static int adm1021_detect(struct i2c_client *client, int kind, | ||
259 | struct i2c_board_info *info) | ||
247 | { | 260 | { |
261 | struct i2c_adapter *adapter = client->adapter; | ||
248 | int i; | 262 | int i; |
249 | struct i2c_client *client; | ||
250 | struct adm1021_data *data; | ||
251 | int err = 0; | ||
252 | const char *type_name = ""; | 263 | const char *type_name = ""; |
253 | int conv_rate, status, config; | 264 | int conv_rate, status, config; |
254 | 265 | ||
255 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 266 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
256 | pr_debug("adm1021: detect failed, " | 267 | pr_debug("adm1021: detect failed, " |
257 | "smbus byte data not supported!\n"); | 268 | "smbus byte data not supported!\n"); |
258 | goto error0; | 269 | return -ENODEV; |
259 | } | ||
260 | |||
261 | /* OK. For now, we presume we have a valid client. We now create the | ||
262 | client structure, even though we cannot fill it completely yet. | ||
263 | But it allows us to access adm1021 register values. */ | ||
264 | |||
265 | if (!(data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL))) { | ||
266 | pr_debug("adm1021: detect failed, kzalloc failed!\n"); | ||
267 | err = -ENOMEM; | ||
268 | goto error0; | ||
269 | } | 270 | } |
270 | 271 | ||
271 | client = &data->client; | ||
272 | i2c_set_clientdata(client, data); | ||
273 | client->addr = address; | ||
274 | client->adapter = adapter; | ||
275 | client->driver = &adm1021_driver; | ||
276 | status = i2c_smbus_read_byte_data(client, ADM1021_REG_STATUS); | 272 | status = i2c_smbus_read_byte_data(client, ADM1021_REG_STATUS); |
277 | conv_rate = i2c_smbus_read_byte_data(client, | 273 | conv_rate = i2c_smbus_read_byte_data(client, |
278 | ADM1021_REG_CONV_RATE_R); | 274 | ADM1021_REG_CONV_RATE_R); |
@@ -284,8 +280,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
284 | || (conv_rate & 0xF8) != 0x00) { | 280 | || (conv_rate & 0xF8) != 0x00) { |
285 | pr_debug("adm1021: detect failed, " | 281 | pr_debug("adm1021: detect failed, " |
286 | "chip not detected!\n"); | 282 | "chip not detected!\n"); |
287 | err = -ENODEV; | 283 | return -ENODEV; |
288 | goto error1; | ||
289 | } | 284 | } |
290 | } | 285 | } |
291 | 286 | ||
@@ -336,24 +331,36 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
336 | type_name = "mc1066"; | 331 | type_name = "mc1066"; |
337 | } | 332 | } |
338 | pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n", | 333 | pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n", |
339 | type_name, i2c_adapter_id(adapter), address); | 334 | type_name, i2c_adapter_id(adapter), client->addr); |
335 | strlcpy(info->type, type_name, I2C_NAME_SIZE); | ||
340 | 336 | ||
341 | /* Fill in the remaining client fields */ | 337 | return 0; |
342 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | 338 | } |
343 | data->type = kind; | ||
344 | mutex_init(&data->update_lock); | ||
345 | 339 | ||
346 | /* Tell the I2C layer a new client has arrived */ | 340 | static int adm1021_probe(struct i2c_client *client, |
347 | if ((err = i2c_attach_client(client))) | 341 | const struct i2c_device_id *id) |
348 | goto error1; | 342 | { |
343 | struct adm1021_data *data; | ||
344 | int err; | ||
345 | |||
346 | data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL); | ||
347 | if (!data) { | ||
348 | pr_debug("adm1021: detect failed, kzalloc failed!\n"); | ||
349 | err = -ENOMEM; | ||
350 | goto error0; | ||
351 | } | ||
352 | |||
353 | i2c_set_clientdata(client, data); | ||
354 | data->type = id->driver_data; | ||
355 | mutex_init(&data->update_lock); | ||
349 | 356 | ||
350 | /* Initialize the ADM1021 chip */ | 357 | /* Initialize the ADM1021 chip */ |
351 | if (kind != lm84 && !read_only) | 358 | if (data->type != lm84 && !read_only) |
352 | adm1021_init_client(client); | 359 | adm1021_init_client(client); |
353 | 360 | ||
354 | /* Register sysfs hooks */ | 361 | /* Register sysfs hooks */ |
355 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1021_group))) | 362 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1021_group))) |
356 | goto error2; | 363 | goto error1; |
357 | 364 | ||
358 | data->hwmon_dev = hwmon_device_register(&client->dev); | 365 | data->hwmon_dev = hwmon_device_register(&client->dev); |
359 | if (IS_ERR(data->hwmon_dev)) { | 366 | if (IS_ERR(data->hwmon_dev)) { |
@@ -365,8 +372,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
365 | 372 | ||
366 | error3: | 373 | error3: |
367 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | 374 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); |
368 | error2: | ||
369 | i2c_detach_client(client); | ||
370 | error1: | 375 | error1: |
371 | kfree(data); | 376 | kfree(data); |
372 | error0: | 377 | error0: |
@@ -382,17 +387,13 @@ static void adm1021_init_client(struct i2c_client *client) | |||
382 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); | 387 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); |
383 | } | 388 | } |
384 | 389 | ||
385 | static int adm1021_detach_client(struct i2c_client *client) | 390 | static int adm1021_remove(struct i2c_client *client) |
386 | { | 391 | { |
387 | struct adm1021_data *data = i2c_get_clientdata(client); | 392 | struct adm1021_data *data = i2c_get_clientdata(client); |
388 | int err; | ||
389 | 393 | ||
390 | hwmon_device_unregister(data->hwmon_dev); | 394 | hwmon_device_unregister(data->hwmon_dev); |
391 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | 395 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); |
392 | 396 | ||
393 | if ((err = i2c_detach_client(client))) | ||
394 | return err; | ||
395 | |||
396 | kfree(data); | 397 | kfree(data); |
397 | return 0; | 398 | return 0; |
398 | } | 399 | } |
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index 1d76de7d75c7..4db04d603ec9 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * adm1025.c | 2 | * adm1025.c |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> | 4 | * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> |
5 | * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> | 5 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> |
6 | * | 6 | * |
7 | * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 | 7 | * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 |
8 | * voltages (including its own power source) and up to two temperatures | 8 | * voltages (including its own power source) and up to two temperatures |
@@ -109,22 +109,35 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; | |||
109 | * Functions declaration | 109 | * Functions declaration |
110 | */ | 110 | */ |
111 | 111 | ||
112 | static int adm1025_attach_adapter(struct i2c_adapter *adapter); | 112 | static int adm1025_probe(struct i2c_client *client, |
113 | static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind); | 113 | const struct i2c_device_id *id); |
114 | static int adm1025_detect(struct i2c_client *client, int kind, | ||
115 | struct i2c_board_info *info); | ||
114 | static void adm1025_init_client(struct i2c_client *client); | 116 | static void adm1025_init_client(struct i2c_client *client); |
115 | static int adm1025_detach_client(struct i2c_client *client); | 117 | static int adm1025_remove(struct i2c_client *client); |
116 | static struct adm1025_data *adm1025_update_device(struct device *dev); | 118 | static struct adm1025_data *adm1025_update_device(struct device *dev); |
117 | 119 | ||
118 | /* | 120 | /* |
119 | * Driver data (common to all clients) | 121 | * Driver data (common to all clients) |
120 | */ | 122 | */ |
121 | 123 | ||
124 | static const struct i2c_device_id adm1025_id[] = { | ||
125 | { "adm1025", adm1025 }, | ||
126 | { "ne1619", ne1619 }, | ||
127 | { } | ||
128 | }; | ||
129 | MODULE_DEVICE_TABLE(i2c, adm1025_id); | ||
130 | |||
122 | static struct i2c_driver adm1025_driver = { | 131 | static struct i2c_driver adm1025_driver = { |
132 | .class = I2C_CLASS_HWMON, | ||
123 | .driver = { | 133 | .driver = { |
124 | .name = "adm1025", | 134 | .name = "adm1025", |
125 | }, | 135 | }, |
126 | .attach_adapter = adm1025_attach_adapter, | 136 | .probe = adm1025_probe, |
127 | .detach_client = adm1025_detach_client, | 137 | .remove = adm1025_remove, |
138 | .id_table = adm1025_id, | ||
139 | .detect = adm1025_detect, | ||
140 | .address_data = &addr_data, | ||
128 | }; | 141 | }; |
129 | 142 | ||
130 | /* | 143 | /* |
@@ -132,7 +145,6 @@ static struct i2c_driver adm1025_driver = { | |||
132 | */ | 145 | */ |
133 | 146 | ||
134 | struct adm1025_data { | 147 | struct adm1025_data { |
135 | struct i2c_client client; | ||
136 | struct device *hwmon_dev; | 148 | struct device *hwmon_dev; |
137 | struct mutex update_lock; | 149 | struct mutex update_lock; |
138 | char valid; /* zero until following fields are valid */ | 150 | char valid; /* zero until following fields are valid */ |
@@ -344,13 +356,6 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); | |||
344 | * Real code | 356 | * Real code |
345 | */ | 357 | */ |
346 | 358 | ||
347 | static int adm1025_attach_adapter(struct i2c_adapter *adapter) | ||
348 | { | ||
349 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
350 | return 0; | ||
351 | return i2c_probe(adapter, &addr_data, adm1025_detect); | ||
352 | } | ||
353 | |||
354 | static struct attribute *adm1025_attributes[] = { | 359 | static struct attribute *adm1025_attributes[] = { |
355 | &sensor_dev_attr_in0_input.dev_attr.attr, | 360 | &sensor_dev_attr_in0_input.dev_attr.attr, |
356 | &sensor_dev_attr_in1_input.dev_attr.attr, | 361 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -403,31 +408,16 @@ static const struct attribute_group adm1025_group_in4 = { | |||
403 | .attrs = adm1025_attributes_in4, | 408 | .attrs = adm1025_attributes_in4, |
404 | }; | 409 | }; |
405 | 410 | ||
406 | /* | 411 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
407 | * The following function does more than just detection. If detection | 412 | static int adm1025_detect(struct i2c_client *client, int kind, |
408 | * succeeds, it also registers the new chip. | 413 | struct i2c_board_info *info) |
409 | */ | ||
410 | static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | ||
411 | { | 414 | { |
412 | struct i2c_client *client; | 415 | struct i2c_adapter *adapter = client->adapter; |
413 | struct adm1025_data *data; | ||
414 | int err = 0; | ||
415 | const char *name = ""; | 416 | const char *name = ""; |
416 | u8 config; | 417 | u8 config; |
417 | 418 | ||
418 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 419 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
419 | goto exit; | 420 | return -ENODEV; |
420 | |||
421 | if (!(data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL))) { | ||
422 | err = -ENOMEM; | ||
423 | goto exit; | ||
424 | } | ||
425 | |||
426 | client = &data->client; | ||
427 | i2c_set_clientdata(client, data); | ||
428 | client->addr = address; | ||
429 | client->adapter = adapter; | ||
430 | client->driver = &adm1025_driver; | ||
431 | 421 | ||
432 | /* | 422 | /* |
433 | * Now we do the remaining detection. A negative kind means that | 423 | * Now we do the remaining detection. A negative kind means that |
@@ -448,8 +438,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
448 | ADM1025_REG_STATUS2) & 0xBC) != 0x00) { | 438 | ADM1025_REG_STATUS2) & 0xBC) != 0x00) { |
449 | dev_dbg(&adapter->dev, | 439 | dev_dbg(&adapter->dev, |
450 | "ADM1025 detection failed at 0x%02x.\n", | 440 | "ADM1025 detection failed at 0x%02x.\n", |
451 | address); | 441 | client->addr); |
452 | goto exit_free; | 442 | return -ENODEV; |
453 | } | 443 | } |
454 | } | 444 | } |
455 | 445 | ||
@@ -465,7 +455,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
465 | } | 455 | } |
466 | } else | 456 | } else |
467 | if (man_id == 0xA1) { /* Philips */ | 457 | if (man_id == 0xA1) { /* Philips */ |
468 | if (address != 0x2E | 458 | if (client->addr != 0x2E |
469 | && (chip_id & 0xF0) == 0x20) { /* NE1619 */ | 459 | && (chip_id & 0xF0) == 0x20) { /* NE1619 */ |
470 | kind = ne1619; | 460 | kind = ne1619; |
471 | } | 461 | } |
@@ -475,7 +465,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
475 | dev_info(&adapter->dev, | 465 | dev_info(&adapter->dev, |
476 | "Unsupported chip (man_id=0x%02X, " | 466 | "Unsupported chip (man_id=0x%02X, " |
477 | "chip_id=0x%02X).\n", man_id, chip_id); | 467 | "chip_id=0x%02X).\n", man_id, chip_id); |
478 | goto exit_free; | 468 | return -ENODEV; |
479 | } | 469 | } |
480 | } | 470 | } |
481 | 471 | ||
@@ -484,23 +474,36 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
484 | } else if (kind == ne1619) { | 474 | } else if (kind == ne1619) { |
485 | name = "ne1619"; | 475 | name = "ne1619"; |
486 | } | 476 | } |
477 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
487 | 478 | ||
488 | /* We can fill in the remaining client fields */ | 479 | return 0; |
489 | strlcpy(client->name, name, I2C_NAME_SIZE); | 480 | } |
490 | mutex_init(&data->update_lock); | ||
491 | 481 | ||
492 | /* Tell the I2C layer a new client has arrived */ | 482 | static int adm1025_probe(struct i2c_client *client, |
493 | if ((err = i2c_attach_client(client))) | 483 | const struct i2c_device_id *id) |
494 | goto exit_free; | 484 | { |
485 | struct adm1025_data *data; | ||
486 | int err; | ||
487 | u8 config; | ||
488 | |||
489 | data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL); | ||
490 | if (!data) { | ||
491 | err = -ENOMEM; | ||
492 | goto exit; | ||
493 | } | ||
494 | |||
495 | i2c_set_clientdata(client, data); | ||
496 | mutex_init(&data->update_lock); | ||
495 | 497 | ||
496 | /* Initialize the ADM1025 chip */ | 498 | /* Initialize the ADM1025 chip */ |
497 | adm1025_init_client(client); | 499 | adm1025_init_client(client); |
498 | 500 | ||
499 | /* Register sysfs hooks */ | 501 | /* Register sysfs hooks */ |
500 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group))) | 502 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group))) |
501 | goto exit_detach; | 503 | goto exit_free; |
502 | 504 | ||
503 | /* Pin 11 is either in4 (+12V) or VID4 */ | 505 | /* Pin 11 is either in4 (+12V) or VID4 */ |
506 | config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); | ||
504 | if (!(config & 0x20)) { | 507 | if (!(config & 0x20)) { |
505 | if ((err = sysfs_create_group(&client->dev.kobj, | 508 | if ((err = sysfs_create_group(&client->dev.kobj, |
506 | &adm1025_group_in4))) | 509 | &adm1025_group_in4))) |
@@ -518,8 +521,6 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
518 | exit_remove: | 521 | exit_remove: |
519 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | 522 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); |
520 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | 523 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); |
521 | exit_detach: | ||
522 | i2c_detach_client(client); | ||
523 | exit_free: | 524 | exit_free: |
524 | kfree(data); | 525 | kfree(data); |
525 | exit: | 526 | exit: |
@@ -568,18 +569,14 @@ static void adm1025_init_client(struct i2c_client *client) | |||
568 | (reg&0x7E)|0x01); | 569 | (reg&0x7E)|0x01); |
569 | } | 570 | } |
570 | 571 | ||
571 | static int adm1025_detach_client(struct i2c_client *client) | 572 | static int adm1025_remove(struct i2c_client *client) |
572 | { | 573 | { |
573 | struct adm1025_data *data = i2c_get_clientdata(client); | 574 | struct adm1025_data *data = i2c_get_clientdata(client); |
574 | int err; | ||
575 | 575 | ||
576 | hwmon_device_unregister(data->hwmon_dev); | 576 | hwmon_device_unregister(data->hwmon_dev); |
577 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | 577 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); |
578 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | 578 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); |
579 | 579 | ||
580 | if ((err = i2c_detach_client(client))) | ||
581 | return err; | ||
582 | |||
583 | kfree(data); | 580 | kfree(data); |
584 | return 0; | 581 | return 0; |
585 | } | 582 | } |
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index 904c6ce9d83f..7fe2441fc845 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -259,7 +259,6 @@ struct pwm_data { | |||
259 | }; | 259 | }; |
260 | 260 | ||
261 | struct adm1026_data { | 261 | struct adm1026_data { |
262 | struct i2c_client client; | ||
263 | struct device *hwmon_dev; | 262 | struct device *hwmon_dev; |
264 | 263 | ||
265 | struct mutex update_lock; | 264 | struct mutex update_lock; |
@@ -293,10 +292,11 @@ struct adm1026_data { | |||
293 | u8 config3; /* Register value */ | 292 | u8 config3; /* Register value */ |
294 | }; | 293 | }; |
295 | 294 | ||
296 | static int adm1026_attach_adapter(struct i2c_adapter *adapter); | 295 | static int adm1026_probe(struct i2c_client *client, |
297 | static int adm1026_detect(struct i2c_adapter *adapter, int address, | 296 | const struct i2c_device_id *id); |
298 | int kind); | 297 | static int adm1026_detect(struct i2c_client *client, int kind, |
299 | static int adm1026_detach_client(struct i2c_client *client); | 298 | struct i2c_board_info *info); |
299 | static int adm1026_remove(struct i2c_client *client); | ||
300 | static int adm1026_read_value(struct i2c_client *client, u8 reg); | 300 | static int adm1026_read_value(struct i2c_client *client, u8 reg); |
301 | static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); | 301 | static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); |
302 | static void adm1026_print_gpio(struct i2c_client *client); | 302 | static void adm1026_print_gpio(struct i2c_client *client); |
@@ -305,22 +305,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev); | |||
305 | static void adm1026_init_client(struct i2c_client *client); | 305 | static void adm1026_init_client(struct i2c_client *client); |
306 | 306 | ||
307 | 307 | ||
308 | static const struct i2c_device_id adm1026_id[] = { | ||
309 | { "adm1026", adm1026 }, | ||
310 | { } | ||
311 | }; | ||
312 | MODULE_DEVICE_TABLE(i2c, adm1026_id); | ||
313 | |||
308 | static struct i2c_driver adm1026_driver = { | 314 | static struct i2c_driver adm1026_driver = { |
315 | .class = I2C_CLASS_HWMON, | ||
309 | .driver = { | 316 | .driver = { |
310 | .name = "adm1026", | 317 | .name = "adm1026", |
311 | }, | 318 | }, |
312 | .attach_adapter = adm1026_attach_adapter, | 319 | .probe = adm1026_probe, |
313 | .detach_client = adm1026_detach_client, | 320 | .remove = adm1026_remove, |
321 | .id_table = adm1026_id, | ||
322 | .detect = adm1026_detect, | ||
323 | .address_data = &addr_data, | ||
314 | }; | 324 | }; |
315 | 325 | ||
316 | static int adm1026_attach_adapter(struct i2c_adapter *adapter) | ||
317 | { | ||
318 | if (!(adapter->class & I2C_CLASS_HWMON)) { | ||
319 | return 0; | ||
320 | } | ||
321 | return i2c_probe(adapter, &addr_data, adm1026_detect); | ||
322 | } | ||
323 | |||
324 | static int adm1026_read_value(struct i2c_client *client, u8 reg) | 326 | static int adm1026_read_value(struct i2c_client *client, u8 reg) |
325 | { | 327 | { |
326 | int res; | 328 | int res; |
@@ -1647,48 +1649,32 @@ static const struct attribute_group adm1026_group_in8_9 = { | |||
1647 | .attrs = adm1026_attributes_in8_9, | 1649 | .attrs = adm1026_attributes_in8_9, |
1648 | }; | 1650 | }; |
1649 | 1651 | ||
1650 | static int adm1026_detect(struct i2c_adapter *adapter, int address, | 1652 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1651 | int kind) | 1653 | static int adm1026_detect(struct i2c_client *client, int kind, |
1654 | struct i2c_board_info *info) | ||
1652 | { | 1655 | { |
1656 | struct i2c_adapter *adapter = client->adapter; | ||
1657 | int address = client->addr; | ||
1653 | int company, verstep; | 1658 | int company, verstep; |
1654 | struct i2c_client *client; | ||
1655 | struct adm1026_data *data; | ||
1656 | int err = 0; | ||
1657 | const char *type_name = ""; | ||
1658 | 1659 | ||
1659 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1660 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1660 | /* We need to be able to do byte I/O */ | 1661 | /* We need to be able to do byte I/O */ |
1661 | goto exit; | 1662 | return -ENODEV; |
1662 | }; | 1663 | }; |
1663 | 1664 | ||
1664 | /* OK. For now, we presume we have a valid client. We now create the | ||
1665 | client structure, even though we cannot fill it completely yet. | ||
1666 | But it allows us to access adm1026_{read,write}_value. */ | ||
1667 | |||
1668 | if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) { | ||
1669 | err = -ENOMEM; | ||
1670 | goto exit; | ||
1671 | } | ||
1672 | |||
1673 | client = &data->client; | ||
1674 | i2c_set_clientdata(client, data); | ||
1675 | client->addr = address; | ||
1676 | client->adapter = adapter; | ||
1677 | client->driver = &adm1026_driver; | ||
1678 | |||
1679 | /* Now, we do the remaining detection. */ | 1665 | /* Now, we do the remaining detection. */ |
1680 | 1666 | ||
1681 | company = adm1026_read_value(client, ADM1026_REG_COMPANY); | 1667 | company = adm1026_read_value(client, ADM1026_REG_COMPANY); |
1682 | verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP); | 1668 | verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP); |
1683 | 1669 | ||
1684 | dev_dbg(&client->dev, "Detecting device at %d,0x%02x with" | 1670 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" |
1685 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", | 1671 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
1686 | i2c_adapter_id(client->adapter), client->addr, | 1672 | i2c_adapter_id(client->adapter), client->addr, |
1687 | company, verstep); | 1673 | company, verstep); |
1688 | 1674 | ||
1689 | /* If auto-detecting, Determine the chip type. */ | 1675 | /* If auto-detecting, Determine the chip type. */ |
1690 | if (kind <= 0) { | 1676 | if (kind <= 0) { |
1691 | dev_dbg(&client->dev, "Autodetecting device at %d,0x%02x " | 1677 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x " |
1692 | "...\n", i2c_adapter_id(adapter), address); | 1678 | "...\n", i2c_adapter_id(adapter), address); |
1693 | if (company == ADM1026_COMPANY_ANALOG_DEV | 1679 | if (company == ADM1026_COMPANY_ANALOG_DEV |
1694 | && verstep == ADM1026_VERSTEP_ADM1026) { | 1680 | && verstep == ADM1026_VERSTEP_ADM1026) { |
@@ -1704,7 +1690,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1704 | verstep); | 1690 | verstep); |
1705 | kind = any_chip; | 1691 | kind = any_chip; |
1706 | } else { | 1692 | } else { |
1707 | dev_dbg(&client->dev, ": Autodetection " | 1693 | dev_dbg(&adapter->dev, ": Autodetection " |
1708 | "failed\n"); | 1694 | "failed\n"); |
1709 | /* Not an ADM1026 ... */ | 1695 | /* Not an ADM1026 ... */ |
1710 | if (kind == 0) { /* User used force=x,y */ | 1696 | if (kind == 0) { /* User used force=x,y */ |
@@ -1713,33 +1699,29 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1713 | "force_adm1026.\n", | 1699 | "force_adm1026.\n", |
1714 | i2c_adapter_id(adapter), address); | 1700 | i2c_adapter_id(adapter), address); |
1715 | } | 1701 | } |
1716 | goto exitfree; | 1702 | return -ENODEV; |
1717 | } | 1703 | } |
1718 | } | 1704 | } |
1705 | strlcpy(info->type, "adm1026", I2C_NAME_SIZE); | ||
1719 | 1706 | ||
1720 | /* Fill in the chip specific driver values */ | 1707 | return 0; |
1721 | switch (kind) { | 1708 | } |
1722 | case any_chip : | 1709 | |
1723 | type_name = "adm1026"; | 1710 | static int adm1026_probe(struct i2c_client *client, |
1724 | break; | 1711 | const struct i2c_device_id *id) |
1725 | case adm1026 : | 1712 | { |
1726 | type_name = "adm1026"; | 1713 | struct adm1026_data *data; |
1727 | break; | 1714 | int err; |
1728 | default : | 1715 | |
1729 | dev_err(&adapter->dev, ": Internal error, invalid " | 1716 | data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL); |
1730 | "kind (%d)!\n", kind); | 1717 | if (!data) { |
1731 | err = -EFAULT; | 1718 | err = -ENOMEM; |
1732 | goto exitfree; | 1719 | goto exit; |
1733 | } | 1720 | } |
1734 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | ||
1735 | 1721 | ||
1736 | /* Fill in the remaining client fields */ | 1722 | i2c_set_clientdata(client, data); |
1737 | mutex_init(&data->update_lock); | 1723 | mutex_init(&data->update_lock); |
1738 | 1724 | ||
1739 | /* Tell the I2C layer a new client has arrived */ | ||
1740 | if ((err = i2c_attach_client(client))) | ||
1741 | goto exitfree; | ||
1742 | |||
1743 | /* Set the VRM version */ | 1725 | /* Set the VRM version */ |
1744 | data->vrm = vid_which_vrm(); | 1726 | data->vrm = vid_which_vrm(); |
1745 | 1727 | ||
@@ -1748,7 +1730,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1748 | 1730 | ||
1749 | /* Register sysfs hooks */ | 1731 | /* Register sysfs hooks */ |
1750 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) | 1732 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) |
1751 | goto exitdetach; | 1733 | goto exitfree; |
1752 | if (data->config1 & CFG1_AIN8_9) | 1734 | if (data->config1 & CFG1_AIN8_9) |
1753 | err = sysfs_create_group(&client->dev.kobj, | 1735 | err = sysfs_create_group(&client->dev.kobj, |
1754 | &adm1026_group_in8_9); | 1736 | &adm1026_group_in8_9); |
@@ -1773,15 +1755,13 @@ exitremove: | |||
1773 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | 1755 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); |
1774 | else | 1756 | else |
1775 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | 1757 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); |
1776 | exitdetach: | ||
1777 | i2c_detach_client(client); | ||
1778 | exitfree: | 1758 | exitfree: |
1779 | kfree(data); | 1759 | kfree(data); |
1780 | exit: | 1760 | exit: |
1781 | return err; | 1761 | return err; |
1782 | } | 1762 | } |
1783 | 1763 | ||
1784 | static int adm1026_detach_client(struct i2c_client *client) | 1764 | static int adm1026_remove(struct i2c_client *client) |
1785 | { | 1765 | { |
1786 | struct adm1026_data *data = i2c_get_clientdata(client); | 1766 | struct adm1026_data *data = i2c_get_clientdata(client); |
1787 | hwmon_device_unregister(data->hwmon_dev); | 1767 | hwmon_device_unregister(data->hwmon_dev); |
@@ -1790,7 +1770,6 @@ static int adm1026_detach_client(struct i2c_client *client) | |||
1790 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | 1770 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); |
1791 | else | 1771 | else |
1792 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | 1772 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); |
1793 | i2c_detach_client(client); | ||
1794 | kfree(data); | 1773 | kfree(data); |
1795 | return 0; | 1774 | return 0; |
1796 | } | 1775 | } |
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 2c6608d453c2..ba84ca5923f9 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c | |||
@@ -115,9 +115,11 @@ static const u8 ADM1029_REG_FAN_DIV[] = { | |||
115 | * Functions declaration | 115 | * Functions declaration |
116 | */ | 116 | */ |
117 | 117 | ||
118 | static int adm1029_attach_adapter(struct i2c_adapter *adapter); | 118 | static int adm1029_probe(struct i2c_client *client, |
119 | static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind); | 119 | const struct i2c_device_id *id); |
120 | static int adm1029_detach_client(struct i2c_client *client); | 120 | static int adm1029_detect(struct i2c_client *client, int kind, |
121 | struct i2c_board_info *info); | ||
122 | static int adm1029_remove(struct i2c_client *client); | ||
121 | static struct adm1029_data *adm1029_update_device(struct device *dev); | 123 | static struct adm1029_data *adm1029_update_device(struct device *dev); |
122 | static int adm1029_init_client(struct i2c_client *client); | 124 | static int adm1029_init_client(struct i2c_client *client); |
123 | 125 | ||
@@ -125,12 +127,22 @@ static int adm1029_init_client(struct i2c_client *client); | |||
125 | * Driver data (common to all clients) | 127 | * Driver data (common to all clients) |
126 | */ | 128 | */ |
127 | 129 | ||
130 | static const struct i2c_device_id adm1029_id[] = { | ||
131 | { "adm1029", adm1029 }, | ||
132 | { } | ||
133 | }; | ||
134 | MODULE_DEVICE_TABLE(i2c, adm1029_id); | ||
135 | |||
128 | static struct i2c_driver adm1029_driver = { | 136 | static struct i2c_driver adm1029_driver = { |
137 | .class = I2C_CLASS_HWMON, | ||
129 | .driver = { | 138 | .driver = { |
130 | .name = "adm1029", | 139 | .name = "adm1029", |
131 | }, | 140 | }, |
132 | .attach_adapter = adm1029_attach_adapter, | 141 | .probe = adm1029_probe, |
133 | .detach_client = adm1029_detach_client, | 142 | .remove = adm1029_remove, |
143 | .id_table = adm1029_id, | ||
144 | .detect = adm1029_detect, | ||
145 | .address_data = &addr_data, | ||
134 | }; | 146 | }; |
135 | 147 | ||
136 | /* | 148 | /* |
@@ -138,7 +150,6 @@ static struct i2c_driver adm1029_driver = { | |||
138 | */ | 150 | */ |
139 | 151 | ||
140 | struct adm1029_data { | 152 | struct adm1029_data { |
141 | struct i2c_client client; | ||
142 | struct device *hwmon_dev; | 153 | struct device *hwmon_dev; |
143 | struct mutex update_lock; | 154 | struct mutex update_lock; |
144 | char valid; /* zero until following fields are valid */ | 155 | char valid; /* zero until following fields are valid */ |
@@ -284,37 +295,14 @@ static const struct attribute_group adm1029_group = { | |||
284 | * Real code | 295 | * Real code |
285 | */ | 296 | */ |
286 | 297 | ||
287 | static int adm1029_attach_adapter(struct i2c_adapter *adapter) | 298 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
299 | static int adm1029_detect(struct i2c_client *client, int kind, | ||
300 | struct i2c_board_info *info) | ||
288 | { | 301 | { |
289 | if (!(adapter->class & I2C_CLASS_HWMON)) | 302 | struct i2c_adapter *adapter = client->adapter; |
290 | return 0; | ||
291 | return i2c_probe(adapter, &addr_data, adm1029_detect); | ||
292 | } | ||
293 | 303 | ||
294 | /* | ||
295 | * The following function does more than just detection. If detection | ||
296 | * succeeds, it also registers the new chip. | ||
297 | */ | ||
298 | |||
299 | static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | ||
300 | { | ||
301 | struct i2c_client *client; | ||
302 | struct adm1029_data *data; | ||
303 | int err = 0; | ||
304 | const char *name = ""; | ||
305 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 304 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
306 | goto exit; | 305 | return -ENODEV; |
307 | |||
308 | if (!(data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL))) { | ||
309 | err = -ENOMEM; | ||
310 | goto exit; | ||
311 | } | ||
312 | |||
313 | client = &data->client; | ||
314 | i2c_set_clientdata(client, data); | ||
315 | client->addr = address; | ||
316 | client->adapter = adapter; | ||
317 | client->driver = &adm1029_driver; | ||
318 | 306 | ||
319 | /* Now we do the detection and identification. A negative kind | 307 | /* Now we do the detection and identification. A negative kind |
320 | * means that the driver was loaded with no force parameter | 308 | * means that the driver was loaded with no force parameter |
@@ -362,32 +350,41 @@ static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | |||
362 | if (kind <= 0) { /* identification failed */ | 350 | if (kind <= 0) { /* identification failed */ |
363 | pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " | 351 | pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " |
364 | "chip_id=0x%02X)\n", man_id, chip_id); | 352 | "chip_id=0x%02X)\n", man_id, chip_id); |
365 | goto exit_free; | 353 | return -ENODEV; |
366 | } | 354 | } |
367 | } | 355 | } |
356 | strlcpy(info->type, "adm1029", I2C_NAME_SIZE); | ||
368 | 357 | ||
369 | if (kind == adm1029) { | 358 | return 0; |
370 | name = "adm1029"; | 359 | } |
360 | |||
361 | static int adm1029_probe(struct i2c_client *client, | ||
362 | const struct i2c_device_id *id) | ||
363 | { | ||
364 | struct adm1029_data *data; | ||
365 | int err; | ||
366 | |||
367 | data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL); | ||
368 | if (!data) { | ||
369 | err = -ENOMEM; | ||
370 | goto exit; | ||
371 | } | 371 | } |
372 | 372 | ||
373 | /* We can fill in the remaining client fields */ | 373 | i2c_set_clientdata(client, data); |
374 | strlcpy(client->name, name, I2C_NAME_SIZE); | ||
375 | mutex_init(&data->update_lock); | 374 | mutex_init(&data->update_lock); |
376 | 375 | ||
377 | /* Tell the I2C layer a new client has arrived */ | ||
378 | if ((err = i2c_attach_client(client))) | ||
379 | goto exit_free; | ||
380 | |||
381 | /* | 376 | /* |
382 | * Initialize the ADM1029 chip | 377 | * Initialize the ADM1029 chip |
383 | * Check config register | 378 | * Check config register |
384 | */ | 379 | */ |
385 | if (adm1029_init_client(client) == 0) | 380 | if (adm1029_init_client(client) == 0) { |
386 | goto exit_detach; | 381 | err = -ENODEV; |
382 | goto exit_free; | ||
383 | } | ||
387 | 384 | ||
388 | /* Register sysfs hooks */ | 385 | /* Register sysfs hooks */ |
389 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) | 386 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) |
390 | goto exit_detach; | 387 | goto exit_free; |
391 | 388 | ||
392 | data->hwmon_dev = hwmon_device_register(&client->dev); | 389 | data->hwmon_dev = hwmon_device_register(&client->dev); |
393 | if (IS_ERR(data->hwmon_dev)) { | 390 | if (IS_ERR(data->hwmon_dev)) { |
@@ -399,8 +396,6 @@ static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) | |||
399 | 396 | ||
400 | exit_remove_files: | 397 | exit_remove_files: |
401 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | 398 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); |
402 | exit_detach: | ||
403 | i2c_detach_client(client); | ||
404 | exit_free: | 399 | exit_free: |
405 | kfree(data); | 400 | kfree(data); |
406 | exit: | 401 | exit: |
@@ -424,17 +419,13 @@ static int adm1029_init_client(struct i2c_client *client) | |||
424 | return 1; | 419 | return 1; |
425 | } | 420 | } |
426 | 421 | ||
427 | static int adm1029_detach_client(struct i2c_client *client) | 422 | static int adm1029_remove(struct i2c_client *client) |
428 | { | 423 | { |
429 | struct adm1029_data *data = i2c_get_clientdata(client); | 424 | struct adm1029_data *data = i2c_get_clientdata(client); |
430 | int err; | ||
431 | 425 | ||
432 | hwmon_device_unregister(data->hwmon_dev); | 426 | hwmon_device_unregister(data->hwmon_dev); |
433 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | 427 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); |
434 | 428 | ||
435 | if ((err = i2c_detach_client(client))) | ||
436 | return err; | ||
437 | |||
438 | kfree(data); | 429 | kfree(data); |
439 | return 0; | 430 | return 0; |
440 | } | 431 | } |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 2bffcab7dc9f..789441830cd8 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -70,7 +70,6 @@ typedef u8 auto_chan_table_t[8][2]; | |||
70 | 70 | ||
71 | /* Each client has this additional data */ | 71 | /* Each client has this additional data */ |
72 | struct adm1031_data { | 72 | struct adm1031_data { |
73 | struct i2c_client client; | ||
74 | struct device *hwmon_dev; | 73 | struct device *hwmon_dev; |
75 | struct mutex update_lock; | 74 | struct mutex update_lock; |
76 | int chip_type; | 75 | int chip_type; |
@@ -99,19 +98,32 @@ struct adm1031_data { | |||
99 | s8 temp_crit[3]; | 98 | s8 temp_crit[3]; |
100 | }; | 99 | }; |
101 | 100 | ||
102 | static int adm1031_attach_adapter(struct i2c_adapter *adapter); | 101 | static int adm1031_probe(struct i2c_client *client, |
103 | static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind); | 102 | const struct i2c_device_id *id); |
103 | static int adm1031_detect(struct i2c_client *client, int kind, | ||
104 | struct i2c_board_info *info); | ||
104 | static void adm1031_init_client(struct i2c_client *client); | 105 | static void adm1031_init_client(struct i2c_client *client); |
105 | static int adm1031_detach_client(struct i2c_client *client); | 106 | static int adm1031_remove(struct i2c_client *client); |
106 | static struct adm1031_data *adm1031_update_device(struct device *dev); | 107 | static struct adm1031_data *adm1031_update_device(struct device *dev); |
107 | 108 | ||
109 | static const struct i2c_device_id adm1031_id[] = { | ||
110 | { "adm1030", adm1030 }, | ||
111 | { "adm1031", adm1031 }, | ||
112 | { } | ||
113 | }; | ||
114 | MODULE_DEVICE_TABLE(i2c, adm1031_id); | ||
115 | |||
108 | /* This is the driver that will be inserted */ | 116 | /* This is the driver that will be inserted */ |
109 | static struct i2c_driver adm1031_driver = { | 117 | static struct i2c_driver adm1031_driver = { |
118 | .class = I2C_CLASS_HWMON, | ||
110 | .driver = { | 119 | .driver = { |
111 | .name = "adm1031", | 120 | .name = "adm1031", |
112 | }, | 121 | }, |
113 | .attach_adapter = adm1031_attach_adapter, | 122 | .probe = adm1031_probe, |
114 | .detach_client = adm1031_detach_client, | 123 | .remove = adm1031_remove, |
124 | .id_table = adm1031_id, | ||
125 | .detect = adm1031_detect, | ||
126 | .address_data = &addr_data, | ||
115 | }; | 127 | }; |
116 | 128 | ||
117 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) | 129 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) |
@@ -693,13 +705,6 @@ static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12); | |||
693 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); | 705 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); |
694 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); | 706 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); |
695 | 707 | ||
696 | static int adm1031_attach_adapter(struct i2c_adapter *adapter) | ||
697 | { | ||
698 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
699 | return 0; | ||
700 | return i2c_probe(adapter, &addr_data, adm1031_detect); | ||
701 | } | ||
702 | |||
703 | static struct attribute *adm1031_attributes[] = { | 708 | static struct attribute *adm1031_attributes[] = { |
704 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 709 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
705 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 710 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
@@ -770,27 +775,15 @@ static const struct attribute_group adm1031_group_opt = { | |||
770 | .attrs = adm1031_attributes_opt, | 775 | .attrs = adm1031_attributes_opt, |
771 | }; | 776 | }; |
772 | 777 | ||
773 | /* This function is called by i2c_probe */ | 778 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
774 | static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | 779 | static int adm1031_detect(struct i2c_client *client, int kind, |
780 | struct i2c_board_info *info) | ||
775 | { | 781 | { |
776 | struct i2c_client *client; | 782 | struct i2c_adapter *adapter = client->adapter; |
777 | struct adm1031_data *data; | ||
778 | int err = 0; | ||
779 | const char *name = ""; | 783 | const char *name = ""; |
780 | 784 | ||
781 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 785 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
782 | goto exit; | 786 | return -ENODEV; |
783 | |||
784 | if (!(data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL))) { | ||
785 | err = -ENOMEM; | ||
786 | goto exit; | ||
787 | } | ||
788 | |||
789 | client = &data->client; | ||
790 | i2c_set_clientdata(client, data); | ||
791 | client->addr = address; | ||
792 | client->adapter = adapter; | ||
793 | client->driver = &adm1031_driver; | ||
794 | 787 | ||
795 | if (kind < 0) { | 788 | if (kind < 0) { |
796 | int id, co; | 789 | int id, co; |
@@ -798,7 +791,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
798 | co = i2c_smbus_read_byte_data(client, 0x3e); | 791 | co = i2c_smbus_read_byte_data(client, 0x3e); |
799 | 792 | ||
800 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) | 793 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) |
801 | goto exit_free; | 794 | return -ENODEV; |
802 | kind = (id == 0x30) ? adm1030 : adm1031; | 795 | kind = (id == 0x30) ? adm1030 : adm1031; |
803 | } | 796 | } |
804 | 797 | ||
@@ -809,28 +802,43 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
809 | * auto fan control helper table. */ | 802 | * auto fan control helper table. */ |
810 | if (kind == adm1030) { | 803 | if (kind == adm1030) { |
811 | name = "adm1030"; | 804 | name = "adm1030"; |
812 | data->chan_select_table = &auto_channel_select_table_adm1030; | ||
813 | } else if (kind == adm1031) { | 805 | } else if (kind == adm1031) { |
814 | name = "adm1031"; | 806 | name = "adm1031"; |
815 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
816 | } | 807 | } |
817 | data->chip_type = kind; | 808 | strlcpy(info->type, name, I2C_NAME_SIZE); |
818 | 809 | ||
819 | strlcpy(client->name, name, I2C_NAME_SIZE); | 810 | return 0; |
811 | } | ||
812 | |||
813 | static int adm1031_probe(struct i2c_client *client, | ||
814 | const struct i2c_device_id *id) | ||
815 | { | ||
816 | struct adm1031_data *data; | ||
817 | int err; | ||
818 | |||
819 | data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL); | ||
820 | if (!data) { | ||
821 | err = -ENOMEM; | ||
822 | goto exit; | ||
823 | } | ||
824 | |||
825 | i2c_set_clientdata(client, data); | ||
826 | data->chip_type = id->driver_data; | ||
820 | mutex_init(&data->update_lock); | 827 | mutex_init(&data->update_lock); |
821 | 828 | ||
822 | /* Tell the I2C layer a new client has arrived */ | 829 | if (data->chip_type == adm1030) |
823 | if ((err = i2c_attach_client(client))) | 830 | data->chan_select_table = &auto_channel_select_table_adm1030; |
824 | goto exit_free; | 831 | else |
832 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
825 | 833 | ||
826 | /* Initialize the ADM1031 chip */ | 834 | /* Initialize the ADM1031 chip */ |
827 | adm1031_init_client(client); | 835 | adm1031_init_client(client); |
828 | 836 | ||
829 | /* Register sysfs hooks */ | 837 | /* Register sysfs hooks */ |
830 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) | 838 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) |
831 | goto exit_detach; | 839 | goto exit_free; |
832 | 840 | ||
833 | if (kind == adm1031) { | 841 | if (data->chip_type == adm1031) { |
834 | if ((err = sysfs_create_group(&client->dev.kobj, | 842 | if ((err = sysfs_create_group(&client->dev.kobj, |
835 | &adm1031_group_opt))) | 843 | &adm1031_group_opt))) |
836 | goto exit_remove; | 844 | goto exit_remove; |
@@ -847,25 +855,19 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
847 | exit_remove: | 855 | exit_remove: |
848 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | 856 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
849 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | 857 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
850 | exit_detach: | ||
851 | i2c_detach_client(client); | ||
852 | exit_free: | 858 | exit_free: |
853 | kfree(data); | 859 | kfree(data); |
854 | exit: | 860 | exit: |
855 | return err; | 861 | return err; |
856 | } | 862 | } |
857 | 863 | ||
858 | static int adm1031_detach_client(struct i2c_client *client) | 864 | static int adm1031_remove(struct i2c_client *client) |
859 | { | 865 | { |
860 | struct adm1031_data *data = i2c_get_clientdata(client); | 866 | struct adm1031_data *data = i2c_get_clientdata(client); |
861 | int ret; | ||
862 | 867 | ||
863 | hwmon_device_unregister(data->hwmon_dev); | 868 | hwmon_device_unregister(data->hwmon_dev); |
864 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | 869 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
865 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | 870 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
866 | if ((ret = i2c_detach_client(client)) != 0) { | ||
867 | return ret; | ||
868 | } | ||
869 | kfree(data); | 871 | kfree(data); |
870 | return 0; | 872 | return 0; |
871 | } | 873 | } |
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 149ef25252e7..2444b15f2e9d 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -130,25 +130,37 @@ static inline unsigned int AOUT_FROM_REG(u8 reg) | |||
130 | return SCALE(reg, 1250, 255); | 130 | return SCALE(reg, 1250, 255); |
131 | } | 131 | } |
132 | 132 | ||
133 | static int adm9240_attach_adapter(struct i2c_adapter *adapter); | 133 | static int adm9240_probe(struct i2c_client *client, |
134 | static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind); | 134 | const struct i2c_device_id *id); |
135 | static int adm9240_detect(struct i2c_client *client, int kind, | ||
136 | struct i2c_board_info *info); | ||
135 | static void adm9240_init_client(struct i2c_client *client); | 137 | static void adm9240_init_client(struct i2c_client *client); |
136 | static int adm9240_detach_client(struct i2c_client *client); | 138 | static int adm9240_remove(struct i2c_client *client); |
137 | static struct adm9240_data *adm9240_update_device(struct device *dev); | 139 | static struct adm9240_data *adm9240_update_device(struct device *dev); |
138 | 140 | ||
139 | /* driver data */ | 141 | /* driver data */ |
142 | static const struct i2c_device_id adm9240_id[] = { | ||
143 | { "adm9240", adm9240 }, | ||
144 | { "ds1780", ds1780 }, | ||
145 | { "lm81", lm81 }, | ||
146 | { } | ||
147 | }; | ||
148 | MODULE_DEVICE_TABLE(i2c, adm9240_id); | ||
149 | |||
140 | static struct i2c_driver adm9240_driver = { | 150 | static struct i2c_driver adm9240_driver = { |
151 | .class = I2C_CLASS_HWMON, | ||
141 | .driver = { | 152 | .driver = { |
142 | .name = "adm9240", | 153 | .name = "adm9240", |
143 | }, | 154 | }, |
144 | .attach_adapter = adm9240_attach_adapter, | 155 | .probe = adm9240_probe, |
145 | .detach_client = adm9240_detach_client, | 156 | .remove = adm9240_remove, |
157 | .id_table = adm9240_id, | ||
158 | .detect = adm9240_detect, | ||
159 | .address_data = &addr_data, | ||
146 | }; | 160 | }; |
147 | 161 | ||
148 | /* per client data */ | 162 | /* per client data */ |
149 | struct adm9240_data { | 163 | struct adm9240_data { |
150 | enum chips type; | ||
151 | struct i2c_client client; | ||
152 | struct device *hwmon_dev; | 164 | struct device *hwmon_dev; |
153 | struct mutex update_lock; | 165 | struct mutex update_lock; |
154 | char valid; | 166 | char valid; |
@@ -532,28 +544,17 @@ static const struct attribute_group adm9240_group = { | |||
532 | 544 | ||
533 | /*** sensor chip detect and driver install ***/ | 545 | /*** sensor chip detect and driver install ***/ |
534 | 546 | ||
535 | static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | 547 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
548 | static int adm9240_detect(struct i2c_client *new_client, int kind, | ||
549 | struct i2c_board_info *info) | ||
536 | { | 550 | { |
537 | struct i2c_client *new_client; | 551 | struct i2c_adapter *adapter = new_client->adapter; |
538 | struct adm9240_data *data; | ||
539 | int err = 0; | ||
540 | const char *name = ""; | 552 | const char *name = ""; |
553 | int address = new_client->addr; | ||
541 | u8 man_id, die_rev; | 554 | u8 man_id, die_rev; |
542 | 555 | ||
543 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 556 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
544 | goto exit; | 557 | return -ENODEV; |
545 | |||
546 | if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) { | ||
547 | err = -ENOMEM; | ||
548 | goto exit; | ||
549 | } | ||
550 | |||
551 | new_client = &data->client; | ||
552 | i2c_set_clientdata(new_client, data); | ||
553 | new_client->addr = address; | ||
554 | new_client->adapter = adapter; | ||
555 | new_client->driver = &adm9240_driver; | ||
556 | new_client->flags = 0; | ||
557 | 558 | ||
558 | if (kind == 0) { | 559 | if (kind == 0) { |
559 | kind = adm9240; | 560 | kind = adm9240; |
@@ -566,7 +567,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
566 | != address) { | 567 | != address) { |
567 | dev_err(&adapter->dev, "detect fail: address match, " | 568 | dev_err(&adapter->dev, "detect fail: address match, " |
568 | "0x%02x\n", address); | 569 | "0x%02x\n", address); |
569 | goto exit_free; | 570 | return -ENODEV; |
570 | } | 571 | } |
571 | 572 | ||
572 | /* check known chip manufacturer */ | 573 | /* check known chip manufacturer */ |
@@ -581,7 +582,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
581 | } else { | 582 | } else { |
582 | dev_err(&adapter->dev, "detect fail: unknown manuf, " | 583 | dev_err(&adapter->dev, "detect fail: unknown manuf, " |
583 | "0x%02x\n", man_id); | 584 | "0x%02x\n", man_id); |
584 | goto exit_free; | 585 | return -ENODEV; |
585 | } | 586 | } |
586 | 587 | ||
587 | /* successful detect, print chip info */ | 588 | /* successful detect, print chip info */ |
@@ -600,20 +601,31 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
600 | } else if (kind == lm81) { | 601 | } else if (kind == lm81) { |
601 | name = "lm81"; | 602 | name = "lm81"; |
602 | } | 603 | } |
604 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
603 | 605 | ||
604 | /* fill in the remaining client fields and attach */ | 606 | return 0; |
605 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 607 | } |
606 | data->type = kind; | ||
607 | mutex_init(&data->update_lock); | ||
608 | 608 | ||
609 | if ((err = i2c_attach_client(new_client))) | 609 | static int adm9240_probe(struct i2c_client *new_client, |
610 | goto exit_free; | 610 | const struct i2c_device_id *id) |
611 | { | ||
612 | struct adm9240_data *data; | ||
613 | int err; | ||
614 | |||
615 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
616 | if (!data) { | ||
617 | err = -ENOMEM; | ||
618 | goto exit; | ||
619 | } | ||
620 | |||
621 | i2c_set_clientdata(new_client, data); | ||
622 | mutex_init(&data->update_lock); | ||
611 | 623 | ||
612 | adm9240_init_client(new_client); | 624 | adm9240_init_client(new_client); |
613 | 625 | ||
614 | /* populate sysfs filesystem */ | 626 | /* populate sysfs filesystem */ |
615 | if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) | 627 | if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) |
616 | goto exit_detach; | 628 | goto exit_free; |
617 | 629 | ||
618 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 630 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
619 | if (IS_ERR(data->hwmon_dev)) { | 631 | if (IS_ERR(data->hwmon_dev)) { |
@@ -625,32 +637,19 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
625 | 637 | ||
626 | exit_remove: | 638 | exit_remove: |
627 | sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); | 639 | sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); |
628 | exit_detach: | ||
629 | i2c_detach_client(new_client); | ||
630 | exit_free: | 640 | exit_free: |
631 | kfree(data); | 641 | kfree(data); |
632 | exit: | 642 | exit: |
633 | return err; | 643 | return err; |
634 | } | 644 | } |
635 | 645 | ||
636 | static int adm9240_attach_adapter(struct i2c_adapter *adapter) | 646 | static int adm9240_remove(struct i2c_client *client) |
637 | { | ||
638 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
639 | return 0; | ||
640 | return i2c_probe(adapter, &addr_data, adm9240_detect); | ||
641 | } | ||
642 | |||
643 | static int adm9240_detach_client(struct i2c_client *client) | ||
644 | { | 647 | { |
645 | struct adm9240_data *data = i2c_get_clientdata(client); | 648 | struct adm9240_data *data = i2c_get_clientdata(client); |
646 | int err; | ||
647 | 649 | ||
648 | hwmon_device_unregister(data->hwmon_dev); | 650 | hwmon_device_unregister(data->hwmon_dev); |
649 | sysfs_remove_group(&client->dev.kobj, &adm9240_group); | 651 | sysfs_remove_group(&client->dev.kobj, &adm9240_group); |
650 | 652 | ||
651 | if ((err = i2c_detach_client(client))) | ||
652 | return err; | ||
653 | |||
654 | kfree(data); | 653 | kfree(data); |
655 | return 0; | 654 | return 0; |
656 | } | 655 | } |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 5c8b6e0ff47c..5c39b4af1b23 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -64,7 +64,6 @@ static unsigned int ads7828_lsb_resol; /* resolution of the ADC sample lsb */ | |||
64 | 64 | ||
65 | /* Each client has this additional data */ | 65 | /* Each client has this additional data */ |
66 | struct ads7828_data { | 66 | struct ads7828_data { |
67 | struct i2c_client client; | ||
68 | struct device *hwmon_dev; | 67 | struct device *hwmon_dev; |
69 | struct mutex update_lock; /* mutex protect updates */ | 68 | struct mutex update_lock; /* mutex protect updates */ |
70 | char valid; /* !=0 if following fields are valid */ | 69 | char valid; /* !=0 if following fields are valid */ |
@@ -73,7 +72,10 @@ struct ads7828_data { | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | /* Function declaration - necessary due to function dependencies */ | 74 | /* Function declaration - necessary due to function dependencies */ |
76 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind); | 75 | static int ads7828_detect(struct i2c_client *client, int kind, |
76 | struct i2c_board_info *info); | ||
77 | static int ads7828_probe(struct i2c_client *client, | ||
78 | const struct i2c_device_id *id); | ||
77 | 79 | ||
78 | /* The ADS7828 returns the 12-bit sample in two bytes, | 80 | /* The ADS7828 returns the 12-bit sample in two bytes, |
79 | these are read as a word then byte-swapped */ | 81 | these are read as a word then byte-swapped */ |
@@ -156,58 +158,43 @@ static const struct attribute_group ads7828_group = { | |||
156 | .attrs = ads7828_attributes, | 158 | .attrs = ads7828_attributes, |
157 | }; | 159 | }; |
158 | 160 | ||
159 | static int ads7828_attach_adapter(struct i2c_adapter *adapter) | 161 | static int ads7828_remove(struct i2c_client *client) |
160 | { | ||
161 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
162 | return 0; | ||
163 | return i2c_probe(adapter, &addr_data, ads7828_detect); | ||
164 | } | ||
165 | |||
166 | static int ads7828_detach_client(struct i2c_client *client) | ||
167 | { | 162 | { |
168 | struct ads7828_data *data = i2c_get_clientdata(client); | 163 | struct ads7828_data *data = i2c_get_clientdata(client); |
169 | hwmon_device_unregister(data->hwmon_dev); | 164 | hwmon_device_unregister(data->hwmon_dev); |
170 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 165 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
171 | i2c_detach_client(client); | ||
172 | kfree(i2c_get_clientdata(client)); | 166 | kfree(i2c_get_clientdata(client)); |
173 | return 0; | 167 | return 0; |
174 | } | 168 | } |
175 | 169 | ||
170 | static const struct i2c_device_id ads7828_id[] = { | ||
171 | { "ads7828", ads7828 }, | ||
172 | { } | ||
173 | }; | ||
174 | MODULE_DEVICE_TABLE(i2c, ads7828_id); | ||
175 | |||
176 | /* This is the driver that will be inserted */ | 176 | /* This is the driver that will be inserted */ |
177 | static struct i2c_driver ads7828_driver = { | 177 | static struct i2c_driver ads7828_driver = { |
178 | .class = I2C_CLASS_HWMON, | ||
178 | .driver = { | 179 | .driver = { |
179 | .name = "ads7828", | 180 | .name = "ads7828", |
180 | }, | 181 | }, |
181 | .attach_adapter = ads7828_attach_adapter, | 182 | .probe = ads7828_probe, |
182 | .detach_client = ads7828_detach_client, | 183 | .remove = ads7828_remove, |
184 | .id_table = ads7828_id, | ||
185 | .detect = ads7828_detect, | ||
186 | .address_data = &addr_data, | ||
183 | }; | 187 | }; |
184 | 188 | ||
185 | /* This function is called by i2c_probe */ | 189 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
186 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | 190 | static int ads7828_detect(struct i2c_client *client, int kind, |
191 | struct i2c_board_info *info) | ||
187 | { | 192 | { |
188 | struct i2c_client *client; | 193 | struct i2c_adapter *adapter = client->adapter; |
189 | struct ads7828_data *data; | ||
190 | int err = 0; | ||
191 | const char *name = ""; | ||
192 | 194 | ||
193 | /* Check we have a valid client */ | 195 | /* Check we have a valid client */ |
194 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) | 196 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) |
195 | goto exit; | 197 | return -ENODEV; |
196 | |||
197 | /* OK. For now, we presume we have a valid client. We now create the | ||
198 | client structure, even though we cannot fill it completely yet. | ||
199 | But it allows us to access ads7828_read_value. */ | ||
200 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); | ||
201 | if (!data) { | ||
202 | err = -ENOMEM; | ||
203 | goto exit; | ||
204 | } | ||
205 | |||
206 | client = &data->client; | ||
207 | i2c_set_clientdata(client, data); | ||
208 | client->addr = address; | ||
209 | client->adapter = adapter; | ||
210 | client->driver = &ads7828_driver; | ||
211 | 198 | ||
212 | /* Now, we do the remaining detection. There is no identification | 199 | /* Now, we do the remaining detection. There is no identification |
213 | dedicated register so attempt to sanity check using knowledge of | 200 | dedicated register so attempt to sanity check using knowledge of |
@@ -225,32 +212,34 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
225 | printk(KERN_DEBUG | 212 | printk(KERN_DEBUG |
226 | "%s : Doesn't look like an ads7828 device\n", | 213 | "%s : Doesn't look like an ads7828 device\n", |
227 | __func__); | 214 | __func__); |
228 | goto exit_free; | 215 | return -ENODEV; |
229 | } | 216 | } |
230 | } | 217 | } |
231 | } | 218 | } |
219 | strlcpy(info->type, "ads7828", I2C_NAME_SIZE); | ||
232 | 220 | ||
233 | /* Determine the chip type - only one kind supported! */ | 221 | return 0; |
234 | if (kind <= 0) | 222 | } |
235 | kind = ads7828; | ||
236 | 223 | ||
237 | if (kind == ads7828) | 224 | static int ads7828_probe(struct i2c_client *client, |
238 | name = "ads7828"; | 225 | const struct i2c_device_id *id) |
226 | { | ||
227 | struct ads7828_data *data; | ||
228 | int err; | ||
239 | 229 | ||
240 | /* Fill in the remaining client fields, put it into the global list */ | 230 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); |
241 | strlcpy(client->name, name, I2C_NAME_SIZE); | 231 | if (!data) { |
232 | err = -ENOMEM; | ||
233 | goto exit; | ||
234 | } | ||
242 | 235 | ||
236 | i2c_set_clientdata(client, data); | ||
243 | mutex_init(&data->update_lock); | 237 | mutex_init(&data->update_lock); |
244 | 238 | ||
245 | /* Tell the I2C layer a new client has arrived */ | ||
246 | err = i2c_attach_client(client); | ||
247 | if (err) | ||
248 | goto exit_free; | ||
249 | |||
250 | /* Register sysfs hooks */ | 239 | /* Register sysfs hooks */ |
251 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); | 240 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); |
252 | if (err) | 241 | if (err) |
253 | goto exit_detach; | 242 | goto exit_free; |
254 | 243 | ||
255 | data->hwmon_dev = hwmon_device_register(&client->dev); | 244 | data->hwmon_dev = hwmon_device_register(&client->dev); |
256 | if (IS_ERR(data->hwmon_dev)) { | 245 | if (IS_ERR(data->hwmon_dev)) { |
@@ -262,8 +251,6 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
262 | 251 | ||
263 | exit_remove: | 252 | exit_remove: |
264 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 253 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
265 | exit_detach: | ||
266 | i2c_detach_client(client); | ||
267 | exit_free: | 254 | exit_free: |
268 | kfree(data); | 255 | kfree(data); |
269 | exit: | 256 | exit: |
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 6b5325f33a2c..d368d8f845e1 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -138,7 +138,6 @@ I2C_CLIENT_INSMOD_1(adt7470); | |||
138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
139 | 139 | ||
140 | struct adt7470_data { | 140 | struct adt7470_data { |
141 | struct i2c_client client; | ||
142 | struct device *hwmon_dev; | 141 | struct device *hwmon_dev; |
143 | struct attribute_group attrs; | 142 | struct attribute_group attrs; |
144 | struct mutex lock; | 143 | struct mutex lock; |
@@ -164,16 +163,28 @@ struct adt7470_data { | |||
164 | u8 pwm_auto_temp[ADT7470_PWM_COUNT]; | 163 | u8 pwm_auto_temp[ADT7470_PWM_COUNT]; |
165 | }; | 164 | }; |
166 | 165 | ||
167 | static int adt7470_attach_adapter(struct i2c_adapter *adapter); | 166 | static int adt7470_probe(struct i2c_client *client, |
168 | static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind); | 167 | const struct i2c_device_id *id); |
169 | static int adt7470_detach_client(struct i2c_client *client); | 168 | static int adt7470_detect(struct i2c_client *client, int kind, |
169 | struct i2c_board_info *info); | ||
170 | static int adt7470_remove(struct i2c_client *client); | ||
171 | |||
172 | static const struct i2c_device_id adt7470_id[] = { | ||
173 | { "adt7470", adt7470 }, | ||
174 | { } | ||
175 | }; | ||
176 | MODULE_DEVICE_TABLE(i2c, adt7470_id); | ||
170 | 177 | ||
171 | static struct i2c_driver adt7470_driver = { | 178 | static struct i2c_driver adt7470_driver = { |
179 | .class = I2C_CLASS_HWMON, | ||
172 | .driver = { | 180 | .driver = { |
173 | .name = "adt7470", | 181 | .name = "adt7470", |
174 | }, | 182 | }, |
175 | .attach_adapter = adt7470_attach_adapter, | 183 | .probe = adt7470_probe, |
176 | .detach_client = adt7470_detach_client, | 184 | .remove = adt7470_remove, |
185 | .id_table = adt7470_id, | ||
186 | .detect = adt7470_detect, | ||
187 | .address_data = &addr_data, | ||
177 | }; | 188 | }; |
178 | 189 | ||
179 | /* | 190 | /* |
@@ -1004,64 +1015,52 @@ static struct attribute *adt7470_attr[] = | |||
1004 | NULL | 1015 | NULL |
1005 | }; | 1016 | }; |
1006 | 1017 | ||
1007 | static int adt7470_attach_adapter(struct i2c_adapter *adapter) | 1018 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1008 | { | 1019 | static int adt7470_detect(struct i2c_client *client, int kind, |
1009 | if (!(adapter->class & I2C_CLASS_HWMON)) | 1020 | struct i2c_board_info *info) |
1010 | return 0; | ||
1011 | return i2c_probe(adapter, &addr_data, adt7470_detect); | ||
1012 | } | ||
1013 | |||
1014 | static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | ||
1015 | { | 1021 | { |
1016 | struct i2c_client *client; | 1022 | struct i2c_adapter *adapter = client->adapter; |
1017 | struct adt7470_data *data; | ||
1018 | int err = 0; | ||
1019 | 1023 | ||
1020 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1024 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1021 | goto exit; | 1025 | return -ENODEV; |
1022 | |||
1023 | if (!(data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL))) { | ||
1024 | err = -ENOMEM; | ||
1025 | goto exit; | ||
1026 | } | ||
1027 | |||
1028 | client = &data->client; | ||
1029 | client->addr = address; | ||
1030 | client->adapter = adapter; | ||
1031 | client->driver = &adt7470_driver; | ||
1032 | |||
1033 | i2c_set_clientdata(client, data); | ||
1034 | |||
1035 | mutex_init(&data->lock); | ||
1036 | 1026 | ||
1037 | if (kind <= 0) { | 1027 | if (kind <= 0) { |
1038 | int vendor, device, revision; | 1028 | int vendor, device, revision; |
1039 | 1029 | ||
1040 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); | 1030 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); |
1041 | if (vendor != ADT7470_VENDOR) { | 1031 | if (vendor != ADT7470_VENDOR) |
1042 | err = -ENODEV; | 1032 | return -ENODEV; |
1043 | goto exit_free; | ||
1044 | } | ||
1045 | 1033 | ||
1046 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); | 1034 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); |
1047 | if (device != ADT7470_DEVICE) { | 1035 | if (device != ADT7470_DEVICE) |
1048 | err = -ENODEV; | 1036 | return -ENODEV; |
1049 | goto exit_free; | ||
1050 | } | ||
1051 | 1037 | ||
1052 | revision = i2c_smbus_read_byte_data(client, | 1038 | revision = i2c_smbus_read_byte_data(client, |
1053 | ADT7470_REG_REVISION); | 1039 | ADT7470_REG_REVISION); |
1054 | if (revision != ADT7470_REVISION) { | 1040 | if (revision != ADT7470_REVISION) |
1055 | err = -ENODEV; | 1041 | return -ENODEV; |
1056 | goto exit_free; | ||
1057 | } | ||
1058 | } else | 1042 | } else |
1059 | dev_dbg(&adapter->dev, "detection forced\n"); | 1043 | dev_dbg(&adapter->dev, "detection forced\n"); |
1060 | 1044 | ||
1061 | strlcpy(client->name, "adt7470", I2C_NAME_SIZE); | 1045 | strlcpy(info->type, "adt7470", I2C_NAME_SIZE); |
1062 | 1046 | ||
1063 | if ((err = i2c_attach_client(client))) | 1047 | return 0; |
1064 | goto exit_free; | 1048 | } |
1049 | |||
1050 | static int adt7470_probe(struct i2c_client *client, | ||
1051 | const struct i2c_device_id *id) | ||
1052 | { | ||
1053 | struct adt7470_data *data; | ||
1054 | int err; | ||
1055 | |||
1056 | data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL); | ||
1057 | if (!data) { | ||
1058 | err = -ENOMEM; | ||
1059 | goto exit; | ||
1060 | } | ||
1061 | |||
1062 | i2c_set_clientdata(client, data); | ||
1063 | mutex_init(&data->lock); | ||
1065 | 1064 | ||
1066 | dev_info(&client->dev, "%s chip found\n", client->name); | 1065 | dev_info(&client->dev, "%s chip found\n", client->name); |
1067 | 1066 | ||
@@ -1071,7 +1070,7 @@ static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1071 | /* Register sysfs hooks */ | 1070 | /* Register sysfs hooks */ |
1072 | data->attrs.attrs = adt7470_attr; | 1071 | data->attrs.attrs = adt7470_attr; |
1073 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) | 1072 | if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) |
1074 | goto exit_detach; | 1073 | goto exit_free; |
1075 | 1074 | ||
1076 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1075 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1077 | if (IS_ERR(data->hwmon_dev)) { | 1076 | if (IS_ERR(data->hwmon_dev)) { |
@@ -1083,21 +1082,18 @@ static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1083 | 1082 | ||
1084 | exit_remove: | 1083 | exit_remove: |
1085 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1084 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1086 | exit_detach: | ||
1087 | i2c_detach_client(client); | ||
1088 | exit_free: | 1085 | exit_free: |
1089 | kfree(data); | 1086 | kfree(data); |
1090 | exit: | 1087 | exit: |
1091 | return err; | 1088 | return err; |
1092 | } | 1089 | } |
1093 | 1090 | ||
1094 | static int adt7470_detach_client(struct i2c_client *client) | 1091 | static int adt7470_remove(struct i2c_client *client) |
1095 | { | 1092 | { |
1096 | struct adt7470_data *data = i2c_get_clientdata(client); | 1093 | struct adt7470_data *data = i2c_get_clientdata(client); |
1097 | 1094 | ||
1098 | hwmon_device_unregister(data->hwmon_dev); | 1095 | hwmon_device_unregister(data->hwmon_dev); |
1099 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1096 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1100 | i2c_detach_client(client); | ||
1101 | kfree(data); | 1097 | kfree(data); |
1102 | return 0; | 1098 | return 0; |
1103 | } | 1099 | } |
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index 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 | ||
145 | struct adt7473_data { | 145 | struct adt7473_data { |
146 | struct i2c_client client; | ||
147 | struct device *hwmon_dev; | 146 | struct device *hwmon_dev; |
148 | struct attribute_group attrs; | 147 | struct attribute_group attrs; |
149 | struct mutex lock; | 148 | struct mutex lock; |
@@ -178,16 +177,28 @@ struct adt7473_data { | |||
178 | u8 max_duty_at_overheat; | 177 | u8 max_duty_at_overheat; |
179 | }; | 178 | }; |
180 | 179 | ||
181 | static int adt7473_attach_adapter(struct i2c_adapter *adapter); | 180 | static int adt7473_probe(struct i2c_client *client, |
182 | static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind); | 181 | const struct i2c_device_id *id); |
183 | static int adt7473_detach_client(struct i2c_client *client); | 182 | static int adt7473_detect(struct i2c_client *client, int kind, |
183 | struct i2c_board_info *info); | ||
184 | static int adt7473_remove(struct i2c_client *client); | ||
185 | |||
186 | static const struct i2c_device_id adt7473_id[] = { | ||
187 | { "adt7473", adt7473 }, | ||
188 | { } | ||
189 | }; | ||
190 | MODULE_DEVICE_TABLE(i2c, adt7473_id); | ||
184 | 191 | ||
185 | static struct i2c_driver adt7473_driver = { | 192 | static struct i2c_driver adt7473_driver = { |
193 | .class = I2C_CLASS_HWMON, | ||
186 | .driver = { | 194 | .driver = { |
187 | .name = "adt7473", | 195 | .name = "adt7473", |
188 | }, | 196 | }, |
189 | .attach_adapter = adt7473_attach_adapter, | 197 | .probe = adt7473_probe, |
190 | .detach_client = adt7473_detach_client, | 198 | .remove = adt7473_remove, |
199 | .id_table = adt7473_id, | ||
200 | .detect = adt7473_detect, | ||
201 | .address_data = &addr_data, | ||
191 | }; | 202 | }; |
192 | 203 | ||
193 | /* | 204 | /* |
@@ -1042,66 +1053,52 @@ static struct attribute *adt7473_attr[] = | |||
1042 | NULL | 1053 | NULL |
1043 | }; | 1054 | }; |
1044 | 1055 | ||
1045 | static int adt7473_attach_adapter(struct i2c_adapter *adapter) | 1056 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1057 | static int adt7473_detect(struct i2c_client *client, int kind, | ||
1058 | struct i2c_board_info *info) | ||
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 | |||
1052 | static 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 | |
1088 | static int adt7473_probe(struct i2c_client *client, | ||
1089 | const struct i2c_device_id *id) | ||
1090 | { | ||
1091 | struct adt7473_data *data; | ||
1092 | int err; | ||
1093 | |||
1094 | data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); | ||
1095 | if (!data) { | ||
1096 | err = -ENOMEM; | ||
1097 | goto exit; | ||
1098 | } | ||
1099 | |||
1100 | i2c_set_clientdata(client, data); | ||
1101 | mutex_init(&data->lock); | ||
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 | ||
1125 | exit_remove: | 1122 | exit_remove: |
1126 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1123 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
1127 | exit_detach: | ||
1128 | i2c_detach_client(client); | ||
1129 | exit_free: | 1124 | exit_free: |
1130 | kfree(data); | 1125 | kfree(data); |
1131 | exit: | 1126 | exit: |
1132 | return err; | 1127 | return err; |
1133 | } | 1128 | } |
1134 | 1129 | ||
1135 | static int adt7473_detach_client(struct i2c_client *client) | 1130 | static 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. */ |
178 | struct asb100_data { | 178 | struct asb100_data { |
179 | struct i2c_client client; | ||
180 | struct device *hwmon_dev; | 179 | struct device *hwmon_dev; |
181 | struct mutex lock; | 180 | struct mutex lock; |
182 | enum chips type; | ||
183 | 181 | ||
184 | struct mutex update_lock; | 182 | struct mutex update_lock; |
185 | unsigned long last_updated; /* In jiffies */ | 183 | unsigned long last_updated; /* In jiffies */ |
@@ -206,18 +204,30 @@ struct asb100_data { | |||
206 | static int asb100_read_value(struct i2c_client *client, u16 reg); | 204 | static int asb100_read_value(struct i2c_client *client, u16 reg); |
207 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); | 205 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); |
208 | 206 | ||
209 | static int asb100_attach_adapter(struct i2c_adapter *adapter); | 207 | static int asb100_probe(struct i2c_client *client, |
210 | static int asb100_detect(struct i2c_adapter *adapter, int address, int kind); | 208 | const struct i2c_device_id *id); |
211 | static int asb100_detach_client(struct i2c_client *client); | 209 | static int asb100_detect(struct i2c_client *client, int kind, |
210 | struct i2c_board_info *info); | ||
211 | static int asb100_remove(struct i2c_client *client); | ||
212 | static struct asb100_data *asb100_update_device(struct device *dev); | 212 | static struct asb100_data *asb100_update_device(struct device *dev); |
213 | static void asb100_init_client(struct i2c_client *client); | 213 | static void asb100_init_client(struct i2c_client *client); |
214 | 214 | ||
215 | static const struct i2c_device_id asb100_id[] = { | ||
216 | { "asb100", asb100 }, | ||
217 | { } | ||
218 | }; | ||
219 | MODULE_DEVICE_TABLE(i2c, asb100_id); | ||
220 | |||
215 | static struct i2c_driver asb100_driver = { | 221 | static struct i2c_driver asb100_driver = { |
222 | .class = I2C_CLASS_HWMON, | ||
216 | .driver = { | 223 | .driver = { |
217 | .name = "asb100", | 224 | .name = "asb100", |
218 | }, | 225 | }, |
219 | .attach_adapter = asb100_attach_adapter, | 226 | .probe = asb100_probe, |
220 | .detach_client = asb100_detach_client, | 227 | .remove = asb100_remove, |
228 | .id_table = asb100_id, | ||
229 | .detect = asb100_detect, | ||
230 | .address_data = &addr_data, | ||
221 | }; | 231 | }; |
222 | 232 | ||
223 | /* 7 Voltages */ | 233 | /* 7 Voltages */ |
@@ -619,35 +629,13 @@ static const struct attribute_group asb100_group = { | |||
619 | .attrs = asb100_attributes, | 629 | .attrs = asb100_attributes, |
620 | }; | 630 | }; |
621 | 631 | ||
622 | /* This function is called when: | 632 | static int asb100_detect_subclients(struct i2c_client *client) |
623 | asb100_driver is inserted (when this module is loaded), for each | ||
624 | available adapter | ||
625 | when a new adapter is inserted (and asb100_driver is still present) | ||
626 | */ | ||
627 | static int asb100_attach_adapter(struct i2c_adapter *adapter) | ||
628 | { | ||
629 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
630 | return 0; | ||
631 | return i2c_probe(adapter, &addr_data, asb100_detect); | ||
632 | } | ||
633 | |||
634 | static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | ||
635 | int kind, struct i2c_client *client) | ||
636 | { | 633 | { |
637 | int i, id, err; | 634 | int i, id, err; |
635 | int address = client->addr; | ||
636 | unsigned short sc_addr[2]; | ||
638 | struct asb100_data *data = i2c_get_clientdata(client); | 637 | struct asb100_data *data = i2c_get_clientdata(client); |
639 | 638 | struct i2c_adapter *adapter = client->adapter; | |
640 | data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
641 | if (!(data->lm75[0])) { | ||
642 | err = -ENOMEM; | ||
643 | goto ERROR_SC_0; | ||
644 | } | ||
645 | |||
646 | data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
647 | if (!(data->lm75[1])) { | ||
648 | err = -ENOMEM; | ||
649 | goto ERROR_SC_1; | ||
650 | } | ||
651 | 639 | ||
652 | id = i2c_adapter_id(adapter); | 640 | id = i2c_adapter_id(adapter); |
653 | 641 | ||
@@ -665,37 +653,34 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | |||
665 | asb100_write_value(client, ASB100_REG_I2C_SUBADDR, | 653 | asb100_write_value(client, ASB100_REG_I2C_SUBADDR, |
666 | (force_subclients[2] & 0x07) | | 654 | (force_subclients[2] & 0x07) | |
667 | ((force_subclients[3] & 0x07) << 4)); | 655 | ((force_subclients[3] & 0x07) << 4)); |
668 | data->lm75[0]->addr = force_subclients[2]; | 656 | sc_addr[0] = force_subclients[2]; |
669 | data->lm75[1]->addr = force_subclients[3]; | 657 | sc_addr[1] = force_subclients[3]; |
670 | } else { | 658 | } else { |
671 | int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR); | 659 | int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR); |
672 | data->lm75[0]->addr = 0x48 + (val & 0x07); | 660 | sc_addr[0] = 0x48 + (val & 0x07); |
673 | data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07); | 661 | sc_addr[1] = 0x48 + ((val >> 4) & 0x07); |
674 | } | 662 | } |
675 | 663 | ||
676 | if (data->lm75[0]->addr == data->lm75[1]->addr) { | 664 | if (sc_addr[0] == sc_addr[1]) { |
677 | dev_err(&client->dev, "duplicate addresses 0x%x " | 665 | dev_err(&client->dev, "duplicate addresses 0x%x " |
678 | "for subclients\n", data->lm75[0]->addr); | 666 | "for subclients\n", sc_addr[0]); |
679 | err = -ENODEV; | 667 | err = -ENODEV; |
680 | goto ERROR_SC_2; | 668 | goto ERROR_SC_2; |
681 | } | 669 | } |
682 | 670 | ||
683 | for (i = 0; i <= 1; i++) { | 671 | data->lm75[0] = i2c_new_dummy(adapter, sc_addr[0]); |
684 | i2c_set_clientdata(data->lm75[i], NULL); | 672 | if (!data->lm75[0]) { |
685 | data->lm75[i]->adapter = adapter; | ||
686 | data->lm75[i]->driver = &asb100_driver; | ||
687 | strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE); | ||
688 | } | ||
689 | |||
690 | if ((err = i2c_attach_client(data->lm75[0]))) { | ||
691 | dev_err(&client->dev, "subclient %d registration " | 673 | dev_err(&client->dev, "subclient %d registration " |
692 | "at address 0x%x failed.\n", i, data->lm75[0]->addr); | 674 | "at address 0x%x failed.\n", 1, sc_addr[0]); |
675 | err = -ENOMEM; | ||
693 | goto ERROR_SC_2; | 676 | goto ERROR_SC_2; |
694 | } | 677 | } |
695 | 678 | ||
696 | if ((err = i2c_attach_client(data->lm75[1]))) { | 679 | data->lm75[1] = i2c_new_dummy(adapter, sc_addr[1]); |
680 | if (!data->lm75[1]) { | ||
697 | dev_err(&client->dev, "subclient %d registration " | 681 | dev_err(&client->dev, "subclient %d registration " |
698 | "at address 0x%x failed.\n", i, data->lm75[1]->addr); | 682 | "at address 0x%x failed.\n", 2, sc_addr[1]); |
683 | err = -ENOMEM; | ||
699 | goto ERROR_SC_3; | 684 | goto ERROR_SC_3; |
700 | } | 685 | } |
701 | 686 | ||
@@ -703,55 +688,31 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, | |||
703 | 688 | ||
704 | /* Undo inits in case of errors */ | 689 | /* Undo inits in case of errors */ |
705 | ERROR_SC_3: | 690 | ERROR_SC_3: |
706 | i2c_detach_client(data->lm75[0]); | 691 | i2c_unregister_device(data->lm75[0]); |
707 | ERROR_SC_2: | 692 | ERROR_SC_2: |
708 | kfree(data->lm75[1]); | ||
709 | ERROR_SC_1: | ||
710 | kfree(data->lm75[0]); | ||
711 | ERROR_SC_0: | ||
712 | return err; | 693 | return err; |
713 | } | 694 | } |
714 | 695 | ||
715 | static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | 696 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
697 | static int asb100_detect(struct i2c_client *client, int kind, | ||
698 | struct i2c_board_info *info) | ||
716 | { | 699 | { |
717 | int err; | 700 | struct i2c_adapter *adapter = client->adapter; |
718 | struct i2c_client *client; | ||
719 | struct asb100_data *data; | ||
720 | 701 | ||
721 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 702 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
722 | pr_debug("asb100.o: detect failed, " | 703 | pr_debug("asb100.o: detect failed, " |
723 | "smbus byte data not supported!\n"); | 704 | "smbus byte data not supported!\n"); |
724 | err = -ENODEV; | 705 | return -ENODEV; |
725 | goto ERROR0; | ||
726 | } | 706 | } |
727 | 707 | ||
728 | /* OK. For now, we presume we have a valid client. We now create the | ||
729 | client structure, even though we cannot fill it completely yet. | ||
730 | But it allows us to access asb100_{read,write}_value. */ | ||
731 | |||
732 | if (!(data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL))) { | ||
733 | pr_debug("asb100.o: detect failed, kzalloc failed!\n"); | ||
734 | err = -ENOMEM; | ||
735 | goto ERROR0; | ||
736 | } | ||
737 | |||
738 | client = &data->client; | ||
739 | mutex_init(&data->lock); | ||
740 | i2c_set_clientdata(client, data); | ||
741 | client->addr = address; | ||
742 | client->adapter = adapter; | ||
743 | client->driver = &asb100_driver; | ||
744 | |||
745 | /* Now, we do the remaining detection. */ | ||
746 | |||
747 | /* The chip may be stuck in some other bank than bank 0. This may | 708 | /* The chip may be stuck in some other bank than bank 0. This may |
748 | make reading other information impossible. Specify a force=... or | 709 | make reading other information impossible. Specify a force=... or |
749 | force_*=... parameter, and the chip will be reset to the right | 710 | force_*=... parameter, and the chip will be reset to the right |
750 | bank. */ | 711 | bank. */ |
751 | if (kind < 0) { | 712 | if (kind < 0) { |
752 | 713 | ||
753 | int val1 = asb100_read_value(client, ASB100_REG_BANK); | 714 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK); |
754 | int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN); | 715 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
755 | 716 | ||
756 | /* If we're in bank 0 */ | 717 | /* If we're in bank 0 */ |
757 | if ((!(val1 & 0x07)) && | 718 | if ((!(val1 & 0x07)) && |
@@ -761,48 +722,60 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
761 | ((val1 & 0x80) && (val2 != 0x06)))) { | 722 | ((val1 & 0x80) && (val2 != 0x06)))) { |
762 | pr_debug("asb100.o: detect failed, " | 723 | pr_debug("asb100.o: detect failed, " |
763 | "bad chip id 0x%02x!\n", val2); | 724 | "bad chip id 0x%02x!\n", val2); |
764 | err = -ENODEV; | 725 | return -ENODEV; |
765 | goto ERROR1; | ||
766 | } | 726 | } |
767 | 727 | ||
768 | } /* kind < 0 */ | 728 | } /* kind < 0 */ |
769 | 729 | ||
770 | /* We have either had a force parameter, or we have already detected | 730 | /* We have either had a force parameter, or we have already detected |
771 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ | 731 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ |
772 | asb100_write_value(client, ASB100_REG_BANK, | 732 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, |
773 | (asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80); | 733 | (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) |
734 | | 0x80); | ||
774 | 735 | ||
775 | /* Determine the chip type. */ | 736 | /* Determine the chip type. */ |
776 | if (kind <= 0) { | 737 | if (kind <= 0) { |
777 | int val1 = asb100_read_value(client, ASB100_REG_WCHIPID); | 738 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); |
778 | int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN); | 739 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
779 | 740 | ||
780 | if ((val1 == 0x31) && (val2 == 0x06)) | 741 | if ((val1 == 0x31) && (val2 == 0x06)) |
781 | kind = asb100; | 742 | kind = asb100; |
782 | else { | 743 | else { |
783 | if (kind == 0) | 744 | if (kind == 0) |
784 | dev_warn(&client->dev, "ignoring " | 745 | dev_warn(&adapter->dev, "ignoring " |
785 | "'force' parameter for unknown chip " | 746 | "'force' parameter for unknown chip " |
786 | "at adapter %d, address 0x%02x.\n", | 747 | "at adapter %d, address 0x%02x.\n", |
787 | i2c_adapter_id(adapter), address); | 748 | i2c_adapter_id(adapter), client->addr); |
788 | err = -ENODEV; | 749 | return -ENODEV; |
789 | goto ERROR1; | ||
790 | } | 750 | } |
791 | } | 751 | } |
792 | 752 | ||
793 | /* Fill in remaining client fields and put it into the global list */ | 753 | strlcpy(info->type, "asb100", I2C_NAME_SIZE); |
794 | strlcpy(client->name, "asb100", I2C_NAME_SIZE); | ||
795 | data->type = kind; | ||
796 | mutex_init(&data->update_lock); | ||
797 | 754 | ||
798 | /* Tell the I2C layer a new client has arrived */ | 755 | return 0; |
799 | if ((err = i2c_attach_client(client))) | 756 | } |
800 | goto ERROR1; | 757 | |
758 | static int asb100_probe(struct i2c_client *client, | ||
759 | const struct i2c_device_id *id) | ||
760 | { | ||
761 | int err; | ||
762 | struct asb100_data *data; | ||
763 | |||
764 | data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL); | ||
765 | if (!data) { | ||
766 | pr_debug("asb100.o: probe failed, kzalloc failed!\n"); | ||
767 | err = -ENOMEM; | ||
768 | goto ERROR0; | ||
769 | } | ||
770 | |||
771 | i2c_set_clientdata(client, data); | ||
772 | mutex_init(&data->lock); | ||
773 | mutex_init(&data->update_lock); | ||
801 | 774 | ||
802 | /* Attach secondary lm75 clients */ | 775 | /* Attach secondary lm75 clients */ |
803 | if ((err = asb100_detect_subclients(adapter, address, kind, | 776 | err = asb100_detect_subclients(client); |
804 | client))) | 777 | if (err) |
805 | goto ERROR2; | 778 | goto ERROR1; |
806 | 779 | ||
807 | /* Initialize the chip */ | 780 | /* Initialize the chip */ |
808 | asb100_init_client(client); | 781 | asb100_init_client(client); |
@@ -827,39 +800,25 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
827 | ERROR4: | 800 | ERROR4: |
828 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | 801 | sysfs_remove_group(&client->dev.kobj, &asb100_group); |
829 | ERROR3: | 802 | ERROR3: |
830 | i2c_detach_client(data->lm75[1]); | 803 | i2c_unregister_device(data->lm75[1]); |
831 | i2c_detach_client(data->lm75[0]); | 804 | i2c_unregister_device(data->lm75[0]); |
832 | kfree(data->lm75[1]); | ||
833 | kfree(data->lm75[0]); | ||
834 | ERROR2: | ||
835 | i2c_detach_client(client); | ||
836 | ERROR1: | 805 | ERROR1: |
837 | kfree(data); | 806 | kfree(data); |
838 | ERROR0: | 807 | ERROR0: |
839 | return err; | 808 | return err; |
840 | } | 809 | } |
841 | 810 | ||
842 | static int asb100_detach_client(struct i2c_client *client) | 811 | static int asb100_remove(struct i2c_client *client) |
843 | { | 812 | { |
844 | struct asb100_data *data = i2c_get_clientdata(client); | 813 | struct asb100_data *data = i2c_get_clientdata(client); |
845 | int err; | ||
846 | |||
847 | /* main client */ | ||
848 | if (data) { | ||
849 | hwmon_device_unregister(data->hwmon_dev); | ||
850 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | ||
851 | } | ||
852 | 814 | ||
853 | if ((err = i2c_detach_client(client))) | 815 | hwmon_device_unregister(data->hwmon_dev); |
854 | return err; | 816 | sysfs_remove_group(&client->dev.kobj, &asb100_group); |
855 | 817 | ||
856 | /* main client */ | 818 | i2c_unregister_device(data->lm75[1]); |
857 | if (data) | 819 | i2c_unregister_device(data->lm75[0]); |
858 | kfree(data); | ||
859 | 820 | ||
860 | /* subclient */ | 821 | kfree(data); |
861 | else | ||
862 | kfree(client); | ||
863 | 822 | ||
864 | return 0; | 823 | return 0; |
865 | } | 824 | } |
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index 01c17e387f03..d191118ba0cb 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -46,21 +46,32 @@ static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; | |||
46 | 46 | ||
47 | I2C_CLIENT_INSMOD_1(atxp1); | 47 | I2C_CLIENT_INSMOD_1(atxp1); |
48 | 48 | ||
49 | static int atxp1_attach_adapter(struct i2c_adapter * adapter); | 49 | static int atxp1_probe(struct i2c_client *client, |
50 | static int atxp1_detach_client(struct i2c_client * client); | 50 | const struct i2c_device_id *id); |
51 | static int atxp1_remove(struct i2c_client *client); | ||
51 | static struct atxp1_data * atxp1_update_device(struct device *dev); | 52 | static struct atxp1_data * atxp1_update_device(struct device *dev); |
52 | static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind); | 53 | static int atxp1_detect(struct i2c_client *client, int kind, |
54 | struct i2c_board_info *info); | ||
55 | |||
56 | static const struct i2c_device_id atxp1_id[] = { | ||
57 | { "atxp1", atxp1 }, | ||
58 | { } | ||
59 | }; | ||
60 | MODULE_DEVICE_TABLE(i2c, atxp1_id); | ||
53 | 61 | ||
54 | static struct i2c_driver atxp1_driver = { | 62 | static struct i2c_driver atxp1_driver = { |
63 | .class = I2C_CLASS_HWMON, | ||
55 | .driver = { | 64 | .driver = { |
56 | .name = "atxp1", | 65 | .name = "atxp1", |
57 | }, | 66 | }, |
58 | .attach_adapter = atxp1_attach_adapter, | 67 | .probe = atxp1_probe, |
59 | .detach_client = atxp1_detach_client, | 68 | .remove = atxp1_remove, |
69 | .id_table = atxp1_id, | ||
70 | .detect = atxp1_detect, | ||
71 | .address_data = &addr_data, | ||
60 | }; | 72 | }; |
61 | 73 | ||
62 | struct atxp1_data { | 74 | struct atxp1_data { |
63 | struct i2c_client client; | ||
64 | struct device *hwmon_dev; | 75 | struct device *hwmon_dev; |
65 | struct mutex update_lock; | 76 | struct mutex update_lock; |
66 | unsigned long last_updated; | 77 | unsigned long last_updated; |
@@ -263,35 +274,16 @@ static const struct attribute_group atxp1_group = { | |||
263 | }; | 274 | }; |
264 | 275 | ||
265 | 276 | ||
266 | static int atxp1_attach_adapter(struct i2c_adapter *adapter) | 277 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
278 | static int atxp1_detect(struct i2c_client *new_client, int kind, | ||
279 | struct i2c_board_info *info) | ||
267 | { | 280 | { |
268 | if (!(adapter->class & I2C_CLASS_HWMON)) | 281 | struct i2c_adapter *adapter = new_client->adapter; |
269 | return 0; | ||
270 | return i2c_probe(adapter, &addr_data, &atxp1_detect); | ||
271 | }; | ||
272 | 282 | ||
273 | static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | ||
274 | { | ||
275 | struct i2c_client * new_client; | ||
276 | struct atxp1_data * data; | ||
277 | int err = 0; | ||
278 | u8 temp; | 283 | u8 temp; |
279 | 284 | ||
280 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 285 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
281 | goto exit; | 286 | return -ENODEV; |
282 | |||
283 | if (!(data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL))) { | ||
284 | err = -ENOMEM; | ||
285 | goto exit; | ||
286 | } | ||
287 | |||
288 | new_client = &data->client; | ||
289 | i2c_set_clientdata(new_client, data); | ||
290 | |||
291 | new_client->addr = address; | ||
292 | new_client->adapter = adapter; | ||
293 | new_client->driver = &atxp1_driver; | ||
294 | new_client->flags = 0; | ||
295 | 287 | ||
296 | /* Detect ATXP1, checking if vendor ID registers are all zero */ | 288 | /* Detect ATXP1, checking if vendor ID registers are all zero */ |
297 | if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) && | 289 | if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) && |
@@ -305,35 +297,46 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
305 | 297 | ||
306 | if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && | 298 | if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && |
307 | (i2c_smbus_read_byte_data(new_client, 0x11) == temp) )) | 299 | (i2c_smbus_read_byte_data(new_client, 0x11) == temp) )) |
308 | goto exit_free; | 300 | return -ENODEV; |
309 | } | 301 | } |
310 | 302 | ||
311 | /* Get VRM */ | 303 | /* Get VRM */ |
312 | data->vrm = vid_which_vrm(); | 304 | temp = vid_which_vrm(); |
313 | 305 | ||
314 | if ((data->vrm != 90) && (data->vrm != 91)) { | 306 | if ((temp != 90) && (temp != 91)) { |
315 | dev_err(&new_client->dev, "Not supporting VRM %d.%d\n", | 307 | dev_err(&adapter->dev, "atxp1: Not supporting VRM %d.%d\n", |
316 | data->vrm / 10, data->vrm % 10); | 308 | temp / 10, temp % 10); |
317 | goto exit_free; | 309 | return -ENODEV; |
318 | } | 310 | } |
319 | 311 | ||
320 | strncpy(new_client->name, "atxp1", I2C_NAME_SIZE); | 312 | strlcpy(info->type, "atxp1", I2C_NAME_SIZE); |
321 | |||
322 | data->valid = 0; | ||
323 | 313 | ||
324 | mutex_init(&data->update_lock); | 314 | return 0; |
315 | } | ||
325 | 316 | ||
326 | err = i2c_attach_client(new_client); | 317 | static int atxp1_probe(struct i2c_client *new_client, |
318 | const struct i2c_device_id *id) | ||
319 | { | ||
320 | struct atxp1_data *data; | ||
321 | int err; | ||
327 | 322 | ||
328 | if (err) | 323 | data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL); |
329 | { | 324 | if (!data) { |
330 | dev_err(&new_client->dev, "Attach client error.\n"); | 325 | err = -ENOMEM; |
331 | goto exit_free; | 326 | goto exit; |
332 | } | 327 | } |
333 | 328 | ||
329 | /* Get VRM */ | ||
330 | data->vrm = vid_which_vrm(); | ||
331 | |||
332 | i2c_set_clientdata(new_client, data); | ||
333 | data->valid = 0; | ||
334 | |||
335 | mutex_init(&data->update_lock); | ||
336 | |||
334 | /* Register sysfs hooks */ | 337 | /* Register sysfs hooks */ |
335 | if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) | 338 | if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) |
336 | goto exit_detach; | 339 | goto exit_free; |
337 | 340 | ||
338 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 341 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
339 | if (IS_ERR(data->hwmon_dev)) { | 342 | if (IS_ERR(data->hwmon_dev)) { |
@@ -348,30 +351,22 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
348 | 351 | ||
349 | exit_remove_files: | 352 | exit_remove_files: |
350 | sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); | 353 | sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); |
351 | exit_detach: | ||
352 | i2c_detach_client(new_client); | ||
353 | exit_free: | 354 | exit_free: |
354 | kfree(data); | 355 | kfree(data); |
355 | exit: | 356 | exit: |
356 | return err; | 357 | return err; |
357 | }; | 358 | }; |
358 | 359 | ||
359 | static int atxp1_detach_client(struct i2c_client * client) | 360 | static int atxp1_remove(struct i2c_client *client) |
360 | { | 361 | { |
361 | struct atxp1_data * data = i2c_get_clientdata(client); | 362 | struct atxp1_data * data = i2c_get_clientdata(client); |
362 | int err; | ||
363 | 363 | ||
364 | hwmon_device_unregister(data->hwmon_dev); | 364 | hwmon_device_unregister(data->hwmon_dev); |
365 | sysfs_remove_group(&client->dev.kobj, &atxp1_group); | 365 | sysfs_remove_group(&client->dev.kobj, &atxp1_group); |
366 | 366 | ||
367 | err = i2c_detach_client(client); | 367 | kfree(data); |
368 | |||
369 | if (err) | ||
370 | dev_err(&client->dev, "Failed to detach client.\n"); | ||
371 | else | ||
372 | kfree(data); | ||
373 | 368 | ||
374 | return err; | 369 | return 0; |
375 | }; | 370 | }; |
376 | 371 | ||
377 | static int __init atxp1_init(void) | 372 | static int __init atxp1_init(void) |
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 5f300ffed657..7415381601c3 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -72,7 +72,6 @@ static const u8 DS1621_REG_TEMP[3] = { | |||
72 | 72 | ||
73 | /* Each client has this additional data */ | 73 | /* Each client has this additional data */ |
74 | struct ds1621_data { | 74 | struct ds1621_data { |
75 | struct i2c_client client; | ||
76 | struct device *hwmon_dev; | 75 | struct device *hwmon_dev; |
77 | struct mutex update_lock; | 76 | struct mutex update_lock; |
78 | char valid; /* !=0 if following fields are valid */ | 77 | char valid; /* !=0 if following fields are valid */ |
@@ -82,20 +81,32 @@ struct ds1621_data { | |||
82 | u8 conf; /* Register encoding, combined */ | 81 | u8 conf; /* Register encoding, combined */ |
83 | }; | 82 | }; |
84 | 83 | ||
85 | static int ds1621_attach_adapter(struct i2c_adapter *adapter); | 84 | static int ds1621_probe(struct i2c_client *client, |
86 | static int ds1621_detect(struct i2c_adapter *adapter, int address, | 85 | const struct i2c_device_id *id); |
87 | int kind); | 86 | static int ds1621_detect(struct i2c_client *client, int kind, |
87 | struct i2c_board_info *info); | ||
88 | static void ds1621_init_client(struct i2c_client *client); | 88 | static void ds1621_init_client(struct i2c_client *client); |
89 | static int ds1621_detach_client(struct i2c_client *client); | 89 | static int ds1621_remove(struct i2c_client *client); |
90 | static struct ds1621_data *ds1621_update_client(struct device *dev); | 90 | static struct ds1621_data *ds1621_update_client(struct device *dev); |
91 | 91 | ||
92 | static const struct i2c_device_id ds1621_id[] = { | ||
93 | { "ds1621", ds1621 }, | ||
94 | { "ds1625", ds1621 }, | ||
95 | { } | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(i2c, ds1621_id); | ||
98 | |||
92 | /* This is the driver that will be inserted */ | 99 | /* This is the driver that will be inserted */ |
93 | static struct i2c_driver ds1621_driver = { | 100 | static struct i2c_driver ds1621_driver = { |
101 | .class = I2C_CLASS_HWMON, | ||
94 | .driver = { | 102 | .driver = { |
95 | .name = "ds1621", | 103 | .name = "ds1621", |
96 | }, | 104 | }, |
97 | .attach_adapter = ds1621_attach_adapter, | 105 | .probe = ds1621_probe, |
98 | .detach_client = ds1621_detach_client, | 106 | .remove = ds1621_remove, |
107 | .id_table = ds1621_id, | ||
108 | .detect = ds1621_detect, | ||
109 | .address_data = &addr_data, | ||
99 | }; | 110 | }; |
100 | 111 | ||
101 | /* All registers are word-sized, except for the configuration register. | 112 | /* All registers are word-sized, except for the configuration register. |
@@ -199,40 +210,18 @@ static const struct attribute_group ds1621_group = { | |||
199 | }; | 210 | }; |
200 | 211 | ||
201 | 212 | ||
202 | static int ds1621_attach_adapter(struct i2c_adapter *adapter) | 213 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
203 | { | 214 | static int ds1621_detect(struct i2c_client *client, int kind, |
204 | if (!(adapter->class & I2C_CLASS_HWMON)) | 215 | struct i2c_board_info *info) |
205 | return 0; | ||
206 | return i2c_probe(adapter, &addr_data, ds1621_detect); | ||
207 | } | ||
208 | |||
209 | /* This function is called by i2c_probe */ | ||
210 | static int ds1621_detect(struct i2c_adapter *adapter, int address, | ||
211 | int kind) | ||
212 | { | 216 | { |
217 | struct i2c_adapter *adapter = client->adapter; | ||
213 | int conf, temp; | 218 | int conf, temp; |
214 | struct i2c_client *client; | 219 | int i; |
215 | struct ds1621_data *data; | ||
216 | int i, err = 0; | ||
217 | 220 | ||
218 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 221 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
219 | | I2C_FUNC_SMBUS_WORD_DATA | 222 | | I2C_FUNC_SMBUS_WORD_DATA |
220 | | I2C_FUNC_SMBUS_WRITE_BYTE)) | 223 | | I2C_FUNC_SMBUS_WRITE_BYTE)) |
221 | goto exit; | 224 | return -ENODEV; |
222 | |||
223 | /* OK. For now, we presume we have a valid client. We now create the | ||
224 | client structure, even though we cannot fill it completely yet. | ||
225 | But it allows us to access ds1621_{read,write}_value. */ | ||
226 | if (!(data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL))) { | ||
227 | err = -ENOMEM; | ||
228 | goto exit; | ||
229 | } | ||
230 | |||
231 | client = &data->client; | ||
232 | i2c_set_clientdata(client, data); | ||
233 | client->addr = address; | ||
234 | client->adapter = adapter; | ||
235 | client->driver = &ds1621_driver; | ||
236 | 225 | ||
237 | /* Now, we do the remaining detection. It is lousy. */ | 226 | /* Now, we do the remaining detection. It is lousy. */ |
238 | if (kind < 0) { | 227 | if (kind < 0) { |
@@ -241,29 +230,41 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
241 | improbable in our case. */ | 230 | improbable in our case. */ |
242 | conf = ds1621_read_value(client, DS1621_REG_CONF); | 231 | conf = ds1621_read_value(client, DS1621_REG_CONF); |
243 | if (conf & DS1621_REG_CONFIG_NVB) | 232 | if (conf & DS1621_REG_CONFIG_NVB) |
244 | goto exit_free; | 233 | return -ENODEV; |
245 | /* The 7 lowest bits of a temperature should always be 0. */ | 234 | /* The 7 lowest bits of a temperature should always be 0. */ |
246 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { | 235 | for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) { |
247 | temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); | 236 | temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); |
248 | if (temp & 0x007f) | 237 | if (temp & 0x007f) |
249 | goto exit_free; | 238 | return -ENODEV; |
250 | } | 239 | } |
251 | } | 240 | } |
252 | 241 | ||
253 | /* Fill in remaining client fields and put it into the global list */ | 242 | strlcpy(info->type, "ds1621", I2C_NAME_SIZE); |
254 | strlcpy(client->name, "ds1621", I2C_NAME_SIZE); | ||
255 | mutex_init(&data->update_lock); | ||
256 | 243 | ||
257 | /* Tell the I2C layer a new client has arrived */ | 244 | return 0; |
258 | if ((err = i2c_attach_client(client))) | 245 | } |
259 | goto exit_free; | 246 | |
247 | static int ds1621_probe(struct i2c_client *client, | ||
248 | const struct i2c_device_id *id) | ||
249 | { | ||
250 | struct ds1621_data *data; | ||
251 | int err; | ||
252 | |||
253 | data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL); | ||
254 | if (!data) { | ||
255 | err = -ENOMEM; | ||
256 | goto exit; | ||
257 | } | ||
258 | |||
259 | i2c_set_clientdata(client, data); | ||
260 | mutex_init(&data->update_lock); | ||
260 | 261 | ||
261 | /* Initialize the DS1621 chip */ | 262 | /* Initialize the DS1621 chip */ |
262 | ds1621_init_client(client); | 263 | ds1621_init_client(client); |
263 | 264 | ||
264 | /* Register sysfs hooks */ | 265 | /* Register sysfs hooks */ |
265 | if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) | 266 | if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) |
266 | goto exit_detach; | 267 | goto exit_free; |
267 | 268 | ||
268 | data->hwmon_dev = hwmon_device_register(&client->dev); | 269 | data->hwmon_dev = hwmon_device_register(&client->dev); |
269 | if (IS_ERR(data->hwmon_dev)) { | 270 | if (IS_ERR(data->hwmon_dev)) { |
@@ -275,25 +276,19 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
275 | 276 | ||
276 | exit_remove_files: | 277 | exit_remove_files: |
277 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | 278 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); |
278 | exit_detach: | ||
279 | i2c_detach_client(client); | ||
280 | exit_free: | 279 | exit_free: |
281 | kfree(data); | 280 | kfree(data); |
282 | exit: | 281 | exit: |
283 | return err; | 282 | return err; |
284 | } | 283 | } |
285 | 284 | ||
286 | static int ds1621_detach_client(struct i2c_client *client) | 285 | static int ds1621_remove(struct i2c_client *client) |
287 | { | 286 | { |
288 | struct ds1621_data *data = i2c_get_clientdata(client); | 287 | struct ds1621_data *data = i2c_get_clientdata(client); |
289 | int err; | ||
290 | 288 | ||
291 | hwmon_device_unregister(data->hwmon_dev); | 289 | hwmon_device_unregister(data->hwmon_dev); |
292 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | 290 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); |
293 | 291 | ||
294 | if ((err = i2c_detach_client(client))) | ||
295 | return err; | ||
296 | |||
297 | kfree(data); | 292 | kfree(data); |
298 | 293 | ||
299 | return 0; | 294 | return 0; |
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index dc1f30e432ea..1692de369969 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -87,7 +87,6 @@ I2C_CLIENT_INSMOD_2(f75373, f75375); | |||
87 | 87 | ||
88 | struct f75375_data { | 88 | struct f75375_data { |
89 | unsigned short addr; | 89 | unsigned short addr; |
90 | struct i2c_client *client; | ||
91 | struct device *hwmon_dev; | 90 | struct device *hwmon_dev; |
92 | 91 | ||
93 | const char *name; | 92 | const char *name; |
@@ -114,21 +113,12 @@ struct f75375_data { | |||
114 | s8 temp_max_hyst[2]; | 113 | s8 temp_max_hyst[2]; |
115 | }; | 114 | }; |
116 | 115 | ||
117 | static int f75375_attach_adapter(struct i2c_adapter *adapter); | 116 | static int f75375_detect(struct i2c_client *client, int kind, |
118 | static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); | 117 | struct i2c_board_info *info); |
119 | static int f75375_detach_client(struct i2c_client *client); | ||
120 | static int f75375_probe(struct i2c_client *client, | 118 | static int f75375_probe(struct i2c_client *client, |
121 | const struct i2c_device_id *id); | 119 | const struct i2c_device_id *id); |
122 | static int f75375_remove(struct i2c_client *client); | 120 | static int f75375_remove(struct i2c_client *client); |
123 | 121 | ||
124 | static struct i2c_driver f75375_legacy_driver = { | ||
125 | .driver = { | ||
126 | .name = "f75375_legacy", | ||
127 | }, | ||
128 | .attach_adapter = f75375_attach_adapter, | ||
129 | .detach_client = f75375_detach_client, | ||
130 | }; | ||
131 | |||
132 | static const struct i2c_device_id f75375_id[] = { | 122 | static const struct i2c_device_id f75375_id[] = { |
133 | { "f75373", f75373 }, | 123 | { "f75373", f75373 }, |
134 | { "f75375", f75375 }, | 124 | { "f75375", f75375 }, |
@@ -137,12 +127,15 @@ static const struct i2c_device_id f75375_id[] = { | |||
137 | MODULE_DEVICE_TABLE(i2c, f75375_id); | 127 | MODULE_DEVICE_TABLE(i2c, f75375_id); |
138 | 128 | ||
139 | static struct i2c_driver f75375_driver = { | 129 | static struct i2c_driver f75375_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
140 | .driver = { | 131 | .driver = { |
141 | .name = "f75375", | 132 | .name = "f75375", |
142 | }, | 133 | }, |
143 | .probe = f75375_probe, | 134 | .probe = f75375_probe, |
144 | .remove = f75375_remove, | 135 | .remove = f75375_remove, |
145 | .id_table = f75375_id, | 136 | .id_table = f75375_id, |
137 | .detect = f75375_detect, | ||
138 | .address_data = &addr_data, | ||
146 | }; | 139 | }; |
147 | 140 | ||
148 | static inline int f75375_read8(struct i2c_client *client, u8 reg) | 141 | static inline int f75375_read8(struct i2c_client *client, u8 reg) |
@@ -607,22 +600,6 @@ static const struct attribute_group f75375_group = { | |||
607 | .attrs = f75375_attributes, | 600 | .attrs = f75375_attributes, |
608 | }; | 601 | }; |
609 | 602 | ||
610 | static int f75375_detach_client(struct i2c_client *client) | ||
611 | { | ||
612 | int err; | ||
613 | |||
614 | f75375_remove(client); | ||
615 | err = i2c_detach_client(client); | ||
616 | if (err) { | ||
617 | dev_err(&client->dev, | ||
618 | "Client deregistration failed, " | ||
619 | "client not detached.\n"); | ||
620 | return err; | ||
621 | } | ||
622 | kfree(client); | ||
623 | return 0; | ||
624 | } | ||
625 | |||
626 | static void f75375_init(struct i2c_client *client, struct f75375_data *data, | 603 | static void f75375_init(struct i2c_client *client, struct f75375_data *data, |
627 | struct f75375s_platform_data *f75375s_pdata) | 604 | struct f75375s_platform_data *f75375s_pdata) |
628 | { | 605 | { |
@@ -651,7 +628,6 @@ static int f75375_probe(struct i2c_client *client, | |||
651 | return -ENOMEM; | 628 | return -ENOMEM; |
652 | 629 | ||
653 | i2c_set_clientdata(client, data); | 630 | i2c_set_clientdata(client, data); |
654 | data->client = client; | ||
655 | mutex_init(&data->update_lock); | 631 | mutex_init(&data->update_lock); |
656 | data->kind = id->driver_data; | 632 | data->kind = id->driver_data; |
657 | 633 | ||
@@ -700,29 +676,13 @@ static int f75375_remove(struct i2c_client *client) | |||
700 | return 0; | 676 | return 0; |
701 | } | 677 | } |
702 | 678 | ||
703 | static int f75375_attach_adapter(struct i2c_adapter *adapter) | 679 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
704 | { | 680 | static int f75375_detect(struct i2c_client *client, int kind, |
705 | if (!(adapter->class & I2C_CLASS_HWMON)) | 681 | struct i2c_board_info *info) |
706 | return 0; | ||
707 | return i2c_probe(adapter, &addr_data, f75375_detect); | ||
708 | } | ||
709 | |||
710 | /* This function is called by i2c_probe */ | ||
711 | static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | ||
712 | { | 682 | { |
713 | struct i2c_client *client; | 683 | struct i2c_adapter *adapter = client->adapter; |
714 | u8 version = 0; | 684 | u8 version = 0; |
715 | int err = 0; | ||
716 | const char *name = ""; | 685 | const char *name = ""; |
717 | struct i2c_device_id id; | ||
718 | |||
719 | if (!(client = kzalloc(sizeof(*client), GFP_KERNEL))) { | ||
720 | err = -ENOMEM; | ||
721 | goto exit; | ||
722 | } | ||
723 | client->addr = address; | ||
724 | client->adapter = adapter; | ||
725 | client->driver = &f75375_legacy_driver; | ||
726 | 686 | ||
727 | if (kind < 0) { | 687 | if (kind < 0) { |
728 | u16 vendid = f75375_read16(client, F75375_REG_VENDOR); | 688 | u16 vendid = f75375_read16(client, F75375_REG_VENDOR); |
@@ -736,7 +696,7 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | |||
736 | dev_err(&adapter->dev, | 696 | dev_err(&adapter->dev, |
737 | "failed,%02X,%02X,%02X\n", | 697 | "failed,%02X,%02X,%02X\n", |
738 | chipid, version, vendid); | 698 | chipid, version, vendid); |
739 | goto exit_free; | 699 | return -ENODEV; |
740 | } | 700 | } |
741 | } | 701 | } |
742 | 702 | ||
@@ -746,43 +706,18 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) | |||
746 | name = "f75373"; | 706 | name = "f75373"; |
747 | } | 707 | } |
748 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); | 708 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); |
749 | strlcpy(client->name, name, I2C_NAME_SIZE); | 709 | strlcpy(info->type, name, I2C_NAME_SIZE); |
750 | |||
751 | if ((err = i2c_attach_client(client))) | ||
752 | goto exit_free; | ||
753 | |||
754 | strlcpy(id.name, name, I2C_NAME_SIZE); | ||
755 | id.driver_data = kind; | ||
756 | if ((err = f75375_probe(client, &id)) < 0) | ||
757 | goto exit_detach; | ||
758 | 710 | ||
759 | return 0; | 711 | return 0; |
760 | |||
761 | exit_detach: | ||
762 | i2c_detach_client(client); | ||
763 | exit_free: | ||
764 | kfree(client); | ||
765 | exit: | ||
766 | return err; | ||
767 | } | 712 | } |
768 | 713 | ||
769 | static int __init sensors_f75375_init(void) | 714 | static int __init sensors_f75375_init(void) |
770 | { | 715 | { |
771 | int status; | 716 | return i2c_add_driver(&f75375_driver); |
772 | status = i2c_add_driver(&f75375_driver); | ||
773 | if (status) | ||
774 | return status; | ||
775 | |||
776 | status = i2c_add_driver(&f75375_legacy_driver); | ||
777 | if (status) | ||
778 | i2c_del_driver(&f75375_driver); | ||
779 | |||
780 | return status; | ||
781 | } | 717 | } |
782 | 718 | ||
783 | static void __exit sensors_f75375_exit(void) | 719 | static void __exit sensors_f75375_exit(void) |
784 | { | 720 | { |
785 | i2c_del_driver(&f75375_legacy_driver); | ||
786 | i2c_del_driver(&f75375_driver); | 721 | i2c_del_driver(&f75375_driver); |
787 | } | 722 | } |
788 | 723 | ||
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c index ed26b66e0831..12c70e402cb2 100644 --- a/drivers/hwmon/fscher.c +++ b/drivers/hwmon/fscher.c | |||
@@ -106,9 +106,11 @@ I2C_CLIENT_INSMOD_1(fscher); | |||
106 | * Functions declaration | 106 | * Functions declaration |
107 | */ | 107 | */ |
108 | 108 | ||
109 | static int fscher_attach_adapter(struct i2c_adapter *adapter); | 109 | static int fscher_probe(struct i2c_client *client, |
110 | static int fscher_detect(struct i2c_adapter *adapter, int address, int kind); | 110 | const struct i2c_device_id *id); |
111 | static int fscher_detach_client(struct i2c_client *client); | 111 | static int fscher_detect(struct i2c_client *client, int kind, |
112 | struct i2c_board_info *info); | ||
113 | static int fscher_remove(struct i2c_client *client); | ||
112 | static struct fscher_data *fscher_update_device(struct device *dev); | 114 | static struct fscher_data *fscher_update_device(struct device *dev); |
113 | static void fscher_init_client(struct i2c_client *client); | 115 | static void fscher_init_client(struct i2c_client *client); |
114 | 116 | ||
@@ -119,12 +121,21 @@ static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value); | |||
119 | * Driver data (common to all clients) | 121 | * Driver data (common to all clients) |
120 | */ | 122 | */ |
121 | 123 | ||
124 | static const struct i2c_device_id fscher_id[] = { | ||
125 | { "fscher", fscher }, | ||
126 | { } | ||
127 | }; | ||
128 | |||
122 | static struct i2c_driver fscher_driver = { | 129 | static struct i2c_driver fscher_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
123 | .driver = { | 131 | .driver = { |
124 | .name = "fscher", | 132 | .name = "fscher", |
125 | }, | 133 | }, |
126 | .attach_adapter = fscher_attach_adapter, | 134 | .probe = fscher_probe, |
127 | .detach_client = fscher_detach_client, | 135 | .remove = fscher_remove, |
136 | .id_table = fscher_id, | ||
137 | .detect = fscher_detect, | ||
138 | .address_data = &addr_data, | ||
128 | }; | 139 | }; |
129 | 140 | ||
130 | /* | 141 | /* |
@@ -132,7 +143,6 @@ static struct i2c_driver fscher_driver = { | |||
132 | */ | 143 | */ |
133 | 144 | ||
134 | struct fscher_data { | 145 | struct fscher_data { |
135 | struct i2c_client client; | ||
136 | struct device *hwmon_dev; | 146 | struct device *hwmon_dev; |
137 | struct mutex update_lock; | 147 | struct mutex update_lock; |
138 | char valid; /* zero until following fields are valid */ | 148 | char valid; /* zero until following fields are valid */ |
@@ -283,38 +293,14 @@ static const struct attribute_group fscher_group = { | |||
283 | * Real code | 293 | * Real code |
284 | */ | 294 | */ |
285 | 295 | ||
286 | static int fscher_attach_adapter(struct i2c_adapter *adapter) | 296 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
287 | { | 297 | static int fscher_detect(struct i2c_client *new_client, int kind, |
288 | if (!(adapter->class & I2C_CLASS_HWMON)) | 298 | struct i2c_board_info *info) |
289 | return 0; | ||
290 | return i2c_probe(adapter, &addr_data, fscher_detect); | ||
291 | } | ||
292 | |||
293 | static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | ||
294 | { | 299 | { |
295 | struct i2c_client *new_client; | 300 | struct i2c_adapter *adapter = new_client->adapter; |
296 | struct fscher_data *data; | ||
297 | int err = 0; | ||
298 | 301 | ||
299 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 302 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
300 | goto exit; | 303 | return -ENODEV; |
301 | |||
302 | /* OK. For now, we presume we have a valid client. We now create the | ||
303 | * client structure, even though we cannot fill it completely yet. | ||
304 | * But it allows us to access i2c_smbus_read_byte_data. */ | ||
305 | if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) { | ||
306 | err = -ENOMEM; | ||
307 | goto exit; | ||
308 | } | ||
309 | |||
310 | /* The common I2C client data is placed right before the | ||
311 | * Hermes-specific data. */ | ||
312 | new_client = &data->client; | ||
313 | i2c_set_clientdata(new_client, data); | ||
314 | new_client->addr = address; | ||
315 | new_client->adapter = adapter; | ||
316 | new_client->driver = &fscher_driver; | ||
317 | new_client->flags = 0; | ||
318 | 304 | ||
319 | /* Do the remaining detection unless force or force_fscher parameter */ | 305 | /* Do the remaining detection unless force or force_fscher parameter */ |
320 | if (kind < 0) { | 306 | if (kind < 0) { |
@@ -324,24 +310,35 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
324 | FSCHER_REG_IDENT_1) != 0x45) /* 'E' */ | 310 | FSCHER_REG_IDENT_1) != 0x45) /* 'E' */ |
325 | || (i2c_smbus_read_byte_data(new_client, | 311 | || (i2c_smbus_read_byte_data(new_client, |
326 | FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */ | 312 | FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */ |
327 | goto exit_free; | 313 | return -ENODEV; |
314 | } | ||
315 | |||
316 | strlcpy(info->type, "fscher", I2C_NAME_SIZE); | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | static int fscher_probe(struct i2c_client *new_client, | ||
322 | const struct i2c_device_id *id) | ||
323 | { | ||
324 | struct fscher_data *data; | ||
325 | int err; | ||
326 | |||
327 | data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL); | ||
328 | if (!data) { | ||
329 | err = -ENOMEM; | ||
330 | goto exit; | ||
328 | } | 331 | } |
329 | 332 | ||
330 | /* Fill in the remaining client fields and put it into the | 333 | i2c_set_clientdata(new_client, data); |
331 | * global list */ | ||
332 | strlcpy(new_client->name, "fscher", I2C_NAME_SIZE); | ||
333 | data->valid = 0; | 334 | data->valid = 0; |
334 | mutex_init(&data->update_lock); | 335 | mutex_init(&data->update_lock); |
335 | 336 | ||
336 | /* Tell the I2C layer a new client has arrived */ | ||
337 | if ((err = i2c_attach_client(new_client))) | ||
338 | goto exit_free; | ||
339 | |||
340 | fscher_init_client(new_client); | 337 | fscher_init_client(new_client); |
341 | 338 | ||
342 | /* Register sysfs hooks */ | 339 | /* Register sysfs hooks */ |
343 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group))) | 340 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group))) |
344 | goto exit_detach; | 341 | goto exit_free; |
345 | 342 | ||
346 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 343 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
347 | if (IS_ERR(data->hwmon_dev)) { | 344 | if (IS_ERR(data->hwmon_dev)) { |
@@ -353,25 +350,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
353 | 350 | ||
354 | exit_remove_files: | 351 | exit_remove_files: |
355 | sysfs_remove_group(&new_client->dev.kobj, &fscher_group); | 352 | sysfs_remove_group(&new_client->dev.kobj, &fscher_group); |
356 | exit_detach: | ||
357 | i2c_detach_client(new_client); | ||
358 | exit_free: | 353 | exit_free: |
359 | kfree(data); | 354 | kfree(data); |
360 | exit: | 355 | exit: |
361 | return err; | 356 | return err; |
362 | } | 357 | } |
363 | 358 | ||
364 | static int fscher_detach_client(struct i2c_client *client) | 359 | static int fscher_remove(struct i2c_client *client) |
365 | { | 360 | { |
366 | struct fscher_data *data = i2c_get_clientdata(client); | 361 | struct fscher_data *data = i2c_get_clientdata(client); |
367 | int err; | ||
368 | 362 | ||
369 | hwmon_device_unregister(data->hwmon_dev); | 363 | hwmon_device_unregister(data->hwmon_dev); |
370 | sysfs_remove_group(&client->dev.kobj, &fscher_group); | 364 | sysfs_remove_group(&client->dev.kobj, &fscher_group); |
371 | 365 | ||
372 | if ((err = i2c_detach_client(client))) | ||
373 | return err; | ||
374 | |||
375 | kfree(data); | 366 | kfree(data); |
376 | return 0; | 367 | return 0; |
377 | } | 368 | } |
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index bd89d270a5ed..967170368933 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c | |||
@@ -171,20 +171,37 @@ static const int FSCHMD_NO_TEMP_SENSORS[5] = { 3, 3, 4, 3, 5 }; | |||
171 | * Functions declarations | 171 | * Functions declarations |
172 | */ | 172 | */ |
173 | 173 | ||
174 | static int fschmd_attach_adapter(struct i2c_adapter *adapter); | 174 | static int fschmd_probe(struct i2c_client *client, |
175 | static int fschmd_detach_client(struct i2c_client *client); | 175 | const struct i2c_device_id *id); |
176 | static int fschmd_detect(struct i2c_client *client, int kind, | ||
177 | struct i2c_board_info *info); | ||
178 | static int fschmd_remove(struct i2c_client *client); | ||
176 | static struct fschmd_data *fschmd_update_device(struct device *dev); | 179 | static struct fschmd_data *fschmd_update_device(struct device *dev); |
177 | 180 | ||
178 | /* | 181 | /* |
179 | * Driver data (common to all clients) | 182 | * Driver data (common to all clients) |
180 | */ | 183 | */ |
181 | 184 | ||
185 | static const struct i2c_device_id fschmd_id[] = { | ||
186 | { "fscpos", fscpos }, | ||
187 | { "fscher", fscher }, | ||
188 | { "fscscy", fscscy }, | ||
189 | { "fschrc", fschrc }, | ||
190 | { "fschmd", fschmd }, | ||
191 | { } | ||
192 | }; | ||
193 | MODULE_DEVICE_TABLE(i2c, fschmd_id); | ||
194 | |||
182 | static struct i2c_driver fschmd_driver = { | 195 | static struct i2c_driver fschmd_driver = { |
196 | .class = I2C_CLASS_HWMON, | ||
183 | .driver = { | 197 | .driver = { |
184 | .name = FSCHMD_NAME, | 198 | .name = FSCHMD_NAME, |
185 | }, | 199 | }, |
186 | .attach_adapter = fschmd_attach_adapter, | 200 | .probe = fschmd_probe, |
187 | .detach_client = fschmd_detach_client, | 201 | .remove = fschmd_remove, |
202 | .id_table = fschmd_id, | ||
203 | .detect = fschmd_detect, | ||
204 | .address_data = &addr_data, | ||
188 | }; | 205 | }; |
189 | 206 | ||
190 | /* | 207 | /* |
@@ -192,7 +209,6 @@ static struct i2c_driver fschmd_driver = { | |||
192 | */ | 209 | */ |
193 | 210 | ||
194 | struct fschmd_data { | 211 | struct fschmd_data { |
195 | struct i2c_client client; | ||
196 | struct device *hwmon_dev; | 212 | struct device *hwmon_dev; |
197 | struct mutex update_lock; | 213 | struct mutex update_lock; |
198 | int kind; | 214 | int kind; |
@@ -269,7 +285,7 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
269 | v = SENSORS_LIMIT(v, -128, 127) + 128; | 285 | v = SENSORS_LIMIT(v, -128, 127) + 128; |
270 | 286 | ||
271 | mutex_lock(&data->update_lock); | 287 | mutex_lock(&data->update_lock); |
272 | i2c_smbus_write_byte_data(&data->client, | 288 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
273 | FSCHMD_REG_TEMP_LIMIT[data->kind][index], v); | 289 | FSCHMD_REG_TEMP_LIMIT[data->kind][index], v); |
274 | data->temp_max[index] = v; | 290 | data->temp_max[index] = v; |
275 | mutex_unlock(&data->update_lock); | 291 | mutex_unlock(&data->update_lock); |
@@ -346,14 +362,14 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute | |||
346 | 362 | ||
347 | mutex_lock(&data->update_lock); | 363 | mutex_lock(&data->update_lock); |
348 | 364 | ||
349 | reg = i2c_smbus_read_byte_data(&data->client, | 365 | reg = i2c_smbus_read_byte_data(to_i2c_client(dev), |
350 | FSCHMD_REG_FAN_RIPPLE[data->kind][index]); | 366 | FSCHMD_REG_FAN_RIPPLE[data->kind][index]); |
351 | 367 | ||
352 | /* bits 2..7 reserved => mask with 0x03 */ | 368 | /* bits 2..7 reserved => mask with 0x03 */ |
353 | reg &= ~0x03; | 369 | reg &= ~0x03; |
354 | reg |= v; | 370 | reg |= v; |
355 | 371 | ||
356 | i2c_smbus_write_byte_data(&data->client, | 372 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
357 | FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg); | 373 | FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg); |
358 | 374 | ||
359 | data->fan_ripple[index] = reg; | 375 | data->fan_ripple[index] = reg; |
@@ -416,7 +432,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev, | |||
416 | 432 | ||
417 | mutex_lock(&data->update_lock); | 433 | mutex_lock(&data->update_lock); |
418 | 434 | ||
419 | i2c_smbus_write_byte_data(&data->client, | 435 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
420 | FSCHMD_REG_FAN_MIN[data->kind][index], v); | 436 | FSCHMD_REG_FAN_MIN[data->kind][index], v); |
421 | data->fan_min[index] = v; | 437 | data->fan_min[index] = v; |
422 | 438 | ||
@@ -448,14 +464,14 @@ static ssize_t store_alert_led(struct device *dev, | |||
448 | 464 | ||
449 | mutex_lock(&data->update_lock); | 465 | mutex_lock(&data->update_lock); |
450 | 466 | ||
451 | reg = i2c_smbus_read_byte_data(&data->client, FSCHMD_REG_CONTROL); | 467 | reg = i2c_smbus_read_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL); |
452 | 468 | ||
453 | if (v) | 469 | if (v) |
454 | reg |= FSCHMD_CONTROL_ALERT_LED_MASK; | 470 | reg |= FSCHMD_CONTROL_ALERT_LED_MASK; |
455 | else | 471 | else |
456 | reg &= ~FSCHMD_CONTROL_ALERT_LED_MASK; | 472 | reg &= ~FSCHMD_CONTROL_ALERT_LED_MASK; |
457 | 473 | ||
458 | i2c_smbus_write_byte_data(&data->client, FSCHMD_REG_CONTROL, reg); | 474 | i2c_smbus_write_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL, reg); |
459 | 475 | ||
460 | data->global_control = reg; | 476 | data->global_control = reg; |
461 | 477 | ||
@@ -600,32 +616,15 @@ static void fschmd_dmi_decode(const struct dmi_header *header) | |||
600 | } | 616 | } |
601 | } | 617 | } |
602 | 618 | ||
603 | static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | 619 | static int fschmd_detect(struct i2c_client *client, int kind, |
620 | struct i2c_board_info *info) | ||
604 | { | 621 | { |
605 | struct i2c_client *client; | 622 | struct i2c_adapter *adapter = client->adapter; |
606 | struct fschmd_data *data; | ||
607 | u8 revision; | ||
608 | const char * const names[5] = { "Poseidon", "Hermes", "Scylla", | ||
609 | "Heracles", "Heimdall" }; | ||
610 | const char * const client_names[5] = { "fscpos", "fscher", "fscscy", | 623 | const char * const client_names[5] = { "fscpos", "fscher", "fscscy", |
611 | "fschrc", "fschmd" }; | 624 | "fschrc", "fschmd" }; |
612 | int i, err = 0; | ||
613 | 625 | ||
614 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 626 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
615 | return 0; | 627 | return -ENODEV; |
616 | |||
617 | /* OK. For now, we presume we have a valid client. We now create the | ||
618 | * client structure, even though we cannot fill it completely yet. | ||
619 | * But it allows us to access i2c_smbus_read_byte_data. */ | ||
620 | if (!(data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL))) | ||
621 | return -ENOMEM; | ||
622 | |||
623 | client = &data->client; | ||
624 | i2c_set_clientdata(client, data); | ||
625 | client->addr = address; | ||
626 | client->adapter = adapter; | ||
627 | client->driver = &fschmd_driver; | ||
628 | mutex_init(&data->update_lock); | ||
629 | 628 | ||
630 | /* Detect & Identify the chip */ | 629 | /* Detect & Identify the chip */ |
631 | if (kind <= 0) { | 630 | if (kind <= 0) { |
@@ -650,9 +649,31 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
650 | else if (!strcmp(id, "HMD")) | 649 | else if (!strcmp(id, "HMD")) |
651 | kind = fschmd; | 650 | kind = fschmd; |
652 | else | 651 | else |
653 | goto exit_free; | 652 | return -ENODEV; |
654 | } | 653 | } |
655 | 654 | ||
655 | strlcpy(info->type, client_names[kind - 1], I2C_NAME_SIZE); | ||
656 | |||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static int fschmd_probe(struct i2c_client *client, | ||
661 | const struct i2c_device_id *id) | ||
662 | { | ||
663 | struct fschmd_data *data; | ||
664 | u8 revision; | ||
665 | const char * const names[5] = { "Poseidon", "Hermes", "Scylla", | ||
666 | "Heracles", "Heimdall" }; | ||
667 | int i, err; | ||
668 | enum chips kind = id->driver_data; | ||
669 | |||
670 | data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL); | ||
671 | if (!data) | ||
672 | return -ENOMEM; | ||
673 | |||
674 | i2c_set_clientdata(client, data); | ||
675 | mutex_init(&data->update_lock); | ||
676 | |||
656 | if (kind == fscpos) { | 677 | if (kind == fscpos) { |
657 | /* The Poseidon has hardwired temp limits, fill these | 678 | /* The Poseidon has hardwired temp limits, fill these |
658 | in for the alarm resetting code */ | 679 | in for the alarm resetting code */ |
@@ -674,11 +695,6 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
674 | 695 | ||
675 | /* i2c kind goes from 1-5, we want from 0-4 to address arrays */ | 696 | /* i2c kind goes from 1-5, we want from 0-4 to address arrays */ |
676 | data->kind = kind - 1; | 697 | data->kind = kind - 1; |
677 | strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE); | ||
678 | |||
679 | /* Tell the I2C layer a new client has arrived */ | ||
680 | if ((err = i2c_attach_client(client))) | ||
681 | goto exit_free; | ||
682 | 698 | ||
683 | for (i = 0; i < ARRAY_SIZE(fschmd_attr); i++) { | 699 | for (i = 0; i < ARRAY_SIZE(fschmd_attr); i++) { |
684 | err = device_create_file(&client->dev, | 700 | err = device_create_file(&client->dev, |
@@ -726,25 +742,14 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) | |||
726 | return 0; | 742 | return 0; |
727 | 743 | ||
728 | exit_detach: | 744 | exit_detach: |
729 | fschmd_detach_client(client); /* will also free data for us */ | 745 | fschmd_remove(client); /* will also free data for us */ |
730 | return err; | ||
731 | |||
732 | exit_free: | ||
733 | kfree(data); | ||
734 | return err; | 746 | return err; |
735 | } | 747 | } |
736 | 748 | ||
737 | static int fschmd_attach_adapter(struct i2c_adapter *adapter) | 749 | static int fschmd_remove(struct i2c_client *client) |
738 | { | ||
739 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
740 | return 0; | ||
741 | return i2c_probe(adapter, &addr_data, fschmd_detect); | ||
742 | } | ||
743 | |||
744 | static int fschmd_detach_client(struct i2c_client *client) | ||
745 | { | 750 | { |
746 | struct fschmd_data *data = i2c_get_clientdata(client); | 751 | struct fschmd_data *data = i2c_get_clientdata(client); |
747 | int i, err; | 752 | int i; |
748 | 753 | ||
749 | /* Check if registered in case we're called from fschmd_detect | 754 | /* Check if registered in case we're called from fschmd_detect |
750 | to cleanup after an error */ | 755 | to cleanup after an error */ |
@@ -760,9 +765,6 @@ static int fschmd_detach_client(struct i2c_client *client) | |||
760 | device_remove_file(&client->dev, | 765 | device_remove_file(&client->dev, |
761 | &fschmd_fan_attr[i].dev_attr); | 766 | &fschmd_fan_attr[i].dev_attr); |
762 | 767 | ||
763 | if ((err = i2c_detach_client(client))) | ||
764 | return err; | ||
765 | |||
766 | kfree(data); | 768 | kfree(data); |
767 | return 0; | 769 | return 0; |
768 | } | 770 | } |
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c index 00f48484e54b..8a7bcf500b4e 100644 --- a/drivers/hwmon/fscpos.c +++ b/drivers/hwmon/fscpos.c | |||
@@ -87,9 +87,11 @@ static u8 FSCPOS_REG_TEMP_STATE[] = { 0x71, 0x81, 0x91 }; | |||
87 | /* | 87 | /* |
88 | * Functions declaration | 88 | * Functions declaration |
89 | */ | 89 | */ |
90 | static int fscpos_attach_adapter(struct i2c_adapter *adapter); | 90 | static int fscpos_probe(struct i2c_client *client, |
91 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); | 91 | const struct i2c_device_id *id); |
92 | static int fscpos_detach_client(struct i2c_client *client); | 92 | static int fscpos_detect(struct i2c_client *client, int kind, |
93 | struct i2c_board_info *info); | ||
94 | static int fscpos_remove(struct i2c_client *client); | ||
93 | 95 | ||
94 | static int fscpos_read_value(struct i2c_client *client, u8 reg); | 96 | static int fscpos_read_value(struct i2c_client *client, u8 reg); |
95 | static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); | 97 | static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); |
@@ -101,19 +103,27 @@ static void reset_fan_alarm(struct i2c_client *client, int nr); | |||
101 | /* | 103 | /* |
102 | * Driver data (common to all clients) | 104 | * Driver data (common to all clients) |
103 | */ | 105 | */ |
106 | static const struct i2c_device_id fscpos_id[] = { | ||
107 | { "fscpos", fscpos }, | ||
108 | { } | ||
109 | }; | ||
110 | |||
104 | static struct i2c_driver fscpos_driver = { | 111 | static struct i2c_driver fscpos_driver = { |
112 | .class = I2C_CLASS_HWMON, | ||
105 | .driver = { | 113 | .driver = { |
106 | .name = "fscpos", | 114 | .name = "fscpos", |
107 | }, | 115 | }, |
108 | .attach_adapter = fscpos_attach_adapter, | 116 | .probe = fscpos_probe, |
109 | .detach_client = fscpos_detach_client, | 117 | .remove = fscpos_remove, |
118 | .id_table = fscpos_id, | ||
119 | .detect = fscpos_detect, | ||
120 | .address_data = &addr_data, | ||
110 | }; | 121 | }; |
111 | 122 | ||
112 | /* | 123 | /* |
113 | * Client data (each client gets its own) | 124 | * Client data (each client gets its own) |
114 | */ | 125 | */ |
115 | struct fscpos_data { | 126 | struct fscpos_data { |
116 | struct i2c_client client; | ||
117 | struct device *hwmon_dev; | 127 | struct device *hwmon_dev; |
118 | struct mutex update_lock; | 128 | struct mutex update_lock; |
119 | char valid; /* 0 until following fields are valid */ | 129 | char valid; /* 0 until following fields are valid */ |
@@ -470,39 +480,14 @@ static const struct attribute_group fscpos_group = { | |||
470 | .attrs = fscpos_attributes, | 480 | .attrs = fscpos_attributes, |
471 | }; | 481 | }; |
472 | 482 | ||
473 | static int fscpos_attach_adapter(struct i2c_adapter *adapter) | 483 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
474 | { | 484 | static int fscpos_detect(struct i2c_client *new_client, int kind, |
475 | if (!(adapter->class & I2C_CLASS_HWMON)) | 485 | struct i2c_board_info *info) |
476 | return 0; | ||
477 | return i2c_probe(adapter, &addr_data, fscpos_detect); | ||
478 | } | ||
479 | |||
480 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | ||
481 | { | 486 | { |
482 | struct i2c_client *new_client; | 487 | struct i2c_adapter *adapter = new_client->adapter; |
483 | struct fscpos_data *data; | ||
484 | int err = 0; | ||
485 | 488 | ||
486 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 489 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
487 | goto exit; | 490 | return -ENODEV; |
488 | |||
489 | /* | ||
490 | * OK. For now, we presume we have a valid client. We now create the | ||
491 | * client structure, even though we cannot fill it completely yet. | ||
492 | * But it allows us to access fscpos_{read,write}_value. | ||
493 | */ | ||
494 | |||
495 | if (!(data = kzalloc(sizeof(struct fscpos_data), GFP_KERNEL))) { | ||
496 | err = -ENOMEM; | ||
497 | goto exit; | ||
498 | } | ||
499 | |||
500 | new_client = &data->client; | ||
501 | i2c_set_clientdata(new_client, data); | ||
502 | new_client->addr = address; | ||
503 | new_client->adapter = adapter; | ||
504 | new_client->driver = &fscpos_driver; | ||
505 | new_client->flags = 0; | ||
506 | 491 | ||
507 | /* Do the remaining detection unless force or force_fscpos parameter */ | 492 | /* Do the remaining detection unless force or force_fscpos parameter */ |
508 | if (kind < 0) { | 493 | if (kind < 0) { |
@@ -512,22 +497,30 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
512 | != 0x45) /* 'E' */ | 497 | != 0x45) /* 'E' */ |
513 | || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_2) | 498 | || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_2) |
514 | != 0x47))/* 'G' */ | 499 | != 0x47))/* 'G' */ |
515 | { | 500 | return -ENODEV; |
516 | dev_dbg(&new_client->dev, "fscpos detection failed\n"); | ||
517 | goto exit_free; | ||
518 | } | ||
519 | } | 501 | } |
520 | 502 | ||
521 | /* Fill in the remaining client fields and put it in the global list */ | 503 | strlcpy(info->type, "fscpos", I2C_NAME_SIZE); |
522 | strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); | ||
523 | 504 | ||
505 | return 0; | ||
506 | } | ||
507 | |||
508 | static int fscpos_probe(struct i2c_client *new_client, | ||
509 | const struct i2c_device_id *id) | ||
510 | { | ||
511 | struct fscpos_data *data; | ||
512 | int err; | ||
513 | |||
514 | data = kzalloc(sizeof(struct fscpos_data), GFP_KERNEL); | ||
515 | if (!data) { | ||
516 | err = -ENOMEM; | ||
517 | goto exit; | ||
518 | } | ||
519 | |||
520 | i2c_set_clientdata(new_client, data); | ||
524 | data->valid = 0; | 521 | data->valid = 0; |
525 | mutex_init(&data->update_lock); | 522 | mutex_init(&data->update_lock); |
526 | 523 | ||
527 | /* Tell the I2C layer a new client has arrived */ | ||
528 | if ((err = i2c_attach_client(new_client))) | ||
529 | goto exit_free; | ||
530 | |||
531 | /* Inizialize the fscpos chip */ | 524 | /* Inizialize the fscpos chip */ |
532 | fscpos_init_client(new_client); | 525 | fscpos_init_client(new_client); |
533 | 526 | ||
@@ -536,7 +529,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
536 | 529 | ||
537 | /* Register sysfs hooks */ | 530 | /* Register sysfs hooks */ |
538 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group))) | 531 | if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group))) |
539 | goto exit_detach; | 532 | goto exit_free; |
540 | 533 | ||
541 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 534 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
542 | if (IS_ERR(data->hwmon_dev)) { | 535 | if (IS_ERR(data->hwmon_dev)) { |
@@ -548,24 +541,19 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
548 | 541 | ||
549 | exit_remove_files: | 542 | exit_remove_files: |
550 | sysfs_remove_group(&new_client->dev.kobj, &fscpos_group); | 543 | sysfs_remove_group(&new_client->dev.kobj, &fscpos_group); |
551 | exit_detach: | ||
552 | i2c_detach_client(new_client); | ||
553 | exit_free: | 544 | exit_free: |
554 | kfree(data); | 545 | kfree(data); |
555 | exit: | 546 | exit: |
556 | return err; | 547 | return err; |
557 | } | 548 | } |
558 | 549 | ||
559 | static int fscpos_detach_client(struct i2c_client *client) | 550 | static int fscpos_remove(struct i2c_client *client) |
560 | { | 551 | { |
561 | struct fscpos_data *data = i2c_get_clientdata(client); | 552 | struct fscpos_data *data = i2c_get_clientdata(client); |
562 | int err; | ||
563 | 553 | ||
564 | hwmon_device_unregister(data->hwmon_dev); | 554 | hwmon_device_unregister(data->hwmon_dev); |
565 | sysfs_remove_group(&client->dev.kobj, &fscpos_group); | 555 | sysfs_remove_group(&client->dev.kobj, &fscpos_group); |
566 | 556 | ||
567 | if ((err = i2c_detach_client(client))) | ||
568 | return err; | ||
569 | kfree(data); | 557 | kfree(data); |
570 | return 0; | 558 | return 0; |
571 | } | 559 | } |
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 33e9e8a8d1ce..7820df45d77a 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -114,7 +114,6 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
114 | 114 | ||
115 | /* Each client has this additional data */ | 115 | /* Each client has this additional data */ |
116 | struct gl518_data { | 116 | struct gl518_data { |
117 | struct i2c_client client; | ||
118 | struct device *hwmon_dev; | 117 | struct device *hwmon_dev; |
119 | enum chips type; | 118 | enum chips type; |
120 | 119 | ||
@@ -138,21 +137,33 @@ struct gl518_data { | |||
138 | u8 beep_enable; /* Boolean */ | 137 | u8 beep_enable; /* Boolean */ |
139 | }; | 138 | }; |
140 | 139 | ||
141 | static int gl518_attach_adapter(struct i2c_adapter *adapter); | 140 | static int gl518_probe(struct i2c_client *client, |
142 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind); | 141 | const struct i2c_device_id *id); |
142 | static int gl518_detect(struct i2c_client *client, int kind, | ||
143 | struct i2c_board_info *info); | ||
143 | static void gl518_init_client(struct i2c_client *client); | 144 | static void gl518_init_client(struct i2c_client *client); |
144 | static int gl518_detach_client(struct i2c_client *client); | 145 | static int gl518_remove(struct i2c_client *client); |
145 | static int gl518_read_value(struct i2c_client *client, u8 reg); | 146 | static int gl518_read_value(struct i2c_client *client, u8 reg); |
146 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); | 147 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); |
147 | static struct gl518_data *gl518_update_device(struct device *dev); | 148 | static struct gl518_data *gl518_update_device(struct device *dev); |
148 | 149 | ||
150 | static const struct i2c_device_id gl518_id[] = { | ||
151 | { "gl518sm", 0 }, | ||
152 | { } | ||
153 | }; | ||
154 | MODULE_DEVICE_TABLE(i2c, gl518_id); | ||
155 | |||
149 | /* This is the driver that will be inserted */ | 156 | /* This is the driver that will be inserted */ |
150 | static struct i2c_driver gl518_driver = { | 157 | static struct i2c_driver gl518_driver = { |
158 | .class = I2C_CLASS_HWMON, | ||
151 | .driver = { | 159 | .driver = { |
152 | .name = "gl518sm", | 160 | .name = "gl518sm", |
153 | }, | 161 | }, |
154 | .attach_adapter = gl518_attach_adapter, | 162 | .probe = gl518_probe, |
155 | .detach_client = gl518_detach_client, | 163 | .remove = gl518_remove, |
164 | .id_table = gl518_id, | ||
165 | .detect = gl518_detect, | ||
166 | .address_data = &addr_data, | ||
156 | }; | 167 | }; |
157 | 168 | ||
158 | /* | 169 | /* |
@@ -472,46 +483,23 @@ static const struct attribute_group gl518_group_r80 = { | |||
472 | * Real code | 483 | * Real code |
473 | */ | 484 | */ |
474 | 485 | ||
475 | static int gl518_attach_adapter(struct i2c_adapter *adapter) | 486 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
476 | { | 487 | static int gl518_detect(struct i2c_client *client, int kind, |
477 | if (!(adapter->class & I2C_CLASS_HWMON)) | 488 | struct i2c_board_info *info) |
478 | return 0; | ||
479 | return i2c_probe(adapter, &addr_data, gl518_detect); | ||
480 | } | ||
481 | |||
482 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | ||
483 | { | 489 | { |
490 | struct i2c_adapter *adapter = client->adapter; | ||
484 | int i; | 491 | int i; |
485 | struct i2c_client *client; | ||
486 | struct gl518_data *data; | ||
487 | int err = 0; | ||
488 | 492 | ||
489 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
490 | I2C_FUNC_SMBUS_WORD_DATA)) | 494 | I2C_FUNC_SMBUS_WORD_DATA)) |
491 | goto exit; | 495 | return -ENODEV; |
492 | |||
493 | /* OK. For now, we presume we have a valid client. We now create the | ||
494 | client structure, even though we cannot fill it completely yet. | ||
495 | But it allows us to access gl518_{read,write}_value. */ | ||
496 | |||
497 | if (!(data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL))) { | ||
498 | err = -ENOMEM; | ||
499 | goto exit; | ||
500 | } | ||
501 | |||
502 | client = &data->client; | ||
503 | i2c_set_clientdata(client, data); | ||
504 | |||
505 | client->addr = address; | ||
506 | client->adapter = adapter; | ||
507 | client->driver = &gl518_driver; | ||
508 | 496 | ||
509 | /* Now, we do the remaining detection. */ | 497 | /* Now, we do the remaining detection. */ |
510 | 498 | ||
511 | if (kind < 0) { | 499 | if (kind < 0) { |
512 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) | 500 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) |
513 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) | 501 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) |
514 | goto exit_free; | 502 | return -ENODEV; |
515 | } | 503 | } |
516 | 504 | ||
517 | /* Determine the chip type. */ | 505 | /* Determine the chip type. */ |
@@ -526,19 +514,32 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
526 | dev_info(&adapter->dev, | 514 | dev_info(&adapter->dev, |
527 | "Ignoring 'force' parameter for unknown " | 515 | "Ignoring 'force' parameter for unknown " |
528 | "chip at adapter %d, address 0x%02x\n", | 516 | "chip at adapter %d, address 0x%02x\n", |
529 | i2c_adapter_id(adapter), address); | 517 | i2c_adapter_id(adapter), client->addr); |
530 | goto exit_free; | 518 | return -ENODEV; |
531 | } | 519 | } |
532 | } | 520 | } |
533 | 521 | ||
534 | /* Fill in the remaining client fields */ | 522 | strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); |
535 | strlcpy(client->name, "gl518sm", I2C_NAME_SIZE); | ||
536 | data->type = kind; | ||
537 | mutex_init(&data->update_lock); | ||
538 | 523 | ||
539 | /* Tell the I2C layer a new client has arrived */ | 524 | return 0; |
540 | if ((err = i2c_attach_client(client))) | 525 | } |
541 | goto exit_free; | 526 | |
527 | static int gl518_probe(struct i2c_client *client, | ||
528 | const struct i2c_device_id *id) | ||
529 | { | ||
530 | struct gl518_data *data; | ||
531 | int err, revision; | ||
532 | |||
533 | data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL); | ||
534 | if (!data) { | ||
535 | err = -ENOMEM; | ||
536 | goto exit; | ||
537 | } | ||
538 | |||
539 | i2c_set_clientdata(client, data); | ||
540 | revision = gl518_read_value(client, GL518_REG_REVISION); | ||
541 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; | ||
542 | mutex_init(&data->update_lock); | ||
542 | 543 | ||
543 | /* Initialize the GL518SM chip */ | 544 | /* Initialize the GL518SM chip */ |
544 | data->alarm_mask = 0xff; | 545 | data->alarm_mask = 0xff; |
@@ -546,7 +547,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
546 | 547 | ||
547 | /* Register sysfs hooks */ | 548 | /* Register sysfs hooks */ |
548 | if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) | 549 | if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) |
549 | goto exit_detach; | 550 | goto exit_free; |
550 | if (data->type == gl518sm_r80) | 551 | if (data->type == gl518sm_r80) |
551 | if ((err = sysfs_create_group(&client->dev.kobj, | 552 | if ((err = sysfs_create_group(&client->dev.kobj, |
552 | &gl518_group_r80))) | 553 | &gl518_group_r80))) |
@@ -564,8 +565,6 @@ exit_remove_files: | |||
564 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | 565 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
565 | if (data->type == gl518sm_r80) | 566 | if (data->type == gl518sm_r80) |
566 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | 567 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); |
567 | exit_detach: | ||
568 | i2c_detach_client(client); | ||
569 | exit_free: | 568 | exit_free: |
570 | kfree(data); | 569 | kfree(data); |
571 | exit: | 570 | exit: |
@@ -591,19 +590,15 @@ static void gl518_init_client(struct i2c_client *client) | |||
591 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); | 590 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); |
592 | } | 591 | } |
593 | 592 | ||
594 | static int gl518_detach_client(struct i2c_client *client) | 593 | static int gl518_remove(struct i2c_client *client) |
595 | { | 594 | { |
596 | struct gl518_data *data = i2c_get_clientdata(client); | 595 | struct gl518_data *data = i2c_get_clientdata(client); |
597 | int err; | ||
598 | 596 | ||
599 | hwmon_device_unregister(data->hwmon_dev); | 597 | hwmon_device_unregister(data->hwmon_dev); |
600 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | 598 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
601 | if (data->type == gl518sm_r80) | 599 | if (data->type == gl518sm_r80) |
602 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | 600 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); |
603 | 601 | ||
604 | if ((err = i2c_detach_client(client))) | ||
605 | return err; | ||
606 | |||
607 | kfree(data); | 602 | kfree(data); |
608 | return 0; | 603 | return 0; |
609 | } | 604 | } |
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 8984ef141627..19616f2242b0 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -79,26 +79,37 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 }; | |||
79 | * Function declarations | 79 | * Function declarations |
80 | */ | 80 | */ |
81 | 81 | ||
82 | static int gl520_attach_adapter(struct i2c_adapter *adapter); | 82 | static int gl520_probe(struct i2c_client *client, |
83 | static int gl520_detect(struct i2c_adapter *adapter, int address, int kind); | 83 | const struct i2c_device_id *id); |
84 | static int gl520_detect(struct i2c_client *client, int kind, | ||
85 | struct i2c_board_info *info); | ||
84 | static void gl520_init_client(struct i2c_client *client); | 86 | static void gl520_init_client(struct i2c_client *client); |
85 | static int gl520_detach_client(struct i2c_client *client); | 87 | static int gl520_remove(struct i2c_client *client); |
86 | static int gl520_read_value(struct i2c_client *client, u8 reg); | 88 | static int gl520_read_value(struct i2c_client *client, u8 reg); |
87 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); | 89 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); |
88 | static struct gl520_data *gl520_update_device(struct device *dev); | 90 | static struct gl520_data *gl520_update_device(struct device *dev); |
89 | 91 | ||
90 | /* Driver data */ | 92 | /* Driver data */ |
93 | static const struct i2c_device_id gl520_id[] = { | ||
94 | { "gl520sm", gl520sm }, | ||
95 | { } | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(i2c, gl520_id); | ||
98 | |||
91 | static struct i2c_driver gl520_driver = { | 99 | static struct i2c_driver gl520_driver = { |
100 | .class = I2C_CLASS_HWMON, | ||
92 | .driver = { | 101 | .driver = { |
93 | .name = "gl520sm", | 102 | .name = "gl520sm", |
94 | }, | 103 | }, |
95 | .attach_adapter = gl520_attach_adapter, | 104 | .probe = gl520_probe, |
96 | .detach_client = gl520_detach_client, | 105 | .remove = gl520_remove, |
106 | .id_table = gl520_id, | ||
107 | .detect = gl520_detect, | ||
108 | .address_data = &addr_data, | ||
97 | }; | 109 | }; |
98 | 110 | ||
99 | /* Client data */ | 111 | /* Client data */ |
100 | struct gl520_data { | 112 | struct gl520_data { |
101 | struct i2c_client client; | ||
102 | struct device *hwmon_dev; | 113 | struct device *hwmon_dev; |
103 | struct mutex update_lock; | 114 | struct mutex update_lock; |
104 | char valid; /* zero until the following fields are valid */ | 115 | char valid; /* zero until the following fields are valid */ |
@@ -669,37 +680,15 @@ static const struct attribute_group gl520_group_opt = { | |||
669 | * Real code | 680 | * Real code |
670 | */ | 681 | */ |
671 | 682 | ||
672 | static int gl520_attach_adapter(struct i2c_adapter *adapter) | 683 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
673 | { | 684 | static int gl520_detect(struct i2c_client *client, int kind, |
674 | if (!(adapter->class & I2C_CLASS_HWMON)) | 685 | struct i2c_board_info *info) |
675 | return 0; | ||
676 | return i2c_probe(adapter, &addr_data, gl520_detect); | ||
677 | } | ||
678 | |||
679 | static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | ||
680 | { | 686 | { |
681 | struct i2c_client *client; | 687 | struct i2c_adapter *adapter = client->adapter; |
682 | struct gl520_data *data; | ||
683 | int err = 0; | ||
684 | 688 | ||
685 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 689 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
686 | I2C_FUNC_SMBUS_WORD_DATA)) | 690 | I2C_FUNC_SMBUS_WORD_DATA)) |
687 | goto exit; | 691 | return -ENODEV; |
688 | |||
689 | /* OK. For now, we presume we have a valid client. We now create the | ||
690 | client structure, even though we cannot fill it completely yet. | ||
691 | But it allows us to access gl520_{read,write}_value. */ | ||
692 | |||
693 | if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) { | ||
694 | err = -ENOMEM; | ||
695 | goto exit; | ||
696 | } | ||
697 | |||
698 | client = &data->client; | ||
699 | i2c_set_clientdata(client, data); | ||
700 | client->addr = address; | ||
701 | client->adapter = adapter; | ||
702 | client->driver = &gl520_driver; | ||
703 | 692 | ||
704 | /* Determine the chip type. */ | 693 | /* Determine the chip type. */ |
705 | if (kind < 0) { | 694 | if (kind < 0) { |
@@ -707,24 +696,36 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
707 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || | 696 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || |
708 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { | 697 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { |
709 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); | 698 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); |
710 | goto exit_free; | 699 | return -ENODEV; |
711 | } | 700 | } |
712 | } | 701 | } |
713 | 702 | ||
714 | /* Fill in the remaining client fields */ | 703 | strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); |
715 | strlcpy(client->name, "gl520sm", I2C_NAME_SIZE); | ||
716 | mutex_init(&data->update_lock); | ||
717 | 704 | ||
718 | /* Tell the I2C layer a new client has arrived */ | 705 | return 0; |
719 | if ((err = i2c_attach_client(client))) | 706 | } |
720 | goto exit_free; | 707 | |
708 | static int gl520_probe(struct i2c_client *client, | ||
709 | const struct i2c_device_id *id) | ||
710 | { | ||
711 | struct gl520_data *data; | ||
712 | int err; | ||
713 | |||
714 | data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL); | ||
715 | if (!data) { | ||
716 | err = -ENOMEM; | ||
717 | goto exit; | ||
718 | } | ||
719 | |||
720 | i2c_set_clientdata(client, data); | ||
721 | mutex_init(&data->update_lock); | ||
721 | 722 | ||
722 | /* Initialize the GL520SM chip */ | 723 | /* Initialize the GL520SM chip */ |
723 | gl520_init_client(client); | 724 | gl520_init_client(client); |
724 | 725 | ||
725 | /* Register sysfs hooks */ | 726 | /* Register sysfs hooks */ |
726 | if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group))) | 727 | if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group))) |
727 | goto exit_detach; | 728 | goto exit_free; |
728 | 729 | ||
729 | if (data->two_temps) { | 730 | if (data->two_temps) { |
730 | if ((err = device_create_file(&client->dev, | 731 | if ((err = device_create_file(&client->dev, |
@@ -764,8 +765,6 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
764 | exit_remove_files: | 765 | exit_remove_files: |
765 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 766 | sysfs_remove_group(&client->dev.kobj, &gl520_group); |
766 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); | 767 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); |
767 | exit_detach: | ||
768 | i2c_detach_client(client); | ||
769 | exit_free: | 768 | exit_free: |
770 | kfree(data); | 769 | kfree(data); |
771 | exit: | 770 | exit: |
@@ -811,18 +810,14 @@ static void gl520_init_client(struct i2c_client *client) | |||
811 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | 810 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); |
812 | } | 811 | } |
813 | 812 | ||
814 | static int gl520_detach_client(struct i2c_client *client) | 813 | static int gl520_remove(struct i2c_client *client) |
815 | { | 814 | { |
816 | struct gl520_data *data = i2c_get_clientdata(client); | 815 | struct gl520_data *data = i2c_get_clientdata(client); |
817 | int err; | ||
818 | 816 | ||
819 | hwmon_device_unregister(data->hwmon_dev); | 817 | hwmon_device_unregister(data->hwmon_dev); |
820 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 818 | sysfs_remove_group(&client->dev.kobj, &gl520_group); |
821 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); | 819 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); |
822 | 820 | ||
823 | if ((err = i2c_detach_client(client))) | ||
824 | return err; | ||
825 | |||
826 | kfree(data); | 821 | kfree(data); |
827 | return 0; | 822 | return 0; |
828 | } | 823 | } |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 116287008083..3195a265f0e9 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor | 2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor |
3 | * with integrated fan control | 3 | * with integrated fan control |
4 | * Copyright (C) 2004-2006 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
5 | * Based on the lm90 driver. | 5 | * Based on the lm90 driver. |
6 | * | 6 | * |
7 | * The LM63 is a sensor chip made by National Semiconductor. It measures | 7 | * The LM63 is a sensor chip made by National Semiconductor. It measures |
@@ -128,24 +128,36 @@ I2C_CLIENT_INSMOD_1(lm63); | |||
128 | * Functions declaration | 128 | * Functions declaration |
129 | */ | 129 | */ |
130 | 130 | ||
131 | static int lm63_attach_adapter(struct i2c_adapter *adapter); | 131 | static int lm63_probe(struct i2c_client *client, |
132 | static int lm63_detach_client(struct i2c_client *client); | 132 | const struct i2c_device_id *id); |
133 | static int lm63_remove(struct i2c_client *client); | ||
133 | 134 | ||
134 | static struct lm63_data *lm63_update_device(struct device *dev); | 135 | static struct lm63_data *lm63_update_device(struct device *dev); |
135 | 136 | ||
136 | static int lm63_detect(struct i2c_adapter *adapter, int address, int kind); | 137 | static int lm63_detect(struct i2c_client *client, int kind, |
138 | struct i2c_board_info *info); | ||
137 | static void lm63_init_client(struct i2c_client *client); | 139 | static void lm63_init_client(struct i2c_client *client); |
138 | 140 | ||
139 | /* | 141 | /* |
140 | * Driver data (common to all clients) | 142 | * Driver data (common to all clients) |
141 | */ | 143 | */ |
142 | 144 | ||
145 | static const struct i2c_device_id lm63_id[] = { | ||
146 | { "lm63", lm63 }, | ||
147 | { } | ||
148 | }; | ||
149 | MODULE_DEVICE_TABLE(i2c, lm63_id); | ||
150 | |||
143 | static struct i2c_driver lm63_driver = { | 151 | static struct i2c_driver lm63_driver = { |
152 | .class = I2C_CLASS_HWMON, | ||
144 | .driver = { | 153 | .driver = { |
145 | .name = "lm63", | 154 | .name = "lm63", |
146 | }, | 155 | }, |
147 | .attach_adapter = lm63_attach_adapter, | 156 | .probe = lm63_probe, |
148 | .detach_client = lm63_detach_client, | 157 | .remove = lm63_remove, |
158 | .id_table = lm63_id, | ||
159 | .detect = lm63_detect, | ||
160 | .address_data = &addr_data, | ||
149 | }; | 161 | }; |
150 | 162 | ||
151 | /* | 163 | /* |
@@ -153,7 +165,6 @@ static struct i2c_driver lm63_driver = { | |||
153 | */ | 165 | */ |
154 | 166 | ||
155 | struct lm63_data { | 167 | struct lm63_data { |
156 | struct i2c_client client; | ||
157 | struct device *hwmon_dev; | 168 | struct device *hwmon_dev; |
158 | struct mutex update_lock; | 169 | struct mutex update_lock; |
159 | char valid; /* zero until following fields are valid */ | 170 | char valid; /* zero until following fields are valid */ |
@@ -411,43 +422,14 @@ static const struct attribute_group lm63_group_fan1 = { | |||
411 | * Real code | 422 | * Real code |
412 | */ | 423 | */ |
413 | 424 | ||
414 | static int lm63_attach_adapter(struct i2c_adapter *adapter) | 425 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
426 | static int lm63_detect(struct i2c_client *new_client, int kind, | ||
427 | struct i2c_board_info *info) | ||
415 | { | 428 | { |
416 | if (!(adapter->class & I2C_CLASS_HWMON)) | 429 | struct i2c_adapter *adapter = new_client->adapter; |
417 | return 0; | ||
418 | return i2c_probe(adapter, &addr_data, lm63_detect); | ||
419 | } | ||
420 | |||
421 | /* | ||
422 | * The following function does more than just detection. If detection | ||
423 | * succeeds, it also registers the new chip. | ||
424 | */ | ||
425 | static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | ||
426 | { | ||
427 | struct i2c_client *new_client; | ||
428 | struct lm63_data *data; | ||
429 | int err = 0; | ||
430 | 430 | ||
431 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 431 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
432 | goto exit; | 432 | return -ENODEV; |
433 | |||
434 | if (!(data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL))) { | ||
435 | err = -ENOMEM; | ||
436 | goto exit; | ||
437 | } | ||
438 | |||
439 | /* The common I2C client data is placed right before the | ||
440 | LM63-specific data. */ | ||
441 | new_client = &data->client; | ||
442 | i2c_set_clientdata(new_client, data); | ||
443 | new_client->addr = address; | ||
444 | new_client->adapter = adapter; | ||
445 | new_client->driver = &lm63_driver; | ||
446 | new_client->flags = 0; | ||
447 | |||
448 | /* Default to an LM63 if forced */ | ||
449 | if (kind == 0) | ||
450 | kind = lm63; | ||
451 | 433 | ||
452 | if (kind < 0) { /* must identify */ | 434 | if (kind < 0) { /* must identify */ |
453 | u8 man_id, chip_id, reg_config1, reg_config2; | 435 | u8 man_id, chip_id, reg_config1, reg_config2; |
@@ -477,25 +459,38 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
477 | dev_dbg(&adapter->dev, "Unsupported chip " | 459 | dev_dbg(&adapter->dev, "Unsupported chip " |
478 | "(man_id=0x%02X, chip_id=0x%02X).\n", | 460 | "(man_id=0x%02X, chip_id=0x%02X).\n", |
479 | man_id, chip_id); | 461 | man_id, chip_id); |
480 | goto exit_free; | 462 | return -ENODEV; |
481 | } | 463 | } |
482 | } | 464 | } |
483 | 465 | ||
484 | strlcpy(new_client->name, "lm63", I2C_NAME_SIZE); | 466 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static int lm63_probe(struct i2c_client *new_client, | ||
472 | const struct i2c_device_id *id) | ||
473 | { | ||
474 | struct lm63_data *data; | ||
475 | int err; | ||
476 | |||
477 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); | ||
478 | if (!data) { | ||
479 | err = -ENOMEM; | ||
480 | goto exit; | ||
481 | } | ||
482 | |||
483 | i2c_set_clientdata(new_client, data); | ||
485 | data->valid = 0; | 484 | data->valid = 0; |
486 | mutex_init(&data->update_lock); | 485 | mutex_init(&data->update_lock); |
487 | 486 | ||
488 | /* Tell the I2C layer a new client has arrived */ | ||
489 | if ((err = i2c_attach_client(new_client))) | ||
490 | goto exit_free; | ||
491 | |||
492 | /* Initialize the LM63 chip */ | 487 | /* Initialize the LM63 chip */ |
493 | lm63_init_client(new_client); | 488 | lm63_init_client(new_client); |
494 | 489 | ||
495 | /* Register sysfs hooks */ | 490 | /* Register sysfs hooks */ |
496 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 491 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
497 | &lm63_group))) | 492 | &lm63_group))) |
498 | goto exit_detach; | 493 | goto exit_free; |
499 | if (data->config & 0x04) { /* tachometer enabled */ | 494 | if (data->config & 0x04) { /* tachometer enabled */ |
500 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 495 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
501 | &lm63_group_fan1))) | 496 | &lm63_group_fan1))) |
@@ -513,8 +508,6 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
513 | exit_remove_files: | 508 | exit_remove_files: |
514 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); | 509 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
515 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); | 510 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
516 | exit_detach: | ||
517 | i2c_detach_client(new_client); | ||
518 | exit_free: | 511 | exit_free: |
519 | kfree(data); | 512 | kfree(data); |
520 | exit: | 513 | exit: |
@@ -556,18 +549,14 @@ static void lm63_init_client(struct i2c_client *client) | |||
556 | (data->config_fan & 0x20) ? "manual" : "auto"); | 549 | (data->config_fan & 0x20) ? "manual" : "auto"); |
557 | } | 550 | } |
558 | 551 | ||
559 | static int lm63_detach_client(struct i2c_client *client) | 552 | static int lm63_remove(struct i2c_client *client) |
560 | { | 553 | { |
561 | struct lm63_data *data = i2c_get_clientdata(client); | 554 | struct lm63_data *data = i2c_get_clientdata(client); |
562 | int err; | ||
563 | 555 | ||
564 | hwmon_device_unregister(data->hwmon_dev); | 556 | hwmon_device_unregister(data->hwmon_dev); |
565 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | 557 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
566 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | 558 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
567 | 559 | ||
568 | if ((err = i2c_detach_client(client))) | ||
569 | return err; | ||
570 | |||
571 | kfree(data); | 560 | kfree(data); |
572 | return 0; | 561 | return 0; |
573 | } | 562 | } |
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 36d5a8c3ad8c..866b401ab6e8 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -52,7 +52,6 @@ I2C_CLIENT_INSMOD_1(lm77); | |||
52 | 52 | ||
53 | /* Each client has this additional data */ | 53 | /* Each client has this additional data */ |
54 | struct lm77_data { | 54 | struct lm77_data { |
55 | struct i2c_client client; | ||
56 | struct device *hwmon_dev; | 55 | struct device *hwmon_dev; |
57 | struct mutex update_lock; | 56 | struct mutex update_lock; |
58 | char valid; | 57 | char valid; |
@@ -65,23 +64,35 @@ struct lm77_data { | |||
65 | u8 alarms; | 64 | u8 alarms; |
66 | }; | 65 | }; |
67 | 66 | ||
68 | static int lm77_attach_adapter(struct i2c_adapter *adapter); | 67 | static int lm77_probe(struct i2c_client *client, |
69 | static int lm77_detect(struct i2c_adapter *adapter, int address, int kind); | 68 | const struct i2c_device_id *id); |
69 | static int lm77_detect(struct i2c_client *client, int kind, | ||
70 | struct i2c_board_info *info); | ||
70 | static void lm77_init_client(struct i2c_client *client); | 71 | static void lm77_init_client(struct i2c_client *client); |
71 | static int lm77_detach_client(struct i2c_client *client); | 72 | static int lm77_remove(struct i2c_client *client); |
72 | static u16 lm77_read_value(struct i2c_client *client, u8 reg); | 73 | static u16 lm77_read_value(struct i2c_client *client, u8 reg); |
73 | static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value); | 74 | static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value); |
74 | 75 | ||
75 | static struct lm77_data *lm77_update_device(struct device *dev); | 76 | static struct lm77_data *lm77_update_device(struct device *dev); |
76 | 77 | ||
77 | 78 | ||
79 | static const struct i2c_device_id lm77_id[] = { | ||
80 | { "lm77", lm77 }, | ||
81 | { } | ||
82 | }; | ||
83 | MODULE_DEVICE_TABLE(i2c, lm77_id); | ||
84 | |||
78 | /* This is the driver that will be inserted */ | 85 | /* This is the driver that will be inserted */ |
79 | static struct i2c_driver lm77_driver = { | 86 | static struct i2c_driver lm77_driver = { |
87 | .class = I2C_CLASS_HWMON, | ||
80 | .driver = { | 88 | .driver = { |
81 | .name = "lm77", | 89 | .name = "lm77", |
82 | }, | 90 | }, |
83 | .attach_adapter = lm77_attach_adapter, | 91 | .probe = lm77_probe, |
84 | .detach_client = lm77_detach_client, | 92 | .remove = lm77_remove, |
93 | .id_table = lm77_id, | ||
94 | .detect = lm77_detect, | ||
95 | .address_data = &addr_data, | ||
85 | }; | 96 | }; |
86 | 97 | ||
87 | /* straight from the datasheet */ | 98 | /* straight from the datasheet */ |
@@ -215,13 +226,6 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); | |||
215 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 226 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
216 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); | 227 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); |
217 | 228 | ||
218 | static int lm77_attach_adapter(struct i2c_adapter *adapter) | ||
219 | { | ||
220 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
221 | return 0; | ||
222 | return i2c_probe(adapter, &addr_data, lm77_detect); | ||
223 | } | ||
224 | |||
225 | static struct attribute *lm77_attributes[] = { | 229 | static struct attribute *lm77_attributes[] = { |
226 | &dev_attr_temp1_input.attr, | 230 | &dev_attr_temp1_input.attr, |
227 | &dev_attr_temp1_crit.attr, | 231 | &dev_attr_temp1_crit.attr, |
@@ -240,32 +244,15 @@ static const struct attribute_group lm77_group = { | |||
240 | .attrs = lm77_attributes, | 244 | .attrs = lm77_attributes, |
241 | }; | 245 | }; |
242 | 246 | ||
243 | /* This function is called by i2c_probe */ | 247 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
244 | static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | 248 | static int lm77_detect(struct i2c_client *new_client, int kind, |
249 | struct i2c_board_info *info) | ||
245 | { | 250 | { |
246 | struct i2c_client *new_client; | 251 | struct i2c_adapter *adapter = new_client->adapter; |
247 | struct lm77_data *data; | ||
248 | int err = 0; | ||
249 | const char *name = ""; | ||
250 | 252 | ||
251 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 253 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
252 | I2C_FUNC_SMBUS_WORD_DATA)) | 254 | I2C_FUNC_SMBUS_WORD_DATA)) |
253 | goto exit; | 255 | return -ENODEV; |
254 | |||
255 | /* OK. For now, we presume we have a valid client. We now create the | ||
256 | client structure, even though we cannot fill it completely yet. | ||
257 | But it allows us to access lm77_{read,write}_value. */ | ||
258 | if (!(data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL))) { | ||
259 | err = -ENOMEM; | ||
260 | goto exit; | ||
261 | } | ||
262 | |||
263 | new_client = &data->client; | ||
264 | i2c_set_clientdata(new_client, data); | ||
265 | new_client->addr = address; | ||
266 | new_client->adapter = adapter; | ||
267 | new_client->driver = &lm77_driver; | ||
268 | new_client->flags = 0; | ||
269 | 256 | ||
270 | /* Here comes the remaining detection. Since the LM77 has no | 257 | /* Here comes the remaining detection. Since the LM77 has no |
271 | register dedicated to identification, we have to rely on the | 258 | register dedicated to identification, we have to rely on the |
@@ -294,7 +281,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
294 | || i2c_smbus_read_word_data(new_client, i + 3) != crit | 281 | || i2c_smbus_read_word_data(new_client, i + 3) != crit |
295 | || i2c_smbus_read_word_data(new_client, i + 4) != min | 282 | || i2c_smbus_read_word_data(new_client, i + 4) != min |
296 | || i2c_smbus_read_word_data(new_client, i + 5) != max) | 283 | || i2c_smbus_read_word_data(new_client, i + 5) != max) |
297 | goto exit_free; | 284 | return -ENODEV; |
298 | 285 | ||
299 | /* sign bits */ | 286 | /* sign bits */ |
300 | if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0) | 287 | if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0) |
@@ -302,51 +289,55 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
302 | || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0) | 289 | || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0) |
303 | || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0) | 290 | || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0) |
304 | || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0)) | 291 | || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0)) |
305 | goto exit_free; | 292 | return -ENODEV; |
306 | 293 | ||
307 | /* unused bits */ | 294 | /* unused bits */ |
308 | if (conf & 0xe0) | 295 | if (conf & 0xe0) |
309 | goto exit_free; | 296 | return -ENODEV; |
310 | 297 | ||
311 | /* 0x06 and 0x07 return the last read value */ | 298 | /* 0x06 and 0x07 return the last read value */ |
312 | cur = i2c_smbus_read_word_data(new_client, 0); | 299 | cur = i2c_smbus_read_word_data(new_client, 0); |
313 | if (i2c_smbus_read_word_data(new_client, 6) != cur | 300 | if (i2c_smbus_read_word_data(new_client, 6) != cur |
314 | || i2c_smbus_read_word_data(new_client, 7) != cur) | 301 | || i2c_smbus_read_word_data(new_client, 7) != cur) |
315 | goto exit_free; | 302 | return -ENODEV; |
316 | hyst = i2c_smbus_read_word_data(new_client, 2); | 303 | hyst = i2c_smbus_read_word_data(new_client, 2); |
317 | if (i2c_smbus_read_word_data(new_client, 6) != hyst | 304 | if (i2c_smbus_read_word_data(new_client, 6) != hyst |
318 | || i2c_smbus_read_word_data(new_client, 7) != hyst) | 305 | || i2c_smbus_read_word_data(new_client, 7) != hyst) |
319 | goto exit_free; | 306 | return -ENODEV; |
320 | min = i2c_smbus_read_word_data(new_client, 4); | 307 | min = i2c_smbus_read_word_data(new_client, 4); |
321 | if (i2c_smbus_read_word_data(new_client, 6) != min | 308 | if (i2c_smbus_read_word_data(new_client, 6) != min |
322 | || i2c_smbus_read_word_data(new_client, 7) != min) | 309 | || i2c_smbus_read_word_data(new_client, 7) != min) |
323 | goto exit_free; | 310 | return -ENODEV; |
324 | 311 | ||
325 | } | 312 | } |
326 | 313 | ||
327 | /* Determine the chip type - only one kind supported! */ | 314 | strlcpy(info->type, "lm77", I2C_NAME_SIZE); |
328 | if (kind <= 0) | ||
329 | kind = lm77; | ||
330 | 315 | ||
331 | if (kind == lm77) { | 316 | return 0; |
332 | name = "lm77"; | 317 | } |
318 | |||
319 | static int lm77_probe(struct i2c_client *new_client, | ||
320 | const struct i2c_device_id *id) | ||
321 | { | ||
322 | struct lm77_data *data; | ||
323 | int err; | ||
324 | |||
325 | data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL); | ||
326 | if (!data) { | ||
327 | err = -ENOMEM; | ||
328 | goto exit; | ||
333 | } | 329 | } |
334 | 330 | ||
335 | /* Fill in the remaining client fields and put it into the global list */ | 331 | i2c_set_clientdata(new_client, data); |
336 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
337 | data->valid = 0; | 332 | data->valid = 0; |
338 | mutex_init(&data->update_lock); | 333 | mutex_init(&data->update_lock); |
339 | 334 | ||
340 | /* Tell the I2C layer a new client has arrived */ | ||
341 | if ((err = i2c_attach_client(new_client))) | ||
342 | goto exit_free; | ||
343 | |||
344 | /* Initialize the LM77 chip */ | 335 | /* Initialize the LM77 chip */ |
345 | lm77_init_client(new_client); | 336 | lm77_init_client(new_client); |
346 | 337 | ||
347 | /* Register sysfs hooks */ | 338 | /* Register sysfs hooks */ |
348 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) | 339 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) |
349 | goto exit_detach; | 340 | goto exit_free; |
350 | 341 | ||
351 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 342 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
352 | if (IS_ERR(data->hwmon_dev)) { | 343 | if (IS_ERR(data->hwmon_dev)) { |
@@ -358,20 +349,17 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
358 | 349 | ||
359 | exit_remove: | 350 | exit_remove: |
360 | sysfs_remove_group(&new_client->dev.kobj, &lm77_group); | 351 | sysfs_remove_group(&new_client->dev.kobj, &lm77_group); |
361 | exit_detach: | ||
362 | i2c_detach_client(new_client); | ||
363 | exit_free: | 352 | exit_free: |
364 | kfree(data); | 353 | kfree(data); |
365 | exit: | 354 | exit: |
366 | return err; | 355 | return err; |
367 | } | 356 | } |
368 | 357 | ||
369 | static int lm77_detach_client(struct i2c_client *client) | 358 | static int lm77_remove(struct i2c_client *client) |
370 | { | 359 | { |
371 | struct lm77_data *data = i2c_get_clientdata(client); | 360 | struct lm77_data *data = i2c_get_clientdata(client); |
372 | hwmon_device_unregister(data->hwmon_dev); | 361 | hwmon_device_unregister(data->hwmon_dev); |
373 | sysfs_remove_group(&client->dev.kobj, &lm77_group); | 362 | sysfs_remove_group(&client->dev.kobj, &lm77_group); |
374 | i2c_detach_client(client); | ||
375 | kfree(data); | 363 | kfree(data); |
376 | return 0; | 364 | return 0; |
377 | } | 365 | } |
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 26c91c9d4769..bcffc1899403 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -108,7 +108,6 @@ static inline long TEMP_FROM_REG(u16 temp) | |||
108 | */ | 108 | */ |
109 | 109 | ||
110 | struct lm80_data { | 110 | struct lm80_data { |
111 | struct i2c_client client; | ||
112 | struct device *hwmon_dev; | 111 | struct device *hwmon_dev; |
113 | struct mutex update_lock; | 112 | struct mutex update_lock; |
114 | char valid; /* !=0 if following fields are valid */ | 113 | char valid; /* !=0 if following fields are valid */ |
@@ -132,10 +131,12 @@ struct lm80_data { | |||
132 | * Functions declaration | 131 | * Functions declaration |
133 | */ | 132 | */ |
134 | 133 | ||
135 | static int lm80_attach_adapter(struct i2c_adapter *adapter); | 134 | static int lm80_probe(struct i2c_client *client, |
136 | static int lm80_detect(struct i2c_adapter *adapter, int address, int kind); | 135 | const struct i2c_device_id *id); |
136 | static int lm80_detect(struct i2c_client *client, int kind, | ||
137 | struct i2c_board_info *info); | ||
137 | static void lm80_init_client(struct i2c_client *client); | 138 | static void lm80_init_client(struct i2c_client *client); |
138 | static int lm80_detach_client(struct i2c_client *client); | 139 | static int lm80_remove(struct i2c_client *client); |
139 | static struct lm80_data *lm80_update_device(struct device *dev); | 140 | static struct lm80_data *lm80_update_device(struct device *dev); |
140 | static int lm80_read_value(struct i2c_client *client, u8 reg); | 141 | static int lm80_read_value(struct i2c_client *client, u8 reg); |
141 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); | 142 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); |
@@ -144,12 +145,22 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); | |||
144 | * Driver data (common to all clients) | 145 | * Driver data (common to all clients) |
145 | */ | 146 | */ |
146 | 147 | ||
148 | static const struct i2c_device_id lm80_id[] = { | ||
149 | { "lm80", lm80 }, | ||
150 | { } | ||
151 | }; | ||
152 | MODULE_DEVICE_TABLE(i2c, lm80_id); | ||
153 | |||
147 | static struct i2c_driver lm80_driver = { | 154 | static struct i2c_driver lm80_driver = { |
155 | .class = I2C_CLASS_HWMON, | ||
148 | .driver = { | 156 | .driver = { |
149 | .name = "lm80", | 157 | .name = "lm80", |
150 | }, | 158 | }, |
151 | .attach_adapter = lm80_attach_adapter, | 159 | .probe = lm80_probe, |
152 | .detach_client = lm80_detach_client, | 160 | .remove = lm80_remove, |
161 | .id_table = lm80_id, | ||
162 | .detect = lm80_detect, | ||
163 | .address_data = &addr_data, | ||
153 | }; | 164 | }; |
154 | 165 | ||
155 | /* | 166 | /* |
@@ -383,13 +394,6 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13); | |||
383 | * Real code | 394 | * Real code |
384 | */ | 395 | */ |
385 | 396 | ||
386 | static int lm80_attach_adapter(struct i2c_adapter *adapter) | ||
387 | { | ||
388 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
389 | return 0; | ||
390 | return i2c_probe(adapter, &addr_data, lm80_detect); | ||
391 | } | ||
392 | |||
393 | static struct attribute *lm80_attributes[] = { | 397 | static struct attribute *lm80_attributes[] = { |
394 | &sensor_dev_attr_in0_min.dev_attr.attr, | 398 | &sensor_dev_attr_in0_min.dev_attr.attr, |
395 | &sensor_dev_attr_in1_min.dev_attr.attr, | 399 | &sensor_dev_attr_in1_min.dev_attr.attr, |
@@ -442,53 +446,46 @@ static const struct attribute_group lm80_group = { | |||
442 | .attrs = lm80_attributes, | 446 | .attrs = lm80_attributes, |
443 | }; | 447 | }; |
444 | 448 | ||
445 | static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | 449 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
450 | static int lm80_detect(struct i2c_client *client, int kind, | ||
451 | struct i2c_board_info *info) | ||
446 | { | 452 | { |
453 | struct i2c_adapter *adapter = client->adapter; | ||
447 | int i, cur; | 454 | int i, cur; |
448 | struct i2c_client *client; | ||
449 | struct lm80_data *data; | ||
450 | int err = 0; | ||
451 | const char *name; | ||
452 | 455 | ||
453 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 456 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
454 | goto exit; | 457 | return -ENODEV; |
455 | |||
456 | /* OK. For now, we presume we have a valid client. We now create the | ||
457 | client structure, even though we cannot fill it completely yet. | ||
458 | But it allows us to access lm80_{read,write}_value. */ | ||
459 | if (!(data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL))) { | ||
460 | err = -ENOMEM; | ||
461 | goto exit; | ||
462 | } | ||
463 | |||
464 | client = &data->client; | ||
465 | i2c_set_clientdata(client, data); | ||
466 | client->addr = address; | ||
467 | client->adapter = adapter; | ||
468 | client->driver = &lm80_driver; | ||
469 | 458 | ||
470 | /* Now, we do the remaining detection. It is lousy. */ | 459 | /* Now, we do the remaining detection. It is lousy. */ |
471 | if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0) | 460 | if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0) |
472 | goto error_free; | 461 | return -ENODEV; |
473 | for (i = 0x2a; i <= 0x3d; i++) { | 462 | for (i = 0x2a; i <= 0x3d; i++) { |
474 | cur = i2c_smbus_read_byte_data(client, i); | 463 | cur = i2c_smbus_read_byte_data(client, i); |
475 | if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur) | 464 | if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur) |
476 | || (i2c_smbus_read_byte_data(client, i + 0x80) != cur) | 465 | || (i2c_smbus_read_byte_data(client, i + 0x80) != cur) |
477 | || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur)) | 466 | || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur)) |
478 | goto error_free; | 467 | return -ENODEV; |
479 | } | 468 | } |
480 | 469 | ||
481 | /* Determine the chip type - only one kind supported! */ | 470 | strlcpy(info->type, "lm80", I2C_NAME_SIZE); |
482 | kind = lm80; | ||
483 | name = "lm80"; | ||
484 | 471 | ||
485 | /* Fill in the remaining client fields */ | 472 | return 0; |
486 | strlcpy(client->name, name, I2C_NAME_SIZE); | 473 | } |
487 | mutex_init(&data->update_lock); | ||
488 | 474 | ||
489 | /* Tell the I2C layer a new client has arrived */ | 475 | static int lm80_probe(struct i2c_client *client, |
490 | if ((err = i2c_attach_client(client))) | 476 | const struct i2c_device_id *id) |
491 | goto error_free; | 477 | { |
478 | struct lm80_data *data; | ||
479 | int err; | ||
480 | |||
481 | data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL); | ||
482 | if (!data) { | ||
483 | err = -ENOMEM; | ||
484 | goto exit; | ||
485 | } | ||
486 | |||
487 | i2c_set_clientdata(client, data); | ||
488 | mutex_init(&data->update_lock); | ||
492 | 489 | ||
493 | /* Initialize the LM80 chip */ | 490 | /* Initialize the LM80 chip */ |
494 | lm80_init_client(client); | 491 | lm80_init_client(client); |
@@ -499,7 +496,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
499 | 496 | ||
500 | /* Register sysfs hooks */ | 497 | /* Register sysfs hooks */ |
501 | if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group))) | 498 | if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group))) |
502 | goto error_detach; | 499 | goto error_free; |
503 | 500 | ||
504 | data->hwmon_dev = hwmon_device_register(&client->dev); | 501 | data->hwmon_dev = hwmon_device_register(&client->dev); |
505 | if (IS_ERR(data->hwmon_dev)) { | 502 | if (IS_ERR(data->hwmon_dev)) { |
@@ -511,23 +508,18 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
511 | 508 | ||
512 | error_remove: | 509 | error_remove: |
513 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | 510 | sysfs_remove_group(&client->dev.kobj, &lm80_group); |
514 | error_detach: | ||
515 | i2c_detach_client(client); | ||
516 | error_free: | 511 | error_free: |
517 | kfree(data); | 512 | kfree(data); |
518 | exit: | 513 | exit: |
519 | return err; | 514 | return err; |
520 | } | 515 | } |
521 | 516 | ||
522 | static int lm80_detach_client(struct i2c_client *client) | 517 | static int lm80_remove(struct i2c_client *client) |
523 | { | 518 | { |
524 | struct lm80_data *data = i2c_get_clientdata(client); | 519 | struct lm80_data *data = i2c_get_clientdata(client); |
525 | int err; | ||
526 | 520 | ||
527 | hwmon_device_unregister(data->hwmon_dev); | 521 | hwmon_device_unregister(data->hwmon_dev); |
528 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | 522 | sysfs_remove_group(&client->dev.kobj, &lm80_group); |
529 | if ((err = i2c_detach_client(client))) | ||
530 | return err; | ||
531 | 523 | ||
532 | kfree(data); | 524 | kfree(data); |
533 | return 0; | 525 | return 0; |
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index 6a8642fa25fb..e59e2d1f080c 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | 3 | * monitoring |
4 | * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is | 6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is |
7 | * a sensor chip made by National Semiconductor. It reports up to four | 7 | * a sensor chip made by National Semiconductor. It reports up to four |
@@ -118,21 +118,34 @@ static const u8 LM83_REG_W_HIGH[] = { | |||
118 | * Functions declaration | 118 | * Functions declaration |
119 | */ | 119 | */ |
120 | 120 | ||
121 | static int lm83_attach_adapter(struct i2c_adapter *adapter); | 121 | static int lm83_detect(struct i2c_client *new_client, int kind, |
122 | static int lm83_detect(struct i2c_adapter *adapter, int address, int kind); | 122 | struct i2c_board_info *info); |
123 | static int lm83_detach_client(struct i2c_client *client); | 123 | static int lm83_probe(struct i2c_client *client, |
124 | const struct i2c_device_id *id); | ||
125 | static int lm83_remove(struct i2c_client *client); | ||
124 | static struct lm83_data *lm83_update_device(struct device *dev); | 126 | static struct lm83_data *lm83_update_device(struct device *dev); |
125 | 127 | ||
126 | /* | 128 | /* |
127 | * Driver data (common to all clients) | 129 | * Driver data (common to all clients) |
128 | */ | 130 | */ |
129 | 131 | ||
132 | static const struct i2c_device_id lm83_id[] = { | ||
133 | { "lm83", lm83 }, | ||
134 | { "lm82", lm82 }, | ||
135 | { } | ||
136 | }; | ||
137 | MODULE_DEVICE_TABLE(i2c, lm83_id); | ||
138 | |||
130 | static struct i2c_driver lm83_driver = { | 139 | static struct i2c_driver lm83_driver = { |
140 | .class = I2C_CLASS_HWMON, | ||
131 | .driver = { | 141 | .driver = { |
132 | .name = "lm83", | 142 | .name = "lm83", |
133 | }, | 143 | }, |
134 | .attach_adapter = lm83_attach_adapter, | 144 | .probe = lm83_probe, |
135 | .detach_client = lm83_detach_client, | 145 | .remove = lm83_remove, |
146 | .id_table = lm83_id, | ||
147 | .detect = lm83_detect, | ||
148 | .address_data = &addr_data, | ||
136 | }; | 149 | }; |
137 | 150 | ||
138 | /* | 151 | /* |
@@ -140,7 +153,6 @@ static struct i2c_driver lm83_driver = { | |||
140 | */ | 153 | */ |
141 | 154 | ||
142 | struct lm83_data { | 155 | struct lm83_data { |
143 | struct i2c_client client; | ||
144 | struct device *hwmon_dev; | 156 | struct device *hwmon_dev; |
145 | struct mutex update_lock; | 157 | struct mutex update_lock; |
146 | char valid; /* zero until following fields are valid */ | 158 | char valid; /* zero until following fields are valid */ |
@@ -278,40 +290,15 @@ static const struct attribute_group lm83_group_opt = { | |||
278 | * Real code | 290 | * Real code |
279 | */ | 291 | */ |
280 | 292 | ||
281 | static int lm83_attach_adapter(struct i2c_adapter *adapter) | 293 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
294 | static int lm83_detect(struct i2c_client *new_client, int kind, | ||
295 | struct i2c_board_info *info) | ||
282 | { | 296 | { |
283 | if (!(adapter->class & I2C_CLASS_HWMON)) | 297 | struct i2c_adapter *adapter = new_client->adapter; |
284 | return 0; | ||
285 | return i2c_probe(adapter, &addr_data, lm83_detect); | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * The following function does more than just detection. If detection | ||
290 | * succeeds, it also registers the new chip. | ||
291 | */ | ||
292 | static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | ||
293 | { | ||
294 | struct i2c_client *new_client; | ||
295 | struct lm83_data *data; | ||
296 | int err = 0; | ||
297 | const char *name = ""; | 298 | const char *name = ""; |
298 | 299 | ||
299 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 300 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
300 | goto exit; | 301 | return -ENODEV; |
301 | |||
302 | if (!(data = kzalloc(sizeof(struct lm83_data), GFP_KERNEL))) { | ||
303 | err = -ENOMEM; | ||
304 | goto exit; | ||
305 | } | ||
306 | |||
307 | /* The common I2C client data is placed right after the | ||
308 | * LM83-specific data. */ | ||
309 | new_client = &data->client; | ||
310 | i2c_set_clientdata(new_client, data); | ||
311 | new_client->addr = address; | ||
312 | new_client->adapter = adapter; | ||
313 | new_client->driver = &lm83_driver; | ||
314 | new_client->flags = 0; | ||
315 | 302 | ||
316 | /* Now we do the detection and identification. A negative kind | 303 | /* Now we do the detection and identification. A negative kind |
317 | * means that the driver was loaded with no force parameter | 304 | * means that the driver was loaded with no force parameter |
@@ -335,8 +322,9 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
335 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) | 322 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) |
336 | & 0x41) != 0x00)) { | 323 | & 0x41) != 0x00)) { |
337 | dev_dbg(&adapter->dev, | 324 | dev_dbg(&adapter->dev, |
338 | "LM83 detection failed at 0x%02x.\n", address); | 325 | "LM83 detection failed at 0x%02x.\n", |
339 | goto exit_free; | 326 | new_client->addr); |
327 | return -ENODEV; | ||
340 | } | 328 | } |
341 | } | 329 | } |
342 | 330 | ||
@@ -361,7 +349,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
361 | dev_info(&adapter->dev, | 349 | dev_info(&adapter->dev, |
362 | "Unsupported chip (man_id=0x%02X, " | 350 | "Unsupported chip (man_id=0x%02X, " |
363 | "chip_id=0x%02X).\n", man_id, chip_id); | 351 | "chip_id=0x%02X).\n", man_id, chip_id); |
364 | goto exit_free; | 352 | return -ENODEV; |
365 | } | 353 | } |
366 | } | 354 | } |
367 | 355 | ||
@@ -372,15 +360,27 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
372 | name = "lm82"; | 360 | name = "lm82"; |
373 | } | 361 | } |
374 | 362 | ||
375 | /* We can fill in the remaining client fields */ | 363 | strlcpy(info->type, name, I2C_NAME_SIZE); |
376 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 364 | |
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static int lm83_probe(struct i2c_client *new_client, | ||
369 | const struct i2c_device_id *id) | ||
370 | { | ||
371 | struct lm83_data *data; | ||
372 | int err; | ||
373 | |||
374 | data = kzalloc(sizeof(struct lm83_data), GFP_KERNEL); | ||
375 | if (!data) { | ||
376 | err = -ENOMEM; | ||
377 | goto exit; | ||
378 | } | ||
379 | |||
380 | i2c_set_clientdata(new_client, data); | ||
377 | data->valid = 0; | 381 | data->valid = 0; |
378 | mutex_init(&data->update_lock); | 382 | mutex_init(&data->update_lock); |
379 | 383 | ||
380 | /* Tell the I2C layer a new client has arrived */ | ||
381 | if ((err = i2c_attach_client(new_client))) | ||
382 | goto exit_free; | ||
383 | |||
384 | /* | 384 | /* |
385 | * Register sysfs hooks | 385 | * Register sysfs hooks |
386 | * The LM82 can only monitor one external diode which is | 386 | * The LM82 can only monitor one external diode which is |
@@ -389,9 +389,9 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
389 | */ | 389 | */ |
390 | 390 | ||
391 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) | 391 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) |
392 | goto exit_detach; | 392 | goto exit_free; |
393 | 393 | ||
394 | if (kind == lm83) { | 394 | if (id->driver_data == lm83) { |
395 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 395 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
396 | &lm83_group_opt))) | 396 | &lm83_group_opt))) |
397 | goto exit_remove_files; | 397 | goto exit_remove_files; |
@@ -408,26 +408,20 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
408 | exit_remove_files: | 408 | exit_remove_files: |
409 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); | 409 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); |
410 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); | 410 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); |
411 | exit_detach: | ||
412 | i2c_detach_client(new_client); | ||
413 | exit_free: | 411 | exit_free: |
414 | kfree(data); | 412 | kfree(data); |
415 | exit: | 413 | exit: |
416 | return err; | 414 | return err; |
417 | } | 415 | } |
418 | 416 | ||
419 | static int lm83_detach_client(struct i2c_client *client) | 417 | static int lm83_remove(struct i2c_client *client) |
420 | { | 418 | { |
421 | struct lm83_data *data = i2c_get_clientdata(client); | 419 | struct lm83_data *data = i2c_get_clientdata(client); |
422 | int err; | ||
423 | 420 | ||
424 | hwmon_device_unregister(data->hwmon_dev); | 421 | hwmon_device_unregister(data->hwmon_dev); |
425 | sysfs_remove_group(&client->dev.kobj, &lm83_group); | 422 | sysfs_remove_group(&client->dev.kobj, &lm83_group); |
426 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); | 423 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); |
427 | 424 | ||
428 | if ((err = i2c_detach_client(client))) | ||
429 | return err; | ||
430 | |||
431 | kfree(data); | 425 | kfree(data); |
432 | return 0; | 426 | return 0; |
433 | } | 427 | } |
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index e1c183f0aae0..21970f0d53a1 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * Philip Edelbrock <phil@netroedge.com> | 5 | * Philip Edelbrock <phil@netroedge.com> |
6 | * Stephen Rousset <stephen.rousset@rocketlogix.com> | 6 | * Stephen Rousset <stephen.rousset@rocketlogix.com> |
7 | * Dan Eaton <dan.eaton@rocketlogix.com> | 7 | * Dan Eaton <dan.eaton@rocketlogix.com> |
8 | * Copyright (C) 2004,2007 Jean Delvare <khali@linux-fr.org> | 8 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
9 | * | 9 | * |
10 | * Original port to Linux 2.6 by Jeff Oliver. | 10 | * Original port to Linux 2.6 by Jeff Oliver. |
11 | * | 11 | * |
@@ -157,22 +157,35 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C }; | |||
157 | * Functions declaration | 157 | * Functions declaration |
158 | */ | 158 | */ |
159 | 159 | ||
160 | static int lm87_attach_adapter(struct i2c_adapter *adapter); | 160 | static int lm87_probe(struct i2c_client *client, |
161 | static int lm87_detect(struct i2c_adapter *adapter, int address, int kind); | 161 | const struct i2c_device_id *id); |
162 | static int lm87_detect(struct i2c_client *new_client, int kind, | ||
163 | struct i2c_board_info *info); | ||
162 | static void lm87_init_client(struct i2c_client *client); | 164 | static void lm87_init_client(struct i2c_client *client); |
163 | static int lm87_detach_client(struct i2c_client *client); | 165 | static int lm87_remove(struct i2c_client *client); |
164 | static struct lm87_data *lm87_update_device(struct device *dev); | 166 | static struct lm87_data *lm87_update_device(struct device *dev); |
165 | 167 | ||
166 | /* | 168 | /* |
167 | * Driver data (common to all clients) | 169 | * Driver data (common to all clients) |
168 | */ | 170 | */ |
169 | 171 | ||
172 | static const struct i2c_device_id lm87_id[] = { | ||
173 | { "lm87", lm87 }, | ||
174 | { "adm1024", adm1024 }, | ||
175 | { } | ||
176 | }; | ||
177 | MODULE_DEVICE_TABLE(i2c, lm87_id); | ||
178 | |||
170 | static struct i2c_driver lm87_driver = { | 179 | static struct i2c_driver lm87_driver = { |
180 | .class = I2C_CLASS_HWMON, | ||
171 | .driver = { | 181 | .driver = { |
172 | .name = "lm87", | 182 | .name = "lm87", |
173 | }, | 183 | }, |
174 | .attach_adapter = lm87_attach_adapter, | 184 | .probe = lm87_probe, |
175 | .detach_client = lm87_detach_client, | 185 | .remove = lm87_remove, |
186 | .id_table = lm87_id, | ||
187 | .detect = lm87_detect, | ||
188 | .address_data = &addr_data, | ||
176 | }; | 189 | }; |
177 | 190 | ||
178 | /* | 191 | /* |
@@ -180,7 +193,6 @@ static struct i2c_driver lm87_driver = { | |||
180 | */ | 193 | */ |
181 | 194 | ||
182 | struct lm87_data { | 195 | struct lm87_data { |
183 | struct i2c_client client; | ||
184 | struct device *hwmon_dev; | 196 | struct device *hwmon_dev; |
185 | struct mutex update_lock; | 197 | struct mutex update_lock; |
186 | char valid; /* zero until following fields are valid */ | 198 | char valid; /* zero until following fields are valid */ |
@@ -562,13 +574,6 @@ static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); | |||
562 | * Real code | 574 | * Real code |
563 | */ | 575 | */ |
564 | 576 | ||
565 | static int lm87_attach_adapter(struct i2c_adapter *adapter) | ||
566 | { | ||
567 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
568 | return 0; | ||
569 | return i2c_probe(adapter, &addr_data, lm87_detect); | ||
570 | } | ||
571 | |||
572 | static struct attribute *lm87_attributes[] = { | 577 | static struct attribute *lm87_attributes[] = { |
573 | &dev_attr_in1_input.attr, | 578 | &dev_attr_in1_input.attr, |
574 | &dev_attr_in1_min.attr, | 579 | &dev_attr_in1_min.attr, |
@@ -656,33 +661,15 @@ static const struct attribute_group lm87_group_opt = { | |||
656 | .attrs = lm87_attributes_opt, | 661 | .attrs = lm87_attributes_opt, |
657 | }; | 662 | }; |
658 | 663 | ||
659 | /* | 664 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
660 | * The following function does more than just detection. If detection | 665 | static int lm87_detect(struct i2c_client *new_client, int kind, |
661 | * succeeds, it also registers the new chip. | 666 | struct i2c_board_info *info) |
662 | */ | ||
663 | static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | ||
664 | { | 667 | { |
665 | struct i2c_client *new_client; | 668 | struct i2c_adapter *adapter = new_client->adapter; |
666 | struct lm87_data *data; | ||
667 | int err = 0; | ||
668 | static const char *names[] = { "lm87", "adm1024" }; | 669 | static const char *names[] = { "lm87", "adm1024" }; |
669 | 670 | ||
670 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 671 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
671 | goto exit; | 672 | return -ENODEV; |
672 | |||
673 | if (!(data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL))) { | ||
674 | err = -ENOMEM; | ||
675 | goto exit; | ||
676 | } | ||
677 | |||
678 | /* The common I2C client data is placed right before the | ||
679 | LM87-specific data. */ | ||
680 | new_client = &data->client; | ||
681 | i2c_set_clientdata(new_client, data); | ||
682 | new_client->addr = address; | ||
683 | new_client->adapter = adapter; | ||
684 | new_client->driver = &lm87_driver; | ||
685 | new_client->flags = 0; | ||
686 | 673 | ||
687 | /* Default to an LM87 if forced */ | 674 | /* Default to an LM87 if forced */ |
688 | if (kind == 0) | 675 | if (kind == 0) |
@@ -704,20 +691,32 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
704 | || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { | 691 | || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { |
705 | dev_dbg(&adapter->dev, | 692 | dev_dbg(&adapter->dev, |
706 | "LM87 detection failed at 0x%02x.\n", | 693 | "LM87 detection failed at 0x%02x.\n", |
707 | address); | 694 | new_client->addr); |
708 | goto exit_free; | 695 | return -ENODEV; |
709 | } | 696 | } |
710 | } | 697 | } |
711 | 698 | ||
712 | /* We can fill in the remaining client fields */ | 699 | strlcpy(info->type, names[kind - 1], I2C_NAME_SIZE); |
713 | strlcpy(new_client->name, names[kind - 1], I2C_NAME_SIZE); | 700 | |
701 | return 0; | ||
702 | } | ||
703 | |||
704 | static int lm87_probe(struct i2c_client *new_client, | ||
705 | const struct i2c_device_id *id) | ||
706 | { | ||
707 | struct lm87_data *data; | ||
708 | int err; | ||
709 | |||
710 | data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL); | ||
711 | if (!data) { | ||
712 | err = -ENOMEM; | ||
713 | goto exit; | ||
714 | } | ||
715 | |||
716 | i2c_set_clientdata(new_client, data); | ||
714 | data->valid = 0; | 717 | data->valid = 0; |
715 | mutex_init(&data->update_lock); | 718 | mutex_init(&data->update_lock); |
716 | 719 | ||
717 | /* Tell the I2C layer a new client has arrived */ | ||
718 | if ((err = i2c_attach_client(new_client))) | ||
719 | goto exit_free; | ||
720 | |||
721 | /* Initialize the LM87 chip */ | 720 | /* Initialize the LM87 chip */ |
722 | lm87_init_client(new_client); | 721 | lm87_init_client(new_client); |
723 | 722 | ||
@@ -732,7 +731,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
732 | 731 | ||
733 | /* Register sysfs hooks */ | 732 | /* Register sysfs hooks */ |
734 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) | 733 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) |
735 | goto exit_detach; | 734 | goto exit_free; |
736 | 735 | ||
737 | if (data->channel & CHAN_NO_FAN(0)) { | 736 | if (data->channel & CHAN_NO_FAN(0)) { |
738 | if ((err = device_create_file(&new_client->dev, | 737 | if ((err = device_create_file(&new_client->dev, |
@@ -832,8 +831,6 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
832 | exit_remove: | 831 | exit_remove: |
833 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group); | 832 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group); |
834 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); | 833 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); |
835 | exit_detach: | ||
836 | i2c_detach_client(new_client); | ||
837 | exit_free: | 834 | exit_free: |
838 | kfree(data); | 835 | kfree(data); |
839 | exit: | 836 | exit: |
@@ -877,18 +874,14 @@ static void lm87_init_client(struct i2c_client *client) | |||
877 | } | 874 | } |
878 | } | 875 | } |
879 | 876 | ||
880 | static int lm87_detach_client(struct i2c_client *client) | 877 | static int lm87_remove(struct i2c_client *client) |
881 | { | 878 | { |
882 | struct lm87_data *data = i2c_get_clientdata(client); | 879 | struct lm87_data *data = i2c_get_clientdata(client); |
883 | int err; | ||
884 | 880 | ||
885 | hwmon_device_unregister(data->hwmon_dev); | 881 | hwmon_device_unregister(data->hwmon_dev); |
886 | sysfs_remove_group(&client->dev.kobj, &lm87_group); | 882 | sysfs_remove_group(&client->dev.kobj, &lm87_group); |
887 | sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); | 883 | sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); |
888 | 884 | ||
889 | if ((err = i2c_detach_client(client))) | ||
890 | return err; | ||
891 | |||
892 | kfree(data); | 885 | kfree(data); |
893 | return 0; | 886 | return 0; |
894 | } | 887 | } |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index d1a3da3dd8e0..c24fe36ac787 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -187,23 +187,44 @@ I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680); | |||
187 | * Functions declaration | 187 | * Functions declaration |
188 | */ | 188 | */ |
189 | 189 | ||
190 | static int lm90_attach_adapter(struct i2c_adapter *adapter); | 190 | static int lm90_detect(struct i2c_client *client, int kind, |
191 | static int lm90_detect(struct i2c_adapter *adapter, int address, | 191 | struct i2c_board_info *info); |
192 | int kind); | 192 | static int lm90_probe(struct i2c_client *client, |
193 | const struct i2c_device_id *id); | ||
193 | static void lm90_init_client(struct i2c_client *client); | 194 | static void lm90_init_client(struct i2c_client *client); |
194 | static int lm90_detach_client(struct i2c_client *client); | 195 | static int lm90_remove(struct i2c_client *client); |
195 | static struct lm90_data *lm90_update_device(struct device *dev); | 196 | static struct lm90_data *lm90_update_device(struct device *dev); |
196 | 197 | ||
197 | /* | 198 | /* |
198 | * Driver data (common to all clients) | 199 | * Driver data (common to all clients) |
199 | */ | 200 | */ |
200 | 201 | ||
202 | static const struct i2c_device_id lm90_id[] = { | ||
203 | { "adm1032", adm1032 }, | ||
204 | { "adt7461", adt7461 }, | ||
205 | { "lm90", lm90 }, | ||
206 | { "lm86", lm86 }, | ||
207 | { "lm89", lm99 }, | ||
208 | { "lm99", lm99 }, /* Missing temperature offset */ | ||
209 | { "max6657", max6657 }, | ||
210 | { "max6658", max6657 }, | ||
211 | { "max6659", max6657 }, | ||
212 | { "max6680", max6680 }, | ||
213 | { "max6681", max6680 }, | ||
214 | { } | ||
215 | }; | ||
216 | MODULE_DEVICE_TABLE(i2c, lm90_id); | ||
217 | |||
201 | static struct i2c_driver lm90_driver = { | 218 | static struct i2c_driver lm90_driver = { |
219 | .class = I2C_CLASS_HWMON, | ||
202 | .driver = { | 220 | .driver = { |
203 | .name = "lm90", | 221 | .name = "lm90", |
204 | }, | 222 | }, |
205 | .attach_adapter = lm90_attach_adapter, | 223 | .probe = lm90_probe, |
206 | .detach_client = lm90_detach_client, | 224 | .remove = lm90_remove, |
225 | .id_table = lm90_id, | ||
226 | .detect = lm90_detect, | ||
227 | .address_data = &addr_data, | ||
207 | }; | 228 | }; |
208 | 229 | ||
209 | /* | 230 | /* |
@@ -211,7 +232,6 @@ static struct i2c_driver lm90_driver = { | |||
211 | */ | 232 | */ |
212 | 233 | ||
213 | struct lm90_data { | 234 | struct lm90_data { |
214 | struct i2c_client client; | ||
215 | struct device *hwmon_dev; | 235 | struct device *hwmon_dev; |
216 | struct mutex update_lock; | 236 | struct mutex update_lock; |
217 | char valid; /* zero until following fields are valid */ | 237 | char valid; /* zero until following fields are valid */ |
@@ -477,40 +497,16 @@ static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value) | |||
477 | return 0; | 497 | return 0; |
478 | } | 498 | } |
479 | 499 | ||
480 | static int lm90_attach_adapter(struct i2c_adapter *adapter) | 500 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
481 | { | 501 | static int lm90_detect(struct i2c_client *new_client, int kind, |
482 | if (!(adapter->class & I2C_CLASS_HWMON)) | 502 | struct i2c_board_info *info) |
483 | return 0; | ||
484 | return i2c_probe(adapter, &addr_data, lm90_detect); | ||
485 | } | ||
486 | |||
487 | /* | ||
488 | * The following function does more than just detection. If detection | ||
489 | * succeeds, it also registers the new chip. | ||
490 | */ | ||
491 | static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | ||
492 | { | 503 | { |
493 | struct i2c_client *new_client; | 504 | struct i2c_adapter *adapter = new_client->adapter; |
494 | struct lm90_data *data; | 505 | int address = new_client->addr; |
495 | int err = 0; | ||
496 | const char *name = ""; | 506 | const char *name = ""; |
497 | 507 | ||
498 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 508 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
499 | goto exit; | 509 | return -ENODEV; |
500 | |||
501 | if (!(data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL))) { | ||
502 | err = -ENOMEM; | ||
503 | goto exit; | ||
504 | } | ||
505 | |||
506 | /* The common I2C client data is placed right before the | ||
507 | LM90-specific data. */ | ||
508 | new_client = &data->client; | ||
509 | i2c_set_clientdata(new_client, data); | ||
510 | new_client->addr = address; | ||
511 | new_client->adapter = adapter; | ||
512 | new_client->driver = &lm90_driver; | ||
513 | new_client->flags = 0; | ||
514 | 510 | ||
515 | /* | 511 | /* |
516 | * Now we do the remaining detection. A negative kind means that | 512 | * Now we do the remaining detection. A negative kind means that |
@@ -538,7 +534,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
538 | LM90_REG_R_CONFIG1)) < 0 | 534 | LM90_REG_R_CONFIG1)) < 0 |
539 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, | 535 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, |
540 | LM90_REG_R_CONVRATE)) < 0) | 536 | LM90_REG_R_CONVRATE)) < 0) |
541 | goto exit_free; | 537 | return -ENODEV; |
542 | 538 | ||
543 | if ((address == 0x4C || address == 0x4D) | 539 | if ((address == 0x4C || address == 0x4D) |
544 | && man_id == 0x01) { /* National Semiconductor */ | 540 | && man_id == 0x01) { /* National Semiconductor */ |
@@ -546,7 +542,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
546 | 542 | ||
547 | if ((reg_config2 = i2c_smbus_read_byte_data(new_client, | 543 | if ((reg_config2 = i2c_smbus_read_byte_data(new_client, |
548 | LM90_REG_R_CONFIG2)) < 0) | 544 | LM90_REG_R_CONFIG2)) < 0) |
549 | goto exit_free; | 545 | return -ENODEV; |
550 | 546 | ||
551 | if ((reg_config1 & 0x2A) == 0x00 | 547 | if ((reg_config1 & 0x2A) == 0x00 |
552 | && (reg_config2 & 0xF8) == 0x00 | 548 | && (reg_config2 & 0xF8) == 0x00 |
@@ -610,10 +606,11 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
610 | dev_info(&adapter->dev, | 606 | dev_info(&adapter->dev, |
611 | "Unsupported chip (man_id=0x%02X, " | 607 | "Unsupported chip (man_id=0x%02X, " |
612 | "chip_id=0x%02X).\n", man_id, chip_id); | 608 | "chip_id=0x%02X).\n", man_id, chip_id); |
613 | goto exit_free; | 609 | return -ENODEV; |
614 | } | 610 | } |
615 | } | 611 | } |
616 | 612 | ||
613 | /* Fill the i2c board info */ | ||
617 | if (kind == lm90) { | 614 | if (kind == lm90) { |
618 | name = "lm90"; | 615 | name = "lm90"; |
619 | } else if (kind == adm1032) { | 616 | } else if (kind == adm1032) { |
@@ -621,7 +618,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
621 | /* The ADM1032 supports PEC, but only if combined | 618 | /* The ADM1032 supports PEC, but only if combined |
622 | transactions are not used. */ | 619 | transactions are not used. */ |
623 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 620 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
624 | new_client->flags |= I2C_CLIENT_PEC; | 621 | info->flags |= I2C_CLIENT_PEC; |
625 | } else if (kind == lm99) { | 622 | } else if (kind == lm99) { |
626 | name = "lm99"; | 623 | name = "lm99"; |
627 | } else if (kind == lm86) { | 624 | } else if (kind == lm86) { |
@@ -633,23 +630,39 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
633 | } else if (kind == adt7461) { | 630 | } else if (kind == adt7461) { |
634 | name = "adt7461"; | 631 | name = "adt7461"; |
635 | } | 632 | } |
633 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
634 | |||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static int lm90_probe(struct i2c_client *new_client, | ||
639 | const struct i2c_device_id *id) | ||
640 | { | ||
641 | struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent); | ||
642 | struct lm90_data *data; | ||
643 | int err; | ||
636 | 644 | ||
637 | /* We can fill in the remaining client fields */ | 645 | data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL); |
638 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 646 | if (!data) { |
639 | data->valid = 0; | 647 | err = -ENOMEM; |
640 | data->kind = kind; | 648 | goto exit; |
649 | } | ||
650 | i2c_set_clientdata(new_client, data); | ||
641 | mutex_init(&data->update_lock); | 651 | mutex_init(&data->update_lock); |
642 | 652 | ||
643 | /* Tell the I2C layer a new client has arrived */ | 653 | /* Set the device type */ |
644 | if ((err = i2c_attach_client(new_client))) | 654 | data->kind = id->driver_data; |
645 | goto exit_free; | 655 | if (data->kind == adm1032) { |
656 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | ||
657 | new_client->flags &= ~I2C_CLIENT_PEC; | ||
658 | } | ||
646 | 659 | ||
647 | /* Initialize the LM90 chip */ | 660 | /* Initialize the LM90 chip */ |
648 | lm90_init_client(new_client); | 661 | lm90_init_client(new_client); |
649 | 662 | ||
650 | /* Register sysfs hooks */ | 663 | /* Register sysfs hooks */ |
651 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) | 664 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) |
652 | goto exit_detach; | 665 | goto exit_free; |
653 | if (new_client->flags & I2C_CLIENT_PEC) { | 666 | if (new_client->flags & I2C_CLIENT_PEC) { |
654 | if ((err = device_create_file(&new_client->dev, | 667 | if ((err = device_create_file(&new_client->dev, |
655 | &dev_attr_pec))) | 668 | &dev_attr_pec))) |
@@ -672,8 +685,6 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
672 | exit_remove_files: | 685 | exit_remove_files: |
673 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); | 686 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); |
674 | device_remove_file(&new_client->dev, &dev_attr_pec); | 687 | device_remove_file(&new_client->dev, &dev_attr_pec); |
675 | exit_detach: | ||
676 | i2c_detach_client(new_client); | ||
677 | exit_free: | 688 | exit_free: |
678 | kfree(data); | 689 | kfree(data); |
679 | exit: | 690 | exit: |
@@ -710,10 +721,9 @@ static void lm90_init_client(struct i2c_client *client) | |||
710 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | 721 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
711 | } | 722 | } |
712 | 723 | ||
713 | static int lm90_detach_client(struct i2c_client *client) | 724 | static int lm90_remove(struct i2c_client *client) |
714 | { | 725 | { |
715 | struct lm90_data *data = i2c_get_clientdata(client); | 726 | struct lm90_data *data = i2c_get_clientdata(client); |
716 | int err; | ||
717 | 727 | ||
718 | hwmon_device_unregister(data->hwmon_dev); | 728 | hwmon_device_unregister(data->hwmon_dev); |
719 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | 729 | sysfs_remove_group(&client->dev.kobj, &lm90_group); |
@@ -722,9 +732,6 @@ static int lm90_detach_client(struct i2c_client *client) | |||
722 | device_remove_file(&client->dev, | 732 | device_remove_file(&client->dev, |
723 | &sensor_dev_attr_temp2_offset.dev_attr); | 733 | &sensor_dev_attr_temp2_offset.dev_attr); |
724 | 734 | ||
725 | if ((err = i2c_detach_client(client))) | ||
726 | return err; | ||
727 | |||
728 | kfree(data); | 735 | kfree(data); |
729 | return 0; | 736 | return 0; |
730 | } | 737 | } |
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index c31942e08246..b2e00c5a7eec 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * lm92 - Hardware monitoring driver | 2 | * lm92 - Hardware monitoring driver |
3 | * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> | 3 | * Copyright (C) 2005-2008 Jean Delvare <khali@linux-fr.org> |
4 | * | 4 | * |
5 | * Based on the lm90 driver, with some ideas taken from the lm_sensors | 5 | * Based on the lm90 driver, with some ideas taken from the lm_sensors |
6 | * lm92 driver as well. | 6 | * lm92 driver as well. |
@@ -96,7 +96,6 @@ static struct i2c_driver lm92_driver; | |||
96 | 96 | ||
97 | /* Client data (each client gets its own) */ | 97 | /* Client data (each client gets its own) */ |
98 | struct lm92_data { | 98 | struct lm92_data { |
99 | struct i2c_client client; | ||
100 | struct device *hwmon_dev; | 99 | struct device *hwmon_dev; |
101 | struct mutex update_lock; | 100 | struct mutex update_lock; |
102 | char valid; /* zero until following fields are valid */ | 101 | char valid; /* zero until following fields are valid */ |
@@ -319,32 +318,15 @@ static const struct attribute_group lm92_group = { | |||
319 | .attrs = lm92_attributes, | 318 | .attrs = lm92_attributes, |
320 | }; | 319 | }; |
321 | 320 | ||
322 | /* The following function does more than just detection. If detection | 321 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
323 | succeeds, it also registers the new chip. */ | 322 | static int lm92_detect(struct i2c_client *new_client, int kind, |
324 | static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | 323 | struct i2c_board_info *info) |
325 | { | 324 | { |
326 | struct i2c_client *new_client; | 325 | struct i2c_adapter *adapter = new_client->adapter; |
327 | struct lm92_data *data; | ||
328 | int err = 0; | ||
329 | char *name; | ||
330 | 326 | ||
331 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 327 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
332 | | I2C_FUNC_SMBUS_WORD_DATA)) | 328 | | I2C_FUNC_SMBUS_WORD_DATA)) |
333 | goto exit; | 329 | return -ENODEV; |
334 | |||
335 | if (!(data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL))) { | ||
336 | err = -ENOMEM; | ||
337 | goto exit; | ||
338 | } | ||
339 | |||
340 | /* Fill in enough client fields so that we can read from the chip, | ||
341 | which is required for identication */ | ||
342 | new_client = &data->client; | ||
343 | i2c_set_clientdata(new_client, data); | ||
344 | new_client->addr = address; | ||
345 | new_client->adapter = adapter; | ||
346 | new_client->driver = &lm92_driver; | ||
347 | new_client->flags = 0; | ||
348 | 330 | ||
349 | /* A negative kind means that the driver was loaded with no force | 331 | /* A negative kind means that the driver was loaded with no force |
350 | parameter (default), so we must identify the chip. */ | 332 | parameter (default), so we must identify the chip. */ |
@@ -364,34 +346,36 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
364 | kind = lm92; /* No separate prefix */ | 346 | kind = lm92; /* No separate prefix */ |
365 | } | 347 | } |
366 | else | 348 | else |
367 | goto exit_free; | 349 | return -ENODEV; |
368 | } else | ||
369 | if (kind == 0) /* Default to an LM92 if forced */ | ||
370 | kind = lm92; | ||
371 | |||
372 | /* Give it the proper name */ | ||
373 | if (kind == lm92) { | ||
374 | name = "lm92"; | ||
375 | } else { /* Supposedly cannot happen */ | ||
376 | dev_dbg(&new_client->dev, "Kind out of range?\n"); | ||
377 | goto exit_free; | ||
378 | } | 350 | } |
379 | 351 | ||
380 | /* Fill in the remaining client fields */ | 352 | strlcpy(info->type, "lm92", I2C_NAME_SIZE); |
381 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 353 | |
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static int lm92_probe(struct i2c_client *new_client, | ||
358 | const struct i2c_device_id *id) | ||
359 | { | ||
360 | struct lm92_data *data; | ||
361 | int err; | ||
362 | |||
363 | data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL); | ||
364 | if (!data) { | ||
365 | err = -ENOMEM; | ||
366 | goto exit; | ||
367 | } | ||
368 | |||
369 | i2c_set_clientdata(new_client, data); | ||
382 | data->valid = 0; | 370 | data->valid = 0; |
383 | mutex_init(&data->update_lock); | 371 | mutex_init(&data->update_lock); |
384 | 372 | ||
385 | /* Tell the i2c subsystem a new client has arrived */ | ||
386 | if ((err = i2c_attach_client(new_client))) | ||
387 | goto exit_free; | ||
388 | |||
389 | /* Initialize the chipset */ | 373 | /* Initialize the chipset */ |
390 | lm92_init_client(new_client); | 374 | lm92_init_client(new_client); |
391 | 375 | ||
392 | /* Register sysfs hooks */ | 376 | /* Register sysfs hooks */ |
393 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) | 377 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) |
394 | goto exit_detach; | 378 | goto exit_free; |
395 | 379 | ||
396 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 380 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
397 | if (IS_ERR(data->hwmon_dev)) { | 381 | if (IS_ERR(data->hwmon_dev)) { |
@@ -403,32 +387,19 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
403 | 387 | ||
404 | exit_remove: | 388 | exit_remove: |
405 | sysfs_remove_group(&new_client->dev.kobj, &lm92_group); | 389 | sysfs_remove_group(&new_client->dev.kobj, &lm92_group); |
406 | exit_detach: | ||
407 | i2c_detach_client(new_client); | ||
408 | exit_free: | 390 | exit_free: |
409 | kfree(data); | 391 | kfree(data); |
410 | exit: | 392 | exit: |
411 | return err; | 393 | return err; |
412 | } | 394 | } |
413 | 395 | ||
414 | static int lm92_attach_adapter(struct i2c_adapter *adapter) | 396 | static int lm92_remove(struct i2c_client *client) |
415 | { | ||
416 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
417 | return 0; | ||
418 | return i2c_probe(adapter, &addr_data, lm92_detect); | ||
419 | } | ||
420 | |||
421 | static int lm92_detach_client(struct i2c_client *client) | ||
422 | { | 397 | { |
423 | struct lm92_data *data = i2c_get_clientdata(client); | 398 | struct lm92_data *data = i2c_get_clientdata(client); |
424 | int err; | ||
425 | 399 | ||
426 | hwmon_device_unregister(data->hwmon_dev); | 400 | hwmon_device_unregister(data->hwmon_dev); |
427 | sysfs_remove_group(&client->dev.kobj, &lm92_group); | 401 | sysfs_remove_group(&client->dev.kobj, &lm92_group); |
428 | 402 | ||
429 | if ((err = i2c_detach_client(client))) | ||
430 | return err; | ||
431 | |||
432 | kfree(data); | 403 | kfree(data); |
433 | return 0; | 404 | return 0; |
434 | } | 405 | } |
@@ -438,12 +409,23 @@ static int lm92_detach_client(struct i2c_client *client) | |||
438 | * Module and driver stuff | 409 | * Module and driver stuff |
439 | */ | 410 | */ |
440 | 411 | ||
412 | static const struct i2c_device_id lm92_id[] = { | ||
413 | { "lm92", lm92 }, | ||
414 | /* max6635 could be added here */ | ||
415 | { } | ||
416 | }; | ||
417 | MODULE_DEVICE_TABLE(i2c, lm92_id); | ||
418 | |||
441 | static struct i2c_driver lm92_driver = { | 419 | static struct i2c_driver lm92_driver = { |
420 | .class = I2C_CLASS_HWMON, | ||
442 | .driver = { | 421 | .driver = { |
443 | .name = "lm92", | 422 | .name = "lm92", |
444 | }, | 423 | }, |
445 | .attach_adapter = lm92_attach_adapter, | 424 | .probe = lm92_probe, |
446 | .detach_client = lm92_detach_client, | 425 | .remove = lm92_remove, |
426 | .id_table = lm92_id, | ||
427 | .detect = lm92_detect, | ||
428 | .address_data = &addr_data, | ||
447 | }; | 429 | }; |
448 | 430 | ||
449 | static int __init sensors_lm92_init(void) | 431 | static int __init sensors_lm92_init(void) |
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index 5e678f5c883d..fc36cadf36fb 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -200,7 +200,6 @@ struct block1_t { | |||
200 | * Client-specific data | 200 | * Client-specific data |
201 | */ | 201 | */ |
202 | struct lm93_data { | 202 | struct lm93_data { |
203 | struct i2c_client client; | ||
204 | struct device *hwmon_dev; | 203 | struct device *hwmon_dev; |
205 | 204 | ||
206 | struct mutex update_lock; | 205 | struct mutex update_lock; |
@@ -2501,45 +2500,14 @@ static void lm93_init_client(struct i2c_client *client) | |||
2501 | "chip to signal ready!\n"); | 2500 | "chip to signal ready!\n"); |
2502 | } | 2501 | } |
2503 | 2502 | ||
2504 | static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | 2503 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
2504 | static int lm93_detect(struct i2c_client *client, int kind, | ||
2505 | struct i2c_board_info *info) | ||
2505 | { | 2506 | { |
2506 | struct lm93_data *data; | 2507 | struct i2c_adapter *adapter = client->adapter; |
2507 | struct i2c_client *client; | ||
2508 | |||
2509 | int err = -ENODEV, func; | ||
2510 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
2511 | |||
2512 | /* choose update routine based on bus capabilities */ | ||
2513 | func = i2c_get_functionality(adapter); | ||
2514 | if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | ||
2515 | (!disable_block) ) { | ||
2516 | dev_dbg(&adapter->dev,"using SMBus block data transactions\n"); | ||
2517 | update = lm93_update_client_full; | ||
2518 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | ||
2519 | dev_dbg(&adapter->dev,"disabled SMBus block data " | ||
2520 | "transactions\n"); | ||
2521 | update = lm93_update_client_min; | ||
2522 | } else { | ||
2523 | dev_dbg(&adapter->dev,"detect failed, " | ||
2524 | "smbus byte and/or word data not supported!\n"); | ||
2525 | goto err_out; | ||
2526 | } | ||
2527 | 2508 | ||
2528 | /* OK. For now, we presume we have a valid client. We now create the | 2509 | if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) |
2529 | client structure, even though we cannot fill it completely yet. | 2510 | return -ENODEV; |
2530 | But it allows us to access lm78_{read,write}_value. */ | ||
2531 | |||
2532 | if ( !(data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL))) { | ||
2533 | dev_dbg(&adapter->dev,"out of memory!\n"); | ||
2534 | err = -ENOMEM; | ||
2535 | goto err_out; | ||
2536 | } | ||
2537 | |||
2538 | client = &data->client; | ||
2539 | i2c_set_clientdata(client, data); | ||
2540 | client->addr = address; | ||
2541 | client->adapter = adapter; | ||
2542 | client->driver = &lm93_driver; | ||
2543 | 2511 | ||
2544 | /* detection */ | 2512 | /* detection */ |
2545 | if (kind < 0) { | 2513 | if (kind < 0) { |
@@ -2548,7 +2516,7 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2548 | if (mfr != 0x01) { | 2516 | if (mfr != 0x01) { |
2549 | dev_dbg(&adapter->dev,"detect failed, " | 2517 | dev_dbg(&adapter->dev,"detect failed, " |
2550 | "bad manufacturer id 0x%02x!\n", mfr); | 2518 | "bad manufacturer id 0x%02x!\n", mfr); |
2551 | goto err_free; | 2519 | return -ENODEV; |
2552 | } | 2520 | } |
2553 | } | 2521 | } |
2554 | 2522 | ||
@@ -2563,31 +2531,61 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2563 | if (kind == 0) | 2531 | if (kind == 0) |
2564 | dev_dbg(&adapter->dev, | 2532 | dev_dbg(&adapter->dev, |
2565 | "(ignored 'force' parameter)\n"); | 2533 | "(ignored 'force' parameter)\n"); |
2566 | goto err_free; | 2534 | return -ENODEV; |
2567 | } | 2535 | } |
2568 | } | 2536 | } |
2569 | 2537 | ||
2570 | /* fill in remaining client fields */ | 2538 | strlcpy(info->type, "lm93", I2C_NAME_SIZE); |
2571 | strlcpy(client->name, "lm93", I2C_NAME_SIZE); | ||
2572 | dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", | 2539 | dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", |
2573 | client->name, i2c_adapter_id(client->adapter), | 2540 | client->name, i2c_adapter_id(client->adapter), |
2574 | client->addr); | 2541 | client->addr); |
2575 | 2542 | ||
2543 | return 0; | ||
2544 | } | ||
2545 | |||
2546 | static int lm93_probe(struct i2c_client *client, | ||
2547 | const struct i2c_device_id *id) | ||
2548 | { | ||
2549 | struct lm93_data *data; | ||
2550 | int err, func; | ||
2551 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
2552 | |||
2553 | /* choose update routine based on bus capabilities */ | ||
2554 | func = i2c_get_functionality(client->adapter); | ||
2555 | if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | ||
2556 | (!disable_block)) { | ||
2557 | dev_dbg(&client->dev, "using SMBus block data transactions\n"); | ||
2558 | update = lm93_update_client_full; | ||
2559 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | ||
2560 | dev_dbg(&client->dev, "disabled SMBus block data " | ||
2561 | "transactions\n"); | ||
2562 | update = lm93_update_client_min; | ||
2563 | } else { | ||
2564 | dev_dbg(&client->dev, "detect failed, " | ||
2565 | "smbus byte and/or word data not supported!\n"); | ||
2566 | err = -ENODEV; | ||
2567 | goto err_out; | ||
2568 | } | ||
2569 | |||
2570 | data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL); | ||
2571 | if (!data) { | ||
2572 | dev_dbg(&client->dev, "out of memory!\n"); | ||
2573 | err = -ENOMEM; | ||
2574 | goto err_out; | ||
2575 | } | ||
2576 | i2c_set_clientdata(client, data); | ||
2577 | |||
2576 | /* housekeeping */ | 2578 | /* housekeeping */ |
2577 | data->valid = 0; | 2579 | data->valid = 0; |
2578 | data->update = update; | 2580 | data->update = update; |
2579 | mutex_init(&data->update_lock); | 2581 | mutex_init(&data->update_lock); |
2580 | 2582 | ||
2581 | /* tell the I2C layer a new client has arrived */ | ||
2582 | if ((err = i2c_attach_client(client))) | ||
2583 | goto err_free; | ||
2584 | |||
2585 | /* initialize the chip */ | 2583 | /* initialize the chip */ |
2586 | lm93_init_client(client); | 2584 | lm93_init_client(client); |
2587 | 2585 | ||
2588 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); | 2586 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); |
2589 | if (err) | 2587 | if (err) |
2590 | goto err_detach; | 2588 | goto err_free; |
2591 | 2589 | ||
2592 | /* Register hwmon driver class */ | 2590 | /* Register hwmon driver class */ |
2593 | data->hwmon_dev = hwmon_device_register(&client->dev); | 2591 | data->hwmon_dev = hwmon_device_register(&client->dev); |
@@ -2597,43 +2595,39 @@ static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | |||
2597 | err = PTR_ERR(data->hwmon_dev); | 2595 | err = PTR_ERR(data->hwmon_dev); |
2598 | dev_err(&client->dev, "error registering hwmon device.\n"); | 2596 | dev_err(&client->dev, "error registering hwmon device.\n"); |
2599 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | 2597 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); |
2600 | err_detach: | ||
2601 | i2c_detach_client(client); | ||
2602 | err_free: | 2598 | err_free: |
2603 | kfree(data); | 2599 | kfree(data); |
2604 | err_out: | 2600 | err_out: |
2605 | return err; | 2601 | return err; |
2606 | } | 2602 | } |
2607 | 2603 | ||
2608 | /* This function is called when: | 2604 | static int lm93_remove(struct i2c_client *client) |
2609 | * lm93_driver is inserted (when this module is loaded), for each | ||
2610 | available adapter | ||
2611 | * when a new adapter is inserted (and lm93_driver is still present) */ | ||
2612 | static int lm93_attach_adapter(struct i2c_adapter *adapter) | ||
2613 | { | ||
2614 | return i2c_probe(adapter, &addr_data, lm93_detect); | ||
2615 | } | ||
2616 | |||
2617 | static int lm93_detach_client(struct i2c_client *client) | ||
2618 | { | 2605 | { |
2619 | struct lm93_data *data = i2c_get_clientdata(client); | 2606 | struct lm93_data *data = i2c_get_clientdata(client); |
2620 | int err = 0; | ||
2621 | 2607 | ||
2622 | hwmon_device_unregister(data->hwmon_dev); | 2608 | hwmon_device_unregister(data->hwmon_dev); |
2623 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | 2609 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); |
2624 | 2610 | ||
2625 | err = i2c_detach_client(client); | 2611 | kfree(data); |
2626 | if (!err) | 2612 | return 0; |
2627 | kfree(data); | ||
2628 | return err; | ||
2629 | } | 2613 | } |
2630 | 2614 | ||
2615 | static const struct i2c_device_id lm93_id[] = { | ||
2616 | { "lm93", lm93 }, | ||
2617 | { } | ||
2618 | }; | ||
2619 | MODULE_DEVICE_TABLE(i2c, lm93_id); | ||
2620 | |||
2631 | static struct i2c_driver lm93_driver = { | 2621 | static struct i2c_driver lm93_driver = { |
2622 | .class = I2C_CLASS_HWMON, | ||
2632 | .driver = { | 2623 | .driver = { |
2633 | .name = "lm93", | 2624 | .name = "lm93", |
2634 | }, | 2625 | }, |
2635 | .attach_adapter = lm93_attach_adapter, | 2626 | .probe = lm93_probe, |
2636 | .detach_client = lm93_detach_client, | 2627 | .remove = lm93_remove, |
2628 | .id_table = lm93_id, | ||
2629 | .detect = lm93_detect, | ||
2630 | .address_data = &addr_data, | ||
2637 | }; | 2631 | }; |
2638 | 2632 | ||
2639 | static int __init lm93_init(void) | 2633 | static int __init lm93_init(void) |
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 7e7267a04544..1ab1cacad598 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -79,23 +79,34 @@ I2C_CLIENT_INSMOD_1(max1619); | |||
79 | * Functions declaration | 79 | * Functions declaration |
80 | */ | 80 | */ |
81 | 81 | ||
82 | static int max1619_attach_adapter(struct i2c_adapter *adapter); | 82 | static int max1619_probe(struct i2c_client *client, |
83 | static int max1619_detect(struct i2c_adapter *adapter, int address, | 83 | const struct i2c_device_id *id); |
84 | int kind); | 84 | static int max1619_detect(struct i2c_client *client, int kind, |
85 | struct i2c_board_info *info); | ||
85 | static void max1619_init_client(struct i2c_client *client); | 86 | static void max1619_init_client(struct i2c_client *client); |
86 | static int max1619_detach_client(struct i2c_client *client); | 87 | static int max1619_remove(struct i2c_client *client); |
87 | static struct max1619_data *max1619_update_device(struct device *dev); | 88 | static struct max1619_data *max1619_update_device(struct device *dev); |
88 | 89 | ||
89 | /* | 90 | /* |
90 | * Driver data (common to all clients) | 91 | * Driver data (common to all clients) |
91 | */ | 92 | */ |
92 | 93 | ||
94 | static const struct i2c_device_id max1619_id[] = { | ||
95 | { "max1619", max1619 }, | ||
96 | { } | ||
97 | }; | ||
98 | MODULE_DEVICE_TABLE(i2c, max1619_id); | ||
99 | |||
93 | static struct i2c_driver max1619_driver = { | 100 | static struct i2c_driver max1619_driver = { |
101 | .class = I2C_CLASS_HWMON, | ||
94 | .driver = { | 102 | .driver = { |
95 | .name = "max1619", | 103 | .name = "max1619", |
96 | }, | 104 | }, |
97 | .attach_adapter = max1619_attach_adapter, | 105 | .probe = max1619_probe, |
98 | .detach_client = max1619_detach_client, | 106 | .remove = max1619_remove, |
107 | .id_table = max1619_id, | ||
108 | .detect = max1619_detect, | ||
109 | .address_data = &addr_data, | ||
99 | }; | 110 | }; |
100 | 111 | ||
101 | /* | 112 | /* |
@@ -103,7 +114,6 @@ static struct i2c_driver max1619_driver = { | |||
103 | */ | 114 | */ |
104 | 115 | ||
105 | struct max1619_data { | 116 | struct max1619_data { |
106 | struct i2c_client client; | ||
107 | struct device *hwmon_dev; | 117 | struct device *hwmon_dev; |
108 | struct mutex update_lock; | 118 | struct mutex update_lock; |
109 | char valid; /* zero until following fields are valid */ | 119 | char valid; /* zero until following fields are valid */ |
@@ -208,41 +218,15 @@ static const struct attribute_group max1619_group = { | |||
208 | * Real code | 218 | * Real code |
209 | */ | 219 | */ |
210 | 220 | ||
211 | static int max1619_attach_adapter(struct i2c_adapter *adapter) | 221 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
212 | { | 222 | static int max1619_detect(struct i2c_client *new_client, int kind, |
213 | if (!(adapter->class & I2C_CLASS_HWMON)) | 223 | struct i2c_board_info *info) |
214 | return 0; | ||
215 | return i2c_probe(adapter, &addr_data, max1619_detect); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * The following function does more than just detection. If detection | ||
220 | * succeeds, it also registers the new chip. | ||
221 | */ | ||
222 | static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | ||
223 | { | 224 | { |
224 | struct i2c_client *new_client; | 225 | struct i2c_adapter *adapter = new_client->adapter; |
225 | struct max1619_data *data; | ||
226 | int err = 0; | ||
227 | const char *name = ""; | ||
228 | u8 reg_config=0, reg_convrate=0, reg_status=0; | 226 | u8 reg_config=0, reg_convrate=0, reg_status=0; |
229 | 227 | ||
230 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 228 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
231 | goto exit; | 229 | return -ENODEV; |
232 | |||
233 | if (!(data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL))) { | ||
234 | err = -ENOMEM; | ||
235 | goto exit; | ||
236 | } | ||
237 | |||
238 | /* The common I2C client data is placed right before the | ||
239 | MAX1619-specific data. */ | ||
240 | new_client = &data->client; | ||
241 | i2c_set_clientdata(new_client, data); | ||
242 | new_client->addr = address; | ||
243 | new_client->adapter = adapter; | ||
244 | new_client->driver = &max1619_driver; | ||
245 | new_client->flags = 0; | ||
246 | 230 | ||
247 | /* | 231 | /* |
248 | * Now we do the remaining detection. A negative kind means that | 232 | * Now we do the remaining detection. A negative kind means that |
@@ -265,8 +249,8 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
265 | || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) { | 249 | || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) { |
266 | dev_dbg(&adapter->dev, | 250 | dev_dbg(&adapter->dev, |
267 | "MAX1619 detection failed at 0x%02x.\n", | 251 | "MAX1619 detection failed at 0x%02x.\n", |
268 | address); | 252 | new_client->addr); |
269 | goto exit_free; | 253 | return -ENODEV; |
270 | } | 254 | } |
271 | } | 255 | } |
272 | 256 | ||
@@ -285,28 +269,37 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
285 | dev_info(&adapter->dev, | 269 | dev_info(&adapter->dev, |
286 | "Unsupported chip (man_id=0x%02X, " | 270 | "Unsupported chip (man_id=0x%02X, " |
287 | "chip_id=0x%02X).\n", man_id, chip_id); | 271 | "chip_id=0x%02X).\n", man_id, chip_id); |
288 | goto exit_free; | 272 | return -ENODEV; |
289 | } | 273 | } |
290 | } | 274 | } |
291 | 275 | ||
292 | if (kind == max1619) | 276 | strlcpy(info->type, "max1619", I2C_NAME_SIZE); |
293 | name = "max1619"; | 277 | |
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int max1619_probe(struct i2c_client *new_client, | ||
282 | const struct i2c_device_id *id) | ||
283 | { | ||
284 | struct max1619_data *data; | ||
285 | int err; | ||
286 | |||
287 | data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL); | ||
288 | if (!data) { | ||
289 | err = -ENOMEM; | ||
290 | goto exit; | ||
291 | } | ||
294 | 292 | ||
295 | /* We can fill in the remaining client fields */ | 293 | i2c_set_clientdata(new_client, data); |
296 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
297 | data->valid = 0; | 294 | data->valid = 0; |
298 | mutex_init(&data->update_lock); | 295 | mutex_init(&data->update_lock); |
299 | 296 | ||
300 | /* Tell the I2C layer a new client has arrived */ | ||
301 | if ((err = i2c_attach_client(new_client))) | ||
302 | goto exit_free; | ||
303 | |||
304 | /* Initialize the MAX1619 chip */ | 297 | /* Initialize the MAX1619 chip */ |
305 | max1619_init_client(new_client); | 298 | max1619_init_client(new_client); |
306 | 299 | ||
307 | /* Register sysfs hooks */ | 300 | /* Register sysfs hooks */ |
308 | if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group))) | 301 | if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group))) |
309 | goto exit_detach; | 302 | goto exit_free; |
310 | 303 | ||
311 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 304 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
312 | if (IS_ERR(data->hwmon_dev)) { | 305 | if (IS_ERR(data->hwmon_dev)) { |
@@ -318,8 +311,6 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
318 | 311 | ||
319 | exit_remove_files: | 312 | exit_remove_files: |
320 | sysfs_remove_group(&new_client->dev.kobj, &max1619_group); | 313 | sysfs_remove_group(&new_client->dev.kobj, &max1619_group); |
321 | exit_detach: | ||
322 | i2c_detach_client(new_client); | ||
323 | exit_free: | 314 | exit_free: |
324 | kfree(data); | 315 | kfree(data); |
325 | exit: | 316 | exit: |
@@ -341,17 +332,13 @@ static void max1619_init_client(struct i2c_client *client) | |||
341 | config & 0xBF); /* run */ | 332 | config & 0xBF); /* run */ |
342 | } | 333 | } |
343 | 334 | ||
344 | static int max1619_detach_client(struct i2c_client *client) | 335 | static int max1619_remove(struct i2c_client *client) |
345 | { | 336 | { |
346 | struct max1619_data *data = i2c_get_clientdata(client); | 337 | struct max1619_data *data = i2c_get_clientdata(client); |
347 | int err; | ||
348 | 338 | ||
349 | hwmon_device_unregister(data->hwmon_dev); | 339 | hwmon_device_unregister(data->hwmon_dev); |
350 | sysfs_remove_group(&client->dev.kobj, &max1619_group); | 340 | sysfs_remove_group(&client->dev.kobj, &max1619_group); |
351 | 341 | ||
352 | if ((err = i2c_detach_client(client))) | ||
353 | return err; | ||
354 | |||
355 | kfree(data); | 342 | kfree(data); |
356 | return 0; | 343 | return 0; |
357 | } | 344 | } |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 52d528b76cc3..f27af6a9da41 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -104,22 +104,34 @@ I2C_CLIENT_INSMOD_1(max6650); | |||
104 | 104 | ||
105 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) | 105 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) |
106 | 106 | ||
107 | static int max6650_attach_adapter(struct i2c_adapter *adapter); | 107 | static int max6650_probe(struct i2c_client *client, |
108 | static int max6650_detect(struct i2c_adapter *adapter, int address, int kind); | 108 | const struct i2c_device_id *id); |
109 | static int max6650_detect(struct i2c_client *client, int kind, | ||
110 | struct i2c_board_info *info); | ||
109 | static int max6650_init_client(struct i2c_client *client); | 111 | static int max6650_init_client(struct i2c_client *client); |
110 | static int max6650_detach_client(struct i2c_client *client); | 112 | static int max6650_remove(struct i2c_client *client); |
111 | static struct max6650_data *max6650_update_device(struct device *dev); | 113 | static struct max6650_data *max6650_update_device(struct device *dev); |
112 | 114 | ||
113 | /* | 115 | /* |
114 | * Driver data (common to all clients) | 116 | * Driver data (common to all clients) |
115 | */ | 117 | */ |
116 | 118 | ||
119 | static const struct i2c_device_id max6650_id[] = { | ||
120 | { "max6650", max6650 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, max6650_id); | ||
124 | |||
117 | static struct i2c_driver max6650_driver = { | 125 | static struct i2c_driver max6650_driver = { |
126 | .class = I2C_CLASS_HWMON, | ||
118 | .driver = { | 127 | .driver = { |
119 | .name = "max6650", | 128 | .name = "max6650", |
120 | }, | 129 | }, |
121 | .attach_adapter = max6650_attach_adapter, | 130 | .probe = max6650_probe, |
122 | .detach_client = max6650_detach_client, | 131 | .remove = max6650_remove, |
132 | .id_table = max6650_id, | ||
133 | .detect = max6650_detect, | ||
134 | .address_data = &addr_data, | ||
123 | }; | 135 | }; |
124 | 136 | ||
125 | /* | 137 | /* |
@@ -128,7 +140,6 @@ static struct i2c_driver max6650_driver = { | |||
128 | 140 | ||
129 | struct max6650_data | 141 | struct max6650_data |
130 | { | 142 | { |
131 | struct i2c_client client; | ||
132 | struct device *hwmon_dev; | 143 | struct device *hwmon_dev; |
133 | struct mutex update_lock; | 144 | struct mutex update_lock; |
134 | char valid; /* zero until following fields are valid */ | 145 | char valid; /* zero until following fields are valid */ |
@@ -437,47 +448,21 @@ static struct attribute_group max6650_attr_grp = { | |||
437 | * Real code | 448 | * Real code |
438 | */ | 449 | */ |
439 | 450 | ||
440 | static int max6650_attach_adapter(struct i2c_adapter *adapter) | 451 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
452 | static int max6650_detect(struct i2c_client *client, int kind, | ||
453 | struct i2c_board_info *info) | ||
441 | { | 454 | { |
442 | if (!(adapter->class & I2C_CLASS_HWMON)) { | 455 | struct i2c_adapter *adapter = client->adapter; |
443 | dev_dbg(&adapter->dev, | 456 | int address = client->addr; |
444 | "FATAL: max6650_attach_adapter class HWMON not set\n"); | ||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | return i2c_probe(adapter, &addr_data, max6650_detect); | ||
449 | } | ||
450 | |||
451 | /* | ||
452 | * The following function does more than just detection. If detection | ||
453 | * succeeds, it also registers the new chip. | ||
454 | */ | ||
455 | |||
456 | static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | ||
457 | { | ||
458 | struct i2c_client *client; | ||
459 | struct max6650_data *data; | ||
460 | int err = -ENODEV; | ||
461 | 457 | ||
462 | dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); | 458 | dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); |
463 | 459 | ||
464 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 460 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
465 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " | 461 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " |
466 | "byte read mode, skipping.\n"); | 462 | "byte read mode, skipping.\n"); |
467 | return 0; | 463 | return -ENODEV; |
468 | } | ||
469 | |||
470 | if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) { | ||
471 | dev_err(&adapter->dev, "max6650: out of memory.\n"); | ||
472 | return -ENOMEM; | ||
473 | } | 464 | } |
474 | 465 | ||
475 | client = &data->client; | ||
476 | i2c_set_clientdata(client, data); | ||
477 | client->addr = address; | ||
478 | client->adapter = adapter; | ||
479 | client->driver = &max6650_driver; | ||
480 | |||
481 | /* | 466 | /* |
482 | * Now we do the remaining detection. A negative kind means that | 467 | * Now we do the remaining detection. A negative kind means that |
483 | * the driver was loaded with no force parameter (default), so we | 468 | * the driver was loaded with no force parameter (default), so we |
@@ -501,28 +486,40 @@ static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | |||
501 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) { | 486 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) { |
502 | dev_dbg(&adapter->dev, | 487 | dev_dbg(&adapter->dev, |
503 | "max6650: detection failed at 0x%02x.\n", address); | 488 | "max6650: detection failed at 0x%02x.\n", address); |
504 | goto err_free; | 489 | return -ENODEV; |
505 | } | 490 | } |
506 | 491 | ||
507 | dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address); | 492 | dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address); |
508 | 493 | ||
509 | strlcpy(client->name, "max6650", I2C_NAME_SIZE); | 494 | strlcpy(info->type, "max6650", I2C_NAME_SIZE); |
510 | mutex_init(&data->update_lock); | ||
511 | 495 | ||
512 | if ((err = i2c_attach_client(client))) { | 496 | return 0; |
513 | dev_err(&adapter->dev, "max6650: failed to attach client.\n"); | 497 | } |
514 | goto err_free; | 498 | |
499 | static int max6650_probe(struct i2c_client *client, | ||
500 | const struct i2c_device_id *id) | ||
501 | { | ||
502 | struct max6650_data *data; | ||
503 | int err; | ||
504 | |||
505 | if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) { | ||
506 | dev_err(&client->dev, "out of memory.\n"); | ||
507 | return -ENOMEM; | ||
515 | } | 508 | } |
516 | 509 | ||
510 | i2c_set_clientdata(client, data); | ||
511 | mutex_init(&data->update_lock); | ||
512 | |||
517 | /* | 513 | /* |
518 | * Initialize the max6650 chip | 514 | * Initialize the max6650 chip |
519 | */ | 515 | */ |
520 | if (max6650_init_client(client)) | 516 | err = max6650_init_client(client); |
521 | goto err_detach; | 517 | if (err) |
518 | goto err_free; | ||
522 | 519 | ||
523 | err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); | 520 | err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); |
524 | if (err) | 521 | if (err) |
525 | goto err_detach; | 522 | goto err_free; |
526 | 523 | ||
527 | data->hwmon_dev = hwmon_device_register(&client->dev); | 524 | data->hwmon_dev = hwmon_device_register(&client->dev); |
528 | if (!IS_ERR(data->hwmon_dev)) | 525 | if (!IS_ERR(data->hwmon_dev)) |
@@ -531,24 +528,19 @@ static int max6650_detect(struct i2c_adapter *adapter, int address, int kind) | |||
531 | err = PTR_ERR(data->hwmon_dev); | 528 | err = PTR_ERR(data->hwmon_dev); |
532 | dev_err(&client->dev, "error registering hwmon device.\n"); | 529 | dev_err(&client->dev, "error registering hwmon device.\n"); |
533 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | 530 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); |
534 | err_detach: | ||
535 | i2c_detach_client(client); | ||
536 | err_free: | 531 | err_free: |
537 | kfree(data); | 532 | kfree(data); |
538 | return err; | 533 | return err; |
539 | } | 534 | } |
540 | 535 | ||
541 | static int max6650_detach_client(struct i2c_client *client) | 536 | static int max6650_remove(struct i2c_client *client) |
542 | { | 537 | { |
543 | struct max6650_data *data = i2c_get_clientdata(client); | 538 | struct max6650_data *data = i2c_get_clientdata(client); |
544 | int err; | ||
545 | 539 | ||
546 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | 540 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); |
547 | hwmon_device_unregister(data->hwmon_dev); | 541 | hwmon_device_unregister(data->hwmon_dev); |
548 | err = i2c_detach_client(client); | 542 | kfree(data); |
549 | if (!err) | 543 | return 0; |
550 | kfree(data); | ||
551 | return err; | ||
552 | } | 544 | } |
553 | 545 | ||
554 | static int max6650_init_client(struct i2c_client *client) | 546 | static int max6650_init_client(struct i2c_client *client) |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 3c9db6598ba7..8bb5cb532d4d 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -96,7 +96,6 @@ static inline int TEMP_FROM_REG(s8 val) | |||
96 | } | 96 | } |
97 | 97 | ||
98 | struct smsc47m192_data { | 98 | struct smsc47m192_data { |
99 | struct i2c_client client; | ||
100 | struct device *hwmon_dev; | 99 | struct device *hwmon_dev; |
101 | struct mutex update_lock; | 100 | struct mutex update_lock; |
102 | char valid; /* !=0 if following fields are valid */ | 101 | char valid; /* !=0 if following fields are valid */ |
@@ -114,18 +113,29 @@ struct smsc47m192_data { | |||
114 | u8 vrm; | 113 | u8 vrm; |
115 | }; | 114 | }; |
116 | 115 | ||
117 | static int smsc47m192_attach_adapter(struct i2c_adapter *adapter); | 116 | static int smsc47m192_probe(struct i2c_client *client, |
118 | static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | 117 | const struct i2c_device_id *id); |
119 | int kind); | 118 | static int smsc47m192_detect(struct i2c_client *client, int kind, |
120 | static int smsc47m192_detach_client(struct i2c_client *client); | 119 | struct i2c_board_info *info); |
120 | static int smsc47m192_remove(struct i2c_client *client); | ||
121 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); | 121 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); |
122 | 122 | ||
123 | static const struct i2c_device_id smsc47m192_id[] = { | ||
124 | { "smsc47m192", smsc47m192 }, | ||
125 | { } | ||
126 | }; | ||
127 | MODULE_DEVICE_TABLE(i2c, smsc47m192_id); | ||
128 | |||
123 | static struct i2c_driver smsc47m192_driver = { | 129 | static struct i2c_driver smsc47m192_driver = { |
130 | .class = I2C_CLASS_HWMON, | ||
124 | .driver = { | 131 | .driver = { |
125 | .name = "smsc47m192", | 132 | .name = "smsc47m192", |
126 | }, | 133 | }, |
127 | .attach_adapter = smsc47m192_attach_adapter, | 134 | .probe = smsc47m192_probe, |
128 | .detach_client = smsc47m192_detach_client, | 135 | .remove = smsc47m192_remove, |
136 | .id_table = smsc47m192_id, | ||
137 | .detect = smsc47m192_detect, | ||
138 | .address_data = &addr_data, | ||
129 | }; | 139 | }; |
130 | 140 | ||
131 | /* Voltages */ | 141 | /* Voltages */ |
@@ -440,17 +450,6 @@ static const struct attribute_group smsc47m192_group_in4 = { | |||
440 | .attrs = smsc47m192_attributes_in4, | 450 | .attrs = smsc47m192_attributes_in4, |
441 | }; | 451 | }; |
442 | 452 | ||
443 | /* This function is called when: | ||
444 | * smsc47m192_driver is inserted (when this module is loaded), for each | ||
445 | available adapter | ||
446 | * when a new adapter is inserted (and smsc47m192_driver is still present) */ | ||
447 | static int smsc47m192_attach_adapter(struct i2c_adapter *adapter) | ||
448 | { | ||
449 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
450 | return 0; | ||
451 | return i2c_probe(adapter, &addr_data, smsc47m192_detect); | ||
452 | } | ||
453 | |||
454 | static void smsc47m192_init_client(struct i2c_client *client) | 453 | static void smsc47m192_init_client(struct i2c_client *client) |
455 | { | 454 | { |
456 | int i; | 455 | int i; |
@@ -481,31 +480,15 @@ static void smsc47m192_init_client(struct i2c_client *client) | |||
481 | } | 480 | } |
482 | } | 481 | } |
483 | 482 | ||
484 | /* This function is called by i2c_probe */ | 483 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
485 | static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | 484 | static int smsc47m192_detect(struct i2c_client *client, int kind, |
486 | int kind) | 485 | struct i2c_board_info *info) |
487 | { | 486 | { |
488 | struct i2c_client *client; | 487 | struct i2c_adapter *adapter = client->adapter; |
489 | struct smsc47m192_data *data; | 488 | int version; |
490 | int err = 0; | ||
491 | int version, config; | ||
492 | 489 | ||
493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 490 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
494 | goto exit; | 491 | return -ENODEV; |
495 | |||
496 | if (!(data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL))) { | ||
497 | err = -ENOMEM; | ||
498 | goto exit; | ||
499 | } | ||
500 | |||
501 | client = &data->client; | ||
502 | i2c_set_clientdata(client, data); | ||
503 | client->addr = address; | ||
504 | client->adapter = adapter; | ||
505 | client->driver = &smsc47m192_driver; | ||
506 | |||
507 | if (kind == 0) | ||
508 | kind = smsc47m192; | ||
509 | 492 | ||
510 | /* Detection criteria from sensors_detect script */ | 493 | /* Detection criteria from sensors_detect script */ |
511 | if (kind < 0) { | 494 | if (kind < 0) { |
@@ -523,26 +506,39 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | |||
523 | } else { | 506 | } else { |
524 | dev_dbg(&adapter->dev, | 507 | dev_dbg(&adapter->dev, |
525 | "SMSC47M192 detection failed at 0x%02x\n", | 508 | "SMSC47M192 detection failed at 0x%02x\n", |
526 | address); | 509 | client->addr); |
527 | goto exit_free; | 510 | return -ENODEV; |
528 | } | 511 | } |
529 | } | 512 | } |
530 | 513 | ||
531 | /* Fill in the remaining client fields and put into the global list */ | 514 | strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); |
532 | strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); | 515 | |
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static int smsc47m192_probe(struct i2c_client *client, | ||
520 | const struct i2c_device_id *id) | ||
521 | { | ||
522 | struct smsc47m192_data *data; | ||
523 | int config; | ||
524 | int err; | ||
525 | |||
526 | data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL); | ||
527 | if (!data) { | ||
528 | err = -ENOMEM; | ||
529 | goto exit; | ||
530 | } | ||
531 | |||
532 | i2c_set_clientdata(client, data); | ||
533 | data->vrm = vid_which_vrm(); | 533 | data->vrm = vid_which_vrm(); |
534 | mutex_init(&data->update_lock); | 534 | mutex_init(&data->update_lock); |
535 | 535 | ||
536 | /* Tell the I2C layer a new client has arrived */ | ||
537 | if ((err = i2c_attach_client(client))) | ||
538 | goto exit_free; | ||
539 | |||
540 | /* Initialize the SMSC47M192 chip */ | 536 | /* Initialize the SMSC47M192 chip */ |
541 | smsc47m192_init_client(client); | 537 | smsc47m192_init_client(client); |
542 | 538 | ||
543 | /* Register sysfs hooks */ | 539 | /* Register sysfs hooks */ |
544 | if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) | 540 | if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) |
545 | goto exit_detach; | 541 | goto exit_free; |
546 | 542 | ||
547 | /* Pin 110 is either in4 (+12V) or VID4 */ | 543 | /* Pin 110 is either in4 (+12V) or VID4 */ |
548 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); | 544 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); |
@@ -563,26 +559,20 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | |||
563 | exit_remove_files: | 559 | exit_remove_files: |
564 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | 560 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); |
565 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | 561 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); |
566 | exit_detach: | ||
567 | i2c_detach_client(client); | ||
568 | exit_free: | 562 | exit_free: |
569 | kfree(data); | 563 | kfree(data); |
570 | exit: | 564 | exit: |
571 | return err; | 565 | return err; |
572 | } | 566 | } |
573 | 567 | ||
574 | static int smsc47m192_detach_client(struct i2c_client *client) | 568 | static int smsc47m192_remove(struct i2c_client *client) |
575 | { | 569 | { |
576 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 570 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
577 | int err; | ||
578 | 571 | ||
579 | hwmon_device_unregister(data->hwmon_dev); | 572 | hwmon_device_unregister(data->hwmon_dev); |
580 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | 573 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); |
581 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | 574 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); |
582 | 575 | ||
583 | if ((err = i2c_detach_client(client))) | ||
584 | return err; | ||
585 | |||
586 | kfree(data); | 576 | kfree(data); |
587 | 577 | ||
588 | return 0; | 578 | return 0; |
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index 76a3859c3fbe..3b01001108c1 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -60,7 +60,6 @@ static const u8 THMC50_REG_TEMP_MAX[] = { 0x39, 0x37, 0x2B }; | |||
60 | 60 | ||
61 | /* Each client has this additional data */ | 61 | /* Each client has this additional data */ |
62 | struct thmc50_data { | 62 | struct thmc50_data { |
63 | struct i2c_client client; | ||
64 | struct device *hwmon_dev; | 63 | struct device *hwmon_dev; |
65 | 64 | ||
66 | struct mutex update_lock; | 65 | struct mutex update_lock; |
@@ -77,17 +76,31 @@ struct thmc50_data { | |||
77 | u8 alarms; | 76 | u8 alarms; |
78 | }; | 77 | }; |
79 | 78 | ||
80 | static int thmc50_attach_adapter(struct i2c_adapter *adapter); | 79 | static int thmc50_detect(struct i2c_client *client, int kind, |
81 | static int thmc50_detach_client(struct i2c_client *client); | 80 | struct i2c_board_info *info); |
81 | static int thmc50_probe(struct i2c_client *client, | ||
82 | const struct i2c_device_id *id); | ||
83 | static int thmc50_remove(struct i2c_client *client); | ||
82 | static void thmc50_init_client(struct i2c_client *client); | 84 | static void thmc50_init_client(struct i2c_client *client); |
83 | static struct thmc50_data *thmc50_update_device(struct device *dev); | 85 | static struct thmc50_data *thmc50_update_device(struct device *dev); |
84 | 86 | ||
87 | static const struct i2c_device_id thmc50_id[] = { | ||
88 | { "adm1022", adm1022 }, | ||
89 | { "thmc50", thmc50 }, | ||
90 | { } | ||
91 | }; | ||
92 | MODULE_DEVICE_TABLE(i2c, thmc50_id); | ||
93 | |||
85 | static struct i2c_driver thmc50_driver = { | 94 | static struct i2c_driver thmc50_driver = { |
95 | .class = I2C_CLASS_HWMON, | ||
86 | .driver = { | 96 | .driver = { |
87 | .name = "thmc50", | 97 | .name = "thmc50", |
88 | }, | 98 | }, |
89 | .attach_adapter = thmc50_attach_adapter, | 99 | .probe = thmc50_probe, |
90 | .detach_client = thmc50_detach_client, | 100 | .remove = thmc50_remove, |
101 | .id_table = thmc50_id, | ||
102 | .detect = thmc50_detect, | ||
103 | .address_data = &addr_data, | ||
91 | }; | 104 | }; |
92 | 105 | ||
93 | static ssize_t show_analog_out(struct device *dev, | 106 | static ssize_t show_analog_out(struct device *dev, |
@@ -250,39 +263,23 @@ static const struct attribute_group temp3_group = { | |||
250 | .attrs = temp3_attributes, | 263 | .attrs = temp3_attributes, |
251 | }; | 264 | }; |
252 | 265 | ||
253 | static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | 266 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
267 | static int thmc50_detect(struct i2c_client *client, int kind, | ||
268 | struct i2c_board_info *info) | ||
254 | { | 269 | { |
255 | unsigned company; | 270 | unsigned company; |
256 | unsigned revision; | 271 | unsigned revision; |
257 | unsigned config; | 272 | unsigned config; |
258 | struct i2c_client *client; | 273 | struct i2c_adapter *adapter = client->adapter; |
259 | struct thmc50_data *data; | ||
260 | struct device *dev; | ||
261 | int err = 0; | 274 | int err = 0; |
262 | const char *type_name; | 275 | const char *type_name; |
263 | 276 | ||
264 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 277 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
265 | pr_debug("thmc50: detect failed, " | 278 | pr_debug("thmc50: detect failed, " |
266 | "smbus byte data not supported!\n"); | 279 | "smbus byte data not supported!\n"); |
267 | goto exit; | 280 | return -ENODEV; |
268 | } | ||
269 | |||
270 | /* OK. For now, we presume we have a valid client. We now create the | ||
271 | client structure, even though we cannot fill it completely yet. | ||
272 | But it allows us to access thmc50 registers. */ | ||
273 | if (!(data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL))) { | ||
274 | pr_debug("thmc50: detect failed, kzalloc failed!\n"); | ||
275 | err = -ENOMEM; | ||
276 | goto exit; | ||
277 | } | 281 | } |
278 | 282 | ||
279 | client = &data->client; | ||
280 | i2c_set_clientdata(client, data); | ||
281 | client->addr = address; | ||
282 | client->adapter = adapter; | ||
283 | client->driver = &thmc50_driver; | ||
284 | dev = &client->dev; | ||
285 | |||
286 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", | 283 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", |
287 | client->addr, i2c_adapter_id(client->adapter)); | 284 | client->addr, i2c_adapter_id(client->adapter)); |
288 | 285 | ||
@@ -307,21 +304,22 @@ static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | |||
307 | } | 304 | } |
308 | if (err == -ENODEV) { | 305 | if (err == -ENODEV) { |
309 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); | 306 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); |
310 | goto exit_free; | 307 | return err; |
311 | } | 308 | } |
312 | data->type = kind; | ||
313 | 309 | ||
314 | if (kind == adm1022) { | 310 | if (kind == adm1022) { |
315 | int id = i2c_adapter_id(client->adapter); | 311 | int id = i2c_adapter_id(client->adapter); |
316 | int i; | 312 | int i; |
317 | 313 | ||
318 | type_name = "adm1022"; | 314 | type_name = "adm1022"; |
319 | data->has_temp3 = (config >> 7) & 1; /* config MSB */ | ||
320 | for (i = 0; i + 1 < adm1022_temp3_num; i += 2) | 315 | for (i = 0; i + 1 < adm1022_temp3_num; i += 2) |
321 | if (adm1022_temp3[i] == id && | 316 | if (adm1022_temp3[i] == id && |
322 | adm1022_temp3[i + 1] == address) { | 317 | adm1022_temp3[i + 1] == client->addr) { |
323 | /* enable 2nd remote temp */ | 318 | /* enable 2nd remote temp */ |
324 | data->has_temp3 = 1; | 319 | config |= (1 << 7); |
320 | i2c_smbus_write_byte_data(client, | ||
321 | THMC50_REG_CONF, | ||
322 | config); | ||
325 | break; | 323 | break; |
326 | } | 324 | } |
327 | } else { | 325 | } else { |
@@ -330,19 +328,33 @@ static int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) | |||
330 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", | 328 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", |
331 | type_name, (revision >> 4) - 0xc, revision & 0xf); | 329 | type_name, (revision >> 4) - 0xc, revision & 0xf); |
332 | 330 | ||
333 | /* Fill in the remaining client fields & put it into the global list */ | 331 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
334 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | ||
335 | mutex_init(&data->update_lock); | ||
336 | 332 | ||
337 | /* Tell the I2C layer a new client has arrived */ | 333 | return 0; |
338 | if ((err = i2c_attach_client(client))) | 334 | } |
339 | goto exit_free; | 335 | |
336 | static int thmc50_probe(struct i2c_client *client, | ||
337 | const struct i2c_device_id *id) | ||
338 | { | ||
339 | struct thmc50_data *data; | ||
340 | int err; | ||
341 | |||
342 | data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL); | ||
343 | if (!data) { | ||
344 | pr_debug("thmc50: detect failed, kzalloc failed!\n"); | ||
345 | err = -ENOMEM; | ||
346 | goto exit; | ||
347 | } | ||
348 | |||
349 | i2c_set_clientdata(client, data); | ||
350 | data->type = id->driver_data; | ||
351 | mutex_init(&data->update_lock); | ||
340 | 352 | ||
341 | thmc50_init_client(client); | 353 | thmc50_init_client(client); |
342 | 354 | ||
343 | /* Register sysfs hooks */ | 355 | /* Register sysfs hooks */ |
344 | if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) | 356 | if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) |
345 | goto exit_detach; | 357 | goto exit_free; |
346 | 358 | ||
347 | /* Register ADM1022 sysfs hooks */ | 359 | /* Register ADM1022 sysfs hooks */ |
348 | if (data->has_temp3) | 360 | if (data->has_temp3) |
@@ -364,34 +376,21 @@ exit_remove_sysfs: | |||
364 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | 376 | sysfs_remove_group(&client->dev.kobj, &temp3_group); |
365 | exit_remove_sysfs_thmc50: | 377 | exit_remove_sysfs_thmc50: |
366 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | 378 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); |
367 | exit_detach: | ||
368 | i2c_detach_client(client); | ||
369 | exit_free: | 379 | exit_free: |
370 | kfree(data); | 380 | kfree(data); |
371 | exit: | 381 | exit: |
372 | return err; | 382 | return err; |
373 | } | 383 | } |
374 | 384 | ||
375 | static int thmc50_attach_adapter(struct i2c_adapter *adapter) | 385 | static int thmc50_remove(struct i2c_client *client) |
376 | { | ||
377 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
378 | return 0; | ||
379 | return i2c_probe(adapter, &addr_data, thmc50_detect); | ||
380 | } | ||
381 | |||
382 | static int thmc50_detach_client(struct i2c_client *client) | ||
383 | { | 386 | { |
384 | struct thmc50_data *data = i2c_get_clientdata(client); | 387 | struct thmc50_data *data = i2c_get_clientdata(client); |
385 | int err; | ||
386 | 388 | ||
387 | hwmon_device_unregister(data->hwmon_dev); | 389 | hwmon_device_unregister(data->hwmon_dev); |
388 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | 390 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); |
389 | if (data->has_temp3) | 391 | if (data->has_temp3) |
390 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | 392 | sysfs_remove_group(&client->dev.kobj, &temp3_group); |
391 | 393 | ||
392 | if ((err = i2c_detach_client(client))) | ||
393 | return err; | ||
394 | |||
395 | kfree(data); | 394 | kfree(data); |
396 | 395 | ||
397 | return 0; | 396 | return 0; |
@@ -412,8 +411,8 @@ static void thmc50_init_client(struct i2c_client *client) | |||
412 | } | 411 | } |
413 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); | 412 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); |
414 | config |= 0x1; /* start the chip if it is in standby mode */ | 413 | config |= 0x1; /* start the chip if it is in standby mode */ |
415 | if (data->has_temp3) | 414 | if (data->type == adm1022 && (config & (1 << 7))) |
416 | config |= 0x80; /* enable 2nd remote temp */ | 415 | data->has_temp3 = 1; |
417 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); | 416 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); |
418 | } | 417 | } |
419 | 418 | ||
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 85077c4c8039..e4e91c9d480a 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -247,7 +247,6 @@ static u8 div_to_reg(int nr, long val) | |||
247 | } | 247 | } |
248 | 248 | ||
249 | struct w83791d_data { | 249 | struct w83791d_data { |
250 | struct i2c_client client; | ||
251 | struct device *hwmon_dev; | 250 | struct device *hwmon_dev; |
252 | struct mutex update_lock; | 251 | struct mutex update_lock; |
253 | 252 | ||
@@ -286,9 +285,11 @@ struct w83791d_data { | |||
286 | u8 vrm; /* hwmon-vid */ | 285 | u8 vrm; /* hwmon-vid */ |
287 | }; | 286 | }; |
288 | 287 | ||
289 | static int w83791d_attach_adapter(struct i2c_adapter *adapter); | 288 | static int w83791d_probe(struct i2c_client *client, |
290 | static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind); | 289 | const struct i2c_device_id *id); |
291 | static int w83791d_detach_client(struct i2c_client *client); | 290 | static int w83791d_detect(struct i2c_client *client, int kind, |
291 | struct i2c_board_info *info); | ||
292 | static int w83791d_remove(struct i2c_client *client); | ||
292 | 293 | ||
293 | static int w83791d_read(struct i2c_client *client, u8 register); | 294 | static int w83791d_read(struct i2c_client *client, u8 register); |
294 | static int w83791d_write(struct i2c_client *client, u8 register, u8 value); | 295 | static int w83791d_write(struct i2c_client *client, u8 register, u8 value); |
@@ -300,12 +301,22 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev); | |||
300 | 301 | ||
301 | static void w83791d_init_client(struct i2c_client *client); | 302 | static void w83791d_init_client(struct i2c_client *client); |
302 | 303 | ||
304 | static const struct i2c_device_id w83791d_id[] = { | ||
305 | { "w83791d", w83791d }, | ||
306 | { } | ||
307 | }; | ||
308 | MODULE_DEVICE_TABLE(i2c, w83791d_id); | ||
309 | |||
303 | static struct i2c_driver w83791d_driver = { | 310 | static struct i2c_driver w83791d_driver = { |
311 | .class = I2C_CLASS_HWMON, | ||
304 | .driver = { | 312 | .driver = { |
305 | .name = "w83791d", | 313 | .name = "w83791d", |
306 | }, | 314 | }, |
307 | .attach_adapter = w83791d_attach_adapter, | 315 | .probe = w83791d_probe, |
308 | .detach_client = w83791d_detach_client, | 316 | .remove = w83791d_remove, |
317 | .id_table = w83791d_id, | ||
318 | .detect = w83791d_detect, | ||
319 | .address_data = &addr_data, | ||
309 | }; | 320 | }; |
310 | 321 | ||
311 | /* following are the sysfs callback functions */ | 322 | /* following are the sysfs callback functions */ |
@@ -905,49 +916,12 @@ static const struct attribute_group w83791d_group = { | |||
905 | .attrs = w83791d_attributes, | 916 | .attrs = w83791d_attributes, |
906 | }; | 917 | }; |
907 | 918 | ||
908 | /* This function is called when: | ||
909 | * w83791d_driver is inserted (when this module is loaded), for each | ||
910 | available adapter | ||
911 | * when a new adapter is inserted (and w83791d_driver is still present) */ | ||
912 | static int w83791d_attach_adapter(struct i2c_adapter *adapter) | ||
913 | { | ||
914 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
915 | return 0; | ||
916 | return i2c_probe(adapter, &addr_data, w83791d_detect); | ||
917 | } | ||
918 | |||
919 | 919 | ||
920 | static int w83791d_create_subclient(struct i2c_adapter *adapter, | 920 | static int w83791d_detect_subclients(struct i2c_client *client) |
921 | struct i2c_client *client, int addr, | ||
922 | struct i2c_client **sub_cli) | ||
923 | { | ||
924 | int err; | ||
925 | struct i2c_client *sub_client; | ||
926 | |||
927 | (*sub_cli) = sub_client = | ||
928 | kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
929 | if (!(sub_client)) { | ||
930 | return -ENOMEM; | ||
931 | } | ||
932 | sub_client->addr = 0x48 + addr; | ||
933 | i2c_set_clientdata(sub_client, NULL); | ||
934 | sub_client->adapter = adapter; | ||
935 | sub_client->driver = &w83791d_driver; | ||
936 | strlcpy(sub_client->name, "w83791d subclient", I2C_NAME_SIZE); | ||
937 | if ((err = i2c_attach_client(sub_client))) { | ||
938 | dev_err(&client->dev, "subclient registration " | ||
939 | "at address 0x%x failed\n", sub_client->addr); | ||
940 | kfree(sub_client); | ||
941 | return err; | ||
942 | } | ||
943 | return 0; | ||
944 | } | ||
945 | |||
946 | |||
947 | static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | ||
948 | int kind, struct i2c_client *client) | ||
949 | { | 921 | { |
922 | struct i2c_adapter *adapter = client->adapter; | ||
950 | struct w83791d_data *data = i2c_get_clientdata(client); | 923 | struct w83791d_data *data = i2c_get_clientdata(client); |
924 | int address = client->addr; | ||
951 | int i, id, err; | 925 | int i, id, err; |
952 | u8 val; | 926 | u8 val; |
953 | 927 | ||
@@ -971,10 +945,7 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
971 | 945 | ||
972 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); | 946 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); |
973 | if (!(val & 0x08)) { | 947 | if (!(val & 0x08)) { |
974 | err = w83791d_create_subclient(adapter, client, | 948 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); |
975 | val & 0x7, &data->lm75[0]); | ||
976 | if (err < 0) | ||
977 | goto error_sc_0; | ||
978 | } | 949 | } |
979 | if (!(val & 0x80)) { | 950 | if (!(val & 0x80)) { |
980 | if ((data->lm75[0] != NULL) && | 951 | if ((data->lm75[0] != NULL) && |
@@ -986,10 +957,8 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
986 | err = -ENODEV; | 957 | err = -ENODEV; |
987 | goto error_sc_1; | 958 | goto error_sc_1; |
988 | } | 959 | } |
989 | err = w83791d_create_subclient(adapter, client, | 960 | data->lm75[1] = i2c_new_dummy(adapter, |
990 | (val >> 4) & 0x7, &data->lm75[1]); | 961 | 0x48 + ((val >> 4) & 0x7)); |
991 | if (err < 0) | ||
992 | goto error_sc_1; | ||
993 | } | 962 | } |
994 | 963 | ||
995 | return 0; | 964 | return 0; |
@@ -997,53 +966,31 @@ static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, | |||
997 | /* Undo inits in case of errors */ | 966 | /* Undo inits in case of errors */ |
998 | 967 | ||
999 | error_sc_1: | 968 | error_sc_1: |
1000 | if (data->lm75[0] != NULL) { | 969 | if (data->lm75[0] != NULL) |
1001 | i2c_detach_client(data->lm75[0]); | 970 | i2c_unregister_device(data->lm75[0]); |
1002 | kfree(data->lm75[0]); | ||
1003 | } | ||
1004 | error_sc_0: | 971 | error_sc_0: |
1005 | return err; | 972 | return err; |
1006 | } | 973 | } |
1007 | 974 | ||
1008 | 975 | ||
1009 | static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | 976 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
977 | static int w83791d_detect(struct i2c_client *client, int kind, | ||
978 | struct i2c_board_info *info) | ||
1010 | { | 979 | { |
1011 | struct i2c_client *client; | 980 | struct i2c_adapter *adapter = client->adapter; |
1012 | struct device *dev; | 981 | int val1, val2; |
1013 | struct w83791d_data *data; | 982 | unsigned short address = client->addr; |
1014 | int i, val1, val2; | ||
1015 | int err = 0; | ||
1016 | const char *client_name = ""; | ||
1017 | 983 | ||
1018 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 984 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1019 | goto error0; | 985 | return -ENODEV; |
1020 | } | 986 | } |
1021 | 987 | ||
1022 | /* OK. For now, we presume we have a valid client. We now create the | ||
1023 | client structure, even though we cannot fill it completely yet. | ||
1024 | But it allows us to access w83791d_{read,write}_value. */ | ||
1025 | if (!(data = kzalloc(sizeof(struct w83791d_data), GFP_KERNEL))) { | ||
1026 | err = -ENOMEM; | ||
1027 | goto error0; | ||
1028 | } | ||
1029 | |||
1030 | client = &data->client; | ||
1031 | dev = &client->dev; | ||
1032 | i2c_set_clientdata(client, data); | ||
1033 | client->addr = address; | ||
1034 | client->adapter = adapter; | ||
1035 | client->driver = &w83791d_driver; | ||
1036 | mutex_init(&data->update_lock); | ||
1037 | |||
1038 | /* Now, we do the remaining detection. */ | ||
1039 | |||
1040 | /* The w83791d may be stuck in some other bank than bank 0. This may | 988 | /* The w83791d may be stuck in some other bank than bank 0. This may |
1041 | make reading other information impossible. Specify a force=... | 989 | make reading other information impossible. Specify a force=... |
1042 | parameter, and the Winbond will be reset to the right bank. */ | 990 | parameter, and the Winbond will be reset to the right bank. */ |
1043 | if (kind < 0) { | 991 | if (kind < 0) { |
1044 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { | 992 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { |
1045 | dev_dbg(dev, "Detection failed at step 1\n"); | 993 | return -ENODEV; |
1046 | goto error1; | ||
1047 | } | 994 | } |
1048 | val1 = w83791d_read(client, W83791D_REG_BANK); | 995 | val1 = w83791d_read(client, W83791D_REG_BANK); |
1049 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 996 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
@@ -1052,15 +999,13 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1052 | /* yes it is Bank0 */ | 999 | /* yes it is Bank0 */ |
1053 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | 1000 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || |
1054 | ((val1 & 0x80) && (val2 != 0x5c))) { | 1001 | ((val1 & 0x80) && (val2 != 0x5c))) { |
1055 | dev_dbg(dev, "Detection failed at step 2\n"); | 1002 | return -ENODEV; |
1056 | goto error1; | ||
1057 | } | 1003 | } |
1058 | } | 1004 | } |
1059 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR | 1005 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR |
1060 | should match */ | 1006 | should match */ |
1061 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { | 1007 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { |
1062 | dev_dbg(dev, "Detection failed at step 3\n"); | 1008 | return -ENODEV; |
1063 | goto error1; | ||
1064 | } | 1009 | } |
1065 | } | 1010 | } |
1066 | 1011 | ||
@@ -1075,30 +1020,33 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1075 | /* get vendor ID */ | 1020 | /* get vendor ID */ |
1076 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 1021 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
1077 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1022 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ |
1078 | dev_dbg(dev, "Detection failed at step 4\n"); | 1023 | return -ENODEV; |
1079 | goto error1; | ||
1080 | } | 1024 | } |
1081 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); | 1025 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); |
1082 | if (val1 == 0x71) { | 1026 | if (val1 == 0x71) { |
1083 | kind = w83791d; | 1027 | kind = w83791d; |
1084 | } else { | 1028 | } else { |
1085 | if (kind == 0) | 1029 | if (kind == 0) |
1086 | dev_warn(dev, | 1030 | dev_warn(&adapter->dev, |
1087 | "w83791d: Ignoring 'force' parameter " | 1031 | "w83791d: Ignoring 'force' parameter " |
1088 | "for unknown chip at adapter %d, " | 1032 | "for unknown chip at adapter %d, " |
1089 | "address 0x%02x\n", | 1033 | "address 0x%02x\n", |
1090 | i2c_adapter_id(adapter), address); | 1034 | i2c_adapter_id(adapter), address); |
1091 | goto error1; | 1035 | return -ENODEV; |
1092 | } | 1036 | } |
1093 | } | 1037 | } |
1094 | 1038 | ||
1095 | if (kind == w83791d) { | 1039 | strlcpy(info->type, "w83791d", I2C_NAME_SIZE); |
1096 | client_name = "w83791d"; | 1040 | |
1097 | } else { | 1041 | return 0; |
1098 | dev_err(dev, "w83791d: Internal error: unknown kind (%d)?!?\n", | 1042 | } |
1099 | kind); | 1043 | |
1100 | goto error1; | 1044 | static int w83791d_probe(struct i2c_client *client, |
1101 | } | 1045 | const struct i2c_device_id *id) |
1046 | { | ||
1047 | struct w83791d_data *data; | ||
1048 | struct device *dev = &client->dev; | ||
1049 | int i, val1, err; | ||
1102 | 1050 | ||
1103 | #ifdef DEBUG | 1051 | #ifdef DEBUG |
1104 | val1 = w83791d_read(client, W83791D_REG_DID_VID4); | 1052 | val1 = w83791d_read(client, W83791D_REG_DID_VID4); |
@@ -1106,15 +1054,18 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1106 | (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); | 1054 | (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); |
1107 | #endif | 1055 | #endif |
1108 | 1056 | ||
1109 | /* Fill in the remaining client fields and put into the global list */ | 1057 | data = kzalloc(sizeof(struct w83791d_data), GFP_KERNEL); |
1110 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 1058 | if (!data) { |
1059 | err = -ENOMEM; | ||
1060 | goto error0; | ||
1061 | } | ||
1111 | 1062 | ||
1112 | /* Tell the I2C layer a new client has arrived */ | 1063 | i2c_set_clientdata(client, data); |
1113 | if ((err = i2c_attach_client(client))) | 1064 | mutex_init(&data->update_lock); |
1114 | goto error1; | ||
1115 | 1065 | ||
1116 | if ((err = w83791d_detect_subclients(adapter, address, kind, client))) | 1066 | err = w83791d_detect_subclients(client); |
1117 | goto error2; | 1067 | if (err) |
1068 | goto error1; | ||
1118 | 1069 | ||
1119 | /* Initialize the chip */ | 1070 | /* Initialize the chip */ |
1120 | w83791d_init_client(client); | 1071 | w83791d_init_client(client); |
@@ -1141,43 +1092,29 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1141 | error4: | 1092 | error4: |
1142 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); | 1093 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
1143 | error3: | 1094 | error3: |
1144 | if (data->lm75[0] != NULL) { | 1095 | if (data->lm75[0] != NULL) |
1145 | i2c_detach_client(data->lm75[0]); | 1096 | i2c_unregister_device(data->lm75[0]); |
1146 | kfree(data->lm75[0]); | 1097 | if (data->lm75[1] != NULL) |
1147 | } | 1098 | i2c_unregister_device(data->lm75[1]); |
1148 | if (data->lm75[1] != NULL) { | ||
1149 | i2c_detach_client(data->lm75[1]); | ||
1150 | kfree(data->lm75[1]); | ||
1151 | } | ||
1152 | error2: | ||
1153 | i2c_detach_client(client); | ||
1154 | error1: | 1099 | error1: |
1155 | kfree(data); | 1100 | kfree(data); |
1156 | error0: | 1101 | error0: |
1157 | return err; | 1102 | return err; |
1158 | } | 1103 | } |
1159 | 1104 | ||
1160 | static int w83791d_detach_client(struct i2c_client *client) | 1105 | static int w83791d_remove(struct i2c_client *client) |
1161 | { | 1106 | { |
1162 | struct w83791d_data *data = i2c_get_clientdata(client); | 1107 | struct w83791d_data *data = i2c_get_clientdata(client); |
1163 | int err; | ||
1164 | |||
1165 | /* main client */ | ||
1166 | if (data) { | ||
1167 | hwmon_device_unregister(data->hwmon_dev); | ||
1168 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); | ||
1169 | } | ||
1170 | 1108 | ||
1171 | if ((err = i2c_detach_client(client))) | 1109 | hwmon_device_unregister(data->hwmon_dev); |
1172 | return err; | 1110 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
1173 | 1111 | ||
1174 | /* main client */ | 1112 | if (data->lm75[0] != NULL) |
1175 | if (data) | 1113 | i2c_unregister_device(data->lm75[0]); |
1176 | kfree(data); | 1114 | if (data->lm75[1] != NULL) |
1177 | /* subclient */ | 1115 | i2c_unregister_device(data->lm75[1]); |
1178 | else | ||
1179 | kfree(client); | ||
1180 | 1116 | ||
1117 | kfree(data); | ||
1181 | return 0; | 1118 | return 0; |
1182 | } | 1119 | } |
1183 | 1120 | ||
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 299629d47ed6..cf94c5b0c879 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -267,9 +267,7 @@ DIV_TO_REG(long val) | |||
267 | } | 267 | } |
268 | 268 | ||
269 | struct w83792d_data { | 269 | struct w83792d_data { |
270 | struct i2c_client client; | ||
271 | struct device *hwmon_dev; | 270 | struct device *hwmon_dev; |
272 | enum chips type; | ||
273 | 271 | ||
274 | struct mutex update_lock; | 272 | struct mutex update_lock; |
275 | char valid; /* !=0 if following fields are valid */ | 273 | char valid; /* !=0 if following fields are valid */ |
@@ -299,9 +297,11 @@ struct w83792d_data { | |||
299 | u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ | 297 | u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ |
300 | }; | 298 | }; |
301 | 299 | ||
302 | static int w83792d_attach_adapter(struct i2c_adapter *adapter); | 300 | static int w83792d_probe(struct i2c_client *client, |
303 | static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind); | 301 | const struct i2c_device_id *id); |
304 | static int w83792d_detach_client(struct i2c_client *client); | 302 | static int w83792d_detect(struct i2c_client *client, int kind, |
303 | struct i2c_board_info *info); | ||
304 | static int w83792d_remove(struct i2c_client *client); | ||
305 | static struct w83792d_data *w83792d_update_device(struct device *dev); | 305 | static struct w83792d_data *w83792d_update_device(struct device *dev); |
306 | 306 | ||
307 | #ifdef DEBUG | 307 | #ifdef DEBUG |
@@ -310,12 +310,22 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev); | |||
310 | 310 | ||
311 | static void w83792d_init_client(struct i2c_client *client); | 311 | static void w83792d_init_client(struct i2c_client *client); |
312 | 312 | ||
313 | static const struct i2c_device_id w83792d_id[] = { | ||
314 | { "w83792d", w83792d }, | ||
315 | { } | ||
316 | }; | ||
317 | MODULE_DEVICE_TABLE(i2c, w83792d_id); | ||
318 | |||
313 | static struct i2c_driver w83792d_driver = { | 319 | static struct i2c_driver w83792d_driver = { |
320 | .class = I2C_CLASS_HWMON, | ||
314 | .driver = { | 321 | .driver = { |
315 | .name = "w83792d", | 322 | .name = "w83792d", |
316 | }, | 323 | }, |
317 | .attach_adapter = w83792d_attach_adapter, | 324 | .probe = w83792d_probe, |
318 | .detach_client = w83792d_detach_client, | 325 | .remove = w83792d_remove, |
326 | .id_table = w83792d_id, | ||
327 | .detect = w83792d_detect, | ||
328 | .address_data = &addr_data, | ||
319 | }; | 329 | }; |
320 | 330 | ||
321 | static inline long in_count_from_reg(int nr, struct w83792d_data *data) | 331 | static inline long in_count_from_reg(int nr, struct w83792d_data *data) |
@@ -864,53 +874,14 @@ store_sf2_level(struct device *dev, struct device_attribute *attr, | |||
864 | return count; | 874 | return count; |
865 | } | 875 | } |
866 | 876 | ||
867 | /* This function is called when: | ||
868 | * w83792d_driver is inserted (when this module is loaded), for each | ||
869 | available adapter | ||
870 | * when a new adapter is inserted (and w83792d_driver is still present) */ | ||
871 | static int | ||
872 | w83792d_attach_adapter(struct i2c_adapter *adapter) | ||
873 | { | ||
874 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
875 | return 0; | ||
876 | return i2c_probe(adapter, &addr_data, w83792d_detect); | ||
877 | } | ||
878 | |||
879 | |||
880 | static int | ||
881 | w83792d_create_subclient(struct i2c_adapter *adapter, | ||
882 | struct i2c_client *new_client, int addr, | ||
883 | struct i2c_client **sub_cli) | ||
884 | { | ||
885 | int err; | ||
886 | struct i2c_client *sub_client; | ||
887 | |||
888 | (*sub_cli) = sub_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
889 | if (!(sub_client)) { | ||
890 | return -ENOMEM; | ||
891 | } | ||
892 | sub_client->addr = 0x48 + addr; | ||
893 | i2c_set_clientdata(sub_client, NULL); | ||
894 | sub_client->adapter = adapter; | ||
895 | sub_client->driver = &w83792d_driver; | ||
896 | sub_client->flags = 0; | ||
897 | strlcpy(sub_client->name, "w83792d subclient", I2C_NAME_SIZE); | ||
898 | if ((err = i2c_attach_client(sub_client))) { | ||
899 | dev_err(&new_client->dev, "subclient registration " | ||
900 | "at address 0x%x failed\n", sub_client->addr); | ||
901 | kfree(sub_client); | ||
902 | return err; | ||
903 | } | ||
904 | return 0; | ||
905 | } | ||
906 | |||
907 | 877 | ||
908 | static int | 878 | static int |
909 | w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | 879 | w83792d_detect_subclients(struct i2c_client *new_client) |
910 | struct i2c_client *new_client) | ||
911 | { | 880 | { |
912 | int i, id, err; | 881 | int i, id, err; |
882 | int address = new_client->addr; | ||
913 | u8 val; | 883 | u8 val; |
884 | struct i2c_adapter *adapter = new_client->adapter; | ||
914 | struct w83792d_data *data = i2c_get_clientdata(new_client); | 885 | struct w83792d_data *data = i2c_get_clientdata(new_client); |
915 | 886 | ||
916 | id = i2c_adapter_id(adapter); | 887 | id = i2c_adapter_id(adapter); |
@@ -932,10 +903,7 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
932 | 903 | ||
933 | val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); | 904 | val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); |
934 | if (!(val & 0x08)) { | 905 | if (!(val & 0x08)) { |
935 | err = w83792d_create_subclient(adapter, new_client, val & 0x7, | 906 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); |
936 | &data->lm75[0]); | ||
937 | if (err < 0) | ||
938 | goto ERROR_SC_0; | ||
939 | } | 907 | } |
940 | if (!(val & 0x80)) { | 908 | if (!(val & 0x80)) { |
941 | if ((data->lm75[0] != NULL) && | 909 | if ((data->lm75[0] != NULL) && |
@@ -945,10 +913,8 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
945 | err = -ENODEV; | 913 | err = -ENODEV; |
946 | goto ERROR_SC_1; | 914 | goto ERROR_SC_1; |
947 | } | 915 | } |
948 | err = w83792d_create_subclient(adapter, new_client, | 916 | data->lm75[1] = i2c_new_dummy(adapter, |
949 | (val >> 4) & 0x7, &data->lm75[1]); | 917 | 0x48 + ((val >> 4) & 0x7)); |
950 | if (err < 0) | ||
951 | goto ERROR_SC_1; | ||
952 | } | 918 | } |
953 | 919 | ||
954 | return 0; | 920 | return 0; |
@@ -956,10 +922,8 @@ w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
956 | /* Undo inits in case of errors */ | 922 | /* Undo inits in case of errors */ |
957 | 923 | ||
958 | ERROR_SC_1: | 924 | ERROR_SC_1: |
959 | if (data->lm75[0] != NULL) { | 925 | if (data->lm75[0] != NULL) |
960 | i2c_detach_client(data->lm75[0]); | 926 | i2c_unregister_device(data->lm75[0]); |
961 | kfree(data->lm75[0]); | ||
962 | } | ||
963 | ERROR_SC_0: | 927 | ERROR_SC_0: |
964 | return err; | 928 | return err; |
965 | } | 929 | } |
@@ -1294,47 +1258,25 @@ static const struct attribute_group w83792d_group = { | |||
1294 | .attrs = w83792d_attributes, | 1258 | .attrs = w83792d_attributes, |
1295 | }; | 1259 | }; |
1296 | 1260 | ||
1261 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
1297 | static int | 1262 | static int |
1298 | w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | 1263 | w83792d_detect(struct i2c_client *client, int kind, struct i2c_board_info *info) |
1299 | { | 1264 | { |
1300 | int i = 0, val1 = 0, val2; | 1265 | struct i2c_adapter *adapter = client->adapter; |
1301 | struct i2c_client *client; | 1266 | int val1, val2; |
1302 | struct device *dev; | 1267 | unsigned short address = client->addr; |
1303 | struct w83792d_data *data; | ||
1304 | int err = 0; | ||
1305 | const char *client_name = ""; | ||
1306 | 1268 | ||
1307 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1269 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1308 | goto ERROR0; | 1270 | return -ENODEV; |
1309 | } | ||
1310 | |||
1311 | /* OK. For now, we presume we have a valid client. We now create the | ||
1312 | client structure, even though we cannot fill it completely yet. | ||
1313 | But it allows us to access w83792d_{read,write}_value. */ | ||
1314 | |||
1315 | if (!(data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL))) { | ||
1316 | err = -ENOMEM; | ||
1317 | goto ERROR0; | ||
1318 | } | 1271 | } |
1319 | 1272 | ||
1320 | client = &data->client; | ||
1321 | dev = &client->dev; | ||
1322 | i2c_set_clientdata(client, data); | ||
1323 | client->addr = address; | ||
1324 | client->adapter = adapter; | ||
1325 | client->driver = &w83792d_driver; | ||
1326 | client->flags = 0; | ||
1327 | |||
1328 | /* Now, we do the remaining detection. */ | ||
1329 | |||
1330 | /* The w83792d may be stuck in some other bank than bank 0. This may | 1273 | /* The w83792d may be stuck in some other bank than bank 0. This may |
1331 | make reading other information impossible. Specify a force=... or | 1274 | make reading other information impossible. Specify a force=... or |
1332 | force_*=... parameter, and the Winbond will be reset to the right | 1275 | force_*=... parameter, and the Winbond will be reset to the right |
1333 | bank. */ | 1276 | bank. */ |
1334 | if (kind < 0) { | 1277 | if (kind < 0) { |
1335 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { | 1278 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { |
1336 | dev_dbg(dev, "Detection failed at step 1\n"); | 1279 | return -ENODEV; |
1337 | goto ERROR1; | ||
1338 | } | 1280 | } |
1339 | val1 = w83792d_read_value(client, W83792D_REG_BANK); | 1281 | val1 = w83792d_read_value(client, W83792D_REG_BANK); |
1340 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | 1282 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
@@ -1342,16 +1284,14 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1342 | if (!(val1 & 0x07)) { /* is Bank0 */ | 1284 | if (!(val1 & 0x07)) { /* is Bank0 */ |
1343 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | 1285 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || |
1344 | ((val1 & 0x80) && (val2 != 0x5c))) { | 1286 | ((val1 & 0x80) && (val2 != 0x5c))) { |
1345 | dev_dbg(dev, "Detection failed at step 2\n"); | 1287 | return -ENODEV; |
1346 | goto ERROR1; | ||
1347 | } | 1288 | } |
1348 | } | 1289 | } |
1349 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR | 1290 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR |
1350 | should match */ | 1291 | should match */ |
1351 | if (w83792d_read_value(client, | 1292 | if (w83792d_read_value(client, |
1352 | W83792D_REG_I2C_ADDR) != address) { | 1293 | W83792D_REG_I2C_ADDR) != address) { |
1353 | dev_dbg(dev, "Detection failed at step 3\n"); | 1294 | return -ENODEV; |
1354 | goto ERROR1; | ||
1355 | } | 1295 | } |
1356 | } | 1296 | } |
1357 | 1297 | ||
@@ -1367,45 +1307,48 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1367 | /* get vendor ID */ | 1307 | /* get vendor ID */ |
1368 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | 1308 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
1369 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1309 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ |
1370 | goto ERROR1; | 1310 | return -ENODEV; |
1371 | } | 1311 | } |
1372 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); | 1312 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); |
1373 | if (val1 == 0x7a) { | 1313 | if (val1 == 0x7a) { |
1374 | kind = w83792d; | 1314 | kind = w83792d; |
1375 | } else { | 1315 | } else { |
1376 | if (kind == 0) | 1316 | if (kind == 0) |
1377 | dev_warn(dev, | 1317 | dev_warn(&adapter->dev, |
1378 | "w83792d: Ignoring 'force' parameter for" | 1318 | "w83792d: Ignoring 'force' parameter for" |
1379 | " unknown chip at adapter %d, address" | 1319 | " unknown chip at adapter %d, address" |
1380 | " 0x%02x\n", i2c_adapter_id(adapter), | 1320 | " 0x%02x\n", i2c_adapter_id(adapter), |
1381 | address); | 1321 | address); |
1382 | goto ERROR1; | 1322 | return -ENODEV; |
1383 | } | 1323 | } |
1384 | } | 1324 | } |
1385 | 1325 | ||
1386 | if (kind == w83792d) { | 1326 | strlcpy(info->type, "w83792d", I2C_NAME_SIZE); |
1387 | client_name = "w83792d"; | 1327 | |
1388 | } else { | 1328 | return 0; |
1389 | dev_err(dev, "w83792d: Internal error: unknown kind (%d)?!?\n", | 1329 | } |
1390 | kind); | 1330 | |
1391 | goto ERROR1; | 1331 | static int |
1392 | } | 1332 | w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id) |
1333 | { | ||
1334 | struct w83792d_data *data; | ||
1335 | struct device *dev = &client->dev; | ||
1336 | int i, val1, err; | ||
1393 | 1337 | ||
1394 | /* Fill in the remaining client fields and put into the global list */ | 1338 | data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL); |
1395 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 1339 | if (!data) { |
1396 | data->type = kind; | 1340 | err = -ENOMEM; |
1341 | goto ERROR0; | ||
1342 | } | ||
1397 | 1343 | ||
1344 | i2c_set_clientdata(client, data); | ||
1398 | data->valid = 0; | 1345 | data->valid = 0; |
1399 | mutex_init(&data->update_lock); | 1346 | mutex_init(&data->update_lock); |
1400 | 1347 | ||
1401 | /* Tell the I2C layer a new client has arrived */ | 1348 | err = w83792d_detect_subclients(client); |
1402 | if ((err = i2c_attach_client(client))) | 1349 | if (err) |
1403 | goto ERROR1; | 1350 | goto ERROR1; |
1404 | 1351 | ||
1405 | if ((err = w83792d_detect_subclients(adapter, address, | ||
1406 | kind, client))) | ||
1407 | goto ERROR2; | ||
1408 | |||
1409 | /* Initialize the chip */ | 1352 | /* Initialize the chip */ |
1410 | w83792d_init_client(client); | 1353 | w83792d_init_client(client); |
1411 | 1354 | ||
@@ -1457,16 +1400,10 @@ exit_remove_files: | |||
1457 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | 1400 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) |
1458 | sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); | 1401 | sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); |
1459 | ERROR3: | 1402 | ERROR3: |
1460 | if (data->lm75[0] != NULL) { | 1403 | if (data->lm75[0] != NULL) |
1461 | i2c_detach_client(data->lm75[0]); | 1404 | i2c_unregister_device(data->lm75[0]); |
1462 | kfree(data->lm75[0]); | 1405 | if (data->lm75[1] != NULL) |
1463 | } | 1406 | i2c_unregister_device(data->lm75[1]); |
1464 | if (data->lm75[1] != NULL) { | ||
1465 | i2c_detach_client(data->lm75[1]); | ||
1466 | kfree(data->lm75[1]); | ||
1467 | } | ||
1468 | ERROR2: | ||
1469 | i2c_detach_client(client); | ||
1470 | ERROR1: | 1407 | ERROR1: |
1471 | kfree(data); | 1408 | kfree(data); |
1472 | ERROR0: | 1409 | ERROR0: |
@@ -1474,30 +1411,23 @@ ERROR0: | |||
1474 | } | 1411 | } |
1475 | 1412 | ||
1476 | static int | 1413 | static int |
1477 | w83792d_detach_client(struct i2c_client *client) | 1414 | w83792d_remove(struct i2c_client *client) |
1478 | { | 1415 | { |
1479 | struct w83792d_data *data = i2c_get_clientdata(client); | 1416 | struct w83792d_data *data = i2c_get_clientdata(client); |
1480 | int err, i; | 1417 | int i; |
1481 | |||
1482 | /* main client */ | ||
1483 | if (data) { | ||
1484 | hwmon_device_unregister(data->hwmon_dev); | ||
1485 | sysfs_remove_group(&client->dev.kobj, &w83792d_group); | ||
1486 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | ||
1487 | sysfs_remove_group(&client->dev.kobj, | ||
1488 | &w83792d_group_fan[i]); | ||
1489 | } | ||
1490 | 1418 | ||
1491 | if ((err = i2c_detach_client(client))) | 1419 | hwmon_device_unregister(data->hwmon_dev); |
1492 | return err; | 1420 | sysfs_remove_group(&client->dev.kobj, &w83792d_group); |
1421 | for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) | ||
1422 | sysfs_remove_group(&client->dev.kobj, | ||
1423 | &w83792d_group_fan[i]); | ||
1493 | 1424 | ||
1494 | /* main client */ | 1425 | if (data->lm75[0] != NULL) |
1495 | if (data) | 1426 | i2c_unregister_device(data->lm75[0]); |
1496 | kfree(data); | 1427 | if (data->lm75[1] != NULL) |
1497 | /* subclient */ | 1428 | i2c_unregister_device(data->lm75[1]); |
1498 | else | ||
1499 | kfree(client); | ||
1500 | 1429 | ||
1430 | kfree(data); | ||
1501 | return 0; | 1431 | return 0; |
1502 | } | 1432 | } |
1503 | 1433 | ||
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index ed3c019b78c7..0a739f1c69be 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c | |||
@@ -179,7 +179,6 @@ static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) | |||
179 | } | 179 | } |
180 | 180 | ||
181 | struct w83793_data { | 181 | struct w83793_data { |
182 | struct i2c_client client; | ||
183 | struct i2c_client *lm75[2]; | 182 | struct i2c_client *lm75[2]; |
184 | struct device *hwmon_dev; | 183 | struct device *hwmon_dev; |
185 | struct mutex update_lock; | 184 | struct mutex update_lock; |
@@ -226,19 +225,31 @@ struct w83793_data { | |||
226 | 225 | ||
227 | static u8 w83793_read_value(struct i2c_client *client, u16 reg); | 226 | static u8 w83793_read_value(struct i2c_client *client, u16 reg); |
228 | static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); | 227 | static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); |
229 | static int w83793_attach_adapter(struct i2c_adapter *adapter); | 228 | static int w83793_probe(struct i2c_client *client, |
230 | static int w83793_detect(struct i2c_adapter *adapter, int address, int kind); | 229 | const struct i2c_device_id *id); |
231 | static int w83793_detach_client(struct i2c_client *client); | 230 | static int w83793_detect(struct i2c_client *client, int kind, |
231 | struct i2c_board_info *info); | ||
232 | static int w83793_remove(struct i2c_client *client); | ||
232 | static void w83793_init_client(struct i2c_client *client); | 233 | static void w83793_init_client(struct i2c_client *client); |
233 | static void w83793_update_nonvolatile(struct device *dev); | 234 | static void w83793_update_nonvolatile(struct device *dev); |
234 | static struct w83793_data *w83793_update_device(struct device *dev); | 235 | static struct w83793_data *w83793_update_device(struct device *dev); |
235 | 236 | ||
237 | static const struct i2c_device_id w83793_id[] = { | ||
238 | { "w83793", w83793 }, | ||
239 | { } | ||
240 | }; | ||
241 | MODULE_DEVICE_TABLE(i2c, w83793_id); | ||
242 | |||
236 | static struct i2c_driver w83793_driver = { | 243 | static struct i2c_driver w83793_driver = { |
244 | .class = I2C_CLASS_HWMON, | ||
237 | .driver = { | 245 | .driver = { |
238 | .name = "w83793", | 246 | .name = "w83793", |
239 | }, | 247 | }, |
240 | .attach_adapter = w83793_attach_adapter, | 248 | .probe = w83793_probe, |
241 | .detach_client = w83793_detach_client, | 249 | .remove = w83793_remove, |
250 | .id_table = w83793_id, | ||
251 | .detect = w83793_detect, | ||
252 | .address_data = &addr_data, | ||
242 | }; | 253 | }; |
243 | 254 | ||
244 | static ssize_t | 255 | static ssize_t |
@@ -1053,89 +1064,51 @@ static void w83793_init_client(struct i2c_client *client) | |||
1053 | 1064 | ||
1054 | } | 1065 | } |
1055 | 1066 | ||
1056 | static int w83793_attach_adapter(struct i2c_adapter *adapter) | 1067 | static int w83793_remove(struct i2c_client *client) |
1057 | { | ||
1058 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
1059 | return 0; | ||
1060 | return i2c_probe(adapter, &addr_data, w83793_detect); | ||
1061 | } | ||
1062 | |||
1063 | static int w83793_detach_client(struct i2c_client *client) | ||
1064 | { | 1068 | { |
1065 | struct w83793_data *data = i2c_get_clientdata(client); | 1069 | struct w83793_data *data = i2c_get_clientdata(client); |
1066 | struct device *dev = &client->dev; | 1070 | struct device *dev = &client->dev; |
1067 | int err, i; | 1071 | int i; |
1068 | 1072 | ||
1069 | /* main client */ | 1073 | hwmon_device_unregister(data->hwmon_dev); |
1070 | if (data) { | ||
1071 | hwmon_device_unregister(data->hwmon_dev); | ||
1072 | 1074 | ||
1073 | for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) | 1075 | for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) |
1074 | device_remove_file(dev, | 1076 | device_remove_file(dev, |
1075 | &w83793_sensor_attr_2[i].dev_attr); | 1077 | &w83793_sensor_attr_2[i].dev_attr); |
1076 | 1078 | ||
1077 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) | 1079 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) |
1078 | device_remove_file(dev, &sda_single_files[i].dev_attr); | 1080 | device_remove_file(dev, &sda_single_files[i].dev_attr); |
1079 | 1081 | ||
1080 | for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) | 1082 | for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) |
1081 | device_remove_file(dev, &w83793_vid[i].dev_attr); | 1083 | device_remove_file(dev, &w83793_vid[i].dev_attr); |
1082 | device_remove_file(dev, &dev_attr_vrm); | 1084 | device_remove_file(dev, &dev_attr_vrm); |
1083 | 1085 | ||
1084 | for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) | 1086 | for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) |
1085 | device_remove_file(dev, &w83793_left_fan[i].dev_attr); | 1087 | device_remove_file(dev, &w83793_left_fan[i].dev_attr); |
1086 | 1088 | ||
1087 | for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) | 1089 | for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) |
1088 | device_remove_file(dev, &w83793_left_pwm[i].dev_attr); | 1090 | device_remove_file(dev, &w83793_left_pwm[i].dev_attr); |
1089 | 1091 | ||
1090 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) | 1092 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
1091 | device_remove_file(dev, &w83793_temp[i].dev_attr); | 1093 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
1092 | } | ||
1093 | 1094 | ||
1094 | if ((err = i2c_detach_client(client))) | 1095 | if (data->lm75[0] != NULL) |
1095 | return err; | 1096 | i2c_unregister_device(data->lm75[0]); |
1097 | if (data->lm75[1] != NULL) | ||
1098 | i2c_unregister_device(data->lm75[1]); | ||
1096 | 1099 | ||
1097 | /* main client */ | 1100 | kfree(data); |
1098 | if (data) | ||
1099 | kfree(data); | ||
1100 | /* subclient */ | ||
1101 | else | ||
1102 | kfree(client); | ||
1103 | 1101 | ||
1104 | return 0; | 1102 | return 0; |
1105 | } | 1103 | } |
1106 | 1104 | ||
1107 | static int | 1105 | static int |
1108 | w83793_create_subclient(struct i2c_adapter *adapter, | 1106 | w83793_detect_subclients(struct i2c_client *client) |
1109 | struct i2c_client *client, int addr, | ||
1110 | struct i2c_client **sub_cli) | ||
1111 | { | ||
1112 | int err = 0; | ||
1113 | struct i2c_client *sub_client; | ||
1114 | |||
1115 | (*sub_cli) = sub_client = | ||
1116 | kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
1117 | if (!(sub_client)) { | ||
1118 | return -ENOMEM; | ||
1119 | } | ||
1120 | sub_client->addr = 0x48 + addr; | ||
1121 | i2c_set_clientdata(sub_client, NULL); | ||
1122 | sub_client->adapter = adapter; | ||
1123 | sub_client->driver = &w83793_driver; | ||
1124 | strlcpy(sub_client->name, "w83793 subclient", I2C_NAME_SIZE); | ||
1125 | if ((err = i2c_attach_client(sub_client))) { | ||
1126 | dev_err(&client->dev, "subclient registration " | ||
1127 | "at address 0x%x failed\n", sub_client->addr); | ||
1128 | kfree(sub_client); | ||
1129 | } | ||
1130 | return err; | ||
1131 | } | ||
1132 | |||
1133 | static int | ||
1134 | w83793_detect_subclients(struct i2c_adapter *adapter, int address, | ||
1135 | int kind, struct i2c_client *client) | ||
1136 | { | 1107 | { |
1137 | int i, id, err; | 1108 | int i, id, err; |
1109 | int address = client->addr; | ||
1138 | u8 tmp; | 1110 | u8 tmp; |
1111 | struct i2c_adapter *adapter = client->adapter; | ||
1139 | struct w83793_data *data = i2c_get_clientdata(client); | 1112 | struct w83793_data *data = i2c_get_clientdata(client); |
1140 | 1113 | ||
1141 | id = i2c_adapter_id(adapter); | 1114 | id = i2c_adapter_id(adapter); |
@@ -1158,11 +1131,7 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1158 | 1131 | ||
1159 | tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); | 1132 | tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); |
1160 | if (!(tmp & 0x08)) { | 1133 | if (!(tmp & 0x08)) { |
1161 | err = | 1134 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); |
1162 | w83793_create_subclient(adapter, client, tmp & 0x7, | ||
1163 | &data->lm75[0]); | ||
1164 | if (err < 0) | ||
1165 | goto ERROR_SC_0; | ||
1166 | } | 1135 | } |
1167 | if (!(tmp & 0x80)) { | 1136 | if (!(tmp & 0x80)) { |
1168 | if ((data->lm75[0] != NULL) | 1137 | if ((data->lm75[0] != NULL) |
@@ -1173,10 +1142,8 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1173 | err = -ENODEV; | 1142 | err = -ENODEV; |
1174 | goto ERROR_SC_1; | 1143 | goto ERROR_SC_1; |
1175 | } | 1144 | } |
1176 | err = w83793_create_subclient(adapter, client, | 1145 | data->lm75[1] = i2c_new_dummy(adapter, |
1177 | (tmp >> 4) & 0x7, &data->lm75[1]); | 1146 | 0x48 + ((tmp >> 4) & 0x7)); |
1178 | if (err < 0) | ||
1179 | goto ERROR_SC_1; | ||
1180 | } | 1147 | } |
1181 | 1148 | ||
1182 | return 0; | 1149 | return 0; |
@@ -1184,69 +1151,44 @@ w83793_detect_subclients(struct i2c_adapter *adapter, int address, | |||
1184 | /* Undo inits in case of errors */ | 1151 | /* Undo inits in case of errors */ |
1185 | 1152 | ||
1186 | ERROR_SC_1: | 1153 | ERROR_SC_1: |
1187 | if (data->lm75[0] != NULL) { | 1154 | if (data->lm75[0] != NULL) |
1188 | i2c_detach_client(data->lm75[0]); | 1155 | i2c_unregister_device(data->lm75[0]); |
1189 | kfree(data->lm75[0]); | ||
1190 | } | ||
1191 | ERROR_SC_0: | 1156 | ERROR_SC_0: |
1192 | return err; | 1157 | return err; |
1193 | } | 1158 | } |
1194 | 1159 | ||
1195 | static int w83793_detect(struct i2c_adapter *adapter, int address, int kind) | 1160 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1161 | static int w83793_detect(struct i2c_client *client, int kind, | ||
1162 | struct i2c_board_info *info) | ||
1196 | { | 1163 | { |
1197 | int i; | 1164 | u8 tmp, bank; |
1198 | u8 tmp, val; | 1165 | struct i2c_adapter *adapter = client->adapter; |
1199 | struct i2c_client *client; | 1166 | unsigned short address = client->addr; |
1200 | struct device *dev; | ||
1201 | struct w83793_data *data; | ||
1202 | int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; | ||
1203 | int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; | ||
1204 | int files_temp = ARRAY_SIZE(w83793_temp) / 6; | ||
1205 | int err = 0; | ||
1206 | 1167 | ||
1207 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1168 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1208 | goto exit; | 1169 | return -ENODEV; |
1209 | } | 1170 | } |
1210 | 1171 | ||
1211 | /* OK. For now, we presume we have a valid client. We now create the | 1172 | bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); |
1212 | client structure, even though we cannot fill it completely yet. | ||
1213 | But it allows us to access w83793_{read,write}_value. */ | ||
1214 | |||
1215 | if (!(data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL))) { | ||
1216 | err = -ENOMEM; | ||
1217 | goto exit; | ||
1218 | } | ||
1219 | |||
1220 | client = &data->client; | ||
1221 | dev = &client->dev; | ||
1222 | i2c_set_clientdata(client, data); | ||
1223 | client->addr = address; | ||
1224 | client->adapter = adapter; | ||
1225 | client->driver = &w83793_driver; | ||
1226 | 1173 | ||
1227 | data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); | ||
1228 | |||
1229 | /* Now, we do the remaining detection. */ | ||
1230 | if (kind < 0) { | 1174 | if (kind < 0) { |
1231 | tmp = data->bank & 0x80 ? 0x5c : 0xa3; | 1175 | tmp = bank & 0x80 ? 0x5c : 0xa3; |
1232 | /* Check Winbond vendor ID */ | 1176 | /* Check Winbond vendor ID */ |
1233 | if (tmp != i2c_smbus_read_byte_data(client, | 1177 | if (tmp != i2c_smbus_read_byte_data(client, |
1234 | W83793_REG_VENDORID)) { | 1178 | W83793_REG_VENDORID)) { |
1235 | pr_debug("w83793: Detection failed at check " | 1179 | pr_debug("w83793: Detection failed at check " |
1236 | "vendor id\n"); | 1180 | "vendor id\n"); |
1237 | err = -ENODEV; | 1181 | return -ENODEV; |
1238 | goto free_mem; | ||
1239 | } | 1182 | } |
1240 | 1183 | ||
1241 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR | 1184 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR |
1242 | should match */ | 1185 | should match */ |
1243 | if ((data->bank & 0x07) == 0 | 1186 | if ((bank & 0x07) == 0 |
1244 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != | 1187 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != |
1245 | (address << 1)) { | 1188 | (address << 1)) { |
1246 | pr_debug("w83793: Detection failed at check " | 1189 | pr_debug("w83793: Detection failed at check " |
1247 | "i2c addr\n"); | 1190 | "i2c addr\n"); |
1248 | err = -ENODEV; | 1191 | return -ENODEV; |
1249 | goto free_mem; | ||
1250 | } | 1192 | } |
1251 | 1193 | ||
1252 | } | 1194 | } |
@@ -1255,30 +1197,47 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1255 | Winbond. Determine the chip type now */ | 1197 | Winbond. Determine the chip type now */ |
1256 | 1198 | ||
1257 | if (kind <= 0) { | 1199 | if (kind <= 0) { |
1258 | if (0x7b == w83793_read_value(client, W83793_REG_CHIPID)) { | 1200 | if (0x7b == i2c_smbus_read_byte_data(client, |
1201 | W83793_REG_CHIPID)) { | ||
1259 | kind = w83793; | 1202 | kind = w83793; |
1260 | } else { | 1203 | } else { |
1261 | if (kind == 0) | 1204 | if (kind == 0) |
1262 | dev_warn(&adapter->dev, "w83793: Ignoring " | 1205 | dev_warn(&adapter->dev, "w83793: Ignoring " |
1263 | "'force' parameter for unknown chip " | 1206 | "'force' parameter for unknown chip " |
1264 | "at address 0x%02x\n", address); | 1207 | "at address 0x%02x\n", address); |
1265 | err = -ENODEV; | 1208 | return -ENODEV; |
1266 | goto free_mem; | ||
1267 | } | 1209 | } |
1268 | } | 1210 | } |
1269 | 1211 | ||
1270 | /* Fill in the remaining client fields and put into the global list */ | 1212 | strlcpy(info->type, "w83793", I2C_NAME_SIZE); |
1271 | strlcpy(client->name, "w83793", I2C_NAME_SIZE); | 1213 | |
1214 | return 0; | ||
1215 | } | ||
1272 | 1216 | ||
1217 | static int w83793_probe(struct i2c_client *client, | ||
1218 | const struct i2c_device_id *id) | ||
1219 | { | ||
1220 | struct device *dev = &client->dev; | ||
1221 | struct w83793_data *data; | ||
1222 | int i, tmp, val, err; | ||
1223 | int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; | ||
1224 | int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; | ||
1225 | int files_temp = ARRAY_SIZE(w83793_temp) / 6; | ||
1226 | |||
1227 | data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL); | ||
1228 | if (!data) { | ||
1229 | err = -ENOMEM; | ||
1230 | goto exit; | ||
1231 | } | ||
1232 | |||
1233 | i2c_set_clientdata(client, data); | ||
1234 | data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); | ||
1273 | mutex_init(&data->update_lock); | 1235 | mutex_init(&data->update_lock); |
1274 | 1236 | ||
1275 | /* Tell the I2C layer a new client has arrived */ | 1237 | err = w83793_detect_subclients(client); |
1276 | if ((err = i2c_attach_client(client))) | 1238 | if (err) |
1277 | goto free_mem; | 1239 | goto free_mem; |
1278 | 1240 | ||
1279 | if ((err = w83793_detect_subclients(adapter, address, kind, client))) | ||
1280 | goto detach_client; | ||
1281 | |||
1282 | /* Initialize the chip */ | 1241 | /* Initialize the chip */ |
1283 | w83793_init_client(client); | 1242 | w83793_init_client(client); |
1284 | 1243 | ||
@@ -1459,16 +1418,10 @@ exit_remove: | |||
1459 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) | 1418 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
1460 | device_remove_file(dev, &w83793_temp[i].dev_attr); | 1419 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
1461 | 1420 | ||
1462 | if (data->lm75[0] != NULL) { | 1421 | if (data->lm75[0] != NULL) |
1463 | i2c_detach_client(data->lm75[0]); | 1422 | i2c_unregister_device(data->lm75[0]); |
1464 | kfree(data->lm75[0]); | 1423 | if (data->lm75[1] != NULL) |
1465 | } | 1424 | i2c_unregister_device(data->lm75[1]); |
1466 | if (data->lm75[1] != NULL) { | ||
1467 | i2c_detach_client(data->lm75[1]); | ||
1468 | kfree(data->lm75[1]); | ||
1469 | } | ||
1470 | detach_client: | ||
1471 | i2c_detach_client(client); | ||
1472 | free_mem: | 1425 | free_mem: |
1473 | kfree(data); | 1426 | kfree(data); |
1474 | exit: | 1427 | exit: |
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 52e268e25dab..ea295b9fc4f4 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c | |||
@@ -81,10 +81,11 @@ I2C_CLIENT_INSMOD_1(w83l785ts); | |||
81 | * Functions declaration | 81 | * Functions declaration |
82 | */ | 82 | */ |
83 | 83 | ||
84 | static int w83l785ts_attach_adapter(struct i2c_adapter *adapter); | 84 | static int w83l785ts_probe(struct i2c_client *client, |
85 | static int w83l785ts_detect(struct i2c_adapter *adapter, int address, | 85 | const struct i2c_device_id *id); |
86 | int kind); | 86 | static int w83l785ts_detect(struct i2c_client *client, int kind, |
87 | static int w83l785ts_detach_client(struct i2c_client *client); | 87 | struct i2c_board_info *info); |
88 | static int w83l785ts_remove(struct i2c_client *client); | ||
88 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); | 89 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); |
89 | static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); | 90 | static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); |
90 | 91 | ||
@@ -92,12 +93,22 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev); | |||
92 | * Driver data (common to all clients) | 93 | * Driver data (common to all clients) |
93 | */ | 94 | */ |
94 | 95 | ||
96 | static const struct i2c_device_id w83l785ts_id[] = { | ||
97 | { "w83l785ts", w83l785ts }, | ||
98 | { } | ||
99 | }; | ||
100 | MODULE_DEVICE_TABLE(i2c, w83l785ts_id); | ||
101 | |||
95 | static struct i2c_driver w83l785ts_driver = { | 102 | static struct i2c_driver w83l785ts_driver = { |
103 | .class = I2C_CLASS_HWMON, | ||
96 | .driver = { | 104 | .driver = { |
97 | .name = "w83l785ts", | 105 | .name = "w83l785ts", |
98 | }, | 106 | }, |
99 | .attach_adapter = w83l785ts_attach_adapter, | 107 | .probe = w83l785ts_probe, |
100 | .detach_client = w83l785ts_detach_client, | 108 | .remove = w83l785ts_remove, |
109 | .id_table = w83l785ts_id, | ||
110 | .detect = w83l785ts_detect, | ||
111 | .address_data = &addr_data, | ||
101 | }; | 112 | }; |
102 | 113 | ||
103 | /* | 114 | /* |
@@ -105,7 +116,6 @@ static struct i2c_driver w83l785ts_driver = { | |||
105 | */ | 116 | */ |
106 | 117 | ||
107 | struct w83l785ts_data { | 118 | struct w83l785ts_data { |
108 | struct i2c_client client; | ||
109 | struct device *hwmon_dev; | 119 | struct device *hwmon_dev; |
110 | struct mutex update_lock; | 120 | struct mutex update_lock; |
111 | char valid; /* zero until following fields are valid */ | 121 | char valid; /* zero until following fields are valid */ |
@@ -135,40 +145,14 @@ static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1); | |||
135 | * Real code | 145 | * Real code |
136 | */ | 146 | */ |
137 | 147 | ||
138 | static int w83l785ts_attach_adapter(struct i2c_adapter *adapter) | 148 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
139 | { | 149 | static int w83l785ts_detect(struct i2c_client *new_client, int kind, |
140 | if (!(adapter->class & I2C_CLASS_HWMON)) | 150 | struct i2c_board_info *info) |
141 | return 0; | ||
142 | return i2c_probe(adapter, &addr_data, w83l785ts_detect); | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * The following function does more than just detection. If detection | ||
147 | * succeeds, it also registers the new chip. | ||
148 | */ | ||
149 | static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | ||
150 | { | 151 | { |
151 | struct i2c_client *new_client; | 152 | struct i2c_adapter *adapter = new_client->adapter; |
152 | struct w83l785ts_data *data; | ||
153 | int err = 0; | ||
154 | |||
155 | 153 | ||
156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 154 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
157 | goto exit; | 155 | return -ENODEV; |
158 | |||
159 | if (!(data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) { | ||
160 | err = -ENOMEM; | ||
161 | goto exit; | ||
162 | } | ||
163 | |||
164 | /* The common I2C client data is placed right before the | ||
165 | * W83L785TS-specific data. */ | ||
166 | new_client = &data->client; | ||
167 | i2c_set_clientdata(new_client, data); | ||
168 | new_client->addr = address; | ||
169 | new_client->adapter = adapter; | ||
170 | new_client->driver = &w83l785ts_driver; | ||
171 | new_client->flags = 0; | ||
172 | 156 | ||
173 | /* | 157 | /* |
174 | * Now we do the remaining detection. A negative kind means that | 158 | * Now we do the remaining detection. A negative kind means that |
@@ -188,8 +172,8 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
188 | W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) { | 172 | W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) { |
189 | dev_dbg(&adapter->dev, | 173 | dev_dbg(&adapter->dev, |
190 | "W83L785TS-S detection failed at 0x%02x.\n", | 174 | "W83L785TS-S detection failed at 0x%02x.\n", |
191 | address); | 175 | new_client->addr); |
192 | goto exit_free; | 176 | return -ENODEV; |
193 | } | 177 | } |
194 | } | 178 | } |
195 | 179 | ||
@@ -214,22 +198,34 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
214 | dev_info(&adapter->dev, | 198 | dev_info(&adapter->dev, |
215 | "Unsupported chip (man_id=0x%04X, " | 199 | "Unsupported chip (man_id=0x%04X, " |
216 | "chip_id=0x%02X).\n", man_id, chip_id); | 200 | "chip_id=0x%02X).\n", man_id, chip_id); |
217 | goto exit_free; | 201 | return -ENODEV; |
218 | } | 202 | } |
219 | } | 203 | } |
220 | 204 | ||
221 | /* We can fill in the remaining client fields. */ | 205 | strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE); |
222 | strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE); | 206 | |
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int w83l785ts_probe(struct i2c_client *new_client, | ||
211 | const struct i2c_device_id *id) | ||
212 | { | ||
213 | struct w83l785ts_data *data; | ||
214 | int err = 0; | ||
215 | |||
216 | data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL); | ||
217 | if (!data) { | ||
218 | err = -ENOMEM; | ||
219 | goto exit; | ||
220 | } | ||
221 | |||
222 | i2c_set_clientdata(new_client, data); | ||
223 | data->valid = 0; | 223 | data->valid = 0; |
224 | mutex_init(&data->update_lock); | 224 | mutex_init(&data->update_lock); |
225 | 225 | ||
226 | /* Default values in case the first read fails (unlikely). */ | 226 | /* Default values in case the first read fails (unlikely). */ |
227 | data->temp[1] = data->temp[0] = 0; | 227 | data->temp[1] = data->temp[0] = 0; |
228 | 228 | ||
229 | /* Tell the I2C layer a new client has arrived. */ | ||
230 | if ((err = i2c_attach_client(new_client))) | ||
231 | goto exit_free; | ||
232 | |||
233 | /* | 229 | /* |
234 | * Initialize the W83L785TS chip | 230 | * Initialize the W83L785TS chip |
235 | * Nothing yet, assume it is already started. | 231 | * Nothing yet, assume it is already started. |
@@ -259,25 +255,20 @@ exit_remove: | |||
259 | &sensor_dev_attr_temp1_input.dev_attr); | 255 | &sensor_dev_attr_temp1_input.dev_attr); |
260 | device_remove_file(&new_client->dev, | 256 | device_remove_file(&new_client->dev, |
261 | &sensor_dev_attr_temp1_max.dev_attr); | 257 | &sensor_dev_attr_temp1_max.dev_attr); |
262 | i2c_detach_client(new_client); | ||
263 | exit_free: | ||
264 | kfree(data); | 258 | kfree(data); |
265 | exit: | 259 | exit: |
266 | return err; | 260 | return err; |
267 | } | 261 | } |
268 | 262 | ||
269 | static int w83l785ts_detach_client(struct i2c_client *client) | 263 | static int w83l785ts_remove(struct i2c_client *client) |
270 | { | 264 | { |
271 | struct w83l785ts_data *data = i2c_get_clientdata(client); | 265 | struct w83l785ts_data *data = i2c_get_clientdata(client); |
272 | int err; | ||
273 | 266 | ||
274 | hwmon_device_unregister(data->hwmon_dev); | 267 | hwmon_device_unregister(data->hwmon_dev); |
275 | device_remove_file(&client->dev, | 268 | device_remove_file(&client->dev, |
276 | &sensor_dev_attr_temp1_input.dev_attr); | 269 | &sensor_dev_attr_temp1_input.dev_attr); |
277 | device_remove_file(&client->dev, | 270 | device_remove_file(&client->dev, |
278 | &sensor_dev_attr_temp1_max.dev_attr); | 271 | &sensor_dev_attr_temp1_max.dev_attr); |
279 | if ((err = i2c_detach_client(client))) | ||
280 | return err; | ||
281 | 272 | ||
282 | kfree(data); | 273 | kfree(data); |
283 | return 0; | 274 | return 0; |
@@ -286,6 +277,18 @@ static int w83l785ts_detach_client(struct i2c_client *client) | |||
286 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) | 277 | static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) |
287 | { | 278 | { |
288 | int value, i; | 279 | int value, i; |
280 | struct device *dev; | ||
281 | const char *prefix; | ||
282 | |||
283 | /* We might be called during detection, at which point the client | ||
284 | isn't yet fully initialized, so we can't use dev_dbg on it */ | ||
285 | if (i2c_get_clientdata(client)) { | ||
286 | dev = &client->dev; | ||
287 | prefix = ""; | ||
288 | } else { | ||
289 | dev = &client->adapter->dev; | ||
290 | prefix = "w83l785ts: "; | ||
291 | } | ||
289 | 292 | ||
290 | /* Frequent read errors have been reported on Asus boards, so we | 293 | /* Frequent read errors have been reported on Asus boards, so we |
291 | * retry on read errors. If it still fails (unlikely), return the | 294 | * retry on read errors. If it still fails (unlikely), return the |
@@ -293,15 +296,15 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) | |||
293 | for (i = 1; i <= MAX_RETRIES; i++) { | 296 | for (i = 1; i <= MAX_RETRIES; i++) { |
294 | value = i2c_smbus_read_byte_data(client, reg); | 297 | value = i2c_smbus_read_byte_data(client, reg); |
295 | if (value >= 0) { | 298 | if (value >= 0) { |
296 | dev_dbg(&client->dev, "Read 0x%02x from register " | 299 | dev_dbg(dev, "%sRead 0x%02x from register 0x%02x.\n", |
297 | "0x%02x.\n", value, reg); | 300 | prefix, value, reg); |
298 | return value; | 301 | return value; |
299 | } | 302 | } |
300 | dev_dbg(&client->dev, "Read failed, will retry in %d.\n", i); | 303 | dev_dbg(dev, "%sRead failed, will retry in %d.\n", prefix, i); |
301 | msleep(i); | 304 | msleep(i); |
302 | } | 305 | } |
303 | 306 | ||
304 | dev_err(&client->dev, "Couldn't read value from register 0x%02x.\n", | 307 | dev_err(dev, "%sCouldn't read value from register 0x%02x.\n", prefix, |
305 | reg); | 308 | reg); |
306 | return defval; | 309 | return defval; |
307 | } | 310 | } |
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index 41e22ddb568a..badca769f350 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -121,7 +121,6 @@ DIV_TO_REG(long val) | |||
121 | } | 121 | } |
122 | 122 | ||
123 | struct w83l786ng_data { | 123 | struct w83l786ng_data { |
124 | struct i2c_client client; | ||
125 | struct device *hwmon_dev; | 124 | struct device *hwmon_dev; |
126 | struct mutex update_lock; | 125 | struct mutex update_lock; |
127 | char valid; /* !=0 if following fields are valid */ | 126 | char valid; /* !=0 if following fields are valid */ |
@@ -146,18 +145,30 @@ struct w83l786ng_data { | |||
146 | u8 tolerance[2]; | 145 | u8 tolerance[2]; |
147 | }; | 146 | }; |
148 | 147 | ||
149 | static int w83l786ng_attach_adapter(struct i2c_adapter *adapter); | 148 | static int w83l786ng_probe(struct i2c_client *client, |
150 | static int w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind); | 149 | const struct i2c_device_id *id); |
151 | static int w83l786ng_detach_client(struct i2c_client *client); | 150 | static int w83l786ng_detect(struct i2c_client *client, int kind, |
151 | struct i2c_board_info *info); | ||
152 | static int w83l786ng_remove(struct i2c_client *client); | ||
152 | static void w83l786ng_init_client(struct i2c_client *client); | 153 | static void w83l786ng_init_client(struct i2c_client *client); |
153 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); | 154 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); |
154 | 155 | ||
156 | static const struct i2c_device_id w83l786ng_id[] = { | ||
157 | { "w83l786ng", w83l786ng }, | ||
158 | { } | ||
159 | }; | ||
160 | MODULE_DEVICE_TABLE(i2c, w83l786ng_id); | ||
161 | |||
155 | static struct i2c_driver w83l786ng_driver = { | 162 | static struct i2c_driver w83l786ng_driver = { |
163 | .class = I2C_CLASS_HWMON, | ||
156 | .driver = { | 164 | .driver = { |
157 | .name = "w83l786ng", | 165 | .name = "w83l786ng", |
158 | }, | 166 | }, |
159 | .attach_adapter = w83l786ng_attach_adapter, | 167 | .probe = w83l786ng_probe, |
160 | .detach_client = w83l786ng_detach_client, | 168 | .remove = w83l786ng_remove, |
169 | .id_table = w83l786ng_id, | ||
170 | .detect = w83l786ng_detect, | ||
171 | .address_data = &addr_data, | ||
161 | }; | 172 | }; |
162 | 173 | ||
163 | static u8 | 174 | static u8 |
@@ -575,42 +586,15 @@ static const struct attribute_group w83l786ng_group = { | |||
575 | }; | 586 | }; |
576 | 587 | ||
577 | static int | 588 | static int |
578 | w83l786ng_attach_adapter(struct i2c_adapter *adapter) | 589 | w83l786ng_detect(struct i2c_client *client, int kind, |
590 | struct i2c_board_info *info) | ||
579 | { | 591 | { |
580 | if (!(adapter->class & I2C_CLASS_HWMON)) | 592 | struct i2c_adapter *adapter = client->adapter; |
581 | return 0; | ||
582 | return i2c_probe(adapter, &addr_data, w83l786ng_detect); | ||
583 | } | ||
584 | |||
585 | static int | ||
586 | w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | ||
587 | { | ||
588 | struct i2c_client *client; | ||
589 | struct device *dev; | ||
590 | struct w83l786ng_data *data; | ||
591 | int i, err = 0; | ||
592 | u8 reg_tmp; | ||
593 | 593 | ||
594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
595 | goto exit; | 595 | return -ENODEV; |
596 | } | ||
597 | |||
598 | /* OK. For now, we presume we have a valid client. We now create the | ||
599 | client structure, even though we cannot fill it completely yet. | ||
600 | But it allows us to access w83l786ng_{read,write}_value. */ | ||
601 | |||
602 | if (!(data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL))) { | ||
603 | err = -ENOMEM; | ||
604 | goto exit; | ||
605 | } | 596 | } |
606 | 597 | ||
607 | client = &data->client; | ||
608 | dev = &client->dev; | ||
609 | i2c_set_clientdata(client, data); | ||
610 | client->addr = address; | ||
611 | client->adapter = adapter; | ||
612 | client->driver = &w83l786ng_driver; | ||
613 | |||
614 | /* | 598 | /* |
615 | * Now we do the remaining detection. A negative kind means that | 599 | * Now we do the remaining detection. A negative kind means that |
616 | * the driver was loaded with no force parameter (default), so we | 600 | * the driver was loaded with no force parameter (default), so we |
@@ -627,8 +611,8 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
627 | W83L786NG_REG_CONFIG) & 0x80) != 0x00)) { | 611 | W83L786NG_REG_CONFIG) & 0x80) != 0x00)) { |
628 | dev_dbg(&adapter->dev, | 612 | dev_dbg(&adapter->dev, |
629 | "W83L786NG detection failed at 0x%02x.\n", | 613 | "W83L786NG detection failed at 0x%02x.\n", |
630 | address); | 614 | client->addr); |
631 | goto exit_free; | 615 | return -ENODEV; |
632 | } | 616 | } |
633 | } | 617 | } |
634 | 618 | ||
@@ -651,17 +635,31 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
651 | dev_info(&adapter->dev, | 635 | dev_info(&adapter->dev, |
652 | "Unsupported chip (man_id=0x%04X, " | 636 | "Unsupported chip (man_id=0x%04X, " |
653 | "chip_id=0x%02X).\n", man_id, chip_id); | 637 | "chip_id=0x%02X).\n", man_id, chip_id); |
654 | goto exit_free; | 638 | return -ENODEV; |
655 | } | 639 | } |
656 | } | 640 | } |
657 | 641 | ||
658 | /* Fill in the remaining client fields and put into the global list */ | 642 | strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); |
659 | strlcpy(client->name, "w83l786ng", I2C_NAME_SIZE); | ||
660 | mutex_init(&data->update_lock); | ||
661 | 643 | ||
662 | /* Tell the I2C layer a new client has arrived */ | 644 | return 0; |
663 | if ((err = i2c_attach_client(client))) | 645 | } |
664 | goto exit_free; | 646 | |
647 | static int | ||
648 | w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
649 | { | ||
650 | struct device *dev = &client->dev; | ||
651 | struct w83l786ng_data *data; | ||
652 | int i, err = 0; | ||
653 | u8 reg_tmp; | ||
654 | |||
655 | data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL); | ||
656 | if (!data) { | ||
657 | err = -ENOMEM; | ||
658 | goto exit; | ||
659 | } | ||
660 | |||
661 | i2c_set_clientdata(client, data); | ||
662 | mutex_init(&data->update_lock); | ||
665 | 663 | ||
666 | /* Initialize the chip */ | 664 | /* Initialize the chip */ |
667 | w83l786ng_init_client(client); | 665 | w83l786ng_init_client(client); |
@@ -693,25 +691,19 @@ w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind) | |||
693 | 691 | ||
694 | exit_remove: | 692 | exit_remove: |
695 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | 693 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); |
696 | i2c_detach_client(client); | ||
697 | exit_free: | ||
698 | kfree(data); | 694 | kfree(data); |
699 | exit: | 695 | exit: |
700 | return err; | 696 | return err; |
701 | } | 697 | } |
702 | 698 | ||
703 | static int | 699 | static int |
704 | w83l786ng_detach_client(struct i2c_client *client) | 700 | w83l786ng_remove(struct i2c_client *client) |
705 | { | 701 | { |
706 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 702 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
707 | int err; | ||
708 | 703 | ||
709 | hwmon_device_unregister(data->hwmon_dev); | 704 | hwmon_device_unregister(data->hwmon_dev); |
710 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | 705 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); |
711 | 706 | ||
712 | if ((err = i2c_detach_client(client))) | ||
713 | return err; | ||
714 | |||
715 | kfree(data); | 707 | kfree(data); |
716 | 708 | ||
717 | return 0; | 709 | return 0; |
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c index 2f150e33c74c..72872d1e63ef 100644 --- a/drivers/i2c/busses/i2c-amd756-s4882.c +++ b/drivers/i2c/busses/i2c-amd756-s4882.c | |||
@@ -155,6 +155,16 @@ static int __init amd756_s4882_init(void) | |||
155 | int i, error; | 155 | int i, error; |
156 | union i2c_smbus_data ioconfig; | 156 | union i2c_smbus_data ioconfig; |
157 | 157 | ||
158 | /* Configure the PCA9556 multiplexer */ | ||
159 | ioconfig.byte = 0x00; /* All I/O to output mode */ | ||
160 | error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, | ||
161 | I2C_SMBUS_BYTE_DATA, &ioconfig); | ||
162 | if (error) { | ||
163 | dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n"); | ||
164 | error = -EIO; | ||
165 | goto ERROR0; | ||
166 | } | ||
167 | |||
158 | /* Unregister physical bus */ | 168 | /* Unregister physical bus */ |
159 | error = i2c_del_adapter(&amd756_smbus); | 169 | error = i2c_del_adapter(&amd756_smbus); |
160 | if (error) { | 170 | if (error) { |
@@ -198,22 +208,11 @@ static int __init amd756_s4882_init(void) | |||
198 | s4882_algo[3].smbus_xfer = amd756_access_virt3; | 208 | s4882_algo[3].smbus_xfer = amd756_access_virt3; |
199 | s4882_algo[4].smbus_xfer = amd756_access_virt4; | 209 | s4882_algo[4].smbus_xfer = amd756_access_virt4; |
200 | 210 | ||
201 | /* Configure the PCA9556 multiplexer */ | ||
202 | ioconfig.byte = 0x00; /* All I/O to output mode */ | ||
203 | error = amd756_smbus.algo->smbus_xfer(&amd756_smbus, 0x18, 0, | ||
204 | I2C_SMBUS_WRITE, 0x03, | ||
205 | I2C_SMBUS_BYTE_DATA, &ioconfig); | ||
206 | if (error) { | ||
207 | dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n"); | ||
208 | error = -EIO; | ||
209 | goto ERROR3; | ||
210 | } | ||
211 | |||
212 | /* Register virtual adapters */ | 211 | /* Register virtual adapters */ |
213 | for (i = 0; i < 5; i++) { | 212 | for (i = 0; i < 5; i++) { |
214 | error = i2c_add_adapter(s4882_adapter+i); | 213 | error = i2c_add_adapter(s4882_adapter+i); |
215 | if (error) { | 214 | if (error) { |
216 | dev_err(&amd756_smbus.dev, | 215 | printk(KERN_ERR "i2c-amd756-s4882: " |
217 | "Virtual adapter %d registration " | 216 | "Virtual adapter %d registration " |
218 | "failed, module not inserted\n", i); | 217 | "failed, module not inserted\n", i); |
219 | for (i--; i >= 0; i--) | 218 | for (i--; i >= 0; i--) |
@@ -252,8 +251,8 @@ static void __exit amd756_s4882_exit(void) | |||
252 | 251 | ||
253 | /* Restore physical bus */ | 252 | /* Restore physical bus */ |
254 | if (i2c_add_adapter(&amd756_smbus)) | 253 | if (i2c_add_adapter(&amd756_smbus)) |
255 | dev_err(&amd756_smbus.dev, "Physical bus restoration " | 254 | printk(KERN_ERR "i2c-amd756-s4882: " |
256 | "failed\n"); | 255 | "Physical bus restoration failed\n"); |
257 | } | 256 | } |
258 | 257 | ||
259 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 258 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c index 6a8995dfd0bb..d1a4cbcf2aa4 100644 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c | |||
@@ -150,6 +150,16 @@ static int __init nforce2_s4985_init(void) | |||
150 | int i, error; | 150 | int i, error; |
151 | union i2c_smbus_data ioconfig; | 151 | union i2c_smbus_data ioconfig; |
152 | 152 | ||
153 | /* Configure the PCA9556 multiplexer */ | ||
154 | ioconfig.byte = 0x00; /* All I/O to output mode */ | ||
155 | error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, | ||
156 | I2C_SMBUS_BYTE_DATA, &ioconfig); | ||
157 | if (error) { | ||
158 | dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n"); | ||
159 | error = -EIO; | ||
160 | goto ERROR0; | ||
161 | } | ||
162 | |||
153 | /* Unregister physical bus */ | 163 | /* Unregister physical bus */ |
154 | if (!nforce2_smbus) | 164 | if (!nforce2_smbus) |
155 | return -ENODEV; | 165 | return -ENODEV; |
@@ -191,24 +201,13 @@ static int __init nforce2_s4985_init(void) | |||
191 | s4985_algo[3].smbus_xfer = nforce2_access_virt3; | 201 | s4985_algo[3].smbus_xfer = nforce2_access_virt3; |
192 | s4985_algo[4].smbus_xfer = nforce2_access_virt4; | 202 | s4985_algo[4].smbus_xfer = nforce2_access_virt4; |
193 | 203 | ||
194 | /* Configure the PCA9556 multiplexer */ | ||
195 | ioconfig.byte = 0x00; /* All I/O to output mode */ | ||
196 | error = nforce2_smbus->algo->smbus_xfer(nforce2_smbus, 0x18, 0, | ||
197 | I2C_SMBUS_WRITE, 0x03, | ||
198 | I2C_SMBUS_BYTE_DATA, &ioconfig); | ||
199 | if (error) { | ||
200 | dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n"); | ||
201 | error = -EIO; | ||
202 | goto ERROR3; | ||
203 | } | ||
204 | |||
205 | /* Register virtual adapters */ | 204 | /* Register virtual adapters */ |
206 | for (i = 0; i < 5; i++) { | 205 | for (i = 0; i < 5; i++) { |
207 | error = i2c_add_adapter(s4985_adapter + i); | 206 | error = i2c_add_adapter(s4985_adapter + i); |
208 | if (error) { | 207 | if (error) { |
209 | dev_err(&nforce2_smbus->dev, | 208 | printk(KERN_ERR "i2c-nforce2-s4985: " |
210 | "Virtual adapter %d registration " | 209 | "Virtual adapter %d registration " |
211 | "failed, module not inserted\n", i); | 210 | "failed, module not inserted\n", i); |
212 | for (i--; i >= 0; i--) | 211 | for (i--; i >= 0; i--) |
213 | i2c_del_adapter(s4985_adapter + i); | 212 | i2c_del_adapter(s4985_adapter + i); |
214 | goto ERROR3; | 213 | goto ERROR3; |
@@ -245,8 +244,8 @@ static void __exit nforce2_s4985_exit(void) | |||
245 | 244 | ||
246 | /* Restore physical bus */ | 245 | /* Restore physical bus */ |
247 | if (i2c_add_adapter(nforce2_smbus)) | 246 | if (i2c_add_adapter(nforce2_smbus)) |
248 | dev_err(&nforce2_smbus->dev, "Physical bus restoration " | 247 | printk(KERN_ERR "i2c-nforce2-s4985: " |
249 | "failed\n"); | 248 | "Physical bus restoration failed\n"); |
250 | } | 249 | } |
251 | 250 | ||
252 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 251 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index 373ea8d8fe8f..2c27193aeaa0 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c | |||
@@ -47,7 +47,6 @@ enum eeprom_nature { | |||
47 | 47 | ||
48 | /* Each client has this additional data */ | 48 | /* Each client has this additional data */ |
49 | struct eeprom_data { | 49 | struct eeprom_data { |
50 | struct i2c_client client; | ||
51 | struct mutex update_lock; | 50 | struct mutex update_lock; |
52 | u8 valid; /* bitfield, bit!=0 if slice is valid */ | 51 | u8 valid; /* bitfield, bit!=0 if slice is valid */ |
53 | unsigned long last_updated[8]; /* In jiffies, 8 slices */ | 52 | unsigned long last_updated[8]; /* In jiffies, 8 slices */ |
@@ -56,19 +55,6 @@ struct eeprom_data { | |||
56 | }; | 55 | }; |
57 | 56 | ||
58 | 57 | ||
59 | static int eeprom_attach_adapter(struct i2c_adapter *adapter); | ||
60 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind); | ||
61 | static int eeprom_detach_client(struct i2c_client *client); | ||
62 | |||
63 | /* This is the driver that will be inserted */ | ||
64 | static struct i2c_driver eeprom_driver = { | ||
65 | .driver = { | ||
66 | .name = "eeprom", | ||
67 | }, | ||
68 | .attach_adapter = eeprom_attach_adapter, | ||
69 | .detach_client = eeprom_detach_client, | ||
70 | }; | ||
71 | |||
72 | static void eeprom_update_client(struct i2c_client *client, u8 slice) | 58 | static void eeprom_update_client(struct i2c_client *client, u8 slice) |
73 | { | 59 | { |
74 | struct eeprom_data *data = i2c_get_clientdata(client); | 60 | struct eeprom_data *data = i2c_get_clientdata(client); |
@@ -148,25 +134,17 @@ static struct bin_attribute eeprom_attr = { | |||
148 | .read = eeprom_read, | 134 | .read = eeprom_read, |
149 | }; | 135 | }; |
150 | 136 | ||
151 | static int eeprom_attach_adapter(struct i2c_adapter *adapter) | 137 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
152 | { | 138 | static int eeprom_detect(struct i2c_client *client, int kind, |
153 | if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD))) | 139 | struct i2c_board_info *info) |
154 | return 0; | ||
155 | return i2c_probe(adapter, &addr_data, eeprom_detect); | ||
156 | } | ||
157 | |||
158 | /* This function is called by i2c_probe */ | ||
159 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | ||
160 | { | 140 | { |
161 | struct i2c_client *client; | 141 | struct i2c_adapter *adapter = client->adapter; |
162 | struct eeprom_data *data; | ||
163 | int err = 0; | ||
164 | 142 | ||
165 | /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all | 143 | /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all |
166 | addresses 0x50-0x57, but we only care about 0x50. So decline | 144 | addresses 0x50-0x57, but we only care about 0x50. So decline |
167 | attaching to addresses >= 0x51 on DDC buses */ | 145 | attaching to addresses >= 0x51 on DDC buses */ |
168 | if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51) | 146 | if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51) |
169 | goto exit; | 147 | return -ENODEV; |
170 | 148 | ||
171 | /* There are four ways we can read the EEPROM data: | 149 | /* There are four ways we can read the EEPROM data: |
172 | (1) I2C block reads (faster, but unsupported by most adapters) | 150 | (1) I2C block reads (faster, but unsupported by most adapters) |
@@ -177,32 +155,33 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
177 | because all known adapters support one of the first two. */ | 155 | because all known adapters support one of the first two. */ |
178 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) | 156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) |
179 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) | 157 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) |
180 | goto exit; | 158 | return -ENODEV; |
159 | |||
160 | strlcpy(info->type, "eeprom", I2C_NAME_SIZE); | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static int eeprom_probe(struct i2c_client *client, | ||
166 | const struct i2c_device_id *id) | ||
167 | { | ||
168 | struct i2c_adapter *adapter = client->adapter; | ||
169 | struct eeprom_data *data; | ||
170 | int err; | ||
181 | 171 | ||
182 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { | 172 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { |
183 | err = -ENOMEM; | 173 | err = -ENOMEM; |
184 | goto exit; | 174 | goto exit; |
185 | } | 175 | } |
186 | 176 | ||
187 | client = &data->client; | ||
188 | memset(data->data, 0xff, EEPROM_SIZE); | 177 | memset(data->data, 0xff, EEPROM_SIZE); |
189 | i2c_set_clientdata(client, data); | 178 | i2c_set_clientdata(client, data); |
190 | client->addr = address; | ||
191 | client->adapter = adapter; | ||
192 | client->driver = &eeprom_driver; | ||
193 | |||
194 | /* Fill in the remaining client fields */ | ||
195 | strlcpy(client->name, "eeprom", I2C_NAME_SIZE); | ||
196 | mutex_init(&data->update_lock); | 179 | mutex_init(&data->update_lock); |
197 | data->nature = UNKNOWN; | 180 | data->nature = UNKNOWN; |
198 | 181 | ||
199 | /* Tell the I2C layer a new client has arrived */ | ||
200 | if ((err = i2c_attach_client(client))) | ||
201 | goto exit_kfree; | ||
202 | |||
203 | /* Detect the Vaio nature of EEPROMs. | 182 | /* Detect the Vaio nature of EEPROMs. |
204 | We use the "PCG-" or "VGN-" prefix as the signature. */ | 183 | We use the "PCG-" or "VGN-" prefix as the signature. */ |
205 | if (address == 0x57 | 184 | if (client->addr == 0x57 |
206 | && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | 185 | && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
207 | char name[4]; | 186 | char name[4]; |
208 | 187 | ||
@@ -221,33 +200,42 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
221 | /* create the sysfs eeprom file */ | 200 | /* create the sysfs eeprom file */ |
222 | err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); | 201 | err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); |
223 | if (err) | 202 | if (err) |
224 | goto exit_detach; | 203 | goto exit_kfree; |
225 | 204 | ||
226 | return 0; | 205 | return 0; |
227 | 206 | ||
228 | exit_detach: | ||
229 | i2c_detach_client(client); | ||
230 | exit_kfree: | 207 | exit_kfree: |
231 | kfree(data); | 208 | kfree(data); |
232 | exit: | 209 | exit: |
233 | return err; | 210 | return err; |
234 | } | 211 | } |
235 | 212 | ||
236 | static int eeprom_detach_client(struct i2c_client *client) | 213 | static int eeprom_remove(struct i2c_client *client) |
237 | { | 214 | { |
238 | int err; | ||
239 | |||
240 | sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); | 215 | sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); |
241 | |||
242 | err = i2c_detach_client(client); | ||
243 | if (err) | ||
244 | return err; | ||
245 | |||
246 | kfree(i2c_get_clientdata(client)); | 216 | kfree(i2c_get_clientdata(client)); |
247 | 217 | ||
248 | return 0; | 218 | return 0; |
249 | } | 219 | } |
250 | 220 | ||
221 | static const struct i2c_device_id eeprom_id[] = { | ||
222 | { "eeprom", 0 }, | ||
223 | { } | ||
224 | }; | ||
225 | |||
226 | static struct i2c_driver eeprom_driver = { | ||
227 | .driver = { | ||
228 | .name = "eeprom", | ||
229 | }, | ||
230 | .probe = eeprom_probe, | ||
231 | .remove = eeprom_remove, | ||
232 | .id_table = eeprom_id, | ||
233 | |||
234 | .class = I2C_CLASS_DDC | I2C_CLASS_SPD, | ||
235 | .detect = eeprom_detect, | ||
236 | .address_data = &addr_data, | ||
237 | }; | ||
238 | |||
251 | static int __init eeprom_init(void) | 239 | static int __init eeprom_init(void) |
252 | { | 240 | { |
253 | return i2c_add_driver(&eeprom_driver); | 241 | return i2c_add_driver(&eeprom_driver); |
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c index 5a0285d8b6f9..033d9d81ec8a 100644 --- a/drivers/i2c/chips/max6875.c +++ b/drivers/i2c/chips/max6875.c | |||
@@ -53,7 +53,7 @@ I2C_CLIENT_INSMOD_1(max6875); | |||
53 | 53 | ||
54 | /* Each client has this additional data */ | 54 | /* Each client has this additional data */ |
55 | struct max6875_data { | 55 | struct max6875_data { |
56 | struct i2c_client client; | 56 | struct i2c_client *fake_client; |
57 | struct mutex update_lock; | 57 | struct mutex update_lock; |
58 | 58 | ||
59 | u32 valid; | 59 | u32 valid; |
@@ -61,19 +61,6 @@ struct max6875_data { | |||
61 | unsigned long last_updated[USER_EEPROM_SLICES]; | 61 | unsigned long last_updated[USER_EEPROM_SLICES]; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | static int max6875_attach_adapter(struct i2c_adapter *adapter); | ||
65 | static int max6875_detect(struct i2c_adapter *adapter, int address, int kind); | ||
66 | static int max6875_detach_client(struct i2c_client *client); | ||
67 | |||
68 | /* This is the driver that will be inserted */ | ||
69 | static struct i2c_driver max6875_driver = { | ||
70 | .driver = { | ||
71 | .name = "max6875", | ||
72 | }, | ||
73 | .attach_adapter = max6875_attach_adapter, | ||
74 | .detach_client = max6875_detach_client, | ||
75 | }; | ||
76 | |||
77 | static void max6875_update_slice(struct i2c_client *client, int slice) | 64 | static void max6875_update_slice(struct i2c_client *client, int slice) |
78 | { | 65 | { |
79 | struct max6875_data *data = i2c_get_clientdata(client); | 66 | struct max6875_data *data = i2c_get_clientdata(client); |
@@ -159,96 +146,87 @@ static struct bin_attribute user_eeprom_attr = { | |||
159 | .read = max6875_read, | 146 | .read = max6875_read, |
160 | }; | 147 | }; |
161 | 148 | ||
162 | static int max6875_attach_adapter(struct i2c_adapter *adapter) | 149 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
150 | static int max6875_detect(struct i2c_client *client, int kind, | ||
151 | struct i2c_board_info *info) | ||
163 | { | 152 | { |
164 | return i2c_probe(adapter, &addr_data, max6875_detect); | 153 | struct i2c_adapter *adapter = client->adapter; |
165 | } | ||
166 | |||
167 | /* This function is called by i2c_probe */ | ||
168 | static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | ||
169 | { | ||
170 | struct i2c_client *real_client; | ||
171 | struct i2c_client *fake_client; | ||
172 | struct max6875_data *data; | ||
173 | int err; | ||
174 | 154 | ||
175 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA | 155 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
176 | | I2C_FUNC_SMBUS_READ_BYTE)) | 156 | | I2C_FUNC_SMBUS_READ_BYTE)) |
177 | return 0; | 157 | return -ENODEV; |
178 | 158 | ||
179 | /* Only check even addresses */ | 159 | /* Only check even addresses */ |
180 | if (address & 1) | 160 | if (client->addr & 1) |
181 | return 0; | 161 | return -ENODEV; |
162 | |||
163 | strlcpy(info->type, "max6875", I2C_NAME_SIZE); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int max6875_probe(struct i2c_client *client, | ||
169 | const struct i2c_device_id *id) | ||
170 | { | ||
171 | struct max6875_data *data; | ||
172 | int err; | ||
182 | 173 | ||
183 | if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) | 174 | if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) |
184 | return -ENOMEM; | 175 | return -ENOMEM; |
185 | 176 | ||
186 | /* A fake client is created on the odd address */ | 177 | /* A fake client is created on the odd address */ |
187 | if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { | 178 | data->fake_client = i2c_new_dummy(client->adapter, client->addr + 1); |
179 | if (!data->fake_client) { | ||
188 | err = -ENOMEM; | 180 | err = -ENOMEM; |
189 | goto exit_kfree1; | 181 | goto exit_kfree; |
190 | } | 182 | } |
191 | 183 | ||
192 | /* Init real i2c_client */ | 184 | /* Init real i2c_client */ |
193 | real_client = &data->client; | 185 | i2c_set_clientdata(client, data); |
194 | i2c_set_clientdata(real_client, data); | ||
195 | real_client->addr = address; | ||
196 | real_client->adapter = adapter; | ||
197 | real_client->driver = &max6875_driver; | ||
198 | strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); | ||
199 | mutex_init(&data->update_lock); | 186 | mutex_init(&data->update_lock); |
200 | 187 | ||
201 | /* Init fake client data */ | 188 | err = sysfs_create_bin_file(&client->dev.kobj, &user_eeprom_attr); |
202 | i2c_set_clientdata(fake_client, NULL); | ||
203 | fake_client->addr = address | 1; | ||
204 | fake_client->adapter = adapter; | ||
205 | fake_client->driver = &max6875_driver; | ||
206 | strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE); | ||
207 | |||
208 | if ((err = i2c_attach_client(real_client)) != 0) | ||
209 | goto exit_kfree2; | ||
210 | |||
211 | if ((err = i2c_attach_client(fake_client)) != 0) | ||
212 | goto exit_detach1; | ||
213 | |||
214 | err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); | ||
215 | if (err) | 189 | if (err) |
216 | goto exit_detach2; | 190 | goto exit_remove_fake; |
217 | 191 | ||
218 | return 0; | 192 | return 0; |
219 | 193 | ||
220 | exit_detach2: | 194 | exit_remove_fake: |
221 | i2c_detach_client(fake_client); | 195 | i2c_unregister_device(data->fake_client); |
222 | exit_detach1: | 196 | exit_kfree: |
223 | i2c_detach_client(real_client); | ||
224 | exit_kfree2: | ||
225 | kfree(fake_client); | ||
226 | exit_kfree1: | ||
227 | kfree(data); | 197 | kfree(data); |
228 | return err; | 198 | return err; |
229 | } | 199 | } |
230 | 200 | ||
231 | /* Will be called for both the real client and the fake client */ | 201 | static int max6875_remove(struct i2c_client *client) |
232 | static int max6875_detach_client(struct i2c_client *client) | ||
233 | { | 202 | { |
234 | int err; | ||
235 | struct max6875_data *data = i2c_get_clientdata(client); | 203 | struct max6875_data *data = i2c_get_clientdata(client); |
236 | 204 | ||
237 | /* data is NULL for the fake client */ | 205 | i2c_unregister_device(data->fake_client); |
238 | if (data) | ||
239 | sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr); | ||
240 | 206 | ||
241 | err = i2c_detach_client(client); | 207 | sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr); |
242 | if (err) | 208 | kfree(data); |
243 | return err; | ||
244 | 209 | ||
245 | if (data) /* real client */ | ||
246 | kfree(data); | ||
247 | else /* fake client */ | ||
248 | kfree(client); | ||
249 | return 0; | 210 | return 0; |
250 | } | 211 | } |
251 | 212 | ||
213 | static const struct i2c_device_id max6875_id[] = { | ||
214 | { "max6875", 0 }, | ||
215 | { } | ||
216 | }; | ||
217 | |||
218 | static struct i2c_driver max6875_driver = { | ||
219 | .driver = { | ||
220 | .name = "max6875", | ||
221 | }, | ||
222 | .probe = max6875_probe, | ||
223 | .remove = max6875_remove, | ||
224 | .id_table = max6875_id, | ||
225 | |||
226 | .detect = max6875_detect, | ||
227 | .address_data = &addr_data, | ||
228 | }; | ||
229 | |||
252 | static int __init max6875_init(void) | 230 | static int __init max6875_init(void) |
253 | { | 231 | { |
254 | return i2c_add_driver(&max6875_driver); | 232 | return i2c_add_driver(&max6875_driver); |
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c index 58ab7f26be26..270de4e56a81 100644 --- a/drivers/i2c/chips/pca9539.c +++ b/drivers/i2c/chips/pca9539.c | |||
@@ -14,8 +14,8 @@ | |||
14 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
15 | #include <linux/hwmon-sysfs.h> | 15 | #include <linux/hwmon-sysfs.h> |
16 | 16 | ||
17 | /* Addresses to scan */ | 17 | /* Addresses to scan: none, device is not autodetected */ |
18 | static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; | 18 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
19 | 19 | ||
20 | /* Insmod parameters */ | 20 | /* Insmod parameters */ |
21 | I2C_CLIENT_INSMOD_1(pca9539); | 21 | I2C_CLIENT_INSMOD_1(pca9539); |
@@ -32,23 +32,6 @@ enum pca9539_cmd | |||
32 | PCA9539_DIRECTION_1 = 7, | 32 | PCA9539_DIRECTION_1 = 7, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | static int pca9539_attach_adapter(struct i2c_adapter *adapter); | ||
36 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind); | ||
37 | static int pca9539_detach_client(struct i2c_client *client); | ||
38 | |||
39 | /* This is the driver that will be inserted */ | ||
40 | static struct i2c_driver pca9539_driver = { | ||
41 | .driver = { | ||
42 | .name = "pca9539", | ||
43 | }, | ||
44 | .attach_adapter = pca9539_attach_adapter, | ||
45 | .detach_client = pca9539_detach_client, | ||
46 | }; | ||
47 | |||
48 | struct pca9539_data { | ||
49 | struct i2c_client client; | ||
50 | }; | ||
51 | |||
52 | /* following are the sysfs callback functions */ | 35 | /* following are the sysfs callback functions */ |
53 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, | 36 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, |
54 | char *buf) | 37 | char *buf) |
@@ -105,77 +88,51 @@ static struct attribute_group pca9539_defattr_group = { | |||
105 | .attrs = pca9539_attributes, | 88 | .attrs = pca9539_attributes, |
106 | }; | 89 | }; |
107 | 90 | ||
108 | static int pca9539_attach_adapter(struct i2c_adapter *adapter) | 91 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
92 | static int pca9539_detect(struct i2c_client *client, int kind, | ||
93 | struct i2c_board_info *info) | ||
109 | { | 94 | { |
110 | return i2c_probe(adapter, &addr_data, pca9539_detect); | 95 | struct i2c_adapter *adapter = client->adapter; |
111 | } | ||
112 | |||
113 | /* This function is called by i2c_probe */ | ||
114 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | ||
115 | { | ||
116 | struct i2c_client *client; | ||
117 | struct pca9539_data *data; | ||
118 | int err = 0; | ||
119 | 96 | ||
120 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 97 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
121 | goto exit; | 98 | return -ENODEV; |
122 | |||
123 | /* OK. For now, we presume we have a valid client. We now create the | ||
124 | client structure, even though we cannot fill it completely yet. */ | ||
125 | if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { | ||
126 | err = -ENOMEM; | ||
127 | goto exit; | ||
128 | } | ||
129 | |||
130 | client = &data->client; | ||
131 | i2c_set_clientdata(client, data); | ||
132 | client->addr = address; | ||
133 | client->adapter = adapter; | ||
134 | client->driver = &pca9539_driver; | ||
135 | |||
136 | if (kind < 0) { | ||
137 | /* Detection: the pca9539 only has 8 registers (0-7). | ||
138 | A read of 7 should succeed, but a read of 8 should fail. */ | ||
139 | if ((i2c_smbus_read_byte_data(client, 7) < 0) || | ||
140 | (i2c_smbus_read_byte_data(client, 8) >= 0)) | ||
141 | goto exit_kfree; | ||
142 | } | ||
143 | |||
144 | strlcpy(client->name, "pca9539", I2C_NAME_SIZE); | ||
145 | |||
146 | /* Tell the I2C layer a new client has arrived */ | ||
147 | if ((err = i2c_attach_client(client))) | ||
148 | goto exit_kfree; | ||
149 | 99 | ||
150 | /* Register sysfs hooks */ | 100 | strlcpy(info->type, "pca9539", I2C_NAME_SIZE); |
151 | err = sysfs_create_group(&client->dev.kobj, | ||
152 | &pca9539_defattr_group); | ||
153 | if (err) | ||
154 | goto exit_detach; | ||
155 | 101 | ||
156 | return 0; | 102 | return 0; |
157 | |||
158 | exit_detach: | ||
159 | i2c_detach_client(client); | ||
160 | exit_kfree: | ||
161 | kfree(data); | ||
162 | exit: | ||
163 | return err; | ||
164 | } | 103 | } |
165 | 104 | ||
166 | static int pca9539_detach_client(struct i2c_client *client) | 105 | static int pca9539_probe(struct i2c_client *client, |
106 | const struct i2c_device_id *id) | ||
167 | { | 107 | { |
168 | int err; | 108 | /* Register sysfs hooks */ |
109 | return sysfs_create_group(&client->dev.kobj, | ||
110 | &pca9539_defattr_group); | ||
111 | } | ||
169 | 112 | ||
113 | static int pca9539_remove(struct i2c_client *client) | ||
114 | { | ||
170 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); | 115 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); |
171 | |||
172 | if ((err = i2c_detach_client(client))) | ||
173 | return err; | ||
174 | |||
175 | kfree(i2c_get_clientdata(client)); | ||
176 | return 0; | 116 | return 0; |
177 | } | 117 | } |
178 | 118 | ||
119 | static const struct i2c_device_id pca9539_id[] = { | ||
120 | { "pca9539", 0 }, | ||
121 | { } | ||
122 | }; | ||
123 | |||
124 | static struct i2c_driver pca9539_driver = { | ||
125 | .driver = { | ||
126 | .name = "pca9539", | ||
127 | }, | ||
128 | .probe = pca9539_probe, | ||
129 | .remove = pca9539_remove, | ||
130 | .id_table = pca9539_id, | ||
131 | |||
132 | .detect = pca9539_detect, | ||
133 | .address_data = &addr_data, | ||
134 | }; | ||
135 | |||
179 | static int __init pca9539_init(void) | 136 | static int __init pca9539_init(void) |
180 | { | 137 | { |
181 | return i2c_add_driver(&pca9539_driver); | 138 | return i2c_add_driver(&pca9539_driver); |
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c index 1b3db2b3ada9..6ec309894c88 100644 --- a/drivers/i2c/chips/pcf8574.c +++ b/drivers/i2c/chips/pcf8574.c | |||
@@ -38,37 +38,19 @@ | |||
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
40 | 40 | ||
41 | /* Addresses to scan */ | 41 | /* Addresses to scan: none, device can't be detected */ |
42 | static const unsigned short normal_i2c[] = { | 42 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
43 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | ||
44 | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, | ||
45 | I2C_CLIENT_END | ||
46 | }; | ||
47 | 43 | ||
48 | /* Insmod parameters */ | 44 | /* Insmod parameters */ |
49 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); | 45 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); |
50 | 46 | ||
51 | /* Each client has this additional data */ | 47 | /* Each client has this additional data */ |
52 | struct pcf8574_data { | 48 | struct pcf8574_data { |
53 | struct i2c_client client; | ||
54 | |||
55 | int write; /* Remember last written value */ | 49 | int write; /* Remember last written value */ |
56 | }; | 50 | }; |
57 | 51 | ||
58 | static int pcf8574_attach_adapter(struct i2c_adapter *adapter); | ||
59 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind); | ||
60 | static int pcf8574_detach_client(struct i2c_client *client); | ||
61 | static void pcf8574_init_client(struct i2c_client *client); | 52 | static void pcf8574_init_client(struct i2c_client *client); |
62 | 53 | ||
63 | /* This is the driver that will be inserted */ | ||
64 | static struct i2c_driver pcf8574_driver = { | ||
65 | .driver = { | ||
66 | .name = "pcf8574", | ||
67 | }, | ||
68 | .attach_adapter = pcf8574_attach_adapter, | ||
69 | .detach_client = pcf8574_detach_client, | ||
70 | }; | ||
71 | |||
72 | /* following are the sysfs callback functions */ | 54 | /* following are the sysfs callback functions */ |
73 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) | 55 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) |
74 | { | 56 | { |
@@ -119,41 +101,22 @@ static const struct attribute_group pcf8574_attr_group = { | |||
119 | * Real code | 101 | * Real code |
120 | */ | 102 | */ |
121 | 103 | ||
122 | static int pcf8574_attach_adapter(struct i2c_adapter *adapter) | 104 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
123 | { | 105 | static int pcf8574_detect(struct i2c_client *client, int kind, |
124 | return i2c_probe(adapter, &addr_data, pcf8574_detect); | 106 | struct i2c_board_info *info) |
125 | } | ||
126 | |||
127 | /* This function is called by i2c_probe */ | ||
128 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | ||
129 | { | 107 | { |
130 | struct i2c_client *client; | 108 | struct i2c_adapter *adapter = client->adapter; |
131 | struct pcf8574_data *data; | 109 | const char *client_name; |
132 | int err = 0; | ||
133 | const char *client_name = ""; | ||
134 | 110 | ||
135 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 111 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
136 | goto exit; | 112 | return -ENODEV; |
137 | |||
138 | /* OK. For now, we presume we have a valid client. We now create the | ||
139 | client structure, even though we cannot fill it completely yet. */ | ||
140 | if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { | ||
141 | err = -ENOMEM; | ||
142 | goto exit; | ||
143 | } | ||
144 | |||
145 | client = &data->client; | ||
146 | i2c_set_clientdata(client, data); | ||
147 | client->addr = address; | ||
148 | client->adapter = adapter; | ||
149 | client->driver = &pcf8574_driver; | ||
150 | 113 | ||
151 | /* Now, we would do the remaining detection. But the PCF8574 is plainly | 114 | /* Now, we would do the remaining detection. But the PCF8574 is plainly |
152 | impossible to detect! Stupid chip. */ | 115 | impossible to detect! Stupid chip. */ |
153 | 116 | ||
154 | /* Determine the chip type */ | 117 | /* Determine the chip type */ |
155 | if (kind <= 0) { | 118 | if (kind <= 0) { |
156 | if (address >= 0x38 && address <= 0x3f) | 119 | if (client->addr >= 0x38 && client->addr <= 0x3f) |
157 | kind = pcf8574a; | 120 | kind = pcf8574a; |
158 | else | 121 | else |
159 | kind = pcf8574; | 122 | kind = pcf8574; |
@@ -163,40 +126,43 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | |||
163 | client_name = "pcf8574a"; | 126 | client_name = "pcf8574a"; |
164 | else | 127 | else |
165 | client_name = "pcf8574"; | 128 | client_name = "pcf8574"; |
129 | strlcpy(info->type, client_name, I2C_NAME_SIZE); | ||
166 | 130 | ||
167 | /* Fill in the remaining client fields and put it into the global list */ | 131 | return 0; |
168 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 132 | } |
133 | |||
134 | static int pcf8574_probe(struct i2c_client *client, | ||
135 | const struct i2c_device_id *id) | ||
136 | { | ||
137 | struct pcf8574_data *data; | ||
138 | int err; | ||
139 | |||
140 | data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL); | ||
141 | if (!data) { | ||
142 | err = -ENOMEM; | ||
143 | goto exit; | ||
144 | } | ||
145 | |||
146 | i2c_set_clientdata(client, data); | ||
169 | 147 | ||
170 | /* Tell the I2C layer a new client has arrived */ | ||
171 | if ((err = i2c_attach_client(client))) | ||
172 | goto exit_free; | ||
173 | |||
174 | /* Initialize the PCF8574 chip */ | 148 | /* Initialize the PCF8574 chip */ |
175 | pcf8574_init_client(client); | 149 | pcf8574_init_client(client); |
176 | 150 | ||
177 | /* Register sysfs hooks */ | 151 | /* Register sysfs hooks */ |
178 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); | 152 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); |
179 | if (err) | 153 | if (err) |
180 | goto exit_detach; | 154 | goto exit_free; |
181 | return 0; | 155 | return 0; |
182 | 156 | ||
183 | exit_detach: | ||
184 | i2c_detach_client(client); | ||
185 | exit_free: | 157 | exit_free: |
186 | kfree(data); | 158 | kfree(data); |
187 | exit: | 159 | exit: |
188 | return err; | 160 | return err; |
189 | } | 161 | } |
190 | 162 | ||
191 | static int pcf8574_detach_client(struct i2c_client *client) | 163 | static int pcf8574_remove(struct i2c_client *client) |
192 | { | 164 | { |
193 | int err; | ||
194 | |||
195 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); | 165 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); |
196 | |||
197 | if ((err = i2c_detach_client(client))) | ||
198 | return err; | ||
199 | |||
200 | kfree(i2c_get_clientdata(client)); | 166 | kfree(i2c_get_clientdata(client)); |
201 | return 0; | 167 | return 0; |
202 | } | 168 | } |
@@ -208,6 +174,24 @@ static void pcf8574_init_client(struct i2c_client *client) | |||
208 | data->write = -EAGAIN; | 174 | data->write = -EAGAIN; |
209 | } | 175 | } |
210 | 176 | ||
177 | static const struct i2c_device_id pcf8574_id[] = { | ||
178 | { "pcf8574", 0 }, | ||
179 | { "pcf8574a", 0 }, | ||
180 | { } | ||
181 | }; | ||
182 | |||
183 | static struct i2c_driver pcf8574_driver = { | ||
184 | .driver = { | ||
185 | .name = "pcf8574", | ||
186 | }, | ||
187 | .probe = pcf8574_probe, | ||
188 | .remove = pcf8574_remove, | ||
189 | .id_table = pcf8574_id, | ||
190 | |||
191 | .detect = pcf8574_detect, | ||
192 | .address_data = &addr_data, | ||
193 | }; | ||
194 | |||
211 | static int __init pcf8574_init(void) | 195 | static int __init pcf8574_init(void) |
212 | { | 196 | { |
213 | return i2c_add_driver(&pcf8574_driver); | 197 | return i2c_add_driver(&pcf8574_driver); |
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c index 3ea08ac0bfa3..07fd7cb3c57d 100644 --- a/drivers/i2c/chips/pcf8575.c +++ b/drivers/i2c/chips/pcf8575.c | |||
@@ -32,11 +32,8 @@ | |||
32 | #include <linux/slab.h> /* kzalloc() */ | 32 | #include <linux/slab.h> /* kzalloc() */ |
33 | #include <linux/sysfs.h> /* sysfs_create_group() */ | 33 | #include <linux/sysfs.h> /* sysfs_create_group() */ |
34 | 34 | ||
35 | /* Addresses to scan */ | 35 | /* Addresses to scan: none, device can't be detected */ |
36 | static const unsigned short normal_i2c[] = { | 36 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
37 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | ||
38 | I2C_CLIENT_END | ||
39 | }; | ||
40 | 37 | ||
41 | /* Insmod parameters */ | 38 | /* Insmod parameters */ |
42 | I2C_CLIENT_INSMOD; | 39 | I2C_CLIENT_INSMOD; |
@@ -44,24 +41,9 @@ I2C_CLIENT_INSMOD; | |||
44 | 41 | ||
45 | /* Each client has this additional data */ | 42 | /* Each client has this additional data */ |
46 | struct pcf8575_data { | 43 | struct pcf8575_data { |
47 | struct i2c_client client; | ||
48 | int write; /* last written value, or error code */ | 44 | int write; /* last written value, or error code */ |
49 | }; | 45 | }; |
50 | 46 | ||
51 | static int pcf8575_attach_adapter(struct i2c_adapter *adapter); | ||
52 | static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind); | ||
53 | static int pcf8575_detach_client(struct i2c_client *client); | ||
54 | |||
55 | /* This is the driver that will be inserted */ | ||
56 | static struct i2c_driver pcf8575_driver = { | ||
57 | .driver = { | ||
58 | .owner = THIS_MODULE, | ||
59 | .name = "pcf8575", | ||
60 | }, | ||
61 | .attach_adapter = pcf8575_attach_adapter, | ||
62 | .detach_client = pcf8575_detach_client, | ||
63 | }; | ||
64 | |||
65 | /* following are the sysfs callback functions */ | 47 | /* following are the sysfs callback functions */ |
66 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, | 48 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, |
67 | char *buf) | 49 | char *buf) |
@@ -126,75 +108,77 @@ static const struct attribute_group pcf8575_attr_group = { | |||
126 | * Real code | 108 | * Real code |
127 | */ | 109 | */ |
128 | 110 | ||
129 | static int pcf8575_attach_adapter(struct i2c_adapter *adapter) | 111 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
112 | static int pcf8575_detect(struct i2c_client *client, int kind, | ||
113 | struct i2c_board_info *info) | ||
130 | { | 114 | { |
131 | return i2c_probe(adapter, &addr_data, pcf8575_detect); | 115 | struct i2c_adapter *adapter = client->adapter; |
116 | |||
117 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
118 | return -ENODEV; | ||
119 | |||
120 | /* This is the place to detect whether the chip at the specified | ||
121 | address really is a PCF8575 chip. However, there is no method known | ||
122 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
123 | |||
124 | strlcpy(info->type, "pcf8575", I2C_NAME_SIZE); | ||
125 | |||
126 | return 0; | ||
132 | } | 127 | } |
133 | 128 | ||
134 | /* This function is called by i2c_probe */ | 129 | static int pcf8575_probe(struct i2c_client *client, |
135 | static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind) | 130 | const struct i2c_device_id *id) |
136 | { | 131 | { |
137 | struct i2c_client *client; | ||
138 | struct pcf8575_data *data; | 132 | struct pcf8575_data *data; |
139 | int err = 0; | 133 | int err; |
140 | |||
141 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
142 | goto exit; | ||
143 | 134 | ||
144 | /* OK. For now, we presume we have a valid client. We now create the | ||
145 | client structure, even though we cannot fill it completely yet. */ | ||
146 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); | 135 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); |
147 | if (!data) { | 136 | if (!data) { |
148 | err = -ENOMEM; | 137 | err = -ENOMEM; |
149 | goto exit; | 138 | goto exit; |
150 | } | 139 | } |
151 | 140 | ||
152 | client = &data->client; | ||
153 | i2c_set_clientdata(client, data); | 141 | i2c_set_clientdata(client, data); |
154 | client->addr = address; | ||
155 | client->adapter = adapter; | ||
156 | client->driver = &pcf8575_driver; | ||
157 | strlcpy(client->name, "pcf8575", I2C_NAME_SIZE); | ||
158 | data->write = -EAGAIN; | 142 | data->write = -EAGAIN; |
159 | 143 | ||
160 | /* This is the place to detect whether the chip at the specified | ||
161 | address really is a PCF8575 chip. However, there is no method known | ||
162 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
163 | |||
164 | /* Tell the I2C layer a new client has arrived */ | ||
165 | err = i2c_attach_client(client); | ||
166 | if (err) | ||
167 | goto exit_free; | ||
168 | |||
169 | /* Register sysfs hooks */ | 144 | /* Register sysfs hooks */ |
170 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); | 145 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); |
171 | if (err) | 146 | if (err) |
172 | goto exit_detach; | 147 | goto exit_free; |
173 | 148 | ||
174 | return 0; | 149 | return 0; |
175 | 150 | ||
176 | exit_detach: | ||
177 | i2c_detach_client(client); | ||
178 | exit_free: | 151 | exit_free: |
179 | kfree(data); | 152 | kfree(data); |
180 | exit: | 153 | exit: |
181 | return err; | 154 | return err; |
182 | } | 155 | } |
183 | 156 | ||
184 | static int pcf8575_detach_client(struct i2c_client *client) | 157 | static int pcf8575_remove(struct i2c_client *client) |
185 | { | 158 | { |
186 | int err; | ||
187 | |||
188 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); | 159 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); |
189 | |||
190 | err = i2c_detach_client(client); | ||
191 | if (err) | ||
192 | return err; | ||
193 | |||
194 | kfree(i2c_get_clientdata(client)); | 160 | kfree(i2c_get_clientdata(client)); |
195 | return 0; | 161 | return 0; |
196 | } | 162 | } |
197 | 163 | ||
164 | static const struct i2c_device_id pcf8575_id[] = { | ||
165 | { "pcf8575", 0 }, | ||
166 | { } | ||
167 | }; | ||
168 | |||
169 | static struct i2c_driver pcf8575_driver = { | ||
170 | .driver = { | ||
171 | .owner = THIS_MODULE, | ||
172 | .name = "pcf8575", | ||
173 | }, | ||
174 | .probe = pcf8575_probe, | ||
175 | .remove = pcf8575_remove, | ||
176 | .id_table = pcf8575_id, | ||
177 | |||
178 | .detect = pcf8575_detect, | ||
179 | .address_data = &addr_data, | ||
180 | }; | ||
181 | |||
198 | static int __init pcf8575_init(void) | 182 | static int __init pcf8575_init(void) |
199 | { | 183 | { |
200 | return i2c_add_driver(&pcf8575_driver); | 184 | return i2c_add_driver(&pcf8575_driver); |
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c index db735379f22f..16ce3e193776 100644 --- a/drivers/i2c/chips/pcf8591.c +++ b/drivers/i2c/chips/pcf8591.c | |||
@@ -72,28 +72,15 @@ MODULE_PARM_DESC(input_mode, | |||
72 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) | 72 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) |
73 | 73 | ||
74 | struct pcf8591_data { | 74 | struct pcf8591_data { |
75 | struct i2c_client client; | ||
76 | struct mutex update_lock; | 75 | struct mutex update_lock; |
77 | 76 | ||
78 | u8 control; | 77 | u8 control; |
79 | u8 aout; | 78 | u8 aout; |
80 | }; | 79 | }; |
81 | 80 | ||
82 | static int pcf8591_attach_adapter(struct i2c_adapter *adapter); | ||
83 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind); | ||
84 | static int pcf8591_detach_client(struct i2c_client *client); | ||
85 | static void pcf8591_init_client(struct i2c_client *client); | 81 | static void pcf8591_init_client(struct i2c_client *client); |
86 | static int pcf8591_read_channel(struct device *dev, int channel); | 82 | static int pcf8591_read_channel(struct device *dev, int channel); |
87 | 83 | ||
88 | /* This is the driver that will be inserted */ | ||
89 | static struct i2c_driver pcf8591_driver = { | ||
90 | .driver = { | ||
91 | .name = "pcf8591", | ||
92 | }, | ||
93 | .attach_adapter = pcf8591_attach_adapter, | ||
94 | .detach_client = pcf8591_detach_client, | ||
95 | }; | ||
96 | |||
97 | /* following are the sysfs callback functions */ | 84 | /* following are the sysfs callback functions */ |
98 | #define show_in_channel(channel) \ | 85 | #define show_in_channel(channel) \ |
99 | static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ | 86 | static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
@@ -180,58 +167,46 @@ static const struct attribute_group pcf8591_attr_group_opt = { | |||
180 | /* | 167 | /* |
181 | * Real code | 168 | * Real code |
182 | */ | 169 | */ |
183 | static int pcf8591_attach_adapter(struct i2c_adapter *adapter) | ||
184 | { | ||
185 | return i2c_probe(adapter, &addr_data, pcf8591_detect); | ||
186 | } | ||
187 | 170 | ||
188 | /* This function is called by i2c_probe */ | 171 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
189 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | 172 | static int pcf8591_detect(struct i2c_client *client, int kind, |
173 | struct i2c_board_info *info) | ||
190 | { | 174 | { |
191 | struct i2c_client *client; | 175 | struct i2c_adapter *adapter = client->adapter; |
192 | struct pcf8591_data *data; | ||
193 | int err = 0; | ||
194 | 176 | ||
195 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | 177 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE |
196 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | 178 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
197 | goto exit; | 179 | return -ENODEV; |
180 | |||
181 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
182 | impossible to detect! Stupid chip. */ | ||
183 | |||
184 | strlcpy(info->type, "pcf8591", I2C_NAME_SIZE); | ||
185 | |||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | static int pcf8591_probe(struct i2c_client *client, | ||
190 | const struct i2c_device_id *id) | ||
191 | { | ||
192 | struct pcf8591_data *data; | ||
193 | int err; | ||
198 | 194 | ||
199 | /* OK. For now, we presume we have a valid client. We now create the | ||
200 | client structure, even though we cannot fill it completely yet. */ | ||
201 | if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { | 195 | if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { |
202 | err = -ENOMEM; | 196 | err = -ENOMEM; |
203 | goto exit; | 197 | goto exit; |
204 | } | 198 | } |
205 | 199 | ||
206 | client = &data->client; | ||
207 | i2c_set_clientdata(client, data); | 200 | i2c_set_clientdata(client, data); |
208 | client->addr = address; | ||
209 | client->adapter = adapter; | ||
210 | client->driver = &pcf8591_driver; | ||
211 | |||
212 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
213 | impossible to detect! Stupid chip. */ | ||
214 | |||
215 | /* Determine the chip type - only one kind supported! */ | ||
216 | if (kind <= 0) | ||
217 | kind = pcf8591; | ||
218 | |||
219 | /* Fill in the remaining client fields and put it into the global | ||
220 | list */ | ||
221 | strlcpy(client->name, "pcf8591", I2C_NAME_SIZE); | ||
222 | mutex_init(&data->update_lock); | 201 | mutex_init(&data->update_lock); |
223 | 202 | ||
224 | /* Tell the I2C layer a new client has arrived */ | ||
225 | if ((err = i2c_attach_client(client))) | ||
226 | goto exit_kfree; | ||
227 | |||
228 | /* Initialize the PCF8591 chip */ | 203 | /* Initialize the PCF8591 chip */ |
229 | pcf8591_init_client(client); | 204 | pcf8591_init_client(client); |
230 | 205 | ||
231 | /* Register sysfs hooks */ | 206 | /* Register sysfs hooks */ |
232 | err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); | 207 | err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); |
233 | if (err) | 208 | if (err) |
234 | goto exit_detach; | 209 | goto exit_kfree; |
235 | 210 | ||
236 | /* Register input2 if not in "two differential inputs" mode */ | 211 | /* Register input2 if not in "two differential inputs" mode */ |
237 | if (input_mode != 3) { | 212 | if (input_mode != 3) { |
@@ -252,24 +227,16 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
252 | exit_sysfs_remove: | 227 | exit_sysfs_remove: |
253 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 228 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
254 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 229 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
255 | exit_detach: | ||
256 | i2c_detach_client(client); | ||
257 | exit_kfree: | 230 | exit_kfree: |
258 | kfree(data); | 231 | kfree(data); |
259 | exit: | 232 | exit: |
260 | return err; | 233 | return err; |
261 | } | 234 | } |
262 | 235 | ||
263 | static int pcf8591_detach_client(struct i2c_client *client) | 236 | static int pcf8591_remove(struct i2c_client *client) |
264 | { | 237 | { |
265 | int err; | ||
266 | |||
267 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 238 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
268 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 239 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
269 | |||
270 | if ((err = i2c_detach_client(client))) | ||
271 | return err; | ||
272 | |||
273 | kfree(i2c_get_clientdata(client)); | 240 | kfree(i2c_get_clientdata(client)); |
274 | return 0; | 241 | return 0; |
275 | } | 242 | } |
@@ -316,6 +283,25 @@ static int pcf8591_read_channel(struct device *dev, int channel) | |||
316 | return (10 * value); | 283 | return (10 * value); |
317 | } | 284 | } |
318 | 285 | ||
286 | static const struct i2c_device_id pcf8591_id[] = { | ||
287 | { "pcf8591", 0 }, | ||
288 | { } | ||
289 | }; | ||
290 | MODULE_DEVICE_TABLE(i2c, pcf8591_id); | ||
291 | |||
292 | static struct i2c_driver pcf8591_driver = { | ||
293 | .driver = { | ||
294 | .name = "pcf8591", | ||
295 | }, | ||
296 | .probe = pcf8591_probe, | ||
297 | .remove = pcf8591_remove, | ||
298 | .id_table = pcf8591_id, | ||
299 | |||
300 | .class = I2C_CLASS_HWMON, /* Nearest choice */ | ||
301 | .detect = pcf8591_detect, | ||
302 | .address_data = &addr_data, | ||
303 | }; | ||
304 | |||
319 | static int __init pcf8591_init(void) | 305 | static int __init pcf8591_init(void) |
320 | { | 306 | { |
321 | if (input_mode < 0 || input_mode > 3) { | 307 | if (input_mode < 0 || input_mode > 3) { |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 0a79f7661017..7608df83d6d1 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -654,6 +654,10 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
654 | 654 | ||
655 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); | 655 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); |
656 | 656 | ||
657 | /* Clear the device structure in case this adapter is ever going to be | ||
658 | added again */ | ||
659 | memset(&adap->dev, 0, sizeof(adap->dev)); | ||
660 | |||
657 | out_unlock: | 661 | out_unlock: |
658 | mutex_unlock(&core_lock); | 662 | mutex_unlock(&core_lock); |
659 | return res; | 663 | return res; |
diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c index 0fd5820d5c61..df52cb355f7d 100644 --- a/drivers/w1/masters/ds2482.c +++ b/drivers/w1/masters/ds2482.c | |||
@@ -94,21 +94,31 @@ static const u8 ds2482_chan_rd[8] = | |||
94 | #define DS2482_REG_STS_1WB 0x01 | 94 | #define DS2482_REG_STS_1WB 0x01 |
95 | 95 | ||
96 | 96 | ||
97 | static int ds2482_attach_adapter(struct i2c_adapter *adapter); | 97 | static int ds2482_probe(struct i2c_client *client, |
98 | static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind); | 98 | const struct i2c_device_id *id); |
99 | static int ds2482_detach_client(struct i2c_client *client); | 99 | static int ds2482_detect(struct i2c_client *client, int kind, |
100 | struct i2c_board_info *info); | ||
101 | static int ds2482_remove(struct i2c_client *client); | ||
100 | 102 | ||
101 | 103 | ||
102 | /** | 104 | /** |
103 | * Driver data (common to all clients) | 105 | * Driver data (common to all clients) |
104 | */ | 106 | */ |
107 | static const struct i2c_device_id ds2482_id[] = { | ||
108 | { "ds2482", 0 }, | ||
109 | { } | ||
110 | }; | ||
111 | |||
105 | static struct i2c_driver ds2482_driver = { | 112 | static struct i2c_driver ds2482_driver = { |
106 | .driver = { | 113 | .driver = { |
107 | .owner = THIS_MODULE, | 114 | .owner = THIS_MODULE, |
108 | .name = "ds2482", | 115 | .name = "ds2482", |
109 | }, | 116 | }, |
110 | .attach_adapter = ds2482_attach_adapter, | 117 | .probe = ds2482_probe, |
111 | .detach_client = ds2482_detach_client, | 118 | .remove = ds2482_remove, |
119 | .id_table = ds2482_id, | ||
120 | .detect = ds2482_detect, | ||
121 | .address_data = &addr_data, | ||
112 | }; | 122 | }; |
113 | 123 | ||
114 | /* | 124 | /* |
@@ -124,7 +134,7 @@ struct ds2482_w1_chan { | |||
124 | }; | 134 | }; |
125 | 135 | ||
126 | struct ds2482_data { | 136 | struct ds2482_data { |
127 | struct i2c_client client; | 137 | struct i2c_client *client; |
128 | struct mutex access_lock; | 138 | struct mutex access_lock; |
129 | 139 | ||
130 | /* 1-wire interface(s) */ | 140 | /* 1-wire interface(s) */ |
@@ -147,7 +157,7 @@ struct ds2482_data { | |||
147 | static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr) | 157 | static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr) |
148 | { | 158 | { |
149 | if (pdev->read_prt != read_ptr) { | 159 | if (pdev->read_prt != read_ptr) { |
150 | if (i2c_smbus_write_byte_data(&pdev->client, | 160 | if (i2c_smbus_write_byte_data(pdev->client, |
151 | DS2482_CMD_SET_READ_PTR, | 161 | DS2482_CMD_SET_READ_PTR, |
152 | read_ptr) < 0) | 162 | read_ptr) < 0) |
153 | return -1; | 163 | return -1; |
@@ -167,7 +177,7 @@ static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr) | |||
167 | */ | 177 | */ |
168 | static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd) | 178 | static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd) |
169 | { | 179 | { |
170 | if (i2c_smbus_write_byte(&pdev->client, cmd) < 0) | 180 | if (i2c_smbus_write_byte(pdev->client, cmd) < 0) |
171 | return -1; | 181 | return -1; |
172 | 182 | ||
173 | pdev->read_prt = DS2482_PTR_CODE_STATUS; | 183 | pdev->read_prt = DS2482_PTR_CODE_STATUS; |
@@ -187,7 +197,7 @@ static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd) | |||
187 | static inline int ds2482_send_cmd_data(struct ds2482_data *pdev, | 197 | static inline int ds2482_send_cmd_data(struct ds2482_data *pdev, |
188 | u8 cmd, u8 byte) | 198 | u8 cmd, u8 byte) |
189 | { | 199 | { |
190 | if (i2c_smbus_write_byte_data(&pdev->client, cmd, byte) < 0) | 200 | if (i2c_smbus_write_byte_data(pdev->client, cmd, byte) < 0) |
191 | return -1; | 201 | return -1; |
192 | 202 | ||
193 | /* all cmds leave in STATUS, except CONFIG */ | 203 | /* all cmds leave in STATUS, except CONFIG */ |
@@ -216,7 +226,7 @@ static int ds2482_wait_1wire_idle(struct ds2482_data *pdev) | |||
216 | 226 | ||
217 | if (!ds2482_select_register(pdev, DS2482_PTR_CODE_STATUS)) { | 227 | if (!ds2482_select_register(pdev, DS2482_PTR_CODE_STATUS)) { |
218 | do { | 228 | do { |
219 | temp = i2c_smbus_read_byte(&pdev->client); | 229 | temp = i2c_smbus_read_byte(pdev->client); |
220 | } while ((temp >= 0) && (temp & DS2482_REG_STS_1WB) && | 230 | } while ((temp >= 0) && (temp & DS2482_REG_STS_1WB) && |
221 | (++retries < DS2482_WAIT_IDLE_TIMEOUT)); | 231 | (++retries < DS2482_WAIT_IDLE_TIMEOUT)); |
222 | } | 232 | } |
@@ -238,13 +248,13 @@ static int ds2482_wait_1wire_idle(struct ds2482_data *pdev) | |||
238 | */ | 248 | */ |
239 | static int ds2482_set_channel(struct ds2482_data *pdev, u8 channel) | 249 | static int ds2482_set_channel(struct ds2482_data *pdev, u8 channel) |
240 | { | 250 | { |
241 | if (i2c_smbus_write_byte_data(&pdev->client, DS2482_CMD_CHANNEL_SELECT, | 251 | if (i2c_smbus_write_byte_data(pdev->client, DS2482_CMD_CHANNEL_SELECT, |
242 | ds2482_chan_wr[channel]) < 0) | 252 | ds2482_chan_wr[channel]) < 0) |
243 | return -1; | 253 | return -1; |
244 | 254 | ||
245 | pdev->read_prt = DS2482_PTR_CODE_CHANNEL; | 255 | pdev->read_prt = DS2482_PTR_CODE_CHANNEL; |
246 | pdev->channel = -1; | 256 | pdev->channel = -1; |
247 | if (i2c_smbus_read_byte(&pdev->client) == ds2482_chan_rd[channel]) { | 257 | if (i2c_smbus_read_byte(pdev->client) == ds2482_chan_rd[channel]) { |
248 | pdev->channel = channel; | 258 | pdev->channel = channel; |
249 | return 0; | 259 | return 0; |
250 | } | 260 | } |
@@ -368,7 +378,7 @@ static u8 ds2482_w1_read_byte(void *data) | |||
368 | ds2482_select_register(pdev, DS2482_PTR_CODE_DATA); | 378 | ds2482_select_register(pdev, DS2482_PTR_CODE_DATA); |
369 | 379 | ||
370 | /* Read the data byte */ | 380 | /* Read the data byte */ |
371 | result = i2c_smbus_read_byte(&pdev->client); | 381 | result = i2c_smbus_read_byte(pdev->client); |
372 | 382 | ||
373 | mutex_unlock(&pdev->access_lock); | 383 | mutex_unlock(&pdev->access_lock); |
374 | 384 | ||
@@ -415,47 +425,38 @@ static u8 ds2482_w1_reset_bus(void *data) | |||
415 | } | 425 | } |
416 | 426 | ||
417 | 427 | ||
418 | /** | 428 | static int ds2482_detect(struct i2c_client *client, int kind, |
419 | * Called to see if the device exists on an i2c bus. | 429 | struct i2c_board_info *info) |
420 | */ | ||
421 | static int ds2482_attach_adapter(struct i2c_adapter *adapter) | ||
422 | { | 430 | { |
423 | return i2c_probe(adapter, &addr_data, ds2482_detect); | 431 | if (!i2c_check_functionality(client->adapter, |
424 | } | 432 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA | |
433 | I2C_FUNC_SMBUS_BYTE)) | ||
434 | return -ENODEV; | ||
425 | 435 | ||
436 | strlcpy(info->type, "ds2482", I2C_NAME_SIZE); | ||
426 | 437 | ||
427 | /* | 438 | return 0; |
428 | * The following function does more than just detection. If detection | 439 | } |
429 | * succeeds, it also registers the new chip. | 440 | |
430 | */ | 441 | static int ds2482_probe(struct i2c_client *client, |
431 | static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind) | 442 | const struct i2c_device_id *id) |
432 | { | 443 | { |
433 | struct ds2482_data *data; | 444 | struct ds2482_data *data; |
434 | struct i2c_client *new_client; | 445 | int err = -ENODEV; |
435 | int err = 0; | ||
436 | int temp1; | 446 | int temp1; |
437 | int idx; | 447 | int idx; |
438 | 448 | ||
439 | if (!i2c_check_functionality(adapter, | ||
440 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA | | ||
441 | I2C_FUNC_SMBUS_BYTE)) | ||
442 | goto exit; | ||
443 | |||
444 | if (!(data = kzalloc(sizeof(struct ds2482_data), GFP_KERNEL))) { | 449 | if (!(data = kzalloc(sizeof(struct ds2482_data), GFP_KERNEL))) { |
445 | err = -ENOMEM; | 450 | err = -ENOMEM; |
446 | goto exit; | 451 | goto exit; |
447 | } | 452 | } |
448 | 453 | ||
449 | new_client = &data->client; | 454 | data->client = client; |
450 | i2c_set_clientdata(new_client, data); | 455 | i2c_set_clientdata(client, data); |
451 | new_client->addr = address; | ||
452 | new_client->driver = &ds2482_driver; | ||
453 | new_client->adapter = adapter; | ||
454 | 456 | ||
455 | /* Reset the device (sets the read_ptr to status) */ | 457 | /* Reset the device (sets the read_ptr to status) */ |
456 | if (ds2482_send_cmd(data, DS2482_CMD_RESET) < 0) { | 458 | if (ds2482_send_cmd(data, DS2482_CMD_RESET) < 0) { |
457 | dev_dbg(&adapter->dev, "DS2482 reset failed at 0x%02x.\n", | 459 | dev_warn(&client->dev, "DS2482 reset failed.\n"); |
458 | address); | ||
459 | goto exit_free; | 460 | goto exit_free; |
460 | } | 461 | } |
461 | 462 | ||
@@ -463,10 +464,10 @@ static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind) | |||
463 | ndelay(525); | 464 | ndelay(525); |
464 | 465 | ||
465 | /* Read the status byte - only reset bit and line should be set */ | 466 | /* Read the status byte - only reset bit and line should be set */ |
466 | temp1 = i2c_smbus_read_byte(new_client); | 467 | temp1 = i2c_smbus_read_byte(client); |
467 | if (temp1 != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) { | 468 | if (temp1 != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) { |
468 | dev_dbg(&adapter->dev, "DS2482 (0x%02x) reset status " | 469 | dev_warn(&client->dev, "DS2482 reset status " |
469 | "0x%02X - not a DS2482\n", address, temp1); | 470 | "0x%02X - not a DS2482\n", temp1); |
470 | goto exit_free; | 471 | goto exit_free; |
471 | } | 472 | } |
472 | 473 | ||
@@ -478,16 +479,8 @@ static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind) | |||
478 | /* Set all config items to 0 (off) */ | 479 | /* Set all config items to 0 (off) */ |
479 | ds2482_send_cmd_data(data, DS2482_CMD_WRITE_CONFIG, 0xF0); | 480 | ds2482_send_cmd_data(data, DS2482_CMD_WRITE_CONFIG, 0xF0); |
480 | 481 | ||
481 | /* We can fill in the remaining client fields */ | ||
482 | snprintf(new_client->name, sizeof(new_client->name), "ds2482-%d00", | ||
483 | data->w1_count); | ||
484 | |||
485 | mutex_init(&data->access_lock); | 482 | mutex_init(&data->access_lock); |
486 | 483 | ||
487 | /* Tell the I2C layer a new client has arrived */ | ||
488 | if ((err = i2c_attach_client(new_client))) | ||
489 | goto exit_free; | ||
490 | |||
491 | /* Register 1-wire interface(s) */ | 484 | /* Register 1-wire interface(s) */ |
492 | for (idx = 0; idx < data->w1_count; idx++) { | 485 | for (idx = 0; idx < data->w1_count; idx++) { |
493 | data->w1_ch[idx].pdev = data; | 486 | data->w1_ch[idx].pdev = data; |
@@ -511,8 +504,6 @@ static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind) | |||
511 | return 0; | 504 | return 0; |
512 | 505 | ||
513 | exit_w1_remove: | 506 | exit_w1_remove: |
514 | i2c_detach_client(new_client); | ||
515 | |||
516 | for (idx = 0; idx < data->w1_count; idx++) { | 507 | for (idx = 0; idx < data->w1_count; idx++) { |
517 | if (data->w1_ch[idx].pdev != NULL) | 508 | if (data->w1_ch[idx].pdev != NULL) |
518 | w1_remove_master_device(&data->w1_ch[idx].w1_bm); | 509 | w1_remove_master_device(&data->w1_ch[idx].w1_bm); |
@@ -523,10 +514,10 @@ exit: | |||
523 | return err; | 514 | return err; |
524 | } | 515 | } |
525 | 516 | ||
526 | static int ds2482_detach_client(struct i2c_client *client) | 517 | static int ds2482_remove(struct i2c_client *client) |
527 | { | 518 | { |
528 | struct ds2482_data *data = i2c_get_clientdata(client); | 519 | struct ds2482_data *data = i2c_get_clientdata(client); |
529 | int err, idx; | 520 | int idx; |
530 | 521 | ||
531 | /* Unregister the 1-wire bridge(s) */ | 522 | /* Unregister the 1-wire bridge(s) */ |
532 | for (idx = 0; idx < data->w1_count; idx++) { | 523 | for (idx = 0; idx < data->w1_count; idx++) { |
@@ -534,13 +525,6 @@ static int ds2482_detach_client(struct i2c_client *client) | |||
534 | w1_remove_master_device(&data->w1_ch[idx].w1_bm); | 525 | w1_remove_master_device(&data->w1_ch[idx].w1_bm); |
535 | } | 526 | } |
536 | 527 | ||
537 | /* Detach the i2c device */ | ||
538 | if ((err = i2c_detach_client(client))) { | ||
539 | dev_err(&client->dev, | ||
540 | "Deregistration failed, client not detached.\n"); | ||
541 | return err; | ||
542 | } | ||
543 | |||
544 | /* Free the memory */ | 528 | /* Free the memory */ |
545 | kfree(data); | 529 | kfree(data); |
546 | return 0; | 530 | return 0; |