mvbc_p.c 7.5 KB

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