sama5d4ek.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright (C) 2014 Atmel
  3. * Bo Shen <voice.shen@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/at91_rstc.h>
  11. #include <asm/arch/atmel_mpddrc.h>
  12. #include <asm/arch/gpio.h>
  13. #include <asm/arch/clk.h>
  14. #include <asm/arch/sama5d3_smc.h>
  15. #include <asm/arch/sama5d4.h>
  16. #include <atmel_hlcdc.h>
  17. #include <debug_uart.h>
  18. #include <lcd.h>
  19. #include <nand.h>
  20. #include <version.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. #ifdef CONFIG_NAND_ATMEL
  23. static void sama5d4ek_nand_hw_init(void)
  24. {
  25. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  26. at91_periph_clk_enable(ATMEL_ID_SMC);
  27. /* Configure SMC CS3 for NAND */
  28. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  29. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
  30. &smc->cs[3].setup);
  31. writel(AT91_SMC_PULSE_NWE(2) | AT91_SMC_PULSE_NCS_WR(3) |
  32. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(3),
  33. &smc->cs[3].pulse);
  34. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  35. &smc->cs[3].cycle);
  36. writel(AT91_SMC_TIMINGS_TCLR(2) | AT91_SMC_TIMINGS_TADL(7) |
  37. AT91_SMC_TIMINGS_TAR(2) | AT91_SMC_TIMINGS_TRR(3) |
  38. AT91_SMC_TIMINGS_TWB(7) | AT91_SMC_TIMINGS_RBNSEL(3)|
  39. AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
  40. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  41. AT91_SMC_MODE_EXNW_DISABLE |
  42. AT91_SMC_MODE_DBW_8 |
  43. AT91_SMC_MODE_TDF_CYCLE(3),
  44. &smc->cs[3].mode);
  45. at91_pio3_set_a_periph(AT91_PIO_PORTC, 5, 0); /* D0 */
  46. at91_pio3_set_a_periph(AT91_PIO_PORTC, 6, 0); /* D1 */
  47. at91_pio3_set_a_periph(AT91_PIO_PORTC, 7, 0); /* D2 */
  48. at91_pio3_set_a_periph(AT91_PIO_PORTC, 8, 0); /* D3 */
  49. at91_pio3_set_a_periph(AT91_PIO_PORTC, 9, 0); /* D4 */
  50. at91_pio3_set_a_periph(AT91_PIO_PORTC, 10, 0); /* D5 */
  51. at91_pio3_set_a_periph(AT91_PIO_PORTC, 11, 0); /* D6 */
  52. at91_pio3_set_a_periph(AT91_PIO_PORTC, 12, 0); /* D7 */
  53. at91_pio3_set_a_periph(AT91_PIO_PORTC, 13, 0); /* RE */
  54. at91_pio3_set_a_periph(AT91_PIO_PORTC, 14, 0); /* WE */
  55. at91_pio3_set_a_periph(AT91_PIO_PORTC, 15, 1); /* NCS */
  56. at91_pio3_set_a_periph(AT91_PIO_PORTC, 16, 1); /* RDY */
  57. at91_pio3_set_a_periph(AT91_PIO_PORTC, 17, 1); /* ALE */
  58. at91_pio3_set_a_periph(AT91_PIO_PORTC, 18, 1); /* CLE */
  59. }
  60. #endif
  61. #ifdef CONFIG_CMD_USB
  62. static void sama5d4ek_usb_hw_init(void)
  63. {
  64. at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
  65. at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
  66. at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
  67. }
  68. #endif
  69. #ifdef CONFIG_LCD
  70. vidinfo_t panel_info = {
  71. .vl_col = 800,
  72. .vl_row = 480,
  73. .vl_clk = 33260000,
  74. .vl_bpix = LCD_BPP,
  75. .vl_tft = 1,
  76. .vl_hsync_len = 5,
  77. .vl_left_margin = 128,
  78. .vl_right_margin = 0,
  79. .vl_vsync_len = 5,
  80. .vl_upper_margin = 23,
  81. .vl_lower_margin = 22,
  82. .mmio = ATMEL_BASE_LCDC,
  83. };
  84. /* No power up/down pin for the LCD pannel */
  85. void lcd_enable(void) { /* Empty! */ }
  86. void lcd_disable(void) { /* Empty! */ }
  87. unsigned int has_lcdc(void)
  88. {
  89. return 1;
  90. }
  91. static void sama5d4ek_lcd_hw_init(void)
  92. {
  93. at91_pio3_set_a_periph(AT91_PIO_PORTA, 24, 0); /* LCDPWM */
  94. at91_pio3_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
  95. at91_pio3_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
  96. at91_pio3_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
  97. at91_pio3_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
  98. at91_pio3_set_a_periph(AT91_PIO_PORTA, 29, 0); /* LCDDEN */
  99. at91_pio3_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
  100. at91_pio3_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
  101. at91_pio3_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
  102. at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
  103. at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
  104. at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
  105. at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
  106. at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
  107. at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
  108. at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
  109. at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
  110. at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
  111. at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */
  112. at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */
  113. at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */
  114. at91_pio3_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */
  115. at91_pio3_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */
  116. at91_pio3_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */
  117. /* Enable clock */
  118. at91_periph_clk_enable(ATMEL_ID_LCDC);
  119. }
  120. #ifdef CONFIG_LCD_INFO
  121. void lcd_show_board_info(void)
  122. {
  123. ulong dram_size, nand_size;
  124. int i;
  125. char temp[32];
  126. lcd_printf("%s\n", U_BOOT_VERSION);
  127. lcd_printf("2014 ATMEL Corp\n");
  128. lcd_printf("at91@atmel.com\n");
  129. lcd_printf("%s CPU at %s MHz\n", get_cpu_name(),
  130. strmhz(temp, get_cpu_clk_rate()));
  131. dram_size = 0;
  132. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  133. dram_size += gd->bd->bi_dram[i].size;
  134. nand_size = 0;
  135. #ifdef CONFIG_NAND_ATMEL
  136. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  137. nand_size += get_nand_dev_by_index(i)->size;
  138. #endif
  139. lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
  140. dram_size >> 20, nand_size >> 20);
  141. }
  142. #endif /* CONFIG_LCD_INFO */
  143. #endif /* CONFIG_LCD */
  144. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  145. static void sama5d4ek_serial3_hw_init(void)
  146. {
  147. at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
  148. at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
  149. /* Enable clock */
  150. at91_periph_clk_enable(ATMEL_ID_USART3);
  151. }
  152. void board_debug_uart_init(void)
  153. {
  154. sama5d4ek_serial3_hw_init();
  155. }
  156. #endif
  157. #ifdef CONFIG_BOARD_EARLY_INIT_F
  158. int board_early_init_f(void)
  159. {
  160. #ifdef CONFIG_DEBUG_UART
  161. debug_uart_init();
  162. #endif
  163. return 0;
  164. }
  165. #endif
  166. int board_init(void)
  167. {
  168. /* adress of boot parameters */
  169. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  170. #ifdef CONFIG_NAND_ATMEL
  171. sama5d4ek_nand_hw_init();
  172. #endif
  173. #ifdef CONFIG_LCD
  174. sama5d4ek_lcd_hw_init();
  175. #endif
  176. #ifdef CONFIG_CMD_USB
  177. sama5d4ek_usb_hw_init();
  178. #endif
  179. return 0;
  180. }
  181. int dram_init(void)
  182. {
  183. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  184. CONFIG_SYS_SDRAM_SIZE);
  185. return 0;
  186. }
  187. /* SPL */
  188. #ifdef CONFIG_SPL_BUILD
  189. void spl_board_init(void)
  190. {
  191. #if CONFIG_SYS_USE_NANDFLASH
  192. sama5d4ek_nand_hw_init();
  193. #endif
  194. }
  195. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  196. {
  197. ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  198. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  199. ATMEL_MPDDRC_CR_NR_ROW_14 |
  200. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  201. ATMEL_MPDDRC_CR_NB_8BANKS |
  202. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
  203. ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
  204. ddr2->rtr = 0x2b0;
  205. ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  206. 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  207. 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  208. 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  209. 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  210. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  211. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  212. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  213. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  214. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  215. 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  216. 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  217. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  218. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  219. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  220. 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  221. 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  222. }
  223. void mem_init(void)
  224. {
  225. struct atmel_mpddrc_config ddr2;
  226. const struct atmel_mpddr *mpddr = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC;
  227. u32 tmp;
  228. ddr2_conf(&ddr2);
  229. /* Enable MPDDR clock */
  230. at91_periph_clk_enable(ATMEL_ID_MPDDRC);
  231. at91_system_clk_enable(AT91_PMC_DDR);
  232. tmp = ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE;
  233. writel(tmp, &mpddr->rd_data_path);
  234. tmp = readl(&mpddr->io_calibr);
  235. tmp = (tmp & ~(ATMEL_MPDDRC_IO_CALIBR_RDIV |
  236. ATMEL_MPDDRC_IO_CALIBR_TZQIO |
  237. ATMEL_MPDDRC_IO_CALIBR_CALCODEP |
  238. ATMEL_MPDDRC_IO_CALIBR_CALCODEN)) |
  239. ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_52 |
  240. ATMEL_MPDDRC_IO_CALIBR_TZQIO_(8) |
  241. ATMEL_MPDDRC_IO_CALIBR_EN_CALIB;
  242. writel(tmp, &mpddr->io_calibr);
  243. /* DDRAM2 Controller initialize */
  244. ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
  245. }
  246. void at91_pmc_init(void)
  247. {
  248. u32 tmp;
  249. tmp = AT91_PMC_PLLAR_29 |
  250. AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
  251. AT91_PMC_PLLXR_MUL(87) |
  252. AT91_PMC_PLLXR_DIV(1);
  253. at91_plla_init(tmp);
  254. at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x0));
  255. tmp = AT91_PMC_MCKR_H32MXDIV |
  256. AT91_PMC_MCKR_PLLADIV_2 |
  257. AT91_PMC_MCKR_MDIV_3 |
  258. AT91_PMC_MCKR_CSS_PLLA;
  259. at91_mck_init(tmp);
  260. }
  261. #endif