spl.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011
  4. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  5. *
  6. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  7. */
  8. #include <common.h>
  9. #include <spl.h>
  10. #include <version.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/hardware.h>
  13. #include <asm/arch/spr_defs.h>
  14. #include <asm/arch/spr_misc.h>
  15. #include <asm/arch/spr_syscntl.h>
  16. #include <linux/mtd/st_smi.h>
  17. static void ddr_clock_init(void)
  18. {
  19. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  20. u32 clkenb, ddrpll;
  21. clkenb = readl(&misc_p->periph1_clken);
  22. clkenb &= ~PERIPH_MPMCMSK;
  23. clkenb |= PERIPH_MPMC_WE;
  24. /* Intentionally done twice */
  25. writel(clkenb, &misc_p->periph1_clken);
  26. writel(clkenb, &misc_p->periph1_clken);
  27. ddrpll = readl(&misc_p->pll_ctr_reg);
  28. ddrpll &= ~MEM_CLK_SEL_MSK;
  29. #if (CONFIG_DDR_HCLK)
  30. ddrpll |= MEM_CLK_HCLK;
  31. #elif (CONFIG_DDR_2HCLK)
  32. ddrpll |= MEM_CLK_2HCLK;
  33. #elif (CONFIG_DDR_PLL2)
  34. ddrpll |= MEM_CLK_PLL2;
  35. #else
  36. #error "please define one of CONFIG_DDR_(HCLK|2HCLK|PLL2)"
  37. #endif
  38. writel(ddrpll, &misc_p->pll_ctr_reg);
  39. writel(readl(&misc_p->periph1_clken) | PERIPH_MPMC_EN,
  40. &misc_p->periph1_clken);
  41. }
  42. static void mpmc_init_values(void)
  43. {
  44. u32 i;
  45. u32 *mpmc_reg_p = (u32 *)CONFIG_SPEAR_MPMCBASE;
  46. u32 *mpmc_val_p = &mpmc_conf_vals[0];
  47. for (i = 0; i < CONFIG_SPEAR_MPMCREGS; i++, mpmc_reg_p++, mpmc_val_p++)
  48. writel(*mpmc_val_p, mpmc_reg_p);
  49. mpmc_reg_p = (u32 *)CONFIG_SPEAR_MPMCBASE;
  50. /*
  51. * MPMC controller start
  52. * MPMC waiting for DLLLOCKREG high
  53. */
  54. writel(0x01000100, &mpmc_reg_p[7]);
  55. while (!(readl(&mpmc_reg_p[3]) & 0x10000))
  56. ;
  57. }
  58. static void mpmc_init(void)
  59. {
  60. /* Clock related settings for DDR */
  61. ddr_clock_init();
  62. /*
  63. * DDR pad register bits are different for different SoCs
  64. * Compensation values are also handled separately
  65. */
  66. plat_ddr_init();
  67. /* Initialize mpmc register values */
  68. mpmc_init_values();
  69. }
  70. static void pll_init(void)
  71. {
  72. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  73. /* Initialize PLLs */
  74. writel(FREQ_332, &misc_p->pll1_frq);
  75. writel(0x1C0A, &misc_p->pll1_cntl);
  76. writel(0x1C0E, &misc_p->pll1_cntl);
  77. writel(0x1C06, &misc_p->pll1_cntl);
  78. writel(0x1C0E, &misc_p->pll1_cntl);
  79. writel(FREQ_332, &misc_p->pll2_frq);
  80. writel(0x1C0A, &misc_p->pll2_cntl);
  81. writel(0x1C0E, &misc_p->pll2_cntl);
  82. writel(0x1C06, &misc_p->pll2_cntl);
  83. writel(0x1C0E, &misc_p->pll2_cntl);
  84. /* wait for pll locks */
  85. while (!(readl(&misc_p->pll1_cntl) & 0x1))
  86. ;
  87. while (!(readl(&misc_p->pll2_cntl) & 0x1))
  88. ;
  89. }
  90. static void mac_init(void)
  91. {
  92. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  93. writel(readl(&misc_p->periph1_clken) & (~PERIPH_GMAC),
  94. &misc_p->periph1_clken);
  95. writel(SYNTH23, &misc_p->gmac_synth_clk);
  96. switch (get_socrev()) {
  97. case SOC_SPEAR600_AA:
  98. case SOC_SPEAR600_AB:
  99. case SOC_SPEAR600_BA:
  100. case SOC_SPEAR600_BB:
  101. case SOC_SPEAR600_BC:
  102. case SOC_SPEAR600_BD:
  103. writel(0x0, &misc_p->gmac_ctr_reg);
  104. break;
  105. case SOC_SPEAR300:
  106. case SOC_SPEAR310:
  107. case SOC_SPEAR320:
  108. writel(0x4, &misc_p->gmac_ctr_reg);
  109. break;
  110. }
  111. writel(readl(&misc_p->periph1_clken) | PERIPH_GMAC,
  112. &misc_p->periph1_clken);
  113. writel(readl(&misc_p->periph1_rst) | PERIPH_GMAC,
  114. &misc_p->periph1_rst);
  115. writel(readl(&misc_p->periph1_rst) & (~PERIPH_GMAC),
  116. &misc_p->periph1_rst);
  117. }
  118. static void sys_init(void)
  119. {
  120. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  121. struct syscntl_regs *syscntl_p =
  122. (struct syscntl_regs *)CONFIG_SPEAR_SYSCNTLBASE;
  123. /* Set system state to SLOW */
  124. writel(SLOW, &syscntl_p->scctrl);
  125. writel(PLL_TIM << 3, &syscntl_p->scpllctrl);
  126. /* Initialize PLLs */
  127. pll_init();
  128. /*
  129. * Ethernet configuration
  130. * To be done only if the tftp boot is not selected already
  131. * Boot code ensures the correct configuration in tftp booting
  132. */
  133. if (!tftp_boot_selected())
  134. mac_init();
  135. writel(RTC_DISABLE | PLLTIMEEN, &misc_p->periph_clk_cfg);
  136. writel(0x555, &misc_p->amba_clk_cfg);
  137. writel(NORMAL, &syscntl_p->scctrl);
  138. /* Wait for system to switch to normal mode */
  139. while (((readl(&syscntl_p->scctrl) >> MODE_SHIFT) & MODE_MASK)
  140. != NORMAL)
  141. ;
  142. }
  143. /*
  144. * get_socrev
  145. *
  146. * Get SoC Revision.
  147. * @return SOC_SPEARXXX
  148. */
  149. int get_socrev(void)
  150. {
  151. #if defined(CONFIG_SPEAR600)
  152. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  153. u32 soc_id = readl(&misc_p->soc_core_id);
  154. u32 pri_socid = (soc_id >> SOC_PRI_SHFT) & 0xFF;
  155. u32 sec_socid = (soc_id >> SOC_SEC_SHFT) & 0xFF;
  156. if ((pri_socid == 'B') && (sec_socid == 'B'))
  157. return SOC_SPEAR600_BB;
  158. else if ((pri_socid == 'B') && (sec_socid == 'C'))
  159. return SOC_SPEAR600_BC;
  160. else if ((pri_socid == 'B') && (sec_socid == 'D'))
  161. return SOC_SPEAR600_BD;
  162. else if (soc_id == 0)
  163. return SOC_SPEAR600_BA;
  164. else
  165. return SOC_SPEAR_NA;
  166. #elif defined(CONFIG_SPEAR300)
  167. return SOC_SPEAR300;
  168. #elif defined(CONFIG_SPEAR310)
  169. return SOC_SPEAR310;
  170. #elif defined(CONFIG_SPEAR320)
  171. return SOC_SPEAR320;
  172. #endif
  173. }
  174. /*
  175. * SNOR (Serial NOR flash) related functions
  176. */
  177. static void snor_init(void)
  178. {
  179. struct smi_regs *const smicntl =
  180. (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
  181. /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
  182. writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
  183. &smicntl->smi_cr1);
  184. }
  185. u32 spl_boot_device(void)
  186. {
  187. u32 mode = 0;
  188. /* Currently only SNOR is supported as the only */
  189. if (snor_boot_selected()) {
  190. /* SNOR-SMI initialization */
  191. snor_init();
  192. mode = BOOT_DEVICE_NOR;
  193. }
  194. return mode;
  195. }
  196. void board_init_f(ulong dummy)
  197. {
  198. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  199. /* Initialize PLLs */
  200. sys_init();
  201. preloader_console_init();
  202. arch_cpu_init();
  203. /* Enable IPs (release reset) */
  204. writel(PERIPH_RST_ALL, &misc_p->periph1_rst);
  205. /* Initialize MPMC */
  206. puts("Configure DDR\n");
  207. mpmc_init();
  208. spear_late_init();
  209. board_init_r(NULL, 0);
  210. }