[PATCH 1/2] driver: reset: th1520-aon: add driver for poweroff/reboot via AON FW

Yao Zi ziyao at disroot.org
Mon Aug 18 02:43:13 PDT 2025


On Mon, Aug 18, 2025 at 03:49:05PM +0800, Icenowy Zheng wrote:
> This driver implements poweroff/reboot support for T-Head TH1520 SoCs
> running the AON firmware by sending a message to the AON firmware's WDG
> part.
> 
> This is a auxiliary device driver, and expects the AON channel to be
> passed via the platform_data of the auxiliary device.
> 
> Signed-off-by: Icenowy Zheng <uwu at icenowy.me>
> ---
>  MAINTAINERS                             |  1 +
>  drivers/power/reset/Kconfig             |  7 ++
>  drivers/power/reset/Makefile            |  1 +
>  drivers/power/reset/th1520-aon-reboot.c | 98 +++++++++++++++++++++++++
>  4 files changed, 107 insertions(+)
>  create mode 100644 drivers/power/reset/th1520-aon-reboot.c

...

> diff --git a/drivers/power/reset/th1520-aon-reboot.c b/drivers/power/reset/th1520-aon-reboot.c
> new file mode 100644
> index 0000000000000..8256c1703ebe8
> --- /dev/null
> +++ b/drivers/power/reset/th1520-aon-reboot.c
> @@ -0,0 +1,98 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * T-HEAD TH1520 AON Firmware Reboot Driver
> + *
> + * Copyright (c) 2025 Icenowy Zheng <uwu at icenowy.me>
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/firmware/thead/thead,th1520-aon.h>
> +#include <linux/module.h>
> +#include <linux/notifier.h>
> +#include <linux/of.h>
> +#include <linux/reboot.h>
> +#include <linux/slab.h>
> +
> +#define TH1520_AON_REBOOT_PRIORITY 200
> +
> +struct th1520_aon_msg_empty_body {
> +	struct th1520_aon_rpc_msg_hdr hdr;
> +	u16 reserved[12];
> +} __packed __aligned(1);
> +
> +static int th1520_aon_pwroff_handler(struct sys_off_data *data)
> +{
> +	struct th1520_aon_chan *aon_chan = data->cb_data;
> +	struct th1520_aon_msg_empty_body msg = {};
> +
> +	msg.hdr.svc = TH1520_AON_RPC_SVC_WDG;
> +	msg.hdr.func = TH1520_AON_WDG_FUNC_POWER_OFF;
> +	msg.hdr.size = TH1520_AON_RPC_MSG_NUM;
> +
> +	th1520_aon_call_rpc(aon_chan, &msg);

It's possible for th1520_aon_call_rpc() to fail. Should we check for its
return value and emit a warning/error if it fails? Though in case of
failure there may not be much we could do...

> +	return NOTIFY_DONE;
> +}

Best regards,
Yao Zi



More information about the linux-riscv mailing list