Linux RTC
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf2127: Simplify probe()
@ 2023-08-28  9:51 Biju Das
  2023-08-28 10:08 ` Alexandre Belloni
  0 siblings, 1 reply; 3+ messages in thread
From: Biju Das @ 2023-08-28  9:51 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, linux-rtc, Geert Uytterhoeven, Andy Shevchenko,
	Prabhakar Mahadev Lad, linux-renesas-soc

Make similar OF and ID table for I2C and simpilfy probe() by replacing
of_device_get_match_data() and id lookup for retrieving match data by
i2c_get_match_data().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
Note:
 * This patch is only compile tested.
---
 drivers/rtc/rtc-pcf2127.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 9c04c4e1a49c..ec3968e3b8ac 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -1349,15 +1349,6 @@ static const struct regmap_bus pcf2127_i2c_regmap = {
 
 static struct i2c_driver pcf2127_i2c_driver;
 
-static const struct i2c_device_id pcf2127_i2c_id[] = {
-	{ "pcf2127", PCF2127 },
-	{ "pcf2129", PCF2129 },
-	{ "pca2129", PCF2129 },
-	{ "pcf2131", PCF2131 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
-
 static int pcf2127_i2c_probe(struct i2c_client *client)
 {
 	struct regmap *regmap;
@@ -1370,18 +1361,9 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
 
-	if (client->dev.of_node) {
-		variant = of_device_get_match_data(&client->dev);
-		if (!variant)
-			return -ENODEV;
-	} else {
-		enum pcf21xx_type type =
-			i2c_match_id(pcf2127_i2c_id, client)->driver_data;
-
-		if (type >= PCF21XX_LAST_ID)
-			return -ENODEV;
-		variant = &pcf21xx_cfg[type];
-	}
+	variant = i2c_get_match_data(client);
+	if (!variant)
+		return -ENODEV;
 
 	config.max_register = variant->max_register,
 
@@ -1396,6 +1378,15 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
 	return pcf2127_probe(&client->dev, regmap, client->irq, variant);
 }
 
+static const struct i2c_device_id pcf2127_i2c_id[] = {
+	{ "pcf2127", (kernel_ulong_t)&pcf21xx_cfg[PCF2127] },
+	{ "pcf2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
+	{ "pca2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
+	{ "pcf2131", (kernel_ulong_t)&pcf21xx_cfg[PCF2131] },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
+
 static struct i2c_driver pcf2127_i2c_driver = {
 	.driver		= {
 		.name	= "rtc-pcf2127-i2c",
-- 
2.25.1


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

* Re: [PATCH] rtc: pcf2127: Simplify probe()
  2023-08-28  9:51 [PATCH] rtc: pcf2127: Simplify probe() Biju Das
@ 2023-08-28 10:08 ` Alexandre Belloni
  2023-08-28 10:31   ` Biju Das
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Belloni @ 2023-08-28 10:08 UTC (permalink / raw)
  To: Biju Das
  Cc: Alessandro Zummo, linux-rtc, Geert Uytterhoeven, Andy Shevchenko,
	Prabhakar Mahadev Lad, linux-renesas-soc

On 28/08/2023 10:51:16+0100, Biju Das wrote:
> Make similar OF and ID table for I2C and simpilfy probe() by replacing
> of_device_get_match_data() and id lookup for retrieving match data by
> i2c_get_match_data().
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> Note:
>  * This patch is only compile tested.

I would really prefer those kind of patches to be actually tested. Else,
I'm going to end up with 60 patches that may or may not break probing.

> ---
>  drivers/rtc/rtc-pcf2127.c | 33 ++++++++++++---------------------
>  1 file changed, 12 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> index 9c04c4e1a49c..ec3968e3b8ac 100644
> --- a/drivers/rtc/rtc-pcf2127.c
> +++ b/drivers/rtc/rtc-pcf2127.c
> @@ -1349,15 +1349,6 @@ static const struct regmap_bus pcf2127_i2c_regmap = {
>  
>  static struct i2c_driver pcf2127_i2c_driver;
>  
> -static const struct i2c_device_id pcf2127_i2c_id[] = {
> -	{ "pcf2127", PCF2127 },
> -	{ "pcf2129", PCF2129 },
> -	{ "pca2129", PCF2129 },
> -	{ "pcf2131", PCF2131 },
> -	{ }
> -};
> -MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
> -
>  static int pcf2127_i2c_probe(struct i2c_client *client)
>  {
>  	struct regmap *regmap;
> @@ -1370,18 +1361,9 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
>  		return -ENODEV;
>  
> -	if (client->dev.of_node) {
> -		variant = of_device_get_match_data(&client->dev);
> -		if (!variant)
> -			return -ENODEV;
> -	} else {
> -		enum pcf21xx_type type =
> -			i2c_match_id(pcf2127_i2c_id, client)->driver_data;
> -
> -		if (type >= PCF21XX_LAST_ID)
> -			return -ENODEV;
> -		variant = &pcf21xx_cfg[type];
> -	}
> +	variant = i2c_get_match_data(client);
> +	if (!variant)
> +		return -ENODEV;
>  
>  	config.max_register = variant->max_register,
>  
> @@ -1396,6 +1378,15 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
>  	return pcf2127_probe(&client->dev, regmap, client->irq, variant);
>  }
>  
> +static const struct i2c_device_id pcf2127_i2c_id[] = {
> +	{ "pcf2127", (kernel_ulong_t)&pcf21xx_cfg[PCF2127] },
> +	{ "pcf2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
> +	{ "pca2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
> +	{ "pcf2131", (kernel_ulong_t)&pcf21xx_cfg[PCF2131] },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
> +
>  static struct i2c_driver pcf2127_i2c_driver = {
>  	.driver		= {
>  		.name	= "rtc-pcf2127-i2c",
> -- 
> 2.25.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* RE: [PATCH] rtc: pcf2127: Simplify probe()
  2023-08-28 10:08 ` Alexandre Belloni
@ 2023-08-28 10:31   ` Biju Das
  0 siblings, 0 replies; 3+ messages in thread
From: Biju Das @ 2023-08-28 10:31 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, linux-rtc@vger.kernel.org, Geert Uytterhoeven,
	Andy Shevchenko, Prabhakar Mahadev Lad,
	linux-renesas-soc@vger.kernel.org

Hi Alexandre Belloni,

Thanks for the feedback.

> Subject: Re: [PATCH] rtc: pcf2127: Simplify probe()
> 
> On 28/08/2023 10:51:16+0100, Biju Das wrote:
> > Make similar OF and ID table for I2C and simpilfy probe() by replacing
> > of_device_get_match_data() and id lookup for retrieving match data by
> > i2c_get_match_data().
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > ---
> > Note:
> >  * This patch is only compile tested.
> 
> I would really prefer those kind of patches to be actually tested.

I agree, users of this driver can test this patch and add their
Tested by tag. It is similar to the change done for rtc-isl1208.c
driver and similar OF/ID match tables tested on that driver.

Cheers,
Biju

 Else,
> I'm going to end up with 60 patches that may or may not break probing.
> 
> > ---
> >  drivers/rtc/rtc-pcf2127.c | 33 ++++++++++++---------------------
> >  1 file changed, 12 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > index 9c04c4e1a49c..ec3968e3b8ac 100644
> > --- a/drivers/rtc/rtc-pcf2127.c
> > +++ b/drivers/rtc/rtc-pcf2127.c
> > @@ -1349,15 +1349,6 @@ static const struct regmap_bus
> > pcf2127_i2c_regmap = {
> >
> >  static struct i2c_driver pcf2127_i2c_driver;
> >
> > -static const struct i2c_device_id pcf2127_i2c_id[] = {
> > -	{ "pcf2127", PCF2127 },
> > -	{ "pcf2129", PCF2129 },
> > -	{ "pca2129", PCF2129 },
> > -	{ "pcf2131", PCF2131 },
> > -	{ }
> > -};
> > -MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
> > -
> >  static int pcf2127_i2c_probe(struct i2c_client *client)  {
> >  	struct regmap *regmap;
> > @@ -1370,18 +1361,9 @@ static int pcf2127_i2c_probe(struct i2c_client
> *client)
> >  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
> >  		return -ENODEV;
> >
> > -	if (client->dev.of_node) {
> > -		variant = of_device_get_match_data(&client->dev);
> > -		if (!variant)
> > -			return -ENODEV;
> > -	} else {
> > -		enum pcf21xx_type type =
> > -			i2c_match_id(pcf2127_i2c_id, client)->driver_data;
> > -
> > -		if (type >= PCF21XX_LAST_ID)
> > -			return -ENODEV;
> > -		variant = &pcf21xx_cfg[type];
> > -	}
> > +	variant = i2c_get_match_data(client);
> > +	if (!variant)
> > +		return -ENODEV;
> >
> >  	config.max_register = variant->max_register,
> >
> > @@ -1396,6 +1378,15 @@ static int pcf2127_i2c_probe(struct i2c_client
> *client)
> >  	return pcf2127_probe(&client->dev, regmap, client->irq, variant);  }
> >
> > +static const struct i2c_device_id pcf2127_i2c_id[] = {
> > +	{ "pcf2127", (kernel_ulong_t)&pcf21xx_cfg[PCF2127] },
> > +	{ "pcf2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
> > +	{ "pca2129", (kernel_ulong_t)&pcf21xx_cfg[PCF2129] },
> > +	{ "pcf2131", (kernel_ulong_t)&pcf21xx_cfg[PCF2131] },
> > +	{ }
> > +};
> > +MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
> > +
> >  static struct i2c_driver pcf2127_i2c_driver = {
> >  	.driver		= {
> >  		.name	= "rtc-pcf2127-i2c",
> > --
> > 2.25.1
> >

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

end of thread, other threads:[~2023-08-28 10:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-28  9:51 [PATCH] rtc: pcf2127: Simplify probe() Biju Das
2023-08-28 10:08 ` Alexandre Belloni
2023-08-28 10:31   ` Biju Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox