redwood.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. */
  26. #include <common.h>
  27. #include "redwood.h"
  28. #include <ppc4xx.h>
  29. #include <asm/processor.h>
  30. #include <i2c.h>
  31. #include <asm-ppc/io.h>
  32. int compare_to_true(char *str);
  33. char *remove_l_w_space(char *in_str);
  34. char *remove_t_w_space(char *in_str);
  35. int get_console_port(void);
  36. static void early_init_EBC(void);
  37. static int bootdevice_selected(void);
  38. static void early_reinit_EBC(int);
  39. static void early_init_UIC(void);
  40. /*
  41. * Define Boot devices
  42. */
  43. #define BOOT_FROM_8BIT_SRAM 0x00
  44. #define BOOT_FROM_16BIT_SRAM 0x01
  45. #define BOOT_FROM_32BIT_SRAM 0x02
  46. #define BOOT_FROM_8BIT_NAND 0x03
  47. #define BOOT_FROM_16BIT_NOR 0x04
  48. #define BOOT_DEVICE_UNKNOWN 0xff
  49. /*
  50. * EBC Devices Characteristics
  51. * Peripheral Bank Access Parameters - EBC_BxAP
  52. * Peripheral Bank Configuration Register - EBC_BxCR
  53. */
  54. /*
  55. * 8 bit width SRAM
  56. * BU Value
  57. * BxAP : 0x03800000 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  58. * B0CR : 0xff098000 - BAS = ff0 - 100 11 00 0000000000000
  59. * B2CR : 0xe7098000 - BAS = e70 - 100 11 00 0000000000000
  60. */
  61. #define EBC_BXAP_8BIT_SRAM \
  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. #define EBC_BXAP_16BIT_SRAM EBC_BXAP_8BIT_SRAM
  70. #define EBC_BXAP_32BIT_SRAM EBC_BXAP_8BIT_SRAM
  71. /*
  72. * NAND flash
  73. * BU Value
  74. * BxAP : 0x048ff240 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  75. * B0CR : 0xff09a000 - BAS = ff0 - 100 11 01 0000000000000
  76. * B2CR : 0xe709a000 - BAS = e70 - 100 11 01 0000000000000
  77. */
  78. #define EBC_BXAP_NAND \
  79. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(7) | \
  80. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  81. EBC_BXAP_CSN_ENCODE(0) | EBC_BXAP_OEN_ENCODE(0) | \
  82. EBC_BXAP_WBN_ENCODE(0) | EBC_BXAP_WBF_ENCODE(0) | \
  83. EBC_BXAP_TH_ENCODE(0) | EBC_BXAP_RE_DISABLED | \
  84. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_WRITEONLY | \
  85. EBC_BXAP_PEN_DISABLED
  86. /*
  87. * NOR flash
  88. * BU Value
  89. * BxAP : 0x048ff240 - 0 00000111 0 00 00 00 00 00 000 0 0 0 0 00000
  90. * B0CR : 0xff09a000 - BAS = ff0 - 100 11 01 0000000000000
  91. * B2CR : 0xe709a000 - BAS = e70 - 100 11 01 0000000000000
  92. */
  93. #define EBC_BXAP_NOR \
  94. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(7) | \
  95. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  96. EBC_BXAP_CSN_ENCODE(0) | EBC_BXAP_OEN_ENCODE(0) | \
  97. EBC_BXAP_WBN_ENCODE(0) | EBC_BXAP_WBF_ENCODE(0) | \
  98. EBC_BXAP_TH_ENCODE(0) | EBC_BXAP_RE_DISABLED | \
  99. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_WRITEONLY | \
  100. EBC_BXAP_PEN_DISABLED
  101. /*
  102. * FPGA
  103. * BU value :
  104. * B1AP = 0x05895240 - 0 00001011 0 00 10 01 01 01 001 0 0 1 0 00000
  105. * B1CR = 0xe201a000 - BAS = e20 - 000 11 01 00000000000000
  106. */
  107. #define EBC_BXAP_FPGA \
  108. EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(11) | \
  109. EBC_BXAP_BCE_DISABLE | EBC_BXAP_BCT_2TRANS | \
  110. EBC_BXAP_CSN_ENCODE(10) | EBC_BXAP_OEN_ENCODE(1) | \
  111. EBC_BXAP_WBN_ENCODE(1) | EBC_BXAP_WBF_ENCODE(1) | \
  112. EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_RE_DISABLED | \
  113. EBC_BXAP_SOR_DELAYED | EBC_BXAP_BEM_RW | \
  114. EBC_BXAP_PEN_DISABLED
  115. #define EBC_BXCR_8BIT_SRAM_CS0 \
  116. EBC_BXCR_BAS_ENCODE(0xFFE00000) | EBC_BXCR_BS_1MB | \
  117. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  118. #define EBC_BXCR_32BIT_SRAM_CS0 \
  119. EBC_BXCR_BAS_ENCODE(0xFFC00000) | EBC_BXCR_BS_1MB | \
  120. EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT
  121. #define EBC_BXCR_NAND_CS0 \
  122. EBC_BXCR_BAS_ENCODE(0xFF000000) | EBC_BXCR_BS_16MB | \
  123. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  124. #define EBC_BXCR_16BIT_SRAM_CS0 \
  125. EBC_BXCR_BAS_ENCODE(0xFFE00000) | EBC_BXCR_BS_2MB | \
  126. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  127. #define EBC_BXCR_NOR_CS0 \
  128. EBC_BXCR_BAS_ENCODE(0xFF000000) | EBC_BXCR_BS_16MB | \
  129. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  130. #define EBC_BXCR_NOR_CS1 \
  131. EBC_BXCR_BAS_ENCODE(0xE0000000) | EBC_BXCR_BS_128MB | \
  132. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  133. #define EBC_BXCR_NAND_CS1 \
  134. EBC_BXCR_BAS_ENCODE(0xE0000000) | EBC_BXCR_BS_128MB | \
  135. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  136. #define EBC_BXCR_NAND_CS2 \
  137. EBC_BXCR_BAS_ENCODE(0xC0000000) | EBC_BXCR_BS_128MB | \
  138. EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT
  139. #define EBC_BXCR_SRAM_CS2 \
  140. EBC_BXCR_BAS_ENCODE(0xC0000000) | EBC_BXCR_BS_4MB | \
  141. EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT
  142. #define EBC_BXCR_LARGE_FLASH_CS2 \
  143. EBC_BXCR_BAS_ENCODE(0xE7000000) | EBC_BXCR_BS_16MB | \
  144. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  145. #define EBC_BXCR_FPGA_CS3 \
  146. EBC_BXCR_BAS_ENCODE(0xE2000000) | EBC_BXCR_BS_1MB | \
  147. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT
  148. /*****************************************************************************
  149. * UBOOT initiated board specific function calls
  150. ****************************************************************************/
  151. int board_early_init_f(void)
  152. {
  153. int computed_boot_device = BOOT_DEVICE_UNKNOWN;
  154. /*
  155. * Initialise EBC
  156. */
  157. early_init_EBC();
  158. /*
  159. * Determine which boot device was selected
  160. */
  161. computed_boot_device = bootdevice_selected();
  162. /*
  163. * Reinit EBC based on selected boot device
  164. */
  165. early_reinit_EBC(computed_boot_device);
  166. /*
  167. * Setup for UIC on 460SX redwood board
  168. */
  169. early_init_UIC();
  170. return 0;
  171. }
  172. int checkboard(void)
  173. {
  174. char *s = getenv("serial#");
  175. printf("Board: Redwood - AMCC 460SX Reference Board");
  176. if (s != NULL) {
  177. puts(", serial# ");
  178. puts(s);
  179. }
  180. putc('\n');
  181. return 0;
  182. }
  183. static void early_init_EBC(void)
  184. {
  185. /*
  186. * Initialize EBC CONFIG -
  187. * Keep the Default value, but the bit PDT which has to be set to 1 ?TBC
  188. * default value :
  189. * 0x07C00000 - 0 0 000 1 1 1 1 1 0000 0 00000 000000000000
  190. */
  191. mtebc(xbcfg, EBC_CFG_LE_UNLOCK |
  192. EBC_CFG_PTD_ENABLE |
  193. EBC_CFG_RTC_16PERCLK |
  194. EBC_CFG_ATC_PREVIOUS |
  195. EBC_CFG_DTC_PREVIOUS |
  196. EBC_CFG_CTC_PREVIOUS |
  197. EBC_CFG_OEO_PREVIOUS |
  198. EBC_CFG_EMC_DEFAULT | EBC_CFG_PME_DISABLE | EBC_CFG_PR_16);
  199. /*
  200. * PART 1 : Initialize EBC Bank 3
  201. * ==============================
  202. * Bank1 is always associated to the EPLD.
  203. * It has to be initialized prior to other banks settings computation
  204. * since some board registers values may be needed to determine the
  205. * boot type
  206. */
  207. mtebc(pb1ap, EBC_BXAP_FPGA);
  208. mtebc(pb1cr, EBC_BXCR_FPGA_CS3);
  209. }
  210. static int bootdevice_selected(void)
  211. {
  212. unsigned long sdr0_pinstp;
  213. unsigned long bootstrap_settings;
  214. int computed_boot_device = BOOT_DEVICE_UNKNOWN;
  215. /*
  216. * Determine which boot device was selected
  217. * =================================================
  218. *
  219. * Read Pin Strap Register in PPC460SX
  220. * Result can either be :
  221. * - Boot strap = boot from EBC 8bits => Small Flash
  222. * - Boot strap = boot from PCI
  223. * - Boot strap = IIC
  224. * In case of boot from IIC, read Serial Device Strap Register1
  225. *
  226. * Result can either be :
  227. * - Boot from EBC - EBC Bus Width = 8bits => Small Flash
  228. * - Boot from EBC - EBC Bus Width = 16bits => Large Flash or SRAM
  229. * - Boot from PCI
  230. */
  231. /* Read Pin Strap Register in PPC460SX */
  232. mfsdr(SDR0_PINSTP, sdr0_pinstp);
  233. bootstrap_settings = sdr0_pinstp & SDR0_PSTRP0_BOOTSTRAP_MASK;
  234. switch (bootstrap_settings) {
  235. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS0:
  236. /*
  237. * Boot from SRAM, 8bit width
  238. */
  239. computed_boot_device = BOOT_FROM_8BIT_SRAM;
  240. break;
  241. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS1:
  242. /*
  243. * Boot from SRAM, 32bit width
  244. */
  245. computed_boot_device = BOOT_FROM_32BIT_SRAM;
  246. break;
  247. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS2:
  248. /*
  249. * Boot from NAND, 8bit width
  250. */
  251. computed_boot_device = BOOT_FROM_8BIT_NAND;
  252. break;
  253. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS4:
  254. /*
  255. * Boot from SRAM, 16bit width
  256. * Boot setting in IIC EEPROM 0x50
  257. */
  258. computed_boot_device = BOOT_FROM_16BIT_SRAM;
  259. break;
  260. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS5:
  261. /*
  262. * Boot from NOR, 16bit width
  263. * Boot setting in IIC EEPROM 0x54
  264. */
  265. computed_boot_device = BOOT_FROM_16BIT_NOR;
  266. break;
  267. default:
  268. /* should not be */
  269. computed_boot_device = BOOT_DEVICE_UNKNOWN;
  270. break;
  271. }
  272. return computed_boot_device;
  273. }
  274. static void early_reinit_EBC(int computed_boot_device)
  275. {
  276. /*
  277. * Compute EBC settings depending on selected boot device
  278. * ======================================================
  279. *
  280. * Resulting EBC init will be among following configurations :
  281. *
  282. * - Boot from EBC 8bits => boot from Small Flash selected
  283. * EBC-CS0 = Small Flash
  284. * EBC-CS2 = Large Flash and SRAM
  285. *
  286. * - Boot from EBC 16bits => boot from Large Flash or SRAM
  287. * EBC-CS0 = Large Flash or SRAM
  288. * EBC-CS2 = Small Flash
  289. *
  290. * - Boot from PCI
  291. * EBC-CS0 = not initialized to avoid address contention
  292. * EBC-CS2 = same as boot from Small Flash selected
  293. */
  294. unsigned long ebc0_cs0_bxap_value = 0, ebc0_cs0_bxcr_value = 0;
  295. unsigned long ebc0_cs1_bxap_value = 0, ebc0_cs1_bxcr_value = 0;
  296. unsigned long ebc0_cs2_bxap_value = 0, ebc0_cs2_bxcr_value = 0;
  297. switch (computed_boot_device) {
  298. /*-------------------------------------------------------------------*/
  299. case BOOT_FROM_8BIT_SRAM:
  300. /*-------------------------------------------------------------------*/
  301. ebc0_cs0_bxap_value = EBC_BXAP_8BIT_SRAM;
  302. ebc0_cs0_bxcr_value = EBC_BXCR_8BIT_SRAM_CS0;
  303. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  304. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  305. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  306. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  307. break;
  308. /*-------------------------------------------------------------------*/
  309. case BOOT_FROM_16BIT_SRAM:
  310. /*-------------------------------------------------------------------*/
  311. ebc0_cs0_bxap_value = EBC_BXAP_16BIT_SRAM;
  312. ebc0_cs0_bxcr_value = EBC_BXCR_16BIT_SRAM_CS0;
  313. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  314. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  315. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  316. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  317. break;
  318. /*-------------------------------------------------------------------*/
  319. case BOOT_FROM_32BIT_SRAM:
  320. /*-------------------------------------------------------------------*/
  321. ebc0_cs0_bxap_value = EBC_BXAP_32BIT_SRAM;
  322. ebc0_cs0_bxcr_value = EBC_BXCR_32BIT_SRAM_CS0;
  323. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  324. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  325. ebc0_cs2_bxap_value = EBC_BXAP_NAND;
  326. ebc0_cs2_bxcr_value = EBC_BXCR_NAND_CS2;
  327. break;
  328. /*-------------------------------------------------------------------*/
  329. case BOOT_FROM_16BIT_NOR:
  330. /*-------------------------------------------------------------------*/
  331. ebc0_cs0_bxap_value = EBC_BXAP_NOR;
  332. ebc0_cs0_bxcr_value = EBC_BXCR_NOR_CS0;
  333. ebc0_cs1_bxap_value = EBC_BXAP_NAND;
  334. ebc0_cs1_bxcr_value = EBC_BXCR_NAND_CS1;
  335. ebc0_cs2_bxap_value = EBC_BXAP_32BIT_SRAM;
  336. ebc0_cs2_bxcr_value = EBC_BXCR_SRAM_CS2;
  337. break;
  338. /*-------------------------------------------------------------------*/
  339. case BOOT_FROM_8BIT_NAND:
  340. /*-------------------------------------------------------------------*/
  341. ebc0_cs0_bxap_value = EBC_BXAP_NAND;
  342. ebc0_cs0_bxcr_value = EBC_BXCR_NAND_CS0;
  343. ebc0_cs1_bxap_value = EBC_BXAP_NOR;
  344. ebc0_cs1_bxcr_value = EBC_BXCR_NOR_CS1;
  345. ebc0_cs2_bxap_value = EBC_BXAP_32BIT_SRAM;
  346. ebc0_cs2_bxcr_value = EBC_BXCR_SRAM_CS2;
  347. break;
  348. /*-------------------------------------------------------------------*/
  349. default:
  350. /*-------------------------------------------------------------------*/
  351. /* BOOT_DEVICE_UNKNOWN */
  352. break;
  353. }
  354. mtebc(pb0ap, ebc0_cs0_bxap_value);
  355. mtebc(pb0cr, ebc0_cs0_bxcr_value);
  356. mtebc(pb1ap, ebc0_cs1_bxap_value);
  357. mtebc(pb1cr, ebc0_cs1_bxcr_value);
  358. mtebc(pb2ap, ebc0_cs2_bxap_value);
  359. mtebc(pb2cr, ebc0_cs2_bxcr_value);
  360. }
  361. static void early_init_UIC(void)
  362. {
  363. /*
  364. * Initialise UIC registers. Clear all interrupts. Disable all
  365. * interrupts.
  366. * Set critical interrupt values. Set interrupt polarities. Set
  367. * interrupt trigger levels. Make bit 0 High priority. Clear all
  368. * interrupts again.
  369. */
  370. mtdcr(uic3sr, 0xffffffff); /* Clear all interrupts */
  371. mtdcr(uic3er, 0x00000000); /* disable all interrupts */
  372. mtdcr(uic3cr, 0x00000000); /* Set Critical / Non Critical
  373. * interrupts */
  374. mtdcr(uic3pr, 0xffffffff); /* Set Interrupt Polarities */
  375. mtdcr(uic3tr, 0x001fffff); /* Set Interrupt Trigger Levels */
  376. mtdcr(uic3vr, 0x00000000); /* int31 highest, base=0x000 */
  377. mtdcr(uic3sr, 0xffffffff); /* clear all interrupts */
  378. mtdcr(uic2sr, 0xffffffff); /* Clear all interrupts */
  379. mtdcr(uic2er, 0x00000000); /* disable all interrupts */
  380. mtdcr(uic2cr, 0x00000000); /* Set Critical / Non Critical
  381. * interrupts */
  382. mtdcr(uic2pr, 0xebebebff); /* Set Interrupt Polarities */
  383. mtdcr(uic2tr, 0x74747400); /* Set Interrupt Trigger Levels */
  384. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  385. mtdcr(uic2sr, 0xffffffff); /* clear all interrupts */
  386. mtdcr(uic1sr, 0xffffffff); /* Clear all interrupts */
  387. mtdcr(uic1er, 0x00000000); /* disable all interrupts */
  388. mtdcr(uic1cr, 0x00000000); /* Set Critical / Non Critical
  389. * interrupts */
  390. mtdcr(uic1pr, 0xffffffff); /* Set Interrupt Polarities */
  391. mtdcr(uic1tr, 0x001fc0ff); /* Set Interrupt Trigger Levels */
  392. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
  393. mtdcr(uic1sr, 0xffffffff); /* clear all interrupts */
  394. mtdcr(uic0sr, 0xffffffff); /* Clear all interrupts */
  395. mtdcr(uic0er, 0x00000000); /* disable all interrupts excepted
  396. * cascade to be checked */
  397. mtdcr(uic0cr, 0x00104001); /* Set Critical / Non Critical
  398. * interrupts */
  399. mtdcr(uic0pr, 0xffffffff); /* Set Interrupt Polarities */
  400. mtdcr(uic0tr, 0x000f003c); /* Set Interrupt Trigger Levels */
  401. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
  402. mtdcr(uic0sr, 0xffffffff); /* clear all interrupts */
  403. }