Commit | Line | Data |
---|---|---|
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> | |
22 | ||
23 | #include <mach/regs-pmu.h> | |
24 | #include <plat/devs.h> | |
25 | ||
26 | /* | |
27 | * Exynos specific wrapper around the generic power domain | |
28 | */ | |
29 | struct exynos_pm_domain { | |
30 | void __iomem *base; | |
31 | char const *name; | |
32 | bool is_off; | |
33 | struct generic_pm_domain pd; | |
34 | }; | |
35 | ||
36 | static 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 | ||
65 | static int exynos_pd_power_on(struct generic_pm_domain *domain) | |
66 | { | |
67 | return exynos_pd_power(domain, true); | |
68 | } | |
69 | ||
70 | static 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) \ | |
76 | static 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 | |
86 | static __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; | |
92 | ||
93 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); | |
94 | if (!pd) { | |
95 | pr_err("%s: failed to allocate memory for domain\n", | |
96 | __func__); | |
97 | return -ENOMEM; | |
98 | } | |
99 | ||
100 | if (of_get_property(np, "samsung,exynos4210-pd-off", NULL)) | |
101 | pd->is_off = true; | |
102 | pd->name = np->name; | |
103 | pd->base = of_iomap(np, 0); | |
104 | pd->pd.power_off = exynos_pd_power_off; | |
105 | pd->pd.power_on = exynos_pd_power_on; | |
106 | pd->pd.of_node = np; | |
107 | pm_genpd_init(&pd->pd, NULL, false); | |
108 | } | |
109 | return 0; | |
110 | } | |
111 | #else | |
112 | static __init int exynos_pm_dt_parse_domains(void) | |
113 | { | |
114 | return 0; | |
115 | } | |
116 | #endif /* CONFIG_OF */ | |
117 | ||
118 | static __init void exynos_pm_add_dev_to_genpd(struct platform_device *pdev, | |
119 | struct exynos_pm_domain *pd) | |
120 | { | |
121 | if (pdev->dev.bus) { | |
122 | if (pm_genpd_add_device(&pd->pd, &pdev->dev)) | |
123 | pr_info("%s: error in adding %s device to %s power" | |
124 | "domain\n", __func__, dev_name(&pdev->dev), | |
125 | pd->name); | |
126 | } | |
127 | } | |
128 | ||
129 | EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc"); | |
130 | EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d"); | |
131 | EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0"); | |
132 | EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1"); | |
133 | EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv"); | |
134 | EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam"); | |
135 | EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps"); | |
136 | ||
137 | static struct exynos_pm_domain *exynos4_pm_domains[] = { | |
138 | &exynos4_pd_mfc, | |
139 | &exynos4_pd_g3d, | |
140 | &exynos4_pd_lcd0, | |
141 | &exynos4_pd_lcd1, | |
142 | &exynos4_pd_tv, | |
143 | &exynos4_pd_cam, | |
144 | &exynos4_pd_gps, | |
145 | }; | |
146 | ||
147 | static __init int exynos4_pm_init_power_domain(void) | |
148 | { | |
149 | int idx; | |
150 | ||
151 | if (of_have_populated_dt()) | |
152 | return exynos_pm_dt_parse_domains(); | |
153 | ||
154 | for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) | |
155 | pm_genpd_init(&exynos4_pm_domains[idx]->pd, NULL, | |
156 | exynos4_pm_domains[idx]->is_off); | |
157 | ||
158 | #ifdef CONFIG_S5P_DEV_FIMD0 | |
159 | exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0); | |
160 | #endif | |
161 | #ifdef CONFIG_S5P_DEV_TV | |
162 | exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv); | |
163 | exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv); | |
164 | #endif | |
165 | #ifdef CONFIG_S5P_DEV_MFC | |
166 | exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc); | |
167 | #endif | |
168 | #ifdef CONFIG_S5P_DEV_FIMC0 | |
169 | exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam); | |
170 | #endif | |
171 | #ifdef CONFIG_S5P_DEV_FIMC1 | |
172 | exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam); | |
173 | #endif | |
174 | #ifdef CONFIG_S5P_DEV_FIMC2 | |
175 | exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam); | |
176 | #endif | |
177 | #ifdef CONFIG_S5P_DEV_FIMC3 | |
178 | exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam); | |
179 | #endif | |
180 | #ifdef CONFIG_S5P_DEV_CSIS0 | |
181 | exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam); | |
182 | #endif | |
183 | #ifdef CONFIG_S5P_DEV_CSIS1 | |
184 | exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam); | |
a9e87bd9 SK |
185 | #endif |
186 | #ifdef CONFIG_S5P_DEV_G2D | |
187 | exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0); | |
75371477 SK |
188 | #endif |
189 | #ifdef CONFIG_S5P_DEV_JPEG | |
190 | exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam); | |
91cfbd4e TA |
191 | #endif |
192 | return 0; | |
193 | } | |
194 | arch_initcall(exynos4_pm_init_power_domain); | |
195 | ||
bb13fabc | 196 | int __init exynos_pm_late_initcall(void) |
91cfbd4e TA |
197 | { |
198 | pm_genpd_poweroff_unused(); | |
199 | return 0; | |
200 | } |