qong.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 <fsl_pmic.h>
  29. #include "qong_fpga.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int dram_init (void)
  32. {
  33. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  34. gd->bd->bi_dram[0].size = get_ram_size((volatile void *)PHYS_SDRAM_1,
  35. PHYS_SDRAM_1_SIZE);
  36. return 0;
  37. }
  38. static void qong_fpga_reset(void)
  39. {
  40. mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
  41. udelay(30);
  42. mx31_gpio_set(QONG_FPGA_RST_PIN, 1);
  43. udelay(300);
  44. }
  45. int board_init (void)
  46. {
  47. /* Chip selects */
  48. /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */
  49. /* Assumptions: HCLK = 133 MHz, tACC = 130ns */
  50. __REG(CSCR_U(0)) = ((0 << 31) | /* SP */
  51. (0 << 30) | /* WP */
  52. (0 << 28) | /* BCD */
  53. (0 << 24) | /* BCS */
  54. (0 << 22) | /* PSZ */
  55. (0 << 21) | /* PME */
  56. (0 << 20) | /* SYNC */
  57. (0 << 16) | /* DOL */
  58. (3 << 14) | /* CNC */
  59. (21 << 8) | /* WSC */
  60. (0 << 7) | /* EW */
  61. (0 << 4) | /* WWS */
  62. (6 << 0) /* EDC */
  63. );
  64. __REG(CSCR_L(0)) = ((2 << 28) | /* OEA */
  65. (1 << 24) | /* OEN */
  66. (3 << 20) | /* EBWA */
  67. (3 << 16) | /* EBWN */
  68. (1 << 12) | /* CSA */
  69. (1 << 11) | /* EBC */
  70. (5 << 8) | /* DSZ */
  71. (1 << 4) | /* CSN */
  72. (0 << 3) | /* PSR */
  73. (0 << 2) | /* CRE */
  74. (0 << 1) | /* WRAP */
  75. (1 << 0) /* CSEN */
  76. );
  77. __REG(CSCR_A(0)) = ((2 << 28) | /* EBRA */
  78. (1 << 24) | /* EBRN */
  79. (2 << 20) | /* RWA */
  80. (2 << 16) | /* RWN */
  81. (0 << 15) | /* MUM */
  82. (0 << 13) | /* LAH */
  83. (2 << 10) | /* LBN */
  84. (0 << 8) | /* LBA */
  85. (0 << 6) | /* DWW */
  86. (0 << 4) | /* DCT */
  87. (0 << 3) | /* WWU */
  88. (0 << 2) | /* AGE */
  89. (0 << 1) | /* CNC2 */
  90. (0 << 0) /* FCE */
  91. );
  92. #ifdef CONFIG_QONG_FPGA
  93. /* CS1: FPGA/Network Controller/GPIO */
  94. /* 16-bit, no DTACK */
  95. __REG(CSCR_U(1)) = 0x00000A01;
  96. __REG(CSCR_L(1)) = 0x20040501;
  97. __REG(CSCR_A(1)) = 0x04020C00;
  98. /* setup pins for FPGA */
  99. mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
  100. mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
  101. mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
  102. mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
  103. mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
  104. /* FPGA reset Pin */
  105. /* rstn = 0 */
  106. mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
  107. mx31_gpio_direction(QONG_FPGA_RST_PIN, MX31_GPIO_DIRECTION_OUT);
  108. /* set interrupt pin as input */
  109. mx31_gpio_direction(QONG_FPGA_IRQ_PIN, MX31_GPIO_DIRECTION_IN);
  110. #endif
  111. /* setup pins for UART1 */
  112. mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
  113. mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
  114. mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
  115. mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
  116. /* setup pins for SPI (pmic) */
  117. mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B);
  118. mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI);
  119. mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO);
  120. mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK);
  121. mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B);
  122. /* board id for linux */
  123. gd->bd->bi_arch_number = MACH_TYPE_QONG;
  124. gd->bd->bi_boot_params = (0x80000100); /* adress of boot parameters */
  125. return 0;
  126. }
  127. int board_late_init(void)
  128. {
  129. u32 val;
  130. /* Enable RTC battery */
  131. val = pmic_reg_read(REG_POWER_CTL0);
  132. pmic_reg_write(REG_POWER_CTL0, val | COINCHEN);
  133. pmic_reg_write(REG_INT_STATUS1, RTCRSTI);
  134. return 0;
  135. }
  136. int checkboard (void)
  137. {
  138. printf("Board: DAVE/DENX Qong\n");
  139. return 0;
  140. }
  141. int misc_init_r (void)
  142. {
  143. #ifdef CONFIG_QONG_FPGA
  144. u32 tmp;
  145. tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
  146. printf("FPGA: ");
  147. printf("version register = %u.%u.%u\n",
  148. (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
  149. #endif
  150. return 0;
  151. }
  152. int board_eth_init(bd_t *bis)
  153. {
  154. #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
  155. return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
  156. #else
  157. return 0;
  158. #endif
  159. }
  160. #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
  161. static void board_nand_setup(void)
  162. {
  163. /* CS3: NAND 8-bit */
  164. __REG(CSCR_U(3)) = 0x00004f00;
  165. __REG(CSCR_L(3)) = 0x20013b31;
  166. __REG(CSCR_A(3)) = 0x00020800;
  167. __REG(IOMUXC_GPR) |= 1 << 13;
  168. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
  169. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
  170. mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
  171. /* Make sure to reset the fpga else you cannot access NAND */
  172. qong_fpga_reset();
  173. /* Enable NAND flash */
  174. mx31_gpio_set(15, 1);
  175. mx31_gpio_set(14, 1);
  176. mx31_gpio_direction(15, MX31_GPIO_DIRECTION_OUT);
  177. mx31_gpio_direction(16, MX31_GPIO_DIRECTION_IN);
  178. mx31_gpio_direction(14, MX31_GPIO_DIRECTION_IN);
  179. mx31_gpio_set(15, 0);
  180. }
  181. int qong_nand_rdy(void *chip)
  182. {
  183. udelay(1);
  184. return mx31_gpio_get(16);
  185. }
  186. void qong_nand_select_chip(struct mtd_info *mtd, int chip)
  187. {
  188. if (chip >= 0)
  189. mx31_gpio_set(15, 0);
  190. else
  191. mx31_gpio_set(15, 1);
  192. }
  193. void qong_nand_plat_init(void *chip)
  194. {
  195. struct nand_chip *nand = (struct nand_chip *)chip;
  196. nand->chip_delay = 20;
  197. nand->select_chip = qong_nand_select_chip;
  198. nand->options &= ~NAND_BUSWIDTH_16;
  199. board_nand_setup();
  200. }
  201. #endif