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/clk.h>
21 #include <linux/delay.h>
22 #include <linux/of_address.h>
23 #include <linux/of_platform.h>
24 #include <linux/sched.h>
26 #define INT_LOCAL_PWR_EN 0x7
27 #define MAX_CLK_PER_DOMAIN 4
30 * Exynos specific wrapper around the generic power domain
32 struct exynos_pm_domain {
36 struct generic_pm_domain pd;
38 struct clk *clk[MAX_CLK_PER_DOMAIN];
39 struct clk *pclk[MAX_CLK_PER_DOMAIN];
42 static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
44 struct exynos_pm_domain *pd;
49 pd = container_of(domain, struct exynos_pm_domain, pd);
52 /* Set oscclk before powering off a domain*/
56 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
57 if (IS_ERR(pd->clk[i]))
59 if (clk_set_parent(pd->clk[i], pd->oscclk))
60 pr_err("%s: error setting oscclk as parent to clock %d\n",
65 pwr = power_on ? INT_LOCAL_PWR_EN : 0;
66 __raw_writel(pwr, base);
71 while ((__raw_readl(base + 0x4) & INT_LOCAL_PWR_EN) != pwr) {
73 op = (power_on) ? "enable" : "disable";
74 pr_err("Power domain %s %s failed\n", domain->name, op);
79 usleep_range(80, 100);
82 /* Restore clocks after powering on a domain*/
86 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
87 if (IS_ERR(pd->clk[i]))
89 if (clk_set_parent(pd->clk[i], pd->pclk[i]))
90 pr_err("%s: error setting parent to clock%d\n",
98 static int exynos_pd_power_on(struct generic_pm_domain *domain)
100 return exynos_pd_power(domain, true);
103 static int exynos_pd_power_off(struct generic_pm_domain *domain)
105 return exynos_pd_power(domain, false);
108 static __init int exynos4_pm_init_power_domain(void)
110 struct platform_device *pdev;
111 struct device_node *np;
113 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
114 struct exynos_pm_domain *pd;
118 pdev = of_find_device_by_node(np);
121 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
123 pr_err("%s: failed to allocate memory for domain\n",
128 pd->pd.name = kstrdup(np->name, GFP_KERNEL);
129 pd->name = pd->pd.name;
130 pd->base = of_iomap(np, 0);
131 pd->pd.power_off = exynos_pd_power_off;
132 pd->pd.power_on = exynos_pd_power_on;
134 pd->oscclk = clk_get(dev, "oscclk");
135 if (IS_ERR(pd->oscclk))
138 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
141 snprintf(clk_name, sizeof(clk_name), "clk%d", i);
142 pd->clk[i] = clk_get(dev, clk_name);
143 if (IS_ERR(pd->clk[i]))
145 snprintf(clk_name, sizeof(clk_name), "pclk%d", i);
146 pd->pclk[i] = clk_get(dev, clk_name);
147 if (IS_ERR(pd->pclk[i])) {
149 pd->clk[i] = ERR_PTR(-EINVAL);
154 if (IS_ERR(pd->clk[0]))
158 on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
160 pm_genpd_init(&pd->pd, NULL, !on);
161 of_genpd_add_provider_simple(np, &pd->pd);
166 arch_initcall(exynos4_pm_init_power_domain);