tqm8540.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. puts ("Initializing\n");
  63. #if defined(CONFIG_DDR_DLL)
  64. {
  65. volatile ccsr_gur_t *gur = &immap->im_gur;
  66. uint temp_ddrdll = 0;
  67. /*
  68. * Work around to stabilize DDR DLL
  69. */
  70. temp_ddrdll = gur->ddrdllcr;
  71. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  72. asm ("sync;isync;msync");
  73. }
  74. #endif
  75. #if defined(CONFIG_SPD_EEPROM)
  76. dram_size = spd_sdram ();
  77. #else
  78. dram_size = fixed_sdram ();
  79. #endif
  80. #if defined(CONFIG_DDR_ECC)
  81. /*
  82. * Initialize and enable DDR ECC.
  83. */
  84. ddr_enable_ecc (dram_size);
  85. #endif
  86. puts (" DDR: ");
  87. return dram_size;
  88. }
  89. /*
  90. * Initialize Local Bus
  91. */
  92. void local_bus_init (void)
  93. {
  94. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  95. volatile ccsr_gur_t *gur = &immap->im_gur;
  96. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  97. uint clkdiv;
  98. uint lbc_hz;
  99. sys_info_t sysinfo;
  100. /*
  101. * Errata LBC11.
  102. * Fix Local Bus clock glitch when DLL is enabled.
  103. *
  104. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  105. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  106. * Between 66 and 133, the DLL is enabled with an override workaround.
  107. */
  108. get_sys_info (&sysinfo);
  109. clkdiv = lbc->lcrr & 0x0f;
  110. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  111. if (lbc_hz < 66) {
  112. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  113. lbc->ltedr = 0xa4c80000; /* DK: !!! */
  114. } else if (lbc_hz >= 133) {
  115. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  116. } else {
  117. /*
  118. * On REV1 boards, need to change CLKDIV before enable DLL.
  119. * Default CLKDIV is 8, change it to 4 temporarily.
  120. */
  121. uint pvr = get_pvr ();
  122. uint temp_lbcdll = 0;
  123. if (pvr == PVR_85xx_REV1) {
  124. /* FIXME: Justify the high bit here. */
  125. lbc->lcrr = 0x10000004;
  126. }
  127. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  128. udelay (200);
  129. /*
  130. * Sample LBC DLL ctrl reg, upshift it to set the
  131. * override bits.
  132. */
  133. temp_lbcdll = gur->lbcdllcr;
  134. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  135. asm ("sync;isync;msync");
  136. }
  137. }
  138. #if defined(CFG_DRAM_TEST)
  139. int testdram (void)
  140. {
  141. uint *pstart = (uint *) CFG_MEMTEST_START;
  142. uint *pend = (uint *) CFG_MEMTEST_END;
  143. uint *p;
  144. printf ("SDRAM test phase 1:\n");
  145. for (p = pstart; p < pend; p++)
  146. *p = 0xaaaaaaaa;
  147. for (p = pstart; p < pend; p++) {
  148. if (*p != 0xaaaaaaaa) {
  149. printf ("SDRAM test fails at: %08x\n", (uint) p);
  150. return 1;
  151. }
  152. }
  153. printf ("SDRAM test phase 2:\n");
  154. for (p = pstart; p < pend; p++)
  155. *p = 0x55555555;
  156. for (p = pstart; p < pend; p++) {
  157. if (*p != 0x55555555) {
  158. printf ("SDRAM test fails at: %08x\n", (uint) p);
  159. return 1;
  160. }
  161. }
  162. printf ("SDRAM test passed.\n");
  163. return 0;
  164. }
  165. #endif
  166. #if !defined(CONFIG_SPD_EEPROM)
  167. /*************************************************************************
  168. * fixed sdram init -- doesn't use serial presence detect.
  169. ************************************************************************/
  170. long int fixed_sdram (void)
  171. {
  172. #ifndef CFG_RAMBOOT
  173. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  174. volatile ccsr_ddr_t *ddr = &immap->im_ddr;
  175. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  176. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  177. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  178. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  179. ddr->sdram_mode = CFG_DDR_MODE;
  180. ddr->sdram_interval = CFG_DDR_INTERVAL;
  181. ddr->err_disable = 0x0000000D;
  182. #if defined (CONFIG_DDR_ECC)
  183. ddr->err_disable = 0x0000000D;
  184. ddr->err_sbe = 0x00ff0000;
  185. #endif
  186. asm ("sync;isync;msync");
  187. udelay (500);
  188. #if defined (CONFIG_DDR_ECC)
  189. /* Enable ECC checking */
  190. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  191. #else
  192. ddr->sdram_cfg = CFG_DDR_CONTROL;
  193. #endif
  194. asm ("sync; isync; msync");
  195. udelay (500);
  196. #endif
  197. return get_ram_size (0, CFG_SDRAM_SIZE * 1024 * 1024);
  198. }
  199. #endif /* !defined(CONFIG_SPD_EEPROM) */
  200. #if defined(CONFIG_PCI)
  201. /*
  202. * Initialize PCI Devices, report devices found.
  203. */
  204. #ifndef CONFIG_PCI_PNP
  205. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  206. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  207. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  208. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  209. PCI_ENET0_MEMADDR,
  210. PCI_COMMAND_MEMORY |
  211. PCI_COMMAND_MASTER}},
  212. {}
  213. };
  214. #endif
  215. static struct pci_controller hose = {
  216. #ifndef CONFIG_PCI_PNP
  217. config_table:pci_mpc85xxads_config_table,
  218. #endif
  219. };
  220. #endif /* CONFIG_PCI */
  221. void pci_init_board (void)
  222. {
  223. #ifdef CONFIG_PCI
  224. extern void pci_mpc85xx_init (struct pci_controller *hose);
  225. pci_mpc85xx_init (&hose);
  226. #endif /* CONFIG_PCI */
  227. }