tqm5200.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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
  9. * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <mpc5xxx.h>
  31. #include <pci.h>
  32. #if defined(CONFIG_MPC5200_DDR)
  33. #include "mt46v16m16-75.h"
  34. #else
  35. #include "mt48lc16m16a2-75.h"
  36. #endif
  37. #ifdef CONFIG_PS2MULT
  38. void ps2mult_early_init(void);
  39. #endif
  40. #ifndef CFG_RAMBOOT
  41. static void sdram_start (int hi_addr)
  42. {
  43. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  44. /* unlock mode register */
  45. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  46. hi_addr_bit;
  47. __asm__ volatile ("sync");
  48. /* precharge all banks */
  49. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  50. hi_addr_bit;
  51. __asm__ volatile ("sync");
  52. #if SDRAM_DDR
  53. /* set mode register: extended mode */
  54. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  55. __asm__ volatile ("sync");
  56. /* set mode register: reset DLL */
  57. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  58. __asm__ volatile ("sync");
  59. #endif
  60. /* precharge all banks */
  61. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  62. hi_addr_bit;
  63. __asm__ volatile ("sync");
  64. /* auto refresh */
  65. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  66. hi_addr_bit;
  67. __asm__ volatile ("sync");
  68. /* set mode register */
  69. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  70. __asm__ volatile ("sync");
  71. /* normal operation */
  72. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  73. __asm__ volatile ("sync");
  74. }
  75. #endif
  76. /*
  77. * ATTENTION: Although partially referenced initdram does NOT make real use
  78. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  79. * is something else than 0x00000000.
  80. */
  81. #if defined(CONFIG_MPC5200)
  82. long int initdram (int board_type)
  83. {
  84. ulong dramsize = 0;
  85. ulong dramsize2 = 0;
  86. #ifndef CFG_RAMBOOT
  87. ulong test1, test2;
  88. /* setup SDRAM chip selects */
  89. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  90. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  91. __asm__ volatile ("sync");
  92. /* setup config registers */
  93. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  94. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  95. __asm__ volatile ("sync");
  96. #if SDRAM_DDR
  97. /* set tap delay */
  98. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  99. __asm__ volatile ("sync");
  100. #endif
  101. /* find RAM size using SDRAM CS0 only */
  102. sdram_start(0);
  103. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  104. sdram_start(1);
  105. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  106. if (test1 > test2) {
  107. sdram_start(0);
  108. dramsize = test1;
  109. } else {
  110. dramsize = test2;
  111. }
  112. /* memory smaller than 1MB is impossible */
  113. if (dramsize < (1 << 20)) {
  114. dramsize = 0;
  115. }
  116. /* set SDRAM CS0 size according to the amount of RAM found */
  117. if (dramsize > 0) {
  118. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  119. __builtin_ffs(dramsize >> 20) - 1;
  120. } else {
  121. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  122. }
  123. /* let SDRAM CS1 start right after CS0 */
  124. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
  125. /* find RAM size using SDRAM CS1 only */
  126. sdram_start(0);
  127. test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
  128. sdram_start(1);
  129. test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
  130. if (test1 > test2) {
  131. sdram_start(0);
  132. dramsize2 = test1;
  133. } else {
  134. dramsize2 = test2;
  135. }
  136. /* memory smaller than 1MB is impossible */
  137. if (dramsize2 < (1 << 20)) {
  138. dramsize2 = 0;
  139. }
  140. /* set SDRAM CS1 size according to the amount of RAM found */
  141. if (dramsize2 > 0) {
  142. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  143. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  144. } else {
  145. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  146. }
  147. #else /* CFG_RAMBOOT */
  148. /* retrieve size of memory connected to SDRAM CS0 */
  149. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  150. if (dramsize >= 0x13) {
  151. dramsize = (1 << (dramsize - 0x13)) << 20;
  152. } else {
  153. dramsize = 0;
  154. }
  155. /* retrieve size of memory connected to SDRAM CS1 */
  156. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  157. if (dramsize2 >= 0x13) {
  158. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  159. } else {
  160. dramsize2 = 0;
  161. }
  162. #endif /* CFG_RAMBOOT */
  163. /* return dramsize + dramsize2; */
  164. return dramsize;
  165. }
  166. #elif defined(CONFIG_MGT5100)
  167. long int initdram (int board_type)
  168. {
  169. ulong dramsize = 0;
  170. #ifndef CFG_RAMBOOT
  171. ulong test1, test2;
  172. /* setup and enable SDRAM chip selects */
  173. *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
  174. *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
  175. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  176. __asm__ volatile ("sync");
  177. /* setup config registers */
  178. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  179. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  180. /* address select register */
  181. *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
  182. __asm__ volatile ("sync");
  183. /* find RAM size */
  184. sdram_start(0);
  185. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  186. sdram_start(1);
  187. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  188. if (test1 > test2) {
  189. sdram_start(0);
  190. dramsize = test1;
  191. } else {
  192. dramsize = test2;
  193. }
  194. /* set SDRAM end address according to size */
  195. *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
  196. #else /* CFG_RAMBOOT */
  197. /* Retrieve amount of SDRAM available */
  198. dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
  199. #endif /* CFG_RAMBOOT */
  200. return dramsize;
  201. }
  202. #else
  203. #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
  204. #endif
  205. int checkboard (void)
  206. {
  207. #if defined (CONFIG_TQM5200_AA)
  208. puts ("Board: TQM5200-AA (TQ-Systems GmbH)\n");
  209. #elif defined (CONFIG_TQM5200_AB)
  210. puts ("Board: TQM5200-AB (TQ-Systems GmbH)\n");
  211. #elif defined (CONFIG_TQM5200_AC)
  212. puts ("Board: TQM5200-AC (TQ-Systems GmbH)\n");
  213. #elif defined (CONFIG_TQM5200)
  214. puts ("Board: TQM5200 (TQ-Systems GmbH)\n");
  215. #endif
  216. #if defined (CONFIG_STK52XX)
  217. puts (" on a STK52XX baseboard\n");
  218. #endif
  219. return 0;
  220. }
  221. void flash_preinit(void)
  222. {
  223. /*
  224. * Now, when we are in RAM, enable flash write
  225. * access for detection process.
  226. * Note that CS_BOOT cannot be cleared when
  227. * executing in flash.
  228. */
  229. #if defined(CONFIG_MGT5100)
  230. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  231. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  232. #endif
  233. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  234. }
  235. #ifdef CONFIG_PCI
  236. static struct pci_controller hose;
  237. extern void pci_mpc5xxx_init(struct pci_controller *);
  238. void pci_init_board(void)
  239. {
  240. pci_mpc5xxx_init(&hose);
  241. }
  242. #endif
  243. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  244. #if defined (CONFIG_MINIFAP)
  245. #define SM501_POWER_MODE0_GATE 0x00000040UL
  246. #define SM501_POWER_MODE1_GATE 0x00000048UL
  247. #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
  248. #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
  249. #define SM501_GPIO_DATA_HIGH 0x00010004UL
  250. #define SM501_GPIO_51 0x00080000UL
  251. #else
  252. #define GPIO_PSC1_4 0x01000000UL
  253. #endif
  254. void init_ide_reset (void)
  255. {
  256. debug ("init_ide_reset\n");
  257. #if defined (CONFIG_MINIFAP)
  258. /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
  259. /* enable GPIO control (in both power modes) */
  260. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
  261. POWER_MODE_GATE_GPIO_PWM_I2C;
  262. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
  263. POWER_MODE_GATE_GPIO_PWM_I2C;
  264. /* configure GPIO51 as output */
  265. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
  266. SM501_GPIO_51;
  267. #else
  268. /* Configure PSC1_4 as GPIO output for ATA reset */
  269. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  270. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  271. #endif
  272. }
  273. void ide_set_reset (int idereset)
  274. {
  275. debug ("ide_reset(%d)\n", idereset);
  276. #if defined (CONFIG_MINIFAP)
  277. if (idereset) {
  278. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
  279. ~SM501_GPIO_51;
  280. } else {
  281. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
  282. SM501_GPIO_51;
  283. }
  284. #else
  285. if (idereset) {
  286. *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
  287. } else {
  288. *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
  289. }
  290. #endif
  291. }
  292. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
  293. #ifdef CONFIG_POST
  294. /*
  295. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  296. * is left open, no keypress is detected.
  297. */
  298. int post_hotkeys_pressed(void)
  299. {
  300. struct mpc5xxx_gpio *gpio;
  301. gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
  302. /*
  303. * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
  304. * CODEC or UART mode. Consumer IrDA should still be possible.
  305. */
  306. gpio->port_config &= ~(0x07000000);
  307. gpio->port_config |= 0x03000000;
  308. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  309. gpio->simple_gpioe |= 0x20000000;
  310. /* Configure GPIO_IRDA_1 as input */
  311. gpio->simple_ddr &= ~(0x20000000);
  312. return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
  313. }
  314. #endif
  315. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  316. void post_word_store (ulong a)
  317. {
  318. volatile ulong *save_addr =
  319. (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
  320. *save_addr = a;
  321. }
  322. ulong post_word_load (void)
  323. {
  324. volatile ulong *save_addr =
  325. (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
  326. return *save_addr;
  327. }
  328. #endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
  329. #ifdef CONFIG_PS2MULT
  330. #ifdef CONFIG_BOARD_EARLY_INIT_R
  331. int board_early_init_r (void)
  332. {
  333. ps2mult_early_init();
  334. return (0);
  335. }
  336. #endif
  337. #endif /* CONFIG_PS2MULT */
  338. #if defined(CONFIG_CS_AUTOCONF)
  339. int last_stage_init (void)
  340. {
  341. /*
  342. * auto scan for really existing devices and re-set chip select
  343. * configuration.
  344. */
  345. u16 save, tmp;
  346. int restore;
  347. /*
  348. * Check for SRAM and SRAM size
  349. */
  350. /* save origianl SRAM content */
  351. save = *(volatile u16 *)CFG_CS2_START;
  352. restore = 1;
  353. /* write test pattern to SRAM */
  354. *(volatile u16 *)CFG_CS2_START = 0xA5A5;
  355. __asm__ volatile ("sync");
  356. /*
  357. * Put a different pattern on the data lines: otherwise they may float
  358. * long enough to read back what we wrote.
  359. */
  360. tmp = *(volatile u16 *)CFG_FLASH_BASE;
  361. if (tmp == 0xA5A5)
  362. puts ("!! possible error in SRAM detection\n");
  363. if (*(volatile u16 *)CFG_CS2_START != 0xA5A5) {
  364. /* no SRAM at all, disable cs */
  365. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
  366. *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
  367. *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
  368. restore = 0;
  369. __asm__ volatile ("sync");
  370. }
  371. else if (*(volatile u16 *)(CFG_CS2_START + (1<<19)) == 0xA5A5) {
  372. /* make sure that we access a mirrored address */
  373. *(volatile u16 *)CFG_CS2_START = 0x1111;
  374. __asm__ volatile ("sync");
  375. if (*(volatile u16 *)(CFG_CS2_START + (1<<19)) == 0x1111) {
  376. /* SRAM size = 512 kByte */
  377. *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CFG_CS2_START,
  378. 0x80000);
  379. __asm__ volatile ("sync");
  380. puts ("SRAM: 512 kB\n");
  381. }
  382. else
  383. puts ("!! possible error in SRAM detection\n");
  384. }
  385. else {
  386. puts ("SRAM: 1 MB\n");
  387. }
  388. /* restore origianl SRAM content */
  389. if (restore) {
  390. *(volatile u16 *)CFG_CS2_START = save;
  391. __asm__ volatile ("sync");
  392. }
  393. /*
  394. * Check for Grafic Controller
  395. */
  396. /* save origianl FB content */
  397. save = *(volatile u16 *)CFG_CS1_START;
  398. restore = 1;
  399. /* write test pattern to FB memory */
  400. *(volatile u16 *)CFG_CS1_START = 0xA5A5;
  401. __asm__ volatile ("sync");
  402. /*
  403. * Put a different pattern on the data lines: otherwise they may float
  404. * long enough to read back what we wrote.
  405. */
  406. tmp = *(volatile u16 *)CFG_FLASH_BASE;
  407. if (tmp == 0xA5A5)
  408. puts ("!! possible error in grafic controller detection\n");
  409. if (*(volatile u16 *)CFG_CS1_START != 0xA5A5) {
  410. /* no grafic controller at all, disable cs */
  411. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
  412. *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
  413. *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
  414. restore = 0;
  415. __asm__ volatile ("sync");
  416. }
  417. else {
  418. puts ("VGA: SMI501 (Voyager) with 8 MB\n");
  419. }
  420. /* restore origianl FB content */
  421. if (restore) {
  422. *(volatile u16 *)CFG_CS1_START = save;
  423. __asm__ volatile ("sync");
  424. }
  425. return 0;
  426. }
  427. #endif /* CONFIG_CS_AUTOCONF */