Skip to content

Commit 2428776

Browse files
bebarinogregkh
authored andcommitted
usb: chipidea: Handle extcon events properly
commit a89b94b53371bbfa582787c2fa3378000ea4263d upstream. We're currently emulating the vbus and id interrupts in the OTGSC read API, but we also need to make sure that if we're handling the events with extcon that we don't enable the interrupts for those events in the hardware. Therefore, properly emulate this register if we're using extcon, but don't enable the interrupts. This allows me to get my cable connect/disconnect working properly without getting spurious interrupts on my device that uses an extcon for these two events. Acked-by: Peter Chen <peter.chen@nxp.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Ivan T. Ivanov" <iivanov.xz@gmail.com> Fixes: 3ecb3e0 ("usb: chipidea: Use extcon framework for VBUS and ID detect") Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: Peter Chen <peter.chen@nxp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4cf7ba5 commit 2428776

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

drivers/usb/chipidea/otg.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
4444
else
4545
val &= ~OTGSC_BSVIS;
4646

47-
cable->changed = false;
48-
4947
if (cable->state)
5048
val |= OTGSC_BSV;
5149
else
5250
val &= ~OTGSC_BSV;
51+
52+
if (cable->enabled)
53+
val |= OTGSC_BSVIE;
54+
else
55+
val &= ~OTGSC_BSVIE;
5356
}
5457

5558
cable = &ci->platdata->id_extcon;
@@ -59,15 +62,18 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
5962
else
6063
val &= ~OTGSC_IDIS;
6164

62-
cable->changed = false;
63-
6465
if (cable->state)
6566
val |= OTGSC_ID;
6667
else
6768
val &= ~OTGSC_ID;
69+
70+
if (cable->enabled)
71+
val |= OTGSC_IDIE;
72+
else
73+
val &= ~OTGSC_IDIE;
6874
}
6975

70-
return val;
76+
return val & mask;
7177
}
7278

7379
/**
@@ -77,6 +83,36 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
7783
*/
7884
void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
7985
{
86+
struct ci_hdrc_cable *cable;
87+
88+
cable = &ci->platdata->vbus_extcon;
89+
if (!IS_ERR(cable->edev)) {
90+
if (data & mask & OTGSC_BSVIS)
91+
cable->changed = false;
92+
93+
/* Don't enable vbus interrupt if using external notifier */
94+
if (data & mask & OTGSC_BSVIE) {
95+
cable->enabled = true;
96+
data &= ~OTGSC_BSVIE;
97+
} else if (mask & OTGSC_BSVIE) {
98+
cable->enabled = false;
99+
}
100+
}
101+
102+
cable = &ci->platdata->id_extcon;
103+
if (!IS_ERR(cable->edev)) {
104+
if (data & mask & OTGSC_IDIS)
105+
cable->changed = false;
106+
107+
/* Don't enable id interrupt if using external notifier */
108+
if (data & mask & OTGSC_IDIE) {
109+
cable->enabled = true;
110+
data &= ~OTGSC_IDIE;
111+
} else if (mask & OTGSC_IDIE) {
112+
cable->enabled = false;
113+
}
114+
}
115+
80116
hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
81117
}
82118

include/linux/usb/chipidea.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct ci_hdrc;
1414
* struct ci_hdrc_cable - structure for external connector cable state tracking
1515
* @state: current state of the line
1616
* @changed: set to true when extcon event happen
17+
* @enabled: set to true if we've enabled the vbus or id interrupt
1718
* @edev: device which generate events
1819
* @ci: driver state of the chipidea device
1920
* @nb: hold event notification callback
@@ -22,6 +23,7 @@ struct ci_hdrc;
2223
struct ci_hdrc_cable {
2324
bool state;
2425
bool changed;
26+
bool enabled;
2527
struct extcon_dev *edev;
2628
struct ci_hdrc *ci;
2729
struct notifier_block nb;

0 commit comments

Comments
 (0)