提交 21acc656 编写于 作者: P Paul Cercueil 提交者: Greg Kroah-Hartman

usb: musb: Add and use inline functions musb_{get,set}_state

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: NPaul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20221026182657.146630-2-paul@crapouillou.netSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 1fac1c4d
...@@ -502,7 +502,7 @@ int musb_set_host(struct musb *musb) ...@@ -502,7 +502,7 @@ int musb_set_host(struct musb *musb)
init_data: init_data:
musb->is_active = 1; musb->is_active = 1;
musb->xceiv->otg->state = OTG_STATE_A_IDLE; musb_set_state(musb, OTG_STATE_A_IDLE);
MUSB_HST_MODE(musb); MUSB_HST_MODE(musb);
return error; return error;
...@@ -549,7 +549,7 @@ int musb_set_peripheral(struct musb *musb) ...@@ -549,7 +549,7 @@ int musb_set_peripheral(struct musb *musb)
init_data: init_data:
musb->is_active = 0; musb->is_active = 0;
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
return error; return error;
...@@ -599,12 +599,12 @@ static void musb_otg_timer_func(struct timer_list *t) ...@@ -599,12 +599,12 @@ static void musb_otg_timer_func(struct timer_list *t)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&musb->lock, flags); spin_lock_irqsave(&musb->lock, flags);
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
musb_dbg(musb, musb_dbg(musb,
"HNP: b_wait_acon timeout; back to b_peripheral"); "HNP: b_wait_acon timeout; back to b_peripheral");
musb_g_disconnect(musb); musb_g_disconnect(musb);
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
musb->is_active = 0; musb->is_active = 0;
break; break;
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
...@@ -612,7 +612,7 @@ static void musb_otg_timer_func(struct timer_list *t) ...@@ -612,7 +612,7 @@ static void musb_otg_timer_func(struct timer_list *t)
musb_dbg(musb, "HNP: %s timeout", musb_dbg(musb, "HNP: %s timeout",
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
musb_platform_set_vbus(musb, 0); musb_platform_set_vbus(musb, 0);
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; musb_set_state(musb, OTG_STATE_A_WAIT_VFALL);
break; break;
default: default:
musb_dbg(musb, "HNP: Unhandled mode %s", musb_dbg(musb, "HNP: Unhandled mode %s",
...@@ -633,7 +633,7 @@ void musb_hnp_stop(struct musb *musb) ...@@ -633,7 +633,7 @@ void musb_hnp_stop(struct musb *musb)
musb_dbg(musb, "HNP: stop from %s", musb_dbg(musb, "HNP: stop from %s",
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_PERIPHERAL: case OTG_STATE_A_PERIPHERAL:
musb_g_disconnect(musb); musb_g_disconnect(musb);
musb_dbg(musb, "HNP: back to %s", musb_dbg(musb, "HNP: back to %s",
...@@ -643,7 +643,7 @@ void musb_hnp_stop(struct musb *musb) ...@@ -643,7 +643,7 @@ void musb_hnp_stop(struct musb *musb)
musb_dbg(musb, "HNP: Disabling HR"); musb_dbg(musb, "HNP: Disabling HR");
if (hcd) if (hcd)
hcd->self.is_b_host = 0; hcd->self.is_b_host = 0;
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
reg = musb_readb(mbase, MUSB_POWER); reg = musb_readb(mbase, MUSB_POWER);
reg |= MUSB_POWER_SUSPENDM; reg |= MUSB_POWER_SUSPENDM;
...@@ -671,7 +671,7 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) ...@@ -671,7 +671,7 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
if (devctl & MUSB_DEVCTL_HM) { if (devctl & MUSB_DEVCTL_HM) {
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
/* remote wakeup? */ /* remote wakeup? */
musb->port1_status |= musb->port1_status |=
...@@ -679,14 +679,14 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) ...@@ -679,14 +679,14 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
| MUSB_PORT_STAT_RESUME; | MUSB_PORT_STAT_RESUME;
musb->rh_timer = jiffies musb->rh_timer = jiffies
+ msecs_to_jiffies(USB_RESUME_TIMEOUT); + msecs_to_jiffies(USB_RESUME_TIMEOUT);
musb->xceiv->otg->state = OTG_STATE_A_HOST; musb_set_state(musb, OTG_STATE_A_HOST);
musb->is_active = 1; musb->is_active = 1;
musb_host_resume_root_hub(musb); musb_host_resume_root_hub(musb);
schedule_delayed_work(&musb->finish_resume_work, schedule_delayed_work(&musb->finish_resume_work,
msecs_to_jiffies(USB_RESUME_TIMEOUT)); msecs_to_jiffies(USB_RESUME_TIMEOUT));
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
musb->is_active = 1; musb->is_active = 1;
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
break; break;
...@@ -696,10 +696,10 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) ...@@ -696,10 +696,10 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
} }
} else { } else {
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
/* possibly DISCONNECT is upcoming */ /* possibly DISCONNECT is upcoming */
musb->xceiv->otg->state = OTG_STATE_A_HOST; musb_set_state(musb, OTG_STATE_A_HOST);
musb_host_resume_root_hub(musb); musb_host_resume_root_hub(musb);
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
...@@ -750,7 +750,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl) ...@@ -750,7 +750,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl)
*/ */
musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
musb->ep0_stage = MUSB_EP0_START; musb->ep0_stage = MUSB_EP0_START;
musb->xceiv->otg->state = OTG_STATE_A_IDLE; musb_set_state(musb, OTG_STATE_A_IDLE);
MUSB_HST_MODE(musb); MUSB_HST_MODE(musb);
musb_platform_set_vbus(musb, 1); musb_platform_set_vbus(musb, 1);
...@@ -777,7 +777,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) ...@@ -777,7 +777,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl)
* REVISIT: do delays from lots of DEBUG_KERNEL checks * REVISIT: do delays from lots of DEBUG_KERNEL checks
* make trouble here, keeping VBUS < 4.4V ? * make trouble here, keeping VBUS < 4.4V ?
*/ */
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
/* recovery is dicey once we've gotten past the /* recovery is dicey once we've gotten past the
* initial stages of enumeration, but if VBUS * initial stages of enumeration, but if VBUS
...@@ -833,7 +833,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) ...@@ -833,7 +833,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
musb_dbg(musb, "SUSPEND (%s) devctl %02x", musb_dbg(musb, "SUSPEND (%s) devctl %02x",
usb_otg_state_string(musb->xceiv->otg->state), devctl); usb_otg_state_string(musb->xceiv->otg->state), devctl);
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_PERIPHERAL: case OTG_STATE_A_PERIPHERAL:
/* We also come here if the cable is removed, since /* We also come here if the cable is removed, since
* this silicon doesn't report ID-no-longer-grounded. * this silicon doesn't report ID-no-longer-grounded.
...@@ -858,7 +858,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) ...@@ -858,7 +858,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
musb_g_suspend(musb); musb_g_suspend(musb);
musb->is_active = musb->g.b_hnp_enable; musb->is_active = musb->g.b_hnp_enable;
if (musb->is_active) { if (musb->is_active) {
musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
musb_dbg(musb, "HNP: Setting timer for b_ase0_brst"); musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
mod_timer(&musb->otg_timer, jiffies mod_timer(&musb->otg_timer, jiffies
+ msecs_to_jiffies( + msecs_to_jiffies(
...@@ -871,7 +871,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) ...@@ -871,7 +871,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
+ msecs_to_jiffies(musb->a_wait_bcon)); + msecs_to_jiffies(musb->a_wait_bcon));
break; break;
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; musb_set_state(musb, OTG_STATE_A_SUSPEND);
musb->is_active = musb->hcd->self.b_hnp_enable; musb->is_active = musb->hcd->self.b_hnp_enable;
break; break;
case OTG_STATE_B_HOST: case OTG_STATE_B_HOST:
...@@ -909,7 +909,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) ...@@ -909,7 +909,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
musb->port1_status |= USB_PORT_STAT_LOW_SPEED; musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
/* indicate new connection to OTG machine */ /* indicate new connection to OTG machine */
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
if (int_usb & MUSB_INTR_SUSPEND) { if (int_usb & MUSB_INTR_SUSPEND) {
musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host"); musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");
...@@ -921,7 +921,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) ...@@ -921,7 +921,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
musb_dbg(musb, "HNP: CONNECT, now b_host"); musb_dbg(musb, "HNP: CONNECT, now b_host");
b_host: b_host:
musb->xceiv->otg->state = OTG_STATE_B_HOST; musb_set_state(musb, OTG_STATE_B_HOST);
if (musb->hcd) if (musb->hcd)
musb->hcd->self.is_b_host = 1; musb->hcd->self.is_b_host = 1;
del_timer(&musb->otg_timer); del_timer(&musb->otg_timer);
...@@ -929,7 +929,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) ...@@ -929,7 +929,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
default: default:
if ((devctl & MUSB_DEVCTL_VBUS) if ((devctl & MUSB_DEVCTL_VBUS)
== (3 << MUSB_DEVCTL_VBUS_SHIFT)) { == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
musb->xceiv->otg->state = OTG_STATE_A_HOST; musb_set_state(musb, OTG_STATE_A_HOST);
if (hcd) if (hcd)
hcd->self.is_b_host = 0; hcd->self.is_b_host = 0;
} }
...@@ -948,7 +948,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) ...@@ -948,7 +948,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
usb_otg_state_string(musb->xceiv->otg->state), usb_otg_state_string(musb->xceiv->otg->state),
MUSB_MODE(musb), devctl); MUSB_MODE(musb), devctl);
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
musb_host_resume_root_hub(musb); musb_host_resume_root_hub(musb);
...@@ -966,7 +966,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) ...@@ -966,7 +966,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
musb_root_disconnect(musb); musb_root_disconnect(musb);
if (musb->hcd) if (musb->hcd)
musb->hcd->self.is_b_host = 0; musb->hcd->self.is_b_host = 0;
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
musb_g_disconnect(musb); musb_g_disconnect(musb);
break; break;
...@@ -1006,7 +1006,7 @@ static void musb_handle_intr_reset(struct musb *musb) ...@@ -1006,7 +1006,7 @@ static void musb_handle_intr_reset(struct musb *musb)
} else { } else {
musb_dbg(musb, "BUS RESET as %s", musb_dbg(musb, "BUS RESET as %s",
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
musb_g_reset(musb); musb_g_reset(musb);
fallthrough; fallthrough;
...@@ -1025,11 +1025,11 @@ static void musb_handle_intr_reset(struct musb *musb) ...@@ -1025,11 +1025,11 @@ static void musb_handle_intr_reset(struct musb *musb)
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
musb_dbg(musb, "HNP: RESET (%s), to b_peripheral", musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
musb_g_reset(musb); musb_g_reset(musb);
break; break;
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
fallthrough; fallthrough;
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
musb_g_reset(musb); musb_g_reset(musb);
...@@ -1216,7 +1216,7 @@ void musb_start(struct musb *musb) ...@@ -1216,7 +1216,7 @@ void musb_start(struct musb *musb)
* (c) peripheral initiates, using SRP * (c) peripheral initiates, using SRP
*/ */
if (musb->port_mode != MUSB_HOST && if (musb->port_mode != MUSB_HOST &&
musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON && musb_get_state(musb) != OTG_STATE_A_WAIT_BCON &&
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) { (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
musb->is_active = 1; musb->is_active = 1;
} else { } else {
...@@ -1908,7 +1908,7 @@ vbus_store(struct device *dev, struct device_attribute *attr, ...@@ -1908,7 +1908,7 @@ vbus_store(struct device *dev, struct device_attribute *attr,
spin_lock_irqsave(&musb->lock, flags); spin_lock_irqsave(&musb->lock, flags);
/* force T(a_wait_bcon) to be zero/unlimited *OR* valid */ /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ; musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON) if (musb_get_state(musb) == OTG_STATE_A_WAIT_BCON)
musb->is_active = 0; musb->is_active = 0;
musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val)); musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
spin_unlock_irqrestore(&musb->lock, flags); spin_unlock_irqrestore(&musb->lock, flags);
...@@ -2089,8 +2089,8 @@ static void musb_irq_work(struct work_struct *data) ...@@ -2089,8 +2089,8 @@ static void musb_irq_work(struct work_struct *data)
musb_pm_runtime_check_session(musb); musb_pm_runtime_check_session(musb);
if (musb->xceiv->otg->state != musb->xceiv_old_state) { if (musb_get_state(musb) != musb->xceiv_old_state) {
musb->xceiv_old_state = musb->xceiv->otg->state; musb->xceiv_old_state = musb_get_state(musb);
sysfs_notify(&musb->controller->kobj, NULL, "mode"); sysfs_notify(&musb->controller->kobj, NULL, "mode");
} }
...@@ -2532,7 +2532,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) ...@@ -2532,7 +2532,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
} }
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
switch (musb->port_mode) { switch (musb->port_mode) {
case MUSB_HOST: case MUSB_HOST:
......
...@@ -592,6 +592,17 @@ static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum) ...@@ -592,6 +592,17 @@ static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum)
musb->ops->clear_ep_rxintr(musb, epnum); musb->ops->clear_ep_rxintr(musb, epnum);
} }
static inline void musb_set_state(struct musb *musb,
enum usb_otg_state otg_state)
{
musb->xceiv->otg->state = otg_state;
}
static inline enum usb_otg_state musb_get_state(struct musb *musb)
{
return musb->xceiv->otg->state;
}
/* /*
* gets the "dr_mode" property from DT and converts it into musb_mode * gets the "dr_mode" property from DT and converts it into musb_mode
* if the property is not found or not recognized returns MUSB_OTG * if the property is not found or not recognized returns MUSB_OTG
......
...@@ -235,7 +235,7 @@ static int musb_softconnect_show(struct seq_file *s, void *unused) ...@@ -235,7 +235,7 @@ static int musb_softconnect_show(struct seq_file *s, void *unused)
u8 reg; u8 reg;
int connect; int connect;
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
case OTG_STATE_A_WAIT_BCON: case OTG_STATE_A_WAIT_BCON:
pm_runtime_get_sync(musb->controller); pm_runtime_get_sync(musb->controller);
...@@ -275,7 +275,7 @@ static ssize_t musb_softconnect_write(struct file *file, ...@@ -275,7 +275,7 @@ static ssize_t musb_softconnect_write(struct file *file,
pm_runtime_get_sync(musb->controller); pm_runtime_get_sync(musb->controller);
if (!strncmp(buf, "0", 1)) { if (!strncmp(buf, "0", 1)) {
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
musb_root_disconnect(musb); musb_root_disconnect(musb);
reg = musb_readb(musb->mregs, MUSB_DEVCTL); reg = musb_readb(musb->mregs, MUSB_DEVCTL);
...@@ -286,7 +286,7 @@ static ssize_t musb_softconnect_write(struct file *file, ...@@ -286,7 +286,7 @@ static ssize_t musb_softconnect_write(struct file *file,
break; break;
} }
} else if (!strncmp(buf, "1", 1)) { } else if (!strncmp(buf, "1", 1)) {
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_WAIT_BCON: case OTG_STATE_A_WAIT_BCON:
/* /*
* musb_save_context() called in musb_runtime_suspend() * musb_save_context() called in musb_runtime_suspend()
......
...@@ -1523,7 +1523,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) ...@@ -1523,7 +1523,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
spin_lock_irqsave(&musb->lock, flags); spin_lock_irqsave(&musb->lock, flags);
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
/* NOTE: OTG state machine doesn't include B_SUSPENDED; /* NOTE: OTG state machine doesn't include B_SUSPENDED;
* that's part of the standard usb 1.1 state machine, and * that's part of the standard usb 1.1 state machine, and
...@@ -1787,7 +1787,7 @@ int musb_gadget_setup(struct musb *musb) ...@@ -1787,7 +1787,7 @@ int musb_gadget_setup(struct musb *musb)
musb->g.speed = USB_SPEED_UNKNOWN; musb->g.speed = USB_SPEED_UNKNOWN;
MUSB_DEV_MODE(musb); MUSB_DEV_MODE(musb);
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
/* this "gadget" abstracts/virtualizes the controller */ /* this "gadget" abstracts/virtualizes the controller */
musb->g.name = musb_driver_name; musb->g.name = musb_driver_name;
...@@ -1852,7 +1852,7 @@ static int musb_gadget_start(struct usb_gadget *g, ...@@ -1852,7 +1852,7 @@ static int musb_gadget_start(struct usb_gadget *g,
musb->is_active = 1; musb->is_active = 1;
otg_set_peripheral(otg, &musb->g); otg_set_peripheral(otg, &musb->g);
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
spin_unlock_irqrestore(&musb->lock, flags); spin_unlock_irqrestore(&musb->lock, flags);
musb_start(musb); musb_start(musb);
...@@ -1897,7 +1897,7 @@ static int musb_gadget_stop(struct usb_gadget *g) ...@@ -1897,7 +1897,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
(void) musb_gadget_vbus_draw(&musb->g, 0); (void) musb_gadget_vbus_draw(&musb->g, 0);
musb->xceiv->otg->state = OTG_STATE_UNDEFINED; musb_set_state(musb, OTG_STATE_UNDEFINED);
musb_stop(musb); musb_stop(musb);
otg_set_peripheral(musb->xceiv->otg, NULL); otg_set_peripheral(musb->xceiv->otg, NULL);
...@@ -1926,7 +1926,7 @@ static int musb_gadget_stop(struct usb_gadget *g) ...@@ -1926,7 +1926,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
void musb_g_resume(struct musb *musb) void musb_g_resume(struct musb *musb)
{ {
musb->is_suspended = 0; musb->is_suspended = 0;
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
...@@ -1952,10 +1952,10 @@ void musb_g_suspend(struct musb *musb) ...@@ -1952,10 +1952,10 @@ void musb_g_suspend(struct musb *musb)
devctl = musb_readb(musb->mregs, MUSB_DEVCTL); devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl); musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl);
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
break; break;
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
musb->is_suspended = 1; musb->is_suspended = 1;
...@@ -2001,22 +2001,22 @@ void musb_g_disconnect(struct musb *musb) ...@@ -2001,22 +2001,22 @@ void musb_g_disconnect(struct musb *musb)
spin_lock(&musb->lock); spin_lock(&musb->lock);
} }
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
default: default:
musb_dbg(musb, "Unhandled disconnect %s, setting a_idle", musb_dbg(musb, "Unhandled disconnect %s, setting a_idle",
usb_otg_state_string(musb->xceiv->otg->state)); usb_otg_state_string(musb->xceiv->otg->state));
musb->xceiv->otg->state = OTG_STATE_A_IDLE; musb_set_state(musb, OTG_STATE_A_IDLE);
MUSB_HST_MODE(musb); MUSB_HST_MODE(musb);
break; break;
case OTG_STATE_A_PERIPHERAL: case OTG_STATE_A_PERIPHERAL:
musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
MUSB_HST_MODE(musb); MUSB_HST_MODE(musb);
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
case OTG_STATE_B_HOST: case OTG_STATE_B_HOST:
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
break; break;
case OTG_STATE_B_SRP_INIT: case OTG_STATE_B_SRP_INIT:
break; break;
...@@ -2080,13 +2080,13 @@ __acquires(musb->lock) ...@@ -2080,13 +2080,13 @@ __acquires(musb->lock)
* In that case, do not rely on devctl for setting * In that case, do not rely on devctl for setting
* peripheral mode. * peripheral mode.
*/ */
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
musb->g.is_a_peripheral = 0; musb->g.is_a_peripheral = 0;
} else if (devctl & MUSB_DEVCTL_BDEVICE) { } else if (devctl & MUSB_DEVCTL_BDEVICE) {
musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
musb->g.is_a_peripheral = 0; musb->g.is_a_peripheral = 0;
} else { } else {
musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
musb->g.is_a_peripheral = 1; musb->g.is_a_peripheral = 1;
} }
......
...@@ -2501,7 +2501,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) ...@@ -2501,7 +2501,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
if (!is_host_active(musb)) if (!is_host_active(musb))
return 0; return 0;
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
return 0; return 0;
case OTG_STATE_A_WAIT_VRISE: case OTG_STATE_A_WAIT_VRISE:
...@@ -2511,7 +2511,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) ...@@ -2511,7 +2511,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
*/ */
devctl = musb_readb(musb->mregs, MUSB_DEVCTL); devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
break; break;
default: default:
break; break;
...@@ -2720,7 +2720,7 @@ int musb_host_setup(struct musb *musb, int power_budget) ...@@ -2720,7 +2720,7 @@ int musb_host_setup(struct musb *musb, int power_budget)
if (musb->port_mode == MUSB_HOST) { if (musb->port_mode == MUSB_HOST) {
MUSB_HST_MODE(musb); MUSB_HST_MODE(musb);
musb->xceiv->otg->state = OTG_STATE_A_IDLE; musb_set_state(musb, OTG_STATE_A_IDLE);
} }
otg_set_host(musb->xceiv->otg, &hcd->self); otg_set_host(musb->xceiv->otg, &hcd->self);
/* don't support otg protocols */ /* don't support otg protocols */
......
...@@ -43,7 +43,7 @@ void musb_host_finish_resume(struct work_struct *work) ...@@ -43,7 +43,7 @@ void musb_host_finish_resume(struct work_struct *work)
musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
usb_hcd_poll_rh_status(musb->hcd); usb_hcd_poll_rh_status(musb->hcd);
/* NOTE: it might really be A_WAIT_BCON ... */ /* NOTE: it might really be A_WAIT_BCON ... */
musb->xceiv->otg->state = OTG_STATE_A_HOST; musb_set_state(musb, OTG_STATE_A_HOST);
spin_unlock_irqrestore(&musb->lock, flags); spin_unlock_irqrestore(&musb->lock, flags);
} }
...@@ -85,9 +85,9 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) ...@@ -85,9 +85,9 @@ int musb_port_suspend(struct musb *musb, bool do_suspend)
musb_dbg(musb, "Root port suspended, power %02x", power); musb_dbg(musb, "Root port suspended, power %02x", power);
musb->port1_status |= USB_PORT_STAT_SUSPEND; musb->port1_status |= USB_PORT_STAT_SUSPEND;
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; musb_set_state(musb, OTG_STATE_A_SUSPEND);
musb->is_active = otg->host->b_hnp_enable; musb->is_active = otg->host->b_hnp_enable;
if (musb->is_active) if (musb->is_active)
mod_timer(&musb->otg_timer, jiffies mod_timer(&musb->otg_timer, jiffies
...@@ -96,7 +96,7 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) ...@@ -96,7 +96,7 @@ int musb_port_suspend(struct musb *musb, bool do_suspend)
musb_platform_try_idle(musb, 0); musb_platform_try_idle(musb, 0);
break; break;
case OTG_STATE_B_HOST: case OTG_STATE_B_HOST:
musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
musb->is_active = otg->host->b_hnp_enable; musb->is_active = otg->host->b_hnp_enable;
musb_platform_try_idle(musb, 0); musb_platform_try_idle(musb, 0);
break; break;
...@@ -123,7 +123,7 @@ void musb_port_reset(struct musb *musb, bool do_reset) ...@@ -123,7 +123,7 @@ void musb_port_reset(struct musb *musb, bool do_reset)
u8 power; u8 power;
void __iomem *mbase = musb->mregs; void __iomem *mbase = musb->mregs;
if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) { if (musb_get_state(musb) == OTG_STATE_B_IDLE) {
musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle"); musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle");
musb->port1_status &= ~USB_PORT_STAT_RESET; musb->port1_status &= ~USB_PORT_STAT_RESET;
return; return;
...@@ -204,20 +204,20 @@ void musb_root_disconnect(struct musb *musb) ...@@ -204,20 +204,20 @@ void musb_root_disconnect(struct musb *musb)
usb_hcd_poll_rh_status(musb->hcd); usb_hcd_poll_rh_status(musb->hcd);
musb->is_active = 0; musb->is_active = 0;
switch (musb->xceiv->otg->state) { switch (musb_get_state(musb)) {
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
if (otg->host->b_hnp_enable) { if (otg->host->b_hnp_enable) {
musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
musb->g.is_a_peripheral = 1; musb->g.is_a_peripheral = 1;
break; break;
} }
fallthrough; fallthrough;
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
musb->is_active = 0; musb->is_active = 0;
break; break;
case OTG_STATE_A_WAIT_VFALL: case OTG_STATE_A_WAIT_VFALL:
musb->xceiv->otg->state = OTG_STATE_B_IDLE; musb_set_state(musb, OTG_STATE_B_IDLE);
break; break;
default: default:
musb_dbg(musb, "host disconnect (%s)", musb_dbg(musb, "host disconnect (%s)",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册