balloon3.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Balloon3 Support
  3. *
  4. * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #include <common.h>
  22. #include <asm/arch/hardware.h>
  23. #include <serial.h>
  24. #include <asm/io.h>
  25. #include <spartan3.h>
  26. #include <command.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. void balloon3_init_fpga(void);
  29. /*
  30. * Miscelaneous platform dependent initialisations
  31. */
  32. int board_init(void)
  33. {
  34. /* arch number of vpac270 */
  35. gd->bd->bi_arch_number = MACH_TYPE_BALLOON3;
  36. /* adress of boot parameters */
  37. gd->bd->bi_boot_params = 0xa0000100;
  38. /* Init the FPGA */
  39. balloon3_init_fpga();
  40. return 0;
  41. }
  42. struct serial_device *default_serial_console(void)
  43. {
  44. return &serial_stuart_device;
  45. }
  46. int dram_init(void)
  47. {
  48. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  49. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  50. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  51. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  52. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  53. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  54. return 0;
  55. }
  56. #ifdef CONFIG_CMD_USB
  57. int usb_board_init(void)
  58. {
  59. writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
  60. ~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
  61. UHCHR);
  62. writel(readl(UHCHR) | UHCHR_FSBIR, UHCHR);
  63. while (readl(UHCHR) & UHCHR_FSBIR)
  64. ;
  65. writel(readl(UHCHR) & ~UHCHR_SSE, UHCHR);
  66. writel((UHCHIE_UPRIE | UHCHIE_RWIE), UHCHIE);
  67. /* Clear any OTG Pin Hold */
  68. if (readl(PSSR) & PSSR_OTGPH)
  69. writel(readl(PSSR) | PSSR_OTGPH, PSSR);
  70. writel(readl(UHCRHDA) & ~(0x200), UHCRHDA);
  71. writel(readl(UHCRHDA) | 0x100, UHCRHDA);
  72. /* Set port power control mask bits, only 3 ports. */
  73. writel(readl(UHCRHDB) | (0x7<<17), UHCRHDB);
  74. /* enable port 2 */
  75. writel(readl(UP2OCR) | UP2OCR_HXOE | UP2OCR_HXS |
  76. UP2OCR_DMPDE | UP2OCR_DPPDE, UP2OCR);
  77. return 0;
  78. }
  79. void usb_board_init_fail(void)
  80. {
  81. return;
  82. }
  83. void usb_board_stop(void)
  84. {
  85. writel(readl(UHCHR) | UHCHR_FHR, UHCHR);
  86. udelay(11);
  87. writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR);
  88. writel(readl(UHCCOMS) | 1, UHCCOMS);
  89. udelay(10);
  90. writel(readl(CKEN) & ~CKEN10_USBHOST, CKEN);
  91. return;
  92. }
  93. #endif
  94. #if defined(CONFIG_FPGA)
  95. /* Toggle GPIO103 and GPIO104 -- PROGB and RDnWR */
  96. int fpga_pgm_fn(int nassert, int nflush, int cookie)
  97. {
  98. if (nassert)
  99. writel(0x80, GPCR3);
  100. else
  101. writel(0x80, GPSR3);
  102. if (nflush)
  103. writel(0x100, GPCR3);
  104. else
  105. writel(0x100, GPSR3);
  106. return nassert;
  107. }
  108. /* Check GPIO83 -- INITB */
  109. int fpga_init_fn(int cookie)
  110. {
  111. return !(readl(GPLR2) & 0x80000);
  112. }
  113. /* Check GPIO84 -- BUSY */
  114. int fpga_busy_fn(int cookie)
  115. {
  116. return !(readl(GPLR2) & 0x100000);
  117. }
  118. /* Check GPIO111 -- DONE */
  119. int fpga_done_fn(int cookie)
  120. {
  121. return readl(GPLR3) & 0x8000;
  122. }
  123. /* Configure GPIO104 as GPIO and deassert it */
  124. int fpga_pre_config_fn(int cookie)
  125. {
  126. writel(readl(GAFR3_L) & ~0x30000, GAFR3_L);
  127. writel(0x100, GPCR3);
  128. return 0;
  129. }
  130. /* Configure GPIO104 as nSKTSEL */
  131. int fpga_post_config_fn(int cookie)
  132. {
  133. writel(readl(GAFR3_L) | 0x10000, GAFR3_L);
  134. return 0;
  135. }
  136. /* Toggle RDnWR */
  137. int fpga_wr_fn(int nassert_write, int flush, int cookie)
  138. {
  139. udelay(1000);
  140. if (nassert_write)
  141. writel(0x100, GPCR3);
  142. else
  143. writel(0x100, GPSR3);
  144. return nassert_write;
  145. }
  146. /* Write program to the FPGA */
  147. int fpga_wdata_fn(uchar data, int flush, int cookie)
  148. {
  149. writeb(data, 0x10f00000);
  150. return 0;
  151. }
  152. /* Toggle Clock pin -- NO-OP */
  153. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  154. {
  155. return assert_clk;
  156. }
  157. /* Toggle ChipSelect pin -- NO-OP */
  158. int fpga_cs_fn(int assert_clk, int flush, int cookie)
  159. {
  160. return assert_clk;
  161. }
  162. Xilinx_Spartan3_Slave_Parallel_fns balloon3_fpga_fns = {
  163. fpga_pre_config_fn,
  164. fpga_pgm_fn,
  165. fpga_init_fn,
  166. NULL, /* err */
  167. fpga_done_fn,
  168. fpga_clk_fn,
  169. fpga_cs_fn,
  170. fpga_wr_fn,
  171. NULL, /* rdata */
  172. fpga_wdata_fn,
  173. fpga_busy_fn,
  174. NULL, /* abort */
  175. fpga_post_config_fn,
  176. };
  177. Xilinx_desc fpga = XILINX_XC3S1000_DESC(slave_parallel,
  178. (void *)&balloon3_fpga_fns, 0);
  179. /* Initialize the FPGA */
  180. void balloon3_init_fpga(void)
  181. {
  182. fpga_init();
  183. fpga_add(fpga_xilinx, &fpga);
  184. }
  185. #else
  186. void balloon3_init_fpga(void) {}
  187. #endif /* CONFIG_FPGA */