linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support
@ 2021-04-12 11:34 Tomi Valkeinen
  2021-04-12 11:34 ` [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API Tomi Valkeinen
                   ` (27 more replies)
  0 siblings, 28 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Hi,

I'm working on adding multistream support to TI CAL driver. This series
is a preparation series: it does not add any new features, but adds
code needed for multistreaming. In other words, with this series the
driver works just like it used to.

The multistream code is not ready yet, but I'd like to start cleaning up
my work branch by getting the "probably ok" patches reviewed and
possibly merged.

 Tomi

Tomi Valkeinen (28):
  media: ti-vpe: cal: add g/s_parm for legacy API
  media: ti-vpe: cal: fix error handling in cal_camerarx_create
  media: ti-vpe: cal: remove unused cal_camerarx->dev field
  media: ti-vpe: cal: rename "sensor" to "source"
  media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to
    runtime resume
  media: ti-vpe: cal: use v4l2_get_link_freq
  media: ti-vpe: cal: add cal_ctx_prepare/unprepare
  media: ti-vpe: cal: change index and cport to u8
  media: ti-vpe: cal: Add PPI context
  media: ti-vpe: cal: Add pixel processing context
  media: ti-vpe: cal: rename cal_ctx->index to dma_ctx
  media: ti-vpe: cal: rename CAL_HL_IRQ_MASK
  media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros
  media: ti-vpe: cal: catch VC errors
  media: ti-vpe: cal: remove wait when stopping camerarx
  media: ti-vpe: cal: disable ppi and pix proc at ctx_stop
  media: ti-vpe: cal: allocate pix proc dynamically
  media: ti-vpe: cal: add 'use_pix_proc' field
  media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race
  media: ti-vpe: cal: add vc and datatype fields to cal_ctx
  media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  media: ti-vpe: cal: set field always to V4L2_FIELD_NONE
  media: ti-vpe: cal: fix typo in a comment
  media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap
  media: ti-vpe: cal: rename non-MC funcs to cal_legacy_*
  media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode
  media: ti-vpe: cal: remove cal_camerarx->fmtinfo
  media: ti-vpe: cal: support 8 DMA contexts

 drivers/media/platform/ti-vpe/cal-camerarx.c | 157 ++++++-------
 drivers/media/platform/ti-vpe/cal-video.c    | 163 +++++++++----
 drivers/media/platform/ti-vpe/cal.c          | 232 ++++++++++++-------
 drivers/media/platform/ti-vpe/cal.h          |  37 +--
 drivers/media/platform/ti-vpe/cal_regs.h     |  51 +---
 5 files changed, 381 insertions(+), 259 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 84+ messages in thread

* [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-17 23:01   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create Tomi Valkeinen
                   ` (26 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

v4l2-compliance complains about g/s_parm when using the non-MC API. Fix
it by adding the functions and just call v4l2_s/g_parm_cap for the
phy subdev.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 7b7436a355ee..86d7cdd27224 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -388,6 +388,20 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
 	return 0;
 }
 
+static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+{
+	struct cal_ctx *ctx = video_drvdata(file);
+
+	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->sensor, a);
+}
+
+static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+{
+	struct cal_ctx *ctx = video_drvdata(file);
+
+	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->sensor, a);
+}
+
 static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
 	.vidioc_querycap      = cal_querycap,
 	.vidioc_enum_fmt_vid_cap  = cal_enum_fmt_vid_cap,
@@ -411,6 +425,8 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
 	.vidioc_log_status    = v4l2_ctrl_log_status,
 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+	.vidioc_g_parm		= cal_g_parm,
+	.vidioc_s_parm		= cal_s_parm,
 };
 
 /* ------------------------------------------------------------------
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
  2021-04-12 11:34 ` [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-17 23:05   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field Tomi Valkeinen
                   ` (25 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

cal_camerarx_create() doesn't handle error returned from
cal_camerarx_sd_init_cfg() and it always runs all the cleanup/free
functions in the error code path. The latter doesn't cause any issues at
the moment as media_entity_cleanup() is an empty function.

Fix the error handling.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index cbe6114908de..820fb483c402 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -812,7 +812,7 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 	if (IS_ERR(phy->base)) {
 		cal_err(cal, "failed to ioremap\n");
 		ret = PTR_ERR(phy->base);
-		goto error;
+		goto err_free_phy;
 	}
 
 	cal_dbg(1, cal, "ioresource %s at %pa - %pa\n",
@@ -820,11 +820,11 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 
 	ret = cal_camerarx_regmap_init(cal, phy);
 	if (ret)
-		goto error;
+		goto err_free_phy;
 
 	ret = cal_camerarx_parse_dt(phy);
 	if (ret)
-		goto error;
+		goto err_free_phy;
 
 	/* Initialize the V4L2 subdev and media entity. */
 	sd = &phy->subdev;
@@ -840,18 +840,21 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 	ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(phy->pads),
 				     phy->pads);
 	if (ret)
-		goto error;
+		goto err_entity_cleanup;
 
-	cal_camerarx_sd_init_cfg(sd, NULL);
+	ret = cal_camerarx_sd_init_cfg(sd, NULL);
+	if (ret)
+		goto err_entity_cleanup;
 
 	ret = v4l2_device_register_subdev(&cal->v4l2_dev, sd);
 	if (ret)
-		goto error;
+		goto err_entity_cleanup;
 
 	return phy;
 
-error:
+err_entity_cleanup:
 	media_entity_cleanup(&phy->subdev.entity);
+err_free_phy:
 	kfree(phy);
 	return ERR_PTR(ret);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
  2021-04-12 11:34 ` [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API Tomi Valkeinen
  2021-04-12 11:34 ` [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18  0:43   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source" Tomi Valkeinen
                   ` (24 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

cal_camerarx->dev field is not used, remove it.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index db0e408eaa94..e079c6a9f93f 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -149,7 +149,6 @@ struct cal_data {
 struct cal_camerarx {
 	void __iomem		*base;
 	struct resource		*res;
-	struct device		*dev;
 	struct regmap_field	*fields[F_MAX_FIELDS];
 
 	struct cal_dev		*cal;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source"
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (2 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-17 23:18   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume Tomi Valkeinen
                   ` (23 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL driver uses "sensor" name to refer to the subdev connected to CAL.
As the subdev can also be a bridge, the naming is misleading and might
cause the reader to think it refers to the actual sensor at the end of
the pipeline.

Rename "sensor" to "source".

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 34 ++++++++++----------
 drivers/media/platform/ti-vpe/cal-video.c    | 26 +++++++--------
 drivers/media/platform/ti-vpe/cal.c          | 20 ++++++------
 drivers/media/platform/ti-vpe/cal.h          |  6 ++--
 4 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 820fb483c402..603405824738 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -50,15 +50,15 @@ static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy)
 	struct v4l2_ctrl *ctrl;
 	s64 rate;
 
-	ctrl = v4l2_ctrl_find(phy->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE);
+	ctrl = v4l2_ctrl_find(phy->source->ctrl_handler, V4L2_CID_PIXEL_RATE);
 	if (!ctrl) {
 		phy_err(phy, "no pixel rate control in subdev: %s\n",
-			phy->sensor->name);
+			phy->source->name);
 		return -EPIPE;
 	}
 
 	rate = v4l2_ctrl_g_ctrl_int64(ctrl);
-	phy_dbg(3, phy, "sensor Pixel Rate: %llu\n", rate);
+	phy_dbg(3, phy, "Source Pixel Rate: %llu\n", rate);
 
 	return rate;
 }
@@ -279,7 +279,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
 	if (external_rate < 0)
 		return external_rate;
 
-	ret = v4l2_subdev_call(phy->sensor, core, s_power, 1);
+	ret = v4l2_subdev_call(phy->source, core, s_power, 1);
 	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
 		phy_err(phy, "power on failed in subdev\n");
 		return ret;
@@ -311,7 +311,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
 	 * 2. CSI PHY and link initialization sequence.
 	 *
 	 *    a. Deassert the CSI-2 PHY reset. Do not wait for reset completion
-	 *       at this point, as it requires the external sensor to send the
+	 *       at this point, as it requires the external source to send the
 	 *       CSI-2 HS clock.
 	 */
 	cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
@@ -370,12 +370,12 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
 	cal_camerarx_power(phy, true);
 
 	/*
-	 * Start the sensor to enable the CSI-2 HS clock. We can now wait for
+	 * Start the source to enable the CSI-2 HS clock. We can now wait for
 	 * CSI-2 PHY reset to complete.
 	 */
-	ret = v4l2_subdev_call(phy->sensor, video, s_stream, 1);
+	ret = v4l2_subdev_call(phy->source, video, s_stream, 1);
 	if (ret) {
-		v4l2_subdev_call(phy->sensor, core, s_power, 0);
+		v4l2_subdev_call(phy->source, core, s_power, 0);
 		cal_camerarx_disable_irqs(phy);
 		phy_err(phy, "stream on failed in subdev\n");
 		return ret;
@@ -435,10 +435,10 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
 	/* Disable the phy */
 	cal_camerarx_disable(phy);
 
-	if (v4l2_subdev_call(phy->sensor, video, s_stream, 0))
+	if (v4l2_subdev_call(phy->source, video, s_stream, 0))
 		phy_err(phy, "stream off failed in subdev\n");
 
-	ret = v4l2_subdev_call(phy->sensor, core, s_power, 0);
+	ret = v4l2_subdev_call(phy->source, core, s_power, 0);
 	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
 		phy_err(phy, "power off failed in subdev\n");
 }
@@ -558,16 +558,16 @@ static int cal_camerarx_parse_dt(struct cal_camerarx *phy)
 		endpoint->bus.mipi_csi2.flags);
 
 	/* Retrieve the connected device and store it for later use. */
-	phy->sensor_ep_node = of_graph_get_remote_endpoint(ep_node);
-	phy->sensor_node = of_graph_get_port_parent(phy->sensor_ep_node);
-	if (!phy->sensor_node) {
+	phy->source_ep_node = of_graph_get_remote_endpoint(ep_node);
+	phy->source_node = of_graph_get_port_parent(phy->source_ep_node);
+	if (!phy->source_node) {
 		phy_dbg(3, phy, "Can't get remote parent\n");
-		of_node_put(phy->sensor_ep_node);
+		of_node_put(phy->source_ep_node);
 		ret = -EINVAL;
 		goto done;
 	}
 
-	phy_dbg(1, phy, "Found connected device %pOFn\n", phy->sensor_node);
+	phy_dbg(1, phy, "Found connected device %pOFn\n", phy->source_node);
 
 done:
 	of_node_put(ep_node);
@@ -866,7 +866,7 @@ void cal_camerarx_destroy(struct cal_camerarx *phy)
 
 	v4l2_device_unregister_subdev(&phy->subdev);
 	media_entity_cleanup(&phy->subdev.entity);
-	of_node_put(phy->sensor_ep_node);
-	of_node_put(phy->sensor_node);
+	of_node_put(phy->source_ep_node);
+	of_node_put(phy->source_node);
 	kfree(phy);
 }
diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 86d7cdd27224..cf603cc9114c 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -128,7 +128,7 @@ static int __subdev_get_format(struct cal_ctx *ctx,
 	sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 	sd_fmt.pad = 0;
 
-	ret = v4l2_subdev_call(ctx->phy->sensor, pad, get_fmt, NULL, &sd_fmt);
+	ret = v4l2_subdev_call(ctx->phy->source, pad, get_fmt, NULL, &sd_fmt);
 	if (ret)
 		return ret;
 
@@ -151,7 +151,7 @@ static int __subdev_set_format(struct cal_ctx *ctx,
 	sd_fmt.pad = 0;
 	*mbus_fmt = *fmt;
 
-	ret = v4l2_subdev_call(ctx->phy->sensor, pad, set_fmt, NULL, &sd_fmt);
+	ret = v4l2_subdev_call(ctx->phy->source, pad, set_fmt, NULL, &sd_fmt);
 	if (ret)
 		return ret;
 
@@ -216,7 +216,7 @@ static int cal_try_fmt_vid_cap(struct file *file, void *priv,
 	fse.code = fmtinfo->code;
 	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 	for (fse.index = 0; ; fse.index++) {
-		ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size,
+		ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size,
 				       NULL, &fse);
 		if (ret)
 			break;
@@ -321,7 +321,7 @@ static int cal_enum_framesizes(struct file *file, void *fh,
 	fse.code = fmtinfo->code;
 	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 
-	ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size, NULL,
+	ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size, NULL,
 			       &fse);
 	if (ret)
 		return ret;
@@ -378,7 +378,7 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
 		return -EINVAL;
 
 	fie.code = fmtinfo->code;
-	ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_interval,
+	ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_interval,
 			       NULL, &fie);
 	if (ret)
 		return ret;
@@ -392,14 +392,14 @@ static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
 
-	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->sensor, a);
+	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->source, a);
 }
 
 static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
 
-	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->sensor, a);
+	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->source, a);
 }
 
 static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
@@ -799,20 +799,20 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
 		memset(&mbus_code, 0, sizeof(mbus_code));
 		mbus_code.index = j;
 		mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-		ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_mbus_code,
+		ret = v4l2_subdev_call(ctx->phy->source, pad, enum_mbus_code,
 				       NULL, &mbus_code);
 		if (ret == -EINVAL)
 			break;
 
 		if (ret) {
 			ctx_err(ctx, "Error enumerating mbus codes in subdev %s: %d\n",
-				ctx->phy->sensor->name, ret);
+				ctx->phy->source->name, ret);
 			return ret;
 		}
 
 		ctx_dbg(2, ctx,
 			"subdev %s: code: %04x idx: %u\n",
-			ctx->phy->sensor->name, mbus_code.code, j);
+			ctx->phy->source->name, mbus_code.code, j);
 
 		for (k = 0; k < cal_num_formats; k++) {
 			fmtinfo = &cal_formats[k];
@@ -830,7 +830,7 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
 
 	if (i == 0) {
 		ctx_err(ctx, "No suitable format reported by subdev %s\n",
-			ctx->phy->sensor->name);
+			ctx->phy->source->name);
 		return -EINVAL;
 	}
 
@@ -867,10 +867,10 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
 	if (!cal_mc_api) {
 		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
 
-		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->sensor->ctrl_handler,
+		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
 					    NULL, true);
 		if (ret < 0) {
-			ctx_err(ctx, "Failed to add sensor ctrl handler\n");
+			ctx_err(ctx, "Failed to add source ctrl handler\n");
 			return ret;
 		}
 	}
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 2e2bef91b2b0..a5340b583592 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -635,20 +635,20 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
 	int pad;
 	int ret;
 
-	if (phy->sensor) {
+	if (phy->source) {
 		phy_info(phy, "Rejecting subdev %s (Already set!!)",
 			 subdev->name);
 		return 0;
 	}
 
-	phy->sensor = subdev;
-	phy_dbg(1, phy, "Using sensor %s for capture\n", subdev->name);
+	phy->source = subdev;
+	phy_dbg(1, phy, "Using source %s for capture\n", subdev->name);
 
 	pad = media_entity_get_fwnode_pad(&subdev->entity,
-					  of_fwnode_handle(phy->sensor_ep_node),
+					  of_fwnode_handle(phy->source_ep_node),
 					  MEDIA_PAD_FL_SOURCE);
 	if (pad < 0) {
-		phy_err(phy, "Sensor %s has no connected source pad\n",
+		phy_err(phy, "Source %s has no connected source pad\n",
 			subdev->name);
 		return pad;
 	}
@@ -658,7 +658,7 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
 				    MEDIA_LNK_FL_IMMUTABLE |
 				    MEDIA_LNK_FL_ENABLED);
 	if (ret) {
-		phy_err(phy, "Failed to create media link for sensor %s\n",
+		phy_err(phy, "Failed to create media link for source %s\n",
 			subdev->name);
 		return ret;
 	}
@@ -701,10 +701,10 @@ static int cal_async_notifier_register(struct cal_dev *cal)
 		struct cal_v4l2_async_subdev *casd;
 		struct fwnode_handle *fwnode;
 
-		if (!phy->sensor_node)
+		if (!phy->source_node)
 			continue;
 
-		fwnode = of_fwnode_handle(phy->sensor_node);
+		fwnode = of_fwnode_handle(phy->source_node);
 		casd = v4l2_async_notifier_add_fwnode_subdev(&cal->notifier,
 							     fwnode,
 							     struct cal_v4l2_async_subdev);
@@ -1045,7 +1045,7 @@ static int cal_probe(struct platform_device *pdev)
 			goto error_camerarx;
 		}
 
-		if (cal->phy[i]->sensor_node)
+		if (cal->phy[i]->source_node)
 			connected = true;
 	}
 
@@ -1057,7 +1057,7 @@ static int cal_probe(struct platform_device *pdev)
 
 	/* Create contexts. */
 	for (i = 0; i < cal->data->num_csi2_phy; ++i) {
-		if (!cal->phy[i]->sensor_node)
+		if (!cal->phy[i]->source_node)
 			continue;
 
 		cal->ctx[i] = cal_ctx_create(cal, i);
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index e079c6a9f93f..af46084580bd 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -155,9 +155,9 @@ struct cal_camerarx {
 	unsigned int		instance;
 
 	struct v4l2_fwnode_endpoint	endpoint;
-	struct device_node	*sensor_ep_node;
-	struct device_node	*sensor_node;
-	struct v4l2_subdev	*sensor;
+	struct device_node	*source_ep_node;
+	struct device_node	*source_node;
+	struct v4l2_subdev	*source;
 	struct media_pipeline	pipe;
 
 	struct v4l2_subdev	subdev;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (3 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source" Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-17 23:27   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq Tomi Valkeinen
                   ` (22 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

For some reason CAL_CTRL is written at the end of cal_ctx_wr_dma_config.
CAL_CTRL is a global (for CAL) register, so it should be independent of
contexts.

Move the code to cal_runtime_resume().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index a5340b583592..b539a9afb3f5 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -403,17 +403,6 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
 	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index), val);
 	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->index,
 		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index)));
-
-	val = cal_read(ctx->cal, CAL_CTRL);
-	cal_set_field(&val, CAL_CTRL_BURSTSIZE_BURST128,
-		      CAL_CTRL_BURSTSIZE_MASK);
-	cal_set_field(&val, 0xF, CAL_CTRL_TAGCNT_MASK);
-	cal_set_field(&val, CAL_CTRL_POSTED_WRITES_NONPOSTED,
-		      CAL_CTRL_POSTED_WRITES_MASK);
-	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGL_MASK);
-	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGH_MASK);
-	cal_write(ctx->cal, CAL_CTRL, val);
-	ctx_dbg(3, ctx, "CAL_CTRL = 0x%08x\n", cal_read(ctx->cal, CAL_CTRL));
 }
 
 void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
@@ -1125,6 +1114,7 @@ static int cal_runtime_resume(struct device *dev)
 {
 	struct cal_dev *cal = dev_get_drvdata(dev);
 	unsigned int i;
+	u32 val;
 
 	if (cal->data->flags & DRA72_CAL_PRE_ES2_LDO_DISABLE) {
 		/*
@@ -1141,6 +1131,17 @@ static int cal_runtime_resume(struct device *dev)
 	 */
 	cal_write(cal, CAL_HL_IRQENABLE_SET(0), CAL_HL_IRQ_OCPO_ERR_MASK);
 
+	val = cal_read(cal, CAL_CTRL);
+	cal_set_field(&val, CAL_CTRL_BURSTSIZE_BURST128,
+		      CAL_CTRL_BURSTSIZE_MASK);
+	cal_set_field(&val, 0xF, CAL_CTRL_TAGCNT_MASK);
+	cal_set_field(&val, CAL_CTRL_POSTED_WRITES_NONPOSTED,
+		      CAL_CTRL_POSTED_WRITES_MASK);
+	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGL_MASK);
+	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGH_MASK);
+	cal_write(cal, CAL_CTRL, val);
+	cal_dbg(3, cal, "CAL_CTRL = 0x%08x\n", cal_read(cal, CAL_CTRL));
+
 	return 0;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (4 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 11:48   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare Tomi Valkeinen
                   ` (21 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL driver uses V4L2_CID_PIXEL_RATE to get the required pixel rate, and
then changes that value to link rate before configuring the registers.

Rewrite the code to use v4l2_get_link_freq(), which simplifies the code
as we get the link rate directly, and it also adds support for
V4L2_CID_LINK_FREQ.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 52 +++++++-------------
 1 file changed, 19 insertions(+), 33 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 603405824738..974fcbb19547 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -45,22 +45,23 @@ static inline void camerarx_write(struct cal_camerarx *phy, u32 offset, u32 val)
  * ------------------------------------------------------------------
  */
 
-static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy)
+static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
 {
-	struct v4l2_ctrl *ctrl;
-	s64 rate;
+	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = &phy->endpoint.bus.mipi_csi2;
+	u32 num_lanes = mipi_csi2->num_data_lanes;
+	u32 bpp = phy->fmtinfo->bpp;
+	s64 freq;
 
-	ctrl = v4l2_ctrl_find(phy->source->ctrl_handler, V4L2_CID_PIXEL_RATE);
-	if (!ctrl) {
-		phy_err(phy, "no pixel rate control in subdev: %s\n",
+	freq = v4l2_get_link_freq(phy->source->ctrl_handler, bpp, 2 * num_lanes);
+	if (freq < 0) {
+		phy_err(phy, "failed to get link freq for subdev: %s\n",
 			phy->source->name);
-		return -EPIPE;
+		return freq;
 	}
 
-	rate = v4l2_ctrl_g_ctrl_int64(ctrl);
-	phy_dbg(3, phy, "Source Pixel Rate: %llu\n", rate);
+	phy_dbg(3, phy, "Source Link Freq: %llu\n", freq);
 
-	return rate;
+	return freq;
 }
 
 static void cal_camerarx_lane_config(struct cal_camerarx *phy)
@@ -116,34 +117,19 @@ void cal_camerarx_disable(struct cal_camerarx *phy)
 #define TCLK_MISS	1
 #define TCLK_SETTLE	14
 
-static void cal_camerarx_config(struct cal_camerarx *phy, s64 external_rate)
+static void cal_camerarx_config(struct cal_camerarx *phy, s64 link_freq)
 {
 	unsigned int reg0, reg1;
 	unsigned int ths_term, ths_settle;
-	unsigned int csi2_ddrclk_khz;
-	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 =
-			&phy->endpoint.bus.mipi_csi2;
-	u32 num_lanes = mipi_csi2->num_data_lanes;
 
 	/* DPHY timing configuration */
 
-	/*
-	 * CSI-2 is DDR and we only count used lanes.
-	 *
-	 * csi2_ddrclk_khz = external_rate / 1000
-	 *		   / (2 * num_lanes) * phy->fmtinfo->bpp;
-	 */
-	csi2_ddrclk_khz = div_s64(external_rate * phy->fmtinfo->bpp,
-				  2 * num_lanes * 1000);
-
-	phy_dbg(1, phy, "csi2_ddrclk_khz: %d\n", csi2_ddrclk_khz);
-
 	/* THS_TERM: Programmed value = floor(20 ns/DDRClk period) */
-	ths_term = 20 * csi2_ddrclk_khz / 1000000;
+	ths_term = div_s64(20 * link_freq, 1000 * 1000 * 1000);
 	phy_dbg(1, phy, "ths_term: %d (0x%02x)\n", ths_term, ths_term);
 
 	/* THS_SETTLE: Programmed value = floor(105 ns/DDRClk period) + 4 */
-	ths_settle = (105 * csi2_ddrclk_khz / 1000000) + 4;
+	ths_settle = div_s64(105 * link_freq, 1000 * 1000 * 1000) + 4;
 	phy_dbg(1, phy, "ths_settle: %d (0x%02x)\n", ths_settle, ths_settle);
 
 	reg0 = camerarx_read(phy, CAL_CSI2_PHY_REG0);
@@ -270,14 +256,14 @@ static void cal_camerarx_ppi_disable(struct cal_camerarx *phy)
 
 static int cal_camerarx_start(struct cal_camerarx *phy)
 {
-	s64 external_rate;
+	s64 link_freq;
 	u32 sscounter;
 	u32 val;
 	int ret;
 
-	external_rate = cal_camerarx_get_external_rate(phy);
-	if (external_rate < 0)
-		return external_rate;
+	link_freq = cal_camerarx_get_ext_link_freq(phy);
+	if (link_freq < 0)
+		return link_freq;
 
 	ret = v4l2_subdev_call(phy->source, core, s_power, 1);
 	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
@@ -325,7 +311,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
 	camerarx_read(phy, CAL_CSI2_PHY_REG0);
 
 	/* Program the PHY timing parameters. */
-	cal_camerarx_config(phy, external_rate);
+	cal_camerarx_config(phy, link_freq);
 
 	/*
 	 *    b. Assert the FORCERXMODE signal.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (5 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:30   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8 Tomi Valkeinen
                   ` (20 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

In the following patches we need to do context configuration which might
fail. Add new functions, cal_ctx_prepare and cal_ctx_unprepare, to
handle such configuration.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c |  9 +++++++++
 drivers/media/platform/ti-vpe/cal.c       | 10 ++++++++++
 drivers/media/platform/ti-vpe/cal.h       |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index cf603cc9114c..8e9bbe6beb23 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -708,6 +708,12 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto error_pipeline;
 	}
 
+	ret = cal_ctx_prepare(ctx);
+	if (ret) {
+		ctx_err(ctx, "Failed to prepare context: %d\n", ret);
+		goto error_pipeline;
+	}
+
 	spin_lock_irq(&ctx->dma.lock);
 	buf = list_first_entry(&ctx->dma.queue, struct cal_buffer, list);
 	ctx->dma.pending = buf;
@@ -733,6 +739,7 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
 error_stop:
 	cal_ctx_stop(ctx);
 	pm_runtime_put_sync(ctx->cal->dev);
+	cal_ctx_unprepare(ctx);
 
 error_pipeline:
 	media_pipeline_stop(&ctx->vdev.entity);
@@ -752,6 +759,8 @@ static void cal_stop_streaming(struct vb2_queue *vq)
 
 	pm_runtime_put_sync(ctx->cal->dev);
 
+	cal_ctx_unprepare(ctx);
+
 	cal_release_buffers(ctx, VB2_BUF_STATE_ERROR);
 
 	media_pipeline_stop(&ctx->vdev.entity);
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index b539a9afb3f5..3d57aedbee0a 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -430,6 +430,16 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
 	return stopped;
 }
 
+int cal_ctx_prepare(struct cal_ctx *ctx)
+{
+	return 0;
+}
+
+void cal_ctx_unprepare(struct cal_ctx *ctx)
+{
+
+}
+
 void cal_ctx_start(struct cal_ctx *ctx)
 {
 	ctx->sequence = 0;
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index af46084580bd..09ad20faa9e1 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -296,6 +296,8 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 					 unsigned int instance);
 void cal_camerarx_destroy(struct cal_camerarx *phy);
 
+int cal_ctx_prepare(struct cal_ctx *ctx);
+void cal_ctx_unprepare(struct cal_ctx *ctx);
 void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr);
 void cal_ctx_start(struct cal_ctx *ctx);
 void cal_ctx_stop(struct cal_ctx *ctx);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (6 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 11:55   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 09/28] media: ti-vpe: cal: Add PPI context Tomi Valkeinen
                   ` (19 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

cal_ctx's index and cport fields are numbers less than 8. In the
following patches we will get a bunch of new fields, all of which are
similar small numbers, so lets change the type to u8.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 09ad20faa9e1..251bb0ba7b3b 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -217,8 +217,8 @@ struct cal_ctx {
 
 	unsigned int		sequence;
 	struct vb2_queue	vb_vidq;
-	unsigned int		index;
-	unsigned int		cport;
+	u8			index;
+	u8			cport;
 };
 
 extern unsigned int cal_debug;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 09/28] media: ti-vpe: cal: Add PPI context
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (7 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8 Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:17   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context Tomi Valkeinen
                   ` (18 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL has 8 PPI contexts per PHY, which are used to tag the incoming data.
The current driver only uses the first PPI, but we need to support all
of them to implement multi-stream support.

Add a ppi_ctx field to cal_ctx, which indicates which of the 8 PPI
contexts is used for the particular cal_ctx. Also clean up the PPI
context register macros to take the PPI context number as a parameter.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c      | 10 ++++++----
 drivers/media/platform/ti-vpe/cal.h      |  1 +
 drivers/media/platform/ti-vpe/cal_regs.h | 18 ++----------------
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 3d57aedbee0a..c550eeb27e79 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -294,7 +294,7 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
 {
 	u32 val;
 
-	val = cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index));
+	val = cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx));
 	cal_set_field(&val, ctx->cport, CAL_CSI2_CTX_CPORT_MASK);
 	/*
 	 * DT type: MIPI CSI-2 Specs
@@ -310,9 +310,10 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
 	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
 	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
 		      CAL_CSI2_CTX_PACK_MODE_MASK);
-	cal_write(ctx->cal, CAL_CSI2_CTX0(ctx->index), val);
-	ctx_dbg(3, ctx, "CAL_CSI2_CTX0(%d) = 0x%08x\n", ctx->index,
-		cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index)));
+	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), val);
+	ctx_dbg(3, ctx, "CAL_CSI2_CTX%d(%d) = 0x%08x\n",
+		ctx->phy->instance, ctx->ppi_ctx,
+		cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx)));
 }
 
 static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
@@ -854,6 +855,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
 	ctx->cal = cal;
 	ctx->phy = cal->phy[inst];
 	ctx->index = inst;
+	ctx->ppi_ctx = inst;
 	ctx->cport = inst;
 
 	ret = cal_ctx_v4l2_init(ctx);
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 251bb0ba7b3b..6eb63268f916 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -219,6 +219,7 @@ struct cal_ctx {
 	struct vb2_queue	vb_vidq;
 	u8			index;
 	u8			cport;
+	u8			ppi_ctx;
 };
 
 extern unsigned int cal_debug;
diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
index f752096dcf7f..5c4f9e642185 100644
--- a/drivers/media/platform/ti-vpe/cal_regs.h
+++ b/drivers/media/platform/ti-vpe/cal_regs.h
@@ -72,22 +72,8 @@
 #define CAL_CSI2_TIMING(m)		(0x314U + (m) * 0x80U)
 #define CAL_CSI2_VC_IRQENABLE(m)	(0x318U + (m) * 0x80U)
 #define CAL_CSI2_VC_IRQSTATUS(m)	(0x328U + (m) * 0x80U)
-#define CAL_CSI2_CTX0(m)		(0x330U + (m) * 0x80U)
-#define CAL_CSI2_CTX1(m)		(0x334U + (m) * 0x80U)
-#define CAL_CSI2_CTX2(m)		(0x338U + (m) * 0x80U)
-#define CAL_CSI2_CTX3(m)		(0x33cU + (m) * 0x80U)
-#define CAL_CSI2_CTX4(m)		(0x340U + (m) * 0x80U)
-#define CAL_CSI2_CTX5(m)		(0x344U + (m) * 0x80U)
-#define CAL_CSI2_CTX6(m)		(0x348U + (m) * 0x80U)
-#define CAL_CSI2_CTX7(m)		(0x34cU + (m) * 0x80U)
-#define CAL_CSI2_STATUS0(m)		(0x350U + (m) * 0x80U)
-#define CAL_CSI2_STATUS1(m)		(0x354U + (m) * 0x80U)
-#define CAL_CSI2_STATUS2(m)		(0x358U + (m) * 0x80U)
-#define CAL_CSI2_STATUS3(m)		(0x35cU + (m) * 0x80U)
-#define CAL_CSI2_STATUS4(m)		(0x360U + (m) * 0x80U)
-#define CAL_CSI2_STATUS5(m)		(0x364U + (m) * 0x80U)
-#define CAL_CSI2_STATUS6(m)		(0x368U + (m) * 0x80U)
-#define CAL_CSI2_STATUS7(m)		(0x36cU + (m) * 0x80U)
+#define CAL_CSI2_CTX(phy, ppi_ctx)	(0x330U + (phy) * 0x80U + (ppi_ctx) * 4)
+#define CAL_CSI2_STATUS(phy, ppi_ctx)	(0x350U + (phy) * 0x80U + (ppi_ctx) * 4)
 
 /* CAL CSI2 PHY register offsets */
 #define CAL_CSI2_PHY_REG0		0x000
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (8 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 09/28] media: ti-vpe: cal: Add PPI context Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:20   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx Tomi Valkeinen
                   ` (17 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL has 4 pixel processing contexts (PIX PROC) of which the driver
currently uses pix proc 0 for PHY0, and pix proc 1 for PHY1 (as the
driver supports only a single source per PHY).

Add a pix_proc field to cal_ctx to allow us to use different pix proc
contexts in the future

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 9 +++++----
 drivers/media/platform/ti-vpe/cal.h | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index c550eeb27e79..3dc83c66fd96 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -355,16 +355,16 @@ static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
 		break;
 	}
 
-	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->index));
+	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc));
 	cal_set_field(&val, extract, CAL_PIX_PROC_EXTRACT_MASK);
 	cal_set_field(&val, CAL_PIX_PROC_DPCMD_BYPASS, CAL_PIX_PROC_DPCMD_MASK);
 	cal_set_field(&val, CAL_PIX_PROC_DPCME_BYPASS, CAL_PIX_PROC_DPCME_MASK);
 	cal_set_field(&val, pack, CAL_PIX_PROC_PACK_MASK);
 	cal_set_field(&val, ctx->cport, CAL_PIX_PROC_CPORT_MASK);
 	cal_set_field(&val, 1, CAL_PIX_PROC_EN_MASK);
-	cal_write(ctx->cal, CAL_PIX_PROC(ctx->index), val);
-	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->index,
-		cal_read(ctx->cal, CAL_PIX_PROC(ctx->index)));
+	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), val);
+	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->pix_proc,
+		cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc)));
 }
 
 static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
@@ -857,6 +857,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
 	ctx->index = inst;
 	ctx->ppi_ctx = inst;
 	ctx->cport = inst;
+	ctx->pix_proc = inst;
 
 	ret = cal_ctx_v4l2_init(ctx);
 	if (ret)
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 6eb63268f916..03c71763f1a5 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -220,6 +220,7 @@ struct cal_ctx {
 	u8			index;
 	u8			cport;
 	u8			ppi_ctx;
+	u8			pix_proc;
 };
 
 extern unsigned int cal_debug;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (9 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:22   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK Tomi Valkeinen
                   ` (16 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Rename cal_ctx->index to dma_ctx to clarify that the field refers to the
DMA context number.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c |  4 +--
 drivers/media/platform/ti-vpe/cal.c       | 38 +++++++++++------------
 drivers/media/platform/ti-vpe/cal.h       |  8 ++---
 3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 8e9bbe6beb23..064efdc31b28 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -897,7 +897,7 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
 				    MEDIA_LNK_FL_ENABLED);
 	if (ret) {
 		ctx_err(ctx, "Failed to create media link for context %u\n",
-			ctx->index);
+			ctx->dma_ctx);
 		video_unregister_device(vfd);
 		return ret;
 	}
