Lines Matching refs:hsotg
52 static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg) in dwc2_get_dr_mode() argument
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()
62 if (dwc2_hw_is_device(hsotg)) { in dwc2_get_dr_mode()
64 dev_err(hsotg->dev, in dwc2_get_dr_mode()
69 } else if (dwc2_hw_is_host(hsotg)) { in dwc2_get_dr_mode()
71 dev_err(hsotg->dev, 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()
88 hsotg->dr_mode = mode; in dwc2_get_dr_mode()
96 struct dwc2_hsotg *hsotg = data; in __dwc2_disable_regulators() local
98 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); in __dwc2_disable_regulators()
101 static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_hw_enable() argument
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()
112 __dwc2_disable_regulators, hsotg); 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()
142 int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_enable() argument
144 int ret = __dwc2_lowlevel_hw_enable(hsotg); in dwc2_lowlevel_hw_enable()
147 hsotg->ll_hw_enabled = true; in dwc2_lowlevel_hw_enable()
151 static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) in __dwc2_lowlevel_hw_disable() argument
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()
181 int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_disable() argument
183 int ret = __dwc2_lowlevel_hw_disable(hsotg); in dwc2_lowlevel_hw_disable()
186 hsotg->ll_hw_enabled = false; in dwc2_lowlevel_hw_disable()
190 static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) in dwc2_lowlevel_hw_init() argument
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()
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()
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()
272 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); in dwc2_driver_remove() local
276 gr = &hsotg->gr_backup; in dwc2_driver_remove()
279 if (hsotg->hibernated) { in dwc2_driver_remove()
281 ret = dwc2_exit_hibernation(hsotg, 0, 0, 1); in dwc2_driver_remove()
283 ret = dwc2_exit_hibernation(hsotg, 0, 0, 0); in dwc2_driver_remove()
286 dev_err(hsotg->dev, in dwc2_driver_remove()
291 if (hsotg->in_ppd) { in dwc2_driver_remove()
292 ret = dwc2_exit_partial_power_down(hsotg, 0, true); 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()
301 if (dwc2_is_device_mode(hsotg)) in dwc2_driver_remove()
302 dwc2_gadget_exit_clock_gating(hsotg, 0); in dwc2_driver_remove()
304 dwc2_host_exit_clock_gating(hsotg, 0); in dwc2_driver_remove()
307 dwc2_debugfs_exit(hsotg); in dwc2_driver_remove()
308 if (hsotg->hcd_enabled) in dwc2_driver_remove()
309 dwc2_hcd_remove(hsotg); in dwc2_driver_remove()
310 if (hsotg->gadget_enabled) in dwc2_driver_remove()
311 dwc2_hsotg_remove(hsotg); in dwc2_driver_remove()
313 dwc2_drd_exit(hsotg); 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()
319 dwc2_lowlevel_hw_disable(hsotg); 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()
341 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); in dwc2_driver_shutdown() local
343 dwc2_disable_global_interrupts(hsotg); in dwc2_driver_shutdown()
344 synchronize_irq(hsotg->irq); in dwc2_driver_shutdown()
352 static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg) in dwc2_check_core_endianness() argument
356 snpsid = ioread32(hsotg->regs + GSNPSID); in dwc2_check_core_endianness()
370 int dwc2_check_core_version(struct dwc2_hsotg *hsotg) in dwc2_check_core_version() argument
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()
384 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", in dwc2_check_core_version()
389 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", in dwc2_check_core_version()
409 struct dwc2_hsotg *hsotg; in dwc2_driver_probe() local
413 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); in dwc2_driver_probe()
414 if (!hsotg) in dwc2_driver_probe()
417 hsotg->dev = &dev->dev; 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()
435 (unsigned long)res->start, hsotg->regs); in dwc2_driver_probe()
437 retval = dwc2_lowlevel_hw_init(hsotg); 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()
463 retval = dwc2_lowlevel_hw_enable(hsotg); in dwc2_driver_probe()
467 hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg); in dwc2_driver_probe()
469 retval = dwc2_get_dr_mode(hsotg); in dwc2_driver_probe()
473 hsotg->need_phy_for_wake = in dwc2_driver_probe()
481 retval = dwc2_check_core_version(hsotg); in dwc2_driver_probe()
489 retval = dwc2_core_reset(hsotg, false); in dwc2_driver_probe()
494 retval = dwc2_get_hwparams(hsotg); in dwc2_driver_probe()
503 dwc2_force_dr_mode(hsotg); in dwc2_driver_probe()
505 retval = dwc2_init_params(hsotg); 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()
524 ggpio = dwc2_readl(hsotg, GGPIO); in dwc2_driver_probe()
527 dwc2_writel(hsotg, ggpio, GGPIO); in dwc2_driver_probe()
533 retval = dwc2_drd_init(hsotg); 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()
540 retval = dwc2_gadget_init(hsotg); in dwc2_driver_probe()
543 hsotg->gadget_enabled = 1; in dwc2_driver_probe()
551 if (hsotg->need_phy_for_wake) in dwc2_driver_probe()
554 hsotg->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()
560 hsotg->reset_phy_on_wake = false; in dwc2_driver_probe()
563 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { in dwc2_driver_probe()
564 retval = dwc2_hcd_init(hsotg); in dwc2_driver_probe()
566 if (hsotg->gadget_enabled) in dwc2_driver_probe()
567 dwc2_hsotg_remove(hsotg); in dwc2_driver_probe()
570 hsotg->hcd_enabled = 1; in dwc2_driver_probe()
573 platform_set_drvdata(dev, hsotg); in dwc2_driver_probe()
574 hsotg->hibernated = 0; in dwc2_driver_probe()
576 dwc2_debugfs_init(hsotg); in dwc2_driver_probe()
579 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_driver_probe()
580 dwc2_lowlevel_hw_disable(hsotg); 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()
589 dwc2_hsotg_remove(hsotg); in dwc2_driver_probe()
599 dwc2_debugfs_exit(hsotg); in dwc2_driver_probe()
600 if (hsotg->hcd_enabled) in dwc2_driver_probe()
601 dwc2_hcd_remove(hsotg); in dwc2_driver_probe()
604 dwc2_drd_exit(hsotg); 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()
611 dwc2_lowlevel_hw_disable(hsotg); in dwc2_driver_probe()