aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc/cil_intr.c
blob: a42b0e6b91fd0f637fe03c767b83bc005f01f0be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/*
 * DesignWare HS OTG controller driver
 * Copyright (C) 2006 Synopsys, Inc.
 * Portions Copyright (C) 2010 Applied Micro Circuits Corporation.
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License version 2 for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/licenses
 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Suite 500, Boston, MA 02110-1335 USA.
 *
 * Based on Synopsys driver version 2.60a
 * Modified by Mark Miesfeld <mmiesfeld@apm.com>
 * Modified by Stefan Roese <sr@denx.de>, DENX Software Engineering
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL SYNOPSYS, INC. BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
 * (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*
 * The Core Interface Layer provides basic services for accessing and
 * managing the DWC_otg hardware. These services are used by both the
 * Host Controller Driver and the Peripheral Controller Driver.
 *
 * This file contains the Common Interrupt handlers.
 */
#include <linux/delay.h>

#include "cil.h"

/**
 *  This function will log a debug message
 */
static int dwc_otg_handle_mode_mismatch_intr(struct core_if *core_if)
{
	u32 gintsts = 0;
	ulong global_regs = core_if->core_global_regs;

	pr_warning("Mode Mismatch Interrupt: currently in %s mode\n",
		   dwc_otg_mode(core_if) ? "Host" : "Device");

	/* Clear interrupt */
	gintsts |= DWC_INTSTS_MODE_MISMTC;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);

	return 1;
}

/**
 *  Start the HCD.  Helper function for using the HCD callbacks.
 */
static inline void hcd_start(struct core_if *core_if)
{
	if (core_if->hcd_cb && core_if->hcd_cb->start)
		core_if->hcd_cb->start(core_if->hcd_cb->p);
}

/**
 *  Stop the HCD.  Helper function for using the HCD callbacks.
 */
static inline void hcd_stop(struct core_if *core_if)
{
	if (core_if->hcd_cb && core_if->hcd_cb->stop)
		core_if->hcd_cb->stop(core_if->hcd_cb->p);
}

/**
 *  Disconnect the HCD.  Helper function for using the HCD callbacks.
 */
static inline void hcd_disconnect(struct core_if *core_if)
{
	if (core_if->hcd_cb && core_if->hcd_cb->disconnect)
		core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
}

/**
 *  Inform the HCD the a New Session has begun.  Helper function for using the
 *  HCD callbacks.
 */
static inline void hcd_session_start(struct core_if *core_if)
{
	if (core_if->hcd_cb && core_if->hcd_cb->session_start)
		core_if->hcd_cb->session_start(core_if->hcd_cb->p);
}

/**
 *  Start the PCD.  Helper function for using the PCD callbacks.
 */
static inline void pcd_start(struct core_if *core_if)
{
	if (core_if->pcd_cb && core_if->pcd_cb->start) {
		struct dwc_pcd *pcd;

		pcd = (struct dwc_pcd *)core_if->pcd_cb->p;
		spin_lock(&pcd->lock);
		core_if->pcd_cb->start(core_if->pcd_cb->p);
		spin_unlock(&pcd->lock);
	}
}

/**
 *  Stop the PCD.  Helper function for using the PCD callbacks.
 */
static inline void pcd_stop(struct core_if *core_if)
{
	if (core_if->pcd_cb && core_if->pcd_cb->stop) {
		struct dwc_pcd *pcd;

		pcd = (struct dwc_pcd *)core_if->pcd_cb->p;
		spin_lock(&pcd->lock);
		core_if->pcd_cb->stop(core_if->pcd_cb->p);
		spin_unlock(&pcd->lock);
	}
}

/**
 *  Suspend the PCD.  Helper function for using the PCD callbacks.
 */
static inline void pcd_suspend(struct core_if *core_if)
{
	if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
		struct dwc_pcd *pcd;

		pcd = (struct dwc_pcd *)core_if->pcd_cb->p;
		spin_lock(&pcd->lock);
		core_if->pcd_cb->suspend(core_if->pcd_cb->p);
		spin_unlock(&pcd->lock);
	}
}

/**
 *  Resume the PCD.  Helper function for using the PCD callbacks.
 */
static inline void pcd_resume(struct core_if *core_if)
{
	if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
		struct dwc_pcd *pcd;

		pcd = (struct dwc_pcd *)core_if->pcd_cb->p;
		spin_lock(&pcd->lock);
		core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
		spin_unlock(&pcd->lock);
	}
}

/**
 * This function handles the OTG Interrupts. It reads the OTG
 * Interrupt Register (GOTGINT) to determine what interrupt has
 * occurred.
 */
static int dwc_otg_handle_otg_intr(struct core_if *core_if)
{
	ulong global_regs = core_if->core_global_regs;
	u32 gotgint;
	u32 gotgctl;
	u32 gintmsk;

	gotgint = dwc_reg_read(global_regs, DWC_GOTGINT);
	if (gotgint & DWC_GINT_SES_ENDDET) {
		gotgctl = dwc_reg_read(global_regs, DWC_GOTGCTL);
		if (core_if->xceiv->state == OTG_STATE_B_HOST) {
			pcd_start(core_if);
			core_if->xceiv->state = OTG_STATE_B_PERIPHERAL;
		} else {
			/*
			 * If not B_HOST and Device HNP still set. HNP did not
			 * succeed
			 */
			if (gotgctl & DWC_GCTL_DEV_HNP_ENA)
				pr_err("Device Not Connected / "
				       "Responding\n");
			/*
			 * If Session End Detected the B-Cable has been
			 * disconnected.  Reset PCD and Gadget driver to a
			 * clean state.
			 */
			pcd_stop(core_if);
		}
		gotgctl = 0;
		gotgctl |= DWC_GCTL_DEV_HNP_ENA;
		dwc_reg_modify(global_regs, DWC_GOTGCTL, gotgctl, 0);
	}
	if (gotgint & DWC_GINT_SES_REQSUC) {
		gotgctl = dwc_reg_read(global_regs, DWC_GOTGCTL);
		if (gotgctl & DWC_GCTL_SES_REQ_SUCCESS) {
			if (core_if->core_params->phy_type ==
			    DWC_PHY_TYPE_PARAM_FS &&
			    core_if->core_params->i2c_enable) {
				core_if->srp_success = 1;
			} else {
				pcd_resume(core_if);

				/* Clear Session Request */
				gotgctl = 0;
				gotgctl |= DWC_GCTL_SES_REQ;
				dwc_reg_modify(global_regs, DWC_GOTGCTL,
					     gotgctl, 0);
			}
		}
	}
	if (gotgint & DWC_GINT_HST_NEGSUC) {
		/*
		 * Print statements during the HNP interrupt handling can cause
		 * it to fail.
		 */
		gotgctl = dwc_reg_read(global_regs, DWC_GOTGCTL);
		if (gotgctl & DWC_GCTL_HOST_NEG_SUCCES) {
			if (dwc_otg_is_host_mode(core_if)) {
				core_if->xceiv->state = OTG_STATE_B_HOST;
				/*
				 * Need to disable SOF interrupt immediately.
				 * When switching from device to host, the PCD
				 * interrupt handler won't handle the
				 * interrupt if host mode is already set. The
				 * HCD interrupt handler won't get called if
				 * the HCD state is HALT. This means that the
				 * interrupt does not get handled and Linux
				 * complains loudly.
				 */
				gintmsk = 0;
				gintmsk |= DWC_INTMSK_STRT_OF_FRM;
				dwc_reg_modify(global_regs, DWC_GINTMSK,
					     gintmsk, 0);
				pcd_stop(core_if);
				/* Initialize the Core for Host mode. */
				hcd_start(core_if);
				core_if->xceiv->state = OTG_STATE_B_HOST;
			}
		} else {
			gotgctl = 0;
			gotgctl |= DWC_GCTL_HNP_REQ;
			gotgctl |= DWC_GCTL_DEV_HNP_ENA;
			dwc_reg_modify(global_regs, DWC_GOTGCTL, gotgctl, 0);

			pr_err("Device Not Connected / Responding\n");
		}
	}
	if (gotgint & DWC_GINT_HST_NEGDET) {
		/*
		 * The disconnect interrupt is set at the same time as
		 * Host Negotiation Detected.  During the mode
		 * switch all interrupts are cleared so the disconnect
		 * interrupt handler will not get executed.
		 */
		if (dwc_otg_is_device_mode(core_if)) {
			hcd_disconnect(core_if);
			pcd_start(core_if);
			core_if->xceiv->state = OTG_STATE_A_PERIPHERAL;
		} else {
			/*
			 * Need to disable SOF interrupt immediately. When
			 * switching from device to host, the PCD interrupt
			 * handler won't handle the interrupt if host mode is
			 * already set. The HCD interrupt handler won't get
			 * called if the HCD state is HALT. This means that
			 * the interrupt does not get handled and Linux
			 * complains loudly.
			 */
			gintmsk = 0;
			gintmsk |= DWC_INTMSK_STRT_OF_FRM;
			dwc_reg_modify(global_regs, DWC_GINTMSK, gintmsk, 0);
			pcd_stop(core_if);
			hcd_start(core_if);
			core_if->xceiv->state = OTG_STATE_A_HOST;
		}
	}
	if (gotgint & DWC_GINT_DEVTOUT)
		pr_info(" ++OTG Interrupt: A-Device Timeout " "Change++\n");
	if (gotgint & DWC_GINT_DEBDONE)
		pr_info(" ++OTG Interrupt: Debounce Done++\n");

	/* Clear GOTGINT */
	dwc_reg_write(global_regs, DWC_GOTGINT, gotgint);
	return 1;
}

