cpu-omap.c 2.8 KB

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