spc1920.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Modified by, Yuli Barcohen, Arabella Software Ltd., yuli@arabellasw.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. #include <config.h>
  26. #include <common.h>
  27. #include <mpc8xx.h>
  28. #include "pld.h"
  29. #include "hpi.h"
  30. #define _NOT_USED_ 0xFFFFFFFF
  31. static long int dram_size (long int, long int *, long int);
  32. const uint sdram_table[] = {
  33. /*
  34. * Single Read. (Offset 0 in UPMB RAM)
  35. */
  36. 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
  37. 0x1FF77C47, /* last */
  38. /*
  39. * SDRAM Initialization (offset 5 in UPMB RAM)
  40. *
  41. * This is no UPM entry point. The following definition uses
  42. * the remaining space to establish an initialization
  43. * sequence, which is executed by a RUN command.
  44. *
  45. */
  46. 0x1FF77C34, 0xEFEABC34, 0x1FB57C35, /* last */
  47. /*
  48. * Burst Read. (Offset 8 in UPMB RAM)
  49. */
  50. 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
  51. 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
  52. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  53. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  54. /*
  55. * Single Write. (Offset 18 in UPMB RAM)
  56. */
  57. 0x1F07FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
  58. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  59. /*
  60. * Burst Write. (Offset 20 in UPMB RAM)
  61. */
  62. 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
  63. 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
  64. _NOT_USED_,
  65. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  66. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  67. /*
  68. * Refresh (Offset 30 in UPMB RAM)
  69. */
  70. 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  71. 0xFFFFFC84, 0xFFFFFC07, /* last */
  72. _NOT_USED_, _NOT_USED_,
  73. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  74. /*
  75. * Exception. (Offset 3c in UPMB RAM)
  76. */
  77. 0x7FFFFC07, /* last */
  78. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  79. };
  80. phys_size_t initdram (int board_type)
  81. {
  82. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  83. volatile memctl8xx_t *memctl = &immr->im_memctl;
  84. /* volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE; */
  85. long int size_b0;
  86. long int size8, size9;
  87. int i;
  88. /*
  89. * Configure UPMB for SDRAM
  90. */
  91. upmconfig (UPMB, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  92. udelay(100);
  93. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  94. /* burst length=4, burst type=sequential, CAS latency=2 */
  95. memctl->memc_mar = CONFIG_SYS_MAR;
  96. /*
  97. * Map controller bank 1 to the SDRAM bank at preliminary address.
  98. */
  99. memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
  100. memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
  101. /* initialize memory address register */
  102. memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL; /* refresh not enabled yet */
  103. /* mode initialization (offset 5) */
  104. udelay (200); /* 0x80006105 */
  105. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x05);
  106. /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */
  107. udelay (1); /* 0x80006130 */
  108. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x30);
  109. udelay (1); /* 0x80006130 */
  110. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x30);
  111. udelay (1); /* 0x80006106 */
  112. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x06);
  113. memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */
  114. udelay (200);
  115. /* Need at least 10 DRAM accesses to stabilize */
  116. for (i = 0; i < 10; ++i) {
  117. volatile unsigned long *addr =
  118. (volatile unsigned long *) CONFIG_SYS_SDRAM_BASE;
  119. unsigned long val;
  120. val = *(addr + i);
  121. *(addr + i) = val;
  122. }
  123. /*
  124. * Check Bank 0 Memory Size for re-configuration
  125. *
  126. * try 8 column mode
  127. */
  128. size8 = dram_size (CONFIG_SYS_MBMR_8COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE);
  129. udelay (1000);
  130. /*
  131. * try 9 column mode
  132. */
  133. size9 = dram_size (CONFIG_SYS_MBMR_9COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE);
  134. if (size8 < size9) { /* leave configuration at 9 columns */
  135. size_b0 = size9;
  136. memctl->memc_mbmr = CONFIG_SYS_MBMR_9COL | MBMR_PTBE;
  137. udelay (500);
  138. } else { /* back to 8 columns */
  139. size_b0 = size8;
  140. memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE;
  141. udelay (500);
  142. }
  143. /*
  144. * Final mapping:
  145. */
  146. memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) |
  147. OR_CSNT_SAM | OR_G5LS | SDRAM_TIMING;
  148. memctl->memc_br1 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMB | BR_V;
  149. udelay (1000);
  150. /* initalize the DSP Host Port Interface */
  151. hpi_init();
  152. /* FRAM Setup */
  153. memctl->memc_or4 = CONFIG_SYS_OR4;
  154. memctl->memc_br4 = CONFIG_SYS_BR4;
  155. udelay(1000);
  156. return (size_b0);
  157. }
  158. /*
  159. * Check memory range for valid RAM. A simple memory test determines
  160. * the actually available RAM size between addresses `base' and
  161. * `base + maxsize'. Some (not all) hardware errors are detected:
  162. * - short between address lines
  163. * - short between data lines
  164. */
  165. static long int dram_size (long int mbmr_value, long int *base,
  166. long int maxsize)
  167. {
  168. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  169. volatile memctl8xx_t *memctl = &immap->im_memctl;
  170. memctl->memc_mbmr = mbmr_value;
  171. return (get_ram_size (base, maxsize));
  172. }
  173. /************* other stuff ******************/
  174. int board_early_init_f(void)
  175. {
  176. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  177. /* Set Go/NoGo led (PA15) to color red */
  178. immap->im_ioport.iop_papar &= ~0x1;
  179. immap->im_ioport.iop_paodr &= ~0x1;
  180. immap->im_ioport.iop_padir |= 0x1;
  181. immap->im_ioport.iop_padat |= 0x1;
  182. #if 0
  183. /* Turn on LED PD9 */
  184. immap->im_ioport.iop_pdpar &= ~(0x0040);
  185. immap->im_ioport.iop_pddir |= 0x0040;
  186. immap->im_ioport.iop_pddat |= 0x0040;
  187. #endif
  188. /*
  189. * Enable console on SMC1. This requires turning on
  190. * the com2_en signal and SMC1_DISABLE
  191. */
  192. /* SMC1_DISABLE: PB17 */
  193. immap->im_cpm.cp_pbodr &= ~0x4000;
  194. immap->im_cpm.cp_pbpar &= ~0x4000;
  195. immap->im_cpm.cp_pbdir |= 0x4000;
  196. immap->im_cpm.cp_pbdat &= ~0x4000;
  197. /* COM2_EN: PD10 */
  198. immap->im_ioport.iop_pdpar &= ~0x0020;
  199. immap->im_ioport.iop_pddir &= ~0x4000;
  200. immap->im_ioport.iop_pddir |= 0x0020;
  201. immap->im_ioport.iop_pddat |= 0x0020;
  202. #ifdef CONFIG_SYS_SMC1_PLD_CLK4 /* SMC1 uses CLK4 from PLD */
  203. immap->im_cpm.cp_simode |= 0x7000;
  204. immap->im_cpm.cp_simode &= ~(0x8000);
  205. #endif
  206. return 0;
  207. }
  208. int last_stage_init(void)
  209. {
  210. #ifdef CONFIG_SPC1920_HPI_TEST
  211. printf("CMB1920 Host Port Interface Test: %s\n",
  212. hpi_test() ? "Failed!" : "OK");
  213. #endif
  214. return 0;
  215. }
  216. int checkboard (void)
  217. {
  218. puts("Board: SPC1920\n");
  219. return 0;
  220. }