Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1364498 > unrolled thread

[PATCH v3 00/16] da8xx USB clocks

Started byDavid Lechner <david@lechnology.com>
First post2016-03-25 01:00 +0100
Last post2016-03-25 01:00 +0100
Articles 10 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3 00/16] da8xx USB clocks David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100
    [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100
      Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe Bin Liu <b-liu@ti.com> - 2016-04-01 00:30 +0200
        Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe David Lechner <david@lechnology.com> - 2016-04-01 00:30 +0200
          Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe Bin Liu <b-liu@ti.com> - 2016-04-01 17:00 +0200
        Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-04-01 12:40 +0200
    [PATCH v3 11/16] ARM: davinci: da8xx: Add USB PHY platform declaration David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100
    [PATCH v3 12/16] ARM: dt: da850: Add cfgchip syscon node David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100
    [PATCH v3 07/16] ARM: davinci: da8xx: add usb phy clocks David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100
    [PATCH v3 13/16] ARM: dt: da850: Add usb phy node David Lechner <david@lechnology.com> - 2016-03-25 01:00 +0100

#1364498 — [PATCH v3 00/16] da8xx USB clocks

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 00/16] da8xx USB clocks
Message-ID<rgnku-1AF-3@gated-at.bofh.it>
This is a reworking of the v2 series based of feedback and review. There were
very many suggestions, so hopefully I didn't miss any. Here are the highlights...

New stuff:

* Fixed the davinci device tree declarations to use the preferred DT address
  convention so that the items I have added can be correct too.
* Moved that davinci clock init so that we don't have to call ioremap in the
  clock mux functions.
* Added a new "syscon" device for the CFGCHIP registers. This is used by the
  USB PHY driver and will be used in the future in common clock framework
  drivers.

Changed:

* USB clocks are moved to a common file instead of having duplicated code.
* PHY driver uses syscon for CFGCHIP registers instead of using them directly.

David Lechner (16):
  dt: davinci: use proper address after @
  mfd: da8xx-cfgchip: New header file for CFGCHIP registers.
  ARM: davinici: da8xx: move usb code to new file
  ARM: davinci: Move clock init after ioremap.
  ARM: davinci: add set_parent callback for mux clocks
  ARM: davinci: da850: use clk->set_parent for async3
  ARM: davinci: da8xx: add usb phy clocks
  dt-bindings: Add bindings for phy-da8xx-usb
  phy: da8xx-usb: new driver for DA8xx SoC USB PHY
  ARM: davinci: da8xx: Add CFGCHIPn syscon platform declaration.
  ARM: davinci: da8xx: Add USB PHY platform declaration
  ARM: dt: da850: Add cfgchip syscon node
  ARM: dt: da850: Add usb phy node
  usb: ohci-da8xx: Remove code that references mach
  usb: musb: da8xx: Use devm in probe
  usb: musb: da8xx: Remove mach code

 .../devicetree/bindings/phy/phy-da8xx-usb.txt      |  40 +++
 arch/arm/boot/dts/da850-enbw-cmc.dts               |   8 +-
 arch/arm/boot/dts/da850-evm.dts                    |  26 +-
 arch/arm/boot/dts/da850.dtsi                       |  61 ++--
 arch/arm/mach-davinci/Makefile                     |   4 +-
 arch/arm/mach-davinci/board-da830-evm.c            |  52 ++-
 arch/arm/mach-davinci/board-da850-evm.c            |   4 +
 arch/arm/mach-davinci/board-mityomapl138.c         |   4 +
 arch/arm/mach-davinci/board-omapl138-hawk.c        |  23 +-
 arch/arm/mach-davinci/clock.c                      |  21 +-
 arch/arm/mach-davinci/clock.h                      |   8 +-
 arch/arm/mach-davinci/common.c                     |   6 -
 arch/arm/mach-davinci/da830.c                      |   2 +
 arch/arm/mach-davinci/da850.c                      |  84 +++--
 arch/arm/mach-davinci/devices-da8xx.c              |  28 ++
 arch/arm/mach-davinci/dm355.c                      |   1 +
 arch/arm/mach-davinci/dm365.c                      |   1 +
 arch/arm/mach-davinci/dm644x.c                     |   1 +
 arch/arm/mach-davinci/dm646x.c                     |   1 +
 arch/arm/mach-davinci/include/mach/da8xx.h         |   6 +
 arch/arm/mach-davinci/usb-da8xx.c                  | 351 +++++++++++++++++++++
 arch/arm/mach-davinci/usb.c                        |  74 +----
 drivers/phy/Kconfig                                |  10 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-da8xx-usb.c                        | 249 +++++++++++++++
 drivers/usb/host/Kconfig                           |   1 +
 drivers/usb/host/ohci-da8xx.c                      | 102 +++---
 drivers/usb/musb/Kconfig                           |   2 +-
 drivers/usb/musb/da8xx.c                           | 160 +++-------
 include/linux/mfd/da8xx-cfgchip.h                  | 160 ++++++++++
 include/linux/phy/phy-da8xx-usb.h                  |  19 ++
 include/linux/platform_data/usb-davinci.h          |  23 --
 32 files changed, 1137 insertions(+), 396 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
 create mode 100644 arch/arm/mach-davinci/usb-da8xx.c
 create mode 100644 drivers/phy/phy-da8xx-usb.c
 create mode 100644 include/linux/mfd/da8xx-cfgchip.h
 create mode 100644 include/linux/phy/phy-da8xx-usb.h

