musb: sunxi: Add set_mode platform function
PATCH 1/2 musb: sunxi: Add set_mode platform function
Move the mode handling to the platform_set_mode callback.
--- drivers/usb/musb/sunxi.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/usb/musb/sunxi.c +19 -11
@@ -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,
Signature · 1 line
2.7.4
PATCH 2/2 musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
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.
--- drivers/usb/musb/sunxi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/usb/musb/sunxi.c +5 -3
@@ -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 ;
Signature · 1 line
2.7.4
PATCH 2/2 musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
Hello.
Quoted 2 lines · Hans de Goede
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.
Quoted 27 lines
detection code in
phy-sun4i-usb.cto signal that VBus is high after enabling VBus and the musb hardware signals aMUSB_INTR_VBUSERRORinterrupt.This commit sets the otg state to
A_WAIT_VRISEupon enabling Vbus makingmusb_stage0_irq()ignore the firstVBUSERR_RETRY_COUNTVBUSERROR interrupts, fixing connection issues in these cases.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/musb/sunxi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/usb/musb/sunxi.c +1
-1@@ -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 {
drivers/usb/musb/sunxi.c static void sunxi_musb_set_vbus(struct musb *musb, int is_on) · line 152
Quoted 10 lines
drivers/usb/musb/sunxi.c +3
-2@@ -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
Bin Liu
maintainerPATCH 2/2 musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
In reply to Hans de GoedeHi,
Quoted 29 lines · Hans de Goede
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.cto signal that VBus is high after enabling VBus and the musb hardware signals aMUSB_INTR_VBUSERRORinterrupt.This commit sets the otg state to
A_WAIT_VRISEupon enabling Vbus makingmusb_stage0_irq()ignore the firstVBUSERR_RETRY_COUNTVBUSERROR interrupts, fixing connection issues in these cases.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/musb/sunxi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/usb/musb/sunxi.c +1
-1@@ -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 {
drivers/usb/musb/sunxi.c static void sunxi_musb_set_vbus(struct musb *musb, int is_on) · line 150
Quoted 8 lines
drivers/usb/musb/sunxi.c +2
-2@@ -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.
Quoted 15 lines
drivers/usb/musb/sunxi.c +2
-0+ }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 ;Signature · 1 line
2.7.4
[linux-sunxi] Re: [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
Hi,
Quoted 35 lines · Bin Liu
Hi,
Quoted 32 lines · Hans de Goede
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.cto signal that VBus is high after enabling VBus and the musb hardware signals aMUSB_INTR_VBUSERRORinterrupt.This commit sets the otg state to
A_WAIT_VRISEupon enabling Vbus makingmusb_stage0_irq()ignore the firstVBUSERR_RETRY_COUNTVBUSERROR interrupts, fixing connection issues in these cases.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/musb/sunxi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/usb/musb/sunxi.c +1
-1@@ -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);
Quoted 8 lines
drivers/usb/musb/sunxi.c static void sunxi_musb_set_vbus(struct musb *musb, int is_on) · line 150
Quoted 5 lines
drivers/usb/musb/sunxi.c +2
-2-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
Quoted 19 lines
Regards,
-Bin.Quoted 15 lines
drivers/usb/musb/sunxi.c +2
-1+ }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
Bin Liu
maintainer[linux-sunxi] Re: [PATCH 2/2] musb: sunxi: Set state to A_WAIT_VRISE when enabling VBus
Hi,
Quoted 47 lines · Hans de Goede
Hi,
Quoted 35 lines · Bin Liu
Hi,
Quoted 32 lines · Hans de Goede
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.cto signal that VBus is high after enabling VBus and the musb hardware signals aMUSB_INTR_VBUSERRORinterrupt.This commit sets the otg state to
A_WAIT_VRISEupon enabling Vbus makingmusb_stage0_irq()ignore the firstVBUSERR_RETRY_COUNTVBUSERROR interrupts, fixing connection issues in these cases.Signed-off-by Hans de Goede <[email protected]>---
drivers/usb/musb/sunxi.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/usb/musb/sunxi.c +1
-1@@ -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);Quoted 8 lines
drivers/usb/musb/sunxi.c static void sunxi_musb_set_vbus(struct musb *musb, int is_on) · line 150
Quoted 5 lines
drivers/usb/musb/sunxi.c +2
-2-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?
Quoted 3 lines
Different code paths,
sunxi_musb_worksets it when the id pin changes (gets pulled low), this function gets called bymusb_corein 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.
Quoted 25 lines
Regards,
Hans
Quoted 19 lines
Regards,
-Bin.Quoted 15 lines
drivers/usb/musb/sunxi.c +2
-1+ }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