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 /* Exynos4 ASV has been in the mailing list, but not upstreamed, yet. */
34 #ifdef CONFIG_EXYNOS_ASV
35 extern unsigned int exynos_result_of_asv;
38 #define MAX_SAFEVOLT 1200000 /* 1.2V */
40 enum exynos4_busf_type {
45 /* Assume that the bus is saturated if the utilization is 40% */
46 #define BUS_SATURATION_RATIO 40
48 enum busclk_level_idx {
57 enum exynos_ppmu_idx {
63 #define EX4210_LV_MAX LV_2
64 #define EX4x12_LV_MAX LV_4
65 #define EX4210_LV_NUM (LV_2 + 1)
66 #define EX4x12_LV_NUM (LV_4 + 1)
69 * struct busfreq_opp_info - opp information for bus
70 * @rate: Frequency in hertz
71 * @volt: Voltage in microvolts corresponding to this OPP
73 struct busfreq_opp_info {
79 enum exynos4_busf_type type;
81 struct devfreq *devfreq;
83 struct regulator *vdd_int;
84 struct regulator *vdd_mif; /* Exynos4412/4212 only */
85 struct busfreq_opp_info curr_oppinfo;
86 struct exynos_ppmu ppmu[PPMU_END];
88 struct notifier_block pm_notifier;
91 /* Dividers calculated at boot/probe-time */
92 unsigned int dmc_divtable[_LV_END]; /* DMC0 */
93 unsigned int top_divtable[_LV_END];
96 /* 4210 controls clock of mif and voltage of int */
97 static struct bus_opp_table exynos4210_busclk_table[] = {
98 {LV_0, 400000, 1150000},
99 {LV_1, 267000, 1050000},
100 {LV_2, 133000, 1025000},
105 * MIF is the main control knob clock for Exynos4x12 MIF/INT
106 * clock and voltage of both mif/int are controlled.
108 static struct bus_opp_table exynos4x12_mifclk_table[] = {
109 {LV_0, 400000, 1100000},
110 {LV_1, 267000, 1000000},
111 {LV_2, 160000, 950000},
112 {LV_3, 133000, 950000},
113 {LV_4, 100000, 950000},
118 * INT is not the control knob of 4x12. LV_x is not meant to represent
119 * the current performance. (MIF does)
121 static struct bus_opp_table exynos4x12_intclk_table[] = {
122 {LV_0, 200000, 1000000},
123 {LV_1, 160000, 950000},
124 {LV_2, 133000, 925000},
125 {LV_3, 100000, 900000},
129 /* TODO: asv volt definitions are "__initdata"? */
130 /* Some chips have different operating voltages */
131 static unsigned int exynos4210_asv_volt[][EX4210_LV_NUM] = {
132 {1150000, 1050000, 1050000},
133 {1125000, 1025000, 1025000},
134 {1100000, 1000000, 1000000},
135 {1075000, 975000, 975000},
136 {1050000, 950000, 950000},
139 static unsigned int exynos4x12_mif_step_50[][EX4x12_LV_NUM] = {
140 /* 400 267 160 133 100 */
141 {1050000, 950000, 900000, 900000, 900000}, /* ASV0 */
142 {1050000, 950000, 900000, 900000, 900000}, /* ASV1 */
143 {1050000, 950000, 900000, 900000, 900000}, /* ASV2 */
144 {1050000, 900000, 900000, 900000, 900000}, /* ASV3 */
145 {1050000, 900000, 900000, 900000, 850000}, /* ASV4 */
146 {1050000, 900000, 900000, 850000, 850000}, /* ASV5 */
147 {1050000, 900000, 850000, 850000, 850000}, /* ASV6 */
148 {1050000, 900000, 850000, 850000, 850000}, /* ASV7 */
149 {1050000, 900000, 850000, 850000, 850000}, /* ASV8 */
152 static unsigned int exynos4x12_int_volt[][EX4x12_LV_NUM] = {
153 /* 200 160 133 100 */
154 {1000000, 950000, 925000, 900000}, /* ASV0 */
155 {975000, 925000, 925000, 900000}, /* ASV1 */
156 {950000, 925000, 900000, 875000}, /* ASV2 */
157 {950000, 900000, 900000, 875000}, /* ASV3 */
158 {925000, 875000, 875000, 875000}, /* ASV4 */
159 {900000, 850000, 850000, 850000}, /* ASV5 */
160 {900000, 850000, 850000, 850000}, /* ASV6 */
161 {900000, 850000, 850000, 850000}, /* ASV7 */
162 {900000, 850000, 850000, 850000}, /* ASV8 */
165 /*** Clock Divider Data for Exynos4210 ***/
166 static unsigned int exynos4210_clkdiv_dmc0[][8] = {
168 * Clock divider value for following
169 * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD
170 * DIVDMCP, DIVCOPY2, DIVCORE_TIMERS }
174 { 3, 1, 1, 1, 1, 1, 3, 1 },
175 /* DMC L1: 266.7MHz */
176 { 4, 1, 1, 2, 1, 1, 3, 1 },
178 { 5, 1, 1, 5, 1, 1, 3, 1 },
180 static unsigned int exynos4210_clkdiv_top[][5] = {
182 * Clock divider value for following
183 * { DIVACLK200, DIVACLK100, DIVACLK160, DIVACLK133, DIVONENAND }
185 /* ACLK200 L0: 200MHz */
187 /* ACLK200 L1: 160MHz */
189 /* ACLK200 L2: 133MHz */
192 static unsigned int exynos4210_clkdiv_lr_bus[][2] = {
194 * Clock divider value for following
195 * { DIVGDL/R, DIVGPL/R }
197 /* ACLK_GDL/R L1: 200MHz */
199 /* ACLK_GDL/R L2: 160MHz */
201 /* ACLK_GDL/R L3: 133MHz */
205 /*** Clock Divider Data for Exynos4212/4412 ***/
206 static unsigned int exynos4x12_clkdiv_dmc0[][6] = {
208 * Clock divider value for following
209 * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD
215 /* DMC L1: 266.7MHz */
224 static unsigned int exynos4x12_clkdiv_dmc1[][6] = {
226 * Clock divider value for following
227 * { G2DACP, DIVC2C, DIVC2C_ACLK }
232 /* DMC L1: 266.7MHz */
241 static unsigned int exynos4x12_clkdiv_top[][5] = {
243 * Clock divider value for following
244 * { DIVACLK266_GPS, DIVACLK100, DIVACLK160,
245 DIVACLK133, DIVONENAND }
248 /* ACLK_GDL/R L0: 200MHz */
250 /* ACLK_GDL/R L1: 200MHz */
252 /* ACLK_GDL/R L2: 160MHz */
254 /* ACLK_GDL/R L3: 133MHz */
256 /* ACLK_GDL/R L4: 100MHz */
259 static unsigned int exynos4x12_clkdiv_lr_bus[][2] = {
261 * Clock divider value for following
262 * { DIVGDL/R, DIVGPL/R }
265 /* ACLK_GDL/R L0: 200MHz */
267 /* ACLK_GDL/R L1: 200MHz */
269 /* ACLK_GDL/R L2: 160MHz */
271 /* ACLK_GDL/R L3: 133MHz */
273 /* ACLK_GDL/R L4: 100MHz */
276 static unsigned int exynos4x12_clkdiv_sclkip[][3] = {
278 * Clock divider value for following
279 * { DIVMFC, DIVJPEG, DIVFIMC0~3}
282 /* SCLK_MFC: 200MHz */
284 /* SCLK_MFC: 200MHz */
286 /* SCLK_MFC: 160MHz */
288 /* SCLK_MFC: 133MHz */
290 /* SCLK_MFC: 100MHz */
295 static int exynos4210_set_busclk(struct busfreq_data *data,
296 struct busfreq_opp_info *oppi)
301 for (index = LV_0; index < EX4210_LV_NUM; index++)
302 if (oppi->rate == exynos4210_busclk_table[index].clk)
305 if (index == EX4210_LV_NUM)
308 /* Change Divider - DMC0 */
309 tmp = data->dmc_divtable[index];
311 __raw_writel(tmp, EXYNOS4_CLKDIV_DMC0);
314 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0);
315 } while (tmp & 0x11111111);
317 /* Change Divider - TOP */
318 tmp = data->top_divtable[index];
320 __raw_writel(tmp, EXYNOS4_CLKDIV_TOP);
323 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_TOP);
324 } while (tmp & 0x11111);
326 /* Change Divider - LEFTBUS */
327 tmp = __raw_readl(EXYNOS4_CLKDIV_LEFTBUS);
329 tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK);
331 tmp |= ((exynos4210_clkdiv_lr_bus[index][0] <<
332 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) |
333 (exynos4210_clkdiv_lr_bus[index][1] <<
334 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT));
336 __raw_writel(tmp, EXYNOS4_CLKDIV_LEFTBUS);
339 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS);
340 } while (tmp & 0x11);
342 /* Change Divider - RIGHTBUS */
343 tmp = __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS);
345 tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK);
347 tmp |= ((exynos4210_clkdiv_lr_bus[index][0] <<
348 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) |
349 (exynos4210_clkdiv_lr_bus[index][1] <<
350 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT));
352 __raw_writel(tmp, EXYNOS4_CLKDIV_RIGHTBUS);
355 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS);
356 } while (tmp & 0x11);
361 static int exynos4x12_set_busclk(struct busfreq_data *data,
362 struct busfreq_opp_info *oppi)
367 for (index = LV_0; index < EX4x12_LV_NUM; index++)
368 if (oppi->rate == exynos4x12_mifclk_table[index].clk)
371 if (index == EX4x12_LV_NUM)
374 /* Change Divider - DMC0 */
375 tmp = data->dmc_divtable[index];
377 __raw_writel(tmp, EXYNOS4_CLKDIV_DMC0);
380 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0);
381 } while (tmp & 0x11111111);
383 /* Change Divider - DMC1 */
384 tmp = __raw_readl(EXYNOS4_CLKDIV_DMC1);
386 tmp &= ~(EXYNOS4_CLKDIV_DMC1_G2D_ACP_MASK |
387 EXYNOS4_CLKDIV_DMC1_C2C_MASK |
388 EXYNOS4_CLKDIV_DMC1_C2CACLK_MASK);
390 tmp |= ((exynos4x12_clkdiv_dmc1[index][0] <<
391 EXYNOS4_CLKDIV_DMC1_G2D_ACP_SHIFT) |
392 (exynos4x12_clkdiv_dmc1[index][1] <<
393 EXYNOS4_CLKDIV_DMC1_C2C_SHIFT) |
394 (exynos4x12_clkdiv_dmc1[index][2] <<
395 EXYNOS4_CLKDIV_DMC1_C2CACLK_SHIFT));
397 __raw_writel(tmp, EXYNOS4_CLKDIV_DMC1);
400 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC1);
401 } while (tmp & 0x111111);
403 /* Change Divider - TOP */
404 tmp = __raw_readl(EXYNOS4_CLKDIV_TOP);
406 tmp &= ~(EXYNOS4_CLKDIV_TOP_ACLK266_GPS_MASK |
407 EXYNOS4_CLKDIV_TOP_ACLK100_MASK |
408 EXYNOS4_CLKDIV_TOP_ACLK160_MASK |
409 EXYNOS4_CLKDIV_TOP_ACLK133_MASK |
410 EXYNOS4_CLKDIV_TOP_ONENAND_MASK);
412 tmp |= ((exynos4x12_clkdiv_top[index][0] <<
413 EXYNOS4_CLKDIV_TOP_ACLK266_GPS_SHIFT) |
414 (exynos4x12_clkdiv_top[index][1] <<
415 EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT) |
416 (exynos4x12_clkdiv_top[index][2] <<
417 EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT) |
418 (exynos4x12_clkdiv_top[index][3] <<
419 EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT) |
420 (exynos4x12_clkdiv_top[index][4] <<
421 EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT));
423 __raw_writel(tmp, EXYNOS4_CLKDIV_TOP);
426 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_TOP);
427 } while (tmp & 0x11111);
429 /* Change Divider - LEFTBUS */
430 tmp = __raw_readl(EXYNOS4_CLKDIV_LEFTBUS);
432 tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK);
434 tmp |= ((exynos4x12_clkdiv_lr_bus[index][0] <<
435 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) |
436 (exynos4x12_clkdiv_lr_bus[index][1] <<
437 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT));
439 __raw_writel(tmp, EXYNOS4_CLKDIV_LEFTBUS);
442 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS);
443 } while (tmp & 0x11);
445 /* Change Divider - RIGHTBUS */
446 tmp = __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS);
448 tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK);
450 tmp |= ((exynos4x12_clkdiv_lr_bus[index][0] <<
451 EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) |
452 (exynos4x12_clkdiv_lr_bus[index][1] <<
453 EXYNOS4_CLKDIV_BUS_GPLR_SHIFT));
455 __raw_writel(tmp, EXYNOS4_CLKDIV_RIGHTBUS);
458 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS);
459 } while (tmp & 0x11);
461 /* Change Divider - MFC */
462 tmp = __raw_readl(EXYNOS4_CLKDIV_MFC);
464 tmp &= ~(EXYNOS4_CLKDIV_MFC_MASK);
466 tmp |= ((exynos4x12_clkdiv_sclkip[index][0] <<
467 EXYNOS4_CLKDIV_MFC_SHIFT));
469 __raw_writel(tmp, EXYNOS4_CLKDIV_MFC);
472 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_MFC);
475 /* Change Divider - JPEG */
476 tmp = __raw_readl(EXYNOS4_CLKDIV_CAM1);
478 tmp &= ~(EXYNOS4_CLKDIV_CAM1_JPEG_MASK);
480 tmp |= ((exynos4x12_clkdiv_sclkip[index][1] <<
481 EXYNOS4_CLKDIV_CAM1_JPEG_SHIFT));
483 __raw_writel(tmp, EXYNOS4_CLKDIV_CAM1);
486 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1);
489 /* Change Divider - FIMC0~3 */
490 tmp = __raw_readl(EXYNOS4_CLKDIV_CAM);
492 tmp &= ~(EXYNOS4_CLKDIV_CAM_FIMC0_MASK | EXYNOS4_CLKDIV_CAM_FIMC1_MASK |
493 EXYNOS4_CLKDIV_CAM_FIMC2_MASK | EXYNOS4_CLKDIV_CAM_FIMC3_MASK);
495 tmp |= ((exynos4x12_clkdiv_sclkip[index][2] <<
496 EXYNOS4_CLKDIV_CAM_FIMC0_SHIFT) |
497 (exynos4x12_clkdiv_sclkip[index][2] <<
498 EXYNOS4_CLKDIV_CAM_FIMC1_SHIFT) |
499 (exynos4x12_clkdiv_sclkip[index][2] <<
500 EXYNOS4_CLKDIV_CAM_FIMC2_SHIFT) |
501 (exynos4x12_clkdiv_sclkip[index][2] <<
502 EXYNOS4_CLKDIV_CAM_FIMC3_SHIFT));
504 __raw_writel(tmp, EXYNOS4_CLKDIV_CAM);
507 tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1);
508 } while (tmp & 0x1111);
513 static void busfreq_mon_reset(struct busfreq_data *data)
517 for (i = 0; i < PPMU_END; i++) {
518 void __iomem *ppmu_base = data->ppmu[i].hw_base;
520 /* Reset the performance and cycle counters */
521 exynos_ppmu_reset(ppmu_base);
523 /* Setup count registers to monitor read/write transactions */
524 data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT;
525 exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3,
526 data->ppmu[i].event[PPMU_PMNCNT3]);
528 exynos_ppmu_start(ppmu_base);
532 static void exynos4_read_ppmu(struct busfreq_data *data)
536 for (i = 0; i < PPMU_END; i++) {
537 void __iomem *ppmu_base = data->ppmu[i].hw_base;
539 exynos_ppmu_stop(ppmu_base);
541 /* Update local data from PPMU */
542 data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT);
544 for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
545 if (data->ppmu[i].event[j] == 0)
546 data->ppmu[i].count[j] = 0;
548 data->ppmu[i].count[j] =
549 exynos_ppmu_read(ppmu_base, j);
553 busfreq_mon_reset(data);
556 static int exynos4x12_get_intspec(unsigned long mifclk)
560 while (exynos4x12_intclk_table[i].clk) {
561 if (exynos4x12_intclk_table[i].clk <= mifclk)
569 static int exynos4_bus_setvolt(struct busfreq_data *data,
570 struct busfreq_opp_info *oppi,
571 struct busfreq_opp_info *oldoppi)
574 unsigned long volt = oppi->volt;
576 switch (data->type) {
577 case TYPE_BUSF_EXYNOS4210:
578 /* OPP represents DMC clock + INT voltage */
579 err = regulator_set_voltage(data->vdd_int, volt,
582 case TYPE_BUSF_EXYNOS4x12:
583 /* OPP represents MIF clock + MIF voltage */
584 err = regulator_set_voltage(data->vdd_mif, volt,
589 tmp = exynos4x12_get_intspec(oppi->rate);
592 regulator_set_voltage(data->vdd_mif,
597 err = regulator_set_voltage(data->vdd_int,
598 exynos4x12_intclk_table[tmp].volt,
602 regulator_set_voltage(data->vdd_mif,
613 static int exynos4_bus_target(struct device *dev, unsigned long *_freq,
617 struct platform_device *pdev = container_of(dev, struct platform_device,
619 struct busfreq_data *data = platform_get_drvdata(pdev);
620 struct dev_pm_opp *opp;
622 unsigned long old_freq = data->curr_oppinfo.rate;
623 struct busfreq_opp_info new_oppinfo;
626 opp = devfreq_recommended_opp(dev, _freq, flags);
631 new_oppinfo.rate = dev_pm_opp_get_freq(opp);
632 new_oppinfo.volt = dev_pm_opp_get_voltage(opp);
634 freq = new_oppinfo.rate;
636 if (old_freq == freq)
639 dev_dbg(dev, "targeting %lukHz %luuV\n", freq, new_oppinfo.volt);
641 mutex_lock(&data->lock);
647 err = exynos4_bus_setvolt(data, &new_oppinfo,
648 &data->curr_oppinfo);
652 if (old_freq != freq) {
653 switch (data->type) {
654 case TYPE_BUSF_EXYNOS4210:
655 err = exynos4210_set_busclk(data, &new_oppinfo);
657 case TYPE_BUSF_EXYNOS4x12:
658 err = exynos4x12_set_busclk(data, &new_oppinfo);
668 err = exynos4_bus_setvolt(data, &new_oppinfo,
669 &data->curr_oppinfo);
673 data->curr_oppinfo = new_oppinfo;
675 mutex_unlock(&data->lock);
679 static int exynos4_get_busier_ppmu(struct busfreq_data *data)
683 unsigned int temp = 0;
685 for (i = 0; i < PPMU_END; i++) {
686 for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
687 if (data->ppmu[i].count[j] > temp) {
688 temp = data->ppmu[i].count[j];
697 static int exynos4_bus_get_dev_status(struct device *dev,
698 struct devfreq_dev_status *stat)
700 struct busfreq_data *data = dev_get_drvdata(dev);
703 exynos4_read_ppmu(data);
704 busier = exynos4_get_busier_ppmu(data);
705 stat->current_frequency = data->curr_oppinfo.rate;
707 /* Number of cycles spent on memory access */
708 stat->busy_time = data->ppmu[busier].count[PPMU_PMNCNT3];
709 stat->busy_time *= 100 / BUS_SATURATION_RATIO;
710 stat->total_time = data->ppmu[busier].ccnt;
712 /* If the counters have overflown, retry */
713 if (data->ppmu[busier].ccnt_overflow ||
714 data->ppmu[busier].count_overflow[0])
720 static struct devfreq_dev_profile exynos4_devfreq_profile = {
721 .initial_freq = 400000,
723 .target = exynos4_bus_target,
724 .get_dev_status = exynos4_bus_get_dev_status,
727 static int exynos4210_init_tables(struct busfreq_data *data)
733 tmp = __raw_readl(EXYNOS4_CLKDIV_DMC0);
734 for (i = LV_0; i < EX4210_LV_NUM; i++) {
735 tmp &= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK |
736 EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK |
737 EXYNOS4_CLKDIV_DMC0_DPHY_MASK |
738 EXYNOS4_CLKDIV_DMC0_DMC_MASK |
739 EXYNOS4_CLKDIV_DMC0_DMCD_MASK |
740 EXYNOS4_CLKDIV_DMC0_DMCP_MASK |
741 EXYNOS4_CLKDIV_DMC0_COPY2_MASK |
742 EXYNOS4_CLKDIV_DMC0_CORETI_MASK);
744 tmp |= ((exynos4210_clkdiv_dmc0[i][0] <<
745 EXYNOS4_CLKDIV_DMC0_ACP_SHIFT) |
746 (exynos4210_clkdiv_dmc0[i][1] <<
747 EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT) |
748 (exynos4210_clkdiv_dmc0[i][2] <<
749 EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT) |
750 (exynos4210_clkdiv_dmc0[i][3] <<
751 EXYNOS4_CLKDIV_DMC0_DMC_SHIFT) |
752 (exynos4210_clkdiv_dmc0[i][4] <<
753 EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT) |
754 (exynos4210_clkdiv_dmc0[i][5] <<
755 EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT) |
756 (exynos4210_clkdiv_dmc0[i][6] <<
757 EXYNOS4_CLKDIV_DMC0_COPY2_SHIFT) |
758 (exynos4210_clkdiv_dmc0[i][7] <<
759 EXYNOS4_CLKDIV_DMC0_CORETI_SHIFT));
761 data->dmc_divtable[i] = tmp;
764 tmp = __raw_readl(EXYNOS4_CLKDIV_TOP);
765 for (i = LV_0; i < EX4210_LV_NUM; i++) {
766 tmp &= ~(EXYNOS4_CLKDIV_TOP_ACLK200_MASK |
767 EXYNOS4_CLKDIV_TOP_ACLK100_MASK |
768 EXYNOS4_CLKDIV_TOP_ACLK160_MASK |
769 EXYNOS4_CLKDIV_TOP_ACLK133_MASK |
770 EXYNOS4_CLKDIV_TOP_ONENAND_MASK);
772 tmp |= ((exynos4210_clkdiv_top[i][0] <<
773 EXYNOS4_CLKDIV_TOP_ACLK200_SHIFT) |
774 (exynos4210_clkdiv_top[i][1] <<
775 EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT) |
776 (exynos4210_clkdiv_top[i][2] <<
777 EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT) |
778 (exynos4210_clkdiv_top[i][3] <<
779 EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT) |
780 (exynos4210_clkdiv_top[i][4] <<
781 EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT));
783 data->top_divtable[i] = tmp;
786 #ifdef CONFIG_EXYNOS_ASV
787 tmp = exynos4_result_of_asv;
789 tmp = 0; /* Max voltages for the reliability of the unknown */
792 pr_debug("ASV Group of Exynos4 is %d\n", tmp);
793 /* Use merged grouping for voltage */
814 pr_warn("Unknown ASV Group. Use max voltage.\n");
818 for (i = LV_0; i < EX4210_LV_NUM; i++)
819 exynos4210_busclk_table[i].volt = exynos4210_asv_volt[mgrp][i];
821 for (i = LV_0; i < EX4210_LV_NUM; i++) {
822 err = dev_pm_opp_add(data->dev, exynos4210_busclk_table[i].clk,
823 exynos4210_busclk_table[i].volt);
825 dev_err(data->dev, "Cannot add opp entries.\n");
834 static int exynos4x12_init_tables(struct busfreq_data *data)
840 /* Enable pause function for DREX2 DVFS */
841 tmp = __raw_readl(EXYNOS4_DMC_PAUSE_CTRL);
842 tmp |= EXYNOS4_DMC_PAUSE_ENABLE;
843 __raw_writel(tmp, EXYNOS4_DMC_PAUSE_CTRL);
845 tmp = __raw_readl(EXYNOS4_CLKDIV_DMC0);
847 for (i = 0; i < EX4x12_LV_NUM; i++) {
848 tmp &= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK |
849 EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK |
850 EXYNOS4_CLKDIV_DMC0_DPHY_MASK |
851 EXYNOS4_CLKDIV_DMC0_DMC_MASK |
852 EXYNOS4_CLKDIV_DMC0_DMCD_MASK |
853 EXYNOS4_CLKDIV_DMC0_DMCP_MASK);
855 tmp |= ((exynos4x12_clkdiv_dmc0[i][0] <<
856 EXYNOS4_CLKDIV_DMC0_ACP_SHIFT) |
857 (exynos4x12_clkdiv_dmc0[i][1] <<
858 EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT) |
859 (exynos4x12_clkdiv_dmc0[i][2] <<
860 EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT) |
861 (exynos4x12_clkdiv_dmc0[i][3] <<
862 EXYNOS4_CLKDIV_DMC0_DMC_SHIFT) |
863 (exynos4x12_clkdiv_dmc0[i][4] <<
864 EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT) |
865 (exynos4x12_clkdiv_dmc0[i][5] <<
866 EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT));
868 data->dmc_divtable[i] = tmp;
871 #ifdef CONFIG_EXYNOS_ASV
872 tmp = exynos4_result_of_asv;
874 tmp = 0; /* Max voltages for the reliability of the unknown */
879 pr_debug("ASV Group of Exynos4x12 is %d\n", tmp);
881 for (i = 0; i < EX4x12_LV_NUM; i++) {
882 exynos4x12_mifclk_table[i].volt =
883 exynos4x12_mif_step_50[tmp][i];
884 exynos4x12_intclk_table[i].volt =
885 exynos4x12_int_volt[tmp][i];
888 for (i = 0; i < EX4x12_LV_NUM; i++) {
889 ret = dev_pm_opp_add(data->dev, exynos4x12_mifclk_table[i].clk,
890 exynos4x12_mifclk_table[i].volt);
892 dev_err(data->dev, "Fail to add opp entries.\n");
900 static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this,
901 unsigned long event, void *ptr)
903 struct busfreq_data *data = container_of(this, struct busfreq_data,
905 struct dev_pm_opp *opp;
906 struct busfreq_opp_info new_oppinfo;
907 unsigned long maxfreq = ULONG_MAX;
911 case PM_SUSPEND_PREPARE:
912 /* Set Fastest and Deactivate DVFS */
913 mutex_lock(&data->lock);
915 data->disabled = true;
918 opp = dev_pm_opp_find_freq_floor(data->dev, &maxfreq);
921 dev_err(data->dev, "%s: unable to find a min freq\n",
923 mutex_unlock(&data->lock);
926 new_oppinfo.rate = dev_pm_opp_get_freq(opp);
927 new_oppinfo.volt = dev_pm_opp_get_voltage(opp);
930 err = exynos4_bus_setvolt(data, &new_oppinfo,
931 &data->curr_oppinfo);
935 switch (data->type) {
936 case TYPE_BUSF_EXYNOS4210:
937 err = exynos4210_set_busclk(data, &new_oppinfo);
939 case TYPE_BUSF_EXYNOS4x12:
940 err = exynos4x12_set_busclk(data, &new_oppinfo);
948 data->curr_oppinfo = new_oppinfo;
950 mutex_unlock(&data->lock);
954 case PM_POST_RESTORE:
955 case PM_POST_SUSPEND:
957 mutex_lock(&data->lock);
958 data->disabled = false;
959 mutex_unlock(&data->lock);
966 static int exynos4_busfreq_probe(struct platform_device *pdev)
968 struct busfreq_data *data;
969 struct dev_pm_opp *opp;
970 struct device *dev = &pdev->dev;
973 data = devm_kzalloc(&pdev->dev, sizeof(struct busfreq_data), GFP_KERNEL);
975 dev_err(dev, "Cannot allocate memory.\n");
979 data->type = pdev->id_entry->driver_data;
980 data->ppmu[PPMU_DMC0].hw_base = S5P_VA_DMC0;
981 data->ppmu[PPMU_DMC1].hw_base = S5P_VA_DMC1;
982 data->pm_notifier.notifier_call = exynos4_busfreq_pm_notifier_event;
984 mutex_init(&data->lock);
986 switch (data->type) {
987 case TYPE_BUSF_EXYNOS4210:
988 err = exynos4210_init_tables(data);
990 case TYPE_BUSF_EXYNOS4x12:
991 err = exynos4x12_init_tables(data);
994 dev_err(dev, "Cannot determine the device id %d\n", data->type);
998 dev_err(dev, "Cannot initialize busfreq table %d\n",
1003 data->vdd_int = devm_regulator_get(dev, "vdd_int");
1004 if (IS_ERR(data->vdd_int)) {
1005 dev_err(dev, "Cannot get the regulator \"vdd_int\"\n");
1006 return PTR_ERR(data->vdd_int);
1008 if (data->type == TYPE_BUSF_EXYNOS4x12) {
1009 data->vdd_mif = devm_regulator_get(dev, "vdd_mif");
1010 if (IS_ERR(data->vdd_mif)) {
1011 dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n");
1012 return PTR_ERR(data->vdd_mif);
1017 opp = dev_pm_opp_find_freq_floor(dev,
1018 &exynos4_devfreq_profile.initial_freq);
1021 dev_err(dev, "Invalid initial frequency %lu kHz.\n",
1022 exynos4_devfreq_profile.initial_freq);
1023 return PTR_ERR(opp);
1025 data->curr_oppinfo.rate = dev_pm_opp_get_freq(opp);
1026 data->curr_oppinfo.volt = dev_pm_opp_get_voltage(opp);
1029 platform_set_drvdata(pdev, data);
1031 data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile,
1032 "simple_ondemand", NULL);
1033 if (IS_ERR(data->devfreq))
1034 return PTR_ERR(data->devfreq);
1037 * Start PPMU (Performance Profiling Monitoring Unit) to check
1038 * utilization of each IP in the Exynos4 SoC.
1040 busfreq_mon_reset(data);
1042 /* Register opp_notifier for Exynos4 busfreq */
1043 err = devfreq_register_opp_notifier(dev, data->devfreq);
1045 dev_err(dev, "Failed to register opp notifier\n");
1046 goto err_notifier_opp;
1049 /* Register pm_notifier for Exynos4 busfreq */
1050 err = register_pm_notifier(&data->pm_notifier);
1052 dev_err(dev, "Failed to setup pm notifier\n");
1053 goto err_notifier_pm;
1059 devfreq_unregister_opp_notifier(dev, data->devfreq);
1061 devfreq_remove_device(data->devfreq);
1066 static int exynos4_busfreq_remove(struct platform_device *pdev)
1068 struct busfreq_data *data = platform_get_drvdata(pdev);
1070 /* Unregister all of notifier chain */
1071 unregister_pm_notifier(&data->pm_notifier);
1072 devfreq_unregister_opp_notifier(data->dev, data->devfreq);
1074 /* Remove devfreq instance */
1075 devfreq_remove_device(data->devfreq);
1080 #ifdef CONFIG_PM_SLEEP
1081 static int exynos4_busfreq_resume(struct device *dev)
1083 struct busfreq_data *data = dev_get_drvdata(dev);
1085 busfreq_mon_reset(data);
1090 static SIMPLE_DEV_PM_OPS(exynos4_busfreq_pm_ops, NULL, exynos4_busfreq_resume);
1092 static const struct platform_device_id exynos4_busfreq_id[] = {
1093 { "exynos4210-busfreq", TYPE_BUSF_EXYNOS4210 },
1094 { "exynos4412-busfreq", TYPE_BUSF_EXYNOS4x12 },
1095 { "exynos4212-busfreq", TYPE_BUSF_EXYNOS4x12 },
1099 static struct platform_driver exynos4_busfreq_driver = {
1100 .probe = exynos4_busfreq_probe,
1101 .remove = exynos4_busfreq_remove,
1102 .id_table = exynos4_busfreq_id,
1104 .name = "exynos4-busfreq",
1105 .owner = THIS_MODULE,
1106 .pm = &exynos4_busfreq_pm_ops,
1110 static int __init exynos4_busfreq_init(void)
1112 return platform_driver_register(&exynos4_busfreq_driver);
1114 late_initcall(exynos4_busfreq_init);
1116 static void __exit exynos4_busfreq_exit(void)
1118 platform_driver_unregister(&exynos4_busfreq_driver);
1120 module_exit(exynos4_busfreq_exit);
1122 MODULE_LICENSE("GPL");
1123 MODULE_DESCRIPTION("EXYNOS4 busfreq driver with devfreq framework");
1124 MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");