Lines Matching refs:ci
100 static void hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) in hw_alloc_regmap() argument
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()
118 static enum ci_revision ci_get_revision(struct ci_hdrc *ci) in ci_get_revision() argument
120 int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION); in ci_get_revision()
124 rev = hw_read_id_reg(ci, ID_ID, REVISION) in ci_get_revision()
141 u32 hw_read_intr_enable(struct ci_hdrc *ci) in hw_read_intr_enable() argument
143 return hw_read(ci, OP_USBINTR, ~0); in hw_read_intr_enable()
153 u32 hw_read_intr_status(struct ci_hdrc *ci) in hw_read_intr_status() argument
155 return hw_read(ci, OP_USBSTS, ~0); in hw_read_intr_status()
165 int hw_port_test_set(struct ci_hdrc *ci, u8 mode) in hw_port_test_set() argument
172 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC)); in hw_port_test_set()
183 u8 hw_port_test_get(struct ci_hdrc *ci) in hw_port_test_get() argument
185 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); in hw_port_test_get()
200 static void ci_hdrc_enter_lpm_common(struct ci_hdrc *ci, bool enable) in ci_hdrc_enter_lpm_common() argument
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()
213 static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) in ci_hdrc_enter_lpm() argument
215 return ci->platdata->enter_lpm(ci, enable); in ci_hdrc_enter_lpm()
218 static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) in hw_device_init() argument
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()
229 hw_alloc_regmap(ci, false); in hw_device_init()
230 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> in hw_device_init()
232 ci->hw_bank.lpm = reg; in hw_device_init()
234 hw_alloc_regmap(ci, !!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()
239 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> 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()
246 ci_hdrc_enter_lpm(ci, false); in hw_device_init()
249 hw_write(ci, OP_USBINTR, 0xffffffff, 0); in hw_device_init()
252 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff); 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()
269 void hw_phymode_configure(struct ci_hdrc *ci) in hw_phymode_configure() argument
273 switch (ci->platdata->phy_mode) { in hw_phymode_configure()
299 if (ci->hw_bank.lpm) { in hw_phymode_configure()
300 hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm); in hw_phymode_configure()
302 hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS); in hw_phymode_configure()
304 hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc); in hw_phymode_configure()
306 hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS); in hw_phymode_configure()
318 static int _ci_usb_phy_init(struct ci_hdrc *ci) in _ci_usb_phy_init() argument
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()
344 static void ci_usb_phy_exit(struct ci_hdrc *ci) in ci_usb_phy_exit() argument
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()
363 static int ci_usb_phy_init(struct ci_hdrc *ci) in ci_usb_phy_init() argument
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()
374 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
379 hw_phymode_configure(ci); in ci_usb_phy_init()
383 hw_phymode_configure(ci); in ci_usb_phy_init()
384 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
389 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
403 void ci_platform_configure(struct ci_hdrc *ci) in ci_platform_configure() argument
407 is_device_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_DC; in ci_platform_configure()
408 is_host_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_HC; in ci_platform_configure()
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()
414 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, 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()
422 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, 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()
428 hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC); in ci_platform_configure()
430 hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC); in ci_platform_configure()
433 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA) in ci_platform_configure()
434 hw_write(ci, OP_TTCTRL, TTCTRL_TTHA_MASK, TTCTRL_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()
439 hw_write_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK, in ci_platform_configure()
440 ci->platdata->ahb_burst_config); in ci_platform_configure()
443 if (!hw_read_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK)) { in ci_platform_configure()
444 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST) in ci_platform_configure()
445 hw_write(ci, OP_BURSTSIZE, TX_BURST_MASK, 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()
449 hw_write(ci, OP_BURSTSIZE, RX_BURST_MASK, in ci_platform_configure()
450 ci->platdata->rx_burst_size); in ci_platform_configure()
460 static int hw_controller_reset(struct ci_hdrc *ci) in hw_controller_reset() argument
464 hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST); in hw_controller_reset()
465 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) { in hw_controller_reset()
480 int hw_device_reset(struct ci_hdrc *ci) in hw_device_reset() argument
485 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0); in hw_device_reset()
486 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in hw_device_reset()
488 ret = hw_controller_reset(ci); in hw_device_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()
502 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); in hw_device_reset()
503 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC); in hw_device_reset()
505 hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); in hw_device_reset()
507 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) { 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()
514 ci_platform_configure(ci); in hw_device_reset()
521 struct ci_hdrc *ci = data; in ci_irq_handler() local
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()
540 otgsc = hw_read_otgsc(ci, ~0); in ci_irq_handler()
541 if (ci_otg_is_fsm_mode(ci)) { in ci_irq_handler()
542 ret = ci_otg_fsm_irq(ci); 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()
555 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); in ci_irq_handler()
556 ci_otg_queue_work(ci); 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()
567 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); in ci_irq_handler()
568 ci_otg_queue_work(ci); 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()
579 static void ci_irq(struct ci_hdrc *ci) in ci_irq() argument
584 ci_irq_handler(ci->irq, ci); in ci_irq()
592 struct ci_hdrc *ci = cbl->ci; in ci_cable_notifier() local
597 ci_irq(ci); in ci_cable_notifier()
603 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); in ci_usb_role_switch_get() local
607 spin_lock_irqsave(&ci->lock, flags); in ci_usb_role_switch_get()
608 role = ci_role_to_usb_role(ci); in ci_usb_role_switch_get()
609 spin_unlock_irqrestore(&ci->lock, flags); in ci_usb_role_switch_get()
617 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); in ci_usb_role_switch_set() local
621 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
624 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
628 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
631 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
635 cable = &ci->platdata->id_extcon; in ci_usb_role_switch_set()
638 cable = &ci->platdata->vbus_extcon; in ci_usb_role_switch_set()
643 ci_irq(ci); in ci_usb_role_switch_set()
647 static enum ci_role ci_get_role(struct ci_hdrc *ci) in ci_get_role() argument
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()
653 role = ci_otg_role(ci); in ci_get_role()
654 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); in ci_get_role()
664 role = ci->roles[CI_ROLE_HOST] ? CI_ROLE_HOST in ci_get_role()
829 static int ci_extcon_register(struct ci_hdrc *ci) in ci_extcon_register() argument
834 id = &ci->platdata->id_extcon; in ci_extcon_register()
835 id->ci = ci; in ci_extcon_register()
837 ret = devm_extcon_register_notifier(ci->dev, id->edev, 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()
848 ret = devm_extcon_register_notifier(ci->dev, vbus->edev, in ci_extcon_register()
851 dev_err(ci->dev, "register VBUS failed\n"); in ci_extcon_register()
861 struct ci_hdrc *ci = container_of(work, struct ci_hdrc, power_lost_work); in ci_power_lost_work() local
864 disable_irq_nosync(ci->irq); in ci_power_lost_work()
865 pm_runtime_get_sync(ci->dev); in ci_power_lost_work()
866 if (!ci_otg_is_fsm_mode(ci)) { in ci_power_lost_work()
867 role = ci_get_role(ci); in ci_power_lost_work()
869 if (ci->role != role) { in ci_power_lost_work()
870 ci_handle_id_switch(ci); 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()
948 struct ci_hdrc *ci = platform_get_drvdata(pdev); in ci_hdrc_query_available_role() local
950 if (!ci) in ci_hdrc_query_available_role()
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()
963 static inline void ci_role_destroy(struct ci_hdrc *ci) in ci_role_destroy() argument
965 ci_hdrc_gadget_destroy(ci); in ci_role_destroy()
966 ci_hdrc_host_destroy(ci); in ci_role_destroy()
967 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_role_destroy()
968 ci_hdrc_otg_destroy(ci); in ci_role_destroy()
971 static void ci_get_otg_capable(struct ci_hdrc *ci) in ci_get_otg_capable() argument
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()
982 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, in ci_get_otg_capable()
990 struct ci_hdrc *ci = dev_get_drvdata(dev); in role_show() local
992 if (ci->role != CI_ROLE_END) in role_show()
993 return sprintf(buf, "%s\n", ci_role(ci)->name); in role_show()
1001 struct ci_hdrc *ci = dev_get_drvdata(dev); in role_store() local
1005 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) { in role_store()
1011 if (!strncmp(buf, ci->roles[role]->name, in role_store()
1012 strlen(ci->roles[role]->name))) 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()
1027 ci_role_stop(ci); in role_store()
1028 ret = ci_role_start(ci, role); in role_store()
1029 if (!ret && ci->role == CI_ROLE_GADGET) in role_store()
1030 ci_handle_vbus_change(ci); in role_store()
1031 enable_irq(ci->irq); in role_store()
1033 mutex_unlock(&ci->mutex); in role_store()
1043 ATTRIBUTE_GROUPS(ci);
1048 struct ci_hdrc *ci; in ci_hdrc_probe() local
1063 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); in ci_hdrc_probe()
1064 if (!ci) 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()
1079 ci->has_short_pkt_limit = !!(ci->platdata->flags & in ci_hdrc_probe()
1081 platform_set_drvdata(pdev, ci); in ci_hdrc_probe()
1083 ret = hw_device_init(ci, base); in ci_hdrc_probe()
1089 ret = ci_ulpi_init(ci); in ci_hdrc_probe()
1093 if (ci->platdata->phy) { in ci_hdrc_probe()
1094 ci->phy = ci->platdata->phy; in ci_hdrc_probe()
1095 } else if (ci->platdata->usb_phy) { in ci_hdrc_probe()
1096 ci->usb_phy = ci->platdata->usb_phy; in ci_hdrc_probe()
1099 ci->phy = devm_phy_get(dev->parent, "usb-phy"); in ci_hdrc_probe()
1101 if (PTR_ERR(ci->phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1104 } else if (IS_ERR(ci->phy)) { in ci_hdrc_probe()
1105 ci->phy = NULL; in ci_hdrc_probe()
1109 if (!ci->phy) { in ci_hdrc_probe()
1110 ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, in ci_hdrc_probe()
1113 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1116 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1117 ci->usb_phy = NULL; in ci_hdrc_probe()
1122 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1123 ci->usb_phy = devm_usb_get_phy(dev->parent, in ci_hdrc_probe()
1126 if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { in ci_hdrc_probe()
1129 } else if (IS_ERR(ci->usb_phy)) { in ci_hdrc_probe()
1130 ci->usb_phy = NULL; in ci_hdrc_probe()
1135 if (!ci->phy && !ci->usb_phy) { in ci_hdrc_probe()
1141 ret = ci_usb_phy_init(ci); in ci_hdrc_probe()
1147 ci->hw_bank.phys = res->start; in ci_hdrc_probe()
1149 ci->irq = platform_get_irq(pdev, 0); in ci_hdrc_probe()
1150 if (ci->irq < 0) { in ci_hdrc_probe()
1151 ret = ci->irq; in ci_hdrc_probe()
1155 ci_get_otg_capable(ci); in ci_hdrc_probe()
1157 dr_mode = ci->platdata->dr_mode; in ci_hdrc_probe()
1160 ret = ci_hdrc_host_init(ci); in ci_hdrc_probe()
1170 ret = ci_hdrc_gadget_init(ci); in ci_hdrc_probe()
1179 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1185 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
1186 ret = ci_hdrc_otg_init(ci); in ci_hdrc_probe()
1194 ci_role_switch.driver_data = ci; in ci_hdrc_probe()
1195 ci->role_switch = usb_role_switch_register(dev, in ci_hdrc_probe()
1197 if (IS_ERR(ci->role_switch)) { in ci_hdrc_probe()
1198 ret = PTR_ERR(ci->role_switch); in ci_hdrc_probe()
1203 ci->role = ci_get_role(ci); in ci_hdrc_probe()
1204 if (!ci_otg_is_fsm_mode(ci)) { in ci_hdrc_probe()
1206 if (ci->role == CI_ROLE_GADGET) { in ci_hdrc_probe()
1208 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in ci_hdrc_probe()
1209 ci_handle_vbus_change(ci); in ci_hdrc_probe()
1212 ret = ci_role_start(ci, ci->role); in ci_hdrc_probe()
1215 ci_role(ci)->name); in ci_hdrc_probe()
1220 ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED, in ci_hdrc_probe()
1221 ci->platdata->name, ci); in ci_hdrc_probe()
1225 ret = ci_extcon_register(ci); in ci_hdrc_probe()
1229 if (ci->supports_runtime_pm) { in ci_hdrc_probe()
1233 pm_runtime_mark_last_busy(ci->dev); in ci_hdrc_probe()
1237 if (ci_otg_is_fsm_mode(ci)) in ci_hdrc_probe()
1238 ci_hdrc_otg_fsm_start(ci); in ci_hdrc_probe()
1241 dbg_create_files(ci); in ci_hdrc_probe()
1246 if (ci->role_switch) in ci_hdrc_probe()
1247 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_probe()
1249 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) in ci_hdrc_probe()
1250 ci_hdrc_otg_destroy(ci); in ci_hdrc_probe()
1252 ci_hdrc_gadget_destroy(ci); in ci_hdrc_probe()
1254 ci_hdrc_host_destroy(ci); in ci_hdrc_probe()
1256 ci_usb_phy_exit(ci); in ci_hdrc_probe()
1258 ci_ulpi_exit(ci); in ci_hdrc_probe()
1265 struct ci_hdrc *ci = platform_get_drvdata(pdev); in ci_hdrc_remove() local
1267 if (ci->role_switch) in ci_hdrc_remove()
1268 usb_role_switch_unregister(ci->role_switch); in ci_hdrc_remove()
1270 if (ci->supports_runtime_pm) { in ci_hdrc_remove()
1276 dbg_remove_files(ci); in ci_hdrc_remove()
1277 ci_role_destroy(ci); in ci_hdrc_remove()
1278 ci_hdrc_enter_lpm(ci, true); in ci_hdrc_remove()
1279 ci_usb_phy_exit(ci); in ci_hdrc_remove()
1280 ci_ulpi_exit(ci); in ci_hdrc_remove()
1285 static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci) in ci_otg_fsm_suspend_for_srp() argument
1287 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_suspend_for_srp()
1288 !hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_suspend_for_srp()
1289 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, in ci_otg_fsm_suspend_for_srp()
1291 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN, in ci_otg_fsm_suspend_for_srp()
1297 static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci) in ci_otg_fsm_wakeup_by_srp() argument
1299 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_wakeup_by_srp()
1300 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { in ci_otg_fsm_wakeup_by_srp()
1301 if (!hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_wakeup_by_srp()
1302 ci->fsm.a_srp_det = 1; in ci_otg_fsm_wakeup_by_srp()
1303 ci->fsm.a_bus_drop = 0; in ci_otg_fsm_wakeup_by_srp()
1305 ci->fsm.id = 1; in ci_otg_fsm_wakeup_by_srp()
1307 ci_otg_queue_work(ci); in ci_otg_fsm_wakeup_by_srp()
1311 static void ci_controller_suspend(struct ci_hdrc *ci) in ci_controller_suspend() argument
1313 disable_irq(ci->irq); in ci_controller_suspend()
1314 ci_hdrc_enter_lpm(ci, true); in ci_controller_suspend()
1315 if (ci->platdata->phy_clkgate_delay_us) in ci_controller_suspend()
1316 usleep_range(ci->platdata->phy_clkgate_delay_us, in ci_controller_suspend()
1317 ci->platdata->phy_clkgate_delay_us + 50); in ci_controller_suspend()
1318 usb_phy_set_suspend(ci->usb_phy, 1); in ci_controller_suspend()
1319 ci->in_lpm = true; in ci_controller_suspend()
1320 enable_irq(ci->irq); in ci_controller_suspend()
1329 static void ci_extcon_wakeup_int(struct ci_hdrc *ci) in ci_extcon_wakeup_int() argument
1332 u32 otgsc = hw_read_otgsc(ci, ~0); in ci_extcon_wakeup_int()
1334 cable_id = &ci->platdata->id_extcon; in ci_extcon_wakeup_int()
1335 cable_vbus = &ci->platdata->vbus_extcon; in ci_extcon_wakeup_int()
1337 if ((!IS_ERR(cable_id->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1338 && ci->is_otg && in ci_extcon_wakeup_int()
1340 ci_irq(ci); in ci_extcon_wakeup_int()
1342 if ((!IS_ERR(cable_vbus->edev) || ci->role_switch) in ci_extcon_wakeup_int()
1343 && ci->is_otg && in ci_extcon_wakeup_int()
1345 ci_irq(ci); in ci_extcon_wakeup_int()
1350 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_controller_resume() local
1355 if (!ci->in_lpm) { in ci_controller_resume()
1360 ci_hdrc_enter_lpm(ci, false); in ci_controller_resume()
1362 ret = ci_ulpi_resume(ci); in ci_controller_resume()
1366 if (ci->usb_phy) { in ci_controller_resume()
1367 usb_phy_set_suspend(ci->usb_phy, 0); in ci_controller_resume()
1368 usb_phy_set_wakeup(ci->usb_phy, false); in ci_controller_resume()
1372 ci->in_lpm = false; in ci_controller_resume()
1373 if (ci->wakeup_int) { in ci_controller_resume()
1374 ci->wakeup_int = false; in ci_controller_resume()
1375 pm_runtime_mark_last_busy(ci->dev); in ci_controller_resume()
1376 pm_runtime_put_autosuspend(ci->dev); in ci_controller_resume()
1377 enable_irq(ci->irq); in ci_controller_resume()
1378 if (ci_otg_is_fsm_mode(ci)) in ci_controller_resume()
1379 ci_otg_fsm_wakeup_by_srp(ci); in ci_controller_resume()
1380 ci_extcon_wakeup_int(ci); in ci_controller_resume()
1389 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_suspend() local
1391 if (ci->wq) in ci_suspend()
1392 flush_workqueue(ci->wq); in ci_suspend()
1399 if (ci->in_lpm) in ci_suspend()
1402 if (ci->in_lpm) { in ci_suspend()
1408 if (ci->role != CI_ROLE_END && ci_role(ci)->suspend) in ci_suspend()
1409 ci_role(ci)->suspend(ci); in ci_suspend()
1412 if (ci_otg_is_fsm_mode(ci)) in ci_suspend()
1413 ci_otg_fsm_suspend_for_srp(ci); in ci_suspend()
1415 usb_phy_set_wakeup(ci->usb_phy, true); in ci_suspend()
1416 enable_irq_wake(ci->irq); in ci_suspend()
1419 ci_controller_suspend(ci); in ci_suspend()
1426 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_resume() local
1435 power_lost = !hw_read(ci, OP_ENDPTLISTADDR, ~0); in ci_resume()
1438 disable_irq_wake(ci->irq); in ci_resume()
1446 ci_usb_phy_exit(ci); in ci_resume()
1447 ci_usb_phy_init(ci); in ci_resume()
1451 if (ci->role != CI_ROLE_END && ci_role(ci)->resume) in ci_resume()
1452 ci_role(ci)->resume(ci, power_lost); in ci_resume()
1455 queue_work(system_freezable_wq, &ci->power_lost_work); in ci_resume()
1457 if (ci->supports_runtime_pm) { in ci_resume()
1469 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_runtime_suspend() local
1473 if (ci->in_lpm) { in ci_runtime_suspend()
1478 if (ci_otg_is_fsm_mode(ci)) in ci_runtime_suspend()
1479 ci_otg_fsm_suspend_for_srp(ci); in ci_runtime_suspend()
1481 usb_phy_set_wakeup(ci->usb_phy, true); in ci_runtime_suspend()
1482 ci_controller_suspend(ci); in ci_runtime_suspend()