at91cap9adk.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 <asm/arch/hardware.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. #define MP_BLOCK_3_BASE 0xFDF00000
  40. DECLARE_GLOBAL_DATA_PTR;
  41. /* ------------------------------------------------------------------------- */
  42. /*
  43. * Miscelaneous platform dependent initialisations
  44. */
  45. static void at91cap9_serial_hw_init(void)
  46. {
  47. #ifdef CONFIG_USART0
  48. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  49. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  50. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
  51. #endif
  52. #ifdef CONFIG_USART1
  53. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  54. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  55. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US1);
  56. #endif
  57. #ifdef CONFIG_USART2
  58. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  59. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  60. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US2);
  61. #endif
  62. #ifdef CONFIG_USART3 /* DBGU */
  63. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  64. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  65. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  66. #endif
  67. }
  68. static void at91cap9_slowclock_hw_init(void)
  69. {
  70. /*
  71. * On AT91CAP9 revC CPUs, the slow clock can be based on an
  72. * internal impreciseRC oscillator or an external 32kHz oscillator.
  73. * Switch to the latter.
  74. */
  75. #define ARCH_ID_AT91CAP9_REVB 0x399
  76. #define ARCH_ID_AT91CAP9_REVC 0x601
  77. if (at91_sys_read(AT91_PMC_VER) == ARCH_ID_AT91CAP9_REVC) {
  78. unsigned i, tmp = at91_sys_read(AT91_SCKCR);
  79. if ((tmp & AT91CAP9_SCKCR_OSCSEL) == AT91CAP9_SCKCR_OSCSEL_RC) {
  80. extern void timer_init(void);
  81. timer_init();
  82. tmp |= AT91CAP9_SCKCR_OSC32EN;
  83. at91_sys_write(AT91_SCKCR, tmp);
  84. for (i = 0; i < 1200; i++)
  85. udelay(1000);
  86. tmp |= AT91CAP9_SCKCR_OSCSEL_32;
  87. at91_sys_write(AT91_SCKCR, tmp);
  88. udelay(200);
  89. tmp &= ~AT91CAP9_SCKCR_RCEN;
  90. at91_sys_write(AT91_SCKCR, tmp);
  91. }
  92. }
  93. }
  94. static void at91cap9_nor_hw_init(void)
  95. {
  96. unsigned long csa;
  97. /* Ensure EBI supply is 3.3V */
  98. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  99. at91_sys_write(AT91_MATRIX_EBICSA,
  100. csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  101. /* Configure SMC CS0 for parallel flash */
  102. at91_sys_write(AT91_SMC_SETUP(0),
  103. AT91_SMC_NWESETUP_(4) | AT91_SMC_NCS_WRSETUP_(2) |
  104. AT91_SMC_NRDSETUP_(4) | AT91_SMC_NCS_RDSETUP_(2));
  105. at91_sys_write(AT91_SMC_PULSE(0),
  106. AT91_SMC_NWEPULSE_(8) | AT91_SMC_NCS_WRPULSE_(10) |
  107. AT91_SMC_NRDPULSE_(8) | AT91_SMC_NCS_RDPULSE_(10));
  108. at91_sys_write(AT91_SMC_CYCLE(0),
  109. AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  110. at91_sys_write(AT91_SMC_MODE(0),
  111. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  112. AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE |
  113. AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
  114. }
  115. #ifdef CONFIG_CMD_NAND
  116. static void at91cap9_nand_hw_init(void)
  117. {
  118. unsigned long csa;
  119. /* Enable CS3 */
  120. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  121. at91_sys_write(AT91_MATRIX_EBICSA,
  122. csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA |
  123. AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  124. /* Configure SMC CS3 for NAND/SmartMedia */
  125. at91_sys_write(AT91_SMC_SETUP(3),
  126. AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1) |
  127. AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  128. at91_sys_write(AT91_SMC_PULSE(3),
  129. AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6) |
  130. AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  131. at91_sys_write(AT91_SMC_CYCLE(3),
  132. AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  133. at91_sys_write(AT91_SMC_MODE(3),
  134. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  135. AT91_SMC_EXNWMODE_DISABLE |
  136. #ifdef CONFIG_SYS_NAND_DBW_16
  137. AT91_SMC_DBW_16 |
  138. #else /* CONFIG_SYS_NAND_DBW_8 */
  139. AT91_SMC_DBW_8 |
  140. #endif
  141. AT91_SMC_TDF_(1));
  142. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD);
  143. /* RDY/BSY is not connected */
  144. /* Enable NandFlash */
  145. at91_set_gpio_output(AT91_PIN_PD15, 1);
  146. }
  147. #endif
  148. #ifdef CONFIG_HAS_DATAFLASH
  149. static void at91cap9_spi_hw_init(void)
  150. {
  151. at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
  152. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  153. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  154. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  155. /* Enable clock */
  156. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
  157. }
  158. #endif
  159. #ifdef CONFIG_MACB
  160. static void at91cap9_macb_hw_init(void)
  161. {
  162. /* Enable clock */
  163. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC);
  164. /*
  165. * Disable pull-up on:
  166. * RXDV (PB22) => PHY normal mode (not Test mode)
  167. * ERX0 (PB25) => PHY ADDR0
  168. * ERX1 (PB26) => PHY ADDR1 => PHYADDR = 0x0
  169. *
  170. * PHY has internal pull-down
  171. */
  172. writel(pin_to_mask(AT91_PIN_PB22) |
  173. pin_to_mask(AT91_PIN_PB25) |
  174. pin_to_mask(AT91_PIN_PB26),
  175. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  176. /* Need to reset PHY -> 500ms reset */
  177. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  178. (AT91_RSTC_ERSTL & (0x0D << 8)) |
  179. AT91_RSTC_URSTEN);
  180. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  181. /* Wait for end hardware reset */
  182. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
  183. /* Restore NRST value */
  184. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  185. (AT91_RSTC_ERSTL & (0x0 << 8)) |
  186. AT91_RSTC_URSTEN);
  187. /* Re-enable pull-up */
  188. writel(pin_to_mask(AT91_PIN_PB22) |
  189. pin_to_mask(AT91_PIN_PB25) |
  190. pin_to_mask(AT91_PIN_PB26),
  191. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  192. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  193. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  194. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  195. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  196. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  197. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  198. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  199. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  200. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  201. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  202. #ifndef CONFIG_RMII
  203. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  204. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  205. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  206. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  207. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  208. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  209. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  210. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  211. #endif
  212. /* Unlock EMAC, 3 0 2 1 sequence */
  213. #define MP_MAC_KEY0 0x5969cb2a
  214. #define MP_MAC_KEY1 0xb4a1872e
  215. #define MP_MAC_KEY2 0x05683fbc
  216. #define MP_MAC_KEY3 0x3634fba4
  217. #define UNLOCK_MAC 0x00000008
  218. writel(MP_MAC_KEY3, MP_BLOCK_3_BASE + 0x3c);
  219. writel(MP_MAC_KEY0, MP_BLOCK_3_BASE + 0x30);
  220. writel(MP_MAC_KEY2, MP_BLOCK_3_BASE + 0x38);
  221. writel(MP_MAC_KEY1, MP_BLOCK_3_BASE + 0x34);
  222. writel(UNLOCK_MAC, MP_BLOCK_3_BASE + 0x40);
  223. }
  224. #endif
  225. #ifdef CONFIG_USB_OHCI_NEW
  226. static void at91cap9_uhp_hw_init(void)
  227. {
  228. /* Unlock USB OHCI, 3 2 0 1 sequence */
  229. #define MP_OHCI_KEY0 0x896c11ca
  230. #define MP_OHCI_KEY1 0x68ebca21
  231. #define MP_OHCI_KEY2 0x4823efbc
  232. #define MP_OHCI_KEY3 0x8651aae4
  233. #define UNLOCK_OHCI 0x00000010
  234. writel(MP_OHCI_KEY3, MP_BLOCK_3_BASE + 0x3c);
  235. writel(MP_OHCI_KEY2, MP_BLOCK_3_BASE + 0x38);
  236. writel(MP_OHCI_KEY0, MP_BLOCK_3_BASE + 0x30);
  237. writel(MP_OHCI_KEY1, MP_BLOCK_3_BASE + 0x34);
  238. writel(UNLOCK_OHCI, MP_BLOCK_3_BASE + 0x40);
  239. }
  240. #endif
  241. #ifdef CONFIG_LCD
  242. vidinfo_t panel_info = {
  243. vl_col: 240,
  244. vl_row: 320,
  245. vl_clk: 4965000,
  246. vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
  247. ATMEL_LCDC_INVFRAME_INVERTED,
  248. vl_bpix: 3,
  249. vl_tft: 1,
  250. vl_hsync_len: 5,
  251. vl_left_margin: 1,
  252. vl_right_margin:33,
  253. vl_vsync_len: 1,
  254. vl_upper_margin:1,
  255. vl_lower_margin:0,
  256. mmio: AT91CAP9_LCDC_BASE,
  257. };
  258. void lcd_enable(void)
  259. {
  260. at91_set_gpio_value(AT91_PIN_PC0, 0); /* power up */
  261. }
  262. void lcd_disable(void)
  263. {
  264. at91_set_gpio_value(AT91_PIN_PC0, 1); /* power down */
  265. }
  266. static void at91cap9_lcd_hw_init(void)
  267. {
  268. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  269. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  270. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  271. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  272. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  273. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  274. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  275. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  276. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  277. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  278. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  279. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  280. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  281. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  282. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  283. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  284. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  285. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  286. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  287. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  288. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  289. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  290. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_LCDC);
  291. gd->fb_base = 0;
  292. }
  293. #ifdef CONFIG_LCD_INFO
  294. #include <nand.h>
  295. #include <version.h>
  296. void lcd_show_board_info(void)
  297. {
  298. ulong dram_size, nand_size;
  299. int i;
  300. char temp[32];
  301. lcd_printf ("%s\n", U_BOOT_VERSION);
  302. lcd_printf ("(C) 2008 ATMEL Corp\n");
  303. lcd_printf ("at91support@atmel.com\n");
  304. lcd_printf ("%s CPU at %s MHz\n",
  305. AT91_CPU_NAME,
  306. strmhz(temp, AT91_MAIN_CLOCK));
  307. dram_size = 0;
  308. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  309. dram_size += gd->bd->bi_dram[i].size;
  310. nand_size = 0;
  311. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  312. nand_size += nand_info[i].size;
  313. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  314. dram_size >> 20,
  315. nand_size >> 20 );
  316. }
  317. #endif /* CONFIG_LCD_INFO */
  318. #endif
  319. int board_init(void)
  320. {
  321. /* Enable Ctrlc */
  322. console_init_f();
  323. /* arch number of AT91CAP9ADK-Board */
  324. gd->bd->bi_arch_number = MACH_TYPE_AT91CAP9ADK;
  325. /* adress of boot parameters */
  326. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  327. at91cap9_serial_hw_init();
  328. at91cap9_slowclock_hw_init();
  329. at91cap9_nor_hw_init();
  330. #ifdef CONFIG_CMD_NAND
  331. at91cap9_nand_hw_init();
  332. #endif
  333. #ifdef CONFIG_HAS_DATAFLASH
  334. at91cap9_spi_hw_init();
  335. #endif
  336. #ifdef CONFIG_MACB
  337. at91cap9_macb_hw_init();
  338. #endif
  339. #ifdef CONFIG_USB_OHCI_NEW
  340. at91cap9_uhp_hw_init();
  341. #endif
  342. #ifdef CONFIG_LCD
  343. at91cap9_lcd_hw_init();
  344. #endif
  345. return 0;
  346. }
  347. int dram_init(void)
  348. {
  349. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  350. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  351. return 0;
  352. }
  353. #ifdef CONFIG_RESET_PHY_R
  354. void reset_phy(void)
  355. {
  356. #ifdef CONFIG_MACB
  357. /*
  358. * Initialize ethernet HW addr prior to starting Linux,
  359. * needed for nfsroot
  360. */
  361. eth_init(gd->bd);
  362. #endif
  363. }
  364. #endif
  365. int board_eth_init(bd_t *bis)
  366. {
  367. int rc = 0;
  368. #ifdef CONFIG_MACB
  369. rc = macb_eth_initialize(0, (void *)AT91CAP9_BASE_EMAC, 0x00);
  370. #endif
  371. return rc;
  372. }