sama5d2_ptc_ek.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Microchip Corporation
  4. * Wenyou Yang <wenyou.yang@microchip.com>
  5. */
  6. #include <common.h>
  7. #include <debug_uart.h>
  8. #include <dm.h>
  9. #include <i2c.h>
  10. #include <nand.h>
  11. #include <version.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/atmel_pio4.h>
  15. #include <asm/arch/atmel_mpddrc.h>
  16. #include <asm/arch/atmel_sdhci.h>
  17. #include <asm/arch/clk.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/arch/sama5d2.h>
  20. #include <asm/arch/sama5d2_smc.h>
  21. extern void at91_pda_detect(void);
  22. DECLARE_GLOBAL_DATA_PTR;
  23. #ifdef CONFIG_NAND_ATMEL
  24. static void board_nand_hw_init(void)
  25. {
  26. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  27. at91_periph_clk_enable(ATMEL_ID_HSMC);
  28. /* Configure SMC CS3 for NAND */
  29. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  30. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
  31. &smc->cs[3].setup);
  32. writel(AT91_SMC_PULSE_NWE(2) | AT91_SMC_PULSE_NCS_WR(4) |
  33. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(3),
  34. &smc->cs[3].pulse);
  35. writel(AT91_SMC_CYCLE_NWE(6) | AT91_SMC_CYCLE_NRD(5),
  36. &smc->cs[3].cycle);
  37. writel(AT91_SMC_TIMINGS_TCLR(2) | AT91_SMC_TIMINGS_TADL(7) |
  38. AT91_SMC_TIMINGS_TAR(2) | AT91_SMC_TIMINGS_TRR(3) |
  39. AT91_SMC_TIMINGS_TWB(7) | AT91_SMC_TIMINGS_RBNSEL(3) |
  40. AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
  41. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  42. AT91_SMC_MODE_EXNW_DISABLE |
  43. AT91_SMC_MODE_DBW_8 |
  44. AT91_SMC_MODE_TDF_CYCLE(3),
  45. &smc->cs[3].mode);
  46. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 22, ATMEL_PIO_DRVSTR_ME); /* D0 */
  47. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 23, ATMEL_PIO_DRVSTR_ME); /* D1 */
  48. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 24, ATMEL_PIO_DRVSTR_ME); /* D2 */
  49. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 25, ATMEL_PIO_DRVSTR_ME); /* D3 */
  50. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 26, ATMEL_PIO_DRVSTR_ME); /* D4 */
  51. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 27, ATMEL_PIO_DRVSTR_ME); /* D5 */
  52. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 28, ATMEL_PIO_DRVSTR_ME); /* D6 */
  53. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 29, ATMEL_PIO_DRVSTR_ME); /* D7 */
  54. atmel_pio4_set_b_periph(AT91_PIO_PORTB, 2, 0); /* RE */
  55. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 30, 0); /* WE */
  56. atmel_pio4_set_b_periph(AT91_PIO_PORTA, 31, ATMEL_PIO_PUEN_MASK); /* NCS */
  57. atmel_pio4_set_b_periph(AT91_PIO_PORTC, 8, ATMEL_PIO_PUEN_MASK); /* RDY */
  58. atmel_pio4_set_b_periph(AT91_PIO_PORTB, 0, ATMEL_PIO_PUEN_MASK); /* ALE */
  59. atmel_pio4_set_b_periph(AT91_PIO_PORTB, 1, ATMEL_PIO_PUEN_MASK); /* CLE */
  60. }
  61. #endif
  62. #ifdef CONFIG_BOARD_LATE_INIT
  63. int board_late_init(void)
  64. {
  65. at91_pda_detect();
  66. return 0;
  67. }
  68. #endif
  69. static void board_usb_hw_init(void)
  70. {
  71. atmel_pio4_set_pio_output(AT91_PIO_PORTB, 12, ATMEL_PIO_PUEN_MASK);
  72. }
  73. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  74. static void board_uart0_hw_init(void)
  75. {
  76. atmel_pio4_set_c_periph(AT91_PIO_PORTB, 26, ATMEL_PIO_PUEN_MASK); /* URXD0 */
  77. atmel_pio4_set_c_periph(AT91_PIO_PORTB, 27, 0); /* UTXD0 */
  78. at91_periph_clk_enable(ATMEL_ID_UART0);
  79. }
  80. void board_debug_uart_init(void)
  81. {
  82. board_uart0_hw_init();
  83. }
  84. #endif
  85. #ifdef CONFIG_BOARD_EARLY_INIT_F
  86. int board_early_init_f(void)
  87. {
  88. #ifdef CONFIG_DEBUG_UART
  89. debug_uart_init();
  90. #endif
  91. return 0;
  92. }
  93. #endif
  94. int board_init(void)
  95. {
  96. /* address of boot parameters */
  97. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  98. #ifdef CONFIG_NAND_ATMEL
  99. board_nand_hw_init();
  100. #endif
  101. #ifdef CONFIG_CMD_USB
  102. board_usb_hw_init();
  103. #endif
  104. return 0;
  105. }
  106. int dram_init(void)
  107. {
  108. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  109. CONFIG_SYS_SDRAM_SIZE);
  110. return 0;
  111. }
  112. #define AT24MAC_MAC_OFFSET 0xfa
  113. #ifdef CONFIG_MISC_INIT_R
  114. int misc_init_r(void)
  115. {
  116. #ifdef CONFIG_I2C_EEPROM
  117. at91_set_ethaddr(AT24MAC_MAC_OFFSET);
  118. #endif
  119. return 0;
  120. }
  121. #endif