1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
5 * Based on da850evm.c. Original Copyrights follow:
7 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
8 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
15 #include <spi_flash.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/ti-common/davinci_nand.h>
19 #include <linux/errno.h>
20 #include <asm/mach-types.h>
21 #include <asm/arch/davinci_misc.h>
22 #ifdef CONFIG_MMC_DAVINCI
24 #include <asm/arch/sdmmc_defs.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 #define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
31 #ifdef CONFIG_MMC_DAVINCI
32 /* MMC0 pin muxer settings */
33 const struct pinmux_config mmc0_pins[] = {
34 /* GP0[11] is required for SD to work on Rev 3 EVMs */
35 { pinmux(0), 8, 4 }, /* GP0[11] */
36 { pinmux(10), 2, 0 }, /* MMCSD0_CLK */
37 { pinmux(10), 2, 1 }, /* MMCSD0_CMD */
38 { pinmux(10), 2, 2 }, /* MMCSD0_DAT_0 */
39 { pinmux(10), 2, 3 }, /* MMCSD0_DAT_1 */
40 { pinmux(10), 2, 4 }, /* MMCSD0_DAT_2 */
41 { pinmux(10), 2, 5 }, /* MMCSD0_DAT_3 */
42 /* LCDK supports only 4-bit mode, remaining pins are not configured */
46 /* UART pin muxer settings */
47 static const struct pinmux_config uart_pins[] = {
54 #ifdef CONFIG_DRIVER_TI_EMAC
55 static const struct pinmux_config emac_pins[] = {
74 #endif /* CONFIG_DRIVER_TI_EMAC */
76 /* I2C pin muxer settings */
77 static const struct pinmux_config i2c_pins[] = {
82 #ifdef CONFIG_NAND_DAVINCI
83 const struct pinmux_config nand_pins[] = {
104 { pinmux(12), 1, 5 },
110 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
116 const struct pinmux_resource pinmuxes[] = {
117 PINMUX_ITEM(uart_pins),
118 PINMUX_ITEM(i2c_pins),
119 #ifdef CONFIG_NAND_DAVINCI
120 PINMUX_ITEM(nand_pins),
124 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
126 const struct lpsc_resource lpsc[] = {
127 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
128 { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
129 { DAVINCI_LPSC_EMAC }, /* image download */
130 { DAVINCI_LPSC_UART2 }, /* console */
131 { DAVINCI_LPSC_GPIO },
132 #ifdef CONFIG_MMC_DAVINCI
133 { DAVINCI_LPSC_MMC_SD },
137 const int lpsc_size = ARRAY_SIZE(lpsc);
139 #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
140 #define CONFIG_DA850_EVM_MAX_CPU_CLK 456000000
144 * get_board_rev() - setup to pass kernel board revision information
146 * bit[0-3] Maximum cpu clock rate supported by onboard SoC
152 u32 get_board_rev(void)
157 int board_early_init_f(void)
160 * Power on required peripherals
161 * ARM does not have access by default to PSC0 and PSC1
162 * assuming here that the DSP bootloader has set the IOPU
163 * such that PSC access is available to ARM
165 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
175 /* arch number of the board */
176 gd->bd->bi_arch_number = MACH_TYPE_OMAPL138_LCDK;
178 /* address of boot parameters */
179 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
182 /* setup the SUSPSRC for ARM to control emulation suspend */
183 writel(readl(&davinci_syscfg_regs->suspsrc) &
184 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
185 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
186 DAVINCI_SYSCFG_SUSPSRC_UART2),
187 &davinci_syscfg_regs->suspsrc);
189 /* configure pinmux settings */
190 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
193 #ifdef CONFIG_NAND_DAVINCI
195 * NAND CS setup - cycle counts based on da850evm NAND timings in the
196 * Linux kernel @ 25MHz EMIFA
198 writel((DAVINCI_ABCR_WSETUP(15) |
199 DAVINCI_ABCR_WSTROBE(63) |
200 DAVINCI_ABCR_WHOLD(7) |
201 DAVINCI_ABCR_RSETUP(15) |
202 DAVINCI_ABCR_RSTROBE(63) |
203 DAVINCI_ABCR_RHOLD(7) |
205 DAVINCI_ABCR_ASIZE_16BIT),
206 &davinci_emif_regs->ab2cr); /* CS3 */
210 #ifdef CONFIG_MMC_DAVINCI
211 if (davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins)) != 0)
215 #ifdef CONFIG_DRIVER_TI_EMAC
216 if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
218 davinci_emac_mii_mode_sel(HAS_RMII);
219 #endif /* CONFIG_DRIVER_TI_EMAC */
221 /* enable the console UART */
222 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
223 DAVINCI_UART_PWREMU_MGMT_UTRST),
224 &davinci_uart2_ctrl_regs->pwremu_mgmt);
229 #ifdef CONFIG_DRIVER_TI_EMAC
231 #endif /* CONFIG_DRIVER_TI_EMAC */
233 #define CFG_MAC_ADDR_SPI_BUS 0
234 #define CFG_MAC_ADDR_SPI_CS 0
235 #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED
236 #define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3
238 #define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K)
240 static int get_mac_addr(u8 *addr)
242 /* Need to find a way to get MAC ADDRESS */
246 void dsp_lpsc_on(unsigned domain, unsigned int id)
248 dv_reg_p mdstat, mdctl, ptstat, ptcmd;
249 struct davinci_psc_regs *psc_regs;
251 psc_regs = davinci_psc0_regs;
252 mdstat = &psc_regs->psc0.mdstat[id];
253 mdctl = &psc_regs->psc0.mdctl[id];
254 ptstat = &psc_regs->ptstat;
255 ptcmd = &psc_regs->ptcmd;
257 while (*ptstat & (0x1 << domain))
260 if ((*mdstat & 0x1f) == 0x03)
261 return; /* Already on and enabled */
265 *ptcmd = 0x1 << domain;
267 while (*ptstat & (0x1 << domain))
269 while ((*mdstat & 0x1f) != 0x03)
270 ; /* Probably an overkill... */
273 static void dspwake(void)
275 unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
277 /* if the device is ARM only, return */
278 if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
281 if (!strcmp(env_get("dspwake"), "no"))
284 *resetvect++ = 0x1E000; /* DSP Idle */
285 /* clear out the next 10 words as NOP */
286 memset(resetvect, 0, sizeof(unsigned) * 10);
288 /* setup the DSP reset vector */
289 REG(HOST1CFG) = DAVINCI_L3CBARAM_BASE;
291 dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
292 REG(PSC0_MDCTL + (15 * 4)) |= 0x100;
295 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
300 int rmii_hw_init(void)
304 #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
306 int misc_init_r(void)
308 uint8_t tmp[20], addr[10];
311 if (env_get("ethaddr") == NULL) {
312 /* Read Ethernet MAC address from EEPROM */
313 if (dvevm_read_mac_address(addr)) {
314 /* Set Ethernet MAC address from EEPROM */
315 davinci_sync_env_enetaddr(addr);
320 if (!is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr)) {
321 sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x",
322 addr[0], addr[1], addr[2], addr[3], addr[4],
325 env_set("ethaddr", (char *)tmp);
327 printf("Invalid MAC address read.\n");
331 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
332 /* Select RMII fucntion through the expander */
334 printf("RMII hardware init failed!!!\n");
342 #if !CONFIG_IS_ENABLED(DM_MMC)
343 #ifdef CONFIG_MMC_DAVINCI
344 static struct davinci_mmc mmc_sd0 = {
345 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
346 .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
347 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
348 .version = MMC_CTLR_VERSION_2,
351 int board_mmc_init(bd_t *bis)
353 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
355 /* Add slot-0 to mmc subsystem */
356 return davinci_mmc_init(bis, &mmc_sd0);