blob: dd115514283d0d3a2de573984391a84df3cc7361 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Howarda868e442015-03-23 09:19:56 +11002/*
3 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 * Based on da850evm.c. Original Copyrights follow:
6 *
7 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
8 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
Peter Howarda868e442015-03-23 09:19:56 +11009 */
10
11#include <common.h>
12#include <i2c.h>
13#include <net.h>
Peter Howarda868e442015-03-23 09:19:56 +110014#include <spi.h>
15#include <spi_flash.h>
16#include <asm/arch/hardware.h>
17#include <asm/ti-common/davinci_nand.h>
18#include <asm/io.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090019#include <linux/errno.h>
Simon Glassc62db352017-05-31 19:47:48 -060020#include <asm/mach-types.h>
Peter Howarda868e442015-03-23 09:19:56 +110021#include <asm/arch/davinci_misc.h>
Masahiro Yamada1d2c0502017-01-10 13:32:07 +090022#ifdef CONFIG_MMC_DAVINCI
Peter Howarda868e442015-03-23 09:19:56 +110023#include <mmc.h>
24#include <asm/arch/sdmmc_defs.h>
25#endif
26
27DECLARE_GLOBAL_DATA_PTR;
28
29#define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
30
Masahiro Yamada1d2c0502017-01-10 13:32:07 +090031#ifdef CONFIG_MMC_DAVINCI
Peter Howarda868e442015-03-23 09:19:56 +110032/* MMC0 pin muxer settings */
33const 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 */
43};
44#endif
45
46/* UART pin muxer settings */
47static const struct pinmux_config uart_pins[] = {
48 { pinmux(0), 4, 6 },
49 { pinmux(0), 4, 7 },
50 { pinmux(4), 2, 4 },
51 { pinmux(4), 2, 5 }
52};
53
54#ifdef CONFIG_DRIVER_TI_EMAC
55static const struct pinmux_config emac_pins[] = {
56 { pinmux(2), 8, 1 },
57 { pinmux(2), 8, 2 },
58 { pinmux(2), 8, 3 },
59 { pinmux(2), 8, 4 },
60 { pinmux(2), 8, 5 },
61 { pinmux(2), 8, 6 },
62 { pinmux(2), 8, 7 },
63 { pinmux(3), 8, 0 },
64 { pinmux(3), 8, 1 },
65 { pinmux(3), 8, 2 },
66 { pinmux(3), 8, 3 },
67 { pinmux(3), 8, 4 },
68 { pinmux(3), 8, 5 },
69 { pinmux(3), 8, 6 },
70 { pinmux(3), 8, 7 },
71 { pinmux(4), 8, 0 },
72 { pinmux(4), 8, 1 }
73};
74#endif /* CONFIG_DRIVER_TI_EMAC */
75
76/* I2C pin muxer settings */
77static const struct pinmux_config i2c_pins[] = {
78 { pinmux(4), 2, 2 },
79 { pinmux(4), 2, 3 }
80};
81
82#ifdef CONFIG_NAND_DAVINCI
83const struct pinmux_config nand_pins[] = {
84 { pinmux(7), 1, 1 },
85 { pinmux(7), 1, 2 },
86 { pinmux(7), 1, 4 },
87 { pinmux(7), 1, 5 },
88 { pinmux(8), 1, 0 },
89 { pinmux(8), 1, 1 },
90 { pinmux(8), 1, 2 },
91 { pinmux(8), 1, 3 },
92 { pinmux(8), 1, 4 },
93 { pinmux(8), 1, 5 },
94 { pinmux(8), 1, 6 },
95 { pinmux(8), 1, 7 },
96 { pinmux(9), 1, 0 },
97 { pinmux(9), 1, 1 },
98 { pinmux(9), 1, 2 },
99 { pinmux(9), 1, 3 },
100 { pinmux(9), 1, 4 },
101 { pinmux(9), 1, 5 },
102 { pinmux(9), 1, 6 },
103 { pinmux(9), 1, 7 },
104 { pinmux(12), 1, 5 },
105 { pinmux(12), 1, 6 }
106};
107
108#endif
109
110#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
111#define HAS_RMII 1
112#else
113#define HAS_RMII 0
114#endif
115
116const struct pinmux_resource pinmuxes[] = {
117 PINMUX_ITEM(uart_pins),
118 PINMUX_ITEM(i2c_pins),
119#ifdef CONFIG_NAND_DAVINCI
120 PINMUX_ITEM(nand_pins),
121#endif
122};
123
124const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
125
126const 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 },
Masahiro Yamada1d2c0502017-01-10 13:32:07 +0900132#ifdef CONFIG_MMC_DAVINCI
Peter Howarda868e442015-03-23 09:19:56 +1100133 { DAVINCI_LPSC_MMC_SD },
134#endif
135};
136
137const int lpsc_size = ARRAY_SIZE(lpsc);
138
139#ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
140#define CONFIG_DA850_EVM_MAX_CPU_CLK 456000000
141#endif
142
143/*
144 * get_board_rev() - setup to pass kernel board revision information
145 * Returns:
146 * bit[0-3] Maximum cpu clock rate supported by onboard SoC
147 * 0000b - 300 MHz
148 * 0001b - 372 MHz
149 * 0010b - 408 MHz
150 * 0011b - 456 MHz
151 */
152u32 get_board_rev(void)
153{
154 return 0;
155}
156
157int board_early_init_f(void)
158{
159 /*
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
164 */
165 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
166 return 1;
167
168 return 0;
169}
170
171int board_init(void)
172{
Peter Howarda868e442015-03-23 09:19:56 +1100173 irq_init();
Peter Howarda868e442015-03-23 09:19:56 +1100174
Tom Rini94ba26f2017-01-25 20:42:35 -0500175 /* arch number of the board */
176 gd->bd->bi_arch_number = MACH_TYPE_OMAPL138_LCDK;
177
Peter Howarda868e442015-03-23 09:19:56 +1100178 /* address of boot parameters */
179 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
180
181
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);
188
189 /* configure pinmux settings */
190 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
191 return 1;
192
193#ifdef CONFIG_NAND_DAVINCI
194 /*
195 * NAND CS setup - cycle counts based on da850evm NAND timings in the
196 * Linux kernel @ 25MHz EMIFA
197 */
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) |
204 DAVINCI_ABCR_TA(3) |
205 DAVINCI_ABCR_ASIZE_16BIT),
206 &davinci_emif_regs->ab2cr); /* CS3 */
207#endif
208
209
Masahiro Yamada1d2c0502017-01-10 13:32:07 +0900210#ifdef CONFIG_MMC_DAVINCI
Peter Howarda868e442015-03-23 09:19:56 +1100211 if (davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins)) != 0)
212 return 1;
213#endif
214
215#ifdef CONFIG_DRIVER_TI_EMAC
216 if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
217 return 1;
218 davinci_emac_mii_mode_sel(HAS_RMII);
219#endif /* CONFIG_DRIVER_TI_EMAC */
220
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);
225
226 return 0;
227}
228
229#ifdef CONFIG_DRIVER_TI_EMAC
230
Peter Howarda868e442015-03-23 09:19:56 +1100231#endif /* CONFIG_DRIVER_TI_EMAC */
232
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
237
238#define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K)
239
240static int get_mac_addr(u8 *addr)
241{
242 /* Need to find a way to get MAC ADDRESS */
243 return 0;
244}
245
246void dsp_lpsc_on(unsigned domain, unsigned int id)
247{
248 dv_reg_p mdstat, mdctl, ptstat, ptcmd;
249 struct davinci_psc_regs *psc_regs;
250
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;
256
257 while (*ptstat & (0x1 << domain))
258 ;
259
260 if ((*mdstat & 0x1f) == 0x03)
261 return; /* Already on and enabled */
262
263 *mdctl |= 0x03;
264
265 *ptcmd = 0x1 << domain;
266
267 while (*ptstat & (0x1 << domain))
268 ;
269 while ((*mdstat & 0x1f) != 0x03)
270 ; /* Probably an overkill... */
271}
272
273static void dspwake(void)
274{
275 unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
276
277 /* if the device is ARM only, return */
278 if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
279 return;
280
Simon Glass00caae62017-08-03 12:22:12 -0600281 if (!strcmp(env_get("dspwake"), "no"))
Peter Howarda868e442015-03-23 09:19:56 +1100282 return;
283
284 *resetvect++ = 0x1E000; /* DSP Idle */
285 /* clear out the next 10 words as NOP */
286 memset(resetvect, 0, sizeof(unsigned) * 10);
287
288 /* setup the DSP reset vector */
289 REG(HOST1CFG) = DAVINCI_L3CBARAM_BASE;
290
291 dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
292 REG(PSC0_MDCTL + (15 * 4)) |= 0x100;
293}
294
295#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
296/**
297 * rmii_hw_init
298 *
299 */
300int rmii_hw_init(void)
301{
302 return 0;
303}
304#endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
305
306int misc_init_r(void)
307{
308 uint8_t tmp[20], addr[10];
309
310
Simon Glass00caae62017-08-03 12:22:12 -0600311 if (env_get("ethaddr") == NULL) {
Peter Howarda868e442015-03-23 09:19:56 +1100312 /* 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);
316 } else {
317 get_mac_addr(addr);
318 }
319
Fabien Parent02c2de62016-11-10 17:16:35 +0100320 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],
323 addr[5]);
Peter Howarda868e442015-03-23 09:19:56 +1100324
Simon Glass382bee52017-08-03 12:22:09 -0600325 env_set("ethaddr", (char *)tmp);
Fabien Parent02c2de62016-11-10 17:16:35 +0100326 } else {
327 printf("Invalid MAC address read.\n");
328 }
Peter Howarda868e442015-03-23 09:19:56 +1100329 }
Fabien Parent02c2de62016-11-10 17:16:35 +0100330
Peter Howarda868e442015-03-23 09:19:56 +1100331#ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
332 /* Select RMII fucntion through the expander */
333 if (rmii_hw_init())
334 printf("RMII hardware init failed!!!\n");
335#endif
336
337 dspwake();
338
339 return 0;
340}
341
Sekhar Nori4fddaf22019-05-30 19:04:54 +0530342#if !CONFIG_IS_ENABLED(DM_MMC)
Masahiro Yamada1d2c0502017-01-10 13:32:07 +0900343#ifdef CONFIG_MMC_DAVINCI
Peter Howarda868e442015-03-23 09:19:56 +1100344static 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,
349};
350
351int board_mmc_init(bd_t *bis)
352{
353 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
354
355 /* Add slot-0 to mmc subsystem */
356 return davinci_mmc_init(bis, &mmc_sd0);
357}
358#endif
Adam Ford21af33e2018-08-09 06:15:14 -0500359#endif