• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020 Loongson Technology Co., Ltd.
4  */
5 #include <linux/kernel.h>
6 #include <linux/export.h>
7 #include <linux/pm.h>
8 #include <linux/types.h>
9 #include <linux/reboot.h>
10 #include <linux/delay.h>
11 #include <linux/console.h>
12 
13 #include <asm/idle.h>
14 #include <asm/loongarchregs.h>
15 #include <asm/reboot.h>
16 #include <loongson.h>
17 
machine_hang(void)18 static void machine_hang(void)
19 {
20 	local_irq_disable();
21 	clear_csr_ecfg(ECFG0_IM);
22 
23 	pr_notice("\n\n** You can safely turn off the power now **\n\n");
24 	console_flush_on_panic(CONSOLE_FLUSH_PENDING);
25 
26 	while (true) {
27 		__arch_cpu_idle();
28 		local_irq_disable();
29 	}
30 }
31 
32 void (*pm_restart)(void) = machine_hang;
33 void (*pm_power_off)(void) = machine_hang;
34 
35 EXPORT_SYMBOL(pm_power_off);
36 
machine_halt(void)37 void machine_halt(void)
38 {
39 #ifdef CONFIG_SMP
40 	preempt_disable();
41 	smp_send_stop();
42 #endif
43 	machine_hang();
44 }
45 
machine_power_off(void)46 void machine_power_off(void)
47 {
48 #ifdef CONFIG_SMP
49 	preempt_disable();
50 	smp_send_stop();
51 #endif
52 #ifdef CONFIG_PM
53 	enable_pci_wakeup();
54 #endif
55 	pm_power_off();
56 }
57 
machine_restart(char * command)58 void machine_restart(char *command)
59 {
60 #ifdef CONFIG_SMP
61 	preempt_disable();
62 	smp_send_stop();
63 #endif
64 	do_kernel_restart(command);
65 	pm_restart();
66 }
67