1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author: Huacai Chen <chenhuacai@loongson.cn>
4  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5  */
6 #include <linux/acpi.h>
7 #include <linux/platform_device.h>
8 
9 #include <asm/bootinfo.h>
10 #include <asm/loongson.h>
11 
enable_gpe_wakeup(void)12 void enable_gpe_wakeup(void)
13 {
14 	if (acpi_disabled)
15 	       return;
16 
17 	if (acpi_gbl_reduced_hardware)
18 	       return;
19 
20 	acpi_enable_all_wakeup_gpes();
21 }
22 
enable_pci_wakeup(void)23 void enable_pci_wakeup(void)
24 {
25 	if (acpi_disabled)
26 	       return;
27 
28 	if (acpi_gbl_reduced_hardware)
29 	       return;
30 
31 	acpi_write_bit_register(ACPI_BITREG_PCIEXP_WAKE_STATUS, 1);
32 
33 	if (acpi_gbl_FADT.flags & ACPI_FADT_PCI_EXPRESS_WAKE)
34 		acpi_write_bit_register(ACPI_BITREG_PCIEXP_WAKE_DISABLE, 0);
35 }
36 
loongson3_acpi_suspend_init(void)37 static int __init loongson3_acpi_suspend_init(void)
38 {
39 #ifdef CONFIG_ACPI
40 	acpi_status status;
41 	uint64_t suspend_addr = 0;
42 
43 	if (acpi_disabled || acpi_gbl_reduced_hardware)
44 		return 0;
45 
46 	acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
47 	status = acpi_evaluate_integer(NULL, "\\SADR", NULL, &suspend_addr);
48 	if (ACPI_FAILURE(status) || !suspend_addr) {
49 		pr_err("ACPI S3 is not support!\n");
50 		return -1;
51 	}
52 	loongson_sysconf.suspend_addr = (u64)phys_to_virt(PHYSADDR(suspend_addr));
53 #endif
54 	return 0;
55 }
56 
57 device_initcall(loongson3_acpi_suspend_init);
58