Lines Matching full:cdns

28 static int cdns3_idle_init(struct cdns3 *cdns);
30 static int cdns3_role_start(struct cdns3 *cdns, enum usb_role role) in cdns3_role_start() argument
37 mutex_lock(&cdns->mutex); in cdns3_role_start()
38 cdns->role = role; in cdns3_role_start()
39 mutex_unlock(&cdns->mutex); in cdns3_role_start()
41 if (!cdns->roles[role]) in cdns3_role_start()
44 if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE) in cdns3_role_start()
47 mutex_lock(&cdns->mutex); in cdns3_role_start()
48 ret = cdns->roles[role]->start(cdns); in cdns3_role_start()
50 cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE; in cdns3_role_start()
51 mutex_unlock(&cdns->mutex); in cdns3_role_start()
56 static void cdns3_role_stop(struct cdns3 *cdns) in cdns3_role_stop() argument
58 enum usb_role role = cdns->role; in cdns3_role_stop()
63 if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE) in cdns3_role_stop()
66 mutex_lock(&cdns->mutex); in cdns3_role_stop()
67 cdns->roles[role]->stop(cdns); in cdns3_role_stop()
68 cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE; in cdns3_role_stop()
69 mutex_unlock(&cdns->mutex); in cdns3_role_stop()
72 static void cdns3_exit_roles(struct cdns3 *cdns) in cdns3_exit_roles() argument
74 cdns3_role_stop(cdns); in cdns3_exit_roles()
75 cdns3_drd_exit(cdns); in cdns3_exit_roles()
80 * @cdns: Pointer to cdns3 structure
84 static int cdns3_core_init_role(struct cdns3 *cdns) in cdns3_core_init_role() argument
86 struct device *dev = cdns->dev; in cdns3_core_init_role()
92 cdns->role = USB_ROLE_NONE; in cdns3_core_init_role()
110 * At this point cdns->dr_mode contains strap configuration. in cdns3_core_init_role()
113 best_dr_mode = cdns->dr_mode; in cdns3_core_init_role()
115 ret = cdns3_idle_init(cdns); in cdns3_core_init_role()
120 best_dr_mode = cdns->dr_mode; in cdns3_core_init_role()
121 } else if (cdns->dr_mode == USB_DR_MODE_OTG) { in cdns3_core_init_role()
123 } else if (cdns->dr_mode != dr_mode) { in cdns3_core_init_role()
131 ret = cdns3_host_init(cdns); in cdns3_core_init_role()
140 ret = cdns3_gadget_init(cdns); in cdns3_core_init_role()
148 cdns->dr_mode = dr_mode; in cdns3_core_init_role()
150 ret = cdns3_drd_update_mode(cdns); in cdns3_core_init_role()
155 ret = cdns3_role_start(cdns, USB_ROLE_NONE); in cdns3_core_init_role()
159 switch (cdns->dr_mode) { in cdns3_core_init_role()
161 ret = cdns3_hw_role_switch(cdns); in cdns3_core_init_role()
166 ret = cdns3_role_start(cdns, USB_ROLE_DEVICE); in cdns3_core_init_role()
171 ret = cdns3_role_start(cdns, USB_ROLE_HOST); in cdns3_core_init_role()
182 cdns3_exit_roles(cdns); in cdns3_core_init_role()
188 * @cdns: Pointer to controller structure.
192 static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns) in cdns3_hw_role_state_machine() argument
197 if (cdns->dr_mode != USB_DR_MODE_OTG) { in cdns3_hw_role_state_machine()
198 if (cdns3_is_host(cdns)) in cdns3_hw_role_state_machine()
200 if (cdns3_is_device(cdns)) in cdns3_hw_role_state_machine()
206 id = cdns3_get_id(cdns); in cdns3_hw_role_state_machine()
207 vbus = cdns3_get_vbus(cdns); in cdns3_hw_role_state_machine()
212 * Previous state: cdns->role in cdns3_hw_role_state_machine()
215 role = cdns->role; in cdns3_hw_role_state_machine()
238 dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role); in cdns3_hw_role_state_machine()
243 static int cdns3_idle_role_start(struct cdns3 *cdns) in cdns3_idle_role_start() argument
248 static void cdns3_idle_role_stop(struct cdns3 *cdns) in cdns3_idle_role_stop() argument
251 phy_reset(cdns->usb3_phy); in cdns3_idle_role_stop()
254 static int cdns3_idle_init(struct cdns3 *cdns) in cdns3_idle_init() argument
258 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); in cdns3_idle_init()
269 cdns->roles[USB_ROLE_NONE] = rdrv; in cdns3_idle_init()
276 * @cdns: controller
278 int cdns3_hw_role_switch(struct cdns3 *cdns) in cdns3_hw_role_switch() argument
284 if (cdns->role_sw) in cdns3_hw_role_switch()
287 pm_runtime_get_sync(cdns->dev); in cdns3_hw_role_switch()
289 current_role = cdns->role; in cdns3_hw_role_switch()
290 real_role = cdns3_hw_role_state_machine(cdns); in cdns3_hw_role_switch()
296 cdns3_role_stop(cdns); in cdns3_hw_role_switch()
298 dev_dbg(cdns->dev, "Switching role %d -> %d", current_role, real_role); in cdns3_hw_role_switch()
300 ret = cdns3_role_start(cdns, real_role); in cdns3_hw_role_switch()
303 dev_err(cdns->dev, "set %d has failed, back to %d\n", in cdns3_hw_role_switch()
305 ret = cdns3_role_start(cdns, current_role); in cdns3_hw_role_switch()
307 dev_err(cdns->dev, "back to %d failed too\n", in cdns3_hw_role_switch()
311 pm_runtime_put_sync(cdns->dev); in cdns3_hw_role_switch()
324 struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); in cdns3_role_get() local
326 return cdns->role; in cdns3_role_get()
340 struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); in cdns3_role_set() local
343 pm_runtime_get_sync(cdns->dev); in cdns3_role_set()
345 if (cdns->role == role) in cdns3_role_set()
348 if (cdns->dr_mode == USB_DR_MODE_HOST) { in cdns3_role_set()
358 if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL) { in cdns3_role_set()
368 cdns3_role_stop(cdns); in cdns3_role_set()
369 ret = cdns3_role_start(cdns, role); in cdns3_role_set()
371 dev_err(cdns->dev, "set role %d has failed\n", role); in cdns3_role_set()
374 pm_runtime_put_sync(cdns->dev); in cdns3_role_set()
378 static int set_phy_power_on(struct cdns3 *cdns) in set_phy_power_on() argument
382 ret = phy_power_on(cdns->usb2_phy); in set_phy_power_on()
386 ret = phy_power_on(cdns->usb3_phy); in set_phy_power_on()
388 phy_power_off(cdns->usb2_phy); in set_phy_power_on()
393 static void set_phy_power_off(struct cdns3 *cdns) in set_phy_power_off() argument
395 phy_power_off(cdns->usb3_phy); in set_phy_power_off()
396 phy_power_off(cdns->usb2_phy); in set_phy_power_off()
408 struct cdns3 *cdns = data; in cdns3_wakeup_irq() local
410 if (cdns->in_lpm) { in cdns3_wakeup_irq()
412 cdns->wakeup_pending = true; in cdns3_wakeup_irq()
413 if ((cdns->role == USB_ROLE_HOST) && cdns->host_dev) in cdns3_wakeup_irq()
414 pm_request_resume(&cdns->host_dev->dev); in cdns3_wakeup_irq()
432 struct cdns3 *cdns; in cdns3_probe() local
442 cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); in cdns3_probe()
443 if (!cdns) in cdns3_probe()
446 cdns->dev = dev; in cdns3_probe()
447 cdns->pdata = dev_get_platdata(dev); in cdns3_probe()
449 platform_set_drvdata(pdev, cdns); in cdns3_probe()
457 cdns->xhci_res[0] = *res; in cdns3_probe()
465 cdns->xhci_res[1] = *res; in cdns3_probe()
467 cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral"); in cdns3_probe()
468 if (cdns->dev_irq == -EPROBE_DEFER) in cdns3_probe()
469 return cdns->dev_irq; in cdns3_probe()
471 if (cdns->dev_irq < 0) in cdns3_probe()
477 cdns->dev_regs = regs; in cdns3_probe()
479 cdns->otg_irq = platform_get_irq_byname(pdev, "otg"); in cdns3_probe()
480 if (cdns->otg_irq == -EPROBE_DEFER) in cdns3_probe()
481 return cdns->otg_irq; in cdns3_probe()
483 if (cdns->otg_irq < 0) { in cdns3_probe()
485 return cdns->otg_irq; in cdns3_probe()
494 cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable"); in cdns3_probe()
496 cdns->otg_res = *res; in cdns3_probe()
498 cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); in cdns3_probe()
499 if (cdns->wakeup_irq == -EPROBE_DEFER) in cdns3_probe()
500 return cdns->wakeup_irq; in cdns3_probe()
501 else if (cdns->wakeup_irq == 0) in cdns3_probe()
504 if (cdns->wakeup_irq < 0) { in cdns3_probe()
506 cdns->wakeup_irq = 0x0; in cdns3_probe()
509 mutex_init(&cdns->mutex); in cdns3_probe()
511 cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); in cdns3_probe()
512 if (IS_ERR(cdns->usb2_phy)) in cdns3_probe()
513 return PTR_ERR(cdns->usb2_phy); in cdns3_probe()
515 ret = phy_init(cdns->usb2_phy); in cdns3_probe()
519 cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy"); in cdns3_probe()
520 if (IS_ERR(cdns->usb3_phy)) in cdns3_probe()
521 return PTR_ERR(cdns->usb3_phy); in cdns3_probe()
523 ret = phy_init(cdns->usb3_phy); in cdns3_probe()
527 ret = set_phy_power_on(cdns); in cdns3_probe()
537 sw_desc.driver_data = cdns; in cdns3_probe()
540 cdns->role_sw = usb_role_switch_register(dev, &sw_desc); in cdns3_probe()
541 if (IS_ERR(cdns->role_sw)) { in cdns3_probe()
542 ret = PTR_ERR(cdns->role_sw); in cdns3_probe()
548 if (cdns->wakeup_irq) { in cdns3_probe()
549 ret = devm_request_irq(cdns->dev, cdns->wakeup_irq, in cdns3_probe()
552 dev_name(cdns->dev), cdns); in cdns3_probe()
555 dev_err(cdns->dev, "couldn't register wakeup irq handler\n"); in cdns3_probe()
560 ret = cdns3_drd_init(cdns); in cdns3_probe()
564 ret = cdns3_core_init_role(cdns); in cdns3_probe()
568 spin_lock_init(&cdns->lock); in cdns3_probe()
586 cdns3_drd_exit(cdns); in cdns3_probe()
587 if (cdns->role_sw) in cdns3_probe()
588 usb_role_switch_unregister(cdns->role_sw); in cdns3_probe()
590 set_phy_power_off(cdns); in cdns3_probe()
592 phy_exit(cdns->usb3_phy); in cdns3_probe()
594 phy_exit(cdns->usb2_phy); in cdns3_probe()
607 struct cdns3 *cdns = platform_get_drvdata(pdev); in cdns3_remove() local
612 cdns3_exit_roles(cdns); in cdns3_remove()
613 usb_role_switch_unregister(cdns->role_sw); in cdns3_remove()
614 set_phy_power_off(cdns); in cdns3_remove()
615 phy_exit(cdns->usb2_phy); in cdns3_remove()
616 phy_exit(cdns->usb3_phy); in cdns3_remove()
625 struct cdns3 *cdns = dev_get_drvdata(dev); in cdns3_set_platform_suspend() local
628 if (cdns->pdata && cdns->pdata->platform_suspend) in cdns3_set_platform_suspend()
629 ret = cdns->pdata->platform_suspend(dev, suspend, wakeup); in cdns3_set_platform_suspend()
636 struct cdns3 *cdns = dev_get_drvdata(dev); in cdns3_controller_suspend() local
640 if (cdns->in_lpm) in cdns3_controller_suspend()
648 cdns3_set_platform_suspend(cdns->dev, true, wakeup); in cdns3_controller_suspend()
649 set_phy_power_off(cdns); in cdns3_controller_suspend()
650 spin_lock_irqsave(&cdns->lock, flags); in cdns3_controller_suspend()
651 cdns->in_lpm = true; in cdns3_controller_suspend()
652 spin_unlock_irqrestore(&cdns->lock, flags); in cdns3_controller_suspend()
653 dev_dbg(cdns->dev, "%s ends\n", __func__); in cdns3_controller_suspend()
660 struct cdns3 *cdns = dev_get_drvdata(dev); in cdns3_controller_resume() local
664 if (!cdns->in_lpm) in cdns3_controller_resume()
667 ret = set_phy_power_on(cdns); in cdns3_controller_resume()
671 cdns3_set_platform_suspend(cdns->dev, false, false); in cdns3_controller_resume()
673 spin_lock_irqsave(&cdns->lock, flags); in cdns3_controller_resume()
674 if (cdns->roles[cdns->role]->resume && !PMSG_IS_AUTO(msg)) in cdns3_controller_resume()
675 cdns->roles[cdns->role]->resume(cdns, false); in cdns3_controller_resume()
677 cdns->in_lpm = false; in cdns3_controller_resume()
678 spin_unlock_irqrestore(&cdns->lock, flags); in cdns3_controller_resume()
679 if (cdns->wakeup_pending) { in cdns3_controller_resume()
680 cdns->wakeup_pending = false; in cdns3_controller_resume()
681 enable_irq(cdns->wakeup_irq); in cdns3_controller_resume()
683 dev_dbg(cdns->dev, "%s ends\n", __func__); in cdns3_controller_resume()
701 struct cdns3 *cdns = dev_get_drvdata(dev); in cdns3_suspend() local
707 if (cdns->roles[cdns->role]->suspend) { in cdns3_suspend()
708 spin_lock_irqsave(&cdns->lock, flags); in cdns3_suspend()
709 cdns->roles[cdns->role]->suspend(cdns, false); in cdns3_suspend()
710 spin_unlock_irqrestore(&cdns->lock, flags); in cdns3_suspend()
740 { .compatible = "cdns,usb3" },
750 .name = "cdns-usb3",