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
9  * Copyright (C) 2009 Lemote, Inc.
10  * Author: Zhangjin Wu, wuzhangjin@gmail.com
11  */
12 #include <linux/init.h>
13 #include <linux/pm.h>
14 
15 #include <asm/reboot.h>
16 
17 #include <loongson.h>
18 
loongson_reboot(void)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 
loongson_restart(char * command)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 */
43 	loongson_reboot();
44 }
45 
loongson_poweroff(void)46 static void loongson_poweroff(void)
47 {
48 	mach_prepare_shutdown();
49 	unreachable();
50 }
51 
loongson_halt(void)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 
mips_reboot_setup(void)61 static int __init mips_reboot_setup(void)
62 {
63 	_machine_restart = loongson_restart;
64 	_machine_halt = loongson_halt;
65 	pm_power_off = loongson_poweroff;
66 
67 	return 0;
68 }
69 
70 arch_initcall(mips_reboot_setup);
71