Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com> |
| 3 | * |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/pm.h> |
Kelvin Cheung | 9ec88b6 | 2016-04-06 20:34:54 +0800 | [diff] [blame] | 12 | #include <linux/sizes.h> |
Ralf Baechle | bdc92d74 | 2013-05-21 16:59:19 +0200 | [diff] [blame] | 13 | #include <asm/idle.h> |
Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 14 | #include <asm/reboot.h> |
| 15 | |
| 16 | #include <loongson1.h> |
| 17 | |
Kelvin Cheung | 9ec88b6 | 2016-04-06 20:34:54 +0800 | [diff] [blame] | 18 | static void __iomem *wdt_reg_base; |
Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 19 | |
| 20 | static void ls1x_halt(void) |
| 21 | { |
| 22 | while (1) { |
| 23 | if (cpu_wait) |
| 24 | cpu_wait(); |
| 25 | } |
| 26 | } |
| 27 | |
Kelvin Cheung | a13f079 | 2014-10-10 11:39:59 +0800 | [diff] [blame] | 28 | static void ls1x_restart(char *command) |
| 29 | { |
Kelvin Cheung | 9ec88b6 | 2016-04-06 20:34:54 +0800 | [diff] [blame] | 30 | __raw_writel(0x1, wdt_reg_base + WDT_EN); |
| 31 | __raw_writel(0x1, wdt_reg_base + WDT_TIMER); |
| 32 | __raw_writel(0x1, wdt_reg_base + WDT_SET); |
Kelvin Cheung | a13f079 | 2014-10-10 11:39:59 +0800 | [diff] [blame] | 33 | |
| 34 | ls1x_halt(); |
| 35 | } |
| 36 | |
Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 37 | static void ls1x_power_off(void) |
| 38 | { |
| 39 | ls1x_halt(); |
| 40 | } |
| 41 | |
| 42 | static int __init ls1x_reboot_setup(void) |
| 43 | { |
Kelvin Cheung | 9ec88b6 | 2016-04-06 20:34:54 +0800 | [diff] [blame] | 44 | wdt_reg_base = ioremap_nocache(LS1X_WDT_BASE, (SZ_4 + SZ_8)); |
| 45 | if (!wdt_reg_base) |
Kelvin Cheung | a13f079 | 2014-10-10 11:39:59 +0800 | [diff] [blame] | 46 | panic("Failed to remap watchdog registers"); |
| 47 | |
Kelvin Cheung | ca585cf | 2012-07-25 16:17:24 +0200 | [diff] [blame] | 48 | _machine_restart = ls1x_restart; |
| 49 | _machine_halt = ls1x_halt; |
| 50 | pm_power_off = ls1x_power_off; |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | arch_initcall(ls1x_reboot_setup); |