rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: Alice Ryhl <aliceryhl@google.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>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Boris Brezillon" <boris.brezillon@collabora.com>,
	"Sebastian Reichel" <sebastian.reichel@collabora.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v6 1/2] rust: regulator: add a bare minimum regulator abstraction
Date: Wed, 2 Jul 2025 10:03:08 -0300	[thread overview]
Message-ID: <1DFECD1D-9445-4D59-A727-37C527B5DFF5@collabora.com> (raw)
In-Reply-To: <CAH5fLgj_eKuo=E7HPgmd1bJNfidGUS37MM1QqRaQ_MJ2kTgCmg@mail.gmail.com>

Hi Alice,

> On 2 Jul 2025, at 07:35, Alice Ryhl <aliceryhl@google.com> wrote:
> 
> On Fri, Jun 27, 2025 at 7:11 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.
>> 
>> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
> 
> Overall looks reasonable to me.
> 
>> +/// 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 {}
> 
> Naming-wise, it's a bit weird that IsEnabled applies to everything
> *but* enabled. And also, the is_enabled() method should probably exist
> for only Dynamic anyway?

I think it's the other way around? Enabled doesn't need this impl precisely
because of the Enabled token. IOW:

Regulator<Enabled>::is_enabled() doesn't make sense.

>  And also, the is_enabled() method should probably exist for only Dynamic anyway?

Also no, because Regulator<Disabled> isn't necessarily disabled. It just was
not enabled by us, but might have been enabled by somebody else in the system.


[…]

> 
> 
>> +impl<T: RegulatorState + 'static> Drop for Regulator<T> {
>> +    fn drop(&mut self) {
>> +        if core::any::TypeId::of::<T>() == core::any::TypeId::of::<Enabled>() {
> 
> I would avoid this kind of logic. Instead, you can add an
> `disable_on_drop()` method or constant to the trait and check it here.
> 
> Alice
> 

Can you expand on this?

— Daniel


  reply	other threads:[~2025-07-02 13:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 17:11 [PATCH v6 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-06-27 17:11 ` [PATCH v6 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
2025-06-29 13:10   ` kernel test robot
2025-07-02 10:35   ` Alice Ryhl
2025-07-02 13:03     ` Daniel Almeida [this message]
2025-07-02 13:12       ` Alice Ryhl
2025-07-02 13:14         ` Daniel Almeida
2025-06-27 17:11 ` [PATCH v6 2/2] MAINAINTERS: add regulator.rs to the regulator API entry Daniel Almeida
2025-07-01 15:28 ` [PATCH v6 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-01 15:34   ` Mark Brown
2025-07-01 16:09     ` Daniel Almeida
2025-07-01 18:22       ` Miguel Ojeda

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=1DFECD1D-9445-4D59-A727-37C527B5DFF5@collabora.com \
    --to=daniel.almeida@collabora.com \
    --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=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).