cpu-ucv2.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * linux/arch/unicore32/kernel/cpu-ucv2.c: 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. int ucv2_verify_speed(struct cpufreq_policy *policy)
  24. {
  25. if (policy->cpu)
  26. return -EINVAL;
  27. cpufreq_verify_within_limits(policy,
  28. policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
  29. return 0;
  30. }
  31. static unsigned int ucv2_getspeed(unsigned int cpu)
  32. {
  33. struct clk *mclk = clk_get(NULL, "MAIN_CLK");
  34. if (cpu)
  35. return 0;
  36. return clk_get_rate(mclk)/1000;
  37. }
  38. static int ucv2_target(struct cpufreq_policy *policy,
  39. unsigned int target_freq,
  40. unsigned int relation)
  41. {
  42. unsigned int cur = ucv2_getspeed(0);
  43. struct cpufreq_freqs freqs;
  44. struct clk *mclk = clk_get(NULL, "MAIN_CLK");
  45. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  46. if (!clk_set_rate(mclk, target_freq * 1000)) {
  47. freqs.old = cur;
  48. freqs.new = target_freq;
  49. freqs.cpu = 0;
  50. }
  51. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  52. return 0;
  53. }
  54. static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
  55. {
  56. if (policy->cpu != 0)
  57. return -EINVAL;
  58. policy->cur = ucv2_getspeed(0);
  59. policy->min = policy->cpuinfo.min_freq = 250000;
  60. policy->max = policy->cpuinfo.max_freq = 1000000;
  61. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  62. return 0;
  63. }
  64. static struct cpufreq_driver ucv2_driver = {
  65. .flags = CPUFREQ_STICKY,
  66. .verify = ucv2_verify_speed,
  67. .target = ucv2_target,
  68. .get = ucv2_getspeed,
  69. .init = ucv2_cpu_init,
  70. .name = "UniCore-II",
  71. };
  72. static int __init ucv2_cpufreq_init(void)
  73. {
  74. return cpufreq_register_driver(&ucv2_driver);
  75. }
  76. arch_initcall(ucv2_cpufreq_init);