1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
7 * Copyright (C) 2012 Freescale Semiconductor, Inc.
9 * Author: Fabio Estevam <fabio.estevam@freescale.com>
12 #include <bmp_layout.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/imx-regs.h>
18 #include <asm/arch/iomux.h>
19 #include <asm/arch/mx6-pins.h>
20 #include <asm/global_data.h>
21 #include <linux/errno.h>
23 #include <asm/mach-imx/iomux-v3.h>
24 #include <asm/mach-imx/boot_mode.h>
25 #include <asm/mach-imx/video.h>
26 #include <asm/arch/crm_regs.h>
28 #include <asm/arch/sys_proto.h>
29 #include <asm/sections.h>
33 #include <i2c_eeprom.h>
38 #include <power/pmic.h>
39 #include <power/regulator.h>
40 #include <power/da9063_pmic.h>
44 DECLARE_GLOBAL_DATA_PTR;
51 #define ARI_BT_4 "aristainetos2_4@2"
52 #define ARI_BT_7 "aristainetos2_7@1"
54 int board_phy_config(struct phy_device *phydev)
56 /* control data pad skew - devaddr = 0x02, register = 0x04 */
57 ksz9031_phy_extended_write(phydev, 0x02,
58 MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
59 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
60 /* rx data pad skew - devaddr = 0x02, register = 0x05 */
61 ksz9031_phy_extended_write(phydev, 0x02,
62 MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
63 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
64 /* tx data pad skew - devaddr = 0x02, register = 0x06 */
65 ksz9031_phy_extended_write(phydev, 0x02,
66 MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
67 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
68 /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */
69 ksz9031_phy_extended_write(phydev, 0x02,
70 MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
71 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF);
73 if (phydev->drv->config)
74 phydev->drv->config(phydev);
79 static int rotate_logo_one(unsigned char *out, unsigned char *in)
83 for (i = 0; i < BMP_LOGO_WIDTH; i++)
84 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
85 out[j * BMP_LOGO_WIDTH + BMP_LOGO_HEIGHT - 1 - i] =
86 in[i * BMP_LOGO_WIDTH + j];
91 * Rotate the BMP_LOGO (only)
92 * Will only work, if the logo is square, as
93 * BMP_LOGO_HEIGHT and BMP_LOGO_WIDTH are defines, not variables
95 void rotate_logo(int rotations)
97 unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT];
98 struct bmp_header *header;
99 unsigned char *in_logo;
102 if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT)
105 header = (struct bmp_header *)bmp_logo_bitmap;
106 in_logo = bmp_logo_bitmap + header->data_offset;
108 /* one 90 degree rotation */
109 if (rotations == 1 || rotations == 2 || rotations == 3)
110 rotate_logo_one(out_logo, in_logo);
112 /* second 90 degree rotation */
113 if (rotations == 2 || rotations == 3)
114 rotate_logo_one(in_logo, out_logo);
116 /* third 90 degree rotation */
118 rotate_logo_one(out_logo, in_logo);
120 /* copy result back to original array */
121 if (rotations == 1 || rotations == 3)
122 for (i = 0; i < BMP_LOGO_WIDTH; i++)
123 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
124 in_logo[i * BMP_LOGO_WIDTH + j] =
125 out_logo[i * BMP_LOGO_WIDTH + j];
128 static void enable_lvds(struct display_info_t const *dev)
130 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
131 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
133 s32 timeout = 100000;
136 reg = readl(&ccm->analog_pll_video);
137 reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN;
138 writel(reg, &ccm->analog_pll_video);
140 /* set PLL5 to 232720000Hz */
141 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
142 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x26);
143 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
144 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
145 writel(reg, &ccm->analog_pll_video);
147 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xC0238),
148 &ccm->analog_pll_video_num);
149 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xF4240),
150 &ccm->analog_pll_video_denom);
152 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
153 writel(reg, &ccm->analog_pll_video);
156 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
159 printf("Warning: video pll lock timeout!\n");
161 reg = readl(&ccm->analog_pll_video);
162 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
163 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
164 writel(reg, &ccm->analog_pll_video);
166 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
167 reg = readl(&ccm->cs2cdr);
168 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
169 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
170 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
171 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
172 writel(reg, &ccm->cs2cdr);
174 reg = readl(&ccm->cscmr2);
175 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
176 writel(reg, &ccm->cscmr2);
178 reg = readl(&ccm->chsccdr);
179 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
180 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
181 writel(reg, &ccm->chsccdr);
183 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
184 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
185 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
186 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
187 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
188 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
189 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
190 writel(reg, &iomux->gpr[2]);
192 reg = readl(&iomux->gpr[3]);
193 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
194 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
195 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
196 writel(reg, &iomux->gpr[3]);
199 static void setup_display(void)
204 static void set_gpr_register(void)
206 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
208 writel(IOMUXC_GPR1_APP_CLK_REQ_N | IOMUXC_GPR1_PCIE_RDY_L23 |
209 IOMUXC_GPR1_EXC_MON_SLVE |
210 (2 << IOMUXC_GPR1_ADDRS0_OFFSET) |
212 &iomuxc_regs->gpr[1]);
213 writel(0x0, &iomuxc_regs->gpr[8]);
214 writel(IOMUXC_GPR12_ARMP_IPG_CLK_EN | IOMUXC_GPR12_ARMP_AHB_CLK_EN |
215 IOMUXC_GPR12_ARMP_ATB_CLK_EN | IOMUXC_GPR12_ARMP_APB_CLK_EN,
216 &iomuxc_regs->gpr[12]);
219 int board_early_init_f(void)
221 select_ldb_di_clock_source(MXC_PLL5_CLK);
225 * clear bss here, so we can use spi driver
226 * before relocation and read Environment
229 memset(__bss_start, 0x00, __bss_end - __bss_start);
234 static void setup_one_led(char *label, int state)
239 ret = led_get_by_label(label, &dev);
241 led_set_state(dev, state);
244 static void setup_board_gpio(void)
246 setup_one_led("led_ena", LEDST_ON);
247 /* switch off Status LEDs */
248 setup_one_led("led_yellow", LEDST_OFF);
249 setup_one_led("led_red", LEDST_OFF);
250 setup_one_led("led_green", LEDST_OFF);
251 setup_one_led("led_blue", LEDST_OFF);
254 static void aristainetos_run_rescue_command(int reason)
256 char rescue_reason_command[20];
258 sprintf(rescue_reason_command, "setenv rreason %d", reason);
259 run_command(rescue_reason_command, 0);
262 static int aristainetos_bootmode_settings(void)
264 struct gpio_desc *desc;
265 struct src *psrc = (struct src *)SRC_BASE_ADDR;
266 unsigned int sbmr1 = readl(&psrc->sbmr1);
275 /* jumper controlled reset of the environment */
276 ret = gpio_hog_lookup_name("env_reset", &desc);
278 if (dm_gpio_get_value(desc)) {
279 printf("\nReset u-boot environment (jumper)\n");
280 run_command("run default_env; saveenv; saveenv", 0);
284 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
286 printf("%s: No eeprom0 path offset\n", __func__);
290 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
292 printf("%s: Could not find EEPROM\n", __func__);
296 ret = i2c_set_chip_offset_len(dev, 2);
300 ret = i2c_eeprom_read(dev, 0x1ff0, (uint8_t *)data, sizeof(data));
302 printf("%s: Could not read EEPROM\n", __func__);
306 /* software controlled reset of the environment (EEPROM magic) */
307 if (strncmp((char *)data, "DeF", 3) == 0) {
308 memset(data, 0xff, 3);
309 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)data, 3);
310 printf("\nReset u-boot environment (EEPROM)\n");
311 run_command("run default_env; saveenv; saveenv", 0);
315 env_set("bootmode", "1");
316 printf("SD bootmode jumper set!\n");
318 env_set("bootmode", "0");
322 * Check the boot-source. If booting from NOR Flash,
325 ret = gpio_hog_lookup_name("bootsel0", &desc);
327 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0;
328 ret = gpio_hog_lookup_name("bootsel1", &desc);
330 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1;
331 ret = gpio_hog_lookup_name("bootsel2", &desc);
333 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2;
336 my_bootdelay = env_get("nor_bootdelay");
338 env_set("bootdelay", my_bootdelay);
340 env_set("bootdelay", "-2");
343 /* jumper controlled boot of the rescue system */
344 ret = gpio_hog_lookup_name("boot_rescue", &desc);
346 if (dm_gpio_get_value(desc)) {
347 printf("\nBooting into Rescue System (jumper)\n");
348 aristainetos_run_rescue_command(16);
349 run_command("run rescue_xload_boot", 0);
353 /* software controlled boot of the rescue system (EEPROM magic) */
354 if (strncmp((char *)&data[3], "ReScUe", 6) == 0) {
355 rescue_reason = *(uint8_t *)&data[9];
356 memset(&data[3], 0xff, 7);
357 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)&data[3], 7);
358 printf("\nBooting into Rescue System (EEPROM)\n");
359 aristainetos_run_rescue_command(rescue_reason);
360 run_command("run rescue_xload_boot", 0);
366 #if defined(CONFIG_DM_PMIC_DA9063)
368 * On the aristainetos2c boards the PMIC needs to be initialized,
369 * because the Ethernet PHY uses a different regulator that is not
370 * setup per hardware default. This does not influence the other versions
371 * as this regulator isn't used there at all.
373 * Unfortunately we have not yet a interface to setup all
376 static int setup_pmic_voltages(void)
382 off = fdt_path_offset(gd->fdt_blob, "pmic0");
384 printf("%s: No pmic path offset\n", __func__);
388 ret = uclass_get_device_by_of_offset(UCLASS_PMIC, off, &dev);
390 printf("%s: Could not find PMIC\n", __func__);
394 pmic_reg_write(dev, DA9063_REG_PAGE_CON, 0x01);
395 pmic_reg_write(dev, DA9063_REG_BPRO_CFG, 0xc1);
396 ret = pmic_reg_read(dev, DA9063_REG_BUCK_ILIM_B);
398 printf("%s: error %d get register\n", __func__, ret);
403 pmic_reg_write(dev, DA9063_REG_BUCK_ILIM_B, ret);
404 pmic_reg_write(dev, DA9063_REG_VBPRO_A, 0x43);
405 pmic_reg_write(dev, DA9063_REG_VBPRO_B, 0xc3);
410 static int setup_pmic_voltages(void)
416 int board_late_init(void)
421 splash_get_pos(&x, &y);
422 bmp_display((ulong)&bmp_logo_bitmap[0], x, y);
424 ret = aristainetos_bootmode_settings();
429 if (gd->board_type == BOARD_TYPE_4)
430 env_set("board_type", ARI_BT_4);
432 env_set("board_type", ARI_BT_7);
434 if (setup_pmic_voltages())
435 printf("Error setup PMIC\n");
442 gd->ram_size = imx_ddr_size();
447 struct display_info_t const displays[] = {
451 .pixfmt = IPU_PIX_FMT_RGB24,
453 .enable = enable_lvds,
467 .vmode = FB_VMODE_NONINTERLACED
471 size_t display_count = ARRAY_SIZE(displays);
475 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
477 /* address of boot parameters */
478 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
483 /* GPIO_1 for USB_OTG_ID */
484 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
488 int board_fit_config_name_match(const char *name)
490 if (gd->board_type == BOARD_TYPE_4 &&
494 if (gd->board_type == BOARD_TYPE_7 &&
501 static void do_board_detect(void)
506 /* default use board type 7 */
507 gd->board_type = BOARD_TYPE_7;
511 ret = env_get_f("panel", s, sizeof(s));
515 if (!strncmp("lg4573", s, 6))
516 gd->board_type = BOARD_TYPE_4;
519 #ifdef CONFIG_DTB_RESELECT
520 int embedded_dtb_select(void)
525 fdtdec_resetup(&rescan);