armada-xp.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Marvell Armada XP 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. * Armada XP Sample At Reset is a 64 bit bitfiled split in two
  23. * register of 32 bits
  24. */
  25. #define SARL 0 /* Low part [0:31] */
  26. #define SARL_AXP_PCLK_FREQ_OPT 21
  27. #define SARL_AXP_PCLK_FREQ_OPT_MASK 0x7
  28. #define SARL_AXP_FAB_FREQ_OPT 24
  29. #define SARL_AXP_FAB_FREQ_OPT_MASK 0xF
  30. #define SARH 4 /* High part [32:63] */
  31. #define SARH_AXP_PCLK_FREQ_OPT (52-32)
  32. #define SARH_AXP_PCLK_FREQ_OPT_MASK 0x1
  33. #define SARH_AXP_PCLK_FREQ_OPT_SHIFT 3
  34. #define SARH_AXP_FAB_FREQ_OPT (51-32)
  35. #define SARH_AXP_FAB_FREQ_OPT_MASK 0x1
  36. #define SARH_AXP_FAB_FREQ_OPT_SHIFT 4
  37. enum { AXP_CPU_TO_NBCLK, AXP_CPU_TO_HCLK, AXP_CPU_TO_DRAMCLK };
  38. static const struct coreclk_ratio axp_coreclk_ratios[] __initconst = {
  39. { .id = AXP_CPU_TO_NBCLK, .name = "nbclk" },
  40. { .id = AXP_CPU_TO_HCLK, .name = "hclk" },
  41. { .id = AXP_CPU_TO_DRAMCLK, .name = "dramclk" },
  42. };
  43. /* Armada XP TCLK frequency is fixed to 250MHz */
  44. static u32 __init axp_get_tclk_freq(void __iomem *sar)
  45. {
  46. return 250000000;
  47. }
  48. /* MV98DX3236 TCLK frequency is fixed to 200MHz */
  49. static u32 __init mv98dx3236_get_tclk_freq(void __iomem *sar)
  50. {
  51. return 200000000;
  52. }
  53. static const u32 axp_cpu_freqs[] __initconst = {
  54. 1000000000,
  55. 1066000000,
  56. 1200000000,
  57. 1333000000,
  58. 1500000000,
  59. 1666000000,
  60. 1800000000,
  61. 2000000000,
  62. 667000000,
  63. 0,
  64. 800000000,
  65. 1600000000,
  66. };
  67. static u32 __init axp_get_cpu_freq(void __iomem *sar)
  68. {
  69. u32 cpu_freq;
  70. u8 cpu_freq_select = 0;
  71. cpu_freq_select = ((readl(sar + SARL) >> SARL_AXP_PCLK_FREQ_OPT) &
  72. SARL_AXP_PCLK_FREQ_OPT_MASK);
  73. /*
  74. * The upper bit is not contiguous to the other ones and
  75. * located in the high part of the SAR registers
  76. */
  77. cpu_freq_select |= (((readl(sar + SARH) >> SARH_AXP_PCLK_FREQ_OPT) &
  78. SARH_AXP_PCLK_FREQ_OPT_MASK) << SARH_AXP_PCLK_FREQ_OPT_SHIFT);
  79. if (cpu_freq_select >= ARRAY_SIZE(axp_cpu_freqs)) {
  80. pr_err("CPU freq select unsupported: %d\n", cpu_freq_select);
  81. cpu_freq = 0;
  82. } else
  83. cpu_freq = axp_cpu_freqs[cpu_freq_select];
  84. return cpu_freq;
  85. }
  86. /* MV98DX3236 CLK frequency is fixed to 800MHz */
  87. static u32 __init mv98dx3236_get_cpu_freq(void __iomem *sar)
  88. {
  89. return 800000000;
  90. }
  91. static const int axp_nbclk_ratios[32][2] __initconst = {
  92. {0, 1}, {1, 2}, {2, 2}, {2, 2},
  93. {1, 2}, {1, 2}, {1, 1}, {2, 3},
  94. {0, 1}, {1, 2}, {2, 4}, {0, 1},
  95. {1, 2}, {0, 1}, {0, 1}, {2, 2},
  96. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  97. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  98. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  99. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  100. };
  101. static const int axp_hclk_ratios[32][2] __initconst = {
  102. {0, 1}, {1, 2}, {2, 6}, {2, 3},
  103. {1, 3}, {1, 4}, {1, 2}, {2, 6},
  104. {0, 1}, {1, 6}, {2, 10}, {0, 1},
  105. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  106. {0, 1}, {0, 1}, {0, 1}, {1, 2},
  107. {2, 6}, {0, 1}, {0, 1}, {0, 1},
  108. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  109. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  110. };
  111. static const int axp_dramclk_ratios[32][2] __initconst = {
  112. {0, 1}, {1, 2}, {2, 3}, {2, 3},
  113. {1, 3}, {1, 2}, {1, 2}, {2, 6},
  114. {0, 1}, {1, 3}, {2, 5}, {0, 1},
  115. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  116. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  117. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  118. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  119. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  120. };
  121. static void __init axp_get_clk_ratio(
  122. void __iomem *sar, int id, int *mult, int *div)
  123. {
  124. u32 opt = ((readl(sar + SARL) >> SARL_AXP_FAB_FREQ_OPT) &
  125. SARL_AXP_FAB_FREQ_OPT_MASK);
  126. /*
  127. * The upper bit is not contiguous to the other ones and
  128. * located in the high part of the SAR registers
  129. */
  130. opt |= (((readl(sar + SARH) >> SARH_AXP_FAB_FREQ_OPT) &
  131. SARH_AXP_FAB_FREQ_OPT_MASK) << SARH_AXP_FAB_FREQ_OPT_SHIFT);
  132. switch (id) {
  133. case AXP_CPU_TO_NBCLK:
  134. *mult = axp_nbclk_ratios[opt][0];
  135. *div = axp_nbclk_ratios[opt][1];
  136. break;
  137. case AXP_CPU_TO_HCLK:
  138. *mult = axp_hclk_ratios[opt][0];
  139. *div = axp_hclk_ratios[opt][1];
  140. break;
  141. case AXP_CPU_TO_DRAMCLK:
  142. *mult = axp_dramclk_ratios[opt][0];
  143. *div = axp_dramclk_ratios[opt][1];
  144. break;
  145. }
  146. }
  147. static const struct coreclk_soc_desc axp_coreclks = {
  148. .get_tclk_freq = axp_get_tclk_freq,
  149. .get_cpu_freq = axp_get_cpu_freq,
  150. .get_clk_ratio = axp_get_clk_ratio,
  151. .ratios = axp_coreclk_ratios,
  152. .num_ratios = ARRAY_SIZE(axp_coreclk_ratios),
  153. };
  154. static const struct coreclk_soc_desc mv98dx3236_coreclks = {
  155. .get_tclk_freq = mv98dx3236_get_tclk_freq,
  156. .get_cpu_freq = mv98dx3236_get_cpu_freq,
  157. };
  158. /*
  159. * Clock Gating Control
  160. */
  161. static const struct clk_gating_soc_desc axp_gating_desc[] __initconst = {
  162. { "audio", NULL, 0, 0 },
  163. { "ge3", NULL, 1, 0 },
  164. { "ge2", NULL, 2, 0 },
  165. { "ge1", NULL, 3, 0 },
  166. { "ge0", NULL, 4, 0 },
  167. { "pex00", NULL, 5, 0 },
  168. { "pex01", NULL, 6, 0 },
  169. { "pex02", NULL, 7, 0 },
  170. { "pex03", NULL, 8, 0 },
  171. { "pex10", NULL, 9, 0 },
  172. { "pex11", NULL, 10, 0 },
  173. { "pex12", NULL, 11, 0 },
  174. { "pex13", NULL, 12, 0 },
  175. { "bp", NULL, 13, 0 },
  176. { "sata0lnk", NULL, 14, 0 },
  177. { "sata0", "sata0lnk", 15, 0 },
  178. { "lcd", NULL, 16, 0 },
  179. { "sdio", NULL, 17, 0 },
  180. { "usb0", NULL, 18, 0 },
  181. { "usb1", NULL, 19, 0 },
  182. { "usb2", NULL, 20, 0 },
  183. { "xor0", NULL, 22, 0 },
  184. { "crypto", NULL, 23, 0 },
  185. { "tdm", NULL, 25, 0 },
  186. { "pex20", NULL, 26, 0 },
  187. { "pex30", NULL, 27, 0 },
  188. { "xor1", NULL, 28, 0 },
  189. { "sata1lnk", NULL, 29, 0 },
  190. { "sata1", "sata1lnk", 30, 0 },
  191. { }
  192. };
  193. static const struct clk_gating_soc_desc mv98dx3236_gating_desc[] __initconst = {
  194. { "ge1", NULL, 3, 0 },
  195. { "ge0", NULL, 4, 0 },
  196. { "pex00", NULL, 5, 0 },
  197. { "sdio", NULL, 17, 0 },
  198. { "xor0", NULL, 22, 0 },
  199. { }
  200. };
  201. static void __init axp_clk_init(struct device_node *np)
  202. {
  203. struct device_node *cgnp =
  204. of_find_compatible_node(NULL, NULL, "marvell,armada-xp-gating-clock");
  205. mvebu_coreclk_setup(np, &axp_coreclks);
  206. if (cgnp)
  207. mvebu_clk_gating_setup(cgnp, axp_gating_desc);
  208. }
  209. CLK_OF_DECLARE(axp_clk, "marvell,armada-xp-core-clock", axp_clk_init);