linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] musb: sunxi: Add set_mode platform function
@ 2016-05-12 18:31 Hans de Goede
  2016-05-12 18:31 ` [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus Hans de Goede
  0 siblings, 1 reply; 6+ messages in thread
From: Hans de Goede @ 2016-05-12 18:31 UTC (permalink / raw)
  To: linux-arm-kernel

Move the mode handling to the platform_set_mode callback.

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

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index fdab423..2c33d9b 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -264,15 +264,6 @@ static int sunxi_musb_init(struct musb *musb)
 	if (ret)
 		goto error_unregister_notifier;
 
-	if (musb->port_mode == MUSB_PORT_MODE_HOST) {
-		ret = phy_power_on(glue->phy);
-		if (ret)
-			goto error_phy_exit;
-		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
-		/* Stop musb work from turning vbus off again */
-		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
-	}
-
 	musb->isr = sunxi_musb_interrupt;
 
 	/* Stop the musb-core from doing runtime pm (not supported on sunxi) */
@@ -280,8 +271,6 @@ static int sunxi_musb_init(struct musb *musb)
 
 	return 0;
 
-error_phy_exit:
-	phy_exit(glue->phy);
 error_unregister_notifier:
 	if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
 		extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
@@ -323,6 +312,24 @@ static int sunxi_musb_exit(struct musb *musb)
 	return 0;
 }
 
+static int sunxi_set_mode(struct musb *musb, u8 mode)
+{
+	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+	int ret;
+
+	if (mode == MUSB_HOST) {
+		ret = phy_power_on(glue->phy);
+		if (ret)
+			return ret;
+
+		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
+		/* Stop musb work from turning vbus off again */
+		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+	}
+
+	return 0;
+}
+
 static void sunxi_musb_enable(struct musb *musb)
 {
 	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
@@ -569,6 +576,7 @@ static const struct musb_platform_ops sunxi_musb_ops = {
 	.exit		= sunxi_musb_exit,
 	.enable		= sunxi_musb_enable,
 	.disable	= sunxi_musb_disable,
+	.set_mode	= sunxi_set_mode,
 	.fifo_offset	= sunxi_musb_fifo_offset,
 	.ep_offset	= sunxi_musb_ep_offset,
 	.busctl_offset	= sunxi_musb_busctl_offset,
-- 
2.7.4

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

* [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
  2016-05-12 18:31 [PATCH 1/2] musb: sunxi: Add set_mode platform function Hans de Goede
@ 2016-05-12 18:31 ` Hans de Goede
  2016-05-12 20:21   ` Sergei Shtylyov
  2016-05-13 18:35   ` Bin Liu
  0 siblings, 2 replies; 6+ messages in thread
From: Hans de Goede @ 2016-05-12 18:31 UTC (permalink / raw)
  To: linux-arm-kernel

When the board is powering attached usb devices via the otg port
sometimes / on some devices it takes slightly too long for the VBus
detection code in phy-sun4i-usb.c to signal that VBus is high after
enabling VBus and the musb hardware signals a MUSB_INTR_VBUSERROR
interrupt.

This commit sets the otg state to A_WAIT_VRISE upon enabling Vbus
making musb_stage0_irq() ignore the first VBUSERR_RETRY_COUNT
VBUSERROR interrupts, fixing connection issues in these cases.

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

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 2c33d9b..2ee48fb 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -112,7 +112,7 @@ static void sunxi_musb_work(struct work_struct *work)
 		if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
 			set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
 			musb->xceiv->otg->default_a = 1;
