clock-sh7709.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * arch/sh/kernel/cpu/sh3/clock-sh7709.c
  3. *
  4. * SH7709 support for the clock framework
  5. *
  6. * Copyright (C) 2005 Andriy Skulysh
  7. *
  8. * Based on arch/sh/kernel/cpu/sh3/clock-sh7705.c
  9. * Copyright (C) 2005 Paul Mundt
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file "COPYING" in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <asm/clock.h>
  18. #include <asm/freq.h>
  19. #include <asm/io.h>
  20. static int stc_multipliers[] = { 1, 2, 4, 8, 3, 6, 1, 1 };
  21. static int ifc_divisors[] = { 1, 2, 4, 1, 3, 1, 1, 1 };
  22. static int pfc_divisors[] = { 1, 2, 4, 1, 3, 6, 1, 1 };
  23. static void set_bus_parent(struct clk *clk)
  24. {
  25. struct clk *bus_clk = clk_get(NULL, "bus_clk");
  26. clk->parent = bus_clk;
  27. clk_put(bus_clk);
  28. }
  29. static void master_clk_init(struct clk *clk)
  30. {
  31. int frqcr = ctrl_inw(FRQCR);
  32. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  33. clk->rate *= pfc_divisors[idx];
  34. }
  35. static struct clk_ops sh7709_master_clk_ops = {
  36. .init = master_clk_init,
  37. };
  38. static void module_clk_recalc(struct clk *clk)
  39. {
  40. int frqcr = ctrl_inw(FRQCR);
  41. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  42. clk->rate = clk->parent->rate / pfc_divisors[idx];
  43. }
  44. static struct clk_ops sh7709_module_clk_ops = {
  45. #ifdef CLOCK_MODE_0_1_2_7
  46. .init = set_bus_parent,
  47. #endif
  48. .recalc = module_clk_recalc,
  49. };
  50. static void bus_clk_recalc(struct clk *clk)
  51. {
  52. int frqcr = ctrl_inw(FRQCR);
  53. int idx = (frqcr & 0x0080) ?
  54. ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1;
  55. clk->rate = clk->parent->rate * stc_multipliers[idx];
  56. }
  57. static struct clk_ops sh7709_bus_clk_ops = {
  58. .recalc = bus_clk_recalc,
  59. };
  60. static void cpu_clk_recalc(struct clk *clk)
  61. {
  62. int frqcr = ctrl_inw(FRQCR);
  63. int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
  64. clk->rate = clk->parent->rate / ifc_divisors[idx];
  65. }
  66. static struct clk_ops sh7709_cpu_clk_ops = {
  67. .init = set_bus_parent,
  68. .recalc = cpu_clk_recalc,
  69. };
  70. static struct clk_ops *sh7709_clk_ops[] = {
  71. &sh7709_master_clk_ops,
  72. &sh7709_module_clk_ops,
  73. &sh7709_bus_clk_ops,
  74. &sh7709_cpu_clk_ops,
  75. };
  76. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  77. {
  78. if (idx < ARRAY_SIZE(sh7709_clk_ops))
  79. *ops = sh7709_clk_ops[idx];
  80. }