Devicetree
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Christian Bruel <christian.bruel@foss.st.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Srinivas Kandagatla <srini@kernel.org>,
	Marek Vasut <marex@nabladev.com>, Vinod Koul <vkoul@kernel.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Pankaj Dev <pankaj.dev@st.com>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-phy@lists.infradead.org
Subject: Re: [PATCH 06/16] usb: typec: add FUSB340 SuperSpeed switch driver
Date: Mon, 31 Aug 2026 13:04:56 +0200	[thread overview]
Message-ID: <apVf2GL-r0Cm8Q53@black.igk.intel.com> (raw)
In-Reply-To: <20260821-ucpd-host-fusb340-v7-2-rfc-v1-6-c5e27cbc0795@foss.st.com>

On Fri, Aug 21, 2026 at 06:23:17PM +0200, Fabrice Gasnier wrote:
> Add a platform driver for the ON Semiconductor FUSB340 SuperSpeed switch.
> The driver uses enable-gpios and select-gpios to control the switch and
> registers Type-C switch and mux providers for Type-C applications where a
> reversible cable requires a switch.
> 
> Assisted-by: GitHub-Copilot:GPT-5.4-mini
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
> ---
>  drivers/usb/typec/mux/Kconfig   |   8 ++
>  drivers/usb/typec/mux/Makefile  |   1 +
>  drivers/usb/typec/mux/fusb340.c | 169 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 178 insertions(+)

> diff --git a/drivers/usb/typec/mux/Kconfig b/drivers/usb/typec/mux/Kconfig
> index 6dd8f961b593..6a1da48a2a8f 100644
> --- a/drivers/usb/typec/mux/Kconfig
> +++ b/drivers/usb/typec/mux/Kconfig
> @@ -12,6 +12,14 @@ config TYPEC_MUX_FSA4480
>  	  common USB Type-C connector.
>  	  If compiled as a module, the module will be named fsa4480.
>  
> +config TYPEC_MUX_FUSB340
> +	tristate "ON Semi FUSB340 SuperSpeed switch driver"
> +	help
> +	  Driver for the ON Semiconductor FUSB340 SuperSpeed switch, which
> +	  provides support for routing SuperSpeed pairs in Type-C applications
> +	  where a reversible cable requires a switch.
> +	  If compiled as a module, the module will be named fusb340.
> +
>  config TYPEC_MUX_GPIO_SBU
>  	tristate "Generic GPIO based SBU mux for USB Type-C applications"
>  	help

Why can't you just use MUX_GPIO_SBU (sorry if I've missed something)?

Thanks,

