blob: ce39e918e4d5f775556cb5fe299a07665a971aa5 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Wu Zhangjin85749d22009-07-02 23:26:45 +08002/*
Wu Zhangjin85749d22009-07-02 23:26:45 +08003 *
4 * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
5 * Author: Fuxin Zhang, zhangfx@lemote.com
Wu Zhangjin6f320962010-01-04 17:16:45 +08006 * Copyright (C) 2009 Lemote, Inc.
Wu Zhangjinf7a904d2010-01-04 17:16:51 +08007 * Author: Zhangjin Wu, wuzhangjin@gmail.com
Wu Zhangjin85749d22009-07-02 23:26:45 +08008 */
9#include <linux/init.h>
10#include <linux/pm.h>
11
Ralf Baechlebdc92d742013-05-21 16:59:19 +020012#include <asm/idle.h>
Wu Zhangjin85749d22009-07-02 23:26:45 +080013#include <asm/reboot.h>
14
15#include <loongson.h>
Huacai Chen1a08f152014-03-21 18:44:02 +080016#include <boot_param.h>
Wu Zhangjin85749d22009-07-02 23:26:45 +080017
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080018static inline void loongson_reboot(void)
19{
20#ifndef CONFIG_CPU_JUMP_WORKAROUNDS
21 ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
22#else
23 void (*func)(void);
24
25 func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4);
26
27 __asm__ __volatile__(
Ralf Baechle70342282013-01-22 12:59:30 +010028 " .set noat \n"
29 " jr %[func] \n"
30 " .set at \n"
Wu Zhangjin64fc74f2010-04-10 20:07:13 +080031 : /* No outputs */
32 : [func] "r" (func));
33#endif
34}
35
Wu Zhangjin85749d22009-07-02 23:26:45 +080036static void loongson_restart(char *command)
37{
Huacai Chen1a08f152014-03-21 18:44:02 +080038#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
Wu Zhangjin85749d22009-07-02 23:26:45 +080039 /* 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();
Huacai Chen1a08f152014-03-21 18:44:02 +080044#else
45 void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
46
47 fw_restart();
48 while (1) {
49 if (cpu_wait)
50 cpu_wait();
51 }
52#endif
Wu Zhangjin85749d22009-07-02 23:26:45 +080053}
54
Wu Zhangjinfc48c412010-01-27 22:39:46 +080055static void loongson_poweroff(void)
Wu Zhangjin85749d22009-07-02 23:26:45 +080056{
Huacai Chen1a08f152014-03-21 18:44:02 +080057#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
Wu Zhangjin85749d22009-07-02 23:26:45 +080058 mach_prepare_shutdown();
Yifeng Li8a966692019-02-06 15:07:21 +080059
60 /*
61 * It needs a wait loop here, but mips/kernel/reset.c already calls
62 * a generic delay loop, machine_hang(), so simply return.
63 */
64 return;
Huacai Chen1a08f152014-03-21 18:44:02 +080065#else
66 void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
67
68 fw_poweroff();
69 while (1) {
70 if (cpu_wait)
71 cpu_wait();
72 }
73#endif
Wu Zhangjin85749d22009-07-02 23:26:45 +080074}
75
Wu Zhangjinfc48c412010-01-27 22:39:46 +080076static void loongson_halt(void)
77{
78 pr_notice("\n\n** You can safely turn off the power now **\n\n");
79 while (1) {
80 if (cpu_wait)
81 cpu_wait();
82 }
83}
84
Wu Zhangjin85749d22009-07-02 23:26:45 +080085static int __init mips_reboot_setup(void)
86{
87 _machine_restart = loongson_restart;
88 _machine_halt = loongson_halt;
Wu Zhangjinfc48c412010-01-27 22:39:46 +080089 pm_power_off = loongson_poweroff;
Wu Zhangjin85749d22009-07-02 23:26:45 +080090
91 return 0;
92}
93
94arch_initcall(mips_reboot_setup);