blob: c6a14a05546959a7ae5a04abfef18e0053dde61b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov29646842015-09-19 16:26:40 +05302/*
3 * K2G EVM : Board initialization
4 *
5 * (C) Copyright 2015
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov29646842015-09-19 16:26:40 +05307 */
8#include <common.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -07009#include <eeprom.h>
Simon Glass6eaea252019-08-01 09:46:48 -060010#include <env.h>
Simon Glassf11478f2019-12-28 10:45:07 -070011#include <hang.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Vitaly Andrianov29646842015-09-19 16:26:40 +053013#include <asm/arch/clock.h>
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +053014#include <asm/ti-common/keystone_net.h>
Roger Quadros44157de2015-09-19 16:26:53 +053015#include <asm/arch/psc_defs.h>
16#include <asm/arch/mmc_host_def.h>
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050017#include <fdtdec.h>
18#include <i2c.h>
Andrew F. Daviseab8f402017-07-31 10:58:21 -050019#include <remoteproc.h>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053020#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020021#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053022
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050023#define K2G_GP_AUDIO_CODEC_ADDRESS 0x1B
24
Lokesh Vutlae22e7642017-05-03 16:58:25 +053025const unsigned int sysclk_array[MAX_SYSCLK] = {
26 19200000,
27 24000000,
28 25000000,
29 26000000,
30};
31
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053032unsigned int get_external_clk(u32 clk)
33{
34 unsigned int clk_freq;
35 u8 sysclk_index = get_sysclk_index();
36
37 switch (clk) {
38 case sys_clk:
39 clk_freq = sysclk_array[sysclk_index];
40 break;
41 case pa_clk:
42 clk_freq = sysclk_array[sysclk_index];
43 break;
44 case tetris_clk:
45 clk_freq = sysclk_array[sysclk_index];
46 break;
47 case ddr3a_clk:
48 clk_freq = sysclk_array[sysclk_index];
49 break;
50 case uart_clk:
51 clk_freq = sysclk_array[sysclk_index];
52 break;
53 default:
54 clk_freq = 0;
55 break;
56 }
57
58 return clk_freq;
59}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053060
Rex Chang4df43d42017-12-28 20:39:59 +053061int speeds[DEVSPEED_NUMSPDS] = {
Lokesh Vutla9027e082016-03-04 10:36:41 -060062 SPD400,
63 SPD600,
64 SPD800,
65 SPD900,
66 SPD1000,
67 SPD900,
68 SPD800,
69 SPD600,
70 SPD400,
71 SPD200,
72};
73
74static int dev_speeds[DEVSPEED_NUMSPDS] = {
75 SPD600,
76 SPD800,
77 SPD900,
78 SPD1000,
79 SPD900,
80 SPD800,
81 SPD600,
82 SPD400,
83};
84
Lokesh Vutlae22e7642017-05-03 16:58:25 +053085static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
86 [SYSCLK_19MHz] = {
87 [SPD400] = {MAIN_PLL, 125, 3, 2},
88 [SPD600] = {MAIN_PLL, 125, 2, 2},
89 [SPD800] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053090 [SPD900] = {MAIN_PLL, 187, 2, 2},
91 [SPD1000] = {MAIN_PLL, 104, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053092 },
93 [SYSCLK_24MHz] = {
94 [SPD400] = {MAIN_PLL, 100, 3, 2},
95 [SPD600] = {MAIN_PLL, 300, 6, 2},
96 [SPD800] = {MAIN_PLL, 200, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053097 [SPD900] = {MAIN_PLL, 75, 1, 2},
98 [SPD1000] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053099 },
100 [SYSCLK_25MHz] = {
101 [SPD400] = {MAIN_PLL, 32, 1, 2},
102 [SPD600] = {MAIN_PLL, 48, 1, 2},
103 [SPD800] = {MAIN_PLL, 64, 1, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530104 [SPD900] = {MAIN_PLL, 72, 1, 2},
105 [SPD1000] = {MAIN_PLL, 80, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530106 },
107 [SYSCLK_26MHz] = {
108 [SPD400] = {MAIN_PLL, 400, 13, 2},
109 [SPD600] = {MAIN_PLL, 230, 5, 2},
110 [SPD800] = {MAIN_PLL, 123, 2, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530111 [SPD900] = {MAIN_PLL, 69, 1, 2},
112 [SPD1000] = {MAIN_PLL, 384, 5, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530113 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600114};
115
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530116static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
117 [SYSCLK_19MHz] = {
118 [SPD200] = {TETRIS_PLL, 625, 6, 10},
119 [SPD400] = {TETRIS_PLL, 125, 1, 6},
120 [SPD600] = {TETRIS_PLL, 125, 1, 4},
121 [SPD800] = {TETRIS_PLL, 333, 2, 4},
122 [SPD900] = {TETRIS_PLL, 187, 2, 2},
123 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
124 },
125 [SYSCLK_24MHz] = {
126 [SPD200] = {TETRIS_PLL, 250, 3, 10},
127 [SPD400] = {TETRIS_PLL, 100, 1, 6},
128 [SPD600] = {TETRIS_PLL, 100, 1, 4},
129 [SPD800] = {TETRIS_PLL, 400, 3, 4},
130 [SPD900] = {TETRIS_PLL, 75, 1, 2},
131 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
132 },
133 [SYSCLK_25MHz] = {
134 [SPD200] = {TETRIS_PLL, 80, 1, 10},
135 [SPD400] = {TETRIS_PLL, 96, 1, 6},
136 [SPD600] = {TETRIS_PLL, 96, 1, 4},
137 [SPD800] = {TETRIS_PLL, 128, 1, 4},
138 [SPD900] = {TETRIS_PLL, 72, 1, 2},
139 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
140 },
141 [SYSCLK_26MHz] = {
142 [SPD200] = {TETRIS_PLL, 307, 4, 10},
143 [SPD400] = {TETRIS_PLL, 369, 4, 6},
144 [SPD600] = {TETRIS_PLL, 369, 4, 4},
145 [SPD800] = {TETRIS_PLL, 123, 1, 4},
146 [SPD900] = {TETRIS_PLL, 69, 1, 2},
147 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
148 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600149};
150
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530151static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
152 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
153 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
154 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
155 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
156};
157
158static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
159 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
160 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
161 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
162 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
163};
164
Rex Chang4df43d42017-12-28 20:39:59 +0530165static struct pll_init_data ddr3_pll_config_800[MAX_SYSCLK] = {
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530166 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
167 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
168 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
169 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
170};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530171
Rex Chang4df43d42017-12-28 20:39:59 +0530172static struct pll_init_data ddr3_pll_config_1066[MAX_SYSCLK] = {
173 [SYSCLK_19MHz] = {DDR3A_PLL, 194, 1, 14},
174 [SYSCLK_24MHz] = {DDR3A_PLL, 156, 1, 14},
175 [SYSCLK_25MHz] = {DDR3A_PLL, 149, 1, 14},
176 [SYSCLK_26MHz] = {DDR3A_PLL, 144, 1, 14},
177};
178
Vitaly Andrianov29646842015-09-19 16:26:40 +0530179struct pll_init_data *get_pll_init_data(int pll)
180{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600181 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530182 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530183 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530184
185 switch (pll) {
186 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600187 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530188 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530189 break;
190 case TETRIS_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530191 speed = get_max_arm_speed(speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530192 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530193 break;
194 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530195 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530196 break;
197 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530198 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530199 break;
200 case DDR3_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530201 if (cpu_revision() & CPU_66AK2G1x) {
202 speed = get_max_arm_speed(speeds);
203 if (speed == SPD1000)
204 data = &ddr3_pll_config_1066[sysclk_index];
205 else
206 data = &ddr3_pll_config_800[sysclk_index];
207 } else {
208 data = &ddr3_pll_config_800[sysclk_index];
209 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530210 break;
211 default:
212 data = NULL;
213 }
214
215 return data;
216}
217
218s16 divn_val[16] = {
219 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
220};
221
Masahiro Yamada0a780172017-05-09 20:31:39 +0900222#if defined(CONFIG_MMC)
Roger Quadros44157de2015-09-19 16:26:53 +0530223int board_mmc_init(bd_t *bis)
224{
225 if (psc_enable_module(KS2_LPSC_MMC)) {
226 printf("%s module enabled failed\n", __func__);
227 return -1;
228 }
229
Rex Chang4df43d42017-12-28 20:39:59 +0530230 if (board_is_k2g_gp() || board_is_k2g_g1())
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500231 omap_mmc_init(0, 0, 0, -1, -1);
232
Roger Quadros44157de2015-09-19 16:26:53 +0530233 omap_mmc_init(1, 0, 0, -1, -1);
234 return 0;
235}
236#endif
237
Jean-Jacques Hiblot2037fa42017-09-15 12:57:24 +0200238#if defined(CONFIG_MULTI_DTB_FIT)
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500239int board_fit_config_name_match(const char *name)
240{
241 bool eeprom_read = board_ti_was_eeprom_read();
242
243 if (!strcmp(name, "keystone-k2g-generic") && !eeprom_read)
244 return 0;
Rex Chang4df43d42017-12-28 20:39:59 +0530245 else if (!strcmp(name, "keystone-k2g-evm") &&
246 (board_ti_is("66AK2GGP") || board_ti_is("66AK2GG1")))
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500247 return 0;
Cooper Jr., Franklina66a4c72017-06-16 17:25:32 -0500248 else if (!strcmp(name, "keystone-k2g-ice") && board_ti_is("66AK2GIC"))
249 return 0;
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500250 else
251 return -1;
252}
253#endif
254
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500255#if defined(CONFIG_DTB_RESELECT)
256static int k2g_alt_board_detect(void)
257{
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100258#ifndef CONFIG_DM_I2C
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500259 int rc;
260
261 rc = i2c_set_bus_num(1);
262 if (rc)
263 return rc;
264
265 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
266 if (rc)
267 return rc;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100268#else
269 struct udevice *bus, *dev;
270 int rc;
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500271
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100272 rc = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
273 if (rc)
274 return rc;
275 rc = dm_i2c_probe(bus, K2G_GP_AUDIO_CODEC_ADDRESS, 0, &dev);
276 if (rc)
277 return rc;
278#endif
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500279 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
280
281 return 0;
282}
283
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530284static void k2g_reset_mux_config(void)
285{
286 /* Unlock the reset mux register */
287 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
288
289 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
290 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
291 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
292
293 /* lock the reset mux register to prevent any spurious writes. */
294 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
295}
296
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500297int embedded_dtb_select(void)
Vitaly Andrianov29646842015-09-19 16:26:40 +0530298{
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500299 int rc;
300 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
301 CONFIG_EEPROM_CHIP_ADDRESS);
302 if (rc) {
303 rc = k2g_alt_board_detect();
304 if (rc) {
305 printf("Unable to do board detection\n");
306 return -1;
307 }
308 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530309
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500310 fdtdec_setup();
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530311
Cooper Jr., Franklinf4bfac82017-06-16 17:25:23 -0500312 k2g_mux_config();
313
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530314 k2g_reset_mux_config();
315
Rex Chang4df43d42017-12-28 20:39:59 +0530316 if (board_is_k2g_gp() || board_is_k2g_g1()) {
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500317 /* deassert FLASH_HOLD */
318 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
319 BIT(9));
320 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
321 BIT(9));
Murali Karicheri420a4882019-02-21 12:02:04 -0500322 } else if (board_is_k2g_ice()) {
323 /* GBE Phy workaround. For Phy to latch the input
324 * configuration, a GPIO reset is asserted at the
325 * Phy reset pin to latch configuration correctly after SoC
326 * reset. GPIO0 Pin 10 (Ball AA20) is used for this on ICE
327 * board. Just do a low to high transition.
328 */
329 clrbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_DIR_OFFSET,
330 BIT(10));
331 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_CLRDATA_OFFSET,
332 BIT(10));
333 /* Delay just to get a transition to high */
334 udelay(100);
335 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_SETDATA_OFFSET,
336 BIT(10));
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500337 }
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530338
Vitaly Andrianov29646842015-09-19 16:26:40 +0530339 return 0;
340}
341#endif
342
Roger Quadros601ab902017-03-13 15:04:32 +0200343#ifdef CONFIG_BOARD_LATE_INIT
344int board_late_init(void)
345{
346#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
347 int rc;
348
349 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
350 CONFIG_EEPROM_CHIP_ADDRESS);
351 if (rc)
352 printf("ti_i2c_eeprom_init failed %d\n", rc);
353
354 board_ti_set_ethaddr(1);
355#endif
356
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500357#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
358 if (board_is_k2g_gp())
Simon Glass6a38e412017-08-03 12:22:09 -0600359 env_set("board_name", "66AK2GGP\0");
Rex Chang4df43d42017-12-28 20:39:59 +0530360 else if (board_is_k2g_g1())
361 env_set("board_name", "66AK2GG1\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500362 else if (board_is_k2g_ice())
Simon Glass6a38e412017-08-03 12:22:09 -0600363 env_set("board_name", "66AK2GIC\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500364#endif
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500365 return 0;
366}
367#endif
368
369#ifdef CONFIG_BOARD_EARLY_INIT_F
370int board_early_init_f(void)
371{
372 init_plls();
373
374 k2g_mux_config();
375
Roger Quadros601ab902017-03-13 15:04:32 +0200376 return 0;
377}
378#endif
379
Vitaly Andrianov29646842015-09-19 16:26:40 +0530380#ifdef CONFIG_SPL_BUILD
381void spl_init_keystone_plls(void)
382{
383 init_plls();
384}
385#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530386
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500387#ifdef CONFIG_TI_SECURE_DEVICE
388void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
389{
Andrew F. Davisa75e8a82018-02-14 11:53:38 -0600390 int id = env_get_ulong("dev_pmmc", 10, 0);
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500391 int ret;
392
393 if (!rproc_is_initialized())
394 rproc_init();
395
396 ret = rproc_load(id, pmmc_image, pmmc_size);
397 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
398 id, pmmc_image, pmmc_size, ret ? " Failed!" : " Success!");
399
400 if (!ret)
401 rproc_start(id);
402}
403
404U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_PMMC, board_pmmc_image_process);
405#endif