mbox

[v4] USB: add devicetree helpers for determining dr_mode and phy_type

Message ID 1359984275-24646-1-git-send-email-s.hauer@pengutronix.de
State New
Headers show

Pull-request

git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next

Message

Sascha Hauer Feb. 4, 2013, 1:24 p.m. UTC
4th round of patches.

Peter, I would be glad if you could test them before your holiday. I rebased
your last round of Chipidea OTG patches onto this series which you can pull
here:

git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next

I couldn't really test the otg patches since my current hardware does not have
the ID pin connected, but I can verify that my usecase still works with your
patches applied.

Alex, should the patches work for you and are fine otherwise, could you apply
them for v3.9?

Sascha



changes since v3:

- add phy patches (which were accidently already part of v2)
- Use OP_DEVLC instead of OP_PORTSC for lpm case
- Use enum usb_dr_mode ub ci_hdrc_probe()

changes since v2:

- fix adding of GPL Header was in wrong patch
- add missing hunk for new file of.c

changes since v1:
- move phy specific of helper to drivers/usb/phy/of.c
- use strcmp instead of strcasecmp for matching property values
- change usb_phy_dr_mode to usb_dr_mode
- change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
- add copyright header to new files
- chipidea: drop mdelay at end of PTS/PTW setup
- chipidea: implement lpm core type handling for PTS/PTW


The following changes since commit 2f0760774711c957c395b31131b848043af98edf:

  USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 10:09:19 +0100)

are available in the git repository at:

  git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next

for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:

  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 12:28:53 +0100)

----------------------------------------------------------------
USB: chipidea patches for v3.9

These add OF helpers for handling the dr_mode and phy_type property
and makes use of them in the chipidea driver.

----------------------------------------------------------------
Marc Kleine-Budde (1):
      usb: otg: use try_module_get in all usb_get_phy functions and add missing module_put

Michael Grzeschik (3):
      USB: add devicetree helpers for determining dr_mode and phy_type
      USB: chipidea: ci13xxx-imx: create dynamic platformdata
      USB: chipidea: add PTW and PTS handling

Sascha Hauer (5):
      USB: move bulk of otg/otg.c to phy/phy.c
      USB chipidea: introduce dual role mode pdata flags
      USB chipidea i.MX: introduce dr_mode property
      USB mxs-phy: Register phy with framework
      USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

 .../devicetree/bindings/usb/ci13xxx-imx.txt        |    6 +
 drivers/usb/chipidea/bits.h                        |   14 +-
 drivers/usb/chipidea/ci13xxx_imx.c                 |   68 +--
 drivers/usb/chipidea/core.c                        |   60 ++-
 drivers/usb/otg/mxs-phy.c                          |    9 +
 drivers/usb/otg/otg.c                              |  423 -------------------
 drivers/usb/phy/Makefile                           |    2 +
 drivers/usb/phy/of.c                               |   47 +++
 drivers/usb/phy/phy.c                              |  438 ++++++++++++++++++++
 drivers/usb/usb-common.c                           |   36 ++
 include/linux/usb/chipidea.h                       |    3 +-
 include/linux/usb/of.h                             |   27 ++
 include/linux/usb/otg.h                            |    7 +
 include/linux/usb/phy.h                            |    9 +
 14 files changed, 687 insertions(+), 462 deletions(-)
 create mode 100644 drivers/usb/phy/of.c
 create mode 100644 drivers/usb/phy/phy.c
 create mode 100644 include/linux/usb/of.h

Comments

