clock-sh7763.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/clock-sh7763.c
  4. *
  5. * SH7763 support for the clock framework
  6. *
  7. * Copyright (C) 2005 Paul Mundt
  8. * Copyright (C) 2007 Yoshihiro Shimoda
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/io.h>
  13. #include <linux/clkdev.h>
  14. #include <asm/clock.h>
  15. #include <asm/freq.h>
  16. #include <asm/io.h>
  17. static int bfc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  18. static int p0fc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  19. static int cfc_divisors[] = { 1, 1, 4, 1, 1, 1, 1, 1 };
  20. static void master_clk_init(struct clk *clk)
  21. {
  22. clk->rate *= p0fc_divisors[(__raw_readl(FRQCR) >> 4) & 0x07];
  23. }
  24. static struct sh_clk_ops sh7763_master_clk_ops = {
  25. .init = master_clk_init,
  26. };
  27. static unsigned long module_clk_recalc(struct clk *clk)
  28. {
  29. int idx = ((__raw_readl(FRQCR) >> 4) & 0x07);
  30. return clk->parent->rate / p0fc_divisors[idx];
  31. }
  32. static struct sh_clk_ops sh7763_module_clk_ops = {
  33. .recalc = module_clk_recalc,
  34. };
  35. static unsigned long bus_clk_recalc(struct clk *clk)
  36. {
  37. int idx = ((__raw_readl(FRQCR) >> 16) & 0x07);
  38. return clk->parent->rate / bfc_divisors[idx];
  39. }
  40. static struct sh_clk_ops sh7763_bus_clk_ops = {
  41. .recalc = bus_clk_recalc,
  42. };
  43. static struct sh_clk_ops sh7763_cpu_clk_ops = {
  44. .recalc = followparent_recalc,
  45. };
  46. static struct sh_clk_ops *sh7763_clk_ops[] = {
  47. &sh7763_master_clk_ops,
  48. &sh7763_module_clk_ops,
  49. &sh7763_bus_clk_ops,
  50. &sh7763_cpu_clk_ops,
  51. };
  52. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  53. {
  54. if (idx < ARRAY_SIZE(sh7763_clk_ops))
  55. *ops = sh7763_clk_ops[idx];
  56. }
  57. static unsigned long shyway_clk_recalc(struct clk *clk)
  58. {
  59. int idx = ((__raw_readl(FRQCR) >> 20) & 0x07);
  60. return clk->parent->rate / cfc_divisors[idx];
  61. }
  62. static struct sh_clk_ops sh7763_shyway_clk_ops = {
  63. .recalc = shyway_clk_recalc,
  64. };
  65. static struct clk sh7763_shyway_clk = {
  66. .flags = CLK_ENABLE_ON_INIT,
  67. .ops = &sh7763_shyway_clk_ops,
  68. };
  69. /*
  70. * Additional SH7763-specific on-chip clocks that aren't already part of the
  71. * clock framework
  72. */
  73. static struct clk *sh7763_onchip_clocks[] = {
  74. &sh7763_shyway_clk,
  75. };
  76. static struct clk_lookup lookups[] = {
  77. /* main clocks */
  78. CLKDEV_CON_ID("shyway_clk", &sh7763_shyway_clk),
  79. };
  80. int __init arch_clk_init(void)
  81. {
  82. struct clk *clk;
  83. int i, ret = 0;
  84. cpg_clk_init();
  85. clk = clk_get(NULL, "master_clk");
  86. for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
  87. struct clk *clkp = sh7763_onchip_clocks[i];
  88. clkp->parent = clk;
  89. ret |= clk_register(clkp);
  90. }
  91. clk_put(clk);
  92. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  93. return ret;
  94. }