bc3450.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. * (C) Copyright 2003-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2004-2005
  9. * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  10. *
  11. * (C) Copyright 2006
  12. * Stefan Strobl, GERSYS GmbH, stefan.strobl@gersys.de
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. #include <mpc5xxx.h>
  34. #include <pci.h>
  35. #include <netdev.h>
  36. #ifdef CONFIG_VIDEO_SM501
  37. #include <sm501.h>
  38. #endif
  39. #if defined(CONFIG_MPC5200_DDR)
  40. #include "mt46v16m16-75.h"
  41. #else
  42. #include "mt48lc16m16a2-75.h"
  43. #endif
  44. #ifdef CONFIG_RTC_MPC5200
  45. #include <rtc.h>
  46. #endif
  47. #ifdef CONFIG_PS2MULT
  48. void ps2mult_early_init(void);
  49. #endif
  50. #ifndef CONFIG_SYS_RAMBOOT
  51. static void sdram_start (int hi_addr)
  52. {
  53. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  54. /* unlock mode register */
  55. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  56. hi_addr_bit;
  57. __asm__ volatile ("sync");
  58. /* precharge all banks */
  59. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  60. hi_addr_bit;
  61. __asm__ volatile ("sync");
  62. #if SDRAM_DDR
  63. /* set mode register: extended mode */
  64. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  65. __asm__ volatile ("sync");
  66. /* set mode register: reset DLL */
  67. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  68. __asm__ volatile ("sync");
  69. #endif
  70. /* precharge all banks */
  71. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  72. hi_addr_bit;
  73. __asm__ volatile ("sync");
  74. /* auto refresh */
  75. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  76. hi_addr_bit;
  77. __asm__ volatile ("sync");
  78. /* set mode register */
  79. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  80. __asm__ volatile ("sync");
  81. /* normal operation */
  82. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  83. __asm__ volatile ("sync");
  84. }
  85. #endif
  86. /*
  87. * ATTENTION: Although partially referenced initdram does NOT make real use
  88. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  89. * is something else than 0x00000000.
  90. */
  91. phys_size_t initdram (int board_type)
  92. {
  93. ulong dramsize = 0;
  94. ulong dramsize2 = 0;
  95. #ifndef CONFIG_SYS_RAMBOOT
  96. ulong test1, test2;
  97. /* setup SDRAM chip selects */
  98. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  99. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  100. __asm__ volatile ("sync");
  101. /* setup config registers */
  102. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  103. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  104. __asm__ volatile ("sync");
  105. #if SDRAM_DDR
  106. /* set tap delay */
  107. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  108. __asm__ volatile ("sync");
  109. #endif
  110. /* find RAM size using SDRAM CS0 only */
  111. sdram_start(0);
  112. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  113. sdram_start(1);
  114. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  115. if (test1 > test2) {
  116. sdram_start(0);
  117. dramsize = test1;
  118. } else {
  119. dramsize = test2;
  120. }
  121. /* memory smaller than 1MB is impossible */
  122. if (dramsize < (1 << 20)) {
  123. dramsize = 0;
  124. }
  125. /* set SDRAM CS0 size according to the amount of RAM found */
  126. if (dramsize > 0) {
  127. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  128. __builtin_ffs(dramsize >> 20) - 1;
  129. } else {
  130. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  131. }
  132. /* let SDRAM CS1 start right after CS0 */
  133. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
  134. /* find RAM size using SDRAM CS1 only */
  135. sdram_start(0);
  136. test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  137. sdram_start(1);
  138. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  139. if (test1 > test2) {
  140. sdram_start(0);
  141. dramsize2 = test1;
  142. } else {
  143. dramsize2 = test2;
  144. }
  145. /* memory smaller than 1MB is impossible */
  146. if (dramsize2 < (1 << 20)) {
  147. dramsize2 = 0;
  148. }
  149. /* set SDRAM CS1 size according to the amount of RAM found */
  150. if (dramsize2 > 0) {
  151. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  152. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  153. } else {
  154. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  155. }
  156. #else /* CONFIG_SYS_RAMBOOT */
  157. /* retrieve size of memory connected to SDRAM CS0 */
  158. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  159. if (dramsize >= 0x13) {
  160. dramsize = (1 << (dramsize - 0x13)) << 20;
  161. } else {
  162. dramsize = 0;
  163. }
  164. /* retrieve size of memory connected to SDRAM CS1 */
  165. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  166. if (dramsize2 >= 0x13) {
  167. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  168. } else {
  169. dramsize2 = 0;
  170. }
  171. #endif /* CONFIG_SYS_RAMBOOT */
  172. return dramsize;
  173. }
  174. int checkboard (void)
  175. {
  176. #if defined (CONFIG_TQM5200)
  177. puts ("Board: TQM5200 (TQ-Components GmbH)\n");
  178. #endif
  179. #if defined (CONFIG_BC3450)
  180. puts ("Dev: GERSYS BC3450\n");
  181. #endif
  182. return 0;
  183. }
  184. void flash_preinit(void)
  185. {
  186. /*
  187. * Now, when we are in RAM, enable flash write
  188. * access for detection process.
  189. * Note that CS_BOOT cannot be cleared when
  190. * executing in flash.
  191. */
  192. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  193. }
  194. #ifdef CONFIG_PCI
  195. static struct pci_controller hose;
  196. extern void pci_mpc5xxx_init(struct pci_controller *);
  197. void pci_init_board(void)
  198. {
  199. pci_mpc5xxx_init(&hose);
  200. }
  201. #endif
  202. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  203. void init_ide_reset (void)
  204. {
  205. debug ("init_ide_reset\n");
  206. /* Configure PSC1_4 as GPIO output for ATA reset */
  207. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  208. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  209. }
  210. void ide_set_reset (int idereset)
  211. {
  212. debug ("ide_reset(%d)\n", idereset);
  213. if (idereset) {
  214. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  215. } else {
  216. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  217. }
  218. }
  219. #endif
  220. #ifdef CONFIG_POST
  221. /*
  222. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  223. * is left open, no keypress is detected.
  224. */
  225. int post_hotkeys_pressed(void)
  226. {
  227. struct mpc5xxx_gpio *gpio;
  228. gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
  229. /*
  230. * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
  231. * CODEC or UART mode. Consumer IrDA should still be possible.
  232. */
  233. gpio->port_config &= ~(0x07000000);
  234. gpio->port_config |= 0x03000000;
  235. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  236. gpio->simple_gpioe |= 0x20000000;
  237. /* Configure GPIO_IRDA_1 as input */
  238. gpio->simple_ddr &= ~(0x20000000);
  239. return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
  240. }
  241. #endif
  242. #ifdef CONFIG_BOARD_EARLY_INIT_R
  243. int board_early_init_r (void)
  244. {
  245. #ifdef CONFIG_RTC_MPC5200
  246. struct rtc_time t;
  247. /* set to Wed Dec 31 19:00:00 1969 */
  248. t.tm_sec = t.tm_min = 0;
  249. t.tm_hour = 19;
  250. t.tm_mday = 31;
  251. t.tm_mon = 12;
  252. t.tm_year = 1969;
  253. t.tm_wday = 3;
  254. rtc_set(&t);
  255. #endif /* CONFIG_RTC_MPC5200 */
  256. #ifdef CONFIG_PS2MULT
  257. ps2mult_early_init();
  258. #endif /* CONFIG_PS2MULT */
  259. return (0);
  260. }
  261. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  262. int last_stage_init (void)
  263. {
  264. /*
  265. * auto scan for really existing devices and re-set chip select
  266. * configuration.
  267. */
  268. u16 save, tmp;
  269. int restore;
  270. /*
  271. * Check for SRAM and SRAM size
  272. */
  273. /* save original SRAM content */
  274. save = *(volatile u16 *)CONFIG_SYS_CS2_START;
  275. restore = 1;
  276. /* write test pattern to SRAM */
  277. *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
  278. __asm__ volatile ("sync");
  279. /*
  280. * Put a different pattern on the data lines: otherwise they may float
  281. * long enough to read back what we wrote.
  282. */
  283. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  284. if (tmp == 0xA5A5)
  285. puts ("!! possible error in SRAM detection\n");
  286. if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
  287. /* no SRAM at all, disable cs */
  288. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
  289. *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
  290. *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
  291. restore = 0;
  292. __asm__ volatile ("sync");
  293. } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
  294. /* make sure that we access a mirrored address */
  295. *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
  296. __asm__ volatile ("sync");
  297. if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
  298. /* SRAM size = 512 kByte */
  299. *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
  300. 0x80000);
  301. __asm__ volatile ("sync");
  302. puts ("SRAM: 512 kB\n");
  303. }
  304. else
  305. puts ("!! possible error in SRAM detection\n");
  306. } else {
  307. puts ("SRAM: 1 MB\n");
  308. }
  309. /* restore origianl SRAM content */
  310. if (restore) {
  311. *(volatile u16 *)CONFIG_SYS_CS2_START = save;
  312. __asm__ volatile ("sync");
  313. }
  314. /*
  315. * Check for Grafic Controller
  316. */
  317. /* save origianl FB content */
  318. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  319. restore = 1;
  320. /* write test pattern to FB memory */
  321. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  322. __asm__ volatile ("sync");
  323. /*
  324. * Put a different pattern on the data lines: otherwise they may float
  325. * long enough to read back what we wrote.
  326. */
  327. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  328. if (tmp == 0xA5A5)
  329. puts ("!! possible error in grafic controller detection\n");
  330. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  331. /* no grafic controller at all, disable cs */
  332. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
  333. *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
  334. *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
  335. restore = 0;
  336. __asm__ volatile ("sync");
  337. } else {
  338. puts ("VGA: SMI501 (Voyager) with 8 MB\n");
  339. }
  340. /* restore origianl FB content */
  341. if (restore) {
  342. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  343. __asm__ volatile ("sync");
  344. }
  345. return 0;
  346. }
  347. #ifdef CONFIG_VIDEO_SM501
  348. #define DISPLAY_WIDTH 640
  349. #define DISPLAY_HEIGHT 480
  350. #ifdef CONFIG_VIDEO_SM501_8BPP
  351. #error CONFIG_VIDEO_SM501_8BPP not supported.
  352. #endif /* CONFIG_VIDEO_SM501_8BPP */
  353. #ifdef CONFIG_VIDEO_SM501_16BPP
  354. #error CONFIG_VIDEO_SM501_16BPP not supported.
  355. #endif /* CONFIG_VIDEO_SM501_16BPP */
  356. #ifdef CONFIG_VIDEO_SM501_32BPP
  357. static const SMI_REGS init_regs [] =
  358. {
  359. #if defined (CONFIG_BC3450_FP) && !defined (CONFIG_BC3450_CRT)
  360. /* FP only */
  361. {0x00004, 0x0},
  362. {0x00048, 0x00021807},
  363. {0x0004C, 0x091a0a01},
  364. {0x00054, 0x1},
  365. {0x00040, 0x00021807},
  366. {0x00044, 0x091a0a01},
  367. {0x00054, 0x0},
  368. {0x80000, 0x01013106},
  369. {0x80004, 0xc428bb17},
  370. {0x80000, 0x03013106},
  371. {0x8000C, 0x00000000},
  372. {0x80010, 0x0a000a00},
  373. {0x80014, 0x02800000},
  374. {0x80018, 0x01e00000},
  375. {0x8001C, 0x00000000},
  376. {0x80020, 0x01e00280},
  377. {0x80024, 0x02fa027f},
  378. {0x80028, 0x004a028b},
  379. {0x8002C, 0x020c01df},
  380. {0x80030, 0x000201e9},
  381. {0x80200, 0x00010200},
  382. {0x80000, 0x0f013106},
  383. #elif defined (CONFIG_BC3450_CRT) && !defined (CONFIG_BC3450_FP)
  384. /* CRT only */
  385. {0x00004, 0x0},
  386. {0x00048, 0x00021807},
  387. {0x0004C, 0x10090a01},
  388. {0x00054, 0x1},
  389. {0x00040, 0x00021807},
  390. {0x00044, 0x10090a01},
  391. {0x00054, 0x0},
  392. {0x80200, 0x00010000},
  393. {0x80204, 0x0},
  394. {0x80208, 0x0A000A00},
  395. {0x8020C, 0x02fa027f},
  396. {0x80210, 0x004a028b},
  397. {0x80214, 0x020c01df},
  398. {0x80218, 0x000201e9},
  399. {0x80200, 0x00013306},
  400. #else /* panel + CRT */
  401. {0x00004, 0x0},
  402. {0x00048, 0x00021807},
  403. {0x0004C, 0x091a0a01},
  404. {0x00054, 0x1},
  405. {0x00040, 0x00021807},
  406. {0x00044, 0x091a0a01},
  407. {0x00054, 0x0},
  408. {0x80000, 0x0f013106},
  409. {0x80004, 0xc428bb17},
  410. {0x8000C, 0x00000000},
  411. {0x80010, 0x0a000a00},
  412. {0x80014, 0x02800000},
  413. {0x80018, 0x01e00000},
  414. {0x8001C, 0x00000000},
  415. {0x80020, 0x01e00280},
  416. {0x80024, 0x02fa027f},
  417. {0x80028, 0x004a028b},
  418. {0x8002C, 0x020c01df},
  419. {0x80030, 0x000201e9},
  420. {0x80200, 0x00010000},
  421. #endif
  422. {0, 0}
  423. };
  424. #endif /* CONFIG_VIDEO_SM501_32BPP */
  425. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  426. /*
  427. * Return text to be printed besides the logo.
  428. */
  429. void video_get_info_str (int line_number, char *info)
  430. {
  431. if (line_number == 1) {
  432. #if defined (CONFIG_TQM5200)
  433. strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
  434. #else
  435. #error No supported board selected
  436. #endif /* CONFIG_TQM5200 */
  437. #if defined (CONFIG_BC3450)
  438. } else if (line_number == 2) {
  439. strcpy (info, " Dev: GERSYS BC3450");
  440. #endif /* CONFIG_BC3450 */
  441. }
  442. else {
  443. info [0] = '\0';
  444. }
  445. }
  446. #endif
  447. /*
  448. * Returns SM501 register base address. First thing called in the
  449. * driver. Checks if SM501 is physically present.
  450. */
  451. unsigned int board_video_init (void)
  452. {
  453. u16 save, tmp;
  454. int restore, ret;
  455. /*
  456. * Check for Grafic Controller
  457. */
  458. /* save origianl FB content */
  459. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  460. restore = 1;
  461. /* write test pattern to FB memory */
  462. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  463. __asm__ volatile ("sync");
  464. /*
  465. * Put a different pattern on the data lines: otherwise they may float
  466. * long enough to read back what we wrote.
  467. */
  468. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  469. if (tmp == 0xA5A5)
  470. puts ("!! possible error in grafic controller detection\n");
  471. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  472. /* no grafic controller found */
  473. restore = 0;
  474. ret = 0;
  475. } else {
  476. ret = SM501_MMIO_BASE;
  477. }
  478. if (restore) {
  479. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  480. __asm__ volatile ("sync");
  481. }
  482. return ret;
  483. }
  484. /*
  485. * Returns SM501 framebuffer address
  486. */
  487. unsigned int board_video_get_fb (void)
  488. {
  489. return SM501_FB_BASE;
  490. }
  491. /*
  492. * Called after initializing the SM501 and before clearing the screen.
  493. */
  494. void board_validate_screen (unsigned int base)
  495. {
  496. }
  497. /*
  498. * Return a pointer to the initialization sequence.
  499. */
  500. const SMI_REGS *board_get_regs (void)
  501. {
  502. return init_regs;
  503. }
  504. int board_get_width (void)
  505. {
  506. return DISPLAY_WIDTH;
  507. }
  508. int board_get_height (void)
  509. {
  510. return DISPLAY_HEIGHT;
  511. }
  512. #endif /* CONFIG_VIDEO_SM501 */
  513. int board_eth_init(bd_t *bis)
  514. {
  515. cpu_eth_init(bis); /* Built in FEC comes first */
  516. return pci_eth_init(bis);
  517. }