@@ -949,7 +949,7 @@ int cal_ctx_v4l2_init(struct cal_ctx *ctx)
 			 | (cal_mc_api ? V4L2_CAP_IO_MC : 0);
 	vfd->v4l2_dev = &ctx->cal->v4l2_dev;
 	vfd->queue = q;
-	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->index);
+	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->dma_ctx);
 	vfd->release = video_device_release_empty;
 	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_video_ops;
 	vfd->lock = &ctx->mutex;
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 3dc83c66fd96..daa0c1ab94e7 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -372,7 +372,7 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
 	unsigned int stride = ctx->v_fmt.fmt.pix.bytesperline;
 	u32 val;
 
-	val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index));
+	val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
 	cal_set_field(&val, ctx->cport, CAL_WR_DMA_CTRL_CPORT_MASK);
 	cal_set_field(&val, ctx->v_fmt.fmt.pix.height,
 		      CAL_WR_DMA_CTRL_YSIZE_MASK);
@@ -383,16 +383,16 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
 	cal_set_field(&val, CAL_WR_DMA_CTRL_PATTERN_LINEAR,
 		      CAL_WR_DMA_CTRL_PATTERN_MASK);
 	cal_set_field(&val, 1, CAL_WR_DMA_CTRL_STALL_RD_MASK);
-	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->index), val);
-	ctx_dbg(3, ctx, "CAL_WR_DMA_CTRL(%d) = 0x%08x\n", ctx->index,
-		cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index)));
+	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
+	ctx_dbg(3, ctx, "CAL_WR_DMA_CTRL(%d) = 0x%08x\n", ctx->dma_ctx,
+		cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx)));
 
-	cal_write_field(ctx->cal, CAL_WR_DMA_OFST(ctx->index),
+	cal_write_field(ctx->cal, CAL_WR_DMA_OFST(ctx->dma_ctx),
 			stride / 16, CAL_WR_DMA_OFST_MASK);
-	ctx_dbg(3, ctx, "CAL_WR_DMA_OFST(%d) = 0x%08x\n", ctx->index,
-		cal_read(ctx->cal, CAL_WR_DMA_OFST(ctx->index)));
+	ctx_dbg(3, ctx, "CAL_WR_DMA_OFST(%d) = 0x%08x\n", ctx->dma_ctx,
+		cal_read(ctx->cal, CAL_WR_DMA_OFST(ctx->dma_ctx)));
 
-	val = cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index));
+	val = cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx));
 	/* 64 bit word means no skipping */
 	cal_set_field(&val, 0, CAL_WR_DMA_XSIZE_XSKIP_MASK);
 	/*
@@ -401,23 +401,23 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
 	 * written per line.
 	 */
 	cal_set_field(&val, stride / 8, CAL_WR_DMA_XSIZE_MASK);
-	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index), val);
-	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->index,
-		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index)));
+	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx), val);
+	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->dma_ctx,
+		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx)));
 }
 
 void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
 {
-	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->index), addr);
+	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->dma_ctx), addr);
 }
 
 static void cal_ctx_wr_dma_disable(struct cal_ctx *ctx)
 {
-	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index));
+	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
 
 	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_DIS,
 		      CAL_WR_DMA_CTRL_MODE_MASK);
-	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->index), val);
+	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
 }
 
 static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
@@ -453,9 +453,9 @@ void cal_ctx_start(struct cal_ctx *ctx)
 
 	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(1),
-		  CAL_HL_IRQ_MASK(ctx->index));
+		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
-		  CAL_HL_IRQ_MASK(ctx->index));
+		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
 }
 
 void cal_ctx_stop(struct cal_ctx *ctx)
@@ -479,9 +479,9 @@ void cal_ctx_stop(struct cal_ctx *ctx)
 
 	/* Disable IRQ_WDMA_END and IRQ_WDMA_START. */
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(1),
-		  CAL_HL_IRQ_MASK(ctx->index));
+		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(2),
-		  CAL_HL_IRQ_MASK(ctx->index));
+		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
 
 	ctx->dma.state = CAL_DMA_STOPPED;
 }
@@ -854,7 +854,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
 
 	ctx->cal = cal;
 	ctx->phy = cal->phy[inst];
