blob: d07b77d23e27f734fa381dd08486ad0ca5695d56 [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 */
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <config.h>
Simon Glass6eaea252019-08-01 09:46:48 -06009#include <env.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060020#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053022#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020023#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053024
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050025#define K2G_GP_AUDIO_CODEC_ADDRESS 0x1B
26
Lokesh Vutlae22e7642017-05-03 16:58:25 +053027const unsigned int sysclk_array[MAX_SYSCLK] = {
28 19200000,
29 24000000,
30 25000000,
31 26000000,
32};
33
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053034unsigned int get_external_clk(u32 clk)
35{
36 unsigned int clk_freq;
37 u8 sysclk_index = get_sysclk_index();
38
39 switch (clk) {
40 case sys_clk:
41 clk_freq = sysclk_array[sysclk_index];
42 break;
43 case pa_clk:
44 clk_freq = sysclk_array[sysclk_index];
45 break;
46 case tetris_clk:
47 clk_freq = sysclk_array[sysclk_index];
48 break;
49 case ddr3a_clk:
50 clk_freq = sysclk_array[sysclk_index];
51 break;
52 case uart_clk:
53 clk_freq = sysclk_array[sysclk_index];
54 break;
55 default:
56 clk_freq = 0;
57 break;
58 }
59
60 return clk_freq;
61}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053062
Rex Chang4df43d42017-12-28 20:39:59 +053063int speeds[DEVSPEED_NUMSPDS] = {
Lokesh Vutla9027e082016-03-04 10:36:41 -060064 SPD400,
65 SPD600,
66 SPD800,
67 SPD900,
68 SPD1000,
69 SPD900,
70 SPD800,
71 SPD600,
72 SPD400,
73 SPD200,
74};
75
76static int dev_speeds[DEVSPEED_NUMSPDS] = {
77 SPD600,
78 SPD800,
79 SPD900,
80 SPD1000,
81 SPD900,
82 SPD800,
83 SPD600,
84 SPD400,
85};
86
Lokesh Vutlae22e7642017-05-03 16:58:25 +053087static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
88 [SYSCLK_19MHz] = {
89 [SPD400] = {MAIN_PLL, 125, 3, 2},
90 [SPD600] = {MAIN_PLL, 125, 2, 2},
91 [SPD800] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053092 [SPD900] = {MAIN_PLL, 187, 2, 2},
93 [SPD1000] = {MAIN_PLL, 104, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053094 },
95 [SYSCLK_24MHz] = {
96 [SPD400] = {MAIN_PLL, 100, 3, 2},
97 [SPD600] = {MAIN_PLL, 300, 6, 2},
98 [SPD800] = {MAIN_PLL, 200, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053099 [SPD900] = {MAIN_PLL, 75, 1, 2},
100 [SPD1000] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530101 },
102 [SYSCLK_25MHz] = {
103 [SPD400] = {MAIN_PLL, 32, 1, 2},
104 [SPD600] = {MAIN_PLL, 48, 1, 2},
105 [SPD800] = {MAIN_PLL, 64, 1, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530106 [SPD900] = {MAIN_PLL, 72, 1, 2},
107 [SPD1000] = {MAIN_PLL, 80, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530108 },
109 [SYSCLK_26MHz] = {
110 [SPD400] = {MAIN_PLL, 400, 13, 2},
111 [SPD600] = {MAIN_PLL, 230, 5, 2},
112 [SPD800] = {MAIN_PLL, 123, 2, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530113 [SPD900] = {MAIN_PLL, 69, 1, 2},
114 [SPD1000] = {MAIN_PLL, 384, 5, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530115 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600116};
117
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530118static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
119 [SYSCLK_19MHz] = {
120 [SPD200] = {TETRIS_PLL, 625, 6, 10},
121 [SPD400] = {TETRIS_PLL, 125, 1, 6},
122 [SPD600] = {TETRIS_PLL, 125, 1, 4},
123 [SPD800] = {TETRIS_PLL, 333, 2, 4},
124 [SPD900] = {TETRIS_PLL, 187, 2, 2},
125 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
126 },
127 [SYSCLK_24MHz] = {
128 [SPD200] = {TETRIS_PLL, 250, 3, 10},
129 [SPD400] = {TETRIS_PLL, 100, 1, 6},
130 [SPD600] = {TETRIS_PLL, 100, 1, 4},
131 [SPD800] = {TETRIS_PLL, 400, 3, 4},
132 [SPD900] = {TETRIS_PLL, 75, 1, 2},
133 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
134 },
135 [SYSCLK_25MHz] = {
136 [SPD200] = {TETRIS_PLL, 80, 1, 10},
137 [SPD400] = {TETRIS_PLL, 96, 1, 6},
138 [SPD600] = {TETRIS_PLL, 96, 1, 4},
139 [SPD800] = {TETRIS_PLL, 128, 1, 4},
140 [SPD900] = {TETRIS_PLL, 72, 1, 2},
141 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
142 },
143 [SYSCLK_26MHz] = {
144 [SPD200] = {TETRIS_PLL, 307, 4, 10},
145 [SPD400] = {TETRIS_PLL, 369, 4, 6},
146 [SPD600] = {TETRIS_PLL, 369, 4, 4},
147 [SPD800] = {TETRIS_PLL, 123, 1, 4},
148 [SPD900] = {TETRIS_PLL, 69, 1, 2},
149 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
150 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600151};
152
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530153static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
154 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
155 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
156 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
157 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
158};
159
160static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
161 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
162 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
163 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
164 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
165};
166
Rex Chang4df43d42017-12-28 20:39:59 +0530167static struct pll_init_data ddr3_pll_config_800[MAX_SYSCLK] = {
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530168 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
169 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
170 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
171 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
172};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530173
Rex Chang4df43d42017-12-28 20:39:59 +0530174static struct pll_init_data ddr3_pll_config_1066[MAX_SYSCLK] = {
175 [SYSCLK_19MHz] = {DDR3A_PLL, 194, 1, 14},
176 [SYSCLK_24MHz] = {DDR3A_PLL, 156, 1, 14},
177 [SYSCLK_25MHz] = {DDR3A_PLL, 149, 1, 14},
178 [SYSCLK_26MHz] = {DDR3A_PLL, 144, 1, 14},
179};
180
Vitaly Andrianov29646842015-09-19 16:26:40 +0530181struct pll_init_data *get_pll_init_data(int pll)
182{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600183 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530184 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530185 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530186
187 switch (pll) {
188 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600189 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530190 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530191 break;
192 case TETRIS_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530193 speed = get_max_arm_speed(speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530194 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530195 break;
196 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530197 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530198 break;
199 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530200 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530201 break;
202 case DDR3_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530203 if (cpu_revision() & CPU_66AK2G1x) {
204 speed = get_max_arm_speed(speeds);
205 if (speed == SPD1000)
206 data = &ddr3_pll_config_1066[sysclk_index];
207 else
208 data = &ddr3_pll_config_800[sysclk_index];
209 } else {
210 data = &ddr3_pll_config_800[sysclk_index];
211 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530212 break;
213 default:
214 data = NULL;
215 }
216
217 return data;
218}
219
220s16 divn_val[16] = {
221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
222};
223
Masahiro Yamada0a780172017-05-09 20:31:39 +0900224#if defined(CONFIG_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900225int board_mmc_init(struct bd_info *bis)
Roger Quadros44157de2015-09-19 16:26:53 +0530226{
227 if (psc_enable_module(KS2_LPSC_MMC)) {
228 printf("%s module enabled failed\n", __func__);
229 return -1;
230 }
231
Rex Chang4df43d42017-12-28 20:39:59 +0530232 if (board_is_k2g_gp() || board_is_k2g_g1())
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500233 omap_mmc_init(0, 0, 0, -1, -1);
234
Roger Quadros44157de2015-09-19 16:26:53 +0530235 omap_mmc_init(1, 0, 0, -1, -1);
236 return 0;
237}
238#endif
239
Jean-Jacques Hiblot2037fa42017-09-15 12:57:24 +0200240#if defined(CONFIG_MULTI_DTB_FIT)
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500241int board_fit_config_name_match(const char *name)
242{
243 bool eeprom_read = board_ti_was_eeprom_read();
244
245 if (!strcmp(name, "keystone-k2g-generic") && !eeprom_read)
246 return 0;
Rex Chang4df43d42017-12-28 20:39:59 +0530247 else if (!strcmp(name, "keystone-k2g-evm") &&
248 (board_ti_is("66AK2GGP") || board_ti_is("66AK2GG1")))
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500249 return 0;
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530250 else if (!strcmp(name, "keystone-k2g-ice") &&
251 (board_ti_is("66AK2GIC") || board_is_k2g_i1()))
Cooper Jr., Franklina66a4c72017-06-16 17:25:32 -0500252 return 0;
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500253 else
254 return -1;
255}
256#endif
257
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500258#if defined(CONFIG_DTB_RESELECT)
259static int k2g_alt_board_detect(void)
260{
Igor Opaniukf7c91762021-02-09 13:52:45 +0200261#if !CONFIG_IS_ENABLED(DM_I2C)
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500262 int rc;
263
264 rc = i2c_set_bus_num(1);
265 if (rc)
266 return rc;
267
268 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
269 if (rc)
270 return rc;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100271#else
272 struct udevice *bus, *dev;
273 int rc;
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500274
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100275 rc = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
276 if (rc)
277 return rc;
278 rc = dm_i2c_probe(bus, K2G_GP_AUDIO_CODEC_ADDRESS, 0, &dev);
279 if (rc)
280 return rc;
281#endif
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500282 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
283
284 return 0;
285}
286
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530287static void k2g_reset_mux_config(void)
288{
289 /* Unlock the reset mux register */
290 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
291
292 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
293 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
294 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
295
296 /* lock the reset mux register to prevent any spurious writes. */
297 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
298}
299
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500300int embedded_dtb_select(void)
Vitaly Andrianov29646842015-09-19 16:26:40 +0530301{
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500302 int rc;
303 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
304 CONFIG_EEPROM_CHIP_ADDRESS);
305 if (rc) {
306 rc = k2g_alt_board_detect();
307 if (rc) {
308 printf("Unable to do board detection\n");
309 return -1;
310 }
311 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530312
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500313 fdtdec_setup();
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530314
Cooper Jr., Franklinf4bfac82017-06-16 17:25:23 -0500315 k2g_mux_config();
316
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530317 k2g_reset_mux_config();
318
Rex Chang4df43d42017-12-28 20:39:59 +0530319 if (board_is_k2g_gp() || board_is_k2g_g1()) {
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500320 /* deassert FLASH_HOLD */
321 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
322 BIT(9));
323 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
324 BIT(9));
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530325 } else if (board_is_k2g_ice() || board_is_k2g_i1()) {
Murali Karicheri420a4882019-02-21 12:02:04 -0500326 /* GBE Phy workaround. For Phy to latch the input
327 * configuration, a GPIO reset is asserted at the
328 * Phy reset pin to latch configuration correctly after SoC
329 * reset. GPIO0 Pin 10 (Ball AA20) is used for this on ICE
330 * board. Just do a low to high transition.
331 */
332 clrbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_DIR_OFFSET,
333 BIT(10));
334 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_CLRDATA_OFFSET,
335 BIT(10));
336 /* Delay just to get a transition to high */
337 udelay(100);
338 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_SETDATA_OFFSET,
339 BIT(10));
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500340 }
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530341
Vitaly Andrianov29646842015-09-19 16:26:40 +0530342 return 0;
343}
344#endif
345
Roger Quadros601ab902017-03-13 15:04:32 +0200346#ifdef CONFIG_BOARD_LATE_INIT
347int board_late_init(void)
348{
349#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
350 int rc;
351
352 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
353 CONFIG_EEPROM_CHIP_ADDRESS);
354 if (rc)
355 printf("ti_i2c_eeprom_init failed %d\n", rc);
356
357 board_ti_set_ethaddr(1);
358#endif
359
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500360#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
361 if (board_is_k2g_gp())
Simon Glass6a38e412017-08-03 12:22:09 -0600362 env_set("board_name", "66AK2GGP\0");
Rex Chang4df43d42017-12-28 20:39:59 +0530363 else if (board_is_k2g_g1())
364 env_set("board_name", "66AK2GG1\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500365 else if (board_is_k2g_ice())
Simon Glass6a38e412017-08-03 12:22:09 -0600366 env_set("board_name", "66AK2GIC\0");
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530367 else if (board_is_k2g_i1())
368 env_set("board_name", "66AK2GI1\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500369#endif
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500370 return 0;
371}
372#endif
373
374#ifdef CONFIG_BOARD_EARLY_INIT_F
375int board_early_init_f(void)
376{
377 init_plls();
378
379 k2g_mux_config();
380
Roger Quadros601ab902017-03-13 15:04:32 +0200381 return 0;
382}
383#endif
384
Vitaly Andrianov29646842015-09-19 16:26:40 +0530385#ifdef CONFIG_SPL_BUILD
386void spl_init_keystone_plls(void)
387{
388 init_plls();
389}
390#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530391
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500392#ifdef CONFIG_TI_SECURE_DEVICE
393void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
394{
Andrew F. Davisa75e8a82018-02-14 11:53:38 -0600395 int id = env_get_ulong("dev_pmmc", 10, 0);
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500396 int ret;
397
398 if (!rproc_is_initialized())
399 rproc_init();
400
401 ret = rproc_load(id, pmmc_image, pmmc_size);
402 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
403 id, pmmc_image, pmmc_size, ret ? " Failed!" : " Success!");
404
405 if (!ret)
406 rproc_start(id);
407}
408
409U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_PMMC, board_pmmc_image_process);
410#endif