unicore2-cpufreq.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * clock scaling for the UniCore-II
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
  7. * Copyright (C) 2001-2010 Guan Xuetao
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/init.h>
  16. #include <linux/clk.h>
  17. #include <linux/cpufreq.h>
  18. #include <mach/hardware.h>
  19. static struct cpufreq_driver ucv2_driver;
  20. /* make sure that only the "userspace" governor is run
  21. * -- anything else wouldn't make sense on this platform, anyway.
  22. */
  23. static int ucv2_verify_speed(struct cpufreq_policy *policy)
  24. {
  25. if (policy->cpu)
  26. return -EINVAL;
  27. cpufreq_verify_within_cpu_limits(policy);
  28. return 0;
  29. }
  30. static unsigned int ucv2_getspeed(unsigned int cpu)
  31. {
  32. struct clk *mclk = clk_get(NULL, "MAIN_CLK");
  33. if (cpu)
  34. return 0;
  35. return clk_get_rate(mclk)/1000;
  36. }
  37. static int ucv2_target(struct cpufreq_policy *policy,
  38. unsigned int target_freq,
  39. unsigned int relation)
  40. {
  41. unsigned int cur = ucv2_getspeed(0);
  42. struct cpufreq_freqs freqs;
  43. struct clk *mclk = clk_get(NULL, "MAIN_CLK");
  44. cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
  45. if (!clk_set_rate(mclk, target_freq * 1000)) {
  46. freqs.old = cur;
  47. freqs.new = target_freq;
  48. }
  49. cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
  50. return 0;
  51. }
  52. static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
  53. {
  54. if (policy->cpu != 0)
  55. return -EINVAL;
  56. policy->min = policy->cpuinfo.min_freq = 250000;
  57. policy->max = policy->cpuinfo.max_freq = 1000000;
  58. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  59. return 0;
  60. }
  61. static struct cpufreq_driver ucv2_driver = {
  62. .flags = CPUFREQ_STICKY,
  63. .verify = ucv2_verify_speed,
  64. .target = ucv2_target,
  65. .get = ucv2_getspeed,
  66. .init = ucv2_cpu_init,
  67. .name = "UniCore-II",
  68. };
  69. static int __init ucv2_cpufreq_init(void)
  70. {
  71. return cpufreq_register_driver(&ucv2_driver);
  72. }
  73. arch_initcall(ucv2_cpufreq_init);