-	ctx->index = inst;
+	ctx->dma_ctx = inst;
 	ctx->ppi_ctx = inst;
 	ctx->cport = inst;
 	ctx->pix_proc = inst;
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 03c71763f1a5..c34b843d2019 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -217,7 +217,7 @@ struct cal_ctx {
 
 	unsigned int		sequence;
 	struct vb2_queue	vb_vidq;
-	u8			index;
+	u8			dma_ctx;
 	u8			cport;
 	u8			ppi_ctx;
 	u8			pix_proc;
@@ -238,11 +238,11 @@ extern bool cal_mc_api;
 	dev_err((cal)->dev, fmt, ##arg)
 
 #define ctx_dbg(level, ctx, fmt, arg...)				\
-	cal_dbg(level, (ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
+	cal_dbg(level, (ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
 #define ctx_info(ctx, fmt, arg...)					\
-	cal_info((ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
+	cal_info((ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
 #define ctx_err(ctx, fmt, arg...)					\
-	cal_err((ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
+	cal_err((ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
 
 #define phy_dbg(level, phy, fmt, arg...)				\
 	cal_dbg(level, (phy)->cal, "phy%u: " fmt, (phy)->instance, ##arg)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (10 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:29   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros Tomi Valkeinen
                   ` (15 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL_HL_IRQ_MASK macro is used for both WDMA start and end status bits.
For clarity, rename CAL_HL_IRQ_MASK macro to CAL_HL_IRQ_WDMA_END_MASK
and CAL_HL_IRQ_WDMA_START_MASK.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c      | 12 ++++++------
 drivers/media/platform/ti-vpe/cal_regs.h |  3 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index daa0c1ab94e7..0abcc83841c6 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -453,9 +453,9 @@ void cal_ctx_start(struct cal_ctx *ctx)
 
 	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(1),
-		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
+		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
-		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
+		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
 }
 
 void cal_ctx_stop(struct cal_ctx *ctx)
@@ -479,9 +479,9 @@ void cal_ctx_stop(struct cal_ctx *ctx)
 
 	/* Disable IRQ_WDMA_END and IRQ_WDMA_START. */
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(1),
-		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
+		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(2),
-		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
+		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
 
 	ctx->dma.state = CAL_DMA_STOPPED;
 }
@@ -589,7 +589,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
 		cal_write(cal, CAL_HL_IRQSTATUS(1), status);
 
 		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
-			if (status & CAL_HL_IRQ_MASK(i))
+			if (status & CAL_HL_IRQ_WDMA_END_MASK(i))
 				cal_irq_wdma_end(cal->ctx[i]);
 		}
 	}
@@ -603,7 +603,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
 		cal_write(cal, CAL_HL_IRQSTATUS(2), status);
 
 		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
-			if (status & CAL_HL_IRQ_MASK(i))
+			if (status & CAL_HL_IRQ_WDMA_START_MASK(i))
 				cal_irq_wdma_start(cal->ctx[i]);
 		}
 	}
diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
index 5c4f9e642185..93d9bf1f3c00 100644
--- a/drivers/media/platform/ti-vpe/cal_regs.h
+++ b/drivers/media/platform/ti-vpe/cal_regs.h
@@ -125,7 +125,8 @@
 #define CAL_HL_IRQ_EOI_LINE_NUMBER_READ0		0
 #define CAL_HL_IRQ_EOI_LINE_NUMBER_EOI0			0
 
-#define CAL_HL_IRQ_MASK(m)			BIT(m)
+#define CAL_HL_IRQ_WDMA_END_MASK(m)		BIT(m)
+#define CAL_HL_IRQ_WDMA_START_MASK(m)		BIT(m)
 
 #define CAL_HL_IRQ_OCPO_ERR_MASK		BIT(6)
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (11 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:32   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 14/28] media: ti-vpe: cal: catch VC errors Tomi Valkeinen
                   ` (14 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

The macros related to CAL_CSI2_VC_IRQ can be handled better by having
the VC number as a macro parameter.

Note that the macros are not used anywhere yet, so no other changes are
needed.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal_regs.h | 30 +++++-------------------
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
index 93d9bf1f3c00..ed658175a444 100644
--- a/drivers/media/platform/ti-vpe/cal_regs.h
+++ b/drivers/media/platform/ti-vpe/cal_regs.h
@@ -406,30 +406,12 @@
 #define CAL_CSI2_TIMING_STOP_STATE_X16_IO1_MASK		BIT(14)
 #define CAL_CSI2_TIMING_FORCE_RX_MODE_IO1_MASK		BIT(15)
 
-#define CAL_CSI2_VC_IRQ_FS_IRQ_0_MASK			BIT(0)
-#define CAL_CSI2_VC_IRQ_FE_IRQ_0_MASK			BIT(1)
-#define CAL_CSI2_VC_IRQ_LS_IRQ_0_MASK			BIT(2)
-#define CAL_CSI2_VC_IRQ_LE_IRQ_0_MASK			BIT(3)
-#define CAL_CSI2_VC_IRQ_CS_IRQ_0_MASK			BIT(4)
-#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_0_MASK	BIT(5)
-#define CAL_CSI2_VC_IRQ_FS_IRQ_1_MASK			BIT(8)
-#define CAL_CSI2_VC_IRQ_FE_IRQ_1_MASK			BIT(9)
-#define CAL_CSI2_VC_IRQ_LS_IRQ_1_MASK			BIT(10)
-#define CAL_CSI2_VC_IRQ_LE_IRQ_1_MASK			BIT(11)
-#define CAL_CSI2_VC_IRQ_CS_IRQ_1_MASK			BIT(12)
-#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_1_MASK	BIT(13)
-#define CAL_CSI2_VC_IRQ_FS_IRQ_2_MASK			BIT(16)
-#define CAL_CSI2_VC_IRQ_FE_IRQ_2_MASK			BIT(17)
-#define CAL_CSI2_VC_IRQ_LS_IRQ_2_MASK			BIT(18)
-#define CAL_CSI2_VC_IRQ_LE_IRQ_2_MASK			BIT(19)
-#define CAL_CSI2_VC_IRQ_CS_IRQ_2_MASK			BIT(20)
-#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_2_MASK	BIT(21)
-#define CAL_CSI2_VC_IRQ_FS_IRQ_3_MASK			BIT(24)
-#define CAL_CSI2_VC_IRQ_FE_IRQ_3_MASK			BIT(25)
-#define CAL_CSI2_VC_IRQ_LS_IRQ_3_MASK			BIT(26)
-#define CAL_CSI2_VC_IRQ_LE_IRQ_3_MASK			BIT(27)
-#define CAL_CSI2_VC_IRQ_CS_IRQ_3_MASK			BIT(28)
-#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_3_MASK	BIT(29)
+#define CAL_CSI2_VC_IRQ_FS_IRQ_MASK(n)			BIT(0 + (n * 8))
+#define CAL_CSI2_VC_IRQ_FE_IRQ_MASK(n)			BIT(1 + (n * 8))
+#define CAL_CSI2_VC_IRQ_LS_IRQ_MASK(n)			BIT(2 + (n * 8))
+#define CAL_CSI2_VC_IRQ_LE_IRQ_MASK(n)			BIT(3 + (n * 8))
+#define CAL_CSI2_VC_IRQ_CS_IRQ_MASK(n)			BIT(4 + (n * 8))
+#define CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(n)	BIT(5 + (n * 8))
 
 #define CAL_CSI2_CTX_DT_MASK		GENMASK(5, 0)
 #define CAL_CSI2_CTX_VC_MASK		GENMASK(7, 6)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 14/28] media: ti-vpe: cal: catch VC errors
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (12 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:38   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx Tomi Valkeinen
                   ` (13 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL driver currently ignores VC related errors. To help catch error
conditions, enable all the VC error interrupts and handle them in the
interrupt handler by printing an error.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 23 ++++++++++++++++----
 drivers/media/platform/ti-vpe/cal.c          |  9 ++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 974fcbb19547..0354f311c5d2 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -226,24 +226,39 @@ static void cal_camerarx_enable_irqs(struct cal_camerarx *phy)
 		CAL_CSI2_COMPLEXIO_IRQ_FIFO_OVR_MASK |
 		CAL_CSI2_COMPLEXIO_IRQ_SHORT_PACKET_MASK |
 		CAL_CSI2_COMPLEXIO_IRQ_ECC_NO_CORRECTION_MASK;
-
-	/* Enable CIO error IRQs. */
+	const u32 vc_err_mask =
+		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(0) |
+		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(1) |
+		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(2) |
+		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(3) |
+		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(0) |
+		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(1) |
+		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(2) |
+		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(3);
+
+	/* Enable CIO & VC error IRQs. */
 	cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
-		  CAL_HL_IRQ_CIO_MASK(phy->instance));
+		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));
 	cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance),
 		  cio_err_mask);
+	cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(phy->instance),
+		  vc_err_mask);
 }
 
 static void cal_camerarx_disable_irqs(struct cal_camerarx *phy)
 {
 	/* Disable CIO error irqs */
 	cal_write(phy->cal, CAL_HL_IRQENABLE_CLR(0),
-		  CAL_HL_IRQ_CIO_MASK(phy->instance));
+		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));
 	cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance), 0);
+	cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(phy->instance), 0);
 }
 
 static void cal_camerarx_ppi_enable(struct cal_camerarx *phy)
 {
+	cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
+			1, CAL_CSI2_PPI_CTRL_ECC_EN_MASK);
+
 	cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
 			1, CAL_CSI2_PPI_CTRL_IF_EN_MASK);
 }
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 0abcc83841c6..092041ddbcfb 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -577,6 +577,15 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
 				cal_write(cal, CAL_CSI2_COMPLEXIO_IRQSTATUS(i),
 					  cio_stat);
 			}
+
+			if (status & CAL_HL_IRQ_VC_MASK(i)) {
+				u32 vc_stat = cal_read(cal, CAL_CSI2_VC_IRQSTATUS(i));
+
+				dev_err_ratelimited(cal->dev,
+						    "CIO%u VC error: %#08x\n", i, vc_stat);
+
+				cal_write(cal, CAL_CSI2_VC_IRQSTATUS(i), vc_stat);
+			}
 		}
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (13 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 14/28] media: ti-vpe: cal: catch VC errors Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:46   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop Tomi Valkeinen
                   ` (12 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
will break an active capture), but the RESET_DONE bit never changes to
"reset is ongoing" state. Thus we always get a timeout.

Drop the wait, as it seems to achieve nothing.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 0354f311c5d2..245c601b992c 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
 
 static void cal_camerarx_stop(struct cal_camerarx *phy)
 {
-	unsigned int i;
 	int ret;
 
 	cal_camerarx_ppi_disable(phy);
@@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
 			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
 			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
 
-	/* Wait for power down completion */
-	for (i = 0; i < 10; i++) {
-		if (cal_read_field(phy->cal,
-				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
-				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
-		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
-			break;
-		usleep_range(1000, 1100);
-	}
-	phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Complex IO in Reset (%d) %s\n",
+	phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Complex IO in Reset\n",
 		phy->instance,
-		cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)), i,
-		(i >= 10) ? "(timeout)" : "");
+		cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)));
 
 	/* Disable the phy */
 	cal_camerarx_disable(phy);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (14 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:49   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically Tomi Valkeinen
                   ` (11 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Disable PPI and pix proc in cal_ctx_stop() to ensure they are not used
if the same context is used later on a different PHY or without pix
proc.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 092041ddbcfb..a6ca341c98bd 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -484,6 +484,12 @@ void cal_ctx_stop(struct cal_ctx *ctx)
 		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
 
 	ctx->dma.state = CAL_DMA_STOPPED;
+
+	/* Disable PPI context */
+	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
+
+	/* Disable pix proc */
+	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
 }
 
 /* ------------------------------------------------------------------
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (15 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 12:59   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field Tomi Valkeinen
                   ` (10 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL has 4 pixel processing units but the units are not needed e.g. for
metadata. As we could be capturing 4 pixel streams and 4 metadata
streams, i.e. using 8 DMA contexts, we cannot assign a pixel processing
unit to every DMA context. Instead we need to reserve a pixel processing
unit only when needed.

Add functions to reserve and release a pix proc unit, and use them in
cal_ctx_prepare/unprepare. Note that for the time being we still always
reserve a pix proc unit.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 44 +++++++++++++++++++++++++++--
 drivers/media/platform/ti-vpe/cal.h |  2 ++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index a6ca341c98bd..e397f59d3bbc 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -290,6 +290,37 @@ void cal_quickdump_regs(struct cal_dev *cal)
  * ------------------------------------------------------------------
  */
 
+#define CAL_MAX_PIX_PROC 4
+
+static int cal_reserve_pix_proc(struct cal_dev *cal)
+{
+	unsigned long ret;
+
+	spin_lock(&cal->v4l2_dev.lock);
+
+	ret = find_first_zero_bit(&cal->reserve_pix_proc_mask, CAL_MAX_PIX_PROC);
+
+	if (ret == CAL_MAX_PIX_PROC) {
+		spin_unlock(&cal->v4l2_dev.lock);
+		return -ENOSPC;
+	}
+
+	cal->reserve_pix_proc_mask |= BIT(ret);
+
+	spin_unlock(&cal->v4l2_dev.lock);
+
+	return ret;
+}
+
+static void cal_release_pix_proc(struct cal_dev *cal, unsigned int pix_proc_num)
+{
+	spin_lock(&cal->v4l2_dev.lock);
+
+	cal->reserve_pix_proc_mask &= ~BIT(pix_proc_num);
+
+	spin_unlock(&cal->v4l2_dev.lock);
+}
+
 static void cal_ctx_csi2_config(struct cal_ctx *ctx)
 {
 	u32 val;
@@ -433,12 +464,22 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
 
 int cal_ctx_prepare(struct cal_ctx *ctx)
 {
+	int ret;
+
+	ret = cal_reserve_pix_proc(ctx->cal);
+	if (ret < 0) {
+		ctx_err(ctx, "Failed to reserve pix proc: %d\n", ret);
+		return ret;
+	}
+
+	ctx->pix_proc = ret;
+
 	return 0;
 }
 
 void cal_ctx_unprepare(struct cal_ctx *ctx)
 {
-
+	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
 }
 
 void cal_ctx_start(struct cal_ctx *ctx)
@@ -872,7 +913,6 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
 	ctx->dma_ctx = inst;
 	ctx->ppi_ctx = inst;
 	ctx->cport = inst;
-	ctx->pix_proc = inst;
 
 	ret = cal_ctx_v4l2_init(ctx);
 	if (ret)
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index c34b843d2019..01e05e46e48d 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -188,6 +188,8 @@ struct cal_dev {
 	struct media_device	mdev;
 	struct v4l2_device	v4l2_dev;
 	struct v4l2_async_notifier notifier;
+
+	unsigned long reserve_pix_proc_mask;
 };
 
 /*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (16 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:00   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race Tomi Valkeinen
                   ` (9 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

We already have functions to reserve and release a pix proc unit, but we
always reserve such and the code expects the pix proc unit to be used.

Add a new field, 'use_pix_proc', to indicate if the pix prox unit has
been reserved and should be used. Use the flag to skip programming pix
proc unit when not needed.

Note that we still always set the use_pix_proc flag to true.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 10 +++++++---
 drivers/media/platform/ti-vpe/cal.h |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index e397f59d3bbc..a1d173bd4613 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -473,13 +473,15 @@ int cal_ctx_prepare(struct cal_ctx *ctx)
 	}
 
 	ctx->pix_proc = ret;
+	ctx->use_pix_proc = true;
 
 	return 0;
 }
 
 void cal_ctx_unprepare(struct cal_ctx *ctx)
 {
-	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
+	if (ctx->use_pix_proc)
+		cal_release_pix_proc(ctx->cal, ctx->pix_proc);
 }
 
 void cal_ctx_start(struct cal_ctx *ctx)
@@ -489,7 +491,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
 
 	/* Configure the CSI-2, pixel processing and write DMA contexts. */
 	cal_ctx_csi2_config(ctx);
-	cal_ctx_pix_proc_config(ctx);
+	if (ctx->use_pix_proc)
+		cal_ctx_pix_proc_config(ctx);
 	cal_ctx_wr_dma_config(ctx);
 
 	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
@@ -530,7 +533,8 @@ void cal_ctx_stop(struct cal_ctx *ctx)
 	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
 
 	/* Disable pix proc */
-	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
+	if (ctx->use_pix_proc)
+		cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
 }
 
 /* ------------------------------------------------------------------
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 01e05e46e48d..409b7276a1fa 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -223,6 +223,8 @@ struct cal_ctx {
 	u8			cport;
 	u8			ppi_ctx;
 	u8			pix_proc;
+
+	bool use_pix_proc;
 };
 
 extern unsigned int cal_debug;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (17 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:04   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx Tomi Valkeinen
                   ` (8 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

I have not noticed any errors due to this, but the DMA configuration
looks racy. Setting the DMA mode bitfield in CAL_WR_DMA_CTRL supposedly
enables the DMA. However, the driver currently a) continues configuring
the DMA after setting the mode, and b) enables the DMA interrupts only
after setting the mode.

This probably doesn't cause any issues as there should be no data coming
in to the DMA yet, but it's still better to fix this.

Add a new function, cal_ctx_wr_dma_enable(), to set the DMA mode field,
and call that function only after the DMA config and the irq enabling
has been done.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index a1d173bd4613..0fef892854ef 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -409,8 +409,6 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
 		      CAL_WR_DMA_CTRL_YSIZE_MASK);
 	cal_set_field(&val, CAL_WR_DMA_CTRL_DTAG_PIX_DAT,
 		      CAL_WR_DMA_CTRL_DTAG_MASK);
-	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
-		      CAL_WR_DMA_CTRL_MODE_MASK);
 	cal_set_field(&val, CAL_WR_DMA_CTRL_PATTERN_LINEAR,
 		      CAL_WR_DMA_CTRL_PATTERN_MASK);
 	cal_set_field(&val, 1, CAL_WR_DMA_CTRL_STALL_RD_MASK);
@@ -442,6 +440,15 @@ void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
 	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->dma_ctx), addr);
 }
 
+static void cal_ctx_wr_dma_enable(struct cal_ctx *ctx)
+{
+	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
+
+	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
+		      CAL_WR_DMA_CTRL_MODE_MASK);
+	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
+}
+
 static void cal_ctx_wr_dma_disable(struct cal_ctx *ctx)
 {
 	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
@@ -500,6 +507,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
 		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
 	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
 		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
+
+	cal_ctx_wr_dma_enable(ctx);
 }
 
 void cal_ctx_stop(struct cal_ctx *ctx)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (18 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:06   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling Tomi Valkeinen
                   ` (7 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

In preparation for supporting multiple virtual channels and datatypes,
add vc and datatype fields to cal_ctx, initialize them to the currently
used values, and use those fields when writing to the register.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 6 ++++--
 drivers/media/platform/ti-vpe/cal.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 0fef892854ef..91d2139adc9b 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -335,8 +335,8 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
 	 *  0x2A: RAW8   1 pixel  = 1 byte
 	 *  0x1E: YUV422 2 pixels = 4 bytes
 	 */
-	cal_set_field(&val, 0x1, CAL_CSI2_CTX_DT_MASK);
-	cal_set_field(&val, 0, CAL_CSI2_CTX_VC_MASK);
+	cal_set_field(&val, ctx->datatype, CAL_CSI2_CTX_DT_MASK);
+	cal_set_field(&val, ctx->vc, CAL_CSI2_CTX_VC_MASK);
 	cal_set_field(&val, ctx->v_fmt.fmt.pix.height, CAL_CSI2_CTX_LINES_MASK);
 	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
 	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
@@ -926,6 +926,8 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
 	ctx->dma_ctx = inst;
 	ctx->ppi_ctx = inst;
 	ctx->cport = inst;
+	ctx->vc = 0;
+	ctx->datatype = 1;	/* datatype filter disabled */
 
 	ret = cal_ctx_v4l2_init(ctx);
 	if (ret)
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 409b7276a1fa..8aa93c92193a 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -223,6 +223,8 @@ struct cal_ctx {
 	u8			cport;
 	u8			ppi_ctx;
 	u8			pix_proc;
+	u8			vc;
+	u8			datatype;
 
 	bool use_pix_proc;
 };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (19 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:09   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE Tomi Valkeinen
                   ` (6 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

cal_ctx_v4l2_register() returns an error code, but the returned error
code is not handled anywhere. However, we can't really even handle the
error in any proper way, so lets just drop the return value and make
sure all error paths have an error print.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c | 16 ++++++++--------
 drivers/media/platform/ti-vpe/cal.h       |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 064efdc31b28..ea9b13c16a06 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -864,14 +864,16 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
 	return 0;
 }
 
-int cal_ctx_v4l2_register(struct cal_ctx *ctx)
+void cal_ctx_v4l2_register(struct cal_ctx *ctx)
 {
 	struct video_device *vfd = &ctx->vdev;
 	int ret;
 
 	ret = cal_ctx_v4l2_init_formats(ctx);
-	if (ret)
-		return ret;
+	if (ret) {
+		ctx_err(ctx, "Failed to init formats: %d\n", ret);
+		return;
+	}
 
 	if (!cal_mc_api) {
 		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
@@ -880,14 +882,14 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
 					    NULL, true);
 		if (ret < 0) {
 			ctx_err(ctx, "Failed to add source ctrl handler\n");
-			return ret;
+			return;
 		}
 	}
 
 	ret = video_register_device(vfd, VFL_TYPE_VIDEO, cal_video_nr);
 	if (ret < 0) {
 		ctx_err(ctx, "Failed to register video device\n");
-		return ret;
+		return;
 	}
 
 	ret = media_create_pad_link(&ctx->phy->subdev.entity,
@@ -899,13 +901,11 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
 		ctx_err(ctx, "Failed to create media link for context %u\n",
 			ctx->dma_ctx);
 		video_unregister_device(vfd);
-		return ret;
+		return;
 	}
 
 	ctx_info(ctx, "V4L2 device registered as %s\n",
 		 video_device_node_name(vfd));
-
-	return 0;
 }
 
 void cal_ctx_v4l2_unregister(struct cal_ctx *ctx)
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 8aa93c92193a..ad7d26c803eb 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -310,7 +310,7 @@ void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr);
 void cal_ctx_start(struct cal_ctx *ctx);
 void cal_ctx_stop(struct cal_ctx *ctx);
 
-int cal_ctx_v4l2_register(struct cal_ctx *ctx);
+void cal_ctx_v4l2_register(struct cal_ctx *ctx);
 void cal_ctx_v4l2_unregister(struct cal_ctx *ctx);
 int cal_ctx_v4l2_init(struct cal_ctx *ctx);
 void cal_ctx_v4l2_cleanup(struct cal_ctx *ctx);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (20 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:14   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment Tomi Valkeinen
                   ` (5 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

cal_camerarx_sd_set_fmt() accepts any value for the format field, but
there should be no reason to have any other value accepted than
V4L2_FIELD_NONE. So set the field always to V4L2_FIELD_NONE.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 245c601b992c..880261d53a1d 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -702,10 +702,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
 	if (!fmtinfo)
 		fmtinfo = &cal_formats[0];
 
-	/*
-	 * Clamp the size, update the code. The field and colorspace are
-	 * accepted as-is.
-	 */
+	/* Clamp the size, update the code. The colorspace is accepted as-is. */
 	bpp = ALIGN(fmtinfo->bpp, 8);
 
 	format->format.width = clamp_t(unsigned int, format->format.width,
@@ -715,6 +712,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
 					CAL_MIN_HEIGHT_LINES,
 					CAL_MAX_HEIGHT_LINES);
 	format->format.code = fmtinfo->code;
+	format->format.field = V4L2_FIELD_NONE;
 
 	/* Store the format and propagate it to the source pad. */
 	fmt = cal_camerarx_get_pad_format(phy, cfg, CAL_CAMERARX_PAD_SINK,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (21 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:14   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap Tomi Valkeinen
                   ` (4 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Fix a typo in a comment in cal_camerarx_sd_set_fmt().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 880261d53a1d..25f4692d210e 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -695,7 +695,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
 		return cal_camerarx_sd_get_fmt(sd, cfg, format);
 
 	/*
-	 * Default to the first format is the requested media bus code isn't
+	 * Default to the first format if the requested media bus code isn't
 	 * supported.
 	 */
 	fmtinfo = cal_format_by_code(format->format.code);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (22 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:17   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_* Tomi Valkeinen
                   ` (3 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

Commit e5b6b07a1b45dd9d19bec1fa1d60750b0fcf2fb0 ("media: v4l2: Extend
VIDIOC_ENUM_FMT to support MC-centric devices") added support to
enumerate formats based in mbus-code.

Add this feature to cal driver.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index ea9b13c16a06..1d9c0fce4b03 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -437,13 +437,28 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
 static int cal_mc_enum_fmt_vid_cap(struct file *file, void  *priv,
 				   struct v4l2_fmtdesc *f)
 {
+	unsigned int i;
+	unsigned int idx;
+
 	if (f->index >= cal_num_formats)
 		return -EINVAL;
 
-	f->pixelformat = cal_formats[f->index].fourcc;
-	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	idx = 0;
 
-	return 0;
+	for (i = 0; i < cal_num_formats; ++i) {
+		if (f->mbus_code && cal_formats[i].code != f->mbus_code)
+			continue;
+
+		if (idx == f->index) {
+			f->pixelformat = cal_formats[i].fourcc;
+			f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+			return 0;
+		}
+
+		idx++;
+	}
+
+	return -EINVAL;
 }
 
 static void cal_mc_try_fmt(struct cal_ctx *ctx, struct v4l2_format *f,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_*
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (23 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:18   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode Tomi Valkeinen
                   ` (2 subsequent siblings)
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

To make it more obvious if the function in question is dealing with
media-controller API or the legacy API, rename legacy API functions to
cal_legacy_*.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c | 46 +++++++++++------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 1d9c0fce4b03..0494cd04b9a5 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -102,7 +102,7 @@ static const struct cal_format_info *find_format_by_code(struct cal_ctx *ctx,
 	return NULL;
 }
 
-static int cal_enum_fmt_vid_cap(struct file *file, void  *priv,
+static int cal_legacy_enum_fmt_vid_cap(struct file *file, void  *priv,
 				struct v4l2_fmtdesc *f)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
@@ -189,7 +189,7 @@ static void cal_calc_format_size(struct cal_ctx *ctx,
 		f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
 }
 
-static int cal_try_fmt_vid_cap(struct file *file, void *priv,
+static int cal_legacy_try_fmt_vid_cap(struct file *file, void *priv,
 			       struct v4l2_format *f)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
@@ -249,7 +249,7 @@ static int cal_try_fmt_vid_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int cal_s_fmt_vid_cap(struct file *file, void *priv,
+static int cal_legacy_s_fmt_vid_cap(struct file *file, void *priv,
 			     struct v4l2_format *f)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
@@ -266,7 +266,7 @@ static int cal_s_fmt_vid_cap(struct file *file, void *priv,
 		return -EBUSY;
 	}
 
-	ret = cal_try_fmt_vid_cap(file, priv, f);
+	ret = cal_legacy_try_fmt_vid_cap(file, priv, f);
 	if (ret < 0)
 		return ret;
 
@@ -300,7 +300,7 @@ static int cal_s_fmt_vid_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int cal_enum_framesizes(struct file *file, void *fh,
+static int cal_legacy_enum_framesizes(struct file *file, void *fh,
 			       struct v4l2_frmsizeenum *fsize)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
@@ -337,7 +337,7 @@ static int cal_enum_framesizes(struct file *file, void *fh,
 	return 0;
 }
 
-static int cal_enum_input(struct file *file, void *priv,
+static int cal_legacy_enum_input(struct file *file, void *priv,
 			  struct v4l2_input *inp)
 {
 	if (inp->index > 0)
@@ -348,19 +348,19 @@ static int cal_enum_input(struct file *file, void *priv,
 	return 0;
 }
 
-static int cal_g_input(struct file *file, void *priv, unsigned int *i)
+static int cal_legacy_g_input(struct file *file, void *priv, unsigned int *i)
 {
 	*i = 0;
 	return 0;
 }
 
-static int cal_s_input(struct file *file, void *priv, unsigned int i)
+static int cal_legacy_s_input(struct file *file, void *priv, unsigned int i)
 {
 	return i > 0 ? -EINVAL : 0;
 }
 
 /* timeperframe is arbitrary and continuous */
-static int cal_enum_frameintervals(struct file *file, void *priv,
+static int cal_legacy_enum_frameintervals(struct file *file, void *priv,
 				   struct v4l2_frmivalenum *fival)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
@@ -388,27 +388,27 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
 	return 0;
 }
 
-static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+static int cal_legacy_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
 
 	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->source, a);
 }
 
-static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+static int cal_legacy_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
 	struct cal_ctx *ctx = video_drvdata(file);
 
 	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->source, a);
 }
 
-static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
+static const struct v4l2_ioctl_ops cal_ioctl_legacy_ops = {
 	.vidioc_querycap      = cal_querycap,
-	.vidioc_enum_fmt_vid_cap  = cal_enum_fmt_vid_cap,
+	.vidioc_enum_fmt_vid_cap  = cal_legacy_enum_fmt_vid_cap,
 	.vidioc_g_fmt_vid_cap     = cal_g_fmt_vid_cap,
-	.vidioc_try_fmt_vid_cap   = cal_try_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap     = cal_s_fmt_vid_cap,
-	.vidioc_enum_framesizes   = cal_enum_framesizes,
+	.vidioc_try_fmt_vid_cap   = cal_legacy_try_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap     = cal_legacy_s_fmt_vid_cap,
+	.vidioc_enum_framesizes   = cal_legacy_enum_framesizes,
 	.vidioc_reqbufs       = vb2_ioctl_reqbufs,
 	.vidioc_create_bufs   = vb2_ioctl_create_bufs,
 	.vidioc_prepare_buf   = vb2_ioctl_prepare_buf,
@@ -416,17 +416,17 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
 	.vidioc_qbuf          = vb2_ioctl_qbuf,
 	.vidioc_dqbuf         = vb2_ioctl_dqbuf,
 	.vidioc_expbuf        = vb2_ioctl_expbuf,
-	.vidioc_enum_input    = cal_enum_input,
-	.vidioc_g_input       = cal_g_input,
-	.vidioc_s_input       = cal_s_input,
-	.vidioc_enum_frameintervals = cal_enum_frameintervals,
+	.vidioc_enum_input    = cal_legacy_enum_input,
+	.vidioc_g_input       = cal_legacy_g_input,
+	.vidioc_s_input       = cal_legacy_s_input,
+	.vidioc_enum_frameintervals = cal_legacy_enum_frameintervals,
 	.vidioc_streamon      = vb2_ioctl_streamon,
 	.vidioc_streamoff     = vb2_ioctl_streamoff,
 	.vidioc_log_status    = v4l2_ctrl_log_status,
 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
-	.vidioc_g_parm		= cal_g_parm,
-	.vidioc_s_parm		= cal_s_parm,
+	.vidioc_g_parm		= cal_legacy_g_parm,
+	.vidioc_s_parm		= cal_legacy_s_parm,
 };
 
 /* ------------------------------------------------------------------
@@ -966,7 +966,7 @@ int cal_ctx_v4l2_init(struct cal_ctx *ctx)
 	vfd->queue = q;
 	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->dma_ctx);
 	vfd->release = video_device_release_empty;
-	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_video_ops;
+	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_legacy_ops;
 	vfd->lock = &ctx->mutex;
 	video_set_drvdata(vfd, ctx);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (24 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_* Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:21   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo Tomi Valkeinen
  2021-04-12 11:34 ` [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts Tomi Valkeinen
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

CAL driver enumerates mbus codes in the connected subdev to create a
list of supported formats reported to userspace, and initializes
ctx->v_fmt and ctx->fmtinfo to one of those formats.

This works fine for legacy mode, but is not correct for MC mode, and the
list is not even used in MC mode.

Fix this by adding a new function, cal_ctx_v4l2_init_mc_format, which
only initializes ctx->v_fmt and ctx->fmtinfo to a default value.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-video.c | 45 ++++++++++++++++++++---
 drivers/media/platform/ti-vpe/cal.h       |  2 +-
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 0494cd04b9a5..95066cca128a 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -879,26 +879,59 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
 	return 0;
 }
 
+static int cal_ctx_v4l2_init_mc_format(struct cal_ctx *ctx)
+{
+	const struct cal_format_info *fmtinfo;
+	struct v4l2_pix_format *pix_fmt = &ctx->v_fmt.fmt.pix;
+
+	fmtinfo = cal_format_by_code(MEDIA_BUS_FMT_UYVY8_2X8);
+	if (!fmtinfo)
+		return -EINVAL;
+
+	pix_fmt->width = 640;
+	pix_fmt->height = 480;
+	pix_fmt->field = V4L2_FIELD_NONE;
+	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
+	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
+	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
+	pix_fmt->pixelformat = fmtinfo->fourcc;
+
+	ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+	/* Save current format */
+	cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
+	ctx->fmtinfo = fmtinfo;
+
+	return 0;
+}
+
 void cal_ctx_v4l2_register(struct cal_ctx *ctx)
 {
 	struct video_device *vfd = &ctx->vdev;
 	int ret;
 
-	ret = cal_ctx_v4l2_init_formats(ctx);
-	if (ret) {
-		ctx_err(ctx, "Failed to init formats: %d\n", ret);
-		return;
-	}
-
 	if (!cal_mc_api) {
 		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
 
+		ret = cal_ctx_v4l2_init_formats(ctx);
+		if (ret) {
+			ctx_err(ctx, "Failed to init formats: %d\n", ret);
+			return;
+		}
+
 		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
 					    NULL, true);
 		if (ret < 0) {
 			ctx_err(ctx, "Failed to add source ctrl handler\n");
 			return;
 		}
+	} else {
+		ret = cal_ctx_v4l2_init_mc_format(ctx);
+		if (ret) {
+			ctx_err(ctx, "Failed to init format: %d\n", ret);
+			return;
+		}
 	}
 
 	ret = video_register_device(vfd, VFL_TYPE_VIDEO, cal_video_nr);
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index ad7d26c803eb..c941d2aec79f 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -213,7 +213,7 @@ struct cal_ctx {
 	/* Used to store current pixel format */
 	struct v4l2_format	v_fmt;
 
-	/* Current subdev enumerated format */
+	/* Current subdev enumerated format (legacy) */
 	const struct cal_format_info	**active_fmt;
 	unsigned int		num_active_fmt;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (25 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:24   ` Laurent Pinchart
  2021-04-12 11:34 ` [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts Tomi Valkeinen
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

struct cal_camerarx has fmtinfo field which is used to point to the
current active input format. The only place where the field is used is
cal_camerarx_get_ext_link_freq().

With multiple streams the whole concept of single input format is not
valid anymore, so lets remove the field by looking up the format in
cal_camerarx_get_ext_link_freq(), making it easier to handle the
multistream-case in the following patches.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 12 ++++++++----
 drivers/media/platform/ti-vpe/cal.h          |  1 -
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 25f4692d210e..efe6513d69e8 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -49,8 +49,15 @@ static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
 {
 	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = &phy->endpoint.bus.mipi_csi2;
 	u32 num_lanes = mipi_csi2->num_data_lanes;
-	u32 bpp = phy->fmtinfo->bpp;
+	u32 bpp;
 	s64 freq;
+	const struct cal_format_info *fmtinfo;
+
+	fmtinfo = cal_format_by_code(phy->formats[CAL_CAMERARX_PAD_SINK].code);
+	if (!fmtinfo)
+		return -EINVAL;
+
+	bpp = fmtinfo->bpp;
 
 	freq = v4l2_get_link_freq(phy->source->ctrl_handler, bpp, 2 * num_lanes);
 	if (freq < 0) {
@@ -723,9 +730,6 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
 					  format->which);
 	*fmt = format->format;
 
-	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
-		phy->fmtinfo = fmtinfo;
-
 	return 0;
 }
 
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index c941d2aec79f..7f35ad5ceac2 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -163,7 +163,6 @@ struct cal_camerarx {
 	struct v4l2_subdev	subdev;
 	struct media_pad	pads[2];
 	struct v4l2_mbus_framefmt	formats[2];
-	const struct cal_format_info	*fmtinfo;
 };
 
 struct cal_dev {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts
  2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
                   ` (26 preceding siblings ...)
  2021-04-12 11:34 ` [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo Tomi Valkeinen
@ 2021-04-12 11:34 ` Tomi Valkeinen
  2021-04-18 13:29   ` Laurent Pinchart
  27 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 11:34 UTC (permalink / raw)
  To: Benoit Parrot, Laurent Pinchart, Pratyush Yadav, Lokesh Vutla,
	linux-media
  Cc: Tomi Valkeinen

The current driver only ever needs 2 DMA contexts (one per PHY), but we
need to use more of the 8 contexts to add support for multiple streams.

Change the code so that we allocate DMA contexts as needed, which at
this time is 1 per PHY, but could be up to 8.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal.c | 38 ++++++++++++-----------------
 drivers/media/platform/ti-vpe/cal.h |  5 ++--
 2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 91d2139adc9b..781fb14f4c7a 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -657,7 +657,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
 		/* Clear Interrupt status */
 		cal_write(cal, CAL_HL_IRQSTATUS(1), status);
 
-		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
+		for (i = 0; i < cal->num_contexts; ++i) {
 			if (status & CAL_HL_IRQ_WDMA_END_MASK(i))
 				cal_irq_wdma_end(cal->ctx[i]);
 		}
@@ -671,7 +671,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
 		/* Clear Interrupt status */
 		cal_write(cal, CAL_HL_IRQSTATUS(2), status);
 
-		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
+		for (i = 0; i < cal->num_contexts; ++i) {
 			if (status & CAL_HL_IRQ_WDMA_START_MASK(i))
 				cal_irq_wdma_start(cal->ctx[i]);
 		}
@@ -741,10 +741,8 @@ static int cal_async_notifier_complete(struct v4l2_async_notifier *notifier)
 	unsigned int i;
 	int ret = 0;
 
-	for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
-		if (cal->ctx[i])
-			cal_ctx_v4l2_register(cal->ctx[i]);
-	}
+	for (i = 0; i < cal->num_contexts; ++i)
+		cal_ctx_v4l2_register(cal->ctx[i]);
 
 	if (cal_mc_api)
 		ret = v4l2_device_register_subdev_nodes(&cal->v4l2_dev);
@@ -846,10 +844,8 @@ static void cal_media_unregister(struct cal_dev *cal)
 	unsigned int i;
 
 	/* Unregister all the V4L2 video devices. */
-	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
-		if (cal->ctx[i])
-			cal_ctx_v4l2_unregister(cal->ctx[i]);
-	}
+	for (i = 0; i < cal->num_contexts; i++)
+		cal_ctx_v4l2_unregister(cal->ctx[i]);
 
 	cal_async_notifier_unregister(cal);
 	media_device_unregister(&cal->mdev);
@@ -896,10 +892,8 @@ static void cal_media_cleanup(struct cal_dev *cal)
 {
 	unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
-		if (cal->ctx[i])
-			cal_ctx_v4l2_cleanup(cal->ctx[i]);
-	}
+	for (i = 0; i < cal->num_contexts; i++)
+		cal_ctx_v4l2_cleanup(cal->ctx[i]);
 
 	v4l2_device_unregister(&cal->v4l2_dev);
 	media_device_cleanup(&cal->mdev);
@@ -1048,7 +1042,6 @@ static int cal_init_camerarx_regmap(struct cal_dev *cal)
 static int cal_probe(struct platform_device *pdev)
 {
 	struct cal_dev *cal;
-	struct cal_ctx *ctx;
 	bool connected = false;
 	unsigned int i;
 	int ret;
@@ -1132,12 +1125,14 @@ static int cal_probe(struct platform_device *pdev)
 		if (!cal->phy[i]->source_node)
 			continue;
 
-		cal->ctx[i] = cal_ctx_create(cal, i);
-		if (!cal->ctx[i]) {
-			cal_err(cal, "Failed to create context %u\n", i);
+		cal->ctx[cal->num_contexts] = cal_ctx_create(cal, i);
+		if (!cal->ctx[cal->num_contexts]) {
+			cal_err(cal, "Failed to create context %u\n", cal->num_contexts);
 			ret = -ENODEV;
 			goto error_context;
 		}
+
+		cal->num_contexts++;
 	}
 
 	/* Register the media device. */
@@ -1148,11 +1143,8 @@ static int cal_probe(struct platform_device *pdev)
 	return 0;
 
 error_context:
-	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
-		ctx = cal->ctx[i];
-		if (ctx)
-			cal_ctx_v4l2_cleanup(ctx);
-	}
+	for (i = 0; i < cal->num_contexts; i++)
+		cal_ctx_v4l2_cleanup(cal->ctx[i]);
 
 error_camerarx:
 	for (i = 0; i < cal->data->num_csi2_phy; i++)
diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
index 7f35ad5ceac2..783876d7cf40 100644
--- a/drivers/media/platform/ti-vpe/cal.h
+++ b/drivers/media/platform/ti-vpe/cal.h
@@ -29,7 +29,7 @@
 #include <media/videobuf2-v4l2.h>
 
 #define CAL_MODULE_NAME			"cal"
-#define CAL_NUM_CONTEXT			2
+#define CAL_MAX_NUM_CONTEXT		8
 #define CAL_NUM_CSI2_PORTS		2
 
 /*
@@ -182,7 +182,8 @@ struct cal_dev {
 	/* Camera Core Module handle */
 	struct cal_camerarx	*phy[CAL_NUM_CSI2_PORTS];
 
-	struct cal_ctx		*ctx[CAL_NUM_CONTEXT];
+	u32 num_contexts;
+	struct cal_ctx		*ctx[CAL_MAX_NUM_CONTEXT];
 
 	struct media_device	mdev;
 	struct v4l2_device	v4l2_dev;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 84+ messages in thread

* Re: [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API
  2021-04-12 11:34 ` [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API Tomi Valkeinen
@ 2021-04-17 23:01   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-17 23:01 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:30PM +0300, Tomi Valkeinen wrote:
> v4l2-compliance complains about g/s_parm when using the non-MC API. Fix
> it by adding the functions and just call v4l2_s/g_parm_cap for the
> phy subdev.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal-video.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 7b7436a355ee..86d7cdd27224 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -388,6 +388,20 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
>  	return 0;
>  }
>  
> +static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct cal_ctx *ctx = video_drvdata(file);
> +
> +	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->sensor, a);
> +}
> +
> +static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct cal_ctx *ctx = video_drvdata(file);
> +
> +	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->sensor, a);
> +}
> +
>  static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
>  	.vidioc_querycap      = cal_querycap,
>  	.vidioc_enum_fmt_vid_cap  = cal_enum_fmt_vid_cap,
> @@ -411,6 +425,8 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
>  	.vidioc_log_status    = v4l2_ctrl_log_status,
>  	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
>  	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
> +	.vidioc_g_parm		= cal_g_parm,
> +	.vidioc_s_parm		= cal_s_parm,
>  };
>  
>  /* ------------------------------------------------------------------

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create
  2021-04-12 11:34 ` [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create Tomi Valkeinen
@ 2021-04-17 23:05   ` Laurent Pinchart
  2021-04-19  8:24     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-17 23:05 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:31PM +0300, Tomi Valkeinen wrote:
> cal_camerarx_create() doesn't handle error returned from
> cal_camerarx_sd_init_cfg()

This looks good.

> and it always runs all the cleanup/free
> functions in the error code path. The latter doesn't cause any issues at
> the moment as media_entity_cleanup() is an empty function.

But this was by design. Do you think we could keep
media_entity_cleanup() idempotent ? That would simplify error paths (as
shown here).

> Fix the error handling.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index cbe6114908de..820fb483c402 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -812,7 +812,7 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
>  	if (IS_ERR(phy->base)) {
>  		cal_err(cal, "failed to ioremap\n");
>  		ret = PTR_ERR(phy->base);
> -		goto error;
> +		goto err_free_phy;
>  	}
>  
>  	cal_dbg(1, cal, "ioresource %s at %pa - %pa\n",
> @@ -820,11 +820,11 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
>  
>  	ret = cal_camerarx_regmap_init(cal, phy);
>  	if (ret)
> -		goto error;
> +		goto err_free_phy;
>  
>  	ret = cal_camerarx_parse_dt(phy);
>  	if (ret)
> -		goto error;
> +		goto err_free_phy;
>  
>  	/* Initialize the V4L2 subdev and media entity. */
>  	sd = &phy->subdev;
> @@ -840,18 +840,21 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
>  	ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(phy->pads),
>  				     phy->pads);
>  	if (ret)
> -		goto error;
> +		goto err_entity_cleanup;
>  
> -	cal_camerarx_sd_init_cfg(sd, NULL);
> +	ret = cal_camerarx_sd_init_cfg(sd, NULL);
> +	if (ret)
> +		goto err_entity_cleanup;
>  
>  	ret = v4l2_device_register_subdev(&cal->v4l2_dev, sd);
>  	if (ret)
> -		goto error;
> +		goto err_entity_cleanup;
>  
>  	return phy;
>  
> -error:
> +err_entity_cleanup:
>  	media_entity_cleanup(&phy->subdev.entity);
> +err_free_phy:
>  	kfree(phy);
>  	return ERR_PTR(ret);
>  }

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source"
  2021-04-12 11:34 ` [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source" Tomi Valkeinen
@ 2021-04-17 23:18   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-17 23:18 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:33PM +0300, Tomi Valkeinen wrote:
> CAL driver uses "sensor" name to refer to the subdev connected to CAL.
> As the subdev can also be a bridge, the naming is misleading and might
> cause the reader to think it refers to the actual sensor at the end of
> the pipeline.
> 
> Rename "sensor" to "source".
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 34 ++++++++++----------
>  drivers/media/platform/ti-vpe/cal-video.c    | 26 +++++++--------
>  drivers/media/platform/ti-vpe/cal.c          | 20 ++++++------
>  drivers/media/platform/ti-vpe/cal.h          |  6 ++--
>  4 files changed, 43 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 820fb483c402..603405824738 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -50,15 +50,15 @@ static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy)
>  	struct v4l2_ctrl *ctrl;
>  	s64 rate;
>  
> -	ctrl = v4l2_ctrl_find(phy->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE);
> +	ctrl = v4l2_ctrl_find(phy->source->ctrl_handler, V4L2_CID_PIXEL_RATE);
>  	if (!ctrl) {
>  		phy_err(phy, "no pixel rate control in subdev: %s\n",
> -			phy->sensor->name);
> +			phy->source->name);
>  		return -EPIPE;
>  	}
>  
>  	rate = v4l2_ctrl_g_ctrl_int64(ctrl);
> -	phy_dbg(3, phy, "sensor Pixel Rate: %llu\n", rate);
> +	phy_dbg(3, phy, "Source Pixel Rate: %llu\n", rate);
>  
>  	return rate;
>  }
> @@ -279,7 +279,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>  	if (external_rate < 0)
>  		return external_rate;
>  
> -	ret = v4l2_subdev_call(phy->sensor, core, s_power, 1);
> +	ret = v4l2_subdev_call(phy->source, core, s_power, 1);
>  	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
>  		phy_err(phy, "power on failed in subdev\n");
>  		return ret;
> @@ -311,7 +311,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>  	 * 2. CSI PHY and link initialization sequence.
>  	 *
>  	 *    a. Deassert the CSI-2 PHY reset. Do not wait for reset completion
> -	 *       at this point, as it requires the external sensor to send the
> +	 *       at this point, as it requires the external source to send the
>  	 *       CSI-2 HS clock.
>  	 */
>  	cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> @@ -370,12 +370,12 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>  	cal_camerarx_power(phy, true);
>  
>  	/*
> -	 * Start the sensor to enable the CSI-2 HS clock. We can now wait for
> +	 * Start the source to enable the CSI-2 HS clock. We can now wait for
>  	 * CSI-2 PHY reset to complete.
>  	 */
> -	ret = v4l2_subdev_call(phy->sensor, video, s_stream, 1);
> +	ret = v4l2_subdev_call(phy->source, video, s_stream, 1);
>  	if (ret) {
> -		v4l2_subdev_call(phy->sensor, core, s_power, 0);
> +		v4l2_subdev_call(phy->source, core, s_power, 0);
>  		cal_camerarx_disable_irqs(phy);
>  		phy_err(phy, "stream on failed in subdev\n");
>  		return ret;
> @@ -435,10 +435,10 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
>  	/* Disable the phy */
>  	cal_camerarx_disable(phy);
>  
> -	if (v4l2_subdev_call(phy->sensor, video, s_stream, 0))
> +	if (v4l2_subdev_call(phy->source, video, s_stream, 0))
>  		phy_err(phy, "stream off failed in subdev\n");
>  
> -	ret = v4l2_subdev_call(phy->sensor, core, s_power, 0);
> +	ret = v4l2_subdev_call(phy->source, core, s_power, 0);
>  	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
>  		phy_err(phy, "power off failed in subdev\n");
>  }
> @@ -558,16 +558,16 @@ static int cal_camerarx_parse_dt(struct cal_camerarx *phy)
>  		endpoint->bus.mipi_csi2.flags);
>  
>  	/* Retrieve the connected device and store it for later use. */
> -	phy->sensor_ep_node = of_graph_get_remote_endpoint(ep_node);
> -	phy->sensor_node = of_graph_get_port_parent(phy->sensor_ep_node);
> -	if (!phy->sensor_node) {
> +	phy->source_ep_node = of_graph_get_remote_endpoint(ep_node);
> +	phy->source_node = of_graph_get_port_parent(phy->source_ep_node);
> +	if (!phy->source_node) {
>  		phy_dbg(3, phy, "Can't get remote parent\n");
> -		of_node_put(phy->sensor_ep_node);
> +		of_node_put(phy->source_ep_node);
>  		ret = -EINVAL;
>  		goto done;
>  	}
>  
> -	phy_dbg(1, phy, "Found connected device %pOFn\n", phy->sensor_node);
> +	phy_dbg(1, phy, "Found connected device %pOFn\n", phy->source_node);
>  
>  done:
>  	of_node_put(ep_node);
> @@ -866,7 +866,7 @@ void cal_camerarx_destroy(struct cal_camerarx *phy)
>  
>  	v4l2_device_unregister_subdev(&phy->subdev);
>  	media_entity_cleanup(&phy->subdev.entity);
> -	of_node_put(phy->sensor_ep_node);
> -	of_node_put(phy->sensor_node);
> +	of_node_put(phy->source_ep_node);
> +	of_node_put(phy->source_node);
>  	kfree(phy);
>  }
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 86d7cdd27224..cf603cc9114c 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -128,7 +128,7 @@ static int __subdev_get_format(struct cal_ctx *ctx,
>  	sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>  	sd_fmt.pad = 0;
>  
> -	ret = v4l2_subdev_call(ctx->phy->sensor, pad, get_fmt, NULL, &sd_fmt);
> +	ret = v4l2_subdev_call(ctx->phy->source, pad, get_fmt, NULL, &sd_fmt);
>  	if (ret)
>  		return ret;
>  
> @@ -151,7 +151,7 @@ static int __subdev_set_format(struct cal_ctx *ctx,
>  	sd_fmt.pad = 0;
>  	*mbus_fmt = *fmt;
>  
> -	ret = v4l2_subdev_call(ctx->phy->sensor, pad, set_fmt, NULL, &sd_fmt);
> +	ret = v4l2_subdev_call(ctx->phy->source, pad, set_fmt, NULL, &sd_fmt);
>  	if (ret)
>  		return ret;
>  
> @@ -216,7 +216,7 @@ static int cal_try_fmt_vid_cap(struct file *file, void *priv,
>  	fse.code = fmtinfo->code;
>  	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>  	for (fse.index = 0; ; fse.index++) {
> -		ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size,
> +		ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size,
>  				       NULL, &fse);
>  		if (ret)
>  			break;
> @@ -321,7 +321,7 @@ static int cal_enum_framesizes(struct file *file, void *fh,
>  	fse.code = fmtinfo->code;
>  	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
>  
> -	ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_size, NULL,
> +	ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_size, NULL,
>  			       &fse);
>  	if (ret)
>  		return ret;
> @@ -378,7 +378,7 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
>  		return -EINVAL;
>  
>  	fie.code = fmtinfo->code;
> -	ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_frame_interval,
> +	ret = v4l2_subdev_call(ctx->phy->source, pad, enum_frame_interval,
>  			       NULL, &fie);
>  	if (ret)
>  		return ret;
> @@ -392,14 +392,14 @@ static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
>  
> -	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->sensor, a);
> +	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->source, a);
>  }
>  
>  static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
>  
> -	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->sensor, a);
> +	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->source, a);
>  }
>  
>  static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
> @@ -799,20 +799,20 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
>  		memset(&mbus_code, 0, sizeof(mbus_code));
>  		mbus_code.index = j;
>  		mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> -		ret = v4l2_subdev_call(ctx->phy->sensor, pad, enum_mbus_code,
> +		ret = v4l2_subdev_call(ctx->phy->source, pad, enum_mbus_code,
>  				       NULL, &mbus_code);
>  		if (ret == -EINVAL)
>  			break;
>  
>  		if (ret) {
>  			ctx_err(ctx, "Error enumerating mbus codes in subdev %s: %d\n",
> -				ctx->phy->sensor->name, ret);
> +				ctx->phy->source->name, ret);
>  			return ret;
>  		}
>  
>  		ctx_dbg(2, ctx,
>  			"subdev %s: code: %04x idx: %u\n",
> -			ctx->phy->sensor->name, mbus_code.code, j);
> +			ctx->phy->source->name, mbus_code.code, j);
>  
>  		for (k = 0; k < cal_num_formats; k++) {
>  			fmtinfo = &cal_formats[k];
> @@ -830,7 +830,7 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
>  
>  	if (i == 0) {
>  		ctx_err(ctx, "No suitable format reported by subdev %s\n",
> -			ctx->phy->sensor->name);
> +			ctx->phy->source->name);
>  		return -EINVAL;
>  	}
>  
> @@ -867,10 +867,10 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  	if (!cal_mc_api) {
>  		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
>  
> -		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->sensor->ctrl_handler,
> +		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
>  					    NULL, true);
>  		if (ret < 0) {
> -			ctx_err(ctx, "Failed to add sensor ctrl handler\n");
> +			ctx_err(ctx, "Failed to add source ctrl handler\n");
>  			return ret;
>  		}
>  	}
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 2e2bef91b2b0..a5340b583592 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -635,20 +635,20 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
>  	int pad;
>  	int ret;
>  
> -	if (phy->sensor) {
> +	if (phy->source) {
>  		phy_info(phy, "Rejecting subdev %s (Already set!!)",
>  			 subdev->name);
>  		return 0;
>  	}
>  
> -	phy->sensor = subdev;
> -	phy_dbg(1, phy, "Using sensor %s for capture\n", subdev->name);
> +	phy->source = subdev;
> +	phy_dbg(1, phy, "Using source %s for capture\n", subdev->name);
>  
>  	pad = media_entity_get_fwnode_pad(&subdev->entity,
> -					  of_fwnode_handle(phy->sensor_ep_node),
> +					  of_fwnode_handle(phy->source_ep_node),
>  					  MEDIA_PAD_FL_SOURCE);
>  	if (pad < 0) {
> -		phy_err(phy, "Sensor %s has no connected source pad\n",
> +		phy_err(phy, "Source %s has no connected source pad\n",
>  			subdev->name);
>  		return pad;
>  	}
> @@ -658,7 +658,7 @@ static int cal_async_notifier_bound(struct v4l2_async_notifier *notifier,
>  				    MEDIA_LNK_FL_IMMUTABLE |
>  				    MEDIA_LNK_FL_ENABLED);
>  	if (ret) {
> -		phy_err(phy, "Failed to create media link for sensor %s\n",
> +		phy_err(phy, "Failed to create media link for source %s\n",
>  			subdev->name);
>  		return ret;
>  	}
> @@ -701,10 +701,10 @@ static int cal_async_notifier_register(struct cal_dev *cal)
>  		struct cal_v4l2_async_subdev *casd;
>  		struct fwnode_handle *fwnode;
>  
> -		if (!phy->sensor_node)
> +		if (!phy->source_node)
>  			continue;
>  
> -		fwnode = of_fwnode_handle(phy->sensor_node);
> +		fwnode = of_fwnode_handle(phy->source_node);
>  		casd = v4l2_async_notifier_add_fwnode_subdev(&cal->notifier,
>  							     fwnode,
>  							     struct cal_v4l2_async_subdev);
> @@ -1045,7 +1045,7 @@ static int cal_probe(struct platform_device *pdev)
>  			goto error_camerarx;
>  		}
>  
> -		if (cal->phy[i]->sensor_node)
> +		if (cal->phy[i]->source_node)
>  			connected = true;
>  	}
>  
> @@ -1057,7 +1057,7 @@ static int cal_probe(struct platform_device *pdev)
>  
>  	/* Create contexts. */
>  	for (i = 0; i < cal->data->num_csi2_phy; ++i) {
> -		if (!cal->phy[i]->sensor_node)
> +		if (!cal->phy[i]->source_node)
>  			continue;
>  
>  		cal->ctx[i] = cal_ctx_create(cal, i);
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index e079c6a9f93f..af46084580bd 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -155,9 +155,9 @@ struct cal_camerarx {
>  	unsigned int		instance;
>  
>  	struct v4l2_fwnode_endpoint	endpoint;
> -	struct device_node	*sensor_ep_node;
> -	struct device_node	*sensor_node;
> -	struct v4l2_subdev	*sensor;
> +	struct device_node	*source_ep_node;
> +	struct device_node	*source_node;
> +	struct v4l2_subdev	*source;
>  	struct media_pipeline	pipe;
>  
>  	struct v4l2_subdev	subdev;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume
  2021-04-12 11:34 ` [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume Tomi Valkeinen
@ 2021-04-17 23:27   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-17 23:27 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:34PM +0300, Tomi Valkeinen wrote:
> For some reason CAL_CTRL is written at the end of cal_ctx_wr_dma_config.
> CAL_CTRL is a global (for CAL) register, so it should be independent of
> contexts.
> 
> Move the code to cal_runtime_resume().
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index a5340b583592..b539a9afb3f5 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -403,17 +403,6 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>  	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index), val);
>  	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->index,
>  		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index)));
> -
> -	val = cal_read(ctx->cal, CAL_CTRL);
> -	cal_set_field(&val, CAL_CTRL_BURSTSIZE_BURST128,
> -		      CAL_CTRL_BURSTSIZE_MASK);
> -	cal_set_field(&val, 0xF, CAL_CTRL_TAGCNT_MASK);
> -	cal_set_field(&val, CAL_CTRL_POSTED_WRITES_NONPOSTED,
> -		      CAL_CTRL_POSTED_WRITES_MASK);
> -	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGL_MASK);
> -	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGH_MASK);
> -	cal_write(ctx->cal, CAL_CTRL, val);
> -	ctx_dbg(3, ctx, "CAL_CTRL = 0x%08x\n", cal_read(ctx->cal, CAL_CTRL));
>  }
>  
>  void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
> @@ -1125,6 +1114,7 @@ static int cal_runtime_resume(struct device *dev)
>  {
>  	struct cal_dev *cal = dev_get_drvdata(dev);
>  	unsigned int i;
> +	u32 val;
>  
>  	if (cal->data->flags & DRA72_CAL_PRE_ES2_LDO_DISABLE) {
>  		/*
> @@ -1141,6 +1131,17 @@ static int cal_runtime_resume(struct device *dev)
>  	 */
>  	cal_write(cal, CAL_HL_IRQENABLE_SET(0), CAL_HL_IRQ_OCPO_ERR_MASK);
>  
> +	val = cal_read(cal, CAL_CTRL);
> +	cal_set_field(&val, CAL_CTRL_BURSTSIZE_BURST128,
> +		      CAL_CTRL_BURSTSIZE_MASK);
> +	cal_set_field(&val, 0xF, CAL_CTRL_TAGCNT_MASK);
> +	cal_set_field(&val, CAL_CTRL_POSTED_WRITES_NONPOSTED,
> +		      CAL_CTRL_POSTED_WRITES_MASK);
> +	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGL_MASK);
> +	cal_set_field(&val, 0xFF, CAL_CTRL_MFLAGH_MASK);
> +	cal_write(cal, CAL_CTRL, val);
> +	cal_dbg(3, cal, "CAL_CTRL = 0x%08x\n", cal_read(cal, CAL_CTRL));

While at it, could you turn the hex values to lower case ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
>  	return 0;
>  }
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field
  2021-04-12 11:34 ` [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field Tomi Valkeinen
@ 2021-04-18  0:43   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18  0:43 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:32PM +0300, Tomi Valkeinen wrote:
> cal_camerarx->dev field is not used, remove it.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index db0e408eaa94..e079c6a9f93f 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -149,7 +149,6 @@ struct cal_data {
>  struct cal_camerarx {
>  	void __iomem		*base;
>  	struct resource		*res;
> -	struct device		*dev;
>  	struct regmap_field	*fields[F_MAX_FIELDS];
>  
>  	struct cal_dev		*cal;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq
  2021-04-12 11:34 ` [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq Tomi Valkeinen
@ 2021-04-18 11:48   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 11:48 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:35PM +0300, Tomi Valkeinen wrote:
> CAL driver uses V4L2_CID_PIXEL_RATE to get the required pixel rate, and
> then changes that value to link rate before configuring the registers.
> 
> Rewrite the code to use v4l2_get_link_freq(), which simplifies the code
> as we get the link rate directly, and it also adds support for
> V4L2_CID_LINK_FREQ.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 52 +++++++-------------
>  1 file changed, 19 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 603405824738..974fcbb19547 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -45,22 +45,23 @@ static inline void camerarx_write(struct cal_camerarx *phy, u32 offset, u32 val)
>   * ------------------------------------------------------------------
>   */
>  
> -static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy)
> +static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
>  {
> -	struct v4l2_ctrl *ctrl;
> -	s64 rate;
> +	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = &phy->endpoint.bus.mipi_csi2;
> +	u32 num_lanes = mipi_csi2->num_data_lanes;
> +	u32 bpp = phy->fmtinfo->bpp;
> +	s64 freq;
>  
> -	ctrl = v4l2_ctrl_find(phy->source->ctrl_handler, V4L2_CID_PIXEL_RATE);
> -	if (!ctrl) {
> -		phy_err(phy, "no pixel rate control in subdev: %s\n",
> +	freq = v4l2_get_link_freq(phy->source->ctrl_handler, bpp, 2 * num_lanes);
> +	if (freq < 0) {
> +		phy_err(phy, "failed to get link freq for subdev: %s\n",

I'd write "for subdev %s" or "for subdev '%s'".

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  			phy->source->name);
> -		return -EPIPE;
> +		return freq;
>  	}
>  
> -	rate = v4l2_ctrl_g_ctrl_int64(ctrl);
> -	phy_dbg(3, phy, "Source Pixel Rate: %llu\n", rate);
> +	phy_dbg(3, phy, "Source Link Freq: %llu\n", freq);
>  
> -	return rate;
> +	return freq;
>  }
>  
>  static void cal_camerarx_lane_config(struct cal_camerarx *phy)
> @@ -116,34 +117,19 @@ void cal_camerarx_disable(struct cal_camerarx *phy)
>  #define TCLK_MISS	1
>  #define TCLK_SETTLE	14
>  
> -static void cal_camerarx_config(struct cal_camerarx *phy, s64 external_rate)
> +static void cal_camerarx_config(struct cal_camerarx *phy, s64 link_freq)
>  {
>  	unsigned int reg0, reg1;
>  	unsigned int ths_term, ths_settle;
> -	unsigned int csi2_ddrclk_khz;
> -	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 =
> -			&phy->endpoint.bus.mipi_csi2;
> -	u32 num_lanes = mipi_csi2->num_data_lanes;
>  
>  	/* DPHY timing configuration */
>  
> -	/*
> -	 * CSI-2 is DDR and we only count used lanes.
> -	 *
> -	 * csi2_ddrclk_khz = external_rate / 1000
> -	 *		   / (2 * num_lanes) * phy->fmtinfo->bpp;
> -	 */
> -	csi2_ddrclk_khz = div_s64(external_rate * phy->fmtinfo->bpp,
> -				  2 * num_lanes * 1000);
> -
> -	phy_dbg(1, phy, "csi2_ddrclk_khz: %d\n", csi2_ddrclk_khz);
> -
>  	/* THS_TERM: Programmed value = floor(20 ns/DDRClk period) */
> -	ths_term = 20 * csi2_ddrclk_khz / 1000000;
> +	ths_term = div_s64(20 * link_freq, 1000 * 1000 * 1000);
>  	phy_dbg(1, phy, "ths_term: %d (0x%02x)\n", ths_term, ths_term);
>  
>  	/* THS_SETTLE: Programmed value = floor(105 ns/DDRClk period) + 4 */
> -	ths_settle = (105 * csi2_ddrclk_khz / 1000000) + 4;
> +	ths_settle = div_s64(105 * link_freq, 1000 * 1000 * 1000) + 4;
>  	phy_dbg(1, phy, "ths_settle: %d (0x%02x)\n", ths_settle, ths_settle);
>  
>  	reg0 = camerarx_read(phy, CAL_CSI2_PHY_REG0);
> @@ -270,14 +256,14 @@ static void cal_camerarx_ppi_disable(struct cal_camerarx *phy)
>  
>  static int cal_camerarx_start(struct cal_camerarx *phy)
>  {
> -	s64 external_rate;
> +	s64 link_freq;
>  	u32 sscounter;
>  	u32 val;
>  	int ret;
>  
> -	external_rate = cal_camerarx_get_external_rate(phy);
> -	if (external_rate < 0)
> -		return external_rate;
> +	link_freq = cal_camerarx_get_ext_link_freq(phy);
> +	if (link_freq < 0)
> +		return link_freq;
>  
>  	ret = v4l2_subdev_call(phy->source, core, s_power, 1);
>  	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
> @@ -325,7 +311,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>  	camerarx_read(phy, CAL_CSI2_PHY_REG0);
>  
>  	/* Program the PHY timing parameters. */
> -	cal_camerarx_config(phy, external_rate);
> +	cal_camerarx_config(phy, link_freq);
>  
>  	/*
>  	 *    b. Assert the FORCERXMODE signal.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8
  2021-04-12 11:34 ` [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8 Tomi Valkeinen
@ 2021-04-18 11:55   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 11:55 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:37PM +0300, Tomi Valkeinen wrote:
> cal_ctx's index and cport fields are numbers less than 8. In the
> following patches we will get a bunch of new fields, all of which are
> similar small numbers, so lets change the type to u8.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 09ad20faa9e1..251bb0ba7b3b 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -217,8 +217,8 @@ struct cal_ctx {
>  
>  	unsigned int		sequence;
>  	struct vb2_queue	vb_vidq;
> -	unsigned int		index;
> -	unsigned int		cport;
> +	u8			index;
> +	u8			cport;
>  };
>  
>  extern unsigned int cal_debug;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 09/28] media: ti-vpe: cal: Add PPI context
  2021-04-12 11:34 ` [PATCH 09/28] media: ti-vpe: cal: Add PPI context Tomi Valkeinen
@ 2021-04-18 12:17   ` Laurent Pinchart
  2021-04-19  9:01     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:17 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:38PM +0300, Tomi Valkeinen wrote:
> CAL has 8 PPI contexts per PHY, which are used to tag the incoming data.
> The current driver only uses the first PPI, but we need to support all
> of them to implement multi-stream support.
> 
> Add a ppi_ctx field to cal_ctx, which indicates which of the 8 PPI
> contexts is used for the particular cal_ctx. Also clean up the PPI
> context register macros to take the PPI context number as a parameter.

As far as I can tell, the TRMs don't mention "PPI contexts". PPI stands
for PHY Protocol Interface, it does identify a particular physical
interface. Would it be better to rename ppi_ctx to csi2_ctx ?  This
would match the register names too.

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c      | 10 ++++++----
>  drivers/media/platform/ti-vpe/cal.h      |  1 +
>  drivers/media/platform/ti-vpe/cal_regs.h | 18 ++----------------
>  3 files changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 3d57aedbee0a..c550eeb27e79 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -294,7 +294,7 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>  {
>  	u32 val;
>  
> -	val = cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index));
> +	val = cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx));
>  	cal_set_field(&val, ctx->cport, CAL_CSI2_CTX_CPORT_MASK);
>  	/*
>  	 * DT type: MIPI CSI-2 Specs
> @@ -310,9 +310,10 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>  	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
>  	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
>  		      CAL_CSI2_CTX_PACK_MODE_MASK);
> -	cal_write(ctx->cal, CAL_CSI2_CTX0(ctx->index), val);
> -	ctx_dbg(3, ctx, "CAL_CSI2_CTX0(%d) = 0x%08x\n", ctx->index,
> -		cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index)));
> +	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), val);
> +	ctx_dbg(3, ctx, "CAL_CSI2_CTX%d(%d) = 0x%08x\n",
> +		ctx->phy->instance, ctx->ppi_ctx,
> +		cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx)));
>  }
>  
>  static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
> @@ -854,6 +855,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>  	ctx->cal = cal;
>  	ctx->phy = cal->phy[inst];
>  	ctx->index = inst;
> +	ctx->ppi_ctx = inst;

To avoid a functional change in this patch, should this be = 0 ?

>  	ctx->cport = inst;
>  
>  	ret = cal_ctx_v4l2_init(ctx);
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 251bb0ba7b3b..6eb63268f916 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -219,6 +219,7 @@ struct cal_ctx {
>  	struct vb2_queue	vb_vidq;
>  	u8			index;
>  	u8			cport;
> +	u8			ppi_ctx;
>  };
>  
>  extern unsigned int cal_debug;
> diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
> index f752096dcf7f..5c4f9e642185 100644
> --- a/drivers/media/platform/ti-vpe/cal_regs.h
> +++ b/drivers/media/platform/ti-vpe/cal_regs.h
> @@ -72,22 +72,8 @@
>  #define CAL_CSI2_TIMING(m)		(0x314U + (m) * 0x80U)
>  #define CAL_CSI2_VC_IRQENABLE(m)	(0x318U + (m) * 0x80U)
>  #define CAL_CSI2_VC_IRQSTATUS(m)	(0x328U + (m) * 0x80U)
> -#define CAL_CSI2_CTX0(m)		(0x330U + (m) * 0x80U)
> -#define CAL_CSI2_CTX1(m)		(0x334U + (m) * 0x80U)
> -#define CAL_CSI2_CTX2(m)		(0x338U + (m) * 0x80U)
> -#define CAL_CSI2_CTX3(m)		(0x33cU + (m) * 0x80U)
> -#define CAL_CSI2_CTX4(m)		(0x340U + (m) * 0x80U)
> -#define CAL_CSI2_CTX5(m)		(0x344U + (m) * 0x80U)
> -#define CAL_CSI2_CTX6(m)		(0x348U + (m) * 0x80U)
> -#define CAL_CSI2_CTX7(m)		(0x34cU + (m) * 0x80U)
> -#define CAL_CSI2_STATUS0(m)		(0x350U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS1(m)		(0x354U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS2(m)		(0x358U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS3(m)		(0x35cU + (m) * 0x80U)
> -#define CAL_CSI2_STATUS4(m)		(0x360U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS5(m)		(0x364U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS6(m)		(0x368U + (m) * 0x80U)
> -#define CAL_CSI2_STATUS7(m)		(0x36cU + (m) * 0x80U)
> +#define CAL_CSI2_CTX(phy, ppi_ctx)	(0x330U + (phy) * 0x80U + (ppi_ctx) * 4)
> +#define CAL_CSI2_STATUS(phy, ppi_ctx)	(0x350U + (phy) * 0x80U + (ppi_ctx) * 4)
>  
>  /* CAL CSI2 PHY register offsets */
>  #define CAL_CSI2_PHY_REG0		0x000

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context
  2021-04-12 11:34 ` [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context Tomi Valkeinen
@ 2021-04-18 12:20   ` Laurent Pinchart
  2021-04-18 12:23     ` Laurent Pinchart
  2021-04-19  9:17     ` Tomi Valkeinen
  0 siblings, 2 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:20 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:39PM +0300, Tomi Valkeinen wrote:
> CAL has 4 pixel processing contexts (PIX PROC) of which the driver
> currently uses pix proc 0 for PHY0, and pix proc 1 for PHY1 (as the
> driver supports only a single source per PHY).
> 
> Add a pix_proc field to cal_ctx to allow us to use different pix proc
> contexts in the future
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 9 +++++----
>  drivers/media/platform/ti-vpe/cal.h | 1 +
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index c550eeb27e79..3dc83c66fd96 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -355,16 +355,16 @@ static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
>  		break;
>  	}
>  
> -	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->index));
> +	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc));
>  	cal_set_field(&val, extract, CAL_PIX_PROC_EXTRACT_MASK);
>  	cal_set_field(&val, CAL_PIX_PROC_DPCMD_BYPASS, CAL_PIX_PROC_DPCMD_MASK);
>  	cal_set_field(&val, CAL_PIX_PROC_DPCME_BYPASS, CAL_PIX_PROC_DPCME_MASK);
>  	cal_set_field(&val, pack, CAL_PIX_PROC_PACK_MASK);
>  	cal_set_field(&val, ctx->cport, CAL_PIX_PROC_CPORT_MASK);
>  	cal_set_field(&val, 1, CAL_PIX_PROC_EN_MASK);
> -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->index), val);
> -	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->index,
> -		cal_read(ctx->cal, CAL_PIX_PROC(ctx->index)));
> +	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), val);
> +	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->pix_proc,

While at it, you could s/%d/%u/

> +		cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc)));

And should we use val here instead of reading the value back ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  }
>  
>  static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
> @@ -857,6 +857,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>  	ctx->index = inst;
>  	ctx->ppi_ctx = inst;
>  	ctx->cport = inst;
> +	ctx->pix_proc = inst;
>  
>  	ret = cal_ctx_v4l2_init(ctx);
>  	if (ret)
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 6eb63268f916..03c71763f1a5 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -220,6 +220,7 @@ struct cal_ctx {
>  	u8			index;
>  	u8			cport;
>  	u8			ppi_ctx;
> +	u8			pix_proc;
>  };
>  
>  extern unsigned int cal_debug;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx
  2021-04-12 11:34 ` [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx Tomi Valkeinen
@ 2021-04-18 12:22   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:22 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:40PM +0300, Tomi Valkeinen wrote:
> Rename cal_ctx->index to dma_ctx to clarify that the field refers to the
> DMA context number.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal-video.c |  4 +--
>  drivers/media/platform/ti-vpe/cal.c       | 38 +++++++++++------------
>  drivers/media/platform/ti-vpe/cal.h       |  8 ++---
>  3 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 8e9bbe6beb23..064efdc31b28 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -897,7 +897,7 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  				    MEDIA_LNK_FL_ENABLED);
>  	if (ret) {
>  		ctx_err(ctx, "Failed to create media link for context %u\n",
> -			ctx->index);
> +			ctx->dma_ctx);
>  		video_unregister_device(vfd);
>  		return ret;
>  	}
> @@ -949,7 +949,7 @@ int cal_ctx_v4l2_init(struct cal_ctx *ctx)
>  			 | (cal_mc_api ? V4L2_CAP_IO_MC : 0);
>  	vfd->v4l2_dev = &ctx->cal->v4l2_dev;
>  	vfd->queue = q;
> -	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->index);
> +	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->dma_ctx);
>  	vfd->release = video_device_release_empty;
>  	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_video_ops;
>  	vfd->lock = &ctx->mutex;
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 3dc83c66fd96..daa0c1ab94e7 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -372,7 +372,7 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>  	unsigned int stride = ctx->v_fmt.fmt.pix.bytesperline;
>  	u32 val;
>  
> -	val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index));
> +	val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
>  	cal_set_field(&val, ctx->cport, CAL_WR_DMA_CTRL_CPORT_MASK);
>  	cal_set_field(&val, ctx->v_fmt.fmt.pix.height,
>  		      CAL_WR_DMA_CTRL_YSIZE_MASK);
> @@ -383,16 +383,16 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>  	cal_set_field(&val, CAL_WR_DMA_CTRL_PATTERN_LINEAR,
>  		      CAL_WR_DMA_CTRL_PATTERN_MASK);
>  	cal_set_field(&val, 1, CAL_WR_DMA_CTRL_STALL_RD_MASK);
> -	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->index), val);
> -	ctx_dbg(3, ctx, "CAL_WR_DMA_CTRL(%d) = 0x%08x\n", ctx->index,
> -		cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index)));
> +	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
> +	ctx_dbg(3, ctx, "CAL_WR_DMA_CTRL(%d) = 0x%08x\n", ctx->dma_ctx,
> +		cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx)));
>  
> -	cal_write_field(ctx->cal, CAL_WR_DMA_OFST(ctx->index),
> +	cal_write_field(ctx->cal, CAL_WR_DMA_OFST(ctx->dma_ctx),
>  			stride / 16, CAL_WR_DMA_OFST_MASK);
> -	ctx_dbg(3, ctx, "CAL_WR_DMA_OFST(%d) = 0x%08x\n", ctx->index,
> -		cal_read(ctx->cal, CAL_WR_DMA_OFST(ctx->index)));
> +	ctx_dbg(3, ctx, "CAL_WR_DMA_OFST(%d) = 0x%08x\n", ctx->dma_ctx,
> +		cal_read(ctx->cal, CAL_WR_DMA_OFST(ctx->dma_ctx)));
>  
> -	val = cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index));
> +	val = cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx));
>  	/* 64 bit word means no skipping */
>  	cal_set_field(&val, 0, CAL_WR_DMA_XSIZE_XSKIP_MASK);
>  	/*
> @@ -401,23 +401,23 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>  	 * written per line.
>  	 */
>  	cal_set_field(&val, stride / 8, CAL_WR_DMA_XSIZE_MASK);
> -	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index), val);
> -	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->index,
> -		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->index)));
> +	cal_write(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx), val);
> +	ctx_dbg(3, ctx, "CAL_WR_DMA_XSIZE(%d) = 0x%08x\n", ctx->dma_ctx,
> +		cal_read(ctx->cal, CAL_WR_DMA_XSIZE(ctx->dma_ctx)));
>  }
>  
>  void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
>  {
> -	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->index), addr);
> +	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->dma_ctx), addr);
>  }
>  
>  static void cal_ctx_wr_dma_disable(struct cal_ctx *ctx)
>  {
> -	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->index));
> +	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
>  
>  	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_DIS,
>  		      CAL_WR_DMA_CTRL_MODE_MASK);
> -	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->index), val);
> +	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
>  }
>  
>  static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
> @@ -453,9 +453,9 @@ void cal_ctx_start(struct cal_ctx *ctx)
>  
>  	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(1),
> -		  CAL_HL_IRQ_MASK(ctx->index));
> +		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
> -		  CAL_HL_IRQ_MASK(ctx->index));
> +		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
>  }
>  
>  void cal_ctx_stop(struct cal_ctx *ctx)
> @@ -479,9 +479,9 @@ void cal_ctx_stop(struct cal_ctx *ctx)
>  
>  	/* Disable IRQ_WDMA_END and IRQ_WDMA_START. */
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(1),
> -		  CAL_HL_IRQ_MASK(ctx->index));
> +		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(2),
> -		  CAL_HL_IRQ_MASK(ctx->index));
> +		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
>  
>  	ctx->dma.state = CAL_DMA_STOPPED;
>  }
> @@ -854,7 +854,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>  
>  	ctx->cal = cal;
>  	ctx->phy = cal->phy[inst];
> -	ctx->index = inst;
> +	ctx->dma_ctx = inst;
>  	ctx->ppi_ctx = inst;
>  	ctx->cport = inst;
>  	ctx->pix_proc = inst;
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 03c71763f1a5..c34b843d2019 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -217,7 +217,7 @@ struct cal_ctx {
>  
>  	unsigned int		sequence;
>  	struct vb2_queue	vb_vidq;
> -	u8			index;
> +	u8			dma_ctx;
>  	u8			cport;
>  	u8			ppi_ctx;
>  	u8			pix_proc;
> @@ -238,11 +238,11 @@ extern bool cal_mc_api;
>  	dev_err((cal)->dev, fmt, ##arg)
>  
>  #define ctx_dbg(level, ctx, fmt, arg...)				\
> -	cal_dbg(level, (ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
> +	cal_dbg(level, (ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
>  #define ctx_info(ctx, fmt, arg...)					\
> -	cal_info((ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
> +	cal_info((ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
>  #define ctx_err(ctx, fmt, arg...)					\
> -	cal_err((ctx)->cal, "ctx%u: " fmt, (ctx)->index, ##arg)
> +	cal_err((ctx)->cal, "ctx%u: " fmt, (ctx)->dma_ctx, ##arg)
>  
>  #define phy_dbg(level, phy, fmt, arg...)				\
>  	cal_dbg(level, (phy)->cal, "phy%u: " fmt, (phy)->instance, ##arg)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context
  2021-04-18 12:20   ` Laurent Pinchart
@ 2021-04-18 12:23     ` Laurent Pinchart
  2021-04-19  9:17     ` Tomi Valkeinen
  1 sibling, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:23 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

And another comment.

On Sun, Apr 18, 2021 at 03:20:29PM +0300, Laurent Pinchart wrote:
> On Mon, Apr 12, 2021 at 02:34:39PM +0300, Tomi Valkeinen wrote:
> > CAL has 4 pixel processing contexts (PIX PROC) of which the driver
> > currently uses pix proc 0 for PHY0, and pix proc 1 for PHY1 (as the
> > driver supports only a single source per PHY).
> > 
> > Add a pix_proc field to cal_ctx to allow us to use different pix proc
> > contexts in the future
> > 
> > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> > ---
> >  drivers/media/platform/ti-vpe/cal.c | 9 +++++----
> >  drivers/media/platform/ti-vpe/cal.h | 1 +
> >  2 files changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> > index c550eeb27e79..3dc83c66fd96 100644
> > --- a/drivers/media/platform/ti-vpe/cal.c
> > +++ b/drivers/media/platform/ti-vpe/cal.c
> > @@ -355,16 +355,16 @@ static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
> >  		break;
> >  	}
> >  
> > -	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->index));
> > +	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc));
> >  	cal_set_field(&val, extract, CAL_PIX_PROC_EXTRACT_MASK);
> >  	cal_set_field(&val, CAL_PIX_PROC_DPCMD_BYPASS, CAL_PIX_PROC_DPCMD_MASK);
> >  	cal_set_field(&val, CAL_PIX_PROC_DPCME_BYPASS, CAL_PIX_PROC_DPCME_MASK);
> >  	cal_set_field(&val, pack, CAL_PIX_PROC_PACK_MASK);
> >  	cal_set_field(&val, ctx->cport, CAL_PIX_PROC_CPORT_MASK);
> >  	cal_set_field(&val, 1, CAL_PIX_PROC_EN_MASK);
> > -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->index), val);
> > -	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->index,
> > -		cal_read(ctx->cal, CAL_PIX_PROC(ctx->index)));
> > +	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), val);
> > +	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->pix_proc,
> 
> While at it, you could s/%d/%u/
> 
> > +		cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc)));
> 
> And should we use val here instead of reading the value back ?

