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];
40 struct clk *asb_clk[MAX_CLK_PER_DOMAIN];
43 static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
45 struct exynos_pm_domain *pd;
51 pd = container_of(domain, struct exynos_pm_domain, pd);
54 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
55 if (IS_ERR(pd->asb_clk[i]))
57 clk_prepare_enable(pd->asb_clk[i]);
60 /* Set oscclk before powering off a domain*/
62 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
63 if (IS_ERR(pd->clk[i]))
65 if (clk_set_parent(pd->clk[i], pd->oscclk))
66 pr_err("%s: error setting oscclk as parent to clock %d\n",
71 pwr = power_on ? INT_LOCAL_PWR_EN : 0;
72 __raw_writel(pwr, base);
77 while ((__raw_readl(base + 0x4) & INT_LOCAL_PWR_EN) != pwr) {
79 op = (power_on) ? "enable" : "disable";
80 pr_err("Power domain %s %s failed\n", domain->name, op);
85 usleep_range(80, 100);
88 /* Restore clocks after powering on a domain*/
90 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
91 if (IS_ERR(pd->clk[i]))
93 if (clk_set_parent(pd->clk[i], pd->pclk[i]))
94 pr_err("%s: error setting parent to clock%d\n",
99 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
100 if (IS_ERR(pd->asb_clk[i]))
102 clk_disable_unprepare(pd->asb_clk[i]);
108 static int exynos_pd_power_on(struct generic_pm_domain *domain)
110 return exynos_pd_power(domain, true);
113 static int exynos_pd_power_off(struct generic_pm_domain *domain)
115 return exynos_pd_power(domain, false);
118 static __init int exynos4_pm_init_power_domain(void)
120 struct platform_device *pdev;
121 struct device_node *np;
123 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
124 struct exynos_pm_domain *pd;
128 pdev = of_find_device_by_node(np);
131 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
133 pr_err("%s: failed to allocate memory for domain\n",
138 pd->pd.name = kstrdup(dev_name(dev), GFP_KERNEL);
139 pd->name = pd->pd.name;
140 pd->base = of_iomap(np, 0);
141 pd->pd.power_off = exynos_pd_power_off;
142 pd->pd.power_on = exynos_pd_power_on;
144 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
147 snprintf(clk_name, sizeof(clk_name), "asb%d", i);
148 pd->asb_clk[i] = clk_get(dev, clk_name);
149 if (IS_ERR(pd->asb_clk[i]))
153 pd->oscclk = clk_get(dev, "oscclk");
154 if (IS_ERR(pd->oscclk))
157 for (i = 0; i < MAX_CLK_PER_DOMAIN; i++) {
160 snprintf(clk_name, sizeof(clk_name), "clk%d", i);
161 pd->clk[i] = clk_get(dev, clk_name);
162 if (IS_ERR(pd->clk[i]))
164 snprintf(clk_name, sizeof(clk_name), "pclk%d", i);
165 pd->pclk[i] = clk_get(dev, clk_name);
166 if (IS_ERR(pd->pclk[i])) {
168 pd->clk[i] = ERR_PTR(-EINVAL);
173 if (IS_ERR(pd->clk[0]))
177 on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
179 pm_genpd_init(&pd->pd, NULL, !on);
180 of_genpd_add_provider_simple(np, &pd->pd);
183 /* Assign the child power domains to their parents */
184 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
185 struct generic_pm_domain *child_domain, *parent_domain;
186 struct of_phandle_args args;
190 child_domain = of_genpd_get_from_provider(&args);
194 if (of_parse_phandle_with_args(np, "power-domains",
195 "#power-domain-cells", 0, &args) != 0)
198 parent_domain = of_genpd_get_from_provider(&args);
202 if (pm_genpd_add_subdomain(parent_domain, child_domain))
203 pr_warn("%s failed to add subdomain: %s\n",
204 parent_domain->name, child_domain->name);
206 pr_info("%s has as child subdomain: %s.\n",
207 parent_domain->name, child_domain->name);
213 arch_initcall(exynos4_pm_init_power_domain);