pm9263.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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/at91sam9263_matrix.h>
  30. #include <asm/arch/at91sam9_smc.h>
  31. #include <asm/arch/at91_common.h>
  32. #include <asm/arch/at91_pmc.h>
  33. #include <asm/arch/at91_rstc.h>
  34. #include <asm/arch/clk.h>
  35. #include <asm/arch/gpio.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. /* Enable CS3 */
  55. csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
  56. at91_sys_write(AT91_MATRIX_EBI0CSA,
  57. csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
  58. /* Configure SMC CS3 for NAND/SmartMedia */
  59. at91_sys_write(AT91_SMC_SETUP(3),
  60. AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(1) |
  61. AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(1));
  62. at91_sys_write(AT91_SMC_PULSE(3),
  63. AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
  64. AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  65. at91_sys_write(AT91_SMC_CYCLE(3),
  66. AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  67. at91_sys_write(AT91_SMC_MODE(3),
  68. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  69. AT91_SMC_EXNWMODE_DISABLE |
  70. #ifdef CONFIG_SYS_NAND_DBW_16
  71. AT91_SMC_DBW_16 |
  72. #else /* CONFIG_SYS_NAND_DBW_8 */
  73. AT91_SMC_DBW_8 |
  74. #endif
  75. AT91_SMC_TDF_(2));
  76. /* Configure RDY/BSY */
  77. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  78. /* Enable NandFlash */
  79. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  80. }
  81. #endif
  82. #ifdef CONFIG_MACB
  83. static void pm9263_macb_hw_init(void)
  84. {
  85. /*
  86. * PB27 enables the 50MHz oscillator for Ethernet PHY
  87. * 1 - enable
  88. * 0 - disable
  89. */
  90. at91_set_gpio_output(AT91_PIN_PB27, 1);
  91. at91_set_gpio_value(AT91_PIN_PB27, 1); /* 1- enable, 0 - disable */
  92. /* Enable clock */
  93. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_EMAC);
  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. writel(pin_to_mask(AT91_PIN_PC25),
  103. pin_to_controller(AT91_PIN_PC0) + PIO_PUDR);
  104. writel(pin_to_mask(AT91_PIN_PE25) |
  105. pin_to_mask(AT91_PIN_PE26),
  106. pin_to_controller(AT91_PIN_PE0) + PIO_PUDR);
  107. /* Re-enable pull-up */
  108. writel(pin_to_mask(AT91_PIN_PC25),
  109. pin_to_controller(AT91_PIN_PC0) + PIO_PUER);
  110. writel(pin_to_mask(AT91_PIN_PE25) |
  111. pin_to_mask(AT91_PIN_PE26),
  112. pin_to_controller(AT91_PIN_PE0) + PIO_PUER);
  113. at91_macb_hw_init();
  114. }
  115. #endif
  116. #ifdef CONFIG_LCD
  117. vidinfo_t panel_info = {
  118. vl_col: 240,
  119. vl_row: 320,
  120. vl_clk: 4965000,
  121. vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
  122. ATMEL_LCDC_INVFRAME_INVERTED,
  123. vl_bpix: 3,
  124. vl_tft: 1,
  125. vl_hsync_len: 5,
  126. vl_left_margin: 1,
  127. vl_right_margin:33,
  128. vl_vsync_len: 1,
  129. vl_upper_margin:1,
  130. vl_lower_margin:0,
  131. mmio: AT91SAM9263_LCDC_BASE,
  132. };
  133. void lcd_enable(void)
  134. {
  135. at91_set_gpio_value(AT91_PIN_PA22, 1); /* power up */
  136. }
  137. void lcd_disable(void)
  138. {
  139. at91_set_gpio_value(AT91_PIN_PA22, 0); /* power down */
  140. }
  141. #ifdef CONFIG_LCD_IN_PSRAM
  142. #define PSRAM_CRE_PIN AT91_PIN_PB29
  143. #define PSRAM_CTRL_REG (PHYS_PSRAM + PHYS_PSRAM_SIZE - 2)
  144. /* Initialize the PSRAM memory */
  145. static int pm9263_lcd_hw_psram_init(void)
  146. {
  147. volatile uint16_t x;
  148. unsigned long csa;
  149. /* Enable CS3 3.3v, no pull-ups */
  150. csa = at91_sys_read(AT91_MATRIX_EBI1CSA);
  151. at91_sys_write(AT91_MATRIX_EBI1CSA,
  152. csa | AT91_MATRIX_EBI1_DBPUC |
  153. AT91_MATRIX_EBI1_VDDIOMSEL_3_3V);
  154. /* Configure SMC1 CS0 for PSRAM - 16-bit */
  155. at91_sys_write(AT91_SMC1_SETUP(0),
  156. AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0) |
  157. AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  158. at91_sys_write(AT91_SMC1_PULSE(0),
  159. AT91_SMC_NWEPULSE_(7) | AT91_SMC_NCS_WRPULSE_(7) |
  160. AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(7));
  161. at91_sys_write(AT91_SMC1_CYCLE(0),
  162. AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  163. at91_sys_write(AT91_SMC1_MODE(0),
  164. AT91_SMC_DBW_16 |
  165. AT91_SMC_PMEN |
  166. AT91_SMC_PS_32);
  167. /* setup PB29 as output */
  168. at91_set_gpio_output(PSRAM_CRE_PIN, 1);
  169. at91_set_gpio_value(PSRAM_CRE_PIN, 0); /* set PSRAM_CRE_PIN to '0' */
  170. /* PSRAM: write BCR */
  171. x = readw(PSRAM_CTRL_REG);
  172. x = readw(PSRAM_CTRL_REG);
  173. writew(1, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  174. writew(0x9d4f, PSRAM_CTRL_REG); /* write the BCR */
  175. /* write RCR of the PSRAM */
  176. x = readw(PSRAM_CTRL_REG);
  177. x = readw(PSRAM_CTRL_REG);
  178. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  179. /* set RCR; 0x10-async mode,0x90-page mode */
  180. writew(0x90, PSRAM_CTRL_REG);
  181. /*
  182. * test to see if the PSRAM is MT45W2M16A or MT45W2M16B
  183. * MT45W2M16B - CRE must be 0
  184. * MT45W2M16A - CRE must be 1
  185. */
  186. writew(0x1234, PHYS_PSRAM);
  187. writew(0x5678, PHYS_PSRAM + 2);
  188. /* test if the chip is MT45W2M16B */
  189. if ((readw(PHYS_PSRAM) != 0x1234) || (readw(PHYS_PSRAM+2) != 0x5678)) {
  190. /* try with CRE=1 (MT45W2M16A) */
  191. at91_set_gpio_value(PSRAM_CRE_PIN, 1); /* set PSRAM_CRE_PIN to '1' */
  192. /* write RCR of the PSRAM */
  193. x = readw(PSRAM_CTRL_REG);
  194. x = readw(PSRAM_CTRL_REG);
  195. writew(0, PSRAM_CTRL_REG); /* 0 - RCR,1 - BCR */
  196. /* set RCR;0x10-async mode,0x90-page mode */
  197. writew(0x90, PSRAM_CTRL_REG);
  198. writew(0x1234, PHYS_PSRAM);
  199. writew(0x5678, PHYS_PSRAM+2);
  200. if ((readw(PHYS_PSRAM) != 0x1234)
  201. || (readw(PHYS_PSRAM + 2) != 0x5678))
  202. return 1;
  203. }
  204. /* Bus matrix */
  205. at91_sys_write( AT91_MATRIX_PRAS5, AT91_MATRIX_M5PR );
  206. at91_sys_write( AT91_MATRIX_SCFG5, AT91_MATRIX_ARBT_FIXED_PRIORITY |
  207. (AT91_MATRIX_FIXED_DEFMSTR & (5 << 18)) |
  208. AT91_MATRIX_DEFMSTR_TYPE_FIXED |
  209. (AT91_MATRIX_SLOT_CYCLE & (0xFF << 0)));
  210. return 0;
  211. }
  212. #endif
  213. static void pm9263_lcd_hw_init(void)
  214. {
  215. at91_set_A_periph(AT91_PIN_PC0, 0); /* LCDVSYNC */
  216. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  217. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  218. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  219. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  220. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  221. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  222. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  223. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  224. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  225. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  226. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  227. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  228. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  229. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  230. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  231. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  232. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  233. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  234. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  235. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  236. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  237. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  238. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_LCDC);
  239. /* Power Control */
  240. at91_set_gpio_output(AT91_PIN_PA22, 1);
  241. at91_set_gpio_value(AT91_PIN_PA22, 0); /* power down */
  242. #ifdef CONFIG_LCD_IN_PSRAM
  243. /* initialize te PSRAM */
  244. int stat = pm9263_lcd_hw_psram_init();
  245. gd->fb_base = (stat == 0) ? PHYS_PSRAM : AT91SAM9263_SRAM0_BASE;
  246. #else
  247. gd->fb_base = AT91SAM9263_SRAM0_BASE;
  248. #endif
  249. }
  250. #ifdef CONFIG_LCD_INFO
  251. #include <nand.h>
  252. #include <version.h>
  253. extern flash_info_t flash_info[];
  254. void lcd_show_board_info(void)
  255. {
  256. ulong dram_size, nand_size, flash_size, dataflash_size;
  257. int i;
  258. char temp[32];
  259. lcd_printf ("%s\n", U_BOOT_VERSION);
  260. lcd_printf ("(C) 2009 Ronetix GmbH\n");
  261. lcd_printf ("support@ronetix.at\n");
  262. lcd_printf ("%s CPU at %s MHz",
  263. AT91_CPU_NAME,
  264. strmhz(temp, get_cpu_clk_rate()));
  265. dram_size = 0;
  266. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  267. dram_size += gd->bd->bi_dram[i].size;
  268. nand_size = 0;
  269. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  270. nand_size += nand_info[i].size;
  271. flash_size = 0;
  272. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
  273. flash_size += flash_info[i].size;
  274. dataflash_size = 0;
  275. for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
  276. dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
  277. dataflash_info[i].Device.pages_size;
  278. lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
  279. "4 MB PSRAM, %ld MB DataFlash\n",
  280. dram_size >> 20,
  281. nand_size >> 20,
  282. flash_size >> 20,
  283. dataflash_size >> 20);
  284. }
  285. #endif /* CONFIG_LCD_INFO */
  286. #endif /* CONFIG_LCD */
  287. int board_init(void)
  288. {
  289. /* Enable Ctrlc */
  290. console_init_f();
  291. at91_sys_write(AT91_PMC_PCER,
  292. (1 << AT91SAM9263_ID_PIOA) |
  293. (1 << AT91SAM9263_ID_PIOCDE) |
  294. (1 << AT91SAM9263_ID_PIOB));
  295. /* arch number of AT91SAM9263EK-Board */
  296. gd->bd->bi_arch_number = MACH_TYPE_PM9263;
  297. /* adress of boot parameters */
  298. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  299. at91_serial_hw_init();
  300. #ifdef CONFIG_CMD_NAND
  301. pm9263_nand_hw_init();
  302. #endif
  303. #ifdef CONFIG_HAS_DATAFLASH
  304. at91_spi0_hw_init(1 << 0);
  305. #endif
  306. #ifdef CONFIG_MACB
  307. pm9263_macb_hw_init();
  308. #endif
  309. #ifdef CONFIG_USB_OHCI_NEW
  310. at91_uhp_hw_init();
  311. #endif
  312. #ifdef CONFIG_LCD
  313. pm9263_lcd_hw_init();
  314. #endif
  315. return 0;
  316. }
  317. int dram_init(void)
  318. {
  319. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  320. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  321. return 0;
  322. }
  323. #ifdef CONFIG_RESET_PHY_R
  324. void reset_phy(void)
  325. {
  326. #ifdef CONFIG_MACB
  327. /*
  328. * Initialize ethernet HW addr prior to starting Linux,
  329. * needed for nfsroot
  330. */
  331. eth_init(gd->bd);
  332. #endif
  333. }
  334. #endif
  335. int board_eth_init(bd_t *bis)
  336. {
  337. int rc = 0;
  338. #ifdef CONFIG_MACB
  339. rc = macb_eth_initialize(0, (void *)AT91SAM9263_BASE_EMAC, 0x01);
  340. #endif
  341. return rc;
  342. }
  343. #ifdef CONFIG_DISPLAY_BOARDINFO
  344. int checkboard (void)
  345. {
  346. char *ss;
  347. printf ("Board : Ronetix PM9263\n");
  348. switch (gd->fb_base) {
  349. case PHYS_PSRAM:
  350. ss = "(PSRAM)";
  351. break;
  352. case AT91SAM9263_SRAM0_BASE:
  353. ss = "(Internal SRAM)";
  354. break;
  355. default:
  356. ss = "";
  357. break;
  358. }
  359. printf("Video memory : 0x%08lX %s\n", gd->fb_base, ss );
  360. printf ("\n");
  361. return 0;
  362. }
  363. #endif