redwood.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * This is the main board level file for the Redwood AMCC board.
  3. *
  4. * (C) Copyright 2008
  5. * Feng Kan, Applied Micro Circuits Corp., fkan@amcc.com
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include "redwood.h"
  11. #include <asm/ppc4xx.h>
  12. #include <asm/processor.h>
  13. #include <i2c.h>
  14. #include <asm/io.h>
  15. int compare_to_true(char *str);
  16. char *remove_l_w_space(char *in_str);
  17. char *remove_t_w_space(char *in_str);
  18. int get_console_port(void);
  19. static void early_init_EBC(void);
  20. static int bootdevice_selected(void);
  21. static void early_reinit_EBC(int);
  22. static void early_init_UIC(void);
  23. /*
  24. * Define Boot devices
  25. */
  26. #define BOOT_FROM_8BIT_SRAM 0x00
  27. #define BOOT_FROM_16BIT_SRAM 0x01
  28. #define BOOT_FROM_32BIT_SRAM 0x02
  29. #define BOOT_FROM_8BIT_NAND 0x03
  30. #define BOOT_FROM_16BIT_NOR 0x04
  31. #define BOOT_DEVICE_UNKNOWN 0xff
  32. /*
  33. * EBC Devices Characteristics
  34. * Peripheral Bank Access Parameters - EBC_BxAP
  35. * Peripheral Bank Configuration Register - EBC_BxCR
  36. */
  37. /*
  38. * 8 bit width SRAM
  39. * BU Value
  40. * BxAP : 0x03800000 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  41. * B0CR : 0xff098000 - BAS = ff0 - 100 11 00 0000000000000
  42. * B2CR : 0xe7098000 - BAS = e70 - 100 11 00 0000000000000
  43. */
  44. #define EBC_BXAP_8BIT_SRAM \
  45. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(7) | \
  46. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  47. EBC_BXAP_CSN_ENCODE(0) | EBC_BXAP_OEN_ENCODE(0) | \
  48. EBC_BXAP_WBN_ENCODE(0) | EBC_BXAP_WBF_ENCODE(0) | \
  49. EBC_BXAP_TH_ENCODE(0) | EBC_BXAP_RE_DISABLED | \
  50. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_WRITEONLY | \
  51. EBC_BXAP_PEN_DISABLED
  52. #define EBC_BXAP_16BIT_SRAM EBC_BXAP_8BIT_SRAM
  53. #define EBC_BXAP_32BIT_SRAM EBC_BXAP_8BIT_SRAM
  54. /*
  55. * NAND flash
  56. * BU Value
  57. * BxAP : 0x048ff240 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  58. * B0CR : 0xff09a000 - BAS = ff0 - 100 11 01 0000000000000
  59. * B2CR : 0xe709a000 - BAS = e70 - 100 11 01 0000000000000
  60. */
  61. #define EBC_BXAP_NAND \
  62. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(7) | \
  63. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  64. EBC_BXAP_CSN_ENCODE(0) | EBC_BXAP_OEN_ENCODE(0) | \
  65. EBC_BXAP_WBN_ENCODE(0) | EBC_BXAP_WBF_ENCODE(0) | \
  66. EBC_BXAP_TH_ENCODE(0) | EBC_BXAP_RE_DISABLED | \
  67. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_WRITEONLY | \
  68. EBC_BXAP_PEN_DISABLED
  69. /*
  70. * NOR flash
  71. * BU Value
  72. * BxAP : 0x048ff240 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  73. * B0CR : 0xff09a000 - BAS = ff0 - 100 11 01 0000000000000
  74. * B2CR : 0xe709a000 - BAS = e70 - 100 11 01 0000000000000
  75. */
  76. #define EBC_BXAP_NOR \
  77. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(7) | \
  78. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  79. EBC_BXAP_CSN_ENCODE(0) | EBC_BXAP_OEN_ENCODE(0) | \
  80. EBC_BXAP_WBN_ENCODE(0) | EBC_BXAP_WBF_ENCODE(0) | \
  81. EBC_BXAP_TH_ENCODE(0) | EBC_BXAP_RE_DISABLED | \
  82. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_WRITEONLY | \
  83. EBC_BXAP_PEN_DISABLED
  84. /*
  85. * FPGA
  86. * BU value :
  87. * B1AP = 0x05895240 - 0 00001011 0 00 10 01 01 01 001 0 0 1 0 00000
  88. * B1CR = 0xe201a000 - BAS = e20 - 000 11 01 00000000000000
  89. */
  90. #define EBC_BXAP_FPGA \
  91. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(11) | \
  92. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  93. EBC_BXAP_CSN_ENCODE(10) | EBC_BXAP_OEN_ENCODE(1) | \
  94. EBC_BXAP_WBN_ENCODE(1) | EBC_BXAP_WBF_ENCODE(1) | \
  95. EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_RE_DISABLED | \
  96. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_RW | \
  97. EBC_BXAP_PEN_DISABLED
  98. #define EBC_BXCR_8BIT_SRAM_CS0 \
  99. EBC_BXCR_BAS_ENCODE(0xFFE00000) | EBC_BXCR_BS_1MB | \
  100. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  101. #define EBC_BXCR_32BIT_SRAM_CS0 \
  102. EBC_BXCR_BAS_ENCODE(0xFFC00000) | EBC_BXCR_BS_1MB | \
  103. EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT
  104. #define EBC_BXCR_NAND_CS0 \
  105. EBC_BXCR_BAS_ENCODE(0xFF000000) | EBC_BXCR_BS_16MB | \
  106. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  107. #define EBC_BXCR_16BIT_SRAM_CS0 \
  108. EBC_BXCR_BAS_ENCODE(0xFFE00000) | EBC_BXCR_BS_2MB | \
  109. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  110. #define EBC_BXCR_NOR_CS0 \
  111. EBC_BXCR_BAS_ENCODE(0xFF000000) | EBC_BXCR_BS_16MB | \
  112. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  113. #define EBC_BXCR_NOR_CS1 \
  114. EBC_BXCR_BAS_ENCODE(0xE0000000) | EBC_BXCR_BS_128MB | \
  115. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  116. #define EBC_BXCR_NAND_CS1 \
  117. EBC_BXCR_BAS_ENCODE(0xE0000000) | EBC_BXCR_BS_128MB | \
  118. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  119. #define EBC_BXCR_NAND_CS2 \
  120. EBC_BXCR_BAS_ENCODE(0xC0000000) | EBC_BXCR_BS_128MB | \
  121. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  122. #define EBC_BXCR_SRAM_CS2 \
  123. EBC_BXCR_BAS_ENCODE(0xC0000000) | EBC_BXCR_BS_4MB | \
  124. EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT
  125. #define EBC_BXCR_LARGE_FLASH_CS2 \
  126. EBC_BXCR_BAS_ENCODE(0xE7000000) | EBC_BXCR_BS_16MB | \
  127. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  128. #define EBC_BXCR_FPGA_CS3 \
  129. EBC_BXCR_BAS_ENCODE(0xE2000000) | EBC_BXCR_BS_1MB | \
  130. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  131. /*****************************************************************************
  132. * UBOOT initiated board specific function calls
  133. ****************************************************************************/
  134. int board_early_init_f(void)
  135. {
  136. int computed_boot_device = BOOT_DEVICE_UNKNOWN;
  137. /*
  138. * Initialise EBC
  139. */
  140. early_init_EBC();
  141. /*
  142. * Determine which boot device was selected
  143. */
  144. computed_boot_device = bootdevice_selected();
  145. /*
  146. * Reinit EBC based on selected boot device
  147. */
  148. early_reinit_EBC(computed_boot_device);
  149. /*
  150. * Setup for UIC on 460SX redwood board
  151. */
  152. early_init_UIC();
  153. return 0;
  154. }
  155. int checkboard(void)
  156. {
  157. char buf[64];
  158. int i = getenv_f("serial#", buf, sizeof(buf));
  159. printf("Board: Redwood - AMCC 460SX Reference Board");
  160. if (i > 0) {
  161. puts(", serial# ");
  162. puts(buf);
  163. }
  164. putc('\n');
  165. return 0;
  166. }
  167. static void early_init_EBC(void)
  168. {
  169. /*
  170. * Initialize EBC CONFIG -
  171. * Keep the Default value, but the bit PDT which has to be set to 1 ?TBC
  172. * default value :
  173. * 0x07C00000 - 0 0 000 1 1 1 1 1 0000 0 00000 000000000000
  174. */
  175. mtebc(EBC0_CFG, EBC_CFG_LE_UNLOCK |
  176. EBC_CFG_PTD_ENABLE |
  177. EBC_CFG_RTC_16PERCLK |
  178. EBC_CFG_ATC_PREVIOUS |
  179. EBC_CFG_DTC_PREVIOUS |
  180. EBC_CFG_CTC_PREVIOUS |
  181. EBC_CFG_OEO_PREVIOUS |
  182. EBC_CFG_EMC_DEFAULT | EBC_CFG_PME_DISABLE | EBC_CFG_PR_16);
  183. /*
  184. * PART 1 : Initialize EBC Bank 3
  185. * ==============================
  186. * Bank1 is always associated to the EPLD.
  187. * It has to be initialized prior to other banks settings computation
  188. * since some board registers values may be needed to determine the
  189. * boot type
  190. */
  191. mtebc(PB1AP, EBC_BXAP_FPGA);
  192. mtebc(PB1CR, EBC_BXCR_FPGA_CS3);
  193. }
  194. static int bootdevice_selected(void)
  195. {
  196. unsigned long sdr0_pinstp;
  197. unsigned long bootstrap_settings;
  198. int computed_boot_device = BOOT_DEVICE_UNKNOWN;
  199. /*
  200. * Determine which boot device was selected
  201. * =================================================
  202. *
  203. * Read Pin Strap Register in PPC460SX
  204. * Result can either be :
  205. * - Boot strap = boot from EBC 8bits => Small Flash
  206. * - Boot strap = boot from PCI
  207. * - Boot strap = IIC
  208. * In case of boot from IIC, read Serial Device Strap Register1
  209. *
  210. * Result can either be :
  211. * - Boot from EBC - EBC Bus Width = 8bits => Small Flash
  212. * - Boot from EBC - EBC Bus Width = 16bits => Large Flash or SRAM
  213. * - Boot from PCI
  214. */
  215. /* Read Pin Strap Register in PPC460SX */
  216. mfsdr(SDR0_PINSTP, sdr0_pinstp);
  217. bootstrap_settings = sdr0_pinstp & SDR0_PSTRP0_BOOTSTRAP_MASK;
  218. switch (bootstrap_settings) {
  219. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS0:
  220. /*
  221. * Boot from SRAM, 8bit width
  222. */
  223. computed_boot_device = BOOT_FROM_8BIT_SRAM;
  224. break;
  225. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS1:
  226. /*
  227. * Boot from SRAM, 32bit width
  228. */
  229. computed_boot_device = BOOT_FROM_32BIT_SRAM;
  230. break;
  231. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS2:
  232. /*
  233. * Boot from NAND, 8bit width
  234. */
  235. computed_boot_device = BOOT_FROM_8BIT_NAND;
  236. break;
  237. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS4:
  238. /*
  239. * Boot from SRAM, 16bit width
  240. * Boot setting in IIC EEPROM 0x50
  241. */
  242. computed_boot_device = BOOT_FROM_16BIT_SRAM;
  243. break;
  244. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS5:
  245. /*
  246. * Boot from NOR, 16bit width
  247. * Boot setting in IIC EEPROM 0x54
  248. */
  249. computed_boot_device = BOOT_FROM_16BIT_NOR;
  250. break;
  251. default:
  252. /* should not be */
  253. computed_boot_device = BOOT_DEVICE_UNKNOWN;
  254. break;
  255. }
  256. return computed_boot_device;
  257. }
  258. static void early_reinit_EBC(int computed_boot_device)
  259. {
  260. /*
  261. * Compute EBC settings depending on selected boot device
  262. * ======================================================
  263. *
  264. * Resulting EBC init will be among following configurations :
  265. *
  266. * - Boot from EBC 8bits => boot from Small Flash selected
  267. * EBC-CS0 = Small Flash
  268. * EBC-CS2 = Large Flash and SRAM
  269. *
  270. * - Boot from EBC 16bits => boot from Large Flash or SRAM
  271. * EBC-CS0 = Large Flash or SRAM
  272. * EBC-CS2 = Small Flash
  273. *
  274. * - Boot from PCI
  275. * EBC-CS0 = not initialized to avoid address contention
  276. * EBC-CS2 = same as boot from Small Flash selected
  277. */
  278. unsigned long ebc0_cs0_bxap_value = 0, ebc0_cs0_bxcr_value = 0;
  279. unsigned long ebc0_cs1_bxap_value = 0, ebc0_cs1_bxcr_value = 0;
  280. unsigned long ebc0_cs2_bxap_value = 0, ebc0_cs2_bxcr_value = 0;
  281. switch (computed_boot_device) {
  282. /*-------------------------------------------------------------------*/
  283. case BOOT_FROM_8BIT_SRAM:
  284. /*-------------------------------------------------------------------*/
  285. ebc0_cs0_bxap_value = EBC_BXAP_8BIT_SRAM;
  286. ebc0_cs0_bxcr_value = EBC_BXCR_8BIT_SRAM_CS0;
  287. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  288. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  289. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  290. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  291. break;
  292. /*-------------------------------------------------------------------*/
  293. case BOOT_FROM_16BIT_SRAM:
  294. /*-------------------------------------------------------------------*/
  295. ebc0_cs0_bxap_value = EBC_BXAP_16BIT_SRAM;
  296. ebc0_cs0_bxcr_value = EBC_BXCR_16BIT_SRAM_CS0;
  297. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  298. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  299. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  300. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  301. break;
  302. /*-------------------------------------------------------------------*/
  303. case BOOT_FROM_32BIT_SRAM:
  304. /*-------------------------------------------------------------------*/
  305. ebc0_cs0_bxap_value = EBC_BXAP_32BIT_SRAM;
  306. ebc0_cs0_bxcr_value = EBC_BXCR_32BIT_SRAM_CS0;
  307. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  308. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  309. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  310. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  311. break;
  312. /*-------------------------------------------------------------------*/
  313. case BOOT_FROM_16BIT_NOR:
  314. /*-------------------------------------------------------------------*/
  315. ebc0_cs0_bxap_value = EBC_BXAP_NOR;
  316. ebc0_cs0_bxcr_value = EBC_BXCR_NOR_CS0;
  317. ebc0_cs1_bxap_value = EBC_BXAP_NAND;
  318. ebc0_cs1_bxcr_value = EBC_BXCR_NAND_CS1;
  319. ebc0_cs2_bxap_value = EBC_BXAP_32BIT_SRAM;
  320. ebc0_cs2_bxcr_value = EBC_BXCR_SRAM_CS2;
  321. break;
  322. /*-------------------------------------------------------------------*/
  323. case BOOT_FROM_8BIT_NAND:
  324. /*-------------------------------------------------------------------*/
  325. ebc0_cs0_bxap_value = EBC_BXAP_NAND;
  326. ebc0_cs0_bxcr_value = EBC_BXCR_NAND_CS0;
  327. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  328. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  329. ebc0_cs2_bxap_value = EBC_BXAP_32BIT_SRAM;
  330. ebc0_cs2_bxcr_value = EBC_BXCR_SRAM_CS2;
  331. break;
  332. /*-------------------------------------------------------------------*/
  333. default:
  334. /*-------------------------------------------------------------------*/
  335. /* BOOT_DEVICE_UNKNOWN */
  336. break;
  337. }
  338. mtebc(PB0AP, ebc0_cs0_bxap_value);
  339. mtebc(PB0CR, ebc0_cs0_bxcr_value);
  340. mtebc(PB1AP, ebc0_cs1_bxap_value);
  341. mtebc(PB1CR, ebc0_cs1_bxcr_value);
  342. mtebc(PB2AP, ebc0_cs2_bxap_value);
  343. mtebc(PB2CR, ebc0_cs2_bxcr_value);
  344. }
  345. static void early_init_UIC(void)
  346. {
  347. /*
  348. * Initialise UIC registers. Clear all interrupts. Disable all
  349. * interrupts.
  350. * Set critical interrupt values. Set interrupt polarities. Set
  351. * interrupt trigger levels. Make bit 0 High priority. Clear all
  352. * interrupts again.
  353. */
  354. mtdcr(UIC3SR, 0xffffffff); /* Clear all interrupts */
  355. mtdcr(UIC3ER, 0x00000000); /* disable all interrupts */
  356. mtdcr(UIC3CR, 0x00000000); /* Set Critical / Non Critical
  357. * interrupts */
  358. mtdcr(UIC3PR, 0xffffffff); /* Set Interrupt Polarities */
  359. mtdcr(UIC3TR, 0x001fffff); /* Set Interrupt Trigger Levels */
  360. mtdcr(UIC3VR, 0x00000000); /* int31 highest, base=0x000 */
  361. mtdcr(UIC3SR, 0xffffffff); /* clear all interrupts */
  362. mtdcr(UIC2SR, 0xffffffff); /* Clear all interrupts */
  363. mtdcr(UIC2ER, 0x00000000); /* disable all interrupts */
  364. mtdcr(UIC2CR, 0x00000000); /* Set Critical / Non Critical
  365. * interrupts */
  366. mtdcr(UIC2PR, 0xebebebff); /* Set Interrupt Polarities */
  367. mtdcr(UIC2TR, 0x74747400); /* Set Interrupt Trigger Levels */
  368. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  369. mtdcr(UIC2SR, 0xffffffff); /* clear all interrupts */
  370. mtdcr(UIC1SR, 0xffffffff); /* Clear all interrupts */
  371. mtdcr(UIC1ER, 0x00000000); /* disable all interrupts */
  372. mtdcr(UIC1CR, 0x00000000); /* Set Critical / Non Critical
  373. * interrupts */
  374. mtdcr(UIC1PR, 0xffffffff); /* Set Interrupt Polarities */
  375. mtdcr(UIC1TR, 0x001fc0ff); /* Set Interrupt Trigger Levels */
  376. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  377. mtdcr(UIC1SR, 0xffffffff); /* clear all interrupts */
  378. mtdcr(UIC0SR, 0xffffffff); /* Clear all interrupts */
  379. mtdcr(UIC0ER, 0x00000000); /* disable all interrupts excepted
  380. * cascade to be checked */
  381. mtdcr(UIC0CR, 0x00104001); /* Set Critical / Non Critical
  382. * interrupts */
  383. mtdcr(UIC0PR, 0xffffffff); /* Set Interrupt Polarities */
  384. mtdcr(UIC0TR, 0x000f003c); /* Set Interrupt Trigger Levels */
  385. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  386. mtdcr(UIC0SR, 0xffffffff); /* clear all interrupts */
  387. }