clock-sh7709.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh3/clock-sh7709.c
  4. *
  5. * SH7709 support for the clock framework
  6. *
  7. * Copyright (C) 2005 Andriy Skulysh
  8. *
  9. * Based on arch/sh/kernel/cpu/sh3/clock-sh7705.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 stc_multipliers[] = { 1, 2, 4, 8, 3, 6, 1, 1 };
  18. static int ifc_divisors[] = { 1, 2, 4, 1, 3, 1, 1, 1 };
  19. static int pfc_divisors[] = { 1, 2, 4, 1, 3, 6, 1, 1 };
  20. static void master_clk_init(struct clk *clk)
  21. {
  22. int frqcr = __raw_readw(FRQCR);
  23. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  24. clk->rate *= pfc_divisors[idx];
  25. }
  26. static struct sh_clk_ops sh7709_master_clk_ops = {
  27. .init = master_clk_init,
  28. };
  29. static unsigned long module_clk_recalc(struct clk *clk)
  30. {
  31. int frqcr = __raw_readw(FRQCR);
  32. int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
  33. return clk->parent->rate / pfc_divisors[idx];
  34. }
  35. static struct sh_clk_ops sh7709_module_clk_ops = {
  36. .recalc = module_clk_recalc,
  37. };
  38. static unsigned long bus_clk_recalc(struct clk *clk)
  39. {
  40. int frqcr = __raw_readw(FRQCR);
  41. int idx = (frqcr & 0x0080) ?
  42. ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1;
  43. return clk->parent->rate * stc_multipliers[idx];
  44. }
  45. static struct sh_clk_ops sh7709_bus_clk_ops = {
  46. .recalc = bus_clk_recalc,
  47. };
  48. static unsigned long cpu_clk_recalc(struct clk *clk)
  49. {
  50. int frqcr = __raw_readw(FRQCR);
  51. int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
  52. return clk->parent->rate / ifc_divisors[idx];
  53. }
  54. static struct sh_clk_ops sh7709_cpu_clk_ops = {
  55. .recalc = cpu_clk_recalc,
  56. };
  57. static struct sh_clk_ops *sh7709_clk_ops[] = {
  58. &sh7709_master_clk_ops,
  59. &sh7709_module_clk_ops,
  60. &sh7709_bus_clk_ops,
  61. &sh7709_cpu_clk_ops,
  62. };
  63. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  64. {
  65. if (idx < ARRAY_SIZE(sh7709_clk_ops))
  66. *ops = sh7709_clk_ops[idx];
  67. }