Lines Matching +full:tpl +full:- +full:support
1 // SPDX-License-Identifier: GPL-2.0
3 * core.c - ChipIdea USB IP core family device controller
5 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
12 * - Four transfers are supported, usbtest is passed
13 * - USB Certification for gadget: CH9 and Mass Storage are passed
14 * - Low power mode
15 * - USB wakeup
19 #include <linux/dma-mapping.h>
105 ci->hw_bank.regmap[i] = in hw_alloc_regmap()
106 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + in hw_alloc_regmap()
110 ci->hw_bank.regmap[i] = ci->hw_bank.op + in hw_alloc_regmap()
111 4 * (i - OP_ENDPTCTRL) + in hw_alloc_regmap()
170 return -EINVAL; in hw_port_test_set()
202 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC; in ci_hdrc_enter_lpm_common()
203 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm))); in ci_hdrc_enter_lpm_common()
206 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm_common()
207 PORTSC_PHCD(ci->hw_bank.lpm)); in ci_hdrc_enter_lpm_common()
209 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm_common()
215 return ci->platdata->enter_lpm(ci, enable); in ci_hdrc_enter_lpm()
223 ci->hw_bank.abs = base; in hw_device_init()
225 ci->hw_bank.cap = ci->hw_bank.abs; in hw_device_init()
226 ci->hw_bank.cap += ci->platdata->capoffset; in hw_device_init()
227 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff); in hw_device_init()
232 ci->hw_bank.lpm = reg; in hw_device_init()
235 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; in hw_device_init()
236 ci->hw_bank.size += OP_LAST; in hw_device_init()
237 ci->hw_bank.size /= sizeof(u32); in hw_device_init()
241 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ in hw_device_init()
243 if (ci->hw_ep_max > ENDPT_MAX) in hw_device_init()
244 return -ENODEV; in hw_device_init()
254 ci->rev = ci_get_revision(ci); in hw_device_init()
256 dev_dbg(ci->dev, in hw_device_init()
258 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); in hw_device_init()
273 switch (ci->platdata->phy_mode) { in hw_phymode_configure()
299 if (ci->hw_bank.lpm) { in hw_phymode_configure()
322 if (ci->phy) { in _ci_usb_phy_init()
323 ret = phy_init(ci->phy); in _ci_usb_phy_init()
327 ret = phy_power_on(ci->phy); in _ci_usb_phy_init()
329 phy_exit(ci->phy); in _ci_usb_phy_init()
333 ret = usb_phy_init(ci->usb_phy); in _ci_usb_phy_init()
346 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_exit()
349 if (ci->phy) { in ci_usb_phy_exit()
350 phy_power_off(ci->phy); in ci_usb_phy_exit()
351 phy_exit(ci->phy); in ci_usb_phy_exit()
353 usb_phy_shutdown(ci->usb_phy); in ci_usb_phy_exit()
367 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_init()
370 switch (ci->platdata->phy_mode) { in ci_usb_phy_init()
411 phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE); in ci_platform_configure()
413 if (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING) in ci_platform_configure()
419 phy_set_mode(ci->phy, PHY_MODE_USB_HOST); in ci_platform_configure()
421 if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING) in ci_platform_configure()
426 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) { in ci_platform_configure()
427 if (ci->hw_bank.lpm) in ci_platform_configure()
433 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA) in ci_platform_configure()
436 hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16); in ci_platform_configure()
438 if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST) in ci_platform_configure()
440 ci->platdata->ahb_burst_config); in ci_platform_configure()
444 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST) in ci_platform_configure()
446 ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK)); in ci_platform_configure()
448 if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST) in ci_platform_configure()
450 ci->platdata->rx_burst_size); in ci_platform_configure()
468 return -ETIMEDOUT; in hw_controller_reset()
490 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret); in hw_device_reset()
494 if (ci->platdata->notify_event) { in hw_device_reset()
495 ret = ci->platdata->notify_event(ci, in hw_device_reset()
508 dev_err(ci->dev, "cannot enter in %s device mode\n", in hw_device_reset()
509 ci_role(ci)->name); in hw_device_reset()
510 dev_err(ci->dev, "lpm = %i\n", ci->hw_bank.lpm); in hw_device_reset()
511 return -ENODEV; in hw_device_reset()
525 if (ci->in_lpm) { in ci_irq_handler()
530 if (ci->wakeup_int) in ci_irq_handler()
534 ci->wakeup_int = true; in ci_irq_handler()
535 pm_runtime_get(ci->dev); in ci_irq_handler()
539 if (ci->is_otg) { in ci_irq_handler()
552 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { in ci_irq_handler()
553 ci->id_event = true; in ci_irq_handler()
564 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { in ci_irq_handler()
565 ci->b_sess_valid_event = true; in ci_irq_handler()
573 if (ci->role != CI_ROLE_END) in ci_irq_handler()
574 ret = ci_role(ci)->irq(ci); in ci_irq_handler()
584 ci_irq_handler(ci->irq, ci); in ci_irq()
592 struct ci_hdrc *ci = cbl->ci; in ci_cable_notifier()
594 cbl->connected = event; in ci_cable_notifier()
595 cbl->changed = true; in ci_cable_notifier()
607 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_get()
609 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_get()
621 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
622 cable->changed = true; in ci_usb_role_switch_set()
623 cable->connected = true; in ci_usb_role_switch_set()
624 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
625 cable->changed = true; in ci_usb_role_switch_set()
626 cable->connected = false; in ci_usb_role_switch_set()
628 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
629 cable->changed = true; in ci_usb_role_switch_set()
630 cable->connected = false; in ci_usb_role_switch_set()
631 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
632 cable->changed = true; in ci_usb_role_switch_set()
633 cable->connected = true; in ci_usb_role_switch_set()
635 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
636 cable->changed = true; in ci_usb_role_switch_set()
637 cable->connected = false; in ci_usb_role_switch_set()
638 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
639 cable->changed = true; in ci_usb_role_switch_set()
640 cable->connected = false; in ci_usb_role_switch_set()
651 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { in ci_get_role()
652 if (ci->is_otg) { in ci_get_role()
657 * If the controller is not OTG capable, but support in ci_get_role()
664 role = ci->roles[CI_ROLE_HOST] ? CI_ROLE_HOST in ci_get_role()
684 if (!platdata->phy_mode) in ci_get_platdata()
685 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); in ci_get_platdata()
687 if (!platdata->dr_mode) in ci_get_platdata()
688 platdata->dr_mode = usb_get_dr_mode(dev); in ci_get_platdata()
690 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN) in ci_get_platdata()
691 platdata->dr_mode = USB_DR_MODE_OTG; in ci_get_platdata()
693 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) { in ci_get_platdata()
695 platdata->reg_vbus = devm_regulator_get_optional(dev, "vbus"); in ci_get_platdata()
696 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { in ci_get_platdata()
697 return -EPROBE_DEFER; in ci_get_platdata()
698 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { in ci_get_platdata()
700 platdata->reg_vbus = NULL; in ci_get_platdata()
701 } else if (IS_ERR(platdata->reg_vbus)) { in ci_get_platdata()
703 PTR_ERR(platdata->reg_vbus)); in ci_get_platdata()
704 return PTR_ERR(platdata->reg_vbus); in ci_get_platdata()
706 /* Get TPL support */ in ci_get_platdata()
707 if (!platdata->tpl_support) in ci_get_platdata()
708 platdata->tpl_support = in ci_get_platdata()
709 of_usb_host_tpl_support(dev->of_node); in ci_get_platdata()
712 if (platdata->dr_mode == USB_DR_MODE_OTG) { in ci_get_platdata()
713 /* We can support HNP and SRP of OTG 2.0 */ in ci_get_platdata()
714 platdata->ci_otg_caps.otg_rev = 0x0200; in ci_get_platdata()
715 platdata->ci_otg_caps.hnp_support = true; in ci_get_platdata()
716 platdata->ci_otg_caps.srp_support = true; in ci_get_platdata()
719 ret = of_usb_update_otg_caps(dev->of_node, in ci_get_platdata()
720 &platdata->ci_otg_caps); in ci_get_platdata()
726 platdata->flags |= CI_HDRC_FORCE_FULLSPEED; in ci_get_platdata()
728 of_property_read_u32(dev->of_node, "phy-clkgate-delay-us", in ci_get_platdata()
729 &platdata->phy_clkgate_delay_us); in ci_get_platdata()
731 platdata->itc_setting = 1; in ci_get_platdata()
733 of_property_read_u32(dev->of_node, "itc-setting", in ci_get_platdata()
734 &platdata->itc_setting); in ci_get_platdata()
736 ret = of_property_read_u32(dev->of_node, "ahb-burst-config", in ci_get_platdata()
737 &platdata->ahb_burst_config); in ci_get_platdata()
739 platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST; in ci_get_platdata()
740 } else if (ret != -EINVAL) { in ci_get_platdata()
741 dev_err(dev, "failed to get ahb-burst-config\n"); in ci_get_platdata()
745 ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword", in ci_get_platdata()
746 &platdata->tx_burst_size); in ci_get_platdata()
748 platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST; in ci_get_platdata()
749 } else if (ret != -EINVAL) { in ci_get_platdata()
750 dev_err(dev, "failed to get tx-burst-size-dword\n"); in ci_get_platdata()
754 ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword", in ci_get_platdata()
755 &platdata->rx_burst_size); in ci_get_platdata()
757 platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST; in ci_get_platdata()
758 } else if (ret != -EINVAL) { in ci_get_platdata()
759 dev_err(dev, "failed to get rx-burst-size-dword\n"); in ci_get_platdata()
763 if (of_property_read_bool(dev->of_node, "non-zero-ttctrl-ttha")) in ci_get_platdata()
764 platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA; in ci_get_platdata()
766 ext_id = ERR_PTR(-ENODEV); in ci_get_platdata()
767 ext_vbus = ERR_PTR(-ENODEV); in ci_get_platdata()
768 if (of_property_read_bool(dev->of_node, "extcon")) { in ci_get_platdata()
771 if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) in ci_get_platdata()
775 if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) in ci_get_platdata()
779 cable = &platdata->vbus_extcon; in ci_get_platdata()
780 cable->nb.notifier_call = ci_cable_notifier; in ci_get_platdata()
781 cable->edev = ext_vbus; in ci_get_platdata()
784 ret = extcon_get_state(cable->edev, EXTCON_USB); in ci_get_platdata()
786 cable->connected = true; in ci_get_platdata()
788 cable->connected = false; in ci_get_platdata()
791 cable = &platdata->id_extcon; in ci_get_platdata()
792 cable->nb.notifier_call = ci_cable_notifier; in ci_get_platdata()
793 cable->edev = ext_id; in ci_get_platdata()
796 ret = extcon_get_state(cable->edev, EXTCON_USB_HOST); in ci_get_platdata()
798 cable->connected = true; in ci_get_platdata()
800 cable->connected = false; in ci_get_platdata()
803 if (device_property_read_bool(dev, "usb-role-switch")) in ci_get_platdata()
804 ci_role_switch.fwnode = dev->fwnode; in ci_get_platdata()
806 platdata->pctl = devm_pinctrl_get(dev); in ci_get_platdata()
807 if (!IS_ERR(platdata->pctl)) { in ci_get_platdata()
810 p = pinctrl_lookup_state(platdata->pctl, "default"); in ci_get_platdata()
812 platdata->pins_default = p; in ci_get_platdata()
814 p = pinctrl_lookup_state(platdata->pctl, "host"); in ci_get_platdata()
816 platdata->pins_host = p; in ci_get_platdata()
818 p = pinctrl_lookup_state(platdata->pctl, "device"); in ci_get_platdata()
820 platdata->pins_device = p; in ci_get_platdata()
823 if (!platdata->enter_lpm) in ci_get_platdata()
824 platdata->enter_lpm = ci_hdrc_enter_lpm_common; in ci_get_platdata()
834 id = &ci->platdata->id_extcon; in ci_extcon_register()
835 id->ci = ci; in ci_extcon_register()
836 if (!IS_ERR_OR_NULL(id->edev)) { in ci_extcon_register()
837 ret = devm_extcon_register_notifier(ci->dev, id->edev, in ci_extcon_register()
838 EXTCON_USB_HOST, &id->nb); in ci_extcon_register()
840 dev_err(ci->dev, "register ID failed\n"); in ci_extcon_register()
845 vbus = &ci->platdata->vbus_extcon; in ci_extcon_register()
846 vbus->ci = ci; in ci_extcon_register()
847 if (!IS_ERR_OR_NULL(vbus->edev)) { in ci_extcon_register()
848 ret = devm_extcon_register_notifier(ci->dev, vbus->edev, in ci_extcon_register()
849 EXTCON_USB, &vbus->nb); in ci_extcon_register()
851 dev_err(ci->dev, "register VBUS failed\n"); in ci_extcon_register()
864 disable_irq_nosync(ci->irq); in ci_power_lost_work()
865 pm_runtime_get_sync(ci->dev); in ci_power_lost_work()
869 if (ci->role != role) { in ci_power_lost_work()
872 if (ci->is_otg && hw_read_otgsc(ci, OTGSC_BSV)) in ci_power_lost_work()
873 usb_gadget_vbus_connect(&ci->gadget); in ci_power_lost_work()
876 pm_runtime_put_sync(ci->dev); in ci_power_lost_work()
877 enable_irq(ci->irq); in ci_power_lost_work()
899 ret = -ENOMEM; in ci_hdrc_add_device()
903 pdev->dev.parent = dev; in ci_hdrc_add_device()
904 device_set_of_node_from_dev(&pdev->dev, dev); in ci_hdrc_add_device()
930 int id = pdev->id; in ci_hdrc_remove_device()
952 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
954 else if (ci->roles[CI_ROLE_HOST]) in ci_hdrc_query_available_role()
956 else if (ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
967 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_role_destroy()
973 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) in ci_get_otg_capable()
974 ci->is_otg = false; in ci_get_otg_capable()
976 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, in ci_get_otg_capable()
979 if (ci->is_otg) { in ci_get_otg_capable()
980 dev_dbg(ci->dev, "It is OTG capable controller\n"); in ci_get_otg_capable()
992 if (ci->role != CI_ROLE_END) in role_show()
993 return sprintf(buf, "%s\n", ci_role(ci)->name); in role_show()
1005 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) { in role_store()
1006 dev_warn(dev, "Current configuration is not dual-role, quit\n"); in role_store()
1007 return -EPERM; in role_store()
1011 if (!strncmp(buf, ci->roles[role]->name, in role_store()
1012 strlen(ci->roles[role]->name))) in role_store()
1016 return -EINVAL; in role_store()
1018 mutex_lock(&ci->mutex); in role_store()
1020 if (role == ci->role) { in role_store()
1021 mutex_unlock(&ci->mutex); in role_store()
1026 disable_irq(ci->irq); in role_store()
1029 if (!ret && ci->role == CI_ROLE_GADGET) in role_store()
1031 enable_irq(ci->irq); in role_store()
1033 mutex_unlock(&ci->mutex); in role_store()
1047 struct device *dev = &pdev->dev; in ci_hdrc_probe()
1056 return -ENODEV; in ci_hdrc_probe()
1065 return -ENOMEM; in ci_hdrc_probe()
1067 spin_lock_init(&ci->lock); in ci_hdrc_probe()
1068 mutex_init(&ci->mutex); in ci_hdrc_probe()
1069 INIT_WORK(&ci->power_lost_work, ci_power_lost_work); in ci_hdrc_probe()
1071 ci->dev = dev; in ci_hdrc_probe()
1072 ci->platdata = dev_get_platdata(dev); in ci_hdrc_probe()
1073 ci->imx28_write_fix = !!(ci->platdata->flags & in ci_hdrc_probe()
1075 ci->supports_runtime_pm = !!(ci->platdata->flags & in ci_hdrc_probe()
1077 ci->has_portsc_pec_bug = !!(ci->platdata->flags & in ci_hdrc_probe()
1084 return -ENODEV; in ci_hdrc_probe()
1091 if (ci->platdata->phy) { in ci_hdrc_probe()
1092 ci->phy = ci->platdata->phy; in ci_hdrc_probe()
1093 } else if (ci->platdata->usb_phy) { in ci_hdrc_probe()
1094 ci->usb_phy = ci->platdata->usb_phy; in ci_hdrc_probe()
1097 ci->phy = devm_phy_get(dev->parent, "usb-phy"); in ci_hdrc_probe()
1099 if (PTR_ERR(ci->phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1100 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1102 } else if (IS_ERR(ci->phy)) { in ci_hdrc_probe()
1103 ci->phy = NULL; in ci_hdrc_probe()
1106 /* Look for a legacy USB PHY from device-tree next */ in ci_hdrc_probe()
1107 if (!ci->phy) { in ci_hdrc_probe()
1108 ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, in ci_hdrc_probe()
1111 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1112 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1114 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1115 ci->usb_phy = NULL; in ci_hdrc_probe()
1120 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1121 ci->usb_phy = devm_usb_get_phy(dev->parent, in ci_hdrc_probe()
1124 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1125 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1127 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1128 ci->usb_phy = NULL; in ci_hdrc_probe()
1133 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1134 ret = -ENXIO; in ci_hdrc_probe()
1145 ci->hw_bank.phys = res->start; in ci_hdrc_probe()
1147 ci->irq = platform_get_irq(pdev, 0); in ci_hdrc_probe()
1148 if (ci->irq < 0) { in ci_hdrc_probe()
1149 ret = ci->irq; in ci_hdrc_probe()
1155 dr_mode = ci->platdata->dr_mode; in ci_hdrc_probe()
1160 if (ret == -ENXIO) in ci_hdrc_probe()
1161 dev_info(dev, "doesn't support host\n"); in ci_hdrc_probe()
1170 if (ret == -ENXIO) in ci_hdrc_probe()
1171 dev_info(dev, "doesn't support gadget\n"); in ci_hdrc_probe()
1177 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1179 ret = -ENODEV; in ci_hdrc_probe()
1183 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1193 ci->role_switch = usb_role_switch_register(dev, in ci_hdrc_probe()
1195 if (IS_ERR(ci->role_switch)) { in ci_hdrc_probe()
1196 ret = PTR_ERR(ci->role_switch); in ci_hdrc_probe()
1201 ci->role = ci_get_role(ci); in ci_hdrc_probe()
1204 if (ci->role == CI_ROLE_GADGET) { in ci_hdrc_probe()
1210 ret = ci_role_start(ci, ci->role); in ci_hdrc_probe()
1213 ci_role(ci)->name); in ci_hdrc_probe()
1218 ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED, in ci_hdrc_probe()
1219 ci->platdata->name, ci); in ci_hdrc_probe()
1227 if (ci->supports_runtime_pm) { in ci_hdrc_probe()
1228 pm_runtime_set_active(&pdev->dev); in ci_hdrc_probe()
1229 pm_runtime_enable(&pdev->dev); in ci_hdrc_probe()
1230 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); in ci_hdrc_probe()
1231 pm_runtime_mark_last_busy(ci->dev); in ci_hdrc_probe()
1232 pm_runtime_use_autosuspend(&pdev->dev); in ci_hdrc_probe()
1238 device_set_wakeup_capable(&pdev->dev, true); in ci_hdrc_probe()
1244 if (ci->role_switch) in ci_hdrc_probe()
1245 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_probe()
1247 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_probe()
1265 if (ci->role_switch) in ci_hdrc_remove()
1266 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_remove()
1268 if (ci->supports_runtime_pm) { in ci_hdrc_remove()
1269 pm_runtime_get_sync(&pdev->dev); in ci_hdrc_remove()
1270 pm_runtime_disable(&pdev->dev); in ci_hdrc_remove()
1271 pm_runtime_put_noidle(&pdev->dev); in ci_hdrc_remove()
1285 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_suspend_for_srp()
1297 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_wakeup_by_srp()
1298 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { in ci_otg_fsm_wakeup_by_srp()
1300 ci->fsm.a_srp_det = 1; in ci_otg_fsm_wakeup_by_srp()
1301 ci->fsm.a_bus_drop = 0; in ci_otg_fsm_wakeup_by_srp()
1303 ci->fsm.id = 1; in ci_otg_fsm_wakeup_by_srp()
1311 disable_irq(ci->irq); in ci_controller_suspend()
1313 if (ci->platdata->phy_clkgate_delay_us) in ci_controller_suspend()
1314 usleep_range(ci->platdata->phy_clkgate_delay_us, in ci_controller_suspend()
1315 ci->platdata->phy_clkgate_delay_us + 50); in ci_controller_suspend()
1316 usb_phy_set_suspend(ci->usb_phy, 1); in ci_controller_suspend()
1317 ci->in_lpm = true; in ci_controller_suspend()
1318 enable_irq(ci->irq); in ci_controller_suspend()
1332 cable_id = &ci->platdata->id_extcon; in ci_extcon_wakeup_int()
1333 cable_vbus = &ci->platdata->vbus_extcon; in ci_extcon_wakeup_int()
1335 if ((!IS_ERR(cable_id->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1336 && ci->is_otg && in ci_extcon_wakeup_int()
1340 if ((!IS_ERR(cable_vbus->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1341 && ci->is_otg && in ci_extcon_wakeup_int()
1353 if (!ci->in_lpm) { in ci_controller_resume()
1364 if (ci->usb_phy) { in ci_controller_resume()
1365 usb_phy_set_suspend(ci->usb_phy, 0); in ci_controller_resume()
1366 usb_phy_set_wakeup(ci->usb_phy, false); in ci_controller_resume()
1370 ci->in_lpm = false; in ci_controller_resume()
1371 if (ci->wakeup_int) { in ci_controller_resume()
1372 ci->wakeup_int = false; in ci_controller_resume()
1373 pm_runtime_mark_last_busy(ci->dev); in ci_controller_resume()
1374 pm_runtime_put_autosuspend(ci->dev); in ci_controller_resume()
1375 enable_irq(ci->irq); in ci_controller_resume()
1389 if (ci->wq) in ci_suspend()
1390 flush_workqueue(ci->wq); in ci_suspend()
1397 if (ci->in_lpm) in ci_suspend()
1400 if (ci->in_lpm) { in ci_suspend()
1406 if (ci->role != CI_ROLE_END && ci_role(ci)->suspend) in ci_suspend()
1407 ci_role(ci)->suspend(ci); in ci_suspend()
1413 usb_phy_set_wakeup(ci->usb_phy, true); in ci_suspend()
1414 enable_irq_wake(ci->irq); in ci_suspend()
1436 disable_irq_wake(ci->irq); in ci_resume()
1443 /* shutdown and re-init for phy */ in ci_resume()
1449 if (ci->role != CI_ROLE_END && ci_role(ci)->resume) in ci_resume()
1450 ci_role(ci)->resume(ci, power_lost); in ci_resume()
1453 queue_work(system_freezable_wq, &ci->power_lost_work); in ci_resume()
1455 if (ci->supports_runtime_pm) { in ci_resume()
1471 if (ci->in_lpm) { in ci_runtime_suspend()
1479 usb_phy_set_wakeup(ci->usb_phy, true); in ci_runtime_suspend()