1 /* arch/arm/mach-rockchip/rk_pm_tests/pvtm_test.c
3 * Copyright (C) 2014 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/clk.h>
16 #include <linux/delay.h>
17 #include <linux/module.h>
18 #include <linux/vmalloc.h>
19 #include <linux/regulator/consumer.h>
20 #include <asm/cacheflush.h>
24 extern int rockchip_tsadc_get_temp(int chn);
25 extern void rk29_wdt_keepalive(void);
26 extern u32 pvtm_get_value(u32 ch, u32 time_us);
30 static const char pi_result[] = "3141592653589793238462643383279528841971693993751058209749445923078164062862089986280348253421170679821480865132823664709384469555822317253594081284811174502841270193852115559644622948954930381964428810975665933446128475648233786783165271201991456485669234634861045432664821339360726024914127372458706606315588174881520920962829254917153643678925903611330530548820466521384146951941511609433057273657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566438602139494639522473719070217986943702770539217176293176752384674818467669451320005681271452635608277857713427577896091736371787214684409012249534301465495853710579227968925892354201995611212902196864344181598136297747713099605187072113499999983729780499510597317328160963185";
34 long a = 10000, b = 0, c = 2800, d = 0, e = 0, g = 0;
38 char *pi_calc, *pi_tmp;
39 char *pi_just = (char *)&pi_result[0];
40 size_t pi_just_size = sizeof(pi_result);
42 result = vmalloc(10000*sizeof(int));
46 f = vmalloc(2801*sizeof(long));
50 pi_calc = vmalloc(1000*sizeof(char));
56 for (; d = 0, g = c*2; c -= 14, result[bit++] = e+d/a, e = d%a)
57 for (b = c; d += f[b]*a, f[b] = d%--g, d /= g--, --b; d *= b)
61 for (i = 0; i < bit; i++)
62 len += sprintf(pi_tmp+len, "%d", result[i]);
64 if (strncmp(pi_just, pi_calc, pi_just_size) == 0) {
75 pr_info("calc_pi error\n");
79 void pvtm_repeat_test(void)
81 struct regulator *regulator_arm;
83 u32 pvtm, delta, old_pvtm;
84 u32 min_pvtm = -1, max_pvtm = 0;
85 u32 average = 0, sum = 0;
88 regulator_arm = regulator_get(NULL, "vdd_arm");
89 if (IS_ERR_OR_NULL(regulator_arm)) {
90 pr_err("get regulator err\n");
94 clk_core = clk_get(NULL, "clk_core");
95 if (IS_ERR_OR_NULL(clk_core)) {
96 pr_err("get clk err\n");
101 for (i = 0; i < n; i++) {
102 rk29_wdt_keepalive();
103 pvtm = pvtm_get_value(0, 1000);
117 delta = max_pvtm - min_pvtm;
118 pr_info("rate %lu volt %d max %u min %u average %u delta %u\n",
119 clk_get_rate(clk_core), regulator_get_voltage(regulator_arm),
120 max_pvtm, min_pvtm, average, delta);
123 void pvtm_samp_interval_test(void)
125 struct regulator *regulator_arm;
126 struct clk *clk_core;
127 u32 pvtm, old_pvtm = 0, samp_interval, times;
130 regulator_arm = regulator_get(NULL, "vdd_arm");
131 if (IS_ERR_OR_NULL(regulator_arm)) {
132 pr_err("get regulator err\n");
136 clk_core = clk_get(NULL, "clk_core");
137 if (IS_ERR_OR_NULL(clk_core)) {
138 pr_err("get clk err\n");
144 for (i = 0; i < n; i++) {
145 rk29_wdt_keepalive();
146 samp_interval = 10 * (1 << i);
147 pvtm = pvtm_get_value(0, samp_interval);
152 times = (1000*pvtm)/old_pvtm;
156 pr_info("rate %lu volt %d samp_interval %d pvtm %d times %d\n",
157 clk_get_rate(clk_core),
158 regulator_get_voltage(regulator_arm),
159 samp_interval, pvtm, times);
163 void pvtm_temp_test(void)
165 struct regulator *regulator_arm;
166 struct clk *clk_core;
167 int temp, old_temp = 0;
171 regulator_arm = regulator_get(NULL, "vdd_arm");
172 if (IS_ERR_OR_NULL(regulator_arm)) {
173 pr_err("get regulator err\n");
177 clk_core = clk_get(NULL, "clk_core");
178 if (IS_ERR_OR_NULL(clk_core)) {
179 pr_err("get clk err\n");
185 regulator_set_voltage(regulator_arm, volt, volt);
186 clk_set_rate(clk_core, rate);
189 rk29_wdt_keepalive();
190 temp = rockchip_tsadc_get_temp(1);
194 if (temp-old_temp >= 2)
195 pr_info("rate %lu volt %d temp %d pvtm %u\n",
196 clk_get_rate(clk_core),
197 regulator_get_voltage(regulator_arm),
198 temp, pvtm_get_value(0, 1000));
205 #define ALL_DONE_FLAG 'a'
206 #define ONE_DONE_FLAG 'o'
207 #define ALL_BUF_SIZE (PAGE_SIZE << 8)
208 #define ONE_BUF_SIZE PAGE_SIZE
209 #define VOLT_STEP (12500) /*mv*/
210 #define VOLT_START (1300000) /*mv*/
211 #define VOLT_END (1000000) /*mv*/
212 #define RATE_STEP (48000000) /*hz*/
213 #define RATE_START (816000000) /*hz*/
214 #define RATE_END (1200000000) /*hz*/
216 void scale_min_pvtm_fix_volt(void)
218 struct regulator *regulator_arm;
219 struct clk *clk_core;
221 u32 pvtm, old_pvtm = 0;
222 int volt, i, ret = 0;
224 regulator_arm = regulator_get(NULL, "vdd_arm");
225 if (IS_ERR_OR_NULL(regulator_arm)) {
226 pr_info("get regulator err\n");
230 clk_core = clk_get(NULL, "clk_core");
231 if (IS_ERR_OR_NULL(clk_core)) {
232 pr_info("get clk err\n");
239 for (i = 0; i < ALL_BUF_SIZE; i += ONE_BUF_SIZE) {
240 if (pvtm_buf[i] == ALL_DONE_FLAG) {
241 pr_info("=============test done!========\n");
245 pr_info("%s", pvtm_buf+i+1);
247 pr_info("no item!!!!\n");
252 rk29_wdt_keepalive();
256 if (pvtm_buf[i] != ONE_DONE_FLAG)
261 if (volt < VOLT_END) {
262 pvtm_buf[i] = ALL_DONE_FLAG;
266 pvtm_buf[i] = ONE_DONE_FLAG;
268 ret = regulator_set_voltage(regulator_arm, volt, volt);
270 pr_err("set volt(%d) err:%d\n", volt, ret);
273 rk29_wdt_keepalive();
279 rk29_wdt_keepalive();
284 clk_set_rate(clk_core, rate);
289 rk29_wdt_keepalive();
291 pvtm = pvtm_get_value(0, 1000);
294 sprintf(pvtm_buf+i+1, "%d %lu %d %d %d\n",
295 volt, clk_get_rate(clk_core), pvtm,
296 rockchip_tsadc_get_temp(1), old_pvtm-pvtm);
298 pr_info("%s", pvtm_buf+i+1);
306 void scale_min_pvtm_fix_rate(void)
308 struct regulator *regulator_arm;
309 struct clk *clk_core;
311 u32 pvtm, old_pvtm = 0;
312 int volt, i, ret = 0;
314 regulator_arm = regulator_get(NULL, "vdd_arm");
315 if (IS_ERR_OR_NULL(regulator_arm)) {
316 pr_info("get regulator err\n");
320 clk_core = clk_get(NULL, "clk_core");
321 if (IS_ERR_OR_NULL(clk_core)) {
322 pr_info("get clk err\n");
329 for (i = 0; i < ALL_BUF_SIZE; i += ONE_BUF_SIZE) {
330 if (pvtm_buf[i] == ALL_DONE_FLAG) {
331 pr_info("=============test done!========\n");
335 pr_info("%s", pvtm_buf+i+1);
337 pr_info("no item!!!!\n");
342 rk29_wdt_keepalive();
346 if (pvtm_buf[i] != ONE_DONE_FLAG)
352 if (rate > RATE_END) {
353 pvtm_buf[i] = ALL_DONE_FLAG;
357 pvtm_buf[i] = ONE_DONE_FLAG;
359 ret = regulator_set_voltage(regulator_arm, volt, volt);
361 pr_err("set volt(%d) err:%d\n", volt, ret);
364 rk29_wdt_keepalive();
369 ret = clk_set_rate(clk_core, rate);
371 rk29_wdt_keepalive();
375 regulator_set_voltage(regulator_arm, volt, volt);
379 rk29_wdt_keepalive();
381 pvtm = pvtm_get_value(0, 1000);
385 sprintf(pvtm_buf+i+1, "%d %lu %d %d %d\n",
386 volt, clk_get_rate(clk_core), pvtm,
387 rockchip_tsadc_get_temp(1), old_pvtm-pvtm);
389 pr_info("%s", pvtm_buf+i+1);
398 void scale_pvtm_fix_freq(void)
400 struct regulator *regulator_arm;
401 struct clk *clk_core_b, *clk_core_l;
403 u32 pvtm, old_pvtm = 0;
406 regulator_arm = regulator_get(NULL, "vdd_arm");
407 if (IS_ERR_OR_NULL(regulator_arm)) {
408 pr_info("get regulator err\n");
412 clk_core_b = clk_get(NULL, "clk_core_b");
413 if (IS_ERR_OR_NULL(clk_core_b)) {
414 pr_info("get clk err\n");
417 clk_core_l = clk_get(NULL, "clk_core_l");
418 if (IS_ERR_OR_NULL(clk_core_l)) {
419 pr_info("get clk err\n");
425 ret = regulator_set_voltage(regulator_arm, volt, volt);
427 pr_err("set volt(%d) err:%d\n", volt, ret);
430 clk_set_rate(clk_core_b, rate);
431 clk_set_rate(clk_core_l, rate);
433 pvtm = pvtm_get_value(0, 1000);
436 pr_info("%d %lu %d %d\n",
437 volt, clk_get_rate(clk_core_b), pvtm, old_pvtm-pvtm);
441 if (rate > 1200000000)
446 void scale_pvtm_fix_volt(void)
448 struct regulator *regulator_arm;
449 struct clk *clk_core_b, *clk_core_l;
451 u32 pvtm, old_pvtm = 0;
454 regulator_arm = regulator_get(NULL, "vdd_arm");
455 if (IS_ERR_OR_NULL(regulator_arm)) {
456 pr_info("get regulator err\n");
460 clk_core_b = clk_get(NULL, "clk_core_b");
461 if (IS_ERR_OR_NULL(clk_core_b)) {
462 pr_info("get clk err\n");
466 clk_core_l = clk_get(NULL, "clk_core_b");
467 if (IS_ERR_OR_NULL(clk_core_l)) {
468 pr_info("get clk err\n");
475 ret = regulator_set_voltage(regulator_arm, volt, volt);
477 pr_err("set volt(%d) err:%d\n", volt, ret);
479 ret = clk_set_rate(clk_core_b, rate);
480 ret = clk_set_rate(clk_core_l, rate);
482 regulator_set_voltage(regulator_arm, volt, volt);
484 pvtm = pvtm_get_value(0, 1000);
488 pr_info("%d %lu %d %d\n",
489 volt, clk_get_rate(clk_core_b), pvtm, old_pvtm-pvtm);
493 regulator_set_voltage(regulator_arm, 1300000, 1300000);
499 ssize_t pvtm_show(struct kobject *kobj, struct kobj_attribute *attr,
504 str += sprintf(str, "core:%d\ngpu:%d\n",
505 pvtm_get_value(0, 1000),
506 pvtm_get_value(1, 1000));
510 ssize_t pvtm_store(struct kobject *kobj, struct kobj_attribute *attr,
511 const char *buf, size_t n)
516 int pvtm_buf_init(void)
519 pvtm_buf = (char *)__get_free_pages(GFP_KERNEL, 8);
524 fs_initcall(pvtm_buf_init);