2 * (C) Copyright 2007-2008
3 * Stelian Pop <stelian@popies.net>
4 * Lead Tech Design <www.leadtechdesign.com>
6 * Achim Ehrlich <aehrlich@taskit.de>
7 * taskit GmbH <www.taskit.de>
10 * Markus Hubig <mhubig@imko.de>
11 * IMKO GmbH <www.imko.de>
13 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/arch/at91sam9260_matrix.h>
19 #include <asm/arch/at91sam9_smc.h>
20 #include <asm/arch/at91_common.h>
21 #include <asm/arch/at91_pmc.h>
22 #include <asm/arch/at91_rstc.h>
23 #include <asm/arch/gpio.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 static void stamp9G20_nand_hw_init(void)
35 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
36 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
39 /* Assign CS3 to NAND/SmartMedia Interface */
40 csa = readl(&matrix->ebicsa);
41 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
42 writel(csa, &matrix->ebicsa);
44 /* Configure SMC CS3 for NAND/SmartMedia */
45 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
46 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
48 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
49 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
51 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
53 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
54 AT91_SMC_MODE_EXNW_DISABLE |
56 AT91_SMC_MODE_TDF_CYCLE(2),
59 /* Configure RDY/BSY */
60 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
62 /* Enable NandFlash */
63 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
67 static void stamp9G20_macb_hw_init(void)
69 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
70 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
73 /* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
74 at91_set_gpio_output(AT91_PIN_PA26, 0);
78 * RXDV (PA17) => PHY normal mode (not Test mode)
79 * ERX0 (PA14) => PHY ADDR0
80 * ERX1 (PA15) => PHY ADDR1
81 * ERX2 (PA25) => PHY ADDR2
82 * ERX3 (PA26) => PHY ADDR3
83 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
85 * PHY has internal pull-down
87 writel(pin_to_mask(AT91_PIN_PA14) |
88 pin_to_mask(AT91_PIN_PA15) |
89 pin_to_mask(AT91_PIN_PA17) |
90 pin_to_mask(AT91_PIN_PA18) |
91 pin_to_mask(AT91_PIN_PA28),
94 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
96 /* Need to reset PHY -> 500ms reset */
97 writel(AT91_RSTC_KEY | (AT91_RSTC_MR_ERSTL(13) &
98 ~AT91_RSTC_MR_URSTEN), &rstc->mr);
99 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
101 /* Wait for end of hardware reset */
102 unsigned long start = get_timer(0);
103 unsigned long timeout = 1000; /* 1000ms */
105 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
107 /* avoid shutdown by watchdog */
111 /* timeout for not getting stuck in an endless loop */
112 if (get_timer(start) >= timeout) {
113 puts("*** ERROR: Timeout waiting for PHY reset!\n");
118 /* Restore NRST value */
119 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
122 /* Re-enable pull-up */
123 writel(pin_to_mask(AT91_PIN_PA14) |
124 pin_to_mask(AT91_PIN_PA15) |
125 pin_to_mask(AT91_PIN_PA17) |
126 pin_to_mask(AT91_PIN_PA18) |
127 pin_to_mask(AT91_PIN_PA28),
130 /* Initialize EMAC=MACB hardware */
133 #endif /* CONFIG_MACB */
135 int board_early_init_f(void)
137 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
139 /* Enable clocks for all PIOs */
140 writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
141 (1 << ATMEL_ID_PIOC), &pmc->pcer);
146 int board_postclk_init(void)
149 * Initialize the serial interface here, because be need a running
150 * timer to set PC9 to high and wait for some time to enable the
151 * level converter of the RS232 interface on the PortuxG20 board.
154 #ifdef CONFIG_PORTUXG20
155 at91_set_gpio_output(AT91_PIN_PC9, 1);
158 at91_seriald_hw_init();
165 /* Adress of boot parameters */
166 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
168 stamp9G20_nand_hw_init();
170 stamp9G20_macb_hw_init();
177 gd->ram_size = get_ram_size(
178 (void *)CONFIG_SYS_SDRAM_BASE,
179 CONFIG_SYS_SDRAM_SIZE);
184 int board_eth_init(bd_t *bis)
186 return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
188 #endif /* CONFIG_MACB */