at91sam9x5ek.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Atmel Corporation
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include <asm/arch/at91sam9x5_matrix.h>
  8. #include <asm/arch/at91sam9_smc.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/at91_rstc.h>
  11. #include <asm/arch/clk.h>
  12. #include <asm/arch/gpio.h>
  13. #include <debug_uart.h>
  14. #include <asm/mach-types.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /* ------------------------------------------------------------------------- */
  17. /*
  18. * Miscelaneous platform dependent initialisations
  19. */
  20. void at91_prepare_cpu_var(void);
  21. #ifdef CONFIG_CMD_NAND
  22. static void at91sam9x5ek_nand_hw_init(void)
  23. {
  24. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  25. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  26. unsigned long csa;
  27. /* Enable CS3 */
  28. csa = readl(&matrix->ebicsa);
  29. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  30. /* NAND flash on D16 */
  31. csa |= AT91_MATRIX_NFD0_ON_D16;
  32. /* Configure IO drive */
  33. csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  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(5) |
  40. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
  41. &smc->cs[3].pulse);
  42. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(6),
  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(1),
  52. &smc->cs[3].mode);
  53. at91_periph_clk_enable(ATMEL_ID_PIOCD);
  54. /* Configure RDY/BSY */
  55. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  56. /* Enable NandFlash */
  57. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  58. at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
  59. at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
  60. at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* NAND ALE */
  61. at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* NAND CLE */
  62. at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
  63. at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
  64. at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
  65. at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
  66. at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
  67. at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
  68. at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
  69. at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
  70. }
  71. #endif
  72. #ifdef CONFIG_BOARD_LATE_INIT
  73. int board_late_init(void)
  74. {
  75. #ifdef CONFIG_DM_VIDEO
  76. at91_video_show_board_info();
  77. #endif
  78. at91_prepare_cpu_var();
  79. return 0;
  80. }
  81. #endif
  82. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  83. void board_debug_uart_init(void)
  84. {
  85. at91_seriald_hw_init();
  86. }
  87. #endif
  88. #ifdef CONFIG_BOARD_EARLY_INIT_F
  89. int board_early_init_f(void)
  90. {
  91. #ifdef CONFIG_DEBUG_UART
  92. debug_uart_init();
  93. #endif
  94. return 0;
  95. }
  96. #endif
  97. int board_init(void)
  98. {
  99. /* arch number of AT91SAM9X5EK-Board */
  100. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9X5EK;
  101. /* adress of boot parameters */
  102. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  103. #ifdef CONFIG_CMD_NAND
  104. at91sam9x5ek_nand_hw_init();
  105. #endif
  106. #if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD)
  107. at91_uhp_hw_init();
  108. #endif
  109. return 0;
  110. }
  111. int dram_init(void)
  112. {
  113. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  114. CONFIG_SYS_SDRAM_SIZE);
  115. return 0;
  116. }
  117. #if defined(CONFIG_SPL_BUILD)
  118. #include <spl.h>
  119. #include <nand.h>
  120. void at91_spl_board_init(void)
  121. {
  122. #ifdef CONFIG_SD_BOOT
  123. at91_mci_hw_init();
  124. #elif CONFIG_NAND_BOOT
  125. at91sam9x5ek_nand_hw_init();
  126. #endif
  127. }
  128. #include <asm/arch/atmel_mpddrc.h>
  129. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  130. {
  131. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  132. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  133. ATMEL_MPDDRC_CR_NR_ROW_13 |
  134. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  135. ATMEL_MPDDRC_CR_NB_8BANKS |
  136. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
  137. ddr2->rtr = 0x411;
  138. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  139. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  140. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  141. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  142. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  143. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  144. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  145. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  146. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  147. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  148. 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  149. 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  150. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  151. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  152. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  153. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  154. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  155. }
  156. void mem_init(void)
  157. {
  158. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  159. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  160. struct atmel_mpddrc_config ddr2;
  161. unsigned long csa;
  162. ddr2_conf(&ddr2);
  163. /* enable DDR2 clock */
  164. writel(AT91_PMC_DDR, &pmc->scer);
  165. /* Chip select 1 is for DDR2/SDRAM */
  166. csa = readl(&matrix->ebicsa);
  167. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  168. csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
  169. csa |= AT91_MATRIX_EBI_DBPD_OFF;
  170. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  171. writel(csa, &matrix->ebicsa);
  172. /* DDRAM2 Controller initialize */
  173. ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
  174. }
  175. #endif