1fbf2728dSLokesh Vutla /*
2fbf2728dSLokesh Vutla * board.c
3fbf2728dSLokesh Vutla *
4fbf2728dSLokesh Vutla * Board functions for TI AM43XX based boards
5fbf2728dSLokesh Vutla *
6fbf2728dSLokesh Vutla * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
7fbf2728dSLokesh Vutla *
8fbf2728dSLokesh Vutla * SPDX-License-Identifier: GPL-2.0+
9fbf2728dSLokesh Vutla */
10fbf2728dSLokesh Vutla
11fbf2728dSLokesh Vutla #include <common.h>
129f1a8cd3SSekhar Nori #include <i2c.h>
131221ce45SMasahiro Yamada #include <linux/errno.h>
14fbf2728dSLokesh Vutla #include <spl.h>
159f81eb77SKishon Vijay Abraham I #include <usb.h>
16e29878fcSMadan Srinivas #include <asm/omap_sec_common.h>
173b34ac13SLokesh Vutla #include <asm/arch/clock.h>
18fbf2728dSLokesh Vutla #include <asm/arch/sys_proto.h>
19fbf2728dSLokesh Vutla #include <asm/arch/mux.h>
20d3daba10SLokesh Vutla #include <asm/arch/ddr_defs.h>
21b5e01eecSLokesh Vutla #include <asm/arch/gpio.h>
22d3daba10SLokesh Vutla #include <asm/emif.h>
2300bbe96eSSemen Protsenko #include <asm/omap_common.h>
245f8bb93bSNishanth Menon #include "../common/board_detect.h"
25fbf2728dSLokesh Vutla #include "board.h"
267aa5598aSTom Rini #include <power/pmic.h>
2783bad102STom Rini #include <power/tps65218.h>
28403d70abSFelipe Balbi #include <power/tps62362.h>
294cdd7fdaSMugunthan V N #include <miiphy.h>
304cdd7fdaSMugunthan V N #include <cpsw.h>
319f81eb77SKishon Vijay Abraham I #include <linux/usb/gadget.h>
329f81eb77SKishon Vijay Abraham I #include <dwc3-uboot.h>
339f81eb77SKishon Vijay Abraham I #include <dwc3-omap-uboot.h>
349f81eb77SKishon Vijay Abraham I #include <ti-usb-phy-uboot.h>
35fbf2728dSLokesh Vutla
36fbf2728dSLokesh Vutla DECLARE_GLOBAL_DATA_PTR;
37fbf2728dSLokesh Vutla
384cdd7fdaSMugunthan V N static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
394cdd7fdaSMugunthan V N
409f1a8cd3SSekhar Nori /*
419f1a8cd3SSekhar Nori * Read header information from EEPROM into global structure.
429f1a8cd3SSekhar Nori */
43140d76a9SLokesh Vutla #ifdef CONFIG_TI_I2C_BOARD_DETECT
do_board_detect(void)44140d76a9SLokesh Vutla void do_board_detect(void)
459f1a8cd3SSekhar Nori {
4664a144dcSSimon Glass if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
4764a144dcSSimon Glass CONFIG_EEPROM_CHIP_ADDRESS))
48140d76a9SLokesh Vutla printf("ti_i2c_eeprom_init failed\n");
499f1a8cd3SSekhar Nori }
50140d76a9SLokesh Vutla #endif
519f1a8cd3SSekhar Nori
527a5f71bcSSourav Poddar #ifndef CONFIG_SKIP_LOWLEVEL_INIT
53fbf2728dSLokesh Vutla
54cf04d032SLokesh Vutla const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = {
55cf04d032SLokesh Vutla { /* 19.2 MHz */
56e2a6207bSJames Doublesin {125, 3, 2, -1, -1, -1, -1}, /* OPP 50 */
57cf04d032SLokesh Vutla {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
58e2a6207bSJames Doublesin {125, 3, 1, -1, -1, -1, -1}, /* OPP 100 */
59e2a6207bSJames Doublesin {150, 3, 1, -1, -1, -1, -1}, /* OPP 120 */
60e2a6207bSJames Doublesin {125, 2, 1, -1, -1, -1, -1}, /* OPP TB */
61e2a6207bSJames Doublesin {625, 11, 1, -1, -1, -1, -1} /* OPP NT */
62cf04d032SLokesh Vutla },
63cf04d032SLokesh Vutla { /* 24 MHz */
64cf04d032SLokesh Vutla {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */
65cf04d032SLokesh Vutla {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
66cf04d032SLokesh Vutla {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */
67cf04d032SLokesh Vutla {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */
68cf04d032SLokesh Vutla {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */
69cf04d032SLokesh Vutla {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */
70cf04d032SLokesh Vutla },
71cf04d032SLokesh Vutla { /* 25 MHz */
72cf04d032SLokesh Vutla {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */
73cf04d032SLokesh Vutla {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
74cf04d032SLokesh Vutla {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */
75cf04d032SLokesh Vutla {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */
76cf04d032SLokesh Vutla {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */
77cf04d032SLokesh Vutla {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */
78cf04d032SLokesh Vutla },
79cf04d032SLokesh Vutla { /* 26 MHz */
80cf04d032SLokesh Vutla {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */
81cf04d032SLokesh Vutla {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
82cf04d032SLokesh Vutla {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */
83cf04d032SLokesh Vutla {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */
84cf04d032SLokesh Vutla {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */
85cf04d032SLokesh Vutla {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */
86cf04d032SLokesh Vutla },
87cf04d032SLokesh Vutla };
88cf04d032SLokesh Vutla
89cf04d032SLokesh Vutla const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = {
90e2a6207bSJames Doublesin {625, 11, -1, -1, 10, 8, 4}, /* 19.2 MHz */
91cf04d032SLokesh Vutla {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */
92cf04d032SLokesh Vutla {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */
93cf04d032SLokesh Vutla {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */
94cf04d032SLokesh Vutla };
95cf04d032SLokesh Vutla
96cf04d032SLokesh Vutla const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = {
97e2a6207bSJames Doublesin {400, 7, 5, -1, -1, -1, -1}, /* 19.2 MHz */
98e2a6207bSJames Doublesin {400, 9, 5, -1, -1, -1, -1}, /* 24 MHz */
99c87b6a96SJames Doublesin {384, 9, 5, -1, -1, -1, -1}, /* 25 MHz */
100e2a6207bSJames Doublesin {480, 12, 5, -1, -1, -1, -1} /* 26 MHz */
101cf04d032SLokesh Vutla };
102cf04d032SLokesh Vutla
103e2a6207bSJames Doublesin const struct dpll_params epos_evm_dpll_ddr[NUM_CRYSTAL_FREQ] = {
104e2a6207bSJames Doublesin {665, 47, 1, -1, 4, -1, -1}, /*19.2*/
105e2a6207bSJames Doublesin {133, 11, 1, -1, 4, -1, -1}, /* 24 MHz */
106e2a6207bSJames Doublesin {266, 24, 1, -1, 4, -1, -1}, /* 25 MHz */
107e2a6207bSJames Doublesin {133, 12, 1, -1, 4, -1, -1} /* 26 MHz */
108e2a6207bSJames Doublesin };
109cf04d032SLokesh Vutla
110cf04d032SLokesh Vutla const struct dpll_params gp_evm_dpll_ddr = {
111e2a6207bSJames Doublesin 50, 2, 1, -1, 2, -1, -1};
112fbf2728dSLokesh Vutla
113403d70abSFelipe Balbi static const struct dpll_params idk_dpll_ddr = {
114403d70abSFelipe Balbi 400, 23, 1, -1, 2, -1, -1
115403d70abSFelipe Balbi };
116403d70abSFelipe Balbi
1177c352cd3STom Rini static const u32 ext_phy_ctrl_const_base_lpddr2[] = {
1187c352cd3STom Rini 0x00500050,
1197c352cd3STom Rini 0x00350035,
1207c352cd3STom Rini 0x00350035,
1217c352cd3STom Rini 0x00350035,
1227c352cd3STom Rini 0x00350035,
1237c352cd3STom Rini 0x00350035,
1247c352cd3STom Rini 0x00000000,
1257c352cd3STom Rini 0x00000000,
1267c352cd3STom Rini 0x00000000,
1277c352cd3STom Rini 0x00000000,
1287c352cd3STom Rini 0x00000000,
1297c352cd3STom Rini 0x00000000,
1307c352cd3STom Rini 0x00000000,
1317c352cd3STom Rini 0x00000000,
1327c352cd3STom Rini 0x00000000,
1337c352cd3STom Rini 0x00000000,
1347c352cd3STom Rini 0x00000000,
1357c352cd3STom Rini 0x00000000,
1367c352cd3STom Rini 0x40001000,
1377c352cd3STom Rini 0x08102040
1387c352cd3STom Rini };
1397c352cd3STom Rini
140d3daba10SLokesh Vutla const struct ctrl_ioregs ioregs_lpddr2 = {
141d3daba10SLokesh Vutla .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE,
142d3daba10SLokesh Vutla .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE,
143d3daba10SLokesh Vutla .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE,
144d3daba10SLokesh Vutla .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
145d3daba10SLokesh Vutla .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
146d3daba10SLokesh Vutla .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
147d3daba10SLokesh Vutla .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
148d3daba10SLokesh Vutla .emif_sdram_config_ext = 0x1,
149d3daba10SLokesh Vutla };
150d3daba10SLokesh Vutla
151d3daba10SLokesh Vutla const struct emif_regs emif_regs_lpddr2 = {
152d3daba10SLokesh Vutla .sdram_config = 0x808012BA,
153d3daba10SLokesh Vutla .ref_ctrl = 0x0000040D,
154d3daba10SLokesh Vutla .sdram_tim1 = 0xEA86B411,
155d3daba10SLokesh Vutla .sdram_tim2 = 0x103A094A,
156d3daba10SLokesh Vutla .sdram_tim3 = 0x0F6BA37F,
157d3daba10SLokesh Vutla .read_idle_ctrl = 0x00050000,
158d3daba10SLokesh Vutla .zq_config = 0x50074BE4,
159d3daba10SLokesh Vutla .temp_alert_config = 0x0,
160d3daba10SLokesh Vutla .emif_rd_wr_lvl_rmp_win = 0x0,
161d3daba10SLokesh Vutla .emif_rd_wr_lvl_rmp_ctl = 0x0,
162d3daba10SLokesh Vutla .emif_rd_wr_lvl_ctl = 0x0,
163e2a6207bSJames Doublesin .emif_ddr_phy_ctlr_1 = 0x0E284006,
1648038b497SCooper Jr., Franklin .emif_rd_wr_exec_thresh = 0x80000405,
165d3daba10SLokesh Vutla .emif_ddr_ext_phy_ctrl_1 = 0x04010040,
166d3daba10SLokesh Vutla .emif_ddr_ext_phy_ctrl_2 = 0x00500050,
167d3daba10SLokesh Vutla .emif_ddr_ext_phy_ctrl_3 = 0x00500050,
168d3daba10SLokesh Vutla .emif_ddr_ext_phy_ctrl_4 = 0x00500050,
1698038b497SCooper Jr., Franklin .emif_ddr_ext_phy_ctrl_5 = 0x00500050,
1708038b497SCooper Jr., Franklin .emif_prio_class_serv_map = 0x80000001,
1718038b497SCooper Jr., Franklin .emif_connect_id_serv_1_map = 0x80000094,
1728038b497SCooper Jr., Franklin .emif_connect_id_serv_2_map = 0x00000000,
1738038b497SCooper Jr., Franklin .emif_cos_config = 0x000FFFFF
174d3daba10SLokesh Vutla };
175d3daba10SLokesh Vutla
176b5e01eecSLokesh Vutla const struct ctrl_ioregs ioregs_ddr3 = {
177b5e01eecSLokesh Vutla .cm0ioctl = DDR3_ADDRCTRL_IOCTRL_VALUE,
178b5e01eecSLokesh Vutla .cm1ioctl = DDR3_ADDRCTRL_WD0_IOCTRL_VALUE,
179b5e01eecSLokesh Vutla .cm2ioctl = DDR3_ADDRCTRL_WD1_IOCTRL_VALUE,
180b5e01eecSLokesh Vutla .dt0ioctl = DDR3_DATA0_IOCTRL_VALUE,
181b5e01eecSLokesh Vutla .dt1ioctl = DDR3_DATA0_IOCTRL_VALUE,
182b5e01eecSLokesh Vutla .dt2ioctrl = DDR3_DATA0_IOCTRL_VALUE,
183b5e01eecSLokesh Vutla .dt3ioctrl = DDR3_DATA0_IOCTRL_VALUE,
184e2a6207bSJames Doublesin .emif_sdram_config_ext = 0xc163,
185b5e01eecSLokesh Vutla };
186b5e01eecSLokesh Vutla
187b5e01eecSLokesh Vutla const struct emif_regs ddr3_emif_regs_400Mhz = {
188b5e01eecSLokesh Vutla .sdram_config = 0x638413B2,
189b5e01eecSLokesh Vutla .ref_ctrl = 0x00000C30,
190b5e01eecSLokesh Vutla .sdram_tim1 = 0xEAAAD4DB,
191b5e01eecSLokesh Vutla .sdram_tim2 = 0x266B7FDA,
192b5e01eecSLokesh Vutla .sdram_tim3 = 0x107F8678,
193b5e01eecSLokesh Vutla .read_idle_ctrl = 0x00050000,
194b5e01eecSLokesh Vutla .zq_config = 0x50074BE4,
195b5e01eecSLokesh Vutla .temp_alert_config = 0x0,
196e27f2dd7SLokesh Vutla .emif_ddr_phy_ctlr_1 = 0x0E004008,
197b5e01eecSLokesh Vutla .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
198b5e01eecSLokesh Vutla .emif_ddr_ext_phy_ctrl_2 = 0x00400040,
199b5e01eecSLokesh Vutla .emif_ddr_ext_phy_ctrl_3 = 0x00400040,
200b5e01eecSLokesh Vutla .emif_ddr_ext_phy_ctrl_4 = 0x00400040,
201b5e01eecSLokesh Vutla .emif_ddr_ext_phy_ctrl_5 = 0x00400040,
202b5e01eecSLokesh Vutla .emif_rd_wr_lvl_rmp_win = 0x0,
203b5e01eecSLokesh Vutla .emif_rd_wr_lvl_rmp_ctl = 0x0,
204b5e01eecSLokesh Vutla .emif_rd_wr_lvl_ctl = 0x0,
2058038b497SCooper Jr., Franklin .emif_rd_wr_exec_thresh = 0x80000405,
2068038b497SCooper Jr., Franklin .emif_prio_class_serv_map = 0x80000001,
2078038b497SCooper Jr., Franklin .emif_connect_id_serv_1_map = 0x80000094,
2088038b497SCooper Jr., Franklin .emif_connect_id_serv_2_map = 0x00000000,
2098038b497SCooper Jr., Franklin .emif_cos_config = 0x000FFFFF
210b5e01eecSLokesh Vutla };
211b5e01eecSLokesh Vutla
2122c952111SFranklin S. Cooper Jr /* EMIF DDR3 Configurations are different for beta AM43X GP EVMs */
2132c952111SFranklin S. Cooper Jr const struct emif_regs ddr3_emif_regs_400Mhz_beta = {
2142c952111SFranklin S. Cooper Jr .sdram_config = 0x638413B2,
2152c952111SFranklin S. Cooper Jr .ref_ctrl = 0x00000C30,
2162c952111SFranklin S. Cooper Jr .sdram_tim1 = 0xEAAAD4DB,
2172c952111SFranklin S. Cooper Jr .sdram_tim2 = 0x266B7FDA,
2182c952111SFranklin S. Cooper Jr .sdram_tim3 = 0x107F8678,
2192c952111SFranklin S. Cooper Jr .read_idle_ctrl = 0x00050000,
2202c952111SFranklin S. Cooper Jr .zq_config = 0x50074BE4,
2212c952111SFranklin S. Cooper Jr .temp_alert_config = 0x0,
2222c952111SFranklin S. Cooper Jr .emif_ddr_phy_ctlr_1 = 0x0E004008,
2232c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
2242c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_2 = 0x00000065,
2252c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
2262c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_4 = 0x000000B5,
2272c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_5 = 0x000000E5,
2288038b497SCooper Jr., Franklin .emif_rd_wr_exec_thresh = 0x80000405,
2298038b497SCooper Jr., Franklin .emif_prio_class_serv_map = 0x80000001,
2308038b497SCooper Jr., Franklin .emif_connect_id_serv_1_map = 0x80000094,
2318038b497SCooper Jr., Franklin .emif_connect_id_serv_2_map = 0x00000000,
2328038b497SCooper Jr., Franklin .emif_cos_config = 0x000FFFFF
2332c952111SFranklin S. Cooper Jr };
2342c952111SFranklin S. Cooper Jr
2352c952111SFranklin S. Cooper Jr /* EMIF DDR3 Configurations are different for production AM43X GP EVMs */
2362c952111SFranklin S. Cooper Jr const struct emif_regs ddr3_emif_regs_400Mhz_production = {
2372c952111SFranklin S. Cooper Jr .sdram_config = 0x638413B2,
2382c952111SFranklin S. Cooper Jr .ref_ctrl = 0x00000C30,
2392c952111SFranklin S. Cooper Jr .sdram_tim1 = 0xEAAAD4DB,
2402c952111SFranklin S. Cooper Jr .sdram_tim2 = 0x266B7FDA,
2412c952111SFranklin S. Cooper Jr .sdram_tim3 = 0x107F8678,
2422c952111SFranklin S. Cooper Jr .read_idle_ctrl = 0x00050000,
2432c952111SFranklin S. Cooper Jr .zq_config = 0x50074BE4,
2442c952111SFranklin S. Cooper Jr .temp_alert_config = 0x0,
2452c952111SFranklin S. Cooper Jr .emif_ddr_phy_ctlr_1 = 0x0E004008,
2462c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
2472c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_2 = 0x00000066,
2482c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
2492c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_4 = 0x000000B9,
2502c952111SFranklin S. Cooper Jr .emif_ddr_ext_phy_ctrl_5 = 0x000000E6,
2518038b497SCooper Jr., Franklin .emif_rd_wr_exec_thresh = 0x80000405,
2528038b497SCooper Jr., Franklin .emif_prio_class_serv_map = 0x80000001,
2538038b497SCooper Jr., Franklin .emif_connect_id_serv_1_map = 0x80000094,
2548038b497SCooper Jr., Franklin .emif_connect_id_serv_2_map = 0x00000000,
2558038b497SCooper Jr., Franklin .emif_cos_config = 0x000FFFFF
2562c952111SFranklin S. Cooper Jr };
2572c952111SFranklin S. Cooper Jr
2589cb9f333SFelipe Balbi static const struct emif_regs ddr3_sk_emif_regs_400Mhz = {
2599cb9f333SFelipe Balbi .sdram_config = 0x638413b2,
2609cb9f333SFelipe Balbi .sdram_config2 = 0x00000000,
2619cb9f333SFelipe Balbi .ref_ctrl = 0x00000c30,
2629cb9f333SFelipe Balbi .sdram_tim1 = 0xeaaad4db,
2639cb9f333SFelipe Balbi .sdram_tim2 = 0x266b7fda,
2649cb9f333SFelipe Balbi .sdram_tim3 = 0x107f8678,
2659cb9f333SFelipe Balbi .read_idle_ctrl = 0x00050000,
2669cb9f333SFelipe Balbi .zq_config = 0x50074be4,
2679cb9f333SFelipe Balbi .temp_alert_config = 0x0,
2689cb9f333SFelipe Balbi .emif_ddr_phy_ctlr_1 = 0x0e084008,
2699cb9f333SFelipe Balbi .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
2709cb9f333SFelipe Balbi .emif_ddr_ext_phy_ctrl_2 = 0x89,
2719cb9f333SFelipe Balbi .emif_ddr_ext_phy_ctrl_3 = 0x90,
2729cb9f333SFelipe Balbi .emif_ddr_ext_phy_ctrl_4 = 0x8e,
2739cb9f333SFelipe Balbi .emif_ddr_ext_phy_ctrl_5 = 0x8d,
2749cb9f333SFelipe Balbi .emif_rd_wr_lvl_rmp_win = 0x0,
2759cb9f333SFelipe Balbi .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
2769cb9f333SFelipe Balbi .emif_rd_wr_lvl_ctl = 0x00000000,
2778038b497SCooper Jr., Franklin .emif_rd_wr_exec_thresh = 0x80000000,
2788038b497SCooper Jr., Franklin .emif_prio_class_serv_map = 0x80000001,
2798038b497SCooper Jr., Franklin .emif_connect_id_serv_1_map = 0x80000094,
2808038b497SCooper Jr., Franklin .emif_connect_id_serv_2_map = 0x00000000,
2818038b497SCooper Jr., Franklin .emif_cos_config = 0x000FFFFF
2829cb9f333SFelipe Balbi };
2839cb9f333SFelipe Balbi
284403d70abSFelipe Balbi static const struct emif_regs ddr3_idk_emif_regs_400Mhz = {
285403d70abSFelipe Balbi .sdram_config = 0x61a11b32,
286403d70abSFelipe Balbi .sdram_config2 = 0x00000000,
287403d70abSFelipe Balbi .ref_ctrl = 0x00000c30,
288403d70abSFelipe Balbi .sdram_tim1 = 0xeaaad4db,
289403d70abSFelipe Balbi .sdram_tim2 = 0x266b7fda,
290403d70abSFelipe Balbi .sdram_tim3 = 0x107f8678,
291403d70abSFelipe Balbi .read_idle_ctrl = 0x00050000,
292403d70abSFelipe Balbi .zq_config = 0x50074be4,
293403d70abSFelipe Balbi .temp_alert_config = 0x00000000,
294403d70abSFelipe Balbi .emif_ddr_phy_ctlr_1 = 0x00008009,
295403d70abSFelipe Balbi .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
296403d70abSFelipe Balbi .emif_ddr_ext_phy_ctrl_2 = 0x00000040,
297403d70abSFelipe Balbi .emif_ddr_ext_phy_ctrl_3 = 0x0000003e,
298403d70abSFelipe Balbi .emif_ddr_ext_phy_ctrl_4 = 0x00000051,
299403d70abSFelipe Balbi .emif_ddr_ext_phy_ctrl_5 = 0x00000051,
300403d70abSFelipe Balbi .emif_rd_wr_lvl_rmp_win = 0x00000000,
301403d70abSFelipe Balbi .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
302403d70abSFelipe Balbi .emif_rd_wr_lvl_ctl = 0x00000000,
303403d70abSFelipe Balbi .emif_rd_wr_exec_thresh = 0x00000405,
304403d70abSFelipe Balbi .emif_prio_class_serv_map = 0x00000000,
305403d70abSFelipe Balbi .emif_connect_id_serv_1_map = 0x00000000,
306403d70abSFelipe Balbi .emif_connect_id_serv_2_map = 0x00000000,
307403d70abSFelipe Balbi .emif_cos_config = 0x00ffffff
308403d70abSFelipe Balbi };
309403d70abSFelipe Balbi
emif_get_ext_phy_ctrl_const_regs(const u32 ** regs,u32 * size)3107c352cd3STom Rini void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size)
3117c352cd3STom Rini {
3127c352cd3STom Rini if (board_is_eposevm()) {
3137c352cd3STom Rini *regs = ext_phy_ctrl_const_base_lpddr2;
3147c352cd3STom Rini *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2);
3157c352cd3STom Rini }
3167c352cd3STom Rini
3177c352cd3STom Rini return;
3187c352cd3STom Rini }
3197c352cd3STom Rini
get_dpll_ddr_params(void)320e2a6207bSJames Doublesin const struct dpll_params *get_dpll_ddr_params(void)
321e2a6207bSJames Doublesin {
322e2a6207bSJames Doublesin int ind = get_sys_clk_index();
323e2a6207bSJames Doublesin
324e2a6207bSJames Doublesin if (board_is_eposevm())
325e2a6207bSJames Doublesin return &epos_evm_dpll_ddr[ind];
326a5051b72SMadan Srinivas else if (board_is_evm() || board_is_sk())
327e2a6207bSJames Doublesin return &gp_evm_dpll_ddr;
328403d70abSFelipe Balbi else if (board_is_idk())
329403d70abSFelipe Balbi return &idk_dpll_ddr;
330e2a6207bSJames Doublesin
3315f8bb93bSNishanth Menon printf(" Board '%s' not supported\n", board_ti_get_name());
332e2a6207bSJames Doublesin return NULL;
333e2a6207bSJames Doublesin }
334e2a6207bSJames Doublesin
335e2a6207bSJames Doublesin
336cf04d032SLokesh Vutla /*
337cf04d032SLokesh Vutla * get_opp_offset:
338cf04d032SLokesh Vutla * Returns the index for safest OPP of the device to boot.
339cf04d032SLokesh Vutla * max_off: Index of the MAX OPP in DEV ATTRIBUTE register.
340cf04d032SLokesh Vutla * min_off: Index of the MIN OPP in DEV ATTRIBUTE register.
341cf04d032SLokesh Vutla * This data is read from dev_attribute register which is e-fused.
342cf04d032SLokesh Vutla * A'1' in bit indicates OPP disabled and not available, a '0' indicates
343cf04d032SLokesh Vutla * OPP available. Lowest OPP starts with min_off. So returning the
344cf04d032SLokesh Vutla * bit with rightmost '0'.
345cf04d032SLokesh Vutla */
get_opp_offset(int max_off,int min_off)346cf04d032SLokesh Vutla static int get_opp_offset(int max_off, int min_off)
347cf04d032SLokesh Vutla {
348cf04d032SLokesh Vutla struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
349feca6e67STom Rini int opp, offset, i;
350feca6e67STom Rini
351feca6e67STom Rini /* Bits 0:11 are defined to be the MPU_MAX_FREQ */
352feca6e67STom Rini opp = readl(&ctrl->dev_attr) & ~0xFFFFF000;
353cf04d032SLokesh Vutla
354cf04d032SLokesh Vutla for (i = max_off; i >= min_off; i--) {
355cf04d032SLokesh Vutla offset = opp & (1 << i);
356cf04d032SLokesh Vutla if (!offset)
357cf04d032SLokesh Vutla return i;
358cf04d032SLokesh Vutla }
359cf04d032SLokesh Vutla
360cf04d032SLokesh Vutla return min_off;
361cf04d032SLokesh Vutla }
362cf04d032SLokesh Vutla
get_dpll_mpu_params(void)363cf04d032SLokesh Vutla const struct dpll_params *get_dpll_mpu_params(void)
364cf04d032SLokesh Vutla {
365cf04d032SLokesh Vutla int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET);
366cf04d032SLokesh Vutla u32 ind = get_sys_clk_index();
367cf04d032SLokesh Vutla
368cf04d032SLokesh Vutla return &dpll_mpu[ind][opp];
369cf04d032SLokesh Vutla }
370cf04d032SLokesh Vutla
get_dpll_core_params(void)371cf04d032SLokesh Vutla const struct dpll_params *get_dpll_core_params(void)
372cf04d032SLokesh Vutla {
373cf04d032SLokesh Vutla int ind = get_sys_clk_index();
374cf04d032SLokesh Vutla
375cf04d032SLokesh Vutla return &dpll_core[ind];
376cf04d032SLokesh Vutla }
377cf04d032SLokesh Vutla
get_dpll_per_params(void)378cf04d032SLokesh Vutla const struct dpll_params *get_dpll_per_params(void)
379cf04d032SLokesh Vutla {
380cf04d032SLokesh Vutla int ind = get_sys_clk_index();
381cf04d032SLokesh Vutla
382cf04d032SLokesh Vutla return &dpll_per[ind];
383fbf2728dSLokesh Vutla }
384fbf2728dSLokesh Vutla
scale_vcores_generic(u32 m)385403d70abSFelipe Balbi void scale_vcores_generic(u32 m)
38683bad102STom Rini {
38783bad102STom Rini int mpu_vdd;
38883bad102STom Rini
38983bad102STom Rini if (i2c_probe(TPS65218_CHIP_PM))
39083bad102STom Rini return;
39183bad102STom Rini
392403d70abSFelipe Balbi switch (m) {
393068ea0a8SFelipe Balbi case 1000:
39483bad102STom Rini mpu_vdd = TPS65218_DCDC_VOLT_SEL_1330MV;
395068ea0a8SFelipe Balbi break;
396d5c082a3SFelipe Balbi case 800:
397d5c082a3SFelipe Balbi mpu_vdd = TPS65218_DCDC_VOLT_SEL_1260MV;
398d5c082a3SFelipe Balbi break;
399d5c082a3SFelipe Balbi case 720:
400d5c082a3SFelipe Balbi mpu_vdd = TPS65218_DCDC_VOLT_SEL_1200MV;
401d5c082a3SFelipe Balbi break;
402068ea0a8SFelipe Balbi case 600:
40383bad102STom Rini mpu_vdd = TPS65218_DCDC_VOLT_SEL_1100MV;
404068ea0a8SFelipe Balbi break;
405d5c082a3SFelipe Balbi case 300:
406d5c082a3SFelipe Balbi mpu_vdd = TPS65218_DCDC_VOLT_SEL_0950MV;
407d5c082a3SFelipe Balbi break;
408068ea0a8SFelipe Balbi default:
40983bad102STom Rini puts("Unknown MPU clock, not scaling\n");
41083bad102STom Rini return;
41183bad102STom Rini }
41283bad102STom Rini
41383bad102STom Rini /* Set DCDC1 (CORE) voltage to 1.1V */
41483bad102STom Rini if (tps65218_voltage_update(TPS65218_DCDC1,
41583bad102STom Rini TPS65218_DCDC_VOLT_SEL_1100MV)) {
416403d70abSFelipe Balbi printf("%s failure\n", __func__);
41783bad102STom Rini return;
41883bad102STom Rini }
41983bad102STom Rini
42083bad102STom Rini /* Set DCDC2 (MPU) voltage */
42183bad102STom Rini if (tps65218_voltage_update(TPS65218_DCDC2, mpu_vdd)) {
422403d70abSFelipe Balbi printf("%s failure\n", __func__);
42383bad102STom Rini return;
42483bad102STom Rini }
425fc69d472SKeerthy
426fc69d472SKeerthy /* Set DCDC3 (DDR) voltage */
427fc69d472SKeerthy if (tps65218_voltage_update(TPS65218_DCDC3,
428fc69d472SKeerthy TPS65218_DCDC3_VOLT_SEL_1350MV)) {
429fc69d472SKeerthy printf("%s failure\n", __func__);
430fc69d472SKeerthy return;
431fc69d472SKeerthy }
43283bad102STom Rini }
43383bad102STom Rini
scale_vcores_idk(u32 m)434403d70abSFelipe Balbi void scale_vcores_idk(u32 m)
435403d70abSFelipe Balbi {
436403d70abSFelipe Balbi int mpu_vdd;
437403d70abSFelipe Balbi
438403d70abSFelipe Balbi if (i2c_probe(TPS62362_I2C_ADDR))
439403d70abSFelipe Balbi return;
440403d70abSFelipe Balbi
441403d70abSFelipe Balbi switch (m) {
442403d70abSFelipe Balbi case 1000:
443403d70abSFelipe Balbi mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
444403d70abSFelipe Balbi break;
445403d70abSFelipe Balbi case 800:
446403d70abSFelipe Balbi mpu_vdd = TPS62362_DCDC_VOLT_SEL_1260MV;
447403d70abSFelipe Balbi break;
448403d70abSFelipe Balbi case 720:
449403d70abSFelipe Balbi mpu_vdd = TPS62362_DCDC_VOLT_SEL_1200MV;
450403d70abSFelipe Balbi break;
451403d70abSFelipe Balbi case 600:
452403d70abSFelipe Balbi mpu_vdd = TPS62362_DCDC_VOLT_SEL_1100MV;
453403d70abSFelipe Balbi break;
454403d70abSFelipe Balbi case 300:
455403d70abSFelipe Balbi mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
456403d70abSFelipe Balbi break;
457403d70abSFelipe Balbi default:
458403d70abSFelipe Balbi puts("Unknown MPU clock, not scaling\n");
459403d70abSFelipe Balbi return;
460403d70abSFelipe Balbi }
461403d70abSFelipe Balbi
462403d70abSFelipe Balbi /* Set VDD_MPU voltage */
463403d70abSFelipe Balbi if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) {
464403d70abSFelipe Balbi printf("%s failure\n", __func__);
465403d70abSFelipe Balbi return;
466403d70abSFelipe Balbi }
467403d70abSFelipe Balbi }
468403d70abSFelipe Balbi
gpi2c_init(void)4695f8bb93bSNishanth Menon void gpi2c_init(void)
4705f8bb93bSNishanth Menon {
4715f8bb93bSNishanth Menon /* When needed to be invoked prior to BSS initialization */
4725f8bb93bSNishanth Menon static bool first_time = true;
4735f8bb93bSNishanth Menon
4745f8bb93bSNishanth Menon if (first_time) {
4755f8bb93bSNishanth Menon enable_i2c0_pin_mux();
4765f8bb93bSNishanth Menon i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
4775f8bb93bSNishanth Menon CONFIG_SYS_OMAP24_I2C_SLAVE);
4785f8bb93bSNishanth Menon first_time = false;
4795f8bb93bSNishanth Menon }
4805f8bb93bSNishanth Menon }
4815f8bb93bSNishanth Menon
scale_vcores(void)482403d70abSFelipe Balbi void scale_vcores(void)
483403d70abSFelipe Balbi {
484403d70abSFelipe Balbi const struct dpll_params *mpu_params;
485403d70abSFelipe Balbi
4865f8bb93bSNishanth Menon /* Ensure I2C is initialized for PMIC configuration */
4875f8bb93bSNishanth Menon gpi2c_init();
4885f8bb93bSNishanth Menon
489403d70abSFelipe Balbi /* Get the frequency */
490403d70abSFelipe Balbi mpu_params = get_dpll_mpu_params();
491403d70abSFelipe Balbi
492403d70abSFelipe Balbi if (board_is_idk())
493403d70abSFelipe Balbi scale_vcores_idk(mpu_params->m);
494403d70abSFelipe Balbi else
495403d70abSFelipe Balbi scale_vcores_generic(mpu_params->m);
496403d70abSFelipe Balbi }
497403d70abSFelipe Balbi
set_uart_mux_conf(void)498fbf2728dSLokesh Vutla void set_uart_mux_conf(void)
499fbf2728dSLokesh Vutla {
500fbf2728dSLokesh Vutla enable_uart0_pin_mux();
501fbf2728dSLokesh Vutla }
502fbf2728dSLokesh Vutla
set_mux_conf_regs(void)503fbf2728dSLokesh Vutla void set_mux_conf_regs(void)
504fbf2728dSLokesh Vutla {
505fbf2728dSLokesh Vutla enable_board_pin_mux();
506fbf2728dSLokesh Vutla }
507fbf2728dSLokesh Vutla
enable_vtt_regulator(void)508b5e01eecSLokesh Vutla static void enable_vtt_regulator(void)
509b5e01eecSLokesh Vutla {
510b5e01eecSLokesh Vutla u32 temp;
511b5e01eecSLokesh Vutla
512b5e01eecSLokesh Vutla /* enable module */
513cd8341b7SDave Gerlach writel(GPIO_CTRL_ENABLEMODULE, AM33XX_GPIO5_BASE + OMAP_GPIO_CTRL);
514b5e01eecSLokesh Vutla
515cd8341b7SDave Gerlach /* enable output for GPIO5_7 */
516cd8341b7SDave Gerlach writel(GPIO_SETDATAOUT(7),
517cd8341b7SDave Gerlach AM33XX_GPIO5_BASE + OMAP_GPIO_SETDATAOUT);
518cd8341b7SDave Gerlach temp = readl(AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
519cd8341b7SDave Gerlach temp = temp & ~(GPIO_OE_ENABLE(7));
520cd8341b7SDave Gerlach writel(temp, AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
521b5e01eecSLokesh Vutla }
522b5e01eecSLokesh Vutla
sdram_init(void)523fbf2728dSLokesh Vutla void sdram_init(void)
524fbf2728dSLokesh Vutla {
525b5e01eecSLokesh Vutla /*
526b5e01eecSLokesh Vutla * EPOS EVM has 1GB LPDDR2 connected to EMIF.
527b5e01eecSLokesh Vutla * GP EMV has 1GB DDR3 connected to EMIF
528b5e01eecSLokesh Vutla * along with VTT regulator.
529b5e01eecSLokesh Vutla */
530b5e01eecSLokesh Vutla if (board_is_eposevm()) {
531d3daba10SLokesh Vutla config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0);
5322c952111SFranklin S. Cooper Jr } else if (board_is_evm_14_or_later()) {
5332c952111SFranklin S. Cooper Jr enable_vtt_regulator();
5342c952111SFranklin S. Cooper Jr config_ddr(0, &ioregs_ddr3, NULL, NULL,
5352c952111SFranklin S. Cooper Jr &ddr3_emif_regs_400Mhz_production, 0);
5362c952111SFranklin S. Cooper Jr } else if (board_is_evm_12_or_later()) {
5372c952111SFranklin S. Cooper Jr enable_vtt_regulator();
5382c952111SFranklin S. Cooper Jr config_ddr(0, &ioregs_ddr3, NULL, NULL,
5392c952111SFranklin S. Cooper Jr &ddr3_emif_regs_400Mhz_beta, 0);
540a5051b72SMadan Srinivas } else if (board_is_evm()) {
541b5e01eecSLokesh Vutla enable_vtt_regulator();
542b5e01eecSLokesh Vutla config_ddr(0, &ioregs_ddr3, NULL, NULL,
543b5e01eecSLokesh Vutla &ddr3_emif_regs_400Mhz, 0);
5449cb9f333SFelipe Balbi } else if (board_is_sk()) {
5459cb9f333SFelipe Balbi config_ddr(400, &ioregs_ddr3, NULL, NULL,
5469cb9f333SFelipe Balbi &ddr3_sk_emif_regs_400Mhz, 0);
547403d70abSFelipe Balbi } else if (board_is_idk()) {
548403d70abSFelipe Balbi config_ddr(400, &ioregs_ddr3, NULL, NULL,
549403d70abSFelipe Balbi &ddr3_idk_emif_regs_400Mhz, 0);
550b5e01eecSLokesh Vutla }
551fbf2728dSLokesh Vutla }
552fbf2728dSLokesh Vutla #endif
553fbf2728dSLokesh Vutla
5547aa5598aSTom Rini /* setup board specific PMIC */
power_init_board(void)5557aa5598aSTom Rini int power_init_board(void)
5567aa5598aSTom Rini {
5577aa5598aSTom Rini struct pmic *p;
5587aa5598aSTom Rini
559403d70abSFelipe Balbi if (board_is_idk()) {
560403d70abSFelipe Balbi power_tps62362_init(I2C_PMIC);
561403d70abSFelipe Balbi p = pmic_get("TPS62362");
562403d70abSFelipe Balbi if (p && !pmic_probe(p))
563403d70abSFelipe Balbi puts("PMIC: TPS62362\n");
564403d70abSFelipe Balbi } else {
5657aa5598aSTom Rini power_tps65218_init(I2C_PMIC);
5667aa5598aSTom Rini p = pmic_get("TPS65218_PMIC");
5677aa5598aSTom Rini if (p && !pmic_probe(p))
5687aa5598aSTom Rini puts("PMIC: TPS65218\n");
569403d70abSFelipe Balbi }
5707aa5598aSTom Rini
5717aa5598aSTom Rini return 0;
5727aa5598aSTom Rini }
5737aa5598aSTom Rini
board_init(void)574fbf2728dSLokesh Vutla int board_init(void)
575fbf2728dSLokesh Vutla {
5768038b497SCooper Jr., Franklin struct l3f_cfg_bwlimiter *bwlimiter = (struct l3f_cfg_bwlimiter *)L3F_CFG_BWLIMITER;
5778038b497SCooper Jr., Franklin u32 mreqprio_0, mreqprio_1, modena_init0_bw_fractional,
5788038b497SCooper Jr., Franklin modena_init0_bw_integer, modena_init0_watermark_0;
5798038b497SCooper Jr., Franklin
580369cbe1eSLokesh Vutla gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
581e53ad4b4Spekon gupta gpmc_init();
582fbf2728dSLokesh Vutla
5838038b497SCooper Jr., Franklin /* Clear all important bits for DSS errata that may need to be tweaked*/
5848038b497SCooper Jr., Franklin mreqprio_0 = readl(&cdev->mreqprio_0) & MREQPRIO_0_SAB_INIT1_MASK &
5858038b497SCooper Jr., Franklin MREQPRIO_0_SAB_INIT0_MASK;
5868038b497SCooper Jr., Franklin
5878038b497SCooper Jr., Franklin mreqprio_1 = readl(&cdev->mreqprio_1) & MREQPRIO_1_DSS_MASK;
5888038b497SCooper Jr., Franklin
5898038b497SCooper Jr., Franklin modena_init0_bw_fractional = readl(&bwlimiter->modena_init0_bw_fractional) &
5908038b497SCooper Jr., Franklin BW_LIMITER_BW_FRAC_MASK;
5918038b497SCooper Jr., Franklin
5928038b497SCooper Jr., Franklin modena_init0_bw_integer = readl(&bwlimiter->modena_init0_bw_integer) &
5938038b497SCooper Jr., Franklin BW_LIMITER_BW_INT_MASK;
5948038b497SCooper Jr., Franklin
5958038b497SCooper Jr., Franklin modena_init0_watermark_0 = readl(&bwlimiter->modena_init0_watermark_0) &
5968038b497SCooper Jr., Franklin BW_LIMITER_BW_WATERMARK_MASK;
5978038b497SCooper Jr., Franklin
5988038b497SCooper Jr., Franklin /* Setting MReq Priority of the DSS*/
5998038b497SCooper Jr., Franklin mreqprio_0 |= 0x77;
6008038b497SCooper Jr., Franklin
6018038b497SCooper Jr., Franklin /*
6028038b497SCooper Jr., Franklin * Set L3 Fast Configuration Register
6038038b497SCooper Jr., Franklin * Limiting bandwith for ARM core to 700 MBPS
6048038b497SCooper Jr., Franklin */
6058038b497SCooper Jr., Franklin modena_init0_bw_fractional |= 0x10;
6068038b497SCooper Jr., Franklin modena_init0_bw_integer |= 0x3;
6078038b497SCooper Jr., Franklin
6088038b497SCooper Jr., Franklin writel(mreqprio_0, &cdev->mreqprio_0);
6098038b497SCooper Jr., Franklin writel(mreqprio_1, &cdev->mreqprio_1);
6108038b497SCooper Jr., Franklin
6118038b497SCooper Jr., Franklin writel(modena_init0_bw_fractional, &bwlimiter->modena_init0_bw_fractional);
6128038b497SCooper Jr., Franklin writel(modena_init0_bw_integer, &bwlimiter->modena_init0_bw_integer);
6138038b497SCooper Jr., Franklin writel(modena_init0_watermark_0, &bwlimiter->modena_init0_watermark_0);
6148038b497SCooper Jr., Franklin
615fbf2728dSLokesh Vutla return 0;
616fbf2728dSLokesh Vutla }
617fbf2728dSLokesh Vutla
618fbf2728dSLokesh Vutla #ifdef CONFIG_BOARD_LATE_INIT
board_late_init(void)619fbf2728dSLokesh Vutla int board_late_init(void)
620fbf2728dSLokesh Vutla {
621f4af163eSSekhar Nori #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
6225f8bb93bSNishanth Menon set_board_info_env(NULL);
6235d4d436cSLokesh Vutla
6245d4d436cSLokesh Vutla /*
6255d4d436cSLokesh Vutla * Default FIT boot on HS devices. Non FIT images are not allowed
6265d4d436cSLokesh Vutla * on HS devices.
6275d4d436cSLokesh Vutla */
6285d4d436cSLokesh Vutla if (get_device_type() == HS_DEVICE)
629382bee57SSimon Glass env_set("boot_fit", "1");
630f4af163eSSekhar Nori #endif
631fbf2728dSLokesh Vutla return 0;
632fbf2728dSLokesh Vutla }
633fbf2728dSLokesh Vutla #endif
6344cdd7fdaSMugunthan V N
6359f81eb77SKishon Vijay Abraham I #ifdef CONFIG_USB_DWC3
6369f81eb77SKishon Vijay Abraham I static struct dwc3_device usb_otg_ss1 = {
6379f81eb77SKishon Vijay Abraham I .maximum_speed = USB_SPEED_HIGH,
6389f81eb77SKishon Vijay Abraham I .base = USB_OTG_SS1_BASE,
6399f81eb77SKishon Vijay Abraham I .tx_fifo_resize = false,
6409f81eb77SKishon Vijay Abraham I .index = 0,
6419f81eb77SKishon Vijay Abraham I };
6429f81eb77SKishon Vijay Abraham I
6439f81eb77SKishon Vijay Abraham I static struct dwc3_omap_device usb_otg_ss1_glue = {
6449f81eb77SKishon Vijay Abraham I .base = (void *)USB_OTG_SS1_GLUE_BASE,
6459f81eb77SKishon Vijay Abraham I .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
6469f81eb77SKishon Vijay Abraham I .index = 0,
6479f81eb77SKishon Vijay Abraham I };
6489f81eb77SKishon Vijay Abraham I
6499f81eb77SKishon Vijay Abraham I static struct ti_usb_phy_device usb_phy1_device = {
6509f81eb77SKishon Vijay Abraham I .usb2_phy_power = (void *)USB2_PHY1_POWER,
6519f81eb77SKishon Vijay Abraham I .index = 0,
6529f81eb77SKishon Vijay Abraham I };
6539f81eb77SKishon Vijay Abraham I
6549f81eb77SKishon Vijay Abraham I static struct dwc3_device usb_otg_ss2 = {
6559f81eb77SKishon Vijay Abraham I .maximum_speed = USB_SPEED_HIGH,
6569f81eb77SKishon Vijay Abraham I .base = USB_OTG_SS2_BASE,
6579f81eb77SKishon Vijay Abraham I .tx_fifo_resize = false,
6589f81eb77SKishon Vijay Abraham I .index = 1,
6599f81eb77SKishon Vijay Abraham I };
6609f81eb77SKishon Vijay Abraham I
6619f81eb77SKishon Vijay Abraham I static struct dwc3_omap_device usb_otg_ss2_glue = {
6629f81eb77SKishon Vijay Abraham I .base = (void *)USB_OTG_SS2_GLUE_BASE,
6639f81eb77SKishon Vijay Abraham I .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
6649f81eb77SKishon Vijay Abraham I .index = 1,
6659f81eb77SKishon Vijay Abraham I };
6669f81eb77SKishon Vijay Abraham I
6679f81eb77SKishon Vijay Abraham I static struct ti_usb_phy_device usb_phy2_device = {
6689f81eb77SKishon Vijay Abraham I .usb2_phy_power = (void *)USB2_PHY2_POWER,
6699f81eb77SKishon Vijay Abraham I .index = 1,
6709f81eb77SKishon Vijay Abraham I };
6719f81eb77SKishon Vijay Abraham I
usb_gadget_handle_interrupts(int index)6722d48aa69SKishon Vijay Abraham I int usb_gadget_handle_interrupts(int index)
6739f81eb77SKishon Vijay Abraham I {
6749f81eb77SKishon Vijay Abraham I u32 status;
6759f81eb77SKishon Vijay Abraham I
6762d48aa69SKishon Vijay Abraham I status = dwc3_omap_uboot_interrupt_status(index);
6779f81eb77SKishon Vijay Abraham I if (status)
6782d48aa69SKishon Vijay Abraham I dwc3_uboot_handle_interrupt(index);
6799f81eb77SKishon Vijay Abraham I
6809f81eb77SKishon Vijay Abraham I return 0;
6819f81eb77SKishon Vijay Abraham I }
68255efaddeSRoger Quadros #endif /* CONFIG_USB_DWC3 */
68355efaddeSRoger Quadros
68455efaddeSRoger Quadros #if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
board_usb_init(int index,enum usb_init_type init)685*99ed6217SFaiz Abbas int board_usb_init(int index, enum usb_init_type init)
68655efaddeSRoger Quadros {
68755efaddeSRoger Quadros enable_usb_clocks(index);
68855efaddeSRoger Quadros #ifdef CONFIG_USB_DWC3
68955efaddeSRoger Quadros switch (index) {
69055efaddeSRoger Quadros case 0:
69155efaddeSRoger Quadros if (init == USB_INIT_DEVICE) {
69255efaddeSRoger Quadros usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
69355efaddeSRoger Quadros usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
69455efaddeSRoger Quadros dwc3_omap_uboot_init(&usb_otg_ss1_glue);
69555efaddeSRoger Quadros ti_usb_phy_uboot_init(&usb_phy1_device);
69655efaddeSRoger Quadros dwc3_uboot_init(&usb_otg_ss1);
69755efaddeSRoger Quadros }
69855efaddeSRoger Quadros break;
69955efaddeSRoger Quadros case 1:
70055efaddeSRoger Quadros if (init == USB_INIT_DEVICE) {
70155efaddeSRoger Quadros usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
70255efaddeSRoger Quadros usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
70355efaddeSRoger Quadros ti_usb_phy_uboot_init(&usb_phy2_device);
70455efaddeSRoger Quadros dwc3_omap_uboot_init(&usb_otg_ss2_glue);
70555efaddeSRoger Quadros dwc3_uboot_init(&usb_otg_ss2);
70655efaddeSRoger Quadros }
70755efaddeSRoger Quadros break;
70855efaddeSRoger Quadros default:
70955efaddeSRoger Quadros printf("Invalid Controller Index\n");
71055efaddeSRoger Quadros }
7119f81eb77SKishon Vijay Abraham I #endif
7129f81eb77SKishon Vijay Abraham I
71355efaddeSRoger Quadros return 0;
71455efaddeSRoger Quadros }
71555efaddeSRoger Quadros
board_usb_cleanup(int index,enum usb_init_type init)716*99ed6217SFaiz Abbas int board_usb_cleanup(int index, enum usb_init_type init)
71755efaddeSRoger Quadros {
71855efaddeSRoger Quadros #ifdef CONFIG_USB_DWC3
71955efaddeSRoger Quadros switch (index) {
72055efaddeSRoger Quadros case 0:
72155efaddeSRoger Quadros case 1:
72255efaddeSRoger Quadros if (init == USB_INIT_DEVICE) {
72355efaddeSRoger Quadros ti_usb_phy_uboot_exit(index);
72455efaddeSRoger Quadros dwc3_uboot_exit(index);
72555efaddeSRoger Quadros dwc3_omap_uboot_exit(index);
72655efaddeSRoger Quadros }
72755efaddeSRoger Quadros break;
72855efaddeSRoger Quadros default:
72955efaddeSRoger Quadros printf("Invalid Controller Index\n");
73055efaddeSRoger Quadros }
73155efaddeSRoger Quadros #endif
73255efaddeSRoger Quadros disable_usb_clocks(index);
73355efaddeSRoger Quadros
73455efaddeSRoger Quadros return 0;
73555efaddeSRoger Quadros }
73655efaddeSRoger Quadros #endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */
73755efaddeSRoger Quadros
7384cdd7fdaSMugunthan V N #ifdef CONFIG_DRIVER_TI_CPSW
7394cdd7fdaSMugunthan V N
cpsw_control(int enabled)7404cdd7fdaSMugunthan V N static void cpsw_control(int enabled)
7414cdd7fdaSMugunthan V N {
7424cdd7fdaSMugunthan V N /* Additional controls can be added here */
7434cdd7fdaSMugunthan V N return;
7444cdd7fdaSMugunthan V N }
7454cdd7fdaSMugunthan V N
7464cdd7fdaSMugunthan V N static struct cpsw_slave_data cpsw_slaves[] = {
7474cdd7fdaSMugunthan V N {
7484cdd7fdaSMugunthan V N .slave_reg_ofs = 0x208,
7494cdd7fdaSMugunthan V N .sliver_reg_ofs = 0xd80,
7504cdd7fdaSMugunthan V N .phy_addr = 16,
7514cdd7fdaSMugunthan V N },
7524cdd7fdaSMugunthan V N {
7534cdd7fdaSMugunthan V N .slave_reg_ofs = 0x308,
7544cdd7fdaSMugunthan V N .sliver_reg_ofs = 0xdc0,
7554cdd7fdaSMugunthan V N .phy_addr = 1,
7564cdd7fdaSMugunthan V N },
7574cdd7fdaSMugunthan V N };
7584cdd7fdaSMugunthan V N
7594cdd7fdaSMugunthan V N static struct cpsw_platform_data cpsw_data = {
7604cdd7fdaSMugunthan V N .mdio_base = CPSW_MDIO_BASE,
7614cdd7fdaSMugunthan V N .cpsw_base = CPSW_BASE,
7624cdd7fdaSMugunthan V N .mdio_div = 0xff,
7634cdd7fdaSMugunthan V N .channels = 8,
7644cdd7fdaSMugunthan V N .cpdma_reg_ofs = 0x800,
7654cdd7fdaSMugunthan V N .slaves = 1,
7664cdd7fdaSMugunthan V N .slave_data = cpsw_slaves,
7674cdd7fdaSMugunthan V N .ale_reg_ofs = 0xd00,
7684cdd7fdaSMugunthan V N .ale_entries = 1024,
7694cdd7fdaSMugunthan V N .host_port_reg_ofs = 0x108,
7704cdd7fdaSMugunthan V N .hw_stats_reg_ofs = 0x900,
7714cdd7fdaSMugunthan V N .bd_ram_ofs = 0x2000,
7724cdd7fdaSMugunthan V N .mac_control = (1 << 5),
7734cdd7fdaSMugunthan V N .control = cpsw_control,
7744cdd7fdaSMugunthan V N .host_port_num = 0,
7754cdd7fdaSMugunthan V N .version = CPSW_CTRL_VERSION_2,
7764cdd7fdaSMugunthan V N };
7774cdd7fdaSMugunthan V N
board_eth_init(bd_t * bis)7784cdd7fdaSMugunthan V N int board_eth_init(bd_t *bis)
7794cdd7fdaSMugunthan V N {
7804cdd7fdaSMugunthan V N int rv;
7814cdd7fdaSMugunthan V N uint8_t mac_addr[6];
7824cdd7fdaSMugunthan V N uint32_t mac_hi, mac_lo;
7834cdd7fdaSMugunthan V N
7844cdd7fdaSMugunthan V N /* try reading mac address from efuse */
7854cdd7fdaSMugunthan V N mac_lo = readl(&cdev->macid0l);
7864cdd7fdaSMugunthan V N mac_hi = readl(&cdev->macid0h);
7874cdd7fdaSMugunthan V N mac_addr[0] = mac_hi & 0xFF;
7884cdd7fdaSMugunthan V N mac_addr[1] = (mac_hi & 0xFF00) >> 8;
7894cdd7fdaSMugunthan V N mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
7904cdd7fdaSMugunthan V N mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
7914cdd7fdaSMugunthan V N mac_addr[4] = mac_lo & 0xFF;
7924cdd7fdaSMugunthan V N mac_addr[5] = (mac_lo & 0xFF00) >> 8;
7934cdd7fdaSMugunthan V N
79400caae6dSSimon Glass if (!env_get("ethaddr")) {
7954cdd7fdaSMugunthan V N puts("<ethaddr> not set. Validating first E-fuse MAC\n");
7960adb5b76SJoe Hershberger if (is_valid_ethaddr(mac_addr))
797fd1e959eSSimon Glass eth_env_set_enetaddr("ethaddr", mac_addr);
7984cdd7fdaSMugunthan V N }
7994cdd7fdaSMugunthan V N
8004cdd7fdaSMugunthan V N mac_lo = readl(&cdev->macid1l);
8014cdd7fdaSMugunthan V N mac_hi = readl(&cdev->macid1h);
8024cdd7fdaSMugunthan V N mac_addr[0] = mac_hi & 0xFF;
8034cdd7fdaSMugunthan V N mac_addr[1] = (mac_hi & 0xFF00) >> 8;
8044cdd7fdaSMugunthan V N mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
8054cdd7fdaSMugunthan V N mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
8064cdd7fdaSMugunthan V N mac_addr[4] = mac_lo & 0xFF;
8074cdd7fdaSMugunthan V N mac_addr[5] = (mac_lo & 0xFF00) >> 8;
8084cdd7fdaSMugunthan V N
80900caae6dSSimon Glass if (!env_get("eth1addr")) {
8100adb5b76SJoe Hershberger if (is_valid_ethaddr(mac_addr))
811fd1e959eSSimon Glass eth_env_set_enetaddr("eth1addr", mac_addr);
8124cdd7fdaSMugunthan V N }
8134cdd7fdaSMugunthan V N
8144cdd7fdaSMugunthan V N if (board_is_eposevm()) {
8154cdd7fdaSMugunthan V N writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
8164cdd7fdaSMugunthan V N cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
8174cdd7fdaSMugunthan V N cpsw_slaves[0].phy_addr = 16;
818619ce62dSFelipe Balbi } else if (board_is_sk()) {
819619ce62dSFelipe Balbi writel(RGMII_MODE_ENABLE, &cdev->miisel);
820619ce62dSFelipe Balbi cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
821619ce62dSFelipe Balbi cpsw_slaves[0].phy_addr = 4;
822619ce62dSFelipe Balbi cpsw_slaves[1].phy_addr = 5;
823403d70abSFelipe Balbi } else if (board_is_idk()) {
824403d70abSFelipe Balbi writel(RGMII_MODE_ENABLE, &cdev->miisel);
825403d70abSFelipe Balbi cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
826403d70abSFelipe Balbi cpsw_slaves[0].phy_addr = 0;
8274cdd7fdaSMugunthan V N } else {
8284cdd7fdaSMugunthan V N writel(RGMII_MODE_ENABLE, &cdev->miisel);
8294cdd7fdaSMugunthan V N cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
8304cdd7fdaSMugunthan V N cpsw_slaves[0].phy_addr = 0;
8314cdd7fdaSMugunthan V N }
8324cdd7fdaSMugunthan V N
8334cdd7fdaSMugunthan V N rv = cpsw_register(&cpsw_data);
8344cdd7fdaSMugunthan V N if (rv < 0)
8354cdd7fdaSMugunthan V N printf("Error %d registering CPSW switch\n", rv);
8364cdd7fdaSMugunthan V N
8374cdd7fdaSMugunthan V N return rv;
8384cdd7fdaSMugunthan V N }
8394cdd7fdaSMugunthan V N #endif
8405a3775a4SLokesh Vutla
8417fe463f5SAndrew F. Davis #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,bd_t * bd)8427fe463f5SAndrew F. Davis int ft_board_setup(void *blob, bd_t *bd)
8437fe463f5SAndrew F. Davis {
8447fe463f5SAndrew F. Davis ft_cpu_setup(blob, bd);
8457fe463f5SAndrew F. Davis
8467fe463f5SAndrew F. Davis return 0;
8477fe463f5SAndrew F. Davis }
8487fe463f5SAndrew F. Davis #endif
8497fe463f5SAndrew F. Davis
8505a3775a4SLokesh Vutla #ifdef CONFIG_SPL_LOAD_FIT
board_fit_config_name_match(const char * name)8515a3775a4SLokesh Vutla int board_fit_config_name_match(const char *name)
8525a3775a4SLokesh Vutla {
8531736121bSLokesh Vutla if (board_is_evm() && !strcmp(name, "am437x-gp-evm"))
8545a3775a4SLokesh Vutla return 0;
8555a3775a4SLokesh Vutla else if (board_is_sk() && !strcmp(name, "am437x-sk-evm"))
8565a3775a4SLokesh Vutla return 0;
8577dd12830SLokesh Vutla else if (board_is_eposevm() && !strcmp(name, "am43x-epos-evm"))
8587dd12830SLokesh Vutla return 0;
85954a92e1aSLokesh Vutla else if (board_is_idk() && !strcmp(name, "am437x-idk-evm"))
86054a92e1aSLokesh Vutla return 0;
8615a3775a4SLokesh Vutla else
8625a3775a4SLokesh Vutla return -1;
8635a3775a4SLokesh Vutla }
8645a3775a4SLokesh Vutla #endif
865e29878fcSMadan Srinivas
866e29878fcSMadan Srinivas #ifdef CONFIG_TI_SECURE_DEVICE
board_fit_image_post_process(void ** p_image,size_t * p_size)867e29878fcSMadan Srinivas void board_fit_image_post_process(void **p_image, size_t *p_size)
868e29878fcSMadan Srinivas {
869e29878fcSMadan Srinivas secure_boot_verify_image(p_image, p_size);
870e29878fcSMadan Srinivas }
8713630094cSAndrew F. Davis
board_tee_image_process(ulong tee_image,size_t tee_size)8723630094cSAndrew F. Davis void board_tee_image_process(ulong tee_image, size_t tee_size)
8733630094cSAndrew F. Davis {
8743630094cSAndrew F. Davis secure_tee_install((u32)tee_image);
8753630094cSAndrew F. Davis }
8763630094cSAndrew F. Davis
8773630094cSAndrew F. Davis U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
878e29878fcSMadan Srinivas #endif
879