From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Cc: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH 04/11] media: rcar-csi2: Use the subdev active state
Date: Mon, 6 May 2024 00:54:25 +0300 [thread overview]
Message-ID: <20240505215425.GJ23227@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240503155127.105235-5-jacopo.mondi@ideasonboard.com>
Hi Jacopo,
Thank you for the patch.
On Fri, May 03, 2024 at 05:51:19PM +0200, Jacopo Mondi wrote:
> Create the subdevice state with v4l2_subdev_init_finalize() and
> implement the init_state() operation to guarantee the state is initialized.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
> drivers/media/platform/renesas/rcar-csi2.c | 138 +++++++++++----------
> 1 file changed, 75 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c
> index 2d464e43a5be..4d4dfb59b025 100644
> --- a/drivers/media/platform/renesas/rcar-csi2.c
> +++ b/drivers/media/platform/renesas/rcar-csi2.c
> @@ -587,7 +587,8 @@ enum rcar_csi2_pads {
> struct rcar_csi2_info {
> int (*init_phtw)(struct rcar_csi2 *priv, unsigned int mbps);
> int (*phy_post_init)(struct rcar_csi2 *priv);
> - int (*start_receiver)(struct rcar_csi2 *priv);
> + int (*start_receiver)(struct rcar_csi2 *priv,
> + struct v4l2_subdev_state *state);
> void (*enter_standby)(struct rcar_csi2 *priv);
> const struct rcsi2_mbps_reg *hsfreqrange;
> unsigned int csi0clkfreqrange;
> @@ -613,8 +614,6 @@ struct rcar_csi2 {
>
> int channel_vc[4];
>
> - struct mutex lock; /* Protects mf and stream_count. */
> - struct v4l2_mbus_framefmt mf;
> int stream_count;
>
> bool cphy;
> @@ -808,20 +807,25 @@ static int rcsi2_get_active_lanes(struct rcar_csi2 *priv,
> return 0;
> }
>
> -static int rcsi2_start_receiver_gen3(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;
> + struct v4l2_mbus_framefmt *fmt;
const
> unsigned int lanes;
> unsigned int i;
> int mbps, ret;
>
> + /* Use the format on the sink pad to compute the receiver config. */
> + fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK);
> +
> dev_dbg(priv->dev, "Input size (%ux%u%c)\n",
> - priv->mf.width, priv->mf.height,
> - priv->mf.field == V4L2_FIELD_NONE ? 'p' : 'i');
> + fmt->width, fmt->height,
> + fmt->field == V4L2_FIELD_NONE ? 'p' : 'i');
>
> /* Code is validated in set_fmt. */
> - format = rcsi2_code_to_fmt(priv->mf.code);
> + format = rcsi2_code_to_fmt(fmt->code);
> if (!format)
> return -EINVAL;
>
> @@ -849,11 +853,11 @@ static int rcsi2_start_receiver_gen3(struct rcar_csi2 *priv)
> vcdt2 |= vcdt_part << ((i % 2) * 16);
> }
>
> - if (priv->mf.field == V4L2_FIELD_ALTERNATE) {
> + if (fmt->field == V4L2_FIELD_ALTERNATE) {
> fld = FLD_DET_SEL(1) | FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2
> | FLD_FLD_EN;
>
> - if (priv->mf.height == 240)
> + if (fmt->height == 240)
> fld |= FLD_FLD_NUM(0);
> else
> fld |= FLD_FLD_NUM(1);
> @@ -1049,15 +1053,18 @@ static int rcsi2_c_phy_setting_v4h(struct rcar_csi2 *priv, int msps)
> return 0;
> }
>
> -static int rcsi2_start_receiver_v4h(struct rcar_csi2 *priv)
> +static int rcsi2_start_receiver_v4h(struct rcar_csi2 *priv,
> + struct v4l2_subdev_state *state)
> {
> const struct rcar_csi2_format *format;
> + struct v4l2_mbus_framefmt *fmt;
const
> unsigned int lanes;
> int msps;
> int ret;
>
> - /* Calculate parameters */
> - format = rcsi2_code_to_fmt(priv->mf.code);
> + /* Use the format on the sink pad to compute the receiver config. */
> + fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK);
> + format = rcsi2_code_to_fmt(fmt->code);
> if (!format)
> return -EINVAL;
>
> @@ -1114,7 +1121,7 @@ static int rcsi2_start_receiver_v4h(struct rcar_csi2 *priv)
> return 0;
> }
>
> -static int rcsi2_start(struct rcar_csi2 *priv)
> +static int rcsi2_start(struct rcar_csi2 *priv, struct v4l2_subdev_state *state)
> {
> int ret;
>
> @@ -1122,7 +1129,7 @@ static int rcsi2_start(struct rcar_csi2 *priv)
> if (ret < 0)
> return ret;
>
> - ret = priv->info->start_receiver(priv);
> + ret = priv->info->start_receiver(priv, state);
> if (ret) {
> rcsi2_enter_standby(priv);
> return ret;
> @@ -1146,17 +1153,16 @@ static void rcsi2_stop(struct rcar_csi2 *priv)
> static int rcsi2_s_stream(struct v4l2_subdev *sd, int enable)
> {
> struct rcar_csi2 *priv = sd_to_csi2(sd);
> + struct v4l2_subdev_state *state;
> int ret = 0;
>
> - mutex_lock(&priv->lock);
> + if (!priv->remote)
> + return -ENODEV;
>
> - if (!priv->remote) {
> - ret = -ENODEV;
> - goto out;
> - }
> + state = v4l2_subdev_lock_and_get_active_state(&priv->subdev);
>
> if (enable && priv->stream_count == 0) {
> - ret = rcsi2_start(priv);
> + ret = rcsi2_start(priv, state);
> if (ret)
> goto out;
> } else if (!enable && priv->stream_count == 1) {
> @@ -1165,49 +1171,26 @@ static int rcsi2_s_stream(struct v4l2_subdev *sd, int enable)
>
> priv->stream_count += enable ? 1 : -1;
> out:
> - mutex_unlock(&priv->lock);
> + v4l2_subdev_unlock_state(state);
>
> return ret;
> }
>
> static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
> - struct v4l2_subdev_state *sd_state,
> + struct v4l2_subdev_state *state,
> struct v4l2_subdev_format *format)
> {
> - struct rcar_csi2 *priv = sd_to_csi2(sd);
> - struct v4l2_mbus_framefmt *framefmt;
> -
> - mutex_lock(&priv->lock);
> + if (format->pad > RCAR_CSI2_SINK)
> + return v4l2_subdev_get_fmt(sd, state, format);
>
> if (!rcsi2_code_to_fmt(format->format.code))
> format->format.code = rcar_csi2_formats[0].code;
>
> - if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> - priv->mf = format->format;
> - } else {
> - framefmt = v4l2_subdev_state_get_format(sd_state, 0);
> - *framefmt = format->format;
> - }
> -
> - mutex_unlock(&priv->lock);
> -
> - return 0;
> -}
> -
> -static int rcsi2_get_pad_format(struct v4l2_subdev *sd,
> - struct v4l2_subdev_state *sd_state,
> - struct v4l2_subdev_format *format)
> -{
> - struct rcar_csi2 *priv = sd_to_csi2(sd);
> -
> - mutex_lock(&priv->lock);
> -
> - if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> - format->format = priv->mf;
> - else
> - format->format = *v4l2_subdev_state_get_format(sd_state, 0);
> + *v4l2_subdev_state_get_format(state, format->pad) = format->format;
>
> - mutex_unlock(&priv->lock);
> + /* Propagate the format to the source pads. */
> + for (unsigned int i = RCAR_CSI2_SOURCE_VC0; i < NR_OF_RCAR_CSI2_PAD; i++)
> + *v4l2_subdev_state_get_format(state, i) = format->format;
>
> return 0;
> }
> @@ -1218,7 +1201,7 @@ static const struct v4l2_subdev_video_ops rcar_csi2_video_ops = {
>
> static const struct v4l2_subdev_pad_ops rcar_csi2_pad_ops = {
> .set_fmt = rcsi2_set_pad_format,
> - .get_fmt = rcsi2_get_pad_format,
> + .get_fmt = v4l2_subdev_get_fmt,
> };
>
> static const struct v4l2_subdev_ops rcar_csi2_subdev_ops = {
> @@ -1226,6 +1209,30 @@ static const struct v4l2_subdev_ops rcar_csi2_subdev_ops = {
> .pad = &rcar_csi2_pad_ops,
> };
>
> +static int rcsi2_init_state(struct v4l2_subdev *sd,
> + struct v4l2_subdev_state *state)
> +{
> + static const struct v4l2_mbus_framefmt rcar_csi2_default_fmt = {
> + .width = 1920,
> + .height = 1080,
> + .code = MEDIA_BUS_FMT_RGB888_1X24,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .field = V4L2_FIELD_NONE,
> + .ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT,
> + .quantization = V4L2_QUANTIZATION_DEFAULT,
> + .xfer_func = V4L2_XFER_FUNC_DEFAULT,
> + };
> +
> + for (unsigned int i = RCAR_CSI2_SINK; i < NR_OF_RCAR_CSI2_PAD; i++)
I would write 'i = 0'.
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> + *v4l2_subdev_state_get_format(state, i) = rcar_csi2_default_fmt;
> +
> + return 0;
> +}
> +
> +static const struct v4l2_subdev_internal_ops rcar_csi2_internal_ops = {
> + .init_state = rcsi2_init_state,
> +};
> +
> static irqreturn_t rcsi2_irq(int irq, void *data)
> {
> struct rcar_csi2 *priv = data;
> @@ -1251,14 +1258,17 @@ static irqreturn_t rcsi2_irq(int irq, void *data)
>
> static irqreturn_t rcsi2_irq_thread(int irq, void *data)
> {
> + struct v4l2_subdev_state *state;
> struct rcar_csi2 *priv = data;
>
> - mutex_lock(&priv->lock);
> + state = v4l2_subdev_lock_and_get_active_state(&priv->subdev);
> +
> rcsi2_stop(priv);
> usleep_range(1000, 2000);
> - if (rcsi2_start(priv))
> + if (rcsi2_start(priv, state))
> dev_warn(priv->dev, "Failed to restart CSI-2 receiver\n");
> - mutex_unlock(&priv->lock);
> +
> + v4l2_subdev_unlock_state(state);
>
> return IRQ_HANDLED;
> }
> @@ -1870,23 +1880,23 @@ static int rcsi2_probe(struct platform_device *pdev)
>
> priv->dev = &pdev->dev;
>
> - mutex_init(&priv->lock);
> priv->stream_count = 0;
>
> ret = rcsi2_probe_resources(priv, pdev);
> if (ret) {
> dev_err(priv->dev, "Failed to get resources\n");
> - goto error_mutex;
> + return ret;
> }
>
> platform_set_drvdata(pdev, priv);
>
> ret = rcsi2_parse_dt(priv);
> if (ret)
> - goto error_mutex;
> + return ret;
>
> priv->subdev.owner = THIS_MODULE;
> priv->subdev.dev = &pdev->dev;
> + priv->subdev.internal_ops = &rcar_csi2_internal_ops;
> v4l2_subdev_init(&priv->subdev, &rcar_csi2_subdev_ops);
> v4l2_set_subdevdata(&priv->subdev, &pdev->dev);
> snprintf(priv->subdev.name, sizeof(priv->subdev.name), "%s %s",
> @@ -1912,21 +1922,25 @@ static int rcsi2_probe(struct platform_device *pdev)
>
> pm_runtime_enable(&pdev->dev);
>
> + ret = v4l2_subdev_init_finalize(&priv->subdev);
> + if (ret)
> + goto error_pm_runtime;
> +
> ret = v4l2_async_register_subdev(&priv->subdev);
> if (ret < 0)
> - goto error_pm_runtime;
> + goto error_subdev;
>
> dev_info(priv->dev, "%d lanes found\n", priv->lanes);
>
> return 0;
>
> +error_subdev:
> + v4l2_subdev_cleanup(&priv->subdev);
> error_pm_runtime:
> pm_runtime_disable(&pdev->dev);
> error_async:
> v4l2_async_nf_unregister(&priv->notifier);
> v4l2_async_nf_cleanup(&priv->notifier);
> -error_mutex:
> - mutex_destroy(&priv->lock);
>
> return ret;
> }
> @@ -1941,8 +1955,6 @@ static void rcsi2_remove(struct platform_device *pdev)
> v4l2_subdev_cleanup(&priv->subdev);
>
> pm_runtime_disable(&pdev->dev);
> -
> - mutex_destroy(&priv->lock);
> }
>
> static struct platform_driver rcar_csi2_pdrv = {
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-05-05 21:54 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 15:51 [PATCH 00/11] media: renesas: rcar-csi2: Use the subdev active state Jacopo Mondi
2024-05-03 15:51 ` [PATCH 01/11] media: rcar-vin: Fix YUYV8_1X16 handling for CSI-2 Jacopo Mondi
2024-05-05 20:50 ` Laurent Pinchart
2024-05-06 15:45 ` Niklas Söderlund
2024-05-03 15:51 ` [PATCH 02/11] media: rcar-csi2: Disable runtime_pm in probe error Jacopo Mondi
2024-05-05 20:52 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 03/11] media: rcar-csi2: Cleanup subdevice in remove() Jacopo Mondi
2024-05-05 20:53 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 04/11] media: rcar-csi2: Use the subdev active state Jacopo Mondi
2024-05-03 18:03 ` Niklas Söderlund
2024-05-05 21:52 ` Laurent Pinchart
2024-05-06 11:18 ` Niklas Söderlund
2024-05-06 7:25 ` Jacopo Mondi
2024-05-06 8:10 ` Geert Uytterhoeven
2024-05-06 11:26 ` Niklas Söderlund
2024-05-05 21:54 ` Laurent Pinchart [this message]
2024-05-03 15:51 ` [PATCH 05/11] media: adv748x-csi2: Initialize subdev format Jacopo Mondi
2024-05-05 21:01 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 06/11] media: adv748x-csi2: Implement enum_mbus_codes Jacopo Mondi
2024-05-05 21:07 ` Laurent Pinchart
2024-05-06 8:10 ` Jacopo Mondi
2024-05-06 8:38 ` Laurent Pinchart
2024-05-06 8:42 ` Jacopo Mondi
2024-05-06 11:30 ` Niklas Söderlund
2024-05-03 15:51 ` [PATCH 07/11] media: adv748x-csi2: Validate the image format Jacopo Mondi
2024-05-05 21:09 ` Laurent Pinchart
2024-05-06 11:37 ` Niklas Söderlund
2024-05-06 13:21 ` Jacopo Mondi
2024-05-06 14:12 ` Niklas Söderlund
2024-05-06 14:36 ` Jacopo Mondi
2024-05-06 14:58 ` Niklas Söderlund
2024-05-06 15:04 ` Jacopo Mondi
2024-05-06 19:02 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 08/11] media: adv748x-csi2: Use the subdev active state Jacopo Mondi
2024-05-05 21:15 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 09/11] media: max9286: Fix enum_mbus_code Jacopo Mondi
2024-05-05 21:18 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 10/11] media: max9286: Use the subdev active state Jacopo Mondi
2024-05-05 21:26 ` Laurent Pinchart
2024-05-03 15:51 ` [PATCH 11/11] media: max9286: Use frame interval from subdev state Jacopo Mondi
2024-05-05 21:36 ` Laurent Pinchart
2024-05-06 9:37 ` Jacopo Mondi
2024-05-06 10:32 ` Laurent Pinchart
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=20240505215425.GJ23227@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).