exynos4x12-cpufreq.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (c) 2010-2012 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS4X12 - 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 "exynos-cpufreq.h"
  19. static struct clk *cpu_clk;
  20. static struct clk *moutcore;
  21. static struct clk *mout_mpll;
  22. static struct clk *mout_apll;
  23. static unsigned int exynos4x12_volt_table[] = {
  24. 1350000, 1287500, 1250000, 1187500, 1137500, 1087500, 1037500,
  25. 1000000, 987500, 975000, 950000, 925000, 900000, 900000
  26. };
  27. static struct cpufreq_frequency_table exynos4x12_freq_table[] = {
  28. {CPUFREQ_BOOST_FREQ, 1500 * 1000},
  29. {L1, 1400 * 1000},
  30. {L2, 1300 * 1000},
  31. {L3, 1200 * 1000},
  32. {L4, 1100 * 1000},
  33. {L5, 1000 * 1000},
  34. {L6, 900 * 1000},
  35. {L7, 800 * 1000},
  36. {L8, 700 * 1000},
  37. {L9, 600 * 1000},
  38. {L10, 500 * 1000},
  39. {L11, 400 * 1000},
  40. {L12, 300 * 1000},
  41. {L13, 200 * 1000},
  42. {0, CPUFREQ_TABLE_END},
  43. };
  44. static struct apll_freq *apll_freq_4x12;
  45. static struct apll_freq apll_freq_4212[] = {
  46. /*
  47. * values:
  48. * freq
  49. * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, CORE2
  50. * clock divider for COPY, HPM, RESERVED
  51. * PLL M, P, S
  52. */
  53. APLL_FREQ(1500, 0, 3, 7, 0, 6, 1, 2, 0, 6, 2, 0, 250, 4, 0),
  54. APLL_FREQ(1400, 0, 3, 7, 0, 6, 1, 2, 0, 6, 2, 0, 175, 3, 0),
  55. APLL_FREQ(1300, 0, 3, 7, 0, 5, 1, 2, 0, 5, 2, 0, 325, 6, 0),
  56. APLL_FREQ(1200, 0, 3, 7, 0, 5, 1, 2, 0, 5, 2, 0, 200, 4, 0),
  57. APLL_FREQ(1100, 0, 3, 6, 0, 4, 1, 2, 0, 4, 2, 0, 275, 6, 0),
  58. APLL_FREQ(1000, 0, 2, 5, 0, 4, 1, 1, 0, 4, 2, 0, 125, 3, 0),
  59. APLL_FREQ(900, 0, 2, 5, 0, 3, 1, 1, 0, 3, 2, 0, 150, 4, 0),
  60. APLL_FREQ(800, 0, 2, 5, 0, 3, 1, 1, 0, 3, 2, 0, 100, 3, 0),
  61. APLL_FREQ(700, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 175, 3, 1),
  62. APLL_FREQ(600, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 200, 4, 1),
  63. APLL_FREQ(500, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 125, 3, 1),
  64. APLL_FREQ(400, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 100, 3, 1),
  65. APLL_FREQ(300, 0, 2, 4, 0, 2, 1, 1, 0, 3, 2, 0, 200, 4, 2),
  66. APLL_FREQ(200, 0, 1, 3, 0, 1, 1, 1, 0, 3, 2, 0, 100, 3, 2),
  67. };
  68. static struct apll_freq apll_freq_4412[] = {
  69. /*
  70. * values:
  71. * freq
  72. * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, CORE2
  73. * clock divider for COPY, HPM, CORES
  74. * PLL M, P, S
  75. */
  76. APLL_FREQ(1500, 0, 3, 7, 0, 6, 1, 2, 0, 6, 0, 7, 250, 4, 0),
  77. APLL_FREQ(1400, 0, 3, 7, 0, 6, 1, 2, 0, 6, 0, 6, 175, 3, 0),
  78. APLL_FREQ(1300, 0, 3, 7, 0, 5, 1, 2, 0, 5, 0, 6, 325, 6, 0),
  79. APLL_FREQ(1200, 0, 3, 7, 0, 5, 1, 2, 0, 5, 0, 5, 200, 4, 0),
  80. APLL_FREQ(1100, 0, 3, 6, 0, 4, 1, 2, 0, 4, 0, 5, 275, 6, 0),
  81. APLL_FREQ(1000, 0, 2, 5, 0, 4, 1, 1, 0, 4, 0, 4, 125, 3, 0),
  82. APLL_FREQ(900, 0, 2, 5, 0, 3, 1, 1, 0, 3, 0, 4, 150, 4, 0),
  83. APLL_FREQ(800, 0, 2, 5, 0, 3, 1, 1, 0, 3, 0, 3, 100, 3, 0),
  84. APLL_FREQ(700, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 3, 175, 3, 1),
  85. APLL_FREQ(600, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 2, 200, 4, 1),
  86. APLL_FREQ(500, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 2, 125, 3, 1),
  87. APLL_FREQ(400, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 1, 100, 3, 1),
  88. APLL_FREQ(300, 0, 2, 4, 0, 2, 1, 1, 0, 3, 0, 1, 200, 4, 2),
  89. APLL_FREQ(200, 0, 1, 3, 0, 1, 1, 1, 0, 3, 0, 0, 100, 3, 2),
  90. };
  91. static void exynos4x12_set_clkdiv(unsigned int div_index)
  92. {
  93. unsigned int tmp;
  94. unsigned int stat_cpu1;
  95. /* Change Divider - CPU0 */
  96. tmp = apll_freq_4x12[div_index].clk_div_cpu0;
  97. __raw_writel(tmp, EXYNOS4_CLKDIV_CPU);
  98. while (__raw_readl(EXYNOS4_CLKDIV_STATCPU) & 0x11111111)
  99. cpu_relax();
  100. /* Change Divider - CPU1 */
  101. tmp = apll_freq_4x12[div_index].clk_div_cpu1;
  102. __raw_writel(tmp, EXYNOS4_CLKDIV_CPU1);
  103. if (soc_is_exynos4212())
  104. stat_cpu1 = 0x11;
  105. else
  106. stat_cpu1 = 0x111;
  107. while (__raw_readl(EXYNOS4_CLKDIV_STATCPU1) & stat_cpu1)
  108. cpu_relax();
  109. }
  110. static void exynos4x12_set_apll(unsigned int index)
  111. {
  112. unsigned int tmp, freq = apll_freq_4x12[index].freq;
  113. /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  114. clk_set_parent(moutcore, mout_mpll);
  115. do {
  116. cpu_relax();
  117. tmp = (__raw_readl(EXYNOS4_CLKMUX_STATCPU)
  118. >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
  119. tmp &= 0x7;
  120. } while (tmp != 0x2);
  121. clk_set_rate(mout_apll, freq * 1000);
  122. /* MUX_CORE_SEL = APLL */
  123. clk_set_parent(moutcore, mout_apll);
  124. do {
  125. cpu_relax();
  126. tmp = __raw_readl(EXYNOS4_CLKMUX_STATCPU);
  127. tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
  128. } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
  129. }
  130. static void exynos4x12_set_frequency(unsigned int old_index,
  131. unsigned int new_index)
  132. {
  133. if (old_index > new_index) {
  134. exynos4x12_set_clkdiv(new_index);
  135. exynos4x12_set_apll(new_index);
  136. } else if (old_index < new_index) {
  137. exynos4x12_set_apll(new_index);
  138. exynos4x12_set_clkdiv(new_index);
  139. }
  140. }
  141. int exynos4x12_cpufreq_init(struct exynos_dvfs_info *info)
  142. {
  143. unsigned long rate;
  144. cpu_clk = clk_get(NULL, "armclk");
  145. if (IS_ERR(cpu_clk))
  146. return PTR_ERR(cpu_clk);
  147. moutcore = clk_get(NULL, "moutcore");
  148. if (IS_ERR(moutcore))
  149. goto err_moutcore;
  150. mout_mpll = clk_get(NULL, "mout_mpll");
  151. if (IS_ERR(mout_mpll))
  152. goto err_mout_mpll;
  153. rate = clk_get_rate(mout_mpll) / 1000;
  154. mout_apll = clk_get(NULL, "mout_apll");
  155. if (IS_ERR(mout_apll))
  156. goto err_mout_apll;
  157. if (soc_is_exynos4212())
  158. apll_freq_4x12 = apll_freq_4212;
  159. else
  160. apll_freq_4x12 = apll_freq_4412;
  161. info->mpll_freq_khz = rate;
  162. /* 800Mhz */
  163. info->pll_safe_idx = L7;
  164. info->cpu_clk = cpu_clk;
  165. info->volt_table = exynos4x12_volt_table;
  166. info->freq_table = exynos4x12_freq_table;
  167. info->set_freq = exynos4x12_set_frequency;
  168. return 0;
  169. err_mout_apll:
  170. clk_put(mout_mpll);
  171. err_mout_mpll:
  172. clk_put(moutcore);
  173. err_moutcore:
  174. clk_put(cpu_clk);
  175. pr_debug("%s: failed initialization\n", __func__);
  176. return -EINVAL;
  177. }