at91sam9m10g45ek.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/at91sam9g45_matrix.h>
  27. #include <asm/arch/at91sam9_smc.h>
  28. #include <asm/arch/at91_common.h>
  29. #include <asm/arch/at91_pmc.h>
  30. #include <asm/arch/at91_rstc.h>
  31. #include <asm/arch/gpio.h>
  32. #include <asm/arch/clk.h>
  33. #include <lcd.h>
  34. #include <atmel_lcdc.h>
  35. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  36. #include <net.h>
  37. #endif
  38. #include <netdev.h>
  39. DECLARE_GLOBAL_DATA_PTR;
  40. /* ------------------------------------------------------------------------- */
  41. /*
  42. * Miscelaneous platform dependent initialisations
  43. */
  44. #ifdef CONFIG_CMD_NAND
  45. void at91sam9m10g45ek_nand_hw_init(void)
  46. {
  47. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  48. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  49. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  50. unsigned long csa;
  51. /* Enable CS3 */
  52. csa = readl(&matrix->ebicsa);
  53. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  54. writel(csa, &matrix->ebicsa);
  55. /* Configure SMC CS3 for NAND/SmartMedia */
  56. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  57. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  58. &smc->cs[3].setup);
  59. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  60. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  61. &smc->cs[3].pulse);
  62. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  63. &smc->cs[3].cycle);
  64. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  65. AT91_SMC_MODE_EXNW_DISABLE |
  66. #ifdef CONFIG_SYS_NAND_DBW_16
  67. AT91_SMC_MODE_DBW_16 |
  68. #else /* CONFIG_SYS_NAND_DBW_8 */
  69. AT91_SMC_MODE_DBW_8 |
  70. #endif
  71. AT91_SMC_MODE_TDF_CYCLE(3),
  72. &smc->cs[3].mode);
  73. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  74. /* Configure RDY/BSY */
  75. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  76. /* Enable NandFlash */
  77. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  78. }
  79. #endif
  80. #ifdef CONFIG_CMD_USB
  81. static void at91sam9m10g45ek_usb_hw_init(void)
  82. {
  83. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  84. writel(1 << ATMEL_ID_PIODE, &pmc->pcer);
  85. at91_set_gpio_output(AT91_PIN_PD1, 0);
  86. at91_set_gpio_output(AT91_PIN_PD3, 0);
  87. }
  88. #endif
  89. #ifdef CONFIG_MACB
  90. static void at91sam9m10g45ek_macb_hw_init(void)
  91. {
  92. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  93. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  94. struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
  95. unsigned long erstl;
  96. /* Enable clock */
  97. writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
  98. /*
  99. * Disable pull-up on:
  100. * RXDV (PA15) => PHY normal mode (not Test mode)
  101. * ERX0 (PA12) => PHY ADDR0
  102. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  103. *
  104. * PHY has internal pull-down
  105. */
  106. writel(pin_to_mask(AT91_PIN_PA15) |
  107. pin_to_mask(AT91_PIN_PA12) |
  108. pin_to_mask(AT91_PIN_PA13),
  109. &pioa->pudr);
  110. erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  111. /* Need to reset PHY -> 500ms reset */
  112. writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
  113. AT91_RSTC_MR_URSTEN, &rstc->mr);
  114. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  115. /* Wait for end hardware reset */
  116. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
  117. ;
  118. /* Restore NRST value */
  119. writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
  120. &rstc->mr);
  121. /* Re-enable pull-up */
  122. writel(pin_to_mask(AT91_PIN_PA15) |
  123. pin_to_mask(AT91_PIN_PA12) |
  124. pin_to_mask(AT91_PIN_PA13),
  125. &pioa->puer);
  126. /* And the pins. */
  127. at91_macb_hw_init();
  128. }
  129. #endif
  130. #ifdef CONFIG_LCD
  131. vidinfo_t panel_info = {
  132. vl_col: 480,
  133. vl_row: 272,
  134. vl_clk: 9000000,
  135. vl_sync: ATMEL_LCDC_INVLINE_NORMAL |
  136. ATMEL_LCDC_INVFRAME_NORMAL,
  137. vl_bpix: 3,
  138. vl_tft: 1,
  139. vl_hsync_len: 45,
  140. vl_left_margin: 1,
  141. vl_right_margin:1,
  142. vl_vsync_len: 1,
  143. vl_upper_margin:40,
  144. vl_lower_margin:1,
  145. mmio : ATMEL_BASE_LCDC,
  146. };
  147. void lcd_enable(void)
  148. {
  149. at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
  150. }
  151. void lcd_disable(void)
  152. {
  153. at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
  154. }
  155. static void at91sam9m10g45ek_lcd_hw_init(void)
  156. {
  157. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  158. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  159. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  160. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  161. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  162. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  163. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  164. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  165. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  166. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  167. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  168. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  169. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  170. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  171. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  172. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  173. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  174. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  175. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  176. at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  177. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  178. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  179. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  180. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  181. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  182. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  183. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  184. at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  185. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  186. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  187. writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
  188. gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
  189. }
  190. #ifdef CONFIG_LCD_INFO
  191. #include <nand.h>
  192. #include <version.h>
  193. void lcd_show_board_info(void)
  194. {
  195. ulong dram_size, nand_size;
  196. int i;
  197. char temp[32];
  198. lcd_printf ("%s\n", U_BOOT_VERSION);
  199. lcd_printf ("(C) 2008 ATMEL Corp\n");
  200. lcd_printf ("at91support@atmel.com\n");
  201. lcd_printf ("%s CPU at %s MHz\n",
  202. ATMEL_CPU_NAME,
  203. strmhz(temp, get_cpu_clk_rate()));
  204. dram_size = 0;
  205. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  206. dram_size += gd->bd->bi_dram[i].size;
  207. nand_size = 0;
  208. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  209. nand_size += nand_info[i].size;
  210. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  211. dram_size >> 20,
  212. nand_size >> 20 );
  213. }
  214. #endif /* CONFIG_LCD_INFO */
  215. #endif
  216. int board_early_init_f(void)
  217. {
  218. at91_seriald_hw_init();
  219. return 0;
  220. }
  221. int board_init(void)
  222. {
  223. /* arch number of AT91SAM9M10G45EK-Board */
  224. #ifdef CONFIG_AT91SAM9M10G45EK
  225. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
  226. #elif defined CONFIG_AT91SAM9G45EKES
  227. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
  228. #endif
  229. /* adress of boot parameters */
  230. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  231. #ifdef CONFIG_CMD_NAND
  232. at91sam9m10g45ek_nand_hw_init();
  233. #endif
  234. #ifdef CONFIG_CMD_USB
  235. at91sam9m10g45ek_usb_hw_init();
  236. #endif
  237. #ifdef CONFIG_HAS_DATAFLASH
  238. at91_spi0_hw_init(1 << 0);
  239. #endif
  240. #ifdef CONFIG_ATMEL_SPI
  241. at91_spi0_hw_init(1 << 4);
  242. #endif
  243. #ifdef CONFIG_MACB
  244. at91sam9m10g45ek_macb_hw_init();
  245. #endif
  246. #ifdef CONFIG_LCD
  247. at91sam9m10g45ek_lcd_hw_init();
  248. #endif
  249. return 0;
  250. }
  251. int dram_init(void)
  252. {
  253. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  254. CONFIG_SYS_SDRAM_SIZE);
  255. return 0;
  256. }
  257. #ifdef CONFIG_RESET_PHY_R
  258. void reset_phy(void)
  259. {
  260. }
  261. #endif
  262. int board_eth_init(bd_t *bis)
  263. {
  264. int rc = 0;
  265. #ifdef CONFIG_MACB
  266. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  267. #endif
  268. return rc;
  269. }
  270. /* SPI chip select control */
  271. #ifdef CONFIG_ATMEL_SPI
  272. #include <spi.h>
  273. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  274. {
  275. return bus == 0 && cs < 2;
  276. }
  277. void spi_cs_activate(struct spi_slave *slave)
  278. {
  279. switch(slave->cs) {
  280. case 1:
  281. at91_set_gpio_output(AT91_PIN_PB18, 0);
  282. break;
  283. case 0:
  284. default:
  285. at91_set_gpio_output(AT91_PIN_PB3, 0);
  286. break;
  287. }
  288. }
  289. void spi_cs_deactivate(struct spi_slave *slave)
  290. {
  291. switch(slave->cs) {
  292. case 1:
  293. at91_set_gpio_output(AT91_PIN_PB18, 1);
  294. break;
  295. case 0:
  296. default:
  297. at91_set_gpio_output(AT91_PIN_PB3, 1);
  298. break;
  299. }
  300. }
  301. #endif /* CONFIG_ATMEL_SPI */