linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v2] usb: uhci: Add clk support to uhci-platform
@ 2018-01-12  5:54 Benjamin Herrenschmidt
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2018-01-12  5:54 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-usb, Greg KH

The Aspeed SoCs use uhci-platform. With the new dynamic clock
control framework, the corresponding IP block clock must be
properly enabled.

This is a simplified variant of what ehci-platform does, it
looks for *one* clock attached to the device, and if it's
there, enables it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

v2. Don't forget to git add latest changes :-) This adds the
    part where we turn the clock off when removing the driver.

 drivers/usb/host/uhci-hcd.h      |  3 +++
 drivers/usb/host/uhci-platform.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index f1cc47292a59..7f9f33c8c232 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -4,6 +4,7 @@
 
 #include <linux/list.h>
 #include <linux/usb.h>
+#include <linux/clk.h>
 
 #define usb_packetid(pipe)	(usb_pipein(pipe) ? USB_PID_IN : USB_PID_OUT)
 #define PIPE_DEVEP_MASK		0x0007ff00
@@ -447,6 +448,8 @@ struct uhci_hcd {
 	int total_load;				/* Sum of array values */
 	short load[MAX_PHASE];			/* Periodic allocations */
 
+	struct clk *clk;			/* (optional) clock source */
+
 	/* Reset host controller */
 	void	(*reset_hc) (struct uhci_hcd *uhci);
 	int	(*check_and_reset_hc) (struct uhci_hcd *uhci);
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index 6cb16d4b2257..3d7da7338391 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -119,6 +119,21 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
 				 "Enabled Aspeed implementation workarounds\n");
 		}
 	}
+
+	/* Get and enable clock if any specified */
+	uhci->clk = devm_clk_get(&pdev->dev, NULL);
+        if (IS_ERR(uhci->clk)) {
+                ret = PTR_ERR(uhci->clk);
+                goto err_rmr;
+        }
+	if (uhci->clk) {
+		ret = clk_prepare_enable(uhci->clk);
+		if (ret) {
+			dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret);
+			goto err_rmr;
+		}
+        }
+
 	ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
 	if (ret)
 		goto err_rmr;
@@ -135,7 +150,10 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
 static int uhci_hcd_platform_remove(struct platform_device *pdev)
 {
 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+	struct uhci_hcd *uhci = hcd_to_uhci(hcd);
 
+	if (uhci->clk)
+		clk_disable_unprepare(uhci->clk);
 	usb_remove_hcd(hcd);
 	usb_put_hcd(hcd);
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [v2] usb: uhci: Add clk support to uhci-platform
@ 2018-01-12 15:52 Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2018-01-12 15:52 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-usb, Greg KH

On Fri, 12 Jan 2018, Benjamin Herrenschmidt wrote:

> The Aspeed SoCs use uhci-platform. With the new dynamic clock
> control framework, the corresponding IP block clock must be
> properly enabled.
> 
> This is a simplified variant of what ehci-platform does, it
> looks for *one* clock attached to the device, and if it's
> there, enables it.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> 
> v2. Don't forget to git add latest changes :-) This adds the
>     part where we turn the clock off when removing the driver.
> 
>  drivers/usb/host/uhci-hcd.h      |  3 +++
>  drivers/usb/host/uhci-platform.c | 18 ++++++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
> index f1cc47292a59..7f9f33c8c232 100644
> --- a/drivers/usb/host/uhci-hcd.h
> +++ b/drivers/usb/host/uhci-hcd.h
> @@ -4,6 +4,7 @@
>  
>  #include <linux/list.h>
>  #include <linux/usb.h>
> +#include <linux/clk.h>
>  
>  #define usb_packetid(pipe)	(usb_pipein(pipe) ? USB_PID_IN : USB_PID_OUT)
>  #define PIPE_DEVEP_MASK		0x0007ff00
> @@ -447,6 +448,8 @@ struct uhci_hcd {
>  	int total_load;				/* Sum of array values */
>  	short load[MAX_PHASE];			/* Periodic allocations */
>  
> +	struct clk *clk;			/* (optional) clock source */
> +
>  	/* Reset host controller */
>  	void	(*reset_hc) (struct uhci_hcd *uhci);
>  	int	(*check_and_reset_hc) (struct uhci_hcd *uhci);
> diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
> index 6cb16d4b2257..3d7da7338391 100644
> --- a/drivers/usb/host/uhci-platform.c
> +++ b/drivers/usb/host/uhci-platform.c
> @@ -119,6 +119,21 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
>  				 "Enabled Aspeed implementation workarounds\n");
>  		}
>  	}
> +
> +	/* Get and enable clock if any specified */
> +	uhci->clk = devm_clk_get(&pdev->dev, NULL);
> +        if (IS_ERR(uhci->clk)) {
> +                ret = PTR_ERR(uhci->clk);
> +                goto err_rmr;
> +        }

