drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic()
[drm/drm-misc.git] / drivers / platform / mips / ls2k-reset.c
blob8f42d5d164802743d55830885c1aa5a5d887c1f2
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2021, Qing Zhang <zhangqing@loongson.cn>
4 * Loongson-2K1000 reset support
5 */
7 #include <linux/of_address.h>
8 #include <linux/pm.h>
9 #include <asm/reboot.h>
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 */
15 static void __iomem *base;
17 static void ls2k_restart(char *command)
19 writel(0x1, base + RST_CNT);
22 static void ls2k_poweroff(void)
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);
30 static int ls2k_reset_init(void)
32 struct device_node *np;
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;
40 base = of_iomap(np, 0);
41 of_node_put(np);
42 if (!base) {
43 pr_info("Failed to map PM register base address\n");
44 return -ENOMEM;
47 _machine_restart = ls2k_restart;
48 pm_power_off = ls2k_poweroff;
50 return 0;
53 arch_initcall(ls2k_reset_init);