Skip to content

Commit 3dacdf1

Browse files
vdsaogregkh
authored andcommitted
usb: factor out state_string() on otg drivers
Provide common otg_state_string() and use it in drivers. Signed-off-by: Anatolij Gustschin <agust@denx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 67e7d64 commit 3dacdf1

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

drivers/usb/otg/isp1301_omap.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -234,29 +234,9 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
234234

235235
/*-------------------------------------------------------------------------*/
236236

237-
static const char *state_string(enum usb_otg_state state)
238-
{
239-
switch (state) {
240-
case OTG_STATE_A_IDLE: return "a_idle";
241-
case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
242-
case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
243-
case OTG_STATE_A_HOST: return "a_host";
244-
case OTG_STATE_A_SUSPEND: return "a_suspend";
245-
case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
246-
case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
247-
case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
248-
case OTG_STATE_B_IDLE: return "b_idle";
249-
case OTG_STATE_B_SRP_INIT: return "b_srp_init";
250-
case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
251-
case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
252-
case OTG_STATE_B_HOST: return "b_host";
253-
default: return "UNDEFINED";
254-
}
255-
}
256-
257237
static inline const char *state_name(struct isp1301 *isp)
258238
{
259-
return state_string(isp->otg.state);
239+
return otg_state_string(isp->otg.state);
260240
}
261241

262242
/*-------------------------------------------------------------------------*/
@@ -501,7 +481,7 @@ static void check_state(struct isp1301 *isp, const char *tag)
501481
if (isp->otg.state == state && !extra)
502482
return;
503483
pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
504-
state_string(state), fsm, state_name(isp),
484+
otg_state_string(state), fsm, state_name(isp),
505485
omap_readl(OTG_CTRL));
506486
}
507487

@@ -1095,7 +1075,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
10951075

10961076
if (state != isp->otg.state)
10971077
pr_debug(" isp, %s -> %s\n",
1098-
state_string(state), state_name(isp));
1078+
otg_state_string(state), state_name(isp));
10991079

11001080
#ifdef CONFIG_USB_OTG
11011081
/* update the OTG controller state to match the isp1301; may

drivers/usb/otg/langwell_otg.c

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,6 @@ static struct pci_driver otg_pci_driver = {
8282
.resume = langwell_otg_resume,
8383
};
8484

85-
static const char *state_string(enum usb_otg_state state)
86-
{
87-
switch (state) {
88-
case OTG_STATE_A_IDLE:
89-
return "a_idle";
90-
case OTG_STATE_A_WAIT_VRISE:
91-
return "a_wait_vrise";
92-
case OTG_STATE_A_WAIT_BCON:
93-
return "a_wait_bcon";
94-
case OTG_STATE_A_HOST:
95-
return "a_host";
96-
case OTG_STATE_A_SUSPEND:
97-
return "a_suspend";
98-
case OTG_STATE_A_PERIPHERAL:
99-
return "a_peripheral";
100-
case OTG_STATE_A_WAIT_VFALL:
101-
return "a_wait_vfall";
102-
case OTG_STATE_A_VBUS_ERR:
103-
return "a_vbus_err";
104-
case OTG_STATE_B_IDLE:
105-
return "b_idle";
106-
case OTG_STATE_B_SRP_INIT:
107-
return "b_srp_init";
108-
case OTG_STATE_B_PERIPHERAL:
109-
return "b_peripheral";
110-
case OTG_STATE_B_WAIT_ACON:
111-
return "b_wait_acon";
112-
case OTG_STATE_B_HOST:
113-
return "b_host";
114-
default:
115-
return "UNDEFINED";
116-
}
117-
}
118-
11985
/* HSM timers */
12086
static inline struct langwell_otg_timer *otg_timer_initializer
12187
(void (*function)(unsigned long), unsigned long expires, unsigned long data)
@@ -968,7 +934,7 @@ static void langwell_otg_work(struct work_struct *work)
968934
pdev = to_pci_dev(lnw->dev);
969935

970936
dev_dbg(lnw->dev, "%s: old state = %s\n", __func__,
971-
state_string(iotg->otg.state));
937+
otg_state_string(iotg->otg.state));
972938

973939
switch (iotg->otg.state) {
974940
case OTG_STATE_UNDEFINED:
@@ -1703,7 +1669,7 @@ static void langwell_otg_work(struct work_struct *work)
17031669
}
17041670

17051671
dev_dbg(lnw->dev, "%s: new state = %s\n", __func__,
1706-
state_string(iotg->otg.state));
1672+
otg_state_string(iotg->otg.state));
17071673
}
17081674

17091675
static ssize_t
@@ -1789,7 +1755,7 @@ show_hsm(struct device *_dev, struct device_attribute *attr, char *buf)
17891755
"b_bus_req = \t%d\n"
17901756
"b_bus_suspend_tmout = \t%d\n"
17911757
"b_bus_suspend_vld = \t%d\n",
1792-
state_string(iotg->otg.state),
1758+
otg_state_string(iotg->otg.state),
17931759
iotg->hsm.a_bus_resume,
17941760
iotg->hsm.a_bus_suspend,
17951761
iotg->hsm.a_conn,

drivers/usb/otg/otg.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,38 @@ int otg_set_transceiver(struct otg_transceiver *x)
6464
return 0;
6565
}
6666
EXPORT_SYMBOL(otg_set_transceiver);
67+
68+
const char *otg_state_string(enum usb_otg_state state)
69+
{
70+
switch (state) {
71+
case OTG_STATE_A_IDLE:
72+
return "a_idle";
73+
case OTG_STATE_A_WAIT_VRISE:
74+
return "a_wait_vrise";
75+
case OTG_STATE_A_WAIT_BCON:
76+
return "a_wait_bcon";
77+
case OTG_STATE_A_HOST:
78+
return "a_host";
79+
case OTG_STATE_A_SUSPEND:
80+
return "a_suspend";
81+
case OTG_STATE_A_PERIPHERAL:
82+
return "a_peripheral";
83+
case OTG_STATE_A_WAIT_VFALL:
84+
return "a_wait_vfall";
85+
case OTG_STATE_A_VBUS_ERR:
86+
return "a_vbus_err";
87+
case OTG_STATE_B_IDLE:
88+
return "b_idle";
89+
case OTG_STATE_B_SRP_INIT:
90+
return "b_srp_init";
91+
case OTG_STATE_B_PERIPHERAL:
92+
return "b_peripheral";
93+
case OTG_STATE_B_WAIT_ACON:
94+
return "b_wait_acon";
95+
case OTG_STATE_B_HOST:
96+
return "b_host";
97+
default:
98+
return "UNDEFINED";
99+
}
100+
}
101+
EXPORT_SYMBOL(otg_state_string);

include/linux/usb/otg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,6 @@ otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
246246

247247
/* for OTG controller drivers (and maybe other stuff) */
248248
extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
249+
extern const char *otg_state_string(enum usb_otg_state state);
249250

250251
#endif /* __LINUX_USB_OTG_H */

0 commit comments

Comments
 (0)