-- 
1.9.1

[toc] | [next] | [standalone]


#1364499 — [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 15/16] usb: musb: da8xx: Use devm in probe
Message-ID<rgnkv-1AF-33@gated-at.bofh.it>
In reply to#1364498
Simplify things a bit by using devm functions where possible.

Signed-off-by: David Lechner <david@lechnology.com>
---

v3 changes:

* Kept clk variable to minimize noise.


 drivers/usb/musb/da8xx.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index b03d3b8..0c1997c 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -490,20 +490,18 @@ static int da8xx_probe(struct platform_device *pdev)
 	struct da8xx_glue		*glue;
 	struct platform_device_info	pinfo;
 	struct clk			*clk;
+	int				ret;
 
-	int				ret = -ENOMEM;
-
-	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
 	if (!glue) {
 		dev_err(&pdev->dev, "failed to allocate glue context\n");
-		goto err0;
+		return -ENOMEM;
 	}
 
-	clk = clk_get(&pdev->dev, "usb20");
+	clk = devm_clk_get(&pdev->dev, "usb20");
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
-		ret = PTR_ERR(clk);
-		goto err3;
+		return PTR_ERR(clk);
 	}
 
 	ret = clk_enable(clk);
@@ -560,12 +558,7 @@ err5:
 	clk_disable(clk);
 
 err4:
-	clk_put(clk);
-
-err3:
-	kfree(glue);
 
-err0:
 	return ret;
 }
 
@@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
 	platform_device_unregister(glue->musb);
 	usb_phy_generic_unregister(glue->phy);
 	clk_disable(glue->clk);
-	clk_put(glue->clk);
-	kfree(glue);
 
 	return 0;
 }
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1368860 — Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe

FromBin Liu <b-liu@ti.com>
Date2016-04-01 00:30 +0200
SubjectRe: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe
Message-ID<riTgd-3dz-1@gated-at.bofh.it>
In reply to#1364499
Hi,

On Thu, Mar 24, 2016 at 06:51:40PM -0500, David Lechner wrote:
> Simplify things a bit by using devm functions where possible.
> 
> Signed-off-by: David Lechner <david@lechnology.com>
> ---
> 
> v3 changes:
> 
> * Kept clk variable to minimize noise.
> 
> 
>  drivers/usb/musb/da8xx.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
> index b03d3b8..0c1997c 100644
> --- a/drivers/usb/musb/da8xx.c
> +++ b/drivers/usb/musb/da8xx.c
> @@ -490,20 +490,18 @@ static int da8xx_probe(struct platform_device *pdev)
>  	struct da8xx_glue		*glue;
>  	struct platform_device_info	pinfo;
>  	struct clk			*clk;
> +	int				ret;
>  
> -	int				ret = -ENOMEM;
> -
> -	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
> +	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
>  	if (!glue) {
>  		dev_err(&pdev->dev, "failed to allocate glue context\n");
> -		goto err0;
> +		return -ENOMEM;
>  	}
>  
> -	clk = clk_get(&pdev->dev, "usb20");
> +	clk = devm_clk_get(&pdev->dev, "usb20");
>  	if (IS_ERR(clk)) {
>  		dev_err(&pdev->dev, "failed to get clock\n");
> -		ret = PTR_ERR(clk);
> -		goto err3;
> +		return PTR_ERR(clk);

memory leak due to not kfree(glue).

>  	}
>  
>  	ret = clk_enable(clk);
> @@ -560,12 +558,7 @@ err5:
>  	clk_disable(clk);
>  
>  err4:
> -	clk_put(clk);
> -
> -err3:
> -	kfree(glue);
>  
> -err0:
>  	return ret;
>  }
>  
> @@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
>  	platform_device_unregister(glue->musb);
>  	usb_phy_generic_unregister(glue->phy);
>  	clk_disable(glue->clk);
> -	clk_put(glue->clk);
> -	kfree(glue);

