From patchwork Wed Mar 6 09:56:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 2224211 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 9C5BD3FCF6 for ; Wed, 6 Mar 2013 10:04:17 +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 1UDB8j-0005pr-Dn; Wed, 06 Mar 2013 10:00:03 +0000 Received: from co9ehsobe002.messaging.microsoft.com ([207.46.163.25] helo=co9outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UDB6C-0004py-I9 for linux-arm-kernel@lists.infradead.org; Wed, 06 Mar 2013 09:57:26 +0000 Received: from mail143-co9-R.bigfish.com (10.236.132.247) by CO9EHSOBE042.bigfish.com (10.236.130.105) with Microsoft SMTP Server id 14.1.225.23; Wed, 6 Mar 2013 09:57:20 +0000 Received: from mail143-co9 (localhost [127.0.0.1]) by mail143-co9-R.bigfish.com (Postfix) with ESMTP id 63ED51E0115; Wed, 6 Mar 2013 09:57:20 +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(zzzz1f42h1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1155h) Received: from mail143-co9 (localhost.localdomain [127.0.0.1]) by mail143-co9 (MessageSwitch) id 136256383761265_9916; Wed, 6 Mar 2013 09:57:17 +0000 (UTC) Received: from CO9EHSMHS022.bigfish.com (unknown [10.236.132.242]) by mail143-co9.bigfish.com (Postfix) with ESMTP id EF4B2400BC; Wed, 6 Mar 2013 09:57:16 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS022.bigfish.com (10.236.130.32) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 6 Mar 2013 09:57:14 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.328.11; Wed, 6 Mar 2013 09:57:12 +0000 Received: from localhost.localdomain (nchen-desktop.ap.freescale.net [10.192.242.40]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r269ufOF006808; Wed, 6 Mar 2013 02:57:09 -0700 From: Peter Chen To: Subject: [PATCH v11 6/9] usb: chipidea: add vbus regulator control Date: Wed, 6 Mar 2013 17:56:37 +0800 Message-ID: <1362563800-16673-7-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1362563800-16673-1-git-send-email-peter.chen@freescale.com> References: <1362563800-16673-1-git-send-email-peter.chen@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130306_045725_054149_51E82244 X-CRM114-Status: GOOD ( 17.92 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.46.163.25 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, m.grzeschik@pengutronix.de, gregkh@linuxfoundation.org, pkondeti@codeaurora.org, linux-usb@vger.kernel.org, balbi@ti.com, mkl@pengutronix.de, kernel@pengutronix.de, matt@genesi-usa.com, shawn.guo@linaro.org, festevam@gmail.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 For boards which have board level vbus control (eg, gpio), we need to operation vbus according to below rules: - For host, the vbus should always be on. - For otg, the vbus needs to be turned on/off when usb role switches. We put vbus operation to host as host is the only vbus user, When we are at host mode, the vbus is on, when we are not at host mode, vbus should be off. Signed-off-by: Peter Chen --- drivers/usb/chipidea/ci.h | 2 ++ drivers/usb/chipidea/core.c | 24 ++++++++---------------- drivers/usb/chipidea/host.c | 23 ++++++++++++++++++++++- include/linux/usb/chipidea.h | 1 + 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index a3777a1..8826cdb 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -133,6 +133,7 @@ struct hw_bank { * @id_event: indicates there is a id event, and handled at ci_otg_work * @b_sess_valid_event: indicates there is a vbus event, and handled * at ci_otg_work + * @reg_vbus: used to control internal vbus regulator */ struct ci13xxx { struct device *dev; @@ -172,6 +173,7 @@ struct ci13xxx { struct usb_otg otg; bool id_event; bool b_sess_valid_event; + struct regulator *reg_vbus; }; static inline struct ci_role_driver *ci_role(struct ci13xxx *ci) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index c563e17..e0ff335 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -364,17 +365,10 @@ static void ci_handle_id_switch(struct ci13xxx *ci) hw_device_reset(ci, USBMODE_CM_IDLE); /* 2. Turn on/off vbus according to coming role */ - if (role == CI_ROLE_GADGET) { - otg_set_vbus(&ci->otg, false); + if (role == CI_ROLE_GADGET) /* wait vbus lower than OTGSC_BSV */ hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0, CI_VBUS_STABLE_TIMEOUT); - } else if (role == CI_ROLE_HOST) { - otg_set_vbus(&ci->otg, true); - /* wait vbus higher than OTGSC_AVV */ - hw_wait_reg(ci, OP_OTGSC, OTGSC_AVV, OTGSC_AVV, - CI_VBUS_STABLE_TIMEOUT); - } /* 3. Begin the new role */ ci_role_start(ci, role); @@ -416,17 +410,14 @@ static void ci_delayed_work(struct work_struct *work) struct delayed_work *dwork = to_delayed_work(work); struct ci13xxx *ci = container_of(dwork, struct ci13xxx, dwork); + /* + * If it is gadget mode, the vbus operation should be done like below: + * 1. Enable vbus detect + * 2. If it has already connected to host, notify udc + */ if (ci->role == CI_ROLE_GADGET) { - /* - * if it is device mode: - * - Enable vbus detect - * - If it has already connected to host, notify udc - */ ci_enable_otg_interrupt(ci, OTGSC_BSVIE); ci_handle_vbus_change(ci); - } else if (ci->is_otg && (ci->role == CI_ROLE_HOST)) { - /* USB Device at the MicroB to A cable */ - otg_set_vbus(&ci->otg, true); } } @@ -603,6 +594,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci->dev = dev; ci->platdata = dev->platform_data; + ci->reg_vbus = ci->platdata->reg_vbus; if (ci->platdata->phy) ci->transceiver = ci->platdata->phy; else diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index ead3158..8efbd44 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -64,9 +65,19 @@ static int host_start(struct ci13xxx *ci) ehci->caps = ci->hw_bank.cap; ehci->has_hostpc = ci->hw_bank.lpm; + if (ci->reg_vbus) { + ret = regulator_enable(ci->reg_vbus); + if (ret) { + dev_err(ci->dev, + "Failed to enable vbus regulator, ret=%d\n", + ret); + goto put_hcd; + } + } + ret = usb_add_hcd(hcd, 0, 0); if (ret) - usb_put_hcd(hcd); + goto disable_reg; else ci->hcd = hcd; @@ -74,6 +85,14 @@ static int host_start(struct ci13xxx *ci) hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); return ret; + +disable_reg: + if (ci->reg_vbus) + regulator_disable(ci->reg_vbus); +put_hcd: + usb_put_hcd(hcd); + + return ret; } static void host_stop(struct ci13xxx *ci) @@ -82,6 +101,8 @@ static void host_stop(struct ci13xxx *ci) usb_remove_hcd(hcd); usb_put_hcd(hcd); + if (ci->reg_vbus) + regulator_disable(ci->reg_vbus); } int ci_hdrc_host_init(struct ci13xxx *ci) diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index d543e4a..1430403 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -23,6 +23,7 @@ struct ci13xxx_platform_data { #define CI13XXX_CONTROLLER_RESET_EVENT 0 #define CI13XXX_CONTROLLER_STOPPED_EVENT 1 void (*notify_event) (struct ci13xxx *ci, unsigned event); + struct regulator *reg_vbus; }; /* Default offset of capability registers */