aboutsummaryrefslogtreecommitdiffstats
path: root/s2ram-ppc.c
blob: c3040bd2220b953f9778e3c4c62d5be3db3cf312 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Suspend-to-RAM - PPC code
 *
 * Copyright 2006 Tim Dijkstra <newsuser@fa...>
 * Copyright 2006 Luca Tettamanti <kronos.it@gm...>
 * Distribute under GPLv2.
 */

#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <linux/pmu.h>

#include "s2ram.h"

void s2ram_add_flag(int opt, const char *arg)
{
	/* We don't take any options */
}

int s2ram_prepare(void)
{
	return 0;
}

void s2ram_resume(void)
{
 /* nop */
}

void identify_machine(void)
{
	printf("We don't have quirks and hence no whitelist on powerpc\n");
}

int machine_known(void)
{
	printf("We don't have quirks and hence no whitelist on powerpc\n");
	return 0;
}

int s2ram_hacks(void)
{
	return 0;
}

int s2ram_is_supported(void)
{
	int fd, ret = 0;
	unsigned long arg = 0;

	/* PMU_IOC_CAN_SLEEP is going away, so we only say unsupported
	* if PMU_IOC_CAN_SLEEP explicitly says we can't */
	fd = open("/dev/pmu", O_RDWR);
	if (fd < 0)
		return 0;

	ret = ioctl(fd, PMU_IOC_CAN_SLEEP, &arg);
	if (!ret && arg != 1)
		ret = ENOTSUP;

	close(fd);

	return 0;
}

static int s2ram_do_pmu (void)
{
	int fd;
	int ret = 0;
	unsigned long arg = 0;

	fd = open("/dev/pmu", O_RDWR);
	if (fd < 0)
		return errno;

	ret = ioctl(fd, PMU_IOC_CAN_SLEEP, &arg);
	if (!ret && arg != 1)
		ret = ENOTSUP;

	if (!ret)
		ret = ioctl(fd, PMU_IOC_SLEEP, 0);

	if (ret)
		ret = errno;

	close(fd);

	return ret;
}

int s2ram_do(void)
{
 int ret;

 /* If this works we're done. Else we just continue as if nothing
 * happened, future kernels will work with /s/p/s.
 */
 ret = s2ram_do_pmu();
 if (!ret)
	return ret;

 return s2ram_generic_do();
}