Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 1 | /* |
| 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 |
| 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 | |
| 15 | #include <asm/reboot.h> |
| 16 | |
| 17 | #include <loongson.h> |
| 18 | |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame^] | 19 | static inline void loongson_reboot(void) |
| 20 | { |
| 21 | #ifndef CONFIG_CPU_JUMP_WORKAROUNDS |
| 22 | ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) (); |
| 23 | #else |
| 24 | void (*func)(void); |
| 25 | |
| 26 | func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4); |
| 27 | |
| 28 | __asm__ __volatile__( |
| 29 | " .set noat \n" |
| 30 | " jr %[func] \n" |
| 31 | " .set at \n" |
| 32 | : /* No outputs */ |
| 33 | : [func] "r" (func)); |
| 34 | #endif |
| 35 | } |
| 36 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 37 | static void loongson_restart(char *command) |
| 38 | { |
| 39 | /* do preparation for reboot */ |
| 40 | mach_prepare_reboot(); |
| 41 | |
| 42 | /* reboot via jumping to boot base address */ |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame^] | 43 | loongson_reboot(); |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 44 | } |
| 45 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 46 | static void loongson_poweroff(void) |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 47 | { |
| 48 | mach_prepare_shutdown(); |
Wu Zhangjin | 6f32096 | 2010-01-04 17:16:45 +0800 | [diff] [blame] | 49 | unreachable(); |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 50 | } |
| 51 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 52 | static void loongson_halt(void) |
| 53 | { |
| 54 | pr_notice("\n\n** You can safely turn off the power now **\n\n"); |
| 55 | while (1) { |
| 56 | if (cpu_wait) |
| 57 | cpu_wait(); |
| 58 | } |
| 59 | } |
| 60 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 61 | static int __init mips_reboot_setup(void) |
| 62 | { |
| 63 | _machine_restart = loongson_restart; |
| 64 | _machine_halt = loongson_halt; |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 65 | pm_power_off = loongson_poweroff; |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | arch_initcall(mips_reboot_setup); |