[PATCH v3 7/7] leds: add synology microp led driver
From: Markus Probst via B4 Relay
Date: Fri Mar 13 2026 - 15:04:21 EST
From: Markus Probst <markus.probst@xxxxxxxxx>
Add a driver to control the power, status, alert and usb LEDs on
Synology NAS devices. This will be bound to a mfd sub-device, registered
by the synology microp core driver.
Tested successfully on a Synology DS923+.
Signed-off-by: Markus Probst <markus.probst@xxxxxxxxx>
---
MAINTAINERS | 1 +
drivers/leds/Kconfig | 11 ++
drivers/leds/Makefile | 1 +
drivers/leds/leds_synology_microp.rs | 303 +++++++++++++++++++++++++++++++++++
4 files changed, 316 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 32932ecab9cf..1d9240055d29 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25544,6 +25544,7 @@ M: Markus Probst <markus.probst@xxxxxxxxx>
S: Maintained
F: Documentation/devicetree/bindings/leds/synology,microp.yaml
F: Documentation/devicetree/bindings/mfd/synology,microp.yaml
+F: drivers/leds/leds_synology_microp.rs
F: drivers/mfd/synology_microp.rs
SYNOPSYS ARC ARCHITECTURE
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 597d7a79c988..9a9609b924fe 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -1029,6 +1029,17 @@ config LEDS_ACER_A500
This option enables support for the Power Button LED of
Acer Iconia Tab A500.
+config LEDS_SYNOLOGY_MICROP
+ tristate "Synology Microp led driver"
+ depends on MFD_SYNOLOGY_MICROP
+ depends on RUST
+ depends on LEDS_CLASS && LEDS_CLASS_MULTICOLOR
+ help
+ Enable support for the MCU found in Synology NAS devices.
+
+ This is needed to control the power, status, alert and usb leds on the
+ NAS device.
+
source "drivers/leds/blink/Kconfig"
comment "Flash and Torch LED drivers"
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 8fdb45d5b439..200101eb26d5 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -89,6 +89,7 @@ obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o
obj-$(CONFIG_LEDS_ST1202) += leds-st1202.o
obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o
obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
+obj-$(CONFIG_LEDS_SYNOLOGY_MICROP) += leds_synology_microp.o
obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o
obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o
obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
diff --git a/drivers/leds/leds_synology_microp.rs b/drivers/leds/leds_synology_microp.rs
new file mode 100644
index 000000000000..d2e94e992981
--- /dev/null
+++ b/drivers/leds/leds_synology_microp.rs
@@ -0,0 +1,303 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Synology Microp led driver
+
+use kernel::{
+ device::Bound,
+ devres::{self, Devres},
+ led::{
+ self,
+ LedOps,
+ MultiColorSubLed, //
+ },
+ new_mutex,
+ platform,
+ prelude::*,
+ serdev,
+ sync::Mutex, //
+};
+use pin_init::pin_init_scope;
+
+kernel::module_platform_driver! {
+ type: SynologyMicropLedDriver,
+ name: "synology_microp_leds",
+ authors: ["Markus Probst <markus.probst@xxxxxxxxx>"],
+ description: "Synology Microp led driver",
+ license: "GPL v2",
+}
+
+#[pin_data]
+struct SynologyMicropLedDriver {
+ #[pin]
+ status: Devres<led::MultiColorDevice<StatusLedHandler>>,
+ #[pin]
+ power: Devres<led::Device<LedHandler>>,
+}
+
+impl platform::Driver for SynologyMicropLedDriver {
+ type IdInfo = ();
+
+ fn probe(
+ dev: &platform::Device<kernel::device::Core>,
+ _id_info: Option<&Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> {
+ pin_init_scope(move || {
+ let fwnode = dev.as_ref().fwnode().ok_or(EINVAL)?;
+
+ if let Some(alert_fwnode) = fwnode.get_child_by_name(c"alert-led") {
+ devres::register(
+ dev.as_ref(),
+ led::DeviceBuilder::new()
+ .fwnode(Some(alert_fwnode))
+ .devicename(c"synology-microp/alert-led")
+ .color(led::Color::Orange)
+ .build(
+ &**dev,
+ try_pin_init!(LedHandler {
+ blink <- new_mutex!(false),
+ command: Command::Alert,
+ }),
+ ),
+ GFP_KERNEL,
+ )?;
+ }
+
+ if let Some(alert_fwnode) = fwnode.get_child_by_name(c"usb-led") {
+ devres::register(
+ dev.as_ref(),
+ led::DeviceBuilder::new()
+ .fwnode(Some(alert_fwnode))
+ .devicename(c"synology-microp/usb-led")
+ .color(led::Color::Green)
+ .build(
+ &**dev,
+ try_pin_init!(LedHandler {
+ blink <- new_mutex!(false),
+ command: Command::Usb,
+ }),
+ ),
+ GFP_KERNEL,
+ )?;
+ }
+
+ Ok(try_pin_init!(Self {
+ status <- led::DeviceBuilder::new()
+ .fwnode(Some(fwnode.get_child_by_name(c"status-led").ok_or(EINVAL)?))
+ .devicename(c"synology-microp/status-led")
+ .color(led::Color::Multi)
+ .build_multicolor(
+ &**dev,
+ try_pin_init!(StatusLedHandler {
+ blink <- new_mutex!(false),
+ }),
+ StatusLedHandler::SUBLEDS,
+ ),
+ power <- led::DeviceBuilder::new()
+ .fwnode(Some(fwnode.get_child_by_name(c"power-led").ok_or(EINVAL)?))
+ .devicename(c"synology-microp/power-led")
+ .color(led::Color::Blue)
+ .default_trigger(c"timer")
+ .build(
+ &**dev,
+ try_pin_init!(LedHandler {
+ blink <- new_mutex!(true),
+ command: Command::Power,
+ }),
+ ),
+ }))
+ })
+ }
+}
+
+enum StatusLedColor {
+ Green,
+ Orange,
+}
+
+enum State {
+ On,
+ Blink,
+ Off,
+}
+
+enum Command {
+ Power(State),
+ Status(StatusLedColor, State),
+ Alert(State),
+ Usb(State),
+}
+
+impl Command {
+ fn write(self, dev: &platform::Device<Bound>) -> Result {
+ // SAFETY: Since we have no of and no acpi match table, we assume this is a mfd sub-device
+ // and our parent is a serial device bus device, bound to the synology microp core driver.
+ let parent = unsafe { dev.as_ref().parent_unchecked::<serdev::Device<Bound>>() };
+ parent.write_all(
+ match self {
+ Self::Power(State::On) => &[0x34],
+ Self::Power(State::Blink) => &[0x35],
+ Self::Power(State::Off) => &[0x36],
+
+ Self::Status(_, State::Off) => &[0x37],
+ Self::Status(StatusLedColor::Green, State::On) => &[0x38],
+ Self::Status(StatusLedColor::Green, State::Blink) => &[0x39],
+ Self::Status(StatusLedColor::Orange, State::On) => &[0x3A],
+ Self::Status(StatusLedColor::Orange, State::Blink) => &[0x3B],
+
+ Self::Alert(State::On) => &[0x4C, 0x41, 0x31],
+ Self::Alert(State::Blink) => &[0x4C, 0x41, 0x32],
+ Self::Alert(State::Off) => &[0x4C, 0x41, 0x33],
+
+ Self::Usb(State::On) => &[0x40],
+ Self::Usb(State::Blink) => &[0x41],
+ Self::Usb(State::Off) => &[0x42],
+ },
+ serdev::Timeout::Max,
+ )?;
+ Ok(())
+ }
+}
+
+#[pin_data]
+struct LedHandler {
+ #[pin]
+ blink: Mutex<bool>,
+ command: fn(State) -> Command,
+}
+
+#[vtable]
+impl LedOps for LedHandler {
+ type Bus = platform::Device<Bound>;
+ type Mode = led::Normal;
+ const BLOCKING: bool = true;
+ const MAX_BRIGHTNESS: u32 = 1;
+
+ fn brightness_set(
+ &self,
+ dev: &Self::Bus,
+ _classdev: &led::Device<Self>,
+ brightness: u32,
+ ) -> Result<()> {
+ let mut blink = self.blink.lock();
+ (self.command)(if brightness == 0 {
+ *blink = false;
+ State::Off
+ } else if *blink {
+ State::Blink
+ } else {
+ State::On
+ })
+ .write(dev)?;
+
+ Ok(())
+ }
+
+ fn blink_set(
+ &self,
+ dev: &Self::Bus,
+ _classdev: &led::Device<Self>,
+ delay_on: &mut usize,
+ delay_off: &mut usize,
+ ) -> Result<()> {
+ let mut blink = self.blink.lock();
+
+ (self.command)(if *delay_on == 0 && *delay_off != 0 {
+ State::Off
+ } else if *delay_on != 0 && *delay_off == 0 {
+ State::On
+ } else {
+ *blink = true;
+ *delay_on = 167;
+ *delay_off = 167;
+
+ State::Blink
+ })
+ .write(dev)
+ }
+}
+
+#[pin_data]
+struct StatusLedHandler {
+ #[pin]
+ blink: Mutex<bool>,
+}
+
+impl StatusLedHandler {
+ const SUBLEDS: &[MultiColorSubLed] = &[
+ MultiColorSubLed::new(led::Color::Green).initial_intensity(1),
+ MultiColorSubLed::new(led::Color::Orange),
+ ];
+}
+
+#[vtable]
+impl LedOps for StatusLedHandler {
+ type Bus = platform::Device<Bound>;
+ type Mode = led::MultiColor;
+ const BLOCKING: bool = true;
+ const MAX_BRIGHTNESS: u32 = 1;
+
+ fn brightness_set(
+ &self,
+ dev: &Self::Bus,
+ classdev: &led::MultiColorDevice<Self>,
+ brightness: u32,
+ ) -> Result<()> {
+ let mut blink = self.blink.lock();
+ if brightness == 0 {
+ *blink = false;
+ }
+
+ let (color, subled_brightness) = if classdev.subleds()[1].intensity == 0 {
+ (StatusLedColor::Green, classdev.subleds()[0].brightness)
+ } else {
+ (StatusLedColor::Orange, classdev.subleds()[1].brightness)
+ };
+
+ Command::Status(
+ color,
+ if subled_brightness == 0 {
+ State::Off
+ } else if *blink {
+ State::Blink
+ } else {
+ State::On
+ },
+ )
+ .write(dev)
+ }
+
+ fn blink_set(
+ &self,
+ dev: &Self::Bus,
+ classdev: &led::MultiColorDevice<Self>,
+ delay_on: &mut usize,
+ delay_off: &mut usize,
+ ) -> Result<()> {
+ let mut blink = self.blink.lock();
+ *blink = true;
+
+ let (color, subled_intensity) = if classdev.subleds()[1].intensity == 0 {
+ (StatusLedColor::Green, classdev.subleds()[0].intensity)
+ } else {
+ (StatusLedColor::Orange, classdev.subleds()[1].intensity)
+ };
+ Command::Status(
+ color,
+ if *delay_on == 0 && *delay_off != 0 {
+ *blink = false;
+ State::Off
+ } else if subled_intensity == 0 {
+ State::Off
+ } else if *delay_on != 0 && *delay_off == 0 {
+ *blink = false;
+ State::On
+ } else {
+ *delay_on = 167;
+ *delay_off = 167;
+
+ State::Blink
+ },
+ )
+ .write(dev)
+ }
+}
--
2.52.0