exynos4x12-cpufreq.c 5.8 KB

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