stamp9g20.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * Achim Ehrlich <aehrlich@taskit.de>
  7. * taskit GmbH <www.taskit.de>
  8. *
  9. * (C) Copyright 2012-
  10. * Markus Hubig <mhubig@imko.de>
  11. * IMKO GmbH <www.imko.de>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <common.h>
  32. #include <asm/io.h>
  33. #include <asm/arch/at91sam9260_matrix.h>
  34. #include <asm/arch/at91sam9_smc.h>
  35. #include <asm/arch/at91_common.h>
  36. #include <asm/arch/at91_pmc.h>
  37. #include <asm/arch/at91_rstc.h>
  38. #include <asm/arch/gpio.h>
  39. #include <watchdog.h>
  40. #ifdef CONFIG_MACB
  41. # include <net.h>
  42. # include <netdev.h>
  43. #endif
  44. DECLARE_GLOBAL_DATA_PTR;
  45. static void stamp9G20_nand_hw_init(void)
  46. {
  47. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  48. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  49. unsigned long csa;
  50. /* Assign CS3 to NAND/SmartMedia Interface */
  51. csa = readl(&matrix->ebicsa);
  52. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  53. writel(csa, &matrix->ebicsa);
  54. /* Configure SMC CS3 for NAND/SmartMedia */
  55. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  56. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  57. &smc->cs[3].setup);
  58. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  59. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  60. &smc->cs[3].pulse);
  61. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  62. &smc->cs[3].cycle);
  63. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  64. AT91_SMC_MODE_EXNW_DISABLE |
  65. AT91_SMC_MODE_DBW_8 |
  66. AT91_SMC_MODE_TDF_CYCLE(2),
  67. &smc->cs[3].mode);
  68. /* Configure RDY/BSY */
  69. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  70. /* Enable NandFlash */
  71. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  72. }
  73. #ifdef CONFIG_MACB
  74. static void stamp9G20_macb_hw_init(void)
  75. {
  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 the PHY Chip via PA26 on the Stamp 2 Adaptor */
  80. at91_set_gpio_output(AT91_PIN_PA26, 0);
  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_PA18) |
  96. pin_to_mask(AT91_PIN_PA28),
  97. &pioa->pudr);
  98. erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  99. /* Need to reset PHY -> 500ms reset */
  100. writel(AT91_RSTC_KEY | (AT91_RSTC_MR_ERSTL(13) &
  101. ~AT91_RSTC_MR_URSTEN), &rstc->mr);
  102. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  103. /* Wait for end of hardware reset */
  104. unsigned long start = get_timer(0);
  105. unsigned long timeout = 1000; /* 1000ms */
  106. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
  107. /* avoid shutdown by watchdog */
  108. WATCHDOG_RESET();
  109. mdelay(10);
  110. /* timeout for not getting stuck in an endless loop */
  111. if (get_timer(start) >= timeout) {
  112. puts("*** ERROR: Timeout waiting for PHY reset!\n");
  113. break;
  114. };
  115. };
  116. /* Restore NRST value */
  117. writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
  118. &rstc->mr);
  119. /* Re-enable pull-up */
  120. writel(pin_to_mask(AT91_PIN_PA14) |
  121. pin_to_mask(AT91_PIN_PA15) |
  122. pin_to_mask(AT91_PIN_PA17) |
  123. pin_to_mask(AT91_PIN_PA18) |
  124. pin_to_mask(AT91_PIN_PA28),
  125. &pioa->puer);
  126. /* Initialize EMAC=MACB hardware */
  127. at91_macb_hw_init();
  128. }
  129. #endif /* CONFIG_MACB */
  130. int board_early_init_f(void)
  131. {
  132. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  133. /* Enable clocks for all PIOs */
  134. writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
  135. (1 << ATMEL_ID_PIOC), &pmc->pcer);
  136. return 0;
  137. }
  138. int board_init(void)
  139. {
  140. /* Adress of boot parameters */
  141. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  142. /* Enable the serial interface */
  143. at91_set_gpio_output(AT91_PIN_PC9, 1);
  144. at91_seriald_hw_init();
  145. stamp9G20_nand_hw_init();
  146. #ifdef CONFIG_MACB
  147. stamp9G20_macb_hw_init();
  148. #endif
  149. return 0;
  150. }
  151. int dram_init(void)
  152. {
  153. gd->ram_size = get_ram_size(
  154. (void *)CONFIG_SYS_SDRAM_BASE,
  155. CONFIG_SYS_SDRAM_SIZE);
  156. return 0;
  157. }
  158. #ifdef CONFIG_MACB
  159. int board_eth_init(bd_t *bis)
  160. {
  161. return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  162. }
  163. #endif /* CONFIG_MACB */