balloon3.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Balloon3 Support
  3. *
  4. * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/hardware.h>
  10. #include <asm/arch/pxa.h>
  11. #include <serial.h>
  12. #include <asm/io.h>
  13. #include <spartan3.h>
  14. #include <command.h>
  15. #include <usb.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. void balloon3_init_fpga(void);
  18. /*
  19. * Miscelaneous platform dependent initialisations
  20. */
  21. int board_init(void)
  22. {
  23. /* We have RAM, disable cache */
  24. dcache_disable();
  25. icache_disable();
  26. /* arch number of balloon3 */
  27. gd->bd->bi_arch_number = MACH_TYPE_BALLOON3;
  28. /* adress of boot parameters */
  29. gd->bd->bi_boot_params = 0xa0000100;
  30. /* Init the FPGA */
  31. balloon3_init_fpga();
  32. return 0;
  33. }
  34. int dram_init(void)
  35. {
  36. pxa2xx_dram_init();
  37. gd->ram_size = PHYS_SDRAM_1_SIZE;
  38. return 0;
  39. }
  40. void dram_init_banksize(void)
  41. {
  42. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  43. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  44. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  45. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  46. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  47. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  48. }
  49. #ifdef CONFIG_CMD_USB
  50. int board_usb_init(int index, enum usb_init_type init)
  51. {
  52. writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
  53. ~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
  54. UHCHR);
  55. writel(readl(UHCHR) | UHCHR_FSBIR, UHCHR);
  56. while (readl(UHCHR) & UHCHR_FSBIR)
  57. ;
  58. writel(readl(UHCHR) & ~UHCHR_SSE, UHCHR);
  59. writel((UHCHIE_UPRIE | UHCHIE_RWIE), UHCHIE);
  60. /* Clear any OTG Pin Hold */
  61. if (readl(PSSR) & PSSR_OTGPH)
  62. writel(readl(PSSR) | PSSR_OTGPH, PSSR);
  63. writel(readl(UHCRHDA) & ~(0x200), UHCRHDA);
  64. writel(readl(UHCRHDA) | 0x100, UHCRHDA);
  65. /* Set port power control mask bits, only 3 ports. */
  66. writel(readl(UHCRHDB) | (0x7<<17), UHCRHDB);
  67. /* enable port 2 */
  68. writel(readl(UP2OCR) | UP2OCR_HXOE | UP2OCR_HXS |
  69. UP2OCR_DMPDE | UP2OCR_DPPDE, UP2OCR);
  70. return 0;
  71. }
  72. int board_usb_cleanup(int index, enum usb_init_type init)
  73. {
  74. return 0;
  75. }
  76. void usb_board_stop(void)
  77. {
  78. writel(readl(UHCHR) | UHCHR_FHR, UHCHR);
  79. udelay(11);
  80. writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR);
  81. writel(readl(UHCCOMS) | 1, UHCCOMS);
  82. udelay(10);
  83. writel(readl(CKEN) & ~CKEN10_USBHOST, CKEN);
  84. return;
  85. }
  86. #endif
  87. #if defined(CONFIG_FPGA)
  88. /* Toggle GPIO103 and GPIO104 -- PROGB and RDnWR */
  89. int fpga_pgm_fn(int nassert, int nflush, int cookie)
  90. {
  91. if (nassert)
  92. writel(0x80, GPCR3);
  93. else
  94. writel(0x80, GPSR3);
  95. if (nflush)
  96. writel(0x100, GPCR3);
  97. else
  98. writel(0x100, GPSR3);
  99. return nassert;
  100. }
  101. /* Check GPIO83 -- INITB */
  102. int fpga_init_fn(int cookie)
  103. {
  104. return !(readl(GPLR2) & 0x80000);
  105. }
  106. /* Check GPIO84 -- BUSY */
  107. int fpga_busy_fn(int cookie)
  108. {
  109. return !(readl(GPLR2) & 0x100000);
  110. }
  111. /* Check GPIO111 -- DONE */
  112. int fpga_done_fn(int cookie)
  113. {
  114. return readl(GPLR3) & 0x8000;
  115. }
  116. /* Configure GPIO104 as GPIO and deassert it */
  117. int fpga_pre_config_fn(int cookie)
  118. {
  119. writel(readl(GAFR3_L) & ~0x30000, GAFR3_L);
  120. writel(0x100, GPCR3);
  121. return 0;
  122. }
  123. /* Configure GPIO104 as nSKTSEL */
  124. int fpga_post_config_fn(int cookie)
  125. {
  126. writel(readl(GAFR3_L) | 0x10000, GAFR3_L);
  127. return 0;
  128. }
  129. /* Toggle RDnWR */
  130. int fpga_wr_fn(int nassert_write, int flush, int cookie)
  131. {
  132. udelay(1000);
  133. if (nassert_write)
  134. writel(0x100, GPCR3);
  135. else
  136. writel(0x100, GPSR3);
  137. return nassert_write;
  138. }
  139. /* Write program to the FPGA */
  140. int fpga_wdata_fn(uchar data, int flush, int cookie)
  141. {
  142. writeb(data, 0x10f00000);
  143. return 0;
  144. }
  145. /* Toggle Clock pin -- NO-OP */
  146. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  147. {
  148. return assert_clk;
  149. }
  150. /* Toggle ChipSelect pin -- NO-OP */
  151. int fpga_cs_fn(int assert_clk, int flush, int cookie)
  152. {
  153. return assert_clk;
  154. }
  155. xilinx_spartan3_slave_parallel_fns balloon3_fpga_fns = {
  156. fpga_pre_config_fn,
  157. fpga_pgm_fn,
  158. fpga_init_fn,
  159. NULL, /* err */
  160. fpga_done_fn,
  161. fpga_clk_fn,
  162. fpga_cs_fn,
  163. fpga_wr_fn,
  164. NULL, /* rdata */
  165. fpga_wdata_fn,
  166. fpga_busy_fn,
  167. NULL, /* abort */
  168. fpga_post_config_fn,
  169. };
  170. xilinx_desc fpga = XILINX_XC3S1000_DESC(slave_parallel,
  171. (void *)&balloon3_fpga_fns, 0);
  172. /* Initialize the FPGA */
  173. void balloon3_init_fpga(void)
  174. {
  175. fpga_init();
  176. fpga_add(fpga_xilinx, &fpga);
  177. }
  178. #else
  179. void balloon3_init_fpga(void) {}
  180. #endif /* CONFIG_FPGA */