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.
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>
23 #include <mach/regs-pmu.h>
24 #include <plat/devs.h>
27 * Exynos specific wrapper around the generic power domain
29 struct exynos_pm_domain {
33 struct generic_pm_domain pd;
36 static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
38 struct exynos_pm_domain *pd;
43 pd = container_of(domain, struct exynos_pm_domain, pd);
46 pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
47 __raw_writel(pwr, base);
52 while ((__raw_readl(base + 0x4) & S5P_INT_LOCAL_PWR_EN) != pwr) {
54 op = (power_on) ? "enable" : "disable";
55 pr_err("Power domain %s %s failed\n", domain->name, op);
60 usleep_range(80, 100);
65 static int exynos_pd_power_on(struct generic_pm_domain *domain)
67 return exynos_pd_power(domain, true);
70 static int exynos_pd_power_off(struct generic_pm_domain *domain)
72 return exynos_pd_power(domain, false);
75 #define EXYNOS_GPD(PD, BASE, NAME) \
76 static struct exynos_pm_domain PD = { \
77 .base = (void __iomem *)BASE, \
80 .power_off = exynos_pd_power_off, \
81 .power_on = exynos_pd_power_on, \
86 static __init int exynos_pm_dt_parse_domains(void)
88 struct device_node *np;
90 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
91 struct exynos_pm_domain *pd;
93 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
95 pr_err("%s: failed to allocate memory for domain\n",
100 if (of_get_property(np, "samsung,exynos4210-pd-off", NULL))
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;
107 pm_genpd_init(&pd->pd, NULL, false);
112 static __init int exynos_pm_dt_parse_domains(void)
116 #endif /* CONFIG_OF */
118 static __init __maybe_unused void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
119 struct exynos_pm_domain *pd)
122 if (!pm_genpd_add_device(&pd->pd, &pdev->dev))
123 pm_genpd_dev_need_restore(&pdev->dev, true);
125 pr_info("%s: error in adding %s device to %s power"
126 "domain\n", __func__, dev_name(&pdev->dev),
131 EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc");
132 EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d");
133 EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0");
134 EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1");
135 EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv");
136 EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam");
137 EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps");
139 static struct exynos_pm_domain *exynos4_pm_domains[] = {
149 static __init int exynos4_pm_init_power_domain(void)
153 if (of_have_populated_dt())
154 return exynos_pm_dt_parse_domains();
156 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) {
157 struct exynos_pm_domain *pd = exynos4_pm_domains[idx];
158 int on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
160 pm_genpd_init(&pd->pd, NULL, !on);
163 #ifdef CONFIG_S5P_DEV_FIMD0
164 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
166 #ifdef CONFIG_S5P_DEV_TV
167 exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv);
168 exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv);
170 #ifdef CONFIG_S5P_DEV_MFC
171 exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc);
173 #ifdef CONFIG_S5P_DEV_FIMC0
174 exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam);
176 #ifdef CONFIG_S5P_DEV_FIMC1
177 exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam);
179 #ifdef CONFIG_S5P_DEV_FIMC2
180 exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam);
182 #ifdef CONFIG_S5P_DEV_FIMC3
183 exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam);
185 #ifdef CONFIG_S5P_DEV_CSIS0
186 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam);
188 #ifdef CONFIG_S5P_DEV_CSIS1
189 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam);
191 #ifdef CONFIG_S5P_DEV_G2D
192 exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0);
194 #ifdef CONFIG_S5P_DEV_JPEG
195 exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam);
199 arch_initcall(exynos4_pm_init_power_domain);
201 int __init exynos_pm_late_initcall(void)
203 pm_genpd_poweroff_unused();