at91cap9adk.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  33. #include <net.h>
  34. #endif
  35. #define MP_BLOCK_3_BASE 0xFDF00000
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /* ------------------------------------------------------------------------- */
  38. /*
  39. * Miscelaneous platform dependent initialisations
  40. */
  41. static void at91cap9_serial_hw_init(void)
  42. {
  43. #ifdef CONFIG_USART0
  44. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  45. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  46. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0);
  47. #endif
  48. #ifdef CONFIG_USART1
  49. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  50. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  51. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1);
  52. #endif
  53. #ifdef CONFIG_USART2
  54. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  55. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  56. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2);
  57. #endif
  58. #ifdef CONFIG_USART3 /* DBGU */
  59. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  60. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  61. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  62. #endif
  63. }
  64. static void at91cap9_nor_hw_init(void)
  65. {
  66. unsigned long csa;
  67. /* Ensure EBI supply is 3.3V */
  68. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  69. at91_sys_write(AT91_MATRIX_EBICSA,
  70. csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  71. /* Configure SMC CS0 for parallel flash */
  72. at91_sys_write(AT91_SMC_SETUP(0),
  73. AT91_SMC_NWESETUP_(4) | AT91_SMC_NCS_WRSETUP_(2) |
  74. AT91_SMC_NRDSETUP_(4) | AT91_SMC_NCS_RDSETUP_(2));
  75. at91_sys_write(AT91_SMC_PULSE(0),
  76. AT91_SMC_NWEPULSE_(8) | AT91_SMC_NCS_WRPULSE_(10) |
  77. AT91_SMC_NRDPULSE_(8) | AT91_SMC_NCS_RDPULSE_(10));
  78. at91_sys_write(AT91_SMC_CYCLE(0),
  79. AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  80. at91_sys_write(AT91_SMC_MODE(0),
  81. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  82. AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE |
  83. AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
  84. }
  85. #ifdef CONFIG_CMD_NAND
  86. static void at91cap9_nand_hw_init(void)
  87. {
  88. unsigned long csa;
  89. /* Enable CS3 */
  90. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  91. at91_sys_write(AT91_MATRIX_EBICSA,
  92. csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA |
  93. AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  94. /* Configure SMC CS3 for NAND/SmartMedia */
  95. at91_sys_write(AT91_SMC_SETUP(3),
  96. AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1) |
  97. AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  98. at91_sys_write(AT91_SMC_PULSE(3),
  99. AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6) |
  100. AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  101. at91_sys_write(AT91_SMC_CYCLE(3),
  102. AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  103. at91_sys_write(AT91_SMC_MODE(3),
  104. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  105. AT91_SMC_EXNWMODE_DISABLE |
  106. AT91_SMC_DBW_8 | AT91_SMC_TDF_(1));
  107. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD);
  108. /* RDY/BSY is not connected */
  109. /* Enable NandFlash */
  110. at91_set_gpio_output(AT91_PIN_PD15, 1);
  111. }
  112. #endif
  113. #ifdef CONFIG_HAS_DATAFLASH
  114. static void at91cap9_spi_hw_init(void)
  115. {
  116. at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
  117. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  118. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  119. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  120. /* Enable clock */
  121. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
  122. }
  123. #endif
  124. #ifdef CONFIG_MACB
  125. static void at91cap9_macb_hw_init(void)
  126. {
  127. /* Enable clock */
  128. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC);
  129. /*
  130. * Disable pull-up on:
  131. * RXDV (PB22) => PHY normal mode (not Test mode)
  132. * ERX0 (PB25) => PHY ADDR0
  133. * ERX1 (PB26) => PHY ADDR1 => PHYADDR = 0x0
  134. *
  135. * PHY has internal pull-down
  136. */
  137. writel(pin_to_mask(AT91_PIN_PB22) |
  138. pin_to_mask(AT91_PIN_PB25) |
  139. pin_to_mask(AT91_PIN_PB26),
  140. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  141. /* Need to reset PHY -> 500ms reset */
  142. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  143. AT91_RSTC_ERSTL | (0x0D << 8) |
  144. AT91_RSTC_URSTEN);
  145. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  146. /* Wait for end hardware reset */
  147. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  148. /* Re-enable pull-up */
  149. writel(pin_to_mask(AT91_PIN_PB22) |
  150. pin_to_mask(AT91_PIN_PB25) |
  151. pin_to_mask(AT91_PIN_PB26),
  152. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  153. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  154. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  155. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  156. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  157. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  158. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  159. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  160. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  161. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  162. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  163. #ifndef CONFIG_RMII
  164. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  165. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  166. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  167. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  168. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  169. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  170. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  171. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  172. #endif
  173. /* Unlock EMAC, 3 0 2 1 sequence */
  174. #define MP_MAC_KEY0 0x5969cb2a
  175. #define MP_MAC_KEY1 0xb4a1872e
  176. #define MP_MAC_KEY2 0x05683fbc
  177. #define MP_MAC_KEY3 0x3634fba4
  178. #define UNLOCK_MAC 0x00000008
  179. writel(MP_MAC_KEY3, MP_BLOCK_3_BASE + 0x3c);
  180. writel(MP_MAC_KEY0, MP_BLOCK_3_BASE + 0x30);
  181. writel(MP_MAC_KEY2, MP_BLOCK_3_BASE + 0x38);
  182. writel(MP_MAC_KEY1, MP_BLOCK_3_BASE + 0x34);
  183. writel(UNLOCK_MAC, MP_BLOCK_3_BASE + 0x40);
  184. }
  185. #endif
  186. #ifdef CONFIG_USB_OHCI_NEW
  187. static void at91cap9_uhp_hw_init(void)
  188. {
  189. /* Unlock USB OHCI, 3 2 0 1 sequence */
  190. #define MP_OHCI_KEY0 0x896c11ca
  191. #define MP_OHCI_KEY1 0x68ebca21
  192. #define MP_OHCI_KEY2 0x4823efbc
  193. #define MP_OHCI_KEY3 0x8651aae4
  194. #define UNLOCK_OHCI 0x00000010
  195. writel(MP_OHCI_KEY3, MP_BLOCK_3_BASE + 0x3c);
  196. writel(MP_OHCI_KEY2, MP_BLOCK_3_BASE + 0x38);
  197. writel(MP_OHCI_KEY0, MP_BLOCK_3_BASE + 0x30);
  198. writel(MP_OHCI_KEY1, MP_BLOCK_3_BASE + 0x34);
  199. writel(UNLOCK_OHCI, MP_BLOCK_3_BASE + 0x40);
  200. }
  201. #endif
  202. int board_init(void)
  203. {
  204. /* Enable Ctrlc */
  205. console_init_f();
  206. /* arch number of AT91CAP9ADK-Board */
  207. gd->bd->bi_arch_number = MACH_TYPE_AT91CAP9ADK;
  208. /* adress of boot parameters */
  209. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  210. at91cap9_serial_hw_init();
  211. at91cap9_nor_hw_init();
  212. #ifdef CONFIG_CMD_NAND
  213. at91cap9_nand_hw_init();
  214. #endif
  215. #ifdef CONFIG_HAS_DATAFLASH
  216. at91cap9_spi_hw_init();
  217. #endif
  218. #ifdef CONFIG_MACB
  219. at91cap9_macb_hw_init();
  220. #endif
  221. #ifdef CONFIG_USB_OHCI_NEW
  222. at91cap9_uhp_hw_init();
  223. #endif
  224. return 0;
  225. }
  226. int dram_init(void)
  227. {
  228. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  229. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  230. return 0;
  231. }
  232. #ifdef CONFIG_RESET_PHY_R
  233. void reset_phy(void)
  234. {
  235. #ifdef CONFIG_MACB
  236. /*
  237. * Initialize ethernet HW addr prior to starting Linux,
  238. * needed for nfsroot
  239. */
  240. eth_init(gd->bd);
  241. #endif
  242. }
  243. #endif