at91sam9m10g45ek.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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/at91sam9g45_matrix.h>
  11. #include <asm/arch/at91sam9_smc.h>
  12. #include <asm/arch/at91_common.h>
  13. #include <asm/arch/at91_pmc.h>
  14. #include <asm/arch/gpio.h>
  15. #include <asm/arch/clk.h>
  16. #include <lcd.h>
  17. #include <atmel_lcdc.h>
  18. #include <atmel_mci.h>
  19. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  20. #include <net.h>
  21. #endif
  22. #include <netdev.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. /* ------------------------------------------------------------------------- */
  25. /*
  26. * Miscelaneous platform dependent initialisations
  27. */
  28. #ifdef CONFIG_CMD_NAND
  29. void at91sam9m10g45ek_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. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  34. unsigned long csa;
  35. /* Enable CS3 */
  36. csa = readl(&matrix->ebicsa);
  37. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  38. writel(csa, &matrix->ebicsa);
  39. /* Configure SMC CS3 for NAND/SmartMedia */
  40. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  41. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  42. &smc->cs[3].setup);
  43. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  44. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  45. &smc->cs[3].pulse);
  46. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  47. &smc->cs[3].cycle);
  48. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  49. AT91_SMC_MODE_EXNW_DISABLE |
  50. #ifdef CONFIG_SYS_NAND_DBW_16
  51. AT91_SMC_MODE_DBW_16 |
  52. #else /* CONFIG_SYS_NAND_DBW_8 */
  53. AT91_SMC_MODE_DBW_8 |
  54. #endif
  55. AT91_SMC_MODE_TDF_CYCLE(3),
  56. &smc->cs[3].mode);
  57. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  58. /* Configure RDY/BSY */
  59. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  60. /* Enable NandFlash */
  61. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  62. }
  63. #endif
  64. #ifdef CONFIG_CMD_USB
  65. static void at91sam9m10g45ek_usb_hw_init(void)
  66. {
  67. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  68. writel(1 << ATMEL_ID_PIODE, &pmc->pcer);
  69. at91_set_gpio_output(AT91_PIN_PD1, 0);
  70. at91_set_gpio_output(AT91_PIN_PD3, 0);
  71. }
  72. #endif
  73. #ifdef CONFIG_MACB
  74. static void at91sam9m10g45ek_macb_hw_init(void)
  75. {
  76. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  77. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  78. /* Enable clock */
  79. writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
  80. /*
  81. * Disable pull-up on:
  82. * RXDV (PA15) => PHY normal mode (not Test mode)
  83. * ERX0 (PA12) => PHY ADDR0
  84. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  85. *
  86. * PHY has internal pull-down
  87. */
  88. writel(pin_to_mask(AT91_PIN_PA15) |
  89. pin_to_mask(AT91_PIN_PA12) |
  90. pin_to_mask(AT91_PIN_PA13),
  91. &pioa->pudr);
  92. at91_phy_reset();
  93. /* Re-enable pull-up */
  94. writel(pin_to_mask(AT91_PIN_PA15) |
  95. pin_to_mask(AT91_PIN_PA12) |
  96. pin_to_mask(AT91_PIN_PA13),
  97. &pioa->puer);
  98. /* And the pins. */
  99. at91_macb_hw_init();
  100. }
  101. #endif
  102. #ifdef CONFIG_LCD
  103. vidinfo_t panel_info = {
  104. .vl_col = 480,
  105. .vl_row = 272,
  106. .vl_clk = 9000000,
  107. .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
  108. ATMEL_LCDC_INVFRAME_NORMAL,
  109. .vl_bpix = 3,
  110. .vl_tft = 1,
  111. .vl_hsync_len = 45,
  112. .vl_left_margin = 1,
  113. .vl_right_margin = 1,
  114. .vl_vsync_len = 1,
  115. .vl_upper_margin = 40,
  116. .vl_lower_margin = 1,
  117. .mmio = ATMEL_BASE_LCDC,
  118. };
  119. void lcd_enable(void)
  120. {
  121. at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
  122. }
  123. void lcd_disable(void)
  124. {
  125. at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
  126. }
  127. static void at91sam9m10g45ek_lcd_hw_init(void)
  128. {
  129. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  130. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  131. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  132. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  133. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  134. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  135. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  136. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  137. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  138. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  139. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  140. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  141. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  142. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  143. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  144. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  145. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  146. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  147. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  148. at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  149. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  150. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  151. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  152. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  153. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  154. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  155. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  156. at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  157. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  158. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  159. writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
  160. gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
  161. }
  162. #ifdef CONFIG_LCD_INFO
  163. #include <nand.h>
  164. #include <version.h>
  165. void lcd_show_board_info(void)
  166. {
  167. ulong dram_size, nand_size;
  168. int i;
  169. char temp[32];
  170. lcd_printf ("%s\n", U_BOOT_VERSION);
  171. lcd_printf ("(C) 2008 ATMEL Corp\n");
  172. lcd_printf ("at91support@atmel.com\n");
  173. lcd_printf ("%s CPU at %s MHz\n",
  174. ATMEL_CPU_NAME,
  175. strmhz(temp, get_cpu_clk_rate()));
  176. dram_size = 0;
  177. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  178. dram_size += gd->bd->bi_dram[i].size;
  179. nand_size = 0;
  180. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  181. nand_size += nand_info[i].size;
  182. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  183. dram_size >> 20,
  184. nand_size >> 20 );
  185. }
  186. #endif /* CONFIG_LCD_INFO */
  187. #endif
  188. #ifdef CONFIG_GENERIC_ATMEL_MCI
  189. int board_mmc_init(bd_t *bis)
  190. {
  191. at91_mci_hw_init();
  192. return atmel_mci_init((void *)ATMEL_BASE_MCI0);
  193. }
  194. #endif
  195. int board_early_init_f(void)
  196. {
  197. at91_seriald_hw_init();
  198. return 0;
  199. }
  200. int board_init(void)
  201. {
  202. /* arch number of AT91SAM9M10G45EK-Board */
  203. #ifdef CONFIG_AT91SAM9M10G45EK
  204. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
  205. #elif defined CONFIG_AT91SAM9G45EKES
  206. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
  207. #endif
  208. /* adress of boot parameters */
  209. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  210. #ifdef CONFIG_CMD_NAND
  211. at91sam9m10g45ek_nand_hw_init();
  212. #endif
  213. #ifdef CONFIG_CMD_USB
  214. at91sam9m10g45ek_usb_hw_init();
  215. #endif
  216. #ifdef CONFIG_HAS_DATAFLASH
  217. at91_spi0_hw_init(1 << 0);
  218. #endif
  219. #ifdef CONFIG_ATMEL_SPI
  220. at91_spi0_hw_init(1 << 4);
  221. #endif
  222. #ifdef CONFIG_MACB
  223. at91sam9m10g45ek_macb_hw_init();
  224. #endif
  225. #ifdef CONFIG_LCD
  226. at91sam9m10g45ek_lcd_hw_init();
  227. #endif
  228. return 0;
  229. }
  230. int dram_init(void)
  231. {
  232. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  233. CONFIG_SYS_SDRAM_SIZE);
  234. return 0;
  235. }
  236. #ifdef CONFIG_RESET_PHY_R
  237. void reset_phy(void)
  238. {
  239. }
  240. #endif
  241. int board_eth_init(bd_t *bis)
  242. {
  243. int rc = 0;
  244. #ifdef CONFIG_MACB
  245. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  246. #endif
  247. return rc;
  248. }
  249. /* SPI chip select control */
  250. #ifdef CONFIG_ATMEL_SPI
  251. #include <spi.h>
  252. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  253. {
  254. return bus == 0 && cs < 2;
  255. }
  256. void spi_cs_activate(struct spi_slave *slave)
  257. {
  258. switch(slave->cs) {
  259. case 1:
  260. at91_set_gpio_output(AT91_PIN_PB18, 0);
  261. break;
  262. case 0:
  263. default:
  264. at91_set_gpio_output(AT91_PIN_PB3, 0);
  265. break;
  266. }
  267. }
  268. void spi_cs_deactivate(struct spi_slave *slave)
  269. {
  270. switch(slave->cs) {
  271. case 1:
  272. at91_set_gpio_output(AT91_PIN_PB18, 1);
  273. break;
  274. case 0:
  275. default:
  276. at91_set_gpio_output(AT91_PIN_PB3, 1);
  277. break;
  278. }
  279. }
  280. #endif /* CONFIG_ATMEL_SPI */