Skip to content

Commit 92ceb2e

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 09b670d commit 92ceb2e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

samples/rust/Kconfig

Lines changed: 10 additions & 0 deletions
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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy