at91sam9263ek.c 6.7 KB

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