Skip to contentSkip to conversation

media: i2c: tvp7002: enable TVP7002 decoder for media controller based usage

PATCH Superseded Prabhakar Lad 2 participants 3 messages May 2, 2013 Media (V4L/DVB)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: i2c: tvp7002: enable TVP7002 decoder for media controller based usage

From: Lad, Prabhakar <[email protected]>

This patch enables tvp7002 decoder driver for media controller based usage by adding v4l2_subdev_pad_ops operations support for enum_mbus_code, set_pad_format, get_pad_format and media_entity_init() on probe and media_entity_cleanup() on remove.

---
Changes for v2:
1: Fixed review comment pointed by Laurent, Don’t return error for set_fmt
but fix the input parameters according to current timings.

 drivers/media/i2c/tvp7002.c |  122 +++++++++++++++++++++++++++++++++++++++++--
 include/media/tvp7002.h     |    2 +
 2 files changed, 119 insertions(+), 5 deletions(-)
drivers/media/i2c/tvp7002.c +117 -5
index 027809c..3be687e 100644
@@ -424,6 +424,8 @@ struct tvp7002 {
 	int streaming;
 
 	const struct tvp7002_timings_definition *current_timings;
+	struct media_pad pad;
+	struct v4l2_mbus_framefmt format;
 };
 
 /*
@@ -880,6 +882,90 @@ static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = {
 	.s_ctrl = tvp7002_s_ctrl,
 };
 
+/*
+ * tvp7002_enum_mbus_code() - Enum supported digital video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @code: pointer to subdev enum mbus code struct
+ *
+ * Enumerate supported digital video formats for pad.
+ */
+static int
+tvp7002_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+		       struct v4l2_subdev_mbus_code_enum *code)
+{
+	/* Check requested format index is within range */
+	if (code->index != 0)
+		return -EINVAL;
+
+	code->code = V4L2_MBUS_FMT_YUYV10_1X20;
+
+	return 0;
+}
+
+/*
+ * tvp7002_set_pad_format() - set video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @fmt: pointer to subdev format struct
+ *
+ * set video format for pad.
+ */
+static int
+tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+		       struct v4l2_subdev_format *fmt)
+{
+	struct tvp7002 *tvp7002 = to_tvp7002(sd);
+
+	/* if format doesn’t match the current timings fix the input
+	 * parameters according to what device supports.
+	 */
+	if (fmt->format.field != tvp7002->current_timings->scanmode ||
+	    fmt->format.code != V4L2_MBUS_FMT_YUYV10_1X20 ||
+	    fmt->format.colorspace != tvp7002->current_timings->color_space ||
+	    fmt->format.width != tvp7002->current_timings->timings.bt.width ||
+	    fmt->format.height != tvp7002->current_timings->timings.bt.height) {
+		fmt->format.field = tvp7002->current_timings->scanmode;
+		fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
+		fmt->format.colorspace = tvp7002->current_timings->color_space;
+		fmt->format.width = tvp7002->current_timings->timings.bt.width;
+		fmt->format.height =
+				tvp7002->current_timings->timings.bt.height;
+	}
+
+	tvp7002->format = fmt->format;
+
+	return 0;
+}
+
+/*
+ * tvp7002_get_pad_format() - get video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @fmt: pointer to subdev format struct
+ *
+ * get video format for pad.
+ */
+static int
+tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+		       struct v4l2_subdev_format *fmt)
+{
+	struct tvp7002 *tvp7002 = to_tvp7002(sd);
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		fmt->format = tvp7002->format;
+		return 0;
+	}
+
+	fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
+	fmt->format.width = tvp7002->current_timings->timings.bt.width;
+	fmt->format.height = tvp7002->current_timings->timings.bt.height;
+	fmt->format.field = tvp7002->current_timings->scanmode;
+	fmt->format.colorspace = tvp7002->current_timings->color_space;
+
+	return 0;
+}
+
 /* V4L2 core operation handlers */
 static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
 	.g_chip_ident = tvp7002_g_chip_ident,
@@ -910,10 +996,18 @@ static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
 	.enum_mbus_fmt = tvp7002_enum_mbus_fmt,
 };
 
