[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
<AS8PR04MB908014E336F99BEEB504EDB7FAC4A@AS8PR04MB9080.eurprd04.prod.outlook.com>
Date: Tue, 4 Nov 2025 07:47:43 +0000
From: "G.N. Zhou (OSS)" <guoniu.zhou@....nxp.com>
To: Laurent Pinchart <laurent.pinchart@...asonboard.com>, "G.N. Zhou (OSS)"
<guoniu.zhou@....nxp.com>
CC: Rui Miguel Silva <rmfrfs@...il.com>, Martin Kepplinger
<martink@...teo.de>, Purism Kernel Team <kernel@...i.sm>, Mauro Carvalho
Chehab <mchehab@...nel.org>, Rob Herring <robh@...nel.org>, Krzysztof
Kozlowski <krzk+dt@...nel.org>, Conor Dooley <conor+dt@...nel.org>, Shawn Guo
<shawnguo@...nel.org>, Sascha Hauer <s.hauer@...gutronix.de>, Pengutronix
Kernel Team <kernel@...gutronix.de>, Fabio Estevam <festevam@...il.com>,
Philipp Zabel <p.zabel@...gutronix.de>, Frank Li <frank.li@....com>,
"linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"imx@...ts.linux.dev" <imx@...ts.linux.dev>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "G.N. Zhou" <guoniu.zhou@....com>
Subject: RE: [PATCH v7 2/5] media: imx8mq-mipi-csi2: Use
devm_clk_bulk_get_all() to fetch clocks
Hi Laurent,
Thanks for your review.
> -----Original Message-----
> From: Laurent Pinchart <laurent.pinchart@...asonboard.com>
> Sent: Monday, October 27, 2025 8:12 AM
> To: G.N. Zhou (OSS) <guoniu.zhou@....nxp.com>
> Cc: Rui Miguel Silva <rmfrfs@...il.com>; Martin Kepplinger
> <martink@...teo.de>; Purism Kernel Team <kernel@...i.sm>; Mauro
> Carvalho Chehab <mchehab@...nel.org>; Rob Herring <robh@...nel.org>;
> Krzysztof Kozlowski <krzk+dt@...nel.org>; Conor Dooley
> <conor+dt@...nel.org>; Shawn Guo <shawnguo@...nel.org>; Sascha Hauer
> <s.hauer@...gutronix.de>; Pengutronix Kernel Team
> <kernel@...gutronix.de>; Fabio Estevam <festevam@...il.com>; Philipp
> Zabel <p.zabel@...gutronix.de>; Frank Li <frank.li@....com>; linux-
> media@...r.kernel.org; devicetree@...r.kernel.org; imx@...ts.linux.dev; linux-
> arm-kernel@...ts.infradead.org; linux-kernel@...r.kernel.org; G.N. Zhou
> <guoniu.zhou@....com>
> Subject: Re: [PATCH v7 2/5] media: imx8mq-mipi-csi2: Use
> devm_clk_bulk_get_all() to fetch clocks
>
> On Thu, Oct 23, 2025 at 05:19:43PM +0800, Guoniu Zhou wrote:
> > From: Guoniu Zhou <guoniu.zhou@....com>
> >
> > Use devm_clk_bulk_get_all() helper to simplify clock handle code.
> >
> > No functional changes intended.
> >
> > Reviewed-by: Frank Li <Frank.Li@....com>
> > Signed-off-by: Guoniu Zhou <guoniu.zhou@....com>
> > ---
> > drivers/media/platform/nxp/imx8mq-mipi-csi2.c | 52
> > ++++++++-------------------
> > 1 file changed, 15 insertions(+), 37 deletions(-)
> >
> > diff --git a/drivers/media/platform/nxp/imx8mq-mipi-csi2.c
> > b/drivers/media/platform/nxp/imx8mq-mipi-csi2.c
> > index
> >
> d333ff43539f061b8b9cf88af2cda8c44b3ec2a9..fd202601d401145da8be23df4
> 451
> > f6af660642c5 100644
> > --- a/drivers/media/platform/nxp/imx8mq-mipi-csi2.c
> > +++ b/drivers/media/platform/nxp/imx8mq-mipi-csi2.c
> > @@ -71,21 +71,6 @@ enum {
> > ST_SUSPENDED = 4,
> > };
> >
> > -enum imx8mq_mipi_csi_clk {
> > - CSI2_CLK_CORE,
> > - CSI2_CLK_ESC,
> > - CSI2_CLK_UI,
> > - CSI2_NUM_CLKS,
> > -};
> > -
> > -static const char * const imx8mq_mipi_csi_clk_id[CSI2_NUM_CLKS] = {
> > - [CSI2_CLK_CORE] = "core",
> > - [CSI2_CLK_ESC] = "esc",
> > - [CSI2_CLK_UI] = "ui",
> > -};
> > -
> > -#define CSI2_NUM_CLKS ARRAY_SIZE(imx8mq_mipi_csi_clk_id)
> > -
> > struct imx8mq_plat_data {
> > int (*enable)(struct csi_state *state, u32 hs_settle);
> > void (*disable)(struct csi_state *state); @@ -111,7 +96,8 @@ struct
> > csi_state {
> > struct device *dev;
> > const struct imx8mq_plat_data *pdata;
> > void __iomem *regs;
> > - struct clk_bulk_data clks[CSI2_NUM_CLKS];
> > + struct clk_bulk_data *clks;
> > + int num_clks;
> > struct reset_control *rst;
> > struct regulator *mipi_phy_regulator;
> >
> > @@ -384,24 +370,16 @@ static void imx8mq_mipi_csi_set_params(struct
> csi_state *state)
> > CSI2RX_SEND_LEVEL);
> > }
> >
> > -static int imx8mq_mipi_csi_clk_enable(struct csi_state *state) -{
> > - return clk_bulk_prepare_enable(CSI2_NUM_CLKS, state->clks);
> > -}
> > -
> > -static void imx8mq_mipi_csi_clk_disable(struct csi_state *state)
> > +static struct clk *find_esc_clk(struct csi_state *state)
>
> This is one of the reasons why I don't like devm_clk_bulk_get_all(). I won't
> object to this patch, but I don't like it. At the very lest, you should look up the
> clock at probe time and cache it in the imx8mq_plat_data structure, to avoid
> looking it up multiple times at runtime.
Ok, but could we cache the clock in the csi_state structure? Because the imx8mq_plat_data
structure instance is const.
>
> > {
> > - clk_bulk_disable_unprepare(CSI2_NUM_CLKS, state->clks);
> > -}
> > -
> > -static int imx8mq_mipi_csi_clk_get(struct csi_state *state) -{
> > - unsigned int i;
> > + int i;
> >
> > - for (i = 0; i < CSI2_NUM_CLKS; i++)
> > - state->clks[i].id = imx8mq_mipi_csi_clk_id[i];
> > + for (i = 0; i < state->num_clks; i++) {
>
> Make state->num_clks unsigned instead of making i signed.
>
> > + if (!strcmp(state->clks[i].id, "esc"))
> > + return state->clks[i].clk;
> > + }
> >
> > - return devm_clk_bulk_get(state->dev, CSI2_NUM_CLKS, state->clks);
> > + return NULL;
>
> This needs to become a probe error.
Got it, will update in next version.
>
> > }
> >
> > static int imx8mq_mipi_csi_calc_hs_settle(struct csi_state *state, @@
> > -456,7 +434,7 @@ static int imx8mq_mipi_csi_calc_hs_settle(struct csi_state
> *state,
> > * documentation recommends picking a value away from the
> boundaries.
> > * Let's pick the average.
> > */
> > - esc_clk_rate = clk_get_rate(state->clks[CSI2_CLK_ESC].clk);
> > + esc_clk_rate = clk_get_rate(find_esc_clk(state));
> > if (!esc_clk_rate) {
> > dev_err(state->dev, "Could not get esc clock rate.\n");
> > return -EINVAL;
> > @@ -783,7 +761,7 @@ static void imx8mq_mipi_csi_pm_suspend(struct
> > device *dev)
> >
> > if (state->state & ST_POWERED) {
> > imx8mq_mipi_csi_stop_stream(state);
> > - imx8mq_mipi_csi_clk_disable(state);
> > + clk_bulk_disable_unprepare(state->num_clks, state->clks);
> > state->state &= ~ST_POWERED;
> > }
> >
> > @@ -801,7 +779,7 @@ static int imx8mq_mipi_csi_pm_resume(struct
> device
> > *dev)
> >
> > if (!(state->state & ST_POWERED)) {
> > state->state |= ST_POWERED;
> > - ret = imx8mq_mipi_csi_clk_enable(state);
> > + ret = clk_bulk_prepare_enable(state->num_clks, state->clks);
> > }
> > if (state->state & ST_STREAMING) {
> > sd_state = v4l2_subdev_lock_and_get_active_state(sd);
> > @@ -1027,9 +1005,9 @@ static int imx8mq_mipi_csi_probe(struct
> platform_device *pdev)
> > if (IS_ERR(state->regs))
> > return PTR_ERR(state->regs);
> >
> > - ret = imx8mq_mipi_csi_clk_get(state);
> > - if (ret < 0)
> > - return ret;
> > + state->num_clks = devm_clk_bulk_get_all(dev, &state->clks);
> > + if (state->num_clks < 0)
> > + return dev_err_probe(dev, state->num_clks, "Failed to get
> > +clocks\n");
> >
> > platform_set_drvdata(pdev, &state->sd);
> >
>
> --
> Regards,
>
> Laurent Pinchart
Powered by blists - more mailing lists