qong.c 5.9 KB

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