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 pd
->pclk
[i
] = clk_get_parent(pd
->clk
[i
]);
66 if (clk_set_parent(pd
->clk
[i
], pd
->oscclk
))
67 pr_err("%s: error setting oscclk as parent to clock %d\n",
72 pwr
= power_on
? INT_LOCAL_PWR_EN
: 0;
73 __raw_writel(pwr
, base
);
78 while ((__raw_readl(base
+ 0x4) & INT_LOCAL_PWR_EN
) != pwr
) {
80 op
= (power_on
) ? "enable" : "disable";
81 pr_err("Power domain %s %s failed\n", domain
->name
, op
);
86 usleep_range(80, 100);
89 /* Restore clocks after powering on a domain*/
91 for (i
= 0; i
< MAX_CLK_PER_DOMAIN
; i
++) {
92 if (IS_ERR(pd
->clk
[i
]))
95 if (IS_ERR(pd
->clk
[i
]))
96 continue; /* Skip on first power up */
97 if (clk_set_parent(pd
->clk
[i
], pd
->pclk
[i
]))
98 pr_err("%s: error setting parent to clock%d\n",
103 for (i
= 0; i
< MAX_CLK_PER_DOMAIN
; i
++) {
104 if (IS_ERR(pd
->asb_clk
[i
]))
106 clk_disable_unprepare(pd
->asb_clk
[i
]);
112 static int exynos_pd_power_on(struct generic_pm_domain
*domain
)
114 return exynos_pd_power(domain
, true);
117 static int exynos_pd_power_off(struct generic_pm_domain
*domain
)
119 return exynos_pd_power(domain
, false);
122 static __init
int exynos4_pm_init_power_domain(void)
124 struct device_node
*np
;
126 for_each_compatible_node(np
, NULL
, "samsung,exynos4210-pd") {
127 struct exynos_pm_domain
*pd
;
130 pd
= kzalloc(sizeof(*pd
), GFP_KERNEL
);
132 pr_err("%s: failed to allocate memory for domain\n",
137 pd
->pd
.name
= kstrdup_const(strrchr(np
->full_name
, '/') + 1,
145 pd
->name
= pd
->pd
.name
;
146 pd
->base
= of_iomap(np
, 0);
148 pr_warn("%s: failed to map memory\n", __func__
);
149 kfree_const(pd
->pd
.name
);
154 pd
->pd
.power_off
= exynos_pd_power_off
;
155 pd
->pd
.power_on
= exynos_pd_power_on
;
157 for (i
= 0; i
< MAX_CLK_PER_DOMAIN
; i
++) {
160 snprintf(clk_name
, sizeof(clk_name
), "asb%d", i
);
161 pd
->asb_clk
[i
] = of_clk_get_by_name(np
, clk_name
);
162 if (IS_ERR(pd
->asb_clk
[i
]))
166 pd
->oscclk
= of_clk_get_by_name(np
, "oscclk");
167 if (IS_ERR(pd
->oscclk
))
170 for (i
= 0; i
< MAX_CLK_PER_DOMAIN
; i
++) {
173 snprintf(clk_name
, sizeof(clk_name
), "clk%d", i
);
174 pd
->clk
[i
] = of_clk_get_by_name(np
, clk_name
);
175 if (IS_ERR(pd
->clk
[i
]))
178 * Skip setting parent on first power up.
179 * The parent at this time may not be useful at all.
181 pd
->pclk
[i
] = ERR_PTR(-EINVAL
);
184 if (IS_ERR(pd
->clk
[0]))
188 on
= __raw_readl(pd
->base
+ 0x4) & INT_LOCAL_PWR_EN
;
190 pm_genpd_init(&pd
->pd
, NULL
, !on
);
191 of_genpd_add_provider_simple(np
, &pd
->pd
);
194 /* Assign the child power domains to their parents */
195 for_each_compatible_node(np
, NULL
, "samsung,exynos4210-pd") {
196 struct generic_pm_domain
*child_domain
, *parent_domain
;
197 struct of_phandle_args args
;
201 child_domain
= of_genpd_get_from_provider(&args
);
202 if (IS_ERR(child_domain
))
205 if (of_parse_phandle_with_args(np
, "power-domains",
206 "#power-domain-cells", 0, &args
) != 0)
209 parent_domain
= of_genpd_get_from_provider(&args
);
210 if (IS_ERR(parent_domain
))
213 if (pm_genpd_add_subdomain(parent_domain
, child_domain
))
214 pr_warn("%s failed to add subdomain: %s\n",
215 parent_domain
->name
, child_domain
->name
);
217 pr_info("%s has as child subdomain: %s.\n",
218 parent_domain
->name
, child_domain
->name
);
223 core_initcall(exynos4_pm_init_power_domain
);