Hi Wolfram/Geert, Do we need to enhance the logic to use device_get_match_data to support OF/ACPI/I2C match like below [1]. Or Are we happy with the current one? + Mark, Linux-clk If I am correct, the new enhancement[1] will add I2C match support [2] drivers. Currently this driver support only OF/ACPI match-data even though driver has I2C matching table. [2] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-renesas-pcie.c#L282 The current patch will be useful for these drivers as well for I2C match support as these drivers have I2C matching table. [3] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-versaclock5.c#L956 [4] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-versaclock7.c#L1111 [1] +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 *data; + + data = device_get_match_data(&client->dev); + if (!data) { + match = i2c_match_id(driver->id_table, client); + if (!match) + return NULL; + + data = (const void *)match->driver_data; + } + > + return data; > +} > +EXPORT_SYMBOL(i2c_get_match_data); Cheers, Biju > -----Original Message----- > From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx> > Sent: Tuesday, June 6, 2023 2:05 PM > To: Wolfram Sang <wsa@xxxxxxxxxx>; Alessandro Zummo > <a.zummo@xxxxxxxxxxxx>; Alexandre Belloni > <alexandre.belloni@xxxxxxxxxxx> > Cc: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>; linux-i2c@xxxxxxxxxxxxxxx; > linux-rtc@xxxxxxxxxxxxxxx; Geert Uytterhoeven <geert+renesas@xxxxxxxxx>; > Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>; linux- > renesas-soc@xxxxxxxxxxxxxxx > Subject: [PATCH v3] i2c: Add i2c_get_match_data() > > Add i2c_get_match_data() to get match data for both I2C and DT-based > matching, so that we can optimize the driver code that uses both. > > Suggested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx> > Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx> > Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx> > --- > v2->v3: > * Added support for getting match data for both I2C and DT-based > matching. > * Added Rb tag from Geert and retained the Rb tag as change is trivial. > 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) { > - 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]; > - } > + config = i2c_get_match_data(client); > + if (!config) > + return -ENODEV; > --- > drivers/i2c/i2c-core-base.c | 21 +++++++++++++++++++++ > include/linux/i2c.h | 2 ++ > 2 files changed, 23 insertions(+) > > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > index ae3af738b03f..15a49f4ba668 100644 > --- a/drivers/i2c/i2c-core-base.c > +++ b/drivers/i2c/i2c-core-base.c > @@ -114,6 +114,27 @@ 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; > + const void *data; > + > + if (client->dev.of_node) { > + data = of_device_get_match_data(&client->dev); > + } else { > + match = i2c_match_id(driver->id_table, client); > + if (!match) > + return NULL; > + > + data = (const void *)match->driver_data; > + } > + > + return 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