at91sam9m10g45ek.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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/clk.h>
  11. #include <asm/arch/at91sam9g45_matrix.h>
  12. #include <asm/arch/at91sam9_smc.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/at91_pmc.h>
  15. #include <asm/arch/gpio.h>
  16. #include <asm/arch/clk.h>
  17. #include <lcd.h>
  18. #include <linux/mtd/nand.h>
  19. #include <atmel_lcdc.h>
  20. #include <atmel_mci.h>
  21. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  22. #include <net.h>
  23. #endif
  24. #include <netdev.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. /* ------------------------------------------------------------------------- */
  27. /*
  28. * Miscelaneous platform dependent initialisations
  29. */
  30. #ifdef CONFIG_CMD_NAND
  31. void at91sam9m10g45ek_nand_hw_init(void)
  32. {
  33. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  34. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  35. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  36. unsigned long csa;
  37. /* Enable CS3 */
  38. csa = readl(&matrix->ebicsa);
  39. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  40. writel(csa, &matrix->ebicsa);
  41. /* Configure SMC CS3 for NAND/SmartMedia */
  42. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  43. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  44. &smc->cs[3].setup);
  45. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  46. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  47. &smc->cs[3].pulse);
  48. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  49. &smc->cs[3].cycle);
  50. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  51. AT91_SMC_MODE_EXNW_DISABLE |
  52. #ifdef CONFIG_SYS_NAND_DBW_16
  53. AT91_SMC_MODE_DBW_16 |
  54. #else /* CONFIG_SYS_NAND_DBW_8 */
  55. AT91_SMC_MODE_DBW_8 |
  56. #endif
  57. AT91_SMC_MODE_TDF_CYCLE(3),
  58. &smc->cs[3].mode);
  59. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  60. /* Configure RDY/BSY */
  61. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  62. /* Enable NandFlash */
  63. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  64. }
  65. #endif
  66. #if defined(CONFIG_SPL_BUILD)
  67. #include <spl.h>
  68. #include <nand.h>
  69. void at91_spl_board_init(void)
  70. {
  71. /*
  72. * On the at91sam9m10g45ek board, the chip wm9711 stays in the
  73. * test mode, so it needs do some action to exit test mode.
  74. */
  75. at91_periph_clk_enable(ATMEL_ID_PIODE);
  76. at91_set_gpio_output(AT91_PIN_PD7, 0);
  77. at91_set_gpio_output(AT91_PIN_PD8, 0);
  78. at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
  79. at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
  80. #ifdef CONFIG_SYS_USE_MMC
  81. at91_mci_hw_init();
  82. #elif CONFIG_SYS_USE_NANDFLASH
  83. at91sam9m10g45ek_nand_hw_init();
  84. #endif
  85. }
  86. #include <asm/arch/atmel_mpddrc.h>
  87. static void ddr2_conf(struct atmel_mpddr *ddr2)
  88. {
  89. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  90. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  91. ATMEL_MPDDRC_CR_NR_ROW_14 |
  92. ATMEL_MPDDRC_CR_DQMS_SHARED |
  93. ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
  94. ddr2->rtr = 0x24b;
  95. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
  96. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
  97. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
  98. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
  99. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
  100. 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
  101. 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
  102. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
  103. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
  104. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  105. 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  106. 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  107. ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  108. 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  109. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  110. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  111. }
  112. void mem_init(void)
  113. {
  114. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  115. struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  116. struct atmel_mpddr ddr2;
  117. unsigned long csa;
  118. ddr2_conf(&ddr2);
  119. /* enable DDR2 clock */
  120. writel(0x4, &pmc->scer);
  121. /* Chip select 1 is for DDR2/SDRAM */
  122. csa = readl(&mat->ebicsa);
  123. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  124. csa &= ~AT91_MATRIX_EBI_VDDIOMSEL_3_3V;
  125. writel(csa, &mat->ebicsa);
  126. /* DDRAM2 Controller initialize */
  127. ddr2_init(ATMEL_BASE_CS6, &ddr2);
  128. }
  129. #endif
  130. #ifdef CONFIG_CMD_USB
  131. static void at91sam9m10g45ek_usb_hw_init(void)
  132. {
  133. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  134. writel(1 << ATMEL_ID_PIODE, &pmc->pcer);
  135. at91_set_gpio_output(AT91_PIN_PD1, 0);
  136. at91_set_gpio_output(AT91_PIN_PD3, 0);
  137. }
  138. #endif
  139. #ifdef CONFIG_MACB
  140. static void at91sam9m10g45ek_macb_hw_init(void)
  141. {
  142. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  143. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  144. /* Enable clock */
  145. writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
  146. /*
  147. * Disable pull-up on:
  148. * RXDV (PA15) => PHY normal mode (not Test mode)
  149. * ERX0 (PA12) => PHY ADDR0
  150. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  151. *
  152. * PHY has internal pull-down
  153. */
  154. writel(pin_to_mask(AT91_PIN_PA15) |
  155. pin_to_mask(AT91_PIN_PA12) |
  156. pin_to_mask(AT91_PIN_PA13),
  157. &pioa->pudr);
  158. at91_phy_reset();
  159. /* Re-enable pull-up */
  160. writel(pin_to_mask(AT91_PIN_PA15) |
  161. pin_to_mask(AT91_PIN_PA12) |
  162. pin_to_mask(AT91_PIN_PA13),
  163. &pioa->puer);
  164. /* And the pins. */
  165. at91_macb_hw_init();
  166. }
  167. #endif
  168. #ifdef CONFIG_LCD
  169. vidinfo_t panel_info = {
  170. .vl_col = 480,
  171. .vl_row = 272,
  172. .vl_clk = 9000000,
  173. .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
  174. ATMEL_LCDC_INVFRAME_NORMAL,
  175. .vl_bpix = 3,
  176. .vl_tft = 1,
  177. .vl_hsync_len = 45,
  178. .vl_left_margin = 1,
  179. .vl_right_margin = 1,
  180. .vl_vsync_len = 1,
  181. .vl_upper_margin = 40,
  182. .vl_lower_margin = 1,
  183. .mmio = ATMEL_BASE_LCDC,
  184. };
  185. void lcd_enable(void)
  186. {
  187. at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
  188. }
  189. void lcd_disable(void)
  190. {
  191. at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
  192. }
  193. static void at91sam9m10g45ek_lcd_hw_init(void)
  194. {
  195. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  196. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  197. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  198. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  199. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  200. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  201. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  202. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  203. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  204. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  205. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  206. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  207. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  208. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  209. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  210. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  211. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  212. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  213. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  214. at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  215. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  216. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  217. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  218. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  219. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  220. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  221. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  222. at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  223. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  224. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  225. writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
  226. gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
  227. }
  228. #ifdef CONFIG_LCD_INFO
  229. #include <nand.h>
  230. #include <version.h>
  231. void lcd_show_board_info(void)
  232. {
  233. ulong dram_size, nand_size;
  234. int i;
  235. char temp[32];
  236. lcd_printf ("%s\n", U_BOOT_VERSION);
  237. lcd_printf ("(C) 2008 ATMEL Corp\n");
  238. lcd_printf ("at91support@atmel.com\n");
  239. lcd_printf ("%s CPU at %s MHz\n",
  240. ATMEL_CPU_NAME,
  241. strmhz(temp, get_cpu_clk_rate()));
  242. dram_size = 0;
  243. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  244. dram_size += gd->bd->bi_dram[i].size;
  245. nand_size = 0;
  246. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  247. nand_size += nand_info[i].size;
  248. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  249. dram_size >> 20,
  250. nand_size >> 20 );
  251. }
  252. #endif /* CONFIG_LCD_INFO */
  253. #endif
  254. #ifdef CONFIG_GENERIC_ATMEL_MCI
  255. int board_mmc_init(bd_t *bis)
  256. {
  257. at91_mci_hw_init();
  258. return atmel_mci_init((void *)ATMEL_BASE_MCI0);
  259. }
  260. #endif
  261. int board_early_init_f(void)
  262. {
  263. at91_seriald_hw_init();
  264. return 0;
  265. }
  266. int board_init(void)
  267. {
  268. /* arch number of AT91SAM9M10G45EK-Board */
  269. #ifdef CONFIG_AT91SAM9M10G45EK
  270. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
  271. #elif defined CONFIG_AT91SAM9G45EKES
  272. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
  273. #endif
  274. /* adress of boot parameters */
  275. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  276. #ifdef CONFIG_CMD_NAND
  277. at91sam9m10g45ek_nand_hw_init();
  278. #endif
  279. #ifdef CONFIG_CMD_USB
  280. at91sam9m10g45ek_usb_hw_init();
  281. #endif
  282. #ifdef CONFIG_HAS_DATAFLASH
  283. at91_spi0_hw_init(1 << 0);
  284. #endif
  285. #ifdef CONFIG_ATMEL_SPI
  286. at91_spi0_hw_init(1 << 4);
  287. #endif
  288. #ifdef CONFIG_MACB
  289. at91sam9m10g45ek_macb_hw_init();
  290. #endif
  291. #ifdef CONFIG_LCD
  292. at91sam9m10g45ek_lcd_hw_init();
  293. #endif
  294. return 0;
  295. }
  296. int dram_init(void)
  297. {
  298. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  299. CONFIG_SYS_SDRAM_SIZE);
  300. return 0;
  301. }
  302. #ifdef CONFIG_RESET_PHY_R
  303. void reset_phy(void)
  304. {
  305. }
  306. #endif
  307. int board_eth_init(bd_t *bis)
  308. {
  309. int rc = 0;
  310. #ifdef CONFIG_MACB
  311. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  312. #endif
  313. return rc;
  314. }
  315. /* SPI chip select control */
  316. #ifdef CONFIG_ATMEL_SPI
  317. #include <spi.h>
  318. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  319. {
  320. return bus == 0 && cs < 2;
  321. }
  322. void spi_cs_activate(struct spi_slave *slave)
  323. {
  324. switch(slave->cs) {
  325. case 1:
  326. at91_set_gpio_output(AT91_PIN_PB18, 0);
  327. break;
  328. case 0:
  329. default:
  330. at91_set_gpio_output(AT91_PIN_PB3, 0);
  331. break;
  332. }
  333. }
  334. void spi_cs_deactivate(struct spi_slave *slave)
  335. {
  336. switch(slave->cs) {
  337. case 1:
  338. at91_set_gpio_output(AT91_PIN_PB18, 1);
  339. break;
  340. case 0:
  341. default:
  342. at91_set_gpio_output(AT91_PIN_PB3, 1);
  343. break;
  344. }
  345. }
  346. #endif /* CONFIG_ATMEL_SPI */