exynos5250-cpufreq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 <linux/of.h>
  19. #include <linux/of_address.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 struct exynos_dvfs_info *cpufreq;
  26. static unsigned int exynos5250_volt_table[] = {
  27. 1300000, 1250000, 1225000, 1200000, 1150000,
  28. 1125000, 1100000, 1075000, 1050000, 1025000,
  29. 1012500, 1000000, 975000, 950000, 937500,
  30. 925000
  31. };
  32. static struct cpufreq_frequency_table exynos5250_freq_table[] = {
  33. {0, L0, 1700 * 1000},
  34. {0, L1, 1600 * 1000},
  35. {0, L2, 1500 * 1000},
  36. {0, L3, 1400 * 1000},
  37. {0, L4, 1300 * 1000},
  38. {0, L5, 1200 * 1000},
  39. {0, L6, 1100 * 1000},
  40. {0, L7, 1000 * 1000},
  41. {0, L8, 900 * 1000},
  42. {0, L9, 800 * 1000},
  43. {0, L10, 700 * 1000},
  44. {0, L11, 600 * 1000},
  45. {0, L12, 500 * 1000},
  46. {0, L13, 400 * 1000},
  47. {0, L14, 300 * 1000},
  48. {0, L15, 200 * 1000},
  49. {0, 0, CPUFREQ_TABLE_END},
  50. };
  51. static struct apll_freq apll_freq_5250[] = {
  52. /*
  53. * values:
  54. * freq
  55. * clock divider for ARM, CPUD, ACP, PERIPH, ATB, PCLK_DBG, APLL, ARM2
  56. * clock divider for COPY, HPM, RESERVED
  57. * PLL M, P, S
  58. */
  59. APLL_FREQ(1700, 0, 3, 7, 7, 7, 3, 5, 0, 0, 2, 0, 425, 6, 0),
  60. APLL_FREQ(1600, 0, 3, 7, 7, 7, 1, 4, 0, 0, 2, 0, 200, 3, 0),
  61. APLL_FREQ(1500, 0, 2, 7, 7, 7, 1, 4, 0, 0, 2, 0, 250, 4, 0),
  62. APLL_FREQ(1400, 0, 2, 7, 7, 6, 1, 4, 0, 0, 2, 0, 175, 3, 0),
  63. APLL_FREQ(1300, 0, 2, 7, 7, 6, 1, 3, 0, 0, 2, 0, 325, 6, 0),
  64. APLL_FREQ(1200, 0, 2, 7, 7, 5, 1, 3, 0, 0, 2, 0, 200, 4, 0),
  65. APLL_FREQ(1100, 0, 3, 7, 7, 5, 1, 3, 0, 0, 2, 0, 275, 6, 0),
  66. APLL_FREQ(1000, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 125, 3, 0),
  67. APLL_FREQ(900, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 150, 4, 0),
  68. APLL_FREQ(800, 0, 1, 7, 7, 4, 1, 2, 0, 0, 2, 0, 100, 3, 0),
  69. APLL_FREQ(700, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 175, 3, 1),
  70. APLL_FREQ(600, 0, 1, 7, 7, 3, 1, 1, 0, 0, 2, 0, 200, 4, 1),
  71. APLL_FREQ(500, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 125, 3, 1),
  72. APLL_FREQ(400, 0, 1, 7, 7, 2, 1, 1, 0, 0, 2, 0, 100, 3, 1),
  73. APLL_FREQ(300, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 200, 4, 2),
  74. APLL_FREQ(200, 0, 1, 7, 7, 1, 1, 1, 0, 0, 2, 0, 100, 3, 2),
  75. };
  76. static void set_clkdiv(unsigned int div_index)
  77. {
  78. unsigned int tmp;
  79. /* Change Divider - CPU0 */
  80. tmp = apll_freq_5250[div_index].clk_div_cpu0;
  81. __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS5_CLKDIV_CPU0);
  82. while (__raw_readl(cpufreq->cmu_regs + EXYNOS5_CLKDIV_STATCPU0)
  83. & 0x11111111)
  84. cpu_relax();
  85. /* Change Divider - CPU1 */
  86. tmp = apll_freq_5250[div_index].clk_div_cpu1;
  87. __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS5_CLKDIV_CPU1);
  88. while (__raw_readl(cpufreq->cmu_regs + EXYNOS5_CLKDIV_STATCPU1) & 0x11)
  89. cpu_relax();
  90. }
  91. static void set_apll(unsigned int index)
  92. {
  93. unsigned int tmp;
  94. unsigned int freq = apll_freq_5250[index].freq;
  95. /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  96. clk_set_parent(moutcore, mout_mpll);
  97. do {
  98. cpu_relax();
  99. tmp = (__raw_readl(cpufreq->cmu_regs + EXYNOS5_CLKMUX_STATCPU)
  100. >> 16);
  101. tmp &= 0x7;
  102. } while (tmp != 0x2);
  103. clk_set_rate(mout_apll, freq * 1000);
  104. /* MUX_CORE_SEL = APLL */
  105. clk_set_parent(moutcore, mout_apll);
  106. do {
  107. cpu_relax();
  108. tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS5_CLKMUX_STATCPU);
  109. tmp &= (0x7 << 16);
  110. } while (tmp != (0x1 << 16));
  111. }
  112. static void exynos5250_set_frequency(unsigned int old_index,
  113. unsigned int new_index)
  114. {
  115. if (old_index > new_index) {
  116. set_clkdiv(new_index);
  117. set_apll(new_index);
  118. } else if (old_index < new_index) {
  119. set_apll(new_index);
  120. set_clkdiv(new_index);
  121. }
  122. }
  123. int exynos5250_cpufreq_init(struct exynos_dvfs_info *info)
  124. {
  125. struct device_node *np;
  126. unsigned long rate;
  127. /*
  128. * HACK: This is a temporary workaround to get access to clock
  129. * controller registers directly and remove static mappings and
  130. * dependencies on platform headers. It is necessary to enable
  131. * Exynos multi-platform support and will be removed together with
  132. * this whole driver as soon as Exynos gets migrated to use
  133. * cpufreq-dt driver.
  134. */
  135. np = of_find_compatible_node(NULL, NULL, "samsung,exynos5250-clock");
  136. if (!np) {
  137. pr_err("%s: failed to find clock controller DT node\n",
  138. __func__);
  139. return -ENODEV;
  140. }
  141. info->cmu_regs = of_iomap(np, 0);
  142. if (!info->cmu_regs) {
  143. pr_err("%s: failed to map CMU registers\n", __func__);
  144. return -EFAULT;
  145. }
  146. cpu_clk = clk_get(NULL, "armclk");
  147. if (IS_ERR(cpu_clk))
  148. return PTR_ERR(cpu_clk);
  149. moutcore = clk_get(NULL, "mout_cpu");
  150. if (IS_ERR(moutcore))
  151. goto err_moutcore;
  152. mout_mpll = clk_get(NULL, "mout_mpll");
  153. if (IS_ERR(mout_mpll))
  154. goto err_mout_mpll;
  155. rate = clk_get_rate(mout_mpll) / 1000;
  156. mout_apll = clk_get(NULL, "mout_apll");
  157. if (IS_ERR(mout_apll))
  158. goto err_mout_apll;
  159. info->mpll_freq_khz = rate;
  160. /* 800Mhz */
  161. info->pll_safe_idx = L9;
  162. info->cpu_clk = cpu_clk;
  163. info->volt_table = exynos5250_volt_table;
  164. info->freq_table = exynos5250_freq_table;
  165. info->set_freq = exynos5250_set_frequency;
  166. cpufreq = info;
  167. return 0;
  168. err_mout_apll:
  169. clk_put(mout_mpll);
  170. err_mout_mpll:
  171. clk_put(moutcore);
  172. err_moutcore:
  173. clk_put(cpu_clk);
  174. pr_err("%s: failed initialization\n", __func__);
  175. return -EINVAL;
  176. }