Skip to content

Commit

Permalink
usb: typec: stusb160x: register role switch before interrupt registra…
Browse files Browse the repository at this point in the history
…tion

commit 86762ad upstream.

During interrupt registration, attach state is checked. If attached,
then the Type-C state is updated with typec_set_xxx functions and role
switch is set with usb_role_switch_set_role().

If the usb_role_switch parameter is error or null, the function simply
returns 0.

So, to update usb_role_switch role if a device is attached before the
irq is registered, usb_role_switch must be registered before irq
registration.

Fixes: da0cb63 ("usb: typec: add support for STUSB160x Type-C controller family")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Link: https://lore.kernel.org/r/20210716120718.20398-2-amelie.delaunay@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ADESTM authored and gregkh committed Jul 28, 2021
1 parent 703527b commit eeb1849
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions drivers/usb/typec/stusb160x.c
Expand Up @@ -739,10 +739,6 @@ static int stusb160x_probe(struct i2c_client *client)
typec_set_pwr_opmode(chip->port, chip->pwr_opmode);

if (client->irq) {
ret = stusb160x_irq_init(chip, client->irq);
if (ret)
goto port_unregister;

chip->role_sw = fwnode_usb_role_switch_get(fwnode);
if (IS_ERR(chip->role_sw)) {
ret = PTR_ERR(chip->role_sw);
Expand All @@ -752,6 +748,10 @@ static int stusb160x_probe(struct i2c_client *client)
ret);
goto port_unregister;
}

ret = stusb160x_irq_init(chip, client->irq);
if (ret)
goto role_sw_put;
} else {
/*
* If Source or Dual power role, need to enable VDD supply
Expand All @@ -775,6 +775,9 @@ static int stusb160x_probe(struct i2c_client *client)

return 0;

role_sw_put:
if (chip->role_sw)
usb_role_switch_put(chip->role_sw);
port_unregister:
typec_unregister_port(chip->port);
all_reg_disable:
Expand Down

0 comments on commit eeb1849

Please sign in to comment.