1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
36 * The Core Interface Layer provides basic services for accessing and
37 * managing the DWC_otg hardware. These services are used by both the
38 * Host Controller Driver and the Peripheral Controller Driver.
40 * This file contains the Common Interrupt handlers.
42 #include "common_port/dwc_os.h"
43 #include "dwc_otg_regs.h"
44 #include "dwc_otg_cil.h"
45 #include "dwc_otg_driver.h"
46 #include "dwc_otg_pcd.h"
47 #include "dwc_otg_hcd.h"
48 #include "usbdev_rk.h"
51 inline const char *op_state_str(dwc_otg_core_if_t * core_if)
53 return (core_if->op_state == A_HOST ? "a_host" :
54 (core_if->op_state == A_SUSPEND ? "a_suspend" :
55 (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
56 (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
57 (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
61 /** This function will log a debug message
63 * @param core_if Programming view of DWC_otg controller.
65 int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
67 gintsts_data_t gintsts;
68 DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
69 dwc_otg_mode(core_if) ? "Host" : "Device");
73 gintsts.b.modemismatch = 1;
74 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
79 * This function handles the OTG Interrupts. It reads the OTG
80 * Interrupt Register (GOTGINT) to determine what interrupt has
83 * @param core_if Programming view of DWC_otg controller.
85 int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
87 dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
88 gotgint_data_t gotgint;
89 gotgctl_data_t gotgctl;
90 gintmsk_data_t gintmsk;
92 dctl_data_t dctl = {.d32=0};
94 gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
95 gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
96 DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
97 op_state_str(core_if));
99 if (gotgint.b.sesenddet) {
100 DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
101 "Session End Detected++ (%s)\n",
102 op_state_str(core_if));
104 /* do soft disconnect */
105 dctl.d32= DWC_READ_REG32( &core_if->dev_if->dev_global_regs->dctl );
106 dctl.b.sftdiscon = 1;
107 DWC_WRITE_REG32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 );
108 dwc_otg_disable_global_interrupts(core_if);
109 core_if->otg_dev->pcd->vbus_status = USB_BC_TYPE_DISCNT;
110 DWC_PRINTF("********session end ,soft disconnect************************\n");
112 gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
114 if (core_if->op_state == B_HOST) {
115 cil_pcd_start(core_if);
116 core_if->op_state = B_PERIPHERAL;
118 /* If not B_HOST and Device HNP still set. HNP
120 if (gotgctl.b.devhnpen) {
121 DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
122 __DWC_ERROR("Device Not Connected/Responding!\n");
125 /* If Session End Detected the B-Cable has
126 * been disconnected. */
127 /* Reset PCD and Gadget driver to a
129 core_if->lx_state = DWC_OTG_L0;
130 DWC_SPINUNLOCK(core_if->lock);
131 cil_pcd_stop(core_if);
132 DWC_SPINLOCK(core_if->lock);
134 if (core_if->otg_ver) {
137 gotgctl.b.devhnpen = 1;
138 DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
139 if (core_if->test_mode == 6) {
140 DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg, dwc_otg_initiate_srp,
141 core_if, 3000, "initate SRP"); //manukz: old value was 50
142 core_if->test_mode = 0;
143 } else if (core_if->adp_enable) {
144 if (core_if->power_down == 2) {
146 gpwrdn.b.pwrdnswtch = 1;
147 DWC_MODIFY_REG32(&core_if->
149 gpwrdn, gpwrdn.d32, 0);
153 gpwrdn.b.pmuintsel = 1;
154 gpwrdn.b.pmuactv = 1;
155 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
156 dwc_otg_adp_sense_start(core_if);
160 if (core_if->otg_ver == 0) {
162 gotgctl.b.devhnpen = 1;
163 DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
166 if (gotgint.b.sesreqsucstschng) {
167 DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
168 "Session Reqeust Success Status Change++\n");
169 gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
170 if (gotgctl.b.sesreqscs) {
172 if ((core_if->core_params->phy_type ==
173 DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
174 core_if->srp_success = 1;
176 DWC_SPINUNLOCK(core_if->lock);
177 cil_pcd_resume(core_if);
178 DWC_SPINLOCK(core_if->lock);
179 /* Clear Session Request */
181 gotgctl.b.sesreq = 1;
182 DWC_MODIFY_REG32(&global_regs->gotgctl,
187 if (gotgint.b.hstnegsucstschng) {
188 /* Print statements during the HNP interrupt handling
189 * can cause it to fail.*/
190 gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
191 /* WA for 3.00a- HW is not setting cur_mode, even sometimes
192 * this does not help*/
193 if (core_if->snpsid >= OTG_CORE_REV_3_00a)
195 if (gotgctl.b.hstnegscs) {
196 if (dwc_otg_is_host_mode(core_if)) {
197 core_if->op_state = B_HOST;
199 * Need to disable SOF interrupt immediately.
200 * When switching from device to host, the PCD
201 * interrupt handler won't handle the
202 * interrupt if host mode is already set. The
203 * HCD interrupt handler won't get called if
204 * the HCD state is HALT. This means that the
205 * interrupt does not get handled and Linux
209 gintmsk.b.sofintr = 1;
210 //gintmsk.b.usbsuspend = 1; // vahrama !!!!!!
211 DWC_MODIFY_REG32(&global_regs->gintmsk,
213 /* Call callback function with spin lock released */
214 DWC_SPINUNLOCK(core_if->lock);
215 cil_pcd_stop(core_if);
217 * Initialize the Core for Host mode.
219 cil_hcd_start(core_if);
220 DWC_SPINLOCK(core_if->lock);
224 gotgctl.b.hnpreq = 1;
225 gotgctl.b.devhnpen = 1;
226 DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
227 DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
228 __DWC_ERROR("Device Not Connected/Responding\n");
231 if (gotgint.b.hstnegdet) {
232 /* The disconnect interrupt is set at the same time as
233 * Host Negotiation Detected. During the mode
234 * switch all interrupts are cleared so the disconnect
235 * interrupt handler will not get executed.
237 DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
238 "Host Negotiation Detected++ (%s)\n",
239 (dwc_otg_is_host_mode(core_if) ? "Host" :
241 if (dwc_otg_is_device_mode(core_if)) {
242 DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
244 DWC_SPINUNLOCK(core_if->lock);
245 cil_hcd_disconnect(core_if);
246 cil_pcd_start(core_if);
247 DWC_SPINLOCK(core_if->lock);
248 core_if->op_state = A_PERIPHERAL;
251 * Need to disable SOF interrupt immediately. When
252 * switching from device to host, the PCD interrupt
253 * handler won't handle the interrupt if host mode is
254 * already set. The HCD interrupt handler won't get
255 * called if the HCD state is HALT. This means that
256 * the interrupt does not get handled and Linux
260 gintmsk.b.sofintr = 1;
261 DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
262 DWC_SPINUNLOCK(core_if->lock);
263 cil_pcd_stop(core_if);
264 cil_hcd_start(core_if);
265 DWC_SPINLOCK(core_if->lock);
266 core_if->op_state = A_HOST;
269 if (gotgint.b.adevtoutchng) {
270 DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
271 "A-Device Timeout Change++\n");
273 if (gotgint.b.debdone) {
274 DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
275 /* Need to power off VBUS after 10s if OTG2 non-hnp capable host*/
276 if(core_if->otg_ver == 1)
277 cil_hcd_session_start(core_if);
281 DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
286 void w_conn_id_status_change(void *p)
288 dwc_otg_core_if_t *core_if = p;
290 gotgctl_data_t gotgctl = {.d32 = 0 };
291 dwc_otg_pcd_t *pcd = core_if->otg_dev->pcd;
293 gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
294 DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
295 DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
297 /* B-Device connector (Device Mode) */
298 if (gotgctl.b.conidsts) {
299 gotgctl_data_t gotgctl_local;
301 /* Wait for switch to device mode. */
302 while (!dwc_otg_is_device_mode(core_if)) {
303 gotgctl_local.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
304 DWC_DEBUGPL(DBG_ANY, "Waiting for Peripheral Mode, Mode=%s count = %d gotgctl=%08x\n",
305 (dwc_otg_is_host_mode(core_if) ? "Host" :
306 "Peripheral"), count, gotgctl_local.d32);
307 dwc_mdelay(1); //vahrama previous value was 100
308 if(!gotgctl_local.b.conidsts)
313 DWC_ASSERT(++count < 10000,
314 "Connection id status change timed out");
315 core_if->op_state = B_PERIPHERAL;
316 cil_hcd_stop(core_if);;
317 //pcd->phy_suspend = 1;
318 pcd->vbus_status = 0;
319 dwc_otg_pcd_start_check_vbus_work(pcd);
320 if(core_if->otg_ver == 0)
321 dwc_otg_core_init(core_if);
322 dwc_otg_enable_global_interrupts(core_if);
323 cil_pcd_start(core_if);
326 /* A-Device connector (Host Mode) */
327 while (!dwc_otg_is_host_mode(core_if)) {
328 DWC_DEBUGPL(DBG_ANY,"Waiting for Host Mode, Mode=%s\n",
329 (dwc_otg_is_host_mode(core_if) ? "Host" :
331 dwc_mdelay(1); //vahrama previously was 100
335 DWC_ASSERT(++count < 10000,
336 "Connection id status change timed out");
337 core_if->op_state = A_HOST;
339 cancel_delayed_work(&pcd->check_vbus_work);
342 * Initialize the Core for Host mode.
344 if (core_if->otg_ver)
345 /* To power off the bus in 10s from the beginning
346 * of test while denounce has not come yet */
347 cil_hcd_session_start(core_if);
349 dwc_otg_core_init(core_if);
350 dwc_otg_enable_global_interrupts(core_if);
351 cil_hcd_start(core_if);
356 * This function handles the Connector ID Status Change Interrupt. It
357 * reads the OTG Interrupt Register (GOTCTL) to determine whether this
358 * is a Device to Host Mode transition or a Host Mode to Device
361 * This only occurs when the cable is connected/removed from the PHY
364 * @param core_if Programming view of DWC_otg controller.
366 int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
370 * Need to disable SOF interrupt immediately. If switching from device
371 * to host, the PCD interrupt handler won't handle the interrupt if
372 * host mode is already set. The HCD interrupt handler won't get
373 * called if the HCD state is HALT. This means that the interrupt does
374 * not get handled and Linux complains loudly.
376 gintmsk_data_t gintmsk = {.d32 = 0 };
377 gintsts_data_t gintsts = {.d32 = 0 };
379 if(core_if->usb_mode != USB_MODE_NORMAL)
382 gintmsk.b.sofintr = 1;
383 DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
385 " ++Connector ID Status Change Interrupt++ (%s)\n",
386 (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
388 DWC_SPINUNLOCK(core_if->lock);
391 * Need to schedule a work, as there are possible DELAY function calls
392 * Release lock before scheduling workq as it holds spinlock during scheduling
395 DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
396 core_if, "connection id status change");
397 DWC_SPINLOCK(core_if->lock);
399 /* Set flag and clear interrupt */
400 gintsts.b.conidstschng = 1;
401 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
407 * This interrupt indicates that a device is initiating the Session
408 * Request Protocol to request the host to turn on bus power so a new
409 * session can begin. The handler responds by turning on bus power. If
410 * the DWC_otg controller is in low power mode, the handler brings the
411 * controller out of low power mode before turning on bus power.
413 * @param core_if Programming view of DWC_otg controller.
415 int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
417 gintsts_data_t gintsts;
419 #ifndef DWC_HOST_ONLY
420 DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
421 if (dwc_otg_is_device_mode(core_if)) {
422 gotgctl_data_t gotgctl = {.d32 = 0 };
423 DWC_PRINTF("SRP: Device mode\n");
425 DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
426 if (gotgctl.b.sesreqscs)
427 DWC_PRINTF("SRP Success\n");
429 DWC_PRINTF("SRP Fail\n");
430 if (core_if->otg_ver) {
432 gotgctl.b.devhnpen = 1;
433 DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, gotgctl.d32, 0);
437 DWC_PRINTF("SRP: Host mode\n");
439 /* Turn on the port power bit. */
440 hprt0.d32 = dwc_otg_read_hprt0(core_if);
442 DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
444 /* Start the Connection timer. So a message can be displayed
445 * if connect does not occur within 10 seconds. */
446 cil_hcd_session_start(core_if);
450 /* Clear interrupt */
452 gintsts.b.sessreqintr = 1;
453 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
458 void w_wakeup_detected(void *data)
460 dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *)data;
462 * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
463 * so that OPT tests pass with all PHYs).
465 hprt0_data_t hprt0 = {.d32 = 0 };
467 pcgcctl_data_t pcgcctl = {.d32 = 0 };
468 /* Restart the Phy Clock */
469 pcgcctl.b.stoppclk = 1;
470 DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
473 hprt0.d32 = dwc_otg_read_hprt0(core_if);
474 DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
476 hprt0.b.prtres = 0; /* Resume */
477 DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
478 DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
479 DWC_READ_REG32(core_if->host_if->hprt0));
481 cil_hcd_resume(core_if);
483 /** Change to L0 state*/
484 core_if->lx_state = DWC_OTG_L0;
488 * This interrupt indicates that the DWC_otg controller has detected a
489 * resume or remote wakeup sequence. If the DWC_otg controller is in
490 * low power mode, the handler must brings the controller out of low
491 * power mode. The controller automatically begins resume
492 * signaling. The handler schedules a time to stop resume signaling.
494 int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
496 gintsts_data_t gintsts;
499 "++Resume and Remote Wakeup Detected Interrupt++\n");
501 DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
503 if (dwc_otg_is_device_mode(core_if)) {
504 dctl_data_t dctl = {.d32 = 0 };
505 DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
506 DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
508 if (core_if->lx_state == DWC_OTG_L2) {
509 #ifdef PARTIAL_POWER_DOWN
510 if (core_if->hwcfg4.b.power_optimiz) {
511 pcgcctl_data_t power = {.d32 = 0 };
513 power.d32 = DWC_READ_REG32(core_if->pcgcctl);
514 DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
517 power.b.stoppclk = 0;
518 DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
521 DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
523 power.b.rstpdwnmodule = 0;
524 DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
527 /* Clear the Remote Wakeup Signaling */
528 dctl.b.rmtwkupsig = 1;
529 DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
532 DWC_SPINUNLOCK(core_if->lock);
533 if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
534 core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
536 DWC_SPINLOCK(core_if->lock);
538 glpmcfg_data_t lpmcfg;
539 pcgcctl_data_t pcgcctl = {.d32 = 0 };
542 DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
543 lpmcfg.b.hird_thres &= (~(1 << 4));
544 lpmcfg.b.en_utmi_sleep = 0;
546 /* Clear Enbl_L1Gating bit. */
547 pcgcctl.b.enbl_sleep_gating = 1;
548 DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,0);
550 DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
553 /** Change to L0 state*/
554 core_if->lx_state = DWC_OTG_L0;
556 if (core_if->lx_state != DWC_OTG_L1) {
557 pcgcctl_data_t pcgcctl = {.d32 = 0 };
559 /* Restart the Phy Clock */
560 pcgcctl.b.stoppclk = 1;
561 DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
562 DWC_TASK_SCHEDULE(core_if->wkp_tasklet);
564 /** Change to L0 state*/
565 core_if->lx_state = DWC_OTG_L0;
569 /* Clear interrupt */
571 gintsts.b.wkupintr = 1;
572 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
578 * This interrupt indicates that the Wakeup Logic has detected a
581 static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t * core_if)
583 gpwrdn_data_t gpwrdn = {.d32 = 0 };
584 gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
585 gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
587 DWC_PRINTF("%s called\n", __FUNCTION__);
589 if (!core_if->hibernation_suspend) {
590 DWC_PRINTF("Already exited from Hibernation\n");
594 /* Switch on the voltage to the core */
595 gpwrdn.b.pwrdnswtch = 1;
596 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
601 gpwrdn.b.pwrdnrstn = 1;
602 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
605 /* Disable power clamps */
607 gpwrdn.b.pwrdnclmp = 1;
608 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
610 /* Remove reset the core signal */
612 gpwrdn.b.pwrdnrstn = 1;
613 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
616 /* Disable PMU interrupt */
618 gpwrdn.b.pmuintsel = 1;
619 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
621 core_if->hibernation_suspend = 0;
625 gpwrdn.b.pmuactv = 1;
626 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
629 if (gpwrdn_temp.b.idsts) {
630 core_if->op_state = B_PERIPHERAL;
631 dwc_otg_core_init(core_if);
632 dwc_otg_enable_global_interrupts(core_if);
633 cil_pcd_start(core_if);
635 core_if->op_state = A_HOST;
636 dwc_otg_core_init(core_if);
637 dwc_otg_enable_global_interrupts(core_if);
638 cil_hcd_start(core_if);
645 * This interrupt indicates that the Wakeup Logic has detected a
646 * remote wakeup sequence.
648 static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
650 gpwrdn_data_t gpwrdn = {.d32 = 0 };
652 "++Powerdown Remote Wakeup Detected Interrupt++\n");
654 if (!core_if->hibernation_suspend) {
655 DWC_PRINTF("Already exited from Hibernation\n");
659 gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
660 if (gpwrdn.b.idsts) { // Device Mode
661 if ((core_if->power_down == 2)
662 && (core_if->hibernation_suspend == 1)) {
663 dwc_otg_device_hibernation_restore(core_if, 0, 0);
666 if ((core_if->power_down == 2)
667 && (core_if->hibernation_suspend == 1)) {
668 dwc_otg_host_hibernation_restore(core_if, 1, 0);
674 static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t * otg_dev)
676 gpwrdn_data_t gpwrdn = {.d32 = 0 };
677 gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
678 dwc_otg_core_if_t *core_if = otg_dev->core_if;
680 DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
681 gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
682 if (core_if->power_down == 2) {
683 if (!core_if->hibernation_suspend) {
684 DWC_PRINTF("Already exited from Hibernation\n");
687 DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
688 /* Switch on the voltage to the core */
689 gpwrdn.b.pwrdnswtch = 1;
690 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
695 gpwrdn.b.pwrdnrstn = 1;
696 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
699 /* Disable power clamps */
701 gpwrdn.b.pwrdnclmp = 1;
702 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
704 /* Remove reset the core signal */
706 gpwrdn.b.pwrdnrstn = 1;
707 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
710 /* Disable PMU interrupt */
712 gpwrdn.b.pmuintsel = 1;
713 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
715 /*Indicates that we are exiting from hibernation */
716 core_if->hibernation_suspend = 0;
720 gpwrdn.b.pmuactv = 1;
721 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
724 gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
725 if (gpwrdn.b.dis_vbus == 1) {
727 gpwrdn.b.dis_vbus = 1;
728 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
731 if (gpwrdn_temp.b.idsts) {
732 core_if->op_state = B_PERIPHERAL;
733 dwc_otg_core_init(core_if);
734 dwc_otg_enable_global_interrupts(core_if);
735 cil_pcd_start(core_if);
737 core_if->op_state = A_HOST;
738 dwc_otg_core_init(core_if);
739 dwc_otg_enable_global_interrupts(core_if);
740 cil_hcd_start(core_if);
744 if (core_if->adp_enable) {
746 DWC_SPINUNLOCK(core_if->lock);
747 /* Change the core_if's lock to hcd/pcd lock depend on mode? */
748 #ifndef DWC_HOST_ONLY
749 if (gpwrdn_temp.b.idsts)
750 core_if->lock = otg_dev->pcd->lock;
752 #ifndef DWC_DEVICE_ONLY
753 if (!gpwrdn_temp.b.idsts) {
754 core_if->lock = otg_dev->hcd->lock;
758 DWC_PRINTF("RESTART ADP\n");
759 if (core_if->adp.probe_enabled)
760 dwc_otg_adp_probe_stop(core_if);
761 if (core_if->adp.sense_enabled)
762 dwc_otg_adp_sense_stop(core_if);
763 if (core_if->adp.sense_timer_started)
764 DWC_TIMER_CANCEL(core_if->adp.sense_timer);
765 if (core_if->adp.vbuson_timer_started)
766 DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
767 core_if->adp.probe_timer_values[0] = -1;
768 core_if->adp.probe_timer_values[1] = -1;
769 core_if->adp.sense_timer_started = 0;
770 core_if->adp.vbuson_timer_started = 0;
771 core_if->adp.probe_counter = 0;
772 core_if->adp.gpwrdn = 0;
774 /* Disable PMU and restart ADP */
776 gpwrdn_temp.b.pmuactv = 1;
777 gpwrdn_temp.b.pmuintsel = 1;
778 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
779 DWC_PRINTF("Check point 1\n");
781 dwc_otg_adp_start(core_if, is_host);
782 DWC_SPINLOCK(core_if->lock);
788 static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
790 gpwrdn_data_t gpwrdn = {.d32 = 0 };
791 int32_t otg_cap_param = core_if->core_params->otg_cap;
792 DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
794 gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
795 if (core_if->power_down == 2) {
796 if (!core_if->hibernation_suspend) {
797 DWC_PRINTF("Already exited from Hibernation\n");
801 if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
802 otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
803 gpwrdn.b.bsessvld == 0) {
804 /* Save gpwrdn register for further usage if stschng interrupt */
805 core_if->gr_backup->gpwrdn_local =
806 DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
807 /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
811 /* Switch on the voltage to the core */
813 gpwrdn.b.pwrdnswtch = 1;
814 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
819 gpwrdn.b.pwrdnrstn = 1;
820 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
823 /* Disable power clamps */
825 gpwrdn.b.pwrdnclmp = 1;
826 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
828 /* Remove reset the core signal */
830 gpwrdn.b.pwrdnrstn = 1;
831 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
834 /* Disable PMU interrupt */
836 gpwrdn.b.pmuintsel = 1;
837 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
840 /*Indicates that we are exiting from hibernation */
841 core_if->hibernation_suspend = 0;
845 gpwrdn.b.pmuactv = 1;
846 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
849 core_if->op_state = B_PERIPHERAL;
850 dwc_otg_core_init(core_if);
851 dwc_otg_enable_global_interrupts(core_if);
852 cil_pcd_start(core_if);
854 if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
855 otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
857 * Initiate SRP after initial ADP probe.
859 dwc_otg_initiate_srp(core_if);
861 } else if (core_if->adp_enable){
862 dwc_otg_adp_probe_stop(core_if);
863 if (DWC_WORKQ_PENDING(core_if->wq_otg))
864 core_if->stop_adpprb = 1;
865 /* Disable Power Down Logic */
867 gpwrdn.b.pmuintsel = 1;
868 gpwrdn.b.pmuactv = 1;
869 DWC_MODIFY_REG32(&core_if->core_global_regs->
870 gpwrdn, gpwrdn.d32, 0);
873 * Initialize the Core for Device mode.
875 core_if->op_state = B_PERIPHERAL;
876 cil_pcd_start(core_if);
877 dwc_otg_enable_global_interrupts(core_if);
884 * This interrupt indicates that the Wakeup Logic has detected a
885 * status change either on IDDIG or BSessVld.
887 static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t * otg_dev)
890 gpwrdn_data_t gpwrdn = {.d32 = 0 };
891 gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
892 dwc_otg_core_if_t *core_if = otg_dev->core_if;
894 DWC_PRINTF("%s called\n", __FUNCTION__);
896 if (core_if->power_down == 2) {
897 if (core_if->hibernation_suspend <= 0) {
898 DWC_PRINTF("Already exited from Hibernation\n");
901 gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
904 gpwrdn_temp.d32 = core_if->adp.gpwrdn;
907 gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
909 if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
910 retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
911 } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
912 retval = dwc_otg_handle_pwrdn_session_change(core_if);
919 * This interrupt indicates that the Wakeup Logic has detected a
922 static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
924 gpwrdn_data_t gpwrdn = {.d32 = 0 };
926 DWC_PRINTF("%s called\n", __FUNCTION__);
928 if (!core_if->hibernation_suspend) {
929 DWC_PRINTF("Already exited from Hibernation\n");
932 #ifdef DWC_DEV_SRPCAP
933 if (core_if->pwron_timer_started) {
934 core_if->pwron_timer_started = 0;
935 DWC_TIMER_CANCEL(core_if->pwron_timer);
939 /* Switch on the voltage to the core */
940 gpwrdn.b.pwrdnswtch = 1;
941 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
946 gpwrdn.b.pwrdnrstn = 1;
947 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
950 /* Disable power clamps */
952 gpwrdn.b.pwrdnclmp = 1;
953 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
955 /* Remove reset the core signal */
957 gpwrdn.b.pwrdnrstn = 1;
958 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
961 /* Disable PMU interrupt */
963 gpwrdn.b.pmuintsel = 1;
964 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
966 /* Indicates that we are exiting from hibernation */
967 core_if->hibernation_suspend = 0;
971 gpwrdn.b.pmuactv = 1;
972 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
975 /* Programm Disable VBUS to 0 */
977 gpwrdn.b.dis_vbus = 1;
978 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
980 /*Initialize the core as Host */
981 core_if->op_state = A_HOST;
982 dwc_otg_core_init(core_if);
983 dwc_otg_enable_global_interrupts(core_if);
984 cil_hcd_start(core_if);
989 /** This interrupt indicates that restore command after Hibernation
990 * was completed by the core. */
991 int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
993 pcgcctl_data_t pcgcctl;
994 DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
996 //TODO De-assert restore signal. 8.a
997 pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
998 if (pcgcctl.b.restoremode == 1) {
999 gintmsk_data_t gintmsk = {.d32 = 0 };
1001 * If restore mode is Remote Wakeup,
1002 * unmask Remote Wakeup interrupt.
1004 gintmsk.b.wkupintr = 1;
1005 DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
1013 * This interrupt indicates that a device has been disconnected from
1016 int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
1018 gintsts_data_t gintsts;
1020 DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
1021 (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
1022 op_state_str(core_if));
1024 /** @todo Consolidate this if statement. */
1025 #ifndef DWC_HOST_ONLY
1026 if (core_if->op_state == B_HOST) {
1027 /* If in device mode Disconnect and stop the HCD, then
1029 DWC_SPINUNLOCK(core_if->lock);
1030 cil_hcd_disconnect(core_if);
1031 cil_pcd_start(core_if);
1032 DWC_SPINLOCK(core_if->lock);
1033 core_if->op_state = B_PERIPHERAL;
1034 } else if (dwc_otg_is_device_mode(core_if)) {
1035 gotgctl_data_t gotgctl = {.d32 = 0 };
1037 DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
1038 if (gotgctl.b.hstsethnpen == 1) {
1039 /* Do nothing, if HNP in process the OTG
1040 * interrupt "Host Negotiation Detected"
1041 * interrupt will do the mode switch.
1043 } else if (gotgctl.b.devhnpen == 0) {
1044 /* If in device mode Disconnect and stop the HCD, then
1046 DWC_SPINUNLOCK(core_if->lock);
1047 cil_hcd_disconnect(core_if);
1048 cil_pcd_start(core_if);
1049 DWC_SPINLOCK(core_if->lock);
1050 core_if->op_state = B_PERIPHERAL;
1052 DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
1055 if (core_if->op_state == A_HOST) {
1056 /* A-Cable still connected but device disconnected. */
1057 cil_hcd_disconnect(core_if);
1058 if (core_if->adp_enable) {
1059 gpwrdn_data_t gpwrdn = {.d32 = 0 };
1060 cil_hcd_stop(core_if);
1061 /* Enable Power Down Logic */
1062 gpwrdn.b.pmuintsel = 1;
1063 gpwrdn.b.pmuactv = 1;
1064 DWC_MODIFY_REG32(&core_if->core_global_regs->
1065 gpwrdn, 0, gpwrdn.d32);
1066 dwc_otg_adp_probe_start(core_if);
1068 /* Power off the core */
1069 if (core_if->power_down == 2) {
1071 gpwrdn.b.pwrdnswtch = 1;
1073 (&core_if->core_global_regs->gpwrdn,
1080 /* Change to L3(OFF) state */
1081 core_if->lx_state = DWC_OTG_L3;
1084 gintsts.b.disconnect = 1;
1085 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
1090 * This interrupt indicates that SUSPEND state has been detected on
1093 * For HNP the USB Suspend interrupt signals the change from
1094 * "a_peripheral" to "a_host".
1096 * When power management is enabled the core will be put in low power
1099 int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
1102 gintsts_data_t gintsts;
1105 DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
1107 if ((core_if->otg_ver == 1) && (core_if->op_state == A_PERIPHERAL))
1108 dwc_mdelay(200); //vahrama - WA - see BU's mail
1110 if (dwc_otg_is_device_mode(core_if)) {
1111 /* Check the Device status register to determine if the Suspend
1112 * state is active. */
1114 DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
1115 DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
1116 DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
1117 "HWCFG4.power Optimize=%d\n",
1118 dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
1120 #ifdef PARTIAL_POWER_DOWN
1121 /** @todo Add a module parameter for power management. */
1123 if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
1124 pcgcctl_data_t power = {.d32 = 0 };
1125 DWC_DEBUGPL(DBG_CIL, "suspend\n");
1127 power.b.pwrclmp = 1;
1128 DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
1130 power.b.rstpdwnmodule = 1;
1131 DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
1133 power.b.stoppclk = 1;
1134 DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
1137 DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
1140 /* PCD callback for suspend. Release the lock inside of callback function */
1141 cil_pcd_suspend(core_if);
1142 if (core_if->power_down == 2)
1144 dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
1145 DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
1146 DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
1148 if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
1149 pcgcctl_data_t pcgcctl = {.d32 = 0 };
1150 gpwrdn_data_t gpwrdn = {.d32 = 0 };
1151 gusbcfg_data_t gusbcfg = {.d32 = 0 };
1153 /* Change to L2(suspend) state */
1154 core_if->lx_state = DWC_OTG_L2;
1156 /* Clear interrupt in gintsts */
1158 gintsts.b.usbsuspend = 1;
1159 DWC_WRITE_REG32(&core_if->core_global_regs->
1160 gintsts, gintsts.d32);
1161 DWC_PRINTF("Start of hibernation completed\n");
1162 dwc_otg_save_global_regs(core_if);
1163 dwc_otg_save_dev_regs(core_if);
1166 DWC_READ_REG32(&core_if->core_global_regs->
1168 if (gusbcfg.b.ulpi_utmi_sel == 1) {
1169 /* ULPI interface */
1170 /* Suspend the Phy Clock */
1172 pcgcctl.b.stoppclk = 1;
1173 DWC_MODIFY_REG32(core_if->pcgcctl, 0,
1176 gpwrdn.b.pmuactv = 1;
1177 DWC_MODIFY_REG32(&core_if->
1179 gpwrdn, 0, gpwrdn.d32);
1181 /* UTMI+ Interface */
1182 gpwrdn.b.pmuactv = 1;
1183 DWC_MODIFY_REG32(&core_if->
1185 gpwrdn, 0, gpwrdn.d32);
1187 pcgcctl.b.stoppclk = 1;
1188 DWC_MODIFY_REG32(core_if->pcgcctl, 0,
1193 /* Set flag to indicate that we are in hibernation */
1194 core_if->hibernation_suspend = 1;
1195 /* Enable interrupts from wake up logic */
1197 gpwrdn.b.pmuintsel = 1;
1198 DWC_MODIFY_REG32(&core_if->core_global_regs->
1199 gpwrdn, 0, gpwrdn.d32);
1202 /* Unmask device mode interrupts in GPWRDN */
1204 gpwrdn.b.rst_det_msk = 1;
1205 gpwrdn.b.lnstchng_msk = 1;
1206 gpwrdn.b.sts_chngint_msk = 1;
1207 DWC_MODIFY_REG32(&core_if->core_global_regs->
1208 gpwrdn, 0, gpwrdn.d32);
1211 /* Enable Power Down Clamp */
1213 gpwrdn.b.pwrdnclmp = 1;
1214 DWC_MODIFY_REG32(&core_if->core_global_regs->
1215 gpwrdn, 0, gpwrdn.d32);
1218 /* Switch off VDD */
1220 gpwrdn.b.pwrdnswtch = 1;
1221 DWC_MODIFY_REG32(&core_if->core_global_regs->
1222 gpwrdn, 0, gpwrdn.d32);
1224 /* Save gpwrdn register for further usage if stschng interrupt */
1225 core_if->gr_backup->gpwrdn_local =
1226 DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
1227 DWC_PRINTF("Hibernation completed\n");
1231 } else if (core_if->power_down == 3) {
1232 pcgcctl_data_t pcgcctl = {.d32 = 0 };
1233 dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
1234 DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
1235 DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
1237 if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
1238 DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
1241 /* Clear interrupt in gintsts */
1243 gintsts.b.usbsuspend = 1;
1244 DWC_WRITE_REG32(&core_if->core_global_regs->
1245 gintsts, gintsts.d32);
1247 dwc_otg_save_global_regs(core_if);
1248 dwc_otg_save_dev_regs(core_if);
1250 /* Wait for 10 PHY clocks */
1253 /* Program GPIO register while entering to xHib */
1254 DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
1256 pcgcctl.b.enbl_extnd_hiber = 1;
1257 DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
1258 DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
1261 pcgcctl.b.extnd_hiber_pwrclmp = 1;
1262 DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
1265 pcgcctl.b.extnd_hiber_switch = 1;
1266 core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
1267 core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
1268 DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
1270 DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
1275 if ((core_if->otg_ver == 1) && (core_if->core_params->otg_cap == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)) {
1276 gotgctl_data_t gotgctl = {.d32 = 0 };
1277 gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
1278 if (gotgctl.b.devhnpen && core_if->otg_ver == 1){
1279 gotgctl_data_t gotgctl = {.d32 = 0 };
1281 /**@todo Is the gotgctl.devhnpen cleared
1282 * by a USB Reset? */
1283 gotgctl.b.devhnpen = 1;
1284 gotgctl.b.hnpreq = 1;
1285 DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl,
1290 if (core_if->op_state == A_PERIPHERAL) {
1291 DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
1292 /* Clear the a_peripheral flag, back to a_host. */
1293 DWC_SPINUNLOCK(core_if->lock);
1294 cil_pcd_stop(core_if);
1295 cil_hcd_start(core_if);
1296 DWC_SPINLOCK(core_if->lock);
1297 core_if->op_state = A_HOST;
1301 /* Change to L2(suspend) state */
1302 core_if->lx_state = DWC_OTG_L2;
1304 /* Clear interrupt */
1306 gintsts.b.usbsuspend = 1;
1307 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
1312 static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
1314 gpwrdn_data_t gpwrdn = {.d32 = 0 };
1315 pcgcctl_data_t pcgcctl = {.d32 = 0 };
1316 gahbcfg_data_t gahbcfg = {.d32 = 0 };
1320 /* Program GPIO register while entering to xHib */
1321 DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
1323 pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
1324 pcgcctl.b.extnd_hiber_pwrclmp = 0;
1325 DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
1328 gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
1329 gpwrdn.b.restore = 1;
1330 DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
1333 restore_lpm_i2c_regs(core_if);
1335 pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
1336 pcgcctl.b.max_xcvrselect = 1;
1337 pcgcctl.b.ess_reg_restored = 0;
1338 pcgcctl.b.extnd_hiber_switch = 0;
1339 pcgcctl.b.extnd_hiber_pwrclmp = 0;
1340 pcgcctl.b.enbl_extnd_hiber = 1;
1341 DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
1343 gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
1344 gahbcfg.b.glblintrmsk = 1;
1345 DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
1347 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
1348 DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
1350 DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
1351 core_if->gr_backup->gusbcfg_local);
1352 DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
1353 core_if->dr_backup->dcfg);
1356 pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
1357 pcgcctl.b.max_xcvrselect = 1;
1358 pcgcctl.d32 |= 0x608;
1359 DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
1363 pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
1364 pcgcctl.b.max_xcvrselect = 1;
1365 pcgcctl.b.ess_reg_restored = 1;
1366 pcgcctl.b.enbl_extnd_hiber = 1;
1367 pcgcctl.b.rstpdwnmodule = 1;
1368 pcgcctl.b.restoremode = 1;
1369 DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
1371 DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
1376 #ifdef CONFIG_USB_DWC_OTG_LPM
1378 * This function hadles LPM transaction received interrupt.
1380 static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
1382 glpmcfg_data_t lpmcfg;
1383 gintsts_data_t gintsts;
1385 if (!core_if->core_params->lpm_enable) {
1386 DWC_PRINTF("Unexpected LPM interrupt\n");
1389 lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
1390 DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
1392 if (dwc_otg_is_host_mode(core_if)) {
1393 cil_hcd_sleep(core_if);
1396 pcgcctl_data_t pcgcctl = {.d32 = 0 };
1398 lpmcfg.b.hird_thres |= (1 << 4);
1399 lpmcfg.b.en_utmi_sleep = 1;
1401 pcgcctl.b.enbl_sleep_gating = 1;
1402 DWC_MODIFY_REG32(core_if->pcgcctl,0,pcgcctl.d32);
1404 if(dwc_otg_get_param_besl_enable(core_if)) {
1405 lpmcfg.b.en_besl = 1;
1408 DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
1412 /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
1414 lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
1415 if (lpmcfg.b.prt_sleep_sts) {
1416 /* Save the current state */
1417 core_if->lx_state = DWC_OTG_L1;
1420 /* Clear interrupt */
1422 gintsts.b.lpmtranrcvd = 1;
1423 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
1426 #endif /* CONFIG_USB_DWC_OTG_LPM */
1429 * This function returns the Core Interrupt register.
1431 static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if)
1433 gahbcfg_data_t gahbcfg = {.d32 = 0 };
1434 gintsts_data_t gintsts;
1435 gintmsk_data_t gintmsk;
1436 gintmsk_data_t gintmsk_common = {.d32 = 0 };
1437 gintmsk_common.b.wkupintr = 1;
1438 gintmsk_common.b.sessreqintr = 1;
1439 gintmsk_common.b.conidstschng = 1;
1440 gintmsk_common.b.otgintr = 1;
1441 gintmsk_common.b.modemismatch = 1;
1442 gintmsk_common.b.disconnect = 1;
1443 gintmsk_common.b.usbsuspend = 1;
1444 #ifdef CONFIG_USB_DWC_OTG_LPM
1445 gintmsk_common.b.lpmtranrcvd = 1;
1447 gintmsk_common.b.restoredone = 1;
1448 /** @todo: The port interrupt occurs while in device
1449 * mode. Added code to CIL to clear the interrupt for now!
1451 gintmsk_common.b.portintr = 1;
1453 gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
1454 gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
1455 gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
1458 /* if any common interrupts set */
1459 if (gintsts.d32 & gintmsk_common.d32) {
1460 DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
1461 gintsts.d32, gintmsk.d32);
1464 if (gahbcfg.b.glblintrmsk)
1465 return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
1471 /* MACRO for clearing interupt bits in GPWRDN register */
1472 #define CLEAR_GPWRDN_INTR(__core_if,__intr) \
1474 gpwrdn_data_t gpwrdn = {.d32=0}; \
1475 gpwrdn.b.__intr = 1; \
1476 DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
1481 * Common interrupt handler.
1483 * The common interrupts are those that occur in both Host and Device mode.
1484 * This handler handles the following interrupts:
1485 * - Mode Mismatch Interrupt
1486 * - Disconnect Interrupt
1488 * - Connector ID Status Change Interrupt
1489 * - Session Request Interrupt.
1490 * - Resume / Remote Wakeup Detected Interrupt.
1491 * - LPM Transaction Received Interrupt
1492 * - ADP Transaction Received Interrupt
1495 int32_t dwc_otg_handle_common_intr(void *dev)
1498 gintsts_data_t gintsts;
1499 gpwrdn_data_t gpwrdn = {.d32 = 0 };
1500 dwc_otg_device_t *otg_dev = dev;
1501 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1502 gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
1504 if (dwc_otg_check_haps_status(core_if) == -1 ) {
1505 DWC_WARN("HAPS is disconnected");
1509 if (dwc_otg_is_device_mode(core_if))
1510 core_if->frame_num = dwc_otg_get_frame_number(core_if);
1513 DWC_SPINLOCK(core_if->lock);
1515 if (core_if->power_down == 3 && core_if->xhib == 1) {
1516 DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
1517 retval |= dwc_otg_handle_xhib_exit_intr(core_if);
1520 DWC_SPINUNLOCK(core_if->lock);
1525 if (core_if->hibernation_suspend <= 0) {
1526 gintsts.d32 = dwc_otg_read_common_intr(core_if);
1528 if (gintsts.b.modemismatch) {
1529 retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
1531 if (gintsts.b.otgintr) {
1532 retval |= dwc_otg_handle_otg_intr(core_if);
1534 if (gintsts.b.conidstschng) {
1536 dwc_otg_handle_conn_id_status_change_intr(core_if);
1538 if (gintsts.b.disconnect) {
1539 retval |= dwc_otg_handle_disconnect_intr(core_if);
1541 if (gintsts.b.sessreqintr) {
1542 retval |= dwc_otg_handle_session_req_intr(core_if);
1544 if (gintsts.b.wkupintr) {
1545 retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
1547 if (gintsts.b.usbsuspend) {
1548 retval |= dwc_otg_handle_usb_suspend_intr(core_if);
1550 #ifdef CONFIG_USB_DWC_OTG_LPM
1551 if (gintsts.b.lpmtranrcvd) {
1552 retval |= dwc_otg_handle_lpm_intr(core_if);
1555 if (gintsts.b.restoredone) {
1557 if (core_if->power_down == 2)
1558 core_if->hibernation_suspend = -1;
1559 else if (core_if->power_down == 3 && core_if->xhib == 2) {
1560 gpwrdn_data_t gpwrdn = {.d32 = 0 };
1561 pcgcctl_data_t pcgcctl = {.d32 = 0 };
1562 dctl_data_t dctl = {.d32 = 0 };
1564 DWC_WRITE_REG32(&core_if->core_global_regs->
1565 gintsts, 0xFFFFFFFF);
1567 DWC_DEBUGPL(DBG_ANY,
1568 "RESTORE DONE generated\n");
1570 gpwrdn.b.restore = 1;
1571 DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
1574 pcgcctl.b.rstpdwnmodule = 1;
1575 DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
1577 DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
1578 DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
1579 DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
1582 dctl.b.pwronprgdone = 1;
1583 DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
1586 dwc_otg_restore_global_regs(core_if);
1587 dwc_otg_restore_dev_regs(core_if, 0);
1590 dctl.b.pwronprgdone = 1;
1591 DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
1595 pcgcctl.b.enbl_extnd_hiber = 1;
1596 DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
1598 /* The core will be in ON STATE */
1599 core_if->lx_state = DWC_OTG_L0;
1602 DWC_SPINUNLOCK(core_if->lock);
1603 if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
1604 core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
1606 DWC_SPINLOCK(core_if->lock);
1610 gintsts.b.restoredone = 1;
1611 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
1612 DWC_PRINTF(" --Restore done interrupt received-- \n");
1615 if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
1616 /* The port interrupt occurs while in device mode with HPRT0
1617 * Port Enable/Disable.
1620 gintsts.b.portintr = 1;
1621 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
1626 DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
1628 if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
1629 CLEAR_GPWRDN_INTR(core_if, disconn_det);
1630 if (gpwrdn.b.linestate == 0) {
1631 dwc_otg_handle_pwrdn_disconnect_intr(core_if);
1633 DWC_PRINTF("Disconnect detected while linestate is not 0\n");
1638 if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
1639 CLEAR_GPWRDN_INTR(core_if, lnstschng);
1640 /* remote wakeup from hibernation */
1641 if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
1642 dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
1644 DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
1648 if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
1649 CLEAR_GPWRDN_INTR(core_if, rst_det);
1650 if (gpwrdn.b.linestate == 0) {
1651 DWC_PRINTF("Reset detected\n");
1652 retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
1655 if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
1656 CLEAR_GPWRDN_INTR(core_if, srp_det);
1657 dwc_otg_handle_pwrdn_srp_intr(core_if);
1661 /* Handle ADP interrupt here */
1662 if (gpwrdn.b.adp_int) {
1663 DWC_PRINTF("ADP interrupt\n");
1664 CLEAR_GPWRDN_INTR(core_if, adp_int);
1665 dwc_otg_adp_handle_intr(core_if);
1668 if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
1669 DWC_PRINTF("STS CHNG interrupt asserted\n");
1670 CLEAR_GPWRDN_INTR(core_if, sts_chngint);
1671 dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
1676 DWC_SPINUNLOCK(core_if->lock);