LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring
@ 2018-04-11 14:38 Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 1/3] eeprom: at24: use devm_nvmem_register() Bartosz Golaszewski
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2018-04-11 14:38 UTC (permalink / raw)
  To: Andy Shevchenko, Peter Rosin, Sven Van Asbroeck
  Cc: linux-i2c, linux-kernel, Bartosz Golaszewski

This is a follow-up to the big series merged for 4.17. The patches
contain some bits and pieces that were missing in the last submission
or depend on some new features merged this merge window.

v1 -> v2:
- dropped patch 1/4 because id_table is still needed as pointed out by
  Peter Rosin
- fixed patch 3/3: we need to free the dummy client if regmap_init fails

Bartosz Golaszewski (3):
  eeprom: at24: use devm_nvmem_register()
  eeprom: at24: provide and use a helper for releasing dummy i2c clients
  eeprom: at24: provide a separate routine for creating dummy i2c
    clients

 drivers/misc/eeprom/at24.c | 71 ++++++++++++++++++++++++--------------
 1 file changed, 46 insertions(+), 25 deletions(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] eeprom: at24: use devm_nvmem_register()
  2018-04-11 14:38 [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Bartosz Golaszewski
@ 2018-04-11 14:38 ` Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 2/3] eeprom: at24: provide and use a helper for releasing dummy i2c clients Bartosz Golaszewski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2018-04-11 14:38 UTC (permalink / raw)
  To: Andy Shevchenko, Peter Rosin, Sven Van Asbroeck
  Cc: linux-i2c, linux-kernel, Bartosz Golaszewski

We now have a managed variant of nvmem_register(). Use it
in at24_probe().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/misc/eeprom/at24.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 0c125f207aea..02c9dd835547 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -685,7 +685,7 @@ static int at24_probe(struct i2c_client *client)
 	nvmem_config.word_size = 1;
 	nvmem_config.size = pdata.byte_len;
 
-	at24->nvmem = nvmem_register(&nvmem_config);
+	at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
 	if (IS_ERR(at24->nvmem)) {
 		err = PTR_ERR(at24->nvmem);
 		goto err_clients;
@@ -718,8 +718,6 @@ static int at24_remove(struct i2c_client *client)
 
 	at24 = i2c_get_clientdata(client);
 
-	nvmem_unregister(at24->nvmem);
-
 	for (i = 1; i < at24->num_addresses; i++)
 		i2c_unregister_device(at24->client[i].client);
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] eeprom: at24: provide and use a helper for releasing dummy i2c clients
  2018-04-11 14:38 [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 1/3] eeprom: at24: use devm_nvmem_register() Bartosz Golaszewski
@ 2018-04-11 14:38 ` Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 3/3] eeprom: at24: provide a separate routine for creating " Bartosz Golaszewski
  2018-04-12 15:08 ` [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Peter Rosin
  3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2018-04-11 14:38 UTC (permalink / raw)
  To: Andy Shevchenko, Peter Rosin, Sven Van Asbroeck
  Cc: linux-i2c, linux-kernel, Bartosz Golaszewski

This allows us to drop two opencoded for loops. We also don't need to
check if the i2c client is NULL before calling i2c_unregister_device().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/misc/eeprom/at24.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 02c9dd835547..163ef7bf18e3 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -532,6 +532,14 @@ static int at24_get_pdata(struct device *dev, struct at24_platform_data *pdata)
 	return 0;
 }
 
+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 unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
 {
 	if (flags & AT24_FLAG_MAC) {
@@ -702,10 +710,7 @@ static int at24_probe(struct i2c_client *client)
 	return 0;
 
 err_clients:
-	for (i = 1; i < num_addresses; i++)
-		if (at24->client[i].client)
-			i2c_unregister_device(at24->client[i].client);
-
+	at24_remove_dummy_clients(at24);
 	pm_runtime_disable(dev);
 
 	return err;
@@ -714,13 +719,10 @@ static int at24_probe(struct i2c_client *client)
 static int at24_remove(struct i2c_client *client)
 {
 	struct at24_data *at24;
-	int i;
 
 	at24 = i2c_get_clientdata(client);
 
-	for (i = 1; i < at24->num_addresses; i++)
-		i2c_unregister_device(at24->client[i].client);
-
+	at24_remove_dummy_clients(at24);
 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] eeprom: at24: provide a separate routine for creating dummy i2c clients
  2018-04-11 14:38 [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 1/3] eeprom: at24: use devm_nvmem_register() Bartosz Golaszewski
  2018-04-11 14:38 ` [PATCH v2 2/3] eeprom: at24: provide and use a helper for releasing dummy i2c clients Bartosz Golaszewski
@ 2018-04-11 14:38 ` Bartosz Golaszewski
  2018-04-12 15:08 ` [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Peter Rosin
  3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2018-04-11 14:38 UTC (permalink / raw)
  To: Andy Shevchenko, Peter Rosin, Sven Van Asbroeck
  Cc: linux-i2c, linux-kernel, Bartosz Golaszewski

Move the code responsible for creating the dummy i2c clients used by
chips taking multiple slave addresses to a separate function.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/misc/eeprom/at24.c | 49 +++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 163ef7bf18e3..b00e2b5c47e8 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -540,6 +540,37 @@ static void at24_remove_dummy_clients(struct at24_data *at24)
 		i2c_unregister_device(at24->client[i].client);
 }
 
