unicore2-cpufreq.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/err.h>
  14. #include <linux/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/init.h>
  17. #include <linux/clk.h>
  18. #include <linux/cpufreq.h>
  19. #include <mach/hardware.h>
  20. static struct cpufreq_driver ucv2_driver;
  21. /* make sure that only the "userspace" governor is run
  22. * -- anything else wouldn't make sense on this platform, anyway.
  23. */
  24. static int ucv2_verify_speed(struct cpufreq_policy *policy)
  25. {
  26. if (policy->cpu)
  27. return -EINVAL;
  28. cpufreq_verify_within_cpu_limits(policy);
  29. return 0;
  30. }
  31. static int ucv2_target(struct cpufreq_policy *policy,
  32. unsigned int target_freq,
  33. unsigned int relation)
  34. {
  35. struct cpufreq_freqs freqs;
  36. int ret;
  37. freqs.old = policy->cur;
  38. freqs.new = target_freq;
  39. cpufreq_freq_transition_begin(policy, &freqs);
  40. ret = clk_set_rate(policy->clk, target_freq * 1000);
  41. cpufreq_freq_transition_end(policy, &freqs, ret);
  42. return ret;
  43. }
  44. static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
  45. {
  46. if (policy->cpu != 0)
  47. return -EINVAL;
  48. policy->min = policy->cpuinfo.min_freq = 250000;
  49. policy->max = policy->cpuinfo.max_freq = 1000000;
  50. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  51. policy->clk = clk_get(NULL, "MAIN_CLK");
  52. return PTR_ERR_OR_ZERO(policy->clk);
  53. }
  54. static struct cpufreq_driver ucv2_driver = {
  55. .flags = CPUFREQ_STICKY,
  56. .verify = ucv2_verify_speed,
  57. .target = ucv2_target,
  58. .get = cpufreq_generic_get,
  59. .init = ucv2_cpu_init,
  60. .name = "UniCore-II",
  61. };
  62. static int __init ucv2_cpufreq_init(void)
  63. {
  64. return cpufreq_register_driver(&ucv2_driver);
  65. }
  66. arch_initcall(ucv2_cpufreq_init);