|
| 1 | +//! Types and traits for SD/MMC peripherals. |
| 2 | +
|
| 3 | +mod bus_width; |
| 4 | +mod fifo_status; |
| 5 | +mod reset; |
| 6 | + |
| 7 | +pub mod command; |
| 8 | +pub mod response; |
| 9 | +pub mod tuning; |
| 10 | + |
| 11 | +pub use bus_width::BusWidth; |
| 12 | +pub use fifo_status::FifoStatus; |
| 13 | +pub use reset::Reset; |
| 14 | + |
| 15 | +use command::MmcCommand; |
| 16 | +use response::MmcResponse; |
| 17 | +use tuning::TuningMode; |
| 18 | + |
| 19 | +/// Common operations for DesignWare MMC controllers on JH7110 SoCs. |
| 20 | +pub trait MmcOps { |
| 21 | + /// Associated error type for the SD/MMC trait. |
| 22 | + type Error; |
| 23 | + |
| 24 | + /// Gets whether the device is a MMC card. |
| 25 | + fn is_mmc(&self) -> bool; |
| 26 | + |
| 27 | + /// Gets whether the device is a SD card. |
| 28 | + fn is_sd(&self) -> bool { |
| 29 | + !self.is_mmc() |
| 30 | + } |
| 31 | + |
| 32 | + /// Gets whether the device is configured for SPI mode. |
| 33 | + fn is_spi(&self) -> bool; |
| 34 | + |
| 35 | + /// Performs bus setup for the SD/MMC device. |
| 36 | + fn setup_bus(&mut self) -> Result<(), Self::Error>; |
| 37 | + |
| 38 | + /// Performs device initialization sequence. |
| 39 | + fn init(&mut self) -> Result<(), Self::Error>; |
| 40 | + |
| 41 | + /// Sets the sample phase for the MMC controller. |
| 42 | + fn set_sample_phase(&mut self, sample_phase: u8); |
| 43 | + |
| 44 | + /// Waits for the FIFO to indicate readiness for read/write operations. |
| 45 | + fn fifo_ready(&self, fifo_status: FifoStatus) -> Result<(), Self::Error>; |
| 46 | + |
| 47 | + /// Waits for the CMD line to reset (usually during power-up). |
| 48 | + fn wait_for_reset(&mut self, reset: Reset, timeout: u64) -> Result<(), Self::Error>; |
| 49 | + |
| 50 | + /// Waits for the busy signal to clear for maximum `timeout_us` microseconds. |
| 51 | + fn wait_while_busy(&mut self, timout_us: u64) -> Result<(), Self::Error>; |
| 52 | + |
| 53 | + /// Writes a SD/MMC command to the card. |
| 54 | + fn write_command<C: MmcCommand>(&mut self, cmd: &C) -> Result<(), Self::Error>; |
| 55 | + |
| 56 | + /// Reads a SD/MMC response based on the provided command argument. |
| 57 | + /// |
| 58 | + /// # Note |
| 59 | + /// |
| 60 | + /// `cmd` should match the last call to `write_command`. |
| 61 | + fn read_response<C: MmcCommand, R: MmcResponse>(&mut self, cmd: &C) -> Result<R, Self::Error>; |
| 62 | + |
| 63 | + /// Reads the raw response bytes from the MMC controller. |
| 64 | + /// |
| 65 | + /// # Note |
| 66 | + /// |
| 67 | + /// Set `exp_crc` to true if a CRC checksum is expected in the response. |
| 68 | + /// |
| 69 | + /// The generic `N` parameter is for the expected length (in bytes) of the response. |
| 70 | + fn response_bytes<const N: usize>(&mut self, exp_crc: bool) -> Result<[u8; N], Self::Error>; |
| 71 | + |
| 72 | + /// Reads data from the MMC data lines. |
| 73 | + fn read_data(&mut self, data: &mut [u8]) -> Result<(), Self::Error>; |
| 74 | + |
| 75 | + /// Writes data to the MMC data lines. |
| 76 | + fn write_data(&mut self, data: &[u8]) -> Result<(), Self::Error>; |
| 77 | + |
| 78 | + /// Requests the card to send a tuning block. |
| 79 | + fn send_tuning(&mut self, bus_width: BusWidth, mode: TuningMode) -> Result<(), Self::Error>; |
| 80 | + |
| 81 | + /// Executes MMC tuning. |
| 82 | + fn execute_tuning(&mut self, bus_width: BusWidth, mode: TuningMode) -> Result<(), Self::Error>; |
| 83 | + |
| 84 | + /// Gets the interrupts status as a 32-bit bitfield. |
| 85 | + fn interrupt(&self) -> u32; |
| 86 | + |
| 87 | + /// Sets the interrupts based on a 32-bit bitfield. |
| 88 | + fn set_interrupt(&mut self, int: u32); |
| 89 | + |
| 90 | + /// Clear all interrupts. |
| 91 | + fn clear_all_interrupt(&mut self); |
| 92 | + |
| 93 | + /// Gets the response interrupts status as a 32-bit bitfield. |
| 94 | + fn response_interrupt(&self) -> u32; |
| 95 | + |
| 96 | + /// Sets the response interrupts based on a 32-bit bitfield. |
| 97 | + fn set_response_interrupt(&mut self, int: u32); |
| 98 | + |
| 99 | + /// Clear all interrupts. |
| 100 | + fn clear_all_response_interrupt(&mut self); |
| 101 | +} |
0 commit comments