mvbc_p.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * (C) Copyright 2003
  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 2005-2007
  9. * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <mpc5xxx.h>
  15. #include <malloc.h>
  16. #include <pci.h>
  17. #include <i2c.h>
  18. #include <fpga.h>
  19. #include <environment.h>
  20. #include <fdt_support.h>
  21. #include <netdev.h>
  22. #include <asm/io.h>
  23. #include "fpga.h"
  24. #include "mvbc_p.h"
  25. #include "../common/mv_common.h"
  26. #define SDRAM_MODE 0x00CD0000
  27. #define SDRAM_CONTROL 0x504F0000
  28. #define SDRAM_CONFIG1 0xD2322800
  29. #define SDRAM_CONFIG2 0x8AD70000
  30. DECLARE_GLOBAL_DATA_PTR;
  31. static void sdram_start (int hi_addr)
  32. {
  33. long hi_bit = hi_addr ? 0x01000000 : 0;
  34. /* unlock mode register */
  35. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit);
  36. /* precharge all banks */
  37. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
  38. /* precharge all banks */
  39. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
  40. /* auto refresh */
  41. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit);
  42. /* set mode register */
  43. out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  44. /* normal operation */
  45. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit);
  46. }
  47. phys_addr_t initdram (int board_type)
  48. {
  49. ulong dramsize = 0;
  50. ulong test1,
  51. test2;
  52. /* setup SDRAM chip selects */
  53. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
  54. /* setup config registers */
  55. out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  56. out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  57. /* find RAM size using SDRAM CS0 only */
  58. sdram_start(0);
  59. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  60. sdram_start(1);
  61. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  62. if (test1 > test2) {
  63. sdram_start(0);
  64. dramsize = test1;
  65. } else
  66. dramsize = test2;
  67. if (dramsize < (1 << 20))
  68. dramsize = 0;
  69. if (dramsize > 0)
  70. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 +
  71. __builtin_ffs(dramsize >> 20) - 1);
  72. else
  73. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0);
  74. return dramsize;
  75. }
  76. void mvbc_init_gpio(void)
  77. {
  78. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  79. printf("Ports : 0x%08x\n", gpio->port_config);
  80. printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG);
  81. out_be32(&gpio->simple_ddr, SIMPLE_DDR);
  82. out_be32(&gpio->simple_dvo, SIMPLE_DVO);
  83. out_be32(&gpio->simple_ode, SIMPLE_ODE);
  84. out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN);
  85. out_8(&gpio->sint_ode, SINT_ODE);
  86. out_8(&gpio->sint_ddr, SINT_DDR);
  87. out_8(&gpio->sint_dvo, SINT_DVO);
  88. out_8(&gpio->sint_inten, SINT_INTEN);
  89. out_be16(&gpio->sint_itype, SINT_ITYPE);
  90. out_8(&gpio->sint_gpioe, SINT_GPIOEN);
  91. out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE);
  92. out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR);
  93. out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO);
  94. out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN);
  95. printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe);
  96. printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe);
  97. }
  98. int misc_init_r(void)
  99. {
  100. char *s = getenv("reset_env");
  101. if (!s) {
  102. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  103. return 0;
  104. udelay(50000);
  105. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  106. return 0;
  107. udelay(50000);
  108. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  109. return 0;
  110. }
  111. printf(" === FACTORY RESET ===\n");
  112. mv_reset_environment();
  113. saveenv();
  114. return -1;
  115. }
  116. int checkboard(void)
  117. {
  118. mvbc_init_gpio();
  119. printf("Board: Matrix Vision mvBlueCOUGAR-P\n");
  120. return 0;
  121. }
  122. void flash_preinit(void)
  123. {
  124. /*
  125. * Now, when we are in RAM, enable flash write
  126. * access for detection process.
  127. * Note that CS_BOOT cannot be cleared when
  128. * executing in flash.
  129. */
  130. clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1);
  131. }
  132. void flash_afterinit(ulong size)
  133. {
  134. out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_BOOTCS_START |
  135. size));
  136. out_be32((u32*)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_BOOTCS_START |
  137. size));
  138. out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
  139. size));
  140. out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
  141. size));
  142. }
  143. void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  144. {
  145. unsigned char line = 0xff;
  146. char *s = getenv("pci_latency");
  147. u32 base;
  148. u8 val = 0;
  149. if (s)
  150. val = simple_strtoul(s, NULL, 16);
  151. if (PCI_BUS(dev) == 0) {
  152. switch (PCI_DEV (dev)) {
  153. case 0xa: /* FPGA */
  154. line = 3;
  155. pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base);
  156. printf("found FPGA - enable arbitration\n");
  157. writel(0x03, (u32*)(base + 0x80c0));
  158. writel(0xf0, (u32*)(base + 0x8080));
  159. if (val)
  160. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val);
  161. break;
  162. case 0xb: /* LAN */
  163. line = 2;
  164. if (val)
  165. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val);
  166. break;
  167. case 0x1a:
  168. break;
  169. default:
  170. printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev));
  171. break;
  172. }
  173. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line);
  174. }
  175. }
  176. struct pci_controller hose = {
  177. fixup_irq:pci_mvbc_fixup_irq
  178. };
  179. extern void pci_mpc5xxx_init(struct pci_controller *);
  180. void pci_init_board(void)
  181. {
  182. mvbc_p_init_fpga();
  183. mv_load_fpga();
  184. pci_mpc5xxx_init(&hose);
  185. }
  186. void show_boot_progress(int val)
  187. {
  188. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  189. switch(val) {
  190. case BOOTSTAGE_ID_START: /* FPGA ok */
  191. setbits_be32(&gpio->simple_dvo, LED_G0);
  192. break;
  193. case BOOTSTAGE_ID_NET_ETH_INIT:
  194. setbits_be32(&gpio->simple_dvo, LED_G1);
  195. break;
  196. case BOOTSTAGE_ID_COPY_RAMDISK:
  197. setbits_be32(&gpio->simple_dvo, LED_Y);
  198. break;
  199. case BOOTSTAGE_ID_RUN_OS:
  200. setbits_be32(&gpio->simple_dvo, LED_R);
  201. break;
  202. default:
  203. break;
  204. }
  205. }
  206. void ft_board_setup(void *blob, bd_t *bd)
  207. {
  208. ft_cpu_setup(blob, bd);
  209. }
  210. int board_eth_init(bd_t *bis)
  211. {
  212. cpu_eth_init(bis); /* Built in FEC comes first */
  213. return pci_eth_init(bis);
  214. }