at91sam9263ek.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <linux/sizes.h>
  10. #include <asm/arch/at91sam9263.h>
  11. #include <asm/arch/at91sam9_smc.h>
  12. #include <asm/arch/at91_common.h>
  13. #include <asm/arch/at91_pmc.h>
  14. #include <asm/arch/at91_matrix.h>
  15. #include <asm/arch/at91_pio.h>
  16. #include <asm/arch/clk.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/arch/hardware.h>
  20. #include <lcd.h>
  21. #include <atmel_lcdc.h>
  22. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  23. #include <net.h>
  24. #endif
  25. #include <netdev.h>
  26. #include <atmel_mci.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* ------------------------------------------------------------------------- */
  29. /*
  30. * Miscelaneous platform dependent initialisations
  31. */
  32. #ifdef CONFIG_CMD_NAND
  33. static void at91sam9263ek_nand_hw_init(void)
  34. {
  35. unsigned long csa;
  36. at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC0;
  37. at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
  38. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  39. /* Enable CS3 */
  40. csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
  41. writel(csa, &matrix->csa[0]);
  42. /* Enable CS3 */
  43. /* Configure SMC CS3 for NAND/SmartMedia */
  44. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  45. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  46. &smc->cs[3].setup);
  47. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  48. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  49. &smc->cs[3].pulse);
  50. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  51. &smc->cs[3].cycle);
  52. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  53. AT91_SMC_MODE_EXNW_DISABLE |
  54. #ifdef CONFIG_SYS_NAND_DBW_16
  55. AT91_SMC_MODE_DBW_16 |
  56. #else /* CONFIG_SYS_NAND_DBW_8 */
  57. AT91_SMC_MODE_DBW_8 |
  58. #endif
  59. AT91_SMC_MODE_TDF_CYCLE(2),
  60. &smc->cs[3].mode);
  61. writel(1 << ATMEL_ID_PIOA | 1 << ATMEL_ID_PIOCDE,
  62. &pmc->pcer);
  63. /* Configure RDY/BSY */
  64. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  65. /* Enable NandFlash */
  66. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  67. }
  68. #endif
  69. #ifdef CONFIG_MACB
  70. static void at91sam9263ek_macb_hw_init(void)
  71. {
  72. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  73. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  74. /* Enable clock */
  75. writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
  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. writel(1 << 25, &pio->pioc.pudr);
  85. writel((1 << 25) | (1 <<26), &pio->pioe.pudr);
  86. at91_phy_reset();
  87. /* Re-enable pull-up */
  88. writel(1 << 25, &pio->pioc.puer);
  89. writel((1 << 25) | (1 <<26), &pio->pioe.puer);
  90. at91_macb_hw_init();
  91. }
  92. #endif
  93. #ifdef CONFIG_LCD
  94. vidinfo_t panel_info = {
  95. .vl_col = 240,
  96. .vl_row = 320,
  97. .vl_clk = 4965000,
  98. .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
  99. ATMEL_LCDC_INVFRAME_INVERTED,
  100. .vl_bpix = 3,
  101. .vl_tft = 1,
  102. .vl_hsync_len = 5,
  103. .vl_left_margin = 1,
  104. .vl_right_margin = 33,
  105. .vl_vsync_len = 1,
  106. .vl_upper_margin = 1,
  107. .vl_lower_margin = 0,
  108. .mmio = ATMEL_BASE_LCDC,
  109. };
  110. void lcd_enable(void)
  111. {
  112. at91_set_pio_value(AT91_PIO_PORTA, 30, 1); /* power up */
  113. }
  114. void lcd_disable(void)
  115. {
  116. at91_set_pio_value(AT91_PIO_PORTA, 30, 0); /* power down */
  117. }
  118. static void at91sam9263ek_lcd_hw_init(void)
  119. {
  120. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  121. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
  122. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
  123. at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
  124. at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
  125. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
  126. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
  127. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
  128. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
  129. at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
  130. at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
  131. at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
  132. at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
  133. at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
  134. at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
  135. at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
  136. at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
  137. at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
  138. at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
  139. at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
  140. at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
  141. at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
  142. at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
  143. writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
  144. gd->fb_base = ATMEL_BASE_SRAM0;
  145. }
  146. #ifdef CONFIG_LCD_INFO
  147. #include <nand.h>
  148. #include <version.h>
  149. #ifndef CONFIG_SYS_NO_FLASH
  150. extern flash_info_t flash_info[];
  151. #endif
  152. void lcd_show_board_info(void)
  153. {
  154. ulong dram_size, nand_size;
  155. #ifndef CONFIG_SYS_NO_FLASH
  156. ulong flash_size;
  157. #endif
  158. int i;
  159. char temp[32];
  160. lcd_printf ("%s\n", U_BOOT_VERSION);
  161. lcd_printf ("(C) 2008 ATMEL Corp\n");
  162. lcd_printf ("at91support@atmel.com\n");
  163. lcd_printf ("%s CPU at %s MHz\n",
  164. ATMEL_CPU_NAME,
  165. strmhz(temp, get_cpu_clk_rate()));
  166. dram_size = 0;
  167. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  168. dram_size += gd->bd->bi_dram[i].size;
  169. nand_size = 0;
  170. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  171. nand_size += nand_info[i].size;
  172. #ifndef CONFIG_SYS_NO_FLASH
  173. flash_size = 0;
  174. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
  175. flash_size += flash_info[i].size;
  176. #endif
  177. lcd_printf (" %ld MB SDRAM, %ld MB NAND",
  178. dram_size >> 20,
  179. nand_size >> 20 );
  180. #ifndef CONFIG_SYS_NO_FLASH
  181. lcd_printf (",\n %ld MB NOR",
  182. flash_size >> 20);
  183. #endif
  184. lcd_puts ("\n");
  185. }
  186. #endif /* CONFIG_LCD_INFO */
  187. #endif
  188. #ifdef CONFIG_GENERIC_ATMEL_MCI
  189. int board_mmc_init(bd_t *bd)
  190. {
  191. at91_mci_hw_init();
  192. return atmel_mci_init((void *)ATMEL_BASE_MCI1);
  193. }
  194. #endif
  195. int board_early_init_f(void)
  196. {
  197. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  198. /* Enable clocks for all PIOs */
  199. writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
  200. (1 << ATMEL_ID_PIOCDE),
  201. &pmc->pcer);
  202. at91_seriald_hw_init();
  203. return 0;
  204. }
  205. int board_init(void)
  206. {
  207. /* arch number of AT91SAM9263EK-Board */
  208. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9263EK;
  209. /* adress of boot parameters */
  210. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  211. #ifdef CONFIG_CMD_NAND
  212. at91sam9263ek_nand_hw_init();
  213. #endif
  214. #ifdef CONFIG_HAS_DATAFLASH
  215. at91_set_pio_output(AT91_PIO_PORTE, 20, 1); /* select spi0 clock */
  216. at91_spi0_hw_init(1 << 0);
  217. #endif
  218. #ifdef CONFIG_MACB
  219. at91sam9263ek_macb_hw_init();
  220. #endif
  221. #ifdef CONFIG_USB_OHCI_NEW
  222. at91_uhp_hw_init();
  223. #endif
  224. #ifdef CONFIG_LCD
  225. at91sam9263ek_lcd_hw_init();
  226. #endif
  227. return 0;
  228. }
  229. int dram_init(void)
  230. {
  231. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  232. CONFIG_SYS_SDRAM_SIZE);
  233. return 0;
  234. }
  235. #ifdef CONFIG_RESET_PHY_R
  236. void reset_phy(void)
  237. {
  238. }
  239. #endif
  240. int board_eth_init(bd_t *bis)
  241. {
  242. int rc = 0;
  243. #ifdef CONFIG_MACB
  244. rc = macb_eth_initialize(0, (void *) ATMEL_BASE_EMAC, 0x00);
  245. #endif
  246. return rc;
  247. }