ipek01.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 2006
  9. * MicroSys GmbH
  10. *
  11. * (C) Copyright 2009
  12. * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. #include <mpc5xxx.h>
  34. #include <pci.h>
  35. #include <netdev.h>
  36. #include <miiphy.h>
  37. #include <libfdt.h>
  38. #include <mb862xx.h>
  39. #include <video_fb.h>
  40. #include <asm/processor.h>
  41. #include <asm/io.h>
  42. #ifdef CONFIG_OF_LIBFDT
  43. #include <fdt_support.h>
  44. #endif /* CONFIG_OF_LIBFDT */
  45. /* mt46v16m16-75 */
  46. #ifdef CONFIG_MPC5200_DDR
  47. /* Settings for XLB = 132 MHz */
  48. #define SDRAM_MODE 0x018D0000
  49. #define SDRAM_EMODE 0x40090000
  50. #define SDRAM_CONTROL 0x714f0f00
  51. #define SDRAM_CONFIG1 0x73722930
  52. #define SDRAM_CONFIG2 0x47770000
  53. #define SDRAM_TAPDELAY 0x10000000
  54. #else
  55. #error SDRAM is not supported on this board
  56. #endif
  57. DECLARE_GLOBAL_DATA_PTR;
  58. static void sdram_start (int hi_addr)
  59. {
  60. struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  61. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  62. /* unlock mode register */
  63. out_be32 (&sdram->ctrl, SDRAM_CONTROL | 0x80000000 | hi_addr_bit);
  64. /* precharge all banks */
  65. out_be32 (&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit);
  66. /* set mode register: extended mode */
  67. out_be32 (&sdram->mode, SDRAM_EMODE);
  68. /* set mode register: reset DLL */
  69. out_be32 (&sdram->mode, SDRAM_MODE | 0x04000000);
  70. /* precharge all banks */
  71. out_be32 (&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit);
  72. /* auto refresh */
  73. out_be32 (&sdram->ctrl, SDRAM_CONTROL | 0x80000004 | hi_addr_bit);
  74. /* set mode register */
  75. out_be32 (&sdram->mode, SDRAM_MODE);
  76. /* normal operation */
  77. out_be32 (&sdram->ctrl, SDRAM_CONTROL | hi_addr_bit);
  78. }
  79. /*
  80. * ATTENTION: Although partially referenced initdram does NOT make real
  81. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
  82. * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
  83. */
  84. phys_size_t initdram (int board_type)
  85. {
  86. struct mpc5xxx_mmap_ctl *mmap_ctl =
  87. (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
  88. struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  89. struct mpc5xxx_cdm *cdm = (struct mpc5xxx_cdm *)MPC5XXX_CDM;
  90. ulong dramsize = 0;
  91. ulong dramsize2 = 0;
  92. ulong test1, test2;
  93. /* setup SDRAM chip selects */
  94. out_be32 (&mmap_ctl->sdram0, 0x0000001e); /* 2G at 0x0 */
  95. out_be32 (&mmap_ctl->sdram1, 0x00000000); /* disabled */
  96. /* setup config registers */
  97. out_be32 (&sdram->config1, SDRAM_CONFIG1);
  98. out_be32 (&sdram->config2, SDRAM_CONFIG2);
  99. /* set tap delay */
  100. out_be32 (&cdm->porcfg, SDRAM_TAPDELAY);
  101. /* find RAM size using SDRAM CS0 only */
  102. sdram_start (0);
  103. test1 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  104. sdram_start (1);
  105. test2 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  106. if (test1 > test2) {
  107. sdram_start (0);
  108. dramsize = test1;
  109. } else {
  110. dramsize = test2;
  111. }
  112. /* memory smaller than 1MB is impossible */
  113. if (dramsize < (1 << 20))
  114. dramsize = 0;
  115. /* set SDRAM CS0 size according to the amount of RAM found */
  116. if (dramsize > 0)
  117. out_be32 (&mmap_ctl->sdram0,
  118. 0x13 + __builtin_ffs (dramsize >> 20) - 1);
  119. else
  120. out_be32 (&mmap_ctl->sdram1, 0); /* disabled */
  121. /*
  122. * On MPC5200B we need to set the special configuration delay in the
  123. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  124. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  125. *
  126. * "The SDelay should be written to a value of 0x00000004. It is
  127. * required to account for changes caused by normal wafer processing
  128. * parameters."
  129. */
  130. out_be32 (&sdram->sdelay, 0x04);
  131. return dramsize + dramsize2;
  132. }
  133. int checkboard (void)
  134. {
  135. puts ("Board: IPEK01 \n");
  136. return 0;
  137. }
  138. void flash_preinit (void)
  139. {
  140. struct mpc5xxx_lpb *lpb = (struct mpc5xxx_lpb *)MPC5XXX_LPB;
  141. /*
  142. * Now, when we are in RAM, enable flash write
  143. * access for detection process.
  144. * Note that CS_BOOT cannot be cleared when
  145. * executing in flash.
  146. */
  147. clrbits_be32 (&lpb->cs0_cfg, 0x1); /* clear RO */
  148. }
  149. void flash_afterinit (ulong start, ulong size)
  150. {
  151. struct mpc5xxx_mmap_ctl *mmap_ctl =
  152. (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
  153. #if defined(CONFIG_BOOT_ROM)
  154. /* adjust mapping */
  155. out_be32 (&mmap_ctl->cs1_start, START_REG (start));
  156. out_be32 (&mmap_ctl->cs1_stop, STOP_REG (start, size));
  157. #else
  158. /* adjust mapping */
  159. out_be32 (&mmap_ctl->boot_start, START_REG (start));
  160. out_be32 (&mmap_ctl->cs0_start, START_REG (start));
  161. out_be32 (&mmap_ctl->boot_stop, STOP_REG (start, size));
  162. out_be32 (&mmap_ctl->cs0_stop, STOP_REG (start, size));
  163. #endif
  164. }
  165. extern flash_info_t flash_info[]; /* info for FLASH chips */
  166. int misc_init_r (void)
  167. {
  168. /* adjust flash start */
  169. gd->bd->bi_flashstart = flash_info[0].start[0];
  170. return (0);
  171. }
  172. #ifdef CONFIG_PCI
  173. static struct pci_controller hose;
  174. extern void pci_mpc5xxx_init (struct pci_controller *);
  175. void pci_init_board (void)
  176. {
  177. pci_mpc5xxx_init (&hose);
  178. }
  179. #endif
  180. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  181. void ft_board_setup (void *blob, bd_t * bd)
  182. {
  183. ft_cpu_setup (blob, bd);
  184. fdt_fixup_memory (blob, (u64) bd->bi_memstart, (u64) bd->bi_memsize);
  185. }
  186. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  187. int board_eth_init(bd_t *bis)
  188. {
  189. cpu_eth_init(bis); /* Built in FEC comes first */
  190. return pci_eth_init(bis);
  191. }
  192. #ifdef CONFIG_VIDEO
  193. extern GraphicDevice mb862xx;
  194. static const gdc_regs init_regs[] = {
  195. {0x0100, 0x00000900},
  196. {0x0020, 0x80190257},
  197. {0x0024, 0x00000000},
  198. {0x0028, 0x00000000},
  199. {0x002c, 0x00000000},
  200. {0x0110, 0x00000000},
  201. {0x0114, 0x00000000},
  202. {0x0118, 0x02570320},
  203. {0x0004, 0x041f0000},
  204. {0x0008, 0x031f031f},
  205. {0x000c, 0x067f0347},
  206. {0x0010, 0x02780000},
  207. {0x0014, 0x0257025c},
  208. {0x0018, 0x00000000},
  209. {0x001c, 0x02570320},
  210. {0x0100, 0x80010900},
  211. {0x0, 0x0}
  212. };
  213. const gdc_regs *board_get_regs (void)
  214. {
  215. return init_regs;
  216. }
  217. /* Returns Lime base address */
  218. unsigned int board_video_init (void)
  219. {
  220. if (mb862xx_probe (CONFIG_SYS_LIME_BASE) != MB862XX_TYPE_LIME)
  221. return 0;
  222. mb862xx.winSizeX = 800;
  223. mb862xx.winSizeY = 600;
  224. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  225. mb862xx.gdfBytesPP = 2;
  226. return CONFIG_SYS_LIME_BASE;
  227. }
  228. #if defined(CONFIG_CONSOLE_EXTRA_INFO)
  229. /*
  230. * Return text to be printed besides the logo.
  231. */
  232. void video_get_info_str (int line_number, char *info)
  233. {
  234. if (line_number == 1)
  235. strcpy (info, " Board: IPEK01");
  236. else
  237. info[0] = '\0';
  238. }
  239. #endif
  240. #endif /* CONFIG_VIDEO */