blob: a71024bcbce5cb3fccd21fd3966809a4805d8d51 [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;
Cooper Jr., Franklina66a4c72017-06-16 17:25:32 -0500251 else if (!strcmp(name, "keystone-k2g-ice") && board_ti_is("66AK2GIC"))
252 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{
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100261#ifndef CONFIG_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));
Murali Karicheri420a4882019-02-21 12:02:04 -0500325 } else if (board_is_k2g_ice()) {
326 /* 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");
Cooper Jr., Franklin7e2edb42017-06-16 17:25:27 -0500367#endif
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500368 return 0;
369}
370#endif
371
372#ifdef CONFIG_BOARD_EARLY_INIT_F
373int board_early_init_f(void)
374{
375 init_plls();
376
377 k2g_mux_config();
378
Roger Quadros601ab902017-03-13 15:04:32 +0200379 return 0;
380}
381#endif
382
Vitaly Andrianov29646842015-09-19 16:26:40 +0530383#ifdef CONFIG_SPL_BUILD
384void spl_init_keystone_plls(void)
385{
386 init_plls();
387}
388#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530389
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500390#ifdef CONFIG_TI_SECURE_DEVICE
391void board_pmmc_image_process(ulong pmmc_image, size_t pmmc_size)
392{
Andrew F. Davisa75e8a82018-02-14 11:53:38 -0600393 int id = env_get_ulong("dev_pmmc", 10, 0);
Andrew F. Daviseab8f402017-07-31 10:58:21 -0500394 int ret;
395
396 if (!rproc_is_initialized())
397 rproc_init();
398
399 ret = rproc_load(id, pmmc_image, pmmc_size);
400 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
401 id, pmmc_image, pmmc_size, ret ? " Failed!" : " Success!");
402
403 if (!ret)
404 rproc_start(id);
405}
406
407U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_PMMC, board_pmmc_image_process);
408#endif