Peter Korsgaard | 85ec2db | 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 | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <errno.h> |
| 13 | #include <spl.h> |
Lokesh Vutla | abb44e6 | 2016-05-16 11:47:29 +0530 | [diff] [blame] | 14 | #include <serial.h> |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/hardware.h> |
| 17 | #include <asm/arch/omap.h> |
| 18 | #include <asm/arch/ddr_defs.h> |
| 19 | #include <asm/arch/clock.h> |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 20 | #include <asm/arch/clk_synthesizer.h> |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 21 | #include <asm/arch/gpio.h> |
| 22 | #include <asm/arch/mmc_host_def.h> |
| 23 | #include <asm/arch/sys_proto.h> |
Steve Kipisz | be9b6f8 | 2013-07-18 15:13:03 -0400 | [diff] [blame] | 24 | #include <asm/arch/mem.h> |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | #include <asm/emif.h> |
| 27 | #include <asm/gpio.h> |
Andrew F. Davis | bd24915 | 2016-08-30 14:06:24 -0500 | [diff] [blame] | 28 | #include <asm/omap_sec_common.h> |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 29 | #include <i2c.h> |
| 30 | #include <miiphy.h> |
| 31 | #include <cpsw.h> |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 32 | #include <power/tps65217.h> |
| 33 | #include <power/tps65910.h> |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 34 | #include <environment.h> |
| 35 | #include <watchdog.h> |
Tom Rini | 810b581 | 2014-03-28 12:03:38 -0400 | [diff] [blame] | 36 | #include <environment.h> |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 37 | #include "../common/board_detect.h" |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 38 | #include "board.h" |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 42 | /* GPIO that controls power to DDR on EVM-SK */ |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 43 | #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio)) |
| 44 | #define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7) |
| 45 | #define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18) |
| 46 | #define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4) |
| 47 | #define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10) |
| 48 | #define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7) |
| 49 | #define GPIO_PHY_RESET GPIO_TO_PIN(2, 5) |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 50 | #define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11) |
| 51 | #define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 52 | |
Mugunthan V N | df7a99f | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 53 | #if defined(CONFIG_SPL_BUILD) || \ |
| 54 | (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH)) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 55 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
Mugunthan V N | df7a99f | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 56 | #endif |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 57 | |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 58 | #define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT) |
| 59 | #define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT) |
| 60 | |
| 61 | #define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1) |
| 62 | #define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1) |
| 63 | |
| 64 | #define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024) |
| 65 | #define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024) |
| 66 | |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 67 | /* |
| 68 | * Read header information from EEPROM into global structure. |
| 69 | */ |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 70 | static inline int __maybe_unused read_eeprom(void) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 71 | { |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 72 | return ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Lokesh Vutla | abb44e6 | 2016-05-16 11:47:29 +0530 | [diff] [blame] | 75 | #ifndef CONFIG_DM_SERIAL |
| 76 | struct serial_device *default_serial_console(void) |
| 77 | { |
| 78 | if (board_is_icev2()) |
| 79 | return &eserial4_device; |
| 80 | else |
| 81 | return &eserial1_device; |
| 82 | } |
| 83 | #endif |
| 84 | |
Tom Rini | 8de09df | 2014-04-09 08:25:57 -0400 | [diff] [blame] | 85 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 86 | static const struct ddr_data ddr2_data = { |
Tom Rini | 7f50a57 | 2014-07-07 21:40:16 -0400 | [diff] [blame] | 87 | .datardsratio0 = MT47H128M16RT25E_RD_DQS, |
| 88 | .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE, |
| 89 | .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static const struct cmd_control ddr2_cmd_ctrl_data = { |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 93 | .cmd0csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 94 | |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 95 | .cmd1csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 96 | |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 97 | .cmd2csratio = MT47H128M16RT25E_RATIO, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static const struct emif_regs ddr2_emif_reg_data = { |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 101 | .sdram_config = MT47H128M16RT25E_EMIF_SDCFG, |
| 102 | .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF, |
| 103 | .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1, |
| 104 | .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2, |
| 105 | .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3, |
| 106 | .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | static const struct ddr_data ddr3_data = { |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 110 | .datardsratio0 = MT41J128MJT125_RD_DQS, |
| 111 | .datawdsratio0 = MT41J128MJT125_WR_DQS, |
| 112 | .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE, |
| 113 | .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 116 | static const struct ddr_data ddr3_beagleblack_data = { |
| 117 | .datardsratio0 = MT41K256M16HA125E_RD_DQS, |
| 118 | .datawdsratio0 = MT41K256M16HA125E_WR_DQS, |
| 119 | .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE, |
| 120 | .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA, |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 123 | static const struct ddr_data ddr3_evm_data = { |
| 124 | .datardsratio0 = MT41J512M8RH125_RD_DQS, |
| 125 | .datawdsratio0 = MT41J512M8RH125_WR_DQS, |
| 126 | .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE, |
| 127 | .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA, |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 130 | static const struct ddr_data ddr3_icev2_data = { |
| 131 | .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz, |
| 132 | .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz, |
| 133 | .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz, |
| 134 | .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz, |
| 135 | }; |
| 136 | |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 137 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 138 | .cmd0csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 139 | .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 140 | |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 141 | .cmd1csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 142 | .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 143 | |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 144 | .cmd2csratio = MT41J128MJT125_RATIO, |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 145 | .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 148 | static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = { |
| 149 | .cmd0csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 150 | .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 151 | |
| 152 | .cmd1csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 153 | .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 154 | |
| 155 | .cmd2csratio = MT41K256M16HA125E_RATIO, |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 156 | .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 157 | }; |
| 158 | |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 159 | static const struct cmd_control ddr3_evm_cmd_ctrl_data = { |
| 160 | .cmd0csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 161 | .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 162 | |
| 163 | .cmd1csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 164 | .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 165 | |
| 166 | .cmd2csratio = MT41J512M8RH125_RATIO, |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 167 | .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT, |
| 168 | }; |
| 169 | |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 170 | static const struct cmd_control ddr3_icev2_cmd_ctrl_data = { |
| 171 | .cmd0csratio = MT41J128MJT125_RATIO_400MHz, |
| 172 | .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz, |
| 173 | |
| 174 | .cmd1csratio = MT41J128MJT125_RATIO_400MHz, |
| 175 | .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz, |
| 176 | |
| 177 | .cmd2csratio = MT41J128MJT125_RATIO_400MHz, |
| 178 | .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz, |
| 179 | }; |
| 180 | |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 181 | static struct emif_regs ddr3_emif_reg_data = { |
Peter Korsgaard | 3adb827 | 2012-10-18 01:21:13 +0000 | [diff] [blame] | 182 | .sdram_config = MT41J128MJT125_EMIF_SDCFG, |
| 183 | .ref_ctrl = MT41J128MJT125_EMIF_SDREF, |
| 184 | .sdram_tim1 = MT41J128MJT125_EMIF_TIM1, |
| 185 | .sdram_tim2 = MT41J128MJT125_EMIF_TIM2, |
| 186 | .sdram_tim3 = MT41J128MJT125_EMIF_TIM3, |
| 187 | .zq_config = MT41J128MJT125_ZQ_CFG, |
Vaibhav Hiremath | c30d57b | 2013-03-14 21:11:16 +0000 | [diff] [blame] | 188 | .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY | |
| 189 | PHY_EN_DYN_PWRDN, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 190 | }; |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 191 | |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 192 | static struct emif_regs ddr3_beagleblack_emif_reg_data = { |
| 193 | .sdram_config = MT41K256M16HA125E_EMIF_SDCFG, |
| 194 | .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF, |
| 195 | .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1, |
| 196 | .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2, |
| 197 | .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3, |
| 198 | .zq_config = MT41K256M16HA125E_ZQ_CFG, |
| 199 | .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY, |
| 200 | }; |
| 201 | |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 202 | static struct emif_regs ddr3_evm_emif_reg_data = { |
| 203 | .sdram_config = MT41J512M8RH125_EMIF_SDCFG, |
| 204 | .ref_ctrl = MT41J512M8RH125_EMIF_SDREF, |
| 205 | .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1, |
| 206 | .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2, |
| 207 | .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3, |
| 208 | .zq_config = MT41J512M8RH125_ZQ_CFG, |
Vaibhav Hiremath | c30d57b | 2013-03-14 21:11:16 +0000 | [diff] [blame] | 209 | .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY | |
| 210 | PHY_EN_DYN_PWRDN, |
Jeff Lance | 7c03a22 | 2013-01-14 05:32:20 +0000 | [diff] [blame] | 211 | }; |
Peter Korsgaard | eb204db | 2013-05-13 08:36:30 +0000 | [diff] [blame] | 212 | |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 213 | static struct emif_regs ddr3_icev2_emif_reg_data = { |
| 214 | .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz, |
| 215 | .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz, |
| 216 | .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz, |
| 217 | .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz, |
| 218 | .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz, |
| 219 | .zq_config = MT41J128MJT125_ZQ_CFG_400MHz, |
| 220 | .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz | |
| 221 | PHY_EN_DYN_PWRDN, |
| 222 | }; |
| 223 | |
Peter Korsgaard | eb204db | 2013-05-13 08:36:30 +0000 | [diff] [blame] | 224 | #ifdef CONFIG_SPL_OS_BOOT |
| 225 | int spl_start_uboot(void) |
| 226 | { |
| 227 | /* break into full u-boot on 'c' */ |
Tom Rini | 810b581 | 2014-03-28 12:03:38 -0400 | [diff] [blame] | 228 | if (serial_tstc() && serial_getc() == 'c') |
| 229 | return 1; |
| 230 | |
| 231 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 232 | env_init(); |
| 233 | env_relocate_spec(); |
| 234 | if (getenv_yesno("boot_os") != 1) |
| 235 | return 1; |
| 236 | #endif |
| 237 | |
| 238 | return 0; |
Peter Korsgaard | eb204db | 2013-05-13 08:36:30 +0000 | [diff] [blame] | 239 | } |
| 240 | #endif |
| 241 | |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 242 | #define OSC (V_OSCK/1000000) |
| 243 | const struct dpll_params dpll_ddr = { |
| 244 | 266, OSC-1, 1, -1, -1, -1, -1}; |
| 245 | const struct dpll_params dpll_ddr_evm_sk = { |
| 246 | 303, OSC-1, 1, -1, -1, -1, -1}; |
| 247 | const struct dpll_params dpll_ddr_bone_black = { |
| 248 | 400, OSC-1, 1, -1, -1, -1, -1}; |
| 249 | |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 250 | void am33xx_spl_board_init(void) |
| 251 | { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 252 | int mpu_vdd; |
| 253 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 254 | if (read_eeprom() < 0) |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 255 | puts("Could not get board ID.\n"); |
| 256 | |
| 257 | /* Get the frequency */ |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 258 | dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 259 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 260 | if (board_is_bone() || board_is_bone_lt()) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 261 | /* BeagleBone PMIC Code */ |
| 262 | int usb_cur_lim; |
| 263 | |
| 264 | /* |
| 265 | * Only perform PMIC configurations if board rev > A1 |
| 266 | * on Beaglebone White |
| 267 | */ |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 268 | if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4)) |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 269 | return; |
| 270 | |
| 271 | if (i2c_probe(TPS65217_CHIP_PM)) |
| 272 | return; |
| 273 | |
| 274 | /* |
| 275 | * On Beaglebone White we need to ensure we have AC power |
| 276 | * before increasing the frequency. |
| 277 | */ |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 278 | if (board_is_bone()) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 279 | uchar pmic_status_reg; |
| 280 | if (tps65217_reg_read(TPS65217_STATUS, |
| 281 | &pmic_status_reg)) |
| 282 | return; |
| 283 | if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) { |
| 284 | puts("No AC power, disabling frequency switch\n"); |
| 285 | return; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Override what we have detected since we know if we have |
| 291 | * a Beaglebone Black it supports 1GHz. |
| 292 | */ |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 293 | if (board_is_bone_lt()) |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 294 | dpll_mpu_opp100.m = MPUPLL_M_1000; |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Increase USB current limit to 1300mA or 1800mA and set |
| 298 | * the MPU voltage controller as needed. |
| 299 | */ |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 300 | if (dpll_mpu_opp100.m == MPUPLL_M_1000) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 301 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA; |
| 302 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV; |
| 303 | } else { |
| 304 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA; |
| 305 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV; |
| 306 | } |
| 307 | |
| 308 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 309 | TPS65217_POWER_PATH, |
| 310 | usb_cur_lim, |
| 311 | TPS65217_USB_INPUT_CUR_LIMIT_MASK)) |
| 312 | puts("tps65217_reg_write failure\n"); |
| 313 | |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 314 | /* Set DCDC3 (CORE) voltage to 1.125V */ |
| 315 | if (tps65217_voltage_update(TPS65217_DEFDCDC3, |
| 316 | TPS65217_DCDC_VOLT_SEL_1125MV)) { |
| 317 | puts("tps65217_voltage_update failure\n"); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | /* Set CORE Frequencies to OPP100 */ |
| 322 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 323 | |
| 324 | /* Set DCDC2 (MPU) voltage */ |
| 325 | if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) { |
| 326 | puts("tps65217_voltage_update failure\n"); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone. |
| 332 | * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black. |
| 333 | */ |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 334 | if (board_is_bone()) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 335 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 336 | TPS65217_DEFLS1, |
| 337 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 338 | TPS65217_LDO_MASK)) |
| 339 | puts("tps65217_reg_write failure\n"); |
| 340 | } else { |
| 341 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 342 | TPS65217_DEFLS1, |
| 343 | TPS65217_LDO_VOLTAGE_OUT_1_8, |
| 344 | TPS65217_LDO_MASK)) |
| 345 | puts("tps65217_reg_write failure\n"); |
| 346 | } |
| 347 | |
| 348 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 349 | TPS65217_DEFLS2, |
| 350 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 351 | TPS65217_LDO_MASK)) |
| 352 | puts("tps65217_reg_write failure\n"); |
| 353 | } else { |
| 354 | int sil_rev; |
| 355 | |
| 356 | /* |
| 357 | * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all |
| 358 | * MPU frequencies we support we use a CORE voltage of |
| 359 | * 1.1375V. For MPU voltage we need to switch based on |
| 360 | * the frequency we are running at. |
| 361 | */ |
| 362 | if (i2c_probe(TPS65910_CTRL_I2C_ADDR)) |
| 363 | return; |
| 364 | |
| 365 | /* |
| 366 | * Depending on MPU clock and PG we will need a different |
| 367 | * VDD to drive at that speed. |
| 368 | */ |
| 369 | sil_rev = readl(&cdev->deviceid) >> 28; |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 370 | mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, |
| 371 | dpll_mpu_opp100.m); |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 372 | |
| 373 | /* Tell the TPS65910 to use i2c */ |
| 374 | tps65910_set_i2c_control(); |
| 375 | |
| 376 | /* First update MPU voltage. */ |
| 377 | if (tps65910_voltage_update(MPU, mpu_vdd)) |
| 378 | return; |
| 379 | |
| 380 | /* Second, update the CORE voltage. */ |
| 381 | if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3)) |
| 382 | return; |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 383 | |
| 384 | /* Set CORE Frequencies to OPP100 */ |
| 385 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /* Set MPU Frequency to what we detected now that voltages are set */ |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 389 | do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 392 | const struct dpll_params *get_dpll_ddr_params(void) |
| 393 | { |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 394 | enable_i2c0_pin_mux(); |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 395 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 396 | if (read_eeprom() < 0) |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 397 | puts("Could not get board ID.\n"); |
| 398 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 399 | if (board_is_evm_sk()) |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 400 | return &dpll_ddr_evm_sk; |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 401 | else if (board_is_bone_lt() || board_is_icev2()) |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 402 | return &dpll_ddr_bone_black; |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 403 | else if (board_is_evm_15_or_later()) |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 404 | return &dpll_ddr_evm_sk; |
| 405 | else |
| 406 | return &dpll_ddr; |
| 407 | } |
| 408 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 409 | void set_uart_mux_conf(void) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 410 | { |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 411 | #if CONFIG_CONS_INDEX == 1 |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 412 | enable_uart0_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 413 | #elif CONFIG_CONS_INDEX == 2 |
Andrew Bradford | 65c51ff | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 414 | enable_uart1_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 415 | #elif CONFIG_CONS_INDEX == 3 |
Andrew Bradford | 65c51ff | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 416 | enable_uart2_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 417 | #elif CONFIG_CONS_INDEX == 4 |
Andrew Bradford | 65c51ff | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 418 | enable_uart3_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 419 | #elif CONFIG_CONS_INDEX == 5 |
Andrew Bradford | 65c51ff | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 420 | enable_uart4_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 421 | #elif CONFIG_CONS_INDEX == 6 |
Andrew Bradford | 65c51ff | 2012-10-25 08:21:30 -0400 | [diff] [blame] | 422 | enable_uart5_pin_mux(); |
Tom Rini | 986d755 | 2014-08-01 09:53:24 -0400 | [diff] [blame] | 423 | #endif |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 424 | } |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 425 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 426 | void set_mux_conf_regs(void) |
| 427 | { |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 428 | if (read_eeprom() < 0) |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 429 | puts("Could not get board ID.\n"); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 430 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 431 | enable_board_pin_mux(); |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 432 | } |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 433 | |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 434 | const struct ctrl_ioregs ioregs_evmsk = { |
| 435 | .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 436 | .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 437 | .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 438 | .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 439 | .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE, |
| 440 | }; |
| 441 | |
| 442 | const struct ctrl_ioregs ioregs_bonelt = { |
| 443 | .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 444 | .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 445 | .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 446 | .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 447 | .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 448 | }; |
| 449 | |
| 450 | const struct ctrl_ioregs ioregs_evm15 = { |
| 451 | .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 452 | .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 453 | .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 454 | .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 455 | .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE, |
| 456 | }; |
| 457 | |
| 458 | const struct ctrl_ioregs ioregs = { |
| 459 | .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 460 | .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 461 | .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 462 | .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 463 | .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE, |
| 464 | }; |
| 465 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 466 | void sdram_init(void) |
| 467 | { |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 468 | if (read_eeprom() < 0) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 469 | puts("Could not get board ID.\n"); |
| 470 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 471 | if (board_is_evm_sk()) { |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 472 | /* |
| 473 | * EVM SK 1.2A and later use gpio0_7 to enable DDR3. |
| 474 | * This is safe enough to do on older revs. |
| 475 | */ |
| 476 | gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en"); |
| 477 | gpio_direction_output(GPIO_DDR_VTT_EN, 1); |
| 478 | } |
| 479 | |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 480 | if (board_is_icev2()) { |
| 481 | gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en"); |
| 482 | gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1); |
| 483 | } |
| 484 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 485 | if (board_is_evm_sk()) |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 486 | config_ddr(303, &ioregs_evmsk, &ddr3_data, |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 487 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 488 | else if (board_is_bone_lt()) |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 489 | config_ddr(400, &ioregs_bonelt, |
Tom Rini | 385bc75 | 2013-03-21 04:30:02 +0000 | [diff] [blame] | 490 | &ddr3_beagleblack_data, |
| 491 | &ddr3_beagleblack_cmd_ctrl_data, |
| 492 | &ddr3_beagleblack_emif_reg_data, 0); |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 493 | else if (board_is_evm_15_or_later()) |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 494 | config_ddr(303, &ioregs_evm15, &ddr3_evm_data, |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 495 | &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0); |
Lokesh Vutla | 5837b90 | 2016-05-16 11:47:24 +0530 | [diff] [blame] | 496 | else if (board_is_icev2()) |
| 497 | config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data, |
| 498 | &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data, |
| 499 | 0); |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 500 | else |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 501 | config_ddr(266, &ioregs, &ddr2_data, |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 502 | &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 503 | } |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 504 | #endif |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 505 | |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 506 | #if !defined(CONFIG_SPL_BUILD) || \ |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 507 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 508 | static void request_and_set_gpio(int gpio, char *name, int val) |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 509 | { |
| 510 | int ret; |
| 511 | |
| 512 | ret = gpio_request(gpio, name); |
| 513 | if (ret < 0) { |
| 514 | printf("%s: Unable to request %s\n", __func__, name); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | ret = gpio_direction_output(gpio, 0); |
| 519 | if (ret < 0) { |
| 520 | printf("%s: Unable to set %s as output\n", __func__, name); |
| 521 | goto err_free_gpio; |
| 522 | } |
| 523 | |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 524 | gpio_set_value(gpio, val); |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 525 | |
| 526 | return; |
| 527 | |
| 528 | err_free_gpio: |
| 529 | gpio_free(gpio); |
| 530 | } |
| 531 | |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 532 | #define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1); |
| 533 | #define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0); |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 534 | |
| 535 | /** |
| 536 | * RMII mode on ICEv2 board needs 50MHz clock. Given the clock |
| 537 | * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle |
| 538 | * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to |
| 539 | * give 50MHz output for Eth0 and 1. |
| 540 | */ |
| 541 | static struct clk_synth cdce913_data = { |
| 542 | .id = 0x81, |
| 543 | .capacitor = 0x90, |
| 544 | .mux = 0x6d, |
| 545 | .pdiv2 = 0x2, |
| 546 | .pdiv3 = 0x2, |
| 547 | }; |
| 548 | #endif |
| 549 | |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 550 | /* |
| 551 | * Basic board specific setup. Pinmux has been handled already. |
| 552 | */ |
| 553 | int board_init(void) |
| 554 | { |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 555 | #if defined(CONFIG_HW_WATCHDOG) |
| 556 | hw_watchdog_init(); |
| 557 | #endif |
| 558 | |
Tom Rini | f3b6a1d | 2013-08-09 11:22:13 -0400 | [diff] [blame] | 559 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
pekon gupta | 53b4b32 | 2013-11-18 19:03:02 +0530 | [diff] [blame] | 560 | #if defined(CONFIG_NOR) || defined(CONFIG_NAND) |
Ilya Yanok | 3d9725e | 2012-11-06 13:06:31 +0000 | [diff] [blame] | 561 | gpmc_init(); |
Steve Kipisz | be9b6f8 | 2013-07-18 15:13:03 -0400 | [diff] [blame] | 562 | #endif |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 563 | |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 564 | #if !defined(CONFIG_SPL_BUILD) || \ |
| 565 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 566 | if (board_is_icev2()) { |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 567 | int rv; |
| 568 | u32 reg; |
| 569 | |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 570 | REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL); |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 571 | /* Make J19 status available on GPIO1_26 */ |
| 572 | REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL); |
| 573 | |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 574 | REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL); |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 575 | /* |
| 576 | * Both ports can be set as RMII-CPSW or MII-PRU-ETH using |
| 577 | * jumpers near the port. Read the jumper value and set |
| 578 | * the pinmux, external mux and PHY clock accordingly. |
| 579 | * As jumper line is overridden by PHY RX_DV pin immediately |
| 580 | * after bootstrap (power-up/reset), we need to sample |
| 581 | * it during PHY reset using GPIO rising edge detection. |
| 582 | */ |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 583 | REQUEST_AND_SET_GPIO(GPIO_PHY_RESET); |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 584 | /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */ |
| 585 | reg = readl(GPIO0_RISINGDETECT) | BIT(11); |
| 586 | writel(reg, GPIO0_RISINGDETECT); |
| 587 | reg = readl(GPIO1_RISINGDETECT) | BIT(26); |
| 588 | writel(reg, GPIO1_RISINGDETECT); |
| 589 | /* Reset PHYs to capture the Jumper setting */ |
| 590 | gpio_set_value(GPIO_PHY_RESET, 0); |
| 591 | udelay(2); /* PHY datasheet states 1uS min. */ |
| 592 | gpio_set_value(GPIO_PHY_RESET, 1); |
| 593 | |
| 594 | reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11); |
| 595 | if (reg) { |
| 596 | writel(reg, GPIO0_IRQSTATUS1); /* clear irq */ |
| 597 | /* RMII mode */ |
| 598 | printf("ETH0, CPSW\n"); |
| 599 | } else { |
| 600 | /* MII mode */ |
| 601 | printf("ETH0, PRU\n"); |
| 602 | cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */ |
| 603 | } |
| 604 | |
| 605 | reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26); |
| 606 | if (reg) { |
| 607 | writel(reg, GPIO1_IRQSTATUS1); /* clear irq */ |
| 608 | /* RMII mode */ |
| 609 | printf("ETH1, CPSW\n"); |
| 610 | gpio_set_value(GPIO_MUX_MII_CTRL, 1); |
| 611 | } else { |
| 612 | /* MII mode */ |
| 613 | printf("ETH1, PRU\n"); |
| 614 | cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */ |
| 615 | } |
| 616 | |
| 617 | /* disable rising edge IRQs */ |
| 618 | reg = readl(GPIO0_RISINGDETECT) & ~BIT(11); |
| 619 | writel(reg, GPIO0_RISINGDETECT); |
| 620 | reg = readl(GPIO1_RISINGDETECT) & ~BIT(26); |
| 621 | writel(reg, GPIO1_RISINGDETECT); |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 622 | |
| 623 | rv = setup_clock_synthesizer(&cdce913_data); |
| 624 | if (rv) { |
| 625 | printf("Clock synthesizer setup failed %d\n", rv); |
| 626 | return rv; |
| 627 | } |
Roger Quadros | bcb4ee8 | 2016-08-24 15:35:50 +0300 | [diff] [blame^] | 628 | |
| 629 | /* reset PHYs */ |
| 630 | gpio_set_value(GPIO_PHY_RESET, 0); |
| 631 | udelay(2); /* PHY datasheet states 1uS min. */ |
| 632 | gpio_set_value(GPIO_PHY_RESET, 1); |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 633 | } |
| 634 | #endif |
| 635 | |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Tom Rini | 4027185 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 639 | #ifdef CONFIG_BOARD_LATE_INIT |
| 640 | int board_late_init(void) |
| 641 | { |
| 642 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 643 | int rc; |
| 644 | char *name = NULL; |
Tom Rini | 4021fd9 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 645 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 646 | rc = read_eeprom(); |
| 647 | if (rc) |
Tom Rini | 4021fd9 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 648 | puts("Could not get board ID.\n"); |
Tom Rini | 4027185 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 649 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 650 | if (board_is_bbg1()) |
| 651 | name = "BBG1"; |
| 652 | set_board_info_env(name); |
Tom Rini | 4027185 | 2012-10-24 07:28:17 +0000 | [diff] [blame] | 653 | #endif |
| 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | #endif |
| 658 | |
Mugunthan V N | df7a99f | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 659 | #ifndef CONFIG_DM_ETH |
| 660 | |
Ilya Yanok | 0760a0d | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 661 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
| 662 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 663 | static void cpsw_control(int enabled) |
| 664 | { |
| 665 | /* VTP can be added here */ |
| 666 | |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 671 | { |
| 672 | .slave_reg_ofs = 0x208, |
| 673 | .sliver_reg_ofs = 0xd80, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 674 | .phy_addr = 0, |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 675 | }, |
| 676 | { |
| 677 | .slave_reg_ofs = 0x308, |
| 678 | .sliver_reg_ofs = 0xdc0, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 679 | .phy_addr = 1, |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 680 | }, |
| 681 | }; |
| 682 | |
| 683 | static struct cpsw_platform_data cpsw_data = { |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 684 | .mdio_base = CPSW_MDIO_BASE, |
| 685 | .cpsw_base = CPSW_BASE, |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 686 | .mdio_div = 0xff, |
| 687 | .channels = 8, |
| 688 | .cpdma_reg_ofs = 0x800, |
| 689 | .slaves = 1, |
| 690 | .slave_data = cpsw_slaves, |
| 691 | .ale_reg_ofs = 0xd00, |
| 692 | .ale_entries = 1024, |
| 693 | .host_port_reg_ofs = 0x108, |
| 694 | .hw_stats_reg_ofs = 0x900, |
Mugunthan V N | ff55987 | 2013-07-08 16:04:37 +0530 | [diff] [blame] | 695 | .bd_ram_ofs = 0x2000, |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 696 | .mac_control = (1 << 5), |
| 697 | .control = cpsw_control, |
| 698 | .host_port_num = 0, |
| 699 | .version = CPSW_CTRL_VERSION_2, |
| 700 | }; |
Ilya Yanok | 44a2c07 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 701 | #endif |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 702 | |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 703 | #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) &&\ |
| 704 | defined(CONFIG_SPL_BUILD)) || \ |
| 705 | ((defined(CONFIG_DRIVER_TI_CPSW) || \ |
| 706 | defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \ |
| 707 | !defined(CONFIG_SPL_BUILD)) |
| 708 | |
Tom Rini | 60fcaaa | 2014-03-26 15:53:12 -0400 | [diff] [blame] | 709 | /* |
| 710 | * This function will: |
| 711 | * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr |
| 712 | * in the environment |
| 713 | * Perform fixups to the PHY present on certain boards. We only need this |
| 714 | * function in: |
| 715 | * - SPL with either CPSW or USB ethernet support |
| 716 | * - Full U-Boot, with either CPSW or USB ethernet |
| 717 | * Build in only these cases to avoid warnings about unused variables |
| 718 | * when we build an SPL that has neither option but full U-Boot will. |
| 719 | */ |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 720 | int board_eth_init(bd_t *bis) |
| 721 | { |
Ilya Yanok | 44a2c07 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 722 | int rv, n = 0; |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 723 | uint8_t mac_addr[6]; |
| 724 | uint32_t mac_hi, mac_lo; |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 725 | __maybe_unused struct ti_am_eeprom *header; |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 726 | |
Ilya Yanok | 0760a0d | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 727 | /* try reading mac address from efuse */ |
| 728 | mac_lo = readl(&cdev->macid0l); |
| 729 | mac_hi = readl(&cdev->macid0h); |
| 730 | mac_addr[0] = mac_hi & 0xFF; |
| 731 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 732 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 733 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 734 | mac_addr[4] = mac_lo & 0xFF; |
| 735 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 736 | |
| 737 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
| 738 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
| 739 | if (!getenv("ethaddr")) { |
| 740 | printf("<ethaddr> not set. Validating first E-fuse MAC\n"); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 741 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 742 | if (is_valid_ethaddr(mac_addr)) |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 743 | eth_setenv_enetaddr("ethaddr", mac_addr); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Joel A Fernandes | f748854 | 2013-05-07 05:52:55 +0000 | [diff] [blame] | 746 | #ifdef CONFIG_DRIVER_TI_CPSW |
Mugunthan V N | 0c1d856 | 2014-02-18 07:31:55 -0500 | [diff] [blame] | 747 | |
| 748 | mac_lo = readl(&cdev->macid1l); |
| 749 | mac_hi = readl(&cdev->macid1h); |
| 750 | mac_addr[0] = mac_hi & 0xFF; |
| 751 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 752 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 753 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 754 | mac_addr[4] = mac_lo & 0xFF; |
| 755 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 756 | |
| 757 | if (!getenv("eth1addr")) { |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 758 | if (is_valid_ethaddr(mac_addr)) |
Mugunthan V N | 0c1d856 | 2014-02-18 07:31:55 -0500 | [diff] [blame] | 759 | eth_setenv_enetaddr("eth1addr", mac_addr); |
| 760 | } |
| 761 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 762 | if (read_eeprom() < 0) |
Tom Rini | 4021fd9 | 2013-07-18 15:13:01 -0400 | [diff] [blame] | 763 | puts("Could not get board ID.\n"); |
| 764 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 765 | if (board_is_bone() || board_is_bone_lt() || |
| 766 | board_is_idk()) { |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 767 | writel(MII_MODE_ENABLE, &cdev->miisel); |
| 768 | cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if = |
| 769 | PHY_INTERFACE_MODE_MII; |
Lokesh Vutla | 0d144f5 | 2016-05-16 11:47:26 +0530 | [diff] [blame] | 770 | } else if (board_is_icev2()) { |
| 771 | writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel); |
| 772 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII; |
| 773 | cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII; |
| 774 | cpsw_slaves[0].phy_addr = 1; |
| 775 | cpsw_slaves[1].phy_addr = 3; |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 776 | } else { |
Heiko Schocher | c4fea29 | 2013-08-19 16:38:56 +0200 | [diff] [blame] | 777 | writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel); |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 778 | cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if = |
| 779 | PHY_INTERFACE_MODE_RGMII; |
| 780 | } |
| 781 | |
Ilya Yanok | 44a2c07 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 782 | rv = cpsw_register(&cpsw_data); |
| 783 | if (rv < 0) |
| 784 | printf("Error %d registering CPSW switch\n", rv); |
| 785 | else |
| 786 | n += rv; |
Joel A Fernandes | f748854 | 2013-05-07 05:52:55 +0000 | [diff] [blame] | 787 | #endif |
Tom Rini | 183943d | 2013-02-12 14:59:23 -0500 | [diff] [blame] | 788 | |
| 789 | /* |
| 790 | * |
| 791 | * CPSW RGMII Internal Delay Mode is not supported in all PVT |
| 792 | * operating points. So we must set the TX clock delay feature |
| 793 | * in the AR8051 PHY. Since we only support a single ethernet |
| 794 | * device in U-Boot, we only do this for the first instance. |
| 795 | */ |
| 796 | #define AR8051_PHY_DEBUG_ADDR_REG 0x1d |
| 797 | #define AR8051_PHY_DEBUG_DATA_REG 0x1e |
| 798 | #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5 |
| 799 | #define AR8051_RGMII_TX_CLK_DLY 0x100 |
| 800 | |
Nishanth Menon | 2afa70d | 2016-02-24 12:30:55 -0600 | [diff] [blame] | 801 | if (board_is_evm_sk() || board_is_gp_evm()) { |
Tom Rini | 183943d | 2013-02-12 14:59:23 -0500 | [diff] [blame] | 802 | const char *devname; |
| 803 | devname = miiphy_get_current_dev(); |
| 804 | |
| 805 | miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG, |
| 806 | AR8051_DEBUG_RGMII_CLK_DLY_REG); |
| 807 | miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG, |
| 808 | AR8051_RGMII_TX_CLK_DLY); |
| 809 | } |
Ilya Yanok | 44a2c07 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 810 | #endif |
Ilya Yanok | 0760a0d | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 811 | #if defined(CONFIG_USB_ETHER) && \ |
| 812 | (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT)) |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 813 | if (is_valid_ethaddr(mac_addr)) |
Ilya Yanok | 0760a0d | 2013-02-05 11:36:26 +0000 | [diff] [blame] | 814 | eth_setenv_enetaddr("usbnet_devaddr", mac_addr); |
| 815 | |
Ilya Yanok | 44a2c07 | 2012-11-06 13:48:24 +0000 | [diff] [blame] | 816 | rv = usb_eth_initialize(bis); |
| 817 | if (rv < 0) |
| 818 | printf("Error %d registering USB_ETHER\n", rv); |
| 819 | else |
| 820 | n += rv; |
| 821 | #endif |
| 822 | return n; |
Peter Korsgaard | 85ec2db | 2012-10-18 01:21:09 +0000 | [diff] [blame] | 823 | } |
| 824 | #endif |
Mugunthan V N | df7a99f | 2015-09-07 14:22:18 +0530 | [diff] [blame] | 825 | |
| 826 | #endif /* CONFIG_DM_ETH */ |
Lokesh Vutla | 89b9f30 | 2016-05-16 11:24:24 +0530 | [diff] [blame] | 827 | |
| 828 | #ifdef CONFIG_SPL_LOAD_FIT |
| 829 | int board_fit_config_name_match(const char *name) |
| 830 | { |
| 831 | if (board_is_gp_evm() && !strcmp(name, "am335x-evm")) |
| 832 | return 0; |
| 833 | else if (board_is_bone() && !strcmp(name, "am335x-bone")) |
| 834 | return 0; |
| 835 | else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack")) |
| 836 | return 0; |
Lokesh Vutla | 5a954ba | 2016-05-16 11:24:28 +0530 | [diff] [blame] | 837 | else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk")) |
| 838 | return 0; |
Lokesh Vutla | 1edfcaf | 2016-05-16 11:24:29 +0530 | [diff] [blame] | 839 | else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen")) |
| 840 | return 0; |
Lokesh Vutla | 7ecf196 | 2016-05-16 11:47:28 +0530 | [diff] [blame] | 841 | else if (board_is_icev2() && !strcmp(name, "am335x-icev2")) |
| 842 | return 0; |
Lokesh Vutla | 89b9f30 | 2016-05-16 11:24:24 +0530 | [diff] [blame] | 843 | else |
| 844 | return -1; |
| 845 | } |
| 846 | #endif |
Andrew F. Davis | bd24915 | 2016-08-30 14:06:24 -0500 | [diff] [blame] | 847 | |
| 848 | #ifdef CONFIG_TI_SECURE_DEVICE |
| 849 | void board_fit_image_post_process(void **p_image, size_t *p_size) |
| 850 | { |
| 851 | secure_boot_verify_image(p_image, p_size); |
| 852 | } |
| 853 | #endif |