diff options
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm93.c | 126 |
1 files changed, 60 insertions, 66 deletions
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) |