clock-sh7201.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * arch/sh/kernel/cpu/sh2a/clock-sh7201.c
  3. *
  4. * SH7201 support for the clock framework
  5. *
  6. * Copyright (C) 2008 Peter Griffin <pgriffin@mpc-data.co.uk>
  7. *
  8. * Based on clock-sh4.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 const int pll1rate[]={1,2,3,4,6,8};
  21. static const int pfc_divisors[]={1,2,3,4,6,8,12};
  22. #define ifc_divisors pfc_divisors
  23. #if (CONFIG_SH_CLK_MD == 0)
  24. #define PLL2 (4)
  25. #elif (CONFIG_SH_CLK_MD == 2)
  26. #define PLL2 (2)
  27. #elif (CONFIG_SH_CLK_MD == 3)
  28. #define PLL2 (1)
  29. #else
  30. #error "Illegal Clock Mode!"
  31. #endif
  32. static void master_clk_init(struct clk *clk)
  33. {
  34. clk->rate = 10000000 * PLL2 * pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0007];
  35. }
  36. static struct clk_ops sh7201_master_clk_ops = {
  37. .init = master_clk_init,
  38. };
  39. static void module_clk_recalc(struct clk *clk)
  40. {
  41. int idx = (ctrl_inw(FREQCR) & 0x0007);
  42. clk->rate = clk->parent->rate / pfc_divisors[idx];
  43. }
  44. static struct clk_ops sh7201_module_clk_ops = {
  45. .recalc = module_clk_recalc,
  46. };
  47. static void bus_clk_recalc(struct clk *clk)
  48. {
  49. int idx = (ctrl_inw(FREQCR) & 0x0007);
  50. clk->rate = clk->parent->rate / pfc_divisors[idx];
  51. }
  52. static struct clk_ops sh7201_bus_clk_ops = {
  53. .recalc = bus_clk_recalc,
  54. };
  55. static void cpu_clk_recalc(struct clk *clk)
  56. {
  57. int idx = ((ctrl_inw(FREQCR) >> 4) & 0x0007);
  58. clk->rate = clk->parent->rate / ifc_divisors[idx];
  59. }
  60. static struct clk_ops sh7201_cpu_clk_ops = {
  61. .recalc = cpu_clk_recalc,
  62. };
  63. static struct clk_ops *sh7201_clk_ops[] = {
  64. &sh7201_master_clk_ops,
  65. &sh7201_module_clk_ops,
  66. &sh7201_bus_clk_ops,
  67. &sh7201_cpu_clk_ops,
  68. };
  69. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  70. {
  71. if (idx < ARRAY_SIZE(sh7201_clk_ops))
  72. *ops = sh7201_clk_ops[idx];
  73. }