Re: [PATCH v2 2/2] usb: dwc3: add dual role support using OTG block

2018-03-08 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
> Felipe,
>
> On 08/03/18 12:39, Felipe Balbi wrote:
>> Roger Quadros  writes:
>> 
>>> This is useful on platforms (e.g. TI AM437x) that don't
>>> have ID available on a GPIO but do have the OTG block.
>>>
>>> We can obtain the ID state via the OTG block and use it
>>> for dual-role switching.
>>>
>>> Signed-off-by: Roger Quadros 
>> 
>> patch one applied fine to testing/next. But not this one:
>
> That's because you will need this commit from v4.16-rc3
>
> c4a5153e87fd  ("usb: dwc3: core: Power-off core/PHYs on system_suspend in 
> host mode")
>
> Could you please apply that and let me know if it works?

indeed, applied fine. thanks

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v2 2/2] usb: dwc3: add dual role support using OTG block

2018-03-08 Thread Roger Quadros
Felipe,

On 08/03/18 12:39, Felipe Balbi wrote:
> Roger Quadros  writes:
> 
>> This is useful on platforms (e.g. TI AM437x) that don't
>> have ID available on a GPIO but do have the OTG block.
>>
>> We can obtain the ID state via the OTG block and use it
>> for dual-role switching.
>>
>> Signed-off-by: Roger Quadros 
> 
> patch one applied fine to testing/next. But not this one:

That's because you will need this commit from v4.16-rc3

c4a5153e87fd("usb: dwc3: core: Power-off core/PHYs on system_suspend in 
host mode")

Could you please apply that and let me know if it works?

> 
> checking file drivers/usb/dwc3/core.c
> Hunk #2 FAILED at 107.
> Hunk #3 succeeded at 122 (offset -5 lines).
> Hunk #4 succeeded at 166 (offset -3 lines).
> Hunk #5 succeeded at 365 (offset 5 lines).
> Hunk #6 succeeded at 382 (offset 5 lines).
> Hunk #7 succeeded at 1193 with fuzz 2 (offset -145 lines).
> Hunk #8 FAILED at 1383.
> 2 out of 8 hunks FAILED
> checking file drivers/usb/dwc3/core.h
> Hunk #2 succeeded at 901 (offset 33 lines).
> Hunk #3 succeeded at 1040 (offset 35 lines).
> Hunk #4 succeeded at 1316 (offset 46 lines).
> Hunk #5 succeeded at 1334 (offset 46 lines).
> Hunk #6 succeeded at 1380 (offset 46 lines).
> checking file drivers/usb/dwc3/drd.c
> 
> care to rebase?
> 

-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] usb: dwc3: add dual role support using OTG block

2018-03-08 Thread Felipe Balbi
Roger Quadros  writes:

> This is useful on platforms (e.g. TI AM437x) that don't
> have ID available on a GPIO but do have the OTG block.
>
> We can obtain the ID state via the OTG block and use it
> for dual-role switching.
>
> Signed-off-by: Roger Quadros 

patch one applied fine to testing/next. But not this one:

checking file drivers/usb/dwc3/core.c
Hunk #2 FAILED at 107.
Hunk #3 succeeded at 122 (offset -5 lines).
Hunk #4 succeeded at 166 (offset -3 lines).
Hunk #5 succeeded at 365 (offset 5 lines).
Hunk #6 succeeded at 382 (offset 5 lines).
Hunk #7 succeeded at 1193 with fuzz 2 (offset -145 lines).
Hunk #8 FAILED at 1383.
2 out of 8 hunks FAILED
checking file drivers/usb/dwc3/core.h
Hunk #2 succeeded at 901 (offset 33 lines).
Hunk #3 succeeded at 1040 (offset 35 lines).
Hunk #4 succeeded at 1316 (offset 46 lines).
Hunk #5 succeeded at 1334 (offset 46 lines).
Hunk #6 succeeded at 1380 (offset 46 lines).
checking file drivers/usb/dwc3/drd.c

care to rebase?

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v2 2/2] usb: dwc3: add dual role support using OTG block

2018-02-27 Thread Roger Quadros
This is useful on platforms (e.g. TI AM437x) that don't
have ID available on a GPIO but do have the OTG block.

We can obtain the ID state via the OTG block and use it
for dual-role switching.

Signed-off-by: Roger Quadros 
---
 drivers/usb/dwc3/core.c |  67 ++-
 drivers/usb/dwc3/core.h |  29 +++
 drivers/usb/dwc3/drd.c  | 489 ++--
 3 files changed, 557 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index df4569d..397a4d4 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -89,10 +89,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
return 0;
 }
 
-static void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
-static int dwc3_event_buffers_setup(struct dwc3 *dwc);
-
-static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
+void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 {
u32 reg;
 
@@ -110,16 +107,19 @@ static void __dwc3_set_mode(struct work_struct *work)
unsigned long flags;
int ret;
 
-   if (!dwc->desired_dr_role)
+   if (dwc->dr_mode != USB_DR_MODE_OTG)
return;
 
-   if (dwc->desired_dr_role == dwc->current_dr_role)
+   if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
+   dwc3_otg_update(dwc, 0);
+
+   if (!dwc->desired_dr_role)
return;
 
-   if (dwc->dr_mode != USB_DR_MODE_OTG)
+   if (dwc->desired_dr_role == dwc->current_dr_role)
return;
 
-   if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG)
+   if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
return;
 
switch (dwc->current_dr_role) {
@@ -130,6 +130,13 @@ static void __dwc3_set_mode(struct work_struct *work)
dwc3_gadget_exit(dwc);
dwc3_event_buffers_cleanup(dwc);
break;
+   case DWC3_GCTL_PRTCAP_OTG:
+   dwc3_otg_exit(dwc);
+   spin_lock_irqsave(>lock, flags);
+   dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE;
+   spin_unlock_irqrestore(>lock, flags);
+   dwc3_otg_update(dwc, 1);
+   break;
default:
break;
}
@@ -165,9 +172,14 @@ static void __dwc3_set_mode(struct work_struct *work)
if (ret)
dev_err(dwc->dev, "failed to initialize peripheral\n");
break;
+   case DWC3_GCTL_PRTCAP_OTG:
+   dwc3_otg_init(dwc);
+   dwc3_otg_update(dwc, 0);
+   break;
default:
break;
}
+
 }
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -351,7 +363,7 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, 
unsigned length)
  *
  * Returns 0 on success otherwise negative errno.
  */
-static int dwc3_event_buffers_setup(struct dwc3 *dwc)
+int dwc3_event_buffers_setup(struct dwc3 *dwc)
 {
struct dwc3_event_buffer*evt;
 
@@ -368,7 +380,7 @@ static int dwc3_event_buffers_setup(struct dwc3 *dwc)
return 0;
 }
 
-static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
+void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
 {
struct dwc3_event_buffer*evt;
 
@@ -1329,6 +1341,20 @@ static int dwc3_suspend_common(struct dwc3 *dwc, 
pm_message_t msg)
if (!PMSG_IS_AUTO(msg))
dwc3_core_exit(dwc);
break;
+   case DWC3_GCTL_PRTCAP_OTG:
+   /* do nothing during runtime_suspend */
+   if (PMSG_IS_AUTO(msg))
+   break;
+
+   if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
+   spin_lock_irqsave(>lock, flags);
+   dwc3_gadget_suspend(dwc);
+   spin_unlock_irqrestore(>lock, flags);
+   }
+
+   dwc3_otg_exit(dwc);
+   dwc3_core_exit(dwc);
+   break;
default:
/* do nothing */
break;
@@ -1360,6 +1386,27 @@ static int dwc3_resume_common(struct dwc3 *dwc, 
pm_message_t msg)
return ret;
}
break;
+   case DWC3_GCTL_PRTCAP_OTG:
+   /* nothing to do on runtime_resume */
+   if (PMSG_IS_AUTO(msg))
+   break;
+
+   ret = dwc3_core_init(dwc);
+   if (ret)
+   return ret;
+
+   dwc3_set_prtcap(dwc, dwc->current_dr_role);
+
+   dwc3_otg_init(dwc);
+   if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
+   dwc3_otg_host_init(dwc);
+   } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
+   spin_lock_irqsave(>lock, flags);
+   dwc3_gadget_resume(dwc);
+   spin_unlock_irqrestore(>lock, flags);
+   }
+
+   break;