Doesn't match with $subject, I'd put them into a seperate patch.

Regards,
-Bin.

[toc] | [prev] | [next] | [standalone]


#1368863 — Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe

FromDavid Lechner <david@lechnology.com>
Date2016-04-01 00:30 +0200
SubjectRe: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe
Message-ID<riTgd-3dz-5@gated-at.bofh.it>
In reply to#1368860
On 03/31/2016 05:21 PM, Bin Liu wrote:

>> -	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
>> +	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
>>   	if (!glue) {
>>   		dev_err(&pdev->dev, "failed to allocate glue context\n");
>> -		goto err0;
>> +		return -ENOMEM;
>>   	}
>>
>> -	clk = clk_get(&pdev->dev, "usb20");
>> +	clk = devm_clk_get(&pdev->dev, "usb20");
>>   	if (IS_ERR(clk)) {
>>   		dev_err(&pdev->dev, "failed to get clock\n");
>> -		ret = PTR_ERR(clk);
>> -		goto err3;
>> +		return PTR_ERR(clk);
>
> memory leak due to not kfree(glue).

It is my understanding that since glue is allocated with devm_kzalloc(), 
that if the probe function returns and error, glue and everything else 
allocated with devm_* will be automatically freed.

If this is not the case, wouldn't devm_kfree() be the appropriate 
function instead?


>> @@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
>>   	platform_device_unregister(glue->musb);
>>   	usb_phy_generic_unregister(glue->phy);
>>   	clk_disable(glue->clk);
>> -	clk_put(glue->clk);
>> -	kfree(glue);
>
> Doesn't match with $subject, I'd put them into a seperate patch.


I disagree. Since these are now automatically freed because of changes 
in the probe function, these changes belong in the same patch.

[toc] | [prev] | [next] | [standalone]


#1369402 — Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe

FromBin Liu <b-liu@ti.com>
Date2016-04-01 17:00 +0200
SubjectRe: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe
Message-ID<rj8Ii-5RJ-13@gated-at.bofh.it>
In reply to#1368863
Hi,

On Thu, Mar 31, 2016 at 05:28:48PM -0500, David Lechner wrote:
> On 03/31/2016 05:21 PM, Bin Liu wrote:
> 
> >>-	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
> >>+	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
> >>  	if (!glue) {
> >>  		dev_err(&pdev->dev, "failed to allocate glue context\n");
> >>-		goto err0;
> >>+		return -ENOMEM;
> >>  	}
> >>
> >>-	clk = clk_get(&pdev->dev, "usb20");
> >>+	clk = devm_clk_get(&pdev->dev, "usb20");
> >>  	if (IS_ERR(clk)) {
> >>  		dev_err(&pdev->dev, "failed to get clock\n");
> >>-		ret = PTR_ERR(clk);
> >>-		goto err3;
> >>+		return PTR_ERR(clk);
> >
> >memory leak due to not kfree(glue).
> 
> It is my understanding that since glue is allocated with
> devm_kzalloc(), that if the probe function returns and error, glue
> and everything else allocated with devm_* will be automatically
> freed.

Ah, right.

> 
> If this is not the case, wouldn't devm_kfree() be the appropriate
> function instead?
> 
> 
> >>@@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
> >>  	platform_device_unregister(glue->musb);
> >>  	usb_phy_generic_unregister(glue->phy);
> >>  	clk_disable(glue->clk);
> >>-	clk_put(glue->clk);
> >>-	kfree(glue);
> >
> >Doesn't match with $subject, I'd put them into a seperate patch.
> 
> 
> I disagree. Since these are now automatically freed because of
> changes in the probe function, these changes belong in the same
> patch.
> 
Ok.

Signed-off-by: Bin Liu <b-liu@ti.com>

Regards,
-Bin.

[toc] | [prev] | [next] | [standalone]


#1369171 — Re: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe

FromSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Date2016-04-01 12:40 +0200
SubjectRe: [PATCH v3 15/16] usb: musb: da8xx: Use devm in probe
Message-ID<rj4EG-2X4-3@gated-at.bofh.it>
In reply to#1368860
Hello.

On 4/1/2016 1:21 AM, Bin Liu wrote:

>> Simplify things a bit by using devm functions where possible.
>>
>> Signed-off-by: David Lechner <david@lechnology.com>
>> ---
>>
>> v3 changes:
>>
>> * Kept clk variable to minimize noise.
>>
>>
>>   drivers/usb/musb/da8xx.c | 19 +++++--------------
>>   1 file changed, 5 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
>> index b03d3b8..0c1997c 100644
>> --- a/drivers/usb/musb/da8xx.c
>> +++ b/drivers/usb/musb/da8xx.c
>> @@ -490,20 +490,18 @@ static int da8xx_probe(struct platform_device *pdev)
>>   	struct da8xx_glue		*glue;
>>   	struct platform_device_info	pinfo;
>>   	struct clk			*clk;
>> +	int				ret;
>>
>> -	int				ret = -ENOMEM;
>> -
>> -	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
>> +	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
>>   	if (!glue) {
>>   		dev_err(&pdev->dev, "failed to allocate glue context\n");
>> -		goto err0;
>> +		return -ENOMEM;
>>   	}
>>
>> -	clk = clk_get(&pdev->dev, "usb20");
>> +	clk = devm_clk_get(&pdev->dev, "usb20");
>>   	if (IS_ERR(clk)) {
>>   		dev_err(&pdev->dev, "failed to get clock\n");
>> -		ret = PTR_ERR(clk);
>> -		goto err3;
>> +		return PTR_ERR(clk);
>
> memory leak due to not kfree(glue).

    No, since devm_kzalloc() was used, the memory will be automatically freed 
on returning error by da8xx_probe().

>>   	}
>>
>>   	ret = clk_enable(clk);
>> @@ -560,12 +558,7 @@ err5:
>>   	clk_disable(clk);
>>
>>   err4:
>> -	clk_put(clk);
>> -
>> -err3:
>> -	kfree(glue);
>>
>> -err0:
>>   	return ret;
>>   }
>>
>> @@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
>>   	platform_device_unregister(glue->musb);
>>   	usb_phy_generic_unregister(glue->phy);
>>   	clk_disable(glue->clk);
>> -	clk_put(glue->clk);
>> -	kfree(glue);
>
> Doesn't match with $subject, I'd put them into a seperate patch.

    Again, these are now done automatically.

> Regards,
> -Bin.

MBR, Sergei

[toc] | [prev] | [next] | [standalone]


#1364500 — [PATCH v3 11/16] ARM: davinci: da8xx: Add USB PHY platform declaration

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 11/16] ARM: davinci: da8xx: Add USB PHY platform declaration
Message-ID<rgnkv-1AF-41@gated-at.bofh.it>
In reply to#1364498
There is now a proper phy driver for the DA8xx SoC USB PHY. This adds the
platform device declarations needed to use it.

