blob: 65bfbb5d06f442efbd6601600097f94124cc171c [file] [log] [blame]
Wu Zhangjin85749d22009-07-02 23:26:45 +08001/*
Ralf Baechle70342282013-01-22 12:59:30 +01002 * 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 Zhangjin85749d22009-07-02 23:26:45 +08004 * 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
Ralf Baechlebdc92d742013-05-21 16:59:19 +020015#include <asm/idle.h>
Wu Zhangjin85749d22009-07-02 23:26:45 +080016#include <asm/reboot.h>
17
18#include <loongson.h>
19
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080020static 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 Baechle70342282013-01-22 12:59:30 +010030 " .set noat \n"
31 " jr %[func] \n"
32 " .set at \n"
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080033 : /* No outputs */
34 : [func] "r" (func));
35#endif
36}
37
Wu Zhangjin85749d22009-07-02 23:26:45 +080038static 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 Zhangjin64fc74f2010-04-10 20:07:13 +080044 loongson_reboot();
Wu Zhangjin85749d22009-07-02 23:26:45 +080045}
46
Wu Zhangjinfc48c412010-01-27 22:39:46 +080047static void loongson_poweroff(void)
Wu Zhangjin85749d22009-07-02 23:26:45 +080048{
49 mach_prepare_shutdown();
Wu Zhangjin6f320962010-01-04 17:16:45 +080050 unreachable();
Wu Zhangjin85749d22009-07-02 23:26:45 +080051}
52
Wu Zhangjinfc48c412010-01-27 22:39:46 +080053static 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 Zhangjin85749d22009-07-02 23:26:45 +080062static int __init mips_reboot_setup(void)
63{
64 _machine_restart = loongson_restart;
65 _machine_halt = loongson_halt;
Wu Zhangjinfc48c412010-01-27 22:39:46 +080066 pm_power_off = loongson_poweroff;
Wu Zhangjin85749d22009-07-02 23:26:45 +080067
68 return 0;
69}
70
71arch_initcall(mips_reboot_setup);