pm9263.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  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. unsigned long csa;
  144. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC1;
  145. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  146. /* Enable CS3 3.3v, no pull-ups */
  147. csa = readl(&matrix->csa[1]) | AT91_MATRIX_CSA_DBPUC |
  148. AT91_MATRIX_CSA_VDDIOMSEL_3_3V;
  149. writel(csa, &matrix->csa[1]);
  150. /* Configure SMC1 CS0 for PSRAM - 16-bit */
  151. writel(AT91_SMC_SETUP_NWE(0) | AT91_SMC_SETUP_NCS_WR(0) |
  152. AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(0),
  153. &smc->cs[0].setup);
  154. writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) |
  155. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(7),
  156. &smc->cs[0].pulse);
  157. writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
  158. &smc->cs[0].cycle);
  159. writel(AT91_SMC_MODE_DBW_16 | AT91_SMC_MODE_PMEN | AT91_SMC_MODE_PS_32,
  160. &smc->cs[0].mode);
  161. /* setup PB29 as output */
  162. at91_set_pio_output(PSRAM_CRE_PIN, 1);
  163. at91_set_pio_value(PSRAM_CRE_PIN, 0); /* set PSRAM_CRE_PIN to '0' */
  164. /* PSRAM: write BCR */
  165. readw(PSRAM_CTRL_REG);
  166. readw(PSRAM_CTRL_REG);
  167. writew(1, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  168. writew(0x9d4f, PSRAM_CTRL_REG); /* write the BCR */
  169. /* write RCR of the PSRAM */
  170. readw(PSRAM_CTRL_REG);
  171. readw(PSRAM_CTRL_REG);
  172. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  173. /* set RCR; 0x10-async mode,0x90-page mode */
  174. writew(0x90, PSRAM_CTRL_REG);
  175. /*
  176. * test to see if the PSRAM is MT45W2M16A or MT45W2M16B
  177. * MT45W2M16B - CRE must be 0
  178. * MT45W2M16A - CRE must be 1
  179. */
  180. writew(0x1234, PHYS_PSRAM);
  181. writew(0x5678, PHYS_PSRAM + 2);
  182. /* test if the chip is MT45W2M16B */
  183. if ((readw(PHYS_PSRAM) != 0x1234) || (readw(PHYS_PSRAM+2) != 0x5678)) {
  184. /* try with CRE=1 (MT45W2M16A) */
  185. at91_set_pio_value(PSRAM_CRE_PIN, 1); /* set PSRAM_CRE_PIN to '1' */
  186. /* write RCR of the PSRAM */
  187. readw(PSRAM_CTRL_REG);
  188. readw(PSRAM_CTRL_REG);
  189. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  190. /* set RCR;0x10-async mode,0x90-page mode */
  191. writew(0x90, PSRAM_CTRL_REG);
  192. writew(0x1234, PHYS_PSRAM);
  193. writew(0x5678, PHYS_PSRAM+2);
  194. if ((readw(PHYS_PSRAM) != 0x1234)
  195. || (readw(PHYS_PSRAM + 2) != 0x5678))
  196. return 1;
  197. }
  198. /* Bus matrix */
  199. writel(AT91_MATRIX_PRA_M5(3), &matrix->pr[5].a);
  200. writel(CONFIG_PSRAM_SCFG, &matrix->scfg[5]);
  201. return 0;
  202. }
  203. #endif
  204. static void pm9263_lcd_hw_init(void)
  205. {
  206. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  207. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDVSYNC */
  208. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
  209. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
  210. at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
  211. at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
  212. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
  213. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
  214. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
  215. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
  216. at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
  217. at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
  218. at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
  219. at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
  220. at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
  221. at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
  222. at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
  223. at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
  224. at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
  225. at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
  226. at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
  227. at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
  228. at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
  229. at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
  230. writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
  231. /* Power Control */
  232. at91_set_pio_output(AT91_PIO_PORTA, 22, 1);
  233. at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power down */
  234. #ifdef CONFIG_LCD_IN_PSRAM
  235. /* initialize te PSRAM */
  236. int stat = pm9263_lcd_hw_psram_init();
  237. gd->fb_base = (stat == 0) ? PHYS_PSRAM : ATMEL_BASE_SRAM0;
  238. #else
  239. gd->fb_base = ATMEL_BASE_SRAM0;
  240. #endif
  241. }
  242. #ifdef CONFIG_LCD_INFO
  243. #include <nand.h>
  244. #include <version.h>
  245. extern flash_info_t flash_info[];
  246. void lcd_show_board_info(void)
  247. {
  248. ulong dram_size, nand_size, flash_size, dataflash_size;
  249. int i;
  250. char temp[32];
  251. lcd_printf ("%s\n", U_BOOT_VERSION);
  252. lcd_printf ("(C) 2009 Ronetix GmbH\n");
  253. lcd_printf ("support@ronetix.at\n");
  254. lcd_printf ("%s CPU at %s MHz",
  255. CONFIG_SYS_AT91_CPU_NAME,
  256. strmhz(temp, get_cpu_clk_rate()));
  257. dram_size = 0;
  258. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  259. dram_size += gd->bd->bi_dram[i].size;
  260. nand_size = 0;
  261. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  262. nand_size += nand_info[i].size;
  263. flash_size = 0;
  264. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
  265. flash_size += flash_info[i].size;
  266. dataflash_size = 0;
  267. for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
  268. dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
  269. dataflash_info[i].Device.pages_size;
  270. lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
  271. "4 MB PSRAM, %ld MB DataFlash\n",
  272. dram_size >> 20,
  273. nand_size >> 20,
  274. flash_size >> 20,
  275. dataflash_size >> 20);
  276. }
  277. #endif /* CONFIG_LCD_INFO */
  278. #endif /* CONFIG_LCD */
  279. int board_init(void)
  280. {
  281. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  282. /* Enable Ctrlc */
  283. console_init_f();
  284. writel((1 << ATMEL_ID_PIOA) |
  285. (1 << ATMEL_ID_PIOCDE) |
  286. (1 << ATMEL_ID_PIOB),
  287. &pmc->pcer);
  288. /* adress of boot parameters */
  289. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  290. at91_seriald_hw_init();
  291. #ifdef CONFIG_CMD_NAND
  292. pm9263_nand_hw_init();
  293. #endif
  294. #ifdef CONFIG_HAS_DATAFLASH
  295. at91_spi0_hw_init(1 << 0);
  296. #endif
  297. #ifdef CONFIG_MACB
  298. pm9263_macb_hw_init();
  299. #endif
  300. #ifdef CONFIG_USB_OHCI_NEW
  301. at91_uhp_hw_init();
  302. #endif
  303. #ifdef CONFIG_LCD
  304. pm9263_lcd_hw_init();
  305. #endif
  306. return 0;
  307. }
  308. int dram_init(void)
  309. {
  310. /* dram_init must store complete ramsize in gd->ram_size */
  311. gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
  312. PHYS_SDRAM_SIZE);
  313. return 0;
  314. }
  315. void dram_init_banksize(void)
  316. {
  317. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  318. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  319. }
  320. #ifdef CONFIG_RESET_PHY_R
  321. void reset_phy(void)
  322. {
  323. }
  324. #endif
  325. int board_eth_init(bd_t *bis)
  326. {
  327. int rc = 0;
  328. #ifdef CONFIG_MACB
  329. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x01);
  330. #endif
  331. return rc;
  332. }
  333. #ifdef CONFIG_DISPLAY_BOARDINFO
  334. int checkboard (void)
  335. {
  336. char *ss;
  337. printf ("Board : Ronetix PM9263\n");
  338. switch (gd->fb_base) {
  339. case PHYS_PSRAM:
  340. ss = "(PSRAM)";
  341. break;
  342. case ATMEL_BASE_SRAM0:
  343. ss = "(Internal SRAM)";
  344. break;
  345. default:
  346. ss = "";
  347. break;
  348. }
  349. printf("Video memory : 0x%08lX %s\n", gd->fb_base, ss );
  350. printf ("\n");
  351. return 0;
  352. }
  353. #endif