+static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
+				  struct regmap_config *regmap_config)
+{
+	struct i2c_client *base_client, *dummy_client;
+	unsigned short int addr;
+	struct regmap *regmap;
+	struct device *dev;
+
+	base_client = at24->client[0].client;
+	dev = &base_client->dev;
+	addr = base_client->addr + index;
+
+	dummy_client = i2c_new_dummy(base_client->adapter,
+				     base_client->addr + index);
+	if (!dummy_client) {
+		dev_err(dev, "address 0x%02x unavailable\n", addr);
+		return -EADDRINUSE;
+	}
+
+	regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
+	if (IS_ERR(regmap)) {
+		i2c_unregister_device(dummy_client);
+		return PTR_ERR(regmap);
+	}
+
+	at24->client[index].client = dummy_client;
+	at24->client[index].regmap = regmap;
+
+	return 0;
+}
+
 static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
 {
 	if (flags & AT24_FLAG_MAC) {
@@ -645,20 +676,10 @@ static int at24_probe(struct i2c_client *client)
 
 	/* use dummy devices for multiple-address chips */
 	for (i = 1; i < num_addresses; i++) {
-		at24->client[i].client = i2c_new_dummy(client->adapter,
-						       client->addr + i);
-		if (!at24->client[i].client) {
-			dev_err(dev, "address 0x%02x unavailable\n",
-				client->addr + i);
-			err = -EADDRINUSE;
-			goto err_clients;
-		}
-		at24->client[i].regmap = devm_regmap_init_i2c(
-						at24->client[i].client,
-						&regmap_config);
-		if (IS_ERR(at24->client[i].regmap)) {
-			err = PTR_ERR(at24->client[i].regmap);
-			goto err_clients;
+		err = at24_make_dummy_client(at24, i, &regmap_config);
+		if (err) {
+			at24_remove_dummy_clients(at24);
+			return err;
 		}
 	}
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring
  2018-04-11 14:38 [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2018-04-11 14:38 ` [PATCH v2 3/3] eeprom: at24: provide a separate routine for creating " Bartosz Golaszewski
@ 2018-04-12 15:08 ` Peter Rosin
  2018-04-20 12:30   ` Bartosz Golaszewski
  3 siblings, 1 reply; 6+ messages in thread
From: Peter Rosin @ 2018-04-12 15:08 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, Sven Van Asbroeck
  Cc: linux-i2c, linux-kernel

On 2018-04-11 16:38, Bartosz Golaszewski wrote:
> This is a follow-up to the big series merged for 4.17. The patches
> contain some bits and pieces that were missing in the last submission
> or depend on some new features merged this merge window.
> 
> v1 -> v2:
> - dropped patch 1/4 because id_table is still needed as pointed out by
>   Peter Rosin
> - fixed patch 3/3: we need to free the dummy client if regmap_init fails
> 
> Bartosz Golaszewski (3):
>   eeprom: at24: use devm_nvmem_register()
>   eeprom: at24: provide and use a helper for releasing dummy i2c clients
>   eeprom: at24: provide a separate routine for creating dummy i2c
>     clients

For all three:

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring
  2018-04-12 15:08 ` [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Peter Rosin
@ 2018-04-20 12:30   ` Bartosz Golaszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2018-04-20 12:30 UTC (permalink / raw)
  To: Peter Rosin
  Cc: Andy Shevchenko, Sven Van Asbroeck, linux-i2c, Linux Kernel Mailing List

2018-04-12 17:08 GMT+02:00 Peter Rosin <peda@axentia.se>:
> On 2018-04-11 16:38, Bartosz Golaszewski wrote:
>> This is a follow-up to the big series merged for 4.17. The patches
>> contain some bits and pieces that were missing in the last submission
>> or depend on some new features merged this merge window.
>>
>> v1 -> v2:
>> - dropped patch 1/4 because id_table is still needed as pointed out by
>>   Peter Rosin
>> - fixed patch 3/3: we need to free the dummy client if regmap_init fails
>>
>> Bartosz Golaszewski (3):
>>   eeprom: at24: use devm_nvmem_register()
>>   eeprom: at24: provide and use a helper for releasing dummy i2c clients
>>   eeprom: at24: provide a separate routine for creating dummy i2c
>>     clients
>
> For all three:
>
> Reviewed-by: Peter Rosin <peda@axentia.se>
>
> Cheers,
> Peter

Applied to at24/for-next.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-20 12:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-11 14:38 [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Bartosz Golaszewski
2018-04-11 14:38 ` [PATCH v2 1/3] eeprom: at24: use devm_nvmem_register() Bartosz Golaszewski
2018-04-11 14:38 ` [PATCH v2 2/3] eeprom: at24: provide and use a helper for releasing dummy i2c clients Bartosz Golaszewski
2018-04-11 14:38 ` [PATCH v2 3/3] eeprom: at24: provide a separate routine for creating " Bartosz Golaszewski
2018-04-12 15:08 ` [PATCH v2 0/3] eeprom: at24: last bits of the big refactoring Peter Rosin
2018-04-20 12:30   ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).