blob: b42546a148319c9b8f7eaacb2fb959d3d94b3cad [file] [log] [blame]
Lokesh Vutlafbf27282013-07-30 11:36:27 +05301/*
2 * board.c
3 *
4 * Board functions for TI AM43XX based boards
5 *
6 * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
Sekhar Nori9f1a8cd2013-12-10 15:02:15 +053012#include <i2c.h>
13#include <asm/errno.h>
Lokesh Vutlafbf27282013-07-30 11:36:27 +053014#include <spl.h>
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +053015#include <usb.h>
Lokesh Vutla3b34ac12013-07-30 11:36:29 +053016#include <asm/arch/clock.h>
Lokesh Vutlafbf27282013-07-30 11:36:27 +053017#include <asm/arch/sys_proto.h>
18#include <asm/arch/mux.h>
Lokesh Vutlad3daba12013-12-10 15:02:22 +053019#include <asm/arch/ddr_defs.h>
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +053020#include <asm/arch/gpio.h>
Lokesh Vutlad3daba12013-12-10 15:02:22 +053021#include <asm/emif.h>
Nishanth Menon5f8bb932016-02-24 12:30:56 -060022#include "../common/board_detect.h"
Lokesh Vutlafbf27282013-07-30 11:36:27 +053023#include "board.h"
Tom Rini7aa55982014-06-23 16:06:29 -040024#include <power/pmic.h>
Tom Rini83bad102014-06-05 11:15:30 -040025#include <power/tps65218.h>
Felipe Balbi403d70a2014-12-22 16:26:17 -060026#include <power/tps62362.h>
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -050027#include <miiphy.h>
28#include <cpsw.h>
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +053029#include <linux/usb/gadget.h>
30#include <dwc3-uboot.h>
31#include <dwc3-omap-uboot.h>
32#include <ti-usb-phy-uboot.h>
Lokesh Vutlafbf27282013-07-30 11:36:27 +053033
34DECLARE_GLOBAL_DATA_PTR;
35
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -050036static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -050037
Sekhar Nori9f1a8cd2013-12-10 15:02:15 +053038/*
39 * Read header information from EEPROM into global structure.
40 */
Nishanth Menon5f8bb932016-02-24 12:30:56 -060041static inline int __maybe_unused read_eeprom(void)
Sekhar Nori9f1a8cd2013-12-10 15:02:15 +053042{
Nishanth Menon5f8bb932016-02-24 12:30:56 -060043 return ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR);
Sekhar Nori9f1a8cd2013-12-10 15:02:15 +053044}
45
Sourav Poddar7a5f71b2014-05-19 16:53:37 -040046#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Lokesh Vutlafbf27282013-07-30 11:36:27 +053047
Lokesh Vutlacf04d032013-12-10 15:02:20 +053048#define NUM_OPPS 6
49
50const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = {
51 { /* 19.2 MHz */
James Doublesine2a62072014-12-22 16:26:10 -060052 {125, 3, 2, -1, -1, -1, -1}, /* OPP 50 */
Lokesh Vutlacf04d032013-12-10 15:02:20 +053053 {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
James Doublesine2a62072014-12-22 16:26:10 -060054 {125, 3, 1, -1, -1, -1, -1}, /* OPP 100 */
55 {150, 3, 1, -1, -1, -1, -1}, /* OPP 120 */
56 {125, 2, 1, -1, -1, -1, -1}, /* OPP TB */
57 {625, 11, 1, -1, -1, -1, -1} /* OPP NT */
Lokesh Vutlacf04d032013-12-10 15:02:20 +053058 },
59 { /* 24 MHz */
60 {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */
61 {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
62 {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */
63 {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */
64 {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */
65 {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */
66 },
67 { /* 25 MHz */
68 {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */
69 {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
70 {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */
71 {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */
72 {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */
73 {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */
74 },
75 { /* 26 MHz */
76 {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */
77 {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
78 {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */
79 {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */
80 {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */
81 {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */
82 },
83};
84
85const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = {
James Doublesine2a62072014-12-22 16:26:10 -060086 {625, 11, -1, -1, 10, 8, 4}, /* 19.2 MHz */
Lokesh Vutlacf04d032013-12-10 15:02:20 +053087 {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */
88 {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */
89 {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */
90};
91
92const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = {
James Doublesine2a62072014-12-22 16:26:10 -060093 {400, 7, 5, -1, -1, -1, -1}, /* 19.2 MHz */
94 {400, 9, 5, -1, -1, -1, -1}, /* 24 MHz */
James Doublesinc87b6a92014-12-22 16:26:12 -060095 {384, 9, 5, -1, -1, -1, -1}, /* 25 MHz */
James Doublesine2a62072014-12-22 16:26:10 -060096 {480, 12, 5, -1, -1, -1, -1} /* 26 MHz */
Lokesh Vutlacf04d032013-12-10 15:02:20 +053097};
98
James Doublesine2a62072014-12-22 16:26:10 -060099const struct dpll_params epos_evm_dpll_ddr[NUM_CRYSTAL_FREQ] = {
100 {665, 47, 1, -1, 4, -1, -1}, /*19.2*/
101 {133, 11, 1, -1, 4, -1, -1}, /* 24 MHz */
102 {266, 24, 1, -1, 4, -1, -1}, /* 25 MHz */
103 {133, 12, 1, -1, 4, -1, -1} /* 26 MHz */
104};
Lokesh Vutlacf04d032013-12-10 15:02:20 +0530105
106const struct dpll_params gp_evm_dpll_ddr = {
James Doublesine2a62072014-12-22 16:26:10 -0600107 50, 2, 1, -1, 2, -1, -1};
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530108
Felipe Balbi403d70a2014-12-22 16:26:17 -0600109static const struct dpll_params idk_dpll_ddr = {
110 400, 23, 1, -1, 2, -1, -1
111};
112
Tom Rini7c352cd2015-06-05 15:51:11 +0530113static const u32 ext_phy_ctrl_const_base_lpddr2[] = {
114 0x00500050,
115 0x00350035,
116 0x00350035,
117 0x00350035,
118 0x00350035,
119 0x00350035,
120 0x00000000,
121 0x00000000,
122 0x00000000,
123 0x00000000,
124 0x00000000,
125 0x00000000,
126 0x00000000,
127 0x00000000,
128 0x00000000,
129 0x00000000,
130 0x00000000,
131 0x00000000,
132 0x40001000,
133 0x08102040
134};
135
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530136const struct ctrl_ioregs ioregs_lpddr2 = {
137 .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE,
138 .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE,
139 .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE,
140 .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
141 .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
142 .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
143 .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
144 .emif_sdram_config_ext = 0x1,
145};
146
147const struct emif_regs emif_regs_lpddr2 = {
148 .sdram_config = 0x808012BA,
149 .ref_ctrl = 0x0000040D,
150 .sdram_tim1 = 0xEA86B411,
151 .sdram_tim2 = 0x103A094A,
152 .sdram_tim3 = 0x0F6BA37F,
153 .read_idle_ctrl = 0x00050000,
154 .zq_config = 0x50074BE4,
155 .temp_alert_config = 0x0,
156 .emif_rd_wr_lvl_rmp_win = 0x0,
157 .emif_rd_wr_lvl_rmp_ctl = 0x0,
158 .emif_rd_wr_lvl_ctl = 0x0,
James Doublesine2a62072014-12-22 16:26:10 -0600159 .emif_ddr_phy_ctlr_1 = 0x0E284006,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500160 .emif_rd_wr_exec_thresh = 0x80000405,
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530161 .emif_ddr_ext_phy_ctrl_1 = 0x04010040,
162 .emif_ddr_ext_phy_ctrl_2 = 0x00500050,
163 .emif_ddr_ext_phy_ctrl_3 = 0x00500050,
164 .emif_ddr_ext_phy_ctrl_4 = 0x00500050,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500165 .emif_ddr_ext_phy_ctrl_5 = 0x00500050,
166 .emif_prio_class_serv_map = 0x80000001,
167 .emif_connect_id_serv_1_map = 0x80000094,
168 .emif_connect_id_serv_2_map = 0x00000000,
169 .emif_cos_config = 0x000FFFFF
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530170};
171
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530172const struct ctrl_ioregs ioregs_ddr3 = {
173 .cm0ioctl = DDR3_ADDRCTRL_IOCTRL_VALUE,
174 .cm1ioctl = DDR3_ADDRCTRL_WD0_IOCTRL_VALUE,
175 .cm2ioctl = DDR3_ADDRCTRL_WD1_IOCTRL_VALUE,
176 .dt0ioctl = DDR3_DATA0_IOCTRL_VALUE,
177 .dt1ioctl = DDR3_DATA0_IOCTRL_VALUE,
178 .dt2ioctrl = DDR3_DATA0_IOCTRL_VALUE,
179 .dt3ioctrl = DDR3_DATA0_IOCTRL_VALUE,
James Doublesine2a62072014-12-22 16:26:10 -0600180 .emif_sdram_config_ext = 0xc163,
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530181};
182
183const struct emif_regs ddr3_emif_regs_400Mhz = {
184 .sdram_config = 0x638413B2,
185 .ref_ctrl = 0x00000C30,
186 .sdram_tim1 = 0xEAAAD4DB,
187 .sdram_tim2 = 0x266B7FDA,
188 .sdram_tim3 = 0x107F8678,
189 .read_idle_ctrl = 0x00050000,
190 .zq_config = 0x50074BE4,
191 .temp_alert_config = 0x0,
Lokesh Vutlae27f2dd2014-02-18 07:31:57 -0500192 .emif_ddr_phy_ctlr_1 = 0x0E004008,
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530193 .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
194 .emif_ddr_ext_phy_ctrl_2 = 0x00400040,
195 .emif_ddr_ext_phy_ctrl_3 = 0x00400040,
196 .emif_ddr_ext_phy_ctrl_4 = 0x00400040,
197 .emif_ddr_ext_phy_ctrl_5 = 0x00400040,
198 .emif_rd_wr_lvl_rmp_win = 0x0,
199 .emif_rd_wr_lvl_rmp_ctl = 0x0,
200 .emif_rd_wr_lvl_ctl = 0x0,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500201 .emif_rd_wr_exec_thresh = 0x80000405,
202 .emif_prio_class_serv_map = 0x80000001,
203 .emif_connect_id_serv_1_map = 0x80000094,
204 .emif_connect_id_serv_2_map = 0x00000000,
205 .emif_cos_config = 0x000FFFFF
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530206};
207
Franklin S. Cooper Jr2c952112014-06-27 13:31:14 -0500208/* EMIF DDR3 Configurations are different for beta AM43X GP EVMs */
209const struct emif_regs ddr3_emif_regs_400Mhz_beta = {
210 .sdram_config = 0x638413B2,
211 .ref_ctrl = 0x00000C30,
212 .sdram_tim1 = 0xEAAAD4DB,
213 .sdram_tim2 = 0x266B7FDA,
214 .sdram_tim3 = 0x107F8678,
215 .read_idle_ctrl = 0x00050000,
216 .zq_config = 0x50074BE4,
217 .temp_alert_config = 0x0,
218 .emif_ddr_phy_ctlr_1 = 0x0E004008,
219 .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
220 .emif_ddr_ext_phy_ctrl_2 = 0x00000065,
221 .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
222 .emif_ddr_ext_phy_ctrl_4 = 0x000000B5,
223 .emif_ddr_ext_phy_ctrl_5 = 0x000000E5,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500224 .emif_rd_wr_exec_thresh = 0x80000405,
225 .emif_prio_class_serv_map = 0x80000001,
226 .emif_connect_id_serv_1_map = 0x80000094,
227 .emif_connect_id_serv_2_map = 0x00000000,
228 .emif_cos_config = 0x000FFFFF
Franklin S. Cooper Jr2c952112014-06-27 13:31:14 -0500229};
230
231/* EMIF DDR3 Configurations are different for production AM43X GP EVMs */
232const struct emif_regs ddr3_emif_regs_400Mhz_production = {
233 .sdram_config = 0x638413B2,
234 .ref_ctrl = 0x00000C30,
235 .sdram_tim1 = 0xEAAAD4DB,
236 .sdram_tim2 = 0x266B7FDA,
237 .sdram_tim3 = 0x107F8678,
238 .read_idle_ctrl = 0x00050000,
239 .zq_config = 0x50074BE4,
240 .temp_alert_config = 0x0,
241 .emif_ddr_phy_ctlr_1 = 0x0E004008,
242 .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
243 .emif_ddr_ext_phy_ctrl_2 = 0x00000066,
244 .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
245 .emif_ddr_ext_phy_ctrl_4 = 0x000000B9,
246 .emif_ddr_ext_phy_ctrl_5 = 0x000000E6,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500247 .emif_rd_wr_exec_thresh = 0x80000405,
248 .emif_prio_class_serv_map = 0x80000001,
249 .emif_connect_id_serv_1_map = 0x80000094,
250 .emif_connect_id_serv_2_map = 0x00000000,
251 .emif_cos_config = 0x000FFFFF
Franklin S. Cooper Jr2c952112014-06-27 13:31:14 -0500252};
253
Felipe Balbi9cb9f332014-06-10 15:01:20 -0500254static const struct emif_regs ddr3_sk_emif_regs_400Mhz = {
255 .sdram_config = 0x638413b2,
256 .sdram_config2 = 0x00000000,
257 .ref_ctrl = 0x00000c30,
258 .sdram_tim1 = 0xeaaad4db,
259 .sdram_tim2 = 0x266b7fda,
260 .sdram_tim3 = 0x107f8678,
261 .read_idle_ctrl = 0x00050000,
262 .zq_config = 0x50074be4,
263 .temp_alert_config = 0x0,
264 .emif_ddr_phy_ctlr_1 = 0x0e084008,
265 .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
266 .emif_ddr_ext_phy_ctrl_2 = 0x89,
267 .emif_ddr_ext_phy_ctrl_3 = 0x90,
268 .emif_ddr_ext_phy_ctrl_4 = 0x8e,
269 .emif_ddr_ext_phy_ctrl_5 = 0x8d,
270 .emif_rd_wr_lvl_rmp_win = 0x0,
271 .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
272 .emif_rd_wr_lvl_ctl = 0x00000000,
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500273 .emif_rd_wr_exec_thresh = 0x80000000,
274 .emif_prio_class_serv_map = 0x80000001,
275 .emif_connect_id_serv_1_map = 0x80000094,
276 .emif_connect_id_serv_2_map = 0x00000000,
277 .emif_cos_config = 0x000FFFFF
Felipe Balbi9cb9f332014-06-10 15:01:20 -0500278};
279
Felipe Balbi403d70a2014-12-22 16:26:17 -0600280static const struct emif_regs ddr3_idk_emif_regs_400Mhz = {
281 .sdram_config = 0x61a11b32,
282 .sdram_config2 = 0x00000000,
283 .ref_ctrl = 0x00000c30,
284 .sdram_tim1 = 0xeaaad4db,
285 .sdram_tim2 = 0x266b7fda,
286 .sdram_tim3 = 0x107f8678,
287 .read_idle_ctrl = 0x00050000,
288 .zq_config = 0x50074be4,
289 .temp_alert_config = 0x00000000,
290 .emif_ddr_phy_ctlr_1 = 0x00008009,
291 .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
292 .emif_ddr_ext_phy_ctrl_2 = 0x00000040,
293 .emif_ddr_ext_phy_ctrl_3 = 0x0000003e,
294 .emif_ddr_ext_phy_ctrl_4 = 0x00000051,
295 .emif_ddr_ext_phy_ctrl_5 = 0x00000051,
296 .emif_rd_wr_lvl_rmp_win = 0x00000000,
297 .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
298 .emif_rd_wr_lvl_ctl = 0x00000000,
299 .emif_rd_wr_exec_thresh = 0x00000405,
300 .emif_prio_class_serv_map = 0x00000000,
301 .emif_connect_id_serv_1_map = 0x00000000,
302 .emif_connect_id_serv_2_map = 0x00000000,
303 .emif_cos_config = 0x00ffffff
304};
305
Tom Rini7c352cd2015-06-05 15:51:11 +0530306void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size)
307{
308 if (board_is_eposevm()) {
309 *regs = ext_phy_ctrl_const_base_lpddr2;
310 *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2);
311 }
312
313 return;
314}
315
Lokesh Vutlacf04d032013-12-10 15:02:20 +0530316/*
317 * get_sys_clk_index : returns the index of the sys_clk read from
318 * ctrl status register. This value is either
319 * read from efuse or sysboot pins.
320 */
321static u32 get_sys_clk_index(void)
322{
323 struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
324 u32 ind = readl(&ctrl->statusreg), src;
325
326 src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT;
327 if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */
328 return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >>
329 CTRL_CRYSTAL_FREQ_SELECTION_SHIFT);
330 else /* Value read from SYS BOOT pins */
331 return ((ind & CTRL_SYSBOOT_15_14_MASK) >>
332 CTRL_SYSBOOT_15_14_SHIFT);
333}
334
James Doublesine2a62072014-12-22 16:26:10 -0600335const struct dpll_params *get_dpll_ddr_params(void)
336{
337 int ind = get_sys_clk_index();
338
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600339 if (read_eeprom() < 0)
340 return NULL;
341
James Doublesine2a62072014-12-22 16:26:10 -0600342 if (board_is_eposevm())
343 return &epos_evm_dpll_ddr[ind];
Madan Srinivasa5051b72016-05-19 19:10:48 -0500344 else if (board_is_evm() || board_is_sk())
James Doublesine2a62072014-12-22 16:26:10 -0600345 return &gp_evm_dpll_ddr;
Felipe Balbi403d70a2014-12-22 16:26:17 -0600346 else if (board_is_idk())
347 return &idk_dpll_ddr;
James Doublesine2a62072014-12-22 16:26:10 -0600348
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600349 printf(" Board '%s' not supported\n", board_ti_get_name());
James Doublesine2a62072014-12-22 16:26:10 -0600350 return NULL;
351}
352
353
Lokesh Vutlacf04d032013-12-10 15:02:20 +0530354/*
355 * get_opp_offset:
356 * Returns the index for safest OPP of the device to boot.
357 * max_off: Index of the MAX OPP in DEV ATTRIBUTE register.
358 * min_off: Index of the MIN OPP in DEV ATTRIBUTE register.
359 * This data is read from dev_attribute register which is e-fused.
360 * A'1' in bit indicates OPP disabled and not available, a '0' indicates
361 * OPP available. Lowest OPP starts with min_off. So returning the
362 * bit with rightmost '0'.
363 */
364static int get_opp_offset(int max_off, int min_off)
365{
366 struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
Tom Rinifeca6e62014-06-05 11:15:27 -0400367 int opp, offset, i;
368
369 /* Bits 0:11 are defined to be the MPU_MAX_FREQ */
370 opp = readl(&ctrl->dev_attr) & ~0xFFFFF000;
Lokesh Vutlacf04d032013-12-10 15:02:20 +0530371
372 for (i = max_off; i >= min_off; i--) {
373 offset = opp & (1 << i);
374 if (!offset)
375 return i;
376 }
377
378 return min_off;
379}
380
381const struct dpll_params *get_dpll_mpu_params(void)
382{
383 int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET);
384 u32 ind = get_sys_clk_index();
385
386 return &dpll_mpu[ind][opp];
387}
388
389const struct dpll_params *get_dpll_core_params(void)
390{
391 int ind = get_sys_clk_index();
392
393 return &dpll_core[ind];
394}
395
396const struct dpll_params *get_dpll_per_params(void)
397{
398 int ind = get_sys_clk_index();
399
400 return &dpll_per[ind];
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530401}
402
Felipe Balbi403d70a2014-12-22 16:26:17 -0600403void scale_vcores_generic(u32 m)
Tom Rini83bad102014-06-05 11:15:30 -0400404{
Tom Rini83bad102014-06-05 11:15:30 -0400405 int mpu_vdd;
Tom Rini83bad102014-06-05 11:15:30 -0400406
407 if (i2c_probe(TPS65218_CHIP_PM))
408 return;
409
Felipe Balbi403d70a2014-12-22 16:26:17 -0600410 switch (m) {
Felipe Balbi068ea0a2014-12-22 16:26:13 -0600411 case 1000:
Tom Rini83bad102014-06-05 11:15:30 -0400412 mpu_vdd = TPS65218_DCDC_VOLT_SEL_1330MV;
Felipe Balbi068ea0a2014-12-22 16:26:13 -0600413 break;
Felipe Balbid5c082a2014-12-22 16:26:15 -0600414 case 800:
415 mpu_vdd = TPS65218_DCDC_VOLT_SEL_1260MV;
416 break;
417 case 720:
418 mpu_vdd = TPS65218_DCDC_VOLT_SEL_1200MV;
419 break;
Felipe Balbi068ea0a2014-12-22 16:26:13 -0600420 case 600:
Tom Rini83bad102014-06-05 11:15:30 -0400421 mpu_vdd = TPS65218_DCDC_VOLT_SEL_1100MV;
Felipe Balbi068ea0a2014-12-22 16:26:13 -0600422 break;
Felipe Balbid5c082a2014-12-22 16:26:15 -0600423 case 300:
424 mpu_vdd = TPS65218_DCDC_VOLT_SEL_0950MV;
425 break;
Felipe Balbi068ea0a2014-12-22 16:26:13 -0600426 default:
Tom Rini83bad102014-06-05 11:15:30 -0400427 puts("Unknown MPU clock, not scaling\n");
428 return;
429 }
430
431 /* Set DCDC1 (CORE) voltage to 1.1V */
432 if (tps65218_voltage_update(TPS65218_DCDC1,
433 TPS65218_DCDC_VOLT_SEL_1100MV)) {
Felipe Balbi403d70a2014-12-22 16:26:17 -0600434 printf("%s failure\n", __func__);
Tom Rini83bad102014-06-05 11:15:30 -0400435 return;
436 }
437
438 /* Set DCDC2 (MPU) voltage */
439 if (tps65218_voltage_update(TPS65218_DCDC2, mpu_vdd)) {
Felipe Balbi403d70a2014-12-22 16:26:17 -0600440 printf("%s failure\n", __func__);
Tom Rini83bad102014-06-05 11:15:30 -0400441 return;
442 }
443}
444
Felipe Balbi403d70a2014-12-22 16:26:17 -0600445void scale_vcores_idk(u32 m)
446{
447 int mpu_vdd;
448
449 if (i2c_probe(TPS62362_I2C_ADDR))
450 return;
451
452 switch (m) {
453 case 1000:
454 mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
455 break;
456 case 800:
457 mpu_vdd = TPS62362_DCDC_VOLT_SEL_1260MV;
458 break;
459 case 720:
460 mpu_vdd = TPS62362_DCDC_VOLT_SEL_1200MV;
461 break;
462 case 600:
463 mpu_vdd = TPS62362_DCDC_VOLT_SEL_1100MV;
464 break;
465 case 300:
466 mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
467 break;
468 default:
469 puts("Unknown MPU clock, not scaling\n");
470 return;
471 }
472
473 /* Set VDD_MPU voltage */
474 if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) {
475 printf("%s failure\n", __func__);
476 return;
477 }
478}
479
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600480void gpi2c_init(void)
481{
482 /* When needed to be invoked prior to BSS initialization */
483 static bool first_time = true;
484
485 if (first_time) {
486 enable_i2c0_pin_mux();
487 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
488 CONFIG_SYS_OMAP24_I2C_SLAVE);
489 first_time = false;
490 }
491}
492
Felipe Balbi403d70a2014-12-22 16:26:17 -0600493void scale_vcores(void)
494{
495 const struct dpll_params *mpu_params;
Felipe Balbi403d70a2014-12-22 16:26:17 -0600496
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600497 if (read_eeprom() < 0)
Felipe Balbi403d70a2014-12-22 16:26:17 -0600498 puts("Could not get board ID.\n");
499
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600500 /* Ensure I2C is initialized for PMIC configuration */
501 gpi2c_init();
502
Felipe Balbi403d70a2014-12-22 16:26:17 -0600503 /* Get the frequency */
504 mpu_params = get_dpll_mpu_params();
505
506 if (board_is_idk())
507 scale_vcores_idk(mpu_params->m);
508 else
509 scale_vcores_generic(mpu_params->m);
510}
511
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530512void set_uart_mux_conf(void)
513{
514 enable_uart0_pin_mux();
515}
516
517void set_mux_conf_regs(void)
518{
519 enable_board_pin_mux();
520}
521
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530522static void enable_vtt_regulator(void)
523{
524 u32 temp;
525
526 /* enable module */
Dave Gerlachcd8341b2014-02-10 11:41:49 -0500527 writel(GPIO_CTRL_ENABLEMODULE, AM33XX_GPIO5_BASE + OMAP_GPIO_CTRL);
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530528
Dave Gerlachcd8341b2014-02-10 11:41:49 -0500529 /* enable output for GPIO5_7 */
530 writel(GPIO_SETDATAOUT(7),
531 AM33XX_GPIO5_BASE + OMAP_GPIO_SETDATAOUT);
532 temp = readl(AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
533 temp = temp & ~(GPIO_OE_ENABLE(7));
534 writel(temp, AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530535}
536
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530537void sdram_init(void)
538{
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600539 if (read_eeprom() < 0)
540 return;
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530541 /*
542 * EPOS EVM has 1GB LPDDR2 connected to EMIF.
543 * GP EMV has 1GB DDR3 connected to EMIF
544 * along with VTT regulator.
545 */
546 if (board_is_eposevm()) {
547 config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0);
Franklin S. Cooper Jr2c952112014-06-27 13:31:14 -0500548 } else if (board_is_evm_14_or_later()) {
549 enable_vtt_regulator();
550 config_ddr(0, &ioregs_ddr3, NULL, NULL,
551 &ddr3_emif_regs_400Mhz_production, 0);
552 } else if (board_is_evm_12_or_later()) {
553 enable_vtt_regulator();
554 config_ddr(0, &ioregs_ddr3, NULL, NULL,
555 &ddr3_emif_regs_400Mhz_beta, 0);
Madan Srinivasa5051b72016-05-19 19:10:48 -0500556 } else if (board_is_evm()) {
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530557 enable_vtt_regulator();
558 config_ddr(0, &ioregs_ddr3, NULL, NULL,
559 &ddr3_emif_regs_400Mhz, 0);
Felipe Balbi9cb9f332014-06-10 15:01:20 -0500560 } else if (board_is_sk()) {
561 config_ddr(400, &ioregs_ddr3, NULL, NULL,
562 &ddr3_sk_emif_regs_400Mhz, 0);
Felipe Balbi403d70a2014-12-22 16:26:17 -0600563 } else if (board_is_idk()) {
564 config_ddr(400, &ioregs_ddr3, NULL, NULL,
565 &ddr3_idk_emif_regs_400Mhz, 0);
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530566 }
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530567}
568#endif
569
Tom Rini7aa55982014-06-23 16:06:29 -0400570/* setup board specific PMIC */
571int power_init_board(void)
572{
573 struct pmic *p;
574
Felipe Balbi403d70a2014-12-22 16:26:17 -0600575 if (board_is_idk()) {
576 power_tps62362_init(I2C_PMIC);
577 p = pmic_get("TPS62362");
578 if (p && !pmic_probe(p))
579 puts("PMIC: TPS62362\n");
580 } else {
581 power_tps65218_init(I2C_PMIC);
582 p = pmic_get("TPS65218_PMIC");
583 if (p && !pmic_probe(p))
584 puts("PMIC: TPS65218\n");
585 }
Tom Rini7aa55982014-06-23 16:06:29 -0400586
587 return 0;
588}
589
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530590int board_init(void)
591{
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500592 struct l3f_cfg_bwlimiter *bwlimiter = (struct l3f_cfg_bwlimiter *)L3F_CFG_BWLIMITER;
593 u32 mreqprio_0, mreqprio_1, modena_init0_bw_fractional,
594 modena_init0_bw_integer, modena_init0_watermark_0;
595
Lokesh Vutla369cbe12013-12-10 15:02:12 +0530596 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon guptae53ad4b2014-07-22 16:03:22 +0530597 gpmc_init();
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530598
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -0500599 /* Clear all important bits for DSS errata that may need to be tweaked*/
600 mreqprio_0 = readl(&cdev->mreqprio_0) & MREQPRIO_0_SAB_INIT1_MASK &
601 MREQPRIO_0_SAB_INIT0_MASK;
602
603 mreqprio_1 = readl(&cdev->mreqprio_1) & MREQPRIO_1_DSS_MASK;
604
605 modena_init0_bw_fractional = readl(&bwlimiter->modena_init0_bw_fractional) &
606 BW_LIMITER_BW_FRAC_MASK;
607
608 modena_init0_bw_integer = readl(&bwlimiter->modena_init0_bw_integer) &
609 BW_LIMITER_BW_INT_MASK;
610
611 modena_init0_watermark_0 = readl(&bwlimiter->modena_init0_watermark_0) &
612 BW_LIMITER_BW_WATERMARK_MASK;
613
614 /* Setting MReq Priority of the DSS*/
615 mreqprio_0 |= 0x77;
616
617 /*
618 * Set L3 Fast Configuration Register
619 * Limiting bandwith for ARM core to 700 MBPS
620 */
621 modena_init0_bw_fractional |= 0x10;
622 modena_init0_bw_integer |= 0x3;
623
624 writel(mreqprio_0, &cdev->mreqprio_0);
625 writel(mreqprio_1, &cdev->mreqprio_1);
626
627 writel(modena_init0_bw_fractional, &bwlimiter->modena_init0_bw_fractional);
628 writel(modena_init0_bw_integer, &bwlimiter->modena_init0_bw_integer);
629 writel(modena_init0_watermark_0, &bwlimiter->modena_init0_watermark_0);
630
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530631 return 0;
632}
633
634#ifdef CONFIG_BOARD_LATE_INIT
635int board_late_init(void)
636{
Sekhar Norif4af1632013-12-10 15:02:16 +0530637#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon5f8bb932016-02-24 12:30:56 -0600638 set_board_info_env(NULL);
Sekhar Norif4af1632013-12-10 15:02:16 +0530639#endif
Lokesh Vutlafbf27282013-07-30 11:36:27 +0530640 return 0;
641}
642#endif
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -0500643
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530644#ifdef CONFIG_USB_DWC3
645static struct dwc3_device usb_otg_ss1 = {
646 .maximum_speed = USB_SPEED_HIGH,
647 .base = USB_OTG_SS1_BASE,
648 .tx_fifo_resize = false,
649 .index = 0,
650};
651
652static struct dwc3_omap_device usb_otg_ss1_glue = {
653 .base = (void *)USB_OTG_SS1_GLUE_BASE,
654 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530655 .index = 0,
656};
657
658static struct ti_usb_phy_device usb_phy1_device = {
659 .usb2_phy_power = (void *)USB2_PHY1_POWER,
660 .index = 0,
661};
662
663static struct dwc3_device usb_otg_ss2 = {
664 .maximum_speed = USB_SPEED_HIGH,
665 .base = USB_OTG_SS2_BASE,
666 .tx_fifo_resize = false,
667 .index = 1,
668};
669
670static struct dwc3_omap_device usb_otg_ss2_glue = {
671 .base = (void *)USB_OTG_SS2_GLUE_BASE,
672 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530673 .index = 1,
674};
675
676static struct ti_usb_phy_device usb_phy2_device = {
677 .usb2_phy_power = (void *)USB2_PHY2_POWER,
678 .index = 1,
679};
680
681int board_usb_init(int index, enum usb_init_type init)
682{
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530683 enable_usb_clocks(index);
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530684 switch (index) {
685 case 0:
686 if (init == USB_INIT_DEVICE) {
687 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
688 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
689 } else {
690 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
691 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
692 }
693
694 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
695 ti_usb_phy_uboot_init(&usb_phy1_device);
696 dwc3_uboot_init(&usb_otg_ss1);
697 break;
698 case 1:
699 if (init == USB_INIT_DEVICE) {
700 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
701 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
702 } else {
703 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
704 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
705 }
706
707 ti_usb_phy_uboot_init(&usb_phy2_device);
708 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
709 dwc3_uboot_init(&usb_otg_ss2);
710 break;
711 default:
712 printf("Invalid Controller Index\n");
713 }
714
715 return 0;
716}
717
718int board_usb_cleanup(int index, enum usb_init_type init)
719{
720 switch (index) {
721 case 0:
722 case 1:
723 ti_usb_phy_uboot_exit(index);
724 dwc3_uboot_exit(index);
725 dwc3_omap_uboot_exit(index);
726 break;
727 default:
728 printf("Invalid Controller Index\n");
729 }
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530730 disable_usb_clocks(index);
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530731
732 return 0;
733}
734
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530735int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530736{
737 u32 status;
738
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530739 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530740 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530741 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham I9f81eb72015-02-23 18:40:21 +0530742
743 return 0;
744}
745#endif
746
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -0500747#ifdef CONFIG_DRIVER_TI_CPSW
748
749static void cpsw_control(int enabled)
750{
751 /* Additional controls can be added here */
752 return;
753}
754
755static struct cpsw_slave_data cpsw_slaves[] = {
756 {
757 .slave_reg_ofs = 0x208,
758 .sliver_reg_ofs = 0xd80,
759 .phy_addr = 16,
760 },
761 {
762 .slave_reg_ofs = 0x308,
763 .sliver_reg_ofs = 0xdc0,
764 .phy_addr = 1,
765 },
766};
767
768static struct cpsw_platform_data cpsw_data = {
769 .mdio_base = CPSW_MDIO_BASE,
770 .cpsw_base = CPSW_BASE,
771 .mdio_div = 0xff,
772 .channels = 8,
773 .cpdma_reg_ofs = 0x800,
774 .slaves = 1,
775 .slave_data = cpsw_slaves,
776 .ale_reg_ofs = 0xd00,
777 .ale_entries = 1024,
778 .host_port_reg_ofs = 0x108,
779 .hw_stats_reg_ofs = 0x900,
780 .bd_ram_ofs = 0x2000,
781 .mac_control = (1 << 5),
782 .control = cpsw_control,
783 .host_port_num = 0,
784 .version = CPSW_CTRL_VERSION_2,
785};
786
787int board_eth_init(bd_t *bis)
788{
789 int rv;
790 uint8_t mac_addr[6];
791 uint32_t mac_hi, mac_lo;
792
793 /* try reading mac address from efuse */
794 mac_lo = readl(&cdev->macid0l);
795 mac_hi = readl(&cdev->macid0h);
796 mac_addr[0] = mac_hi & 0xFF;
797 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
798 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
799 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
800 mac_addr[4] = mac_lo & 0xFF;
801 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
802
803 if (!getenv("ethaddr")) {
804 puts("<ethaddr> not set. Validating first E-fuse MAC\n");
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500805 if (is_valid_ethaddr(mac_addr))
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -0500806 eth_setenv_enetaddr("ethaddr", mac_addr);
807 }
808
809 mac_lo = readl(&cdev->macid1l);
810 mac_hi = readl(&cdev->macid1h);
811 mac_addr[0] = mac_hi & 0xFF;
812 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
813 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
814 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
815 mac_addr[4] = mac_lo & 0xFF;
816 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
817
818 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500819 if (is_valid_ethaddr(mac_addr))
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -0500820 eth_setenv_enetaddr("eth1addr", mac_addr);
821 }
822
823 if (board_is_eposevm()) {
824 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
825 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
826 cpsw_slaves[0].phy_addr = 16;
Felipe Balbi619ce622014-06-10 15:01:21 -0500827 } else if (board_is_sk()) {
828 writel(RGMII_MODE_ENABLE, &cdev->miisel);
829 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
830 cpsw_slaves[0].phy_addr = 4;
831 cpsw_slaves[1].phy_addr = 5;
Felipe Balbi403d70a2014-12-22 16:26:17 -0600832 } else if (board_is_idk()) {
833 writel(RGMII_MODE_ENABLE, &cdev->miisel);
834 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
835 cpsw_slaves[0].phy_addr = 0;
Mugunthan V N4cdd7fd2014-02-18 07:31:54 -0500836 } else {
837 writel(RGMII_MODE_ENABLE, &cdev->miisel);
838 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
839 cpsw_slaves[0].phy_addr = 0;
840 }
841
842 rv = cpsw_register(&cpsw_data);
843 if (rv < 0)
844 printf("Error %d registering CPSW switch\n", rv);
845
846 return rv;
847}
848#endif
Lokesh Vutla5a3775a2016-05-16 11:11:15 +0530849
850#ifdef CONFIG_SPL_LOAD_FIT
851int board_fit_config_name_match(const char *name)
852{
853 if (board_is_gpevm() && !strcmp(name, "am437x-gp-evm"))
854 return 0;
855 else if (board_is_sk() && !strcmp(name, "am437x-sk-evm"))
856 return 0;
Lokesh Vutla7dd12832016-05-16 11:11:17 +0530857 else if (board_is_eposevm() && !strcmp(name, "am43x-epos-evm"))
858 return 0;
Lokesh Vutla54a92e12016-05-16 11:11:18 +0530859 else if (board_is_idk() && !strcmp(name, "am437x-idk-evm"))
860 return 0;
Lokesh Vutla5a3775a2016-05-16 11:11:15 +0530861 else
862 return -1;
863}
864#endif