/*
 * Wakeup Workqueue implementation
 */
static void port_otg_wqfunc(struct work_struct *work)
{
	struct core_if *core_if = container_of(work, struct core_if,
					       usb_port_otg);
	ulong global_regs = core_if->core_global_regs;
	u32 count = 0;
	u32 gotgctl;

	pr_info("%s\n", __func__);

	gotgctl = dwc_reg_read(global_regs, DWC_GOTGCTL);
	if (gotgctl & DWC_GCTL_CONN_ID_STATUS) {
		/*
		 * B-Device connector (device mode) wait for switch to device
		 * mode.
		 */
		while (!dwc_otg_is_device_mode(core_if) && ++count <= 10000) {
			pr_info("Waiting for Peripheral Mode, "
				"Mode=%s\n", dwc_otg_is_host_mode(core_if) ?
				"Host" : "Peripheral");
			msleep(100);
		}
		BUG_ON(count > 10000);
		core_if->xceiv->state = OTG_STATE_B_PERIPHERAL;
		dwc_otg_core_init(core_if);
		dwc_otg_enable_global_interrupts(core_if);
		pcd_start(core_if);
	} else {
		/*
		 * A-Device connector (host mode) wait for switch to host
		 * mode.
		 */
		while (!dwc_otg_is_host_mode(core_if) && ++count <= 10000) {
			pr_info("Waiting for Host Mode, Mode=%s\n",
				dwc_otg_is_host_mode(core_if) ?
				"Host" : "Peripheral");
			msleep(100);
		}
		BUG_ON(count > 10000);
		core_if->xceiv->state = OTG_STATE_A_HOST;
		dwc_otg_core_init(core_if);
		dwc_otg_enable_global_interrupts(core_if);
		hcd_start(core_if);
	}
}

/**
 * This function handles the Connector ID Status Change Interrupt.  It
 * reads the OTG Interrupt Register (GOTCTL) to determine whether this
 * is a Device to Host Mode transition or a Host Mode to Device
 * Transition.
 *
 * This only occurs when the cable is connected/removed from the PHY
 * connector.
 */
static int dwc_otg_handle_conn_id_status_change_intr(struct core_if *core_if)
{
	u32 gintsts = 0;
	u32 gintmsk = 0;
	ulong global_regs = core_if->core_global_regs;

	/*
	 * Need to disable SOF interrupt immediately. If switching from device
	 * to host, the PCD interrupt handler won't handle the interrupt if
	 * host mode is already set. The HCD interrupt handler won't get
	 * called if the HCD state is HALT. This means that the interrupt does
	 * not get handled and Linux complains loudly.
	 */
	gintmsk |= DWC_INTSTS_STRT_OF_FRM;
	dwc_reg_modify(global_regs, DWC_GINTMSK, gintmsk, 0);

	INIT_WORK(&core_if->usb_port_otg, port_otg_wqfunc);
	schedule_work(&core_if->usb_port_otg);

	/* Set flag and clear interrupt */
	gintsts |= DWC_INTSTS_CON_ID_STS_CHG;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
	return 1;
}

/**
 * This interrupt indicates that a device is initiating the Session
 * Request Protocol to request the host to turn on bus power so a new
 * session can begin. The handler responds by turning on bus power. If
 * the DWC_otg controller is in low power mode, the handler brings the
 * controller out of low power mode before turning on bus power.
 */
static int dwc_otg_handle_session_req_intr(struct core_if *core_if)
{
	u32 gintsts = 0;
	ulong global_regs = core_if->core_global_regs;

	if (!dwc_has_feature(core_if, DWC_HOST_ONLY)) {
		u32 hprt0;

		if (dwc_otg_is_device_mode(core_if)) {
			pr_info("SRP: Device mode\n");
		} else {
			pr_info("SRP: Host mode\n");

			/* Turn on the port power bit. */
			hprt0 = dwc_otg_read_hprt0(core_if);
			hprt0 = DWC_HPRT0_PRT_PWR_RW(hprt0, 1);
			dwc_reg_write(core_if->host_if->hprt0, 0, hprt0);

			/*
			 * Start the Connection timer.
			 * A message can be displayed,
			 * if connect does not occur within 10 seconds.
			 */
			hcd_session_start(core_if);
		}
	}
	/* Clear interrupt */
	gintsts |= DWC_INTSTS_NEW_SES_DET;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
	return 1;
}

/**
 * This interrupt indicates that the DWC_otg controller has detected a
 * resume or remote wakeup sequence. If the DWC_otg controller is in
 * low power mode, the handler must brings the controller out of low
 * power mode. The controller automatically begins resume
 * signaling. The handler schedules a time to stop resume signaling.
 */
static int dwc_otg_handle_wakeup_detected_intr(struct core_if *core_if)
{
	u32 gintsts = 0;
	struct device_if *dev_if = core_if->dev_if;
	ulong global_regs = core_if->core_global_regs;

	if (dwc_otg_is_device_mode(core_if)) {
		u32 dctl = 0;

		/* Clear the Remote Wakeup Signalling */
		dctl = DEC_DCTL_REMOTE_WAKEUP_SIG(dctl, 1);
		dwc_reg_modify(dev_if->dev_global_regs, DWC_DCTL, dctl, 0);

		if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup)
			core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
	} else {
		u32 pcgcctl = 0;

		/* Restart the Phy Clock */
		pcgcctl = DWC_PCGCCTL_STOP_CLK_SET(pcgcctl);
		dwc_reg_modify(core_if->pcgcctl, 0, pcgcctl, 0);
		schedule_delayed_work(&core_if->usb_port_wakeup, 10);
	}

	/* Clear interrupt */
	gintsts |= DWC_INTSTS_WKP;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
	return 1;
}

/**
 * This interrupt indicates that a device has been disconnected from
 * the root port.
 */
static int dwc_otg_handle_disconnect_intr(struct core_if *core_if)
{
	u32 gintsts = 0;
	ulong global_regs = core_if->core_global_regs;

	if (!dwc_has_feature(core_if, DWC_HOST_ONLY)) {
		if (core_if->xceiv->state == OTG_STATE_B_HOST) {
			hcd_disconnect(core_if);
			pcd_start(core_if);
			core_if->xceiv->state = OTG_STATE_B_PERIPHERAL;
		} else if (dwc_otg_is_device_mode(core_if)) {
			u32 gotgctl;

			gotgctl = dwc_reg_read(global_regs, DWC_GOTGCTL);

			/*
			 * If HNP is in process, do nothing.
			 * The OTG "Host Negotiation Detected"
			 * interrupt will do the mode switch.
			 * Otherwise, since we are in device mode,
			 * disconnect and stop the HCD,
			 * then start the PCD.
			 */
			if ((gotgctl) & DWC_GCTL_DEV_HNP_ENA) {
				hcd_disconnect(core_if);
				pcd_start(core_if);
				core_if->xceiv->state = OTG_STATE_B_PERIPHERAL;
			}
		} else if (core_if->xceiv->state == OTG_STATE_A_HOST) {
			/* A-Cable still connected but device disconnected. */
			hcd_disconnect(core_if);
		}
	}
	gintsts |= DWC_INTSTS_SES_DISCON_DET;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
	return 1;
}

/**
 * This interrupt indicates that SUSPEND state has been detected on
 * the USB.
 *
 * For HNP the USB Suspend interrupt signals the change from
 * "a_peripheral" to "a_host".
 *
 * When power management is enabled the core will be put in low power
 * mode.
 */
