Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(d1): add smhc driver #299

Merged
merged 39 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ece1b7a
Create SMHC driver skeleton
jspngh Jul 30, 2023
d7f9249
Create sdmmc kernel service, copied from i2c service
jspngh Jul 30, 2023
f2488b9
Copy some kernel communication stuff from TWI to SMHC driver
jspngh Jul 30, 2023
ef24fa1
Add SDMMC uuid
jspngh Jul 30, 2023
b7c1a2f
Replace Transfer/Transaction with Command/Response in sdmmc service
jspngh Aug 5, 2023
95e5daa
sdmmc: rework `Command` and start implementation of `SdCardClient`
jspngh Sep 3, 2023
9d1f933
smhc driver: initial implementation of `run` and `command` functions
jspngh Sep 3, 2023
cdd8ce7
Add smhc in `src/lib.rs`
jspngh Sep 3, 2023
63e88b0
Rebase on main
jspngh Sep 20, 2023
36663e7
sdmmc: add *data* field to `Response::Short`
jspngh Sep 20, 2023
183dd96
smhc driver: implement `advance_isr`
jspngh Sep 20, 2023
391d9c9
ccu.rs: fix swapped docs in `BusGatingResetRegister`
jspngh Sep 20, 2023
6a39d6e
sdmmc: implement `initialize` function
jspngh Sep 24, 2023
c32ffc0
Add small function to test SdCardClient
jspngh Sep 24, 2023
92438ce
sdmmc: implement more functions
jspngh Sep 25, 2023
befaf60
sdmmc: implement reading from SD card for allwinner-d1
jspngh Oct 26, 2023
abaf683
Apply some PR feedback
jspngh Nov 2, 2023
3722c51
smhc: reduce module clock rate to 100 MHz
jspngh Nov 2, 2023
5a5c468
ccu: set gating and reset in single line
jspngh Nov 19, 2023
597a9b7
smhc: extract `reset_fifo` function
jspngh Nov 19, 2023
4a45088
smhc: refactor `idmac` descriptors to be inline with `dmac` implement…
jspngh Nov 19, 2023
24cb3cb
smhc: apply more PR feedback
jspngh Nov 19, 2023
d53a807
dmac: some spelling fixes
jspngh Nov 19, 2023
4853c46
smhc: fix some check + clippy lints
jspngh Nov 19, 2023
4910303
smhc: fix lints + formatting
jspngh Nov 20, 2023
a0a3a9b
kernel/src/services/mod: fix rustfmt
jspngh Nov 20, 2023
8de1561
smhc+sdmmc: improve error handling + doc comments
jspngh Nov 20, 2023
1b01fa5
sdmmc: map [u32;4] to u128 for card identification register
jspngh Nov 20, 2023
18d2757
smhc: add `num` field to `Smhc` struct
jspngh Nov 21, 2023
c517354
smhc: use `bool` for single-bit fields in `Cfg` bitfield
jspngh Nov 21, 2023
d676e44
smhc: update some doc comments
jspngh Nov 21, 2023
a8478c7
allwinner-d1/src/lib: remove sdcard test code
jspngh Nov 26, 2023
0f14a11
sdmmc: update mapping of [u32;4] to u128
jspngh Nov 27, 2023
87c505f
Merge branch 'main' into jspngh/smhc-driver
hawkw Nov 28, 2023
86c6b8d
sdmmc: use `maitake::time` to sleep in `SdCardClient::initialize`
jspngh Dec 5, 2023
29c1dd1
sdmmc: `Response::Long` contains u128
jspngh Dec 5, 2023
15c49d5
sdmmc: move response tracing line to `SdCardClient::cmd`
jspngh Dec 5, 2023
091961b
sdmmc: refactor Error to struct with *kind* and *message*
jspngh Dec 8, 2023
3649fed
sdmmc: small style improvements
jspngh Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions platforms/allwinner-d1/d1-core/src/ccu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ pub struct Ccu {
ccu: CCU,
}

#[derive(PartialEq)]
pub enum BusGating {
Mask,
Pass,
}

#[derive(PartialEq)]
pub enum BusReset {
Assert,
Deassert,
}

/// Trait to be implemented for module clocks that can be gated and reset
pub trait BusGatingResetRegister {
/// Enable or disable the clock reset bit
fn gating(ccu: &mut CCU, pass: bool);
/// Enable or disable the clock gating bit
fn reset(ccu: &mut CCU, deassert: bool);
fn gating(ccu: &mut CCU, gating: BusGating);
/// Enable or disable the clock reset bit
fn reset(ccu: &mut CCU, reset: BusReset);
}

