All of lore.kernel.org
 help / color / mirror / Atom feed
From: richard.zhao@freescale.com (Richard Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 07/11] USB: chipidea: add vbus detect for udc
Date: Tue, 28 Aug 2012 15:03:13 +0800	[thread overview]
Message-ID: <1346137397-32374-8-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1346137397-32374-1-git-send-email-richard.zhao@freescale.com>

Using vbus valid interrupt to detect vbus.

Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
---
 drivers/usb/chipidea/ci.h  |    1 +
 drivers/usb/chipidea/udc.c |   39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index d738603..e25d126 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -139,6 +139,7 @@ struct ci13xxx {
 	enum ci_role			role;
 	bool				is_otg;
 	struct work_struct		work;
+	struct work_struct		vbus_work;
 	struct workqueue_struct		*wq;
 
 	struct dma_pool			*qh_pool;
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 9fb6394..2cb4498 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -308,6 +308,18 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *ci)
 	return reg;
 }
 
+static void hw_enable_vbus_intr(struct ci13xxx *ci)
+{
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIS, OTGSC_AVVIS);
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIE, OTGSC_AVVIE);
+	queue_work(ci->wq, &ci->vbus_work);
+}
+
+static void hw_disable_vbus_intr(struct ci13xxx *ci)
+{
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIE, 0);
+}
+
 /**
  * hw_test_and_clear_setup_guard: test & clear setup guard (execute without
  *                                interruption)
@@ -374,6 +386,16 @@ static int hw_usb_reset(struct ci13xxx *ci)
 	return 0;
 }
 
+static void vbus_work(struct work_struct *work)
+{
+	struct ci13xxx *ci = container_of(work, struct ci13xxx, vbus_work);
+
+	if (hw_read(ci, OP_OTGSC, OTGSC_AVV))
+		usb_gadget_vbus_connect(&ci->gadget);
+	else
+		usb_gadget_vbus_disconnect(&ci->gadget);
+}
+
 /******************************************************************************
  * UTIL block
  *****************************************************************************/
