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>
106 ci->hw_bank.regmap[i] = in hw_alloc_regmap()
107 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + in hw_alloc_regmap()
111 ci->hw_bank.regmap[i] = ci->hw_bank.op + in hw_alloc_regmap()
112 4 * (i - OP_ENDPTCTRL) + in hw_alloc_regmap()
171 return -EINVAL; in hw_port_test_set()
203 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC; in ci_hdrc_enter_lpm_common()
204 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm))); in ci_hdrc_enter_lpm_common()
207 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm_common()
208 PORTSC_PHCD(ci->hw_bank.lpm)); in ci_hdrc_enter_lpm_common()
210 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm_common()
216 return ci->platdata->enter_lpm(ci, enable); in ci_hdrc_enter_lpm()
224 ci->hw_bank.abs = base; in hw_device_init()
226 ci->hw_bank.cap = ci->hw_bank.abs; in hw_device_init()
227 ci->hw_bank.cap += ci->platdata->capoffset; in hw_device_init()
228 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff); in hw_device_init()
233 ci->hw_bank.lpm = reg; in hw_device_init()
236 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; in hw_device_init()
237 ci->hw_bank.size += OP_LAST; in hw_device_init()
238 ci->hw_bank.size /= sizeof(u32); in hw_device_init()
242 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ in hw_device_init()
244 if (ci->hw_ep_max > ENDPT_MAX) in hw_device_init()
245 return -ENODEV; in hw_device_init()
255 ci->rev = ci_get_revision(ci); in hw_device_init()
257 dev_dbg(ci->dev, in hw_device_init()
259 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); in hw_device_init()
274 switch (ci->platdata->phy_mode) { in hw_phymode_configure()
300 if (ci->hw_bank.lpm) { in hw_phymode_configure()
323 if (ci->phy) { in _ci_usb_phy_init()
324 ret = phy_init(ci->phy); in _ci_usb_phy_init()
328 ret = phy_power_on(ci->phy); in _ci_usb_phy_init()
330 phy_exit(ci->phy); in _ci_usb_phy_init()
334 ret = usb_phy_init(ci->usb_phy); in _ci_usb_phy_init()
347 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_exit()
350 if (ci->phy) { in ci_usb_phy_exit()
351 phy_power_off(ci->phy); in ci_usb_phy_exit()
352 phy_exit(ci->phy); in ci_usb_phy_exit()
354 usb_phy_shutdown(ci->usb_phy); in ci_usb_phy_exit()
368 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_init()
371 switch (ci->platdata->phy_mode) { in ci_usb_phy_init()
412 phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE); in ci_platform_configure()
414 if (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING) in ci_platform_configure()
420 phy_set_mode(ci->phy, PHY_MODE_USB_HOST); in ci_platform_configure()
422 if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING) in ci_platform_configure()
427 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) { in ci_platform_configure()
428 if (ci->hw_bank.lpm) in ci_platform_configure()
434 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA) in ci_platform_configure()
437 hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16); in ci_platform_configure()
439 if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST) in ci_platform_configure()
441 ci->platdata->ahb_burst_config); in ci_platform_configure()
445 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST) in ci_platform_configure()
447 ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK)); in ci_platform_configure()
449 if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST) in ci_platform_configure()
451 ci->platdata->rx_burst_size); in ci_platform_configure()
469 return -ETIMEDOUT; in hw_controller_reset()
491 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret); in hw_device_reset()
495 if (ci->platdata->notify_event) { in hw_device_reset()
496 ret = ci->platdata->notify_event(ci, in hw_device_reset()
509 dev_err(ci->dev, "cannot enter in %s device mode\n", in hw_device_reset()
510 ci_role(ci)->name); in hw_device_reset()
511 dev_err(ci->dev, "lpm = %i\n", ci->hw_bank.lpm); in hw_device_reset()
512 return -ENODEV; in hw_device_reset()
526 if (ci->in_lpm) { in ci_irq_handler()
531 if (ci->wakeup_int) in ci_irq_handler()
535 ci->wakeup_int = true; in ci_irq_handler()
536 pm_runtime_get(ci->dev); in ci_irq_handler()
540 if (ci->is_otg) { in ci_irq_handler()
553 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { in ci_irq_handler()
554 ci->id_event = true; in ci_irq_handler()
565 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { in ci_irq_handler()
566 ci->b_sess_valid_event = true; in ci_irq_handler()
574 if (ci->role != CI_ROLE_END) in ci_irq_handler()
575 ret = ci_role(ci)->irq(ci); in ci_irq_handler()
585 ci_irq_handler(ci->irq, ci); in ci_irq()
593 struct ci_hdrc *ci = cbl->ci; in ci_cable_notifier()
595 cbl->connected = event; in ci_cable_notifier()
596 cbl->changed = true; in ci_cable_notifier()
608 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_get()
610 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_get()
622 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
623 cable->changed = true; in ci_usb_role_switch_set()
624 cable->connected = true; in ci_usb_role_switch_set()
625 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
626 cable->changed = true; in ci_usb_role_switch_set()
627 cable->connected = false; in ci_usb_role_switch_set()
629 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
630 cable->changed = true; in ci_usb_role_switch_set()
631 cable->connected = false; in ci_usb_role_switch_set()
632 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
633 cable->changed = true; in ci_usb_role_switch_set()
634 cable->connected = true; in ci_usb_role_switch_set()
636 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
637 cable->changed = true; in ci_usb_role_switch_set()
638 cable->connected = false; in ci_usb_role_switch_set()
639 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
640 cable->changed = true; in ci_usb_role_switch_set()
641 cable->connected = false; in ci_usb_role_switch_set()
652 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { in ci_get_role()
653 if (ci->is_otg) { in ci_get_role()
658 * If the controller is not OTG capable, but support in ci_get_role()
665 role = ci->roles[CI_ROLE_HOST] ? CI_ROLE_HOST in ci_get_role()
685 if (!platdata->phy_mode) in ci_get_platdata()
686 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); in ci_get_platdata()
688 if (!platdata->dr_mode) in ci_get_platdata()
689 platdata->dr_mode = usb_get_dr_mode(dev); in ci_get_platdata()
691 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN) in ci_get_platdata()
692 platdata->dr_mode = USB_DR_MODE_OTG; in ci_get_platdata()
694 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) { in ci_get_platdata()
696 platdata->reg_vbus = devm_regulator_get_optional(dev, "vbus"); in ci_get_platdata()
697 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { in ci_get_platdata()
698 return -EPROBE_DEFER; in ci_get_platdata()
699 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { in ci_get_platdata()
701 platdata->reg_vbus = NULL; in ci_get_platdata()
702 } else if (IS_ERR(platdata->reg_vbus)) { in ci_get_platdata()
704 PTR_ERR(platdata->reg_vbus)); in ci_get_platdata()
705 return PTR_ERR(platdata->reg_vbus); in ci_get_platdata()
707 /* Get TPL support */ in ci_get_platdata()
708 if (!platdata->tpl_support) in ci_get_platdata()
709 platdata->tpl_support = in ci_get_platdata()
710 of_usb_host_tpl_support(dev->of_node); in ci_get_platdata()
713 if (platdata->dr_mode == USB_DR_MODE_OTG) { in ci_get_platdata()
714 /* We can support HNP and SRP of OTG 2.0 */ in ci_get_platdata()
715 platdata->ci_otg_caps.otg_rev = 0x0200; in ci_get_platdata()
716 platdata->ci_otg_caps.hnp_support = true; in ci_get_platdata()
717 platdata->ci_otg_caps.srp_support = true; in ci_get_platdata()
720 ret = of_usb_update_otg_caps(dev->of_node, in ci_get_platdata()
721 &platdata->ci_otg_caps); in ci_get_platdata()
727 platdata->flags |= CI_HDRC_FORCE_FULLSPEED; in ci_get_platdata()
729 of_property_read_u32(dev->of_node, "phy-clkgate-delay-us", in ci_get_platdata()
730 &platdata->phy_clkgate_delay_us); in ci_get_platdata()
732 platdata->itc_setting = 1; in ci_get_platdata()
734 of_property_read_u32(dev->of_node, "itc-setting", in ci_get_platdata()
735 &platdata->itc_setting); in ci_get_platdata()
737 ret = of_property_read_u32(dev->of_node, "ahb-burst-config", in ci_get_platdata()
738 &platdata->ahb_burst_config); in ci_get_platdata()
740 platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST; in ci_get_platdata()
741 } else if (ret != -EINVAL) { in ci_get_platdata()
742 dev_err(dev, "failed to get ahb-burst-config\n"); in ci_get_platdata()
746 ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword", in ci_get_platdata()
747 &platdata->tx_burst_size); in ci_get_platdata()
749 platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST; in ci_get_platdata()
750 } else if (ret != -EINVAL) { in ci_get_platdata()
751 dev_err(dev, "failed to get tx-burst-size-dword\n"); in ci_get_platdata()
755 ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword", in ci_get_platdata()
756 &platdata->rx_burst_size); in ci_get_platdata()
758 platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST; in ci_get_platdata()
759 } else if (ret != -EINVAL) { in ci_get_platdata()
760 dev_err(dev, "failed to get rx-burst-size-dword\n"); in ci_get_platdata()
764 if (of_property_read_bool(dev->of_node, "non-zero-ttctrl-ttha")) in ci_get_platdata()
765 platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA; in ci_get_platdata()
767 ext_id = ERR_PTR(-ENODEV); in ci_get_platdata()
768 ext_vbus = ERR_PTR(-ENODEV); in ci_get_platdata()
769 if (of_property_present(dev->of_node, "extcon")) { in ci_get_platdata()
772 if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) in ci_get_platdata()
776 if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) in ci_get_platdata()
780 cable = &platdata->vbus_extcon; in ci_get_platdata()
781 cable->nb.notifier_call = ci_cable_notifier; in ci_get_platdata()
782 cable->edev = ext_vbus; in ci_get_platdata()
785 ret = extcon_get_state(cable->edev, EXTCON_USB); in ci_get_platdata()
787 cable->connected = true; in ci_get_platdata()
789 cable->connected = false; in ci_get_platdata()
792 cable = &platdata->id_extcon; in ci_get_platdata()
793 cable->nb.notifier_call = ci_cable_notifier; in ci_get_platdata()
794 cable->edev = ext_id; in ci_get_platdata()
797 ret = extcon_get_state(cable->edev, EXTCON_USB_HOST); in ci_get_platdata()
799 cable->connected = true; in ci_get_platdata()
801 cable->connected = false; in ci_get_platdata()
804 if (device_property_read_bool(dev, "usb-role-switch")) in ci_get_platdata()
805 ci_role_switch.fwnode = dev->fwnode; in ci_get_platdata()
807 platdata->pctl = devm_pinctrl_get(dev); in ci_get_platdata()
808 if (!IS_ERR(platdata->pctl)) { in ci_get_platdata()
811 p = pinctrl_lookup_state(platdata->pctl, "default"); in ci_get_platdata()
813 platdata->pins_default = p; in ci_get_platdata()
815 p = pinctrl_lookup_state(platdata->pctl, "host"); in ci_get_platdata()
817 platdata->pins_host = p; in ci_get_platdata()
819 p = pinctrl_lookup_state(platdata->pctl, "device"); in ci_get_platdata()
821 platdata->pins_device = p; in ci_get_platdata()
824 if (!platdata->enter_lpm) in ci_get_platdata()
825 platdata->enter_lpm = ci_hdrc_enter_lpm_common; in ci_get_platdata()
835 id = &ci->platdata->id_extcon; in ci_extcon_register()
836 id->ci = ci; in ci_extcon_register()
837 if (!IS_ERR_OR_NULL(id->edev)) { in ci_extcon_register()
838 ret = devm_extcon_register_notifier(ci->dev, id->edev, in ci_extcon_register()
839 EXTCON_USB_HOST, &id->nb); in ci_extcon_register()
841 dev_err(ci->dev, "register ID failed\n"); in ci_extcon_register()
846 vbus = &ci->platdata->vbus_extcon; in ci_extcon_register()
847 vbus->ci = ci; in ci_extcon_register()
848 if (!IS_ERR_OR_NULL(vbus->edev)) { in ci_extcon_register()
849 ret = devm_extcon_register_notifier(ci->dev, vbus->edev, in ci_extcon_register()
850 EXTCON_USB, &vbus->nb); in ci_extcon_register()
852 dev_err(ci->dev, "register VBUS failed\n"); in ci_extcon_register()
865 disable_irq_nosync(ci->irq); in ci_power_lost_work()
866 pm_runtime_get_sync(ci->dev); in ci_power_lost_work()
870 if (ci->role != role) { in ci_power_lost_work()
873 if (ci->is_otg && hw_read_otgsc(ci, OTGSC_BSV)) in ci_power_lost_work()
874 usb_gadget_vbus_connect(&ci->gadget); in ci_power_lost_work()
877 pm_runtime_put_sync(ci->dev); in ci_power_lost_work()
878 enable_irq(ci->irq); in ci_power_lost_work()
900 ret = -ENOMEM; in ci_hdrc_add_device()
904 pdev->dev.parent = dev; in ci_hdrc_add_device()
905 device_set_of_node_from_dev(&pdev->dev, dev); in ci_hdrc_add_device()
919 dev_pm_domain_detach(&pdev->dev, false); in ci_hdrc_add_device()
933 int id = pdev->id; in ci_hdrc_remove_device()
955 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
957 else if (ci->roles[CI_ROLE_HOST]) in ci_hdrc_query_available_role()
959 else if (ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
970 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_role_destroy()
976 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) in ci_get_otg_capable()
977 ci->is_otg = false; in ci_get_otg_capable()
979 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, in ci_get_otg_capable()
982 if (ci->is_otg) { in ci_get_otg_capable()
983 dev_dbg(ci->dev, "It is OTG capable controller\n"); in ci_get_otg_capable()
995 if (ci->role != CI_ROLE_END) in role_show()
996 return sprintf(buf, "%s\n", ci_role(ci)->name); in role_show()
1008 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) { in role_store()
1009 dev_warn(dev, "Current configuration is not dual-role, quit\n"); in role_store()
1010 return -EPERM; in role_store()
1014 if (!strncmp(buf, ci->roles[role]->name, in role_store()
1015 strlen(ci->roles[role]->name))) in role_store()
1019 return -EINVAL; in role_store()
1021 mutex_lock(&ci->mutex); in role_store()
1023 if (role == ci->role) { in role_store()
1024 mutex_unlock(&ci->mutex); in role_store()
1029 disable_irq(ci->irq); in role_store()
1032 if (!ret && ci->role == CI_ROLE_GADGET) in role_store()
1034 enable_irq(ci->irq); in role_store()
1036 mutex_unlock(&ci->mutex); in role_store()
1050 struct device *dev = &pdev->dev; in ci_hdrc_probe()
1059 return -ENODEV; in ci_hdrc_probe()
1068 return -ENOMEM; in ci_hdrc_probe()
1070 spin_lock_init(&ci->lock); in ci_hdrc_probe()
1071 mutex_init(&ci->mutex); in ci_hdrc_probe()
1072 INIT_WORK(&ci->power_lost_work, ci_power_lost_work); in ci_hdrc_probe()
1074 ci->dev = dev; in ci_hdrc_probe()
1075 ci->platdata = dev_get_platdata(dev); in ci_hdrc_probe()
1076 ci->imx28_write_fix = !!(ci->platdata->flags & in ci_hdrc_probe()
1078 ci->supports_runtime_pm = !!(ci->platdata->flags & in ci_hdrc_probe()
1080 ci->has_portsc_pec_bug = !!(ci->platdata->flags & in ci_hdrc_probe()
1082 ci->has_short_pkt_limit = !!(ci->platdata->flags & in ci_hdrc_probe()
1089 return -ENODEV; in ci_hdrc_probe()
1096 if (ci->platdata->phy) { in ci_hdrc_probe()
1097 ci->phy = ci->platdata->phy; in ci_hdrc_probe()
1098 } else if (ci->platdata->usb_phy) { in ci_hdrc_probe()
1099 ci->usb_phy = ci->platdata->usb_phy; in ci_hdrc_probe()
1102 ci->phy = devm_phy_get(dev->parent, "usb-phy"); in ci_hdrc_probe()
1104 if (PTR_ERR(ci->phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1105 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1107 } else if (IS_ERR(ci->phy)) { in ci_hdrc_probe()
1108 ci->phy = NULL; in ci_hdrc_probe()
1111 /* Look for a legacy USB PHY from device-tree next */ in ci_hdrc_probe()
1112 if (!ci->phy) { in ci_hdrc_probe()
1113 ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, in ci_hdrc_probe()
1116 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1117 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1119 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1120 ci->usb_phy = NULL; in ci_hdrc_probe()
1125 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1126 ci->usb_phy = devm_usb_get_phy(dev->parent, in ci_hdrc_probe()
1129 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1130 ret = -EPROBE_DEFER; in ci_hdrc_probe()
1132 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1133 ci->usb_phy = NULL; in ci_hdrc_probe()
1138 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1139 ret = -ENXIO; in ci_hdrc_probe()
1150 ci->hw_bank.phys = res->start; in ci_hdrc_probe()
1152 ci->irq = platform_get_irq(pdev, 0); in ci_hdrc_probe()
1153 if (ci->irq < 0) { in ci_hdrc_probe()
1154 ret = ci->irq; in ci_hdrc_probe()
1160 dr_mode = ci->platdata->dr_mode; in ci_hdrc_probe()
1165 if (ret == -ENXIO) in ci_hdrc_probe()
1166 dev_info(dev, "doesn't support host\n"); in ci_hdrc_probe()
1175 if (ret == -ENXIO) in ci_hdrc_probe()
1176 dev_info(dev, "doesn't support gadget\n"); in ci_hdrc_probe()
1182 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1184 ret = -ENODEV; in ci_hdrc_probe()
1188 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1198 ci->role_switch = usb_role_switch_register(dev, in ci_hdrc_probe()
1200 if (IS_ERR(ci->role_switch)) { in ci_hdrc_probe()
1201 ret = PTR_ERR(ci->role_switch); in ci_hdrc_probe()
1206 ci->role = ci_get_role(ci); in ci_hdrc_probe()
1209 if (ci->role == CI_ROLE_GADGET) { in ci_hdrc_probe()
1215 ret = ci_role_start(ci, ci->role); in ci_hdrc_probe()
1218 ci_role(ci)->name); in ci_hdrc_probe()
1223 ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED, in ci_hdrc_probe()
1224 ci->platdata->name, ci); in ci_hdrc_probe()
1232 if (ci->supports_runtime_pm) { in ci_hdrc_probe()
1233 pm_runtime_set_active(&pdev->dev); in ci_hdrc_probe()
1234 pm_runtime_enable(&pdev->dev); in ci_hdrc_probe()
1235 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); in ci_hdrc_probe()
1236 pm_runtime_mark_last_busy(ci->dev); in ci_hdrc_probe()
1237 pm_runtime_use_autosuspend(&pdev->dev); in ci_hdrc_probe()
1243 device_set_wakeup_capable(&pdev->dev, true); in ci_hdrc_probe()
1249 if (ci->role_switch) in ci_hdrc_probe()
1250 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_probe()
1252 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_probe()
1270 if (ci->role_switch) in ci_hdrc_remove()
1271 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_remove()
1273 if (ci->supports_runtime_pm) { in ci_hdrc_remove()
1274 pm_runtime_get_sync(&pdev->dev); in ci_hdrc_remove()
1275 pm_runtime_disable(&pdev->dev); in ci_hdrc_remove()
1276 pm_runtime_put_noidle(&pdev->dev); in ci_hdrc_remove()
1290 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_suspend_for_srp()
1302 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_wakeup_by_srp()
1303 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { in ci_otg_fsm_wakeup_by_srp()
1305 ci->fsm.a_srp_det = 1; in ci_otg_fsm_wakeup_by_srp()
1306 ci->fsm.a_bus_drop = 0; in ci_otg_fsm_wakeup_by_srp()
1308 ci->fsm.id = 1; in ci_otg_fsm_wakeup_by_srp()
1316 disable_irq(ci->irq); in ci_controller_suspend()
1318 if (ci->platdata->phy_clkgate_delay_us) in ci_controller_suspend()
1319 usleep_range(ci->platdata->phy_clkgate_delay_us, in ci_controller_suspend()
1320 ci->platdata->phy_clkgate_delay_us + 50); in ci_controller_suspend()
1321 usb_phy_set_suspend(ci->usb_phy, 1); in ci_controller_suspend()
1322 ci->in_lpm = true; in ci_controller_suspend()
1323 enable_irq(ci->irq); in ci_controller_suspend()
1337 cable_id = &ci->platdata->id_extcon; in ci_extcon_wakeup_int()
1338 cable_vbus = &ci->platdata->vbus_extcon; in ci_extcon_wakeup_int()
1340 if ((!IS_ERR(cable_id->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1341 && ci->is_otg && in ci_extcon_wakeup_int()
1345 if ((!IS_ERR(cable_vbus->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1346 && ci->is_otg && in ci_extcon_wakeup_int()
1358 if (!ci->in_lpm) { in ci_controller_resume()
1369 if (ci->usb_phy) { in ci_controller_resume()
1370 usb_phy_set_suspend(ci->usb_phy, 0); in ci_controller_resume()
1371 usb_phy_set_wakeup(ci->usb_phy, false); in ci_controller_resume()
1375 ci->in_lpm = false; in ci_controller_resume()
1376 if (ci->wakeup_int) { in ci_controller_resume()
1377 ci->wakeup_int = false; in ci_controller_resume()
1378 pm_runtime_put_autosuspend(ci->dev); in ci_controller_resume()
1379 enable_irq(ci->irq); in ci_controller_resume()
1393 if (ci->wq) in ci_suspend()
1394 flush_workqueue(ci->wq); in ci_suspend()
1401 if (ci->in_lpm) in ci_suspend()
1404 if (ci->in_lpm) { in ci_suspend()
1410 if (ci->role != CI_ROLE_END && ci_role(ci)->suspend) in ci_suspend()
1411 ci_role(ci)->suspend(ci); in ci_suspend()
1417 usb_phy_set_wakeup(ci->usb_phy, true); in ci_suspend()
1418 enable_irq_wake(ci->irq); in ci_suspend()
1440 disable_irq_wake(ci->irq); in ci_resume()
1447 /* shutdown and re-init for phy */ in ci_resume()
1453 if (ci->role != CI_ROLE_END && ci_role(ci)->resume) in ci_resume()
1454 ci_role(ci)->resume(ci, power_lost); in ci_resume()
1457 queue_work(system_freezable_wq, &ci->power_lost_work); in ci_resume()
1459 if (ci->supports_runtime_pm) { in ci_resume()
1475 if (ci->in_lpm) { in ci_runtime_suspend()
1483 usb_phy_set_wakeup(ci->usb_phy, true); in ci_runtime_suspend()