Skip to content

Commit

Permalink
smhc: fix some check + clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jspngh committed Nov 19, 2023
1 parent d53a807 commit 4853c46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
40 changes: 19 additions & 21 deletions platforms/allwinner-d1/d1-core/src/drivers/smhc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Note: We sometimes force a pass by ref mut to enforce exclusive access
#![allow(clippy::needless_pass_by_ref_mut)]

//! Driver for the Allwinner D1's SMHC peripheral.
//!
//! The D1 contains three separate SD/MMC Host Controllers: [`SMHC0`], [`SMHC1`] and [`SMHC2`].
Expand All @@ -13,7 +16,7 @@ use core::{
task::{Poll, Waker},
};

use crate::ccu::{BusGatingResetRegister, Ccu};
use crate::ccu::Ccu;
use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2};

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just check

warning: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check failure on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just clippy

error: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

Check failure on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just clippy

error: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

Check failure on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just clippy

error: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

Check failure on line 20 in platforms/allwinner-d1/d1-core/src/drivers/smhc.rs

View workflow job for this annotation

GitHub Actions / just clippy

error: unused imports: `SMHC1`, `SMHC2` --> platforms/allwinner-d1/d1-core/src/drivers/smhc.rs:20:44 | 20 | use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2}; | ^^^^^ ^^^^^ | = note: `-D unused-imports` implied by `-D warnings`
use kernel::{
mnemos_alloc::containers::FixedVec,
Expand Down Expand Up @@ -356,8 +359,8 @@ impl Smhc {
// Should this (auto_stop select) be part of the params?
let (data_trans, trans_dir, auto_stop) = match params.kind {
sdmmc::CommandKind::Control => (false, false, false),
sdmmc::CommandKind::Read(len) => (true, false, true),
sdmmc::CommandKind::Write(len) => (true, true, true),
sdmmc::CommandKind::Read(_len) => (true, false, true),
sdmmc::CommandKind::Write(_len) => (true, true, true),
};
let chk_resp_crc = params.rsp_crc;
let long_resp = params.rsp_type == sdmmc::ResponseType::Long;
Expand Down Expand Up @@ -579,7 +582,7 @@ impl SmhcData {
// you have to *write* a 1 to their location (W1C = write 1 to clear).

self.err = Self::error_status(smhc);
if let Some(err) = self.err {
if self.err.is_some() {
// Clear all interrupt bits
smhc.smhc_rintsts.write(|w| unsafe { w.bits(0xFFFF_FFFF) });
smhc.smhc_idst.write(|w| unsafe { w.bits(0x3FF) });
Expand Down Expand Up @@ -674,7 +677,7 @@ impl SmhcData {
mod idmac {
use core::mem;
use core::ptr::NonNull;
use mycelium_bitfield::{bitfield, enum_from_bits};
use mycelium_bitfield::bitfield;

/// A descriptor that describes how memory needs to transfer data
/// between the SMHC port and host memory. Multiple DMA transfers
Expand Down Expand Up @@ -703,9 +706,9 @@ mod idmac {

#[derive(Debug)]
pub(super) enum Error {
InvalidBufferAddr,
InvalidBufferSize,
InvalidLink,
BufferAddr,
BufferSize,
Link,
}

bitfield! {
Expand Down Expand Up @@ -789,11 +792,16 @@ mod idmac {
buff: &'_ mut [u8],
) -> Result<DescriptorBuilder<&'_ mut [u8]>, Error> {
if buff.len() > Descriptor::MAX_LEN as usize {
return Err(Error::InvalidBufferSize);
return Err(Error::BufferSize);
}

if (buff.len() & 0b11) > 0 {
return Err(Error::InvalidBufferSize);
return Err(Error::BufferSize);
}

let buff_addr = buff.as_mut_ptr() as *mut _ as u32;
if (buff_addr & 0b11) > 0 {
return Err(Error::BufferAddr);
}

Ok(DescriptorBuilder {
Expand Down Expand Up @@ -832,20 +840,10 @@ mod idmac {
/// Must be 13 bits wide or less.
pub const MAX_LEN: u32 = (1 << 13) - 1;

/// Indicates whether the descriptor is currently owned by the IDMAC.
pub fn is_owned(&self) -> bool {
self.configuration.get(Cfg::DES_OWN_FLAG) != 0
}

/// Indicates whether an error happened during transfer.
pub fn is_err(&self) -> bool {
self.configuration.get(Cfg::ERR_FLAG) != 0
}

fn addr_to_link(link: NonNull<Self>) -> Result<u32, Error> {
let addr = link.as_ptr() as usize;
if addr & (mem::align_of::<Self>() - 1) > 0 {
return Err(Error::InvalidLink);
return Err(Error::Link);
}

Ok((addr as u32) >> 2)
Expand Down
18 changes: 11 additions & 7 deletions source/kernel/src/services/sdmmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
registry::{self, known_uuids, Envelope, KernelHandle, RegisteredDriver},
Kernel,
};
use core::{convert::Infallible, fmt, time::Duration};
use uuid::Uuid;

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -114,7 +113,9 @@ pub enum Response {
/// The 32-bit value from the 48-bit response.
/// Potentially also includes the data buffer if this was a read command.
Short {
/// The response on the command line.
value: u32,
/// The received data, in case of a read command.
data: Option<FixedVec<u8>>,
},
/// The 128-bit value from the 136-bit response.
Expand Down Expand Up @@ -164,8 +165,11 @@ pub struct SdCardClient {
/// The different types of cards
#[derive(Debug, PartialEq)]
pub enum CardType {
/// Standard capacity v1
SD1,
/// Standard capacity v2 (or later)
SD2,
/// High capacity
SDHC,
}

Expand Down Expand Up @@ -279,7 +283,7 @@ impl SdCardClient {
// TODO: limit the number of attempts
let ocr = loop {
// Go to *APP* mode before sending application command
self.cmd(Command {
let _ = self.cmd(Command {
index: 55,
argument: 0,
options: HardwareOptions::None,
Expand All @@ -292,7 +296,7 @@ impl SdCardClient {

let mut op_cond_arg = OCR_VOLTAGE_MASK & 0x00ff8000;
if card_type != CardType::SD1 {
op_cond_arg = OCR_HCS | op_cond_arg;
op_cond_arg |= OCR_HCS;
}
match self
.cmd(Command {
Expand Down Expand Up @@ -340,7 +344,7 @@ impl SdCardClient {
})
.await?
{
Response::Short { .. } => return Err(Error::Response),
Response::Short { .. } => Err(Error::Response),
Response::Long(value) => {
tracing::trace!("CMD2 response: {value:?}");
// TODO: map [u32; 4] value to u128
Expand All @@ -367,7 +371,7 @@ impl SdCardClient {
tracing::trace!("CMD3 response: {value:#x}");
Ok(RelativeCardAddress(value))
}
Response::Long(_) => return Err(Error::Response),
Response::Long(_) => Err(Error::Response),
}
}

Expand All @@ -389,14 +393,14 @@ impl SdCardClient {
tracing::trace!("CMD7 response: {value:#x}");
Ok(CardStatus(value))
}
Response::Long(_) => return Err(Error::Response),
Response::Long(_) => Err(Error::Response),
}
}

/// Use 4 data lanes
pub async fn set_wide_bus(&mut self, rca: RelativeCardAddress) -> Result<CardStatus, Error> {
// Go to *APP* mode before sending application command
self.cmd(Command {
let _ = self.cmd(Command {
index: 55,
argument: rca.0,
options: HardwareOptions::None,
Expand Down

0 comments on commit 4853c46

Please sign in to comment.