at91sam9n12ek.c 7.0 KB

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