clock-sh7780.c 2.6 KB

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