x86, efi: Set runtime_version to the EFI spec revision
[linux/fpc-iii.git] / arch / arm / mach-exynos / pm_domains.c
blob9f1351de52f7533a731f6d2d2d26bb644c639c09
1 /*
2 * Exynos Generic power domain support.
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
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.
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.
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>
22 #include <linux/of_platform.h>
23 #include <linux/sched.h>
25 #include <mach/regs-pmu.h>
26 #include <plat/devs.h>
29 * Exynos specific wrapper around the generic power domain
31 struct exynos_pm_domain {
32 void __iomem *base;
33 char const *name;
34 bool is_off;
35 struct generic_pm_domain pd;
38 static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
40 struct exynos_pm_domain *pd;
41 void __iomem *base;
42 u32 timeout, pwr;
43 char *op;
45 pd = container_of(domain, struct exynos_pm_domain, pd);
46 base = pd->base;
48 pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
49 __raw_writel(pwr, base);
51 /* Wait max 1ms */
52 timeout = 10;
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;
60 timeout--;
61 cpu_relax();
62 usleep_range(80, 100);
64 return 0;
67 static int exynos_pd_power_on(struct generic_pm_domain *domain)
69 return exynos_pd_power(domain, true);
72 static int exynos_pd_power_off(struct generic_pm_domain *domain)
74 return exynos_pd_power(domain, false);
77 #define EXYNOS_GPD(PD, BASE, NAME) \
78 static 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 }, \
87 #ifdef CONFIG_OF
88 static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
89 struct device *dev)
91 int ret;
93 dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
95 while (1) {
96 ret = pm_genpd_add_device(&pd->pd, dev);
97 if (ret != -EAGAIN)
98 break;
99 cond_resched();
102 pm_genpd_dev_need_restore(dev, true);
105 static void exynos_remove_device_from_domain(struct device *dev)
107 struct generic_pm_domain *genpd = dev_to_genpd(dev);
108 int ret;
110 dev_dbg(dev, "removing from power domain %s\n", genpd->name);
112 while (1) {
113 ret = pm_genpd_remove_device(genpd, dev);
114 if (ret != -EAGAIN)
115 break;
116 cond_resched();
120 static void exynos_read_domain_from_dt(struct device *dev)
122 struct platform_device *pd_pdev;
123 struct exynos_pm_domain *pd;
124 struct device_node *node;
126 node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
127 if (!node)
128 return;
129 pd_pdev = of_find_device_by_node(node);
130 if (!pd_pdev)
131 return;
132 pd = platform_get_drvdata(pd_pdev);
133 exynos_add_device_to_domain(pd, dev);
136 static int exynos_pm_notifier_call(struct notifier_block *nb,
137 unsigned long event, void *data)
139 struct device *dev = data;
141 switch (event) {
142 case BUS_NOTIFY_BIND_DRIVER:
143 if (dev->of_node)
144 exynos_read_domain_from_dt(dev);
146 break;
148 case BUS_NOTIFY_UNBOUND_DRIVER:
149 exynos_remove_device_from_domain(dev);
151 break;
153 return NOTIFY_DONE;
156 static struct notifier_block platform_nb = {
157 .notifier_call = exynos_pm_notifier_call,
160 static __init int exynos_pm_dt_parse_domains(void)
162 struct platform_device *pdev;
163 struct device_node *np;
165 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
166 struct exynos_pm_domain *pd;
167 int on;
169 pdev = of_find_device_by_node(np);
171 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
172 if (!pd) {
173 pr_err("%s: failed to allocate memory for domain\n",
174 __func__);
175 return -ENOMEM;
178 pd->pd.name = kstrdup(np->name, GFP_KERNEL);
179 pd->name = pd->pd.name;
180 pd->base = of_iomap(np, 0);
181 pd->pd.power_off = exynos_pd_power_off;
182 pd->pd.power_on = exynos_pd_power_on;
183 pd->pd.of_node = np;
185 platform_set_drvdata(pdev, pd);
187 on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
189 pm_genpd_init(&pd->pd, NULL, !on);
192 bus_register_notifier(&platform_bus_type, &platform_nb);
194 return 0;
196 #else
197 static __init int exynos_pm_dt_parse_domains(void)
199 return 0;
201 #endif /* CONFIG_OF */
203 static __init __maybe_unused void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
204 struct exynos_pm_domain *pd)
206 if (pdev->dev.bus) {
207 if (!pm_genpd_add_device(&pd->pd, &pdev->dev))
208 pm_genpd_dev_need_restore(&pdev->dev, true);
209 else
210 pr_info("%s: error in adding %s device to %s power"
211 "domain\n", __func__, dev_name(&pdev->dev),
212 pd->name);
216 EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc");
217 EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d");
218 EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0");
219 EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1");
220 EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv");
221 EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam");
222 EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps");
224 static struct exynos_pm_domain *exynos4_pm_domains[] = {
225 &exynos4_pd_mfc,
226 &exynos4_pd_g3d,
227 &exynos4_pd_lcd0,
228 &exynos4_pd_lcd1,
229 &exynos4_pd_tv,
230 &exynos4_pd_cam,
231 &exynos4_pd_gps,
234 static __init int exynos4_pm_init_power_domain(void)
236 int idx;
238 if (of_have_populated_dt())
239 return exynos_pm_dt_parse_domains();
241 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) {
242 struct exynos_pm_domain *pd = exynos4_pm_domains[idx];
243 int on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
245 pm_genpd_init(&pd->pd, NULL, !on);
248 #ifdef CONFIG_S5P_DEV_FIMD0
249 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
250 #endif
251 #ifdef CONFIG_S5P_DEV_TV
252 exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv);
253 exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv);
254 #endif
255 #ifdef CONFIG_S5P_DEV_MFC
256 exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc);
257 #endif
258 #ifdef CONFIG_S5P_DEV_FIMC0
259 exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam);
260 #endif
261 #ifdef CONFIG_S5P_DEV_FIMC1
262 exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam);
263 #endif
264 #ifdef CONFIG_S5P_DEV_FIMC2
265 exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam);
266 #endif
267 #ifdef CONFIG_S5P_DEV_FIMC3
268 exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam);
269 #endif
270 #ifdef CONFIG_S5P_DEV_CSIS0
271 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam);
272 #endif
273 #ifdef CONFIG_S5P_DEV_CSIS1
274 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam);
275 #endif
276 #ifdef CONFIG_S5P_DEV_G2D
277 exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0);
278 #endif
279 #ifdef CONFIG_S5P_DEV_JPEG
280 exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam);
281 #endif
282 return 0;
284 arch_initcall(exynos4_pm_init_power_domain);
286 int __init exynos_pm_late_initcall(void)
288 pm_genpd_poweroff_unused();
289 return 0;