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