at91cap9adk.c 11 KB

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