mpc8568mds.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. * Copyright 2007,2009-2011 Freescale Semiconductor, Inc.
  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/mmu.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/fsl_pci.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <asm/fsl_serdes.h>
  32. #include <spd_sdram.h>
  33. #include <i2c.h>
  34. #include <ioports.h>
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #include "bcsr.h"
  38. const qe_iop_conf_t qe_iop_conf_tab[] = {
  39. /* GETH1 */
  40. {4, 10, 1, 0, 2}, /* TxD0 */
  41. {4, 9, 1, 0, 2}, /* TxD1 */
  42. {4, 8, 1, 0, 2}, /* TxD2 */
  43. {4, 7, 1, 0, 2}, /* TxD3 */
  44. {4, 23, 1, 0, 2}, /* TxD4 */
  45. {4, 22, 1, 0, 2}, /* TxD5 */
  46. {4, 21, 1, 0, 2}, /* TxD6 */
  47. {4, 20, 1, 0, 2}, /* TxD7 */
  48. {4, 15, 2, 0, 2}, /* RxD0 */
  49. {4, 14, 2, 0, 2}, /* RxD1 */
  50. {4, 13, 2, 0, 2}, /* RxD2 */
  51. {4, 12, 2, 0, 2}, /* RxD3 */
  52. {4, 29, 2, 0, 2}, /* RxD4 */
  53. {4, 28, 2, 0, 2}, /* RxD5 */
  54. {4, 27, 2, 0, 2}, /* RxD6 */
  55. {4, 26, 2, 0, 2}, /* RxD7 */
  56. {4, 11, 1, 0, 2}, /* TX_EN */
  57. {4, 24, 1, 0, 2}, /* TX_ER */
  58. {4, 16, 2, 0, 2}, /* RX_DV */
  59. {4, 30, 2, 0, 2}, /* RX_ER */
  60. {4, 17, 2, 0, 2}, /* RX_CLK */
  61. {4, 19, 1, 0, 2}, /* GTX_CLK */
  62. {1, 31, 2, 0, 3}, /* GTX125 */
  63. /* GETH2 */
  64. {5, 10, 1, 0, 2}, /* TxD0 */
  65. {5, 9, 1, 0, 2}, /* TxD1 */
  66. {5, 8, 1, 0, 2}, /* TxD2 */
  67. {5, 7, 1, 0, 2}, /* TxD3 */
  68. {5, 23, 1, 0, 2}, /* TxD4 */
  69. {5, 22, 1, 0, 2}, /* TxD5 */
  70. {5, 21, 1, 0, 2}, /* TxD6 */
  71. {5, 20, 1, 0, 2}, /* TxD7 */
  72. {5, 15, 2, 0, 2}, /* RxD0 */
  73. {5, 14, 2, 0, 2}, /* RxD1 */
  74. {5, 13, 2, 0, 2}, /* RxD2 */
  75. {5, 12, 2, 0, 2}, /* RxD3 */
  76. {5, 29, 2, 0, 2}, /* RxD4 */
  77. {5, 28, 2, 0, 2}, /* RxD5 */
  78. {5, 27, 2, 0, 3}, /* RxD6 */
  79. {5, 26, 2, 0, 2}, /* RxD7 */
  80. {5, 11, 1, 0, 2}, /* TX_EN */
  81. {5, 24, 1, 0, 2}, /* TX_ER */
  82. {5, 16, 2, 0, 2}, /* RX_DV */
  83. {5, 30, 2, 0, 2}, /* RX_ER */
  84. {5, 17, 2, 0, 2}, /* RX_CLK */
  85. {5, 19, 1, 0, 2}, /* GTX_CLK */
  86. {1, 31, 2, 0, 3}, /* GTX125 */
  87. {4, 6, 3, 0, 2}, /* MDIO */
  88. {4, 5, 1, 0, 2}, /* MDC */
  89. /* UART1 */
  90. {2, 0, 1, 0, 2}, /* UART_SOUT1 */
  91. {2, 1, 1, 0, 2}, /* UART_RTS1 */
  92. {2, 2, 2, 0, 2}, /* UART_CTS1 */
  93. {2, 3, 2, 0, 2}, /* UART_SIN1 */
  94. {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
  95. };
  96. void local_bus_init(void);
  97. int board_early_init_f (void)
  98. {
  99. /*
  100. * Initialize local bus.
  101. */
  102. local_bus_init ();
  103. enable_8568mds_duart();
  104. enable_8568mds_flash_write();
  105. #if defined(CONFIG_UEC_ETH1) || defined(CONFIG_UEC_ETH2)
  106. reset_8568mds_uccs();
  107. #endif
  108. #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS)
  109. enable_8568mds_qe_mdio();
  110. #endif
  111. #ifdef CONFIG_SYS_I2C2_OFFSET
  112. /* Enable I2C2_SCL and I2C2_SDA */
  113. volatile struct par_io *port_c;
  114. port_c = (struct par_io*)(CONFIG_SYS_IMMR + 0xe0140);
  115. port_c->cpdir2 |= 0x0f000000;
  116. port_c->cppar2 &= ~0x0f000000;
  117. port_c->cppar2 |= 0x0a000000;
  118. #endif
  119. return 0;
  120. }
  121. int checkboard (void)
  122. {
  123. printf ("Board: 8568 MDS\n");
  124. return 0;
  125. }
  126. /*
  127. * Initialize Local Bus
  128. */
  129. void
  130. local_bus_init(void)
  131. {
  132. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  133. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  134. uint clkdiv;
  135. uint lbc_hz;
  136. sys_info_t sysinfo;
  137. get_sys_info(&sysinfo);
  138. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  139. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  140. gur->lbiuiplldcr1 = 0x00078080;
  141. if (clkdiv == 16) {
  142. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  143. } else if (clkdiv == 8) {
  144. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  145. } else if (clkdiv == 4) {
  146. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  147. }
  148. lbc->lcrr |= 0x00030000;
  149. asm("sync;isync;msync");
  150. }
  151. /*
  152. * Initialize SDRAM memory on the Local Bus.
  153. */
  154. void lbc_sdram_init(void)
  155. {
  156. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  157. uint idx;
  158. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  159. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  160. uint lsdmr_common;
  161. puts("LBC SDRAM: ");
  162. print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
  163. "\n ");
  164. /*
  165. * Setup SDRAM Base and Option Registers
  166. */
  167. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  168. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  169. asm("msync");
  170. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  171. asm("msync");
  172. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  173. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  174. asm("msync");
  175. /*
  176. * MPC8568 uses "new" 15-16 style addressing.
  177. */
  178. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  179. lsdmr_common |= LSDMR_BSMA1516;
  180. /*
  181. * Issue PRECHARGE ALL command.
  182. */
  183. lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
  184. asm("sync;msync");
  185. *sdram_addr = 0xff;
  186. ppcDcbf((unsigned long) sdram_addr);
  187. udelay(100);
  188. /*
  189. * Issue 8 AUTO REFRESH commands.
  190. */
  191. for (idx = 0; idx < 8; idx++) {
  192. lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
  193. asm("sync;msync");
  194. *sdram_addr = 0xff;
  195. ppcDcbf((unsigned long) sdram_addr);
  196. udelay(100);
  197. }
  198. /*
  199. * Issue 8 MODE-set command.
  200. */
  201. lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
  202. asm("sync;msync");
  203. *sdram_addr = 0xff;
  204. ppcDcbf((unsigned long) sdram_addr);
  205. udelay(100);
  206. /*
  207. * Issue NORMAL OP command.
  208. */
  209. lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
  210. asm("sync;msync");
  211. *sdram_addr = 0xff;
  212. ppcDcbf((unsigned long) sdram_addr);
  213. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  214. #endif /* enable SDRAM init */
  215. }
  216. #if defined(CONFIG_PCI)
  217. #ifndef CONFIG_PCI_PNP
  218. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  219. {
  220. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  221. pci_cfgfunc_config_device,
  222. {PCI_ENET0_IOADDR,
  223. PCI_ENET0_MEMADDR,
  224. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  225. },
  226. {}
  227. };
  228. #endif
  229. static struct pci_controller pci1_hose;
  230. #endif /* CONFIG_PCI */
  231. /*
  232. * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
  233. */
  234. void
  235. pib_init(void)
  236. {
  237. u8 val8, orig_i2c_bus;
  238. /*
  239. * Assign PIB PMC2/3 to PCI bus
  240. */
  241. /*switch temporarily to I2C bus #2 */
  242. orig_i2c_bus = i2c_get_bus_num();
  243. i2c_set_bus_num(1);
  244. val8 = 0x00;
  245. i2c_write(0x23, 0x6, 1, &val8, 1);
  246. i2c_write(0x23, 0x7, 1, &val8, 1);
  247. val8 = 0xff;
  248. i2c_write(0x23, 0x2, 1, &val8, 1);
  249. i2c_write(0x23, 0x3, 1, &val8, 1);
  250. val8 = 0x00;
  251. i2c_write(0x26, 0x6, 1, &val8, 1);
  252. val8 = 0x34;
  253. i2c_write(0x26, 0x7, 1, &val8, 1);
  254. val8 = 0xf9;
  255. i2c_write(0x26, 0x2, 1, &val8, 1);
  256. val8 = 0xff;
  257. i2c_write(0x26, 0x3, 1, &val8, 1);
  258. val8 = 0x00;
  259. i2c_write(0x27, 0x6, 1, &val8, 1);
  260. i2c_write(0x27, 0x7, 1, &val8, 1);
  261. val8 = 0xff;
  262. i2c_write(0x27, 0x2, 1, &val8, 1);
  263. val8 = 0xef;
  264. i2c_write(0x27, 0x3, 1, &val8, 1);
  265. asm("eieio");
  266. }
  267. #ifdef CONFIG_PCI
  268. void pci_init_board(void)
  269. {
  270. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  271. int first_free_busno = 0;
  272. #ifdef CONFIG_PCI1
  273. struct fsl_pci_info pci_info;
  274. u32 devdisr, pordevsr, io_sel;
  275. u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
  276. devdisr = in_be32(&gur->devdisr);
  277. pordevsr = in_be32(&gur->pordevsr);
  278. porpllsr = in_be32(&gur->porpllsr);
  279. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  280. debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  281. pci_speed = 66666000;
  282. pci_32 = 1;
  283. pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  284. pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  285. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  286. SET_STD_PCI_INFO(pci_info, 1);
  287. set_next_law(pci_info.mem_phys,
  288. law_size_bits(pci_info.mem_size), pci_info.law);
  289. set_next_law(pci_info.io_phys,
  290. law_size_bits(pci_info.io_size), pci_info.law);
  291. pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
  292. printf("PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
  293. (pci_32) ? 32 : 64,
  294. (pci_speed == 33333000) ? "33" :
  295. (pci_speed == 66666000) ? "66" : "unknown",
  296. pci_clk_sel ? "sync" : "async",
  297. pci_agent ? "agent" : "host",
  298. pci_arb ? "arbiter" : "external-arbiter",
  299. pci_info.regs);
  300. #ifndef CONFIG_PCI_PNP
  301. pci1_hose.config_table = pci_mpc8568mds_config_table;
  302. #endif
  303. first_free_busno = fsl_pci_init_port(&pci_info,
  304. &pci1_hose, first_free_busno);
  305. } else {
  306. printf("PCI: disabled\n");
  307. }
  308. puts("\n");
  309. #else
  310. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  311. #endif
  312. fsl_pcie_init_board(first_free_busno);
  313. }
  314. #endif /* CONFIG_PCI */
  315. #if defined(CONFIG_OF_BOARD_SETUP)
  316. void ft_board_setup(void *blob, bd_t *bd)
  317. {
  318. ft_cpu_setup(blob, bd);
  319. FT_FSL_PCI_SETUP;
  320. }
  321. #endif