pm9263.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
  6. * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/sizes.h>
  28. #include <asm/arch/at91sam9263.h>
  29. #include <asm/arch/at91sam9_smc.h>
  30. #include <asm/arch/at91_common.h>
  31. #include <asm/arch/at91_pmc.h>
  32. #include <asm/arch/at91_rstc.h>
  33. #include <asm/arch/at91_matrix.h>
  34. #include <asm/arch/at91_pio.h>
  35. #include <asm/arch/clk.h>
  36. #include <asm/arch/io.h>
  37. #include <asm/arch/hardware.h>
  38. #include <lcd.h>
  39. #include <atmel_lcdc.h>
  40. #include <dataflash.h>
  41. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  42. #include <net.h>
  43. #endif
  44. #include <netdev.h>
  45. DECLARE_GLOBAL_DATA_PTR;
  46. /* ------------------------------------------------------------------------- */
  47. /*
  48. * Miscelaneous platform dependent initialisations
  49. */
  50. #ifdef CONFIG_CMD_NAND
  51. static void pm9263_nand_hw_init(void)
  52. {
  53. unsigned long csa;
  54. at91_smc_t *smc = (at91_smc_t *) AT91_SMC0_BASE;
  55. at91_matrix_t *matrix = (at91_matrix_t *) AT91_MATRIX_BASE;
  56. /* Enable CS3 */
  57. csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
  58. writel(csa, &matrix->csa[0]);
  59. /* Configure SMC CS3 for NAND/SmartMedia */
  60. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  61. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
  62. &smc->cs[3].setup);
  63. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  64. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  65. &smc->cs[3].pulse);
  66. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  67. &smc->cs[3].cycle);
  68. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  69. AT91_SMC_MODE_EXNW_DISABLE |
  70. #ifdef CONFIG_SYS_NAND_DBW_16
  71. AT91_SMC_MODE_DBW_16 |
  72. #else /* CONFIG_SYS_NAND_DBW_8 */
  73. AT91_SMC_MODE_DBW_8 |
  74. #endif
  75. AT91_SMC_MODE_TDF_CYCLE(2),
  76. &smc->cs[3].mode);
  77. /* Configure RDY/BSY */
  78. at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  79. /* Enable NandFlash */
  80. at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  81. }
  82. #endif
  83. #ifdef CONFIG_MACB
  84. static void pm9263_macb_hw_init(void)
  85. {
  86. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  87. /*
  88. * PB27 enables the 50MHz oscillator for Ethernet PHY
  89. * 1 - enable
  90. * 0 - disable
  91. */
  92. at91_set_pio_output(AT91_PIO_PORTB, 27, 1);
  93. at91_set_pio_value(AT91_PIO_PORTB, 27, 1); /* 1- enable, 0 - disable */
  94. /* Enable clock */
  95. writel(1 << AT91SAM9263_ID_EMAC, &pmc->pcer);
  96. /*
  97. * Disable pull-up on:
  98. * RXDV (PC25) => PHY normal mode (not Test mode)
  99. * ERX0 (PE25) => PHY ADDR0
  100. * ERX1 (PE26) => PHY ADDR1 => PHYADDR = 0x0
  101. *
  102. * PHY has internal pull-down
  103. */
  104. at91_set_pio_pullup(AT91_PIO_PORTC, 25, 0);
  105. at91_set_pio_pullup(AT91_PIO_PORTE, 25, 0);
  106. at91_set_pio_pullup(AT91_PIO_PORTE, 26, 0);
  107. /* Re-enable pull-up */
  108. at91_set_pio_pullup(AT91_PIO_PORTC, 25, 1);
  109. at91_set_pio_pullup(AT91_PIO_PORTE, 25, 1);
  110. at91_set_pio_pullup(AT91_PIO_PORTE, 26, 1);
  111. at91_macb_hw_init();
  112. }
  113. #endif
  114. #ifdef CONFIG_LCD
  115. vidinfo_t panel_info = {
  116. vl_col: 240,
  117. vl_row: 320,
  118. vl_clk: 4965000,
  119. vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
  120. ATMEL_LCDC_INVFRAME_INVERTED,
  121. vl_bpix: 3,
  122. vl_tft: 1,
  123. vl_hsync_len: 5,
  124. vl_left_margin: 1,
  125. vl_right_margin:33,
  126. vl_vsync_len: 1,
  127. vl_upper_margin:1,
  128. vl_lower_margin:0,
  129. mmio: AT91SAM9263_LCDC_BASE,
  130. };
  131. void lcd_enable(void)
  132. {
  133. at91_set_pio_value(AT91_PIO_PORTA, 22, 1); /* power up */
  134. }
  135. void lcd_disable(void)
  136. {
  137. at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power down */
  138. }
  139. #ifdef CONFIG_LCD_IN_PSRAM
  140. #define PSRAM_CRE_PIN AT91_PIO_PORTB, 29
  141. #define PSRAM_CTRL_REG (PHYS_PSRAM + PHYS_PSRAM_SIZE - 2)
  142. /* Initialize the PSRAM memory */
  143. static int pm9263_lcd_hw_psram_init(void)
  144. {
  145. volatile uint16_t x;
  146. unsigned long csa;
  147. at91_smc_t *smc = (at91_smc_t *) AT91_SMC1_BASE;
  148. at91_matrix_t *matrix = (at91_matrix_t *) AT91_MATRIX_BASE;
  149. /* Enable CS3 3.3v, no pull-ups */
  150. csa = readl(&matrix->csa[1]) | AT91_MATRIX_CSA_DBPUC |
  151. AT91_MATRIX_CSA_VDDIOMSEL_3_3V;
  152. writel(csa, &matrix->csa[1]);
  153. /* Configure SMC1 CS0 for PSRAM - 16-bit */
  154. writel(AT91_SMC_SETUP_NWE(0) | AT91_SMC_SETUP_NCS_WR(0) |
  155. AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(0),
  156. &smc->cs[0].setup);
  157. writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) |
  158. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(7),
  159. &smc->cs[0].pulse);
  160. writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
  161. &smc->cs[0].cycle);
  162. writel(AT91_SMC_MODE_DBW_16 | AT91_SMC_MODE_PMEN | AT91_SMC_MODE_PS_32,
  163. &smc->cs[0].mode);
  164. /* setup PB29 as output */
  165. at91_set_pio_output(PSRAM_CRE_PIN, 1);
  166. at91_set_pio_value(PSRAM_CRE_PIN, 0); /* set PSRAM_CRE_PIN to '0' */
  167. /* PSRAM: write BCR */
  168. x = readw(PSRAM_CTRL_REG);
  169. x = readw(PSRAM_CTRL_REG);
  170. writew(1, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  171. writew(0x9d4f, PSRAM_CTRL_REG); /* write the BCR */
  172. /* write RCR of the PSRAM */
  173. x = readw(PSRAM_CTRL_REG);
  174. x = readw(PSRAM_CTRL_REG);
  175. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  176. /* set RCR; 0x10-async mode,0x90-page mode */
  177. writew(0x90, PSRAM_CTRL_REG);
  178. /*
  179. * test to see if the PSRAM is MT45W2M16A or MT45W2M16B
  180. * MT45W2M16B - CRE must be 0
  181. * MT45W2M16A - CRE must be 1
  182. */
  183. writew(0x1234, PHYS_PSRAM);
  184. writew(0x5678, PHYS_PSRAM + 2);
  185. /* test if the chip is MT45W2M16B */
  186. if ((readw(PHYS_PSRAM) != 0x1234) || (readw(PHYS_PSRAM+2) != 0x5678)) {
  187. /* try with CRE=1 (MT45W2M16A) */
  188. at91_set_pio_value(PSRAM_CRE_PIN, 1); /* set PSRAM_CRE_PIN to '1' */
  189. /* write RCR of the PSRAM */
  190. x = readw(PSRAM_CTRL_REG);
  191. x = readw(PSRAM_CTRL_REG);
  192. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  193. /* set RCR;0x10-async mode,0x90-page mode */
  194. writew(0x90, PSRAM_CTRL_REG);
  195. writew(0x1234, PHYS_PSRAM);
  196. writew(0x5678, PHYS_PSRAM+2);
  197. if ((readw(PHYS_PSRAM) != 0x1234)
  198. || (readw(PHYS_PSRAM + 2) != 0x5678))
  199. return 1;
  200. }
  201. /* Bus matrix */
  202. writel(AT91_MATRIX_PRA_M5(3), &matrix->pr[5].a);
  203. writel(CONFIG_PSRAM_SCFG, &matrix->scfg[5]);
  204. return 0;
  205. }
  206. #endif
  207. static void pm9263_lcd_hw_init(void)
  208. {
  209. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  210. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDVSYNC */
  211. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
  212. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
  213. at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
  214. at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
  215. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
  216. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
  217. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
  218. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
  219. at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
  220. at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
  221. at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
  222. at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
  223. at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
  224. at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
  225. at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
  226. at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
  227. at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
  228. at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
  229. at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
  230. at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
  231. at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
  232. at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
  233. writel(1 << AT91SAM9263_ID_LCDC, &pmc->pcer);
  234. /* Power Control */
  235. at91_set_pio_output(AT91_PIO_PORTA, 22, 1);
  236. at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power down */
  237. #ifdef CONFIG_LCD_IN_PSRAM
  238. /* initialize te PSRAM */
  239. int stat = pm9263_lcd_hw_psram_init();
  240. gd->fb_base = (stat == 0) ? PHYS_PSRAM : AT91SAM9263_SRAM0_BASE;
  241. #else
  242. gd->fb_base = AT91SAM9263_SRAM0_BASE;
  243. #endif
  244. }
  245. #ifdef CONFIG_LCD_INFO
  246. #include <nand.h>
  247. #include <version.h>
  248. extern flash_info_t flash_info[];
  249. void lcd_show_board_info(void)
  250. {
  251. ulong dram_size, nand_size, flash_size, dataflash_size;
  252. int i;
  253. char temp[32];
  254. lcd_printf ("%s\n", U_BOOT_VERSION);
  255. lcd_printf ("(C) 2009 Ronetix GmbH\n");
  256. lcd_printf ("support@ronetix.at\n");
  257. lcd_printf ("%s CPU at %s MHz",
  258. CONFIG_SYS_AT91_CPU_NAME,
  259. strmhz(temp, get_cpu_clk_rate()));
  260. dram_size = 0;
  261. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  262. dram_size += gd->bd->bi_dram[i].size;
  263. nand_size = 0;
  264. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  265. nand_size += nand_info[i].size;
  266. flash_size = 0;
  267. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
  268. flash_size += flash_info[i].size;
  269. dataflash_size = 0;
  270. for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
  271. dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
  272. dataflash_info[i].Device.pages_size;
  273. lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
  274. "4 MB PSRAM, %ld MB DataFlash\n",
  275. dram_size >> 20,
  276. nand_size >> 20,
  277. flash_size >> 20,
  278. dataflash_size >> 20);
  279. }
  280. #endif /* CONFIG_LCD_INFO */
  281. #endif /* CONFIG_LCD */
  282. int board_init(void)
  283. {
  284. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  285. /* Enable Ctrlc */
  286. console_init_f();
  287. writel((1 << AT91SAM9263_ID_PIOA) |
  288. (1 << AT91SAM9263_ID_PIOCDE) |
  289. (1 << AT91SAM9263_ID_PIOB),
  290. &pmc->pcer);
  291. /* arch number of AT91SAM9263EK-Board */
  292. gd->bd->bi_arch_number = MACH_TYPE_PM9263;
  293. /* adress of boot parameters */
  294. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  295. at91_serial_hw_init();
  296. #ifdef CONFIG_CMD_NAND
  297. pm9263_nand_hw_init();
  298. #endif
  299. #ifdef CONFIG_HAS_DATAFLASH
  300. at91_spi0_hw_init(1 << 0);
  301. #endif
  302. #ifdef CONFIG_MACB
  303. pm9263_macb_hw_init();
  304. #endif
  305. #ifdef CONFIG_USB_OHCI_NEW
  306. at91_uhp_hw_init();
  307. #endif
  308. #ifdef CONFIG_LCD
  309. pm9263_lcd_hw_init();
  310. #endif
  311. return 0;
  312. }
  313. int dram_init(void)
  314. {
  315. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  316. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  317. return 0;
  318. }
  319. #ifdef CONFIG_RESET_PHY_R
  320. void reset_phy(void)
  321. {
  322. }
  323. #endif
  324. int board_eth_init(bd_t *bis)
  325. {
  326. int rc = 0;
  327. #ifdef CONFIG_MACB
  328. rc = macb_eth_initialize(0, (void *)AT91_EMAC_BASE, 0x01);
  329. #endif
  330. return rc;
  331. }
  332. #ifdef CONFIG_DISPLAY_BOARDINFO
  333. int checkboard (void)
  334. {
  335. char *ss;
  336. printf ("Board : Ronetix PM9263\n");
  337. switch (gd->fb_base) {
  338. case PHYS_PSRAM:
  339. ss = "(PSRAM)";
  340. break;
  341. case AT91SAM9263_SRAM0_BASE:
  342. ss = "(Internal SRAM)";
  343. break;
  344. default:
  345. ss = "";
  346. break;
  347. }
  348. printf("Video memory : 0x%08lX %s\n", gd->fb_base, ss );
  349. printf ("\n");
  350. return 0;
  351. }
  352. #endif