clock.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Keystone2: pll initialization
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/clock_defs.h>
  12. #define MAX_SPEEDS 13
  13. static void wait_for_completion(const struct pll_init_data *data)
  14. {
  15. int i;
  16. for (i = 0; i < 100; i++) {
  17. sdelay(450);
  18. if ((pllctl_reg_read(data->pll, stat) & PLLSTAT_GO) == 0)
  19. break;
  20. }
  21. }
  22. void init_pll(const struct pll_init_data *data)
  23. {
  24. u32 tmp, tmp_ctl, pllm, plld, pllod, bwadj;
  25. pllm = data->pll_m - 1;
  26. plld = (data->pll_d - 1) & PLL_DIV_MASK;
  27. pllod = (data->pll_od - 1) & PLL_CLKOD_MASK;
  28. if (data->pll == MAIN_PLL) {
  29. /* The requered delay before main PLL configuration */
  30. sdelay(210000);
  31. tmp = pllctl_reg_read(data->pll, secctl);
  32. if (tmp & (PLLCTL_BYPASS)) {
  33. setbits_le32(keystone_pll_regs[data->pll].reg1,
  34. BIT(MAIN_ENSAT_OFFSET));
  35. pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLEN |
  36. PLLCTL_PLLENSRC);
  37. sdelay(340);
  38. pllctl_reg_setbits(data->pll, secctl, PLLCTL_BYPASS);
  39. pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLPWRDN);
  40. sdelay(21000);
  41. pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLPWRDN);
  42. } else {
  43. pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLEN |
  44. PLLCTL_PLLENSRC);
  45. sdelay(340);
  46. }
  47. pllctl_reg_write(data->pll, mult, pllm & PLLM_MULT_LO_MASK);
  48. clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
  49. PLLM_MULT_HI_SMASK, (pllm << 6));
  50. /* Set the BWADJ (12 bit field) */
  51. tmp_ctl = pllm >> 1; /* Divide the pllm by 2 */
  52. clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
  53. PLL_BWADJ_LO_SMASK,
  54. (tmp_ctl << PLL_BWADJ_LO_SHIFT));
  55. clrsetbits_le32(keystone_pll_regs[data->pll].reg1,
  56. PLL_BWADJ_HI_MASK,
  57. (tmp_ctl >> 8));
  58. /*
  59. * Set the pll divider (6 bit field) *
  60. * PLLD[5:0] is located in MAINPLLCTL0
  61. */
  62. clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
  63. PLL_DIV_MASK, plld);
  64. /* Set the OUTPUT DIVIDE (4 bit field) in SECCTL */
  65. pllctl_reg_rmw(data->pll, secctl, PLL_CLKOD_SMASK,
  66. (pllod << PLL_CLKOD_SHIFT));
  67. wait_for_completion(data);
  68. pllctl_reg_write(data->pll, div1, PLLM_RATIO_DIV1);
  69. pllctl_reg_write(data->pll, div2, PLLM_RATIO_DIV2);
  70. pllctl_reg_write(data->pll, div3, PLLM_RATIO_DIV3);
  71. pllctl_reg_write(data->pll, div4, PLLM_RATIO_DIV4);
  72. pllctl_reg_write(data->pll, div5, PLLM_RATIO_DIV5);
  73. pllctl_reg_setbits(data->pll, alnctl, 0x1f);
  74. /*
  75. * Set GOSET bit in PLLCMD to initiate the GO operation
  76. * to change the divide
  77. */
  78. pllctl_reg_setbits(data->pll, cmd, PLLSTAT_GO);
  79. sdelay(1500); /* wait for the phase adj */
  80. wait_for_completion(data);
  81. /* Reset PLL */
  82. pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLRST);
  83. sdelay(21000); /* Wait for a minimum of 7 us*/
  84. pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLRST);
  85. sdelay(105000); /* Wait for PLL Lock time (min 50 us) */
  86. pllctl_reg_clrbits(data->pll, secctl, PLLCTL_BYPASS);
  87. tmp = pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLEN);
  88. #ifndef CONFIG_SOC_K2E
  89. } else if (data->pll == TETRIS_PLL) {
  90. bwadj = pllm >> 1;
  91. /* 1.5 Set PLLCTL0[BYPASS] =1 (enable bypass), */
  92. setbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
  93. /*
  94. * Set CHIPMISCCTL1[13] = 0 (enable glitchfree bypass)
  95. * only applicable for Kepler
  96. */
  97. clrbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN);
  98. /* 2 In PLLCTL1, write PLLRST = 1 (PLL is reset) */
  99. setbits_le32(keystone_pll_regs[data->pll].reg1 ,
  100. PLL_PLLRST | PLLCTL_ENSAT);
  101. /*
  102. * 3 Program PLLM and PLLD in PLLCTL0 register
  103. * 4 Program BWADJ[7:0] in PLLCTL0 and BWADJ[11:8] in
  104. * PLLCTL1 register. BWADJ value must be set
  105. * to ((PLLM + 1) >> 1) – 1)
  106. */
  107. tmp = ((bwadj & PLL_BWADJ_LO_MASK) << PLL_BWADJ_LO_SHIFT) |
  108. (pllm << 6) |
  109. (plld & PLL_DIV_MASK) |
  110. (pllod << PLL_CLKOD_SHIFT) | PLLCTL_BYPASS;
  111. __raw_writel(tmp, keystone_pll_regs[data->pll].reg0);
  112. /* Set BWADJ[11:8] bits */
  113. tmp = __raw_readl(keystone_pll_regs[data->pll].reg1);
  114. tmp &= ~(PLL_BWADJ_HI_MASK);
  115. tmp |= ((bwadj>>8) & PLL_BWADJ_HI_MASK);
  116. __raw_writel(tmp, keystone_pll_regs[data->pll].reg1);
  117. /*
  118. * 5 Wait for at least 5 us based on the reference
  119. * clock (PLL reset time)
  120. */
  121. sdelay(21000); /* Wait for a minimum of 7 us*/
  122. /* 6 In PLLCTL1, write PLLRST = 0 (PLL reset is released) */
  123. clrbits_le32(keystone_pll_regs[data->pll].reg1, PLL_PLLRST);
  124. /*
  125. * 7 Wait for at least 500 * REFCLK cycles * (PLLD + 1)
  126. * (PLL lock time)
  127. */
  128. sdelay(105000);
  129. /* 8 disable bypass */
  130. clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
  131. /*
  132. * 9 Set CHIPMISCCTL1[13] = 1 (disable glitchfree bypass)
  133. * only applicable for Kepler
  134. */
  135. setbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN);
  136. #endif
  137. } else {
  138. setbits_le32(keystone_pll_regs[data->pll].reg1, PLLCTL_ENSAT);
  139. /*
  140. * process keeps state of Bypass bit while programming
  141. * all other DDR PLL settings
  142. */
  143. tmp = __raw_readl(keystone_pll_regs[data->pll].reg0);
  144. tmp &= PLLCTL_BYPASS; /* clear everything except Bypass */
  145. /*
  146. * Set the BWADJ[7:0], PLLD[5:0] and PLLM to PLLCTL0,
  147. * bypass disabled
  148. */
  149. bwadj = pllm >> 1;
  150. tmp |= ((bwadj & PLL_BWADJ_LO_SHIFT) << PLL_BWADJ_LO_SHIFT) |
  151. (pllm << PLL_MULT_SHIFT) |
  152. (plld & PLL_DIV_MASK) |
  153. (pllod << PLL_CLKOD_SHIFT);
  154. __raw_writel(tmp, keystone_pll_regs[data->pll].reg0);
  155. /* Set BWADJ[11:8] bits */
  156. tmp = __raw_readl(keystone_pll_regs[data->pll].reg1);
  157. tmp &= ~(PLL_BWADJ_HI_MASK);
  158. tmp |= ((bwadj >> 8) & PLL_BWADJ_HI_MASK);
  159. /* set PLL Select (bit 13) for PASS PLL */
  160. if (data->pll == PASS_PLL)
  161. tmp |= PLLCTL_PAPLL;
  162. __raw_writel(tmp, keystone_pll_regs[data->pll].reg1);
  163. /* Reset bit: bit 14 for both DDR3 & PASS PLL */
  164. tmp = PLL_PLLRST;
  165. /* Set RESET bit = 1 */
  166. setbits_le32(keystone_pll_regs[data->pll].reg1, tmp);
  167. /* Wait for a minimum of 7 us*/
  168. sdelay(21000);
  169. /* Clear RESET bit */
  170. clrbits_le32(keystone_pll_regs[data->pll].reg1, tmp);
  171. sdelay(105000);
  172. /* clear BYPASS (Enable PLL Mode) */
  173. clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
  174. sdelay(21000); /* Wait for a minimum of 7 us*/
  175. }
  176. /*
  177. * This is required to provide a delay between multiple
  178. * consequent PPL configurations
  179. */
  180. sdelay(210000);
  181. }
  182. void init_plls(int num_pll, struct pll_init_data *config)
  183. {
  184. int i;
  185. for (i = 0; i < num_pll; i++)
  186. init_pll(&config[i]);
  187. }
  188. static int get_max_speed(u32 val, int *speeds)
  189. {
  190. int j;
  191. if (!val)
  192. return speeds[0];
  193. for (j = 1; j < MAX_SPEEDS; j++) {
  194. if (val == 1)
  195. return speeds[j];
  196. val >>= 1;
  197. }
  198. return SPD800;
  199. }
  200. #ifdef CONFIG_SOC_K2HK
  201. static u32 read_efuse_bootrom(void)
  202. {
  203. return (cpu_revision() > 1) ? __raw_readl(KS2_EFUSE_BOOTROM) :
  204. __raw_readl(KS2_REV1_DEVSPEED);
  205. }
  206. #else
  207. static inline u32 read_efuse_bootrom(void)
  208. {
  209. return __raw_readl(KS2_EFUSE_BOOTROM);
  210. }
  211. #endif
  212. inline int get_max_dev_speed(void)
  213. {
  214. return get_max_speed(read_efuse_bootrom() & 0xffff, dev_speeds);
  215. }
  216. #ifndef CONFIG_SOC_K2E
  217. inline int get_max_arm_speed(void)
  218. {
  219. return get_max_speed((read_efuse_bootrom() >> 16) & 0xffff, arm_speeds);
  220. }
  221. #endif