pm9263.c 11 KB

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