at91sam9x5ek.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Copyright (C) 2012 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/at91sam9x5_matrix.h>
  9. #include <asm/arch/at91sam9_smc.h>
  10. #include <asm/arch/at91_common.h>
  11. #include <asm/arch/at91_rstc.h>
  12. #include <asm/arch/clk.h>
  13. #include <asm/arch/gpio.h>
  14. #include <debug_uart.h>
  15. #include <lcd.h>
  16. #include <atmel_hlcdc.h>
  17. #ifdef CONFIG_LCD_INFO
  18. #include <nand.h>
  19. #include <version.h>
  20. #endif
  21. DECLARE_GLOBAL_DATA_PTR;
  22. /* ------------------------------------------------------------------------- */
  23. /*
  24. * Miscelaneous platform dependent initialisations
  25. */
  26. #ifdef CONFIG_CMD_NAND
  27. static void at91sam9x5ek_nand_hw_init(void)
  28. {
  29. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  30. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  31. unsigned long csa;
  32. /* Enable CS3 */
  33. csa = readl(&matrix->ebicsa);
  34. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  35. /* NAND flash on D16 */
  36. csa |= AT91_MATRIX_NFD0_ON_D16;
  37. /* Configure IO drive */
  38. csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  39. writel(csa, &matrix->ebicsa);
  40. /* Configure SMC CS3 for NAND/SmartMedia */
  41. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  42. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  43. &smc->cs[3].setup);
  44. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
  45. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
  46. &smc->cs[3].pulse);
  47. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(6),
  48. &smc->cs[3].cycle);
  49. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  50. AT91_SMC_MODE_EXNW_DISABLE |
  51. #ifdef CONFIG_SYS_NAND_DBW_16
  52. AT91_SMC_MODE_DBW_16 |
  53. #else /* CONFIG_SYS_NAND_DBW_8 */
  54. AT91_SMC_MODE_DBW_8 |
  55. #endif
  56. AT91_SMC_MODE_TDF_CYCLE(1),
  57. &smc->cs[3].mode);
  58. at91_periph_clk_enable(ATMEL_ID_PIOCD);
  59. /* Configure RDY/BSY */
  60. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  61. /* Enable NandFlash */
  62. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  63. at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
  64. at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
  65. at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* NAND ALE */
  66. at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* NAND CLE */
  67. at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
  68. at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
  69. at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
  70. at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
  71. at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
  72. at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
  73. at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
  74. at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
  75. }
  76. #endif
  77. #ifdef CONFIG_LCD
  78. vidinfo_t panel_info = {
  79. .vl_col = 800,
  80. .vl_row = 480,
  81. .vl_clk = 24000000,
  82. .vl_sync = LCDC_LCDCFG5_HSPOL | LCDC_LCDCFG5_VSPOL,
  83. .vl_bpix = LCD_BPP,
  84. .vl_tft = 1,
  85. .vl_clk_pol = 1,
  86. .vl_hsync_len = 128,
  87. .vl_left_margin = 64,
  88. .vl_right_margin = 64,
  89. .vl_vsync_len = 2,
  90. .vl_upper_margin = 22,
  91. .vl_lower_margin = 21,
  92. .mmio = ATMEL_BASE_LCDC,
  93. };
  94. void lcd_enable(void)
  95. {
  96. if (has_lcdc())
  97. at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 1); /* power up */
  98. }
  99. void lcd_disable(void)
  100. {
  101. if (has_lcdc())
  102. at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 0); /* power down */
  103. }
  104. static void at91sam9x5ek_lcd_hw_init(void)
  105. {
  106. if (has_lcdc()) {
  107. at91_pio3_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDPWM */
  108. at91_pio3_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDVSYNC */
  109. at91_pio3_set_a_periph(AT91_PIO_PORTC, 28, 0); /* LCDHSYNC */
  110. at91_pio3_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDDISP */
  111. at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 0); /* LCDDEN */
  112. at91_pio3_set_a_periph(AT91_PIO_PORTC, 30, 0); /* LCDPCK */
  113. at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDD0 */
  114. at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDD1 */
  115. at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDD2 */
  116. at91_pio3_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDD3 */
  117. at91_pio3_set_a_periph(AT91_PIO_PORTC, 4, 0); /* LCDD4 */
  118. at91_pio3_set_a_periph(AT91_PIO_PORTC, 5, 0); /* LCDD5 */
  119. at91_pio3_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD6 */
  120. at91_pio3_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD7 */
  121. at91_pio3_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD8 */
  122. at91_pio3_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD9 */
  123. at91_pio3_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD10 */
  124. at91_pio3_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD11 */
  125. at91_pio3_set_a_periph(AT91_PIO_PORTC, 12, 0); /* LCDD12 */
  126. at91_pio3_set_a_periph(AT91_PIO_PORTC, 13, 0); /* LCDD13 */
  127. at91_pio3_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD14 */
  128. at91_pio3_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD15 */
  129. at91_pio3_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD16 */
  130. at91_pio3_set_a_periph(AT91_PIO_PORTC, 17, 0); /* LCDD17 */
  131. at91_pio3_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD18 */
  132. at91_pio3_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD19 */
  133. at91_pio3_set_a_periph(AT91_PIO_PORTC, 20, 0); /* LCDD20 */
  134. at91_pio3_set_a_periph(AT91_PIO_PORTC, 21, 0); /* LCDD21 */
  135. at91_pio3_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD22 */
  136. at91_pio3_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD23 */
  137. at91_periph_clk_enable(ATMEL_ID_LCDC);
  138. }
  139. }
  140. #ifdef CONFIG_LCD_INFO
  141. void lcd_show_board_info(void)
  142. {
  143. ulong dram_size, nand_size;
  144. int i;
  145. char temp[32];
  146. if (has_lcdc()) {
  147. lcd_printf("%s\n", U_BOOT_VERSION);
  148. lcd_printf("(C) 2012 ATMEL Corp\n");
  149. lcd_printf("at91support@atmel.com\n");
  150. lcd_printf("%s CPU at %s MHz\n",
  151. get_cpu_name(),
  152. strmhz(temp, get_cpu_clk_rate()));
  153. dram_size = 0;
  154. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  155. dram_size += gd->bd->bi_dram[i].size;
  156. nand_size = 0;
  157. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  158. nand_size += nand_info[i]->size;
  159. lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
  160. dram_size >> 20,
  161. nand_size >> 20);
  162. }
  163. }
  164. #endif /* CONFIG_LCD_INFO */
  165. #endif /* CONFIG_LCD */
  166. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  167. void board_debug_uart_init(void)
  168. {
  169. at91_seriald_hw_init();
  170. }
  171. #endif
  172. #ifdef CONFIG_BOARD_EARLY_INIT_F
  173. int board_early_init_f(void)
  174. {
  175. #ifdef CONFIG_DEBUG_UART
  176. debug_uart_init();
  177. #endif
  178. return 0;
  179. }
  180. #endif
  181. int board_init(void)
  182. {
  183. /* arch number of AT91SAM9X5EK-Board */
  184. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9X5EK;
  185. /* adress of boot parameters */
  186. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  187. #ifdef CONFIG_CMD_NAND
  188. at91sam9x5ek_nand_hw_init();
  189. #endif
  190. #if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD)
  191. at91_uhp_hw_init();
  192. #endif
  193. #ifdef CONFIG_LCD
  194. at91sam9x5ek_lcd_hw_init();
  195. #endif
  196. return 0;
  197. }
  198. int dram_init(void)
  199. {
  200. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  201. CONFIG_SYS_SDRAM_SIZE);
  202. return 0;
  203. }
  204. #if defined(CONFIG_SPL_BUILD)
  205. #include <spl.h>
  206. #include <nand.h>
  207. void at91_spl_board_init(void)
  208. {
  209. #ifdef CONFIG_SYS_USE_MMC
  210. at91_mci_hw_init();
  211. #elif CONFIG_SYS_USE_NANDFLASH
  212. at91sam9x5ek_nand_hw_init();
  213. #endif
  214. }
  215. #include <asm/arch/atmel_mpddrc.h>
  216. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  217. {
  218. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  219. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  220. ATMEL_MPDDRC_CR_NR_ROW_13 |
  221. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  222. ATMEL_MPDDRC_CR_NB_8BANKS |
  223. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
  224. ddr2->rtr = 0x411;
  225. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  226. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  227. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  228. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  229. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  230. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  231. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  232. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  233. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  234. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  235. 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  236. 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  237. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  238. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  239. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  240. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  241. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  242. }
  243. void mem_init(void)
  244. {
  245. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  246. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  247. struct atmel_mpddrc_config ddr2;
  248. unsigned long csa;
  249. ddr2_conf(&ddr2);
  250. /* enable DDR2 clock */
  251. writel(AT91_PMC_DDR, &pmc->scer);
  252. /* Chip select 1 is for DDR2/SDRAM */
  253. csa = readl(&matrix->ebicsa);
  254. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  255. csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
  256. csa |= AT91_MATRIX_EBI_DBPD_OFF;
  257. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  258. writel(csa, &matrix->ebicsa);
  259. /* DDRAM2 Controller initialize */
  260. ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
  261. }
  262. #endif