Skip to content

Commit a2c2458

Browse files
pcercueigregkh
authored andcommitted
usb: musb: Add and use inline functions musb_{get,set}_state
commit 21acc656a06e912341d9db66c67b58cc7ed071e7 upstream. Instead of manipulating musb->xceiv->otg->state directly, use the newly introduced musb_get_state() and musb_set_state() inline functions. Later, these inline functions will be modified to get rid of the musb->xceiv dependency, which prevents the musb code from using the generic PHY subsystem. Signed-off-by: Paul Cercueil <[email protected]> Link: https://lore.kernel.org/r/[email protected] Stable-dep-of: 67a59f82196c ("usb: musb: fix gadget state on disconnect") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 63b7dc0 commit a2c2458

File tree

6 files changed

+71
-60
lines changed

6 files changed

+71
-60
lines changed

drivers/usb/musb/musb_core.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ int musb_set_host(struct musb *musb)
502502

503503
init_data:
504504
musb->is_active = 1;
505-
musb->xceiv->otg->state = OTG_STATE_A_IDLE;
505+
musb_set_state(musb, OTG_STATE_A_IDLE);
506506
MUSB_HST_MODE(musb);
507507

508508
return error;
@@ -549,7 +549,7 @@ int musb_set_peripheral(struct musb *musb)
549549

550550
init_data:
551551
musb->is_active = 0;
552-
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
552+
musb_set_state(musb, OTG_STATE_B_IDLE);
553553
MUSB_DEV_MODE(musb);
554554

555555
return error;
@@ -599,20 +599,20 @@ static void musb_otg_timer_func(struct timer_list *t)
599599
unsigned long flags;
600600

