Skip to content

earlgrey: Add SPI mux support - #412

Draft
lchiawei wants to merge 2 commits into
OpenPRoT:earlgrey-hwefrom
lchiawei:feature/spi-mux-handle
Draft

earlgrey: Add SPI mux support#412
lchiawei wants to merge 2 commits into
OpenPRoT:earlgrey-hwefrom
lchiawei:feature/spi-mux-handle

Conversation

@lchiawei

Copy link
Copy Markdown

No description provided.

@lchiawei
lchiawei requested a review from cfrantz August 11, 2026 19:14
@lchiawei lchiawei changed the title Feature/spi mux handle [earlgrey] Add spi mux handle Aug 11, 2026
@lchiawei lchiawei changed the title [earlgrey] Add spi mux handle earlgrey: Add spi mux support Aug 11, 2026
@lchiawei lchiawei changed the title earlgrey: Add spi mux support earlgrey: Add SPI mux support Aug 11, 2026
pub struct SwitchMuxFinOp {
/// A bitmap indicating which SPI flash devices are accessible.
/// Bit `i` set to 1 means Flash device `i` is accessible (e.g., bit 0 = 0x1 for Host 0, bit 1 = 0x2 for Host 1).
pub accessible_flash_bitmap: u32,

@anthonychen1251 anthonychen1251 Aug 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Could u8 be sufficient for the use case here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes you're right. Changed to u8.

.map_err(ErrorCode::from)?;
let _ = sleep_until(SystemClock::now() + RESET_HOLD_DELAY);

// Step 2: Switch MUX selection channel (LOW for Host 0, HIGH for Host 1).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should we use the inverse logic (HIGH for Host 0 and LOW for Host 1) for the MUX selection? In the integration block diagram, Earlgrey's SPI HOST 0 is connected to SPI EEPROM 0, while SPI HOST 1 is connected to SPI EEPROM 1. When the SPI_MUX_CTRL is pulled low, it directs the main CPU complex to SPI EEPROM 0. This implies that Earlgrey has exclusive access to SPI EEPROM 1, and the associated SPI HOST is 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nice catch. Tried to use more descriptive names to avoid mental computation and confusion in the future: HostCpu0Earlgrey1, HostCpu1Earlgrey0

@lchiawei
lchiawei force-pushed the feature/spi-mux-handle branch from 92258ac to bb0a050 Compare August 13, 2026 07:20
Add a dedicated control channel and multi-channel IPC infrastructure to
coordinate SPI MUX switching and flash access in Earlgrey firmware.

Key changes:
1. Control Plane Isolation:
   - Introduce `SPI_FLASH_MUX_SERVICE` and `FlashMuxClient` in
     `target/earlgrey/services/platform/flash_mux.rs`.
   - Add opcodes `IPC_OP_FLASH_SWITCH_MUX_NOTICE` (quiesce access) and
     `IPC_OP_FLASH_SWITCH_MUX_FIN_NOTICE` (re-initialize 4-Byte address mode).
   - Keep generic `services/flash` 100% clean of platform-specific MUX logic.
   - Update `PlatformServer::switch_mux` to use `FlashMuxClient` and `SpiMuxRoute`.

2. Multi-Channel Flash Server:
   - Provide dedicated data channels `SPI_FLASH0_SERVICE` and `SPI_FLASH1_SERVICE`.
   - Provide dynamic data channel `SPI_GENERIC_FLASH_SERVICE` that routes to
     the active flash device.
   - Isolate internal `EFLASH_SERVICE` from MUX switching operations.
   - Directly reject inactive or quiesced channels with `FLASH_GENERIC_INACCESSIBLE`.

3. Verification:
   - Update `target/earlgrey/tests/spi_flash` with E2E hardware verification.
   - Verify dedicated channel rejection, quiescence rejection, and 4-Byte
     address mode operation on the CW340 FPGA target.
@lchiawei
lchiawei force-pushed the feature/spi-mux-handle branch from bb0a050 to e242e6a Compare August 13, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants