diff options
Diffstat (limited to 'arch/arm/mach-exynos/pm_domains.c')
-rw-r--r-- | arch/arm/mach-exynos/pm_domains.c | 93 |
1 files changed, 89 insertions, 4 deletions
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c index c0bc83a7663e..9f1351de52f7 100644 --- a/arch/arm/mach-exynos/pm_domains.c +++ b/arch/arm/mach-exynos/pm_domains.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/pm_domain.h> | 19 | #include <linux/pm_domain.h> |
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/of_address.h> | 21 | #include <linux/of_address.h> |
22 | #include <linux/of_platform.h> | ||
23 | #include <linux/sched.h> | ||
22 | 24 | ||
23 | #include <mach/regs-pmu.h> | 25 | #include <mach/regs-pmu.h> |
24 | #include <plat/devs.h> | 26 | #include <plat/devs.h> |
@@ -83,12 +85,88 @@ static struct exynos_pm_domain PD = { \ | |||
83 | } | 85 | } |
84 | 86 | ||
85 | #ifdef CONFIG_OF | 87 | #ifdef CONFIG_OF |
88 | static void exynos_add_device_to_domain(struct exynos_pm_domain *pd, | ||
89 | struct device *dev) | ||
90 | { | ||
91 | int ret; | ||
92 | |||
93 | dev_dbg(dev, "adding to power domain %s\n", pd->pd.name); | ||
94 | |||
95 | while (1) { | ||
96 | ret = pm_genpd_add_device(&pd->pd, dev); | ||
97 | if (ret != -EAGAIN) | ||
98 | break; | ||
99 | cond_resched(); | ||
100 | } | ||
101 | |||
102 | pm_genpd_dev_need_restore(dev, true); | ||
103 | } | ||
104 | |||
105 | static void exynos_remove_device_from_domain(struct device *dev) | ||
106 | { | ||
107 | struct generic_pm_domain *genpd = dev_to_genpd(dev); | ||
108 | int ret; | ||
109 | |||
110 | dev_dbg(dev, "removing from power domain %s\n", genpd->name); | ||
111 | |||
112 | while (1) { | ||
113 | ret = pm_genpd_remove_device(genpd, dev); | ||
114 | if (ret != -EAGAIN) | ||
115 | break; | ||
116 | cond_resched(); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | static void exynos_read_domain_from_dt(struct device *dev) | ||
121 | { | ||
122 | struct platform_device *pd_pdev; | ||
123 | struct exynos_pm_domain *pd; | ||
124 | struct device_node *node; | ||
125 | |||
126 | node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0); | ||
127 | if (!node) | ||
128 | return; | ||
129 | pd_pdev = of_find_device_by_node(node); | ||
130 | if (!pd_pdev) | ||
131 | return; | ||
132 | pd = platform_get_drvdata(pd_pdev); | ||
133 | exynos_add_device_to_domain(pd, dev); | ||
134 | } | ||
135 | |||
136 | static int exynos_pm_notifier_call(struct notifier_block *nb, | ||
137 | unsigned long event, void *data) | ||
138 | { | ||
139 | struct device *dev = data; | ||
140 | |||
141 | switch (event) { | ||
142 | case BUS_NOTIFY_BIND_DRIVER: | ||
143 | if (dev->of_node) | ||
144 | exynos_read_domain_from_dt(dev); | ||
145 | |||
146 | break; | ||
147 | |||
148 | case BUS_NOTIFY_UNBOUND_DRIVER: | ||
149 | exynos_remove_device_from_domain(dev); | ||
150 | |||
151 | break; | ||
152 | } | ||
153 | return NOTIFY_DONE; | ||
154 | } | ||
155 | |||
156 | static struct notifier_block platform_nb = { | ||
157 | .notifier_call = exynos_pm_notifier_call, | ||
158 | }; | ||
159 | |||
86 | static __init int exynos_pm_dt_parse_domains(void) | 160 | static __init int exynos_pm_dt_parse_domains(void) |
87 | { | 161 | { |
162 | struct platform_device *pdev; | ||
88 | struct device_node *np; | 163 | struct device_node *np; |
89 | 164 | ||
90 | for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") { | 165 | for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") { |
91 | struct exynos_pm_domain *pd; | 166 | struct exynos_pm_domain *pd; |
167 | int on; | ||
168 | |||
169 | pdev = of_find_device_by_node(np); | ||
92 | 170 | ||
93 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); | 171 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); |
94 | if (!pd) { | 172 | if (!pd) { |
@@ -97,15 +175,22 @@ static __init int exynos_pm_dt_parse_domains(void) | |||
97 | return -ENOMEM; | 175 | return -ENOMEM; |
98 | } | 176 | } |
99 | 177 | ||
100 | if (of_get_property(np, "samsung,exynos4210-pd-off", NULL)) | 178 | pd->pd.name = kstrdup(np->name, GFP_KERNEL); |
101 | pd->is_off = true; | 179 | pd->name = pd->pd.name; |
102 | pd->name = np->name; | ||
103 | pd->base = of_iomap(np, 0); | 180 | pd->base = of_iomap(np, 0); |
104 | pd->pd.power_off = exynos_pd_power_off; | 181 | pd->pd.power_off = exynos_pd_power_off; |
105 | pd->pd.power_on = exynos_pd_power_on; | 182 | pd->pd.power_on = exynos_pd_power_on; |
106 | pd->pd.of_node = np; | 183 | pd->pd.of_node = np; |
107 | pm_genpd_init(&pd->pd, NULL, false); | 184 | |
185 | platform_set_drvdata(pdev, pd); | ||
186 | |||
187 | on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN; | ||
188 | |||
189 | pm_genpd_init(&pd->pd, NULL, !on); | ||
108 | } | 190 | } |
191 | |||
192 | bus_register_notifier(&platform_bus_type, &platform_nb); | ||
193 | |||
109 | return 0; | 194 | return 0; |
110 | } | 195 | } |
111 | #else | 196 | #else |