Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Functions for omap5 based boards. |
| 4 | * |
| 5 | * (C) Copyright 2011 |
| 6 | * Texas Instruments, <www.ti.com> |
| 7 | * |
| 8 | * Author : |
| 9 | * Aneesh V <aneesh@ti.com> |
| 10 | * Steve Sakoman <steve@sakoman.com> |
| 11 | * Sricharan <r.sricharan@ti.com> |
| 12 | * |
| 13 | * See file CREDITS for list of people who contributed to this |
| 14 | * project. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
| 18 | * published by the Free Software Foundation; either version 2 of |
| 19 | * the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 29 | * MA 02111-1307 USA |
| 30 | */ |
| 31 | #include <common.h> |
| 32 | #include <asm/armv7.h> |
| 33 | #include <asm/arch/cpu.h> |
| 34 | #include <asm/arch/sys_proto.h> |
| 35 | #include <asm/sizes.h> |
| 36 | #include <asm/utils.h> |
| 37 | #include <asm/arch/gpio.h> |
Lokesh Vutla | 0f42de6 | 2012-05-22 00:03:25 +0000 | [diff] [blame] | 38 | #include <asm/emif.h> |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
SRICHARAN R | d3901b1 | 2012-03-12 02:25:40 +0000 | [diff] [blame] | 42 | u32 *const omap_si_rev = (u32 *)OMAP5_SRAM_SCRATCH_OMAP5_REV; |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 43 | |
| 44 | static struct gpio_bank gpio_bank_54xx[6] = { |
| 45 | { (void *)OMAP54XX_GPIO1_BASE, METHOD_GPIO_24XX }, |
| 46 | { (void *)OMAP54XX_GPIO2_BASE, METHOD_GPIO_24XX }, |
| 47 | { (void *)OMAP54XX_GPIO3_BASE, METHOD_GPIO_24XX }, |
| 48 | { (void *)OMAP54XX_GPIO4_BASE, METHOD_GPIO_24XX }, |
| 49 | { (void *)OMAP54XX_GPIO5_BASE, METHOD_GPIO_24XX }, |
| 50 | { (void *)OMAP54XX_GPIO6_BASE, METHOD_GPIO_24XX }, |
| 51 | }; |
| 52 | |
| 53 | const struct gpio_bank *const omap_gpio_bank = gpio_bank_54xx; |
| 54 | |
| 55 | #ifdef CONFIG_SPL_BUILD |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 56 | /* LPDDR2 specific IO settings */ |
| 57 | static void io_settings_lpddr2(void) |
| 58 | { |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 59 | const struct ctrl_ioregs *ioregs; |
| 60 | |
| 61 | get_ioregs(&ioregs); |
| 62 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch1_0); |
| 63 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch1_1); |
| 64 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch2_0); |
| 65 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch2_1); |
| 66 | writel(ioregs->ctrl_lpddr2ch, (*ctrl)->control_lpddr2ch1_0); |
| 67 | writel(ioregs->ctrl_lpddr2ch, (*ctrl)->control_lpddr2ch1_1); |
| 68 | writel(ioregs->ctrl_ddrio_0, (*ctrl)->control_ddrio_0); |
| 69 | writel(ioregs->ctrl_ddrio_1, (*ctrl)->control_ddrio_1); |
| 70 | writel(ioregs->ctrl_ddrio_2, (*ctrl)->control_ddrio_2); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* DDR3 specific IO settings */ |
| 74 | static void io_settings_ddr3(void) |
| 75 | { |
| 76 | u32 io_settings = 0; |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 77 | const struct ctrl_ioregs *ioregs; |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 78 | |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 79 | get_ioregs(&ioregs); |
| 80 | writel(ioregs->ctrl_ddr3ch, (*ctrl)->control_ddr3ch1_0); |
| 81 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch1_0); |
| 82 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch1_1); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 83 | |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 84 | writel(ioregs->ctrl_ddr3ch, (*ctrl)->control_ddr3ch2_0); |
| 85 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch2_0); |
| 86 | writel(ioregs->ctrl_ddrch, (*ctrl)->control_ddrch2_1); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 87 | |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 88 | writel(ioregs->ctrl_ddrio_0, (*ctrl)->control_ddrio_0); |
| 89 | writel(ioregs->ctrl_ddrio_1, (*ctrl)->control_ddrio_1); |
| 90 | writel(ioregs->ctrl_ddrio_2, (*ctrl)->control_ddrio_2); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 91 | |
| 92 | /* omap5432 does not use lpddr2 */ |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 93 | writel(ioregs->ctrl_lpddr2ch, (*ctrl)->control_lpddr2ch1_0); |
| 94 | writel(ioregs->ctrl_lpddr2ch, (*ctrl)->control_lpddr2ch1_1); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 95 | |
Lokesh Vutla | d8ac050 | 2013-02-04 04:22:05 +0000 | [diff] [blame] | 96 | writel(ioregs->ctrl_emif_sdram_config_ext, |
| 97 | (*ctrl)->control_emif1_sdram_config_ext); |
| 98 | writel(ioregs->ctrl_emif_sdram_config_ext, |
| 99 | (*ctrl)->control_emif2_sdram_config_ext); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 100 | |
| 101 | /* Disable DLL select */ |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 102 | io_settings = (readl((*ctrl)->control_port_emif1_sdram_config) |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 103 | & 0xFFEFFFFF); |
| 104 | writel(io_settings, |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 105 | (*ctrl)->control_port_emif1_sdram_config); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 106 | |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 107 | io_settings = (readl((*ctrl)->control_port_emif2_sdram_config) |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 108 | & 0xFFEFFFFF); |
| 109 | writel(io_settings, |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 110 | (*ctrl)->control_port_emif2_sdram_config); |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 113 | /* |
| 114 | * Some tuning of IOs for optimal power and performance |
| 115 | */ |
| 116 | void do_io_settings(void) |
| 117 | { |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 118 | u32 io_settings = 0, mask = 0; |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 119 | |
| 120 | /* Impedance settings EMMC, C2C 1,2, hsi2 */ |
| 121 | mask = (ds_mask << 2) | (ds_mask << 8) | |
| 122 | (ds_mask << 16) | (ds_mask << 18); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 123 | io_settings = readl((*ctrl)->control_smart1io_padconf_0) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 124 | (~mask); |
| 125 | io_settings |= (ds_60_ohm << 8) | (ds_45_ohm << 16) | |
| 126 | (ds_45_ohm << 18) | (ds_60_ohm << 2); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 127 | writel(io_settings, (*ctrl)->control_smart1io_padconf_0); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 128 | |
| 129 | /* Impedance settings Mcspi2 */ |
| 130 | mask = (ds_mask << 30); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 131 | io_settings = readl((*ctrl)->control_smart1io_padconf_1) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 132 | (~mask); |
| 133 | io_settings |= (ds_60_ohm << 30); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 134 | writel(io_settings, (*ctrl)->control_smart1io_padconf_1); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 135 | |
| 136 | /* Impedance settings C2C 3,4 */ |
| 137 | mask = (ds_mask << 14) | (ds_mask << 16); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 138 | io_settings = readl((*ctrl)->control_smart1io_padconf_2) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 139 | (~mask); |
| 140 | io_settings |= (ds_45_ohm << 14) | (ds_45_ohm << 16); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 141 | writel(io_settings, (*ctrl)->control_smart1io_padconf_2); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 142 | |
| 143 | /* Slew rate settings EMMC, C2C 1,2 */ |
| 144 | mask = (sc_mask << 8) | (sc_mask << 16) | (sc_mask << 18); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 145 | io_settings = readl((*ctrl)->control_smart2io_padconf_0) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 146 | (~mask); |
| 147 | io_settings |= (sc_fast << 8) | (sc_na << 16) | (sc_na << 18); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 148 | writel(io_settings, (*ctrl)->control_smart2io_padconf_0); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 149 | |
| 150 | /* Slew rate settings hsi2, Mcspi2 */ |
| 151 | mask = (sc_mask << 24) | (sc_mask << 28); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 152 | io_settings = readl((*ctrl)->control_smart2io_padconf_1) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 153 | (~mask); |
| 154 | io_settings |= (sc_fast << 28) | (sc_fast << 24); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 155 | writel(io_settings, (*ctrl)->control_smart2io_padconf_1); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 156 | |
| 157 | /* Slew rate settings C2C 3,4 */ |
| 158 | mask = (sc_mask << 16) | (sc_mask << 18); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 159 | io_settings = readl((*ctrl)->control_smart2io_padconf_2) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 160 | (~mask); |
| 161 | io_settings |= (sc_na << 16) | (sc_na << 18); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 162 | writel(io_settings, (*ctrl)->control_smart2io_padconf_2); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 163 | |
| 164 | /* impedance and slew rate settings for usb */ |
| 165 | mask = (usb_i_mask << 29) | (usb_i_mask << 26) | (usb_i_mask << 23) | |
| 166 | (usb_i_mask << 20) | (usb_i_mask << 17) | (usb_i_mask << 14); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 167 | io_settings = readl((*ctrl)->control_smart3io_padconf_1) & |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 168 | (~mask); |
| 169 | io_settings |= (ds_60_ohm << 29) | (ds_60_ohm << 26) | |
| 170 | (ds_60_ohm << 23) | (sc_fast << 20) | |
| 171 | (sc_fast << 17) | (sc_fast << 14); |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 172 | writel(io_settings, (*ctrl)->control_smart3io_padconf_1); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 173 | |
Lokesh Vutla | fef54c3 | 2013-02-04 04:21:59 +0000 | [diff] [blame] | 174 | if (emif_sdram_type() == EMIF_SDRAM_TYPE_LPDDR2) |
Lokesh Vutla | ff7b2a9 | 2012-05-22 00:03:23 +0000 | [diff] [blame] | 175 | io_settings_lpddr2(); |
| 176 | else |
| 177 | io_settings_ddr3(); |
SRICHARAN R | 8ec587d | 2012-03-12 02:25:36 +0000 | [diff] [blame] | 178 | |
| 179 | /* Efuse settings */ |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 180 | writel(EFUSE_1, (*ctrl)->control_efuse_1); |
| 181 | writel(EFUSE_2, (*ctrl)->control_efuse_2); |
| 182 | writel(EFUSE_3, (*ctrl)->control_efuse_3); |
| 183 | writel(EFUSE_4, (*ctrl)->control_efuse_4); |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 184 | } |
| 185 | #endif |
| 186 | |
Lokesh Vutla | 0f42de6 | 2012-05-22 00:03:25 +0000 | [diff] [blame] | 187 | void config_data_eye_leveling_samples(u32 emif_base) |
| 188 | { |
Lokesh Vutla | 0f42de6 | 2012-05-22 00:03:25 +0000 | [diff] [blame] | 189 | /*EMIF_SDRAM_CONFIG_EXT-Read data eye leveling no of samples =4*/ |
| 190 | if (emif_base == EMIF1_BASE) |
| 191 | writel(SDRAM_CONFIG_EXT_RD_LVL_4_SAMPLES, |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 192 | (*ctrl)->control_emif1_sdram_config_ext); |
Lokesh Vutla | 0f42de6 | 2012-05-22 00:03:25 +0000 | [diff] [blame] | 193 | else if (emif_base == EMIF2_BASE) |
| 194 | writel(SDRAM_CONFIG_EXT_RD_LVL_4_SAMPLES, |
Lokesh Vutla | 834b6b0 | 2013-02-04 04:22:04 +0000 | [diff] [blame] | 195 | (*ctrl)->control_emif2_sdram_config_ext); |
Lokesh Vutla | 0f42de6 | 2012-05-22 00:03:25 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 198 | void init_omap_revision(void) |
| 199 | { |
| 200 | /* |
| 201 | * For some of the ES2/ES1 boards ID_CODE is not reliable: |
| 202 | * Also, ES1 and ES2 have different ARM revisions |
| 203 | * So use ARM revision for identification |
| 204 | */ |
| 205 | unsigned int rev = cortex_rev(); |
| 206 | |
SRICHARAN R | cf85056 | 2013-02-12 01:33:41 +0000 | [diff] [blame] | 207 | switch (readl(CONTROL_ID_CODE)) { |
| 208 | case OMAP5430_CONTROL_ID_CODE_ES1_0: |
| 209 | *omap_si_rev = OMAP5430_ES1_0; |
| 210 | if (rev == MIDR_CORTEX_A15_R2P2) |
| 211 | *omap_si_rev = OMAP5430_ES2_0; |
| 212 | break; |
| 213 | case OMAP5432_CONTROL_ID_CODE_ES1_0: |
| 214 | *omap_si_rev = OMAP5432_ES1_0; |
| 215 | if (rev == MIDR_CORTEX_A15_R2P2) |
| 216 | *omap_si_rev = OMAP5432_ES2_0; |
| 217 | break; |
| 218 | case OMAP5430_CONTROL_ID_CODE_ES2_0: |
| 219 | *omap_si_rev = OMAP5430_ES2_0; |
| 220 | break; |
| 221 | case OMAP5432_CONTROL_ID_CODE_ES2_0: |
| 222 | *omap_si_rev = OMAP5432_ES2_0; |
SRICHARAN R | 602476e | 2012-03-12 02:25:39 +0000 | [diff] [blame] | 223 | break; |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 224 | default: |
SRICHARAN R | d3901b1 | 2012-03-12 02:25:40 +0000 | [diff] [blame] | 225 | *omap_si_rev = OMAP5430_SILICON_ID_INVALID; |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 226 | } |
| 227 | } |
SRICHARAN R | a8f08fd | 2012-03-12 02:25:52 +0000 | [diff] [blame] | 228 | |
| 229 | void reset_cpu(ulong ignored) |
| 230 | { |
| 231 | u32 omap_rev = omap_revision(); |
| 232 | |
| 233 | /* |
| 234 | * WARM reset is not functional in case of OMAP5430 ES1.0 soc. |
| 235 | * So use cold reset in case instead. |
| 236 | */ |
| 237 | if (omap_rev == OMAP5430_ES1_0) |
| 238 | writel(PRM_RSTCTRL_RESET << 0x1, PRM_RSTCTRL); |
| 239 | else |
| 240 | writel(PRM_RSTCTRL_RESET, PRM_RSTCTRL); |
| 241 | } |