clock-sh7780.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/clock-sh7780.c
  4. *
  5. * SH7780 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 <linux/io.h>
  12. #include <linux/clkdev.h>
  13. #include <asm/clock.h>
  14. #include <asm/freq.h>
  15. #include <asm/io.h>
  16. static int ifc_divisors[] = { 2, 4 };
  17. static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };
  18. static int pfc_divisors[] = { 1, 24, 24, 1 };
  19. static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };
  20. static void master_clk_init(struct clk *clk)
  21. {
  22. clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003];
  23. }
  24. static struct sh_clk_ops sh7780_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) & 0x0003);
  30. return clk->parent->rate / pfc_divisors[idx];
  31. }
  32. static struct sh_clk_ops sh7780_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) & 0x0007);
  38. return clk->parent->rate / bfc_divisors[idx];
  39. }
  40. static struct sh_clk_ops sh7780_bus_clk_ops = {
  41. .recalc = bus_clk_recalc,
  42. };
  43. static unsigned long cpu_clk_recalc(struct clk *clk)
  44. {
  45. int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001);
  46. return clk->parent->rate / ifc_divisors[idx];
  47. }
  48. static struct sh_clk_ops sh7780_cpu_clk_ops = {
  49. .recalc = cpu_clk_recalc,
  50. };
  51. static struct sh_clk_ops *sh7780_clk_ops[] = {
  52. &sh7780_master_clk_ops,
  53. &sh7780_module_clk_ops,
  54. &sh7780_bus_clk_ops,
  55. &sh7780_cpu_clk_ops,
  56. };
  57. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  58. {
  59. if (idx < ARRAY_SIZE(sh7780_clk_ops))
  60. *ops = sh7780_clk_ops[idx];
  61. }
  62. static unsigned long shyway_clk_recalc(struct clk *clk)
  63. {
  64. int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007);
  65. return clk->parent->rate / cfc_divisors[idx];
  66. }
  67. static struct sh_clk_ops sh7780_shyway_clk_ops = {
  68. .recalc = shyway_clk_recalc,
  69. };
  70. static struct clk sh7780_shyway_clk = {
  71. .flags = CLK_ENABLE_ON_INIT,
  72. .ops = &sh7780_shyway_clk_ops,
  73. };
  74. /*
  75. * Additional SH7780-specific on-chip clocks that aren't already part of the
  76. * clock framework
  77. */
  78. static struct clk *sh7780_onchip_clocks[] = {
  79. &sh7780_shyway_clk,
  80. };
  81. static struct clk_lookup lookups[] = {
  82. /* main clocks */
  83. CLKDEV_CON_ID("shyway_clk", &sh7780_shyway_clk),
  84. };
  85. int __init arch_clk_init(void)
  86. {
  87. struct clk *clk;
  88. int i, ret = 0;
  89. cpg_clk_init();
  90. clk = clk_get(NULL, "master_clk");
  91. for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
  92. struct clk *clkp = sh7780_onchip_clocks[i];
  93. clkp->parent = clk;
  94. ret |= clk_register(clkp);
  95. }
  96. clk_put(clk);
  97. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  98. return ret;
  99. }