blob: 21aec8f065627dd91a0b3b82a0e790cb233905b2 [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>
Vitaly Andrianov680ec772015-09-19 16:26:45 +053014#include "mux-k2g.h"
Roger Quadros601ab902017-03-13 15:04:32 +020015#include "../common/board_detect.h"
Vitaly Andrianov29646842015-09-19 16:26:40 +053016
Lokesh Vutlae22e7642017-05-03 16:58:25 +053017const unsigned int sysclk_array[MAX_SYSCLK] = {
18 19200000,
19 24000000,
20 25000000,
21 26000000,
22};
23
Lokesh Vutlaa9a0e122017-05-03 16:58:26 +053024unsigned int get_external_clk(u32 clk)
25{
26 unsigned int clk_freq;
27 u8 sysclk_index = get_sysclk_index();
28
29 switch (clk) {
30 case sys_clk:
31 clk_freq = sysclk_array[sysclk_index];
32 break;
33 case pa_clk:
34 clk_freq = sysclk_array[sysclk_index];
35 break;
36 case tetris_clk:
37 clk_freq = sysclk_array[sysclk_index];
38 break;
39 case ddr3a_clk:
40 clk_freq = sysclk_array[sysclk_index];
41 break;
42 case uart_clk:
43 clk_freq = sysclk_array[sysclk_index];
44 break;
45 default:
46 clk_freq = 0;
47 break;
48 }
49
50 return clk_freq;
51}
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053052
Lokesh Vutla9027e082016-03-04 10:36:41 -060053static int arm_speeds[DEVSPEED_NUMSPDS] = {
54 SPD400,
55 SPD600,
56 SPD800,
57 SPD900,
58 SPD1000,
59 SPD900,
60 SPD800,
61 SPD600,
62 SPD400,
63 SPD200,
64};
65
66static int dev_speeds[DEVSPEED_NUMSPDS] = {
67 SPD600,
68 SPD800,
69 SPD900,
70 SPD1000,
71 SPD900,
72 SPD800,
73 SPD600,
74 SPD400,
75};
76
Lokesh Vutlae22e7642017-05-03 16:58:25 +053077static struct pll_init_data main_pll_config[MAX_SYSCLK][NUM_SPDS] = {
78 [SYSCLK_19MHz] = {
79 [SPD400] = {MAIN_PLL, 125, 3, 2},
80 [SPD600] = {MAIN_PLL, 125, 2, 2},
81 [SPD800] = {MAIN_PLL, 250, 3, 2},
82 [SPD900] = {TETRIS_PLL, 187, 2, 2},
83 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
84 },
85 [SYSCLK_24MHz] = {
86 [SPD400] = {MAIN_PLL, 100, 3, 2},
87 [SPD600] = {MAIN_PLL, 300, 6, 2},
88 [SPD800] = {MAIN_PLL, 200, 3, 2},
89 [SPD900] = {TETRIS_PLL, 75, 1, 2},
90 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
91 },
92 [SYSCLK_25MHz] = {
93 [SPD400] = {MAIN_PLL, 32, 1, 2},
94 [SPD600] = {MAIN_PLL, 48, 1, 2},
95 [SPD800] = {MAIN_PLL, 64, 1, 2},
96 [SPD900] = {TETRIS_PLL, 72, 1, 2},
97 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
98 },
99 [SYSCLK_26MHz] = {
100 [SPD400] = {MAIN_PLL, 400, 13, 2},
101 [SPD600] = {MAIN_PLL, 230, 5, 2},
102 [SPD800] = {MAIN_PLL, 123, 2, 2},
103 [SPD900] = {TETRIS_PLL, 69, 1, 2},
104 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
105 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600106};
107
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530108static struct pll_init_data tetris_pll_config[MAX_SYSCLK][NUM_SPDS] = {
109 [SYSCLK_19MHz] = {
110 [SPD200] = {TETRIS_PLL, 625, 6, 10},
111 [SPD400] = {TETRIS_PLL, 125, 1, 6},
112 [SPD600] = {TETRIS_PLL, 125, 1, 4},
113 [SPD800] = {TETRIS_PLL, 333, 2, 4},
114 [SPD900] = {TETRIS_PLL, 187, 2, 2},
115 [SPD1000] = {TETRIS_PLL, 104, 1, 2},
116 },
117 [SYSCLK_24MHz] = {
118 [SPD200] = {TETRIS_PLL, 250, 3, 10},
119 [SPD400] = {TETRIS_PLL, 100, 1, 6},
120 [SPD600] = {TETRIS_PLL, 100, 1, 4},
121 [SPD800] = {TETRIS_PLL, 400, 3, 4},
122 [SPD900] = {TETRIS_PLL, 75, 1, 2},
123 [SPD1000] = {TETRIS_PLL, 250, 3, 2},
124 },
125 [SYSCLK_25MHz] = {
126 [SPD200] = {TETRIS_PLL, 80, 1, 10},
127 [SPD400] = {TETRIS_PLL, 96, 1, 6},
128 [SPD600] = {TETRIS_PLL, 96, 1, 4},
129 [SPD800] = {TETRIS_PLL, 128, 1, 4},
130 [SPD900] = {TETRIS_PLL, 72, 1, 2},
131 [SPD1000] = {TETRIS_PLL, 80, 1, 2},
132 },
133 [SYSCLK_26MHz] = {
134 [SPD200] = {TETRIS_PLL, 307, 4, 10},
135 [SPD400] = {TETRIS_PLL, 369, 4, 6},
136 [SPD600] = {TETRIS_PLL, 369, 4, 4},
137 [SPD800] = {TETRIS_PLL, 123, 1, 4},
138 [SPD900] = {TETRIS_PLL, 69, 1, 2},
139 [SPD1000] = {TETRIS_PLL, 384, 5, 2},
140 },
Lokesh Vutla9027e082016-03-04 10:36:41 -0600141};
142
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530143static struct pll_init_data uart_pll_config[MAX_SYSCLK] = {
144 [SYSCLK_19MHz] = {UART_PLL, 160, 1, 8},
145 [SYSCLK_24MHz] = {UART_PLL, 128, 1, 8},
146 [SYSCLK_25MHz] = {UART_PLL, 768, 5, 10},
147 [SYSCLK_26MHz] = {UART_PLL, 384, 13, 2},
148};
149
150static struct pll_init_data nss_pll_config[MAX_SYSCLK] = {
151 [SYSCLK_19MHz] = {NSS_PLL, 625, 6, 2},
152 [SYSCLK_24MHz] = {NSS_PLL, 250, 3, 2},
153 [SYSCLK_25MHz] = {NSS_PLL, 80, 1, 2},
154 [SYSCLK_26MHz] = {NSS_PLL, 1000, 13, 2},
155};
156
157static struct pll_init_data ddr3_pll_config[MAX_SYSCLK] = {
158 [SYSCLK_19MHz] = {DDR3A_PLL, 167, 1, 16},
159 [SYSCLK_24MHz] = {DDR3A_PLL, 133, 1, 16},
160 [SYSCLK_25MHz] = {DDR3A_PLL, 128, 1, 16},
161 [SYSCLK_26MHz] = {DDR3A_PLL, 123, 1, 16},
162};
Vitaly Andrianov29646842015-09-19 16:26:40 +0530163
164struct pll_init_data *get_pll_init_data(int pll)
165{
Lokesh Vutla9027e082016-03-04 10:36:41 -0600166 int speed;
Vitaly Andrianov29646842015-09-19 16:26:40 +0530167 struct pll_init_data *data = NULL;
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530168 u8 sysclk_index = get_sysclk_index();
Vitaly Andrianov29646842015-09-19 16:26:40 +0530169
170 switch (pll) {
171 case MAIN_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600172 speed = get_max_dev_speed(dev_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530173 data = &main_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530174 break;
175 case TETRIS_PLL:
Lokesh Vutla9027e082016-03-04 10:36:41 -0600176 speed = get_max_arm_speed(arm_speeds);
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530177 data = &tetris_pll_config[sysclk_index][speed];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530178 break;
179 case NSS_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530180 data = &nss_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530181 break;
182 case UART_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530183 data = &uart_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530184 break;
185 case DDR3_PLL:
Lokesh Vutlae22e7642017-05-03 16:58:25 +0530186 data = &ddr3_pll_config[sysclk_index];
Vitaly Andrianov29646842015-09-19 16:26:40 +0530187 break;
188 default:
189 data = NULL;
190 }
191
192 return data;
193}
194
195s16 divn_val[16] = {
196 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
197};
198
Masahiro Yamada0a780172017-05-09 20:31:39 +0900199#if defined(CONFIG_MMC)
Roger Quadros44157de2015-09-19 16:26:53 +0530200int board_mmc_init(bd_t *bis)
201{
202 if (psc_enable_module(KS2_LPSC_MMC)) {
203 printf("%s module enabled failed\n", __func__);
204 return -1;
205 }
206
207 omap_mmc_init(0, 0, 0, -1, -1);
208 omap_mmc_init(1, 0, 0, -1, -1);
209 return 0;
210}
211#endif
212
Vitaly Andrianov29646842015-09-19 16:26:40 +0530213#ifdef CONFIG_BOARD_EARLY_INIT_F
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530214
215static void k2g_reset_mux_config(void)
216{
217 /* Unlock the reset mux register */
218 clrbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
219
220 /* Configure BOOTCFG_RSTMUX8 for WDT event to cause a device reset */
221 clrsetbits_le32(KS2_RSTMUX8, RSTMUX_OMODE8_MASK,
222 RSTMUX_OMODE8_DEV_RESET << RSTMUX_OMODE8_SHIFT);
223
224 /* lock the reset mux register to prevent any spurious writes. */
225 setbits_le32(KS2_RSTMUX8, RSTMUX_LOCK8_MASK);
226}
227
Vitaly Andrianov29646842015-09-19 16:26:40 +0530228int board_early_init_f(void)
229{
230 init_plls();
231
Vitaly Andrianov680ec772015-09-19 16:26:45 +0530232 k2g_mux_config();
233
Lokesh Vutla2f31ff12016-05-26 19:05:44 +0530234 k2g_reset_mux_config();
235
Lokesh Vutlabd46e0e2015-09-19 16:26:54 +0530236 /* deassert FLASH_HOLD */
237 clrbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_DIR_OFFSET,
238 BIT(9));
239 setbits_le32(K2G_GPIO1_BANK2_BASE + K2G_GPIO_SETDATA_OFFSET,
240 BIT(9));
241
Vitaly Andrianov29646842015-09-19 16:26:40 +0530242 return 0;
243}
244#endif
245
Roger Quadros601ab902017-03-13 15:04:32 +0200246#ifdef CONFIG_BOARD_LATE_INIT
247int board_late_init(void)
248{
249#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_TI_I2C_BOARD_DETECT)
250 int rc;
251
252 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
253 CONFIG_EEPROM_CHIP_ADDRESS);
254 if (rc)
255 printf("ti_i2c_eeprom_init failed %d\n", rc);
256
257 board_ti_set_ethaddr(1);
258#endif
259
260 return 0;
261}
262#endif
263
Vitaly Andrianov29646842015-09-19 16:26:40 +0530264#ifdef CONFIG_SPL_BUILD
265void spl_init_keystone_plls(void)
266{
267 init_plls();
268}
269#endif
Vitaly Andrianovcafc8f42015-09-19 16:26:52 +0530270
271#ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
272struct eth_priv_t eth_priv_cfg[] = {
273 {
274 .int_name = "K2G_EMAC",
275 .rx_flow = 0,
276 .phy_addr = 0,
277 .slave_port = 1,
278 .sgmii_link_type = SGMII_LINK_MAC_PHY,
279 .phy_if = PHY_INTERFACE_MODE_RGMII,
280 },
281};
282
283int get_num_eth_ports(void)
284{
285 return sizeof(eth_priv_cfg) / sizeof(struct eth_priv_t);
286}
287#endif