armada-39x.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Marvell Armada 39x SoC clocks
  3. *
  4. * Copyright (C) 2015 Marvell
  5. *
  6. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  7. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  8. * Andrew Lunn <andrew@lunn.ch>
  9. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/clk-provider.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include "common.h"
  20. /*
  21. * SARL[14:10] : Ratios between CPU, NBCLK, HCLK and DCLK.
  22. *
  23. * SARL[15] : TCLK frequency
  24. * 0 = 250 MHz
  25. * 1 = 200 MHz
  26. *
  27. * SARH[0] : Reference clock frequency
  28. * 0 = 25 Mhz
  29. * 1 = 40 Mhz
  30. */
  31. #define SARL 0
  32. #define SARL_A390_TCLK_FREQ_OPT 15
  33. #define SARL_A390_TCLK_FREQ_OPT_MASK 0x1
  34. #define SARL_A390_CPU_DDR_L2_FREQ_OPT 10
  35. #define SARL_A390_CPU_DDR_L2_FREQ_OPT_MASK 0x1F
  36. #define SARH 4
  37. #define SARH_A390_REFCLK_FREQ BIT(0)
  38. static const u32 armada_39x_tclk_frequencies[] __initconst = {
  39. 250000000,
  40. 200000000,
  41. };
  42. static u32 __init armada_39x_get_tclk_freq(void __iomem *sar)
  43. {
  44. u8 tclk_freq_select;
  45. tclk_freq_select = ((readl(sar + SARL) >> SARL_A390_TCLK_FREQ_OPT) &
  46. SARL_A390_TCLK_FREQ_OPT_MASK);
  47. return armada_39x_tclk_frequencies[tclk_freq_select];
  48. }
  49. static const u32 armada_39x_cpu_frequencies[] __initconst = {
  50. [0x0] = 666 * 1000 * 1000,
  51. [0x2] = 800 * 1000 * 1000,
  52. [0x3] = 800 * 1000 * 1000,
  53. [0x4] = 1066 * 1000 * 1000,
  54. [0x5] = 1066 * 1000 * 1000,
  55. [0x6] = 1200 * 1000 * 1000,
  56. [0x8] = 1332 * 1000 * 1000,
  57. [0xB] = 1600 * 1000 * 1000,
  58. [0xC] = 1600 * 1000 * 1000,
  59. [0x12] = 1800 * 1000 * 1000,
  60. [0x1E] = 1800 * 1000 * 1000,
  61. };
  62. static u32 __init armada_39x_get_cpu_freq(void __iomem *sar)
  63. {
  64. u8 cpu_freq_select;
  65. cpu_freq_select = ((readl(sar + SARL) >> SARL_A390_CPU_DDR_L2_FREQ_OPT) &
  66. SARL_A390_CPU_DDR_L2_FREQ_OPT_MASK);
  67. if (cpu_freq_select >= ARRAY_SIZE(armada_39x_cpu_frequencies)) {
  68. pr_err("Selected CPU frequency (%d) unsupported\n",
  69. cpu_freq_select);
  70. return 0;
  71. }
  72. return armada_39x_cpu_frequencies[cpu_freq_select];
  73. }
  74. enum { A390_CPU_TO_NBCLK, A390_CPU_TO_HCLK, A390_CPU_TO_DCLK };
  75. static const struct coreclk_ratio armada_39x_coreclk_ratios[] __initconst = {
  76. { .id = A390_CPU_TO_NBCLK, .name = "nbclk" },
  77. { .id = A390_CPU_TO_HCLK, .name = "hclk" },
  78. { .id = A390_CPU_TO_DCLK, .name = "dclk" },
  79. };
  80. static void __init armada_39x_get_clk_ratio(
  81. void __iomem *sar, int id, int *mult, int *div)
  82. {
  83. switch (id) {
  84. case A390_CPU_TO_NBCLK:
  85. *mult = 1;
  86. *div = 2;
  87. break;
  88. case A390_CPU_TO_HCLK:
  89. *mult = 1;
  90. *div = 4;
  91. break;
  92. case A390_CPU_TO_DCLK:
  93. *mult = 1;
  94. *div = 2;
  95. break;
  96. }
  97. }
  98. static u32 __init armada_39x_refclk_ratio(void __iomem *sar)
  99. {
  100. if (readl(sar + SARH) & SARH_A390_REFCLK_FREQ)
  101. return 40 * 1000 * 1000;
  102. else
  103. return 25 * 1000 * 1000;
  104. }
  105. static const struct coreclk_soc_desc armada_39x_coreclks = {
  106. .get_tclk_freq = armada_39x_get_tclk_freq,
  107. .get_cpu_freq = armada_39x_get_cpu_freq,
  108. .get_clk_ratio = armada_39x_get_clk_ratio,
  109. .get_refclk_freq = armada_39x_refclk_ratio,
  110. .ratios = armada_39x_coreclk_ratios,
  111. .num_ratios = ARRAY_SIZE(armada_39x_coreclk_ratios),
  112. };
  113. static void __init armada_39x_coreclk_init(struct device_node *np)
  114. {
  115. mvebu_coreclk_setup(np, &armada_39x_coreclks);
  116. }
  117. CLK_OF_DECLARE(armada_39x_core_clk, "marvell,armada-390-core-clock",
  118. armada_39x_coreclk_init);
  119. /*
  120. * Clock Gating Control
  121. */
  122. static const struct clk_gating_soc_desc armada_39x_gating_desc[] __initconst = {
  123. { "pex1", NULL, 5 },
  124. { "pex2", NULL, 6 },
  125. { "pex3", NULL, 7 },
  126. { "pex0", NULL, 8 },
  127. { "usb3h0", NULL, 9 },
  128. { "sdio", NULL, 17 },
  129. { "xor0", NULL, 22 },
  130. { "xor1", NULL, 28 },
  131. { }
  132. };
  133. static void __init armada_39x_clk_gating_init(struct device_node *np)
  134. {
  135. mvebu_clk_gating_setup(np, armada_39x_gating_desc);
  136. }
  137. CLK_OF_DECLARE(armada_39x_clk_gating, "marvell,armada-390-gating-clock",
  138. armada_39x_clk_gating_init);