2015-02-11 02:10:28

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] dmaengine: dw: support for clockless platforms

On Tue, Jan 20, 2015 at 8:57 PM, Heikki Krogerus
<[email protected]> wrote:
> When requesting clock in the platform driver, leaving
> chip->clk value as NULL if -ENOENT is returned, and
> continue. With other errors returning failure. It makes the
> driver usable on platforms that do not provide the clock.
>
> Signed-off-by: Heikki Krogerus <[email protected]>
> ---
> drivers/dma/dw/platform.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
> index 32ea1ac..b183bc0 100644
> --- a/drivers/dma/dw/platform.c
> +++ b/drivers/dma/dw/platform.c
> @@ -180,8 +180,12 @@ static int dw_probe(struct platform_device *pdev)
> chip->dev = dev;
>
> chip->clk = devm_clk_get(chip->dev, "hclk");
> - if (IS_ERR(chip->clk))
> - return PTR_ERR(chip->clk);
> + if (IS_ERR(chip->clk)) {
> + if (PTR_ERR(chip->clk) == -ENOENT)
> + chip->clk = NULL;

This is wrong and reasons are mentioned in this thread:

http://lists.infradead.org/pipermail/linux-arm-kernel/2012-March/088437.html

You don't need to set it to NULL, if CONFIG_HAVE_CLK isn't set
the dummy routines would take care of it.


2015-02-11 12:03:24

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] dmaengine: dw: support for clockless platforms

On Wed, 2015-02-11 at 10:10 +0800, Viresh Kumar wrote:
> On Tue, Jan 20, 2015 at 8:57 PM, Heikki Krogerus
> <[email protected]> wrote:
> > When requesting clock in the platform driver, leaving
> > chip->clk value as NULL if -ENOENT is returned, and
> > continue. With other errors returning failure. It makes the
> > driver usable on platforms that do not provide the clock.
> >
> > Signed-off-by: Heikki Krogerus <[email protected]>
> > ---
> > drivers/dma/dw/platform.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
> > index 32ea1ac..b183bc0 100644
> > --- a/drivers/dma/dw/platform.c
> > +++ b/drivers/dma/dw/platform.c
> > @@ -180,8 +180,12 @@ static int dw_probe(struct platform_device *pdev)
> > chip->dev = dev;
> >
> > chip->clk = devm_clk_get(chip->dev, "hclk");
> > - if (IS_ERR(chip->clk))
> > - return PTR_ERR(chip->clk);
> > + if (IS_ERR(chip->clk)) {
> > + if (PTR_ERR(chip->clk) == -ENOENT)
> > + chip->clk = NULL;
>
> This is wrong and reasons are mentioned in this thread:
>
> http://lists.infradead.org/pipermail/linux-arm-kernel/2012-March/088437.html

Thanks for the link.

>
> You don't need to set it to NULL, if CONFIG_HAVE_CLK isn't set
> the dummy routines would take care of it.

Yeah, but in our case we have CONFIG_HAVE_CLK=y and no clk is provided
since IP is clockless. What could you suggest to do in such case?

--
Andy Shevchenko <[email protected]>
Intel Finland Oy

2015-02-11 12:07:40

by Russell King - ARM Linux

[permalink] [raw]
Subject: Re: [PATCH] dmaengine: dw: support for clockless platforms

On Wed, Feb 11, 2015 at 02:02:39PM +0200, Andy Shevchenko wrote:
> On Wed, 2015-02-11 at 10:10 +0800, Viresh Kumar wrote:
> > > chip->clk = devm_clk_get(chip->dev, "hclk");
> > > - if (IS_ERR(chip->clk))
> > > - return PTR_ERR(chip->clk);
> > > + if (IS_ERR(chip->clk)) {
> > > + if (PTR_ERR(chip->clk) == -ENOENT)
> > > + chip->clk = NULL;
> >
> > You don't need to set it to NULL, if CONFIG_HAVE_CLK isn't set
> > the dummy routines would take care of it.
>
> Yeah, but in our case we have CONFIG_HAVE_CLK=y and no clk is provided
> since IP is clockless. What could you suggest to do in such case?

chip->clk = devm_clk_get(chip->dev, "hclk");
if (IS_ERR(chip->clk) && PTR_ERR(chip->clk) != -ENOENT)
return PTR_ERR(chip->clk);

You can then test for the presence of a clk via IS_ERR(chip->clk).

I'm just debating whether we should add a clk_is_valid() inline function
to linux/clk.h to avoid these shouting tests, and make it easier for
people test this in a generic manner.

--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

2015-02-11 12:19:48

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] dmaengine: dw: support for clockless platforms

On Wed, 2015-02-11 at 12:07 +0000, Russell King - ARM Linux wrote:
> On Wed, Feb 11, 2015 at 02:02:39PM +0200, Andy Shevchenko wrote:
> > On Wed, 2015-02-11 at 10:10 +0800, Viresh Kumar wrote:
> > > > chip->clk = devm_clk_get(chip->dev, "hclk");
> > > > - if (IS_ERR(chip->clk))
> > > > - return PTR_ERR(chip->clk);
> > > > + if (IS_ERR(chip->clk)) {
> > > > + if (PTR_ERR(chip->clk) == -ENOENT)
> > > > + chip->clk = NULL;
> > >
> > > You don't need to set it to NULL, if CONFIG_HAVE_CLK isn't set
> > > the dummy routines would take care of it.
> >
> > Yeah, but in our case we have CONFIG_HAVE_CLK=y and no clk is provided
> > since IP is clockless. What could you suggest to do in such case?
>
> chip->clk = devm_clk_get(chip->dev, "hclk");
> if (IS_ERR(chip->clk) && PTR_ERR(chip->clk) != -ENOENT)
> return PTR_ERR(chip->clk);
>
> You can then test for the presence of a clk via IS_ERR(chip->clk).
>
> I'm just debating whether we should add a clk_is_valid() inline function
> to linux/clk.h to avoid these shouting tests, and make it easier for
> people test this in a generic manner.

I guess clock framework may handle whatever is gotten from clk_get().
In driver much cleaner to use direct calls with exceptions (like you
can't get a valid clock rate from non-existing clock).
So, what about just passing by the error code and doing nothing?

--
Andy Shevchenko <[email protected]>
Intel Finland Oy