mpc8540ads.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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(" SDRAM: ");
  109. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  110. /*
  111. * Setup SDRAM Base and Option Registers
  112. */
  113. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  114. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  115. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  116. asm("msync");
  117. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  118. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  119. asm("sync");
  120. /*
  121. * Configure the SDRAM controller.
  122. */
  123. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
  124. asm("sync");
  125. *sdram_addr = 0xff;
  126. ppcDcbf((unsigned long) sdram_addr);
  127. udelay(100);
  128. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
  129. asm("sync");
  130. *sdram_addr = 0xff;
  131. ppcDcbf((unsigned long) sdram_addr);
  132. udelay(100);
  133. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
  134. asm("sync");
  135. *sdram_addr = 0xff;
  136. ppcDcbf((unsigned long) sdram_addr);
  137. udelay(100);
  138. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  139. asm("sync");
  140. *sdram_addr = 0xff;
  141. ppcDcbf((unsigned long) sdram_addr);
  142. udelay(100);
  143. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
  144. asm("sync");
  145. *sdram_addr = 0xff;
  146. ppcDcbf((unsigned long) sdram_addr);
  147. udelay(100);
  148. }
  149. #if !defined(CONFIG_SPD_EEPROM)
  150. /*************************************************************************
  151. * fixed sdram init -- doesn't use serial presence detect.
  152. ************************************************************************/
  153. phys_size_t fixed_sdram(void)
  154. {
  155. #ifndef CONFIG_SYS_RAMBOOT
  156. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  157. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  158. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  159. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  160. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  161. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  162. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  163. #if defined (CONFIG_DDR_ECC)
  164. ddr->err_disable = 0x0000000D;
  165. ddr->err_sbe = 0x00ff0000;
  166. #endif
  167. asm("sync;isync;msync");
  168. udelay(500);
  169. #if defined (CONFIG_DDR_ECC)
  170. /* Enable ECC checking */
  171. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  172. #else
  173. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  174. #endif
  175. asm("sync; isync; msync");
  176. udelay(500);
  177. #endif
  178. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  179. }
  180. #endif /* !defined(CONFIG_SPD_EEPROM) */
  181. #if defined(CONFIG_PCI)
  182. /*
  183. * Initialize PCI Devices, report devices found.
  184. */
  185. static struct pci_controller hose;
  186. #endif /* CONFIG_PCI */
  187. void
  188. pci_init_board(void)
  189. {
  190. #ifdef CONFIG_PCI
  191. pci_mpc85xx_init(&hose);
  192. #endif /* CONFIG_PCI */
  193. }
  194. #if defined(CONFIG_OF_BOARD_SETUP)
  195. void
  196. ft_board_setup(void *blob, bd_t *bd)
  197. {
  198. int node, tmp[2];
  199. const char *path;
  200. ft_cpu_setup(blob, bd);
  201. node = fdt_path_offset(blob, "/aliases");
  202. tmp[0] = 0;
  203. if (node >= 0) {
  204. #ifdef CONFIG_PCI
  205. path = fdt_getprop(blob, node, "pci0", NULL);
  206. if (path) {
  207. tmp[1] = hose.last_busno - hose.first_busno;
  208. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  209. }
  210. #endif
  211. }
  212. }
  213. #endif