Lines Matching full:fsm
3 * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
11 * This file mainly handles OTG fsm, it includes OTG fsm operations
40 t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_req); in a_bus_req_show()
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()
68 mutex_unlock(&ci->fsm.lock); in a_bus_req_store()
74 mutex_unlock(&ci->fsm.lock); in a_bus_req_store()
89 t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_drop); in a_bus_drop_show()
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()
114 mutex_unlock(&ci->fsm.lock); in a_bus_drop_store()
129 t = scnprintf(next, size, "%d\n", ci->fsm.b_bus_req); in b_bus_req_show()
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()
152 mutex_unlock(&ci->fsm.lock); in b_bus_req_store()
158 mutex_unlock(&ci->fsm.lock); in b_bus_req_store()
173 mutex_lock(&ci->fsm.lock); in a_clr_err_store()
175 ci->fsm.a_clr_err = 1; in a_clr_err_store()
178 mutex_unlock(&ci->fsm.lock); in a_clr_err_store()
199 * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h
285 /* OTG FSM timer handlers */
288 ci->fsm.a_wait_vrise_tmout = 1; in a_wait_vrise_tmout()
294 ci->fsm.a_wait_vfall_tmout = 1; in a_wait_vfall_tmout()
300 ci->fsm.a_wait_bcon_tmout = 1; in a_wait_bcon_tmout()
306 ci->fsm.a_aidl_bdis_tmout = 1; in a_aidl_bdis_tmout()
312 ci->fsm.b_ase0_brst_tmout = 1; in b_ase0_brst_tmout()
318 ci->fsm.a_bidl_adis_tmout = 1; in a_bidl_adis_tmout()
324 ci->fsm.a_bus_suspend = 1; in b_aidl_bdis_tmout()
330 ci->fsm.b_se0_srp = 1; in b_se0_srp_tmout()
336 ci->fsm.b_srp_done = 1; in b_srp_fail_tmout()
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()
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()
363 * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h
436 static void ci_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) in ci_otg_fsm_add_timer() argument
438 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_add_timer()
445 static void ci_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) in ci_otg_fsm_del_timer() argument
447 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_fsm_del_timer()
458 static void ci_otg_drv_vbus(struct otg_fsm *fsm, int on) in ci_otg_drv_vbus() argument
461 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_drv_vbus()
483 fsm->a_srp_det = 0; in ci_otg_drv_vbus()
484 fsm->power_up = 0; in ci_otg_drv_vbus()
492 fsm->a_bus_drop = 1; in ci_otg_drv_vbus()
493 fsm->a_bus_req = 0; in ci_otg_drv_vbus()
500 static void ci_otg_loc_conn(struct otg_fsm *fsm, int on) in ci_otg_loc_conn() argument
502 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_loc_conn()
519 static void ci_otg_loc_sof(struct otg_fsm *fsm, int on) in ci_otg_loc_sof() argument
523 if (!fsm->otg->host) in ci_otg_loc_sof()
526 udev = usb_hub_find_child(fsm->otg->host->root_hub, 1); in ci_otg_loc_sof()
542 static void ci_otg_start_pulse(struct otg_fsm *fsm) in ci_otg_start_pulse() argument
544 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_pulse()
553 static int ci_otg_start_host(struct otg_fsm *fsm, int on) in ci_otg_start_host() argument
555 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_host()
567 static int ci_otg_start_gadget(struct otg_fsm *fsm, int on) in ci_otg_start_gadget() argument
569 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); in ci_otg_start_gadget()
593 * Don't do fsm transition for B device in ci_otg_fsm_work()
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()
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()
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()
632 } else if (ci->fsm.otg->state == OTG_STATE_A_HOST) { in ci_otg_fsm_work()
643 * Update fsm variables in each state if catching expected interrupts,
644 * called by otg fsm isr.
649 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_event() local
655 switch (ci->fsm.otg->state) { in ci_otg_fsm_event()
658 fsm->b_conn = 1; in ci_otg_fsm_event()
659 fsm->a_bus_req = 1; in ci_otg_fsm_event()
665 fsm->b_sess_vld = 1; in ci_otg_fsm_event()
674 if (fsm->a_bus_suspend == 1) in ci_otg_fsm_event()
675 fsm->a_bus_suspend = 0; in ci_otg_fsm_event()
680 fsm->a_conn = 0; in ci_otg_fsm_event()
681 fsm->b_bus_req = 0; in ci_otg_fsm_event()
687 fsm->b_bus_suspend = 1; in ci_otg_fsm_event()
700 if (fsm->b_bus_suspend == 1) { in ci_otg_fsm_event()
702 fsm->b_bus_suspend = 0; in ci_otg_fsm_event()
708 fsm->b_conn = 0; in ci_otg_fsm_event()
720 fsm->b_conn = 0; in ci_otg_fsm_event()
726 fsm->a_conn = 1; in ci_otg_fsm_event()
736 * ci_otg_irq - otg fsm related irq handling
737 * and also update otg fsm variable by monitoring usb host and udc
745 struct otg_fsm *fsm = &ci->fsm; in ci_otg_fsm_irq() local
749 fsm->id = (otgsc & OTGSC_ID) ? 1 : 0; in ci_otg_fsm_irq()
754 fsm->a_srp_det = 1; in ci_otg_fsm_irq()
755 fsm->a_bus_drop = 0; in ci_otg_fsm_irq()
758 if (fsm->id == 0) { in ci_otg_fsm_irq()
759 fsm->a_bus_drop = 0; in ci_otg_fsm_irq()
760 fsm->a_bus_req = 1; in ci_otg_fsm_irq()
766 fsm->b_sess_vld = 1; in ci_otg_fsm_irq()
769 fsm->b_ssend_srp = 0; in ci_otg_fsm_irq()
771 fsm->b_sess_vld = 0; in ci_otg_fsm_irq()
772 if (fsm->id) in ci_otg_fsm_irq()
778 fsm->a_vbus_vld = 1; in ci_otg_fsm_irq()
780 fsm->a_vbus_vld = 0; in ci_otg_fsm_irq()
781 fsm->b_conn = 0; in ci_otg_fsm_irq()
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()
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()
838 if (ci->fsm.id) { in ci_hdrc_otg_fsm_init()
839 ci->fsm.b_ssend_srp = in ci_hdrc_otg_fsm_init()
841 ci->fsm.b_sess_vld = in ci_hdrc_otg_fsm_init()