ccm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * (C) Copyright 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc8xx.h>
  25. #include <commproc.h>
  26. #include <command.h>
  27. /* ------------------------------------------------------------------------- */
  28. static long int dram_size (long int, long int *, long int);
  29. void can_driver_enable (void);
  30. void can_driver_disable (void);
  31. int fpga_init(void);
  32. /* ------------------------------------------------------------------------- */
  33. #define _NOT_USED_ 0xFFFFFFFF
  34. const uint sdram_table[] =
  35. {
  36. /*
  37. * Single Read. (Offset 0 in UPMA RAM)
  38. */
  39. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
  40. 0x1FF5FC47, /* last */
  41. /*
  42. * SDRAM Initialization (offset 5 in UPMA RAM)
  43. *
  44. * This is no UPM entry point. The following definition uses
  45. * the remaining space to establish an initialization
  46. * sequence, which is executed by a RUN command.
  47. *
  48. */
  49. 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
  50. /*
  51. * Burst Read. (Offset 8 in UPMA RAM)
  52. */
  53. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  54. 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
  55. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. /*
  58. * Single Write. (Offset 18 in UPMA RAM)
  59. */
  60. 0x1F0DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
  61. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  62. /*
  63. * Burst Write. (Offset 20 in UPMA RAM)
  64. */
  65. 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
  66. 0xF0AFFC00, 0xE1BAFC04, 0x1FF5FC47, /* last */
  67. _NOT_USED_,
  68. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  69. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  70. /*
  71. * Refresh (Offset 30 in UPMA RAM)
  72. */
  73. 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  74. 0xFFFFFC84, 0xFFFFFC07, /* last */
  75. _NOT_USED_, _NOT_USED_,
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. /*
  78. * Exception. (Offset 3c in UPMA RAM)
  79. */
  80. 0x7FFFFC07, /* last */
  81. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  82. };
  83. /* ------------------------------------------------------------------------- */
  84. /*
  85. * Check Board Identity:
  86. *
  87. * Always return 1 (no second DRAM bank since based on TQM8xxL module)
  88. */
  89. int checkboard (void)
  90. {
  91. unsigned char *s;
  92. unsigned char buf[64];
  93. s = (getenv_r ("serial#", buf, sizeof(buf)) > 0) ? buf : NULL;
  94. puts ("Board: Siemens CCM");
  95. if (s) {
  96. puts (" (");
  97. for (; *s; ++s) {
  98. if (*s == ' ')
  99. break;
  100. putc (*s);
  101. }
  102. putc (')');
  103. }
  104. putc ('\n');
  105. return (0);
  106. }
  107. /* ------------------------------------------------------------------------- */
  108. /*
  109. * If Power-On-Reset switch off the Red and Green LED: At reset, the
  110. * data direction registers are cleared and must therefore be restored.
  111. */
  112. #define RSR_CSRS 0x08000000
  113. int power_on_reset(void)
  114. {
  115. /* Test Reset Status Register */
  116. return ((volatile immap_t *)CFG_IMMR)->im_clkrst.car_rsr & RSR_CSRS ? 0:1;
  117. }
  118. #define PB_LED_GREEN 0x10000 /* red LED is on PB.15 */
  119. #define PB_LED_RED 0x20000 /* red LED is on PB.14 */
  120. #define PB_LEDS (PB_LED_GREEN | PB_LED_RED);
  121. static void init_leds (void)
  122. {
  123. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  124. immap->im_cpm.cp_pbpar &= ~PB_LEDS;
  125. immap->im_cpm.cp_pbodr &= ~PB_LEDS;
  126. immap->im_cpm.cp_pbdir |= PB_LEDS;
  127. /* Check stop reset status */
  128. if (power_on_reset()) {
  129. immap->im_cpm.cp_pbdat &= ~PB_LEDS;
  130. }
  131. }
  132. /* ------------------------------------------------------------------------- */
  133. long int initdram (int board_type)
  134. {
  135. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  136. volatile memctl8xx_t *memctl = &immap->im_memctl;
  137. long int size8, size9;
  138. long int size = 0;
  139. unsigned long reg;
  140. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  141. /*
  142. * Preliminary prescaler for refresh (depends on number of
  143. * banks): This value is selected for four cycles every 62.4 us
  144. * with two SDRAM banks or four cycles every 31.2 us with one
  145. * bank. It will be adjusted after memory sizing.
  146. */
  147. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  148. memctl->memc_mar = 0x00000088;
  149. /*
  150. * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
  151. * preliminary addresses - these have to be modified after the
  152. * SDRAM size has been determined.
  153. */
  154. memctl->memc_or2 = CFG_OR2_PRELIM;
  155. memctl->memc_br2 = CFG_BR2_PRELIM;
  156. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  157. udelay(200);
  158. /* perform SDRAM initializsation sequence */
  159. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  160. udelay(1);
  161. memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
  162. udelay(1);
  163. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  164. udelay (1000);
  165. /*
  166. * Check Bank 0 Memory Size for re-configuration
  167. *
  168. * try 8 column mode
  169. */
  170. size8 = dram_size (CFG_MAMR_8COL, (ulong *)SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  171. udelay (1000);
  172. /*
  173. * try 9 column mode
  174. */
  175. size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  176. if (size8 < size9) { /* leave configuration at 9 columns */
  177. size = size9;
  178. /* debug ("SDRAM in 9 column mode: %ld MB\n", size >> 20); */
  179. } else { /* back to 8 columns */
  180. size = size8;
  181. memctl->memc_mamr = CFG_MAMR_8COL;
  182. udelay(500);
  183. /* debug ("SDRAM in 8 column mode: %ld MB\n", size >> 20); */
  184. }
  185. udelay (1000);
  186. /*
  187. * Adjust refresh rate depending on SDRAM type
  188. * For types > 128 MBit leave it at the current (fast) rate
  189. */
  190. if (size < 0x02000000) {
  191. /* reduce to 15.6 us (62.4 us / quad) */
  192. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  193. udelay(1000);
  194. }
  195. /*
  196. * Final mapping
  197. */
  198. memctl->memc_or2 = ((-size) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  199. memctl->memc_br2 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  200. /* adjust refresh rate depending on SDRAM type, one bank */
  201. reg = memctl->memc_mptpr;
  202. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  203. memctl->memc_mptpr = reg;
  204. can_driver_enable ();
  205. init_leds ();
  206. udelay(10000);
  207. return (size);
  208. }
  209. /* ------------------------------------------------------------------------- */
  210. /*
  211. * Warning - both the PUMA load mode and the CAN driver use UPM B,
  212. * so make sure only one of both is active.
  213. */
  214. void can_driver_enable (void)
  215. {
  216. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  217. volatile memctl8xx_t *memctl = &immap->im_memctl;
  218. /* Initialize MBMR */
  219. memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
  220. /* Initialize UPMB for CAN: single read */
  221. memctl->memc_mdr = 0xFFFFC004;
  222. memctl->memc_mcr = 0x0100 | UPMB;
  223. memctl->memc_mdr = 0x0FFFD004;
  224. memctl->memc_mcr = 0x0101 | UPMB;
  225. memctl->memc_mdr = 0x0FFFC000;
  226. memctl->memc_mcr = 0x0102 | UPMB;
  227. memctl->memc_mdr = 0x3FFFC004;
  228. memctl->memc_mcr = 0x0103 | UPMB;
  229. memctl->memc_mdr = 0xFFFFDC05;
  230. memctl->memc_mcr = 0x0104 | UPMB;
  231. /* Initialize UPMB for CAN: single write */
  232. memctl->memc_mdr = 0xFFFCC004;
  233. memctl->memc_mcr = 0x0118 | UPMB;
  234. memctl->memc_mdr = 0xCFFCD004;
  235. memctl->memc_mcr = 0x0119 | UPMB;
  236. memctl->memc_mdr = 0x0FFCC000;
  237. memctl->memc_mcr = 0x011A | UPMB;
  238. memctl->memc_mdr = 0x7FFCC004;
  239. memctl->memc_mcr = 0x011B | UPMB;
  240. memctl->memc_mdr = 0xFFFDCC05;
  241. memctl->memc_mcr = 0x011C | UPMB;
  242. /* Initialize OR3 / BR3 for CAN Bus Controller */
  243. memctl->memc_or3 = CFG_OR3_CAN;
  244. memctl->memc_br3 = CFG_BR3_CAN;
  245. }
  246. void can_driver_disable (void)
  247. {
  248. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  249. volatile memctl8xx_t *memctl = &immap->im_memctl;
  250. /* Reset OR3 / BR3 to disable CAN Bus Controller */
  251. memctl->memc_br3 = 0;
  252. memctl->memc_or3 = 0;
  253. memctl->memc_mbmr = 0;
  254. }
  255. /* ------------------------------------------------------------------------- */
  256. /*
  257. * Check memory range for valid RAM. A simple memory test determines
  258. * the actually available RAM size between addresses `base' and
  259. * `base + maxsize'. Some (not all) hardware errors are detected:
  260. * - short between address lines
  261. * - short between data lines
  262. */
  263. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  264. {
  265. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  266. volatile memctl8xx_t *memctl = &immap->im_memctl;
  267. volatile long int *addr;
  268. ulong cnt, val;
  269. ulong save[32]; /* to make test non-destructive */
  270. unsigned char i = 0;
  271. memctl->memc_mamr = mamr_value;
  272. for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
  273. addr = base + cnt; /* pointer arith! */
  274. save[i++] = *addr;
  275. *addr = ~cnt;
  276. }
  277. /* write 0 to base address */
  278. addr = base;
  279. save[i] = *addr;
  280. *addr = 0;
  281. /* check at base address */
  282. if ((val = *addr) != 0) {
  283. *addr = save[i];
  284. return (0);
  285. }
  286. for (cnt = 1; cnt <= maxsize/sizeof(long); cnt <<= 1) {
  287. addr = base + cnt; /* pointer arith! */
  288. val = *addr;
  289. *addr = save[--i];
  290. if (val != (~cnt)) {
  291. return (cnt * sizeof(long));
  292. }
  293. }
  294. return (maxsize);
  295. }
  296. /* ------------------------------------------------------------------------- */
  297. #define ETH_CFG_BITS (CFG_PB_ETH_CFG1 | CFG_PB_ETH_CFG2 | CFG_PB_ETH_CFG3 )
  298. #define ETH_ALL_BITS (ETH_CFG_BITS | CFG_PB_ETH_POWERDOWN)
  299. void reset_phy(void)
  300. {
  301. immap_t *immr = (immap_t *)CFG_IMMR;
  302. ulong value;
  303. /* Configure all needed port pins for GPIO */
  304. #if CFG_ETH_MDDIS_VALUE
  305. immr->im_ioport.iop_padat |= CFG_PA_ETH_MDDIS;
  306. #else
  307. immr->im_ioport.iop_padat &= ~(CFG_PA_ETH_MDDIS | CFG_PA_ETH_RESET); /* Set low */
  308. #endif
  309. immr->im_ioport.iop_papar &= ~(CFG_PA_ETH_MDDIS | CFG_PA_ETH_RESET); /* GPIO */
  310. immr->im_ioport.iop_paodr &= ~(CFG_PA_ETH_MDDIS | CFG_PA_ETH_RESET); /* active output */
  311. immr->im_ioport.iop_padir |= CFG_PA_ETH_MDDIS | CFG_PA_ETH_RESET; /* output */
  312. immr->im_cpm.cp_pbpar &= ~(ETH_ALL_BITS); /* GPIO */
  313. immr->im_cpm.cp_pbodr &= ~(ETH_ALL_BITS); /* active output */
  314. value = immr->im_cpm.cp_pbdat;
  315. /* Assert Powerdown and Reset signals */
  316. value |= CFG_PB_ETH_POWERDOWN;
  317. /* PHY configuration includes MDDIS and CFG1 ... CFG3 */
  318. #if CFG_ETH_CFG1_VALUE
  319. value |= CFG_PB_ETH_CFG1;
  320. #else
  321. value &= ~(CFG_PB_ETH_CFG1);
  322. #endif
  323. #if CFG_ETH_CFG2_VALUE
  324. value |= CFG_PB_ETH_CFG2;
  325. #else
  326. value &= ~(CFG_PB_ETH_CFG2);
  327. #endif
  328. #if CFG_ETH_CFG3_VALUE
  329. value |= CFG_PB_ETH_CFG3;
  330. #else
  331. value &= ~(CFG_PB_ETH_CFG3);
  332. #endif
  333. /* Drive output signals to initial state */
  334. immr->im_cpm.cp_pbdat = value;
  335. immr->im_cpm.cp_pbdir |= ETH_ALL_BITS;
  336. udelay (10000);
  337. /* De-assert Ethernet Powerdown */
  338. immr->im_cpm.cp_pbdat &= ~(CFG_PB_ETH_POWERDOWN); /* Enable PHY power */
  339. udelay (10000);
  340. /* de-assert RESET signal of PHY */
  341. immr->im_ioport.iop_padat |= CFG_PA_ETH_RESET;
  342. udelay (1000);
  343. }
  344. int misc_init_r (void)
  345. {
  346. fpga_init();
  347. return (0);
  348. }
  349. /* ------------------------------------------------------------------------- */