Lines Matching refs:hsotg

82 static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg)  in dwc2_get_dr_mode()  argument
86 hsotg->dr_mode = usb_get_dr_mode(hsotg->dev); in dwc2_get_dr_mode()
87 if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN) in dwc2_get_dr_mode()
88 hsotg->dr_mode = USB_DR_MODE_OTG; in dwc2_get_dr_mode()
90 mode = hsotg->dr_mode; in dwc2_get_dr_mode()
92 if (dwc2_hw_is_device(hsotg)) { in dwc2_get_dr_mode()
94 dev_err(hsotg->dev, in dwc2_get_dr_mode()
99 } else if (dwc2_hw_is_host(hsotg)) { in dwc2_get_dr_mode()
101 dev_err(hsotg->dev, in dwc2_get_dr_mode()
113 if (mode != hsotg->dr_mode) { in dwc2_get_dr_mode()
114 dev_warn(hsotg->dev, in dwc2_get_dr_mode()
118 hsotg->dr_mode = mode; in dwc2_get_dr_mode()
126 struct dwc2_hsotg *hsotg = data; in __dwc2_disable_regulators() local
128 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); in __dwc2_disable_regulators()
131 static int __dwc2_lowlevel_phy_enable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_phy_enable() argument
133 struct platform_device *pdev = to_platform_device(hsotg->dev); in __dwc2_lowlevel_phy_enable()
136 if (hsotg->uphy) { in __dwc2_lowlevel_phy_enable()
137 ret = usb_phy_init(hsotg->uphy); in __dwc2_lowlevel_phy_enable()
138 } else if (hsotg->plat && hsotg->plat->phy_init) { in __dwc2_lowlevel_phy_enable()
139 ret = hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); in __dwc2_lowlevel_phy_enable()
141 ret = phy_init(hsotg->phy); in __dwc2_lowlevel_phy_enable()
143 ret = phy_power_on(hsotg->phy); in __dwc2_lowlevel_phy_enable()
156 int dwc2_lowlevel_phy_enable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_phy_enable() argument
158 int ret = __dwc2_lowlevel_phy_enable(hsotg); in dwc2_lowlevel_phy_enable()
161 hsotg->ll_phy_enabled = true; in dwc2_lowlevel_phy_enable()
165 static int __dwc2_lowlevel_phy_disable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_phy_disable() argument
167 struct platform_device *pdev = to_platform_device(hsotg->dev); in __dwc2_lowlevel_phy_disable()
170 if (hsotg->uphy) { in __dwc2_lowlevel_phy_disable()
171 usb_phy_shutdown(hsotg->uphy); in __dwc2_lowlevel_phy_disable()
172 } else if (hsotg->plat && hsotg->plat->phy_exit) { in __dwc2_lowlevel_phy_disable()
173 ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); in __dwc2_lowlevel_phy_disable()
175 ret = phy_power_off(hsotg->phy); in __dwc2_lowlevel_phy_disable()
177 ret = phy_exit(hsotg->phy); in __dwc2_lowlevel_phy_disable()
190 int dwc2_lowlevel_phy_disable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_phy_disable() argument
192 int ret = __dwc2_lowlevel_phy_disable(hsotg); in dwc2_lowlevel_phy_disable()
195 hsotg->ll_phy_enabled = false; in dwc2_lowlevel_phy_disable()
199 static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_hw_enable() argument
201 struct platform_device *pdev = to_platform_device(hsotg->dev); in __dwc2_lowlevel_hw_enable()
204 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), in __dwc2_lowlevel_hw_enable()
205 hsotg->supplies); in __dwc2_lowlevel_hw_enable()
210 __dwc2_disable_regulators, hsotg); in __dwc2_lowlevel_hw_enable()
214 ret = clk_bulk_prepare_enable(hsotg->num_clks, hsotg->clks); in __dwc2_lowlevel_hw_enable()
218 if (!hsotg->ll_phy_enabled) in __dwc2_lowlevel_hw_enable()
219 ret = dwc2_lowlevel_phy_enable(hsotg); in __dwc2_lowlevel_hw_enable()
231 int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_enable() argument
233 int ret = __dwc2_lowlevel_hw_enable(hsotg); in dwc2_lowlevel_hw_enable()
236 hsotg->ll_hw_enabled = true; in dwc2_lowlevel_hw_enable()
240 static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_hw_disable() argument
244 if (hsotg->ll_phy_enabled) in __dwc2_lowlevel_hw_disable()
245 ret = dwc2_lowlevel_phy_disable(hsotg); in __dwc2_lowlevel_hw_disable()
250 clk_bulk_disable_unprepare(hsotg->num_clks, hsotg->clks); in __dwc2_lowlevel_hw_disable()
262 int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_disable() argument
264 int ret = __dwc2_lowlevel_hw_disable(hsotg); in dwc2_lowlevel_hw_disable()
267 hsotg->ll_hw_enabled = false; in dwc2_lowlevel_hw_disable()
271 static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_init() argument
275 hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2"); in dwc2_lowlevel_hw_init()
276 if (IS_ERR(hsotg->reset)) { in dwc2_lowlevel_hw_init()
277 ret = PTR_ERR(hsotg->reset); in dwc2_lowlevel_hw_init()
278 dev_err(hsotg->dev, "error getting reset control %d\n", ret); in dwc2_lowlevel_hw_init()
282 reset_control_deassert(hsotg->reset); in dwc2_lowlevel_hw_init()
284 hsotg->reset_ecc = devm_reset_control_get_optional(hsotg->dev, "dwc2-ecc"); in dwc2_lowlevel_hw_init()
285 if (IS_ERR(hsotg->reset_ecc)) { in dwc2_lowlevel_hw_init()
286 ret = PTR_ERR(hsotg->reset_ecc); in dwc2_lowlevel_hw_init()
287 dev_err(hsotg->dev, "error getting reset control for ecc %d\n", ret); in dwc2_lowlevel_hw_init()
291 reset_control_deassert(hsotg->reset_ecc); in dwc2_lowlevel_hw_init()
297 hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy"); in dwc2_lowlevel_hw_init()
298 if (IS_ERR(hsotg->phy)) { in dwc2_lowlevel_hw_init()
299 ret = PTR_ERR(hsotg->phy); in dwc2_lowlevel_hw_init()
303 hsotg->phy = NULL; in dwc2_lowlevel_hw_init()
308 dev_err(hsotg->dev, "error getting phy %d\n", ret); in dwc2_lowlevel_hw_init()
313 if (!hsotg->phy) { in dwc2_lowlevel_hw_init()
314 hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2); in dwc2_lowlevel_hw_init()
315 if (IS_ERR(hsotg->uphy)) { in dwc2_lowlevel_hw_init()
316 ret = PTR_ERR(hsotg->uphy); in dwc2_lowlevel_hw_init()
320 hsotg->uphy = NULL; in dwc2_lowlevel_hw_init()
325 dev_err(hsotg->dev, "error getting usb phy %d\n", in dwc2_lowlevel_hw_init()
332 hsotg->plat = dev_get_platdata(hsotg->dev); in dwc2_lowlevel_hw_init()
335 if (hsotg->dev->of_node) { in dwc2_lowlevel_hw_init()
336 ret = devm_clk_bulk_get_all(hsotg->dev, &hsotg->clks); in dwc2_lowlevel_hw_init()
344 hsotg->num_clks = 0; in dwc2_lowlevel_hw_init()
346 hsotg->num_clks = ret; in dwc2_lowlevel_hw_init()
350 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) in dwc2_lowlevel_hw_init()
351 hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i]; in dwc2_lowlevel_hw_init()
353 ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies), in dwc2_lowlevel_hw_init()
354 hsotg->supplies); in dwc2_lowlevel_hw_init()
357 dev_err(hsotg->dev, "failed to request supplies: %d\n", in dwc2_lowlevel_hw_init()
377 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); in dwc2_driver_remove() local
379 dwc2_debugfs_exit(hsotg); in dwc2_driver_remove()
380 if (hsotg->hcd_enabled) in dwc2_driver_remove()
381 dwc2_hcd_remove(hsotg); in dwc2_driver_remove()
382 if (hsotg->gadget_enabled) in dwc2_driver_remove()
383 dwc2_hsotg_remove(hsotg); in dwc2_driver_remove()
385 dwc2_drd_exit(hsotg); in dwc2_driver_remove()
387 if (hsotg->params.activate_stm_id_vb_detection) in dwc2_driver_remove()
388 regulator_disable(hsotg->usb33d); in dwc2_driver_remove()
390 pm_runtime_put_sync(hsotg->dev); in dwc2_driver_remove()
391 pm_runtime_disable(hsotg->dev); in dwc2_driver_remove()
393 if (hsotg->ll_hw_enabled) in dwc2_driver_remove()
394 dwc2_lowlevel_hw_disable(hsotg); in dwc2_driver_remove()
396 reset_control_assert(hsotg->reset); in dwc2_driver_remove()
397 reset_control_assert(hsotg->reset_ecc); in dwc2_driver_remove()
416 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); in dwc2_driver_shutdown() local
418 dwc2_disable_global_interrupts(hsotg); in dwc2_driver_shutdown()
419 synchronize_irq(hsotg->irq); in dwc2_driver_shutdown()
427 static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg) in dwc2_check_core_endianness() argument
431 snpsid = ioread32(hsotg->regs + GSNPSID); in dwc2_check_core_endianness()
445 int dwc2_check_core_version(struct dwc2_hsotg *hsotg) in dwc2_check_core_version() argument
447 struct dwc2_hw_params *hw = &hsotg->hw_params; in dwc2_check_core_version()
455 hw->snpsid = dwc2_readl(hsotg, GSNPSID); in dwc2_check_core_version()
459 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", in dwc2_check_core_version()
464 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", in dwc2_check_core_version()
484 struct dwc2_hsotg *hsotg; in dwc2_driver_probe() local
488 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); in dwc2_driver_probe()
489 if (!hsotg) in dwc2_driver_probe()
492 hsotg->dev = &dev->dev; in dwc2_driver_probe()
505 hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res); in dwc2_driver_probe()
506 if (IS_ERR(hsotg->regs)) in dwc2_driver_probe()
507 return PTR_ERR(hsotg->regs); in dwc2_driver_probe()
510 (unsigned long)res->start, hsotg->regs); in dwc2_driver_probe()
512 retval = dwc2_lowlevel_hw_init(hsotg); in dwc2_driver_probe()
516 spin_lock_init(&hsotg->lock); in dwc2_driver_probe()
518 hsotg->irq = platform_get_irq(dev, 0); in dwc2_driver_probe()
519 if (hsotg->irq < 0) in dwc2_driver_probe()
520 return hsotg->irq; in dwc2_driver_probe()
522 dev_dbg(hsotg->dev, "registering common handler for irq%d\n", in dwc2_driver_probe()
523 hsotg->irq); in dwc2_driver_probe()
524 retval = devm_request_irq(hsotg->dev, hsotg->irq, in dwc2_driver_probe()
526 dev_name(hsotg->dev), hsotg); in dwc2_driver_probe()
530 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); in dwc2_driver_probe()
531 if (IS_ERR(hsotg->vbus_supply)) { in dwc2_driver_probe()
532 retval = PTR_ERR(hsotg->vbus_supply); in dwc2_driver_probe()
533 hsotg->vbus_supply = NULL; in dwc2_driver_probe()
538 retval = dwc2_lowlevel_hw_enable(hsotg); in dwc2_driver_probe()
542 hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg); in dwc2_driver_probe()
544 pm_runtime_enable(hsotg->dev); in dwc2_driver_probe()
545 retval = pm_runtime_get_sync(hsotg->dev); in dwc2_driver_probe()
549 retval = dwc2_get_dr_mode(hsotg); in dwc2_driver_probe()
553 hsotg->need_phy_for_wake = in dwc2_driver_probe()
561 retval = dwc2_check_core_version(hsotg); in dwc2_driver_probe()
569 retval = dwc2_core_reset(hsotg, false); in dwc2_driver_probe()
574 retval = dwc2_get_hwparams(hsotg); in dwc2_driver_probe()
583 dwc2_force_dr_mode(hsotg); in dwc2_driver_probe()
585 retval = dwc2_init_params(hsotg); in dwc2_driver_probe()
589 if (hsotg->params.activate_stm_id_vb_detection) { in dwc2_driver_probe()
592 hsotg->usb33d = devm_regulator_get(hsotg->dev, "usb33d"); in dwc2_driver_probe()
593 if (IS_ERR(hsotg->usb33d)) { in dwc2_driver_probe()
594 retval = PTR_ERR(hsotg->usb33d); in dwc2_driver_probe()
596 dev_err(hsotg->dev, in dwc2_driver_probe()
601 retval = regulator_enable(hsotg->usb33d); in dwc2_driver_probe()
603 dev_err(hsotg->dev, in dwc2_driver_probe()
608 ggpio = dwc2_readl(hsotg, GGPIO); in dwc2_driver_probe()
611 dwc2_writel(hsotg, ggpio, GGPIO); in dwc2_driver_probe()
617 retval = dwc2_drd_init(hsotg); in dwc2_driver_probe()
620 dev_err(hsotg->dev, "failed to initialize dual-role\n"); in dwc2_driver_probe()
624 if (hsotg->dr_mode != USB_DR_MODE_HOST) { in dwc2_driver_probe()
625 retval = dwc2_gadget_init(hsotg); in dwc2_driver_probe()
628 hsotg->gadget_enabled = 1; in dwc2_driver_probe()
636 if (hsotg->need_phy_for_wake) in dwc2_driver_probe()
639 hsotg->reset_phy_on_wake = in dwc2_driver_probe()
642 if (hsotg->reset_phy_on_wake && !hsotg->phy) { in dwc2_driver_probe()
643 dev_warn(hsotg->dev, in dwc2_driver_probe()
645 hsotg->reset_phy_on_wake = false; in dwc2_driver_probe()
648 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { in dwc2_driver_probe()
649 retval = dwc2_hcd_init(hsotg); in dwc2_driver_probe()
651 if (hsotg->gadget_enabled) in dwc2_driver_probe()
652 dwc2_hsotg_remove(hsotg); in dwc2_driver_probe()
655 hsotg->hcd_enabled = 1; in dwc2_driver_probe()
658 platform_set_drvdata(dev, hsotg); in dwc2_driver_probe()
659 hsotg->hibernated = 0; in dwc2_driver_probe()
661 dwc2_debugfs_init(hsotg); in dwc2_driver_probe()
664 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_driver_probe()
665 dwc2_lowlevel_hw_disable(hsotg); in dwc2_driver_probe()
667 if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { in dwc2_driver_probe()
668 if (hsotg->ll_phy_enabled) in dwc2_driver_probe()
669 dwc2_lowlevel_phy_disable(hsotg); in dwc2_driver_probe()
675 if (hsotg->gadget_enabled) { in dwc2_driver_probe()
676 retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget); in dwc2_driver_probe()
678 hsotg->gadget.udc = NULL; in dwc2_driver_probe()
679 dwc2_hsotg_remove(hsotg); in dwc2_driver_probe()
689 dwc2_debugfs_exit(hsotg); in dwc2_driver_probe()
690 if (hsotg->hcd_enabled) in dwc2_driver_probe()
691 dwc2_hcd_remove(hsotg); in dwc2_driver_probe()
694 dwc2_drd_exit(hsotg); in dwc2_driver_probe()
697 if (hsotg->params.activate_stm_id_vb_detection) in dwc2_driver_probe()
698 regulator_disable(hsotg->usb33d); in dwc2_driver_probe()
700 pm_runtime_put_sync(hsotg->dev); in dwc2_driver_probe()
701 pm_runtime_disable(hsotg->dev); in dwc2_driver_probe()
702 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) in dwc2_driver_probe()
703 dwc2_lowlevel_hw_disable(hsotg); in dwc2_driver_probe()