ARM: EXYNOS: Remove check for device tree presence
[deliverable/linux.git] / arch / arm / mach-exynos / pm_domains.c
CommitLineData
91cfbd4e
TA
1/*
2 * Exynos Generic power domain support.
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * Implementation of Exynos specific power domain control which is used in
8 * conjunction with runtime-pm. Support for both device-tree and non-device-tree
9 * based power domain support is included.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14*/
15
16#include <linux/io.h>
17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/pm_domain.h>
20#include <linux/delay.h>
21#include <linux/of_address.h>
8a65d236
TF
22#include <linux/of_platform.h>
23#include <linux/sched.h>
91cfbd4e
TA
24
25#include <mach/regs-pmu.h>
26#include <plat/devs.h>
27
28/*
29 * Exynos specific wrapper around the generic power domain
30 */
31struct exynos_pm_domain {
32 void __iomem *base;
33 char const *name;
34 bool is_off;
35 struct generic_pm_domain pd;
36};
37
38static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
39{
40 struct exynos_pm_domain *pd;
41 void __iomem *base;
42 u32 timeout, pwr;
43 char *op;
44
45 pd = container_of(domain, struct exynos_pm_domain, pd);
46 base = pd->base;
47
48 pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
49 __raw_writel(pwr, base);
50
51 /* Wait max 1ms */
52 timeout = 10;
53
54 while ((__raw_readl(base + 0x4) & S5P_INT_LOCAL_PWR_EN) != pwr) {
55 if (!timeout) {
56 op = (power_on) ? "enable" : "disable";
57 pr_err("Power domain %s %s failed\n", domain->name, op);
58 return -ETIMEDOUT;
59 }
60 timeout--;
61 cpu_relax();
62 usleep_range(80, 100);
63 }
64 return 0;
65}
66
67static int exynos_pd_power_on(struct generic_pm_domain *domain)
68{
69 return exynos_pd_power(domain, true);
70}
71
72static int exynos_pd_power_off(struct generic_pm_domain *domain)
73{
74 return exynos_pd_power(domain, false);
75}
76
77#define EXYNOS_GPD(PD, BASE, NAME) \
78static struct exynos_pm_domain PD = { \
79 .base = (void __iomem *)BASE, \
80 .name = NAME, \
81 .pd = { \
82 .power_off = exynos_pd_power_off, \
83 .power_on = exynos_pd_power_on, \
84 }, \
85}
86
8a65d236
TF
87static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
88 struct device *dev)
89{
90 int ret;
91
92 dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
93
94 while (1) {
95 ret = pm_genpd_add_device(&pd->pd, dev);
96 if (ret != -EAGAIN)
97 break;
98 cond_resched();
99 }
100
101 pm_genpd_dev_need_restore(dev, true);
102}
103
104static void exynos_remove_device_from_domain(struct device *dev)
105{
106 struct generic_pm_domain *genpd = dev_to_genpd(dev);
107 int ret;
108
109 dev_dbg(dev, "removing from power domain %s\n", genpd->name);
110
111 while (1) {
112 ret = pm_genpd_remove_device(genpd, dev);
113 if (ret != -EAGAIN)
114 break;
115 cond_resched();
116 }
117}
118
119static void exynos_read_domain_from_dt(struct device *dev)
120{
121 struct platform_device *pd_pdev;
122 struct exynos_pm_domain *pd;
123 struct device_node *node;
124
125 node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
126 if (!node)
127 return;
128 pd_pdev = of_find_device_by_node(node);
129 if (!pd_pdev)
130 return;
131 pd = platform_get_drvdata(pd_pdev);
132 exynos_add_device_to_domain(pd, dev);
133}
134
135static int exynos_pm_notifier_call(struct notifier_block *nb,
136 unsigned long event, void *data)
137{
138 struct device *dev = data;
139
140 switch (event) {
141 case BUS_NOTIFY_BIND_DRIVER:
142 if (dev->of_node)
143 exynos_read_domain_from_dt(dev);
144
145 break;
146
147 case BUS_NOTIFY_UNBOUND_DRIVER:
148 exynos_remove_device_from_domain(dev);
149
150 break;
151 }
152 return NOTIFY_DONE;
153}
154
155static struct notifier_block platform_nb = {
156 .notifier_call = exynos_pm_notifier_call,
157};
158
91cfbd4e
TA
159static __init int exynos_pm_dt_parse_domains(void)
160{
8a65d236 161 struct platform_device *pdev;
91cfbd4e
TA
162 struct device_node *np;
163
164 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
165 struct exynos_pm_domain *pd;
2ed5f236 166 int on;
91cfbd4e 167
8a65d236
TF
168 pdev = of_find_device_by_node(np);
169
91cfbd4e
TA
170 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
171 if (!pd) {
172 pr_err("%s: failed to allocate memory for domain\n",
173 __func__);
174 return -ENOMEM;
175 }
176
7add0ec0
TF
177 pd->pd.name = kstrdup(np->name, GFP_KERNEL);
178 pd->name = pd->pd.name;
91cfbd4e
TA
179 pd->base = of_iomap(np, 0);
180 pd->pd.power_off = exynos_pd_power_off;
181 pd->pd.power_on = exynos_pd_power_on;
182 pd->pd.of_node = np;
2ed5f236 183
8a65d236
TF
184 platform_set_drvdata(pdev, pd);
185
2ed5f236
TF
186 on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
187
188 pm_genpd_init(&pd->pd, NULL, !on);
91cfbd4e 189 }
8a65d236
TF
190
191 bus_register_notifier(&platform_bus_type, &platform_nb);
192
91cfbd4e
TA
193 return 0;
194}
91cfbd4e 195
8ab08c0c 196static __init __maybe_unused void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
91cfbd4e
TA
197 struct exynos_pm_domain *pd)
198{
199 if (pdev->dev.bus) {
ebc35c72
MS
200 if (!pm_genpd_add_device(&pd->pd, &pdev->dev))
201 pm_genpd_dev_need_restore(&pdev->dev, true);
202 else
91cfbd4e
TA
203 pr_info("%s: error in adding %s device to %s power"
204 "domain\n", __func__, dev_name(&pdev->dev),
205 pd->name);
206 }
207}
208
209EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc");
210EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d");
211EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0");
212EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1");
213EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv");
214EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam");
215EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps");
216
217static struct exynos_pm_domain *exynos4_pm_domains[] = {
218 &exynos4_pd_mfc,
219 &exynos4_pd_g3d,
220 &exynos4_pd_lcd0,
221 &exynos4_pd_lcd1,
222 &exynos4_pd_tv,
223 &exynos4_pd_cam,
224 &exynos4_pd_gps,
225};
226
227static __init int exynos4_pm_init_power_domain(void)
228{
229 int idx;
230
231 if (of_have_populated_dt())
232 return exynos_pm_dt_parse_domains();
233
76eb5567
MS
234 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) {
235 struct exynos_pm_domain *pd = exynos4_pm_domains[idx];
236 int on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
237
238 pm_genpd_init(&pd->pd, NULL, !on);
239 }
91cfbd4e
TA
240
241#ifdef CONFIG_S5P_DEV_FIMD0
242 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
243#endif
244#ifdef CONFIG_S5P_DEV_TV
245 exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv);
246 exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv);
247#endif
248#ifdef CONFIG_S5P_DEV_MFC
249 exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc);
250#endif
251#ifdef CONFIG_S5P_DEV_FIMC0
252 exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam);
253#endif
254#ifdef CONFIG_S5P_DEV_FIMC1
255 exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam);
256#endif
257#ifdef CONFIG_S5P_DEV_FIMC2
258 exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam);
259#endif
260#ifdef CONFIG_S5P_DEV_FIMC3
261 exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam);
262#endif
263#ifdef CONFIG_S5P_DEV_CSIS0
264 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam);
265#endif
266#ifdef CONFIG_S5P_DEV_CSIS1
267 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam);
a9e87bd9
SK
268#endif
269#ifdef CONFIG_S5P_DEV_G2D
270 exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0);
75371477
SK
271#endif
272#ifdef CONFIG_S5P_DEV_JPEG
273 exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam);
91cfbd4e
TA
274#endif
275 return 0;
276}
277arch_initcall(exynos4_pm_init_power_domain);
278
bb13fabc 279int __init exynos_pm_late_initcall(void)
91cfbd4e
TA
280{
281 pm_genpd_poweroff_unused();
282 return 0;
283}
This page took 0.098661 seconds and 5 git commands to generate.