at91sam9n12ek.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_pmc.h>
  13. #include <asm/arch/at91_rstc.h>
  14. #include <asm/arch/at91_pio.h>
  15. #include <asm/arch/clk.h>
  16. #include <lcd.h>
  17. #include <atmel_hlcdc.h>
  18. #include <atmel_mci.h>
  19. #include <netdev.h>
  20. #ifdef CONFIG_LCD_INFO
  21. #include <nand.h>
  22. #include <version.h>
  23. #endif
  24. DECLARE_GLOBAL_DATA_PTR;
  25. /* ------------------------------------------------------------------------- */
  26. /*
  27. * Miscelaneous platform dependent initialisations
  28. */
  29. #ifdef CONFIG_NAND_ATMEL
  30. static void at91sam9n12ek_nand_hw_init(void)
  31. {
  32. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  33. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  34. unsigned long csa;
  35. /* Assign CS3 to NAND/SmartMedia Interface */
  36. csa = readl(&matrix->ebicsa);
  37. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  38. /* Configure databus */
  39. csa &= ~AT91_MATRIX_NFD0_ON_D16; /* nandflash connect to D0~D15 */
  40. /* Configure IO drive */
  41. csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
  42. writel(csa, &matrix->ebicsa);
  43. /* Configure SMC CS3 for NAND/SmartMedia */
  44. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  45. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  46. &smc->cs[3].setup);
  47. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
  48. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
  49. &smc->cs[3].pulse);
  50. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(7),
  51. &smc->cs[3].cycle);
  52. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  53. AT91_SMC_MODE_EXNW_DISABLE |
  54. #ifdef CONFIG_SYS_NAND_DBW_16
  55. AT91_SMC_MODE_DBW_16 |
  56. #else /* CONFIG_SYS_NAND_DBW_8 */
  57. AT91_SMC_MODE_DBW_8 |
  58. #endif
  59. AT91_SMC_MODE_TDF_CYCLE(1),
  60. &smc->cs[3].mode);
  61. /* Configure RDY/BSY pin */
  62. at91_set_pio_input(AT91_PIO_PORTD, 5, 1);
  63. /* Configure ENABLE pin for NandFlash */
  64. at91_set_pio_output(AT91_PIO_PORTD, 4, 1);
  65. at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
  66. at91_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
  67. at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* ALE */
  68. at91_set_a_periph(AT91_PIO_PORTD, 3, 1); /* CLE */
  69. }
  70. #endif
  71. #ifdef CONFIG_LCD
  72. vidinfo_t panel_info = {
  73. .vl_col = 480,
  74. .vl_row = 272,
  75. .vl_clk = 9000000,
  76. .vl_bpix = LCD_BPP,
  77. .vl_sync = 0,
  78. .vl_tft = 1,
  79. .vl_hsync_len = 5,
  80. .vl_left_margin = 8,
  81. .vl_right_margin = 43,
  82. .vl_vsync_len = 10,
  83. .vl_upper_margin = 4,
  84. .vl_lower_margin = 12,
  85. .mmio = ATMEL_BASE_LCDC,
  86. };
  87. void lcd_enable(void)
  88. {
  89. at91_set_pio_output(AT91_PIO_PORTC, 25, 0); /* power up */
  90. }
  91. void lcd_disable(void)
  92. {
  93. at91_set_pio_output(AT91_PIO_PORTC, 25, 1); /* power down */
  94. }
  95. #ifdef CONFIG_LCD_INFO
  96. void lcd_show_board_info(void)
  97. {
  98. ulong dram_size, nand_size;
  99. int i;
  100. char temp[32];
  101. lcd_printf("%s\n", U_BOOT_VERSION);
  102. lcd_printf("ATMEL Corp\n");
  103. lcd_printf("at91@atmel.com\n");
  104. lcd_printf("%s CPU at %s MHz\n",
  105. ATMEL_CPU_NAME,
  106. strmhz(temp, get_cpu_clk_rate()));
  107. dram_size = 0;
  108. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  109. dram_size += gd->bd->bi_dram[i].size;
  110. nand_size = 0;
  111. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  112. nand_size += nand_info[i].size;
  113. lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
  114. dram_size >> 20,
  115. nand_size >> 20);
  116. }
  117. #endif /* CONFIG_LCD_INFO */
  118. #endif /* CONFIG_LCD */
  119. /* SPI chip select control */
  120. #ifdef CONFIG_ATMEL_SPI
  121. #include <spi.h>
  122. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  123. {
  124. return bus == 0 && cs < 2;
  125. }
  126. void spi_cs_activate(struct spi_slave *slave)
  127. {
  128. switch (slave->cs) {
  129. case 0:
  130. at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
  131. break;
  132. case 1:
  133. at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
  134. break;
  135. }
  136. }
  137. void spi_cs_deactivate(struct spi_slave *slave)
  138. {
  139. switch (slave->cs) {
  140. case 0:
  141. at91_set_pio_output(AT91_PIO_PORTA, 14, 1);
  142. break;
  143. case 1:
  144. at91_set_pio_output(AT91_PIO_PORTA, 7, 1);
  145. break;
  146. }
  147. }
  148. #endif /* CONFIG_ATMEL_SPI */
  149. #ifdef CONFIG_GENERIC_ATMEL_MCI
  150. int board_mmc_init(bd_t *bd)
  151. {
  152. at91_mci_hw_init();
  153. return atmel_mci_init((void *)ATMEL_BASE_HSMCI0);
  154. }
  155. #endif
  156. #ifdef CONFIG_KS8851_MLL
  157. void at91sam9n12ek_ks8851_hw_init(void)
  158. {
  159. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  160. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  161. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  162. &smc->cs[2].setup);
  163. writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) |
  164. AT91_SMC_PULSE_NRD(7) | AT91_SMC_PULSE_NCS_RD(7),
  165. &smc->cs[2].pulse);
  166. writel(AT91_SMC_CYCLE_NWE(9) | AT91_SMC_CYCLE_NRD(9),
  167. &smc->cs[2].cycle);
  168. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  169. AT91_SMC_MODE_EXNW_DISABLE |
  170. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  171. AT91_SMC_MODE_TDF_CYCLE(1),
  172. &smc->cs[2].mode);
  173. /* Configure NCS2 PIN */
  174. at91_set_b_periph(AT91_PIO_PORTD, 19, 0);
  175. }
  176. #endif
  177. #ifdef CONFIG_USB_ATMEL
  178. void at91sam9n12ek_usb_hw_init(void)
  179. {
  180. at91_set_pio_output(AT91_PIO_PORTB, 7, 0);
  181. }
  182. #endif
  183. int board_early_init_f(void)
  184. {
  185. /* Enable clocks for all PIOs */
  186. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  187. writel((1 << ATMEL_ID_PIOAB) | (1 << ATMEL_ID_PIOCD), &pmc->pcer);
  188. at91_seriald_hw_init();
  189. return 0;
  190. }
  191. int board_init(void)
  192. {
  193. /* adress of boot parameters */
  194. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  195. #ifdef CONFIG_NAND_ATMEL
  196. at91sam9n12ek_nand_hw_init();
  197. #endif
  198. #ifdef CONFIG_ATMEL_SPI
  199. at91_spi0_hw_init(1 << 0);
  200. #endif
  201. #ifdef CONFIG_LCD
  202. at91_lcd_hw_init();
  203. #endif
  204. #ifdef CONFIG_KS8851_MLL
  205. at91sam9n12ek_ks8851_hw_init();
  206. #endif
  207. #ifdef CONFIG_USB_ATMEL
  208. at91sam9n12ek_usb_hw_init();
  209. #endif
  210. return 0;
  211. }
  212. #ifdef CONFIG_KS8851_MLL
  213. int board_eth_init(bd_t *bis)
  214. {
  215. return ks8851_mll_initialize(0, CONFIG_KS8851_MLL_BASEADDR);
  216. }
  217. #endif
  218. int dram_init(void)
  219. {
  220. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  221. CONFIG_SYS_SDRAM_SIZE);
  222. return 0;
  223. }