Drivers to support the MCU on QNAP NAS devices
Subsystems (12)
Heiko Stuebner
maintainerv9 cover Drivers to support the MCU on QNAP NAS devices
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
For the MCU "SPEC3" and "SPEC4" are listed which is configured in the model.conf of the device. When setting the value from SPEC4 to SPEC3 on my TS433, the supported commands change, but the command interface stays the same and especially the version command is the same.
The binding also does not expose any interals of the device that might change, so hopefully there shouldn't be big roadblocks to support different devices, apart from possibly adapting the commands.
changes in v9:
- add Acks + cc-stable to HID patch
- make timeout-value a constant in core mfd-driver
- some flush serdev before sending a new command
changes in v8:
- patch for hid-sensor hub to not do wonky stuff with an old platform-data copy
I hope my reading of the situation is correct here, but that initial platform_data really seemed wrong
mfd:
- flush serial before writing a new command
- wait for send to complete before starting the receive wait-timeout
- set expected length to 0 directly when the reply is complete not after leaving the receive callback
changes in v7:
- use ASCII representation in commands where possible instead of hex vals
- drop get_variant function and use mfd platform-data instead
mfd:
- a lot of style improvements
leds:
- name variables better (value -> brightness, num -> num_err_led)
- handle preservation of blink mode more effectively
- snprintf -> scnprintf
- drop duplicate "failed to register ... LED" messages
changes in v6:
- format mcu commands arrays in single lines (Lee)
mfd:
- drop obsolete remain kdoc for the removed
reply_lock (kernel test robot)
changes in v5:
binding:
- add Conor's Reviewed-by
mfd:
Address comments from Lee
- improve commit message
- improve Kconfig help text
- sort headers alphabetical
- style and spelling improvements
- constants for magic numbers
- drop reply assignment, the mcu only replies to commands sent to it, so there should only ever be one command in fligth.
hwmon:
Add Acked-by from Guenter and address some remarks
- don't allow empty fan subnode
- use num var directly when getting cooling levels, without using ret intermediate
- use dev_err_probe in thermal init function
changes in v4:
binding:
- move cooling properties into a fan subnode and reference fan-common.yaml (Rob)
- dropped Krzysztof's Ack because of this
mfd:
- use correct format-string for size_t (kernel test robot)
input:
- added Dmitry's Ack
hwmon:
- adapted to fan-subnode when reading cooling properties
- dropped Guenter's Ack because of this
changes in v3:
mfd
- use correct power-off priority: default
- constify the cmd-data array in command functions (Dmitry)
leds:
- don't point to temporary buffers for cdev->name (Florian Eckert)
hwmon:
- use clamp_val(), don't try to reimplement (Guenter)
- add Guenter's Ack
input:
address Dmitry's comments
- constify some cmd arrays
- add input-close callback to cancel beep worker
- drop initial input event report
changes in v2:
binding:
- rename to qnap,ts433-mcu.yaml (Krzysztof)
- drop "preserve formatting" indicator (Krzysztof)
- add Krzysztof's Review tag
mfd:
- fix checkpatch --strict CHECKs
- add a MAINTAINERS entry for all qnap-mcu-parts
Heiko Stuebner (9):
HID: hid-sensor-hub: don't use stale platform-data on remove
mfd: core: make platform_data pointer const in struct mfd_cell
dt-bindings: mfd: add binding for qnap,ts433-mcu devices
mfd: add base driver for qnap-mcu devices
leds: add driver for LEDs from qnap-mcu devices
Input: add driver for the input part of qnap-mcu devices
hwmon: add driver for the hwmon parts of qnap-mcu devices
arm64: dts: rockchip: hook up the MCU on the QNAP TS433
arm64: dts: rockchip: set hdd led labels on qnap-ts433
.../bindings/mfd/qnap,ts433-mcu.yaml | 42 ++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/qnap-mcu-hwmon.rst | 27 ++ MAINTAINERS | 9 + .../boot/dts/rockchip/rk3568-qnap-ts433.dts | 61 +++ drivers/hid/hid-sensor-hub.c | 21 +- drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/qnap-mcu-hwmon.c | 364 ++++++++++++++++++ drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile | 1 + drivers/input/misc/qnap-mcu-input.c | 153 ++++++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-qnap-mcu.c | 227 +++++++++++ drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 ++++++++++++++++ include/linux/mfd/core.h | 2 +- include/linux/mfd/qnap-mcu.h | 26 ++ 20 files changed, 1316 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/qnap,ts433-mcu.yaml create mode 100644 Documentation/hwmon/qnap-mcu-hwmon.rst create mode 100644 drivers/hwmon/qnap-mcu-hwmon.c create mode 100644 drivers/input/misc/qnap-mcu-input.c create mode 100644 drivers/leds/leds-qnap-mcu.c create mode 100644 drivers/mfd/qnap-mcu.c create mode 100644 include/linux/mfd/qnap-mcu.h
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 1/9 HID: hid-sensor-hub: don't use stale platform-data on remove
The hid-sensor-hub creates the individual device structs and transfers them to the created mfd platform-devices via the platform_data in the mfd_cell.
Before e651a1da442a ("HID: hid-sensor-hub: Allow parallel synchronous reads") the sensor-hub was managing access centrally, with one "completion" in the hub's data structure, which needed to be finished on removal at the latest.
The mentioned commit then moved this central management to each hid sensor device, resulting on a completion in each struct hid_sensor_hub_device. The remove procedure was adapted to go through all sensor devices and finish any pending "completion".
What this didn't take into account was, platform_device_add_data() that is used by mfd_add{_hotplug}_devices() does a kmemdup on the submitted platform-data. So the data the platform-device gets is a copy of the original data, meaning that the device worked on a different completion than what sensor_hub_remove() currently wants to access.
To fix that, use device_for_each_child() to go through each child-device similar to how mfd_remove_devices() unregisters the devices later and with that get the live platform_data to finalize the correct completion.
--- drivers/hid/hid-sensor-hub.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/hid/hid-sensor-hub.c +14 -7
@@ -730,23 +730,30 @@ static int sensor_hub_probe(struct hid_device *hdev,return ret; } +static int sensor_hub_finalize_pending_fn (struct device *dev,void *data) +{ +struct hid_sensor_hub_device *hsdev = dev->platform_data; + +if (hsdev->pending.status) +complete (&hsdev->pending.ready); + +return 0 ; +} +static void sensor_hub_remove (struct hid_device *hdev) {struct sensor_hub_data *data =hid_get_drvdata (hdev);unsigned long flags; -int i;hid_dbg (hdev," hardware removed\n" );hid_hw_close (hdev);hid_hw_stop (hdev); +spin_lock_irqsave (&data->lock, flags); -for (i =0 ; i < data->hid_sensor_client_cnt; ++i) { -struct hid_sensor_hub_device *hsdev = - data->hid_sensor_hub_client_devs[i].platform_data; -if (hsdev->pending.status) -complete (&hsdev->pending.ready); - } +device_for_each_child (&hdev->dev,NULL , + sensor_hub_finalize_pending_fn);spin_unlock_irqrestore (&data->lock, flags); +mfd_remove_devices (&hdev->dev);mutex_destroy (&data->mutex); }
Signature · 1 line
2.45.2
Re: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 18 lines · Heiko Stuebner
The hid-sensor-hub creates the individual device structs and transfers them to the created mfd platform-devices via the
platform_datain themfd_cell.Before
e651a1da442a("HID: hid-sensor-hub: Allow parallel synchronous reads") the sensor-hub was managing access centrally, with one "completion" in the hub's data structure, which needed to be finished on removal at the latest.The mentioned commit then moved this central management to each hid sensor device, resulting on a completion in each struct
hid_sensor_hub_device. The remove procedure was adapted to go through all sensor devices and finish any pending "completion".What this didn't take into account was,
platform_device_add_data()that is used by mfd_add{_hotplug}_devices() does a kmemdup on the submitted platform-data. So the data the platform-device gets is a copy of the original data, meaning that the device worked on a different completion than whatsensor_hub_remove()currently wants to access.
Quoted 8 lines
To fix that, use
device_for_each_child()to go through each child-device similar to howmfd_remove_devices()unregisters the devices later and with that get the liveplatform_datato finalize the correct completion.Fixes e651a1da442a ("HID: hid-sensor-hub: Allow parallel synchronous reads")
Are you planning to merge this together with the rest of the set, or do you want me to expedite it? I'll be happy to apply it separately as a proper fix.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Heiko Stübner
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Hi Jiri,
Am Donnerstag, 7. November 2024, 13:59:04 CET schrieb Jiri Kosina:
Quoted 29 lines · Heiko Stuebner
Quoted 19 lines
The hid-sensor-hub creates the individual device structs and transfers them to the created mfd platform-devices via the
platform_datain themfd_cell.Before
e651a1da442a("HID: hid-sensor-hub: Allow parallel synchronous reads") the sensor-hub was managing access centrally, with one "completion" in the hub's data structure, which needed to be finished on removal at the latest.The mentioned commit then moved this central management to each hid sensor device, resulting on a completion in each struct
hid_sensor_hub_device. The remove procedure was adapted to go through all sensor devices and finish any pending "completion".What this didn't take into account was,
platform_device_add_data()that is used by mfd_add{_hotplug}_devices() does a kmemdup on the submitted platform-data. So the data the platform-device gets is a copy of the original data, meaning that the device worked on a different completion than whatsensor_hub_remove()currently wants to access.Quoted 8 lines
To fix that, use
device_for_each_child()to go through each child-device similar to howmfd_remove_devices()unregisters the devices later and with that get the liveplatform_datato finalize the correct completion.Fixes e651a1da442a ("HID: hid-sensor-hub: Allow parallel synchronous reads")
Quoted 5 lines
Acked-by Jiri Kosina <[email protected]>Are you planning to merge this together with the rest of the set, or do you want me to expedite it? I'll be happy to apply it separately as a proper fix.
This change was more or less a surprise find, because I wanted to make the platform_data pointer in the mfd_cell struct const and this the hid sensor hub stood out as doing something strange ;-) .
So patch 2 of this series actually depends on this change to not cause build errors.
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
Heiko
Jiri Kosina
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 6 lines · Heiko Stübner
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Lee Jones
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 9 lines · Jiri Kosina
Quoted 6 lines · Heiko Stübner
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Quoted 7 lines
Ah, right.
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Signature · 1 line
Lee Jones [李琼斯]
Lee Jones
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 13 lines · Lee Jones
Quoted 11 lines · Jiri Kosina
Quoted 6 lines · Heiko Stübner
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Looking to apply this set now.
Ack please.
Signature · 1 line
Lee Jones [李琼斯]
Jiri Kosina
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 13 lines · Lee Jones
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Looking to apply this set now.
Ack please.
I'd preferer if Srinivas could ack this as the more specific maintainer. Srinivas, please?
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Heiko Stübner
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Am Mittwoch, 11. Dezember 2024, 13:24:42 CET schrieb Jiri Kosina:
Quoted 17 lines · Lee Jones
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I can take it now with an Ack.
Looking to apply this set now.
Ack please.
I'd preferer if Srinivas could ack this as the more specific maintainer. Srinivas, please?
The patch already includes the
Ack from Srinivas Pandruvada <[email protected]>
from a previous version, so I guess it should be ok already?
Re: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 19 lines · Heiko Stübner
Quoted 19 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Looking to apply this set now.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Ack please.
I'd preferer if Srinivas could ack this as the more specific maintainer. Srinivas, please?
The patch already includes the
Ack from Srinivas Pandruvada <[email protected]>
from a previous version, so I guess it should be ok already?
Ah, I missed that, indeed, sorry for the noise.
With that
and Lee, please feel free to take it.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Lee Jones
maintainerRe: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 30 lines · Jiri Kosina
Quoted 19 lines · Heiko Stübner
Quoted 19 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
This change was more or less a surprise find, because I wanted to make the
platform_datapointer in themfd_cellstruct const and this the hid sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause build errors.
Ah, right.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the mcu series might need to wait after 6.13-rc1 anyway - but I guess that depends on how Lee sees things ;-) .
OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Looking to apply this set now.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Ack please.
I'd preferer if Srinivas could ack this as the more specific maintainer. Srinivas, please?
The patch already includes the
Ack from Srinivas Pandruvada <[email protected]>
from a previous version, so I guess it should be ok already?
Quoted 7 lines
Ah, I missed that, indeed, sorry for the noise.
With that
Acked-by Jiri Kosina <[email protected]>and Lee, please feel free to take it.
Thanks, will do.
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v9 1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
In reply to Jiri KosinaQuoted 24 lines · Jiri Kosina
Quoted 22 lines · Lee Jones
Quoted 21 lines
Quoted 12 lines
Quoted 9 lines
This change was more or less a surprise find, because I wanted to make
theplatform_datapointer in themfd_cellstruct const and this the hid
sensor hub stood out as doing something strange ;-) .So patch 2 of this series actually depends on this change to not cause
build errors.Ah, right.
Quoted 7 lines
Quoted 5 lines
But seeing that we're after -rc6 alredy, I would assume the brunt of the
mcu series might need to wait after 6.13-rc1 anyway - but I guess that
depends on how Lee sees things ;-) .OK, I am keeping my hands off it for the time being.
I can take it now with an Ack.
Quoted 7 lines
Quoted 3 lines
Looking to apply this set now.
Ack please.
I'd preferer if Srinivas could ack this as the more specific maintainer.
Srinivas, please?
My ACK is already in the patch:
reads")
Thanks,
Srinivas
Quoted 3 lines
Thanks,
Heiko Stuebner
maintainerPATCH v9 2/9 mfd: core: make platform_data pointer const in struct mfd_cell
In reply to Heiko StuebnerThe content of the platform_data of a struct mfd_cell is simply passed on to the platform_device_add_data() call in mfd_add_device() .
platform_device_add_data() already handles the data behind that pointer as const and also uses kmemdup to create a copy of the data before handing that copy over to the newly created platform-device, so there is no reason to not extend this to struct mfd_cell, as the old copy in the mfd_cell will be stale anyway.
This allows to pass structs gathered from of_device_get_match_data() as platform-data to sub-devices - which is retrieved as const already.
--- include/linux/mfd/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mfd/core.h +1 -1
@@ -72,7 +72,7 @@ struct mfd_cell {int (*resume)(struct platform_device *dev);/* platform data passed to the sub devices drivers */ -void *platform_data; +const void *platform_data;size_t pdata_size;/* Matches ACPI */
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 3/9 dt-bindings: mfd: add binding for qnap,ts433-mcu devices
In reply to Heiko StuebnerThese MCUs can be found in network attached storage devices made by QNAP. They are connected to a serial port of the host device and provide functionality like LEDs, power-control and temperature monitoring.
LEDs, buttons, etc are all elements of the MCU firmware itself, so don't need devicetree input, though the fan gets its cooling settings from a fan-0 subnode.
A binding for the LEDs for setting the linux-default-trigger may come later, once all the LEDs are understood and ATA controllers actually can address individual port-LEDs, but are really optional.
--- .../bindings/mfd/qnap,ts433-mcu.yaml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/qnap,ts433-mcu.yaml
Documentation/devicetree/bindings/mfd/qnap,ts433-mcu.yaml new file +42 -0
@@ -0,0 +1,42 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/qnap,ts433-mcu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: QNAP NAS on-board Microcontroller + +maintainers: + - Heiko Stuebner <[email protected]> + +description: + QNAP embeds a microcontroller on their NAS devices adding system feature + as PWM Fan control, additional LEDs, power button status and more. + +properties: + compatible: + enum: + - qnap,ts433-mcu + +patternProperties: + "^fan-[0-9]+$": + $ref: /schemas/hwmon/fan-common.yaml# + unevaluatedProperties: false + +required: + - compatible + +additionalProperties: false + +examples: + - | + uart { + mcu { + compatible = "qnap,ts433-mcu"; + + fan-0 { + #cooling-cells = <2>; + cooling-levels = <0 64 89 128 166 204 221 238>; + }; + }; + };
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 4/9 mfd: add base driver for qnap-mcu devices
In reply to Heiko StuebnerThese microcontroller units are used in network-attached-storage devices made by QNAP and provide additional functionality to the system.
This adds the base driver that implements the serial protocol via serdev and additionally hooks into the poweroff handlers to turn off the parts of the system not supplied by the general PMIC.
Turning off (at least the TSx33 devices using Rockchip SoCs) consists of two separate actions. Turning off the MCU alone does not turn off the main SoC and turning off only the SoC/PMIC does not turn off the hard-drives. Also if the MCU is not turned off, the system also won't start again until it is unplugged from power.
So on shutdown the MCU needs to be turned off separately before the main PMIC.
The protocol spoken by the MCU is sadly not documented, but was obtained by listening to the chatter on the serial port, as thankfully the "hal_app" program from QNAPs firmware allows triggering all/most MCU actions from the command line.
The implementation of how to talk to the serial device got some inspiration from the rave-sp servdev driver.
--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++++++++++++++++++ include/linux/mfd/qnap-mcu.h | 26 +++ 5 files changed, 385 insertions(+) create mode 100644 drivers/mfd/qnap-mcu.c create mode 100644 include/linux/mfd/qnap-mcu.h
MAINTAINERS +6 -0
@@ -18878,6 +18878,12 @@ L: [email protected] S: Odd Fixes F: drivers/media/tuners/qm1d1c0042* +QNAP MCU DRIVER +M: Heiko Stuebner <[email protected]> +S: Maintained +F: drivers/mfd/qnap-mcu.c +F: include/linux/qnap-mcu.h + QNX4 FILESYSTEM M: Anders Larsen <[email protected]> S: Maintained
drivers/mfd/Kconfig +13 -0
@@ -2386,6 +2386,19 @@ config MFD_INTEL_M10_BMC_PMCI additional drivers must be enabled in order to use the functionality of the device. +config MFD_QNAP_MCU + tristate "QNAP microcontroller unit core driver" + depends on SERIAL_DEV_BUS + select MFD_CORE + help + Select this to get support for the QNAP MCU device found in + several devices of QNAP network attached storage products that + implements additional functionality for the device, like fan + and LED control. + + This driver implements the base serial protocol to talk to the + device and provides functions for the other parts to hook into. + config MFD_RSMU_I2C tristate "Renesas Synchronization Management Unit with I2C" depends on I2C && OF
drivers/mfd/Makefile +2 -0
@@ -288,5 +288,7 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC_PMCI) += intel-m10-bmc-pmci.o obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o obj-$(CONFIG_MFD_ATC260X_I2C) += atc260x-i2c.o +obj-$(CONFIG_MFD_QNAP_MCU) += qnap-mcu.o + obj-$(CONFIG_MFD_RSMU_I2C) += rsmu_i2c.o rsmu_core.o obj-$(CONFIG_MFD_RSMU_SPI) += rsmu_spi.o rsmu_core.o
drivers/mfd/qnap-mcu.c new file +338 -0
338 lines not on this page · raw message
include/linux/mfd/qnap-mcu.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Core definitions for QNAP MCU MFD driver. +* Copyright (C) 2024 Heiko Stuebner <[email protected]> +*/ + +#ifndef _LINUX_QNAP_MCU_H_ +#define _LINUX_QNAP_MCU_H_ + +struct qnap_mcu ; + +struct qnap_mcu_variant { +u32 baud_rate; +int num_drives; +int fan_pwm_min; +int fan_pwm_max; +bool usb_led; +}; + +int qnap_mcu_exec (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size, +u8 *reply_data,size_t reply_data_size); +int qnap_mcu_exec_with_ack (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size); + +#endif /* _LINUX_QNAP_MCU_H_ */
Signature · 1 line
2.45.2
Re: [PATCH v9 4/9] mfd: add base driver for qnap-mcu devices
Op 07-11-2024 om 12:47 schreef Heiko Stuebner:
Quoted 62 lines
These microcontroller units are used in network-attached-storage devices made by QNAP and provide additional functionality to the system.
This adds the base driver that implements the serial protocol via serdev and additionally hooks into the poweroff handlers to turn off the parts of the system not supplied by the general PMIC.
Turning off (at least the TSx33 devices using Rockchip SoCs) consists of two separate actions. Turning off the MCU alone does not turn off the main SoC and turning off only the SoC/PMIC does not turn off the hard-drives. Also if the MCU is not turned off, the system also won't start again until it is unplugged from power.
So on shutdown the MCU needs to be turned off separately before the main PMIC.
The protocol spoken by the MCU is sadly not documented, but was obtained by listening to the chatter on the serial port, as thankfully the "
hal_app" program from QNAPs firmware allows triggering all/most MCU actions from the command line.The implementation of how to talk to the serial device got some inspiration from the rave-sp servdev driver.
Signed-off-by Heiko Stuebner <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++++++++++++++++++ include/linux/mfd/qnap-mcu.h | 26 +++ 5 files changed, 385 insertions(+)create mode 100644
drivers/mfd/qnap-mcu.c
create mode 100644include/linux/mfd/qnap-mcu.h[...]
drivers/mfd/qnap-mcu.c new file +20
-0+int qnap_mcu_exec (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size, +u8 *reply_data,size_t reply_data_size) +{ +unsigned char rx[QNAP_MCU_RX_BUFFER_SIZE ]; +size_t length = reply_data_size +QNAP_MCU_CHECKSUM_SIZE ; +struct qnap_mcu_reply *reply = &mcu->reply; +int ret =0 ; + +if (length >sizeof (rx)) { +dev_err (&mcu->serdev->dev,"expected data too big for receive buffer" ); +return -EINVAL ; + } + +mutex_lock (&mcu->bus_lock); + + reply->data = rx, + reply->length = length, + reply->received =0 , +reinit_completion (&reply->done);
drivers/mfd/qnap-mcu.c line 174
Quoted 10 lines
drivers/mfd/qnap-mcu.c new file +10
-0+ +qnap_mcu_write (mcu, cmd_data, cmd_data_size); + +serdev_device_wait_until_sent (mcu->serdev,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS )); + +if (!wait_for_completion_timeout (&reply->done,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS ))) { +dev_err (&mcu->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ; + }else { +u8 crc =qnap_mcu_csum (rx, reply_data_size);
Here rx is still not initialized.
Quoted 15 lines
drivers/mfd/qnap-mcu.c new file +14
-0+ +if (crc != rx[reply_data_size]) { +dev_err (&mcu->serdev->dev, +"Invalid Checksum received\n" ); + ret = -EIO ; + }else { +memcpy (reply_data, rx, reply_data_size); + } + } + +mutex_unlock (&mcu->bus_lock); +return ret; +} +EXPORT_SYMBOL_GPL (qnap_mcu_exec);
Heiko Stübner
maintainerRe: [PATCH v9 4/9] mfd: add base driver for qnap-mcu devices
Hi Kees,
Am Donnerstag, 19. Dezember 2024, 20:18:38 CET schrieb Kees Bakker:
Quoted 66 lines
Op 07-11-2024 om 12:47 schreef Heiko Stuebner:
Quoted 65 lines
These microcontroller units are used in network-attached-storage devices made by QNAP and provide additional functionality to the system.
This adds the base driver that implements the serial protocol via serdev and additionally hooks into the poweroff handlers to turn off the parts of the system not supplied by the general PMIC.
Turning off (at least the TSx33 devices using Rockchip SoCs) consists of two separate actions. Turning off the MCU alone does not turn off the main SoC and turning off only the SoC/PMIC does not turn off the hard-drives. Also if the MCU is not turned off, the system also won't start again until it is unplugged from power.
So on shutdown the MCU needs to be turned off separately before the main PMIC.
The protocol spoken by the MCU is sadly not documented, but was obtained by listening to the chatter on the serial port, as thankfully the "
hal_app" program from QNAPs firmware allows triggering all/most MCU actions from the command line.The implementation of how to talk to the serial device got some inspiration from the rave-sp servdev driver.
Signed-off-by Heiko Stuebner <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++++++++++++++++++ include/linux/mfd/qnap-mcu.h | 26 +++ 5 files changed, 385 insertions(+)create mode 100644
drivers/mfd/qnap-mcu.c
create mode 100644include/linux/mfd/qnap-mcu.h[...]
drivers/mfd/qnap-mcu.c new file +23
-0+int qnap_mcu_exec (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size, +u8 *reply_data,size_t reply_data_size) +{ +unsigned char rx[QNAP_MCU_RX_BUFFER_SIZE ]; +size_t length = reply_data_size +QNAP_MCU_CHECKSUM_SIZE ; +struct qnap_mcu_reply *reply = &mcu->reply; +int ret =0 ; + +if (length >sizeof (rx)) { +dev_err (&mcu->serdev->dev,"expected data too big for receive buffer" ); +return -EINVAL ; + } + +mutex_lock (&mcu->bus_lock); + + reply->data = rx, + reply->length = length, + reply->received =0 , +reinit_completion (&reply->done); + +qnap_mcu_write (mcu, cmd_data, cmd_data_size); +
Quoted 8 lines
drivers/mfd/qnap-mcu.c line 174
Quoted 7 lines
drivers/mfd/qnap-mcu.c new file +7
-0+serdev_device_wait_until_sent (mcu->serdev,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS )); + +if (!wait_for_completion_timeout (&reply->done,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS ))) { +dev_err (&mcu->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ; + }else { +u8 crc =qnap_mcu_csum (rx, reply_data_size);Here
rxis still not initialized.
The MCU works in a way that a sent command always causes "reply_data_size" bytes to be returned.
So for each qnap_mcu_write() above we know that this amount of bytes has been returned (and thus written into rx) if the completion above finishes sucessfully.
"rx" is assigned to reply->data above (same as the expected received size). When characters are received on the serial line, this will trigger qnap_mcu_receive_buf() from the serdev and thus fill those elements in rx.
So if we land at the qnap_mcu_csum() call, we do have received the expected amount of bytes from the serdev and thus rx is filled accordingly.
If we don't receive the needed amount of bytes, we end up in the timeout above that.
What did I miss?
Heiko
Quoted 16 lines
Quoted 15 lines
drivers/mfd/qnap-mcu.c new file +14
-0+ +if (crc != rx[reply_data_size]) { +dev_err (&mcu->serdev->dev, +"Invalid Checksum received\n" ); + ret = -EIO ; + }else { +memcpy (reply_data, rx, reply_data_size); + } + } + +mutex_unlock (&mcu->bus_lock); +return ret; +} +EXPORT_SYMBOL_GPL (qnap_mcu_exec);
Re: [PATCH v9 4/9] mfd: add base driver for qnap-mcu devices
Op 19-12-2024 om 20:43 schreef Heiko Stübner:
Quoted 88 lines
Hi Kees,
Am Donnerstag, 19. Dezember 2024, 20:18:38 CET schrieb Kees Bakker:
Quoted 66 lines
Op 07-11-2024 om 12:47 schreef Heiko Stuebner:
Quoted 65 lines
These microcontroller units are used in network-attached-storage devices made by QNAP and provide additional functionality to the system.
This adds the base driver that implements the serial protocol via serdev and additionally hooks into the poweroff handlers to turn off the parts of the system not supplied by the general PMIC.
Turning off (at least the TSx33 devices using Rockchip SoCs) consists of two separate actions. Turning off the MCU alone does not turn off the main SoC and turning off only the SoC/PMIC does not turn off the hard-drives. Also if the MCU is not turned off, the system also won't start again until it is unplugged from power.
So on shutdown the MCU needs to be turned off separately before the main PMIC.
The protocol spoken by the MCU is sadly not documented, but was obtained by listening to the chatter on the serial port, as thankfully the "
hal_app" program from QNAPs firmware allows triggering all/most MCU actions from the command line.The implementation of how to talk to the serial device got some inspiration from the rave-sp servdev driver.
Signed-off-by Heiko Stuebner <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++++++++++++++++++ include/linux/mfd/qnap-mcu.h | 26 +++ 5 files changed, 385 insertions(+)create mode 100644
drivers/mfd/qnap-mcu.ccreate mode 100644include/linux/mfd/qnap-mcu.h[...]
drivers/mfd/qnap-mcu.c new file +23
-0+int qnap_mcu_exec (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size, +u8 *reply_data,size_t reply_data_size) +{ +unsigned char rx[QNAP_MCU_RX_BUFFER_SIZE ]; +size_t length = reply_data_size +QNAP_MCU_CHECKSUM_SIZE ; +struct qnap_mcu_reply *reply = &mcu->reply; +int ret =0 ; + +if (length >sizeof (rx)) { +dev_err (&mcu->serdev->dev,"expected data too big for receive buffer" ); +return -EINVAL ; + } + +mutex_lock (&mcu->bus_lock); + + reply->data = rx, + reply->length = length, + reply->received =0 , +reinit_completion (&reply->done); + +qnap_mcu_write (mcu, cmd_data, cmd_data_size); +Quoted 8 lines
drivers/mfd/qnap-mcu.c line 174
Quoted 7 lines
drivers/mfd/qnap-mcu.c new file +7
-0+serdev_device_wait_until_sent (mcu->serdev,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS )); + +if (!wait_for_completion_timeout (&reply->done,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS ))) { +dev_err (&mcu->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ; + }else { +u8 crc =qnap_mcu_csum (rx, reply_data_size);Here
rxis still not initialized.The MCU works in a way that a sent command always causes "
reply_data_size" bytes to be returned.So for each
qnap_mcu_write()above we know that this amount of bytes has been returned (and thus written into rx) if the completion above finishes sucessfully."rx" is assigned to
reply->dataabove (same as the expected received size). When characters are received on the serial line, this will triggerqnap_mcu_receive_buf()from the serdev and thus fill those elements in rx.
Quoted 7 lines
So if we land at the
qnap_mcu_csum()call, we do have received the expected amount of bytes from the serdev and thus rx is filled accordingly.If we don't receive the needed amount of bytes, we end up in the timeout above that.
What did I miss?
Sorry, my fault. I missed the essential part of the external event (external for this function that is).
Thanks for explaining.
Quoted 22 lines
Heiko
Quoted 15 lines
Quoted 15 lines
drivers/mfd/qnap-mcu.c new file +14
-0+ +if (crc != rx[reply_data_size]) { +dev_err (&mcu->serdev->dev, +"Invalid Checksum received\n" ); + ret = -EIO ; + }else { +memcpy (reply_data, rx, reply_data_size); + } + } + +mutex_unlock (&mcu->bus_lock); +return ret; +} +EXPORT_SYMBOL_GPL (qnap_mcu_exec);
Heiko Stübner
maintainerRe: [PATCH v9 4/9] mfd: add base driver for qnap-mcu devices
Am Donnerstag, 19. Dezember 2024, 20:51:41 CET schrieb Kees Bakker:
Quoted 92 lines
Op 19-12-2024 om 20:43 schreef Heiko Stübner:
Quoted 91 lines
Hi Kees,
Am Donnerstag, 19. Dezember 2024, 20:18:38 CET schrieb Kees Bakker:
Quoted 66 lines
Op 07-11-2024 om 12:47 schreef Heiko Stuebner:
Quoted 65 lines
These microcontroller units are used in network-attached-storage devices made by QNAP and provide additional functionality to the system.
This adds the base driver that implements the serial protocol via serdev and additionally hooks into the poweroff handlers to turn off the parts of the system not supplied by the general PMIC.
Turning off (at least the TSx33 devices using Rockchip SoCs) consists of two separate actions. Turning off the MCU alone does not turn off the main SoC and turning off only the SoC/PMIC does not turn off the hard-drives. Also if the MCU is not turned off, the system also won't start again until it is unplugged from power.
So on shutdown the MCU needs to be turned off separately before the main PMIC.
The protocol spoken by the MCU is sadly not documented, but was obtained by listening to the chatter on the serial port, as thankfully the "
hal_app" program from QNAPs firmware allows triggering all/most MCU actions from the command line.The implementation of how to talk to the serial device got some inspiration from the rave-sp servdev driver.
Signed-off-by Heiko Stuebner <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++++++++++++++++++ include/linux/mfd/qnap-mcu.h | 26 +++ 5 files changed, 385 insertions(+)create mode 100644
drivers/mfd/qnap-mcu.ccreate mode 100644include/linux/mfd/qnap-mcu.h[...]
drivers/mfd/qnap-mcu.c new file +23
-0+int qnap_mcu_exec (struct qnap_mcu *mcu, +const u8 *cmd_data,size_t cmd_data_size, +u8 *reply_data,size_t reply_data_size) +{ +unsigned char rx[QNAP_MCU_RX_BUFFER_SIZE ]; +size_t length = reply_data_size +QNAP_MCU_CHECKSUM_SIZE ; +struct qnap_mcu_reply *reply = &mcu->reply; +int ret =0 ; + +if (length >sizeof (rx)) { +dev_err (&mcu->serdev->dev,"expected data too big for receive buffer" ); +return -EINVAL ; + } + +mutex_lock (&mcu->bus_lock); + + reply->data = rx, + reply->length = length, + reply->received =0 , +reinit_completion (&reply->done); + +qnap_mcu_write (mcu, cmd_data, cmd_data_size); +Quoted 8 lines
drivers/mfd/qnap-mcu.c line 174
Quoted 7 lines
drivers/mfd/qnap-mcu.c new file +7
-0+serdev_device_wait_until_sent (mcu->serdev,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS )); + +if (!wait_for_completion_timeout (&reply->done,msecs_to_jiffies (QNAP_MCU_TIMEOUT_MS ))) { +dev_err (&mcu->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ; + }else { +u8 crc =qnap_mcu_csum (rx, reply_data_size);Here
rxis still not initialized.The MCU works in a way that a sent command always causes "
reply_data_size" bytes to be returned.So for each
qnap_mcu_write()above we know that this amount of bytes has been returned (and thus written into rx) if the completion above finishes sucessfully."rx" is assigned to
reply->dataabove (same as the expected received size). When characters are received on the serial line, this will triggerqnap_mcu_receive_buf()from the serdev and thus fill those elements in rx.So if we land at the
qnap_mcu_csum()call, we do have received the expected amount of bytes from the serdev and thus rx is filled accordingly.
Quoted 7 lines
Quoted 4 lines
If we don't receive the needed amount of bytes, we end up in the timeout above that.
What did I miss?
Sorry, my fault. I missed the essential part of the external event (external for this function that is).
Thanks for explaining.
no worries :-) .
The more eyes, the better.
Heiko
Heiko Stuebner
maintainerPATCH v9 5/9 leds: add driver for LEDs from qnap-mcu devices
In reply to Heiko StuebnerThis adds a driver that connects to the qnap-mcu mfd driver and provides access to the LEDs on it.
--- MAINTAINERS | 1 + drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-qnap-mcu.c | 227 +++++++++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 drivers/leds/leds-qnap-mcu.c
MAINTAINERS +1 -0
@@ -18881,6 +18881,7 @@ F: drivers/media/tuners/qm1d1c0042* QNAP MCU DRIVER M: Heiko Stuebner <[email protected]> S: Maintained +F: drivers/leds/leds-qnap-mcu.c F: drivers/mfd/qnap-mcu.c F: include/linux/qnap-mcu.h
drivers/leds/Kconfig +11 -0
@@ -580,6 +580,17 @@ config LEDS_PCA995X LED driver chips accessed via the I2C bus. Supported devices include PCA9955BTW, PCA9952TW and PCA9955TW. +config LEDS_QNAP_MCU + tristate "LED Support for QNAP MCU controllers" + depends on LEDS_CLASS + depends on MFD_QNAP_MCU + help + This option enables support for LEDs available on embedded + controllers used in QNAP NAS devices. + + This driver can also be built as a module. If so, the module + will be called qnap-mcu-leds. + config LEDS_WM831X_STATUS tristate "LED support for status LEDs on WM831x PMICs" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_LEDS_PCA995X) += leds-pca995x.o obj-$(CONFIG_LEDS_PM8058) += leds-pm8058.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_PWM) += leds-pwm.o +obj-$(CONFIG_LEDS_QNAP_MCU) += leds-qnap-mcu.o obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o
drivers/leds/leds-qnap-mcu.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 6/9 Input: add driver for the input part of qnap-mcu devices
In reply to Heiko StuebnerThe MCU controls the power-button and beeper, so expose them as input device. There is of course no interrupt line, so the status of the power-button needs to be polled. To generate an event the power-button also needs to be held for 1-2 seconds, so the polling interval does not need to be overly fast.
--- MAINTAINERS | 1 + drivers/input/misc/Kconfig | 12 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/qnap-mcu-input.c | 153 ++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 drivers/input/misc/qnap-mcu-input.c
MAINTAINERS +1 -0
@@ -18881,6 +18881,7 @@ F: drivers/media/tuners/qm1d1c0042* QNAP MCU DRIVER M: Heiko Stuebner <[email protected]> S: Maintained +F: drivers/input/misc/qnap-mcu-input.c F: drivers/leds/leds-qnap-mcu.c F: drivers/mfd/qnap-mcu.c F: include/linux/qnap-mcu.h
drivers/input/misc/Kconfig +12 -0
@@ -917,6 +917,18 @@ config INPUT_HISI_POWERKEY To compile this driver as a module, choose M here: the module will be called hisi_powerkey. +config INPUT_QNAP_MCU + tristate "Input Support for QNAP MCU controllers" + depends on MFD_QNAP_MCU + help + This option enables support for input elements available on + embedded controllers used in QNAP NAS devices. + + This includes a polled power-button as well as a beeper. + + To compile this driver as a module, choose M here: the + module will be called qnap-mcu-input. + config INPUT_RAVE_SP_PWRBUTTON tristate "RAVE SP Power button Driver" depends on RAVE_SP_CORE
drivers/input/misc/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o obj-$(CONFIG_INPUT_POWERMATE) += powermate.o obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o obj-$(CONFIG_INPUT_PWM_VIBRA) += pwm-vibra.o +obj-$(CONFIG_INPUT_QNAP_MCU) += qnap-mcu-input.o obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o obj-$(CONFIG_INPUT_REGULATOR_HAPTIC) += regulator-haptic.o
drivers/input/misc/qnap-mcu-input.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 7/9 hwmon: add driver for the hwmon parts of qnap-mcu devices
In reply to Heiko StuebnerThe MCU can be found on network-attached-storage devices made by QNAP and provides access to fan control including reading back its RPM as well as reading the temperature of the NAS case.
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/qnap-mcu-hwmon.rst | 27 ++ MAINTAINERS | 1 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/qnap-mcu-hwmon.c | 364 +++++++++++++++++++++++++ 6 files changed, 406 insertions(+) create mode 100644 Documentation/hwmon/qnap-mcu-hwmon.rst create mode 100644 drivers/hwmon/qnap-mcu-hwmon.c
Documentation/hwmon/index.rst +1 -0
@@ -199,6 +199,7 @@ Hardware Monitoring Kernel Drivers pxe1610 pwm-fan q54sj108a2 + qnap-mcu-hwmon raspberrypi-hwmon sbrmi sbtsi_temp
Documentation/hwmon/qnap-mcu-hwmon.rst new file +27 -0
@@ -0,0 +1,27 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver qnap-mcu-hwmon +============================ + +This driver enables the use of the hardware monitoring and fan control +of the MCU used on some QNAP network attached storage devices. + +Author: Heiko Stuebner <[email protected]> + +Description +----------- + +The driver implements a simple interface for driving the fan controlled by +setting its PWM output value and exposes the fan rpm and case-temperature +to user space through hwmon's sysfs interface. + +The fan rotation speed returned via the optional 'fan1_input' is calculated +inside the MCU device. + +The driver provides the following sensor accesses in sysfs: + +=============== ======= ======================================================= +fan1_input ro fan tachometer speed in RPM +pwm1 rw relative speed (0-255), 255=max. speed. +temp1_input ro Measured temperature in millicelsius +=============== ======= =======================================================
MAINTAINERS +1 -0
@@ -18881,6 +18881,7 @@ F: drivers/media/tuners/qm1d1c0042* QNAP MCU DRIVER M: Heiko Stuebner <[email protected]> S: Maintained +F: drivers/hwmon/qnap-mcu-hwmon.c F: drivers/input/misc/qnap-mcu-input.c F: drivers/leds/leds-qnap-mcu.c F: drivers/mfd/qnap-mcu.c
drivers/hwmon/Kconfig +12 -0
@@ -1800,6 +1800,18 @@ config SENSORS_PWM_FAN This driver can also be built as a module. If so, the module will be called pwm-fan. +config SENSORS_QNAP_MCU_HWMON + tristate "QNAP MCU hardware monitoring" + depends on MFD_QNAP_MCU + depends on THERMAL || THERMAL=n + help + Say yes here to enable support for fan and temperature sensor + connected to a QNAP MCU, as found in a number of QNAP network + attached storage devices. + + This driver can also be built as a module. If so, the module + will be called qnap-mcu-hwmon. + config SENSORS_RASPBERRYPI_HWMON tristate "Raspberry Pi voltage monitor" depends on RASPBERRYPI_FIRMWARE || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
drivers/hwmon/Makefile +1 -0
@@ -187,6 +187,7 @@ obj-$(CONFIG_SENSORS_POWERZ) += powerz.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o +obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.o obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o obj-$(CONFIG_SENSORS_SBTSI) += sbtsi_temp.o obj-$(CONFIG_SENSORS_SBRMI) += sbrmi.o
drivers/hwmon/qnap-mcu-hwmon.c new file +364 -0
364 lines not on this page · raw message
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 8/9 arm64: dts: rockchip: hook up the MCU on the QNAP TS433
In reply to Heiko StuebnerThe MCU is an important part of the device functionality. It provides functionality like fan-control, more leds, etc and even more important without it, the NAS-device cannot even fully turned off.
Hook up the serial device to its uart and hook into the thermal management to control the fan according to the cpu temperature.
While the MCU also provides a temperature sensor for the case, this one is just polled and does not provide functionality for handling trip points in hardware, so a lot of polling would be involved. As the cpu is only cooled passively in these devices, it's temperature rising will indicate the temperature level of the system just earlier.
--- .../boot/dts/rockchip/rk3568-qnap-ts433.dts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+)
arch/arm64/boot/dts/rockchip/rk3568-qnap-ts433.dts +57 -0
@@ -483,6 +483,54 @@ rgmii_phy0: ethernet-phy@0 { }; }; +/* + * The MCU can provide system temperature too, but only by polling and of + * course also cannot set trip points. So attach to the cpu thermal-zone + * instead to control the fan. + */ +&cpu_thermal { + trips { + case_fan0: case-fan0 { + hysteresis = <2000>; + temperature = <35000>; + type = "active"; + }; + + case_fan1: case-fan1 { + hysteresis = <2000>; + temperature = <45000>; + type = "active"; + }; + + case_fan2: case-fan2 { + hysteresis = <2000>; + temperature = <65000>; + type = "active"; + }; + }; + + cooling-maps { + /* + * Always provide some air movement, due to small case + * full of harddrives. + */ + map1 { + cooling-device = <&fan THERMAL_NO_LIMIT 1>; + trip = <&case_fan0>; + }; + + map2 { + cooling-device = <&fan 2 3>; + trip = <&case_fan1>; + }; + + map3 { + cooling-device = <&fan 4 THERMAL_NO_LIMIT>; + trip = <&case_fan2>; + }; + }; +}; + &pcie30phy { data-lanes = <1 2>; status = "okay";
@@ -582,6 +630,15 @@ &tsadc { */ &uart0 { status = "okay"; + + mcu { + compatible = "qnap,ts433-mcu"; + + fan: fan-0 { + #cooling-cells = <2>; + cooling-levels = <0 64 89 128 166 204 221 238>; + }; + }; }; /*
Signature · 1 line
2.45.2
Heiko Stuebner
maintainerPATCH v9 9/9 arm64: dts: rockchip: set hdd led labels on qnap-ts433
In reply to Heiko StuebnerThe automatically generated names for the LEDs from color and function do not match nicely for the 4 hdds, so set them manually per the label property to also match the LEDs generated from the MCU.
--- arch/arm64/boot/dts/rockchip/rk3568-qnap-ts433.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/rockchip/rk3568-qnap-ts433.dts +4 -0
@@ -50,6 +50,7 @@ led-0 { color = <LED_COLOR_ID_GREEN>; function = LED_FUNCTION_DISK; gpios = <&gpio1 RK_PD5 GPIO_ACTIVE_LOW>; + label = "hdd1:green:disk"; linux,default-trigger = "disk-activity"; pinctrl-names = "default"; pinctrl-0 = <&hdd1_led_pin>;
@@ -59,6 +60,7 @@ led-1 { color = <LED_COLOR_ID_GREEN>; function = LED_FUNCTION_DISK; gpios = <&gpio1 RK_PD6 GPIO_ACTIVE_LOW>; + label = "hdd2:green:disk"; linux,default-trigger = "disk-activity"; pinctrl-names = "default"; pinctrl-0 = <&hdd2_led_pin>;
@@ -68,6 +70,7 @@ led-2 { color = <LED_COLOR_ID_GREEN>; function = LED_FUNCTION_DISK; gpios = <&gpio1 RK_PD7 GPIO_ACTIVE_LOW>; + label = "hdd3:green:disk"; linux,default-trigger = "disk-activity"; pinctrl-names = "default"; pinctrl-0 = <&hdd3_led_pin>;
@@ -77,6 +80,7 @@ led-3 { color = <LED_COLOR_ID_GREEN>; function = LED_FUNCTION_DISK; gpios = <&gpio2 RK_PA0 GPIO_ACTIVE_LOW>; + label = "hdd4:green:disk"; linux,default-trigger = "disk-activity"; pinctrl-names = "default"; pinctrl-0 = <&hdd4_led_pin>;
Signature · 1 line
2.45.2
Quoted 11 lines · Heiko Stuebner
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
[...]
Applied, thanks!
[1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
commit: e079a120f31e3f9c00180aa13c1df18cc138f7fe
[2/9] mfd: core: make platform_data pointer const in struct mfd_cell
commit: 8f4009ad901c44f0428dbde654c4dd1fb29c863b
[3/9] dt-bindings: mfd: add binding for qnap,ts433-mcu devices
commit: 8877bcff3e3b4f08a1fc0232dbfdaeda085cfdf3
[4/9] mfd: add base driver for qnap-mcu devices
commit: 944ca826f69e4723853b3876875b03aeafe67b60
[5/9] leds: add driver for LEDs from qnap-mcu devices
commit: fe6a21ee38f12e3e5f9adbd2f9a840be105b943f
[6/9] Input: add driver for the input part of qnap-mcu devices
commit: 4b27e0da257371d3d141fae38fdbdc3c3a67bce6
[7/9] hwmon: add driver for the hwmon parts of qnap-mcu devices
commit: 41755872a8a8ab8d1644459d9634c53b743fe2be[8/9] arm64: dts: rockchip: hook up the MCU on the QNAP TS433
(no commit info)
[9/9] arm64: dts: rockchip: set hdd led labels on qnap-ts433
(no commit info)
--
Lee Jones [李琼斯]
Lee Jones
maintainerQuoted 30 lines · Lee Jones
Quoted 11 lines · Heiko Stuebner
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
[...]
Applied, thanks!
[1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
commit: e079a120f31e3f9c00180aa13c1df18cc138f7fe [2/9] mfd: core: make platform_data pointer const in struct mfd_cell commit: 8f4009ad901c44f0428dbde654c4dd1fb29c863b [3/9] dt-bindings: mfd: add binding for qnap,ts433-mcu devices commit: 8877bcff3e3b4f08a1fc0232dbfdaeda085cfdf3 [4/9] mfd: add base driver for qnap-mcu devices commit: 944ca826f69e4723853b3876875b03aeafe67b60 [5/9] leds: add driver for LEDs from qnap-mcu devices commit: fe6a21ee38f12e3e5f9adbd2f9a840be105b943f [6/9] Input: add driver for the input part of qnap-mcu devicesj commit: 4b27e0da257371d3d141fae38fdbdc3c3a67bce6 [7/9] hwmon: add driver for the hwmon parts of qnap-mcu devices commit: 41755872a8a8ab8d1644459d9634c53b743fe2be
Quoted 4 lines
[8/9] arm64: dts: rockchip: hook up the MCU on the QNAP TS433
(no commit info)
[9/9] arm64: dts: rockchip: set hdd led labels on qnap-ts433
(no commit info)
As you can see, I have _not_ applied these two DTS patches.
Signature · 1 line
Lee Jones [李琼斯]
Lee Jones
maintainerQuoted 16 lines · Lee Jones
Quoted 11 lines · Heiko Stuebner
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
[...]
Applied, thanks!
[1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 13 lines
commit: e079a120f31e3f9c00180aa13c1df18cc138f7fe
[2/9] mfd: core: make platform_data pointer const in struct mfd_cell
commit: 8f4009ad901c44f0428dbde654c4dd1fb29c863b
[3/9] dt-bindings: mfd: add binding for qnap,ts433-mcu devices
commit: 8877bcff3e3b4f08a1fc0232dbfdaeda085cfdf3
[4/9] mfd: add base driver for qnap-mcu devices
commit: 944ca826f69e4723853b3876875b03aeafe67b60
[5/9] leds: add driver for LEDs from qnap-mcu devices
commit: fe6a21ee38f12e3e5f9adbd2f9a840be105b943f
[6/9] Input: add driver for the input part of qnap-mcu devices
commit: 4b27e0da257371d3d141fae38fdbdc3c3a67bce6
[7/9] hwmon: add driver for the hwmon parts of qnap-mcu devices
commit: 41755872a8a8ab8d1644459d9634c53b743fe2beOnce build testing is complete, I'll send out a PR.
Note to self: ib-mfd-hid-hwmon-input-leds-6.14
Signature · 1 line
Lee Jones [李琼斯]
Heiko Stübner
maintainerAm Donnerstag, 12. Dezember 2024, 18:19:54 CET schrieb Lee Jones:
Quoted 32 lines · Lee Jones
Quoted 17 lines · Heiko Stuebner
Quoted 11 lines
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
[...]
Applied, thanks!
[1/9] HID: hid-sensor-hub: don't use stale platform-data on remove
Quoted 13 lines
commit: e079a120f31e3f9c00180aa13c1df18cc138f7fe [2/9] mfd: core: make platform_data pointer const in struct mfd_cell commit: 8f4009ad901c44f0428dbde654c4dd1fb29c863b [3/9] dt-bindings: mfd: add binding for qnap,ts433-mcu devices commit: 8877bcff3e3b4f08a1fc0232dbfdaeda085cfdf3 [4/9] mfd: add base driver for qnap-mcu devices commit: 944ca826f69e4723853b3876875b03aeafe67b60 [5/9] leds: add driver for LEDs from qnap-mcu devices commit: fe6a21ee38f12e3e5f9adbd2f9a840be105b943f [6/9] Input: add driver for the input part of qnap-mcu devices commit: 4b27e0da257371d3d141fae38fdbdc3c3a67bce6 [7/9] hwmon: add driver for the hwmon parts of qnap-mcu devices commit: 41755872a8a8ab8d1644459d9634c53b743fe2be
Quoted 1 line
Once build testing is complete, I'll send out a PR.
thanks a lot for picking up the driver patches.
Heiko
Lee Jones
maintainer[GIT PULL] Immutable branch between MFD, HID, HWMON, Input and LEDs due for the v6.14 merge window
In reply to Heiko StuebnerEnjoy!
The following changes since commit 40384c840ea1944d7c5a392e8975ed088ecf0b37:
Linux 6.13-rc1 (2024-12-01 14:28:56 -0800)
are available in the Git repository at:
ssh://[email protected]/pub/scm/linux/kernel/git/lee/mfd.git tags/ib-mfd-hid-hwmon-input-leds-v6.14
for you to fetch changes up to 9855caf5d4eb1d8b8bba60be256186ea8e0f907c:
hwmon: add driver for the hwmon parts of qnap-mcu devices (2024-12-17 13:14:48 +0000)
----------------------------------------------------------------
Immutable branch between MFD, HID, HWMON, Input and LEDs due for the v6.14 merge window
----------------------------------------------------------------
Heiko Stuebner (7):
HID: hid-sensor-hub: don't use stale platform-data on remove
mfd: core: Make platform_data pointer const in struct mfd_cell
dt-bindings: mfd: Add binding for qnap,ts433-mcu devices
mfd: Add base driver for qnap-mcu devices
leds: Add driver for LEDs from qnap-mcu devices
Input: add driver for the input part of qnap-mcu devices
hwmon: add driver for the hwmon parts of qnap-mcu devices
.../devicetree/bindings/mfd/qnap,ts433-mcu.yaml | 42 +++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/qnap-mcu-hwmon.rst | 27 ++ MAINTAINERS | 9 + drivers/hid/hid-sensor-hub.c | 21 +- drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/qnap-mcu-hwmon.c | 364 +++++++++++++++++++++ drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile | 1 + drivers/input/misc/qnap-mcu-input.c | 153 +++++++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-qnap-mcu.c | 227 +++++++++++++ drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 2 + drivers/mfd/qnap-mcu.c | 338 +++++++++++++++++++ include/linux/mfd/core.h | 2 +- include/linux/mfd/qnap-mcu.h | 26 ++ 19 files changed, 1255 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/qnap,ts433-mcu.yaml create mode 100644 Documentation/hwmon/qnap-mcu-hwmon.rst create mode 100644 drivers/hwmon/qnap-mcu-hwmon.c create mode 100644 drivers/input/misc/qnap-mcu-input.c create mode 100644 drivers/leds/leds-qnap-mcu.c create mode 100644 drivers/mfd/qnap-mcu.c create mode 100644 include/linux/mfd/qnap-mcu.h
Signature · 1 line
Lee Jones [李琼斯]
Re: (subset) [PATCH v9 0/9] Drivers to support the MCU on QNAP NAS devices
In reply to Heiko StuebnerQuoted 11 lines · Heiko Stuebner
This implements a set of drivers for the MCU used on QNAP NAS devices.
Of course no documentation for the serial protocol is available, so thankfully QNAP has a tool on their rescue-inird to talk to the MCU and I found interceptty [0] to listen to what goes over the serial connection.
In general it looks like there are two different generations in general, an "EC" device and now this "MCU" - referenced in the strings of the userspace handlers for those devices.
[...]
Applied, thanks!
[8/9] arm64: dts: rockchip: hook up the MCU on the QNAP TS433
commit: 989e3dd871349e76919911ac628e97ff6cb1ad51
[9/9] arm64: dts: rockchip: set hdd led labels on qnap-ts433
commit: 47f34eab58294d7bb2583f9519b4022e74d56437Best regards,
Signature · 1 line
Heiko Stuebner <[email protected]>