Skip to content

Commit

Permalink
samples: rust: add regulator consumer driver sample
Browse files Browse the repository at this point in the history
Add a basic sample for using the regulator consumer API.

Signed-off-by: Fabien Parent <[email protected]>
  • Loading branch information
Fabo committed Nov 14, 2023
1 parent dd5792c commit 6a6168b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/rust/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ config SAMPLE_RUST_PRINT

If unsure, say N.

config SAMPLE_RUST_REGULATOR_CONSUMER
tristate "Regulator consumer device driver"
help
This option builds the Rust regulator consumer driver sample.

To compile this as a module, choose M here:
the module will be called rust_regulator_consumer.

If unsure, say N.

config SAMPLE_RUST_HOSTPROGS
bool "Host programs"
help
Expand Down
1 change: 1 addition & 0 deletions samples/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
obj-$(CONFIG_SAMPLE_RUST_REGULATOR_CONSUMER) += rust_regulator_consumer.o

subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
27 changes: 27 additions & 0 deletions samples/rust/rust_regulator_consumer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0

//! Rust regulator consumer driver sample.
use kernel::{c_str, device, module_platform_driver, of, platform, prelude::*,
regulator::consumer::{Mode, Regulator}};

module_platform_driver! {
type: Driver,
name: "rust_regulator_consumer",
license: "GPL",
}

struct Driver;
impl platform::Driver for Driver {
kernel::define_of_id_table! {(), [
(of::DeviceId::Compatible(b"rust,regulator-consumer"), None),
]}

fn probe(pdev: &mut platform::Device, _id_info: Option<&Self::IdInfo>) -> Result {
let dev = device::Device::from_dev(pdev);
let vbus = Regulator::get(&dev, c_str!("vbus"))?;
let _ = vbus.enable()?;

Ok(())
}
}

0 comments on commit 6a6168b

Please sign in to comment.