Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 |
| 4 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 5 | * |
| 6 | * Based on: |
| 7 | * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 8 | * |
| 9 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/iomux.h> |
| 15 | #include <asm/arch/mx6-pins.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 16 | #include <linux/errno.h> |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 17 | #include <asm/gpio.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 18 | #include <asm/mach-imx/iomux-v3.h> |
| 19 | #include <asm/mach-imx/boot_mode.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 20 | #include <asm/mach-imx/video.h> |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 21 | #include <asm/arch/crm_regs.h> |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 22 | #include <asm/io.h> |
| 23 | #include <asm/arch/sys_proto.h> |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 24 | #include <bmp_logo.h> |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 25 | #include <dm/root.h> |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 26 | #include <env.h> |
Heiko Schocher | f7cf76f | 2019-12-01 11:23:23 +0100 | [diff] [blame] | 27 | #include <i2c_eeprom.h> |
| 28 | #include <i2c.h> |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 29 | #include <micrel.h> |
Heiko Schocher | 5e65496 | 2019-12-01 11:23:18 +0100 | [diff] [blame] | 30 | #include <miiphy.h> |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 31 | #include <lcd.h> |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 32 | #include <led.h> |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 33 | #include <splash.h> |
| 34 | #include <video_fb.h> |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 38 | enum { |
| 39 | BOARD_TYPE_4 = 4, |
| 40 | BOARD_TYPE_7 = 7, |
| 41 | }; |
| 42 | |
| 43 | #define ARI_BT_4 "aristainetos2_4@2" |
| 44 | #define ARI_BT_7 "aristainetos2_7@1" |
| 45 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 46 | int board_phy_config(struct phy_device *phydev) |
| 47 | { |
| 48 | /* control data pad skew - devaddr = 0x02, register = 0x04 */ |
| 49 | ksz9031_phy_extended_write(phydev, 0x02, |
| 50 | MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, |
| 51 | MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000); |
| 52 | /* rx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 53 | ksz9031_phy_extended_write(phydev, 0x02, |
| 54 | MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, |
| 55 | MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000); |
| 56 | /* tx data pad skew - devaddr = 0x02, register = 0x06 */ |
| 57 | ksz9031_phy_extended_write(phydev, 0x02, |
| 58 | MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, |
| 59 | MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000); |
| 60 | /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */ |
| 61 | ksz9031_phy_extended_write(phydev, 0x02, |
| 62 | MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, |
| 63 | MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF); |
| 64 | |
| 65 | if (phydev->drv->config) |
| 66 | phydev->drv->config(phydev); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 71 | static int rotate_logo_one(unsigned char *out, unsigned char *in) |
| 72 | { |
| 73 | int i, j; |
| 74 | |
| 75 | for (i = 0; i < BMP_LOGO_WIDTH; i++) |
| 76 | for (j = 0; j < BMP_LOGO_HEIGHT; j++) |
| 77 | out[j * BMP_LOGO_WIDTH + BMP_LOGO_HEIGHT - 1 - i] = |
| 78 | in[i * BMP_LOGO_WIDTH + j]; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Rotate the BMP_LOGO (only) |
| 84 | * Will only work, if the logo is square, as |
| 85 | * BMP_LOGO_HEIGHT and BMP_LOGO_WIDTH are defines, not variables |
| 86 | */ |
| 87 | void rotate_logo(int rotations) |
| 88 | { |
| 89 | unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT]; |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 90 | struct bmp_header *header; |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 91 | unsigned char *in_logo; |
| 92 | int i, j; |
| 93 | |
| 94 | if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT) |
| 95 | return; |
| 96 | |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 97 | header = (struct bmp_header *)bmp_logo_bitmap; |
| 98 | in_logo = bmp_logo_bitmap + header->data_offset; |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 99 | |
| 100 | /* one 90 degree rotation */ |
| 101 | if (rotations == 1 || rotations == 2 || rotations == 3) |
| 102 | rotate_logo_one(out_logo, in_logo); |
| 103 | |
| 104 | /* second 90 degree rotation */ |
| 105 | if (rotations == 2 || rotations == 3) |
| 106 | rotate_logo_one(in_logo, out_logo); |
| 107 | |
| 108 | /* third 90 degree rotation */ |
| 109 | if (rotations == 3) |
| 110 | rotate_logo_one(out_logo, in_logo); |
| 111 | |
| 112 | /* copy result back to original array */ |
| 113 | if (rotations == 1 || rotations == 3) |
| 114 | for (i = 0; i < BMP_LOGO_WIDTH; i++) |
| 115 | for (j = 0; j < BMP_LOGO_HEIGHT; j++) |
| 116 | in_logo[i * BMP_LOGO_WIDTH + j] = |
| 117 | out_logo[i * BMP_LOGO_WIDTH + j]; |
| 118 | } |
| 119 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 120 | static void enable_lvds(struct display_info_t const *dev) |
| 121 | { |
| 122 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 123 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 124 | int reg; |
| 125 | s32 timeout = 100000; |
| 126 | |
| 127 | /* set PLL5 clock */ |
| 128 | reg = readl(&ccm->analog_pll_video); |
| 129 | reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 130 | writel(reg, &ccm->analog_pll_video); |
| 131 | |
| 132 | /* set PLL5 to 232720000Hz */ |
| 133 | reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT; |
| 134 | reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x26); |
| 135 | reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT; |
| 136 | reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0); |
| 137 | writel(reg, &ccm->analog_pll_video); |
| 138 | |
| 139 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xC0238), |
| 140 | &ccm->analog_pll_video_num); |
| 141 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xF4240), |
| 142 | &ccm->analog_pll_video_denom); |
| 143 | |
| 144 | reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 145 | writel(reg, &ccm->analog_pll_video); |
| 146 | |
| 147 | while (timeout--) |
| 148 | if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK) |
| 149 | break; |
| 150 | if (timeout < 0) |
| 151 | printf("Warning: video pll lock timeout!\n"); |
| 152 | |
| 153 | reg = readl(&ccm->analog_pll_video); |
| 154 | reg |= BM_ANADIG_PLL_VIDEO_ENABLE; |
| 155 | reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS; |
| 156 | writel(reg, &ccm->analog_pll_video); |
| 157 | |
| 158 | /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */ |
| 159 | reg = readl(&ccm->cs2cdr); |
| 160 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
| 161 | | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK); |
| 162 | reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
| 163 | | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET); |
| 164 | writel(reg, &ccm->cs2cdr); |
| 165 | |
| 166 | reg = readl(&ccm->cscmr2); |
| 167 | reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV; |
| 168 | writel(reg, &ccm->cscmr2); |
| 169 | |
| 170 | reg = readl(&ccm->chsccdr); |
| 171 | reg |= (CHSCCDR_CLK_SEL_LDB_DI0 |
| 172 | << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
| 173 | writel(reg, &ccm->chsccdr); |
| 174 | |
| 175 | reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
| 176 | | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH |
| 177 | | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH |
| 178 | | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
| 179 | | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
| 180 | | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED |
| 181 | | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0; |
| 182 | writel(reg, &iomux->gpr[2]); |
| 183 | |
| 184 | reg = readl(&iomux->gpr[3]); |
| 185 | reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK) |
| 186 | | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 |
| 187 | << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET); |
| 188 | writel(reg, &iomux->gpr[3]); |
| 189 | } |
| 190 | |
| 191 | static void enable_spi_display(struct display_info_t const *dev) |
| 192 | { |
| 193 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 194 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 195 | int reg; |
| 196 | s32 timeout = 100000; |
| 197 | |
| 198 | #if defined(CONFIG_VIDEO_BMP_LOGO) |
| 199 | rotate_logo(3); /* portrait display in landscape mode */ |
| 200 | #endif |
| 201 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 202 | reg = readl(&ccm->cs2cdr); |
| 203 | |
| 204 | /* select pll 5 clock */ |
| 205 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
| 206 | | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK); |
| 207 | writel(reg, &ccm->cs2cdr); |
| 208 | |
| 209 | /* set PLL5 to 197994996Hz */ |
| 210 | reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT; |
| 211 | reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x21); |
| 212 | reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT; |
| 213 | reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0); |
| 214 | writel(reg, &ccm->analog_pll_video); |
| 215 | |
| 216 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xfbf4), |
| 217 | &ccm->analog_pll_video_num); |
| 218 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xf4240), |
| 219 | &ccm->analog_pll_video_denom); |
| 220 | |
| 221 | reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 222 | writel(reg, &ccm->analog_pll_video); |
| 223 | |
| 224 | while (timeout--) |
| 225 | if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK) |
| 226 | break; |
| 227 | if (timeout < 0) |
| 228 | printf("Warning: video pll lock timeout!\n"); |
| 229 | |
| 230 | reg = readl(&ccm->analog_pll_video); |
| 231 | reg |= BM_ANADIG_PLL_VIDEO_ENABLE; |
| 232 | reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS; |
| 233 | writel(reg, &ccm->analog_pll_video); |
| 234 | |
| 235 | /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */ |
| 236 | reg = readl(&ccm->cs2cdr); |
| 237 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
| 238 | | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK); |
| 239 | reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
| 240 | | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET); |
| 241 | writel(reg, &ccm->cs2cdr); |
| 242 | |
| 243 | reg = readl(&ccm->cscmr2); |
| 244 | reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV; |
| 245 | writel(reg, &ccm->cscmr2); |
| 246 | |
| 247 | reg = readl(&ccm->chsccdr); |
| 248 | reg |= (CHSCCDR_CLK_SEL_LDB_DI0 |
| 249 | << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
| 250 | reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK; |
| 251 | reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET); |
| 252 | reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK; |
| 253 | reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET); |
| 254 | writel(reg, &ccm->chsccdr); |
| 255 | |
| 256 | reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
| 257 | | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH |
| 258 | | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH |
| 259 | | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
| 260 | | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
| 261 | | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED |
| 262 | | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0; |
| 263 | writel(reg, &iomux->gpr[2]); |
| 264 | |
| 265 | reg = readl(&iomux->gpr[3]); |
| 266 | reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK) |
| 267 | | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 |
| 268 | << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET); |
| 269 | writel(reg, &iomux->gpr[3]); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void setup_display(void) |
| 273 | { |
| 274 | enable_ipu_clock(); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 277 | static void set_gpr_register(void) |
| 278 | { |
| 279 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 280 | |
| 281 | writel(IOMUXC_GPR1_APP_CLK_REQ_N | IOMUXC_GPR1_PCIE_RDY_L23 | |
| 282 | IOMUXC_GPR1_EXC_MON_SLVE | |
| 283 | (2 << IOMUXC_GPR1_ADDRS0_OFFSET) | |
| 284 | IOMUXC_GPR1_ACT_CS0, |
| 285 | &iomuxc_regs->gpr[1]); |
| 286 | writel(0x0, &iomuxc_regs->gpr[8]); |
| 287 | writel(IOMUXC_GPR12_ARMP_IPG_CLK_EN | IOMUXC_GPR12_ARMP_AHB_CLK_EN | |
| 288 | IOMUXC_GPR12_ARMP_ATB_CLK_EN | IOMUXC_GPR12_ARMP_APB_CLK_EN, |
| 289 | &iomuxc_regs->gpr[12]); |
| 290 | } |
| 291 | |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 292 | extern char __bss_start[], __bss_end[]; |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 293 | int board_early_init_f(void) |
| 294 | { |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 295 | select_ldb_di_clock_source(MXC_PLL5_CLK); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 296 | set_gpr_register(); |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * clear bss here, so we can use spi driver |
| 300 | * before relocation and read Environment |
| 301 | * from spi flash. |
| 302 | */ |
| 303 | memset(__bss_start, 0x00, __bss_end - __bss_start); |
| 304 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 308 | static void setup_one_led(char *label, int state) |
| 309 | { |
| 310 | struct udevice *dev; |
| 311 | int ret; |
| 312 | |
| 313 | ret = led_get_by_label(label, &dev); |
| 314 | if (ret == 0) |
| 315 | led_set_state(dev, state); |
| 316 | } |
| 317 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 318 | static void setup_board_gpio(void) |
| 319 | { |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 320 | setup_one_led("led_ena", LEDST_ON); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 321 | /* switch off Status LEDs */ |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 322 | setup_one_led("led_yellow", LEDST_OFF); |
| 323 | setup_one_led("led_red", LEDST_OFF); |
| 324 | setup_one_led("led_green", LEDST_OFF); |
| 325 | setup_one_led("led_blue", LEDST_OFF); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Heiko Schocher | f7cf76f | 2019-12-01 11:23:23 +0100 | [diff] [blame] | 328 | #define ARI_RESC_FMT "setenv rescue_reason setenv bootargs \\${bootargs}" \ |
| 329 | " rescueReason=%d " |
| 330 | |
| 331 | static void aristainetos_run_rescue_command(int reason) |
| 332 | { |
| 333 | char rescue_reason_command[80]; |
| 334 | |
| 335 | sprintf(rescue_reason_command, ARI_RESC_FMT, reason); |
| 336 | run_command(rescue_reason_command, 0); |
| 337 | } |
| 338 | |
| 339 | static int aristainetos_eeprom(void) |
| 340 | { |
| 341 | struct udevice *dev; |
| 342 | int off; |
| 343 | int ret; |
| 344 | u8 data[0x10]; |
| 345 | u8 rescue_reason; |
| 346 | |
| 347 | off = fdt_path_offset(gd->fdt_blob, "eeprom0"); |
| 348 | if (off < 0) { |
| 349 | printf("%s: No eeprom0 path offset\n", __func__); |
| 350 | return off; |
| 351 | } |
| 352 | |
| 353 | ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev); |
| 354 | if (ret) { |
| 355 | printf("%s: Could not find EEPROM\n", __func__); |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | ret = i2c_set_chip_offset_len(dev, 2); |
| 360 | if (ret) |
| 361 | return ret; |
| 362 | |
| 363 | ret = i2c_eeprom_read(dev, 0x1ff0, (uint8_t *)data, 6); |
| 364 | if (ret) { |
| 365 | printf("%s: Could not read EEPROM\n", __func__); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | if (strncmp((char *)&data[3], "ReScUe", 6) == 0) { |
| 370 | rescue_reason = *(uint8_t *)&data[9]; |
| 371 | memset(&data[3], 0xff, 7); |
| 372 | i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)&data[3], 7); |
| 373 | printf("\nBooting into Rescue System (EEPROM)\n"); |
| 374 | aristainetos_run_rescue_command(rescue_reason); |
| 375 | run_command("run rescue_load_fit rescueboot", 0); |
| 376 | } else if (strncmp((char *)data, "DeF", 3) == 0) { |
| 377 | memset(data, 0xff, 3); |
| 378 | i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)data, 3); |
| 379 | printf("\nClear u-boot environment (set back to defaults)\n"); |
| 380 | run_command("run default_env; saveenv; saveenv", 0); |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | }; |
| 385 | |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 386 | static void aristainetos_bootmode_settings(void) |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 387 | { |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 388 | struct gpio_desc *desc; |
| 389 | struct src *psrc = (struct src *)SRC_BASE_ADDR; |
| 390 | unsigned int sbmr1 = readl(&psrc->sbmr1); |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 391 | char *my_bootdelay; |
| 392 | char bootmode = 0; |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 393 | int ret; |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * Check the boot-source. If booting from NOR Flash, |
| 397 | * disable bootdelay |
| 398 | */ |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 399 | ret = gpio_hog_lookup_name("bootsel0", &desc); |
| 400 | if (!ret) |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 401 | bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0; |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 402 | ret = gpio_hog_lookup_name("bootsel1", &desc); |
| 403 | if (!ret) |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 404 | bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1; |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 405 | ret = gpio_hog_lookup_name("bootsel2", &desc); |
| 406 | if (!ret) |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 407 | bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2; |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 408 | |
| 409 | if (bootmode == 7) { |
| 410 | my_bootdelay = env_get("nor_bootdelay"); |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 411 | if (my_bootdelay) |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 412 | env_set("bootdelay", my_bootdelay); |
| 413 | else |
| 414 | env_set("bootdelay", "-2"); |
| 415 | } |
| 416 | |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 417 | if (sbmr1 & 0x40) { |
| 418 | env_set("bootmode", "1"); |
| 419 | printf("SD bootmode jumper set!\n"); |
| 420 | } else { |
| 421 | env_set("bootmode", "0"); |
| 422 | } |
| 423 | |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 424 | /* read out some jumper values*/ |
| 425 | ret = gpio_hog_lookup_name("env_reset", &desc); |
| 426 | if (!ret) { |
| 427 | if (dm_gpio_get_value(desc)) { |
| 428 | printf("\nClear env (set back to defaults)\n"); |
| 429 | run_command("run default_env; saveenv; saveenv", 0); |
| 430 | } |
| 431 | } |
| 432 | ret = gpio_hog_lookup_name("boot_rescue", &desc); |
| 433 | if (!ret) { |
| 434 | if (dm_gpio_get_value(desc)) { |
| 435 | aristainetos_run_rescue_command(16); |
| 436 | run_command("run rescue_xload_boot", 0); |
| 437 | } |
| 438 | } |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | int board_late_init(void) |
| 442 | { |
| 443 | int x, y; |
| 444 | |
| 445 | led_default_state(); |
| 446 | splash_get_pos(&x, &y); |
| 447 | bmp_display((ulong)&bmp_logo_bitmap[0], x, y); |
| 448 | |
| 449 | aristainetos_bootmode_settings(); |
Heiko Schocher | fc7e3cc | 2019-12-01 11:23:15 +0100 | [diff] [blame] | 450 | |
Heiko Schocher | f7cf76f | 2019-12-01 11:23:23 +0100 | [diff] [blame] | 451 | /* eeprom work */ |
| 452 | aristainetos_eeprom(); |
| 453 | |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 454 | /* set board_type */ |
| 455 | if (gd->board_type == BOARD_TYPE_4) |
| 456 | env_set("board_type", ARI_BT_4); |
| 457 | else |
| 458 | env_set("board_type", ARI_BT_7); |
Heiko Schocher | 0ed133a | 2019-12-01 11:23:26 +0100 | [diff] [blame] | 459 | |
Heiko Schocher | 0f1130b | 2019-12-01 11:23:11 +0100 | [diff] [blame] | 460 | return 0; |
| 461 | } |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 462 | |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 463 | int dram_init(void) |
Heiko Schocher | 2f6bb0a | 2014-10-30 13:14:03 +0100 | [diff] [blame] | 464 | { |
Fabio Estevam | 84c5168 | 2016-07-23 13:23:39 -0300 | [diff] [blame] | 465 | gd->ram_size = imx_ddr_size(); |
Heiko Schocher | 2f6bb0a | 2014-10-30 13:14:03 +0100 | [diff] [blame] | 466 | |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 467 | return 0; |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 470 | struct display_info_t const displays[] = { |
| 471 | { |
| 472 | .bus = -1, |
| 473 | .addr = 0, |
| 474 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 475 | .detect = NULL, |
| 476 | .enable = enable_lvds, |
| 477 | .mode = { |
| 478 | .name = "lb07wv8", |
| 479 | .refresh = 60, |
| 480 | .xres = 800, |
| 481 | .yres = 480, |
Heiko Schocher | d0d005b | 2015-08-11 08:09:44 +0200 | [diff] [blame] | 482 | .pixclock = 30066, |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 483 | .left_margin = 88, |
| 484 | .right_margin = 88, |
Heiko Schocher | d0d005b | 2015-08-11 08:09:44 +0200 | [diff] [blame] | 485 | .upper_margin = 20, |
| 486 | .lower_margin = 20, |
Heiko Schocher | b4b39a7 | 2015-01-20 10:06:18 +0100 | [diff] [blame] | 487 | .hsync_len = 80, |
Heiko Schocher | d0d005b | 2015-08-11 08:09:44 +0200 | [diff] [blame] | 488 | .vsync_len = 5, |
| 489 | .sync = FB_SYNC_EXT, |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 490 | .vmode = FB_VMODE_NONINTERLACED |
| 491 | } |
| 492 | } |
Heiko Schocher | 9627084 | 2015-08-24 11:36:40 +0200 | [diff] [blame] | 493 | #if ((CONFIG_SYS_BOARD_VERSION == 2) || (CONFIG_SYS_BOARD_VERSION == 3)) |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 494 | , { |
| 495 | .bus = -1, |
| 496 | .addr = 0, |
| 497 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 498 | .detect = NULL, |
| 499 | .enable = enable_spi_display, |
| 500 | .mode = { |
| 501 | .name = "lg4573", |
Heiko Schocher | d0d005b | 2015-08-11 08:09:44 +0200 | [diff] [blame] | 502 | .refresh = 57, |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 503 | .xres = 480, |
| 504 | .yres = 800, |
| 505 | .pixclock = 37037, |
| 506 | .left_margin = 59, |
| 507 | .right_margin = 10, |
| 508 | .upper_margin = 15, |
| 509 | .lower_margin = 15, |
| 510 | .hsync_len = 10, |
| 511 | .vsync_len = 15, |
| 512 | .sync = FB_SYNC_EXT | FB_SYNC_HOR_HIGH_ACT | |
| 513 | FB_SYNC_VERT_HIGH_ACT, |
| 514 | .vmode = FB_VMODE_NONINTERLACED |
| 515 | } |
| 516 | } |
| 517 | #endif |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 518 | }; |
| 519 | size_t display_count = ARRAY_SIZE(displays); |
| 520 | |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 521 | iomux_v3_cfg_t nfc_pads[] = { |
| 522 | MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 523 | MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 524 | MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 525 | MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 526 | MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 527 | MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 528 | MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 529 | MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 530 | MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 531 | MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 532 | MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 533 | MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 534 | MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 535 | MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 536 | MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 537 | MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 538 | }; |
| 539 | |
| 540 | static void setup_gpmi_nand(void) |
| 541 | { |
| 542 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 543 | |
| 544 | /* config gpmi nand iomux */ |
| 545 | imx_iomux_v3_setup_multiple_pads(nfc_pads, |
| 546 | ARRAY_SIZE(nfc_pads)); |
| 547 | |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 548 | /* gate ENFC_CLK_ROOT clock first,before clk source switch */ |
| 549 | clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
| 550 | |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 551 | /* config gpmi and bch clock to 100 MHz */ |
| 552 | clrsetbits_le32(&mxc_ccm->cs2cdr, |
| 553 | MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK | |
| 554 | MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK | |
| 555 | MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK, |
| 556 | MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) | |
| 557 | MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) | |
| 558 | MXC_CCM_CS2CDR_ENFC_CLK_SEL(3)); |
| 559 | |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 560 | /* enable ENFC_CLK_ROOT clock */ |
| 561 | setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
| 562 | |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 563 | /* enable gpmi and bch clock gating */ |
| 564 | setbits_le32(&mxc_ccm->CCGR4, |
| 565 | MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK | |
| 566 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK | |
| 567 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK | |
| 568 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK | |
| 569 | MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET); |
| 570 | |
| 571 | /* enable apbh clock gating */ |
| 572 | setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK); |
| 573 | } |
| 574 | |
| 575 | int board_init(void) |
| 576 | { |
| 577 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 578 | |
| 579 | /* address of boot parameters */ |
| 580 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 581 | |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 582 | setup_board_gpio(); |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 583 | setup_gpmi_nand(); |
Heiko Schocher | 621ff13 | 2019-12-01 11:23:19 +0100 | [diff] [blame] | 584 | setup_display(); |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 585 | |
| 586 | /* GPIO_1 for USB_OTG_ID */ |
Heiko Schocher | 7254d92 | 2015-05-18 13:32:31 +0200 | [diff] [blame] | 587 | clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0); |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Heiko Schocher | ccc7595 | 2019-12-01 11:23:12 +0100 | [diff] [blame] | 591 | int board_fit_config_name_match(const char *name) |
| 592 | { |
| 593 | if (gd->board_type == BOARD_TYPE_4 && |
| 594 | strchr(name, 0x34)) |
| 595 | return 0; |
| 596 | |
| 597 | if (gd->board_type == BOARD_TYPE_7 && |
| 598 | strchr(name, 0x37)) |
| 599 | return 0; |
| 600 | |
| 601 | return -1; |
| 602 | } |
| 603 | |
| 604 | static void do_board_detect(void) |
| 605 | { |
| 606 | int ret; |
| 607 | char s[30]; |
| 608 | |
| 609 | /* default use board type 7 */ |
| 610 | gd->board_type = BOARD_TYPE_7; |
| 611 | if (env_init()) |
| 612 | return; |
| 613 | |
| 614 | ret = env_get_f("panel", s, sizeof(s)); |
| 615 | if (ret < 0) |
| 616 | return; |
| 617 | |
| 618 | if (!strncmp("lg4573", s, 6)) |
| 619 | gd->board_type = BOARD_TYPE_4; |
| 620 | } |
| 621 | |
| 622 | #ifdef CONFIG_DTB_RESELECT |
| 623 | int embedded_dtb_select(void) |
| 624 | { |
| 625 | int rescan; |
| 626 | |
| 627 | do_board_detect(); |
| 628 | fdtdec_resetup(&rescan); |
| 629 | |
Heiko Schocher | e379c03 | 2014-07-18 06:07:22 +0200 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | #endif |