Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *
0004  * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
0005  * Author: Fuxin Zhang, zhangfx@lemote.com
0006  * Copyright (C) 2009 Lemote, Inc.
0007  * Author: Zhangjin Wu, wuzhangjin@gmail.com
0008  */
0009 #include <linux/init.h>
0010 #include <linux/pm.h>
0011 
0012 #include <asm/idle.h>
0013 #include <asm/reboot.h>
0014 
0015 #include <loongson.h>
0016 
0017 static inline void loongson_reboot(void)
0018 {
0019 #ifndef CONFIG_CPU_JUMP_WORKAROUNDS
0020     ((void (*)(void))ioremap(LOONGSON_BOOT_BASE, 4)) ();
0021 #else
0022     void (*func)(void);
0023 
0024     func = (void *)ioremap(LOONGSON_BOOT_BASE, 4);
0025 
0026     __asm__ __volatile__(
0027     "   .set    noat                        \n"
0028     "   jr  %[func]                     \n"
0029     "   .set    at                      \n"
0030     : /* No outputs */
0031     : [func] "r" (func));
0032 #endif
0033 }
0034 
0035 static void loongson_restart(char *command)
0036 {
0037     /* do preparation for reboot */
0038     mach_prepare_reboot();
0039 
0040     /* reboot via jumping to boot base address */
0041     loongson_reboot();
0042 }
0043 
0044 static void loongson_poweroff(void)
0045 {
0046     mach_prepare_shutdown();
0047 
0048     /*
0049      * It needs a wait loop here, but mips/kernel/reset.c already calls
0050      * a generic delay loop, machine_hang(), so simply return.
0051      */
0052     return;
0053 }
0054 
0055 static void loongson_halt(void)
0056 {
0057     pr_notice("\n\n** You can safely turn off the power now **\n\n");
0058     while (1) {
0059         if (cpu_wait)
0060             cpu_wait();
0061     }
0062 }
0063 
0064 static int __init mips_reboot_setup(void)
0065 {
0066     _machine_restart = loongson_restart;
0067     _machine_halt = loongson_halt;
0068     pm_power_off = loongson_poweroff;
0069 
0070     return 0;
0071 }
0072 
0073 arch_initcall(mips_reboot_setup);