Given that these patterns are common in the driver, a separate patch to
address them all (if desired) would likely be best.

> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> >  }
> >  
> >  static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
> > @@ -857,6 +857,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
> >  	ctx->index = inst;
> >  	ctx->ppi_ctx = inst;
> >  	ctx->cport = inst;
> > +	ctx->pix_proc = inst;
> >  
> >  	ret = cal_ctx_v4l2_init(ctx);
> >  	if (ret)
> > diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> > index 6eb63268f916..03c71763f1a5 100644
> > --- a/drivers/media/platform/ti-vpe/cal.h
> > +++ b/drivers/media/platform/ti-vpe/cal.h
> > @@ -220,6 +220,7 @@ struct cal_ctx {
> >  	u8			index;
> >  	u8			cport;
> >  	u8			ppi_ctx;
> > +	u8			pix_proc;
> >  };
> >  
> >  extern unsigned int cal_debug;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK
  2021-04-12 11:34 ` [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK Tomi Valkeinen
@ 2021-04-18 12:29   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:29 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:41PM +0300, Tomi Valkeinen wrote:
> CAL_HL_IRQ_MASK macro is used for both WDMA start and end status bits.
> For clarity, rename CAL_HL_IRQ_MASK macro to CAL_HL_IRQ_WDMA_END_MASK
> and CAL_HL_IRQ_WDMA_START_MASK.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c      | 12 ++++++------
>  drivers/media/platform/ti-vpe/cal_regs.h |  3 ++-
>  2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index daa0c1ab94e7..0abcc83841c6 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -453,9 +453,9 @@ void cal_ctx_start(struct cal_ctx *ctx)
>  
>  	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(1),
> -		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
> +		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
> -		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
> +		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
>  }
>  
>  void cal_ctx_stop(struct cal_ctx *ctx)
> @@ -479,9 +479,9 @@ void cal_ctx_stop(struct cal_ctx *ctx)
>  
>  	/* Disable IRQ_WDMA_END and IRQ_WDMA_START. */
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(1),
> -		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
> +		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_CLR(2),
> -		  CAL_HL_IRQ_MASK(ctx->dma_ctx));
> +		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
>  
>  	ctx->dma.state = CAL_DMA_STOPPED;
>  }
> @@ -589,7 +589,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
>  		cal_write(cal, CAL_HL_IRQSTATUS(1), status);
>  
>  		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
> -			if (status & CAL_HL_IRQ_MASK(i))
> +			if (status & CAL_HL_IRQ_WDMA_END_MASK(i))
>  				cal_irq_wdma_end(cal->ctx[i]);
>  		}
>  	}
> @@ -603,7 +603,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
>  		cal_write(cal, CAL_HL_IRQSTATUS(2), status);
>  
>  		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
> -			if (status & CAL_HL_IRQ_MASK(i))
> +			if (status & CAL_HL_IRQ_WDMA_START_MASK(i))
>  				cal_irq_wdma_start(cal->ctx[i]);
>  		}
>  	}
> diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
> index 5c4f9e642185..93d9bf1f3c00 100644
> --- a/drivers/media/platform/ti-vpe/cal_regs.h
> +++ b/drivers/media/platform/ti-vpe/cal_regs.h
> @@ -125,7 +125,8 @@
>  #define CAL_HL_IRQ_EOI_LINE_NUMBER_READ0		0
>  #define CAL_HL_IRQ_EOI_LINE_NUMBER_EOI0			0
>  
> -#define CAL_HL_IRQ_MASK(m)			BIT(m)
> +#define CAL_HL_IRQ_WDMA_END_MASK(m)		BIT(m)
> +#define CAL_HL_IRQ_WDMA_START_MASK(m)		BIT(m)

I foresee a risk of mixing the two macros, using
CAL_HL_IRQ_WDMA_START_MASK with IRQ(1) or CAL_HL_IRQ_WDMA_END_MASK with
IRQ(2). Not sure how we could prevent that though, and it won't make any
functional difference (but could lead to other bugs), so

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  #define CAL_HL_IRQ_OCPO_ERR_MASK		BIT(6)
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros
  2021-04-12 11:34 ` [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros Tomi Valkeinen
@ 2021-04-18 12:32   ` Laurent Pinchart
  2021-04-19 10:29     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:32 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:42PM +0300, Tomi Valkeinen wrote:
> The macros related to CAL_CSI2_VC_IRQ can be handled better by having
> the VC number as a macro parameter.
> 
> Note that the macros are not used anywhere yet, so no other changes are
> needed.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal_regs.h | 30 +++++-------------------
>  1 file changed, 6 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
> index 93d9bf1f3c00..ed658175a444 100644
> --- a/drivers/media/platform/ti-vpe/cal_regs.h
> +++ b/drivers/media/platform/ti-vpe/cal_regs.h
> @@ -406,30 +406,12 @@
>  #define CAL_CSI2_TIMING_STOP_STATE_X16_IO1_MASK		BIT(14)
>  #define CAL_CSI2_TIMING_FORCE_RX_MODE_IO1_MASK		BIT(15)
>  
> -#define CAL_CSI2_VC_IRQ_FS_IRQ_0_MASK			BIT(0)
> -#define CAL_CSI2_VC_IRQ_FE_IRQ_0_MASK			BIT(1)
> -#define CAL_CSI2_VC_IRQ_LS_IRQ_0_MASK			BIT(2)
> -#define CAL_CSI2_VC_IRQ_LE_IRQ_0_MASK			BIT(3)
> -#define CAL_CSI2_VC_IRQ_CS_IRQ_0_MASK			BIT(4)
> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_0_MASK	BIT(5)
> -#define CAL_CSI2_VC_IRQ_FS_IRQ_1_MASK			BIT(8)
> -#define CAL_CSI2_VC_IRQ_FE_IRQ_1_MASK			BIT(9)
> -#define CAL_CSI2_VC_IRQ_LS_IRQ_1_MASK			BIT(10)
> -#define CAL_CSI2_VC_IRQ_LE_IRQ_1_MASK			BIT(11)
> -#define CAL_CSI2_VC_IRQ_CS_IRQ_1_MASK			BIT(12)
> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_1_MASK	BIT(13)
> -#define CAL_CSI2_VC_IRQ_FS_IRQ_2_MASK			BIT(16)
> -#define CAL_CSI2_VC_IRQ_FE_IRQ_2_MASK			BIT(17)
> -#define CAL_CSI2_VC_IRQ_LS_IRQ_2_MASK			BIT(18)
> -#define CAL_CSI2_VC_IRQ_LE_IRQ_2_MASK			BIT(19)
> -#define CAL_CSI2_VC_IRQ_CS_IRQ_2_MASK			BIT(20)
> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_2_MASK	BIT(21)
> -#define CAL_CSI2_VC_IRQ_FS_IRQ_3_MASK			BIT(24)
> -#define CAL_CSI2_VC_IRQ_FE_IRQ_3_MASK			BIT(25)
> -#define CAL_CSI2_VC_IRQ_LS_IRQ_3_MASK			BIT(26)
> -#define CAL_CSI2_VC_IRQ_LE_IRQ_3_MASK			BIT(27)
> -#define CAL_CSI2_VC_IRQ_CS_IRQ_3_MASK			BIT(28)
> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_3_MASK	BIT(29)
> +#define CAL_CSI2_VC_IRQ_FS_IRQ_MASK(n)			BIT(0 + (n * 8))

This should be BIT(0 + (n) * 8). Same below.

As they're single bits, I would have dropped the _MASK suffix.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +#define CAL_CSI2_VC_IRQ_FE_IRQ_MASK(n)			BIT(1 + (n * 8))
> +#define CAL_CSI2_VC_IRQ_LS_IRQ_MASK(n)			BIT(2 + (n * 8))
> +#define CAL_CSI2_VC_IRQ_LE_IRQ_MASK(n)			BIT(3 + (n * 8))
> +#define CAL_CSI2_VC_IRQ_CS_IRQ_MASK(n)			BIT(4 + (n * 8))
> +#define CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(n)	BIT(5 + (n * 8))
>  
>  #define CAL_CSI2_CTX_DT_MASK		GENMASK(5, 0)
>  #define CAL_CSI2_CTX_VC_MASK		GENMASK(7, 6)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 14/28] media: ti-vpe: cal: catch VC errors
  2021-04-12 11:34 ` [PATCH 14/28] media: ti-vpe: cal: catch VC errors Tomi Valkeinen
@ 2021-04-18 12:38   ` Laurent Pinchart
  2021-04-19 11:19     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:38 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:43PM +0300, Tomi Valkeinen wrote:
> CAL driver currently ignores VC related errors. To help catch error
> conditions, enable all the VC error interrupts and handle them in the
> interrupt handler by printing an error.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 23 ++++++++++++++++----
>  drivers/media/platform/ti-vpe/cal.c          |  9 ++++++++
>  2 files changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 974fcbb19547..0354f311c5d2 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -226,24 +226,39 @@ static void cal_camerarx_enable_irqs(struct cal_camerarx *phy)
>  		CAL_CSI2_COMPLEXIO_IRQ_FIFO_OVR_MASK |
>  		CAL_CSI2_COMPLEXIO_IRQ_SHORT_PACKET_MASK |
>  		CAL_CSI2_COMPLEXIO_IRQ_ECC_NO_CORRECTION_MASK;
> -
> -	/* Enable CIO error IRQs. */
> +	const u32 vc_err_mask =
> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(0) |
> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(1) |
> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(2) |
> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(3) |
> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(0) |
> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(1) |
> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(2) |
> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(3);
> +
> +	/* Enable CIO & VC error IRQs. */
>  	cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
> -		  CAL_HL_IRQ_CIO_MASK(phy->instance));
> +		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));

Line wrap ? Same in multiple places below. I know there's no strict 80
columns limit anymore, but I don't think longer lines help with
readability in this patch (not to mention the coding style inconsistency
with the rest of the driver).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  	cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance),
>  		  cio_err_mask);
> +	cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(phy->instance),
> +		  vc_err_mask);
>  }
>  
>  static void cal_camerarx_disable_irqs(struct cal_camerarx *phy)
>  {
>  	/* Disable CIO error irqs */
>  	cal_write(phy->cal, CAL_HL_IRQENABLE_CLR(0),
> -		  CAL_HL_IRQ_CIO_MASK(phy->instance));
> +		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));
>  	cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance), 0);
> +	cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(phy->instance), 0);
>  }
>  
>  static void cal_camerarx_ppi_enable(struct cal_camerarx *phy)
>  {
> +	cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
> +			1, CAL_CSI2_PPI_CTRL_ECC_EN_MASK);
> +
>  	cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
>  			1, CAL_CSI2_PPI_CTRL_IF_EN_MASK);
>  }
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 0abcc83841c6..092041ddbcfb 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -577,6 +577,15 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
>  				cal_write(cal, CAL_CSI2_COMPLEXIO_IRQSTATUS(i),
>  					  cio_stat);
>  			}
> +
> +			if (status & CAL_HL_IRQ_VC_MASK(i)) {
> +				u32 vc_stat = cal_read(cal, CAL_CSI2_VC_IRQSTATUS(i));
> +
> +				dev_err_ratelimited(cal->dev,
> +						    "CIO%u VC error: %#08x\n", i, vc_stat);
> +
> +				cal_write(cal, CAL_CSI2_VC_IRQSTATUS(i), vc_stat);
> +			}
>  		}
>  	}
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-12 11:34 ` [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx Tomi Valkeinen
@ 2021-04-18 12:46   ` Laurent Pinchart
  2021-04-19 11:29     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:46 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
> will break an active capture), but the RESET_DONE bit never changes to
> "reset is ongoing" state. Thus we always get a timeout.
> 
> Drop the wait, as it seems to achieve nothing.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
>  1 file changed, 2 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 0354f311c5d2..245c601b992c 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>  
>  static void cal_camerarx_stop(struct cal_camerarx *phy)
>  {
> -	unsigned int i;
>  	int ret;
>  
>  	cal_camerarx_ppi_disable(phy);
> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
>  			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>  			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
>  
> -	/* Wait for power down completion */
> -	for (i = 0; i < 10; i++) {
> -		if (cal_read_field(phy->cal,
> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)

Isn't this the wrong condition ? I would have expected
CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
you always get a timeout.

> -			break;
> -		usleep_range(1000, 1100);
> -	}
> -	phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Complex IO in Reset (%d) %s\n",
> +	phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Complex IO in Reset\n",
>  		phy->instance,
> -		cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)), i,
> -		(i >= 10) ? "(timeout)" : "");
> +		cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)));
>  
>  	/* Disable the phy */
>  	cal_camerarx_disable(phy);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop
  2021-04-12 11:34 ` [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop Tomi Valkeinen
@ 2021-04-18 12:49   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:49 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:45PM +0300, Tomi Valkeinen wrote:
> Disable PPI and pix proc in cal_ctx_stop() to ensure they are not used
> if the same context is used later on a different PHY or without pix
> proc.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 092041ddbcfb..a6ca341c98bd 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -484,6 +484,12 @@ void cal_ctx_stop(struct cal_ctx *ctx)
>  		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
>  
>  	ctx->dma.state = CAL_DMA_STOPPED;
> +
> +	/* Disable PPI context */
> +	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
> +
> +	/* Disable pix proc */
> +	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
>  }
>  
>  /* ------------------------------------------------------------------

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically
  2021-04-12 11:34 ` [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically Tomi Valkeinen
@ 2021-04-18 12:59   ` Laurent Pinchart
  2021-04-19 11:45     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 12:59 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:46PM +0300, Tomi Valkeinen wrote:
> CAL has 4 pixel processing units but the units are not needed e.g. for
> metadata. As we could be capturing 4 pixel streams and 4 metadata
> streams, i.e. using 8 DMA contexts, we cannot assign a pixel processing
> unit to every DMA context. Instead we need to reserve a pixel processing
> unit only when needed.
> 
> Add functions to reserve and release a pix proc unit, and use them in
> cal_ctx_prepare/unprepare. Note that for the time being we still always
> reserve a pix proc unit.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 44 +++++++++++++++++++++++++++--
>  drivers/media/platform/ti-vpe/cal.h |  2 ++
>  2 files changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index a6ca341c98bd..e397f59d3bbc 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -290,6 +290,37 @@ void cal_quickdump_regs(struct cal_dev *cal)
>   * ------------------------------------------------------------------
>   */
>  
> +#define CAL_MAX_PIX_PROC 4
> +
> +static int cal_reserve_pix_proc(struct cal_dev *cal)
> +{
> +	unsigned long ret;
> +
> +	spin_lock(&cal->v4l2_dev.lock);
> +
> +	ret = find_first_zero_bit(&cal->reserve_pix_proc_mask, CAL_MAX_PIX_PROC);
> +
> +	if (ret == CAL_MAX_PIX_PROC) {
> +		spin_unlock(&cal->v4l2_dev.lock);
> +		return -ENOSPC;
> +	}
> +
> +	cal->reserve_pix_proc_mask |= BIT(ret);
> +
> +	spin_unlock(&cal->v4l2_dev.lock);
> +
> +	return ret;
> +}
> +
> +static void cal_release_pix_proc(struct cal_dev *cal, unsigned int pix_proc_num)
> +{
> +	spin_lock(&cal->v4l2_dev.lock);
> +
> +	cal->reserve_pix_proc_mask &= ~BIT(pix_proc_num);
> +
> +	spin_unlock(&cal->v4l2_dev.lock);
> +}
> +
>  static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>  {
>  	u32 val;
> @@ -433,12 +464,22 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
>  
>  int cal_ctx_prepare(struct cal_ctx *ctx)
>  {
> +	int ret;
> +
> +	ret = cal_reserve_pix_proc(ctx->cal);
> +	if (ret < 0) {
> +		ctx_err(ctx, "Failed to reserve pix proc: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ctx->pix_proc = ret;

I wonder if this is the right place to allocate a context, it may be
better to reject invalid pipeline configurations earlier on. It's fine
for now, we can revisit this in subsequent patches, with the full
multiplexed streams implementation.

Another option would be to allocate the context in cal_ctx_create() for
now, with a call to cal_reserve_pix_proc(), and move it later in the
context of the patch series that implements support for multiplexed
streams.

> +
>  	return 0;
>  }
>  
>  void cal_ctx_unprepare(struct cal_ctx *ctx)
>  {
> -
> +	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
>  }
>  
>  void cal_ctx_start(struct cal_ctx *ctx)
> @@ -872,7 +913,6 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>  	ctx->dma_ctx = inst;
>  	ctx->ppi_ctx = inst;
>  	ctx->cport = inst;
> -	ctx->pix_proc = inst;
>  
>  	ret = cal_ctx_v4l2_init(ctx);
>  	if (ret)
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index c34b843d2019..01e05e46e48d 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -188,6 +188,8 @@ struct cal_dev {
>  	struct media_device	mdev;
>  	struct v4l2_device	v4l2_dev;
>  	struct v4l2_async_notifier notifier;
> +
> +	unsigned long reserve_pix_proc_mask;

I would have named this used_pix_proc_mask.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  };
>  
>  /*

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field
  2021-04-12 11:34 ` [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field Tomi Valkeinen
@ 2021-04-18 13:00   ` Laurent Pinchart
  2021-04-19 11:53     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:00 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:47PM +0300, Tomi Valkeinen wrote:
> We already have functions to reserve and release a pix proc unit, but we
> always reserve such and the code expects the pix proc unit to be used.
> 
> Add a new field, 'use_pix_proc', to indicate if the pix prox unit has
> been reserved and should be used. Use the flag to skip programming pix
> proc unit when not needed.
> 
> Note that we still always set the use_pix_proc flag to true.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 10 +++++++---
>  drivers/media/platform/ti-vpe/cal.h |  2 ++
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index e397f59d3bbc..a1d173bd4613 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -473,13 +473,15 @@ int cal_ctx_prepare(struct cal_ctx *ctx)
>  	}
>  
>  	ctx->pix_proc = ret;
> +	ctx->use_pix_proc = true;
>  
>  	return 0;
>  }
>  
>  void cal_ctx_unprepare(struct cal_ctx *ctx)
>  {
> -	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
> +	if (ctx->use_pix_proc)
> +		cal_release_pix_proc(ctx->cal, ctx->pix_proc);
>  }
>  
>  void cal_ctx_start(struct cal_ctx *ctx)
> @@ -489,7 +491,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
>  
>  	/* Configure the CSI-2, pixel processing and write DMA contexts. */
>  	cal_ctx_csi2_config(ctx);
> -	cal_ctx_pix_proc_config(ctx);
> +	if (ctx->use_pix_proc)
> +		cal_ctx_pix_proc_config(ctx);
>  	cal_ctx_wr_dma_config(ctx);
>  
>  	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
> @@ -530,7 +533,8 @@ void cal_ctx_stop(struct cal_ctx *ctx)
>  	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
>  
>  	/* Disable pix proc */
> -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
> +	if (ctx->use_pix_proc)
> +		cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
>  }
>  
>  /* ------------------------------------------------------------------
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 01e05e46e48d..409b7276a1fa 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -223,6 +223,8 @@ struct cal_ctx {
>  	u8			cport;
>  	u8			ppi_ctx;
>  	u8			pix_proc;
> +
> +	bool use_pix_proc;

Indentation ?

How about turning pix_proc to a signed value, and using -1 to indicate
it's not used ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  };
>  
>  extern unsigned int cal_debug;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race
  2021-04-12 11:34 ` [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race Tomi Valkeinen
@ 2021-04-18 13:04   ` Laurent Pinchart
  2021-04-19 12:02     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:04 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:48PM +0300, Tomi Valkeinen wrote:
> I have not noticed any errors due to this, but the DMA configuration
> looks racy. Setting the DMA mode bitfield in CAL_WR_DMA_CTRL supposedly
> enables the DMA. However, the driver currently a) continues configuring
> the DMA after setting the mode, and b) enables the DMA interrupts only
> after setting the mode.
> 
> This probably doesn't cause any issues as there should be no data coming
> in to the DMA yet, but it's still better to fix this.
> 
> Add a new function, cal_ctx_wr_dma_enable(), to set the DMA mode field,
> and call that function only after the DMA config and the irq enabling
> has been done.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index a1d173bd4613..0fef892854ef 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -409,8 +409,6 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>  		      CAL_WR_DMA_CTRL_YSIZE_MASK);
>  	cal_set_field(&val, CAL_WR_DMA_CTRL_DTAG_PIX_DAT,
>  		      CAL_WR_DMA_CTRL_DTAG_MASK);
> -	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
> -		      CAL_WR_DMA_CTRL_MODE_MASK);
>  	cal_set_field(&val, CAL_WR_DMA_CTRL_PATTERN_LINEAR,
>  		      CAL_WR_DMA_CTRL_PATTERN_MASK);
>  	cal_set_field(&val, 1, CAL_WR_DMA_CTRL_STALL_RD_MASK);
> @@ -442,6 +440,15 @@ void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
>  	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->dma_ctx), addr);
>  }
>  
> +static void cal_ctx_wr_dma_enable(struct cal_ctx *ctx)
> +{
> +	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
> +
> +	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
> +		      CAL_WR_DMA_CTRL_MODE_MASK);
> +	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
> +}
> +
>  static void cal_ctx_wr_dma_disable(struct cal_ctx *ctx)
>  {
>  	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
> @@ -500,6 +507,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
>  		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
>  	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
>  		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
> +
> +	cal_ctx_wr_dma_enable(ctx);
>  }

You could also move the IRQ enabling before the call to
cal_ctx_wr_dma_config(), and reorder the configuration in
cal_ctx_wr_dma_config() to write CAL_WR_DMA_CTRL last. That would save a
read-modify-write cycle.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  void cal_ctx_stop(struct cal_ctx *ctx)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx
  2021-04-12 11:34 ` [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx Tomi Valkeinen
@ 2021-04-18 13:06   ` Laurent Pinchart
  2021-04-19 12:07     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:06 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:49PM +0300, Tomi Valkeinen wrote:
> In preparation for supporting multiple virtual channels and datatypes,
> add vc and datatype fields to cal_ctx, initialize them to the currently
> used values, and use those fields when writing to the register.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 6 ++++--
>  drivers/media/platform/ti-vpe/cal.h | 2 ++
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 0fef892854ef..91d2139adc9b 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -335,8 +335,8 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>  	 *  0x2A: RAW8   1 pixel  = 1 byte
>  	 *  0x1E: YUV422 2 pixels = 4 bytes
>  	 */
> -	cal_set_field(&val, 0x1, CAL_CSI2_CTX_DT_MASK);
> -	cal_set_field(&val, 0, CAL_CSI2_CTX_VC_MASK);
> +	cal_set_field(&val, ctx->datatype, CAL_CSI2_CTX_DT_MASK);
> +	cal_set_field(&val, ctx->vc, CAL_CSI2_CTX_VC_MASK);
>  	cal_set_field(&val, ctx->v_fmt.fmt.pix.height, CAL_CSI2_CTX_LINES_MASK);
>  	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
>  	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
> @@ -926,6 +926,8 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>  	ctx->dma_ctx = inst;
>  	ctx->ppi_ctx = inst;
>  	ctx->cport = inst;
> +	ctx->vc = 0;
> +	ctx->datatype = 1;	/* datatype filter disabled */

Could you define a macro in cal_regs.h for this ? You can then drop the
comment.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  	ret = cal_ctx_v4l2_init(ctx);
>  	if (ret)
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 409b7276a1fa..8aa93c92193a 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -223,6 +223,8 @@ struct cal_ctx {
>  	u8			cport;
>  	u8			ppi_ctx;
>  	u8			pix_proc;
> +	u8			vc;
> +	u8			datatype;
>  
>  	bool use_pix_proc;
>  };

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  2021-04-12 11:34 ` [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling Tomi Valkeinen
@ 2021-04-18 13:09   ` Laurent Pinchart
  2021-04-20 10:50     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:09 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:50PM +0300, Tomi Valkeinen wrote:
> cal_ctx_v4l2_register() returns an error code, but the returned error
> code is not handled anywhere. However, we can't really even handle the
> error in any proper way, so lets just drop the return value and make
> sure all error paths have an error print.

Ouch. Doesn't this call for registering the video node earlier, at probe
time, instead of in the async notifier complete callback ?

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-video.c | 16 ++++++++--------
>  drivers/media/platform/ti-vpe/cal.h       |  2 +-
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 064efdc31b28..ea9b13c16a06 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -864,14 +864,16 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
>  	return 0;
>  }
>  
> -int cal_ctx_v4l2_register(struct cal_ctx *ctx)
> +void cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  {
>  	struct video_device *vfd = &ctx->vdev;
>  	int ret;
>  
>  	ret = cal_ctx_v4l2_init_formats(ctx);
> -	if (ret)
> -		return ret;
> +	if (ret) {
> +		ctx_err(ctx, "Failed to init formats: %d\n", ret);
> +		return;
> +	}
>  
>  	if (!cal_mc_api) {
>  		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
> @@ -880,14 +882,14 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  					    NULL, true);
>  		if (ret < 0) {
>  			ctx_err(ctx, "Failed to add source ctrl handler\n");
> -			return ret;
> +			return;
>  		}
>  	}
>  
>  	ret = video_register_device(vfd, VFL_TYPE_VIDEO, cal_video_nr);
>  	if (ret < 0) {
>  		ctx_err(ctx, "Failed to register video device\n");
> -		return ret;
> +		return;
>  	}
>  
>  	ret = media_create_pad_link(&ctx->phy->subdev.entity,
> @@ -899,13 +901,11 @@ int cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  		ctx_err(ctx, "Failed to create media link for context %u\n",
>  			ctx->dma_ctx);
>  		video_unregister_device(vfd);
> -		return ret;
> +		return;
>  	}
>  
>  	ctx_info(ctx, "V4L2 device registered as %s\n",
>  		 video_device_node_name(vfd));
> -
> -	return 0;
>  }
>  
>  void cal_ctx_v4l2_unregister(struct cal_ctx *ctx)
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 8aa93c92193a..ad7d26c803eb 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -310,7 +310,7 @@ void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr);
>  void cal_ctx_start(struct cal_ctx *ctx);
>  void cal_ctx_stop(struct cal_ctx *ctx);
>  
> -int cal_ctx_v4l2_register(struct cal_ctx *ctx);
> +void cal_ctx_v4l2_register(struct cal_ctx *ctx);
>  void cal_ctx_v4l2_unregister(struct cal_ctx *ctx);
>  int cal_ctx_v4l2_init(struct cal_ctx *ctx);
>  void cal_ctx_v4l2_cleanup(struct cal_ctx *ctx);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE
  2021-04-12 11:34 ` [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE Tomi Valkeinen
@ 2021-04-18 13:14   ` Laurent Pinchart
  2021-04-19 12:34     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:14 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:51PM +0300, Tomi Valkeinen wrote:
> cal_camerarx_sd_set_fmt() accepts any value for the format field, but
> there should be no reason to have any other value accepted than
> V4L2_FIELD_NONE. So set the field always to V4L2_FIELD_NONE.

What if the source produces V4L2_FIELD_INTERLACED_(TB|BT) ? Shouldn't we
accept that and propagate it ? Same for V4L2_FIELD_TOP and
V4L2_FIELD_BOTTOM I suppose. V4L2_FIELD_SEQ_(TB|BT) is likely not needed
as I doubt sources will send that. V4L2_FIELD_ALTERNATE is a bit more
tricky, as the driver has to report which field a particular buffer
contains, and I'm not sure we could do so (maybe based on the CSI-2
frame number ?).

