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
Open
MT-149180: add basic ipc/extcon mechanism to send usb events from the stm through the kernel#41Overdr0ne wants to merge 10 commits into
Overdr0ne wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
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-ipcSPI 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.
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.
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 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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