From: Markus Probst <markus.probst@posteo.de>
To: "Gary Guo" <gary@garyguo.net>, "Lee Jones" <lee@kernel.org>,
"Pavel Machek" <pavel@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Dave Ertman" <david.m.ertman@intel.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Ira Weiny" <iweiny@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-leds@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v24 1/4] rust: leds: add basic led classdev abstractions
Date: Fri, 04 Sep 2026 13:15:37 +0000 [thread overview]
Message-ID: <612e01853459f0eb87fe78b7f5fdb73e22cd1776.camel@posteo.de> (raw)
In-Reply-To: <DL6JWHOEG91Y.1BKBUP653Z5D@garyguo.net>
[-- Attachment #1: Type: text/plain, Size: 4892 bytes --]
On Fri, 2026-09-04 at 14:03 +0100, Gary Guo wrote:
> On Thu Sep 3, 2026 at 12:01 AM BST, Markus Probst wrote:
> > Implement the core abstractions needed for led class devices, including:
> >
> > * `led::LedOps` - the trait for handling leds, including
> > `brightness_set`, `brightness_get` and `blink_set`
> >
> > * `led::DeviceBuilder` - the builder for the led class device
> >
> > * `led::Device` - a safe wrapper around `led_classdev`
> >
> > Signed-off-by: Markus Probst <markus.probst@posteo.de>
> > ---
> > rust/kernel/led.rs | 288 ++++++++++++++++++++++++++++++++++++++++++++++
> > rust/kernel/led/normal.rs | 230 ++++++++++++++++++++++++++++++++++++
> > rust/kernel/lib.rs | 1 +
> > 3 files changed, 519 insertions(+)
> >
> > [snip]
> >
> > +/// Trait defining the operations for a LED driver.
> > +///
> > +/// # Examples
> > +/// ```
> > +/// use kernel::{
> > +/// device,
> > +/// devres::Devres,
> > +/// led,
> > +/// macros::vtable,
> > +/// platform,
> > +/// prelude::*, //
> > +/// };
> > +///
> > +/// struct MyLedOps;
> > +///
> > +///
> > +/// #[vtable]
> > +/// impl led::LedOps for MyLedOps {
> > +/// type Bus = platform::Device<device::Bound>;
> > +/// const BLOCKING: bool = false;
> > +/// const MAX_BRIGHTNESS: u32 = 255;
> > +///
> > +/// fn brightness_set<'bound>(
> > +/// &self,
> > +/// _dev: &'bound platform::Device<device::Bound>,
> > +/// _classdev: &led::Device<'bound, Self>,
> > +/// _brightness: u32
> > +/// ) -> Result<()> {
> > +/// // Set the brightness for the led here
> > +/// Ok(())
> > +/// }
> > +/// }
> > +/// ```
> > +/// Led drivers must implement this trait in order to register and handle a [`Device`].
> > +#[vtable]
> > +pub trait LedOps: Send + Sync + Sized {
> > + /// The bus device required by the implementation.
> > + #[allow(private_bounds)]
> > + type Bus: AsBusDevice<Bound>;
>
> Does LED class device has no private data that driver can use? This can be
> either a private pointer or extra allocation living at the end of the classdev
> struct.
On every callback `&self` is passed to the LedOps, which could be
considered the leds private data. It is currently stored in front of
the `led_classdev` struct.
>
> It's usually a antipattern to get the bus device directly, especially that in
> Rust we do not allow anything other than callbacks to access data on bus
> devices.
>
> Instead, the class device registration should provide a data initializer, and
> the callbacks would receive a pointer to the data instead. In cases that a
> device resource has to be referenced, it should be kept inside the private data
> by the driver themselves.
It should be possible to store a pointer to the bus device directly on
this data, thus I can remove it.
If I think about it, I could add a `led::Device::drvdata` function, so
it could be accessed from the drivers private data. Sync is a
requirement anyway.
Thanks
- Markus Probst
>
> Best,
> Gary
>
> > +
> > + /// If set true, [`LedOps::brightness_set`] and [`LedOps::blink_set`] must perform the
> > + /// operation immediately. If set false, they must not sleep.
> > + const BLOCKING: bool;
> > + /// The max brightness level.
> > + const MAX_BRIGHTNESS: u32;
> > +
> > + /// Sets the brightness level.
> > + ///
> > + /// See also [`LedOps::BLOCKING`].
> > + fn brightness_set<'bound>(
> > + &self,
> > + dev: &'bound Self::Bus,
> > + classdev: &Device<'bound, Self>,
> > + brightness: u32,
> > + ) -> Result<()>;
> > +
> > + /// Gets the current brightness level.
> > + fn brightness_get<'bound>(
> > + &self,
> > + dev: &'bound Self::Bus,
> > + classdev: &Device<'bound, Self>,
> > + ) -> Result<u32> {
> > + let _ = (dev, classdev);
> > + build_error!(VTABLE_DEFAULT_ERROR)
> > + }
> > +
> > + /// Activates hardware accelerated blinking.
> > + ///
> > + /// delays are in milliseconds. If both are zero, a sensible default should be chosen.
> > + /// The caller should adjust the timings in that case and if it can't match the values
> > + /// specified exactly. Setting the brightness to 0 will disable the hardware accelerated
> > + /// blinking.
> > + ///
> > + /// See also [`LedOps::BLOCKING`].
> > + fn blink_set<'bound>(
> > + &self,
> > + dev: &'bound Self::Bus,
> > + classdev: &Device<'bound, Self>,
> > + delay_on: &mut usize,
> > + delay_off: &mut usize,
> > + ) -> Result<()> {
> > + let _ = (dev, classdev, delay_on, delay_off);
> > + build_error!(VTABLE_DEFAULT_ERROR)
> > + }
> > +}
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
next prev parent reply other threads:[~2026-09-04 13:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 23:01 [PATCH v24 0/4] rust: leds: add led classdev abstractions Markus Probst
2026-09-02 23:01 ` [PATCH v24 1/4] rust: leds: add basic " Markus Probst
2026-09-02 23:17 ` sashiko-bot
2026-09-04 13:03 ` Gary Guo
2026-09-04 13:15 ` Markus Probst [this message]
2026-09-04 13:32 ` Gary Guo
2026-09-04 14:04 ` Markus Probst
2026-09-02 23:01 ` [PATCH v24 2/4] rust: leds: add Mode trait Markus Probst
2026-09-02 23:08 ` sashiko-bot
2026-09-02 23:01 ` [PATCH v24 3/4] rust: leds: add multicolor classdev abstractions Markus Probst
2026-09-02 23:15 ` sashiko-bot
2026-09-02 23:01 ` [PATCH v24 4/4] MAINTAINERS: rust: leds: Add rust abstraction entry Markus Probst
2026-09-02 23:35 ` [PATCH v24 0/4] rust: leds: add led classdev abstractions Markus Probst
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=612e01853459f0eb87fe78b7f5fdb73e22cd1776.camel@posteo.de \
--to=markus.probst@posteo.de \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=iweiny@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=lee@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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