clock-sh7757.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-sh7757.c
  3. *
  4. * SH7757 support for the clock framework
  5. *
  6. * Copyright (C) 2009 Renesas Solutions Corp.
  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 <linux/io.h>
  15. #include <asm/clock.h>
  16. #include <asm/freq.h>
  17. static int ifc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  18. 16, 1, 1, 32, 1, 1, 1, 1 };
  19. static int sfc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  20. 16, 1, 1, 32, 1, 1, 1, 1 };
  21. static int bfc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  22. 16, 1, 1, 32, 1, 1, 1, 1 };
  23. static int p1fc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  24. 16, 1, 1, 32, 1, 1, 1, 1 };
  25. static void master_clk_init(struct clk *clk)
  26. {
  27. clk->rate = CONFIG_SH_PCLK_FREQ * 16;
  28. }
  29. static struct clk_ops sh7757_master_clk_ops = {
  30. .init = master_clk_init,
  31. };
  32. static void module_clk_recalc(struct clk *clk)
  33. {
  34. int idx = ctrl_inl(FRQCR) & 0x0000000f;
  35. clk->rate = clk->parent->rate / p1fc_divisors[idx];
  36. }
  37. static struct clk_ops sh7757_module_clk_ops = {
  38. .recalc = module_clk_recalc,
  39. };
  40. static void bus_clk_recalc(struct clk *clk)
  41. {
  42. int idx = (ctrl_inl(FRQCR) >> 8) & 0x0000000f;
  43. clk->rate = clk->parent->rate / bfc_divisors[idx];
  44. }
  45. static struct clk_ops sh7757_bus_clk_ops = {
  46. .recalc = bus_clk_recalc,
  47. };
  48. static void cpu_clk_recalc(struct clk *clk)
  49. {
  50. int idx = (ctrl_inl(FRQCR) >> 20) & 0x0000000f;
  51. clk->rate = clk->parent->rate / ifc_divisors[idx];
  52. }
  53. static struct clk_ops sh7757_cpu_clk_ops = {
  54. .recalc = cpu_clk_recalc,
  55. };
  56. static struct clk_ops *sh7757_clk_ops[] = {
  57. &sh7757_master_clk_ops,
  58. &sh7757_module_clk_ops,
  59. &sh7757_bus_clk_ops,
  60. &sh7757_cpu_clk_ops,
  61. };
  62. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  63. {
  64. if (idx < ARRAY_SIZE(sh7757_clk_ops))
  65. *ops = sh7757_clk_ops[idx];
  66. }
  67. static void shyway_clk_recalc(struct clk *clk)
  68. {
  69. int idx = (ctrl_inl(FRQCR) >> 12) & 0x0000000f;
  70. clk->rate = clk->parent->rate / sfc_divisors[idx];
  71. }
  72. static struct clk_ops sh7757_shyway_clk_ops = {
  73. .recalc = shyway_clk_recalc,
  74. };
  75. static struct clk sh7757_shyway_clk = {
  76. .name = "shyway_clk",
  77. .flags = CLK_ENABLE_ON_INIT,
  78. .ops = &sh7757_shyway_clk_ops,
  79. };
  80. /*
  81. * Additional sh7757-specific on-chip clocks that aren't already part of the
  82. * clock framework
  83. */
  84. static struct clk *sh7757_onchip_clocks[] = {
  85. &sh7757_shyway_clk,
  86. };
  87. static int __init sh7757_clk_init(void)
  88. {
  89. struct clk *clk = clk_get(NULL, "master_clk");
  90. int i;
  91. for (i = 0; i < ARRAY_SIZE(sh7757_onchip_clocks); i++) {
  92. struct clk *clkp = sh7757_onchip_clocks[i];
  93. clkp->parent = clk;
  94. clk_register(clkp);
  95. clk_enable(clkp);
  96. }
  97. /*
  98. * Now that we have the rest of the clocks registered, we need to
  99. * force the parent clock to propagate so that these clocks will
  100. * automatically figure out their rate. We cheat by handing the
  101. * parent clock its current rate and forcing child propagation.
  102. */
  103. clk_set_rate(clk, clk_get_rate(clk));
  104. clk_put(clk);
  105. return 0;
  106. }
  107. arch_initcall(sh7757_clk_init);