Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * Sascha Hauer, Pengutronix |
| 5 | * |
| 6 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
Gaurav Jain | 607571a | 2022-03-24 11:50:29 +0530 | [diff] [blame] | 7 | * Copyright 2021 NXP |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Sean Anderson | bee0b6b | 2021-02-04 16:44:22 -0500 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/imx-regs.h> |
| 16 | #include <asm/arch/clock.h> |
| 17 | #include <asm/arch/sys_proto.h> |
Diego Dorta | 3a5bf53 | 2017-09-27 13:12:37 -0300 | [diff] [blame] | 18 | #include <asm/bootm.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 19 | #include <asm/mach-imx/boot_mode.h> |
| 20 | #include <asm/mach-imx/dma.h> |
| 21 | #include <asm/mach-imx/hab.h> |
Fabio Estevam | 48e65b0 | 2013-02-07 06:45:23 +0000 | [diff] [blame] | 22 | #include <stdbool.h> |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 23 | #include <asm/arch/mxc_hdmi.h> |
| 24 | #include <asm/arch/crm_regs.h> |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 25 | #include <dm.h> |
| 26 | #include <imx_thermal.h> |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 27 | #include <mmc.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 28 | |
Jorge Ramirez-Ortiz | 76d9539 | 2020-10-23 21:18:41 +0200 | [diff] [blame] | 29 | #define has_err007805() \ |
| 30 | (is_mx6sl() || is_mx6dl() || is_mx6solo() || is_mx6ull()) |
| 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 | |
Simon Glass | 85ed77d | 2024-09-29 19:49:46 -0600 | [diff] [blame] | 40 | #if !defined(CONFIG_XPL_BUILD) && 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 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 47 | U_BOOT_DRVINFO(imx6_thermal) = { |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 48 | .name = "imx_thermal", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 49 | .plat = &imx6_thermal_plat, |
Ye.Li | f19692c | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 50 | }; |
| 51 | #endif |
| 52 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 53 | #if defined(CONFIG_IMX_HAB) |
Paul Geurts | df0f95a | 2024-11-01 09:49:20 +0100 | [diff] [blame] | 54 | struct imx_fuse const imx_sec_config_fuse = { |
Adrian Alonso | 6ec8d84 | 2015-10-12 13:48:12 -0500 | [diff] [blame] | 55 | .bank = 0, |
| 56 | .word = 6, |
| 57 | }; |
Paul Geurts | fea4004 | 2024-11-01 09:49:21 +0100 | [diff] [blame] | 58 | |
| 59 | struct imx_fuse const imx_field_return_fuse = { |
| 60 | .bank = 5, |
| 61 | .word = 6, |
| 62 | }; |
Adrian Alonso | 6ec8d84 | 2015-10-12 13:48:12 -0500 | [diff] [blame] | 63 | #endif |
| 64 | |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 65 | u32 get_nr_cpus(void) |
| 66 | { |
| 67 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
| 68 | return readl(&scu->config) & 3; |
| 69 | } |
| 70 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 71 | u32 get_cpu_rev(void) |
| 72 | { |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 73 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 74 | u32 reg = readl(&anatop->digprog_sololite); |
| 75 | u32 type = ((reg >> 16) & 0xff); |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 76 | u32 major, cfg = 0; |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 77 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 78 | if (type != MXC_CPU_MX6SL) { |
| 79 | reg = readl(&anatop->digprog); |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 80 | struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR; |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 81 | cfg = readl(&scu->config) & 3; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 82 | type = ((reg >> 16) & 0xff); |
| 83 | if (type == MXC_CPU_MX6DL) { |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 84 | if (!cfg) |
| 85 | type = MXC_CPU_MX6SOLO; |
| 86 | } |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 87 | |
| 88 | if (type == MXC_CPU_MX6Q) { |
| 89 | if (cfg == 1) |
| 90 | type = MXC_CPU_MX6D; |
| 91 | } |
| 92 | |
Peng Fan | c53d0c9 | 2019-08-08 09:55:52 +0000 | [diff] [blame] | 93 | if (type == MXC_CPU_MX6ULL) { |
| 94 | if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6)) |
| 95 | type = MXC_CPU_MX6ULZ; |
| 96 | } |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 97 | } |
Peng Fan | 8838323 | 2015-06-11 18:30:36 +0800 | [diff] [blame] | 98 | major = ((reg >> 8) & 0xff); |
Peng Fan | 5f24792 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 99 | if ((major >= 1) && |
| 100 | ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) { |
| 101 | major--; |
| 102 | type = MXC_CPU_MX6QP; |
| 103 | if (cfg == 1) |
| 104 | type = MXC_CPU_MX6DP; |
| 105 | } |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 106 | reg &= 0xff; /* mx6 silicon revision */ |
Ye Li | 10f19c7 | 2019-07-10 10:38:37 +0000 | [diff] [blame] | 107 | |
| 108 | /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/ |
| 109 | if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5)) |
| 110 | reg = 0x3; |
| 111 | |
Peng Fan | 8838323 | 2015-06-11 18:30:36 +0800 | [diff] [blame] | 112 | return (type << 12) | (reg + (0x10 * (major + 1))); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 115 | /* |
| 116 | * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440) |
| 117 | * defines a 2-bit SPEED_GRADING |
| 118 | */ |
| 119 | #define OCOTP_CFG3_SPEED_SHIFT 16 |
| 120 | #define OCOTP_CFG3_SPEED_800MHZ 0 |
| 121 | #define OCOTP_CFG3_SPEED_850MHZ 1 |
| 122 | #define OCOTP_CFG3_SPEED_1GHZ 2 |
| 123 | #define OCOTP_CFG3_SPEED_1P2GHZ 3 |
| 124 | |
Peng Fan | 441e905 | 2016-05-03 11:13:04 +0800 | [diff] [blame] | 125 | /* |
| 126 | * For i.MX6UL |
| 127 | */ |
| 128 | #define OCOTP_CFG3_SPEED_528MHZ 1 |
| 129 | #define OCOTP_CFG3_SPEED_696MHZ 2 |
| 130 | |
Sébastien Szymanski | b130c8a | 2017-08-02 17:05:27 +0200 | [diff] [blame] | 131 | /* |
| 132 | * For i.MX6ULL |
| 133 | */ |
| 134 | #define OCOTP_CFG3_SPEED_792MHZ 2 |
| 135 | #define OCOTP_CFG3_SPEED_900MHZ 3 |
| 136 | |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 137 | u32 get_cpu_speed_grade_hz(void) |
| 138 | { |
| 139 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 140 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 141 | struct fuse_bank0_regs *fuse = |
| 142 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 143 | uint32_t val; |
| 144 | |
| 145 | val = readl(&fuse->cfg3); |
| 146 | val >>= OCOTP_CFG3_SPEED_SHIFT; |
| 147 | val &= 0x3; |
| 148 | |
Sébastien Szymanski | b130c8a | 2017-08-02 17:05:27 +0200 | [diff] [blame] | 149 | if (is_mx6ul()) { |
Peng Fan | 441e905 | 2016-05-03 11:13:04 +0800 | [diff] [blame] | 150 | if (val == OCOTP_CFG3_SPEED_528MHZ) |
| 151 | return 528000000; |
| 152 | else if (val == OCOTP_CFG3_SPEED_696MHZ) |
Sébastien Szymanski | 415c7ce | 2017-08-02 17:05:26 +0200 | [diff] [blame] | 153 | return 696000000; |
Peng Fan | 441e905 | 2016-05-03 11:13:04 +0800 | [diff] [blame] | 154 | else |
| 155 | return 0; |
| 156 | } |
| 157 | |
Sébastien Szymanski | b130c8a | 2017-08-02 17:05:27 +0200 | [diff] [blame] | 158 | if (is_mx6ull()) { |
| 159 | if (val == OCOTP_CFG3_SPEED_528MHZ) |
| 160 | return 528000000; |
| 161 | else if (val == OCOTP_CFG3_SPEED_792MHZ) |
| 162 | return 792000000; |
| 163 | else if (val == OCOTP_CFG3_SPEED_900MHZ) |
| 164 | return 900000000; |
| 165 | else |
| 166 | return 0; |
| 167 | } |
| 168 | |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 169 | switch (val) { |
| 170 | /* Valid for IMX6DQ */ |
| 171 | case OCOTP_CFG3_SPEED_1P2GHZ: |
Peng Fan | 6c4f76f | 2016-05-23 18:35:58 +0800 | [diff] [blame] | 172 | if (is_mx6dq() || is_mx6dqp()) |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 173 | return 1200000000; |
| 174 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 175 | case OCOTP_CFG3_SPEED_1GHZ: |
| 176 | return 996000000; |
| 177 | /* Valid for IMX6DQ */ |
| 178 | case OCOTP_CFG3_SPEED_850MHZ: |
Peng Fan | 6c4f76f | 2016-05-23 18:35:58 +0800 | [diff] [blame] | 179 | if (is_mx6dq() || is_mx6dqp()) |
Tim Harvey | 258d046 | 2015-05-18 07:02:24 -0700 | [diff] [blame] | 180 | return 852000000; |
| 181 | /* Valid for IMX6SX/IMX6SDL/IMX6DQ */ |
| 182 | case OCOTP_CFG3_SPEED_800MHZ: |
| 183 | return 792000000; |
| 184 | } |
| 185 | return 0; |
| 186 | } |
| 187 | |
Tim Harvey | 5e0e193 | 2015-05-18 06:56:45 -0700 | [diff] [blame] | 188 | /* |
| 189 | * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480) |
| 190 | * defines a 2-bit Temperature Grade |
| 191 | * |
Fabio Estevam | a24859c | 2017-06-22 10:50:05 -0300 | [diff] [blame] | 192 | * return temperature grade and min/max temperature in Celsius |
Tim Harvey | 5e0e193 | 2015-05-18 06:56:45 -0700 | [diff] [blame] | 193 | */ |
| 194 | #define OCOTP_MEM0_TEMP_SHIFT 6 |
| 195 | |
| 196 | u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 197 | { |
| 198 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 199 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 200 | struct fuse_bank1_regs *fuse = |
| 201 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 202 | uint32_t val; |
| 203 | |
| 204 | val = readl(&fuse->mem0); |
| 205 | val >>= OCOTP_MEM0_TEMP_SHIFT; |
| 206 | val &= 0x3; |
| 207 | |
| 208 | if (minc && maxc) { |
| 209 | if (val == TEMP_AUTOMOTIVE) { |
| 210 | *minc = -40; |
| 211 | *maxc = 125; |
| 212 | } else if (val == TEMP_INDUSTRIAL) { |
| 213 | *minc = -40; |
| 214 | *maxc = 105; |
| 215 | } else if (val == TEMP_EXTCOMMERCIAL) { |
| 216 | *minc = -20; |
| 217 | *maxc = 105; |
| 218 | } else { |
| 219 | *minc = 0; |
| 220 | *maxc = 95; |
| 221 | } |
| 222 | } |
| 223 | return val; |
| 224 | } |
| 225 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 226 | #ifdef CONFIG_REVISION_TAG |
| 227 | u32 __weak get_board_rev(void) |
| 228 | { |
| 229 | u32 cpurev = get_cpu_rev(); |
| 230 | u32 type = ((cpurev >> 12) & 0xff); |
| 231 | if (type == MXC_CPU_MX6SOLO) |
| 232 | cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF); |
| 233 | |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 234 | if (type == MXC_CPU_MX6D) |
| 235 | cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF); |
| 236 | |
Fabio Estevam | 435998b | 2013-03-27 07:36:55 +0000 | [diff] [blame] | 237 | return cpurev; |
| 238 | } |
| 239 | #endif |
| 240 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 241 | static void clear_ldo_ramp(void) |
| 242 | { |
| 243 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 244 | int reg; |
| 245 | |
| 246 | /* ROM may modify LDO ramp up time according to fuse setting, so in |
| 247 | * order to be in the safe side we neeed to reset these settings to |
| 248 | * match the reset value: 0'b00 |
| 249 | */ |
| 250 | reg = readl(&anatop->ana_misc2); |
| 251 | reg &= ~(0x3f << 24); |
| 252 | writel(reg, &anatop->ana_misc2); |
| 253 | } |
| 254 | |
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 the PMU_REG_CORE register |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 257 | * |
Fabio Estevam | 2e95fe1 | 2014-06-13 01:42:37 -0300 | [diff] [blame] | 258 | * Set LDO_SOC/PU/ARM regulators to the specified millivolt level. |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 259 | * Possible values are from 0.725V to 1.450V in steps of |
| 260 | * 0.025V (25mV). |
| 261 | */ |
Marek Vasut | 02fec41 | 2019-11-26 09:35:32 +0100 | [diff] [blame] | 262 | int set_ldo_voltage(enum ldo_reg ldo, u32 mv) |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 263 | { |
| 264 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 265 | u32 val, step, old, reg = readl(&anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 266 | u8 shift; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 267 | |
Peng Fan | 81224c4 | 2017-08-08 16:21:35 +0800 | [diff] [blame] | 268 | /* No LDO_SOC/PU/ARM */ |
| 269 | if (is_mx6sll()) |
| 270 | return 0; |
| 271 | |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 272 | if (mv < 725) |
| 273 | val = 0x00; /* Power gated off */ |
| 274 | else if (mv > 1450) |
| 275 | val = 0x1F; /* Power FET switched full on. No regulation */ |
| 276 | else |
| 277 | val = (mv - 700) / 25; |
| 278 | |
Fabio Estevam | cf621ff | 2013-12-26 14:51:31 -0200 | [diff] [blame] | 279 | clear_ldo_ramp(); |
| 280 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 281 | switch (ldo) { |
| 282 | case LDO_SOC: |
| 283 | shift = 18; |
| 284 | break; |
| 285 | case LDO_PU: |
| 286 | shift = 9; |
| 287 | break; |
| 288 | case LDO_ARM: |
| 289 | shift = 0; |
| 290 | break; |
| 291 | default: |
| 292 | return -EINVAL; |
| 293 | } |
| 294 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 295 | old = (reg & (0x1F << shift)) >> shift; |
| 296 | step = abs(val - old); |
| 297 | if (step == 0) |
| 298 | return 0; |
| 299 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 300 | reg = (reg & ~(0x1F << shift)) | (val << shift); |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 301 | writel(reg, &anatop->reg_core); |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 302 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 303 | /* |
| 304 | * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per |
| 305 | * step |
| 306 | */ |
| 307 | udelay(3 * step); |
| 308 | |
Fabio Estevam | a47ec52 | 2013-12-26 14:51:33 -0200 | [diff] [blame] | 309 | return 0; |
Dirk Behme | 8c46594 | 2012-05-02 02:12:17 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 312 | static void set_ahb_rate(u32 val) |
| 313 | { |
| 314 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 315 | u32 reg, div; |
| 316 | |
| 317 | div = get_periph_clk() / val - 1; |
| 318 | reg = readl(&mxc_ccm->cbcdr); |
| 319 | |
| 320 | writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) | |
| 321 | (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr); |
| 322 | } |
| 323 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 324 | static void clear_mmdc_ch_mask(void) |
| 325 | { |
| 326 | 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] | 327 | u32 reg; |
| 328 | reg = readl(&mxc_ccm->ccdr); |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 329 | |
| 330 | /* Clear MMDC channel mask */ |
Peng Fan | 81224c4 | 2017-08-08 16:21:35 +0800 | [diff] [blame] | 331 | if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll()) |
Ye Li | 64cef44 | 2016-03-09 16:13:48 +0800 | [diff] [blame] | 332 | reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK); |
| 333 | else |
| 334 | 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] | 335 | writel(reg, &mxc_ccm->ccdr); |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 336 | } |
| 337 | |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 338 | #define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8 |
| 339 | |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 340 | static void init_bandgap(void) |
| 341 | { |
| 342 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 343 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 344 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 345 | struct fuse_bank1_regs *fuse = |
| 346 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 347 | uint32_t val; |
| 348 | |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 349 | /* |
| 350 | * Ensure the bandgap has stabilized. |
| 351 | */ |
| 352 | while (!(readl(&anatop->ana_misc0) & 0x80)) |
| 353 | ; |
| 354 | /* |
| 355 | * For best noise performance of the analog blocks using the |
| 356 | * outputs of the bandgap, the reftop_selfbiasoff bit should |
| 357 | * be set. |
| 358 | */ |
| 359 | writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set); |
Peng Fan | 6b98935 | 2016-08-11 14:02:50 +0800 | [diff] [blame] | 360 | /* |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 361 | * On i.MX6ULL,we need to set VBGADJ bits according to the |
| 362 | * REFTOP_TRIM[3:0] in fuse table |
| 363 | * 000 - set REFTOP_VBGADJ[2:0] to 3b'110, |
| 364 | * 110 - set REFTOP_VBGADJ[2:0] to 3b'000, |
| 365 | * 001 - set REFTOP_VBGADJ[2:0] to 3b'001, |
| 366 | * 010 - set REFTOP_VBGADJ[2:0] to 3b'010, |
| 367 | * 011 - set REFTOP_VBGADJ[2:0] to 3b'011, |
| 368 | * 100 - set REFTOP_VBGADJ[2:0] to 3b'100, |
| 369 | * 101 - set REFTOP_VBGADJ[2:0] to 3b'101, |
| 370 | * 111 - set REFTOP_VBGADJ[2:0] to 3b'111, |
Peng Fan | 6b98935 | 2016-08-11 14:02:50 +0800 | [diff] [blame] | 371 | */ |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 372 | if (is_mx6ull()) { |
Dario Binacchi | ca9177d | 2022-01-31 08:50:05 +0100 | [diff] [blame] | 373 | static const u32 map[] = {6, 1, 2, 3, 4, 5, 0, 7}; |
| 374 | |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 375 | val = readl(&fuse->mem0); |
| 376 | val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT; |
| 377 | val &= 0x7; |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 378 | |
Dario Binacchi | ca9177d | 2022-01-31 08:50:05 +0100 | [diff] [blame] | 379 | writel(map[val] << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT, |
Peng Fan | 656d233 | 2016-10-08 17:03:00 +0800 | [diff] [blame] | 380 | &anatop->ana_misc0_set); |
| 381 | } |
| 382 | } |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 383 | |
Fabio Estevam | 3e59fa9 | 2019-11-04 09:44:34 -0300 | [diff] [blame] | 384 | #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL) |
| 385 | static void noc_setup(void) |
| 386 | { |
| 387 | enable_ipu_clock(); |
| 388 | |
| 389 | writel(0x80000201, 0xbb0608); |
| 390 | /* Bypass IPU1 QoS generator */ |
| 391 | writel(0x00000002, 0x00bb048c); |
| 392 | /* Bypass IPU2 QoS generator */ |
| 393 | writel(0x00000002, 0x00bb050c); |
| 394 | /* Bandwidth THR for of PRE0 */ |
| 395 | writel(0x00000200, 0x00bb0690); |
| 396 | /* Bandwidth THR for of PRE1 */ |
| 397 | writel(0x00000200, 0x00bb0710); |
| 398 | /* Bandwidth THR for of PRE2 */ |
| 399 | writel(0x00000200, 0x00bb0790); |
| 400 | /* Bandwidth THR for of PRE3 */ |
| 401 | writel(0x00000200, 0x00bb0810); |
| 402 | /* Saturation THR for of PRE0 */ |
| 403 | writel(0x00000010, 0x00bb0694); |
| 404 | /* Saturation THR for of PRE1 */ |
| 405 | writel(0x00000010, 0x00bb0714); |
| 406 | /* Saturation THR for of PRE2 */ |
| 407 | writel(0x00000010, 0x00bb0794); |
| 408 | /* Saturation THR for of PRE */ |
| 409 | writel(0x00000010, 0x00bb0814); |
| 410 | |
| 411 | disable_ipu_clock(); |
| 412 | } |
| 413 | #endif |
| 414 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 415 | int arch_cpu_init(void) |
| 416 | { |
Peng Fan | 946333d | 2017-08-08 16:21:38 +0800 | [diff] [blame] | 417 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 418 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 419 | init_aips(); |
| 420 | |
Anson Huang | 9a149bc | 2014-01-23 14:00:19 +0800 | [diff] [blame] | 421 | /* Need to clear MMDC_CHx_MASK to make warm reset work. */ |
| 422 | clear_mmdc_ch_mask(); |
| 423 | |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 424 | /* |
Peng Fan | c0e0ebf | 2015-01-15 14:22:32 +0800 | [diff] [blame] | 425 | * Disable self-bias circuit in the analog bandap. |
| 426 | * The self-bias circuit is used by the bandgap during startup. |
| 427 | * This bit should be set after the bandgap has initialized. |
| 428 | */ |
| 429 | init_bandgap(); |
| 430 | |
Peng Fan | ae86e3f | 2016-08-11 14:02:43 +0800 | [diff] [blame] | 431 | if (!is_mx6ul() && !is_mx6ull()) { |
Peng Fan | f60137e | 2016-03-09 16:44:36 +0800 | [diff] [blame] | 432 | /* |
| 433 | * When low freq boot is enabled, ROM will not set AHB |
| 434 | * freq, so we need to ensure AHB freq is 132MHz in such |
| 435 | * scenario. |
| 436 | * |
| 437 | * To i.MX6UL, when power up, default ARM core and |
| 438 | * AHB rate is 396M and 132M. |
| 439 | */ |
| 440 | if (mxc_get_clock(MXC_ARM_CLK) == 396000000) |
| 441 | set_ahb_rate(132000000); |
| 442 | } |
Anson Huang | 05a464f | 2014-01-23 14:00:18 +0800 | [diff] [blame] | 443 | |
Peng Fan | 2b990ea | 2016-09-28 09:40:27 +0800 | [diff] [blame] | 444 | if (is_mx6ul()) { |
| 445 | if (is_soc_rev(CHIP_REV_1_0) == 0) { |
| 446 | /* |
| 447 | * According to the design team's requirement on |
| 448 | * i.MX6UL,the PMIC_STBY_REQ PAD should be configured |
| 449 | * as open drain 100K (0x0000b8a0). |
| 450 | * Only exists on TO1.0 |
| 451 | */ |
| 452 | writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c); |
| 453 | } else { |
| 454 | /* |
| 455 | * From TO1.1, SNVS adds internal pull up control |
| 456 | * for POR_B, the register filed is GPBIT[1:0], |
| 457 | * after system boot up, it can be set to 2b'01 |
| 458 | * to disable internal pull up.It can save about |
| 459 | * 30uA power in SNVS mode. |
| 460 | */ |
| 461 | writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) & |
| 462 | (~0x1400)) | 0x400, |
| 463 | MX6UL_SNVS_LP_BASE_ADDR + 0x10); |
| 464 | } |
Peng Fan | a2cba65 | 2016-03-09 16:44:37 +0800 | [diff] [blame] | 465 | } |
| 466 | |
Peng Fan | b64bf0b | 2016-08-11 14:02:46 +0800 | [diff] [blame] | 467 | if (is_mx6ull()) { |
| 468 | /* |
| 469 | * GPBIT[1:0] is suggested to set to 2'b11: |
| 470 | * 2'b00 : always PUP100K |
| 471 | * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL |
| 472 | * 2'b10 : always disable PUP100K |
| 473 | * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL |
| 474 | * register offset is different from i.MX6UL, since |
| 475 | * i.MX6UL is fixed by ECO. |
| 476 | */ |
| 477 | writel(readl(MX6UL_SNVS_LP_BASE_ADDR) | |
| 478 | 0x3, MX6UL_SNVS_LP_BASE_ADDR); |
| 479 | } |
| 480 | |
Peng Fan | a2cba65 | 2016-03-09 16:44:37 +0800 | [diff] [blame] | 481 | /* Set perclk to source from OSC 24MHz */ |
Jorge Ramirez-Ortiz | 76d9539 | 2020-10-23 21:18:41 +0200 | [diff] [blame] | 482 | if (has_err007805()) |
Peng Fan | fe7052a | 2017-08-08 16:21:39 +0800 | [diff] [blame] | 483 | setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK); |
Ye.Li | 622dfbd | 2014-10-30 18:20:58 +0800 | [diff] [blame] | 484 | |
Fabio Estevam | 5f79d46 | 2017-11-23 10:55:33 -0200 | [diff] [blame] | 485 | imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */ |
Stefan Roese | 8338d1d | 2013-04-15 21:14:12 +0000 | [diff] [blame] | 486 | |
Peng Fan | 946333d | 2017-08-08 16:21:38 +0800 | [diff] [blame] | 487 | if (is_mx6sx()) |
| 488 | setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL); |
| 489 | |
Dirk Behme | 0adb215 | 2015-03-09 14:48:48 +0100 | [diff] [blame] | 490 | init_src(); |
| 491 | |
Fabio Estevam | 3e59fa9 | 2019-11-04 09:44:34 -0300 | [diff] [blame] | 492 | #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL) |
| 493 | if (is_mx6dqp()) |
| 494 | noc_setup(); |
| 495 | #endif |
Sven Schwermer | 2645cfa | 2022-01-02 20:36:56 +0100 | [diff] [blame] | 496 | |
| 497 | enable_ca7_smp(); |
| 498 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 499 | return 0; |
| 500 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 501 | |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 502 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 503 | __weak int board_mmc_get_env_dev(int devno) |
| 504 | { |
| 505 | return CONFIG_SYS_MMC_ENV_DEV; |
| 506 | } |
| 507 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 508 | static int mmc_get_boot_dev(void) |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 509 | { |
Harald Seiler | 51390ba | 2021-12-01 10:11:47 +0100 | [diff] [blame] | 510 | u32 soc_sbmr = imx6_src_get_boot_mode(); |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 511 | u32 bootsel; |
| 512 | int devno; |
| 513 | |
| 514 | /* |
| 515 | * Refer to |
| 516 | * "i.MX 6Dual/6Quad Applications Processor Reference Manual" |
| 517 | * Chapter "8.5.3.1 Expansion Device eFUSE Configuration" |
| 518 | * i.MX6SL/SX/UL has same layout. |
| 519 | */ |
| 520 | bootsel = (soc_sbmr & 0x000000FF) >> 6; |
| 521 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 522 | /* No boot from sd/mmc */ |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 523 | if (bootsel != 1) |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 524 | return -1; |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 525 | |
| 526 | /* BOOT_CFG2[3] and BOOT_CFG2[4] */ |
| 527 | devno = (soc_sbmr & 0x00001800) >> 11; |
| 528 | |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 529 | return devno; |
| 530 | } |
| 531 | |
| 532 | int mmc_get_env_dev(void) |
| 533 | { |
| 534 | int devno = mmc_get_boot_dev(); |
| 535 | |
| 536 | /* If not boot from sd/mmc, use default value */ |
| 537 | if (devno < 0) |
| 538 | return CONFIG_SYS_MMC_ENV_DEV; |
| 539 | |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 540 | return board_mmc_get_env_dev(devno); |
| 541 | } |
Soeren Moch | bc177f1 | 2016-02-04 14:41:15 +0100 | [diff] [blame] | 542 | |
| 543 | #ifdef CONFIG_SYS_MMC_ENV_PART |
| 544 | __weak int board_mmc_get_env_part(int devno) |
| 545 | { |
| 546 | return CONFIG_SYS_MMC_ENV_PART; |
| 547 | } |
| 548 | |
| 549 | uint mmc_get_env_part(struct mmc *mmc) |
| 550 | { |
| 551 | int devno = mmc_get_boot_dev(); |
| 552 | |
| 553 | /* If not boot from sd/mmc, use default value */ |
| 554 | if (devno < 0) |
| 555 | return CONFIG_SYS_MMC_ENV_PART; |
| 556 | |
| 557 | return board_mmc_get_env_part(devno); |
| 558 | } |
| 559 | #endif |
Peng Fan | 850dbca | 2016-01-28 16:51:26 +0800 | [diff] [blame] | 560 | #endif |
| 561 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 562 | int board_postclk_init(void) |
| 563 | { |
Peng Fan | 81224c4 | 2017-08-08 16:21:35 +0800 | [diff] [blame] | 564 | /* NO LDO SOC on i.MX6SLL */ |
| 565 | if (is_mx6sll()) |
| 566 | return 0; |
| 567 | |
Fabio Estevam | 99b370b | 2013-12-26 14:51:34 -0200 | [diff] [blame] | 568 | set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */ |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Simon Glass | 85ed77d | 2024-09-29 19:49:46 -0600 | [diff] [blame] | 573 | #ifndef CONFIG_XPL_BUILD |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 574 | /* |
| 575 | * cfg_val will be used for |
| 576 | * 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] | 577 | * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0] |
| 578 | * instead of SBMR1 to determine the boot device. |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 579 | */ |
| 580 | const struct boot_mode soc_boot_modes[] = { |
| 581 | {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, |
| 582 | /* reserved value should start rom usb */ |
Stefan Agner | 6b46c46 | 2017-06-09 13:13:12 -0700 | [diff] [blame] | 583 | #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL) |
| 584 | {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)}, |
| 585 | #else |
Stefan Agner | eb4b62b | 2016-09-15 15:04:39 -0700 | [diff] [blame] | 586 | {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)}, |
Stefan Agner | 6b46c46 | 2017-06-09 13:13:12 -0700 | [diff] [blame] | 587 | #endif |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 588 | {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)}, |
Nikolay Dimitrov | 284d901 | 2014-08-10 20:03:07 +0300 | [diff] [blame] | 589 | {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)}, |
| 590 | {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)}, |
| 591 | {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)}, |
| 592 | {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)}, |
Fabio Estevam | 40efe77 | 2024-08-17 16:13:13 -0300 | [diff] [blame] | 593 | {"ecspi3:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x0a)}, |
| 594 | {"ecspi3:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x1a)}, |
| 595 | {"ecspi3:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x2a)}, |
| 596 | {"ecspi3:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x3a)}, |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 597 | /* 4 bit bus width */ |
| 598 | {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)}, |
| 599 | {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 600 | {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 601 | {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)}, |
| 602 | {NULL, 0}, |
| 603 | }; |
Anatolij Gustschin | 938734e | 2017-08-28 17:51:33 +0200 | [diff] [blame] | 604 | #endif |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 605 | |
Peng Fan | 92683e6 | 2015-10-29 15:54:50 +0800 | [diff] [blame] | 606 | void reset_misc(void) |
| 607 | { |
Simon Glass | 85ed77d | 2024-09-29 19:49:46 -0600 | [diff] [blame] | 608 | #ifndef CONFIG_XPL_BUILD |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 609 | #if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_VIDEO) |
Peng Fan | 92683e6 | 2015-10-29 15:54:50 +0800 | [diff] [blame] | 610 | lcdif_power_down(); |
| 611 | #endif |
Michael Trimarchi | c41042a | 2018-06-20 23:27:54 +0200 | [diff] [blame] | 612 | #endif |
Peng Fan | 92683e6 | 2015-10-29 15:54:50 +0800 | [diff] [blame] | 613 | } |
| 614 | |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 615 | void s_init(void) |
| 616 | { |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 617 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 618 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 619 | u32 mask480; |
| 620 | u32 mask528; |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 621 | u32 reg, periph1, periph2; |
Fabio Estevam | 6633e3f | 2014-07-09 16:13:29 -0300 | [diff] [blame] | 622 | |
Peng Fan | 81224c4 | 2017-08-08 16:21:35 +0800 | [diff] [blame] | 623 | if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll()) |
Fabio Estevam | 6633e3f | 2014-07-09 16:13:29 -0300 | [diff] [blame] | 624 | return; |
| 625 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 626 | /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs |
| 627 | * to make sure PFD is working right, otherwise, PFDs may |
| 628 | * not output clock after reset, MX6DL and MX6SL have added 396M pfd |
| 629 | * workaround in ROM code, as bus clock need it |
| 630 | */ |
| 631 | |
| 632 | mask480 = ANATOP_PFD_CLKGATE_MASK(0) | |
| 633 | ANATOP_PFD_CLKGATE_MASK(1) | |
| 634 | ANATOP_PFD_CLKGATE_MASK(2) | |
| 635 | ANATOP_PFD_CLKGATE_MASK(3); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 636 | mask528 = ANATOP_PFD_CLKGATE_MASK(1) | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 637 | ANATOP_PFD_CLKGATE_MASK(3); |
| 638 | |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 639 | reg = readl(&ccm->cbcmr); |
| 640 | periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) |
| 641 | >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET); |
| 642 | periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) |
| 643 | >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET); |
| 644 | |
| 645 | /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */ |
| 646 | if ((periph2 != 0x2) && (periph1 != 0x2)) |
| 647 | mask528 |= ANATOP_PFD_CLKGATE_MASK(0); |
| 648 | |
| 649 | if ((periph2 != 0x1) && (periph1 != 0x1) && |
| 650 | (periph2 != 0x3) && (periph1 != 0x3)) |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 651 | mask528 |= ANATOP_PFD_CLKGATE_MASK(2); |
Ye.Li | 2987687 | 2014-09-09 10:17:00 +0800 | [diff] [blame] | 652 | |
Eric Nelson | 2c37d3b | 2013-08-29 12:41:46 -0700 | [diff] [blame] | 653 | writel(mask480, &anatop->pfd_480_set); |
| 654 | writel(mask528, &anatop->pfd_528_set); |
| 655 | writel(mask480, &anatop->pfd_480_clr); |
| 656 | writel(mask528, &anatop->pfd_528_clr); |
Stephen Warren | 57ab23f | 2013-02-26 12:28:29 +0000 | [diff] [blame] | 657 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 658 | |
| 659 | #ifdef CONFIG_IMX_HDMI |
| 660 | void imx_enable_hdmi_phy(void) |
| 661 | { |
| 662 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
| 663 | u8 reg; |
| 664 | reg = readb(&hdmi->phy_conf0); |
| 665 | reg |= HDMI_PHY_CONF0_PDZ_MASK; |
| 666 | writeb(reg, &hdmi->phy_conf0); |
| 667 | udelay(3000); |
| 668 | reg |= HDMI_PHY_CONF0_ENTMDS_MASK; |
| 669 | writeb(reg, &hdmi->phy_conf0); |
| 670 | udelay(3000); |
| 671 | reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK; |
| 672 | writeb(reg, &hdmi->phy_conf0); |
| 673 | writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz); |
| 674 | } |
| 675 | |
| 676 | void imx_setup_hdmi(void) |
| 677 | { |
| 678 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 679 | struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR; |
Peng Fan | 95ae612 | 2016-03-09 16:07:23 +0800 | [diff] [blame] | 680 | int reg, count; |
| 681 | u8 val; |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 682 | |
| 683 | /* Turn on HDMI PHY clock */ |
| 684 | reg = readl(&mxc_ccm->CCGR2); |
| 685 | reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK| |
| 686 | MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK; |
| 687 | writel(reg, &mxc_ccm->CCGR2); |
| 688 | writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz); |
| 689 | reg = readl(&mxc_ccm->chsccdr); |
| 690 | reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK| |
| 691 | MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK| |
| 692 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK); |
| 693 | reg |= (CHSCCDR_PODF_DIVIDE_BY_3 |
| 694 | << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
| 695 | |(CHSCCDR_IPU_PRE_CLK_540M_PFD |
| 696 | << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET); |
| 697 | writel(reg, &mxc_ccm->chsccdr); |
Peng Fan | 95ae612 | 2016-03-09 16:07:23 +0800 | [diff] [blame] | 698 | |
| 699 | /* Clear the overflow condition */ |
| 700 | if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) { |
| 701 | /* TMDS software reset */ |
| 702 | writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz); |
| 703 | val = readb(&hdmi->fc_invidconf); |
| 704 | /* Need minimum 3 times to write to clear the register */ |
| 705 | for (count = 0 ; count < 5 ; count++) |
| 706 | writeb(val, &hdmi->fc_invidconf); |
| 707 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 708 | } |
| 709 | #endif |
Peng Fan | fb3a3b7 | 2016-01-28 16:55:05 +0800 | [diff] [blame] | 710 | |
Heinrich Schuchardt | cdd0c85 | 2020-06-26 19:57:55 +0200 | [diff] [blame] | 711 | #ifdef CONFIG_ARCH_MISC_INIT |
Sean Anderson | bee0b6b | 2021-02-04 16:44:22 -0500 | [diff] [blame] | 712 | /* |
| 713 | * UNIQUE_ID describes a unique ID based on silicon wafer |
| 714 | * and die X/Y position |
| 715 | * |
| 716 | * UNIQUE_ID offset 0x410 |
| 717 | * 31:0 fuse 0 |
| 718 | * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID |
| 719 | * |
| 720 | * UNIQUE_ID offset 0x420 |
| 721 | * 31:24 fuse 1 |
| 722 | * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID |
| 723 | * 23:16 fuse 1 |
| 724 | * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID |
| 725 | * 15:11 fuse 1 |
| 726 | * The wafer number of the wafer on which the device was fabricated/SJC |
| 727 | * CHALLENGE/ Unique ID |
| 728 | * 10:0 fuse 1 |
| 729 | * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID |
| 730 | */ |
| 731 | static void setup_serial_number(void) |
| 732 | { |
| 733 | char serial_string[17]; |
| 734 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 735 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 736 | struct fuse_bank0_regs *fuse = |
| 737 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 738 | |
| 739 | if (env_get("serial#")) |
| 740 | return; |
| 741 | |
| 742 | snprintf(serial_string, sizeof(serial_string), "%08x%08x", |
| 743 | fuse->uid_low, fuse->uid_high); |
| 744 | env_set("serial#", serial_string); |
| 745 | } |
| 746 | |
Heinrich Schuchardt | cdd0c85 | 2020-06-26 19:57:55 +0200 | [diff] [blame] | 747 | int arch_misc_init(void) |
| 748 | { |
Gaurav Jain | 607571a | 2022-03-24 11:50:29 +0530 | [diff] [blame] | 749 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 750 | struct udevice *dev; |
| 751 | int ret; |
| 752 | |
| 753 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 754 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 755 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | 607571a | 2022-03-24 11:50:29 +0530 | [diff] [blame] | 756 | } |
Kshitiz Varshney | e00a29f | 2022-12-22 09:50:28 +0100 | [diff] [blame] | 757 | |
| 758 | if (IS_ENABLED(CONFIG_FSL_DCP_RNG)) { |
| 759 | struct udevice *dev; |
| 760 | int ret; |
| 761 | |
| 762 | ret = uclass_get_device_by_driver(UCLASS_RNG, DM_DRIVER_GET(dcp_rng), &dev); |
| 763 | if (ret) |
| 764 | printf("Failed to initialize dcp rng: %d\n", ret); |
| 765 | } |
| 766 | |
Sean Anderson | bee0b6b | 2021-02-04 16:44:22 -0500 | [diff] [blame] | 767 | setup_serial_number(); |
Heinrich Schuchardt | cdd0c85 | 2020-06-26 19:57:55 +0200 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | #endif |
Michael Trimarchi | d9de3f8 | 2018-06-23 16:10:06 +0200 | [diff] [blame] | 771 | |
| 772 | /* |
| 773 | * gpr_init() function is common for boards using MX6S, MX6DL, MX6D, |
| 774 | * MX6Q and MX6QP processors |
| 775 | */ |
Breno Lima | f22b109 | 2017-08-24 10:00:16 -0300 | [diff] [blame] | 776 | void gpr_init(void) |
| 777 | { |
| 778 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 779 | |
Christoph Niedermaier | 2082ebf | 2018-10-19 17:40:54 +0200 | [diff] [blame] | 780 | /* |
| 781 | * If this function is used in a common MX6 spl implementation |
| 782 | * we have to ensure that it is only called for suitable cpu types, |
| 783 | * otherwise it breaks hardware parts like enet1, can1, can2, etc. |
| 784 | */ |
| 785 | if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl()) |
| 786 | return; |
| 787 | |
Breno Lima | f22b109 | 2017-08-24 10:00:16 -0300 | [diff] [blame] | 788 | /* enable AXI cache for VDOA/VPU/IPU */ |
| 789 | writel(0xF00000CF, &iomux->gpr[4]); |
| 790 | if (is_mx6dqp()) { |
| 791 | /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */ |
| 792 | writel(0x77177717, &iomux->gpr[6]); |
| 793 | writel(0x77177717, &iomux->gpr[7]); |
| 794 | } else { |
| 795 | /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */ |
| 796 | writel(0x007F007F, &iomux->gpr[6]); |
| 797 | writel(0x007F007F, &iomux->gpr[7]); |
| 798 | } |
| 799 | } |