xref: /openbmc/u-boot/board/davinci/da8xxevm/da850evm.c (revision 6b873dcabd85ca4109a76c488c653609ea71c848)
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>
3152b0f877SChristian Riesch #include <asm/arch/pinmux_defs.h>
3289b765c7SSudhakar Rajashekhara #include <asm/io.h>
33d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h>
34cf2c24e3SNagabhushana Netagunte #include <hwconfig.h>
3589b765c7SSudhakar Rajashekhara 
3689b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR;
3789b765c7SSudhakar Rajashekhara 
383d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
39d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
40d2607401SSudhakar Rajashekhara #define HAS_RMII 1
41d2607401SSudhakar Rajashekhara #else
42d2607401SSudhakar Rajashekhara #define HAS_RMII 0
43d2607401SSudhakar Rajashekhara #endif
44d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */
45d2607401SSudhakar Rajashekhara 
46cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
47cf2c24e3SNagabhushana Netagunte {
48cf2c24e3SNagabhushana Netagunte 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
49cf2c24e3SNagabhushana Netagunte 	struct davinci_psc_regs *psc_regs;
50cf2c24e3SNagabhushana Netagunte 
51cf2c24e3SNagabhushana Netagunte 	psc_regs = davinci_psc0_regs;
52cf2c24e3SNagabhushana Netagunte 	mdstat = &psc_regs->psc0.mdstat[id];
53cf2c24e3SNagabhushana Netagunte 	mdctl = &psc_regs->psc0.mdctl[id];
54cf2c24e3SNagabhushana Netagunte 	ptstat = &psc_regs->ptstat;
55cf2c24e3SNagabhushana Netagunte 	ptcmd = &psc_regs->ptcmd;
56cf2c24e3SNagabhushana Netagunte 
57cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
58cf2c24e3SNagabhushana Netagunte 		;
59cf2c24e3SNagabhushana Netagunte 
60cf2c24e3SNagabhushana Netagunte 	if ((*mdstat & 0x1f) == 0x03)
61cf2c24e3SNagabhushana Netagunte 		return;                 /* Already on and enabled */
62cf2c24e3SNagabhushana Netagunte 
63cf2c24e3SNagabhushana Netagunte 	*mdctl |= 0x03;
64cf2c24e3SNagabhushana Netagunte 
65cf2c24e3SNagabhushana Netagunte 	*ptcmd = 0x1 << domain;
66cf2c24e3SNagabhushana Netagunte 
67cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
68cf2c24e3SNagabhushana Netagunte 		;
69cf2c24e3SNagabhushana Netagunte 	while ((*mdstat & 0x1f) != 0x03)
70cf2c24e3SNagabhushana Netagunte 		;		/* Probably an overkill... */
71cf2c24e3SNagabhushana Netagunte }
72cf2c24e3SNagabhushana Netagunte 
73cf2c24e3SNagabhushana Netagunte static void dspwake(void)
74cf2c24e3SNagabhushana Netagunte {
75cf2c24e3SNagabhushana Netagunte 	unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
76cf2c24e3SNagabhushana Netagunte 	u32 val;
77cf2c24e3SNagabhushana Netagunte 
78cf2c24e3SNagabhushana Netagunte 	/* if the device is ARM only, return */
79cf2c24e3SNagabhushana Netagunte 	if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
80cf2c24e3SNagabhushana Netagunte 		return;
81cf2c24e3SNagabhushana Netagunte 
82cf2c24e3SNagabhushana Netagunte 	if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
83cf2c24e3SNagabhushana Netagunte 		return;
84cf2c24e3SNagabhushana Netagunte 
85cf2c24e3SNagabhushana Netagunte 	*resetvect++ = 0x1E000; /* DSP Idle */
86cf2c24e3SNagabhushana Netagunte 	/* clear out the next 10 words as NOP */
87cf2c24e3SNagabhushana Netagunte 	memset(resetvect, 0, sizeof(unsigned) *10);
88cf2c24e3SNagabhushana Netagunte 
89cf2c24e3SNagabhushana Netagunte 	/* setup the DSP reset vector */
90cf2c24e3SNagabhushana Netagunte 	writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
91cf2c24e3SNagabhushana Netagunte 
92cf2c24e3SNagabhushana Netagunte 	dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
93cf2c24e3SNagabhushana Netagunte 	val = readl(PSC0_MDCTL + (15 * 4));
94cf2c24e3SNagabhushana Netagunte 	val |= 0x100;
95cf2c24e3SNagabhushana Netagunte 	writel(val, (PSC0_MDCTL + (15 * 4)));
96cf2c24e3SNagabhushana Netagunte }
97cf2c24e3SNagabhushana Netagunte 
98cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
99cf2c24e3SNagabhushana Netagunte {
100cf2c24e3SNagabhushana Netagunte 	dspwake();
101cf2c24e3SNagabhushana Netagunte 	return 0;
102cf2c24e3SNagabhushana Netagunte }
103cf2c24e3SNagabhushana Netagunte 
10452b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = {
10552b0f877SChristian Riesch #ifdef CONFIG_USE_NOR
10652b0f877SChristian Riesch 	/* GP0[11] is required for NOR to work on Rev 3 EVMs */
10752b0f877SChristian Riesch 	{ pinmux(0), 8, 4 },	/* GP0[11] */
10852b0f877SChristian Riesch #endif
10952b0f877SChristian Riesch };
11052b0f877SChristian Riesch 
1113d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = {
112591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC
11352b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mdio),
11452b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
11552b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_rmii),
11652b0f877SChristian Riesch #else
11752b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mii),
11852b0f877SChristian Riesch #endif
119591d8019SChristian Riesch #endif
12089b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
12152b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_base),
12252b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_scs0),
12389b765c7SSudhakar Rajashekhara #endif
12452b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_txrx),
12552b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_rtscts),
12652b0f877SChristian Riesch 	PINMUX_ITEM(i2c0_pins),
127756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
12852b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs3),
12952b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs4),
13052b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nand),
1311506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
13252b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs2),
13352b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nor),
134756d1fe7SBen Gardiner #endif
13552b0f877SChristian Riesch 	PINMUX_ITEM(gpio_pins),
13689b765c7SSudhakar Rajashekhara };
13789b765c7SSudhakar Rajashekhara 
1383d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
1393d2c8e6cSChristian Riesch 
140*6b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = {
14189b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
14289b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
14389b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_EMAC },	/* image download */
14489b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_UART2 },	/* console */
14589b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_GPIO },
14689b765c7SSudhakar Rajashekhara };
14789b765c7SSudhakar Rajashekhara 
148*6b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc);
149*6b873dcaSSughosh Ganu 
1504f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
1514f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK	300000000
1524f6fc15bSSekhar Nori #endif
1534f6fc15bSSekhar Nori 
154754f8cb6SManjunath Hadli #define REV_AM18X_EVM		0x100
155754f8cb6SManjunath Hadli 
1564f6fc15bSSekhar Nori /*
1574f6fc15bSSekhar Nori  * get_board_rev() - setup to pass kernel board revision information
1584f6fc15bSSekhar Nori  * Returns:
1594f6fc15bSSekhar Nori  * bit[0-3]	Maximum cpu clock rate supported by onboard SoC
1604f6fc15bSSekhar Nori  *		0000b - 300 MHz
1614f6fc15bSSekhar Nori  *		0001b - 372 MHz
1624f6fc15bSSekhar Nori  *		0010b - 408 MHz
1634f6fc15bSSekhar Nori  *		0011b - 456 MHz
1644f6fc15bSSekhar Nori  */
1654f6fc15bSSekhar Nori u32 get_board_rev(void)
1664f6fc15bSSekhar Nori {
1674f6fc15bSSekhar Nori 	char *s;
1684f6fc15bSSekhar Nori 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
1694f6fc15bSSekhar Nori 	u32 rev = 0;
1704f6fc15bSSekhar Nori 
1714f6fc15bSSekhar Nori 	s = getenv("maxcpuclk");
1724f6fc15bSSekhar Nori 	if (s)
1734f6fc15bSSekhar Nori 		maxcpuclk = simple_strtoul(s, NULL, 10);
1744f6fc15bSSekhar Nori 
1754f6fc15bSSekhar Nori 	if (maxcpuclk >= 456000000)
1764f6fc15bSSekhar Nori 		rev = 3;
1774f6fc15bSSekhar Nori 	else if (maxcpuclk >= 408000000)
1784f6fc15bSSekhar Nori 		rev = 2;
1794f6fc15bSSekhar Nori 	else if (maxcpuclk >= 372000000)
1804f6fc15bSSekhar Nori 		rev = 1;
181754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM
182754f8cb6SManjunath Hadli 	rev |= REV_AM18X_EVM;
183754f8cb6SManjunath Hadli #endif
1844f6fc15bSSekhar Nori 	return rev;
1854f6fc15bSSekhar Nori }
1864f6fc15bSSekhar Nori 
187ae5c77ddSChristian Riesch int board_early_init_f(void)
188ae5c77ddSChristian Riesch {
189ae5c77ddSChristian Riesch 	/*
190ae5c77ddSChristian Riesch 	 * Power on required peripherals
191ae5c77ddSChristian Riesch 	 * ARM does not have access by default to PSC0 and PSC1
192ae5c77ddSChristian Riesch 	 * assuming here that the DSP bootloader has set the IOPU
193ae5c77ddSChristian Riesch 	 * such that PSC access is available to ARM
194ae5c77ddSChristian Riesch 	 */
195ae5c77ddSChristian Riesch 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
196ae5c77ddSChristian Riesch 		return 1;
197ae5c77ddSChristian Riesch 
198ae5c77ddSChristian Riesch 	return 0;
199ae5c77ddSChristian Riesch }
200ae5c77ddSChristian Riesch 
20189b765c7SSudhakar Rajashekhara int board_init(void)
20289b765c7SSudhakar Rajashekhara {
2036f0d7ae2SWolfgang Denk #ifdef CONFIG_USE_NOR
2040f3d6b06SNagabhushana Netagunte 	u32 val;
2056f0d7ae2SWolfgang Denk #endif
2066f0d7ae2SWolfgang Denk 
20789b765c7SSudhakar Rajashekhara #ifndef CONFIG_USE_IRQ
20889b765c7SSudhakar Rajashekhara 	irq_init();
20989b765c7SSudhakar Rajashekhara #endif
21089b765c7SSudhakar Rajashekhara 
211a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
212a3f88293SBen Gardiner 	/*
213a3f88293SBen Gardiner 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
214a3f88293SBen Gardiner 	 * Linux kernel @ 25MHz EMIFA
215a3f88293SBen Gardiner 	 */
216a3f88293SBen Gardiner 	writel((DAVINCI_ABCR_WSETUP(0) |
21724a514c4SBen Gardiner 		DAVINCI_ABCR_WSTROBE(1) |
218a3f88293SBen Gardiner 		DAVINCI_ABCR_WHOLD(0) |
219a3f88293SBen Gardiner 		DAVINCI_ABCR_RSETUP(0) |
220a3f88293SBen Gardiner 		DAVINCI_ABCR_RSTROBE(1) |
221a3f88293SBen Gardiner 		DAVINCI_ABCR_RHOLD(0) |
22224a514c4SBen Gardiner 		DAVINCI_ABCR_TA(1) |
223a3f88293SBen Gardiner 		DAVINCI_ABCR_ASIZE_8BIT),
224a3f88293SBen Gardiner 	       &davinci_emif_regs->ab2cr); /* CS3 */
225a3f88293SBen Gardiner #endif
226a3f88293SBen Gardiner 
22789b765c7SSudhakar Rajashekhara 	/* arch number of the board */
22889b765c7SSudhakar Rajashekhara 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
22989b765c7SSudhakar Rajashekhara 
23089b765c7SSudhakar Rajashekhara 	/* address of boot parameters */
23189b765c7SSudhakar Rajashekhara 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
23289b765c7SSudhakar Rajashekhara 
23389b765c7SSudhakar Rajashekhara 	/* setup the SUSPSRC for ARM to control emulation suspend */
23489b765c7SSudhakar Rajashekhara 	writel(readl(&davinci_syscfg_regs->suspsrc) &
23589b765c7SSudhakar Rajashekhara 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
23689b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
23789b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_UART2),
23889b765c7SSudhakar Rajashekhara 	       &davinci_syscfg_regs->suspsrc);
23989b765c7SSudhakar Rajashekhara 
24089b765c7SSudhakar Rajashekhara 	/* configure pinmux settings */
24189b765c7SSudhakar Rajashekhara 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
24289b765c7SSudhakar Rajashekhara 		return 1;
24389b765c7SSudhakar Rajashekhara 
2440f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
2450f3d6b06SNagabhushana Netagunte 	/* Set the GPIO direction as output */
2460f3d6b06SNagabhushana Netagunte 	clrbits_be32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
2470f3d6b06SNagabhushana Netagunte 
2480f3d6b06SNagabhushana Netagunte 	/* Set the output as low */
2490f3d6b06SNagabhushana Netagunte 	val = readl(GPIO_BANK0_REG_SET_ADDR);
2500f3d6b06SNagabhushana Netagunte 	val |= (0x01 << 11);
2510f3d6b06SNagabhushana Netagunte 	writel(val, GPIO_BANK0_REG_CLR_ADDR);
2520f3d6b06SNagabhushana Netagunte #endif
2530f3d6b06SNagabhushana Netagunte 
2543d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
2556d1c649fSStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
2563d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
2573d248d37SBen Gardiner 
25889b765c7SSudhakar Rajashekhara 	/* enable the console UART */
25989b765c7SSudhakar Rajashekhara 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
26089b765c7SSudhakar Rajashekhara 		DAVINCI_UART_PWREMU_MGMT_UTRST),
26189b765c7SSudhakar Rajashekhara 	       &davinci_uart2_ctrl_regs->pwremu_mgmt);
26289b765c7SSudhakar Rajashekhara 
26389b765c7SSudhakar Rajashekhara 	return 0;
26489b765c7SSudhakar Rajashekhara }
2653d248d37SBen Gardiner 
2663d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
2673d248d37SBen Gardiner 
268d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
269d2607401SSudhakar Rajashekhara /**
270d2607401SSudhakar Rajashekhara  * rmii_hw_init
271d2607401SSudhakar Rajashekhara  *
272d2607401SSudhakar Rajashekhara  * DA850/OMAP-L138 EVM can interface to a daughter card for
273d2607401SSudhakar Rajashekhara  * additional features. This card has an I2C GPIO Expander TCA6416
274d2607401SSudhakar Rajashekhara  * to select the required functions like camera, RMII Ethernet,
275d2607401SSudhakar Rajashekhara  * character LCD, video.
276d2607401SSudhakar Rajashekhara  *
277d2607401SSudhakar Rajashekhara  * Initialization of the expander involves configuring the
278d2607401SSudhakar Rajashekhara  * polarity and direction of the ports. P07-P05 are used here.
279d2607401SSudhakar Rajashekhara  * These ports are connected to a Mux chip which enables only one
280d2607401SSudhakar Rajashekhara  * functionality at a time.
281d2607401SSudhakar Rajashekhara  *
282d2607401SSudhakar Rajashekhara  * For RMII phy to respond, the MII MDIO clock has to be  disabled
283d2607401SSudhakar Rajashekhara  * since both the PHY devices have address as zero. The MII MDIO
284d2607401SSudhakar Rajashekhara  * clock is controlled via GPIO2[6].
285d2607401SSudhakar Rajashekhara  *
286d2607401SSudhakar Rajashekhara  * This code is valid for Beta version of the hardware
287d2607401SSudhakar Rajashekhara  */
288d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
289d2607401SSudhakar Rajashekhara {
290d2607401SSudhakar Rajashekhara 	const struct pinmux_config gpio_pins[] = {
291d2607401SSudhakar Rajashekhara 		{ pinmux(6), 8, 1 }
292d2607401SSudhakar Rajashekhara 	};
293d2607401SSudhakar Rajashekhara 	u_int8_t buf[2];
294d2607401SSudhakar Rajashekhara 	unsigned int temp;
295d2607401SSudhakar Rajashekhara 	int ret;
296d2607401SSudhakar Rajashekhara 
297d2607401SSudhakar Rajashekhara 	/* PinMux for GPIO */
298d2607401SSudhakar Rajashekhara 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
299d2607401SSudhakar Rajashekhara 		return 1;
300d2607401SSudhakar Rajashekhara 
301d2607401SSudhakar Rajashekhara 	/* I2C Exapnder configuration */
302d2607401SSudhakar Rajashekhara 	/* Set polarity to non-inverted */
303d2607401SSudhakar Rajashekhara 	buf[0] = 0x0;
304d2607401SSudhakar Rajashekhara 	buf[1] = 0x0;
305d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
306d2607401SSudhakar Rajashekhara 	if (ret) {
307d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
308d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
309d2607401SSudhakar Rajashekhara 		return ret;
310d2607401SSudhakar Rajashekhara 	}
311d2607401SSudhakar Rajashekhara 
312d2607401SSudhakar Rajashekhara 	/* Configure P07-P05 as outputs */
313d2607401SSudhakar Rajashekhara 	buf[0] = 0x1f;
314d2607401SSudhakar Rajashekhara 	buf[1] = 0xff;
315d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
316d2607401SSudhakar Rajashekhara 	if (ret) {
317d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
318d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
319d2607401SSudhakar Rajashekhara 	}
320d2607401SSudhakar Rajashekhara 
321d2607401SSudhakar Rajashekhara 	/* For Ethernet RMII selection
322d2607401SSudhakar Rajashekhara 	 * P07(SelA)=0
323d2607401SSudhakar Rajashekhara 	 * P06(SelB)=1
324d2607401SSudhakar Rajashekhara 	 * P05(SelC)=1
325d2607401SSudhakar Rajashekhara 	 */
326d2607401SSudhakar Rajashekhara 	if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
327d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x read FAILED!!!\n",
328d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
329d2607401SSudhakar Rajashekhara 	}
330d2607401SSudhakar Rajashekhara 
331d2607401SSudhakar Rajashekhara 	buf[0] &= 0x1f;
332d2607401SSudhakar Rajashekhara 	buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
333d2607401SSudhakar Rajashekhara 	if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
334d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
335d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
336d2607401SSudhakar Rajashekhara 	}
337d2607401SSudhakar Rajashekhara 
338d2607401SSudhakar Rajashekhara 	/* Set the output as high */
339d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_SET_ADDR);
340d2607401SSudhakar Rajashekhara 	temp |= (0x01 << 6);
341d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_SET_ADDR) = temp;
342d2607401SSudhakar Rajashekhara 
343d2607401SSudhakar Rajashekhara 	/* Set the GPIO direction as output */
344d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_DIR_ADDR);
345d2607401SSudhakar Rajashekhara 	temp &= ~(0x01 << 6);
346d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
347d2607401SSudhakar Rajashekhara 
348d2607401SSudhakar Rajashekhara 	return 0;
349d2607401SSudhakar Rajashekhara }
350d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
351d2607401SSudhakar Rajashekhara 
3523d248d37SBen Gardiner /*
3533d248d37SBen Gardiner  * Initializes on-board ethernet controllers.
3543d248d37SBen Gardiner  */
3553d248d37SBen Gardiner int board_eth_init(bd_t *bis)
3563d248d37SBen Gardiner {
357d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
358d2607401SSudhakar Rajashekhara 	/* Select RMII fucntion through the expander */
359d2607401SSudhakar Rajashekhara 	if (rmii_hw_init())
360d2607401SSudhakar Rajashekhara 		printf("RMII hardware init failed!!!\n");
361d2607401SSudhakar Rajashekhara #endif
3623d248d37SBen Gardiner 	if (!davinci_emac_initialize()) {
3633d248d37SBen Gardiner 		printf("Error: Ethernet init failed!\n");
3643d248d37SBen Gardiner 		return -1;
3653d248d37SBen Gardiner 	}
3663d248d37SBen Gardiner 
3673d248d37SBen Gardiner 	return 0;
3683d248d37SBen Gardiner }
3693d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
370