cpu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * linux/arch/arm/mach-integrator/cpu.c
  3. *
  4. * Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
  5. *
  6. * $Id: cpu.c,v 1.6 2002/07/18 13:58:51 rmk Exp $
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * CPU support functions
  13. */
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/slab.h>
  19. #include <linux/sched.h>
  20. #include <linux/smp.h>
  21. #include <linux/init.h>
  22. #include <asm/hardware.h>
  23. #include <asm/io.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/hardware/icst525.h>
  26. static struct cpufreq_driver integrator_driver;
  27. #define CM_ID (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET)
  28. #define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET)
  29. #define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET)
  30. #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
  31. static const struct icst525_params lclk_params = {
  32. .ref = 24000,
  33. .vco_max = 320000,
  34. .vd_min = 8,
  35. .vd_max = 132,
  36. .rd_min = 24,
  37. .rd_max = 24,
  38. };
  39. static const struct icst525_params cclk_params = {
  40. .ref = 24000,
  41. .vco_max = 320000,
  42. .vd_min = 12,
  43. .vd_max = 160,
  44. .rd_min = 24,
  45. .rd_max = 24,
  46. };
  47. /*
  48. * Validate the speed policy.
  49. */
  50. static int integrator_verify_policy(struct cpufreq_policy *policy)
  51. {
  52. struct icst525_vco vco;
  53. cpufreq_verify_within_limits(policy,
  54. policy->cpuinfo.min_freq,
  55. policy->cpuinfo.max_freq);
  56. vco = icst525_khz_to_vco(&cclk_params, policy->max);
  57. policy->max = icst525_khz(&cclk_params, vco);
  58. vco = icst525_khz_to_vco(&cclk_params, policy->min);
  59. policy->min = icst525_khz(&cclk_params, vco);
  60. cpufreq_verify_within_limits(policy,
  61. policy->cpuinfo.min_freq,
  62. policy->cpuinfo.max_freq);
  63. return 0;
  64. }
  65. static int integrator_set_target(struct cpufreq_policy *policy,
  66. unsigned int target_freq,
  67. unsigned int relation)
  68. {
  69. cpumask_t cpus_allowed;
  70. int cpu = policy->cpu;
  71. struct icst525_vco vco;
  72. struct cpufreq_freqs freqs;
  73. u_int cm_osc;
  74. /*
  75. * Save this threads cpus_allowed mask.
  76. */
  77. cpus_allowed = current->cpus_allowed;
  78. /*
  79. * Bind to the specified CPU. When this call returns,
  80. * we should be running on the right CPU.
  81. */
  82. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  83. BUG_ON(cpu != smp_processor_id());
  84. /* get current setting */
  85. cm_osc = __raw_readl(CM_OSC);
  86. if (machine_is_integrator()) {
  87. vco.s = (cm_osc >> 8) & 7;
  88. } else if (machine_is_cintegrator()) {
  89. vco.s = 1;
  90. }
  91. vco.v = cm_osc & 255;
  92. vco.r = 22;
  93. freqs.old = icst525_khz(&cclk_params, vco);
  94. /* icst525_khz_to_vco rounds down -- so we need the next
  95. * larger freq in case of CPUFREQ_RELATION_L.
  96. */
  97. if (relation == CPUFREQ_RELATION_L)
  98. target_freq += 999;
  99. if (target_freq > policy->max)
  100. target_freq = policy->max;
  101. vco = icst525_khz_to_vco(&cclk_params, target_freq);
  102. freqs.new = icst525_khz(&cclk_params, vco);
  103. freqs.cpu = policy->cpu;
  104. if (freqs.old == freqs.new) {
  105. set_cpus_allowed(current, cpus_allowed);
  106. return 0;
  107. }
  108. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  109. cm_osc = __raw_readl(CM_OSC);
  110. if (machine_is_integrator()) {
  111. cm_osc &= 0xfffff800;
  112. cm_osc |= vco.s << 8;
  113. } else if (machine_is_cintegrator()) {
  114. cm_osc &= 0xffffff00;
  115. }
  116. cm_osc |= vco.v;
  117. __raw_writel(0xa05f, CM_LOCK);
  118. __raw_writel(cm_osc, CM_OSC);
  119. __raw_writel(0, CM_LOCK);
  120. /*
  121. * Restore the CPUs allowed mask.
  122. */
  123. set_cpus_allowed(current, cpus_allowed);
  124. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  125. return 0;
  126. }
  127. static unsigned int integrator_get(unsigned int cpu)
  128. {
  129. cpumask_t cpus_allowed;
  130. unsigned int current_freq;
  131. u_int cm_osc;
  132. struct icst525_vco vco;
  133. cpus_allowed = current->cpus_allowed;
  134. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  135. BUG_ON(cpu != smp_processor_id());
  136. /* detect memory etc. */
  137. cm_osc = __raw_readl(CM_OSC);
  138. if (machine_is_integrator()) {
  139. vco.s = (cm_osc >> 8) & 7;
  140. } else if (machine_is_cintegrator()) {
  141. vco.s = 1;
  142. }
  143. vco.v = cm_osc & 255;
  144. vco.r = 22;
  145. current_freq = icst525_khz(&cclk_params, vco); /* current freq */
  146. set_cpus_allowed(current, cpus_allowed);
  147. return current_freq;
  148. }
  149. static int integrator_cpufreq_init(struct cpufreq_policy *policy)
  150. {
  151. /* set default policy and cpuinfo */
  152. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  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);