ipek01.c 6.3 KB

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