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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
|
/*
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* EXYNOS5430 - EAGLE Core frequency scaling support
*
* 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/kernel.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/cpufreq.h>
#include <linux/clk-private.h>
#include <mach/map.h>
#include <mach/regs-clock.h>
#include <mach/regs-clock-exynos5430.h>
#include <mach/regs-pmu.h>
#include <mach/cpufreq.h>
#include <mach/asv-exynos.h>
#define CPUFREQ_LEVEL_END_CA15 (L23 + 1)
#define L2_LOCAL_PWR_EN 0x7
#undef PRINT_DIV_VAL
#undef ENABLE_CLKOUT
#define EMA_VAL_REG (S5P_VA_CHIPID2 + 0x20)
#define EMA_CON1_SHIFT 2
#define EMA_CON2_SHIFT 5
#define EMA_CON_MASK 0x7
#define EMA_VAL_0 0x0
#define EMA_VAL_1 0x1
#define EMA_VAL_3 0x3
#define EMA_VAL_4 0x4
#define EMA_VOLT 900000
#define EGL_L1_EMA_SHIFT 8
#define EGL_L2_EMA_SHIFT 20
#define CLK_EGL_EMA_OFFSET 0x0330
static int max_support_idx_CA15;
static int min_support_idx_CA15 = (CPUFREQ_LEVEL_END_CA15 - 1);
static struct clk *mout_egl;
static struct clk *mout_egl_pll;
static struct clk *sclk_bus_pll;
static struct clk *mout_bus_pll_user;
static struct clk *fout_egl_pll;
static unsigned int spd_option_flag, spd_sel;
static void __iomem *clk_egl_2_base;
static int egl_ema_con1;
static int egl_ema_con2;
static unsigned int exynos5430_volt_table_CA15[CPUFREQ_LEVEL_END_CA15];
static unsigned int exynos5430_abb_table_CA15[CPUFREQ_LEVEL_END_CA15];
static struct cpufreq_frequency_table exynos5430_freq_table_CA15[] = {
{L0, 2500 * 1000},
{L1, 2400 * 1000},
{L2, 2300 * 1000},
{L3, 2200 * 1000},
{L4, 2100 * 1000},
{L5, 2000 * 1000},
{L6, 1900 * 1000},
{L7, 1800 * 1000},
{L8, 1700 * 1000},
{L9, 1600 * 1000},
{L10, 1500 * 1000},
{L11, 1400 * 1000},
{L12, 1300 * 1000},
{L13, 1200 * 1000},
{L14, 1100 * 1000},
{L15, 1000 * 1000},
{L16, 900 * 1000},
{L17, 800 * 1000},
{L18, 700 * 1000},
{L19, 600 * 1000},
{L20, 500 * 1000},
{L21, 400 * 1000},
{L22, 300 * 1000},
{L23, 200 * 1000},
{0, CPUFREQ_TABLE_END},
};
static struct cpufreq_clkdiv exynos5430_clkdiv_table_CA15[CPUFREQ_LEVEL_END_CA15];
static unsigned int clkdiv_cpu0_5430_CA15[CPUFREQ_LEVEL_END_CA15][6] = {
/*
* Clock divider value for following
* { EGL1, EGL2, ACLK_EGL, PCLK_EGL,
* ATCLK, PCLK_DBG_EGL }
*/
/* ARM L0: 2.5GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L1: 2.4GMHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L2: 2.3GMHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L3: 2.2GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L4: 2.1GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L5: 2.0GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L6: 1.9GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L7: 1.8GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L8: 1.7GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L9: 1.6GHz */
{ 0, 0, 4, 7, 7, 7 },
/* ARM L10: 1.5GHz */
{ 0, 0, 3, 7, 7, 7 },
/* ARM L11: 1.4GHz */
{ 0, 0, 3, 7, 7, 7 },
/* ARM L12: 1.3GHz */
{ 0, 0, 3, 7, 7, 7 },
/* ARM L13: 1.2GHz */
{ 0, 0, 3, 7, 7, 7 },
/* ARM L14: 1.1GHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L15: 1.0GHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L16: 900MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L17: 800MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L18: 700MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L19: 600MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L20: 500MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L21: 400MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L22: 300MHz */
{ 0, 0, 2, 7, 7, 7 },
/* ARM L23: 200MHz */
{ 0, 0, 2, 7, 7, 7 },
};
static unsigned int clkdiv_cpu1_5430_CA15[CPUFREQ_LEVEL_END_CA15][2] = {
/*
* Clock divider value for following
* { SCLK_EGL_PLL, SCLK_HPM_EGL }
*/
/* ARM L0: 2.5GHz */
{ 1, 7 },
/* ARM L1: 2.4GMHz */
{ 1, 7 },
/* ARM L2: 2.3GMHz */
{ 1, 7 },
/* ARM L3: 2.2GHz */
{ 1, 7 },
/* ARM L4: 2.1GHz */
{ 1, 7 },
/* ARM L5: 2.0GHz */
{ 1, 7 },
/* ARM L6: 1.9GHz */
{ 1, 7 },
/* ARM L7: 1.8GHz */
{ 1, 7 },
/* ARM L8: 1.7GHz */
{ 1, 7 },
/* ARM L9: 1.6GHz */
{ 1, 7 },
/* ARM L10: 1.5GHz */
{ 1, 7 },
/* ARM L11: 1.4GHz */
{ 1, 7 },
/* ARM L12: 1.3GHz */
{ 1, 7 },
/* ARM L13: 1.2GHz */
{ 1, 7 },
/* ARM L14: 1.1GHz */
{ 1, 7 },
/* ARM L15: 1.0GHz */
{ 1, 7 },
/* ARM L16: 900MHz */
{ 1, 7 },
/* ARM L17: 800MHz */
{ 1, 7 },
/* ARM L18: 700MHz */
{ 1, 7 },
/* ARM L19: 600MHz */
{ 1, 7 },
/* ARM L20: 500MHz */
{ 1, 7 },
/* ARM L21: 400MHz */
{ 1, 7 },
/* ARM L22: 300MHz */
{ 1, 7 },
/* ARM L23: 200MHz */
{ 1, 7 },
};
static unsigned int exynos5430_egl_pll_pms_table_CA15[CPUFREQ_LEVEL_END_CA15] = {
/* MDIV | PDIV | SDIV */
/* EGL_PLL FOUT L0: 2.5GHz */
PLL2450X_PMS(625, 6, 0),
/* EGL_PLL FOUT L1: 2.4GHz */
PLL2450X_PMS(500, 5, 0),
/* EGL_PLL FOUT L2: 2.3GHz */
PLL2450X_PMS(575, 6, 0),
/* EGL_PLL FOUT L3: 2.2GHz */
PLL2450X_PMS(550, 6, 0),
/* EGL_PLL FOUT L4: 2.1GHz */
PLL2450X_PMS(350, 4, 0),
/* EGL_PLL FOUT L5: 2.0GHz */
PLL2450X_PMS(500, 6, 0),
/* EGL_PLL FOUT L6: 1.9GHz */
PLL2450X_PMS(475, 6, 0),
/* EGL_PLL FOUT L7: 1.8GHz */
PLL2450X_PMS(375, 5, 0),
/* EGL_PLL FOUT L8: 1.7GHz */
PLL2450X_PMS(425, 6, 0),
/* EGL_PLL FOUT L9: 1.6GHz */
PLL2450X_PMS(400, 6, 0),
/* EGL_PLL FOUT L10: 1.5GHz */
PLL2450X_PMS(250, 4, 0),
/* EGL_PLL FOUT L11: 1.4GHz */
PLL2450X_PMS(350, 6, 0),
/* EGL_PLL FOUT L12: 1.3GHz */
PLL2450X_PMS(325, 6, 0),
/* EGL_PLL FOUT L13: 1.2GHz */
PLL2450X_PMS(500, 5, 1),
/* EGL_PLL FOUT L14: 1.1GHz */
PLL2450X_PMS(550, 6, 1),
/* EGL_PLL FOUT L15: 1.0GHz */
PLL2450X_PMS(500, 6, 1),
/* EGL_PLL FOUT L16: 900MHz */
PLL2450X_PMS(375, 5, 1),
/* EGL_PLL FOUT L17: 800MHz */
PLL2450X_PMS(400, 6, 1),
/* EGL_PLL FOUT L18: 700MHz */
PLL2450X_PMS(350, 6, 1),
/* EGL_PLL FOUT L19: 600MHz */
PLL2450X_PMS(500, 5, 2),
/* EGL_PLL FOUT L20: 500MHz */
PLL2450X_PMS(500, 6, 2),
/* EGL_PLL FOUT L21: 400MHz */
PLL2450X_PMS(400, 6, 2),
/* EGL_PLL FOUT L22: 300MHz */
PLL2450X_PMS(500, 5, 3),
/* EGL_PLL FOUT L23: 200MHz */
PLL2450X_PMS(400, 6, 3),
};
/*
* ASV group voltage table
*/
static const unsigned int asv_voltage_5430_CA15[CPUFREQ_LEVEL_END_CA15] = {
1300000, /* LO 2500 */
1300000, /* L1 2400 */
1300000, /* L2 2300 */
1300000, /* L3 2200 */
1300000, /* L4 2100 */
1300000, /* L5 2000 */
1300000, /* L6 1900 */
1300000, /* L7 1800 */
1275000, /* L8 1700 */
1250000, /* L9 1600 */
1225000, /* L10 1500 */
1187500, /* L11 1400 */
1150000, /* L12 1300 */
1125000, /* L13 1200 */
1100000, /* L14 1100 */
1075000, /* L15 1000 */
1050000, /* L16 900 */
1025000, /* L17 800 */
1025000, /* L18 700 */
1000000, /* L19 600 */
1000000, /* L20 500 */
975000, /* L21 400 */
925000, /* L22 300 */
925000, /* L23 200 */
};
/* Minimum memory throughput in megabytes per second */
static int exynos5430_bus_table_CA15[CPUFREQ_LEVEL_END_CA15] = {
825000, /* 2.5 GHz */
825000, /* 2.4 GHz */
825000, /* 2.3 GHz */
825000, /* 2.2 GHz */
825000, /* 2.1 GHz */
825000, /* 2.0 GHz */
825000, /* 1.9 GHz */
825000, /* 1.8 GHz */
633000, /* 1.7 MHz */
633000, /* 1.6 GHz */
633000, /* 1.5 GHz */
633000, /* 1.4 GHz */
543000, /* 1.3 GHz */
543000, /* 1.2 GHz */
413000, /* 1.1 GHz */
413000, /* 1.0 GHz */
0, /* 900 MHz */
0, /* 800 MHz */
0, /* 700 MHz */
0, /* 600 MHz */
0, /* 500 MHz */
0, /* 400 MHz */
0, /* 300 MHz */
0, /* 200 MHz */
};
static int exynos5430_ema_valid_check_CA15(int ema_con_val)
{
int ret = 0;
switch (ema_con_val) {
case EMA_VAL_0:
case EMA_VAL_1:
case EMA_VAL_3:
case EMA_VAL_4:
ret = ema_con_val;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static void exynos5430_set_ema_CA15(unsigned int target_volt)
{
unsigned int tmp;
tmp = __raw_readl(clk_egl_2_base + CLK_EGL_EMA_OFFSET);
if (target_volt > EMA_VOLT) {
if (egl_ema_con1 > 0) {
tmp &= ~((EMA_CON_MASK << EGL_L1_EMA_SHIFT) |
(EMA_CON_MASK << EGL_L2_EMA_SHIFT));
tmp |= ((egl_ema_con1 << EGL_L1_EMA_SHIFT) |
(egl_ema_con1 << EGL_L2_EMA_SHIFT));
__raw_writel(tmp, clk_egl_2_base + CLK_EGL_EMA_OFFSET);
}
} else {
if (egl_ema_con2 > 0) {
tmp &= ~((EMA_CON_MASK << EGL_L1_EMA_SHIFT) |
(EMA_CON_MASK << EGL_L2_EMA_SHIFT));
tmp |= ((egl_ema_con2 << EGL_L1_EMA_SHIFT) |
(egl_ema_con2 << EGL_L2_EMA_SHIFT));
__raw_writel(tmp, clk_egl_2_base + CLK_EGL_EMA_OFFSET);
}
}
}
static void exynos5430_set_clkdiv_CA15(unsigned int div_index)
{
unsigned int tmp, tmp1;
/* Change Divider - EGL0 */
tmp = exynos5430_clkdiv_table_CA15[div_index].clkdiv0;
__raw_writel(tmp, EXYNOS5430_DIV_EGL0);
while (__raw_readl(EXYNOS5430_DIV_STAT_EGL0) & 0x111111)
cpu_relax();
/* Change Divider - EGL1 */
tmp1 = exynos5430_clkdiv_table_CA15[div_index].clkdiv1;
__raw_writel(tmp1, EXYNOS5430_DIV_EGL1);
while (__raw_readl(EXYNOS5430_DIV_STAT_EGL1) & 0x11)
cpu_relax();
#ifdef PRINT_DIV_VAL
tmp = __raw_readl(EXYNOS5430_DIV_EGL0);
tmp1 = __raw_readl(EXYNOS5430_DIV_EGL1);
pr_info("%s: DIV_EGL0[0x%08x], DIV_EGL1[0x%08x]\n",
__func__, tmp, tmp1);
#endif
}
static void exynos5430_set_egl_pll_CA15(unsigned int new_index, unsigned int old_index)
{
unsigned int tmp, pdiv;
/* 1. before change to BUS_PLL, set div for BUS_PLL output */
if ((new_index < L17) && (old_index < L17))
exynos5430_set_clkdiv_CA15(L17); /* pll_safe_idx of CA15 */
/* 2. CLKMUX_SEL_EGL = MOUT_BUS_PLL_USER, EGLCLK uses BUS_PLL_USER for lock time */
if (clk_set_parent(mout_egl, mout_bus_pll_user))
pr_err("Unable to set parent %s of clock %s.\n",
mout_bus_pll_user->name, mout_egl->name);
do {
cpu_relax();
tmp = __raw_readl(EXYNOS5430_SRC_STAT_EGL2);
tmp &= EXYNOS5430_SRC_STAT_EGL2_EGL_MASK;
tmp >>= EXYNOS5430_SRC_STAT_EGL2_EGL_SHIFT;
} while (tmp != 0x2);
/* 3. Set EGL_PLL Lock time */
pdiv = ((exynos5430_egl_pll_pms_table_CA15[new_index] &
EXYNOS5430_PLL_PDIV_MASK) >> EXYNOS5430_PLL_PDIV_SHIFT);
__raw_writel((pdiv * 150), EXYNOS5430_EGL_PLL_LOCK);
/* 4. Change PLL PMS values */
tmp = __raw_readl(EXYNOS5430_EGL_PLL_CON0);
tmp &= ~(EXYNOS5430_PLL_MDIV_MASK |
EXYNOS5430_PLL_PDIV_MASK |
EXYNOS5430_PLL_SDIV_MASK);
tmp |= exynos5430_egl_pll_pms_table_CA15[new_index];
__raw_writel(tmp, EXYNOS5430_EGL_PLL_CON0);
/* 5. wait_lock_time */
do {
cpu_relax();
tmp = __raw_readl(EXYNOS5430_EGL_PLL_CON0);
} while (!(tmp & (0x1 << EXYNOS5430_EGL_PLL_CON0_LOCKED_SHIFT)));
/* 6. CLKMUX_SEL_EGL = MOUT_EGL_PLL */
if (clk_set_parent(mout_egl, mout_egl_pll))
pr_err("Unable to set parent %s of clock %s.\n",
mout_egl_pll->name, mout_egl->name);
do {
cpu_relax();
tmp = __raw_readl(EXYNOS5430_SRC_STAT_EGL2);
tmp &= EXYNOS5430_SRC_STAT_EGL2_EGL_MASK;
tmp >>= EXYNOS5430_SRC_STAT_EGL2_EGL_SHIFT;
} while (tmp != 0x1);
/* 7. restore original div value */
if ((new_index < L17) && (old_index < L17))
exynos5430_set_clkdiv_CA15(new_index);
}
static bool exynos5430_pms_change_CA15(unsigned int old_index,
unsigned int new_index)
{
unsigned int old_pm = (exynos5430_egl_pll_pms_table_CA15[old_index] >>
EXYNOS5430_PLL_PDIV_SHIFT);
unsigned int new_pm = (exynos5430_egl_pll_pms_table_CA15[new_index] >>
EXYNOS5430_PLL_PDIV_SHIFT);
return (old_pm == new_pm) ? 0 : 1;
}
static void exynos5430_set_frequency_CA15(unsigned int old_index,
unsigned int new_index)
{
unsigned int tmp;
if (old_index > new_index) {
if (!exynos5430_pms_change_CA15(old_index, new_index)) {
/* 1. Change the system clock divider values */
exynos5430_set_clkdiv_CA15(new_index);
/* 2. Change just s value in egl_pll m,p,s value */
tmp = __raw_readl(EXYNOS5430_EGL_PLL_CON0);
tmp &= ~EXYNOS5430_PLL_SDIV_MASK;
tmp |= (exynos5430_egl_pll_pms_table_CA15[new_index] & EXYNOS5430_PLL_SDIV_MASK);
__raw_writel(tmp, EXYNOS5430_EGL_PLL_CON0);
} else {
/* Clock Configuration Procedure */
/* 1. Change the system clock divider values */
exynos5430_set_clkdiv_CA15(new_index);
/* 2. Change the egl_pll m,p,s value */
exynos5430_set_egl_pll_CA15(new_index, old_index);
}
} else if (old_index < new_index) {
if (!exynos5430_pms_change_CA15(old_index, new_index)) {
/* 1. Change just s value in egl_pll m,p,s value */
tmp = __raw_readl(EXYNOS5430_EGL_PLL_CON0);
tmp &= ~EXYNOS5430_PLL_SDIV_MASK;
tmp |= (exynos5430_egl_pll_pms_table_CA15[new_index] & EXYNOS5430_PLL_SDIV_MASK);
__raw_writel(tmp, EXYNOS5430_EGL_PLL_CON0);
/* 2. Change the system clock divider values */
exynos5430_set_clkdiv_CA15(new_index);
} else {
/* Clock Configuration Procedure */
/* 1. Change the egl_pll m,p,s value */
exynos5430_set_egl_pll_CA15(new_index, old_index);
/* 2. Change the system clock divider values */
exynos5430_set_clkdiv_CA15(new_index);
}
}
clk_set_rate(fout_egl_pll, exynos5430_freq_table_CA15[new_index].frequency * 1000);
}
static void __init set_volt_table_CA15(void)
{
unsigned int i;
unsigned int asv_volt = 0;
for (i = 0; i < CPUFREQ_LEVEL_END_CA15; i++) {
asv_volt = get_match_volt(ID_ARM, exynos5430_freq_table_CA15[i].frequency);
if (!asv_volt)
exynos5430_volt_table_CA15[i] = asv_voltage_5430_CA15[i];
else
exynos5430_volt_table_CA15[i] = asv_volt;
pr_info("CPUFREQ of CA15 L%d : %d uV\n", i,
exynos5430_volt_table_CA15[i]);
exynos5430_abb_table_CA15[i] =
get_match_abb(ID_ARM, exynos5430_freq_table_CA15[i].frequency);
pr_info("CPUFREQ of CA15 L%d : ABB %d\n", i,
exynos5430_abb_table_CA15[i]);
}
exynos5430_get_egl_speed_option(&spd_option_flag, &spd_sel);
if (spd_option_flag == EGL_DISABLE_SPD_OPTION) {
max_support_idx_CA15 = L13; /* 1.2 GHz */
} else {
if (spd_sel == EGL_SPD_SEL_1500_MHZ)
max_support_idx_CA15 = L10; /* 1.5 GHz */
#if defined(CONFIG_SOC_EXYNOS5430_L)
else if (spd_sel == EGL_SPD_SEL_1700_MHZ)
max_support_idx_CA15 = L8; /* 1.7 GHz */
else if (spd_sel == EGL_SPD_SEL_1900_MHZ ||
spd_sel == EGL_SPD_SEL_2000_MHZ ||
spd_sel == EGL_SPD_SEL_2100_MHZ)
max_support_idx_CA15 = L7; /* 1.8 GHz */
#else
else if (spd_sel == EGL_SPD_SEL_1700_MHZ)
max_support_idx_CA15 = L8; /* 1.7 GHz */
else if (spd_sel == EGL_SPD_SEL_1900_MHZ)
max_support_idx_CA15 = L6; /* 1.9 GHz */
else if (spd_sel == EGL_SPD_SEL_2000_MHZ)
max_support_idx_CA15 = L5; /* 2.0 GHz */
else if (spd_sel == EGL_SPD_SEL_2100_MHZ)
max_support_idx_CA15 = L5; /* 2.0 GHz */
#endif
else
panic("can not support speed select (0x%x)\n", spd_sel);
}
min_support_idx_CA15 = L17; /* 800 MHz */
pr_info("CPUFREQ of CA15 max_freq : L%d %u khz\n", max_support_idx_CA15,
exynos5430_freq_table_CA15[max_support_idx_CA15].frequency);
pr_info("CPUFREQ of CA15 min_freq : L%d %u khz\n", min_support_idx_CA15,
exynos5430_freq_table_CA15[min_support_idx_CA15].frequency);
}
static bool exynos5430_is_alive_CA15(void)
{
unsigned int tmp;
tmp = __raw_readl(EXYNOS5430_EGL_PLL_CON1);
tmp &= EXYNOS5430_PLL_BYPASS_MASK;
tmp >>= EXYNOS5430_PLL_BYPASS_SHIFT;
return !tmp ? true : false;
}
int __init exynos5_cpufreq_CA15_init(struct exynos_dvfs_info *info)
{
int i;
unsigned int tmp;
unsigned long rate;
set_volt_table_CA15();
mout_egl = __clk_lookup("mout_egl");
if (!mout_egl) {
pr_err("failed get mout_egl clk\n");
return -EINVAL;
}
mout_egl_pll = __clk_lookup("mout_egl_pll");
if (!mout_egl_pll) {
pr_err("failed get mout_egl_pll clk\n");
goto err_mout_egl_pll;
}
if (clk_set_parent(mout_egl, mout_egl_pll)) {
pr_err("Unable to set parent %s of clock %s.\n",
mout_egl_pll->name, mout_egl->name);
goto err_clk_set_parent_egl;
}
sclk_bus_pll = __clk_lookup("sclk_bus_pll");
if (!sclk_bus_pll) {
pr_err("failed get sclk_bus_pll clk\n");
goto err_sclk_bus_pll;
}
mout_bus_pll_user = __clk_lookup("mout_bus_pll_egl_user");
if (!mout_bus_pll_user) {
pr_err("failed get mout_bus_pll_egl_user clk\n");
goto err_mout_bus_pll_user;
}
if (clk_set_parent(mout_bus_pll_user, sclk_bus_pll)) {
pr_err("Unable to set parent %s of clock %s.\n",
sclk_bus_pll->name, mout_bus_pll_user->name);
goto err_clk_set_parent_bus_pll;
}
rate = clk_get_rate(mout_bus_pll_user) / 1000;
fout_egl_pll = __clk_lookup("fout_egl_pll");
if (!fout_egl_pll) {
pr_err("failed get fout_egl_pll clk\n");
goto err_fout_egl_pll;
}
clk_put(sclk_bus_pll);
for (i = L0; i < CPUFREQ_LEVEL_END_CA15; i++) {
exynos5430_clkdiv_table_CA15[i].index = i;
/* CLK_DIV_EGL0 */
tmp = __raw_readl(EXYNOS5430_DIV_EGL0);
tmp &= ~(EXYNOS5430_DIV_EGL0_EGL1_MASK |
EXYNOS5430_DIV_EGL0_EGL2_MASK |
EXYNOS5430_DIV_EGL0_ACLK_EGL_MASK |
EXYNOS5430_DIV_EGL0_PCLK_EGL_MASK |
EXYNOS5430_DIV_EGL0_ATCLK_EGL_MASK |
EXYNOS5430_DIV_EGL0_PCLK_DBG_EGL_MASK);
tmp |= ((clkdiv_cpu0_5430_CA15[i][0] << EXYNOS5430_DIV_EGL0_EGL1_SHIFT) |
(clkdiv_cpu0_5430_CA15[i][1] << EXYNOS5430_DIV_EGL0_EGL2_SHIFT) |
(clkdiv_cpu0_5430_CA15[i][2] << EXYNOS5430_DIV_EGL0_ACLK_EGL_SHIFT) |
(clkdiv_cpu0_5430_CA15[i][3] << EXYNOS5430_DIV_EGL0_PCLK_EGL_SHIFT) |
(clkdiv_cpu0_5430_CA15[i][4] << EXYNOS5430_DIV_EGL0_ATCLK_EGL_SHIFT) |
(clkdiv_cpu0_5430_CA15[i][5] << EXYNOS5430_DIV_EGL0_PCLK_DBG_EGL_SHIFT));
exynos5430_clkdiv_table_CA15[i].clkdiv0 = tmp;
/* CLK_DIV_EGL1 */
tmp = __raw_readl(EXYNOS5430_DIV_EGL1);
tmp &= ~(EXYNOS5430_DIV_EGL1_EGL_PLL_MASK |
EXYNOS5430_DIV_EGL1_SCLK_HPM_EGL_MASK);
tmp |= ((clkdiv_cpu1_5430_CA15[i][0] << EXYNOS5430_DIV_EGL1_EGL_PLL_SHIFT) |
(clkdiv_cpu1_5430_CA15[i][1] << EXYNOS5430_DIV_EGL1_SCLK_HPM_EGL_SHIFT));
exynos5430_clkdiv_table_CA15[i].clkdiv1 = tmp;
}
/* Save EMA control values */
tmp = __raw_readl(EMA_VAL_REG);
egl_ema_con1 = (tmp >> EMA_CON1_SHIFT) & EMA_CON_MASK;
egl_ema_con2 = (tmp >> EMA_CON2_SHIFT) & EMA_CON_MASK;
egl_ema_con1 = exynos5430_ema_valid_check_CA15(egl_ema_con1);
egl_ema_con2 = exynos5430_ema_valid_check_CA15(egl_ema_con2);
pr_info("%s: ema_con1[%d], ema_con2[%d]\n", __func__, egl_ema_con1, egl_ema_con2);
clk_egl_2_base = ioremap(EXYNOS5430_PA_CMU_EGL2, SZ_4K);
if (!clk_egl_2_base) {
pr_err("failed to ioremap for EMA\n");
goto err_ioremap;
}
info->mpll_freq_khz = rate;
info->pll_safe_idx = L17;
info->max_support_idx = max_support_idx_CA15;
info->min_support_idx = min_support_idx_CA15;
if (spd_option_flag == EGL_DISABLE_SPD_OPTION) {
/* booting frequency is 800MHz */
info->boot_cpu_min_qos = exynos5430_freq_table_CA15[L17].frequency;
info->boot_cpu_max_qos = exynos5430_freq_table_CA15[L17].frequency;
} else {
/* booting frequency is 1.2GHz */
info->boot_cpu_min_qos = exynos5430_freq_table_CA15[L13].frequency;
info->boot_cpu_max_qos = exynos5430_freq_table_CA15[L13].frequency;
}
info->bus_table = exynos5430_bus_table_CA15;
info->cpu_clk = fout_egl_pll;
info->volt_table = exynos5430_volt_table_CA15;
info->abb_table = exynos5430_abb_table_CA15;
info->freq_table = exynos5430_freq_table_CA15;
info->set_freq = exynos5430_set_frequency_CA15;
info->set_ema = exynos5430_set_ema_CA15;
info->need_apll_change = exynos5430_pms_change_CA15;
info->is_alive = exynos5430_is_alive_CA15;
#ifdef ENABLE_CLKOUT
/* dividing EGL_CLK to 1/16 */
tmp = __raw_readl(EXYNOS5430_CLKOUT_CMU_EGL);
tmp &= ~0xfff;
tmp |= 0xf02;
__raw_writel(tmp, EXYNOS5430_CLKOUT_CMU_EGL);
#endif
__raw_writel(0x00, EXYNOS5430_EGL_STOPCTRL);
return 0;
err_ioremap:
clk_put(fout_egl_pll);
err_fout_egl_pll:
err_clk_set_parent_bus_pll:
clk_put(mout_bus_pll_user);
err_mout_bus_pll_user:
clk_put(sclk_bus_pll);
err_sclk_bus_pll:
err_clk_set_parent_egl:
clk_put(mout_egl_pll);
err_mout_egl_pll:
clk_put(mout_egl);
pr_debug("%s: failed initialization\n", __func__);
return -EINVAL;
}
|