> diff --git a/drivers/usb/typec/mux/Makefile b/drivers/usb/typec/mux/Makefile
> index b4f599eb5053..ef8d2b05ff7f 100644
> --- a/drivers/usb/typec/mux/Makefile
> +++ b/drivers/usb/typec/mux/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>  
>  obj-$(CONFIG_TYPEC_MUX_FSA4480)		+= fsa4480.o
> +obj-$(CONFIG_TYPEC_MUX_FUSB340)		+= fusb340.o
>  obj-$(CONFIG_TYPEC_MUX_GPIO_SBU)	+= gpio-sbu-mux.o
>  obj-$(CONFIG_TYPEC_MUX_PI3USB30532)	+= pi3usb30532.o
>  obj-$(CONFIG_TYPEC_MUX_INTEL_PMC)	+= intel_pmc_mux.o
> diff --git a/drivers/usb/typec/mux/fusb340.c b/drivers/usb/typec/mux/fusb340.c
> new file mode 100644
> index 000000000000..0f0e45743784
> --- /dev/null
> +++ b/drivers/usb/typec/mux/fusb340.c
> @@ -0,0 +1,169 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * ON Semiconductor FUSB340 SuperSpeed switch driver
> + *
> + * Copyright (C) 2026 STMicroelectronics
> + */
> +
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/usb/typec_altmode.h>
> +#include <linux/usb/typec_mux.h>
> +
> +struct fusb340 {
> +	struct gpio_desc *enable_gpio;
> +	struct gpio_desc *select_gpio;
> +	struct mutex lock; /* serialize orientation and mode updates */
> +	struct typec_switch_dev *sw;
> +	struct typec_mux_dev *mux;
> +	enum typec_orientation orientation;
> +	unsigned long mode;
> +};
> +
> +static void fusb340_update_locked(struct fusb340 *fusb)
> +{
> +	bool enable = fusb->mode == TYPEC_STATE_USB &&
> +		      fusb->orientation != TYPEC_ORIENTATION_NONE;
> +	bool select = fusb->orientation == TYPEC_ORIENTATION_REVERSE;
> +
> +	gpiod_set_value_cansleep(fusb->enable_gpio, enable);
> +	gpiod_set_value_cansleep(fusb->select_gpio, select);
> +}
> +
> +static int fusb340_switch_set(struct typec_switch_dev *sw,
> +			      enum typec_orientation orientation)
> +{
> +	struct fusb340 *fusb = typec_switch_get_drvdata(sw);
> +
> +	mutex_lock(&fusb->lock);
> +
> +	if (fusb->orientation != orientation) {
> +		fusb->orientation = orientation;
> +		fusb340_update_locked(fusb);
> +	}
> +
> +	mutex_unlock(&fusb->lock);
> +
> +	return 0;
> +}
> +
> +static int fusb340_mux_set(struct typec_mux_dev *mux,
> +			   struct typec_mux_state *state)
> +{
> +	struct fusb340 *fusb = typec_mux_get_drvdata(mux);
> +	int ret = 0;
> +
> +	mutex_lock(&fusb->lock);
> +
> +	if (state->mode != TYPEC_STATE_SAFE && state->mode != TYPEC_STATE_USB) {
> +		ret = -EOPNOTSUPP;
> +		goto out_unlock;
> +	}
> +
> +	if (fusb->mode != state->mode) {
> +		fusb->mode = state->mode;
> +		fusb340_update_locked(fusb);
> +	}
> +
> +out_unlock:
> +	mutex_unlock(&fusb->lock);
> +
> +	return ret;
> +}
> +
> +static int fusb340_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct typec_switch_desc sw_desc = { };
> +	struct typec_mux_desc mux_desc = { };
> +	struct fusb340 *fusb;
> +	int ret;
> +
> +	fusb = devm_kzalloc(dev, sizeof(*fusb), GFP_KERNEL);
> +	if (!fusb)
> +		return -ENOMEM;
> +
> +	fusb->orientation = TYPEC_ORIENTATION_NONE;
> +	fusb->mode = TYPEC_STATE_SAFE;
> +
> +	fusb->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
> +	if (IS_ERR(fusb->enable_gpio))
> +		return dev_err_probe(dev, PTR_ERR(fusb->enable_gpio),
> +				     "failed to get enable gpio\n");
> +
> +	fusb->select_gpio = devm_gpiod_get(dev, "select", GPIOD_OUT_LOW);
> +	if (IS_ERR(fusb->select_gpio))
> +		return dev_err_probe(dev, PTR_ERR(fusb->select_gpio),
> +				     "failed to get select gpio\n");
> +
> +	mutex_init(&fusb->lock);
> +
> +	sw_desc.drvdata = fusb;
> +	sw_desc.fwnode = dev_fwnode(dev);
> +	sw_desc.set = fusb340_switch_set;
> +
> +	fusb->sw = typec_switch_register(dev, &sw_desc);
> +	if (IS_ERR(fusb->sw)) {
> +		ret = dev_err_probe(dev, PTR_ERR(fusb->sw),
> +				    "failed to register typec switch\n");
> +		goto err_mutex_destroy;
> +	}
> +
> +	mux_desc.drvdata = fusb;
> +	mux_desc.fwnode = dev_fwnode(dev);
> +	mux_desc.set = fusb340_mux_set;
> +
> +	fusb->mux = typec_mux_register(dev, &mux_desc);
> +	if (IS_ERR(fusb->mux)) {
> +		ret = dev_err_probe(dev, PTR_ERR(fusb->mux),
> +				    "failed to register typec mux\n");
> +		goto err_unregister_switch;
> +	}
> +
> +	platform_set_drvdata(pdev, fusb);
> +
> +	return 0;
> +
> +err_unregister_switch:
> +	typec_switch_unregister(fusb->sw);
> +err_mutex_destroy:
> +	mutex_destroy(&fusb->lock);
> +	return ret;
> +}
> +
> +static void fusb340_remove(struct platform_device *pdev)
> +{
> +	struct fusb340 *fusb = platform_get_drvdata(pdev);
> +
> +	gpiod_set_value_cansleep(fusb->enable_gpio, 0);
> +	gpiod_set_value_cansleep(fusb->select_gpio, 0);
> +
> +	typec_mux_unregister(fusb->mux);
> +	typec_switch_unregister(fusb->sw);
> +	mutex_destroy(&fusb->lock);
> +}
> +
> +static const struct of_device_id fusb340_of_match[] = {
> +	{ .compatible = "onnn,fusb340" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, fusb340_of_match);
> +
> +static struct platform_driver fusb340_driver = {
> +	.probe = fusb340_probe,
> +	.remove = fusb340_remove,
> +	.driver = {
> +		.name = "fusb340",
> +		.of_match_table = fusb340_of_match,
> +	},
> +};
> +module_platform_driver(fusb340_driver);
> +
> +MODULE_DESCRIPTION("ON Semiconductor FUSB340 SuperSpeed switch driver");
> +MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@foss.st.com>");
> +MODULE_LICENSE("GPL");
> 
> -- 
> 2.43.0

-- 
heikki

  reply	other threads:[~2026-08-31 11:05 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 16:23 [PATCH 00/16] Add support for USB Type-C on STM32MP25 Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 01/16] dt-bindings: usb: st,tcpp: Document TCPP USB-C PD protection chip Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 02/16] usb: typec: tcpm: Add STM32 tcpp driver Fabrice Gasnier
