Skip to content

Commit 09fa276

Browse files
jremmetswatagar
authored andcommitted
FROMLIST: usb: typec: hd3ss3220: Enable VBUS based on role state
For systems where the ID pin isn't available as gpio use the ATTACHED_STATE register instead to control vbus. >From the datasheet: "This is an additional method to communicate attach other than the ID pin. These bits can be read by the application to determine what was attached." Use this method if id-gpios property is not set, but the connector node has vbus-supply defined. Check regulator state as peripheral and detach can disable vbus. Signed-off-by: Jan Remmet <j.remmet@phytec.de> Link: https://lore.kernel.org/r/20260123-wip-jremmet-hd3ss3220_vbus-v2-1-bcad313ce92b@phytec.de
1 parent 0082888 commit 09fa276

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

drivers/usb/typec/hd3ss3220.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ static const struct typec_operations hd3ss3220_ops = {
204204
.port_type_set = hd3ss3220_port_type_set,
205205
};
206206

207+
static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
208+
{
209+
int ret;
210+
211+
if (regulator_is_enabled(hd3ss3220->vbus) == on)
212+
return;
213+
214+
if (on)
215+
ret = regulator_enable(hd3ss3220->vbus);
216+
else
217+
ret = regulator_disable(hd3ss3220->vbus);
218+
219+
if (ret)
220+
dev_err(hd3ss3220->dev,
221+
"vbus regulator %s failed: %d\n", on ? "disable" : "enable", ret);
222+
}
223+
207224
static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
208225
{
209226
enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220);
@@ -221,6 +238,9 @@ static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
221238
break;
222239
}
223240

241+
if (hd3ss3220->vbus && !hd3ss3220->id_gpiod)
242+
hd3ss3220_regulator_control(hd3ss3220, role_state == USB_ROLE_HOST);
243+
224244
hd3ss3220->role_state = role_state;
225245
}
226246

@@ -330,18 +350,10 @@ static const struct regmap_config config = {
330350
static irqreturn_t hd3ss3220_id_isr(int irq, void *dev_id)
331351
{
332352
struct hd3ss3220 *hd3ss3220 = dev_id;
333-
int ret;
334353
int id;
335354

336355
id = gpiod_get_value_cansleep(hd3ss3220->id_gpiod);
337-
if (!id)
338-
ret = regulator_enable(hd3ss3220->vbus);
339-
else
340-
ret = regulator_disable(hd3ss3220->vbus);
341-
342-
if (ret)
343-
dev_err(hd3ss3220->dev,
344-
"vbus regulator %s failed: %d\n", id ? "disable" : "enable", ret);
356+
hd3ss3220_regulator_control(hd3ss3220, !id);
345357

346358
return IRQ_HANDLED;
347359
}

0 commit comments

Comments
 (0)