aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-samsung/pd.c
blob: 2d408897bf9077e26e01050ff8d13fb2349e9907 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* linux/arch/arm/plat-samsung/pd.c
 *
 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Samsung Power domain support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/pm_runtime.h>

#include <plat/pd.h>

static int samsung_pd_probe(struct platform_device *pdev)
{
	struct samsung_pd_info *pdata = pdev->dev.platform_data;
	struct device *dev = &pdev->dev;
	int ret = 0;

	if (!pdata) {
		dev_err(dev, "no device data specified\n");
		return -ENOENT;
	}

	pdata->id = pdev->id;
	if (pdata->init) {
		ret = pdata->init(dev);
		if (ret) {
			dev_err(dev, "init fails");
			return ret;
		}
	}

	pm_runtime_set_active(dev);
	pm_runtime_enable(dev);

	dev_info(dev, "power domain registered\n");
	return 0;
}

static int __devexit samsung_pd_remove(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;

	pm_runtime_disable(dev);
	return 0;
}

static int samsung_pd_suspend(struct device *dev)
{
	struct samsung_pd_info *pdata = dev->platform_data;
	int ret = 0;

	if (pdata->save)
		ret = pdata->save(dev);

	dev_dbg(dev, "suspended\n");

	return ret;
}

static int samsung_pd_resume(struct device *dev)
{
	struct samsung_pd_info *pdata = dev->platform_data;
	int ret = 0;

	if (pdata->restore)
		ret = pdata->restore(dev);

	dev_dbg(dev, "resumed\n");

	return ret;
}

static int samsung_pd_runtime_suspend(struct device *dev)
{
	struct samsung_pd_info *pdata = dev->platform_data;
	int ret = 0;

	if (pdata->disable)
		ret = pdata->disable(dev);

	dev_dbg(dev, "runtime suspended\n");
	return ret;
}

static int samsung_pd_runtime_resume(struct device *dev)
{
	struct samsung_pd_info *pdata = dev->platform_data;
	int ret = 0;

	if (pdata->enable)
		ret = pdata->enable(dev);

	dev_dbg(dev, "runtime resumed\n");
	return ret;
}

static const struct dev_pm_ops samsung_pd_pm_ops = {
	.suspend		= samsung_pd_suspend,
	.resume			= samsung_pd_resume,
	.runtime_suspend	= samsung_pd_runtime_suspend,
	.runtime_resume		= samsung_pd_runtime_resume,
};

static struct platform_driver samsung_pd_driver = {
	.driver		= {
		.name		= "samsung-pd",
		.owner		= THIS_MODULE,
		.pm		= &samsung_pd_pm_ops,
	},
	.probe		= samsung_pd_probe,
	.remove		= __devexit_p(samsung_pd_remove),
};

static int __init samsung_pd_init(void)
{
	int ret;

	ret = platform_driver_register(&samsung_pd_driver);
	if (ret)
		printk(KERN_ERR "%s: failed to add PD driver\n", __func__);

	return ret;
}
arch_initcall(samsung_pd_init);