at91sam9n12ek.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * (C) Copyright 2013 Atmel Corporation
  3. * Josh Wu <josh.wu@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/at91sam9x5_matrix.h>
  10. #include <asm/arch/at91sam9_smc.h>
  11. #include <asm/arch/at91_common.h>
  12. #include <asm/arch/at91_rstc.h>
  13. #include <asm/arch/at91_pio.h>
  14. #include <asm/arch/clk.h>
  15. #include <debug_uart.h>
  16. #include <lcd.h>
  17. #include <atmel_hlcdc.h>
  18. #include <netdev.h>
  19. #ifdef CONFIG_LCD_INFO
  20. #include <nand.h>
  21. #include <version.h>
  22. #endif
  23. DECLARE_GLOBAL_DATA_PTR;
  24. /* ------------------------------------------------------------------------- */
  25. /*
  26. * Miscelaneous platform dependent initialisations
  27. */
  28. #ifdef CONFIG_NAND_ATMEL
  29. static void at91sam9n12ek_nand_hw_init(void)
  30. {
  31. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  32. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  33. unsigned long csa;
  34. /* Assign CS3 to NAND/SmartMedia Interface */
  35. csa = readl(&matrix->ebicsa);
  36. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  37. /* Configure databus */
  38. csa &= ~AT91_MATRIX_NFD0_ON_D16; /* nandflash connect to D0~D15 */
  39. /* Configure IO drive */
  40. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  41. writel(csa, &matrix->ebicsa);
  42. /* Configure SMC CS3 for NAND/SmartMedia */
  43. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  44. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  45. &smc->cs[3].setup);
  46. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
  47. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
  48. &smc->cs[3].pulse);
  49. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(7),
  50. &smc->cs[3].cycle);
  51. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  52. AT91_SMC_MODE_EXNW_DISABLE |
  53. #ifdef CONFIG_SYS_NAND_DBW_16
  54. AT91_SMC_MODE_DBW_16 |
  55. #else /* CONFIG_SYS_NAND_DBW_8 */
  56. AT91_SMC_MODE_DBW_8 |
  57. #endif
  58. AT91_SMC_MODE_TDF_CYCLE(1),
  59. &smc->cs[3].mode);
  60. /* Configure RDY/BSY pin */
  61. at91_set_pio_input(AT91_PIO_PORTD, 5, 1);
  62. /* Configure ENABLE pin for NandFlash */
  63. at91_set_pio_output(AT91_PIO_PORTD, 4, 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); /* ALE */
  67. at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* CLE */
  68. }
  69. #endif
  70. #ifdef CONFIG_LCD
  71. vidinfo_t panel_info = {
  72. .vl_col = 480,
  73. .vl_row = 272,
  74. .vl_clk = 9000000,
  75. .vl_bpix = LCD_BPP,
  76. .vl_sync = 0,
  77. .vl_tft = 1,
  78. .vl_hsync_len = 5,
  79. .vl_left_margin = 8,
  80. .vl_right_margin = 43,
  81. .vl_vsync_len = 10,
  82. .vl_upper_margin = 4,
  83. .vl_lower_margin = 12,
  84. .mmio = ATMEL_BASE_LCDC,
  85. };
  86. void lcd_enable(void)
  87. {
  88. at91_set_pio_output(AT91_PIO_PORTC, 25, 0); /* power up */
  89. }
  90. void lcd_disable(void)
  91. {
  92. at91_set_pio_output(AT91_PIO_PORTC, 25, 1); /* power down */
  93. }
  94. #ifdef CONFIG_LCD_INFO
  95. void lcd_show_board_info(void)
  96. {
  97. ulong dram_size, nand_size;
  98. int i;
  99. char temp[32];
  100. lcd_printf("%s\n", U_BOOT_VERSION);
  101. lcd_printf("ATMEL Corp\n");
  102. lcd_printf("at91@atmel.com\n");
  103. lcd_printf("%s CPU at %s MHz\n",
  104. ATMEL_CPU_NAME,
  105. strmhz(temp, get_cpu_clk_rate()));
  106. dram_size = 0;
  107. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  108. dram_size += gd->bd->bi_dram[i].size;
  109. nand_size = 0;
  110. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  111. nand_size += get_nand_dev_by_index(i)->size;
  112. lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
  113. dram_size >> 20,
  114. nand_size >> 20);
  115. }
  116. #endif /* CONFIG_LCD_INFO */
  117. #endif /* CONFIG_LCD */
  118. #ifdef CONFIG_KS8851_MLL
  119. void at91sam9n12ek_ks8851_hw_init(void)
  120. {
  121. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  122. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  123. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  124. &smc->cs[2].setup);
  125. writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) |
  126. AT91_SMC_PULSE_NRD(7) | AT91_SMC_PULSE_NCS_RD(7),
  127. &smc->cs[2].pulse);
  128. writel(AT91_SMC_CYCLE_NWE(9) | AT91_SMC_CYCLE_NRD(9),
  129. &smc->cs[2].cycle);
  130. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  131. AT91_SMC_MODE_EXNW_DISABLE |
  132. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  133. AT91_SMC_MODE_TDF_CYCLE(1),
  134. &smc->cs[2].mode);
  135. /* Configure NCS2 PIN */
  136. at91_pio3_set_b_periph(AT91_PIO_PORTD, 19, 0);
  137. }
  138. #endif
  139. #ifdef CONFIG_USB_ATMEL
  140. void at91sam9n12ek_usb_hw_init(void)
  141. {
  142. at91_set_pio_output(AT91_PIO_PORTB, 7, 0);
  143. }
  144. #endif
  145. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  146. void board_debug_uart_init(void)
  147. {
  148. at91_seriald_hw_init();
  149. }
  150. #endif
  151. #ifdef CONFIG_BOARD_EARLY_INIT_F
  152. int board_early_init_f(void)
  153. {
  154. #ifdef CONFIG_DEBUG_UART
  155. debug_uart_init();
  156. #endif
  157. return 0;
  158. }
  159. #endif
  160. int board_init(void)
  161. {
  162. /* adress of boot parameters */
  163. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  164. #ifdef CONFIG_NAND_ATMEL
  165. at91sam9n12ek_nand_hw_init();
  166. #endif
  167. #ifdef CONFIG_LCD
  168. at91_lcd_hw_init();
  169. #endif
  170. #ifdef CONFIG_KS8851_MLL
  171. at91sam9n12ek_ks8851_hw_init();
  172. #endif
  173. #ifdef CONFIG_USB_ATMEL
  174. at91sam9n12ek_usb_hw_init();
  175. #endif
  176. return 0;
  177. }
  178. #ifdef CONFIG_KS8851_MLL
  179. int board_eth_init(bd_t *bis)
  180. {
  181. return ks8851_mll_initialize(0, CONFIG_KS8851_MLL_BASEADDR);
  182. }
  183. #endif
  184. int dram_init(void)
  185. {
  186. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  187. CONFIG_SYS_SDRAM_SIZE);
  188. return 0;
  189. }
  190. #if defined(CONFIG_SPL_BUILD)
  191. #include <spl.h>
  192. #include <nand.h>
  193. void at91_spl_board_init(void)
  194. {
  195. #ifdef CONFIG_SD_BOOT
  196. at91_mci_hw_init();
  197. #elif CONFIG_NAND_BOOT
  198. at91sam9n12ek_nand_hw_init();
  199. #elif CONFIG_SPI_BOOT
  200. at91_spi0_hw_init(1 << 4);
  201. #endif
  202. }
  203. #include <asm/arch/atmel_mpddrc.h>
  204. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  205. {
  206. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  207. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  208. ATMEL_MPDDRC_CR_NR_ROW_13 |
  209. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  210. ATMEL_MPDDRC_CR_NB_8BANKS |
  211. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
  212. ddr2->rtr = 0x411;
  213. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  214. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  215. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  216. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  217. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  218. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  219. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  220. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  221. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  222. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  223. 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  224. 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  225. ddr2->tpr2 = (2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  226. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  227. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  228. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  229. }
  230. void mem_init(void)
  231. {
  232. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  233. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  234. struct atmel_mpddrc_config ddr2;
  235. unsigned long csa;
  236. ddr2_conf(&ddr2);
  237. /* enable DDR2 clock */
  238. writel(AT91_PMC_DDR, &pmc->scer);
  239. /* Chip select 1 is for DDR2/SDRAM */
  240. csa = readl(&matrix->ebicsa);
  241. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  242. csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
  243. csa |= AT91_MATRIX_EBI_DBPD_OFF;
  244. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  245. writel(csa, &matrix->ebicsa);
  246. /* DDRAM2 Controller initialize */
  247. ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
  248. }
  249. #endif