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 <plat/devs.h>
30 * Exynos specific wrapper around the generic power domain
32 struct exynos_pm_domain {
36 struct generic_pm_domain pd;
39 static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
41 struct exynos_pm_domain *pd;
46 pd = container_of(domain, struct exynos_pm_domain, pd);
49 pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
50 __raw_writel(pwr, base);
55 while ((__raw_readl(base + 0x4) & S5P_INT_LOCAL_PWR_EN) != pwr) {
57 op = (power_on) ? "enable" : "disable";
58 pr_err("Power domain %s %s failed\n", domain->name, op);
63 usleep_range(80, 100);
68 static int exynos_pd_power_on(struct generic_pm_domain *domain)
70 return exynos_pd_power(domain, true);
73 static int exynos_pd_power_off(struct generic_pm_domain *domain)
75 return exynos_pd_power(domain, false);
78 static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
83 dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
86 ret = pm_genpd_add_device(&pd->pd, dev);
92 pm_genpd_dev_need_restore(dev, true);
95 static void exynos_remove_device_from_domain(struct device *dev)
97 struct generic_pm_domain *genpd = dev_to_genpd(dev);
100 dev_dbg(dev, "removing from power domain %s\n", genpd->name);
103 ret = pm_genpd_remove_device(genpd, dev);
110 static void exynos_read_domain_from_dt(struct device *dev)
112 struct platform_device *pd_pdev;
113 struct exynos_pm_domain *pd;
114 struct device_node *node;
116 node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
119 pd_pdev = of_find_device_by_node(node);
122 pd = platform_get_drvdata(pd_pdev);
123 exynos_add_device_to_domain(pd, dev);
126 static int exynos_pm_notifier_call(struct notifier_block *nb,
127 unsigned long event, void *data)
129 struct device *dev = data;
132 case BUS_NOTIFY_BIND_DRIVER:
134 exynos_read_domain_from_dt(dev);
138 case BUS_NOTIFY_UNBOUND_DRIVER:
139 exynos_remove_device_from_domain(dev);
146 static struct notifier_block platform_nb = {
147 .notifier_call = exynos_pm_notifier_call,
150 static __init int exynos4_pm_init_power_domain(void)
152 struct platform_device *pdev;
153 struct device_node *np;
155 for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
156 struct exynos_pm_domain *pd;
159 pdev = of_find_device_by_node(np);
161 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
163 pr_err("%s: failed to allocate memory for domain\n",
168 pd->pd.name = kstrdup(np->name, GFP_KERNEL);
169 pd->name = pd->pd.name;
170 pd->base = of_iomap(np, 0);
171 pd->pd.power_off = exynos_pd_power_off;
172 pd->pd.power_on = exynos_pd_power_on;
175 platform_set_drvdata(pdev, pd);
177 on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
179 pm_genpd_init(&pd->pd, NULL, !on);
182 bus_register_notifier(&platform_bus_type, &platform_nb);
186 arch_initcall(exynos4_pm_init_power_domain);