cpu.c 5.1 KB

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