All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Match data improvements for bq24257_charger driver
@ 2023-09-02 19:33 Biju Das
  2023-09-02 19:33 ` [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync Biju Das
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Biju Das @ 2023-09-02 19:33 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Biju Das, linux-pm, linux-kernel, Biju Das, Andy Shevchenko

This patch series aims to add match data improvements for bq24257_charger
driver.

This patch series is only compile tested.

Biju Das (2):
  power: supply: bq24257_charger: Make chip type and name in sync
  power: supply: bq24257_charger: Some cleanups

 drivers/power/supply/bq24257_charger.c | 76 +++++++++++++-------------
 1 file changed, 38 insertions(+), 38 deletions(-)

-- 
2.25.1


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

* [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-02 19:33 [PATCH 0/2] Match data improvements for bq24257_charger driver Biju Das
@ 2023-09-02 19:33 ` Biju Das
  2023-09-04 10:07   ` Andy Shevchenko
  2023-09-02 19:33 ` [PATCH 2/2] power: supply: bq24257_charger: Some cleanups Biju Das
  2023-09-12 21:52 ` [PATCH 0/2] Match data improvements for bq24257_charger driver Sebastian Reichel
  2 siblings, 1 reply; 10+ messages in thread
From: Biju Das @ 2023-09-02 19:33 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Biju Das, linux-pm, linux-kernel, Biju Das, Andy Shevchenko

Add struct bq2425x_chip_info to make enum bq2425x_chip and it's name in
sync and replace chip->info in struct bq24257_device and add struct
bq2425x_chip_info as match data for OF/ACPI/ID tables.

Simpilfy probe() by replacing acpi_match_device() and id lookup for
retrieving match data by using i2c_get_match_data().

Drop bq2425x_chip_name as there is no user and also drop the comment
related to syncing chip and name as it is taken care by struct
bq2425x_chip_info.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/power/supply/bq24257_charger.c | 70 +++++++++++++-------------
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 2852860abf86..188812f4a79b 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -35,20 +35,15 @@
 
 #define BQ24257_ILIM_SET_DELAY		1000	/* msec */
 
-/*
- * When adding support for new devices make sure that enum bq2425x_chip and
- * bq2425x_chip_name[] always stay in sync!
- */
 enum bq2425x_chip {
 	BQ24250,
 	BQ24251,
 	BQ24257,
 };
 
-static const char *const bq2425x_chip_name[] = {
-	"bq24250",
-	"bq24251",
-	"bq24257",
+struct bq2425x_chip_info {
+	const char *const name;
+	enum bq2425x_chip chip;
 };
 
 enum bq24257_fields {
@@ -84,7 +79,7 @@ struct bq24257_device {
 	struct device *dev;
 	struct power_supply *charger;
 
-	enum bq2425x_chip chip;
+	const struct bq2425x_chip_info *info;
 
 	struct regmap *rmap;
 	struct regmap_field *rmap_fields[F_MAX_FIELDS];
@@ -329,7 +324,7 @@ static int bq24257_power_supply_get_property(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_MODEL_NAME:
-		val->strval = bq2425x_chip_name[bq->chip];
+		val->strval = bq->info->name;
 		break;
 
 	case POWER_SUPPLY_PROP_ONLINE:
@@ -947,10 +942,8 @@ static int bq24257_fw_probe(struct bq24257_device *bq)
 
 static int bq24257_probe(struct i2c_client *client)
 {
-	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct i2c_adapter *adapter = client->adapter;
 	struct device *dev = &client->dev;
-	const struct acpi_device_id *acpi_id;
 	struct bq24257_device *bq;
 	int ret;
 	int i;
@@ -967,17 +960,9 @@ static int bq24257_probe(struct i2c_client *client)
 	bq->client = client;
 	bq->dev = dev;
 
-	if (ACPI_HANDLE(dev)) {
-		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
-					    &client->dev);
-		if (!acpi_id) {
-			dev_err(dev, "Failed to match ACPI device\n");
-			return -ENODEV;
-		}
-		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
-	} else {
-		bq->chip = (enum bq2425x_chip)id->driver_data;
-	}
+	bq->info = i2c_get_match_data(client);
+	if (!bq->info)
+		return dev_err_probe(dev, -ENODEV, "Failed to match device\n");
 
 	mutex_init(&bq->lock);
 
@@ -1015,7 +1000,7 @@ static int bq24257_probe(struct i2c_client *client)
 	 * used for the automatic setting of the input current limit setting so
 	 * explicitly disable that feature.
 	 */
-	if (bq->chip == BQ24250)
+	if (bq->info->chip == BQ24250)
 		bq->iilimit_autoset_enable = false;
 
 	if (bq->iilimit_autoset_enable)
@@ -1028,7 +1013,7 @@ static int bq24257_probe(struct i2c_client *client)
 	 * the PG state. We also use a SW-based approach for all other devices
 	 * if the PG pin is either not defined or can't be probed.
 	 */
-	if (bq->chip != BQ24250)
+	if (bq->info->chip != BQ24250)
 		bq24257_pg_gpio_probe(bq);
 
 	if (PTR_ERR(bq->pg) == -EPROBE_DEFER)
@@ -1066,7 +1051,7 @@ static int bq24257_probe(struct i2c_client *client)
 					bq24257_irq_handler_thread,
 					IRQF_TRIGGER_FALLING |
 					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-					bq2425x_chip_name[bq->chip], bq);
+					bq->info->name, bq);
 	if (ret) {
 		dev_err(dev, "Failed to request IRQ #%d\n", client->irq);
 		return ret;
@@ -1132,27 +1117,42 @@ static const struct dev_pm_ops bq24257_pm = {
 	SET_SYSTEM_SLEEP_PM_OPS(bq24257_suspend, bq24257_resume)
 };
 
+static const struct bq2425x_chip_info bq24250_info = {
+	.name = "bq24250",
+	.chip = BQ24250,
+};
+
+static const struct bq2425x_chip_info bq24251_info = {
+	.name = "bq24251",
+	.chip = BQ24251,
+};
+
+static const struct bq2425x_chip_info bq24257_info = {
+	.name = "bq24257",
+	.chip = BQ24257,
+};
+
 static const struct i2c_device_id bq24257_i2c_ids[] = {
-	{ "bq24250", BQ24250 },
-	{ "bq24251", BQ24251 },
-	{ "bq24257", BQ24257 },
+	{ "bq24250", (kernel_ulong_t)&bq24250_info },
+	{ "bq24251", (kernel_ulong_t)&bq24251_info },
+	{ "bq24257", (kernel_ulong_t)&bq24257_info },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids);
 
 static const struct of_device_id bq24257_of_match[] __maybe_unused = {
-	{ .compatible = "ti,bq24250", },
-	{ .compatible = "ti,bq24251", },
-	{ .compatible = "ti,bq24257", },
+	{ .compatible = "ti,bq24250", &bq24250_info },
+	{ .compatible = "ti,bq24251", &bq24251_info },
+	{ .compatible = "ti,bq24257", &bq24257_info },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, bq24257_of_match);
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id bq24257_acpi_match[] = {
-	{ "BQ242500", BQ24250 },
-	{ "BQ242510", BQ24251 },
-	{ "BQ242570", BQ24257 },
+	{ "BQ242500", (kernel_ulong_t)&bq24250_info },
+	{ "BQ242510", (kernel_ulong_t)&bq24251_info },
+	{ "BQ242570", (kernel_ulong_t)&bq24257_info },
 	{},
 };
 MODULE_DEVICE_TABLE(acpi, bq24257_acpi_match);
-- 
2.25.1


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

* [PATCH 2/2] power: supply: bq24257_charger: Some cleanups
  2023-09-02 19:33 [PATCH 0/2] Match data improvements for bq24257_charger driver Biju Das
  2023-09-02 19:33 ` [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync Biju Das
@ 2023-09-02 19:33 ` Biju Das
  2023-09-04 10:08   ` Andy Shevchenko
  2023-09-12 21:52 ` [PATCH 0/2] Match data improvements for bq24257_charger driver Sebastian Reichel
  2 siblings, 1 reply; 10+ messages in thread
From: Biju Das @ 2023-09-02 19:33 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Biju Das, linux-pm, linux-kernel, Biju Das, Andy Shevchenko

Some cleanups:
 * Remove trailing comma in the terminator entry for OF/ID/ACPI table.
 * Drop a space from terminator entry for OF table.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/power/supply/bq24257_charger.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 188812f4a79b..801d0d2c5f2e 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -1136,7 +1136,7 @@ static const struct i2c_device_id bq24257_i2c_ids[] = {
 	{ "bq24250", (kernel_ulong_t)&bq24250_info },
 	{ "bq24251", (kernel_ulong_t)&bq24251_info },
 	{ "bq24257", (kernel_ulong_t)&bq24257_info },
-	{},
+	{}
 };
 MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids);
 
@@ -1144,7 +1144,7 @@ static const struct of_device_id bq24257_of_match[] __maybe_unused = {
 	{ .compatible = "ti,bq24250", &bq24250_info },
 	{ .compatible = "ti,bq24251", &bq24251_info },
 	{ .compatible = "ti,bq24257", &bq24257_info },
-	{ },
+	{}
 };
 MODULE_DEVICE_TABLE(of, bq24257_of_match);
 
@@ -1153,7 +1153,7 @@ static const struct acpi_device_id bq24257_acpi_match[] = {
 	{ "BQ242500", (kernel_ulong_t)&bq24250_info },
 	{ "BQ242510", (kernel_ulong_t)&bq24251_info },
 	{ "BQ242570", (kernel_ulong_t)&bq24257_info },
-	{},
+	{}
 };
 MODULE_DEVICE_TABLE(acpi, bq24257_acpi_match);
 #endif
-- 
2.25.1


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

* Re: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-02 19:33 ` [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync Biju Das
@ 2023-09-04 10:07   ` Andy Shevchenko
  2023-09-10  7:10     ` Biju Das
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-09-04 10:07 UTC (permalink / raw)
  To: Biju Das; +Cc: Sebastian Reichel, linux-pm, linux-kernel, Biju Das

On Sat, Sep 02, 2023 at 08:33:30PM +0100, Biju Das wrote:
> Add struct bq2425x_chip_info to make enum bq2425x_chip and it's name in
> sync and replace chip->info in struct bq24257_device and add struct
> bq2425x_chip_info as match data for OF/ACPI/ID tables.
> 
> Simpilfy probe() by replacing acpi_match_device() and id lookup for
> retrieving match data by using i2c_get_match_data().
> 
> Drop bq2425x_chip_name as there is no user and also drop the comment
> related to syncing chip and name as it is taken care by struct
> bq2425x_chip_info.

...

> -	if (ACPI_HANDLE(dev)) {
> -		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
> -					    &client->dev);
> -		if (!acpi_id) {
> -			dev_err(dev, "Failed to match ACPI device\n");
> -			return -ENODEV;
> -		}
> -		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
> -	} else {
> -		bq->chip = (enum bq2425x_chip)id->driver_data;
> -	}

Do we still need acpi.h after this change?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 2/2] power: supply: bq24257_charger: Some cleanups
  2023-09-02 19:33 ` [PATCH 2/2] power: supply: bq24257_charger: Some cleanups Biju Das
@ 2023-09-04 10:08   ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-09-04 10:08 UTC (permalink / raw)
  To: Biju Das; +Cc: Sebastian Reichel, linux-pm, linux-kernel, Biju Das

On Sat, Sep 02, 2023 at 08:33:31PM +0100, Biju Das wrote:
> Some cleanups:
>  * Remove trailing comma in the terminator entry for OF/ID/ACPI table.
>  * Drop a space from terminator entry for OF table.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* RE: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-04 10:07   ` Andy Shevchenko
@ 2023-09-10  7:10     ` Biju Das
  2023-09-11 10:15       ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Biju Das @ 2023-09-10  7:10 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Sebastian Reichel, linux-pm, linux-kernel, Biju Das

Hi Andy Shevchenko,

> Subject: Re: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and
> name in sync
> 
> On Sat, Sep 02, 2023 at 08:33:30PM +0100, Biju Das wrote:
> > Add struct bq2425x_chip_info to make enum bq2425x_chip and it's name
> > in sync and replace chip->info in struct bq24257_device and add struct
> > bq2425x_chip_info as match data for OF/ACPI/ID tables.
> >
> > Simpilfy probe() by replacing acpi_match_device() and id lookup for
> > retrieving match data by using i2c_get_match_data().
> >
> > Drop bq2425x_chip_name as there is no user and also drop the comment
> > related to syncing chip and name as it is taken care by struct
> > bq2425x_chip_info.
> 
> ...
> 
> > -	if (ACPI_HANDLE(dev)) {
> > -		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
> > -					    &client->dev);
> > -		if (!acpi_id) {
> > -			dev_err(dev, "Failed to match ACPI device\n");
> > -			return -ENODEV;
> > -		}
> > -		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
> > -	} else {
> > -		bq->chip = (enum bq2425x_chip)id->driver_data;
> > -	}
> 
> Do we still need acpi.h after this change?

Yes, it is still needed as it is using 
ACPI_PTR.

Cheers,
Biju

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

* Re: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-10  7:10     ` Biju Das
@ 2023-09-11 10:15       ` Andy Shevchenko
  2023-09-12 21:49         ` Sebastian Reichel
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-09-11 10:15 UTC (permalink / raw)
  To: Biju Das; +Cc: Sebastian Reichel, linux-pm, linux-kernel, Biju Das

