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>
16 #include <asm/arch/hardware.h>
17 #include <asm/ti-common/davinci_nand.h>
20 #include <dm/platdata.h>
21 #include <linux/errno.h>
22 #include <asm/mach-types.h>
23 #include <asm/arch/davinci_misc.h>
24 #ifdef CONFIG_MMC_DAVINCI
26 #include <asm/arch/sdmmc_defs.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 #define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
33 #ifdef CONFIG_MMC_DAVINCI
34 /* MMC0 pin muxer settings */
35 const struct pinmux_config mmc0_pins[] = {
36 /* GP0[11] is required for SD to work on Rev 3 EVMs */
37 { pinmux(0), 8, 4 }, /* GP0[11] */
38 { pinmux(10), 2, 0 }, /* MMCSD0_CLK */
39 { pinmux(10), 2, 1 }, /* MMCSD0_CMD */
40 { pinmux(10), 2, 2 }, /* MMCSD0_DAT_0 */
41 { pinmux(10), 2, 3 }, /* MMCSD0_DAT_1 */
42 { pinmux(10), 2, 4 }, /* MMCSD0_DAT_2 */
43 { pinmux(10), 2, 5 }, /* MMCSD0_DAT_3 */
44 /* LCDK supports only 4-bit mode, remaining pins are not configured */
48 /* UART pin muxer settings */
49 static const struct pinmux_config uart_pins[] = {
56 #ifdef CONFIG_DRIVER_TI_EMAC
57 static const struct pinmux_config emac_pins[] = {
76 #endif /* CONFIG_DRIVER_TI_EMAC */
78 /* I2C pin muxer settings */
79 static const struct pinmux_config i2c_pins[] = {
84 #ifdef CONFIG_NAND_DAVINCI
85 const struct pinmux_config nand_pins[] = {
106 { pinmux(12), 1, 5 },
112 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
118 const struct pinmux_resource pinmuxes[] = {
119 PINMUX_ITEM(uart_pins),
120 PINMUX_ITEM(i2c_pins),
121 #ifdef CONFIG_NAND_DAVINCI
122 PINMUX_ITEM(nand_pins),
126 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
128 const struct lpsc_resource lpsc[] = {
129 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
130 { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
131 { DAVINCI_LPSC_EMAC }, /* image download */
132 { DAVINCI_LPSC_UART2 }, /* console */
133 { DAVINCI_LPSC_GPIO },
134 #ifdef CONFIG_MMC_DAVINCI
135 { DAVINCI_LPSC_MMC_SD },
139 const int lpsc_size = ARRAY_SIZE(lpsc);
141 #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
142 #define CONFIG_DA850_EVM_MAX_CPU_CLK 456000000
146 * get_board_rev() - setup to pass kernel board revision information
148 * bit[0-3] Maximum cpu clock rate supported by onboard SoC
154 u32 get_board_rev(void)
159 int board_early_init_f(void)
162 * Power on required peripherals
163 * ARM does not have access by default to PSC0 and PSC1
164 * assuming here that the DSP bootloader has set the IOPU
165 * such that PSC access is available to ARM
167 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
177 /* arch number of the board */
178 gd->bd->bi_arch_number = MACH_TYPE_OMAPL138_LCDK;
180 /* address of boot parameters */
181 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
184 /* setup the SUSPSRC for ARM to control emulation suspend */
185 writel(readl(&davinci_syscfg_regs->suspsrc) &
186 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
187 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
188 DAVINCI_SYSCFG_SUSPSRC_UART2),
189 &davinci_syscfg_regs->suspsrc);
191 /* configure pinmux settings */
192 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
195 #ifdef CONFIG_NAND_DAVINCI
197 * NAND CS setup - cycle counts based on da850evm NAND timings in the
198 * Linux kernel @ 25MHz EMIFA
200 writel((DAVINCI_ABCR_WSETUP(15) |
201 DAVINCI_ABCR_WSTROBE(63) |
202 DAVINCI_ABCR_WHOLD(7) |
203 DAVINCI_ABCR_RSETUP(15) |
204 DAVINCI_ABCR_RSTROBE(63) |
205 DAVINCI_ABCR_RHOLD(7) |
207 DAVINCI_ABCR_ASIZE_16BIT),
208 &davinci_emif_regs->ab2cr); /* CS3 */
212 #ifdef CONFIG_MMC_DAVINCI
213 if (davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins)) != 0)
217 #ifdef CONFIG_DRIVER_TI_EMAC
218 if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
220 davinci_emac_mii_mode_sel(HAS_RMII);
221 #endif /* CONFIG_DRIVER_TI_EMAC */
223 /* enable the console UART */
224 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
225 DAVINCI_UART_PWREMU_MGMT_UTRST),
226 &davinci_uart2_ctrl_regs->pwremu_mgmt);
231 #define CFG_MAC_ADDR_SPI_BUS 0
232 #define CFG_MAC_ADDR_SPI_CS 0
233 #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED
234 #define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3
236 #define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K)
238 static int get_mac_addr(u8 *addr)
240 /* Need to find a way to get MAC ADDRESS */
244 void dsp_lpsc_on(unsigned domain, unsigned int id)
246 dv_reg_p mdstat, mdctl, ptstat, ptcmd;
247 struct davinci_psc_regs *psc_regs;
249 psc_regs = davinci_psc0_regs;
250 mdstat = &psc_regs->psc0.mdstat[id];
251 mdctl = &psc_regs->psc0.mdctl[id];
252 ptstat = &psc_regs->ptstat;
253 ptcmd = &psc_regs->ptcmd;
255 while (*ptstat & (0x1 << domain))
258 if ((*mdstat & 0x1f) == 0x03)
259 return; /* Already on and enabled */
263 *ptcmd = 0x1 << domain;
265 while (*ptstat & (0x1 << domain))
267 while ((*mdstat & 0x1f) != 0x03)
268 ; /* Probably an overkill... */
271 static void dspwake(void)
273 unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
275 /* if the device is ARM only, return */
276 if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
279 if (!strcmp(env_get("dspwake"), "no"))
282 *resetvect++ = 0x1E000; /* DSP Idle */
283 /* clear out the next 10 words as NOP */
284 memset(resetvect, 0, sizeof(unsigned) * 10);
286 /* setup the DSP reset vector */
287 REG(HOST1CFG) = DAVINCI_L3CBARAM_BASE;
289 dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
290 REG(PSC0_MDCTL + (15 * 4)) |= 0x100;
293 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
298 int rmii_hw_init(void)
302 #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
304 int misc_init_r(void)
306 uint8_t tmp[20], addr[10];
309 if (env_get("ethaddr") == NULL) {
310 /* Read Ethernet MAC address from EEPROM */
311 if (dvevm_read_mac_address(addr)) {
312 /* Set Ethernet MAC address from EEPROM */
313 davinci_sync_env_enetaddr(addr);
318 if (!is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr)) {
319 sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x",
320 addr[0], addr[1], addr[2], addr[3], addr[4],
323 env_set("ethaddr", (char *)tmp);
325 printf("Invalid MAC address read.\n");
329 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
330 /* Select RMII fucntion through the expander */
332 printf("RMII hardware init failed!!!\n");
340 #if !CONFIG_IS_ENABLED(DM_MMC)
341 #ifdef CONFIG_MMC_DAVINCI
342 static struct davinci_mmc mmc_sd0 = {
343 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
344 .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
345 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
348 int board_mmc_init(struct bd_info *bis)
350 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
352 /* Add slot-0 to mmc subsystem */
353 return davinci_mmc_init(bis, &mmc_sd0);
358 #ifdef CONFIG_SPL_BUILD
359 static const struct ns16550_platdata serial_pdata = {
360 .base = DAVINCI_UART2_BASE,
363 .fcr = UART_FCR_DEFVAL,
366 U_BOOT_DEVICE(omapl138_uart) = {
367 .name = "ns16550_serial",
368 .plat = &serial_pdata,
371 static const struct davinci_mmc_plat mmc_platdata = {
372 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
376 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
377 .host_caps = MMC_MODE_4BIT,
378 .b_max = DAVINCI_MAX_BLOCKS,
382 U_BOOT_DEVICE(omapl138_mmc) = {
383 .name = "ti_da830_mmc",
384 .plat = &mmc_platdata,
387 void spl_board_init(void)
389 davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins));