clock-sh7786.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7786.c
  3. *
  4. * SH7786 support for the clock framework
  5. *
  6. * Copyright (C) 2008, 2009 Renesas Solutions Corp.
  7. * Kuninori Morimoto <morimoto.kuninori@renesas.com>
  8. *
  9. * Based on SH7785
  10. * Copyright (C) 2007 Paul Mundt
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file "COPYING" in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <asm/clock.h>
  19. #include <asm/freq.h>
  20. #include <asm/io.h>
  21. static int ifc_divisors[] = { 1, 2, 4, 1 };
  22. static int sfc_divisors[] = { 1, 1, 4, 1 };
  23. static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 1,
  24. 24, 32, 1, 1, 1, 1, 1, 1 };
  25. static int mfc_divisors[] = { 1, 1, 4, 1 };
  26. static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 16, 1,
  27. 24, 32, 1, 48, 1, 1, 1, 1 };
  28. static void master_clk_init(struct clk *clk)
  29. {
  30. clk->rate *= pfc_divisors[ctrl_inl(FRQMR1) & 0x000f];
  31. }
  32. static struct clk_ops sh7786_master_clk_ops = {
  33. .init = master_clk_init,
  34. };
  35. static unsigned long module_clk_recalc(struct clk *clk)
  36. {
  37. int idx = (ctrl_inl(FRQMR1) & 0x000f);
  38. return clk->parent->rate / pfc_divisors[idx];
  39. }
  40. static struct clk_ops sh7786_module_clk_ops = {
  41. .recalc = module_clk_recalc,
  42. };
  43. static unsigned long bus_clk_recalc(struct clk *clk)
  44. {
  45. int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
  46. return clk->parent->rate / bfc_divisors[idx];
  47. }
  48. static struct clk_ops sh7786_bus_clk_ops = {
  49. .recalc = bus_clk_recalc,
  50. };
  51. static unsigned long cpu_clk_recalc(struct clk *clk)
  52. {
  53. int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003);
  54. return clk->parent->rate / ifc_divisors[idx];
  55. }
  56. static struct clk_ops sh7786_cpu_clk_ops = {
  57. .recalc = cpu_clk_recalc,
  58. };
  59. static struct clk_ops *sh7786_clk_ops[] = {
  60. &sh7786_master_clk_ops,
  61. &sh7786_module_clk_ops,
  62. &sh7786_bus_clk_ops,
  63. &sh7786_cpu_clk_ops,
  64. };
  65. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  66. {
  67. if (idx < ARRAY_SIZE(sh7786_clk_ops))
  68. *ops = sh7786_clk_ops[idx];
  69. }
  70. static unsigned long shyway_clk_recalc(struct clk *clk)
  71. {
  72. int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
  73. return clk->parent->rate / sfc_divisors[idx];
  74. }
  75. static struct clk_ops sh7786_shyway_clk_ops = {
  76. .recalc = shyway_clk_recalc,
  77. };
  78. static struct clk sh7786_shyway_clk = {
  79. .name = "shyway_clk",
  80. .flags = CLK_ENABLE_ON_INIT,
  81. .ops = &sh7786_shyway_clk_ops,
  82. };
  83. static unsigned long ddr_clk_recalc(struct clk *clk)
  84. {
  85. int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003);
  86. return clk->parent->rate / mfc_divisors[idx];
  87. }
  88. static struct clk_ops sh7786_ddr_clk_ops = {
  89. .recalc = ddr_clk_recalc,
  90. };
  91. static struct clk sh7786_ddr_clk = {
  92. .name = "ddr_clk",
  93. .flags = CLK_ENABLE_ON_INIT,
  94. .ops = &sh7786_ddr_clk_ops,
  95. };
  96. /*
  97. * Additional SH7786-specific on-chip clocks that aren't already part of the
  98. * clock framework
  99. */
  100. static struct clk *sh7786_onchip_clocks[] = {
  101. &sh7786_shyway_clk,
  102. &sh7786_ddr_clk,
  103. };
  104. int __init arch_clk_init(void)
  105. {
  106. struct clk *clk;
  107. int i, ret = 0;
  108. cpg_clk_init();
  109. clk = clk_get(NULL, "master_clk");
  110. for (i = 0; i < ARRAY_SIZE(sh7786_onchip_clocks); i++) {
  111. struct clk *clkp = sh7786_onchip_clocks[i];
  112. clkp->parent = clk;
  113. ret |= clk_register(clkp);
  114. }
  115. clk_put(clk);
  116. return ret;
  117. }