armada-370.c 4.7 KB

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