exynos4210-cpufreq.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "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 exynos4210_volt_table[] = {
  24. 1250000, 1150000, 1050000, 975000, 950000,
  25. };
  26. static struct cpufreq_frequency_table exynos4210_freq_table[] = {
  27. {L0, 1200 * 1000},
  28. {L1, 1000 * 1000},
  29. {L2, 800 * 1000},
  30. {L3, 500 * 1000},
  31. {L4, 200 * 1000},
  32. {0, CPUFREQ_TABLE_END},
  33. };
  34. static struct apll_freq apll_freq_4210[] = {
  35. /*
  36. * values:
  37. * freq
  38. * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, RESERVED
  39. * clock divider for COPY, HPM, RESERVED
  40. * PLL M, P, S
  41. */
  42. APLL_FREQ(1200, 0, 3, 7, 3, 4, 1, 7, 0, 5, 0, 0, 150, 3, 1),
  43. APLL_FREQ(1000, 0, 3, 7, 3, 4, 1, 7, 0, 4, 0, 0, 250, 6, 1),
  44. APLL_FREQ(800, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 200, 6, 1),
  45. APLL_FREQ(500, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 250, 6, 2),
  46. APLL_FREQ(200, 0, 1, 3, 1, 3, 1, 0, 0, 3, 0, 0, 200, 6, 3),
  47. };
  48. static void exynos4210_set_clkdiv(unsigned int div_index)
  49. {
  50. unsigned int tmp;
  51. /* Change Divider - CPU0 */
  52. tmp = apll_freq_4210[div_index].clk_div_cpu0;
  53. __raw_writel(tmp, EXYNOS4_CLKDIV_CPU);
  54. do {
  55. tmp = __raw_readl(EXYNOS4_CLKDIV_STATCPU);
  56. } while (tmp & 0x1111111);
  57. /* Change Divider - CPU1 */
  58. tmp = apll_freq_4210[div_index].clk_div_cpu1;
  59. __raw_writel(tmp, EXYNOS4_CLKDIV_CPU1);
  60. do {
  61. tmp = __raw_readl(EXYNOS4_CLKDIV_STATCPU1);
  62. } while (tmp & 0x11);
  63. }
  64. static void exynos4210_set_apll(unsigned int index)
  65. {
  66. unsigned int tmp, freq = apll_freq_4210[index].freq;
  67. /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  68. clk_set_parent(moutcore, mout_mpll);
  69. do {
  70. tmp = (__raw_readl(EXYNOS4_CLKMUX_STATCPU)
  71. >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
  72. tmp &= 0x7;
  73. } while (tmp != 0x2);
  74. clk_set_rate(mout_apll, freq * 1000);
  75. /* MUX_CORE_SEL = APLL */
  76. clk_set_parent(moutcore, mout_apll);
  77. do {
  78. tmp = __raw_readl(EXYNOS4_CLKMUX_STATCPU);
  79. tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
  80. } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
  81. }
  82. static void exynos4210_set_frequency(unsigned int old_index,
  83. unsigned int new_index)
  84. {
  85. if (old_index > new_index) {
  86. exynos4210_set_clkdiv(new_index);
  87. exynos4210_set_apll(new_index);
  88. } else if (old_index < new_index) {
  89. exynos4210_set_apll(new_index);
  90. exynos4210_set_clkdiv(new_index);
  91. }
  92. }
  93. int exynos4210_cpufreq_init(struct exynos_dvfs_info *info)
  94. {
  95. unsigned long rate;
  96. cpu_clk = clk_get(NULL, "armclk");
  97. if (IS_ERR(cpu_clk))
  98. return PTR_ERR(cpu_clk);
  99. moutcore = clk_get(NULL, "moutcore");
  100. if (IS_ERR(moutcore))
  101. goto err_moutcore;
  102. mout_mpll = clk_get(NULL, "mout_mpll");
  103. if (IS_ERR(mout_mpll))
  104. goto err_mout_mpll;
  105. rate = clk_get_rate(mout_mpll) / 1000;
  106. mout_apll = clk_get(NULL, "mout_apll");
  107. if (IS_ERR(mout_apll))
  108. goto err_mout_apll;
  109. info->mpll_freq_khz = rate;
  110. /* 800Mhz */
  111. info->pll_safe_idx = L2;
  112. info->cpu_clk = cpu_clk;
  113. info->volt_table = exynos4210_volt_table;
  114. info->freq_table = exynos4210_freq_table;
  115. info->set_freq = exynos4210_set_frequency;
  116. return 0;
  117. err_mout_apll:
  118. clk_put(mout_mpll);
  119. err_mout_mpll:
  120. clk_put(moutcore);
  121. err_moutcore:
  122. clk_put(cpu_clk);
  123. pr_debug("%s: failed initialization\n", __func__);
  124. return -EINVAL;
  125. }