[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241218-ncv6336-v1-4-b8d973747f7a@gmail.com>
Date: Wed, 18 Dec 2024 15:36:34 -0800
From: Fabien Parent <parent.f@...il.com>
To: Rob Herring <robh@...nel.org>, Saravana Kannan <saravanak@...gle.com>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Wolfram Sang <wsa+renesas@...g-engineering.com>,
Mark Brown <broonie@...nel.org>, Liam Girdwood <lgirdwood@...il.com>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konradybcio@...nel.org>, Fabien Parent <parent.f@...il.com>
Cc: devicetree@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-i2c@...r.kernel.org,
linux-arm-msm@...r.kernel.org, vinod.koul@...aro.org,
Fabien Parent <fabien.parent@...aro.org>
Subject: [PATCH 4/9] rust: regulator: add abstraction for Regulator's modes
From: Fabien Parent <fabien.parent@...aro.org>
The type regulator::Mode is used by both the regulator consumer
abstraction and the regulator driver abstraction. This commits
adds a shared abstraction for it.
Signed-off-by: Fabien Parent <fabien.parent@...aro.org>
---
MAINTAINERS | 1 +
rust/bindings/bindings_helper.h | 1 +
rust/kernel/lib.rs | 2 ++
rust/kernel/regulator.rs | 42 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 46 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index acb3942eb1b66ec2bc09ac50f51c2054b7b45355..90c231f0aa7381aa8d206fb94c5d1f013dfcae41 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25159,6 +25159,7 @@ F: Documentation/power/regulator/
F: drivers/regulator/
F: include/dt-bindings/regulator/
F: include/linux/regulator/
+F: rust/kernel/regulator.rs
K: regulator_get_optional
VOLTAGE AND CURRENT REGULATOR IRQ HELPERS
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 48d2b91b34067e7e9ee9c64c2e42681e988e9aad..b18d772bc3a0e78d749cc9e5ae81a4237a57f8c5 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -29,6 +29,7 @@
#include <linux/poll.h>
#include <linux/refcount.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <linux/sched.h>
#include <linux/security.h>
#include <linux/slab.h>
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 456e979724d1079045cb157086ff2b2ed0fcca3b..3aa36648e9571e305a89f5d1353c0dd44e136384 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -68,6 +68,8 @@
pub mod rbtree;
#[cfg(CONFIG_REGMAP)]
pub mod regmap;
+#[cfg(CONFIG_REGULATOR)]
+pub mod regulator;
pub mod revocable;
pub mod security;
pub mod seq_file;
diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
new file mode 100644
index 0000000000000000000000000000000000000000..d695ac955193efcfda62770784a92d70d606b93d
--- /dev/null
+++ b/rust/kernel/regulator.rs
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! SoC Regulators
+
+use crate::{
+ bindings,
+ error::{code::*, Error, Result},
+};
+
+/// Regulators operating modes
+#[derive(Copy, Clone)]
+#[repr(u32)]
+pub enum Mode {
+ /// Invalid mode
+ Invalid = bindings::REGULATOR_MODE_INVALID,
+ /// Regulator can handle fast changes in it's load
+ Fast = bindings::REGULATOR_MODE_FAST,
+ /// Normal regulator power supply mode
+ Normal = bindings::REGULATOR_MODE_NORMAL,
+ /// Regulator runs in a more efficient mode for light loads
+ Idle = bindings::REGULATOR_MODE_IDLE,
+ /// Regulator runs in the most efficient mode for very light loads
+ Standby = bindings::REGULATOR_MODE_STANDBY,
+}
+
+impl TryFrom<core::ffi::c_uint> for Mode {
+ type Error = Error;
+
+ /// Convert a mode represented as an unsigned integer into its Rust enum equivalent
+ ///
+ /// If the integer does not match any of the [`Mode`], then [`EINVAL`] is returned
+ fn try_from(mode: core::ffi::c_uint) -> Result<Self> {
+ match mode {
+ bindings::REGULATOR_MODE_FAST => Ok(Self::Fast),
+ bindings::REGULATOR_MODE_NORMAL => Ok(Self::Normal),
+ bindings::REGULATOR_MODE_IDLE => Ok(Self::Idle),
+ bindings::REGULATOR_MODE_STANDBY => Ok(Self::Standby),
+ bindings::REGULATOR_MODE_INVALID => Ok(Self::Invalid),
+ _ => Err(EINVAL),
+ }
+ }
+}
--
2.45.2
Powered by blists - more mailing lists