* [PATCH 0/2] Match data improvements for ov7670 driver @ 2023-09-10 15:00 Biju Das 2023-09-10 15:00 ` [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables Biju Das 2023-09-10 15:00 ` [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery Biju Das 0 siblings, 2 replies; 9+ messages in thread From: Biju Das @ 2023-09-10 15:00 UTC (permalink / raw) To: Sakari Ailus, Mauro Carvalho Chehab Cc: Biju Das, linux-media, linux-kernel, Biju Das, Andy Shevchenko This patch series aims to add match data improvements for ov7670 driver. This patch is only compile tested. Biju Das (2): media: i2c: ov7670: Extend match support for OF tables media: i2c: ov7670: Drop CONFIG_OF ifdeffery drivers/media/i2c/ov7670.c | 52 ++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 30 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables 2023-09-10 15:00 [PATCH 0/2] Match data improvements for ov7670 driver Biju Das @ 2023-09-10 15:00 ` Biju Das 2023-09-11 8:08 ` Jacopo Mondi 2023-09-11 8:50 ` Kieran Bingham 2023-09-10 15:00 ` [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery Biju Das 1 sibling, 2 replies; 9+ messages in thread From: Biju Das @ 2023-09-10 15:00 UTC (permalink / raw) To: Sakari Ailus, Mauro Carvalho Chehab Cc: Biju Das, linux-media, linux-kernel, Biju Das, Andy Shevchenko The driver has an OF match table, still, it uses an ID lookup table for retrieving match data. Currently, the driver is working on the assumption that an I2C device registered via OF will always match a legacy I2C device ID. The correct approach is to have an OF device ID table using i2c_get_match_data() if the devices are registered via OF/ID. Unify the OF/ID table by using struct ov7670_devtype as match data for both these tables and replace the ID lookup table for the match data by i2c_get_match_data(). Split the array ov7670_devdata[] as individual variables, and make lines shorter by referring to e.g. &ov7670_devdata instead of &ov7670_devdata[MODEL_OV7670]. Drop enum ov7670_model as there is no user. While at it, remove the trailing comma in the terminator entry for the OF table making code robust against (theoretical) misrebases or other similar things where the new entry goes _after_ the termination without the compiler noticing. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- drivers/media/i2c/ov7670.c | 47 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index 2f55491ef571..644457e6993d 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -186,11 +186,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ #define REG_BD60MAX 0xab /* 60hz banding step limit */ -enum ov7670_model { - MODEL_OV7670 = 0, - MODEL_OV7675, -}; - struct ov7670_win_size { int width; int height; @@ -1774,21 +1769,6 @@ static const struct v4l2_subdev_internal_ops ov7670_subdev_internal_ops = { /* ----------------------------------------------------------------------- */ -static const struct ov7670_devtype ov7670_devdata[] = { - [MODEL_OV7670] = { - .win_sizes = ov7670_win_sizes, - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), - .set_framerate = ov7670_set_framerate_legacy, - .get_framerate = ov7670_get_framerate_legacy, - }, - [MODEL_OV7675] = { - .win_sizes = ov7675_win_sizes, - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), - .set_framerate = ov7675_set_framerate, - .get_framerate = ov7675_get_framerate, - }, -}; - static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info) { info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", @@ -1849,7 +1829,6 @@ static int ov7670_parse_dt(struct device *dev, static int ov7670_probe(struct i2c_client *client) { - const struct i2c_device_id *id = i2c_client_get_device_id(client); struct v4l2_fract tpf; struct v4l2_subdev *sd; struct ov7670_info *info; @@ -1923,7 +1902,7 @@ static int ov7670_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - info->devtype = &ov7670_devdata[id->driver_data]; + info->devtype = i2c_get_match_data(client); info->fmt = &ov7670_formats[0]; info->wsize = &info->devtype->win_sizes[0]; @@ -2013,17 +1992,31 @@ static void ov7670_remove(struct i2c_client *client) media_entity_cleanup(&info->sd.entity); } +static const struct ov7670_devtype ov7670_devdata = { + .win_sizes = ov7670_win_sizes, + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), + .set_framerate = ov7670_set_framerate_legacy, + .get_framerate = ov7670_get_framerate_legacy, +}; + +static const struct ov7670_devtype ov7675_devdata = { + .win_sizes = ov7675_win_sizes, + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), + .set_framerate = ov7675_set_framerate, + .get_framerate = ov7675_get_framerate, +}; + static const struct i2c_device_id ov7670_id[] = { - { "ov7670", MODEL_OV7670 }, - { "ov7675", MODEL_OV7675 }, - { } + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(i2c, ov7670_id); #if IS_ENABLED(CONFIG_OF) static const struct of_device_id ov7670_of_match[] = { - { .compatible = "ovti,ov7670", }, - { /* sentinel */ }, + { .compatible = "ovti,ov7670", &ov7670_devdata }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ov7670_of_match); #endif -- 2.25.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables 2023-09-10 15:00 ` [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables Biju Das @ 2023-09-11 8:08 ` Jacopo Mondi 2023-09-11 8:18 ` Biju Das 2023-09-11 8:50 ` Kieran Bingham 1 sibling, 1 reply; 9+ messages in thread From: Jacopo Mondi @ 2023-09-11 8:08 UTC (permalink / raw) To: Biju Das Cc: Sakari Ailus, Mauro Carvalho Chehab, linux-media, linux-kernel, Biju Das, Andy Shevchenko Hi Biju On Sun, Sep 10, 2023 at 04:00:32PM +0100, Biju Das wrote: > The driver has an OF match table, still, it uses an ID lookup table for > retrieving match data. Currently, the driver is working on the > assumption that an I2C device registered via OF will always match a > legacy I2C device ID. The correct approach is to have an OF device ID > table using i2c_get_match_data() if the devices are registered via OF/ID. > > Unify the OF/ID table by using struct ov7670_devtype as match data for > both these tables and replace the ID lookup table for the match data by > i2c_get_match_data(). > > Split the array ov7670_devdata[] as individual variables, and > make lines shorter by referring to e.g. &ov7670_devdata instead of > &ov7670_devdata[MODEL_OV7670]. > > Drop enum ov7670_model as there is no user. > > While at it, remove the trailing comma in the terminator entry for the OF > table making code robust against (theoretical) misrebases or other similar > things where the new entry goes _after_ the termination without the > compiler noticing. > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > drivers/media/i2c/ov7670.c | 47 ++++++++++++++++---------------------- > 1 file changed, 20 insertions(+), 27 deletions(-) > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > index 2f55491ef571..644457e6993d 100644 > --- a/drivers/media/i2c/ov7670.c > +++ b/drivers/media/i2c/ov7670.c > @@ -186,11 +186,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); > #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ > #define REG_BD60MAX 0xab /* 60hz banding step limit */ > > -enum ov7670_model { > - MODEL_OV7670 = 0, > - MODEL_OV7675, > -}; > - > struct ov7670_win_size { > int width; > int height; > @@ -1774,21 +1769,6 @@ static const struct v4l2_subdev_internal_ops ov7670_subdev_internal_ops = { > > /* ----------------------------------------------------------------------- */ > > -static const struct ov7670_devtype ov7670_devdata[] = { > - [MODEL_OV7670] = { > - .win_sizes = ov7670_win_sizes, > - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > - .set_framerate = ov7670_set_framerate_legacy, > - .get_framerate = ov7670_get_framerate_legacy, > - }, > - [MODEL_OV7675] = { > - .win_sizes = ov7675_win_sizes, > - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > - .set_framerate = ov7675_set_framerate, > - .get_framerate = ov7675_get_framerate, > - }, > -}; > - > static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info) > { > info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", > @@ -1849,7 +1829,6 @@ static int ov7670_parse_dt(struct device *dev, > > static int ov7670_probe(struct i2c_client *client) > { > - const struct i2c_device_id *id = i2c_client_get_device_id(client); > struct v4l2_fract tpf; > struct v4l2_subdev *sd; > struct ov7670_info *info; > @@ -1923,7 +1902,7 @@ static int ov7670_probe(struct i2c_client *client) > v4l_info(client, "chip found @ 0x%02x (%s)\n", > client->addr << 1, client->adapter->name); > > - info->devtype = &ov7670_devdata[id->driver_data]; > + info->devtype = i2c_get_match_data(client); I was about to complain this function is not used, but then I noticed you just introduced it, so this is like the first user! > info->fmt = &ov7670_formats[0]; > info->wsize = &info->devtype->win_sizes[0]; > > @@ -2013,17 +1992,31 @@ static void ov7670_remove(struct i2c_client *client) > media_entity_cleanup(&info->sd.entity); > } > > +static const struct ov7670_devtype ov7670_devdata = { > + .win_sizes = ov7670_win_sizes, > + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > + .set_framerate = ov7670_set_framerate_legacy, > + .get_framerate = ov7670_get_framerate_legacy, > +}; > + > +static const struct ov7670_devtype ov7675_devdata = { > + .win_sizes = ov7675_win_sizes, > + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > + .set_framerate = ov7675_set_framerate, > + .get_framerate = ov7675_get_framerate, > +}; > + > static const struct i2c_device_id ov7670_id[] = { > - { "ov7670", MODEL_OV7670 }, > - { "ov7675", MODEL_OV7675 }, > - { } > + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, > + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, > + { /* sentinel */ } > }; > MODULE_DEVICE_TABLE(i2c, ov7670_id); > > #if IS_ENABLED(CONFIG_OF) > static const struct of_device_id ov7670_of_match[] = { > - { .compatible = "ovti,ov7670", }, > - { /* sentinel */ }, > + { .compatible = "ovti,ov7670", &ov7670_devdata }, > + { /* sentinel */ } The patch looks good to me, would be nice to know if you have been able to run-time test at least one of the drivers you have moved to use i2c_get_match_data(). Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com> > }; > MODULE_DEVICE_TABLE(of, ov7670_of_match); > #endif > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables 2023-09-11 8:08 ` Jacopo Mondi @ 2023-09-11 8:18 ` Biju Das 2023-09-11 8:57 ` Jacopo Mondi 0 siblings, 1 reply; 9+ messages in thread From: Biju Das @ 2023-09-11 8:18 UTC (permalink / raw) To: Jacopo Mondi Cc: Sakari Ailus, Mauro Carvalho Chehab, linux-media, linux-kernel, Biju Das, Andy Shevchenko Hi Jacopo Mondi, Thanks for the feedback. > Subject: Re: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF > tables > > Hi Biju > > On Sun, Sep 10, 2023 at 04:00:32PM +0100, Biju Das wrote: > > The driver has an OF match table, still, it uses an ID lookup table > > for retrieving match data. Currently, the driver is working on the > > assumption that an I2C device registered via OF will always match a > > legacy I2C device ID. The correct approach is to have an OF device ID > > table using i2c_get_match_data() if the devices are registered via OF/ID. > > > > Unify the OF/ID table by using struct ov7670_devtype as match data for > > both these tables and replace the ID lookup table for the match data > > by i2c_get_match_data(). > > > > Split the array ov7670_devdata[] as individual variables, and make > > lines shorter by referring to e.g. &ov7670_devdata instead of > > &ov7670_devdata[MODEL_OV7670]. > > > > Drop enum ov7670_model as there is no user. > > > > While at it, remove the trailing comma in the terminator entry for the > > OF table making code robust against (theoretical) misrebases or other > > similar things where the new entry goes _after_ the termination > > without the compiler noticing. > > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > --- > > drivers/media/i2c/ov7670.c | 47 > > ++++++++++++++++---------------------- > > 1 file changed, 20 insertions(+), 27 deletions(-) > > > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > > index 2f55491ef571..644457e6993d 100644 > > --- a/drivers/media/i2c/ov7670.c > > +++ b/drivers/media/i2c/ov7670.c > > @@ -186,11 +186,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); > > #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ > > #define REG_BD60MAX 0xab /* 60hz banding step limit */ > > > > -enum ov7670_model { > > - MODEL_OV7670 = 0, > > - MODEL_OV7675, > > -}; > > - > > struct ov7670_win_size { > > int width; > > int height; > > @@ -1774,21 +1769,6 @@ static const struct v4l2_subdev_internal_ops > > ov7670_subdev_internal_ops = { > > > > /* > > ---------------------------------------------------------------------- > > - */ > > > > -static const struct ov7670_devtype ov7670_devdata[] = { > > - [MODEL_OV7670] = { > > - .win_sizes = ov7670_win_sizes, > > - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > > - .set_framerate = ov7670_set_framerate_legacy, > > - .get_framerate = ov7670_get_framerate_legacy, > > - }, > > - [MODEL_OV7675] = { > > - .win_sizes = ov7675_win_sizes, > > - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > > - .set_framerate = ov7675_set_framerate, > > - .get_framerate = ov7675_get_framerate, > > - }, > > -}; > > - > > static int ov7670_init_gpio(struct i2c_client *client, struct > > ov7670_info *info) { > > info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", > > @@ -1849,7 +1829,6 @@ static int ov7670_parse_dt(struct device *dev, > > > > static int ov7670_probe(struct i2c_client *client) { > > - const struct i2c_device_id *id = i2c_client_get_device_id(client); > > struct v4l2_fract tpf; > > struct v4l2_subdev *sd; > > struct ov7670_info *info; > > @@ -1923,7 +1902,7 @@ static int ov7670_probe(struct i2c_client *client) > > v4l_info(client, "chip found @ 0x%02x (%s)\n", > > client->addr << 1, client->adapter->name); > > > > - info->devtype = &ov7670_devdata[id->driver_data]; > > + info->devtype = i2c_get_match_data(client); > > I was about to complain this function is not used, but then I noticed you > just introduced it, so this is like the first user! This driver is not the first user. Now plenty of users are there in Linux-next, 6.6-rc1 and [1] https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=testing&qt=grep&q=biju.das > > > > info->fmt = &ov7670_formats[0]; > > info->wsize = &info->devtype->win_sizes[0]; > > > > @@ -2013,17 +1992,31 @@ static void ov7670_remove(struct i2c_client > *client) > > media_entity_cleanup(&info->sd.entity); > > } > > > > +static const struct ov7670_devtype ov7670_devdata = { > > + .win_sizes = ov7670_win_sizes, > > + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > > + .set_framerate = ov7670_set_framerate_legacy, > > + .get_framerate = ov7670_get_framerate_legacy, }; > > + > > +static const struct ov7670_devtype ov7675_devdata = { > > + .win_sizes = ov7675_win_sizes, > > + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > > + .set_framerate = ov7675_set_framerate, > > + .get_framerate = ov7675_get_framerate, }; > > + > > static const struct i2c_device_id ov7670_id[] = { > > - { "ov7670", MODEL_OV7670 }, > > - { "ov7675", MODEL_OV7675 }, > > - { } > > + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, > > + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, > > + { /* sentinel */ } > > }; > > MODULE_DEVICE_TABLE(i2c, ov7670_id); > > > > #if IS_ENABLED(CONFIG_OF) > > static const struct of_device_id ov7670_of_match[] = { > > - { .compatible = "ovti,ov7670", }, > > - { /* sentinel */ }, > > + { .compatible = "ovti,ov7670", &ov7670_devdata }, > > + { /* sentinel */ } > > The patch looks good to me, would be nice to know if you have been able to > run-time test at least one of the drivers you have moved to use > i2c_get_match_data(). I already done similar testing on [1], [2] and [3] [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.6-rc1&id=b7f73b6e921b457a222e86cf53fe3950c6b5aed5 [2] https://lore.kernel.org/all/20230830142358.275459-1-biju.das.jz@bp.renesas.com/ [3] https://lore.kernel.org/all/OS0PR01MB5922F55D18824F155228259086E7A@OS0PR01MB5922.jpnprd01.prod.outlook.com/ Cheers, Biju > > Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com> > > > }; > > MODULE_DEVICE_TABLE(of, ov7670_of_match); #endif > > -- > > 2.25.1 > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables 2023-09-11 8:18 ` Biju Das @ 2023-09-11 8:57 ` Jacopo Mondi 0 siblings, 0 replies; 9+ messages in thread From: Jacopo Mondi @ 2023-09-11 8:57 UTC (permalink / raw) To: Biju Das Cc: Jacopo Mondi, Sakari Ailus, Mauro Carvalho Chehab, linux-media, linux-kernel, Biju Das, Andy Shevchenko Hi Biju On Mon, Sep 11, 2023 at 08:18:37AM +0000, Biju Das wrote: > Hi Jacopo Mondi, > > Thanks for the feedback. > > > Subject: Re: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF > > tables > > > > Hi Biju > > > > On Sun, Sep 10, 2023 at 04:00:32PM +0100, Biju Das wrote: > > > The driver has an OF match table, still, it uses an ID lookup table > > > for retrieving match data. Currently, the driver is working on the > > > assumption that an I2C device registered via OF will always match a > > > legacy I2C device ID. The correct approach is to have an OF device ID > > > table using i2c_get_match_data() if the devices are registered via OF/ID. > > > > > > Unify the OF/ID table by using struct ov7670_devtype as match data for > > > both these tables and replace the ID lookup table for the match data > > > by i2c_get_match_data(). > > > > > > Split the array ov7670_devdata[] as individual variables, and make > > > lines shorter by referring to e.g. &ov7670_devdata instead of > > > &ov7670_devdata[MODEL_OV7670]. > > > > > > Drop enum ov7670_model as there is no user. > > > > > > While at it, remove the trailing comma in the terminator entry for the > > > OF table making code robust against (theoretical) misrebases or other > > > similar things where the new entry goes _after_ the termination > > > without the compiler noticing. > > > > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > > --- > > > drivers/media/i2c/ov7670.c | 47 > > > ++++++++++++++++---------------------- > > > 1 file changed, 20 insertions(+), 27 deletions(-) > > > > > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > > > index 2f55491ef571..644457e6993d 100644 > > > --- a/drivers/media/i2c/ov7670.c > > > +++ b/drivers/media/i2c/ov7670.c > > > @@ -186,11 +186,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); > > > #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ > > > #define REG_BD60MAX 0xab /* 60hz banding step limit */ > > > > > > -enum ov7670_model { > > > - MODEL_OV7670 = 0, > > > - MODEL_OV7675, > > > -}; > > > - > > > struct ov7670_win_size { > > > int width; > > > int height; > > > @@ -1774,21 +1769,6 @@ static const struct v4l2_subdev_internal_ops > > > ov7670_subdev_internal_ops = { > > > > > > /* > > > ---------------------------------------------------------------------- > > > - */ > > > > > > -static const struct ov7670_devtype ov7670_devdata[] = { > > > - [MODEL_OV7670] = { > > > - .win_sizes = ov7670_win_sizes, > > > - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > > > - .set_framerate = ov7670_set_framerate_legacy, > > > - .get_framerate = ov7670_get_framerate_legacy, > > > - }, > > > - [MODEL_OV7675] = { > > > - .win_sizes = ov7675_win_sizes, > > > - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > > > - .set_framerate = ov7675_set_framerate, > > > - .get_framerate = ov7675_get_framerate, > > > - }, > > > -}; > > > - > > > static int ov7670_init_gpio(struct i2c_client *client, struct > > > ov7670_info *info) { > > > info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", > > > @@ -1849,7 +1829,6 @@ static int ov7670_parse_dt(struct device *dev, > > > > > > static int ov7670_probe(struct i2c_client *client) { > > > - const struct i2c_device_id *id = i2c_client_get_device_id(client); > > > struct v4l2_fract tpf; > > > struct v4l2_subdev *sd; > > > struct ov7670_info *info; > > > @@ -1923,7 +1902,7 @@ static int ov7670_probe(struct i2c_client *client) > > > v4l_info(client, "chip found @ 0x%02x (%s)\n", > > > client->addr << 1, client->adapter->name); > > > > > > - info->devtype = &ov7670_devdata[id->driver_data]; > > > + info->devtype = i2c_get_match_data(client); > > > > I was about to complain this function is not used, but then I noticed you > > just introduced it, so this is like the first user! > > This driver is not the first user. Now plenty of users are there in Linux-next, 6.6-rc1 and [1] > > https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=testing&qt=grep&q=biju.das > Ah sorry, I was on media/master > > > > > > > info->fmt = &ov7670_formats[0]; > > > info->wsize = &info->devtype->win_sizes[0]; > > > > > > @@ -2013,17 +1992,31 @@ static void ov7670_remove(struct i2c_client > > *client) > > > media_entity_cleanup(&info->sd.entity); > > > } > > > > > > +static const struct ov7670_devtype ov7670_devdata = { > > > + .win_sizes = ov7670_win_sizes, > > > + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > > > + .set_framerate = ov7670_set_framerate_legacy, > > > + .get_framerate = ov7670_get_framerate_legacy, }; > > > + > > > +static const struct ov7670_devtype ov7675_devdata = { > > > + .win_sizes = ov7675_win_sizes, > > > + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > > > + .set_framerate = ov7675_set_framerate, > > > + .get_framerate = ov7675_get_framerate, }; > > > + > > > static const struct i2c_device_id ov7670_id[] = { > > > - { "ov7670", MODEL_OV7670 }, > > > - { "ov7675", MODEL_OV7675 }, > > > - { } > > > + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, > > > + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, > > > + { /* sentinel */ } > > > }; > > > MODULE_DEVICE_TABLE(i2c, ov7670_id); > > > > > > #if IS_ENABLED(CONFIG_OF) > > > static const struct of_device_id ov7670_of_match[] = { > > > - { .compatible = "ovti,ov7670", }, > > > - { /* sentinel */ }, > > > + { .compatible = "ovti,ov7670", &ov7670_devdata }, > > > + { /* sentinel */ } > > > > The patch looks good to me, would be nice to know if you have been able to > > run-time test at least one of the drivers you have moved to use > > i2c_get_match_data(). > > I already done similar testing on [1], [2] and [3] > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.6-rc1&id=b7f73b6e921b457a222e86cf53fe3950c6b5aed5 > > [2] https://lore.kernel.org/all/20230830142358.275459-1-biju.das.jz@bp.renesas.com/ > > [3] https://lore.kernel.org/all/OS0PR01MB5922F55D18824F155228259086E7A@OS0PR01MB5922.jpnprd01.prod.outlook.com/ Ok, thanks a lot for confirming, it will make it easier to review the other series with confidence! Thanks j > > Cheers, > Biju > > > > > Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com> > > > > > }; > > > MODULE_DEVICE_TABLE(of, ov7670_of_match); #endif > > > -- > > > 2.25.1 > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables 2023-09-10 15:00 ` [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables Biju Das 2023-09-11 8:08 ` Jacopo Mondi @ 2023-09-11 8:50 ` Kieran Bingham 1 sibling, 0 replies; 9+ messages in thread From: Kieran Bingham @ 2023-09-11 8:50 UTC (permalink / raw) To: Biju Das, Mauro Carvalho Chehab, Sakari Ailus Cc: Biju Das, linux-media, linux-kernel, Biju Das, Andy Shevchenko Quoting Biju Das (2023-09-10 16:00:32) > The driver has an OF match table, still, it uses an ID lookup table for > retrieving match data. Currently, the driver is working on the > assumption that an I2C device registered via OF will always match a > legacy I2C device ID. The correct approach is to have an OF device ID > table using i2c_get_match_data() if the devices are registered via OF/ID. > > Unify the OF/ID table by using struct ov7670_devtype as match data for > both these tables and replace the ID lookup table for the match data by > i2c_get_match_data(). > > Split the array ov7670_devdata[] as individual variables, and > make lines shorter by referring to e.g. &ov7670_devdata instead of > &ov7670_devdata[MODEL_OV7670]. > > Drop enum ov7670_model as there is no user. > > While at it, remove the trailing comma in the terminator entry for the OF > table making code robust against (theoretical) misrebases or other similar > things where the new entry goes _after_ the termination without the > compiler noticing. > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > drivers/media/i2c/ov7670.c | 47 ++++++++++++++++---------------------- > 1 file changed, 20 insertions(+), 27 deletions(-) > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > index 2f55491ef571..644457e6993d 100644 > --- a/drivers/media/i2c/ov7670.c > +++ b/drivers/media/i2c/ov7670.c > @@ -186,11 +186,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); > #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ > #define REG_BD60MAX 0xab /* 60hz banding step limit */ > > -enum ov7670_model { > - MODEL_OV7670 = 0, > - MODEL_OV7675, > -}; > - > struct ov7670_win_size { > int width; > int height; > @@ -1774,21 +1769,6 @@ static const struct v4l2_subdev_internal_ops ov7670_subdev_internal_ops = { > > /* ----------------------------------------------------------------------- */ > > -static const struct ov7670_devtype ov7670_devdata[] = { > - [MODEL_OV7670] = { > - .win_sizes = ov7670_win_sizes, > - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > - .set_framerate = ov7670_set_framerate_legacy, > - .get_framerate = ov7670_get_framerate_legacy, > - }, > - [MODEL_OV7675] = { > - .win_sizes = ov7675_win_sizes, > - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > - .set_framerate = ov7675_set_framerate, > - .get_framerate = ov7675_get_framerate, > - }, > -}; > - > static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info) > { > info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", > @@ -1849,7 +1829,6 @@ static int ov7670_parse_dt(struct device *dev, > > static int ov7670_probe(struct i2c_client *client) > { > - const struct i2c_device_id *id = i2c_client_get_device_id(client); > struct v4l2_fract tpf; > struct v4l2_subdev *sd; > struct ov7670_info *info; > @@ -1923,7 +1902,7 @@ static int ov7670_probe(struct i2c_client *client) > v4l_info(client, "chip found @ 0x%02x (%s)\n", > client->addr << 1, client->adapter->name); > > - info->devtype = &ov7670_devdata[id->driver_data]; > + info->devtype = i2c_get_match_data(client); > info->fmt = &ov7670_formats[0]; > info->wsize = &info->devtype->win_sizes[0]; > > @@ -2013,17 +1992,31 @@ static void ov7670_remove(struct i2c_client *client) > media_entity_cleanup(&info->sd.entity); > } > > +static const struct ov7670_devtype ov7670_devdata = { > + .win_sizes = ov7670_win_sizes, > + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), > + .set_framerate = ov7670_set_framerate_legacy, > + .get_framerate = ov7670_get_framerate_legacy, > +}; > + > +static const struct ov7670_devtype ov7675_devdata = { > + .win_sizes = ov7675_win_sizes, > + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), > + .set_framerate = ov7675_set_framerate, > + .get_framerate = ov7675_get_framerate, > +}; > + > static const struct i2c_device_id ov7670_id[] = { > - { "ov7670", MODEL_OV7670 }, > - { "ov7675", MODEL_OV7675 }, > - { } > + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, > + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, > + { /* sentinel */ } > }; > MODULE_DEVICE_TABLE(i2c, ov7670_id); > > #if IS_ENABLED(CONFIG_OF) > static const struct of_device_id ov7670_of_match[] = { > - { .compatible = "ovti,ov7670", }, > - { /* sentinel */ }, > + { .compatible = "ovti,ov7670", &ov7670_devdata }, > + { /* sentinel */ } This all looks good to me - by why is there no ov7675 compatible string? Should that be added? (as a separate patch?) Can the model be detected at runtime (Is there a version register on this chip?) But otherwise looks fine. Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> > }; > MODULE_DEVICE_TABLE(of, ov7670_of_match); > #endif > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery 2023-09-10 15:00 [PATCH 0/2] Match data improvements for ov7670 driver Biju Das 2023-09-10 15:00 ` [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables Biju Das @ 2023-09-10 15:00 ` Biju Das 2023-09-11 8:13 ` Jacopo Mondi 1 sibling, 1 reply; 9+ messages in thread From: Biju Das @ 2023-09-10 15:00 UTC (permalink / raw) To: Sakari Ailus, Mauro Carvalho Chehab Cc: Biju Das, linux-media, linux-kernel, Biju Das, Andy Shevchenko Drop of_match_ptr() from ov7670_driver and get rid of ugly CONFIG_OF if check. This slightly increases the size of ov7670_driver on non-OF system and shouldn't be an issue. Add mod_devicetable.h include. It also allows, in case if needed, to enumerate this device via ACPI with PRP0001 magic. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- drivers/media/i2c/ov7670.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index 644457e6993d..41032394a464 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -10,6 +10,7 @@ */ #include <linux/clk.h> #include <linux/init.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/i2c.h> @@ -2013,18 +2014,16 @@ static const struct i2c_device_id ov7670_id[] = { }; MODULE_DEVICE_TABLE(i2c, ov7670_id); -#if IS_ENABLED(CONFIG_OF) static const struct of_device_id ov7670_of_match[] = { { .compatible = "ovti,ov7670", &ov7670_devdata }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ov7670_of_match); -#endif static struct i2c_driver ov7670_driver = { .driver = { .name = "ov7670", - .of_match_table = of_match_ptr(ov7670_of_match), + .of_match_table = ov7670_of_match, }, .probe = ov7670_probe, .remove = ov7670_remove, -- 2.25.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery 2023-09-10 15:00 ` [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery Biju Das @ 2023-09-11 8:13 ` Jacopo Mondi 2023-09-11 8:21 ` Biju Das 0 siblings, 1 reply; 9+ messages in thread From: Jacopo Mondi @ 2023-09-11 8:13 UTC (permalink / raw) To: Biju Das Cc: Sakari Ailus, Mauro Carvalho Chehab, linux-media, linux-kernel, Biju Das, Andy Shevchenko Hi Biju On Sun, Sep 10, 2023 at 04:00:33PM +0100, Biju Das wrote: > Drop of_match_ptr() from ov7670_driver and get rid of ugly CONFIG_OF > if check. This slightly increases the size of ov7670_driver on non-OF > system and shouldn't be an issue. > > Add mod_devicetable.h include. > > It also allows, in case if needed, to enumerate this device via ACPI with > PRP0001 magic. > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > drivers/media/i2c/ov7670.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > index 644457e6993d..41032394a464 100644 > --- a/drivers/media/i2c/ov7670.c > +++ b/drivers/media/i2c/ov7670.c > @@ -10,6 +10,7 @@ > */ > #include <linux/clk.h> > #include <linux/init.h> > +#include <linux/mod_devicetable.h> > #include <linux/module.h> > #include <linux/slab.h> > #include <linux/i2c.h> > @@ -2013,18 +2014,16 @@ static const struct i2c_device_id ov7670_id[] = { > }; > MODULE_DEVICE_TABLE(i2c, ov7670_id); > > -#if IS_ENABLED(CONFIG_OF) > static const struct of_device_id ov7670_of_match[] = { > { .compatible = "ovti,ov7670", &ov7670_devdata }, > { /* sentinel */ } > }; > MODULE_DEVICE_TABLE(of, ov7670_of_match); > -#endif > > static struct i2c_driver ov7670_driver = { > .driver = { > .name = "ov7670", > - .of_match_table = of_match_ptr(ov7670_of_match), > + .of_match_table = ov7670_of_match, While at it, but possibily separate from this patch, all the #if defined(CONFIG_MEDIA_CONTROLLER) entries could be removed as well, as since commit 7d3c7d2a2914 ("media: i2c: Add a camera sensor top level menu") the MEDIA_CONTROLLER symbol is selected by the top-level menu. Let me know if you intended to send a patch or should I. For this one: Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com> Thanks j > }, > .probe = ov7670_probe, > .remove = ov7670_remove, > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery 2023-09-11 8:13 ` Jacopo Mondi @ 2023-09-11 8:21 ` Biju Das 0 siblings, 0 replies; 9+ messages in thread From: Biju Das @ 2023-09-11 8:21 UTC (permalink / raw) To: Jacopo Mondi Cc: Sakari Ailus, Mauro Carvalho Chehab, linux-media, linux-kernel, Biju Das, Andy Shevchenko Hi Jacopo Mondi, Thanks for the feedback. > Subject: Re: [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery > > Hi Biju > > On Sun, Sep 10, 2023 at 04:00:33PM +0100, Biju Das wrote: > > Drop of_match_ptr() from ov7670_driver and get rid of ugly CONFIG_OF > > if check. This slightly increases the size of ov7670_driver on non-OF > > system and shouldn't be an issue. > > > > Add mod_devicetable.h include. > > > > It also allows, in case if needed, to enumerate this device via ACPI > > with > > PRP0001 magic. > > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > --- > > drivers/media/i2c/ov7670.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > > index 644457e6993d..41032394a464 100644 > > --- a/drivers/media/i2c/ov7670.c > > +++ b/drivers/media/i2c/ov7670.c > > @@ -10,6 +10,7 @@ > > */ > > #include <linux/clk.h> > > #include <linux/init.h> > > +#include <linux/mod_devicetable.h> > > #include <linux/module.h> > > #include <linux/slab.h> > > #include <linux/i2c.h> > > @@ -2013,18 +2014,16 @@ static const struct i2c_device_id ov7670_id[] > > = { }; MODULE_DEVICE_TABLE(i2c, ov7670_id); > > > > -#if IS_ENABLED(CONFIG_OF) > > static const struct of_device_id ov7670_of_match[] = { > > { .compatible = "ovti,ov7670", &ov7670_devdata }, > > { /* sentinel */ } > > }; > > MODULE_DEVICE_TABLE(of, ov7670_of_match); -#endif > > > > static struct i2c_driver ov7670_driver = { > > .driver = { > > .name = "ov7670", > > - .of_match_table = of_match_ptr(ov7670_of_match), > > + .of_match_table = ov7670_of_match, > > While at it, but possibily separate from this patch, all the > > #if defined(CONFIG_MEDIA_CONTROLLER) > > entries could be removed as well, as since commit 7d3c7d2a2914 > ("media: i2c: Add a camera sensor top level menu") the MEDIA_CONTROLLER > symbol is selected by the top-level menu. > > Let me know if you intended to send a patch or should I. Please feel free to send a patch to fix CONFIG_MEDIA_CONTROLLER ifdeffery. Cheers, Biju > > For this one: > Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com> > > Thanks > j > > > > > }, > > .probe = ov7670_probe, > > .remove = ov7670_remove, > > -- > > 2.25.1 > > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-09-11 21:17 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-09-10 15:00 [PATCH 0/2] Match data improvements for ov7670 driver Biju Das 2023-09-10 15:00 ` [PATCH 1/2] media: i2c: ov7670: Extend match support for OF tables Biju Das 2023-09-11 8:08 ` Jacopo Mondi 2023-09-11 8:18 ` Biju Das 2023-09-11 8:57 ` Jacopo Mondi 2023-09-11 8:50 ` Kieran Bingham 2023-09-10 15:00 ` [PATCH 2/2] media: i2c: ov7670: Drop CONFIG_OF ifdeffery Biju Das 2023-09-11 8:13 ` Jacopo Mondi 2023-09-11 8:21 ` Biju Das
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®