cpufreq-s3c2410.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/clock.h>
  26. #include <plat/cpu-freq-core.h>
  27. /* Note, 2410A has an extra mode for 1:4:4 ratio, bit 2 of CLKDIV */
  28. static void s3c2410_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
  29. {
  30. u32 clkdiv = 0;
  31. if (cfg->divs.h_divisor == 2)
  32. clkdiv |= S3C2410_CLKDIVN_HDIVN;
  33. if (cfg->divs.p_divisor != cfg->divs.h_divisor)
  34. clkdiv |= S3C2410_CLKDIVN_PDIVN;
  35. __raw_writel(clkdiv, S3C2410_CLKDIVN);
  36. }
  37. static int s3c2410_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
  38. {
  39. unsigned long hclk, fclk, pclk;
  40. unsigned int hdiv, pdiv;
  41. unsigned long hclk_max;
  42. fclk = cfg->freq.fclk;
  43. hclk_max = cfg->max.hclk;
  44. cfg->freq.armclk = fclk;
  45. s3c_freq_dbg("%s: fclk is %lu, max hclk %lu\n",
  46. __func__, fclk, hclk_max);
  47. hdiv = (fclk > cfg->max.hclk) ? 2 : 1;
  48. hclk = fclk / hdiv;
  49. if (hclk > cfg->max.hclk) {
  50. s3c_freq_dbg("%s: hclk too big\n", __func__);
  51. return -EINVAL;
  52. }
  53. pdiv = (hclk > cfg->max.pclk) ? 2 : 1;
  54. pclk = hclk / pdiv;
  55. if (pclk > cfg->max.pclk) {
  56. s3c_freq_dbg("%s: pclk too big\n", __func__);
  57. return -EINVAL;
  58. }
  59. pdiv *= hdiv;
  60. /* record the result */
  61. cfg->divs.p_divisor = pdiv;
  62. cfg->divs.h_divisor = hdiv;
  63. return 0;
  64. }
  65. static struct s3c_cpufreq_info s3c2410_cpufreq_info = {
  66. .max = {
  67. .fclk = 200000000,
  68. .hclk = 100000000,
  69. .pclk = 50000000,
  70. },
  71. /* transition latency is about 5ms worst-case, so
  72. * set 10ms to be sure */
  73. .latency = 10000000,
  74. .locktime_m = 150,
  75. .locktime_u = 150,
  76. .locktime_bits = 12,
  77. .need_pll = 1,
  78. .name = "s3c2410",
  79. .calc_iotiming = s3c2410_iotiming_calc,
  80. .set_iotiming = s3c2410_iotiming_set,
  81. .get_iotiming = s3c2410_iotiming_get,
  82. .resume_clocks = s3c2410_setup_clocks,
  83. .set_fvco = s3c2410_set_fvco,
  84. .set_refresh = s3c2410_cpufreq_setrefresh,
  85. .set_divs = s3c2410_cpufreq_setdivs,
  86. .calc_divs = s3c2410_cpufreq_calcdivs,
  87. .debug_io_show = s3c_cpufreq_debugfs_call(s3c2410_iotiming_debugfs),
  88. };
  89. static int s3c2410_cpufreq_add(struct device *dev,
  90. struct subsys_interface *sif)
  91. {
  92. return s3c_cpufreq_register(&s3c2410_cpufreq_info);
  93. }
  94. static struct subsys_interface s3c2410_cpufreq_interface = {
  95. .name = "s3c2410_cpufreq",
  96. .subsys = &s3c2410_subsys,
  97. .add_dev = s3c2410_cpufreq_add,
  98. };
  99. static int __init s3c2410_cpufreq_init(void)
  100. {
  101. return subsys_interface_register(&s3c2410_cpufreq_interface);
  102. }
  103. arch_initcall(s3c2410_cpufreq_init);
  104. static int s3c2410a_cpufreq_add(struct device *dev,
  105. struct subsys_interface *sif)
  106. {
  107. /* alter the maximum freq settings for S3C2410A. If a board knows
  108. * it only has a maximum of 200, then it should register its own
  109. * limits. */
  110. s3c2410_cpufreq_info.max.fclk = 266000000;
  111. s3c2410_cpufreq_info.max.hclk = 133000000;
  112. s3c2410_cpufreq_info.max.pclk = 66500000;
  113. s3c2410_cpufreq_info.name = "s3c2410a";
  114. return s3c2410_cpufreq_add(dev, sif);
  115. }
  116. static struct subsys_interface s3c2410a_cpufreq_interface = {
  117. .name = "s3c2410a_cpufreq",
  118. .subsys = &s3c2410a_subsys,
  119. .add_dev = s3c2410a_cpufreq_add,
  120. };
  121. static int __init s3c2410a_cpufreq_init(void)
  122. {
  123. return subsys_interface_register(&s3c2410a_cpufreq_interface);
  124. }
  125. arch_initcall(s3c2410a_cpufreq_init);