cpu-omap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <asm/hardware.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/io.h>
  25. #include <asm/system.h>
  26. #include <asm/hardware/clock.h>
  27. /* TODO: Add support for SDRAM timing changes */
  28. int omap_verify_speed(struct cpufreq_policy *policy)
  29. {
  30. struct clk * mpu_clk;
  31. if (policy->cpu)
  32. return -EINVAL;
  33. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
  34. policy->cpuinfo.max_freq);
  35. mpu_clk = clk_get(NULL, "mpu");
  36. if (IS_ERR(mpu_clk))
  37. return PTR_ERR(mpu_clk);
  38. policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000;
  39. policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000;
  40. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
  41. policy->cpuinfo.max_freq);
  42. clk_put(mpu_clk);
  43. return 0;
  44. }
  45. unsigned int omap_getspeed(unsigned int cpu)
  46. {
  47. struct clk * mpu_clk;
  48. unsigned long rate;
  49. if (cpu)
  50. return 0;
  51. mpu_clk = clk_get(NULL, "mpu");
  52. if (IS_ERR(mpu_clk))
  53. return 0;
  54. rate = clk_get_rate(mpu_clk) / 1000;
  55. clk_put(mpu_clk);
  56. return rate;
  57. }
  58. static int omap_target(struct cpufreq_policy *policy,
  59. unsigned int target_freq,
  60. unsigned int relation)
  61. {
  62. struct clk * mpu_clk;
  63. struct cpufreq_freqs freqs;
  64. int ret = 0;
  65. mpu_clk = clk_get(NULL, "mpu");
  66. if (IS_ERR(mpu_clk))
  67. return PTR_ERR(mpu_clk);
  68. freqs.old = omap_getspeed(0);
  69. freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
  70. freqs.cpu = 0;
  71. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  72. ret = clk_set_rate(mpu_clk, target_freq * 1000);
  73. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  74. clk_put(mpu_clk);
  75. return ret;
  76. }
  77. static int __init omap_cpu_init(struct cpufreq_policy *policy)
  78. {
  79. struct clk * mpu_clk;
  80. mpu_clk = clk_get(NULL, "mpu");
  81. if (IS_ERR(mpu_clk))
  82. return PTR_ERR(mpu_clk);
  83. if (policy->cpu != 0)
  84. return -EINVAL;
  85. policy->cur = policy->min = policy->max = omap_getspeed(0);
  86. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  87. policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
  88. policy->cpuinfo.max_freq = clk_round_rate(mpu_clk, 216000000) / 1000;
  89. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  90. clk_put(mpu_clk);
  91. return 0;
  92. }
  93. static struct cpufreq_driver omap_driver = {
  94. .flags = CPUFREQ_STICKY,
  95. .verify = omap_verify_speed,
  96. .target = omap_target,
  97. .get = omap_getspeed,
  98. .init = omap_cpu_init,
  99. .name = "omap",
  100. };
  101. static int __init omap_cpufreq_init(void)
  102. {
  103. return cpufreq_register_driver(&omap_driver);
  104. }
  105. arch_initcall(omap_cpufreq_init);