afeb9260.c 5.0 KB

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