diff mbox

[1/2] net: davinci_mdio: enable and disable clock

Message ID 1343936616-29318-1-git-send-email-zonque@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Mack Aug. 2, 2012, 7:43 p.m. UTC
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 <zonque@gmail.com>
---
 drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Russell King - ARM Linux Aug. 2, 2012, 7:53 p.m. UTC | #1
On Thu, Aug 02, 2012 at 09:43:35PM +0200, Daniel Mack wrote:
> 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.
Paul Walmsley Aug. 2, 2012, 8:20 p.m. UTC | #2
Hi

On Thu, 2 Aug 2012, Daniel Mack wrote:

> 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 <zonque@gmail.com>

> ---
>  drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
> index cd7ee20..b4b6015 100644
> --- a/drivers/net/ethernet/ti/davinci_mdio.c
> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
> @@ -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
Daniel Mack Aug. 2, 2012, 8:28 p.m. UTC | #3
On 02.08.2012 22:20, Paul Walmsley wrote:
> Hi
> 
> On Thu, 2 Aug 2012, Daniel Mack wrote:
> 
>> 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 <zonque@gmail.com>
> 
>> ---
>>  drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
>>  1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
>> index cd7ee20..b4b6015 100644
>> --- a/drivers/net/ethernet/ti/davinci_mdio.c
>> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
>> @@ -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.

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.

> 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
Vaibhav Hiremath Aug. 3, 2012, 5:16 a.m. UTC | #4
On 8/3/2012 1:13 AM, Daniel Mack wrote:
> 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 <zonque@gmail.com>
> ---
>  drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
> index cd7ee20..b4b6015 100644
> --- a/drivers/net/ethernet/ti/davinci_mdio.c
> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
> @@ -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);
> +

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
Daniel Mack Aug. 3, 2012, 5:22 a.m. UTC | #5
On 03.08.2012 07:16, Vaibhav Hiremath wrote:
> 
> 
> On 8/3/2012 1:13 AM, Daniel Mack wrote:
>> 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 <zonque@gmail.com>
>> ---
>>  drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
>>  1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
>> index cd7ee20..b4b6015 100644
>> --- a/drivers/net/ethernet/ti/davinci_mdio.c
>> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
>> @@ -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);
>> +
> 
> 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.

> 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
Vaibhav Hiremath Aug. 3, 2012, 5:53 a.m. UTC | #6
On Fri, Aug 03, 2012 at 10:52:40, Daniel Mack wrote:
> On 03.08.2012 07:16, Vaibhav Hiremath wrote:
> > 
> > 
> > On 8/3/2012 1:13 AM, Daniel Mack wrote:
> >> 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 <zonque@gmail.com>
> >> ---
> >>  drivers/net/ethernet/ti/davinci_mdio.c | 16 ++++++++++++++--
> >>  1 file changed, 14 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
> >> index cd7ee20..b4b6015 100644
> >> --- a/drivers/net/ethernet/ti/davinci_mdio.c
> >> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
> >> @@ -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);
> >> +
> > 
> > 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.
> 
> > 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.
> 
> 

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
diff mbox

Patch

diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index cd7ee20..b4b6015 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -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);