Lines Matching refs:dwc

19 static void dwc3_otg_disable_events(struct dwc3 *dwc, u32 disable_mask)  in dwc3_otg_disable_events()  argument
21 u32 reg = dwc3_readl(dwc->regs, DWC3_OEVTEN); in dwc3_otg_disable_events()
24 dwc3_writel(dwc->regs, DWC3_OEVTEN, reg); in dwc3_otg_disable_events()
27 static void dwc3_otg_enable_events(struct dwc3 *dwc, u32 enable_mask) in dwc3_otg_enable_events() argument
29 u32 reg = dwc3_readl(dwc->regs, DWC3_OEVTEN); in dwc3_otg_enable_events()
32 dwc3_writel(dwc->regs, DWC3_OEVTEN, reg); in dwc3_otg_enable_events()
35 static void dwc3_otg_clear_events(struct dwc3 *dwc) in dwc3_otg_clear_events() argument
37 u32 reg = dwc3_readl(dwc->regs, DWC3_OEVT); in dwc3_otg_clear_events()
39 dwc3_writel(dwc->regs, DWC3_OEVTEN, reg); in dwc3_otg_clear_events()
54 struct dwc3 *dwc = _dwc; in dwc3_otg_thread_irq() local
56 spin_lock(&dwc->lock); in dwc3_otg_thread_irq()
57 if (dwc->otg_restart_host) { in dwc3_otg_thread_irq()
58 dwc3_otg_host_init(dwc); in dwc3_otg_thread_irq()
59 dwc->otg_restart_host = false; in dwc3_otg_thread_irq()
62 spin_unlock(&dwc->lock); in dwc3_otg_thread_irq()
64 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); in dwc3_otg_thread_irq()
72 struct dwc3 *dwc = _dwc; in dwc3_otg_irq() local
75 reg = dwc3_readl(dwc->regs, DWC3_OEVT); in dwc3_otg_irq()
79 dwc3_writel(dwc->regs, DWC3_OEVT, reg); in dwc3_otg_irq()
83 if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST && in dwc3_otg_irq()
85 dwc->otg_restart_host = true; in dwc3_otg_irq()
86 dwc3_writel(dwc->regs, DWC3_OEVT, reg); in dwc3_otg_irq()
93 static void dwc3_otgregs_init(struct dwc3 *dwc) in dwc3_otgregs_init() argument
103 reg = dwc3_readl(dwc->regs, DWC3_OCFG); in dwc3_otgregs_init()
105 dwc3_writel(dwc->regs, DWC3_OCFG, reg); in dwc3_otgregs_init()
108 reg = dwc3_readl(dwc->regs, DWC3_GCTL); in dwc3_otgregs_init()
110 dwc3_writel(dwc->regs, DWC3_GCTL, reg); in dwc3_otgregs_init()
117 reg = dwc3_readl(dwc->regs, DWC3_OCFG); in dwc3_otgregs_init()
119 dwc3_writel(dwc->regs, DWC3_OCFG, reg); in dwc3_otgregs_init()
121 dwc3_otg_clear_events(dwc); in dwc3_otgregs_init()
123 dwc3_otg_disable_events(dwc, DWC3_OTG_ALL_EVENTS); in dwc3_otgregs_init()
125 dwc3_otg_enable_events(dwc, DWC3_OTG_ALL_EVENTS); in dwc3_otgregs_init()
130 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otgregs_init()
134 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otgregs_init()
137 static int dwc3_otg_get_irq(struct dwc3 *dwc) in dwc3_otg_get_irq() argument
139 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_otg_get_irq()
167 void dwc3_otg_init(struct dwc3 *dwc) in dwc3_otg_init() argument
176 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG); in dwc3_otg_init()
178 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_otg_init()
180 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_otg_init()
183 dwc3_otgregs_init(dwc); in dwc3_otg_init()
186 void dwc3_otg_exit(struct dwc3 *dwc) in dwc3_otg_exit() argument
189 dwc3_otg_disable_events(dwc, DWC3_OTG_ALL_EVENTS); in dwc3_otg_exit()
191 dwc3_otg_clear_events(dwc); in dwc3_otg_exit()
195 void dwc3_otg_host_init(struct dwc3 *dwc) in dwc3_otg_host_init() argument
206 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otg_host_init()
209 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otg_host_init()
214 reg = dwc3_readl(dwc->regs, DWC3_OCFG); in dwc3_otg_host_init()
216 dwc3_writel(dwc->regs, DWC3_OCFG, reg); in dwc3_otg_host_init()
231 if (!dwc->dis_u2_susphy_quirk) { in dwc3_otg_host_init()
232 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_otg_host_init()
234 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_otg_host_init()
238 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otg_host_init()
240 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otg_host_init()
244 static void dwc3_otg_host_exit(struct dwc3 *dwc) in dwc3_otg_host_exit() argument
261 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otg_host_exit()
263 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otg_host_exit()
267 static void dwc3_otg_device_init(struct dwc3 *dwc) in dwc3_otg_device_init() argument
277 reg = dwc3_readl(dwc->regs, DWC3_OCFG); in dwc3_otg_device_init()
280 dwc3_writel(dwc->regs, DWC3_OCFG, reg); in dwc3_otg_device_init()
286 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otg_device_init()
290 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otg_device_init()
292 dwc3_otg_enable_events(dwc, DWC3_OEVTEN_BDEVSESSVLDDETEN); in dwc3_otg_device_init()
294 if (!dwc->dis_u2_susphy_quirk) { in dwc3_otg_device_init()
295 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_otg_device_init()
297 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_otg_device_init()
303 static void dwc3_otg_device_exit(struct dwc3 *dwc) in dwc3_otg_device_exit() argument
317 dwc3_otg_disable_events(dwc, DWC3_OEVTEN_BDEVHNPCHNGEN | in dwc3_otg_device_exit()
322 reg = dwc3_readl(dwc->regs, DWC3_OCTL); in dwc3_otg_device_exit()
325 dwc3_writel(dwc->regs, DWC3_OCTL, reg); in dwc3_otg_device_exit()
328 void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus) in dwc3_otg_update() argument
335 if (dwc->dr_mode != USB_DR_MODE_OTG) in dwc3_otg_update()
339 if (dwc->current_dr_role != DWC3_GCTL_PRTCAP_OTG) in dwc3_otg_update()
343 reg = dwc3_readl(dwc->regs, DWC3_OSTS); in dwc3_otg_update()
346 dwc->desired_otg_role = id ? DWC3_OTG_ROLE_DEVICE : in dwc3_otg_update()
350 if (dwc->desired_otg_role == dwc->current_otg_role) in dwc3_otg_update()
353 switch (dwc->current_otg_role) { in dwc3_otg_update()
355 dwc3_host_exit(dwc); in dwc3_otg_update()
356 spin_lock_irqsave(&dwc->lock, flags); in dwc3_otg_update()
357 dwc3_otg_host_exit(dwc); in dwc3_otg_update()
358 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_otg_update()
361 dwc3_gadget_exit(dwc); in dwc3_otg_update()
362 spin_lock_irqsave(&dwc->lock, flags); in dwc3_otg_update()
363 dwc3_event_buffers_cleanup(dwc); in dwc3_otg_update()
364 dwc3_otg_device_exit(dwc); in dwc3_otg_update()
365 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_otg_update()
371 spin_lock_irqsave(&dwc->lock, flags); in dwc3_otg_update()
373 dwc->current_otg_role = dwc->desired_otg_role; in dwc3_otg_update()
375 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_otg_update()
377 switch (dwc->desired_otg_role) { in dwc3_otg_update()
379 spin_lock_irqsave(&dwc->lock, flags); in dwc3_otg_update()
380 dwc3_otgregs_init(dwc); in dwc3_otg_update()
381 dwc3_otg_host_init(dwc); in dwc3_otg_update()
382 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_otg_update()
383 ret = dwc3_host_init(dwc); in dwc3_otg_update()
385 dev_err(dwc->dev, "failed to initialize host\n"); in dwc3_otg_update()
387 if (dwc->usb2_phy) in dwc3_otg_update()
388 otg_set_vbus(dwc->usb2_phy->otg, true); in dwc3_otg_update()
389 if (dwc->usb2_generic_phy) in dwc3_otg_update()
390 phy_set_mode(dwc->usb2_generic_phy, in dwc3_otg_update()
395 spin_lock_irqsave(&dwc->lock, flags); in dwc3_otg_update()
396 dwc3_otgregs_init(dwc); in dwc3_otg_update()
397 dwc3_otg_device_init(dwc); in dwc3_otg_update()
398 dwc3_event_buffers_setup(dwc); in dwc3_otg_update()
399 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_otg_update()
401 if (dwc->usb2_phy) in dwc3_otg_update()
402 otg_set_vbus(dwc->usb2_phy->otg, false); in dwc3_otg_update()
403 if (dwc->usb2_generic_phy) in dwc3_otg_update()
404 phy_set_mode(dwc->usb2_generic_phy, in dwc3_otg_update()
406 ret = dwc3_gadget_init(dwc); in dwc3_otg_update()
408 dev_err(dwc->dev, "failed to initialize peripheral\n"); in dwc3_otg_update()
415 static void dwc3_drd_update(struct dwc3 *dwc) in dwc3_drd_update() argument
419 if (dwc->edev) { in dwc3_drd_update()
420 id = extcon_get_state(dwc->edev, EXTCON_USB_HOST); in dwc3_drd_update()
423 dwc3_set_mode(dwc, id ? in dwc3_drd_update()
432 struct dwc3 *dwc = container_of(nb, struct dwc3, edev_nb); in dwc3_drd_notifier() local
434 dwc3_set_mode(dwc, event ? in dwc3_drd_notifier()
446 struct dwc3 *dwc = usb_role_switch_get_drvdata(sw); in dwc3_usb_role_switch_set() local
457 if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) in dwc3_usb_role_switch_set()
464 dwc3_set_mode(dwc, mode); in dwc3_usb_role_switch_set()
470 struct dwc3 *dwc = usb_role_switch_get_drvdata(sw); in dwc3_usb_role_switch_get() local
474 spin_lock_irqsave(&dwc->lock, flags); in dwc3_usb_role_switch_get()
475 switch (dwc->current_dr_role) { in dwc3_usb_role_switch_get()
483 role = dwc->current_otg_role; in dwc3_usb_role_switch_get()
486 if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) in dwc3_usb_role_switch_get()
492 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_usb_role_switch_get()
496 static int dwc3_setup_role_switch(struct dwc3 *dwc) in dwc3_setup_role_switch() argument
501 dwc->role_switch_default_mode = usb_get_role_switch_default_mode(dwc->dev); in dwc3_setup_role_switch()
502 if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) { in dwc3_setup_role_switch()
505 dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL; in dwc3_setup_role_switch()
509 dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); in dwc3_setup_role_switch()
512 dwc3_role_switch.driver_data = dwc; in dwc3_setup_role_switch()
513 dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); in dwc3_setup_role_switch()
514 if (IS_ERR(dwc->role_sw)) in dwc3_setup_role_switch()
515 return PTR_ERR(dwc->role_sw); in dwc3_setup_role_switch()
517 if (dwc->dev->of_node) { in dwc3_setup_role_switch()
519 int ret = devm_of_platform_populate(dwc->dev); in dwc3_setup_role_switch()
522 usb_role_switch_unregister(dwc->role_sw); in dwc3_setup_role_switch()
523 dwc->role_sw = NULL; in dwc3_setup_role_switch()
524 dev_err(dwc->dev, "DWC3 platform devices creation failed: %i\n", ret); in dwc3_setup_role_switch()
529 dwc3_set_mode(dwc, mode); in dwc3_setup_role_switch()
537 int dwc3_drd_init(struct dwc3 *dwc) in dwc3_drd_init() argument
542 device_property_read_bool(dwc->dev, "usb-role-switch")) in dwc3_drd_init()
543 return dwc3_setup_role_switch(dwc); in dwc3_drd_init()
545 if (dwc->edev) { in dwc3_drd_init()
546 dwc->edev_nb.notifier_call = dwc3_drd_notifier; in dwc3_drd_init()
547 ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST, in dwc3_drd_init()
548 &dwc->edev_nb); in dwc3_drd_init()
550 dev_err(dwc->dev, "couldn't register cable notifier\n"); in dwc3_drd_init()
554 dwc3_drd_update(dwc); in dwc3_drd_init()
556 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG); in dwc3_drd_init()
559 irq = dwc3_otg_get_irq(dwc); in dwc3_drd_init()
563 dwc->otg_irq = irq; in dwc3_drd_init()
566 dwc3_otg_disable_events(dwc, DWC3_OTG_ALL_EVENTS); in dwc3_drd_init()
568 dwc3_otg_clear_events(dwc); in dwc3_drd_init()
570 ret = request_threaded_irq(dwc->otg_irq, dwc3_otg_irq, in dwc3_drd_init()
572 IRQF_SHARED, "dwc3-otg", dwc); in dwc3_drd_init()
574 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_drd_init()
575 dwc->otg_irq, ret); in dwc3_drd_init()
580 dwc3_otg_init(dwc); in dwc3_drd_init()
581 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); in dwc3_drd_init()
587 void dwc3_drd_exit(struct dwc3 *dwc) in dwc3_drd_exit() argument
591 if (dwc->role_sw) in dwc3_drd_exit()
592 usb_role_switch_unregister(dwc->role_sw); in dwc3_drd_exit()
594 if (dwc->edev) in dwc3_drd_exit()
595 extcon_unregister_notifier(dwc->edev, EXTCON_USB_HOST, in dwc3_drd_exit()
596 &dwc->edev_nb); in dwc3_drd_exit()
598 cancel_work_sync(&dwc->drd_work); in dwc3_drd_exit()
601 switch (dwc->current_dr_role) { in dwc3_drd_exit()
603 dwc3_host_exit(dwc); in dwc3_drd_exit()
606 dwc3_gadget_exit(dwc); in dwc3_drd_exit()
607 dwc3_event_buffers_cleanup(dwc); in dwc3_drd_exit()
610 dwc3_otg_exit(dwc); in dwc3_drd_exit()
611 spin_lock_irqsave(&dwc->lock, flags); in dwc3_drd_exit()
612 dwc->desired_otg_role = DWC3_OTG_ROLE_IDLE; in dwc3_drd_exit()
613 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_drd_exit()
614 dwc3_otg_update(dwc, 1); in dwc3_drd_exit()
620 if (dwc->otg_irq) in dwc3_drd_exit()
621 free_irq(dwc->otg_irq, dwc); in dwc3_drd_exit()