2026-08-22  4:50   ` Marek Vasut
2026-08-21 16:23 ` [PATCH 03/16] dt-bindings: usb: st,stm32-ucpd: Document STM32 UCPD controller Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 04/16] usb: typec: tcpm: Add STM32 UCPD driver Fabrice Gasnier
2026-08-24 14:38   ` Philipp Zabel
2026-08-21 16:23 ` [PATCH 05/16] dt-bindings: usb: add FUSB340 switch binding Fabrice Gasnier
2026-08-22  4:49   ` Marek Vasut
2026-08-25 13:09     ` Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 06/16] usb: typec: add FUSB340 SuperSpeed switch driver Fabrice Gasnier
2026-08-31 11:04   ` Heikki Krogerus [this message]
2026-08-21 16:23 ` [PATCH 07/16] dt-bindings: nvmem: st,stm32-romem: align patternProperties regex on nvmem-deprecated-cells.yaml Fabrice Gasnier
2026-08-27 12:51   ` Krzysztof Kozlowski
2026-08-21 16:23 ` [PATCH 08/16] arm64: dts: st: Add ucpd node on stm32mp251 Fabrice Gasnier
2026-08-22  5:00   ` Marek Vasut
2026-08-26 13:19     ` Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 09/16] arm64: dts: st: add i2c1 pinctrl entries for stm32mp25 Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 10/16] arm64: dts: st: add tcpp " Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 11/16] dt-bindings: usb: dwc3: stm32: refer to dwc3-common Fabrice Gasnier
2026-08-27 12:44   ` Krzysztof Kozlowski
2026-08-21 16:23 ` [PATCH 12/16] dt-bindings: phy: stm32: adapt usb2phy as syscon child on stm32mp25 Fabrice Gasnier
2026-08-27 12:54   ` Krzysztof Kozlowski
2026-08-21 16:23 ` [PATCH 13/16] dt-bindings: arm: stm32mp2: allow child nodes since simple-mfd transition Fabrice Gasnier
2026-08-27 12:50   ` Krzysztof Kozlowski
2026-08-21 16:23 ` [PATCH 14/16] arm64: dts: st: enable usb on stm32mp257f-ev1 Fabrice Gasnier
2026-08-27 12:55   ` Krzysztof Kozlowski
2026-08-21 16:23 ` [PATCH 15/16] arm64: dts: st: enable usb on stm32mp257f-dk Fabrice Gasnier
2026-08-21 16:23 ` [PATCH 16/16] arm64: configs: enable usb and its dependencies used on stm32mp25 Fabrice Gasnier
2026-08-22  7:28   ` Krzysztof Kozlowski
2026-08-27 12:45 ` [PATCH 00/16] Add support for USB Type-C on STM32MP25 Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=apVf2GL-r0Cm8Q53@black.igk.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=broonie@kernel.org \
    --cc=christian.bruel@foss.st.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=marex@nabladev.com \
    --cc=neil.armstrong@linaro.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pankaj.dev@st.com \
    --cc=robh@kernel.org \
    --cc=srini@kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox