spl.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (C) 2011
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <version.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/hardware.h>
  29. #include <asm/arch/spr_defs.h>
  30. #include <asm/arch/spr_misc.h>
  31. #include <asm/arch/spr_syscntl.h>
  32. inline void hang(void)
  33. {
  34. serial_puts("### ERROR ### Please RESET the board ###\n");
  35. for (;;)
  36. ;
  37. }
  38. static void ddr_clock_init(void)
  39. {
  40. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  41. u32 clkenb, ddrpll;
  42. clkenb = readl(&misc_p->periph1_clken);
  43. clkenb &= ~PERIPH_MPMCMSK;
  44. clkenb |= PERIPH_MPMC_WE;
  45. /* Intentionally done twice */
  46. writel(clkenb, &misc_p->periph1_clken);
  47. writel(clkenb, &misc_p->periph1_clken);
  48. ddrpll = readl(&misc_p->pll_ctr_reg);
  49. ddrpll &= ~MEM_CLK_SEL_MSK;
  50. #if (CONFIG_DDR_HCLK)
  51. ddrpll |= MEM_CLK_HCLK;
  52. #elif (CONFIG_DDR_2HCLK)
  53. ddrpll |= MEM_CLK_2HCLK;
  54. #elif (CONFIG_DDR_PLL2)
  55. ddrpll |= MEM_CLK_PLL2;
  56. #else
  57. #error "please define one of CONFIG_DDR_(HCLK|2HCLK|PLL2)"
  58. #endif
  59. writel(ddrpll, &misc_p->pll_ctr_reg);
  60. writel(readl(&misc_p->periph1_clken) | PERIPH_MPMC_EN,
  61. &misc_p->periph1_clken);
  62. }
  63. static void mpmc_init_values(void)
  64. {
  65. u32 i;
  66. u32 *mpmc_reg_p = (u32 *)CONFIG_SPEAR_MPMCBASE;
  67. u32 *mpmc_val_p = &mpmc_conf_vals[0];
  68. for (i = 0; i < CONFIG_SPEAR_MPMCREGS; i++, mpmc_reg_p++, mpmc_val_p++)
  69. writel(*mpmc_val_p, mpmc_reg_p);
  70. mpmc_reg_p = (u32 *)CONFIG_SPEAR_MPMCBASE;
  71. /*
  72. * MPMC controller start
  73. * MPMC waiting for DLLLOCKREG high
  74. */
  75. writel(0x01000100, &mpmc_reg_p[7]);
  76. while (!(readl(&mpmc_reg_p[3]) & 0x10000))
  77. ;
  78. }
  79. static void mpmc_init(void)
  80. {
  81. /* Clock related settings for DDR */
  82. ddr_clock_init();
  83. /*
  84. * DDR pad register bits are different for different SoCs
  85. * Compensation values are also handled separately
  86. */
  87. plat_ddr_init();
  88. /* Initialize mpmc register values */
  89. mpmc_init_values();
  90. }
  91. static void pll_init(void)
  92. {
  93. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  94. /* Initialize PLLs */
  95. writel(FREQ_332, &misc_p->pll1_frq);
  96. writel(0x1C0A, &misc_p->pll1_cntl);
  97. writel(0x1C0E, &misc_p->pll1_cntl);
  98. writel(0x1C06, &misc_p->pll1_cntl);
  99. writel(0x1C0E, &misc_p->pll1_cntl);
  100. writel(FREQ_332, &misc_p->pll2_frq);
  101. writel(0x1C0A, &misc_p->pll2_cntl);
  102. writel(0x1C0E, &misc_p->pll2_cntl);
  103. writel(0x1C06, &misc_p->pll2_cntl);
  104. writel(0x1C0E, &misc_p->pll2_cntl);
  105. /* wait for pll locks */
  106. while (!(readl(&misc_p->pll1_cntl) & 0x1))
  107. ;
  108. while (!(readl(&misc_p->pll2_cntl) & 0x1))
  109. ;
  110. }
  111. static void mac_init(void)
  112. {
  113. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  114. writel(readl(&misc_p->periph1_clken) & (~PERIPH_GMAC),
  115. &misc_p->periph1_clken);
  116. writel(SYNTH23, &misc_p->gmac_synth_clk);
  117. switch (get_socrev()) {
  118. case SOC_SPEAR600_AA:
  119. case SOC_SPEAR600_AB:
  120. case SOC_SPEAR600_BA:
  121. case SOC_SPEAR600_BB:
  122. case SOC_SPEAR600_BC:
  123. case SOC_SPEAR600_BD:
  124. writel(0x0, &misc_p->gmac_ctr_reg);
  125. break;
  126. case SOC_SPEAR300:
  127. case SOC_SPEAR310:
  128. case SOC_SPEAR320:
  129. writel(0x4, &misc_p->gmac_ctr_reg);
  130. break;
  131. }
  132. writel(readl(&misc_p->periph1_clken) | PERIPH_GMAC,
  133. &misc_p->periph1_clken);
  134. writel(readl(&misc_p->periph1_rst) | PERIPH_GMAC,
  135. &misc_p->periph1_rst);
  136. writel(readl(&misc_p->periph1_rst) & (~PERIPH_GMAC),
  137. &misc_p->periph1_rst);
  138. }
  139. static void sys_init(void)
  140. {
  141. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  142. struct syscntl_regs *syscntl_p =
  143. (struct syscntl_regs *)CONFIG_SPEAR_SYSCNTLBASE;
  144. /* Set system state to SLOW */
  145. writel(SLOW, &syscntl_p->scctrl);
  146. writel(PLL_TIM << 3, &syscntl_p->scpllctrl);
  147. /* Initialize PLLs */
  148. pll_init();
  149. /*
  150. * Ethernet configuration
  151. * To be done only if the tftp boot is not selected already
  152. * Boot code ensures the correct configuration in tftp booting
  153. */
  154. if (!tftp_boot_selected())
  155. mac_init();
  156. writel(RTC_DISABLE | PLLTIMEEN, &misc_p->periph_clk_cfg);
  157. writel(0x555, &misc_p->amba_clk_cfg);
  158. writel(NORMAL, &syscntl_p->scctrl);
  159. /* Wait for system to switch to normal mode */
  160. while (((readl(&syscntl_p->scctrl) >> MODE_SHIFT) & MODE_MASK)
  161. != NORMAL)
  162. ;
  163. }
  164. /*
  165. * get_socrev
  166. *
  167. * Get SoC Revision.
  168. * @return SOC_SPEARXXX
  169. */
  170. int get_socrev(void)
  171. {
  172. #if defined(CONFIG_SPEAR600)
  173. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  174. u32 soc_id = readl(&misc_p->soc_core_id);
  175. u32 pri_socid = (soc_id >> SOC_PRI_SHFT) & 0xFF;
  176. u32 sec_socid = (soc_id >> SOC_SEC_SHFT) & 0xFF;
  177. if ((pri_socid == 'B') && (sec_socid == 'B'))
  178. return SOC_SPEAR600_BB;
  179. else if ((pri_socid == 'B') && (sec_socid == 'C'))
  180. return SOC_SPEAR600_BC;
  181. else if ((pri_socid == 'B') && (sec_socid == 'D'))
  182. return SOC_SPEAR600_BD;
  183. else if (soc_id == 0)
  184. return SOC_SPEAR600_BA;
  185. else
  186. return SOC_SPEAR_NA;
  187. #elif defined(CONFIG_SPEAR300)
  188. return SOC_SPEAR300;
  189. #elif defined(CONFIG_SPEAR310)
  190. return SOC_SPEAR310;
  191. #elif defined(CONFIG_SPEAR320)
  192. return SOC_SPEAR320;
  193. #endif
  194. }
  195. void lowlevel_init(void)
  196. {
  197. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  198. const char *u_boot_rev = U_BOOT_VERSION;
  199. /* Initialize PLLs */
  200. sys_init();
  201. /* Initialize UART */
  202. serial_init();
  203. /* Print U-Boot SPL version string */
  204. serial_puts("\nU-Boot SPL ");
  205. /* Avoid a second "U-Boot" coming from this string */
  206. u_boot_rev = &u_boot_rev[7];
  207. serial_puts(u_boot_rev);
  208. serial_puts(" (");
  209. serial_puts(U_BOOT_DATE);
  210. serial_puts(" - ");
  211. serial_puts(U_BOOT_TIME);
  212. serial_puts(")\n");
  213. #if defined(CONFIG_OS_BOOT)
  214. writel(readl(&misc_p->periph1_clken) | PERIPH_UART1,
  215. &misc_p->periph1_clken);
  216. #endif
  217. /* Enable IPs (release reset) */
  218. writel(PERIPH_RST_ALL, &misc_p->periph1_rst);
  219. /* Initialize MPMC */
  220. serial_puts("Configure DDR\n");
  221. mpmc_init();
  222. /* SoC specific initialization */
  223. soc_init();
  224. }
  225. void spear_late_init(void)
  226. {
  227. struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
  228. writel(0x80000007, &misc_p->arb_icm_ml1);
  229. writel(0x80000007, &misc_p->arb_icm_ml2);
  230. writel(0x80000007, &misc_p->arb_icm_ml3);
  231. writel(0x80000007, &misc_p->arb_icm_ml4);
  232. writel(0x80000007, &misc_p->arb_icm_ml5);
  233. writel(0x80000007, &misc_p->arb_icm_ml6);
  234. writel(0x80000007, &misc_p->arb_icm_ml7);
  235. writel(0x80000007, &misc_p->arb_icm_ml8);
  236. writel(0x80000007, &misc_p->arb_icm_ml9);
  237. }