clock-shx3.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-shx3.c
  3. *
  4. * SH-X3 support for the clock framework
  5. *
  6. * Copyright (C) 2006-2007 Renesas Technology Corp.
  7. * Copyright (C) 2006-2007 Renesas Solutions Corp.
  8. * Copyright (C) 2006-2007 Paul Mundt
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <asm/clock.h>
  17. #include <asm/freq.h>
  18. #include <asm/io.h>
  19. static int ifc_divisors[] = { 1, 2, 4 ,6 };
  20. static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18, 24, 32, 36, 48 };
  21. static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18, 24, 32, 36, 48 };
  22. static int cfc_divisors[] = { 1, 1, 4, 6 };
  23. #define IFC_POS 28
  24. #define IFC_MSK 0x0003
  25. #define BFC_MSK 0x000f
  26. #define PFC_MSK 0x000f
  27. #define CFC_MSK 0x0003
  28. #define BFC_POS 16
  29. #define PFC_POS 0
  30. #define CFC_POS 20
  31. static void master_clk_init(struct clk *clk)
  32. {
  33. clk->rate *= pfc_divisors[(ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK];
  34. }
  35. static struct clk_ops shx3_master_clk_ops = {
  36. .init = master_clk_init,
  37. };
  38. static unsigned long module_clk_recalc(struct clk *clk)
  39. {
  40. int idx = ((ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK);
  41. return clk->parent->rate / pfc_divisors[idx];
  42. }
  43. static struct clk_ops shx3_module_clk_ops = {
  44. .recalc = module_clk_recalc,
  45. };
  46. static unsigned long bus_clk_recalc(struct clk *clk)
  47. {
  48. int idx = ((ctrl_inl(FRQCR) >> BFC_POS) & BFC_MSK);
  49. return clk->parent->rate / bfc_divisors[idx];
  50. }
  51. static struct clk_ops shx3_bus_clk_ops = {
  52. .recalc = bus_clk_recalc,
  53. };
  54. static unsigned long cpu_clk_recalc(struct clk *clk)
  55. {
  56. int idx = ((ctrl_inl(FRQCR) >> IFC_POS) & IFC_MSK);
  57. return clk->parent->rate / ifc_divisors[idx];
  58. }
  59. static struct clk_ops shx3_cpu_clk_ops = {
  60. .recalc = cpu_clk_recalc,
  61. };
  62. static struct clk_ops *shx3_clk_ops[] = {
  63. &shx3_master_clk_ops,
  64. &shx3_module_clk_ops,
  65. &shx3_bus_clk_ops,
  66. &shx3_cpu_clk_ops,
  67. };
  68. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  69. {
  70. if (idx < ARRAY_SIZE(shx3_clk_ops))
  71. *ops = shx3_clk_ops[idx];
  72. }
  73. static unsigned long shyway_clk_recalc(struct clk *clk)
  74. {
  75. int idx = ((ctrl_inl(FRQCR) >> CFC_POS) & CFC_MSK);
  76. return clk->parent->rate / cfc_divisors[idx];
  77. }
  78. static struct clk_ops shx3_shyway_clk_ops = {
  79. .recalc = shyway_clk_recalc,
  80. };
  81. static struct clk shx3_shyway_clk = {
  82. .name = "shyway_clk",
  83. .flags = CLK_ENABLE_ON_INIT,
  84. .ops = &shx3_shyway_clk_ops,
  85. };
  86. /*
  87. * Additional SHx3-specific on-chip clocks that aren't already part of the
  88. * clock framework
  89. */
  90. static struct clk *shx3_onchip_clocks[] = {
  91. &shx3_shyway_clk,
  92. };
  93. int __init arch_clk_init(void)
  94. {
  95. struct clk *clk;
  96. int i, ret = 0;
  97. cpg_clk_init();
  98. clk = clk_get(NULL, "master_clk");
  99. for (i = 0; i < ARRAY_SIZE(shx3_onchip_clocks); i++) {
  100. struct clk *clkp = shx3_onchip_clocks[i];
  101. clkp->parent = clk;
  102. ret |= clk_register(clkp);
  103. }
  104. clk_put(clk);
  105. return ret;
  106. }