at91sam9n12ek.c 6.4 KB

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