[PATCH v1 9/9] coresight: Consolidate clock enabling

Leo Yan leo.yan at arm.com
Tue Apr 1 08:29:45 PDT 2025


On Tue, Apr 01, 2025 at 03:58:42PM +0100, James Clark wrote:

[...]

> >   /*
> > - * Attempt to find and enable "APB clock" for the given device
> > + * Attempt to find and enable programming clock (pclk) and trace clock (atclk)
> > + * for the given device.
> >    *
> > - * Returns:
> > + * The AMBA bus driver will cover the pclk, to avoid duplicate operations,
> > + * skip to get and enable the pclk for an AMBA device.
> >    *
> > - * clk   - Clock is found and enabled
> > - * NULL  - Clock is not needed as it is managed by the AMBA bus driver
> > - * ERROR - Clock is found but failed to enable
> > + * atclk is an optional clock, it will be only enabled when it is existed.
> > + * Otherwise, a NULL pointer will be returned to caller.
> > + *
> > + * Returns: '0' on Success; Error code otherwise.
> >    */
> > -static inline struct clk *coresight_get_enable_apb_pclk(struct device *dev)
> > +static inline int coresight_get_enable_clocks(struct device *dev,
> > +					      struct clk **pclk,
> > +					      struct clk **atclk)
> 
> This function has grown a bit now, probably best to remove it from the
> header and export it instead.

Sure.  I can move this function into coresight-core.c file.

> >   {
> > -	struct clk *pclk = NULL;
> > +	WARN_ON(!pclk);
> >   	if (!dev_is_amba(dev)) {
> > -		pclk = devm_clk_get_enabled(dev, "apb_pclk");
> > -		if (IS_ERR(pclk))
> > -			pclk = devm_clk_get_enabled(dev, "apb");
> > +		*pclk = devm_clk_get_enabled(dev, "apb_pclk");
> > +		if (IS_ERR(*pclk))
> > +			*pclk = devm_clk_get_enabled(dev, "apb");
> > +		if (IS_ERR(*pclk))
> > +			return PTR_ERR(*pclk);
> > +	} else {
> > +		/* Don't enable pclk for an AMBA device */
> > +		*pclk = NULL;
> 
> Now the "apb" clock won't be enabled for amba devices. I'm assuming that's
> fine if the clock was always called "apb_pclk" for them, but the commit that
> added the new clock name didn't specify any special casing either.

> Can we have a comment that says it's deliberate? But the more I think about
> it the more I'm confused why CTCU needed a different clock name to be
> defined, when all the other Coresight devices use "apb_pclk".

Yes, seems to me, "apb" clock is the same thing with "apb_pclk".  As
CTCU DT binding has been merged, for backward compatible, we cannot
remove it now.

CTCU driver only supports static probe, it is never probed by AMBA bus
driver.  I think this is another reason that "apb_pclk" is not used in
CTCU driver.  I can add a comment like:

  "apb_pclk" is the default clock name used by the AMBA bus driver,
  while "apb" is used only by the CTCU driver.  A CoreSight driver
  should use "apb_pclk" as its programming clock name.

Thanks,
Leo

> >   	}
> > -	return pclk;
> > +	if (atclk) {
> > +		*atclk = devm_clk_get_optional_enabled(dev, "atclk");
> > +		if (IS_ERR(*atclk))
> > +			return PTR_ERR(*atclk);
> > +	}
> > +
> > +	return 0;
> >   }
> >   #define CORESIGHT_PIDRn(i)	(0xFE0 + ((i) * 4))
> 



More information about the linux-arm-kernel mailing list