clock-sh7203.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * arch/sh/kernel/cpu/sh2a/clock-sh7203.c
  3. *
  4. * SH7203 support for the clock framework
  5. *
  6. * Copyright (C) 2007 Kieran Bingham (MPC-Data Ltd)
  7. *
  8. * Based on clock-sh7263.c
  9. * Copyright (C) 2006 Yoshinori Sato
  10. *
  11. * Based on clock-sh4.c
  12. * Copyright (C) 2005 Paul Mundt
  13. *
  14. * This file is subject to the terms and conditions of the GNU General Public
  15. * License. See the file "COPYING" in the main directory of this archive
  16. * for more details.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <asm/clock.h>
  21. #include <asm/freq.h>
  22. #include <asm/io.h>
  23. static const int pll1rate[]={8,12,16,0};
  24. static const int pfc_divisors[]={1,2,3,4,6,8,12};
  25. #define ifc_divisors pfc_divisors
  26. static unsigned int pll2_mult;
  27. static void master_clk_init(struct clk *clk)
  28. {
  29. clk->rate *= pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0003] * pll2_mult;
  30. }
  31. static struct sh_clk_ops sh7203_master_clk_ops = {
  32. .init = master_clk_init,
  33. };
  34. static unsigned long module_clk_recalc(struct clk *clk)
  35. {
  36. int idx = (__raw_readw(FREQCR) & 0x0007);
  37. return clk->parent->rate / pfc_divisors[idx];
  38. }
  39. static struct sh_clk_ops sh7203_module_clk_ops = {
  40. .recalc = module_clk_recalc,
  41. };
  42. static unsigned long bus_clk_recalc(struct clk *clk)
  43. {
  44. int idx = (__raw_readw(FREQCR) & 0x0007);
  45. return clk->parent->rate / pfc_divisors[idx-2];
  46. }
  47. static struct sh_clk_ops sh7203_bus_clk_ops = {
  48. .recalc = bus_clk_recalc,
  49. };
  50. static struct sh_clk_ops sh7203_cpu_clk_ops = {
  51. .recalc = followparent_recalc,
  52. };
  53. static struct sh_clk_ops *sh7203_clk_ops[] = {
  54. &sh7203_master_clk_ops,
  55. &sh7203_module_clk_ops,
  56. &sh7203_bus_clk_ops,
  57. &sh7203_cpu_clk_ops,
  58. };
  59. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  60. {
  61. if (test_mode_pin(MODE_PIN1))
  62. pll2_mult = 4;
  63. else if (test_mode_pin(MODE_PIN0))
  64. pll2_mult = 2;
  65. else
  66. pll2_mult = 1;
  67. if (idx < ARRAY_SIZE(sh7203_clk_ops))
  68. *ops = sh7203_clk_ops[idx];
  69. }