mgcoge.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  189. *
  190. * This routine performs standard 8260 initialization sequence
  191. * and calculates the available memory size. It may be called
  192. * several times to try different SDRAM configurations on both
  193. * 60x and local buses.
  194. */
  195. static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
  196. ulong orx, volatile uchar * base)
  197. {
  198. volatile uchar c = 0xff;
  199. volatile uint *sdmr_ptr;
  200. volatile uint *orx_ptr;
  201. ulong maxsize, size;
  202. int i;
  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. sdmr_ptr = &memctl->memc_psdmr;
  210. orx_ptr = &memctl->memc_or1;
  211. *orx_ptr = orx;
  212. /*
  213. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  214. *
  215. * "At system reset, initialization software must set up the
  216. * programmable parameters in the memory controller banks registers
  217. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  218. * system software should execute the following initialization sequence
  219. * for each SDRAM device.
  220. *
  221. * 1. Issue a PRECHARGE-ALL-BANKS command
  222. * 2. Issue eight CBR REFRESH commands
  223. * 3. Issue a MODE-SET command to initialize the mode register
  224. *
  225. * The initial commands are executed by setting P/LSDMR[OP] and
  226. * accessing the SDRAM with a single-byte transaction."
  227. *
  228. * The appropriate BRx/ORx registers have already been set when we
  229. * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE.
  230. */
  231. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  232. *base = c;
  233. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  234. for (i = 0; i < 8; i++)
  235. *base = c;
  236. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  237. *(base + CONFIG_SYS_MRS_OFFS) = c; /* setting MR on address lines */
  238. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  239. *base = c;
  240. size = get_ram_size ((long *)base, maxsize);
  241. *orx_ptr = orx | ~(size - 1);
  242. return (size);
  243. }
  244. phys_size_t initdram (int board_type)
  245. {
  246. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  247. volatile memctl8260_t *memctl = &immap->im_memctl;
  248. long psize;
  249. memctl->memc_psrt = CONFIG_SYS_PSRT;
  250. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  251. #ifndef CONFIG_SYS_RAMBOOT
  252. /* 60x SDRAM setup:
  253. */
  254. psize = try_init (memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
  255. (uchar *) CONFIG_SYS_SDRAM_BASE);
  256. #endif /* CONFIG_SYS_RAMBOOT */
  257. icache_enable ();
  258. return (psize);
  259. }
  260. int checkboard(void)
  261. {
  262. puts ("Board: Keymile mgcoge");
  263. if (ethernet_present ())
  264. puts (" with PIGGY.");
  265. puts ("\n");
  266. return 0;
  267. }
  268. /*
  269. * Early board initalization.
  270. */
  271. int board_early_init_r (void)
  272. {
  273. /* setup the UPIOx */
  274. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc0);
  275. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x15);
  276. return 0;
  277. }
  278. int hush_init_var (void)
  279. {
  280. ivm_read_eeprom ();
  281. return 0;
  282. }
  283. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  284. /*
  285. * update "memory" property in the blob
  286. */
  287. void ft_blob_update (void *blob, bd_t *bd)
  288. {
  289. ulong memory_data[2] = {0};
  290. ulong *flash_data = NULL;
  291. ulong flash_reg[6] = {0};
  292. flash_info_t *info;
  293. int len;
  294. int size;
  295. int i = 0;
  296. memory_data[0] = cpu_to_be32 (bd->bi_memstart);
  297. memory_data[1] = cpu_to_be32 (bd->bi_memsize);
  298. fdt_set_node_and_value (blob, "/memory", "reg", memory_data,
  299. sizeof (memory_data));
  300. len = fdt_get_node_and_value (blob, "/localbus", "ranges",
  301. (void *)&flash_data);
  302. if (flash_data == NULL) {
  303. printf ("%s: error /localbus/ranges entry\n", __FUNCTION__);
  304. return;
  305. }
  306. /* update Flash addr, size */
  307. while ( i < (len / 4)) {
  308. switch (flash_data[i]) {
  309. case 0:
  310. info = flash_get_info(CONFIG_SYS_FLASH_BASE);
  311. flash_data[i + 1] = 0;
  312. flash_data[i + 2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE);
  313. flash_data[i + 3] = cpu_to_be32 (info->size);
  314. break;
  315. case 5:
  316. info = flash_get_info(CONFIG_SYS_FLASH_BASE_1);
  317. size = info->size;
  318. info = flash_get_info(CONFIG_SYS_FLASH_BASE_2);
  319. size += info->size;
  320. flash_data[i + 1] = 0;
  321. flash_data[i + 2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE_1);
  322. flash_data[i + 3] = cpu_to_be32 (size);
  323. break;
  324. default:
  325. break;
  326. }
  327. i += 4;
  328. }
  329. fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data,
  330. len);
  331. info = flash_get_info(CONFIG_SYS_FLASH_BASE_1);
  332. flash_reg[0] = cpu_to_be32 (5);
  333. flash_reg[2] = cpu_to_be32 (info->size);
  334. flash_reg[3] = flash_reg[0];
  335. flash_reg[4] = flash_reg[2];
  336. info = flash_get_info(CONFIG_SYS_FLASH_BASE_2);
  337. flash_reg[5] = cpu_to_be32 (info->size);
  338. fdt_set_node_and_value (blob, "/localbus/flash@5,0", "reg", flash_reg,
  339. sizeof (flash_reg));
  340. }
  341. void ft_board_setup (void *blob, bd_t *bd)
  342. {
  343. ft_cpu_setup (blob, bd);
  344. ft_blob_update (blob, bd);
  345. }
  346. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */