clock-sh7710.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh3/clock-sh7710.c
  4. *
  5. * SH7710 support for the clock framework
  6. *
  7. * Copyright (C) 2005 Paul Mundt
  8. *
  9. * FRQCR parsing hacked out of arch/sh/kernel/time.c
  10. *
  11. * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
  12. * Copyright (C) 2000 Philipp Rumpf <[email protected]>
  13. * Copyright (C) 2002, 2003, 2004 Paul Mundt
  14. * Copyright (C) 2002 M. R. Brown <[email protected]>
  15. */
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <asm/clock.h>
  19. #include <asm/freq.h>
  20. #include <asm/io.h>
  21. static int md_table[] = { 1, 2, 3, 4, 6, 8, 12 };
  22. static void master_clk_init(struct clk *clk)
  23. {
  24. clk->rate *= md_table[__raw_readw(FRQCR) & 0x0007];
  25. }
  26. static struct sh_clk_ops sh7710_master_clk_ops = {
  27. .init = master_clk_init,
  28. };
  29. static unsigned long module_clk_recalc(struct clk *clk)
  30. {
  31. int idx = (__raw_readw(FRQCR) & 0x0007);
  32. return clk->parent->rate / md_table[idx];
  33. }
  34. static struct sh_clk_ops sh7710_module_clk_ops = {
  35. .recalc = module_clk_recalc,
  36. };
  37. static unsigned long bus_clk_recalc(struct clk *clk)
  38. {
  39. int idx = (__raw_readw(FRQCR) & 0x0700) >> 8;
  40. return clk->parent->rate / md_table[idx];
  41. }
  42. static struct sh_clk_ops sh7710_bus_clk_ops = {
  43. .recalc = bus_clk_recalc,
  44. };
  45. static unsigned long cpu_clk_recalc(struct clk *clk)
  46. {
  47. int idx = (__raw_readw(FRQCR) & 0x0070) >> 4;
  48. return clk->parent->rate / md_table[idx];
  49. }
  50. static struct sh_clk_ops sh7710_cpu_clk_ops = {
  51. .recalc = cpu_clk_recalc,
  52. };
  53. static struct sh_clk_ops *sh7710_clk_ops[] = {
  54. &sh7710_master_clk_ops,
  55. &sh7710_module_clk_ops,
  56. &sh7710_bus_clk_ops,
  57. &sh7710_cpu_clk_ops,
  58. };
  59. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  60. {
  61. if (idx < ARRAY_SIZE(sh7710_clk_ops))
  62. *ops = sh7710_clk_ops[idx];
  63. }