at91sam9260ek.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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/at91sam9260.h>
  26. #include <asm/arch/at91sam9260_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. #include <asm/arch/hardware.h>
  33. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  34. #include <net.h>
  35. #endif
  36. #include <netdev.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /* ------------------------------------------------------------------------- */
  39. /*
  40. * Miscelaneous platform dependent initialisations
  41. */
  42. static void at91sam9260ek_serial_hw_init(void)
  43. {
  44. #ifdef CONFIG_USART0
  45. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  46. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  47. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0);
  48. #endif
  49. #ifdef CONFIG_USART1
  50. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  51. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  52. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1);
  53. #endif
  54. #ifdef CONFIG_USART2
  55. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  56. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  57. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2);
  58. #endif
  59. #ifdef CONFIG_USART3 /* DBGU */
  60. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  61. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  62. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  63. #endif
  64. }
  65. #ifdef CONFIG_CMD_NAND
  66. static void at91sam9260ek_nand_hw_init(void)
  67. {
  68. unsigned long csa;
  69. /* Enable CS3 */
  70. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  71. at91_sys_write(AT91_MATRIX_EBICSA,
  72. csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  73. /* Configure SMC CS3 for NAND/SmartMedia */
  74. at91_sys_write(AT91_SMC_SETUP(3),
  75. AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0) |
  76. AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  77. at91_sys_write(AT91_SMC_PULSE(3),
  78. AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
  79. AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  80. at91_sys_write(AT91_SMC_CYCLE(3),
  81. AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  82. at91_sys_write(AT91_SMC_MODE(3),
  83. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  84. AT91_SMC_EXNWMODE_DISABLE |
  85. #ifdef CFG_NAND_DBW_16
  86. AT91_SMC_DBW_16 |
  87. #else /* CFG_NAND_DBW_8 */
  88. AT91_SMC_DBW_8 |
  89. #endif
  90. AT91_SMC_TDF_(2));
  91. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
  92. /* Configure RDY/BSY */
  93. at91_set_gpio_input(AT91_PIN_PC13, 1);
  94. /* Enable NandFlash */
  95. at91_set_gpio_output(AT91_PIN_PC14, 1);
  96. }
  97. #endif
  98. #ifdef CONFIG_HAS_DATAFLASH
  99. static void at91sam9260ek_spi_hw_init(void)
  100. {
  101. at91_set_A_periph(AT91_PIN_PA3, 0); /* SPI0_NPCS0 */
  102. at91_set_B_periph(AT91_PIN_PC11, 0); /* SPI0_NPCS1 */
  103. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  104. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  105. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  106. /* Enable clock */
  107. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_SPI0);
  108. }
  109. #endif
  110. #ifdef CONFIG_MACB
  111. static void at91sam9260ek_macb_hw_init(void)
  112. {
  113. /* Enable clock */
  114. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_EMAC);
  115. /*
  116. * Disable pull-up on:
  117. * RXDV (PA17) => PHY normal mode (not Test mode)
  118. * ERX0 (PA14) => PHY ADDR0
  119. * ERX1 (PA15) => PHY ADDR1
  120. * ERX2 (PA25) => PHY ADDR2
  121. * ERX3 (PA26) => PHY ADDR3
  122. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  123. *
  124. * PHY has internal pull-down
  125. */
  126. writel(pin_to_mask(AT91_PIN_PA14) |
  127. pin_to_mask(AT91_PIN_PA15) |
  128. pin_to_mask(AT91_PIN_PA17) |
  129. pin_to_mask(AT91_PIN_PA25) |
  130. pin_to_mask(AT91_PIN_PA26) |
  131. pin_to_mask(AT91_PIN_PA28),
  132. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  133. /* Need to reset PHY -> 500ms reset */
  134. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  135. (AT91_RSTC_ERSTL & (0x0D << 8)) |
  136. AT91_RSTC_URSTEN);
  137. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  138. /* Wait for end hardware reset */
  139. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  140. /* Restore NRST value */
  141. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  142. (AT91_RSTC_ERSTL & (0x0 << 8)) |
  143. AT91_RSTC_URSTEN);
  144. /* Re-enable pull-up */
  145. writel(pin_to_mask(AT91_PIN_PA14) |
  146. pin_to_mask(AT91_PIN_PA15) |
  147. pin_to_mask(AT91_PIN_PA17) |
  148. pin_to_mask(AT91_PIN_PA25) |
  149. pin_to_mask(AT91_PIN_PA26) |
  150. pin_to_mask(AT91_PIN_PA28),
  151. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  152. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  153. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  154. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  155. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  156. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  157. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  158. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  159. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  160. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  161. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  162. #ifndef CONFIG_RMII
  163. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  164. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  165. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  166. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  167. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  168. #if defined(CONFIG_AT91SAM9260EK)
  169. /*
  170. * use PA10, PA11 for ETX2, ETX3.
  171. * PA23 and PA24 are for TWI EEPROM
  172. */
  173. at91_set_B_periph(AT91_PIN_PA10, 0); /* ETX2 */
  174. at91_set_B_periph(AT91_PIN_PA11, 0); /* ETX3 */
  175. #else
  176. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  177. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  178. #endif
  179. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  180. #endif
  181. }
  182. #endif
  183. int board_init(void)
  184. {
  185. /* Enable Ctrlc */
  186. console_init_f();
  187. /* arch number of AT91SAM9260EK-Board */
  188. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9260EK;
  189. /* adress of boot parameters */
  190. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  191. at91sam9260ek_serial_hw_init();
  192. #ifdef CONFIG_CMD_NAND
  193. at91sam9260ek_nand_hw_init();
  194. #endif
  195. #ifdef CONFIG_HAS_DATAFLASH
  196. at91sam9260ek_spi_hw_init();
  197. #endif
  198. #ifdef CONFIG_MACB
  199. at91sam9260ek_macb_hw_init();
  200. #endif
  201. return 0;
  202. }
  203. int dram_init(void)
  204. {
  205. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  206. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  207. return 0;
  208. }
  209. #ifdef CONFIG_RESET_PHY_R
  210. void reset_phy(void)
  211. {
  212. #ifdef CONFIG_MACB
  213. /*
  214. * Initialize ethernet HW addr prior to starting Linux,
  215. * needed for nfsroot
  216. */
  217. eth_init(gd->bd);
  218. #endif
  219. }
  220. #endif
  221. int board_eth_init(bd_t *bis)
  222. {
  223. int rc = 0;
  224. #ifdef CONFIG_MACB
  225. rc = macb_eth_initialize(0, (void *)AT91_BASE_EMAC, 0x00);
  226. #endif
  227. return rc;
  228. }