public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Frank Li <Frank.Li@nxp.com>
Cc: Steve Longerbeam <slongerbeam@gmail.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	imx@lists.linux.dev, linux-media@vger.kernel.org,
	linux-staging@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v2 3/5] media: staging: media: imx6-mipi-csi2: use devm_clk_bulk_get_all() to fetch clocks
Date: Wed, 21 Jan 2026 04:08:08 +0200	[thread overview]
Message-ID: <20260121020808.GG403250@killaraus> (raw)
In-Reply-To: <20260116-stage-csi2-cleanup-v2-3-a56e9cb25196@nxp.com>

On Fri, Jan 16, 2026 at 11:17:58AM -0500, Frank Li wrote:
> Use devm_clk_bulk_get_all_enabled() helper to simplify clock handling.
> 
> Defer all clock prepare and enable to csi2_start(), which previous only
> enable pix clock here.
> 
> Add clk_enable at log_status().
> 
> Do that safely because there are not register access before csi2_start().
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> changes in v2
> - add clk_bulk_prepare_enable() get at csi2_log_status()
> ---
>  drivers/staging/media/imx/imx6-mipi-csi2.c | 57 +++++++++---------------------
>  1 file changed, 16 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
> index 4f740170d2bbf586ac0a58b5d25f8f8432e9e6a3..e1b4b7fb53131ce9515b9441d8fc420e85d3e993 100644
> --- a/drivers/staging/media/imx/imx6-mipi-csi2.c
> +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
> @@ -39,9 +39,8 @@ struct csi2_dev {
>  	struct v4l2_subdev sd;
>  	struct v4l2_async_notifier notifier;
>  	struct media_pad pad[CSI2_NUM_PADS];
> -	struct clk *dphy_clk;
> -	struct clk *pllref_clk;
> -	struct clk *pix_clk; /* what is this? */
> +	struct clk_bulk_data *clks;
> +	int num_clks;
>  	void __iomem *base;
>  
>  	struct v4l2_subdev *remote;
> @@ -343,7 +342,7 @@ static int csi2_start(struct csi2_dev *csi2)
>  	unsigned int lanes;
>  	int ret;
>  
> -	ret = clk_prepare_enable(csi2->pix_clk);
> +	ret = clk_bulk_prepare_enable(csi2->num_clks, csi2->clks);
>  	if (ret)
>  		return ret;
>  
> @@ -390,7 +389,7 @@ static int csi2_start(struct csi2_dev *csi2)
>  err_assert_reset:
>  	csi2_enable(csi2, false);
>  err_disable_clk:
> -	clk_disable_unprepare(csi2->pix_clk);
> +	clk_bulk_disable_unprepare(csi2->num_clks, csi2->clks);
>  	return ret;
>  }
>  
> @@ -401,7 +400,7 @@ static void csi2_stop(struct csi2_dev *csi2)
>  	v4l2_subdev_call(csi2->src_sd, video, post_streamoff);
>  
>  	csi2_enable(csi2, false);
> -	clk_disable_unprepare(csi2->pix_clk);
> +	clk_bulk_disable_unprepare(csi2->num_clks, csi2->clks);
>  }
>  
>  /*
> @@ -570,6 +569,11 @@ static int csi2_registered(struct v4l2_subdev *sd)
>  static int csi2_log_status(struct v4l2_subdev *sd)
>  {
>  	struct csi2_dev *csi2 = sd_to_dev(sd);
> +	int ret;
> +
> +	ret = clk_bulk_prepare_enable(csi2->num_clks, csi2->clks);
> +	if (ret)
> +		return ret;
>  
>  	v4l2_info(sd, "-----MIPI CSI status-----\n");
>  	v4l2_info(sd, "VERSION: 0x%x\n",
> @@ -601,6 +605,8 @@ static int csi2_log_status(struct v4l2_subdev *sd)
>  	v4l2_info(sd, "PHY_TST_CTRL1: 0x%x\n",
>  		  readl(csi2->base + CSI2_PHY_TST_CTRL1));
>  
> +	clk_bulk_disable_unprepare(csi2->num_clks, csi2->clks);
> +
>  	return 0;
>  }
>  
> @@ -749,24 +755,6 @@ static int csi2_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref");
> -	if (IS_ERR(csi2->pllref_clk)) {
> -		v4l2_err(&csi2->sd, "failed to get pll reference clock\n");
> -		return PTR_ERR(csi2->pllref_clk);
> -	}
> -
> -	csi2->dphy_clk = devm_clk_get(&pdev->dev, "dphy");
> -	if (IS_ERR(csi2->dphy_clk)) {
> -		v4l2_err(&csi2->sd, "failed to get dphy clock\n");
> -		return PTR_ERR(csi2->dphy_clk);
> -	}
> -
> -	csi2->pix_clk = devm_clk_get(&pdev->dev, "pix");
> -	if (IS_ERR(csi2->pix_clk)) {
> -		v4l2_err(&csi2->sd, "failed to get pixel clock\n");
> -		return PTR_ERR(csi2->pix_clk);
> -	}
> -
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!res) {
>  		v4l2_err(&csi2->sd, "failed to get platform resources\n");
> @@ -781,20 +769,12 @@ static int csi2_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ret = clk_prepare_enable(csi2->pllref_clk);
> -	if (ret) {
> -		v4l2_err(&csi2->sd, "failed to enable pllref_clk\n");
> -		return ret;
> -	}
> -
> -	ret = clk_prepare_enable(csi2->dphy_clk);
> -	if (ret) {
> -		v4l2_err(&csi2->sd, "failed to enable dphy_clk\n");
> -		goto pllref_off;
> -	}
> -
>  	platform_set_drvdata(pdev, &csi2->sd);
>  
> +	csi2->num_clks = devm_clk_bulk_get_all(&pdev->dev, &csi2->clks);
> +	if (csi2->num_clks < 0)
> +		return dev_err_probe(&pdev->dev, csi2->num_clks, "Failed to get clocks\n");

I'm still really not a fan of devm_clk_bulk_get_all(). I would prefer
using clk_bulk_get(). The rest looks fine, although I would have split
this patch in two, one to switch to the bulk API, and one to move
enabling/disabling of the clocks.

Ah, no, there's one clock that's already enabled at start time, so a
single patch is fine.

> +
>  	ret = csi2_async_register(csi2);
>  	if (ret)
>  		goto clean_notifier;
> @@ -804,9 +784,6 @@ static int csi2_probe(struct platform_device *pdev)
>  clean_notifier:
>  	v4l2_async_nf_unregister(&csi2->notifier);
>  	v4l2_async_nf_cleanup(&csi2->notifier);
> -	clk_disable_unprepare(csi2->dphy_clk);
> -pllref_off:
> -	clk_disable_unprepare(csi2->pllref_clk);
>  	return ret;
>  }
>  
> @@ -818,8 +795,6 @@ static void csi2_remove(struct platform_device *pdev)
>  	v4l2_async_nf_unregister(&csi2->notifier);
>  	v4l2_async_nf_cleanup(&csi2->notifier);
>  	v4l2_async_unregister_subdev(sd);
> -	clk_disable_unprepare(csi2->dphy_clk);
> -	clk_disable_unprepare(csi2->pllref_clk);
>  	media_entity_cleanup(&sd->entity);
>  }
>  

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2026-01-21  2:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 16:17 [PATCH RESEND v2 0/5] media: staging: media: imx6-mipi-csi2: trivial cleanup to prepare convert to common dw mipi csi2 Frank Li
2026-01-16 16:17 ` [PATCH RESEND v2 1/5] media: staging: media: imx6-mipi-csi2: replace spaces with tabs for alignment Frank Li
2026-01-21  1:59   ` Laurent Pinchart
2026-01-16 16:17 ` [PATCH RESEND v2 2/5] media: staging: media: imx6-mipi-csi2: use devm_mutex_init() to simplify code Frank Li
2026-01-21  2:00   ` Laurent Pinchart
2026-01-16 16:17 ` [PATCH RESEND v2 3/5] media: staging: media: imx6-mipi-csi2: use devm_clk_bulk_get_all() to fetch clocks Frank Li
2026-01-21  2:08   ` Laurent Pinchart [this message]
2026-01-16 16:17 ` [PATCH RESEND v2 4/5] media: staging: media: imx6-mipi-csi2: use guard() to simplify code Frank Li
2026-01-21  2:13   ` Laurent Pinchart
2026-01-16 16:18 ` [PATCH RESEND v2 5/5] media: staging: media: imx6-mipi-csi2: use devm_platform_ioremap_resource() " Frank Li
2026-01-21  2:17 ` [PATCH RESEND v2 0/5] media: staging: media: imx6-mipi-csi2: trivial cleanup to prepare convert to common dw mipi csi2 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=20260121020808.GG403250@killaraus \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=Frank.Li@nxp.com \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=slongerbeam@gmail.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