1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/*
* Exynos Generic power domain support.
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Implementation of Exynos specific power domain control which is used in
* conjunction with runtime-pm. Support for both device-tree and non-device-tree
* based power domain support is included.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/* #include <mach/tmu.h> */
#include <linux/delay.h>
#include "pm_domains-exynos7580.h"
struct exynos7580_pd_data *exynos_pd_find_data(struct exynos_pm_domain *pd)
{
int i;
struct exynos7580_pd_data *pd_data;
/* find pd_data for each power domain */
for (i = 0, pd_data = &pd_data_list[0]; i < ARRAY_SIZE(pd_data_list); i++, pd_data++) {
if (strcmp(pd_data->name, pd->name))
continue;
DEBUG_PRINT_INFO("%s: found pd_data\n", pd->name);
break;
}
return pd_data;
}
int exynos_pd_clk_get(struct exynos_pm_domain *pd)
{
int i = 0;
struct exynos7580_pd_data *pd_data = pd->pd_data;
struct exynos_pd_clk *top_clks = NULL;
DEBUG_PRINT_INFO("%s: fetch pd top clkd\n", pd->name);
if (!pd_data) {
pr_err(PM_DOMAIN_PREFIX "pd_data is null\n");
return -ENODEV;
}
if (!pd_data->top_clks) {
DEBUG_PRINT_INFO("%s: pd clk not defined \n", pd->name);
return 0;
}
top_clks = pd_data->top_clks;
for (i = 0; i < pd_data->num_top_clks; i++) {
top_clks[i].clock = samsung_clk_get_by_reg((unsigned long)top_clks[i].reg, top_clks[i].bit_offset);
if (!top_clks[i].clock) {
pr_err(PM_DOMAIN_PREFIX "clk_get of %s's top clock has been failed i = %d \n", pd->name, i);
return -ENODEV;
}
}
return 0;
}
static int exynos7_pd_enable_ccf_clks(struct exynos_pd_clk *ptr, int nr_regs)
{
unsigned int ret;
for (; nr_regs > 0; nr_regs--, ptr++) {
ret = clk_prepare_enable(ptr->clock);
if (ret)
return ret;
DEBUG_PRINT_INFO("clock name : %s, usage_count : %d, SFR : 0x%x\n",
ptr->clock->name, ptr->clock->enable_count, __raw_readl(ptr->reg));
}
return 0;
}
static void exynos7_pd_disable_ccf_clks(struct exynos_pd_clk *ptr, int nr_regs)
{
for (; nr_regs > 0; nr_regs--, ptr++) {
if (ptr->clock->enable_count > 0) {
clk_disable_unprepare(ptr->clock);
DEBUG_PRINT_INFO("clock name : %s, usage_count : %d, SFR : 0x%x\n",
ptr->clock->name, ptr->clock->enable_count, __raw_readl(ptr->reg));
}
}
}
static void exynos7_pd_set_sys_pwr_regs(struct exynos_pd_reg *ptr, int nr_regs)
{
unsigned int reg;
if (!ptr)
return;
for (; nr_regs > 0; nr_regs--, ptr++) {
reg = __raw_readl(ptr->reg);
reg &= ~(1 << ptr->bit_offset);
__raw_writel(reg, ptr->reg);
}
}
static void exynos_pd_notify_power_state(struct exynos_pm_domain *pd, unsigned int turn_on)
{
#if defined(CONFIG_ARM_EXYNOS7580_BUS_DEVFREQ) && defined(CONFIG_PM_RUNTIME)
/* will be enabled once it is integrated with devfreq */
/* exynos7_int_notify_power_status(pd->genpd.name, true); */
/* exynos7_isp_notify_power_status(pd->genpd.name, true); */
/* exynos7_disp_notify_power_status(pd->genpd.name, true); */
#endif
}
static int exynos_pd_power_init(struct exynos_pm_domain *pd)
{
struct exynos7580_pd_data *pd_data = pd->pd_data;
DEBUG_PRINT_INFO("%s's init callback start\n", pd->name);
/* enable the top clocks, disabled by unused clock gating */
if (!pd_data->top_clks)
return 0;
exynos7_pd_enable_ccf_clks(pd_data->top_clks, pd_data->num_top_clks);
DEBUG_PRINT_INFO("%s's init callback start\n", pd->name);
return 0;
}
static int exynos_pd_power_on_pre(struct exynos_pm_domain *pd)
{
struct exynos7580_pd_data *pd_data = pd->pd_data;
DEBUG_PRINT_INFO("%s's on_pre callback start\n", pd->name);
/* 1. Enabling Top-to-Local clocks */
if (!pd_data->top_clks)
DEBUG_PRINT_INFO("Nothing to do for %s :\n", pd->name);
else
exynos7_pd_enable_ccf_clks(pd_data->top_clks, pd_data->num_top_clks);
/* 2. Setting sys pwr regs */
exynos7_pd_set_sys_pwr_regs(pd_data->sys_pwr_regs, pd_data->num_sys_pwr_regs);
DEBUG_PRINT_INFO("%s's on_pre callback end\n", pd->name);
return 0;
}
static int exynos_pd_power_on_post(struct exynos_pm_domain *pd)
{
struct exynos7580_pd_data *pd_data = pd->pd_data;
DEBUG_PRINT_INFO("%s's on_post callback start\n", pd->name);
/* 1. Restoring resetted SFRs belonged to this block */
exynos_restore_sfr(pd_data->save_list, pd_data->num_save_list);
exynos_pd_notify_power_state(pd, true);
DEBUG_PRINT_INFO("%s's on_post callback end\n", pd->name);
return 0;
}
static int exynos_pd_power_off_pre(struct exynos_pm_domain *pd)
{
struct exynos7580_pd_data *pd_data = pd->pd_data;
DEBUG_PRINT_INFO("%s's off_pre callback start\n", pd->name);
/* 1. Save SFRs belonged to this block */
exynos_save_sfr(pd_data->save_list, pd_data->num_save_list);
/* 2. Setting sys pwr */
exynos7_pd_set_sys_pwr_regs(pd_data->sys_pwr_regs, pd_data->num_sys_pwr_regs);
DEBUG_PRINT_INFO("%s's off_pre callback end\n", pd->name);
return 0;
}
static int exynos_pd_power_off_post(struct exynos_pm_domain *pd)
{
struct exynos7580_pd_data *pd_data = pd->pd_data;
DEBUG_PRINT_INFO("%s's off_post callback start\n", pd->name);
/* Disable the CMU top clocks */
if (!pd_data->top_clks)
DEBUG_PRINT_INFO("Nothing to do for %s :\n", pd->name);
else
exynos7_pd_disable_ccf_clks(pd_data->top_clks, pd_data->num_top_clks);
DEBUG_PRINT_INFO("%s's off_post callback end\n", pd->name);
return 0;
}
static struct exynos_pd_callback pd_callback_list[] = {
{
.name = "pd-aud",
.init = exynos_pd_power_init,
.on_pre = exynos_pd_power_on_pre,
.on_post = exynos_pd_power_on_post,
.off_pre = exynos_pd_power_off_pre,
}, {
.name = "pd-mfcmscl",
.init = exynos_pd_power_init,
.on_pre = exynos_pd_power_on_pre,
.on_post = exynos_pd_power_on_post,
.off_pre = exynos_pd_power_off_pre,
.off_post = exynos_pd_power_off_post,
}, {
.name = "pd-disp",
.init = exynos_pd_power_init,
.on_pre = exynos_pd_power_on_pre,
.on_post = exynos_pd_power_on_post,
.off_pre = exynos_pd_power_off_pre,
.off_post = exynos_pd_power_off_post,
}, {
.name = "pd-g3d",
.init = exynos_pd_power_init,
.on_pre = exynos_pd_power_on_pre,
.on_post = exynos_pd_power_on_post,
.off_pre = exynos_pd_power_off_pre,
.off_post = exynos_pd_power_off_post,
}, {
.name = "pd-isp",
.init = exynos_pd_power_init,
.on_pre = exynos_pd_power_on_pre,
.on_post = exynos_pd_power_on_post,
.off_pre = exynos_pd_power_off_pre,
.off_post = exynos_pd_power_off_post,
},
};
struct exynos_pd_callback *exynos_pd_find_callback(struct exynos_pm_domain *pd)
{
struct exynos_pd_callback *cb = NULL;
int i;
DEBUG_PRINT_INFO("%s: find callback function for\n", pd->name);
/* find callback function for power domain */
for (i = 0, cb = &pd_callback_list[0]; i < ARRAY_SIZE(pd_callback_list); i++, cb++) {
if (strcmp(cb->name, pd->name))
continue;
DEBUG_PRINT_INFO("%s: found callback function\n", pd->name);
break;
}
pd->cb = cb;
return cb;
}
|