at91sam9263ek.c 6.7 KB

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