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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/* linux/arch/arm64/mach-exynos/asv-exynos.c
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* EXYNOS5 - ASV(Adoptive Support Voltage) driver
*
* 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 <linux/init.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/slab.h>
#ifdef CONFIG_SEC_PM_DEBUG
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#endif
#include <plat/cpu.h>
#include <mach/map.h>
#include <mach/asv-exynos.h>
#include <mach/asv-exynos_cal.h>
static LIST_HEAD(asv_list);
static DEFINE_MUTEX(asv_mutex);
static struct asv_common *exynos_asv_common;
#ifdef CONFIG_EXYNOS_ASV_MARGIN_TEST
#define MARGIN_UNIT (12500)
#define ID_NAME(x) \
(x == ID_CL1) ? "CL1" : \
((x == ID_CL0) ? "CL0" : \
((x == ID_INT) ? "INT" : \
((x == ID_MIF) ? "MIF" : \
((x == ID_G3D) ? "G3D" : \
((x == ID_ISP) ? "ISP" : \
"OTHERS")))))
static int offset_percent;
static int __init get_offset_volt(char *str)
{
get_option(&str, &offset_percent);
return 0;
}
early_param("volt_offset_percent", get_offset_volt);
#endif
void add_asv_member(struct asv_info *exynos_asv_info)
{
mutex_lock(&asv_mutex);
list_add_tail(&exynos_asv_info->node, &asv_list);
mutex_unlock(&asv_mutex);
}
struct asv_info *asv_get(enum asv_type_id exynos_asv_type_id)
{
struct asv_info *match_asv_info;
list_for_each_entry(match_asv_info, &asv_list, node)
if (exynos_asv_type_id == match_asv_info->asv_type)
return match_asv_info;
return 0;
}
#if defined (CONFIG_EXYNOS_ASV)
unsigned int get_match_volt(enum asv_type_id target_type, unsigned int target_freq)
{
struct asv_info *match_asv_info = asv_get(target_type);
unsigned int target_dvfs_level;
unsigned int i;
#ifdef CONFIG_EXYNOS_ASV_MARGIN_TEST
int actual_volt = 0;
int margin_volt;
#endif
if (!match_asv_info) {
pr_info("EXYNOS ASV: failed to get_match_volt(type: %d)\n", target_type);
return 0;
}
target_dvfs_level = match_asv_info->dvfs_level_nr;
for (i = 0; i < target_dvfs_level; i++) {
if (match_asv_info->asv_volt[i].asv_freq == target_freq) {
#ifndef CONFIG_EXYNOS_ASV_MARGIN_TEST
return match_asv_info->asv_volt[i].asv_value;
#else
actual_volt = match_asv_info->asv_volt[i].asv_value;
break;
#endif
}
}
#ifdef CONFIG_EXYNOS_ASV_MARGIN_TEST
if (actual_volt) {
margin_volt = actual_volt + ((actual_volt * offset_percent)/100);
if (offset_percent < -5) {
if (((actual_volt * offset_percent)/100) % MARGIN_UNIT != 0)
margin_volt -= ((actual_volt * offset_percent)/100) % MARGIN_UNIT;
} else if (offset_percent < 0) {
if (((actual_volt * offset_percent)/100) % MARGIN_UNIT != 0)
margin_volt -= MARGIN_UNIT + ((actual_volt * offset_percent)/100) % MARGIN_UNIT;
} else if (offset_percent <= 5) {
if ((actual_volt * offset_percent/100) % MARGIN_UNIT != 0)
margin_volt += MARGIN_UNIT - ((actual_volt * offset_percent)/100) % MARGIN_UNIT;
} else {
if (((actual_volt * offset_percent)/100) % MARGIN_UNIT != 0)
margin_volt -= ((actual_volt * offset_percent)/100) % MARGIN_UNIT;
}
pr_info("%s[%d] offset_percent: %d Freq: %dKHz Actual:Margin volts[%d : %d] ",
ID_NAME(target_type), target_type, offset_percent,
target_freq, actual_volt, margin_volt);
return (unsigned int) margin_volt;
}
#endif
/* If there is no matched freq, return max supplied voltage */
return match_asv_info->max_volt_value;
}
#endif
#if defined (CONFIG_EXYNOS_ASV_DYNAMIC_ABB)
unsigned int get_match_abb(enum asv_type_id target_type, unsigned int target_freq)
{
struct asv_info *match_asv_info = asv_get(target_type);
unsigned int target_dvfs_level;
unsigned int i;
if (!match_asv_info) {
pr_info("EXYNOS ASV: failed to get_match_abb(type: %d)\n", target_type);
return 0;
}
target_dvfs_level = match_asv_info->dvfs_level_nr;
if (!match_asv_info->asv_abb) {
pr_info("EXYNOS ASV: request for nonexist asv type(type: %d)\n", target_type);
return 0;
}
for (i = 0; i < target_dvfs_level; i++) {
if (match_asv_info->asv_abb[i].asv_freq == target_freq)
return match_asv_info->asv_abb[i].asv_value;
}
/* If there is no matched freq, return default BB value */
return ABB_BYPASS;
}
bool is_set_abb_first(enum asv_type_id target_type, unsigned int old_freq, unsigned int target_freq)
{
int old_abb, target_abb;
old_abb = get_match_abb(target_type, old_freq);
target_abb = get_match_abb(target_type, target_freq);
if (old_abb == ABB_BYPASS && (target_abb == ABB_X070 || target_abb == ABB_X080))
return true;
else if ((old_abb == ABB_X120 || old_abb == ABB_X130) && target_abb == ABB_BYPASS)
return true;
else if (old_abb == ABB_BYPASS && (target_abb == ABB_X120 || target_abb == ABB_X130))
return false;
else
return true;
}
unsigned int set_match_abb(enum asv_type_id target_type, unsigned int target_abb)
{
struct asv_info *match_asv_info = asv_get(target_type);
if (!match_asv_info) {
pr_info("EXYNOS ASV: failed to set_match_abb(type: %d)\n", target_type);
return 0;
}
if (!match_asv_info->abb_info) {
pr_info("EXYNOS ASV: request for nonexist abb(type: %d)\n", target_type);
return 0;
}
match_asv_info->abb_info->target_abb = target_abb;
match_asv_info->abb_info->set_target_abb(match_asv_info);
return 0;
}
#endif
static void set_asv_info(struct asv_common *exynos_asv_common, bool show_volt)
{
struct asv_info *exynos_asv_info;
unsigned int match_grp_nr = 0;
list_for_each_entry(exynos_asv_info, &asv_list, node) {
match_grp_nr = exynos_asv_info->ops->get_asv_group(exynos_asv_common);
exynos_asv_info->result_asv_grp = match_grp_nr;
pr_info("%s ASV IDS/HPM group is %d\n", exynos_asv_info->name,
exynos_asv_info->result_asv_grp);
exynos_asv_info->ops->set_asv_info(exynos_asv_info, show_volt);
}
}
unsigned int get_sub_grp_match_asv_grp(enum asv_type_id target_type, unsigned int lv)
{
struct asv_info *match_asv_info = asv_get(target_type);
if (!match_asv_info) {
pr_info("EXYNOS ASV: failed to %s(type: %d)\n", __func__, target_type);
return 0;
}
if (!match_asv_info->asv_sub_grp) {
pr_info("EXYNOS ASV: request for nonexist asv_sub_grp(type: %d)\n", target_type);
return 0;
}
if (cal_get_table_ver() == 0)
return 15;
return match_asv_info->ops->get_asv_sub_group(match_asv_info, lv);
}
#ifdef CONFIG_EXYNOS_ASV_SUPPORT_RCC
void set_rcc_info(void)
{
struct asv_info *asv_info;
list_for_each_entry(asv_info, &asv_list, node)
asv_info->ops->set_rcc_info(asv_info);
exynos_asv_common->ops_cal->set_rcc_limit_info();
}
#endif
#ifdef CONFIG_SEC_PM_DEBUG
static int asv_group_show(struct seq_file *s, void *d)
{
struct asv_info *ai;
int i;
bool useABB = false;
list_for_each_entry(ai, &asv_list, node) {
seq_printf(s, "%s ASV group is %d\n", ai->name, ai->result_asv_grp);
#ifdef CONFIG_EXYNOS_ASV_DYNAMIC_ABB
if (ai->ops_cal && ai->ops_cal->get_use_abb)
useABB = ai->ops_cal->get_use_abb(ai->asv_type);
else
useABB = false;
#else
useABB = false;
#endif
for (i = 0; i < ai->dvfs_level_nr; i++) {
#ifdef CONFIG_EXYNOS_ASV_SUPPORT_RCC
if (useABB)
seq_printf(s, "%s LV%d freq : %d volt : %d, "
"abb : %d, rcc: %d, group: %d\n",
ai->name, i,
ai->asv_volt[i].asv_freq,
ai->asv_volt[i].asv_value,
ai->asv_abb[i].asv_value,
ai->asv_rcc[i].asv_value,
ai->asv_sub_grp[i].asv_grp);
else
seq_printf(s, "%s LV%d freq : %d volt : %d, "
"rcc : %d, group : %d\n",
ai->name, i,
ai->asv_volt[i].asv_freq,
ai->asv_volt[i].asv_value,
ai->asv_rcc[i].asv_value,
ai->asv_sub_grp[i].asv_grp);
#else
if (useABB)
seq_printf(s, "%s LV%d freq : %d volt : %d, "
"abb : %d, group: %d\n",
ai->name, i,
ai->asv_volt[i].asv_freq,
ai->asv_volt[i].asv_value,
ai->asv_abb[i].asv_value,
ai->asv_sub_grp[i].asv_grp);
else
seq_printf(s, "%s LV%d freq : %d volt : %d, "
"group : %d\n",
ai->name, i,
ai->asv_volt[i].asv_freq,
ai->asv_volt[i].asv_value,
ai->asv_sub_grp[i].asv_grp);
#endif
}
}
return 0;
}
static int asv_group_open(struct inode *inode, struct file *file)
{
return single_open(file, asv_group_show, inode->i_private);
}
const static struct file_operations asv_group_fops = {
.open = asv_group_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int asv_summary_show(struct seq_file *s, void *d)
{
unsigned int asv_summary[ASV_TYPE_END];
unsigned int i;
for (i = 0; i < ASV_TYPE_END; i++)
asv_summary[i] = get_sub_grp_match_asv_grp(i, 0);
seq_printf(s, "big:%u, LITTLE:%u, INT:%u, MIF:%u, G3D:%u, ISP:%u\n",
asv_summary[ID_CL1], asv_summary[ID_CL0],
asv_summary[ID_INT], asv_summary[ID_MIF],
asv_summary[ID_G3D], asv_summary[ID_ISP]);
return 0;
}
static int asv_summary_open(struct inode *inode, struct file *file)
{
return single_open(file, asv_summary_show, inode->i_private);
}
const static struct file_operations asv_summary_fops = {
.open = asv_summary_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif /* CONFIG_SEC_PM_DEBUG */
static int __init asv_init(void)
{
int ret = 0;
exynos_asv_common = kzalloc(sizeof(struct asv_common), GFP_KERNEL);
if (!exynos_asv_common) {
pr_err("ASV : Allocation failed\n");
ret = -EINVAL;
goto out;
}
/* Define init function for each SoC types */
ret = exynos_init_asv(exynos_asv_common);
if (ret) {
pr_err("ASV : Unknown SoC type\n");
ret = -EINVAL;
goto out;
}
if (ret) {
pr_err("ASV : asv initialize failed\n");
goto out;
}
/* If it is need to initialize, run init function */
if (exynos_asv_common->init) {
if (exynos_asv_common->init()) {
pr_err("ASV : Can not run init functioin\n");
ret = -EINVAL;
goto out;
}
}
/* Regist ASV member for each SoC */
if (exynos_asv_common->regist_asv_member) {
ret = exynos_asv_common->regist_asv_member();
} else {
pr_err("ASV : There is no regist_asv_member function\n");
ret = -EINVAL;
goto out;
}
set_asv_info(exynos_asv_common, true);
#ifdef CONFIG_SEC_PM_DEBUG
debugfs_create_file("asv_group", S_IRUSR, NULL, NULL, &asv_group_fops);
debugfs_create_file("asv_summary", S_IRUSR, NULL, NULL, &asv_summary_fops);
#endif
out:
return ret;
}
arch_initcall_sync(asv_init);
|