clock-sh7757.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/clkdev.h>
  16. #include <asm/clock.h>
  17. #include <asm/freq.h>
  18. static int ifc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  19. 16, 1, 1, 32, 1, 1, 1, 1 };
  20. static int sfc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  21. 16, 1, 1, 32, 1, 1, 1, 1 };
  22. static int bfc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  23. 16, 1, 1, 32, 1, 1, 1, 1 };
  24. static int p1fc_divisors[] = { 2, 1, 4, 1, 1, 8, 1, 1,
  25. 16, 1, 1, 32, 1, 1, 1, 1 };
  26. static void master_clk_init(struct clk *clk)
  27. {
  28. clk->rate = CONFIG_SH_PCLK_FREQ * 16;
  29. }
  30. static struct clk_ops sh7757_master_clk_ops = {
  31. .init = master_clk_init,
  32. };
  33. static void module_clk_recalc(struct clk *clk)
  34. {
  35. int idx = __raw_readl(FRQCR) & 0x0000000f;
  36. clk->rate = clk->parent->rate / p1fc_divisors[idx];
  37. }
  38. static struct clk_ops sh7757_module_clk_ops = {
  39. .recalc = module_clk_recalc,
  40. };
  41. static void bus_clk_recalc(struct clk *clk)
  42. {
  43. int idx = (__raw_readl(FRQCR) >> 8) & 0x0000000f;
  44. clk->rate = clk->parent->rate / bfc_divisors[idx];
  45. }
  46. static struct clk_ops sh7757_bus_clk_ops = {
  47. .recalc = bus_clk_recalc,
  48. };
  49. static void cpu_clk_recalc(struct clk *clk)
  50. {
  51. int idx = (__raw_readl(FRQCR) >> 20) & 0x0000000f;
  52. clk->rate = clk->parent->rate / ifc_divisors[idx];
  53. }
  54. static struct clk_ops sh7757_cpu_clk_ops = {
  55. .recalc = cpu_clk_recalc,
  56. };
  57. static struct clk_ops *sh7757_clk_ops[] = {
  58. &sh7757_master_clk_ops,
  59. &sh7757_module_clk_ops,
  60. &sh7757_bus_clk_ops,
  61. &sh7757_cpu_clk_ops,
  62. };
  63. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  64. {
  65. if (idx < ARRAY_SIZE(sh7757_clk_ops))
  66. *ops = sh7757_clk_ops[idx];
  67. }
  68. static void shyway_clk_recalc(struct clk *clk)
  69. {
  70. int idx = (__raw_readl(FRQCR) >> 12) & 0x0000000f;
  71. clk->rate = clk->parent->rate / sfc_divisors[idx];
  72. }
  73. static struct clk_ops sh7757_shyway_clk_ops = {
  74. .recalc = shyway_clk_recalc,
  75. };
  76. static struct clk sh7757_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. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  88. static struct clk_lookup lookups[] = {
  89. /* main clocks */
  90. CLKDEV_CON_ID("shyway_clk", &sh7757_shyway_clk),
  91. };
  92. static int __init sh7757_clk_init(void)
  93. {
  94. struct clk *clk = clk_get(NULL, "master_clk");
  95. int i;
  96. for (i = 0; i < ARRAY_SIZE(sh7757_onchip_clocks); i++) {
  97. struct clk *clkp = sh7757_onchip_clocks[i];
  98. clkp->parent = clk;
  99. clk_register(clkp);
  100. clk_enable(clkp);
  101. }
  102. /*
  103. * Now that we have the rest of the clocks registered, we need to
  104. * force the parent clock to propagate so that these clocks will
  105. * automatically figure out their rate. We cheat by handing the
  106. * parent clock its current rate and forcing child propagation.
  107. */
  108. clk_set_rate(clk, clk_get_rate(clk));
  109. clk_put(clk);
  110. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  111. return 0;
  112. }
  113. arch_initcall(sh7757_clk_init);