tqm8540.c 6.0 KB

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