clock-sh7763.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7763.c
  3. *
  4. * SH7763 support for the clock framework
  5. *
  6. * Copyright (C) 2005 Paul Mundt
  7. * Copyright (C) 2007 Yoshihiro Shimoda
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <asm/clock.h>
  16. #include <asm/freq.h>
  17. #include <asm/io.h>
  18. static int bfc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  19. static int p0fc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  20. static int cfc_divisors[] = { 1, 1, 4, 1, 1, 1, 1, 1 };
  21. static void master_clk_init(struct clk *clk)
  22. {
  23. clk->rate *= p0fc_divisors[(ctrl_inl(FRQCR) >> 4) & 0x07];
  24. }
  25. static struct clk_ops sh7763_master_clk_ops = {
  26. .init = master_clk_init,
  27. };
  28. static void module_clk_recalc(struct clk *clk)
  29. {
  30. int idx = ((ctrl_inl(FRQCR) >> 4) & 0x07);
  31. clk->rate = clk->parent->rate / p0fc_divisors[idx];
  32. }
  33. static struct clk_ops sh7763_module_clk_ops = {
  34. .recalc = module_clk_recalc,
  35. };
  36. static void bus_clk_recalc(struct clk *clk)
  37. {
  38. int idx = ((ctrl_inl(FRQCR) >> 16) & 0x07);
  39. clk->rate = clk->parent->rate / bfc_divisors[idx];
  40. }
  41. static struct clk_ops sh7763_bus_clk_ops = {
  42. .recalc = bus_clk_recalc,
  43. };
  44. static void cpu_clk_recalc(struct clk *clk)
  45. {
  46. clk->rate = clk->parent->rate;
  47. }
  48. static struct clk_ops sh7763_cpu_clk_ops = {
  49. .recalc = cpu_clk_recalc,
  50. };
  51. static struct clk_ops *sh7763_clk_ops[] = {
  52. &sh7763_master_clk_ops,
  53. &sh7763_module_clk_ops,
  54. &sh7763_bus_clk_ops,
  55. &sh7763_cpu_clk_ops,
  56. };
  57. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  58. {
  59. if (idx < ARRAY_SIZE(sh7763_clk_ops))
  60. *ops = sh7763_clk_ops[idx];
  61. }
  62. static void shyway_clk_recalc(struct clk *clk)
  63. {
  64. int idx = ((ctrl_inl(FRQCR) >> 20) & 0x07);
  65. clk->rate = clk->parent->rate / cfc_divisors[idx];
  66. }
  67. static struct clk_ops sh7763_shyway_clk_ops = {
  68. .recalc = shyway_clk_recalc,
  69. };
  70. static struct clk sh7763_shyway_clk = {
  71. .name = "shyway_clk",
  72. .flags = CLK_ALWAYS_ENABLED,
  73. .ops = &sh7763_shyway_clk_ops,
  74. };
  75. /*
  76. * Additional SH7763-specific on-chip clocks that aren't already part of the
  77. * clock framework
  78. */
  79. static struct clk *sh7763_onchip_clocks[] = {
  80. &sh7763_shyway_clk,
  81. };
  82. static int __init sh7763_clk_init(void)
  83. {
  84. struct clk *clk = clk_get(NULL, "master_clk");
  85. int i;
  86. for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
  87. struct clk *clkp = sh7763_onchip_clocks[i];
  88. clkp->parent = clk;
  89. clk_register(clkp);
  90. clk_enable(clkp);
  91. }
  92. /*
  93. * Now that we have the rest of the clocks registered, we need to
  94. * force the parent clock to propagate so that these clocks will
  95. * automatically figure out their rate. We cheat by handing the
  96. * parent clock its current rate and forcing child propagation.
  97. */
  98. clk_set_rate(clk, clk_get_rate(clk));
  99. clk_put(clk);
  100. return 0;
  101. }
  102. arch_initcall(sh7763_clk_init);