Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Loongson64: Add Loongson-2K1000 reset platform driver

Add power management register operations to support reboot and poweroff.

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Qing Zhang and committed by
Thomas Bogendoerfer
7eb7819a fc5bb239

+60
+6
drivers/platform/mips/Kconfig
··· 30 30 help 31 31 Loongson RS780E PCH ACPI Controller driver. 32 32 33 + config LS2K_RESET 34 + bool "Loongson-2K1000 Reset Controller" 35 + depends on MACH_LOONGSON64 || COMPILE_TEST 36 + help 37 + Loongson-2K1000 Reset Controller driver. 38 + 33 39 endif # MIPS_PLATFORM_DEVICES
+1
drivers/platform/mips/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o 3 3 obj-$(CONFIG_RS780E_ACPI) += rs780e-acpi.o 4 + obj-$(CONFIG_LS2K_RESET) += ls2k-reset.o
+53
drivers/platform/mips/ls2k-reset.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2021, Qing Zhang <zhangqing@loongson.cn> 4 + * Loongson-2K1000 reset support 5 + */ 6 + 7 + #include <linux/of_address.h> 8 + #include <linux/pm.h> 9 + #include <asm/reboot.h> 10 + 11 + #define PM1_STS 0x0c /* Power Management 1 Status Register */ 12 + #define PM1_CNT 0x14 /* Power Management 1 Control Register */ 13 + #define RST_CNT 0x30 /* Reset Control Register */ 14 + 15 + static void __iomem *base; 16 + 17 + static void ls2k_restart(char *command) 18 + { 19 + writel(0x1, base + RST_CNT); 20 + } 21 + 22 + static void ls2k_poweroff(void) 23 + { 24 + /* Clear */ 25 + writel((readl(base + PM1_STS) & 0xffffffff), base + PM1_STS); 26 + /* Sleep Enable | Soft Off*/ 27 + writel(GENMASK(12, 10) | BIT(13), base + PM1_CNT); 28 + } 29 + 30 + static int ls2k_reset_init(void) 31 + { 32 + struct device_node *np; 33 + 34 + np = of_find_compatible_node(NULL, NULL, "loongson,ls2k-pm"); 35 + if (!np) { 36 + pr_info("Failed to get PM node\n"); 37 + return -ENODEV; 38 + } 39 + 40 + base = of_iomap(np, 0); 41 + if (!base) { 42 + pr_info("Failed to map PM register base address\n"); 43 + return -ENOMEM; 44 + } 45 + 46 + _machine_restart = ls2k_restart; 47 + pm_power_off = ls2k_poweroff; 48 + 49 + of_node_put(np); 50 + return 0; 51 + } 52 + 53 + arch_initcall(ls2k_reset_init);