From patchwork Fri Mar 15 10:04:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 2275661 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 456D23FC8A for ; Fri, 15 Mar 2013 10:08:08 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGRVq-0003a9-Ui; Fri, 15 Mar 2013 10:05:22 +0000 Received: from am1ehsobe002.messaging.microsoft.com ([213.199.154.205] helo=am1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGRVl-0003Z2-Vj for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2013 10:05:19 +0000 Received: from mail33-am1-R.bigfish.com (10.3.201.239) by AM1EHSOBE001.bigfish.com (10.3.204.21) with Microsoft SMTP Server id 14.1.225.23; Fri, 15 Mar 2013 10:05:08 +0000 Received: from mail33-am1 (localhost [127.0.0.1]) by mail33-am1-R.bigfish.com (Postfix) with ESMTP id C54AC3402CE; Fri, 15 Mar 2013 10:05:05 +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: -2 X-BigFish: VS-2(zz98dI1432Izz1f42h1ee6h1de0h1202h1e76h1d1ah1d2ahzzz2dh2a8h668h839h944hd25hd2bhf0ah1220h1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh162dh1631h1758h18e1h1946h19b5h1ad9h1b0ah1155h) Received: from mail33-am1 (localhost.localdomain [127.0.0.1]) by mail33-am1 (MessageSwitch) id 1363341858805325_12320; Fri, 15 Mar 2013 10:04:18 +0000 (UTC) Received: from AM1EHSMHS004.bigfish.com (unknown [10.3.201.230]) by mail33-am1.bigfish.com (Postfix) with ESMTP id 7790D120083; Fri, 15 Mar 2013 10:04:18 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by AM1EHSMHS004.bigfish.com (10.3.207.104) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 15 Mar 2013 10:04:18 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.328.11; Fri, 15 Mar 2013 10:04:16 +0000 Received: from nchen-desktop (nchen-desktop.ap.freescale.net [10.192.242.40]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r2FA49no023690; Fri, 15 Mar 2013 03:04:10 -0700 Date: Fri, 15 Mar 2013 18:04:08 +0800 From: Peter Chen To: Felipe Balbi Subject: Re: [PATCH 14/14] usb: udc-core: add judgement logic for usb_gadget_connect Message-ID: <20130315100408.GG28361@nchen-desktop> References: <1363240242-25775-1-git-send-email-peter.chen@freescale.com> <1363240242-25775-15-git-send-email-peter.chen@freescale.com> <20130314090005.GB14443@arwen.pp.htv.fi> <20130314092438.GB26420@nchen-desktop> <20130314101904.GD32369@arwen.pp.htv.fi> <20130315060615.GB28361@nchen-desktop> <20130315075128.GF5074@arwen.pp.htv.fi> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130315075128.GF5074@arwen.pp.htv.fi> User-Agent: Mutt/1.5.20 (2009-06-14) X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130315_060518_251881_A2CBD5A9 X-CRM114-Status: GOOD ( 23.36 ) 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 [213.199.154.205 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: stigge@antcom.de, kgene.kim@samsung.com, eric.y.miao@gmail.com, alexander.shishkin@linux.intel.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, haojian.zhuang@gmail.com, chao.xie@marvell.com, ben-linux@fluff.org, yuxu@marvell.com, leoli@freescale.com, plagnioj@jcrosoft.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Fri, Mar 15, 2013 at 09:51:29AM +0200, Felipe Balbi wrote: > > that's all wrong and needs to be fixed. UDC-core has to be the central > point for all these details. We start with the easiest way (call connect > unconditionally after gadget driver is loaded) and optimize it as we go > (making sure that there is VBUS before connecting pullups); but we can't > bypass UDC-core and call usb_gadget_connect() directly from UDC driver. I have an idea that let the gadget driver call usb_gadget_connect/disconnect, and make a refcount for calling .pullup at usb_gadget_connect/disconnect. Below is an initial idea for it, I think it can also cover both udc and uvc case. drivers/usb/chipidea/udc.c | 6 ++---- drivers/usb/gadget/composite.c | 6 ++++++ include/linux/usb/gadget.h | 21 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) > > In that case, the pullup will not be called, it will check if gadget > > module is loaded. > > I don't see that in your patch. At each udc driver, it makes sure it, maybe we can move it to usb_gaget_connect /usb_gadget_disconnect or its abstract layer. > > > > I am not familiar with SRP, but I think vbus is pre-condition. > > hehe, google SRP. > > Nah, I'll save you the trouble. SRP is a mechanism for the USB > peripheral to ask the host to enable VBUS. This means that we can keep > the VBUS charge pump disabled, and thus save power, until peripheral > requests for a session. Thanks. > > -- > balbi diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 81184b9..4b6b2d8 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1386,17 +1386,15 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) pm_runtime_get_sync(&_gadget->dev); hw_device_reset(ci, USBMODE_CM_DC); hw_device_state(ci, ci->ep0out->qh.dma); - ci13xxx_pullup(_gadget, true); + ci->driver->connect(&ci->gadget); dev_dbg(ci->dev, "Connected to host\n"); } else { - if (ci->driver) - ci->driver->disconnect(&ci->gadget); + ci->driver->disconnect(&ci->gadget); hw_device_state(ci, 0); if (ci->platdata->notify_event) ci->platdata->notify_event(ci, CI13XXX_CONTROLLER_STOPPED_EVENT); _gadget_stop_activity(&ci->gadget); - ci13xxx_pullup(_gadget, false); pm_runtime_put_sync(&_gadget->dev); dev_dbg(ci->dev, "Disconnected from host\n"); } diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 7c821de..b7bf5ae 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1479,6 +1479,11 @@ done: return value; } +void composite_connect(struct usb_gadget *gadget) +{ + usb_gadget_connect(gadget); +} + void composite_disconnect(struct usb_gadget *gadget) { struct usb_composite_dev *cdev = get_gadget_data(gadget); @@ -1492,6 +1497,7 @@ void composite_disconnect(struct usb_gadget *gadget) reset_config(cdev); if (cdev->driver->disconnect) cdev->driver->disconnect(cdev); + usb_gadget_disconnect(gadget); spin_unlock_irqrestore(&cdev->lock, flags); } diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 7e373a2..7f7e6bf 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -536,6 +536,7 @@ struct usb_gadget { struct device dev; unsigned out_epnum; unsigned in_epnum; + int connection; }; static inline void set_gadget_data(struct usb_gadget *gadget, void *data) @@ -722,9 +723,16 @@ static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) */ static inline int usb_gadget_connect(struct usb_gadget *gadget) { + int ret = 0; if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup(gadget, 1); + + if (gadget->connection == 0) + ret = gadget->ops->pullup(gadget, 1); + if (!ret) + gadget->connection ++; + + return ret; } /** @@ -744,9 +752,18 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget) */ static inline int usb_gadget_disconnect(struct usb_gadget *gadget) { + int ret = 0; + if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup(gadget, 0); + + if (gadget->connection == 1) + ret = gadget->ops->pullup(gadget, 0); + + if (!ret) + gadget->connection --; + + return ret; } > >