[PATCH v3 6/7] mfd: Add synology microp core driver

Markus Probst via B4 Relay posted 7 patches 3 weeks, 3 days ago
There is a newer version of this series
[PATCH v3 6/7] mfd: Add synology microp core driver
Posted by Markus Probst via B4 Relay 3 weeks, 3 days ago
From: Markus Probst <markus.probst@posteo.de>

Add a synology microp core driver, written in Rust.
The driver targets a microcontroller found in Synology NAS devices. It
only provides the base for sub-devices, like LEDs.

Tested successfully on a Synology DS923+.

Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
 MAINTAINERS                    |  7 +++++++
 drivers/mfd/Kconfig            | 11 ++++++++++
 drivers/mfd/Makefile           |  2 ++
 drivers/mfd/synology_microp.rs | 46 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fa49e40836ab..32932ecab9cf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25539,6 +25539,13 @@ F:	drivers/dma-buf/sync_*
 F:	include/linux/sync_file.h
 F:	include/uapi/linux/sync_file.h
 
+SYNOLOGY MICROP DRIVER
+M:	Markus Probst <markus.probst@posteo.de>
+S:	Maintained
+F:	Documentation/devicetree/bindings/leds/synology,microp.yaml
+F:	Documentation/devicetree/bindings/mfd/synology,microp.yaml
+F:	drivers/mfd/synology_microp.rs
+
 SYNOPSYS ARC ARCHITECTURE
 M:	Vineet Gupta <vgupta@kernel.org>
 L:	linux-snps-arc@lists.infradead.org
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 7192c9d1d268..8b8b391d1b47 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1320,6 +1320,17 @@ config MFD_SY7636A
 	  To enable support for building sub-devices as modules,
 	  choose M here.
 
+config MFD_SYNOLOGY_MICROP
+	tristate "Synology Microp core driver"
+	depends on RUST
+	select RUST_SERIAL_DEV_BUS_ABSTRACTIONS
+	select MFD_CORE
+	help
+	  Enable support for the MCU found in Synology NAS devices.
+
+	  This driver only provides the base for sub-devices. For additional
+	  functionality, you have to enable support for the sub-devices as well.
+
 config MFD_RDC321X
 	tristate "RDC R-321x southbridge"
 	select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index e75e8045c28a..f754be7163cd 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -304,3 +304,5 @@ obj-$(CONFIG_MFD_RSMU_SPI)	+= rsmu_spi.o rsmu_core.o
 obj-$(CONFIG_MFD_UPBOARD_FPGA)	+= upboard-fpga.o
 
 obj-$(CONFIG_MFD_LOONGSON_SE)	+= loongson-se.o
+
+obj-$(CONFIG_MFD_SYNOLOGY_MICROP)	+= synology_microp.o
diff --git a/drivers/mfd/synology_microp.rs b/drivers/mfd/synology_microp.rs
new file mode 100644
index 000000000000..b9b5fff5c18d
--- /dev/null
+++ b/drivers/mfd/synology_microp.rs
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Synology Microp core driver
+
+use kernel::{
+    device,
+    mfd,
+    of,
+    prelude::*,
+    serdev, //
+};
+
+kernel::module_serdev_device_driver! {
+    type: SynologyMicropCoreDriver,
+    name: "synology_microp",
+    authors: ["Markus Probst <markus.probst@posteo.de>"],
+    description: "Synology Microp core driver",
+    license: "GPL v2",
+}
+
+struct SynologyMicropCoreDriver;
+
+kernel::of_device_table!(
+    OF_TABLE,
+    MODULE_OF_TABLE,
+    <SynologyMicropCoreDriver as serdev::Driver>::IdInfo,
+    [(of::DeviceId::new(c"synology,microp"), ()),]
+);
+
+#[vtable]
+impl serdev::Driver for SynologyMicropCoreDriver {
+    type IdInfo = ();
+    const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+    const MFD_CELLS: Option<&'static [mfd::Cell]> =
+        Some(&[mfd::Cell::new(c"synology_microp_leds").of(c"synology,microp-leds", None)]);
+
+    fn probe(
+        dev: &serdev::Device<device::Core>,
+        _id_info: Option<&Self::IdInfo>,
+    ) -> impl PinInit<Self, kernel::error::Error> {
+        let _ = dev.set_baudrate(9600);
+        dev.set_flow_control(false);
+        dev.set_parity(serdev::Parity::None)?;
+        Ok(Self)
+    }
+}

-- 
2.52.0