clock-sh7712.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh3/clock-sh7712.c
  4. *
  5. * SH7712 support for the clock framework
  6. *
  7. * Copyright (C) 2007 Andrew Murray <[email protected]>
  8. *
  9. * Based on arch/sh/kernel/cpu/sh3/clock-sh3.c
  10. * Copyright (C) 2005 Paul Mundt
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <asm/clock.h>
  15. #include <asm/freq.h>
  16. #include <asm/io.h>
  17. static int multipliers[] = { 1, 2, 3 };
  18. static int divisors[] = { 1, 2, 3, 4, 6 };
  19. static void master_clk_init(struct clk *clk)
  20. {
  21. int frqcr = __raw_readw(FRQCR);
  22. int idx = (frqcr & 0x0300) >> 8;
  23. clk->rate *= multipliers[idx];
  24. }
  25. static struct sh_clk_ops sh7712_master_clk_ops = {
  26. .init = master_clk_init,
  27. };
  28. static unsigned long module_clk_recalc(struct clk *clk)
  29. {
  30. int frqcr = __raw_readw(FRQCR);
  31. int idx = frqcr & 0x0007;
  32. return clk->parent->rate / divisors[idx];
  33. }
  34. static struct sh_clk_ops sh7712_module_clk_ops = {
  35. .recalc = module_clk_recalc,
  36. };
  37. static unsigned long cpu_clk_recalc(struct clk *clk)
  38. {
  39. int frqcr = __raw_readw(FRQCR);
  40. int idx = (frqcr & 0x0030) >> 4;
  41. return clk->parent->rate / divisors[idx];
  42. }
  43. static struct sh_clk_ops sh7712_cpu_clk_ops = {
  44. .recalc = cpu_clk_recalc,
  45. };
  46. static struct sh_clk_ops *sh7712_clk_ops[] = {
  47. &sh7712_master_clk_ops,
  48. &sh7712_module_clk_ops,
  49. &sh7712_cpu_clk_ops,
  50. };
  51. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  52. {
  53. if (idx < ARRAY_SIZE(sh7712_clk_ops))
  54. *ops = sh7712_clk_ops[idx];
  55. }