summaryrefslogtreecommitdiff
path: root/arch/mips/loongson64/pm.c
blob: 5f0604af8f13647b25d871eefaff64440f49f6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * loongson-specific suspend support
 *
 *  Copyright (C) 2009 Lemote Inc.
 *  Author: Wu Zhangjin <wuzhangjin@gmail.com>
 */
#include <linux/suspend.h>
#include <linux/pm.h>

#include <asm/mipsregs.h>

#include <loongson.h>

asmlinkage void loongson_lefi_sleep(unsigned long sleep_addr);

static int lefi_pm_enter(suspend_state_t state)
{
	switch (state) {
	case PM_SUSPEND_MEM:
		pm_set_suspend_via_firmware();
		loongson_lefi_sleep(loongson_sysconf.suspend_addr);
		pm_set_resume_via_firmware();
		return 0;
	default:
		return -EINVAL;
	}
}

static int lefi_pm_valid_state(suspend_state_t state)
{
	switch (state) {
	case PM_SUSPEND_MEM:
		return !!loongson_sysconf.suspend_addr;
	default:
		return 0;
	}
}

static const struct platform_suspend_ops lefi_pm_ops = {
	.valid	= lefi_pm_valid_state,
	.enter	= lefi_pm_enter,
};

static int __init loongson_pm_init(void)
{
	if (loongson_sysconf.fw_interface == LOONGSON_LEFI)
		suspend_set_ops(&lefi_pm_ops);

	return 0;
}
arch_initcall(loongson_pm_init);