dove.c 4.4 KB

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