Skip to content

Commit 40ed51a

Browse files
Peter Chengregkh
authored andcommitted
usb: chipidea: host: add vbus regulator control
For boards which have board level vbus control (eg, through gpio), we need to vbus operation according to below rules: - For host, we need open vbus before start hcd, and close it after remove hcd. - For otg, the vbus needs to be on/off when usb role switches. When the host roles begins, it opens vbus; when the host role finishes, it closes vbus. 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. Tested-by: Marek Vasut <[email protected]> Signed-off-by: Peter Chen <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1542d9c commit 40ed51a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/usb/chipidea/host.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/usb.h>
2525
#include <linux/usb/hcd.h>
2626
#include <linux/usb/chipidea.h>
27+
#include <linux/regulator/consumer.h>
2728

2829
#include "../host/ehci.h"
2930

@@ -65,16 +66,34 @@ static int host_start(struct ci_hdrc *ci)
6566
ehci->has_hostpc = ci->hw_bank.lpm;
6667
ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
6768

69+
if (ci->platdata->reg_vbus) {
70+
ret = regulator_enable(ci->platdata->reg_vbus);
71+
if (ret) {
72+
dev_err(ci->dev,
73+
"Failed to enable vbus regulator, ret=%d\n",
74+
ret);
75+
goto put_hcd;
76+
}
77+
}
78+
6879
ret = usb_add_hcd(hcd, 0, 0);
6980
if (ret)
70-
usb_put_hcd(hcd);
81+
goto disable_reg;
7182
else
7283
ci->hcd = hcd;
7384

7485
if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
7586
hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
7687

7788
return ret;
89+
90+
disable_reg:
91+
regulator_disable(ci->platdata->reg_vbus);
92+
93+
put_hcd:
94+
usb_put_hcd(hcd);
95+
96+
return ret;
7897
}
7998

8099
static void host_stop(struct ci_hdrc *ci)
@@ -83,6 +102,8 @@ static void host_stop(struct ci_hdrc *ci)
83102

84103
usb_remove_hcd(hcd);
85104
usb_put_hcd(hcd);
105+
if (ci->platdata->reg_vbus)
106+
regulator_disable(ci->platdata->reg_vbus);
86107
}
87108

88109
int ci_hdrc_host_init(struct ci_hdrc *ci)

0 commit comments

Comments
 (0)