mgcoge.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 <net.h>
  28. #include <asm/io.h>
  29. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  30. #include <libfdt.h>
  31. #endif
  32. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  33. #include <i2c.h>
  34. #endif
  35. #include "../common/common.h"
  36. /*
  37. * I/O Port configuration table
  38. *
  39. * if conf is 1, then that port pin will be configured at boot time
  40. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  41. */
  42. const iop_conf_t iop_conf_tab[4][32] = {
  43. /* Port A */
  44. { /* conf ppar psor pdir podr pdat */
  45. /* PA31 */ { 0, 0, 0, 0, 0, 0 }, /* PA31 */
  46. /* PA30 */ { 0, 0, 0, 0, 0, 0 }, /* PA30 */
  47. /* PA29 */ { 0, 0, 0, 0, 0, 0 }, /* PA29 */
  48. /* PA28 */ { 0, 0, 0, 0, 0, 0 }, /* PA28 */
  49. /* PA27 */ { 0, 0, 0, 0, 0, 0 }, /* PA27 */
  50. /* PA26 */ { 0, 0, 0, 0, 0, 0 }, /* PA26 */
  51. /* PA25 */ { 0, 0, 0, 0, 0, 0 }, /* PA25 */
  52. /* PA24 */ { 0, 0, 0, 0, 0, 0 }, /* PA24 */
  53. /* PA23 */ { 0, 0, 0, 0, 0, 0 }, /* PA23 */
  54. /* PA22 */ { 0, 0, 0, 0, 0, 0 }, /* PA22 */
  55. /* PA21 */ { 0, 0, 0, 0, 0, 0 }, /* PA21 */
  56. /* PA20 */ { 0, 0, 0, 0, 0, 0 }, /* PA20 */
  57. /* PA19 */ { 0, 0, 0, 0, 0, 0 }, /* PA19 */
  58. /* PA18 */ { 0, 0, 0, 0, 0, 0 }, /* PA18 */
  59. /* PA17 */ { 0, 0, 0, 0, 0, 0 }, /* PA17 */
  60. /* PA16 */ { 0, 0, 0, 0, 0, 0 }, /* PA16 */
  61. /* PA15 */ { 0, 0, 0, 0, 0, 0 }, /* PA15 */
  62. /* PA14 */ { 0, 0, 0, 0, 0, 0 }, /* PA14 */
  63. /* PA13 */ { 0, 0, 0, 0, 0, 0 }, /* PA13 */
  64. /* PA12 */ { 0, 0, 0, 0, 0, 0 }, /* PA12 */
  65. /* PA11 */ { 0, 0, 0, 0, 0, 0 }, /* PA11 */
  66. /* PA10 */ { 0, 0, 0, 0, 0, 0 }, /* PA10 */
  67. /* PA9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TxD */
  68. /* PA8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC2 RxD */
  69. /* PA7 */ { 0, 0, 0, 0, 0, 0 }, /* PA7 */
  70. /* PA6 */ { 0, 0, 0, 0, 0, 0 }, /* PA6 */
  71. /* PA5 */ { 0, 0, 0, 0, 0, 0 }, /* PA5 */
  72. /* PA4 */ { 0, 0, 0, 0, 0, 0 }, /* PA4 */
  73. /* PA3 */ { 0, 0, 0, 0, 0, 0 }, /* PA3 */
  74. /* PA2 */ { 0, 0, 0, 0, 0, 0 }, /* PA2 */
  75. /* PA1 */ { 0, 0, 0, 0, 0, 0 }, /* PA1 */
  76. /* PA0 */ { 0, 0, 0, 0, 0, 0 } /* PA0 */
  77. },
  78. /* Port B */
  79. { /* conf ppar psor pdir podr pdat */
  80. /* PB31 */ { 0, 0, 0, 0, 0, 0 }, /* PB31 */
  81. /* PB30 */ { 0, 0, 0, 0, 0, 0 }, /* PB30 */
  82. /* PB29 */ { 0, 0, 0, 0, 0, 0 }, /* PB29 */
  83. /* PB28 */ { 0, 0, 0, 0, 0, 0 }, /* PB28 */
  84. /* PB27 */ { 0, 0, 0, 0, 0, 0 }, /* PB27 */
  85. /* PB26 */ { 0, 0, 0, 0, 0, 0 }, /* PB26 */
  86. /* PB25 */ { 0, 0, 0, 0, 0, 0 }, /* PB25 */
  87. /* PB24 */ { 0, 0, 0, 0, 0, 0 }, /* PB24 */
  88. /* PB23 */ { 0, 0, 0, 0, 0, 0 }, /* PB23 */
  89. /* PB22 */ { 0, 0, 0, 0, 0, 0 }, /* PB22 */
  90. /* PB21 */ { 0, 0, 0, 0, 0, 0 }, /* PB21 */
  91. /* PB20 */ { 0, 0, 0, 0, 0, 0 }, /* PB20 */
  92. /* PB19 */ { 0, 0, 0, 0, 0, 0 }, /* PB19 */
  93. /* PB18 */ { 0, 0, 0, 0, 0, 0 }, /* PB18 */
  94. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  95. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  96. /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  97. /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  98. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  99. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  100. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  101. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  102. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  103. /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  104. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  105. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  106. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  107. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  108. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  109. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  110. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  111. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  112. },
  113. /* Port C */
  114. { /* conf ppar psor pdir podr pdat */
  115. /* PC31 */ { 0, 0, 0, 0, 0, 0 }, /* PC31 */
  116. /* PC30 */ { 0, 0, 0, 0, 0, 0 }, /* PC30 */
  117. /* PC29 */ { 0, 0, 0, 0, 0, 0 }, /* PC29 */
  118. /* PC28 */ { 0, 0, 0, 0, 0, 0 }, /* PC28 */
  119. /* PC27 */ { 0, 0, 0, 0, 0, 0 }, /* PC27 */
  120. /* PC26 */ { 0, 0, 0, 0, 0, 0 }, /* PC26 */
  121. /* PC25 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 RxClk */
  122. /* PC24 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 TxClk */
  123. /* PC23 */ { 0, 0, 0, 0, 0, 0 }, /* PC23 */
  124. /* PC22 */ { 0, 0, 0, 0, 0, 0 }, /* PC22 */
  125. /* PC21 */ { 0, 0, 0, 0, 0, 0 }, /* PC21 */
  126. /* PC20 */ { 0, 0, 0, 0, 0, 0 }, /* PC20 */
  127. /* PC19 */ { 0, 0, 0, 0, 0, 0 }, /* PC19 */
  128. /* PC18 */ { 0, 0, 0, 0, 0, 0 }, /* PC18 */
  129. /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* PC17 */
  130. /* PC16 */ { 0, 0, 0, 0, 0, 0 }, /* PC16 */
  131. /* PC15 */ { 0, 0, 0, 0, 0, 0 }, /* PC15 */
  132. /* PC14 */ { 0, 0, 0, 0, 0, 0 }, /* PC14 */
  133. /* PC13 */ { 0, 0, 0, 0, 0, 0 }, /* PC13 */
  134. /* PC12 */ { 0, 0, 0, 0, 0, 0 }, /* PC12 */
  135. /* PC11 */ { 0, 0, 0, 0, 0, 0 }, /* PC11 */
  136. /* PC10 */ { 0, 0, 0, 0, 0, 0 }, /* PC10 */
  137. /* PC9 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CTS */
  138. /* PC8 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CD */
  139. /* PC7 */ { 0, 0, 0, 0, 0, 0 }, /* PC7 */
  140. /* PC6 */ { 0, 0, 0, 0, 0, 0 }, /* PC6 */
  141. /* PC5 */ { 0, 0, 0, 0, 0, 0 }, /* PC5 */
  142. /* PC4 */ { 0, 0, 0, 0, 0, 0 }, /* PC4 */
  143. /* PC3 */ { 0, 0, 0, 0, 0, 0 }, /* PC3 */
  144. /* PC2 */ { 0, 0, 0, 0, 0, 0 }, /* PC2 */
  145. /* PC1 */ { 0, 0, 0, 0, 0, 0 }, /* PC1 */
  146. /* PC0 */ { 0, 0, 0, 0, 0, 0 }, /* PC0 */
  147. },
  148. /* Port D */
  149. { /* conf ppar psor pdir podr pdat */
  150. /* PD31 */ { 0, 0, 0, 0, 0, 0 }, /* PD31 */
  151. /* PD30 */ { 0, 0, 0, 0, 0, 0 }, /* PD30 */
  152. /* PD29 */ { 0, 0, 0, 0, 0, 0 }, /* PD29 */
  153. /* PD28 */ { 0, 0, 0, 0, 0, 0 }, /* PD28 */
  154. /* PD27 */ { 0, 0, 0, 0, 0, 0 }, /* PD27 */
  155. /* PD26 */ { 0, 0, 0, 0, 0, 0 }, /* PD26 */
  156. /* PD25 */ { 0, 0, 0, 0, 0, 0 }, /* PD25 */
  157. /* PD24 */ { 0, 0, 0, 0, 0, 0 }, /* PD24 */
  158. /* PD23 */ { 0, 0, 0, 0, 0, 0 }, /* PD23 */
  159. /* PD22 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: RXD */
  160. /* PD21 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: TXD */
  161. /* PD20 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: RTS */
  162. /* PD19 */ { 0, 0, 0, 0, 0, 0 }, /* PD19 */
  163. /* PD18 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
  164. /* PD17 */ { 0, 0, 0, 0, 0, 0 }, /* PD17 */
  165. /* PD16 */ { 0, 0, 0, 0, 0, 0 }, /* PD16 */
  166. #if defined(CONFIG_HARD_I2C)
  167. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  168. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  169. #else
  170. /* PD15 */ { 1, 0, 0, 0, 1, 1 }, /* PD15 */
  171. /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* PD14 */
  172. #endif
  173. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  174. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  175. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  176. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  177. /* PD9 */ { 0, 0, 0, 0, 0, 0 }, /* PD9 */
  178. /* PD8 */ { 0, 0, 0, 0, 0, 0 }, /* PD8 */
  179. /* PD7 */ { 0, 0, 0, 0, 0, 0 }, /* PD7 */
  180. /* PD6 */ { 0, 0, 0, 0, 0, 0 }, /* PD6 */
  181. /* PD5 */ { 0, 0, 0, 0, 0, 0 }, /* PD5 */
  182. /* PD4 */ { 0, 0, 0, 0, 0, 0 }, /* PD4 */
  183. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  184. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  185. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  186. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  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 (volatile memctl8260_t * memctl, ulong sdmr,
  197. ulong orx, volatile uchar * base)
  198. {
  199. volatile uchar c = 0xff;
  200. volatile uint *sdmr_ptr;
  201. volatile uint *orx_ptr;
  202. ulong maxsize, size;
  203. int i;
  204. /* We must be able to test a location outsize the maximum legal size
  205. * to find out THAT we are outside; but this address still has to be
  206. * mapped by the controller. That means, that the initial mapping has
  207. * to be (at least) twice as large as the maximum expected size.
  208. */
  209. maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
  210. sdmr_ptr = &memctl->memc_psdmr;
  211. orx_ptr = &memctl->memc_or1;
  212. *orx_ptr = orx;
  213. /*
  214. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  215. *
  216. * "At system reset, initialization software must set up the
  217. * programmable parameters in the memory controller banks registers
  218. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  219. * system software should execute the following initialization sequence
  220. * for each SDRAM device.
  221. *
  222. * 1. Issue a PRECHARGE-ALL-BANKS command
  223. * 2. Issue eight CBR REFRESH commands
  224. * 3. Issue a MODE-SET command to initialize the mode register
  225. *
  226. * The initial commands are executed by setting P/LSDMR[OP] and
  227. * accessing the SDRAM with a single-byte transaction."
  228. *
  229. * The appropriate BRx/ORx registers have already been set when we
  230. * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE.
  231. */
  232. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  233. *base = c;
  234. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  235. for (i = 0; i < 8; i++)
  236. *base = c;
  237. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  238. *(base + CONFIG_SYS_MRS_OFFS) = c; /* setting MR on address lines */
  239. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  240. *base = c;
  241. size = get_ram_size ((long *)base, maxsize);
  242. *orx_ptr = orx | ~(size - 1);
  243. return (size);
  244. }
  245. phys_size_t initdram (int board_type)
  246. {
  247. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  248. volatile memctl8260_t *memctl = &immap->im_memctl;
  249. long psize;
  250. memctl->memc_psrt = CONFIG_SYS_PSRT;
  251. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  252. #ifndef CONFIG_SYS_RAMBOOT
  253. /* 60x SDRAM setup:
  254. */
  255. psize = try_init (memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
  256. (uchar *) CONFIG_SYS_SDRAM_BASE);
  257. #endif /* CONFIG_SYS_RAMBOOT */
  258. icache_enable ();
  259. return (psize);
  260. }
  261. int checkboard(void)
  262. {
  263. puts ("Board: Keymile mgcoge");
  264. if (ethernet_present ())
  265. puts (" with PIGGY.");
  266. puts ("\n");
  267. return 0;
  268. }
  269. /*
  270. * Early board initalization.
  271. */
  272. int board_early_init_r (void)
  273. {
  274. /* setup the UPIOx */
  275. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc0);
  276. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x15);
  277. return 0;
  278. }
  279. int hush_init_var (void)
  280. {
  281. ivm_read_eeprom ();
  282. return 0;
  283. }
  284. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  285. extern int fdt_set_node_and_value (void *blob,
  286. char *nodename,
  287. char *regname,
  288. void *var,
  289. int size);
  290. /*
  291. * update "memory" property in the blob
  292. */
  293. void ft_blob_update (void *blob, bd_t *bd)
  294. {
  295. ulong memory_data[2] = {0};
  296. ulong flash_data[8] = {0};
  297. flash_info_t *info;
  298. memory_data[0] = cpu_to_be32 (bd->bi_memstart);
  299. memory_data[1] = cpu_to_be32 (bd->bi_memsize);
  300. fdt_set_node_and_value (blob, "/memory", "reg", memory_data,
  301. sizeof (memory_data));
  302. /* update Flash addr, size */
  303. info = flash_get_info(CONFIG_SYS_FLASH_BASE);
  304. flash_data[2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE);
  305. flash_data[3] = cpu_to_be32 (info->size);
  306. flash_data[4] = cpu_to_be32 (5);
  307. flash_data[5] = cpu_to_be32 (0);
  308. info = flash_get_info(CONFIG_SYS_FLASH_BASE_1);
  309. flash_data[6] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE_1);
  310. flash_data[7] = cpu_to_be32 (info->size);
  311. fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data,
  312. sizeof (flash_data));
  313. /* MAC addr */
  314. fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address",
  315. bd->bi_enetaddr, sizeof (u8) * 6);
  316. }
  317. void ft_board_setup (void *blob, bd_t *bd)
  318. {
  319. ft_cpu_setup (blob, bd);
  320. ft_blob_update (blob, bd);
  321. }
  322. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */