km83xx.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Copyright (C) 2006 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * Copyright (C) 2007 Logic Product Development, Inc.
  6. * Peter Barada <peterb@logicpd.com>
  7. *
  8. * Copyright (C) 2007 MontaVista Software, Inc.
  9. * Anton Vorontsov <avorontsov@ru.mvista.com>
  10. *
  11. * (C) Copyright 2008 - 2010
  12. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. */
  19. #include <common.h>
  20. #include <ioports.h>
  21. #include <mpc83xx.h>
  22. #include <i2c.h>
  23. #include <miiphy.h>
  24. #include <asm/io.h>
  25. #include <asm/mmu.h>
  26. #include <asm/processor.h>
  27. #include <pci.h>
  28. #include <libfdt.h>
  29. #include "../common/common.h"
  30. const qe_iop_conf_t qe_iop_conf_tab[] = {
  31. /* port pin dir open_drain assign */
  32. #if defined(CONFIG_KMETER1)
  33. /* MDIO */
  34. {0, 1, 3, 0, 2}, /* MDIO */
  35. {0, 2, 1, 0, 1}, /* MDC */
  36. /* UCC4 - UEC */
  37. {1, 14, 1, 0, 1}, /* TxD0 */
  38. {1, 15, 1, 0, 1}, /* TxD1 */
  39. {1, 20, 2, 0, 1}, /* RxD0 */
  40. {1, 21, 2, 0, 1}, /* RxD1 */
  41. {1, 18, 1, 0, 1}, /* TX_EN */
  42. {1, 26, 2, 0, 1}, /* RX_DV */
  43. {1, 27, 2, 0, 1}, /* RX_ER */
  44. {1, 24, 2, 0, 1}, /* COL */
  45. {1, 25, 2, 0, 1}, /* CRS */
  46. {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */
  47. {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */
  48. /* DUART - UART2 */
  49. {5, 0, 1, 0, 2}, /* UART2_SOUT */
  50. {5, 2, 1, 0, 1}, /* UART2_RTS */
  51. {5, 3, 2, 0, 2}, /* UART2_SIN */
  52. {5, 1, 2, 0, 3}, /* UART2_CTS */
  53. #else
  54. /* Local Bus */
  55. {0, 16, 1, 0, 3}, /* LA00 */
  56. {0, 17, 1, 0, 3}, /* LA01 */
  57. {0, 18, 1, 0, 3}, /* LA02 */
  58. {0, 19, 1, 0, 3}, /* LA03 */
  59. {0, 20, 1, 0, 3}, /* LA04 */
  60. {0, 21, 1, 0, 3}, /* LA05 */
  61. {0, 22, 1, 0, 3}, /* LA06 */
  62. {0, 23, 1, 0, 3}, /* LA07 */
  63. {0, 24, 1, 0, 3}, /* LA08 */
  64. {0, 25, 1, 0, 3}, /* LA09 */
  65. {0, 26, 1, 0, 3}, /* LA10 */
  66. {0, 27, 1, 0, 3}, /* LA11 */
  67. {0, 28, 1, 0, 3}, /* LA12 */
  68. {0, 29, 1, 0, 3}, /* LA13 */
  69. {0, 30, 1, 0, 3}, /* LA14 */
  70. {0, 31, 1, 0, 3}, /* LA15 */
  71. /* MDIO */
  72. {3, 4, 3, 0, 2}, /* MDIO */
  73. {3, 5, 1, 0, 2}, /* MDC */
  74. /* UCC4 - UEC */
  75. {1, 18, 1, 0, 1}, /* TxD0 */
  76. {1, 19, 1, 0, 1}, /* TxD1 */
  77. {1, 22, 2, 0, 1}, /* RxD0 */
  78. {1, 23, 2, 0, 1}, /* RxD1 */
  79. {1, 26, 2, 0, 1}, /* RxER */
  80. {1, 28, 2, 0, 1}, /* Rx_DV */
  81. {1, 30, 1, 0, 1}, /* TxEN */
  82. {1, 31, 2, 0, 1}, /* CRS */
  83. {3, 10, 2, 0, 3}, /* TxCLK->CLK17 */
  84. #endif
  85. /* END of table */
  86. {0, 0, 0, 0, QE_IOP_TAB_END},
  87. };
  88. static int board_init_i2c_busses(void)
  89. {
  90. I2C_MUX_DEVICE *dev = NULL;
  91. uchar *buf;
  92. /* Set up the Bus for the DTTs */
  93. buf = (unsigned char *) getenv("dtt_bus");
  94. if (buf != NULL)
  95. dev = i2c_mux_ident_muxstring(buf);
  96. if (dev == NULL) {
  97. printf("Error couldn't add Bus for DTT\n");
  98. printf("please setup dtt_bus to where your\n");
  99. printf("DTT is found.\n");
  100. }
  101. return 0;
  102. }
  103. #if defined(CONFIG_SUVD3)
  104. const uint upma_table[] = {
  105. 0x1ffedc00, 0x0ffcdc80, 0x0ffcdc80, 0x0ffcdc04, /* Words 0 to 3 */
  106. 0x0ffcdc00, 0xffffcc00, 0xffffcc01, 0xfffffc01, /* Words 4 to 7 */
  107. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 8 to 11 */
  108. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 12 to 15 */
  109. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 16 to 19 */
  110. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 20 to 23 */
  111. 0x9cfffc00, 0x00fffc80, 0x00fffc80, 0x00fffc00, /* Words 24 to 27 */
  112. 0xffffec04, 0xffffec01, 0xfffffc01, 0xfffffc01, /* Words 28 to 31 */
  113. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 32 to 35 */
  114. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 36 to 39 */
  115. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 40 to 43 */
  116. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 44 to 47 */
  117. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 48 to 51 */
  118. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 52 to 55 */
  119. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 56 to 59 */
  120. 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01 /* Words 60 to 63 */
  121. };
  122. #endif
  123. int board_early_init_r(void)
  124. {
  125. struct km_bec_fpga *base =
  126. (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
  127. #if defined(CONFIG_SUVD3)
  128. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  129. fsl_lbc_t *lbc = &immap->im_lbc;
  130. u32 *mxmr = &lbc->mamr;
  131. #endif
  132. #if defined(CONFIG_MPC8360)
  133. unsigned short svid;
  134. /*
  135. * Because of errata in the UCCs, we have to write to the reserved
  136. * registers to slow the clocks down.
  137. */
  138. svid = SVR_REV(mfspr(SVR));
  139. switch (svid) {
  140. case 0x0020:
  141. /*
  142. * MPC8360ECE.pdf QE_ENET10 table 4:
  143. * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
  144. * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
  145. */
  146. setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000);
  147. break;
  148. case 0x0021:
  149. /*
  150. * MPC8360ECE.pdf QE_ENET10 table 4:
  151. * IMMR + 0x14AC[24:27] = 1010
  152. */
  153. clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac),
  154. 0x00000050, 0x000000a0);
  155. break;
  156. }
  157. #endif
  158. /* enable the PHY on the PIGGY */
  159. setbits_8(&base->pgy_eth, 0x01);
  160. /* enable the Unit LED (green) */
  161. setbits_8(&base->oprth, WRL_BOOT);
  162. #if defined(CONFIG_SUVD3)
  163. /* configure UPMA for APP1 */
  164. upmconfig(UPMA, (uint *) upma_table,
  165. sizeof(upma_table) / sizeof(uint));
  166. out_be32(mxmr, CONFIG_SYS_MAMR);
  167. #endif
  168. return 0;
  169. }
  170. int misc_init_r(void)
  171. {
  172. /* add board specific i2c busses */
  173. board_init_i2c_busses();
  174. return 0;
  175. }
  176. int last_stage_init(void)
  177. {
  178. set_km_env();
  179. return 0;
  180. }
  181. int fixed_sdram(void)
  182. {
  183. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  184. u32 msize = 0;
  185. u32 ddr_size;
  186. u32 ddr_size_log2;
  187. out_be32(&im->sysconf.ddrlaw[0].ar, (LAWAR_EN | 0x1e));
  188. out_be32(&im->ddr.csbnds[0].csbnds, CONFIG_SYS_DDR_CS0_BNDS);
  189. out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
  190. out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  191. out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  192. out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  193. out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  194. out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
  195. out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
  196. out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
  197. out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
  198. out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
  199. out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
  200. udelay(200);
  201. out_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
  202. msize = CONFIG_SYS_DDR_SIZE << 20;
  203. disable_addr_trans();
  204. msize = get_ram_size(CONFIG_SYS_DDR_BASE, msize);
  205. enable_addr_trans();
  206. msize /= (1024 * 1024);
  207. if (CONFIG_SYS_DDR_SIZE != msize) {
  208. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  209. (ddr_size > 1);
  210. ddr_size = ddr_size >> 1, ddr_size_log2++)
  211. if (ddr_size & 1)
  212. return -1;
  213. out_be32(&im->sysconf.ddrlaw[0].ar,
  214. (LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE)));
  215. out_be32(&im->ddr.csbnds[0].csbnds,
  216. (((msize / 16) - 1) & 0xff));
  217. }
  218. return msize;
  219. }
  220. phys_size_t initdram(int board_type)
  221. {
  222. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  223. u32 msize = 0;
  224. if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
  225. return -1;
  226. out_be32(&im->sysconf.ddrlaw[0].bar,
  227. CONFIG_SYS_DDR_BASE & LAWBAR_BAR);
  228. msize = fixed_sdram();
  229. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  230. /*
  231. * Initialize DDR ECC byte
  232. */
  233. ddr_enable_ecc(msize * 1024 * 1024);
  234. #endif
  235. /* return total bus SDRAM size(bytes) -- DDR */
  236. return msize * 1024 * 1024;
  237. }
  238. int checkboard(void)
  239. {
  240. puts("Board: Keymile " CONFIG_KM_BOARD_NAME);
  241. if (ethernet_present())
  242. puts(" with PIGGY.");
  243. puts("\n");
  244. return 0;
  245. }
  246. #if defined(CONFIG_OF_BOARD_SETUP)
  247. void ft_board_setup(void *blob, bd_t *bd)
  248. {
  249. ft_cpu_setup(blob, bd);
  250. }
  251. #endif
  252. #if defined(CONFIG_HUSH_INIT_VAR)
  253. int hush_init_var(void)
  254. {
  255. ivm_read_eeprom();
  256. return 0;
  257. }
  258. #endif