mpc8568mds.c 7.9 KB

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