exynos4210-cpufreq.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS4210 - 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 exynos4210_volt_table[] = {
  27. 1250000, 1150000, 1050000, 975000, 950000,
  28. };
  29. static struct cpufreq_frequency_table exynos4210_freq_table[] = {
  30. {0, L0, 1200 * 1000},
  31. {0, L1, 1000 * 1000},
  32. {0, L2, 800 * 1000},
  33. {0, L3, 500 * 1000},
  34. {0, L4, 200 * 1000},
  35. {0, 0, CPUFREQ_TABLE_END},
  36. };
  37. static struct apll_freq apll_freq_4210[] = {
  38. /*
  39. * values:
  40. * freq
  41. * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, RESERVED
  42. * clock divider for COPY, HPM, RESERVED
  43. * PLL M, P, S
  44. */
  45. APLL_FREQ(1200, 0, 3, 7, 3, 4, 1, 7, 0, 5, 0, 0, 150, 3, 1),
  46. APLL_FREQ(1000, 0, 3, 7, 3, 4, 1, 7, 0, 4, 0, 0, 250, 6, 1),
  47. APLL_FREQ(800, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 200, 6, 1),
  48. APLL_FREQ(500, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 250, 6, 2),
  49. APLL_FREQ(200, 0, 1, 3, 1, 3, 1, 0, 0, 3, 0, 0, 200, 6, 3),
  50. };
  51. static void exynos4210_set_clkdiv(unsigned int div_index)
  52. {
  53. unsigned int tmp;
  54. /* Change Divider - CPU0 */
  55. tmp = apll_freq_4210[div_index].clk_div_cpu0;
  56. __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS4_CLKDIV_CPU);
  57. do {
  58. tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKDIV_STATCPU);
  59. } while (tmp & 0x1111111);
  60. /* Change Divider - CPU1 */
  61. tmp = apll_freq_4210[div_index].clk_div_cpu1;
  62. __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS4_CLKDIV_CPU1);
  63. do {
  64. tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKDIV_STATCPU1);
  65. } while (tmp & 0x11);
  66. }
  67. static void exynos4210_set_apll(unsigned int index)
  68. {
  69. unsigned int tmp, freq = apll_freq_4210[index].freq;
  70. /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  71. clk_set_parent(moutcore, mout_mpll);
  72. do {
  73. tmp = (__raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKMUX_STATCPU)
  74. >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
  75. tmp &= 0x7;
  76. } while (tmp != 0x2);
  77. clk_set_rate(mout_apll, freq * 1000);
  78. /* MUX_CORE_SEL = APLL */
  79. clk_set_parent(moutcore, mout_apll);
  80. do {
  81. tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKMUX_STATCPU);
  82. tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
  83. } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
  84. }
  85. static void exynos4210_set_frequency(unsigned int old_index,
  86. unsigned int new_index)
  87. {
  88. if (old_index > new_index) {
  89. exynos4210_set_clkdiv(new_index);
  90. exynos4210_set_apll(new_index);
  91. } else if (old_index < new_index) {
  92. exynos4210_set_apll(new_index);
  93. exynos4210_set_clkdiv(new_index);
  94. }
  95. }
  96. int exynos4210_cpufreq_init(struct exynos_dvfs_info *info)
  97. {
  98. struct device_node *np;
  99. unsigned long rate;
  100. /*
  101. * HACK: This is a temporary workaround to get access to clock
  102. * controller registers directly and remove static mappings and
  103. * dependencies on platform headers. It is necessary to enable
  104. * Exynos multi-platform support and will be removed together with
  105. * this whole driver as soon as Exynos gets migrated to use
  106. * cpufreq-cpu0 driver.
  107. */
  108. np = of_find_compatible_node(NULL, NULL, "samsung,exynos4210-clock");
  109. if (!np) {
  110. pr_err("%s: failed to find clock controller DT node\n",
  111. __func__);
  112. return -ENODEV;
  113. }
  114. info->cmu_regs = of_iomap(np, 0);
  115. if (!info->cmu_regs) {
  116. pr_err("%s: failed to map CMU registers\n", __func__);
  117. return -EFAULT;
  118. }
  119. cpu_clk = clk_get(NULL, "armclk");
  120. if (IS_ERR(cpu_clk))
  121. return PTR_ERR(cpu_clk);
  122. moutcore = clk_get(NULL, "moutcore");
  123. if (IS_ERR(moutcore))
  124. goto err_moutcore;
  125. mout_mpll = clk_get(NULL, "mout_mpll");
  126. if (IS_ERR(mout_mpll))
  127. goto err_mout_mpll;
  128. rate = clk_get_rate(mout_mpll) / 1000;
  129. mout_apll = clk_get(NULL, "mout_apll");
  130. if (IS_ERR(mout_apll))
  131. goto err_mout_apll;
  132. info->mpll_freq_khz = rate;
  133. /* 800Mhz */
  134. info->pll_safe_idx = L2;
  135. info->cpu_clk = cpu_clk;
  136. info->volt_table = exynos4210_volt_table;
  137. info->freq_table = exynos4210_freq_table;
  138. info->set_freq = exynos4210_set_frequency;
  139. cpufreq = info;
  140. return 0;
  141. err_mout_apll:
  142. clk_put(mout_mpll);
  143. err_mout_mpll:
  144. clk_put(moutcore);
  145. err_moutcore:
  146. clk_put(cpu_clk);
  147. pr_debug("%s: failed initialization\n", __func__);
  148. return -EINVAL;
  149. }