cpu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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(policy, bf533_freq_table, target_freq, relation, &index))
  76. return -EINVAL;
  77. cclk_mhz = bf533_freq_table[index].frequency;
  78. vco_mhz = bf533_freq_table[index].index;
  79. dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
  80. freqs.old = bf533_getfreq(0);
  81. freqs.new = cclk_mhz;
  82. freqs.cpu = 0;
  83. pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
  84. cclk_mhz, vco_mhz, index, target_freq, freqs.old);
  85. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  86. local_irq_save(flags);
  87. dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
  88. local_irq_restore(flags);
  89. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  90. vco_mhz = get_vco();
  91. cclk_mhz = get_cclk();
  92. return 0;
  93. }
  94. /* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
  95. * this platform, anyway.
  96. */
  97. static int bf533_verify_speed(struct cpufreq_policy *policy)
  98. {
  99. return cpufreq_frequency_table_verify(policy, &bf533_freq_table);
  100. }
  101. static int __init __bf533_cpu_init(struct cpufreq_policy *policy)
  102. {
  103. int result;
  104. if (policy->cpu != 0)
  105. return -EINVAL;
  106. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  107. /*Now ,only support one cpu */
  108. policy->cur = bf533_getfreq(0);
  109. cpufreq_frequency_table_get_attr(bf533_freq_table, policy->cpu);
  110. return cpufreq_frequency_table_cpuinfo(policy, bf533_freq_table);
  111. }
  112. static struct freq_attr *bf533_freq_attr[] = {
  113. &cpufreq_freq_attr_scaling_available_freqs,
  114. NULL,
  115. };
  116. static struct cpufreq_driver bf533_driver = {
  117. .verify = bf533_verify_speed,
  118. .target = bf533_target,
  119. .get = bf533_getfreq,
  120. .init = __bf533_cpu_init,
  121. .name = "bf533",
  122. .owner = THIS_MODULE,
  123. .attr = bf533_freq_attr,
  124. };
  125. static int __init bf533_cpu_init(void)
  126. {
  127. return cpufreq_register_driver(&bf533_driver);
  128. }
  129. static void __exit bf533_cpu_exit(void)
  130. {
  131. cpufreq_unregister_driver(&bf533_driver);
  132. }
  133. MODULE_AUTHOR("Mickael Kang");
  134. MODULE_DESCRIPTION("cpufreq driver for BF533 CPU");
  135. MODULE_LICENSE("GPL");
  136. module_init(bf533_cpu_init);
  137. module_exit(bf533_cpu_exit);