muas3001.c 16 KB

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