s3c2410-cpufreq.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2006-2008 Simtec Electronics
  3. * http://armlinux.simtec.co.uk/
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 CPU Frequency scaling
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/ioport.h>
  16. #include <linux/cpufreq.h>
  17. #include <linux/device.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/io.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/map.h>
  23. #include <mach/regs-clock.h>
  24. #include <plat/cpu.h>
  25. #include <plat/cpu-freq-core.h>
  26. /* Note, 2410A has an extra mode for 1:4:4 ratio, bit 2 of CLKDIV */
  27. static void s3c2410_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
  28. {
  29. u32 clkdiv = 0;
  30. if (cfg->divs.h_divisor == 2)
  31. clkdiv |= S3C2410_CLKDIVN_HDIVN;
  32. if (cfg->divs.p_divisor != cfg->divs.h_divisor)
  33. clkdiv |= S3C2410_CLKDIVN_PDIVN;
  34. __raw_writel(clkdiv, S3C2410_CLKDIVN);
  35. }
  36. static int s3c2410_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
  37. {
  38. unsigned long hclk, fclk, pclk;
  39. unsigned int hdiv, pdiv;
  40. unsigned long hclk_max;
  41. fclk = cfg->freq.fclk;
  42. hclk_max = cfg->max.hclk;
  43. cfg->freq.armclk = fclk;
  44. s3c_freq_dbg("%s: fclk is %lu, max hclk %lu\n",
  45. __func__, fclk, hclk_max);
  46. hdiv = (fclk > cfg->max.hclk) ? 2 : 1;
  47. hclk = fclk / hdiv;
  48. if (hclk > cfg->max.hclk) {
  49. s3c_freq_dbg("%s: hclk too big\n", __func__);
  50. return -EINVAL;
  51. }
  52. pdiv = (hclk > cfg->max.pclk) ? 2 : 1;
  53. pclk = hclk / pdiv;
  54. if (pclk > cfg->max.pclk) {
  55. s3c_freq_dbg("%s: pclk too big\n", __func__);
  56. return -EINVAL;
  57. }
  58. pdiv *= hdiv;
  59. /* record the result */
  60. cfg->divs.p_divisor = pdiv;
  61. cfg->divs.h_divisor = hdiv;
  62. return 0;
  63. }
  64. static struct s3c_cpufreq_info s3c2410_cpufreq_info = {
  65. .max = {
  66. .fclk = 200000000,
  67. .hclk = 100000000,
  68. .pclk = 50000000,
  69. },
  70. /* transition latency is about 5ms worst-case, so
  71. * set 10ms to be sure */
  72. .latency = 10000000,
  73. .locktime_m = 150,
  74. .locktime_u = 150,
  75. .locktime_bits = 12,
  76. .need_pll = 1,
  77. .name = "s3c2410",
  78. .calc_iotiming = s3c2410_iotiming_calc,
  79. .set_iotiming = s3c2410_iotiming_set,
  80. .get_iotiming = s3c2410_iotiming_get,
  81. .set_fvco = s3c2410_set_fvco,
  82. .set_refresh = s3c2410_cpufreq_setrefresh,
  83. .set_divs = s3c2410_cpufreq_setdivs,
  84. .calc_divs = s3c2410_cpufreq_calcdivs,
  85. .debug_io_show = s3c_cpufreq_debugfs_call(s3c2410_iotiming_debugfs),
  86. };
  87. static int s3c2410_cpufreq_add(struct device *dev,
  88. struct subsys_interface *sif)
  89. {
  90. return s3c_cpufreq_register(&s3c2410_cpufreq_info);
  91. }
  92. static struct subsys_interface s3c2410_cpufreq_interface = {
  93. .name = "s3c2410_cpufreq",
  94. .subsys = &s3c2410_subsys,
  95. .add_dev = s3c2410_cpufreq_add,
  96. };
  97. static int __init s3c2410_cpufreq_init(void)
  98. {
  99. return subsys_interface_register(&s3c2410_cpufreq_interface);
  100. }
  101. arch_initcall(s3c2410_cpufreq_init);
  102. static int s3c2410a_cpufreq_add(struct device *dev,
  103. struct subsys_interface *sif)
  104. {
  105. /* alter the maximum freq settings for S3C2410A. If a board knows
  106. * it only has a maximum of 200, then it should register its own
  107. * limits. */
  108. s3c2410_cpufreq_info.max.fclk = 266000000;
  109. s3c2410_cpufreq_info.max.hclk = 133000000;
  110. s3c2410_cpufreq_info.max.pclk = 66500000;
  111. s3c2410_cpufreq_info.name = "s3c2410a";
  112. return s3c2410_cpufreq_add(dev, sif);
  113. }
  114. static struct subsys_interface s3c2410a_cpufreq_interface = {
  115. .name = "s3c2410a_cpufreq",
  116. .subsys = &s3c2410a_subsys,
  117. .add_dev = s3c2410a_cpufreq_add,
  118. };
  119. static int __init s3c2410a_cpufreq_init(void)
  120. {
  121. return subsys_interface_register(&s3c2410a_cpufreq_interface);
  122. }
  123. arch_initcall(s3c2410a_cpufreq_init);