1 // SPDX-License-Identifier: GPL-2.0 2 3 //! Rust SoC Platform driver sample. 4 5 use kernel::{ 6 acpi, 7 device::Core, 8 of, 9 platform, 10 prelude::*, 11 soc, 12 str::CString, 13 sync::aref::ARef, // 14 }; 15 use pin_init::pin_init_scope; 16 17 #[pin_data] 18 struct SampleSocDriver { 19 pdev: ARef<platform::Device>, 20 #[pin] 21 _dev_reg: soc::Registration, 22 } 23 24 kernel::of_device_table!( 25 OF_TABLE, 26 <SampleSocDriver as platform::Driver>::IdInfo, 27 [(of::DeviceId::new(c"test,rust-device"), ())] 28 ); 29 30 kernel::acpi_device_table!( 31 ACPI_TABLE, 32 <SampleSocDriver as platform::Driver>::IdInfo, 33 [(acpi::DeviceId::new(c"LNUXBEEF"), ())] 34 ); 35 36 impl platform::Driver for SampleSocDriver { 37 type IdInfo = (); 38 type Data<'bound> = Self; 39 const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE); 40 const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE); 41 42 fn probe<'bound>( 43 pdev: &'bound platform::Device<Core<'_>>, 44 _info: Option<&'bound Self::IdInfo>, 45 ) -> impl PinInit<Self, Error> + 'bound { 46 dev_dbg!(pdev, "Probe Rust SoC driver sample.\n"); 47 48 let pdev = pdev.into(); 49 pin_init_scope(move || { 50 let machine = CString::try_from(c"My cool ACME15 dev board")?; 51 let family = CString::try_from(c"ACME")?; 52 let revision = CString::try_from(c"1.2")?; 53 let serial_number = CString::try_from(c"12345")?; 54 let soc_id = CString::try_from(c"ACME15")?; 55 56 let attr = soc::Attributes { 57 machine: Some(machine), 58 family: Some(family), 59 revision: Some(revision), 60 serial_number: Some(serial_number), 61 soc_id: Some(soc_id), 62 }; 63 64 Ok(try_pin_init!(SampleSocDriver { 65 pdev: pdev, 66 _dev_reg <- soc::Registration::new(attr), 67 }? Error)) 68 }) 69 } 70 } 71 72 kernel::module_platform_driver! { 73 type: SampleSocDriver, 74 name: "rust_soc", 75 authors: ["Matthew Maurer"], 76 description: "Rust SoC Driver", 77 license: "GPL", 78 } 79