cpu.c 5.0 KB

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