From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 841B64F5E19 for ; Fri, 9 Oct 2026 18:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791571929; cv=none; b=pisHiONOTopULPzsJejqTyIb59JbxfLUwBn6q0REIf6U3SiszOoGRdA1v3HIKOhrr4g6ZH0IuZBwr1JxCisKYQczwEYVm68U29vOuxA7GSDWugMmgBYW9t0eyxpZfQ82QlkEX2fzoZdRJjB0j3uP16n7Dn2oYbPpHMvTFQ7Unrs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791571929; c=relaxed/simple; bh=CGsSouXbLNX0cRECIXyTMJVcjhnhpLk543IpFYJZEVY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FLvokrjbZuutv8dNON63mIgk+b9D51NkXktKQ3LnS1WJsgdKgHvYj5cexEoJJ1HJZ+oQy8iNBE4EtLr0nly2/ffVpC5R6gZMCz//b8jn/4MT1Q2y1YfnutN5RQ7pt07etFQnK8yh58lV0U01WdLG3Jdu77of+LYu54OK84ugRdo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pw9HgPss; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pw9HgPss" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C02B1F00893; Fri, 9 Oct 2026 18:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791571928; bh=LEA3p4YPwgQaoGr6H4RcIZE6g5/a+camPePCa7aAZ78=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Pw9HgPsspP48wV7BVNpVmRR56d68n8WQ55lK/S3rR6goaqLV08BeVhhqBhYE7n6tp appP3/ALXjR1KG/ULAgWLLR9NQenFm5b6Ze8sMy/GugKvMmNj/2fOX/OljDr9B2QVB Jplk8VI14fISzg5nq3mZTl2lXL1zaJ7Qq1ZeIbWtSOvILMWyzXqB+0BUVduOXt3EGQ gR3BQDw0CQQYTxyEbLGZKB1TYLuHfBuNrQoFDky6c85jfpvVKawJ3q0NXmSk7a/BU9 y3b0IqpCIaWgbKiMxY5B3AX9ZeicuWsyliUBseviZNO+PWrf45Z2HGAHbPeozTiIwd jbntiXNVq9K3Q== Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfauth.phl.internal (Postfix) with ESMTP id A995AF40066; Fri, 9 Oct 2026 14:52:06 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 09 Oct 2026 14:52:06 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFpqUGWu6p6hPoGOpiRsskvvc3k8f41nkcj5ENIrSq8Ynb4Aw0OOXTw3K1Iw8tu4C 7lx4kE/mx9ryewefxm5meTOcI98ZqN43LAKkq+qxYAvVZMNcNyhP5r0R5eaSOYgyLEa3jS 7UZPBh/0wfBQAru08UCKTVkcE+51cRBwMXzpHAeDnwYX2KjWSkta1Bz3pXWehgtTAgr7Oa g5fQNzdabEK1H9Es7QQqDLZxPGqQvuo2iI25vtxadjnPWMJxyaBDPOOz8a6rj0pRDgWdxR wNIfOW9tknd7//uzN6loAaWKgztgK4tvWdkoXNIbJhIgxvVj+gKAgDpBhWwkwMQQTR3SST qMvq2FmDdD3ku0453iDzQi17qDJuIB7KGcrjQ5IxtHZTSyaGyFbFQW9pNIPGN0GW5pWRno hqWWzNBtg08SN+D78yHRoxIGS2iBLr1otHsR3pw/ZDzz00AkxuNWsDTfhLSIubq6VCJdHC aSSo2KZBlpgtxDCMDMQ68XVKyJnwobxl4BEhccOPDOoYYiXL/ZEH/jD9TPbUADZT2e7RfI awnevonEjrhYf+WSExUKeElu+AlU3jU2Fb6lPfHtsVL3UVL6GblRB7As3/zIG6WLe56CFS S1VqA7aR8+9JPHwY3B9mSO4Fjm9gJOYlilPNHoffVNxt+JkXSVQpxQs/JJnw X-ME-Proxy: Feedback-ID: i8dbe485b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Oct 2026 14:52:05 -0400 (EDT) Date: Fri, 9 Oct 2026 11:52:04 -0700 From: Boqun Feng To: Markus Probst Cc: Lee Jones , Pavel Machek , Greg Kroah-Hartman , Dave Ertman , Leon Romanovsky , Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , "Rafael J. Wysocki" , Bjorn Helgaas , Krzysztof =?iso-8859-1?Q?Wilczy=B4nski?= , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , Onur =?iso-8859-1?Q?=D6zkan?= , Ira Weiny , 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 Message-ID: References: <20260930-rust_leds-v26-0-83837331020e@posteo.de> <20260930-rust_leds-v26-3-83837331020e@posteo.de> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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 > #include > #include > +#include > #include > #include > #include > 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 { > /// > /// 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 + 'bound>: Deref; > 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 + '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, > + intensity: UnsafeCell, These should be `Atomic`, or am I missing something here? Using `Atomic` 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>, > + /// Arbitrary data for the driver to store. > + pub channel: u32, > +} > + [...]