dove.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Marvell Dove 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. #include "dove-divider.h"
  20. /*
  21. * Core Clocks
  22. *
  23. * Dove PLL sample-at-reset configuration
  24. *
  25. * SAR0[8:5] : CPU frequency
  26. * 5 = 1000 MHz
  27. * 6 = 933 MHz
  28. * 7 = 933 MHz
  29. * 8 = 800 MHz
  30. * 9 = 800 MHz
  31. * 10 = 800 MHz
  32. * 11 = 1067 MHz
  33. * 12 = 667 MHz
  34. * 13 = 533 MHz
  35. * 14 = 400 MHz
  36. * 15 = 333 MHz
  37. * others reserved.
  38. *
  39. * SAR0[11:9] : CPU to L2 Clock divider ratio
  40. * 0 = (1/1) * CPU
  41. * 2 = (1/2) * CPU
  42. * 4 = (1/3) * CPU
  43. * 6 = (1/4) * CPU
  44. * others reserved.
  45. *
  46. * SAR0[15:12] : CPU to DDR DRAM Clock divider ratio
  47. * 0 = (1/1) * CPU
  48. * 2 = (1/2) * CPU
  49. * 3 = (2/5) * CPU
  50. * 4 = (1/3) * CPU
  51. * 6 = (1/4) * CPU
  52. * 8 = (1/5) * CPU
  53. * 10 = (1/6) * CPU
  54. * 12 = (1/7) * CPU
  55. * 14 = (1/8) * CPU
  56. * 15 = (1/10) * CPU
  57. * others reserved.
  58. *
  59. * SAR0[24:23] : TCLK frequency
  60. * 0 = 166 MHz
  61. * 1 = 125 MHz
  62. * others reserved.
  63. */
  64. #define SAR_DOVE_CPU_FREQ 5
  65. #define SAR_DOVE_CPU_FREQ_MASK 0xf
  66. #define SAR_DOVE_L2_RATIO 9
  67. #define SAR_DOVE_L2_RATIO_MASK 0x7
  68. #define SAR_DOVE_DDR_RATIO 12
  69. #define SAR_DOVE_DDR_RATIO_MASK 0xf
  70. #define SAR_DOVE_TCLK_FREQ 23
  71. #define SAR_DOVE_TCLK_FREQ_MASK 0x3
  72. enum { DOVE_CPU_TO_L2, DOVE_CPU_TO_DDR };
  73. static const struct coreclk_ratio dove_coreclk_ratios[] __initconst = {
  74. { .id = DOVE_CPU_TO_L2, .name = "l2clk", },
  75. { .id = DOVE_CPU_TO_DDR, .name = "ddrclk", }
  76. };
  77. static const u32 dove_tclk_freqs[] __initconst = {
  78. 166666667,
  79. 125000000,
  80. 0, 0
  81. };
  82. static u32 __init dove_get_tclk_freq(void __iomem *sar)
  83. {
  84. u32 opt = (readl(sar) >> SAR_DOVE_TCLK_FREQ) &
  85. SAR_DOVE_TCLK_FREQ_MASK;
  86. return dove_tclk_freqs[opt];
  87. }
  88. static const u32 dove_cpu_freqs[] __initconst = {
  89. 0, 0, 0, 0, 0,
  90. 1000000000,
  91. 933333333, 933333333,
  92. 800000000, 800000000, 800000000,
  93. 1066666667,
  94. 666666667,
  95. 533333333,
  96. 400000000,
  97. 333333333
  98. };
  99. static u32 __init dove_get_cpu_freq(void __iomem *sar)
  100. {
  101. u32 opt = (readl(sar) >> SAR_DOVE_CPU_FREQ) &
  102. SAR_DOVE_CPU_FREQ_MASK;
  103. return dove_cpu_freqs[opt];
  104. }
  105. static const int dove_cpu_l2_ratios[8][2] __initconst = {
  106. { 1, 1 }, { 0, 1 }, { 1, 2 }, { 0, 1 },
  107. { 1, 3 }, { 0, 1 }, { 1, 4 }, { 0, 1 }
  108. };
  109. static const int dove_cpu_ddr_ratios[16][2] __initconst = {
  110. { 1, 1 }, { 0, 1 }, { 1, 2 }, { 2, 5 },
  111. { 1, 3 }, { 0, 1 }, { 1, 4 }, { 0, 1 },
  112. { 1, 5 }, { 0, 1 }, { 1, 6 }, { 0, 1 },
  113. { 1, 7 }, { 0, 1 }, { 1, 8 }, { 1, 10 }
  114. };
  115. static void __init dove_get_clk_ratio(
  116. void __iomem *sar, int id, int *mult, int *div)
  117. {
  118. switch (id) {
  119. case DOVE_CPU_TO_L2:
  120. {
  121. u32 opt = (readl(sar) >> SAR_DOVE_L2_RATIO) &
  122. SAR_DOVE_L2_RATIO_MASK;
  123. *mult = dove_cpu_l2_ratios[opt][0];
  124. *div = dove_cpu_l2_ratios[opt][1];
  125. break;
  126. }
  127. case DOVE_CPU_TO_DDR:
  128. {
  129. u32 opt = (readl(sar) >> SAR_DOVE_DDR_RATIO) &
  130. SAR_DOVE_DDR_RATIO_MASK;
  131. *mult = dove_cpu_ddr_ratios[opt][0];
  132. *div = dove_cpu_ddr_ratios[opt][1];
  133. break;
  134. }
  135. }
  136. }
  137. static const struct coreclk_soc_desc dove_coreclks = {
  138. .get_tclk_freq = dove_get_tclk_freq,
  139. .get_cpu_freq = dove_get_cpu_freq,
  140. .get_clk_ratio = dove_get_clk_ratio,
  141. .ratios = dove_coreclk_ratios,
  142. .num_ratios = ARRAY_SIZE(dove_coreclk_ratios),
  143. };
  144. /*
  145. * Clock Gating Control
  146. */
  147. static const struct clk_gating_soc_desc dove_gating_desc[] __initconst = {
  148. { "usb0", NULL, 0, 0 },
  149. { "usb1", NULL, 1, 0 },
  150. { "ge", "gephy", 2, 0 },
  151. { "sata", NULL, 3, 0 },
  152. { "pex0", NULL, 4, 0 },
  153. { "pex1", NULL, 5, 0 },
  154. { "sdio0", NULL, 8, 0 },
  155. { "sdio1", NULL, 9, 0 },
  156. { "nand", NULL, 10, 0 },
  157. { "camera", NULL, 11, 0 },
  158. { "i2s0", NULL, 12, 0 },
  159. { "i2s1", NULL, 13, 0 },
  160. { "crypto", NULL, 15, 0 },
  161. { "ac97", NULL, 21, 0 },
  162. { "pdma", NULL, 22, 0 },
  163. { "xor0", NULL, 23, 0 },
  164. { "xor1", NULL, 24, 0 },
  165. { "gephy", NULL, 30, 0 },
  166. { }
  167. };
  168. static void __init dove_clk_init(struct device_node *np)
  169. {
  170. struct device_node *cgnp =
  171. of_find_compatible_node(NULL, NULL, "marvell,dove-gating-clock");
  172. struct device_node *ddnp =
  173. of_find_compatible_node(NULL, NULL, "marvell,dove-divider-clock");
  174. mvebu_coreclk_setup(np, &dove_coreclks);
  175. if (ddnp)
  176. dove_divider_clk_init(ddnp);
  177. if (cgnp)
  178. mvebu_clk_gating_setup(cgnp, dove_gating_desc);
  179. }
  180. CLK_OF_DECLARE(dove_clk, "marvell,dove-core-clock", dove_clk_init);