sbc35_a9g20.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/arch/at91sam9260.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. #include <asm/arch/io.h>
  36. #include <asm/arch/hardware.h>
  37. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  38. #include <net.h>
  39. #endif
  40. #include <netdev.h>
  41. DECLARE_GLOBAL_DATA_PTR;
  42. /* ------------------------------------------------------------------------- */
  43. /*
  44. * Miscelaneous platform dependent initialisations
  45. */
  46. #ifdef CONFIG_CMD_NAND
  47. static void sbc35_a9g20_nand_hw_init(void)
  48. {
  49. unsigned long csa;
  50. /* Enable CS3 */
  51. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  52. at91_sys_write(AT91_MATRIX_EBICSA,
  53. csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  54. /* Configure SMC CS3 for NAND/SmartMedia */
  55. at91_sys_write(AT91_SMC_SETUP(3),
  56. AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0) |
  57. AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  58. at91_sys_write(AT91_SMC_PULSE(3),
  59. AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
  60. AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  61. at91_sys_write(AT91_SMC_CYCLE(3),
  62. AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  63. at91_sys_write(AT91_SMC_MODE(3),
  64. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  65. AT91_SMC_EXNWMODE_DISABLE |
  66. #ifdef CONFIG_SYS_NAND_DBW_16
  67. AT91_SMC_DBW_16 |
  68. #else /* CONFIG_SYS_NAND_DBW_8 */
  69. AT91_SMC_DBW_8 |
  70. #endif
  71. AT91_SMC_TDF_(2));
  72. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
  73. /* Configure RDY/BSY */
  74. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  75. /* Enable NandFlash */
  76. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  77. }
  78. #endif
  79. #ifdef CONFIG_MACB
  80. static void sbc35_a9g20_macb_hw_init(void)
  81. {
  82. unsigned long rstc;
  83. /* Enable clock */
  84. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_EMAC);
  85. /*
  86. * Disable pull-up on:
  87. * RXDV (PA17) => PHY normal mode (not Test mode)
  88. * ERX0 (PA14) => PHY ADDR0
  89. * ERX1 (PA15) => PHY ADDR1
  90. * ERX2 (PA25) => PHY ADDR2
  91. * ERX3 (PA26) => PHY ADDR3
  92. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  93. *
  94. * PHY has internal pull-down
  95. */
  96. writel(pin_to_mask(AT91_PIN_PA14) |
  97. pin_to_mask(AT91_PIN_PA15) |
  98. pin_to_mask(AT91_PIN_PA17) |
  99. pin_to_mask(AT91_PIN_PA25) |
  100. pin_to_mask(AT91_PIN_PA26) |
  101. pin_to_mask(AT91_PIN_PA28),
  102. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  103. rstc = at91_sys_read(AT91_RSTC_MR) & AT91_RSTC_ERSTL;
  104. /* Need to reset PHY -> 500ms reset */
  105. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  106. (AT91_RSTC_ERSTL & (0x0D << 8)) |
  107. AT91_RSTC_URSTEN);
  108. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  109. /* Wait for end hardware reset */
  110. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  111. /* Restore NRST value */
  112. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  113. (rstc) |
  114. AT91_RSTC_URSTEN);
  115. /* Re-enable pull-up */
  116. writel(pin_to_mask(AT91_PIN_PA14) |
  117. pin_to_mask(AT91_PIN_PA15) |
  118. pin_to_mask(AT91_PIN_PA17) |
  119. pin_to_mask(AT91_PIN_PA25) |
  120. pin_to_mask(AT91_PIN_PA26) |
  121. pin_to_mask(AT91_PIN_PA28),
  122. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  123. at91_macb_hw_init();
  124. }
  125. #endif
  126. int board_init(void)
  127. {
  128. /* Enable Ctrlc */
  129. console_init_f();
  130. gd->bd->bi_arch_number = MACH_TYPE_SBC35_A9G20;
  131. /* adress of boot parameters */
  132. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  133. at91_serial_hw_init();
  134. sbc35_a9g20_nand_hw_init();
  135. #ifdef CONFIG_ATMEL_SPI
  136. at91_spi0_hw_init(1 << 4 | 1 << 5);
  137. #endif
  138. #ifdef CONFIG_MACB
  139. sbc35_a9g20_macb_hw_init();
  140. #endif
  141. return 0;
  142. }
  143. int dram_init(void)
  144. {
  145. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  146. if(get_ram_size((long *) PHYS_SDRAM, PHYS_SDRAM_SIZE) != PHYS_SDRAM_SIZE)
  147. return -1;
  148. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  149. return 0;
  150. }
  151. #ifdef CONFIG_RESET_PHY_R
  152. void reset_phy(void)
  153. {
  154. }
  155. #endif
  156. int board_eth_init(bd_t *bis)
  157. {
  158. int rc = 0;
  159. #ifdef CONFIG_MACB
  160. rc = macb_eth_initialize(0, (void *)AT91SAM9260_BASE_EMAC, 0x00);
  161. #endif
  162. return rc;
  163. }