Commit e7308628 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

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: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
parent a188339c
...@@ -507,14 +507,6 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev) ...@@ -507,14 +507,6 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
return cdata; return cdata;
} }
static void at24_remove_dummy_clients(struct at24_data *at24)
{
int i;
for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i].client);
}
static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
struct regmap_config *regmap_config) struct regmap_config *regmap_config)
{ {
...@@ -527,18 +519,14 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, ...@@ -527,18 +519,14 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
dev = &base_client->dev; dev = &base_client->dev;
addr = base_client->addr + index; addr = base_client->addr + index;
dummy_client = i2c_new_dummy(base_client->adapter, dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
base_client->addr + index); base_client->addr + index);
if (!dummy_client) { if (IS_ERR(dummy_client))
dev_err(dev, "address 0x%02x unavailable\n", addr); return PTR_ERR(dummy_client);
return -EADDRINUSE;
}
regmap = devm_regmap_init_i2c(dummy_client, regmap_config); regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap))
i2c_unregister_device(dummy_client);
return PTR_ERR(regmap); return PTR_ERR(regmap);
}
at24->client[index].client = dummy_client; at24->client[index].client = dummy_client;
at24->client[index].regmap = regmap; at24->client[index].regmap = regmap;
...@@ -693,11 +681,9 @@ static int at24_probe(struct i2c_client *client) ...@@ -693,11 +681,9 @@ static int at24_probe(struct i2c_client *client)
/* use dummy devices for multiple-address chips */ /* use dummy devices for multiple-address chips */
for (i = 1; i < num_addresses; i++) { for (i = 1; i < num_addresses; i++) {
err = at24_make_dummy_client(at24, i, &regmap_config); err = at24_make_dummy_client(at24, i, &regmap_config);
if (err) { if (err)
at24_remove_dummy_clients(at24);
return err; return err;
} }
}
i2c_set_clientdata(client, at24); i2c_set_clientdata(client, at24);
...@@ -713,7 +699,7 @@ static int at24_probe(struct i2c_client *client) ...@@ -713,7 +699,7 @@ static int at24_probe(struct i2c_client *client)
pm_runtime_idle(dev); pm_runtime_idle(dev);
if (err) { if (err) {
err = -ENODEV; err = -ENODEV;
goto err_clients; goto err_runtime_pm;
} }
nvmem_config.name = dev_name(dev); nvmem_config.name = dev_name(dev);
...@@ -733,7 +719,7 @@ static int at24_probe(struct i2c_client *client) ...@@ -733,7 +719,7 @@ static int at24_probe(struct i2c_client *client)
at24->nvmem = devm_nvmem_register(dev, &nvmem_config); at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
if (IS_ERR(at24->nvmem)) { if (IS_ERR(at24->nvmem)) {
err = PTR_ERR(at24->nvmem); err = PTR_ERR(at24->nvmem);
goto err_clients; goto err_runtime_pm;
} }
dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 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,8 +728,7 @@ static int at24_probe(struct i2c_client *client)
return 0; return 0;
err_clients: err_runtime_pm:
at24_remove_dummy_clients(at24);
pm_runtime_disable(dev); pm_runtime_disable(dev);
return err; return err;
...@@ -751,11 +736,6 @@ static int at24_probe(struct i2c_client *client) ...@@ -751,11 +736,6 @@ static int at24_probe(struct i2c_client *client)
static int at24_remove(struct i2c_client *client) static int at24_remove(struct i2c_client *client)
{ {
struct at24_data *at24;
at24 = i2c_get_clientdata(client);
at24_remove_dummy_clients(at24);
pm_runtime_disable(&client->dev); pm_runtime_disable(&client->dev);
pm_runtime_set_suspended(&client->dev); pm_runtime_set_suspended(&client->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment