All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function
@ 2016-09-18 16:50 Hans de Goede
  2016-09-18 16:50 ` [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode Hans de Goede
  2016-09-20  4:45 ` [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Kishon Vijay Abraham I
  0 siblings, 2 replies; 8+ messages in thread
From: Hans de Goede @ 2016-09-18 16:50 UTC (permalink / raw)
  To: linux-arm-kernel

The sunxi musb has a bug where sometimes it will generate a babble
error on device disconnect instead of a disconnect irq. When this
happens the musb-controller switches from host mode to device mode
(it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
gets stuck in this state.

Clearing this requires reporting Vbus low for 200 or more ms, but
on some devices Vbus is simply always high (host-only mode, no Vbus
control). The phy-sun4i-usb code already has code to force a session
end for devices without Vbus control.

This commit adds a sun4i_usb_phy_force_session_end() function exporting
this functionality to the sunxi-musb glue, so that it can force a session
end to fixup the stuck state after a babble error.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/phy/phy-sun4i-usb.c       | 11 +++++++++++
 include/linux/phy/phy-sun4i-usb.h |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 43c0d98..06f4e11a 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -470,6 +470,17 @@ void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
 }
 EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
 
+void sun4i_usb_phy_force_session_end(struct phy *_phy)
+{
+	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
+	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+
+	data->id_det = -1;
+	data->force_session_end = true;
+	queue_delayed_work(system_wq, &data->detect, 0);
+}
+EXPORT_SYMBOL_GPL(sun4i_usb_phy_force_session_end);
+
 static const struct phy_ops sun4i_usb_phy_ops = {
 	.init		= sun4i_usb_phy_init,
 	.exit		= sun4i_usb_phy_exit,
diff --git a/include/linux/phy/phy-sun4i-usb.h b/include/linux/phy/phy-sun4i-usb.h
index 50aed92..3bb773f 100644
--- a/include/linux/phy/phy-sun4i-usb.h
+++ b/include/linux/phy/phy-sun4i-usb.h
@@ -23,4 +23,11 @@
  */
 void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled);
 
+/**
+ * sun4i_usb_force_session_end() - Force the current session to end
+ *				   by reporting VBus low for 200+ ms
+ * @phy: reference to a sun4i usb phy
+ */
+void sun4i_usb_phy_force_session_end(struct phy *phy);
+
 #endif
-- 
2.9.3

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

* [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode
  2016-09-18 16:50 [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Hans de Goede
@ 2016-09-18 16:50 ` Hans de Goede
  2016-09-22  2:33   ` Bin Liu
  2016-09-20  4:45 ` [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Kishon Vijay Abraham I
  1 sibling, 1 reply; 8+ messages in thread
From: Hans de Goede @ 2016-09-18 16:50 UTC (permalink / raw)
  To: linux-arm-kernel

The sunxi musb has a bug where sometimes it will generate a babble
error on device disconnect instead of a disconnect irq. When this
happens the musb-controller switches from host mode to device mode
(it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
gets stuck in this state.

Clearing this requires reporting Vbus low for 200 or more ms, but
on some devices Vbus is simply always high (host-only mode, no Vbus
control).

This commit calls sun4i_usb_phy_force_session_end() on babble errors
in host-mode, fixing the musb controller being stuck in this state
on systems without Vbus control; and also fixes the need to unplug
the usb-b -> usb-a cable to get out of this state on systems with
Vbus control.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/musb/sunxi.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 1408245..5079d90 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -192,8 +192,18 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
 	 * normally babble never happens treat it as disconnect.
 	 */
 	if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
+		struct sunxi_glue *glue =
+				dev_get_drvdata(musb->controller->parent);
+
+		dev_warn(musb->controller->parent, "babble, treating as disconnect\n");
+
 		musb->int_usb &= ~MUSB_INTR_BABBLE;
 		musb->int_usb |= MUSB_INTR_DISCONNECT;
+		/*
+		 * Fix the musb controller sometimes getting stuck in
+		 * bdevice state after a babble error.
+		 */
+		sun4i_usb_phy_force_session_end(glue->phy);
 	}
 
 	if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) {
-- 
2.9.3

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

* [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function
  2016-09-18 16:50 [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Hans de Goede
  2016-09-18 16:50 ` [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode Hans de Goede
@ 2016-09-20  4:45 ` Kishon Vijay Abraham I
  2016-09-21  8:05   ` Hans de Goede
  1 sibling, 1 reply; 8+ messages in thread
From: Kishon Vijay Abraham I @ 2016-09-20  4:45 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Sunday 18 September 2016 10:20 PM, Hans de Goede wrote:
> The sunxi musb has a bug where sometimes it will generate a babble
> error on device disconnect instead of a disconnect irq. When this
> happens the musb-controller switches from host mode to device mode
> (it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
> gets stuck in this state.
> 
> Clearing this requires reporting Vbus low for 200 or more ms, but
> on some devices Vbus is simply always high (host-only mode, no Vbus
> control). The phy-sun4i-usb code already has code to force a session
> end for devices without Vbus control.
> 
> This commit adds a sun4i_usb_phy_force_session_end() function exporting
> this functionality to the sunxi-musb glue, so that it can force a session
> end to fixup the stuck state after a babble error.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/phy/phy-sun4i-usb.c       | 11 +++++++++++
>  include/linux/phy/phy-sun4i-usb.h |  7 +++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index 43c0d98..06f4e11a 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -470,6 +470,17 @@ void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
>  }
>  EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
>  
> +void sun4i_usb_phy_force_session_end(struct phy *_phy)
> +{
> +	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
> +	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
> +
> +	data->id_det = -1;
> +	data->force_session_end = true;
> +	queue_delayed_work(system_wq, &data->detect, 0);
> +}
> +EXPORT_SYMBOL_GPL(sun4i_usb_phy_force_session_end);

Er.. one more export symbol :-(
> +
>  static const struct phy_ops sun4i_usb_phy_ops = {
>  	.init		= sun4i_usb_phy_init,
>  	.exit		= sun4i_usb_phy_exit,
> diff --git a/include/linux/phy/phy-sun4i-usb.h b/include/linux/phy/phy-sun4i-usb.h
> index 50aed92..3bb773f 100644
> --- a/include/linux/phy/phy-sun4i-usb.h
> +++ b/include/linux/phy/phy-sun4i-usb.h
> @@ -23,4 +23,11 @@
>   */
>  void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled);
>  
> +/**
> + * sun4i_usb_force_session_end() - Force the current session to end
> + *				   by reporting VBus low for 200+ ms
> + * @phy: reference to a sun4i usb phy
> + */
> +void sun4i_usb_phy_force_session_end(struct phy *phy);

Should we include a static inline function if sun4i phy is not defined?

Thanks
Kishon

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

* [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function
  2016-09-20  4:45 ` [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Kishon Vijay Abraham I
@ 2016-09-21  8:05   ` Hans de Goede
  2016-09-22  2:28     ` Bin Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Hans de Goede @ 2016-09-21  8:05 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 09/20/2016 07:45 AM, Kishon Vijay Abraham I wrote:
> Hi,
>
> On Sunday 18 September 2016 10:20 PM, Hans de Goede wrote:
>> The sunxi musb has a bug where sometimes it will generate a babble
>> error on device disconnect instead of a disconnect irq. When this
>> happens the musb-controller switches from host mode to device mode
>> (it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
>> gets stuck in this state.
>>
>> Clearing this requires reporting Vbus low for 200 or more ms, but
>> on some devices Vbus is simply always high (host-only mode, no Vbus
>> control). The phy-sun4i-usb code already has code to force a session
>> end for devices without Vbus control.
>>
>> This commit adds a sun4i_usb_phy_force_session_end() function exporting
>> this functionality to the sunxi-musb glue, so that it can force a session
>> end to fixup the stuck state after a babble error.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/phy/phy-sun4i-usb.c       | 11 +++++++++++
>>  include/linux/phy/phy-sun4i-usb.h |  7 +++++++
>>  2 files changed, 18 insertions(+)
>>
>> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
>> index 43c0d98..06f4e11a 100644
>> --- a/drivers/phy/phy-sun4i-usb.c
>> +++ b/drivers/phy/phy-sun4i-usb.c
>> @@ -470,6 +470,17 @@ void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
>>  }
>>  EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
>>
>> +void sun4i_usb_phy_force_session_end(struct phy *_phy)
>> +{
>> +	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
>> +	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
>> +
>> +	data->id_det = -1;
>> +	data->force_session_end = true;
>> +	queue_delayed_work(system_wq, &data->detect, 0);
>> +}
>> +EXPORT_SYMBOL_GPL(sun4i_usb_phy_force_session_end);
>
> Er.. one more export symbol :-(

Yes unfortunately we need one more to work around sunxi musb / phy bugs.

>> +
>>  static const struct phy_ops sun4i_usb_phy_ops = {
>>  	.init		= sun4i_usb_phy_init,
>>  	.exit		= sun4i_usb_phy_exit,
>> diff --git a/include/linux/phy/phy-sun4i-usb.h b/include/linux/phy/phy-sun4i-usb.h
>> index 50aed92..3bb773f 100644
>> --- a/include/linux/phy/phy-sun4i-usb.h
>> +++ b/include/linux/phy/phy-sun4i-usb.h
>> @@ -23,4 +23,11 @@
>>   */
>>  void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled);
>>
>> +/**
>> + * sun4i_usb_force_session_end() - Force the current session to end
>> + *				   by reporting VBus low for 200+ ms
>> + * @phy: reference to a sun4i usb phy
>> + */
>> +void sun4i_usb_phy_force_session_end(struct phy *phy);
>
> Should we include a static inline function if sun4i phy is not defined?

No, we're also not doing that for the already exported
sun4i_usb_phy_set_squelch_detect()

And it is not necessary since the only caller is drivers/usb/musb/sunxi.c,
and drivers/usb/musb/Kconfig has:

config USB_MUSB_SUNXI
         tristate "Allwinner (sunxi)"
         depends on PHY_SUN4I_USB

Regards,

Hans

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

* [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function
  2016-09-21  8:05   ` Hans de Goede
@ 2016-09-22  2:28     ` Bin Liu
  2016-09-22  7:31       ` Hans de Goede
  0 siblings, 1 reply; 8+ messages in thread
From: Bin Liu @ 2016-09-22  2:28 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Wed, Sep 21, 2016 at 11:05:33AM +0300, Hans de Goede wrote:
> Hi,
> 
> On 09/20/2016 07:45 AM, Kishon Vijay Abraham I wrote:
> >Hi,
> >
> >On Sunday 18 September 2016 10:20 PM, Hans de Goede wrote:
> >>The sunxi musb has a bug where sometimes it will generate a babble
> >>error on device disconnect instead of a disconnect irq. When this
> >>happens the musb-controller switches from host mode to device mode
> >>(it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
> >>gets stuck in this state.
> >>
> >>Clearing this requires reporting Vbus low for 200 or more ms, but
> >>on some devices Vbus is simply always high (host-only mode, no Vbus
> >>control). The phy-sun4i-usb code already has code to force a session
> >>end for devices without Vbus control.
> >>
> >>This commit adds a sun4i_usb_phy_force_session_end() function exporting
> >>this functionality to the sunxi-musb glue, so that it can force a session
> >>end to fixup the stuck state after a babble error.
> >>
> >>Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> >>---
> >> drivers/phy/phy-sun4i-usb.c       | 11 +++++++++++
> >> include/linux/phy/phy-sun4i-usb.h |  7 +++++++
> >> 2 files changed, 18 insertions(+)
> >>
> >>diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> >>index 43c0d98..06f4e11a 100644
> >>--- a/drivers/phy/phy-sun4i-usb.c
> >>+++ b/drivers/phy/phy-sun4i-usb.c
> >>@@ -470,6 +470,17 @@ void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
> >> }
> >> EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
> >>
> >>+void sun4i_usb_phy_force_session_end(struct phy *_phy)
> >>+{
> >>+	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
> >>+	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
> >>+
> >>+	data->id_det = -1;
> >>+	data->force_session_end = true;
> >>+	queue_delayed_work(system_wq, &data->detect, 0);
> >>+}
> >>+EXPORT_SYMBOL_GPL(sun4i_usb_phy_force_session_end);
> >
> >Er.. one more export symbol :-(
> 
> Yes unfortunately we need one more to work around sunxi musb / phy bugs.

Instead, can you somehow reuse sun4i_usb_phy_set_mode()?

Regards,
-Bin.

> 
> >>+
> >> static const struct phy_ops sun4i_usb_phy_ops = {
> >> 	.init		= sun4i_usb_phy_init,
> >> 	.exit		= sun4i_usb_phy_exit,
> >>diff --git a/include/linux/phy/phy-sun4i-usb.h b/include/linux/phy/phy-sun4i-usb.h
> >>index 50aed92..3bb773f 100644
> >>--- a/include/linux/phy/phy-sun4i-usb.h
> >>+++ b/include/linux/phy/phy-sun4i-usb.h
> >>@@ -23,4 +23,11 @@
> >>  */
> >> void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled);
> >>
> >>+/**
> >>+ * sun4i_usb_force_session_end() - Force the current session to end
> >>+ *				   by reporting VBus low for 200+ ms
> >>+ * @phy: reference to a sun4i usb phy
> >>+ */
> >>+void sun4i_usb_phy_force_session_end(struct phy *phy);
> >
> >Should we include a static inline function if sun4i phy is not defined?
> 
> No, we're also not doing that for the already exported
> sun4i_usb_phy_set_squelch_detect()
> 
> And it is not necessary since the only caller is drivers/usb/musb/sunxi.c,
> and drivers/usb/musb/Kconfig has:
> 
> config USB_MUSB_SUNXI
>         tristate "Allwinner (sunxi)"
>         depends on PHY_SUN4I_USB
> 
> Regards,
> 
> Hans

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

* [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode
  2016-09-18 16:50 ` [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode Hans de Goede
@ 2016-09-22  2:33   ` Bin Liu
  2016-09-22  8:05     ` Hans de Goede
  0 siblings, 1 reply; 8+ messages in thread
From: Bin Liu @ 2016-09-22  2:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Sun, Sep 18, 2016 at 06:50:18PM +0200, Hans de Goede wrote:
> The sunxi musb has a bug where sometimes it will generate a babble
> error on device disconnect instead of a disconnect irq. When this
> happens the musb-controller switches from host mode to device mode
> (it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
> gets stuck in this state.
> 
> Clearing this requires reporting Vbus low for 200 or more ms, but
> on some devices Vbus is simply always high (host-only mode, no Vbus
> control).
> 
> This commit calls sun4i_usb_phy_force_session_end() on babble errors
> in host-mode, fixing the musb controller being stuck in this state
> on systems without Vbus control; and also fixes the need to unplug
> the usb-b -> usb-a cable to get out of this state on systems with
> Vbus control.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/usb/musb/sunxi.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> index 1408245..5079d90 100644
> --- a/drivers/usb/musb/sunxi.c
> +++ b/drivers/usb/musb/sunxi.c
> @@ -192,8 +192,18 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
>  	 * normally babble never happens treat it as disconnect.
>  	 */
>  	if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {

musb_interrupt() handle BABBLE in host mode, and has a glue hook
musb_platform_recover() in musb_recover_from_babble().

Maybe you can use it?

> +		struct sunxi_glue *glue =
> +				dev_get_drvdata(musb->controller->parent);
> +
> +		dev_warn(musb->controller->parent, "babble, treating as disconnect\n");
> +
>  		musb->int_usb &= ~MUSB_INTR_BABBLE;
>  		musb->int_usb |= MUSB_INTR_DISCONNECT;
> +		/*
> +		 * Fix the musb controller sometimes getting stuck in
> +		 * bdevice state after a babble error.
> +		 */
> +		sun4i_usb_phy_force_session_end(glue->phy);

As I commented in PATCH 1/2, can you somehow reuse
sun4i_usb_phy_set_mode() instead?

>  	}
>  
>  	if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) {
> -- 
> 2.9.3

Regards,
-Bin.

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

* [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function
  2016-09-22  2:28     ` Bin Liu
@ 2016-09-22  7:31       ` Hans de Goede
  0 siblings, 0 replies; 8+ messages in thread
From: Hans de Goede @ 2016-09-22  7:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 09/22/2016 05:28 AM, Bin Liu wrote:
> Hi,
>
> On Wed, Sep 21, 2016 at 11:05:33AM +0300, Hans de Goede wrote:
>> Hi,
>>
>> On 09/20/2016 07:45 AM, Kishon Vijay Abraham I wrote:
>>> Hi,
>>>
>>> On Sunday 18 September 2016 10:20 PM, Hans de Goede wrote:
>>>> The sunxi musb has a bug where sometimes it will generate a babble
>>>> error on device disconnect instead of a disconnect irq. When this
>>>> happens the musb-controller switches from host mode to device mode
>>>> (it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
>>>> gets stuck in this state.
>>>>
>>>> Clearing this requires reporting Vbus low for 200 or more ms, but
>>>> on some devices Vbus is simply always high (host-only mode, no Vbus
>>>> control). The phy-sun4i-usb code already has code to force a session
>>>> end for devices without Vbus control.
>>>>
>>>> This commit adds a sun4i_usb_phy_force_session_end() function exporting
>>>> this functionality to the sunxi-musb glue, so that it can force a session
>>>> end to fixup the stuck state after a babble error.
>>>>
>>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>>> ---
>>>> drivers/phy/phy-sun4i-usb.c       | 11 +++++++++++
>>>> include/linux/phy/phy-sun4i-usb.h |  7 +++++++
>>>> 2 files changed, 18 insertions(+)
>>>>
>>>> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
>>>> index 43c0d98..06f4e11a 100644
>>>> --- a/drivers/phy/phy-sun4i-usb.c
>>>> +++ b/drivers/phy/phy-sun4i-usb.c
>>>> @@ -470,6 +470,17 @@ void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
>>>> }
>>>> EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
>>>>
>>>> +void sun4i_usb_phy_force_session_end(struct phy *_phy)
>>>> +{
>>>> +	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
>>>> +	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
>>>> +
>>>> +	data->id_det = -1;
>>>> +	data->force_session_end = true;
>>>> +	queue_delayed_work(system_wq, &data->detect, 0);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(sun4i_usb_phy_force_session_end);
>>>
>>> Er.. one more export symbol :-(
>>
>> Yes unfortunately we need one more to work around sunxi musb / phy bugs.
>
> Instead, can you somehow reuse sun4i_usb_phy_set_mode()?

That was my first thought too, and I looked into this, but it did not
work out.

Regards,

Hans

>
> Regards,
> -Bin.
>
>>
>>>> +
>>>> static const struct phy_ops sun4i_usb_phy_ops = {
>>>> 	.init		= sun4i_usb_phy_init,
>>>> 	.exit		= sun4i_usb_phy_exit,
>>>> diff --git a/include/linux/phy/phy-sun4i-usb.h b/include/linux/phy/phy-sun4i-usb.h
>>>> index 50aed92..3bb773f 100644
>>>> --- a/include/linux/phy/phy-sun4i-usb.h
>>>> +++ b/include/linux/phy/phy-sun4i-usb.h
>>>> @@ -23,4 +23,11 @@
>>>>  */
>>>> void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled);
>>>>
>>>> +/**
>>>> + * sun4i_usb_force_session_end() - Force the current session to end
>>>> + *				   by reporting VBus low for 200+ ms
>>>> + * @phy: reference to a sun4i usb phy
>>>> + */
>>>> +void sun4i_usb_phy_force_session_end(struct phy *phy);
>>>
>>> Should we include a static inline function if sun4i phy is not defined?
>>
>> No, we're also not doing that for the already exported
>> sun4i_usb_phy_set_squelch_detect()
>>
>> And it is not necessary since the only caller is drivers/usb/musb/sunxi.c,
>> and drivers/usb/musb/Kconfig has:
>>
>> config USB_MUSB_SUNXI
>>         tristate "Allwinner (sunxi)"
>>         depends on PHY_SUN4I_USB
>>
>> Regards,
>>
>> Hans

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

* [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode
  2016-09-22  2:33   ` Bin Liu
@ 2016-09-22  8:05     ` Hans de Goede
  0 siblings, 0 replies; 8+ messages in thread
From: Hans de Goede @ 2016-09-22  8:05 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 09/22/2016 05:33 AM, Bin Liu wrote:
> Hi,
>
> On Sun, Sep 18, 2016 at 06:50:18PM +0200, Hans de Goede wrote:
>> The sunxi musb has a bug where sometimes it will generate a babble
>> error on device disconnect instead of a disconnect irq. When this
>> happens the musb-controller switches from host mode to device mode
>> (it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
>> gets stuck in this state.
>>
>> Clearing this requires reporting Vbus low for 200 or more ms, but
>> on some devices Vbus is simply always high (host-only mode, no Vbus
>> control).
>>
>> This commit calls sun4i_usb_phy_force_session_end() on babble errors
>> in host-mode, fixing the musb controller being stuck in this state
>> on systems without Vbus control; and also fixes the need to unplug
>> the usb-b -> usb-a cable to get out of this state on systems with
>> Vbus control.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/usb/musb/sunxi.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
>> index 1408245..5079d90 100644
>> --- a/drivers/usb/musb/sunxi.c
>> +++ b/drivers/usb/musb/sunxi.c
>> @@ -192,8 +192,18 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
>>  	 * normally babble never happens treat it as disconnect.
>>  	 */
>>  	if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
>
> musb_interrupt() handle BABBLE in host mode, and has a glue hook
> musb_platform_recover() in musb_recover_from_babble().
>
> Maybe you can use it?

Ah yes, I looked at this at the past, but that was before the babble
recover rework by Felipe Balbi which got commited on 2015-03-10.

With this rework the sunxi code should indeed be able to use the core
recovery, and we can use the musb_platform_recover() to force a
session end.

And thinking more about you're other remark, I do think I can
actually modify the sun4i phy_set_mode callback so that it can
be used for this.

I'll post a v2 with these changes soon-ish.

Regards,

Hans


>> +		struct sunxi_glue *glue =
>> +				dev_get_drvdata(musb->controller->parent);
>> +
>> +		dev_warn(musb->controller->parent, "babble, treating as disconnect\n");
>> +
>>  		musb->int_usb &= ~MUSB_INTR_BABBLE;
>>  		musb->int_usb |= MUSB_INTR_DISCONNECT;
>> +		/*
>> +		 * Fix the musb controller sometimes getting stuck in
>> +		 * bdevice state after a babble error.
>> +		 */
>> +		sun4i_usb_phy_force_session_end(glue->phy);
>
> As I commented in PATCH 1/2, can you somehow reuse
> sun4i_usb_phy_set_mode() instead?
>
>>  	}
>>
>>  	if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) {
>> --
>> 2.9.3
>
> Regards,
> -Bin.
>

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

end of thread, other threads:[~2016-09-22  8:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-18 16:50 [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Hans de Goede
2016-09-18 16:50 ` [PATCH 2/2] musb: sunxi: Force session end on babble errors in host-mode Hans de Goede
2016-09-22  2:33   ` Bin Liu
2016-09-22  8:05     ` Hans de Goede
2016-09-20  4:45 ` [PATCH 1/2] phy-sun4i-usb: Add sun4i_usb_phy_force_session_end() function Kishon Vijay Abraham I
2016-09-21  8:05   ` Hans de Goede
2016-09-22  2:28     ` Bin Liu
2016-09-22  7:31       ` Hans de Goede

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.