balloon3.c 4.7 KB

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