From patchwork Fri Feb 23 13:46:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 10237803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E00760209 for ; Fri, 23 Feb 2018 13:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A5A828E38 for ; Fri, 23 Feb 2018 13:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ED4928FCF; Fri, 23 Feb 2018 13:47:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A727E28E38 for ; Fri, 23 Feb 2018 13:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=udRuhF3TwdGbLXPwefw1CHNknckDYpYm43fH39bKRiA=; b=ovLRvFltxtisa6 vglxW4g4pqQ1B1m0o7v4fXyt/wALEm4PZzRgyGKHwOsRApWcYPy1EE7N6XbRZQXKADuZhZJYbiiZh iidJXwYqsfTTXl/3M1Hn6usBzg1Viwd9MAdZKunJ13SpsA9eglBLUOBTv4t+P3VrSxch2cLVZKsw4 +kOgGa23Af/d7CHrArHjvcwqVliYhUOiXc4i18IrDtXGtO3an1OzmKCAWn0VlBqZyUQlocVpvFCk1 cimnipDQNAll13PE1RfwsdNfpLE+RaMximHUkg0xGh8/aTzr6ZL6SkRM4l3Ow1y6Gw/QeG4UoNY45 pFLdWyLwm+y2qP4AFGLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epDhF-0000Le-F5; Fri, 23 Feb 2018 13:47:33 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epDh1-00008N-CB for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2018 13:47:27 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w1NDhksA030084; Fri, 23 Feb 2018 14:46:56 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2g9bn31ygf-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 23 Feb 2018 14:46:56 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 983723A; Fri, 23 Feb 2018 13:46:52 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6F0784F7C; Fri, 23 Feb 2018 13:46:52 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.94) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Feb 2018 14:46:52 +0100 Received: from localhost (10.201.20.5) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Feb 2018 14:46:51 +0100 From: Amelie Delaunay To: Greg Kroah-Hartman , Rob Herring , Mark Rutland , Tony Prisk , Alan Stern , "Roger Quadros" , Felipe Balbi Subject: [PATCH v3] usb: host: ehci-platform: add support for optional external vbus supply Date: Fri, 23 Feb 2018 14:46:51 +0100 Message-ID: <1519393611-31367-1-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.201.20.5] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-02-23_04:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_054719_871602_4ADAC3AD X-CRM114-Status: GOOD ( 18.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Amelie Delaunay , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On some boards, especially when vbus supply requires large current, and the charge pump on the PHY isn't enough, an external vbus power switch may be used. Add support for optional external vbus supply per port in ehci-platform. Signed-off-by: Amelie Delaunay Reviewed-by: Roger Quadros --- Changes in v3: * Address Felipe Balbi comments: reduce indentation in ehci_platform_port_power. * Address Roger Quadros and Alan Stern comments: platforms can have one external vbus supply per port, so add support to get as many optional regulator as implemented ports on the host controller. Changes in v2: * Address Roger Quadros comments: move regulator_enable/disable from ehci_platform_power_on/off to ehci_platform_port_power. --- Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 + drivers/usb/host/ehci-platform.c | 52 +++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt index 3efde12..cd576db 100644 --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt @@ -19,6 +19,7 @@ Optional properties: - phys : phandle + phy specifier pair - phy-names : "usb" - resets : phandle + reset specifier pair + - portN_vbus-supply : phandle of regulator supplying vbus for port N Example (Sequoia 440EPx): ehci@e0000300 { diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c index b065a96..8e9f201 100644 --- a/drivers/usb/host/ehci-platform.c +++ b/drivers/usb/host/ehci-platform.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ struct ehci_platform_priv { struct reset_control *rsts; struct phy **phys; int num_phys; + struct regulator **vbus_supplies; bool reset_on_resume; }; @@ -56,7 +58,8 @@ static int ehci_platform_reset(struct usb_hcd *hcd) struct platform_device *pdev = to_platform_device(hcd->self.controller); struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev); struct ehci_hcd *ehci = hcd_to_ehci(hcd); - int retval; + struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); + int portnum, n_ports, retval; ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug; @@ -71,11 +74,57 @@ static int ehci_platform_reset(struct usb_hcd *hcd) if (retval) return retval; + n_ports = HCS_N_PORTS(ehci->hcs_params); + priv->vbus_supplies = devm_kcalloc(&pdev->dev, n_ports, + sizeof(struct regulator *), + GFP_KERNEL); + if (!priv->vbus_supplies) + return -ENOMEM; + + for (portnum = 0; portnum < n_ports; portnum++) { + struct regulator *vbus_supply; + char id[20]; + + sprintf(id, "port%d_vbus", portnum); + + vbus_supply = devm_regulator_get_optional(&pdev->dev, id); + if (IS_ERR(vbus_supply)) { + retval = PTR_ERR(vbus_supply); + if (retval == -ENODEV) + priv->vbus_supplies[portnum] = NULL; + else + return retval; + } else { + priv->vbus_supplies[portnum] = vbus_supply; + } + } + if (pdata->no_io_watchdog) ehci->need_io_watchdog = 0; return 0; } +static int ehci_platform_port_power(struct usb_hcd *hcd, int portnum, + bool enable) +{ + struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); + int ret; + + if (!priv->vbus_supplies[portnum]) + return 0; + + if (enable) + ret = regulator_enable(priv->vbus_supplies[portnum]); + else + ret = regulator_disable(priv->vbus_supplies[portnum]); + if (ret) + dev_err(hcd->self.controller, + "failed to %s vbus supply for port %d: %d\n", + enable ? "enable" : "disable", portnum, ret); + + return ret; +} + static int ehci_platform_power_on(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); @@ -134,6 +183,7 @@ static struct hc_driver __read_mostly ehci_platform_hc_driver; static const struct ehci_driver_overrides platform_overrides __initconst = { .reset = ehci_platform_reset, .extra_priv_size = sizeof(struct ehci_platform_priv), + .port_power = ehci_platform_port_power, }; static struct usb_ehci_pdata ehci_platform_defaults = {