cris-etraxfs-cpufreq.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/cpufreq.h>
  4. #include <hwregs/reg_map.h>
  5. #include <arch/hwregs/reg_rdwr.h>
  6. #include <arch/hwregs/config_defs.h>
  7. #include <arch/hwregs/bif_core_defs.h>
  8. static int
  9. cris_sdram_freq_notifier(struct notifier_block *nb, unsigned long val,
  10. void *data);
  11. static struct notifier_block cris_sdram_freq_notifier_block = {
  12. .notifier_call = cris_sdram_freq_notifier
  13. };
  14. static struct cpufreq_frequency_table cris_freq_table[] = {
  15. {0, 0x01, 6000},
  16. {0, 0x02, 200000},
  17. {0, 0, CPUFREQ_TABLE_END},
  18. };
  19. static unsigned int cris_freq_get_cpu_frequency(unsigned int cpu)
  20. {
  21. reg_config_rw_clk_ctrl clk_ctrl;
  22. clk_ctrl = REG_RD(config, regi_config, rw_clk_ctrl);
  23. return clk_ctrl.pll ? 200000 : 6000;
  24. }
  25. static int cris_freq_target(struct cpufreq_policy *policy, unsigned int state)
  26. {
  27. reg_config_rw_clk_ctrl clk_ctrl;
  28. clk_ctrl = REG_RD(config, regi_config, rw_clk_ctrl);
  29. local_irq_disable();
  30. /* Even though we may be SMP they will share the same clock
  31. * so all settings are made on CPU0. */
  32. if (cris_freq_table[state].frequency == 200000)
  33. clk_ctrl.pll = 1;
  34. else
  35. clk_ctrl.pll = 0;
  36. REG_WR(config, regi_config, rw_clk_ctrl, clk_ctrl);
  37. local_irq_enable();
  38. return 0;
  39. }
  40. static int cris_freq_cpu_init(struct cpufreq_policy *policy)
  41. {
  42. return cpufreq_generic_init(policy, cris_freq_table, 1000000);
  43. }
  44. static struct cpufreq_driver cris_freq_driver = {
  45. .get = cris_freq_get_cpu_frequency,
  46. .verify = cpufreq_generic_frequency_table_verify,
  47. .target_index = cris_freq_target,
  48. .init = cris_freq_cpu_init,
  49. .name = "cris_freq",
  50. .attr = cpufreq_generic_attr,
  51. };
  52. static int __init cris_freq_init(void)
  53. {
  54. int ret;
  55. ret = cpufreq_register_driver(&cris_freq_driver);
  56. cpufreq_register_notifier(&cris_sdram_freq_notifier_block,
  57. CPUFREQ_TRANSITION_NOTIFIER);
  58. return ret;
  59. }
  60. static int
  61. cris_sdram_freq_notifier(struct notifier_block *nb, unsigned long val,
  62. void *data)
  63. {
  64. int i;
  65. struct cpufreq_freqs *freqs = data;
  66. if (val == CPUFREQ_PRECHANGE) {
  67. reg_bif_core_rw_sdram_timing timing =
  68. REG_RD(bif_core, regi_bif_core, rw_sdram_timing);
  69. timing.cpd = (freqs->new == 200000 ? 0 : 1);
  70. if (freqs->new == 200000)
  71. for (i = 0; i < 50000; i++) ;
  72. REG_WR(bif_core, regi_bif_core, rw_sdram_timing, timing);
  73. }
  74. return 0;
  75. }
  76. module_init(cris_freq_init);