601601
spin_lock_irqsave(&musb->lock, flags);
602-
switch (musb->xceiv->otg->state) {
602+
switch (musb_get_state(musb)) {
603603
case OTG_STATE_B_WAIT_ACON:
604604
musb_dbg(musb,
605605
"HNP: b_wait_acon timeout; back to b_peripheral");
606606
musb_g_disconnect(musb);
607-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
607+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
608608
musb->is_active = 0;
609609
break;
610610
case OTG_STATE_A_SUSPEND:
611611
case OTG_STATE_A_WAIT_BCON:
612612
musb_dbg(musb, "HNP: %s timeout",
613613
usb_otg_state_string(musb->xceiv->otg->state));
614614
musb_platform_set_vbus(musb, 0);
615-
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
615+
musb_set_state(musb, OTG_STATE_A_WAIT_VFALL);
616616
break;
617617
default:
618618
musb_dbg(musb, "HNP: Unhandled mode %s",
@@ -633,7 +633,7 @@ void musb_hnp_stop(struct musb *musb)
633633
musb_dbg(musb, "HNP: stop from %s",
634634
usb_otg_state_string(musb->xceiv->otg->state));
635635

636-
switch (musb->xceiv->otg->state) {
636+
switch (musb_get_state(musb)) {
637637
case OTG_STATE_A_PERIPHERAL:
638638
musb_g_disconnect(musb);
639639
musb_dbg(musb, "HNP: back to %s",
@@ -643,7 +643,7 @@ void musb_hnp_stop(struct musb *musb)
643643
musb_dbg(musb, "HNP: Disabling HR");
644644
if (hcd)
645645
hcd->self.is_b_host = 0;
646-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
646+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
647647
MUSB_DEV_MODE(musb);
648648
reg = musb_readb(mbase, MUSB_POWER);
649649
reg |= MUSB_POWER_SUSPENDM;
@@ -671,22 +671,22 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
671671
usb_otg_state_string(musb->xceiv->otg->state));
672672

673673
if (devctl & MUSB_DEVCTL_HM) {
674-
switch (musb->xceiv->otg->state) {
674+
switch (musb_get_state(musb)) {
675675
case OTG_STATE_A_SUSPEND:
676676
/* remote wakeup? */
677677
musb->port1_status |=
678678
(USB_PORT_STAT_C_SUSPEND << 16)
679679
| MUSB_PORT_STAT_RESUME;
680680
musb->rh_timer = jiffies
681681
+ msecs_to_jiffies(USB_RESUME_TIMEOUT);
682-
musb->xceiv->otg->state = OTG_STATE_A_HOST;
682+
musb_set_state(musb, OTG_STATE_A_HOST);
683683
musb->is_active = 1;
684684
musb_host_resume_root_hub(musb);
685685
schedule_delayed_work(&musb->finish_resume_work,
686686
msecs_to_jiffies(USB_RESUME_TIMEOUT));
687687
break;
688688
case OTG_STATE_B_WAIT_ACON:
689-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
689+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
690690
musb->is_active = 1;
691691
MUSB_DEV_MODE(musb);
692692
break;
@@ -696,10 +696,10 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
696696
usb_otg_state_string(musb->xceiv->otg->state));
697697
}
698698
} else {
699-
switch (musb->xceiv->otg->state) {
699+
switch (musb_get_state(musb)) {
700700
case OTG_STATE_A_SUSPEND:
701701
/* possibly DISCONNECT is upcoming */
702-
musb->xceiv->otg->state = OTG_STATE_A_HOST;
702+
musb_set_state(musb, OTG_STATE_A_HOST);
703703
musb_host_resume_root_hub(musb);
704704
break;
705705
case OTG_STATE_B_WAIT_ACON:
@@ -750,7 +750,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl)
750750
*/
751751
musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
752752
musb->ep0_stage = MUSB_EP0_START;
753-
musb->xceiv->otg->state = OTG_STATE_A_IDLE;
753+
musb_set_state(musb, OTG_STATE_A_IDLE);
754754
MUSB_HST_MODE(musb);
755755
musb_platform_set_vbus(musb, 1);
756756

@@ -777,7 +777,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl)
777777
* REVISIT: do delays from lots of DEBUG_KERNEL checks
778778
* make trouble here, keeping VBUS < 4.4V ?
779779
*/
780-
switch (musb->xceiv->otg->state) {
780+
switch (musb_get_state(musb)) {
781781
case OTG_STATE_A_HOST:
782782
/* recovery is dicey once we've gotten past the
783783
* initial stages of enumeration, but if VBUS
@@ -833,7 +833,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
833833
musb_dbg(musb, "SUSPEND (%s) devctl %02x",
834834
usb_otg_state_string(musb->xceiv->otg->state), devctl);
835835

836-
switch (musb->xceiv->otg->state) {
836+
switch (musb_get_state(musb)) {
837837
case OTG_STATE_A_PERIPHERAL:
838838
/* We also come here if the cable is removed, since
839839
* this silicon doesn't report ID-no-longer-grounded.
@@ -858,7 +858,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
858858
musb_g_suspend(musb);
859859
musb->is_active = musb->g.b_hnp_enable;
860860
if (musb->is_active) {
861-
musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;
861+
musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
862862
musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
863863
mod_timer(&musb->otg_timer, jiffies
864864
+ msecs_to_jiffies(
@@ -871,7 +871,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
871871
+ msecs_to_jiffies(musb->a_wait_bcon));
872872
break;
873873
case OTG_STATE_A_HOST:
874-
musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;
874+
musb_set_state(musb, OTG_STATE_A_SUSPEND);
875875
musb->is_active = musb->hcd->self.b_hnp_enable;
876876
break;
877877
case OTG_STATE_B_HOST:
@@ -909,7 +909,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
909909
musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
910910

911911
/* indicate new connection to OTG machine */
912-
switch (musb->xceiv->otg->state) {
912+
switch (musb_get_state(musb)) {
913913
case OTG_STATE_B_PERIPHERAL:
914914
if (int_usb & MUSB_INTR_SUSPEND) {
915915
musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");
@@ -921,15 +921,15 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
921921
case OTG_STATE_B_WAIT_ACON:
922922
musb_dbg(musb, "HNP: CONNECT, now b_host");
923923
b_host:
924-
musb->xceiv->otg->state = OTG_STATE_B_HOST;
924+
musb_set_state(musb, OTG_STATE_B_HOST);
925925
if (musb->hcd)
926926
musb->hcd->self.is_b_host = 1;
927927
del_timer(&musb->otg_timer);
928928
break;
929929
default:
930930
if ((devctl & MUSB_DEVCTL_VBUS)
931931
== (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
932-
musb->xceiv->otg->state = OTG_STATE_A_HOST;
932+
musb_set_state(musb, OTG_STATE_A_HOST);
933933
if (hcd)
934934
hcd->self.is_b_host = 0;
935935
}
@@ -948,7 +948,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
948948
usb_otg_state_string(musb->xceiv->otg->state),
949949
MUSB_MODE(musb), devctl);
950950

951-
switch (musb->xceiv->otg->state) {
951+
switch (musb_get_state(musb)) {
952952
case OTG_STATE_A_HOST:
953953
case OTG_STATE_A_SUSPEND:
954954
musb_host_resume_root_hub(musb);
@@ -966,7 +966,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
966966
musb_root_disconnect(musb);
967967
if (musb->hcd)
968968
musb->hcd->self.is_b_host = 0;
969-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
969+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
970970
MUSB_DEV_MODE(musb);
971971
musb_g_disconnect(musb);
972972
break;
@@ -1006,7 +1006,7 @@ static void musb_handle_intr_reset(struct musb *musb)
10061006
} else {
10071007
musb_dbg(musb, "BUS RESET as %s",
10081008
usb_otg_state_string(musb->xceiv->otg->state));
1009-
switch (musb->xceiv->otg->state) {
1009+
switch (musb_get_state(musb)) {
10101010
case OTG_STATE_A_SUSPEND:
10111011
musb_g_reset(musb);
10121012
fallthrough;
@@ -1025,11 +1025,11 @@ static void musb_handle_intr_reset(struct musb *musb)
10251025
case OTG_STATE_B_WAIT_ACON:
10261026
musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",
10271027
usb_otg_state_string(musb->xceiv->otg->state));
1028-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
1028+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
10291029
musb_g_reset(musb);
10301030
break;
10311031
case OTG_STATE_B_IDLE:
1032-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
1032+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
10331033
fallthrough;
10341034
case OTG_STATE_B_PERIPHERAL:
10351035
musb_g_reset(musb);
@@ -1216,8 +1216,8 @@ void musb_start(struct musb *musb)
12161216
* (c) peripheral initiates, using SRP
12171217
*/
12181218
if (musb->port_mode != MUSB_HOST &&
1219-
musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&
1220-
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
1219+
musb_get_state(musb) != OTG_STATE_A_WAIT_BCON &&
1220+
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
12211221
musb->is_active = 1;
12221222
} else {
12231223
devctl |= MUSB_DEVCTL_SESSION;
@@ -1908,7 +1908,7 @@ vbus_store(struct device *dev, struct device_attribute *attr,
19081908
spin_lock_irqsave(&musb->lock, flags);
19091909
/* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
19101910
musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
1911-
if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)
1911+
if (musb_get_state(musb) == OTG_STATE_A_WAIT_BCON)
19121912
musb->is_active = 0;
19131913
musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
19141914
spin_unlock_irqrestore(&musb->lock, flags);
@@ -2089,8 +2089,8 @@ static void musb_irq_work(struct work_struct *data)
20892089

20902090
musb_pm_runtime_check_session(musb);
20912091

2092-
if (musb->xceiv->otg->state != musb->xceiv_old_state) {
2093-
musb->xceiv_old_state = musb->xceiv->otg->state;
2092+
if (musb_get_state(musb) != musb->xceiv_old_state) {
2093+
musb->xceiv_old_state = musb_get_state(musb);
20942094
sysfs_notify(&musb->controller->kobj, NULL, "mode");
20952095
}
20962096

@@ -2532,7 +2532,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
25322532
}
25332533

25342534
MUSB_DEV_MODE(musb);
2535-
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
2535+
musb_set_state(musb, OTG_STATE_B_IDLE);
25362536

25372537
switch (musb->port_mode) {
25382538
case MUSB_HOST:

drivers/usb/musb/musb_core.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,17 @@ static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum)
592592
musb->ops->clear_ep_rxintr(musb, epnum);
593593
}
594594

595+
static inline void musb_set_state(struct musb *musb,
596+
enum usb_otg_state otg_state)
597+
{
598+
musb->xceiv->otg->state = otg_state;
599+
}
600+
601+
static inline enum usb_otg_state musb_get_state(struct musb *musb)
602+
{
603+
return musb->xceiv->otg->state;
604+
}
605+
595606
/*
596607
* gets the "dr_mode" property from DT and converts it into musb_mode
597608
* if the property is not found or not recognized returns MUSB_OTG

drivers/usb/musb/musb_debugfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static int musb_softconnect_show(struct seq_file *s, void *unused)
235235
u8 reg;
236236
int connect;
237237

238-
switch (musb->xceiv->otg->state) {
238+
switch (musb_get_state(musb)) {
239239
case OTG_STATE_A_HOST:
240240
case OTG_STATE_A_WAIT_BCON:
241241
pm_runtime_get_sync(musb->controller);
@@ -275,7 +275,7 @@ static ssize_t musb_softconnect_write(struct file *file,
275275

276276
pm_runtime_get_sync(musb->controller);
277277
if (!strncmp(buf, "0", 1)) {
278-
switch (musb->xceiv->otg->state) {
278+
switch (musb_get_state(musb)) {
279279
case OTG_STATE_A_HOST:
280280
musb_root_disconnect(musb);
281281
reg = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -286,7 +286,7 @@ static ssize_t musb_softconnect_write(struct file *file,
286286
break;
287287
}
288288
} else if (!strncmp(buf, "1", 1)) {
289-
switch (musb->xceiv->otg->state) {
289+
switch (musb_get_state(musb)) {
290290
case OTG_STATE_A_WAIT_BCON:
291291
/*
292292
* musb_save_context() called in musb_runtime_suspend()

drivers/usb/musb/musb_gadget.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
15301530

15311531
spin_lock_irqsave(&musb->lock, flags);
15321532

1533-
switch (musb->xceiv->otg->state) {
1533+
switch (musb_get_state(musb)) {
15341534
case OTG_STATE_B_PERIPHERAL:
15351535
/* NOTE: OTG state machine doesn't include B_SUSPENDED;
15361536
* that's part of the standard usb 1.1 state machine, and
@@ -1792,7 +1792,7 @@ int musb_gadget_setup(struct musb *musb)
17921792
musb->g.speed = USB_SPEED_UNKNOWN;
17931793

17941794
MUSB_DEV_MODE(musb);
1795-
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
1795+
musb_set_state(musb, OTG_STATE_B_IDLE);
17961796

17971797
/* this "gadget" abstracts/virtualizes the controller */
17981798
musb->g.name = musb_driver_name;
@@ -1857,7 +1857,7 @@ static int musb_gadget_start(struct usb_gadget *g,
18571857
musb->is_active = 1;
18581858

18591859
otg_set_peripheral(otg, &musb->g);
1860-
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
1860+
musb_set_state(musb, OTG_STATE_B_IDLE);
18611861
spin_unlock_irqrestore(&musb->lock, flags);
18621862

18631863
musb_start(musb);
@@ -1902,7 +1902,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
19021902

19031903
(void) musb_gadget_vbus_draw(&musb->g, 0);
19041904

1905-
musb->xceiv->otg->state = OTG_STATE_UNDEFINED;
1905+
musb_set_state(musb, OTG_STATE_UNDEFINED);
19061906
musb_stop(musb);
19071907
otg_set_peripheral(musb->xceiv->otg, NULL);
19081908

@@ -1931,7 +1931,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
19311931
void musb_g_resume(struct musb *musb)
19321932
{
19331933
musb->is_suspended = 0;
1934-
switch (musb->xceiv->otg->state) {
1934+
switch (musb_get_state(musb)) {
19351935
case OTG_STATE_B_IDLE:
19361936
break;
19371937
case OTG_STATE_B_WAIT_ACON:
@@ -1957,10 +1957,10 @@ void musb_g_suspend(struct musb *musb)
19571957
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
19581958
musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl);
19591959

1960-
switch (musb->xceiv->otg->state) {
1960+
switch (musb_get_state(musb)) {
19611961
case OTG_STATE_B_IDLE:
19621962
if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
1963-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
1963+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
19641964
break;
19651965
case OTG_STATE_B_PERIPHERAL:
19661966
musb->is_suspended = 1;
@@ -2006,22 +2006,22 @@ void musb_g_disconnect(struct musb *musb)
20062006
spin_lock(&musb->lock);
20072007
}
20082008

2009-
switch (musb->xceiv->otg->state) {
2009+
switch (musb_get_state(musb)) {
20102010
default:
20112011
musb_dbg(musb, "Unhandled disconnect %s, setting a_idle",
20122012
usb_otg_state_string(musb->xceiv->otg->state));
2013-
musb->xceiv->otg->state = OTG_STATE_A_IDLE;
2013+
musb_set_state(musb, OTG_STATE_A_IDLE);
20142014
MUSB_HST_MODE(musb);
20152015
break;
20162016
case OTG_STATE_A_PERIPHERAL:
2017-
musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;
2017+
musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
20182018
MUSB_HST_MODE(musb);
20192019
break;
20202020
case OTG_STATE_B_WAIT_ACON:
20212021
case OTG_STATE_B_HOST:
20222022
case OTG_STATE_B_PERIPHERAL:
20232023
case OTG_STATE_B_IDLE:
2024-
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
2024+
musb_set_state(musb, OTG_STATE_B_IDLE);
20252025
break;
20262026
case OTG_STATE_B_SRP_INIT:
20272027
break;
@@ -2085,13 +2085,13 @@ __acquires(musb->lock)
20852085
* In that case, do not rely on devctl for setting
20862086
* peripheral mode.
20872087
*/
2088-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
2088+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
20892089
musb->g.is_a_peripheral = 0;
20902090
} else if (devctl & MUSB_DEVCTL_BDEVICE) {
2091-
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
2091+
musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
20922092
musb->g.is_a_peripheral = 0;
20932093
} else {
2094-
musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL;
2094+
musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
20952095
musb->g.is_a_peripheral = 1;
20962096
}
20972097

0 commit comments

Comments
 (0)