Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 1 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 2 | * This program is free software; you can redistribute it and/or modify it |
| 3 | * under the terms of the GNU General Public License as published by the |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 4 | * Free Software Foundation; either version 2 of the License, or (at your |
| 5 | * option) any later version. |
| 6 | * |
| 7 | * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology |
| 8 | * Author: Fuxin Zhang, zhangfx@lemote.com |
Wu Zhangjin | 6f32096 | 2010-01-04 17:16:45 +0800 | [diff] [blame] | 9 | * Copyright (C) 2009 Lemote, Inc. |
Wu Zhangjin | f7a904d | 2010-01-04 17:16:51 +0800 | [diff] [blame] | 10 | * Author: Zhangjin Wu, wuzhangjin@gmail.com |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 11 | */ |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/pm.h> |
| 14 | |
Ralf Baechle | bdc92d74 | 2013-05-21 16:59:19 +0200 | [diff] [blame^] | 15 | #include <asm/idle.h> |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 16 | #include <asm/reboot.h> |
| 17 | |
| 18 | #include <loongson.h> |
| 19 | |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 20 | static inline void loongson_reboot(void) |
| 21 | { |
| 22 | #ifndef CONFIG_CPU_JUMP_WORKAROUNDS |
| 23 | ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) (); |
| 24 | #else |
| 25 | void (*func)(void); |
| 26 | |
| 27 | func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4); |
| 28 | |
| 29 | __asm__ __volatile__( |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 30 | " .set noat \n" |
| 31 | " jr %[func] \n" |
| 32 | " .set at \n" |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 33 | : /* No outputs */ |
| 34 | : [func] "r" (func)); |
| 35 | #endif |
| 36 | } |
| 37 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 38 | static void loongson_restart(char *command) |
| 39 | { |
| 40 | /* do preparation for reboot */ |
| 41 | mach_prepare_reboot(); |
| 42 | |
| 43 | /* reboot via jumping to boot base address */ |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 44 | loongson_reboot(); |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 45 | } |
| 46 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 47 | static void loongson_poweroff(void) |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 48 | { |
| 49 | mach_prepare_shutdown(); |
Wu Zhangjin | 6f32096 | 2010-01-04 17:16:45 +0800 | [diff] [blame] | 50 | unreachable(); |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 53 | static void loongson_halt(void) |
| 54 | { |
| 55 | pr_notice("\n\n** You can safely turn off the power now **\n\n"); |
| 56 | while (1) { |
| 57 | if (cpu_wait) |
| 58 | cpu_wait(); |
| 59 | } |
| 60 | } |
| 61 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 62 | static int __init mips_reboot_setup(void) |
| 63 | { |
| 64 | _machine_restart = loongson_restart; |
| 65 | _machine_halt = loongson_halt; |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 66 | pm_power_off = loongson_poweroff; |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | arch_initcall(mips_reboot_setup); |