Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * board.c |
| 3 | * |
| 4 | * Board functions for TI AM335X based boards |
| 5 | * |
| 6 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <errno.h> |
| 13 | #include <spl.h> |
| 14 | #include <asm/arch/cpu.h> |
| 15 | #include <asm/arch/hardware.h> |
| 16 | #include <asm/arch/omap.h> |
| 17 | #include <asm/arch/ddr_defs.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/arch/gpio.h> |
| 20 | #include <asm/arch/mmc_host_def.h> |
| 21 | #include <asm/arch/sys_proto.h> |
Steve Kipisz | cd8845d | 2013-07-18 15:13:03 -0400 | [diff] [blame] | 22 | #include <asm/arch/mem.h> |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/emif.h> |
| 25 | #include <asm/gpio.h> |
| 26 | #include <i2c.h> |
| 27 | #include <miiphy.h> |
| 28 | #include <cpsw.h> |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 29 | #include <power/tps65217.h> |
| 30 | #include <power/tps65910.h> |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 31 | #include <environment.h> |
| 32 | #include <watchdog.h> |
Tom Rini | ba9a670 | 2014-03-28 12:03:38 -0400 | [diff] [blame] | 33 | #include <environment.h> |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 34 | #include "../common/board_detect.h" |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 35 | #include "board.h" |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 39 | /* GPIO that controls power to DDR on EVM-SK */ |
| 40 | #define GPIO_DDR_VTT_EN 7 |
| 41 | |
Mugunthan V N | bd83e3d | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 42 | #if defined(CONFIG_SPL_BUILD) || \ |
| 43 | (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH)) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 44 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
Mugunthan V N | bd83e3d | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 45 | #endif |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 46 | |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 47 | /* |
| 48 | * Read header information from EEPROM into global structure. |
| 49 | */ |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 50 | static inline int __maybe_unused read_eeprom(void) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 51 | { |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 52 | return ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR); |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Tom Rini | d0e6d34 | 2014-04-09 08:25:57 -0400 | [diff] [blame] | 55 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 56 | static const struct ddr_data ddr2_data = { |
Tom Rini | c4f80f5 | 2014-07-07 21:40:16 -0400 | [diff] [blame] | 57 | .datardsratio0 = MT47H128M16RT25E_RD_DQS, |
| 58 | .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE, |
| 59 | .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static const struct cmd_control ddr2_cmd_ctrl_data = { |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 63 | .cmd0csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 64 | |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 65 | .cmd1csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 66 | |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 67 | .cmd2csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | static const struct emif_regs ddr2_emif_reg_data = { |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 71 | .sdram_config = MT47H128M16RT25E_EMIF_SDCFG, |
| 72 | .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF, |
| 73 | .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1, |
| 74 | .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2, |
| 75 | .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3, |
| 76 | .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const struct ddr_data ddr3_data = { |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 80 | .datardsratio0 = MT41J128MJT125_RD_DQS, |
| 81 | .datawdsratio0 = MT41J128MJT125_WR_DQS, |
| 82 | .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE, |
| 83 | .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 86 | static const struct ddr_data ddr3_beagleblack_data = { |
| 87 | .datardsratio0 = MT41K256M16HA125E_RD_DQS, |
| 88 | .datawdsratio0 = MT41K256M16HA125E_WR_DQS, |
| 89 | .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE, |
| 90 | .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA, |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 93 | static const struct ddr_data ddr3_evm_data = { |
| 94 | .datardsratio0 = MT41J512M8RH125_RD_DQS, |
| 95 | .datawdsratio0 = MT41J512M8RH125_WR_DQS, |
| 96 | .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE, |
| 97 | .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA, |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 100 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 101 | .cmd0csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 102 | .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 103 | |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 104 | .cmd1csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 105 | .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 106 | |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 107 | .cmd2csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 108 | .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 111 | static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = { |
| 112 | .cmd0csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 113 | .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 114 | |
| 115 | .cmd1csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 116 | .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 117 | |
| 118 | .cmd2csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 119 | .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 120 | }; |
| 121 | |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 122 | static const struct cmd_control ddr3_evm_cmd_ctrl_data = { |
| 123 | .cmd0csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 124 | .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 125 | |
| 126 | .cmd1csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 127 | .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 128 | |
| 129 | .cmd2csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 130 | .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 131 | }; |
| 132 | |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 133 | static struct emif_regs ddr3_emif_reg_data = { |
Peter Korsgaard | c7d35be | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 134 | .sdram_config = MT41J128MJT125_EMIF_SDCFG, |
| 135 | .ref_ctrl = MT41J128MJT125_EMIF_SDREF, |
| 136 | .sdram_tim1 = MT41J128MJT125_EMIF_TIM1, |
| 137 | .sdram_tim2 = MT41J128MJT125_EMIF_TIM2, |
| 138 | .sdram_tim3 = MT41J128MJT125_EMIF_TIM3, |
| 139 | .zq_config = MT41J128MJT125_ZQ_CFG, |
Vaibhav Hiremath | 59dcf97 | 2013-03-14 21:11:16 +0000 | [diff] [blame] | 140 | .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY | |
| 141 | PHY_EN_DYN_PWRDN, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 142 | }; |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 143 | |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 144 | static struct emif_regs ddr3_beagleblack_emif_reg_data = { |
| 145 | .sdram_config = MT41K256M16HA125E_EMIF_SDCFG, |
| 146 | .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF, |
| 147 | .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1, |
| 148 | .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2, |
| 149 | .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3, |
| 150 | .zq_config = MT41K256M16HA125E_ZQ_CFG, |
| 151 | .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY, |
| 152 | }; |
| 153 | |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 154 | static struct emif_regs ddr3_evm_emif_reg_data = { |
| 155 | .sdram_config = MT41J512M8RH125_EMIF_SDCFG, |
| 156 | .ref_ctrl = MT41J512M8RH125_EMIF_SDREF, |
| 157 | .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1, |
| 158 | .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2, |
| 159 | .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3, |
| 160 | .zq_config = MT41J512M8RH125_ZQ_CFG, |
Vaibhav Hiremath | 59dcf97 | 2013-03-14 21:11:16 +0000 | [diff] [blame] | 161 | .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY | |
| 162 | PHY_EN_DYN_PWRDN, |
Jeff Lance | 13526f7 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 163 | }; |
Peter Korsgaard | 12d7a47 | 2013-05-13 08:36:30 +0000 | [diff] [blame] | 164 | |
| 165 | #ifdef CONFIG_SPL_OS_BOOT |
| 166 | int spl_start_uboot(void) |
| 167 | { |
| 168 | /* break into full u-boot on 'c' */ |
Tom Rini | ba9a670 | 2014-03-28 12:03:38 -0400 | [diff] [blame] | 169 | if (serial_tstc() && serial_getc() == 'c') |
| 170 | return 1; |
| 171 | |
| 172 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 173 | env_init(); |
| 174 | env_relocate_spec(); |
| 175 | if (getenv_yesno("boot_os") != 1) |
| 176 | return 1; |
| 177 | #endif |
| 178 | |
| 179 | return 0; |
Peter Korsgaard | 12d7a47 | 2013-05-13 08:36:30 +0000 | [diff] [blame] | 180 | } |
| 181 | #endif |
| 182 | |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 183 | #define OSC (V_OSCK/1000000) |
| 184 | const struct dpll_params dpll_ddr = { |
| 185 | 266, OSC-1, 1, -1, -1, -1, -1}; |
| 186 | const struct dpll_params dpll_ddr_evm_sk = { |
| 187 | 303, OSC-1, 1, -1, -1, -1, -1}; |
| 188 | const struct dpll_params dpll_ddr_bone_black = { |
| 189 | 400, OSC-1, 1, -1, -1, -1, -1}; |
| 190 | |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 191 | void am33xx_spl_board_init(void) |
| 192 | { |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 193 | int mpu_vdd; |
| 194 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 195 | if (read_eeprom() < 0) |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 196 | puts("Could not get board ID.\n"); |
| 197 | |
| 198 | /* Get the frequency */ |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 199 | dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 200 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 201 | if (board_is_bone() || board_is_bone_lt()) { |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 202 | /* BeagleBone PMIC Code */ |
| 203 | int usb_cur_lim; |
| 204 | |
| 205 | /* |
| 206 | * Only perform PMIC configurations if board rev > A1 |
| 207 | * on Beaglebone White |
| 208 | */ |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 209 | if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4)) |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 210 | return; |
| 211 | |
| 212 | if (i2c_probe(TPS65217_CHIP_PM)) |
| 213 | return; |
| 214 | |
| 215 | /* |
| 216 | * On Beaglebone White we need to ensure we have AC power |
| 217 | * before increasing the frequency. |
| 218 | */ |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 219 | if (board_is_bone()) { |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 220 | uchar pmic_status_reg; |
| 221 | if (tps65217_reg_read(TPS65217_STATUS, |
| 222 | &pmic_status_reg)) |
| 223 | return; |
| 224 | if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) { |
| 225 | puts("No AC power, disabling frequency switch\n"); |
| 226 | return; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Override what we have detected since we know if we have |
| 232 | * a Beaglebone Black it supports 1GHz. |
| 233 | */ |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 234 | if (board_is_bone_lt()) |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 235 | dpll_mpu_opp100.m = MPUPLL_M_1000; |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 236 | |
| 237 | /* |
| 238 | * Increase USB current limit to 1300mA or 1800mA and set |
| 239 | * the MPU voltage controller as needed. |
| 240 | */ |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 241 | if (dpll_mpu_opp100.m == MPUPLL_M_1000) { |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 242 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA; |
| 243 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV; |
| 244 | } else { |
| 245 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA; |
| 246 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV; |
| 247 | } |
| 248 | |
| 249 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 250 | TPS65217_POWER_PATH, |
| 251 | usb_cur_lim, |
| 252 | TPS65217_USB_INPUT_CUR_LIMIT_MASK)) |
| 253 | puts("tps65217_reg_write failure\n"); |
| 254 | |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 255 | /* Set DCDC3 (CORE) voltage to 1.125V */ |
| 256 | if (tps65217_voltage_update(TPS65217_DEFDCDC3, |
| 257 | TPS65217_DCDC_VOLT_SEL_1125MV)) { |
| 258 | puts("tps65217_voltage_update failure\n"); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | /* Set CORE Frequencies to OPP100 */ |
| 263 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 264 | |
| 265 | /* Set DCDC2 (MPU) voltage */ |
| 266 | if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) { |
| 267 | puts("tps65217_voltage_update failure\n"); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone. |
| 273 | * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black. |
| 274 | */ |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 275 | if (board_is_bone()) { |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 276 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 277 | TPS65217_DEFLS1, |
| 278 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 279 | TPS65217_LDO_MASK)) |
| 280 | puts("tps65217_reg_write failure\n"); |
| 281 | } else { |
| 282 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 283 | TPS65217_DEFLS1, |
| 284 | TPS65217_LDO_VOLTAGE_OUT_1_8, |
| 285 | TPS65217_LDO_MASK)) |
| 286 | puts("tps65217_reg_write failure\n"); |
| 287 | } |
| 288 | |
| 289 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 290 | TPS65217_DEFLS2, |
| 291 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 292 | TPS65217_LDO_MASK)) |
| 293 | puts("tps65217_reg_write failure\n"); |
| 294 | } else { |
| 295 | int sil_rev; |
| 296 | |
| 297 | /* |
| 298 | * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all |
| 299 | * MPU frequencies we support we use a CORE voltage of |
| 300 | * 1.1375V. For MPU voltage we need to switch based on |
| 301 | * the frequency we are running at. |
| 302 | */ |
| 303 | if (i2c_probe(TPS65910_CTRL_I2C_ADDR)) |
| 304 | return; |
| 305 | |
| 306 | /* |
| 307 | * Depending on MPU clock and PG we will need a different |
| 308 | * VDD to drive at that speed. |
| 309 | */ |
| 310 | sil_rev = readl(&cdev->deviceid) >> 28; |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 311 | mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, |
| 312 | dpll_mpu_opp100.m); |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 313 | |
| 314 | /* Tell the TPS65910 to use i2c */ |
| 315 | tps65910_set_i2c_control(); |
| 316 | |
| 317 | /* First update MPU voltage. */ |
| 318 | if (tps65910_voltage_update(MPU, mpu_vdd)) |
| 319 | return; |
| 320 | |
| 321 | /* Second, update the CORE voltage. */ |
| 322 | if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3)) |
| 323 | return; |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 324 | |
| 325 | /* Set CORE Frequencies to OPP100 */ |
| 326 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* Set MPU Frequency to what we detected now that voltages are set */ |
Steve Kipisz | 52f7d84 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 330 | do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); |
Tom Rini | 9721027 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 333 | const struct dpll_params *get_dpll_ddr_params(void) |
| 334 | { |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 335 | enable_i2c0_pin_mux(); |
Heiko Schocher | 6789e84 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 336 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 337 | if (read_eeprom() < 0) |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 338 | puts("Could not get board ID.\n"); |
| 339 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 340 | if (board_is_evm_sk()) |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 341 | return &dpll_ddr_evm_sk; |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 342 | else if (board_is_bone_lt()) |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 343 | return &dpll_ddr_bone_black; |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 344 | else if (board_is_evm_15_or_later()) |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 345 | return &dpll_ddr_evm_sk; |
| 346 | else |
| 347 | return &dpll_ddr; |
| 348 | } |
| 349 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 350 | void set_uart_mux_conf(void) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 351 | { |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 352 | #if CONFIG_CONS_INDEX == 1 |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 353 | enable_uart0_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 354 | #elif CONFIG_CONS_INDEX == 2 |
Andrew Bradford | 6422b70 | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 355 | enable_uart1_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 356 | #elif CONFIG_CONS_INDEX == 3 |
Andrew Bradford | 6422b70 | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 357 | enable_uart2_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 358 | #elif CONFIG_CONS_INDEX == 4 |
Andrew Bradford | 6422b70 | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 359 | enable_uart3_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 360 | #elif CONFIG_CONS_INDEX == 5 |
Andrew Bradford | 6422b70 | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 361 | enable_uart4_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 362 | #elif CONFIG_CONS_INDEX == 6 |
Andrew Bradford | 6422b70 | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 363 | enable_uart5_pin_mux(); |
Tom Rini | 1286b7f | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 364 | #endif |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 365 | } |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 366 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 367 | void set_mux_conf_regs(void) |
| 368 | { |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 369 | if (read_eeprom() < 0) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 370 | puts("Could not get board ID.\n"); |
| 371 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 372 | enable_board_pin_mux(); |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 373 | } |
| 374 | |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 375 | const struct ctrl_ioregs ioregs_evmsk = { |
| 376 | .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 377 | .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 378 | .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 379 | .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 380 | .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 381 | }; |
| 382 | |
| 383 | const struct ctrl_ioregs ioregs_bonelt = { |
| 384 | .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 385 | .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 386 | .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 387 | .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 388 | .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 389 | }; |
| 390 | |
| 391 | const struct ctrl_ioregs ioregs_evm15 = { |
| 392 | .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 393 | .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 394 | .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 395 | .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 396 | .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 397 | }; |
| 398 | |
| 399 | const struct ctrl_ioregs ioregs = { |
| 400 | .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 401 | .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 402 | .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 403 | .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 404 | .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 405 | }; |
| 406 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 407 | void sdram_init(void) |
| 408 | { |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 409 | if (read_eeprom() < 0) |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 410 | puts("Could not get board ID.\n"); |
| 411 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 412 | if (board_is_evm_sk()) { |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 413 | /* |
| 414 | * EVM SK 1.2A and later use gpio0_7 to enable DDR3. |
| 415 | * This is safe enough to do on older revs. |
| 416 | */ |
| 417 | gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en"); |
| 418 | gpio_direction_output(GPIO_DDR_VTT_EN, 1); |
| 419 | } |
| 420 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 421 | if (board_is_evm_sk()) |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 422 | config_ddr(303, &ioregs_evmsk, &ddr3_data, |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 423 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 424 | else if (board_is_bone_lt()) |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 425 | config_ddr(400, &ioregs_bonelt, |
Tom Rini | c7ba18a | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 426 | &ddr3_beagleblack_data, |
| 427 | &ddr3_beagleblack_cmd_ctrl_data, |
| 428 | &ddr3_beagleblack_emif_reg_data, 0); |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 429 | else if (board_is_evm_15_or_later()) |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 430 | config_ddr(303, &ioregs_evm15, &ddr3_evm_data, |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 431 | &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0); |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 432 | else |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 433 | config_ddr(266, &ioregs, &ddr2_data, |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 434 | &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0); |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 435 | } |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 436 | #endif |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 437 | |
| 438 | /* |
| 439 | * Basic board specific setup. Pinmux has been handled already. |
| 440 | */ |
| 441 | int board_init(void) |
| 442 | { |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 443 | #if defined(CONFIG_HW_WATCHDOG) |
| 444 | hw_watchdog_init(); |
| 445 | #endif |
| 446 | |
Tom Rini | 73feefd | 2013-08-09 11:22:13 -0400 | [diff] [blame] | 447 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
pekon gupta | 2c17e6d | 2013-11-18 19:03:02 +0530 | [diff] [blame] | 448 | #if defined(CONFIG_NOR) || defined(CONFIG_NAND) |
Ilya Yanok | 98b5c26 | 2012-11-06 13:06:31 +0000 | [diff] [blame] | 449 | gpmc_init(); |
Steve Kipisz | cd8845d | 2013-07-18 15:13:03 -0400 | [diff] [blame] | 450 | #endif |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
Tom Rini | 044fc14 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 454 | #ifdef CONFIG_BOARD_LATE_INIT |
| 455 | int board_late_init(void) |
| 456 | { |
| 457 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 458 | int rc; |
| 459 | char *name = NULL; |
Tom Rini | ace4275 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 460 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 461 | rc = read_eeprom(); |
| 462 | if (rc) |
Tom Rini | ace4275 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 463 | puts("Could not get board ID.\n"); |
Tom Rini | 044fc14 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 464 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 465 | if (board_is_bbg1()) |
| 466 | name = "BBG1"; |
| 467 | set_board_info_env(name); |
Tom Rini | 044fc14 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 468 | #endif |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | #endif |
| 473 | |
Mugunthan V N | bd83e3d | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 474 | #ifndef CONFIG_DM_ETH |
| 475 | |
Ilya Yanok | c0e6679 | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 476 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
| 477 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 478 | static void cpsw_control(int enabled) |
| 479 | { |
| 480 | /* VTP can be added here */ |
| 481 | |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 486 | { |
| 487 | .slave_reg_ofs = 0x208, |
| 488 | .sliver_reg_ofs = 0xd80, |
Mugunthan V N | 9c653aa | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 489 | .phy_addr = 0, |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 490 | }, |
| 491 | { |
| 492 | .slave_reg_ofs = 0x308, |
| 493 | .sliver_reg_ofs = 0xdc0, |
Mugunthan V N | 9c653aa | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 494 | .phy_addr = 1, |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 495 | }, |
| 496 | }; |
| 497 | |
| 498 | static struct cpsw_platform_data cpsw_data = { |
Matt Porter | 81df2ba | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 499 | .mdio_base = CPSW_MDIO_BASE, |
| 500 | .cpsw_base = CPSW_BASE, |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 501 | .mdio_div = 0xff, |
| 502 | .channels = 8, |
| 503 | .cpdma_reg_ofs = 0x800, |
| 504 | .slaves = 1, |
| 505 | .slave_data = cpsw_slaves, |
| 506 | .ale_reg_ofs = 0xd00, |
| 507 | .ale_entries = 1024, |
| 508 | .host_port_reg_ofs = 0x108, |
| 509 | .hw_stats_reg_ofs = 0x900, |
Mugunthan V N | 2bf36ac | 2013-07-08 16:04:37 +0530 | [diff] [blame] | 510 | .bd_ram_ofs = 0x2000, |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 511 | .mac_control = (1 << 5), |
| 512 | .control = cpsw_control, |
| 513 | .host_port_num = 0, |
| 514 | .version = CPSW_CTRL_VERSION_2, |
| 515 | }; |
Ilya Yanok | d2aa115 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 516 | #endif |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 517 | |
Tom Rini | 68996b8 | 2014-03-26 15:53:12 -0400 | [diff] [blame] | 518 | /* |
| 519 | * This function will: |
| 520 | * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr |
| 521 | * in the environment |
| 522 | * Perform fixups to the PHY present on certain boards. We only need this |
| 523 | * function in: |
| 524 | * - SPL with either CPSW or USB ethernet support |
| 525 | * - Full U-Boot, with either CPSW or USB ethernet |
| 526 | * Build in only these cases to avoid warnings about unused variables |
| 527 | * when we build an SPL that has neither option but full U-Boot will. |
| 528 | */ |
| 529 | #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) \ |
| 530 | && defined(CONFIG_SPL_BUILD)) || \ |
| 531 | ((defined(CONFIG_DRIVER_TI_CPSW) || \ |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 532 | defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \ |
Tom Rini | 68996b8 | 2014-03-26 15:53:12 -0400 | [diff] [blame] | 533 | !defined(CONFIG_SPL_BUILD)) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 534 | int board_eth_init(bd_t *bis) |
| 535 | { |
Ilya Yanok | d2aa115 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 536 | int rv, n = 0; |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 537 | uint8_t mac_addr[6]; |
| 538 | uint32_t mac_hi, mac_lo; |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 539 | __maybe_unused struct ti_am_eeprom *header; |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 540 | |
Ilya Yanok | c0e6679 | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 541 | /* try reading mac address from efuse */ |
| 542 | mac_lo = readl(&cdev->macid0l); |
| 543 | mac_hi = readl(&cdev->macid0h); |
| 544 | mac_addr[0] = mac_hi & 0xFF; |
| 545 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 546 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 547 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 548 | mac_addr[4] = mac_lo & 0xFF; |
| 549 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 550 | |
| 551 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
| 552 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
| 553 | if (!getenv("ethaddr")) { |
| 554 | printf("<ethaddr> not set. Validating first E-fuse MAC\n"); |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 555 | |
Joe Hershberger | 0adb5b7 | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 556 | if (is_valid_ethaddr(mac_addr)) |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 557 | eth_setenv_enetaddr("ethaddr", mac_addr); |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Joel A Fernandes | a662e0c | 2013-05-07 05:52:55 +0000 | [diff] [blame] | 560 | #ifdef CONFIG_DRIVER_TI_CPSW |
Mugunthan V N | a35ad51 | 2014-02-18 07:31:55 -0500 | [diff] [blame] | 561 | |
| 562 | mac_lo = readl(&cdev->macid1l); |
| 563 | mac_hi = readl(&cdev->macid1h); |
| 564 | mac_addr[0] = mac_hi & 0xFF; |
| 565 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 566 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 567 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 568 | mac_addr[4] = mac_lo & 0xFF; |
| 569 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 570 | |
| 571 | if (!getenv("eth1addr")) { |
Joe Hershberger | 0adb5b7 | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 572 | if (is_valid_ethaddr(mac_addr)) |
Mugunthan V N | a35ad51 | 2014-02-18 07:31:55 -0500 | [diff] [blame] | 573 | eth_setenv_enetaddr("eth1addr", mac_addr); |
| 574 | } |
| 575 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 576 | if (read_eeprom() < 0) |
Tom Rini | ace4275 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 577 | puts("Could not get board ID.\n"); |
| 578 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 579 | if (board_is_bone() || board_is_bone_lt() || |
| 580 | board_is_idk()) { |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 581 | writel(MII_MODE_ENABLE, &cdev->miisel); |
| 582 | cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if = |
| 583 | PHY_INTERFACE_MODE_MII; |
| 584 | } else { |
Heiko Schocher | dafd4db | 2013-08-19 16:38:56 +0200 | [diff] [blame] | 585 | writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel); |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 586 | cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if = |
| 587 | PHY_INTERFACE_MODE_RGMII; |
| 588 | } |
| 589 | |
Ilya Yanok | d2aa115 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 590 | rv = cpsw_register(&cpsw_data); |
| 591 | if (rv < 0) |
| 592 | printf("Error %d registering CPSW switch\n", rv); |
| 593 | else |
| 594 | n += rv; |
Joel A Fernandes | a662e0c | 2013-05-07 05:52:55 +0000 | [diff] [blame] | 595 | #endif |
Tom Rini | 1634e96 | 2013-02-12 14:59:23 -0500 | [diff] [blame] | 596 | |
| 597 | /* |
| 598 | * |
| 599 | * CPSW RGMII Internal Delay Mode is not supported in all PVT |
| 600 | * operating points. So we must set the TX clock delay feature |
| 601 | * in the AR8051 PHY. Since we only support a single ethernet |
| 602 | * device in U-Boot, we only do this for the first instance. |
| 603 | */ |
| 604 | #define AR8051_PHY_DEBUG_ADDR_REG 0x1d |
| 605 | #define AR8051_PHY_DEBUG_DATA_REG 0x1e |
| 606 | #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5 |
| 607 | #define AR8051_RGMII_TX_CLK_DLY 0x100 |
| 608 | |
Nishanth Menon | 770e68c | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 609 | if (board_is_evm_sk() || board_is_gp_evm()) { |
Tom Rini | 1634e96 | 2013-02-12 14:59:23 -0500 | [diff] [blame] | 610 | const char *devname; |
| 611 | devname = miiphy_get_current_dev(); |
| 612 | |
| 613 | miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG, |
| 614 | AR8051_DEBUG_RGMII_CLK_DLY_REG); |
| 615 | miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG, |
| 616 | AR8051_RGMII_TX_CLK_DLY); |
| 617 | } |
Ilya Yanok | d2aa115 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 618 | #endif |
Ilya Yanok | c0e6679 | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 619 | #if defined(CONFIG_USB_ETHER) && \ |
| 620 | (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT)) |
Joe Hershberger | 0adb5b7 | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 621 | if (is_valid_ethaddr(mac_addr)) |
Ilya Yanok | c0e6679 | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 622 | eth_setenv_enetaddr("usbnet_devaddr", mac_addr); |
| 623 | |
Ilya Yanok | d2aa115 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 624 | rv = usb_eth_initialize(bis); |
| 625 | if (rv < 0) |
| 626 | printf("Error %d registering USB_ETHER\n", rv); |
| 627 | else |
| 628 | n += rv; |
| 629 | #endif |
| 630 | return n; |
Peter Korsgaard | e363426 | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 631 | } |
| 632 | #endif |
Mugunthan V N | bd83e3d | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 633 | |
| 634 | #endif /* CONFIG_DM_ETH */ |