Lines Matching +full:otg +full:- +full:switch
1 // SPDX-License-Identifier: GPL-2.0+
3 * OTG Finite State Machine from OTG spec
8 * Jerry Huang <Chang-Ming.Huang@freescale.com>
18 #include <linux/usb/otg.h>
19 #include <linux/usb/otg-fsm.h>
33 if (fsm->protocol != protocol) { in otg_set_protocol()
34 VDBG("Changing role fsm->protocol= %d; new protocol= %d\n", in otg_set_protocol()
35 fsm->protocol, protocol); in otg_set_protocol()
37 if (fsm->protocol == PROTO_HOST) in otg_set_protocol()
39 else if (fsm->protocol == PROTO_GADGET) in otg_set_protocol()
52 fsm->protocol = protocol; in otg_set_protocol()
62 switch (old_state) { in otg_leave_state()
65 fsm->b_se0_srp = 0; in otg_leave_state()
66 fsm->adp_sns = 0; in otg_leave_state()
67 fsm->adp_prb = 0; in otg_leave_state()
70 fsm->data_pulse = 0; in otg_leave_state()
71 fsm->b_srp_done = 0; in otg_leave_state()
74 if (fsm->otg->gadget) in otg_leave_state()
75 fsm->otg->gadget->host_request_flag = 0; in otg_leave_state()
79 fsm->b_ase0_brst_tmout = 0; in otg_leave_state()
84 fsm->adp_prb = 0; in otg_leave_state()
88 fsm->a_wait_vrise_tmout = 0; in otg_leave_state()
92 fsm->a_wait_bcon_tmout = 0; in otg_leave_state()
99 fsm->a_aidl_bdis_tmout = 0; in otg_leave_state()
100 fsm->a_suspend_req_inf = 0; in otg_leave_state()
104 fsm->a_bidl_adis_tmout = 0; in otg_leave_state()
105 if (fsm->otg->gadget) in otg_leave_state()
106 fsm->otg->gadget->host_request_flag = 0; in otg_leave_state()
110 fsm->a_wait_vfall_tmout = 0; in otg_leave_state()
125 enum usb_otg_state state = fsm->otg->state; in otg_hnp_polling_work()
132 udev = usb_hub_find_child(fsm->otg->host->root_hub, 1); in otg_hnp_polling_work()
134 dev_err(fsm->otg->host->controller, in otg_hnp_polling_work()
139 *fsm->host_req_flag = 0; in otg_hnp_polling_work()
147 fsm->host_req_flag, in otg_hnp_polling_work()
151 dev_err(&udev->dev, "Get one byte OTG status failed\n"); in otg_hnp_polling_work()
155 flag = *fsm->host_req_flag; in otg_hnp_polling_work()
158 schedule_delayed_work(&fsm->hnp_polling_work, in otg_hnp_polling_work()
162 dev_err(&udev->dev, "host request flag %d is invalid\n", flag); in otg_hnp_polling_work()
169 if (!fsm->otg->host->b_hnp_enable) { in otg_hnp_polling_work()
177 fsm->otg->host->b_hnp_enable = 1; in otg_hnp_polling_work()
179 fsm->a_bus_req = 0; in otg_hnp_polling_work()
181 fsm->b_bus_req = 0; in otg_hnp_polling_work()
193 if (!fsm->host_req_flag) in otg_start_hnp_polling()
196 if (!fsm->hnp_work_inited) { in otg_start_hnp_polling()
197 INIT_DELAYED_WORK(&fsm->hnp_polling_work, otg_hnp_polling_work); in otg_start_hnp_polling()
198 fsm->hnp_work_inited = true; in otg_start_hnp_polling()
201 schedule_delayed_work(&fsm->hnp_polling_work, in otg_start_hnp_polling()
208 if (fsm->otg->state == new_state) in otg_set_state()
211 otg_leave_state(fsm, fsm->otg->state); in otg_set_state()
212 switch (new_state) { in otg_set_state()
244 fsm->a_bus_suspend = 0; in otg_set_state()
251 usb_bus_start_enum(fsm->otg->host, in otg_set_state()
252 fsm->otg->host->otg_port); in otg_set_state()
286 if (!fsm->a_bus_req || fsm->a_suspend_req_inf) in otg_set_state()
322 fsm->otg->state = new_state; in otg_set_state()
323 fsm->state_changed = 1; in otg_set_state()
332 mutex_lock(&fsm->lock); in otg_statemachine()
334 state = fsm->otg->state; in otg_statemachine()
335 fsm->state_changed = 0; in otg_statemachine()
338 switch (state) { in otg_statemachine()
340 VDBG("fsm->id = %d\n", fsm->id); in otg_statemachine()
341 if (fsm->id) in otg_statemachine()
347 if (!fsm->id) in otg_statemachine()
349 else if (fsm->b_sess_vld && fsm->otg->gadget) in otg_statemachine()
351 else if ((fsm->b_bus_req || fsm->adp_change || fsm->power_up) && in otg_statemachine()
352 fsm->b_ssend_srp && fsm->b_se0_srp) in otg_statemachine()
356 if (!fsm->id || fsm->b_srp_done) in otg_statemachine()
360 if (!fsm->id || !fsm->b_sess_vld) in otg_statemachine()
362 else if (fsm->b_bus_req && fsm->otg-> in otg_statemachine()
363 gadget->b_hnp_enable && fsm->a_bus_suspend) in otg_statemachine()
367 if (fsm->a_conn) in otg_statemachine()
369 else if (!fsm->id || !fsm->b_sess_vld) in otg_statemachine()
371 else if (fsm->a_bus_resume || fsm->b_ase0_brst_tmout) { in otg_statemachine()
372 fsm->b_ase0_brst_tmout = 0; in otg_statemachine()
377 if (!fsm->id || !fsm->b_sess_vld) in otg_statemachine()
379 else if (!fsm->b_bus_req || !fsm->a_conn || fsm->test_device) in otg_statemachine()
383 if (fsm->id) in otg_statemachine()
385 else if (!fsm->a_bus_drop && (fsm->a_bus_req || in otg_statemachine()
386 fsm->a_srp_det || fsm->adp_change || fsm->power_up)) in otg_statemachine()
390 if (fsm->a_vbus_vld) in otg_statemachine()
392 else if (fsm->id || fsm->a_bus_drop || in otg_statemachine()
393 fsm->a_wait_vrise_tmout) in otg_statemachine()
397 if (!fsm->a_vbus_vld) in otg_statemachine()
399 else if (fsm->b_conn) in otg_statemachine()
401 else if (fsm->id || fsm->a_bus_drop || fsm->a_wait_bcon_tmout) in otg_statemachine()
405 if (fsm->id || fsm->a_bus_drop) in otg_statemachine()
407 else if ((!fsm->a_bus_req || fsm->a_suspend_req_inf) && in otg_statemachine()
408 fsm->otg->host->b_hnp_enable) in otg_statemachine()
410 else if (!fsm->b_conn) in otg_statemachine()
412 else if (!fsm->a_vbus_vld) in otg_statemachine()
416 if (!fsm->b_conn && fsm->otg->host->b_hnp_enable) in otg_statemachine()
418 else if (!fsm->b_conn && !fsm->otg->host->b_hnp_enable) in otg_statemachine()
420 else if (fsm->a_bus_req || fsm->b_bus_resume) in otg_statemachine()
422 else if (fsm->id || fsm->a_bus_drop || fsm->a_aidl_bdis_tmout) in otg_statemachine()
424 else if (!fsm->a_vbus_vld) in otg_statemachine()
428 if (fsm->id || fsm->a_bus_drop) in otg_statemachine()
430 else if (fsm->a_bidl_adis_tmout || fsm->b_bus_suspend) in otg_statemachine()
432 else if (!fsm->a_vbus_vld) in otg_statemachine()
436 if (fsm->a_wait_vfall_tmout) in otg_statemachine()
440 if (fsm->id || fsm->a_bus_drop || fsm->a_clr_err) in otg_statemachine()
446 mutex_unlock(&fsm->lock); in otg_statemachine()
448 VDBG("quit statemachine, changed = %d\n", fsm->state_changed); in otg_statemachine()
449 return fsm->state_changed; in otg_statemachine()
452 MODULE_DESCRIPTION("OTG Finite State Machine");