cpu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * File: arch/blackfin/mach-bf537/cpu.c
  3. * Based on:
  4. * Author: michael.kang@analog.com
  5. *
  6. * Created:
  7. * Description: clock scaling for the bf537
  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 MFREQ(x) {VCO(x),VCO(x)/4},{VCO(x),VCO(x)/2},{VCO(x),VCO(x)}
  44. /* frequency */
  45. static struct cpufreq_frequency_table bf537_freq_table[] = {
  46. MFREQ(1),
  47. MFREQ(3),
  48. {VCO4, VCO4 / 2}, {VCO4, VCO4},
  49. MFREQ(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 bf537_getfreq(unsigned int cpu)
  57. {
  58. unsigned long cclk_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 bf537_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;
  73. struct cpufreq_freqs freqs;
  74. if (cpufreq_frequency_table_target(policy, bf537_freq_table, target_freq, relation, &index))
  75. return -EINVAL;
  76. cclk_mhz = bf537_freq_table[index].frequency;
  77. vco_mhz = bf537_freq_table[index].index;
  78. dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
  79. freqs.old = bf537_getfreq(0);
  80. freqs.new = cclk_mhz;
  81. freqs.cpu = 0;
  82. pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
  83. cclk_mhz, vco_mhz, index, target_freq, freqs.old);
  84. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  85. local_irq_save(flags);
  86. dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
  87. local_irq_restore(flags);
  88. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  89. vco_mhz = get_vco();
  90. cclk_mhz = get_cclk();
  91. return 0;
  92. }
  93. /* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
  94. * this platform, anyway.
  95. */
  96. static int bf537_verify_speed(struct cpufreq_policy *policy)
  97. {
  98. return cpufreq_frequency_table_verify(policy, &bf537_freq_table);
  99. }
  100. static int __init __bf537_cpu_init(struct cpufreq_policy *policy)
  101. {
  102. if (policy->cpu != 0)
  103. return -EINVAL;
  104. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  105. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  106. /*Now ,only support one cpu */
  107. policy->cur = bf537_getfreq(0);
  108. cpufreq_frequency_table_get_attr(bf537_freq_table, policy->cpu);
  109. return cpufreq_frequency_table_cpuinfo(policy, bf537_freq_table);
  110. }
  111. static struct freq_attr *bf537_freq_attr[] = {
  112. &cpufreq_freq_attr_scaling_available_freqs,
  113. NULL,
  114. };
  115. static struct cpufreq_driver bf537_driver = {
  116. .verify = bf537_verify_speed,
  117. .target = bf537_target,
  118. .get = bf537_getfreq,
  119. .init = __bf537_cpu_init,
  120. .name = "bf537",
  121. .owner = THIS_MODULE,
  122. .attr = bf537_freq_attr,
  123. };
  124. static int __init bf537_cpu_init(void)
  125. {
  126. return cpufreq_register_driver(&bf537_driver);
  127. }
  128. static void __exit bf537_cpu_exit(void)
  129. {
  130. cpufreq_unregister_driver(&bf537_driver);
  131. }
  132. MODULE_AUTHOR("Mickael Kang");
  133. MODULE_DESCRIPTION("cpufreq driver for BF537 CPU");
  134. MODULE_LICENSE("GPL");
  135. module_init(bf537_cpu_init);
  136. module_exit(bf537_cpu_exit);