On Sun, Sep 10, 2023 at 07:10:06AM +0000, Biju Das wrote:
> Hi Andy Shevchenko,
> > On Sat, Sep 02, 2023 at 08:33:30PM +0100, Biju Das wrote:

...

> > > -	if (ACPI_HANDLE(dev)) {
> > > -		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
> > > -					    &client->dev);
> > > -		if (!acpi_id) {
> > > -			dev_err(dev, "Failed to match ACPI device\n");
> > > -			return -ENODEV;
> > > -		}
> > > -		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
> > > -	} else {
> > > -		bq->chip = (enum bq2425x_chip)id->driver_data;
> > > -	}
> > 
> > Do we still need acpi.h after this change?
> 
> Yes, it is still needed as it is using 
> ACPI_PTR.

Can we, please, drop ACPI_PTR() as it's more harmful than useful (same way as
you dropped the ifdeffery for OF cases in other patches)?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-11 10:15       ` Andy Shevchenko
@ 2023-09-12 21:49         ` Sebastian Reichel
  2023-09-13 11:23           ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastian Reichel @ 2023-09-12 21:49 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Biju Das, linux-pm, linux-kernel, Biju Das

[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]

Hi,

On Mon, Sep 11, 2023 at 01:15:09PM +0300, Andy Shevchenko wrote:
> On Sun, Sep 10, 2023 at 07:10:06AM +0000, Biju Das wrote:
> > Hi Andy Shevchenko,
> > > On Sat, Sep 02, 2023 at 08:33:30PM +0100, Biju Das wrote:
> 
> ...
> 
> > > > -	if (ACPI_HANDLE(dev)) {
> > > > -		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
> > > > -					    &client->dev);
> > > > -		if (!acpi_id) {
> > > > -			dev_err(dev, "Failed to match ACPI device\n");
> > > > -			return -ENODEV;
> > > > -		}
> > > > -		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
> > > > -	} else {
> > > > -		bq->chip = (enum bq2425x_chip)id->driver_data;
> > > > -	}
> > > 
> > > Do we still need acpi.h after this change?
> > 
> > Yes, it is still needed as it is using 
> > ACPI_PTR.
> 
> Can we, please, drop ACPI_PTR() as it's more harmful than useful (same way as
> you dropped the ifdeffery for OF cases in other patches)?

