exynos4210-cpufreq.c 3.7 KB

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