Philip Oberfichtner | 9d680d1 | 2022-05-19 13:52:48 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2017 DENX Software Engineering GmbH, Heiko Schocher <hs@denx.de> |
| 4 | * Copyright (c) 2019 Bosch Thermotechnik GmbH |
| 5 | * Copyright (c) 2022 DENX Software Engineering GmbH, Philip Oberfichtner <pro@denx.de> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Tom Rini | e3b3264 | 2023-03-09 11:22:07 -0500 | [diff] [blame] | 9 | #include <cpu_func.h> |
Philip Oberfichtner | 9d680d1 | 2022-05-19 13:52:48 +0200 | [diff] [blame] | 10 | #include <bootstage.h> |
| 11 | #include <dm.h> |
| 12 | #include <dm/platform_data/serial_mxc.h> |
| 13 | #include <dm/device-internal.h> |
| 14 | #include <env.h> |
| 15 | #include <env_internal.h> |
| 16 | #include <hang.h> |
| 17 | #include <init.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <mmc.h> |
| 20 | |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/gpio.h> |
| 23 | #include <linux/sizes.h> |
| 24 | |
| 25 | #include <asm/arch/clock.h> |
| 26 | #include <asm/arch/crm_regs.h> |
| 27 | #include <asm/arch/iomux.h> |
| 28 | #include <asm/arch/mx6-pins.h> |
| 29 | #include <asm/arch/sys_proto.h> |
| 30 | #include <asm/mach-imx/iomux-v3.h> |
| 31 | #include <usb.h> |
| 32 | #include <usb/ehci-ci.h> |
| 33 | #include <fuse.h> |
| 34 | |
| 35 | #include <watchdog.h> |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
| 39 | #define GPIO_ACC_PLAT_DETECT IMX_GPIO_NR(5, 9) |
| 40 | #define GPIO_ACC_RAM_VOLT_DETECT IMX_GPIO_NR(5, 0) |
| 41 | #define GPIO_BUZZER IMX_GPIO_NR(1, 18) |
| 42 | #define GPIO_LAN1_RESET IMX_GPIO_NR(4, 27) |
| 43 | #define GPIO_LAN2_RESET IMX_GPIO_NR(4, 19) |
| 44 | #define GPIO_LAN3_RESET IMX_GPIO_NR(4, 18) |
| 45 | #define GPIO_USB_HUB_RESET IMX_GPIO_NR(5, 5) |
| 46 | #define GPIO_EXP_RS485_RESET IMX_GPIO_NR(4, 16) |
| 47 | #define GPIO_TOUCH_RESET IMX_GPIO_NR(1, 20) |
| 48 | |
| 49 | #define BOARD_INFO_MAGIC 0x19730517 |
| 50 | |
| 51 | struct board_info { |
| 52 | int magic; |
| 53 | int board; |
| 54 | int rev; |
| 55 | }; |
| 56 | |
| 57 | static struct board_info *detect_board(void); |
| 58 | |
| 59 | #define PFID_BOARD_ACC 0xe |
| 60 | |
| 61 | static const char * const name_board[] = { |
| 62 | [PFID_BOARD_ACC] = "ACC", |
| 63 | }; |
| 64 | |
| 65 | #define PFID_REV_22 0x8 |
| 66 | #define PFID_REV_21 0x9 |
| 67 | #define PFID_REV_20 0xa |
| 68 | #define PFID_REV_14 0xb |
| 69 | #define PFID_REV_13 0xc |
| 70 | #define PFID_REV_12 0xd |
| 71 | #define PFID_REV_11 0xe |
| 72 | #define PFID_REV_10 0xf |
| 73 | |
| 74 | static const char * const name_revision[] = { |
| 75 | [0 ... PFID_REV_10] = "Unknown", |
| 76 | [PFID_REV_10] = "1.0", |
| 77 | [PFID_REV_11] = "1.1", |
| 78 | [PFID_REV_12] = "1.2", |
| 79 | [PFID_REV_13] = "1.3", |
| 80 | [PFID_REV_14] = "1.4", |
| 81 | [PFID_REV_20] = "2.0", |
| 82 | [PFID_REV_21] = "2.1", |
| 83 | [PFID_REV_22] = "2.2", |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * NXP Reset Default: 0x0001B0B0 |
| 88 | * - Schmitt trigger input (PAD_CTL_HYS) |
| 89 | * - 100K Ohm Pull Up (PAD_CTL_PUS_100K_UP) |
| 90 | * - Pull Enabled (PAD_CTL_PUE) |
| 91 | * - Pull/Keeper Enabled (PAD_CTL_PKE) |
| 92 | * - CMOS output (No PAD_CTL_ODE) |
| 93 | * - Medium Speed (PAD_CTL_SPEED_MED) |
| 94 | * - 40 Ohm drive strength (PAD_CTL_DSE_40ohm) |
| 95 | * - Slow (PAD_CTL_SRE_SLOW) |
| 96 | */ |
| 97 | |
| 98 | /* Input, no pull up/down: 0x0x000100B0 */ |
| 99 | #define GPIN_PAD_CTRL (PAD_CTL_HYS \ |
| 100 | | PAD_CTL_SPEED_MED \ |
| 101 | | PAD_CTL_DSE_40ohm \ |
| 102 | | PAD_CTL_SRE_SLOW) |
| 103 | |
| 104 | /* Input, pull up: 0x0x0001B0B0 */ |
| 105 | #define GPIN_PU_PAD_CTRL (PAD_CTL_HYS \ |
| 106 | | PAD_CTL_PUS_100K_UP \ |
| 107 | | PAD_CTL_PUE \ |
| 108 | | PAD_CTL_PKE \ |
| 109 | | PAD_CTL_SPEED_MED \ |
| 110 | | PAD_CTL_DSE_40ohm \ |
| 111 | | PAD_CTL_SRE_SLOW) |
| 112 | |
| 113 | /* Input, pull down: 0x0x000130B0 */ |
| 114 | #define GPIN_PD_PAD_CTRL (PAD_CTL_HYS \ |
| 115 | | PAD_CTL_PUS_100K_DOWN \ |
| 116 | | PAD_CTL_PUE \ |
| 117 | | PAD_CTL_PKE \ |
| 118 | | PAD_CTL_SPEED_MED \ |
| 119 | | PAD_CTL_DSE_40ohm \ |
| 120 | | PAD_CTL_SRE_SLOW) |
| 121 | |
| 122 | static const iomux_v3_cfg_t board_detect_pads[] = { |
| 123 | /* Platform detect */ |
| 124 | IOMUX_PADS(PAD_DISP0_DAT15__GPIO5_IO09 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 125 | /* RAM Volt detect */ |
| 126 | IOMUX_PADS(PAD_EIM_WAIT__GPIO5_IO00 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 127 | /* PFID 0..9 */ |
| 128 | IOMUX_PADS(PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 129 | IOMUX_PADS(PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 130 | IOMUX_PADS(PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 131 | IOMUX_PADS(PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 132 | IOMUX_PADS(PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 133 | IOMUX_PADS(PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 134 | IOMUX_PADS(PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 135 | IOMUX_PADS(PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 136 | IOMUX_PADS(PAD_NANDF_CS3__GPIO6_IO16 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 137 | IOMUX_PADS(PAD_NANDF_CS1__GPIO6_IO14 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 138 | /* Manufacturer */ |
| 139 | IOMUX_PADS(PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(GPIN_PAD_CTRL)), |
| 140 | /* Redundant */ |
| 141 | IOMUX_PADS(PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(GPIN_PU_PAD_CTRL)) |
| 142 | }; |
| 143 | |
| 144 | static int gpio_acc_pfid[] = { |
| 145 | IMX_GPIO_NR(2, 0), |
| 146 | IMX_GPIO_NR(2, 1), |
| 147 | IMX_GPIO_NR(2, 2), |
| 148 | IMX_GPIO_NR(2, 3), |
| 149 | IMX_GPIO_NR(2, 4), |
| 150 | IMX_GPIO_NR(6, 14), |
| 151 | IMX_GPIO_NR(6, 15), |
| 152 | IMX_GPIO_NR(2, 5), |
| 153 | IMX_GPIO_NR(2, 6), |
| 154 | IMX_GPIO_NR(2, 7), |
| 155 | IMX_GPIO_NR(6, 16), |
| 156 | IMX_GPIO_NR(5, 4), |
| 157 | }; |
| 158 | |
| 159 | static int init_gpio(int nr) |
| 160 | { |
| 161 | int ret; |
| 162 | |
| 163 | ret = gpio_request(nr, ""); |
| 164 | if (ret != 0) { |
| 165 | printf("Could not request gpio nr: %d\n", nr); |
| 166 | hang(); |
| 167 | } |
| 168 | ret = gpio_direction_input(nr); |
| 169 | if (ret != 0) { |
| 170 | printf("Could not set gpio nr: %d to input\n", nr); |
| 171 | hang(); |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * We want to detect the board type only once in SPL, |
| 178 | * so we store the board_info struct at beginning in IRAM. |
| 179 | * |
| 180 | * U-Boot itself can read it also, and do not need again |
| 181 | * to detect board type. |
| 182 | * |
| 183 | */ |
| 184 | static struct board_info *detect_board(void) |
| 185 | { |
| 186 | struct board_info *binfo = (struct board_info *)IRAM_BASE_ADDR; |
| 187 | int i; |
| 188 | |
| 189 | if (binfo->magic == BOARD_INFO_MAGIC) |
| 190 | return binfo; |
| 191 | |
| 192 | puts("Board: "); |
| 193 | SETUP_IOMUX_PADS(board_detect_pads); |
| 194 | init_gpio(GPIO_ACC_PLAT_DETECT); |
| 195 | if (gpio_get_value(GPIO_ACC_PLAT_DETECT)) { |
| 196 | puts("not supported"); |
| 197 | hang(); |
| 198 | } else { |
| 199 | puts("Bosch "); |
| 200 | } |
| 201 | |
| 202 | for (i = 0; i < sizeof(gpio_acc_pfid) / sizeof(int); i++) |
| 203 | init_gpio(gpio_acc_pfid[i]); |
| 204 | |
| 205 | binfo->board = gpio_get_value(gpio_acc_pfid[0]) << 0 | |
| 206 | gpio_get_value(gpio_acc_pfid[1]) << 1 | |
| 207 | gpio_get_value(gpio_acc_pfid[2]) << 2 | |
| 208 | gpio_get_value(gpio_acc_pfid[11]) << 3; |
| 209 | printf("%s ", name_board[binfo->board]); |
| 210 | |
| 211 | binfo->rev = gpio_get_value(gpio_acc_pfid[7]) << 0 | |
| 212 | gpio_get_value(gpio_acc_pfid[8]) << 1 | |
| 213 | gpio_get_value(gpio_acc_pfid[9]) << 2 | |
| 214 | gpio_get_value(gpio_acc_pfid[10]) << 3; |
| 215 | printf("rev: %s\n", name_revision[binfo->rev]); |
| 216 | |
| 217 | binfo->magic = BOARD_INFO_MAGIC; |
| 218 | |
| 219 | return binfo; |
| 220 | } |
| 221 | |
| 222 | static void unset_early_gpio(void) |
| 223 | { |
| 224 | init_gpio(GPIO_LAN1_RESET); |
| 225 | init_gpio(GPIO_LAN2_RESET); |
| 226 | init_gpio(GPIO_LAN3_RESET); |
| 227 | init_gpio(GPIO_USB_HUB_RESET); |
| 228 | init_gpio(GPIO_EXP_RS485_RESET); |
| 229 | init_gpio(GPIO_TOUCH_RESET); |
| 230 | |
| 231 | gpio_set_value(GPIO_LAN1_RESET, 1); |
| 232 | gpio_set_value(GPIO_LAN2_RESET, 1); |
| 233 | gpio_set_value(GPIO_LAN3_RESET, 1); |
| 234 | gpio_set_value(GPIO_USB_HUB_RESET, 1); |
| 235 | gpio_set_value(GPIO_EXP_RS485_RESET, 1); |
| 236 | gpio_set_value(GPIO_TOUCH_RESET, 1); |
| 237 | } |
| 238 | |
| 239 | enum env_location env_get_location(enum env_operation op, int prio) |
| 240 | { |
| 241 | if (op == ENVOP_SAVE || op == ENVOP_ERASE) |
| 242 | return ENVL_MMC; |
| 243 | |
| 244 | switch (prio) { |
| 245 | case 0: |
| 246 | return ENVL_NOWHERE; |
| 247 | |
| 248 | case 1: |
| 249 | return ENVL_MMC; |
| 250 | } |
| 251 | |
| 252 | return ENVL_UNKNOWN; |
| 253 | } |
| 254 | |
| 255 | int board_late_init(void) |
| 256 | { |
| 257 | struct board_info *binfo = detect_board(); |
| 258 | |
| 259 | switch (binfo->board) { |
| 260 | case PFID_BOARD_ACC: |
| 261 | env_set("bootconf", "conf-imx6q-bosch-acc.dtb"); |
| 262 | break; |
| 263 | default: |
| 264 | printf("Unknown board %d\n", binfo->board); |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | unset_early_gpio(); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | int board_init(void) |
| 274 | { |
| 275 | /* Address of boot parameters */ |
| 276 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | int dram_init(void) |
| 282 | { |
| 283 | gd->ram_size = imx_ddr_size(); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | #if IS_ENABLED(CONFIG_SPL_BUILD) |
| 289 | #include <asm/arch/crm_regs.h> |
| 290 | #include <asm/arch/imx-regs.h> |
| 291 | #include <asm/arch/iomux.h> |
| 292 | #include <asm/arch/mx6-ddr.h> |
| 293 | #include <asm/arch/mx6-pins.h> |
| 294 | #include <asm/arch/sys_proto.h> |
| 295 | #include <spl.h> |
| 296 | |
| 297 | /* Early |
| 298 | * - Buzzer -> GPIO IN, Pull-Down (PWM enabled by Kernel later-on, lacks of an |
| 299 | * external pull-down resistor) |
| 300 | * - Touch clean reset on every boot |
| 301 | * - Ethernet(s), USB Hub, Expansion RS485 -> Clean reset on each u-boot init |
| 302 | */ |
| 303 | static const iomux_v3_cfg_t early_pads[] = { |
| 304 | IOMUX_PADS(PAD_SD1_CMD__GPIO1_IO18 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* Buzzer PWM */ |
| 305 | IOMUX_PADS(PAD_DISP0_DAT6__GPIO4_IO27 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #FEC_RESET_B */ |
| 306 | IOMUX_PADS(PAD_DI0_PIN2__GPIO4_IO18 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #ETH1_RESET */ |
| 307 | IOMUX_PADS(PAD_DI0_PIN3__GPIO4_IO19 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #ETH2_RESET */ |
| 308 | IOMUX_PADS(PAD_DISP0_DAT11__GPIO5_IO05 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #USB Reset */ |
| 309 | IOMUX_PADS(PAD_DI0_DISP_CLK__GPIO4_IO16 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #UART_RESET */ |
| 310 | IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #CTOUCH_RESET */ |
| 311 | }; |
| 312 | |
| 313 | static void setup_iomux_early(void) |
| 314 | { |
| 315 | SETUP_IOMUX_PADS(early_pads); |
| 316 | } |
| 317 | |
| 318 | static void set_early_gpio(void) |
| 319 | { |
| 320 | init_gpio(GPIO_BUZZER); |
| 321 | init_gpio(GPIO_LAN1_RESET); |
| 322 | init_gpio(GPIO_LAN2_RESET); |
| 323 | init_gpio(GPIO_LAN3_RESET); |
| 324 | init_gpio(GPIO_USB_HUB_RESET); |
| 325 | init_gpio(GPIO_EXP_RS485_RESET); |
| 326 | init_gpio(GPIO_TOUCH_RESET); |
| 327 | |
| 328 | /* Reset signals are active low */ |
| 329 | gpio_set_value(GPIO_BUZZER, 0); |
| 330 | gpio_set_value(GPIO_LAN1_RESET, 0); |
| 331 | gpio_set_value(GPIO_LAN2_RESET, 0); |
| 332 | gpio_set_value(GPIO_LAN3_RESET, 0); |
| 333 | gpio_set_value(GPIO_USB_HUB_RESET, 0); |
| 334 | gpio_set_value(GPIO_EXP_RS485_RESET, 0); |
| 335 | gpio_set_value(GPIO_TOUCH_RESET, 0); |
| 336 | } |
| 337 | |
| 338 | /* UART */ |
| 339 | #define UART_PAD_CTRL \ |
| 340 | (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 341 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 342 | |
| 343 | #undef UART_PAD_CTRL |
| 344 | #define UART_PAD_CTRL 0x1b0b1 |
| 345 | static const iomux_v3_cfg_t uart2_pads[] = { |
| 346 | IOMUX_PADS(PAD_SD3_DAT4__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 347 | IOMUX_PADS(PAD_SD3_DAT5__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 348 | IOMUX_PADS(PAD_SD3_CMD__UART2_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 349 | IOMUX_PADS(PAD_SD3_CLK__UART2_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 350 | }; |
| 351 | |
| 352 | static void setup_iomux_uart(void) |
| 353 | { |
| 354 | SETUP_IOMUX_PADS(uart2_pads); |
| 355 | } |
| 356 | |
| 357 | void spl_board_init(void) |
| 358 | { |
| 359 | } |
| 360 | |
| 361 | static const struct mx6dq_iomux_ddr_regs acc_mx6d_ddr_ioregs = { |
| 362 | .dram_sdclk_0 = 0x00008038, |
| 363 | .dram_sdclk_1 = 0x00008038, |
| 364 | .dram_cas = 0x00008028, |
| 365 | .dram_ras = 0x00008028, |
| 366 | .dram_reset = 0x00000028, |
| 367 | .dram_sdcke0 = 0x00003000, |
| 368 | .dram_sdcke1 = 0x00003000, |
| 369 | .dram_sdba2 = 0x00008000, |
| 370 | .dram_sdodt0 = 0x00000028, |
| 371 | .dram_sdodt1 = 0x00000028, |
| 372 | .dram_sdqs0 = 0x00008038, |
| 373 | .dram_sdqs1 = 0x00008038, |
| 374 | .dram_sdqs2 = 0x00008038, |
| 375 | .dram_sdqs3 = 0x00008038, |
| 376 | .dram_sdqs4 = 0x00008038, |
| 377 | .dram_sdqs5 = 0x00008038, |
| 378 | .dram_sdqs6 = 0x00008038, |
| 379 | .dram_sdqs7 = 0x00008038, |
| 380 | .dram_dqm0 = 0x00008038, |
| 381 | .dram_dqm1 = 0x00008038, |
| 382 | .dram_dqm2 = 0x00008038, |
| 383 | .dram_dqm3 = 0x00008038, |
| 384 | .dram_dqm4 = 0x00008038, |
| 385 | .dram_dqm5 = 0x00008038, |
| 386 | .dram_dqm6 = 0x00008038, |
| 387 | .dram_dqm7 = 0x00008038, |
| 388 | }; |
| 389 | |
| 390 | static const struct mx6dq_iomux_grp_regs acc_mx6d_grp_ioregs = { |
| 391 | .grp_ddr_type = 0x000C0000, |
| 392 | .grp_ddrmode_ctl = 0x00020000, |
| 393 | .grp_ddrpke = 0x00000000, |
| 394 | .grp_addds = 0x00000030, |
| 395 | .grp_ctlds = 0x00000028, |
| 396 | .grp_ddrmode = 0x00020000, |
| 397 | .grp_b0ds = 0x00000038, |
| 398 | .grp_b1ds = 0x00000038, |
| 399 | .grp_b2ds = 0x00000038, |
| 400 | .grp_b3ds = 0x00000038, |
| 401 | .grp_b4ds = 0x00000038, |
| 402 | .grp_b5ds = 0x00000038, |
| 403 | .grp_b6ds = 0x00000038, |
| 404 | .grp_b7ds = 0x00000038, |
| 405 | }; |
| 406 | |
| 407 | static const struct mx6_mmdc_calibration acc_mx6d_mmdc_calib = { |
| 408 | .p0_mpwldectrl0 = 0x0020001F, |
| 409 | .p0_mpwldectrl1 = 0x00280021, |
| 410 | .p1_mpwldectrl0 = 0x00120028, |
| 411 | .p1_mpwldectrl1 = 0x000D001F, |
| 412 | .p0_mpdgctrl0 = 0x43340342, |
| 413 | .p0_mpdgctrl1 = 0x03300325, |
| 414 | .p1_mpdgctrl0 = 0x4334033E, |
| 415 | .p1_mpdgctrl1 = 0x03280270, |
| 416 | .p0_mprddlctl = 0x46373B3E, |
| 417 | .p1_mprddlctl = 0x3B383544, |
| 418 | .p0_mpwrdlctl = 0x36383E40, |
| 419 | .p1_mpwrdlctl = 0x4030433A, |
| 420 | }; |
| 421 | |
| 422 | /* Micron MT41K128M16JT-125 (standard - 1600,CL=11) |
| 423 | * !!! i.MX6 does NOT support data rates higher than DDR3-1066 !!! |
| 424 | * So this setting is actually invalid! |
| 425 | * |
| 426 | static const struct mx6_ddr3_cfg acc_mx6d_mem_ddr3_1600 = { |
| 427 | .mem_speed = 1600, |
| 428 | .density = 2, |
| 429 | .width = 16, |
| 430 | .banks = 8, |
| 431 | .rowaddr = 14, |
| 432 | .coladdr = 10, |
| 433 | .pagesz = 2, |
| 434 | .trcd = 1375, |
| 435 | .trcmin = 4875, |
| 436 | .trasmin = 3500, |
| 437 | .SRT = 0, |
| 438 | }; |
| 439 | */ |
| 440 | |
| 441 | /* Micron MT41K128M16JT-125 is backward-compatible with 1333,CL=9 (-15E) and 1066,CL=7 (-187E) |
| 442 | * Lowering to 1066 saves on ACC ~0.25 Watt at DC In with negligible performance loss |
| 443 | * width set to 64, as four chips are used on acc (4 * 16 = 64) |
| 444 | */ |
| 445 | static const struct mx6_ddr3_cfg acc_mx6d_mem_ddr3_1066 = { |
| 446 | .mem_speed = 1066, |
| 447 | .density = 2, |
| 448 | .width = 64, |
| 449 | .banks = 8, |
| 450 | .rowaddr = 14, |
| 451 | .coladdr = 10, |
| 452 | .pagesz = 2, |
| 453 | .trcd = 1313, // 13.125ns |
| 454 | .trcmin = 5063, // 50.625ns |
| 455 | .trasmin = 3750, // 37.5ns |
| 456 | .SRT = 0, // Set to 1 for temperatures above 85°C |
| 457 | }; |
| 458 | |
| 459 | static const struct mx6_ddr_sysinfo acc_mx6d_ddr_info = { |
| 460 | .ddr_type = DDR_TYPE_DDR3, |
| 461 | /* width of data bus:0=16,1=32,2=64 */ |
| 462 | .dsize = 2, |
| 463 | .cs_density = 32, /* 32Gb per CS */ |
| 464 | .ncs = 1, /* single chip select */ |
| 465 | .cs1_mirror = 0, |
| 466 | .rtt_wr = 1, /* DDR3_RTT_60_OHM, RTT_Wr = RZQ/4 */ |
| 467 | .rtt_nom = 1, /* DDR3_RTT_60_OHM, RTT_Nom = RZQ/4 */ |
| 468 | .walat = 0, /* Write additional latency */ |
| 469 | .ralat = 5, /* Read additional latency */ |
| 470 | .mif3_mode = 3, /* Command prediction working mode */ |
| 471 | .bi_on = 1, /* Bank interleaving enabled */ |
| 472 | .sde_to_rst = 0x33, /* 14 cycles, 200us (JEDEC default) */ |
| 473 | .rst_to_cke = 0x33, /* 33 cycles, 500us (JEDEC default) */ |
| 474 | }; |
| 475 | |
| 476 | #define ACC_SPREAD_SPECTRUM_STOP 0x0fa |
| 477 | #define ACC_SPREAD_SPECTRUM_STEP 0x001 |
| 478 | #define ACC_SPREAD_SPECTRUM_DENOM 0x190 |
| 479 | |
| 480 | static void ccgr_init(void) |
| 481 | { |
| 482 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 483 | |
| 484 | /* Turn clocks on/off */ |
| 485 | writel(0x00C0000F, &ccm->CCGR0); |
| 486 | writel(0x0030FC00, &ccm->CCGR1); |
| 487 | writel(0x03FF0033, &ccm->CCGR2); |
| 488 | writel(0x3FF3300F, &ccm->CCGR3); |
| 489 | writel(0x0003C300, &ccm->CCGR4); |
| 490 | writel(0x0F3000C3, &ccm->CCGR5); |
| 491 | writel(0x00000FFF, &ccm->CCGR6); |
| 492 | |
| 493 | /* Enable spread spectrum */ |
| 494 | writel(BM_ANADIG_PLL_528_SS_ENABLE | |
| 495 | BF_ANADIG_PLL_528_SS_STOP(ACC_SPREAD_SPECTRUM_STOP) | |
| 496 | BF_ANADIG_PLL_528_SS_STEP(ACC_SPREAD_SPECTRUM_STEP), |
| 497 | &ccm->analog_pll_528_ss); |
| 498 | |
| 499 | writel(BF_ANADIG_PLL_528_DENOM_B(ACC_SPREAD_SPECTRUM_DENOM), |
| 500 | &ccm->analog_pll_528_denom); |
| 501 | } |
| 502 | |
| 503 | /* MMC board initialization is needed till adding DM support in SPL */ |
| 504 | #if IS_ENABLED(CONFIG_FSL_ESDHC_IMX) && !IS_ENABLED(CONFIG_DM_MMC) |
| 505 | #include <mmc.h> |
| 506 | #include <fsl_esdhc_imx.h> |
| 507 | |
| 508 | static const iomux_v3_cfg_t usdhc2_pads[] = { |
| 509 | IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(0x00017069)), |
| 510 | IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(0x00010038)), |
| 511 | IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(0x00017069)), |
| 512 | IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(0x00017069)), |
| 513 | IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(0x00017069)), |
| 514 | IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(0x00017069)), |
| 515 | IOMUX_PADS(PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(0x0001B0B0)), /* CD */ |
| 516 | }; |
| 517 | |
| 518 | static const iomux_v3_cfg_t usdhc4_pads[] = { |
| 519 | IOMUX_PADS(PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(0x00017059)), |
| 520 | IOMUX_PADS(PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(0x00010059)), |
| 521 | IOMUX_PADS(PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(0x00017059)), |
| 522 | IOMUX_PADS(PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(0x00017059)), |
| 523 | IOMUX_PADS(PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(0x00017059)), |
| 524 | IOMUX_PADS(PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(0x00017059)), |
| 525 | IOMUX_PADS(PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(0x00017059)), |
| 526 | IOMUX_PADS(PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(0x00017059)), |
| 527 | IOMUX_PADS(PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(0x00017059)), |
| 528 | IOMUX_PADS(PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(0x00017059)), |
| 529 | }; |
| 530 | |
| 531 | struct fsl_esdhc_cfg usdhc_cfg[2] = { |
| 532 | {USDHC2_BASE_ADDR, 1, 4}, |
| 533 | {USDHC4_BASE_ADDR, 1, 8}, |
| 534 | }; |
| 535 | |
| 536 | #define USDHC2_CD_GPIO IMX_GPIO_NR(1, 4) |
| 537 | |
| 538 | int board_mmc_getcd(struct mmc *mmc) |
| 539 | { |
| 540 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 541 | int ret = 0; |
| 542 | |
| 543 | detect_board(); |
| 544 | |
| 545 | switch (cfg->esdhc_base) { |
| 546 | case USDHC2_BASE_ADDR: |
| 547 | return !gpio_get_value(USDHC2_CD_GPIO); |
| 548 | case USDHC4_BASE_ADDR: |
| 549 | return 1; /* eMMC always present */ |
| 550 | } |
| 551 | |
| 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | int board_mmc_init(struct bd_info *bis) |
| 556 | { |
| 557 | int i, ret; |
| 558 | |
| 559 | gpio_direction_input(USDHC2_CD_GPIO); |
| 560 | /* |
| 561 | * According to the board_mmc_init() the following map is done: |
| 562 | * (U-boot device node) (Physical Port) |
| 563 | * mmc0 USDHC2 |
| 564 | * mmc1 USDHC4 |
| 565 | */ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 566 | for (i = 0; i < CFG_SYS_FSL_USDHC_NUM; i++) { |
Philip Oberfichtner | 9d680d1 | 2022-05-19 13:52:48 +0200 | [diff] [blame] | 567 | switch (i) { |
| 568 | case 0: |
| 569 | SETUP_IOMUX_PADS(usdhc2_pads); |
| 570 | usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 571 | break; |
| 572 | case 1: |
| 573 | SETUP_IOMUX_PADS(usdhc4_pads); |
| 574 | usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK); |
| 575 | break; |
| 576 | default: |
| 577 | printf("Warning - USDHC%d controller not supporting\n", |
| 578 | i + 1); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]); |
| 583 | if (ret) { |
| 584 | printf("Warning: failed to initialize mmc dev %d\n", i); |
| 585 | return ret; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | #endif |
| 592 | |
| 593 | void board_boot_order(u32 *spl_boot_list) |
| 594 | { |
| 595 | u32 bmode = imx6_src_get_boot_mode(); |
| 596 | u8 boot_dev = BOOT_DEVICE_MMC1; |
| 597 | |
| 598 | detect_board(); |
| 599 | |
| 600 | switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { |
| 601 | case IMX6_BMODE_SD: |
| 602 | case IMX6_BMODE_ESD: |
| 603 | /* SD/eSD - BOOT_DEVICE_MMC1 */ |
| 604 | if (IS_ENABLED(CONFIG_SYS_BOOT_EMMC)) { |
| 605 | /* |
| 606 | * boot from SD is not allowed, if boot from eMMC is |
| 607 | * configured. |
| 608 | */ |
| 609 | puts("SD boot not allowed\n"); |
| 610 | spl_boot_list[0] = BOOT_DEVICE_NONE; |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | boot_dev = BOOT_DEVICE_MMC1; |
| 615 | break; |
| 616 | |
| 617 | case IMX6_BMODE_MMC: |
| 618 | case IMX6_BMODE_EMMC: |
| 619 | /* MMC/eMMC */ |
| 620 | boot_dev = BOOT_DEVICE_MMC2; |
| 621 | break; |
| 622 | default: |
| 623 | /* Default - BOOT_DEVICE_MMC1 */ |
| 624 | printf("Wrong board boot order\n"); |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | spl_boot_list[0] = boot_dev; |
| 629 | } |
| 630 | |
| 631 | static void setup_ddr(void) |
| 632 | { |
| 633 | struct board_info *binfo = detect_board(); |
| 634 | |
| 635 | switch (binfo->rev) { |
| 636 | case PFID_REV_20: |
| 637 | case PFID_REV_21: |
| 638 | case PFID_REV_22: |
| 639 | default: |
| 640 | /* Rev 2 board has i.MX6 Dual with 64-bit RAM */ |
| 641 | mx6dq_dram_iocfg(acc_mx6d_mem_ddr3_1066.width, |
| 642 | &acc_mx6d_ddr_ioregs, |
| 643 | &acc_mx6d_grp_ioregs); |
| 644 | mx6_dram_cfg(&acc_mx6d_ddr_info, &acc_mx6d_mmdc_calib, |
| 645 | &acc_mx6d_mem_ddr3_1066); |
| 646 | /* Perform DDR DRAM calibration */ |
| 647 | udelay(100); |
| 648 | mmdc_do_write_level_calibration(&acc_mx6d_ddr_info); |
| 649 | mmdc_do_dqs_calibration(&acc_mx6d_ddr_info); |
| 650 | break; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | void board_init_f(ulong dummy) |
| 655 | { |
| 656 | /* setup AIPS and disable watchdog power-down counter (only enabled after reset) */ |
| 657 | arch_cpu_init(); |
| 658 | |
| 659 | ccgr_init(); |
| 660 | gpr_init(); |
| 661 | |
| 662 | /* setup GP timer */ |
| 663 | timer_init(); |
| 664 | |
| 665 | /* Enable device tree and early DM support*/ |
| 666 | spl_early_init(); |
| 667 | |
| 668 | /* Setup early required pinmuxes */ |
| 669 | setup_iomux_early(); |
| 670 | set_early_gpio(); |
| 671 | |
| 672 | /* Setup UART pinmux */ |
| 673 | setup_iomux_uart(); |
| 674 | |
| 675 | /* UART clocks enabled and gd valid - init serial console */ |
| 676 | preloader_console_init(); |
| 677 | |
| 678 | setup_ddr(); |
| 679 | |
| 680 | /* Clear the BSS. */ |
| 681 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 682 | |
| 683 | /* load/boot image from boot device */ |
| 684 | board_init_r(NULL, 0); |
| 685 | } |
| 686 | #endif |
| 687 | |
| 688 | #if IS_ENABLED(CONFIG_USB_EHCI_MX6) |
| 689 | #define USB_OTHERREGS_OFFSET 0x800 |
| 690 | #define UCTRL_PWR_POL BIT(9) |
| 691 | |
| 692 | int board_usb_phy_mode(int port) |
| 693 | { |
| 694 | if (port == 1) |
| 695 | return USB_INIT_HOST; |
| 696 | else |
| 697 | return usb_phy_mode(port); |
| 698 | } |
| 699 | |
| 700 | int board_ehci_hcd_init(int port) |
| 701 | { |
| 702 | u32 *usbnc_usb_ctrl; |
| 703 | |
| 704 | if (port > 1) |
| 705 | return -EINVAL; |
| 706 | |
| 707 | usbnc_usb_ctrl = (u32 *)(USB_BASE_ADDR + USB_OTHERREGS_OFFSET + |
| 708 | port * 4); |
| 709 | |
| 710 | /* Set Power polarity */ |
| 711 | setbits_le32(usbnc_usb_ctrl, UCTRL_PWR_POL); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | #endif |
| 716 | |
| 717 | int board_fit_config_name_match(const char *name) |
| 718 | { |
| 719 | if (!strcmp(name, "imx6q-bosch-acc")) |
| 720 | return 0; |
| 721 | return -1; |
| 722 | } |
| 723 | |
Tom Rini | e3b3264 | 2023-03-09 11:22:07 -0500 | [diff] [blame] | 724 | void reset_cpu(void) |
Philip Oberfichtner | 9d680d1 | 2022-05-19 13:52:48 +0200 | [diff] [blame] | 725 | { |
| 726 | puts("Hanging CPU for watchdog reset!\n"); |
| 727 | hang(); |
| 728 | } |
| 729 | |
| 730 | #if CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS) |
| 731 | void show_boot_progress(int val) |
| 732 | { |
| 733 | u32 fuseval; |
| 734 | int ret; |
| 735 | |
| 736 | if (val < 0) |
| 737 | val *= -1; |
| 738 | |
| 739 | switch (val) { |
| 740 | case BOOTSTAGE_ID_ENTER_CLI_LOOP: |
| 741 | printf("autoboot failed, check fuse\n"); |
| 742 | ret = fuse_read(0, 6, &fuseval); |
| 743 | if (ret == 0 && (fuseval & 0x2) == 0x0) { |
| 744 | printf("Enter cmdline, as device not closed\n"); |
| 745 | return; |
| 746 | } |
| 747 | ret = fuse_read(5, 7, &fuseval); |
| 748 | if (ret == 0 && fuseval == 0x0) { |
| 749 | printf("Enter cmdline, as it is a Development device\n"); |
| 750 | return; |
| 751 | } |
| 752 | panic("do not enter cmdline"); |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | #endif |