armada-xp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. static const u32 axp_cpu_freqs[] __initconst = {
  49. 1000000000,
  50. 1066000000,
  51. 1200000000,
  52. 1333000000,
  53. 1500000000,
  54. 1666000000,
  55. 1800000000,
  56. 2000000000,
  57. 667000000,
  58. 0,
  59. 800000000,
  60. 1600000000,
  61. };
  62. static u32 __init axp_get_cpu_freq(void __iomem *sar)
  63. {
  64. u32 cpu_freq;
  65. u8 cpu_freq_select = 0;
  66. cpu_freq_select = ((readl(sar + SARL) >> SARL_AXP_PCLK_FREQ_OPT) &
  67. SARL_AXP_PCLK_FREQ_OPT_MASK);
  68. /*
  69. * The upper bit is not contiguous to the other ones and
  70. * located in the high part of the SAR registers
  71. */
  72. cpu_freq_select |= (((readl(sar + SARH) >> SARH_AXP_PCLK_FREQ_OPT) &
  73. SARH_AXP_PCLK_FREQ_OPT_MASK) << SARH_AXP_PCLK_FREQ_OPT_SHIFT);
  74. if (cpu_freq_select >= ARRAY_SIZE(axp_cpu_freqs)) {
  75. pr_err("CPU freq select unsupported: %d\n", cpu_freq_select);
  76. cpu_freq = 0;
  77. } else
  78. cpu_freq = axp_cpu_freqs[cpu_freq_select];
  79. return cpu_freq;
  80. }
  81. static const int axp_nbclk_ratios[32][2] __initconst = {
  82. {0, 1}, {1, 2}, {2, 2}, {2, 2},
  83. {1, 2}, {1, 2}, {1, 1}, {2, 3},
  84. {0, 1}, {1, 2}, {2, 4}, {0, 1},
  85. {1, 2}, {0, 1}, {0, 1}, {2, 2},
  86. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  87. {2, 3}, {0, 1}, {0, 1}, {0, 1},
  88. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  89. {0, 1}, {0, 1}, {0, 1}, {0, 1},
  90. };
  91. static const int axp_hclk_ratios[32][2] __initconst = {
  92. {0, 1}, {1, 2}, {2, 6}, {2, 3},
  93. {1, 3}, {1, 4}, {1, 2}, {2, 6},
  94. {0, 1}, {1, 6}, {2, 10}, {0, 1},
  95. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  96. {0, 1}, {0, 1}, {0, 1}, {1, 2},
  97. {2, 6}, {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_dramclk_ratios[32][2] __initconst = {
  102. {0, 1}, {1, 2}, {2, 3}, {2, 3},
  103. {1, 3}, {1, 2}, {1, 2}, {2, 6},
  104. {0, 1}, {1, 3}, {2, 5}, {0, 1},
  105. {1, 4}, {0, 1}, {0, 1}, {2, 5},
  106. {0, 1}, {0, 1}, {0, 1}, {1, 1},
  107. {2, 3}, {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 void __init axp_get_clk_ratio(
  112. void __iomem *sar, int id, int *mult, int *div)
  113. {
  114. u32 opt = ((readl(sar + SARL) >> SARL_AXP_FAB_FREQ_OPT) &
  115. SARL_AXP_FAB_FREQ_OPT_MASK);
  116. /*
  117. * The upper bit is not contiguous to the other ones and
  118. * located in the high part of the SAR registers
  119. */
  120. opt |= (((readl(sar + SARH) >> SARH_AXP_FAB_FREQ_OPT) &
  121. SARH_AXP_FAB_FREQ_OPT_MASK) << SARH_AXP_FAB_FREQ_OPT_SHIFT);
  122. switch (id) {
  123. case AXP_CPU_TO_NBCLK:
  124. *mult = axp_nbclk_ratios[opt][0];
  125. *div = axp_nbclk_ratios[opt][1];
  126. break;
  127. case AXP_CPU_TO_HCLK:
  128. *mult = axp_hclk_ratios[opt][0];
  129. *div = axp_hclk_ratios[opt][1];
  130. break;
  131. case AXP_CPU_TO_DRAMCLK:
  132. *mult = axp_dramclk_ratios[opt][0];
  133. *div = axp_dramclk_ratios[opt][1];
  134. break;
  135. }
  136. }
  137. static const struct coreclk_soc_desc axp_coreclks = {
  138. .get_tclk_freq = axp_get_tclk_freq,
  139. .get_cpu_freq = axp_get_cpu_freq,
  140. .get_clk_ratio = axp_get_clk_ratio,
  141. .ratios = axp_coreclk_ratios,
  142. .num_ratios = ARRAY_SIZE(axp_coreclk_ratios),
  143. };
  144. /*
  145. * Clock Gating Control
  146. */
  147. static const struct clk_gating_soc_desc axp_gating_desc[] __initconst = {
  148. { "audio", NULL, 0, 0 },
  149. { "ge3", NULL, 1, 0 },
  150. { "ge2", NULL, 2, 0 },
  151. { "ge1", NULL, 3, 0 },
  152. { "ge0", NULL, 4, 0 },
  153. { "pex00", NULL, 5, 0 },
  154. { "pex01", NULL, 6, 0 },
  155. { "pex02", NULL, 7, 0 },
  156. { "pex03", NULL, 8, 0 },
  157. { "pex10", NULL, 9, 0 },
  158. { "pex11", NULL, 10, 0 },
  159. { "pex12", NULL, 11, 0 },
  160. { "pex13", NULL, 12, 0 },
  161. { "bp", NULL, 13, 0 },
  162. { "sata0lnk", NULL, 14, 0 },
  163. { "sata0", "sata0lnk", 15, 0 },
  164. { "lcd", NULL, 16, 0 },
  165. { "sdio", NULL, 17, 0 },
  166. { "usb0", NULL, 18, 0 },
  167. { "usb1", NULL, 19, 0 },
  168. { "usb2", NULL, 20, 0 },
  169. { "xor0", NULL, 22, 0 },
  170. { "crypto", NULL, 23, 0 },
  171. { "tdm", NULL, 25, 0 },
  172. { "pex20", NULL, 26, 0 },
  173. { "pex30", NULL, 27, 0 },
  174. { "xor1", NULL, 28, 0 },
  175. { "sata1lnk", NULL, 29, 0 },
  176. { "sata1", "sata1lnk", 30, 0 },
  177. { }
  178. };
  179. static void __init axp_clk_init(struct device_node *np)
  180. {
  181. struct device_node *cgnp =
  182. of_find_compatible_node(NULL, NULL, "marvell,armada-xp-gating-clock");
  183. mvebu_coreclk_setup(np, &axp_coreclks);
  184. if (cgnp)
  185. mvebu_clk_gating_setup(cgnp, axp_gating_desc);
  186. }
  187. CLK_OF_DECLARE(axp_clk, "marvell,armada-xp-core-clock", axp_clk_init);