Signed-off-by: David Lechner <david@lechnology.com>
---

v3 changes:

* The declaration is now in the new usb-da8xx.c file.

 arch/arm/mach-davinci/board-da830-evm.c     | 28 +++++-----------------------
 arch/arm/mach-davinci/board-omapl138-hawk.c |  5 +++++
 arch/arm/mach-davinci/include/mach/da8xx.h  |  1 +
 arch/arm/mach-davinci/usb-da8xx.c           | 11 +++++++++++
 4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c b/arch/arm/mach-davinci/board-da830-evm.c
index 3051cb6..6421cfe 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -26,7 +26,6 @@
 #include <linux/platform_data/mtd-davinci.h>
 #include <linux/platform_data/mtd-davinci-aemif.h>
 #include <linux/platform_data/spi-davinci.h>
-#include <linux/platform_data/usb-davinci.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -106,30 +105,8 @@ static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id)
 
 static __init void da830_evm_usb_init(void)
 {
-	u32 cfgchip2;
 	int ret;
 
-	/*
-	 * Set up USB clock/mode in the CFGCHIP2 register.
-	 * FYI:  CFGCHIP2 is 0x0000ef00 initially.
-	 */
-	cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
-	/*
-	 * We have to override VBUS/ID signals when MUSB is configured into the
-	 * host-only mode -- ID pin will float if no cable is connected, so the
-	 * controller won't be able to drive VBUS thinking that it's a B-device.
-	 * Otherwise, we want to use the OTG mode and enable VBUS comparators.
-	 */
-	cfgchip2 &= ~CFGCHIP2_OTGMODE;
-#ifdef	CONFIG_USB_MUSB_HOST
-	cfgchip2 |=  CFGCHIP2_FORCE_HOST;
-#else
-	cfgchip2 |=  CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
-#endif
-
-	__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
 	/* USB_REFCLKIN is not used. */
 	ret = da8xx_register_usb20_phy_clk(false);
 	if (ret)
@@ -141,6 +118,11 @@ static __init void da830_evm_usb_init(void)
 		pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
 			__func__, ret);
 