As Sergei mentioned, please be consistent in the use of tabs vs. 
spaces.

Do you have to worry about EPROBE_DEFER errors at any point?

> +	if (uhci->clk) {
> +		ret = clk_prepare_enable(uhci->clk);
> +		if (ret) {
> +			dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret);
> +			goto err_rmr;
> +		}
> +        }
> +
>  	ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
>  	if (ret)
>  		goto err_rmr;

This error path needs to call clk_disable_unprepare.

> @@ -135,7 +150,10 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
>  static int uhci_hcd_platform_remove(struct platform_device *pdev)
>  {
>  	struct usb_hcd *hcd = platform_get_drvdata(pdev);
> +	struct uhci_hcd *uhci = hcd_to_uhci(hcd);
>  
> +	if (uhci->clk)
> +		clk_disable_unprepare(uhci->clk);
>  	usb_remove_hcd(hcd);
>  	usb_put_hcd(hcd);

Alan Stern
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [v2] usb: uhci: Add clk support to uhci-platform
@ 2018-01-12 22:28 Benjamin Herrenschmidt
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2018-01-12 22:28 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-usb, Greg KH

On Fri, 2018-01-12 at 10:52 -0500, Alan Stern wrote:
> 
> As Sergei mentioned, please be consistent in the use of tabs vs. 
> spaces.
> 
> Do you have to worry about EPROBE_DEFER errors at any point?

I don't think so, not on the SoC I'm using but it might be worthwhile
adding support for it just in case...
> 
> > +     if (uhci->clk) {
> > +             ret = clk_prepare_enable(uhci->clk);
> > +             if (ret) {
> > +                     dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret);
> > +                     goto err_rmr;
> > +             }
> > +        }
> > +
> >        ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
> >        if (ret)
> >                goto err_rmr;
> 
> This error path needs to call clk_disable_unprepare.

Yeah ok.

> > @@ -135,7 +150,10 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
> >   static int uhci_hcd_platform_remove(struct platform_device *pdev)
> >   {
> >        struct usb_hcd *hcd = platform_get_drvdata(pdev);
> > +     struct uhci_hcd *uhci = hcd_to_uhci(hcd);
> >   
> > +     if (uhci->clk)
> > +             clk_disable_unprepare(uhci->clk);
> >        usb_remove_hcd(hcd);
> >        usb_put_hcd(hcd);
> 
> Alan Stern
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [v2] usb: uhci: Add clk support to uhci-platform
@ 2018-01-12 22:34 Benjamin Herrenschmidt
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2018-01-12 22:34 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-usb, Greg KH

On Sat, 2018-01-13 at 09:28 +1100, Benjamin Herrenschmidt wrote:
> On Fri, 2018-01-12 at 10:52 -0500, Alan Stern wrote:
> > 
> > As Sergei mentioned, please be consistent in the use of tabs vs. 
> > spaces.
> > 
> > Do you have to worry about EPROBE_DEFER errors at any point?
> 
> I don't think so, not on the SoC I'm using but it might be worthwhile
> adding support for it just in case...

Actually, thinking more about it, what support ? If we hit it, we
return that error, isn't it all that is needed ?

Cheers,
Ben.
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [v2] usb: uhci: Add clk support to uhci-platform
@ 2018-01-13  3:21 Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2018-01-13  3:21 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-usb, Greg KH

On Sat, 13 Jan 2018, Benjamin Herrenschmidt wrote:

> On Sat, 2018-01-13 at 09:28 +1100, Benjamin Herrenschmidt wrote:
> > On Fri, 2018-01-12 at 10:52 -0500, Alan Stern wrote:
> > > 
> > > As Sergei mentioned, please be consistent in the use of tabs vs. 
> > > spaces.
> > > 
> > > Do you have to worry about EPROBE_DEFER errors at any point?
> > 
> > I don't think so, not on the SoC I'm using but it might be worthwhile
> > adding support for it just in case...
> 
> Actually, thinking more about it, what support ? If we hit it, we
> return that error, isn't it all that is needed ?

Come to think about it, the only support people seem to use is
suppressing an error message when the error is -EPROBE_DEFER.  Since
your code doesn't have any error messages anyway, I guess you don't
need to do anything.

Alan Stern
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-13  3:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-12  5:54 [v2] usb: uhci: Add clk support to uhci-platform Benjamin Herrenschmidt
  -- strict thread matches above, loose matches on Subject: below --
2018-01-12 15:52 Alan Stern
2018-01-12 22:28 Benjamin Herrenschmidt
2018-01-12 22:34 Benjamin Herrenschmidt
2018-01-13  3:21 Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).