]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.28/usb-chipidea-handle-extcon-events-properly.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.9.28 / usb-chipidea-handle-extcon-events-properly.patch
CommitLineData
b74db2ac
GKH
1From a89b94b53371bbfa582787c2fa3378000ea4263d Mon Sep 17 00:00:00 2001
2From: Stephen Boyd <stephen.boyd@linaro.org>
3Date: Wed, 28 Dec 2016 14:56:51 -0800
4Subject: usb: chipidea: Handle extcon events properly
5
6From: Stephen Boyd <stephen.boyd@linaro.org>
7
8commit a89b94b53371bbfa582787c2fa3378000ea4263d upstream.
9
10We're currently emulating the vbus and id interrupts in the OTGSC
11read API, but we also need to make sure that if we're handling
12the events with extcon that we don't enable the interrupts for
13those events in the hardware. Therefore, properly emulate this
14register if we're using extcon, but don't enable the interrupts.
15This allows me to get my cable connect/disconnect working
16properly without getting spurious interrupts on my device that
17uses an extcon for these two events.
18
19Acked-by: Peter Chen <peter.chen@nxp.com>
20Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21Cc: "Ivan T. Ivanov" <iivanov.xz@gmail.com>
22Fixes: 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
23Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
24Signed-off-by: Peter Chen <peter.chen@nxp.com>
25Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26
27---
28 drivers/usb/chipidea/otg.c | 46 ++++++++++++++++++++++++++++++++++++++-----
29 include/linux/usb/chipidea.h | 2 +
30 2 files changed, 43 insertions(+), 5 deletions(-)
31
32--- a/drivers/usb/chipidea/otg.c
33+++ b/drivers/usb/chipidea/otg.c
34@@ -44,12 +44,15 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u3
35 else
36 val &= ~OTGSC_BSVIS;
37
38- cable->changed = false;
39-
40 if (cable->state)
41 val |= OTGSC_BSV;
42 else
43 val &= ~OTGSC_BSV;
44+
45+ if (cable->enabled)
46+ val |= OTGSC_BSVIE;
47+ else
48+ val &= ~OTGSC_BSVIE;
49 }
50
51 cable = &ci->platdata->id_extcon;
52@@ -59,15 +62,18 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u3
53 else
54 val &= ~OTGSC_IDIS;
55
56- cable->changed = false;
57-
58 if (cable->state)
59 val |= OTGSC_ID;
60 else
61 val &= ~OTGSC_ID;
62+
63+ if (cable->enabled)
64+ val |= OTGSC_IDIE;
65+ else
66+ val &= ~OTGSC_IDIE;
67 }
68
69- return val;
70+ return val & mask;
71 }
72
73 /**
74@@ -77,6 +83,36 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u3
75 */
76 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
77 {
78+ struct ci_hdrc_cable *cable;
79+
80+ cable = &ci->platdata->vbus_extcon;
81+ if (!IS_ERR(cable->edev)) {
82+ if (data & mask & OTGSC_BSVIS)
83+ cable->changed = false;
84+
85+ /* Don't enable vbus interrupt if using external notifier */
86+ if (data & mask & OTGSC_BSVIE) {
87+ cable->enabled = true;
88+ data &= ~OTGSC_BSVIE;
89+ } else if (mask & OTGSC_BSVIE) {
90+ cable->enabled = false;
91+ }
92+ }
93+
94+ cable = &ci->platdata->id_extcon;
95+ if (!IS_ERR(cable->edev)) {
96+ if (data & mask & OTGSC_IDIS)
97+ cable->changed = false;
98+
99+ /* Don't enable id interrupt if using external notifier */
100+ if (data & mask & OTGSC_IDIE) {
101+ cable->enabled = true;
102+ data &= ~OTGSC_IDIE;
103+ } else if (mask & OTGSC_IDIE) {
104+ cable->enabled = false;
105+ }
106+ }
107+
108 hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
109 }
110
111--- a/include/linux/usb/chipidea.h
112+++ b/include/linux/usb/chipidea.h
113@@ -14,6 +14,7 @@ struct ci_hdrc;
114 * struct ci_hdrc_cable - structure for external connector cable state tracking
115 * @state: current state of the line
116 * @changed: set to true when extcon event happen
117+ * @enabled: set to true if we've enabled the vbus or id interrupt
118 * @edev: device which generate events
119 * @ci: driver state of the chipidea device
120 * @nb: hold event notification callback
121@@ -22,6 +23,7 @@ struct ci_hdrc;
122 struct ci_hdrc_cable {
123 bool state;
124 bool changed;
125+ bool enabled;
126 struct extcon_dev *edev;
127 struct ci_hdrc *ci;
128 struct notifier_block nb;