Lines Matching refs:ci
98 static void hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) in hw_alloc_regmap() argument
103 ci->hw_bank.regmap[i] = in hw_alloc_regmap()
104 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + in hw_alloc_regmap()
108 ci->hw_bank.regmap[i] = ci->hw_bank.op + in hw_alloc_regmap()
116 static enum ci_revision ci_get_revision(struct ci_hdrc *ci) in ci_get_revision() argument
118 int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION); in ci_get_revision()
122 rev = hw_read_id_reg(ci, ID_ID, REVISION) in ci_get_revision()
139 u32 hw_read_intr_enable(struct ci_hdrc *ci) in hw_read_intr_enable() argument
141 return hw_read(ci, OP_USBINTR, ~0); in hw_read_intr_enable()
151 u32 hw_read_intr_status(struct ci_hdrc *ci) in hw_read_intr_status() argument
153 return hw_read(ci, OP_USBSTS, ~0); in hw_read_intr_status()
163 int hw_port_test_set(struct ci_hdrc *ci, u8 mode) in hw_port_test_set() argument
170 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC)); in hw_port_test_set()
181 u8 hw_port_test_get(struct ci_hdrc *ci) in hw_port_test_get() argument
183 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); in hw_port_test_get()
198 static void ci_hdrc_enter_lpm_common(struct ci_hdrc *ci, bool enable) in ci_hdrc_enter_lpm_common() argument
200 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC; in ci_hdrc_enter_lpm_common()
201 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm))); in ci_hdrc_enter_lpm_common()
204 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm_common()
205 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()
211 static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) in ci_hdrc_enter_lpm() argument
213 return ci->platdata->enter_lpm(ci, enable); in ci_hdrc_enter_lpm()
216 static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) in hw_device_init() argument
221 ci->hw_bank.abs = base; in hw_device_init()
223 ci->hw_bank.cap = ci->hw_bank.abs; in hw_device_init()
224 ci->hw_bank.cap += ci->platdata->capoffset; in hw_device_init()
225 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff); in hw_device_init()
227 hw_alloc_regmap(ci, false); in hw_device_init()
228 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> in hw_device_init()
230 ci->hw_bank.lpm = reg; in hw_device_init()
232 hw_alloc_regmap(ci, !!reg); in hw_device_init()
233 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; in hw_device_init()
234 ci->hw_bank.size += OP_LAST; in hw_device_init()
235 ci->hw_bank.size /= sizeof(u32); in hw_device_init()
237 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> in hw_device_init()
239 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ in hw_device_init()
241 if (ci->hw_ep_max > ENDPT_MAX) in hw_device_init()
244 ci_hdrc_enter_lpm(ci, false); in hw_device_init()
247 hw_write(ci, OP_USBINTR, 0xffffffff, 0); in hw_device_init()
250 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff); in hw_device_init()
252 ci->rev = ci_get_revision(ci); in hw_device_init()
254 dev_dbg(ci->dev, in hw_device_init()
256 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); in hw_device_init()
267 void hw_phymode_configure(struct ci_hdrc *ci) in hw_phymode_configure() argument
271 switch (ci->platdata->phy_mode) { in hw_phymode_configure()
297 if (ci->hw_bank.lpm) { in hw_phymode_configure()
298 hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm); in hw_phymode_configure()
300 hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS); in hw_phymode_configure()
302 hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc); in hw_phymode_configure()
304 hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS); in hw_phymode_configure()
316 static int _ci_usb_phy_init(struct ci_hdrc *ci) in _ci_usb_phy_init() argument
320 if (ci->phy) { in _ci_usb_phy_init()
321 ret = phy_init(ci->phy); in _ci_usb_phy_init()
325 ret = phy_power_on(ci->phy); in _ci_usb_phy_init()
327 phy_exit(ci->phy); in _ci_usb_phy_init()
331 ret = usb_phy_init(ci->usb_phy); in _ci_usb_phy_init()
342 static void ci_usb_phy_exit(struct ci_hdrc *ci) in ci_usb_phy_exit() argument
344 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_exit()
347 if (ci->phy) { in ci_usb_phy_exit()
348 phy_power_off(ci->phy); in ci_usb_phy_exit()
349 phy_exit(ci->phy); in ci_usb_phy_exit()
351 usb_phy_shutdown(ci->usb_phy); in ci_usb_phy_exit()
361 static int ci_usb_phy_init(struct ci_hdrc *ci) in ci_usb_phy_init() argument
365 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL) in ci_usb_phy_init()
368 switch (ci->platdata->phy_mode) { in ci_usb_phy_init()
372 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
377 hw_phymode_configure(ci); in ci_usb_phy_init()
381 hw_phymode_configure(ci); in ci_usb_phy_init()
382 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
387 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
401 void ci_platform_configure(struct ci_hdrc *ci) in ci_platform_configure() argument
405 is_device_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_DC; in ci_platform_configure()
406 is_host_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_HC; in ci_platform_configure()
409 phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE); in ci_platform_configure()
411 if (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING) in ci_platform_configure()
412 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, in ci_platform_configure()
417 phy_set_mode(ci->phy, PHY_MODE_USB_HOST); in ci_platform_configure()
419 if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING) in ci_platform_configure()
420 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, in ci_platform_configure()
424 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) { in ci_platform_configure()
425 if (ci->hw_bank.lpm) in ci_platform_configure()
426 hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC); in ci_platform_configure()
428 hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC); in ci_platform_configure()
431 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA) in ci_platform_configure()
432 hw_write(ci, OP_TTCTRL, TTCTRL_TTHA_MASK, TTCTRL_TTHA); in ci_platform_configure()
434 hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16); in ci_platform_configure()
436 if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST) in ci_platform_configure()
437 hw_write_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK, in ci_platform_configure()
438 ci->platdata->ahb_burst_config); in ci_platform_configure()
441 if (!hw_read_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK)) { in ci_platform_configure()
442 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST) in ci_platform_configure()
443 hw_write(ci, OP_BURSTSIZE, TX_BURST_MASK, in ci_platform_configure()
444 ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK)); in ci_platform_configure()
446 if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST) in ci_platform_configure()
447 hw_write(ci, OP_BURSTSIZE, RX_BURST_MASK, in ci_platform_configure()
448 ci->platdata->rx_burst_size); in ci_platform_configure()
458 static int hw_controller_reset(struct ci_hdrc *ci) in hw_controller_reset() argument
462 hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST); in hw_controller_reset()
463 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) { in hw_controller_reset()
478 int hw_device_reset(struct ci_hdrc *ci) in hw_device_reset() argument
483 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0); in hw_device_reset()
484 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in hw_device_reset()
486 ret = hw_controller_reset(ci); in hw_device_reset()
488 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret); in hw_device_reset()
492 if (ci->platdata->notify_event) { in hw_device_reset()
493 ret = ci->platdata->notify_event(ci, in hw_device_reset()
500 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); in hw_device_reset()
501 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC); in hw_device_reset()
503 hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); in hw_device_reset()
505 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) { in hw_device_reset()
506 dev_err(ci->dev, "cannot enter in %s device mode\n", in hw_device_reset()
507 ci_role(ci)->name); in hw_device_reset()
508 dev_err(ci->dev, "lpm = %i\n", ci->hw_bank.lpm); in hw_device_reset()
512 ci_platform_configure(ci); in hw_device_reset()
519 struct ci_hdrc *ci = data; in ci_irq_handler() local
523 if (ci->in_lpm) { in ci_irq_handler()
525 ci->wakeup_int = true; in ci_irq_handler()
526 pm_runtime_get(ci->dev); in ci_irq_handler()
530 if (ci->is_otg) { in ci_irq_handler()
531 otgsc = hw_read_otgsc(ci, ~0); in ci_irq_handler()
532 if (ci_otg_is_fsm_mode(ci)) { in ci_irq_handler()
533 ret = ci_otg_fsm_irq(ci); in ci_irq_handler()
543 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { in ci_irq_handler()
544 ci->id_event = true; in ci_irq_handler()
546 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); in ci_irq_handler()
547 ci_otg_queue_work(ci); in ci_irq_handler()
555 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { in ci_irq_handler()
556 ci->b_sess_valid_event = true; in ci_irq_handler()
558 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); in ci_irq_handler()
559 ci_otg_queue_work(ci); in ci_irq_handler()
564 if (ci->role != CI_ROLE_END) in ci_irq_handler()
565 ret = ci_role(ci)->irq(ci); in ci_irq_handler()
570 static void ci_irq(struct ci_hdrc *ci) in ci_irq() argument
575 ci_irq_handler(ci->irq, ci); in ci_irq()
583 struct ci_hdrc *ci = cbl->ci; in ci_cable_notifier() local
588 ci_irq(ci); in ci_cable_notifier()
594 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); in ci_usb_role_switch_get() local
598 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_get()
599 role = ci_role_to_usb_role(ci); in ci_usb_role_switch_get()
600 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_get()
608 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); in ci_usb_role_switch_set() local
610 enum usb_role current_role = ci_role_to_usb_role(ci); in ci_usb_role_switch_set()
614 if ((ci_role != CI_ROLE_END && !ci->roles[ci_role]) || in ci_usb_role_switch_set()
618 pm_runtime_get_sync(ci->dev); in ci_usb_role_switch_set()
620 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_set()
622 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
624 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
629 ci_irq(ci); in ci_usb_role_switch_set()
630 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_set()
631 if (ci->wq && role != USB_ROLE_NONE) in ci_usb_role_switch_set()
632 flush_workqueue(ci->wq); in ci_usb_role_switch_set()
633 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_set()
640 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
642 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
647 ci_irq(ci); in ci_usb_role_switch_set()
649 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_set()
650 pm_runtime_put_sync(ci->dev); in ci_usb_role_switch_set()
813 static int ci_extcon_register(struct ci_hdrc *ci) in ci_extcon_register() argument
818 id = &ci->platdata->id_extcon; in ci_extcon_register()
819 id->ci = ci; in ci_extcon_register()
821 ret = devm_extcon_register_notifier(ci->dev, id->edev, in ci_extcon_register()
824 dev_err(ci->dev, "register ID failed\n"); in ci_extcon_register()
829 vbus = &ci->platdata->vbus_extcon; in ci_extcon_register()
830 vbus->ci = ci; in ci_extcon_register()
832 ret = devm_extcon_register_notifier(ci->dev, vbus->edev, in ci_extcon_register()
835 dev_err(ci->dev, "register VBUS failed\n"); in ci_extcon_register()
910 struct ci_hdrc *ci = platform_get_drvdata(pdev); in ci_hdrc_query_available_role() local
912 if (!ci) in ci_hdrc_query_available_role()
914 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
916 else if (ci->roles[CI_ROLE_HOST]) in ci_hdrc_query_available_role()
918 else if (ci->roles[CI_ROLE_GADGET]) in ci_hdrc_query_available_role()
925 static inline void ci_role_destroy(struct ci_hdrc *ci) in ci_role_destroy() argument
927 ci_hdrc_gadget_destroy(ci); in ci_role_destroy()
928 ci_hdrc_host_destroy(ci); in ci_role_destroy()
929 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_role_destroy()
930 ci_hdrc_otg_destroy(ci); in ci_role_destroy()
933 static void ci_get_otg_capable(struct ci_hdrc *ci) in ci_get_otg_capable() argument
935 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) in ci_get_otg_capable()
936 ci->is_otg = false; in ci_get_otg_capable()
938 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, in ci_get_otg_capable()
941 if (ci->is_otg) { in ci_get_otg_capable()
942 dev_dbg(ci->dev, "It is OTG capable controller\n"); in ci_get_otg_capable()
944 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, in ci_get_otg_capable()
952 struct ci_hdrc *ci = dev_get_drvdata(dev); in role_show() local
954 if (ci->role != CI_ROLE_END) in role_show()
955 return sprintf(buf, "%s\n", ci_role(ci)->name); in role_show()
963 struct ci_hdrc *ci = dev_get_drvdata(dev); in role_store() local
967 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) { in role_store()
973 if (!strncmp(buf, ci->roles[role]->name, in role_store()
974 strlen(ci->roles[role]->name))) in role_store()
977 if (role == CI_ROLE_END || role == ci->role) in role_store()
981 disable_irq(ci->irq); in role_store()
982 ci_role_stop(ci); in role_store()
983 ret = ci_role_start(ci, role); in role_store()
984 if (!ret && ci->role == CI_ROLE_GADGET) in role_store()
985 ci_handle_vbus_change(ci); in role_store()
986 enable_irq(ci->irq); in role_store()
997 ATTRIBUTE_GROUPS(ci);
1002 struct ci_hdrc *ci; in ci_hdrc_probe() local
1018 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); in ci_hdrc_probe()
1019 if (!ci) in ci_hdrc_probe()
1022 spin_lock_init(&ci->lock); in ci_hdrc_probe()
1023 ci->dev = dev; in ci_hdrc_probe()
1024 ci->platdata = dev_get_platdata(dev); in ci_hdrc_probe()
1025 ci->imx28_write_fix = !!(ci->platdata->flags & in ci_hdrc_probe()
1027 ci->supports_runtime_pm = !!(ci->platdata->flags & in ci_hdrc_probe()
1029 platform_set_drvdata(pdev, ci); in ci_hdrc_probe()
1031 ret = hw_device_init(ci, base); in ci_hdrc_probe()
1037 ret = ci_ulpi_init(ci); in ci_hdrc_probe()
1041 if (ci->platdata->phy) { in ci_hdrc_probe()
1042 ci->phy = ci->platdata->phy; in ci_hdrc_probe()
1043 } else if (ci->platdata->usb_phy) { in ci_hdrc_probe()
1044 ci->usb_phy = ci->platdata->usb_phy; in ci_hdrc_probe()
1047 ci->phy = devm_phy_get(dev->parent, "usb-phy"); in ci_hdrc_probe()
1049 if (PTR_ERR(ci->phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1052 } else if (IS_ERR(ci->phy)) { in ci_hdrc_probe()
1053 ci->phy = NULL; in ci_hdrc_probe()
1057 if (!ci->phy) { in ci_hdrc_probe()
1058 ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, in ci_hdrc_probe()
1061 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1064 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1065 ci->usb_phy = NULL; in ci_hdrc_probe()
1070 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1071 ci->usb_phy = devm_usb_get_phy(dev->parent, in ci_hdrc_probe()
1074 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1077 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1078 ci->usb_phy = NULL; in ci_hdrc_probe()
1083 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1089 ret = ci_usb_phy_init(ci); in ci_hdrc_probe()
1095 ci->hw_bank.phys = res->start; in ci_hdrc_probe()
1097 ci->irq = platform_get_irq(pdev, 0); in ci_hdrc_probe()
1098 if (ci->irq < 0) { in ci_hdrc_probe()
1099 ret = ci->irq; in ci_hdrc_probe()
1103 ci_get_otg_capable(ci); in ci_hdrc_probe()
1105 dr_mode = ci->platdata->dr_mode; in ci_hdrc_probe()
1108 ret = ci_hdrc_host_init(ci); in ci_hdrc_probe()
1118 ret = ci_hdrc_gadget_init(ci); in ci_hdrc_probe()
1127 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1133 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1134 ret = ci_hdrc_otg_init(ci); in ci_hdrc_probe()
1142 ci_role_switch.driver_data = ci; in ci_hdrc_probe()
1143 ci->role_switch = usb_role_switch_register(dev, in ci_hdrc_probe()
1145 if (IS_ERR(ci->role_switch)) { in ci_hdrc_probe()
1146 ret = PTR_ERR(ci->role_switch); in ci_hdrc_probe()
1151 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1152 if (ci->is_otg) { in ci_hdrc_probe()
1153 ci->role = ci_otg_role(ci); in ci_hdrc_probe()
1155 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); in ci_hdrc_probe()
1162 ci->role = CI_ROLE_GADGET; in ci_hdrc_probe()
1165 ci->role = ci->roles[CI_ROLE_HOST] in ci_hdrc_probe()
1170 if (!ci_otg_is_fsm_mode(ci)) { in ci_hdrc_probe()
1172 if (ci->role == CI_ROLE_GADGET) { in ci_hdrc_probe()
1174 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in ci_hdrc_probe()
1175 ci_handle_vbus_change(ci); in ci_hdrc_probe()
1178 ret = ci_role_start(ci, ci->role); in ci_hdrc_probe()
1181 ci_role(ci)->name); in ci_hdrc_probe()
1186 ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED, in ci_hdrc_probe()
1187 ci->platdata->name, ci); in ci_hdrc_probe()
1191 ret = ci_extcon_register(ci); in ci_hdrc_probe()
1195 if (ci->supports_runtime_pm) { in ci_hdrc_probe()
1199 pm_runtime_mark_last_busy(ci->dev); in ci_hdrc_probe()
1203 if (ci_otg_is_fsm_mode(ci)) in ci_hdrc_probe()
1204 ci_hdrc_otg_fsm_start(ci); in ci_hdrc_probe()
1207 dbg_create_files(ci); in ci_hdrc_probe()
1212 if (ci->role_switch) in ci_hdrc_probe()
1213 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_probe()
1215 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_probe()
1216 ci_hdrc_otg_destroy(ci); in ci_hdrc_probe()
1218 ci_hdrc_gadget_destroy(ci); in ci_hdrc_probe()
1220 ci_hdrc_host_destroy(ci); in ci_hdrc_probe()
1222 ci_usb_phy_exit(ci); in ci_hdrc_probe()
1224 ci_ulpi_exit(ci); in ci_hdrc_probe()
1231 struct ci_hdrc *ci = platform_get_drvdata(pdev); in ci_hdrc_remove() local
1233 if (ci->role_switch) in ci_hdrc_remove()
1234 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_remove()
1236 if (ci->supports_runtime_pm) { in ci_hdrc_remove()
1242 dbg_remove_files(ci); in ci_hdrc_remove()
1243 ci_role_destroy(ci); in ci_hdrc_remove()
1244 ci_hdrc_enter_lpm(ci, true); in ci_hdrc_remove()
1245 ci_usb_phy_exit(ci); in ci_hdrc_remove()
1246 ci_ulpi_exit(ci); in ci_hdrc_remove()
1253 static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci) in ci_otg_fsm_suspend_for_srp() argument
1255 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_suspend_for_srp()
1256 !hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_suspend_for_srp()
1257 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, in ci_otg_fsm_suspend_for_srp()
1259 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN, in ci_otg_fsm_suspend_for_srp()
1265 static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci) in ci_otg_fsm_wakeup_by_srp() argument
1267 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_wakeup_by_srp()
1268 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { in ci_otg_fsm_wakeup_by_srp()
1269 if (!hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_wakeup_by_srp()
1270 ci->fsm.a_srp_det = 1; in ci_otg_fsm_wakeup_by_srp()
1271 ci->fsm.a_bus_drop = 0; in ci_otg_fsm_wakeup_by_srp()
1273 ci->fsm.id = 1; in ci_otg_fsm_wakeup_by_srp()
1275 ci_otg_queue_work(ci); in ci_otg_fsm_wakeup_by_srp()
1279 static void ci_controller_suspend(struct ci_hdrc *ci) in ci_controller_suspend() argument
1281 disable_irq(ci->irq); in ci_controller_suspend()
1282 ci_hdrc_enter_lpm(ci, true); in ci_controller_suspend()
1283 if (ci->platdata->phy_clkgate_delay_us) in ci_controller_suspend()
1284 usleep_range(ci->platdata->phy_clkgate_delay_us, in ci_controller_suspend()
1285 ci->platdata->phy_clkgate_delay_us + 50); in ci_controller_suspend()
1286 usb_phy_set_suspend(ci->usb_phy, 1); in ci_controller_suspend()
1287 ci->in_lpm = true; in ci_controller_suspend()
1288 enable_irq(ci->irq); in ci_controller_suspend()
1297 static void ci_extcon_wakeup_int(struct ci_hdrc *ci) in ci_extcon_wakeup_int() argument
1300 u32 otgsc = hw_read_otgsc(ci, ~0); in ci_extcon_wakeup_int()
1302 cable_id = &ci->platdata->id_extcon; in ci_extcon_wakeup_int()
1303 cable_vbus = &ci->platdata->vbus_extcon; in ci_extcon_wakeup_int()
1305 if (!IS_ERR(cable_id->edev) && ci->is_otg && in ci_extcon_wakeup_int()
1307 ci_irq(ci); in ci_extcon_wakeup_int()
1309 if (!IS_ERR(cable_vbus->edev) && ci->is_otg && in ci_extcon_wakeup_int()
1311 ci_irq(ci); in ci_extcon_wakeup_int()
1316 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_controller_resume() local
1321 if (!ci->in_lpm) { in ci_controller_resume()
1326 ci_hdrc_enter_lpm(ci, false); in ci_controller_resume()
1328 ret = ci_ulpi_resume(ci); in ci_controller_resume()
1332 if (ci->usb_phy) { in ci_controller_resume()
1333 usb_phy_set_suspend(ci->usb_phy, 0); in ci_controller_resume()
1334 usb_phy_set_wakeup(ci->usb_phy, false); in ci_controller_resume()
1338 ci->in_lpm = false; in ci_controller_resume()
1339 if (ci->wakeup_int) { in ci_controller_resume()
1340 ci->wakeup_int = false; in ci_controller_resume()
1341 pm_runtime_mark_last_busy(ci->dev); in ci_controller_resume()
1342 pm_runtime_put_autosuspend(ci->dev); in ci_controller_resume()
1343 enable_irq(ci->irq); in ci_controller_resume()
1344 if (ci_otg_is_fsm_mode(ci)) in ci_controller_resume()
1345 ci_otg_fsm_wakeup_by_srp(ci); in ci_controller_resume()
1346 ci_extcon_wakeup_int(ci); in ci_controller_resume()
1355 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_suspend() local
1357 if (ci->wq) in ci_suspend()
1358 flush_workqueue(ci->wq); in ci_suspend()
1365 if (ci->in_lpm) in ci_suspend()
1368 if (ci->in_lpm) { in ci_suspend()
1374 if (ci_otg_is_fsm_mode(ci)) in ci_suspend()
1375 ci_otg_fsm_suspend_for_srp(ci); in ci_suspend()
1377 usb_phy_set_wakeup(ci->usb_phy, true); in ci_suspend()
1378 enable_irq_wake(ci->irq); in ci_suspend()
1381 ci_controller_suspend(ci); in ci_suspend()
1388 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_resume() local
1392 disable_irq_wake(ci->irq); in ci_resume()
1398 if (ci->supports_runtime_pm) { in ci_resume()
1410 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_runtime_suspend() local
1414 if (ci->in_lpm) { in ci_runtime_suspend()
1419 if (ci_otg_is_fsm_mode(ci)) in ci_runtime_suspend()
1420 ci_otg_fsm_suspend_for_srp(ci); in ci_runtime_suspend()
1422 usb_phy_set_wakeup(ci->usb_phy, true); in ci_runtime_suspend()
1423 ci_controller_suspend(ci); in ci_runtime_suspend()