|
|
Log in / Subscribe / Register

rust: leds: add led classdev abstractions

From:  Markus Probst <markus.probst-AT-posteo.de>
To:  Greg Kroah-Hartman <gregkh-AT-linuxfoundation.org>, Miguel Ojeda <ojeda-AT-kernel.org>, Alex Gaynor <alex.gaynor-AT-gmail.com>, Danilo Krummrich <dakr-AT-kernel.org>, "Rafael J. Wysocki" <rafael-AT-kernel.org>, Lee Jones <lee-AT-kernel.org>, Pavel Machek <pavel-AT-kernel.org>
Subject:  [PATCH v6 0/2] rust: leds: add led classdev abstractions
Date:  Thu, 23 Oct 2025 17:28:15 +0000
Message-ID:  <20251023172803.730677-1-markus.probst@posteo.de>
Cc:  Dave Ertman <david.m.ertman-AT-intel.com>, Ira Weiny <ira.weiny-AT-intel.com>, Leon Romanovsky <leon-AT-kernel.org>, Boqun Feng <boqun.feng-AT-gmail.com>, Gary Guo <gary-AT-garyguo.net>, bjorn3_gh-AT-protonmail.com, Benno Lossin <lossin-AT-kernel.org>, Andreas Hindborg <a.hindborg-AT-kernel.org>, Alice Ryhl <aliceryhl-AT-google.com>, Trevor Gross <tmgross-AT-umich.edu>, Bjorn Helgaas <bhelgaas-AT-google.com>, Krzysztof Wilczyński <kwilczynski-AT-kernel.org>, Markus Probst <markus.probst-AT-posteo.de>, rust-for-linux-AT-vger.kernel.org, linux-leds-AT-vger.kernel.org, linux-pci-AT-vger.kernel.org, linux-kernel-AT-vger.kernel.org
Archive-link:  Article

This patch series has previously been contained in
https://lore.kernel.org/rust-for-linux/20251008181027.662...
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/DDDS2V0V2NVJ.16ZKX...

The following changes were made:
* add abstraction to convert a device reference to a bus device
  reference for use in class device callbacks

* add basic led classdev abstractions to register and unregister leds

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 (2):
  rust: Add trait to convert a device reference to a bus device
    reference
  rust: leds: add basic led classdev abstractions

 rust/kernel/auxiliary.rs |   7 +
 rust/kernel/device.rs    |  30 ++++
 rust/kernel/led.rs       | 375 +++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs       |   1 +
 rust/kernel/pci.rs       |   7 +
 rust/kernel/platform.rs  |   7 +
 rust/kernel/usb.rs       |   6 +
 7 files changed, 433 insertions(+)
 create mode 100644 rust/kernel/led.rs

-- 
2.51.0




Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds