at91sam9260ek.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  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/io.h>
  26. #include <asm/arch/at91sam9260_matrix.h>
  27. #include <asm/arch/at91sam9_smc.h>
  28. #include <asm/arch/at91_common.h>
  29. #include <asm/arch/at91_pmc.h>
  30. #include <asm/arch/at91_rstc.h>
  31. #include <asm/arch/gpio.h>
  32. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  33. # include <net.h>
  34. #endif
  35. #include <netdev.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /* ------------------------------------------------------------------------- */
  38. /*
  39. * Miscelaneous platform dependent initialisations
  40. */
  41. #ifdef CONFIG_CMD_NAND
  42. static void at91sam9260ek_nand_hw_init(void)
  43. {
  44. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  45. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  46. unsigned long csa;
  47. /* Assign CS3 to NAND/SmartMedia Interface */
  48. csa = readl(&matrix->ebicsa);
  49. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  50. writel(csa, &matrix->ebicsa);
  51. /* Configure SMC CS3 for NAND/SmartMedia */
  52. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  53. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  54. &smc->cs[3].setup);
  55. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  56. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  57. &smc->cs[3].pulse);
  58. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  59. &smc->cs[3].cycle);
  60. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  61. AT91_SMC_MODE_EXNW_DISABLE |
  62. #ifdef CONFIG_SYS_NAND_DBW_16
  63. AT91_SMC_MODE_DBW_16 |
  64. #else /* CONFIG_SYS_NAND_DBW_8 */
  65. AT91_SMC_MODE_DBW_8 |
  66. #endif
  67. AT91_SMC_MODE_TDF_CYCLE(2),
  68. &smc->cs[3].mode);
  69. /* Configure RDY/BSY */
  70. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  71. /* Enable NandFlash */
  72. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  73. }
  74. #endif
  75. #ifdef CONFIG_MACB
  76. static void at91sam9260ek_macb_hw_init(void)
  77. {
  78. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  79. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  80. struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
  81. unsigned long erstl;
  82. /* Enable EMAC clock */
  83. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  84. /*
  85. * Disable pull-up on:
  86. * RXDV (PA17) => PHY normal mode (not Test mode)
  87. * ERX0 (PA14) => PHY ADDR0
  88. * ERX1 (PA15) => PHY ADDR1
  89. * ERX2 (PA25) => PHY ADDR2
  90. * ERX3 (PA26) => PHY ADDR3
  91. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  92. *
  93. * PHY has internal pull-down
  94. */
  95. writel(pin_to_mask(AT91_PIN_PA14) |
  96. pin_to_mask(AT91_PIN_PA15) |
  97. pin_to_mask(AT91_PIN_PA17) |
  98. pin_to_mask(AT91_PIN_PA25) |
  99. pin_to_mask(AT91_PIN_PA26) |
  100. pin_to_mask(AT91_PIN_PA28),
  101. &pioa->pudr);
  102. erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  103. /* Need to reset PHY -> 500ms reset */
  104. writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
  105. AT91_RSTC_MR_URSTEN, &rstc->mr);
  106. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  107. /* Wait for end hardware reset */
  108. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
  109. ;
  110. /* Restore NRST value */
  111. writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
  112. &rstc->mr);
  113. /* Re-enable pull-up */
  114. writel(pin_to_mask(AT91_PIN_PA14) |
  115. pin_to_mask(AT91_PIN_PA15) |
  116. pin_to_mask(AT91_PIN_PA17) |
  117. pin_to_mask(AT91_PIN_PA25) |
  118. pin_to_mask(AT91_PIN_PA26) |
  119. pin_to_mask(AT91_PIN_PA28),
  120. &pioa->puer);
  121. /* Initialize EMAC=MACB hardware */
  122. at91_macb_hw_init();
  123. }
  124. #endif
  125. int board_early_init_f(void)
  126. {
  127. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  128. /* Enable clocks for all PIOs */
  129. writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
  130. (1 << ATMEL_ID_PIOC),
  131. &pmc->pcer);
  132. return 0;
  133. }
  134. int board_init(void)
  135. {
  136. #ifdef CONFIG_AT91SAM9G20EK
  137. /* arch number of AT91SAM9260EK-Board */
  138. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G20EK;
  139. #else
  140. /* arch number of AT91SAM9260EK-Board */
  141. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9260EK;
  142. #endif
  143. /* adress of boot parameters */
  144. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  145. at91_seriald_hw_init();
  146. #ifdef CONFIG_CMD_NAND
  147. at91sam9260ek_nand_hw_init();
  148. #endif
  149. #ifdef CONFIG_HAS_DATAFLASH
  150. at91_spi0_hw_init((1 << 0) | (1 << 1));
  151. #endif
  152. #ifdef CONFIG_MACB
  153. at91sam9260ek_macb_hw_init();
  154. #endif
  155. return 0;
  156. }
  157. int dram_init(void)
  158. {
  159. gd->ram_size = get_ram_size(
  160. (void *)CONFIG_SYS_SDRAM_BASE,
  161. CONFIG_SYS_SDRAM_SIZE);
  162. return 0;
  163. }
  164. #ifdef CONFIG_RESET_PHY_R
  165. void reset_phy(void)
  166. {
  167. }
  168. #endif
  169. int board_eth_init(bd_t *bis)
  170. {
  171. int rc = 0;
  172. #ifdef CONFIG_MACB
  173. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  174. #endif
  175. return rc;
  176. }