clock-sh73180.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-sh73180.c
  3. *
  4. * SH73180 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. /*
  25. * SH73180 uses a common set of divisors, so this is quite simple..
  26. */
  27. static int divisors[] = { 1, 2, 3, 4, 6, 8, 12, 16 };
  28. static void master_clk_init(struct clk *clk)
  29. {
  30. clk->rate *= divisors[ctrl_inl(FRQCR) & 0x0007];
  31. }
  32. static struct clk_ops sh73180_master_clk_ops = {
  33. .init = master_clk_init,
  34. };
  35. static void module_clk_recalc(struct clk *clk)
  36. {
  37. int idx = (ctrl_inl(FRQCR) & 0x0007);
  38. clk->rate = clk->parent->rate / divisors[idx];
  39. }
  40. static struct clk_ops sh73180_module_clk_ops = {
  41. .recalc = module_clk_recalc,
  42. };
  43. static void bus_clk_recalc(struct clk *clk)
  44. {
  45. int idx = (ctrl_inl(FRQCR) >> 12) & 0x0007;
  46. clk->rate = clk->parent->rate / divisors[idx];
  47. }
  48. static struct clk_ops sh73180_bus_clk_ops = {
  49. .recalc = bus_clk_recalc,
  50. };
  51. static void cpu_clk_recalc(struct clk *clk)
  52. {
  53. int idx = (ctrl_inl(FRQCR) >> 20) & 0x0007;
  54. clk->rate = clk->parent->rate / divisors[idx];
  55. }
  56. static struct clk_ops sh73180_cpu_clk_ops = {
  57. .recalc = cpu_clk_recalc,
  58. };
  59. static struct clk_ops *sh73180_clk_ops[] = {
  60. &sh73180_master_clk_ops,
  61. &sh73180_module_clk_ops,
  62. &sh73180_bus_clk_ops,
  63. &sh73180_cpu_clk_ops,
  64. };
  65. void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
  66. {
  67. if (idx < ARRAY_SIZE(sh73180_clk_ops))
  68. *ops = sh73180_clk_ops[idx];
  69. }