rust: leds: add led classdev abstractions
v10 cover rust: leds: add led classdev abstractions
This patch series has previously been contained in
https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
which added a rust written led driver for a microcontroller via i2c.
As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required.
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
The following changes were made:
* add basic led classdev abstractions to register and unregister leds
* add basic led classdev abstractions to register and unregister multicolor leds
Changes since v9:
* add missing periods in documentation
* duplicate led::Device and led::Adapter instead of using a complex trait
* fix imports not using prelude
* adapt to CStr change
* documented led::Color::Multi and led::Color::Rgb
Changes since v8:
* accept Option<ARef<Fwnode>> in led::InitData::fwnode()
* make functions in MultiColorSubLed const
* drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core
Changes since v7:
* adjusted import style
* added classdev parameter to callback functions in LedOps
* implement led::Color
* extend led::InitData with
- initial_brightness
- default_trigger
- default_color
* split generic and normal led classdev abstractions up (see patch 3/4)
* add multicolor led class device abstractions (see patch 4/4)
* added MAINTAINERS entry
Changes since v6:
* fixed typos
* improved documentation
Changes since v5:
* rename IntoBusDevice trait into AsBusDevice
* fix documentation about LedOps::BLOCKING
* removed dependency on i2c bindings
* added AsBusDevice implementation for platform::Device
* removed device::Device fallback implementation
* document that AsBusDevice must not be used by drivers and is intended for bus and class device abstractions only.
Changes since v4:
* add abstraction to convert a device reference to a bus device reference
* require the bus device as parent device and provide it in class device callbacks
* remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions)
* fixed formatting in led::Device::new
* fixed LedOps::BLOCKING did the inverse effect
Changes since v3:
* fixed kunit tests failing because of example in documentation
Changes since v2:
* return Devres on led::Device creation
* replace KBox<T> with T in struct definition
* increment and decrement reference-count of fwnode
* make a device parent mandatory for led classdev creation
* rename led::Handler to led::LedOps
* add optional brightness_get function to led::LedOps
* use #[vtable] instead of const BLINK: bool
* use Opaque::cast_from instead of casting a pointer
* improve documentation
* improve support for older rust versions
* use &Device<Bound> for parent
Changes since v1:
* fixed typos noticed by Onur Özkan
---
Markus Probst (3):
rust: leds: add basic led classdev abstractions
rust: leds: split generic and normal led classdev abstractions up
rust: leds: add multicolor classdev abstractions
MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 384 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 223 +++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 917 insertions(+)
---
base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
change-id: 20251114-rust_leds-a959f7c2f7f9 -----BEGIN PGP SIGNATURE-----
iQJPBAABCAA5FiEEgnQYxPSsWOdyMMRzNHYf+OetQ9IFAmlcaKAbFIAAAAAABAAO bWFudTIsMi41KzEuMTEsMiwyAAoJEDR2H/jnrUPSBEUP/33pKBKvhSWu8N/AOXvw umj6JGGpUjRxhrcsuD7S1J4sdGrr2CHg8zCD6OYKlmCY5mEi/7tS9MtdZHnYAv35 etsYgGpJZOn0yb+anoE2jP2ks0nNUSR3ZN4he+BizrKr0jjeljrgezyAV9vvb6to sQDSMSnsJEcORBtIUZn8ONTJb2lbmKzgnrGc1xS7oXiMOO2mEt4A3m6zPuT0kzzd l2Wtu2N0Sc28TWJHC3c10h6o0ZSUQrduNcFjHe/KmCXTJLV0ozdmKCMiyNvzYbEK 0/ch4T8SFVNu3qAJIX2H4ceWXnl3QSaFrcv5FRFA1SRySF6sNa3G2Dssu8CX9HrW yqpX0USXDXPAL1p+nnsKwAF4LE0xr+hEicaRZhezQGxkm7DsPmJrwAtRRvmog5OS a/0C2H/j6h/Zm7Y43ttME4krkTyx3ZdN1mVLZPOo9ednUzU4OYaMruwADr2jsLNH DiVBcgjIbuWpDAFx0+ApEHmfzpkAlSZz4MYE+Ny0vrXbUyvipx+rLuQJvuFI8wp0 24T9/femehee5b4hzkhnCdZ06JqnO8yVSseMVHTWrjyYtsUdkm75kWdn0ixRJrxR MgsKnEjIOAQLQC1i174+FBi/QbTz4TeTKKEYaYlWX0TQ9kyCDvjb9aQzpg9SjQGq EWc8LddS+CRAAd3V3DrLSOTh
=zjT9
-----END PGP SIGNATURE-----
Signature · 1 line
Markus Probst <[email protected]>
PATCH RESEND v10 1/3 rust: leds: add basic led classdev abstractions
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::InitData - data set for the led class device
* led::Device - a safe wrapper around led_classdev
--- MAINTAINERS | 7 + rust/kernel/led.rs | 450 +++++++++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 458 insertions(+)
MAINTAINERS +7 -0
@@ -14269,6 +14269,13 @@ F: drivers/leds/ F: include/dt-bindings/leds/ F: include/linux/leds.h +LED SUBSYSTEM [RUST] +M: Markus Probst <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: rust/kernel/led.rs + LEGO MINDSTORMS EV3 R: David Lechner <[email protected]> S: Maintained
rust/kernel/led.rs new file +450 -0
450 lines not on this page · raw message
rust/kernel/lib.rs +1 -0
@@ -108,6 +108,7 @@pub mod jump_label;#[cfg( CONFIG_KUNIT )] pub mod kunit; +pub mod led;pub mod list;pub mod maple_tree;pub mod miscdevice;
Signature · 1 line
2.52.0
PATCH RESEND v10 2/3 rust: leds: split generic and normal led classdev abstractions up
In reply to Markus ProbstMove code specific to normal led class devices into a separate file and introduce the led::Mode trait to allow for other types of led class devices in led::LedOps.
--- MAINTAINERS | 1 + rust/kernel/led.rs | 242 ++++++---------------------------------------- rust/kernel/led/normal.rs | 223 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 210 deletions(-)
MAINTAINERS +1 -0
@@ -14275,6 +14275,7 @@ L: [email protected] L: [email protected] S: Maintained F: rust/kernel/led.rs +F: rust/kernel/led/ LEGO MINDSTORMS EV3 R: David Lechner <[email protected]>
rust/kernel/led.rs +32 -210
283 lines not on this page · raw message
rust/kernel/led/normal.rs new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH RESEND v10 3/3 rust: leds: add multicolor classdev abstractions
In reply to Markus ProbstImplement 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
--- rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 30 +++- rust/kernel/led/multicolor.rs | 384 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 1 deletion(-)
rust/bindings/bindings_helper.h +1 -0
@@ -62,6 +62,7 @@#include <linux/ioport.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>
rust/kernel/led.rs +29 -1
@@ -33,8 +33,12 @@ }, // }; +#[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 };/// The led init data representation.
@@ -229,7 +233,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,
@@ -261,7 +282,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 <T :LedOps <Mode =Self >>;
rust/kernel/led/multicolor.rs new file +384 -0
384 lines not on this page · raw message
Signature · 1 line
2.52.0