summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2019-05-20 03:10:41 -0400
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2019-05-28 11:54:51 -0400
commite7308628d0ae5c90d2895d0f3e6030c390431ca6 (patch)
treebe8eaf993e89a02bf672e2be8a668214f514d8d6 /drivers/misc
parenta188339ca5a396acc588e5851ed7e19f66b0ebd9 (diff)
eeprom: at24: use devm_i2c_new_dummy_device()
Now that it's upstream, use the resource managed version of i2c_new_dummy_device(). Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/eeprom/at24.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 63aa541c9608..bdeec0777029 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -507,14 +507,6 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
507 return cdata; 507 return cdata;
508} 508}
509 509
510static void at24_remove_dummy_clients(struct at24_data *at24)
511{
512 int i;
513
514 for (i = 1; i < at24->num_addresses; i++)
515 i2c_unregister_device(at24->client[i].client);
516}
517
518static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, 510static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
519 struct regmap_config *regmap_config) 511 struct regmap_config *regmap_config)
520{ 512{
@@ -527,18 +519,14 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
527 dev = &base_client->dev; 519 dev = &base_client->dev;
528 addr = base_client->addr + index; 520 addr = base_client->addr + index;
529 521
530 dummy_client = i2c_new_dummy(base_client->adapter, 522 dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
531 base_client->addr + index); 523 base_client->addr + index);
532 if (!dummy_client) { 524 if (IS_ERR(dummy_client))
533 dev_err(dev, "address 0x%02x unavailable\n", addr); 525 return PTR_ERR(dummy_client);
534 return -EADDRINUSE;
535 }
536 526
537 regmap = devm_regmap_init_i2c(dummy_client, regmap_config); 527 regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
538 if (IS_ERR(regmap)) { 528 if (IS_ERR(regmap))
539 i2c_unregister_device(dummy_client);
540 return PTR_ERR(regmap); 529 return PTR_ERR(regmap);
541 }
542 530
543 at24->client[index].client = dummy_client; 531 at24->client[index].client = dummy_client;
544 at24->client[index].regmap = regmap; 532 at24->client[index].regmap = regmap;
@@ -693,10 +681,8 @@ static int at24_probe(struct i2c_client *client)
693 /* use dummy devices for multiple-address chips */ 681 /* use dummy devices for multiple-address chips */
694 for (i = 1; i < num_addresses; i++) { 682 for (i = 1; i < num_addresses; i++) {
695 err = at24_make_dummy_client(at24, i, &regmap_config); 683 err = at24_make_dummy_client(at24, i, &regmap_config);
696 if (err) { 684 if (err)
697 at24_remove_dummy_clients(at24);
698 return err; 685 return err;
699 }
700 } 686 }
701 687
702 i2c_set_clientdata(client, at24); 688 i2c_set_clientdata(client, at24);
@@ -713,7 +699,7 @@ static int at24_probe(struct i2c_client *client)
713 pm_runtime_idle(dev); 699 pm_runtime_idle(dev);
714 if (err) { 700 if (err) {
715 err = -ENODEV; 701 err = -ENODEV;
716 goto err_clients; 702 goto err_runtime_pm;
717 } 703 }
718 704
719 nvmem_config.name = dev_name(dev); 705 nvmem_config.name = dev_name(dev);
@@ -733,7 +719,7 @@ static int at24_probe(struct i2c_client *client)
733 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 719 at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
734 if (IS_ERR(at24->nvmem)) { 720 if (IS_ERR(at24->nvmem)) {
735 err = PTR_ERR(at24->nvmem); 721 err = PTR_ERR(at24->nvmem);
736 goto err_clients; 722 goto err_runtime_pm;
737 } 723 }
738 724
739 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 725 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n",
@@ -742,8 +728,7 @@ static int at24_probe(struct i2c_client *client)
742 728
743 return 0; 729 return 0;
744 730
745err_clients: 731err_runtime_pm:
746 at24_remove_dummy_clients(at24);
747 pm_runtime_disable(dev); 732 pm_runtime_disable(dev);
748 733
749 return err; 734 return err;
@@ -751,11 +736,6 @@ err_clients:
751 736
752static int at24_remove(struct i2c_client *client) 737static int at24_remove(struct i2c_client *client)
753{ 738{
754 struct at24_data *at24;
755
756 at24 = i2c_get_clientdata(client);
757
758 at24_remove_dummy_clients(at24);
759 pm_runtime_disable(&client->dev); 739 pm_runtime_disable(&client->dev);
760 pm_runtime_set_suspended(&client->dev); 740 pm_runtime_set_suspended(&client->dev);
761 741