memoryCall.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* linux/arch/arm/plat-s3c24xx/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. * S3C24XX 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/cpu.h>
  19. #include <linux/clk.h>
  20. #include <linux/err.h>
  21. #include <linux/io.h>
  22. #include <linux/device.h>
  23. #include <linux/sysfs.h>
  24. #include <linux/slab.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <plat/cpu.h>
  28. #include <plat/clock.h>
  29. #include <plat/cpu-freq-core.h>
  30. #include <mach/regs-clock.h>
  31. /* note, cpufreq support deals in kHz, no Hz */
  32. static struct cpufreq_driver s3c24xx_driver;
  33. static struct s3c_cpufreq_config cpu_cur;
  34. static struct s3c_iotimings s3c24xx_iotiming;
  35. static struct cpufreq_frequency_table *pll_reg;
  36. static unsigned int last_target = ~0;
  37. static unsigned int ftab_size;
  38. static struct cpufreq_frequency_table *ftab;
  39. static struct clk *_clk_mpll;
  40. static struct clk *_clk_xtal;
  41. static struct clk *clk_fclk;
  42. static struct clk *clk_hclk;
  43. static struct clk *clk_pclk;
  44. static struct clk *clk_arm;
  45. #ifdef CONFIG_CPU_FREQ_S3C24XX_DEBUGFS
  46. struct s3c_cpufreq_config *s3c_cpufreq_getconfig(void)
  47. {
  48. return &cpu_cur;
  49. }
  50. struct s3c_iotimings *s3c_cpufreq_getiotimings(void)
  51. {
  52. return &s3c24xx_iotiming;
  53. }
  54. #endif /* CONFIG_CPU_FREQ_S3C24XX_DEBUGFS */
  55. static void s3c_cpufreq_getcur(struct s3c_cpufreq_config *cfg)
  56. {
  57. unsigned long fclk, pclk, hclk, armclk;
  58. cfg->freq.fclk = fclk = clk_get_rate(clk_fclk);
  59. cfg->freq.hclk = hclk = clk_get_rate(clk_hclk);
  60. cfg->freq.pclk = pclk = clk_get_rate(clk_pclk);
  61. cfg->freq.armclk = armclk = clk_get_rate(clk_arm);
  62. cfg->pll.index = __raw_readl(S3C2410_MPLLCON);
  63. cfg->pll.frequency = fclk;
  64. cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
  65. cfg->divs.h_divisor = fclk / hclk;
  66. cfg->divs.p_divisor = fclk / pclk;
  67. }
  68. static inline void s3c_cpufreq_calc(struct s3c_cpufreq_config *cfg)
  69. {
  70. unsigned long pll = cfg->pll.frequency;
  71. cfg->freq.fclk = pll;
  72. cfg->freq.hclk = pll / cfg->divs.h_divisor;
  73. cfg->freq.pclk = pll / cfg->divs.p_divisor;
  74. /* convert hclk into 10ths of nanoseconds for io calcs */
  75. cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
  76. }
  77. static inline int closer(unsigned int target, unsigned int n, unsigned int c)
  78. {
  79. int diff_cur = abs(target - c);
  80. int diff_new = abs(target - n);
  81. return (diff_new < diff_cur);
  82. }
  83. static void s3c_cpufreq_show(const char *pfx,
  84. struct s3c_cpufreq_config *cfg)
  85. {
  86. s3c_freq_dbg("%s: Fvco=%u, F=%lu, A=%lu, H=%lu (%u), P=%lu (%u)\n",
  87. pfx, cfg->pll.frequency, cfg->freq.fclk, cfg->freq.armclk,
  88. cfg->freq.hclk, cfg->divs.h_divisor,
  89. cfg->freq.pclk, cfg->divs.p_divisor);
  90. }
  91. /* functions to wrapper the driver info calls to do the cpu specific work */
  92. static void s3c_cpufreq_setio(struct s3c_cpufreq_config *cfg)
  93. {
  94. if (cfg->info->set_iotiming)
  95. (cfg->info->set_iotiming)(cfg, &s3c24xx_iotiming);
  96. }
  97. static int s3c_cpufreq_calcio(struct s3c_cpufreq_config *cfg)
  98. {
  99. if (cfg->info->calc_iotiming)
  100. return (cfg->info->calc_iotiming)(cfg, &s3c24xx_iotiming);
  101. return 0;
  102. }
  103. static void s3c_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg)
  104. {
  105. (cfg->info->set_refresh)(cfg);
  106. }
  107. static void s3c_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
  108. {
  109. (cfg->info->set_divs)(cfg);
  110. }
  111. static int s3c_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
  112. {
  113. return (cfg->info->calc_divs)(cfg);
  114. }
  115. static void s3c_cpufreq_setfvco(struct s3c_cpufreq_config *cfg)
  116. {
  117. (cfg->info->set_fvco)(cfg);
  118. }
  119. static inline void s3c_cpufreq_resume_clocks(void)
  120. {
  121. cpu_cur.info->resume_clocks();
  122. }
  123. static inline void s3c_cpufreq_updateclk(struct clk *clk,
  124. unsigned int freq)
  125. {
  126. clk_set_rate(clk, freq);
  127. }