* [PATCH v8 0/2] Add a bare-minimum Regulator abstraction
@ 2025-07-14 18:52 Daniel Almeida
2025-07-14 18:52 ` [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Daniel Almeida @ 2025-07-14 18:52 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown
Cc: linux-kernel, rust-for-linux, Alexandre Courbot, Daniel Almeida
Changes in v8:
- Added Alex's r-b
- Added helpers/regulator.c, since the stubs are declared as inline if
CONFIG_REGULATOR is not set (Intel bot)
- Removed unneeded "regulator.enable()" line from docs: it was not needed
and, ironically, it misused the API by choosing Regulator<Dynamic>
and then not keeping the enabled count count balenced (Alex)
- Clarified that the "Enabled" state decreases the enabled refcount when it
drops (Alex)
- Renamed "Microvolt" as "Voltage" and introduced
from_microvolts/as_microvolts (Alex)
- Fixed the spelling for MAINTAINERS in the second commit (Alex)
- Link to v7: https://lore.kernel.org/rust-for-linux/20250704-topics-tyr-regulator-v7-0-77bfca2e22dc@collabora.com/
Changes in v7:
- Add RegulatorState::DISABLE_ON_DROP (Alice)
- Remove #[cfg(CONFIG_REGULATOR)] in lib.rs (if this is N we will use
the stubs)
- Add the bound on 'static directly on RegulatorState to avoid
repetition
- Removed the `data` member on the example (Alice)
- Removed the `mut` token from try_into_enabled() and
try_into_disabled() (Miguel & Intel bot)
- Link to v6: https://lore.kernel.org/r/20250627-topics-tyr-regulator-v6-0-1d015219b454@collabora.com
Changes in v6:
- Use ManuallyDrop<T> to avoid running the destructor in
try_into_enabled() and try_into_disabled(). This is the same strategy
that was being used successfully in the pre-typestate version of this
patch
- Link to v5: https://lore.kernel.org/r/20250623-topics-tyr-regulator-v5-0-99069658cb54@collabora.com
Changes in v5:
- Remove TryIntoEnabled and TryIntoDisabled traits (they were only
implemented for a single type anyways)
- Added regulator.rs to VOLTAGE AND CURRENT REGULATOR FRAMEWORK
- Applied the diff from Miguel Ojeda to format the docs
- Link to v4: https://lore.kernel.org/r/20250609-topics-tyr-regulator-v4-1-b4fdcf1385a7@collabora.com
Changes in v4:
- Rewrote the abstraction to use typestates as per the suggestions by
Benno and Alex.
- Introduced the `Dynamic` state.
- Added more examples.
- Fixed some broken docs.
- Link to v3: https://lore.kernel.org/r/20250513-topics-tyr-regulator-v3-1-4cc2704dfec6@collabora.com
Changes in v3:
- Rebased on rust-next
- Added examples to showcase the API
- Fixed some rendering issues in the docs
- Exposed {get|set}_voltage for both Regulator and EnabledRegulator
- Derived Clone, Copy, PartialEq and Eq for Microvolt
- Link to v2: https://lore.kernel.org/r/20250326-topics-tyr-regulator-v2-1-c0ea6a861be6@collabora.com
Resend v2:
- cc Regulator maintainers
Changes from v1:
- Rebased on rust-next
- Split the design into two types as suggested by Alice Ryhl.
- Modify the docs to highlight how users can use kernel::types::Either
or an enum to enable and disable the regulator at runtime.
- Link to v1: https://lore.kernel.org/rust-for-linux/20250219162517.278362-1-daniel.almeida@collabora.com/
---
Daniel Almeida (2):
rust: regulator: add a bare minimum regulator abstraction
MAINTAINERS: add regulator.rs to the regulator API entry
MAINTAINERS | 1 +
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/regulator.c | 43 +++++
rust/kernel/lib.rs | 1 +
rust/kernel/regulator.rs | 418 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 465 insertions(+)
---
base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e
change-id: 20250714-topics-tyr-regulator2-3aecd5492b2d
Best regards,
--
Daniel Almeida <daniel.almeida@collabora.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction
2025-07-14 18:52 [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
@ 2025-07-14 18:52 ` Daniel Almeida
2025-07-14 19:31 ` Alice Ryhl
2025-07-14 18:52 ` [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry Daniel Almeida
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Daniel Almeida @ 2025-07-14 18:52 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown
Cc: linux-kernel, rust-for-linux, Alexandre Courbot, Daniel Almeida
Add a bare minimum regulator abstraction to be used by Rust drivers.
This abstraction adds a small subset of the regulator API, which is
thought to be sufficient for the drivers we have now.
Regulators provide the power needed by many hardware blocks and thus are
likely to be needed by a lot of drivers.
It was tested on rk3588, where it was used to power up the "mali"
regulator in order to power up the GPU.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/regulator.c | 43 +++++
rust/kernel/lib.rs | 1 +
rust/kernel/regulator.rs | 418 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 464 insertions(+)
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index bc494745f67b82e7a3a6f53055ece0fc3acf6e0d..109b9987091b96a8f5bdc6d4dc2c89cb4bdcdcce 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -64,6 +64,7 @@
#include <linux/poll.h>
#include <linux/property.h>
#include <linux/refcount.h>
+#include <linux/regulator/consumer.h>
#include <linux/sched.h>
#include <linux/security.h>
#include <linux/slab.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 16fa9bca5949b85e8d4cdcfe8e6886124f72d8d8..68e1ee9388aa4a5390132ec0549f84f7aad9fef1 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -32,6 +32,7 @@
#include "pci.c"
#include "pid_namespace.c"
#include "rbtree.c"
+#include "regulator.c"
#include "rcu.c"
#include "refcount.c"
#include "security.c"
diff --git a/rust/helpers/regulator.c b/rust/helpers/regulator.c
new file mode 100644
index 0000000000000000000000000000000000000000..cd8b7ba648ee33dd14326c9242fb6c96ab8e32a7
--- /dev/null
+++ b/rust/helpers/regulator.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/regulator/consumer.h>
+
+#ifndef CONFIG_REGULATOR
+
+void rust_helper_regulator_put(struct regulator *regulator)
+{
+ regulator_put(regulator);
+}
+
+int rust_helper_regulator_set_voltage(struct regulator *regulator, int min_uV,
+ int max_uV)
+{
+ return regulator_set_voltage(regulator, min_uV, max_uV);
+}
+
+int rust_helper_regulator_get_voltage(struct regulator *regulator)
+{
+ return regulator_get_voltage(regulator);
+}
+
+struct regulator *rust_helper_regulator_get(struct device *dev, const char *id)
+{
+ return regulator_get(dev, id);
+}
+
+int rust_helper_regulator_enable(struct regulator *regulator)
+{
+ return regulator_enable(regulator);
+}
+
+int rust_helper_regulator_disable(struct regulator *regulator)
+{
+ return regulator_disable(regulator);
+}
+
+int rust_helper_regulator_is_enabled(struct regulator *regulator)
+{
+ return regulator_is_enabled(regulator);
+}
+
+#endif
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 6b4774b2b1c37f4da1866e993be6230bc6715841..5e4cd8c5e6ff1c4af52a5b1be4c4c32b5104e233 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -100,6 +100,7 @@
pub mod prelude;
pub mod print;
pub mod rbtree;
+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..65f3a125348f2d821898188b4ac6a0b593f18bf2
--- /dev/null
+++ b/rust/kernel/regulator.rs
@@ -0,0 +1,418 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Regulator abstractions, providing a standard kernel interface to control
+//! voltage and current regulators.
+//!
+//! The intention is to allow systems to dynamically control regulator power
+//! output in order to save power and prolong battery life. This applies to both
+//! voltage regulators (where voltage output is controllable) and current sinks
+//! (where current limit is controllable).
+//!
+//! C header: [`include/linux/regulator/consumer.h`](srctree/include/linux/regulator/consumer.h)
+//!
+//! Regulators are modeled in Rust with a collection of states. Each state may
+//! enforce a given invariant, and they may convert between each other where applicable.
+//!
+//! See [Voltage and current regulator API](https://docs.kernel.org/driver-api/regulator.html)
+//! for more information.
+
+use crate::{
+ bindings,
+ device::Device,
+ error::{from_err_ptr, to_result, Result},
+ prelude::*,
+};
+
+use core::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull};
+
+mod private {
+ pub trait Sealed {}
+
+ impl Sealed for super::Enabled {}
+ impl Sealed for super::Disabled {}
+ impl Sealed for super::Dynamic {}
+}
+
+/// A trait representing the different states a [`Regulator`] can be in.
+pub trait RegulatorState: private::Sealed + 'static {
+ /// Whether the regulator should be disabled when dropped.
+ const DISABLE_ON_DROP: bool;
+}
+
+/// A state where the [`Regulator`] is known to be enabled.
+///
+/// The `enable` reference count held by this state is decremented when it is
+/// dropped.
+pub struct Enabled;
+
+/// A state where this [`Regulator`] handle has not specifically asked for the
+/// underlying regulator to be enabled. This means that this reference does not
+/// own an `enable` reference count, but the regulator may still be on.
+pub struct Disabled;
+
+/// A state that models the C API. The [`Regulator`] can be either enabled or
+/// disabled, and the user is in control of the reference count. This is also
+/// the default state.
+///
+/// Use [`Regulator::is_enabled`] to check the regulator's current state.
+pub struct Dynamic;
+
+impl RegulatorState for Enabled {
+ const DISABLE_ON_DROP: bool = true;
+}
+
+impl RegulatorState for Disabled {
+ const DISABLE_ON_DROP: bool = false;
+}
+
+impl RegulatorState for Dynamic {
+ const DISABLE_ON_DROP: bool = false;
+}
+
+/// A trait that abstracts the ability to check if a [`Regulator`] is enabled.
+pub trait IsEnabled: RegulatorState {}
+impl IsEnabled for Disabled {}
+impl IsEnabled for Dynamic {}
+
+/// An error that can occur when trying to convert a [`Regulator`] between states.
+pub struct Error<State: RegulatorState> {
+ /// The error that occurred.
+ pub error: kernel::error::Error,
+
+ /// The regulator that caused the error, so that the operation may be retried.
+ pub regulator: Regulator<State>,
+}
+
+/// A `struct regulator` abstraction.
+///
+/// # Examples
+///
+/// ## Enabling a regulator
+///
+/// This example uses [`Regulator<Enabled>`], which is suitable for drivers that
+/// enable a regulator at probe time and leave them on until the device is
+/// removed or otherwise shutdown.
+///
+/// These users can store [`Regulator<Enabled>`] directly in their driver's
+/// private data struct.
+///
+/// ```
+/// # use kernel::prelude::*;
+/// # use kernel::c_str;
+/// # use kernel::device::Device;
+/// # use kernel::regulator::{Voltage, Regulator, Disabled, Enabled};
+/// fn enable(dev: &Device, min_voltage: Voltage, max_voltage: Voltage) -> Result {
+/// // Obtain a reference to a (fictitious) regulator.
+/// let regulator: Regulator<Disabled> = Regulator::<Disabled>::get(dev, c_str!("vcc"))?;
+///
+/// // The voltage can be set before enabling the regulator if needed, e.g.:
+/// regulator.set_voltage(min_voltage, max_voltage)?;
+///
+/// // The same applies for `get_voltage()`, i.e.:
+/// let voltage: Voltage = regulator.get_voltage()?;
+///
+/// // Enables the regulator, consuming the previous value.
+/// //
+/// // From now on, the regulator is known to be enabled because of the type
+/// // `Enabled`.
+/// //
+/// // If this operation fails, the `Error` will contain the regulator
+/// // reference, so that the operation may be retried.
+/// let regulator: Regulator<Enabled> =
+/// regulator.try_into_enabled().map_err(|error| error.error)?;
+///
+/// // The voltage can also be set after enabling the regulator, e.g.:
+/// regulator.set_voltage(min_voltage, max_voltage)?;
+///
+/// // The same applies for `get_voltage()`, i.e.:
+/// let voltage: Voltage = regulator.get_voltage()?;
+///
+/// // Dropping an enabled regulator will disable it. The refcount will be
+/// // decremented.
+/// drop(regulator);
+///
+/// // ...
+///
+/// Ok(())
+/// }
+/// ```
+///
+/// A more concise shortcut is available for enabling a regulator. This is
+/// equivalent to `regulator_get_enable()`:
+///
+/// ```
+/// # use kernel::prelude::*;
+/// # use kernel::c_str;
+/// # use kernel::device::Device;
+/// # use kernel::regulator::{Voltage, Regulator, Enabled};
+/// fn enable(dev: &Device) -> Result {
+/// // Obtain a reference to a (fictitious) regulator and enable it.
+/// let regulator: Regulator<Enabled> = Regulator::<Enabled>::get(dev, c_str!("vcc"))?;
+///
+/// // Dropping an enabled regulator will disable it. The refcount will be
+/// // decremented.
+/// drop(regulator);
+///
+/// // ...
+///
+/// Ok(())
+/// }
+/// ```
+///
+/// ## Disabling a regulator
+///
+/// ```
+/// # use kernel::prelude::*;
+/// # use kernel::device::Device;
+/// # use kernel::regulator::{Regulator, Enabled, Disabled};
+/// fn disable(dev: &Device, regulator: Regulator<Enabled>) -> Result {
+/// // We can also disable an enabled regulator without reliquinshing our
+/// // refcount:
+/// //
+/// // If this operation fails, the `Error` will contain the regulator
+/// // reference, so that the operation may be retried.
+/// let regulator: Regulator<Disabled> =
+/// regulator.try_into_disabled().map_err(|error| error.error)?;
+///
+/// // The refcount will be decremented when `regulator` is dropped.
+/// drop(regulator);
+///
+/// // ...
+///
+/// Ok(())
+/// }
+/// ```
+///
+/// ## Using [`Regulator<Dynamic>`]
+///
+/// This example mimics the behavior of the C API, where the user is in
+/// control of the enabled reference count. This is useful for drivers that
+/// might call enable and disable to manage the `enable` reference count at
+/// runtime, perhaps as a result of `open()` and `close()` calls or whatever
+/// other driver-specific or subsystem-specific hooks.
+///
+/// ```
+/// # use kernel::prelude::*;
+/// # use kernel::c_str;
+/// # use kernel::device::Device;
+/// # use kernel::regulator::{Regulator, Dynamic};
+/// struct PrivateData {
+/// regulator: Regulator<Dynamic>,
+/// }
+///
+/// // A fictictious probe function that obtains a regulator and sets it up.
+/// fn probe(dev: &Device) -> Result<PrivateData> {
+/// // Obtain a reference to a (fictitious) regulator.
+/// let mut regulator = Regulator::<Dynamic>::get(dev, c_str!("vcc"))?;
+///
+/// Ok(PrivateData { regulator })
+/// }
+///
+/// // A fictictious function that indicates that the device is going to be used.
+/// fn open(dev: &Device, data: &mut PrivateData) -> Result {
+/// // Increase the `enabled` reference count.
+/// data.regulator.enable()?;
+///
+/// Ok(())
+/// }
+///
+/// fn close(dev: &Device, data: &mut PrivateData) -> Result {
+/// // Decrease the `enabled` reference count.
+/// data.regulator.disable()?;
+///
+/// Ok(())
+/// }
+///
+/// fn remove(dev: &Device, data: PrivateData) -> Result {
+/// // `PrivateData` is dropped here, which will drop the
+/// // `Regulator<Dynamic>` in turn.
+/// //
+/// // The reference that was obtained by `regulator_get()` will be
+/// // released, but it is up to the user to make sure that the number of calls
+/// // to `enable()` and `disabled()` are balanced before this point.
+/// Ok(())
+/// }
+/// ```
+///
+/// # Invariants
+///
+/// - `inner` is a non-null wrapper over a pointer to a `struct
+/// regulator` obtained from [`regulator_get()`].
+///
+/// [`regulator_get()`]: https://docs.kernel.org/driver-api/regulator.html#c.regulator_get
+pub struct Regulator<State = Dynamic>
+where
+ State: RegulatorState,
+{
+ inner: NonNull<bindings::regulator>,
+ _phantom: PhantomData<State>,
+}
+
+impl<T: RegulatorState> Regulator<T> {
+ /// Sets the voltage for the regulator.
+ ///
+ /// This can be used to ensure that the device powers up cleanly.
+ pub fn set_voltage(&self, min_voltage: Voltage, max_voltage: Voltage) -> Result {
+ // SAFETY: Safe as per the type invariants of `Regulator`.
+ to_result(unsafe {
+ bindings::regulator_set_voltage(
+ self.inner.as_ptr(),
+ min_voltage.as_microvolts(),
+ max_voltage.as_microvolts(),
+ )
+ })
+ }
+
+ /// Gets the current voltage of the regulator.
+ pub fn get_voltage(&self) -> Result<Voltage> {
+ // SAFETY: Safe as per the type invariants of `Regulator`.
+ let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
+ if voltage < 0 {
+ Err(kernel::error::Error::from_errno(voltage))
+ } else {
+ Ok(Voltage::from_microvolts(voltage))
+ }
+ }
+
+ fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
+ // SAFETY: It is safe to call `regulator_get()`, on a device pointer
+ // received from the C code.
+ let inner = from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_ptr()) })?;
+
+ // SAFETY: We can safely trust `inner` to be a pointer to a valid
+ // regulator if `ERR_PTR` was not returned.
+ let inner = unsafe { NonNull::new_unchecked(inner) };
+
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+
+ fn enable_internal(&mut self) -> Result {
+ // SAFETY: Safe as per the type invariants of `Regulator`.
+ to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) })
+ }
+
+ fn disable_internal(&mut self) -> Result {
+ // SAFETY: Safe as per the type invariants of `Regulator`.
+ to_result(unsafe { bindings::regulator_disable(self.inner.as_ptr()) })
+ }
+}
+
+impl Regulator<Disabled> {
+ /// Obtains a [`Regulator`] instance from the system.
+ pub fn get(dev: &Device, name: &CStr) -> Result<Self> {
+ Regulator::get_internal(dev, name)
+ }
+
+ /// Attempts to convert the regulator to an enabled state.
+ pub fn try_into_enabled(self) -> Result<Regulator<Enabled>, Error<Disabled>> {
+ // We will be transferring the ownership of our `regulator_get()` count to
+ // `Regulator<Enabled>`.
+ let mut regulator = ManuallyDrop::new(self);
+
+ regulator
+ .enable_internal()
+ .map(|()| Regulator {
+ inner: regulator.inner,
+ _phantom: PhantomData,
+ })
+ .map_err(|error| Error {
+ error,
+ regulator: ManuallyDrop::into_inner(regulator),
+ })
+ }
+}
+
+impl Regulator<Enabled> {
+ /// Obtains a [`Regulator`] instance from the system and enables it.
+ ///
+ /// This is equivalent to calling `regulator_get_enable()` in the C API.
+ pub fn get(dev: &Device, name: &CStr) -> Result<Self> {
+ Regulator::<Disabled>::get_internal(dev, name)?
+ .try_into_enabled()
+ .map_err(|error| error.error)
+ }
+
+ /// Attempts to convert the regulator to a disabled state.
+ pub fn try_into_disabled(self) -> Result<Regulator<Disabled>, Error<Enabled>> {
+ // We will be transferring the ownership of our `regulator_get()` count
+ // to `Regulator<Disabled>`.
+ let mut regulator = ManuallyDrop::new(self);
+
+ regulator
+ .disable_internal()
+ .map(|()| Regulator {
+ inner: regulator.inner,
+ _phantom: PhantomData,
+ })
+ .map_err(|error| Error {
+ error,
+ regulator: ManuallyDrop::into_inner(regulator),
+ })
+ }
+}
+
+impl Regulator<Dynamic> {
+ /// Obtains a [`Regulator`] instance from the system. The current state of
+ /// the regulator is unknown and it is up to the user to manage the enabled
+ /// reference count.
+ ///
+ /// This closely mimics the behavior of the C API and can be used to
+ /// dynamically manage the enabled reference count at runtime.
+ pub fn get(dev: &Device, name: &CStr) -> Result<Self> {
+ Regulator::get_internal(dev, name)
+ }
+
+ /// Increases the `enabled` reference count.
+ pub fn enable(&mut self) -> Result {
+ self.enable_internal()
+ }
+
+ /// Decreases the `enabled` reference count.
+ pub fn disable(&mut self) -> Result {
+ self.disable_internal()
+ }
+}
+
+impl<T: IsEnabled> Regulator<T> {
+ /// Checks if the regulator is enabled.
+ pub fn is_enabled(&self) -> bool {
+ // SAFETY: Safe as per the type invariants of `Regulator`.
+ unsafe { bindings::regulator_is_enabled(self.inner.as_ptr()) != 0 }
+ }
+}
+
+impl<T: RegulatorState> Drop for Regulator<T> {
+ fn drop(&mut self) {
+ if T::DISABLE_ON_DROP {
+ // SAFETY: By the type invariants, we know that `self` owns a
+ // reference on the enabled refcount, so it is safe to relinquish it
+ // now.
+ unsafe { bindings::regulator_disable(self.inner.as_ptr()) };
+ }
+ // SAFETY: By the type invariants, we know that `self` owns a reference,
+ // so it is safe to relinquish it now.
+ unsafe { bindings::regulator_put(self.inner.as_ptr()) };
+ }
+}
+
+/// A voltage.
+///
+/// This type represents a voltage value in microvolts.
+#[repr(transparent)]
+#[derive(Copy, Clone, PartialEq, Eq)]
+pub struct Voltage(i32);
+
+impl Voltage {
+ /// Creates a new `Voltage` from a value in microvolts.
+ pub fn from_microvolts(uv: i32) -> Self {
+ Self(uv)
+ }
+
+ /// Returns the value of the voltage in microvolts as an [`i32`].
+ pub fn as_microvolts(self) -> i32 {
+ self.0
+ }
+}
--
2.50.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry
2025-07-14 18:52 [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-14 18:52 ` [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
@ 2025-07-14 18:52 ` Daniel Almeida
2025-07-14 21:47 ` Miguel Ojeda
2025-07-14 18:59 ` [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-16 15:23 ` Mark Brown
3 siblings, 1 reply; 7+ messages in thread
From: Daniel Almeida @ 2025-07-14 18:52 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown
Cc: linux-kernel, rust-for-linux, Daniel Almeida
Add this file to the regulator API entry as requested by Mark Brown.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 0c1d245bf7b84f8a78b811e0c9c5a3edc09edc22..e37c0fc523964171ab6a9bc59f155b6bf1ab79e0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26525,6 +26525,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git
F: Documentation/devicetree/bindings/regulator/
F: Documentation/power/regulator/
F: drivers/regulator/
+F: rust/kernel/regulator.rs
F: include/dt-bindings/regulator/
F: include/linux/regulator/
K: regulator_get_optional
--
2.50.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v8 0/2] Add a bare-minimum Regulator abstraction
2025-07-14 18:52 [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-14 18:52 ` [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
2025-07-14 18:52 ` [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry Daniel Almeida
@ 2025-07-14 18:59 ` Daniel Almeida
2025-07-16 15:23 ` Mark Brown
3 siblings, 0 replies; 7+ messages in thread
From: Daniel Almeida @ 2025-07-14 18:59 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown
Cc: linux-kernel, rust-for-linux, Alexandre Courbot
Mark, this looks like a good candidate for merging, how do you want to go about
this?
I believe that this should go through the regulator tree, but I guess it can go
through the Rust tree if you give your acked-by.
-- Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction
2025-07-14 18:52 ` [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
@ 2025-07-14 19:31 ` Alice Ryhl
0 siblings, 0 replies; 7+ messages in thread
From: Alice Ryhl @ 2025-07-14 19:31 UTC (permalink / raw)
To: Daniel Almeida
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown,
linux-kernel, rust-for-linux, Alexandre Courbot
On Mon, Jul 14, 2025 at 8:52 PM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
>
> Add a bare minimum regulator abstraction to be used by Rust drivers.
> This abstraction adds a small subset of the regulator API, which is
> thought to be sufficient for the drivers we have now.
>
> Regulators provide the power needed by many hardware blocks and thus are
> likely to be needed by a lot of drivers.
>
> It was tested on rk3588, where it was used to power up the "mali"
> regulator in order to power up the GPU.
>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry
2025-07-14 18:52 ` [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry Daniel Almeida
@ 2025-07-14 21:47 ` Miguel Ojeda
0 siblings, 0 replies; 7+ messages in thread
From: Miguel Ojeda @ 2025-07-14 21:47 UTC (permalink / raw)
To: Daniel Almeida
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Mark Brown,
linux-kernel, rust-for-linux
On Mon, Jul 14, 2025 at 8:52 PM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
>
> Add this file to the regulator API entry as requested by Mark Brown.
>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Great, thanks Mark!
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 0/2] Add a bare-minimum Regulator abstraction
2025-07-14 18:52 [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
` (2 preceding siblings ...)
2025-07-14 18:59 ` [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
@ 2025-07-16 15:23 ` Mark Brown
3 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2025-07-16 15:23 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Liam Girdwood, Daniel Almeida
Cc: linux-kernel, rust-for-linux, Alexandre Courbot
On Mon, 14 Jul 2025 15:52:03 -0300, Daniel Almeida wrote:
> Changes in v8:
> - Added Alex's r-b
> - Added helpers/regulator.c, since the stubs are declared as inline if
> CONFIG_REGULATOR is not set (Intel bot)
> - Removed unneeded "regulator.enable()" line from docs: it was not needed
> and, ironically, it misused the API by choosing Regulator<Dynamic>
> and then not keeping the enabled count count balenced (Alex)
> - Clarified that the "Enabled" state decreases the enabled refcount when it
> drops (Alex)
> - Renamed "Microvolt" as "Voltage" and introduced
> from_microvolts/as_microvolts (Alex)
> - Fixed the spelling for MAINTAINERS in the second commit (Alex)
> - Link to v7: https://lore.kernel.org/rust-for-linux/20250704-topics-tyr-regulator-v7-0-77bfca2e22dc@collabora.com/
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
Thanks!
[1/2] rust: regulator: add a bare minimum regulator abstraction
commit: 9b614ceada7cb846de1a1c3bb0b29b0a2726ef45
[2/2] MAINTAINERS: add regulator.rs to the regulator API entry
commit: d9f334fca5448907cc47ba8553926f9ba148512f
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-16 15:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 18:52 [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-14 18:52 ` [PATCH v8 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
2025-07-14 19:31 ` Alice Ryhl
2025-07-14 18:52 ` [PATCH v8 2/2] MAINTAINERS: add regulator.rs to the regulator API entry Daniel Almeida
2025-07-14 21:47 ` Miguel Ojeda
2025-07-14 18:59 ` [PATCH v8 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-16 15:23 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).