* [PATCH v2] i2c: Add i2c_get_match_data()
@ 2023-06-01 17:17 Biju Das
2023-06-02 6:45 ` Geert Uytterhoeven
2023-06-05 9:25 ` Wolfram Sang
0 siblings, 2 replies; 6+ messages in thread
From: Biju Das @ 2023-06-01 17:17 UTC (permalink / raw)
To: Wolfram Sang, Alessandro Zummo, Alexandre Belloni
Cc: Biju Das, linux-i2c, linux-rtc, Geert Uytterhoeven,
Prabhakar Mahadev Lad, linux-renesas-soc
Add i2c_get_match_data() similar to of_device_get_match_data(),
so that we can optimize the driver code that uses both I2C and
DT-based matching.
Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
* Dropped parameter const struct i2c_device_id *id and the helper function.
eg: The RTC pcf85063/isl1208 driver code can be optimized with this patch.
- if (client->dev.of_node) {
+ if (client->dev.of_node)
config = of_device_get_match_data(&client->dev);
- if (!config)
- return -ENODEV;
- } else {
- enum pcf85063_type type =
- i2c_match_id(pcf85063_ids, client)->driver_data;
- if (type >= PCF85063_LAST_ID)
- return -ENODEV;
- config = &pcf85063_cfg[type];
- }
+ else
+ config = i2c_get_match_data(client);
+
+ if (!config)
+ return -ENODEV;
---
drivers/i2c/i2c-core-base.c | 14 ++++++++++++++
include/linux/i2c.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ae3af738b03f..8576a1647785 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -114,6 +114,20 @@ const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
}
EXPORT_SYMBOL_GPL(i2c_match_id);
+const void *i2c_get_match_data(const struct i2c_client *client)
+{
+ struct device_driver *drv = client->dev.driver;
+ struct i2c_driver *driver = to_i2c_driver(drv);
+ const struct i2c_device_id *match;
+
+ match = i2c_match_id(driver->id_table, client);
+ if (!match)
+ return NULL;
+
+ return (const void *)match->driver_data;
+}
+EXPORT_SYMBOL(i2c_get_match_data);
+
static int i2c_device_match(struct device *dev, struct device_driver *drv)
{
struct i2c_client *client = i2c_verify_client(dev);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 13a1ce38cb0c..3430cc2b05a6 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -367,6 +367,8 @@ struct i2c_adapter *i2c_verify_adapter(struct device *dev);
const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client);
+const void *i2c_get_match_data(const struct i2c_client *client);
+
static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
{
struct device * const dev = kobj_to_dev(kobj);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] i2c: Add i2c_get_match_data()
2023-06-01 17:17 [PATCH v2] i2c: Add i2c_get_match_data() Biju Das
@ 2023-06-02 6:45 ` Geert Uytterhoeven
2023-06-05 9:25 ` Wolfram Sang
1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-06-02 6:45 UTC (permalink / raw)
To: Biju Das
Cc: Wolfram Sang, Alessandro Zummo, Alexandre Belloni, linux-i2c,
linux-rtc, Geert Uytterhoeven, Prabhakar Mahadev Lad,
linux-renesas-soc
On Thu, Jun 1, 2023 at 7:17 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> Add i2c_get_match_data() similar to of_device_get_match_data(),
> so that we can optimize the driver code that uses both I2C and
> DT-based matching.
>
> Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v1->v2:
> * Dropped parameter const struct i2c_device_id *id and the helper function.
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] i2c: Add i2c_get_match_data()
2023-06-01 17:17 [PATCH v2] i2c: Add i2c_get_match_data() Biju Das
2023-06-02 6:45 ` Geert Uytterhoeven
@ 2023-06-05 9:25 ` Wolfram Sang
2023-06-05 9:47 ` Biju Das
1 sibling, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2023-06-05 9:25 UTC (permalink / raw)
To: Biju Das
Cc: Alessandro Zummo, Alexandre Belloni, linux-i2c, linux-rtc,
Geert Uytterhoeven, Prabhakar Mahadev Lad, linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 227 bytes --]
> + if (client->dev.of_node)
> config = of_device_get_match_data(&client->dev);
Has it been considered adding this check to the new helper function as
well? Saves even more boilerplate code, I'd think.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v2] i2c: Add i2c_get_match_data()
2023-06-05 9:25 ` Wolfram Sang
@ 2023-06-05 9:47 ` Biju Das
2023-06-05 10:01 ` Wolfram Sang
0 siblings, 1 reply; 6+ messages in thread
From: Biju Das @ 2023-06-05 9:47 UTC (permalink / raw)
To: Wolfram Sang
Cc: Alessandro Zummo, Alexandre Belloni, linux-i2c, linux-rtc,
Geert Uytterhoeven, Prabhakar Mahadev Lad, linux-renesas-soc
Hi Wolfram,
Thanks for the feedback.
> -----Original Message-----
> From: Wolfram Sang <wsa@kernel.org>
> Sent: Monday, June 5, 2023 10:25 AM
> To: Biju Das <biju.das.jz@bp.renesas.com>
> Cc: Alessandro Zummo <a.zummo@towertech.it>; Alexandre Belloni
> <alexandre.belloni@bootlin.com>; linux-i2c@vger.kernel.org; linux-
> rtc@vger.kernel.org; Geert Uytterhoeven <geert+renesas@glider.be>;
> Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>; linux-
> renesas-soc@vger.kernel.org
> Subject: Re: [PATCH v2] i2c: Add i2c_get_match_data()
>
>
> > + if (client->dev.of_node)
> > config = of_device_get_match_data(&client->dev);
>
> Has it been considered adding this check to the new helper function as
> well? Saves even more boilerplate code, I'd think.
You mean like below?? The new helper function will do both I2C and DT-based matching??
const void *i2c_get_match_data(const struct i2c_client *client)
{
struct device_driver *drv = client->dev.driver;
struct i2c_driver *driver = to_i2c_driver(drv);
const struct i2c_device_id *match;
const void *match_data;
if (client->dev.of_node){
match_data = of_device_get_match_data(&client->dev);
} else {
match = i2c_match_id(driver->id_table, client);
if (!match)
return NULL;
match_data = (const void *)match->driver_data;
}
return match_data;
}
EXPORT_SYMBOL(i2c_get_match_data);
Cheers,
Biju
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] i2c: Add i2c_get_match_data()
2023-06-05 9:47 ` Biju Das
@ 2023-06-05 10:01 ` Wolfram Sang
2023-06-05 10:24 ` Biju Das
0 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2023-06-05 10:01 UTC (permalink / raw)
To: Biju Das
Cc: Alessandro Zummo, Alexandre Belloni, linux-i2c, linux-rtc,
Geert Uytterhoeven, Prabhakar Mahadev Lad, linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 814 bytes --]
> You mean like below?? The new helper function will do both I2C and DT-based matching??
> const void *i2c_get_match_data(const struct i2c_client *client)
> {
> struct device_driver *drv = client->dev.driver;
> struct i2c_driver *driver = to_i2c_driver(drv);
> const struct i2c_device_id *match;
> const void *match_data;
>
> if (client->dev.of_node){
> match_data = of_device_get_match_data(&client->dev);
> } else {
> match = i2c_match_id(driver->id_table, client);
> if (!match)
> return NULL;
>
> match_data = (const void *)match->driver_data;
> }
>
> return match_data;
> }
> EXPORT_SYMBOL(i2c_get_match_data);
Yes. Not good? I thought a function named 'i2c_get_match_data' should
get match_data and find out itself where it is coming from. No?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v2] i2c: Add i2c_get_match_data()
2023-06-05 10:01 ` Wolfram Sang
@ 2023-06-05 10:24 ` Biju Das
0 siblings, 0 replies; 6+ messages in thread
From: Biju Das @ 2023-06-05 10:24 UTC (permalink / raw)
To: Wolfram Sang
Cc: Alessandro Zummo, Alexandre Belloni, linux-i2c, linux-rtc,
Geert Uytterhoeven, Prabhakar Mahadev Lad, linux-renesas-soc
Hi Wolfram,
> Subject: Re: [PATCH v2] i2c: Add i2c_get_match_data()
>
>
> > You mean like below?? The new helper function will do both I2C and DT-
> based matching??
> > const void *i2c_get_match_data(const struct i2c_client *client) {
> > struct device_driver *drv = client->dev.driver;
> > struct i2c_driver *driver = to_i2c_driver(drv);
> > const struct i2c_device_id *match;
> > const void *match_data;
> >
> > if (client->dev.of_node){
> > match_data = of_device_get_match_data(&client->dev);
> > } else {
> > match = i2c_match_id(driver->id_table, client);
> > if (!match)
> > return NULL;
> >
> > match_data = (const void *)match->driver_data;
> > }
> >
> > return match_data;
> > }
> > EXPORT_SYMBOL(i2c_get_match_data);
>
> Yes. Not good? I thought a function named 'i2c_get_match_data' should
> get match_data and find out itself where it is coming from. No?
Yes, It looks good to me based on your explanation.
Cheers,
Biju
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-06-05 10:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 17:17 [PATCH v2] i2c: Add i2c_get_match_data() Biju Das
2023-06-02 6:45 ` Geert Uytterhoeven
2023-06-05 9:25 ` Wolfram Sang
2023-06-05 9:47 ` Biju Das
2023-06-05 10:01 ` Wolfram Sang
2023-06-05 10:24 ` Biju Das
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).