at91sam9263ek.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/arch/at91sam9263.h>
  26. #include <asm/arch/at91sam9263_matrix.h>
  27. #include <asm/arch/at91sam9_smc.h>
  28. #include <asm/arch/at91_pmc.h>
  29. #include <asm/arch/at91_rstc.h>
  30. #include <asm/arch/gpio.h>
  31. #include <asm/arch/io.h>
  32. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  33. #include <net.h>
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /* ------------------------------------------------------------------------- */
  37. /*
  38. * Miscelaneous platform dependent initialisations
  39. */
  40. static void at91sam9263ek_serial_hw_init(void)
  41. {
  42. #ifdef CONFIG_USART0
  43. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  44. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  45. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0);
  46. #endif
  47. #ifdef CONFIG_USART1
  48. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  49. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  50. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1);
  51. #endif
  52. #ifdef CONFIG_USART2
  53. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  54. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  55. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2);
  56. #endif
  57. #ifdef CONFIG_USART3 /* DBGU */
  58. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  59. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  60. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  61. #endif
  62. }
  63. #ifdef CONFIG_CMD_NAND
  64. static void at91sam9263ek_nand_hw_init(void)
  65. {
  66. unsigned long csa;
  67. /* Enable CS3 */
  68. csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
  69. at91_sys_write(AT91_MATRIX_EBI0CSA,
  70. csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
  71. /* Configure SMC CS3 for NAND/SmartMedia */
  72. at91_sys_write(AT91_SMC_SETUP(3),
  73. AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0) |
  74. AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  75. at91_sys_write(AT91_SMC_PULSE(3),
  76. AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
  77. AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  78. at91_sys_write(AT91_SMC_CYCLE(3),
  79. AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  80. at91_sys_write(AT91_SMC_MODE(3),
  81. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  82. AT91_SMC_EXNWMODE_DISABLE |
  83. #ifdef CFG_NAND_DBW_16
  84. AT91_SMC_DBW_16 |
  85. #else /* CFG_NAND_DBW_8 */
  86. AT91_SMC_DBW_8 |
  87. #endif
  88. AT91_SMC_TDF_(2));
  89. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_PIOA |
  90. 1 << AT91SAM9263_ID_PIOCDE);
  91. /* Configure RDY/BSY */
  92. at91_set_gpio_input(AT91_PIN_PA22, 1);
  93. /* Enable NandFlash */
  94. at91_set_gpio_output(AT91_PIN_PD15, 1);
  95. }
  96. #endif
  97. #ifdef CONFIG_HAS_DATAFLASH
  98. static void at91sam9263ek_spi_hw_init(void)
  99. {
  100. at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
  101. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  102. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  103. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  104. /* Enable clock */
  105. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_SPI0);
  106. }
  107. #endif
  108. #ifdef CONFIG_MACB
  109. static void at91sam9263ek_macb_hw_init(void)
  110. {
  111. /* Enable clock */
  112. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_EMAC);
  113. /*
  114. * Disable pull-up on:
  115. * RXDV (PC25) => PHY normal mode (not Test mode)
  116. * ERX0 (PE25) => PHY ADDR0
  117. * ERX1 (PE26) => PHY ADDR1 => PHYADDR = 0x0
  118. *
  119. * PHY has internal pull-down
  120. */
  121. writel(pin_to_mask(AT91_PIN_PC25),
  122. pin_to_controller(AT91_PIN_PC0) + PIO_PUDR);
  123. writel(pin_to_mask(AT91_PIN_PE25) |
  124. pin_to_mask(AT91_PIN_PE26),
  125. pin_to_controller(AT91_PIN_PE0) + PIO_PUDR);
  126. /* Need to reset PHY -> 500ms reset */
  127. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  128. AT91_RSTC_ERSTL | (0x0D << 8) |
  129. AT91_RSTC_URSTEN);
  130. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  131. /* Wait for end hardware reset */
  132. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  133. /* Re-enable pull-up */
  134. writel(pin_to_mask(AT91_PIN_PC25),
  135. pin_to_controller(AT91_PIN_PC0) + PIO_PUER);
  136. writel(pin_to_mask(AT91_PIN_PE25) |
  137. pin_to_mask(AT91_PIN_PE26),
  138. pin_to_controller(AT91_PIN_PE0) + PIO_PUER);
  139. at91_set_A_periph(AT91_PIN_PE21, 0); /* ETXCK_EREFCK */
  140. at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
  141. at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
  142. at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
  143. at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
  144. at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
  145. at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
  146. at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
  147. at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
  148. at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
  149. #ifndef CONFIG_RMII
  150. at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
  151. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  152. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  153. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  154. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  155. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  156. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  157. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  158. #endif
  159. }
  160. #endif
  161. #ifdef CONFIG_USB_OHCI_NEW
  162. static void at91sam9263ek_uhp_hw_init(void)
  163. {
  164. /* Enable VBus on UHP ports */
  165. at91_set_gpio_output(AT91_PIN_PA21, 0);
  166. at91_set_gpio_output(AT91_PIN_PA24, 0);
  167. }
  168. #endif
  169. int board_init(void)
  170. {
  171. /* Enable Ctrlc */
  172. console_init_f();
  173. /* arch number of AT91SAM9263EK-Board */
  174. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9263EK;
  175. /* adress of boot parameters */
  176. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  177. at91sam9263ek_serial_hw_init();
  178. #ifdef CONFIG_CMD_NAND
  179. at91sam9263ek_nand_hw_init();
  180. #endif
  181. #ifdef CONFIG_HAS_DATAFLASH
  182. at91sam9263ek_spi_hw_init();
  183. #endif
  184. #ifdef CONFIG_MACB
  185. at91sam9263ek_macb_hw_init();
  186. #endif
  187. #ifdef CONFIG_USB_OHCI_NEW
  188. at91sam9263ek_uhp_hw_init();
  189. #endif
  190. return 0;
  191. }
  192. int dram_init(void)
  193. {
  194. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  195. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  196. return 0;
  197. }
  198. #ifdef CONFIG_RESET_PHY_R
  199. void reset_phy(void)
  200. {
  201. #ifdef CONFIG_MACB
  202. /*
  203. * Initialize ethernet HW addr prior to starting Linux,
  204. * needed for nfsroot
  205. */
  206. eth_init(gd->bd);
  207. #endif
  208. }
  209. #endif