From: Amelie Delaunay <amelie.delaunay@st.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Tony Prisk <linux@prisktech.co.nz>,
Alan Stern <stern@rowland.harvard.edu>,
Roger Quadros <rogerq@ti.com>,
Felipe Balbi <felipe.balbi@linux.intel.com>,
Robin Murphy <robin.murphy@arm.com>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Amelie Delaunay <amelie.delaunay@st.com>
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 [thread overview]
Message-ID: <1519897899-8577-3-git-send-email-amelie.delaunay@st.com> (raw)
In-Reply-To: <1519897899-8577-1-git-send-email-amelie.delaunay@st.com>
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 <amelie.delaunay@st.com>
Reviewed-by: Roger Quadros <rogerq@ti.com>
---
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 <linux/of.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
#include <linux/reset.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
@@ -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 = {
--
2.7.4
prev parent reply other threads:[~2018-03-01 9:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-01 9:51 [PATCH v4 0/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
2018-03-01 9:51 ` [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property Amelie Delaunay
2018-03-06 1:57 ` Rob Herring
2018-03-06 14:09 ` Robin Murphy
2018-03-06 14:40 ` Rob Herring
2018-03-20 9:10 ` Amelie DELAUNAY
2018-03-01 9:51 ` Amelie Delaunay [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1519897899-8577-3-git-send-email-amelie.delaunay@st.com \
--to=amelie.delaunay@st.com \
--cc=devicetree@vger.kernel.org \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@prisktech.co.nz \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rogerq@ti.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).