I'm fine dropping support for interlaced formats until someone wants to
support them though, it's up to you.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 245c601b992c..880261d53a1d 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -702,10 +702,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
>  	if (!fmtinfo)
>  		fmtinfo = &cal_formats[0];
>  
> -	/*
> -	 * Clamp the size, update the code. The field and colorspace are
> -	 * accepted as-is.
> -	 */
> +	/* Clamp the size, update the code. The colorspace is accepted as-is. */
>  	bpp = ALIGN(fmtinfo->bpp, 8);
>  
>  	format->format.width = clamp_t(unsigned int, format->format.width,
> @@ -715,6 +712,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
>  					CAL_MIN_HEIGHT_LINES,
>  					CAL_MAX_HEIGHT_LINES);
>  	format->format.code = fmtinfo->code;
> +	format->format.field = V4L2_FIELD_NONE;
>  
>  	/* Store the format and propagate it to the source pad. */
>  	fmt = cal_camerarx_get_pad_format(phy, cfg, CAL_CAMERARX_PAD_SINK,

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment
  2021-04-12 11:34 ` [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment Tomi Valkeinen
@ 2021-04-18 13:14   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:14 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:52PM +0300, Tomi Valkeinen wrote:
> Fix a typo in a comment in cal_camerarx_sd_set_fmt().
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 880261d53a1d..25f4692d210e 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -695,7 +695,7 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
>  		return cal_camerarx_sd_get_fmt(sd, cfg, format);
>  
>  	/*
> -	 * Default to the first format is the requested media bus code isn't
> +	 * Default to the first format if the requested media bus code isn't
>  	 * supported.
>  	 */
>  	fmtinfo = cal_format_by_code(format->format.code);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap
  2021-04-12 11:34 ` [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap Tomi Valkeinen
@ 2021-04-18 13:17   ` Laurent Pinchart
  2021-04-19 12:50     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:17 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:53PM +0300, Tomi Valkeinen wrote:
> Commit e5b6b07a1b45dd9d19bec1fa1d60750b0fcf2fb0 ("media: v4l2: Extend

You can abbreviate that to 12 characters if desired.

> VIDIOC_ENUM_FMT to support MC-centric devices") added support to
> enumerate formats based in mbus-code.
> 
> Add this feature to cal driver.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-video.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index ea9b13c16a06..1d9c0fce4b03 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -437,13 +437,28 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
>  static int cal_mc_enum_fmt_vid_cap(struct file *file, void  *priv,
>  				   struct v4l2_fmtdesc *f)
>  {
> +	unsigned int i;
> +	unsigned int idx;
> +
>  	if (f->index >= cal_num_formats)
>  		return -EINVAL;
>  
> -	f->pixelformat = cal_formats[f->index].fourcc;
> -	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

As a shortcut, you could have

	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (!f->mbus_code) {
		f->pixelformat = cal_formats[f->index].fourcc;
		return 0;
	}

> +	idx = 0;
>  
> -	return 0;
> +	for (i = 0; i < cal_num_formats; ++i) {
> +		if (f->mbus_code && cal_formats[i].code != f->mbus_code)

And drop the first condition here, as well as f->type below. Up to you.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +			continue;
> +
> +		if (idx == f->index) {
> +			f->pixelformat = cal_formats[i].fourcc;
> +			f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> +			return 0;
> +		}
> +
> +		idx++;
> +	}
> +
> +	return -EINVAL;
>  }
>  
>  static void cal_mc_try_fmt(struct cal_ctx *ctx, struct v4l2_format *f,

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_*
  2021-04-12 11:34 ` [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_* Tomi Valkeinen
@ 2021-04-18 13:18   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:18 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:54PM +0300, Tomi Valkeinen wrote:
> To make it more obvious if the function in question is dealing with
> media-controller API or the legacy API, rename legacy API functions to
> cal_legacy_*.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-video.c | 46 +++++++++++------------
>  1 file changed, 23 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 1d9c0fce4b03..0494cd04b9a5 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -102,7 +102,7 @@ static const struct cal_format_info *find_format_by_code(struct cal_ctx *ctx,
>  	return NULL;
>  }
>  
> -static int cal_enum_fmt_vid_cap(struct file *file, void  *priv,
> +static int cal_legacy_enum_fmt_vid_cap(struct file *file, void  *priv,
>  				struct v4l2_fmtdesc *f)

Could you update the indentation ? Same below.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
> @@ -189,7 +189,7 @@ static void cal_calc_format_size(struct cal_ctx *ctx,
>  		f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
>  }
>  
> -static int cal_try_fmt_vid_cap(struct file *file, void *priv,
> +static int cal_legacy_try_fmt_vid_cap(struct file *file, void *priv,
>  			       struct v4l2_format *f)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
> @@ -249,7 +249,7 @@ static int cal_try_fmt_vid_cap(struct file *file, void *priv,
>  	return 0;
>  }
>  
> -static int cal_s_fmt_vid_cap(struct file *file, void *priv,
> +static int cal_legacy_s_fmt_vid_cap(struct file *file, void *priv,
>  			     struct v4l2_format *f)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
> @@ -266,7 +266,7 @@ static int cal_s_fmt_vid_cap(struct file *file, void *priv,
>  		return -EBUSY;
>  	}
>  
> -	ret = cal_try_fmt_vid_cap(file, priv, f);
> +	ret = cal_legacy_try_fmt_vid_cap(file, priv, f);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -300,7 +300,7 @@ static int cal_s_fmt_vid_cap(struct file *file, void *priv,
>  	return 0;
>  }
>  
> -static int cal_enum_framesizes(struct file *file, void *fh,
> +static int cal_legacy_enum_framesizes(struct file *file, void *fh,
>  			       struct v4l2_frmsizeenum *fsize)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
> @@ -337,7 +337,7 @@ static int cal_enum_framesizes(struct file *file, void *fh,
>  	return 0;
>  }
>  
> -static int cal_enum_input(struct file *file, void *priv,
> +static int cal_legacy_enum_input(struct file *file, void *priv,
>  			  struct v4l2_input *inp)
>  {
>  	if (inp->index > 0)
> @@ -348,19 +348,19 @@ static int cal_enum_input(struct file *file, void *priv,
>  	return 0;
>  }
>  
> -static int cal_g_input(struct file *file, void *priv, unsigned int *i)
> +static int cal_legacy_g_input(struct file *file, void *priv, unsigned int *i)
>  {
>  	*i = 0;
>  	return 0;
>  }
>  
> -static int cal_s_input(struct file *file, void *priv, unsigned int i)
> +static int cal_legacy_s_input(struct file *file, void *priv, unsigned int i)
>  {
>  	return i > 0 ? -EINVAL : 0;
>  }
>  
>  /* timeperframe is arbitrary and continuous */
> -static int cal_enum_frameintervals(struct file *file, void *priv,
> +static int cal_legacy_enum_frameintervals(struct file *file, void *priv,
>  				   struct v4l2_frmivalenum *fival)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
> @@ -388,27 +388,27 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
>  	return 0;
>  }
>  
> -static int cal_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +static int cal_legacy_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
>  
>  	return v4l2_g_parm_cap(video_devdata(file), ctx->phy->source, a);
>  }
>  
> -static int cal_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +static int cal_legacy_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>  {
>  	struct cal_ctx *ctx = video_drvdata(file);
>  
>  	return v4l2_s_parm_cap(video_devdata(file), ctx->phy->source, a);
>  }
>  
> -static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
> +static const struct v4l2_ioctl_ops cal_ioctl_legacy_ops = {
>  	.vidioc_querycap      = cal_querycap,
> -	.vidioc_enum_fmt_vid_cap  = cal_enum_fmt_vid_cap,
> +	.vidioc_enum_fmt_vid_cap  = cal_legacy_enum_fmt_vid_cap,
>  	.vidioc_g_fmt_vid_cap     = cal_g_fmt_vid_cap,
> -	.vidioc_try_fmt_vid_cap   = cal_try_fmt_vid_cap,
> -	.vidioc_s_fmt_vid_cap     = cal_s_fmt_vid_cap,
> -	.vidioc_enum_framesizes   = cal_enum_framesizes,
> +	.vidioc_try_fmt_vid_cap   = cal_legacy_try_fmt_vid_cap,
> +	.vidioc_s_fmt_vid_cap     = cal_legacy_s_fmt_vid_cap,
> +	.vidioc_enum_framesizes   = cal_legacy_enum_framesizes,
>  	.vidioc_reqbufs       = vb2_ioctl_reqbufs,
>  	.vidioc_create_bufs   = vb2_ioctl_create_bufs,
>  	.vidioc_prepare_buf   = vb2_ioctl_prepare_buf,
> @@ -416,17 +416,17 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
>  	.vidioc_qbuf          = vb2_ioctl_qbuf,
>  	.vidioc_dqbuf         = vb2_ioctl_dqbuf,
>  	.vidioc_expbuf        = vb2_ioctl_expbuf,
> -	.vidioc_enum_input    = cal_enum_input,
> -	.vidioc_g_input       = cal_g_input,
> -	.vidioc_s_input       = cal_s_input,
> -	.vidioc_enum_frameintervals = cal_enum_frameintervals,
> +	.vidioc_enum_input    = cal_legacy_enum_input,
> +	.vidioc_g_input       = cal_legacy_g_input,
> +	.vidioc_s_input       = cal_legacy_s_input,
> +	.vidioc_enum_frameintervals = cal_legacy_enum_frameintervals,
>  	.vidioc_streamon      = vb2_ioctl_streamon,
>  	.vidioc_streamoff     = vb2_ioctl_streamoff,
>  	.vidioc_log_status    = v4l2_ctrl_log_status,
>  	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
>  	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
> -	.vidioc_g_parm		= cal_g_parm,
> -	.vidioc_s_parm		= cal_s_parm,
> +	.vidioc_g_parm		= cal_legacy_g_parm,
> +	.vidioc_s_parm		= cal_legacy_s_parm,
>  };
>  
>  /* ------------------------------------------------------------------
> @@ -966,7 +966,7 @@ int cal_ctx_v4l2_init(struct cal_ctx *ctx)
>  	vfd->queue = q;
>  	snprintf(vfd->name, sizeof(vfd->name), "CAL output %u", ctx->dma_ctx);
>  	vfd->release = video_device_release_empty;
> -	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_video_ops;
> +	vfd->ioctl_ops = cal_mc_api ? &cal_ioctl_mc_ops : &cal_ioctl_legacy_ops;
>  	vfd->lock = &ctx->mutex;
>  	video_set_drvdata(vfd, ctx);
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode
  2021-04-12 11:34 ` [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode Tomi Valkeinen
@ 2021-04-18 13:21   ` Laurent Pinchart
  2021-04-19 13:01     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:21 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:55PM +0300, Tomi Valkeinen wrote:
> CAL driver enumerates mbus codes in the connected subdev to create a
> list of supported formats reported to userspace, and initializes
> ctx->v_fmt and ctx->fmtinfo to one of those formats.
> 
> This works fine for legacy mode, but is not correct for MC mode, and the
> list is not even used in MC mode.
> 
> Fix this by adding a new function, cal_ctx_v4l2_init_mc_format, which
> only initializes ctx->v_fmt and ctx->fmtinfo to a default value.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-video.c | 45 ++++++++++++++++++++---
>  drivers/media/platform/ti-vpe/cal.h       |  2 +-
>  2 files changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 0494cd04b9a5..95066cca128a 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -879,26 +879,59 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
>  	return 0;
>  }
>  
> +static int cal_ctx_v4l2_init_mc_format(struct cal_ctx *ctx)
> +{
> +	const struct cal_format_info *fmtinfo;
> +	struct v4l2_pix_format *pix_fmt = &ctx->v_fmt.fmt.pix;
> +
> +	fmtinfo = cal_format_by_code(MEDIA_BUS_FMT_UYVY8_2X8);

	if (WARN_ON(!fmt_info))
		return;

As this really can't happen.

> +	if (!fmtinfo)
> +		return -EINVAL;
> +
> +	pix_fmt->width = 640;
> +	pix_fmt->height = 480;
> +	pix_fmt->field = V4L2_FIELD_NONE;
> +	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
> +	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
> +	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
> +	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
> +	pix_fmt->pixelformat = fmtinfo->fourcc;
> +
> +	ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> +
> +	/* Save current format */
> +	cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
> +	ctx->fmtinfo = fmtinfo;
> +
> +	return 0;
> +}
> +
>  void cal_ctx_v4l2_register(struct cal_ctx *ctx)
>  {
>  	struct video_device *vfd = &ctx->vdev;
>  	int ret;
>  
> -	ret = cal_ctx_v4l2_init_formats(ctx);
> -	if (ret) {
> -		ctx_err(ctx, "Failed to init formats: %d\n", ret);
> -		return;
> -	}
> -
>  	if (!cal_mc_api) {
>  		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
>  
> +		ret = cal_ctx_v4l2_init_formats(ctx);
> +		if (ret) {
> +			ctx_err(ctx, "Failed to init formats: %d\n", ret);
> +			return;
> +		}
> +
>  		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
>  					    NULL, true);
>  		if (ret < 0) {
>  			ctx_err(ctx, "Failed to add source ctrl handler\n");
>  			return;
>  		}
> +	} else {
> +		ret = cal_ctx_v4l2_init_mc_format(ctx);
> +		if (ret) {
> +			ctx_err(ctx, "Failed to init format: %d\n", ret);
> +			return;
> +		}

And you can drop the error check here.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  	}
>  
>  	ret = video_register_device(vfd, VFL_TYPE_VIDEO, cal_video_nr);
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index ad7d26c803eb..c941d2aec79f 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -213,7 +213,7 @@ struct cal_ctx {
>  	/* Used to store current pixel format */
>  	struct v4l2_format	v_fmt;
>  
> -	/* Current subdev enumerated format */
> +	/* Current subdev enumerated format (legacy) */
>  	const struct cal_format_info	**active_fmt;
>  	unsigned int		num_active_fmt;
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo
  2021-04-12 11:34 ` [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo Tomi Valkeinen
@ 2021-04-18 13:24   ` Laurent Pinchart
  2021-04-19 13:08     ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:24 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:56PM +0300, Tomi Valkeinen wrote:
> struct cal_camerarx has fmtinfo field which is used to point to the
> current active input format. The only place where the field is used is
> cal_camerarx_get_ext_link_freq().
> 
> With multiple streams the whole concept of single input format is not
> valid anymore, so lets remove the field by looking up the format in
> cal_camerarx_get_ext_link_freq(), making it easier to handle the
> multistream-case in the following patches.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal-camerarx.c | 12 ++++++++----
>  drivers/media/platform/ti-vpe/cal.h          |  1 -
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> index 25f4692d210e..efe6513d69e8 100644
> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> @@ -49,8 +49,15 @@ static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
>  {
>  	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = &phy->endpoint.bus.mipi_csi2;
>  	u32 num_lanes = mipi_csi2->num_data_lanes;
> -	u32 bpp = phy->fmtinfo->bpp;
> +	u32 bpp;
>  	s64 freq;
> +	const struct cal_format_info *fmtinfo;

I'd declare this after num_lanes as I like the reverse xmas tree order.

> +
> +	fmtinfo = cal_format_by_code(phy->formats[CAL_CAMERARX_PAD_SINK].code);
> +	if (!fmtinfo)
> +		return -EINVAL;
> +
> +	bpp = fmtinfo->bpp;

I wonder if we'll end up dropping this, as falling back to
V4L2_CID_PIXEL_RATE in v4l2_get_link_freq() makes less sense when using
multiplexed streams. Something to worry about later.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  	freq = v4l2_get_link_freq(phy->source->ctrl_handler, bpp, 2 * num_lanes);
>  	if (freq < 0) {
> @@ -723,9 +730,6 @@ static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd,
>  					  format->which);
>  	*fmt = format->format;
>  
> -	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> -		phy->fmtinfo = fmtinfo;
> -
>  	return 0;
>  }
>  
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index c941d2aec79f..7f35ad5ceac2 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -163,7 +163,6 @@ struct cal_camerarx {
>  	struct v4l2_subdev	subdev;
>  	struct media_pad	pads[2];
>  	struct v4l2_mbus_framefmt	formats[2];
> -	const struct cal_format_info	*fmtinfo;
>  };
>  
>  struct cal_dev {

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts
  2021-04-12 11:34 ` [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts Tomi Valkeinen
@ 2021-04-18 13:29   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:29 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:57PM +0300, Tomi Valkeinen wrote:
> The current driver only ever needs 2 DMA contexts (one per PHY), but we
> need to use more of the 8 contexts to add support for multiple streams.
> 
> Change the code so that we allocate DMA contexts as needed, which at
> this time is 1 per PHY, but could be up to 8.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 38 ++++++++++++-----------------
>  drivers/media/platform/ti-vpe/cal.h |  5 ++--
>  2 files changed, 18 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 91d2139adc9b..781fb14f4c7a 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -657,7 +657,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
>  		/* Clear Interrupt status */
>  		cal_write(cal, CAL_HL_IRQSTATUS(1), status);
>  
> -		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
> +		for (i = 0; i < cal->num_contexts; ++i) {
>  			if (status & CAL_HL_IRQ_WDMA_END_MASK(i))
>  				cal_irq_wdma_end(cal->ctx[i]);
>  		}
> @@ -671,7 +671,7 @@ static irqreturn_t cal_irq(int irq_cal, void *data)
>  		/* Clear Interrupt status */
>  		cal_write(cal, CAL_HL_IRQSTATUS(2), status);
>  
> -		for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
> +		for (i = 0; i < cal->num_contexts; ++i) {
>  			if (status & CAL_HL_IRQ_WDMA_START_MASK(i))
>  				cal_irq_wdma_start(cal->ctx[i]);
>  		}
> @@ -741,10 +741,8 @@ static int cal_async_notifier_complete(struct v4l2_async_notifier *notifier)
>  	unsigned int i;
>  	int ret = 0;
>  
> -	for (i = 0; i < ARRAY_SIZE(cal->ctx); ++i) {
> -		if (cal->ctx[i])
> -			cal_ctx_v4l2_register(cal->ctx[i]);
> -	}
> +	for (i = 0; i < cal->num_contexts; ++i)
> +		cal_ctx_v4l2_register(cal->ctx[i]);
>  
>  	if (cal_mc_api)
>  		ret = v4l2_device_register_subdev_nodes(&cal->v4l2_dev);
> @@ -846,10 +844,8 @@ static void cal_media_unregister(struct cal_dev *cal)
>  	unsigned int i;
>  
>  	/* Unregister all the V4L2 video devices. */
> -	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
> -		if (cal->ctx[i])
> -			cal_ctx_v4l2_unregister(cal->ctx[i]);
> -	}
> +	for (i = 0; i < cal->num_contexts; i++)
> +		cal_ctx_v4l2_unregister(cal->ctx[i]);
>  
>  	cal_async_notifier_unregister(cal);
>  	media_device_unregister(&cal->mdev);
> @@ -896,10 +892,8 @@ static void cal_media_cleanup(struct cal_dev *cal)
>  {
>  	unsigned int i;
>  
> -	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
> -		if (cal->ctx[i])
> -			cal_ctx_v4l2_cleanup(cal->ctx[i]);
> -	}
> +	for (i = 0; i < cal->num_contexts; i++)
> +		cal_ctx_v4l2_cleanup(cal->ctx[i]);
>  
>  	v4l2_device_unregister(&cal->v4l2_dev);
>  	media_device_cleanup(&cal->mdev);
> @@ -1048,7 +1042,6 @@ static int cal_init_camerarx_regmap(struct cal_dev *cal)
>  static int cal_probe(struct platform_device *pdev)
>  {
>  	struct cal_dev *cal;
> -	struct cal_ctx *ctx;
>  	bool connected = false;
>  	unsigned int i;
>  	int ret;
> @@ -1132,12 +1125,14 @@ static int cal_probe(struct platform_device *pdev)
>  		if (!cal->phy[i]->source_node)
>  			continue;
>  
> -		cal->ctx[i] = cal_ctx_create(cal, i);
> -		if (!cal->ctx[i]) {
> -			cal_err(cal, "Failed to create context %u\n", i);
> +		cal->ctx[cal->num_contexts] = cal_ctx_create(cal, i);
> +		if (!cal->ctx[cal->num_contexts]) {
> +			cal_err(cal, "Failed to create context %u\n", cal->num_contexts);

Line wrap.

I would have kept indexing the array using i though. This code will be
reworked later, and for now I think it would make it more readable to
avoid this particular change.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  			ret = -ENODEV;
>  			goto error_context;
>  		}
> +
> +		cal->num_contexts++;
>  	}
>  
>  	/* Register the media device. */
> @@ -1148,11 +1143,8 @@ static int cal_probe(struct platform_device *pdev)
>  	return 0;
>  
>  error_context:
> -	for (i = 0; i < ARRAY_SIZE(cal->ctx); i++) {
> -		ctx = cal->ctx[i];
> -		if (ctx)
> -			cal_ctx_v4l2_cleanup(ctx);
> -	}
> +	for (i = 0; i < cal->num_contexts; i++)
> +		cal_ctx_v4l2_cleanup(cal->ctx[i]);
>  
>  error_camerarx:
>  	for (i = 0; i < cal->data->num_csi2_phy; i++)
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index 7f35ad5ceac2..783876d7cf40 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -29,7 +29,7 @@
>  #include <media/videobuf2-v4l2.h>
>  
>  #define CAL_MODULE_NAME			"cal"
> -#define CAL_NUM_CONTEXT			2
> +#define CAL_MAX_NUM_CONTEXT		8
>  #define CAL_NUM_CSI2_PORTS		2
>  
>  /*
> @@ -182,7 +182,8 @@ struct cal_dev {
>  	/* Camera Core Module handle */
>  	struct cal_camerarx	*phy[CAL_NUM_CSI2_PORTS];
>  
> -	struct cal_ctx		*ctx[CAL_NUM_CONTEXT];
> +	u32 num_contexts;
> +	struct cal_ctx		*ctx[CAL_MAX_NUM_CONTEXT];
>  
>  	struct media_device	mdev;
>  	struct v4l2_device	v4l2_dev;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare
  2021-04-12 11:34 ` [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare Tomi Valkeinen
@ 2021-04-18 13:30   ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-18 13:30 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

Thank you for the patch.

On Mon, Apr 12, 2021 at 02:34:36PM +0300, Tomi Valkeinen wrote:
> In the following patches we need to do context configuration which might
> fail. Add new functions, cal_ctx_prepare and cal_ctx_unprepare, to
> handle such configuration.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/ti-vpe/cal-video.c |  9 +++++++++
>  drivers/media/platform/ti-vpe/cal.c       | 10 ++++++++++
>  drivers/media/platform/ti-vpe/cal.h       |  2 ++
>  3 files changed, 21 insertions(+)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index cf603cc9114c..8e9bbe6beb23 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -708,6 +708,12 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
>  		goto error_pipeline;
>  	}
>  
> +	ret = cal_ctx_prepare(ctx);
> +	if (ret) {
> +		ctx_err(ctx, "Failed to prepare context: %d\n", ret);
> +		goto error_pipeline;
> +	}
> +
>  	spin_lock_irq(&ctx->dma.lock);
>  	buf = list_first_entry(&ctx->dma.queue, struct cal_buffer, list);
>  	ctx->dma.pending = buf;
> @@ -733,6 +739,7 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
>  error_stop:
>  	cal_ctx_stop(ctx);
>  	pm_runtime_put_sync(ctx->cal->dev);
> +	cal_ctx_unprepare(ctx);
>  
>  error_pipeline:
>  	media_pipeline_stop(&ctx->vdev.entity);
> @@ -752,6 +759,8 @@ static void cal_stop_streaming(struct vb2_queue *vq)
>  
>  	pm_runtime_put_sync(ctx->cal->dev);
>  
> +	cal_ctx_unprepare(ctx);
> +
>  	cal_release_buffers(ctx, VB2_BUF_STATE_ERROR);
>  
>  	media_pipeline_stop(&ctx->vdev.entity);
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index b539a9afb3f5..3d57aedbee0a 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -430,6 +430,16 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
>  	return stopped;
>  }
>  
> +int cal_ctx_prepare(struct cal_ctx *ctx)
> +{
> +	return 0;
> +}
> +
> +void cal_ctx_unprepare(struct cal_ctx *ctx)
> +{
> +
> +}
> +
>  void cal_ctx_start(struct cal_ctx *ctx)
>  {
>  	ctx->sequence = 0;
> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> index af46084580bd..09ad20faa9e1 100644
> --- a/drivers/media/platform/ti-vpe/cal.h
> +++ b/drivers/media/platform/ti-vpe/cal.h
> @@ -296,6 +296,8 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
>  					 unsigned int instance);
>  void cal_camerarx_destroy(struct cal_camerarx *phy);
>  
> +int cal_ctx_prepare(struct cal_ctx *ctx);
> +void cal_ctx_unprepare(struct cal_ctx *ctx);
>  void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr);
>  void cal_ctx_start(struct cal_ctx *ctx);
>  void cal_ctx_stop(struct cal_ctx *ctx);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create
  2021-04-17 23:05   ` Laurent Pinchart
@ 2021-04-19  8:24     ` Tomi Valkeinen
  2021-04-19  8:31       ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19  8:24 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 02:05, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:31PM +0300, Tomi Valkeinen wrote:
>> cal_camerarx_create() doesn't handle error returned from
>> cal_camerarx_sd_init_cfg()
> 
> This looks good.
> 
>> and it always runs all the cleanup/free
>> functions in the error code path. The latter doesn't cause any issues at
>> the moment as media_entity_cleanup() is an empty function.
> 
> But this was by design. Do you think we could keep
> media_entity_cleanup() idempotent ? That would simplify error paths (as
> shown here).

It isn't documented. I can change the doc for media_entity_cleanup to 
state it can be called multiple times, if that was the intention, and 
simplify the error handling here.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create
  2021-04-19  8:24     ` Tomi Valkeinen
@ 2021-04-19  8:31       ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-19  8:31 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Apr 19, 2021 at 11:24:01AM +0300, Tomi Valkeinen wrote:
> On 18/04/2021 02:05, Laurent Pinchart wrote:
> > On Mon, Apr 12, 2021 at 02:34:31PM +0300, Tomi Valkeinen wrote:
> >> cal_camerarx_create() doesn't handle error returned from
> >> cal_camerarx_sd_init_cfg()
> > 
> > This looks good.
> > 
> >> and it always runs all the cleanup/free
> >> functions in the error code path. The latter doesn't cause any issues at
> >> the moment as media_entity_cleanup() is an empty function.
> > 
> > But this was by design. Do you think we could keep
> > media_entity_cleanup() idempotent ? That would simplify error paths (as
> > shown here).
> 
> It isn't documented. I can change the doc for media_entity_cleanup to 
> state it can be called multiple times, if that was the intention, and 
> simplify the error handling here.

That would be my preference. media_entity_cleanup() isn't
performance-sensitive, so I'd favour ease of use and simplicity of error
handling in drivers.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 09/28] media: ti-vpe: cal: Add PPI context
  2021-04-18 12:17   ` Laurent Pinchart
@ 2021-04-19  9:01     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19  9:01 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:17, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:38PM +0300, Tomi Valkeinen wrote:
>> CAL has 8 PPI contexts per PHY, which are used to tag the incoming data.
>> The current driver only uses the first PPI, but we need to support all
>> of them to implement multi-stream support.
>>
>> Add a ppi_ctx field to cal_ctx, which indicates which of the 8 PPI
>> contexts is used for the particular cal_ctx. Also clean up the PPI
>> context register macros to take the PPI context number as a parameter.
> 
> As far as I can tell, the TRMs don't mention "PPI contexts". PPI stands
> for PHY Protocol Interface, it does identify a particular physical
> interface. Would it be better to rename ppi_ctx to csi2_ctx ?  This
> would match the register names too.

At least DRA76 TRM says, for example, these:

"Number of contexts for PPI interface #0"
"The PPI context IDs of interleaved streams must match."
"Each PPI FSM has 8 copies of the CAL_CSI2_CTXy_l (y = [0 to 7],
CAL_CSI2_CTX0_l through CAL_CSI2_CTX7_l) state registers (that is, 
contexts)."

It's true changing ppi_ctx to csi2_ctx would match the register names 
neatly. But then again, the TRM doesn't mention CSI2 context, as far as 
I can tell.

However, I think csi2_ctx is more understandable than ppi_ctx. So 
perhaps I'll change it.

>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c      | 10 ++++++----
>>   drivers/media/platform/ti-vpe/cal.h      |  1 +
>>   drivers/media/platform/ti-vpe/cal_regs.h | 18 ++----------------
>>   3 files changed, 9 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index 3d57aedbee0a..c550eeb27e79 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -294,7 +294,7 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>>   {
>>   	u32 val;
>>   
>> -	val = cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index));
>> +	val = cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx));
>>   	cal_set_field(&val, ctx->cport, CAL_CSI2_CTX_CPORT_MASK);
>>   	/*
>>   	 * DT type: MIPI CSI-2 Specs
>> @@ -310,9 +310,10 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>>   	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
>>   	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
>>   		      CAL_CSI2_CTX_PACK_MODE_MASK);
>> -	cal_write(ctx->cal, CAL_CSI2_CTX0(ctx->index), val);
>> -	ctx_dbg(3, ctx, "CAL_CSI2_CTX0(%d) = 0x%08x\n", ctx->index,
>> -		cal_read(ctx->cal, CAL_CSI2_CTX0(ctx->index)));
>> +	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), val);
>> +	ctx_dbg(3, ctx, "CAL_CSI2_CTX%d(%d) = 0x%08x\n",
>> +		ctx->phy->instance, ctx->ppi_ctx,
>> +		cal_read(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx)));
>>   }
>>   
>>   static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
>> @@ -854,6 +855,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>>   	ctx->cal = cal;
>>   	ctx->phy = cal->phy[inst];
>>   	ctx->index = inst;
>> +	ctx->ppi_ctx = inst;
> 
> To avoid a functional change in this patch, should this be = 0 ?

Define "functional change" =). The context used may be different after 
this patch, but there's no change in how the HW functions. I changed it 
to 'inst' here, instead of keeping it as 0, as this works fine for both 
the legacy and new functionality and thus I don't need to remember to 
change it later.

I should mention this in the commit desc, though.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context
  2021-04-18 12:20   ` Laurent Pinchart
  2021-04-18 12:23     ` Laurent Pinchart
@ 2021-04-19  9:17     ` Tomi Valkeinen
  1 sibling, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19  9:17 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:20, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:39PM +0300, Tomi Valkeinen wrote:
>> CAL has 4 pixel processing contexts (PIX PROC) of which the driver
>> currently uses pix proc 0 for PHY0, and pix proc 1 for PHY1 (as the
>> driver supports only a single source per PHY).
>>
>> Add a pix_proc field to cal_ctx to allow us to use different pix proc
>> contexts in the future
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c | 9 +++++----
>>   drivers/media/platform/ti-vpe/cal.h | 1 +
>>   2 files changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index c550eeb27e79..3dc83c66fd96 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -355,16 +355,16 @@ static void cal_ctx_pix_proc_config(struct cal_ctx *ctx)
>>   		break;
>>   	}
>>   
>> -	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->index));
>> +	val = cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc));
>>   	cal_set_field(&val, extract, CAL_PIX_PROC_EXTRACT_MASK);
>>   	cal_set_field(&val, CAL_PIX_PROC_DPCMD_BYPASS, CAL_PIX_PROC_DPCMD_MASK);
>>   	cal_set_field(&val, CAL_PIX_PROC_DPCME_BYPASS, CAL_PIX_PROC_DPCME_MASK);
>>   	cal_set_field(&val, pack, CAL_PIX_PROC_PACK_MASK);
>>   	cal_set_field(&val, ctx->cport, CAL_PIX_PROC_CPORT_MASK);
>>   	cal_set_field(&val, 1, CAL_PIX_PROC_EN_MASK);
>> -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->index), val);
>> -	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->index,
>> -		cal_read(ctx->cal, CAL_PIX_PROC(ctx->index)));
>> +	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), val);
>> +	ctx_dbg(3, ctx, "CAL_PIX_PROC(%d) = 0x%08x\n", ctx->pix_proc,
> 
> While at it, you could s/%d/%u/
> 
>> +		cal_read(ctx->cal, CAL_PIX_PROC(ctx->pix_proc)));
> 
> And should we use val here instead of reading the value back ?

I think it's usually good to read the value from the register. It'll 
show what the register value really is, not what we thought we wrote. 
Usually those two should be the same, but in some cases there are 
read-only fields or non-writeable areas.

That said, I'm not sure if any of the registers printed in cal.c have 
any of those fields, so... I don't feel strongly either way, but I also 
don't see benefit in doing the change (verifying there are no read-only 
fields, and fixing the conflicts).

I can change this and the other similar cases if you have a reason why 
it's better =).

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros
  2021-04-18 12:32   ` Laurent Pinchart
@ 2021-04-19 10:29     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 10:29 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:32, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:42PM +0300, Tomi Valkeinen wrote:
>> The macros related to CAL_CSI2_VC_IRQ can be handled better by having
>> the VC number as a macro parameter.
>>
>> Note that the macros are not used anywhere yet, so no other changes are
>> needed.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal_regs.h | 30 +++++-------------------
>>   1 file changed, 6 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal_regs.h b/drivers/media/platform/ti-vpe/cal_regs.h
>> index 93d9bf1f3c00..ed658175a444 100644
>> --- a/drivers/media/platform/ti-vpe/cal_regs.h
>> +++ b/drivers/media/platform/ti-vpe/cal_regs.h
>> @@ -406,30 +406,12 @@
>>   #define CAL_CSI2_TIMING_STOP_STATE_X16_IO1_MASK		BIT(14)
>>   #define CAL_CSI2_TIMING_FORCE_RX_MODE_IO1_MASK		BIT(15)
>>   
>> -#define CAL_CSI2_VC_IRQ_FS_IRQ_0_MASK			BIT(0)
>> -#define CAL_CSI2_VC_IRQ_FE_IRQ_0_MASK			BIT(1)
>> -#define CAL_CSI2_VC_IRQ_LS_IRQ_0_MASK			BIT(2)
>> -#define CAL_CSI2_VC_IRQ_LE_IRQ_0_MASK			BIT(3)
>> -#define CAL_CSI2_VC_IRQ_CS_IRQ_0_MASK			BIT(4)
>> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_0_MASK	BIT(5)
>> -#define CAL_CSI2_VC_IRQ_FS_IRQ_1_MASK			BIT(8)
>> -#define CAL_CSI2_VC_IRQ_FE_IRQ_1_MASK			BIT(9)
>> -#define CAL_CSI2_VC_IRQ_LS_IRQ_1_MASK			BIT(10)
>> -#define CAL_CSI2_VC_IRQ_LE_IRQ_1_MASK			BIT(11)
>> -#define CAL_CSI2_VC_IRQ_CS_IRQ_1_MASK			BIT(12)
>> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_1_MASK	BIT(13)
>> -#define CAL_CSI2_VC_IRQ_FS_IRQ_2_MASK			BIT(16)
>> -#define CAL_CSI2_VC_IRQ_FE_IRQ_2_MASK			BIT(17)
>> -#define CAL_CSI2_VC_IRQ_LS_IRQ_2_MASK			BIT(18)
>> -#define CAL_CSI2_VC_IRQ_LE_IRQ_2_MASK			BIT(19)
>> -#define CAL_CSI2_VC_IRQ_CS_IRQ_2_MASK			BIT(20)
>> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_2_MASK	BIT(21)
>> -#define CAL_CSI2_VC_IRQ_FS_IRQ_3_MASK			BIT(24)
>> -#define CAL_CSI2_VC_IRQ_FE_IRQ_3_MASK			BIT(25)
>> -#define CAL_CSI2_VC_IRQ_LS_IRQ_3_MASK			BIT(26)
>> -#define CAL_CSI2_VC_IRQ_LE_IRQ_3_MASK			BIT(27)
>> -#define CAL_CSI2_VC_IRQ_CS_IRQ_3_MASK			BIT(28)
>> -#define CAL_CSI2_VC_IRQ_ECC_CORRECTION0_IRQ_3_MASK	BIT(29)
>> +#define CAL_CSI2_VC_IRQ_FS_IRQ_MASK(n)			BIT(0 + (n * 8))
> 
> This should be BIT(0 + (n) * 8). Same below.
> 
> As they're single bits, I would have dropped the _MASK suffix.

All the BIT(x) macros use _MASK suffix in the driver.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 14/28] media: ti-vpe: cal: catch VC errors
  2021-04-18 12:38   ` Laurent Pinchart
@ 2021-04-19 11:19     ` Tomi Valkeinen
  2021-04-28 23:44       ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 11:19 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:38, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:43PM +0300, Tomi Valkeinen wrote:
>> CAL driver currently ignores VC related errors. To help catch error
>> conditions, enable all the VC error interrupts and handle them in the
>> interrupt handler by printing an error.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal-camerarx.c | 23 ++++++++++++++++----
>>   drivers/media/platform/ti-vpe/cal.c          |  9 ++++++++
>>   2 files changed, 28 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> index 974fcbb19547..0354f311c5d2 100644
>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> @@ -226,24 +226,39 @@ static void cal_camerarx_enable_irqs(struct cal_camerarx *phy)
>>   		CAL_CSI2_COMPLEXIO_IRQ_FIFO_OVR_MASK |
>>   		CAL_CSI2_COMPLEXIO_IRQ_SHORT_PACKET_MASK |
>>   		CAL_CSI2_COMPLEXIO_IRQ_ECC_NO_CORRECTION_MASK;
>> -
>> -	/* Enable CIO error IRQs. */
>> +	const u32 vc_err_mask =
>> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(0) |
>> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(1) |
>> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(2) |
>> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(3) |
>> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(0) |
>> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(1) |
>> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(2) |
>> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(3);
>> +
>> +	/* Enable CIO & VC error IRQs. */
>>   	cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
>> -		  CAL_HL_IRQ_CIO_MASK(phy->instance));
>> +		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));
> 
> Line wrap ? Same in multiple places below. I know there's no strict 80
> columns limit anymore, but I don't think longer lines help with
> readability in this patch (not to mention the coding style inconsistency
> with the rest of the driver).

