sama5d4ek.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014 Atmel
  4. * Bo Shen <voice.shen@atmel.com>
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/at91_common.h>
  9. #include <asm/arch/at91_rstc.h>
  10. #include <asm/arch/atmel_mpddrc.h>
  11. #include <asm/arch/gpio.h>
  12. #include <asm/arch/clk.h>
  13. #include <asm/arch/sama5d3_smc.h>
  14. #include <asm/arch/sama5d4.h>
  15. #include <debug_uart.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. #ifdef CONFIG_NAND_ATMEL
  18. static void sama5d4ek_nand_hw_init(void)
  19. {
  20. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  21. at91_periph_clk_enable(ATMEL_ID_SMC);
  22. /* Configure SMC CS3 for NAND */
  23. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  24. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
  25. &smc->cs[3].setup);
  26. writel(AT91_SMC_PULSE_NWE(2) | AT91_SMC_PULSE_NCS_WR(3) |
  27. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(3),
  28. &smc->cs[3].pulse);
  29. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  30. &smc->cs[3].cycle);
  31. writel(AT91_SMC_TIMINGS_TCLR(2) | AT91_SMC_TIMINGS_TADL(7) |
  32. AT91_SMC_TIMINGS_TAR(2) | AT91_SMC_TIMINGS_TRR(3) |
  33. AT91_SMC_TIMINGS_TWB(7) | AT91_SMC_TIMINGS_RBNSEL(3)|
  34. AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
  35. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  36. AT91_SMC_MODE_EXNW_DISABLE |
  37. AT91_SMC_MODE_DBW_8 |
  38. AT91_SMC_MODE_TDF_CYCLE(3),
  39. &smc->cs[3].mode);
  40. at91_pio3_set_a_periph(AT91_PIO_PORTC, 5, 0); /* D0 */
  41. at91_pio3_set_a_periph(AT91_PIO_PORTC, 6, 0); /* D1 */
  42. at91_pio3_set_a_periph(AT91_PIO_PORTC, 7, 0); /* D2 */
  43. at91_pio3_set_a_periph(AT91_PIO_PORTC, 8, 0); /* D3 */
  44. at91_pio3_set_a_periph(AT91_PIO_PORTC, 9, 0); /* D4 */
  45. at91_pio3_set_a_periph(AT91_PIO_PORTC, 10, 0); /* D5 */
  46. at91_pio3_set_a_periph(AT91_PIO_PORTC, 11, 0); /* D6 */
  47. at91_pio3_set_a_periph(AT91_PIO_PORTC, 12, 0); /* D7 */
  48. at91_pio3_set_a_periph(AT91_PIO_PORTC, 13, 0); /* RE */
  49. at91_pio3_set_a_periph(AT91_PIO_PORTC, 14, 0); /* WE */
  50. at91_pio3_set_a_periph(AT91_PIO_PORTC, 15, 1); /* NCS */
  51. at91_pio3_set_a_periph(AT91_PIO_PORTC, 16, 1); /* RDY */
  52. at91_pio3_set_a_periph(AT91_PIO_PORTC, 17, 1); /* ALE */
  53. at91_pio3_set_a_periph(AT91_PIO_PORTC, 18, 1); /* CLE */
  54. }
  55. #endif
  56. #ifdef CONFIG_CMD_USB
  57. static void sama5d4ek_usb_hw_init(void)
  58. {
  59. at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
  60. at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
  61. at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
  62. }
  63. #endif
  64. #ifdef CONFIG_BOARD_LATE_INIT
  65. int board_late_init(void)
  66. {
  67. #ifdef CONFIG_DM_VIDEO
  68. at91_video_show_board_info();
  69. #endif
  70. return 0;
  71. }
  72. #endif
  73. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  74. static void sama5d4ek_serial3_hw_init(void)
  75. {
  76. at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
  77. at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
  78. /* Enable clock */
  79. at91_periph_clk_enable(ATMEL_ID_USART3);
  80. }
  81. void board_debug_uart_init(void)
  82. {
  83. sama5d4ek_serial3_hw_init();
  84. }
  85. #endif
  86. #ifdef CONFIG_BOARD_EARLY_INIT_F
  87. int board_early_init_f(void)
  88. {
  89. #ifdef CONFIG_DEBUG_UART
  90. debug_uart_init();
  91. #endif
  92. return 0;
  93. }
  94. #endif
  95. int board_init(void)
  96. {
  97. /* adress of boot parameters */
  98. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  99. #ifdef CONFIG_NAND_ATMEL
  100. sama5d4ek_nand_hw_init();
  101. #endif
  102. #ifdef CONFIG_CMD_USB
  103. sama5d4ek_usb_hw_init();
  104. #endif
  105. return 0;
  106. }
  107. int dram_init(void)
  108. {
  109. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  110. CONFIG_SYS_SDRAM_SIZE);
  111. return 0;
  112. }
  113. /* SPL */
  114. #ifdef CONFIG_SPL_BUILD
  115. void spl_board_init(void)
  116. {
  117. #if CONFIG_NAND_BOOT
  118. sama5d4ek_nand_hw_init();
  119. #endif
  120. }
  121. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  122. {
  123. ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  124. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  125. ATMEL_MPDDRC_CR_NR_ROW_14 |
  126. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  127. ATMEL_MPDDRC_CR_NB_8BANKS |
  128. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
  129. ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
  130. ddr2->rtr = 0x2b0;
  131. ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  132. 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  133. 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  134. 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  135. 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  136. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  137. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  138. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  139. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  140. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  141. 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  142. 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  143. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  144. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  145. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  146. 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  147. 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  148. }
  149. void mem_init(void)
  150. {
  151. struct atmel_mpddrc_config ddr2;
  152. const struct atmel_mpddr *mpddr = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC;
  153. u32 tmp;
  154. ddr2_conf(&ddr2);
  155. /* Enable MPDDR clock */
  156. at91_periph_clk_enable(ATMEL_ID_MPDDRC);
  157. at91_system_clk_enable(AT91_PMC_DDR);
  158. tmp = ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE;
  159. writel(tmp, &mpddr->rd_data_path);
  160. tmp = readl(&mpddr->io_calibr);
  161. tmp = (tmp & ~(ATMEL_MPDDRC_IO_CALIBR_RDIV |
  162. ATMEL_MPDDRC_IO_CALIBR_TZQIO |
  163. ATMEL_MPDDRC_IO_CALIBR_CALCODEP |
  164. ATMEL_MPDDRC_IO_CALIBR_CALCODEN)) |
  165. ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_52 |
  166. ATMEL_MPDDRC_IO_CALIBR_TZQIO_(8) |
  167. ATMEL_MPDDRC_IO_CALIBR_EN_CALIB;
  168. writel(tmp, &mpddr->io_calibr);
  169. /* DDRAM2 Controller initialize */
  170. ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
  171. }
  172. void at91_pmc_init(void)
  173. {
  174. u32 tmp;
  175. tmp = AT91_PMC_PLLAR_29 |
  176. AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
  177. AT91_PMC_PLLXR_MUL(87) |
  178. AT91_PMC_PLLXR_DIV(1);
  179. at91_plla_init(tmp);
  180. at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x0));
  181. tmp = AT91_PMC_MCKR_H32MXDIV |
  182. AT91_PMC_MCKR_PLLADIV_2 |
  183. AT91_PMC_MCKR_MDIV_3 |
  184. AT91_PMC_MCKR_CSS_PLLA;
  185. at91_mck_init(tmp);
  186. }
  187. #endif