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()
259 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_del_timer()
261 hrtimer_cancel(&ci->otg_fsm_hrtimer); in ci_otg_del_timer()
262 spin_lock_irqsave(&ci->lock, flags); in ci_otg_del_timer()
263 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_otg_del_timer()
266 enabled_timer_bits = ci->enabled_otg_timer_bits; in ci_otg_del_timer()
270 ktime_before(ci->hr_timeouts[next_timer], in ci_otg_del_timer()
271 ci->hr_timeouts[cur_timer])) in ci_otg_del_timer()
277 ci->next_otg_timer = next_timer; in ci_otg_del_timer()
278 hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, in ci_otg_del_timer()
279 ci->hr_timeouts[next_timer], NSEC_PER_MSEC, in ci_otg_del_timer()
282 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_del_timer()
286 static int a_wait_vrise_tmout(struct ci_hdrc *ci) in a_wait_vrise_tmout() argument
288 ci->fsm.a_wait_vrise_tmout = 1; in a_wait_vrise_tmout()
292 static int a_wait_vfall_tmout(struct ci_hdrc *ci) in a_wait_vfall_tmout() argument
294 ci->fsm.a_wait_vfall_tmout = 1; in a_wait_vfall_tmout()
298 static int a_wait_bcon_tmout(struct ci_hdrc *ci) in a_wait_bcon_tmout() argument
300 ci->fsm.a_wait_bcon_tmout = 1; in a_wait_bcon_tmout()
304 static int a_aidl_bdis_tmout(struct ci_hdrc *ci) in a_aidl_bdis_tmout() argument
306 ci->fsm.a_aidl_bdis_tmout = 1; in a_aidl_bdis_tmout()
310 static int b_ase0_brst_tmout(struct ci_hdrc *ci) in b_ase0_brst_tmout() argument
312 ci->fsm.b_ase0_brst_tmout = 1; in b_ase0_brst_tmout()
316 static int a_bidl_adis_tmout(struct ci_hdrc *ci) in a_bidl_adis_tmout() argument
318 ci->fsm.a_bidl_adis_tmout = 1; in a_bidl_adis_tmout()
322 static int b_aidl_bdis_tmout(struct ci_hdrc *ci) in b_aidl_bdis_tmout() argument
324 ci->fsm.a_bus_suspend = 1; in b_aidl_bdis_tmout()
328 static int b_se0_srp_tmout(struct ci_hdrc *ci) in b_se0_srp_tmout() argument
330 ci->fsm.b_se0_srp = 1; in b_se0_srp_tmout()
334 static int b_srp_fail_tmout(struct ci_hdrc *ci) in b_srp_fail_tmout() argument
336 ci->fsm.b_srp_done = 1; in b_srp_fail_tmout()
340 static int b_data_pls_tmout(struct ci_hdrc *ci) in b_data_pls_tmout() argument
342 ci->fsm.b_srp_done = 1; in b_data_pls_tmout()
343 ci->fsm.b_bus_req = 0; in b_data_pls_tmout()
344 if (ci->fsm.power_up) in b_data_pls_tmout()
345 ci->fsm.power_up = 0; in b_data_pls_tmout()
346 hw_write_otgsc(ci, OTGSC_HABA, 0); in b_data_pls_tmout()
347 pm_runtime_put(ci->dev); in b_data_pls_tmout()
351 static int b_ssend_srp_tmout(struct ci_hdrc *ci) in b_ssend_srp_tmout() argument
353 ci->fsm.b_ssend_srp = 1; in b_ssend_srp_tmout()
355 if (ci->fsm.otg->state == OTG_STATE_B_IDLE) in b_ssend_srp_tmout()
385 struct ci_hdrc *ci = container_of(t, struct ci_hdrc, otg_fsm_hrtimer); in ci_otg_hrtimer_func() local
392 spin_lock_irqsave(&ci->lock, flags); in ci_otg_hrtimer_func()
393 enabled_timer_bits = ci->enabled_otg_timer_bits; in ci_otg_hrtimer_func()
394 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_otg_hrtimer_func()
398 if (ktime_compare(now, ci->hr_timeouts[cur_timer]) >= 0) { in ci_otg_hrtimer_func()
399 ci->enabled_otg_timer_bits &= ~(1 << cur_timer); in ci_otg_hrtimer_func()
401 ret = otg_timer_handlers[cur_timer](ci); in ci_otg_hrtimer_func()
404 ktime_before(ci->hr_timeouts[cur_timer], in ci_otg_hrtimer_func()
405 ci->hr_timeouts[next_timer])) in ci_otg_hrtimer_func()
411 timeout = &ci->hr_timeouts[next_timer]; in ci_otg_hrtimer_func()
412 hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, *timeout, in ci_otg_hrtimer_func()
414 ci->next_otg_timer = next_timer; in ci_otg_hrtimer_func()
416 spin_unlock_irqrestore(&ci->lock, flags); in ci_otg_hrtimer_func()
419 ci_otg_queue_work(ci); in ci_otg_hrtimer_func()
425 static int ci_otg_init_timers(struct ci_hdrc *ci) in ci_otg_init_timers() argument
427 hrtimer_init(&ci->otg_fsm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in ci_otg_init_timers()
428 ci->otg_fsm_hrtimer.function = ci_otg_hrtimer_func; in ci_otg_init_timers()
438 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_add_timer() local
441 ci_otg_add_timer(ci, t); in ci_otg_fsm_add_timer()
447 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_del_timer() local
450 ci_otg_del_timer(ci, t); in ci_otg_fsm_del_timer()
461 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_drv_vbus() local
465 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, in ci_otg_drv_vbus()
467 if (ci->platdata->reg_vbus) { in ci_otg_drv_vbus()
468 ret = regulator_enable(ci->platdata->reg_vbus); in ci_otg_drv_vbus()
470 dev_err(ci->dev, in ci_otg_drv_vbus()
477 if (ci->platdata->flags & CI_HDRC_PHY_VBUS_CONTROL) in ci_otg_drv_vbus()
478 usb_phy_vbus_on(ci->usb_phy); in ci_otg_drv_vbus()
481 hw_write_otgsc(ci, OTGSC_DPIE, 0); in ci_otg_drv_vbus()
486 if (ci->platdata->reg_vbus) in ci_otg_drv_vbus()
487 regulator_disable(ci->platdata->reg_vbus); in ci_otg_drv_vbus()
489 if (ci->platdata->flags & CI_HDRC_PHY_VBUS_CONTROL) in ci_otg_drv_vbus()
490 usb_phy_vbus_off(ci->usb_phy); in ci_otg_drv_vbus()
502 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_loc_conn() local
505 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); in ci_otg_loc_conn()
507 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in ci_otg_loc_conn()
544 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_pulse() local
547 hw_write_otgsc(ci, OTGSC_HADP, OTGSC_HADP); in ci_otg_start_pulse()
549 pm_runtime_get(ci->dev); in ci_otg_start_pulse()
550 ci_otg_add_timer(ci, B_DATA_PLS); in ci_otg_start_pulse()
555 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_host() local
558 ci_role_stop(ci); in ci_otg_start_host()
559 ci_role_start(ci, CI_ROLE_HOST); in ci_otg_start_host()
561 ci_role_stop(ci); in ci_otg_start_host()
562 ci_role_start(ci, CI_ROLE_GADGET); in ci_otg_start_host()
569 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_gadget() local
572 usb_gadget_vbus_connect(&ci->gadget); in ci_otg_start_gadget()
574 usb_gadget_vbus_disconnect(&ci->gadget); in ci_otg_start_gadget()
590 int ci_otg_fsm_work(struct ci_hdrc *ci) in ci_otg_fsm_work() argument
596 if (ci->fsm.id && !(ci->driver) && in ci_otg_fsm_work()
597 ci->fsm.otg->state < OTG_STATE_A_IDLE) in ci_otg_fsm_work()
600 pm_runtime_get_sync(ci->dev); in ci_otg_fsm_work()
601 if (otg_statemachine(&ci->fsm)) { in ci_otg_fsm_work()
602 if (ci->fsm.otg->state == OTG_STATE_A_IDLE) { in ci_otg_fsm_work()
611 if ((ci->fsm.id) || (ci->id_event) || in ci_otg_fsm_work()
612 (ci->fsm.power_up)) { in ci_otg_fsm_work()
613 ci_otg_queue_work(ci); in ci_otg_fsm_work()
616 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | in ci_otg_fsm_work()
618 hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); in ci_otg_fsm_work()
619 hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE); in ci_otg_fsm_work()
621 if (ci->id_event) in ci_otg_fsm_work()
622 ci->id_event = false; in ci_otg_fsm_work()
623 } else if (ci->fsm.otg->state == OTG_STATE_B_IDLE) { in ci_otg_fsm_work()
624 if (ci->fsm.b_sess_vld) { in ci_otg_fsm_work()
625 ci->fsm.power_up = 0; in ci_otg_fsm_work()
630 ci_otg_queue_work(ci); in ci_otg_fsm_work()
632 } else if (ci->fsm.otg->state == OTG_STATE_A_HOST) { in ci_otg_fsm_work()
633 pm_runtime_mark_last_busy(ci->dev); in ci_otg_fsm_work()
634 pm_runtime_put_autosuspend(ci->dev); in ci_otg_fsm_work()
638 pm_runtime_put_sync(ci->dev); in ci_otg_fsm_work()
646 static void ci_otg_fsm_event(struct ci_hdrc *ci) in ci_otg_fsm_event() argument
649 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_event()
651 intr_sts = hw_read_intr_status(ci); in ci_otg_fsm_event()
652 otg_bsess_vld = hw_read_otgsc(ci, OTGSC_BSV); in ci_otg_fsm_event()
653 port_conn = hw_read(ci, OP_PORTSC, PORTSC_CCS); in ci_otg_fsm_event()
655 switch (ci->fsm.otg->state) { in ci_otg_fsm_event()
660 ci_otg_queue_work(ci); in ci_otg_fsm_event()
666 ci_otg_queue_work(ci); in ci_otg_fsm_event()
671 ci_otg_add_timer(ci, B_AIDL_BDIS); in ci_otg_fsm_event()
673 ci_otg_del_timer(ci, B_AIDL_BDIS); in ci_otg_fsm_event()
682 ci_otg_queue_work(ci); in ci_otg_fsm_event()
693 ci_otg_add_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
697 ci_otg_del_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
701 ci_otg_del_timer(ci, A_BIDL_ADIS); in ci_otg_fsm_event()
711 if (ci->driver) { in ci_otg_fsm_event()
713 ci->gadget.is_a_peripheral = 1; in ci_otg_fsm_event()
715 ci_otg_queue_work(ci); in ci_otg_fsm_event()
721 ci_otg_queue_work(ci); in ci_otg_fsm_event()
727 ci_otg_queue_work(ci); in ci_otg_fsm_event()
741 irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci) in ci_otg_fsm_irq() argument
745 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_irq()
747 otgsc = hw_read_otgsc(ci, ~0); in ci_otg_fsm_irq()
753 hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); in ci_otg_fsm_irq()
757 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); in ci_otg_fsm_irq()
761 ci->id_event = true; in ci_otg_fsm_irq()
764 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); in ci_otg_fsm_irq()
767 ci_otg_del_timer(ci, B_SSEND_SRP); in ci_otg_fsm_irq()
768 ci_otg_del_timer(ci, B_SRP_FAIL); in ci_otg_fsm_irq()
773 ci_otg_add_timer(ci, B_SSEND_SRP); in ci_otg_fsm_irq()
776 hw_write_otgsc(ci, OTGSC_AVVIS, OTGSC_AVVIS); in ci_otg_fsm_irq()
784 ci_otg_queue_work(ci); in ci_otg_fsm_irq()
788 ci_otg_fsm_event(ci); in ci_otg_fsm_irq()
793 void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_start() argument
795 ci_otg_queue_work(ci); in ci_hdrc_otg_fsm_start()
798 int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_init() argument
802 if (ci->phy) in ci_hdrc_otg_fsm_init()
803 ci->otg.phy = ci->phy; in ci_hdrc_otg_fsm_init()
805 ci->otg.usb_phy = ci->usb_phy; in ci_hdrc_otg_fsm_init()
807 ci->otg.gadget = &ci->gadget; in ci_hdrc_otg_fsm_init()
808 ci->fsm.otg = &ci->otg; in ci_hdrc_otg_fsm_init()
809 ci->fsm.power_up = 1; in ci_hdrc_otg_fsm_init()
810 ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0; in ci_hdrc_otg_fsm_init()
811 ci->fsm.otg->state = OTG_STATE_UNDEFINED; in ci_hdrc_otg_fsm_init()
812 ci->fsm.ops = &ci_otg_ops; in ci_hdrc_otg_fsm_init()
813 ci->gadget.hnp_polling_support = 1; in ci_hdrc_otg_fsm_init()
814 ci->fsm.host_req_flag = devm_kzalloc(ci->dev, 1, GFP_KERNEL); in ci_hdrc_otg_fsm_init()
815 if (!ci->fsm.host_req_flag) in ci_hdrc_otg_fsm_init()
818 mutex_init(&ci->fsm.lock); in ci_hdrc_otg_fsm_init()
820 retval = ci_otg_init_timers(ci); in ci_hdrc_otg_fsm_init()
822 dev_err(ci->dev, "Couldn't init OTG timers\n"); in ci_hdrc_otg_fsm_init()
825 ci->enabled_otg_timer_bits = 0; in ci_hdrc_otg_fsm_init()
826 ci->next_otg_timer = NUM_OTG_FSM_TIMERS; in ci_hdrc_otg_fsm_init()
828 retval = sysfs_create_group(&ci->dev->kobj, &inputs_attr_group); in ci_hdrc_otg_fsm_init()
830 dev_dbg(ci->dev, in ci_hdrc_otg_fsm_init()
836 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE); in ci_hdrc_otg_fsm_init()
838 if (ci->fsm.id) { in ci_hdrc_otg_fsm_init()
839 ci->fsm.b_ssend_srp = in ci_hdrc_otg_fsm_init()
840 hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1; in ci_hdrc_otg_fsm_init()
841 ci->fsm.b_sess_vld = in ci_hdrc_otg_fsm_init()
842 hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0; in ci_hdrc_otg_fsm_init()
844 hw_write_otgsc(ci, OTGSC_BSVIE, OTGSC_BSVIE); in ci_hdrc_otg_fsm_init()
850 void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) in ci_hdrc_otg_fsm_remove() argument
852 sysfs_remove_group(&ci->dev->kobj, &inputs_attr_group); in ci_hdrc_otg_fsm_remove()