at91sam9x5ek.c 9.3 KB

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