1 /* drivers/devfreq/exynos4210_memorybus.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 * MyungJoo Ham <myungjoo.ham@samsung.com>
7 * EXYNOS4 - Memory/Bus clock frequency scaling support in DEVFREQ framework
8 * This version supports EXYNOS4210 only. This changes bus frequencies
9 * and vddint voltages. Exynos4412/4212 should be able to be supported
10 * with minor modifications.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
19 #include <linux/slab.h>
20 #include <linux/mutex.h>
21 #include <linux/suspend.h>
22 #include <linux/pm_opp.h>
23 #include <linux/devfreq.h>
24 #include <linux/platform_device.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/module.h>
30 #include "exynos_ppmu.h"
31 #include "exynos4_bus.h"
33 #define MAX_SAFEVOLT 1200000 /* 1.2V */
35 enum exynos4_busf_type
{
40 /* Assume that the bus is saturated if the utilization is 40% */
41 #define BUS_SATURATION_RATIO 40
43 enum busclk_level_idx
{
52 enum exynos_ppmu_idx
{
58 #define EX4210_LV_MAX LV_2
59 #define EX4x12_LV_MAX LV_4
60 #define EX4210_LV_NUM (LV_2 + 1)
61 #define EX4x12_LV_NUM (LV_4 + 1)
64 * struct busfreq_opp_info - opp information for bus
65 * @rate: Frequency in hertz
66 * @volt: Voltage in microvolts corresponding to this OPP
68 struct busfreq_opp_info
{
74 enum exynos4_busf_type type
;
76 struct devfreq
*devfreq
;
78 struct regulator
*vdd_int
;
79 struct regulator
*vdd_mif
; /* Exynos4412/4212 only */
80 struct busfreq_opp_info curr_oppinfo
;
81 struct busfreq_ppmu_data ppmu_data
;
83 struct notifier_block pm_notifier
;
86 /* Dividers calculated at boot/probe-time */
87 unsigned int dmc_divtable
[_LV_END
]; /* DMC0 */
88 unsigned int top_divtable
[_LV_END
];
91 /* 4210 controls clock of mif and voltage of int */
92 static struct bus_opp_table exynos4210_busclk_table
[] = {
93 {LV_0
, 400000, 1150000},
94 {LV_1
, 267000, 1050000},
95 {LV_2
, 133000, 1025000},
100 * MIF is the main control knob clock for Exynos4x12 MIF/INT
101 * clock and voltage of both mif/int are controlled.
103 static struct bus_opp_table exynos4x12_mifclk_table
[] = {
104 {LV_0
, 400000, 1100000},
105 {LV_1
, 267000, 1000000},
106 {LV_2
, 160000, 950000},
107 {LV_3
, 133000, 950000},
108 {LV_4
, 100000, 950000},
113 * INT is not the control knob of 4x12. LV_x is not meant to represent
114 * the current performance. (MIF does)
116 static struct bus_opp_table exynos4x12_intclk_table
[] = {
117 {LV_0
, 200000, 1000000},
118 {LV_1
, 160000, 950000},
119 {LV_2
, 133000, 925000},
120 {LV_3
, 100000, 900000},
124 /* TODO: asv volt definitions are "__initdata"? */
125 /* Some chips have different operating voltages */
126 static unsigned int exynos4210_asv_volt
[][EX4210_LV_NUM
] = {
127 {1150000, 1050000, 1050000},
128 {1125000, 1025000, 1025000},
129 {1100000, 1000000, 1000000},
130 {1075000, 975000, 975000},
131 {1050000, 950000, 950000},
134 static unsigned int exynos4x12_mif_step_50
[][EX4x12_LV_NUM
] = {
135 /* 400 267 160 133 100 */
136 {1050000, 950000, 900000, 900000, 900000}, /* ASV0 */
137 {1050000, 950000, 900000, 900000, 900000}, /* ASV1 */
138 {1050000, 950000, 900000, 900000, 900000}, /* ASV2 */
139 {1050000, 900000, 900000, 900000, 900000}, /* ASV3 */
140 {1050000, 900000, 900000, 900000, 850000}, /* ASV4 */
141 {1050000, 900000, 900000, 850000, 850000}, /* ASV5 */
142 {1050000, 900000, 850000, 850000, 850000}, /* ASV6 */
143 {1050000, 900000, 850000, 850000, 850000}, /* ASV7 */
144 {1050000, 900000, 850000, 850000, 850000}, /* ASV8 */
147 static unsigned int exynos4x12_int_volt
[][EX4x12_LV_NUM
] = {
148 /* 200 160 133 100 */
149 {1000000, 950000, 925000, 900000}, /* ASV0 */
150 {975000, 925000, 925000, 900000}, /* ASV1 */
151 {950000, 925000, 900000, 875000}, /* ASV2 */
152 {950000, 900000, 900000, 875000}, /* ASV3 */
153 {925000, 875000, 875000, 875000}, /* ASV4 */
154 {900000, 850000, 850000, 850000}, /* ASV5 */
155 {900000, 850000, 850000, 850000}, /* ASV6 */
156 {900000, 850000, 850000, 850000}, /* ASV7 */
157 {900000, 850000, 850000, 850000}, /* ASV8 */
160 /*** Clock Divider Data for Exynos4210 ***/
161 static unsigned int exynos4210_clkdiv_dmc0
[][8] = {
163 * Clock divider value for following
164 * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD
165 * DIVDMCP, DIVCOPY2, DIVCORE_TIMERS }
169 { 3, 1, 1, 1, 1, 1, 3, 1 },
170 /* DMC L1: 266.7MHz */
171 { 4, 1, 1, 2, 1, 1, 3, 1 },
173 { 5, 1, 1, 5, 1, 1, 3, 1 },
175 static unsigned int exynos4210_clkdiv_top
[][5] = {
177 * Clock divider value for following
178 * { DIVACLK200, DIVACLK100, DIVACLK160, DIVACLK133, DIVONENAND }
180 /* ACLK200 L0: 200MHz */
182 /* ACLK200 L1: 160MHz */
184 /* ACLK200 L2: 133MHz */
187 static unsigned int exynos4210_clkdiv_lr_bus
[][2] = {
189 * Clock divider value for following
190 * { DIVGDL/R, DIVGPL/R }
192 /* ACLK_GDL/R L1: 200MHz */
194 /* ACLK_GDL/R L2: 160MHz */
196 /* ACLK_GDL/R L3: 133MHz */
200 /*** Clock Divider Data for Exynos4212/4412 ***/
201 static unsigned int exynos4x12_clkdiv_dmc0
[][6] = {
203 * Clock divider value for following
204 * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD
210 /* DMC L1: 266.7MHz */
219 static unsigned int exynos4x12_clkdiv_dmc1
[][6] = {
221 * Clock divider value for following
222 * { G2DACP, DIVC2C, DIVC2C_ACLK }
227 /* DMC L1: 266.7MHz */
236 static unsigned int exynos4x12_clkdiv_top
[][5] = {
238 * Clock divider value for following
239 * { DIVACLK266_GPS, DIVACLK100, DIVACLK160,
240 DIVACLK133, DIVONENAND }
243 /* ACLK_GDL/R L0: 200MHz */
245 /* ACLK_GDL/R L1: 200MHz */
247 /* ACLK_GDL/R L2: 160MHz */
249 /* ACLK_GDL/R L3: 133MHz */
251 /* ACLK_GDL/R L4: 100MHz */
254 static unsigned int exynos4x12_clkdiv_lr_bus
[][2] = {
256 * Clock divider value for following
257 * { DIVGDL/R, DIVGPL/R }
260 /* ACLK_GDL/R L0: 200MHz */
262 /* ACLK_GDL/R L1: 200MHz */
264 /* ACLK_GDL/R L2: 160MHz */
266 /* ACLK_GDL/R L3: 133MHz */
268 /* ACLK_GDL/R L4: 100MHz */
271 static unsigned int exynos4x12_clkdiv_sclkip
[][3] = {
273 * Clock divider value for following
274 * { DIVMFC, DIVJPEG, DIVFIMC0~3}
277 /* SCLK_MFC: 200MHz */
279 /* SCLK_MFC: 200MHz */
281 /* SCLK_MFC: 160MHz */
283 /* SCLK_MFC: 133MHz */
285 /* SCLK_MFC: 100MHz */
290 static int exynos4210_set_busclk(struct busfreq_data
*data
,
291 struct busfreq_opp_info
*oppi
)
296 for (index
= LV_0
; index
< EX4210_LV_NUM
; index
++)
297 if (oppi
->rate
== exynos4210_busclk_table
[index
].clk
)
300 if (index
== EX4210_LV_NUM
)
303 /* Change Divider - DMC0 */
304 tmp
= data
->dmc_divtable
[index
];
306 __raw_writel(tmp
, EXYNOS4_CLKDIV_DMC0
);
309 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0
);
310 } while (tmp
& 0x11111111);
312 /* Change Divider - TOP */
313 tmp
= data
->top_divtable
[index
];
315 __raw_writel(tmp
, EXYNOS4_CLKDIV_TOP
);
318 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_TOP
);
319 } while (tmp
& 0x11111);
321 /* Change Divider - LEFTBUS */
322 tmp
= __raw_readl(EXYNOS4_CLKDIV_LEFTBUS
);
324 tmp
&= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK
| EXYNOS4_CLKDIV_BUS_GPLR_MASK
);
326 tmp
|= ((exynos4210_clkdiv_lr_bus
[index
][0] <<
327 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT
) |
328 (exynos4210_clkdiv_lr_bus
[index
][1] <<
329 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT
));
331 __raw_writel(tmp
, EXYNOS4_CLKDIV_LEFTBUS
);
334 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS
);
335 } while (tmp
& 0x11);
337 /* Change Divider - RIGHTBUS */
338 tmp
= __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS
);
340 tmp
&= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK
| EXYNOS4_CLKDIV_BUS_GPLR_MASK
);
342 tmp
|= ((exynos4210_clkdiv_lr_bus
[index
][0] <<
343 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT
) |
344 (exynos4210_clkdiv_lr_bus
[index
][1] <<
345 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT
));
347 __raw_writel(tmp
, EXYNOS4_CLKDIV_RIGHTBUS
);
350 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS
);
351 } while (tmp
& 0x11);
356 static int exynos4x12_set_busclk(struct busfreq_data
*data
,
357 struct busfreq_opp_info
*oppi
)
362 for (index
= LV_0
; index
< EX4x12_LV_NUM
; index
++)
363 if (oppi
->rate
== exynos4x12_mifclk_table
[index
].clk
)
366 if (index
== EX4x12_LV_NUM
)
369 /* Change Divider - DMC0 */
370 tmp
= data
->dmc_divtable
[index
];
372 __raw_writel(tmp
, EXYNOS4_CLKDIV_DMC0
);
375 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0
);
376 } while (tmp
& 0x11111111);
378 /* Change Divider - DMC1 */
379 tmp
= __raw_readl(EXYNOS4_CLKDIV_DMC1
);
381 tmp
&= ~(EXYNOS4_CLKDIV_DMC1_G2D_ACP_MASK
|
382 EXYNOS4_CLKDIV_DMC1_C2C_MASK
|
383 EXYNOS4_CLKDIV_DMC1_C2CACLK_MASK
);
385 tmp
|= ((exynos4x12_clkdiv_dmc1
[index
][0] <<
386 EXYNOS4_CLKDIV_DMC1_G2D_ACP_SHIFT
) |
387 (exynos4x12_clkdiv_dmc1
[index
][1] <<
388 EXYNOS4_CLKDIV_DMC1_C2C_SHIFT
) |
389 (exynos4x12_clkdiv_dmc1
[index
][2] <<
390 EXYNOS4_CLKDIV_DMC1_C2CACLK_SHIFT
));
392 __raw_writel(tmp
, EXYNOS4_CLKDIV_DMC1
);
395 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_DMC1
);
396 } while (tmp
& 0x111111);
398 /* Change Divider - TOP */
399 tmp
= __raw_readl(EXYNOS4_CLKDIV_TOP
);
401 tmp
&= ~(EXYNOS4_CLKDIV_TOP_ACLK266_GPS_MASK
|
402 EXYNOS4_CLKDIV_TOP_ACLK100_MASK
|
403 EXYNOS4_CLKDIV_TOP_ACLK160_MASK
|
404 EXYNOS4_CLKDIV_TOP_ACLK133_MASK
|
405 EXYNOS4_CLKDIV_TOP_ONENAND_MASK
);
407 tmp
|= ((exynos4x12_clkdiv_top
[index
][0] <<
408 EXYNOS4_CLKDIV_TOP_ACLK266_GPS_SHIFT
) |
409 (exynos4x12_clkdiv_top
[index
][1] <<
410 EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT
) |
411 (exynos4x12_clkdiv_top
[index
][2] <<
412 EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT
) |
413 (exynos4x12_clkdiv_top
[index
][3] <<
414 EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT
) |
415 (exynos4x12_clkdiv_top
[index
][4] <<
416 EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT
));
418 __raw_writel(tmp
, EXYNOS4_CLKDIV_TOP
);
421 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_TOP
);
422 } while (tmp
& 0x11111);
424 /* Change Divider - LEFTBUS */
425 tmp
= __raw_readl(EXYNOS4_CLKDIV_LEFTBUS
);
427 tmp
&= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK
| EXYNOS4_CLKDIV_BUS_GPLR_MASK
);
429 tmp
|= ((exynos4x12_clkdiv_lr_bus
[index
][0] <<
430 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT
) |
431 (exynos4x12_clkdiv_lr_bus
[index
][1] <<
432 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT
));
434 __raw_writel(tmp
, EXYNOS4_CLKDIV_LEFTBUS
);
437 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS
);
438 } while (tmp
& 0x11);
440 /* Change Divider - RIGHTBUS */
441 tmp
= __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS
);
443 tmp
&= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK
| EXYNOS4_CLKDIV_BUS_GPLR_MASK
);
445 tmp
|= ((exynos4x12_clkdiv_lr_bus
[index
][0] <<
446 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT
) |
447 (exynos4x12_clkdiv_lr_bus
[index
][1] <<
448 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT
));
450 __raw_writel(tmp
, EXYNOS4_CLKDIV_RIGHTBUS
);
453 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS
);
454 } while (tmp
& 0x11);
456 /* Change Divider - MFC */
457 tmp
= __raw_readl(EXYNOS4_CLKDIV_MFC
);
459 tmp
&= ~(EXYNOS4_CLKDIV_MFC_MASK
);
461 tmp
|= ((exynos4x12_clkdiv_sclkip
[index
][0] <<
462 EXYNOS4_CLKDIV_MFC_SHIFT
));
464 __raw_writel(tmp
, EXYNOS4_CLKDIV_MFC
);
467 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_MFC
);
470 /* Change Divider - JPEG */
471 tmp
= __raw_readl(EXYNOS4_CLKDIV_CAM1
);
473 tmp
&= ~(EXYNOS4_CLKDIV_CAM1_JPEG_MASK
);
475 tmp
|= ((exynos4x12_clkdiv_sclkip
[index
][1] <<
476 EXYNOS4_CLKDIV_CAM1_JPEG_SHIFT
));
478 __raw_writel(tmp
, EXYNOS4_CLKDIV_CAM1
);
481 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1
);
484 /* Change Divider - FIMC0~3 */
485 tmp
= __raw_readl(EXYNOS4_CLKDIV_CAM
);
487 tmp
&= ~(EXYNOS4_CLKDIV_CAM_FIMC0_MASK
| EXYNOS4_CLKDIV_CAM_FIMC1_MASK
|
488 EXYNOS4_CLKDIV_CAM_FIMC2_MASK
| EXYNOS4_CLKDIV_CAM_FIMC3_MASK
);
490 tmp
|= ((exynos4x12_clkdiv_sclkip
[index
][2] <<
491 EXYNOS4_CLKDIV_CAM_FIMC0_SHIFT
) |
492 (exynos4x12_clkdiv_sclkip
[index
][2] <<
493 EXYNOS4_CLKDIV_CAM_FIMC1_SHIFT
) |
494 (exynos4x12_clkdiv_sclkip
[index
][2] <<
495 EXYNOS4_CLKDIV_CAM_FIMC2_SHIFT
) |
496 (exynos4x12_clkdiv_sclkip
[index
][2] <<
497 EXYNOS4_CLKDIV_CAM_FIMC3_SHIFT
));
499 __raw_writel(tmp
, EXYNOS4_CLKDIV_CAM
);
502 tmp
= __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1
);
503 } while (tmp
& 0x1111);
508 static int exynos4x12_get_intspec(unsigned long mifclk
)
512 while (exynos4x12_intclk_table
[i
].clk
) {
513 if (exynos4x12_intclk_table
[i
].clk
<= mifclk
)
521 static int exynos4_bus_setvolt(struct busfreq_data
*data
,
522 struct busfreq_opp_info
*oppi
,
523 struct busfreq_opp_info
*oldoppi
)
526 unsigned long volt
= oppi
->volt
;
528 switch (data
->type
) {
529 case TYPE_BUSF_EXYNOS4210
:
530 /* OPP represents DMC clock + INT voltage */
531 err
= regulator_set_voltage(data
->vdd_int
, volt
,
534 case TYPE_BUSF_EXYNOS4x12
:
535 /* OPP represents MIF clock + MIF voltage */
536 err
= regulator_set_voltage(data
->vdd_mif
, volt
,
541 tmp
= exynos4x12_get_intspec(oppi
->rate
);
544 regulator_set_voltage(data
->vdd_mif
,
549 err
= regulator_set_voltage(data
->vdd_int
,
550 exynos4x12_intclk_table
[tmp
].volt
,
554 regulator_set_voltage(data
->vdd_mif
,
565 static int exynos4_bus_target(struct device
*dev
, unsigned long *_freq
,
569 struct platform_device
*pdev
= container_of(dev
, struct platform_device
,
571 struct busfreq_data
*data
= platform_get_drvdata(pdev
);
572 struct dev_pm_opp
*opp
;
574 unsigned long old_freq
= data
->curr_oppinfo
.rate
;
575 struct busfreq_opp_info new_oppinfo
;
578 opp
= devfreq_recommended_opp(dev
, _freq
, flags
);
583 new_oppinfo
.rate
= dev_pm_opp_get_freq(opp
);
584 new_oppinfo
.volt
= dev_pm_opp_get_voltage(opp
);
586 freq
= new_oppinfo
.rate
;
588 if (old_freq
== freq
)
591 dev_dbg(dev
, "targeting %lukHz %luuV\n", freq
, new_oppinfo
.volt
);
593 mutex_lock(&data
->lock
);
599 err
= exynos4_bus_setvolt(data
, &new_oppinfo
,
600 &data
->curr_oppinfo
);
604 if (old_freq
!= freq
) {
605 switch (data
->type
) {
606 case TYPE_BUSF_EXYNOS4210
:
607 err
= exynos4210_set_busclk(data
, &new_oppinfo
);
609 case TYPE_BUSF_EXYNOS4x12
:
610 err
= exynos4x12_set_busclk(data
, &new_oppinfo
);
620 err
= exynos4_bus_setvolt(data
, &new_oppinfo
,
621 &data
->curr_oppinfo
);
625 data
->curr_oppinfo
= new_oppinfo
;
627 mutex_unlock(&data
->lock
);
631 static int exynos4_bus_get_dev_status(struct device
*dev
,
632 struct devfreq_dev_status
*stat
)
634 struct busfreq_data
*data
= dev_get_drvdata(dev
);
635 struct busfreq_ppmu_data
*ppmu_data
= &data
->ppmu_data
;
638 exynos_read_ppmu(ppmu_data
);
639 busier
= exynos_get_busier_ppmu(ppmu_data
);
640 stat
->current_frequency
= data
->curr_oppinfo
.rate
;
642 /* Number of cycles spent on memory access */
643 stat
->busy_time
= ppmu_data
->ppmu
[busier
].count
[PPMU_PMNCNT3
];
644 stat
->busy_time
*= 100 / BUS_SATURATION_RATIO
;
645 stat
->total_time
= ppmu_data
->ppmu
[busier
].ccnt
;
647 /* If the counters have overflown, retry */
648 if (ppmu_data
->ppmu
[busier
].ccnt_overflow
||
649 ppmu_data
->ppmu
[busier
].count_overflow
[0])
655 static struct devfreq_dev_profile exynos4_devfreq_profile
= {
656 .initial_freq
= 400000,
658 .target
= exynos4_bus_target
,
659 .get_dev_status
= exynos4_bus_get_dev_status
,
662 static int exynos4210_init_tables(struct busfreq_data
*data
)
668 tmp
= __raw_readl(EXYNOS4_CLKDIV_DMC0
);
669 for (i
= LV_0
; i
< EX4210_LV_NUM
; i
++) {
670 tmp
&= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK
|
671 EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK
|
672 EXYNOS4_CLKDIV_DMC0_DPHY_MASK
|
673 EXYNOS4_CLKDIV_DMC0_DMC_MASK
|
674 EXYNOS4_CLKDIV_DMC0_DMCD_MASK
|
675 EXYNOS4_CLKDIV_DMC0_DMCP_MASK
|
676 EXYNOS4_CLKDIV_DMC0_COPY2_MASK
|
677 EXYNOS4_CLKDIV_DMC0_CORETI_MASK
);
679 tmp
|= ((exynos4210_clkdiv_dmc0
[i
][0] <<
680 EXYNOS4_CLKDIV_DMC0_ACP_SHIFT
) |
681 (exynos4210_clkdiv_dmc0
[i
][1] <<
682 EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT
) |
683 (exynos4210_clkdiv_dmc0
[i
][2] <<
684 EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT
) |
685 (exynos4210_clkdiv_dmc0
[i
][3] <<
686 EXYNOS4_CLKDIV_DMC0_DMC_SHIFT
) |
687 (exynos4210_clkdiv_dmc0
[i
][4] <<
688 EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT
) |
689 (exynos4210_clkdiv_dmc0
[i
][5] <<
690 EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT
) |
691 (exynos4210_clkdiv_dmc0
[i
][6] <<
692 EXYNOS4_CLKDIV_DMC0_COPY2_SHIFT
) |
693 (exynos4210_clkdiv_dmc0
[i
][7] <<
694 EXYNOS4_CLKDIV_DMC0_CORETI_SHIFT
));
696 data
->dmc_divtable
[i
] = tmp
;
699 tmp
= __raw_readl(EXYNOS4_CLKDIV_TOP
);
700 for (i
= LV_0
; i
< EX4210_LV_NUM
; i
++) {
701 tmp
&= ~(EXYNOS4_CLKDIV_TOP_ACLK200_MASK
|
702 EXYNOS4_CLKDIV_TOP_ACLK100_MASK
|
703 EXYNOS4_CLKDIV_TOP_ACLK160_MASK
|
704 EXYNOS4_CLKDIV_TOP_ACLK133_MASK
|
705 EXYNOS4_CLKDIV_TOP_ONENAND_MASK
);
707 tmp
|= ((exynos4210_clkdiv_top
[i
][0] <<
708 EXYNOS4_CLKDIV_TOP_ACLK200_SHIFT
) |
709 (exynos4210_clkdiv_top
[i
][1] <<
710 EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT
) |
711 (exynos4210_clkdiv_top
[i
][2] <<
712 EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT
) |
713 (exynos4210_clkdiv_top
[i
][3] <<
714 EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT
) |
715 (exynos4210_clkdiv_top
[i
][4] <<
716 EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT
));
718 data
->top_divtable
[i
] = tmp
;
722 * TODO: init tmp based on busfreq_data
723 * (device-tree or platform-data)
725 tmp
= 0; /* Max voltages for the reliability of the unknown */
727 pr_debug("ASV Group of Exynos4 is %d\n", tmp
);
728 /* Use merged grouping for voltage */
749 pr_warn("Unknown ASV Group. Use max voltage.\n");
753 for (i
= LV_0
; i
< EX4210_LV_NUM
; i
++)
754 exynos4210_busclk_table
[i
].volt
= exynos4210_asv_volt
[mgrp
][i
];
756 for (i
= LV_0
; i
< EX4210_LV_NUM
; i
++) {
757 err
= dev_pm_opp_add(data
->dev
, exynos4210_busclk_table
[i
].clk
,
758 exynos4210_busclk_table
[i
].volt
);
760 dev_err(data
->dev
, "Cannot add opp entries.\n");
769 static int exynos4x12_init_tables(struct busfreq_data
*data
)
775 /* Enable pause function for DREX2 DVFS */
776 tmp
= __raw_readl(EXYNOS4_DMC_PAUSE_CTRL
);
777 tmp
|= EXYNOS4_DMC_PAUSE_ENABLE
;
778 __raw_writel(tmp
, EXYNOS4_DMC_PAUSE_CTRL
);
780 tmp
= __raw_readl(EXYNOS4_CLKDIV_DMC0
);
782 for (i
= 0; i
< EX4x12_LV_NUM
; i
++) {
783 tmp
&= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK
|
784 EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK
|
785 EXYNOS4_CLKDIV_DMC0_DPHY_MASK
|
786 EXYNOS4_CLKDIV_DMC0_DMC_MASK
|
787 EXYNOS4_CLKDIV_DMC0_DMCD_MASK
|
788 EXYNOS4_CLKDIV_DMC0_DMCP_MASK
);
790 tmp
|= ((exynos4x12_clkdiv_dmc0
[i
][0] <<
791 EXYNOS4_CLKDIV_DMC0_ACP_SHIFT
) |
792 (exynos4x12_clkdiv_dmc0
[i
][1] <<
793 EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT
) |
794 (exynos4x12_clkdiv_dmc0
[i
][2] <<
795 EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT
) |
796 (exynos4x12_clkdiv_dmc0
[i
][3] <<
797 EXYNOS4_CLKDIV_DMC0_DMC_SHIFT
) |
798 (exynos4x12_clkdiv_dmc0
[i
][4] <<
799 EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT
) |
800 (exynos4x12_clkdiv_dmc0
[i
][5] <<
801 EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT
));
803 data
->dmc_divtable
[i
] = tmp
;
806 tmp
= 0; /* Max voltages for the reliability of the unknown */
810 pr_debug("ASV Group of Exynos4x12 is %d\n", tmp
);
812 for (i
= 0; i
< EX4x12_LV_NUM
; i
++) {
813 exynos4x12_mifclk_table
[i
].volt
=
814 exynos4x12_mif_step_50
[tmp
][i
];
815 exynos4x12_intclk_table
[i
].volt
=
816 exynos4x12_int_volt
[tmp
][i
];
819 for (i
= 0; i
< EX4x12_LV_NUM
; i
++) {
820 ret
= dev_pm_opp_add(data
->dev
, exynos4x12_mifclk_table
[i
].clk
,
821 exynos4x12_mifclk_table
[i
].volt
);
823 dev_err(data
->dev
, "Fail to add opp entries.\n");
831 static int exynos4_busfreq_pm_notifier_event(struct notifier_block
*this,
832 unsigned long event
, void *ptr
)
834 struct busfreq_data
*data
= container_of(this, struct busfreq_data
,
836 struct dev_pm_opp
*opp
;
837 struct busfreq_opp_info new_oppinfo
;
838 unsigned long maxfreq
= ULONG_MAX
;
842 case PM_SUSPEND_PREPARE
:
843 /* Set Fastest and Deactivate DVFS */
844 mutex_lock(&data
->lock
);
846 data
->disabled
= true;
849 opp
= dev_pm_opp_find_freq_floor(data
->dev
, &maxfreq
);
852 dev_err(data
->dev
, "%s: unable to find a min freq\n",
854 mutex_unlock(&data
->lock
);
857 new_oppinfo
.rate
= dev_pm_opp_get_freq(opp
);
858 new_oppinfo
.volt
= dev_pm_opp_get_voltage(opp
);
861 err
= exynos4_bus_setvolt(data
, &new_oppinfo
,
862 &data
->curr_oppinfo
);
866 switch (data
->type
) {
867 case TYPE_BUSF_EXYNOS4210
:
868 err
= exynos4210_set_busclk(data
, &new_oppinfo
);
870 case TYPE_BUSF_EXYNOS4x12
:
871 err
= exynos4x12_set_busclk(data
, &new_oppinfo
);
879 data
->curr_oppinfo
= new_oppinfo
;
881 mutex_unlock(&data
->lock
);
885 case PM_POST_RESTORE
:
886 case PM_POST_SUSPEND
:
888 mutex_lock(&data
->lock
);
889 data
->disabled
= false;
890 mutex_unlock(&data
->lock
);
897 static int exynos4_busfreq_probe(struct platform_device
*pdev
)
899 struct busfreq_data
*data
;
900 struct busfreq_ppmu_data
*ppmu_data
;
901 struct dev_pm_opp
*opp
;
902 struct device
*dev
= &pdev
->dev
;
905 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct busfreq_data
), GFP_KERNEL
);
907 dev_err(dev
, "Cannot allocate memory.\n");
911 ppmu_data
= &data
->ppmu_data
;
912 ppmu_data
->ppmu_end
= PPMU_END
;
913 ppmu_data
->ppmu
= devm_kzalloc(dev
,
914 sizeof(struct exynos_ppmu
) * PPMU_END
,
916 if (!ppmu_data
->ppmu
) {
917 dev_err(dev
, "Failed to allocate memory for exynos_ppmu\n");
921 data
->type
= pdev
->id_entry
->driver_data
;
922 ppmu_data
->ppmu
[PPMU_DMC0
].hw_base
= S5P_VA_DMC0
;
923 ppmu_data
->ppmu
[PPMU_DMC1
].hw_base
= S5P_VA_DMC1
;
924 data
->pm_notifier
.notifier_call
= exynos4_busfreq_pm_notifier_event
;
926 mutex_init(&data
->lock
);
928 switch (data
->type
) {
929 case TYPE_BUSF_EXYNOS4210
:
930 err
= exynos4210_init_tables(data
);
932 case TYPE_BUSF_EXYNOS4x12
:
933 err
= exynos4x12_init_tables(data
);
936 dev_err(dev
, "Cannot determine the device id %d\n", data
->type
);
940 dev_err(dev
, "Cannot initialize busfreq table %d\n",
945 data
->vdd_int
= devm_regulator_get(dev
, "vdd_int");
946 if (IS_ERR(data
->vdd_int
)) {
947 dev_err(dev
, "Cannot get the regulator \"vdd_int\"\n");
948 return PTR_ERR(data
->vdd_int
);
950 if (data
->type
== TYPE_BUSF_EXYNOS4x12
) {
951 data
->vdd_mif
= devm_regulator_get(dev
, "vdd_mif");
952 if (IS_ERR(data
->vdd_mif
)) {
953 dev_err(dev
, "Cannot get the regulator \"vdd_mif\"\n");
954 return PTR_ERR(data
->vdd_mif
);
959 opp
= dev_pm_opp_find_freq_floor(dev
,
960 &exynos4_devfreq_profile
.initial_freq
);
963 dev_err(dev
, "Invalid initial frequency %lu kHz.\n",
964 exynos4_devfreq_profile
.initial_freq
);
967 data
->curr_oppinfo
.rate
= dev_pm_opp_get_freq(opp
);
968 data
->curr_oppinfo
.volt
= dev_pm_opp_get_voltage(opp
);
971 platform_set_drvdata(pdev
, data
);
973 data
->devfreq
= devm_devfreq_add_device(dev
, &exynos4_devfreq_profile
,
974 "simple_ondemand", NULL
);
975 if (IS_ERR(data
->devfreq
))
976 return PTR_ERR(data
->devfreq
);
979 * Start PPMU (Performance Profiling Monitoring Unit) to check
980 * utilization of each IP in the Exynos4 SoC.
982 busfreq_mon_reset(ppmu_data
);
984 /* Register opp_notifier for Exynos4 busfreq */
985 err
= devm_devfreq_register_opp_notifier(dev
, data
->devfreq
);
987 dev_err(dev
, "Failed to register opp notifier\n");
991 /* Register pm_notifier for Exynos4 busfreq */
992 err
= register_pm_notifier(&data
->pm_notifier
);
994 dev_err(dev
, "Failed to setup pm notifier\n");
1001 static int exynos4_busfreq_remove(struct platform_device
*pdev
)
1003 struct busfreq_data
*data
= platform_get_drvdata(pdev
);
1005 /* Unregister all of notifier chain */
1006 unregister_pm_notifier(&data
->pm_notifier
);
1011 #ifdef CONFIG_PM_SLEEP
1012 static int exynos4_busfreq_resume(struct device
*dev
)
1014 struct busfreq_data
*data
= dev_get_drvdata(dev
);
1015 struct busfreq_ppmu_data
*ppmu_data
= &data
->ppmu_data
;
1017 busfreq_mon_reset(ppmu_data
);
1022 static SIMPLE_DEV_PM_OPS(exynos4_busfreq_pm_ops
, NULL
, exynos4_busfreq_resume
);
1024 static const struct platform_device_id exynos4_busfreq_id
[] = {
1025 { "exynos4210-busfreq", TYPE_BUSF_EXYNOS4210
},
1026 { "exynos4412-busfreq", TYPE_BUSF_EXYNOS4x12
},
1027 { "exynos4212-busfreq", TYPE_BUSF_EXYNOS4x12
},
1031 static struct platform_driver exynos4_busfreq_driver
= {
1032 .probe
= exynos4_busfreq_probe
,
1033 .remove
= exynos4_busfreq_remove
,
1034 .id_table
= exynos4_busfreq_id
,
1036 .name
= "exynos4-busfreq",
1037 .pm
= &exynos4_busfreq_pm_ops
,
1041 static int __init
exynos4_busfreq_init(void)
1043 return platform_driver_register(&exynos4_busfreq_driver
);
1045 late_initcall(exynos4_busfreq_init
);
1047 static void __exit
exynos4_busfreq_exit(void)
1049 platform_driver_unregister(&exynos4_busfreq_driver
);
1051 module_exit(exynos4_busfreq_exit
);
1053 MODULE_LICENSE("GPL");
1054 MODULE_DESCRIPTION("EXYNOS4 busfreq driver with devfreq framework");
1055 MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");