cpu-omap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * linux/arch/arm/plat-omap/cpu-omap.c
  3. *
  4. * CPU frequency scaling for OMAP
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Written by Tony Lindgren <tony@atomide.com>
  8. *
  9. * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/cpufreq.h>
  19. #include <linux/delay.h>
  20. #include <linux/init.h>
  21. #include <linux/err.h>
  22. #include <linux/clk.h>
  23. #include <asm/hardware.h>
  24. #include <asm/io.h>
  25. #include <asm/system.h>
  26. /* TODO: Add support for SDRAM timing changes */
  27. int omap_verify_speed(struct cpufreq_policy *policy)
  28. {
  29. struct clk * mpu_clk;
  30. if (policy->cpu)
  31. return -EINVAL;
  32. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
  33. policy->cpuinfo.max_freq);
  34. mpu_clk = clk_get(NULL, "mpu");
  35. if (IS_ERR(mpu_clk))
  36. return PTR_ERR(mpu_clk);
  37. policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000;
  38. policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000;
  39. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
  40. policy->cpuinfo.max_freq);
  41. clk_put(mpu_clk);
  42. return 0;
  43. }
  44. unsigned int omap_getspeed(unsigned int cpu)
  45. {
  46. struct clk * mpu_clk;
  47. unsigned long rate;
  48. if (cpu)
  49. return 0;
  50. mpu_clk = clk_get(NULL, "mpu");
  51. if (IS_ERR(mpu_clk))
  52. return 0;
  53. rate = clk_get_rate(mpu_clk) / 1000;
  54. clk_put(mpu_clk);
  55. return rate;
  56. }
  57. static int omap_target(struct cpufreq_policy *policy,
  58. unsigned int target_freq,
  59. unsigned int relation)
  60. {
  61. struct clk * mpu_clk;
  62. struct cpufreq_freqs freqs;
  63. int ret = 0;
  64. mpu_clk = clk_get(NULL, "mpu");
  65. if (IS_ERR(mpu_clk))
  66. return PTR_ERR(mpu_clk);
  67. freqs.old = omap_getspeed(0);
  68. freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
  69. freqs.cpu = 0;
  70. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  71. ret = clk_set_rate(mpu_clk, target_freq * 1000);
  72. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  73. clk_put(mpu_clk);
  74. return ret;
  75. }
  76. static int __init omap_cpu_init(struct cpufreq_policy *policy)
  77. {
  78. struct clk * mpu_clk;
  79. mpu_clk = clk_get(NULL, "mpu");
  80. if (IS_ERR(mpu_clk))
  81. return PTR_ERR(mpu_clk);
  82. if (policy->cpu != 0)
  83. return -EINVAL;
  84. policy->cur = policy->min = policy->max = omap_getspeed(0);
  85. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  86. policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
  87. policy->cpuinfo.max_freq = clk_round_rate(mpu_clk, 216000000) / 1000;
  88. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  89. clk_put(mpu_clk);
  90. return 0;
  91. }
  92. static struct cpufreq_driver omap_driver = {
  93. .flags = CPUFREQ_STICKY,
  94. .verify = omap_verify_speed,
  95. .target = omap_target,
  96. .get = omap_getspeed,
  97. .init = omap_cpu_init,
  98. .name = "omap",
  99. };
  100. static int __init omap_cpufreq_init(void)
  101. {
  102. return cpufreq_register_driver(&omap_driver);
  103. }
  104. arch_initcall(omap_cpufreq_init);