at91sam9261ek.c 7.4 KB

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