Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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