xref: /openbmc/u-boot/board/davinci/da8xxevm/da850evm.c (revision 4aeb939e77e4c43195be64a07e6035d3f7af9e91)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
289b765c7SSudhakar Rajashekhara /*
389b765c7SSudhakar Rajashekhara  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
489b765c7SSudhakar Rajashekhara  *
589b765c7SSudhakar Rajashekhara  * Based on da830evm.c. Original Copyrights follow:
689b765c7SSudhakar Rajashekhara  *
789b765c7SSudhakar Rajashekhara  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
889b765c7SSudhakar Rajashekhara  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
989b765c7SSudhakar Rajashekhara  */
1089b765c7SSudhakar Rajashekhara 
1189b765c7SSudhakar Rajashekhara #include <common.h>
128e51c0f2SAdam Ford #include <dm.h>
139925f1dbSAlex Kiernan #include <environment.h>
1489b765c7SSudhakar Rajashekhara #include <i2c.h>
153d248d37SBen Gardiner #include <net.h>
163d248d37SBen Gardiner #include <netdev.h>
1738fed6eeSHadli, Manjunath #include <spi.h>
1838fed6eeSHadli, Manjunath #include <spi_flash.h>
1989b765c7SSudhakar Rajashekhara #include <asm/arch/hardware.h>
203e01ed00SKhoronzhuk, Ivan #include <asm/ti-common/davinci_nand.h>
213d248d37SBen Gardiner #include <asm/arch/emac_defs.h>
2252b0f877SChristian Riesch #include <asm/arch/pinmux_defs.h>
2389b765c7SSudhakar Rajashekhara #include <asm/io.h>
24d7f9b503SSughosh Ganu #include <asm/arch/davinci_misc.h>
251221ce45SMasahiro Yamada #include <linux/errno.h>
26cf2c24e3SNagabhushana Netagunte #include <hwconfig.h>
27c62db35dSSimon Glass #include <asm/mach-types.h>
288e51c0f2SAdam Ford #include <asm/gpio.h>
2989b765c7SSudhakar Rajashekhara 
301d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
31ecc98ec1SLad, Prabhakar #include <mmc.h>
32ecc98ec1SLad, Prabhakar #include <asm/arch/sdmmc_defs.h>
33ecc98ec1SLad, Prabhakar #endif
34ecc98ec1SLad, Prabhakar 
3589b765c7SSudhakar Rajashekhara DECLARE_GLOBAL_DATA_PTR;
3689b765c7SSudhakar Rajashekhara 
373d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
38d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
39d2607401SSudhakar Rajashekhara #define HAS_RMII 1
40d2607401SSudhakar Rajashekhara #else
41d2607401SSudhakar Rajashekhara #define HAS_RMII 0
42d2607401SSudhakar Rajashekhara #endif
43d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC */
44d2607401SSudhakar Rajashekhara 
4538fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_BUS	0
4638fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_CS	0
4738fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MAX_HZ	CONFIG_SF_DEFAULT_SPEED
4838fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_SPI_MODE	SPI_MODE_3
4938fed6eeSHadli, Manjunath 
5038fed6eeSHadli, Manjunath #define CFG_MAC_ADDR_OFFSET	(flash->size - SZ_64K)
5138fed6eeSHadli, Manjunath 
5238fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
5338fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr)
5438fed6eeSHadli, Manjunath {
5538fed6eeSHadli, Manjunath 	struct spi_flash *flash;
5638fed6eeSHadli, Manjunath 	int ret;
5738fed6eeSHadli, Manjunath 
5838fed6eeSHadli, Manjunath 	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
5938fed6eeSHadli, Manjunath 			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
6038fed6eeSHadli, Manjunath 	if (!flash) {
6138fed6eeSHadli, Manjunath 		printf("Error - unable to probe SPI flash.\n");
6238fed6eeSHadli, Manjunath 		return -1;
6338fed6eeSHadli, Manjunath 	}
6438fed6eeSHadli, Manjunath 
65a4670f8eSAdam Ford 	ret = spi_flash_read(flash, (CFG_MAC_ADDR_OFFSET) + 1, 7, addr);
6638fed6eeSHadli, Manjunath 	if (ret) {
6738fed6eeSHadli, Manjunath 		printf("Error - unable to read MAC address from SPI flash.\n");
6838fed6eeSHadli, Manjunath 		return -1;
6938fed6eeSHadli, Manjunath 	}
7038fed6eeSHadli, Manjunath 
7138fed6eeSHadli, Manjunath 	return ret;
7238fed6eeSHadli, Manjunath }
7338fed6eeSHadli, Manjunath #endif
7438fed6eeSHadli, Manjunath 
75cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
76cf2c24e3SNagabhushana Netagunte {
77cf2c24e3SNagabhushana Netagunte 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
78cf2c24e3SNagabhushana Netagunte 	struct davinci_psc_regs *psc_regs;
79cf2c24e3SNagabhushana Netagunte 
80cf2c24e3SNagabhushana Netagunte 	psc_regs = davinci_psc0_regs;
81cf2c24e3SNagabhushana Netagunte 	mdstat = &psc_regs->psc0.mdstat[id];
82cf2c24e3SNagabhushana Netagunte 	mdctl = &psc_regs->psc0.mdctl[id];
83cf2c24e3SNagabhushana Netagunte 	ptstat = &psc_regs->ptstat;
84cf2c24e3SNagabhushana Netagunte 	ptcmd = &psc_regs->ptcmd;
85cf2c24e3SNagabhushana Netagunte 
86cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
87cf2c24e3SNagabhushana Netagunte 		;
88cf2c24e3SNagabhushana Netagunte 
89cf2c24e3SNagabhushana Netagunte 	if ((*mdstat & 0x1f) == 0x03)
90cf2c24e3SNagabhushana Netagunte 		return;                 /* Already on and enabled */
91cf2c24e3SNagabhushana Netagunte 
92cf2c24e3SNagabhushana Netagunte 	*mdctl |= 0x03;
93cf2c24e3SNagabhushana Netagunte 
94cf2c24e3SNagabhushana Netagunte 	*ptcmd = 0x1 << domain;
95cf2c24e3SNagabhushana Netagunte 
96cf2c24e3SNagabhushana Netagunte 	while (*ptstat & (0x1 << domain))
97cf2c24e3SNagabhushana Netagunte 		;
98cf2c24e3SNagabhushana Netagunte 	while ((*mdstat & 0x1f) != 0x03)
99cf2c24e3SNagabhushana Netagunte 		;		/* Probably an overkill... */
100cf2c24e3SNagabhushana Netagunte }
101cf2c24e3SNagabhushana Netagunte 
102cf2c24e3SNagabhushana Netagunte static void dspwake(void)
103cf2c24e3SNagabhushana Netagunte {
104cf2c24e3SNagabhushana Netagunte 	unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
105cf2c24e3SNagabhushana Netagunte 	u32 val;
106cf2c24e3SNagabhushana Netagunte 
107cf2c24e3SNagabhushana Netagunte 	/* if the device is ARM only, return */
108cf2c24e3SNagabhushana Netagunte 	if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
109cf2c24e3SNagabhushana Netagunte 		return;
110cf2c24e3SNagabhushana Netagunte 
111cf2c24e3SNagabhushana Netagunte 	if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
112cf2c24e3SNagabhushana Netagunte 		return;
113cf2c24e3SNagabhushana Netagunte 
114cf2c24e3SNagabhushana Netagunte 	*resetvect++ = 0x1E000; /* DSP Idle */
115cf2c24e3SNagabhushana Netagunte 	/* clear out the next 10 words as NOP */
116cf2c24e3SNagabhushana Netagunte 	memset(resetvect, 0, sizeof(unsigned) *10);
117cf2c24e3SNagabhushana Netagunte 
118cf2c24e3SNagabhushana Netagunte 	/* setup the DSP reset vector */
119cf2c24e3SNagabhushana Netagunte 	writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
120cf2c24e3SNagabhushana Netagunte 
121cf2c24e3SNagabhushana Netagunte 	dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
122cf2c24e3SNagabhushana Netagunte 	val = readl(PSC0_MDCTL + (15 * 4));
123cf2c24e3SNagabhushana Netagunte 	val |= 0x100;
124cf2c24e3SNagabhushana Netagunte 	writel(val, (PSC0_MDCTL + (15 * 4)));
125cf2c24e3SNagabhushana Netagunte }
126cf2c24e3SNagabhushana Netagunte 
127cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
128cf2c24e3SNagabhushana Netagunte {
129cf2c24e3SNagabhushana Netagunte 	dspwake();
13038fed6eeSHadli, Manjunath 
131206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)
132206a1038SHadli, Manjunath 
13338fed6eeSHadli, Manjunath 	uchar env_enetaddr[6];
13438fed6eeSHadli, Manjunath 	int enetaddr_found;
135206a1038SHadli, Manjunath 
13635affd7aSSimon Glass 	enetaddr_found = eth_env_get_enetaddr("ethaddr", env_enetaddr);
137206a1038SHadli, Manjunath 
138919ccb9fSAdam Ford #endif
139919ccb9fSAdam Ford 
140206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
14138fed6eeSHadli, Manjunath 	int spi_mac_read;
14238fed6eeSHadli, Manjunath 	uchar buff[6];
14338fed6eeSHadli, Manjunath 
14438fed6eeSHadli, Manjunath 	spi_mac_read = get_mac_addr(buff);
145a4670f8eSAdam Ford 	buff[0] = 0;
14638fed6eeSHadli, Manjunath 
14738fed6eeSHadli, Manjunath 	/*
14838fed6eeSHadli, Manjunath 	 * MAC address not present in the environment
14938fed6eeSHadli, Manjunath 	 * try and read the MAC address from SPI flash
15038fed6eeSHadli, Manjunath 	 * and set it.
15138fed6eeSHadli, Manjunath 	 */
15238fed6eeSHadli, Manjunath 	if (!enetaddr_found) {
15338fed6eeSHadli, Manjunath 		if (!spi_mac_read) {
1540adb5b76SJoe Hershberger 			if (is_valid_ethaddr(buff)) {
155fd1e959eSSimon Glass 				if (eth_env_set_enetaddr("ethaddr", buff)) {
15638fed6eeSHadli, Manjunath 					printf("Warning: Failed to "
15738fed6eeSHadli, Manjunath 					"set MAC address from SPI flash\n");
15838fed6eeSHadli, Manjunath 				}
15938fed6eeSHadli, Manjunath 			} else {
16038fed6eeSHadli, Manjunath 					printf("Warning: Invalid "
16138fed6eeSHadli, Manjunath 					"MAC address read from SPI flash\n");
16238fed6eeSHadli, Manjunath 			}
16338fed6eeSHadli, Manjunath 		}
16438fed6eeSHadli, Manjunath 	} else {
16538fed6eeSHadli, Manjunath 		/*
16638fed6eeSHadli, Manjunath 		 * MAC address present in environment compare it with
16738fed6eeSHadli, Manjunath 		 * the MAC address in SPI flash and warn on mismatch
16838fed6eeSHadli, Manjunath 		 */
1690adb5b76SJoe Hershberger 		if (!spi_mac_read && is_valid_ethaddr(buff) &&
17038fed6eeSHadli, Manjunath 		    memcmp(env_enetaddr, buff, 6))
17138fed6eeSHadli, Manjunath 			printf("Warning: MAC address in SPI flash don't match "
17238fed6eeSHadli, Manjunath 					"with the MAC address in the environment\n");
17338fed6eeSHadli, Manjunath 		printf("Default using MAC address from environment\n");
17438fed6eeSHadli, Manjunath 	}
175919ccb9fSAdam Ford 
176919ccb9fSAdam Ford #elif defined(CONFIG_MAC_ADDR_IN_EEPROM)
177206a1038SHadli, Manjunath 	uint8_t enetaddr[8];
178206a1038SHadli, Manjunath 	int eeprom_mac_read;
179206a1038SHadli, Manjunath 
180206a1038SHadli, Manjunath 	/* Read Ethernet MAC address from EEPROM */
181206a1038SHadli, Manjunath 	eeprom_mac_read = dvevm_read_mac_address(enetaddr);
182206a1038SHadli, Manjunath 
183206a1038SHadli, Manjunath 	/*
184206a1038SHadli, Manjunath 	 * MAC address not present in the environment
185206a1038SHadli, Manjunath 	 * try and read the MAC address from EEPROM flash
186206a1038SHadli, Manjunath 	 * and set it.
187206a1038SHadli, Manjunath 	 */
188206a1038SHadli, Manjunath 	if (!enetaddr_found) {
189206a1038SHadli, Manjunath 		if (eeprom_mac_read)
190206a1038SHadli, Manjunath 			/* Set Ethernet MAC address from EEPROM */
191206a1038SHadli, Manjunath 			davinci_sync_env_enetaddr(enetaddr);
192206a1038SHadli, Manjunath 	} else {
193206a1038SHadli, Manjunath 		/*
194206a1038SHadli, Manjunath 		 * MAC address present in environment compare it with
195206a1038SHadli, Manjunath 		 * the MAC address in EEPROM and warn on mismatch
196206a1038SHadli, Manjunath 		 */
197206a1038SHadli, Manjunath 		if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
198206a1038SHadli, Manjunath 			printf("Warning: MAC address in EEPROM don't match "
199206a1038SHadli, Manjunath 					"with the MAC address in the environment\n");
200206a1038SHadli, Manjunath 		printf("Default using MAC address from environment\n");
201206a1038SHadli, Manjunath 	}
202206a1038SHadli, Manjunath 
203206a1038SHadli, Manjunath #endif
204cf2c24e3SNagabhushana Netagunte 	return 0;
205cf2c24e3SNagabhushana Netagunte }
206cf2c24e3SNagabhushana Netagunte 
207*4aeb939eSAdam Ford #ifndef CONFIG_DM_MMC
2081d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
209ecc98ec1SLad, Prabhakar static struct davinci_mmc mmc_sd0 = {
210ecc98ec1SLad, Prabhakar 	.reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
211ecc98ec1SLad, Prabhakar 	.host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
212ecc98ec1SLad, Prabhakar 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
213ecc98ec1SLad, Prabhakar 	.version = MMC_CTLR_VERSION_2,
214ecc98ec1SLad, Prabhakar };
215ecc98ec1SLad, Prabhakar 
216ecc98ec1SLad, Prabhakar int board_mmc_init(bd_t *bis)
217ecc98ec1SLad, Prabhakar {
218ecc98ec1SLad, Prabhakar 	mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
219ecc98ec1SLad, Prabhakar 
220ecc98ec1SLad, Prabhakar 	/* Add slot-0 to mmc subsystem */
221ecc98ec1SLad, Prabhakar 	return davinci_mmc_init(bis, &mmc_sd0);
222ecc98ec1SLad, Prabhakar }
223ecc98ec1SLad, Prabhakar #endif
224*4aeb939eSAdam Ford #endif
225ecc98ec1SLad, Prabhakar 
22652b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = {
22752b0f877SChristian Riesch #ifdef CONFIG_USE_NOR
22852b0f877SChristian Riesch 	/* GP0[11] is required for NOR to work on Rev 3 EVMs */
22952b0f877SChristian Riesch 	{ pinmux(0), 8, 4 },	/* GP0[11] */
23052b0f877SChristian Riesch #endif
2311d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
232ecc98ec1SLad, Prabhakar 	/* GP0[11] is required for SD to work on Rev 3 EVMs */
233ecc98ec1SLad, Prabhakar 	{ pinmux(0),  8, 4 },	/* GP0[11] */
234ecc98ec1SLad, Prabhakar #endif
23552b0f877SChristian Riesch };
23652b0f877SChristian Riesch 
2373d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = {
238591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC
23952b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mdio),
24052b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
24152b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_rmii),
24252b0f877SChristian Riesch #else
24352b0f877SChristian Riesch 	PINMUX_ITEM(emac_pins_mii),
24452b0f877SChristian Riesch #endif
245591d8019SChristian Riesch #endif
24689b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
24752b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_base),
24852b0f877SChristian Riesch 	PINMUX_ITEM(spi1_pins_scs0),
24989b765c7SSudhakar Rajashekhara #endif
25052b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_txrx),
25152b0f877SChristian Riesch 	PINMUX_ITEM(uart2_pins_rtscts),
25252b0f877SChristian Riesch 	PINMUX_ITEM(i2c0_pins),
253756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
25452b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs3),
25552b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs4),
25652b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nand),
2571506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
25852b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_cs2),
25952b0f877SChristian Riesch 	PINMUX_ITEM(emifa_pins_nor),
260756d1fe7SBen Gardiner #endif
26152b0f877SChristian Riesch 	PINMUX_ITEM(gpio_pins),
2621d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
263ecc98ec1SLad, Prabhakar 	PINMUX_ITEM(mmc0_pins),
264ecc98ec1SLad, Prabhakar #endif
26589b765c7SSudhakar Rajashekhara };
26689b765c7SSudhakar Rajashekhara 
2673d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
2683d2c8e6cSChristian Riesch 
2696b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = {
27089b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_AEMIF },	/* NAND, NOR */
27189b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_SPI1 },	/* Serial Flash */
27289b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_EMAC },	/* image download */
27389b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_UART2 },	/* console */
27489b765c7SSudhakar Rajashekhara 	{ DAVINCI_LPSC_GPIO },
2751d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
276ecc98ec1SLad, Prabhakar 	{ DAVINCI_LPSC_MMC_SD },
277ecc98ec1SLad, Prabhakar #endif
27889b765c7SSudhakar Rajashekhara };
27989b765c7SSudhakar Rajashekhara 
2806b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc);
2816b873dcaSSughosh Ganu 
2824f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
2834f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK	300000000
2844f6fc15bSSekhar Nori #endif
2854f6fc15bSSekhar Nori 
286754f8cb6SManjunath Hadli #define REV_AM18X_EVM		0x100
287754f8cb6SManjunath Hadli 
2884f6fc15bSSekhar Nori /*
2894f6fc15bSSekhar Nori  * get_board_rev() - setup to pass kernel board revision information
2904f6fc15bSSekhar Nori  * Returns:
2914f6fc15bSSekhar Nori  * bit[0-3]	Maximum cpu clock rate supported by onboard SoC
2924f6fc15bSSekhar Nori  *		0000b - 300 MHz
2934f6fc15bSSekhar Nori  *		0001b - 372 MHz
2944f6fc15bSSekhar Nori  *		0010b - 408 MHz
2954f6fc15bSSekhar Nori  *		0011b - 456 MHz
2964f6fc15bSSekhar Nori  */
2974f6fc15bSSekhar Nori u32 get_board_rev(void)
2984f6fc15bSSekhar Nori {
2994f6fc15bSSekhar Nori 	char *s;
3004f6fc15bSSekhar Nori 	u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
3014f6fc15bSSekhar Nori 	u32 rev = 0;
3024f6fc15bSSekhar Nori 
30300caae6dSSimon Glass 	s = env_get("maxcpuclk");
3044f6fc15bSSekhar Nori 	if (s)
3054f6fc15bSSekhar Nori 		maxcpuclk = simple_strtoul(s, NULL, 10);
3064f6fc15bSSekhar Nori 
3074f6fc15bSSekhar Nori 	if (maxcpuclk >= 456000000)
3084f6fc15bSSekhar Nori 		rev = 3;
3094f6fc15bSSekhar Nori 	else if (maxcpuclk >= 408000000)
3104f6fc15bSSekhar Nori 		rev = 2;
3114f6fc15bSSekhar Nori 	else if (maxcpuclk >= 372000000)
3124f6fc15bSSekhar Nori 		rev = 1;
313754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM
314754f8cb6SManjunath Hadli 	rev |= REV_AM18X_EVM;
315754f8cb6SManjunath Hadli #endif
3164f6fc15bSSekhar Nori 	return rev;
3174f6fc15bSSekhar Nori }
3184f6fc15bSSekhar Nori 
319ae5c77ddSChristian Riesch int board_early_init_f(void)
320ae5c77ddSChristian Riesch {
321ae5c77ddSChristian Riesch 	/*
322ae5c77ddSChristian Riesch 	 * Power on required peripherals
323ae5c77ddSChristian Riesch 	 * ARM does not have access by default to PSC0 and PSC1
324ae5c77ddSChristian Riesch 	 * assuming here that the DSP bootloader has set the IOPU
325ae5c77ddSChristian Riesch 	 * such that PSC access is available to ARM
326ae5c77ddSChristian Riesch 	 */
327ae5c77ddSChristian Riesch 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
328ae5c77ddSChristian Riesch 		return 1;
329ae5c77ddSChristian Riesch 
330ae5c77ddSChristian Riesch 	return 0;
331ae5c77ddSChristian Riesch }
332ae5c77ddSChristian Riesch 
33389b765c7SSudhakar Rajashekhara int board_init(void)
33489b765c7SSudhakar Rajashekhara {
33589b765c7SSudhakar Rajashekhara 	irq_init();
33689b765c7SSudhakar Rajashekhara 
337a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
338a3f88293SBen Gardiner 	/*
339a3f88293SBen Gardiner 	 * NAND CS setup - cycle counts based on da850evm NAND timings in the
340a3f88293SBen Gardiner 	 * Linux kernel @ 25MHz EMIFA
341a3f88293SBen Gardiner 	 */
342de94b80dSLad, Prabhakar 	writel((DAVINCI_ABCR_WSETUP(2) |
343de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WSTROBE(2) |
344de94b80dSLad, Prabhakar 		DAVINCI_ABCR_WHOLD(1) |
345de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSETUP(1) |
346de94b80dSLad, Prabhakar 		DAVINCI_ABCR_RSTROBE(4) |
347a3f88293SBen Gardiner 		DAVINCI_ABCR_RHOLD(0) |
34824a514c4SBen Gardiner 		DAVINCI_ABCR_TA(1) |
349a3f88293SBen Gardiner 		DAVINCI_ABCR_ASIZE_8BIT),
350a3f88293SBen Gardiner 	       &davinci_emif_regs->ab2cr); /* CS3 */
351a3f88293SBen Gardiner #endif
352a3f88293SBen Gardiner 
35389b765c7SSudhakar Rajashekhara 	/* arch number of the board */
35489b765c7SSudhakar Rajashekhara 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
35589b765c7SSudhakar Rajashekhara 
35689b765c7SSudhakar Rajashekhara 	/* address of boot parameters */
35789b765c7SSudhakar Rajashekhara 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
35889b765c7SSudhakar Rajashekhara 
35989b765c7SSudhakar Rajashekhara 	/* setup the SUSPSRC for ARM to control emulation suspend */
36089b765c7SSudhakar Rajashekhara 	writel(readl(&davinci_syscfg_regs->suspsrc) &
36189b765c7SSudhakar Rajashekhara 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
36289b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
36389b765c7SSudhakar Rajashekhara 		 DAVINCI_SYSCFG_SUSPSRC_UART2),
36489b765c7SSudhakar Rajashekhara 	       &davinci_syscfg_regs->suspsrc);
36589b765c7SSudhakar Rajashekhara 
36689b765c7SSudhakar Rajashekhara 	/* configure pinmux settings */
36789b765c7SSudhakar Rajashekhara 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
36889b765c7SSudhakar Rajashekhara 		return 1;
36989b765c7SSudhakar Rajashekhara 
3700f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
3710f3d6b06SNagabhushana Netagunte 	/* Set the GPIO direction as output */
3723864cb21SChristian Riesch 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3730f3d6b06SNagabhushana Netagunte 
3740f3d6b06SNagabhushana Netagunte 	/* Set the output as low */
3753864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_CLR_ADDR);
3760f3d6b06SNagabhushana Netagunte #endif
3770f3d6b06SNagabhushana Netagunte 
3781d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
3796652c62eSRajashekhara, Sudhakar 	/* Set the GPIO direction as output */
3806652c62eSRajashekhara, Sudhakar 	clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
3816652c62eSRajashekhara, Sudhakar 
3826652c62eSRajashekhara, Sudhakar 	/* Set the output as high */
3833864cb21SChristian Riesch 	writel(0x01 << 11, GPIO_BANK0_REG_SET_ADDR);
3846652c62eSRajashekhara, Sudhakar #endif
3856652c62eSRajashekhara, Sudhakar 
3863d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3876d1c649fSStefano Babic 	davinci_emac_mii_mode_sel(HAS_RMII);
3883d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
3893d248d37SBen Gardiner 
39089b765c7SSudhakar Rajashekhara 	/* enable the console UART */
39189b765c7SSudhakar Rajashekhara 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
39289b765c7SSudhakar Rajashekhara 		DAVINCI_UART_PWREMU_MGMT_UTRST),
39389b765c7SSudhakar Rajashekhara 	       &davinci_uart2_ctrl_regs->pwremu_mgmt);
39489b765c7SSudhakar Rajashekhara 
39589b765c7SSudhakar Rajashekhara 	return 0;
39689b765c7SSudhakar Rajashekhara }
3973d248d37SBen Gardiner 
3983d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
3993d248d37SBen Gardiner 
400d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
401d2607401SSudhakar Rajashekhara /**
402d2607401SSudhakar Rajashekhara  * rmii_hw_init
403d2607401SSudhakar Rajashekhara  *
404d2607401SSudhakar Rajashekhara  * DA850/OMAP-L138 EVM can interface to a daughter card for
405d2607401SSudhakar Rajashekhara  * additional features. This card has an I2C GPIO Expander TCA6416
406d2607401SSudhakar Rajashekhara  * to select the required functions like camera, RMII Ethernet,
407d2607401SSudhakar Rajashekhara  * character LCD, video.
408d2607401SSudhakar Rajashekhara  *
409d2607401SSudhakar Rajashekhara  * Initialization of the expander involves configuring the
410d2607401SSudhakar Rajashekhara  * polarity and direction of the ports. P07-P05 are used here.
411d2607401SSudhakar Rajashekhara  * These ports are connected to a Mux chip which enables only one
412d2607401SSudhakar Rajashekhara  * functionality at a time.
413d2607401SSudhakar Rajashekhara  *
414d2607401SSudhakar Rajashekhara  * For RMII phy to respond, the MII MDIO clock has to be  disabled
415d2607401SSudhakar Rajashekhara  * since both the PHY devices have address as zero. The MII MDIO
416d2607401SSudhakar Rajashekhara  * clock is controlled via GPIO2[6].
417d2607401SSudhakar Rajashekhara  *
418d2607401SSudhakar Rajashekhara  * This code is valid for Beta version of the hardware
419d2607401SSudhakar Rajashekhara  */
420d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
421d2607401SSudhakar Rajashekhara {
422d2607401SSudhakar Rajashekhara 	const struct pinmux_config gpio_pins[] = {
423d2607401SSudhakar Rajashekhara 		{ pinmux(6), 8, 1 }
424d2607401SSudhakar Rajashekhara 	};
425d2607401SSudhakar Rajashekhara 	u_int8_t buf[2];
426d2607401SSudhakar Rajashekhara 	unsigned int temp;
427d2607401SSudhakar Rajashekhara 	int ret;
428d2607401SSudhakar Rajashekhara 
429d2607401SSudhakar Rajashekhara 	/* PinMux for GPIO */
430d2607401SSudhakar Rajashekhara 	if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
431d2607401SSudhakar Rajashekhara 		return 1;
432d2607401SSudhakar Rajashekhara 
433d2607401SSudhakar Rajashekhara 	/* I2C Exapnder configuration */
434d2607401SSudhakar Rajashekhara 	/* Set polarity to non-inverted */
435d2607401SSudhakar Rajashekhara 	buf[0] = 0x0;
436d2607401SSudhakar Rajashekhara 	buf[1] = 0x0;
437d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
438d2607401SSudhakar Rajashekhara 	if (ret) {
439d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
440d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
441d2607401SSudhakar Rajashekhara 		return ret;
442d2607401SSudhakar Rajashekhara 	}
443d2607401SSudhakar Rajashekhara 
444d2607401SSudhakar Rajashekhara 	/* Configure P07-P05 as outputs */
445d2607401SSudhakar Rajashekhara 	buf[0] = 0x1f;
446d2607401SSudhakar Rajashekhara 	buf[1] = 0xff;
447d2607401SSudhakar Rajashekhara 	ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
448d2607401SSudhakar Rajashekhara 	if (ret) {
449d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
450d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
451d2607401SSudhakar Rajashekhara 	}
452d2607401SSudhakar Rajashekhara 
453d2607401SSudhakar Rajashekhara 	/* For Ethernet RMII selection
454d2607401SSudhakar Rajashekhara 	 * P07(SelA)=0
455d2607401SSudhakar Rajashekhara 	 * P06(SelB)=1
456d2607401SSudhakar Rajashekhara 	 * P05(SelC)=1
457d2607401SSudhakar Rajashekhara 	 */
458d2607401SSudhakar Rajashekhara 	if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
459d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x read FAILED!!!\n",
460d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
461d2607401SSudhakar Rajashekhara 	}
462d2607401SSudhakar Rajashekhara 
463d2607401SSudhakar Rajashekhara 	buf[0] &= 0x1f;
464d2607401SSudhakar Rajashekhara 	buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
465d2607401SSudhakar Rajashekhara 	if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
466d2607401SSudhakar Rajashekhara 		printf("\nExpander @ 0x%02x write FAILED!!!\n",
467d2607401SSudhakar Rajashekhara 				CONFIG_SYS_I2C_EXPANDER_ADDR);
468d2607401SSudhakar Rajashekhara 	}
469d2607401SSudhakar Rajashekhara 
470d2607401SSudhakar Rajashekhara 	/* Set the output as high */
471d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_SET_ADDR);
472d2607401SSudhakar Rajashekhara 	temp |= (0x01 << 6);
473d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_SET_ADDR) = temp;
474d2607401SSudhakar Rajashekhara 
475d2607401SSudhakar Rajashekhara 	/* Set the GPIO direction as output */
476d2607401SSudhakar Rajashekhara 	temp = REG(GPIO_BANK2_REG_DIR_ADDR);
477d2607401SSudhakar Rajashekhara 	temp &= ~(0x01 << 6);
478d2607401SSudhakar Rajashekhara 	REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
479d2607401SSudhakar Rajashekhara 
480d2607401SSudhakar Rajashekhara 	return 0;
481d2607401SSudhakar Rajashekhara }
482d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
483d2607401SSudhakar Rajashekhara 
4843d248d37SBen Gardiner /*
4853d248d37SBen Gardiner  * Initializes on-board ethernet controllers.
4863d248d37SBen Gardiner  */
4873d248d37SBen Gardiner int board_eth_init(bd_t *bis)
4883d248d37SBen Gardiner {
489d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
490d2607401SSudhakar Rajashekhara 	/* Select RMII fucntion through the expander */
491d2607401SSudhakar Rajashekhara 	if (rmii_hw_init())
492d2607401SSudhakar Rajashekhara 		printf("RMII hardware init failed!!!\n");
493d2607401SSudhakar Rajashekhara #endif
4943d248d37SBen Gardiner 	if (!davinci_emac_initialize()) {
4953d248d37SBen Gardiner 		printf("Error: Ethernet init failed!\n");
4963d248d37SBen Gardiner 		return -1;
4973d248d37SBen Gardiner 	}
4983d248d37SBen Gardiner 
4993d248d37SBen Gardiner 	return 0;
5003d248d37SBen Gardiner }
5013d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
502