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> |
Fabio Estevam | 1340929 | 2014-01-29 17:39:49 -0200 | [diff] [blame] | 11 | #include <asm/armv7.h> |
Jeroen Hofstee | 1abf3a1 | 2014-10-08 22:57:52 +0200 | [diff] [blame] | 12 | #include <asm/bootm.h> |
Fabio Estevam | 1340929 | 2014-01-29 17:39:49 -0200 | [diff] [blame] | 13 | #include <asm/pl310.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 14 | #include <asm/errno.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/imx-regs.h> |
| 17 | #include <asm/arch/clock.h> |
| 18 | #include <asm/arch/sys_proto.h> |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 19 | #include <asm/imx-common/boot_mode.h> |
Stefan Roese | 8338d1d | 2013-04-15 21:14:12 +0000 | [diff] [blame] | 20 | #include <asm/imx-common/dma.h> |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 21 | #include <stdbool.h> |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 22 | #include <asm/arch/mxc_hdmi.h> |
| 23 | #include <asm/arch/crm_regs.h> |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 24 | #include <dm.h> |
| 25 | #include <imx_thermal.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 26 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 27 | enum ldo_reg { |
| 28 | LDO_ARM, |
| 29 | LDO_SOC, |
| 30 | LDO_PU, |
| 31 | }; |
| 32 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 33 | struct scu_regs { |
| 34 | u32 ctrl; |
| 35 | u32 config; |
| 36 | u32 status; |
| 37 | u32 invalidate; |
| 38 | u32 fpga_rev; |
| 39 | }; |
| 40 | |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 41 | #if defined(CONFIG_IMX6_THERMAL) |
| 42 | static const struct imx_thermal_plat imx6_thermal_plat = { |
| 43 | .regs = (void *)ANATOP_BASE_ADDR, |
| 44 | .fuse_bank = 1, |
| 45 | .fuse_word = 6, |
| 46 | }; |
| 47 | |
| 48 | U_BOOT_DEVICE(imx6_thermal) = { |
| 49 | .name = "imx_thermal", |
| 50 | .platdata = &imx6_thermal_plat, |
| 51 | }; |
| 52 | #endif |
| 53 | |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 54 | u32 get_nr_cpus(void) |
| 55 | { |
| 56 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
| 57 | return readl(&scu->config) & 3; |
| 58 | } |
| 59 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 60 | u32 get_cpu_rev(void) |
| 61 | { |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 62 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 63 | u32 reg = readl(&anatop->digprog_sololite); |
| 64 | u32 type = ((reg >> 16) & 0xff); |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 65 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 66 | if (type != MXC_CPU_MX6SL) { |
| 67 | reg = readl(&anatop->digprog); |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 68 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
| 69 | u32 cfg = readl(&scu->config) & 3; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 70 | type = ((reg >> 16) & 0xff); |
| 71 | if (type == MXC_CPU_MX6DL) { |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 72 | if (!cfg) |
| 73 | type = MXC_CPU_MX6SOLO; |
| 74 | } |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 75 | |
| 76 | if (type == MXC_CPU_MX6Q) { |
| 77 | if (cfg == 1) |
| 78 | type = MXC_CPU_MX6D; |
| 79 | } |
| 80 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 81 | } |
| 82 | reg &= 0xff; /* mx6 silicon revision */ |
| 83 | return (type << 12) | (reg + 0x10); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 86 | /* |
| 87 | * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440) |
| 88 | * defines a 2-bit SPEED_GRADING |
| 89 | */ |
| 90 | #define OCOTP_CFG3_SPEED_SHIFT 16 |
| 91 | #define OCOTP_CFG3_SPEED_800MHZ 0 |
| 92 | #define OCOTP_CFG3_SPEED_850MHZ 1 |
| 93 | #define OCOTP_CFG3_SPEED_1GHZ 2 |
| 94 | #define OCOTP_CFG3_SPEED_1P2GHZ 3 |
| 95 | |
| 96 | u32 get_cpu_speed_grade_hz(void) |
| 97 | { |
| 98 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 99 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 100 | struct fuse_bank0_regs *fuse = |
| 101 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 102 | uint32_t val; |
| 103 | |
| 104 | val = readl(&fuse->cfg3); |
| 105 | val >>= OCOTP_CFG3_SPEED_SHIFT; |
| 106 | val &= 0x3; |
| 107 | |
| 108 | switch (val) { |
| 109 | /* Valid for IMX6DQ */ |
| 110 | case OCOTP_CFG3_SPEED_1P2GHZ: |
| 111 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) |
| 112 | return 1200000000; |
| 113 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 114 | case OCOTP_CFG3_SPEED_1GHZ: |
| 115 | return 996000000; |
| 116 | /* Valid for IMX6DQ */ |
| 117 | case OCOTP_CFG3_SPEED_850MHZ: |
| 118 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) |
| 119 | return 852000000; |
| 120 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 121 | case OCOTP_CFG3_SPEED_800MHZ: |
| 122 | return 792000000; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
Tim Harvey | 5e0e193 | 2015-05-18 06:56:45 -0700 | [diff] [blame^] | 127 | /* |
| 128 | * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480) |
| 129 | * defines a 2-bit Temperature Grade |
| 130 | * |
| 131 | * return temperature grade and min/max temperature in celcius |
| 132 | */ |
| 133 | #define OCOTP_MEM0_TEMP_SHIFT 6 |
| 134 | |
| 135 | u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 136 | { |
| 137 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 138 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 139 | struct fuse_bank1_regs *fuse = |
| 140 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 141 | uint32_t val; |
| 142 | |
| 143 | val = readl(&fuse->mem0); |
| 144 | val >>= OCOTP_MEM0_TEMP_SHIFT; |
| 145 | val &= 0x3; |
| 146 | |
| 147 | if (minc && maxc) { |
| 148 | if (val == TEMP_AUTOMOTIVE) { |
| 149 | *minc = -40; |
| 150 | *maxc = 125; |
| 151 | } else if (val == TEMP_INDUSTRIAL) { |
| 152 | *minc = -40; |
| 153 | *maxc = 105; |
| 154 | } else if (val == TEMP_EXTCOMMERCIAL) { |
| 155 | *minc = -20; |
| 156 | *maxc = 105; |
| 157 | } else { |
| 158 | *minc = 0; |
| 159 | *maxc = 95; |
| 160 | } |
| 161 | } |
| 162 | return val; |
| 163 | } |
| 164 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 165 | #ifdef CONFIG_REVISION_TAG |
| 166 | u32 __weak get_board_rev(void) |
| 167 | { |
| 168 | u32 cpurev = get_cpu_rev(); |
| 169 | u32 type = ((cpurev >> 12) & 0xff); |
| 170 | if (type == MXC_CPU_MX6SOLO) |
| 171 | cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF); |
| 172 | |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 173 | if (type == MXC_CPU_MX6D) |
| 174 | cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF); |
| 175 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 176 | return cpurev; |
| 177 | } |
| 178 | #endif |
| 179 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 180 | void init_aips(void) |
| 181 | { |
Jason Liu | bb25e07 | 2012-01-10 00:52:59 +0000 | [diff] [blame] | 182 | struct aipstz_regs *aips1, *aips2; |
Fabio Estevam | 712ab88 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 183 | #ifdef CONFIG_MX6SX |
| 184 | struct aipstz_regs *aips3; |
| 185 | #endif |
Jason Liu | bb25e07 | 2012-01-10 00:52:59 +0000 | [diff] [blame] | 186 | |
| 187 | aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR; |
| 188 | aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR; |
Fabio Estevam | 712ab88 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 189 | #ifdef CONFIG_MX6SX |
Ye.Li | 00cce36 | 2015-01-14 17:18:12 +0800 | [diff] [blame] | 190 | aips3 = (struct aipstz_regs *)AIPS3_CONFIG_BASE_ADDR; |
Fabio Estevam | 712ab88 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 191 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Set all MPROTx to be non-bufferable, trusted for R/W, |
| 195 | * not forced to user-mode. |
| 196 | */ |
Jason Liu | bb25e07 | 2012-01-10 00:52:59 +0000 | [diff] [blame] | 197 | writel(0x77777777, &aips1->mprot0); |
| 198 | writel(0x77777777, &aips1->mprot1); |
| 199 | writel(0x77777777, &aips2->mprot0); |
| 200 | writel(0x77777777, &aips2->mprot1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 201 | |
Jason Liu | bb25e07 | 2012-01-10 00:52:59 +0000 | [diff] [blame] | 202 | /* |
| 203 | * Set all OPACRx to be non-bufferable, not require |
| 204 | * supervisor privilege level for access,allow for |
| 205 | * write access and untrusted master access. |
| 206 | */ |
| 207 | writel(0x00000000, &aips1->opacr0); |
| 208 | writel(0x00000000, &aips1->opacr1); |
| 209 | writel(0x00000000, &aips1->opacr2); |
| 210 | writel(0x00000000, &aips1->opacr3); |
| 211 | writel(0x00000000, &aips1->opacr4); |
| 212 | writel(0x00000000, &aips2->opacr0); |
| 213 | writel(0x00000000, &aips2->opacr1); |
| 214 | writel(0x00000000, &aips2->opacr2); |
| 215 | writel(0x00000000, &aips2->opacr3); |
| 216 | writel(0x00000000, &aips2->opacr4); |
Fabio Estevam | 712ab88 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 217 | |
| 218 | #ifdef CONFIG_MX6SX |
| 219 | /* |
| 220 | * Set all MPROTx to be non-bufferable, trusted for R/W, |
| 221 | * not forced to user-mode. |
| 222 | */ |
| 223 | writel(0x77777777, &aips3->mprot0); |
| 224 | writel(0x77777777, &aips3->mprot1); |
| 225 | |
| 226 | /* |
| 227 | * Set all OPACRx to be non-bufferable, not require |
| 228 | * supervisor privilege level for access,allow for |
| 229 | * write access and untrusted master access. |
| 230 | */ |
| 231 | writel(0x00000000, &aips3->opacr0); |
| 232 | writel(0x00000000, &aips3->opacr1); |
| 233 | writel(0x00000000, &aips3->opacr2); |
| 234 | writel(0x00000000, &aips3->opacr3); |
| 235 | writel(0x00000000, &aips3->opacr4); |
| 236 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 239 | static void clear_ldo_ramp(void) |
| 240 | { |
| 241 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 242 | int reg; |
| 243 | |
| 244 | /* ROM may modify LDO ramp up time according to fuse setting, so in |
| 245 | * order to be in the safe side we neeed to reset these settings to |
| 246 | * match the reset value: 0'b00 |
| 247 | */ |
| 248 | reg = readl(&anatop->ana_misc2); |
| 249 | reg &= ~(0x3f << 24); |
| 250 | writel(reg, &anatop->ana_misc2); |
| 251 | } |
| 252 | |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 253 | /* |
Fabio Estevam | 2e95fe1 | 2014-06-13 01:42:37 -0300 | [diff] [blame] | 254 | * Set the PMU_REG_CORE register |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 255 | * |
Fabio Estevam | 2e95fe1 | 2014-06-13 01:42:37 -0300 | [diff] [blame] | 256 | * Set LDO_SOC/PU/ARM regulators to the specified millivolt level. |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 257 | * Possible values are from 0.725V to 1.450V in steps of |
| 258 | * 0.025V (25mV). |
| 259 | */ |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 260 | static int set_ldo_voltage(enum ldo_reg ldo, u32 mv) |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 261 | { |
| 262 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 263 | u32 val, step, old, reg = readl(&anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 264 | u8 shift; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 265 | |
| 266 | if (mv < 725) |
| 267 | val = 0x00; /* Power gated off */ |
| 268 | else if (mv > 1450) |
| 269 | val = 0x1F; /* Power FET switched full on. No regulation */ |
| 270 | else |
| 271 | val = (mv - 700) / 25; |
| 272 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 273 | clear_ldo_ramp(); |
| 274 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 275 | switch (ldo) { |
| 276 | case LDO_SOC: |
| 277 | shift = 18; |
| 278 | break; |
| 279 | case LDO_PU: |
| 280 | shift = 9; |
| 281 | break; |
| 282 | case LDO_ARM: |
| 283 | shift = 0; |
| 284 | break; |
| 285 | default: |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 289 | old = (reg & (0x1F << shift)) >> shift; |
| 290 | step = abs(val - old); |
| 291 | if (step == 0) |
| 292 | return 0; |
| 293 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 294 | reg = (reg & ~(0x1F << shift)) | (val << shift); |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 295 | writel(reg, &anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 296 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 297 | /* |
| 298 | * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per |
| 299 | * step |
| 300 | */ |
| 301 | udelay(3 * step); |
| 302 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 303 | return 0; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 306 | static void imx_set_wdog_powerdown(bool enable) |
| 307 | { |
| 308 | struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 309 | struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR; |
| 310 | |
Peng Fan | cc844dc | 2015-01-15 14:22:33 +0800 | [diff] [blame] | 311 | #ifdef CONFIG_MX6SX |
| 312 | struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR; |
| 313 | writew(enable, &wdog3->wmcr); |
| 314 | #endif |
| 315 | |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 316 | /* Write to the PDE (Power Down Enable) bit */ |
| 317 | writew(enable, &wdog1->wmcr); |
| 318 | writew(enable, &wdog2->wmcr); |
| 319 | } |
| 320 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 321 | static void set_ahb_rate(u32 val) |
| 322 | { |
| 323 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 324 | u32 reg, div; |
| 325 | |
| 326 | div = get_periph_clk() / val - 1; |
| 327 | reg = readl(&mxc_ccm->cbcdr); |
| 328 | |
| 329 | writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) | |
| 330 | (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr); |
| 331 | } |
| 332 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 333 | static void clear_mmdc_ch_mask(void) |
| 334 | { |
| 335 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 336 | |
| 337 | /* Clear MMDC channel mask */ |
| 338 | writel(0, &mxc_ccm->ccdr); |
| 339 | } |
| 340 | |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 341 | static void init_bandgap(void) |
| 342 | { |
| 343 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 344 | /* |
| 345 | * Ensure the bandgap has stabilized. |
| 346 | */ |
| 347 | while (!(readl(&anatop->ana_misc0) & 0x80)) |
| 348 | ; |
| 349 | /* |
| 350 | * For best noise performance of the analog blocks using the |
| 351 | * outputs of the bandgap, the reftop_selfbiasoff bit should |
| 352 | * be set. |
| 353 | */ |
| 354 | writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set); |
| 355 | } |
| 356 | |
| 357 | |
Ye.Li | 622dfbd | 2014-10-30 18:20:58 +0800 | [diff] [blame] | 358 | #ifdef CONFIG_MX6SL |
| 359 | static void set_preclk_from_osc(void) |
| 360 | { |
| 361 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 362 | u32 reg; |
| 363 | |
| 364 | reg = readl(&mxc_ccm->cscmr1); |
| 365 | reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK; |
| 366 | writel(reg, &mxc_ccm->cscmr1); |
| 367 | } |
| 368 | #endif |
| 369 | |
Dirk Behme | 0adb215 | 2015-03-09 14:48:48 +0100 | [diff] [blame] | 370 | #define SRC_SCR_WARM_RESET_ENABLE 0 |
| 371 | |
| 372 | static void init_src(void) |
| 373 | { |
| 374 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 375 | u32 val; |
| 376 | |
| 377 | /* |
| 378 | * force warm reset sources to generate cold reset |
| 379 | * for a more reliable restart |
| 380 | */ |
| 381 | val = readl(&src_regs->scr); |
| 382 | val &= ~(1 << SRC_SCR_WARM_RESET_ENABLE); |
| 383 | writel(val, &src_regs->scr); |
| 384 | } |
| 385 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 386 | int arch_cpu_init(void) |
| 387 | { |
| 388 | init_aips(); |
| 389 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 390 | /* Need to clear MMDC_CHx_MASK to make warm reset work. */ |
| 391 | clear_mmdc_ch_mask(); |
| 392 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 393 | /* |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 394 | * Disable self-bias circuit in the analog bandap. |
| 395 | * The self-bias circuit is used by the bandgap during startup. |
| 396 | * This bit should be set after the bandgap has initialized. |
| 397 | */ |
| 398 | init_bandgap(); |
| 399 | |
| 400 | /* |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 401 | * When low freq boot is enabled, ROM will not set AHB |
| 402 | * freq, so we need to ensure AHB freq is 132MHz in such |
| 403 | * scenario. |
| 404 | */ |
| 405 | if (mxc_get_clock(MXC_ARM_CLK) == 396000000) |
| 406 | set_ahb_rate(132000000); |
| 407 | |
Ye.Li | 622dfbd | 2014-10-30 18:20:58 +0800 | [diff] [blame] | 408 | /* Set perclk to source from OSC 24MHz */ |
| 409 | #if defined(CONFIG_MX6SL) |
| 410 | set_preclk_from_osc(); |
| 411 | #endif |
| 412 | |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 413 | imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */ |
Stefan Roese | 8338d1d | 2013-04-15 21:14:12 +0000 | [diff] [blame] | 414 | |
| 415 | #ifdef CONFIG_APBH_DMA |
| 416 | /* Start APBH DMA */ |
| 417 | mxs_dma_init(); |
| 418 | #endif |
| 419 | |
Dirk Behme | 0adb215 | 2015-03-09 14:48:48 +0100 | [diff] [blame] | 420 | init_src(); |
| 421 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 422 | return 0; |
| 423 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 424 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 425 | int board_postclk_init(void) |
| 426 | { |
| 427 | set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */ |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Eric Nelson | c94ce4a | 2012-03-04 11:47:38 +0000 | [diff] [blame] | 432 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 433 | void enable_caches(void) |
| 434 | { |
Nitin Garg | b1ce701 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 435 | #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH) |
| 436 | enum dcache_option option = DCACHE_WRITETHROUGH; |
| 437 | #else |
| 438 | enum dcache_option option = DCACHE_WRITEBACK; |
| 439 | #endif |
| 440 | |
Frank Li | 40c4100 | 2013-11-14 00:58:46 +0800 | [diff] [blame] | 441 | /* Avoid random hang when download by usb */ |
| 442 | invalidate_dcache_all(); |
Nitin Garg | b1ce701 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 443 | |
Eric Nelson | c94ce4a | 2012-03-04 11:47:38 +0000 | [diff] [blame] | 444 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 445 | dcache_enable(); |
Nitin Garg | b1ce701 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 446 | |
| 447 | /* Enable caching on OCRAM and ROM */ |
| 448 | mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR, |
| 449 | ROMCP_ARB_END_ADDR, |
| 450 | option); |
| 451 | mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR, |
| 452 | IRAM_SIZE, |
| 453 | option); |
Eric Nelson | c94ce4a | 2012-03-04 11:47:38 +0000 | [diff] [blame] | 454 | } |
| 455 | #endif |
| 456 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 457 | #if defined(CONFIG_FEC_MXC) |
Fabio Estevam | 04fc128 | 2011-12-20 05:46:31 +0000 | [diff] [blame] | 458 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 459 | { |
Benoît Thébaudeau | fa7e395 | 2013-04-23 10:17:38 +0000 | [diff] [blame] | 460 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 461 | struct fuse_bank *bank = &ocotp->bank[4]; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 462 | struct fuse_bank4_regs *fuse = |
| 463 | (struct fuse_bank4_regs *)bank->fuse_regs; |
| 464 | |
Jason Liu | bf651aa | 2011-12-19 02:38:13 +0000 | [diff] [blame] | 465 | u32 value = readl(&fuse->mac_addr_high); |
| 466 | mac[0] = (value >> 8); |
| 467 | mac[1] = value ; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 468 | |
Jason Liu | bf651aa | 2011-12-19 02:38:13 +0000 | [diff] [blame] | 469 | value = readl(&fuse->mac_addr_low); |
| 470 | mac[2] = value >> 24 ; |
| 471 | mac[3] = value >> 16 ; |
| 472 | mac[4] = value >> 8 ; |
| 473 | mac[5] = value ; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 474 | |
| 475 | } |
| 476 | #endif |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 477 | |
| 478 | void boot_mode_apply(unsigned cfg_val) |
| 479 | { |
| 480 | unsigned reg; |
Eric Nelson | 7b8731a | 2012-09-18 15:26:32 +0000 | [diff] [blame] | 481 | struct src *psrc = (struct src *)SRC_BASE_ADDR; |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 482 | writel(cfg_val, &psrc->gpr9); |
| 483 | reg = readl(&psrc->gpr10); |
| 484 | if (cfg_val) |
| 485 | reg |= 1 << 28; |
| 486 | else |
| 487 | reg &= ~(1 << 28); |
| 488 | writel(reg, &psrc->gpr10); |
| 489 | } |
| 490 | /* |
| 491 | * cfg_val will be used for |
| 492 | * 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] | 493 | * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0] |
| 494 | * instead of SBMR1 to determine the boot device. |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 495 | */ |
| 496 | const struct boot_mode soc_boot_modes[] = { |
| 497 | {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, |
| 498 | /* reserved value should start rom usb */ |
| 499 | {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)}, |
| 500 | {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)}, |
Nikolay Dimitrov | 284d901 | 2014-08-10 20:03:07 +0300 | [diff] [blame] | 501 | {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)}, |
| 502 | {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)}, |
| 503 | {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)}, |
| 504 | {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)}, |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 505 | /* 4 bit bus width */ |
| 506 | {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)}, |
| 507 | {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 508 | {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 509 | {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)}, |
| 510 | {NULL, 0}, |
| 511 | }; |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 512 | |
| 513 | void s_init(void) |
| 514 | { |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 515 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 516 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 517 | u32 mask480; |
| 518 | u32 mask528; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 519 | u32 reg, periph1, periph2; |
Fabio Estevam | 6633e3f | 2014-07-09 16:13:29 -0300 | [diff] [blame] | 520 | |
| 521 | if (is_cpu_type(MXC_CPU_MX6SX)) |
| 522 | return; |
| 523 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 524 | /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs |
| 525 | * to make sure PFD is working right, otherwise, PFDs may |
| 526 | * not output clock after reset, MX6DL and MX6SL have added 396M pfd |
| 527 | * workaround in ROM code, as bus clock need it |
| 528 | */ |
| 529 | |
| 530 | mask480 = ANATOP_PFD_CLKGATE_MASK(0) | |
| 531 | ANATOP_PFD_CLKGATE_MASK(1) | |
| 532 | ANATOP_PFD_CLKGATE_MASK(2) | |
| 533 | ANATOP_PFD_CLKGATE_MASK(3); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 534 | mask528 = ANATOP_PFD_CLKGATE_MASK(1) | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 535 | ANATOP_PFD_CLKGATE_MASK(3); |
| 536 | |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 537 | reg = readl(&ccm->cbcmr); |
| 538 | periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) |
| 539 | >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET); |
| 540 | periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) |
| 541 | >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET); |
| 542 | |
| 543 | /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */ |
| 544 | if ((periph2 != 0x2) && (periph1 != 0x2)) |
| 545 | mask528 |= ANATOP_PFD_CLKGATE_MASK(0); |
| 546 | |
| 547 | if ((periph2 != 0x1) && (periph1 != 0x1) && |
| 548 | (periph2 != 0x3) && (periph1 != 0x3)) |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 549 | mask528 |= ANATOP_PFD_CLKGATE_MASK(2); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 550 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 551 | writel(mask480, &anatop->pfd_480_set); |
| 552 | writel(mask528, &anatop->pfd_528_set); |
| 553 | writel(mask480, &anatop->pfd_480_clr); |
| 554 | writel(mask528, &anatop->pfd_528_clr); |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 555 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 556 | |
| 557 | #ifdef CONFIG_IMX_HDMI |
| 558 | void imx_enable_hdmi_phy(void) |
| 559 | { |
| 560 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
| 561 | u8 reg; |
| 562 | reg = readb(&hdmi->phy_conf0); |
| 563 | reg |= HDMI_PHY_CONF0_PDZ_MASK; |
| 564 | writeb(reg, &hdmi->phy_conf0); |
| 565 | udelay(3000); |
| 566 | reg |= HDMI_PHY_CONF0_ENTMDS_MASK; |
| 567 | writeb(reg, &hdmi->phy_conf0); |
| 568 | udelay(3000); |
| 569 | reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK; |
| 570 | writeb(reg, &hdmi->phy_conf0); |
| 571 | writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz); |
| 572 | } |
| 573 | |
| 574 | void imx_setup_hdmi(void) |
| 575 | { |
| 576 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 577 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
| 578 | int reg; |
| 579 | |
| 580 | /* Turn on HDMI PHY clock */ |
| 581 | reg = readl(&mxc_ccm->CCGR2); |
| 582 | reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK| |
| 583 | MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK; |
| 584 | writel(reg, &mxc_ccm->CCGR2); |
| 585 | writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz); |
| 586 | reg = readl(&mxc_ccm->chsccdr); |
| 587 | reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK| |
| 588 | MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK| |
| 589 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK); |
| 590 | reg |= (CHSCCDR_PODF_DIVIDE_BY_3 |
| 591 | << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
| 592 | |(CHSCCDR_IPU_PRE_CLK_540M_PFD |
| 593 | << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET); |
| 594 | writel(reg, &mxc_ccm->chsccdr); |
| 595 | } |
| 596 | #endif |
Fabio Estevam | 1340929 | 2014-01-29 17:39:49 -0200 | [diff] [blame] | 597 | |
| 598 | #ifndef CONFIG_SYS_L2CACHE_OFF |
| 599 | #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002 |
| 600 | void v7_outer_cache_enable(void) |
| 601 | { |
| 602 | struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE; |
| 603 | unsigned int val; |
| 604 | |
Fabio Estevam | 761da0f | 2015-03-11 17:12:12 -0300 | [diff] [blame] | 605 | |
| 606 | /* |
| 607 | * Set bit 22 in the auxiliary control register. If this bit |
| 608 | * is cleared, PL310 treats Normal Shared Non-cacheable |
| 609 | * accesses as Cacheable no-allocate. |
| 610 | */ |
| 611 | setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE); |
| 612 | |
Fabio Estevam | 1340929 | 2014-01-29 17:39:49 -0200 | [diff] [blame] | 613 | #if defined CONFIG_MX6SL |
| 614 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 615 | val = readl(&iomux->gpr[11]); |
| 616 | if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) { |
| 617 | /* L2 cache configured as OCRAM, reset it */ |
| 618 | val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM; |
| 619 | writel(val, &iomux->gpr[11]); |
| 620 | } |
| 621 | #endif |
| 622 | |
Ye.Li | a3e539a | 2014-08-20 17:18:24 +0800 | [diff] [blame] | 623 | /* Must disable the L2 before changing the latency parameters */ |
| 624 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 625 | |
Fabio Estevam | 1340929 | 2014-01-29 17:39:49 -0200 | [diff] [blame] | 626 | writel(0x132, &pl310->pl310_tag_latency_ctrl); |
| 627 | writel(0x132, &pl310->pl310_data_latency_ctrl); |
| 628 | |
| 629 | val = readl(&pl310->pl310_prefetch_ctrl); |
| 630 | |
| 631 | /* Turn on the L2 I/D prefetch */ |
| 632 | val |= 0x30000000; |
| 633 | |
| 634 | /* |
| 635 | * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0 |
| 636 | * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2 |
| 637 | * But according to ARM PL310 errata: 752271 |
| 638 | * ID: 752271: Double linefill feature can cause data corruption |
| 639 | * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2 |
| 640 | * Workaround: The only workaround to this erratum is to disable the |
| 641 | * double linefill feature. This is the default behavior. |
| 642 | */ |
| 643 | |
| 644 | #ifndef CONFIG_MX6Q |
| 645 | val |= 0x40800000; |
| 646 | #endif |
| 647 | writel(val, &pl310->pl310_prefetch_ctrl); |
| 648 | |
| 649 | val = readl(&pl310->pl310_power_ctrl); |
| 650 | val |= L2X0_DYNAMIC_CLK_GATING_EN; |
| 651 | val |= L2X0_STNDBY_MODE_EN; |
| 652 | writel(val, &pl310->pl310_power_ctrl); |
| 653 | |
| 654 | setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 655 | } |
| 656 | |
| 657 | void v7_outer_cache_disable(void) |
| 658 | { |
| 659 | struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE; |
| 660 | |
| 661 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 662 | } |
| 663 | #endif /* !CONFIG_SYS_L2CACHE_OFF */ |