mpc8568mds.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 <i2c.h>
  30. #include "bcsr.h"
  31. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  32. extern void ddr_enable_ecc(unsigned int dram_size);
  33. #endif
  34. extern long int spd_sdram(void);
  35. void local_bus_init(void);
  36. void sdram_init(void);
  37. int board_early_init_f (void)
  38. {
  39. /*
  40. * Initialize local bus.
  41. */
  42. local_bus_init ();
  43. enable_8568mds_duart();
  44. enable_8568mds_flash_write();
  45. #ifdef CFG_I2C2_OFFSET
  46. /* Enable I2C2_SCL and I2C2_SDA */
  47. volatile struct par_io *port_c;
  48. port_c = (struct par_io*)(CFG_IMMR + 0xe0140);
  49. port_c->cpdir2 |= 0x0f000000;
  50. port_c->cppar2 &= ~0x0f000000;
  51. port_c->cppar2 |= 0x0a000000;
  52. #endif
  53. return 0;
  54. }
  55. int checkboard (void)
  56. {
  57. printf ("Board: 8568 MDS\n");
  58. return 0;
  59. }
  60. long int
  61. initdram(int board_type)
  62. {
  63. long dram_size = 0;
  64. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  65. puts("Initializing\n");
  66. #if defined(CONFIG_DDR_DLL)
  67. {
  68. /*
  69. * Work around to stabilize DDR DLL MSYNC_IN.
  70. * Errata DDR9 seems to have been fixed.
  71. * This is now the workaround for Errata DDR11:
  72. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  73. */
  74. volatile ccsr_gur_t *gur= &immap->im_gur;
  75. gur->ddrdllcr = 0x81000000;
  76. asm("sync;isync;msync");
  77. udelay(200);
  78. }
  79. #endif
  80. dram_size = spd_sdram();
  81. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  82. /*
  83. * Initialize and enable DDR ECC.
  84. */
  85. ddr_enable_ecc(dram_size);
  86. #endif
  87. /*
  88. * SDRAM Initialization
  89. */
  90. sdram_init();
  91. puts(" DDR: ");
  92. return dram_size;
  93. }
  94. /*
  95. * Initialize Local Bus
  96. */
  97. void
  98. local_bus_init(void)
  99. {
  100. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  101. volatile ccsr_gur_t *gur = &immap->im_gur;
  102. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  103. uint clkdiv;
  104. uint lbc_hz;
  105. sys_info_t sysinfo;
  106. get_sys_info(&sysinfo);
  107. clkdiv = (lbc->lcrr & 0x0f) * 2;
  108. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  109. gur->lbiuiplldcr1 = 0x00078080;
  110. if (clkdiv == 16) {
  111. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  112. } else if (clkdiv == 8) {
  113. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  114. } else if (clkdiv == 4) {
  115. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  116. }
  117. lbc->lcrr |= 0x00030000;
  118. asm("sync;isync;msync");
  119. }
  120. /*
  121. * Initialize SDRAM memory on the Local Bus.
  122. */
  123. void
  124. sdram_init(void)
  125. {
  126. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  127. uint idx;
  128. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  129. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  130. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  131. uint lsdmr_common;
  132. puts(" SDRAM: ");
  133. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  134. /*
  135. * Setup SDRAM Base and Option Registers
  136. */
  137. lbc->or2 = CFG_OR2_PRELIM;
  138. asm("msync");
  139. lbc->br2 = CFG_BR2_PRELIM;
  140. asm("msync");
  141. lbc->lbcr = CFG_LBC_LBCR;
  142. asm("msync");
  143. lbc->lsrt = CFG_LBC_LSRT;
  144. lbc->mrtpr = CFG_LBC_MRTPR;
  145. asm("msync");
  146. /*
  147. * MPC8568 uses "new" 15-16 style addressing.
  148. */
  149. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  150. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  151. /*
  152. * Issue PRECHARGE ALL command.
  153. */
  154. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  155. asm("sync;msync");
  156. *sdram_addr = 0xff;
  157. ppcDcbf((unsigned long) sdram_addr);
  158. udelay(100);
  159. /*
  160. * Issue 8 AUTO REFRESH commands.
  161. */
  162. for (idx = 0; idx < 8; idx++) {
  163. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  164. asm("sync;msync");
  165. *sdram_addr = 0xff;
  166. ppcDcbf((unsigned long) sdram_addr);
  167. udelay(100);
  168. }
  169. /*
  170. * Issue 8 MODE-set command.
  171. */
  172. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  173. asm("sync;msync");
  174. *sdram_addr = 0xff;
  175. ppcDcbf((unsigned long) sdram_addr);
  176. udelay(100);
  177. /*
  178. * Issue NORMAL OP command.
  179. */
  180. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  181. asm("sync;msync");
  182. *sdram_addr = 0xff;
  183. ppcDcbf((unsigned long) sdram_addr);
  184. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  185. #endif /* enable SDRAM init */
  186. }
  187. #if defined(CFG_DRAM_TEST)
  188. int
  189. testdram(void)
  190. {
  191. uint *pstart = (uint *) CFG_MEMTEST_START;
  192. uint *pend = (uint *) CFG_MEMTEST_END;
  193. uint *p;
  194. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  195. CFG_MEMTEST_START,
  196. CFG_MEMTEST_END);
  197. printf("DRAM test phase 1:\n");
  198. for (p = pstart; p < pend; p++)
  199. *p = 0xaaaaaaaa;
  200. for (p = pstart; p < pend; p++) {
  201. if (*p != 0xaaaaaaaa) {
  202. printf ("DRAM test fails at: %08x\n", (uint) p);
  203. return 1;
  204. }
  205. }
  206. printf("DRAM test phase 2:\n");
  207. for (p = pstart; p < pend; p++)
  208. *p = 0x55555555;
  209. for (p = pstart; p < pend; p++) {
  210. if (*p != 0x55555555) {
  211. printf ("DRAM test fails at: %08x\n", (uint) p);
  212. return 1;
  213. }
  214. }
  215. printf("DRAM test passed.\n");
  216. return 0;
  217. }
  218. #endif
  219. #if defined(CONFIG_PCI)
  220. #ifndef CONFIG_PCI_PNP
  221. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  222. {
  223. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  224. pci_cfgfunc_config_device,
  225. {PCI_ENET0_IOADDR,
  226. PCI_ENET0_MEMADDR,
  227. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  228. },
  229. {}
  230. };
  231. #endif
  232. static struct pci_controller hose[] = {
  233. {
  234. #ifndef CONFIG_PCI_PNP
  235. config_table: pci_mpc8568mds_config_table,
  236. #endif
  237. }
  238. };
  239. #endif /* CONFIG_PCI */
  240. /*
  241. * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
  242. */
  243. void
  244. pib_init(void)
  245. {
  246. u8 val8, orig_i2c_bus;
  247. /*
  248. * Assign PIB PMC2/3 to PCI bus
  249. */
  250. /*switch temporarily to I2C bus #2 */
  251. orig_i2c_bus = i2c_get_bus_num();
  252. i2c_set_bus_num(1);
  253. val8 = 0x00;
  254. i2c_write(0x23, 0x6, 1, &val8, 1);
  255. i2c_write(0x23, 0x7, 1, &val8, 1);
  256. val8 = 0xff;
  257. i2c_write(0x23, 0x2, 1, &val8, 1);
  258. i2c_write(0x23, 0x3, 1, &val8, 1);
  259. val8 = 0x00;
  260. i2c_write(0x26, 0x6, 1, &val8, 1);
  261. val8 = 0x34;
  262. i2c_write(0x26, 0x7, 1, &val8, 1);
  263. val8 = 0xf9;
  264. i2c_write(0x26, 0x2, 1, &val8, 1);
  265. val8 = 0xff;
  266. i2c_write(0x26, 0x3, 1, &val8, 1);
  267. val8 = 0x00;
  268. i2c_write(0x27, 0x6, 1, &val8, 1);
  269. i2c_write(0x27, 0x7, 1, &val8, 1);
  270. val8 = 0xff;
  271. i2c_write(0x27, 0x2, 1, &val8, 1);
  272. val8 = 0xef;
  273. i2c_write(0x27, 0x3, 1, &val8, 1);
  274. asm("eieio");
  275. }
  276. void
  277. pci_init_board(void)
  278. {
  279. #ifdef CONFIG_PCI
  280. pib_init();
  281. pci_mpc85xx_init(&hose);
  282. #endif
  283. }