at91sam9x5ek.c 8.5 KB

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