Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -21732,6 +21732,7 @@ F: drivers/mailbox/mailbox-th1520.c
F: drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
F: drivers/pinctrl/pinctrl-th1520.c
F: drivers/pmdomain/thead/
F: drivers/power/reset/th1520-aon-reboot.c
F: drivers/power/sequencing/pwrseq-thead-gpu.c
F: drivers/reset/reset-th1520.c
F: include/dt-bindings/clock/thead,th1520-clk-ap.h
Expand Down
35 changes: 33 additions & 2 deletions drivers/pmdomain/thead/th1520-pm-domains.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,39 @@ static void th1520_pd_init_all_off(struct generic_pm_domain **domains,
}
}

static void th1520_pd_pwrseq_unregister_adev(void *adev)
static void th1520_pd_unregister_adev(void *adev)
{
auxiliary_device_delete(adev);
auxiliary_device_uninit(adev);
}

static int th1520_pd_reboot_init(struct device *dev, struct th1520_aon_chan *aon_chan)
{
struct auxiliary_device *adev;
int ret;

adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL);
if (!adev)
return -ENOMEM;

adev->name = "reboot";
adev->dev.parent = dev;
adev->dev.platform_data = aon_chan;

ret = auxiliary_device_init(adev);
if (ret)
return ret;

ret = auxiliary_device_add(adev);
if (ret) {
auxiliary_device_uninit(adev);
return ret;
}

return devm_add_action_or_reset(dev, th1520_pd_unregister_adev,
adev);
}

static int th1520_pd_pwrseq_gpu_init(struct device *dev)
{
struct auxiliary_device *adev;
Expand Down Expand Up @@ -169,7 +196,7 @@ static int th1520_pd_pwrseq_gpu_init(struct device *dev)
return ret;
}

return devm_add_action_or_reset(dev, th1520_pd_pwrseq_unregister_adev,
return devm_add_action_or_reset(dev, th1520_pd_unregister_adev,
adev);
}

Expand Down Expand Up @@ -235,6 +262,10 @@ static int th1520_pd_probe(struct platform_device *pdev)
if (ret)
goto err_clean_provider;

ret = th1520_pd_reboot_init(dev, aon_chan);
if (ret)
goto err_clean_provider;

return 0;

err_clean_provider:
Expand Down
7 changes: 7 additions & 0 deletions drivers/power/reset/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ config POWER_RESET_ST
help
Reset support for STMicroelectronics boards.

config POWER_RESET_TH1520_AON
tristate "T-Head TH1520 AON firmware poweroff and reset driver"
depends on TH1520_PM_DOMAINS
help
This driver supports power-off and reset operations for T-Head
TH1520 SoCs running the AON firmware.

config POWER_RESET_TORADEX_EC
tristate "Toradex Embedded Controller power-off and reset driver"
depends on ARCH_MXC || COMPILE_TEST
Expand Down
1 change: 1 addition & 0 deletions drivers/power/reset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o
obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o
obj-$(CONFIG_POWER_RESET_TH1520_AON) += th1520-aon-reboot.o
obj-$(CONFIG_POWER_RESET_TORADEX_EC) += tdx-ec-poweroff.o
obj-$(CONFIG_POWER_RESET_TPS65086) += tps65086-restart.o
obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o
Expand Down
98 changes: 98 additions & 0 deletions drivers/power/reset/th1520-aon-reboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: GPL-2.0
/*
* T-HEAD TH1520 AON Firmware Reboot Driver
*
* Copyright (c) 2025 Icenowy Zheng <uwu@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);

return NOTIFY_DONE;
}

static int th1520_aon_restart_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_RESTART;
msg.hdr.size = TH1520_AON_RPC_MSG_NUM;

th1520_aon_call_rpc(aon_chan, &msg);

return NOTIFY_DONE;
}

static int th1520_aon_reboot_probe(struct auxiliary_device *adev,
const struct auxiliary_device_id *id)
{
struct device *dev = &adev->dev;
int ret;

/* Expect struct th1520_aon_chan to be passed via platform_data */
ret = devm_register_sys_off_handler(dev, SYS_OFF_MODE_POWER_OFF,
TH1520_AON_REBOOT_PRIORITY,
th1520_aon_pwroff_handler,
adev->dev.platform_data);

if (ret) {
dev_err(dev, "Failed to register power off handler\n");
return ret;
}

ret = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART,
TH1520_AON_REBOOT_PRIORITY,
th1520_aon_restart_handler,
adev->dev.platform_data);

if (ret) {
dev_err(dev, "Failed to register restart handler\n");
return ret;
}

return 0;
}

static const struct auxiliary_device_id th1520_aon_reboot_id_table[] = {
{ .name = "th1520_pm_domains.reboot" },
{},
};
MODULE_DEVICE_TABLE(auxiliary, th1520_aon_reboot_id_table);

static struct auxiliary_driver th1520_aon_reboot_driver = {
.driver = {
.name = "th1520-aon-reboot",
},
.probe = th1520_aon_reboot_probe,
.id_table = th1520_aon_reboot_id_table,
};
module_auxiliary_driver(th1520_aon_reboot_driver);

MODULE_AUTHOR("Icenowy Zheng <uwu@icenowy.me>");
MODULE_DESCRIPTION("T-HEAD TH1520 AON-firmware-based reboot driver");
MODULE_LICENSE("GPL");
Loading