| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 |
|
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 |
|
| 70 | use kernel::{
|
| 71 | acpi,
|
| 72 | device,
|
| 73 | devres::Devres,
|
| 74 | i2c,
|
| 75 | of,
|
| 76 | platform,
|
| 77 | prelude::*,
|
| 78 | sync::aref::ARef, |
| 79 | };
|
| 80 |
|
| 81 | #[pin_data]
|
| 82 | struct SampleDriver {
|
| 83 | parent_dev: ARef<platform::Device>,
|
| 84 | #[pin]
|
| 85 | _reg: Devres<i2c::Registration>,
|
| 86 | }
|
| 87 |
|
| 88 | kernel::of_device_table!(
|
| 89 | OF_TABLE,
|
| 90 | <SampleDriver as platform::Driver>::IdInfo,
|
| 91 | [(of::DeviceId::new(c"test,rust-device"), ())]
|
| 92 | );
|
| 93 |
|
| 94 | kernel::acpi_device_table!(
|
| 95 | ACPI_TABLE,
|
| 96 | <SampleDriver as platform::Driver>::IdInfo,
|
| 97 | [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
|
| 98 | );
|
| 99 |
|
| 100 | const SAMPLE_I2C_CLIENT_ADDR: u16 = 0x30;
|
| 101 | const SAMPLE_I2C_ADAPTER_INDEX: i32 = 0;
|
| 102 | const BOARD_INFO: i2c::I2cBoardInfo =
|
| 103 | i2c::I2cBoardInfo::new(c"rust_driver_i2c", SAMPLE_I2C_CLIENT_ADDR);
|
| 104 |
|
| 105 | impl platform::Driver for SampleDriver {
|
| 106 | type IdInfo = ();
|
| 107 | type Data<'bound> = Self;
|
| 108 | const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
|
| 109 | const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
|
| 110 |
|
| 111 | fn probe<'bound>(
|
| 112 | pdev: &'bound platform::Device<device::Core<'_>>,
|
| 113 | _info: Option<&'bound Self::IdInfo>,
|
| 114 | ) -> impl PinInit<Self, Error> + 'bound {
|
| 115 | dev_info!(
|
| 116 | pdev.as_ref(),
|
| 117 | "Probe Rust I2C Client registration sample.\n"
|
| 118 | );
|
| 119 |
|
| 120 | kernel::try_pin_init!( Self {
|
| 121 | parent_dev: pdev.into(),
|
| 122 |
|
| 123 | _reg <- {
|
| 124 | let adapter = i2c::I2cAdapter::get(SAMPLE_I2C_ADAPTER_INDEX)?;
|
| 125 |
|
| 126 | i2c::Registration::new(&adapter, &BOARD_INFO, pdev.as_ref())
|
| 127 | }
|
| 128 | })
|
| 129 | }
|
| 130 |
|
| 131 | fn unbind<'bound>(
|
| 132 | pdev: &'bound platform::Device<device::Core<'_>>,
|
| 133 | _this: Pin<&Self::Data<'bound>>,
|
| 134 | ) {
|
| 135 | dev_info!(
|
| 136 | pdev.as_ref(),
|
| 137 | "Unbind Rust I2C Client registration sample.\n"
|
| 138 | );
|
| 139 | }
|
| 140 | }
|
| 141 |
|
| 142 | kernel::module_platform_driver! {
|
| 143 | type: SampleDriver,
|
| 144 | name: "rust_device_i2c",
|
| 145 | authors: ["Danilo Krummrich", "Igor Korotin"],
|
| 146 | description: "Rust I2C client registration",
|
| 147 | license: "GPL v2",
|
| 148 | }
|