blob: 01328f1955c2be2fdee8728ebe9bb8f09a06bab7 [file] [log] [blame]
Vitaly Andrianov29646842015-09-19 16:26:40 +05301/*
2 * K2G EVM : Board initialization
3 *
4 * (C) Copyright 2015
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9#include <common.h>
10#include <asm/arch/clock.h>
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +053011#include <asm/ti-common/keystone_net.h>
Roger Quadros44157de2015-09-19 16:26:53 +053012#include <asm/arch/psc_defs.h>
13#include <asm/arch/mmc_host_def.h>
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050014#include <fdtdec.h>
15#include <i2c.h>
Andrew F. Daviseab8f402017-07-31 10:58:21 -050016#include <remoteproc.h>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053017#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020018#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053019
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050020#define K2G_GP_AUDIO_CODEC_ADDRESS 0x1B
21
Lokesh Vutlae22e7642017-05-03 16:58:25 +053022const unsigned int sysclk_array[MAX_SYSCLK] = {
23 19200000,
24 24000000,
25 25000000,
26 26000000,
27};
28
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053029unsigned int get_external_clk(u32 clk)
30{
31 unsigned int clk_freq;
32 u8 sysclk_index = get_sysclk_index();
33
34 switch (clk) {
35 case sys_clk:
36 clk_freq = sysclk_array[sysclk_index];
37 break;
38 case pa_clk:
39 clk_freq = sysclk_array[sysclk_index];
40 break;
41 case tetris_clk:
42 clk_freq = sysclk_array[sysclk_index];
43 break;
44 case ddr3a_clk:
45 clk_freq = sysclk_array[sysclk_index];
46 break;
47 case uart_clk:
48 clk_freq = sysclk_array[sysclk_index];
49 break;
50 default:
51 clk_freq = 0;
52 break;
53 }
54
55 return clk_freq;
56}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053057
Lokesh Vutla9027e082016-03-04 10:36:41 -060058static int arm_speeds[DEVSPEED_NUMSPDS] = {
59 SPD400,
60 SPD600,
61 SPD800,
62 SPD900,
63 SPD1000,
64 SPD900,
65 SPD800,
66 SPD600,
67 SPD400,
68 SPD200,
69};
70
71static int dev_speeds[DEVSPEED_NUMSPDS] = {
72 SPD600,
73 SPD800,
74 SPD900,
75 SPD1000,
76 SPD900,
77 SPD800,
78 SPD600,
79 SPD400,
80};
81
Lokesh Vutlae22e7642017-05-03 16:58:25 +053082static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
83 [SYSCLK_19MHz] = {
84 [SPD400] = {MAIN_PLL, 125, 3, 2},
85 [SPD600] = {MAIN_PLL, 125, 2, 2},
86 [SPD800] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053087 [SPD900] = {MAIN_PLL, 187, 2, 2},
88 [SPD1000] = {MAIN_PLL, 104, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053089 },
90 [SYSCLK_24MHz] = {
91 [SPD400] = {MAIN_PLL, 100, 3, 2},
92 [SPD600] = {MAIN_PLL, 300, 6, 2},
93 [SPD800] = {MAIN_PLL, 200, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053094 [SPD900] = {MAIN_PLL, 75, 1, 2},
95 [SPD1000] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053096 },
97 [SYSCLK_25MHz] = {
98 [SPD400] = {MAIN_PLL, 32, 1, 2},
99 [SPD600] = {MAIN_PLL, 48, 1, 2},
100 [SPD800] = {MAIN_PLL, 64, 1, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530101 [SPD900] = {MAIN_PLL, 72, 1, 2},
102 [SPD1000] = {MAIN_PLL, 80, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530103 },
104 [SYSCLK_26MHz] = {
105 [SPD400] = {MAIN_PLL, 400, 13, 2},
106 [SPD600] = {MAIN_PLL, 230, 5, 2},
107 [SPD800] = {MAIN_PLL, 123, 2, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530108 [SPD900] = {MAIN_PLL, 69, 1, 2},
109 [SPD1000] = {MAIN_PLL, 384, 5, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530110 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600111};
112
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530113static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
114 [SYSCLK_19MHz] = {
115 [SPD200] = {TETRIS_PLL, 625, 6, 10},
116 [SPD400] = {TETRIS_PLL, 125, 1, 6},
117 [SPD600] = {TETRIS_PLL, 125, 1, 4},
118 [SPD800] = {TETRIS_PLL, 333, 2, 4},
119 [SPD900] = {TETRIS_PLL, 187, 2, 2},
120 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
121 },
122 [SYSCLK_24MHz] = {
123 [SPD200] = {TETRIS_PLL, 250, 3, 10},
124 [SPD400] = {TETRIS_PLL, 100, 1, 6},
125 [SPD600] = {TETRIS_PLL, 100, 1, 4},
126 [SPD800] = {TETRIS_PLL, 400, 3, 4},
127 [SPD900] = {TETRIS_PLL, 75, 1, 2},
128 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
129 },
130 [SYSCLK_25MHz] = {
131 [SPD200] = {TETRIS_PLL, 80, 1, 10},
132 [SPD400] = {TETRIS_PLL, 96, 1, 6},
133 [SPD600] = {TETRIS_PLL, 96, 1, 4},
134 [SPD800] = {TETRIS_PLL, 128, 1, 4},
135 [SPD900] = {TETRIS_PLL, 72, 1, 2},
136 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
137 },
138 [SYSCLK_26MHz] = {
139 [SPD200] = {TETRIS_PLL, 307, 4, 10},
140 [SPD400] = {TETRIS_PLL, 369, 4, 6},
141 [SPD600] = {TETRIS_PLL, 369, 4, 4},
142 [SPD800] = {TETRIS_PLL, 123, 1, 4},
143 [SPD900] = {TETRIS_PLL, 69, 1, 2},
144 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
145 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600146};
147
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530148static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
149 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
150 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
151 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
152 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
153};
154
155static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
156 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
157 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
158 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
159 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
160};
161
162static struct pll_init_data ddr3_pll_config[MAX_SYSCLK] = {
163 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
164 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
165 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
166 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
167};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530168
169struct pll_init_data *get_pll_init_data(int pll)
170{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600171 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530172 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530173 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530174
175 switch (pll) {
176 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600177 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530178 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530179 break;
180 case TETRIS_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600181 speed = get_max_arm_speed(arm_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530182 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530183 break;
184 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530185 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530186 break;
187 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530188 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530189 break;
190 case DDR3_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530191 data = &ddr3_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530192 break;
193 default:
194 data = NULL;
195 }
196
197 return data;
198}
199
200s16 divn_val[16] = {
201 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
202};
203
Masahiro Yamada0a780172017-05-09 20:31:39 +0900204#if defined(CONFIG_MMC)
Roger Quadros44157de2015-09-19 16:26:53 +0530205int board_mmc_init(bd_t *bis)
206{
207 if (psc_enable_module(KS2_LPSC_MMC)) {
208 printf("%s module enabled failed\n", __func__);
209 return -1;
210 }
211
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500212 if (board_is_k2g_gp())
213 omap_mmc_init(0, 0, 0, -1, -1);
214
Roger Quadros44157de2015-09-19 16:26:53 +0530215 omap_mmc_init(1, 0, 0, -1, -1);
216 return 0;
217}
218#endif
219
Jean-Jacques Hiblot2037fa42017-09-15 12:57:24 +0200220#if defined(CONFIG_MULTI_DTB_FIT)
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500221int board_fit_config_name_match(const char *name)
222{
223 bool eeprom_read = board_ti_was_eeprom_read();
224
225 if (!strcmp(name, "keystone-k2g-generic") && !eeprom_read)
226 return 0;
227 else if (!strcmp(name, "keystone-k2g-evm") && board_ti_is("66AK2GGP"))
228 return 0;
Cooper Jr., Franklina66a4c72017-06-16 17:25:32 -0500229 else if (!strcmp(name, "keystone-k2g-ice") && board_ti_is("66AK2GIC"))
230 return 0;
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500231 else
232 return -1;
233}
234#endif
235
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500236#if defined(CONFIG_DTB_RESELECT)
237static int k2g_alt_board_detect(void)
238{
239 int rc;
240
241 rc = i2c_set_bus_num(1);
242 if (rc)
243 return rc;
244
245 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
246 if (rc)
247 return rc;
248
249 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
250
251 return 0;
252}
253
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530254static void k2g_reset_mux_config(void)
255{
256 /* Unlock the reset mux register */
257 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
258
259 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
260 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
261 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
262
263 /* lock the reset mux register to prevent any spurious writes. */
264 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
265}
266
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500267int embedded_dtb_select(void)
Vitaly Andrianov29646842015-09-19 16:26:40 +0530268{
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500269 int rc;
270 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
271 CONFIG_EEPROM_CHIP_ADDRESS);
272 if (rc) {
273 rc = k2g_alt_board_detect();
274 if (rc) {
275 printf("Unable to do board detection\n");
276 return -1;
277 }
278 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530279
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500280 fdtdec_setup();
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530281
Cooper Jr., Franklinf4bfac82017-06-16 17:25:23 -0500282 k2g_mux_config();
283
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530284 k2g_reset_mux_config();
285
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500286 if (board_is_k2g_gp()) {
287 /* deassert FLASH_HOLD */
288 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
289 BIT(9));
290 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
291 BIT(9));
292 }
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530293
Vitaly Andrianov29646842015-09-19 16:26:40 +0530294 return 0;
295}
296#endif
297
Roger Quadros601ab902017-03-13 15:04:32 +0200298#ifdef CONFIG_BOARD_LATE_INIT
299int board_late_init(void)
300{
301#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
302 int rc;
303
304 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
305 CONFIG_EEPROM_CHIP_ADDRESS);
306 if (rc)
307 printf("ti_i2c_eeprom_init failed %d\n", rc);
308
309 board_ti_set_ethaddr(1);
310#endif
311
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500312#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
313 if (board_is_k2g_gp())
Simon Glass6a38e412017-08-03 12:22:09 -0600314 env_set("board_name", "66AK2GGP\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500315 else if (board_is_k2g_ice())
Simon Glass6a38e412017-08-03 12:22:09 -0600316 env_set("board_name", "66AK2GIC\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500317#endif
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500318 return 0;
319}
320#endif
321
322#ifdef CONFIG_BOARD_EARLY_INIT_F
323int board_early_init_f(void)
324{
325 init_plls();
326
327 k2g_mux_config();
328
Roger Quadros601ab902017-03-13 15:04:32 +0200329 return 0;
330}
331#endif
332
Vitaly Andrianov29646842015-09-19 16:26:40 +0530333#ifdef CONFIG_SPL_BUILD
334void spl_init_keystone_plls(void)
335{
336 init_plls();
337}
338#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530339
340#ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
341struct eth_priv_t eth_priv_cfg[] = {
342 {
343 .int_name = "K2G_EMAC",
344 .rx_flow = 0,
345 .phy_addr = 0,
346 .slave_port = 1,
347 .sgmii_link_type = SGMII_LINK_MAC_PHY,
348 .phy_if = PHY_INTERFACE_MODE_RGMII,
349 },
350};
351
352int get_num_eth_ports(void)
353{
354 return sizeof(eth_priv_cfg) / sizeof(struct eth_priv_t);
355}
356#endif
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500357
358#ifdef CONFIG_TI_SECURE_DEVICE
359void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
360{
361 int id = getenv_ulong("dev_pmmc", 10, 0);
362 int ret;
363
364 if (!rproc_is_initialized())
365 rproc_init();
366
367 ret = rproc_load(id, pmmc_image, pmmc_size);
368 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
369 id, pmmc_image, pmmc_size, ret ? " Failed!" : " Success!");
370
371 if (!ret)
372 rproc_start(id);
373}
374
375U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_PMMC, board_pmmc_image_process);
376#endif