I will go ahead and merge this series, ACPI_PTR() and
of_match_ptr() should be removed in a separate cleanup patch.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 0/2] Match data improvements for bq24257_charger driver
  2023-09-02 19:33 [PATCH 0/2] Match data improvements for bq24257_charger driver Biju Das
  2023-09-02 19:33 ` [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync Biju Das
  2023-09-02 19:33 ` [PATCH 2/2] power: supply: bq24257_charger: Some cleanups Biju Das
@ 2023-09-12 21:52 ` Sebastian Reichel
  2 siblings, 0 replies; 10+ messages in thread
From: Sebastian Reichel @ 2023-09-12 21:52 UTC (permalink / raw)
  To: Sebastian Reichel, Biju Das
  Cc: linux-pm, linux-kernel, Biju Das, Andy Shevchenko


On Sat, 02 Sep 2023 20:33:29 +0100, Biju Das wrote:
> This patch series aims to add match data improvements for bq24257_charger
> driver.
> 
> This patch series is only compile tested.
> 
> Biju Das (2):
>   power: supply: bq24257_charger: Make chip type and name in sync
>   power: supply: bq24257_charger: Some cleanups
> 
> [...]

Applied, thanks!

[1/2] power: supply: bq24257_charger: Make chip type and name in sync
      commit: 3dc4a291a1b156d3ee9a78672ec950601bd68c1c
[2/2] power: supply: bq24257_charger: Some cleanups
      commit: b92f5e4fccc2ca96241904bb1a4e96547b69163d

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


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

* Re: [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync
  2023-09-12 21:49         ` Sebastian Reichel
