at91cap9adk.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  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/arch/at91cap9.h>
  26. #include <asm/arch/at91cap9_matrix.h>
  27. #include <asm/arch/at91sam9_smc.h>
  28. #include <asm/arch/at91_pmc.h>
  29. #include <asm/arch/at91_rstc.h>
  30. #include <asm/arch/gpio.h>
  31. #include <asm/arch/io.h>
  32. #include <lcd.h>
  33. #include <atmel_lcdc.h>
  34. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  35. #include <net.h>
  36. #endif
  37. #define MP_BLOCK_3_BASE 0xFDF00000
  38. DECLARE_GLOBAL_DATA_PTR;
  39. /* ------------------------------------------------------------------------- */
  40. /*
  41. * Miscelaneous platform dependent initialisations
  42. */
  43. static void at91cap9_serial_hw_init(void)
  44. {
  45. #ifdef CONFIG_USART0
  46. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  47. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  48. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0);
  49. #endif
  50. #ifdef CONFIG_USART1
  51. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  52. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  53. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1);
  54. #endif
  55. #ifdef CONFIG_USART2
  56. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  57. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  58. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2);
  59. #endif
  60. #ifdef CONFIG_USART3 /* DBGU */
  61. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  62. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  63. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  64. #endif
  65. }
  66. static void at91cap9_nor_hw_init(void)
  67. {
  68. unsigned long csa;
  69. /* Ensure EBI supply is 3.3V */
  70. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  71. at91_sys_write(AT91_MATRIX_EBICSA,
  72. csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  73. /* Configure SMC CS0 for parallel flash */
  74. at91_sys_write(AT91_SMC_SETUP(0),
  75. AT91_SMC_NWESETUP_(4) | AT91_SMC_NCS_WRSETUP_(2) |
  76. AT91_SMC_NRDSETUP_(4) | AT91_SMC_NCS_RDSETUP_(2));
  77. at91_sys_write(AT91_SMC_PULSE(0),
  78. AT91_SMC_NWEPULSE_(8) | AT91_SMC_NCS_WRPULSE_(10) |
  79. AT91_SMC_NRDPULSE_(8) | AT91_SMC_NCS_RDPULSE_(10));
  80. at91_sys_write(AT91_SMC_CYCLE(0),
  81. AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  82. at91_sys_write(AT91_SMC_MODE(0),
  83. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  84. AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE |
  85. AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
  86. }
  87. #ifdef CONFIG_CMD_NAND
  88. static void at91cap9_nand_hw_init(void)
  89. {
  90. unsigned long csa;
  91. /* Enable CS3 */
  92. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  93. at91_sys_write(AT91_MATRIX_EBICSA,
  94. csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA |
  95. AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  96. /* Configure SMC CS3 for NAND/SmartMedia */
  97. at91_sys_write(AT91_SMC_SETUP(3),
  98. AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1) |
  99. AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  100. at91_sys_write(AT91_SMC_PULSE(3),
  101. AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6) |
  102. AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  103. at91_sys_write(AT91_SMC_CYCLE(3),
  104. AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  105. at91_sys_write(AT91_SMC_MODE(3),
  106. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  107. AT91_SMC_EXNWMODE_DISABLE |
  108. #ifdef CFG_NAND_DBW_16
  109. AT91_SMC_DBW_16 |
  110. #else /* CFG_NAND_DBW_8 */
  111. AT91_SMC_DBW_8 |
  112. #endif
  113. AT91_SMC_TDF_(1));
  114. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD);
  115. /* RDY/BSY is not connected */
  116. /* Enable NandFlash */
  117. at91_set_gpio_output(AT91_PIN_PD15, 1);
  118. }
  119. #endif
  120. #ifdef CONFIG_HAS_DATAFLASH
  121. static void at91cap9_spi_hw_init(void)
  122. {
  123. at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
  124. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  125. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  126. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  127. /* Enable clock */
  128. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
  129. }
  130. #endif
  131. #ifdef CONFIG_MACB
  132. static void at91cap9_macb_hw_init(void)
  133. {
  134. /* Enable clock */
  135. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC);
  136. /*
  137. * Disable pull-up on:
  138. * RXDV (PB22) => PHY normal mode (not Test mode)
  139. * ERX0 (PB25) => PHY ADDR0
  140. * ERX1 (PB26) => PHY ADDR1 => PHYADDR = 0x0
  141. *
  142. * PHY has internal pull-down
  143. */
  144. writel(pin_to_mask(AT91_PIN_PB22) |
  145. pin_to_mask(AT91_PIN_PB25) |
  146. pin_to_mask(AT91_PIN_PB26),
  147. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  148. /* Need to reset PHY -> 500ms reset */
  149. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  150. AT91_RSTC_ERSTL | (0x0D << 8) |
  151. AT91_RSTC_URSTEN);
  152. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  153. /* Wait for end hardware reset */
  154. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  155. /* Re-enable pull-up */
  156. writel(pin_to_mask(AT91_PIN_PB22) |
  157. pin_to_mask(AT91_PIN_PB25) |
  158. pin_to_mask(AT91_PIN_PB26),
  159. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  160. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  161. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  162. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  163. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  164. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  165. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  166. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  167. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  168. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  169. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  170. #ifndef CONFIG_RMII
  171. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  172. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  173. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  174. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  175. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  176. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  177. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  178. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  179. #endif
  180. /* Unlock EMAC, 3 0 2 1 sequence */
  181. #define MP_MAC_KEY0 0x5969cb2a
  182. #define MP_MAC_KEY1 0xb4a1872e
  183. #define MP_MAC_KEY2 0x05683fbc
  184. #define MP_MAC_KEY3 0x3634fba4
  185. #define UNLOCK_MAC 0x00000008
  186. writel(MP_MAC_KEY3, MP_BLOCK_3_BASE + 0x3c);
  187. writel(MP_MAC_KEY0, MP_BLOCK_3_BASE + 0x30);
  188. writel(MP_MAC_KEY2, MP_BLOCK_3_BASE + 0x38);
  189. writel(MP_MAC_KEY1, MP_BLOCK_3_BASE + 0x34);
  190. writel(UNLOCK_MAC, MP_BLOCK_3_BASE + 0x40);
  191. }
  192. #endif
  193. #ifdef CONFIG_USB_OHCI_NEW
  194. static void at91cap9_uhp_hw_init(void)
  195. {
  196. /* Unlock USB OHCI, 3 2 0 1 sequence */
  197. #define MP_OHCI_KEY0 0x896c11ca
  198. #define MP_OHCI_KEY1 0x68ebca21
  199. #define MP_OHCI_KEY2 0x4823efbc
  200. #define MP_OHCI_KEY3 0x8651aae4
  201. #define UNLOCK_OHCI 0x00000010
  202. writel(MP_OHCI_KEY3, MP_BLOCK_3_BASE + 0x3c);
  203. writel(MP_OHCI_KEY2, MP_BLOCK_3_BASE + 0x38);
  204. writel(MP_OHCI_KEY0, MP_BLOCK_3_BASE + 0x30);
  205. writel(MP_OHCI_KEY1, MP_BLOCK_3_BASE + 0x34);
  206. writel(UNLOCK_OHCI, MP_BLOCK_3_BASE + 0x40);
  207. }
  208. #endif
  209. #ifdef CONFIG_LCD
  210. vidinfo_t panel_info = {
  211. vl_col: 240,
  212. vl_row: 320,
  213. vl_clk: 4965000,
  214. vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
  215. ATMEL_LCDC_INVFRAME_INVERTED,
  216. vl_bpix: 3,
  217. vl_tft: 1,
  218. vl_hsync_len: 5,
  219. vl_left_margin: 1,
  220. vl_right_margin:33,
  221. vl_vsync_len: 1,
  222. vl_upper_margin:1,
  223. vl_lower_margin:0,
  224. mmio: AT91CAP9_LCDC_BASE,
  225. };
  226. void lcd_enable(void)
  227. {
  228. at91_set_gpio_value(AT91_PIN_PC0, 0); /* power up */
  229. }
  230. void lcd_disable(void)
  231. {
  232. at91_set_gpio_value(AT91_PIN_PC0, 1); /* power down */
  233. }
  234. static void at91cap9_lcd_hw_init(void)
  235. {
  236. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  237. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  238. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  239. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  240. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  241. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  242. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  243. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  244. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  245. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  246. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  247. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  248. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  249. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  250. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  251. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  252. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  253. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  254. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  255. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  256. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  257. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  258. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_LCDC);
  259. gd->fb_base = 0;
  260. }
  261. #endif
  262. int board_init(void)
  263. {
  264. /* Enable Ctrlc */
  265. console_init_f();
  266. /* arch number of AT91CAP9ADK-Board */
  267. gd->bd->bi_arch_number = MACH_TYPE_AT91CAP9ADK;
  268. /* adress of boot parameters */
  269. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  270. at91cap9_serial_hw_init();
  271. at91cap9_nor_hw_init();
  272. #ifdef CONFIG_CMD_NAND
  273. at91cap9_nand_hw_init();
  274. #endif
  275. #ifdef CONFIG_HAS_DATAFLASH
  276. at91cap9_spi_hw_init();
  277. #endif
  278. #ifdef CONFIG_MACB
  279. at91cap9_macb_hw_init();
  280. #endif
  281. #ifdef CONFIG_USB_OHCI_NEW
  282. at91cap9_uhp_hw_init();
  283. #endif
  284. #ifdef CONFIG_LCD
  285. at91cap9_lcd_hw_init();
  286. #endif
  287. return 0;
  288. }
  289. int dram_init(void)
  290. {
  291. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  292. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  293. return 0;
  294. }
  295. #ifdef CONFIG_RESET_PHY_R
  296. void reset_phy(void)
  297. {
  298. #ifdef CONFIG_MACB
  299. /*
  300. * Initialize ethernet HW addr prior to starting Linux,
  301. * needed for nfsroot
  302. */
  303. eth_init(gd->bd);
  304. #endif
  305. }
  306. #endif