From: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Jacopo Mondi" <jacopo.mondi@ideasonboard.com>
Subject: Re: [PATCH v3 13/15] media: rcar-csi2: Call get_frame_desc to find out VC & DT (Gen3)
Date: Tue, 16 Dec 2025 14:58:57 +0200 [thread overview]
Message-ID: <b483e725-4e3e-45b9-9a20-001fe1c7acf0@ideasonboard.com> (raw)
In-Reply-To: <20250602134926.GB23515@pendragon.ideasonboard.com>
Hi,
On 02/06/2025 16:49, Laurent Pinchart wrote:
> Hi Tomi,
>
> Thank you for the patch.
>
> On Fri, May 30, 2025 at 04:50:42PM +0300, Tomi Valkeinen wrote:
>> Call get_frame_desc to find out VC & DT, for Gen3 platforms, instead of
>> hardcoding the VC routing and deducing the DT based on the mbus format.
>>
>> If the source subdevice doesn't implement .get_frame_desc, we use a
>> fallback case where we assume there's a single stream with VC = 0 and DT
>> based on the mbus format.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
>> ---
>> drivers/media/platform/renesas/rcar-csi2.c | 113 +++++++++++++++++++----------
>> 1 file changed, 76 insertions(+), 37 deletions(-)
>>
>> diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c
>> index b9f83aae725a..8f708196ef49 100644
>> --- a/drivers/media/platform/renesas/rcar-csi2.c
>> +++ b/drivers/media/platform/renesas/rcar-csi2.c
>> @@ -71,10 +71,7 @@ struct rcar_csi2;
>> #define FLD_REG 0x1c
>> #define FLD_FLD_NUM(n) (((n) & 0xff) << 16)
>> #define FLD_DET_SEL(n) (((n) & 0x3) << 4)
>> -#define FLD_FLD_EN4 BIT(3)
>> -#define FLD_FLD_EN3 BIT(2)
>> -#define FLD_FLD_EN2 BIT(1)
>> -#define FLD_FLD_EN BIT(0)
>> +#define FLD_FLD_EN(ch) BIT(ch)
>>
>> /* Automatic Standby Control */
>> #define ASTBY_REG 0x20
>> @@ -1066,52 +1063,94 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv,
>> static int rcsi2_start_receiver_gen3(struct rcar_csi2 *priv,
>> struct v4l2_subdev_state *state)
>> {
>> - const struct rcar_csi2_format *format;
>> - u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
>> - const struct v4l2_mbus_framefmt *fmt;
>> + u32 phycnt, vcdt = 0, vcdt2 = 0;
>> + u32 fld = FLD_DET_SEL(1);
>> + struct v4l2_mbus_frame_desc source_fd;
>> + struct v4l2_subdev_route *route;
>> unsigned int lanes;
>> - unsigned int i;
>> int mbps, ret;
>> + u8 ch = 0;
>>
>> - /* Use the format on the sink pad to compute the receiver config. */
>> - fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK, 0);
>> + ret = v4l2_subdev_call(priv->remote, pad, get_frame_desc,
>> + priv->remote_pad, &source_fd);
>> + if (ret && ret != -ENOIOCTLCMD) {
>> + return ret;
>> + } else if (ret == -ENOIOCTLCMD) {
>
> if (ret && ret != -ENOIOCTLCMD)
> return ret;
>
> if (ret == -ENOIOCTLCMD) {
Yep, that's cleaner.
>> + /* Create a fallback source_fd */
>> + struct v4l2_mbus_frame_desc *fd = &source_fd;
>> + const struct rcar_csi2_format *format;
>> + struct v4l2_mbus_framefmt *fmt;
>>
>> - dev_dbg(priv->dev, "Input size (%ux%u%c)\n",
>> - fmt->width, fmt->height,
>> - fmt->field == V4L2_FIELD_NONE ? 'p' : 'i');
>> + fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK, 0);
>> + if (!fmt)
>> + return -EINVAL;
>>
>> - /* Code is validated in set_fmt. */
>> - format = rcsi2_code_to_fmt(fmt->code);
>> - if (!format)
>> - return -EINVAL;
>> + format = rcsi2_code_to_fmt(fmt->code);
>> + if (!format)
>> + return -EINVAL;
>>
>> - /*
>> - * Enable all supported CSI-2 channels with virtual channel and
>> - * data type matching.
>> - *
>> - * NOTE: It's not possible to get individual datatype for each
>> - * source virtual channel. Once this is possible in V4L2
>> - * it should be used here.
>> - */
>> - for (i = 0; i < priv->info->num_channels; i++) {
>> + memset(fd, 0, sizeof(*fd));
>> +
>> + fd->num_entries = 1;
>> + fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2;
>> + fd->entry[0].stream = 0;
>> + fd->entry[0].pixelcode = fmt->code;
>> + fd->entry[0].bus.csi2.vc = 0;
>> + fd->entry[0].bus.csi2.dt = format->datatype;
>> + }
>> +
>> + for_each_active_route(&state->routing, route) {
>> + struct v4l2_mbus_frame_desc_entry *source_entry = NULL;
>
> const
Yep.
>> + const struct v4l2_mbus_framefmt *fmt;
>> + const struct rcar_csi2_format *format;
>> + unsigned int i;
>> + u8 vc, dt;
>> u32 vcdt_part;
>>
>> - if (priv->channel_vc[i] < 0)
>> - continue;
>> + for (i = 0; i < source_fd.num_entries; i++) {
>> + if (source_fd.entry[i].stream == route->sink_stream) {
>
> No need to check the pad ?
We only have a single sink pad in CSI-2.
>> + source_entry = &source_fd.entry[i];
>> + break;
>> + }
>> + }
>> +
>> + if (!source_entry) {
>> + dev_err(priv->dev,
>> + "Failed to find stream from source frame desc\n");
>> + return -EPIPE;
>> + }
>>
>> - vcdt_part = VCDT_SEL_VC(priv->channel_vc[i]) | VCDT_VCDTN_EN |
>> - VCDT_SEL_DTN_ON | VCDT_SEL_DT(format->datatype);
>> + vc = source_entry->bus.csi2.vc;
>> + dt = source_entry->bus.csi2.dt;
>> +
>> + vcdt_part = VCDT_SEL_VC(vc) | VCDT_VCDTN_EN |
>> + VCDT_SEL_DTN_ON | VCDT_SEL_DT(dt);
>
> I would drop the vc and dt variables and write
>
> vcdt_part = VCDT_SEL_VC(source_entry->bus.csi2.vc)
> | VCDT_VCDTN_EN | VCDT_SEL_DTN_ON
> | VCDT_SEL_DT(source_entry->bus.csi2.dt);
Yes, I think this is fine too.
>>
>> /* Store in correct reg and offset. */
>> - if (i < 2)
>> - vcdt |= vcdt_part << ((i % 2) * 16);
>> + if (ch < 2)
>> + vcdt |= vcdt_part << ((ch % 2) * 16);
>> else
>> - vcdt2 |= vcdt_part << ((i % 2) * 16);
>> - }
>> + vcdt2 |= vcdt_part << ((ch % 2) * 16);
>> +
>> + fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK,
>> + route->sink_stream);
>> + if (!fmt)
>> + return -EINVAL;
>> +
>> + dev_dbg(priv->dev, "Input size (%ux%u%c)\n",
>> + fmt->width, fmt->height,
>> + fmt->field == V4L2_FIELD_NONE ? 'p' : 'i');
>>
>> - if (fmt->field == V4L2_FIELD_ALTERNATE)
>> - fld = FLD_DET_SEL(1) | FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2
>> - | FLD_FLD_EN;
>> + /* Code is validated in set_fmt. */
>
> Then why don't you drop the !format check ?
It's a copy of the existing code. I've been reluctant to change gen3
code, as I can't test. But I can't really see how this could be wrong,
so I'll just drop the check here.
Tomi
>> + format = rcsi2_code_to_fmt(fmt->code);
>> + if (!format)
>> + return -EINVAL;
>> +
>> + if (fmt->field == V4L2_FIELD_ALTERNATE)
>> + fld |= FLD_FLD_EN(ch);
>> +
>> + ch++;
>> + }
>>
>> /*
>> * Get the number of active data lanes inspecting the remote mbus
>
next prev parent reply other threads:[~2025-12-16 12:59 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 13:50 [PATCH v3 00/15] media: rcar: Streams support Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 01/15] media: rcar-csi2: Use the pad version of v4l2_get_link_freq() Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-07-02 15:07 ` Niklas Söderlund
2025-07-02 20:51 ` Laurent Pinchart
2025-06-06 11:57 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 02/15] media: rcar-isp: Improve ISPPROCMODE_DT_PROC_MODE_VC Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-06-06 11:58 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 03/15] media: rcar-isp: Move {enable|disable}_streams() calls Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-09-26 11:22 ` Tomi Valkeinen
2025-09-27 6:17 ` Niklas Söderlund
2025-12-16 12:48 ` Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 04/15] media: rcar-csi2: " Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-05-30 13:50 ` [PATCH v3 05/15] media: rcar-csi2: Move rcar2_calc_mbps() Tomi Valkeinen
2025-06-02 14:03 ` Laurent Pinchart
2025-06-06 12:03 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 06/15] media: rcar-csi2: Simplify rcsi2_calc_mbps() Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-06-06 12:02 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 07/15] media: rcar-csi2: Optimize rcsi2_calc_mbps() Tomi Valkeinen
2025-06-02 9:43 ` Laurent Pinchart
2025-06-06 12:07 ` Niklas Söderlund
2025-12-08 14:03 ` Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 08/15] media: rcar-csi2: Switch to Streams API Tomi Valkeinen
2025-06-02 14:06 ` Laurent Pinchart
2025-12-16 13:15 ` Tomi Valkeinen
2025-06-06 12:09 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 09/15] media: rcar-isp: " Tomi Valkeinen
2025-06-02 14:17 ` Laurent Pinchart
2025-06-06 12:10 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 10/15] media: rcar-csi2: Add .get_frame_desc op Tomi Valkeinen
2025-06-02 9:44 ` Laurent Pinchart
2025-06-06 12:14 ` Niklas Söderlund
2025-12-16 13:18 ` Tomi Valkeinen
2025-12-16 13:22 ` Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 11/15] media: rcar-isp: Call get_frame_desc to find out VC & DT Tomi Valkeinen
2025-06-02 13:22 ` Laurent Pinchart
2025-12-16 11:57 ` Tomi Valkeinen
2025-06-06 12:20 ` Niklas Söderlund
2025-12-16 13:35 ` Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 12/15] media: rcar-csi2: Add more stream support to rcsi2_calc_mbps() Tomi Valkeinen
2025-06-02 13:28 ` Laurent Pinchart
2025-12-16 12:45 ` Tomi Valkeinen
2025-06-06 12:25 ` Niklas Söderlund
2025-05-30 13:50 ` [PATCH v3 13/15] media: rcar-csi2: Call get_frame_desc to find out VC & DT (Gen3) Tomi Valkeinen
2025-06-02 13:49 ` Laurent Pinchart
2025-12-16 12:58 ` Tomi Valkeinen [this message]
2025-05-30 13:50 ` [PATCH v3 14/15] media: rcar-csi2: Add full streams support Tomi Valkeinen
2025-06-02 13:54 ` Laurent Pinchart
2025-12-16 13:03 ` Tomi Valkeinen
2025-05-30 13:50 ` [PATCH v3 15/15] media: rcar-isp: " Tomi Valkeinen
2025-06-02 13:57 ` Laurent Pinchart
2025-12-16 13:11 ` Tomi Valkeinen
2025-06-06 12:32 ` [PATCH v3 00/15] media: rcar: Streams support Niklas Söderlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b483e725-4e3e-45b9-9a20-001fe1c7acf0@ideasonboard.com \
--to=tomi.valkeinen+renesas@ideasonboard.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab+huawei@kernel.org \
--cc=mchehab@kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=niklas.soderlund@ragnatech.se \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®