Lines Matching +full:disable +full:- +full:hibernation +full:- +full:mode
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * platform.c - DesignWare HS OTG Controller platform driver
13 #include <linux/dma-mapping.h>
18 #include <linux/platform_data/s3c-hsotg.h>
39 * ------------------------------
41 * HST DEV any : ---
44 * DEV HST any : ---
54 enum usb_dr_mode mode; in dwc2_get_dr_mode() local
56 hsotg->dr_mode = usb_get_dr_mode(hsotg->dev); in dwc2_get_dr_mode()
57 if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN) in dwc2_get_dr_mode()
58 hsotg->dr_mode = USB_DR_MODE_OTG; in dwc2_get_dr_mode()
60 mode = hsotg->dr_mode; in dwc2_get_dr_mode()
64 dev_err(hsotg->dev, in dwc2_get_dr_mode()
65 "Controller does not support host mode.\n"); in dwc2_get_dr_mode()
66 return -EINVAL; in dwc2_get_dr_mode()
68 mode = USB_DR_MODE_PERIPHERAL; in dwc2_get_dr_mode()
71 dev_err(hsotg->dev, in dwc2_get_dr_mode()
72 "Controller does not support device mode.\n"); in dwc2_get_dr_mode()
73 return -EINVAL; in dwc2_get_dr_mode()
75 mode = USB_DR_MODE_HOST; in dwc2_get_dr_mode()
78 mode = USB_DR_MODE_HOST; in dwc2_get_dr_mode()
80 mode = USB_DR_MODE_PERIPHERAL; in dwc2_get_dr_mode()
83 if (mode != hsotg->dr_mode) { in dwc2_get_dr_mode()
84 dev_warn(hsotg->dev, in dwc2_get_dr_mode()
86 mode == USB_DR_MODE_HOST ? "host" : "device"); in dwc2_get_dr_mode()
88 hsotg->dr_mode = mode; in dwc2_get_dr_mode()
98 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); in __dwc2_disable_regulators()
103 struct platform_device *pdev = to_platform_device(hsotg->dev); in __dwc2_lowlevel_hw_enable()
106 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), in __dwc2_lowlevel_hw_enable()
107 hsotg->supplies); in __dwc2_lowlevel_hw_enable()
111 ret = devm_add_action_or_reset(&pdev->dev, in __dwc2_lowlevel_hw_enable()
116 if (hsotg->clk) { in __dwc2_lowlevel_hw_enable()
117 ret = clk_prepare_enable(hsotg->clk); in __dwc2_lowlevel_hw_enable()
122 if (hsotg->uphy) { in __dwc2_lowlevel_hw_enable()
123 ret = usb_phy_init(hsotg->uphy); in __dwc2_lowlevel_hw_enable()
124 } else if (hsotg->plat && hsotg->plat->phy_init) { in __dwc2_lowlevel_hw_enable()
125 ret = hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); in __dwc2_lowlevel_hw_enable()
127 ret = phy_init(hsotg->phy); in __dwc2_lowlevel_hw_enable()
129 ret = phy_power_on(hsotg->phy); in __dwc2_lowlevel_hw_enable()
136 * dwc2_lowlevel_hw_enable - enable platform lowlevel hw resources
140 * low-level USB platform resources (phy, clock, regulators)
147 hsotg->ll_hw_enabled = true; in dwc2_lowlevel_hw_enable()
153 struct platform_device *pdev = to_platform_device(hsotg->dev); in __dwc2_lowlevel_hw_disable()
156 if (hsotg->uphy) { in __dwc2_lowlevel_hw_disable()
157 usb_phy_shutdown(hsotg->uphy); in __dwc2_lowlevel_hw_disable()
158 } else if (hsotg->plat && hsotg->plat->phy_exit) { in __dwc2_lowlevel_hw_disable()
159 ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); in __dwc2_lowlevel_hw_disable()
161 ret = phy_power_off(hsotg->phy); in __dwc2_lowlevel_hw_disable()
163 ret = phy_exit(hsotg->phy); in __dwc2_lowlevel_hw_disable()
168 if (hsotg->clk) in __dwc2_lowlevel_hw_disable()
169 clk_disable_unprepare(hsotg->clk); in __dwc2_lowlevel_hw_disable()
175 * dwc2_lowlevel_hw_disable - disable platform lowlevel hw resources
179 * low-level USB platform resources (phy, clock, regulators)
186 hsotg->ll_hw_enabled = false; in dwc2_lowlevel_hw_disable()
194 hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2"); in dwc2_lowlevel_hw_init()
195 if (IS_ERR(hsotg->reset)) in dwc2_lowlevel_hw_init()
196 return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->reset), in dwc2_lowlevel_hw_init()
199 reset_control_deassert(hsotg->reset); in dwc2_lowlevel_hw_init()
201 hsotg->reset_ecc = devm_reset_control_get_optional(hsotg->dev, "dwc2-ecc"); in dwc2_lowlevel_hw_init()
202 if (IS_ERR(hsotg->reset_ecc)) in dwc2_lowlevel_hw_init()
203 return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->reset_ecc), in dwc2_lowlevel_hw_init()
206 reset_control_deassert(hsotg->reset_ecc); in dwc2_lowlevel_hw_init()
212 hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy"); in dwc2_lowlevel_hw_init()
213 if (IS_ERR(hsotg->phy)) { in dwc2_lowlevel_hw_init()
214 ret = PTR_ERR(hsotg->phy); in dwc2_lowlevel_hw_init()
216 case -ENODEV: in dwc2_lowlevel_hw_init()
217 case -ENOSYS: in dwc2_lowlevel_hw_init()
218 hsotg->phy = NULL; in dwc2_lowlevel_hw_init()
221 return dev_err_probe(hsotg->dev, ret, "error getting phy\n"); in dwc2_lowlevel_hw_init()
225 if (!hsotg->phy) { in dwc2_lowlevel_hw_init()
226 hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2); in dwc2_lowlevel_hw_init()
227 if (IS_ERR(hsotg->uphy)) { in dwc2_lowlevel_hw_init()
228 ret = PTR_ERR(hsotg->uphy); in dwc2_lowlevel_hw_init()
230 case -ENODEV: in dwc2_lowlevel_hw_init()
231 case -ENXIO: in dwc2_lowlevel_hw_init()
232 hsotg->uphy = NULL; in dwc2_lowlevel_hw_init()
235 return dev_err_probe(hsotg->dev, ret, "error getting usb phy\n"); in dwc2_lowlevel_hw_init()
240 hsotg->plat = dev_get_platdata(hsotg->dev); in dwc2_lowlevel_hw_init()
243 hsotg->clk = devm_clk_get_optional(hsotg->dev, "otg"); in dwc2_lowlevel_hw_init()
244 if (IS_ERR(hsotg->clk)) in dwc2_lowlevel_hw_init()
245 return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->clk), "cannot get otg clock\n"); in dwc2_lowlevel_hw_init()
248 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) in dwc2_lowlevel_hw_init()
249 hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i]; in dwc2_lowlevel_hw_init()
251 ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies), in dwc2_lowlevel_hw_init()
252 hsotg->supplies); in dwc2_lowlevel_hw_init()
254 return dev_err_probe(hsotg->dev, ret, "failed to request supplies\n"); in dwc2_lowlevel_hw_init()
260 * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
276 gr = &hsotg->gr_backup; in dwc2_driver_remove()
278 /* Exit Hibernation when driver is removed. */ in dwc2_driver_remove()
279 if (hsotg->hibernated) { in dwc2_driver_remove()
280 if (gr->gotgctl & GOTGCTL_CURMODE_HOST) in dwc2_driver_remove()
286 dev_err(hsotg->dev, in dwc2_driver_remove()
287 "exit hibernation failed.\n"); in dwc2_driver_remove()
291 if (hsotg->in_ppd) { in dwc2_driver_remove()
294 dev_err(hsotg->dev, in dwc2_driver_remove()
299 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && in dwc2_driver_remove()
300 hsotg->bus_suspended) { in dwc2_driver_remove()
308 if (hsotg->hcd_enabled) in dwc2_driver_remove()
310 if (hsotg->gadget_enabled) in dwc2_driver_remove()
315 if (hsotg->params.activate_stm_id_vb_detection) in dwc2_driver_remove()
316 regulator_disable(hsotg->usb33d); in dwc2_driver_remove()
318 if (hsotg->ll_hw_enabled) in dwc2_driver_remove()
321 reset_control_assert(hsotg->reset); in dwc2_driver_remove()
322 reset_control_assert(hsotg->reset_ecc); in dwc2_driver_remove()
328 * dwc2_driver_shutdown() - Called on device shutdown
335 * at shutdown-time which may bring the system clock below the threshold
336 * of being able to handle the dwc2 interrupts. Disabling dwc2-irqs
344 synchronize_irq(hsotg->irq); in dwc2_driver_shutdown()
348 * dwc2_check_core_endianness() - Returns true if core and AHB have
356 snpsid = ioread32(hsotg->regs + GSNPSID); in dwc2_check_core_endianness()
365 * dwc2_check_core_version() - Check core version
372 struct dwc2_hw_params *hw = &hsotg->hw_params; in dwc2_check_core_version()
380 hw->snpsid = dwc2_readl(hsotg, GSNPSID); in dwc2_check_core_version()
381 if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID && in dwc2_check_core_version()
382 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID && in dwc2_check_core_version()
383 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) { in dwc2_check_core_version()
384 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", in dwc2_check_core_version()
385 hw->snpsid); in dwc2_check_core_version()
386 return -ENODEV; in dwc2_check_core_version()
389 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", in dwc2_check_core_version()
390 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, in dwc2_check_core_version()
391 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); in dwc2_check_core_version()
396 * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
413 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); in dwc2_driver_probe()
415 return -ENOMEM; in dwc2_driver_probe()
417 hsotg->dev = &dev->dev; in dwc2_driver_probe()
422 if (!dev->dev.dma_mask) in dwc2_driver_probe()
423 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in dwc2_driver_probe()
424 retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32)); in dwc2_driver_probe()
426 dev_err(&dev->dev, "can't set coherent DMA mask: %d\n", retval); in dwc2_driver_probe()
430 hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res); in dwc2_driver_probe()
431 if (IS_ERR(hsotg->regs)) in dwc2_driver_probe()
432 return PTR_ERR(hsotg->regs); in dwc2_driver_probe()
434 dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", in dwc2_driver_probe()
435 (unsigned long)res->start, hsotg->regs); in dwc2_driver_probe()
441 spin_lock_init(&hsotg->lock); in dwc2_driver_probe()
443 hsotg->irq = platform_get_irq(dev, 0); in dwc2_driver_probe()
444 if (hsotg->irq < 0) in dwc2_driver_probe()
445 return hsotg->irq; in dwc2_driver_probe()
447 dev_dbg(hsotg->dev, "registering common handler for irq%d\n", in dwc2_driver_probe()
448 hsotg->irq); in dwc2_driver_probe()
449 retval = devm_request_irq(hsotg->dev, hsotg->irq, in dwc2_driver_probe()
451 dev_name(hsotg->dev), hsotg); in dwc2_driver_probe()
455 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); in dwc2_driver_probe()
456 if (IS_ERR(hsotg->vbus_supply)) { in dwc2_driver_probe()
457 retval = PTR_ERR(hsotg->vbus_supply); in dwc2_driver_probe()
458 hsotg->vbus_supply = NULL; in dwc2_driver_probe()
459 if (retval != -ENODEV) in dwc2_driver_probe()
467 hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg); in dwc2_driver_probe()
473 hsotg->need_phy_for_wake = in dwc2_driver_probe()
474 of_property_read_bool(dev->dev.of_node, in dwc2_driver_probe()
475 "snps,need-phy-for-wake"); in dwc2_driver_probe()
486 * Reset before dwc2_get_hwparams() then it could get power-on real in dwc2_driver_probe()
499 * For OTG cores, set the force mode bits to reflect the value in dwc2_driver_probe()
500 * of dr_mode. Force mode bits should not be touched at any in dwc2_driver_probe()
509 if (hsotg->params.activate_stm_id_vb_detection) { in dwc2_driver_probe()
512 hsotg->usb33d = devm_regulator_get(hsotg->dev, "usb33d"); in dwc2_driver_probe()
513 if (IS_ERR(hsotg->usb33d)) { in dwc2_driver_probe()
514 retval = PTR_ERR(hsotg->usb33d); in dwc2_driver_probe()
515 dev_err_probe(hsotg->dev, retval, "failed to request usb33d supply\n"); in dwc2_driver_probe()
518 retval = regulator_enable(hsotg->usb33d); in dwc2_driver_probe()
520 dev_err_probe(hsotg->dev, retval, "failed to enable usb33d supply\n"); in dwc2_driver_probe()
535 dev_err_probe(hsotg->dev, retval, "failed to initialize dual-role\n"); in dwc2_driver_probe()
539 if (hsotg->dr_mode != USB_DR_MODE_HOST) { in dwc2_driver_probe()
543 hsotg->gadget_enabled = 1; in dwc2_driver_probe()
551 if (hsotg->need_phy_for_wake) in dwc2_driver_probe()
552 device_set_wakeup_capable(&dev->dev, true); in dwc2_driver_probe()
554 hsotg->reset_phy_on_wake = in dwc2_driver_probe()
555 of_property_read_bool(dev->dev.of_node, in dwc2_driver_probe()
556 "snps,reset-phy-on-wake"); in dwc2_driver_probe()
557 if (hsotg->reset_phy_on_wake && !hsotg->phy) { in dwc2_driver_probe()
558 dev_warn(hsotg->dev, in dwc2_driver_probe()
559 "Quirk reset-phy-on-wake only supports generic PHYs\n"); in dwc2_driver_probe()
560 hsotg->reset_phy_on_wake = false; in dwc2_driver_probe()
563 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { in dwc2_driver_probe()
566 if (hsotg->gadget_enabled) in dwc2_driver_probe()
570 hsotg->hcd_enabled = 1; in dwc2_driver_probe()
574 hsotg->hibernated = 0; in dwc2_driver_probe()
579 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_driver_probe()
585 if (hsotg->gadget_enabled) { in dwc2_driver_probe()
586 retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget); in dwc2_driver_probe()
588 hsotg->gadget.udc = NULL; in dwc2_driver_probe()
600 if (hsotg->hcd_enabled) in dwc2_driver_probe()
607 if (hsotg->params.activate_stm_id_vb_detection) in dwc2_driver_probe()
608 regulator_disable(hsotg->usb33d); in dwc2_driver_probe()
610 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) in dwc2_driver_probe()
626 if (dwc2->params.activate_stm_id_vb_detection) { in dwc2_suspend()
631 * Need to force the mode to the current mode to avoid Mode in dwc2_suspend()
636 spin_lock_irqsave(&dwc2->lock, flags); in dwc2_suspend()
647 spin_unlock_irqrestore(&dwc2->lock, flags); in dwc2_suspend()
654 regulator_disable(dwc2->usb33d); in dwc2_suspend()
657 if (dwc2->ll_hw_enabled && in dwc2_suspend()
660 dwc2->phy_off_for_suspend = true; in dwc2_suspend()
671 if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { in dwc2_resume()
676 dwc2->phy_off_for_suspend = false; in dwc2_resume()
678 if (dwc2->params.activate_stm_id_vb_detection) { in dwc2_resume()
682 ret = regulator_enable(dwc2->usb33d); in dwc2_resume()
694 spin_lock_irqsave(&dwc2->lock, flags); in dwc2_resume()
700 spin_unlock_irqrestore(&dwc2->lock, flags); in dwc2_resume()
703 if (!dwc2->role_sw) { in dwc2_resume()