clock-sh7203.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #if (CONFIG_SH_CLK_MD == 0)
  27. #define PLL2 (1)
  28. #elif (CONFIG_SH_CLK_MD == 1)
  29. #define PLL2 (2)
  30. #elif (CONFIG_SH_CLK_MD == 2)
  31. #define PLL2 (4)
  32. #elif (CONFIG_SH_CLK_MD == 3)
  33. #define PLL2 (4)
  34. #else
  35. #error "Illegal Clock Mode!"
  36. #endif
  37. static void master_clk_init(struct clk *clk)
  38. {
  39. clk->rate *= pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0003] * PLL2 ;
  40. }
  41. static struct clk_ops sh7203_master_clk_ops = {
  42. .init = master_clk_init,
  43. };
  44. static void module_clk_recalc(struct clk *clk)
  45. {
  46. int idx = (ctrl_inw(FREQCR) & 0x0007);
  47. clk->rate = clk->parent->rate / pfc_divisors[idx];
  48. }
  49. static struct clk_ops sh7203_module_clk_ops = {
  50. .recalc = module_clk_recalc,
  51. };
  52. static void bus_clk_recalc(struct clk *clk)
  53. {
  54. int idx = (ctrl_inw(FREQCR) & 0x0007);
  55. clk->rate = clk->parent->rate / pfc_divisors[idx-2];
  56. }
  57. static struct clk_ops sh7203_bus_clk_ops = {
  58. .recalc = bus_clk_recalc,
  59. };
  60. static void cpu_clk_recalc(struct clk *clk)
  61. {
  62. clk->rate = clk->parent->rate;
  63. }
  64. static struct clk_ops sh7203_cpu_clk_ops = {
  65. .recalc = cpu_clk_recalc,
  66. };
  67. static struct clk_ops *sh7203_clk_ops[] = {
  68. &sh7203_master_clk_ops,
  69. &sh7203_module_clk_ops,
  70. &sh7203_bus_clk_ops,
  71. &sh7203_cpu_clk_ops,
  72. };
  73. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  74. {
  75. if (idx < ARRAY_SIZE(sh7203_clk_ops))
  76. *ops = sh7203_clk_ops[idx];
  77. }