hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/usb/musb/omap2430.c
....@@ -38,69 +38,6 @@
3838
3939 static struct omap2430_glue *_glue;
4040
41
-static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
42
-{
43
- struct usb_otg *otg = musb->xceiv->otg;
44
- u8 devctl;
45
- unsigned long timeout = jiffies + msecs_to_jiffies(1000);
46
- /* HDRC controls CPEN, but beware current surges during device
47
- * connect. They can trigger transient overcurrent conditions
48
- * that must be ignored.
49
- */
50
-
51
- devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
52
-
53
- if (is_on) {
54
- if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) {
55
- int loops = 100;
56
- /* start the session */
57
- devctl |= MUSB_DEVCTL_SESSION;
58
- musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
59
- /*
60
- * Wait for the musb to set as A device to enable the
61
- * VBUS
62
- */
63
- while (musb_readb(musb->mregs, MUSB_DEVCTL) &
64
- MUSB_DEVCTL_BDEVICE) {
65
-
66
- mdelay(5);
67
- cpu_relax();
68
-
69
- if (time_after(jiffies, timeout)
70
- || loops-- <= 0) {
71
- dev_err(musb->controller,
72
- "configured as A device timeout");
73
- break;
74
- }
75
- }
76
-
77
- otg_set_vbus(otg, 1);
78
- } else {
79
- musb->is_active = 1;
80
- musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
81
- devctl |= MUSB_DEVCTL_SESSION;
82
- MUSB_HST_MODE(musb);
83
- }
84
- } else {
85
- musb->is_active = 0;
86
-
87
- /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and
88
- * jumping right to B_IDLE...
89
- */
90
-
91
- musb->xceiv->otg->state = OTG_STATE_B_IDLE;
92
- devctl &= ~MUSB_DEVCTL_SESSION;
93
-
94
- MUSB_DEV_MODE(musb);
95
- }
96
- musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
97
-
98
- dev_dbg(musb->controller, "VBUS %s, devctl %02x "
99
- /* otg %3x conf %08x prcm %08x */ "\n",
100
- usb_otg_state_string(musb->xceiv->otg->state),
101
- musb_readb(musb->mregs, MUSB_DEVCTL));
102
-}
103
-
10441 static inline void omap2430_low_level_exit(struct musb *musb)
10542 {
10643 u32 l;
....@@ -140,24 +77,52 @@
14077 return 0;
14178 }
14279
80
+/*
81
+ * HDRC controls CPEN, but beware current surges during device connect.
82
+ * They can trigger transient overcurrent conditions that must be ignored.
83
+ *
84
+ * Note that we're skipping A_WAIT_VFALL -> A_IDLE and jumping right to B_IDLE
85
+ * as set by musb_set_peripheral().
86
+ */
14387 static void omap_musb_set_mailbox(struct omap2430_glue *glue)
14488 {
14589 struct musb *musb = glue_to_musb(glue);
146
- struct musb_hdrc_platform_data *pdata =
147
- dev_get_platdata(musb->controller);
148
- struct omap_musb_board_data *data = pdata->board_data;
90
+ int error;
14991
15092 pm_runtime_get_sync(musb->controller);
93
+
94
+ dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
95
+ usb_otg_state_string(musb->xceiv->otg->state),
96
+ musb_readb(musb->mregs, MUSB_DEVCTL));
97
+
15198 switch (glue->status) {
15299 case MUSB_ID_GROUND:
153100 dev_dbg(musb->controller, "ID GND\n");
154
-
155
- musb->xceiv->otg->state = OTG_STATE_A_IDLE;
156
- musb->xceiv->last_event = USB_EVENT_ID;
157
- if (musb->gadget_driver) {
158
- omap_control_usb_set_mode(glue->control_otghs,
159
- USB_MODE_HOST);
160
- omap2430_musb_set_vbus(musb, 1);
101
+ switch (musb->xceiv->otg->state) {
102
+ case OTG_STATE_A_IDLE:
103
+ error = musb_set_host(musb);
104
+ if (error)
105
+ break;
106
+ musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
107
+ fallthrough;
108
+ case OTG_STATE_A_WAIT_VRISE:
109
+ case OTG_STATE_A_WAIT_BCON:
110
+ case OTG_STATE_A_HOST:
111
+ /*
112
+ * On multiple ID ground interrupts just keep enabling
113
+ * VBUS. At least cpcap VBUS shuts down otherwise.
114
+ */
115
+ otg_set_vbus(musb->xceiv->otg, 1);
116
+ break;
117
+ default:
118
+ musb->xceiv->otg->state = OTG_STATE_A_IDLE;
119
+ musb->xceiv->last_event = USB_EVENT_ID;
120
+ if (musb->gadget_driver) {
121
+ omap_control_usb_set_mode(glue->control_otghs,
122
+ USB_MODE_HOST);
123
+ otg_set_vbus(musb->xceiv->otg, 1);
124
+ }
125
+ break;
161126 }
162127 break;
163128
....@@ -174,12 +139,8 @@
174139 dev_dbg(musb->controller, "VBUS Disconnect\n");
175140
176141 musb->xceiv->last_event = USB_EVENT_NONE;
177
- if (musb->gadget_driver)
178
- omap2430_musb_set_vbus(musb, 0);
179
-
180
- if (data->interface_type == MUSB_INTERFACE_UTMI)
181
- otg_set_vbus(musb->xceiv->otg, 0);
182
-
142
+ musb_set_peripheral(musb);
143
+ otg_set_vbus(musb->xceiv->otg, 0);
183144 omap_control_usb_set_mode(glue->control_otghs,
184145 USB_MODE_DISCONNECT);
185146 break;
....@@ -226,7 +187,6 @@
226187 u32 l;
227188 int status = 0;
228189 struct device *dev = musb->controller;
229
- struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
230190 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
231191 struct omap_musb_board_data *data = plat->board_data;
232192
....@@ -282,50 +242,17 @@
282242 musb_readl(musb->mregs, OTG_INTERFSEL),
283243 musb_readl(musb->mregs, OTG_SIMENABLE));
284244
285
- if (glue->status != MUSB_UNKNOWN)
286
- omap_musb_set_mailbox(glue);
287
-
288245 return 0;
289246 }
290247
291248 static void omap2430_musb_enable(struct musb *musb)
292249 {
293
- u8 devctl;
294
- unsigned long timeout = jiffies + msecs_to_jiffies(1000);
295250 struct device *dev = musb->controller;
296251 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
297
- struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
298
- struct omap_musb_board_data *data = pdata->board_data;
299252
300
-
301
- switch (glue->status) {
302
-
303
- case MUSB_ID_GROUND:
304
- omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
305
- if (data->interface_type != MUSB_INTERFACE_UTMI)
306
- break;
307
- devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
308
- /* start the session */
309
- devctl |= MUSB_DEVCTL_SESSION;
310
- musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
311
- while (musb_readb(musb->mregs, MUSB_DEVCTL) &
312
- MUSB_DEVCTL_BDEVICE) {
313
- cpu_relax();
314
-
315
- if (time_after(jiffies, timeout)) {
316
- dev_err(dev, "configured as A device timeout");
317
- break;
318
- }
319
- }
320
- break;
321
-
322
- case MUSB_VBUS_VALID:
323
- omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
324
- break;
325
-
326
- default:
327
- break;
328
- }
253
+ if (glue->status == MUSB_UNKNOWN)
254
+ glue->status = MUSB_VBUS_OFF;
255
+ omap_musb_set_mailbox(glue);
329256 }
330257
331258 static void omap2430_musb_disable(struct musb *musb)
....@@ -433,6 +360,7 @@
433360 control_node = of_parse_phandle(np, "ctrl-module", 0);
434361 if (control_node) {
435362 control_pdev = of_find_device_by_node(control_node);
363
+ of_node_put(control_node);
436364 if (!control_pdev) {
437365 dev_err(&pdev->dev, "Failed to get control device\n");
438366 ret = -EINVAL;
....@@ -529,6 +457,9 @@
529457
530458 omap2430_low_level_exit(musb);
531459
460
+ phy_power_off(musb->phy);
461
+ phy_exit(musb->phy);
462
+
532463 return 0;
533464 }
534465
....@@ -540,10 +471,16 @@
540471 if (!musb)
541472 return 0;
542473
474
+ phy_init(musb->phy);
475
+ phy_power_on(musb->phy);
476
+
543477 omap2430_low_level_init(musb);
544478 musb_writel(musb->mregs, OTG_INTERFSEL,
545479 musb->context.otg_interfsel);
546480
481
+ /* Wait for musb to get oriented. Otherwise we can get babble */
482
+ usleep_range(200000, 250000);
483
+
547484 return 0;
548485 }
549486