[Linux-stm32] [PATCH v3 2/2] usb: typec: mux: gpio-sbu: enable when only used for orientation

Heikki Krogerus heikki.krogerus at linux.intel.com
Mon Aug 31 10:11:42 UTC 2026


On Wed, Aug 26, 2026 at 02:16:36PM +0200, Fabrice Gasnier wrote:
> When used as orientation-switch only (no mode-switch, e.g. no altmode),
> the optional enable gpio remains disabled.
> Enable it from the switch_set() routine, in this case, when the
> orientation is set and the enable-gpios property has been provided.
> Move enable GPIO configuration after the swapped configuration has
> been done, to avoid possible glitches in case both signals are changed.
> 
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier at foss.st.com>

Acked-by: Heikki Krogerus <heikki.krogerus at linux.intel.com>

> ---
> Changes in v3
> - Fix missed v2 update on probing mode-switch property.
> Changes in v2
> - fix issues reported by Sashiko: probe mode-switch property before
>   registering Type-C switch, to avoid possible race. Configure enable
>   GPIO after swapp GPIO has been configured, in case both transition.
> ---
>  drivers/usb/typec/mux/gpio-sbu-mux.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/gpio-sbu-mux.c b/drivers/usb/typec/mux/gpio-sbu-mux.c
> index 1834f1a2dd9d..b1aa976aca24 100644
> --- a/drivers/usb/typec/mux/gpio-sbu-mux.c
> +++ b/drivers/usb/typec/mux/gpio-sbu-mux.c
> @@ -17,6 +17,7 @@ struct gpio_sbu_mux {
>  
>  	struct typec_switch_dev *sw;
>  	struct typec_mux_dev *mux;
> +	bool mode_switch;
>  
>  	struct mutex lock; /* protect enabled and swapped */
>  	bool enabled;
> @@ -40,19 +41,24 @@ static int gpio_sbu_switch_set(struct typec_switch_dev *sw,
>  		enabled = false;
>  		break;
>  	case TYPEC_ORIENTATION_NORMAL:
> +		if (!sbu_mux->mode_switch)
> +			enabled = true;
>  		swapped = false;
>  		break;
>  	case TYPEC_ORIENTATION_REVERSE:
> +		if (!sbu_mux->mode_switch)
> +			enabled = true;
>  		swapped = true;
>  		break;
>  	}
>  
> -	if (enabled != sbu_mux->enabled)
> -		gpiod_set_value_cansleep(sbu_mux->enable_gpio, enabled);
> -
>  	if (swapped != sbu_mux->swapped)
>  		gpiod_set_value_cansleep(sbu_mux->select_gpio, swapped);
>  
> +	/* If both enabled and swapped transition, set enable GPIO after to avoid glitches */
> +	if (enabled != sbu_mux->enabled)
> +		gpiod_set_value_cansleep(sbu_mux->enable_gpio, enabled);
> +
>  	sbu_mux->enabled = enabled;
>  	sbu_mux->swapped = swapped;
>  
> @@ -120,6 +126,7 @@ static int gpio_sbu_mux_probe(struct platform_device *pdev)
>  	sw_desc.fwnode = dev_fwnode(dev);
>  	sw_desc.set = gpio_sbu_switch_set;
>  
> +	sbu_mux->mode_switch = device_property_read_bool(dev, "mode-switch");
>  	sbu_mux->sw = typec_switch_register(dev, &sw_desc);
>  	if (IS_ERR(sbu_mux->sw))
>  		return dev_err_probe(dev, PTR_ERR(sbu_mux->sw),
> 
> -- 
> 2.43.0

-- 
heikki



More information about the Linux-stm32 mailing list