clock-shx3.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <linux/io.h>
  17. #include <asm/clkdev.h>
  18. #include <asm/clock.h>
  19. #include <asm/freq.h>
  20. static int ifc_divisors[] = { 1, 2, 4 ,6 };
  21. static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18, 24, 32, 36, 48 };
  22. static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18, 24, 32, 36, 48 };
  23. static int cfc_divisors[] = { 1, 1, 4, 6 };
  24. #define IFC_POS 28
  25. #define IFC_MSK 0x0003
  26. #define BFC_MSK 0x000f
  27. #define PFC_MSK 0x000f
  28. #define CFC_MSK 0x0003
  29. #define BFC_POS 16
  30. #define PFC_POS 0
  31. #define CFC_POS 20
  32. static void master_clk_init(struct clk *clk)
  33. {
  34. clk->rate *= pfc_divisors[(__raw_readl(FRQCR) >> PFC_POS) & PFC_MSK];
  35. }
  36. static struct clk_ops shx3_master_clk_ops = {
  37. .init = master_clk_init,
  38. };
  39. static unsigned long module_clk_recalc(struct clk *clk)
  40. {
  41. int idx = ((__raw_readl(FRQCR) >> PFC_POS) & PFC_MSK);
  42. return clk->parent->rate / pfc_divisors[idx];
  43. }
  44. static struct clk_ops shx3_module_clk_ops = {
  45. .recalc = module_clk_recalc,
  46. };
  47. static unsigned long bus_clk_recalc(struct clk *clk)
  48. {
  49. int idx = ((__raw_readl(FRQCR) >> BFC_POS) & BFC_MSK);
  50. return clk->parent->rate / bfc_divisors[idx];
  51. }
  52. static struct clk_ops shx3_bus_clk_ops = {
  53. .recalc = bus_clk_recalc,
  54. };
  55. static unsigned long cpu_clk_recalc(struct clk *clk)
  56. {
  57. int idx = ((__raw_readl(FRQCR) >> IFC_POS) & IFC_MSK);
  58. return clk->parent->rate / ifc_divisors[idx];
  59. }
  60. static struct clk_ops shx3_cpu_clk_ops = {
  61. .recalc = cpu_clk_recalc,
  62. };
  63. static struct clk_ops *shx3_clk_ops[] = {
  64. &shx3_master_clk_ops,
  65. &shx3_module_clk_ops,
  66. &shx3_bus_clk_ops,
  67. &shx3_cpu_clk_ops,
  68. };
  69. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  70. {
  71. if (idx < ARRAY_SIZE(shx3_clk_ops))
  72. *ops = shx3_clk_ops[idx];
  73. }
  74. static unsigned long shyway_clk_recalc(struct clk *clk)
  75. {
  76. int idx = ((__raw_readl(FRQCR) >> CFC_POS) & CFC_MSK);
  77. return clk->parent->rate / cfc_divisors[idx];
  78. }
  79. static struct clk_ops shx3_shyway_clk_ops = {
  80. .recalc = shyway_clk_recalc,
  81. };
  82. static struct clk shx3_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. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  94. static struct clk_lookup lookups[] = {
  95. /* main clocks */
  96. CLKDEV_CON_ID("shyway_clk", &shx3_shyway_clk),
  97. };
  98. int __init arch_clk_init(void)
  99. {
  100. struct clk *clk;
  101. int i, ret = 0;
  102. cpg_clk_init();
  103. clk = clk_get(NULL, "master_clk");
  104. for (i = 0; i < ARRAY_SIZE(shx3_onchip_clocks); i++) {
  105. struct clk *clkp = shx3_onchip_clocks[i];
  106. clkp->parent = clk;
  107. ret |= clk_register(clkp);
  108. }
  109. clk_put(clk);
  110. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  111. return ret;
  112. }