cris-etraxfs-cpufreq.c 2.3 KB

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