static int dwc_otg_handle_usb_suspend_intr(struct core_if *core_if)
{
	u32 dsts = 0;
	u32 gintsts = 0;
	ulong global_regs = core_if->core_global_regs;
	struct device_if *dev_if = core_if->dev_if;

	if (dwc_otg_is_device_mode(core_if)) {
		/*
		 * Check the Device status register to determine if the Suspend
		 * state is active.
		 */
		dsts = dwc_reg_read(dev_if->dev_global_regs, DWC_DSTS);
		/* PCD callback for suspend. */
		pcd_suspend(core_if);
	} else {
		if (core_if->xceiv->state == OTG_STATE_A_PERIPHERAL) {
			/* Clear the a_peripheral flag, back to a_host. */
			pcd_stop(core_if);
			hcd_start(core_if);
			core_if->xceiv->state = OTG_STATE_A_HOST;
		}
	}

	/* Clear interrupt */
	gintsts |= DWC_INTMSK_USB_SUSP;
	dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
	return 1;
}

/**
 * This function returns the Core Interrupt register.
 *
 * Although the Host Port interrupt (portintr) is documented as host mode
 * only, it appears to occur in device mode when Port Enable / Disable Changed
 * bit in HPRT0 is set. The code in dwc_otg_handle_common_intr checks if in
 * device mode and just clears the interrupt.
 */
static inline u32 dwc_otg_read_common_intr(struct core_if *core_if)
{
	u32 gintsts;
	u32 gintmsk;
	u32 gintmsk_common = 0;
	ulong global_regs = core_if->core_global_regs;

	gintmsk_common |= DWC_INTMSK_WKP;
	gintmsk_common |= DWC_INTMSK_NEW_SES_DET;
	gintmsk_common |= DWC_INTMSK_CON_ID_STS_CHG;
	gintmsk_common |= DWC_INTMSK_OTG;
	gintmsk_common |= DWC_INTMSK_MODE_MISMTC;
	gintmsk_common |= DWC_INTMSK_SES_DISCON_DET;
	gintmsk_common |= DWC_INTMSK_USB_SUSP;
	gintmsk_common |= DWC_INTMSK_HST_PORT;

	gintsts = dwc_reg_read(global_regs, DWC_GINTSTS);
	gintmsk = dwc_reg_read(global_regs, DWC_GINTMSK);

	return (gintsts & gintmsk) & gintmsk_common;
}

/**
 * Common interrupt handler.
 *
 * The common interrupts are those that occur in both Host and Device mode.
 * This handler handles the following interrupts:
 * - Mode Mismatch Interrupt
 * - Disconnect Interrupt
 * - OTG Interrupt
 * - Connector ID Status Change Interrupt
 * - Session Request Interrupt.
 * - Resume / Remote Wakeup Detected Interrupt.
 *
 * - Host Port Interrupt.  Although this interrupt is documented as only
 *   occurring in Host mode, it also occurs in Device mode when Port Enable /
 *   Disable Changed bit in HPRT0 is set. If it is seen here, while in Device
 *   mode, the interrupt is just cleared.
 *
 */
int dwc_otg_handle_common_intr(struct core_if *core_if)
{
	int retval = 0;
	u32 gintsts;
	ulong global_regs = core_if->core_global_regs;

	gintsts = dwc_otg_read_common_intr(core_if);

	if (gintsts & DWC_INTSTS_MODE_MISMTC)
		retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
	if (gintsts & DWC_INTSTS_OTG)
		retval |= dwc_otg_handle_otg_intr(core_if);
	if (gintsts & DWC_INTSTS_CON_ID_STS_CHG)
		retval |= dwc_otg_handle_conn_id_status_change_intr(core_if);
	if (gintsts & DWC_INTSTS_SES_DISCON_DET)
		retval |= dwc_otg_handle_disconnect_intr(core_if);
	if (gintsts & DWC_INTSTS_NEW_SES_DET)
		retval |= dwc_otg_handle_session_req_intr(core_if);
	if (gintsts & DWC_INTSTS_WKP)
		retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
	if (gintsts & DWC_INTMSK_USB_SUSP)
		retval |= dwc_otg_handle_usb_suspend_intr(core_if);

	if ((gintsts & DWC_INTSTS_HST_PORT) &&
			dwc_otg_is_device_mode(core_if)) {
		gintsts = 0;
		gintsts |= DWC_INTSTS_HST_PORT;
		dwc_reg_write(global_regs, DWC_GINTSTS, gintsts);
		retval |= 1;
		pr_info("RECEIVED PORTINT while in Device mode\n");
	}

	return retval;
}