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> |
Huacai Chen | 1a08f15 | 2014-03-21 18:44:02 +0800 | [diff] [blame] | 19 | #include <boot_param.h> |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 20 | |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 21 | static inline void loongson_reboot(void) |
| 22 | { |
| 23 | #ifndef CONFIG_CPU_JUMP_WORKAROUNDS |
| 24 | ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) (); |
| 25 | #else |
| 26 | void (*func)(void); |
| 27 | |
| 28 | func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4); |
| 29 | |
| 30 | __asm__ __volatile__( |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 31 | " .set noat \n" |
| 32 | " jr %[func] \n" |
| 33 | " .set at \n" |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 34 | : /* No outputs */ |
| 35 | : [func] "r" (func)); |
| 36 | #endif |
| 37 | } |
| 38 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 39 | static void loongson_restart(char *command) |
| 40 | { |
Huacai Chen | 1a08f15 | 2014-03-21 18:44:02 +0800 | [diff] [blame] | 41 | #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 42 | /* do preparation for reboot */ |
| 43 | mach_prepare_reboot(); |
| 44 | |
| 45 | /* reboot via jumping to boot base address */ |
Wu Zhangjin | 64fc74f | 2010-04-10 20:07:13 +0800 | [diff] [blame] | 46 | loongson_reboot(); |
Huacai Chen | 1a08f15 | 2014-03-21 18:44:02 +0800 | [diff] [blame] | 47 | #else |
| 48 | void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr; |
| 49 | |
| 50 | fw_restart(); |
| 51 | while (1) { |
| 52 | if (cpu_wait) |
| 53 | cpu_wait(); |
| 54 | } |
| 55 | #endif |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 58 | static void loongson_poweroff(void) |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 59 | { |
Huacai Chen | 1a08f15 | 2014-03-21 18:44:02 +0800 | [diff] [blame] | 60 | #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 61 | mach_prepare_shutdown(); |
Wu Zhangjin | 6f32096 | 2010-01-04 17:16:45 +0800 | [diff] [blame] | 62 | unreachable(); |
Huacai Chen | 1a08f15 | 2014-03-21 18:44:02 +0800 | [diff] [blame] | 63 | #else |
| 64 | void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr; |
| 65 | |
| 66 | fw_poweroff(); |
| 67 | while (1) { |
| 68 | if (cpu_wait) |
| 69 | cpu_wait(); |
| 70 | } |
| 71 | #endif |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 74 | static void loongson_halt(void) |
| 75 | { |
| 76 | pr_notice("\n\n** You can safely turn off the power now **\n\n"); |
| 77 | while (1) { |
| 78 | if (cpu_wait) |
| 79 | cpu_wait(); |
| 80 | } |
| 81 | } |
| 82 | |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 83 | static int __init mips_reboot_setup(void) |
| 84 | { |
| 85 | _machine_restart = loongson_restart; |
| 86 | _machine_halt = loongson_halt; |
Wu Zhangjin | fc48c41 | 2010-01-27 22:39:46 +0800 | [diff] [blame] | 87 | pm_power_off = loongson_poweroff; |
Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | arch_initcall(mips_reboot_setup); |