* [PATCH 1/4] platform/x86: clevo-laptop: add minimal WMI driver skeleton and Kbuild plumbing
2026-11-22 4:35 [PATCH 0/4] platform/x86: clevo-laptop: add initial Rust driver for keyboard backlight Nick Dowsett via B4 Relay
@ 2026-11-22 4:35 ` Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 2/4] platform/x86: clevo-laptop: add EC WMI query interface and BIOS feature check Nick Dowsett via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Nick Dowsett via B4 Relay @ 2026-11-22 4:35 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: Armin Wolf, Werner Sembach, linux-kernel, platform-driver-x86,
rust-for-linux, Nick Dowsett
From: Nick Dowsett <nick42d@gmail.com>
- Add `drivers/platform/x86/clevo-laptop.rs` with module implementation,
DMI board check, and Driver registration.
- Add Kconfig and MAINTAINERS entries and Makefile wiring.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
MAINTAINERS | 6 +++
drivers/platform/x86/Kconfig | 17 +++++++++
drivers/platform/x86/Makefile | 3 ++
drivers/platform/x86/clevo-laptop.rs | 72 ++++++++++++++++++++++++++++++++++++
4 files changed, 98 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb2b8..1130c293e84d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6566,6 +6566,12 @@ F: scripts/Makefile.clang
F: scripts/clang-tools/
K: \b(?i:clang|llvm)\b
+CLEVO LAPTOP DRIVER
+M: Nick Dowsett <nick42d@gmail.com>
+L: platform-driver-x86@vger.kernel.org
+S: Maintained
+F: drivers/platform/x86/clevo-laptop.rs
+
CLK API
M: Russell King <linux@armlinux.org.uk>
L: linux-clk@vger.kernel.org
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9ce384e0475e..18aa4550c9f4 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -1059,6 +1059,23 @@ config OXP_EC
source "drivers/platform/x86/tuxedo/Kconfig"
+config CLEVO_LAPTOP
+ tristate "Clevo Laptop Platform Driver"
+ depends on RUST
+ depends on ACPI_WMI=y
+ depends on DMI
+ depends on LEDS_CLASS
+ help
+ This driver provides platform support for Clevo barebones and
+ rebranded laptops (Tuxedo, Metabox, Sager, XMG, etc.).
+ Currently only Clevo NLx0AU boards (e.g. Metabox Edge NL57AU)
+ with a 5-step white keyboard backlight are supported over WMI.
+ It is intended to be extended with additional Clevo models and
+ EC features over time.
+
+ To compile this driver as a module, choose M here: the module
+ will be called clevo-laptop.
+
endif # X86_PLATFORM_DEVICES
config P2SB
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 229057234d00..070af05a2064 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -158,6 +158,9 @@ obj-$(CONFIG_SILICOM_PLATFORM) += silicom-platform.o
# TUXEDO
obj-y += tuxedo/
+# Clevo
+obj-$(CONFIG_CLEVO_LAPTOP) += clevo-laptop.o
+
# Winmate
obj-$(CONFIG_WINMATE_FM07_KEYS) += winmate-fm07-keys.o
diff --git a/drivers/platform/x86/clevo-laptop.rs b/drivers/platform/x86/clevo-laptop.rs
new file mode 100644
index 000000000000..1d862c57b3fe
--- /dev/null
+++ b/drivers/platform/x86/clevo-laptop.rs
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Clevo Laptop Driver.
+//!
+//! Currently supports only the 5-step white keyboard backlight on Clevo
+//! NLx0AU boards (e.g., Metabox Edge NL57AU).
+//!
+//! Copyright (C) 2026 Nick Dowsett <nick42d@gmail.com>.
+//!
+//! Inspired by Tuxedo Computers' drivers.
+
+use kernel::{
+ device,
+ dmi,
+ prelude::*,
+ wmi, //
+};
+
+/// # Note
+///
+/// This GUID is non-unique (shared by Uniwill for example) and cannot be trusted
+/// to uniquely identify a Clevo device.
+const CLEVO_WMI_METHOD_GUID: &CStr = c"ABBC0F6D-8EA1-11D1-00A0-C90629100000";
+/// DMI board name allowlist, restricted to tested boards since the WMI GUID is not
+/// unique.
+const SUPPORTED_BOARDS: &[&CStr] = &[c"NLx0AU"];
+
+module! {
+ type: ClevoLaptopModule,
+ name: "clevo-laptop",
+ authors: ["Nick Dowsett <nick42d@gmail.com>"],
+ description: "Clevo Laptop Driver (Keyboard Backlight)",
+ license: "GPL",
+}
+
+/// RAII guard for Clevo Laptop Module holding all subsystem drivers e.g WMI.
+#[pin_data]
+struct ClevoLaptopModule {
+ #[pin]
+ _wmi_driver: wmi::Registration<WmiDriver>,
+}
+
+impl kernel::InPlaceModule for ClevoLaptopModule {
+ fn init(module: &'static ThisModule) -> impl PinInit<Self, Error> {
+ pin_init::pin_init_scope(move || {
+ if dmi::get_system_info(dmi::Field::BoardName)
+ .is_none_or(|board| !SUPPORTED_BOARDS.contains(&board))
+ {
+ return Err(ENODEV);
+ }
+ Ok(try_pin_init!(Self {
+ _wmi_driver <- wmi::Registration::new(c"clevo-laptop", module),
+ }))
+ })
+ }
+}
+
+/// RAII guard for Clevo WMI driver holding all subsystem devices e.g LED device.
+#[pin_data]
+struct WmiDriver {}
+
+kernel::wmi_device_table!(WMI_TABLE, [wmi::DeviceId::new(CLEVO_WMI_METHOD_GUID)]);
+
+impl wmi::Driver for WmiDriver {
+ type Data<'bound> = WmiDriver;
+ const ID_TABLE: wmi::IdTable = &WMI_TABLE;
+ fn probe<'bound>(
+ _dev: &'bound wmi::Device<device::Core<'_>>,
+ ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
+ try_pin_init!(WmiDriver {})
+ }
+}
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/4] platform/x86: clevo-laptop: add EC WMI query interface and BIOS feature check
2026-11-22 4:35 [PATCH 0/4] platform/x86: clevo-laptop: add initial Rust driver for keyboard backlight Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 1/4] platform/x86: clevo-laptop: add minimal WMI driver skeleton and Kbuild plumbing Nick Dowsett via B4 Relay
@ 2026-11-22 4:35 ` Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 3/4] platform/x86: clevo-laptop: probe keyboard backlight type and detect 5-step white backlight Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 4/4] platform/x86: clevo-laptop: register 5-step white keyboard backlight LED device Nick Dowsett via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Nick Dowsett via B4 Relay @ 2026-11-22 4:35 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: Armin Wolf, Werner Sembach, linux-kernel, platform-driver-x86,
rust-for-linux, Nick Dowsett
From: Nick Dowsett <nick42d@gmail.com>
- Add `EcQuery` trait and implement `EcInterface` for sending commands to
the Clevo EC over WMI.
- Add `GetBiosFeatures1` query to verify the EC responds during probe.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
drivers/platform/x86/clevo-laptop.rs | 104 ++++++++++++++++++++++++++++++++++-
1 file changed, 102 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/clevo-laptop.rs b/drivers/platform/x86/clevo-laptop.rs
index 1d862c57b3fe..289b30c478ec 100644
--- a/drivers/platform/x86/clevo-laptop.rs
+++ b/drivers/platform/x86/clevo-laptop.rs
@@ -24,6 +24,8 @@
/// DMI board name allowlist, restricted to tested boards since the WMI GUID is not
/// unique.
const SUPPORTED_BOARDS: &[&CStr] = &[c"NLx0AU"];
+const CLEVO_EC_CMD_GET_BIOS_FEATURES_1: u8 = 0x52;
+const CLEVO_EC_WMI_INSTANCE: u8 = 0;
module! {
type: ClevoLaptopModule,
@@ -33,6 +35,21 @@
license: "GPL",
}
+/// Represents a query that can run on the Clevo Embedded Controller (EC).
+///
+/// # Endianness note
+/// Clevo EC sends and receives little endian data.
+/// As this is a `platform/x86` driver, no conversion is required.
+trait EcQuery {
+ type Output;
+ /// EC method code.
+ fn cmd(&self) -> u8;
+ /// EC method args.
+ fn args(&self) -> EcMethodArgs;
+ /// Each command must know how to deserialize itself from the raw EC output.
+ fn deserialize_output(output: &[u8]) -> Result<Self::Output>;
+}
+
/// RAII guard for Clevo Laptop Module holding all subsystem drivers e.g WMI.
#[pin_data]
struct ClevoLaptopModule {
@@ -65,8 +82,91 @@ impl wmi::Driver for WmiDriver {
type Data<'bound> = WmiDriver;
const ID_TABLE: wmi::IdTable = &WMI_TABLE;
fn probe<'bound>(
- _dev: &'bound wmi::Device<device::Core<'_>>,
+ dev: &'bound wmi::Device<device::Core<'_>>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
- try_pin_init!(WmiDriver {})
+ pin_init::pin_init_scope(move || {
+ let backend = EcInterface::Wmi(dev);
+
+ backend.query(GetBiosFeatures1).map_err(|_| ENODEV)?;
+
+ Ok(try_pin_init!(WmiDriver {}))
+ })
+ }
+}
+
+/// Interface to Clevo Embedded Controller.
+enum EcInterface<'a> {
+ Wmi(&'a wmi::Device<device::Bound>),
+}
+impl<'a> EcInterface<'a> {
+ /// Send a query to the EC, receiving a response.
+ fn query<Q>(&self, query: Q) -> Result<Q::Output>
+ where
+ Q: EcQuery + core::fmt::Debug,
+ Q::Output: core::fmt::Debug,
+ {
+ let cmd = query.cmd();
+ let arg = query.args();
+
+ match self {
+ Self::Wmi(wdev) => {
+ dev_dbg!(
+ wdev.as_ref(),
+ "ec cmd {query:?} method_id 0x{cmd:02x} arg {arg:x?}\n"
+ );
+ let buf = wdev.invoke_method(
+ CLEVO_EC_WMI_INSTANCE,
+ cmd.into(),
+ arg.as_bytes(),
+ core::mem::size_of::<Q::Output>(),
+ )?;
+
+ let res = Q::deserialize_output(&buf)?;
+ dev_dbg!(wdev.as_ref(), "ec cmd {query:?} -> {res:?}\n");
+ Ok(res)
+ }
+ }
}
}
+
+/// Args for a command sent to the EC.
+#[derive(Debug)]
+enum EcMethodArgs {
+ Scalar(u32),
+}
+impl EcMethodArgs {
+ /// Convert to the type expected by the EC.
+ fn as_bytes(&self) -> &[u8] {
+ match self {
+ // Clevo EC expects little-endian integers; x86 is always little-endian.
+ Self::Scalar(val) => val.as_bytes(),
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+struct GetBiosFeatures1;
+
+impl EcQuery for GetBiosFeatures1 {
+ type Output = BiosFeatures1;
+ fn cmd(&self) -> u8 {
+ CLEVO_EC_CMD_GET_BIOS_FEATURES_1
+ }
+ fn args(&self) -> EcMethodArgs {
+ EcMethodArgs::Scalar(0)
+ }
+ fn deserialize_output(output: &[u8]) -> Result<Self::Output> {
+ let (feat, _) = BiosFeatures1::read_from_prefix(output).map_err(|_| ENODATA)?;
+ if feat == BiosFeatures1::INVALID {
+ return Err(ENODEV);
+ }
+ Ok(feat)
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
+struct BiosFeatures1(u32);
+
+impl BiosFeatures1 {
+ const INVALID: Self = Self(0xFFFF_FFFF);
+}
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] platform/x86: clevo-laptop: probe keyboard backlight type and detect 5-step white backlight
2026-11-22 4:35 [PATCH 0/4] platform/x86: clevo-laptop: add initial Rust driver for keyboard backlight Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 1/4] platform/x86: clevo-laptop: add minimal WMI driver skeleton and Kbuild plumbing Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 2/4] platform/x86: clevo-laptop: add EC WMI query interface and BIOS feature check Nick Dowsett via B4 Relay
@ 2026-11-22 4:35 ` Nick Dowsett via B4 Relay
2026-11-22 4:35 ` [PATCH 4/4] platform/x86: clevo-laptop: register 5-step white keyboard backlight LED device Nick Dowsett via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Nick Dowsett via B4 Relay @ 2026-11-22 4:35 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: Armin Wolf, Werner Sembach, linux-kernel, platform-driver-x86,
rust-for-linux, Nick Dowsett
From: Nick Dowsett <nick42d@gmail.com>
- Add `GetSpecs` and `GetBiosFeatures2` EC queries and `KbBacklightType`
detection (with retries and BIOS features fallback for older devices).
- Restrict probe to the supported 5-step white keyboard backlight.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
drivers/platform/x86/clevo-laptop.rs | 125 +++++++++++++++++++++++++++++++++++
1 file changed, 125 insertions(+)
diff --git a/drivers/platform/x86/clevo-laptop.rs b/drivers/platform/x86/clevo-laptop.rs
index 289b30c478ec..6f08bf295c07 100644
--- a/drivers/platform/x86/clevo-laptop.rs
+++ b/drivers/platform/x86/clevo-laptop.rs
@@ -13,6 +13,10 @@
device,
dmi,
prelude::*,
+ time::{
+ delay::fsleep,
+ Delta, //
+ },
wmi, //
};
@@ -24,7 +28,12 @@
/// DMI board name allowlist, restricted to tested boards since the WMI GUID is not
/// unique.
const SUPPORTED_BOARDS: &[&CStr] = &[c"NLx0AU"];
+const CLEVO_EC_CMD_GET_SPECS: u8 = 0x0D;
const CLEVO_EC_CMD_GET_BIOS_FEATURES_1: u8 = 0x52;
+const CLEVO_EC_CMD_GET_BIOS_FEATURES_2: u8 = 0x7A;
+const CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB: u32 = 0x4000_0000;
+const CLEVO_BIOS_FEATURE_CODE_3_ZONE_RGB_KB: u32 = 0x0040_0000;
+const CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB_MAX_5: u32 = 0x4000;
const CLEVO_EC_WMI_INSTANCE: u8 = 0;
module! {
@@ -89,6 +98,17 @@ fn probe<'bound>(
backend.query(GetBiosFeatures1).map_err(|_| ENODEV)?;
+ // MVP: Only the NL57AU 5-step white backlight is supported.
+ if backend.detect_backlight_type()? != Some(KbBacklightType::FixedColor) {
+ return Err(ENODEV);
+ }
+ let has_white_5 = backend
+ .query(GetBiosFeatures2)
+ .is_ok_and(|feat2| feat2.has_white_only_kb_max_5());
+ if !has_white_5 {
+ return Err(ENODEV);
+ }
+
Ok(try_pin_init!(WmiDriver {}))
})
}
@@ -127,6 +147,61 @@ fn query<Q>(&self, query: Q) -> Result<Q::Output>
}
}
}
+ /// Detect backlight type e.g white.
+ fn detect_backlight_type(&self) -> Result<Option<KbBacklightType>> {
+ const MAX_RETRIES: usize = 3;
+ const RETRY_SLEEP_DURATION: Delta = Delta::from_millis(50);
+
+ for attempt in 0..MAX_RETRIES {
+ if attempt != 0 {
+ pr_debug!(
+ "KbBacklightType::None probably wrong, retrying - attempt {} of {}\n",
+ attempt,
+ MAX_RETRIES - 1
+ );
+ fsleep(RETRY_SLEEP_DURATION);
+ }
+ if let Ok(specs) = self.query(GetSpecs) {
+ let backlight_type = specs.kb_backlight_type();
+ if backlight_type != Ok(None) {
+ return backlight_type.map_err(|_| ENODEV);
+ }
+ }
+ }
+
+ // Check for devices <= Intel 8th gen (only white only, 3 zone RGB,
+ // or no backlight on these devices)
+ let feat1 = self.query(GetBiosFeatures1).map_err(|_| ENODEV)?;
+ if feat1.has_3_zone_rgb_kb() {
+ Ok(Some(KbBacklightType::ThreeZoneRgb))
+ } else if feat1.has_white_only_kb() {
+ Ok(Some(KbBacklightType::FixedColor))
+ } else {
+ Ok(None)
+ }
+ }
+}
+
+/// Keyboard backlight type - e.g Fixed Color
+#[derive(PartialEq)]
+#[repr(u8)]
+enum KbBacklightType {
+ FixedColor = 0x01,
+ ThreeZoneRgb = 0x02,
+ OneZoneRgb = 0x06,
+ PerKeyRgb = 0xF3,
+}
+impl KbBacklightType {
+ const fn from_raw(raw: u8) -> Result<Option<Self>, u8> {
+ match raw {
+ 0x01 => Ok(Some(KbBacklightType::FixedColor)),
+ 0x02 => Ok(Some(KbBacklightType::ThreeZoneRgb)),
+ 0x06 => Ok(Some(KbBacklightType::OneZoneRgb)),
+ 0xF3 => Ok(Some(KbBacklightType::PerKeyRgb)),
+ 0x00 => Ok(None),
+ other => Err(other),
+ }
+ }
}
/// Args for a command sent to the EC.
@@ -144,8 +219,12 @@ fn as_bytes(&self) -> &[u8] {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+struct GetSpecs;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct GetBiosFeatures1;
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+struct GetBiosFeatures2;
impl EcQuery for GetBiosFeatures1 {
type Output = BiosFeatures1;
@@ -163,10 +242,56 @@ fn deserialize_output(output: &[u8]) -> Result<Self::Output> {
Ok(feat)
}
}
+impl EcQuery for GetBiosFeatures2 {
+ type Output = BiosFeatures2;
+ fn cmd(&self) -> u8 {
+ CLEVO_EC_CMD_GET_BIOS_FEATURES_2
+ }
+ fn args(&self) -> EcMethodArgs {
+ EcMethodArgs::Scalar(0)
+ }
+ fn deserialize_output(output: &[u8]) -> Result<Self::Output> {
+ let (feat, _) = BiosFeatures2::read_from_prefix(output).map_err(|_| ENODATA)?;
+ Ok(feat)
+ }
+}
+impl EcQuery for GetSpecs {
+ type Output = Specs;
+ fn cmd(&self) -> u8 {
+ CLEVO_EC_CMD_GET_SPECS
+ }
+ fn args(&self) -> EcMethodArgs {
+ EcMethodArgs::Scalar(0)
+ }
+ fn deserialize_output(output: &[u8]) -> Result<Self::Output> {
+ let (specs, _) = Specs::read_from_prefix(output).map_err(|_| ENODATA)?;
+ Ok(specs)
+ }
+}
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
struct BiosFeatures1(u32);
+#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
+struct BiosFeatures2(u32);
+#[derive(Debug, Clone, Copy, PartialEq, Eq, FromBytes)]
+struct Specs([u8; 16]);
impl BiosFeatures1 {
const INVALID: Self = Self(0xFFFF_FFFF);
+ const fn has_white_only_kb(self) -> bool {
+ (self.0 & CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB) != 0
+ }
+ const fn has_3_zone_rgb_kb(self) -> bool {
+ (self.0 & CLEVO_BIOS_FEATURE_CODE_3_ZONE_RGB_KB) != 0
+ }
+}
+impl BiosFeatures2 {
+ const fn has_white_only_kb_max_5(self) -> bool {
+ (self.0 & CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB_MAX_5) != 0
+ }
+}
+impl Specs {
+ const fn kb_backlight_type(&self) -> Result<Option<KbBacklightType>, u8> {
+ KbBacklightType::from_raw(self.0[0x0F])
+ }
}
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 4/4] platform/x86: clevo-laptop: register 5-step white keyboard backlight LED device
2026-11-22 4:35 [PATCH 0/4] platform/x86: clevo-laptop: add initial Rust driver for keyboard backlight Nick Dowsett via B4 Relay
` (2 preceding siblings ...)
2026-11-22 4:35 ` [PATCH 3/4] platform/x86: clevo-laptop: probe keyboard backlight type and detect 5-step white backlight Nick Dowsett via B4 Relay
@ 2026-11-22 4:35 ` Nick Dowsett via B4 Relay
3 siblings, 0 replies; 5+ messages in thread
From: Nick Dowsett via B4 Relay @ 2026-11-22 4:35 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: Armin Wolf, Werner Sembach, linux-kernel, platform-driver-x86,
rust-for-linux, Nick Dowsett
From: Nick Dowsett <nick42d@gmail.com>
- Add `SetWhiteBrightness` EC command and `Brightness` wrapper.
- Implement `LedOps` (`FixedColorLedOperations`) and register a
`white:kbd_backlight` LED class device during WMI probe.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
drivers/platform/x86/clevo-laptop.rs | 100 +++++++++++++++++++++++++++++++++--
1 file changed, 95 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/clevo-laptop.rs b/drivers/platform/x86/clevo-laptop.rs
index 6f08bf295c07..0a9cb96e7811 100644
--- a/drivers/platform/x86/clevo-laptop.rs
+++ b/drivers/platform/x86/clevo-laptop.rs
@@ -10,8 +10,14 @@
//! Inspired by Tuxedo Computers' drivers.
use kernel::{
+ self,
device,
dmi,
+ led::{
+ self,
+ LedOps,
+ Normal, //
+ },
prelude::*,
time::{
delay::fsleep,
@@ -31,6 +37,7 @@
const CLEVO_EC_CMD_GET_SPECS: u8 = 0x0D;
const CLEVO_EC_CMD_GET_BIOS_FEATURES_1: u8 = 0x52;
const CLEVO_EC_CMD_GET_BIOS_FEATURES_2: u8 = 0x7A;
+const CLEVO_EC_CMD_SET_KB_WHITE_LEDS: u8 = 0x27;
const CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB: u32 = 0x4000_0000;
const CLEVO_BIOS_FEATURE_CODE_3_ZONE_RGB_KB: u32 = 0x0040_0000;
const CLEVO_BIOS_FEATURE_CODE_WHITE_ONLY_KB_MAX_5: u32 = 0x4000;
@@ -63,7 +70,7 @@ trait EcQuery {
#[pin_data]
struct ClevoLaptopModule {
#[pin]
- _wmi_driver: wmi::Registration<WmiDriver>,
+ _wmi_driver: wmi::Registration<WmiDriver<'static>>,
}
impl kernel::InPlaceModule for ClevoLaptopModule {
@@ -83,12 +90,14 @@ fn init(module: &'static ThisModule) -> impl PinInit<Self, Error> {
/// RAII guard for Clevo WMI driver holding all subsystem devices e.g LED device.
#[pin_data]
-struct WmiDriver {}
+struct WmiDriver<'a> {
+ _led: LedRegistration<'a>,
+}
kernel::wmi_device_table!(WMI_TABLE, [wmi::DeviceId::new(CLEVO_WMI_METHOD_GUID)]);
-impl wmi::Driver for WmiDriver {
- type Data<'bound> = WmiDriver;
+impl wmi::Driver for WmiDriver<'_> {
+ type Data<'bound> = WmiDriver<'bound>;
const ID_TABLE: wmi::IdTable = &WMI_TABLE;
fn probe<'bound>(
dev: &'bound wmi::Device<device::Core<'_>>,
@@ -109,11 +118,64 @@ fn probe<'bound>(
return Err(ENODEV);
}
- Ok(try_pin_init!(WmiDriver {}))
+ if let Err(e) = backend.query(SetWhiteBrightness(Brightness::OFF)) {
+ dev_dbg!(
+ dev,
+ "Error {e:?} setting keyboard brightness on initialization.\n"
+ );
+ }
+
+ let led_dev = KBox::pin_init(
+ led::DeviceBuilder::new()
+ .name(c"white:kbd_backlight")
+ .color(led::Color::White)
+ .build(
+ dev.as_ref(),
+ try_pin_init!(FixedColorLedOperations { backend }),
+ ),
+ GFP_KERNEL,
+ )?;
+
+ Ok(try_pin_init!(WmiDriver {
+ _led: LedRegistration::White5Step { _dev: led_dev },
+ }))
})
}
}
+/// RAII guard for Clevo LED device holding the appropriate sysfs device for the backlight type.
+enum LedRegistration<'a> {
+ White5Step {
+ _dev: Pin<
+ KBox<led::Device<'a, FixedColorLedOperations<'a, { Brightness::MAX_WHITE_5.raw() }>>>,
+ >,
+ },
+}
+
+/// Represents how to perform LED operations for a Clevo single-color LED keyboard, generic over
+/// `MAX_BRIGHTNESS`.
+#[pin_data]
+struct FixedColorLedOperations<'a, const MAX_BRIGHTNESS: u8> {
+ backend: EcInterface<'a>,
+}
+#[vtable]
+impl<'a, const MAX_BRIGHTNESS: u8> LedOps for FixedColorLedOperations<'a, MAX_BRIGHTNESS> {
+ const BLOCKING: bool = true;
+ const MAX_BRIGHTNESS: u32 = MAX_BRIGHTNESS as u32;
+ type Mode = Normal;
+
+ fn brightness_set<'bound>(
+ self: &<Self::Mode as led::Mode>::Device<'bound, Self>,
+ brightness: u32,
+ ) -> Result<()> {
+ let clamped = u8::try_from(brightness)
+ .unwrap_or(MAX_BRIGHTNESS)
+ .min(MAX_BRIGHTNESS);
+ self.backend
+ .query(SetWhiteBrightness(Brightness::new(clamped)))
+ }
+}
+
/// Interface to Clevo Embedded Controller.
enum EcInterface<'a> {
Wmi(&'a wmi::Device<device::Bound>),
@@ -182,6 +244,20 @@ fn detect_backlight_type(&self) -> Result<Option<KbBacklightType>> {
}
}
+/// Keyboard backlight brightness level.
+#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
+struct Brightness(u8);
+impl Brightness {
+ const OFF: Self = Self(0);
+ const MAX_WHITE_5: Self = Self(5);
+ const fn new(val: u8) -> Self {
+ Self(val)
+ }
+ const fn raw(self) -> u8 {
+ self.0
+ }
+}
+
/// Keyboard backlight type - e.g Fixed Color
#[derive(PartialEq)]
#[repr(u8)]
@@ -219,6 +295,8 @@ fn as_bytes(&self) -> &[u8] {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+struct SetWhiteBrightness(Brightness);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct GetSpecs;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -226,6 +304,18 @@ fn as_bytes(&self) -> &[u8] {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct GetBiosFeatures2;
+impl EcQuery for SetWhiteBrightness {
+ type Output = ();
+ fn cmd(&self) -> u8 {
+ CLEVO_EC_CMD_SET_KB_WHITE_LEDS
+ }
+ fn args(&self) -> EcMethodArgs {
+ EcMethodArgs::Scalar(self.0.raw().into())
+ }
+ fn deserialize_output(_output: &[u8]) -> Result<Self::Output> {
+ Ok(())
+ }
+}
impl EcQuery for GetBiosFeatures1 {
type Output = BiosFeatures1;
fn cmd(&self) -> u8 {
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread