Message ID | 20230828095116.36922-1-biju.das.jz@bp.renesas.com (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | rtc: pcf2127: Simplify probe() | expand |
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 >
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 > >
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",
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(-)