exynos5250-cpufreq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2010-20122Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS5250 - CPU frequency scaling support
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/err.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/slab.h>
  17. #include <linux/cpufreq.h>
  18. #include <mach/map.h>
  19. #include "exynos-cpufreq.h"
  20. static struct clk *cpu_clk;
  21. static struct clk *moutcore;
  22. static struct clk *mout_mpll;
  23. static struct clk *mout_apll;
  24. static unsigned int exynos5250_volt_table[] = {
  25. 1300000, 1250000, 1225000, 1200000, 1150000,
  26. 1125000, 1100000, 1075000, 1050000, 1025000,
  27. 1012500, 1000000, 975000, 950000, 937500,
  28. 925000
  29. };
  30. static struct cpufreq_frequency_table exynos5250_freq_table[] = {
  31. {L0, 1700 * 1000},
  32. {L1, 1600 * 1000},
  33. {L2, 1500 * 1000},
  34. {L3, 1400 * 1000},
  35. {L4, 1300 * 1000},
  36. {L5, 1200 * 1000},
  37. {L6, 1100 * 1000},
  38. {L7, 1000 * 1000},
  39. {L8, 900 * 1000},
  40. {L9, 800 * 1000},
  41. {L10, 700 * 1000},
  42. {L11, 600 * 1000},
  43. {L12, 500 * 1000},
  44. {L13, 400 * 1000},
  45. {L14, 300 * 1000},
  46. {L15, 200 * 1000},
  47. {0, CPUFREQ_TABLE_END},
  48. };
  49. static struct apll_freq apll_freq_5250[] = {
  50. /*
  51. * values:
  52. * freq
  53. * clock divider for ARM, CPUD, ACP, PERIPH, ATB, PCLK_DBG, APLL, ARM2
  54. * clock divider for COPY, HPM, RESERVED
  55. * PLL M, P, S
  56. */
  57. APLL_FREQ(1700, 0, 3, 7, 7, 7, 3, 5, 0, 0, 2, 0, 425, 6, 0),
  58. APLL_FREQ(1600, 0, 3, 7, 7, 7, 1, 4, 0, 0, 2, 0, 200, 3, 0),
  59. APLL_FREQ(1500, 0, 2, 7, 7, 7, 1, 4, 0, 0, 2, 0, 250, 4, 0),
  60. APLL_FREQ(1400, 0, 2, 7, 7, 6, 1, 4, 0, 0, 2, 0, 175, 3, 0),
  61. APLL_FREQ(1300, 0, 2, 7, 7, 6, 1, 3, 0, 0, 2, 0, 325, 6, 0),
  62. APLL_FREQ(1200, 0, 2, 7, 7, 5, 1, 3, 0, 0, 2, 0, 200, 4, 0),
  63. APLL_FREQ(1100, 0, 3, 7, 7, 5, 1, 3, 0, 0, 2, 0, 275, 6, 0),
  64. APLL_FREQ(1000, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 125, 3, 0),
  65. APLL_FREQ(900, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 150, 4, 0),
  66. APLL_FREQ(800, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 100, 3, 0),
  67. APLL_FREQ(700, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 175, 3, 1),
  68. APLL_FREQ(600, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 200, 4, 1),
  69. APLL_FREQ(500, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 125, 3, 1),
  70. APLL_FREQ(400, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 100, 3, 1),
  71. APLL_FREQ(300, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 200, 4, 2),
  72. APLL_FREQ(200, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 100, 3, 2),
  73. };
  74. static void set_clkdiv(unsigned int div_index)
  75. {
  76. unsigned int tmp;
  77. /* Change Divider - CPU0 */
  78. tmp = apll_freq_5250[div_index].clk_div_cpu0;
  79. __raw_writel(tmp, EXYNOS5_CLKDIV_CPU0);
  80. while (__raw_readl(EXYNOS5_CLKDIV_STATCPU0) & 0x11111111)
  81. cpu_relax();
  82. /* Change Divider - CPU1 */
  83. tmp = apll_freq_5250[div_index].clk_div_cpu1;
  84. __raw_writel(tmp, EXYNOS5_CLKDIV_CPU1);
  85. while (__raw_readl(EXYNOS5_CLKDIV_STATCPU1) & 0x11)
  86. cpu_relax();
  87. }
  88. static void set_apll(unsigned int index)
  89. {
  90. unsigned int tmp;
  91. unsigned int freq = apll_freq_5250[index].freq;
  92. /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  93. clk_set_parent(moutcore, mout_mpll);
  94. do {
  95. cpu_relax();
  96. tmp = (__raw_readl(EXYNOS5_CLKMUX_STATCPU) >> 16);
  97. tmp &= 0x7;
  98. } while (tmp != 0x2);
  99. clk_set_rate(mout_apll, freq * 1000);
  100. /* MUX_CORE_SEL = APLL */
  101. clk_set_parent(moutcore, mout_apll);
  102. do {
  103. cpu_relax();
  104. tmp = __raw_readl(EXYNOS5_CLKMUX_STATCPU);
  105. tmp &= (0x7 << 16);
  106. } while (tmp != (0x1 << 16));
  107. }
  108. static void exynos5250_set_frequency(unsigned int old_index,
  109. unsigned int new_index)
  110. {
  111. if (old_index > new_index) {
  112. set_clkdiv(new_index);
  113. set_apll(new_index);
  114. } else if (old_index < new_index) {
  115. set_apll(new_index);
  116. set_clkdiv(new_index);
  117. }
  118. }
  119. int exynos5250_cpufreq_init(struct exynos_dvfs_info *info)
  120. {
  121. unsigned long rate;
  122. cpu_clk = clk_get(NULL, "armclk");
  123. if (IS_ERR(cpu_clk))
  124. return PTR_ERR(cpu_clk);
  125. moutcore = clk_get(NULL, "mout_cpu");
  126. if (IS_ERR(moutcore))
  127. goto err_moutcore;
  128. mout_mpll = clk_get(NULL, "mout_mpll");
  129. if (IS_ERR(mout_mpll))
  130. goto err_mout_mpll;
  131. rate = clk_get_rate(mout_mpll) / 1000;
  132. mout_apll = clk_get(NULL, "mout_apll");
  133. if (IS_ERR(mout_apll))
  134. goto err_mout_apll;
  135. info->mpll_freq_khz = rate;
  136. /* 800Mhz */
  137. info->pll_safe_idx = L9;
  138. info->cpu_clk = cpu_clk;
  139. info->volt_table = exynos5250_volt_table;
  140. info->freq_table = exynos5250_freq_table;
  141. info->set_freq = exynos5250_set_frequency;
  142. return 0;
  143. err_mout_apll:
  144. clk_put(mout_mpll);
  145. err_mout_mpll:
  146. clk_put(moutcore);
  147. err_moutcore:
  148. clk_put(cpu_clk);
  149. pr_err("%s: failed initialization\n", __func__);
  150. return -EINVAL;
  151. }