+/* media pad related operation handlers */
+static const struct v4l2_subdev_pad_ops tvp7002_pad_ops = {
+	.enum_mbus_code = tvp7002_enum_mbus_code,
+	.get_fmt = tvp7002_get_pad_format,
+	.set_fmt = tvp7002_set_pad_format,
+};
+
 /* V4L2 top level operation handlers */
 static const struct v4l2_subdev_ops tvp7002_ops = {
 	.core = &tvp7002_core_ops,
 	.video = &tvp7002_video_ops,
+	.pad = &tvp7002_pad_ops,
 };
 
 /*
@@ -993,19 +1087,35 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
 	timings = device->current_timings->timings;
 	error = tvp7002_s_dv_timings(sd, &timings);
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	strlcpy(sd->name, TVP7002_MODULE_NAME, sizeof(sd->name));
+	device->pad.flags = MEDIA_PAD_FL_SOURCE;
+	device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	device->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
+
+	error = media_entity_init(&device->sd.entity, 1, &device->pad, 0);
+	if (error < 0)
+		return error;
+#endif
+
 	v4l2_ctrl_handler_init(&device->hdl, 1);
 	v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
 			V4L2_CID_GAIN, 0, 255, 1, 0);
 	sd->ctrl_handler = &device->hdl;
 	if (device->hdl.error) {
-		int err = device->hdl.error;
-
-		v4l2_ctrl_handler_free(&device->hdl);
-		return err;
+		error = device->hdl.error;
+		goto done;
 	}
 	v4l2_ctrl_handler_setup(&device->hdl);
 
 	return 0;
+
+done:
+	v4l2_ctrl_handler_free(&device->hdl);
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	media_entity_cleanup(&device->sd.entity);
+#endif
+	return error;
 }
 
 /*
@@ -1022,7 +1132,9 @@ static int tvp7002_remove(struct i2c_client *c)
 
 	v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter"
 				"on address 0x%x\n", c->addr);
-
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	media_entity_cleanup(&device->sd.entity);
+#endif
 	v4l2_device_unregister_subdev(sd);
 	v4l2_ctrl_handler_free(&device->hdl);
 	return 0;
include/media/tvp7002.h +2 -0
index ee43534..7123048 100644
@@ -26,6 +26,8 @@
 #ifndef _TVP7002_H_
 #define _TVP7002_H_
 
+#define TVP7002_MODULE_NAME "tvp7002"
+
 /* Platform-dependent data
  *
  * clk_polarity:
Signature · 1 line
1.7.4.1
#1 lore raw

Ho Prabhakar,

Thank you for the patch.

Quoted 21 lines · On Thursday 02 May 2013 11:14:42 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

This patch enables tvp7002 decoder driver for media controller based usage by adding v4l2_subdev_pad_ops operations support for enum_mbus_code, set_pad_format, get_pad_format and media_entity_init() on probe and media_entity_cleanup() on remove.

---
Changes for v2:
1: Fixed review comment pointed by Laurent, Don’t return error for set_fmt
but fix the input parameters according to current timings.

 drivers/media/i2c/tvp7002.c |  122 ++++++++++++++++++++++++++++++++++++++--
 include/media/tvp7002.h     |    2 +
 2 files changed, 119 insertions(+), 5 deletions(-)
drivers/media/i2c/tvp7002.c +0 -0
index 027809c..3be687e 100644

[snip]

Quoted 19 lines
drivers/media/i2c/tvp7002.c +19 -0
+/*
+ * tvp7002_set_pad_format() - set video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @fmt: pointer to subdev format struct
+ *
+ * set video format for pad.
+ */
+static int
+tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+		       struct v4l2_subdev_format *fmt)
+{
+	struct tvp7002 *tvp7002 = to_tvp7002(sd);
+
+	/* if format doesn’t match the current timings fix the input
+	 * parameters according to what device supports.
+	 */
+	if (fmt->format.field != tvp7002->current_timings->scanmode ||
+	    fmt->format.code != V4L2_MBUS_FMT_YUYV10_1X20 ||

drivers/media/i2c/tvp7002.c static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = { · line 934

Quoted 10 lines
drivers/media/i2c/tvp7002.c +10 -0
+	    fmt->format.colorspace != tvp7002->current_timings->color_space ||
+	    fmt->format.width != tvp7002->current_timings->timings.bt.width ||
+	    fmt->format.height != tvp7002->current_timings->timings.bt.height) {
+		fmt->format.field = tvp7002->current_timings->scanmode;
+		fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
+		fmt->format.colorspace = tvp7002->current_timings->color_space;
+		fmt->format.width = tvp7002->current_timings->timings.bt.width;
+		fmt->format.height =
+				tvp7002->current_timings->timings.bt.height;
+	}

You can do this unconditionally.

drivers/media/i2c/tvp7002.c static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = { · line 936

Quoted 1 line
drivers/media/i2c/tvp7002.c +1 -0
+	tvp7002->format = fmt->format;

That's not valid for TRY formats.

As the format is fixed, I would get rid of the struct tvp7002 format field, remove the ACTIVE format check below, and just call tvp7002_get_pad_format in tvp7002_set_pad_format.

static int
tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *fmt)

{
	struct tvp7002 *tvp7002 = to_tvp7002(sd);

	fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
	fmt->format.width = tvp7002->current_timings->timings.bt.width;
	fmt->format.height = tvp7002->current_timings->timings.bt.height;
	fmt->format.field = tvp7002->current_timings->scanmode;
	fmt->format.colorspace = tvp7002->current_timings->color_space;

	return 0;
}

static int
tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *fmt)

{
	return tvp7002_get_pad_format(sd, fh, fmt);
}
Quoted 30 lines
drivers/media/i2c/tvp7002.c +30 -0
+	return 0;
+}
+
+/*
+ * tvp7002_get_pad_format() - get video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @fmt: pointer to subdev format struct
+ *
+ * get video format for pad.
+ */
+static int
+tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+		       struct v4l2_subdev_format *fmt)
+{
+	struct tvp7002 *tvp7002 = to_tvp7002(sd);
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		fmt->format = tvp7002->format;
+		return 0;
+	}
+
+	fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
+	fmt->format.width = tvp7002->current_timings->timings.bt.width;
+	fmt->format.height = tvp7002->current_timings->timings.bt.height;
+	fmt->format.field = tvp7002->current_timings->scanmode;
+	fmt->format.colorspace = tvp7002->current_timings->color_space;
+
+	return 0;
+}

