···33To show how to demo OTG HNP and SRP functions via sys input files44with 2 Freescale i.MX6Q sabre SD boards.5566-1.1 How to enable OTG FSM in menuconfig66+1.1 How to enable OTG FSM77---------------------------------------88-Select CONFIG_USB_OTG_FSM, rebuild kernel Image and modules.99-If you want to check some internal variables for otg fsm,1010-mount debugfs, there are 2 files which can show otg fsm1111-variables and some controller registers value:88+1.1.1 Select CONFIG_USB_OTG_FSM in menuconfig, rebuild kernel99+Image and modules. If you want to check some internal1010+variables for otg fsm, mount debugfs, there are 2 files1111+which can show otg fsm variables and some controller registers value:1212cat /sys/kernel/debug/ci_hdrc.0/otg1313cat /sys/kernel/debug/ci_hdrc.0/registers1414+1.1.2 Add below entries in your dts file for your controller node1515+ otg-rev = <0x0200>;1616+ adp-disable;141715181.2 Test operations1619-------------------
-4
drivers/usb/chipidea/ci_hdrc_imx.c
···292292 if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM)293293 data->supports_runtime_pm = true;294294295295- ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));296296- if (ret)297297- goto err_clk;298298-299295 ret = imx_usbmisc_init(data->usbmisc_data);300296 if (ret) {301297 dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", ret);
+4-6
drivers/usb/common/usb-otg-fsm.c
···6161 return 0;6262}63636464-static int state_changed;6565-6664/* Called when leaving a state. Do state clean up jobs here */6765static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)6866{···206208/* Called when entering a state */207209static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)208210{209209- state_changed = 1;210211 if (fsm->otg->state == new_state)211212 return 0;212213 VDBG("Set state: %s\n", usb_otg_state_string(new_state));···321324 }322325323326 fsm->otg->state = new_state;327327+ fsm->state_changed = 1;324328 return 0;325329}326330···333335 mutex_lock(&fsm->lock);334336335337 state = fsm->otg->state;336336- state_changed = 0;338338+ fsm->state_changed = 0;337339 /* State machine state change judgement */338340339341 switch (state) {···446448 }447449 mutex_unlock(&fsm->lock);448450449449- VDBG("quit statemachine, changed = %d\n", state_changed);450450- return state_changed;451451+ VDBG("quit statemachine, changed = %d\n", fsm->state_changed);452452+ return fsm->state_changed;451453}452454EXPORT_SYMBOL_GPL(otg_statemachine);
+84-7
include/linux/usb/otg-fsm.h
···7272 NUM_OTG_FSM_TIMERS,7373};74747575-/* OTG state machine according to the OTG spec */7575+/**7676+ * struct otg_fsm - OTG state machine according to the OTG spec7777+ *7878+ * OTG hardware Inputs7979+ *8080+ * Common inputs for A and B device8181+ * @id: TRUE for B-device, FALSE for A-device.8282+ * @adp_change: TRUE when current ADP measurement (n) value, compared to the8383+ * ADP measurement taken at n-2, differs by more than CADP_THR8484+ * @power_up: TRUE when the OTG device first powers up its USB system and8585+ * ADP measurement taken if ADP capable8686+ *8787+ * A-Device state inputs8888+ * @a_srp_det: TRUE if the A-device detects SRP8989+ * @a_vbus_vld: TRUE when VBUS voltage is in regulation9090+ * @b_conn: TRUE if the A-device detects connection from the B-device9191+ * @a_bus_resume: TRUE when the B-device detects that the A-device is signaling9292+ * a resume (K state)9393+ * B-Device state inputs9494+ * @a_bus_suspend: TRUE when the B-device detects that the A-device has put the9595+ * bus into suspend9696+ * @a_conn: TRUE if the B-device detects a connection from the A-device9797+ * @b_se0_srp: TRUE when the line has been at SE0 for more than the minimum9898+ * time before generating SRP9999+ * @b_ssend_srp: TRUE when the VBUS has been below VOTG_SESS_VLD for more than100100+ * the minimum time before generating SRP101101+ * @b_sess_vld: TRUE when the B-device detects that the voltage on VBUS is102102+ * above VOTG_SESS_VLD103103+ * @test_device: TRUE when the B-device switches to B-Host and detects an OTG104104+ * test device. This must be set by host/hub driver105105+ *106106+ * Application inputs (A-Device)107107+ * @a_bus_drop: TRUE when A-device application needs to power down the bus108108+ * @a_bus_req: TRUE when A-device application wants to use the bus.109109+ * FALSE to suspend the bus110110+ *111111+ * Application inputs (B-Device)112112+ * @b_bus_req: TRUE during the time that the Application running on the113113+ * B-device wants to use the bus114114+ *115115+ * Auxilary inputs (OTG v1.3 only. Obsolete now.)116116+ * @a_sess_vld: TRUE if the A-device detects that VBUS is above VA_SESS_VLD117117+ * @b_bus_suspend: TRUE when the A-device detects that the B-device has put118118+ * the bus into suspend119119+ * @b_bus_resume: TRUE when the A-device detects that the B-device is signaling120120+ * resume on the bus121121+ *122122+ * OTG Output status. Read only for users. Updated by OTG FSM helpers defined123123+ * in this file124124+ *125125+ * Outputs for Both A and B device126126+ * @drv_vbus: TRUE when A-device is driving VBUS127127+ * @loc_conn: TRUE when the local device has signaled that it is connected128128+ * to the bus129129+ * @loc_sof: TRUE when the local device is generating activity on the bus130130+ * @adp_prb: TRUE when the local device is in the process of doing131131+ * ADP probing132132+ *133133+ * Outputs for B-device state134134+ * @adp_sns: TRUE when the B-device is in the process of carrying out135135+ * ADP sensing136136+ * @data_pulse: TRUE when the B-device is performing data line pulsing137137+ *138138+ * Internal Variables139139+ *140140+ * a_set_b_hnp_en: TRUE when the A-device has successfully set the141141+ * b_hnp_enable bit in the B-device.142142+ * Unused as OTG fsm uses otg->host->b_hnp_enable instead143143+ * b_srp_done: TRUE when the B-device has completed initiating SRP144144+ * b_hnp_enable: TRUE when the B-device has accepted the145145+ * SetFeature(b_hnp_enable) B-device.146146+ * Unused as OTG fsm uses otg->gadget->b_hnp_enable instead147147+ * a_clr_err: Asserted (by application ?) to clear a_vbus_err due to an148148+ * overcurrent condition and causes the A-device to transition149149+ * to a_wait_vfall150150+ */76151struct otg_fsm {77152 /* Input */78153 int id;79154 int adp_change;80155 int power_up;8181- int test_device;8282- int a_bus_drop;8383- int a_bus_req;84156 int a_srp_det;85157 int a_vbus_vld;86158 int b_conn;87159 int a_bus_resume;88160 int a_bus_suspend;89161 int a_conn;9090- int b_bus_req;91162 int b_se0_srp;92163 int b_ssend_srp;93164 int b_sess_vld;165165+ int test_device;166166+ int a_bus_drop;167167+ int a_bus_req;168168+ int b_bus_req;169169+94170 /* Auxilary inputs */95171 int a_sess_vld;96172 int b_bus_resume;97173 int b_bus_suspend;9817499175 /* Output */100100- int data_pulse;101176 int drv_vbus;102177 int loc_conn;103178 int loc_sof;104179 int adp_prb;105180 int adp_sns;181181+ int data_pulse;106182107183 /* Internal variables */108184 int a_set_b_hnp_en;···186110 int b_hnp_enable;187111 int a_clr_err;188112189189- /* Informative variables */113113+ /* Informative variables. All unused as of now */190114 int a_bus_drop_inf;191115 int a_bus_req_inf;192116 int a_clr_err_inf;···210134 struct mutex lock;211135 u8 *host_req_flag;212136 struct delayed_work hnp_polling_work;137137+ bool state_changed;213138};214139215140struct otg_fsm_ops {