qong.c 5.9 KB

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