From: Mark Brown <broonie@kernel.org>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Boris Brezillon" <boris.brezillon@collabora.com>,
"Sebastian Reichel" <sebastian.reichel@collabora.com>,
lgirdwood@gmail.com, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH RESEND v2] rust: regulator: add a bare minimum regulator abstraction
Date: Wed, 26 Mar 2025 18:56:54 +0000 [thread overview]
Message-ID: <a98eb789-4c49-4607-ad15-76e260888d64@sirena.org.uk> (raw)
In-Reply-To: <20250326-topics-tyr-regulator-v2-1-780b0362f70d@collabora.com>
[-- Attachment #1: Type: text/plain, Size: 2558 bytes --]
On Wed, Mar 26, 2025 at 03:39:33PM -0300, Daniel Almeida wrote:
This is flagged as a resend but appears to be the first copy I've
seen...
> 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 are modeled with two types: [`Regulator`] and
> +//! [`EnabledRegulator`].
It would be helpful to see what the client code actually looks like
here.
> + /// Enables the regulator.
> + pub fn enable(self) -> Result<EnabledRegulator> {
> + // SAFETY: Safe as per the type invariants of `Regulator`.
> + let res = to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) });
> + res.map(|()| EnabledRegulator { inner: self })
> + }
I assume this map does soemthing to report errors?
> +impl EnabledRegulator {
> + /// Disables the regulator.
> + pub fn disable(self) -> Result<Regulator> {
> + // Keep the count on `regulator_get()`.
> + let regulator = ManuallyDrop::new(self);
> +
> + // SAFETY: Safe as per the type invariants of `Self`.
> + let res = to_result(unsafe { bindings::regulator_disable(regulator.as_ptr()) });
> +
> + res.map(|()| Regulator {
> + inner: regulator.inner.inner,
> + })
> + }
This looks like user code could manually call it which feels like asking
for trouble?
> + /// Sets the voltage for the regulator.
> + pub fn set_voltage(&self, min_uv: Microvolt, max_uv: Microvolt) -> Result {
> + // SAFETY: Safe as per the type invariants of `Regulator`.
> + to_result(unsafe { bindings::regulator_set_voltage(self.as_ptr(), min_uv.0, max_uv.0) })
> + }
set_voltage() is only implemented for enabled regulators. It is
reasonable for a driver to want to set the voltage for a regulator prior
to enabling it in order to ensure that the device powers up cleanly,
there may be different requirements for power on from on and idle so the
constraints may not be enough to ensure that a device can power on
cleanly.
> + /// Gets the current voltage of the regulator.
> + pub fn get_voltage(&self) -> Result<Microvolt> {
> + // SAFETY: Safe as per the type invariants of `Regulator`.
> + let voltage = unsafe { bindings::regulator_get_voltage(self.as_ptr()) };
> + if voltage < 0 {
> + Err(Error::from_errno(voltage))
> + } else {
> + Ok(Microvolt(voltage))
> + }
> + }
Same issue here.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-03-26 18:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 18:39 Daniel Almeida
2025-03-26 18:56 ` Mark Brown [this message]
2025-03-26 19:49 ` Daniel Almeida
2025-03-27 11:32 ` Mark Brown
2025-03-27 11:36 ` Maud Spierings
2025-03-27 11:42 ` Mark Brown
2025-03-27 11:46 ` Daniel Almeida
2025-03-27 11:50 ` Danilo Krummrich
2025-03-27 12:06 ` Daniel Almeida
2025-03-27 13:46 ` Sebastian Reichel
2025-03-27 15:06 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a98eb789-4c49-4607-ad15-76e260888d64@sirena.org.uk \
--to=broonie@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sebastian.reichel@collabora.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®