pm9263.c 10 KB

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