summaryrefslogtreecommitdiff
path: root/drivers/mfd/qnap-mcu.c
AgeCommit message (Collapse)Author
2025-11-21mfd: qnap-mcu: Hook up the EEPROM sub-deviceHeiko Stuebner
Add the qnap-mcu-eeprom platform-driver as sub-device for the MCU. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251103232942.410386-3-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-11-20mfd: qnap-mcu: Add proper error handling for command errorsHeiko Stuebner
Further investigation revealed that the MCU in QNAP devices may return two error states. One "@8" for a checksum error in the submitted command and one "@9" for any generic (and sadly unspecified) error. These error codes with 2 data character can of course also be shorter then the expected reply length for the submitted command, so we'll need to check the received data for error codes and exit the receive portion early in that case. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251113165218.449616-5-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-11-20mfd: qnap-mcu: Move checksum verification to its own functionHeiko Stuebner
We'll need the checksum check in a second place in the future, so move the verification code to a separate function. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251113165218.449616-4-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-11-20mfd: qnap-mcu: Use EPROTO in stead of EIO on checksum errorsHeiko Stuebner
EPROTO stands for protocol error and a lot of driver already use it to designate errors in the sent or received data from a peripheral. So use it in the qnap-mcu as well for checksum errors. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251113165218.449616-3-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-11-20mfd: qnap-mcu: Calculate the checksum on the actual number of bytes receivedHeiko Stuebner
In the case of an error message, the number of received bytes can be less than originally expected but still contain a valid message. If the transfer itself ended in an error we would exit earlier already. So calculate the checksum on the number of received bytes and not the number of expected bytes. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251113165218.449616-2-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-10-01mfd: qnap-mcu: Improve structure in qnap_mcu_execHeiko Stuebner
Now with guard(mutex) in place, we can make the function's structure a bit easier to read, by removing the nested if-else-clauses. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20250804130726.3180806-5-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-10-01mfd: qnap-mcu: Convert to guard(mutex) in qnap_mcu_execHeiko Stuebner
guard() makes sure that the mutex gets unlocked when the function returns and thus removes the need for unlock gotos or similar mechanisms and therefore allows for a simpler function structure. So convert the qnap_mcu_exec function to use it. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20250804130726.3180806-4-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-10-01mfd: qnap-mcu: Handle errors returned from qnap_mcu_writeHeiko Stuebner
qnap_mcu_write can return errors and those were not checked before. So do that now. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20250804130726.3180806-3-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-10-01mfd: qnap-mcu: Add driver data for TS233 variantHeiko Stuebner
Add the TS233 compatible and affiliated driver data to qnap-mcu. The TS233 is mostly similar to the TS433, except not having any of the PCIe components, so there are only 2 drives. The fan pwm-limits from the vendor-configuration also are the same as for the ts433 variant. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20250730173423.1878599-3-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
2025-03-14mfd: qnap-mcu: Convert commas to semicolons in qnap_mcu_exec()Chen Ni
Replace comma between expressions with semicolons. Using a ',' in place of a ';' can have unintended side effects. Although that is not the case here, it is seems best to use ';' unless ',' is intended. Found by inspection. No functional change intended. Compile tested only. Fixes: 998f70d1806b ("mfd: Add base driver for qnap-mcu devices") Signed-off-by: Chen Ni <nichen@iscas.ac.cn> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20250310031145.650950-1-nichen@iscas.ac.cn Signed-off-by: Lee Jones <lee@kernel.org>
2024-12-17mfd: Add base driver for qnap-mcu devicesHeiko Stuebner
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 <heiko@sntech.de> Link: https://lore.kernel.org/r/20241107114712.538976-5-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>