cris-artpec3-cpufreq.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/cpufreq.h>
  4. #include <hwregs/reg_map.h>
  5. #include <hwregs/reg_rdwr.h>
  6. #include <hwregs/clkgen_defs.h>
  7. #include <hwregs/ddr2_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_clkgen_rw_clk_ctrl clk_ctrl;
  22. clk_ctrl = REG_RD(clkgen, regi_clkgen, 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_clkgen_rw_clk_ctrl clk_ctrl;
  28. clk_ctrl = REG_RD(clkgen, regi_clkgen, 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(clkgen, regi_clkgen, 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_ddr2_rw_cfg cfg =
  68. REG_RD(ddr2, regi_ddr2_ctrl, rw_cfg);
  69. cfg.ref_interval = (freqs->new == 200000 ? 1560 : 46);
  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);