at91sam9n12ek.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 <lcd.h>
  16. #include <atmel_hlcdc.h>
  17. #include <atmel_mci.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_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
  65. at91_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
  66. at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* ALE */
  67. at91_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 += nand_info[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. /* SPI chip select control */
  119. #ifdef CONFIG_ATMEL_SPI
  120. #include <spi.h>
  121. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  122. {
  123. return bus == 0 && cs < 2;
  124. }
  125. void spi_cs_activate(struct spi_slave *slave)
  126. {
  127. switch (slave->cs) {
  128. case 0:
  129. at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
  130. break;
  131. case 1:
  132. at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
  133. break;
  134. }
  135. }
  136. void spi_cs_deactivate(struct spi_slave *slave)
  137. {
  138. switch (slave->cs) {
  139. case 0:
  140. at91_set_pio_output(AT91_PIO_PORTA, 14, 1);
  141. break;
  142. case 1:
  143. at91_set_pio_output(AT91_PIO_PORTA, 7, 1);
  144. break;
  145. }
  146. }
  147. #endif /* CONFIG_ATMEL_SPI */
  148. #ifdef CONFIG_GENERIC_ATMEL_MCI
  149. int board_mmc_init(bd_t *bd)
  150. {
  151. at91_mci_hw_init();
  152. return atmel_mci_init((void *)ATMEL_BASE_HSMCI0);
  153. }
  154. #endif
  155. #ifdef CONFIG_KS8851_MLL
  156. void at91sam9n12ek_ks8851_hw_init(void)
  157. {
  158. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  159. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  160. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  161. &smc->cs[2].setup);
  162. writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) |
  163. AT91_SMC_PULSE_NRD(7) | AT91_SMC_PULSE_NCS_RD(7),
  164. &smc->cs[2].pulse);
  165. writel(AT91_SMC_CYCLE_NWE(9) | AT91_SMC_CYCLE_NRD(9),
  166. &smc->cs[2].cycle);
  167. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  168. AT91_SMC_MODE_EXNW_DISABLE |
  169. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  170. AT91_SMC_MODE_TDF_CYCLE(1),
  171. &smc->cs[2].mode);
  172. /* Configure NCS2 PIN */
  173. at91_set_b_periph(AT91_PIO_PORTD, 19, 0);
  174. }
  175. #endif
  176. #ifdef CONFIG_USB_ATMEL
  177. void at91sam9n12ek_usb_hw_init(void)
  178. {
  179. at91_set_pio_output(AT91_PIO_PORTB, 7, 0);
  180. }
  181. #endif
  182. int board_early_init_f(void)
  183. {
  184. at91_periph_clk_enable(ATMEL_ID_PIOAB);
  185. at91_periph_clk_enable(ATMEL_ID_PIOCD);
  186. at91_seriald_hw_init();
  187. return 0;
  188. }
  189. int board_init(void)
  190. {
  191. /* adress of boot parameters */
  192. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  193. #ifdef CONFIG_NAND_ATMEL
  194. at91sam9n12ek_nand_hw_init();
  195. #endif
  196. #ifdef CONFIG_ATMEL_SPI
  197. at91_spi0_hw_init(1 << 0);
  198. #endif
  199. #ifdef CONFIG_LCD
  200. at91_lcd_hw_init();
  201. #endif
  202. #ifdef CONFIG_KS8851_MLL
  203. at91sam9n12ek_ks8851_hw_init();
  204. #endif
  205. #ifdef CONFIG_USB_ATMEL
  206. at91sam9n12ek_usb_hw_init();
  207. #endif
  208. return 0;
  209. }
  210. #ifdef CONFIG_KS8851_MLL
  211. int board_eth_init(bd_t *bis)
  212. {
  213. return ks8851_mll_initialize(0, CONFIG_KS8851_MLL_BASEADDR);
  214. }
  215. #endif
  216. int dram_init(void)
  217. {
  218. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  219. CONFIG_SYS_SDRAM_SIZE);
  220. return 0;
  221. }
  222. #if defined(CONFIG_SPL_BUILD)
  223. #include <spl.h>
  224. #include <nand.h>
  225. void at91_spl_board_init(void)
  226. {
  227. #ifdef CONFIG_SYS_USE_MMC
  228. at91_mci_hw_init();
  229. #elif CONFIG_SYS_USE_NANDFLASH
  230. at91sam9n12ek_nand_hw_init();
  231. #elif CONFIG_SYS_USE_SPIFLASH
  232. at91_spi0_hw_init(1 << 4);
  233. #endif
  234. }
  235. #include <asm/arch/atmel_mpddrc.h>
  236. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  237. {
  238. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  239. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  240. ATMEL_MPDDRC_CR_NR_ROW_13 |
  241. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  242. ATMEL_MPDDRC_CR_NB_8BANKS |
  243. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
  244. ddr2->rtr = 0x411;
  245. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  246. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  247. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  248. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  249. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  250. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  251. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  252. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  253. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  254. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  255. 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  256. 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  257. ddr2->tpr2 = (2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  258. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  259. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  260. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  261. }
  262. void mem_init(void)
  263. {
  264. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  265. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  266. struct atmel_mpddrc_config ddr2;
  267. unsigned long csa;
  268. ddr2_conf(&ddr2);
  269. /* enable DDR2 clock */
  270. writel(AT91_PMC_DDR, &pmc->scer);
  271. /* Chip select 1 is for DDR2/SDRAM */
  272. csa = readl(&matrix->ebicsa);
  273. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  274. csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
  275. csa |= AT91_MATRIX_EBI_DBPD_OFF;
  276. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  277. writel(csa, &matrix->ebicsa);
  278. /* DDRAM2 Controller initialize */
  279. ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
  280. }
  281. #endif