xref: /rk3399_rockchip-uboot/board/bluewater/gurnard/gurnard.c (revision 00caae6d47645e68d6e5277aceb69592b49381a6)
1885fc03aSAndre Renaud /*
2885fc03aSAndre Renaud  * Bluewater Systems Snapper 9260/9G20 modules
3885fc03aSAndre Renaud  *
4885fc03aSAndre Renaud  * (C) Copyright 2011 Bluewater Systems
5885fc03aSAndre Renaud  *   Author: Andre Renaud <andre@bluewatersys.com>
6885fc03aSAndre Renaud  *   Author: Ryan Mallon <ryan@bluewatersys.com>
7885fc03aSAndre Renaud  *
8885fc03aSAndre Renaud  * SPDX-License-Identifier:	GPL-2.0+
9885fc03aSAndre Renaud  */
10885fc03aSAndre Renaud 
11885fc03aSAndre Renaud #include <common.h>
12885fc03aSAndre Renaud #include <atmel_lcd.h>
13885fc03aSAndre Renaud #include <atmel_lcdc.h>
14885fc03aSAndre Renaud #include <atmel_mci.h>
15885fc03aSAndre Renaud #include <dm.h>
16885fc03aSAndre Renaud #include <lcd.h>
17885fc03aSAndre Renaud #include <net.h>
18885fc03aSAndre Renaud #ifndef CONFIG_DM_ETH
19885fc03aSAndre Renaud #include <netdev.h>
20885fc03aSAndre Renaud #endif
21885fc03aSAndre Renaud #include <spi.h>
22885fc03aSAndre Renaud #include <asm/gpio.h>
23885fc03aSAndre Renaud #include <asm/io.h>
24c62db35dSSimon Glass #include <asm/mach-types.h>
25885fc03aSAndre Renaud #include <asm/arch/at91sam9g45_matrix.h>
26885fc03aSAndre Renaud #include <asm/arch/at91sam9_smc.h>
27885fc03aSAndre Renaud #include <asm/arch/at91_common.h>
28885fc03aSAndre Renaud #include <asm/arch/at91_emac.h>
29885fc03aSAndre Renaud #include <asm/arch/at91_rstc.h>
30885fc03aSAndre Renaud #include <asm/arch/at91_rtc.h>
31885fc03aSAndre Renaud #include <asm/arch/at91_sck.h>
32885fc03aSAndre Renaud #include <asm/arch/atmel_serial.h>
33885fc03aSAndre Renaud #include <asm/arch/clk.h>
34885fc03aSAndre Renaud #include <asm/arch/gpio.h>
35885fc03aSAndre Renaud #include <dm/uclass-internal.h>
36885fc03aSAndre Renaud 
37885fc03aSAndre Renaud #ifdef CONFIG_GURNARD_SPLASH
38885fc03aSAndre Renaud #include "splash_logo.h"
39885fc03aSAndre Renaud #endif
40885fc03aSAndre Renaud 
41885fc03aSAndre Renaud DECLARE_GLOBAL_DATA_PTR;
42885fc03aSAndre Renaud 
43885fc03aSAndre Renaud /* IO Expander pins */
44885fc03aSAndre Renaud #define IO_EXP_ETH_RESET	(0 << 1)
45885fc03aSAndre Renaud #define IO_EXP_ETH_POWER	(1 << 1)
46885fc03aSAndre Renaud 
47885fc03aSAndre Renaud #ifdef CONFIG_MACB
gurnard_macb_hw_init(void)48885fc03aSAndre Renaud static void gurnard_macb_hw_init(void)
49885fc03aSAndre Renaud {
50885fc03aSAndre Renaud 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
51885fc03aSAndre Renaud 
52885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_EMAC);
53885fc03aSAndre Renaud 
54885fc03aSAndre Renaud 	/*
55885fc03aSAndre Renaud 	 * Enable pull-up on:
56885fc03aSAndre Renaud 	 *	RXDV (PA12) => MODE0 - PHY also has pull-up
57885fc03aSAndre Renaud 	 *	ERX0 (PA13) => MODE1 - PHY also has pull-up
58885fc03aSAndre Renaud 	 *	ERX1 (PA15) => MODE2 - PHY also has pull-up
59885fc03aSAndre Renaud 	 */
60885fc03aSAndre Renaud 	writel(pin_to_mask(AT91_PIN_PA15) |
61885fc03aSAndre Renaud 	       pin_to_mask(AT91_PIN_PA12) |
62885fc03aSAndre Renaud 	       pin_to_mask(AT91_PIN_PA13),
63885fc03aSAndre Renaud 	       &pioa->puer);
64885fc03aSAndre Renaud 
65885fc03aSAndre Renaud 	at91_phy_reset();
66885fc03aSAndre Renaud 
67885fc03aSAndre Renaud 	at91_macb_hw_init();
68885fc03aSAndre Renaud }
69885fc03aSAndre Renaud #endif
70885fc03aSAndre Renaud 
71885fc03aSAndre Renaud #ifdef CONFIG_CMD_NAND
gurnard_nand_hw_init(void)72885fc03aSAndre Renaud static int gurnard_nand_hw_init(void)
73885fc03aSAndre Renaud {
74885fc03aSAndre Renaud 	struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
75885fc03aSAndre Renaud 	struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
76885fc03aSAndre Renaud 	ulong flags;
77885fc03aSAndre Renaud 	int ret;
78885fc03aSAndre Renaud 
79885fc03aSAndre Renaud 	/* Enable CS3 as NAND/SmartMedia */
80885fc03aSAndre Renaud 	setbits_le32(&matrix->ebicsa, AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
81885fc03aSAndre Renaud 
82885fc03aSAndre Renaud 	/* Configure SMC CS3 for NAND/SmartMedia */
83885fc03aSAndre Renaud 	writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
84885fc03aSAndre Renaud 	       AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
85885fc03aSAndre Renaud 	       &smc->cs[3].setup);
86885fc03aSAndre Renaud 	writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
87885fc03aSAndre Renaud 	       AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
88885fc03aSAndre Renaud 	       &smc->cs[3].pulse);
89885fc03aSAndre Renaud 	writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
90885fc03aSAndre Renaud 	       &smc->cs[3].cycle);
91885fc03aSAndre Renaud #ifdef CONFIG_SYS_NAND_DBW_16
92885fc03aSAndre Renaud 	flags = AT91_SMC_MODE_DBW_16;
93885fc03aSAndre Renaud #else
94885fc03aSAndre Renaud 	flags = AT91_SMC_MODE_DBW_8;
95885fc03aSAndre Renaud #endif
96885fc03aSAndre Renaud 	writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
97885fc03aSAndre Renaud 	       AT91_SMC_MODE_EXNW_DISABLE |
98885fc03aSAndre Renaud 	       flags |
99885fc03aSAndre Renaud 	       AT91_SMC_MODE_TDF_CYCLE(3),
100885fc03aSAndre Renaud 	       &smc->cs[3].mode);
101885fc03aSAndre Renaud 
102885fc03aSAndre Renaud 	ret = gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand_rdy");
103885fc03aSAndre Renaud 	if (ret)
104885fc03aSAndre Renaud 		return ret;
105885fc03aSAndre Renaud 	gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
106885fc03aSAndre Renaud 
107885fc03aSAndre Renaud 	/* Enable NandFlash */
108885fc03aSAndre Renaud 	ret = gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand_ce");
109885fc03aSAndre Renaud 	if (ret)
110885fc03aSAndre Renaud 		return ret;
111885fc03aSAndre Renaud 	gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
112885fc03aSAndre Renaud 
113885fc03aSAndre Renaud 	return 0;
114885fc03aSAndre Renaud }
115885fc03aSAndre Renaud #endif
116885fc03aSAndre Renaud 
117885fc03aSAndre Renaud #ifdef CONFIG_GURNARD_SPLASH
lcd_splash(int width,int height)118885fc03aSAndre Renaud static void lcd_splash(int width, int height)
119885fc03aSAndre Renaud {
120885fc03aSAndre Renaud 	u16 colour;
121885fc03aSAndre Renaud 	int x, y;
122885fc03aSAndre Renaud 	u16 *base_addr = (u16 *)gd->video_bottom;
123885fc03aSAndre Renaud 
124885fc03aSAndre Renaud 	memset(base_addr, 0xff, width * height * 2);
125885fc03aSAndre Renaud 	/*
126885fc03aSAndre Renaud 	 * Blit the logo to the center of the screen
127885fc03aSAndre Renaud 	 */
128885fc03aSAndre Renaud 	for (y = 0; y < BMP_LOGO_HEIGHT; y++) {
129885fc03aSAndre Renaud 		for (x = 0; x < BMP_LOGO_WIDTH; x++) {
130885fc03aSAndre Renaud 			int posx, posy;
131885fc03aSAndre Renaud 			colour = bmp_logo_palette[bmp_logo_bitmap[
132885fc03aSAndre Renaud 			    y * BMP_LOGO_WIDTH + x]];
133885fc03aSAndre Renaud 			posx = x + (width - BMP_LOGO_WIDTH) / 2;
134885fc03aSAndre Renaud 			posy = y;
135885fc03aSAndre Renaud 			base_addr[posy * width + posx] = colour;
136885fc03aSAndre Renaud 		}
137885fc03aSAndre Renaud 	}
138885fc03aSAndre Renaud }
139885fc03aSAndre Renaud #endif
140885fc03aSAndre Renaud 
141885fc03aSAndre Renaud #ifdef CONFIG_DM_VIDEO
at91sam9g45_lcd_hw_init(void)142885fc03aSAndre Renaud static void at91sam9g45_lcd_hw_init(void)
143885fc03aSAndre Renaud {
144885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE0, 0);	/* LCDDPWR */
145885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE2, 0);	/* LCDCC */
146885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE3, 0);	/* LCDVSYNC */
147885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE4, 0);	/* LCDHSYNC */
148885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE5, 0);	/* LCDDOTCK */
149885fc03aSAndre Renaud 
150885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE7, 0);	/* LCDD0 */
151885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE8, 0);	/* LCDD1 */
152885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE9, 0);	/* LCDD2 */
153885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE10, 0);	/* LCDD3 */
154885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE11, 0);	/* LCDD4 */
155885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE12, 0);	/* LCDD5 */
156885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE13, 0);	/* LCDD6 */
157885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE14, 0);	/* LCDD7 */
158885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE15, 0);	/* LCDD8 */
159885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE16, 0);	/* LCDD9 */
160885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE17, 0);	/* LCDD10 */
161885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE18, 0);	/* LCDD11 */
162885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE19, 0);	/* LCDD12 */
163885fc03aSAndre Renaud 	at91_set_B_periph(AT91_PIN_PE20, 0);	/* LCDD13 */
164885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE21, 0);	/* LCDD14 */
165885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE22, 0);	/* LCDD15 */
166885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE23, 0);	/* LCDD16 */
167885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE24, 0);	/* LCDD17 */
168885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE25, 0);	/* LCDD18 */
169885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE26, 0);	/* LCDD19 */
170885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE27, 0);	/* LCDD20 */
171885fc03aSAndre Renaud 	at91_set_B_periph(AT91_PIN_PE28, 0);	/* LCDD21 */
172885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE29, 0);	/* LCDD22 */
173885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE30, 0);	/* LCDD23 */
174885fc03aSAndre Renaud 
175885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_LCDC);
176885fc03aSAndre Renaud }
177885fc03aSAndre Renaud #endif
178885fc03aSAndre Renaud 
179885fc03aSAndre Renaud #ifdef CONFIG_GURNARD_FPGA
180885fc03aSAndre Renaud /**
181885fc03aSAndre Renaud  * Initialise the memory bus settings so that we can talk to the
182885fc03aSAndre Renaud  * memory mapped FPGA
183885fc03aSAndre Renaud  */
fpga_hw_init(void)184885fc03aSAndre Renaud static int fpga_hw_init(void)
185885fc03aSAndre Renaud {
186885fc03aSAndre Renaud 	struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
187885fc03aSAndre Renaud 	struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
188885fc03aSAndre Renaud 	int i;
189885fc03aSAndre Renaud 
190885fc03aSAndre Renaud 	setbits_le32(&matrix->ebicsa, AT91_MATRIX_EBI_CS1A_SDRAMC);
191885fc03aSAndre Renaud 
192885fc03aSAndre Renaud 	at91_set_a_periph(2, 4, 0); /* EBIA21 */
193885fc03aSAndre Renaud 	at91_set_a_periph(2, 5, 0); /* EBIA22 */
194885fc03aSAndre Renaud 	at91_set_a_periph(2, 6, 0); /* EBIA23 */
195885fc03aSAndre Renaud 	at91_set_a_periph(2, 7, 0); /* EBIA24 */
196885fc03aSAndre Renaud 	at91_set_a_periph(2, 12, 0); /* EBIA25 */
197885fc03aSAndre Renaud 	for (i = 15; i <= 31; i++) /* EBINWAIT & EBID16 - 31 */
198885fc03aSAndre Renaud 		at91_set_a_periph(2, i, 0);
199885fc03aSAndre Renaud 
200885fc03aSAndre Renaud 	/* configure SMC cs0 for FPGA access timing */
201885fc03aSAndre Renaud 	writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(2) |
202885fc03aSAndre Renaud 	       AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(2),
203885fc03aSAndre Renaud 	       &smc->cs[0].setup);
204885fc03aSAndre Renaud 	writel(AT91_SMC_PULSE_NWE(5) | AT91_SMC_PULSE_NCS_WR(4) |
205885fc03aSAndre Renaud 	       AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(4),
206885fc03aSAndre Renaud 	       &smc->cs[0].pulse);
207885fc03aSAndre Renaud 	writel(AT91_SMC_CYCLE_NWE(6) | AT91_SMC_CYCLE_NRD(6),
208885fc03aSAndre Renaud 	       &smc->cs[0].cycle);
209885fc03aSAndre Renaud 	writel(AT91_SMC_MODE_BAT |
210885fc03aSAndre Renaud 	       AT91_SMC_MODE_EXNW_DISABLE |
211885fc03aSAndre Renaud 	       AT91_SMC_MODE_DBW_32 |
212885fc03aSAndre Renaud 	       AT91_SMC_MODE_TDF |
213885fc03aSAndre Renaud 	       AT91_SMC_MODE_TDF_CYCLE(2),
214885fc03aSAndre Renaud 	       &smc->cs[0].mode);
215885fc03aSAndre Renaud 
216885fc03aSAndre Renaud 	/* Do a write to within EBI_CS1 to enable the SDCK */
217885fc03aSAndre Renaud 	writel(0, ATMEL_BASE_CS1);
218885fc03aSAndre Renaud 
219885fc03aSAndre Renaud 	return 0;
220885fc03aSAndre Renaud }
221885fc03aSAndre Renaud #endif
222885fc03aSAndre Renaud 
223885fc03aSAndre Renaud #ifdef CONFIG_CMD_USB
224885fc03aSAndre Renaud 
225885fc03aSAndre Renaud #define USB0_ENABLE_PIN		AT91_PIN_PB22
226885fc03aSAndre Renaud #define USB1_ENABLE_PIN		AT91_PIN_PB23
227885fc03aSAndre Renaud 
gurnard_usb_init(void)228885fc03aSAndre Renaud void gurnard_usb_init(void)
229885fc03aSAndre Renaud {
230885fc03aSAndre Renaud 	at91_set_gpio_output(USB0_ENABLE_PIN, 1);
231885fc03aSAndre Renaud 	at91_set_gpio_value(USB0_ENABLE_PIN, 0);
232885fc03aSAndre Renaud 	at91_set_gpio_output(USB1_ENABLE_PIN, 1);
233885fc03aSAndre Renaud 	at91_set_gpio_value(USB1_ENABLE_PIN, 0);
234885fc03aSAndre Renaud }
235885fc03aSAndre Renaud #endif
236885fc03aSAndre Renaud 
237885fc03aSAndre Renaud #ifdef CONFIG_GENERIC_ATMEL_MCI
cpu_mmc_init(bd_t * bis)238885fc03aSAndre Renaud int cpu_mmc_init(bd_t *bis)
239885fc03aSAndre Renaud {
240885fc03aSAndre Renaud 	return atmel_mci_init((void *)ATMEL_BASE_MCI0);
241885fc03aSAndre Renaud }
242885fc03aSAndre Renaud #endif
243885fc03aSAndre Renaud 
gurnard_enable_console(int enable)244885fc03aSAndre Renaud static void gurnard_enable_console(int enable)
245885fc03aSAndre Renaud {
246885fc03aSAndre Renaud 	at91_set_gpio_output(AT91_PIN_PB14, 1);
247885fc03aSAndre Renaud 	at91_set_gpio_value(AT91_PIN_PB14, enable ? 0 : 1);
248885fc03aSAndre Renaud }
249885fc03aSAndre Renaud 
at91sam9g45_slowclock_init(void)250885fc03aSAndre Renaud void at91sam9g45_slowclock_init(void)
251885fc03aSAndre Renaud {
252885fc03aSAndre Renaud 	/*
253885fc03aSAndre Renaud 	 * On AT91SAM9G45 revC CPUs, the slow clock can be based on an
254885fc03aSAndre Renaud 	 * internal impreciseRC oscillator or an external 32kHz oscillator.
255885fc03aSAndre Renaud 	 * Switch to the latter.
256885fc03aSAndre Renaud 	 */
257885fc03aSAndre Renaud 	unsigned i, tmp;
258885fc03aSAndre Renaud 	ulong *reg = (ulong *)ATMEL_BASE_SCKCR;
259885fc03aSAndre Renaud 
260885fc03aSAndre Renaud 	tmp = readl(reg);
261885fc03aSAndre Renaud 	if ((tmp & AT91SAM9G45_SCKCR_OSCSEL) == AT91SAM9G45_SCKCR_OSCSEL_RC) {
262885fc03aSAndre Renaud 		timer_init();
263885fc03aSAndre Renaud 		tmp |= AT91SAM9G45_SCKCR_OSC32EN;
264885fc03aSAndre Renaud 		writel(tmp, reg);
265885fc03aSAndre Renaud 		for (i = 0; i < 1200; i++)
266885fc03aSAndre Renaud 			udelay(1000);
267885fc03aSAndre Renaud 		tmp |= AT91SAM9G45_SCKCR_OSCSEL_32;
268885fc03aSAndre Renaud 		writel(tmp, reg);
269885fc03aSAndre Renaud 		udelay(200);
270885fc03aSAndre Renaud 		tmp &= ~AT91SAM9G45_SCKCR_RCEN;
271885fc03aSAndre Renaud 		writel(tmp, reg);
272885fc03aSAndre Renaud 	}
273885fc03aSAndre Renaud }
274885fc03aSAndre Renaud 
board_early_init_f(void)275885fc03aSAndre Renaud int board_early_init_f(void)
276885fc03aSAndre Renaud {
277885fc03aSAndre Renaud 	at91_seriald_hw_init();
278885fc03aSAndre Renaud 	gurnard_enable_console(1);
279885fc03aSAndre Renaud 
280885fc03aSAndre Renaud 	return 0;
281885fc03aSAndre Renaud }
282885fc03aSAndre Renaud 
board_init(void)283885fc03aSAndre Renaud int board_init(void)
284885fc03aSAndre Renaud {
285885fc03aSAndre Renaud 	const char *rev_str;
286885fc03aSAndre Renaud #ifdef CONFIG_CMD_NAND
287885fc03aSAndre Renaud 	int ret;
288885fc03aSAndre Renaud #endif
289885fc03aSAndre Renaud 
290885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_PIOA);
291885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_PIOB);
292885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_PIOC);
293885fc03aSAndre Renaud 	at91_periph_clk_enable(ATMEL_ID_PIODE);
294885fc03aSAndre Renaud 
295885fc03aSAndre Renaud 	at91sam9g45_slowclock_init();
296885fc03aSAndre Renaud 
297885fc03aSAndre Renaud 	/*
298885fc03aSAndre Renaud 	 * Clear the RTC IDR to disable all IRQs. Avoid issues when Linux
299885fc03aSAndre Renaud 	 * boots with spurious IRQs.
300885fc03aSAndre Renaud 	 */
301885fc03aSAndre Renaud 	writel(0xffffffff, AT91_RTC_IDR);
302885fc03aSAndre Renaud 
303885fc03aSAndre Renaud 	/* Make sure that the reset signal is attached properly */
304885fc03aSAndre Renaud 	setbits_le32(AT91_ASM_RSTC_MR, AT91_RSTC_KEY | AT91_RSTC_MR_URSTEN);
305885fc03aSAndre Renaud 
306885fc03aSAndre Renaud 	gd->bd->bi_arch_number = MACH_TYPE_SNAPPER_9260;
307885fc03aSAndre Renaud 
308885fc03aSAndre Renaud 	/* Address of boot parameters */
309885fc03aSAndre Renaud 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
310885fc03aSAndre Renaud 
311885fc03aSAndre Renaud #ifdef CONFIG_CMD_NAND
312885fc03aSAndre Renaud 	ret = gurnard_nand_hw_init();
313885fc03aSAndre Renaud 	if (ret)
314885fc03aSAndre Renaud 		return ret;
315885fc03aSAndre Renaud #endif
316885fc03aSAndre Renaud #ifdef CONFIG_ATMEL_SPI
317885fc03aSAndre Renaud 	at91_spi0_hw_init(1 << 4);
318885fc03aSAndre Renaud #endif
319885fc03aSAndre Renaud 
320885fc03aSAndre Renaud #ifdef CONFIG_MACB
321885fc03aSAndre Renaud 	gurnard_macb_hw_init();
322885fc03aSAndre Renaud #endif
323885fc03aSAndre Renaud 
324885fc03aSAndre Renaud #ifdef CONFIG_GURNARD_FPGA
325885fc03aSAndre Renaud 	fpga_hw_init();
326885fc03aSAndre Renaud #endif
327885fc03aSAndre Renaud 
328885fc03aSAndre Renaud #ifdef CONFIG_CMD_USB
329885fc03aSAndre Renaud 	gurnard_usb_init();
330885fc03aSAndre Renaud #endif
331885fc03aSAndre Renaud 
332885fc03aSAndre Renaud #ifdef CONFIG_CMD_MMC
333885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PA12, 0);
334885fc03aSAndre Renaud 	at91_set_gpio_output(AT91_PIN_PA8, 1);
335885fc03aSAndre Renaud 	at91_set_gpio_value(AT91_PIN_PA8, 0);
336885fc03aSAndre Renaud 	at91_mci_hw_init();
337885fc03aSAndre Renaud #endif
338885fc03aSAndre Renaud 
339885fc03aSAndre Renaud #ifdef CONFIG_DM_VIDEO
340885fc03aSAndre Renaud 	at91sam9g45_lcd_hw_init();
341885fc03aSAndre Renaud 	at91_set_A_periph(AT91_PIN_PE6, 1);	/* power up */
342885fc03aSAndre Renaud 
343885fc03aSAndre Renaud 	/* Select the second timing index for board rev 2 */
344*00caae6dSSimon Glass 	rev_str = env_get("board_rev");
345885fc03aSAndre Renaud 	if (rev_str && !strncmp(rev_str, "2", 1)) {
346885fc03aSAndre Renaud 		struct udevice *dev;
347885fc03aSAndre Renaud 
348885fc03aSAndre Renaud 		uclass_find_first_device(UCLASS_VIDEO, &dev);
349885fc03aSAndre Renaud 		if (dev) {
350885fc03aSAndre Renaud 			struct atmel_lcd_platdata *plat = dev_get_platdata(dev);
351885fc03aSAndre Renaud 
352885fc03aSAndre Renaud 			plat->timing_index = 1;
353885fc03aSAndre Renaud 		}
354885fc03aSAndre Renaud 	}
355885fc03aSAndre Renaud #endif
356885fc03aSAndre Renaud 
357885fc03aSAndre Renaud 	return 0;
358885fc03aSAndre Renaud }
359885fc03aSAndre Renaud 
board_late_init(void)360885fc03aSAndre Renaud int board_late_init(void)
361885fc03aSAndre Renaud {
362885fc03aSAndre Renaud 	u_int8_t env_enetaddr[8];
363885fc03aSAndre Renaud 	char *env_str;
364885fc03aSAndre Renaud 	char *end;
365885fc03aSAndre Renaud 	int i;
366885fc03aSAndre Renaud 
367885fc03aSAndre Renaud 	/*
368885fc03aSAndre Renaud 	 * Set MAC address so we do not need to init Ethernet before Linux
369885fc03aSAndre Renaud 	 * boot
370885fc03aSAndre Renaud 	 */
371*00caae6dSSimon Glass 	env_str = env_get("ethaddr");
372885fc03aSAndre Renaud 	if (env_str) {
373885fc03aSAndre Renaud 		struct at91_emac *emac = (struct at91_emac *)ATMEL_BASE_EMAC;
374885fc03aSAndre Renaud 		/* Parse MAC address */
375885fc03aSAndre Renaud 		for (i = 0; i < 6; i++) {
376885fc03aSAndre Renaud 			env_enetaddr[i] = env_str ?
377885fc03aSAndre Renaud 				simple_strtoul(env_str, &end, 16) : 0;
378885fc03aSAndre Renaud 			if (env_str)
379885fc03aSAndre Renaud 				env_str = (*end) ? end+1 : end;
380885fc03aSAndre Renaud 		}
381885fc03aSAndre Renaud 
382885fc03aSAndre Renaud 		/* Set hardware address */
383885fc03aSAndre Renaud 		writel(env_enetaddr[0] | env_enetaddr[1] << 8 |
384885fc03aSAndre Renaud 		       env_enetaddr[2] << 16 | env_enetaddr[3] << 24,
385885fc03aSAndre Renaud 		       &emac->sa2l);
386885fc03aSAndre Renaud 		writel((env_enetaddr[4] | env_enetaddr[5] << 8), &emac->sa2h);
387885fc03aSAndre Renaud 
388*00caae6dSSimon Glass 		printf("MAC:   %s\n", env_get("ethaddr"));
389885fc03aSAndre Renaud 	} else {
390885fc03aSAndre Renaud 		/* Not set in environment */
391885fc03aSAndre Renaud 		printf("MAC:   not set\n");
392885fc03aSAndre Renaud 	}
393885fc03aSAndre Renaud #ifdef CONFIG_GURNARD_SPLASH
394885fc03aSAndre Renaud 	lcd_splash(480, 272);
395885fc03aSAndre Renaud #endif
396885fc03aSAndre Renaud 
397885fc03aSAndre Renaud 	return 0;
398885fc03aSAndre Renaud }
399885fc03aSAndre Renaud 
400885fc03aSAndre Renaud #ifndef CONFIG_DM_ETH
board_eth_init(bd_t * bis)401885fc03aSAndre Renaud int board_eth_init(bd_t *bis)
402885fc03aSAndre Renaud {
403885fc03aSAndre Renaud 	return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0);
404885fc03aSAndre Renaud }
405885fc03aSAndre Renaud #endif
406885fc03aSAndre Renaud 
dram_init(void)407885fc03aSAndre Renaud int dram_init(void)
408885fc03aSAndre Renaud {
409885fc03aSAndre Renaud 	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
410885fc03aSAndre Renaud 				    CONFIG_SYS_SDRAM_SIZE);
411885fc03aSAndre Renaud 	return 0;
412885fc03aSAndre Renaud }
413885fc03aSAndre Renaud 
reset_phy(void)414885fc03aSAndre Renaud void reset_phy(void)
415885fc03aSAndre Renaud {
416885fc03aSAndre Renaud }
417885fc03aSAndre Renaud 
418885fc03aSAndre Renaud /* SPI chip select control - only used for FPGA programming */
419885fc03aSAndre Renaud #ifdef CONFIG_ATMEL_SPI
420885fc03aSAndre Renaud 
spi_cs_is_valid(unsigned int bus,unsigned int cs)421885fc03aSAndre Renaud int spi_cs_is_valid(unsigned int bus, unsigned int cs)
422885fc03aSAndre Renaud {
423885fc03aSAndre Renaud 	return bus == 0 && cs == 0;
424885fc03aSAndre Renaud }
425885fc03aSAndre Renaud 
spi_cs_activate(struct spi_slave * slave)426885fc03aSAndre Renaud void spi_cs_activate(struct spi_slave *slave)
427885fc03aSAndre Renaud {
428885fc03aSAndre Renaud 	/* We don't use chipselects for FPGA programming */
429885fc03aSAndre Renaud }
430885fc03aSAndre Renaud 
spi_cs_deactivate(struct spi_slave * slave)431885fc03aSAndre Renaud void spi_cs_deactivate(struct spi_slave *slave)
432885fc03aSAndre Renaud {
433885fc03aSAndre Renaud 	/* We don't use chipselects for FPGA programming */
434885fc03aSAndre Renaud }
435885fc03aSAndre Renaud #endif /* CONFIG_ATMEL_SPI */
436885fc03aSAndre Renaud 
437885fc03aSAndre Renaud static struct atmel_serial_platdata at91sam9260_serial_plat = {
438885fc03aSAndre Renaud 	.base_addr = ATMEL_BASE_DBGU,
439885fc03aSAndre Renaud };
440885fc03aSAndre Renaud 
441885fc03aSAndre Renaud U_BOOT_DEVICE(at91sam9260_serial) = {
442885fc03aSAndre Renaud 	.name	= "serial_atmel",
443885fc03aSAndre Renaud 	.platdata = &at91sam9260_serial_plat,
444885fc03aSAndre Renaud };
445