mgcoge.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  28. #include <libfdt.h>
  29. #endif
  30. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  31. #include <i2c.h>
  32. #endif
  33. /*
  34. * I/O Port configuration table
  35. *
  36. * if conf is 1, then that port pin will be configured at boot time
  37. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  38. */
  39. const iop_conf_t iop_conf_tab[4][32] = {
  40. /* Port A */
  41. { /* conf ppar psor pdir podr pdat */
  42. /* PA31 */ { 0, 0, 0, 0, 0, 0 }, /* PA31 */
  43. /* PA30 */ { 0, 0, 0, 0, 0, 0 }, /* PA30 */
  44. /* PA29 */ { 0, 0, 0, 0, 0, 0 }, /* PA29 */
  45. /* PA28 */ { 0, 0, 0, 0, 0, 0 }, /* PA28 */
  46. /* PA27 */ { 0, 0, 0, 0, 0, 0 }, /* PA27 */
  47. /* PA26 */ { 0, 0, 0, 0, 0, 0 }, /* PA26 */
  48. /* PA25 */ { 0, 0, 0, 0, 0, 0 }, /* PA25 */
  49. /* PA24 */ { 0, 0, 0, 0, 0, 0 }, /* PA24 */
  50. /* PA23 */ { 0, 0, 0, 0, 0, 0 }, /* PA23 */
  51. /* PA22 */ { 0, 0, 0, 0, 0, 0 }, /* PA22 */
  52. /* PA21 */ { 0, 0, 0, 0, 0, 0 }, /* PA21 */
  53. /* PA20 */ { 0, 0, 0, 0, 0, 0 }, /* PA20 */
  54. /* PA19 */ { 0, 0, 0, 0, 0, 0 }, /* PA19 */
  55. /* PA18 */ { 0, 0, 0, 0, 0, 0 }, /* PA18 */
  56. /* PA17 */ { 0, 0, 0, 0, 0, 0 }, /* PA17 */
  57. /* PA16 */ { 0, 0, 0, 0, 0, 0 }, /* PA16 */
  58. /* PA15 */ { 0, 0, 0, 0, 0, 0 }, /* PA15 */
  59. /* PA14 */ { 0, 0, 0, 0, 0, 0 }, /* PA14 */
  60. /* PA13 */ { 0, 0, 0, 0, 0, 0 }, /* PA13 */
  61. /* PA12 */ { 0, 0, 0, 0, 0, 0 }, /* PA12 */
  62. /* PA11 */ { 0, 0, 0, 0, 0, 0 }, /* PA11 */
  63. /* PA10 */ { 0, 0, 0, 0, 0, 0 }, /* PA10 */
  64. /* PA9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TxD */
  65. /* PA8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC2 RxD */
  66. /* PA7 */ { 0, 0, 0, 0, 0, 0 }, /* PA7 */
  67. /* PA6 */ { 0, 0, 0, 0, 0, 0 }, /* PA6 */
  68. /* PA5 */ { 0, 0, 0, 0, 0, 0 }, /* PA5 */
  69. /* PA4 */ { 0, 0, 0, 0, 0, 0 }, /* PA4 */
  70. /* PA3 */ { 0, 0, 0, 0, 0, 0 }, /* PA3 */
  71. /* PA2 */ { 0, 0, 0, 0, 0, 0 }, /* PA2 */
  72. /* PA1 */ { 0, 0, 0, 0, 0, 0 }, /* PA1 */
  73. /* PA0 */ { 0, 0, 0, 0, 0, 0 } /* PA0 */
  74. },
  75. /* Port B */
  76. { /* conf ppar psor pdir podr pdat */
  77. /* PB31 */ { 0, 0, 0, 0, 0, 0 }, /* PB31 */
  78. /* PB30 */ { 0, 0, 0, 0, 0, 0 }, /* PB30 */
  79. /* PB29 */ { 0, 0, 0, 0, 0, 0 }, /* PB29 */
  80. /* PB28 */ { 0, 0, 0, 0, 0, 0 }, /* PB28 */
  81. /* PB27 */ { 0, 0, 0, 0, 0, 0 }, /* PB27 */
  82. /* PB26 */ { 0, 0, 0, 0, 0, 0 }, /* PB26 */
  83. /* PB25 */ { 0, 0, 0, 0, 0, 0 }, /* PB25 */
  84. /* PB24 */ { 0, 0, 0, 0, 0, 0 }, /* PB24 */
  85. /* PB23 */ { 0, 0, 0, 0, 0, 0 }, /* PB23 */
  86. /* PB22 */ { 0, 0, 0, 0, 0, 0 }, /* PB22 */
  87. /* PB21 */ { 0, 0, 0, 0, 0, 0 }, /* PB21 */
  88. /* PB20 */ { 0, 0, 0, 0, 0, 0 }, /* PB20 */
  89. /* PB19 */ { 0, 0, 0, 0, 0, 0 }, /* PB19 */
  90. /* PB18 */ { 0, 0, 0, 0, 0, 0 }, /* PB18 */
  91. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  92. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  93. /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  94. /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  95. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  96. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  97. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  98. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  99. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  100. /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  101. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  102. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  103. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  104. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  105. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  106. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  107. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  108. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  109. },
  110. /* Port C */
  111. { /* conf ppar psor pdir podr pdat */
  112. /* PC31 */ { 0, 0, 0, 0, 0, 0 }, /* PC31 */
  113. /* PC30 */ { 0, 0, 0, 0, 0, 0 }, /* PC30 */
  114. /* PC29 */ { 0, 0, 0, 0, 0, 0 }, /* PC29 */
  115. /* PC28 */ { 0, 0, 0, 0, 0, 0 }, /* PC28 */
  116. /* PC27 */ { 0, 0, 0, 0, 0, 0 }, /* PC27 */
  117. /* PC26 */ { 0, 0, 0, 0, 0, 0 }, /* PC26 */
  118. /* PC25 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 RxClk */
  119. /* PC24 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4 TxClk */
  120. /* PC23 */ { 0, 0, 0, 0, 0, 0 }, /* PC23 */
  121. /* PC22 */ { 0, 0, 0, 0, 0, 0 }, /* PC22 */
  122. /* PC21 */ { 0, 0, 0, 0, 0, 0 }, /* PC21 */
  123. /* PC20 */ { 0, 0, 0, 0, 0, 0 }, /* PC20 */
  124. /* PC19 */ { 0, 0, 0, 0, 0, 0 }, /* PC19 */
  125. /* PC18 */ { 0, 0, 0, 0, 0, 0 }, /* PC18 */
  126. /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* PC17 */
  127. /* PC16 */ { 0, 0, 0, 0, 0, 0 }, /* PC16 */
  128. /* PC15 */ { 0, 0, 0, 0, 0, 0 }, /* PC15 */
  129. /* PC14 */ { 0, 0, 0, 0, 0, 0 }, /* PC14 */
  130. /* PC13 */ { 0, 0, 0, 0, 0, 0 }, /* PC13 */
  131. /* PC12 */ { 0, 0, 0, 0, 0, 0 }, /* PC12 */
  132. /* PC11 */ { 0, 0, 0, 0, 0, 0 }, /* PC11 */
  133. /* PC10 */ { 0, 0, 0, 0, 0, 0 }, /* PC10 */
  134. /* PC9 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CTS */
  135. /* PC8 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: CD */
  136. /* PC7 */ { 0, 0, 0, 0, 0, 0 }, /* PC7 */
  137. /* PC6 */ { 0, 0, 0, 0, 0, 0 }, /* PC6 */
  138. /* PC5 */ { 0, 0, 0, 0, 0, 0 }, /* PC5 */
  139. /* PC4 */ { 0, 0, 0, 0, 0, 0 }, /* PC4 */
  140. /* PC3 */ { 0, 0, 0, 0, 0, 0 }, /* PC3 */
  141. /* PC2 */ { 0, 0, 0, 0, 0, 0 }, /* PC2 */
  142. /* PC1 */ { 0, 0, 0, 0, 0, 0 }, /* PC1 */
  143. /* PC0 */ { 0, 0, 0, 0, 0, 0 }, /* PC0 */
  144. },
  145. /* Port D */
  146. { /* conf ppar psor pdir podr pdat */
  147. /* PD31 */ { 0, 0, 0, 0, 0, 0 }, /* PD31 */
  148. /* PD30 */ { 0, 0, 0, 0, 0, 0 }, /* PD30 */
  149. /* PD29 */ { 0, 0, 0, 0, 0, 0 }, /* PD29 */
  150. /* PD28 */ { 0, 0, 0, 0, 0, 0 }, /* PD28 */
  151. /* PD27 */ { 0, 0, 0, 0, 0, 0 }, /* PD27 */
  152. /* PD26 */ { 0, 0, 0, 0, 0, 0 }, /* PD26 */
  153. /* PD25 */ { 0, 0, 0, 0, 0, 0 }, /* PD25 */
  154. /* PD24 */ { 0, 0, 0, 0, 0, 0 }, /* PD24 */
  155. /* PD23 */ { 0, 0, 0, 0, 0, 0 }, /* PD23 */
  156. /* PD22 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: RXD */
  157. /* PD21 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: TXD */
  158. /* PD20 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: RTS */
  159. /* PD19 */ { 0, 0, 0, 0, 0, 0 }, /* PD19 */
  160. /* PD18 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
  161. /* PD17 */ { 0, 0, 0, 0, 0, 0 }, /* PD17 */
  162. /* PD16 */ { 0, 0, 0, 0, 0, 0 }, /* PD16 */
  163. #if defined(CONFIG_HARD_I2C)
  164. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  165. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  166. #else
  167. /* PD15 */ { 1, 0, 0, 0, 1, 1 }, /* PD15 */
  168. /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* PD14 */
  169. #endif
  170. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  171. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  172. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  173. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  174. /* PD9 */ { 0, 0, 0, 0, 0, 0 }, /* PD9 */
  175. /* PD8 */ { 0, 0, 0, 0, 0, 0 }, /* PD8 */
  176. /* PD7 */ { 0, 0, 0, 0, 0, 0 }, /* PD7 */
  177. /* PD6 */ { 0, 0, 0, 0, 0, 0 }, /* PD6 */
  178. /* PD5 */ { 0, 0, 0, 0, 0, 0 }, /* PD5 */
  179. /* PD4 */ { 0, 0, 0, 0, 0, 0 }, /* PD4 */
  180. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  181. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  182. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  183. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
  184. }
  185. };
  186. /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  187. *
  188. * This routine performs standard 8260 initialization sequence
  189. * and calculates the available memory size. It may be called
  190. * several times to try different SDRAM configurations on both
  191. * 60x and local buses.
  192. */
  193. static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
  194. ulong orx, volatile uchar * base)
  195. {
  196. volatile uchar c = 0xff;
  197. volatile uint *sdmr_ptr;
  198. volatile uint *orx_ptr;
  199. ulong maxsize, size;
  200. int i;
  201. /* We must be able to test a location outsize the maximum legal size
  202. * to find out THAT we are outside; but this address still has to be
  203. * mapped by the controller. That means, that the initial mapping has
  204. * to be (at least) twice as large as the maximum expected size.
  205. */
  206. maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
  207. sdmr_ptr = &memctl->memc_psdmr;
  208. orx_ptr = &memctl->memc_or1;
  209. *orx_ptr = 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 CFG_SDRAM_BASE.
  228. */
  229. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  230. *base = c;
  231. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  232. for (i = 0; i < 8; i++)
  233. *base = c;
  234. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  235. *(base + CFG_MRS_OFFS) = c; /* setting MR on address lines */
  236. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  237. *base = c;
  238. size = get_ram_size ((long *)base, maxsize);
  239. *orx_ptr = orx | ~(size - 1);
  240. return (size);
  241. }
  242. phys_size_t initdram (int board_type)
  243. {
  244. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  245. volatile memctl8260_t *memctl = &immap->im_memctl;
  246. long psize;
  247. memctl->memc_psrt = CFG_PSRT;
  248. memctl->memc_mptpr = CFG_MPTPR;
  249. #ifndef CFG_RAMBOOT
  250. /* 60x SDRAM setup:
  251. */
  252. psize = try_init (memctl, CFG_PSDMR, CFG_OR1,
  253. (uchar *) CFG_SDRAM_BASE);
  254. #endif /* CFG_RAMBOOT */
  255. icache_enable ();
  256. return (psize);
  257. }
  258. int checkboard(void)
  259. {
  260. puts ("Board: mgcoge\n");
  261. return 0;
  262. }
  263. /*
  264. * Early board initalization.
  265. */
  266. int board_early_init_r (void)
  267. {
  268. /* setup the UPIOx */
  269. *(char *)(CFG_PIGGY_BASE + 0x02) = 0xc0;
  270. *(char *)(CFG_PIGGY_BASE + 0x03) = 0x15;
  271. return 0;
  272. }
  273. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  274. /*
  275. * update "memory" property in the blob
  276. */
  277. void ft_blob_update (void *blob, bd_t *bd)
  278. {
  279. int ret, nodeoffset = 0;
  280. ulong memory_data[2] = {0};
  281. ulong flash_data[8] = {0};
  282. memory_data[0] = cpu_to_be32 (bd->bi_memstart);
  283. memory_data[1] = cpu_to_be32 (bd->bi_memsize);
  284. nodeoffset = fdt_path_offset (blob, "/memory");
  285. if (nodeoffset >= 0) {
  286. ret = fdt_setprop (blob, nodeoffset, "reg", memory_data,
  287. sizeof (memory_data));
  288. if (ret < 0)
  289. printf ("ft_blob_update(): cannot set /memory/reg "
  290. "property err:%s\n", fdt_strerror (ret));
  291. } else {
  292. /* memory node is required in dts */
  293. printf ("ft_blob_update(): cannot find /memory node "
  294. "err:%s\n", fdt_strerror (nodeoffset));
  295. }
  296. /* update Flash addr, size */
  297. flash_data[2] = cpu_to_be32 (CFG_FLASH_BASE);
  298. flash_data[3] = cpu_to_be32 (CFG_FLASH_SIZE);
  299. flash_data[4] = cpu_to_be32 (1);
  300. flash_data[5] = cpu_to_be32 (0);
  301. flash_data[6] = cpu_to_be32 (CFG_FLASH_BASE_1);
  302. flash_data[7] = cpu_to_be32 (CFG_FLASH_SIZE_1);
  303. nodeoffset = fdt_path_offset (blob, "/localbus");
  304. if (nodeoffset >= 0) {
  305. ret = fdt_setprop (blob, nodeoffset, "ranges", flash_data,
  306. sizeof (flash_data));
  307. if (ret < 0)
  308. printf ("ft_blob_update(): cannot set /localbus/ranges "
  309. "property err:%s\n", fdt_strerror (ret));
  310. } else {
  311. /* memory node is required in dts */
  312. printf ("ft_blob_update(): cannot find /localbus node "
  313. "err:%s\n", fdt_strerror (nodeoffset));
  314. }
  315. /* MAC Adresse */
  316. nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet");
  317. if (nodeoffset >= 0) {
  318. ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr,
  319. sizeof (uchar) * 6);
  320. if (ret < 0)
  321. printf ("ft_blob_update(): cannot set /soc/cpm/ethernet/mac-address "
  322. "property err:%s\n", fdt_strerror (ret));
  323. } else {
  324. /* memory node is required in dts */
  325. printf ("ft_blob_update(): cannot find /soc/cpm/ethernet node "
  326. "err:%s\n", fdt_strerror (nodeoffset));
  327. }
  328. }
  329. void ft_board_setup (void *blob, bd_t *bd)
  330. {
  331. ft_cpu_setup (blob, bd);
  332. ft_blob_update (blob, bd);
  333. }
  334. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */