2023-09-23 16:38:23

by Biju Das

[permalink] [raw]
Subject: [PATCH v2 0/3] Match data improvements for tvp541x driver

This patch series aims to add match data improvements for tvp541x driver.

This patch series is only compile tested.

v1->v2:
* Added Rb tag from Jacopo for patch#1 and patch#2.
* Adeed patch#3 for sorting header files.

Biju Das (3):
media: tvp541x: Extend match support for OF tables
media: tvp541x: Drop CONFIG_OF ifdeffery
media: tvp541x: Sort header files

drivers/media/i2c/tvp514x.c | 49 +++++++++++++++++--------------------
1 file changed, 23 insertions(+), 26 deletions(-)

--
2.25.1


2023-09-23 16:38:24

by Biju Das

[permalink] [raw]
Subject: [PATCH v2 1/3] media: tvp541x: Extend match support for OF tables

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 tvp514x_reg as match data for both
these tables and replace the ID lookup table for the match data by
i2c_get_match_data() and simplifly probe().

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 <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
v1->v2:
* Added Rb tag from Jacopo.
---
drivers/media/i2c/tvp514x.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index aa6d4b67b6d5..4d0ffaa312c5 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -118,7 +118,7 @@ struct tvp514x_decoder {
struct media_pad pad;
struct v4l2_mbus_framefmt format;

- struct tvp514x_reg *int_seq;
+ const struct tvp514x_reg *int_seq;
};

/* TVP514x default register values */
@@ -1024,7 +1024,6 @@ tvp514x_get_pdata(struct i2c_client *client)
static int
tvp514x_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
struct tvp514x_platform_data *pdata = tvp514x_get_pdata(client);
struct tvp514x_decoder *decoder;
struct v4l2_subdev *sd;
@@ -1049,7 +1048,7 @@ tvp514x_probe(struct i2c_client *client)
memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
sizeof(tvp514x_reg_list_default));

- decoder->int_seq = (struct tvp514x_reg *)id->driver_data;
+ decoder->int_seq = i2c_get_match_data(client);

/* Copy board specific information here */
decoder->pdata = pdata;
@@ -1183,22 +1182,21 @@ static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
* driver_data - Driver data
*/
static const struct i2c_device_id tvp514x_id[] = {
- {"tvp5146", (unsigned long)tvp5146_init_reg_seq},
- {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq},
- {"tvp5147", (unsigned long)tvp5147_init_reg_seq},
- {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq},
- {},
+ {"tvp5146", (kernel_ulong_t)tvp5146_init_reg_seq },
+ {"tvp5146m2", (kernel_ulong_t)tvp514xm_init_reg_seq },
+ {"tvp5147", (kernel_ulong_t)tvp5147_init_reg_seq },
+ {"tvp5147m1", (kernel_ulong_t)tvp514xm_init_reg_seq },
+ { /* sentinel */ }
};
-
MODULE_DEVICE_TABLE(i2c, tvp514x_id);

#if IS_ENABLED(CONFIG_OF)
static const struct of_device_id tvp514x_of_match[] = {
- { .compatible = "ti,tvp5146", },
- { .compatible = "ti,tvp5146m2", },
- { .compatible = "ti,tvp5147", },
- { .compatible = "ti,tvp5147m1", },
- { /* sentinel */ },
+ { .compatible = "ti,tvp5146", .data = tvp5146_init_reg_seq },
+ { .compatible = "ti,tvp5146m2", .data = tvp514xm_init_reg_seq },
+ { .compatible = "ti,tvp5147", .data = tvp5147_init_reg_seq },
+ { .compatible = "ti,tvp5147m1", .data = tvp514xm_init_reg_seq },
+ { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, tvp514x_of_match);
#endif
--
2.25.1

2023-09-23 16:39:17

by Biju Das

[permalink] [raw]
Subject: [PATCH v2 3/3] media: tvp541x: Sort header files

Sort header files alphabetically.

Suggested-by: Jacopo Mondi <[email protected]>
Signed-off-by: Biju Das <[email protected]>
---
v2:
* New patch.
---
drivers/media/i2c/tvp514x.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 569a9437ec86..c37f605cb75f 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -16,24 +16,24 @@
* Prabhakar Lad <[email protected]>
*/

-#include <linux/i2c.h>
-#include <linux/slab.h>
#include <linux/delay.h>
-#include <linux/videodev2.h>
+#include <linux/i2c.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/v4l2-mediabus.h>
#include <linux/of.h>
#include <linux/of_graph.h>
+#include <linux/slab.h>
+#include <linux/v4l2-mediabus.h>
+#include <linux/videodev2.h>

+#include <media/i2c/tvp514x.h>
+#include <media/media-entity.h>
#include <media/v4l2-async.h>
-#include <media/v4l2-device.h>
#include <media/v4l2-common.h>
-#include <media/v4l2-mediabus.h>
-#include <media/v4l2-fwnode.h>
#include <media/v4l2-ctrls.h>
-#include <media/i2c/tvp514x.h>
-#include <media/media-entity.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-mediabus.h>

#include "tvp514x_regs.h"

--
2.25.1

2023-09-23 16:39:19

by Biju Das

[permalink] [raw]
Subject: [PATCH v2 2/3] media: tvp541x: Drop CONFIG_OF ifdeffery

Drop of_match_ptr() from tvp514x_driver and get rid of ugly CONFIG_OF
if check. This slightly increases the size of tvp514x_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 <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
v1->v2:
* Added Rb tag from Jacopo.
---
drivers/media/i2c/tvp514x.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 4d0ffaa312c5..569a9437ec86 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/videodev2.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/v4l2-mediabus.h>
#include <linux/of.h>
@@ -1190,7 +1191,6 @@ static const struct i2c_device_id tvp514x_id[] = {
};
MODULE_DEVICE_TABLE(i2c, tvp514x_id);

-#if IS_ENABLED(CONFIG_OF)
static const struct of_device_id tvp514x_of_match[] = {
{ .compatible = "ti,tvp5146", .data = tvp5146_init_reg_seq },
{ .compatible = "ti,tvp5146m2", .data = tvp514xm_init_reg_seq },
@@ -1199,11 +1199,10 @@ static const struct of_device_id tvp514x_of_match[] = {
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, tvp514x_of_match);
-#endif

static struct i2c_driver tvp514x_driver = {
.driver = {
- .of_match_table = of_match_ptr(tvp514x_of_match),
+ .of_match_table = tvp514x_of_match,
.name = TVP514X_MODULE_NAME,
},
.probe = tvp514x_probe,
--
2.25.1