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>
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
{
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
;
45 pd
= container_of(domain
, struct exynos_pm_domain
, pd
);
48 pwr
= power_on
? S5P_INT_LOCAL_PWR_EN
: 0;
49 __raw_writel(pwr
, base
);
54 while ((__raw_readl(base
+ 0x4) & S5P_INT_LOCAL_PWR_EN
) != pwr
) {
56 op
= (power_on
) ? "enable" : "disable";
57 pr_err("Power domain %s %s failed\n", domain
->name
, op
);
62 usleep_range(80, 100);
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, \
82 .power_off = exynos_pd_power_off, \
83 .power_on = exynos_pd_power_on, \
88 static void exynos_add_device_to_domain(struct exynos_pm_domain
*pd
,
93 dev_dbg(dev
, "adding to power domain %s\n", pd
->pd
.name
);
96 ret
= pm_genpd_add_device(&pd
->pd
, dev
);
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
);
110 dev_dbg(dev
, "removing from power domain %s\n", genpd
->name
);
113 ret
= pm_genpd_remove_device(genpd
, dev
);
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);
129 pd_pdev
= of_find_device_by_node(node
);
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
;
142 case BUS_NOTIFY_BIND_DRIVER
:
144 exynos_read_domain_from_dt(dev
);
148 case BUS_NOTIFY_UNBOUND_DRIVER
:
149 exynos_remove_device_from_domain(dev
);
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
;
169 pdev
= of_find_device_by_node(np
);
171 pd
= kzalloc(sizeof(*pd
), GFP_KERNEL
);
173 pr_err("%s: failed to allocate memory for domain\n",
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
;
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
);
197 static __init
int exynos_pm_dt_parse_domains(void)
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
)
207 if (!pm_genpd_add_device(&pd
->pd
, &pdev
->dev
))
208 pm_genpd_dev_need_restore(&pdev
->dev
, true);
210 pr_info("%s: error in adding %s device to %s power"
211 "domain\n", __func__
, dev_name(&pdev
->dev
),
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
[] = {
234 static __init
int exynos4_pm_init_power_domain(void)
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
);
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
);
255 #ifdef CONFIG_S5P_DEV_MFC
256 exynos_pm_add_dev_to_genpd(&s5p_device_mfc
, &exynos4_pd_mfc
);
258 #ifdef CONFIG_S5P_DEV_FIMC0
259 exynos_pm_add_dev_to_genpd(&s5p_device_fimc0
, &exynos4_pd_cam
);
261 #ifdef CONFIG_S5P_DEV_FIMC1
262 exynos_pm_add_dev_to_genpd(&s5p_device_fimc1
, &exynos4_pd_cam
);
264 #ifdef CONFIG_S5P_DEV_FIMC2
265 exynos_pm_add_dev_to_genpd(&s5p_device_fimc2
, &exynos4_pd_cam
);
267 #ifdef CONFIG_S5P_DEV_FIMC3
268 exynos_pm_add_dev_to_genpd(&s5p_device_fimc3
, &exynos4_pd_cam
);
270 #ifdef CONFIG_S5P_DEV_CSIS0
271 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0
, &exynos4_pd_cam
);
273 #ifdef CONFIG_S5P_DEV_CSIS1
274 exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1
, &exynos4_pd_cam
);
276 #ifdef CONFIG_S5P_DEV_G2D
277 exynos_pm_add_dev_to_genpd(&s5p_device_g2d
, &exynos4_pd_lcd0
);
279 #ifdef CONFIG_S5P_DEV_JPEG
280 exynos_pm_add_dev_to_genpd(&s5p_device_jpeg
, &exynos4_pd_cam
);
284 arch_initcall(exynos4_pm_init_power_domain
);
286 int __init
exynos_pm_late_initcall(void)
288 pm_genpd_poweroff_unused();