mgcoge.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * (C) Copyright 2007 - 2008
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc8260.h>
  25. #include <ioports.h>
  26. #include <malloc.h>
  27. #include <asm/io.h>
  28. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  29. #include <libfdt.h>
  30. #endif
  31. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  32. #include <i2c.h>
  33. #endif
  34. #include "../common/common.h"
  35. /*
  36. * I/O Port configuration table
  37. *
  38. * if conf is 1, then that port pin will be configured at boot time
  39. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  40. */
  41. const iop_conf_t iop_conf_tab[4][32] = {
  42. /* Port A */
  43. { /* conf ppar psor pdir podr pdat */
  44. /* PA31 */ { 0, 0, 0, 0, 0, 0 }, /* PA31 */
  45. /* PA30 */ { 0, 0, 0, 0, 0, 0 }, /* PA30 */
  46. /* PA29 */ { 0, 0, 0, 0, 0, 0 }, /* PA29 */
  47. /* PA28 */ { 0, 0, 0, 0, 0, 0 }, /* PA28 */
  48. /* PA27 */ { 0, 0, 0, 0, 0, 0 }, /* PA27 */
  49. /* PA26 */ { 0, 0, 0, 0, 0, 0 }, /* PA26 */
  50. /* PA25 */ { 0, 0, 0, 0, 0, 0 }, /* PA25 */
  51. /* PA24 */ { 0, 0, 0, 0, 0, 0 }, /* PA24 */
  52. /* PA23 */ { 0, 0, 0, 0, 0, 0 }, /* PA23 */
  53. /* PA22 */ { 0, 0, 0, 0, 0, 0 }, /* PA22 */
  54. /* PA21 */ { 0, 0, 0, 0, 0, 0 }, /* PA21 */
  55. /* PA20 */ { 0, 0, 0, 0, 0, 0 }, /* PA20 */
  56. /* PA19 */ { 0, 0, 0, 0, 0, 0 }, /* PA19 */
  57. /* PA18 */ { 0, 0, 0, 0, 0, 0 }, /* PA18 */
  58. /* PA17 */ { 0, 0, 0, 0, 0, 0 }, /* PA17 */
  59. /* PA16 */ { 0, 0, 0, 0, 0, 0 }, /* PA16 */
  60. /* PA15 */ { 0, 0, 0, 0, 0, 0 }, /* PA15 */
  61. /* PA14 */ { 0, 0, 0, 0, 0, 0 }, /* PA14 */
  62. /* PA13 */ { 0, 0, 0, 0, 0, 0 }, /* PA13 */
  63. /* PA12 */ { 0, 0, 0, 0, 0, 0 }, /* PA12 */
  64. /* PA11 */ { 0, 0, 0, 0, 0, 0 }, /* PA11 */
  65. /* PA10 */ { 0, 0, 0, 0, 0, 0 }, /* PA10 */
  66. /* PA9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TxD */
  67. /* PA8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC2 RxD */
  68. /* PA7 */ { 0, 0, 0, 0, 0, 0 }, /* PA7 */
  69. /* PA6 */ { 0, 0, 0, 0, 0, 0 }, /* PA6 */
  70. /* PA5 */ { 0, 0, 0, 0, 0, 0 }, /* PA5 */
  71. /* PA4 */ { 0, 0, 0, 0, 0, 0 }, /* PA4 */
  72. /* PA3 */ { 0, 0, 0, 0, 0, 0 }, /* PA3 */
  73. /* PA2 */ { 0, 0, 0, 0, 0, 0 }, /* PA2 */
  74. /* PA1 */ { 0, 0, 0, 0, 0, 0 }, /* PA1 */
  75. /* PA0 */ { 0, 0, 0, 0, 0, 0 } /* PA0 */
  76. },
  77. /* Port B */
  78. { /* conf ppar psor pdir podr pdat */
  79. /* PB31 */ { 0, 0, 0, 0, 0, 0 }, /* PB31 */
  80. /* PB30 */ { 0, 0, 0, 0, 0, 0 }, /* PB30 */
  81. /* PB29 */ { 0, 0, 0, 0, 0, 0 }, /* PB29 */
  82. /* PB28 */ { 0, 0, 0, 0, 0, 0 }, /* PB28 */
  83. /* PB27 */ { 0, 0, 0, 0, 0, 0 }, /* PB27 */
  84. /* PB26 */ { 0, 0, 0, 0, 0, 0 }, /* PB26 */
  85. /* PB25 */ { 0, 0, 0, 0, 0, 0 }, /* PB25 */
  86. /* PB24 */ { 0, 0, 0, 0, 0, 0 }, /* PB24 */
  87. /* PB23 */ { 0, 0, 0, 0, 0, 0 }, /* PB23 */
  88. /* PB22 */ { 0, 0, 0, 0, 0, 0 }, /* PB22 */
  89. /* PB21 */ { 0, 0, 0, 0, 0, 0 }, /* PB21 */
  90. /* PB20 */ { 0, 0, 0, 0, 0, 0 }, /* PB20 */
  91. /* PB19 */ { 0, 0, 0, 0, 0, 0 }, /* PB19 */
  92. /* PB18 */ { 0, 0, 0, 0, 0, 0 }, /* PB18 */
  93. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  94. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  95. /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  96. /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  97. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  98. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  99. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  100. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  101. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  102. /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  103. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  104. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  105. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  106. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  107. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  108. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  109. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  110. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  111. },
  112. /* Port C */
  113. { /* conf ppar psor pdir podr pdat */
  114. /* PC31 */ { 0, 0, 0, 0, 0, 0 }, /* PC31 */
  115. /* PC30 */ { 0, 0, 0, 0, 0, 0 }, /* PC30 */
  116. /* PC29 */ { 0, 0, 0, 0, 0, 0 }, /* PC29 */
  117. /* PC28 */ { 0, 0, 0, 0, 0, 0 }, /* PC28 */
  118. /* PC27 */ { 0, 0, 0, 0, 0, 0 }, /* PC27 */
  119. /* PC26 */ { 0, 0, 0, 0, 0, 0 }, /* PC26 */
  120. /* PC25 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 RxClk */
  121. /* PC24 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 TxClk */
  122. /* PC23 */ { 0, 0, 0, 0, 0, 0 }, /* PC23 */
  123. /* PC22 */ { 0, 0, 0, 0, 0, 0 }, /* PC22 */
  124. /* PC21 */ { 0, 0, 0, 0, 0, 0 }, /* PC21 */
  125. /* PC20 */ { 0, 0, 0, 0, 0, 0 }, /* PC20 */
  126. /* PC19 */ { 0, 0, 0, 0, 0, 0 }, /* PC19 */
  127. /* PC18 */ { 0, 0, 0, 0, 0, 0 }, /* PC18 */
  128. /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* PC17 */
  129. /* PC16 */ { 0, 0, 0, 0, 0, 0 }, /* PC16 */
  130. /* PC15 */ { 0, 0, 0, 0, 0, 0 }, /* PC15 */
  131. /* PC14 */ { 0, 0, 0, 0, 0, 0 }, /* PC14 */
  132. /* PC13 */ { 0, 0, 0, 0, 0, 0 }, /* PC13 */
  133. /* PC12 */ { 0, 0, 0, 0, 0, 0 }, /* PC12 */
  134. /* PC11 */ { 0, 0, 0, 0, 0, 0 }, /* PC11 */
  135. /* PC10 */ { 0, 0, 0, 0, 0, 0 }, /* PC10 */
  136. /* PC9 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CTS */
  137. /* PC8 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CD */
  138. /* PC7 */ { 0, 0, 0, 0, 0, 0 }, /* PC7 */
  139. /* PC6 */ { 0, 0, 0, 0, 0, 0 }, /* PC6 */
  140. /* PC5 */ { 0, 0, 0, 0, 0, 0 }, /* PC5 */
  141. /* PC4 */ { 0, 0, 0, 0, 0, 0 }, /* PC4 */
  142. /* PC3 */ { 0, 0, 0, 0, 0, 0 }, /* PC3 */
  143. /* PC2 */ { 0, 0, 0, 0, 0, 0 }, /* PC2 */
  144. /* PC1 */ { 0, 0, 0, 0, 0, 0 }, /* PC1 */
  145. /* PC0 */ { 0, 0, 0, 0, 0, 0 }, /* PC0 */
  146. },
  147. /* Port D */
  148. { /* conf ppar psor pdir podr pdat */
  149. /* PD31 */ { 0, 0, 0, 0, 0, 0 }, /* PD31 */
  150. /* PD30 */ { 0, 0, 0, 0, 0, 0 }, /* PD30 */
  151. /* PD29 */ { 0, 0, 0, 0, 0, 0 }, /* PD29 */
  152. /* PD28 */ { 0, 0, 0, 0, 0, 0 }, /* PD28 */
  153. /* PD27 */ { 0, 0, 0, 0, 0, 0 }, /* PD27 */
  154. /* PD26 */ { 0, 0, 0, 0, 0, 0 }, /* PD26 */
  155. /* PD25 */ { 0, 0, 0, 0, 0, 0 }, /* PD25 */
  156. /* PD24 */ { 0, 0, 0, 0, 0, 0 }, /* PD24 */
  157. /* PD23 */ { 0, 0, 0, 0, 0, 0 }, /* PD23 */
  158. /* PD22 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: RXD */
  159. /* PD21 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: TXD */
  160. /* PD20 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: RTS */
  161. /* PD19 */ { 0, 0, 0, 0, 0, 0 }, /* PD19 */
  162. /* PD18 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
  163. /* PD17 */ { 0, 0, 0, 0, 0, 0 }, /* PD17 */
  164. /* PD16 */ { 0, 0, 0, 0, 0, 0 }, /* PD16 */
  165. #if defined(CONFIG_HARD_I2C)
  166. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  167. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  168. #else
  169. /* PD15 */ { 1, 0, 0, 0, 1, 1 }, /* PD15 */
  170. /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* PD14 */
  171. #endif
  172. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  173. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  174. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  175. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  176. /* PD9 */ { 0, 0, 0, 0, 0, 0 }, /* PD9 */
  177. /* PD8 */ { 0, 0, 0, 0, 0, 0 }, /* PD8 */
  178. /* PD7 */ { 0, 0, 0, 0, 0, 0 }, /* PD7 */
  179. /* PD6 */ { 0, 0, 0, 0, 0, 0 }, /* PD6 */
  180. /* PD5 */ { 0, 0, 0, 0, 0, 0 }, /* PD5 */
  181. /* PD4 */ { 0, 0, 0, 0, 0, 0 }, /* PD4 */
  182. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  183. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  184. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  185. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  186. }
  187. };
  188. /*
  189. * Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  190. *
  191. * This routine performs standard 8260 initialization sequence
  192. * and calculates the available memory size. It may be called
  193. * several times to try different SDRAM configurations on both
  194. * 60x and local buses.
  195. */
  196. static long int try_init(memctl8260_t *memctl, ulong sdmr,
  197. ulong orx, uchar *base)
  198. {
  199. uchar c = 0xff;
  200. ulong maxsize, size;
  201. int i;
  202. /*
  203. * We must be able to test a location outsize the maximum legal size
  204. * to find out THAT we are outside; but this address still has to be
  205. * mapped by the controller. That means, that the initial mapping has
  206. * to be (at least) twice as large as the maximum expected size.
  207. */
  208. maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
  209. out_be32(&memctl->memc_or1, orx);
  210. /*
  211. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  212. *
  213. * "At system reset, initialization software must set up the
  214. * programmable parameters in the memory controller banks registers
  215. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  216. * system software should execute the following initialization sequence
  217. * for each SDRAM device.
  218. *
  219. * 1. Issue a PRECHARGE-ALL-BANKS command
  220. * 2. Issue eight CBR REFRESH commands
  221. * 3. Issue a MODE-SET command to initialize the mode register
  222. *
  223. * The initial commands are executed by setting P/LSDMR[OP] and
  224. * accessing the SDRAM with a single-byte transaction."
  225. *
  226. * The appropriate BRx/ORx registers have already been set when we
  227. * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE.
  228. */
  229. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA);
  230. out_8(base, c);
  231. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR);
  232. for (i = 0; i < 8; i++)
  233. out_8(base, c);
  234. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW);
  235. /* setting MR on address lines */
  236. out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c);
  237. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN);
  238. out_8(base, c);
  239. size = get_ram_size((long *)base, maxsize);
  240. out_be32(&memctl->memc_or1, orx | ~(size - 1));
  241. return (size);
  242. }
  243. phys_size_t initdram(int board_type)
  244. {
  245. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  246. memctl8260_t *memctl = &immap->im_memctl;
  247. long psize;
  248. out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT);
  249. out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
  250. #ifndef CONFIG_SYS_RAMBOOT
  251. /* 60x SDRAM setup:
  252. */
  253. psize = try_init(memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
  254. (uchar *) CONFIG_SYS_SDRAM_BASE);
  255. #endif /* CONFIG_SYS_RAMBOOT */
  256. icache_enable();
  257. return (psize);
  258. }
  259. int checkboard(void)
  260. {
  261. #if defined(CONFIG_MGCOGE)
  262. puts("Board: Keymile mgcoge");
  263. #else
  264. puts("Board: Keymile mgcoge2ne");
  265. #endif
  266. if (ethernet_present())
  267. puts(" with PIGGY.");
  268. puts("\n");
  269. return 0;
  270. }
  271. #define DIPSWITCH_OFFSET 0x89
  272. #define DIPSWITCH_MASK 0x0f
  273. int last_stage_init(void)
  274. {
  275. u8 dip_switch;
  276. /* Dip switch */
  277. dip_switch = readb(CONFIG_SYS_BFTICU_BASE + DIPSWITCH_OFFSET);
  278. dip_switch &= DIPSWITCH_MASK;
  279. /* dip switch 'full reset' or 'db erase' */
  280. if (dip_switch & 0x1 || dip_switch & 0x2) {
  281. /* start bootloader */
  282. puts("DIP: Enabled\n");
  283. setenv("actual_bank", "0");
  284. }
  285. return 0;
  286. }
  287. /*
  288. * Early board initalization.
  289. */
  290. int board_early_init_r(void)
  291. {
  292. struct km_bec_fpga *base = (struct km_bec_fpga *)CONFIG_SYS_PIGGY_BASE;
  293. /* setup the UPIOx */
  294. /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */
  295. out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED));
  296. /* SCC4 enable, halfduplex, FCC1 powerdown */
  297. out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA |
  298. H_OPORTS_FCC1_PW_DWN));
  299. return 0;
  300. }
  301. int hush_init_var(void)
  302. {
  303. ivm_read_eeprom();
  304. return 0;
  305. }
  306. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  307. void ft_board_setup(void *blob, bd_t *bd)
  308. {
  309. ft_cpu_setup(blob, bd);
  310. }
  311. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */