mvbc_p.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. #define SDRAM_MODE 0x00CD0000
  42. #define SDRAM_CONTROL 0x504F0000
  43. #define SDRAM_CONFIG1 0xD2322800
  44. #define SDRAM_CONFIG2 0x8AD70000
  45. DECLARE_GLOBAL_DATA_PTR;
  46. static void sdram_start (int hi_addr)
  47. {
  48. long hi_bit = hi_addr ? 0x01000000 : 0;
  49. /* unlock mode register */
  50. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit);
  51. /* precharge all banks */
  52. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
  53. /* precharge all banks */
  54. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
  55. /* auto refresh */
  56. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit);
  57. /* set mode register */
  58. out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  59. /* normal operation */
  60. out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit);
  61. }
  62. phys_addr_t initdram (int board_type)
  63. {
  64. ulong dramsize = 0;
  65. ulong test1,
  66. test2;
  67. /* setup SDRAM chip selects */
  68. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
  69. /* setup config registers */
  70. out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  71. out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  72. /* find RAM size using SDRAM CS0 only */
  73. sdram_start(0);
  74. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  75. sdram_start(1);
  76. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  77. if (test1 > test2) {
  78. sdram_start(0);
  79. dramsize = test1;
  80. } else
  81. dramsize = test2;
  82. if (dramsize < (1 << 20))
  83. dramsize = 0;
  84. if (dramsize > 0)
  85. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 +
  86. __builtin_ffs(dramsize >> 20) - 1);
  87. else
  88. out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0);
  89. return dramsize;
  90. }
  91. void mvbc_init_gpio(void)
  92. {
  93. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  94. printf("Ports : 0x%08x\n", gpio->port_config);
  95. printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG);
  96. out_be32(&gpio->simple_ddr, SIMPLE_DDR);
  97. out_be32(&gpio->simple_dvo, SIMPLE_DVO);
  98. out_be32(&gpio->simple_ode, SIMPLE_ODE);
  99. out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN);
  100. out_8(&gpio->sint_ode, SINT_ODE);
  101. out_8(&gpio->sint_ddr, SINT_DDR);
  102. out_8(&gpio->sint_dvo, SINT_DVO);
  103. out_8(&gpio->sint_inten, SINT_INTEN);
  104. out_be16(&gpio->sint_itype, SINT_ITYPE);
  105. out_8(&gpio->sint_gpioe, SINT_GPIOEN);
  106. out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE);
  107. out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR);
  108. out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO);
  109. out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN);
  110. printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe);
  111. printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe);
  112. }
  113. void reset_environment(void)
  114. {
  115. char *s, sernr[64];
  116. printf("\n*** RESET ENVIRONMENT ***\n");
  117. memset(sernr, 0, sizeof(sernr));
  118. s = getenv("serial#");
  119. if (s) {
  120. printf("found serial# : %s\n", s);
  121. strncpy(sernr, s, 64);
  122. }
  123. gd->env_valid = 0;
  124. env_relocate();
  125. if (s)
  126. setenv("serial#", sernr);
  127. }
  128. int misc_init_r(void)
  129. {
  130. char *s = getenv("reset_env");
  131. if (!s) {
  132. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  133. return 0;
  134. udelay(50000);
  135. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  136. return 0;
  137. udelay(50000);
  138. if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
  139. return 0;
  140. }
  141. printf(" === FACTORY RESET ===\n");
  142. reset_environment();
  143. saveenv();
  144. return -1;
  145. }
  146. int checkboard(void)
  147. {
  148. mvbc_init_gpio();
  149. printf("Board: Matrix Vision mvBlueCOUGAR-P\n");
  150. return 0;
  151. }
  152. void flash_preinit(void)
  153. {
  154. /*
  155. * Now, when we are in RAM, enable flash write
  156. * access for detection process.
  157. * Note that CS_BOOT cannot be cleared when
  158. * executing in flash.
  159. */
  160. clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1);
  161. }
  162. void flash_afterinit(ulong size)
  163. {
  164. out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_BOOTCS_START |
  165. size));
  166. out_be32((u32*)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_BOOTCS_START |
  167. size));
  168. out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
  169. size));
  170. out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
  171. size));
  172. }
  173. void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  174. {
  175. unsigned char line = 0xff;
  176. u32 base;
  177. if (PCI_BUS(dev) == 0) {
  178. switch (PCI_DEV (dev)) {
  179. case 0xa: /* FPGA */
  180. line = 3;
  181. pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base);
  182. printf("found FPA - enable arbitration\n");
  183. writel(0x03, (u32*)(base + 0x80c0));
  184. writel(0xf0, (u32*)(base + 0x8080));
  185. break;
  186. case 0xb: /* LAN */
  187. line = 2;
  188. break;
  189. case 0x1a:
  190. break;
  191. default:
  192. printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev));
  193. break;
  194. }
  195. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line);
  196. }
  197. }
  198. struct pci_controller hose = {
  199. fixup_irq:pci_mvbc_fixup_irq
  200. };
  201. int mvbc_p_load_fpga(void)
  202. {
  203. size_t data_size = 0;
  204. void *fpga_data = NULL;
  205. char *datastr = getenv("fpgadata");
  206. char *sizestr = getenv("fpgadatasize");
  207. if (datastr)
  208. fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
  209. if (sizestr)
  210. data_size = (size_t)simple_strtoul(sizestr, NULL, 16);
  211. return fpga_load(0, fpga_data, data_size);
  212. }
  213. extern void pci_mpc5xxx_init(struct pci_controller *);
  214. void pci_init_board(void)
  215. {
  216. char *s;
  217. int load_fpga = 1;
  218. mvbc_p_init_fpga();
  219. s = getenv("skip_fpga");
  220. if (s) {
  221. printf("found 'skip_fpga' -> FPGA _not_ loaded !\n");
  222. load_fpga = 0;
  223. }
  224. if (load_fpga) {
  225. printf("loading FPGA ... ");
  226. mvbc_p_load_fpga();
  227. printf("done\n");
  228. }
  229. pci_mpc5xxx_init(&hose);
  230. }
  231. u8 *dhcp_vendorex_prep(u8 *e)
  232. {
  233. char *ptr;
  234. /* DHCP vendor-class-identifier = 60 */
  235. if ((ptr = getenv("dhcp_vendor-class-identifier"))) {
  236. *e++ = 60;
  237. *e++ = strlen(ptr);
  238. while (*ptr)
  239. *e++ = *ptr++;
  240. }
  241. /* DHCP_CLIENT_IDENTIFIER = 61 */
  242. if ((ptr = getenv("dhcp_client_id"))) {
  243. *e++ = 61;
  244. *e++ = strlen(ptr);
  245. while (*ptr)
  246. *e++ = *ptr++;
  247. }
  248. return e;
  249. }
  250. u8 *dhcp_vendorex_proc (u8 *popt)
  251. {
  252. return NULL;
  253. }
  254. void show_boot_progress(int val)
  255. {
  256. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
  257. switch(val) {
  258. case 0: /* FPGA ok */
  259. setbits_be32(&gpio->simple_dvo, 0x80);
  260. break;
  261. case 1:
  262. setbits_be32(&gpio->simple_dvo, 0x40);
  263. break;
  264. case 12:
  265. setbits_be32(&gpio->simple_dvo, 0x20);
  266. break;
  267. case 15:
  268. setbits_be32(&gpio->simple_dvo, 0x10);
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. void ft_board_setup(void *blob, bd_t *bd)
  275. {
  276. ft_cpu_setup(blob, bd);
  277. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  278. }
  279. int board_eth_init(bd_t *bis)
  280. {
  281. cpu_eth_init(bis); /* Built in FEC comes first */
  282. return pci_eth_init(bis);
  283. }