Lines Matching refs:ci
121 static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) in hw_alloc_regmap() argument
126 ci->hw_bank.regmap[i] = in hw_alloc_regmap()
127 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + in hw_alloc_regmap()
131 ci->hw_bank.regmap[i] = ci->hw_bank.op + in hw_alloc_regmap()
140 static enum ci_revision ci_get_revision(struct ci_hdrc *ci) in ci_get_revision() argument
142 int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION); in ci_get_revision()
146 rev = hw_read_id_reg(ci, ID_ID, REVISION) in ci_get_revision()
163 u32 hw_read_intr_enable(struct ci_hdrc *ci) in hw_read_intr_enable() argument
165 return hw_read(ci, OP_USBINTR, ~0); in hw_read_intr_enable()
175 u32 hw_read_intr_status(struct ci_hdrc *ci) in hw_read_intr_status() argument
177 return hw_read(ci, OP_USBSTS, ~0); in hw_read_intr_status()
186 int hw_port_test_set(struct ci_hdrc *ci, u8 mode) in hw_port_test_set() argument
193 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC)); in hw_port_test_set()
204 u8 hw_port_test_get(struct ci_hdrc *ci) in hw_port_test_get() argument
206 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); in hw_port_test_get()
221 static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) in ci_hdrc_enter_lpm() argument
223 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC; in ci_hdrc_enter_lpm()
224 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm))); in ci_hdrc_enter_lpm()
227 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm()
228 PORTSC_PHCD(ci->hw_bank.lpm)); in ci_hdrc_enter_lpm()
230 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), in ci_hdrc_enter_lpm()
234 static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) in hw_device_init() argument
239 ci->hw_bank.abs = base; in hw_device_init()
241 ci->hw_bank.cap = ci->hw_bank.abs; in hw_device_init()
242 ci->hw_bank.cap += ci->platdata->capoffset; in hw_device_init()
243 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff); in hw_device_init()
245 hw_alloc_regmap(ci, false); in hw_device_init()
246 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> in hw_device_init()
248 ci->hw_bank.lpm = reg; in hw_device_init()
250 hw_alloc_regmap(ci, !!reg); in hw_device_init()
251 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; in hw_device_init()
252 ci->hw_bank.size += OP_LAST; in hw_device_init()
253 ci->hw_bank.size /= sizeof(u32); in hw_device_init()
255 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> in hw_device_init()
257 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ in hw_device_init()
259 if (ci->hw_ep_max > ENDPT_MAX) in hw_device_init()
262 ci_hdrc_enter_lpm(ci, false); in hw_device_init()
265 hw_write(ci, OP_USBINTR, 0xffffffff, 0); in hw_device_init()
268 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff); in hw_device_init()
270 ci->rev = ci_get_revision(ci); in hw_device_init()
272 dev_dbg(ci->dev, in hw_device_init()
274 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); in hw_device_init()
285 static void hw_phymode_configure(struct ci_hdrc *ci) in hw_phymode_configure() argument
289 switch (ci->platdata->phy_mode) { in hw_phymode_configure()
315 if (ci->hw_bank.lpm) { in hw_phymode_configure()
316 hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm); in hw_phymode_configure()
318 hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS); in hw_phymode_configure()
320 hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc); in hw_phymode_configure()
322 hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS); in hw_phymode_configure()
333 static int _ci_usb_phy_init(struct ci_hdrc *ci) in _ci_usb_phy_init() argument
337 if (ci->phy) { in _ci_usb_phy_init()
338 ret = phy_init(ci->phy); in _ci_usb_phy_init()
342 ret = phy_power_on(ci->phy); in _ci_usb_phy_init()
344 phy_exit(ci->phy); in _ci_usb_phy_init()
348 ret = usb_phy_init(ci->usb_phy); in _ci_usb_phy_init()
359 static void ci_usb_phy_exit(struct ci_hdrc *ci) in ci_usb_phy_exit() argument
361 if (ci->phy) { in ci_usb_phy_exit()
362 phy_power_off(ci->phy); in ci_usb_phy_exit()
363 phy_exit(ci->phy); in ci_usb_phy_exit()
365 usb_phy_shutdown(ci->usb_phy); in ci_usb_phy_exit()
375 static int ci_usb_phy_init(struct ci_hdrc *ci) in ci_usb_phy_init() argument
379 switch (ci->platdata->phy_mode) { in ci_usb_phy_init()
383 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
388 hw_phymode_configure(ci); in ci_usb_phy_init()
392 hw_phymode_configure(ci); in ci_usb_phy_init()
393 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
398 ret = _ci_usb_phy_init(ci); in ci_usb_phy_init()
412 static int hw_controller_reset(struct ci_hdrc *ci) in hw_controller_reset() argument
416 hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST); in hw_controller_reset()
417 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) { in hw_controller_reset()
432 int hw_device_reset(struct ci_hdrc *ci) in hw_device_reset() argument
437 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0); in hw_device_reset()
438 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in hw_device_reset()
440 ret = hw_controller_reset(ci); in hw_device_reset()
442 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret); in hw_device_reset()
446 if (ci->platdata->notify_event) in hw_device_reset()
447 ci->platdata->notify_event(ci, in hw_device_reset()
450 if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING) in hw_device_reset()
451 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); in hw_device_reset()
453 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) { in hw_device_reset()
454 if (ci->hw_bank.lpm) in hw_device_reset()
455 hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC); in hw_device_reset()
457 hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC); in hw_device_reset()
461 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); in hw_device_reset()
462 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC); in hw_device_reset()
464 hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); in hw_device_reset()
466 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) { in hw_device_reset()
467 pr_err("cannot enter in %s device mode", ci_role(ci)->name); in hw_device_reset()
468 pr_err("lpm = %i", ci->hw_bank.lpm); in hw_device_reset()
490 int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask, in hw_wait_reg() argument
495 while (hw_read(ci, reg, mask) != value) { in hw_wait_reg()
497 dev_err(ci->dev, "timeout waiting for %08x in %d\n", in hw_wait_reg()
509 struct ci_hdrc *ci = data; in ci_irq() local
513 if (ci->in_lpm) { in ci_irq()
515 ci->wakeup_int = true; in ci_irq()
516 pm_runtime_get(ci->dev); in ci_irq()
520 if (ci->is_otg) { in ci_irq()
521 otgsc = hw_read_otgsc(ci, ~0); in ci_irq()
522 if (ci_otg_is_fsm_mode(ci)) { in ci_irq()
523 ret = ci_otg_fsm_irq(ci); in ci_irq()
533 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { in ci_irq()
534 ci->id_event = true; in ci_irq()
536 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); in ci_irq()
537 ci_otg_queue_work(ci); in ci_irq()
545 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { in ci_irq()
546 ci->b_sess_valid_event = true; in ci_irq()
548 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); in ci_irq()
549 ci_otg_queue_work(ci); in ci_irq()
554 if (ci->role != CI_ROLE_END) in ci_irq()
555 ret = ci_role(ci)->irq(ci); in ci_irq()
655 static inline void ci_role_destroy(struct ci_hdrc *ci) in ci_role_destroy() argument
657 ci_hdrc_gadget_destroy(ci); in ci_role_destroy()
658 ci_hdrc_host_destroy(ci); in ci_role_destroy()
659 if (ci->is_otg) in ci_role_destroy()
660 ci_hdrc_otg_destroy(ci); in ci_role_destroy()
663 static void ci_get_otg_capable(struct ci_hdrc *ci) in ci_get_otg_capable() argument
665 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) in ci_get_otg_capable()
666 ci->is_otg = false; in ci_get_otg_capable()
668 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, in ci_get_otg_capable()
671 if (ci->is_otg) { in ci_get_otg_capable()
672 dev_dbg(ci->dev, "It is OTG capable controller\n"); in ci_get_otg_capable()
674 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, in ci_get_otg_capable()
682 struct ci_hdrc *ci; in ci_hdrc_probe() local
698 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); in ci_hdrc_probe()
699 if (!ci) in ci_hdrc_probe()
702 ci->dev = dev; in ci_hdrc_probe()
703 ci->platdata = dev_get_platdata(dev); in ci_hdrc_probe()
704 ci->imx28_write_fix = !!(ci->platdata->flags & in ci_hdrc_probe()
706 ci->supports_runtime_pm = !!(ci->platdata->flags & in ci_hdrc_probe()
709 ret = hw_device_init(ci, base); in ci_hdrc_probe()
715 if (ci->platdata->phy) { in ci_hdrc_probe()
716 ci->phy = ci->platdata->phy; in ci_hdrc_probe()
717 } else if (ci->platdata->usb_phy) { in ci_hdrc_probe()
718 ci->usb_phy = ci->platdata->usb_phy; in ci_hdrc_probe()
720 ci->phy = devm_phy_get(dev->parent, "usb-phy"); in ci_hdrc_probe()
721 ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2); in ci_hdrc_probe()
724 if (PTR_ERR(ci->phy) == -ENOSYS && in ci_hdrc_probe()
725 PTR_ERR(ci->usb_phy) == -ENXIO) in ci_hdrc_probe()
728 if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) in ci_hdrc_probe()
731 if (IS_ERR(ci->phy)) in ci_hdrc_probe()
732 ci->phy = NULL; in ci_hdrc_probe()
733 else if (IS_ERR(ci->usb_phy)) in ci_hdrc_probe()
734 ci->usb_phy = NULL; in ci_hdrc_probe()
737 ret = ci_usb_phy_init(ci); in ci_hdrc_probe()
743 ci->hw_bank.phys = res->start; in ci_hdrc_probe()
745 ci->irq = platform_get_irq(pdev, 0); in ci_hdrc_probe()
746 if (ci->irq < 0) { in ci_hdrc_probe()
748 ret = ci->irq; in ci_hdrc_probe()
752 ci_get_otg_capable(ci); in ci_hdrc_probe()
754 dr_mode = ci->platdata->dr_mode; in ci_hdrc_probe()
757 ret = ci_hdrc_host_init(ci); in ci_hdrc_probe()
763 ret = ci_hdrc_gadget_init(ci); in ci_hdrc_probe()
768 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
774 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
775 ret = ci_hdrc_otg_init(ci); in ci_hdrc_probe()
782 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { in ci_hdrc_probe()
783 if (ci->is_otg) { in ci_hdrc_probe()
784 ci->role = ci_otg_role(ci); in ci_hdrc_probe()
786 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); in ci_hdrc_probe()
793 ci->role = CI_ROLE_GADGET; in ci_hdrc_probe()
796 ci->role = ci->roles[CI_ROLE_HOST] in ci_hdrc_probe()
801 if (!ci_otg_is_fsm_mode(ci)) { in ci_hdrc_probe()
803 if (ci->role == CI_ROLE_GADGET) in ci_hdrc_probe()
804 ci_handle_vbus_change(ci); in ci_hdrc_probe()
806 ret = ci_role_start(ci, ci->role); in ci_hdrc_probe()
809 ci_role(ci)->name); in ci_hdrc_probe()
814 platform_set_drvdata(pdev, ci); in ci_hdrc_probe()
815 ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED, in ci_hdrc_probe()
816 ci->platdata->name, ci); in ci_hdrc_probe()
820 if (ci->supports_runtime_pm) { in ci_hdrc_probe()
824 pm_runtime_mark_last_busy(ci->dev); in ci_hdrc_probe()
828 if (ci_otg_is_fsm_mode(ci)) in ci_hdrc_probe()
829 ci_hdrc_otg_fsm_start(ci); in ci_hdrc_probe()
833 ret = dbg_create_files(ci); in ci_hdrc_probe()
838 ci_role_destroy(ci); in ci_hdrc_probe()
840 ci_usb_phy_exit(ci); in ci_hdrc_probe()
847 struct ci_hdrc *ci = platform_get_drvdata(pdev); in ci_hdrc_remove() local
849 if (ci->supports_runtime_pm) { in ci_hdrc_remove()
855 dbg_remove_files(ci); in ci_hdrc_remove()
856 ci_role_destroy(ci); in ci_hdrc_remove()
857 ci_hdrc_enter_lpm(ci, true); in ci_hdrc_remove()
858 ci_usb_phy_exit(ci); in ci_hdrc_remove()
865 static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci) in ci_otg_fsm_suspend_for_srp() argument
867 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_suspend_for_srp()
868 !hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_suspend_for_srp()
869 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, in ci_otg_fsm_suspend_for_srp()
871 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN, in ci_otg_fsm_suspend_for_srp()
877 static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci) in ci_otg_fsm_wakeup_by_srp() argument
879 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && in ci_otg_fsm_wakeup_by_srp()
880 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { in ci_otg_fsm_wakeup_by_srp()
881 if (!hw_read_otgsc(ci, OTGSC_ID)) { in ci_otg_fsm_wakeup_by_srp()
882 ci->fsm.a_srp_det = 1; in ci_otg_fsm_wakeup_by_srp()
883 ci->fsm.a_bus_drop = 0; in ci_otg_fsm_wakeup_by_srp()
885 ci->fsm.id = 1; in ci_otg_fsm_wakeup_by_srp()
887 ci_otg_queue_work(ci); in ci_otg_fsm_wakeup_by_srp()
891 static void ci_controller_suspend(struct ci_hdrc *ci) in ci_controller_suspend() argument
893 disable_irq(ci->irq); in ci_controller_suspend()
894 ci_hdrc_enter_lpm(ci, true); in ci_controller_suspend()
895 usb_phy_set_suspend(ci->usb_phy, 1); in ci_controller_suspend()
896 ci->in_lpm = true; in ci_controller_suspend()
897 enable_irq(ci->irq); in ci_controller_suspend()
902 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_controller_resume() local
906 if (!ci->in_lpm) { in ci_controller_resume()
911 ci_hdrc_enter_lpm(ci, false); in ci_controller_resume()
912 if (ci->usb_phy) { in ci_controller_resume()
913 usb_phy_set_suspend(ci->usb_phy, 0); in ci_controller_resume()
914 usb_phy_set_wakeup(ci->usb_phy, false); in ci_controller_resume()
918 ci->in_lpm = false; in ci_controller_resume()
919 if (ci->wakeup_int) { in ci_controller_resume()
920 ci->wakeup_int = false; in ci_controller_resume()
921 pm_runtime_mark_last_busy(ci->dev); in ci_controller_resume()
922 pm_runtime_put_autosuspend(ci->dev); in ci_controller_resume()
923 enable_irq(ci->irq); in ci_controller_resume()
924 if (ci_otg_is_fsm_mode(ci)) in ci_controller_resume()
925 ci_otg_fsm_wakeup_by_srp(ci); in ci_controller_resume()
934 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_suspend() local
936 if (ci->wq) in ci_suspend()
937 flush_workqueue(ci->wq); in ci_suspend()
944 if (ci->in_lpm) in ci_suspend()
947 if (ci->in_lpm) { in ci_suspend()
953 if (ci_otg_is_fsm_mode(ci)) in ci_suspend()
954 ci_otg_fsm_suspend_for_srp(ci); in ci_suspend()
956 usb_phy_set_wakeup(ci->usb_phy, true); in ci_suspend()
957 enable_irq_wake(ci->irq); in ci_suspend()
960 ci_controller_suspend(ci); in ci_suspend()
967 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_resume() local
971 disable_irq_wake(ci->irq); in ci_resume()
977 if (ci->supports_runtime_pm) { in ci_resume()
989 struct ci_hdrc *ci = dev_get_drvdata(dev); in ci_runtime_suspend() local
993 if (ci->in_lpm) { in ci_runtime_suspend()
998 if (ci_otg_is_fsm_mode(ci)) in ci_runtime_suspend()
999 ci_otg_fsm_suspend_for_srp(ci); in ci_runtime_suspend()
1001 usb_phy_set_wakeup(ci->usb_phy, true); in ci_runtime_suspend()
1002 ci_controller_suspend(ci); in ci_runtime_suspend()