+	ret = da8xx_register_usbphy();
+	if (ret)
+		pr_warn("%s: USB PHY registration failed: %d\n",
+			__func__, ret);
+
 	ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
 	if (ret)
 		pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c b/arch/arm/mach-davinci/board-omapl138-hawk.c
index 8691a25..79aaa84 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -260,6 +260,11 @@ static __init void omapl138_hawk_usb_init(void)
 		pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
 			__func__, ret);
 
+	ret = da8xx_register_usbphy();
+	if (ret)
+		pr_warn("%s: USB PHY registration failed: %d\n",
+			__func__, ret);
+
 	ret = gpio_request_one(DA850_USB1_VBUS_PIN,
 			GPIOF_DIR_OUT, "USB1 VBUS");
 	if (ret < 0) {
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h b/arch/arm/mach-davinci/include/mach/da8xx.h
index c32444b..44ab55e 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -92,6 +92,7 @@ int da8xx_register_watchdog(void);
 int da8xx_register_usb_refclkin(int rate);
 int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usbphy(void);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c b/arch/arm/mach-davinci/usb-da8xx.c
index aca5867..6bd0009 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -6,6 +6,7 @@
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/mfd/da8xx-cfgchip.h>
+#include <linux/phy/phy.h>
 #include <linux/usb/musb.h>
 
 #include <asm/delay.h>
@@ -231,6 +232,16 @@ int __init da8xx_register_usb11_phy_clk(bool use_usb_refclkin)
 	return ret;
 }
 
+static struct platform_device da8xx_usbphy = {
+	.name		= "da8xx-usbphy",
+	.id		= 0,
+};
+
+int __init da8xx_register_usbphy(void)
+{
+	return platform_device_register(&da8xx_usbphy);
+}
+
 #if IS_ENABLED(CONFIG_USB_MUSB_HDRC)
 
 static struct musb_hdrc_eps_bits musb_eps[] = {
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1364501 — [PATCH v3 12/16] ARM: dt: da850: Add cfgchip syscon node

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 12/16] ARM: dt: da850: Add cfgchip syscon node
Message-ID<rgnkv-1AF-29@gated-at.bofh.it>
In reply to#1364498
Add a syscon node for the SoC CFGCHIPn registers. This is needed for
the new usb phy driver.

Signed-off-by: David Lechner <david@lechnology.com>
---

v3 changes: This is a new patch.


 arch/arm/boot/dts/da850.dtsi | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 4294849..a360713 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -150,6 +150,10 @@
 			};
 
 		};
+		cfgchip: cfgchip@1417c {
+			compatible = "ti,da830-cfgchip", "syscon";
+			reg = <0x1417c 0x14>;
+		};
 		edma0: edma@0 {
 			compatible = "ti,edma3-tpcc";
 			/* eDMA3 CC0: 0x01c0 0000 - 0x01c0 7fff */
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1364502 — [PATCH v3 07/16] ARM: davinci: da8xx: add usb phy clocks

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 07/16] ARM: davinci: da8xx: add usb phy clocks
Message-ID<rgnkv-1AF-43@gated-at.bofh.it>
In reply to#1364498
Up to this point, the USB phy clock configuration was handled manually in
the board files and in the usb drivers. This adds proper clocks so that
the usb drivers can use clk_get and clk_enable and not have to worry about
the details. Also, the related code is removed from the board files and
replaced with the new clock registration functions.

