| .. | .. |
|---|
| 121 | 121 | return 0; |
|---|
| 122 | 122 | } |
|---|
| 123 | 123 | |
|---|
| 124 | +static void __dwc2_disable_regulators(void *data) |
|---|
| 125 | +{ |
|---|
| 126 | + struct dwc2_hsotg *hsotg = data; |
|---|
| 127 | + |
|---|
| 128 | + regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); |
|---|
| 129 | +} |
|---|
| 130 | + |
|---|
| 124 | 131 | static int __dwc2_lowlevel_phy_enable(struct dwc2_hsotg *hsotg) |
|---|
| 125 | 132 | { |
|---|
| 126 | 133 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
|---|
| .. | .. |
|---|
| 131 | 138 | } else if (hsotg->plat && hsotg->plat->phy_init) { |
|---|
| 132 | 139 | ret = hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); |
|---|
| 133 | 140 | } else { |
|---|
| 134 | | - ret = phy_power_on(hsotg->phy); |
|---|
| 141 | + ret = phy_init(hsotg->phy); |
|---|
| 135 | 142 | if (ret == 0) |
|---|
| 136 | | - ret = phy_init(hsotg->phy); |
|---|
| 143 | + ret = phy_power_on(hsotg->phy); |
|---|
| 137 | 144 | } |
|---|
| 138 | 145 | |
|---|
| 139 | 146 | return ret; |
|---|
| .. | .. |
|---|
| 165 | 172 | } else if (hsotg->plat && hsotg->plat->phy_exit) { |
|---|
| 166 | 173 | ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
|---|
| 167 | 174 | } else { |
|---|
| 168 | | - ret = phy_exit(hsotg->phy); |
|---|
| 175 | + ret = phy_power_off(hsotg->phy); |
|---|
| 169 | 176 | if (ret == 0) |
|---|
| 170 | | - ret = phy_power_off(hsotg->phy); |
|---|
| 177 | + ret = phy_exit(hsotg->phy); |
|---|
| 171 | 178 | } |
|---|
| 172 | 179 | |
|---|
| 173 | 180 | return ret; |
|---|
| .. | .. |
|---|
| 191 | 198 | |
|---|
| 192 | 199 | static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) |
|---|
| 193 | 200 | { |
|---|
| 194 | | - int clk, ret; |
|---|
| 201 | + struct platform_device *pdev = to_platform_device(hsotg->dev); |
|---|
| 202 | + int ret; |
|---|
| 195 | 203 | |
|---|
| 196 | 204 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
|---|
| 197 | 205 | hsotg->supplies); |
|---|
| 198 | 206 | if (ret) |
|---|
| 199 | 207 | return ret; |
|---|
| 200 | 208 | |
|---|
| 201 | | - for (clk = 0; clk < DWC2_MAX_CLKS && hsotg->clks[clk]; clk++) { |
|---|
| 202 | | - ret = clk_prepare_enable(hsotg->clks[clk]); |
|---|
| 203 | | - if (ret) { |
|---|
| 204 | | - while (--clk >= 0) |
|---|
| 205 | | - clk_disable_unprepare(hsotg->clks[clk]); |
|---|
| 206 | | - return ret; |
|---|
| 207 | | - } |
|---|
| 208 | | - } |
|---|
| 209 | + ret = devm_add_action_or_reset(&pdev->dev, |
|---|
| 210 | + __dwc2_disable_regulators, hsotg); |
|---|
| 211 | + if (ret) |
|---|
| 212 | + return ret; |
|---|
| 213 | + |
|---|
| 214 | + ret = clk_bulk_prepare_enable(hsotg->num_clks, hsotg->clks); |
|---|
| 215 | + if (ret) |
|---|
| 216 | + return ret; |
|---|
| 209 | 217 | |
|---|
| 210 | 218 | if (!hsotg->ll_phy_enabled) |
|---|
| 211 | 219 | ret = dwc2_lowlevel_phy_enable(hsotg); |
|---|
| .. | .. |
|---|
| 231 | 239 | |
|---|
| 232 | 240 | static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) |
|---|
| 233 | 241 | { |
|---|
| 234 | | - int clk, ret = 0; |
|---|
| 242 | + int ret = 0; |
|---|
| 235 | 243 | |
|---|
| 236 | 244 | if (hsotg->ll_phy_enabled) |
|---|
| 237 | 245 | ret = dwc2_lowlevel_phy_disable(hsotg); |
|---|
| .. | .. |
|---|
| 239 | 247 | if (ret) |
|---|
| 240 | 248 | return ret; |
|---|
| 241 | 249 | |
|---|
| 242 | | - for (clk = DWC2_MAX_CLKS - 1; clk >= 0; clk--) |
|---|
| 243 | | - if (hsotg->clks[clk]) |
|---|
| 244 | | - clk_disable_unprepare(hsotg->clks[clk]); |
|---|
| 250 | + clk_bulk_disable_unprepare(hsotg->num_clks, hsotg->clks); |
|---|
| 245 | 251 | |
|---|
| 246 | | - ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
|---|
| 247 | | - hsotg->supplies); |
|---|
| 248 | | - |
|---|
| 249 | | - return ret; |
|---|
| 252 | + return 0; |
|---|
| 250 | 253 | } |
|---|
| 251 | 254 | |
|---|
| 252 | 255 | /** |
|---|
| .. | .. |
|---|
| 265 | 268 | return ret; |
|---|
| 266 | 269 | } |
|---|
| 267 | 270 | |
|---|
| 268 | | -/* Only used to reset usb phy at interrupter runtime */ |
|---|
| 269 | | -static void dwc2_reset_phy_work(struct work_struct *data) |
|---|
| 270 | | -{ |
|---|
| 271 | | - struct dwc2_hsotg *hsotg = container_of(data, struct dwc2_hsotg, |
|---|
| 272 | | - phy_rst_work); |
|---|
| 273 | | - phy_reset(hsotg->phy); |
|---|
| 274 | | -} |
|---|
| 275 | | - |
|---|
| 276 | 271 | static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) |
|---|
| 277 | 272 | { |
|---|
| 278 | | - int i, clk, ret; |
|---|
| 273 | + int i, ret; |
|---|
| 279 | 274 | |
|---|
| 280 | 275 | hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2"); |
|---|
| 281 | 276 | if (IS_ERR(hsotg->reset)) { |
|---|
| .. | .. |
|---|
| 294 | 289 | } |
|---|
| 295 | 290 | |
|---|
| 296 | 291 | reset_control_deassert(hsotg->reset_ecc); |
|---|
| 297 | | - |
|---|
| 298 | | - /* Set default UTMI width */ |
|---|
| 299 | | - hsotg->phyif = GUSBCFG_PHYIF16; |
|---|
| 300 | 292 | |
|---|
| 301 | 293 | /* |
|---|
| 302 | 294 | * Attempt to find a generic PHY, then look for an old style |
|---|
| .. | .. |
|---|
| 317 | 309 | return ret; |
|---|
| 318 | 310 | } |
|---|
| 319 | 311 | } |
|---|
| 320 | | - INIT_WORK(&hsotg->phy_rst_work, dwc2_reset_phy_work); |
|---|
| 321 | 312 | |
|---|
| 322 | 313 | if (!hsotg->phy) { |
|---|
| 323 | 314 | hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2); |
|---|
| .. | .. |
|---|
| 340 | 331 | |
|---|
| 341 | 332 | hsotg->plat = dev_get_platdata(hsotg->dev); |
|---|
| 342 | 333 | |
|---|
| 343 | | - if (hsotg->phy) { |
|---|
| 334 | + /* Clock */ |
|---|
| 335 | + if (hsotg->dev->of_node) { |
|---|
| 336 | + ret = devm_clk_bulk_get_all(hsotg->dev, &hsotg->clks); |
|---|
| 337 | + if (ret == -EPROBE_DEFER) |
|---|
| 338 | + return ret; |
|---|
| 344 | 339 | /* |
|---|
| 345 | | - * If using the generic PHY framework, check if the PHY bus |
|---|
| 346 | | - * width is 8-bit and set the phyif appropriately. |
|---|
| 340 | + * Clocks are optional, but new DT platforms should support all |
|---|
| 341 | + * clocks as required by the DT-binding. |
|---|
| 347 | 342 | */ |
|---|
| 348 | | - if (phy_get_bus_width(hsotg->phy) == 8) |
|---|
| 349 | | - hsotg->phyif = GUSBCFG_PHYIF8; |
|---|
| 350 | | - } |
|---|
| 351 | | - |
|---|
| 352 | | - for (clk = 0; clk < DWC2_MAX_CLKS; clk++) { |
|---|
| 353 | | - hsotg->clks[clk] = of_clk_get(hsotg->dev->of_node, clk); |
|---|
| 354 | | - if (IS_ERR(hsotg->clks[clk])) { |
|---|
| 355 | | - ret = PTR_ERR(hsotg->clks[clk]); |
|---|
| 356 | | - if (ret == -EPROBE_DEFER) { |
|---|
| 357 | | - while (--clk >= 0) |
|---|
| 358 | | - clk_put(hsotg->clks[clk]); |
|---|
| 359 | | - return ret; |
|---|
| 360 | | - } |
|---|
| 361 | | - |
|---|
| 362 | | - hsotg->clks[clk] = NULL; |
|---|
| 363 | | - break; |
|---|
| 364 | | - } |
|---|
| 343 | + if (ret < 0) |
|---|
| 344 | + hsotg->num_clks = 0; |
|---|
| 345 | + else |
|---|
| 346 | + hsotg->num_clks = ret; |
|---|
| 365 | 347 | } |
|---|
| 366 | 348 | |
|---|
| 367 | 349 | /* Regulators */ |
|---|
| .. | .. |
|---|
| 371 | 353 | ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies), |
|---|
| 372 | 354 | hsotg->supplies); |
|---|
| 373 | 355 | if (ret) { |
|---|
| 374 | | - dev_err(hsotg->dev, "failed to request supplies: %d\n", ret); |
|---|
| 356 | + if (ret != -EPROBE_DEFER) |
|---|
| 357 | + dev_err(hsotg->dev, "failed to request supplies: %d\n", |
|---|
| 358 | + ret); |
|---|
| 375 | 359 | return ret; |
|---|
| 376 | 360 | } |
|---|
| 377 | 361 | return 0; |
|---|
| .. | .. |
|---|
| 397 | 381 | dwc2_hcd_remove(hsotg); |
|---|
| 398 | 382 | if (hsotg->gadget_enabled) |
|---|
| 399 | 383 | dwc2_hsotg_remove(hsotg); |
|---|
| 384 | + |
|---|
| 385 | + dwc2_drd_exit(hsotg); |
|---|
| 386 | + |
|---|
| 387 | + if (hsotg->params.activate_stm_id_vb_detection) |
|---|
| 388 | + regulator_disable(hsotg->usb33d); |
|---|
| 400 | 389 | |
|---|
| 401 | 390 | pm_runtime_put_sync(hsotg->dev); |
|---|
| 402 | 391 | pm_runtime_disable(hsotg->dev); |
|---|
| .. | .. |
|---|
| 448 | 437 | } |
|---|
| 449 | 438 | |
|---|
| 450 | 439 | /** |
|---|
| 440 | + * Check core version |
|---|
| 441 | + * |
|---|
| 442 | + * @hsotg: Programming view of the DWC_otg controller |
|---|
| 443 | + * |
|---|
| 444 | + */ |
|---|
| 445 | +int dwc2_check_core_version(struct dwc2_hsotg *hsotg) |
|---|
| 446 | +{ |
|---|
| 447 | + struct dwc2_hw_params *hw = &hsotg->hw_params; |
|---|
| 448 | + |
|---|
| 449 | + /* |
|---|
| 450 | + * Attempt to ensure this device is really a DWC_otg Controller. |
|---|
| 451 | + * Read and verify the GSNPSID register contents. The value should be |
|---|
| 452 | + * 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx |
|---|
| 453 | + */ |
|---|
| 454 | + |
|---|
| 455 | + hw->snpsid = dwc2_readl(hsotg, GSNPSID); |
|---|
| 456 | + if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID && |
|---|
| 457 | + (hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID && |
|---|
| 458 | + (hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) { |
|---|
| 459 | + dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", |
|---|
| 460 | + hw->snpsid); |
|---|
| 461 | + return -ENODEV; |
|---|
| 462 | + } |
|---|
| 463 | + |
|---|
| 464 | + dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", |
|---|
| 465 | + hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, |
|---|
| 466 | + hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); |
|---|
| 467 | + return 0; |
|---|
| 468 | +} |
|---|
| 469 | + |
|---|
| 470 | +/** |
|---|
| 451 | 471 | * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg |
|---|
| 452 | 472 | * driver |
|---|
| 453 | 473 | * |
|---|
| .. | .. |
|---|
| 482 | 502 | return retval; |
|---|
| 483 | 503 | } |
|---|
| 484 | 504 | |
|---|
| 485 | | - res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
|---|
| 486 | | - hsotg->regs = devm_ioremap_resource(&dev->dev, res); |
|---|
| 505 | + hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res); |
|---|
| 487 | 506 | if (IS_ERR(hsotg->regs)) |
|---|
| 488 | 507 | return PTR_ERR(hsotg->regs); |
|---|
| 489 | 508 | |
|---|
| .. | .. |
|---|
| 497 | 516 | spin_lock_init(&hsotg->lock); |
|---|
| 498 | 517 | |
|---|
| 499 | 518 | hsotg->irq = platform_get_irq(dev, 0); |
|---|
| 500 | | - if (hsotg->irq < 0) { |
|---|
| 501 | | - dev_err(&dev->dev, "missing IRQ resource\n"); |
|---|
| 519 | + if (hsotg->irq < 0) |
|---|
| 502 | 520 | return hsotg->irq; |
|---|
| 503 | | - } |
|---|
| 504 | 521 | |
|---|
| 505 | 522 | dev_dbg(hsotg->dev, "registering common handler for irq%d\n", |
|---|
| 506 | 523 | hsotg->irq); |
|---|
| .. | .. |
|---|
| 509 | 526 | dev_name(hsotg->dev), hsotg); |
|---|
| 510 | 527 | if (retval) |
|---|
| 511 | 528 | return retval; |
|---|
| 529 | + |
|---|
| 530 | + hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); |
|---|
| 531 | + if (IS_ERR(hsotg->vbus_supply)) { |
|---|
| 532 | + retval = PTR_ERR(hsotg->vbus_supply); |
|---|
| 533 | + hsotg->vbus_supply = NULL; |
|---|
| 534 | + if (retval != -ENODEV) |
|---|
| 535 | + return retval; |
|---|
| 536 | + } |
|---|
| 512 | 537 | |
|---|
| 513 | 538 | retval = dwc2_lowlevel_hw_enable(hsotg); |
|---|
| 514 | 539 | if (retval) |
|---|
| .. | .. |
|---|
| 522 | 547 | goto error; |
|---|
| 523 | 548 | |
|---|
| 524 | 549 | retval = dwc2_get_dr_mode(hsotg); |
|---|
| 550 | + if (retval) |
|---|
| 551 | + goto error; |
|---|
| 552 | + |
|---|
| 553 | + hsotg->need_phy_for_wake = |
|---|
| 554 | + of_property_read_bool(dev->dev.of_node, |
|---|
| 555 | + "snps,need-phy-for-wake"); |
|---|
| 556 | + |
|---|
| 557 | + /* |
|---|
| 558 | + * Before performing any core related operations |
|---|
| 559 | + * check core version. |
|---|
| 560 | + */ |
|---|
| 561 | + retval = dwc2_check_core_version(hsotg); |
|---|
| 525 | 562 | if (retval) |
|---|
| 526 | 563 | goto error; |
|---|
| 527 | 564 | |
|---|
| .. | .. |
|---|
| 549 | 586 | if (retval) |
|---|
| 550 | 587 | goto error; |
|---|
| 551 | 588 | |
|---|
| 589 | + if (hsotg->params.activate_stm_id_vb_detection) { |
|---|
| 590 | + u32 ggpio; |
|---|
| 591 | + |
|---|
| 592 | + hsotg->usb33d = devm_regulator_get(hsotg->dev, "usb33d"); |
|---|
| 593 | + if (IS_ERR(hsotg->usb33d)) { |
|---|
| 594 | + retval = PTR_ERR(hsotg->usb33d); |
|---|
| 595 | + if (retval != -EPROBE_DEFER) |
|---|
| 596 | + dev_err(hsotg->dev, |
|---|
| 597 | + "failed to request usb33d supply: %d\n", |
|---|
| 598 | + retval); |
|---|
| 599 | + goto error; |
|---|
| 600 | + } |
|---|
| 601 | + retval = regulator_enable(hsotg->usb33d); |
|---|
| 602 | + if (retval) { |
|---|
| 603 | + dev_err(hsotg->dev, |
|---|
| 604 | + "failed to enable usb33d supply: %d\n", retval); |
|---|
| 605 | + goto error; |
|---|
| 606 | + } |
|---|
| 607 | + |
|---|
| 608 | + ggpio = dwc2_readl(hsotg, GGPIO); |
|---|
| 609 | + ggpio |= GGPIO_STM32_OTG_GCCFG_IDEN; |
|---|
| 610 | + ggpio |= GGPIO_STM32_OTG_GCCFG_VBDEN; |
|---|
| 611 | + dwc2_writel(hsotg, ggpio, GGPIO); |
|---|
| 612 | + |
|---|
| 613 | + /* ID/VBUS detection startup time */ |
|---|
| 614 | + usleep_range(5000, 7000); |
|---|
| 615 | + } |
|---|
| 616 | + |
|---|
| 617 | + retval = dwc2_drd_init(hsotg); |
|---|
| 618 | + if (retval) { |
|---|
| 619 | + if (retval != -EPROBE_DEFER) |
|---|
| 620 | + dev_err(hsotg->dev, "failed to initialize dual-role\n"); |
|---|
| 621 | + goto error_init; |
|---|
| 622 | + } |
|---|
| 623 | + |
|---|
| 552 | 624 | if (hsotg->dr_mode != USB_DR_MODE_HOST) { |
|---|
| 553 | 625 | retval = dwc2_gadget_init(hsotg); |
|---|
| 554 | 626 | if (retval) |
|---|
| 555 | | - goto error; |
|---|
| 627 | + goto error_drd; |
|---|
| 556 | 628 | hsotg->gadget_enabled = 1; |
|---|
| 629 | + } |
|---|
| 630 | + |
|---|
| 631 | + /* |
|---|
| 632 | + * If we need PHY for wakeup we must be wakeup capable. |
|---|
| 633 | + * When we have a device that can wake without the PHY we |
|---|
| 634 | + * can adjust this condition. |
|---|
| 635 | + */ |
|---|
| 636 | + if (hsotg->need_phy_for_wake) |
|---|
| 637 | + device_set_wakeup_capable(&dev->dev, true); |
|---|
| 638 | + |
|---|
| 639 | + hsotg->reset_phy_on_wake = |
|---|
| 640 | + of_property_read_bool(dev->dev.of_node, |
|---|
| 641 | + "snps,reset-phy-on-wake"); |
|---|
| 642 | + if (hsotg->reset_phy_on_wake && !hsotg->phy) { |
|---|
| 643 | + dev_warn(hsotg->dev, |
|---|
| 644 | + "Quirk reset-phy-on-wake only supports generic PHYs\n"); |
|---|
| 645 | + hsotg->reset_phy_on_wake = false; |
|---|
| 557 | 646 | } |
|---|
| 558 | 647 | |
|---|
| 559 | 648 | if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { |
|---|
| .. | .. |
|---|
| 561 | 650 | if (retval) { |
|---|
| 562 | 651 | if (hsotg->gadget_enabled) |
|---|
| 563 | 652 | dwc2_hsotg_remove(hsotg); |
|---|
| 564 | | - goto error; |
|---|
| 653 | + goto error_drd; |
|---|
| 565 | 654 | } |
|---|
| 566 | 655 | hsotg->hcd_enabled = 1; |
|---|
| 567 | 656 | } |
|---|
| .. | .. |
|---|
| 588 | 677 | if (retval) { |
|---|
| 589 | 678 | hsotg->gadget.udc = NULL; |
|---|
| 590 | 679 | dwc2_hsotg_remove(hsotg); |
|---|
| 591 | | - goto error; |
|---|
| 680 | + goto error_debugfs; |
|---|
| 592 | 681 | } |
|---|
| 593 | 682 | } |
|---|
| 594 | 683 | #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ |
|---|
| 595 | 684 | return 0; |
|---|
| 596 | 685 | |
|---|
| 686 | +#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ |
|---|
| 687 | + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) |
|---|
| 688 | +error_debugfs: |
|---|
| 689 | + dwc2_debugfs_exit(hsotg); |
|---|
| 690 | + if (hsotg->hcd_enabled) |
|---|
| 691 | + dwc2_hcd_remove(hsotg); |
|---|
| 692 | +#endif |
|---|
| 693 | +error_drd: |
|---|
| 694 | + dwc2_drd_exit(hsotg); |
|---|
| 695 | + |
|---|
| 696 | +error_init: |
|---|
| 697 | + if (hsotg->params.activate_stm_id_vb_detection) |
|---|
| 698 | + regulator_disable(hsotg->usb33d); |
|---|
| 597 | 699 | error: |
|---|
| 598 | 700 | pm_runtime_put_sync(hsotg->dev); |
|---|
| 599 | 701 | pm_runtime_disable(hsotg->dev); |
|---|
| .. | .. |
|---|
| 605 | 707 | static int __maybe_unused dwc2_suspend(struct device *dev) |
|---|
| 606 | 708 | { |
|---|
| 607 | 709 | struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); |
|---|
| 710 | + bool is_device_mode = dwc2_is_device_mode(dwc2); |
|---|
| 608 | 711 | int ret = 0; |
|---|
| 609 | 712 | |
|---|
| 610 | | - if (dwc2_is_device_mode(dwc2)) |
|---|
| 713 | + if (is_device_mode) |
|---|
| 611 | 714 | dwc2_hsotg_suspend(dwc2); |
|---|
| 612 | 715 | |
|---|
| 613 | | - if (dwc2->ll_hw_enabled) |
|---|
| 716 | + dwc2_drd_suspend(dwc2); |
|---|
| 717 | + |
|---|
| 718 | + if (dwc2->params.activate_stm_id_vb_detection) { |
|---|
| 719 | + unsigned long flags; |
|---|
| 720 | + u32 ggpio, gotgctl; |
|---|
| 721 | + |
|---|
| 722 | + /* |
|---|
| 723 | + * Need to force the mode to the current mode to avoid Mode |
|---|
| 724 | + * Mismatch Interrupt when ID detection will be disabled. |
|---|
| 725 | + */ |
|---|
| 726 | + dwc2_force_mode(dwc2, !is_device_mode); |
|---|
| 727 | + |
|---|
| 728 | + spin_lock_irqsave(&dwc2->lock, flags); |
|---|
| 729 | + gotgctl = dwc2_readl(dwc2, GOTGCTL); |
|---|
| 730 | + /* bypass debounce filter, enable overrides */ |
|---|
| 731 | + gotgctl |= GOTGCTL_DBNCE_FLTR_BYPASS; |
|---|
| 732 | + gotgctl |= GOTGCTL_BVALOEN | GOTGCTL_AVALOEN; |
|---|
| 733 | + /* Force A / B session if needed */ |
|---|
| 734 | + if (gotgctl & GOTGCTL_ASESVLD) |
|---|
| 735 | + gotgctl |= GOTGCTL_AVALOVAL; |
|---|
| 736 | + if (gotgctl & GOTGCTL_BSESVLD) |
|---|
| 737 | + gotgctl |= GOTGCTL_BVALOVAL; |
|---|
| 738 | + dwc2_writel(dwc2, gotgctl, GOTGCTL); |
|---|
| 739 | + spin_unlock_irqrestore(&dwc2->lock, flags); |
|---|
| 740 | + |
|---|
| 741 | + ggpio = dwc2_readl(dwc2, GGPIO); |
|---|
| 742 | + ggpio &= ~GGPIO_STM32_OTG_GCCFG_IDEN; |
|---|
| 743 | + ggpio &= ~GGPIO_STM32_OTG_GCCFG_VBDEN; |
|---|
| 744 | + dwc2_writel(dwc2, ggpio, GGPIO); |
|---|
| 745 | + |
|---|
| 746 | + regulator_disable(dwc2->usb33d); |
|---|
| 747 | + } |
|---|
| 748 | + |
|---|
| 749 | + if (dwc2->ll_hw_enabled && |
|---|
| 750 | + (is_device_mode || dwc2_host_can_poweroff_phy(dwc2))) { |
|---|
| 614 | 751 | ret = __dwc2_lowlevel_hw_disable(dwc2); |
|---|
| 752 | + dwc2->phy_off_for_suspend = true; |
|---|
| 753 | + } |
|---|
| 615 | 754 | |
|---|
| 616 | 755 | return ret; |
|---|
| 617 | 756 | } |
|---|
| .. | .. |
|---|
| 622 | 761 | unsigned long flags; |
|---|
| 623 | 762 | int ret = 0; |
|---|
| 624 | 763 | |
|---|
| 625 | | - if (dwc2->ll_hw_enabled) { |
|---|
| 764 | + if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { |
|---|
| 626 | 765 | ret = __dwc2_lowlevel_hw_enable(dwc2); |
|---|
| 627 | 766 | if (ret) |
|---|
| 628 | 767 | return ret; |
|---|
| 629 | 768 | } |
|---|
| 769 | + dwc2->phy_off_for_suspend = false; |
|---|
| 770 | + |
|---|
| 771 | + if (dwc2->params.activate_stm_id_vb_detection) { |
|---|
| 772 | + unsigned long flags; |
|---|
| 773 | + u32 ggpio, gotgctl; |
|---|
| 774 | + |
|---|
| 775 | + ret = regulator_enable(dwc2->usb33d); |
|---|
| 776 | + if (ret) |
|---|
| 777 | + return ret; |
|---|
| 778 | + |
|---|
| 779 | + ggpio = dwc2_readl(dwc2, GGPIO); |
|---|
| 780 | + ggpio |= GGPIO_STM32_OTG_GCCFG_IDEN; |
|---|
| 781 | + ggpio |= GGPIO_STM32_OTG_GCCFG_VBDEN; |
|---|
| 782 | + dwc2_writel(dwc2, ggpio, GGPIO); |
|---|
| 783 | + |
|---|
| 784 | + /* ID/VBUS detection startup time */ |
|---|
| 785 | + usleep_range(5000, 7000); |
|---|
| 786 | + |
|---|
| 787 | + spin_lock_irqsave(&dwc2->lock, flags); |
|---|
| 788 | + gotgctl = dwc2_readl(dwc2, GOTGCTL); |
|---|
| 789 | + gotgctl &= ~GOTGCTL_DBNCE_FLTR_BYPASS; |
|---|
| 790 | + gotgctl &= ~(GOTGCTL_BVALOEN | GOTGCTL_AVALOEN | |
|---|
| 791 | + GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL); |
|---|
| 792 | + dwc2_writel(dwc2, gotgctl, GOTGCTL); |
|---|
| 793 | + spin_unlock_irqrestore(&dwc2->lock, flags); |
|---|
| 794 | + } |
|---|
| 795 | + |
|---|
| 796 | + /* Need to restore FORCEDEVMODE/FORCEHOSTMODE */ |
|---|
| 797 | + dwc2_force_dr_mode(dwc2); |
|---|
| 798 | + |
|---|
| 799 | + dwc2_drd_resume(dwc2); |
|---|
| 630 | 800 | |
|---|
| 631 | 801 | if (dwc2->dr_mode == USB_DR_MODE_HOST && dwc2_is_device_mode(dwc2)) { |
|---|
| 632 | 802 | /* Reinit for Host mode if lost power */ |
|---|