[snip]

Quoted 22 lines
drivers/media/i2c/tvp7002.c +11 -2
@@ -993,19 +1087,35 @@ static int tvp7002_probe(struct i2c_client *c, const
 struct i2c_device_id *id) timings = device->current_timings->timings;
 	error = tvp7002_s_dv_timings(sd, &timings);
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	strlcpy(sd->name, TVP7002_MODULE_NAME, sizeof(sd->name));
+	device->pad.flags = MEDIA_PAD_FL_SOURCE;
+	device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	device->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
+
+	error = media_entity_init(&device->sd.entity, 1, &device->pad, 0);
+	if (error < 0)
+		return error;
+#endif
+
 	v4l2_ctrl_handler_init(&device->hdl, 1);
 	v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
 			V4L2_CID_GAIN, 0, 255, 1, 0);
 	sd->ctrl_handler = &device->hdl;
 	if (device->hdl.error) {
-		int err = device->hdl.error;
-

drivers/media/i2c/tvp7002.c static int tvp7002_probe(struct i2c_client *c, const · line 1113

Quoted 10 lines
drivers/media/i2c/tvp7002.c +4 -2
-		v4l2_ctrl_handler_free(&device->hdl);
-		return err;
+		error = device->hdl.error;
+		goto done;
 	}
 	v4l2_ctrl_handler_setup(&device->hdl);
 
 	return 0;
+
+done:

Please rename the label to 'error', as it only handles error cases.

Quoted 6 lines
drivers/media/i2c/tvp7002.c +5 -0
+	v4l2_ctrl_handler_free(&device->hdl);
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	media_entity_cleanup(&device->sd.entity);
+#endif
+	return error;
 }
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

Thanks for the review.

Quoted 84 lines · Laurent Pinchart