Signed-off-by: David Lechner <david@lechnology.com>
---

v3 changes:

* Clocks are now in usb-da8xx.c instead of having duplicated code in da830.c
  and da850.c.
* No longer calling ioremap in set_parent() functions.
* Added timeout while waiting for PLL to lock.
* Renamed USB reference clock to usb_refclkin.
* Clocks are now dynamically registered.
* usb_refclkin rate is specified when registered, so it no longer has a default
  value of 48MHz. It does not have to be registered if it is not used.
* Parent clock for clock muxes are set when clock is registered.
* Board files that use da8xx usb are updated to call the new register functions.


 arch/arm/mach-davinci/board-da830-evm.c     |  22 ++-
 arch/arm/mach-davinci/board-omapl138-hawk.c |  16 +-
 arch/arm/mach-davinci/include/mach/da8xx.h  |   3 +
 arch/arm/mach-davinci/usb-da8xx.c           | 218 +++++++++++++++++++++++++++-
 4 files changed, 239 insertions(+), 20 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c b/arch/arm/mach-davinci/board-da830-evm.c
index 3d8cf8c..605d444 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -115,18 +115,6 @@ static __init void da830_evm_usb_init(void)
 	 */
 	cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
 
-	/* USB2.0 PHY reference clock is 24 MHz */
-	cfgchip2 &= ~CFGCHIP2_REFFREQ;
-	cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
-
-	/*
-	 * Select internal reference clock for USB 2.0 PHY
-	 * and use it as a clock source for USB 1.1 PHY
-	 * (this is the default setting anyway).
-	 */
-	cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;
-	cfgchip2 |=  CFGCHIP2_USB2PHYCLKMUX;
-
 	/*
 	 * We have to override VBUS/ID signals when MUSB is configured into the
 	 * host-only mode -- ID pin will float if no cable is connected, so the
@@ -143,6 +131,16 @@ static __init void da830_evm_usb_init(void)
 	__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
 
 	/* USB_REFCLKIN is not used. */
+	ret = da8xx_register_usb20_phy_clk(false);
+	if (ret)
+		pr_warn("%s: USB 2.0 PHY CLK registration failed: %d\n",
+			__func__, ret);
+
+	ret = da8xx_register_usb11_phy_clk(false);
+	if (ret)
+		pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
+			__func__, ret);
+
 	ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
 	if (ret)
 		pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c b/arch/arm/mach-davinci/board-omapl138-hawk.c
index ee62486..d4930b6 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -243,7 +243,6 @@ static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
 static __init void omapl138_hawk_usb_init(void)
 {
 	int ret;
-	u32 cfgchip2;
 
 	ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
 	if (ret) {
@@ -251,12 +250,15 @@ static __init void omapl138_hawk_usb_init(void)
 		return;
 	}
 
-	/* Setup the Ref. clock frequency for the HAWK at 24 MHz. */
-
-	cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-	cfgchip2 &= ~CFGCHIP2_REFFREQ;
-	cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
-	__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+	/* USB_REFCLKIN is not used. */
+	ret = da8xx_register_usb20_phy_clk(false);
+	if (ret)
+		pr_warn("%s: USB 2.0 PHY CLK registration failed: %d\n",
+			__func__, ret);
+	ret = da8xx_register_usb11_phy_clk(false);
+	if (ret)
+		pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
+			__func__, ret);
 
 	ret = gpio_request_one(DA850_USB1_VBUS_PIN,
 			GPIOF_DIR_OUT, "USB1 VBUS");
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h b/arch/arm/mach-davinci/include/mach/da8xx.h
index f9f9713..c367530 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -88,6 +88,9 @@ int da850_register_edma(struct edma_rsv_info *rsv[2]);
 int da8xx_register_i2c(int instance, struct davinci_i2c_platform_data *pdata);
 int da8xx_register_spi_bus(int instance, unsigned num_chipselect);
 int da8xx_register_watchdog(void);
