Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1502647

[PATCH v5 05/23] usb: chipidea: Handle extcon events properly

From Stephen Boyd <stephen.boyd@linaro.org>
Newsgroups linux.kernel
Subject [PATCH v5 05/23] usb: chipidea: Handle extcon events properly
Date 2016-10-18 04:10 +0200
Message-ID <sts0N-3Pu-7@gated-at.bofh.it> (permalink)
References <strR7-3vV-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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: 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 drivers/usb/chipidea/otg.c   | 46 +++++++++++++++++++++++++++++++++++++++-----
 include/linux/usb/chipidea.h |  2 ++
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index a829607c3e4d..0cf149edddd8 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -44,12 +44,15 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_BSVIS;
 
-		cable->changed = false;
-
 		if (cable->state)
 			val |= OTGSC_BSV;
 		else
 			val &= ~OTGSC_BSV;
+
+		if (cable->enabled)
+			val |= OTGSC_BSVIE;
+		else
+			val &= ~OTGSC_BSVIE;
 	}
 
 	cable = &ci->platdata->id_extcon;
@@ -59,15 +62,18 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_IDIS;
 
-		cable->changed = false;
-
 		if (cable->state)
 			val |= OTGSC_ID;
 		else
 			val &= ~OTGSC_ID;
+
+		if (cable->enabled)
+			val |= OTGSC_IDIE;
+		else
+			val &= ~OTGSC_IDIE;
 	}
 
-	return val;
+	return val & mask;
 }
 
 /**
@@ -77,6 +83,36 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
  */
 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
 {
+	struct ci_hdrc_cable *cable;
+
+	cable = &ci->platdata->vbus_extcon;
+	if (!IS_ERR(cable->edev)) {
+		if (data & mask & OTGSC_BSVIS)
+			cable->changed = false;
+
+		/* Don't enable vbus interrupt if using external notifier */
+		if (data & mask & OTGSC_BSVIE) {
+			cable->enabled = true;
+			data &= ~OTGSC_BSVIE;
+		} else if (mask & OTGSC_BSVIE) {
+			cable->enabled = false;
+		}
+	}
+
+	cable = &ci->platdata->id_extcon;
+	if (!IS_ERR(cable->edev)) {
+		if (data & mask & OTGSC_IDIS)
+			cable->changed = false;
+
+		/* Don't enable id interrupt if using external notifier */
+		if (data & mask & OTGSC_IDIE) {
+			cable->enabled = true;
+			data &= ~OTGSC_IDIE;
+		} else if (mask & OTGSC_IDIE) {
+			cable->enabled = false;
+		}
+	}
+
 	hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
 }
 
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 5dd75fa47dd8..f9be467d6695 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -14,6 +14,7 @@ struct ci_hdrc;
  * struct ci_hdrc_cable - structure for external connector cable state tracking
  * @state: current state of the line
  * @changed: set to true when extcon event happen
+ * @enabled: set to true if we've enabled the vbus or id interrupt
  * @edev: device which generate events
  * @ci: driver state of the chipidea device
  * @nb: hold event notification callback
@@ -22,6 +23,7 @@ struct ci_hdrc;
 struct ci_hdrc_cable {
 	bool				state;
 	bool				changed;
+	bool				enabled;
 	struct extcon_dev		*edev;
 	struct ci_hdrc			*ci;
 	struct notifier_block		nb;
-- 
2.10.0.297.gf6727b0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5 00/23] Support qcom's HSIC USB and rewrite USB2 HS support Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 12/23] usb: chipidea: msm: Mark device as runtime pm active Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 05/23] usb: chipidea: Handle extcon events properly Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 04/23] usb: chipidea: Only read/write OTGSC from one place Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 10/23] usb: chipidea: Consolidate extcon notifiers Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 15/23] usb: chipidea: msm: Add proper clk and reset support Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 14/23] usb: chipidea: msm: Use hw_write_id_reg() instead of writel Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 13/23] usb: chipidea: msm: Rely on core to override AHBBURST Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 03/23] usb: ulpi: Support device discovery via DT Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
    Re: [PATCH v5 03/23] usb: ulpi: Support device discovery via DT Rob Herring <robh@kernel.org> - 2016-10-18 18:50 +0200
  [PATCH v5 16/23] usb: chipidea: msm: Mux over secondary phy at the right time Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
  [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable path Stephen Boyd <stephen.boyd@linaro.org> - 2016-10-18 04:10 +0200
    Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable  path Peter Chen <hzpeterchen@gmail.com> - 2016-10-19 03:20 +0200
      Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable  path Peter Chen <hzpeterchen@gmail.com> - 2016-10-19 16:40 +0200
        Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable  path Peter Chen <hzpeterchen@gmail.com> - 2016-10-20 12:20 +0200
          Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable  path Peter Chen <hzpeterchen@gmail.com> - 2016-10-21 04:20 +0200
  Re: [PATCH v5 00/23] Support qcom's HSIC USB and rewrite USB2 HS  support Peter Chen <hzpeterchen@gmail.com> - 2016-10-18 11:40 +0200

csiph-web