This source file includes following definitions.
- dwc2_op_state_str
- dwc2_handle_usb_port_intr
- dwc2_handle_mode_mismatch_intr
- dwc2_handle_otg_intr
- dwc2_handle_conn_id_status_change_intr
- dwc2_handle_session_req_intr
- dwc2_wakeup_from_lpm_l1
- dwc2_handle_wakeup_detected_intr
- dwc2_handle_disconnect_intr
- dwc2_handle_usb_suspend_intr
- dwc2_handle_lpm_intr
- dwc2_read_common_intr
- dwc2_handle_gpwrdn_intr
- dwc2_handle_common_intr
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 #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>
47 #include <linux/io.h>
48 #include <linux/slab.h>
49 #include <linux/usb.h>
50
51 #include <linux/usb/hcd.h>
52 #include <linux/usb/ch11.h>
53
54 #include "core.h"
55 #include "hcd.h"
56
57 static const char *dwc2_op_state_str(struct dwc2_hsotg *hsotg)
58 {
59 switch (hsotg->op_state) {
60 case OTG_STATE_A_HOST:
61 return "a_host";
62 case OTG_STATE_A_SUSPEND:
63 return "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:
69 return "b_host";
70 default:
71 return "unknown";
72 }
73 }
74
75
76
77
78
79
80
81
82 static void dwc2_handle_usb_port_intr(struct dwc2_hsotg *hsotg)
83 {
84 u32 hprt0 = dwc2_readl(hsotg, HPRT0);
85
86 if (hprt0 & HPRT0_ENACHG) {
87 hprt0 &= ~HPRT0_ENA;
88 dwc2_writel(hsotg, hprt0, HPRT0);
89 }
90 }
91
92
93
94
95
96
97 static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg)
98 {
99
100 dwc2_writel(hsotg, GINTSTS_MODEMIS, GINTSTS);
101
102 dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n",
103 dwc2_is_host_mode(hsotg) ? "Host" : "Device");
104 }
105
106
107
108
109
110
111
112 static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg)
113 {
114 u32 gotgint;
115 u32 gotgctl;
116 u32 gintmsk;
117
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));
122
123 if (gotgint & GOTGINT_SES_END_DET) {
124 dev_dbg(hsotg->dev,
125 " ++OTG Interrupt: Session End Detected++ (%s)\n",
126 dwc2_op_state_str(hsotg));
127 gotgctl = dwc2_readl(hsotg, GOTGCTL);
128
129 if (dwc2_is_device_mode(hsotg))
130 dwc2_hsotg_disconnect(hsotg);
131
132 if (hsotg->op_state == OTG_STATE_B_HOST) {
133 hsotg->op_state = OTG_STATE_B_PERIPHERAL;
134 } else {
135
136
137
138
139 if (gotgctl & GOTGCTL_DEVHNPEN) {
140 dev_dbg(hsotg->dev, "Session End Detected\n");
141 dev_err(hsotg->dev,
142 "Device Not Connected/Responding!\n");
143 }
144
145
146
147
148
149
150 hsotg->lx_state = DWC2_L0;
151 }
152
153 gotgctl = dwc2_readl(hsotg, GOTGCTL);
154 gotgctl &= ~GOTGCTL_DEVHNPEN;
155 dwc2_writel(hsotg, gotgctl, GOTGCTL);
156 }
157
158 if (gotgint & GOTGINT_SES_REQ_SUC_STS_CHNG) {
159 dev_dbg(hsotg->dev,
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;
166 } else {
167
168 gotgctl = dwc2_readl(hsotg, GOTGCTL);
169 gotgctl &= ~GOTGCTL_SESREQ;
170 dwc2_writel(hsotg, gotgctl, GOTGCTL);
171 }
172 }
173 }
174
175 if (gotgint & GOTGINT_HST_NEG_SUC_STS_CHNG) {
176
177
178
179
180 gotgctl = dwc2_readl(hsotg, GOTGCTL);
181
182
183
184
185 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a)
186 udelay(100);
187 if (gotgctl & GOTGCTL_HSTNEGSCS) {
188 if (dwc2_is_host_mode(hsotg)) {
189 hsotg->op_state = OTG_STATE_B_HOST;
190
191
192
193
194
195
196
197
198
199
200 gintmsk = dwc2_readl(hsotg, GINTMSK);
201 gintmsk &= ~GINTSTS_SOF;
202 dwc2_writel(hsotg, gintmsk, GINTMSK);
203
204
205
206
207
208 spin_unlock(&hsotg->lock);
209
210
211 dwc2_hcd_start(hsotg);
212 spin_lock(&hsotg->lock);
213 hsotg->op_state = OTG_STATE_B_HOST;
214 }
215 } else {
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");
220 dev_err(hsotg->dev,
221 "Device Not Connected/Responding\n");
222 }
223 }
224
225 if (gotgint & GOTGINT_HST_NEG_DET) {
226
227
228
229
230
231
232 dev_dbg(hsotg->dev,
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",
237 hsotg->op_state);
238 spin_unlock(&hsotg->lock);
239 dwc2_hcd_disconnect(hsotg, false);
240 spin_lock(&hsotg->lock);
241 hsotg->op_state = OTG_STATE_A_PERIPHERAL;
242 } else {
243
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;
251 }
252 }
253
254 if (gotgint & GOTGINT_A_DEV_TOUT_CHG)
255 dev_dbg(hsotg->dev,
256 " ++OTG Interrupt: A-Device Timeout Change++\n");
257 if (gotgint & GOTGINT_DBNCE_DONE)
258 dev_dbg(hsotg->dev, " ++OTG Interrupt: Debounce Done++\n");
259
260
261 dwc2_writel(hsotg, gotgint, GOTGINT);
262 }
263
264
265
266
267
268
269
270
271
272
273
274 static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg)
275 {
276 u32 gintmsk;
277
278
279 dwc2_writel(hsotg, GINTSTS_CONIDSTSCHNG, GINTSTS);
280
281
282 gintmsk = dwc2_readl(hsotg, GINTMSK);
283 gintmsk &= ~GINTSTS_SOF;
284 dwc2_writel(hsotg, gintmsk, GINTMSK);
285
286 dev_dbg(hsotg->dev, " ++Connector ID Status Change Interrupt++ (%s)\n",
287 dwc2_is_host_mode(hsotg) ? "Host" : "Device");
288
289
290
291
292
293
294 if (hsotg->wq_otg) {
295 spin_unlock(&hsotg->lock);
296 queue_work(hsotg->wq_otg, &hsotg->wf_otg);
297 spin_lock(&hsotg->lock);
298 }
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312 static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
313 {
314 int ret;
315
316
317 dwc2_writel(hsotg, GINTSTS_SESSREQINT, GINTSTS);
318
319 dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n",
320 hsotg->lx_state);
321
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))
326 dev_err(hsotg->dev,
327 "exit power_down failed\n");
328 }
329
330
331
332
333
334 dwc2_hsotg_disconnect(hsotg);
335 }
336 }
337
338
339
340
341
342
343
344 static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg)
345 {
346 u32 glpmcfg;
347 u32 i = 0;
348
349 if (hsotg->lx_state != DWC2_L1) {
350 dev_err(hsotg->dev, "Core isn't in DWC2_L1 state\n");
351 return;
352 }
353
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);
360
361 do {
362 glpmcfg = dwc2_readl(hsotg, GLPMCFG);
363
364 if (!(glpmcfg & (GLPMCFG_COREL1RES_MASK |
365 GLPMCFG_L1RESUMEOK | GLPMCFG_SLPSTS)))
366 break;
367
368 udelay(1);
369 } while (++i < 200);
370
371 if (i == 200) {
372 dev_err(hsotg->dev, "Failed to exit L1 sleep state in 200us.\n");
373 return;
374 }
375 dwc2_gadget_init_lpm(hsotg);
376 } else {
377
378 dev_err(hsotg->dev, "Host side LPM is not supported.\n");
379 return;
380 }
381
382
383 hsotg->lx_state = DWC2_L0;
384
385
386 call_gadget(hsotg, resume);
387 }
388
389
390
391
392
393
394
395
396 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
397 {
398 int ret;
399
400
401 dwc2_writel(hsotg, GINTSTS_WKUPINT, GINTSTS);
402
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);
405
406 if (hsotg->lx_state == DWC2_L1) {
407 dwc2_wakeup_from_lpm_l1(hsotg);
408 return;
409 }
410
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);
416
417
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");
423
424 call_gadget(hsotg, resume);
425 }
426
427 hsotg->lx_state = DWC2_L0;
428 } else {
429 if (hsotg->params.power_down)
430 return;
431
432 if (hsotg->lx_state != DWC2_L1) {
433 u32 pcgcctl = dwc2_readl(hsotg, PCGCTL);
434
435
436 pcgcctl &= ~PCGCTL_STOPPCLK;
437 dwc2_writel(hsotg, pcgcctl, PCGCTL);
438
439
440
441
442
443
444
445
446
447 if (hsotg->reset_phy_on_wake)
448 dwc2_host_schedule_phy_reset(hsotg);
449
450 mod_timer(&hsotg->wkp_timer,
451 jiffies + msecs_to_jiffies(71));
452 } else {
453
454 hsotg->lx_state = DWC2_L0;
455 }
456 }
457 }
458
459
460
461
462
463 static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg)
464 {
465 dwc2_writel(hsotg, GINTSTS_DISCONNINT, GINTSTS);
466
467 dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n",
468 dwc2_is_host_mode(hsotg) ? "Host" : "Device",
469 dwc2_op_state_str(hsotg));
470
471 if (hsotg->op_state == OTG_STATE_A_HOST)
472 dwc2_hcd_disconnect(hsotg, false);
473 }
474
475
476
477
478
479
480
481
482
483 static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
484 {
485 u32 dsts;
486 int ret;
487
488
489 dwc2_writel(hsotg, GINTSTS_USBSUSP, GINTSTS);
490
491 dev_dbg(hsotg->dev, "USB SUSPEND\n");
492
493 if (dwc2_is_device_mode(hsotg)) {
494
495
496
497
498 dsts = dwc2_readl(hsotg, DSTS);
499 dev_dbg(hsotg->dev, "%s: DSTS=0x%0x\n", __func__, dsts);
500 dev_dbg(hsotg->dev,
501 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d HWCFG4.Hibernation=%d\n",
502 !!(dsts & DSTS_SUSPSTS),
503 hsotg->hw_params.power_optimized,
504 hsotg->hw_params.hibernation);
505
506
507 if (!dwc2_is_device_connected(hsotg)) {
508 dev_dbg(hsotg->dev,
509 "ignore suspend request before enumeration\n");
510 return;
511 }
512 if (dsts & DSTS_SUSPSTS) {
513 if (hsotg->hw_params.power_optimized) {
514 ret = dwc2_enter_partial_power_down(hsotg);
515 if (ret) {
516 if (ret != -ENOTSUPP)
517 dev_err(hsotg->dev,
518 "%s: enter partial_power_down failed\n",
519 __func__);
520 goto skip_power_saving;
521 }
522
523 udelay(100);
524
525
526 if (!IS_ERR_OR_NULL(hsotg->uphy))
527 usb_phy_set_suspend(hsotg->uphy, true);
528 }
529
530 if (hsotg->hw_params.hibernation) {
531 ret = dwc2_enter_hibernation(hsotg, 0);
532 if (ret && ret != -ENOTSUPP)
533 dev_err(hsotg->dev,
534 "%s: enter hibernation failed\n",
535 __func__);
536 }
537 skip_power_saving:
538
539
540
541
542 hsotg->lx_state = DWC2_L2;
543
544
545 call_gadget(hsotg, suspend);
546 }
547 } else {
548 if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
549 dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
550
551
552 hsotg->lx_state = DWC2_L2;
553
554 spin_unlock(&hsotg->lock);
555 dwc2_hcd_start(hsotg);
556 spin_lock(&hsotg->lock);
557 hsotg->op_state = OTG_STATE_A_HOST;
558 }
559 }
560 }
561
562
563
564
565
566
567
568 static void dwc2_handle_lpm_intr(struct dwc2_hsotg *hsotg)
569 {
570 u32 glpmcfg;
571 u32 pcgcctl;
572 u32 hird;
573 u32 hird_thres;
574 u32 hird_thres_en;
575 u32 enslpm;
576
577
578 dwc2_writel(hsotg, GINTSTS_LPMTRANRCVD, GINTSTS);
579
580 glpmcfg = dwc2_readl(hsotg, GLPMCFG);
581
582 if (!(glpmcfg & GLPMCFG_LPMCAP)) {
583 dev_err(hsotg->dev, "Unexpected LPM interrupt\n");
584 return;
585 }
586
587 hird = (glpmcfg & GLPMCFG_HIRD_MASK) >> GLPMCFG_HIRD_SHIFT;
588 hird_thres = (glpmcfg & GLPMCFG_HIRD_THRES_MASK &
589 ~GLPMCFG_HIRD_THRES_EN) >> GLPMCFG_HIRD_THRES_SHIFT;
590 hird_thres_en = glpmcfg & GLPMCFG_HIRD_THRES_EN;
591 enslpm = glpmcfg & GLPMCFG_ENBLSLPM;
592
593 if (dwc2_is_device_mode(hsotg)) {
594 dev_dbg(hsotg->dev, "HIRD_THRES_EN = %d\n", hird_thres_en);
595
596 if (hird_thres_en && hird >= hird_thres) {
597 dev_dbg(hsotg->dev, "L1 with utmi_l1_suspend_n\n");
598 } else if (enslpm) {
599 dev_dbg(hsotg->dev, "L1 with utmi_sleep_n\n");
600 } else {
601 dev_dbg(hsotg->dev, "Entering Sleep with L1 Gating\n");
602
603 pcgcctl = dwc2_readl(hsotg, PCGCTL);
604 pcgcctl |= PCGCTL_ENBL_SLEEP_GATING;
605 dwc2_writel(hsotg, pcgcctl, PCGCTL);
606 }
607
608
609
610 udelay(10);
611
612 glpmcfg = dwc2_readl(hsotg, GLPMCFG);
613
614 if (glpmcfg & GLPMCFG_SLPSTS) {
615
616 hsotg->lx_state = DWC2_L1;
617 dev_dbg(hsotg->dev,
618 "Core is in L1 sleep glpmcfg=%08x\n", glpmcfg);
619
620
621 call_gadget(hsotg, suspend);
622 }
623 }
624 }
625
626 #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
627 GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \
628 GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \
629 GINTSTS_USBSUSP | GINTSTS_PRTINT | \
630 GINTSTS_LPMTRANRCVD)
631
632
633
634
635 static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
636 {
637 u32 gintsts;
638 u32 gintmsk;
639 u32 gahbcfg;
640 u32 gintmsk_common = GINTMSK_COMMON;
641
642 gintsts = dwc2_readl(hsotg, GINTSTS);
643 gintmsk = dwc2_readl(hsotg, GINTMSK);
644 gahbcfg = dwc2_readl(hsotg, GAHBCFG);
645
646
647 if (gintsts & gintmsk_common)
648 dev_dbg(hsotg->dev, "gintsts=%08x gintmsk=%08x\n",
649 gintsts, gintmsk);
650
651 if (gahbcfg & GAHBCFG_GLBL_INTR_EN)
652 return gintsts & gintmsk & gintmsk_common;
653 else
654 return 0;
655 }
656
657
658
659
660
661
662
663 static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg)
664 {
665 u32 gpwrdn;
666 int linestate;
667
668 gpwrdn = dwc2_readl(hsotg, GPWRDN);
669
670 dwc2_writel(hsotg, gpwrdn, GPWRDN);
671 linestate = (gpwrdn & GPWRDN_LINESTATE_MASK) >> GPWRDN_LINESTATE_SHIFT;
672 dev_dbg(hsotg->dev,
673 "%s: dwc2_handle_gpwrdwn_intr called gpwrdn= %08x\n", __func__,
674 gpwrdn);
675
676 if ((gpwrdn & GPWRDN_DISCONN_DET) &&
677 (gpwrdn & GPWRDN_DISCONN_DET_MSK) && !linestate) {
678 u32 gpwrdn_tmp;
679
680 dev_dbg(hsotg->dev, "%s: GPWRDN_DISCONN_DET\n", __func__);
681
682
683 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
684 gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH;
685 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
686 udelay(10);
687
688
689 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
690 gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN;
691 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
692 udelay(10);
693
694
695 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
696 gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP;
697 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
698 udelay(10);
699
700
701 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
702 gpwrdn_tmp |= GPWRDN_PWRDNRSTN;
703 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
704 udelay(10);
705
706
707 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
708 gpwrdn_tmp &= ~GPWRDN_PMUINTSEL;
709 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
710
711
712 gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
713 gpwrdn_tmp &= ~GPWRDN_PMUACTV;
714 dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
715
716 hsotg->hibernated = 0;
717
718 if (gpwrdn & GPWRDN_IDSTS) {
719 hsotg->op_state = OTG_STATE_B_PERIPHERAL;
720 dwc2_core_init(hsotg, false);
721 dwc2_enable_global_interrupts(hsotg);
722 dwc2_hsotg_core_init_disconnected(hsotg, false);
723 dwc2_hsotg_core_connect(hsotg);
724 } else {
725 hsotg->op_state = OTG_STATE_A_HOST;
726
727
728 dwc2_core_init(hsotg, false);
729 dwc2_enable_global_interrupts(hsotg);
730 dwc2_hcd_start(hsotg);
731 }
732 }
733
734 if ((gpwrdn & GPWRDN_LNSTSCHG) &&
735 (gpwrdn & GPWRDN_LNSTSCHG_MSK) && linestate) {
736 dev_dbg(hsotg->dev, "%s: GPWRDN_LNSTSCHG\n", __func__);
737 if (hsotg->hw_params.hibernation &&
738 hsotg->hibernated) {
739 if (gpwrdn & GPWRDN_IDSTS) {
740 dwc2_exit_hibernation(hsotg, 0, 0, 0);
741 call_gadget(hsotg, resume);
742 } else {
743 dwc2_exit_hibernation(hsotg, 1, 0, 1);
744 }
745 }
746 }
747 if ((gpwrdn & GPWRDN_RST_DET) && (gpwrdn & GPWRDN_RST_DET_MSK)) {
748 dev_dbg(hsotg->dev, "%s: GPWRDN_RST_DET\n", __func__);
749 if (!linestate && (gpwrdn & GPWRDN_BSESSVLD))
750 dwc2_exit_hibernation(hsotg, 0, 1, 0);
751 }
752 if ((gpwrdn & GPWRDN_STS_CHGINT) &&
753 (gpwrdn & GPWRDN_STS_CHGINT_MSK) && linestate) {
754 dev_dbg(hsotg->dev, "%s: GPWRDN_STS_CHGINT\n", __func__);
755 if (hsotg->hw_params.hibernation &&
756 hsotg->hibernated) {
757 if (gpwrdn & GPWRDN_IDSTS) {
758 dwc2_exit_hibernation(hsotg, 0, 0, 0);
759 call_gadget(hsotg, resume);
760 } else {
761 dwc2_exit_hibernation(hsotg, 1, 0, 1);
762 }
763 }
764 }
765 }
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780 irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
781 {
782 struct dwc2_hsotg *hsotg = dev;
783 u32 gintsts;
784 irqreturn_t retval = IRQ_NONE;
785
786 spin_lock(&hsotg->lock);
787
788 if (!dwc2_is_controller_alive(hsotg)) {
789 dev_warn(hsotg->dev, "Controller is dead\n");
790 goto out;
791 }
792
793
794 if (dwc2_is_device_mode(hsotg))
795 hsotg->frame_number = (dwc2_readl(hsotg, DSTS)
796 & DSTS_SOFFN_MASK) >> DSTS_SOFFN_SHIFT;
797 else
798 hsotg->frame_number = (dwc2_readl(hsotg, HFNUM)
799 & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
800
801 gintsts = dwc2_read_common_intr(hsotg);
802 if (gintsts & ~GINTSTS_PRTINT)
803 retval = IRQ_HANDLED;
804
805
806 if (hsotg->hibernated) {
807 dwc2_handle_gpwrdn_intr(hsotg);
808 retval = IRQ_HANDLED;
809 goto out;
810 }
811
812 if (gintsts & GINTSTS_MODEMIS)
813 dwc2_handle_mode_mismatch_intr(hsotg);
814 if (gintsts & GINTSTS_OTGINT)
815 dwc2_handle_otg_intr(hsotg);
816 if (gintsts & GINTSTS_CONIDSTSCHNG)
817 dwc2_handle_conn_id_status_change_intr(hsotg);
818 if (gintsts & GINTSTS_DISCONNINT)
819 dwc2_handle_disconnect_intr(hsotg);
820 if (gintsts & GINTSTS_SESSREQINT)
821 dwc2_handle_session_req_intr(hsotg);
822 if (gintsts & GINTSTS_WKUPINT)
823 dwc2_handle_wakeup_detected_intr(hsotg);
824 if (gintsts & GINTSTS_USBSUSP)
825 dwc2_handle_usb_suspend_intr(hsotg);
826 if (gintsts & GINTSTS_LPMTRANRCVD)
827 dwc2_handle_lpm_intr(hsotg);
828
829 if (gintsts & GINTSTS_PRTINT) {
830
831
832
833
834 if (dwc2_is_device_mode(hsotg)) {
835 dev_dbg(hsotg->dev,
836 " --Port interrupt received in Device mode--\n");
837 dwc2_handle_usb_port_intr(hsotg);
838 retval = IRQ_HANDLED;
839 }
840 }
841
842 out:
843 spin_unlock(&hsotg->lock);
844 return retval;
845 }