at91sam9x5ek.c 7.8 KB

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