mvbc_p.c 7.5 KB

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