Ho Prabhakar,

Thank you for the patch.

Quoted 21 lines · On Thursday 02 May 2013 11:14:42 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

This patch enables tvp7002 decoder driver for media controller based usage by adding v4l2_subdev_pad_ops operations support for enum_mbus_code, set_pad_format, get_pad_format and media_entity_init() on probe and media_entity_cleanup() on remove.

---
Changes for v2:
1: Fixed review comment pointed by Laurent, Don’t return error for set_fmt
but fix the input parameters according to current timings.

 drivers/media/i2c/tvp7002.c |  122 ++++++++++++++++++++++++++++++++++++++--
 include/media/tvp7002.h     |    2 +
 2 files changed, 119 insertions(+), 5 deletions(-)
drivers/media/i2c/tvp7002.c +0 -0
index 027809c..3be687e 100644

[snip]

Quoted 19 lines
drivers/media/i2c/tvp7002.c +19 -0
+/*
+ * tvp7002_set_pad_format() - set video format on pad
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @fh: file handle for the subdev
+ * @fmt: pointer to subdev format struct
+ *
+ * set video format for pad.
+ */
+static int
+tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
+                    struct v4l2_subdev_format *fmt)
+{
+     struct tvp7002 *tvp7002 = to_tvp7002(sd);
+
+     /* if format doesn’t match the current timings fix the input
+      * parameters according to what device supports.
+      */
+     if (fmt->format.field != tvp7002->current_timings->scanmode ||
+         fmt->format.code != V4L2_MBUS_FMT_YUYV10_1X20 ||

drivers/media/i2c/tvp7002.c static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = { · line 934

Quoted 10 lines
drivers/media/i2c/tvp7002.c +10 -0
+         fmt->format.colorspace != tvp7002->current_timings->color_space ||
+         fmt->format.width != tvp7002->current_timings->timings.bt.width ||
+         fmt->format.height != tvp7002->current_timings->timings.bt.height) {
+             fmt->format.field = tvp7002->current_timings->scanmode;
+             fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
+             fmt->format.colorspace = tvp7002->current_timings->color_space;
+             fmt->format.width = tvp7002->current_timings->timings.bt.width;
+             fmt->format.height =
+                             tvp7002->current_timings->timings.bt.height;
+     }

You can do this unconditionally.

Quoted 1 line

+ tvp7002->format = fmt->format;

That's not valid for TRY formats.

As the format is fixed, I would get rid of the struct tvp7002 format field, remove the ACTIVE format check below, and just call tvp7002_get_pad_format in tvp7002_set_pad_format.

static int
tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *fmt)

{
        struct tvp7002 *tvp7002 = to_tvp7002(sd);

        fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
        fmt->format.width = tvp7002->current_timings->timings.bt.width;
        fmt->format.height = tvp7002->current_timings->timings.bt.height;
        fmt->format.field = tvp7002->current_timings->scanmode;
        fmt->format.colorspace = tvp7002->current_timings->color_space;

        return 0;
}
Quoted 7 lines

static int
tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *fmt)

{
        return tvp7002_get_pad_format(sd, fh, fmt);
}

Alright makes sense.

Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/tvp7002.c +5 -0
+     return 0;
+}
+
+/*
+ * tvp7002_get_pad_format() - get video format on pad

[Snip]

Quoted 14 lines
Quoted 14 lines
      v4l2_ctrl_handler_init(&device->hdl, 1);
      v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
                      V4L2_CID_GAIN, 0, 255, 1, 0);
      sd->ctrl_handler = &device->hdl;
      if (device->hdl.error) {
drivers/media/i2c/tvp7002.c +2 -4
-             int err = device->hdl.error;
-
-             v4l2_ctrl_handler_free(&device->hdl);
-             return err;
+             error = device->hdl.error;
+             goto done;
      }
      v4l2_ctrl_handler_setup(&device->hdl);
Quoted 6 lines

drivers/media/i2c/tvp7002.c

Quoted 3 lines
      return 0;
drivers/media/i2c/tvp7002.c +2 -0
+
+done:

Please rename the label to 'error', as it only handles error cases.

OK

Regards,
--Prabhakar Lad