at91sam9m10g45ek.c 9.5 KB

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