From patchwork Thu Mar 1 09:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 10250681 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 A5C0460211 for ; Thu, 1 Mar 2018 09:54:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9159228FFF for ; Thu, 1 Mar 2018 09:54:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84FC829004; Thu, 1 Mar 2018 09:54:08 +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 6915628FFF for ; Thu, 1 Mar 2018 09:54:06 +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:References:In-Reply-To: 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: List-Owner; bh=Zi7nNU/d3HshlmtpCxYhIclLofudG2/uRNNisNw/rLQ=; b=YWOhvr5gHLnDe5 xhgQmBUjKJB/v+K05s46cxtffe04eJuQKrlzbkr1rIta5gKgvJvsMJcDM3r4Tr38cqop5AkyOOMkT SdUhmr4ADEIOkcRoqoisX5UZfe9JzQIqVHQJfMCnGHWD9re4q8gVgMjpqHmQKypaKv8oiBv/loJ9O v341YmvPxTHV0CMrsxzzt3iP0uT3+46Z3pdk9SmZJcfAB/ByjYdkoKvCvFXfkoTGpberN5AiRZH2y nddEKrVR7RlRj9ciQVLDImaeC9kdof1AG+NlD++2P/c3ZrKK8AegCz1J+Mubs6UPLwZ4B6uhFKcQ4 MtijS0QA9wgpJu4vZZ1w==; 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 1erKuV-00058V-I3; Thu, 01 Mar 2018 09:53:59 +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 1erKtf-0004gr-9b for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 09:53:19 +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 w219nDx6031832; Thu, 1 Mar 2018 10:51:49 +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 2gaxpwrmbv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 01 Mar 2018 10:51:49 +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 AA3463D; Thu, 1 Mar 2018 09:51:47 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8A4B72678; Thu, 1 Mar 2018 09:51:47 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.94) by SAFEX1HUBCAS23.st.com (10.75.90.46) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 1 Mar 2018 10:51:47 +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; Thu, 1 Mar 2018 10:51:47 +0100 From: Amelie Delaunay To: Greg Kroah-Hartman , Rob Herring , Mark Rutland , Tony Prisk , Alan Stern , "Roger Quadros" , Felipe Balbi , "Robin Murphy" Subject: [PATCH v4 2/2] usb: host: ehci-platform: add support for optional external vbus supply Date: Thu, 1 Mar 2018 10:51:39 +0100 Message-ID: <1519897899-8577-3-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519897899-8577-1-git-send-email-amelie.delaunay@st.com> References: <1519897899-8577-1-git-send-email-amelie.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.20.5] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-01_05:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_015307_836714_8A0ABD13 X-CRM114-Status: GOOD ( 17.65 ) 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 --- drivers/usb/host/ehci-platform.c | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c index b065a96..e0dace7 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,56 @@ 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(*priv->vbus_supplies), + 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) + 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 +182,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 = {