armada-370.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Marvell Armada 370 SoC clocks
  4. *
  5. * Copyright (C) 2012 Marvell
  6. *
  7. * Gregory CLEMENT <[email protected]>
  8. * Sebastian Hesselbarth <[email protected]>
  9. * Andrew Lunn <[email protected]>
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/io.h>
  15. #include <linux/of.h>
  16. #include "common.h"
  17. /*
  18. * Core Clocks
  19. */
  20. #define SARL 0 /* Low part [0:31] */
  21. #define SARL_A370_SSCG_ENABLE BIT(10)
  22. #define SARL_A370_PCLK_FREQ_OPT 11
  23. #define SARL_A370_PCLK_FREQ_OPT_MASK 0xF
  24. #define SARL_A370_FAB_FREQ_OPT 15
  25. #define SARL_A370_FAB_FREQ_OPT_MASK 0x1F
  26. #define SARL_A370_TCLK_FREQ_OPT 20
  27. #define SARL_A370_TCLK_FREQ_OPT_MASK 0x1
  28. enum { A370_CPU_TO_NBCLK, A370_CPU_TO_HCLK, A370_CPU_TO_DRAMCLK };
  29. static const struct coreclk_ratio a370_coreclk_ratios[] __initconst = {
  30. { .id = A370_CPU_TO_NBCLK, .name = "nbclk" },
  31. { .id = A370_CPU_TO_HCLK, .name = "hclk" },
  32. { .id = A370_CPU_TO_DRAMCLK, .name = "dramclk" },
  33. };
  34. static const u32 a370_tclk_freqs[] __initconst = {
  35. 166000000,
  36. 200000000,
  37. };
  38. static u32 __init a370_get_tclk_freq(void __iomem *sar)
  39. {
  40. u8 tclk_freq_select = 0;
  41. tclk_freq_select = ((readl(sar) >> SARL_A370_TCLK_FREQ_OPT) &
  42. SARL_A370_TCLK_FREQ_OPT_MASK);
  43. return a370_tclk_freqs[tclk_freq_select];
  44. }
  45. static const u32 a370_cpu_freqs[] __initconst = {
  46. 400000000,
  47. 533000000,
  48. 667000000,
  49. 800000000,
  50. 1000000000,
  51. 1067000000,
  52. 1200000000,
  53. };
  54. static u32 __init a370_get_cpu_freq(void __iomem *sar)
  55. {
  56. u32 cpu_freq;
  57. u8 cpu_freq_select = 0;
  58. cpu_freq_select = ((readl(sar) >> SARL_A370_PCLK_FREQ_OPT) &
  59. SARL_A370_PCLK_FREQ_OPT_MASK);
  60. if (cpu_freq_select >= ARRAY_SIZE(a370_cpu_freqs)) {
  61. pr_err("CPU freq select unsupported %d\n", cpu_freq_select);
  62. cpu_freq = 0;
  63. } else
  64. cpu_freq = a370_cpu_freqs[cpu_freq_select];
  65. return cpu_freq;
  66. }
  67. static const int a370_nbclk_ratios[32][2] __initconst = {
  68. {0, 1}, {1, 2}, {2, 2}, {2, 2},
  69. {1, 2}, {1, 2}, {1, 1}, {2, 3},
  70. {0, 1}, {1, 2}, {2, 4}, {0, 1},
  71. {1, 2}, {0, 1}, {0, 1}, {2, 2},
  72. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  73. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  74. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  75. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  76. };
  77. static const int a370_hclk_ratios[32][2] __initconst = {
  78. {0, 1}, {1, 2}, {2, 6}, {2, 3},
  79. {1, 3}, {1, 4}, {1, 2}, {2, 6},
  80. {0, 1}, {1, 6}, {2, 10}, {0, 1},
  81. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  82. {0, 1}, {0, 1}, {0, 1}, {1, 2},
  83. {2, 6}, {0, 1}, {0, 1}, {0, 1},
  84. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  85. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  86. };
  87. static const int a370_dramclk_ratios[32][2] __initconst = {
  88. {0, 1}, {1, 2}, {2, 3}, {2, 3},
  89. {1, 3}, {1, 2}, {1, 2}, {2, 6},
  90. {0, 1}, {1, 3}, {2, 5}, {0, 1},
  91. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  92. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  93. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  94. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  95. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  96. };
  97. static void __init a370_get_clk_ratio(
  98. void __iomem *sar, int id, int *mult, int *div)
  99. {
  100. u32 opt = ((readl(sar) >> SARL_A370_FAB_FREQ_OPT) &
  101. SARL_A370_FAB_FREQ_OPT_MASK);
  102. switch (id) {
  103. case A370_CPU_TO_NBCLK:
  104. *mult = a370_nbclk_ratios[opt][0];
  105. *div = a370_nbclk_ratios[opt][1];
  106. break;
  107. case A370_CPU_TO_HCLK:
  108. *mult = a370_hclk_ratios[opt][0];
  109. *div = a370_hclk_ratios[opt][1];
  110. break;
  111. case A370_CPU_TO_DRAMCLK:
  112. *mult = a370_dramclk_ratios[opt][0];
  113. *div = a370_dramclk_ratios[opt][1];
  114. break;
  115. }
  116. }
  117. static bool a370_is_sscg_enabled(void __iomem *sar)
  118. {
  119. return !(readl(sar) & SARL_A370_SSCG_ENABLE);
  120. }
  121. static const struct coreclk_soc_desc a370_coreclks = {
  122. .get_tclk_freq = a370_get_tclk_freq,
  123. .get_cpu_freq = a370_get_cpu_freq,
  124. .get_clk_ratio = a370_get_clk_ratio,
  125. .is_sscg_enabled = a370_is_sscg_enabled,
  126. .fix_sscg_deviation = kirkwood_fix_sscg_deviation,
  127. .ratios = a370_coreclk_ratios,
  128. .num_ratios = ARRAY_SIZE(a370_coreclk_ratios),
  129. };
  130. /*
  131. * Clock Gating Control
  132. */
  133. static const struct clk_gating_soc_desc a370_gating_desc[] __initconst = {
  134. { "audio", NULL, 0, 0 },
  135. { "pex0_en", NULL, 1, 0 },
  136. { "pex1_en", NULL, 2, 0 },
  137. { "ge1", NULL, 3, 0 },
  138. { "ge0", NULL, 4, 0 },
  139. { "pex0", "pex0_en", 5, 0 },
  140. { "pex1", "pex1_en", 9, 0 },
  141. { "sata0", NULL, 15, 0 },
  142. { "sdio", NULL, 17, 0 },
  143. { "crypto", NULL, 23, CLK_IGNORE_UNUSED },
  144. { "tdm", NULL, 25, 0 },
  145. { "ddr", NULL, 28, CLK_IGNORE_UNUSED },
  146. { "sata1", NULL, 30, 0 },
  147. { }
  148. };
  149. static void __init a370_clk_init(struct device_node *np)
  150. {
  151. struct device_node *cgnp =
  152. of_find_compatible_node(NULL, NULL, "marvell,armada-370-gating-clock");
  153. mvebu_coreclk_setup(np, &a370_coreclks);
  154. if (cgnp) {
  155. mvebu_clk_gating_setup(cgnp, a370_gating_desc);
  156. of_node_put(cgnp);
  157. }
  158. }
  159. CLK_OF_DECLARE(a370_clk, "marvell,armada-370-core-clock", a370_clk_init);