integrator-cpufreq.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * CPU support functions
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/cpufreq.h>
  14. #include <linux/sched.h>
  15. #include <linux/smp.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <mach/hardware.h>
  19. #include <mach/platform.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/hardware/icst.h>
  22. static struct cpufreq_driver integrator_driver;
  23. #define CM_ID __io_address(INTEGRATOR_HDR_ID)
  24. #define CM_OSC __io_address(INTEGRATOR_HDR_OSC)
  25. #define CM_STAT __io_address(INTEGRATOR_HDR_STAT)
  26. #define CM_LOCK __io_address(INTEGRATOR_HDR_LOCK)
  27. static const struct icst_params lclk_params = {
  28. .ref = 24000000,
  29. .vco_max = ICST525_VCO_MAX_5V,
  30. .vco_min = ICST525_VCO_MIN,
  31. .vd_min = 8,
  32. .vd_max = 132,
  33. .rd_min = 24,
  34. .rd_max = 24,
  35. .s2div = icst525_s2div,
  36. .idx2s = icst525_idx2s,
  37. };
  38. static const struct icst_params cclk_params = {
  39. .ref = 24000000,
  40. .vco_max = ICST525_VCO_MAX_5V,
  41. .vco_min = ICST525_VCO_MIN,
  42. .vd_min = 12,
  43. .vd_max = 160,
  44. .rd_min = 24,
  45. .rd_max = 24,
  46. .s2div = icst525_s2div,
  47. .idx2s = icst525_idx2s,
  48. };
  49. /*
  50. * Validate the speed policy.
  51. */
  52. static int integrator_verify_policy(struct cpufreq_policy *policy)
  53. {
  54. struct icst_vco vco;
  55. cpufreq_verify_within_limits(policy,
  56. policy->cpuinfo.min_freq,
  57. policy->cpuinfo.max_freq);
  58. vco = icst_hz_to_vco(&cclk_params, policy->max * 1000);
  59. policy->max = icst_hz(&cclk_params, vco) / 1000;
  60. vco = icst_hz_to_vco(&cclk_params, policy->min * 1000);
  61. policy->min = icst_hz(&cclk_params, vco) / 1000;
  62. cpufreq_verify_within_limits(policy,
  63. policy->cpuinfo.min_freq,
  64. policy->cpuinfo.max_freq);
  65. return 0;
  66. }
  67. static int integrator_set_target(struct cpufreq_policy *policy,
  68. unsigned int target_freq,
  69. unsigned int relation)
  70. {
  71. cpumask_t cpus_allowed;
  72. int cpu = policy->cpu;
  73. struct icst_vco vco;
  74. struct cpufreq_freqs freqs;
  75. u_int cm_osc;
  76. /*
  77. * Save this threads cpus_allowed mask.
  78. */
  79. cpus_allowed = current->cpus_allowed;
  80. /*
  81. * Bind to the specified CPU. When this call returns,
  82. * we should be running on the right CPU.
  83. */
  84. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  85. BUG_ON(cpu != smp_processor_id());
  86. /* get current setting */
  87. cm_osc = __raw_readl(CM_OSC);
  88. if (machine_is_integrator()) {
  89. vco.s = (cm_osc >> 8) & 7;
  90. } else if (machine_is_cintegrator()) {
  91. vco.s = 1;
  92. }
  93. vco.v = cm_osc & 255;
  94. vco.r = 22;
  95. freqs.old = icst_hz(&cclk_params, vco) / 1000;
  96. /* icst_hz_to_vco rounds down -- so we need the next
  97. * larger freq in case of CPUFREQ_RELATION_L.
  98. */
  99. if (relation == CPUFREQ_RELATION_L)
  100. target_freq += 999;
  101. if (target_freq > policy->max)
  102. target_freq = policy->max;
  103. vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
  104. freqs.new = icst_hz(&cclk_params, vco) / 1000;
  105. if (freqs.old == freqs.new) {
  106. set_cpus_allowed(current, cpus_allowed);
  107. return 0;
  108. }
  109. cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
  110. cm_osc = __raw_readl(CM_OSC);
  111. if (machine_is_integrator()) {
  112. cm_osc &= 0xfffff800;
  113. cm_osc |= vco.s << 8;
  114. } else if (machine_is_cintegrator()) {
  115. cm_osc &= 0xffffff00;
  116. }
  117. cm_osc |= vco.v;
  118. __raw_writel(0xa05f, CM_LOCK);
  119. __raw_writel(cm_osc, CM_OSC);
  120. __raw_writel(0, CM_LOCK);
  121. /*
  122. * Restore the CPUs allowed mask.
  123. */
  124. set_cpus_allowed(current, cpus_allowed);
  125. cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
  126. return 0;
  127. }
  128. static unsigned int integrator_get(unsigned int cpu)
  129. {
  130. cpumask_t cpus_allowed;
  131. unsigned int current_freq;
  132. u_int cm_osc;
  133. struct icst_vco vco;
  134. cpus_allowed = current->cpus_allowed;
  135. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  136. BUG_ON(cpu != smp_processor_id());
  137. /* detect memory etc. */
  138. cm_osc = __raw_readl(CM_OSC);
  139. if (machine_is_integrator()) {
  140. vco.s = (cm_osc >> 8) & 7;
  141. } else {
  142. vco.s = 1;
  143. }
  144. vco.v = cm_osc & 255;
  145. vco.r = 22;
  146. current_freq = icst_hz(&cclk_params, vco) / 1000; /* current freq */
  147. set_cpus_allowed(current, cpus_allowed);
  148. return current_freq;
  149. }
  150. static int integrator_cpufreq_init(struct cpufreq_policy *policy)
  151. {
  152. /* set default policy and cpuinfo */
  153. policy->cpuinfo.max_freq = 160000;
  154. policy->cpuinfo.min_freq = 12000;
  155. policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
  156. policy->cur = policy->min = policy->max = integrator_get(policy->cpu);
  157. return 0;
  158. }
  159. static struct cpufreq_driver integrator_driver = {
  160. .verify = integrator_verify_policy,
  161. .target = integrator_set_target,
  162. .get = integrator_get,
  163. .init = integrator_cpufreq_init,
  164. .name = "integrator",
  165. };
  166. static int __init integrator_cpu_init(void)
  167. {
  168. return cpufreq_register_driver(&integrator_driver);
  169. }
  170. static void __exit integrator_cpu_exit(void)
  171. {
  172. cpufreq_unregister_driver(&integrator_driver);
  173. }
  174. MODULE_AUTHOR ("Russell M. King");
  175. MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
  176. MODULE_LICENSE ("GPL");
  177. module_init(integrator_cpu_init);
  178. module_exit(integrator_cpu_exit);