mgcoge.c 16 KB

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