Driver

Trait Driver 

Source
pub trait Driver: Send {
    type IdInfo: 'static;

    const I2C_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
    const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
    const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;

    // Required method
    fn probe(
        dev: &I2cClient<Core>,
        id_info: Option<&Self::IdInfo>,
    ) -> impl PinInit<Self, Error>;

    // Provided methods
    fn shutdown(dev: &I2cClient<Core>, this: Pin<&Self>) { ... }
    fn unbind(dev: &I2cClient<Core>, this: Pin<&Self>) { ... }
}
Expand description

The i2c driver trait.

Drivers must implement this trait in order to get a i2c driver registered.

§Example


 struct MyDriver;

 kernel::acpi_device_table!(
     ACPI_TABLE,
     MODULE_ACPI_TABLE,
     <MyDriver as i2c::Driver>::IdInfo,
     [
         (acpi::DeviceId::new(c_str!("LNUXBEEF")), ())
     ]
 );

 kernel::i2c_device_table!(
     I2C_TABLE,
     MODULE_I2C_TABLE,
     <MyDriver as i2c::Driver>::IdInfo,
     [
          (i2c::DeviceId::new(c_str!("rust_driver_i2c")), ())
     ]
 );

 kernel::of_device_table!(
     OF_TABLE,
     MODULE_OF_TABLE,
     <MyDriver as i2c::Driver>::IdInfo,
     [
         (of::DeviceId::new(c_str!("test,device")), ())
     ]
 );

 impl i2c::Driver for MyDriver {
     type IdInfo = ();
     const I2C_ID_TABLE: Option<i2c::IdTable<Self::IdInfo>> = Some(&I2C_TABLE);
     const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
     const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

     fn probe(
         _idev: &i2c::I2cClient<Core>,
         _id_info: Option<&Self::IdInfo>,
     ) -> impl PinInit<Self, Error> {
         Err(ENODEV)
     }

     fn shutdown(_idev: &i2c::I2cClient<Core>, this: Pin<&Self>) {
     }
 }

Provided Associated Constants§

Source

const I2C_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of device ids supported by the driver.

Source

const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of OF device ids supported by the driver.

Source

const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of ACPI device ids supported by the driver.

Required Associated Types§

Source

type IdInfo: 'static

The type holding information about each device id supported by the driver.

Required Methods§

Source

fn probe( dev: &I2cClient<Core>, id_info: Option<&Self::IdInfo>, ) -> impl PinInit<Self, Error>

I2C driver probe.

Called when a new i2c client is added or discovered. Implementers should attempt to initialize the client here.

Provided Methods§

Source

fn shutdown(dev: &I2cClient<Core>, this: Pin<&Self>)

I2C driver shutdown.

Called by the kernel during system reboot or power-off to allow the Driver to bring the I2cClient into a safe state. Implementing this callback is optional.

Typical actions include stopping transfers, disabling interrupts, or resetting the hardware to prevent undesired behavior during shutdown.

This callback is distinct from final resource cleanup, as the driver instance remains valid after it returns. Any deallocation or teardown of driver-owned resources should instead be handled in Self::drop.

Source

fn unbind(dev: &I2cClient<Core>, this: Pin<&Self>)

I2C driver unbind.

Called when the I2cClient is unbound from its bound Driver. Implementing this callback is optional.

This callback serves as a place for drivers to perform teardown operations that require a &Device<Core> or &Device<Bound> reference. For instance, drivers may try to perform I/O operations to gracefully tear down the device.

Otherwise, release operations for driver resources should be performed in Self::drop.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§