clock-sh7780.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7780.c
  3. *
  4. * SH7780 support for the clock framework
  5. *
  6. * Copyright (C) 2005 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[] = { 2, 4 };
  18. static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };
  19. static int pfc_divisors[] = { 1, 24, 24, 1 };
  20. static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };
  21. static void master_clk_init(struct clk *clk)
  22. {
  23. clk->rate *= pfc_divisors[ctrl_inl(FRQCR) & 0x0003];
  24. }
  25. static struct clk_ops sh7780_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) & 0x0003);
  31. clk->rate = clk->parent->rate / pfc_divisors[idx];
  32. }
  33. static struct clk_ops sh7780_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) & 0x0007);
  39. clk->rate = clk->parent->rate / bfc_divisors[idx];
  40. }
  41. static struct clk_ops sh7780_bus_clk_ops = {
  42. .recalc = bus_clk_recalc,
  43. };
  44. static void cpu_clk_recalc(struct clk *clk)
  45. {
  46. int idx = ((ctrl_inl(FRQCR) >> 24) & 0x0001);
  47. clk->rate = clk->parent->rate / ifc_divisors[idx];
  48. }
  49. static struct clk_ops sh7780_cpu_clk_ops = {
  50. .recalc = cpu_clk_recalc,
  51. };
  52. static struct clk_ops *sh7780_clk_ops[] = {
  53. &sh7780_master_clk_ops,
  54. &sh7780_module_clk_ops,
  55. &sh7780_bus_clk_ops,
  56. &sh7780_cpu_clk_ops,
  57. };
  58. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  59. {
  60. if (idx < ARRAY_SIZE(sh7780_clk_ops))
  61. *ops = sh7780_clk_ops[idx];
  62. }
  63. static void shyway_clk_recalc(struct clk *clk)
  64. {
  65. int idx = ((ctrl_inl(FRQCR) >> 20) & 0x0007);
  66. clk->rate = clk->parent->rate / cfc_divisors[idx];
  67. }
  68. static struct clk_ops sh7780_shyway_clk_ops = {
  69. .recalc = shyway_clk_recalc,
  70. };
  71. static struct clk sh7780_shyway_clk = {
  72. .name = "shyway_clk",
  73. .flags = CLK_ALWAYS_ENABLED,
  74. .ops = &sh7780_shyway_clk_ops,
  75. };
  76. /*
  77. * Additional SH7780-specific on-chip clocks that aren't already part of the
  78. * clock framework
  79. */
  80. static struct clk *sh7780_onchip_clocks[] = {
  81. &sh7780_shyway_clk,
  82. };
  83. static int __init sh7780_clk_init(void)
  84. {
  85. struct clk *clk = clk_get(NULL, "master_clk");
  86. int i;
  87. for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
  88. struct clk *clkp = sh7780_onchip_clocks[i];
  89. clkp->parent = clk;
  90. clk_register(clkp);
  91. clk_enable(clkp);
  92. }
  93. /*
  94. * Now that we have the rest of the clocks registered, we need to
  95. * force the parent clock to propagate so that these clocks will
  96. * automatically figure out their rate. We cheat by handing the
  97. * parent clock its current rate and forcing child propagation.
  98. */
  99. clk_set_rate(clk, clk_get_rate(clk));
  100. clk_put(clk);
  101. return 0;
  102. }
  103. arch_initcall(sh7780_clk_init);