@ 2023-09-13 11:23           ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-09-13 11:23 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Biju Das, linux-pm, linux-kernel, Biju Das

On Tue, Sep 12, 2023 at 11:49:25PM +0200, Sebastian Reichel wrote:
> On Mon, Sep 11, 2023 at 01:15:09PM +0300, Andy Shevchenko wrote:
> > On Sun, Sep 10, 2023 at 07:10:06AM +0000, Biju Das wrote:
> > > Hi Andy Shevchenko,
> > > > On Sat, Sep 02, 2023 at 08:33:30PM +0100, Biju Das wrote:

...

> > > > Do we still need acpi.h after this change?
> > > 
> > > Yes, it is still needed as it is using 
> > > ACPI_PTR.
> > 
> > Can we, please, drop ACPI_PTR() as it's more harmful than useful (same way as
> > you dropped the ifdeffery for OF cases in other patches)?
> 
> I will go ahead and merge this series, ACPI_PTR() and
> of_match_ptr() should be removed in a separate cleanup patch.

Sure, that's exactly what I expects to happen.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-09-13 11:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-02 19:33 [PATCH 0/2] Match data improvements for bq24257_charger driver Biju Das
2023-09-02 19:33 ` [PATCH 1/2] power: supply: bq24257_charger: Make chip type and name in sync Biju Das
2023-09-04 10:07   ` Andy Shevchenko
2023-09-10  7:10     ` Biju Das
2023-09-11 10:15       ` Andy Shevchenko
2023-09-12 21:49         ` Sebastian Reichel
2023-09-13 11:23           ` Andy Shevchenko
2023-09-02 19:33 ` [PATCH 2/2] power: supply: bq24257_charger: Some cleanups Biju Das
2023-09-04 10:08   ` Andy Shevchenko
2023-09-12 21:52 ` [PATCH 0/2] Match data improvements for bq24257_charger driver Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.