summaryrefslogtreecommitdiff
path: root/kernel/platform.c
blob: 66eb41af168dcfa924953fa06f5bd04a68b1d83e (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
/*
 * platform driver support 
 */

#include <linux/platform.h>
#include <linux/module.h>
#include <linux/errno.h>


void default_reboot(char * cmd)
{
	/* nothing */
}

void default_halt(void)
{
	/* nothing */
}

int default_suspend(int state, int flags)
{
	return -ENOSYS;
}

static struct platform_t default_platform = {
	.name		= "Default Platform",
	.suspend_states	= 0,
	.reboot		= default_reboot,
	.halt		= default_halt,
	.power_off	= default_halt,
	.suspend	= default_suspend,
	.idle		= default_idle,
};

struct platform_t * platform = &default_platform;
static spinlock_t platform_lock = SPIN_LOCK_UNLOCKED;

/**
 * set_platform_driver - set the platform driver.
 * @pf:	driver to set it to
 *
 * Return -EEXIST if someone else already owns it.
 */
int set_platform_driver(struct platform_t * pf)
{
	if (!pf)
		return -EINVAL;
	spin_lock(&platform_lock);
	if (platform != &default_platform) {
		spin_unlock(&platform_lock);
		return -EEXIST;
	}
	platform = pf;
	spin_unlock(&platform_lock);
	return 0;
}

void remove_platform_driver(struct platform_t * pf)
{
	spin_lock(&platform_lock);
	if (platform == pf)
		platform = &default_platform;
	spin_unlock(&platform_lock);
}

EXPORT_SYMBOL(default_reboot);
EXPORT_SYMBOL(default_halt);
EXPORT_SYMBOL(default_suspend);

EXPORT_SYMBOL(platform);
EXPORT_SYMBOL(set_platform_driver);
EXPORT_SYMBOL(remove_platform_driver);