// TODO: should this move into the `Clint`?
Expand All @@ -49,16 +61,16 @@ impl Ccu {

/// De-assert the reset bit and enable the clock gating bit for the given module
pub fn enable_module<MODULE: BusGatingResetRegister>(&mut self, _mod: &mut MODULE) {
MODULE::reset(&mut self.ccu, true);
MODULE::reset(&mut self.ccu, BusReset::Deassert);
sdelay(20);
MODULE::gating(&mut self.ccu, true);
MODULE::gating(&mut self.ccu, BusGating::Pass);
}

/// Disable the clock gating bit and assert the reset bit for the given module
pub fn disable_module<MODULE: BusGatingResetRegister>(&mut self, _mod: &mut MODULE) {
MODULE::gating(&mut self.ccu, false);
MODULE::gating(&mut self.ccu, BusGating::Mask);
// TODO: delay?
MODULE::reset(&mut self.ccu, false);
MODULE::reset(&mut self.ccu, BusReset::Assert);
}

/// Allow modules to configure their own clock on a PAC level
Expand Down Expand Up @@ -248,12 +260,16 @@ macro_rules! impl_bgr {
($($MODULE:ident : ($reg:ident, $gating:ident, $reset:ident),)+) => {
$(
impl BusGatingResetRegister for $MODULE {
fn gating(ccu: &mut CCU, pass: bool) {
ccu.$reg.modify(|_, w| w.$gating().bit(pass));
fn gating(ccu: &mut CCU, gating: BusGating) {
ccu.$reg.modify(|_, w| {
w.$gating().bit(gating == BusGating::Pass)
});
}

fn reset(ccu: &mut CCU, deassert: bool) {
ccu.$reg.modify(|_, w| w.$reset().bit(deassert));
fn reset(ccu: &mut CCU, reset: BusReset) {
ccu.$reg.modify(|_, w| {
w.$reset().bit(reset == BusReset::Deassert)
});
}
}
)+
Expand Down
7 changes: 4 additions & 3 deletions platforms/allwinner-d1/d1-core/src/dmac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod descriptor;
/// This struct is constructed using [`Dmac::new`], which initializes the DMA
/// controller and returns a `Dmac`. Since this struct is essentially a token
/// representing that the DMAC has been initialized, it may be freely copied
/// into any driver that wishes to perform DMA oeprations.
/// into any driver that wishes to perform DMA operations.
#[derive(Copy, Clone)]
pub struct Dmac {
// this struct is essentially used as a "yes, the DMAC is initialized now" token...
Expand Down Expand Up @@ -89,7 +89,7 @@ pub enum ChannelMode {
/// transfer completes, and waits for the peripheral to pull the DMA
/// Active signal low before starting the next transfer.
///
/// The Allwinner documentationh for the D1 describes this mode as follows:
/// The Allwinner documentation for the D1 describes this mode as follows:
///
/// > * When the DMAC detects a valid external request signal, the DMAC
/// > starts to operate the peripheral device. The internal DRQ always
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Dmac {
/// some of the data it wanted. If we were reading from a device, reads may
/// have side effects and incomplete reads may leave the device in a weird
/// state. Cancelling an incomplete transfer may result in, for example,
/// writing out half of a string to the UART, or only part of a structured
/// writing out half of a string to the UART, or only part of a structured
/// message over SPI, and so on. But, at least we don't have abandoned DMA
/// transfers running around in random parts of the heap you probably wanted
/// to use for normal stuff like having strings, or whatever it is that
Expand Down Expand Up @@ -398,6 +398,7 @@ impl Channel {
/// dropped, the descriptor and its associated memory region may also be
/// dropped safely.
///
/// Of course, the transfer may still have completed partially. If we
/// were writing to a device, the device may be unhappy to have only gotten
/// some of the data it wanted. If we were reading from a device, reads may
/// have side effects and incomplete reads may leave the device in a weird
Expand Down
1 change: 1 addition & 0 deletions platforms/allwinner-d1/d1-core/src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "sharp-display")]
pub mod sharp_display;
pub mod smhc;
pub mod spim;
pub mod twi;
pub mod uart;
Loading
Loading