Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 1 | /* |
| 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 Nori | 9f1a8cd | 2013-12-10 15:02:15 +0530 | [diff] [blame] | 12 | #include <i2c.h> |
| 13 | #include <asm/errno.h> |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 14 | #include <spl.h> |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 15 | #include <usb.h> |
Lokesh Vutla | 3b34ac1 | 2013-07-30 11:36:29 +0530 | [diff] [blame] | 16 | #include <asm/arch/clock.h> |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/arch/mux.h> |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 19 | #include <asm/arch/ddr_defs.h> |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 20 | #include <asm/arch/gpio.h> |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 21 | #include <asm/emif.h> |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 22 | #include "board.h" |
Tom Rini | 7aa5598 | 2014-06-23 16:06:29 -0400 | [diff] [blame] | 23 | #include <power/pmic.h> |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 24 | #include <power/tps65218.h> |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 25 | #include <power/tps62362.h> |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 26 | #include <miiphy.h> |
| 27 | #include <cpsw.h> |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 28 | #include <linux/usb/gadget.h> |
| 29 | #include <dwc3-uboot.h> |
| 30 | #include <dwc3-omap-uboot.h> |
| 31 | #include <ti-usb-phy-uboot.h> |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 35 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 36 | |
Sekhar Nori | 9f1a8cd | 2013-12-10 15:02:15 +0530 | [diff] [blame] | 37 | /* |
| 38 | * Read header information from EEPROM into global structure. |
| 39 | */ |
| 40 | static int read_eeprom(struct am43xx_board_id *header) |
| 41 | { |
| 42 | /* Check if baseboard eeprom is available */ |
| 43 | if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) { |
| 44 | printf("Could not probe the EEPROM at 0x%x\n", |
| 45 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 46 | return -ENODEV; |
| 47 | } |
| 48 | |
| 49 | /* read the eeprom using i2c */ |
| 50 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header, |
| 51 | sizeof(struct am43xx_board_id))) { |
| 52 | printf("Could not read the EEPROM\n"); |
| 53 | return -EIO; |
| 54 | } |
| 55 | |
| 56 | if (header->magic != 0xEE3355AA) { |
| 57 | /* |
| 58 | * read the eeprom using i2c again, |
| 59 | * but use only a 1 byte address |
| 60 | */ |
| 61 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header, |
| 62 | sizeof(struct am43xx_board_id))) { |
| 63 | printf("Could not read the EEPROM at 0x%x\n", |
| 64 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 65 | return -EIO; |
| 66 | } |
| 67 | |
| 68 | if (header->magic != 0xEE3355AA) { |
| 69 | printf("Incorrect magic number (0x%x) in EEPROM\n", |
| 70 | header->magic); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | strncpy(am43xx_board_name, (char *)header->name, sizeof(header->name)); |
| 76 | am43xx_board_name[sizeof(header->name)] = 0; |
| 77 | |
Franklin S. Cooper Jr | 2c95211 | 2014-06-27 13:31:14 -0500 | [diff] [blame] | 78 | strncpy(am43xx_board_rev, (char *)header->version, sizeof(header->version)); |
| 79 | am43xx_board_rev[sizeof(header->version)] = 0; |
| 80 | |
Sekhar Nori | 9f1a8cd | 2013-12-10 15:02:15 +0530 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Sourav Poddar | 7a5f71b | 2014-05-19 16:53:37 -0400 | [diff] [blame] | 84 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 85 | |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 86 | #define NUM_OPPS 6 |
| 87 | |
| 88 | const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = { |
| 89 | { /* 19.2 MHz */ |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 90 | {125, 3, 2, -1, -1, -1, -1}, /* OPP 50 */ |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 91 | {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */ |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 92 | {125, 3, 1, -1, -1, -1, -1}, /* OPP 100 */ |
| 93 | {150, 3, 1, -1, -1, -1, -1}, /* OPP 120 */ |
| 94 | {125, 2, 1, -1, -1, -1, -1}, /* OPP TB */ |
| 95 | {625, 11, 1, -1, -1, -1, -1} /* OPP NT */ |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 96 | }, |
| 97 | { /* 24 MHz */ |
| 98 | {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */ |
| 99 | {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */ |
| 100 | {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */ |
| 101 | {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */ |
| 102 | {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */ |
| 103 | {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */ |
| 104 | }, |
| 105 | { /* 25 MHz */ |
| 106 | {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */ |
| 107 | {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */ |
| 108 | {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */ |
| 109 | {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */ |
| 110 | {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */ |
| 111 | {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */ |
| 112 | }, |
| 113 | { /* 26 MHz */ |
| 114 | {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */ |
| 115 | {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */ |
| 116 | {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */ |
| 117 | {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */ |
| 118 | {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */ |
| 119 | {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */ |
| 120 | }, |
| 121 | }; |
| 122 | |
| 123 | const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = { |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 124 | {625, 11, -1, -1, 10, 8, 4}, /* 19.2 MHz */ |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 125 | {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */ |
| 126 | {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */ |
| 127 | {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */ |
| 128 | }; |
| 129 | |
| 130 | const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = { |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 131 | {400, 7, 5, -1, -1, -1, -1}, /* 19.2 MHz */ |
| 132 | {400, 9, 5, -1, -1, -1, -1}, /* 24 MHz */ |
James Doublesin | c87b6a9 | 2014-12-22 16:26:12 -0600 | [diff] [blame] | 133 | {384, 9, 5, -1, -1, -1, -1}, /* 25 MHz */ |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 134 | {480, 12, 5, -1, -1, -1, -1} /* 26 MHz */ |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 135 | }; |
| 136 | |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 137 | const struct dpll_params epos_evm_dpll_ddr[NUM_CRYSTAL_FREQ] = { |
| 138 | {665, 47, 1, -1, 4, -1, -1}, /*19.2*/ |
| 139 | {133, 11, 1, -1, 4, -1, -1}, /* 24 MHz */ |
| 140 | {266, 24, 1, -1, 4, -1, -1}, /* 25 MHz */ |
| 141 | {133, 12, 1, -1, 4, -1, -1} /* 26 MHz */ |
| 142 | }; |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 143 | |
| 144 | const struct dpll_params gp_evm_dpll_ddr = { |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 145 | 50, 2, 1, -1, 2, -1, -1}; |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 146 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 147 | static const struct dpll_params idk_dpll_ddr = { |
| 148 | 400, 23, 1, -1, 2, -1, -1 |
| 149 | }; |
| 150 | |
Tom Rini | 7c352cd | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 151 | static const u32 ext_phy_ctrl_const_base_lpddr2[] = { |
| 152 | 0x00500050, |
| 153 | 0x00350035, |
| 154 | 0x00350035, |
| 155 | 0x00350035, |
| 156 | 0x00350035, |
| 157 | 0x00350035, |
| 158 | 0x00000000, |
| 159 | 0x00000000, |
| 160 | 0x00000000, |
| 161 | 0x00000000, |
| 162 | 0x00000000, |
| 163 | 0x00000000, |
| 164 | 0x00000000, |
| 165 | 0x00000000, |
| 166 | 0x00000000, |
| 167 | 0x00000000, |
| 168 | 0x00000000, |
| 169 | 0x00000000, |
| 170 | 0x40001000, |
| 171 | 0x08102040 |
| 172 | }; |
| 173 | |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 174 | const struct ctrl_ioregs ioregs_lpddr2 = { |
| 175 | .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE, |
| 176 | .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE, |
| 177 | .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE, |
| 178 | .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE, |
| 179 | .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE, |
| 180 | .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE, |
| 181 | .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE, |
| 182 | .emif_sdram_config_ext = 0x1, |
| 183 | }; |
| 184 | |
| 185 | const struct emif_regs emif_regs_lpddr2 = { |
| 186 | .sdram_config = 0x808012BA, |
| 187 | .ref_ctrl = 0x0000040D, |
| 188 | .sdram_tim1 = 0xEA86B411, |
| 189 | .sdram_tim2 = 0x103A094A, |
| 190 | .sdram_tim3 = 0x0F6BA37F, |
| 191 | .read_idle_ctrl = 0x00050000, |
| 192 | .zq_config = 0x50074BE4, |
| 193 | .temp_alert_config = 0x0, |
| 194 | .emif_rd_wr_lvl_rmp_win = 0x0, |
| 195 | .emif_rd_wr_lvl_rmp_ctl = 0x0, |
| 196 | .emif_rd_wr_lvl_ctl = 0x0, |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 197 | .emif_ddr_phy_ctlr_1 = 0x0E284006, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 198 | .emif_rd_wr_exec_thresh = 0x80000405, |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 199 | .emif_ddr_ext_phy_ctrl_1 = 0x04010040, |
| 200 | .emif_ddr_ext_phy_ctrl_2 = 0x00500050, |
| 201 | .emif_ddr_ext_phy_ctrl_3 = 0x00500050, |
| 202 | .emif_ddr_ext_phy_ctrl_4 = 0x00500050, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 203 | .emif_ddr_ext_phy_ctrl_5 = 0x00500050, |
| 204 | .emif_prio_class_serv_map = 0x80000001, |
| 205 | .emif_connect_id_serv_1_map = 0x80000094, |
| 206 | .emif_connect_id_serv_2_map = 0x00000000, |
| 207 | .emif_cos_config = 0x000FFFFF |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 208 | }; |
| 209 | |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 210 | const struct ctrl_ioregs ioregs_ddr3 = { |
| 211 | .cm0ioctl = DDR3_ADDRCTRL_IOCTRL_VALUE, |
| 212 | .cm1ioctl = DDR3_ADDRCTRL_WD0_IOCTRL_VALUE, |
| 213 | .cm2ioctl = DDR3_ADDRCTRL_WD1_IOCTRL_VALUE, |
| 214 | .dt0ioctl = DDR3_DATA0_IOCTRL_VALUE, |
| 215 | .dt1ioctl = DDR3_DATA0_IOCTRL_VALUE, |
| 216 | .dt2ioctrl = DDR3_DATA0_IOCTRL_VALUE, |
| 217 | .dt3ioctrl = DDR3_DATA0_IOCTRL_VALUE, |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 218 | .emif_sdram_config_ext = 0xc163, |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | const struct emif_regs ddr3_emif_regs_400Mhz = { |
| 222 | .sdram_config = 0x638413B2, |
| 223 | .ref_ctrl = 0x00000C30, |
| 224 | .sdram_tim1 = 0xEAAAD4DB, |
| 225 | .sdram_tim2 = 0x266B7FDA, |
| 226 | .sdram_tim3 = 0x107F8678, |
| 227 | .read_idle_ctrl = 0x00050000, |
| 228 | .zq_config = 0x50074BE4, |
| 229 | .temp_alert_config = 0x0, |
Lokesh Vutla | e27f2dd | 2014-02-18 07:31:57 -0500 | [diff] [blame] | 230 | .emif_ddr_phy_ctlr_1 = 0x0E004008, |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 231 | .emif_ddr_ext_phy_ctrl_1 = 0x08020080, |
| 232 | .emif_ddr_ext_phy_ctrl_2 = 0x00400040, |
| 233 | .emif_ddr_ext_phy_ctrl_3 = 0x00400040, |
| 234 | .emif_ddr_ext_phy_ctrl_4 = 0x00400040, |
| 235 | .emif_ddr_ext_phy_ctrl_5 = 0x00400040, |
| 236 | .emif_rd_wr_lvl_rmp_win = 0x0, |
| 237 | .emif_rd_wr_lvl_rmp_ctl = 0x0, |
| 238 | .emif_rd_wr_lvl_ctl = 0x0, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 239 | .emif_rd_wr_exec_thresh = 0x80000405, |
| 240 | .emif_prio_class_serv_map = 0x80000001, |
| 241 | .emif_connect_id_serv_1_map = 0x80000094, |
| 242 | .emif_connect_id_serv_2_map = 0x00000000, |
| 243 | .emif_cos_config = 0x000FFFFF |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 244 | }; |
| 245 | |
Franklin S. Cooper Jr | 2c95211 | 2014-06-27 13:31:14 -0500 | [diff] [blame] | 246 | /* EMIF DDR3 Configurations are different for beta AM43X GP EVMs */ |
| 247 | const struct emif_regs ddr3_emif_regs_400Mhz_beta = { |
| 248 | .sdram_config = 0x638413B2, |
| 249 | .ref_ctrl = 0x00000C30, |
| 250 | .sdram_tim1 = 0xEAAAD4DB, |
| 251 | .sdram_tim2 = 0x266B7FDA, |
| 252 | .sdram_tim3 = 0x107F8678, |
| 253 | .read_idle_ctrl = 0x00050000, |
| 254 | .zq_config = 0x50074BE4, |
| 255 | .temp_alert_config = 0x0, |
| 256 | .emif_ddr_phy_ctlr_1 = 0x0E004008, |
| 257 | .emif_ddr_ext_phy_ctrl_1 = 0x08020080, |
| 258 | .emif_ddr_ext_phy_ctrl_2 = 0x00000065, |
| 259 | .emif_ddr_ext_phy_ctrl_3 = 0x00000091, |
| 260 | .emif_ddr_ext_phy_ctrl_4 = 0x000000B5, |
| 261 | .emif_ddr_ext_phy_ctrl_5 = 0x000000E5, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 262 | .emif_rd_wr_exec_thresh = 0x80000405, |
| 263 | .emif_prio_class_serv_map = 0x80000001, |
| 264 | .emif_connect_id_serv_1_map = 0x80000094, |
| 265 | .emif_connect_id_serv_2_map = 0x00000000, |
| 266 | .emif_cos_config = 0x000FFFFF |
Franklin S. Cooper Jr | 2c95211 | 2014-06-27 13:31:14 -0500 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | /* EMIF DDR3 Configurations are different for production AM43X GP EVMs */ |
| 270 | const struct emif_regs ddr3_emif_regs_400Mhz_production = { |
| 271 | .sdram_config = 0x638413B2, |
| 272 | .ref_ctrl = 0x00000C30, |
| 273 | .sdram_tim1 = 0xEAAAD4DB, |
| 274 | .sdram_tim2 = 0x266B7FDA, |
| 275 | .sdram_tim3 = 0x107F8678, |
| 276 | .read_idle_ctrl = 0x00050000, |
| 277 | .zq_config = 0x50074BE4, |
| 278 | .temp_alert_config = 0x0, |
| 279 | .emif_ddr_phy_ctlr_1 = 0x0E004008, |
| 280 | .emif_ddr_ext_phy_ctrl_1 = 0x08020080, |
| 281 | .emif_ddr_ext_phy_ctrl_2 = 0x00000066, |
| 282 | .emif_ddr_ext_phy_ctrl_3 = 0x00000091, |
| 283 | .emif_ddr_ext_phy_ctrl_4 = 0x000000B9, |
| 284 | .emif_ddr_ext_phy_ctrl_5 = 0x000000E6, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 285 | .emif_rd_wr_exec_thresh = 0x80000405, |
| 286 | .emif_prio_class_serv_map = 0x80000001, |
| 287 | .emif_connect_id_serv_1_map = 0x80000094, |
| 288 | .emif_connect_id_serv_2_map = 0x00000000, |
| 289 | .emif_cos_config = 0x000FFFFF |
Franklin S. Cooper Jr | 2c95211 | 2014-06-27 13:31:14 -0500 | [diff] [blame] | 290 | }; |
| 291 | |
Felipe Balbi | 9cb9f33 | 2014-06-10 15:01:20 -0500 | [diff] [blame] | 292 | static const struct emif_regs ddr3_sk_emif_regs_400Mhz = { |
| 293 | .sdram_config = 0x638413b2, |
| 294 | .sdram_config2 = 0x00000000, |
| 295 | .ref_ctrl = 0x00000c30, |
| 296 | .sdram_tim1 = 0xeaaad4db, |
| 297 | .sdram_tim2 = 0x266b7fda, |
| 298 | .sdram_tim3 = 0x107f8678, |
| 299 | .read_idle_ctrl = 0x00050000, |
| 300 | .zq_config = 0x50074be4, |
| 301 | .temp_alert_config = 0x0, |
| 302 | .emif_ddr_phy_ctlr_1 = 0x0e084008, |
| 303 | .emif_ddr_ext_phy_ctrl_1 = 0x08020080, |
| 304 | .emif_ddr_ext_phy_ctrl_2 = 0x89, |
| 305 | .emif_ddr_ext_phy_ctrl_3 = 0x90, |
| 306 | .emif_ddr_ext_phy_ctrl_4 = 0x8e, |
| 307 | .emif_ddr_ext_phy_ctrl_5 = 0x8d, |
| 308 | .emif_rd_wr_lvl_rmp_win = 0x0, |
| 309 | .emif_rd_wr_lvl_rmp_ctl = 0x00000000, |
| 310 | .emif_rd_wr_lvl_ctl = 0x00000000, |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 311 | .emif_rd_wr_exec_thresh = 0x80000000, |
| 312 | .emif_prio_class_serv_map = 0x80000001, |
| 313 | .emif_connect_id_serv_1_map = 0x80000094, |
| 314 | .emif_connect_id_serv_2_map = 0x00000000, |
| 315 | .emif_cos_config = 0x000FFFFF |
Felipe Balbi | 9cb9f33 | 2014-06-10 15:01:20 -0500 | [diff] [blame] | 316 | }; |
| 317 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 318 | static const struct emif_regs ddr3_idk_emif_regs_400Mhz = { |
| 319 | .sdram_config = 0x61a11b32, |
| 320 | .sdram_config2 = 0x00000000, |
| 321 | .ref_ctrl = 0x00000c30, |
| 322 | .sdram_tim1 = 0xeaaad4db, |
| 323 | .sdram_tim2 = 0x266b7fda, |
| 324 | .sdram_tim3 = 0x107f8678, |
| 325 | .read_idle_ctrl = 0x00050000, |
| 326 | .zq_config = 0x50074be4, |
| 327 | .temp_alert_config = 0x00000000, |
| 328 | .emif_ddr_phy_ctlr_1 = 0x00008009, |
| 329 | .emif_ddr_ext_phy_ctrl_1 = 0x08020080, |
| 330 | .emif_ddr_ext_phy_ctrl_2 = 0x00000040, |
| 331 | .emif_ddr_ext_phy_ctrl_3 = 0x0000003e, |
| 332 | .emif_ddr_ext_phy_ctrl_4 = 0x00000051, |
| 333 | .emif_ddr_ext_phy_ctrl_5 = 0x00000051, |
| 334 | .emif_rd_wr_lvl_rmp_win = 0x00000000, |
| 335 | .emif_rd_wr_lvl_rmp_ctl = 0x00000000, |
| 336 | .emif_rd_wr_lvl_ctl = 0x00000000, |
| 337 | .emif_rd_wr_exec_thresh = 0x00000405, |
| 338 | .emif_prio_class_serv_map = 0x00000000, |
| 339 | .emif_connect_id_serv_1_map = 0x00000000, |
| 340 | .emif_connect_id_serv_2_map = 0x00000000, |
| 341 | .emif_cos_config = 0x00ffffff |
| 342 | }; |
| 343 | |
Tom Rini | 7c352cd | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 344 | void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size) |
| 345 | { |
| 346 | if (board_is_eposevm()) { |
| 347 | *regs = ext_phy_ctrl_const_base_lpddr2; |
| 348 | *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2); |
| 349 | } |
| 350 | |
| 351 | return; |
| 352 | } |
| 353 | |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 354 | /* |
| 355 | * get_sys_clk_index : returns the index of the sys_clk read from |
| 356 | * ctrl status register. This value is either |
| 357 | * read from efuse or sysboot pins. |
| 358 | */ |
| 359 | static u32 get_sys_clk_index(void) |
| 360 | { |
| 361 | struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE; |
| 362 | u32 ind = readl(&ctrl->statusreg), src; |
| 363 | |
| 364 | src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT; |
| 365 | if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */ |
| 366 | return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >> |
| 367 | CTRL_CRYSTAL_FREQ_SELECTION_SHIFT); |
| 368 | else /* Value read from SYS BOOT pins */ |
| 369 | return ((ind & CTRL_SYSBOOT_15_14_MASK) >> |
| 370 | CTRL_SYSBOOT_15_14_SHIFT); |
| 371 | } |
| 372 | |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 373 | const struct dpll_params *get_dpll_ddr_params(void) |
| 374 | { |
| 375 | int ind = get_sys_clk_index(); |
| 376 | |
| 377 | if (board_is_eposevm()) |
| 378 | return &epos_evm_dpll_ddr[ind]; |
| 379 | else if (board_is_gpevm() || board_is_sk()) |
| 380 | return &gp_evm_dpll_ddr; |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 381 | else if (board_is_idk()) |
| 382 | return &idk_dpll_ddr; |
James Doublesin | e2a6207 | 2014-12-22 16:26:10 -0600 | [diff] [blame] | 383 | |
| 384 | printf(" Board '%s' not supported\n", am43xx_board_name); |
| 385 | return NULL; |
| 386 | } |
| 387 | |
| 388 | |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 389 | /* |
| 390 | * get_opp_offset: |
| 391 | * Returns the index for safest OPP of the device to boot. |
| 392 | * max_off: Index of the MAX OPP in DEV ATTRIBUTE register. |
| 393 | * min_off: Index of the MIN OPP in DEV ATTRIBUTE register. |
| 394 | * This data is read from dev_attribute register which is e-fused. |
| 395 | * A'1' in bit indicates OPP disabled and not available, a '0' indicates |
| 396 | * OPP available. Lowest OPP starts with min_off. So returning the |
| 397 | * bit with rightmost '0'. |
| 398 | */ |
| 399 | static int get_opp_offset(int max_off, int min_off) |
| 400 | { |
| 401 | struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE; |
Tom Rini | feca6e6 | 2014-06-05 11:15:27 -0400 | [diff] [blame] | 402 | int opp, offset, i; |
| 403 | |
| 404 | /* Bits 0:11 are defined to be the MPU_MAX_FREQ */ |
| 405 | opp = readl(&ctrl->dev_attr) & ~0xFFFFF000; |
Lokesh Vutla | cf04d03 | 2013-12-10 15:02:20 +0530 | [diff] [blame] | 406 | |
| 407 | for (i = max_off; i >= min_off; i--) { |
| 408 | offset = opp & (1 << i); |
| 409 | if (!offset) |
| 410 | return i; |
| 411 | } |
| 412 | |
| 413 | return min_off; |
| 414 | } |
| 415 | |
| 416 | const struct dpll_params *get_dpll_mpu_params(void) |
| 417 | { |
| 418 | int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET); |
| 419 | u32 ind = get_sys_clk_index(); |
| 420 | |
| 421 | return &dpll_mpu[ind][opp]; |
| 422 | } |
| 423 | |
| 424 | const struct dpll_params *get_dpll_core_params(void) |
| 425 | { |
| 426 | int ind = get_sys_clk_index(); |
| 427 | |
| 428 | return &dpll_core[ind]; |
| 429 | } |
| 430 | |
| 431 | const struct dpll_params *get_dpll_per_params(void) |
| 432 | { |
| 433 | int ind = get_sys_clk_index(); |
| 434 | |
| 435 | return &dpll_per[ind]; |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 438 | void scale_vcores_generic(u32 m) |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 439 | { |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 440 | int mpu_vdd; |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 441 | |
| 442 | if (i2c_probe(TPS65218_CHIP_PM)) |
| 443 | return; |
| 444 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 445 | switch (m) { |
Felipe Balbi | 068ea0a | 2014-12-22 16:26:13 -0600 | [diff] [blame] | 446 | case 1000: |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 447 | mpu_vdd = TPS65218_DCDC_VOLT_SEL_1330MV; |
Felipe Balbi | 068ea0a | 2014-12-22 16:26:13 -0600 | [diff] [blame] | 448 | break; |
Felipe Balbi | d5c082a | 2014-12-22 16:26:15 -0600 | [diff] [blame] | 449 | case 800: |
| 450 | mpu_vdd = TPS65218_DCDC_VOLT_SEL_1260MV; |
| 451 | break; |
| 452 | case 720: |
| 453 | mpu_vdd = TPS65218_DCDC_VOLT_SEL_1200MV; |
| 454 | break; |
Felipe Balbi | 068ea0a | 2014-12-22 16:26:13 -0600 | [diff] [blame] | 455 | case 600: |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 456 | mpu_vdd = TPS65218_DCDC_VOLT_SEL_1100MV; |
Felipe Balbi | 068ea0a | 2014-12-22 16:26:13 -0600 | [diff] [blame] | 457 | break; |
Felipe Balbi | d5c082a | 2014-12-22 16:26:15 -0600 | [diff] [blame] | 458 | case 300: |
| 459 | mpu_vdd = TPS65218_DCDC_VOLT_SEL_0950MV; |
| 460 | break; |
Felipe Balbi | 068ea0a | 2014-12-22 16:26:13 -0600 | [diff] [blame] | 461 | default: |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 462 | puts("Unknown MPU clock, not scaling\n"); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | /* Set DCDC1 (CORE) voltage to 1.1V */ |
| 467 | if (tps65218_voltage_update(TPS65218_DCDC1, |
| 468 | TPS65218_DCDC_VOLT_SEL_1100MV)) { |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 469 | printf("%s failure\n", __func__); |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | |
| 473 | /* Set DCDC2 (MPU) voltage */ |
| 474 | if (tps65218_voltage_update(TPS65218_DCDC2, mpu_vdd)) { |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 475 | printf("%s failure\n", __func__); |
Tom Rini | 83bad10 | 2014-06-05 11:15:30 -0400 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | } |
| 479 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 480 | void scale_vcores_idk(u32 m) |
| 481 | { |
| 482 | int mpu_vdd; |
| 483 | |
| 484 | if (i2c_probe(TPS62362_I2C_ADDR)) |
| 485 | return; |
| 486 | |
| 487 | switch (m) { |
| 488 | case 1000: |
| 489 | mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV; |
| 490 | break; |
| 491 | case 800: |
| 492 | mpu_vdd = TPS62362_DCDC_VOLT_SEL_1260MV; |
| 493 | break; |
| 494 | case 720: |
| 495 | mpu_vdd = TPS62362_DCDC_VOLT_SEL_1200MV; |
| 496 | break; |
| 497 | case 600: |
| 498 | mpu_vdd = TPS62362_DCDC_VOLT_SEL_1100MV; |
| 499 | break; |
| 500 | case 300: |
| 501 | mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV; |
| 502 | break; |
| 503 | default: |
| 504 | puts("Unknown MPU clock, not scaling\n"); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | /* Set VDD_MPU voltage */ |
| 509 | if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) { |
| 510 | printf("%s failure\n", __func__); |
| 511 | return; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | void scale_vcores(void) |
| 516 | { |
| 517 | const struct dpll_params *mpu_params; |
| 518 | struct am43xx_board_id header; |
| 519 | |
| 520 | enable_i2c0_pin_mux(); |
| 521 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
| 522 | if (read_eeprom(&header) < 0) |
| 523 | puts("Could not get board ID.\n"); |
| 524 | |
| 525 | /* Get the frequency */ |
| 526 | mpu_params = get_dpll_mpu_params(); |
| 527 | |
| 528 | if (board_is_idk()) |
| 529 | scale_vcores_idk(mpu_params->m); |
| 530 | else |
| 531 | scale_vcores_generic(mpu_params->m); |
| 532 | } |
| 533 | |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 534 | void set_uart_mux_conf(void) |
| 535 | { |
| 536 | enable_uart0_pin_mux(); |
| 537 | } |
| 538 | |
| 539 | void set_mux_conf_regs(void) |
| 540 | { |
| 541 | enable_board_pin_mux(); |
| 542 | } |
| 543 | |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 544 | static void enable_vtt_regulator(void) |
| 545 | { |
| 546 | u32 temp; |
| 547 | |
| 548 | /* enable module */ |
Dave Gerlach | cd8341b | 2014-02-10 11:41:49 -0500 | [diff] [blame] | 549 | writel(GPIO_CTRL_ENABLEMODULE, AM33XX_GPIO5_BASE + OMAP_GPIO_CTRL); |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 550 | |
Dave Gerlach | cd8341b | 2014-02-10 11:41:49 -0500 | [diff] [blame] | 551 | /* enable output for GPIO5_7 */ |
| 552 | writel(GPIO_SETDATAOUT(7), |
| 553 | AM33XX_GPIO5_BASE + OMAP_GPIO_SETDATAOUT); |
| 554 | temp = readl(AM33XX_GPIO5_BASE + OMAP_GPIO_OE); |
| 555 | temp = temp & ~(GPIO_OE_ENABLE(7)); |
| 556 | writel(temp, AM33XX_GPIO5_BASE + OMAP_GPIO_OE); |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 557 | } |
| 558 | |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 559 | void sdram_init(void) |
| 560 | { |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 561 | /* |
| 562 | * EPOS EVM has 1GB LPDDR2 connected to EMIF. |
| 563 | * GP EMV has 1GB DDR3 connected to EMIF |
| 564 | * along with VTT regulator. |
| 565 | */ |
| 566 | if (board_is_eposevm()) { |
| 567 | config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0); |
Franklin S. Cooper Jr | 2c95211 | 2014-06-27 13:31:14 -0500 | [diff] [blame] | 568 | } else if (board_is_evm_14_or_later()) { |
| 569 | enable_vtt_regulator(); |
| 570 | config_ddr(0, &ioregs_ddr3, NULL, NULL, |
| 571 | &ddr3_emif_regs_400Mhz_production, 0); |
| 572 | } else if (board_is_evm_12_or_later()) { |
| 573 | enable_vtt_regulator(); |
| 574 | config_ddr(0, &ioregs_ddr3, NULL, NULL, |
| 575 | &ddr3_emif_regs_400Mhz_beta, 0); |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 576 | } else if (board_is_gpevm()) { |
| 577 | enable_vtt_regulator(); |
| 578 | config_ddr(0, &ioregs_ddr3, NULL, NULL, |
| 579 | &ddr3_emif_regs_400Mhz, 0); |
Felipe Balbi | 9cb9f33 | 2014-06-10 15:01:20 -0500 | [diff] [blame] | 580 | } else if (board_is_sk()) { |
| 581 | config_ddr(400, &ioregs_ddr3, NULL, NULL, |
| 582 | &ddr3_sk_emif_regs_400Mhz, 0); |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 583 | } else if (board_is_idk()) { |
| 584 | config_ddr(400, &ioregs_ddr3, NULL, NULL, |
| 585 | &ddr3_idk_emif_regs_400Mhz, 0); |
Lokesh Vutla | b5e01ee | 2013-12-10 15:02:23 +0530 | [diff] [blame] | 586 | } |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 587 | } |
| 588 | #endif |
| 589 | |
Tom Rini | 7aa5598 | 2014-06-23 16:06:29 -0400 | [diff] [blame] | 590 | /* setup board specific PMIC */ |
| 591 | int power_init_board(void) |
| 592 | { |
| 593 | struct pmic *p; |
| 594 | |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 595 | if (board_is_idk()) { |
| 596 | power_tps62362_init(I2C_PMIC); |
| 597 | p = pmic_get("TPS62362"); |
| 598 | if (p && !pmic_probe(p)) |
| 599 | puts("PMIC: TPS62362\n"); |
| 600 | } else { |
| 601 | power_tps65218_init(I2C_PMIC); |
| 602 | p = pmic_get("TPS65218_PMIC"); |
| 603 | if (p && !pmic_probe(p)) |
| 604 | puts("PMIC: TPS65218\n"); |
| 605 | } |
Tom Rini | 7aa5598 | 2014-06-23 16:06:29 -0400 | [diff] [blame] | 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 610 | int board_init(void) |
| 611 | { |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 612 | struct l3f_cfg_bwlimiter *bwlimiter = (struct l3f_cfg_bwlimiter *)L3F_CFG_BWLIMITER; |
| 613 | u32 mreqprio_0, mreqprio_1, modena_init0_bw_fractional, |
| 614 | modena_init0_bw_integer, modena_init0_watermark_0; |
| 615 | |
Lokesh Vutla | 369cbe1 | 2013-12-10 15:02:12 +0530 | [diff] [blame] | 616 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
pekon gupta | e53ad4b | 2014-07-22 16:03:22 +0530 | [diff] [blame] | 617 | gpmc_init(); |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 618 | |
Cooper Jr., Franklin | 8038b49 | 2014-06-27 13:31:15 -0500 | [diff] [blame] | 619 | /* Clear all important bits for DSS errata that may need to be tweaked*/ |
| 620 | mreqprio_0 = readl(&cdev->mreqprio_0) & MREQPRIO_0_SAB_INIT1_MASK & |
| 621 | MREQPRIO_0_SAB_INIT0_MASK; |
| 622 | |
| 623 | mreqprio_1 = readl(&cdev->mreqprio_1) & MREQPRIO_1_DSS_MASK; |
| 624 | |
| 625 | modena_init0_bw_fractional = readl(&bwlimiter->modena_init0_bw_fractional) & |
| 626 | BW_LIMITER_BW_FRAC_MASK; |
| 627 | |
| 628 | modena_init0_bw_integer = readl(&bwlimiter->modena_init0_bw_integer) & |
| 629 | BW_LIMITER_BW_INT_MASK; |
| 630 | |
| 631 | modena_init0_watermark_0 = readl(&bwlimiter->modena_init0_watermark_0) & |
| 632 | BW_LIMITER_BW_WATERMARK_MASK; |
| 633 | |
| 634 | /* Setting MReq Priority of the DSS*/ |
| 635 | mreqprio_0 |= 0x77; |
| 636 | |
| 637 | /* |
| 638 | * Set L3 Fast Configuration Register |
| 639 | * Limiting bandwith for ARM core to 700 MBPS |
| 640 | */ |
| 641 | modena_init0_bw_fractional |= 0x10; |
| 642 | modena_init0_bw_integer |= 0x3; |
| 643 | |
| 644 | writel(mreqprio_0, &cdev->mreqprio_0); |
| 645 | writel(mreqprio_1, &cdev->mreqprio_1); |
| 646 | |
| 647 | writel(modena_init0_bw_fractional, &bwlimiter->modena_init0_bw_fractional); |
| 648 | writel(modena_init0_bw_integer, &bwlimiter->modena_init0_bw_integer); |
| 649 | writel(modena_init0_watermark_0, &bwlimiter->modena_init0_watermark_0); |
| 650 | |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | #ifdef CONFIG_BOARD_LATE_INIT |
| 655 | int board_late_init(void) |
| 656 | { |
Sekhar Nori | f4af163 | 2013-12-10 15:02:16 +0530 | [diff] [blame] | 657 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 658 | char safe_string[HDR_NAME_LEN + 1]; |
| 659 | struct am43xx_board_id header; |
| 660 | |
| 661 | if (read_eeprom(&header) < 0) |
| 662 | puts("Could not get board ID.\n"); |
| 663 | |
| 664 | /* Now set variables based on the header. */ |
| 665 | strncpy(safe_string, (char *)header.name, sizeof(header.name)); |
| 666 | safe_string[sizeof(header.name)] = 0; |
| 667 | setenv("board_name", safe_string); |
| 668 | |
| 669 | strncpy(safe_string, (char *)header.version, sizeof(header.version)); |
| 670 | safe_string[sizeof(header.version)] = 0; |
| 671 | setenv("board_rev", safe_string); |
| 672 | #endif |
Lokesh Vutla | fbf2728 | 2013-07-30 11:36:27 +0530 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | #endif |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 676 | |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 677 | #ifdef CONFIG_USB_DWC3 |
| 678 | static struct dwc3_device usb_otg_ss1 = { |
| 679 | .maximum_speed = USB_SPEED_HIGH, |
| 680 | .base = USB_OTG_SS1_BASE, |
| 681 | .tx_fifo_resize = false, |
| 682 | .index = 0, |
| 683 | }; |
| 684 | |
| 685 | static struct dwc3_omap_device usb_otg_ss1_glue = { |
| 686 | .base = (void *)USB_OTG_SS1_GLUE_BASE, |
| 687 | .utmi_mode = DWC3_OMAP_UTMI_MODE_SW, |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 688 | .index = 0, |
| 689 | }; |
| 690 | |
| 691 | static struct ti_usb_phy_device usb_phy1_device = { |
| 692 | .usb2_phy_power = (void *)USB2_PHY1_POWER, |
| 693 | .index = 0, |
| 694 | }; |
| 695 | |
| 696 | static struct dwc3_device usb_otg_ss2 = { |
| 697 | .maximum_speed = USB_SPEED_HIGH, |
| 698 | .base = USB_OTG_SS2_BASE, |
| 699 | .tx_fifo_resize = false, |
| 700 | .index = 1, |
| 701 | }; |
| 702 | |
| 703 | static struct dwc3_omap_device usb_otg_ss2_glue = { |
| 704 | .base = (void *)USB_OTG_SS2_GLUE_BASE, |
| 705 | .utmi_mode = DWC3_OMAP_UTMI_MODE_SW, |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 706 | .index = 1, |
| 707 | }; |
| 708 | |
| 709 | static struct ti_usb_phy_device usb_phy2_device = { |
| 710 | .usb2_phy_power = (void *)USB2_PHY2_POWER, |
| 711 | .index = 1, |
| 712 | }; |
| 713 | |
| 714 | int board_usb_init(int index, enum usb_init_type init) |
| 715 | { |
Kishon Vijay Abraham I | 6f1af1e | 2015-08-19 16:16:27 +0530 | [diff] [blame] | 716 | enable_usb_clocks(index); |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 717 | switch (index) { |
| 718 | case 0: |
| 719 | if (init == USB_INIT_DEVICE) { |
| 720 | usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL; |
| 721 | usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID; |
| 722 | } else { |
| 723 | usb_otg_ss1.dr_mode = USB_DR_MODE_HOST; |
| 724 | usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND; |
| 725 | } |
| 726 | |
| 727 | dwc3_omap_uboot_init(&usb_otg_ss1_glue); |
| 728 | ti_usb_phy_uboot_init(&usb_phy1_device); |
| 729 | dwc3_uboot_init(&usb_otg_ss1); |
| 730 | break; |
| 731 | case 1: |
| 732 | if (init == USB_INIT_DEVICE) { |
| 733 | usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL; |
| 734 | usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID; |
| 735 | } else { |
| 736 | usb_otg_ss2.dr_mode = USB_DR_MODE_HOST; |
| 737 | usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND; |
| 738 | } |
| 739 | |
| 740 | ti_usb_phy_uboot_init(&usb_phy2_device); |
| 741 | dwc3_omap_uboot_init(&usb_otg_ss2_glue); |
| 742 | dwc3_uboot_init(&usb_otg_ss2); |
| 743 | break; |
| 744 | default: |
| 745 | printf("Invalid Controller Index\n"); |
| 746 | } |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 752 | { |
| 753 | switch (index) { |
| 754 | case 0: |
| 755 | case 1: |
| 756 | ti_usb_phy_uboot_exit(index); |
| 757 | dwc3_uboot_exit(index); |
| 758 | dwc3_omap_uboot_exit(index); |
| 759 | break; |
| 760 | default: |
| 761 | printf("Invalid Controller Index\n"); |
| 762 | } |
Kishon Vijay Abraham I | 6f1af1e | 2015-08-19 16:16:27 +0530 | [diff] [blame] | 763 | disable_usb_clocks(index); |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | |
Kishon Vijay Abraham I | 2d48aa6 | 2015-02-23 18:40:23 +0530 | [diff] [blame] | 768 | int usb_gadget_handle_interrupts(int index) |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 769 | { |
| 770 | u32 status; |
| 771 | |
Kishon Vijay Abraham I | 2d48aa6 | 2015-02-23 18:40:23 +0530 | [diff] [blame] | 772 | status = dwc3_omap_uboot_interrupt_status(index); |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 773 | if (status) |
Kishon Vijay Abraham I | 2d48aa6 | 2015-02-23 18:40:23 +0530 | [diff] [blame] | 774 | dwc3_uboot_handle_interrupt(index); |
Kishon Vijay Abraham I | 9f81eb7 | 2015-02-23 18:40:21 +0530 | [diff] [blame] | 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | #endif |
| 779 | |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 780 | #ifdef CONFIG_DRIVER_TI_CPSW |
| 781 | |
| 782 | static void cpsw_control(int enabled) |
| 783 | { |
| 784 | /* Additional controls can be added here */ |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 789 | { |
| 790 | .slave_reg_ofs = 0x208, |
| 791 | .sliver_reg_ofs = 0xd80, |
| 792 | .phy_addr = 16, |
| 793 | }, |
| 794 | { |
| 795 | .slave_reg_ofs = 0x308, |
| 796 | .sliver_reg_ofs = 0xdc0, |
| 797 | .phy_addr = 1, |
| 798 | }, |
| 799 | }; |
| 800 | |
| 801 | static struct cpsw_platform_data cpsw_data = { |
| 802 | .mdio_base = CPSW_MDIO_BASE, |
| 803 | .cpsw_base = CPSW_BASE, |
| 804 | .mdio_div = 0xff, |
| 805 | .channels = 8, |
| 806 | .cpdma_reg_ofs = 0x800, |
| 807 | .slaves = 1, |
| 808 | .slave_data = cpsw_slaves, |
| 809 | .ale_reg_ofs = 0xd00, |
| 810 | .ale_entries = 1024, |
| 811 | .host_port_reg_ofs = 0x108, |
| 812 | .hw_stats_reg_ofs = 0x900, |
| 813 | .bd_ram_ofs = 0x2000, |
| 814 | .mac_control = (1 << 5), |
| 815 | .control = cpsw_control, |
| 816 | .host_port_num = 0, |
| 817 | .version = CPSW_CTRL_VERSION_2, |
| 818 | }; |
| 819 | |
| 820 | int board_eth_init(bd_t *bis) |
| 821 | { |
| 822 | int rv; |
| 823 | uint8_t mac_addr[6]; |
| 824 | uint32_t mac_hi, mac_lo; |
| 825 | |
| 826 | /* try reading mac address from efuse */ |
| 827 | mac_lo = readl(&cdev->macid0l); |
| 828 | mac_hi = readl(&cdev->macid0h); |
| 829 | mac_addr[0] = mac_hi & 0xFF; |
| 830 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 831 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 832 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 833 | mac_addr[4] = mac_lo & 0xFF; |
| 834 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 835 | |
| 836 | if (!getenv("ethaddr")) { |
| 837 | puts("<ethaddr> not set. Validating first E-fuse MAC\n"); |
Joe Hershberger | 0adb5b7 | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 838 | if (is_valid_ethaddr(mac_addr)) |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 839 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 840 | } |
| 841 | |
| 842 | mac_lo = readl(&cdev->macid1l); |
| 843 | mac_hi = readl(&cdev->macid1h); |
| 844 | mac_addr[0] = mac_hi & 0xFF; |
| 845 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 846 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 847 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 848 | mac_addr[4] = mac_lo & 0xFF; |
| 849 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 850 | |
| 851 | if (!getenv("eth1addr")) { |
Joe Hershberger | 0adb5b7 | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 852 | if (is_valid_ethaddr(mac_addr)) |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 853 | eth_setenv_enetaddr("eth1addr", mac_addr); |
| 854 | } |
| 855 | |
| 856 | if (board_is_eposevm()) { |
| 857 | writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel); |
| 858 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII; |
| 859 | cpsw_slaves[0].phy_addr = 16; |
Felipe Balbi | 619ce62 | 2014-06-10 15:01:21 -0500 | [diff] [blame] | 860 | } else if (board_is_sk()) { |
| 861 | writel(RGMII_MODE_ENABLE, &cdev->miisel); |
| 862 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII; |
| 863 | cpsw_slaves[0].phy_addr = 4; |
| 864 | cpsw_slaves[1].phy_addr = 5; |
Felipe Balbi | 403d70a | 2014-12-22 16:26:17 -0600 | [diff] [blame] | 865 | } else if (board_is_idk()) { |
| 866 | writel(RGMII_MODE_ENABLE, &cdev->miisel); |
| 867 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII; |
| 868 | cpsw_slaves[0].phy_addr = 0; |
Mugunthan V N | 4cdd7fd | 2014-02-18 07:31:54 -0500 | [diff] [blame] | 869 | } else { |
| 870 | writel(RGMII_MODE_ENABLE, &cdev->miisel); |
| 871 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII; |
| 872 | cpsw_slaves[0].phy_addr = 0; |
| 873 | } |
| 874 | |
| 875 | rv = cpsw_register(&cpsw_data); |
| 876 | if (rv < 0) |
| 877 | printf("Error %d registering CPSW switch\n", rv); |
| 878 | |
| 879 | return rv; |
| 880 | } |
| 881 | #endif |