afeb9260.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. * (C) Copyright 2008 Sergey Lapin <slapin@ossfans.org>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/arch/at91sam9260.h>
  27. #include <asm/arch/at91sam9260_matrix.h>
  28. #include <asm/arch/at91sam9_smc.h>
  29. #include <asm/arch/at91_pmc.h>
  30. #include <asm/arch/at91_rstc.h>
  31. #include <asm/arch/gpio.h>
  32. #include <asm/arch/io.h>
  33. #include <asm/arch/hardware.h>
  34. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  35. #include <netdev.h>
  36. #include <net.h>
  37. #endif
  38. DECLARE_GLOBAL_DATA_PTR;
  39. /* ------------------------------------------------------------------------- */
  40. /*
  41. * Miscelaneous platform dependent initialisations
  42. */
  43. static void afeb9260_serial_hw_init(void)
  44. {
  45. #ifdef CONFIG_USART0
  46. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  47. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  48. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US0);
  49. #endif
  50. #ifdef CONFIG_USART1
  51. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  52. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  53. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US1);
  54. #endif
  55. #ifdef CONFIG_USART2
  56. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  57. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  58. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US2);
  59. #endif
  60. #ifdef CONFIG_USART3 /* DBGU */
  61. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  62. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  63. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  64. #endif
  65. }
  66. static void afeb9260_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_(0) | AT91_SMC_NCS_WRSETUP_(0) |
  76. AT91_SMC_NRDSETUP_(0) | 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. AT91_SMC_DBW_8 |
  86. AT91_SMC_TDF_(2));
  87. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
  88. /* Configure RDY/BSY */
  89. at91_set_gpio_input(AT91_PIN_PC13, 1);
  90. /* Enable NandFlash */
  91. at91_set_gpio_output(AT91_PIN_PC14, 1);
  92. }
  93. static void afeb9260_spi_hw_init(void)
  94. {
  95. at91_set_A_periph(AT91_PIN_PA3, 0); /* SPI0_NPCS0 */
  96. at91_set_B_periph(AT91_PIN_PC11, 0); /* SPI0_NPCS1 */
  97. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  98. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  99. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  100. /* Enable clock */
  101. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_SPI0);
  102. }
  103. #ifdef CONFIG_MACB
  104. static void afeb9260_macb_hw_init(void)
  105. {
  106. /* Enable clock */
  107. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_EMAC);
  108. /*
  109. * Disable pull-up on:
  110. * RXDV (PA17) => PHY normal mode (not Test mode)
  111. * ERX0 (PA14) => PHY ADDR0
  112. * ERX1 (PA15) => PHY ADDR1
  113. * ERX2 (PA25) => PHY ADDR2
  114. * ERX3 (PA26) => PHY ADDR3
  115. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  116. *
  117. * PHY has internal pull-down
  118. */
  119. writel(pin_to_mask(AT91_PIN_PA14) |
  120. pin_to_mask(AT91_PIN_PA15) |
  121. pin_to_mask(AT91_PIN_PA17) |
  122. pin_to_mask(AT91_PIN_PA25) |
  123. pin_to_mask(AT91_PIN_PA26) |
  124. pin_to_mask(AT91_PIN_PA28),
  125. pin_to_controller(AT91_PIN_PA0) + 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. /* Restore NRST value */
  134. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  135. AT91_RSTC_ERSTL | (0x0 << 8) |
  136. AT91_RSTC_URSTEN);
  137. /* Re-enable pull-up */
  138. writel(pin_to_mask(AT91_PIN_PA14) |
  139. pin_to_mask(AT91_PIN_PA15) |
  140. pin_to_mask(AT91_PIN_PA17) |
  141. pin_to_mask(AT91_PIN_PA25) |
  142. pin_to_mask(AT91_PIN_PA26) |
  143. pin_to_mask(AT91_PIN_PA28),
  144. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  145. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  146. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  147. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  148. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  149. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  150. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  151. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  152. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  153. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  154. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  155. #ifndef CONFIG_RMII
  156. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  157. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  158. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  159. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  160. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  161. at91_set_B_periph(AT91_PIN_PA10, 0); /* ETX2 */
  162. at91_set_B_periph(AT91_PIN_PA11, 0); /* ETX3 */
  163. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  164. #endif
  165. }
  166. #endif
  167. int board_init(void)
  168. {
  169. /* Enable Ctrlc */
  170. console_init_f();
  171. /* arch number of AT91SAM9260EK-Board */
  172. gd->bd->bi_arch_number = MACH_TYPE_AFEB9260;
  173. /* adress of boot parameters */
  174. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  175. afeb9260_serial_hw_init();
  176. #ifdef CONFIG_CMD_NAND
  177. afeb9260_nand_hw_init();
  178. #endif
  179. afeb9260_spi_hw_init();
  180. #ifdef CONFIG_MACB
  181. afeb9260_macb_hw_init();
  182. #endif
  183. return 0;
  184. }
  185. int dram_init(void)
  186. {
  187. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  188. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  189. return 0;
  190. }
  191. #ifdef CONFIG_RESET_PHY_R
  192. void reset_phy(void)
  193. {
  194. #ifdef CONFIG_MACB
  195. /*
  196. * Initialize ethernet HW addr prior to starting Linux,
  197. * needed for nfsroot
  198. */
  199. eth_init(gd->bd);
  200. #endif
  201. }
  202. #endif
  203. int board_eth_init(bd_t *bis)
  204. {
  205. int rc = 0;
  206. #ifdef CONFIG_MACB
  207. rc = macb_eth_initialize(0, (void *)AT91SAM9260_BASE_EMAC, 0x00);
  208. #endif
  209. return rc;
  210. }