at91sam9260ek.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/at91sam9260_matrix.h>
  11. #include <asm/arch/at91sam9_smc.h>
  12. #include <asm/arch/at91_common.h>
  13. #include <asm/arch/at91_pmc.h>
  14. #include <asm/arch/gpio.h>
  15. #include <atmel_mci.h>
  16. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  17. # include <net.h>
  18. #endif
  19. #include <netdev.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /* ------------------------------------------------------------------------- */
  22. /*
  23. * Miscelaneous platform dependent initialisations
  24. */
  25. #ifdef CONFIG_CMD_NAND
  26. static void at91sam9260ek_nand_hw_init(void)
  27. {
  28. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  29. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  30. unsigned long csa;
  31. /* Assign CS3 to NAND/SmartMedia Interface */
  32. csa = readl(&matrix->ebicsa);
  33. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  34. writel(csa, &matrix->ebicsa);
  35. /* Configure SMC CS3 for NAND/SmartMedia */
  36. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  37. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  38. &smc->cs[3].setup);
  39. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  40. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  41. &smc->cs[3].pulse);
  42. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  43. &smc->cs[3].cycle);
  44. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  45. AT91_SMC_MODE_EXNW_DISABLE |
  46. #ifdef CONFIG_SYS_NAND_DBW_16
  47. AT91_SMC_MODE_DBW_16 |
  48. #else /* CONFIG_SYS_NAND_DBW_8 */
  49. AT91_SMC_MODE_DBW_8 |
  50. #endif
  51. AT91_SMC_MODE_TDF_CYCLE(2),
  52. &smc->cs[3].mode);
  53. /* Configure RDY/BSY */
  54. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  55. /* Enable NandFlash */
  56. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  57. }
  58. #endif
  59. #ifdef CONFIG_MACB
  60. static void at91sam9260ek_macb_hw_init(void)
  61. {
  62. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  63. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  64. /* Enable EMAC clock */
  65. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  66. /*
  67. * Disable pull-up on:
  68. * RXDV (PA17) => PHY normal mode (not Test mode)
  69. * ERX0 (PA14) => PHY ADDR0
  70. * ERX1 (PA15) => PHY ADDR1
  71. * ERX2 (PA25) => PHY ADDR2
  72. * ERX3 (PA26) => PHY ADDR3
  73. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  74. *
  75. * PHY has internal pull-down
  76. */
  77. writel(pin_to_mask(AT91_PIN_PA14) |
  78. pin_to_mask(AT91_PIN_PA15) |
  79. pin_to_mask(AT91_PIN_PA17) |
  80. pin_to_mask(AT91_PIN_PA25) |
  81. pin_to_mask(AT91_PIN_PA26) |
  82. pin_to_mask(AT91_PIN_PA28),
  83. &pioa->pudr);
  84. at91_phy_reset();
  85. /* Re-enable pull-up */
  86. writel(pin_to_mask(AT91_PIN_PA14) |
  87. pin_to_mask(AT91_PIN_PA15) |
  88. pin_to_mask(AT91_PIN_PA17) |
  89. pin_to_mask(AT91_PIN_PA25) |
  90. pin_to_mask(AT91_PIN_PA26) |
  91. pin_to_mask(AT91_PIN_PA28),
  92. &pioa->puer);
  93. /* Initialize EMAC=MACB hardware */
  94. at91_macb_hw_init();
  95. }
  96. #endif
  97. #ifdef CONFIG_GENERIC_ATMEL_MCI
  98. int board_mmc_init(bd_t *bd)
  99. {
  100. at91_mci_hw_init();
  101. return atmel_mci_init((void *)ATMEL_BASE_MCI);
  102. }
  103. #endif
  104. int board_early_init_f(void)
  105. {
  106. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  107. /* Enable clocks for all PIOs */
  108. writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
  109. (1 << ATMEL_ID_PIOC),
  110. &pmc->pcer);
  111. return 0;
  112. }
  113. int board_init(void)
  114. {
  115. /* adress of boot parameters */
  116. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  117. at91_seriald_hw_init();
  118. #ifdef CONFIG_CMD_NAND
  119. at91sam9260ek_nand_hw_init();
  120. #endif
  121. #ifdef CONFIG_HAS_DATAFLASH
  122. at91_spi0_hw_init((1 << 0) | (1 << 1));
  123. #endif
  124. #ifdef CONFIG_MACB
  125. at91sam9260ek_macb_hw_init();
  126. #endif
  127. return 0;
  128. }
  129. int dram_init(void)
  130. {
  131. gd->ram_size = get_ram_size(
  132. (void *)CONFIG_SYS_SDRAM_BASE,
  133. CONFIG_SYS_SDRAM_SIZE);
  134. return 0;
  135. }
  136. #ifdef CONFIG_RESET_PHY_R
  137. void reset_phy(void)
  138. {
  139. }
  140. #endif
  141. int board_eth_init(bd_t *bis)
  142. {
  143. int rc = 0;
  144. #ifdef CONFIG_MACB
  145. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  146. #endif
  147. return rc;
  148. }