Lines Matching refs:ci
36 struct ci_hdrc *ci = dev_get_drvdata(dev); in a_bus_req_show() local
40 t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_req); in a_bus_req_show()
51 struct ci_hdrc *ci = dev_get_drvdata(dev); in a_bus_req_store() local
56 mutex_lock(&ci->fsm.lock); in a_bus_req_store()
58 ci->fsm.a_bus_req = 0; in a_bus_req_store()
61 if (ci->fsm.a_bus_drop) { in a_bus_req_store()
62 mutex_unlock(&ci->fsm.lock); in a_bus_req_store()
65 ci->fsm.a_bus_req = 1; in a_bus_req_store()
66 if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) { in a_bus_req_store()
67 ci->gadget.host_request_flag = 1; in a_bus_req_store()
68 mutex_unlock(&ci->fsm.lock); in a_bus_req_store()
73 ci_otg_queue_work(ci); in a_bus_req_store()
74 mutex_unlock(&ci->fsm.lock); in a_bus_req_store()
85 struct ci_hdrc *ci = dev_get_drvdata(dev); in a_bus_drop_show() local
89 t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_drop); in a_bus_drop_show()
100 struct ci_hdrc *ci = dev_get_drvdata(dev); in a_bus_drop_store() local
105 mutex_lock(&ci->fsm.lock); in a_bus_drop_store()
107 ci->fsm.a_bus_drop = 0; in a_bus_drop_store()
109 ci->fsm.a_bus_drop = 1; in a_bus_drop_store()
110 ci->fsm.a_bus_req = 0; in a_bus_drop_store()
113 ci_otg_queue_work(ci); in a_bus_drop_store()
114 mutex_unlock(&ci->fsm.lock); in a_bus_drop_store()
125 struct ci_hdrc *ci = dev_get_drvdata(dev); in b_bus_req_show() local
129 t = scnprintf(next, size, "%d\n", ci->fsm.b_bus_req); in b_bus_req_show()
140 struct ci_hdrc *ci = dev_get_drvdata(dev); in b_bus_req_store() local
145 mutex_lock(&ci->fsm.lock); in b_bus_req_store()
147 ci->fsm.b_bus_req = 0; in b_bus_req_store()
149 ci->fsm.b_bus_req = 1; in b_bus_req_store()
150 if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) { in b_bus_req_store()
151 ci->gadget.host_request_flag = 1; in b_bus_req_store()
152 mutex_unlock(&ci->fsm.lock); in b_bus_req_store()
157 ci_otg_queue_work(ci); in b_bus_req_store()
158 mutex_unlock(&ci->fsm.lock); in b_bus_req_store()
168 struct ci_hdrc *ci = dev_get_drvdata(dev); in a_clr_err_store() local
173 mutex_lock(&ci->fsm.lock); in a_clr_err_store()
175 ci->fsm.a_clr_err = 1; in a_clr_err_store()
177 ci_otg_queue_work(ci); in a_clr_err_store()
178 mutex_unlock(&ci->fsm.lock); in a_clr_err_store()
219 static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) in ci_otg_add_timer() argument
226 spin_lock_irqsave(&ci->lock, flags); in ci_otg_add_timer()
229 ci->hr_timeouts[t] = ktime_add(ktime_get(), in ci_otg_add_timer()
231 ci->enabled_otg_timer_bits |= (1 << t); in ci_otg_add_timer()
232 if ((ci->next_otg_timer == NUM_OTG_FSM_TIMERS) || in ci_otg_add_timer()
233 ktime_after(ci->hr_timeouts[ci->next_otg_timer], in ci_otg_add_timer()
234 ci->hr_timeouts[t])) { in ci_otg_add_timer()
235 ci->next_otg_timer = t; in ci_otg_add_timer()
236 hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, in ci_otg_add_timer()
237 ci->hr_timeouts[t], NSEC_PER_MSEC, in ci_otg_add_timer()
240 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_add_timer()
246 static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) in ci_otg_del_timer() argument
252 !(ci->enabled_otg_timer_bits & (1 << t))) in ci_otg_del_timer()
255 spin_lock_irqsave(&ci->lock, flags); in ci_otg_del_timer()
256 ci->enabled_otg_timer_bits &= ~(1 << t); in ci_otg_del_timer()
257 if (ci->next_otg_timer == t) { in ci_otg_del_timer()
258 if (ci->enabled_otg_timer_bits == 0) { in ci_otg_del_timer()
260 hrtimer_cancel(&ci->otg_fsm_hrtimer); in ci_otg_del_timer()
261 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_otg_del_timer()
264 enabled_timer_bits = ci->enabled_otg_timer_bits; in ci_otg_del_timer()
268 ktime_before(ci->hr_timeouts[next_timer], in ci_otg_del_timer()
269 ci->hr_timeouts[cur_timer])) in ci_otg_del_timer()
275 ci->next_otg_timer = next_timer; in ci_otg_del_timer()
276 hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, in ci_otg_del_timer()
277 ci->hr_timeouts[next_timer], NSEC_PER_MSEC, in ci_otg_del_timer()
280 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_del_timer()
284 static int a_wait_vrise_tmout(struct ci_hdrc *ci) in a_wait_vrise_tmout() argument
286 ci->fsm.a_wait_vrise_tmout = 1; in a_wait_vrise_tmout()
290 static int a_wait_vfall_tmout(struct ci_hdrc *ci) in a_wait_vfall_tmout() argument
292 ci->fsm.a_wait_vfall_tmout = 1; in a_wait_vfall_tmout()
296 static int a_wait_bcon_tmout(struct ci_hdrc *ci) in a_wait_bcon_tmout() argument
298 ci->fsm.a_wait_bcon_tmout = 1; in a_wait_bcon_tmout()
302 static int a_aidl_bdis_tmout(struct ci_hdrc *ci) in a_aidl_bdis_tmout() argument
304 ci->fsm.a_aidl_bdis_tmout = 1; in a_aidl_bdis_tmout()
308 static int b_ase0_brst_tmout(struct ci_hdrc *ci) in b_ase0_brst_tmout() argument
310 ci->fsm.b_ase0_brst_tmout = 1; in b_ase0_brst_tmout()
314 static int a_bidl_adis_tmout(struct ci_hdrc *ci) in a_bidl_adis_tmout() argument
316 ci->fsm.a_bidl_adis_tmout = 1; in a_bidl_adis_tmout()
320 static int b_aidl_bdis_tmout(struct ci_hdrc *ci) in b_aidl_bdis_tmout() argument
322 ci->fsm.a_bus_suspend = 1; in b_aidl_bdis_tmout()
326 static int b_se0_srp_tmout(struct ci_hdrc *ci) in b_se0_srp_tmout() argument
328 ci->fsm.b_se0_srp = 1; in b_se0_srp_tmout()
332 static int b_srp_fail_tmout(struct ci_hdrc *ci) in b_srp_fail_tmout() argument
334 ci->fsm.b_srp_done = 1; in b_srp_fail_tmout()
338 static int b_data_pls_tmout(struct ci_hdrc *ci) in b_data_pls_tmout() argument
340 ci->fsm.b_srp_done = 1; in b_data_pls_tmout()
341 ci->fsm.b_bus_req = 0; in b_data_pls_tmout()
342 if (ci->fsm.power_up) in b_data_pls_tmout()
343 ci->fsm.power_up = 0; in b_data_pls_tmout()
344 hw_write_otgsc(ci, OTGSC_HABA, 0); in b_data_pls_tmout()
345 pm_runtime_put(ci->dev); in b_data_pls_tmout()
349 static int b_ssend_srp_tmout(struct ci_hdrc *ci) in b_ssend_srp_tmout() argument
351 ci->fsm.b_ssend_srp = 1; in b_ssend_srp_tmout()
353 if (ci->fsm.otg->state == OTG_STATE_B_IDLE) in b_ssend_srp_tmout()
383 struct ci_hdrc *ci = container_of(t, struct ci_hdrc, otg_fsm_hrtimer); in ci_otg_hrtimer_func() local
390 spin_lock_irqsave(&ci->lock, flags); in ci_otg_hrtimer_func()
391 enabled_timer_bits = ci->enabled_otg_timer_bits; in ci_otg_hrtimer_func()
392 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_otg_hrtimer_func()
396 if (ktime_compare(now, ci->hr_timeouts[cur_timer]) >= 0) { in ci_otg_hrtimer_func()
397 ci->enabled_otg_timer_bits &= ~(1 << cur_timer); in ci_otg_hrtimer_func()
399 ret = otg_timer_handlers[cur_timer](ci); in ci_otg_hrtimer_func()
402 ktime_before(ci->hr_timeouts[cur_timer], in ci_otg_hrtimer_func()
403 ci->hr_timeouts[next_timer])) in ci_otg_hrtimer_func()
409 timeout = &ci->hr_timeouts[next_timer]; in ci_otg_hrtimer_func()
410 hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, *timeout, in ci_otg_hrtimer_func()
412 ci->next_otg_timer = next_timer; in ci_otg_hrtimer_func()
414 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_hrtimer_func()
417 ci_otg_queue_work(ci); in ci_otg_hrtimer_func()
423 static int ci_otg_init_timers(struct ci_hdrc *ci) in ci_otg_init_timers() argument
425 hrtimer_init(&ci->otg_fsm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in ci_otg_init_timers()
426 ci->otg_fsm_hrtimer.function = ci_otg_hrtimer_func; in ci_otg_init_timers()
436 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_add_timer() local
439 ci_otg_add_timer(ci, t); in ci_otg_fsm_add_timer()
445 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_del_timer() local
448 ci_otg_del_timer(ci, t); in ci_otg_fsm_del_timer()
459 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_drv_vbus() local
463 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, in ci_otg_drv_vbus()
465 if (ci->platdata->reg_vbus) { in ci_otg_drv_vbus()
466 ret = regulator_enable(ci->platdata->reg_vbus); in ci_otg_drv_vbus()
468 dev_err(ci->dev, in ci_otg_drv_vbus()
475 hw_write_otgsc(ci, OTGSC_DPIE, 0); in ci_otg_drv_vbus()
480 if (ci->platdata->reg_vbus) in ci_otg_drv_vbus()
481 regulator_disable(ci->platdata->reg_vbus); in ci_otg_drv_vbus()
493 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_loc_conn() local
496 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); in ci_otg_loc_conn()
498 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in ci_otg_loc_conn()
535 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_pulse() local
538 hw_write_otgsc(ci, OTGSC_HADP, OTGSC_HADP); in ci_otg_start_pulse()
540 pm_runtime_get(ci->dev); in ci_otg_start_pulse()
541 ci_otg_add_timer(ci, B_DATA_PLS); in ci_otg_start_pulse()
546 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_host() local
549 ci_role_stop(ci); in ci_otg_start_host()
550 ci_role_start(ci, CI_ROLE_HOST); in ci_otg_start_host()
552 ci_role_stop(ci); in ci_otg_start_host()
553 ci_role_start(ci, CI_ROLE_GADGET); in ci_otg_start_host()
560 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_gadget() local
563 usb_gadget_vbus_connect(&ci->gadget); in ci_otg_start_gadget()
565 usb_gadget_vbus_disconnect(&ci->gadget); in ci_otg_start_gadget()
581 int ci_otg_fsm_work(struct ci_hdrc *ci) in ci_otg_fsm_work() argument
587 if (ci->fsm.id && !(ci->driver) && in ci_otg_fsm_work()
588 ci->fsm.otg->state < OTG_STATE_A_IDLE) in ci_otg_fsm_work()
591 pm_runtime_get_sync(ci->dev); in ci_otg_fsm_work()
592 if (otg_statemachine(&ci->fsm)) { in ci_otg_fsm_work()
593 if (ci->fsm.otg->state == OTG_STATE_A_IDLE) { in ci_otg_fsm_work()
602 if ((ci->fsm.id) || (ci->id_event) || in ci_otg_fsm_work()
603 (ci->fsm.power_up)) { in ci_otg_fsm_work()
604 ci_otg_queue_work(ci); in ci_otg_fsm_work()
607 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | in ci_otg_fsm_work()
609 hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); in ci_otg_fsm_work()
610 hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE); in ci_otg_fsm_work()
612 if (ci->id_event) in ci_otg_fsm_work()
613 ci->id_event = false; in ci_otg_fsm_work()
614 } else if (ci->fsm.otg->state == OTG_STATE_B_IDLE) { in ci_otg_fsm_work()
615 if (ci->fsm.b_sess_vld) { in ci_otg_fsm_work()
616 ci->fsm.power_up = 0; in ci_otg_fsm_work()
621 ci_otg_queue_work(ci); in ci_otg_fsm_work()
623 } else if (ci->fsm.otg->state == OTG_STATE_A_HOST) { in ci_otg_fsm_work()
624 pm_runtime_mark_last_busy(ci->dev); in ci_otg_fsm_work()
625 pm_runtime_put_autosuspend(ci->dev); in ci_otg_fsm_work()
629 pm_runtime_put_sync(ci->dev); in ci_otg_fsm_work()
637 static void ci_otg_fsm_event(struct ci_hdrc *ci) in ci_otg_fsm_event() argument
640 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_event()
642 intr_sts = hw_read_intr_status(ci); in ci_otg_fsm_event()
643 otg_bsess_vld = hw_read_otgsc(ci, OTGSC_BSV); in ci_otg_fsm_event()
644 port_conn = hw_read(ci, OP_PORTSC, PORTSC_CCS); in ci_otg_fsm_event()
646 switch (ci->fsm.otg->state) { in ci_otg_fsm_event()
651 ci_otg_queue_work(ci); in ci_otg_fsm_event()
657 ci_otg_queue_work(ci); in ci_otg_fsm_event()
662 ci_otg_add_timer(ci, B_AIDL_BDIS); in ci_otg_fsm_event()
664 ci_otg_del_timer(ci, B_AIDL_BDIS); in ci_otg_fsm_event()
673 ci_otg_queue_work(ci); in ci_otg_fsm_event()
684 ci_otg_add_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
688 ci_otg_del_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
692 ci_otg_del_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
702 if (ci->driver) { in ci_otg_fsm_event()
704 ci->gadget.is_a_peripheral = 1; in ci_otg_fsm_event()
706 ci_otg_queue_work(ci); in ci_otg_fsm_event()
712 ci_otg_queue_work(ci); in ci_otg_fsm_event()
718 ci_otg_queue_work(ci); in ci_otg_fsm_event()
732 irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci) in ci_otg_fsm_irq() argument
736 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_irq()
738 otgsc = hw_read_otgsc(ci, ~0); in ci_otg_fsm_irq()
744 hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); in ci_otg_fsm_irq()
748 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); in ci_otg_fsm_irq()
752 ci->id_event = true; in ci_otg_fsm_irq()
755 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); in ci_otg_fsm_irq()
758 ci_otg_del_timer(ci, B_SSEND_SRP); in ci_otg_fsm_irq()
759 ci_otg_del_timer(ci, B_SRP_FAIL); in ci_otg_fsm_irq()
764 ci_otg_add_timer(ci, B_SSEND_SRP); in ci_otg_fsm_irq()
767 hw_write_otgsc(ci, OTGSC_AVVIS, OTGSC_AVVIS); in ci_otg_fsm_irq()
775 ci_otg_queue_work(ci); in ci_otg_fsm_irq()
779 ci_otg_fsm_event(ci); in ci_otg_fsm_irq()
784 void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_start() argument
786 ci_otg_queue_work(ci); in ci_hdrc_otg_fsm_start()
789 int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_init() argument
793 if (ci->phy) in ci_hdrc_otg_fsm_init()
794 ci->otg.phy = ci->phy; in ci_hdrc_otg_fsm_init()
796 ci->otg.usb_phy = ci->usb_phy; in ci_hdrc_otg_fsm_init()
798 ci->otg.gadget = &ci->gadget; in ci_hdrc_otg_fsm_init()
799 ci->fsm.otg = &ci->otg; in ci_hdrc_otg_fsm_init()
800 ci->fsm.power_up = 1; in ci_hdrc_otg_fsm_init()
801 ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0; in ci_hdrc_otg_fsm_init()
802 ci->fsm.otg->state = OTG_STATE_UNDEFINED; in ci_hdrc_otg_fsm_init()
803 ci->fsm.ops = &ci_otg_ops; in ci_hdrc_otg_fsm_init()
804 ci->gadget.hnp_polling_support = 1; in ci_hdrc_otg_fsm_init()
805 ci->fsm.host_req_flag = devm_kzalloc(ci->dev, 1, GFP_KERNEL); in ci_hdrc_otg_fsm_init()
806 if (!ci->fsm.host_req_flag) in ci_hdrc_otg_fsm_init()
809 mutex_init(&ci->fsm.lock); in ci_hdrc_otg_fsm_init()
811 retval = ci_otg_init_timers(ci); in ci_hdrc_otg_fsm_init()
813 dev_err(ci->dev, "Couldn't init OTG timers\n"); in ci_hdrc_otg_fsm_init()
816 ci->enabled_otg_timer_bits = 0; in ci_hdrc_otg_fsm_init()
817 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_hdrc_otg_fsm_init()
819 retval = sysfs_create_group(&ci->dev->kobj, &inputs_attr_group); in ci_hdrc_otg_fsm_init()
821 dev_dbg(ci->dev, in ci_hdrc_otg_fsm_init()
827 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE); in ci_hdrc_otg_fsm_init()
829 if (ci->fsm.id) { in ci_hdrc_otg_fsm_init()
830 ci->fsm.b_ssend_srp = in ci_hdrc_otg_fsm_init()
831 hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1; in ci_hdrc_otg_fsm_init()
832 ci->fsm.b_sess_vld = in ci_hdrc_otg_fsm_init()
833 hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0; in ci_hdrc_otg_fsm_init()
835 hw_write_otgsc(ci, OTGSC_BSVIE, OTGSC_BSVIE); in ci_hdrc_otg_fsm_init()
841 void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_remove() argument
843 sysfs_remove_group(&ci->dev->kobj, &inputs_attr_group); in ci_hdrc_otg_fsm_remove()