Skip to content

Commit

Permalink
补全I2c 调整bcm
Browse files Browse the repository at this point in the history
I2c: 补全algorithm
bcm: 调整代码布局,填充部分批注,函数
Signed-off-by: Nostalgia <[email protected]>
  • Loading branch information
lvyuemeng committed Aug 13, 2024
1 parent 0b90e04 commit 0b583e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
32 changes: 25 additions & 7 deletions drivers/i2c/busses/i2c_bcm2835_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

//! BCM2835 master mode driver
use kernel::{
bindings,
bindings, c_str,
clk::Clk,
clk_provider::{ClkHw, ClkInitData, ClkOps},
completion::Completion,
container_of, define_of_id_table,
device::{self, Device, RawDevice},
driver::DeviceRemoval,
error::to_result,
i2c::{self, I2cAdapter, I2cAdapterQuirks, I2cAlgorithm, I2cMsg, I2C_M_NOSTART, I2C_M_RD},
interrupt::{request_irq, IrqHandler, IRQF_SHARED},
io_mem::IoMem,
irq,
irq, module_platform_driver, new_completion,
of::DeviceId,
platform,
prelude::*,
str::CString,
sync::Arc,
{c_str, container_of, define_of_id_table, module_platform_driver, new_completion},
};

/// I2C 地址预留空间
Expand Down Expand Up @@ -338,7 +339,6 @@ impl Bcm2835I2cDev {
}
}

// TODO: impl interrupt irq_handler
fn bcm2835_i2c_isr(this_irq: i32, data: &mut Bcm2835I2cDev) -> irq::Return {
let i2c_dev = unsafe { &mut *(data as *mut Bcm2835I2cDev) };

Expand Down Expand Up @@ -412,6 +412,16 @@ fn goto_complete(i2c_dev: &mut Bcm2835I2cDev) -> irq::Return {
irq::Return::Handled
}

struct Bcm2835I2cIrqHandler;

impl IrqHandler for Bcm2835I2cIrqHandler {
type Context = Bcm2835I2cDev;

fn handler(irq: i32, ctx: &mut Self::Context) -> irq::Return {
bcm2835_i2c_isr(irq, ctx)
}
}

unsafe extern "C" fn bcm2835_i2c_isr_cb(this_irq: i32, data: *mut core::ffi::c_void) -> u32 {
bcm2835_i2c_isr(this_irq, unsafe { &mut *data.cast() }) as u32
}
Expand Down Expand Up @@ -507,7 +517,7 @@ impl I2cAlgorithm for Bcm2835I2cAlgo {
}

//static BCM2835_I2C_QUIRKS: I2cAdapterQuirks =
//I2cAdapterQuirks::new().set_flags(i2c::I2C_AQ_NO_CLK_STRETCH as u64);
//I2cAdapterQuirks::new().set_flags(i2c::I2C_AQ_NO_CLK_STRETCH as u64);

struct Bcm2835I2cData {}
unsafe impl Sync for Bcm2835I2cDev {}
Expand Down Expand Up @@ -568,7 +578,7 @@ impl platform::Driver for Bcm2835I2cDriver {

let irq = pdev.irq_resource(0)?;

let ret = unsafe {
/*let ret = unsafe {
bindings::request_threaded_irq(
irq as u32,
Some(bcm2835_i2c_isr_cb),
Expand All @@ -581,7 +591,15 @@ impl platform::Driver for Bcm2835I2cDriver {
if ret < 0 {
dev_err!(pdev, "Could not request IRQ: {}\n", irq);
to_result(ret)?;
}
}*/

request_irq(
irq as u32,
Bcm2835I2cIrqHandler,
IRQF_SHARED as u64,
c_str!("i2c_bcm2835_rust"),
&i2c_dev,
)?;
i2c_dev.irq = irq;

// TODO: setup i2c_adapter
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
irq,
str::CStr,
};
use core::{marker::PhantomData, task::Context};
use core::marker::PhantomData;

pub const IRQF_TRIGGER_NONE: u32 = bindings::IRQF_TRIGGER_NONE;
pub const IRQF_TRIGGER_RISING: u32 = bindings::IRQF_TRIGGER_RISING;
Expand Down

0 comments on commit 0b583e5

Please sign in to comment.