From patchwork Tue Aug 28 07:03:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 1379401 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 77C4BDF283 for ; Tue, 28 Aug 2012 07:11:29 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T6Fty-0003k0-Um; Tue, 28 Aug 2012 07:07:55 +0000 Received: from ch1ehsobe001.messaging.microsoft.com ([216.32.181.181] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T6FsS-000335-HB for linux-arm-kernel@lists.infradead.org; Tue, 28 Aug 2012 07:06:21 +0000 Received: from mail133-ch1-R.bigfish.com (10.43.68.247) by CH1EHSOBE005.bigfish.com (10.43.70.55) with Microsoft SMTP Server id 14.1.225.23; Tue, 28 Aug 2012 07:06:19 +0000 Received: from mail133-ch1 (localhost [127.0.0.1]) by mail133-ch1-R.bigfish.com (Postfix) with ESMTP id 510DF200D1; Tue, 28 Aug 2012 07:06:19 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah1155h) Received: from mail133-ch1 (localhost.localdomain [127.0.0.1]) by mail133-ch1 (MessageSwitch) id 1346137577278898_10583; Tue, 28 Aug 2012 07:06:17 +0000 (UTC) Received: from CH1EHSMHS020.bigfish.com (snatpool3.int.messaging.microsoft.com [10.43.68.227]) by mail133-ch1.bigfish.com (Postfix) with ESMTP id 402BD3C0045; Tue, 28 Aug 2012 07:06:17 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS020.bigfish.com (10.43.70.20) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 28 Aug 2012 07:06:14 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.309.3; Tue, 28 Aug 2012 02:06:14 -0500 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q7S72ogL032560; Tue, 28 Aug 2012 00:06:02 -0700 From: Richard Zhao To: , Subject: [PATCH v2 07/11] USB: chipidea: add vbus detect for udc Date: Tue, 28 Aug 2012 15:03:13 +0800 Message-ID: <1346137397-32374-8-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1346137397-32374-1-git-send-email-richard.zhao@freescale.com> References: <1346137397-32374-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.181 listed in list.dnswl.org] 0.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, B20596@freescale.com, dong.aisheng@linaro.org, fabio.estevam@freescale.com, alexander.shishkin@linux.intel.com, B29397@freescale.com, balbi@ti.com, stern@rowland.harvard.edu, kernel@pengutronix.de, gregkh@linuxfoundation.org, richard.zhao@freescale.com, shawn.guo@linaro.org, mkl@pengutronix.de, linuxzsc@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Using vbus valid interrupt to detect vbus. Signed-off-by: Richard Zhao --- 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; }