cpu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * File: arch/blackfin/mach-bf533/cpu.c
  3. * Based on:
  4. * Author: michael.kang@analog.com
  5. *
  6. * Created:
  7. * Description: clock scaling for the bf533
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/types.h>
  31. #include <linux/init.h>
  32. #include <linux/cpufreq.h>
  33. #include <asm/dpmc.h>
  34. #include <linux/fs.h>
  35. #include <asm/bfin-global.h>
  36. /* CONFIG_CLKIN_HZ=11059200 */
  37. #define VCO5 (CONFIG_CLKIN_HZ*45) /*497664000 */
  38. #define VCO4 (CONFIG_CLKIN_HZ*36) /*398131200 */
  39. #define VCO3 (CONFIG_CLKIN_HZ*27) /*298598400 */
  40. #define VCO2 (CONFIG_CLKIN_HZ*18) /*199065600 */
  41. #define VCO1 (CONFIG_CLKIN_HZ*9) /*99532800 */
  42. #define VCO(x) VCO##x
  43. #define FREQ(x) {VCO(x),VCO(x)/4},{VCO(x),VCO(x)/2},{VCO(x),VCO(x)}
  44. /* frequency */
  45. static struct cpufreq_frequency_table bf533_freq_table[] = {
  46. FREQ(1),
  47. FREQ(3),
  48. {VCO4, VCO4 / 2}, {VCO4, VCO4},
  49. FREQ(5),
  50. {0, CPUFREQ_TABLE_END},
  51. };
  52. /*
  53. * dpmc_fops->ioctl()
  54. * static int dpmc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  55. */
  56. static int bf533_getfreq(unsigned int cpu)
  57. {
  58. unsigned long cclk_mhz, vco_mhz;
  59. /* The driver only support single cpu */
  60. if (cpu == 0)
  61. dpmc_fops.ioctl(NULL, NULL, IOCTL_GET_CORECLOCK, &cclk_mhz);
  62. else
  63. cclk_mhz = -1;
  64. return cclk_mhz;
  65. }
  66. static int bf533_target(struct cpufreq_policy *policy,
  67. unsigned int target_freq, unsigned int relation)
  68. {
  69. unsigned long cclk_mhz;
  70. unsigned long vco_mhz;
  71. unsigned long flags;
  72. unsigned int index, vco_index;
  73. int i;
  74. struct cpufreq_freqs freqs;
  75. if (cpufreq_frequency_table_target
  76. (policy, bf533_freq_table, target_freq, relation, &index))
  77. return -EINVAL;
  78. cclk_mhz = bf533_freq_table[index].frequency;
  79. vco_mhz = bf533_freq_table[index].index;
  80. dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
  81. freqs.old = bf533_getfreq(0);
  82. freqs.new = cclk_mhz;
  83. freqs.cpu = 0;
  84. pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
  85. cclk_mhz, vco_mhz, index, target_freq, freqs.old);
  86. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  87. local_irq_save(flags);
  88. dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
  89. local_irq_restore(flags);
  90. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  91. vco_mhz = get_vco();
  92. cclk_mhz = get_cclk();
  93. return 0;
  94. }
  95. /* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
  96. * this platform, anyway.
  97. */
  98. static int bf533_verify_speed(struct cpufreq_policy *policy)
  99. {
  100. return cpufreq_frequency_table_verify(policy, &bf533_freq_table);
  101. }
  102. static int __init __bf533_cpu_init(struct cpufreq_policy *policy)
  103. {
  104. int result;
  105. if (policy->cpu != 0)
  106. return -EINVAL;
  107. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  108. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  109. /*Now ,only support one cpu */
  110. policy->cur = bf533_getfreq(0);
  111. cpufreq_frequency_table_get_attr(bf533_freq_table, policy->cpu);
  112. return cpufreq_frequency_table_cpuinfo(policy, bf533_freq_table);
  113. }
  114. static struct freq_attr *bf533_freq_attr[] = {
  115. &cpufreq_freq_attr_scaling_available_freqs,
  116. NULL,
  117. };
  118. static struct cpufreq_driver bf533_driver = {
  119. .verify = bf533_verify_speed,
  120. .target = bf533_target,
  121. .get = bf533_getfreq,
  122. .init = __bf533_cpu_init,
  123. .name = "bf533",
  124. .owner = THIS_MODULE,
  125. .attr = bf533_freq_attr,
  126. };
  127. static int __init bf533_cpu_init(void)
  128. {
  129. return cpufreq_register_driver(&bf533_driver);
  130. }
  131. static void __exit bf533_cpu_exit(void)
  132. {
  133. cpufreq_unregister_driver(&bf533_driver);
  134. }
  135. MODULE_AUTHOR("Mickael Kang");
  136. MODULE_DESCRIPTION("cpufreq driver for BF533 CPU");
  137. MODULE_LICENSE("GPL");
  138. module_init(bf533_cpu_init);
  139. module_exit(bf533_cpu_exit);