clock-sh7706.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * arch/sh/kernel/cpu/sh3/clock-sh7706.c
  3. *
  4. * SH7706 support for the clock framework
  5. *
  6. * Copyright (C) 2006 Takashi YOSHII
  7. *
  8. * Based on arch/sh/kernel/cpu/sh3/clock-sh7709.c
  9. * Copyright (C) 2005 Andriy Skulysh
  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, 1, 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 master_clk_init(struct clk *clk)
  24. {
  25. int frqcr = __raw_readw(FRQCR);
  26. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  27. clk->rate *= pfc_divisors[idx];
  28. }
  29. static struct sh_clk_ops sh7706_master_clk_ops = {
  30. .init = master_clk_init,
  31. };
  32. static unsigned long module_clk_recalc(struct clk *clk)
  33. {
  34. int frqcr = __raw_readw(FRQCR);
  35. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  36. return clk->parent->rate / pfc_divisors[idx];
  37. }
  38. static struct sh_clk_ops sh7706_module_clk_ops = {
  39. .recalc = module_clk_recalc,
  40. };
  41. static unsigned long bus_clk_recalc(struct clk *clk)
  42. {
  43. int frqcr = __raw_readw(FRQCR);
  44. int idx = ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4);
  45. return clk->parent->rate / stc_multipliers[idx];
  46. }
  47. static struct sh_clk_ops sh7706_bus_clk_ops = {
  48. .recalc = bus_clk_recalc,
  49. };
  50. static unsigned long cpu_clk_recalc(struct clk *clk)
  51. {
  52. int frqcr = __raw_readw(FRQCR);
  53. int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
  54. return clk->parent->rate / ifc_divisors[idx];
  55. }
  56. static struct sh_clk_ops sh7706_cpu_clk_ops = {
  57. .recalc = cpu_clk_recalc,
  58. };
  59. static struct sh_clk_ops *sh7706_clk_ops[] = {
  60. &sh7706_master_clk_ops,
  61. &sh7706_module_clk_ops,
  62. &sh7706_bus_clk_ops,
  63. &sh7706_cpu_clk_ops,
  64. };
  65. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  66. {
  67. if (idx < ARRAY_SIZE(sh7706_clk_ops))
  68. *ops = sh7706_clk_ops[idx];
  69. }