blob: a60715e11306b272bc0402a8f8351a2afec5fc48 [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>
Huacai Chen1a08f152014-03-21 18:44:02 +080019#include <boot_param.h>
Wu Zhangjin85749d22009-07-02 23:26:45 +080020
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080021static 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 Baechle70342282013-01-22 12:59:30 +010031 " .set noat \n"
32 " jr %[func] \n"
33 " .set at \n"
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080034 : /* No outputs */
35 : [func] "r" (func));
36#endif
37}
38
Wu Zhangjin85749d22009-07-02 23:26:45 +080039static void loongson_restart(char *command)
40{
Huacai Chen1a08f152014-03-21 18:44:02 +080041#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
Wu Zhangjin85749d22009-07-02 23:26:45 +080042 /* do preparation for reboot */
43 mach_prepare_reboot();
44
45 /* reboot via jumping to boot base address */
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080046 loongson_reboot();
Huacai Chen1a08f152014-03-21 18:44:02 +080047#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 Zhangjin85749d22009-07-02 23:26:45 +080056}
57
Wu Zhangjinfc48c412010-01-27 22:39:46 +080058static void loongson_poweroff(void)
Wu Zhangjin85749d22009-07-02 23:26:45 +080059{
Huacai Chen1a08f152014-03-21 18:44:02 +080060#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
Wu Zhangjin85749d22009-07-02 23:26:45 +080061 mach_prepare_shutdown();
Wu Zhangjin6f320962010-01-04 17:16:45 +080062 unreachable();
Huacai Chen1a08f152014-03-21 18:44:02 +080063#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 Zhangjin85749d22009-07-02 23:26:45 +080072}
73
Wu Zhangjinfc48c412010-01-27 22:39:46 +080074static 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 Zhangjin85749d22009-07-02 23:26:45 +080083static int __init mips_reboot_setup(void)
84{
85 _machine_restart = loongson_restart;
86 _machine_halt = loongson_halt;
Wu Zhangjinfc48c412010-01-27 22:39:46 +080087 pm_power_off = loongson_poweroff;
Wu Zhangjin85749d22009-07-02 23:26:45 +080088
89 return 0;
90}
91
92arch_initcall(mips_reboot_setup);