From a36a1c092a219d46b3c9f8f3028543f0f2a508d3 Mon Sep 17 00:00:00 2001 From: Ondrej Jirman Date: Mon, 9 Jul 2018 15:23:50 +0200 Subject: [PATCH] cmd: Add ariscrun command for starting CPUS CPUS is a power management co-processor on some Allwinner SoCs (H3, A83T). Signed-off-by: Ondrej Jirman --- cmd/Kconfig | 9 +++++++ cmd/Makefile | 1 + cmd/sunxi-arisc.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 cmd/sunxi-arisc.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 4e61565aab1..47f231f9c9e 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1691,6 +1691,15 @@ endmenu source "cmd/ti/Kconfig" +menu "sunxi specific command line interface" + +config CMD_SUNXI_ARISC + bool "command for starting ARISC code on sunxi platforms" + help + Support for starting OpenRISC coprocessor on sunxi platforms. + +endmenu + config CMD_BOOTSTAGE bool "Enable the 'bootstage' command" depends on BOOTSTAGE diff --git a/cmd/Makefile b/cmd/Makefile index ac843b4b16a..68de6a26bf8 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_PMIC) += pmic.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +obj-$(CONFIG_CMD_SUNXI_ARISC) += sunxi-arisc.o # Android Verified Boot 2.0 obj-$(CONFIG_CMD_AVB) += avb.o diff --git a/cmd/sunxi-arisc.c b/cmd/sunxi-arisc.c new file mode 100644 index 00000000000..92dd9c2f6b0 --- /dev/null +++ b/cmd/sunxi-arisc.c @@ -0,0 +1,69 @@ +/* + * Written by Ondrej Jirman , 2018 + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +#define R_CPUCFG_BASE 0x01f01c00 + +static void reset_cpus(int stop) +{ + uint32_t cpu_cfg; + + cpu_cfg = readl(R_CPUCFG_BASE); + cpu_cfg &= ~(1uL); + writel(cpu_cfg, R_CPUCFG_BASE); + + mdelay(1); + + if (!stop) { + cpu_cfg |= 1; + writel(cpu_cfg, R_CPUCFG_BASE); + } +} + +static int do_arisc_start(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + reset_cpus(0); + return 0; +} + +static int do_arisc_stop(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + reset_cpus(1); + return 0; +} + +static int do_arisc_takeover(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + reset_cpus(0); + + while (1) { + WATCHDOG_RESET(); + mdelay(10); + } + + return 0; +} + +U_BOOT_CMD( + arisc_start, 3, 1, do_arisc_start, + "reset arisc comprocessor and de-assert the reset line", + "" +); + +U_BOOT_CMD( + arisc_stop, 3, 1, do_arisc_stop, + "reset arisc comprocessor and keep it reset", + "" +); + +U_BOOT_CMD( + arisc_takeover, 3, 1, do_arisc_takeover, + "reset arisc comprocessor and de-assert the reset line, stop u-boot", + "" +);