-			musb->xceiv->otg->state = OTG_STATE_A_IDLE;
+			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
 			MUSB_HST_MODE(musb);
 			devctl |= MUSB_DEVCTL_SESSION;
 		} else {
@@ -145,9 +145,10 @@ static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
 {
 	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
 
-	if (is_on)
+	if (is_on) {
 		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
-	else
+		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
+	} else
 		clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
 
 	schedule_work(&glue->work);
@@ -325,6 +326,7 @@ static int sunxi_set_mode(struct musb *musb, u8 mode)
 		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
 		/* Stop musb work from turning vbus off again */
 		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
 	}
 
 	return 0;
-- 
2.7.4

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

* [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
  2016-05-12 18:31 ` [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus Hans de Goede
@ 2016-05-12 20:21   ` Sergei Shtylyov
  2016-05-13 18:35   ` Bin Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2016-05-12 20:21 UTC (permalink / raw)
  To: linux-arm-kernel

Hello.

On 05/12/2016 09:31 PM, Hans de Goede wrote:

> When the board is powering attached usb devices via the otg port
> sometimes / on some devices it takes slightly too long for the VBus

    I think it's either VBUS or Vbus, not this strange spelling.

> detection code in phy-sun4i-usb.c to signal that VBus is high after
> enabling VBus and the musb hardware signals a MUSB_INTR_VBUSERROR
> interrupt.
>
> This commit sets the otg state to A_WAIT_VRISE upon enabling Vbus
> making musb_stage0_irq() ignore the first VBUSERR_RETRY_COUNT
> VBUSERROR interrupts, fixing connection issues in these cases.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/usb/musb/sunxi.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> index 2c33d9b..2ee48fb 100644
> --- a/drivers/usb/musb/sunxi.c
> +++ b/drivers/usb/musb/sunxi.c
> @@ -112,7 +112,7 @@ static void sunxi_musb_work(struct work_struct *work)
>  		if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
>  			set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>  			musb->xceiv->otg->default_a = 1;
> -			musb->xceiv->otg->state = OTG_STATE_A_IDLE;
> +			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>  			MUSB_HST_MODE(musb);
>  			devctl |= MUSB_DEVCTL_SESSION;
>  		} else {
> @@ -145,9 +145,10 @@ static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
>  {
>  	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>
> -	if (is_on)
> +	if (is_on) {
>  		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> -	else
> +		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
> +	} else
>  		clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);

   CodingStyle, all *if* branches should use {} if one uses {}.

[...]

MBR, Sergei

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

* [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
  2016-05-12 18:31 ` [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus Hans de Goede
  2016-05-12 20:21   ` Sergei Shtylyov
@ 2016-05-13 18:35   ` Bin Liu
  2016-05-14  9:07     ` [linux-sunxi] " Hans de Goede
  1 sibling, 1 reply; 6+ messages in thread
From: Bin Liu @ 2016-05-13 18:35 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Thu, May 12, 2016 at 08:31:09PM +0200, Hans de Goede wrote:
> When the board is powering attached usb devices via the otg port
> sometimes / on some devices it takes slightly too long for the VBus
> detection code in phy-sun4i-usb.c to signal that VBus is high after
> enabling VBus and the musb hardware signals a MUSB_INTR_VBUSERROR
> interrupt.
> 
> This commit sets the otg state to A_WAIT_VRISE upon enabling Vbus
> making musb_stage0_irq() ignore the first VBUSERR_RETRY_COUNT
> VBUSERROR interrupts, fixing connection issues in these cases.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/usb/musb/sunxi.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> index 2c33d9b..2ee48fb 100644
> --- a/drivers/usb/musb/sunxi.c
> +++ b/drivers/usb/musb/sunxi.c
> @@ -112,7 +112,7 @@ static void sunxi_musb_work(struct work_struct *work)
>  		if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
>  			set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>  			musb->xceiv->otg->default_a = 1;
> -			musb->xceiv->otg->state = OTG_STATE_A_IDLE;
> +			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>  			MUSB_HST_MODE(musb);
>  			devctl |= MUSB_DEVCTL_SESSION;
>  		} else {
> @@ -145,9 +145,10 @@ static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
>  {
>  	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>  
> -	if (is_on)
> +	if (is_on) {
>  		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> -	else
> +		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;

Why this has to be set in both sunxi_musb_work() and here? Only setting
it in the work is not efficient?

Regards,
-Bin.

> +	} else
>  		clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>  
>  	schedule_work(&glue->work);
> @@ -325,6 +326,7 @@ static int sunxi_set_mode(struct musb *musb, u8 mode)
>  		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>  		/* Stop musb work from turning vbus off again */
>  		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> +		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>  	}
>  
>  	return 0;
> -- 
> 2.7.4
> 

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

* [linux-sunxi] Re: [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
  2016-05-13 18:35   ` Bin Liu
@ 2016-05-14  9:07     ` Hans de Goede
  2016-05-15  4:22       ` Bin Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Hans de Goede @ 2016-05-14  9:07 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 13-05-16 20:35, Bin Liu wrote:
> Hi,
>
> On Thu, May 12, 2016 at 08:31:09PM +0200, Hans de Goede wrote:
>> When the board is powering attached usb devices via the otg port
>> sometimes / on some devices it takes slightly too long for the VBus
>> detection code in phy-sun4i-usb.c to signal that VBus is high after
>> enabling VBus and the musb hardware signals a MUSB_INTR_VBUSERROR
>> interrupt.
>>
>> This commit sets the otg state to A_WAIT_VRISE upon enabling Vbus
>> making musb_stage0_irq() ignore the first VBUSERR_RETRY_COUNT
>> VBUSERROR interrupts, fixing connection issues in these cases.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/usb/musb/sunxi.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
>> index 2c33d9b..2ee48fb 100644
>> --- a/drivers/usb/musb/sunxi.c
>> +++ b/drivers/usb/musb/sunxi.c
>> @@ -112,7 +112,7 @@ static void sunxi_musb_work(struct work_struct *work)
>>  		if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
>>  			set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>>  			musb->xceiv->otg->default_a = 1;
>> -			musb->xceiv->otg->state = OTG_STATE_A_IDLE;
>> +			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>>  			MUSB_HST_MODE(musb);
>>  			devctl |= MUSB_DEVCTL_SESSION;
>>  		} else {
>> @@ -145,9 +145,10 @@ static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
>>  {
>>  	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>>
>> -	if (is_on)
>> +	if (is_on) {
>>  		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> -	else
>> +		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>
> Why this has to be set in both sunxi_musb_work() and here? Only setting
> it in the work is not efficient?

Different code paths, sunxi_musb_work sets it when the id pin changes
(gets pulled low), this function gets called by musb_core in response
to a session-request interrupt.

Regards,

Hans


>
> Regards,
> -Bin.
>
>> +	} else
>>  		clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>>
>>  	schedule_work(&glue->work);
>> @@ -325,6 +326,7 @@ static int sunxi_set_mode(struct musb *musb, u8 mode)
>>  		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>>  		/* Stop musb work from turning vbus off again */
>>  		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> +		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
>>  	}
>>
>>  	return 0;
>> --
>> 2.7.4
>>

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

* [linux-sunxi] Re: [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
  2016-05-14  9:07     ` [linux-sunxi] " Hans de Goede
@ 2016-05-15  4:22       ` Bin Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Bin Liu @ 2016-05-15  4:22 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Sat, May 14, 2016 at 11:07:51AM +0200, Hans de Goede wrote:
> Hi,
> 
> On 13-05-16 20:35, Bin Liu wrote:
> >Hi,
> >
> >On Thu, May 12, 2016 at 08:31:09PM +0200, Hans de Goede wrote:
> >>When the board is powering attached usb devices via the otg port
> >>sometimes / on some devices it takes slightly too long for the VBus
> >>detection code in phy-sun4i-usb.c to signal that VBus is high after
> >>enabling VBus and the musb hardware signals a MUSB_INTR_VBUSERROR
> >>interrupt.
> >>
> >>This commit sets the otg state to A_WAIT_VRISE upon enabling Vbus
> >>making musb_stage0_irq() ignore the first VBUSERR_RETRY_COUNT
> >>VBUSERROR interrupts, fixing connection issues in these cases.
> >>
> >>Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> >>---
> >> drivers/usb/musb/sunxi.c | 8 +++++---
> >> 1 file changed, 5 insertions(+), 3 deletions(-)
> >>
> >>diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> >>index 2c33d9b..2ee48fb 100644
> >>--- a/drivers/usb/musb/sunxi.c
> >>+++ b/drivers/usb/musb/sunxi.c
> >>@@ -112,7 +112,7 @@ static void sunxi_musb_work(struct work_struct *work)
> >> 		if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
> >> 			set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> >> 			musb->xceiv->otg->default_a = 1;
> >>-			musb->xceiv->otg->state = OTG_STATE_A_IDLE;
> >>+			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
> >> 			MUSB_HST_MODE(musb);
> >> 			devctl |= MUSB_DEVCTL_SESSION;
> >> 		} else {
> >>@@ -145,9 +145,10 @@ static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
> >> {
> >> 	struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> >>
> >>-	if (is_on)
> >>+	if (is_on) {
> >> 		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> >>-	else
> >>+		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
> >
> >Why this has to be set in both sunxi_musb_work() and here? Only setting
> >it in the work is not efficient?
> 
> Different code paths, sunxi_musb_work sets it when the id pin changes
> (gets pulled low), this function gets called by musb_core in response
> to a session-request interrupt.

Ok, I see what I missed. An interrupt could happen right after
_set_vbus() but before _musb_work().

Regards,
-Bin.

> 
> Regards,
> 
> Hans
> 
> 
> >
> >Regards,
> >-Bin.
> >
> >>+	} else
> >> 		clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> >>
> >> 	schedule_work(&glue->work);
> >>@@ -325,6 +326,7 @@ static int sunxi_set_mode(struct musb *musb, u8 mode)
> >> 		set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
> >> 		/* Stop musb work from turning vbus off again */
> >> 		set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> >>+		musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
> >> 	}
> >>
> >> 	return 0;
> >>--
> >>2.7.4
> >>

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

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-12 18:31 [PATCH 1/2] musb: sunxi: Add set_mode platform function Hans de Goede
2016-05-12 18:31 ` [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus Hans de Goede
2016-05-12 20:21   ` Sergei Shtylyov
2016-05-13 18:35   ` Bin Liu
2016-05-14  9:07     ` [linux-sunxi] " Hans de Goede
2016-05-15  4:22       ` Bin Liu

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