19 #include <linux/slab.h>
26 #include <linux/module.h>
29 #ifdef CONFIG_EXYNOS_ASV
30 extern unsigned int exynos_result_of_asv;
33 #include <mach/regs-clock.h>
37 #define MAX_SAFEVOLT 1200000
45 #define BUS_SATURATION_RATIO 40
71 #define EX4210_LV_MAX LV_2
72 #define EX4x12_LV_MAX LV_4
73 #define EX4210_LV_NUM (LV_2 + 1)
74 #define EX4x12_LV_NUM (LV_4 + 1)
102 {
LV_0, 400000, 1150000},
103 {
LV_1, 267000, 1050000},
104 {
LV_2, 133000, 1025000},
113 {
LV_0, 400000, 1100000},
114 {
LV_1, 267000, 1000000},
115 {
LV_2, 160000, 950000},
116 {
LV_3, 133000, 950000},
117 {
LV_4, 100000, 950000},
126 {
LV_0, 200000, 1000000},
127 {
LV_1, 160000, 950000},
128 {
LV_2, 133000, 925000},
129 {
LV_3, 100000, 900000},
136 {1150000, 1050000, 1050000},
137 {1125000, 1025000, 1025000},
138 {1100000, 1000000, 1000000},
139 {1075000, 975000, 975000},
140 {1050000, 950000, 950000},
143 static unsigned int exynos4x12_mif_step_50[][
EX4x12_LV_NUM] = {
145 {1050000, 950000, 900000, 900000, 900000},
146 {1050000, 950000, 900000, 900000, 900000},
147 {1050000, 950000, 900000, 900000, 900000},
148 {1050000, 900000, 900000, 900000, 900000},
149 {1050000, 900000, 900000, 900000, 850000},
150 {1050000, 900000, 900000, 850000, 850000},
151 {1050000, 900000, 850000, 850000, 850000},
152 {1050000, 900000, 850000, 850000, 850000},
153 {1050000, 900000, 850000, 850000, 850000},
158 {1000000, 950000, 925000, 900000},
159 {975000, 925000, 925000, 900000},
160 {950000, 925000, 900000, 875000},
161 {950000, 900000, 900000, 875000},
162 {925000, 875000, 875000, 875000},
163 {900000, 850000, 850000, 850000},
164 {900000, 850000, 850000, 850000},
165 {900000, 850000, 850000, 850000},
166 {900000, 850000, 850000, 850000},
170 static unsigned int exynos4210_clkdiv_dmc0[][8] = {
178 { 3, 1, 1, 1, 1, 1, 3, 1 },
180 { 4, 1, 1, 2, 1, 1, 3, 1 },
182 { 5, 1, 1, 5, 1, 1, 3, 1 },
184 static unsigned int exynos4210_clkdiv_top[][5] = {
196 static unsigned int exynos4210_clkdiv_lr_bus[][2] = {
210 static unsigned int exynos4x12_clkdiv_dmc0[][6] = {
228 static unsigned int exynos4x12_clkdiv_dmc1[][6] = {
245 static unsigned int exynos4x12_clkdiv_top[][5] = {
263 static unsigned int exynos4x12_clkdiv_lr_bus[][2] = {
280 static unsigned int exynos4x12_clkdiv_sclkip[][3] = {
308 if (index == EX4210_LV_NUM)
318 }
while (tmp & 0x11111111);
327 }
while (tmp & 0x11111);
334 tmp |= ((exynos4210_clkdiv_lr_bus[
index][0] <<
336 (exynos4210_clkdiv_lr_bus[index][1] <<
343 }
while (tmp & 0x11);
350 tmp |= ((exynos4210_clkdiv_lr_bus[
index][0] <<
352 (exynos4210_clkdiv_lr_bus[index][1] <<
359 }
while (tmp & 0x11);
364 static int exynos4x12_set_busclk(
struct busfreq_data *data,
struct opp *opp)
370 if (
opp_get_freq(opp) == exynos4x12_mifclk_table[index].clk)
373 if (index == EX4x12_LV_NUM)
383 }
while (tmp & 0x11111111);
392 tmp |= ((exynos4x12_clkdiv_dmc1[
index][0] <<
394 (exynos4x12_clkdiv_dmc1[index][1] <<
396 (exynos4x12_clkdiv_dmc1[
index][2] <<
403 }
while (tmp & 0x111111);
414 tmp |= ((exynos4x12_clkdiv_top[
index][0] <<
416 (exynos4x12_clkdiv_top[index][1] <<
418 (exynos4x12_clkdiv_top[
index][2] <<
420 (exynos4x12_clkdiv_top[index][3] <<
422 (exynos4x12_clkdiv_top[
index][4] <<
429 }
while (tmp & 0x11111);
436 tmp |= ((exynos4x12_clkdiv_lr_bus[
index][0] <<
438 (exynos4x12_clkdiv_lr_bus[index][1] <<
445 }
while (tmp & 0x11);
452 tmp |= ((exynos4x12_clkdiv_lr_bus[
index][0] <<
454 (exynos4x12_clkdiv_lr_bus[index][1] <<
461 }
while (tmp & 0x11);
468 tmp |= ((exynos4x12_clkdiv_sclkip[
index][0] <<
482 tmp |= ((exynos4x12_clkdiv_sclkip[
index][1] <<
497 tmp |= ((exynos4x12_clkdiv_sclkip[
index][2] <<
499 (exynos4x12_clkdiv_sclkip[index][2] <<
501 (exynos4x12_clkdiv_sclkip[
index][2] <<
503 (exynos4x12_clkdiv_sclkip[index][2] <<
510 }
while (tmp & 0x1111);
516 static void busfreq_mon_reset(
struct busfreq_data *data)
520 for (i = 0; i < 2; i++) {
530 data->
dmc[
i].event = 0x6;
539 static void exynos4_read_ppmu(
struct busfreq_data *data)
543 for (i = 0; i < 2; i++) {
554 data->
dmc[
i].ccnt_overflow = overflow & (1 << 31);
558 ppmu_base + (0xf110 + (0x10 * j)));
559 data->
dmc[
i].count_overflow[
j] = overflow & (1 <<
j);
563 busfreq_mon_reset(data);
566 static int exynos4x12_get_intspec(
unsigned long mifclk)
570 while (exynos4x12_intclk_table[i].clk) {
571 if (exynos4x12_intclk_table[i].clk <= mifclk)
579 static int exynos4_bus_setvolt(
struct busfreq_data *data,
struct opp *opp,
585 switch (data->
type) {
607 exynos4x12_intclk_table[tmp].
volt,
622 static int exynos4_bus_target(
struct device *
dev,
unsigned long *_freq,
636 if (old_freq == freq)
647 err = exynos4_bus_setvolt(data, opp, data->
curr_opp);
651 if (old_freq != freq) {
652 switch (data->
type) {
654 err = exynos4210_set_busclk(data, opp);
657 err = exynos4x12_set_busclk(data, opp);
667 err = exynos4_bus_setvolt(data, opp, data->
curr_opp);
677 static int exynos4_get_busier_dmc(
struct busfreq_data *data)
682 p0 *= data->
dmc[1].ccnt;
683 p1 *= data->
dmc[0].ccnt;
685 if (data->
dmc[1].ccnt == 0)
693 static int exynos4_bus_get_dev_status(
struct device *dev,
703 exynos4_read_ppmu(data);
704 busier_dmc = exynos4_get_busier_dmc(data);
715 switch ((memctrl >> 8) & 0xf) {
717 cycles_x2 = ((timing >> 16) & 0xf) * 2;
721 cycles_x2 = ((timing >> 8) & 0xf) + ((timing >> 0) & 0xf);
724 pr_err(
"%s: Unknown Memory Type(%d).\n", __func__,
725 (memctrl >> 8) & 0xf);
730 stat->
busy_time = data->
dmc[busier_dmc].count[0] / 2 * (cycles_x2 + 2);
735 if (data->
dmc[busier_dmc].ccnt_overflow ||
736 data->
dmc[busier_dmc].count_overflow[0])
742 static void exynos4_bus_exit(
struct device *dev)
750 .initial_freq = 400000,
752 .target = exynos4_bus_target,
753 .get_dev_status = exynos4_bus_get_dev_status,
754 .exit = exynos4_bus_exit,
757 static int exynos4210_init_tables(
struct busfreq_data *data)
774 tmp |= ((exynos4210_clkdiv_dmc0[
i][0] <<
776 (exynos4210_clkdiv_dmc0[i][1] <<
778 (exynos4210_clkdiv_dmc0[
i][2] <<
780 (exynos4210_clkdiv_dmc0[i][3] <<
782 (exynos4210_clkdiv_dmc0[
i][4] <<
784 (exynos4210_clkdiv_dmc0[i][5] <<
786 (exynos4210_clkdiv_dmc0[
i][6] <<
788 (exynos4210_clkdiv_dmc0[i][7] <<
802 tmp |= ((exynos4210_clkdiv_top[
i][0] <<
804 (exynos4210_clkdiv_top[i][1] <<
806 (exynos4210_clkdiv_top[
i][2] <<
808 (exynos4210_clkdiv_top[i][3] <<
810 (exynos4210_clkdiv_top[
i][4] <<
816 #ifdef CONFIG_EXYNOS_ASV
817 tmp = exynos4_result_of_asv;
822 pr_debug(
"ASV Group of Exynos4 is %d\n", tmp);
844 pr_warn(
"Unknown ASV Group. Use max voltage.\n");
849 exynos4210_busclk_table[i].volt = exynos4210_asv_volt[mgrp][i];
853 exynos4210_busclk_table[i].
volt);
855 dev_err(data->
dev,
"Cannot add opp entries.\n");
864 static int exynos4x12_init_tables(
struct busfreq_data *data)
885 tmp |= ((exynos4x12_clkdiv_dmc0[
i][0] <<
887 (exynos4x12_clkdiv_dmc0[i][1] <<
889 (exynos4x12_clkdiv_dmc0[
i][2] <<
891 (exynos4x12_clkdiv_dmc0[i][3] <<
893 (exynos4x12_clkdiv_dmc0[
i][4] <<
895 (exynos4x12_clkdiv_dmc0[i][5] <<
901 #ifdef CONFIG_EXYNOS_ASV
902 tmp = exynos4_result_of_asv;
909 pr_debug(
"ASV Group of Exynos4x12 is %d\n", tmp);
912 exynos4x12_mifclk_table[
i].
volt =
913 exynos4x12_mif_step_50[
tmp][
i];
914 exynos4x12_intclk_table[
i].
volt =
915 exynos4x12_int_volt[
tmp][
i];
920 exynos4x12_mifclk_table[i].
volt);
922 dev_err(data->
dev,
"Fail to add opp entries.\n");
930 static int exynos4_busfreq_pm_notifier_event(
struct notifier_block *
this,
948 err = exynos4_bus_setvolt(data, opp, data->
curr_opp);
952 switch (data->
type) {
954 err = exynos4210_set_busclk(data, opp);
957 err = exynos4x12_set_busclk(data, opp);
992 dev_err(dev,
"Cannot allocate memory.\n");
999 data->
pm_notifier.notifier_call = exynos4_busfreq_pm_notifier_event;
1003 switch (data->
type) {
1005 err = exynos4210_init_tables(data);
1008 err = exynos4x12_init_tables(data);
1011 dev_err(dev,
"Cannot determine the device id %d\n", data->
type);
1019 dev_err(dev,
"Cannot get the regulator \"vdd_int\"\n");
1026 dev_err(dev,
"Cannot get the regulator \"vdd_mif\"\n");
1036 dev_err(dev,
"Invalid initial frequency %lu kHz.\n",
1043 platform_set_drvdata(pdev, data);
1045 busfreq_mon_reset(data);
1058 dev_err(dev,
"Failed to setup pm notifier\n");
1059 goto err_devfreq_add;
1076 struct busfreq_data *data = platform_get_drvdata(pdev);
1088 static int exynos4_busfreq_resume(
struct device *dev)
1092 busfreq_mon_reset(data);
1096 static const struct dev_pm_ops exynos4_busfreq_pm = {
1097 .resume = exynos4_busfreq_resume,
1108 .probe = exynos4_busfreq_probe,
1110 .id_table = exynos4_busfreq_id,
1112 .
name =
"exynos4-busfreq",
1114 .pm = &exynos4_busfreq_pm,
1118 static int __init exynos4_busfreq_init(
void)
1124 static void __exit exynos4_busfreq_exit(
void)