tqm5200.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. #ifndef CFG_RAMBOOT
  38. static void sdram_start (int hi_addr)
  39. {
  40. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  41. /* unlock mode register */
  42. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  43. hi_addr_bit;
  44. __asm__ volatile ("sync");
  45. /* precharge all banks */
  46. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  47. hi_addr_bit;
  48. __asm__ volatile ("sync");
  49. #if SDRAM_DDR
  50. /* set mode register: extended mode */
  51. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  52. __asm__ volatile ("sync");
  53. /* set mode register: reset DLL */
  54. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  55. __asm__ volatile ("sync");
  56. #endif
  57. /* precharge all banks */
  58. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  59. hi_addr_bit;
  60. __asm__ volatile ("sync");
  61. /* auto refresh */
  62. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  63. hi_addr_bit;
  64. __asm__ volatile ("sync");
  65. /* set mode register */
  66. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  67. __asm__ volatile ("sync");
  68. /* normal operation */
  69. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  70. __asm__ volatile ("sync");
  71. }
  72. #endif
  73. /*
  74. * ATTENTION: Although partially referenced initdram does NOT make real use
  75. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  76. * is something else than 0x00000000.
  77. */
  78. #if defined(CONFIG_MPC5200)
  79. long int initdram (int board_type)
  80. {
  81. ulong dramsize = 0;
  82. ulong dramsize2 = 0;
  83. #ifndef CFG_RAMBOOT
  84. ulong test1, test2;
  85. /* setup SDRAM chip selects */
  86. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  87. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  88. __asm__ volatile ("sync");
  89. /* setup config registers */
  90. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  91. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  92. __asm__ volatile ("sync");
  93. #if SDRAM_DDR
  94. /* set tap delay */
  95. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  96. __asm__ volatile ("sync");
  97. #endif
  98. /* find RAM size using SDRAM CS0 only */
  99. sdram_start(0);
  100. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  101. sdram_start(1);
  102. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  103. if (test1 > test2) {
  104. sdram_start(0);
  105. dramsize = test1;
  106. } else {
  107. dramsize = test2;
  108. }
  109. /* memory smaller than 1MB is impossible */
  110. if (dramsize < (1 << 20)) {
  111. dramsize = 0;
  112. }
  113. /* set SDRAM CS0 size according to the amount of RAM found */
  114. if (dramsize > 0) {
  115. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  116. __builtin_ffs(dramsize >> 20) - 1;
  117. } else {
  118. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  119. }
  120. /* let SDRAM CS1 start right after CS0 */
  121. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
  122. /* find RAM size using SDRAM CS1 only */
  123. sdram_start(0);
  124. test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
  125. sdram_start(1);
  126. test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
  127. if (test1 > test2) {
  128. sdram_start(0);
  129. dramsize2 = test1;
  130. } else {
  131. dramsize2 = test2;
  132. }
  133. /* memory smaller than 1MB is impossible */
  134. if (dramsize2 < (1 << 20)) {
  135. dramsize2 = 0;
  136. }
  137. /* set SDRAM CS1 size according to the amount of RAM found */
  138. if (dramsize2 > 0) {
  139. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  140. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  141. } else {
  142. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  143. }
  144. #else /* CFG_RAMBOOT */
  145. /* retrieve size of memory connected to SDRAM CS0 */
  146. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  147. if (dramsize >= 0x13) {
  148. dramsize = (1 << (dramsize - 0x13)) << 20;
  149. } else {
  150. dramsize = 0;
  151. }
  152. /* retrieve size of memory connected to SDRAM CS1 */
  153. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  154. if (dramsize2 >= 0x13) {
  155. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  156. } else {
  157. dramsize2 = 0;
  158. }
  159. #endif /* CFG_RAMBOOT */
  160. /* return dramsize + dramsize2; */
  161. return dramsize;
  162. }
  163. #elif defined(CONFIG_MGT5100)
  164. long int initdram (int board_type)
  165. {
  166. ulong dramsize = 0;
  167. #ifndef CFG_RAMBOOT
  168. ulong test1, test2;
  169. /* setup and enable SDRAM chip selects */
  170. *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
  171. *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
  172. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  173. __asm__ volatile ("sync");
  174. /* setup config registers */
  175. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  176. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  177. /* address select register */
  178. *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
  179. __asm__ volatile ("sync");
  180. /* find RAM size */
  181. sdram_start(0);
  182. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  183. sdram_start(1);
  184. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  185. if (test1 > test2) {
  186. sdram_start(0);
  187. dramsize = test1;
  188. } else {
  189. dramsize = test2;
  190. }
  191. /* set SDRAM end address according to size */
  192. *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
  193. #else /* CFG_RAMBOOT */
  194. /* Retrieve amount of SDRAM available */
  195. dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
  196. #endif /* CFG_RAMBOOT */
  197. return dramsize;
  198. }
  199. #else
  200. #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
  201. #endif
  202. int checkboard (void)
  203. {
  204. #if defined (CONFIG_TQM5200_AA)
  205. puts ("Board: TQM5200-AA (TQ-Systems GmbH)\n");
  206. #endif
  207. #if defined (CONFIG_TQM5200_AB)
  208. puts ("Board: TQM5200-AB (TQ-Systems GmbH)\n");
  209. #endif
  210. #if defined (CONFIG_TQM5200_AC)
  211. puts ("Board: TQM5200-AC (TQ-Systems GmbH)\n");
  212. #endif
  213. return 0;
  214. }
  215. void flash_preinit(void)
  216. {
  217. /*
  218. * Now, when we are in RAM, enable flash write
  219. * access for detection process.
  220. * Note that CS_BOOT cannot be cleared when
  221. * executing in flash.
  222. */
  223. #if defined(CONFIG_MGT5100)
  224. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  225. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  226. #endif
  227. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  228. }
  229. #ifdef CONFIG_PCI
  230. static struct pci_controller hose;
  231. extern void pci_mpc5xxx_init(struct pci_controller *);
  232. void pci_init_board(void)
  233. {
  234. pci_mpc5xxx_init(&hose);
  235. }
  236. #endif
  237. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  238. #if defined (CONFIG_MINIFAP)
  239. #define SM501_POWER_MODE0_GATE 0x00000040UL
  240. #define SM501_POWER_MODE1_GATE 0x00000048UL
  241. #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
  242. #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
  243. #define SM501_GPIO_DATA_HIGH 0x00010004UL
  244. #define SM501_GPIO_51 0x00080000UL
  245. #else
  246. #define GPIO_PSC1_4 0x01000000UL
  247. #endif
  248. void init_ide_reset (void)
  249. {
  250. debug ("init_ide_reset\n");
  251. #if defined (CONFIG_MINIFAP)
  252. /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
  253. /* enable GPIO control (in both power modes) */
  254. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
  255. POWER_MODE_GATE_GPIO_PWM_I2C;
  256. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
  257. POWER_MODE_GATE_GPIO_PWM_I2C;
  258. /* configure GPIO51 as output */
  259. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
  260. SM501_GPIO_51;
  261. #else
  262. /* Configure PSC1_4 as GPIO output for ATA reset */
  263. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  264. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  265. #endif
  266. }
  267. void ide_set_reset (int idereset)
  268. {
  269. debug ("ide_reset(%d)\n", idereset);
  270. #if defined (CONFIG_MINIFAP)
  271. if (idereset) {
  272. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
  273. ~SM501_GPIO_51;
  274. } else {
  275. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
  276. SM501_GPIO_51;
  277. }
  278. #else
  279. if (idereset) {
  280. *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
  281. } else {
  282. *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
  283. }
  284. #endif
  285. }
  286. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
  287. #ifdef CONFIG_POST
  288. /*
  289. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  290. * is left open, no keypress is detected.
  291. */
  292. int post_hotkeys_pressed(void)
  293. {
  294. struct mpc5xxx_gpio *gpio;
  295. gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
  296. /*
  297. * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
  298. * CODEC or UART mode. Consumer IrDA should still be possible.
  299. */
  300. gpio->port_config &= ~(0x07000000);
  301. gpio->port_config |= 0x03000000;
  302. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  303. gpio->simple_gpioe |= 0x20000000;
  304. /* Configure GPIO_IRDA_1 as input */
  305. gpio->simple_ddr &= ~(0x20000000);
  306. return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
  307. }
  308. #endif
  309. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  310. void post_word_store (ulong a)
  311. {
  312. volatile ulong *save_addr =
  313. (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
  314. *save_addr = a;
  315. }
  316. ulong post_word_load (void)
  317. {
  318. volatile ulong *save_addr =
  319. (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
  320. return *save_addr;
  321. }
  322. #endif /* CONFIG_POST || CONFIG_LOGBUFFER*/