xref: /openbmc/u-boot/board/davinci/da8xxevm/da850evm.c (revision a4670f8ebb5b4df6afeb5155fb5b44c1d1d154b9)
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>
26c62db35dSSimon Glass #include <asm/mach-types.h>
2789b765c7SSudhakar Rajashekhara 
281d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
29ecc98ec1SLad, Prabhakar #include <mmc.h>
30ecc98ec1SLad, Prabhakar #include <asm/arch/sdmmc_defs.h>
31ecc98ec1SLad, Prabhakar #endif
32ecc98ec1SLad, Prabhakar 
3389b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR;
3489b765c7SSudhakar Rajashekhara 
353d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
36d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
37d2607401SSudhakar Rajashekhara #define HAS_RMII 1
38d2607401SSudhakar Rajashekhara #else
39d2607401SSudhakar Rajashekhara #define HAS_RMII 0
40d2607401SSudhakar Rajashekhara #endif
41d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */
42d2607401SSudhakar Rajashekhara 
4338fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_BUS	0
4438fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_CS	0
4538fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MAX_HZ	CONFIG_SF_DEFAULT_SPEED
4638fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MODE	SPI_MODE_3
4738fed6eeSHadli, Manjunath 
4838fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_OFFSET	(flash->size - SZ_64K)
4938fed6eeSHadli, Manjunath 
5038fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
5138fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr)
5238fed6eeSHadli, Manjunath {
5338fed6eeSHadli, Manjunath 	struct spi_flash *flash;
5438fed6eeSHadli, Manjunath 	int ret;
5538fed6eeSHadli, Manjunath 
5638fed6eeSHadli, Manjunath 	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
5738fed6eeSHadli, Manjunath 			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
5838fed6eeSHadli, Manjunath 	if (!flash) {
5938fed6eeSHadli, Manjunath 		printf("Error - unable to probe SPI flash.\n");
6038fed6eeSHadli, Manjunath 		return -1;
6138fed6eeSHadli, Manjunath 	}
6238fed6eeSHadli, Manjunath 
63*a4670f8eSAdam Ford 	ret = spi_flash_read(flash, (CFG_MAC_ADDR_OFFSET) + 1, 7, addr);
6438fed6eeSHadli, Manjunath 	if (ret) {
6538fed6eeSHadli, Manjunath 		printf("Error - unable to read MAC address from SPI flash.\n");
6638fed6eeSHadli, Manjunath 		return -1;
6738fed6eeSHadli, Manjunath 	}
6838fed6eeSHadli, Manjunath 
6938fed6eeSHadli, Manjunath 	return ret;
7038fed6eeSHadli, Manjunath }
7138fed6eeSHadli, Manjunath #endif
7238fed6eeSHadli, Manjunath 
73cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
74cf2c24e3SNagabhushana Netagunte {
75cf2c24e3SNagabhushana Netagunte 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
76cf2c24e3SNagabhushana Netagunte 	struct davinci_psc_regs *psc_regs;
77cf2c24e3SNagabhushana Netagunte 
78cf2c24e3SNagabhushana Netagunte 	psc_regs = davinci_psc0_regs;
79cf2c24e3SNagabhushana Netagunte 	mdstat = &psc_regs->psc0.mdstat[id];
80cf2c24e3SNagabhushana Netagunte 	mdctl = &psc_regs->psc0.mdctl[id];
81cf2c24e3SNagabhushana Netagunte 	ptstat = &psc_regs->ptstat;
82cf2c24e3SNagabhushana Netagunte 	ptcmd = &psc_regs->ptcmd;
83cf2c24e3SNagabhushana Netagunte 
84cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
85cf2c24e3SNagabhushana Netagunte 		;
86cf2c24e3SNagabhushana Netagunte 
87cf2c24e3SNagabhushana Netagunte 	if ((*mdstat & 0x1f) == 0x03)
88cf2c24e3SNagabhushana Netagunte 		return;                 /* Already on and enabled */
89cf2c24e3SNagabhushana Netagunte 
90cf2c24e3SNagabhushana Netagunte 	*mdctl |= 0x03;
91cf2c24e3SNagabhushana Netagunte 
92cf2c24e3SNagabhushana Netagunte 	*ptcmd = 0x1 << domain;
93cf2c24e3SNagabhushana Netagunte 
94cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
95cf2c24e3SNagabhushana Netagunte 		;
96cf2c24e3SNagabhushana Netagunte 	while ((*mdstat & 0x1f) != 0x03)
97cf2c24e3SNagabhushana Netagunte 		;		/* Probably an overkill... */
98cf2c24e3SNagabhushana Netagunte }
99cf2c24e3SNagabhushana Netagunte 
100cf2c24e3SNagabhushana Netagunte static void dspwake(void)
101cf2c24e3SNagabhushana Netagunte {
102cf2c24e3SNagabhushana Netagunte 	unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
103cf2c24e3SNagabhushana Netagunte 	u32 val;
104cf2c24e3SNagabhushana Netagunte 
105cf2c24e3SNagabhushana Netagunte 	/* if the device is ARM only, return */
106cf2c24e3SNagabhushana Netagunte 	if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
107cf2c24e3SNagabhushana Netagunte 		return;
108cf2c24e3SNagabhushana Netagunte 
109cf2c24e3SNagabhushana Netagunte 	if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
110cf2c24e3SNagabhushana Netagunte 		return;
111cf2c24e3SNagabhushana Netagunte 
112cf2c24e3SNagabhushana Netagunte 	*resetvect++ = 0x1E000; /* DSP Idle */
113cf2c24e3SNagabhushana Netagunte 	/* clear out the next 10 words as NOP */
114cf2c24e3SNagabhushana Netagunte 	memset(resetvect, 0, sizeof(unsigned) *10);
115cf2c24e3SNagabhushana Netagunte 
116cf2c24e3SNagabhushana Netagunte 	/* setup the DSP reset vector */
117cf2c24e3SNagabhushana Netagunte 	writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
118cf2c24e3SNagabhushana Netagunte 
119cf2c24e3SNagabhushana Netagunte 	dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
120cf2c24e3SNagabhushana Netagunte 	val = readl(PSC0_MDCTL + (15 * 4));
121cf2c24e3SNagabhushana Netagunte 	val |= 0x100;
122cf2c24e3SNagabhushana Netagunte 	writel(val, (PSC0_MDCTL + (15 * 4)));
123cf2c24e3SNagabhushana Netagunte }
124cf2c24e3SNagabhushana Netagunte 
125cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
126cf2c24e3SNagabhushana Netagunte {
127cf2c24e3SNagabhushana Netagunte 	dspwake();
12838fed6eeSHadli, Manjunath 
129206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)
130206a1038SHadli, Manjunath 
13138fed6eeSHadli, Manjunath 	uchar env_enetaddr[6];
13238fed6eeSHadli, Manjunath 	int enetaddr_found;
133206a1038SHadli, Manjunath 
13435affd7aSSimon Glass 	enetaddr_found = eth_env_get_enetaddr("ethaddr", env_enetaddr);
135206a1038SHadli, Manjunath 
136919ccb9fSAdam Ford #endif
137919ccb9fSAdam Ford 
138206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
13938fed6eeSHadli, Manjunath 	int spi_mac_read;
14038fed6eeSHadli, Manjunath 	uchar buff[6];
14138fed6eeSHadli, Manjunath 
14238fed6eeSHadli, Manjunath 	spi_mac_read = get_mac_addr(buff);
143*a4670f8eSAdam Ford 	buff[0] = 0;
14438fed6eeSHadli, Manjunath 
14538fed6eeSHadli, Manjunath 	/*
14638fed6eeSHadli, Manjunath 	 * MAC address not present in the environment
14738fed6eeSHadli, Manjunath 	 * try and read the MAC address from SPI flash
14838fed6eeSHadli, Manjunath 	 * and set it.
14938fed6eeSHadli, Manjunath 	 */
15038fed6eeSHadli, Manjunath 	if (!enetaddr_found) {
15138fed6eeSHadli, Manjunath 		if (!spi_mac_read) {
1520adb5b76SJoe Hershberger 			if (is_valid_ethaddr(buff)) {
153fd1e959eSSimon Glass 				if (eth_env_set_enetaddr("ethaddr", buff)) {
15438fed6eeSHadli, Manjunath 					printf("Warning: Failed to "
15538fed6eeSHadli, Manjunath 					"set MAC address from SPI flash\n");
15638fed6eeSHadli, Manjunath 				}
15738fed6eeSHadli, Manjunath 			} else {
15838fed6eeSHadli, Manjunath 					printf("Warning: Invalid "
15938fed6eeSHadli, Manjunath 					"MAC address read from SPI flash\n");
16038fed6eeSHadli, Manjunath 			}
16138fed6eeSHadli, Manjunath 		}
16238fed6eeSHadli, Manjunath 	} else {
16338fed6eeSHadli, Manjunath 		/*
16438fed6eeSHadli, Manjunath 		 * MAC address present in environment compare it with
16538fed6eeSHadli, Manjunath 		 * the MAC address in SPI flash and warn on mismatch
16638fed6eeSHadli, Manjunath 		 */
1670adb5b76SJoe Hershberger 		if (!spi_mac_read && is_valid_ethaddr(buff) &&
16838fed6eeSHadli, Manjunath 		    memcmp(env_enetaddr, buff, 6))
16938fed6eeSHadli, Manjunath 			printf("Warning: MAC address in SPI flash don't match "
17038fed6eeSHadli, Manjunath 					"with the MAC address in the environment\n");
17138fed6eeSHadli, Manjunath 		printf("Default using MAC address from environment\n");
17238fed6eeSHadli, Manjunath 	}
173919ccb9fSAdam Ford 
174919ccb9fSAdam Ford #elif defined(CONFIG_MAC_ADDR_IN_EEPROM)
175206a1038SHadli, Manjunath 	uint8_t enetaddr[8];
176206a1038SHadli, Manjunath 	int eeprom_mac_read;
177206a1038SHadli, Manjunath 
178206a1038SHadli, Manjunath 	/* Read Ethernet MAC address from EEPROM */
179206a1038SHadli, Manjunath 	eeprom_mac_read = dvevm_read_mac_address(enetaddr);
180206a1038SHadli, Manjunath 
181206a1038SHadli, Manjunath 	/*
182206a1038SHadli, Manjunath 	 * MAC address not present in the environment
183206a1038SHadli, Manjunath 	 * try and read the MAC address from EEPROM flash
184206a1038SHadli, Manjunath 	 * and set it.
185206a1038SHadli, Manjunath 	 */
186206a1038SHadli, Manjunath 	if (!enetaddr_found) {
187206a1038SHadli, Manjunath 		if (eeprom_mac_read)
188206a1038SHadli, Manjunath 			/* Set Ethernet MAC address from EEPROM */
189206a1038SHadli, Manjunath 			davinci_sync_env_enetaddr(enetaddr);
190206a1038SHadli, Manjunath 	} else {
191206a1038SHadli, Manjunath 		/*
192206a1038SHadli, Manjunath 		 * MAC address present in environment compare it with
193206a1038SHadli, Manjunath 		 * the MAC address in EEPROM and warn on mismatch
194206a1038SHadli, Manjunath 		 */
195206a1038SHadli, Manjunath 		if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
196206a1038SHadli, Manjunath 			printf("Warning: MAC address in EEPROM don't match "
197206a1038SHadli, Manjunath 					"with the MAC address in the environment\n");
198206a1038SHadli, Manjunath 		printf("Default using MAC address from environment\n");
199206a1038SHadli, Manjunath 	}
200206a1038SHadli, Manjunath 
201206a1038SHadli, Manjunath #endif
202cf2c24e3SNagabhushana Netagunte 	return 0;
203cf2c24e3SNagabhushana Netagunte }
204cf2c24e3SNagabhushana Netagunte 
2051d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
206ecc98ec1SLad, Prabhakar static struct davinci_mmc mmc_sd0 = {
207ecc98ec1SLad, Prabhakar 	.reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
208ecc98ec1SLad, Prabhakar 	.host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
209ecc98ec1SLad, Prabhakar 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
210ecc98ec1SLad, Prabhakar 	.version = MMC_CTLR_VERSION_2,
211ecc98ec1SLad, Prabhakar };
212ecc98ec1SLad, Prabhakar 
213ecc98ec1SLad, Prabhakar int board_mmc_init(bd_t *bis)
214ecc98ec1SLad, Prabhakar {
215ecc98ec1SLad, Prabhakar 	mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
216ecc98ec1SLad, Prabhakar 
217ecc98ec1SLad, Prabhakar 	/* Add slot-0 to mmc subsystem */
218ecc98ec1SLad, Prabhakar 	return davinci_mmc_init(bis, &mmc_sd0);
219ecc98ec1SLad, Prabhakar }
220ecc98ec1SLad, Prabhakar #endif
221ecc98ec1SLad, Prabhakar 
22252b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = {
22352b0f877SChristian Riesch #ifdef CONFIG_USE_NOR
22452b0f877SChristian Riesch 	/* GP0[11] is required for NOR to work on Rev 3 EVMs */
22552b0f877SChristian Riesch 	{ pinmux(0), 8, 4 },	/* GP0[11] */
22652b0f877SChristian Riesch #endif
2271d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
228ecc98ec1SLad, Prabhakar 	/* GP0[11] is required for SD to work on Rev 3 EVMs */
229ecc98ec1SLad, Prabhakar 	{ pinmux(0),  8, 4 },	/* GP0[11] */
230ecc98ec1SLad, Prabhakar #endif
23152b0f877SChristian Riesch };
23252b0f877SChristian Riesch 
2333d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = {
234591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC
23552b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mdio),
23652b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
23752b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_rmii),
23852b0f877SChristian Riesch #else
23952b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mii),
24052b0f877SChristian Riesch #endif
241591d8019SChristian Riesch #endif
24289b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
24352b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_base),
24452b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_scs0),
24589b765c7SSudhakar Rajashekhara #endif
24652b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_txrx),
24752b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_rtscts),
24852b0f877SChristian Riesch 	PINMUX_ITEM(i2c0_pins),
249756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
25052b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs3),
25152b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs4),
25252b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nand),
2531506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
25452b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs2),
25552b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nor),
256756d1fe7SBen Gardiner #endif
25752b0f877SChristian Riesch 	PINMUX_ITEM(gpio_pins),
2581d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
259ecc98ec1SLad, Prabhakar 	PINMUX_ITEM(mmc0_pins),
260ecc98ec1SLad, Prabhakar #endif
26189b765c7SSudhakar Rajashekhara };
26289b765c7SSudhakar Rajashekhara 
2633d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
2643d2c8e6cSChristian Riesch 
2656b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = {
26689b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
26789b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
26889b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_EMAC },	/* image download */
26989b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_UART2 },	/* console */
27089b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_GPIO },
2711d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
272ecc98ec1SLad, Prabhakar 	{ DAVINCI_LPSC_MMC_SD },
273ecc98ec1SLad, Prabhakar #endif
27489b765c7SSudhakar Rajashekhara };
27589b765c7SSudhakar Rajashekhara 
2766b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc);
2776b873dcaSSughosh Ganu 
2784f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
2794f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK	300000000
2804f6fc15bSSekhar Nori #endif
2814f6fc15bSSekhar Nori 
282754f8cb6SManjunath Hadli #define REV_AM18X_EVM		0x100
283754f8cb6SManjunath Hadli 
2844f6fc15bSSekhar Nori /*
2854f6fc15bSSekhar Nori  * get_board_rev() - setup to pass kernel board revision information
2864f6fc15bSSekhar Nori  * Returns:
2874f6fc15bSSekhar Nori  * bit[0-3]	Maximum cpu clock rate supported by onboard SoC
2884f6fc15bSSekhar Nori  *		0000b - 300 MHz
2894f6fc15bSSekhar Nori  *		0001b - 372 MHz
2904f6fc15bSSekhar Nori  *		0010b - 408 MHz
2914f6fc15bSSekhar Nori  *		0011b - 456 MHz
2924f6fc15bSSekhar Nori  */
2934f6fc15bSSekhar Nori u32 get_board_rev(void)
2944f6fc15bSSekhar Nori {
2954f6fc15bSSekhar Nori 	char *s;
2964f6fc15bSSekhar Nori 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
2974f6fc15bSSekhar Nori 	u32 rev = 0;
2984f6fc15bSSekhar Nori 
29900caae6dSSimon Glass 	s = env_get("maxcpuclk");
3004f6fc15bSSekhar Nori 	if (s)
3014f6fc15bSSekhar Nori 		maxcpuclk = simple_strtoul(s, NULL, 10);
3024f6fc15bSSekhar Nori 
3034f6fc15bSSekhar Nori 	if (maxcpuclk >= 456000000)
3044f6fc15bSSekhar Nori 		rev = 3;
3054f6fc15bSSekhar Nori 	else if (maxcpuclk >= 408000000)
3064f6fc15bSSekhar Nori 		rev = 2;
3074f6fc15bSSekhar Nori 	else if (maxcpuclk >= 372000000)
3084f6fc15bSSekhar Nori 		rev = 1;
309754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM
310754f8cb6SManjunath Hadli 	rev |= REV_AM18X_EVM;
311754f8cb6SManjunath Hadli #endif
3124f6fc15bSSekhar Nori 	return rev;
3134f6fc15bSSekhar Nori }
3144f6fc15bSSekhar Nori 
315ae5c77ddSChristian Riesch int board_early_init_f(void)
316ae5c77ddSChristian Riesch {
317ae5c77ddSChristian Riesch 	/*
318ae5c77ddSChristian Riesch 	 * Power on required peripherals
319ae5c77ddSChristian Riesch 	 * ARM does not have access by default to PSC0 and PSC1
320ae5c77ddSChristian Riesch 	 * assuming here that the DSP bootloader has set the IOPU
321ae5c77ddSChristian Riesch 	 * such that PSC access is available to ARM
322ae5c77ddSChristian Riesch 	 */
323ae5c77ddSChristian Riesch 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
324ae5c77ddSChristian Riesch 		return 1;
325ae5c77ddSChristian Riesch 
326ae5c77ddSChristian Riesch 	return 0;
327ae5c77ddSChristian Riesch }
328ae5c77ddSChristian Riesch 
32989b765c7SSudhakar Rajashekhara int board_init(void)
33089b765c7SSudhakar Rajashekhara {
33189b765c7SSudhakar Rajashekhara 	irq_init();
33289b765c7SSudhakar Rajashekhara 
333a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
334a3f88293SBen Gardiner 	/*
335a3f88293SBen Gardiner 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
336a3f88293SBen Gardiner 	 * Linux kernel @ 25MHz EMIFA
337a3f88293SBen Gardiner 	 */
338de94b80dSLad, Prabhakar 	writel((DAVINCI_ABCR_WSETUP(2) |
339de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WSTROBE(2) |
340de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WHOLD(1) |
341de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSETUP(1) |
342de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSTROBE(4) |
343a3f88293SBen Gardiner 		DAVINCI_ABCR_RHOLD(0) |
34424a514c4SBen Gardiner 		DAVINCI_ABCR_TA(1) |
345a3f88293SBen Gardiner 		DAVINCI_ABCR_ASIZE_8BIT),
346a3f88293SBen Gardiner 	       &davinci_emif_regs->ab2cr); /* CS3 */
347a3f88293SBen Gardiner #endif
348a3f88293SBen Gardiner 
34989b765c7SSudhakar Rajashekhara 	/* arch number of the board */
35089b765c7SSudhakar Rajashekhara 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
35189b765c7SSudhakar Rajashekhara 
35289b765c7SSudhakar Rajashekhara 	/* address of boot parameters */
35389b765c7SSudhakar Rajashekhara 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
35489b765c7SSudhakar Rajashekhara 
35589b765c7SSudhakar Rajashekhara 	/* setup the SUSPSRC for ARM to control emulation suspend */
35689b765c7SSudhakar Rajashekhara 	writel(readl(&davinci_syscfg_regs->suspsrc) &
35789b765c7SSudhakar Rajashekhara 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
35889b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
35989b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_UART2),
36089b765c7SSudhakar Rajashekhara 	       &davinci_syscfg_regs->suspsrc);
36189b765c7SSudhakar Rajashekhara 
36289b765c7SSudhakar Rajashekhara 	/* configure pinmux settings */
36389b765c7SSudhakar Rajashekhara 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
36489b765c7SSudhakar Rajashekhara 		return 1;
36589b765c7SSudhakar Rajashekhara 
3660f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
3670f3d6b06SNagabhushana Netagunte 	/* Set the GPIO direction as output */
3683864cb21SChristian Riesch 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3690f3d6b06SNagabhushana Netagunte 
3700f3d6b06SNagabhushana Netagunte 	/* Set the output as low */
3713864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_CLR_ADDR);
3720f3d6b06SNagabhushana Netagunte #endif
3730f3d6b06SNagabhushana Netagunte 
3741d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
3756652c62eSRajashekhara, Sudhakar 	/* Set the GPIO direction as output */
3766652c62eSRajashekhara, Sudhakar 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3776652c62eSRajashekhara, Sudhakar 
3786652c62eSRajashekhara, Sudhakar 	/* Set the output as high */
3793864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_SET_ADDR);
3806652c62eSRajashekhara, Sudhakar #endif
3816652c62eSRajashekhara, Sudhakar 
3823d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3836d1c649fSStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
3843d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
3853d248d37SBen Gardiner 
38689b765c7SSudhakar Rajashekhara 	/* enable the console UART */
38789b765c7SSudhakar Rajashekhara 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
38889b765c7SSudhakar Rajashekhara 		DAVINCI_UART_PWREMU_MGMT_UTRST),
38989b765c7SSudhakar Rajashekhara 	       &davinci_uart2_ctrl_regs->pwremu_mgmt);
39089b765c7SSudhakar Rajashekhara 
39189b765c7SSudhakar Rajashekhara 	return 0;
39289b765c7SSudhakar Rajashekhara }
3933d248d37SBen Gardiner 
3943d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3953d248d37SBen Gardiner 
396d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
397d2607401SSudhakar Rajashekhara /**
398d2607401SSudhakar Rajashekhara  * rmii_hw_init
399d2607401SSudhakar Rajashekhara  *
400d2607401SSudhakar Rajashekhara  * DA850/OMAP-L138 EVM can interface to a daughter card for
401d2607401SSudhakar Rajashekhara  * additional features. This card has an I2C GPIO Expander TCA6416
402d2607401SSudhakar Rajashekhara  * to select the required functions like camera, RMII Ethernet,
403d2607401SSudhakar Rajashekhara  * character LCD, video.
404d2607401SSudhakar Rajashekhara  *
405d2607401SSudhakar Rajashekhara  * Initialization of the expander involves configuring the
406d2607401SSudhakar Rajashekhara  * polarity and direction of the ports. P07-P05 are used here.
407d2607401SSudhakar Rajashekhara  * These ports are connected to a Mux chip which enables only one
408d2607401SSudhakar Rajashekhara  * functionality at a time.
409d2607401SSudhakar Rajashekhara  *
410d2607401SSudhakar Rajashekhara  * For RMII phy to respond, the MII MDIO clock has to be  disabled
411d2607401SSudhakar Rajashekhara  * since both the PHY devices have address as zero. The MII MDIO
412d2607401SSudhakar Rajashekhara  * clock is controlled via GPIO2[6].
413d2607401SSudhakar Rajashekhara  *
414d2607401SSudhakar Rajashekhara  * This code is valid for Beta version of the hardware
415d2607401SSudhakar Rajashekhara  */
416d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
417d2607401SSudhakar Rajashekhara {
418d2607401SSudhakar Rajashekhara 	const struct pinmux_config gpio_pins[] = {
419d2607401SSudhakar Rajashekhara 		{ pinmux(6), 8, 1 }
420d2607401SSudhakar Rajashekhara 	};
421d2607401SSudhakar Rajashekhara 	u_int8_t buf[2];
422d2607401SSudhakar Rajashekhara 	unsigned int temp;
423d2607401SSudhakar Rajashekhara 	int ret;
424d2607401SSudhakar Rajashekhara 
425d2607401SSudhakar Rajashekhara 	/* PinMux for GPIO */
426d2607401SSudhakar Rajashekhara 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
427d2607401SSudhakar Rajashekhara 		return 1;
428d2607401SSudhakar Rajashekhara 
429d2607401SSudhakar Rajashekhara 	/* I2C Exapnder configuration */
430d2607401SSudhakar Rajashekhara 	/* Set polarity to non-inverted */
431d2607401SSudhakar Rajashekhara 	buf[0] = 0x0;
432d2607401SSudhakar Rajashekhara 	buf[1] = 0x0;
433d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
434d2607401SSudhakar Rajashekhara 	if (ret) {
435d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
436d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
437d2607401SSudhakar Rajashekhara 		return ret;
438d2607401SSudhakar Rajashekhara 	}
439d2607401SSudhakar Rajashekhara 
440d2607401SSudhakar Rajashekhara 	/* Configure P07-P05 as outputs */
441d2607401SSudhakar Rajashekhara 	buf[0] = 0x1f;
442d2607401SSudhakar Rajashekhara 	buf[1] = 0xff;
443d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
444d2607401SSudhakar Rajashekhara 	if (ret) {
445d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
446d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
447d2607401SSudhakar Rajashekhara 	}
448d2607401SSudhakar Rajashekhara 
449d2607401SSudhakar Rajashekhara 	/* For Ethernet RMII selection
450d2607401SSudhakar Rajashekhara 	 * P07(SelA)=0
451d2607401SSudhakar Rajashekhara 	 * P06(SelB)=1
452d2607401SSudhakar Rajashekhara 	 * P05(SelC)=1
453d2607401SSudhakar Rajashekhara 	 */
454d2607401SSudhakar Rajashekhara 	if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
455d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x read FAILED!!!\n",
456d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
457d2607401SSudhakar Rajashekhara 	}
458d2607401SSudhakar Rajashekhara 
459d2607401SSudhakar Rajashekhara 	buf[0] &= 0x1f;
460d2607401SSudhakar Rajashekhara 	buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
461d2607401SSudhakar Rajashekhara 	if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
462d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
463d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
464d2607401SSudhakar Rajashekhara 	}
465d2607401SSudhakar Rajashekhara 
466d2607401SSudhakar Rajashekhara 	/* Set the output as high */
467d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_SET_ADDR);
468d2607401SSudhakar Rajashekhara 	temp |= (0x01 << 6);
469d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_SET_ADDR) = temp;
470d2607401SSudhakar Rajashekhara 
471d2607401SSudhakar Rajashekhara 	/* Set the GPIO direction as output */
472d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_DIR_ADDR);
473d2607401SSudhakar Rajashekhara 	temp &= ~(0x01 << 6);
474d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
475d2607401SSudhakar Rajashekhara 
476d2607401SSudhakar Rajashekhara 	return 0;
477d2607401SSudhakar Rajashekhara }
478d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
479d2607401SSudhakar Rajashekhara 
4803d248d37SBen Gardiner /*
4813d248d37SBen Gardiner  * Initializes on-board ethernet controllers.
4823d248d37SBen Gardiner  */
4833d248d37SBen Gardiner int board_eth_init(bd_t *bis)
4843d248d37SBen Gardiner {
485d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
486d2607401SSudhakar Rajashekhara 	/* Select RMII fucntion through the expander */
487d2607401SSudhakar Rajashekhara 	if (rmii_hw_init())
488d2607401SSudhakar Rajashekhara 		printf("RMII hardware init failed!!!\n");
489d2607401SSudhakar Rajashekhara #endif
4903d248d37SBen Gardiner 	if (!davinci_emac_initialize()) {
4913d248d37SBen Gardiner 		printf("Error: Ethernet init failed!\n");
4923d248d37SBen Gardiner 		return -1;
4933d248d37SBen Gardiner 	}
4943d248d37SBen Gardiner 
4953d248d37SBen Gardiner 	return 0;
4963d248d37SBen Gardiner }
4973d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
498