balloon3.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. /* We have RAM, disable cache */
  35. dcache_disable();
  36. icache_disable();
  37. /* arch number of vpac270 */
  38. gd->bd->bi_arch_number = MACH_TYPE_BALLOON3;
  39. /* adress of boot parameters */
  40. gd->bd->bi_boot_params = 0xa0000100;
  41. /* Init the FPGA */
  42. balloon3_init_fpga();
  43. return 0;
  44. }
  45. struct serial_device *default_serial_console(void)
  46. {
  47. return &serial_stuart_device;
  48. }
  49. extern void pxa_dram_init(void);
  50. int dram_init(void)
  51. {
  52. pxa_dram_init();
  53. gd->ram_size = PHYS_SDRAM_1_SIZE;
  54. return 0;
  55. }
  56. void dram_init_banksize(void)
  57. {
  58. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  59. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  60. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  61. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  62. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  63. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  64. }
  65. #ifdef CONFIG_CMD_USB
  66. int usb_board_init(void)
  67. {
  68. writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
  69. ~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
  70. UHCHR);
  71. writel(readl(UHCHR) | UHCHR_FSBIR, UHCHR);
  72. while (readl(UHCHR) & UHCHR_FSBIR)
  73. ;
  74. writel(readl(UHCHR) & ~UHCHR_SSE, UHCHR);
  75. writel((UHCHIE_UPRIE | UHCHIE_RWIE), UHCHIE);
  76. /* Clear any OTG Pin Hold */
  77. if (readl(PSSR) & PSSR_OTGPH)
  78. writel(readl(PSSR) | PSSR_OTGPH, PSSR);
  79. writel(readl(UHCRHDA) & ~(0x200), UHCRHDA);
  80. writel(readl(UHCRHDA) | 0x100, UHCRHDA);
  81. /* Set port power control mask bits, only 3 ports. */
  82. writel(readl(UHCRHDB) | (0x7<<17), UHCRHDB);
  83. /* enable port 2 */
  84. writel(readl(UP2OCR) | UP2OCR_HXOE | UP2OCR_HXS |
  85. UP2OCR_DMPDE | UP2OCR_DPPDE, UP2OCR);
  86. return 0;
  87. }
  88. void usb_board_init_fail(void)
  89. {
  90. return;
  91. }
  92. void usb_board_stop(void)
  93. {
  94. writel(readl(UHCHR) | UHCHR_FHR, UHCHR);
  95. udelay(11);
  96. writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR);
  97. writel(readl(UHCCOMS) | 1, UHCCOMS);
  98. udelay(10);
  99. writel(readl(CKEN) & ~CKEN10_USBHOST, CKEN);
  100. return;
  101. }
  102. #endif
  103. #if defined(CONFIG_FPGA)
  104. /* Toggle GPIO103 and GPIO104 -- PROGB and RDnWR */
  105. int fpga_pgm_fn(int nassert, int nflush, int cookie)
  106. {
  107. if (nassert)
  108. writel(0x80, GPCR3);
  109. else
  110. writel(0x80, GPSR3);
  111. if (nflush)
  112. writel(0x100, GPCR3);
  113. else
  114. writel(0x100, GPSR3);
  115. return nassert;
  116. }
  117. /* Check GPIO83 -- INITB */
  118. int fpga_init_fn(int cookie)
  119. {
  120. return !(readl(GPLR2) & 0x80000);
  121. }
  122. /* Check GPIO84 -- BUSY */
  123. int fpga_busy_fn(int cookie)
  124. {
  125. return !(readl(GPLR2) & 0x100000);
  126. }
  127. /* Check GPIO111 -- DONE */
  128. int fpga_done_fn(int cookie)
  129. {
  130. return readl(GPLR3) & 0x8000;
  131. }
  132. /* Configure GPIO104 as GPIO and deassert it */
  133. int fpga_pre_config_fn(int cookie)
  134. {
  135. writel(readl(GAFR3_L) & ~0x30000, GAFR3_L);
  136. writel(0x100, GPCR3);
  137. return 0;
  138. }
  139. /* Configure GPIO104 as nSKTSEL */
  140. int fpga_post_config_fn(int cookie)
  141. {
  142. writel(readl(GAFR3_L) | 0x10000, GAFR3_L);
  143. return 0;
  144. }
  145. /* Toggle RDnWR */
  146. int fpga_wr_fn(int nassert_write, int flush, int cookie)
  147. {
  148. udelay(1000);
  149. if (nassert_write)
  150. writel(0x100, GPCR3);
  151. else
  152. writel(0x100, GPSR3);
  153. return nassert_write;
  154. }
  155. /* Write program to the FPGA */
  156. int fpga_wdata_fn(uchar data, int flush, int cookie)
  157. {
  158. writeb(data, 0x10f00000);
  159. return 0;
  160. }
  161. /* Toggle Clock pin -- NO-OP */
  162. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  163. {
  164. return assert_clk;
  165. }
  166. /* Toggle ChipSelect pin -- NO-OP */
  167. int fpga_cs_fn(int assert_clk, int flush, int cookie)
  168. {
  169. return assert_clk;
  170. }
  171. Xilinx_Spartan3_Slave_Parallel_fns balloon3_fpga_fns = {
  172. fpga_pre_config_fn,
  173. fpga_pgm_fn,
  174. fpga_init_fn,
  175. NULL, /* err */
  176. fpga_done_fn,
  177. fpga_clk_fn,
  178. fpga_cs_fn,
  179. fpga_wr_fn,
  180. NULL, /* rdata */
  181. fpga_wdata_fn,
  182. fpga_busy_fn,
  183. NULL, /* abort */
  184. fpga_post_config_fn,
  185. };
  186. Xilinx_desc fpga = XILINX_XC3S1000_DESC(slave_parallel,
  187. (void *)&balloon3_fpga_fns, 0);
  188. /* Initialize the FPGA */
  189. void balloon3_init_fpga(void)
  190. {
  191. fpga_init();
  192. fpga_add(fpga_xilinx, &fpga);
  193. }
  194. #else
  195. void balloon3_init_fpga(void) {}
  196. #endif /* CONFIG_FPGA */