1 From 531ef5ebea96394ddb7f554d4d88e017dde30a59 Mon Sep 17 00:00:00 2001
2 From: Amelie Delaunay <amelie.delaunay@st.com>
3 Date: Tue, 13 Feb 2018 09:28:12 +0100
4 Subject: [PATCH] usb: dwc2: add support for host mode external vbus supply
6 This patch adds a way to enable an external vbus supply in host mode,
7 when dwc2 drvvbus signal is not used.
9 This patch is very similar to the one done in U-Boot dwc2 driver [1]. It
10 also adds dynamic vbus supply management depending on the role and state
13 [1] https://lists.denx.de/pipermail/u-boot/2017-March/283434.html
15 Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
16 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
18 drivers/usb/dwc2/core.h | 2 ++
19 drivers/usb/dwc2/hcd.c | 26 ++++++++++++++++++++++++++
20 2 files changed, 28 insertions(+)
22 --- a/drivers/usb/dwc2/core.h
23 +++ b/drivers/usb/dwc2/core.h
24 @@ -777,6 +777,7 @@ struct dwc2_hregs_backup {
25 * @plat: The platform specific configuration data. This can be
26 * removed once all SoCs support usb transceiver.
27 * @supplies: Definition of USB power supplies
28 + * @vbus_supply: Regulator supplying vbus.
29 * @phyif: PHY interface width
30 * @lock: Spinlock that protects all the driver data structures
31 * @priv: Stores a pointer to the struct usb_hcd
32 @@ -914,6 +915,7 @@ struct dwc2_hsotg {
34 struct dwc2_hsotg_plat *plat;
35 struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
36 + struct regulator *vbus_supply;
40 --- a/drivers/usb/dwc2/hcd.c
41 +++ b/drivers/usb/dwc2/hcd.c
42 @@ -359,6 +359,23 @@ static void dwc2_gusbcfg_init(struct dwc
43 dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
46 +static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
48 + hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
49 + if (IS_ERR(hsotg->vbus_supply))
52 + return regulator_enable(hsotg->vbus_supply);
55 +static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg)
57 + if (hsotg->vbus_supply)
58 + return regulator_disable(hsotg->vbus_supply);
64 * dwc2_enable_host_interrupts() - Enables the Host mode interrupts
66 @@ -3346,6 +3363,7 @@ static void dwc2_conn_id_status_change(s
68 /* B-Device connector (Device Mode) */
69 if (gotgctl & GOTGCTL_CONID_B) {
70 + dwc2_vbus_supply_exit(hsotg);
71 /* Wait for switch to device mode */
72 dev_dbg(hsotg->dev, "connId B\n");
73 if (hsotg->bus_suspended) {
74 @@ -4455,6 +4473,9 @@ static int _dwc2_hcd_start(struct usb_hc
77 spin_unlock_irqrestore(&hsotg->lock, flags);
79 + dwc2_vbus_supply_init(hsotg);
84 @@ -4482,6 +4503,8 @@ static void _dwc2_hcd_stop(struct usb_hc
85 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
86 spin_unlock_irqrestore(&hsotg->lock, flags);
88 + dwc2_vbus_supply_exit(hsotg);
90 usleep_range(1000, 3000);
93 @@ -4518,6 +4541,7 @@ static int _dwc2_hcd_suspend(struct usb_
96 dwc2_writel(hprt0, hsotg->regs + HPRT0);
97 + dwc2_vbus_supply_exit(hsotg);
100 /* Enter hibernation */
101 @@ -4598,6 +4622,8 @@ static int _dwc2_hcd_resume(struct usb_h
102 spin_unlock_irqrestore(&hsotg->lock, flags);
103 dwc2_port_resume(hsotg);
105 + dwc2_vbus_supply_init(hsotg);
107 /* Wait for controller to correctly update D+/D- level */
108 usleep_range(3000, 5000);