armada-375.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Marvell Armada 375 SoC clocks
  3. *
  4. * Copyright (C) 2014 Marvell
  5. *
  6. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  7. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  8. * Andrew Lunn <andrew@lunn.ch>
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/io.h>
  17. #include <linux/of.h>
  18. #include "common.h"
  19. /*
  20. * Core Clocks
  21. */
  22. /*
  23. * For the Armada 375 SoCs, the CPU, DDR and L2 clocks frequencies are
  24. * all modified at the same time, and not separately as for the Armada
  25. * 370 or the Armada XP SoCs.
  26. *
  27. * SAR1[21:17] : CPU frequency DDR frequency L2 frequency
  28. * 6 = 400 MHz 400 MHz 200 MHz
  29. * 15 = 600 MHz 600 MHz 300 MHz
  30. * 21 = 800 MHz 534 MHz 400 MHz
  31. * 25 = 1000 MHz 500 MHz 500 MHz
  32. * others reserved.
  33. *
  34. * SAR1[22] : TCLK frequency
  35. * 0 = 166 MHz
  36. * 1 = 200 MHz
  37. */
  38. #define SAR1_A375_TCLK_FREQ_OPT 22
  39. #define SAR1_A375_TCLK_FREQ_OPT_MASK 0x1
  40. #define SAR1_A375_CPU_DDR_L2_FREQ_OPT 17
  41. #define SAR1_A375_CPU_DDR_L2_FREQ_OPT_MASK 0x1F
  42. static const u32 armada_375_tclk_frequencies[] __initconst = {
  43. 166000000,
  44. 200000000,
  45. };
  46. static u32 __init armada_375_get_tclk_freq(void __iomem *sar)
  47. {
  48. u8 tclk_freq_select;
  49. tclk_freq_select = ((readl(sar) >> SAR1_A375_TCLK_FREQ_OPT) &
  50. SAR1_A375_TCLK_FREQ_OPT_MASK);
  51. return armada_375_tclk_frequencies[tclk_freq_select];
  52. }
  53. static const u32 armada_375_cpu_frequencies[] __initconst = {
  54. 0, 0, 0, 0, 0, 0,
  55. 400000000,
  56. 0, 0, 0, 0, 0, 0, 0, 0,
  57. 600000000,
  58. 0, 0, 0, 0, 0,
  59. 800000000,
  60. 0, 0, 0,
  61. 1000000000,
  62. };
  63. static u32 __init armada_375_get_cpu_freq(void __iomem *sar)
  64. {
  65. u8 cpu_freq_select;
  66. cpu_freq_select = ((readl(sar) >> SAR1_A375_CPU_DDR_L2_FREQ_OPT) &
  67. SAR1_A375_CPU_DDR_L2_FREQ_OPT_MASK);
  68. if (cpu_freq_select >= ARRAY_SIZE(armada_375_cpu_frequencies)) {
  69. pr_err("Selected CPU frequency (%d) unsupported\n",
  70. cpu_freq_select);
  71. return 0;
  72. } else
  73. return armada_375_cpu_frequencies[cpu_freq_select];
  74. }
  75. enum { A375_CPU_TO_DDR, A375_CPU_TO_L2 };
  76. static const struct coreclk_ratio armada_375_coreclk_ratios[] __initconst = {
  77. { .id = A375_CPU_TO_L2, .name = "l2clk" },
  78. { .id = A375_CPU_TO_DDR, .name = "ddrclk" },
  79. };
  80. static const int armada_375_cpu_l2_ratios[32][2] __initconst = {
  81. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  82. {0, 1}, {0, 1}, {1, 2}, {0, 1},
  83. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  84. {0, 1}, {0, 1}, {0, 1}, {1, 2},
  85. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  86. {0, 1}, {1, 2}, {0, 1}, {0, 1},
  87. {0, 1}, {1, 2}, {0, 1}, {0, 1},
  88. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  89. };
  90. static const int armada_375_cpu_ddr_ratios[32][2] __initconst = {
  91. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  92. {0, 1}, {0, 1}, {1, 1}, {0, 1},
  93. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  94. {0, 1}, {0, 1}, {0, 1}, {2, 3},
  95. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  96. {0, 1}, {2, 3}, {0, 1}, {0, 1},
  97. {0, 1}, {1, 2}, {0, 1}, {0, 1},
  98. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  99. };
  100. static void __init armada_375_get_clk_ratio(
  101. void __iomem *sar, int id, int *mult, int *div)
  102. {
  103. u32 opt = ((readl(sar) >> SAR1_A375_CPU_DDR_L2_FREQ_OPT) &
  104. SAR1_A375_CPU_DDR_L2_FREQ_OPT_MASK);
  105. switch (id) {
  106. case A375_CPU_TO_L2:
  107. *mult = armada_375_cpu_l2_ratios[opt][0];
  108. *div = armada_375_cpu_l2_ratios[opt][1];
  109. break;
  110. case A375_CPU_TO_DDR:
  111. *mult = armada_375_cpu_ddr_ratios[opt][0];
  112. *div = armada_375_cpu_ddr_ratios[opt][1];
  113. break;
  114. }
  115. }
  116. static const struct coreclk_soc_desc armada_375_coreclks = {
  117. .get_tclk_freq = armada_375_get_tclk_freq,
  118. .get_cpu_freq = armada_375_get_cpu_freq,
  119. .get_clk_ratio = armada_375_get_clk_ratio,
  120. .ratios = armada_375_coreclk_ratios,
  121. .num_ratios = ARRAY_SIZE(armada_375_coreclk_ratios),
  122. };
  123. static void __init armada_375_coreclk_init(struct device_node *np)
  124. {
  125. mvebu_coreclk_setup(np, &armada_375_coreclks);
  126. }
  127. CLK_OF_DECLARE(armada_375_core_clk, "marvell,armada-375-core-clock",
  128. armada_375_coreclk_init);
  129. /*
  130. * Clock Gating Control
  131. */
  132. static const struct clk_gating_soc_desc armada_375_gating_desc[] __initconst = {
  133. { "mu", NULL, 2 },
  134. { "pp", NULL, 3 },
  135. { "ptp", NULL, 4 },
  136. { "pex0", NULL, 5 },
  137. { "pex1", NULL, 6 },
  138. { "audio", NULL, 8 },
  139. { "nd_clk", "nand", 11 },
  140. { "sata0_link", "sata0_core", 14 },
  141. { "sata0_core", NULL, 15 },
  142. { "usb3", NULL, 16 },
  143. { "sdio", NULL, 17 },
  144. { "usb", NULL, 18 },
  145. { "gop", NULL, 19 },
  146. { "sata1_link", "sata1_core", 20 },
  147. { "sata1_core", NULL, 21 },
  148. { "xor0", NULL, 22 },
  149. { "xor1", NULL, 23 },
  150. { "copro", NULL, 24 },
  151. { "tdm", NULL, 25 },
  152. { "crypto0_enc", NULL, 28 },
  153. { "crypto0_core", NULL, 29 },
  154. { "crypto1_enc", NULL, 30 },
  155. { "crypto1_core", NULL, 31 },
  156. { }
  157. };
  158. static void __init armada_375_clk_gating_init(struct device_node *np)
  159. {
  160. mvebu_clk_gating_setup(np, armada_375_gating_desc);
  161. }
  162. CLK_OF_DECLARE(armada_375_clk_gating, "marvell,armada-375-gating-clock",
  163. armada_375_clk_gating_init);