xref: /openbmc/u-boot/board/davinci/da8xxevm/da850evm.c (revision 1d2c0506d31a9997e5ffc22e90942902f673b107)
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  *
91a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
1089b765c7SSudhakar Rajashekhara  */
1189b765c7SSudhakar Rajashekhara 
1289b765c7SSudhakar Rajashekhara #include <common.h>
1389b765c7SSudhakar Rajashekhara #include <i2c.h>
143d248d37SBen Gardiner #include <net.h>
153d248d37SBen Gardiner #include <netdev.h>
1638fed6eeSHadli, Manjunath #include <spi.h>
1738fed6eeSHadli, Manjunath #include <spi_flash.h>
1889b765c7SSudhakar Rajashekhara #include <asm/arch/hardware.h>
193e01ed00SKhoronzhuk, Ivan #include <asm/ti-common/davinci_nand.h>
203d248d37SBen Gardiner #include <asm/arch/emac_defs.h>
2152b0f877SChristian Riesch #include <asm/arch/pinmux_defs.h>
2289b765c7SSudhakar Rajashekhara #include <asm/io.h>
23d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h>
241221ce45SMasahiro Yamada #include <linux/errno.h>
25cf2c24e3SNagabhushana Netagunte #include <hwconfig.h>
2689b765c7SSudhakar Rajashekhara 
27*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
28ecc98ec1SLad, Prabhakar #include <mmc.h>
29ecc98ec1SLad, Prabhakar #include <asm/arch/sdmmc_defs.h>
30ecc98ec1SLad, Prabhakar #endif
31ecc98ec1SLad, Prabhakar 
3289b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR;
3389b765c7SSudhakar Rajashekhara 
343d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
35d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
36d2607401SSudhakar Rajashekhara #define HAS_RMII 1
37d2607401SSudhakar Rajashekhara #else
38d2607401SSudhakar Rajashekhara #define HAS_RMII 0
39d2607401SSudhakar Rajashekhara #endif
40d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */
41d2607401SSudhakar Rajashekhara 
4238fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_BUS	0
4338fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_CS	0
4438fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MAX_HZ	CONFIG_SF_DEFAULT_SPEED
4538fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MODE	SPI_MODE_3
4638fed6eeSHadli, Manjunath 
4738fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_OFFSET	(flash->size - SZ_64K)
4838fed6eeSHadli, Manjunath 
4938fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
5038fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr)
5138fed6eeSHadli, Manjunath {
5238fed6eeSHadli, Manjunath 	struct spi_flash *flash;
5338fed6eeSHadli, Manjunath 	int ret;
5438fed6eeSHadli, Manjunath 
5538fed6eeSHadli, Manjunath 	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
5638fed6eeSHadli, Manjunath 			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
5738fed6eeSHadli, Manjunath 	if (!flash) {
5838fed6eeSHadli, Manjunath 		printf("Error - unable to probe SPI flash.\n");
5938fed6eeSHadli, Manjunath 		return -1;
6038fed6eeSHadli, Manjunath 	}
6138fed6eeSHadli, Manjunath 
6238fed6eeSHadli, Manjunath 	ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr);
6338fed6eeSHadli, Manjunath 	if (ret) {
6438fed6eeSHadli, Manjunath 		printf("Error - unable to read MAC address from SPI flash.\n");
6538fed6eeSHadli, Manjunath 		return -1;
6638fed6eeSHadli, Manjunath 	}
6738fed6eeSHadli, Manjunath 
6838fed6eeSHadli, Manjunath 	return ret;
6938fed6eeSHadli, Manjunath }
7038fed6eeSHadli, Manjunath #endif
7138fed6eeSHadli, Manjunath 
72cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
73cf2c24e3SNagabhushana Netagunte {
74cf2c24e3SNagabhushana Netagunte 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
75cf2c24e3SNagabhushana Netagunte 	struct davinci_psc_regs *psc_regs;
76cf2c24e3SNagabhushana Netagunte 
77cf2c24e3SNagabhushana Netagunte 	psc_regs = davinci_psc0_regs;
78cf2c24e3SNagabhushana Netagunte 	mdstat = &psc_regs->psc0.mdstat[id];
79cf2c24e3SNagabhushana Netagunte 	mdctl = &psc_regs->psc0.mdctl[id];
80cf2c24e3SNagabhushana Netagunte 	ptstat = &psc_regs->ptstat;
81cf2c24e3SNagabhushana Netagunte 	ptcmd = &psc_regs->ptcmd;
82cf2c24e3SNagabhushana Netagunte 
83cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
84cf2c24e3SNagabhushana Netagunte 		;
85cf2c24e3SNagabhushana Netagunte 
86cf2c24e3SNagabhushana Netagunte 	if ((*mdstat & 0x1f) == 0x03)
87cf2c24e3SNagabhushana Netagunte 		return;                 /* Already on and enabled */
88cf2c24e3SNagabhushana Netagunte 
89cf2c24e3SNagabhushana Netagunte 	*mdctl |= 0x03;
90cf2c24e3SNagabhushana Netagunte 
91cf2c24e3SNagabhushana Netagunte 	*ptcmd = 0x1 << domain;
92cf2c24e3SNagabhushana Netagunte 
93cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
94cf2c24e3SNagabhushana Netagunte 		;
95cf2c24e3SNagabhushana Netagunte 	while ((*mdstat & 0x1f) != 0x03)
96cf2c24e3SNagabhushana Netagunte 		;		/* Probably an overkill... */
97cf2c24e3SNagabhushana Netagunte }
98cf2c24e3SNagabhushana Netagunte 
99cf2c24e3SNagabhushana Netagunte static void dspwake(void)
100cf2c24e3SNagabhushana Netagunte {
101cf2c24e3SNagabhushana Netagunte 	unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
102cf2c24e3SNagabhushana Netagunte 	u32 val;
103cf2c24e3SNagabhushana Netagunte 
104cf2c24e3SNagabhushana Netagunte 	/* if the device is ARM only, return */
105cf2c24e3SNagabhushana Netagunte 	if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
106cf2c24e3SNagabhushana Netagunte 		return;
107cf2c24e3SNagabhushana Netagunte 
108cf2c24e3SNagabhushana Netagunte 	if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
109cf2c24e3SNagabhushana Netagunte 		return;
110cf2c24e3SNagabhushana Netagunte 
111cf2c24e3SNagabhushana Netagunte 	*resetvect++ = 0x1E000; /* DSP Idle */
112cf2c24e3SNagabhushana Netagunte 	/* clear out the next 10 words as NOP */
113cf2c24e3SNagabhushana Netagunte 	memset(resetvect, 0, sizeof(unsigned) *10);
114cf2c24e3SNagabhushana Netagunte 
115cf2c24e3SNagabhushana Netagunte 	/* setup the DSP reset vector */
116cf2c24e3SNagabhushana Netagunte 	writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
117cf2c24e3SNagabhushana Netagunte 
118cf2c24e3SNagabhushana Netagunte 	dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
119cf2c24e3SNagabhushana Netagunte 	val = readl(PSC0_MDCTL + (15 * 4));
120cf2c24e3SNagabhushana Netagunte 	val |= 0x100;
121cf2c24e3SNagabhushana Netagunte 	writel(val, (PSC0_MDCTL + (15 * 4)));
122cf2c24e3SNagabhushana Netagunte }
123cf2c24e3SNagabhushana Netagunte 
124cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
125cf2c24e3SNagabhushana Netagunte {
126cf2c24e3SNagabhushana Netagunte 	dspwake();
12738fed6eeSHadli, Manjunath 
128206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)
129206a1038SHadli, Manjunath 
13038fed6eeSHadli, Manjunath 	uchar env_enetaddr[6];
13138fed6eeSHadli, Manjunath 	int enetaddr_found;
132206a1038SHadli, Manjunath 
133206a1038SHadli, Manjunath 	enetaddr_found = eth_getenv_enetaddr("ethaddr", env_enetaddr);
134206a1038SHadli, Manjunath 
135206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
13638fed6eeSHadli, Manjunath 	int spi_mac_read;
13738fed6eeSHadli, Manjunath 	uchar buff[6];
13838fed6eeSHadli, Manjunath 
13938fed6eeSHadli, Manjunath 	spi_mac_read = get_mac_addr(buff);
14038fed6eeSHadli, Manjunath 
14138fed6eeSHadli, Manjunath 	/*
14238fed6eeSHadli, Manjunath 	 * MAC address not present in the environment
14338fed6eeSHadli, Manjunath 	 * try and read the MAC address from SPI flash
14438fed6eeSHadli, Manjunath 	 * and set it.
14538fed6eeSHadli, Manjunath 	 */
14638fed6eeSHadli, Manjunath 	if (!enetaddr_found) {
14738fed6eeSHadli, Manjunath 		if (!spi_mac_read) {
1480adb5b76SJoe Hershberger 			if (is_valid_ethaddr(buff)) {
14938fed6eeSHadli, Manjunath 				if (eth_setenv_enetaddr("ethaddr", buff)) {
15038fed6eeSHadli, Manjunath 					printf("Warning: Failed to "
15138fed6eeSHadli, Manjunath 					"set MAC address from SPI flash\n");
15238fed6eeSHadli, Manjunath 				}
15338fed6eeSHadli, Manjunath 			} else {
15438fed6eeSHadli, Manjunath 					printf("Warning: Invalid "
15538fed6eeSHadli, Manjunath 					"MAC address read from SPI flash\n");
15638fed6eeSHadli, Manjunath 			}
15738fed6eeSHadli, Manjunath 		}
15838fed6eeSHadli, Manjunath 	} else {
15938fed6eeSHadli, Manjunath 		/*
16038fed6eeSHadli, Manjunath 		 * MAC address present in environment compare it with
16138fed6eeSHadli, Manjunath 		 * the MAC address in SPI flash and warn on mismatch
16238fed6eeSHadli, Manjunath 		 */
1630adb5b76SJoe Hershberger 		if (!spi_mac_read && is_valid_ethaddr(buff) &&
16438fed6eeSHadli, Manjunath 		    memcmp(env_enetaddr, buff, 6))
16538fed6eeSHadli, Manjunath 			printf("Warning: MAC address in SPI flash don't match "
16638fed6eeSHadli, Manjunath 					"with the MAC address in the environment\n");
16738fed6eeSHadli, Manjunath 		printf("Default using MAC address from environment\n");
16838fed6eeSHadli, Manjunath 	}
16938fed6eeSHadli, Manjunath #endif
170206a1038SHadli, Manjunath 	uint8_t enetaddr[8];
171206a1038SHadli, Manjunath 	int eeprom_mac_read;
172206a1038SHadli, Manjunath 
173206a1038SHadli, Manjunath 	/* Read Ethernet MAC address from EEPROM */
174206a1038SHadli, Manjunath 	eeprom_mac_read = dvevm_read_mac_address(enetaddr);
175206a1038SHadli, Manjunath 
176206a1038SHadli, Manjunath 	/*
177206a1038SHadli, Manjunath 	 * MAC address not present in the environment
178206a1038SHadli, Manjunath 	 * try and read the MAC address from EEPROM flash
179206a1038SHadli, Manjunath 	 * and set it.
180206a1038SHadli, Manjunath 	 */
181206a1038SHadli, Manjunath 	if (!enetaddr_found) {
182206a1038SHadli, Manjunath 		if (eeprom_mac_read)
183206a1038SHadli, Manjunath 			/* Set Ethernet MAC address from EEPROM */
184206a1038SHadli, Manjunath 			davinci_sync_env_enetaddr(enetaddr);
185206a1038SHadli, Manjunath 	} else {
186206a1038SHadli, Manjunath 		/*
187206a1038SHadli, Manjunath 		 * MAC address present in environment compare it with
188206a1038SHadli, Manjunath 		 * the MAC address in EEPROM and warn on mismatch
189206a1038SHadli, Manjunath 		 */
190206a1038SHadli, Manjunath 		if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
191206a1038SHadli, Manjunath 			printf("Warning: MAC address in EEPROM don't match "
192206a1038SHadli, Manjunath 					"with the MAC address in the environment\n");
193206a1038SHadli, Manjunath 		printf("Default using MAC address from environment\n");
194206a1038SHadli, Manjunath 	}
195206a1038SHadli, Manjunath 
196206a1038SHadli, Manjunath #endif
197cf2c24e3SNagabhushana Netagunte 	return 0;
198cf2c24e3SNagabhushana Netagunte }
199cf2c24e3SNagabhushana Netagunte 
200*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
201ecc98ec1SLad, Prabhakar static struct davinci_mmc mmc_sd0 = {
202ecc98ec1SLad, Prabhakar 	.reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
203ecc98ec1SLad, Prabhakar 	.host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
204ecc98ec1SLad, Prabhakar 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
205ecc98ec1SLad, Prabhakar 	.version = MMC_CTLR_VERSION_2,
206ecc98ec1SLad, Prabhakar };
207ecc98ec1SLad, Prabhakar 
208ecc98ec1SLad, Prabhakar int board_mmc_init(bd_t *bis)
209ecc98ec1SLad, Prabhakar {
210ecc98ec1SLad, Prabhakar 	mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
211ecc98ec1SLad, Prabhakar 
212ecc98ec1SLad, Prabhakar 	/* Add slot-0 to mmc subsystem */
213ecc98ec1SLad, Prabhakar 	return davinci_mmc_init(bis, &mmc_sd0);
214ecc98ec1SLad, Prabhakar }
215ecc98ec1SLad, Prabhakar #endif
216ecc98ec1SLad, Prabhakar 
21752b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = {
21852b0f877SChristian Riesch #ifdef CONFIG_USE_NOR
21952b0f877SChristian Riesch 	/* GP0[11] is required for NOR to work on Rev 3 EVMs */
22052b0f877SChristian Riesch 	{ pinmux(0), 8, 4 },	/* GP0[11] */
22152b0f877SChristian Riesch #endif
222*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
223ecc98ec1SLad, Prabhakar 	/* GP0[11] is required for SD to work on Rev 3 EVMs */
224ecc98ec1SLad, Prabhakar 	{ pinmux(0),  8, 4 },	/* GP0[11] */
225ecc98ec1SLad, Prabhakar #endif
22652b0f877SChristian Riesch };
22752b0f877SChristian Riesch 
2283d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = {
229591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC
23052b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mdio),
23152b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
23252b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_rmii),
23352b0f877SChristian Riesch #else
23452b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mii),
23552b0f877SChristian Riesch #endif
236591d8019SChristian Riesch #endif
23789b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
23852b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_base),
23952b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_scs0),
24089b765c7SSudhakar Rajashekhara #endif
24152b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_txrx),
24252b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_rtscts),
24352b0f877SChristian Riesch 	PINMUX_ITEM(i2c0_pins),
244756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
24552b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs3),
24652b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs4),
24752b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nand),
2481506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
24952b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs2),
25052b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nor),
251756d1fe7SBen Gardiner #endif
25252b0f877SChristian Riesch 	PINMUX_ITEM(gpio_pins),
253*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
254ecc98ec1SLad, Prabhakar 	PINMUX_ITEM(mmc0_pins),
255ecc98ec1SLad, Prabhakar #endif
25689b765c7SSudhakar Rajashekhara };
25789b765c7SSudhakar Rajashekhara 
2583d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
2593d2c8e6cSChristian Riesch 
2606b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = {
26189b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
26289b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
26389b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_EMAC },	/* image download */
26489b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_UART2 },	/* console */
26589b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_GPIO },
266*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
267ecc98ec1SLad, Prabhakar 	{ DAVINCI_LPSC_MMC_SD },
268ecc98ec1SLad, Prabhakar #endif
26989b765c7SSudhakar Rajashekhara };
27089b765c7SSudhakar Rajashekhara 
2716b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc);
2726b873dcaSSughosh Ganu 
2734f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
2744f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK	300000000
2754f6fc15bSSekhar Nori #endif
2764f6fc15bSSekhar Nori 
277754f8cb6SManjunath Hadli #define REV_AM18X_EVM		0x100
278754f8cb6SManjunath Hadli 
2794f6fc15bSSekhar Nori /*
2804f6fc15bSSekhar Nori  * get_board_rev() - setup to pass kernel board revision information
2814f6fc15bSSekhar Nori  * Returns:
2824f6fc15bSSekhar Nori  * bit[0-3]	Maximum cpu clock rate supported by onboard SoC
2834f6fc15bSSekhar Nori  *		0000b - 300 MHz
2844f6fc15bSSekhar Nori  *		0001b - 372 MHz
2854f6fc15bSSekhar Nori  *		0010b - 408 MHz
2864f6fc15bSSekhar Nori  *		0011b - 456 MHz
2874f6fc15bSSekhar Nori  */
2884f6fc15bSSekhar Nori u32 get_board_rev(void)
2894f6fc15bSSekhar Nori {
2904f6fc15bSSekhar Nori 	char *s;
2914f6fc15bSSekhar Nori 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
2924f6fc15bSSekhar Nori 	u32 rev = 0;
2934f6fc15bSSekhar Nori 
2944f6fc15bSSekhar Nori 	s = getenv("maxcpuclk");
2954f6fc15bSSekhar Nori 	if (s)
2964f6fc15bSSekhar Nori 		maxcpuclk = simple_strtoul(s, NULL, 10);
2974f6fc15bSSekhar Nori 
2984f6fc15bSSekhar Nori 	if (maxcpuclk >= 456000000)
2994f6fc15bSSekhar Nori 		rev = 3;
3004f6fc15bSSekhar Nori 	else if (maxcpuclk >= 408000000)
3014f6fc15bSSekhar Nori 		rev = 2;
3024f6fc15bSSekhar Nori 	else if (maxcpuclk >= 372000000)
3034f6fc15bSSekhar Nori 		rev = 1;
304754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM
305754f8cb6SManjunath Hadli 	rev |= REV_AM18X_EVM;
306754f8cb6SManjunath Hadli #endif
3074f6fc15bSSekhar Nori 	return rev;
3084f6fc15bSSekhar Nori }
3094f6fc15bSSekhar Nori 
310ae5c77ddSChristian Riesch int board_early_init_f(void)
311ae5c77ddSChristian Riesch {
312ae5c77ddSChristian Riesch 	/*
313ae5c77ddSChristian Riesch 	 * Power on required peripherals
314ae5c77ddSChristian Riesch 	 * ARM does not have access by default to PSC0 and PSC1
315ae5c77ddSChristian Riesch 	 * assuming here that the DSP bootloader has set the IOPU
316ae5c77ddSChristian Riesch 	 * such that PSC access is available to ARM
317ae5c77ddSChristian Riesch 	 */
318ae5c77ddSChristian Riesch 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
319ae5c77ddSChristian Riesch 		return 1;
320ae5c77ddSChristian Riesch 
321ae5c77ddSChristian Riesch 	return 0;
322ae5c77ddSChristian Riesch }
323ae5c77ddSChristian Riesch 
32489b765c7SSudhakar Rajashekhara int board_init(void)
32589b765c7SSudhakar Rajashekhara {
32689b765c7SSudhakar Rajashekhara #ifndef CONFIG_USE_IRQ
32789b765c7SSudhakar Rajashekhara 	irq_init();
32889b765c7SSudhakar Rajashekhara #endif
32989b765c7SSudhakar Rajashekhara 
330a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
331a3f88293SBen Gardiner 	/*
332a3f88293SBen Gardiner 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
333a3f88293SBen Gardiner 	 * Linux kernel @ 25MHz EMIFA
334a3f88293SBen Gardiner 	 */
335de94b80dSLad, Prabhakar 	writel((DAVINCI_ABCR_WSETUP(2) |
336de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WSTROBE(2) |
337de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WHOLD(1) |
338de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSETUP(1) |
339de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSTROBE(4) |
340a3f88293SBen Gardiner 		DAVINCI_ABCR_RHOLD(0) |
34124a514c4SBen Gardiner 		DAVINCI_ABCR_TA(1) |
342a3f88293SBen Gardiner 		DAVINCI_ABCR_ASIZE_8BIT),
343a3f88293SBen Gardiner 	       &davinci_emif_regs->ab2cr); /* CS3 */
344a3f88293SBen Gardiner #endif
345a3f88293SBen Gardiner 
34689b765c7SSudhakar Rajashekhara 	/* arch number of the board */
34789b765c7SSudhakar Rajashekhara 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
34889b765c7SSudhakar Rajashekhara 
34989b765c7SSudhakar Rajashekhara 	/* address of boot parameters */
35089b765c7SSudhakar Rajashekhara 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
35189b765c7SSudhakar Rajashekhara 
35289b765c7SSudhakar Rajashekhara 	/* setup the SUSPSRC for ARM to control emulation suspend */
35389b765c7SSudhakar Rajashekhara 	writel(readl(&davinci_syscfg_regs->suspsrc) &
35489b765c7SSudhakar Rajashekhara 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
35589b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
35689b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_UART2),
35789b765c7SSudhakar Rajashekhara 	       &davinci_syscfg_regs->suspsrc);
35889b765c7SSudhakar Rajashekhara 
35989b765c7SSudhakar Rajashekhara 	/* configure pinmux settings */
36089b765c7SSudhakar Rajashekhara 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
36189b765c7SSudhakar Rajashekhara 		return 1;
36289b765c7SSudhakar Rajashekhara 
3630f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
3640f3d6b06SNagabhushana Netagunte 	/* Set the GPIO direction as output */
3653864cb21SChristian Riesch 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3660f3d6b06SNagabhushana Netagunte 
3670f3d6b06SNagabhushana Netagunte 	/* Set the output as low */
3683864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_CLR_ADDR);
3690f3d6b06SNagabhushana Netagunte #endif
3700f3d6b06SNagabhushana Netagunte 
371*1d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
3726652c62eSRajashekhara, Sudhakar 	/* Set the GPIO direction as output */
3736652c62eSRajashekhara, Sudhakar 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3746652c62eSRajashekhara, Sudhakar 
3756652c62eSRajashekhara, Sudhakar 	/* Set the output as high */
3763864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_SET_ADDR);
3776652c62eSRajashekhara, Sudhakar #endif
3786652c62eSRajashekhara, Sudhakar 
3793d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3806d1c649fSStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
3813d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
3823d248d37SBen Gardiner 
38389b765c7SSudhakar Rajashekhara 	/* enable the console UART */
38489b765c7SSudhakar Rajashekhara 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
38589b765c7SSudhakar Rajashekhara 		DAVINCI_UART_PWREMU_MGMT_UTRST),
38689b765c7SSudhakar Rajashekhara 	       &davinci_uart2_ctrl_regs->pwremu_mgmt);
38789b765c7SSudhakar Rajashekhara 
38889b765c7SSudhakar Rajashekhara 	return 0;
38989b765c7SSudhakar Rajashekhara }
3903d248d37SBen Gardiner 
3913d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3923d248d37SBen Gardiner 
393d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
394d2607401SSudhakar Rajashekhara /**
395d2607401SSudhakar Rajashekhara  * rmii_hw_init
396d2607401SSudhakar Rajashekhara  *
397d2607401SSudhakar Rajashekhara  * DA850/OMAP-L138 EVM can interface to a daughter card for
398d2607401SSudhakar Rajashekhara  * additional features. This card has an I2C GPIO Expander TCA6416
399d2607401SSudhakar Rajashekhara  * to select the required functions like camera, RMII Ethernet,
400d2607401SSudhakar Rajashekhara  * character LCD, video.
401d2607401SSudhakar Rajashekhara  *
402d2607401SSudhakar Rajashekhara  * Initialization of the expander involves configuring the
403d2607401SSudhakar Rajashekhara  * polarity and direction of the ports. P07-P05 are used here.
404d2607401SSudhakar Rajashekhara  * These ports are connected to a Mux chip which enables only one
405d2607401SSudhakar Rajashekhara  * functionality at a time.
406d2607401SSudhakar Rajashekhara  *
407d2607401SSudhakar Rajashekhara  * For RMII phy to respond, the MII MDIO clock has to be  disabled
408d2607401SSudhakar Rajashekhara  * since both the PHY devices have address as zero. The MII MDIO
409d2607401SSudhakar Rajashekhara  * clock is controlled via GPIO2[6].
410d2607401SSudhakar Rajashekhara  *
411d2607401SSudhakar Rajashekhara  * This code is valid for Beta version of the hardware
412d2607401SSudhakar Rajashekhara  */
413d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
414d2607401SSudhakar Rajashekhara {
415d2607401SSudhakar Rajashekhara 	const struct pinmux_config gpio_pins[] = {
416d2607401SSudhakar Rajashekhara 		{ pinmux(6), 8, 1 }
417d2607401SSudhakar Rajashekhara 	};
418d2607401SSudhakar Rajashekhara 	u_int8_t buf[2];
419d2607401SSudhakar Rajashekhara 	unsigned int temp;
420d2607401SSudhakar Rajashekhara 	int ret;
421d2607401SSudhakar Rajashekhara 
422d2607401SSudhakar Rajashekhara 	/* PinMux for GPIO */
423d2607401SSudhakar Rajashekhara 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
424d2607401SSudhakar Rajashekhara 		return 1;
425d2607401SSudhakar Rajashekhara 
426d2607401SSudhakar Rajashekhara 	/* I2C Exapnder configuration */
427d2607401SSudhakar Rajashekhara 	/* Set polarity to non-inverted */
428d2607401SSudhakar Rajashekhara 	buf[0] = 0x0;
429d2607401SSudhakar Rajashekhara 	buf[1] = 0x0;
430d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
431d2607401SSudhakar Rajashekhara 	if (ret) {
432d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
433d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
434d2607401SSudhakar Rajashekhara 		return ret;
435d2607401SSudhakar Rajashekhara 	}
436d2607401SSudhakar Rajashekhara 
437d2607401SSudhakar Rajashekhara 	/* Configure P07-P05 as outputs */
438d2607401SSudhakar Rajashekhara 	buf[0] = 0x1f;
439d2607401SSudhakar Rajashekhara 	buf[1] = 0xff;
440d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
441d2607401SSudhakar Rajashekhara 	if (ret) {
442d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
443d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
444d2607401SSudhakar Rajashekhara 	}
445d2607401SSudhakar Rajashekhara 
446d2607401SSudhakar Rajashekhara 	/* For Ethernet RMII selection
447d2607401SSudhakar Rajashekhara 	 * P07(SelA)=0
448d2607401SSudhakar Rajashekhara 	 * P06(SelB)=1
449d2607401SSudhakar Rajashekhara 	 * P05(SelC)=1
450d2607401SSudhakar Rajashekhara 	 */
451d2607401SSudhakar Rajashekhara 	if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
452d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x read FAILED!!!\n",
453d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
454d2607401SSudhakar Rajashekhara 	}
455d2607401SSudhakar Rajashekhara 
456d2607401SSudhakar Rajashekhara 	buf[0] &= 0x1f;
457d2607401SSudhakar Rajashekhara 	buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
458d2607401SSudhakar Rajashekhara 	if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
459d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
460d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
461d2607401SSudhakar Rajashekhara 	}
462d2607401SSudhakar Rajashekhara 
463d2607401SSudhakar Rajashekhara 	/* Set the output as high */
464d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_SET_ADDR);
465d2607401SSudhakar Rajashekhara 	temp |= (0x01 << 6);
466d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_SET_ADDR) = temp;
467d2607401SSudhakar Rajashekhara 
468d2607401SSudhakar Rajashekhara 	/* Set the GPIO direction as output */
469d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_DIR_ADDR);
470d2607401SSudhakar Rajashekhara 	temp &= ~(0x01 << 6);
471d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
472d2607401SSudhakar Rajashekhara 
473d2607401SSudhakar Rajashekhara 	return 0;
474d2607401SSudhakar Rajashekhara }
475d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
476d2607401SSudhakar Rajashekhara 
4773d248d37SBen Gardiner /*
4783d248d37SBen Gardiner  * Initializes on-board ethernet controllers.
4793d248d37SBen Gardiner  */
4803d248d37SBen Gardiner int board_eth_init(bd_t *bis)
4813d248d37SBen Gardiner {
482d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
483d2607401SSudhakar Rajashekhara 	/* Select RMII fucntion through the expander */
484d2607401SSudhakar Rajashekhara 	if (rmii_hw_init())
485d2607401SSudhakar Rajashekhara 		printf("RMII hardware init failed!!!\n");
486d2607401SSudhakar Rajashekhara #endif
4873d248d37SBen Gardiner 	if (!davinci_emac_initialize()) {
4883d248d37SBen Gardiner 		printf("Error: Ethernet init failed!\n");
4893d248d37SBen Gardiner 		return -1;
4903d248d37SBen Gardiner 	}
4913d248d37SBen Gardiner 
4923d248d37SBen Gardiner 	return 0;
4933d248d37SBen Gardiner }
4943d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
495