Roger Quadros Feb. 4, 2013, 1:59 p.m. UTC | #1
On 02/04/2013 03:24 PM, Sascha Hauer wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> In patch "5d3c28b usb: otg: add device tree support to otg library"
> devm_usb_get_phy_by_phandle() was added. It uses try_module_get() to lock the
> phy driver in memory. The corresponding module_put() is missing in that patch.
> 
> This patch adds try_module_get() to usb_get_phy() and usb_get_phy_dev().
> Further the missing module_put() is added to usb_put_phy().
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/usb/otg/otg.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
> index e181439..2bd03d2 100644
> --- a/drivers/usb/otg/otg.c
> +++ b/drivers/usb/otg/otg.c
> @@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
>  	spin_lock_irqsave(&phy_lock, flags);
>  
>  	phy = __usb_find_phy(&phy_list, type);
> -	if (IS_ERR(phy)) {
> +	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
>  		pr_err("unable to find transceiver of type %s\n",
>  			usb_phy_type_string(type));
>  		goto err0;

There are 2 problems with this.

- If phy was found but try_module_get failed you are not returning error code.

- If phy was found and try_module_get fails we would want to use deferred probing,
since this case is possible if the phy module is not yet loaded and alive but can be in
the future.

I would change the code to

	if (IS_ERR(phy)) {
		pr_err("unable to find transceiver of type %s\n",
			usb_phy_type_string(type));
		goto err0;
	}

	if (!try_module_get(phy->dev->driver->owner)) {
		phy = ERR_PTR(-EPROBE_DEFER);
		goto err0;
	}

> @@ -228,7 +228,7 @@ struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
>  	spin_lock_irqsave(&phy_lock, flags);
>  
>  	phy = __usb_find_phy_dev(dev, &phy_bind_list, index);
> -	if (IS_ERR(phy)) {
> +	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
>  		pr_err("unable to find transceiver\n");
>  		goto err0;
>  	}
> @@ -301,8 +301,12 @@ EXPORT_SYMBOL(devm_usb_put_phy);
>   */
>  void usb_put_phy(struct usb_phy *x)
>  {
> -	if (x)
> +	if (x) {
> +		struct module *owner = x->dev->driver->owner;
> +
>  		put_device(x->dev);
> +		module_put(owner);
> +	}
>  }
>  EXPORT_SYMBOL(usb_put_phy);
>  
> 

cheers,
-roger
Marc Kleine-Budde Feb. 4, 2013, 2:10 p.m. UTC | #2
On 02/04/2013 02:59 PM, Roger Quadros wrote:
> On 02/04/2013 03:24 PM, Sascha Hauer wrote:
>> From: Marc Kleine-Budde <mkl@pengutronix.de>
>>
>> In patch "5d3c28b usb: otg: add device tree support to otg library"
>> devm_usb_get_phy_by_phandle() was added. It uses try_module_get() to lock the
>> phy driver in memory. The corresponding module_put() is missing in that patch.
>>
>> This patch adds try_module_get() to usb_get_phy() and usb_get_phy_dev().
>> Further the missing module_put() is added to usb_put_phy().
>>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>>  drivers/usb/otg/otg.c |   10 +++++++---
>>  1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
>> index e181439..2bd03d2 100644
>> --- a/drivers/usb/otg/otg.c
>> +++ b/drivers/usb/otg/otg.c
>> @@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
>>  	spin_lock_irqsave(&phy_lock, flags);
>>  
>>  	phy = __usb_find_phy(&phy_list, type);
>> -	if (IS_ERR(phy)) {
>> +	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
>>  		pr_err("unable to find transceiver of type %s\n",
>>  			usb_phy_type_string(type));
>>  		goto err0;
> 
> There are 2 problems with this.
> 
> - If phy was found but try_module_get failed you are not returning error code.

Correct - but....

> - If phy was found and try_module_get fails we would want to use deferred probing,
> since this case is possible if the phy module is not yet loaded and alive but can be in
> the future.

...this should not happen, as the phy list is protected by the
spin_lock. If a phy driver module has added a the phy to the
infrastructure, but has been rmmod'ed without removing the phy. The phy
driver is broken anyway.

Marc
Roger Quadros Feb. 4, 2013, 2:39 p.m. UTC | #3
On 02/04/2013 04:10 PM, Marc Kleine-Budde wrote:
> On 02/04/2013 02:59 PM, Roger Quadros wrote:
>> On 02/04/2013 03:24 PM, Sascha Hauer wrote:
>>> From: Marc Kleine-Budde <mkl@pengutronix.de>
>>>
>>> In patch "5d3c28b usb: otg: add device tree support to otg library"
>>> devm_usb_get_phy_by_phandle() was added. It uses try_module_get() to lock the
>>> phy driver in memory. The corresponding module_put() is missing in that patch.
>>>
>>> This patch adds try_module_get() to usb_get_phy() and usb_get_phy_dev().
>>> Further the missing module_put() is added to usb_put_phy().
>>>
>>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>>> ---
>>>  drivers/usb/otg/otg.c |   10 +++++++---
>>>  1 file changed, 7 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
>>> index e181439..2bd03d2 100644
>>> --- a/drivers/usb/otg/otg.c
>>> +++ b/drivers/usb/otg/otg.c
>>> @@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
>>>  	spin_lock_irqsave(&phy_lock, flags);
>>>  
>>>  	phy = __usb_find_phy(&phy_list, type);
>>> -	if (IS_ERR(phy)) {
>>> +	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
>>>  		pr_err("unable to find transceiver of type %s\n",
>>>  			usb_phy_type_string(type));
>>>  		goto err0;
>>
>> There are 2 problems with this.
>>
>> - If phy was found but try_module_get failed you are not returning error code.
> 
> Correct - but....
> 
>> - If phy was found and try_module_get fails we would want to use deferred probing,
>> since this case is possible if the phy module is not yet loaded and alive but can be in
>> the future.
> 
> ...this should not happen, as the phy list is protected by the
> spin_lock. If a phy driver module has added a the phy to the
> infrastructure, but has been rmmod'ed without removing the phy. The phy
> driver is broken anyway.
> 

Yes, you are right.

cheers,
-roger
Sergei Shtylyov Feb. 5, 2013, 11:45 a.m. UTC | #4
Hello.

On 04-02-2013 17:24, Sascha Hauer wrote:

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>   drivers/usb/chipidea/ci13xxx_imx.c |   39 +++++++++++++++++-------------------
>   1 file changed, 18 insertions(+), 21 deletions(-)

> diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
> index b598bb8f..136869b 100644
> --- a/drivers/usb/chipidea/ci13xxx_imx.c
> +++ b/drivers/usb/chipidea/ci13xxx_imx.c
[...]
> @@ -147,19 +146,21 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
>   		return ret;
>   	}
>
> +	phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
> +

    No need for emoty line here. Keep the style as it was please.

> +	if (PTR_ERR(phy) == -EPROBE_DEFER) {

    Is it valid to call PTR_ERR() on non-error pointer? Isn't it better to do 
this check under *else* clause below the next *if*.

> +		ret = -EPROBE_DEFER;
> +		goto err_clk;
> +	}
> +

    This empty line is also not needed, I think.

> +	if (!IS_ERR(phy)) {
> +		ret = usb_phy_init(phy);
> +		if (ret) {
> +			dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
> +			goto err_clk;
>   		}
> +
> +		data->phy = phy;
>   	}
>
>   	/* we only support host now, so enable vbus here */

WBR, Sergei
Sascha Hauer Feb. 5, 2013, 11:58 a.m. UTC | #5
On Tue, Feb 05, 2013 at 03:45:12PM +0400, Sergei Shtylyov wrote:
> Hello.
> 
> On 04-02-2013 17:24, Sascha Hauer wrote:
> 
> >Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> >---
> >  drivers/usb/chipidea/ci13xxx_imx.c |   39 +++++++++++++++++-------------------
> >  1 file changed, 18 insertions(+), 21 deletions(-)
> 
> >diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
> >index b598bb8f..136869b 100644
> >--- a/drivers/usb/chipidea/ci13xxx_imx.c
> >+++ b/drivers/usb/chipidea/ci13xxx_imx.c
> [...]
> >@@ -147,19 +146,21 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
> >  		return ret;
> >  	}
> >
> >+	phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
> >+
> 
>    No need for emoty line here. Keep the style as it was please.
> 
> >+	if (PTR_ERR(phy) == -EPROBE_DEFER) {
> 
>    Is it valid to call PTR_ERR() on non-error pointer?

Why shouldn't it?

> Isn't it
> better to do this check under *else* clause below the next *if*.

For better readability, yes.

Sascha

> 
> >+		ret = -EPROBE_DEFER;
> >+		goto err_clk;
> >+	}
> >+
> 
>    This empty line is also not needed, I think.
> 
> >+	if (!IS_ERR(phy)) {
> >+		ret = usb_phy_init(phy);
> >+		if (ret) {
> >+			dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
> >+			goto err_clk;
> >  		}
> >+
> >+		data->phy = phy;
> >  	}
> >
> >  	/* we only support host now, so enable vbus here */
> 
> WBR, Sergei
> 
>
Sascha Hauer Feb. 7, 2013, 10:56 a.m. UTC | #6
Alexander,

Did you have a chance to look at this series? Development of this driver
has stalled for too long now, I don't want to miss the next merge
window.

Thanks
 Sascha

On Mon, Feb 04, 2013 at 02:24:26PM +0100, Sascha Hauer wrote:
> 4th round of patches.
> 
> Peter, I would be glad if you could test them before your holiday. I rebased
> your last round of Chipidea OTG patches onto this series which you can pull
> here:
> 
> git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next
> 
> I couldn't really test the otg patches since my current hardware does not have
> the ID pin connected, but I can verify that my usecase still works with your
> patches applied.
> 
> Alex, should the patches work for you and are fine otherwise, could you apply
> them for v3.9?
> 
> Sascha
> 
> 
> 
> changes since v3:
> 
> - add phy patches (which were accidently already part of v2)
> - Use OP_DEVLC instead of OP_PORTSC for lpm case
> - Use enum usb_dr_mode ub ci_hdrc_probe()
> 
> changes since v2:
> 
> - fix adding of GPL Header was in wrong patch
> - add missing hunk for new file of.c
> 
> changes since v1:
> - move phy specific of helper to drivers/usb/phy/of.c
> - use strcmp instead of strcasecmp for matching property values
> - change usb_phy_dr_mode to usb_dr_mode
> - change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
> - add copyright header to new files
> - chipidea: drop mdelay at end of PTS/PTW setup
> - chipidea: implement lpm core type handling for PTS/PTW
> 
> 
> The following changes since commit 2f0760774711c957c395b31131b848043af98edf:
> 
>   USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 10:09:19 +0100)
> 
> are available in the git repository at:
> 
>   git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next
> 
> for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:
> 
>   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 12:28:53 +0100)
> 
> ----------------------------------------------------------------
> USB: chipidea patches for v3.9
> 
> These add OF helpers for handling the dr_mode and phy_type property
> and makes use of them in the chipidea driver.
> 
> ----------------------------------------------------------------
> Marc Kleine-Budde (1):
>       usb: otg: use try_module_get in all usb_get_phy functions and add missing module_put
> 
> Michael Grzeschik (3):
>       USB: add devicetree helpers for determining dr_mode and phy_type
>       USB: chipidea: ci13xxx-imx: create dynamic platformdata
>       USB: chipidea: add PTW and PTS handling
> 
> Sascha Hauer (5):
>       USB: move bulk of otg/otg.c to phy/phy.c
>       USB chipidea: introduce dual role mode pdata flags
>       USB chipidea i.MX: introduce dr_mode property
>       USB mxs-phy: Register phy with framework
>       USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy
> 
>  .../devicetree/bindings/usb/ci13xxx-imx.txt        |    6 +
>  drivers/usb/chipidea/bits.h                        |   14 +-
>  drivers/usb/chipidea/ci13xxx_imx.c                 |   68 +--
>  drivers/usb/chipidea/core.c                        |   60 ++-
>  drivers/usb/otg/mxs-phy.c                          |    9 +
>  drivers/usb/otg/otg.c                              |  423 -------------------
>  drivers/usb/phy/Makefile                           |    2 +
>  drivers/usb/phy/of.c                               |   47 +++
>  drivers/usb/phy/phy.c                              |  438 ++++++++++++++++++++
>  drivers/usb/usb-common.c                           |   36 ++
>  include/linux/usb/chipidea.h                       |    3 +-
>  include/linux/usb/of.h                             |   27 ++
>  include/linux/usb/otg.h                            |    7 +
>  include/linux/usb/phy.h                            |    9 +
>  14 files changed, 687 insertions(+), 462 deletions(-)
>  create mode 100644 drivers/usb/phy/of.c
>  create mode 100644 drivers/usb/phy/phy.c
>  create mode 100644 include/linux/usb/of.h
>
Sascha Hauer Feb. 12, 2013, 1:59 p.m. UTC | #7
On Thu, Feb 07, 2013 at 11:56:32AM +0100, Sascha Hauer wrote:
> Alexander,
> 
> Did you have a chance to look at this series? Development of this driver
> has stalled for too long now, I don't want to miss the next merge
> window.

Alexander,

Any comments?

Thanks
 Sascha

> 
> Thanks
>  Sascha
> 
> On Mon, Feb 04, 2013 at 02:24:26PM +0100, Sascha Hauer wrote:
> > 4th round of patches.
> > 
> > Peter, I would be glad if you could test them before your holiday. I rebased
> > your last round of Chipidea OTG patches onto this series which you can pull
> > here:
> > 
> > git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next
> > 
> > I couldn't really test the otg patches since my current hardware does not have
> > the ID pin connected, but I can verify that my usecase still works with your
> > patches applied.
> > 
> > Alex, should the patches work for you and are fine otherwise, could you apply
> > them for v3.9?
> > 
> > Sascha
> > 
> > 
> > 
> > changes since v3:
> > 
> > - add phy patches (which were accidently already part of v2)
> > - Use OP_DEVLC instead of OP_PORTSC for lpm case
> > - Use enum usb_dr_mode ub ci_hdrc_probe()
> > 
> > changes since v2:
> > 
> > - fix adding of GPL Header was in wrong patch
> > - add missing hunk for new file of.c
> > 
> > changes since v1:
> > - move phy specific of helper to drivers/usb/phy/of.c
> > - use strcmp instead of strcasecmp for matching property values
> > - change usb_phy_dr_mode to usb_dr_mode
> > - change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
> > - add copyright header to new files
> > - chipidea: drop mdelay at end of PTS/PTW setup
> > - chipidea: implement lpm core type handling for PTS/PTW
> > 
> > 
> > The following changes since commit 2f0760774711c957c395b31131b848043af98edf:
> > 
> >   USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 10:09:19 +0100)
> > 
> > are available in the git repository at:
> > 
> >   git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next
> > 
> > for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:
> > 
> >   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 12:28:53 +0100)
> > 
> > ----------------------------------------------------------------
> > USB: chipidea patches for v3.9
> > 
> > These add OF helpers for handling the dr_mode and phy_type property
> > and makes use of them in the chipidea driver.
> > 
> > ----------------------------------------------------------------
> > Marc Kleine-Budde (1):
> >       usb: otg: use try_module_get in all usb_get_phy functions and add missing module_put
> > 
> > Michael Grzeschik (3):
> >       USB: add devicetree helpers for determining dr_mode and phy_type
> >       USB: chipidea: ci13xxx-imx: create dynamic platformdata
> >       USB: chipidea: add PTW and PTS handling
> > 
> > Sascha Hauer (5):
> >       USB: move bulk of otg/otg.c to phy/phy.c
> >       USB chipidea: introduce dual role mode pdata flags
> >       USB chipidea i.MX: introduce dr_mode property
> >       USB mxs-phy: Register phy with framework
> >       USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy
> > 
> >  .../devicetree/bindings/usb/ci13xxx-imx.txt        |    6 +
> >  drivers/usb/chipidea/bits.h                        |   14 +-
> >  drivers/usb/chipidea/ci13xxx_imx.c                 |   68 +--
> >  drivers/usb/chipidea/core.c                        |   60 ++-
> >  drivers/usb/otg/mxs-phy.c                          |    9 +
> >  drivers/usb/otg/otg.c                              |  423 -------------------
> >  drivers/usb/phy/Makefile                           |    2 +
> >  drivers/usb/phy/of.c                               |   47 +++
> >  drivers/usb/phy/phy.c                              |  438 ++++++++++++++++++++
> >  drivers/usb/usb-common.c                           |   36 ++
> >  include/linux/usb/chipidea.h                       |    3 +-
> >  include/linux/usb/of.h                             |   27 ++
> >  include/linux/usb/otg.h                            |    7 +
> >  include/linux/usb/phy.h                            |    9 +
> >  14 files changed, 687 insertions(+), 462 deletions(-)
> >  create mode 100644 drivers/usb/phy/of.c
> >  create mode 100644 drivers/usb/phy/phy.c
> >  create mode 100644 include/linux/usb/of.h
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
Alexander Shishkin Feb. 14, 2013, 9:36 a.m. UTC | #8
Sascha Hauer <s.hauer@pengutronix.de> writes:

> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>
> This adds two little devicetree helper functions for determining the
> dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> the devicetree.
>
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/usb/phy/Makefile |    1 +
>  drivers/usb/phy/of.c     |   47 ++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/usb-common.c |   36 +++++++++++++++++++++++++++++++++++
>  include/linux/usb/of.h   |   27 ++++++++++++++++++++++++++
>  include/linux/usb/otg.h  |    7 +++++++
>  include/linux/usb/phy.h  |    9 +++++++++
>  6 files changed, 127 insertions(+)
>  create mode 100644 drivers/usb/phy/of.c
>  create mode 100644 include/linux/usb/of.h
>
> diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
> index 9fa6327..e1be1e8 100644
> --- a/drivers/usb/phy/Makefile
> +++ b/drivers/usb/phy/Makefile
> @@ -5,6 +5,7 @@
>  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
>  
>  obj-$(CONFIG_USB_OTG_UTILS)		+= phy.o
> +obj-$(CONFIG_OF)			+= of.o
>  obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
>  obj-$(CONFIG_OMAP_USB3)			+= omap-usb3.o
>  obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
> diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
> new file mode 100644
> index 0000000..e6f3b74
> --- /dev/null
> +++ b/drivers/usb/phy/of.c
> @@ -0,0 +1,47 @@
> +/*
> + * USB of helper code
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/usb/of.h>
> +#include <linux/usb/otg.h>
> +
> +static const char *usbphy_modes[] = {
> +	[USBPHY_INTERFACE_MODE_UNKNOWN]	= "",
> +	[USBPHY_INTERFACE_MODE_UTMI]	= "utmi",
> +	[USBPHY_INTERFACE_MODE_UTMIW]	= "utmi_wide",
> +	[USBPHY_INTERFACE_MODE_ULPI]	= "ulpi",
> +	[USBPHY_INTERFACE_MODE_SERIAL]	= "serial",
> +	[USBPHY_INTERFACE_MODE_HSIC]	= "hsic",
> +};
> +
> +/**
> + * of_usb_get_phy_mode - Get phy mode for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * The function gets phy interface string from property 'phy_type',
> + * and returns the correspondig enum usb_phy_interface
> + */
> +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
> +{
> +	const char *phy_type;
> +	int err, i;
> +
> +	err = of_property_read_string(np, "phy_type", &phy_type);
> +	if (err < 0)
> +		return USBPHY_INTERFACE_MODE_UNKNOWN;
> +
> +	for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
> +		if (!strcmp(phy_type, usbphy_modes[i]))
> +			return i;
> +
> +	return USBPHY_INTERFACE_MODE_UNKNOWN;
> +}
> +EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> index d29503e..ad4d87d 100644
> --- a/drivers/usb/usb-common.c
> +++ b/drivers/usb/usb-common.c
> @@ -14,6 +14,9 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/usb/ch9.h>
> +#include <linux/of.h>
> +#include <linux/usb/of.h>
> +#include <linux/usb/otg.h>
>  
>  const char *usb_speed_string(enum usb_device_speed speed)
>  {
> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
>  }
>  EXPORT_SYMBOL_GPL(usb_speed_string);
>  
> +#ifdef CONFIG_OF
> +static const char *usb_dr_modes[] = {
> +	[USB_DR_MODE_UNKNOWN]		= "",
> +	[USB_DR_MODE_HOST]		= "host",
> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> +	[USB_DR_MODE_OTG]		= "otg",
> +};

It turns out this is a problem, especially since this is generic usb
code: we have a chipidea controller (a patchset just arrived) that does
both host and peripheral, but not otg. And I'm told now that dwc3
controller can be synthesized like that too.

Summoning Felipe to the thread, this patch is largely his call anyway.

Regards,
--
Alex
Marc Kleine-Budde Feb. 14, 2013, 9:49 a.m. UTC | #9
On 02/14/2013 10:36 AM, Alexander Shishkin wrote:
> Sascha Hauer <s.hauer@pengutronix.de> writes:
> 
>> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>>
>> This adds two little devicetree helper functions for determining the
>> dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
>> the devicetree.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>>  drivers/usb/phy/Makefile |    1 +
>>  drivers/usb/phy/of.c     |   47 ++++++++++++++++++++++++++++++++++++++++++++++
>>  drivers/usb/usb-common.c |   36 +++++++++++++++++++++++++++++++++++
>>  include/linux/usb/of.h   |   27 ++++++++++++++++++++++++++
>>  include/linux/usb/otg.h  |    7 +++++++
>>  include/linux/usb/phy.h  |    9 +++++++++
>>  6 files changed, 127 insertions(+)
>>  create mode 100644 drivers/usb/phy/of.c
>>  create mode 100644 include/linux/usb/of.h
>>
>> diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
>> index 9fa6327..e1be1e8 100644
>> --- a/drivers/usb/phy/Makefile
>> +++ b/drivers/usb/phy/Makefile
>> @@ -5,6 +5,7 @@
>>  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
>>  
>>  obj-$(CONFIG_USB_OTG_UTILS)		+= phy.o
>> +obj-$(CONFIG_OF)			+= of.o
>>  obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
>>  obj-$(CONFIG_OMAP_USB3)			+= omap-usb3.o
>>  obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
>> diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
>> new file mode 100644
>> index 0000000..e6f3b74
>> --- /dev/null
>> +++ b/drivers/usb/phy/of.c
>> @@ -0,0 +1,47 @@
>> +/*
>> + * USB of helper code
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/usb/of.h>
>> +#include <linux/usb/otg.h>
>> +
>> +static const char *usbphy_modes[] = {
>> +	[USBPHY_INTERFACE_MODE_UNKNOWN]	= "",
>> +	[USBPHY_INTERFACE_MODE_UTMI]	= "utmi",
>> +	[USBPHY_INTERFACE_MODE_UTMIW]	= "utmi_wide",
>> +	[USBPHY_INTERFACE_MODE_ULPI]	= "ulpi",
>> +	[USBPHY_INTERFACE_MODE_SERIAL]	= "serial",
>> +	[USBPHY_INTERFACE_MODE_HSIC]	= "hsic",
>> +};
>> +
>> +/**
>> + * of_usb_get_phy_mode - Get phy mode for given device_node
>> + * @np:	Pointer to the given device_node
>> + *
>> + * The function gets phy interface string from property 'phy_type',
>> + * and returns the correspondig enum usb_phy_interface
>> + */
>> +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
>> +{
>> +	const char *phy_type;
>> +	int err, i;
>> +
>> +	err = of_property_read_string(np, "phy_type", &phy_type);
>> +	if (err < 0)
>> +		return USBPHY_INTERFACE_MODE_UNKNOWN;
>> +
>> +	for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
>> +		if (!strcmp(phy_type, usbphy_modes[i]))
>> +			return i;
>> +
>> +	return USBPHY_INTERFACE_MODE_UNKNOWN;
>> +}
>> +EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
>> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
>> index d29503e..ad4d87d 100644
>> --- a/drivers/usb/usb-common.c
>> +++ b/drivers/usb/usb-common.c
>> @@ -14,6 +14,9 @@
>>  #include <linux/kernel.h>
>>  #include <linux/module.h>
>>  #include <linux/usb/ch9.h>
>> +#include <linux/of.h>
>> +#include <linux/usb/of.h>
>> +#include <linux/usb/otg.h>
>>  
>>  const char *usb_speed_string(enum usb_device_speed speed)
>>  {
>> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
>>  }
>>  EXPORT_SYMBOL_GPL(usb_speed_string);
>>  
>> +#ifdef CONFIG_OF
>> +static const char *usb_dr_modes[] = {
>> +	[USB_DR_MODE_UNKNOWN]		= "",
>> +	[USB_DR_MODE_HOST]		= "host",
>> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
>> +	[USB_DR_MODE_OTG]		= "otg",
>> +};
> 
> It turns out this is a problem, especially since this is generic usb
> code: we have a chipidea controller (a patchset just arrived) that does
> both host and peripheral, but not otg. And I'm told now that dwc3
> controller can be synthesized like that too.

