mvbc_p.c 6.6 KB

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