David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/io.h> |
| 7 | #include <linux/pm.h> |
| 8 | #include <linux/sizes.h> |
| 9 | #include <asm/idle.h> |
| 10 | #include <asm/reboot.h> |
| 11 | |
| 12 | #include <loongson1.h> |
| 13 | |
| 14 | static void __iomem *wdt_reg_base; |
| 15 | |
| 16 | static void ls1x_halt(void) |
| 17 | { |
| 18 | while (1) { |
| 19 | if (cpu_wait) |
| 20 | cpu_wait(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | static void ls1x_restart(char *command) |
| 25 | { |
| 26 | __raw_writel(0x1, wdt_reg_base + WDT_EN); |
| 27 | __raw_writel(0x1, wdt_reg_base + WDT_TIMER); |
| 28 | __raw_writel(0x1, wdt_reg_base + WDT_SET); |
| 29 | |
| 30 | ls1x_halt(); |
| 31 | } |
| 32 | |
| 33 | static void ls1x_power_off(void) |
| 34 | { |
| 35 | ls1x_halt(); |
| 36 | } |
| 37 | |
| 38 | static int __init ls1x_reboot_setup(void) |
| 39 | { |
| 40 | wdt_reg_base = ioremap_nocache(LS1X_WDT_BASE, (SZ_4 + SZ_8)); |
| 41 | if (!wdt_reg_base) |
| 42 | panic("Failed to remap watchdog registers"); |
| 43 | |
| 44 | _machine_restart = ls1x_restart; |
| 45 | _machine_halt = ls1x_halt; |
| 46 | pm_power_off = ls1x_power_off; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | arch_initcall(ls1x_reboot_setup); |