You mean a single instance of the controller (i.e. USB port) is host and
peripheral but has no otg registers. This means the mode of the port is
configured by userspace via the debugfs file? Is this possible?

The above property describes a single port not the whole controller. If
there is a controller with one host and one peripheral port the code in
this patch should be sufficient, as you have a property in the DT for
each port.

Marc
Felipe Balbi Feb. 14, 2013, 9:58 a.m. UTC | #10
Hi,

On Thu, Feb 14, 2013 at 10:49:44AM +0100, Marc Kleine-Budde wrote:
> >> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> >> index d29503e..ad4d87d 100644
> >> --- a/drivers/usb/usb-common.c
> >> +++ b/drivers/usb/usb-common.c
> >> @@ -14,6 +14,9 @@
> >>  #include <linux/kernel.h>
> >>  #include <linux/module.h>
> >>  #include <linux/usb/ch9.h>
> >> +#include <linux/of.h>
> >> +#include <linux/usb/of.h>
> >> +#include <linux/usb/otg.h>
> >>  
> >>  const char *usb_speed_string(enum usb_device_speed speed)
> >>  {
> >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> >>  }
> >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> >>  
> >> +#ifdef CONFIG_OF
> >> +static const char *usb_dr_modes[] = {
> >> +	[USB_DR_MODE_UNKNOWN]		= "",
> >> +	[USB_DR_MODE_HOST]		= "host",
> >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> >> +	[USB_DR_MODE_OTG]		= "otg",
> >> +};
> > 
> > It turns out this is a problem, especially since this is generic usb
> > code: we have a chipidea controller (a patchset just arrived) that does
> > both host and peripheral, but not otg. And I'm told now that dwc3
> > controller can be synthesized like that too.

I wonder if this part is really necessary. Usually you would read it
from HW's registers. For dwc3, it's quite recently that we allowed the
driver to be built with host-only, device-only or DRD functionality.

Also, this is likely to create troubles if not done correctly. Imagine
user compiles a host-only driver and board passes dr_mode = peripheral ?

Maybe we can ignore dr_mode in host-only and device-only builds and only
look at it for DRD builds ?

> You mean a single instance of the controller (i.e. USB port) is host and
> peripheral but has no otg registers. This means the mode of the port is
> configured by userspace via the debugfs file? Is this possible?

yes, it is possible. Dual-Role doesn't imply OTG, but OTG implies
Dual-Role.

> The above property describes a single port not the whole controller. If
> there is a controller with one host and one peripheral port the code in
> this patch should be sufficient, as you have a property in the DT for
> each port.

I don't think you can have a single controller like that, but good that
it supports.
Sascha Hauer Feb. 14, 2013, 10:07 a.m. UTC | #11
On Thu, Feb 14, 2013 at 11:58:22AM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 10:49:44AM +0100, Marc Kleine-Budde wrote:
> > >> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> > >> index d29503e..ad4d87d 100644
> > >> --- a/drivers/usb/usb-common.c
> > >> +++ b/drivers/usb/usb-common.c
> > >> @@ -14,6 +14,9 @@
> > >>  #include <linux/kernel.h>
> > >>  #include <linux/module.h>
> > >>  #include <linux/usb/ch9.h>
> > >> +#include <linux/of.h>
> > >> +#include <linux/usb/of.h>
> > >> +#include <linux/usb/otg.h>
> > >>  
> > >>  const char *usb_speed_string(enum usb_device_speed speed)
> > >>  {
> > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> > >>  }
> > >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> > >>  
> > >> +#ifdef CONFIG_OF
> > >> +static const char *usb_dr_modes[] = {
> > >> +	[USB_DR_MODE_UNKNOWN]		= "",
> > >> +	[USB_DR_MODE_HOST]		= "host",
> > >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> > >> +	[USB_DR_MODE_OTG]		= "otg",
> > >> +};
> > > 
> > > It turns out this is a problem, especially since this is generic usb
> > > code: we have a chipidea controller (a patchset just arrived) that does
> > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > controller can be synthesized like that too.
> 
> I wonder if this part is really necessary. Usually you would read it
> from HW's registers. For dwc3, it's quite recently that we allowed the
> driver to be built with host-only, device-only or DRD functionality.

We have quite some boards on which the ID pin is not wired up, so if a
core is both host and device capable there is no way to detect the
wanted mode if not given from the devicetree.

> 
> Also, this is likely to create troubles if not done correctly. Imagine
> user compiles a host-only driver and board passes dr_mode = peripheral ?

Either nothing will happen or some "you messed it up" printk should show
the user what's going on.

> 
> Maybe we can ignore dr_mode in host-only and device-only builds and only
> look at it for DRD builds ?

If something is or is not compiled in the kernel this doesn't mean the kernel
is not started on boards with a different situation.

Sascha
Marc Kleine-Budde Feb. 14, 2013, 10:11 a.m. UTC | #12
On 02/14/2013 10:58 AM, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 10:49:44AM +0100, Marc Kleine-Budde wrote:
>>>> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
>>>> index d29503e..ad4d87d 100644
>>>> --- a/drivers/usb/usb-common.c
>>>> +++ b/drivers/usb/usb-common.c
>>>> @@ -14,6 +14,9 @@
>>>>  #include <linux/kernel.h>
>>>>  #include <linux/module.h>
>>>>  #include <linux/usb/ch9.h>
>>>> +#include <linux/of.h>
>>>> +#include <linux/usb/of.h>
>>>> +#include <linux/usb/otg.h>
>>>>  
>>>>  const char *usb_speed_string(enum usb_device_speed speed)
>>>>  {
>>>> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
>>>>  }
>>>>  EXPORT_SYMBOL_GPL(usb_speed_string);
>>>>  
>>>> +#ifdef CONFIG_OF
>>>> +static const char *usb_dr_modes[] = {
>>>> +	[USB_DR_MODE_UNKNOWN]		= "",
>>>> +	[USB_DR_MODE_HOST]		= "host",
>>>> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
>>>> +	[USB_DR_MODE_OTG]		= "otg",
>>>> +};
>>>
>>> It turns out this is a problem, especially since this is generic usb
>>> code: we have a chipidea controller (a patchset just arrived) that does
>>> both host and peripheral, but not otg. And I'm told now that dwc3
>>> controller can be synthesized like that too.
> 
> I wonder if this part is really necessary. Usually you would read it
> from HW's registers. For dwc3, it's quite recently that we allowed the
> driver to be built with host-only, device-only or DRD functionality.

The imx25 USB version of the chipidea IP Core get's really confused if
you read from the CAP_DCCPARAMS register on the host only port. In
freescale's documentation the register is marked as reserved. The host
port will not work then.

> Also, this is likely to create troubles if not done correctly. Imagine
> user compiles a host-only driver and board passes dr_mode = peripheral ?

Use dev_err() and inform the user.

> Maybe we can ignore dr_mode in host-only and device-only builds and only
> look at it for DRD builds ?
> 
>> You mean a single instance of the controller (i.e. USB port) is host and
>> peripheral but has no otg registers. This means the mode of the port is
>> configured by userspace via the debugfs file? Is this possible?
> 
> yes, it is possible. Dual-Role doesn't imply OTG, but OTG implies
> Dual-Role.

Thanks for the info. Then we need a fourth value for the helper code.
What's a sensible sting: "dual-role", "dr"?

>> The above property describes a single port not the whole controller. If
>> there is a controller with one host and one peripheral port the code in
>> this patch should be sufficient, as you have a property in the DT for
>> each port.
> 
> I don't think you can have a single controller like that, but good that
> it supports.

The DT binding is per USB port, so that's a by product of good
abstraction :)

Marc
Felipe Balbi Feb. 14, 2013, 10:15 a.m. UTC | #13
Hi,

On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> > > >>  }
> > > >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> > > >>  
> > > >> +#ifdef CONFIG_OF
> > > >> +static const char *usb_dr_modes[] = {
> > > >> +	[USB_DR_MODE_UNKNOWN]		= "",
> > > >> +	[USB_DR_MODE_HOST]		= "host",
> > > >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> > > >> +	[USB_DR_MODE_OTG]		= "otg",
> > > >> +};
> > > > 
> > > > It turns out this is a problem, especially since this is generic usb
> > > > code: we have a chipidea controller (a patchset just arrived) that does
> > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > controller can be synthesized like that too.
> > 
> > I wonder if this part is really necessary. Usually you would read it
> > from HW's registers. For dwc3, it's quite recently that we allowed the
> > driver to be built with host-only, device-only or DRD functionality.
> 
> We have quite some boards on which the ID pin is not wired up, so if a
> core is both host and device capable there is no way to detect the
> wanted mode if not given from the devicetree.

right, that's fair. But that doesn't mean board can't work as both,
right. The IP is still the same, just the board is wired differently ;-)

> > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > look at it for DRD builds ?
> 
> If something is or is not compiled in the kernel this doesn't mean the kernel
> is not started on boards with a different situation.

who said kernel wouldn't start ? If you request a host-only build, you
need to force your IP into working as host, since that's all you have,
either that or you bail out on probe().

If board wants to work as a device, well tough luck, go figure how to
setup Kconfig properly.
Felipe Balbi Feb. 14, 2013, 10:16 a.m. UTC | #14
On Thu, Feb 14, 2013 at 11:11:55AM +0100, Marc Kleine-Budde wrote:
> >>>> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> >>>>  }
> >>>>  EXPORT_SYMBOL_GPL(usb_speed_string);
> >>>>  
> >>>> +#ifdef CONFIG_OF
> >>>> +static const char *usb_dr_modes[] = {
> >>>> +	[USB_DR_MODE_UNKNOWN]		= "",
> >>>> +	[USB_DR_MODE_HOST]		= "host",
> >>>> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> >>>> +	[USB_DR_MODE_OTG]		= "otg",
> >>>> +};
> >>>
> >>> It turns out this is a problem, especially since this is generic usb
> >>> code: we have a chipidea controller (a patchset just arrived) that does
> >>> both host and peripheral, but not otg. And I'm told now that dwc3
> >>> controller can be synthesized like that too.
> > 
> > I wonder if this part is really necessary. Usually you would read it
> > from HW's registers. For dwc3, it's quite recently that we allowed the
> > driver to be built with host-only, device-only or DRD functionality.
> 
> The imx25 USB version of the chipidea IP Core get's really confused if
> you read from the CAP_DCCPARAMS register on the host only port. In
> freescale's documentation the register is marked as reserved. The host
> port will not work then.

heh, nicely done.

> > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > look at it for DRD builds ?
> > 
> >> You mean a single instance of the controller (i.e. USB port) is host and
> >> peripheral but has no otg registers. This means the mode of the port is
> >> configured by userspace via the debugfs file? Is this possible?
> > 
> > yes, it is possible. Dual-Role doesn't imply OTG, but OTG implies
> > Dual-Role.
> 
> Thanks for the info. Then we need a fourth value for the helper code.
> What's a sensible sting: "dual-role", "dr"?

dual-role.
Sascha Hauer Feb. 14, 2013, 11:24 a.m. UTC | #15
On Thu, Feb 14, 2013 at 12:15:10PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> > > > >>  }
> > > > >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> > > > >>  
> > > > >> +#ifdef CONFIG_OF
> > > > >> +static const char *usb_dr_modes[] = {
> > > > >> +	[USB_DR_MODE_UNKNOWN]		= "",
> > > > >> +	[USB_DR_MODE_HOST]		= "host",
> > > > >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> > > > >> +	[USB_DR_MODE_OTG]		= "otg",
> > > > >> +};
> > > > > 
> > > > > It turns out this is a problem, especially since this is generic usb
> > > > > code: we have a chipidea controller (a patchset just arrived) that does
> > > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > > controller can be synthesized like that too.
> > > 
> > > I wonder if this part is really necessary. Usually you would read it
> > > from HW's registers. For dwc3, it's quite recently that we allowed the
> > > driver to be built with host-only, device-only or DRD functionality.
> > 
> > We have quite some boards on which the ID pin is not wired up, so if a
> > core is both host and device capable there is no way to detect the
> > wanted mode if not given from the devicetree.
> 
> right, that's fair. But that doesn't mean board can't work as both,
> right. The IP is still the same, just the board is wired differently ;-)

Yes, it is. Usually I run kernels with both host and device support enabled.
Consider the IP is OTG capable, the chipidea driver will initialize
both roles. Now if a board only supports one role and does not have an
ID pin, how do I make sure the driver is in the correct mode? I need to
specify it somehow. Otherwise I may end up on a host-only board with the
driver sitting in device mode, or with a device-only board with the
driver sitting in host mode.

> 
> > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > look at it for DRD builds ?
> > 
> > If something is or is not compiled in the kernel this doesn't mean the kernel
> > is not started on boards with a different situation.
> 
> who said kernel wouldn't start ? If you request a host-only build, you
> need to force your IP into working as host, since that's all you have,
> either that or you bail out on probe().

Let me clarify, I don't want to use Kconfig to specify my boards
capabilities. If a kernel is compiled for host mode only and the
devicetree specifies a port is device-only, then yes, the driver
should bail out on probe, maybe leaving a message that it found
a device for which the suitable role is not compiled in.

Sascha
Alexander Shishkin Feb. 14, 2013, 1:07 p.m. UTC | #16
Sascha Hauer <s.hauer@pengutronix.de> writes:

> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>
> This patch makes it possible to configure the PTW and PTS bits inside
> the portsc register for host and device mode before the driver starts
> and the phy can be addressed as hardware implementation is designed.
>
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  .../devicetree/bindings/usb/ci13xxx-imx.txt        |    5 +++
>  drivers/usb/chipidea/bits.h                        |   14 ++++++-
>  drivers/usb/chipidea/ci13xxx_imx.c                 |    3 ++
>  drivers/usb/chipidea/core.c                        |   39 ++++++++++++++++++++
>  include/linux/usb/chipidea.h                       |    1 +
>  5 files changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> index 5778b9c..dd42ccd 100644
> --- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> +++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> @@ -5,6 +5,11 @@ Required properties:
>  - reg: Should contain registers location and length
>  - interrupts: Should contain controller interrupt
>  
> +Recommended properies:
> +- phy_type: the type of the phy connected to the core. Should be one
> +  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
> +  property the PORTSC register won't be touched
> +

Looks like this bit belongs to patch 3/9, where you're adding devicetree
hooks. Otherwise looks good.

Regards,
--
Alex
Felipe Balbi Feb. 14, 2013, 1:10 p.m. UTC | #17
On Thu, Feb 14, 2013 at 12:24:49PM +0100, Sascha Hauer wrote:
> On Thu, Feb 14, 2013 at 12:15:10PM +0200, Felipe Balbi wrote:
> > Hi,
> > 
> > On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> > > > > >>  }
> > > > > >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> > > > > >>  
> > > > > >> +#ifdef CONFIG_OF
> > > > > >> +static const char *usb_dr_modes[] = {
> > > > > >> +	[USB_DR_MODE_UNKNOWN]		= "",
> > > > > >> +	[USB_DR_MODE_HOST]		= "host",
> > > > > >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> > > > > >> +	[USB_DR_MODE_OTG]		= "otg",
> > > > > >> +};
> > > > > > 
> > > > > > It turns out this is a problem, especially since this is generic usb
> > > > > > code: we have a chipidea controller (a patchset just arrived) that does
> > > > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > > > controller can be synthesized like that too.
> > > > 
> > > > I wonder if this part is really necessary. Usually you would read it
> > > > from HW's registers. For dwc3, it's quite recently that we allowed the
> > > > driver to be built with host-only, device-only or DRD functionality.
> > > 
> > > We have quite some boards on which the ID pin is not wired up, so if a
> > > core is both host and device capable there is no way to detect the
> > > wanted mode if not given from the devicetree.
> > 
> > right, that's fair. But that doesn't mean board can't work as both,
> > right. The IP is still the same, just the board is wired differently ;-)
> 
> Yes, it is. Usually I run kernels with both host and device support enabled.
> Consider the IP is OTG capable, the chipidea driver will initialize
> both roles. Now if a board only supports one role and does not have an
> ID pin, how do I make sure the driver is in the correct mode? I need to
> specify it somehow. Otherwise I may end up on a host-only board with the
> driver sitting in device mode, or with a device-only board with the
> driver sitting in host mode.

right.

> > > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > > look at it for DRD builds ?
> > > 
> > > If something is or is not compiled in the kernel this doesn't mean the kernel
> > > is not started on boards with a different situation.
> > 
> > who said kernel wouldn't start ? If you request a host-only build, you
> > need to force your IP into working as host, since that's all you have,
> > either that or you bail out on probe().
> 
> Let me clarify, I don't want to use Kconfig to specify my boards
> capabilities. If a kernel is compiled for host mode only and the
> devicetree specifies a port is device-only, then yes, the driver
> should bail out on probe, maybe leaving a message that it found
> a device for which the suitable role is not compiled in.

yeah, this is why I said we should ignore dr_mode (or bail out) when
!OTG.
Alexander Shishkin Feb. 14, 2013, 1:22 p.m. UTC | #18
Sascha Hauer <s.hauer@pengutronix.de> writes:

> 4th round of patches.
>
> Peter, I would be glad if you could test them before your holiday. I rebased
> your last round of Chipidea OTG patches onto this series which you can pull
> here:
>
> git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next
>
> I couldn't really test the otg patches since my current hardware does not have
> the ID pin connected, but I can verify that my usecase still works with your
> patches applied.
>
> Alex, should the patches work for you and are fine otherwise, could you apply
> them for v3.9?

Looks good in general. I just realised the comment I made on 5/9 is not
entirely valid, but the dr_mode setting needs one extra option as was
discussed. Also, all the phy/otg patches (1/9, 2/9, 3/9, 8/9) need
Felipe's ack, then I can apply the series.

Regards,
--
Alex
Sascha Hauer Feb. 14, 2013, 4:06 p.m. UTC | #19
On Thu, Feb 14, 2013 at 03:10:15PM +0200, Felipe Balbi wrote:
> On Thu, Feb 14, 2013 at 12:24:49PM +0100, Sascha Hauer wrote:
> > On Thu, Feb 14, 2013 at 12:15:10PM +0200, Felipe Balbi wrote:
> > > Hi,
> > > 
> > > On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > > > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
> > > > > > >>  }
> > > > > > >>  EXPORT_SYMBOL_GPL(usb_speed_string);
> > > > > > >>  
> > > > > > >> +#ifdef CONFIG_OF
> > > > > > >> +static const char *usb_dr_modes[] = {
> > > > > > >> +	[USB_DR_MODE_UNKNOWN]		= "",
> > > > > > >> +	[USB_DR_MODE_HOST]		= "host",
> > > > > > >> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> > > > > > >> +	[USB_DR_MODE_OTG]		= "otg",
> > > > > > >> +};
> > > > > > > 
> > > > > > > It turns out this is a problem, especially since this is generic usb
> > > > > > > code: we have a chipidea controller (a patchset just arrived) that does
> > > > > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > > > > controller can be synthesized like that too.
> > > > > 
> > > > > I wonder if this part is really necessary. Usually you would read it
> > > > > from HW's registers. For dwc3, it's quite recently that we allowed the
> > > > > driver to be built with host-only, device-only or DRD functionality.
> > > > 
> > > > We have quite some boards on which the ID pin is not wired up, so if a
> > > > core is both host and device capable there is no way to detect the
> > > > wanted mode if not given from the devicetree.
> > > 
> > > right, that's fair. But that doesn't mean board can't work as both,
> > > right. The IP is still the same, just the board is wired differently ;-)
> > 
> > Yes, it is. Usually I run kernels with both host and device support enabled.
> > Consider the IP is OTG capable, the chipidea driver will initialize
> > both roles. Now if a board only supports one role and does not have an
> > ID pin, how do I make sure the driver is in the correct mode? I need to
> > specify it somehow. Otherwise I may end up on a host-only board with the
> > driver sitting in device mode, or with a device-only board with the
> > driver sitting in host mode.
> 
> right.
> 
> > > > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > > > look at it for DRD builds ?
> > > > 
> > > > If something is or is not compiled in the kernel this doesn't mean the kernel
> > > > is not started on boards with a different situation.
> > > 
> > > who said kernel wouldn't start ? If you request a host-only build, you
> > > need to force your IP into working as host, since that's all you have,
> > > either that or you bail out on probe().
> > 
> > Let me clarify, I don't want to use Kconfig to specify my boards
> > capabilities. If a kernel is compiled for host mode only and the
> > devicetree specifies a port is device-only, then yes, the driver
> > should bail out on probe, maybe leaving a message that it found
> > a device for which the suitable role is not compiled in.
> 
> yeah, this is why I said we should ignore dr_mode (or bail out) when
> !OTG.

Ok, that's what the patch effectively does. We have this in chipidea/core.c:

| 	dr_mode = ci->platdata->dr_mode;
| 	if (dr_mode == USB_DR_MODE_UNKNOWN)
| 		dr_mode = USB_DR_MODE_OTG;

default to otg if nothing specified.

| 
| 	/* initialize role(s) before the interrupt is requested */
| 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
| 		ret = ci_hdrc_host_init(ci);
| 		if (ret)
| 			dev_info(dev, "doesn't support host\n");
| 	}

If we can do OTG or host, try to initialize host role,

| 
| 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
| 		ret = ci_hdrc_gadget_init(ci);
| 		if (ret)
| 			dev_info(dev, "doesn't support gadget\n");
| 	}

if we can do otg or peripheral, try to initialize device role,

| 
| 	if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
| 		dev_err(dev, "no supported roles\n");
| 		ret = -ENODEV;
| 		goto rm_wq;
| 	}

If we have no roles, complain and bail out.

ci_hdrc_host_init / ci_hdrc_gadget_init are static inline noops when
gadget or host are disabled.

Sascha
Felipe Balbi Feb. 14, 2013, 6:04 p.m. UTC | #20
Hi,

On Thu, Feb 14, 2013 at 05:06:55PM +0100, Sascha Hauer wrote:
> > > > > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > > > > look at it for DRD builds ?
> > > > > 
> > > > > If something is or is not compiled in the kernel this doesn't mean the kernel
> > > > > is not started on boards with a different situation.
> > > > 
> > > > who said kernel wouldn't start ? If you request a host-only build, you
> > > > need to force your IP into working as host, since that's all you have,
> > > > either that or you bail out on probe().
> > > 
> > > Let me clarify, I don't want to use Kconfig to specify my boards
> > > capabilities. If a kernel is compiled for host mode only and the
> > > devicetree specifies a port is device-only, then yes, the driver
> > > should bail out on probe, maybe leaving a message that it found
> > > a device for which the suitable role is not compiled in.
> > 
> > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > !OTG.
> 
> Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> 
> | 	dr_mode = ci->platdata->dr_mode;
> | 	if (dr_mode == USB_DR_MODE_UNKNOWN)
> | 		dr_mode = USB_DR_MODE_OTG;
> 
> default to otg if nothing specified.

you missed my point. I wanted something like:

dr_mode = ci->platdata->dr_mode;
if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
	dr_mode = USB_DR_MODE_OTG;

this copes with the situation where dr_mode == USB_DR_MODE_HOST but
kernel is gadget-only.
Sascha Hauer Feb. 14, 2013, 6:30 p.m. UTC | #21
On Thu, Feb 14, 2013 at 08:04:44PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 05:06:55PM +0100, Sascha Hauer wrote:
> > > > > > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > > > > > look at it for DRD builds ?
> > > > > > 
> > > > > > If something is or is not compiled in the kernel this doesn't mean the kernel
> > > > > > is not started on boards with a different situation.
> > > > > 
> > > > > who said kernel wouldn't start ? If you request a host-only build, you
> > > > > need to force your IP into working as host, since that's all you have,
> > > > > either that or you bail out on probe().
> > > > 
> > > > Let me clarify, I don't want to use Kconfig to specify my boards
> > > > capabilities. If a kernel is compiled for host mode only and the
> > > > devicetree specifies a port is device-only, then yes, the driver
> > > > should bail out on probe, maybe leaving a message that it found
> > > > a device for which the suitable role is not compiled in.
> > > 
> > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > !OTG.
> > 
> > Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> > 
> > | 	dr_mode = ci->platdata->dr_mode;
> > | 	if (dr_mode == USB_DR_MODE_UNKNOWN)
> > | 		dr_mode = USB_DR_MODE_OTG;
> > 
> > default to otg if nothing specified.
> 
> you missed my point. I wanted something like:
> 
> dr_mode = ci->platdata->dr_mode;
> if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
> 	dr_mode = USB_DR_MODE_OTG;

So everytime the chipidea driver cannot do OTG the driver falls back to
exactly this mode?

> 
> this copes with the situation where dr_mode == USB_DR_MODE_HOST but
> kernel is gadget-only.

When I specify dr_mode = USB_DR_MODE_HOST in the devicetree indicating
that my board is only host capable I exactly want the driver to be in
host mode for this device, or to bail out if the kernel does not have
host support compiled in.

Sorry, I still don't get it.

Sascha
Felipe Balbi Feb. 14, 2013, 7:36 p.m. UTC | #22
Hi,

On Thu, Feb 14, 2013 at 07:30:26PM +0100, Sascha Hauer wrote:
> > > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > > !OTG.
> > > 
> > > Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> > > 
> > > | 	dr_mode = ci->platdata->dr_mode;
> > > | 	if (dr_mode == USB_DR_MODE_UNKNOWN)
> > > | 		dr_mode = USB_DR_MODE_OTG;
> > > 
> > > default to otg if nothing specified.
> > 
> > you missed my point. I wanted something like:
> > 
> > dr_mode = ci->platdata->dr_mode;
> > if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
> > 	dr_mode = USB_DR_MODE_OTG;
> 
> So everytime the chipidea driver cannot do OTG the driver falls back to
> exactly this mode?

hehe, that was me being stupid I meant something like:

if (!IS_ENABLED(HOST) && dr_mode == HOST)

or

if (!IS_ENABLED(GADGET) && dr_mode == GADGET)

in those cases, it's best to either force OTG (then driver will work
with whatever it has) or bail out.

Thinking a bit harder, it's best to bail as you can't be sure udc.c or
host.c have been compiled in.

> > this copes with the situation where dr_mode == USB_DR_MODE_HOST but
> > kernel is gadget-only.
> 
> When I specify dr_mode = USB_DR_MODE_HOST in the devicetree indicating
> that my board is only host capable I exactly want the driver to be in
> host mode for this device, or to bail out if the kernel does not have
> host support compiled in.

right.
Sascha Hauer Feb. 15, 2013, 10:54 a.m. UTC | #23
On Thu, Feb 14, 2013 at 09:36:26PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 07:30:26PM +0100, Sascha Hauer wrote:
> > > > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > > > !OTG.
> > > > 
> > > > Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> > > > 
> > > > | 	dr_mode = ci->platdata->dr_mode;
> > > > | 	if (dr_mode == USB_DR_MODE_UNKNOWN)
> > > > | 		dr_mode = USB_DR_MODE_OTG;
> > > > 
> > > > default to otg if nothing specified.
> > > 
> > > you missed my point. I wanted something like:
> > > 
> > > dr_mode = ci->platdata->dr_mode;
> > > if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
> > > 	dr_mode = USB_DR_MODE_OTG;
> > 
> > So everytime the chipidea driver cannot do OTG the driver falls back to
> > exactly this mode?
> 
> hehe, that was me being stupid I meant something like:
> 
> if (!IS_ENABLED(HOST) && dr_mode == HOST)
> 
> or
> 
> if (!IS_ENABLED(GADGET) && dr_mode == GADGET)
> 
> in those cases, it's best to either force OTG (then driver will work
> with whatever it has) or bail out.
> 
> Thinking a bit harder, it's best to bail as you can't be sure udc.c or
> host.c have been compiled in.

