Skip to content

MT-149180: add basic ipc/extcon mechanism to send usb events from the stm through the kernel#41

Open
Overdr0ne wants to merge 10 commits into
MultiTracksDotCom:developfrom
Overdr0ne:MT-149180
Open

MT-149180: add basic ipc/extcon mechanism to send usb events from the stm through the kernel#41
Overdr0ne wants to merge 10 commits into
MultiTracksDotCom:developfrom
Overdr0ne:MT-149180

Conversation

@Overdr0ne
Copy link
Copy Markdown

@Overdr0ne Overdr0ne commented Jun 1, 2026

MT-149180

This change implements a SPI IPC driver that triggers extcon events. The idea is, those extcon events look just like they would if they came from an onboard usb controller. I created some debug nodes to simulate disconnect and vbus detected events, which get sent to the extcon nodes where you can see the uevents in userspace here. So I’m only simulating the extcon part of the signal path, not yet anything with SPI. That part is in place, but I just need to get a clear spec on the SPI packet- we might already have that, I just need to look. Once the stm side is done, it should be a pretty simple modification to finish wiring things up.

multitracks:~# udevadm monitor&
[1] 3358
monitor will print the received events for:
multitracks:~# UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent


multitracks:~# echo 2 > /sys/kernel/debug/stm_ipc/usb1_sim
KERNEL[453.920839] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
KERNEL[453.920975] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
UDEV  [453.946124] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
UDEV  [453.947456] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
multitracks:~# echo 0 > /sys/kernel/debug/stm_ipc/usb1_sim
KERNEL[496.200781] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
KERNEL[496.200920] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
UDEV  [496.225930] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)
UDEV  [496.227230] change   /devices/platform/soc@0/30800000.bus/30800000.spba-bus/30830000.spi/spi_master/spi1/spi1.0/30830000.spi:stm32-ipc@0:connector-usb1/extcon/extcon0 (extcon)

I'm leaving this as a draft for now because the stm side isn't done, and I made up my own packet spec, but it would be safe to integrate so people can try it out

dev QA: @dnappier-mt

@Overdr0ne Overdr0ne marked this pull request as ready for review June 3, 2026 19:31
Copilot AI review requested due to automatic review settings June 3, 2026 19:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an STM32 SPI-based IPC driver that publishes USB role/connection events as virtual extcon connectors, and wires it up for the mt-connect platform.

Changes:

  • Introduce extcon-stm32-ipc SPI core + child “virtual connector” platform driver with debugfs simulation support
  • Add Kconfig/Makefile integration for CONFIG_EXTCON_STM32_SPI_IPC
  • Update mt-connect DTS/defconfig to instantiate the SPI IPC device and connect USB controllers via extcon

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
drivers/extcon/extcon-stm32-ipc.c New SPI IPC + virtual extcon implementation, IRQ handling, and debugfs simulation hooks
drivers/extcon/Makefile Build integration for new extcon driver object
drivers/extcon/Kconfig New EXTCON_STM32_SPI_IPC configuration option
arch/arm64/configs/mt_connect_defconfig Enables the new driver in the platform defconfig
arch/arm64/boot/dts/freescale/mt-connect.dts Replaces spidev node with STM32 IPC node, adds connector children, and links USB extcon phandles

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drivers/extcon/extcon-stm32-ipc.c
Comment thread drivers/extcon/extcon-stm32-ipc.c Outdated
Comment thread drivers/extcon/extcon-stm32-ipc.c
Comment thread drivers/extcon/extcon-stm32-ipc.c Outdated
Comment thread drivers/extcon/extcon-stm32-ipc.c Outdated
Comment thread drivers/extcon/Kconfig Outdated
Overdr0ne added 10 commits June 3, 2026 16:00
Add a custom SPI client driver that functions as an extcon event
provider. This driver communicates with an external STM32 co-processor
over SPI using an attention line (interrupt) to propagate USB cable
events.

It registers separate virtual extcon sub-devices for each connector,
allowing ChipIdea OTG controllers to switch between Host/Peripheral
roles. A debugfs simulation interface is also exposed for runtime testing.
Enable CONFIG_EXTCON_STM32_SPI_IPC in mt_connect_defconfig to compile
the custom stm-spi-ipc extcon driver directly into the kernel.
Configure the ECSPI2 controller on mt-connect to support the STM32 SPI
IPC slave node and its virtual USB connector child nodes. Bind
&usbotg1 and &usbotg2 to their respective virtual extcon connectors
and enable role switching. Set up pin control and active-low interrupt
for GPIO2_IO11.
Copilot AI review requested due to automatic review settings June 3, 2026 23:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment on lines +205 to +210
struct stm_ipc_priv *parent_priv = dev_get_drvdata(dev->parent);
if (parent_priv && parent_priv->debugfs_root) {
char name[32];
snprintf(name, sizeof(name), "usb%d_sim", priv->port_id + 1);
debugfs_create_file(name, 0200, parent_priv->debugfs_root, priv, &stm_ipc_sim_fops);
}
Comment on lines +244 to +247
struct dentry *parent;

/* Setup CRC8 lookup table (polynomial 0x07) */
crc8_populate_msb(stm_crc8_table, STM_IPC_CRC8_POLYNOMIAL);
} __packed;

/* Parent SPI controller private structure */
DECLARE_CRC8_TABLE(stm_crc8_table);
Comment on lines +186 to +190
ret = of_property_read_u32(dev->of_node, "port-id", &priv->port_id);
if (ret) {
dev_err(dev, "Missing 'port-id' property\n");
return ret;
}
Comment thread drivers/extcon/Kconfig
Comment on lines +179 to +182
config EXTCON_STM32_SPI_IPC
tristate "STM32 SPI IPC and Virtual Extcon support"
depends on SPI
select CRC8
/* Fallback to safe disconnected state on protocol error */
extcon_set_state_sync(edev, EXTCON_USB, false);
extcon_set_state_sync(edev, EXTCON_USB_HOST, false);
pr_warn_ratelimited("stm-spi-ipc: Invalid USB connector state: %u\n", state);
Comment on lines +250 to +260
parent = debugfs_create_dir("stm_ipc", NULL);
if (IS_ERR_OR_NULL(parent)) {
dev_warn(&spi->dev, "Failed to create debugfs parent directory\n");
priv->debugfs_root = NULL;
} else {
priv->debugfs_root = debugfs_create_dir(dev_name(&spi->dev), parent);
if (IS_ERR_OR_NULL(priv->debugfs_root)) {
dev_warn(&spi->dev, "Failed to create debugfs root directory\n");
priv->debugfs_root = NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants