at91sam9261ek.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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/at91sam9261.h>
  26. #include <asm/arch/at91sam9261_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_DRIVER_DM9000)
  33. #include <net.h>
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /* ------------------------------------------------------------------------- */
  37. /*
  38. * Miscelaneous platform dependent initialisations
  39. */
  40. static void at91sam9261ek_serial_hw_init(void)
  41. {
  42. #ifdef CONFIG_USART0
  43. at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */
  44. at91_set_A_periph(AT91_PIN_PC9, 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_PC12, 1); /* TXD1 */
  49. at91_set_A_periph(AT91_PIN_PC13, 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_PC14, 1); /* TXD2 */
  54. at91_set_A_periph(AT91_PIN_PC15, 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_PA9, 0); /* DRXD */
  59. at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
  60. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  61. #endif
  62. }
  63. #ifdef CONFIG_CMD_NAND
  64. static void at91sam9261ek_nand_hw_init(void)
  65. {
  66. unsigned long csa;
  67. /* Enable CS3 */
  68. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  69. at91_sys_write(AT91_MATRIX_EBICSA,
  70. csa | AT91_MATRIX_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_(2) | AT91_SMC_NCS_WRPULSE_(5) |
  77. AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
  78. at91_sys_write(AT91_SMC_CYCLE(3),
  79. AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  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_(1));
  89. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_PIOC);
  90. /* Configure RDY/BSY */
  91. at91_set_gpio_input(AT91_PIN_PC15, 1);
  92. /* Enable NandFlash */
  93. at91_set_gpio_output(AT91_PIN_PC14, 1);
  94. at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
  95. at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
  96. }
  97. #endif
  98. #ifdef CONFIG_HAS_DATAFLASH
  99. static void at91sam9261ek_spi_hw_init(void)
  100. {
  101. at91_set_A_periph(AT91_PIN_PA3, 0); /* SPI0_NPCS0 */
  102. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  103. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  104. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  105. /* Enable clock */
  106. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_SPI0);
  107. }
  108. #endif
  109. #ifdef CONFIG_DRIVER_DM9000
  110. static void at91sam9261ek_dm9000_hw_init(void)
  111. {
  112. /* Configure SMC CS2 for DM9000 */
  113. at91_sys_write(AT91_SMC_SETUP(2),
  114. AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0) |
  115. AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
  116. at91_sys_write(AT91_SMC_PULSE(2),
  117. AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(8) |
  118. AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(8));
  119. at91_sys_write(AT91_SMC_CYCLE(2),
  120. AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  121. at91_sys_write(AT91_SMC_MODE(2),
  122. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  123. AT91_SMC_EXNWMODE_DISABLE |
  124. AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16 |
  125. AT91_SMC_TDF_(1));
  126. /* Configure Reset signal as output */
  127. at91_set_gpio_output(AT91_PIN_PC10, 0);
  128. /* Configure Interrupt pin as input, no pull-up */
  129. at91_set_gpio_input(AT91_PIN_PC11, 0);
  130. }
  131. #endif
  132. int board_init(void)
  133. {
  134. /* Enable Ctrlc */
  135. console_init_f();
  136. /* arch number of AT91SAM9261EK-Board */
  137. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
  138. /* adress of boot parameters */
  139. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  140. at91sam9261ek_serial_hw_init();
  141. #ifdef CONFIG_CMD_NAND
  142. at91sam9261ek_nand_hw_init();
  143. #endif
  144. #ifdef CONFIG_HAS_DATAFLASH
  145. at91sam9261ek_spi_hw_init();
  146. #endif
  147. #ifdef CONFIG_DRIVER_DM9000
  148. at91sam9261ek_dm9000_hw_init();
  149. #endif
  150. return 0;
  151. }
  152. int dram_init(void)
  153. {
  154. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  155. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  156. return 0;
  157. }
  158. #ifdef CONFIG_RESET_PHY_R
  159. void reset_phy(void)
  160. {
  161. #ifdef CONFIG_DRIVER_DM9000
  162. /*
  163. * Initialize ethernet HW addr prior to starting Linux,
  164. * needed for nfsroot
  165. */
  166. eth_init(gd->bd);
  167. #endif
  168. }
  169. #endif