1 // SPDX-License-Identifier: GPL-2.0
3 // Exynos Generic power domain support.
5 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 // http://www.samsung.com
8 // Implementation of Exynos specific power domain control which is used in
9 // conjunction with runtime-pm. Support for both device-tree and non-device-tree
10 // based power domain support is included.
13 #include <linux/err.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/pm_domain.h>
17 #include <linux/delay.h>
19 #include <linux/of_address.h>
20 #include <linux/pm_runtime.h>
22 struct exynos_pm_domain_config
{
23 /* Value for LOCAL_PWR_CFG and STATUS fields for each domain */
28 * Exynos specific wrapper around the generic power domain
30 struct exynos_pm_domain
{
32 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
? pd
->local_pwr_cfg
: 0;
47 writel_relaxed(pwr
, base
);
52 while ((readl_relaxed(base
+ 0x4) & pd
->local_pwr_cfg
) != pwr
) {
54 op
= (power_on
) ? "enable" : "disable";
55 pr_err("Power domain %s %s failed\n", domain
->name
, op
);
60 usleep_range(80, 100);
66 static int exynos_pd_power_on(struct generic_pm_domain
*domain
)
68 return exynos_pd_power(domain
, true);
71 static int exynos_pd_power_off(struct generic_pm_domain
*domain
)
73 return exynos_pd_power(domain
, false);
76 static const struct exynos_pm_domain_config exynos4210_cfg
= {
80 static const struct exynos_pm_domain_config exynos5433_cfg
= {
84 static const struct of_device_id exynos_pm_domain_of_match
[] = {
86 .compatible
= "samsung,exynos4210-pd",
87 .data
= &exynos4210_cfg
,
89 .compatible
= "samsung,exynos5433-pd",
90 .data
= &exynos5433_cfg
,
95 static const char *exynos_get_domain_name(struct device_node
*node
)
99 if (of_property_read_string(node
, "label", &name
) < 0)
100 name
= kbasename(node
->full_name
);
101 return kstrdup_const(name
, GFP_KERNEL
);
104 static int exynos_pd_probe(struct platform_device
*pdev
)
106 const struct exynos_pm_domain_config
*pm_domain_cfg
;
107 struct device
*dev
= &pdev
->dev
;
108 struct device_node
*np
= dev
->of_node
;
109 struct of_phandle_args child
, parent
;
110 struct exynos_pm_domain
*pd
;
113 pm_domain_cfg
= of_device_get_match_data(dev
);
114 pd
= devm_kzalloc(dev
, sizeof(*pd
), GFP_KERNEL
);
118 pd
->pd
.name
= exynos_get_domain_name(np
);
122 pd
->base
= of_iomap(np
, 0);
124 kfree_const(pd
->pd
.name
);
128 pd
->pd
.power_off
= exynos_pd_power_off
;
129 pd
->pd
.power_on
= exynos_pd_power_on
;
130 pd
->local_pwr_cfg
= pm_domain_cfg
->local_pwr_cfg
;
132 on
= readl_relaxed(pd
->base
+ 0x4) & pd
->local_pwr_cfg
;
134 pm_genpd_init(&pd
->pd
, NULL
, !on
);
135 ret
= of_genpd_add_provider_simple(np
, &pd
->pd
);
137 if (ret
== 0 && of_parse_phandle_with_args(np
, "power-domains",
138 "#power-domain-cells", 0, &parent
) == 0) {
140 child
.args_count
= 0;
142 if (of_genpd_add_subdomain(&parent
, &child
))
143 pr_warn("%pOF failed to add subdomain: %pOF\n",
144 parent
.np
, child
.np
);
146 pr_info("%pOF has as child subdomain: %pOF.\n",
147 parent
.np
, child
.np
);
150 pm_runtime_enable(dev
);
154 static struct platform_driver exynos_pd_driver
= {
155 .probe
= exynos_pd_probe
,
158 .of_match_table
= exynos_pm_domain_of_match
,
159 .suppress_bind_attrs
= true,
163 static __init
int exynos4_pm_init_power_domain(void)
165 return platform_driver_register(&exynos_pd_driver
);
167 core_initcall(exynos4_pm_init_power_domain
);