qong.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. *
  3. * (c) 2009 Emcraft Systems, Ilya Yanok <yanok@emcraft.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <netdev.h>
  25. #include <asm/arch/mx31.h>
  26. #include <asm/arch/mx31-regs.h>
  27. #include <nand.h>
  28. #include "qong_fpga.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. int dram_init (void)
  31. {
  32. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  33. gd->bd->bi_dram[0].size = get_ram_size((volatile void *)PHYS_SDRAM_1,
  34. PHYS_SDRAM_1_SIZE);
  35. return 0;
  36. }
  37. static void qong_fpga_reset(void)
  38. {
  39. mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
  40. udelay(30);
  41. mx31_gpio_set(QONG_FPGA_RST_PIN, 1);
  42. udelay(300);
  43. }
  44. int board_init (void)
  45. {
  46. /* Chip selects */
  47. /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */
  48. /* Assumptions: HCLK = 133 MHz, tACC = 130ns */
  49. __REG(CSCR_U(0)) = ((0 << 31) | /* SP */
  50. (0 << 30) | /* WP */
  51. (0 << 28) | /* BCD */
  52. (0 << 24) | /* BCS */
  53. (0 << 22) | /* PSZ */
  54. (0 << 21) | /* PME */
  55. (0 << 20) | /* SYNC */
  56. (0 << 16) | /* DOL */
  57. (3 << 14) | /* CNC */
  58. (21 << 8) | /* WSC */
  59. (0 << 7) | /* EW */
  60. (0 << 4) | /* WWS */
  61. (6 << 0) /* EDC */
  62. );
  63. __REG(CSCR_L(0)) = ((2 << 28) | /* OEA */
  64. (1 << 24) | /* OEN */
  65. (3 << 20) | /* EBWA */
  66. (3 << 16) | /* EBWN */
  67. (1 << 12) | /* CSA */
  68. (1 << 11) | /* EBC */
  69. (5 << 8) | /* DSZ */
  70. (1 << 4) | /* CSN */
  71. (0 << 3) | /* PSR */
  72. (0 << 2) | /* CRE */
  73. (0 << 1) | /* WRAP */
  74. (1 << 0) /* CSEN */
  75. );
  76. __REG(CSCR_A(0)) = ((2 << 28) | /* EBRA */
  77. (1 << 24) | /* EBRN */
  78. (2 << 20) | /* RWA */
  79. (2 << 16) | /* RWN */
  80. (0 << 15) | /* MUM */
  81. (0 << 13) | /* LAH */
  82. (2 << 10) | /* LBN */
  83. (0 << 8) | /* LBA */
  84. (0 << 6) | /* DWW */
  85. (0 << 4) | /* DCT */
  86. (0 << 3) | /* WWU */
  87. (0 << 2) | /* AGE */
  88. (0 << 1) | /* CNC2 */
  89. (0 << 0) /* FCE */
  90. );
  91. #ifdef CONFIG_QONG_FPGA
  92. /* CS1: FPGA/Network Controller/GPIO */
  93. /* 16-bit, no DTACK */
  94. __REG(CSCR_U(1)) = 0x00000A01;
  95. __REG(CSCR_L(1)) = 0x20040501;
  96. __REG(CSCR_A(1)) = 0x04020C00;
  97. /* setup pins for FPGA */
  98. mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
  99. mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
  100. mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
  101. mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
  102. mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
  103. /* FPGA reset Pin */
  104. /* rstn = 0 */
  105. mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
  106. mx31_gpio_direction(QONG_FPGA_RST_PIN, MX31_GPIO_DIRECTION_OUT);
  107. /* set interrupt pin as input */
  108. mx31_gpio_direction(QONG_FPGA_IRQ_PIN, MX31_GPIO_DIRECTION_IN);
  109. #endif
  110. /* setup pins for UART1 */
  111. mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
  112. mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
  113. mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
  114. mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
  115. /* board id for linux */
  116. gd->bd->bi_arch_number = MACH_TYPE_QONG;
  117. gd->bd->bi_boot_params = (0x80000100); /* adress of boot parameters */
  118. return 0;
  119. }
  120. int checkboard (void)
  121. {
  122. printf("Board: DAVE/DENX Qong\n");
  123. return 0;
  124. }
  125. int misc_init_r (void)
  126. {
  127. #ifdef CONFIG_QONG_FPGA
  128. u32 tmp;
  129. tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
  130. printf("FPGA: ");
  131. printf("version register = %u.%u.%u\n",
  132. (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
  133. #endif
  134. return 0;
  135. }
  136. int board_eth_init(bd_t *bis)
  137. {
  138. #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
  139. return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
  140. #else
  141. return 0;
  142. #endif
  143. }
  144. #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
  145. static void board_nand_setup(void)
  146. {
  147. /* CS3: NAND 8-bit */
  148. __REG(CSCR_U(3)) = 0x00004f00;
  149. __REG(CSCR_L(3)) = 0x20013b31;
  150. __REG(CSCR_A(3)) = 0x00020800;
  151. __REG(IOMUXC_GPR) |= 1 << 13;
  152. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
  153. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
  154. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
  155. /* Make sure to reset the fpga else you cannot access NAND */
  156. qong_fpga_reset();
  157. /* Enable NAND flash */
  158. mx31_gpio_set(15, 1);
  159. mx31_gpio_set(14, 1);
  160. mx31_gpio_direction(15, MX31_GPIO_DIRECTION_OUT);
  161. mx31_gpio_direction(16, MX31_GPIO_DIRECTION_IN);
  162. mx31_gpio_direction(14, MX31_GPIO_DIRECTION_IN);
  163. mx31_gpio_set(15, 0);
  164. }
  165. int qong_nand_rdy(void *chip)
  166. {
  167. udelay(1);
  168. return mx31_gpio_get(16);
  169. }
  170. void qong_nand_select_chip(struct mtd_info *mtd, int chip)
  171. {
  172. if (chip >= 0)
  173. mx31_gpio_set(15, 0);
  174. else
  175. mx31_gpio_set(15, 1);
  176. }
  177. void qong_nand_plat_init(void *chip)
  178. {
  179. struct nand_chip *nand = (struct nand_chip *)chip;
  180. nand->chip_delay = 20;
  181. nand->select_chip = qong_nand_select_chip;
  182. nand->options &= ~NAND_BUSWIDTH_16;
  183. board_nand_setup();
  184. }
  185. #endif