at91sam9x5ek.c 7.4 KB

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