tqm8540.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright 2005 DENX Software Engineering
  3. * Copyright 2004 Freescale Semiconductor.
  4. * (C) Copyright 2002,2003, Motorola Inc.
  5. * Xianghua Xiao, (X.Xiao@motorola.com)
  6. *
  7. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <pci.h>
  29. #include <asm/processor.h>
  30. #include <asm/immap_85xx.h>
  31. #include <spd.h>
  32. #if defined(CONFIG_DDR_ECC)
  33. extern void ddr_enable_ecc (unsigned int dram_size);
  34. #endif
  35. extern long int spd_sdram (void);
  36. void local_bus_init (void);
  37. long int fixed_sdram (void);
  38. int board_early_init_f (void)
  39. {
  40. return 0;
  41. }
  42. int checkboard (void)
  43. {
  44. puts ("Board: TQM8540\n");
  45. #ifdef CONFIG_PCI
  46. printf ("PCI1: 32 bit, %d MHz (compiled)\n",
  47. CONFIG_SYS_CLK_FREQ / 1000000);
  48. #else
  49. printf ("PCI1: disabled\n");
  50. #endif
  51. /*
  52. * Initialize local bus.
  53. */
  54. local_bus_init ();
  55. return 0;
  56. }
  57. long int initdram (int board_type)
  58. {
  59. long dram_size = 0;
  60. extern long spd_sdram (void);
  61. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  62. #if defined(CONFIG_DDR_DLL)
  63. {
  64. volatile ccsr_gur_t *gur= &immap->im_gur;
  65. int i,x;
  66. x = 10;
  67. /*
  68. * Work around to stabilize DDR DLL
  69. */
  70. gur->ddrdllcr = 0x81000000;
  71. asm("sync;isync;msync");
  72. udelay (200);
  73. while (gur->ddrdllcr != 0x81000100) {
  74. gur->devdisr = gur->devdisr | 0x00010000;
  75. asm("sync;isync;msync");
  76. for (i=0; i<x; i++)
  77. ;
  78. gur->devdisr = gur->devdisr & 0xfff7ffff;
  79. asm("sync;isync;msync");
  80. x++;
  81. }
  82. }
  83. #endif
  84. #if defined(CONFIG_SPD_EEPROM)
  85. dram_size = spd_sdram ();
  86. #else
  87. dram_size = fixed_sdram ();
  88. #endif
  89. #if defined(CONFIG_DDR_ECC)
  90. /*
  91. * Initialize and enable DDR ECC.
  92. */
  93. ddr_enable_ecc (dram_size);
  94. #endif
  95. return dram_size;
  96. }
  97. /*
  98. * Initialize Local Bus
  99. */
  100. void local_bus_init (void)
  101. {
  102. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  103. volatile ccsr_gur_t *gur = &immap->im_gur;
  104. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  105. uint clkdiv;
  106. uint lbc_hz;
  107. sys_info_t sysinfo;
  108. /*
  109. * Errata LBC11.
  110. * Fix Local Bus clock glitch when DLL is enabled.
  111. *
  112. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  113. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  114. * Between 66 and 133, the DLL is enabled with an override workaround.
  115. */
  116. get_sys_info (&sysinfo);
  117. clkdiv = lbc->lcrr & 0x0f;
  118. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  119. if (lbc_hz < 66) {
  120. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  121. lbc->ltedr = 0xa4c80000; /* DK: !!! */
  122. } else if (lbc_hz >= 133) {
  123. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  124. } else {
  125. /*
  126. * On REV1 boards, need to change CLKDIV before enable DLL.
  127. * Default CLKDIV is 8, change it to 4 temporarily.
  128. */
  129. uint pvr = get_pvr ();
  130. uint temp_lbcdll = 0;
  131. if (pvr == PVR_85xx_REV1) {
  132. /* FIXME: Justify the high bit here. */
  133. lbc->lcrr = 0x10000004;
  134. }
  135. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  136. udelay (200);
  137. /*
  138. * Sample LBC DLL ctrl reg, upshift it to set the
  139. * override bits.
  140. */
  141. temp_lbcdll = gur->lbcdllcr;
  142. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  143. asm ("sync;isync;msync");
  144. }
  145. }
  146. #if defined(CFG_DRAM_TEST)
  147. int testdram (void)
  148. {
  149. uint *pstart = (uint *) CFG_MEMTEST_START;
  150. uint *pend = (uint *) CFG_MEMTEST_END;
  151. uint *p;
  152. printf ("SDRAM test phase 1:\n");
  153. for (p = pstart; p < pend; p++)
  154. *p = 0xaaaaaaaa;
  155. for (p = pstart; p < pend; p++) {
  156. if (*p != 0xaaaaaaaa) {
  157. printf ("SDRAM test fails at: %08x\n", (uint) p);
  158. return 1;
  159. }
  160. }
  161. printf ("SDRAM test phase 2:\n");
  162. for (p = pstart; p < pend; p++)
  163. *p = 0x55555555;
  164. for (p = pstart; p < pend; p++) {
  165. if (*p != 0x55555555) {
  166. printf ("SDRAM test fails at: %08x\n", (uint) p);
  167. return 1;
  168. }
  169. }
  170. printf ("SDRAM test passed.\n");
  171. return 0;
  172. }
  173. #endif
  174. #if !defined(CONFIG_SPD_EEPROM)
  175. /*************************************************************************
  176. * fixed sdram init -- doesn't use serial presence detect.
  177. ************************************************************************/
  178. long int fixed_sdram (void)
  179. {
  180. #ifndef CFG_RAMBOOT
  181. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  182. volatile ccsr_ddr_t *ddr = &immap->im_ddr;
  183. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  184. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  185. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  186. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  187. ddr->sdram_mode = CFG_DDR_MODE;
  188. ddr->sdram_interval = CFG_DDR_INTERVAL;
  189. ddr->err_disable = 0x0000000D;
  190. #if defined (CONFIG_DDR_ECC)
  191. ddr->err_disable = 0x0000000D;
  192. ddr->err_sbe = 0x00ff0000;
  193. #endif
  194. asm ("sync;isync;msync");
  195. udelay (500);
  196. #if defined (CONFIG_DDR_ECC)
  197. /* Enable ECC checking */
  198. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  199. #else
  200. ddr->sdram_cfg = CFG_DDR_CONTROL;
  201. #endif
  202. asm ("sync; isync; msync");
  203. udelay (500);
  204. #endif
  205. return get_ram_size (0, CFG_SDRAM_SIZE * 1024 * 1024);
  206. }
  207. #endif /* !defined(CONFIG_SPD_EEPROM) */
  208. #if defined(CONFIG_PCI)
  209. /*
  210. * Initialize PCI Devices, report devices found.
  211. */
  212. #ifndef CONFIG_PCI_PNP
  213. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  214. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  215. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  216. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  217. PCI_ENET0_MEMADDR,
  218. PCI_COMMAND_MEMORY |
  219. PCI_COMMAND_MASTER}},
  220. {}
  221. };
  222. #endif
  223. static struct pci_controller hose = {
  224. #ifndef CONFIG_PCI_PNP
  225. config_table:pci_mpc85xxads_config_table,
  226. #endif
  227. };
  228. #endif /* CONFIG_PCI */
  229. void pci_init_board (void)
  230. {
  231. #ifdef CONFIG_PCI
  232. extern void pci_mpc85xx_init (struct pci_controller *hose);
  233. pci_mpc85xx_init (&hose);
  234. #endif /* CONFIG_PCI */
  235. }