cpu-freq.c 3.7 KB

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