Look again, that's what the current code does. Maybe it's not coded as
explicit as you describe above.

| 	/* initialize role(s) before the interrupt is requested */
| 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
| 		ret = ci_hdrc_host_init(ci);
| 		if (ret)
| 			dev_info(dev, "doesn't support host\n");
| 	}

if IS_ENABLED(HOST), then ci_hdrc_host_init() will set
ci->roles[CI_ROLE_HOST] in case it manages to initialize the host driver.

if !IS_ENABLED(HOST), then ci_hdrc_host_init() will be a static inline
noop function, so ci->roles[CI_ROLE_HOST] ends up being NULL.

| 
| 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
| 		ret = ci_hdrc_gadget_init(ci);
| 		if (ret)
| 			dev_info(dev, "doesn't support gadget\n");
| 	}

Same applies for gadget.

| 
| 	if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
| 		dev_err(dev, "no supported roles\n");
| 		ret = -ENODEV;
| 		goto rm_wq;
| 	}

At this point (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET])
means that the intersection of what is requested and what we are able to
do is empty. The reasons could be That the requested mode is not compiled
into the kernel, or the requested role failed to initialize.

Sascha
Peter Chen Feb. 17, 2013, 9 a.m. UTC | #24
On Fri, Feb 15, 2013 at 11:54:10AM +0100, Sascha Hauer wrote:
> On Thu, Feb 14, 2013 at 09:36:26PM +0200, Felipe Balbi wrote:
> > Hi,
> > 
> > On Thu, Feb 14, 2013 at 07:30:26PM +0100, Sascha Hauer wrote:
> > > > > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > > > > !OTG.
> > > > > 
> > > > > Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> > > > > 
> > > > > | 	dr_mode = ci->platdata->dr_mode;
> > > > > | 	if (dr_mode == USB_DR_MODE_UNKNOWN)
> > > > > | 		dr_mode = USB_DR_MODE_OTG;
> > > > > 
> > > > > default to otg if nothing specified.
> > > > 
> > > > you missed my point. I wanted something like:
> > > > 
> > > > dr_mode = ci->platdata->dr_mode;
> > > > if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
> > > > 	dr_mode = USB_DR_MODE_OTG;
> > > 
> > > So everytime the chipidea driver cannot do OTG the driver falls back to
> > > exactly this mode?
> > 
> > hehe, that was me being stupid I meant something like:
> > 
> > if (!IS_ENABLED(HOST) && dr_mode == HOST)
> > 
> > or
> > 
> > if (!IS_ENABLED(GADGET) && dr_mode == GADGET)
> > 
> > in those cases, it's best to either force OTG (then driver will work
> > with whatever it has) or bail out.
> > 
> > Thinking a bit harder, it's best to bail as you can't be sure udc.c or
> > host.c have been compiled in.
> 
> Look again, that's what the current code does. Maybe it's not coded as
> explicit as you describe above.
> 
> | 	/* initialize role(s) before the interrupt is requested */
> | 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
> | 		ret = ci_hdrc_host_init(ci);
> | 		if (ret)
> | 			dev_info(dev, "doesn't support host\n");
> | 	}
> 
> if IS_ENABLED(HOST), then ci_hdrc_host_init() will set
> ci->roles[CI_ROLE_HOST] in case it manages to initialize the host driver.
> 
> if !IS_ENABLED(HOST), then ci_hdrc_host_init() will be a static inline
> noop function, so ci->roles[CI_ROLE_HOST] ends up being NULL.
> 
> | 
> | 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
> | 		ret = ci_hdrc_gadget_init(ci);
> | 		if (ret)
> | 			dev_info(dev, "doesn't support gadget\n");
> | 	}
> 
> Same applies for gadget.
> 
> | 
> | 	if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
> | 		dev_err(dev, "no supported roles\n");
> | 		ret = -ENODEV;
> | 		goto rm_wq;
> | 	}
> 
> At this point (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET])
> means that the intersection of what is requested and what we are able to
> do is empty. The reasons could be That the requested mode is not compiled
> into the kernel, or the requested role failed to initialize.
I have tested host-only capable port (host 1) and dr_mode = "host" DT setting
(OTG port) as well as only compile chipidea gadget, the "no support roles"
will be reported, and fails probe, see below. (The platform layer probe's
error needs to my another patch in my otg patchset)

ci_hdrc ci_hdrc.0: ChipIdea HDRC found, lpm: 0; cap: c08a6100 op: c08a6140
ci_hdrc ci_hdrc.0: doesn't support host
ci_hdrc ci_hdrc.0: no supported roles
imx_usb 2184000.usb: Can't register ci_hdrc platform device, err=-19
imx_usb 2184200.usb: pinctrl get/select failed, err=-19
ci_hdrc ci_hdrc.1: ChipIdea HDRC found, lpm: 0; cap: c08ae300 op: c08ae340
ci_hdrc ci_hdrc.1: doesn't support host
ci_hdrc ci_hdrc.1: doesn't support gadget
ci_hdrc ci_hdrc.1: no supported roles
imx_usb 2184200.usb: Can't register ci_hdrc platform device, err=-19

> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> --
> 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
>
Felipe Balbi Feb. 19, 2013, 9:30 a.m. UTC | #25
On Mon, Feb 04, 2013 at 02:24:28PM +0100, Sascha Hauer wrote:
> Most of otg/otg.c is not otg specific, but phy specific, so move it
> to the phy directory.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Reported-by: Kishon Vijay Abraham I <kishon@ti.com>
> Cc: Felipe Balbi <balbi@ti.com>

this is pretty ok, I'll start queueing patches for v3.10 in about a week
or two.
Sascha Hauer Feb. 19, 2013, 7:06 p.m. UTC | #26
On Tue, Feb 19, 2013 at 11:30:19AM +0200, Felipe Balbi wrote:
> On Mon, Feb 04, 2013 at 02:24:28PM +0100, Sascha Hauer wrote:
> > Most of otg/otg.c is not otg specific, but phy specific, so move it
> > to the phy directory.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > Reported-by: Kishon Vijay Abraham I <kishon@ti.com>
> > Cc: Felipe Balbi <balbi@ti.com>
> 
> this is pretty ok, I'll start queueing patches for v3.10 in about a week
> or two.

Ok, thanks. I'll resend this after the merge window.

Sascha
Felipe Balbi Feb. 19, 2013, 7:48 p.m. UTC | #27
On Tue, Feb 19, 2013 at 08:06:35PM +0100, Sascha Hauer wrote:
> On Tue, Feb 19, 2013 at 11:30:19AM +0200, Felipe Balbi wrote:
> > On Mon, Feb 04, 2013 at 02:24:28PM +0100, Sascha Hauer wrote:
> > > Most of otg/otg.c is not otg specific, but phy specific, so move it
> > > to the phy directory.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > Reported-by: Kishon Vijay Abraham I <kishon@ti.com>
> > > Cc: Felipe Balbi <balbi@ti.com>
> > 
> > this is pretty ok, I'll start queueing patches for v3.10 in about a week
> > or two.
> 
> Ok, thanks. I'll resend this after the merge window.