+int da8xx_register_usb_refclkin(int rate);
+int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c b/arch/arm/mach-davinci/usb-da8xx.c
index 728a11f..aca5867 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -1,20 +1,236 @@
 /*
  * DA8xx USB
  */
+#include <linux/clk.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/mfd/da8xx-cfgchip.h>
 #include <linux/usb/musb.h>
 
+#include <asm/delay.h>
+#include <mach/clock.h>
 #include <mach/common.h>
 #include <mach/irqs.h>
 #include <mach/cputype.h>
 #include <mach/da8xx.h>
-#include <linux/platform_data/usb-davinci.h>
+
+#include "clock.h"
 
 #define DA8XX_USB0_BASE 	0x01e00000
 #define DA8XX_USB1_BASE 	0x01e25000
 
+static struct clk usb_refclkin = {
+	.name		= "usb_refclkin",
+	.set_rate	= davinci_simple_set_rate,
+};
+
+static struct clk_lookup usb_refclkin_lookup =
+	CLK(NULL, "usb_refclkin", &usb_refclkin);
+
+/**
+ * da8xx_register_usb_refclkin - register USB_REFCLKIN clock
+ *
+ * @rate: The clock rate in Hz
+ *
+ * This clock is only needed if the board provides an external USB_REFCLKIN
+ * signal, in which case it will be used as the parent of usb20_phy_clk and/or
+ * usb11_phy_clk.
+ */
+int __init da8xx_register_usb_refclkin(int rate)
+{
+	int ret;
+
+	usb_refclkin.rate = rate;
+	ret = clk_register(&usb_refclkin);
+	if (ret)
+		return ret;
+
+	clkdev_add(&usb_refclkin_lookup);
+
+	return 0;
+}
+
+static void usb20_phy_clk_enable(struct clk *clk)
+{
+	u32 val;
+	u32 timeout = 500000; /* 500 msec */
+
+	val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	/*
+	 * Turn on the USB 2.0 PHY, but just the PLL, and not OTG. The USB 1.1
+	 * host may use the PLL clock without USB 2.0 OTG being used.
+	 */
+	val &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN);
+	val |= CFGCHIP2_PHY_PLLON;
+
+	writel(val, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	while (--timeout) {
+		val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+		if (val & CFGCHIP2_PHYCLKGD)
+			return;
+		udelay(1);
+	}
+
+	pr_err("Timeout waiting for USB 2.0 PHY clock good.\n");
+}
+
+static void usb20_phy_clk_disable(struct clk *clk)
+{
+	u32 val;
+
+	val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+	val |= CFGCHIP2_PHYPWRDN;
+	writel(val, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+}
+
+static int usb20_phy_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+	u32 val;
+
+	val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	/* Set the mux depending on the parent clock. */
+	if (parent == &usb_refclkin)
+		val &= ~CFGCHIP2_USB2PHYCLKMUX;
+	else if (strcmp(parent->name, "pll0_aux_clk") == 0)
+		val |= CFGCHIP2_USB2PHYCLKMUX;
+	else {
+		pr_err("Bad parent on USB 2.0 PHY clock.\n");
+		return -EINVAL;
+	}
+
+	/* reference frequency also comes from parent clock */
+	val &= ~CFGCHIP2_REFFREQ_MASK;
+	switch (clk_get_rate(parent)) {
+	case 12000000:
+		val |= CFGCHIP2_REFFREQ_12MHZ;
+		break;
+	case 13000000:
+		val |= CFGCHIP2_REFFREQ_13MHZ;
+		break;
+	case 19200000:
+		val |= CFGCHIP2_REFFREQ_19_2MHZ;
+		break;
+	case 20000000:
+		val |= CFGCHIP2_REFFREQ_20MHZ;
+		break;
+	case 24000000:
+		val |= CFGCHIP2_REFFREQ_24MHZ;
+		break;
+	case 26000000:
+		val |= CFGCHIP2_REFFREQ_26MHZ;
+		break;
+	case 38400000:
+		val |= CFGCHIP2_REFFREQ_38_4MHZ;
+		break;
+	case 40000000:
+		val |= CFGCHIP2_REFFREQ_40MHZ;
+		break;
+	case 48000000:
+		val |= CFGCHIP2_REFFREQ_48MHZ;
+		break;
+	default:
+		pr_err("Bad parent clock rate on USB 2.0 PHY clock.\n");
+		return -EINVAL;
+	}
+
+	writel(val, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	return 0;
+}
+
+static struct clk usb20_phy_clk = {
+	.name		= "usb20_phy",
+	.clk_enable	= usb20_phy_clk_enable,
+	.clk_disable	= usb20_phy_clk_disable,
+	.set_parent	= usb20_phy_clk_set_parent,
+};
+
+static struct clk_lookup usb20_phy_clk_lookup =
+	CLK(NULL, "usb20_phy", &usb20_phy_clk);
+
+/**
+ * da8xx_register_usb20_phy_clk - register USB0PHYCLKMUX clock
+ *
+ * @use_usb_refclkin: Selects the parent clock - either "usb_refclkin" if true
+ *	or "pll0_aux" if false.
+ */
+int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)
+{
+	struct clk *parent;
+	int ret = 0;
+
+	parent = clk_get(NULL, use_usb_refclkin ? "usb_refclkin" : "pll0_aux");
+	if (IS_ERR(parent))
+		return PTR_ERR(parent);
+
+	usb20_phy_clk.parent = parent;
+	ret = clk_register(&usb20_phy_clk);
+	if (!ret)
+		clkdev_add(&usb20_phy_clk_lookup);
+
+	clk_put(parent);
+
+	return ret;
+}
+
+static int usb11_phy_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+	u32 val;
+
+	val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	/* Set the USB 1.1 PHY clock mux based on the parent clock. */
+	if (parent == &usb20_phy_clk)
+		val &= ~CFGCHIP2_USB1PHYCLKMUX;
+	else if (parent == &usb_refclkin)
+		val |= CFGCHIP2_USB1PHYCLKMUX;
+	else {
+		pr_err("Bad parent on USB 1.1 PHY clock.\n");
+		return -EINVAL;
+	}
+
+	writel(val, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	return 0;
+}
+
+static struct clk usb11_phy_clk = {
+	.name		= "usb11_phy",
+	.set_parent	= usb11_phy_clk_set_parent,
+};
+
+static struct clk_lookup usb11_phy_clk_lookup =
+	CLK(NULL, "usb11_phy", &usb11_phy_clk);
+
+/**
+ * da8xx_register_usb11_phy_clk - register USB1PHYCLKMUX clock
+ *
+ * @use_usb_refclkin: Selects the parent clock - either "usb_refclkin" if true
+ *	or "usb20_phy" if false.
+ */
+int __init da8xx_register_usb11_phy_clk(bool use_usb_refclkin)
+{
+	struct clk *parent;
+	int ret = 0;
+
+	parent = clk_get(NULL, use_usb_refclkin ? "usb_refclkin" : "usb20_phy");
+	if (IS_ERR(parent))
+		return PTR_ERR(parent);
+
+	usb11_phy_clk.parent = parent;
+	ret = clk_register(&usb11_phy_clk);
+	if (!ret)
+		clkdev_add(&usb11_phy_clk_lookup);
+
+	clk_put(parent);
+
+	return ret;
+}
+
 #if IS_ENABLED(CONFIG_USB_MUSB_HDRC)
 
 static struct musb_hdrc_eps_bits musb_eps[] = {
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1364503 — [PATCH v3 13/16] ARM: dt: da850: Add usb phy node

FromDavid Lechner <david@lechnology.com>
Date2016-03-25 01:00 +0100
Subject[PATCH v3 13/16] ARM: dt: da850: Add usb phy node
Message-ID<rgnkv-1AF-35@gated-at.bofh.it>
In reply to#1364498
Add a node for the new usb phy driver.

Signed-off-by: David Lechner <david@lechnology.com>
---

v3 changes:

* No longer needs reg property since we are now using syscon instead.


 arch/arm/boot/dts/da850.dtsi | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index a360713..83ea8f6 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -313,6 +313,11 @@
 					36
 					>;
 		};
+		usbphy: usbphy {
+			compatible = "ti,da830-usbphy";
+			#phy-cells = <1>;
+			status = "disabled";
+		};
 		gpio: gpio@226000 {
 			compatible = "ti,dm6441-gpio";
 			gpio-controller;
-- 
1.9.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web