xref: /linux/arch/loongarch/power/platform.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1366bb35aSHuacai Chen // SPDX-License-Identifier: GPL-2.0
2366bb35aSHuacai Chen /*
3366bb35aSHuacai Chen  * Author: Huacai Chen <chenhuacai@loongson.cn>
4366bb35aSHuacai Chen  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5366bb35aSHuacai Chen  */
6366bb35aSHuacai Chen #include <linux/acpi.h>
7366bb35aSHuacai Chen #include <linux/platform_device.h>
8366bb35aSHuacai Chen 
9366bb35aSHuacai Chen #include <asm/bootinfo.h>
10366bb35aSHuacai Chen #include <asm/loongson.h>
11366bb35aSHuacai Chen 
enable_gpe_wakeup(void)12366bb35aSHuacai Chen void enable_gpe_wakeup(void)
13366bb35aSHuacai Chen {
14366bb35aSHuacai Chen 	if (acpi_disabled)
15366bb35aSHuacai Chen 	       return;
16366bb35aSHuacai Chen 
17366bb35aSHuacai Chen 	if (acpi_gbl_reduced_hardware)
18366bb35aSHuacai Chen 	       return;
19366bb35aSHuacai Chen 
20366bb35aSHuacai Chen 	acpi_enable_all_wakeup_gpes();
21366bb35aSHuacai Chen }
22366bb35aSHuacai Chen 
enable_pci_wakeup(void)23366bb35aSHuacai Chen void enable_pci_wakeup(void)
24366bb35aSHuacai Chen {
25366bb35aSHuacai Chen 	if (acpi_disabled)
26366bb35aSHuacai Chen 	       return;
27366bb35aSHuacai Chen 
28366bb35aSHuacai Chen 	if (acpi_gbl_reduced_hardware)
29366bb35aSHuacai Chen 	       return;
30366bb35aSHuacai Chen 
31366bb35aSHuacai Chen 	acpi_write_bit_register(ACPI_BITREG_PCIEXP_WAKE_STATUS, 1);
32366bb35aSHuacai Chen 
33366bb35aSHuacai Chen 	if (acpi_gbl_FADT.flags & ACPI_FADT_PCI_EXPRESS_WAKE)
34366bb35aSHuacai Chen 		acpi_write_bit_register(ACPI_BITREG_PCIEXP_WAKE_DISABLE, 0);
35366bb35aSHuacai Chen }
36366bb35aSHuacai Chen 
37f60d251bSHuacai Chen static struct platform_device loongson3_cpufreq_device = {
38f60d251bSHuacai Chen 	.name = "loongson3_cpufreq",
39f60d251bSHuacai Chen 	.id = -1,
40f60d251bSHuacai Chen };
41f60d251bSHuacai Chen 
loongson_cpufreq_init(void)42f60d251bSHuacai Chen static int __init loongson_cpufreq_init(void)
43f60d251bSHuacai Chen {
44f60d251bSHuacai Chen 	if (!cpu_has_scalefreq)
45f60d251bSHuacai Chen 		return -ENODEV;
46f60d251bSHuacai Chen 
47f60d251bSHuacai Chen 	return platform_device_register(&loongson3_cpufreq_device);
48f60d251bSHuacai Chen }
49f60d251bSHuacai Chen 
50f60d251bSHuacai Chen arch_initcall(loongson_cpufreq_init);
51f60d251bSHuacai Chen 
default_suspend_addr(void)52*e523a5a6SJiaxun Yang static void default_suspend_addr(void)
53*e523a5a6SJiaxun Yang {
54*e523a5a6SJiaxun Yang 	acpi_enter_sleep_state(ACPI_STATE_S3);
55*e523a5a6SJiaxun Yang }
56*e523a5a6SJiaxun Yang 
loongson3_acpi_suspend_init(void)57366bb35aSHuacai Chen static int __init loongson3_acpi_suspend_init(void)
58366bb35aSHuacai Chen {
59366bb35aSHuacai Chen #ifdef CONFIG_ACPI
60366bb35aSHuacai Chen 	acpi_status status;
61366bb35aSHuacai Chen 	uint64_t suspend_addr = 0;
62366bb35aSHuacai Chen 
63*e523a5a6SJiaxun Yang 	if (acpi_disabled)
64366bb35aSHuacai Chen 		return 0;
65366bb35aSHuacai Chen 
66*e523a5a6SJiaxun Yang 	if (!acpi_gbl_reduced_hardware)
67366bb35aSHuacai Chen 		acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
68*e523a5a6SJiaxun Yang 
69*e523a5a6SJiaxun Yang 	if (!acpi_sleep_state_supported(ACPI_STATE_S3))
70*e523a5a6SJiaxun Yang 		return 0;
71*e523a5a6SJiaxun Yang 
72366bb35aSHuacai Chen 	status = acpi_evaluate_integer(NULL, "\\SADR", NULL, &suspend_addr);
73366bb35aSHuacai Chen 	if (ACPI_FAILURE(status) || !suspend_addr) {
74*e523a5a6SJiaxun Yang 		pr_info("ACPI S3 supported with hardware register default\n");
75*e523a5a6SJiaxun Yang 		loongson_sysconf.suspend_addr = (u64)default_suspend_addr;
76*e523a5a6SJiaxun Yang 	} else {
77*e523a5a6SJiaxun Yang 		pr_info("ACPI S3 supported with Loongson ACPI SADR extension\n");
78366bb35aSHuacai Chen 		loongson_sysconf.suspend_addr = (u64)phys_to_virt(PHYSADDR(suspend_addr));
79*e523a5a6SJiaxun Yang 	}
80366bb35aSHuacai Chen #endif
81366bb35aSHuacai Chen 	return 0;
82366bb35aSHuacai Chen }
83366bb35aSHuacai Chen 
84366bb35aSHuacai Chen device_initcall(loongson3_acpi_suspend_init);
85