cpu-omap.c 3.0 KB

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