at91cap9adk.c 9.8 KB

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