1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * core_intr.c - DesignWare HS OTG Controller common interrupt handling
5 * Copyright (C) 2004-2013 Synopsys, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The names of the above-listed copyright holders may not be used
17 * to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * ALTERNATIVELY, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") as published by the Free Software
22 * Foundation; either version 2 of the License, or (at your option) any
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file contains the common interrupt handlers
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <linux/spinlock.h>
45 #include <linux/interrupt.h>
46 #include <linux/dma-mapping.h>
48 #include <linux/slab.h>
49 #include <linux/usb.h>
51 #include <linux/usb/hcd.h>
52 #include <linux/usb/ch11.h>
57 static const char *dwc2_op_state_str(struct dwc2_hsotg
*hsotg
)
59 switch (hsotg
->op_state
) {
60 case OTG_STATE_A_HOST
:
62 case OTG_STATE_A_SUSPEND
:
64 case OTG_STATE_A_PERIPHERAL
:
65 return "a_peripheral";
66 case OTG_STATE_B_PERIPHERAL
:
67 return "b_peripheral";
68 case OTG_STATE_B_HOST
:
76 * dwc2_handle_usb_port_intr - handles OTG PRTINT interrupts.
77 * When the PRTINT interrupt fires, there are certain status bits in the Host
78 * Port that needs to get cleared.
80 * @hsotg: Programming view of DWC_otg controller
82 static void dwc2_handle_usb_port_intr(struct dwc2_hsotg
*hsotg
)
84 u32 hprt0
= dwc2_readl(hsotg
, HPRT0
);
86 if (hprt0
& HPRT0_ENACHG
) {
88 dwc2_writel(hsotg
, hprt0
, HPRT0
);
93 * dwc2_handle_mode_mismatch_intr() - Logs a mode mismatch warning message
95 * @hsotg: Programming view of DWC_otg controller
97 static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg
*hsotg
)
100 dwc2_writel(hsotg
, GINTSTS_MODEMIS
, GINTSTS
);
102 dev_warn(hsotg
->dev
, "Mode Mismatch Interrupt: currently in %s mode\n",
103 dwc2_is_host_mode(hsotg
) ? "Host" : "Device");
107 * dwc2_handle_otg_intr() - Handles the OTG Interrupts. It reads the OTG
108 * Interrupt Register (GOTGINT) to determine what interrupt has occurred.
110 * @hsotg: Programming view of DWC_otg controller
112 static void dwc2_handle_otg_intr(struct dwc2_hsotg
*hsotg
)
118 gotgint
= dwc2_readl(hsotg
, GOTGINT
);
119 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
120 dev_dbg(hsotg
->dev
, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint
,
121 dwc2_op_state_str(hsotg
));
123 if (gotgint
& GOTGINT_SES_END_DET
) {
125 " ++OTG Interrupt: Session End Detected++ (%s)\n",
126 dwc2_op_state_str(hsotg
));
127 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
129 if (dwc2_is_device_mode(hsotg
))
130 dwc2_hsotg_disconnect(hsotg
);
132 if (hsotg
->op_state
== OTG_STATE_B_HOST
) {
133 hsotg
->op_state
= OTG_STATE_B_PERIPHERAL
;
136 * If not B_HOST and Device HNP still set, HNP did
139 if (gotgctl
& GOTGCTL_DEVHNPEN
) {
140 dev_dbg(hsotg
->dev
, "Session End Detected\n");
142 "Device Not Connected/Responding!\n");
146 * If Session End Detected the B-Cable has been
149 /* Reset to a clean state */
150 hsotg
->lx_state
= DWC2_L0
;
153 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
154 gotgctl
&= ~GOTGCTL_DEVHNPEN
;
155 dwc2_writel(hsotg
, gotgctl
, GOTGCTL
);
158 if (gotgint
& GOTGINT_SES_REQ_SUC_STS_CHNG
) {
160 " ++OTG Interrupt: Session Request Success Status Change++\n");
161 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
162 if (gotgctl
& GOTGCTL_SESREQSCS
) {
163 if (hsotg
->params
.phy_type
== DWC2_PHY_TYPE_PARAM_FS
&&
164 hsotg
->params
.i2c_enable
) {
165 hsotg
->srp_success
= 1;
167 /* Clear Session Request */
168 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
169 gotgctl
&= ~GOTGCTL_SESREQ
;
170 dwc2_writel(hsotg
, gotgctl
, GOTGCTL
);
175 if (gotgint
& GOTGINT_HST_NEG_SUC_STS_CHNG
) {
177 * Print statements during the HNP interrupt handling
178 * can cause it to fail
180 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
182 * WA for 3.00a- HW is not setting cur_mode, even sometimes
185 if (hsotg
->hw_params
.snpsid
>= DWC2_CORE_REV_3_00a
)
187 if (gotgctl
& GOTGCTL_HSTNEGSCS
) {
188 if (dwc2_is_host_mode(hsotg
)) {
189 hsotg
->op_state
= OTG_STATE_B_HOST
;
191 * Need to disable SOF interrupt immediately.
192 * When switching from device to host, the PCD
193 * interrupt handler won't handle the interrupt
194 * if host mode is already set. The HCD
195 * interrupt handler won't get called if the
196 * HCD state is HALT. This means that the
197 * interrupt does not get handled and Linux
200 gintmsk
= dwc2_readl(hsotg
, GINTMSK
);
201 gintmsk
&= ~GINTSTS_SOF
;
202 dwc2_writel(hsotg
, gintmsk
, GINTMSK
);
205 * Call callback function with spin lock
208 spin_unlock(&hsotg
->lock
);
210 /* Initialize the Core for Host mode */
211 dwc2_hcd_start(hsotg
);
212 spin_lock(&hsotg
->lock
);
213 hsotg
->op_state
= OTG_STATE_B_HOST
;
216 gotgctl
= dwc2_readl(hsotg
, GOTGCTL
);
217 gotgctl
&= ~(GOTGCTL_HNPREQ
| GOTGCTL_DEVHNPEN
);
218 dwc2_writel(hsotg
, gotgctl
, GOTGCTL
);
219 dev_dbg(hsotg
->dev
, "HNP Failed\n");
221 "Device Not Connected/Responding\n");
225 if (gotgint
& GOTGINT_HST_NEG_DET
) {
227 * The disconnect interrupt is set at the same time as
228 * Host Negotiation Detected. During the mode switch all
229 * interrupts are cleared so the disconnect interrupt
230 * handler will not get executed.
233 " ++OTG Interrupt: Host Negotiation Detected++ (%s)\n",
234 (dwc2_is_host_mode(hsotg
) ? "Host" : "Device"));
235 if (dwc2_is_device_mode(hsotg
)) {
236 dev_dbg(hsotg
->dev
, "a_suspend->a_peripheral (%d)\n",
238 spin_unlock(&hsotg
->lock
);
239 dwc2_hcd_disconnect(hsotg
, false);
240 spin_lock(&hsotg
->lock
);
241 hsotg
->op_state
= OTG_STATE_A_PERIPHERAL
;
243 /* Need to disable SOF interrupt immediately */
244 gintmsk
= dwc2_readl(hsotg
, GINTMSK
);
245 gintmsk
&= ~GINTSTS_SOF
;
246 dwc2_writel(hsotg
, gintmsk
, GINTMSK
);
247 spin_unlock(&hsotg
->lock
);
248 dwc2_hcd_start(hsotg
);
249 spin_lock(&hsotg
->lock
);
250 hsotg
->op_state
= OTG_STATE_A_HOST
;
254 if (gotgint
& GOTGINT_A_DEV_TOUT_CHG
)
256 " ++OTG Interrupt: A-Device Timeout Change++\n");
257 if (gotgint
& GOTGINT_DBNCE_DONE
)
258 dev_dbg(hsotg
->dev
, " ++OTG Interrupt: Debounce Done++\n");
261 dwc2_writel(hsotg
, gotgint
, GOTGINT
);
265 * dwc2_handle_conn_id_status_change_intr() - Handles the Connector ID Status
268 * @hsotg: Programming view of DWC_otg controller
270 * Reads the OTG Interrupt Register (GOTCTL) to determine whether this is a
271 * Device to Host Mode transition or a Host to Device Mode transition. This only
272 * occurs when the cable is connected/removed from the PHY connector.
274 static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg
*hsotg
)
278 /* Clear interrupt */
279 dwc2_writel(hsotg
, GINTSTS_CONIDSTSCHNG
, GINTSTS
);
281 /* Need to disable SOF interrupt immediately */
282 gintmsk
= dwc2_readl(hsotg
, GINTMSK
);
283 gintmsk
&= ~GINTSTS_SOF
;
284 dwc2_writel(hsotg
, gintmsk
, GINTMSK
);
286 dev_dbg(hsotg
->dev
, " ++Connector ID Status Change Interrupt++ (%s)\n",
287 dwc2_is_host_mode(hsotg
) ? "Host" : "Device");
290 * Need to schedule a work, as there are possible DELAY function calls.
291 * Release lock before scheduling workq as it holds spinlock during
295 spin_unlock(&hsotg
->lock
);
296 queue_work(hsotg
->wq_otg
, &hsotg
->wf_otg
);
297 spin_lock(&hsotg
->lock
);
302 * dwc2_handle_session_req_intr() - This interrupt indicates that a device is
303 * initiating the Session Request Protocol to request the host to turn on bus
304 * power so a new session can begin
306 * @hsotg: Programming view of DWC_otg controller
308 * This handler responds by turning on bus power. If the DWC_otg controller is
309 * in low power mode, this handler brings the controller out of low power mode
310 * before turning on bus power.
312 static void dwc2_handle_session_req_intr(struct dwc2_hsotg
*hsotg
)
316 /* Clear interrupt */
317 dwc2_writel(hsotg
, GINTSTS_SESSREQINT
, GINTSTS
);
319 dev_dbg(hsotg
->dev
, "Session request interrupt - lx_state=%d\n",
322 if (dwc2_is_device_mode(hsotg
)) {
323 if (hsotg
->lx_state
== DWC2_L2
) {
324 ret
= dwc2_exit_partial_power_down(hsotg
, true);
325 if (ret
&& (ret
!= -ENOTSUPP
))
327 "exit power_down failed\n");
331 * Report disconnect if there is any previous session
334 dwc2_hsotg_disconnect(hsotg
);
339 * dwc2_wakeup_from_lpm_l1 - Exit the device from LPM L1 state
341 * @hsotg: Programming view of DWC_otg controller
344 static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg
*hsotg
)
349 if (hsotg
->lx_state
!= DWC2_L1
) {
350 dev_err(hsotg
->dev
, "Core isn't in DWC2_L1 state\n");
354 glpmcfg
= dwc2_readl(hsotg
, GLPMCFG
);
355 if (dwc2_is_device_mode(hsotg
)) {
356 dev_dbg(hsotg
->dev
, "Exit from L1 state\n");
357 glpmcfg
&= ~GLPMCFG_ENBLSLPM
;
358 glpmcfg
&= ~GLPMCFG_HIRD_THRES_EN
;
359 dwc2_writel(hsotg
, glpmcfg
, GLPMCFG
);
362 glpmcfg
= dwc2_readl(hsotg
, GLPMCFG
);
364 if (!(glpmcfg
& (GLPMCFG_COREL1RES_MASK
|
365 GLPMCFG_L1RESUMEOK
| GLPMCFG_SLPSTS
)))
372 dev_err(hsotg
->dev
, "Failed to exit L1 sleep state in 200us.\n");
375 dwc2_gadget_init_lpm(hsotg
);
378 dev_err(hsotg
->dev
, "Host side LPM is not supported.\n");
382 /* Change to L0 state */
383 hsotg
->lx_state
= DWC2_L0
;
385 /* Inform gadget to exit from L1 */
386 call_gadget(hsotg
, resume
);
390 * This interrupt indicates that the DWC_otg controller has detected a
391 * resume or remote wakeup sequence. If the DWC_otg controller is in
392 * low power mode, the handler must brings the controller out of low
393 * power mode. The controller automatically begins resume signaling.
394 * The handler schedules a time to stop resume signaling.
396 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg
*hsotg
)
400 /* Clear interrupt */
401 dwc2_writel(hsotg
, GINTSTS_WKUPINT
, GINTSTS
);
403 dev_dbg(hsotg
->dev
, "++Resume or Remote Wakeup Detected Interrupt++\n");
404 dev_dbg(hsotg
->dev
, "%s lxstate = %d\n", __func__
, hsotg
->lx_state
);
406 if (hsotg
->lx_state
== DWC2_L1
) {
407 dwc2_wakeup_from_lpm_l1(hsotg
);
411 if (dwc2_is_device_mode(hsotg
)) {
412 dev_dbg(hsotg
->dev
, "DSTS=0x%0x\n",
413 dwc2_readl(hsotg
, DSTS
));
414 if (hsotg
->lx_state
== DWC2_L2
) {
415 u32 dctl
= dwc2_readl(hsotg
, DCTL
);
417 /* Clear Remote Wakeup Signaling */
418 dctl
&= ~DCTL_RMTWKUPSIG
;
419 dwc2_writel(hsotg
, dctl
, DCTL
);
420 ret
= dwc2_exit_partial_power_down(hsotg
, true);
421 if (ret
&& (ret
!= -ENOTSUPP
))
422 dev_err(hsotg
->dev
, "exit power_down failed\n");
424 call_gadget(hsotg
, resume
);
426 /* Change to L0 state */
427 hsotg
->lx_state
= DWC2_L0
;
429 if (hsotg
->params
.power_down
)
432 if (hsotg
->lx_state
!= DWC2_L1
) {
433 u32 pcgcctl
= dwc2_readl(hsotg
, PCGCTL
);
435 /* Restart the Phy Clock */
436 pcgcctl
&= ~PCGCTL_STOPPCLK
;
437 dwc2_writel(hsotg
, pcgcctl
, PCGCTL
);
438 mod_timer(&hsotg
->wkp_timer
,
439 jiffies
+ msecs_to_jiffies(71));
441 /* Change to L0 state */
442 hsotg
->lx_state
= DWC2_L0
;
448 * This interrupt indicates that a device has been disconnected from the
451 static void dwc2_handle_disconnect_intr(struct dwc2_hsotg
*hsotg
)
453 dwc2_writel(hsotg
, GINTSTS_DISCONNINT
, GINTSTS
);
455 dev_dbg(hsotg
->dev
, "++Disconnect Detected Interrupt++ (%s) %s\n",
456 dwc2_is_host_mode(hsotg
) ? "Host" : "Device",
457 dwc2_op_state_str(hsotg
));
459 if (hsotg
->op_state
== OTG_STATE_A_HOST
)
460 dwc2_hcd_disconnect(hsotg
, false);
464 * This interrupt indicates that SUSPEND state has been detected on the USB.
466 * For HNP the USB Suspend interrupt signals the change from "a_peripheral"
469 * When power management is enabled the core will be put in low power mode.
471 static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg
*hsotg
)
476 /* Clear interrupt */
477 dwc2_writel(hsotg
, GINTSTS_USBSUSP
, GINTSTS
);
479 dev_dbg(hsotg
->dev
, "USB SUSPEND\n");
481 if (dwc2_is_device_mode(hsotg
)) {
483 * Check the Device status register to determine if the Suspend
486 dsts
= dwc2_readl(hsotg
, DSTS
);
487 dev_dbg(hsotg
->dev
, "%s: DSTS=0x%0x\n", __func__
, dsts
);
489 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d HWCFG4.Hibernation=%d\n",
490 !!(dsts
& DSTS_SUSPSTS
),
491 hsotg
->hw_params
.power_optimized
,
492 hsotg
->hw_params
.hibernation
);
494 /* Ignore suspend request before enumeration */
495 if (!dwc2_is_device_connected(hsotg
)) {
497 "ignore suspend request before enumeration\n");
500 if (dsts
& DSTS_SUSPSTS
) {
501 if (hsotg
->hw_params
.power_optimized
) {
502 ret
= dwc2_enter_partial_power_down(hsotg
);
504 if (ret
!= -ENOTSUPP
)
506 "%s: enter partial_power_down failed\n",
508 goto skip_power_saving
;
513 /* Ask phy to be suspended */
514 if (!IS_ERR_OR_NULL(hsotg
->uphy
))
515 usb_phy_set_suspend(hsotg
->uphy
, true);
518 if (hsotg
->hw_params
.hibernation
) {
519 ret
= dwc2_enter_hibernation(hsotg
, 0);
520 if (ret
&& ret
!= -ENOTSUPP
)
522 "%s: enter hibernation failed\n",
527 * Change to L2 (suspend) state before releasing
530 hsotg
->lx_state
= DWC2_L2
;
532 /* Call gadget suspend callback */
533 call_gadget(hsotg
, suspend
);
536 if (hsotg
->op_state
== OTG_STATE_A_PERIPHERAL
) {
537 dev_dbg(hsotg
->dev
, "a_peripheral->a_host\n");
539 /* Change to L2 (suspend) state */
540 hsotg
->lx_state
= DWC2_L2
;
541 /* Clear the a_peripheral flag, back to a_host */
542 spin_unlock(&hsotg
->lock
);
543 dwc2_hcd_start(hsotg
);
544 spin_lock(&hsotg
->lock
);
545 hsotg
->op_state
= OTG_STATE_A_HOST
;
551 * dwc2_handle_lpm_intr - GINTSTS_LPMTRANRCVD Interrupt handler
553 * @hsotg: Programming view of DWC_otg controller
556 static void dwc2_handle_lpm_intr(struct dwc2_hsotg
*hsotg
)
565 /* Clear interrupt */
566 dwc2_writel(hsotg
, GINTSTS_LPMTRANRCVD
, GINTSTS
);
568 glpmcfg
= dwc2_readl(hsotg
, GLPMCFG
);
570 if (!(glpmcfg
& GLPMCFG_LPMCAP
)) {
571 dev_err(hsotg
->dev
, "Unexpected LPM interrupt\n");
575 hird
= (glpmcfg
& GLPMCFG_HIRD_MASK
) >> GLPMCFG_HIRD_SHIFT
;
576 hird_thres
= (glpmcfg
& GLPMCFG_HIRD_THRES_MASK
&
577 ~GLPMCFG_HIRD_THRES_EN
) >> GLPMCFG_HIRD_THRES_SHIFT
;
578 hird_thres_en
= glpmcfg
& GLPMCFG_HIRD_THRES_EN
;
579 enslpm
= glpmcfg
& GLPMCFG_ENBLSLPM
;
581 if (dwc2_is_device_mode(hsotg
)) {
582 dev_dbg(hsotg
->dev
, "HIRD_THRES_EN = %d\n", hird_thres_en
);
584 if (hird_thres_en
&& hird
>= hird_thres
) {
585 dev_dbg(hsotg
->dev
, "L1 with utmi_l1_suspend_n\n");
587 dev_dbg(hsotg
->dev
, "L1 with utmi_sleep_n\n");
589 dev_dbg(hsotg
->dev
, "Entering Sleep with L1 Gating\n");
591 pcgcctl
= dwc2_readl(hsotg
, PCGCTL
);
592 pcgcctl
|= PCGCTL_ENBL_SLEEP_GATING
;
593 dwc2_writel(hsotg
, pcgcctl
, PCGCTL
);
596 * Examine prt_sleep_sts after TL1TokenTetry period max (10 us)
600 glpmcfg
= dwc2_readl(hsotg
, GLPMCFG
);
602 if (glpmcfg
& GLPMCFG_SLPSTS
) {
603 /* Save the current state */
604 hsotg
->lx_state
= DWC2_L1
;
606 "Core is in L1 sleep glpmcfg=%08x\n", glpmcfg
);
608 /* Inform gadget that we are in L1 state */
609 call_gadget(hsotg
, suspend
);
614 #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
615 GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \
616 GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \
617 GINTSTS_USBSUSP | GINTSTS_PRTINT | \
621 * This function returns the Core Interrupt register
623 static u32
dwc2_read_common_intr(struct dwc2_hsotg
*hsotg
)
628 u32 gintmsk_common
= GINTMSK_COMMON
;
630 gintsts
= dwc2_readl(hsotg
, GINTSTS
);
631 gintmsk
= dwc2_readl(hsotg
, GINTMSK
);
632 gahbcfg
= dwc2_readl(hsotg
, GAHBCFG
);
634 /* If any common interrupts set */
635 if (gintsts
& gintmsk_common
)
636 dev_dbg(hsotg
->dev
, "gintsts=%08x gintmsk=%08x\n",
639 if (gahbcfg
& GAHBCFG_GLBL_INTR_EN
)
640 return gintsts
& gintmsk
& gintmsk_common
;
646 * GPWRDN interrupt handler.
648 * The GPWRDN interrupts are those that occur in both Host and
649 * Device mode while core is in hibernated state.
651 static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg
*hsotg
)
656 gpwrdn
= dwc2_readl(hsotg
, GPWRDN
);
657 /* clear all interrupt */
658 dwc2_writel(hsotg
, gpwrdn
, GPWRDN
);
659 linestate
= (gpwrdn
& GPWRDN_LINESTATE_MASK
) >> GPWRDN_LINESTATE_SHIFT
;
661 "%s: dwc2_handle_gpwrdwn_intr called gpwrdn= %08x\n", __func__
,
664 if ((gpwrdn
& GPWRDN_DISCONN_DET
) &&
665 (gpwrdn
& GPWRDN_DISCONN_DET_MSK
) && !linestate
) {
668 dev_dbg(hsotg
->dev
, "%s: GPWRDN_DISCONN_DET\n", __func__
);
670 /* Switch-on voltage to the core */
671 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
672 gpwrdn_tmp
&= ~GPWRDN_PWRDNSWTCH
;
673 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
677 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
678 gpwrdn_tmp
&= ~GPWRDN_PWRDNRSTN
;
679 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
682 /* Disable Power Down Clamp */
683 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
684 gpwrdn_tmp
&= ~GPWRDN_PWRDNCLMP
;
685 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
688 /* Deassert reset core */
689 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
690 gpwrdn_tmp
|= GPWRDN_PWRDNRSTN
;
691 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
694 /* Disable PMU interrupt */
695 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
696 gpwrdn_tmp
&= ~GPWRDN_PMUINTSEL
;
697 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
699 /* De-assert Wakeup Logic */
700 gpwrdn_tmp
= dwc2_readl(hsotg
, GPWRDN
);
701 gpwrdn_tmp
&= ~GPWRDN_PMUACTV
;
702 dwc2_writel(hsotg
, gpwrdn_tmp
, GPWRDN
);
704 hsotg
->hibernated
= 0;
706 if (gpwrdn
& GPWRDN_IDSTS
) {
707 hsotg
->op_state
= OTG_STATE_B_PERIPHERAL
;
708 dwc2_core_init(hsotg
, false);
709 dwc2_enable_global_interrupts(hsotg
);
710 dwc2_hsotg_core_init_disconnected(hsotg
, false);
711 dwc2_hsotg_core_connect(hsotg
);
713 hsotg
->op_state
= OTG_STATE_A_HOST
;
715 /* Initialize the Core for Host mode */
716 dwc2_core_init(hsotg
, false);
717 dwc2_enable_global_interrupts(hsotg
);
718 dwc2_hcd_start(hsotg
);
722 if ((gpwrdn
& GPWRDN_LNSTSCHG
) &&
723 (gpwrdn
& GPWRDN_LNSTSCHG_MSK
) && linestate
) {
724 dev_dbg(hsotg
->dev
, "%s: GPWRDN_LNSTSCHG\n", __func__
);
725 if (hsotg
->hw_params
.hibernation
&&
727 if (gpwrdn
& GPWRDN_IDSTS
) {
728 dwc2_exit_hibernation(hsotg
, 0, 0, 0);
729 call_gadget(hsotg
, resume
);
731 dwc2_exit_hibernation(hsotg
, 1, 0, 1);
735 if ((gpwrdn
& GPWRDN_RST_DET
) && (gpwrdn
& GPWRDN_RST_DET_MSK
)) {
736 dev_dbg(hsotg
->dev
, "%s: GPWRDN_RST_DET\n", __func__
);
737 if (!linestate
&& (gpwrdn
& GPWRDN_BSESSVLD
))
738 dwc2_exit_hibernation(hsotg
, 0, 1, 0);
740 if ((gpwrdn
& GPWRDN_STS_CHGINT
) &&
741 (gpwrdn
& GPWRDN_STS_CHGINT_MSK
) && linestate
) {
742 dev_dbg(hsotg
->dev
, "%s: GPWRDN_STS_CHGINT\n", __func__
);
743 if (hsotg
->hw_params
.hibernation
&&
745 if (gpwrdn
& GPWRDN_IDSTS
) {
746 dwc2_exit_hibernation(hsotg
, 0, 0, 0);
747 call_gadget(hsotg
, resume
);
749 dwc2_exit_hibernation(hsotg
, 1, 0, 1);
756 * Common interrupt handler
758 * The common interrupts are those that occur in both Host and Device mode.
759 * This handler handles the following interrupts:
760 * - Mode Mismatch Interrupt
762 * - Connector ID Status Change Interrupt
763 * - Disconnect Interrupt
764 * - Session Request Interrupt
765 * - Resume / Remote Wakeup Detected Interrupt
766 * - Suspend Interrupt
768 irqreturn_t
dwc2_handle_common_intr(int irq
, void *dev
)
770 struct dwc2_hsotg
*hsotg
= dev
;
772 irqreturn_t retval
= IRQ_NONE
;
774 spin_lock(&hsotg
->lock
);
776 if (!dwc2_is_controller_alive(hsotg
)) {
777 dev_warn(hsotg
->dev
, "Controller is dead\n");
781 /* Reading current frame number value in device or host modes. */
782 if (dwc2_is_device_mode(hsotg
))
783 hsotg
->frame_number
= (dwc2_readl(hsotg
, DSTS
)
784 & DSTS_SOFFN_MASK
) >> DSTS_SOFFN_SHIFT
;
786 hsotg
->frame_number
= (dwc2_readl(hsotg
, HFNUM
)
787 & HFNUM_FRNUM_MASK
) >> HFNUM_FRNUM_SHIFT
;
789 gintsts
= dwc2_read_common_intr(hsotg
);
790 if (gintsts
& ~GINTSTS_PRTINT
)
791 retval
= IRQ_HANDLED
;
793 /* In case of hibernated state gintsts must not work */
794 if (hsotg
->hibernated
) {
795 dwc2_handle_gpwrdn_intr(hsotg
);
796 retval
= IRQ_HANDLED
;
800 if (gintsts
& GINTSTS_MODEMIS
)
801 dwc2_handle_mode_mismatch_intr(hsotg
);
802 if (gintsts
& GINTSTS_OTGINT
)
803 dwc2_handle_otg_intr(hsotg
);
804 if (gintsts
& GINTSTS_CONIDSTSCHNG
)
805 dwc2_handle_conn_id_status_change_intr(hsotg
);
806 if (gintsts
& GINTSTS_DISCONNINT
)
807 dwc2_handle_disconnect_intr(hsotg
);
808 if (gintsts
& GINTSTS_SESSREQINT
)
809 dwc2_handle_session_req_intr(hsotg
);
810 if (gintsts
& GINTSTS_WKUPINT
)
811 dwc2_handle_wakeup_detected_intr(hsotg
);
812 if (gintsts
& GINTSTS_USBSUSP
)
813 dwc2_handle_usb_suspend_intr(hsotg
);
814 if (gintsts
& GINTSTS_LPMTRANRCVD
)
815 dwc2_handle_lpm_intr(hsotg
);
817 if (gintsts
& GINTSTS_PRTINT
) {
819 * The port interrupt occurs while in device mode with HPRT0
820 * Port Enable/Disable
822 if (dwc2_is_device_mode(hsotg
)) {
824 " --Port interrupt received in Device mode--\n");
825 dwc2_handle_usb_port_intr(hsotg
);
826 retval
= IRQ_HANDLED
;
831 spin_unlock(&hsotg
->lock
);