| .. | .. |
|---|
| 38 | 38 | |
|---|
| 39 | 39 | static struct omap2430_glue *_glue; |
|---|
| 40 | 40 | |
|---|
| 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 | | - |
|---|
| 104 | 41 | static inline void omap2430_low_level_exit(struct musb *musb) |
|---|
| 105 | 42 | { |
|---|
| 106 | 43 | u32 l; |
|---|
| .. | .. |
|---|
| 140 | 77 | return 0; |
|---|
| 141 | 78 | } |
|---|
| 142 | 79 | |
|---|
| 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 | + */ |
|---|
| 143 | 87 | static void omap_musb_set_mailbox(struct omap2430_glue *glue) |
|---|
| 144 | 88 | { |
|---|
| 145 | 89 | 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; |
|---|
| 149 | 91 | |
|---|
| 150 | 92 | 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 | + |
|---|
| 151 | 98 | switch (glue->status) { |
|---|
| 152 | 99 | case MUSB_ID_GROUND: |
|---|
| 153 | 100 | 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; |
|---|
| 161 | 126 | } |
|---|
| 162 | 127 | break; |
|---|
| 163 | 128 | |
|---|
| .. | .. |
|---|
| 174 | 139 | dev_dbg(musb->controller, "VBUS Disconnect\n"); |
|---|
| 175 | 140 | |
|---|
| 176 | 141 | 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); |
|---|
| 183 | 144 | omap_control_usb_set_mode(glue->control_otghs, |
|---|
| 184 | 145 | USB_MODE_DISCONNECT); |
|---|
| 185 | 146 | break; |
|---|
| .. | .. |
|---|
| 226 | 187 | u32 l; |
|---|
| 227 | 188 | int status = 0; |
|---|
| 228 | 189 | struct device *dev = musb->controller; |
|---|
| 229 | | - struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
|---|
| 230 | 190 | struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); |
|---|
| 231 | 191 | struct omap_musb_board_data *data = plat->board_data; |
|---|
| 232 | 192 | |
|---|
| .. | .. |
|---|
| 282 | 242 | musb_readl(musb->mregs, OTG_INTERFSEL), |
|---|
| 283 | 243 | musb_readl(musb->mregs, OTG_SIMENABLE)); |
|---|
| 284 | 244 | |
|---|
| 285 | | - if (glue->status != MUSB_UNKNOWN) |
|---|
| 286 | | - omap_musb_set_mailbox(glue); |
|---|
| 287 | | - |
|---|
| 288 | 245 | return 0; |
|---|
| 289 | 246 | } |
|---|
| 290 | 247 | |
|---|
| 291 | 248 | static void omap2430_musb_enable(struct musb *musb) |
|---|
| 292 | 249 | { |
|---|
| 293 | | - u8 devctl; |
|---|
| 294 | | - unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
|---|
| 295 | 250 | struct device *dev = musb->controller; |
|---|
| 296 | 251 | 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; |
|---|
| 299 | 252 | |
|---|
| 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); |
|---|
| 329 | 256 | } |
|---|
| 330 | 257 | |
|---|
| 331 | 258 | static void omap2430_musb_disable(struct musb *musb) |
|---|
| .. | .. |
|---|
| 433 | 360 | control_node = of_parse_phandle(np, "ctrl-module", 0); |
|---|
| 434 | 361 | if (control_node) { |
|---|
| 435 | 362 | control_pdev = of_find_device_by_node(control_node); |
|---|
| 363 | + of_node_put(control_node); |
|---|
| 436 | 364 | if (!control_pdev) { |
|---|
| 437 | 365 | dev_err(&pdev->dev, "Failed to get control device\n"); |
|---|
| 438 | 366 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 529 | 457 | |
|---|
| 530 | 458 | omap2430_low_level_exit(musb); |
|---|
| 531 | 459 | |
|---|
| 460 | + phy_power_off(musb->phy); |
|---|
| 461 | + phy_exit(musb->phy); |
|---|
| 462 | + |
|---|
| 532 | 463 | return 0; |
|---|
| 533 | 464 | } |
|---|
| 534 | 465 | |
|---|
| .. | .. |
|---|
| 540 | 471 | if (!musb) |
|---|
| 541 | 472 | return 0; |
|---|
| 542 | 473 | |
|---|
| 474 | + phy_init(musb->phy); |
|---|
| 475 | + phy_power_on(musb->phy); |
|---|
| 476 | + |
|---|
| 543 | 477 | omap2430_low_level_init(musb); |
|---|
| 544 | 478 | musb_writel(musb->mregs, OTG_INTERFSEL, |
|---|
| 545 | 479 | musb->context.otg_interfsel); |
|---|
| 546 | 480 | |
|---|
| 481 | + /* Wait for musb to get oriented. Otherwise we can get babble */ |
|---|
| 482 | + usleep_range(200000, 250000); |
|---|
| 483 | + |
|---|
| 547 | 484 | return 0; |
|---|
| 548 | 485 | } |
|---|
| 549 | 486 | |
|---|