Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Sascha Hauer, Pengutronix |
| 4 | * |
| 5 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/errno.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/sys_proto.h> |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 16 | #include <asm/imx-common/boot_mode.h> |
Stefan Roese | 8338d1d | 2013-04-15 21:14:12 +0000 | [diff] [blame] | 17 | #include <asm/imx-common/dma.h> |
Adrian Alonso | 6ec8d84 | 2015-10-12 13:48:12 -0500 | [diff] [blame] | 18 | #include <asm/imx-common/hab.h> |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 19 | #include <stdbool.h> |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 20 | #include <asm/arch/mxc_hdmi.h> |
| 21 | #include <asm/arch/crm_regs.h> |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 22 | #include <dm.h> |
| 23 | #include <imx_thermal.h> |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 24 | #include <mmc.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 25 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 26 | enum ldo_reg { |
| 27 | LDO_ARM, |
| 28 | LDO_SOC, |
| 29 | LDO_PU, |
| 30 | }; |
| 31 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 32 | struct scu_regs { |
| 33 | u32 ctrl; |
| 34 | u32 config; |
| 35 | u32 status; |
| 36 | u32 invalidate; |
| 37 | u32 fpga_rev; |
| 38 | }; |
| 39 | |
Adrian Alonso | ce08c36 | 2015-09-02 13:54:13 -0500 | [diff] [blame] | 40 | #if defined(CONFIG_IMX_THERMAL) |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 41 | static const struct imx_thermal_plat imx6_thermal_plat = { |
| 42 | .regs = (void *)ANATOP_BASE_ADDR, |
| 43 | .fuse_bank = 1, |
| 44 | .fuse_word = 6, |
| 45 | }; |
| 46 | |
| 47 | U_BOOT_DEVICE(imx6_thermal) = { |
| 48 | .name = "imx_thermal", |
| 49 | .platdata = &imx6_thermal_plat, |
| 50 | }; |
| 51 | #endif |
| 52 | |
Adrian Alonso | 6ec8d84 | 2015-10-12 13:48:12 -0500 | [diff] [blame] | 53 | #if defined(CONFIG_SECURE_BOOT) |
| 54 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 55 | .bank = 0, |
| 56 | .word = 6, |
| 57 | }; |
| 58 | #endif |
| 59 | |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 60 | u32 get_nr_cpus(void) |
| 61 | { |
| 62 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
| 63 | return readl(&scu->config) & 3; |
| 64 | } |
| 65 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 66 | u32 get_cpu_rev(void) |
| 67 | { |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 68 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 69 | u32 reg = readl(&anatop->digprog_sololite); |
| 70 | u32 type = ((reg >> 16) & 0xff); |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 71 | u32 major, cfg = 0; |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 72 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 73 | if (type != MXC_CPU_MX6SL) { |
| 74 | reg = readl(&anatop->digprog); |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 75 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 76 | cfg = readl(&scu->config) & 3; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 77 | type = ((reg >> 16) & 0xff); |
| 78 | if (type == MXC_CPU_MX6DL) { |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 79 | if (!cfg) |
| 80 | type = MXC_CPU_MX6SOLO; |
| 81 | } |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 82 | |
| 83 | if (type == MXC_CPU_MX6Q) { |
| 84 | if (cfg == 1) |
| 85 | type = MXC_CPU_MX6D; |
| 86 | } |
| 87 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 88 | } |
Peng Fan | 8838323 | 2015-06-11 18:30:36 +0800 | [diff] [blame] | 89 | major = ((reg >> 8) & 0xff); |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 90 | if ((major >= 1) && |
| 91 | ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) { |
| 92 | major--; |
| 93 | type = MXC_CPU_MX6QP; |
| 94 | if (cfg == 1) |
| 95 | type = MXC_CPU_MX6DP; |
| 96 | } |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 97 | reg &= 0xff; /* mx6 silicon revision */ |
Peng Fan | 8838323 | 2015-06-11 18:30:36 +0800 | [diff] [blame] | 98 | return (type << 12) | (reg + (0x10 * (major + 1))); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 101 | /* |
| 102 | * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440) |
| 103 | * defines a 2-bit SPEED_GRADING |
| 104 | */ |
| 105 | #define OCOTP_CFG3_SPEED_SHIFT 16 |
| 106 | #define OCOTP_CFG3_SPEED_800MHZ 0 |
| 107 | #define OCOTP_CFG3_SPEED_850MHZ 1 |
| 108 | #define OCOTP_CFG3_SPEED_1GHZ 2 |
| 109 | #define OCOTP_CFG3_SPEED_1P2GHZ 3 |
| 110 | |
| 111 | u32 get_cpu_speed_grade_hz(void) |
| 112 | { |
| 113 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 114 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 115 | struct fuse_bank0_regs *fuse = |
| 116 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 117 | uint32_t val; |
| 118 | |
| 119 | val = readl(&fuse->cfg3); |
| 120 | val >>= OCOTP_CFG3_SPEED_SHIFT; |
| 121 | val &= 0x3; |
| 122 | |
| 123 | switch (val) { |
| 124 | /* Valid for IMX6DQ */ |
| 125 | case OCOTP_CFG3_SPEED_1P2GHZ: |
| 126 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) |
| 127 | return 1200000000; |
| 128 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 129 | case OCOTP_CFG3_SPEED_1GHZ: |
| 130 | return 996000000; |
| 131 | /* Valid for IMX6DQ */ |
| 132 | case OCOTP_CFG3_SPEED_850MHZ: |
| 133 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) |
| 134 | return 852000000; |
| 135 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 136 | case OCOTP_CFG3_SPEED_800MHZ: |
| 137 | return 792000000; |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
Tim Harvey | 5e0e193 | 2015-05-18 06:56:45 -0700 | [diff] [blame] | 142 | /* |
| 143 | * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480) |
| 144 | * defines a 2-bit Temperature Grade |
| 145 | * |
| 146 | * return temperature grade and min/max temperature in celcius |
| 147 | */ |
| 148 | #define OCOTP_MEM0_TEMP_SHIFT 6 |
| 149 | |
| 150 | u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 151 | { |
| 152 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 153 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 154 | struct fuse_bank1_regs *fuse = |
| 155 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 156 | uint32_t val; |
| 157 | |
| 158 | val = readl(&fuse->mem0); |
| 159 | val >>= OCOTP_MEM0_TEMP_SHIFT; |
| 160 | val &= 0x3; |
| 161 | |
| 162 | if (minc && maxc) { |
| 163 | if (val == TEMP_AUTOMOTIVE) { |
| 164 | *minc = -40; |
| 165 | *maxc = 125; |
| 166 | } else if (val == TEMP_INDUSTRIAL) { |
| 167 | *minc = -40; |
| 168 | *maxc = 105; |
| 169 | } else if (val == TEMP_EXTCOMMERCIAL) { |
| 170 | *minc = -20; |
| 171 | *maxc = 105; |
| 172 | } else { |
| 173 | *minc = 0; |
| 174 | *maxc = 95; |
| 175 | } |
| 176 | } |
| 177 | return val; |
| 178 | } |
| 179 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 180 | #ifdef CONFIG_REVISION_TAG |
| 181 | u32 __weak get_board_rev(void) |
| 182 | { |
| 183 | u32 cpurev = get_cpu_rev(); |
| 184 | u32 type = ((cpurev >> 12) & 0xff); |
| 185 | if (type == MXC_CPU_MX6SOLO) |
| 186 | cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF); |
| 187 | |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 188 | if (type == MXC_CPU_MX6D) |
| 189 | cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF); |
| 190 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 191 | return cpurev; |
| 192 | } |
| 193 | #endif |
| 194 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 195 | static void clear_ldo_ramp(void) |
| 196 | { |
| 197 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 198 | int reg; |
| 199 | |
| 200 | /* ROM may modify LDO ramp up time according to fuse setting, so in |
| 201 | * order to be in the safe side we neeed to reset these settings to |
| 202 | * match the reset value: 0'b00 |
| 203 | */ |
| 204 | reg = readl(&anatop->ana_misc2); |
| 205 | reg &= ~(0x3f << 24); |
| 206 | writel(reg, &anatop->ana_misc2); |
| 207 | } |
| 208 | |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 209 | /* |
Fabio Estevam | 2e95fe1 | 2014-06-13 01:42:37 -0300 | [diff] [blame] | 210 | * Set the PMU_REG_CORE register |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 211 | * |
Fabio Estevam | 2e95fe1 | 2014-06-13 01:42:37 -0300 | [diff] [blame] | 212 | * Set LDO_SOC/PU/ARM regulators to the specified millivolt level. |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 213 | * Possible values are from 0.725V to 1.450V in steps of |
| 214 | * 0.025V (25mV). |
| 215 | */ |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 216 | static int set_ldo_voltage(enum ldo_reg ldo, u32 mv) |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 217 | { |
| 218 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 219 | u32 val, step, old, reg = readl(&anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 220 | u8 shift; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 221 | |
| 222 | if (mv < 725) |
| 223 | val = 0x00; /* Power gated off */ |
| 224 | else if (mv > 1450) |
| 225 | val = 0x1F; /* Power FET switched full on. No regulation */ |
| 226 | else |
| 227 | val = (mv - 700) / 25; |
| 228 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 229 | clear_ldo_ramp(); |
| 230 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 231 | switch (ldo) { |
| 232 | case LDO_SOC: |
| 233 | shift = 18; |
| 234 | break; |
| 235 | case LDO_PU: |
| 236 | shift = 9; |
| 237 | break; |
| 238 | case LDO_ARM: |
| 239 | shift = 0; |
| 240 | break; |
| 241 | default: |
| 242 | return -EINVAL; |
| 243 | } |
| 244 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 245 | old = (reg & (0x1F << shift)) >> shift; |
| 246 | step = abs(val - old); |
| 247 | if (step == 0) |
| 248 | return 0; |
| 249 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 250 | reg = (reg & ~(0x1F << shift)) | (val << shift); |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 251 | writel(reg, &anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 252 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 253 | /* |
| 254 | * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per |
| 255 | * step |
| 256 | */ |
| 257 | udelay(3 * step); |
| 258 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 259 | return 0; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 262 | static void set_ahb_rate(u32 val) |
| 263 | { |
| 264 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 265 | u32 reg, div; |
| 266 | |
| 267 | div = get_periph_clk() / val - 1; |
| 268 | reg = readl(&mxc_ccm->cbcdr); |
| 269 | |
| 270 | writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) | |
| 271 | (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr); |
| 272 | } |
| 273 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 274 | static void clear_mmdc_ch_mask(void) |
| 275 | { |
| 276 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 277 | u32 reg; |
| 278 | reg = readl(&mxc_ccm->ccdr); |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 279 | |
| 280 | /* Clear MMDC channel mask */ |
Ye Li | 64cef44 | 2016-03-09 16:13:48 +0800 | [diff] [blame] | 281 | if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL) || is_cpu_type(MXC_CPU_MX6SL)) |
| 282 | reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK); |
| 283 | else |
| 284 | reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK); |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 285 | writel(reg, &mxc_ccm->ccdr); |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 286 | } |
| 287 | |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 288 | static void init_bandgap(void) |
| 289 | { |
| 290 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 291 | /* |
| 292 | * Ensure the bandgap has stabilized. |
| 293 | */ |
| 294 | while (!(readl(&anatop->ana_misc0) & 0x80)) |
| 295 | ; |
| 296 | /* |
| 297 | * For best noise performance of the analog blocks using the |
| 298 | * outputs of the bandgap, the reftop_selfbiasoff bit should |
| 299 | * be set. |
| 300 | */ |
| 301 | writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set); |
| 302 | } |
| 303 | |
| 304 | |
Ye.Li | 622dfbd | 2014-10-30 18:20:58 +0800 | [diff] [blame] | 305 | #ifdef CONFIG_MX6SL |
| 306 | static void set_preclk_from_osc(void) |
| 307 | { |
| 308 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 309 | u32 reg; |
| 310 | |
| 311 | reg = readl(&mxc_ccm->cscmr1); |
| 312 | reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK; |
| 313 | writel(reg, &mxc_ccm->cscmr1); |
| 314 | } |
| 315 | #endif |
| 316 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 317 | int arch_cpu_init(void) |
| 318 | { |
| 319 | init_aips(); |
| 320 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 321 | /* Need to clear MMDC_CHx_MASK to make warm reset work. */ |
| 322 | clear_mmdc_ch_mask(); |
| 323 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 324 | /* |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 325 | * Disable self-bias circuit in the analog bandap. |
| 326 | * The self-bias circuit is used by the bandgap during startup. |
| 327 | * This bit should be set after the bandgap has initialized. |
| 328 | */ |
| 329 | init_bandgap(); |
| 330 | |
Peng Fan | f60137e | 2016-03-09 16:44:36 +0800 | [diff] [blame] | 331 | if (!IS_ENABLED(CONFIG_MX6UL)) { |
| 332 | /* |
| 333 | * When low freq boot is enabled, ROM will not set AHB |
| 334 | * freq, so we need to ensure AHB freq is 132MHz in such |
| 335 | * scenario. |
| 336 | * |
| 337 | * To i.MX6UL, when power up, default ARM core and |
| 338 | * AHB rate is 396M and 132M. |
| 339 | */ |
| 340 | if (mxc_get_clock(MXC_ARM_CLK) == 396000000) |
| 341 | set_ahb_rate(132000000); |
| 342 | } |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 343 | |
Peng Fan | a2cba65 | 2016-03-09 16:44:37 +0800 | [diff] [blame] | 344 | if (IS_ENABLED(CONFIG_MX6UL) && is_soc_rev(CHIP_REV_1_0) == 0) { |
| 345 | /* |
| 346 | * According to the design team's requirement on i.MX6UL, |
| 347 | * the PMIC_STBY_REQ PAD should be configured as open |
| 348 | * drain 100K (0x0000b8a0). |
| 349 | * Only exists on TO1.0 |
| 350 | */ |
| 351 | writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c); |
| 352 | } |
| 353 | |
| 354 | /* Set perclk to source from OSC 24MHz */ |
Ye.Li | 622dfbd | 2014-10-30 18:20:58 +0800 | [diff] [blame] | 355 | #if defined(CONFIG_MX6SL) |
| 356 | set_preclk_from_osc(); |
| 357 | #endif |
| 358 | |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 359 | imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */ |
Stefan Roese | 8338d1d | 2013-04-15 21:14:12 +0000 | [diff] [blame] | 360 | |
| 361 | #ifdef CONFIG_APBH_DMA |
| 362 | /* Start APBH DMA */ |
| 363 | mxs_dma_init(); |
| 364 | #endif |
| 365 | |
Dirk Behme | 0adb215 | 2015-03-09 14:48:48 +0100 | [diff] [blame] | 366 | init_src(); |
| 367 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 368 | return 0; |
| 369 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 370 | |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 371 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 372 | __weak int board_mmc_get_env_dev(int devno) |
| 373 | { |
| 374 | return CONFIG_SYS_MMC_ENV_DEV; |
| 375 | } |
| 376 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 377 | static int mmc_get_boot_dev(void) |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 378 | { |
| 379 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 380 | u32 soc_sbmr = readl(&src_regs->sbmr1); |
| 381 | u32 bootsel; |
| 382 | int devno; |
| 383 | |
| 384 | /* |
| 385 | * Refer to |
| 386 | * "i.MX 6Dual/6Quad Applications Processor Reference Manual" |
| 387 | * Chapter "8.5.3.1 Expansion Device eFUSE Configuration" |
| 388 | * i.MX6SL/SX/UL has same layout. |
| 389 | */ |
| 390 | bootsel = (soc_sbmr & 0x000000FF) >> 6; |
| 391 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 392 | /* No boot from sd/mmc */ |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 393 | if (bootsel != 1) |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 394 | return -1; |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 395 | |
| 396 | /* BOOT_CFG2[3] and BOOT_CFG2[4] */ |
| 397 | devno = (soc_sbmr & 0x00001800) >> 11; |
| 398 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 399 | return devno; |
| 400 | } |
| 401 | |
| 402 | int mmc_get_env_dev(void) |
| 403 | { |
| 404 | int devno = mmc_get_boot_dev(); |
| 405 | |
| 406 | /* If not boot from sd/mmc, use default value */ |
| 407 | if (devno < 0) |
| 408 | return CONFIG_SYS_MMC_ENV_DEV; |
| 409 | |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 410 | return board_mmc_get_env_dev(devno); |
| 411 | } |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 412 | |
| 413 | #ifdef CONFIG_SYS_MMC_ENV_PART |
| 414 | __weak int board_mmc_get_env_part(int devno) |
| 415 | { |
| 416 | return CONFIG_SYS_MMC_ENV_PART; |
| 417 | } |
| 418 | |
| 419 | uint mmc_get_env_part(struct mmc *mmc) |
| 420 | { |
| 421 | int devno = mmc_get_boot_dev(); |
| 422 | |
| 423 | /* If not boot from sd/mmc, use default value */ |
| 424 | if (devno < 0) |
| 425 | return CONFIG_SYS_MMC_ENV_PART; |
| 426 | |
| 427 | return board_mmc_get_env_part(devno); |
| 428 | } |
| 429 | #endif |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 430 | #endif |
| 431 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 432 | int board_postclk_init(void) |
| 433 | { |
| 434 | set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */ |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 439 | #if defined(CONFIG_FEC_MXC) |
Fabio Estevam | 04fc128 | 2011-12-20 05:46:31 +0000 | [diff] [blame] | 440 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 441 | { |
Benoît Thébaudeau | fa7e395 | 2013-04-23 10:17:38 +0000 | [diff] [blame] | 442 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 443 | struct fuse_bank *bank = &ocotp->bank[4]; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 444 | struct fuse_bank4_regs *fuse = |
| 445 | (struct fuse_bank4_regs *)bank->fuse_regs; |
| 446 | |
Ye Li | d5d8bf7 | 2016-02-01 10:41:31 +0800 | [diff] [blame] | 447 | if ((is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL)) && |
| 448 | dev_id == 1) { |
| 449 | u32 value = readl(&fuse->mac_addr2); |
| 450 | mac[0] = value >> 24 ; |
| 451 | mac[1] = value >> 16 ; |
| 452 | mac[2] = value >> 8 ; |
| 453 | mac[3] = value ; |
| 454 | |
| 455 | value = readl(&fuse->mac_addr1); |
| 456 | mac[4] = value >> 24 ; |
| 457 | mac[5] = value >> 16 ; |
| 458 | |
| 459 | } else { |
| 460 | u32 value = readl(&fuse->mac_addr1); |
| 461 | mac[0] = (value >> 8); |
| 462 | mac[1] = value ; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 463 | |
Ye Li | d5d8bf7 | 2016-02-01 10:41:31 +0800 | [diff] [blame] | 464 | value = readl(&fuse->mac_addr0); |
| 465 | mac[2] = value >> 24 ; |
| 466 | mac[3] = value >> 16 ; |
| 467 | mac[4] = value >> 8 ; |
| 468 | mac[5] = value ; |
| 469 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 470 | |
| 471 | } |
| 472 | #endif |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 473 | |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 474 | /* |
| 475 | * cfg_val will be used for |
| 476 | * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0] |
Nikita Kiryanov | 9fba842 | 2014-10-29 19:28:33 +0200 | [diff] [blame] | 477 | * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0] |
| 478 | * instead of SBMR1 to determine the boot device. |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 479 | */ |
| 480 | const struct boot_mode soc_boot_modes[] = { |
| 481 | {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, |
| 482 | /* reserved value should start rom usb */ |
| 483 | {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)}, |
| 484 | {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)}, |
Nikolay Dimitrov | 284d901 | 2014-08-10 20:03:07 +0300 | [diff] [blame] | 485 | {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)}, |
| 486 | {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)}, |
| 487 | {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)}, |
| 488 | {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)}, |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 489 | /* 4 bit bus width */ |
| 490 | {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)}, |
| 491 | {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 492 | {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 493 | {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)}, |
| 494 | {NULL, 0}, |
| 495 | }; |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 496 | |
Peng Fan | 92683e6 | 2015-10-29 15:54:50 +0800 | [diff] [blame] | 497 | void reset_misc(void) |
| 498 | { |
| 499 | #ifdef CONFIG_VIDEO_MXS |
| 500 | lcdif_power_down(); |
| 501 | #endif |
| 502 | } |
| 503 | |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 504 | void s_init(void) |
| 505 | { |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 506 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 507 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 508 | u32 mask480; |
| 509 | u32 mask528; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 510 | u32 reg, periph1, periph2; |
Fabio Estevam | 6633e3f | 2014-07-09 16:13:29 -0300 | [diff] [blame] | 511 | |
Peng Fan | cf333da | 2015-07-20 19:28:29 +0800 | [diff] [blame] | 512 | if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL)) |
Fabio Estevam | 6633e3f | 2014-07-09 16:13:29 -0300 | [diff] [blame] | 513 | return; |
| 514 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 515 | /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs |
| 516 | * to make sure PFD is working right, otherwise, PFDs may |
| 517 | * not output clock after reset, MX6DL and MX6SL have added 396M pfd |
| 518 | * workaround in ROM code, as bus clock need it |
| 519 | */ |
| 520 | |
| 521 | mask480 = ANATOP_PFD_CLKGATE_MASK(0) | |
| 522 | ANATOP_PFD_CLKGATE_MASK(1) | |
| 523 | ANATOP_PFD_CLKGATE_MASK(2) | |
| 524 | ANATOP_PFD_CLKGATE_MASK(3); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 525 | mask528 = ANATOP_PFD_CLKGATE_MASK(1) | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 526 | ANATOP_PFD_CLKGATE_MASK(3); |
| 527 | |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 528 | reg = readl(&ccm->cbcmr); |
| 529 | periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) |
| 530 | >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET); |
| 531 | periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) |
| 532 | >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET); |
| 533 | |
| 534 | /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */ |
| 535 | if ((periph2 != 0x2) && (periph1 != 0x2)) |
| 536 | mask528 |= ANATOP_PFD_CLKGATE_MASK(0); |
| 537 | |
| 538 | if ((periph2 != 0x1) && (periph1 != 0x1) && |
| 539 | (periph2 != 0x3) && (periph1 != 0x3)) |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 540 | mask528 |= ANATOP_PFD_CLKGATE_MASK(2); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 541 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 542 | writel(mask480, &anatop->pfd_480_set); |
| 543 | writel(mask528, &anatop->pfd_528_set); |
| 544 | writel(mask480, &anatop->pfd_480_clr); |
| 545 | writel(mask528, &anatop->pfd_528_clr); |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 546 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 547 | |
| 548 | #ifdef CONFIG_IMX_HDMI |
| 549 | void imx_enable_hdmi_phy(void) |
| 550 | { |
| 551 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
| 552 | u8 reg; |
| 553 | reg = readb(&hdmi->phy_conf0); |
| 554 | reg |= HDMI_PHY_CONF0_PDZ_MASK; |
| 555 | writeb(reg, &hdmi->phy_conf0); |
| 556 | udelay(3000); |
| 557 | reg |= HDMI_PHY_CONF0_ENTMDS_MASK; |
| 558 | writeb(reg, &hdmi->phy_conf0); |
| 559 | udelay(3000); |
| 560 | reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK; |
| 561 | writeb(reg, &hdmi->phy_conf0); |
| 562 | writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz); |
| 563 | } |
| 564 | |
| 565 | void imx_setup_hdmi(void) |
| 566 | { |
| 567 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 568 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
Peng Fan | 95ae612 | 2016-03-09 16:07:23 +0800 | [diff] [blame] | 569 | int reg, count; |
| 570 | u8 val; |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 571 | |
| 572 | /* Turn on HDMI PHY clock */ |
| 573 | reg = readl(&mxc_ccm->CCGR2); |
| 574 | reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK| |
| 575 | MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK; |
| 576 | writel(reg, &mxc_ccm->CCGR2); |
| 577 | writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz); |
| 578 | reg = readl(&mxc_ccm->chsccdr); |
| 579 | reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK| |
| 580 | MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK| |
| 581 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK); |
| 582 | reg |= (CHSCCDR_PODF_DIVIDE_BY_3 |
| 583 | << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
| 584 | |(CHSCCDR_IPU_PRE_CLK_540M_PFD |
| 585 | << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET); |
| 586 | writel(reg, &mxc_ccm->chsccdr); |
Peng Fan | 95ae612 | 2016-03-09 16:07:23 +0800 | [diff] [blame] | 587 | |
| 588 | /* Clear the overflow condition */ |
| 589 | if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) { |
| 590 | /* TMDS software reset */ |
| 591 | writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz); |
| 592 | val = readb(&hdmi->fc_invidconf); |
| 593 | /* Need minimum 3 times to write to clear the register */ |
| 594 | for (count = 0 ; count < 5 ; count++) |
| 595 | writeb(val, &hdmi->fc_invidconf); |
| 596 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 597 | } |
| 598 | #endif |
Peng Fan | fb3a3b7 | 2016-01-28 16:55:05 +0800 | [diff] [blame] | 599 | |
| 600 | #ifdef CONFIG_IMX_BOOTAUX |
| 601 | int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data) |
| 602 | { |
| 603 | struct src *src_reg; |
| 604 | u32 stack, pc; |
| 605 | |
| 606 | if (!boot_private_data) |
| 607 | return -EINVAL; |
| 608 | |
| 609 | stack = *(u32 *)boot_private_data; |
| 610 | pc = *(u32 *)(boot_private_data + 4); |
| 611 | |
| 612 | /* Set the stack and pc to M4 bootROM */ |
| 613 | writel(stack, M4_BOOTROM_BASE_ADDR); |
| 614 | writel(pc, M4_BOOTROM_BASE_ADDR + 4); |
| 615 | |
| 616 | /* Enable M4 */ |
| 617 | src_reg = (struct src *)SRC_BASE_ADDR; |
| 618 | clrsetbits_le32(&src_reg->scr, SRC_SCR_M4C_NON_SCLR_RST_MASK, |
| 619 | SRC_SCR_M4_ENABLE_MASK); |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | int arch_auxiliary_core_check_up(u32 core_id) |
| 625 | { |
| 626 | struct src *src_reg = (struct src *)SRC_BASE_ADDR; |
| 627 | unsigned val; |
| 628 | |
| 629 | val = readl(&src_reg->scr); |
| 630 | |
| 631 | if (val & SRC_SCR_M4C_NON_SCLR_RST_MASK) |
| 632 | return 0; /* assert in reset */ |
| 633 | |
| 634 | return 1; |
| 635 | } |
| 636 | #endif |