Linux LED subsystem development
 help / color / mirror / Atom feed
From: Boqun Feng <boqun@kernel.org>
To: Markus Probst <markus.probst@posteo.de>
Cc: "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>,
	"Gary Guo" <gary@garyguo.net>,
	"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´nski" <kwilczynski@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>,
	rust-for-linux@vger.kernel.org, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v26 3/4] rust: leds: Add multicolor classdev abstractions
Date: Fri, 9 Oct 2026 11:52:04 -0700	[thread overview]
Message-ID: <ask31EX01lSL9QJ9@tardis.local> (raw)
In-Reply-To: <20260930-rust_leds-v26-3-83837331020e@posteo.de>

On Wed, Sep 30, 2026 at 01:05:32PM +0000, Markus Probst wrote:
> Implement the abstractions needed for multicolor led class devices,
> including:
> 
> * `led::MultiColor` - the led mode implementation
> 
> * `MultiColorSubLed` - a safe wrapper arround `mc_subled`
> 
> * `led::MultiColorDevice` - a safe wrapper around `led_classdev_mc`
> 
> * `led::DeviceBuilder::build_multicolor` - a function to register a new
>   multicolor led class device
> 
> Signed-off-by: Markus Probst <markus.probst@posteo.de>
> ---
>  rust/bindings/bindings_helper.h |   1 +
>  rust/kernel/led.rs              |  34 ++-
>  rust/kernel/led/multicolor.rs   | 445 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 479 insertions(+), 1 deletion(-)
> 
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> index 4b31aa7f432f..81a03985322a 100644
> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -69,6 +69,7 @@
>  #include <linux/iosys-map.h>
>  #include <linux/jiffies.h>
>  #include <linux/jump_label.h>
> +#include <linux/led-class-multicolor.h>
>  #include <linux/mdio.h>
>  #include <linux/mm.h>
>  #include <linux/miscdevice.h>
> diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs
> index c17f8ef75006..4b66fe41a80c 100644
> --- a/rust/kernel/led.rs
> +++ b/rust/kernel/led.rs
> @@ -30,8 +30,16 @@
>      types::Opaque, //
>  };
>  
> +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)]
> +mod multicolor;
>  mod normal;
>  
> +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)]
> +pub use multicolor::{
> +    MultiColor,
> +    MultiColorDevice,
> +    MultiColorSubLed, //
> +};
>  pub use normal::{
>      Device,
>      Normal, //
> @@ -233,7 +241,24 @@ pub enum Color {
>      Violet = bindings::LED_COLOR_ID_VIOLET,
>      Yellow = bindings::LED_COLOR_ID_YELLOW,
>      Ir = bindings::LED_COLOR_ID_IR,
> +    #[cfg_attr(
> +        CONFIG_LEDS_CLASS_MULTICOLOR,
> +        doc = "Use this color for a [`MultiColor`] led."
> +    )]
> +    #[cfg_attr(
> +        not(CONFIG_LEDS_CLASS_MULTICOLOR),
> +        doc = "Use this color for a `MultiColor` led."
> +    )]
> +    /// If the led supports RGB, use [`Color::Rgb`] instead.
>      Multi = bindings::LED_COLOR_ID_MULTI,
> +    #[cfg_attr(
> +        CONFIG_LEDS_CLASS_MULTICOLOR,
> +        doc = "Use this color for a [`MultiColor`] led with rgb support."
> +    )]
> +    #[cfg_attr(
> +        not(CONFIG_LEDS_CLASS_MULTICOLOR),
> +        doc = "Use this color for a `MultiColor` led with rgb support."
> +    )]
>      Rgb = bindings::LED_COLOR_ID_RGB,
>      Purple = bindings::LED_COLOR_ID_PURPLE,
>      Orange = bindings::LED_COLOR_ID_ORANGE,
> @@ -274,7 +299,14 @@ fn try_from(value: u32) -> core::result::Result<Self, Self::Error> {
>  ///
>  /// Each led mode has its own led class device type with different capabilities.
>  ///
> -/// See [`Normal`].
> +#[cfg_attr(
> +    CONFIG_LEDS_CLASS_MULTICOLOR,
> +    doc = "See [`Normal`] and [`MultiColor`]."
> +)]
> +#[cfg_attr(
> +    not(CONFIG_LEDS_CLASS_MULTICOLOR),
> +    doc = "See [`Normal`] and `MultiColor`."
> +)]
>  pub trait Mode: private::Sealed {
>      /// The class device for the led mode.
>      type Device<'bound, T: LedOps<Mode = Self> + 'bound>: Deref<Target = T>;
> diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor.rs
> new file mode 100644
> index 000000000000..309487bdf38a
> --- /dev/null
> +++ b/rust/kernel/led/multicolor.rs
> @@ -0,0 +1,445 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Led mode for the `struct led_classdev_mc`.
> +//!
> +//! C header: [`include/linux/led-class-multicolor.h`](srctree/include/linux/led-class-multicolor.h)
> +
> +use core::{
> +    cell::UnsafeCell,
> +    num::NonZero,
> +    ptr, //
> +};
> +
> +use crate::types::ScopeGuard;
> +
> +use super::*;
> +
> +/// The led mode for the `struct led_classdev_mc`. Leds with this mode can have multiple colors.
> +pub enum MultiColor {}
> +impl Mode for MultiColor {
> +    type Device<'bound, T: LedOps<Mode = Self> + 'bound> = MultiColorDevice<'bound, T>;
> +}
> +impl private::Sealed for MultiColor {}
> +
> +/// The multicolor sub led info representation.
> +///
> +/// This structure represents the Rust abstraction for a C `struct mc_subled`.
> +#[repr(C)]
> +#[derive(Debug)]
> +#[non_exhaustive]
> +pub struct MultiColorSubLed {
> +    /// The color of the sub led
> +    pub color: Color,
> +    brightness: UnsafeCell<u32>,
> +    intensity: UnsafeCell<u32>,

These should be `Atomic<u32>`, or am I missing something here? Using
`Atomic<u32>` should resolve sashiko's comment on this patch.

Regards,
Boqun

> +    /// The maximum supported intensity value.
> +    ///
> +    /// If None the maximum intensity equals to [`LedOps::MAX_BRIGHTNESS`].
> +    pub max_intensity: Option<NonZero<u32>>,
> +    /// Arbitrary data for the driver to store.
> +    pub channel: u32,
> +}
> +
[...]

  parent reply	other threads:[~2026-10-09 18:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 13:05 [PATCH v26 0/4] rust: leds: Add led classdev abstractions Markus Probst
2026-09-30 13:05 ` [PATCH v26 1/4] rust: leds: Add basic " Markus Probst
2026-09-30 13:18   ` sashiko-bot
2026-09-30 13:05 ` [PATCH v26 2/4] rust: leds: Add Mode trait Markus Probst
2026-09-30 13:10   ` sashiko-bot
2026-09-30 13:05 ` [PATCH v26 3/4] rust: leds: Add multicolor classdev abstractions Markus Probst
2026-09-30 13:17   ` sashiko-bot
2026-10-09 18:52   ` Boqun Feng [this message]
2026-10-09 19:18     ` Markus Probst
2026-10-09 19:34       ` Boqun Feng
2026-10-09 19:59         ` Markus Probst
2026-10-09 20:08           ` Boqun Feng
2026-10-09 22:11             ` leds: KCSAN report Markus Probst
2026-09-30 13:05 ` [PATCH v26 4/4] MAINTAINERS: rust: leds: Add rust abstraction entry Markus Probst
2026-10-08 11:32 ` [PATCH v26 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=ask31EX01lSL9QJ9@tardis.local \
    --to=boqun@kernel.org \
    --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=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=markus.probst@posteo.de \
    --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