blob: 9001255f829dbecd287e5bd232bd3845b54a7df7 [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>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053016#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020017#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053018
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -050019#define K2G_GP_AUDIO_CODEC_ADDRESS 0x1B
20
Lokesh Vutlae22e7642017-05-03 16:58:25 +053021const unsigned int sysclk_array[MAX_SYSCLK] = {
22 19200000,
23 24000000,
24 25000000,
25 26000000,
26};
27
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053028unsigned int get_external_clk(u32 clk)
29{
30 unsigned int clk_freq;
31 u8 sysclk_index = get_sysclk_index();
32
33 switch (clk) {
34 case sys_clk:
35 clk_freq = sysclk_array[sysclk_index];
36 break;
37 case pa_clk:
38 clk_freq = sysclk_array[sysclk_index];
39 break;
40 case tetris_clk:
41 clk_freq = sysclk_array[sysclk_index];
42 break;
43 case ddr3a_clk:
44 clk_freq = sysclk_array[sysclk_index];
45 break;
46 case uart_clk:
47 clk_freq = sysclk_array[sysclk_index];
48 break;
49 default:
50 clk_freq = 0;
51 break;
52 }
53
54 return clk_freq;
55}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053056
Lokesh Vutla9027e082016-03-04 10:36:41 -060057static int arm_speeds[DEVSPEED_NUMSPDS] = {
58 SPD400,
59 SPD600,
60 SPD800,
61 SPD900,
62 SPD1000,
63 SPD900,
64 SPD800,
65 SPD600,
66 SPD400,
67 SPD200,
68};
69
70static int dev_speeds[DEVSPEED_NUMSPDS] = {
71 SPD600,
72 SPD800,
73 SPD900,
74 SPD1000,
75 SPD900,
76 SPD800,
77 SPD600,
78 SPD400,
79};
80
Lokesh Vutlae22e7642017-05-03 16:58:25 +053081static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
82 [SYSCLK_19MHz] = {
83 [SPD400] = {MAIN_PLL, 125, 3, 2},
84 [SPD600] = {MAIN_PLL, 125, 2, 2},
85 [SPD800] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053086 [SPD900] = {MAIN_PLL, 187, 2, 2},
87 [SPD1000] = {MAIN_PLL, 104, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053088 },
89 [SYSCLK_24MHz] = {
90 [SPD400] = {MAIN_PLL, 100, 3, 2},
91 [SPD600] = {MAIN_PLL, 300, 6, 2},
92 [SPD800] = {MAIN_PLL, 200, 3, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +053093 [SPD900] = {MAIN_PLL, 75, 1, 2},
94 [SPD1000] = {MAIN_PLL, 250, 3, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +053095 },
96 [SYSCLK_25MHz] = {
97 [SPD400] = {MAIN_PLL, 32, 1, 2},
98 [SPD600] = {MAIN_PLL, 48, 1, 2},
99 [SPD800] = {MAIN_PLL, 64, 1, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530100 [SPD900] = {MAIN_PLL, 72, 1, 2},
101 [SPD1000] = {MAIN_PLL, 80, 1, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530102 },
103 [SYSCLK_26MHz] = {
104 [SPD400] = {MAIN_PLL, 400, 13, 2},
105 [SPD600] = {MAIN_PLL, 230, 5, 2},
106 [SPD800] = {MAIN_PLL, 123, 2, 2},
Lokesh Vutla318735b2017-05-20 05:49:27 +0530107 [SPD900] = {MAIN_PLL, 69, 1, 2},
108 [SPD1000] = {MAIN_PLL, 384, 5, 2},
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530109 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600110};
111
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530112static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
113 [SYSCLK_19MHz] = {
114 [SPD200] = {TETRIS_PLL, 625, 6, 10},
115 [SPD400] = {TETRIS_PLL, 125, 1, 6},
116 [SPD600] = {TETRIS_PLL, 125, 1, 4},
117 [SPD800] = {TETRIS_PLL, 333, 2, 4},
118 [SPD900] = {TETRIS_PLL, 187, 2, 2},
119 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
120 },
121 [SYSCLK_24MHz] = {
122 [SPD200] = {TETRIS_PLL, 250, 3, 10},
123 [SPD400] = {TETRIS_PLL, 100, 1, 6},
124 [SPD600] = {TETRIS_PLL, 100, 1, 4},
125 [SPD800] = {TETRIS_PLL, 400, 3, 4},
126 [SPD900] = {TETRIS_PLL, 75, 1, 2},
127 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
128 },
129 [SYSCLK_25MHz] = {
130 [SPD200] = {TETRIS_PLL, 80, 1, 10},
131 [SPD400] = {TETRIS_PLL, 96, 1, 6},
132 [SPD600] = {TETRIS_PLL, 96, 1, 4},
133 [SPD800] = {TETRIS_PLL, 128, 1, 4},
134 [SPD900] = {TETRIS_PLL, 72, 1, 2},
135 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
136 },
137 [SYSCLK_26MHz] = {
138 [SPD200] = {TETRIS_PLL, 307, 4, 10},
139 [SPD400] = {TETRIS_PLL, 369, 4, 6},
140 [SPD600] = {TETRIS_PLL, 369, 4, 4},
141 [SPD800] = {TETRIS_PLL, 123, 1, 4},
142 [SPD900] = {TETRIS_PLL, 69, 1, 2},
143 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
144 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600145};
146
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530147static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
148 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
149 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
150 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
151 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
152};
153
154static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
155 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
156 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
157 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
158 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
159};
160
161static struct pll_init_data ddr3_pll_config[MAX_SYSCLK] = {
162 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
163 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
164 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
165 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
166};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530167
168struct pll_init_data *get_pll_init_data(int pll)
169{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600170 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530171 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530172 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530173
174 switch (pll) {
175 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600176 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530177 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530178 break;
179 case TETRIS_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600180 speed = get_max_arm_speed(arm_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530181 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530182 break;
183 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530184 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530185 break;
186 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530187 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530188 break;
189 case DDR3_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530190 data = &ddr3_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530191 break;
192 default:
193 data = NULL;
194 }
195
196 return data;
197}
198
199s16 divn_val[16] = {
200 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
201};
202
Masahiro Yamada0a780172017-05-09 20:31:39 +0900203#if defined(CONFIG_MMC)
Roger Quadros44157de2015-09-19 16:26:53 +0530204int board_mmc_init(bd_t *bis)
205{
206 if (psc_enable_module(KS2_LPSC_MMC)) {
207 printf("%s module enabled failed\n", __func__);
208 return -1;
209 }
210
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500211 if (board_is_k2g_gp())
212 omap_mmc_init(0, 0, 0, -1, -1);
213
Roger Quadros44157de2015-09-19 16:26:53 +0530214 omap_mmc_init(1, 0, 0, -1, -1);
215 return 0;
216}
217#endif
218
Cooper Jr., Franklin43ff2242017-06-16 17:25:16 -0500219#if defined(CONFIG_FIT_EMBED)
220int board_fit_config_name_match(const char *name)
221{
222 bool eeprom_read = board_ti_was_eeprom_read();
223
224 if (!strcmp(name, "keystone-k2g-generic") && !eeprom_read)
225 return 0;
226 else if (!strcmp(name, "keystone-k2g-evm") && board_ti_is("66AK2GGP"))
227 return 0;
228 else
229 return -1;
230}
231#endif
232
Cooper Jr., Franklin74f22ca2017-06-16 17:25:15 -0500233#if defined(CONFIG_DTB_RESELECT)
234static int k2g_alt_board_detect(void)
235{
236 int rc;
237
238 rc = i2c_set_bus_num(1);
239 if (rc)
240 return rc;
241
242 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
243 if (rc)
244 return rc;
245
246 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
247
248 return 0;
249}
250
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530251static void k2g_reset_mux_config(void)
252{
253 /* Unlock the reset mux register */
254 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
255
256 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
257 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
258 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
259
260 /* lock the reset mux register to prevent any spurious writes. */
261 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
262}
263
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500264int embedded_dtb_select(void)
Vitaly Andrianov29646842015-09-19 16:26:40 +0530265{
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500266 int rc;
267 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
268 CONFIG_EEPROM_CHIP_ADDRESS);
269 if (rc) {
270 rc = k2g_alt_board_detect();
271 if (rc) {
272 printf("Unable to do board detection\n");
273 return -1;
274 }
275 }
Vitaly Andrianov29646842015-09-19 16:26:40 +0530276
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500277 fdtdec_setup();
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530278
Cooper Jr., Franklinf4bfac82017-06-16 17:25:23 -0500279 k2g_mux_config();
280
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530281 k2g_reset_mux_config();
282
Cooper Jr., Franklin16e28972017-06-16 17:25:26 -0500283 if (board_is_k2g_gp()) {
284 /* deassert FLASH_HOLD */
285 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
286 BIT(9));
287 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
288 BIT(9));
289 }
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530290
Vitaly Andrianov29646842015-09-19 16:26:40 +0530291 return 0;
292}
293#endif
294
Roger Quadros601ab902017-03-13 15:04:32 +0200295#ifdef CONFIG_BOARD_LATE_INIT
296int board_late_init(void)
297{
298#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
299 int rc;
300
301 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
302 CONFIG_EEPROM_CHIP_ADDRESS);
303 if (rc)
304 printf("ti_i2c_eeprom_init failed %d\n", rc);
305
306 board_ti_set_ethaddr(1);
307#endif
308
Cooper Jr., Franklin3413a582017-06-16 17:25:17 -0500309 return 0;
310}
311#endif
312
313#ifdef CONFIG_BOARD_EARLY_INIT_F
314int board_early_init_f(void)
315{
316 init_plls();
317
318 k2g_mux_config();
319
Roger Quadros601ab902017-03-13 15:04:32 +0200320 return 0;
321}
322#endif
323
Vitaly Andrianov29646842015-09-19 16:26:40 +0530324#ifdef CONFIG_SPL_BUILD
325void spl_init_keystone_plls(void)
326{
327 init_plls();
328}
329#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530330
331#ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
332struct eth_priv_t eth_priv_cfg[] = {
333 {
334 .int_name = "K2G_EMAC",
335 .rx_flow = 0,
336 .phy_addr = 0,
337 .slave_port = 1,
338 .sgmii_link_type = SGMII_LINK_MAC_PHY,
339 .phy_if = PHY_INTERFACE_MODE_RGMII,
340 },
341};
342
343int get_num_eth_ports(void)
344{
345 return sizeof(eth_priv_cfg) / sizeof(struct eth_priv_t);
346}
347#endif