blob: 5229afad63b0e8149ee96445fb6c6df30736becd [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 Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Vitaly Andrianov29646842015-09-19 16:26:40 +053014#include <asm/arch/clock.h>
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +053015#include <asm/ti-common/keystone_net.h>
Roger Quadros44157de2015-09-19 16:26:53 +053016#include <asm/arch/psc_defs.h>
17#include <asm/arch/mmc_host_def.h>
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050018#include <fdtdec.h>
19#include <i2c.h>
Andrew F. Daviseab8f402017-07-31 10:58:21 -050020#include <remoteproc.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060021#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053023#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020024#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053025
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050026#define K2G_GP_AUDIO_CODEC_ADDRESS 0x1B
27
Lokesh Vutlae22e7642017-05-03 16:58:25 +053028const unsigned int sysclk_array[MAX_SYSCLK] = {
29 19200000,
30 24000000,
31 25000000,
32 26000000,
33};
34
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053035unsigned int get_external_clk(u32 clk)
36{
37 unsigned int clk_freq;
38 u8 sysclk_index = get_sysclk_index();
39
40 switch (clk) {
41 case sys_clk:
42 clk_freq = sysclk_array[sysclk_index];
43 break;
44 case pa_clk:
45 clk_freq = sysclk_array[sysclk_index];
46 break;
47 case tetris_clk:
48 clk_freq = sysclk_array[sysclk_index];
49 break;
50 case ddr3a_clk:
51 clk_freq = sysclk_array[sysclk_index];
52 break;
53 case uart_clk:
54 clk_freq = sysclk_array[sysclk_index];
55 break;
56 default:
57 clk_freq = 0;
58 break;
59 }
60
61 return clk_freq;
62}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053063
Rex Chang4df43d42017-12-28 20:39:59 +053064int speeds[DEVSPEED_NUMSPDS] = {
Lokesh Vutla9027e082016-03-04 10:36:41 -060065 SPD400,
66 SPD600,
67 SPD800,
68 SPD900,
69 SPD1000,
70 SPD900,
71 SPD800,
72 SPD600,
73 SPD400,
74 SPD200,
75};
76
77static int dev_speeds[DEVSPEED_NUMSPDS] = {
78 SPD600,
79 SPD800,
80 SPD900,
81 SPD1000,
82 SPD900,
83 SPD800,
84 SPD600,
85 SPD400,
86};
87
Lokesh Vutlae22e7642017-05-03 16:58:25 +053088static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
89 [SYSCLK_19MHz] = {
90 [SPD400] = {MAIN_PLL, 125, 3, 2},
91 [SPD600] = {MAIN_PLL, 125, 2, 2},
92 [SPD800] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053093 [SPD900] = {MAIN_PLL, 187, 2, 2},
94 [SPD1000] = {MAIN_PLL, 104, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053095 },
96 [SYSCLK_24MHz] = {
97 [SPD400] = {MAIN_PLL, 100, 3, 2},
98 [SPD600] = {MAIN_PLL, 300, 6, 2},
99 [SPD800] = {MAIN_PLL, 200, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530100 [SPD900] = {MAIN_PLL, 75, 1, 2},
101 [SPD1000] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530102 },
103 [SYSCLK_25MHz] = {
104 [SPD400] = {MAIN_PLL, 32, 1, 2},
105 [SPD600] = {MAIN_PLL, 48, 1, 2},
106 [SPD800] = {MAIN_PLL, 64, 1, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530107 [SPD900] = {MAIN_PLL, 72, 1, 2},
108 [SPD1000] = {MAIN_PLL, 80, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530109 },
110 [SYSCLK_26MHz] = {
111 [SPD400] = {MAIN_PLL, 400, 13, 2},
112 [SPD600] = {MAIN_PLL, 230, 5, 2},
113 [SPD800] = {MAIN_PLL, 123, 2, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530114 [SPD900] = {MAIN_PLL, 69, 1, 2},
115 [SPD1000] = {MAIN_PLL, 384, 5, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530116 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600117};
118
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530119static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
120 [SYSCLK_19MHz] = {
121 [SPD200] = {TETRIS_PLL, 625, 6, 10},
122 [SPD400] = {TETRIS_PLL, 125, 1, 6},
123 [SPD600] = {TETRIS_PLL, 125, 1, 4},
124 [SPD800] = {TETRIS_PLL, 333, 2, 4},
125 [SPD900] = {TETRIS_PLL, 187, 2, 2},
126 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
127 },
128 [SYSCLK_24MHz] = {
129 [SPD200] = {TETRIS_PLL, 250, 3, 10},
130 [SPD400] = {TETRIS_PLL, 100, 1, 6},
131 [SPD600] = {TETRIS_PLL, 100, 1, 4},
132 [SPD800] = {TETRIS_PLL, 400, 3, 4},
133 [SPD900] = {TETRIS_PLL, 75, 1, 2},
134 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
135 },
136 [SYSCLK_25MHz] = {
137 [SPD200] = {TETRIS_PLL, 80, 1, 10},
138 [SPD400] = {TETRIS_PLL, 96, 1, 6},
139 [SPD600] = {TETRIS_PLL, 96, 1, 4},
140 [SPD800] = {TETRIS_PLL, 128, 1, 4},
141 [SPD900] = {TETRIS_PLL, 72, 1, 2},
142 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
143 },
144 [SYSCLK_26MHz] = {
145 [SPD200] = {TETRIS_PLL, 307, 4, 10},
146 [SPD400] = {TETRIS_PLL, 369, 4, 6},
147 [SPD600] = {TETRIS_PLL, 369, 4, 4},
148 [SPD800] = {TETRIS_PLL, 123, 1, 4},
149 [SPD900] = {TETRIS_PLL, 69, 1, 2},
150 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
151 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600152};
153
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530154static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
155 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
156 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
157 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
158 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
159};
160
161static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
162 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
163 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
164 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
165 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
166};
167
Rex Chang4df43d42017-12-28 20:39:59 +0530168static struct pll_init_data ddr3_pll_config_800[MAX_SYSCLK] = {
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530169 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
170 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
171 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
172 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
173};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530174
Rex Chang4df43d42017-12-28 20:39:59 +0530175static struct pll_init_data ddr3_pll_config_1066[MAX_SYSCLK] = {
176 [SYSCLK_19MHz] = {DDR3A_PLL, 194, 1, 14},
177 [SYSCLK_24MHz] = {DDR3A_PLL, 156, 1, 14},
178 [SYSCLK_25MHz] = {DDR3A_PLL, 149, 1, 14},
179 [SYSCLK_26MHz] = {DDR3A_PLL, 144, 1, 14},
180};
181
Vitaly Andrianov29646842015-09-19 16:26:40 +0530182struct pll_init_data *get_pll_init_data(int pll)
183{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600184 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530185 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530186 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530187
188 switch (pll) {
189 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600190 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530191 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530192 break;
193 case TETRIS_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530194 speed = get_max_arm_speed(speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530195 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530196 break;
197 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530198 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530199 break;
200 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530201 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530202 break;
203 case DDR3_PLL:
Rex Chang4df43d42017-12-28 20:39:59 +0530204 if (cpu_revision() & CPU_66AK2G1x) {
205 speed = get_max_arm_speed(speeds);
206 if (speed == SPD1000)
207 data = &ddr3_pll_config_1066[sysclk_index];
208 else
209 data = &ddr3_pll_config_800[sysclk_index];
210 } else {
211 data = &ddr3_pll_config_800[sysclk_index];
212 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530213 break;
214 default:
215 data = NULL;
216 }
217
218 return data;
219}
220
221s16 divn_val[16] = {
222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
223};
224
Masahiro Yamada0a780172017-05-09 20:31:39 +0900225#if defined(CONFIG_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900226int board_mmc_init(struct bd_info *bis)
Roger Quadros44157de2015-09-19 16:26:53 +0530227{
228 if (psc_enable_module(KS2_LPSC_MMC)) {
229 printf("%s module enabled failed\n", __func__);
230 return -1;
231 }
232
Rex Chang4df43d42017-12-28 20:39:59 +0530233 if (board_is_k2g_gp() || board_is_k2g_g1())
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500234 omap_mmc_init(0, 0, 0, -1, -1);
235
Roger Quadros44157de2015-09-19 16:26:53 +0530236 omap_mmc_init(1, 0, 0, -1, -1);
237 return 0;
238}
239#endif
240
Jean-Jacques Hiblot2037fa42017-09-15 12:57:24 +0200241#if defined(CONFIG_MULTI_DTB_FIT)
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500242int board_fit_config_name_match(const char *name)
243{
244 bool eeprom_read = board_ti_was_eeprom_read();
245
246 if (!strcmp(name, "keystone-k2g-generic") && !eeprom_read)
247 return 0;
Rex Chang4df43d42017-12-28 20:39:59 +0530248 else if (!strcmp(name, "keystone-k2g-evm") &&
249 (board_ti_is("66AK2GGP") || board_ti_is("66AK2GG1")))
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500250 return 0;
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530251 else if (!strcmp(name, "keystone-k2g-ice") &&
252 (board_ti_is("66AK2GIC") || board_is_k2g_i1()))
Cooper Jr., Franklina66a4c72017-06-16 17:25:32 -0500253 return 0;
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500254 else
255 return -1;
256}
257#endif
258
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500259#if defined(CONFIG_DTB_RESELECT)
260static int k2g_alt_board_detect(void)
261{
Igor Opaniukf7c91762021-02-09 13:52:45 +0200262#if !CONFIG_IS_ENABLED(DM_I2C)
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500263 int rc;
264
265 rc = i2c_set_bus_num(1);
266 if (rc)
267 return rc;
268
269 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
270 if (rc)
271 return rc;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100272#else
273 struct udevice *bus, *dev;
274 int rc;
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500275
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100276 rc = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
277 if (rc)
278 return rc;
279 rc = dm_i2c_probe(bus, K2G_GP_AUDIO_CODEC_ADDRESS, 0, &dev);
280 if (rc)
281 return rc;
282#endif
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500283 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
284
285 return 0;
286}
287
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530288static void k2g_reset_mux_config(void)
289{
290 /* Unlock the reset mux register */
291 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
292
293 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
294 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
295 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
296
297 /* lock the reset mux register to prevent any spurious writes. */
298 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
299}
300
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500301int embedded_dtb_select(void)
Vitaly Andrianov29646842015-09-19 16:26:40 +0530302{
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500303 int rc;
304 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
305 CONFIG_EEPROM_CHIP_ADDRESS);
306 if (rc) {
307 rc = k2g_alt_board_detect();
308 if (rc) {
309 printf("Unable to do board detection\n");
310 return -1;
311 }
312 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530313
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500314 fdtdec_setup();
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530315
Cooper Jr., Franklinf4bfac82017-06-16 17:25:23 -0500316 k2g_mux_config();
317
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530318 k2g_reset_mux_config();
319
Rex Chang4df43d42017-12-28 20:39:59 +0530320 if (board_is_k2g_gp() || board_is_k2g_g1()) {
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500321 /* deassert FLASH_HOLD */
322 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
323 BIT(9));
324 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
325 BIT(9));
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530326 } else if (board_is_k2g_ice() || board_is_k2g_i1()) {
Murali Karicheri420a4882019-02-21 12:02:04 -0500327 /* GBE Phy workaround. For Phy to latch the input
328 * configuration, a GPIO reset is asserted at the
329 * Phy reset pin to latch configuration correctly after SoC
330 * reset. GPIO0 Pin 10 (Ball AA20) is used for this on ICE
331 * board. Just do a low to high transition.
332 */
333 clrbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_DIR_OFFSET,
334 BIT(10));
335 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_CLRDATA_OFFSET,
336 BIT(10));
337 /* Delay just to get a transition to high */
338 udelay(100);
339 setbits_le32(K2G_GPIO0_BANK0_BASE + K2G_GPIO_SETDATA_OFFSET,
340 BIT(10));
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500341 }
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530342
Vitaly Andrianov29646842015-09-19 16:26:40 +0530343 return 0;
344}
345#endif
346
Roger Quadros601ab902017-03-13 15:04:32 +0200347#ifdef CONFIG_BOARD_LATE_INIT
348int board_late_init(void)
349{
350#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
351 int rc;
352
353 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
354 CONFIG_EEPROM_CHIP_ADDRESS);
355 if (rc)
356 printf("ti_i2c_eeprom_init failed %d\n", rc);
357
358 board_ti_set_ethaddr(1);
359#endif
360
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500361#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
362 if (board_is_k2g_gp())
Simon Glass6a38e412017-08-03 12:22:09 -0600363 env_set("board_name", "66AK2GGP\0");
Rex Chang4df43d42017-12-28 20:39:59 +0530364 else if (board_is_k2g_g1())
365 env_set("board_name", "66AK2GG1\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500366 else if (board_is_k2g_ice())
Simon Glass6a38e412017-08-03 12:22:09 -0600367 env_set("board_name", "66AK2GIC\0");
Lokesh Vutlaac38c922020-12-17 22:58:07 +0530368 else if (board_is_k2g_i1())
369 env_set("board_name", "66AK2GI1\0");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500370#endif
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500371 return 0;
372}
373#endif
374
375#ifdef CONFIG_BOARD_EARLY_INIT_F
376int board_early_init_f(void)
377{
378 init_plls();
379
380 k2g_mux_config();
381
Roger Quadros601ab902017-03-13 15:04:32 +0200382 return 0;
383}
384#endif
385
Vitaly Andrianov29646842015-09-19 16:26:40 +0530386#ifdef CONFIG_SPL_BUILD
387void spl_init_keystone_plls(void)
388{
389 init_plls();
390}
391#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530392
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500393#ifdef CONFIG_TI_SECURE_DEVICE
394void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
395{
Andrew F. Davisa75e8a82018-02-14 11:53:38 -0600396 int id = env_get_ulong("dev_pmmc", 10, 0);
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500397 int ret;
398
399 if (!rproc_is_initialized())
400 rproc_init();
401
402 ret = rproc_load(id, pmmc_image, pmmc_size);
403 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
404 id, pmmc_image, pmmc_size, ret ? " Failed!" : " Success!");
405
406 if (!ret)
407 rproc_start(id);
408}
409
410U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_PMMC, board_pmmc_image_process);
411#endif