blob: 9e10d6225d9bca134931d2da11d0ba63da784972 [file] [log] [blame]
Wu Zhangjin85749d22009-07-02 23:26:45 +08001/*
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 Zhangjin6f320962010-01-04 17:16:45 +08009 * Copyright (C) 2009 Lemote, Inc.
Wu Zhangjinf7a904d2010-01-04 17:16:51 +080010 * Author: Zhangjin Wu, wuzhangjin@gmail.com
Wu Zhangjin85749d22009-07-02 23:26:45 +080011 */
12#include <linux/init.h>
13#include <linux/pm.h>
14
15#include <asm/reboot.h>
16
17#include <loongson.h>
18
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080019static 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 Zhangjin85749d22009-07-02 23:26:45 +080037static 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 Zhangjin64fc74f2010-04-10 20:07:13 +080043 loongson_reboot();
Wu Zhangjin85749d22009-07-02 23:26:45 +080044}
45
Wu Zhangjinfc48c412010-01-27 22:39:46 +080046static void loongson_poweroff(void)
Wu Zhangjin85749d22009-07-02 23:26:45 +080047{
48 mach_prepare_shutdown();
Wu Zhangjin6f320962010-01-04 17:16:45 +080049 unreachable();
Wu Zhangjin85749d22009-07-02 23:26:45 +080050}
51
Wu Zhangjinfc48c412010-01-27 22:39:46 +080052static 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 Zhangjin85749d22009-07-02 23:26:45 +080061static int __init mips_reboot_setup(void)
62{
63 _machine_restart = loongson_restart;
64 _machine_halt = loongson_halt;
Wu Zhangjinfc48c412010-01-27 22:39:46 +080065 pm_power_off = loongson_poweroff;
Wu Zhangjin85749d22009-07-02 23:26:45 +080066
67 return 0;
68}
69
70arch_initcall(mips_reboot_setup);