clock-sh7770.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/clock-sh7770.c
  4. *
  5. * SH7770 support for the clock framework
  6. *
  7. * Copyright (C) 2005 Paul Mundt
  8. */
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <asm/clock.h>
  12. #include <asm/freq.h>
  13. #include <asm/io.h>
  14. static int ifc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
  15. static int bfc_divisors[] = { 1, 1, 1, 1, 1, 8,12, 1 };
  16. static int pfc_divisors[] = { 1, 8, 1,10,12,16, 1, 1 };
  17. static void master_clk_init(struct clk *clk)
  18. {
  19. clk->rate *= pfc_divisors[(__raw_readl(FRQCR) >> 28) & 0x000f];
  20. }
  21. static struct sh_clk_ops sh7770_master_clk_ops = {
  22. .init = master_clk_init,
  23. };
  24. static unsigned long module_clk_recalc(struct clk *clk)
  25. {
  26. int idx = ((__raw_readl(FRQCR) >> 28) & 0x000f);
  27. return clk->parent->rate / pfc_divisors[idx];
  28. }
  29. static struct sh_clk_ops sh7770_module_clk_ops = {
  30. .recalc = module_clk_recalc,
  31. };
  32. static unsigned long bus_clk_recalc(struct clk *clk)
  33. {
  34. int idx = (__raw_readl(FRQCR) & 0x000f);
  35. return clk->parent->rate / bfc_divisors[idx];
  36. }
  37. static struct sh_clk_ops sh7770_bus_clk_ops = {
  38. .recalc = bus_clk_recalc,
  39. };
  40. static unsigned long cpu_clk_recalc(struct clk *clk)
  41. {
  42. int idx = ((__raw_readl(FRQCR) >> 24) & 0x000f);
  43. return clk->parent->rate / ifc_divisors[idx];
  44. }
  45. static struct sh_clk_ops sh7770_cpu_clk_ops = {
  46. .recalc = cpu_clk_recalc,
  47. };
  48. static struct sh_clk_ops *sh7770_clk_ops[] = {
  49. &sh7770_master_clk_ops,
  50. &sh7770_module_clk_ops,
  51. &sh7770_bus_clk_ops,
  52. &sh7770_cpu_clk_ops,
  53. };
  54. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  55. {
  56. if (idx < ARRAY_SIZE(sh7770_clk_ops))
  57. *ops = sh7770_clk_ops[idx];
  58. }