1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * loongson-specific suspend support 4 * 5 * Copyright (C) 2009 Lemote Inc. 6 * Author: Wu Zhangjin <wuzhangjin@gmail.com> 7 */ 8 #include <linux/suspend.h> 9 #include <linux/pm.h> 10 11 #include <asm/mipsregs.h> 12 13 #include <loongson.h> 14 15 asmlinkage void loongson_lefi_sleep(unsigned long sleep_addr); 16 17 static int lefi_pm_enter(suspend_state_t state) 18 { 19 switch (state) { 20 case PM_SUSPEND_MEM: 21 pm_set_suspend_via_firmware(); 22 loongson_lefi_sleep(loongson_sysconf.suspend_addr); 23 pm_set_resume_via_firmware(); 24 return 0; 25 default: 26 return -EINVAL; 27 } 28 } 29 30 static int lefi_pm_valid_state(suspend_state_t state) 31 { 32 switch (state) { 33 case PM_SUSPEND_MEM: 34 return !!loongson_sysconf.suspend_addr; 35 default: 36 return 0; 37 } 38 } 39 40 static const struct platform_suspend_ops lefi_pm_ops = { 41 .valid = lefi_pm_valid_state, 42 .enter = lefi_pm_enter, 43 }; 44 45 static int __init loongson_pm_init(void) 46 { 47 if (loongson_sysconf.fw_interface == LOONGSON_LEFI) 48 suspend_set_ops(&lefi_pm_ops); 49 50 return 0; 51 } 52 arch_initcall(loongson_pm_init); 53