clock-sh7785.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7785.c
  3. *
  4. * SH7785 support for the clock framework
  5. *
  6. * Copyright (C) 2007 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <asm/clock.h>
  15. #include <asm/freq.h>
  16. #include <asm/io.h>
  17. static int ifc_divisors[] = { 1, 2, 4, 6 };
  18. static int ufc_divisors[] = { 1, 1, 4, 6 };
  19. static int sfc_divisors[] = { 1, 1, 4, 6 };
  20. static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18,
  21. 24, 32, 36, 48, 1, 1, 1, 1 };
  22. static int mfc_divisors[] = { 1, 1, 4, 6 };
  23. static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18,
  24. 24, 32, 36, 48, 1, 1, 1, 1 };
  25. static void master_clk_init(struct clk *clk)
  26. {
  27. clk->rate *= pfc_divisors[ctrl_inl(FRQMR1) & 0x000f];
  28. }
  29. static struct clk_ops sh7785_master_clk_ops = {
  30. .init = master_clk_init,
  31. };
  32. static void module_clk_recalc(struct clk *clk)
  33. {
  34. int idx = (ctrl_inl(FRQMR1) & 0x000f);
  35. clk->rate = clk->parent->rate / pfc_divisors[idx];
  36. }
  37. static struct clk_ops sh7785_module_clk_ops = {
  38. .recalc = module_clk_recalc,
  39. };
  40. static void bus_clk_recalc(struct clk *clk)
  41. {
  42. int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
  43. clk->rate = clk->parent->rate / bfc_divisors[idx];
  44. }
  45. static struct clk_ops sh7785_bus_clk_ops = {
  46. .recalc = bus_clk_recalc,
  47. };
  48. static void cpu_clk_recalc(struct clk *clk)
  49. {
  50. int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003);
  51. clk->rate = clk->parent->rate / ifc_divisors[idx];
  52. }
  53. static struct clk_ops sh7785_cpu_clk_ops = {
  54. .recalc = cpu_clk_recalc,
  55. };
  56. static struct clk_ops *sh7785_clk_ops[] = {
  57. &sh7785_master_clk_ops,
  58. &sh7785_module_clk_ops,
  59. &sh7785_bus_clk_ops,
  60. &sh7785_cpu_clk_ops,
  61. };
  62. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  63. {
  64. if (idx < ARRAY_SIZE(sh7785_clk_ops))
  65. *ops = sh7785_clk_ops[idx];
  66. }
  67. static void shyway_clk_recalc(struct clk *clk)
  68. {
  69. int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
  70. clk->rate = clk->parent->rate / sfc_divisors[idx];
  71. }
  72. static struct clk_ops sh7785_shyway_clk_ops = {
  73. .recalc = shyway_clk_recalc,
  74. };
  75. static struct clk sh7785_shyway_clk = {
  76. .name = "shyway_clk",
  77. .flags = CLK_ALWAYS_ENABLED,
  78. .ops = &sh7785_shyway_clk_ops,
  79. };
  80. static void ddr_clk_recalc(struct clk *clk)
  81. {
  82. int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003);
  83. clk->rate = clk->parent->rate / mfc_divisors[idx];
  84. }
  85. static struct clk_ops sh7785_ddr_clk_ops = {
  86. .recalc = ddr_clk_recalc,
  87. };
  88. static struct clk sh7785_ddr_clk = {
  89. .name = "ddr_clk",
  90. .flags = CLK_ALWAYS_ENABLED,
  91. .ops = &sh7785_ddr_clk_ops,
  92. };
  93. static void ram_clk_recalc(struct clk *clk)
  94. {
  95. int idx = ((ctrl_inl(FRQMR1) >> 24) & 0x0003);
  96. clk->rate = clk->parent->rate / ufc_divisors[idx];
  97. }
  98. static struct clk_ops sh7785_ram_clk_ops = {
  99. .recalc = ram_clk_recalc,
  100. };
  101. static struct clk sh7785_ram_clk = {
  102. .name = "ram_clk",
  103. .flags = CLK_ALWAYS_ENABLED,
  104. .ops = &sh7785_ram_clk_ops,
  105. };
  106. /*
  107. * Additional SH7785-specific on-chip clocks that aren't already part of the
  108. * clock framework
  109. */
  110. static struct clk *sh7785_onchip_clocks[] = {
  111. &sh7785_shyway_clk,
  112. &sh7785_ddr_clk,
  113. &sh7785_ram_clk,
  114. };
  115. static int __init sh7785_clk_init(void)
  116. {
  117. struct clk *clk = clk_get(NULL, "master_clk");
  118. int i;
  119. for (i = 0; i < ARRAY_SIZE(sh7785_onchip_clocks); i++) {
  120. struct clk *clkp = sh7785_onchip_clocks[i];
  121. clkp->parent = clk;
  122. clk_register(clkp);
  123. clk_enable(clkp);
  124. }
  125. /*
  126. * Now that we have the rest of the clocks registered, we need to
  127. * force the parent clock to propagate so that these clocks will
  128. * automatically figure out their rate. We cheat by handing the
  129. * parent clock its current rate and forcing child propagation.
  130. */
  131. clk_set_rate(clk, clk_get_rate(clk));
  132. clk_put(clk);
  133. return 0;
  134. }
  135. arch_initcall(sh7785_clk_init);