exynos5250-cpufreq.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 <mach/regs-clock.h>
  20. #include "exynos-cpufreq.h"
  21. static struct clk *cpu_clk;
  22. static struct clk *moutcore;
  23. static struct clk *mout_mpll;
  24. static struct clk *mout_apll;
  25. static unsigned int exynos5250_volt_table[] = {
  26. 1300000, 1250000, 1225000, 1200000, 1150000,
  27. 1125000, 1100000, 1075000, 1050000, 1025000,
  28. 1012500, 1000000, 975000, 950000, 937500,
  29. 925000
  30. };
  31. static struct cpufreq_frequency_table exynos5250_freq_table[] = {
  32. {L0, 1700 * 1000},
  33. {L1, 1600 * 1000},
  34. {L2, 1500 * 1000},
  35. {L3, 1400 * 1000},
  36. {L4, 1300 * 1000},
  37. {L5, 1200 * 1000},
  38. {L6, 1100 * 1000},
  39. {L7, 1000 * 1000},
  40. {L8, 900 * 1000},
  41. {L9, 800 * 1000},
  42. {L10, 700 * 1000},
  43. {L11, 600 * 1000},
  44. {L12, 500 * 1000},
  45. {L13, 400 * 1000},
  46. {L14, 300 * 1000},
  47. {L15, 200 * 1000},
  48. {0, CPUFREQ_TABLE_END},
  49. };
  50. static struct apll_freq apll_freq_5250[] = {
  51. /*
  52. * values:
  53. * freq
  54. * clock divider for ARM, CPUD, ACP, PERIPH, ATB, PCLK_DBG, APLL, ARM2
  55. * clock divider for COPY, HPM, RESERVED
  56. * PLL M, P, S
  57. */
  58. APLL_FREQ(1700, 0, 3, 7, 7, 7, 3, 5, 0, 0, 2, 0, 425, 6, 0),
  59. APLL_FREQ(1600, 0, 3, 7, 7, 7, 1, 4, 0, 0, 2, 0, 200, 3, 0),
  60. APLL_FREQ(1500, 0, 2, 7, 7, 7, 1, 4, 0, 0, 2, 0, 250, 4, 0),
  61. APLL_FREQ(1400, 0, 2, 7, 7, 6, 1, 4, 0, 0, 2, 0, 175, 3, 0),
  62. APLL_FREQ(1300, 0, 2, 7, 7, 6, 1, 3, 0, 0, 2, 0, 325, 6, 0),
  63. APLL_FREQ(1200, 0, 2, 7, 7, 5, 1, 3, 0, 0, 2, 0, 200, 4, 0),
  64. APLL_FREQ(1100, 0, 3, 7, 7, 5, 1, 3, 0, 0, 2, 0, 275, 6, 0),
  65. APLL_FREQ(1000, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 125, 3, 0),
  66. APLL_FREQ(900, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 150, 4, 0),
  67. APLL_FREQ(800, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 100, 3, 0),
  68. APLL_FREQ(700, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 175, 3, 1),
  69. APLL_FREQ(600, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 200, 4, 1),
  70. APLL_FREQ(500, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 125, 3, 1),
  71. APLL_FREQ(400, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 100, 3, 1),
  72. APLL_FREQ(300, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 200, 4, 2),
  73. APLL_FREQ(200, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 100, 3, 2),
  74. };
  75. static void set_clkdiv(unsigned int div_index)
  76. {
  77. unsigned int tmp;
  78. /* Change Divider - CPU0 */
  79. tmp = apll_freq_5250[div_index].clk_div_cpu0;
  80. __raw_writel(tmp, EXYNOS5_CLKDIV_CPU0);
  81. while (__raw_readl(EXYNOS5_CLKDIV_STATCPU0) & 0x11111111)
  82. cpu_relax();
  83. /* Change Divider - CPU1 */
  84. tmp = apll_freq_5250[div_index].clk_div_cpu1;
  85. __raw_writel(tmp, EXYNOS5_CLKDIV_CPU1);
  86. while (__raw_readl(EXYNOS5_CLKDIV_STATCPU1) & 0x11)
  87. cpu_relax();
  88. }
  89. static void set_apll(unsigned int new_index,
  90. unsigned int old_index)
  91. {
  92. unsigned int tmp, pdiv;
  93. /* 1. MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  94. clk_set_parent(moutcore, mout_mpll);
  95. do {
  96. cpu_relax();
  97. tmp = (__raw_readl(EXYNOS5_CLKMUX_STATCPU) >> 16);
  98. tmp &= 0x7;
  99. } while (tmp != 0x2);
  100. /* 2. Set APLL Lock time */
  101. pdiv = ((apll_freq_5250[new_index].mps >> 8) & 0x3f);
  102. __raw_writel((pdiv * 250), EXYNOS5_APLL_LOCK);
  103. /* 3. Change PLL PMS values */
  104. tmp = __raw_readl(EXYNOS5_APLL_CON0);
  105. tmp &= ~((0x3ff << 16) | (0x3f << 8) | (0x7 << 0));
  106. tmp |= apll_freq_5250[new_index].mps;
  107. __raw_writel(tmp, EXYNOS5_APLL_CON0);
  108. /* 4. wait_lock_time */
  109. do {
  110. cpu_relax();
  111. tmp = __raw_readl(EXYNOS5_APLL_CON0);
  112. } while (!(tmp & (0x1 << 29)));
  113. /* 5. MUX_CORE_SEL = APLL */
  114. clk_set_parent(moutcore, mout_apll);
  115. do {
  116. cpu_relax();
  117. tmp = __raw_readl(EXYNOS5_CLKMUX_STATCPU);
  118. tmp &= (0x7 << 16);
  119. } while (tmp != (0x1 << 16));
  120. }
  121. static bool exynos5250_pms_change(unsigned int old_index, unsigned int new_index)
  122. {
  123. unsigned int old_pm = apll_freq_5250[old_index].mps >> 8;
  124. unsigned int new_pm = apll_freq_5250[new_index].mps >> 8;
  125. return (old_pm == new_pm) ? 0 : 1;
  126. }
  127. static void exynos5250_set_frequency(unsigned int old_index,
  128. unsigned int new_index)
  129. {
  130. unsigned int tmp;
  131. if (old_index > new_index) {
  132. if (!exynos5250_pms_change(old_index, new_index)) {
  133. /* 1. Change the system clock divider values */
  134. set_clkdiv(new_index);
  135. /* 2. Change just s value in apll m,p,s value */
  136. tmp = __raw_readl(EXYNOS5_APLL_CON0);
  137. tmp &= ~(0x7 << 0);
  138. tmp |= apll_freq_5250[new_index].mps & 0x7;
  139. __raw_writel(tmp, EXYNOS5_APLL_CON0);
  140. } else {
  141. /* Clock Configuration Procedure */
  142. /* 1. Change the system clock divider values */
  143. set_clkdiv(new_index);
  144. /* 2. Change the apll m,p,s value */
  145. set_apll(new_index, old_index);
  146. }
  147. } else if (old_index < new_index) {
  148. if (!exynos5250_pms_change(old_index, new_index)) {
  149. /* 1. Change just s value in apll m,p,s value */
  150. tmp = __raw_readl(EXYNOS5_APLL_CON0);
  151. tmp &= ~(0x7 << 0);
  152. tmp |= apll_freq_5250[new_index].mps & 0x7;
  153. __raw_writel(tmp, EXYNOS5_APLL_CON0);
  154. /* 2. Change the system clock divider values */
  155. set_clkdiv(new_index);
  156. } else {
  157. /* Clock Configuration Procedure */
  158. /* 1. Change the apll m,p,s value */
  159. set_apll(new_index, old_index);
  160. /* 2. Change the system clock divider values */
  161. set_clkdiv(new_index);
  162. }
  163. }
  164. }
  165. int exynos5250_cpufreq_init(struct exynos_dvfs_info *info)
  166. {
  167. unsigned long rate;
  168. cpu_clk = clk_get(NULL, "armclk");
  169. if (IS_ERR(cpu_clk))
  170. return PTR_ERR(cpu_clk);
  171. moutcore = clk_get(NULL, "mout_cpu");
  172. if (IS_ERR(moutcore))
  173. goto err_moutcore;
  174. mout_mpll = clk_get(NULL, "mout_mpll");
  175. if (IS_ERR(mout_mpll))
  176. goto err_mout_mpll;
  177. rate = clk_get_rate(mout_mpll) / 1000;
  178. mout_apll = clk_get(NULL, "mout_apll");
  179. if (IS_ERR(mout_apll))
  180. goto err_mout_apll;
  181. info->mpll_freq_khz = rate;
  182. /* 800Mhz */
  183. info->pll_safe_idx = L9;
  184. info->cpu_clk = cpu_clk;
  185. info->volt_table = exynos5250_volt_table;
  186. info->freq_table = exynos5250_freq_table;
  187. info->set_freq = exynos5250_set_frequency;
  188. info->need_apll_change = exynos5250_pms_change;
  189. return 0;
  190. err_mout_apll:
  191. clk_put(mout_mpll);
  192. err_mout_mpll:
  193. clk_put(moutcore);
  194. err_moutcore:
  195. clk_put(cpu_clk);
  196. pr_err("%s: failed initialization\n", __func__);
  197. return -EINVAL;
  198. }
  199. EXPORT_SYMBOL(exynos5250_cpufreq_init);