blob: d1abc1a94ecd519f5cb4253c4741a09fc68c2f5d [file] [log] [blame]
Thomas Abraham91cfbd42012-01-27 15:25:00 +09001/*
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>
22
23#include <mach/regs-pmu.h>
24#include <plat/devs.h>
25
26/*
27 * Exynos specific wrapper around the generic power domain
28 */
29struct exynos_pm_domain {
30 void __iomem *base;
31 char const *name;
32 bool is_off;
33 struct generic_pm_domain pd;
34};
35
36static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
37{
38 struct exynos_pm_domain *pd;
39 void __iomem *base;
40 u32 timeout, pwr;
41 char *op;
42
43 pd = container_of(domain, struct exynos_pm_domain, pd);
44 base = pd->base;
45
46 pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
47 __raw_writel(pwr, base);
48
49 /* Wait max 1ms */
50 timeout = 10;
51
52 while ((__raw_readl(base + 0x4) & S5P_INT_LOCAL_PWR_EN) != pwr) {
53 if (!timeout) {
54 op = (power_on) ? "enable" : "disable";
55 pr_err("Power domain %s %s failed\n", domain->name, op);
56 return -ETIMEDOUT;
57 }
58 timeout--;
59 cpu_relax();
60 usleep_range(80, 100);
61 }
62 return 0;
63}
64
65static int exynos_pd_power_on(struct generic_pm_domain *domain)
66{
67 return exynos_pd_power(domain, true);
68}
69
70static int exynos_pd_power_off(struct generic_pm_domain *domain)
71{
72 return exynos_pd_power(domain, false);
73}
74
75#define EXYNOS_GPD(PD, BASE, NAME) \
76static struct exynos_pm_domain PD = { \
77 .base = (void __iomem *)BASE, \
78 .name = NAME, \
79 .pd = { \
80 .power_off = exynos_pd_power_off, \
81 .power_on = exynos_pd_power_on, \
82 }, \
83}
84
85#ifdef CONFIG_OF
86static __init int exynos_pm_dt_parse_domains(void)
87{
88 struct device_node *np;
89
90 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
91 struct exynos_pm_domain *pd;
Tomasz Figa2ed5f232012-11-22 00:21:08 +090092 int on;
Thomas Abraham91cfbd42012-01-27 15:25:00 +090093
94 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
95 if (!pd) {
96 pr_err("%s: failed to allocate memory for domain\n",
97 __func__);
98 return -ENOMEM;
99 }
100
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900101 pd->name = np->name;
102 pd->base = of_iomap(np, 0);
103 pd->pd.power_off = exynos_pd_power_off;
104 pd->pd.power_on = exynos_pd_power_on;
105 pd->pd.of_node = np;
Tomasz Figa2ed5f232012-11-22 00:21:08 +0900106
107 on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
108
109 pm_genpd_init(&pd->pd, NULL, !on);
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900110 }
111 return 0;
112}
113#else
114static __init int exynos_pm_dt_parse_domains(void)
115{
116 return 0;
117}
118#endif /* CONFIG_OF */
119
Arnd Bergmann8ab08c02012-08-04 10:28:33 +0000120static __init __maybe_unused void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900121 struct exynos_pm_domain *pd)
122{
123 if (pdev->dev.bus) {
Marek Szyprowskiebc35c72012-07-12 17:29:55 +0900124 if (!pm_genpd_add_device(&pd->pd, &pdev->dev))
125 pm_genpd_dev_need_restore(&pdev->dev, true);
126 else
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900127 pr_info("%s: error in adding %s device to %s power"
128 "domain\n", __func__, dev_name(&pdev->dev),
129 pd->name);
130 }
131}
132
133EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc");
134EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d");
135EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0");
136EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1");
137EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv");
138EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam");
139EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps");
140
141static struct exynos_pm_domain *exynos4_pm_domains[] = {
142 &exynos4_pd_mfc,
143 &exynos4_pd_g3d,
144 &exynos4_pd_lcd0,
145 &exynos4_pd_lcd1,
146 &exynos4_pd_tv,
147 &exynos4_pd_cam,
148 &exynos4_pd_gps,
149};
150
151static __init int exynos4_pm_init_power_domain(void)
152{
153 int idx;
154
155 if (of_have_populated_dt())
156 return exynos_pm_dt_parse_domains();
157
Marek Szyprowski76eb5562012-07-12 17:29:54 +0900158 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) {
159 struct exynos_pm_domain *pd = exynos4_pm_domains[idx];
160 int on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
161
162 pm_genpd_init(&pd->pd, NULL, !on);
163 }
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900164
165#ifdef CONFIG_S5P_DEV_FIMD0
166 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
167#endif
168#ifdef CONFIG_S5P_DEV_TV
169 exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv);
170 exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv);
171#endif
172#ifdef CONFIG_S5P_DEV_MFC
173 exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc);
174#endif
175#ifdef CONFIG_S5P_DEV_FIMC0
176 exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam);
177#endif
178#ifdef CONFIG_S5P_DEV_FIMC1
179 exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam);
180#endif
181#ifdef CONFIG_S5P_DEV_FIMC2
182 exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam);
183#endif
184#ifdef CONFIG_S5P_DEV_FIMC3
185 exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam);
186#endif
187#ifdef CONFIG_S5P_DEV_CSIS0
188 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam);
189#endif
190#ifdef CONFIG_S5P_DEV_CSIS1
191 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam);
192#endif
Sachin Kamata9e87bd2012-03-09 06:54:34 -0800193#ifdef CONFIG_S5P_DEV_G2D
194 exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0);
195#endif
Sachin Kamat75371472012-03-10 02:54:36 -0800196#ifdef CONFIG_S5P_DEV_JPEG
197 exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam);
198#endif
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900199 return 0;
200}
201arch_initcall(exynos4_pm_init_power_domain);
202
Shawn Guobb13fab2012-04-26 10:35:40 +0800203int __init exynos_pm_late_initcall(void)
Thomas Abraham91cfbd42012-01-27 15:25:00 +0900204{
205 pm_genpd_poweroff_unused();
206 return 0;
207}