clock-sh7203.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh2a/clock-sh7203.c
  4. *
  5. * SH7203 support for the clock framework
  6. *
  7. * Copyright (C) 2007 Kieran Bingham (MPC-Data Ltd)
  8. *
  9. * Based on clock-sh7263.c
  10. * Copyright (C) 2006 Yoshinori Sato
  11. *
  12. * Based on clock-sh4.c
  13. * Copyright (C) 2005 Paul Mundt
  14. */
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <asm/clock.h>
  18. #include <asm/freq.h>
  19. #include <asm/io.h>
  20. static const int pll1rate[]={8,12,16,0};
  21. static const int pfc_divisors[]={1,2,3,4,6,8,12};
  22. #define ifc_divisors pfc_divisors
  23. static unsigned int pll2_mult;
  24. static void master_clk_init(struct clk *clk)
  25. {
  26. clk->rate *= pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0003] * pll2_mult;
  27. }
  28. static struct sh_clk_ops sh7203_master_clk_ops = {
  29. .init = master_clk_init,
  30. };
  31. static unsigned long module_clk_recalc(struct clk *clk)
  32. {
  33. int idx = (__raw_readw(FREQCR) & 0x0007);
  34. return clk->parent->rate / pfc_divisors[idx];
  35. }
  36. static struct sh_clk_ops sh7203_module_clk_ops = {
  37. .recalc = module_clk_recalc,
  38. };
  39. static unsigned long bus_clk_recalc(struct clk *clk)
  40. {
  41. int idx = (__raw_readw(FREQCR) & 0x0007);
  42. return clk->parent->rate / pfc_divisors[idx-2];
  43. }
  44. static struct sh_clk_ops sh7203_bus_clk_ops = {
  45. .recalc = bus_clk_recalc,
  46. };
  47. static struct sh_clk_ops sh7203_cpu_clk_ops = {
  48. .recalc = followparent_recalc,
  49. };
  50. static struct sh_clk_ops *sh7203_clk_ops[] = {
  51. &sh7203_master_clk_ops,
  52. &sh7203_module_clk_ops,
  53. &sh7203_bus_clk_ops,
  54. &sh7203_cpu_clk_ops,
  55. };
  56. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  57. {
  58. if (test_mode_pin(MODE_PIN1))
  59. pll2_mult = 4;
  60. else if (test_mode_pin(MODE_PIN0))
  61. pll2_mult = 2;
  62. else
  63. pll2_mult = 1;
  64. if (idx < ARRAY_SIZE(sh7203_clk_ops))
  65. *ops = sh7203_clk_ops[idx];
  66. }