net: davinci_mdio: enable and disable clock
PATCH 1/2 net: davinci_mdio: enable and disable clock
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/davinci_mdio.c +14 -2
@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; } +clk_enable (data->clk); +dev_set_drvdata (dev, data); data->dev = dev;spin_lock_init (&data->lock);
@@ -379,8 +381,11 @@ bail_out:if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);
@@ -397,8 +402,11 @@ static int __devexit davinci_mdio_remove(struct platform_device *pdev)if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);
@@ -427,6 +435,8 @@ static int davinci_mdio_suspend(struct device *dev) data->suspended = true;spin_unlock (&data->lock); +clk_disable (data->clk); +return 0 ; }
@@ -435,6 +445,8 @@ static int davinci_mdio_resume(struct device *dev)struct davinci_mdio_data *data =dev_get_drvdata (dev);u32 ctrl; +clk_enable (data->clk); +spin_lock (&data->lock);pm_runtime_put_sync (data->dev);
Signature · 1 line
1.7.11.2
PATCH 2/2 net: davinci_mdio: add DT bindings
--- .../devicetree/bindings/net/davinci_mdio.txt | 24 +++++++++++++ drivers/net/ethernet/ti/davinci_mdio.c | 39 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davinci_mdio.txt
Documentation/devicetree/bindings/net/davinci_mdio.txt new file +24 -0
@@ -0,0 +1,24 @@ +Davinci MDIO DT bindings + +Required properties: + + - compatible : should be "ti,davinci-mdio" + +Optional properties: + + - bus-freq : an integer to specify the bus speed + +Examples: + + mdio: davinci_mdio at 4a101000 { + compatible = "ti,davinci-mdio"; + ti,hwmods = "davinci_mdio"; + }; + + or + + mdio: davinci_mdio at 4a101000 { + compatible = "ti,davinci-mdio"; + reg = <0x4a101000 0x100>; + }; +
drivers/net/ethernet/ti/davinci_mdio.c +39 -0
@@ -36,6 +36,8 @@#include <linux/io.h> #include <linux/pm_runtime.h> #include <linux/davinci_emac.h> +#include <linux/of.h> +#include <linux/of_device.h> /* * This timeout definition is a worst-case ultra defensive measure against
@@ -289,6 +291,37 @@ static int davinci_mdio_write(struct mii_bus *bus, int phy_id,return 0 ; } +#ifdef CONFIG_OF +static const struct of_device_id davinci_mdio_dt_ids[] = { + { .compatible ="ti,davinci-mdio" }, + { } +}; +MODULE_DEVICE_TABLE (of, davinci_mdio_dt_ids); + +static inline int davinci_mdio_probe_dt (struct device *dev, +struct mdio_platform_data *pdata) +{ +struct device_node *np = dev->of_node; +const struct of_device_id *of_id = +of_match_device (davinci_mdio_dt_ids, dev); +u32 tmp; + +if (!of_id) +return 0 ; + +if (of_property_read_u32 (np,"bus-freq" , &tmp) ==0 ) + pdata->bus_freq = tmp; + +return 0 ; +} +#else +static inline int davinci_mdio_probe_dt (struct device *dev, +struct mdio_platform_data *pdata) +{ +return 0 ; +} +#endif +static int __devinit davinci_mdio_probe (struct platform_device *pdev) {struct mdio_platform_data *pdata = pdev->dev.platform_data;
@@ -306,6 +339,10 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) data->pdata = pdata ? (*pdata) : default_pdata; + ret =davinci_mdio_probe_dt (dev, pdata); +if (ret <0 ) + goto free_mem; + data->bus =mdiobus_alloc ();if (!data->bus) {dev_err (dev,"failed to alloc mii bus\n" );
@@ -389,6 +426,7 @@ bail_out:pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev); +free_mem:kfree (data);return ret;
@@ -471,6 +509,7 @@ static struct platform_driver davinci_mdio_driver = { .name = "davinci_mdio", .owner = THIS_MODULE, .pm = &davinci_mdio_pm_ops, + .of_match_table = of_match_ptr(davinci_mdio_dt_ids), }, .probe = davinci_mdio_probe, .remove = __devexit_p(davinci_mdio_remove),
Signature · 1 line
1.7.11.2
Quoted 3 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Hmm, this looks like it could do with improvement, especially as we're moving everything over to a common clk API.
1. This driver could do with clk_prepare()/clk_unprepare() calls.
2. This driver should not be making the assumption that NULL means it can avoid clk_* calls. It should instead be using
if (!IS_ERR(clk))
Thanks.
Quoted 9 lines · Russell King - ARM Linux
Quoted 3 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Hmm, this looks like it could do with improvement, especially as we're moving everything over to a common clk API.
1. This driver could do with clk_prepare()/clk_unprepare() calls.
Ok, done.
Quoted 3 lines
2. This driver should not be making the assumption that NULL means it can avoid clk_* calls. It should instead be using
if (!IS_ERR(clk))
Well spotted. Amended patch below.
Thanks,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-net-davinci_mdio-prepare-and-unprepare-clocks.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120802/2fa5d4e5/attachment.bin>
Hi
Quoted 15 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Signed-off-by Daniel Mack <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/net/ethernet/ti/davinci_mdio.c +0
-0
drivers/net/ethernet/ti/davinci_mdio.c static int __devinit davinci_mdio_probe(struct platform_device *pdev) · line 336
Quoted 5 lines
drivers/net/ethernet/ti/davinci_mdio.c +2
-0@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; } +clk_enable (data->clk); +
This doesn't look right. This clock should be enabled by the pm_runtime_get_sync() call just above this. It shouldn't be necessary to enable it again unless something isn't right with the integration data. Likewise the pm_runtime_put_sync() calls should be superfluous.
What hwmod data/device tree file are you using with this?
- Paul
Quoted 22 lines · Paul Walmsley
Hi
Quoted 18 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Signed-off-by Daniel Mack <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/net/ethernet/ti/davinci_mdio.c +0
-0@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; }
Quoted 7 lines
drivers/net/ethernet/ti/davinci_mdio.c static int __devinit davinci_mdio_probe(struct platform_device *pdev) · line 336
Quoted 2 lines
drivers/net/ethernet/ti/davinci_mdio.c +2
-0+clk_enable (data->clk); +This doesn't look right. This clock should be enabled by the
pm_runtime_get_sync()call just above this. It shouldn't be necessary to enable it again unless something isn't right with the integration data. Likewise thepm_runtime_put_sync()calls should be superfluous.
Aah, thanks for the heads-up. To explain, I first worked with a dirty hack to alias the clock, and I definitely needed these extra calls then.
Quoted 1 line
What hwmod data/device tree file are you using with this?
Later, I added the hwmod to move away from these hacks, and indeed, that lets the pm runtime code handle the clock enabling. With that in place, the patch we're talking about here is in fact unnecessary.
The second one though (the one that adds DT bindings) should go in.
I will send a separate one later that fixes the IS_ERR(data->clk) error that Russell spotted. But that's now unrelated.
Thanks for the review,
Daniel
Quoted 58 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Signed-off-by Daniel Mack <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/net/ethernet/ti/davinci_mdio.c +12
-2@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; } +clk_enable (data->clk); +dev_set_drvdata (dev, data); data->dev = dev;spin_lock_init (&data->lock);@@ -379,8 +381,11 @@ bail_out:if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -397,8 +402,11 @@ static int __devexit davinci_mdio_remove(struct platform_device *pdev)if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -427,6 +435,8 @@ static int davinci_mdio_suspend(struct device *dev) data->suspended = true;spin_unlock (&data->lock); +clk_disable (data->clk); +return 0 ; }
drivers/net/ethernet/ti/davinci_mdio.c static int davinci_mdio_resume(struct device *dev) · line 449
Quoted 5 lines
drivers/net/ethernet/ti/davinci_mdio.c +2
-0@@ -435,6 +445,8 @@ static int davinci_mdio_resume(struct device *dev)struct davinci_mdio_data *data =dev_get_drvdata (dev);u32 ctrl; +clk_enable (data->clk); +
Danial,
I would request you to wait for this, its not that simple and straight. And once you migrate to runtime PM you don't need clk_enable/disable, this should get handled under runtime PM api's.
Also have you read my another email post -
http://comments.gmane.org/gmane.linux.ports.arm.omap/80796
Certainly, with respect to CPSW & MDIO, this patch is not enough and requires further investigation. I have started looking at this and hopefully will have some solution soon...
Thanks,
Vaibhav
Quoted 64 lines · Vaibhav Hiremath
Quoted 61 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Signed-off-by Daniel Mack <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/net/ethernet/ti/davinci_mdio.c +12
-2@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; } +clk_enable (data->clk); +dev_set_drvdata (dev, data); data->dev = dev;spin_lock_init (&data->lock);@@ -379,8 +381,11 @@ bail_out:if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -397,8 +402,11 @@ static int __devexit davinci_mdio_remove(struct platform_device *pdev)if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -427,6 +435,8 @@ static int davinci_mdio_suspend(struct device *dev) data->suspended = true;spin_unlock (&data->lock); +clk_disable (data->clk); +return 0 ; }@@ -435,6 +445,8 @@ static int davinci_mdio_resume(struct device *dev)struct davinci_mdio_data *data =dev_get_drvdata (dev);u32 ctrl;
Quoted 8 lines
drivers/net/ethernet/ti/davinci_mdio.c static int davinci_mdio_resume(struct device *dev) · line 449
Quoted 2 lines
drivers/net/ethernet/ti/davinci_mdio.c +2
-0+clk_enable (data->clk); +Danial,
I would request you to wait for this, its not that simple and straight. And once you migrate to runtime PM you don't need clk_enable/disable, this should get handled under runtime PM api's.
As I said, it can be dropped.
Quoted 7 lines
Also have you read my another email post -
http://comments.gmane.org/gmane.linux.ports.arm.omap/80796
Certainly, with respect to CPSW & MDIO, this patch is not enough and requires further investigation. I have started looking at this and hopefully will have some solution soon...
Ok, no problem. We certainly need the DT bindings for davinci_mdio. With that applied, and the hwmod added (in the patch I posted yesterday), I can at least mount the rootfs via NFS, which is all I currently need.
Best regards,
Daniel
Quoted 80 lines · Daniel Mack
Quoted 64 lines · Vaibhav Hiremath
Quoted 61 lines · Daniel Mack
Make the driver control the device clocks. Appearantly, the Davinci platform probes this driver with the clock all powered up, but on OMAP, this isn't the case.
Signed-off-by Daniel Mack <[email protected]>--- drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/net/ethernet/ti/davinci_mdio.c +12
-2@@ -332,6 +332,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev) goto bail_out; } +clk_enable (data->clk); +dev_set_drvdata (dev, data); data->dev = dev;spin_lock_init (&data->lock);@@ -379,8 +381,11 @@ bail_out:if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -397,8 +402,11 @@ static int __devexit davinci_mdio_remove(struct platform_device *pdev)if (data->bus)mdiobus_free (data->bus); -if (data->clk) +if (data->clk) { +clk_disable (data->clk);clk_put (data->clk); + } +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);@@ -427,6 +435,8 @@ static int davinci_mdio_suspend(struct device *dev) data->suspended = true;spin_unlock (&data->lock); +clk_disable (data->clk); +return 0 ; }@@ -435,6 +445,8 @@ static int davinci_mdio_resume(struct device *dev)struct davinci_mdio_data *data =dev_get_drvdata (dev);u32 ctrl;Quoted 8 lines
drivers/net/ethernet/ti/davinci_mdio.c static int davinci_mdio_resume(struct device *dev) · line 449
Quoted 2 lines
drivers/net/ethernet/ti/davinci_mdio.c +2
-0+clk_enable (data->clk); +Danial,
I would request you to wait for this, its not that simple and straight. And once you migrate to runtime PM you don't need clk_enable/disable, this should get handled under runtime PM api's.
As I said, it can be dropped.
Quoted 4 lines
Also have you read my another email post -
Quoted 9 lines
Quoted 3 lines
Certainly, with respect to CPSW & MDIO, this patch is not enough and requires further investigation. I have started looking at this and hopefully will have some solution soon...
Ok, no problem. We certainly need the DT bindings for
davinci_mdio. With that applied, and the hwmod added (in the patch I posted yesterday), I can at least mount the rootfs via NFS, which is all I currently need.
I certainly understand your requirement here.
Actually this is not the only device we have, the same issue is applicable to PWM subsystem available in AM335x. Hopefully I should have something soon on this.
Thanks,
Vaibhav