sbc35_a9g20.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * Copyright (C) 2009
  7. * Albin Tonnerre, Free-Electrons <albin.tonnerre@free-electrons.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/at91sam9260_matrix.h>
  30. #include <asm/arch/at91sam9_smc.h>
  31. #include <asm/arch/at91_common.h>
  32. #include <asm/arch/at91_pmc.h>
  33. #include <asm/arch/at91_rstc.h>
  34. #include <asm/arch/gpio.h>
  35. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  36. #include <net.h>
  37. #endif
  38. #include <netdev.h>
  39. DECLARE_GLOBAL_DATA_PTR;
  40. /* ------------------------------------------------------------------------- */
  41. /*
  42. * Miscelaneous platform dependent initialisations
  43. */
  44. #ifdef CONFIG_CMD_NAND
  45. static void sbc35_a9g20_nand_hw_init(void)
  46. {
  47. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  48. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  49. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  50. unsigned long csa;
  51. /* Enable CS3 */
  52. csa = readl(&matrix->ebicsa);
  53. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  54. writel(csa, &matrix->ebicsa);
  55. /* Configure SMC CS3 for NAND/SmartMedia */
  56. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  57. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  58. &smc->cs[3].setup);
  59. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  60. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  61. &smc->cs[3].pulse);
  62. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  63. &smc->cs[3].cycle);
  64. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  65. AT91_SMC_MODE_EXNW_DISABLE |
  66. #ifdef CONFIG_SYS_NAND_DBW_16
  67. AT91_SMC_MODE_DBW_16 |
  68. #else /* CONFIG_SYS_NAND_DBW_8 */
  69. AT91_SMC_MODE_DBW_8 |
  70. #endif
  71. AT91_SMC_MODE_TDF_CYCLE(2),
  72. &smc->cs[3].mode);
  73. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  74. /* Configure RDY/BSY */
  75. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  76. /* Enable NandFlash */
  77. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  78. }
  79. #endif
  80. #ifdef CONFIG_MACB
  81. static void sbc35_a9g20_macb_hw_init(void)
  82. {
  83. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  84. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  85. struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
  86. unsigned long erstl;
  87. /* Enable EMAC clock */
  88. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  89. /*
  90. * Disable pull-up on:
  91. * RXDV (PA17) => PHY normal mode (not Test mode)
  92. * ERX0 (PA14) => PHY ADDR0
  93. * ERX1 (PA15) => PHY ADDR1
  94. * ERX2 (PA25) => PHY ADDR2
  95. * ERX3 (PA26) => PHY ADDR3
  96. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  97. *
  98. * PHY has internal pull-down
  99. */
  100. writel(pin_to_mask(AT91_PIN_PA14) |
  101. pin_to_mask(AT91_PIN_PA15) |
  102. pin_to_mask(AT91_PIN_PA17) |
  103. pin_to_mask(AT91_PIN_PA25) |
  104. pin_to_mask(AT91_PIN_PA26) |
  105. pin_to_mask(AT91_PIN_PA28),
  106. &pioa->pudr);
  107. erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  108. /* Need to reset PHY -> 500ms reset */
  109. writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
  110. AT91_RSTC_MR_URSTEN, &rstc->mr);
  111. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  112. /* Wait for end hardware reset */
  113. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
  114. ;
  115. /* Restore NRST value */
  116. writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
  117. &rstc->mr);
  118. /* Re-enable pull-up */
  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. &pioa->puer);
  126. at91_macb_hw_init();
  127. }
  128. #endif
  129. int board_init(void)
  130. {
  131. /* Enable Ctrlc */
  132. console_init_f();
  133. gd->bd->bi_arch_number = MACH_TYPE_SBC35_A9G20;
  134. /* adress of boot parameters */
  135. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  136. at91_seriald_hw_init();
  137. sbc35_a9g20_nand_hw_init();
  138. #ifdef CONFIG_ATMEL_SPI
  139. at91_spi0_hw_init(1 << 4 | 1 << 5);
  140. #endif
  141. #ifdef CONFIG_MACB
  142. sbc35_a9g20_macb_hw_init();
  143. #endif
  144. return 0;
  145. }
  146. int dram_init(void)
  147. {
  148. gd->ram_size = get_ram_size(
  149. (void *)CONFIG_SYS_SDRAM_BASE,
  150. CONFIG_SYS_SDRAM_SIZE);
  151. return 0;
  152. }
  153. #ifdef CONFIG_RESET_PHY_R
  154. void reset_phy(void)
  155. {
  156. }
  157. #endif
  158. int board_eth_init(bd_t *bis)
  159. {
  160. int rc = 0;
  161. #ifdef CONFIG_MACB
  162. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  163. #endif
  164. return rc;
  165. }