mpc8540ads.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * (C) Copyright 2002,2003, Motorola Inc.
  4. * Xianghua Xiao, (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <pci.h>
  28. #include <asm/processor.h>
  29. #include <asm/mmu.h>
  30. #include <asm/immap_85xx.h>
  31. #include <asm/fsl_ddr_sdram.h>
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  35. extern void ddr_enable_ecc(unsigned int dram_size);
  36. #endif
  37. void local_bus_init(void);
  38. int checkboard (void)
  39. {
  40. puts("Board: ADS\n");
  41. #ifdef CONFIG_PCI
  42. printf("PCI1: 32 bit, %d MHz (compiled)\n",
  43. CONFIG_SYS_CLK_FREQ / 1000000);
  44. #else
  45. printf("PCI1: disabled\n");
  46. #endif
  47. /*
  48. * Initialize local bus.
  49. */
  50. local_bus_init();
  51. return 0;
  52. }
  53. /*
  54. * Initialize Local Bus
  55. */
  56. void
  57. local_bus_init(void)
  58. {
  59. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  60. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  61. uint clkdiv;
  62. uint lbc_hz;
  63. sys_info_t sysinfo;
  64. /*
  65. * Errata LBC11.
  66. * Fix Local Bus clock glitch when DLL is enabled.
  67. *
  68. * If localbus freq is < 66MHz, DLL bypass mode must be used.
  69. * If localbus freq is > 133MHz, DLL can be safely enabled.
  70. * Between 66 and 133, the DLL is enabled with an override workaround.
  71. */
  72. get_sys_info(&sysinfo);
  73. clkdiv = lbc->lcrr & LCRR_CLKDIV;
  74. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  75. if (lbc_hz < 66) {
  76. lbc->lcrr = CONFIG_SYS_LBC_LCRR | 0x80000000; /* DLL Bypass */
  77. } else if (lbc_hz >= 133) {
  78. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  79. } else {
  80. /*
  81. * On REV1 boards, need to change CLKDIV before enable DLL.
  82. * Default CLKDIV is 8, change it to 4 temporarily.
  83. */
  84. uint pvr = get_pvr();
  85. uint temp_lbcdll = 0;
  86. if (pvr == PVR_85xx_REV1) {
  87. /* FIXME: Justify the high bit here. */
  88. lbc->lcrr = 0x10000004;
  89. }
  90. lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  91. udelay(200);
  92. /*
  93. * Sample LBC DLL ctrl reg, upshift it to set the
  94. * override bits.
  95. */
  96. temp_lbcdll = gur->lbcdllcr;
  97. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  98. asm("sync;isync;msync");
  99. }
  100. }
  101. /*
  102. * Initialize SDRAM memory on the Local Bus.
  103. */
  104. void lbc_sdram_init(void)
  105. {
  106. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  107. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  108. puts("LBC SDRAM: ");
  109. print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
  110. "\n ");
  111. /*
  112. * Setup SDRAM Base and Option Registers
  113. */
  114. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  115. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  116. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  117. asm("msync");
  118. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  119. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  120. asm("sync");
  121. /*
  122. * Configure the SDRAM controller.
  123. */
  124. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
  125. asm("sync");
  126. *sdram_addr = 0xff;
  127. ppcDcbf((unsigned long) sdram_addr);
  128. udelay(100);
  129. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
  130. asm("sync");
  131. *sdram_addr = 0xff;
  132. ppcDcbf((unsigned long) sdram_addr);
  133. udelay(100);
  134. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
  135. asm("sync");
  136. *sdram_addr = 0xff;
  137. ppcDcbf((unsigned long) sdram_addr);
  138. udelay(100);
  139. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  140. asm("sync");
  141. *sdram_addr = 0xff;
  142. ppcDcbf((unsigned long) sdram_addr);
  143. udelay(100);
  144. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
  145. asm("sync");
  146. *sdram_addr = 0xff;
  147. ppcDcbf((unsigned long) sdram_addr);
  148. udelay(100);
  149. }
  150. #if !defined(CONFIG_SPD_EEPROM)
  151. /*************************************************************************
  152. * fixed sdram init -- doesn't use serial presence detect.
  153. ************************************************************************/
  154. phys_size_t fixed_sdram(void)
  155. {
  156. #ifndef CONFIG_SYS_RAMBOOT
  157. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  158. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  159. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  160. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  161. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  162. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  163. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  164. #if defined (CONFIG_DDR_ECC)
  165. ddr->err_disable = 0x0000000D;
  166. ddr->err_sbe = 0x00ff0000;
  167. #endif
  168. asm("sync;isync;msync");
  169. udelay(500);
  170. #if defined (CONFIG_DDR_ECC)
  171. /* Enable ECC checking */
  172. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  173. #else
  174. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  175. #endif
  176. asm("sync; isync; msync");
  177. udelay(500);
  178. #endif
  179. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  180. }
  181. #endif /* !defined(CONFIG_SPD_EEPROM) */
  182. #if defined(CONFIG_PCI)
  183. /*
  184. * Initialize PCI Devices, report devices found.
  185. */
  186. static struct pci_controller hose;
  187. #endif /* CONFIG_PCI */
  188. void
  189. pci_init_board(void)
  190. {
  191. #ifdef CONFIG_PCI
  192. pci_mpc85xx_init(&hose);
  193. #endif /* CONFIG_PCI */
  194. }
  195. #if defined(CONFIG_OF_BOARD_SETUP)
  196. void
  197. ft_board_setup(void *blob, bd_t *bd)
  198. {
  199. int node, tmp[2];
  200. const char *path;
  201. ft_cpu_setup(blob, bd);
  202. node = fdt_path_offset(blob, "/aliases");
  203. tmp[0] = 0;
  204. if (node >= 0) {
  205. #ifdef CONFIG_PCI
  206. path = fdt_getprop(blob, node, "pci0", NULL);
  207. if (path) {
  208. tmp[1] = hose.last_busno - hose.first_busno;
  209. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  210. }
  211. #endif
  212. }
  213. }
  214. #endif