clock-sh7780.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7780.c
  3. *
  4. * SH7780 support for the clock framework
  5. *
  6. * Copyright (C) 2005 Paul Mundt
  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 <linux/clkdev.h>
  16. #include <asm/clock.h>
  17. #include <asm/freq.h>
  18. #include <asm/io.h>
  19. static int ifc_divisors[] = { 2, 4 };
  20. static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };
  21. static int pfc_divisors[] = { 1, 24, 24, 1 };
  22. static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };
  23. static void master_clk_init(struct clk *clk)
  24. {
  25. clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003];
  26. }
  27. static struct sh_clk_ops sh7780_master_clk_ops = {
  28. .init = master_clk_init,
  29. };
  30. static unsigned long module_clk_recalc(struct clk *clk)
  31. {
  32. int idx = (__raw_readl(FRQCR) & 0x0003);
  33. return clk->parent->rate / pfc_divisors[idx];
  34. }
  35. static struct sh_clk_ops sh7780_module_clk_ops = {
  36. .recalc = module_clk_recalc,
  37. };
  38. static unsigned long bus_clk_recalc(struct clk *clk)
  39. {
  40. int idx = ((__raw_readl(FRQCR) >> 16) & 0x0007);
  41. return clk->parent->rate / bfc_divisors[idx];
  42. }
  43. static struct sh_clk_ops sh7780_bus_clk_ops = {
  44. .recalc = bus_clk_recalc,
  45. };
  46. static unsigned long cpu_clk_recalc(struct clk *clk)
  47. {
  48. int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001);
  49. return clk->parent->rate / ifc_divisors[idx];
  50. }
  51. static struct sh_clk_ops sh7780_cpu_clk_ops = {
  52. .recalc = cpu_clk_recalc,
  53. };
  54. static struct sh_clk_ops *sh7780_clk_ops[] = {
  55. &sh7780_master_clk_ops,
  56. &sh7780_module_clk_ops,
  57. &sh7780_bus_clk_ops,
  58. &sh7780_cpu_clk_ops,
  59. };
  60. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  61. {
  62. if (idx < ARRAY_SIZE(sh7780_clk_ops))
  63. *ops = sh7780_clk_ops[idx];
  64. }
  65. static unsigned long shyway_clk_recalc(struct clk *clk)
  66. {
  67. int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007);
  68. return clk->parent->rate / cfc_divisors[idx];
  69. }
  70. static struct sh_clk_ops sh7780_shyway_clk_ops = {
  71. .recalc = shyway_clk_recalc,
  72. };
  73. static struct clk sh7780_shyway_clk = {
  74. .flags = CLK_ENABLE_ON_INIT,
  75. .ops = &sh7780_shyway_clk_ops,
  76. };
  77. /*
  78. * Additional SH7780-specific on-chip clocks that aren't already part of the
  79. * clock framework
  80. */
  81. static struct clk *sh7780_onchip_clocks[] = {
  82. &sh7780_shyway_clk,
  83. };
  84. static struct clk_lookup lookups[] = {
  85. /* main clocks */
  86. CLKDEV_CON_ID("shyway_clk", &sh7780_shyway_clk),
  87. };
  88. int __init arch_clk_init(void)
  89. {
  90. struct clk *clk;
  91. int i, ret = 0;
  92. cpg_clk_init();
  93. clk = clk_get(NULL, "master_clk");
  94. for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
  95. struct clk *clkp = sh7780_onchip_clocks[i];
  96. clkp->parent = clk;
  97. ret |= clk_register(clkp);
  98. }
  99. clk_put(clk);
  100. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  101. return ret;
  102. }