Skip to content

Commit 0f9b6e4

Browse files
Fabrice GasnierPatrice Chotard
authored andcommitted
usb: typec: stusb160x: add support for power supplies
STUSB160x Type-C controller has three optional regulators. Try to get them, and enable them all at probe time. Enforce the 30ms Tload max delay has elapsed before accessing the registers. Change-Id: Icc25ce9fe287b94bd3f60ed470d4f04874f7e839 Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/515011 Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com> ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com> Reviewed-by: Patrick DELAUNAY <patrick.delaunay@foss.st.com> Domain-Review: Patrice CHOTARD <patrice.chotard@foss.st.com> ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
1 parent ecef178 commit 0f9b6e4

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

drivers/usb/typec/typec-stusb160x.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <i2c.h>
1111
#include <typec.h>
1212
#include <dm/device_compat.h>
13+
#include <linux/delay.h>
14+
#include <power/regulator.h>
1315

1416
#define STUSB160X_ALERT_STATUS 0x0B /* RC */
1517
#define STUSB160X_CC_CONNECTION BIT(6)
@@ -92,9 +94,50 @@ static u8 stusb160x_get_nb_connector(struct udevice *dev)
9294

9395
static int stusb160x_probe(struct udevice *dev)
9496
{
97+
struct udevice *vsys_supply, *vdd_supply, *vconn_supply;
9598
int power_mode_ctrl;
9699
int ret;
97100

101+
/* Get "vsys", "vdd" and "vconn" optional regulators, enable them. */
102+
ret = device_get_supply_regulator(dev, "vsys-supply", &vsys_supply);
103+
if (ret && ret != -ENOENT)
104+
return ret;
105+
106+
if (vsys_supply) {
107+
ret = regulator_set_enable_if_allowed(vsys_supply, true);
108+
if (ret) {
109+
dev_err(dev, "Error enabling vsys supply (ret=%d)\n", ret);
110+
return ret;
111+
}
112+
}
113+
114+
ret = device_get_supply_regulator(dev, "vdd-supply", &vdd_supply);
115+
if (ret && ret != -ENOENT)
116+
return ret;
117+
118+
if (vdd_supply) {
119+
ret = regulator_set_enable_if_allowed(vdd_supply, true);
120+
if (ret) {
121+
dev_err(dev, "Error enabling vdd supply (ret=%d)\n", ret);
122+
return ret;
123+
}
124+
}
125+
126+
ret = device_get_supply_regulator(dev, "vconn-supply", &vconn_supply);
127+
if (ret && ret != -ENOENT)
128+
return ret;
129+
130+
if (vconn_supply) {
131+
ret = regulator_set_enable_if_allowed(vconn_supply, true);
132+
if (ret) {
133+
dev_err(dev, "Error enabling vconn supply (ret=%d)\n", ret);
134+
return ret;
135+
}
136+
}
137+
138+
/* Tload: I2C registers loading time from NVM */
139+
mdelay(30);
140+
98141
/* configure STUSB160X_CC_POWER_MODE_CTRL */
99142
power_mode_ctrl = dm_i2c_reg_read(dev, STUSB160X_CC_POWER_MODE_CTRL);
100143
if (power_mode_ctrl < 0)

0 commit comments

Comments
 (0)