cool great, that lets me wait for v3.9-rc1 before queueing, much
better ;-)
Peter Chen Feb. 22, 2013, 2:09 a.m. UTC | #28
On Mon, Feb 04, 2013 at 02:24:32PM +0100, Sascha Hauer wrote:
> Even if a chipidea core is otg capable the board may not. This allows
> to explicitly set the core to host/peripheral mode. Without these
> flags the driver falls back to the old behaviour.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/usb/chipidea/core.c  |   21 +++++++++++++++------
>  include/linux/usb/chipidea.h |    2 +-
>  2 files changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index 04d68cb..c89f2aa 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -435,6 +435,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>  	struct resource	*res;
>  	void __iomem	*base;
>  	int		ret;
> +	enum usb_dr_mode dr_mode;
>  
>  	if (!dev->platform_data) {
>  		dev_err(dev, "platform data missing\n");
> @@ -487,14 +488,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> -	ret = ci_hdrc_gadget_init(ci);
> -	if (ret)
> -		dev_info(dev, "doesn't support gadget\n");
> +	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {

Can we change "USB_DR_MODE_PERIPHERAL" to "USB_DR_MODE_GADGET", since we always
use gadget to stands for device or peripheral mode at code (like below
CI_ROLE_GADGET), it may make code uniform.

> +		ret = ci_hdrc_gadget_init(ci);
> +		if (ret)
> +			dev_info(dev, "doesn't support gadget\n");
> +	}
>  
>  	if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
>  		dev_err(dev, "no supported roles\n");
Marc Kleine-Budde Feb. 27, 2013, 10:23 a.m. UTC | #29
On 02/14/2013 02:07 PM, Alexander Shishkin wrote:
> Sascha Hauer <s.hauer@pengutronix.de> writes:
> 
>> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>>
>> This patch makes it possible to configure the PTW and PTS bits inside
>> the portsc register for host and device mode before the driver starts
>> and the phy can be addressed as hardware implementation is designed.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>>  .../devicetree/bindings/usb/ci13xxx-imx.txt        |    5 +++
>>  drivers/usb/chipidea/bits.h                        |   14 ++++++-
>>  drivers/usb/chipidea/ci13xxx_imx.c                 |    3 ++
>>  drivers/usb/chipidea/core.c                        |   39 ++++++++++++++++++++
>>  include/linux/usb/chipidea.h                       |    1 +
>>  5 files changed, 61 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
>> index 5778b9c..dd42ccd 100644
>> --- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
>> +++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
>> @@ -5,6 +5,11 @@ Required properties:
>>  - reg: Should contain registers location and length
>>  - interrupts: Should contain controller interrupt
>>  
>> +Recommended properies:
>> +- phy_type: the type of the phy connected to the core. Should be one
>> +  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
>> +  property the PORTSC register won't be touched
>> +
> 
> Looks like this bit belongs to patch 3/9, where you're adding devicetree
> hooks. Otherwise looks good.

Nope. Patch 3/9 adds the device tree helper code. But this patch adds
the functionality to the chipidea imx glue code, so the update of the
devicetree docs belongs into this patch.

Marc
Marc Kleine-Budde Feb. 27, 2013, 10:42 a.m. UTC | #30
On 02/22/2013 03:09 AM, Peter Chen wrote:
> On Mon, Feb 04, 2013 at 02:24:32PM +0100, Sascha Hauer wrote:
>> Even if a chipidea core is otg capable the board may not. This allows
>> to explicitly set the core to host/peripheral mode. Without these
>> flags the driver falls back to the old behaviour.
>>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>>  drivers/usb/chipidea/core.c  |   21 +++++++++++++++------
>>  include/linux/usb/chipidea.h |    2 +-
>>  2 files changed, 16 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
>> index 04d68cb..c89f2aa 100644
>> --- a/drivers/usb/chipidea/core.c
>> +++ b/drivers/usb/chipidea/core.c
>> @@ -435,6 +435,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>>  	struct resource	*res;
>>  	void __iomem	*base;
>>  	int		ret;
>> +	enum usb_dr_mode dr_mode;
>>  
>>  	if (!dev->platform_data) {
>>  		dev_err(dev, "platform data missing\n");
>> @@ -487,14 +488,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>>  		return -ENODEV;
>>  	}
>>  
>> -	ret = ci_hdrc_gadget_init(ci);
>> -	if (ret)
>> -		dev_info(dev, "doesn't support gadget\n");
>> +	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
> 
> Can we change "USB_DR_MODE_PERIPHERAL" to "USB_DR_MODE_GADGET", since we always
> use gadget to stands for device or peripheral mode at code (like below
> CI_ROLE_GADGET), it may make code uniform.

Peripheral mode seems to be the more official name compared to gadget. I
vote for keeping peripheral in the DT and changing the chipidea to use
peripheral instead of gadget (in a later patch(es)).

Marc
Peter Chen March 13, 2013, 9:43 a.m. UTC | #31
On Mon, Feb 04, 2013 at 02:24:29PM +0100, Sascha Hauer wrote:
> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
> 
> This adds two little devicetree helper functions for determining the
> dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> the devicetree.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/usb/phy/Makefile |    1 +
>  drivers/usb/phy/of.c     |   47 ++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/usb-common.c |   36 +++++++++++++++++++++++++++++++++++
>  include/linux/usb/of.h   |   27 ++++++++++++++++++++++++++
>  include/linux/usb/otg.h  |    7 +++++++
>  include/linux/usb/phy.h  |    9 +++++++++
>  6 files changed, 127 insertions(+)
>  create mode 100644 drivers/usb/phy/of.c
>  create mode 100644 include/linux/usb/of.h
> 
> diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
> index 9fa6327..e1be1e8 100644
> --- a/drivers/usb/phy/Makefile
> +++ b/drivers/usb/phy/Makefile
> @@ -5,6 +5,7 @@
>  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
>  
>  obj-$(CONFIG_USB_OTG_UTILS)		+= phy.o
> +obj-$(CONFIG_OF)			+= of.o
>  obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
>  obj-$(CONFIG_OMAP_USB3)			+= omap-usb3.o
>  obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
> diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
> new file mode 100644
> index 0000000..e6f3b74
> --- /dev/null
> +++ b/drivers/usb/phy/of.c
> @@ -0,0 +1,47 @@
> +/*
> + * USB of helper code
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/usb/of.h>
> +#include <linux/usb/otg.h>
> +
> +static const char *usbphy_modes[] = {
> +	[USBPHY_INTERFACE_MODE_UNKNOWN]	= "",
> +	[USBPHY_INTERFACE_MODE_UTMI]	= "utmi",
> +	[USBPHY_INTERFACE_MODE_UTMIW]	= "utmi_wide",
> +	[USBPHY_INTERFACE_MODE_ULPI]	= "ulpi",
> +	[USBPHY_INTERFACE_MODE_SERIAL]	= "serial",
> +	[USBPHY_INTERFACE_MODE_HSIC]	= "hsic",
> +};
> +
> +/**
> + * of_usb_get_phy_mode - Get phy mode for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * The function gets phy interface string from property 'phy_type',
> + * and returns the correspondig enum usb_phy_interface
> + */
> +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
> +{
> +	const char *phy_type;
> +	int err, i;
> +
> +	err = of_property_read_string(np, "phy_type", &phy_type);
> +	if (err < 0)
> +		return USBPHY_INTERFACE_MODE_UNKNOWN;
> +
> +	for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
> +		if (!strcmp(phy_type, usbphy_modes[i]))
> +			return i;
> +
> +	return USBPHY_INTERFACE_MODE_UNKNOWN;
> +}
> +EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> index d29503e..ad4d87d 100644
> --- a/drivers/usb/usb-common.c
> +++ b/drivers/usb/usb-common.c
> @@ -14,6 +14,9 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/usb/ch9.h>
> +#include <linux/of.h>
> +#include <linux/usb/of.h>
> +#include <linux/usb/otg.h>
>  
>  const char *usb_speed_string(enum usb_device_speed speed)
>  {
> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
>  }
>  EXPORT_SYMBOL_GPL(usb_speed_string);
>  
> +#ifdef CONFIG_OF
> +static const char *usb_dr_modes[] = {
> +	[USB_DR_MODE_UNKNOWN]		= "",
> +	[USB_DR_MODE_HOST]		= "host",
> +	[USB_DR_MODE_PERIPHERAL]	= "peripheral",
> +	[USB_DR_MODE_OTG]		= "otg",
> +};
> +
> +/**
> + * of_usb_get_dr_mode - Get dual role mode for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * The function gets phy interface string from property 'dr_mode',
> + * and returns the correspondig enum usb_dr_mode
> + */
> +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
> +{
> +	const char *dr_mode;
> +	int err, i;
> +
> +	err = of_property_read_string(np, "dr_mode", &dr_mode);
> +	if (err < 0)
> +		return USB_DR_MODE_UNKNOWN;
> +
> +	for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
> +		if (!strcmp(dr_mode, usb_dr_modes[i]))
> +			return i;
> +
> +	return USB_DR_MODE_UNKNOWN;
> +}
> +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
> +#endif
> +
>  MODULE_LICENSE("GPL");
> diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
> new file mode 100644
> index 0000000..4681a20
> --- /dev/null
> +++ b/include/linux/usb/of.h
> @@ -0,0 +1,27 @@
> +/*
> + * OF helpers for usb devices.
> + *
> + * This file is released under the GPLv2
> + */
> +
> +#ifndef __LINUX_USB_OF_H
> +#define __LINUX_USB_OF_H
> +
> +#include <linux/usb/phy.h>

Hi Michael,

When I use allmodconfig to build all usb module, I meet below
error. After changing #include <linux/usb/otg.h>, below
error is disappeared.

 GEN     /home/b29397/work/code/git/linus/linux-2.6/outout/all/Makefile
 scripts/kconfig/conf --allmodconfig Kconfig
#
# configuration written to .config
#
 /home/b29397/work/code/git/linus/linux-2.6/arch/x86/Makefile:92: stack protector enabled but no compiler support
 /home/b29397/work/code/git/linus/linux-2.6/arch/x86/Makefile:107: CONFIG_X86_X32 enabled but no binutils support
   GEN     /home/b29397/work/code/git/linus/linux-2.6/outout/all/Makefile
   scripts/kconfig/conf --silentoldconfig Kconfig
   /home/b29397/work/code/git/linus/linux-2.6/arch/x86/Makefile:92: stack protector enabled but no compiler support
   /home/b29397/work/code/git/linus/linux-2.6/arch/x86/Makefile:107: CONFIG_X86_X32 enabled but no binutils support
   make[2]: Nothing to be done for `all'.
     GEN     /home/b29397/work/code/git/linus/linux-2.6/outout/all/Makefile
       CHK     include/generated/uapi/linux/version.h
       make[2]: Nothing to be done for `relocs'.
         Using /home/b29397/work/code/git/linus/linux-2.6 as source for kernel
	   CHK     include/generated/utsrelease.h
	     CALL    /home/b29397/work/code/git/linus/linux-2.6/scripts/checksyscalls.sh
	       CC [M]  drivers/usb/usb-common.o
	       In file included from /home/b29397/work/code/git/linus/linux-2.6/drivers/usb/usb-common.c:18:
	       /home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h:22: error: return type is an incomplete type
	       /home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h: In function ‘of_usb_get_dr_mode’:
	       /home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h:23: error: ‘USB_DR_MODE_UNKNOWN’ undeclared (first use in this function)
	/home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h:23: error: (Each undeclared identifier is reported only once
			/home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h:23: error: for each function it appears in.)
	/home/b29397/work/code/git/linus/linux-2.6/include/linux/usb/of.h:23: warning: ‘return’ with a value, in function returning void
	make[2]: *** [drivers/usb/usb-common.o] Error 1
	make[2]: *** Waiting for unfinished jobs....