Skip to contentSkip to conversation

dmaengine: dw: support for clockless platforms

PATCH Applied Heikki Krogerus 5 participants 7 messages Jan 20, 2015 – Feb 11, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: dw: support for clockless platforms

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.

---
 drivers/dma/dw/platform.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dma/dw/platform.c +6 -2
index 32ea1ac..b183bc0 100644
@@ -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;
+		else
+			return PTR_ERR(chip->clk);
+	}
 	err = clk_prepare_enable(chip->clk);
 	if (err)
 		return err;
Signature · 1 line
2.1.4
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Heikki Krogerus

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.

Quoted 23 lines
---
 drivers/dma/dw/platform.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dma/dw/platform.c +6 -2
index 32ea1ac..b183bc0 100644
@@ -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;
+		else
+			return PTR_ERR(chip->clk);
+	}
 	err = clk_prepare_enable(chip->clk);
 	if (err)
 		return err;
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Applied
#2 lore raw
In reply to Heikki Krogerus
Quoted 4 lines · Heikki Krogerus

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.

Applied, thanks

Signature · 1 line
~Vinod
#3 lore raw
In reply to Heikki Krogerus
Quoted 15 lines · Heikki Krogerus

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.

---
 drivers/dma/dw/platform.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dma/dw/platform.c +0 -0
index 32ea1ac..b183bc0 100644

drivers/dma/dw/platform.c static int dw_probe(struct platform_device *pdev) · line 185

Quoted 8 lines
drivers/dma/dw/platform.c +3 -2
@@ -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.

#4 lore raw
Quoted 28 lines · Viresh Kumar
Quoted 15 lines · Heikki Krogerus

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.

---
 drivers/dma/dw/platform.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dma/dw/platform.c +0 -0
index 32ea1ac..b183bc0 100644

drivers/dma/dw/platform.c static int dw_probe(struct platform_device *pdev) · line 185

Quoted 8 lines
drivers/dma/dw/platform.c +3 -2
@@ -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:

Quoted 1 line

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

Thanks for the link.

Quoted 3 lines

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?

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Viresh Kumar
Quoted 6 lines
        chip->clk = devm_clk_get(chip->dev, "hclk");
drivers/dma/dw/platform.c +3 -2
-       if (IS_ERR(chip->clk))
-               return PTR_ERR(chip->clk);
+       if (IS_ERR(chip->clk)) {
+               if (PTR_ERR(chip->clk) == -ENOENT)
+                       chip->clk = NULL;
Quoted 5 lines
Quoted 2 lines

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.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#6 lore raw
Quoted 19 lines · Russell King - ARM Linux
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Viresh Kumar
Quoted 6 lines
        chip->clk = devm_clk_get(chip->dev, "hclk");
drivers/dma/dw/platform.c +3 -2
-       if (IS_ERR(chip->clk))
-               return PTR_ERR(chip->clk);
+       if (IS_ERR(chip->clk)) {
+               if (PTR_ERR(chip->clk) == -ENOENT)
+                       chip->clk = NULL;
Quoted 5 lines
Quoted 2 lines

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);
Quoted 5 lines

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?

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy