cpu.c 5.0 KB

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