at91sam9261ek.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007-2008
  4. * Stelian Pop <stelian@popies.net>
  5. * Lead Tech Design <www.leadtechdesign.com>
  6. */
  7. #include <common.h>
  8. #include <debug_uart.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/at91sam9261.h>
  11. #include <asm/arch/at91sam9261_matrix.h>
  12. #include <asm/arch/at91sam9_smc.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/at91_rstc.h>
  15. #include <asm/arch/clk.h>
  16. #include <asm/arch/gpio.h>
  17. #include <lcd.h>
  18. #include <atmel_lcdc.h>
  19. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
  20. #include <net.h>
  21. #include <netdev.h>
  22. #endif
  23. #include <asm/mach-types.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. /* ------------------------------------------------------------------------- */
  26. /*
  27. * Miscelaneous platform dependent initialisations
  28. */
  29. #ifdef CONFIG_CMD_NAND
  30. static void at91sam9261ek_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. /* Enable CS3 */
  36. csa = readl(&matrix->ebicsa);
  37. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  38. writel(csa, &matrix->ebicsa);
  39. /* Configure SMC CS3 for NAND/SmartMedia */
  40. #ifdef CONFIG_AT91SAM9G10EK
  41. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  42. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  43. &smc->cs[3].setup);
  44. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) |
  45. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7),
  46. &smc->cs[3].pulse);
  47. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
  48. &smc->cs[3].cycle);
  49. #else
  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(3) |
  54. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  55. &smc->cs[3].pulse);
  56. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  57. &smc->cs[3].cycle);
  58. #endif
  59. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  60. AT91_SMC_MODE_EXNW_DISABLE |
  61. #ifdef CONFIG_SYS_NAND_DBW_16
  62. AT91_SMC_MODE_DBW_16 |
  63. #else /* CONFIG_SYS_NAND_DBW_8 */
  64. AT91_SMC_MODE_DBW_8 |
  65. #endif
  66. AT91_SMC_MODE_TDF_CYCLE(2),
  67. &smc->cs[3].mode);
  68. at91_periph_clk_enable(ATMEL_ID_PIOC);
  69. /* Configure RDY/BSY */
  70. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  71. /* Enable NandFlash */
  72. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  73. at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
  74. at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
  75. }
  76. #endif
  77. #ifdef CONFIG_DRIVER_DM9000
  78. static void at91sam9261ek_dm9000_hw_init(void)
  79. {
  80. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  81. /* Configure SMC CS2 for DM9000 */
  82. #ifdef CONFIG_AT91SAM9G10EK
  83. writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
  84. AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0),
  85. &smc->cs[2].setup);
  86. writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) |
  87. AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8),
  88. &smc->cs[2].pulse);
  89. writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
  90. &smc->cs[2].cycle);
  91. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  92. AT91_SMC_MODE_EXNW_DISABLE |
  93. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  94. AT91_SMC_MODE_TDF_CYCLE(1),
  95. &smc->cs[2].mode);
  96. #else
  97. writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
  98. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  99. &smc->cs[2].setup);
  100. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
  101. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
  102. &smc->cs[2].pulse);
  103. writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
  104. &smc->cs[2].cycle);
  105. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  106. AT91_SMC_MODE_EXNW_DISABLE |
  107. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  108. AT91_SMC_MODE_TDF_CYCLE(1),
  109. &smc->cs[2].mode);
  110. #endif
  111. /* Configure Reset signal as output */
  112. at91_set_gpio_output(AT91_PIN_PC10, 0);
  113. /* Configure Interrupt pin as input, no pull-up */
  114. at91_set_gpio_input(AT91_PIN_PC11, 0);
  115. }
  116. #endif
  117. #ifdef CONFIG_LCD
  118. vidinfo_t panel_info = {
  119. .vl_col = 240,
  120. .vl_row = 320,
  121. .vl_clk = 4965000,
  122. .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
  123. ATMEL_LCDC_INVFRAME_INVERTED,
  124. .vl_bpix = 3,
  125. .vl_tft = 1,
  126. .vl_hsync_len = 5,
  127. .vl_left_margin = 1,
  128. .vl_right_margin = 33,
  129. .vl_vsync_len = 1,
  130. .vl_upper_margin = 1,
  131. .vl_lower_margin = 0,
  132. .mmio = ATMEL_BASE_LCDC,
  133. };
  134. void lcd_enable(void)
  135. {
  136. at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
  137. }
  138. void lcd_disable(void)
  139. {
  140. at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
  141. }
  142. static void at91sam9261ek_lcd_hw_init(void)
  143. {
  144. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  145. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  146. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  147. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  148. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  149. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  150. at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
  151. at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
  152. at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
  153. at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
  154. at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
  155. at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
  156. at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
  157. at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
  158. at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
  159. at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
  160. at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
  161. at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
  162. at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
  163. at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
  164. at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
  165. at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
  166. at91_system_clk_enable(AT91_PMC_HCK1);
  167. /* For 9G10EK, let U-Boot allocate the framebuffer in SDRAM */
  168. #ifdef CONFIG_AT91SAM9261EK
  169. gd->fb_base = ATMEL_BASE_SRAM;
  170. #endif
  171. }
  172. #ifdef CONFIG_LCD_INFO
  173. #include <nand.h>
  174. #include <version.h>
  175. void lcd_show_board_info(void)
  176. {
  177. ulong dram_size, nand_size;
  178. int i;
  179. char temp[32];
  180. lcd_printf ("%s\n", U_BOOT_VERSION);
  181. lcd_printf ("(C) 2008 ATMEL Corp\n");
  182. lcd_printf ("at91support@atmel.com\n");
  183. lcd_printf ("%s CPU at %s MHz\n",
  184. ATMEL_CPU_NAME,
  185. strmhz(temp, get_cpu_clk_rate()));
  186. dram_size = 0;
  187. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  188. dram_size += gd->bd->bi_dram[i].size;
  189. nand_size = 0;
  190. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  191. nand_size += get_nand_dev_by_index(i)->size;
  192. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  193. dram_size >> 20,
  194. nand_size >> 20 );
  195. }
  196. #endif /* CONFIG_LCD_INFO */
  197. #endif
  198. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  199. void board_debug_uart_init(void)
  200. {
  201. at91_seriald_hw_init();
  202. }
  203. #endif
  204. #ifdef CONFIG_BOARD_EARLY_INIT_F
  205. int board_early_init_f(void)
  206. {
  207. #ifdef CONFIG_DEBUG_UART
  208. debug_uart_init();
  209. #endif
  210. return 0;
  211. }
  212. #endif
  213. int board_init(void)
  214. {
  215. #ifdef CONFIG_AT91SAM9G10EK
  216. /* arch number of AT91SAM9G10EK-Board */
  217. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G10EK;
  218. #else
  219. /* arch number of AT91SAM9261EK-Board */
  220. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
  221. #endif
  222. /* adress of boot parameters */
  223. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  224. #ifdef CONFIG_CMD_NAND
  225. at91sam9261ek_nand_hw_init();
  226. #endif
  227. #ifdef CONFIG_DRIVER_DM9000
  228. at91sam9261ek_dm9000_hw_init();
  229. #endif
  230. #ifdef CONFIG_LCD
  231. at91sam9261ek_lcd_hw_init();
  232. #endif
  233. return 0;
  234. }
  235. #ifdef CONFIG_DRIVER_DM9000
  236. int board_eth_init(bd_t *bis)
  237. {
  238. return dm9000_initialize(bis);
  239. }
  240. #endif
  241. int dram_init(void)
  242. {
  243. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  244. CONFIG_SYS_SDRAM_SIZE);
  245. return 0;
  246. }
  247. #ifdef CONFIG_RESET_PHY_R
  248. void reset_phy(void)
  249. {
  250. #ifdef CONFIG_DRIVER_DM9000
  251. /*
  252. * Initialize ethernet HW addr prior to starting Linux,
  253. * needed for nfsroot
  254. */
  255. eth_init();
  256. #endif
  257. }
  258. #endif