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
52*cb19c293SJagan Teki #ifdef CONFIG_SPL_BUILD
53*cb19c293SJagan Teki #include <ns16550.h>
54*cb19c293SJagan Teki #include <dm/platform_data/spi_davinci.h>
55*cb19c293SJagan Teki
56*cb19c293SJagan Teki static const struct ns16550_platdata da850evm_serial = {
57*cb19c293SJagan Teki .base = DAVINCI_UART2_BASE,
58*cb19c293SJagan Teki .reg_shift = 2,
59*cb19c293SJagan Teki .clock = 150000000,
60*cb19c293SJagan Teki .fcr = UART_FCR_DEFVAL,
61*cb19c293SJagan Teki };
62*cb19c293SJagan Teki
63*cb19c293SJagan Teki U_BOOT_DEVICE(da850evm_uart) = {
64*cb19c293SJagan Teki .name = "ns16550_serial",
65*cb19c293SJagan Teki .platdata = &da850evm_serial,
66*cb19c293SJagan Teki };
67*cb19c293SJagan Teki
68*cb19c293SJagan Teki static const struct davinci_spi_platdata davinci_spi_data = {
69*cb19c293SJagan Teki .regs = (struct davinci_spi_regs *)0x01f0e000,
70*cb19c293SJagan Teki .num_cs = 4,
71*cb19c293SJagan Teki };
72*cb19c293SJagan Teki
73*cb19c293SJagan Teki U_BOOT_DEVICE(davinci_spi) = {
74*cb19c293SJagan Teki .name = "davinci_spi",
75*cb19c293SJagan Teki .platdata = &davinci_spi_data,
76*cb19c293SJagan Teki };
77*cb19c293SJagan Teki #endif
78*cb19c293SJagan Teki
7938fed6eeSHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
get_mac_addr(u8 * addr)8038fed6eeSHadli, Manjunath static int get_mac_addr(u8 *addr)
8138fed6eeSHadli, Manjunath {
8238fed6eeSHadli, Manjunath struct spi_flash *flash;
8338fed6eeSHadli, Manjunath int ret;
8438fed6eeSHadli, Manjunath
8538fed6eeSHadli, Manjunath flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
8638fed6eeSHadli, Manjunath CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
8738fed6eeSHadli, Manjunath if (!flash) {
8838fed6eeSHadli, Manjunath printf("Error - unable to probe SPI flash.\n");
8938fed6eeSHadli, Manjunath return -1;
9038fed6eeSHadli, Manjunath }
9138fed6eeSHadli, Manjunath
92a4670f8eSAdam Ford ret = spi_flash_read(flash, (CFG_MAC_ADDR_OFFSET) + 1, 7, addr);
9338fed6eeSHadli, Manjunath if (ret) {
9438fed6eeSHadli, Manjunath printf("Error - unable to read MAC address from SPI flash.\n");
9538fed6eeSHadli, Manjunath return -1;
9638fed6eeSHadli, Manjunath }
9738fed6eeSHadli, Manjunath
9838fed6eeSHadli, Manjunath return ret;
9938fed6eeSHadli, Manjunath }
10038fed6eeSHadli, Manjunath #endif
10138fed6eeSHadli, Manjunath
dsp_lpsc_on(unsigned domain,unsigned int id)102cf2c24e3SNagabhushana Netagunte void dsp_lpsc_on(unsigned domain, unsigned int id)
103cf2c24e3SNagabhushana Netagunte {
104cf2c24e3SNagabhushana Netagunte dv_reg_p mdstat, mdctl, ptstat, ptcmd;
105cf2c24e3SNagabhushana Netagunte struct davinci_psc_regs *psc_regs;
106cf2c24e3SNagabhushana Netagunte
107cf2c24e3SNagabhushana Netagunte psc_regs = davinci_psc0_regs;
108cf2c24e3SNagabhushana Netagunte mdstat = &psc_regs->psc0.mdstat[id];
109cf2c24e3SNagabhushana Netagunte mdctl = &psc_regs->psc0.mdctl[id];
110cf2c24e3SNagabhushana Netagunte ptstat = &psc_regs->ptstat;
111cf2c24e3SNagabhushana Netagunte ptcmd = &psc_regs->ptcmd;
112cf2c24e3SNagabhushana Netagunte
113cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain))
114cf2c24e3SNagabhushana Netagunte ;
115cf2c24e3SNagabhushana Netagunte
116cf2c24e3SNagabhushana Netagunte if ((*mdstat & 0x1f) == 0x03)
117cf2c24e3SNagabhushana Netagunte return; /* Already on and enabled */
118cf2c24e3SNagabhushana Netagunte
119cf2c24e3SNagabhushana Netagunte *mdctl |= 0x03;
120cf2c24e3SNagabhushana Netagunte
121cf2c24e3SNagabhushana Netagunte *ptcmd = 0x1 << domain;
122cf2c24e3SNagabhushana Netagunte
123cf2c24e3SNagabhushana Netagunte while (*ptstat & (0x1 << domain))
124cf2c24e3SNagabhushana Netagunte ;
125cf2c24e3SNagabhushana Netagunte while ((*mdstat & 0x1f) != 0x03)
126cf2c24e3SNagabhushana Netagunte ; /* Probably an overkill... */
127cf2c24e3SNagabhushana Netagunte }
128cf2c24e3SNagabhushana Netagunte
dspwake(void)129cf2c24e3SNagabhushana Netagunte static void dspwake(void)
130cf2c24e3SNagabhushana Netagunte {
131cf2c24e3SNagabhushana Netagunte unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
132cf2c24e3SNagabhushana Netagunte u32 val;
133cf2c24e3SNagabhushana Netagunte
134cf2c24e3SNagabhushana Netagunte /* if the device is ARM only, return */
135cf2c24e3SNagabhushana Netagunte if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
136cf2c24e3SNagabhushana Netagunte return;
137cf2c24e3SNagabhushana Netagunte
138cf2c24e3SNagabhushana Netagunte if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
139cf2c24e3SNagabhushana Netagunte return;
140cf2c24e3SNagabhushana Netagunte
141cf2c24e3SNagabhushana Netagunte *resetvect++ = 0x1E000; /* DSP Idle */
142cf2c24e3SNagabhushana Netagunte /* clear out the next 10 words as NOP */
143cf2c24e3SNagabhushana Netagunte memset(resetvect, 0, sizeof(unsigned) *10);
144cf2c24e3SNagabhushana Netagunte
145cf2c24e3SNagabhushana Netagunte /* setup the DSP reset vector */
146cf2c24e3SNagabhushana Netagunte writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
147cf2c24e3SNagabhushana Netagunte
148cf2c24e3SNagabhushana Netagunte dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
149cf2c24e3SNagabhushana Netagunte val = readl(PSC0_MDCTL + (15 * 4));
150cf2c24e3SNagabhushana Netagunte val |= 0x100;
151cf2c24e3SNagabhushana Netagunte writel(val, (PSC0_MDCTL + (15 * 4)));
152cf2c24e3SNagabhushana Netagunte }
153cf2c24e3SNagabhushana Netagunte
misc_init_r(void)154cf2c24e3SNagabhushana Netagunte int misc_init_r(void)
155cf2c24e3SNagabhushana Netagunte {
156cf2c24e3SNagabhushana Netagunte dspwake();
15738fed6eeSHadli, Manjunath
158206a1038SHadli, Manjunath #if defined(CONFIG_MAC_ADDR_IN_SPIFLASH) || defined(CONFIG_MAC_ADDR_IN_EEPROM)
159206a1038SHadli, Manjunath
16038fed6eeSHadli, Manjunath uchar env_enetaddr[6];
16138fed6eeSHadli, Manjunath int enetaddr_found;
162206a1038SHadli, Manjunath
16335affd7aSSimon Glass enetaddr_found = eth_env_get_enetaddr("ethaddr", env_enetaddr);
164206a1038SHadli, Manjunath
165919ccb9fSAdam Ford #endif
166919ccb9fSAdam Ford
167206a1038SHadli, Manjunath #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
16838fed6eeSHadli, Manjunath int spi_mac_read;
16938fed6eeSHadli, Manjunath uchar buff[6];
17038fed6eeSHadli, Manjunath
17138fed6eeSHadli, Manjunath spi_mac_read = get_mac_addr(buff);
172a4670f8eSAdam Ford buff[0] = 0;
17338fed6eeSHadli, Manjunath
17438fed6eeSHadli, Manjunath /*
17538fed6eeSHadli, Manjunath * MAC address not present in the environment
17638fed6eeSHadli, Manjunath * try and read the MAC address from SPI flash
17738fed6eeSHadli, Manjunath * and set it.
17838fed6eeSHadli, Manjunath */
17938fed6eeSHadli, Manjunath if (!enetaddr_found) {
18038fed6eeSHadli, Manjunath if (!spi_mac_read) {
1810adb5b76SJoe Hershberger if (is_valid_ethaddr(buff)) {
182fd1e959eSSimon Glass if (eth_env_set_enetaddr("ethaddr", buff)) {
18338fed6eeSHadli, Manjunath printf("Warning: Failed to "
18438fed6eeSHadli, Manjunath "set MAC address from SPI flash\n");
18538fed6eeSHadli, Manjunath }
18638fed6eeSHadli, Manjunath } else {
18738fed6eeSHadli, Manjunath printf("Warning: Invalid "
18838fed6eeSHadli, Manjunath "MAC address read from SPI flash\n");
18938fed6eeSHadli, Manjunath }
19038fed6eeSHadli, Manjunath }
19138fed6eeSHadli, Manjunath } else {
19238fed6eeSHadli, Manjunath /*
19338fed6eeSHadli, Manjunath * MAC address present in environment compare it with
19438fed6eeSHadli, Manjunath * the MAC address in SPI flash and warn on mismatch
19538fed6eeSHadli, Manjunath */
1960adb5b76SJoe Hershberger if (!spi_mac_read && is_valid_ethaddr(buff) &&
19738fed6eeSHadli, Manjunath memcmp(env_enetaddr, buff, 6))
19838fed6eeSHadli, Manjunath printf("Warning: MAC address in SPI flash don't match "
19938fed6eeSHadli, Manjunath "with the MAC address in the environment\n");
20038fed6eeSHadli, Manjunath printf("Default using MAC address from environment\n");
20138fed6eeSHadli, Manjunath }
202919ccb9fSAdam Ford
203919ccb9fSAdam Ford #elif defined(CONFIG_MAC_ADDR_IN_EEPROM)
204206a1038SHadli, Manjunath uint8_t enetaddr[8];
205206a1038SHadli, Manjunath int eeprom_mac_read;
206206a1038SHadli, Manjunath
207206a1038SHadli, Manjunath /* Read Ethernet MAC address from EEPROM */
208206a1038SHadli, Manjunath eeprom_mac_read = dvevm_read_mac_address(enetaddr);
209206a1038SHadli, Manjunath
210206a1038SHadli, Manjunath /*
211206a1038SHadli, Manjunath * MAC address not present in the environment
212206a1038SHadli, Manjunath * try and read the MAC address from EEPROM flash
213206a1038SHadli, Manjunath * and set it.
214206a1038SHadli, Manjunath */
215206a1038SHadli, Manjunath if (!enetaddr_found) {
216206a1038SHadli, Manjunath if (eeprom_mac_read)
217206a1038SHadli, Manjunath /* Set Ethernet MAC address from EEPROM */
218206a1038SHadli, Manjunath davinci_sync_env_enetaddr(enetaddr);
219206a1038SHadli, Manjunath } else {
220206a1038SHadli, Manjunath /*
221206a1038SHadli, Manjunath * MAC address present in environment compare it with
222206a1038SHadli, Manjunath * the MAC address in EEPROM and warn on mismatch
223206a1038SHadli, Manjunath */
224206a1038SHadli, Manjunath if (eeprom_mac_read && memcmp(enetaddr, env_enetaddr, 6))
225206a1038SHadli, Manjunath printf("Warning: MAC address in EEPROM don't match "
226206a1038SHadli, Manjunath "with the MAC address in the environment\n");
227206a1038SHadli, Manjunath printf("Default using MAC address from environment\n");
228206a1038SHadli, Manjunath }
229206a1038SHadli, Manjunath
230206a1038SHadli, Manjunath #endif
231cf2c24e3SNagabhushana Netagunte return 0;
232cf2c24e3SNagabhushana Netagunte }
233cf2c24e3SNagabhushana Netagunte
2344aeb939eSAdam Ford #ifndef CONFIG_DM_MMC
2351d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
236ecc98ec1SLad, Prabhakar static struct davinci_mmc mmc_sd0 = {
237ecc98ec1SLad, Prabhakar .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
238ecc98ec1SLad, Prabhakar .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
239ecc98ec1SLad, Prabhakar .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
240ecc98ec1SLad, Prabhakar .version = MMC_CTLR_VERSION_2,
241ecc98ec1SLad, Prabhakar };
242ecc98ec1SLad, Prabhakar
board_mmc_init(bd_t * bis)243ecc98ec1SLad, Prabhakar int board_mmc_init(bd_t *bis)
244ecc98ec1SLad, Prabhakar {
245ecc98ec1SLad, Prabhakar mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
246ecc98ec1SLad, Prabhakar
247ecc98ec1SLad, Prabhakar /* Add slot-0 to mmc subsystem */
248ecc98ec1SLad, Prabhakar return davinci_mmc_init(bis, &mmc_sd0);
249ecc98ec1SLad, Prabhakar }
250ecc98ec1SLad, Prabhakar #endif
2514aeb939eSAdam Ford #endif
252ecc98ec1SLad, Prabhakar
25352b0f877SChristian Riesch static const struct pinmux_config gpio_pins[] = {
25452b0f877SChristian Riesch #ifdef CONFIG_USE_NOR
25552b0f877SChristian Riesch /* GP0[11] is required for NOR to work on Rev 3 EVMs */
25652b0f877SChristian Riesch { pinmux(0), 8, 4 }, /* GP0[11] */
25752b0f877SChristian Riesch #endif
2581d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
259ecc98ec1SLad, Prabhakar /* GP0[11] is required for SD to work on Rev 3 EVMs */
260ecc98ec1SLad, Prabhakar { pinmux(0), 8, 4 }, /* GP0[11] */
261ecc98ec1SLad, Prabhakar #endif
26252b0f877SChristian Riesch };
26352b0f877SChristian Riesch
2643d2c8e6cSChristian Riesch const struct pinmux_resource pinmuxes[] = {
265591d8019SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC
26652b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mdio),
26752b0f877SChristian Riesch #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
26852b0f877SChristian Riesch PINMUX_ITEM(emac_pins_rmii),
26952b0f877SChristian Riesch #else
27052b0f877SChristian Riesch PINMUX_ITEM(emac_pins_mii),
27152b0f877SChristian Riesch #endif
272591d8019SChristian Riesch #endif
27389b765c7SSudhakar Rajashekhara #ifdef CONFIG_SPI_FLASH
27452b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_base),
27552b0f877SChristian Riesch PINMUX_ITEM(spi1_pins_scs0),
27689b765c7SSudhakar Rajashekhara #endif
27752b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_txrx),
27852b0f877SChristian Riesch PINMUX_ITEM(uart2_pins_rtscts),
27952b0f877SChristian Riesch PINMUX_ITEM(i2c0_pins),
280756d1fe7SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
28152b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs3),
28252b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs4),
28352b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nand),
2841506b0a8SNagabhushana Netagunte #elif defined(CONFIG_USE_NOR)
28552b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_cs2),
28652b0f877SChristian Riesch PINMUX_ITEM(emifa_pins_nor),
287756d1fe7SBen Gardiner #endif
28852b0f877SChristian Riesch PINMUX_ITEM(gpio_pins),
2891d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
290ecc98ec1SLad, Prabhakar PINMUX_ITEM(mmc0_pins),
291ecc98ec1SLad, Prabhakar #endif
29289b765c7SSudhakar Rajashekhara };
29389b765c7SSudhakar Rajashekhara
2943d2c8e6cSChristian Riesch const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
2953d2c8e6cSChristian Riesch
2966b873dcaSSughosh Ganu const struct lpsc_resource lpsc[] = {
29789b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
29889b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
29989b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_EMAC }, /* image download */
30089b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_UART2 }, /* console */
30189b765c7SSudhakar Rajashekhara { DAVINCI_LPSC_GPIO },
3021d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
303ecc98ec1SLad, Prabhakar { DAVINCI_LPSC_MMC_SD },
304ecc98ec1SLad, Prabhakar #endif
30589b765c7SSudhakar Rajashekhara };
30689b765c7SSudhakar Rajashekhara
3076b873dcaSSughosh Ganu const int lpsc_size = ARRAY_SIZE(lpsc);
3086b873dcaSSughosh Ganu
3094f6fc15bSSekhar Nori #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
3104f6fc15bSSekhar Nori #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000
3114f6fc15bSSekhar Nori #endif
3124f6fc15bSSekhar Nori
313754f8cb6SManjunath Hadli #define REV_AM18X_EVM 0x100
314754f8cb6SManjunath Hadli
3154f6fc15bSSekhar Nori /*
3164f6fc15bSSekhar Nori * get_board_rev() - setup to pass kernel board revision information
3174f6fc15bSSekhar Nori * Returns:
3184f6fc15bSSekhar Nori * bit[0-3] Maximum cpu clock rate supported by onboard SoC
3194f6fc15bSSekhar Nori * 0000b - 300 MHz
3204f6fc15bSSekhar Nori * 0001b - 372 MHz
3214f6fc15bSSekhar Nori * 0010b - 408 MHz
3224f6fc15bSSekhar Nori * 0011b - 456 MHz
3234f6fc15bSSekhar Nori */
get_board_rev(void)3244f6fc15bSSekhar Nori u32 get_board_rev(void)
3254f6fc15bSSekhar Nori {
3264f6fc15bSSekhar Nori char *s;
3274f6fc15bSSekhar Nori u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
3284f6fc15bSSekhar Nori u32 rev = 0;
3294f6fc15bSSekhar Nori
33000caae6dSSimon Glass s = env_get("maxcpuclk");
3314f6fc15bSSekhar Nori if (s)
3324f6fc15bSSekhar Nori maxcpuclk = simple_strtoul(s, NULL, 10);
3334f6fc15bSSekhar Nori
3344f6fc15bSSekhar Nori if (maxcpuclk >= 456000000)
3354f6fc15bSSekhar Nori rev = 3;
3364f6fc15bSSekhar Nori else if (maxcpuclk >= 408000000)
3374f6fc15bSSekhar Nori rev = 2;
3384f6fc15bSSekhar Nori else if (maxcpuclk >= 372000000)
3394f6fc15bSSekhar Nori rev = 1;
340754f8cb6SManjunath Hadli #ifdef CONFIG_DA850_AM18X_EVM
341754f8cb6SManjunath Hadli rev |= REV_AM18X_EVM;
342754f8cb6SManjunath Hadli #endif
3434f6fc15bSSekhar Nori return rev;
3444f6fc15bSSekhar Nori }
3454f6fc15bSSekhar Nori
board_early_init_f(void)346ae5c77ddSChristian Riesch int board_early_init_f(void)
347ae5c77ddSChristian Riesch {
348ae5c77ddSChristian Riesch /*
349ae5c77ddSChristian Riesch * Power on required peripherals
350ae5c77ddSChristian Riesch * ARM does not have access by default to PSC0 and PSC1
351ae5c77ddSChristian Riesch * assuming here that the DSP bootloader has set the IOPU
352ae5c77ddSChristian Riesch * such that PSC access is available to ARM
353ae5c77ddSChristian Riesch */
354ae5c77ddSChristian Riesch if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
355ae5c77ddSChristian Riesch return 1;
356ae5c77ddSChristian Riesch
357ae5c77ddSChristian Riesch return 0;
358ae5c77ddSChristian Riesch }
359ae5c77ddSChristian Riesch
board_init(void)36089b765c7SSudhakar Rajashekhara int board_init(void)
36189b765c7SSudhakar Rajashekhara {
36289b765c7SSudhakar Rajashekhara irq_init();
36389b765c7SSudhakar Rajashekhara
364a3f88293SBen Gardiner #ifdef CONFIG_NAND_DAVINCI
365a3f88293SBen Gardiner /*
366a3f88293SBen Gardiner * NAND CS setup - cycle counts based on da850evm NAND timings in the
367a3f88293SBen Gardiner * Linux kernel @ 25MHz EMIFA
368a3f88293SBen Gardiner */
369de94b80dSLad, Prabhakar writel((DAVINCI_ABCR_WSETUP(2) |
370de94b80dSLad, Prabhakar DAVINCI_ABCR_WSTROBE(2) |
371de94b80dSLad, Prabhakar DAVINCI_ABCR_WHOLD(1) |
372de94b80dSLad, Prabhakar DAVINCI_ABCR_RSETUP(1) |
373de94b80dSLad, Prabhakar DAVINCI_ABCR_RSTROBE(4) |
374a3f88293SBen Gardiner DAVINCI_ABCR_RHOLD(0) |
37524a514c4SBen Gardiner DAVINCI_ABCR_TA(1) |
376a3f88293SBen Gardiner DAVINCI_ABCR_ASIZE_8BIT),
377a3f88293SBen Gardiner &davinci_emif_regs->ab2cr); /* CS3 */
378a3f88293SBen Gardiner #endif
379a3f88293SBen Gardiner
38089b765c7SSudhakar Rajashekhara /* arch number of the board */
38189b765c7SSudhakar Rajashekhara gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
38289b765c7SSudhakar Rajashekhara
38389b765c7SSudhakar Rajashekhara /* address of boot parameters */
38489b765c7SSudhakar Rajashekhara gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
38589b765c7SSudhakar Rajashekhara
38689b765c7SSudhakar Rajashekhara /* setup the SUSPSRC for ARM to control emulation suspend */
38789b765c7SSudhakar Rajashekhara writel(readl(&davinci_syscfg_regs->suspsrc) &
38889b765c7SSudhakar Rajashekhara ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
38989b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
39089b765c7SSudhakar Rajashekhara DAVINCI_SYSCFG_SUSPSRC_UART2),
39189b765c7SSudhakar Rajashekhara &davinci_syscfg_regs->suspsrc);
39289b765c7SSudhakar Rajashekhara
39389b765c7SSudhakar Rajashekhara /* configure pinmux settings */
39489b765c7SSudhakar Rajashekhara if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
39589b765c7SSudhakar Rajashekhara return 1;
39689b765c7SSudhakar Rajashekhara
3970f3d6b06SNagabhushana Netagunte #ifdef CONFIG_USE_NOR
3980f3d6b06SNagabhushana Netagunte /* Set the GPIO direction as output */
3993864cb21SChristian Riesch clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
4000f3d6b06SNagabhushana Netagunte
4010f3d6b06SNagabhushana Netagunte /* Set the output as low */
4023864cb21SChristian Riesch writel(0x01 << 11, GPIO_BANK0_REG_CLR_ADDR);
4030f3d6b06SNagabhushana Netagunte #endif
4040f3d6b06SNagabhushana Netagunte
4051d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
4066652c62eSRajashekhara, Sudhakar /* Set the GPIO direction as output */
4076652c62eSRajashekhara, Sudhakar clrbits_le32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
4086652c62eSRajashekhara, Sudhakar
4096652c62eSRajashekhara, Sudhakar /* Set the output as high */
4103864cb21SChristian Riesch writel(0x01 << 11, GPIO_BANK0_REG_SET_ADDR);
4116652c62eSRajashekhara, Sudhakar #endif
4126652c62eSRajashekhara, Sudhakar
4133d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
4146d1c649fSStefano Babic davinci_emac_mii_mode_sel(HAS_RMII);
4153d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
4163d248d37SBen Gardiner
41789b765c7SSudhakar Rajashekhara /* enable the console UART */
41889b765c7SSudhakar Rajashekhara writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
41989b765c7SSudhakar Rajashekhara DAVINCI_UART_PWREMU_MGMT_UTRST),
42089b765c7SSudhakar Rajashekhara &davinci_uart2_ctrl_regs->pwremu_mgmt);
42189b765c7SSudhakar Rajashekhara
42289b765c7SSudhakar Rajashekhara return 0;
42389b765c7SSudhakar Rajashekhara }
4243d248d37SBen Gardiner
4253d248d37SBen Gardiner #ifdef CONFIG_DRIVER_TI_EMAC
4263d248d37SBen Gardiner
427d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
428d2607401SSudhakar Rajashekhara /**
429d2607401SSudhakar Rajashekhara * rmii_hw_init
430d2607401SSudhakar Rajashekhara *
431d2607401SSudhakar Rajashekhara * DA850/OMAP-L138 EVM can interface to a daughter card for
432d2607401SSudhakar Rajashekhara * additional features. This card has an I2C GPIO Expander TCA6416
433d2607401SSudhakar Rajashekhara * to select the required functions like camera, RMII Ethernet,
434d2607401SSudhakar Rajashekhara * character LCD, video.
435d2607401SSudhakar Rajashekhara *
436d2607401SSudhakar Rajashekhara * Initialization of the expander involves configuring the
437d2607401SSudhakar Rajashekhara * polarity and direction of the ports. P07-P05 are used here.
438d2607401SSudhakar Rajashekhara * These ports are connected to a Mux chip which enables only one
439d2607401SSudhakar Rajashekhara * functionality at a time.
440d2607401SSudhakar Rajashekhara *
441d2607401SSudhakar Rajashekhara * For RMII phy to respond, the MII MDIO clock has to be disabled
442d2607401SSudhakar Rajashekhara * since both the PHY devices have address as zero. The MII MDIO
443d2607401SSudhakar Rajashekhara * clock is controlled via GPIO2[6].
444d2607401SSudhakar Rajashekhara *
445d2607401SSudhakar Rajashekhara * This code is valid for Beta version of the hardware
446d2607401SSudhakar Rajashekhara */
rmii_hw_init(void)447d2607401SSudhakar Rajashekhara int rmii_hw_init(void)
448d2607401SSudhakar Rajashekhara {
449d2607401SSudhakar Rajashekhara const struct pinmux_config gpio_pins[] = {
450d2607401SSudhakar Rajashekhara { pinmux(6), 8, 1 }
451d2607401SSudhakar Rajashekhara };
452d2607401SSudhakar Rajashekhara u_int8_t buf[2];
453d2607401SSudhakar Rajashekhara unsigned int temp;
454d2607401SSudhakar Rajashekhara int ret;
455d2607401SSudhakar Rajashekhara
456d2607401SSudhakar Rajashekhara /* PinMux for GPIO */
457d2607401SSudhakar Rajashekhara if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
458d2607401SSudhakar Rajashekhara return 1;
459d2607401SSudhakar Rajashekhara
460d2607401SSudhakar Rajashekhara /* I2C Exapnder configuration */
461d2607401SSudhakar Rajashekhara /* Set polarity to non-inverted */
462d2607401SSudhakar Rajashekhara buf[0] = 0x0;
463d2607401SSudhakar Rajashekhara buf[1] = 0x0;
464d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
465d2607401SSudhakar Rajashekhara if (ret) {
466d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n",
467d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR);
468d2607401SSudhakar Rajashekhara return ret;
469d2607401SSudhakar Rajashekhara }
470d2607401SSudhakar Rajashekhara
471d2607401SSudhakar Rajashekhara /* Configure P07-P05 as outputs */
472d2607401SSudhakar Rajashekhara buf[0] = 0x1f;
473d2607401SSudhakar Rajashekhara buf[1] = 0xff;
474d2607401SSudhakar Rajashekhara ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
475d2607401SSudhakar Rajashekhara if (ret) {
476d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n",
477d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR);
478d2607401SSudhakar Rajashekhara }
479d2607401SSudhakar Rajashekhara
480d2607401SSudhakar Rajashekhara /* For Ethernet RMII selection
481d2607401SSudhakar Rajashekhara * P07(SelA)=0
482d2607401SSudhakar Rajashekhara * P06(SelB)=1
483d2607401SSudhakar Rajashekhara * P05(SelC)=1
484d2607401SSudhakar Rajashekhara */
485d2607401SSudhakar Rajashekhara if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
486d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x read FAILED!!!\n",
487d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR);
488d2607401SSudhakar Rajashekhara }
489d2607401SSudhakar Rajashekhara
490d2607401SSudhakar Rajashekhara buf[0] &= 0x1f;
491d2607401SSudhakar Rajashekhara buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
492d2607401SSudhakar Rajashekhara if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
493d2607401SSudhakar Rajashekhara printf("\nExpander @ 0x%02x write FAILED!!!\n",
494d2607401SSudhakar Rajashekhara CONFIG_SYS_I2C_EXPANDER_ADDR);
495d2607401SSudhakar Rajashekhara }
496d2607401SSudhakar Rajashekhara
497d2607401SSudhakar Rajashekhara /* Set the output as high */
498d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_SET_ADDR);
499d2607401SSudhakar Rajashekhara temp |= (0x01 << 6);
500d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_SET_ADDR) = temp;
501d2607401SSudhakar Rajashekhara
502d2607401SSudhakar Rajashekhara /* Set the GPIO direction as output */
503d2607401SSudhakar Rajashekhara temp = REG(GPIO_BANK2_REG_DIR_ADDR);
504d2607401SSudhakar Rajashekhara temp &= ~(0x01 << 6);
505d2607401SSudhakar Rajashekhara REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
506d2607401SSudhakar Rajashekhara
507d2607401SSudhakar Rajashekhara return 0;
508d2607401SSudhakar Rajashekhara }
509d2607401SSudhakar Rajashekhara #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
510d2607401SSudhakar Rajashekhara
5113d248d37SBen Gardiner /*
5123d248d37SBen Gardiner * Initializes on-board ethernet controllers.
5133d248d37SBen Gardiner */
board_eth_init(bd_t * bis)5143d248d37SBen Gardiner int board_eth_init(bd_t *bis)
5153d248d37SBen Gardiner {
516d2607401SSudhakar Rajashekhara #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
517d2607401SSudhakar Rajashekhara /* Select RMII fucntion through the expander */
518d2607401SSudhakar Rajashekhara if (rmii_hw_init())
519d2607401SSudhakar Rajashekhara printf("RMII hardware init failed!!!\n");
520d2607401SSudhakar Rajashekhara #endif
5213d248d37SBen Gardiner if (!davinci_emac_initialize()) {
5223d248d37SBen Gardiner printf("Error: Ethernet init failed!\n");
5233d248d37SBen Gardiner return -1;
5243d248d37SBen Gardiner }
5253d248d37SBen Gardiner
5263d248d37SBen Gardiner return 0;
5273d248d37SBen Gardiner }
5283d248d37SBen Gardiner #endif /* CONFIG_DRIVER_TI_EMAC */
529