Skip to content

Commit 6a6168b

Browse files
committed
samples: rust: add regulator consumer driver sample
Add a basic sample for using the regulator consumer API. Signed-off-by: Fabien Parent <fabien.parent@linaro.org>
1 parent dd5792c commit 6a6168b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

samples/rust/Kconfig

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ config SAMPLE_RUST_PRINT
3030

3131
If unsure, say N.
3232

33+
config SAMPLE_RUST_REGULATOR_CONSUMER
34+
tristate "Regulator consumer device driver"
35+
help
36+
This option builds the Rust regulator consumer driver sample.
37+
38+
To compile this as a module, choose M here:
39+
the module will be called rust_regulator_consumer.
40+
41+
If unsure, say N.
42+
3343
config SAMPLE_RUST_HOSTPROGS
3444
bool "Host programs"
3545
help

samples/rust/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
44
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
5+
obj-$(CONFIG_SAMPLE_RUST_REGULATOR_CONSUMER) += rust_regulator_consumer.o
56

67
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Rust regulator consumer driver sample.
4+
5+
use kernel::{c_str, device, module_platform_driver, of, platform, prelude::*,
6+
regulator::consumer::{Mode, Regulator}};
7+
8+
module_platform_driver! {
9+
type: Driver,
10+
name: "rust_regulator_consumer",
11+
license: "GPL",
12+
}
13+
14+
struct Driver;
15+
impl platform::Driver for Driver {
16+
kernel::define_of_id_table! {(), [
17+
(of::DeviceId::Compatible(b"rust,regulator-consumer"), None),
18+
]}
19+
20+
fn probe(pdev: &mut platform::Device, _id_info: Option<&Self::IdInfo>) -> Result {
21+
let dev = device::Device::from_dev(pdev);
22+
let vbus = Regulator::get(&dev, c_str!("vbus"))?;
23+
let _ = vbus.enable()?;
24+
25+
Ok(())
26+
}
27+
}

0 commit comments

Comments
 (0)