xref: /openbmc/u-boot/board/davinci/ea20/ea20.c (revision e5ee9125)
1649a33e4SStefano Babic /*
2649a33e4SStefano Babic  * (C) Copyright 2010
3649a33e4SStefano Babic  * Stefano Babic, DENX Software Engineering, sbabic@denx.de
4649a33e4SStefano Babic  *
5649a33e4SStefano Babic  * Based on da850evm.c, original Copyrights follow:
6649a33e4SStefano Babic  *
7649a33e4SStefano Babic  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8649a33e4SStefano Babic  *
9649a33e4SStefano Babic  * Based on da830evm.c. Original Copyrights follow:
10649a33e4SStefano Babic  *
11649a33e4SStefano Babic  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
12649a33e4SStefano Babic  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
13649a33e4SStefano Babic  *
14649a33e4SStefano Babic  * This program is free software; you can redistribute it and/or modify
15649a33e4SStefano Babic  * it under the terms of the GNU General Public License as published by
16649a33e4SStefano Babic  * the Free Software Foundation; either version 2 of the License, or
17649a33e4SStefano Babic  * (at your option) any later version.
18649a33e4SStefano Babic  *
19649a33e4SStefano Babic  * This program is distributed in the hope that it will be useful,
20649a33e4SStefano Babic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21649a33e4SStefano Babic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22649a33e4SStefano Babic  * GNU General Public License for more details.
23649a33e4SStefano Babic  *
24649a33e4SStefano Babic  * You should have received a copy of the GNU General Public License
25649a33e4SStefano Babic  * along with this program; if not, write to the Free Software
26649a33e4SStefano Babic  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27649a33e4SStefano Babic  */
28649a33e4SStefano Babic 
29649a33e4SStefano Babic #include <common.h>
30649a33e4SStefano Babic #include <i2c.h>
31649a33e4SStefano Babic #include <net.h>
32649a33e4SStefano Babic #include <netdev.h>
33649a33e4SStefano Babic #include <asm/arch/hardware.h>
34649a33e4SStefano Babic #include <asm/arch/emif_defs.h>
35649a33e4SStefano Babic #include <asm/arch/emac_defs.h>
36649a33e4SStefano Babic #include <asm/io.h>
37649a33e4SStefano Babic #include <asm/arch/davinci_misc.h>
38ca1646b8SBastian Ruppert #include <asm/arch/gpio.h>
39649a33e4SStefano Babic 
40649a33e4SStefano Babic DECLARE_GLOBAL_DATA_PTR;
41649a33e4SStefano Babic 
42649a33e4SStefano Babic #define pinmux(x)	(&davinci_syscfg_regs->pinmux[x])
43649a33e4SStefano Babic 
44649a33e4SStefano Babic /* SPI0 pin muxer settings */
45649a33e4SStefano Babic static const struct pinmux_config spi1_pins[] = {
46649a33e4SStefano Babic 	{ pinmux(5), 1, 1 },
47649a33e4SStefano Babic 	{ pinmux(5), 1, 2 },
48649a33e4SStefano Babic 	{ pinmux(5), 1, 4 },
49649a33e4SStefano Babic 	{ pinmux(5), 1, 5 }
50649a33e4SStefano Babic };
51649a33e4SStefano Babic 
52f9fc237fSBastian Ruppert /* UART0 pin muxer settings */
53649a33e4SStefano Babic static const struct pinmux_config uart_pins[] = {
54f9fc237fSBastian Ruppert 	{ pinmux(3), 2, 7 },
55f9fc237fSBastian Ruppert 	{ pinmux(3), 2, 6 },
56f9fc237fSBastian Ruppert 	{ pinmux(3), 2, 4 },
57f9fc237fSBastian Ruppert 	{ pinmux(3), 2, 5 }
58649a33e4SStefano Babic };
59649a33e4SStefano Babic 
60649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
61649a33e4SStefano Babic #define HAS_RMII 1
62649a33e4SStefano Babic static const struct pinmux_config emac_pins[] = {
63649a33e4SStefano Babic 	{ pinmux(14), 8, 2 },
64649a33e4SStefano Babic 	{ pinmux(14), 8, 3 },
65649a33e4SStefano Babic 	{ pinmux(14), 8, 4 },
66649a33e4SStefano Babic 	{ pinmux(14), 8, 5 },
67649a33e4SStefano Babic 	{ pinmux(14), 8, 6 },
68649a33e4SStefano Babic 	{ pinmux(14), 8, 7 },
69649a33e4SStefano Babic 	{ pinmux(15), 8, 1 },
70649a33e4SStefano Babic 	{ pinmux(4), 8, 0 },
71649a33e4SStefano Babic 	{ pinmux(4), 8, 1 }
72649a33e4SStefano Babic };
73649a33e4SStefano Babic #endif
74649a33e4SStefano Babic 
75649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI
76649a33e4SStefano Babic const struct pinmux_config nand_pins[] = {
7717a8904bSStefano Babic 	{ pinmux(7), 1, 0},	/* CS2 */
7817a8904bSStefano Babic 	{ pinmux(7), 0, 1},	/* CS3  in three state*/
7917a8904bSStefano Babic 	{ pinmux(7), 1, 4 },	/* EMA_WE */
8017a8904bSStefano Babic 	{ pinmux(7), 1, 5 },	/* EMA_OE */
8117a8904bSStefano Babic 	{ pinmux(9), 1, 0 },	/* EMA_D[7] */
8217a8904bSStefano Babic 	{ pinmux(9), 1, 1 },	/* EMA_D[6] */
8317a8904bSStefano Babic 	{ pinmux(9), 1, 2 },	/* EMA_D[5] */
8417a8904bSStefano Babic 	{ pinmux(9), 1, 3 },	/* EMA_D[4] */
8517a8904bSStefano Babic 	{ pinmux(9), 1, 4 },	/* EMA_D[3] */
8617a8904bSStefano Babic 	{ pinmux(9), 1, 5 },	/* EMA_D[2] */
8717a8904bSStefano Babic 	{ pinmux(9), 1, 6 },	/* EMA_D[1] */
8817a8904bSStefano Babic 	{ pinmux(9), 1, 7 },	/* EMA_D[0] */
8917a8904bSStefano Babic 	{ pinmux(12), 1, 5 },	/* EMA_A[2] */
9017a8904bSStefano Babic 	{ pinmux(12), 1, 6 },	/* EMA_A[1] */
9117a8904bSStefano Babic 	{ pinmux(6), 1, 0 }	/* EMA_CLK */
92649a33e4SStefano Babic };
93649a33e4SStefano Babic #endif
94649a33e4SStefano Babic 
95ca1646b8SBastian Ruppert const struct pinmux_config gpio_pins[] = {
96ca1646b8SBastian Ruppert 	{ pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/
97ca1646b8SBastian Ruppert 	{ pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/
98ca1646b8SBastian Ruppert 	{ pinmux(13), 8, 3 }  /* GPIO6[12] U0_SW1 on EA20-00101_2*/
99ca1646b8SBastian Ruppert };
100ca1646b8SBastian Ruppert 
101*e5ee9125SBastian Ruppert const struct pinmux_config halten_pin[] = {
102*e5ee9125SBastian Ruppert 	{ pinmux(3),  4, 2 } /* GPIO8[6] HALTEN */
103*e5ee9125SBastian Ruppert };
104*e5ee9125SBastian Ruppert 
105649a33e4SStefano Babic static const struct pinmux_resource pinmuxes[] = {
106649a33e4SStefano Babic #ifdef CONFIG_SPI_FLASH
107649a33e4SStefano Babic 	PINMUX_ITEM(spi1_pins),
108649a33e4SStefano Babic #endif
109649a33e4SStefano Babic 	PINMUX_ITEM(uart_pins),
110649a33e4SStefano Babic #ifdef CONFIG_NAND_DAVINCI
111649a33e4SStefano Babic 	PINMUX_ITEM(nand_pins),
112649a33e4SStefano Babic #endif
113649a33e4SStefano Babic };
114649a33e4SStefano Babic 
115649a33e4SStefano Babic static const struct lpsc_resource lpsc[] = {
116649a33e4SStefano Babic 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
117649a33e4SStefano Babic 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
118649a33e4SStefano Babic 	{ DAVINCI_LPSC_EMAC },	/* image download */
119f9fc237fSBastian Ruppert 	{ DAVINCI_LPSC_UART0 },	/* console */
120649a33e4SStefano Babic 	{ DAVINCI_LPSC_GPIO },
121649a33e4SStefano Babic };
122649a33e4SStefano Babic 
1231c6ec6ddSStefano Babic int board_early_init_f(void)
124649a33e4SStefano Babic {
125ca1646b8SBastian Ruppert 	struct davinci_gpio *gpio6_base =
126ca1646b8SBastian Ruppert 			(struct davinci_gpio *)DAVINCI_GPIO_BANK67;
127ca1646b8SBastian Ruppert 
128ca1646b8SBastian Ruppert 	/* PinMux for GPIO */
129ca1646b8SBastian Ruppert 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
130ca1646b8SBastian Ruppert 		return 1;
131ca1646b8SBastian Ruppert 
132ca1646b8SBastian Ruppert 	/* Set the RESETOUTn low */
133ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->set_data) & ~(1 << 15)),
134ca1646b8SBastian Ruppert 		&gpio6_base->set_data);
135ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->dir) & ~(1 << 15)), &gpio6_base->dir);
136ca1646b8SBastian Ruppert 
137ca1646b8SBastian Ruppert 	/* Set U0_SW0 low for UART0 as console*/
138ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->set_data) & ~(1 << 10)),
139ca1646b8SBastian Ruppert 		&gpio6_base->set_data);
140ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->dir) & ~(1 << 10)), &gpio6_base->dir);
141ca1646b8SBastian Ruppert 
142ca1646b8SBastian Ruppert 	/* Set U0_SW1 low for UART0 as console*/
143ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->set_data) & ~(1 << 12)),
144ca1646b8SBastian Ruppert 		&gpio6_base->set_data);
145ca1646b8SBastian Ruppert 	writel((readl(&gpio6_base->dir) & ~(1 << 12)), &gpio6_base->dir);
146ca1646b8SBastian Ruppert 
147649a33e4SStefano Babic #ifndef CONFIG_USE_IRQ
148649a33e4SStefano Babic 	irq_init();
149649a33e4SStefano Babic #endif
150649a33e4SStefano Babic 
151649a33e4SStefano Babic 	/*
152649a33e4SStefano Babic 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
153649a33e4SStefano Babic 	 * Linux kernel @ 25MHz EMIFA
154649a33e4SStefano Babic 	 */
15517a8904bSStefano Babic #ifdef CONFIG_NAND_DAVINCI
156649a33e4SStefano Babic 	writel((DAVINCI_ABCR_WSETUP(0) |
15717a8904bSStefano Babic 		DAVINCI_ABCR_WSTROBE(1) |
158649a33e4SStefano Babic 		DAVINCI_ABCR_WHOLD(0) |
159649a33e4SStefano Babic 		DAVINCI_ABCR_RSETUP(0) |
160649a33e4SStefano Babic 		DAVINCI_ABCR_RSTROBE(1) |
161649a33e4SStefano Babic 		DAVINCI_ABCR_RHOLD(0) |
162649a33e4SStefano Babic 		DAVINCI_ABCR_TA(0) |
163649a33e4SStefano Babic 		DAVINCI_ABCR_ASIZE_8BIT),
16417a8904bSStefano Babic 	       &davinci_emif_regs->ab1cr); /* CS2 */
165649a33e4SStefano Babic #endif
166649a33e4SStefano Babic 
167649a33e4SStefano Babic 	/*
168649a33e4SStefano Babic 	 * Power on required peripherals
169649a33e4SStefano Babic 	 * ARM does not have access by default to PSC0 and PSC1
170649a33e4SStefano Babic 	 * assuming here that the DSP bootloader has set the IOPU
171649a33e4SStefano Babic 	 * such that PSC access is available to ARM
172649a33e4SStefano Babic 	 */
173649a33e4SStefano Babic 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
174649a33e4SStefano Babic 		return 1;
175649a33e4SStefano Babic 
176649a33e4SStefano Babic 	/* setup the SUSPSRC for ARM to control emulation suspend */
177649a33e4SStefano Babic 	writel(readl(&davinci_syscfg_regs->suspsrc) &
178649a33e4SStefano Babic 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
179649a33e4SStefano Babic 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
180f9fc237fSBastian Ruppert 		 DAVINCI_SYSCFG_SUSPSRC_UART0),
181649a33e4SStefano Babic 	       &davinci_syscfg_regs->suspsrc);
182649a33e4SStefano Babic 
183649a33e4SStefano Babic 	/* configure pinmux settings */
184649a33e4SStefano Babic 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
185649a33e4SStefano Babic 		return 1;
186649a33e4SStefano Babic 
187649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
188649a33e4SStefano Babic 	if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
189649a33e4SStefano Babic 		return 1;
190649a33e4SStefano Babic 
191649a33e4SStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
192649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */
193649a33e4SStefano Babic 
194649a33e4SStefano Babic 	/* enable the console UART */
195649a33e4SStefano Babic 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
196649a33e4SStefano Babic 		DAVINCI_UART_PWREMU_MGMT_UTRST),
197f9fc237fSBastian Ruppert 	       &davinci_uart0_ctrl_regs->pwremu_mgmt);
198649a33e4SStefano Babic 
199649a33e4SStefano Babic 	return 0;
200649a33e4SStefano Babic }
201649a33e4SStefano Babic 
2021c6ec6ddSStefano Babic int board_init(void)
2031c6ec6ddSStefano Babic {
2041c6ec6ddSStefano Babic 	/* arch number of the board */
2051c6ec6ddSStefano Babic 	gd->bd->bi_arch_number = MACH_TYPE_EA20;
2061c6ec6ddSStefano Babic 
2071c6ec6ddSStefano Babic 	/* address of boot parameters */
2081c6ec6ddSStefano Babic 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
2091c6ec6ddSStefano Babic 
2101c6ec6ddSStefano Babic 	return 0;
2111c6ec6ddSStefano Babic }
212*e5ee9125SBastian Ruppert 
213*e5ee9125SBastian Ruppert #ifdef BOARD_LATE_INIT
214*e5ee9125SBastian Ruppert 
215*e5ee9125SBastian Ruppert int board_late_init(void)
216*e5ee9125SBastian Ruppert {
217*e5ee9125SBastian Ruppert 	struct davinci_gpio *gpio8_base =
218*e5ee9125SBastian Ruppert 			(struct davinci_gpio *)DAVINCI_GPIO_BANK8;
219*e5ee9125SBastian Ruppert 
220*e5ee9125SBastian Ruppert 	/* PinMux for HALTEN */
221*e5ee9125SBastian Ruppert 	if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0)
222*e5ee9125SBastian Ruppert 		return 1;
223*e5ee9125SBastian Ruppert 
224*e5ee9125SBastian Ruppert 	/* Set HALTEN to high */
225*e5ee9125SBastian Ruppert 	writel((readl(&gpio8_base->set_data) | (1 << 6)),
226*e5ee9125SBastian Ruppert 		&gpio8_base->set_data);
227*e5ee9125SBastian Ruppert 	writel((readl(&gpio8_base->dir) & ~(1 << 6)), &gpio8_base->dir);
228*e5ee9125SBastian Ruppert 
229*e5ee9125SBastian Ruppert 	return 0;
230*e5ee9125SBastian Ruppert }
231*e5ee9125SBastian Ruppert #endif /* BOARD_LATE_INIT */
232*e5ee9125SBastian Ruppert 
233649a33e4SStefano Babic #ifdef CONFIG_DRIVER_TI_EMAC
234649a33e4SStefano Babic 
235649a33e4SStefano Babic /*
236649a33e4SStefano Babic  * Initializes on-board ethernet controllers.
237649a33e4SStefano Babic  */
238649a33e4SStefano Babic int board_eth_init(bd_t *bis)
239649a33e4SStefano Babic {
240649a33e4SStefano Babic 	if (!davinci_emac_initialize()) {
241649a33e4SStefano Babic 		printf("Error: Ethernet init failed!\n");
242649a33e4SStefano Babic 		return -1;
243649a33e4SStefano Babic 	}
244649a33e4SStefano Babic 
245649a33e4SStefano Babic 	/*
246649a33e4SStefano Babic 	 * This board has a RMII PHY. However, the MDC line on the SOM
247649a33e4SStefano Babic 	 * must not be disabled (there is no MII PHY on the
248649a33e4SStefano Babic 	 * baseboard) via the GPIO2[6], because this pin
249649a33e4SStefano Babic 	 * disables at the same time the SPI flash.
250649a33e4SStefano Babic 	 */
251649a33e4SStefano Babic 
252649a33e4SStefano Babic 	return 0;
253649a33e4SStefano Babic }
254649a33e4SStefano Babic #endif /* CONFIG_DRIVER_TI_EMAC */
255