at91sam9260ek.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/clk.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_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  63. at91_periph_clk_enable(ATMEL_ID_EMAC0);
  64. /*
  65. * Disable pull-up on:
  66. * RXDV (PA17) => PHY normal mode (not Test mode)
  67. * ERX0 (PA14) => PHY ADDR0
  68. * ERX1 (PA15) => PHY ADDR1
  69. * ERX2 (PA25) => PHY ADDR2
  70. * ERX3 (PA26) => PHY ADDR3
  71. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  72. *
  73. * PHY has internal pull-down
  74. */
  75. writel(pin_to_mask(AT91_PIN_PA14) |
  76. pin_to_mask(AT91_PIN_PA15) |
  77. pin_to_mask(AT91_PIN_PA17) |
  78. pin_to_mask(AT91_PIN_PA25) |
  79. pin_to_mask(AT91_PIN_PA26) |
  80. pin_to_mask(AT91_PIN_PA28),
  81. &pioa->pudr);
  82. at91_phy_reset();
  83. /* Re-enable pull-up */
  84. writel(pin_to_mask(AT91_PIN_PA14) |
  85. pin_to_mask(AT91_PIN_PA15) |
  86. pin_to_mask(AT91_PIN_PA17) |
  87. pin_to_mask(AT91_PIN_PA25) |
  88. pin_to_mask(AT91_PIN_PA26) |
  89. pin_to_mask(AT91_PIN_PA28),
  90. &pioa->puer);
  91. /* Initialize EMAC=MACB hardware */
  92. at91_macb_hw_init();
  93. }
  94. #endif
  95. #ifdef CONFIG_GENERIC_ATMEL_MCI
  96. int board_mmc_init(bd_t *bd)
  97. {
  98. at91_mci_hw_init();
  99. return atmel_mci_init((void *)ATMEL_BASE_MCI);
  100. }
  101. #endif
  102. int board_early_init_f(void)
  103. {
  104. at91_periph_clk_enable(ATMEL_ID_PIOA);
  105. at91_periph_clk_enable(ATMEL_ID_PIOB);
  106. at91_periph_clk_enable(ATMEL_ID_PIOC);
  107. return 0;
  108. }
  109. int board_init(void)
  110. {
  111. /* adress of boot parameters */
  112. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  113. at91_seriald_hw_init();
  114. #ifdef CONFIG_CMD_NAND
  115. at91sam9260ek_nand_hw_init();
  116. #endif
  117. #ifdef CONFIG_HAS_DATAFLASH
  118. at91_spi0_hw_init((1 << 0) | (1 << 1));
  119. #endif
  120. #ifdef CONFIG_MACB
  121. at91sam9260ek_macb_hw_init();
  122. #endif
  123. return 0;
  124. }
  125. int dram_init(void)
  126. {
  127. gd->ram_size = get_ram_size(
  128. (void *)CONFIG_SYS_SDRAM_BASE,
  129. CONFIG_SYS_SDRAM_SIZE);
  130. return 0;
  131. }
  132. #ifdef CONFIG_RESET_PHY_R
  133. void reset_phy(void)
  134. {
  135. }
  136. #endif
  137. int board_eth_init(bd_t *bis)
  138. {
  139. int rc = 0;
  140. #ifdef CONFIG_MACB
  141. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  142. #endif
  143. return rc;
  144. }