diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-07-16 13:30:09 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-07-16 13:30:09 -0400 |
commit | 9c97fb4d255fbf6713ee2d77dd8ed8ae770a7e49 (patch) | |
tree | d3f613aebbe01f2c13ef1f7fcd8b30724561fa29 | |
parent | 57f7eb0bcb2316dc264cd26f38b33dd2cf3151c1 (diff) |
hwmon: (adm1029) Convert to a new-style i2c driver
The new-style adm1029 driver implements the optional detect() callback
to cover the use cases of the legacy driver.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Corentin Labbe <corentin.labbe@geomatys.fr>
-rw-r--r-- | drivers/hwmon/adm1029.c | 97 |
1 files changed, 44 insertions, 53 deletions
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 | } |