clock-sh7201.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh2a/clock-sh7201.c
  4. *
  5. * SH7201 support for the clock framework
  6. *
  7. * Copyright (C) 2008 Peter Griffin <[email protected]>
  8. *
  9. * Based on clock-sh4.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 const int pll1rate[]={1,2,3,4,6,8};
  18. static const int pfc_divisors[]={1,2,3,4,6,8,12};
  19. #define ifc_divisors pfc_divisors
  20. static unsigned int pll2_mult;
  21. static void master_clk_init(struct clk *clk)
  22. {
  23. clk->rate = 10000000 * pll2_mult *
  24. pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0007];
  25. }
  26. static struct sh_clk_ops sh7201_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(FREQCR) & 0x0007);
  32. return clk->parent->rate / pfc_divisors[idx];
  33. }
  34. static struct sh_clk_ops sh7201_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(FREQCR) & 0x0007);
  40. return clk->parent->rate / pfc_divisors[idx];
  41. }
  42. static struct sh_clk_ops sh7201_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(FREQCR) >> 4) & 0x0007);
  48. return clk->parent->rate / ifc_divisors[idx];
  49. }
  50. static struct sh_clk_ops sh7201_cpu_clk_ops = {
  51. .recalc = cpu_clk_recalc,
  52. };
  53. static struct sh_clk_ops *sh7201_clk_ops[] = {
  54. &sh7201_master_clk_ops,
  55. &sh7201_module_clk_ops,
  56. &sh7201_bus_clk_ops,
  57. &sh7201_cpu_clk_ops,
  58. };
  59. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  60. {
  61. if (test_mode_pin(MODE_PIN1 | MODE_PIN0))
  62. pll2_mult = 1;
  63. else if (test_mode_pin(MODE_PIN1))
  64. pll2_mult = 2;
  65. else
  66. pll2_mult = 4;
  67. if (idx < ARRAY_SIZE(sh7201_clk_ops))
  68. *ops = sh7201_clk_ops[idx];
  69. }