Well, I disagree, but I guess that's in the eye of the beholder.

If we have a coding style with strict 80 column limit, then there are 
other places I need to start fixing too. My personal coding style is 
such that around 80 columns I start thinking about splitting if it can 
be done without any messiness, around 100 I seriously try to split it, 
and around 120 I think it's broken.

I can change this and the other similar line, the end result is only 
slightly messier, but...

>> +
>> +			if (status & CAL_HL_IRQ_VC_MASK(i)) {
>> +				u32 vc_stat = cal_read(cal, CAL_CSI2_VC_IRQSTATUS(i));
>> +
>> +				dev_err_ratelimited(cal->dev,
>> +						    "CIO%u VC error: %#08x\n", i, vc_stat);
>> +
>> +				cal_write(cal, CAL_CSI2_VC_IRQSTATUS(i), vc_stat);
>> +			}

...especially for this part sticking to 80 columns uglifies the code.

u32 vc_stat =
	cal_read(cal,
		 CAL_CSI2_VC_IRQSTATUS(i));

or

u32 cio_stat = cal_read(cal,
	CAL_CSI2_COMPLEXIO_IRQSTATUS(i));

I could split parts to a separate function, but I don't think the end 
result would be better.

I think we discuss the 80-column problem almost in every series. Maybe 
we need to agree to some clear predefined rules to avoid future 
discussions about this? =)

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-18 12:46   ` Laurent Pinchart
@ 2021-04-19 11:29     ` Tomi Valkeinen
  2021-04-28 23:57       ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 11:29 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:46, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
>> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
>> will break an active capture), but the RESET_DONE bit never changes to
>> "reset is ongoing" state. Thus we always get a timeout.
>>
>> Drop the wait, as it seems to achieve nothing.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
>>   1 file changed, 2 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> index 0354f311c5d2..245c601b992c 100644
>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>>   
>>   static void cal_camerarx_stop(struct cal_camerarx *phy)
>>   {
>> -	unsigned int i;
>>   	int ret;
>>   
>>   	cal_camerarx_ppi_disable(phy);
>> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
>>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
>>   
>> -	/* Wait for power down completion */
>> -	for (i = 0; i < 10; i++) {
>> -		if (cal_read_field(phy->cal,
>> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
>> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
>> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
> 
> Isn't this the wrong condition ? I would have expected
> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
> you always get a timeout.

No, I don't think so. The complexio reset is set active just before the 
wait. So the reset status should show reset ongoing, until at some point 
we release the reset (we do that when starting the PHY again).

The TRM doesn't talk about this, though. So, I guess the status might go 
to RESETONGOING for a very short time and back to RESETCOMPLETED before 
the code can see the RESETONGOING. But I suspect the status just stays 
at RESETCOMPLETED.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically
  2021-04-18 12:59   ` Laurent Pinchart
@ 2021-04-19 11:45     ` Tomi Valkeinen
  2021-04-29  0:04       ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 11:45 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 15:59, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:46PM +0300, Tomi Valkeinen wrote:
>> CAL has 4 pixel processing units but the units are not needed e.g. for
>> metadata. As we could be capturing 4 pixel streams and 4 metadata
>> streams, i.e. using 8 DMA contexts, we cannot assign a pixel processing
>> unit to every DMA context. Instead we need to reserve a pixel processing
>> unit only when needed.
>>
>> Add functions to reserve and release a pix proc unit, and use them in
>> cal_ctx_prepare/unprepare. Note that for the time being we still always
>> reserve a pix proc unit.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c | 44 +++++++++++++++++++++++++++--
>>   drivers/media/platform/ti-vpe/cal.h |  2 ++
>>   2 files changed, 44 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index a6ca341c98bd..e397f59d3bbc 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -290,6 +290,37 @@ void cal_quickdump_regs(struct cal_dev *cal)
>>    * ------------------------------------------------------------------
>>    */
>>   
>> +#define CAL_MAX_PIX_PROC 4
>> +
>> +static int cal_reserve_pix_proc(struct cal_dev *cal)
>> +{
>> +	unsigned long ret;
>> +
>> +	spin_lock(&cal->v4l2_dev.lock);
>> +
>> +	ret = find_first_zero_bit(&cal->reserve_pix_proc_mask, CAL_MAX_PIX_PROC);
>> +
>> +	if (ret == CAL_MAX_PIX_PROC) {
>> +		spin_unlock(&cal->v4l2_dev.lock);
>> +		return -ENOSPC;
>> +	}
>> +
>> +	cal->reserve_pix_proc_mask |= BIT(ret);
>> +
>> +	spin_unlock(&cal->v4l2_dev.lock);
>> +
>> +	return ret;
>> +}
>> +
>> +static void cal_release_pix_proc(struct cal_dev *cal, unsigned int pix_proc_num)
>> +{
>> +	spin_lock(&cal->v4l2_dev.lock);
>> +
>> +	cal->reserve_pix_proc_mask &= ~BIT(pix_proc_num);
>> +
>> +	spin_unlock(&cal->v4l2_dev.lock);
>> +}
>> +
>>   static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>>   {
>>   	u32 val;
>> @@ -433,12 +464,22 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
>>   
>>   int cal_ctx_prepare(struct cal_ctx *ctx)
>>   {
>> +	int ret;
>> +
>> +	ret = cal_reserve_pix_proc(ctx->cal);
>> +	if (ret < 0) {
>> +		ctx_err(ctx, "Failed to reserve pix proc: %d\n", ret);
>> +		return ret;
>> +	}
>> +
>> +	ctx->pix_proc = ret;
> 
> I wonder if this is the right place to allocate a context, it may be
> better to reject invalid pipeline configurations earlier on. It's fine
> for now, we can revisit this in subsequent patches, with the full
> multiplexed streams implementation.

Earlier than what? Even before cal_start_streaming()? I guess we could 
do this in cal_vb2_ioctl_reqbufs and cal_vb2_ioctl_create_bufs, but then 
I'm not sure where to free the pix proc.

> Another option would be to allocate the context in cal_ctx_create() for
> now, with a call to cal_reserve_pix_proc(), and move it later in the
> context of the patch series that implements support for multiplexed
> streams.

For now cal_reserve_pix_proc() will always succeed, as we have 4 pix 
procs but only ever allocate 2 at the same time. If there is a better 
place to do this for multiplexed streams, which is not available yet at 
this patch, then I agree, we could just do this in cal_ctx_create until 
we have that better place available.

>> +
>>   	return 0;
>>   }
>>   
>>   void cal_ctx_unprepare(struct cal_ctx *ctx)
>>   {
>> -
>> +	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
>>   }
>>   
>>   void cal_ctx_start(struct cal_ctx *ctx)
>> @@ -872,7 +913,6 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>>   	ctx->dma_ctx = inst;
>>   	ctx->ppi_ctx = inst;
>>   	ctx->cport = inst;
>> -	ctx->pix_proc = inst;
>>   
>>   	ret = cal_ctx_v4l2_init(ctx);
>>   	if (ret)
>> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
>> index c34b843d2019..01e05e46e48d 100644
>> --- a/drivers/media/platform/ti-vpe/cal.h
>> +++ b/drivers/media/platform/ti-vpe/cal.h
>> @@ -188,6 +188,8 @@ struct cal_dev {
>>   	struct media_device	mdev;
>>   	struct v4l2_device	v4l2_dev;
>>   	struct v4l2_async_notifier notifier;
>> +
>> +	unsigned long reserve_pix_proc_mask;
> 
> I would have named this used_pix_proc_mask.

The name has a typo, and should actually be 'reserved_pix_proc_mask'. 
Doesn't 'used' mean that something was used, but may not be used 
anymore? So... in_use_pix_proc_mask? 'active'? I don't know, I like 
'reserved' best here.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field
  2021-04-18 13:00   ` Laurent Pinchart
@ 2021-04-19 11:53     ` Tomi Valkeinen
  2021-04-29  0:07       ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 11:53 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:00, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:47PM +0300, Tomi Valkeinen wrote:
>> We already have functions to reserve and release a pix proc unit, but we
>> always reserve such and the code expects the pix proc unit to be used.
>>
>> Add a new field, 'use_pix_proc', to indicate if the pix prox unit has
>> been reserved and should be used. Use the flag to skip programming pix
>> proc unit when not needed.
>>
>> Note that we still always set the use_pix_proc flag to true.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c | 10 +++++++---
>>   drivers/media/platform/ti-vpe/cal.h |  2 ++
>>   2 files changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index e397f59d3bbc..a1d173bd4613 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -473,13 +473,15 @@ int cal_ctx_prepare(struct cal_ctx *ctx)
>>   	}
>>   
>>   	ctx->pix_proc = ret;
>> +	ctx->use_pix_proc = true;
>>   
>>   	return 0;
>>   }
>>   
>>   void cal_ctx_unprepare(struct cal_ctx *ctx)
>>   {
>> -	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
>> +	if (ctx->use_pix_proc)
>> +		cal_release_pix_proc(ctx->cal, ctx->pix_proc);
>>   }
>>   
>>   void cal_ctx_start(struct cal_ctx *ctx)
>> @@ -489,7 +491,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
>>   
>>   	/* Configure the CSI-2, pixel processing and write DMA contexts. */
>>   	cal_ctx_csi2_config(ctx);
>> -	cal_ctx_pix_proc_config(ctx);
>> +	if (ctx->use_pix_proc)
>> +		cal_ctx_pix_proc_config(ctx);
>>   	cal_ctx_wr_dma_config(ctx);
>>   
>>   	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
>> @@ -530,7 +533,8 @@ void cal_ctx_stop(struct cal_ctx *ctx)
>>   	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
>>   
>>   	/* Disable pix proc */
>> -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
>> +	if (ctx->use_pix_proc)
>> +		cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
>>   }
>>   
>>   /* ------------------------------------------------------------------
>> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
>> index 01e05e46e48d..409b7276a1fa 100644
>> --- a/drivers/media/platform/ti-vpe/cal.h
>> +++ b/drivers/media/platform/ti-vpe/cal.h
>> @@ -223,6 +223,8 @@ struct cal_ctx {
>>   	u8			cport;
>>   	u8			ppi_ctx;
>>   	u8			pix_proc;
>> +
>> +	bool use_pix_proc;
> 
> Indentation ?
> 
> How about turning pix_proc to a signed value, and using -1 to indicate
> it's not used ?

I considered that. But then, instead of "if (ctx->use_pix_proc)" I would 
have "if (ctx->use_pix_proc >= 0)". I think the former is better. And 
having a non-zero default value always makes me a bit uneasy.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race
  2021-04-18 13:04   ` Laurent Pinchart
@ 2021-04-19 12:02     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 12:02 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:04, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:48PM +0300, Tomi Valkeinen wrote:
>> I have not noticed any errors due to this, but the DMA configuration
>> looks racy. Setting the DMA mode bitfield in CAL_WR_DMA_CTRL supposedly
>> enables the DMA. However, the driver currently a) continues configuring
>> the DMA after setting the mode, and b) enables the DMA interrupts only
>> after setting the mode.
>>
>> This probably doesn't cause any issues as there should be no data coming
>> in to the DMA yet, but it's still better to fix this.
>>
>> Add a new function, cal_ctx_wr_dma_enable(), to set the DMA mode field,
>> and call that function only after the DMA config and the irq enabling
>> has been done.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c | 13 +++++++++++--
>>   1 file changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index a1d173bd4613..0fef892854ef 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -409,8 +409,6 @@ static void cal_ctx_wr_dma_config(struct cal_ctx *ctx)
>>   		      CAL_WR_DMA_CTRL_YSIZE_MASK);
>>   	cal_set_field(&val, CAL_WR_DMA_CTRL_DTAG_PIX_DAT,
>>   		      CAL_WR_DMA_CTRL_DTAG_MASK);
>> -	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
>> -		      CAL_WR_DMA_CTRL_MODE_MASK);
>>   	cal_set_field(&val, CAL_WR_DMA_CTRL_PATTERN_LINEAR,
>>   		      CAL_WR_DMA_CTRL_PATTERN_MASK);
>>   	cal_set_field(&val, 1, CAL_WR_DMA_CTRL_STALL_RD_MASK);
>> @@ -442,6 +440,15 @@ void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr)
>>   	cal_write(ctx->cal, CAL_WR_DMA_ADDR(ctx->dma_ctx), addr);
>>   }
>>   
>> +static void cal_ctx_wr_dma_enable(struct cal_ctx *ctx)
>> +{
>> +	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
>> +
>> +	cal_set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
>> +		      CAL_WR_DMA_CTRL_MODE_MASK);
>> +	cal_write(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx), val);
>> +}
>> +
>>   static void cal_ctx_wr_dma_disable(struct cal_ctx *ctx)
>>   {
>>   	u32 val = cal_read(ctx->cal, CAL_WR_DMA_CTRL(ctx->dma_ctx));
>> @@ -500,6 +507,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
>>   		  CAL_HL_IRQ_WDMA_END_MASK(ctx->dma_ctx));
>>   	cal_write(ctx->cal, CAL_HL_IRQENABLE_SET(2),
>>   		  CAL_HL_IRQ_WDMA_START_MASK(ctx->dma_ctx));
>> +
>> +	cal_ctx_wr_dma_enable(ctx);
>>   }
> 
> You could also move the IRQ enabling before the call to
> cal_ctx_wr_dma_config(), and reorder the configuration in
> cal_ctx_wr_dma_config() to write CAL_WR_DMA_CTRL last. That would save a
> read-modify-write cycle.

Yes, I did that initially, but then ended up with a separate dma_enable 
call for clarity (I find it a bit misleading that cal_ctx_wr_dma_config 
would start the dma) and to have matching dma_enable and dma_disable calls.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx
  2021-04-18 13:06   ` Laurent Pinchart
@ 2021-04-19 12:07     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 12:07 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:06, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:49PM +0300, Tomi Valkeinen wrote:
>> In preparation for supporting multiple virtual channels and datatypes,
>> add vc and datatype fields to cal_ctx, initialize them to the currently
>> used values, and use those fields when writing to the register.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal.c | 6 ++++--
>>   drivers/media/platform/ti-vpe/cal.h | 2 ++
>>   2 files changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
>> index 0fef892854ef..91d2139adc9b 100644
>> --- a/drivers/media/platform/ti-vpe/cal.c
>> +++ b/drivers/media/platform/ti-vpe/cal.c
>> @@ -335,8 +335,8 @@ static void cal_ctx_csi2_config(struct cal_ctx *ctx)
>>   	 *  0x2A: RAW8   1 pixel  = 1 byte
>>   	 *  0x1E: YUV422 2 pixels = 4 bytes
>>   	 */
>> -	cal_set_field(&val, 0x1, CAL_CSI2_CTX_DT_MASK);
>> -	cal_set_field(&val, 0, CAL_CSI2_CTX_VC_MASK);
>> +	cal_set_field(&val, ctx->datatype, CAL_CSI2_CTX_DT_MASK);
>> +	cal_set_field(&val, ctx->vc, CAL_CSI2_CTX_VC_MASK);
>>   	cal_set_field(&val, ctx->v_fmt.fmt.pix.height, CAL_CSI2_CTX_LINES_MASK);
>>   	cal_set_field(&val, CAL_CSI2_CTX_ATT_PIX, CAL_CSI2_CTX_ATT_MASK);
>>   	cal_set_field(&val, CAL_CSI2_CTX_PACK_MODE_LINE,
>> @@ -926,6 +926,8 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
>>   	ctx->dma_ctx = inst;
>>   	ctx->ppi_ctx = inst;
>>   	ctx->cport = inst;
>> +	ctx->vc = 0;
>> +	ctx->datatype = 1;	/* datatype filter disabled */
> 
> Could you define a macro in cal_regs.h for this ? You can then drop the
> comment.

Yes, good idea. I added:

#define CAL_CSI2_CTX_DT_DISABLED	0
#define CAL_CSI2_CTX_DT_ANY		1

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE
  2021-04-18 13:14   ` Laurent Pinchart
@ 2021-04-19 12:34     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 12:34 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:14, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:51PM +0300, Tomi Valkeinen wrote:
>> cal_camerarx_sd_set_fmt() accepts any value for the format field, but
>> there should be no reason to have any other value accepted than
>> V4L2_FIELD_NONE. So set the field always to V4L2_FIELD_NONE.
> 
> What if the source produces V4L2_FIELD_INTERLACED_(TB|BT) ? Shouldn't we
> accept that and propagate it ? Same for V4L2_FIELD_TOP and
> V4L2_FIELD_BOTTOM I suppose. V4L2_FIELD_SEQ_(TB|BT) is likely not needed
> as I doubt sources will send that. V4L2_FIELD_ALTERNATE is a bit more
> tricky, as the driver has to report which field a particular buffer
> contains, and I'm not sure we could do so (maybe based on the CSI-2
> frame number ?).
> 
> I'm fine dropping support for interlaced formats until someone wants to
> support them though, it's up to you.

To be honest, I kind of presumed that interlace is not supported. But I 
can see it mentioned very shortly in the TRM. If I recall right, I added 
this because v4l2-compliance complained as the driver accepted any value.

I'll read about the v4l2 interlace handling to understand this better.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap
  2021-04-18 13:17   ` Laurent Pinchart
@ 2021-04-19 12:50     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 12:50 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:17, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:53PM +0300, Tomi Valkeinen wrote:
>> Commit e5b6b07a1b45dd9d19bec1fa1d60750b0fcf2fb0 ("media: v4l2: Extend
> 
> You can abbreviate that to 12 characters if desired.
> 
>> VIDIOC_ENUM_FMT to support MC-centric devices") added support to
>> enumerate formats based in mbus-code.
>>
>> Add this feature to cal driver.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal-video.c | 21 ++++++++++++++++++---
>>   1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
>> index ea9b13c16a06..1d9c0fce4b03 100644
>> --- a/drivers/media/platform/ti-vpe/cal-video.c
>> +++ b/drivers/media/platform/ti-vpe/cal-video.c
>> @@ -437,13 +437,28 @@ static const struct v4l2_ioctl_ops cal_ioctl_video_ops = {
>>   static int cal_mc_enum_fmt_vid_cap(struct file *file, void  *priv,
>>   				   struct v4l2_fmtdesc *f)
>>   {
>> +	unsigned int i;
>> +	unsigned int idx;
>> +
>>   	if (f->index >= cal_num_formats)
>>   		return -EINVAL;
>>   
>> -	f->pixelformat = cal_formats[f->index].fourcc;
>> -	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> 
> As a shortcut, you could have
> 
> 	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> 
> 	if (!f->mbus_code) {
> 		f->pixelformat = cal_formats[f->index].fourcc;
> 		return 0;
> 	}
> 
>> +	idx = 0;
>>   
>> -	return 0;
>> +	for (i = 0; i < cal_num_formats; ++i) {
>> +		if (f->mbus_code && cal_formats[i].code != f->mbus_code)
> 
> And drop the first condition here, as well as f->type below. Up to you.

True, but in a patch that adds metadata support (not posted) I add also 
metadata formats into the cal_formats array, and I need to iterate and 
skip the possible metadata-formats even for !f->mbus_code case.

I'm not sure if that approach is good or not (I also tried separate 
metadata format array but that just caused mess elsewhere), but for the 
time being I'd rather keep this as it is to easily allow adding the 
metadata formats.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode
  2021-04-18 13:21   ` Laurent Pinchart
@ 2021-04-19 13:01     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 13:01 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:21, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:55PM +0300, Tomi Valkeinen wrote:
>> CAL driver enumerates mbus codes in the connected subdev to create a
>> list of supported formats reported to userspace, and initializes
>> ctx->v_fmt and ctx->fmtinfo to one of those formats.
>>
>> This works fine for legacy mode, but is not correct for MC mode, and the
>> list is not even used in MC mode.
>>
>> Fix this by adding a new function, cal_ctx_v4l2_init_mc_format, which
>> only initializes ctx->v_fmt and ctx->fmtinfo to a default value.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal-video.c | 45 ++++++++++++++++++++---
>>   drivers/media/platform/ti-vpe/cal.h       |  2 +-
>>   2 files changed, 40 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
>> index 0494cd04b9a5..95066cca128a 100644
>> --- a/drivers/media/platform/ti-vpe/cal-video.c
>> +++ b/drivers/media/platform/ti-vpe/cal-video.c
>> @@ -879,26 +879,59 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx)
>>   	return 0;
>>   }
>>   
>> +static int cal_ctx_v4l2_init_mc_format(struct cal_ctx *ctx)
>> +{
>> +	const struct cal_format_info *fmtinfo;
>> +	struct v4l2_pix_format *pix_fmt = &ctx->v_fmt.fmt.pix;
>> +
>> +	fmtinfo = cal_format_by_code(MEDIA_BUS_FMT_UYVY8_2X8);
> 
> 	if (WARN_ON(!fmt_info))
> 		return;
> 
> As this really can't happen.

Can't, but if it does and we don't handle the error, the driver will 
probably crash somewhere as ctx->fmtinfo is NULL. So maybe just drop the 
'if' totally, and we'll get that crash early, below via fmtinfo->fourcc.

> 
>> +	if (!fmtinfo)
>> +		return -EINVAL;
>> +
>> +	pix_fmt->width = 640;
>> +	pix_fmt->height = 480;
>> +	pix_fmt->field = V4L2_FIELD_NONE;
>> +	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
>> +	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
>> +	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
>> +	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
>> +	pix_fmt->pixelformat = fmtinfo->fourcc;
>> +
>> +	ctx->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
>> +
>> +	/* Save current format */
>> +	cal_calc_format_size(ctx, fmtinfo, &ctx->v_fmt);
>> +	ctx->fmtinfo = fmtinfo;
>> +
>> +	return 0;
>> +}
>> +
>>   void cal_ctx_v4l2_register(struct cal_ctx *ctx)
>>   {
>>   	struct video_device *vfd = &ctx->vdev;
>>   	int ret;
>>   
>> -	ret = cal_ctx_v4l2_init_formats(ctx);
>> -	if (ret) {
>> -		ctx_err(ctx, "Failed to init formats: %d\n", ret);
>> -		return;
>> -	}
>> -
>>   	if (!cal_mc_api) {
>>   		struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
>>   
>> +		ret = cal_ctx_v4l2_init_formats(ctx);
>> +		if (ret) {
>> +			ctx_err(ctx, "Failed to init formats: %d\n", ret);
>> +			return;
>> +		}
>> +
>>   		ret = v4l2_ctrl_add_handler(hdl, ctx->phy->source->ctrl_handler,
>>   					    NULL, true);
>>   		if (ret < 0) {
>>   			ctx_err(ctx, "Failed to add source ctrl handler\n");
>>   			return;
>>   		}
>> +	} else {
>> +		ret = cal_ctx_v4l2_init_mc_format(ctx);
>> +		if (ret) {
>> +			ctx_err(ctx, "Failed to init format: %d\n", ret);
>> +			return;
>> +		}
> 
> And you can drop the error check here.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
>>   	}
>>   
>>   	ret = video_register_device(vfd, VFL_TYPE_VIDEO, cal_video_nr);
>> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
>> index ad7d26c803eb..c941d2aec79f 100644
>> --- a/drivers/media/platform/ti-vpe/cal.h
>> +++ b/drivers/media/platform/ti-vpe/cal.h
>> @@ -213,7 +213,7 @@ struct cal_ctx {
>>   	/* Used to store current pixel format */
>>   	struct v4l2_format	v_fmt;
>>   
>> -	/* Current subdev enumerated format */
>> +	/* Current subdev enumerated format (legacy) */
>>   	const struct cal_format_info	**active_fmt;
>>   	unsigned int		num_active_fmt;
>>   
> 


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo
  2021-04-18 13:24   ` Laurent Pinchart
@ 2021-04-19 13:08     ` Tomi Valkeinen
  0 siblings, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-19 13:08 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:24, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:56PM +0300, Tomi Valkeinen wrote:
>> struct cal_camerarx has fmtinfo field which is used to point to the
>> current active input format. The only place where the field is used is
>> cal_camerarx_get_ext_link_freq().
>>
>> With multiple streams the whole concept of single input format is not
>> valid anymore, so lets remove the field by looking up the format in
>> cal_camerarx_get_ext_link_freq(), making it easier to handle the
>> multistream-case in the following patches.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/media/platform/ti-vpe/cal-camerarx.c | 12 ++++++++----
>>   drivers/media/platform/ti-vpe/cal.h          |  1 -
>>   2 files changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> index 25f4692d210e..efe6513d69e8 100644
>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
>> @@ -49,8 +49,15 @@ static s64 cal_camerarx_get_ext_link_freq(struct cal_camerarx *phy)
>>   {
>>   	struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = &phy->endpoint.bus.mipi_csi2;
>>   	u32 num_lanes = mipi_csi2->num_data_lanes;
>> -	u32 bpp = phy->fmtinfo->bpp;
>> +	u32 bpp;
>>   	s64 freq;
>> +	const struct cal_format_info *fmtinfo;
> 
> I'd declare this after num_lanes as I like the reverse xmas tree order.
> 
>> +
>> +	fmtinfo = cal_format_by_code(phy->formats[CAL_CAMERARX_PAD_SINK].code);
>> +	if (!fmtinfo)
>> +		return -EINVAL;
>> +
>> +	bpp = fmtinfo->bpp;
> 
> I wonder if we'll end up dropping this, as falling back to
> V4L2_CID_PIXEL_RATE in v4l2_get_link_freq() makes less sense when using
> multiplexed streams. Something to worry about later.

You're right, it goes behind an if in an unposted patch:

if (cal_streams_api) {
	bpp = 0;
} else {
	const struct cal_format_info *fmtinfo;

	fmtinfo = cal_format_by_code(phy->formats[CAL_CAMERARX_PAD_SINK].code);
	if (!fmtinfo)
		return -EINVAL;

	bpp = fmtinfo->bpp;
}

and calling v4l2_get_link_freq with mul == 0 (bpp) will result in ENOENT if
V4L2_CID_LINK_FREQ is not available.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  2021-04-18 13:09   ` Laurent Pinchart
@ 2021-04-20 10:50     ` Tomi Valkeinen
  2021-04-20 11:17       ` Tomi Valkeinen
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-20 10:50 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 18/04/2021 16:09, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Mon, Apr 12, 2021 at 02:34:50PM +0300, Tomi Valkeinen wrote:
>> cal_ctx_v4l2_register() returns an error code, but the returned error
>> code is not handled anywhere. However, we can't really even handle the
>> error in any proper way, so lets just drop the return value and make
>> sure all error paths have an error print.
> 
> Ouch. Doesn't this call for registering the video node earlier, at probe
> time, instead of in the async notifier complete callback ?

Shouldn't we only register uAPI access points after the kernel has 
probed (succesfully) the hardware? If we register the video nodes at 
probe time I presume we would have to add checks to all the cal ioctl 
handlers to check if we have actually probed.

v4l2_async_notifier_operations.complete can return an error, but it's 
not quite clear to me what happens in that case and how the driver 
should handle it.

I'll look at this a bit, maybe it's still better to handle the error in 
complete callback and return the error from there, than ignoring the error.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  2021-04-20 10:50     ` Tomi Valkeinen
@ 2021-04-20 11:17       ` Tomi Valkeinen
  2021-04-29  0:10         ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-04-20 11:17 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 20/04/2021 13:50, Tomi Valkeinen wrote:
> On 18/04/2021 16:09, Laurent Pinchart wrote:
>> Hi Tomi,
>>
>> Thank you for the patch.
>>
>> On Mon, Apr 12, 2021 at 02:34:50PM +0300, Tomi Valkeinen wrote:
>>> cal_ctx_v4l2_register() returns an error code, but the returned error
>>> code is not handled anywhere. However, we can't really even handle the
>>> error in any proper way, so lets just drop the return value and make
>>> sure all error paths have an error print.
>>
>> Ouch. Doesn't this call for registering the video node earlier, at probe
>> time, instead of in the async notifier complete callback ?
> 
> Shouldn't we only register uAPI access points after the kernel has 
> probed (succesfully) the hardware? If we register the video nodes at 
> probe time I presume we would have to add checks to all the cal ioctl 
> handlers to check if we have actually probed.
> 
> v4l2_async_notifier_operations.complete can return an error, but it's 
> not quite clear to me what happens in that case and how the driver 
> should handle it.
> 
> I'll look at this a bit, maybe it's still better to handle the error in 
> complete callback and return the error from there, than ignoring the error.

Well, handling the error in complete callback seems to work fine. I'm 
not sure why I didn't do that and instead went with the approach in this 
patch.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 14/28] media: ti-vpe: cal: catch VC errors
  2021-04-19 11:19     ` Tomi Valkeinen
@ 2021-04-28 23:44       ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-28 23:44 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Apr 19, 2021 at 02:19:01PM +0300, Tomi Valkeinen wrote:
> On 18/04/2021 15:38, Laurent Pinchart wrote:
> > On Mon, Apr 12, 2021 at 02:34:43PM +0300, Tomi Valkeinen wrote:
> >> CAL driver currently ignores VC related errors. To help catch error
> >> conditions, enable all the VC error interrupts and handle them in the
> >> interrupt handler by printing an error.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/media/platform/ti-vpe/cal-camerarx.c | 23 ++++++++++++++++----
> >>   drivers/media/platform/ti-vpe/cal.c          |  9 ++++++++
> >>   2 files changed, 28 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> index 974fcbb19547..0354f311c5d2 100644
> >> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> @@ -226,24 +226,39 @@ static void cal_camerarx_enable_irqs(struct cal_camerarx *phy)
> >>   		CAL_CSI2_COMPLEXIO_IRQ_FIFO_OVR_MASK |
> >>   		CAL_CSI2_COMPLEXIO_IRQ_SHORT_PACKET_MASK |
> >>   		CAL_CSI2_COMPLEXIO_IRQ_ECC_NO_CORRECTION_MASK;
> >> -
> >> -	/* Enable CIO error IRQs. */
> >> +	const u32 vc_err_mask =
> >> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(0) |
> >> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(1) |
> >> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(2) |
> >> +		CAL_CSI2_VC_IRQ_CS_IRQ_MASK(3) |
> >> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(0) |
> >> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(1) |
> >> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(2) |
> >> +		CAL_CSI2_VC_IRQ_ECC_CORRECTION_IRQ_MASK(3);
> >> +
> >> +	/* Enable CIO & VC error IRQs. */
> >>   	cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
> >> -		  CAL_HL_IRQ_CIO_MASK(phy->instance));
> >> +		  CAL_HL_IRQ_CIO_MASK(phy->instance) | CAL_HL_IRQ_VC_MASK(phy->instance));
> > 
> > Line wrap ? Same in multiple places below. I know there's no strict 80
> > columns limit anymore, but I don't think longer lines help with
> > readability in this patch (not to mention the coding style inconsistency
> > with the rest of the driver).
> 
> Well, I disagree, but I guess that's in the eye of the beholder.
> 
> If we have a coding style with strict 80 column limit, then there are 
> other places I need to start fixing too. My personal coding style is 
> such that around 80 columns I start thinking about splitting if it can 
> be done without any messiness, around 100 I seriously try to split it, 
> and around 120 I think it's broken.

It then all depends on your messiness gauge :-) For the code above,

 	cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
		  CAL_HL_IRQ_CIO_MASK(phy->instance) |
		  CAL_HL_IRQ_VC_MASK(phy->instance));

doesn't seem messy at all to me (quite the contrary actually).

> I can change this and the other similar line, the end result is only 
> slightly messier, but...
> 
> >> +
> >> +			if (status & CAL_HL_IRQ_VC_MASK(i)) {
> >> +				u32 vc_stat = cal_read(cal, CAL_CSI2_VC_IRQSTATUS(i));
> >> +
> >> +				dev_err_ratelimited(cal->dev,
> >> +						    "CIO%u VC error: %#08x\n", i, vc_stat);
> >> +
> >> +				cal_write(cal, CAL_CSI2_VC_IRQSTATUS(i), vc_stat);
> >> +			}
> 
> ...especially for this part sticking to 80 columns uglifies the code.
> 
> u32 vc_stat =
> 	cal_read(cal,
> 		 CAL_CSI2_VC_IRQSTATUS(i));
> 
> or
> 
> u32 cio_stat = cal_read(cal,
> 	CAL_CSI2_COMPLEXIO_IRQSTATUS(i));

That would be messy, and I think it should either stay as-is, or the
function should be refactored with code broken out in multiple functions
(probably overkill for this specific example).

The next line, however, I would have written as

				dev_err_ratelimited(cal->dev,
						    "CIO%u VC error: %#08x\n",
						    i, vc_stat);

> I could split parts to a separate function, but I don't think the end 
> result would be better.
> 
> I think we discuss the 80-column problem almost in every series. Maybe 
> we need to agree to some clear predefined rules to avoid future 
> discussions about this? =)

So all we need is a metric that measure code mess, right ? :-)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-19 11:29     ` Tomi Valkeinen
@ 2021-04-28 23:57       ` Laurent Pinchart
  2021-05-04  7:56         ` Tomi Valkeinen
  2021-06-04 13:44         ` Laurent Pinchart
  0 siblings, 2 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-28 23:57 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Apr 19, 2021 at 02:29:20PM +0300, Tomi Valkeinen wrote:
> On 18/04/2021 15:46, Laurent Pinchart wrote:
> > On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
> >> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
> >> will break an active capture), but the RESET_DONE bit never changes to
> >> "reset is ongoing" state. Thus we always get a timeout.
> >>
> >> Drop the wait, as it seems to achieve nothing.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
> >>   1 file changed, 2 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> index 0354f311c5d2..245c601b992c 100644
> >> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
> >>   
> >>   static void cal_camerarx_stop(struct cal_camerarx *phy)
> >>   {
> >> -	unsigned int i;
> >>   	int ret;
> >>   
> >>   	cal_camerarx_ppi_disable(phy);
> >> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
> >>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
> >>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
> >>   
> >> -	/* Wait for power down completion */
> >> -	for (i = 0; i < 10; i++) {
> >> -		if (cal_read_field(phy->cal,
> >> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> >> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
> >> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
> > 
> > Isn't this the wrong condition ? I would have expected
> > CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
> > CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
> > you always get a timeout.
> 
> No, I don't think so. The complexio reset is set active just before the 
> wait. So the reset status should show reset ongoing, until at some point 
> we release the reset (we do that when starting the PHY again).
>
> The TRM doesn't talk about this, though. So, I guess the status might go 
> to RESETONGOING for a very short time and back to RESETCOMPLETED before 
> the code can see the RESETONGOING. But I suspect the status just stays 
> at RESETCOMPLETED.

The TRM is indeed not very clear. My understanding was that asserting
RESET_CTRL initiates the reset, and RESET_DONE switches to 1 once the
reset completes. There's however a note in the initialization sequence
that states

a. Deassert the CAMERARX reset:
i. Set CAL_CSI2_COMPLEXIO_CFG_j[30] RESET_CTRL to 0x1.
CAUTION
For the CAL_CSI2_COMPLEXIO_CFG_j[29] RESET_DONE bit to be set to 0x1
(reset completed), the external sensor must to be active and sending the
MIPI HS BYTECLK (that is, RXBYTECLKHS clock).

The RESET_DONE bit may thus only toggle when de-asserting the reset
signal (by setting RESET_CTRL to 1). It would be useful to test that
hypothesis by reading RESET_DONE just before setting RESET_CTRL to 1,
and right after. I'd expect the values to be 0 and 1 respectively. If
that's the case, then this patch is likely correct, so

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


The register macros are quite confusing by the way. We have

#define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK          BIT(30)
#define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL                       0
#define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL           1

When reading the code, I thought

        cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
                        CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
                        CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK)

meant that we were setting the reset bit to 1. I would personally get
rid of the _MASK suffixes for single bits, and use 0 and 1 in the code
instead of CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL and
CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically
  2021-04-19 11:45     ` Tomi Valkeinen
@ 2021-04-29  0:04       ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-29  0:04 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Apr 19, 2021 at 02:45:53PM +0300, Tomi Valkeinen wrote:
> On 18/04/2021 15:59, Laurent Pinchart wrote:
> > On Mon, Apr 12, 2021 at 02:34:46PM +0300, Tomi Valkeinen wrote:
> >> CAL has 4 pixel processing units but the units are not needed e.g. for
> >> metadata. As we could be capturing 4 pixel streams and 4 metadata
> >> streams, i.e. using 8 DMA contexts, we cannot assign a pixel processing
> >> unit to every DMA context. Instead we need to reserve a pixel processing
> >> unit only when needed.
> >>
> >> Add functions to reserve and release a pix proc unit, and use them in
> >> cal_ctx_prepare/unprepare. Note that for the time being we still always
> >> reserve a pix proc unit.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/media/platform/ti-vpe/cal.c | 44 +++++++++++++++++++++++++++--
> >>   drivers/media/platform/ti-vpe/cal.h |  2 ++
> >>   2 files changed, 44 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> >> index a6ca341c98bd..e397f59d3bbc 100644
> >> --- a/drivers/media/platform/ti-vpe/cal.c
> >> +++ b/drivers/media/platform/ti-vpe/cal.c
> >> @@ -290,6 +290,37 @@ void cal_quickdump_regs(struct cal_dev *cal)
> >>    * ------------------------------------------------------------------
> >>    */
> >>   
> >> +#define CAL_MAX_PIX_PROC 4
> >> +
> >> +static int cal_reserve_pix_proc(struct cal_dev *cal)
> >> +{
> >> +	unsigned long ret;
> >> +
> >> +	spin_lock(&cal->v4l2_dev.lock);
> >> +
> >> +	ret = find_first_zero_bit(&cal->reserve_pix_proc_mask, CAL_MAX_PIX_PROC);
> >> +
> >> +	if (ret == CAL_MAX_PIX_PROC) {
> >> +		spin_unlock(&cal->v4l2_dev.lock);
> >> +		return -ENOSPC;
> >> +	}
> >> +
> >> +	cal->reserve_pix_proc_mask |= BIT(ret);
> >> +
> >> +	spin_unlock(&cal->v4l2_dev.lock);
> >> +
> >> +	return ret;
> >> +}
> >> +
> >> +static void cal_release_pix_proc(struct cal_dev *cal, unsigned int pix_proc_num)
> >> +{
> >> +	spin_lock(&cal->v4l2_dev.lock);
> >> +
> >> +	cal->reserve_pix_proc_mask &= ~BIT(pix_proc_num);
> >> +
> >> +	spin_unlock(&cal->v4l2_dev.lock);
> >> +}
> >> +
> >>   static void cal_ctx_csi2_config(struct cal_ctx *ctx)
> >>   {
> >>   	u32 val;
> >> @@ -433,12 +464,22 @@ static bool cal_ctx_wr_dma_stopped(struct cal_ctx *ctx)
> >>   
> >>   int cal_ctx_prepare(struct cal_ctx *ctx)
> >>   {
> >> +	int ret;
> >> +
> >> +	ret = cal_reserve_pix_proc(ctx->cal);
> >> +	if (ret < 0) {
> >> +		ctx_err(ctx, "Failed to reserve pix proc: %d\n", ret);
> >> +		return ret;
> >> +	}
> >> +
> >> +	ctx->pix_proc = ret;
> > 
> > I wonder if this is the right place to allocate a context, it may be
> > better to reject invalid pipeline configurations earlier on. It's fine
> > for now, we can revisit this in subsequent patches, with the full
> > multiplexed streams implementation.
> 
> Earlier than what? Even before cal_start_streaming()? I guess we could 
> do this in cal_vb2_ioctl_reqbufs and cal_vb2_ioctl_create_bufs, but then 
> I'm not sure where to free the pix proc.

I'm trying to recall what I meant :-) There are only two options really,
at stream start (that's the latest point at which we need to guarantee a
valid pipeline), or when configuring routing (either through link setup,
or internal subdev routing). I'm not sure if the second option is even
possible. Buffer allocation isn't the right place.

> > Another option would be to allocate the context in cal_ctx_create() for
> > now, with a call to cal_reserve_pix_proc(), and move it later in the
> > context of the patch series that implements support for multiplexed
> > streams.
> 
> For now cal_reserve_pix_proc() will always succeed, as we have 4 pix 
> procs but only ever allocate 2 at the same time. If there is a better 
> place to do this for multiplexed streams, which is not available yet at 
> this patch, then I agree, we could just do this in cal_ctx_create until 
> we have that better place available.

Maybe that's what I meant :-) As I can't really recall, it probably
doesn't matter much.

> >> +
> >>   	return 0;
> >>   }
> >>   
> >>   void cal_ctx_unprepare(struct cal_ctx *ctx)
> >>   {
> >> -
> >> +	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
> >>   }
> >>   
> >>   void cal_ctx_start(struct cal_ctx *ctx)
> >> @@ -872,7 +913,6 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
> >>   	ctx->dma_ctx = inst;
> >>   	ctx->ppi_ctx = inst;
> >>   	ctx->cport = inst;
> >> -	ctx->pix_proc = inst;
> >>   
> >>   	ret = cal_ctx_v4l2_init(ctx);
> >>   	if (ret)
> >> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> >> index c34b843d2019..01e05e46e48d 100644
> >> --- a/drivers/media/platform/ti-vpe/cal.h
> >> +++ b/drivers/media/platform/ti-vpe/cal.h
> >> @@ -188,6 +188,8 @@ struct cal_dev {
> >>   	struct media_device	mdev;
> >>   	struct v4l2_device	v4l2_dev;
> >>   	struct v4l2_async_notifier notifier;
> >> +
> >> +	unsigned long reserve_pix_proc_mask;
> > 
> > I would have named this used_pix_proc_mask.
> 
> The name has a typo, and should actually be 'reserved_pix_proc_mask'. 
> Doesn't 'used' mean that something was used, but may not be used 
> anymore? So... in_use_pix_proc_mask? 'active'? I don't know, I like 
> 'reserved' best here.

"reserved" is indeed better than "reserve". I may still like "used"
better, but I don't care much. Or you could flip it, and have
"free_pix_proc_mask". Up to you.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field
  2021-04-19 11:53     ` Tomi Valkeinen
@ 2021-04-29  0:07       ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-29  0:07 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Apr 19, 2021 at 02:53:56PM +0300, Tomi Valkeinen wrote:
> On 18/04/2021 16:00, Laurent Pinchart wrote:
> > On Mon, Apr 12, 2021 at 02:34:47PM +0300, Tomi Valkeinen wrote:
> >> We already have functions to reserve and release a pix proc unit, but we
> >> always reserve such and the code expects the pix proc unit to be used.
> >>
> >> Add a new field, 'use_pix_proc', to indicate if the pix prox unit has
> >> been reserved and should be used. Use the flag to skip programming pix
> >> proc unit when not needed.
> >>
> >> Note that we still always set the use_pix_proc flag to true.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/media/platform/ti-vpe/cal.c | 10 +++++++---
> >>   drivers/media/platform/ti-vpe/cal.h |  2 ++
> >>   2 files changed, 9 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> >> index e397f59d3bbc..a1d173bd4613 100644
> >> --- a/drivers/media/platform/ti-vpe/cal.c
> >> +++ b/drivers/media/platform/ti-vpe/cal.c
> >> @@ -473,13 +473,15 @@ int cal_ctx_prepare(struct cal_ctx *ctx)
> >>   	}
> >>   
> >>   	ctx->pix_proc = ret;
> >> +	ctx->use_pix_proc = true;
> >>   
> >>   	return 0;
> >>   }
> >>   
> >>   void cal_ctx_unprepare(struct cal_ctx *ctx)
> >>   {
> >> -	cal_release_pix_proc(ctx->cal, ctx->pix_proc);
> >> +	if (ctx->use_pix_proc)
> >> +		cal_release_pix_proc(ctx->cal, ctx->pix_proc);
> >>   }
> >>   
> >>   void cal_ctx_start(struct cal_ctx *ctx)
> >> @@ -489,7 +491,8 @@ void cal_ctx_start(struct cal_ctx *ctx)
> >>   
> >>   	/* Configure the CSI-2, pixel processing and write DMA contexts. */
> >>   	cal_ctx_csi2_config(ctx);
> >> -	cal_ctx_pix_proc_config(ctx);
> >> +	if (ctx->use_pix_proc)
> >> +		cal_ctx_pix_proc_config(ctx);
> >>   	cal_ctx_wr_dma_config(ctx);
> >>   
> >>   	/* Enable IRQ_WDMA_END and IRQ_WDMA_START. */
> >> @@ -530,7 +533,8 @@ void cal_ctx_stop(struct cal_ctx *ctx)
> >>   	cal_write(ctx->cal, CAL_CSI2_CTX(ctx->phy->instance, ctx->ppi_ctx), 0);
> >>   
> >>   	/* Disable pix proc */
> >> -	cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
> >> +	if (ctx->use_pix_proc)
> >> +		cal_write(ctx->cal, CAL_PIX_PROC(ctx->pix_proc), 0);
> >>   }
> >>   
> >>   /* ------------------------------------------------------------------
> >> diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h
> >> index 01e05e46e48d..409b7276a1fa 100644
> >> --- a/drivers/media/platform/ti-vpe/cal.h
> >> +++ b/drivers/media/platform/ti-vpe/cal.h
> >> @@ -223,6 +223,8 @@ struct cal_ctx {
> >>   	u8			cport;
> >>   	u8			ppi_ctx;
> >>   	u8			pix_proc;
> >> +
> >> +	bool use_pix_proc;
> > 
> > Indentation ?
> > 
> > How about turning pix_proc to a signed value, and using -1 to indicate
> > it's not used ?
> 
> I considered that. But then, instead of "if (ctx->use_pix_proc)" I would 
> have "if (ctx->use_pix_proc >= 0)". I think the former is better. And 
> having a non-zero default value always makes me a bit uneasy.

I personally feel more uneasy when having a bool that qualifies whether
another field is valid or not :-) Probably because I then never know
what to set the other field to when setting the bool to false. It could
just be me, it doesn't matter much.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling
  2021-04-20 11:17       ` Tomi Valkeinen
@ 2021-04-29  0:10         ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-04-29  0:10 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Tue, Apr 20, 2021 at 02:17:36PM +0300, Tomi Valkeinen wrote:
> On 20/04/2021 13:50, Tomi Valkeinen wrote:
> > On 18/04/2021 16:09, Laurent Pinchart wrote:
> >> On Mon, Apr 12, 2021 at 02:34:50PM +0300, Tomi Valkeinen wrote:
> >>> cal_ctx_v4l2_register() returns an error code, but the returned error
> >>> code is not handled anywhere. However, we can't really even handle the
> >>> error in any proper way, so lets just drop the return value and make
> >>> sure all error paths have an error print.
> >>
> >> Ouch. Doesn't this call for registering the video node earlier, at probe
> >> time, instead of in the async notifier complete callback ?
> > 
> > Shouldn't we only register uAPI access points after the kernel has 
> > probed (succesfully) the hardware? If we register the video nodes at 
> > probe time I presume we would have to add checks to all the cal ioctl 
> > handlers to check if we have actually probed.

There's a long-lasting debate on this topic :-) The issue with
registering video nodes when all the subdevs have been acquired is that
you should then unregister them with a subdev is removed. The
re-registration gets fairly messy, especially if userspace keeps a video
device node open. It's not like V4L2 handles object life time management
correctly anyway, as it's completely broken in the core, maybe we
shouldn't care and just decide that unbinding a device from its driver
is unsupported.

> > v4l2_async_notifier_operations.complete can return an error, but it's 
> > not quite clear to me what happens in that case and how the driver 
> > should handle it.
> > 
> > I'll look at this a bit, maybe it's still better to handle the error in 
> > complete callback and return the error from there, than ignoring the error.
> 
> Well, handling the error in complete callback seems to work fine. I'm 
> not sure why I didn't do that and instead went with the approach in this 
> patch.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-28 23:57       ` Laurent Pinchart
@ 2021-05-04  7:56         ` Tomi Valkeinen
  2021-06-04 13:44         ` Laurent Pinchart
  1 sibling, 0 replies; 84+ messages in thread
From: Tomi Valkeinen @ 2021-05-04  7:56 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 29/04/2021 02:57, Laurent Pinchart wrote:
> Hi Tomi,
> 
> On Mon, Apr 19, 2021 at 02:29:20PM +0300, Tomi Valkeinen wrote:
>> On 18/04/2021 15:46, Laurent Pinchart wrote:
>>> On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
>>>> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
>>>> will break an active capture), but the RESET_DONE bit never changes to
>>>> "reset is ongoing" state. Thus we always get a timeout.
>>>>
>>>> Drop the wait, as it seems to achieve nothing.
>>>>
>>>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>>>> ---
>>>>    drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
>>>>    1 file changed, 2 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>> index 0354f311c5d2..245c601b992c 100644
>>>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>>>>    
>>>>    static void cal_camerarx_stop(struct cal_camerarx *phy)
>>>>    {
>>>> -	unsigned int i;
>>>>    	int ret;
>>>>    
>>>>    	cal_camerarx_ppi_disable(phy);
>>>> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
>>>>    
>>>> -	/* Wait for power down completion */
>>>> -	for (i = 0; i < 10; i++) {
>>>> -		if (cal_read_field(phy->cal,
>>>> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
>>>> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
>>>> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
>>>
>>> Isn't this the wrong condition ? I would have expected
>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
>>> you always get a timeout.
>>
>> No, I don't think so. The complexio reset is set active just before the
>> wait. So the reset status should show reset ongoing, until at some point
>> we release the reset (we do that when starting the PHY again).
>>
>> The TRM doesn't talk about this, though. So, I guess the status might go
>> to RESETONGOING for a very short time and back to RESETCOMPLETED before
>> the code can see the RESETONGOING. But I suspect the status just stays
>> at RESETCOMPLETED.
> 
> The TRM is indeed not very clear. My understanding was that asserting
> RESET_CTRL initiates the reset, and RESET_DONE switches to 1 once the
> reset completes. There's however a note in the initialization sequence
> that states

No, it's a bit to keep (or release) camerarx in reset. When the camerarx 
is being started, both reset ctrl and done are 0. The driver then 
releases the reset by setting ctrl to 1. Nothing happens at this time, 
as the camerarx needs the byteclk from the sensor to finish the reset. 
Later, when the sensor has been started, done changes to 1. This works fine.

The problem is on the stop side. Setting ctrl back to 0 does something, 
as the capture stops, so presumably the camerarx goes into reset state. 
But the done bit does not change.

The done bit is back to 0 when we start the camerarx again. My guess is 
that it's reset when the CAL module is turned off via runtime PM. This 
is not good, as there's no strict rule that says CAL will be turned off 
by runtime PM. However, I have not found any other way to reset the done 
bit. And in the case that we don't get a CAL reset, I guess we're still 
fine, as the camerarx is just already out of reset, and works.

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-04-28 23:57       ` Laurent Pinchart
  2021-05-04  7:56         ` Tomi Valkeinen
@ 2021-06-04 13:44         ` Laurent Pinchart
  2021-06-07 10:41           ` Tomi Valkeinen
  1 sibling, 1 reply; 84+ messages in thread
From: Laurent Pinchart @ 2021-06-04 13:44 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Thu, Apr 29, 2021 at 02:57:23AM +0300, Laurent Pinchart wrote:
> On Mon, Apr 19, 2021 at 02:29:20PM +0300, Tomi Valkeinen wrote:
> > On 18/04/2021 15:46, Laurent Pinchart wrote:
> > > On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
> > >> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
> > >> will break an active capture), but the RESET_DONE bit never changes to
> > >> "reset is ongoing" state. Thus we always get a timeout.
> > >>
> > >> Drop the wait, as it seems to achieve nothing.
> > >>
> > >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> > >> ---
> > >>   drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
> > >>   1 file changed, 2 insertions(+), 13 deletions(-)
> > >>
> > >> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> > >> index 0354f311c5d2..245c601b992c 100644
> > >> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> > >> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> > >> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
> > >>   
> > >>   static void cal_camerarx_stop(struct cal_camerarx *phy)
> > >>   {
> > >> -	unsigned int i;
> > >>   	int ret;
> > >>   
> > >>   	cal_camerarx_ppi_disable(phy);
> > >> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
> > >>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
> > >>   			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
> > >>   
> > >> -	/* Wait for power down completion */
> > >> -	for (i = 0; i < 10; i++) {
> > >> -		if (cal_read_field(phy->cal,
> > >> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> > >> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
> > >> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
> > > 
> > > Isn't this the wrong condition ? I would have expected
> > > CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
> > > CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
> > > you always get a timeout.
> > 
> > No, I don't think so. The complexio reset is set active just before the 
> > wait. So the reset status should show reset ongoing, until at some point 
> > we release the reset (we do that when starting the PHY again).
> >
> > The TRM doesn't talk about this, though. So, I guess the status might go 
> > to RESETONGOING for a very short time and back to RESETCOMPLETED before 
> > the code can see the RESETONGOING. But I suspect the status just stays 
> > at RESETCOMPLETED.
> 
> The TRM is indeed not very clear. My understanding was that asserting
> RESET_CTRL initiates the reset, and RESET_DONE switches to 1 once the
> reset completes. There's however a note in the initialization sequence
> that states
> 
> a. Deassert the CAMERARX reset:
> i. Set CAL_CSI2_COMPLEXIO_CFG_j[30] RESET_CTRL to 0x1.
> CAUTION
> For the CAL_CSI2_COMPLEXIO_CFG_j[29] RESET_DONE bit to be set to 0x1
> (reset completed), the external sensor must to be active and sending the
> MIPI HS BYTECLK (that is, RXBYTECLKHS clock).
> 
> The RESET_DONE bit may thus only toggle when de-asserting the reset
> signal (by setting RESET_CTRL to 1). It would be useful to test that
> hypothesis by reading RESET_DONE just before setting RESET_CTRL to 1,
> and right after. I'd expect the values to be 0 and 1 respectively. If
> that's the case, then this patch is likely correct, so
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> 
> The register macros are quite confusing by the way. We have
> 
> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK          BIT(30)
> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL                       0
> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL           1
> 
> When reading the code, I thought
> 
>         cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
>                         CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>                         CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK)
> 
> meant that we were setting the reset bit to 1. I would personally get
> rid of the _MASK suffixes for single bits, and use 0 and 1 in the code
> instead of CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL and
> CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL.

Do you think this would be a good idea ? It can be done in a follow-up
patch.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-06-04 13:44         ` Laurent Pinchart
@ 2021-06-07 10:41           ` Tomi Valkeinen
  2021-06-09 12:31             ` Laurent Pinchart
  0 siblings, 1 reply; 84+ messages in thread
From: Tomi Valkeinen @ 2021-06-07 10:41 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

On 04/06/2021 16:44, Laurent Pinchart wrote:
> Hi Tomi,
> 
> On Thu, Apr 29, 2021 at 02:57:23AM +0300, Laurent Pinchart wrote:
>> On Mon, Apr 19, 2021 at 02:29:20PM +0300, Tomi Valkeinen wrote:
>>> On 18/04/2021 15:46, Laurent Pinchart wrote:
>>>> On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
>>>>> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
>>>>> will break an active capture), but the RESET_DONE bit never changes to
>>>>> "reset is ongoing" state. Thus we always get a timeout.
>>>>>
>>>>> Drop the wait, as it seems to achieve nothing.
>>>>>
>>>>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>>>>> ---
>>>>>    drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
>>>>>    1 file changed, 2 insertions(+), 13 deletions(-)
>>>>>
>>>>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>>> index 0354f311c5d2..245c601b992c 100644
>>>>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
>>>>> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
>>>>>    
>>>>>    static void cal_camerarx_stop(struct cal_camerarx *phy)
>>>>>    {
>>>>> -	unsigned int i;
>>>>>    	int ret;
>>>>>    
>>>>>    	cal_camerarx_ppi_disable(phy);
>>>>> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
>>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
>>>>>    
>>>>> -	/* Wait for power down completion */
>>>>> -	for (i = 0; i < 10; i++) {
>>>>> -		if (cal_read_field(phy->cal,
>>>>> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
>>>>> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
>>>>> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
>>>>
>>>> Isn't this the wrong condition ? I would have expected
>>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
>>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
>>>> you always get a timeout.
>>>
>>> No, I don't think so. The complexio reset is set active just before the
>>> wait. So the reset status should show reset ongoing, until at some point
>>> we release the reset (we do that when starting the PHY again).
>>>
>>> The TRM doesn't talk about this, though. So, I guess the status might go
>>> to RESETONGOING for a very short time and back to RESETCOMPLETED before
>>> the code can see the RESETONGOING. But I suspect the status just stays
>>> at RESETCOMPLETED.
>>
>> The TRM is indeed not very clear. My understanding was that asserting
>> RESET_CTRL initiates the reset, and RESET_DONE switches to 1 once the
>> reset completes. There's however a note in the initialization sequence
>> that states
>>
>> a. Deassert the CAMERARX reset:
>> i. Set CAL_CSI2_COMPLEXIO_CFG_j[30] RESET_CTRL to 0x1.
>> CAUTION
>> For the CAL_CSI2_COMPLEXIO_CFG_j[29] RESET_DONE bit to be set to 0x1
>> (reset completed), the external sensor must to be active and sending the
>> MIPI HS BYTECLK (that is, RXBYTECLKHS clock).
>>
>> The RESET_DONE bit may thus only toggle when de-asserting the reset
>> signal (by setting RESET_CTRL to 1). It would be useful to test that
>> hypothesis by reading RESET_DONE just before setting RESET_CTRL to 1,
>> and right after. I'd expect the values to be 0 and 1 respectively. If
>> that's the case, then this patch is likely correct, so
>>
>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>
>>
>> The register macros are quite confusing by the way. We have
>>
>> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK          BIT(30)
>> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL                       0
>> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL           1
>>
>> When reading the code, I thought
>>
>>          cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
>>                          CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
>>                          CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK)
>>
>> meant that we were setting the reset bit to 1. I would personally get
>> rid of the _MASK suffixes for single bits, and use 0 and 1 in the code
>> instead of CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL and
>> CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL.
> 
> Do you think this would be a good idea ? It can be done in a follow-up
> patch.

I'd rather keep the MASK prefix as it's used for multiple bit masks too.

I think the problem here is the define for 0. The define should tell 
what the bit value does, but here it's just the field name. The value 
defines could perhaps be:

#define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_ASSERT           0
#define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_DEASSERT         1

Using just 0 or 1 may work fine at times, but often you don't know what 
they mean. You set 1 to RESET_CTRL. Does it put the IP into reset? Or 
release the reset?

Some other bits in cal_regs.h are fine, like:

#define CAL_CTRL_PWRSCPCLK_MASK			BIT(21)
#define CAL_CTRL_PWRSCPCLK_AUTO				0
#define CAL_CTRL_PWRSCPCLK_FORCE			1

But some have this same issue:

#define CAL_CTRL_POSTED_WRITES_MASK		BIT(0)
#define CAL_CTRL_POSTED_WRITES_NONPOSTED		0
#define CAL_CTRL_POSTED_WRITES				1

  Tomi

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx
  2021-06-07 10:41           ` Tomi Valkeinen
@ 2021-06-09 12:31             ` Laurent Pinchart
  0 siblings, 0 replies; 84+ messages in thread
From: Laurent Pinchart @ 2021-06-09 12:31 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Benoit Parrot, Pratyush Yadav, Lokesh Vutla, linux-media

Hi Tomi,

On Mon, Jun 07, 2021 at 01:41:07PM +0300, Tomi Valkeinen wrote:
> On 04/06/2021 16:44, Laurent Pinchart wrote:
> > On Thu, Apr 29, 2021 at 02:57:23AM +0300, Laurent Pinchart wrote:
> >> On Mon, Apr 19, 2021 at 02:29:20PM +0300, Tomi Valkeinen wrote:
> >>> On 18/04/2021 15:46, Laurent Pinchart wrote:
> >>>> On Mon, Apr 12, 2021 at 02:34:44PM +0300, Tomi Valkeinen wrote:
> >>>>> Asserting ComplexIO reset seems to affect the HW (ie. asserting reset
> >>>>> will break an active capture), but the RESET_DONE bit never changes to
> >>>>> "reset is ongoing" state. Thus we always get a timeout.
> >>>>>
> >>>>> Drop the wait, as it seems to achieve nothing.
> >>>>>
> >>>>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >>>>> ---
> >>>>>    drivers/media/platform/ti-vpe/cal-camerarx.c | 15 ++-------------
> >>>>>    1 file changed, 2 insertions(+), 13 deletions(-)
> >>>>>
> >>>>> diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >>>>> index 0354f311c5d2..245c601b992c 100644
> >>>>> --- a/drivers/media/platform/ti-vpe/cal-camerarx.c
> >>>>> +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
> >>>>> @@ -405,7 +405,6 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
> >>>>>    
> >>>>>    static void cal_camerarx_stop(struct cal_camerarx *phy)
> >>>>>    {
> >>>>> -	unsigned int i;
> >>>>>    	int ret;
> >>>>>    
> >>>>>    	cal_camerarx_ppi_disable(phy);
> >>>>> @@ -419,19 +418,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
> >>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
> >>>>>    			CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
> >>>>>    
> >>>>> -	/* Wait for power down completion */
> >>>>> -	for (i = 0; i < 10; i++) {
> >>>>> -		if (cal_read_field(phy->cal,
> >>>>> -				   CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> >>>>> -				   CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_MASK) ==
> >>>>> -		    CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING)
> >>>>
> >>>> Isn't this the wrong condition ? I would have expected
> >>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETCOMPLETED, not
> >>>> CAL_CSI2_COMPLEXIO_CFG_RESET_DONE_RESETONGOING. That could explain why
> >>>> you always get a timeout.
> >>>
> >>> No, I don't think so. The complexio reset is set active just before the
> >>> wait. So the reset status should show reset ongoing, until at some point
> >>> we release the reset (we do that when starting the PHY again).
> >>>
> >>> The TRM doesn't talk about this, though. So, I guess the status might go
> >>> to RESETONGOING for a very short time and back to RESETCOMPLETED before
> >>> the code can see the RESETONGOING. But I suspect the status just stays
> >>> at RESETCOMPLETED.
> >>
> >> The TRM is indeed not very clear. My understanding was that asserting
> >> RESET_CTRL initiates the reset, and RESET_DONE switches to 1 once the
> >> reset completes. There's however a note in the initialization sequence
> >> that states
> >>
> >> a. Deassert the CAMERARX reset:
> >> i. Set CAL_CSI2_COMPLEXIO_CFG_j[30] RESET_CTRL to 0x1.
> >> CAUTION
> >> For the CAL_CSI2_COMPLEXIO_CFG_j[29] RESET_DONE bit to be set to 0x1
> >> (reset completed), the external sensor must to be active and sending the
> >> MIPI HS BYTECLK (that is, RXBYTECLKHS clock).
> >>
> >> The RESET_DONE bit may thus only toggle when de-asserting the reset
> >> signal (by setting RESET_CTRL to 1). It would be useful to test that
> >> hypothesis by reading RESET_DONE just before setting RESET_CTRL to 1,
> >> and right after. I'd expect the values to be 0 and 1 respectively. If
> >> that's the case, then this patch is likely correct, so
> >>
> >> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>
> >>
> >> The register macros are quite confusing by the way. We have
> >>
> >> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK          BIT(30)
> >> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL                       0
> >> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL           1
> >>
> >> When reading the code, I thought
> >>
> >>          cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
> >>                          CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL,
> >>                          CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK)
> >>
> >> meant that we were setting the reset bit to 1. I would personally get
> >> rid of the _MASK suffixes for single bits, and use 0 and 1 in the code
> >> instead of CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL and
> >> CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL.
> > 
> > Do you think this would be a good idea ? It can be done in a follow-up
> > patch.
> 
> I'd rather keep the MASK prefix as it's used for multiple bit masks too.
> 
> I think the problem here is the define for 0. The define should tell 
> what the bit value does, but here it's just the field name. The value 
> defines could perhaps be:
> 
> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_ASSERT           0
> #define CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_DEASSERT         1
> 
> Using just 0 or 1 may work fine at times, but often you don't know what 
> they mean. You set 1 to RESET_CTRL. Does it put the IP into reset? Or 
> release the reset?

I have a small preference for dropping _MASK for single bits, but the
above is fine with me too, it's entirely up to you.

> Some other bits in cal_regs.h are fine, like:
> 
> #define CAL_CTRL_PWRSCPCLK_MASK			BIT(21)
> #define CAL_CTRL_PWRSCPCLK_AUTO				0
> #define CAL_CTRL_PWRSCPCLK_FORCE			1
> 
> But some have this same issue:
> 
> #define CAL_CTRL_POSTED_WRITES_MASK		BIT(0)
> #define CAL_CTRL_POSTED_WRITES_NONPOSTED		0
> #define CAL_CTRL_POSTED_WRITES				1

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 84+ messages in thread

end of thread, other threads:[~2021-06-09 12:31 UTC | newest]

Thread overview: 84+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 11:34 [PATCH 00/28] media: ti-vpe: cal: prepare for multistream support Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 01/28] media: ti-vpe: cal: add g/s_parm for legacy API Tomi Valkeinen
2021-04-17 23:01   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 02/28] media: ti-vpe: cal: fix error handling in cal_camerarx_create Tomi Valkeinen
2021-04-17 23:05   ` Laurent Pinchart
2021-04-19  8:24     ` Tomi Valkeinen
2021-04-19  8:31       ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 03/28] media: ti-vpe: cal: remove unused cal_camerarx->dev field Tomi Valkeinen
2021-04-18  0:43   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 04/28] media: ti-vpe: cal: rename "sensor" to "source" Tomi Valkeinen
2021-04-17 23:18   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 05/28] media: ti-vpe: cal: move global config from cal_ctx_wr_dma_config to runtime resume Tomi Valkeinen
2021-04-17 23:27   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 06/28] media: ti-vpe: cal: use v4l2_get_link_freq Tomi Valkeinen
2021-04-18 11:48   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 07/28] media: ti-vpe: cal: add cal_ctx_prepare/unprepare Tomi Valkeinen
2021-04-18 13:30   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 08/28] media: ti-vpe: cal: change index and cport to u8 Tomi Valkeinen
2021-04-18 11:55   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 09/28] media: ti-vpe: cal: Add PPI context Tomi Valkeinen
2021-04-18 12:17   ` Laurent Pinchart
2021-04-19  9:01     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 10/28] media: ti-vpe: cal: Add pixel processing context Tomi Valkeinen
2021-04-18 12:20   ` Laurent Pinchart
2021-04-18 12:23     ` Laurent Pinchart
2021-04-19  9:17     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 11/28] media: ti-vpe: cal: rename cal_ctx->index to dma_ctx Tomi Valkeinen
2021-04-18 12:22   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 12/28] media: ti-vpe: cal: rename CAL_HL_IRQ_MASK Tomi Valkeinen
2021-04-18 12:29   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 13/28] media: ti-vpe: cal: clean up CAL_CSI2_VC_IRQ_* macros Tomi Valkeinen
2021-04-18 12:32   ` Laurent Pinchart
2021-04-19 10:29     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 14/28] media: ti-vpe: cal: catch VC errors Tomi Valkeinen
2021-04-18 12:38   ` Laurent Pinchart
2021-04-19 11:19     ` Tomi Valkeinen
2021-04-28 23:44       ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 15/28] media: ti-vpe: cal: remove wait when stopping camerarx Tomi Valkeinen
2021-04-18 12:46   ` Laurent Pinchart
2021-04-19 11:29     ` Tomi Valkeinen
2021-04-28 23:57       ` Laurent Pinchart
2021-05-04  7:56         ` Tomi Valkeinen
2021-06-04 13:44         ` Laurent Pinchart
2021-06-07 10:41           ` Tomi Valkeinen
2021-06-09 12:31             ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 16/28] media: ti-vpe: cal: disable ppi and pix proc at ctx_stop Tomi Valkeinen
2021-04-18 12:49   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 17/28] media: ti-vpe: cal: allocate pix proc dynamically Tomi Valkeinen
2021-04-18 12:59   ` Laurent Pinchart
2021-04-19 11:45     ` Tomi Valkeinen
2021-04-29  0:04       ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 18/28] media: ti-vpe: cal: add 'use_pix_proc' field Tomi Valkeinen
2021-04-18 13:00   ` Laurent Pinchart
2021-04-19 11:53     ` Tomi Valkeinen
2021-04-29  0:07       ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 19/28] media: ti-vpe: cal: add cal_ctx_wr_dma_enable and fix a race Tomi Valkeinen
2021-04-18 13:04   ` Laurent Pinchart
2021-04-19 12:02     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 20/28] media: ti-vpe: cal: add vc and datatype fields to cal_ctx Tomi Valkeinen
2021-04-18 13:06   ` Laurent Pinchart
2021-04-19 12:07     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 21/28] media: ti-vpe: cal: fix cal_ctx_v4l2_register error handling Tomi Valkeinen
2021-04-18 13:09   ` Laurent Pinchart
2021-04-20 10:50     ` Tomi Valkeinen
2021-04-20 11:17       ` Tomi Valkeinen
2021-04-29  0:10         ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 22/28] media: ti-vpe: cal: set field always to V4L2_FIELD_NONE Tomi Valkeinen
2021-04-18 13:14   ` Laurent Pinchart
2021-04-19 12:34     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 23/28] media: ti-vpe: cal: fix typo in a comment Tomi Valkeinen
2021-04-18 13:14   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 24/28] media: ti-vpe: cal: add mbus_code support to cal_mc_enum_fmt_vid_cap Tomi Valkeinen
2021-04-18 13:17   ` Laurent Pinchart
2021-04-19 12:50     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 25/28] media: ti-vpe: cal: rename non-MC funcs to cal_legacy_* Tomi Valkeinen
2021-04-18 13:18   ` Laurent Pinchart
2021-04-12 11:34 ` [PATCH 26/28] media: ti-vpe: cal: init ctx->v_fmt correctly in MC mode Tomi Valkeinen
2021-04-18 13:21   ` Laurent Pinchart
2021-04-19 13:01     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 27/28] media: ti-vpe: cal: remove cal_camerarx->fmtinfo Tomi Valkeinen
2021-04-18 13:24   ` Laurent Pinchart
2021-04-19 13:08     ` Tomi Valkeinen
2021-04-12 11:34 ` [PATCH 28/28] media: ti-vpe: cal: support 8 DMA contexts Tomi Valkeinen
2021-04-18 13:29   ` Laurent Pinchart

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).