xref: /openbmc/u-boot/board/davinci/da8xxevm/da850evm.c (revision 6f0d7ae26564a9beb429bb72b2ccf65e73816835)
189b765c7SSudhakar Rajashekhara /*
289b765c7SSudhakar Rajashekhara  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
389b765c7SSudhakar Rajashekhara  *
489b765c7SSudhakar Rajashekhara  * Based on da830evm.c. Original Copyrights follow:
589b765c7SSudhakar Rajashekhara  *
689b765c7SSudhakar Rajashekhara  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
789b765c7SSudhakar Rajashekhara  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
889b765c7SSudhakar Rajashekhara  *
989b765c7SSudhakar Rajashekhara  * This program is free software; you can redistribute it and/or modify
1089b765c7SSudhakar Rajashekhara  * it under the terms of the GNU General Public License as published by
1189b765c7SSudhakar Rajashekhara  * the Free Software Foundation; either version 2 of the License, or
1289b765c7SSudhakar Rajashekhara  * (at your option) any later version.
1389b765c7SSudhakar Rajashekhara  *
1489b765c7SSudhakar Rajashekhara  * This program is distributed in the hope that it will be useful,
1589b765c7SSudhakar Rajashekhara  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1689b765c7SSudhakar Rajashekhara  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1789b765c7SSudhakar Rajashekhara  * GNU General Public License for more details.
1889b765c7SSudhakar Rajashekhara  *
1989b765c7SSudhakar Rajashekhara  * You should have received a copy of the GNU General Public License
2089b765c7SSudhakar Rajashekhara  * along with this program; if not, write to the Free Software
2189b765c7SSudhakar Rajashekhara  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2289b765c7SSudhakar Rajashekhara  */
2389b765c7SSudhakar Rajashekhara 
2489b765c7SSudhakar Rajashekhara #include <common.h>
2589b765c7SSudhakar Rajashekhara #include <i2c.h>
263d248d37SBen Gardiner #include <net.h>
273d248d37SBen Gardiner #include <netdev.h>
2889b765c7SSudhakar Rajashekhara #include <asm/arch/hardware.h>
29a3f88293SBen Gardiner #include <asm/arch/emif_defs.h>
303d248d37SBen Gardiner #include <asm/arch/emac_defs.h>
3189b765c7SSudhakar Rajashekhara #include <asm/io.h>
32d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h>
33cf2c24e3SNagabhushana Netagunte #include <hwconfig.h>
3489b765c7SSudhakar Rajashekhara 
3589b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR;
3689b765c7SSudhakar Rajashekhara 
3737adbf9bSPrakash PM #define pinmux(x)	(&davinci_syscfg_regs->pinmux[x])
3889b765c7SSudhakar Rajashekhara 
3989b765c7SSudhakar Rajashekhara /* SPI0 pin muxer settings */
4089b765c7SSudhakar Rajashekhara static const struct pinmux_config spi1_pins[] = {
4137adbf9bSPrakash PM 	{ pinmux(5), 1, 1 },
4237adbf9bSPrakash PM 	{ pinmux(5), 1, 2 },
4337adbf9bSPrakash PM 	{ pinmux(5), 1, 4 },
4437adbf9bSPrakash PM 	{ pinmux(5), 1, 5 }
4589b765c7SSudhakar Rajashekhara };
4689b765c7SSudhakar Rajashekhara 
4789b765c7SSudhakar Rajashekhara /* UART pin muxer settings */
4889b765c7SSudhakar Rajashekhara static const struct pinmux_config uart_pins[] = {
4937adbf9bSPrakash PM 	{ pinmux(0), 4, 6 },
5037adbf9bSPrakash PM 	{ pinmux(0), 4, 7 },
5137adbf9bSPrakash PM 	{ pinmux(4), 2, 4 },
5237adbf9bSPrakash PM 	{ pinmux(4), 2, 5 }
5389b765c7SSudhakar Rajashekhara };
5489b765c7SSudhakar Rajashekhara 
553d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
563d248d37SBen Gardiner static const struct pinmux_config emac_pins[] = {
57d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
58d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 2 },
59d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 3 },
60d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 4 },
61d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 5 },
62d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 6 },
63d2607401SSudhakar Rajashekhara 	{ pinmux(14), 8, 7 },
64d2607401SSudhakar Rajashekhara 	{ pinmux(15), 8, 1 },
65d2607401SSudhakar Rajashekhara #else /* ! CONFIG_DRIVER_TI_EMAC_USE_RMII */
663d248d37SBen Gardiner 	{ pinmux(2), 8, 1 },
673d248d37SBen Gardiner 	{ pinmux(2), 8, 2 },
683d248d37SBen Gardiner 	{ pinmux(2), 8, 3 },
693d248d37SBen Gardiner 	{ pinmux(2), 8, 4 },
703d248d37SBen Gardiner 	{ pinmux(2), 8, 5 },
713d248d37SBen Gardiner 	{ pinmux(2), 8, 6 },
723d248d37SBen Gardiner 	{ pinmux(2), 8, 7 },
733d248d37SBen Gardiner 	{ pinmux(3), 8, 0 },
743d248d37SBen Gardiner 	{ pinmux(3), 8, 1 },
753d248d37SBen Gardiner 	{ pinmux(3), 8, 2 },
763d248d37SBen Gardiner 	{ pinmux(3), 8, 3 },
773d248d37SBen Gardiner 	{ pinmux(3), 8, 4 },
783d248d37SBen Gardiner 	{ pinmux(3), 8, 5 },
793d248d37SBen Gardiner 	{ pinmux(3), 8, 6 },
803d248d37SBen Gardiner 	{ pinmux(3), 8, 7 },
81d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
823d248d37SBen Gardiner 	{ pinmux(4), 8, 0 },
833d248d37SBen Gardiner 	{ pinmux(4), 8, 1 }
843d248d37SBen Gardiner };
853d248d37SBen Gardiner 
8689b765c7SSudhakar Rajashekhara /* I2C pin muxer settings */
8789b765c7SSudhakar Rajashekhara static const struct pinmux_config i2c_pins[] = {
8837adbf9bSPrakash PM 	{ pinmux(4), 2, 2 },
8937adbf9bSPrakash PM 	{ pinmux(4), 2, 3 }
9089b765c7SSudhakar Rajashekhara };
9189b765c7SSudhakar Rajashekhara 
92756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
93756d1fe7SBen Gardiner const struct pinmux_config nand_pins[] = {
94756d1fe7SBen Gardiner 	{ pinmux(7), 1, 1 },
95756d1fe7SBen Gardiner 	{ pinmux(7), 1, 2 },
96756d1fe7SBen Gardiner 	{ pinmux(7), 1, 4 },
97756d1fe7SBen Gardiner 	{ pinmux(7), 1, 5 },
98756d1fe7SBen Gardiner 	{ pinmux(9), 1, 0 },
99756d1fe7SBen Gardiner 	{ pinmux(9), 1, 1 },
100756d1fe7SBen Gardiner 	{ pinmux(9), 1, 2 },
101756d1fe7SBen Gardiner 	{ pinmux(9), 1, 3 },
102756d1fe7SBen Gardiner 	{ pinmux(9), 1, 4 },
103756d1fe7SBen Gardiner 	{ pinmux(9), 1, 5 },
104756d1fe7SBen Gardiner 	{ pinmux(9), 1, 6 },
105756d1fe7SBen Gardiner 	{ pinmux(9), 1, 7 },
106756d1fe7SBen Gardiner 	{ pinmux(12), 1, 5 },
107756d1fe7SBen Gardiner 	{ pinmux(12), 1, 6 }
108756d1fe7SBen Gardiner };
1091506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
1101506b0a8SNagabhushana Netagunte /* NOR pin muxer settings */
1111506b0a8SNagabhushana Netagunte const struct pinmux_config nor_pins[] = {
1120f3d6b06SNagabhushana Netagunte 	/* GP0[11] is required for NOR to work on Rev 3 EVMs */
1130f3d6b06SNagabhushana Netagunte 	{ pinmux(0), 8, 4 },	/* GP0[11] */
1141506b0a8SNagabhushana Netagunte 	{ pinmux(5), 1, 6 },
1151506b0a8SNagabhushana Netagunte 	{ pinmux(6), 1, 6 },
1161506b0a8SNagabhushana Netagunte 	{ pinmux(7), 1, 0 },
1171506b0a8SNagabhushana Netagunte 	{ pinmux(7), 1, 4 },
1181506b0a8SNagabhushana Netagunte 	{ pinmux(7), 1, 5 },
1191506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 0 },
1201506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 1 },
1211506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 2 },
1221506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 3 },
1231506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 4 },
1241506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 5 },
1251506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 6 },
1261506b0a8SNagabhushana Netagunte 	{ pinmux(8), 1, 7 },
1271506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 0 },
1281506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 1 },
1291506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 2 },
1301506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 3 },
1311506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 4 },
1321506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 5 },
1331506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 6 },
1341506b0a8SNagabhushana Netagunte 	{ pinmux(9), 1, 7 },
1351506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 0 },
1361506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 1 },
1371506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 2 },
1381506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 3 },
1391506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 4 },
1401506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 5 },
1411506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 6 },
1421506b0a8SNagabhushana Netagunte 	{ pinmux(10), 1, 7 },
1431506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 0 },
1441506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 1 },
1451506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 2 },
1461506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 3 },
1471506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 4 },
1481506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 5 },
1491506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 6 },
1501506b0a8SNagabhushana Netagunte 	{ pinmux(11), 1, 7 },
1511506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 0 },
1521506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 1 },
1531506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 2 },
1541506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 3 },
1551506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 4 },
1561506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 5 },
1571506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 6 },
1581506b0a8SNagabhushana Netagunte 	{ pinmux(12), 1, 7 }
1591506b0a8SNagabhushana Netagunte };
160756d1fe7SBen Gardiner #endif
161756d1fe7SBen Gardiner 
162d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
163d2607401SSudhakar Rajashekhara #define HAS_RMII 1
164d2607401SSudhakar Rajashekhara #else
165d2607401SSudhakar Rajashekhara #define HAS_RMII 0
166d2607401SSudhakar Rajashekhara #endif
167d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */
168d2607401SSudhakar Rajashekhara 
169cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
170cf2c24e3SNagabhushana Netagunte {
171cf2c24e3SNagabhushana Netagunte 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
172cf2c24e3SNagabhushana Netagunte 	struct davinci_psc_regs *psc_regs;
173cf2c24e3SNagabhushana Netagunte 
174cf2c24e3SNagabhushana Netagunte 	psc_regs = davinci_psc0_regs;
175cf2c24e3SNagabhushana Netagunte 	mdstat = &psc_regs->psc0.mdstat[id];
176cf2c24e3SNagabhushana Netagunte 	mdctl = &psc_regs->psc0.mdctl[id];
177cf2c24e3SNagabhushana Netagunte 	ptstat = &psc_regs->ptstat;
178cf2c24e3SNagabhushana Netagunte 	ptcmd = &psc_regs->ptcmd;
179cf2c24e3SNagabhushana Netagunte 
180cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
181cf2c24e3SNagabhushana Netagunte 		;
182cf2c24e3SNagabhushana Netagunte 
183cf2c24e3SNagabhushana Netagunte 	if ((*mdstat & 0x1f) == 0x03)
184cf2c24e3SNagabhushana Netagunte 		return;                 /* Already on and enabled */
185cf2c24e3SNagabhushana Netagunte 
186cf2c24e3SNagabhushana Netagunte 	*mdctl |= 0x03;
187cf2c24e3SNagabhushana Netagunte 
188cf2c24e3SNagabhushana Netagunte 	*ptcmd = 0x1 << domain;
189cf2c24e3SNagabhushana Netagunte 
190cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
191cf2c24e3SNagabhushana Netagunte 		;
192cf2c24e3SNagabhushana Netagunte 	while ((*mdstat & 0x1f) != 0x03)
193cf2c24e3SNagabhushana Netagunte 		;		/* Probably an overkill... */
194cf2c24e3SNagabhushana Netagunte }
195cf2c24e3SNagabhushana Netagunte 
196cf2c24e3SNagabhushana Netagunte static void dspwake(void)
197cf2c24e3SNagabhushana Netagunte {
198cf2c24e3SNagabhushana Netagunte 	unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
199cf2c24e3SNagabhushana Netagunte 	u32 val;
200cf2c24e3SNagabhushana Netagunte 
201cf2c24e3SNagabhushana Netagunte 	/* if the device is ARM only, return */
202cf2c24e3SNagabhushana Netagunte 	if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
203cf2c24e3SNagabhushana Netagunte 		return;
204cf2c24e3SNagabhushana Netagunte 
205cf2c24e3SNagabhushana Netagunte 	if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
206cf2c24e3SNagabhushana Netagunte 		return;
207cf2c24e3SNagabhushana Netagunte 
208cf2c24e3SNagabhushana Netagunte 	*resetvect++ = 0x1E000; /* DSP Idle */
209cf2c24e3SNagabhushana Netagunte 	/* clear out the next 10 words as NOP */
210cf2c24e3SNagabhushana Netagunte 	memset(resetvect, 0, sizeof(unsigned) *10);
211cf2c24e3SNagabhushana Netagunte 
212cf2c24e3SNagabhushana Netagunte 	/* setup the DSP reset vector */
213cf2c24e3SNagabhushana Netagunte 	writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
214cf2c24e3SNagabhushana Netagunte 
215cf2c24e3SNagabhushana Netagunte 	dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
216cf2c24e3SNagabhushana Netagunte 	val = readl(PSC0_MDCTL + (15 * 4));
217cf2c24e3SNagabhushana Netagunte 	val |= 0x100;
218cf2c24e3SNagabhushana Netagunte 	writel(val, (PSC0_MDCTL + (15 * 4)));
219cf2c24e3SNagabhushana Netagunte }
220cf2c24e3SNagabhushana Netagunte 
221cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
222cf2c24e3SNagabhushana Netagunte {
223cf2c24e3SNagabhushana Netagunte 	dspwake();
224cf2c24e3SNagabhushana Netagunte 	return 0;
225cf2c24e3SNagabhushana Netagunte }
226cf2c24e3SNagabhushana Netagunte 
22789b765c7SSudhakar Rajashekhara static const struct pinmux_resource pinmuxes[] = {
22889b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
22989b765c7SSudhakar Rajashekhara 	PINMUX_ITEM(spi1_pins),
23089b765c7SSudhakar Rajashekhara #endif
23189b765c7SSudhakar Rajashekhara 	PINMUX_ITEM(uart_pins),
23289b765c7SSudhakar Rajashekhara 	PINMUX_ITEM(i2c_pins),
233756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
234756d1fe7SBen Gardiner 	PINMUX_ITEM(nand_pins),
2351506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
2361506b0a8SNagabhushana Netagunte 	PINMUX_ITEM(nor_pins),
237756d1fe7SBen Gardiner #endif
23889b765c7SSudhakar Rajashekhara };
23989b765c7SSudhakar Rajashekhara 
24089b765c7SSudhakar Rajashekhara static const struct lpsc_resource lpsc[] = {
24189b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
24289b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
24389b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_EMAC },	/* image download */
24489b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_UART2 },	/* console */
24589b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_GPIO },
24689b765c7SSudhakar Rajashekhara };
24789b765c7SSudhakar Rajashekhara 
2484f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
2494f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK	300000000
2504f6fc15bSSekhar Nori #endif
2514f6fc15bSSekhar Nori 
2524f6fc15bSSekhar Nori /*
2534f6fc15bSSekhar Nori  * get_board_rev() - setup to pass kernel board revision information
2544f6fc15bSSekhar Nori  * Returns:
2554f6fc15bSSekhar Nori  * bit[0-3]	Maximum cpu clock rate supported by onboard SoC
2564f6fc15bSSekhar Nori  *		0000b - 300 MHz
2574f6fc15bSSekhar Nori  *		0001b - 372 MHz
2584f6fc15bSSekhar Nori  *		0010b - 408 MHz
2594f6fc15bSSekhar Nori  *		0011b - 456 MHz
2604f6fc15bSSekhar Nori  */
2614f6fc15bSSekhar Nori u32 get_board_rev(void)
2624f6fc15bSSekhar Nori {
2634f6fc15bSSekhar Nori 	char *s;
2644f6fc15bSSekhar Nori 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
2654f6fc15bSSekhar Nori 	u32 rev = 0;
2664f6fc15bSSekhar Nori 
2674f6fc15bSSekhar Nori 	s = getenv("maxcpuclk");
2684f6fc15bSSekhar Nori 	if (s)
2694f6fc15bSSekhar Nori 		maxcpuclk = simple_strtoul(s, NULL, 10);
2704f6fc15bSSekhar Nori 
2714f6fc15bSSekhar Nori 	if (maxcpuclk >= 456000000)
2724f6fc15bSSekhar Nori 		rev = 3;
2734f6fc15bSSekhar Nori 	else if (maxcpuclk >= 408000000)
2744f6fc15bSSekhar Nori 		rev = 2;
2754f6fc15bSSekhar Nori 	else if (maxcpuclk >= 372000000)
2764f6fc15bSSekhar Nori 		rev = 1;
2774f6fc15bSSekhar Nori 
2784f6fc15bSSekhar Nori 	return rev;
2794f6fc15bSSekhar Nori }
2804f6fc15bSSekhar Nori 
28189b765c7SSudhakar Rajashekhara int board_init(void)
28289b765c7SSudhakar Rajashekhara {
283*6f0d7ae2SWolfgang Denk #ifdef CONFIG_USE_NOR
2840f3d6b06SNagabhushana Netagunte 	u32 val;
285*6f0d7ae2SWolfgang Denk #endif
286*6f0d7ae2SWolfgang Denk 
28789b765c7SSudhakar Rajashekhara #ifndef CONFIG_USE_IRQ
28889b765c7SSudhakar Rajashekhara 	irq_init();
28989b765c7SSudhakar Rajashekhara #endif
29089b765c7SSudhakar Rajashekhara 
291a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
292a3f88293SBen Gardiner 	/*
293a3f88293SBen Gardiner 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
294a3f88293SBen Gardiner 	 * Linux kernel @ 25MHz EMIFA
295a3f88293SBen Gardiner 	 */
296a3f88293SBen Gardiner 	writel((DAVINCI_ABCR_WSETUP(0) |
29724a514c4SBen Gardiner 		DAVINCI_ABCR_WSTROBE(1) |
298a3f88293SBen Gardiner 		DAVINCI_ABCR_WHOLD(0) |
299a3f88293SBen Gardiner 		DAVINCI_ABCR_RSETUP(0) |
300a3f88293SBen Gardiner 		DAVINCI_ABCR_RSTROBE(1) |
301a3f88293SBen Gardiner 		DAVINCI_ABCR_RHOLD(0) |
30224a514c4SBen Gardiner 		DAVINCI_ABCR_TA(1) |
303a3f88293SBen Gardiner 		DAVINCI_ABCR_ASIZE_8BIT),
304a3f88293SBen Gardiner 	       &davinci_emif_regs->ab2cr); /* CS3 */
305a3f88293SBen Gardiner #endif
306a3f88293SBen Gardiner 
30789b765c7SSudhakar Rajashekhara 	/* arch number of the board */
30889b765c7SSudhakar Rajashekhara 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
30989b765c7SSudhakar Rajashekhara 
31089b765c7SSudhakar Rajashekhara 	/* address of boot parameters */
31189b765c7SSudhakar Rajashekhara 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
31289b765c7SSudhakar Rajashekhara 
31389b765c7SSudhakar Rajashekhara 	/*
31489b765c7SSudhakar Rajashekhara 	 * Power on required peripherals
31589b765c7SSudhakar Rajashekhara 	 * ARM does not have access by default to PSC0 and PSC1
31689b765c7SSudhakar Rajashekhara 	 * assuming here that the DSP bootloader has set the IOPU
31789b765c7SSudhakar Rajashekhara 	 * such that PSC access is available to ARM
31889b765c7SSudhakar Rajashekhara 	 */
31989b765c7SSudhakar Rajashekhara 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
32089b765c7SSudhakar Rajashekhara 		return 1;
32189b765c7SSudhakar Rajashekhara 
32289b765c7SSudhakar Rajashekhara 	/* setup the SUSPSRC for ARM to control emulation suspend */
32389b765c7SSudhakar Rajashekhara 	writel(readl(&davinci_syscfg_regs->suspsrc) &
32489b765c7SSudhakar Rajashekhara 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
32589b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
32689b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_UART2),
32789b765c7SSudhakar Rajashekhara 	       &davinci_syscfg_regs->suspsrc);
32889b765c7SSudhakar Rajashekhara 
32989b765c7SSudhakar Rajashekhara 	/* configure pinmux settings */
33089b765c7SSudhakar Rajashekhara 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
33189b765c7SSudhakar Rajashekhara 		return 1;
33289b765c7SSudhakar Rajashekhara 
3330f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
3340f3d6b06SNagabhushana Netagunte 	/* Set the GPIO direction as output */
3350f3d6b06SNagabhushana Netagunte 	clrbits_be32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3360f3d6b06SNagabhushana Netagunte 
3370f3d6b06SNagabhushana Netagunte 	/* Set the output as low */
3380f3d6b06SNagabhushana Netagunte 	val = readl(GPIO_BANK0_REG_SET_ADDR);
3390f3d6b06SNagabhushana Netagunte 	val |= (0x01 << 11);
3400f3d6b06SNagabhushana Netagunte 	writel(val, GPIO_BANK0_REG_CLR_ADDR);
3410f3d6b06SNagabhushana Netagunte #endif
3420f3d6b06SNagabhushana Netagunte 
3433d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3443d248d37SBen Gardiner 	if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
3453d248d37SBen Gardiner 		return 1;
346d2607401SSudhakar Rajashekhara 
3476d1c649fSStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
3483d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
3493d248d37SBen Gardiner 
35089b765c7SSudhakar Rajashekhara 	/* enable the console UART */
35189b765c7SSudhakar Rajashekhara 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
35289b765c7SSudhakar Rajashekhara 		DAVINCI_UART_PWREMU_MGMT_UTRST),
35389b765c7SSudhakar Rajashekhara 	       &davinci_uart2_ctrl_regs->pwremu_mgmt);
35489b765c7SSudhakar Rajashekhara 
35589b765c7SSudhakar Rajashekhara 	return 0;
35689b765c7SSudhakar Rajashekhara }
3573d248d37SBen Gardiner 
3583d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3593d248d37SBen Gardiner 
360d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
361d2607401SSudhakar Rajashekhara /**
362d2607401SSudhakar Rajashekhara  * rmii_hw_init
363d2607401SSudhakar Rajashekhara  *
364d2607401SSudhakar Rajashekhara  * DA850/OMAP-L138 EVM can interface to a daughter card for
365d2607401SSudhakar Rajashekhara  * additional features. This card has an I2C GPIO Expander TCA6416
366d2607401SSudhakar Rajashekhara  * to select the required functions like camera, RMII Ethernet,
367d2607401SSudhakar Rajashekhara  * character LCD, video.
368d2607401SSudhakar Rajashekhara  *
369d2607401SSudhakar Rajashekhara  * Initialization of the expander involves configuring the
370d2607401SSudhakar Rajashekhara  * polarity and direction of the ports. P07-P05 are used here.
371d2607401SSudhakar Rajashekhara  * These ports are connected to a Mux chip which enables only one
372d2607401SSudhakar Rajashekhara  * functionality at a time.
373d2607401SSudhakar Rajashekhara  *
374d2607401SSudhakar Rajashekhara  * For RMII phy to respond, the MII MDIO clock has to be  disabled
375d2607401SSudhakar Rajashekhara  * since both the PHY devices have address as zero. The MII MDIO
376d2607401SSudhakar Rajashekhara  * clock is controlled via GPIO2[6].
377d2607401SSudhakar Rajashekhara  *
378d2607401SSudhakar Rajashekhara  * This code is valid for Beta version of the hardware
379d2607401SSudhakar Rajashekhara  */
380d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
381d2607401SSudhakar Rajashekhara {
382d2607401SSudhakar Rajashekhara 	const struct pinmux_config gpio_pins[] = {
383d2607401SSudhakar Rajashekhara 		{ pinmux(6), 8, 1 }
384d2607401SSudhakar Rajashekhara 	};
385d2607401SSudhakar Rajashekhara 	u_int8_t buf[2];
386d2607401SSudhakar Rajashekhara 	unsigned int temp;
387d2607401SSudhakar Rajashekhara 	int ret;
388d2607401SSudhakar Rajashekhara 
389d2607401SSudhakar Rajashekhara 	/* PinMux for GPIO */
390d2607401SSudhakar Rajashekhara 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
391d2607401SSudhakar Rajashekhara 		return 1;
392d2607401SSudhakar Rajashekhara 
393d2607401SSudhakar Rajashekhara 	/* I2C Exapnder configuration */
394d2607401SSudhakar Rajashekhara 	/* Set polarity to non-inverted */
395d2607401SSudhakar Rajashekhara 	buf[0] = 0x0;
396d2607401SSudhakar Rajashekhara 	buf[1] = 0x0;
397d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
398d2607401SSudhakar Rajashekhara 	if (ret) {
399d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
400d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
401d2607401SSudhakar Rajashekhara 		return ret;
402d2607401SSudhakar Rajashekhara 	}
403d2607401SSudhakar Rajashekhara 
404d2607401SSudhakar Rajashekhara 	/* Configure P07-P05 as outputs */
405d2607401SSudhakar Rajashekhara 	buf[0] = 0x1f;
406d2607401SSudhakar Rajashekhara 	buf[1] = 0xff;
407d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
408d2607401SSudhakar Rajashekhara 	if (ret) {
409d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
410d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
411d2607401SSudhakar Rajashekhara 	}
412d2607401SSudhakar Rajashekhara 
413d2607401SSudhakar Rajashekhara 	/* For Ethernet RMII selection
414d2607401SSudhakar Rajashekhara 	 * P07(SelA)=0
415d2607401SSudhakar Rajashekhara 	 * P06(SelB)=1
416d2607401SSudhakar Rajashekhara 	 * P05(SelC)=1
417d2607401SSudhakar Rajashekhara 	 */
418d2607401SSudhakar Rajashekhara 	if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
419d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x read FAILED!!!\n",
420d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
421d2607401SSudhakar Rajashekhara 	}
422d2607401SSudhakar Rajashekhara 
423d2607401SSudhakar Rajashekhara 	buf[0] &= 0x1f;
424d2607401SSudhakar Rajashekhara 	buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
425d2607401SSudhakar Rajashekhara 	if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
426d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
427d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
428d2607401SSudhakar Rajashekhara 	}
429d2607401SSudhakar Rajashekhara 
430d2607401SSudhakar Rajashekhara 	/* Set the output as high */
431d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_SET_ADDR);
432d2607401SSudhakar Rajashekhara 	temp |= (0x01 << 6);
433d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_SET_ADDR) = temp;
434d2607401SSudhakar Rajashekhara 
435d2607401SSudhakar Rajashekhara 	/* Set the GPIO direction as output */
436d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_DIR_ADDR);
437d2607401SSudhakar Rajashekhara 	temp &= ~(0x01 << 6);
438d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
439d2607401SSudhakar Rajashekhara 
440d2607401SSudhakar Rajashekhara 	return 0;
441d2607401SSudhakar Rajashekhara }
442d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
443d2607401SSudhakar Rajashekhara 
4443d248d37SBen Gardiner /*
4453d248d37SBen Gardiner  * Initializes on-board ethernet controllers.
4463d248d37SBen Gardiner  */
4473d248d37SBen Gardiner int board_eth_init(bd_t *bis)
4483d248d37SBen Gardiner {
449d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
450d2607401SSudhakar Rajashekhara 	/* Select RMII fucntion through the expander */
451d2607401SSudhakar Rajashekhara 	if (rmii_hw_init())
452d2607401SSudhakar Rajashekhara 		printf("RMII hardware init failed!!!\n");
453d2607401SSudhakar Rajashekhara #endif
4543d248d37SBen Gardiner 	if (!davinci_emac_initialize()) {
4553d248d37SBen Gardiner 		printf("Error: Ethernet init failed!\n");
4563d248d37SBen Gardiner 		return -1;
4573d248d37SBen Gardiner 	}
4583d248d37SBen Gardiner 
4593d248d37SBen Gardiner 	return 0;
4603d248d37SBen Gardiner }
4613d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
462