clock-sh4.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-sh4.c
  3. *
  4. * Generic SH-4 support for the clock framework
  5. *
  6. * Copyright (C) 2005 Paul Mundt
  7. *
  8. * FRQCR parsing hacked out of arch/sh/kernel/time.c
  9. *
  10. * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
  11. * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
  12. * Copyright (C) 2002, 2003, 2004 Paul Mundt
  13. * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file "COPYING" in the main directory of this archive
  17. * for more details.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <asm/clock.h>
  22. #include <asm/freq.h>
  23. #include <asm/io.h>
  24. static int ifc_divisors[] = { 1, 2, 3, 4, 6, 8, 1, 1 };
  25. #define bfc_divisors ifc_divisors /* Same */
  26. static int pfc_divisors[] = { 2, 3, 4, 6, 8, 2, 2, 2 };
  27. static void master_clk_init(struct clk *clk)
  28. {
  29. clk->rate *= pfc_divisors[__raw_readw(FRQCR) & 0x0007];
  30. }
  31. static struct sh_clk_ops sh4_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(FRQCR) & 0x0007);
  37. return clk->parent->rate / pfc_divisors[idx];
  38. }
  39. static struct sh_clk_ops sh4_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(FRQCR) >> 3) & 0x0007;
  45. return clk->parent->rate / bfc_divisors[idx];
  46. }
  47. static struct sh_clk_ops sh4_bus_clk_ops = {
  48. .recalc = bus_clk_recalc,
  49. };
  50. static unsigned long cpu_clk_recalc(struct clk *clk)
  51. {
  52. int idx = (__raw_readw(FRQCR) >> 6) & 0x0007;
  53. return clk->parent->rate / ifc_divisors[idx];
  54. }
  55. static struct sh_clk_ops sh4_cpu_clk_ops = {
  56. .recalc = cpu_clk_recalc,
  57. };
  58. static struct sh_clk_ops *sh4_clk_ops[] = {
  59. &sh4_master_clk_ops,
  60. &sh4_module_clk_ops,
  61. &sh4_bus_clk_ops,
  62. &sh4_cpu_clk_ops,
  63. };
  64. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  65. {
  66. if (idx < ARRAY_SIZE(sh4_clk_ops))
  67. *ops = sh4_clk_ops[idx];
  68. }