mpc8568mds.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Copyright 2007 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/immap_85xx.h>
  28. #include <spd.h>
  29. #include "bcsr.h"
  30. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  31. extern void ddr_enable_ecc(unsigned int dram_size);
  32. #endif
  33. extern long int spd_sdram(void);
  34. void local_bus_init(void);
  35. void sdram_init(void);
  36. int board_early_init_f (void)
  37. {
  38. /*
  39. * Initialize local bus.
  40. */
  41. local_bus_init ();
  42. enable_8568mds_duart();
  43. enable_8568mds_flash_write();
  44. return 0;
  45. }
  46. int checkboard (void)
  47. {
  48. printf ("Board: 8568 MDS\n");
  49. return 0;
  50. }
  51. long int
  52. initdram(int board_type)
  53. {
  54. long dram_size = 0;
  55. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  56. puts("Initializing\n");
  57. #if defined(CONFIG_DDR_DLL)
  58. {
  59. /*
  60. * Work around to stabilize DDR DLL MSYNC_IN.
  61. * Errata DDR9 seems to have been fixed.
  62. * This is now the workaround for Errata DDR11:
  63. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  64. */
  65. volatile ccsr_gur_t *gur= &immap->im_gur;
  66. gur->ddrdllcr = 0x81000000;
  67. asm("sync;isync;msync");
  68. udelay(200);
  69. }
  70. #endif
  71. dram_size = spd_sdram();
  72. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  73. /*
  74. * Initialize and enable DDR ECC.
  75. */
  76. ddr_enable_ecc(dram_size);
  77. #endif
  78. /*
  79. * SDRAM Initialization
  80. */
  81. sdram_init();
  82. puts(" DDR: ");
  83. return dram_size;
  84. }
  85. /*
  86. * Initialize Local Bus
  87. */
  88. void
  89. local_bus_init(void)
  90. {
  91. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  92. volatile ccsr_gur_t *gur = &immap->im_gur;
  93. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  94. uint clkdiv;
  95. uint lbc_hz;
  96. sys_info_t sysinfo;
  97. get_sys_info(&sysinfo);
  98. clkdiv = (lbc->lcrr & 0x0f) * 2;
  99. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  100. gur->lbiuiplldcr1 = 0x00078080;
  101. if (clkdiv == 16) {
  102. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  103. } else if (clkdiv == 8) {
  104. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  105. } else if (clkdiv == 4) {
  106. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  107. }
  108. lbc->lcrr |= 0x00030000;
  109. asm("sync;isync;msync");
  110. }
  111. /*
  112. * Initialize SDRAM memory on the Local Bus.
  113. */
  114. void
  115. sdram_init(void)
  116. {
  117. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  118. uint idx;
  119. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  120. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  121. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  122. uint lsdmr_common;
  123. puts(" SDRAM: ");
  124. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  125. /*
  126. * Setup SDRAM Base and Option Registers
  127. */
  128. lbc->or2 = CFG_OR2_PRELIM;
  129. asm("msync");
  130. lbc->br2 = CFG_BR2_PRELIM;
  131. asm("msync");
  132. lbc->lbcr = CFG_LBC_LBCR;
  133. asm("msync");
  134. lbc->lsrt = CFG_LBC_LSRT;
  135. lbc->mrtpr = CFG_LBC_MRTPR;
  136. asm("msync");
  137. /*
  138. * MPC8568 uses "new" 15-16 style addressing.
  139. */
  140. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  141. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  142. /*
  143. * Issue PRECHARGE ALL command.
  144. */
  145. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  146. asm("sync;msync");
  147. *sdram_addr = 0xff;
  148. ppcDcbf((unsigned long) sdram_addr);
  149. udelay(100);
  150. /*
  151. * Issue 8 AUTO REFRESH commands.
  152. */
  153. for (idx = 0; idx < 8; idx++) {
  154. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  155. asm("sync;msync");
  156. *sdram_addr = 0xff;
  157. ppcDcbf((unsigned long) sdram_addr);
  158. udelay(100);
  159. }
  160. /*
  161. * Issue 8 MODE-set command.
  162. */
  163. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  164. asm("sync;msync");
  165. *sdram_addr = 0xff;
  166. ppcDcbf((unsigned long) sdram_addr);
  167. udelay(100);
  168. /*
  169. * Issue NORMAL OP command.
  170. */
  171. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  172. asm("sync;msync");
  173. *sdram_addr = 0xff;
  174. ppcDcbf((unsigned long) sdram_addr);
  175. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  176. #endif /* enable SDRAM init */
  177. }
  178. #if defined(CFG_DRAM_TEST)
  179. int
  180. testdram(void)
  181. {
  182. uint *pstart = (uint *) CFG_MEMTEST_START;
  183. uint *pend = (uint *) CFG_MEMTEST_END;
  184. uint *p;
  185. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  186. CFG_MEMTEST_START,
  187. CFG_MEMTEST_END);
  188. printf("DRAM test phase 1:\n");
  189. for (p = pstart; p < pend; p++)
  190. *p = 0xaaaaaaaa;
  191. for (p = pstart; p < pend; p++) {
  192. if (*p != 0xaaaaaaaa) {
  193. printf ("DRAM test fails at: %08x\n", (uint) p);
  194. return 1;
  195. }
  196. }
  197. printf("DRAM test phase 2:\n");
  198. for (p = pstart; p < pend; p++)
  199. *p = 0x55555555;
  200. for (p = pstart; p < pend; p++) {
  201. if (*p != 0x55555555) {
  202. printf ("DRAM test fails at: %08x\n", (uint) p);
  203. return 1;
  204. }
  205. }
  206. printf("DRAM test passed.\n");
  207. return 0;
  208. }
  209. #endif
  210. #if defined(CONFIG_PCI)
  211. #ifndef CONFIG_PCI_PNP
  212. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  213. {
  214. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  215. pci_cfgfunc_config_device,
  216. {PCI_ENET0_IOADDR,
  217. PCI_ENET0_MEMADDR,
  218. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  219. },
  220. {}
  221. };
  222. #endif
  223. static struct pci_controller hose[] = {
  224. #ifndef CONFIG_PCI_PNP
  225. { config_table: pci_mpc8568mds_config_table,},
  226. #endif
  227. #ifdef CONFIG_MPC85XX_PCI2
  228. {},
  229. #endif
  230. };
  231. #endif /* CONFIG_PCI */
  232. void
  233. pci_init_board(void)
  234. {
  235. #ifdef CONFIG_PCI
  236. pci_mpc85xx_init(&hose);
  237. #endif
  238. }