@@ -1376,6 +1398,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
 		if (is_active) {
 			pm_runtime_get_sync(&_gadget->dev);
 			hw_device_reset(ci, USBMODE_CM_DC);
+			hw_enable_vbus_intr(ci);
 			hw_device_state(ci, ci->ep0out->qh.dma);
 		} else {
 			hw_device_state(ci, 0);
@@ -1517,8 +1540,10 @@ static int ci13xxx_start(struct usb_gadget *gadget,
 	pm_runtime_get_sync(&ci->gadget.dev);
 	if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) {
 		if (ci->vbus_active) {
-			if (ci->platdata->flags & CI13XXX_REGS_SHARED)
+			if (ci->platdata->flags & CI13XXX_REGS_SHARED) {
 				hw_device_reset(ci, USBMODE_CM_DC);
+				hw_enable_vbus_intr(ci);
+			}
 		} else {
 			pm_runtime_put_sync(&ci->gadget.dev);
 			goto done;
@@ -1624,6 +1649,13 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
 	} else {
 		retval = IRQ_NONE;
 	}
+
+	intr = hw_read(ci, OP_OTGSC, ~0);
+	hw_write(ci, OP_OTGSC, ~0, intr);
+
+	if (intr & (OTGSC_AVVIE & OTGSC_AVVIS))
+		queue_work(ci->wq, &ci->vbus_work);
+
 	spin_unlock(&ci->lock);
 
 	return retval;
@@ -1699,6 +1731,7 @@ static int udc_start(struct ci13xxx *ci)
 		retval = hw_device_reset(ci, USBMODE_CM_DC);
 		if (retval)
 			goto put_transceiver;
+		hw_enable_vbus_intr(ci);
 	}
 
 	retval = device_register(&ci->gadget.dev);
@@ -1762,6 +1795,9 @@ static void udc_stop(struct ci13xxx *ci)
 	if (ci == NULL)
 		return;
 
+	hw_disable_vbus_intr(ci);
+	cancel_work_sync(&ci->vbus_work);
+
 	usb_del_gadget_udc(&ci->gadget);
 
 	for (i = 0; i < ci->hw_ep_max; i++) {
@@ -1806,6 +1842,7 @@ int ci_hdrc_gadget_init(struct ci13xxx *ci)
 	rdrv->irq	= udc_irq;
 	rdrv->name	= "gadget";
 	ci->roles[CI_ROLE_GADGET] = rdrv;
+	INIT_WORK(&ci->vbus_work, vbus_work);
 
 	return 0;
 }
-- 
1.7.9.5

  parent reply	other threads:[~2012-08-28  7:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-28  7:03 [PATCH v2 00/11] chipidea/imx: add otg support and some bug fix Richard Zhao
2012-08-28  7:03 ` [PATCH v2 01/11] USB: chipidea: imx: add pinctrl support Richard Zhao
2012-08-28  7:03 ` [PATCH v2 02/11] USB: chipidea: delay 2ms before read ID status at probe time Richard Zhao
2012-08-28  7:03 ` [PATCH v2 03/11] USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq handler Richard Zhao
2012-08-28  7:03 ` [PATCH v2 04/11] USB: chipidea: clear gadget struct at udc_start fail path Richard Zhao
2012-08-28  8:29   ` Alexander Shishkin
2012-08-28  9:09     ` Richard Zhao
2012-08-29  8:03       ` Alexander Shishkin
2012-08-29  8:22         ` Richard Zhao
2012-08-29  9:44           ` Alexander Shishkin
2012-08-29 10:37             ` Richard Zhao
2012-08-28  7:03 ` [PATCH v2 05/11] USB: chipidea: don't let probe fail if otg controller start one role failed Richard Zhao
2012-08-28  8:38   ` Alexander Shishkin
2012-08-28  9:27     ` Richard Zhao
2012-08-29  8:10       ` Alexander Shishkin
2012-08-29  8:33         ` Richard Zhao
2012-08-29  9:48           ` Alexander Shishkin
2012-08-29 10:46             ` Richard Zhao
2012-09-04 14:17               ` Richard Zhao
2012-09-11  7:23               ` Alexander Shishkin
2012-09-11  8:18                 ` Richard Zhao
2012-09-12 10:47                   ` Alexander Shishkin
2012-09-14  8:35                     ` Richard Zhao
2012-09-14 10:25                       ` Alexander Shishkin
2012-09-17  8:59                         ` Richard Zhao
2012-08-28  7:03 ` [PATCH v2 06/11] USB: mxs-phy: add basic otg support Richard Zhao
2012-09-11  9:05   ` Felipe Balbi
2012-09-12 10:39   ` Heikki Krogerus
2012-09-14  8:30     ` Richard Zhao
2012-09-14  8:56   ` Chen Peter-B29397
2012-09-14 10:53     ` Richard Zhao
2012-08-28  7:03 ` Richard Zhao [this message]
2012-08-28  7:03 ` [PATCH v2 08/11] USB: chipidea: convert to use devm_request_irq Richard Zhao
2012-08-28  7:03 ` [PATCH v2 09/11] USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG Richard Zhao
2012-08-28  7:03 ` [PATCH v2 10/11] USB: chipidea: add set_vbus_power support Richard Zhao
2012-09-19  1:25   ` Richard Zhao
2012-08-28  7:03 ` [PATCH v2 11/11] USB: chipidea: re-order irq handling to avoid unhandled irq Richard Zhao
2012-09-05 14:27 ` [PATCH v2 00/11] chipidea/imx: add otg support and some bug fix Marc Kleine-Budde
2012-09-05 15:01 ` Michael Grzeschik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346137397-32374-8-git-send-email-richard.zhao@freescale.com \
    --to=richard.zhao@freescale.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.