armada-370.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Marvell Armada 370 SoC clocks
  3. *
  4. * Copyright (C) 2012 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. #define SARL 0 /* Low part [0:31] */
  23. #define SARL_A370_PCLK_FREQ_OPT 11
  24. #define SARL_A370_PCLK_FREQ_OPT_MASK 0xF
  25. #define SARL_A370_FAB_FREQ_OPT 15
  26. #define SARL_A370_FAB_FREQ_OPT_MASK 0x1F
  27. #define SARL_A370_TCLK_FREQ_OPT 20
  28. #define SARL_A370_TCLK_FREQ_OPT_MASK 0x1
  29. enum { A370_CPU_TO_NBCLK, A370_CPU_TO_HCLK, A370_CPU_TO_DRAMCLK };
  30. static const struct coreclk_ratio a370_coreclk_ratios[] __initconst = {
  31. { .id = A370_CPU_TO_NBCLK, .name = "nbclk" },
  32. { .id = A370_CPU_TO_HCLK, .name = "hclk" },
  33. { .id = A370_CPU_TO_DRAMCLK, .name = "dramclk" },
  34. };
  35. static const u32 a370_tclk_freqs[] __initconst = {
  36. 16600000,
  37. 20000000,
  38. };
  39. static u32 __init a370_get_tclk_freq(void __iomem *sar)
  40. {
  41. u8 tclk_freq_select = 0;
  42. tclk_freq_select = ((readl(sar) >> SARL_A370_TCLK_FREQ_OPT) &
  43. SARL_A370_TCLK_FREQ_OPT_MASK);
  44. return a370_tclk_freqs[tclk_freq_select];
  45. }
  46. static const u32 a370_cpu_freqs[] __initconst = {
  47. 400000000,
  48. 533000000,
  49. 667000000,
  50. 800000000,
  51. 1000000000,
  52. 1067000000,
  53. 1200000000,
  54. };
  55. static u32 __init a370_get_cpu_freq(void __iomem *sar)
  56. {
  57. u32 cpu_freq;
  58. u8 cpu_freq_select = 0;
  59. cpu_freq_select = ((readl(sar) >> SARL_A370_PCLK_FREQ_OPT) &
  60. SARL_A370_PCLK_FREQ_OPT_MASK);
  61. if (cpu_freq_select >= ARRAY_SIZE(a370_cpu_freqs)) {
  62. pr_err("CPU freq select unsupported %d\n", cpu_freq_select);
  63. cpu_freq = 0;
  64. } else
  65. cpu_freq = a370_cpu_freqs[cpu_freq_select];
  66. return cpu_freq;
  67. }
  68. static const int a370_nbclk_ratios[32][2] __initconst = {
  69. {0, 1}, {1, 2}, {2, 2}, {2, 2},
  70. {1, 2}, {1, 2}, {1, 1}, {2, 3},
  71. {0, 1}, {1, 2}, {2, 4}, {0, 1},
  72. {1, 2}, {0, 1}, {0, 1}, {2, 2},
  73. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  74. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  75. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  76. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  77. };
  78. static const int a370_hclk_ratios[32][2] __initconst = {
  79. {0, 1}, {1, 2}, {2, 6}, {2, 3},
  80. {1, 3}, {1, 4}, {1, 2}, {2, 6},
  81. {0, 1}, {1, 6}, {2, 10}, {0, 1},
  82. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  83. {0, 1}, {0, 1}, {0, 1}, {1, 2},
  84. {2, 6}, {0, 1}, {0, 1}, {0, 1},
  85. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  86. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  87. };
  88. static const int a370_dramclk_ratios[32][2] __initconst = {
  89. {0, 1}, {1, 2}, {2, 3}, {2, 3},
  90. {1, 3}, {1, 2}, {1, 2}, {2, 6},
  91. {0, 1}, {1, 3}, {2, 5}, {0, 1},
  92. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  93. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  94. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  95. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  96. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  97. };
  98. static void __init a370_get_clk_ratio(
  99. void __iomem *sar, int id, int *mult, int *div)
  100. {
  101. u32 opt = ((readl(sar) >> SARL_A370_FAB_FREQ_OPT) &
  102. SARL_A370_FAB_FREQ_OPT_MASK);
  103. switch (id) {
  104. case A370_CPU_TO_NBCLK:
  105. *mult = a370_nbclk_ratios[opt][0];
  106. *div = a370_nbclk_ratios[opt][1];
  107. break;
  108. case A370_CPU_TO_HCLK:
  109. *mult = a370_hclk_ratios[opt][0];
  110. *div = a370_hclk_ratios[opt][1];
  111. break;
  112. case A370_CPU_TO_DRAMCLK:
  113. *mult = a370_dramclk_ratios[opt][0];
  114. *div = a370_dramclk_ratios[opt][1];
  115. break;
  116. }
  117. }
  118. static const struct coreclk_soc_desc a370_coreclks = {
  119. .get_tclk_freq = a370_get_tclk_freq,
  120. .get_cpu_freq = a370_get_cpu_freq,
  121. .get_clk_ratio = a370_get_clk_ratio,
  122. .ratios = a370_coreclk_ratios,
  123. .num_ratios = ARRAY_SIZE(a370_coreclk_ratios),
  124. };
  125. static void __init a370_coreclk_init(struct device_node *np)
  126. {
  127. mvebu_coreclk_setup(np, &a370_coreclks);
  128. }
  129. CLK_OF_DECLARE(a370_core_clk, "marvell,armada-370-core-clock",
  130. a370_coreclk_init);
  131. /*
  132. * Clock Gating Control
  133. */
  134. static const struct clk_gating_soc_desc a370_gating_desc[] __initconst = {
  135. { "audio", NULL, 0, 0 },
  136. { "pex0_en", NULL, 1, 0 },
  137. { "pex1_en", NULL, 2, 0 },
  138. { "ge1", NULL, 3, 0 },
  139. { "ge0", NULL, 4, 0 },
  140. { "pex0", "pex0_en", 5, 0 },
  141. { "pex1", "pex1_en", 9, 0 },
  142. { "sata0", NULL, 15, 0 },
  143. { "sdio", NULL, 17, 0 },
  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_gating_init(struct device_node *np)
  150. {
  151. mvebu_clk_gating_setup(np, a370_gating_desc);
  152. }
  153. CLK_OF_DECLARE(a370_clk_gating, "marvell,armada-370-gating-clock",
  154. a370_clk_gating_init);