blob: 770f3d7d0d55964750c8b410e2128c5324a267ce [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherf853c6c2014-07-18 06:07:22 +02002/*
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 Schocherf853c6c2014-07-18 06:07:22 +020010 */
11
Simon Glassbcb87b62022-10-18 07:10:26 -060012#include <common.h>
13#include <bmp_layout.h>
Simon Glassed38aef2020-05-10 11:40:03 -060014#include <command.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060015#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060016#include <init.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020017#include <asm/arch/clock.h>
18#include <asm/arch/imx-regs.h>
19#include <asm/arch/iomux.h>
20#include <asm/arch/mx6-pins.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090022#include <linux/errno.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020023#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020024#include <asm/mach-imx/iomux-v3.h>
25#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020026#include <asm/mach-imx/video.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020027#include <asm/arch/crm_regs.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020028#include <asm/io.h>
29#include <asm/arch/sys_proto.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010030#include <bmp_logo.h>
Heiko Schocher54333792019-12-01 11:23:12 +010031#include <dm/root.h>
Heiko Schochera051ee92019-12-01 11:23:11 +010032#include <env.h>
Heiko Schocherab77bef2020-11-30 20:46:05 +010033#include <env_internal.h>
Heiko Schocherc6729682019-12-01 11:23:23 +010034#include <i2c_eeprom.h>
35#include <i2c.h>
Heiko Schochera051ee92019-12-01 11:23:11 +010036#include <micrel.h>
Heiko Schocher441b0542019-12-01 11:23:18 +010037#include <miiphy.h>
Heiko Schocher495956b2019-12-01 11:23:15 +010038#include <led.h>
Heiko Schocherf5210a92020-03-02 09:44:03 +010039#include <power/pmic.h>
40#include <power/regulator.h>
41#include <power/da9063_pmic.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010042#include <splash.h>
Simon Glassbcb87b62022-10-18 07:10:26 -060043#include <video.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020044
45DECLARE_GLOBAL_DATA_PTR;
46
Heiko Schocher54333792019-12-01 11:23:12 +010047enum {
48 BOARD_TYPE_4 = 4,
49 BOARD_TYPE_7 = 7,
50};
51
52#define ARI_BT_4 "aristainetos2_4@2"
53#define ARI_BT_7 "aristainetos2_7@1"
54
Heiko Schochera051ee92019-12-01 11:23:11 +010055int board_phy_config(struct phy_device *phydev)
56{
57 /* control data pad skew - devaddr = 0x02, register = 0x04 */
58 ksz9031_phy_extended_write(phydev, 0x02,
59 MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
60 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
61 /* rx data pad skew - devaddr = 0x02, register = 0x05 */
62 ksz9031_phy_extended_write(phydev, 0x02,
63 MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
64 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
65 /* tx data pad skew - devaddr = 0x02, register = 0x06 */
66 ksz9031_phy_extended_write(phydev, 0x02,
67 MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
68 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
69 /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */
70 ksz9031_phy_extended_write(phydev, 0x02,
71 MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
72 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF);
73
74 if (phydev->drv->config)
75 phydev->drv->config(phydev);
76
77 return 0;
78}
79
Heiko Schochera051ee92019-12-01 11:23:11 +010080static int rotate_logo_one(unsigned char *out, unsigned char *in)
81{
82 int i, j;
83
84 for (i = 0; i < BMP_LOGO_WIDTH; i++)
85 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
86 out[j * BMP_LOGO_WIDTH + BMP_LOGO_HEIGHT - 1 - i] =
87 in[i * BMP_LOGO_WIDTH + j];
88 return 0;
89}
90
91/*
92 * Rotate the BMP_LOGO (only)
93 * Will only work, if the logo is square, as
94 * BMP_LOGO_HEIGHT and BMP_LOGO_WIDTH are defines, not variables
95 */
96void rotate_logo(int rotations)
97{
98 unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT];
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010099 struct bmp_header *header;
Heiko Schochera051ee92019-12-01 11:23:11 +0100100 unsigned char *in_logo;
101 int i, j;
102
103 if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT)
104 return;
105
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100106 header = (struct bmp_header *)bmp_logo_bitmap;
107 in_logo = bmp_logo_bitmap + header->data_offset;
Heiko Schochera051ee92019-12-01 11:23:11 +0100108
109 /* one 90 degree rotation */
110 if (rotations == 1 || rotations == 2 || rotations == 3)
111 rotate_logo_one(out_logo, in_logo);
112
113 /* second 90 degree rotation */
114 if (rotations == 2 || rotations == 3)
115 rotate_logo_one(in_logo, out_logo);
116
117 /* third 90 degree rotation */
118 if (rotations == 3)
119 rotate_logo_one(out_logo, in_logo);
120
121 /* copy result back to original array */
122 if (rotations == 1 || rotations == 3)
123 for (i = 0; i < BMP_LOGO_WIDTH; i++)
124 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
125 in_logo[i * BMP_LOGO_WIDTH + j] =
126 out_logo[i * BMP_LOGO_WIDTH + j];
127}
128
Heiko Schochera051ee92019-12-01 11:23:11 +0100129static void enable_lvds(struct display_info_t const *dev)
130{
131 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
132 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
133 int reg;
134 s32 timeout = 100000;
135
136 /* set PLL5 clock */
137 reg = readl(&ccm->analog_pll_video);
138 reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN;
139 writel(reg, &ccm->analog_pll_video);
140
141 /* set PLL5 to 232720000Hz */
142 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
143 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x26);
144 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
145 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
146 writel(reg, &ccm->analog_pll_video);
147
148 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xC0238),
149 &ccm->analog_pll_video_num);
150 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xF4240),
151 &ccm->analog_pll_video_denom);
152
153 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
154 writel(reg, &ccm->analog_pll_video);
155
156 while (timeout--)
157 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
158 break;
159 if (timeout < 0)
160 printf("Warning: video pll lock timeout!\n");
161
162 reg = readl(&ccm->analog_pll_video);
163 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
164 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
165 writel(reg, &ccm->analog_pll_video);
166
167 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
168 reg = readl(&ccm->cs2cdr);
169 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
170 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
171 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
172 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
173 writel(reg, &ccm->cs2cdr);
174
175 reg = readl(&ccm->cscmr2);
176 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
177 writel(reg, &ccm->cscmr2);
178
179 reg = readl(&ccm->chsccdr);
180 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
181 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
182 writel(reg, &ccm->chsccdr);
183
184 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
185 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
186 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
187 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
188 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
189 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
190 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
191 writel(reg, &iomux->gpr[2]);
192
193 reg = readl(&iomux->gpr[3]);
194 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
195 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
196 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
197 writel(reg, &iomux->gpr[3]);
198}
199
Heiko Schochera051ee92019-12-01 11:23:11 +0100200static void setup_display(void)
201{
202 enable_ipu_clock();
Heiko Schochera051ee92019-12-01 11:23:11 +0100203}
204
Heiko Schochera051ee92019-12-01 11:23:11 +0100205static void set_gpr_register(void)
206{
207 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
208
209 writel(IOMUXC_GPR1_APP_CLK_REQ_N | IOMUXC_GPR1_PCIE_RDY_L23 |
210 IOMUXC_GPR1_EXC_MON_SLVE |
211 (2 << IOMUXC_GPR1_ADDRS0_OFFSET) |
212 IOMUXC_GPR1_ACT_CS0,
213 &iomuxc_regs->gpr[1]);
214 writel(0x0, &iomuxc_regs->gpr[8]);
215 writel(IOMUXC_GPR12_ARMP_IPG_CLK_EN | IOMUXC_GPR12_ARMP_AHB_CLK_EN |
216 IOMUXC_GPR12_ARMP_ATB_CLK_EN | IOMUXC_GPR12_ARMP_APB_CLK_EN,
217 &iomuxc_regs->gpr[12]);
218}
219
Heiko Schocher54333792019-12-01 11:23:12 +0100220extern char __bss_start[], __bss_end[];
Heiko Schochera051ee92019-12-01 11:23:11 +0100221int board_early_init_f(void)
222{
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100223 select_ldb_di_clock_source(MXC_PLL5_CLK);
Heiko Schochera051ee92019-12-01 11:23:11 +0100224 set_gpr_register();
Heiko Schocher54333792019-12-01 11:23:12 +0100225
226 /*
227 * clear bss here, so we can use spi driver
228 * before relocation and read Environment
229 * from spi flash.
230 */
231 memset(__bss_start, 0x00, __bss_end - __bss_start);
232
Heiko Schochera051ee92019-12-01 11:23:11 +0100233 return 0;
234}
235
Heiko Schocher495956b2019-12-01 11:23:15 +0100236static void setup_one_led(char *label, int state)
Heiko Schochera051ee92019-12-01 11:23:11 +0100237{
Heiko Schocher495956b2019-12-01 11:23:15 +0100238 struct udevice *dev;
239 int ret;
Heiko Schochera051ee92019-12-01 11:23:11 +0100240
Heiko Schocher495956b2019-12-01 11:23:15 +0100241 ret = led_get_by_label(label, &dev);
242 if (ret == 0)
243 led_set_state(dev, state);
244}
245
246static void setup_board_gpio(void)
247{
248 setup_one_led("led_ena", LEDST_ON);
Heiko Schochera051ee92019-12-01 11:23:11 +0100249 /* switch off Status LEDs */
Heiko Schocher495956b2019-12-01 11:23:15 +0100250 setup_one_led("led_yellow", LEDST_OFF);
251 setup_one_led("led_red", LEDST_OFF);
252 setup_one_led("led_green", LEDST_OFF);
253 setup_one_led("led_blue", LEDST_OFF);
Heiko Schochera051ee92019-12-01 11:23:11 +0100254}
255
Heiko Schocherc6729682019-12-01 11:23:23 +0100256static void aristainetos_run_rescue_command(int reason)
257{
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100258 char rescue_reason_command[20];
Heiko Schocherc6729682019-12-01 11:23:23 +0100259
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100260 sprintf(rescue_reason_command, "setenv rreason %d", reason);
Heiko Schocherc6729682019-12-01 11:23:23 +0100261 run_command(rescue_reason_command, 0);
262}
263
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100264static int aristainetos_bootmode_settings(void)
Heiko Schocherc6729682019-12-01 11:23:23 +0100265{
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100266 struct gpio_desc *desc;
267 struct src *psrc = (struct src *)SRC_BASE_ADDR;
268 unsigned int sbmr1 = readl(&psrc->sbmr1);
269 char *my_bootdelay;
270 char bootmode = 0;
271 int ret;
Heiko Schocherc6729682019-12-01 11:23:23 +0100272 struct udevice *dev;
273 int off;
Heiko Schocherc6729682019-12-01 11:23:23 +0100274 u8 data[0x10];
275 u8 rescue_reason;
276
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100277 /* jumper controlled reset of the environment */
278 ret = gpio_hog_lookup_name("env_reset", &desc);
279 if (!ret) {
280 if (dm_gpio_get_value(desc)) {
281 printf("\nReset u-boot environment (jumper)\n");
282 run_command("run default_env; saveenv; saveenv", 0);
283 }
284 }
285
Heiko Schocherc6729682019-12-01 11:23:23 +0100286 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
287 if (off < 0) {
288 printf("%s: No eeprom0 path offset\n", __func__);
289 return off;
290 }
291
292 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
293 if (ret) {
294 printf("%s: Could not find EEPROM\n", __func__);
295 return ret;
296 }
297
298 ret = i2c_set_chip_offset_len(dev, 2);
299 if (ret)
300 return ret;
301
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100302 ret = i2c_eeprom_read(dev, 0x1ff0, (uint8_t *)data, sizeof(data));
Heiko Schocherc6729682019-12-01 11:23:23 +0100303 if (ret) {
304 printf("%s: Could not read EEPROM\n", __func__);
305 return ret;
306 }
307
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100308 /* software controlled reset of the environment (EEPROM magic) */
309 if (strncmp((char *)data, "DeF", 3) == 0) {
Heiko Schocherc6729682019-12-01 11:23:23 +0100310 memset(data, 0xff, 3);
311 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)data, 3);
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100312 printf("\nReset u-boot environment (EEPROM)\n");
Heiko Schocherc6729682019-12-01 11:23:23 +0100313 run_command("run default_env; saveenv; saveenv", 0);
314 }
315
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100316 if (sbmr1 & 0x40) {
317 env_set("bootmode", "1");
318 printf("SD bootmode jumper set!\n");
319 } else {
320 env_set("bootmode", "0");
321 }
Heiko Schochera051ee92019-12-01 11:23:11 +0100322
323 /*
324 * Check the boot-source. If booting from NOR Flash,
325 * disable bootdelay
326 */
Heiko Schochere3379da2019-12-01 11:23:26 +0100327 ret = gpio_hog_lookup_name("bootsel0", &desc);
328 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100329 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0;
Heiko Schochere3379da2019-12-01 11:23:26 +0100330 ret = gpio_hog_lookup_name("bootsel1", &desc);
331 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100332 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1;
Heiko Schochere3379da2019-12-01 11:23:26 +0100333 ret = gpio_hog_lookup_name("bootsel2", &desc);
334 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100335 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2;
Heiko Schochera051ee92019-12-01 11:23:11 +0100336
337 if (bootmode == 7) {
338 my_bootdelay = env_get("nor_bootdelay");
Heiko Schochere3379da2019-12-01 11:23:26 +0100339 if (my_bootdelay)
Heiko Schochera051ee92019-12-01 11:23:11 +0100340 env_set("bootdelay", my_bootdelay);
341 else
342 env_set("bootdelay", "-2");
343 }
344
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100345 /* jumper controlled boot of the rescue system */
Heiko Schocher495956b2019-12-01 11:23:15 +0100346 ret = gpio_hog_lookup_name("boot_rescue", &desc);
347 if (!ret) {
348 if (dm_gpio_get_value(desc)) {
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100349 printf("\nBooting into Rescue System (jumper)\n");
Heiko Schocher495956b2019-12-01 11:23:15 +0100350 aristainetos_run_rescue_command(16);
351 run_command("run rescue_xload_boot", 0);
352 }
353 }
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100354
355 /* software controlled boot of the rescue system (EEPROM magic) */
356 if (strncmp((char *)&data[3], "ReScUe", 6) == 0) {
357 rescue_reason = *(uint8_t *)&data[9];
358 memset(&data[3], 0xff, 7);
359 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)&data[3], 7);
360 printf("\nBooting into Rescue System (EEPROM)\n");
361 aristainetos_run_rescue_command(rescue_reason);
362 run_command("run rescue_xload_boot", 0);
363 }
364
365 return 0;
Heiko Schochere3379da2019-12-01 11:23:26 +0100366}
367
Heiko Schocherf5210a92020-03-02 09:44:03 +0100368#if defined(CONFIG_DM_PMIC_DA9063)
369/*
370 * On the aristainetos2c boards the PMIC needs to be initialized,
371 * because the Ethernet PHY uses a different regulator that is not
372 * setup per hardware default. This does not influence the other versions
373 * as this regulator isn't used there at all.
374 *
375 * Unfortunately we have not yet a interface to setup all
376 * values we need.
377 */
378static int setup_pmic_voltages(void)
379{
380 struct udevice *dev;
381 int off;
382 int ret;
383
384 off = fdt_path_offset(gd->fdt_blob, "pmic0");
385 if (off < 0) {
386 printf("%s: No pmic path offset\n", __func__);
387 return off;
388 }
389
390 ret = uclass_get_device_by_of_offset(UCLASS_PMIC, off, &dev);
391 if (ret) {
392 printf("%s: Could not find PMIC\n", __func__);
393 return ret;
394 }
395
396 pmic_reg_write(dev, DA9063_REG_PAGE_CON, 0x01);
397 pmic_reg_write(dev, DA9063_REG_BPRO_CFG, 0xc1);
398 ret = pmic_reg_read(dev, DA9063_REG_BUCK_ILIM_B);
399 if (ret < 0) {
400 printf("%s: error %d get register\n", __func__, ret);
401 return ret;
402 }
403 ret &= 0xf0;
404 ret |= 0x09;
405 pmic_reg_write(dev, DA9063_REG_BUCK_ILIM_B, ret);
406 pmic_reg_write(dev, DA9063_REG_VBPRO_A, 0x43);
407 pmic_reg_write(dev, DA9063_REG_VBPRO_B, 0xc3);
408
409 return 0;
410}
411#else
412static int setup_pmic_voltages(void)
413{
414 return 0;
415}
416#endif
417
Heiko Schochere3379da2019-12-01 11:23:26 +0100418int board_late_init(void)
419{
420 int x, y;
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100421 int ret;
Heiko Schochere3379da2019-12-01 11:23:26 +0100422
Heiko Schochere3379da2019-12-01 11:23:26 +0100423 splash_get_pos(&x, &y);
424 bmp_display((ulong)&bmp_logo_bitmap[0], x, y);
425
Heiko Schocher5a0baf42020-11-30 20:46:02 +0100426 ret = aristainetos_bootmode_settings();
427 if (ret)
428 return ret;
Heiko Schocherc6729682019-12-01 11:23:23 +0100429
Heiko Schocher54333792019-12-01 11:23:12 +0100430 /* set board_type */
431 if (gd->board_type == BOARD_TYPE_4)
432 env_set("board_type", ARI_BT_4);
433 else
434 env_set("board_type", ARI_BT_7);
Heiko Schochere3379da2019-12-01 11:23:26 +0100435
Heiko Schocherf5210a92020-03-02 09:44:03 +0100436 if (setup_pmic_voltages())
437 printf("Error setup PMIC\n");
438
Heiko Schochera051ee92019-12-01 11:23:11 +0100439 return 0;
440}
Heiko Schocher05729822015-05-18 13:32:31 +0200441
Heiko Schocher05729822015-05-18 13:32:31 +0200442int dram_init(void)
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200443{
Fabio Estevam1b23fe52016-07-23 13:23:39 -0300444 gd->ram_size = imx_ddr_size();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200445
Heiko Schocher05729822015-05-18 13:32:31 +0200446 return 0;
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200447}
448
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200449struct display_info_t const displays[] = {
450 {
451 .bus = -1,
452 .addr = 0,
453 .pixfmt = IPU_PIX_FMT_RGB24,
454 .detect = NULL,
455 .enable = enable_lvds,
456 .mode = {
457 .name = "lb07wv8",
458 .refresh = 60,
459 .xres = 800,
460 .yres = 480,
Heiko Schocher27813292015-08-11 08:09:44 +0200461 .pixclock = 30066,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200462 .left_margin = 88,
463 .right_margin = 88,
Heiko Schocher27813292015-08-11 08:09:44 +0200464 .upper_margin = 20,
465 .lower_margin = 20,
Heiko Schocher69f0e442015-01-20 10:06:18 +0100466 .hsync_len = 80,
Heiko Schocher27813292015-08-11 08:09:44 +0200467 .vsync_len = 5,
468 .sync = FB_SYNC_EXT,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200469 .vmode = FB_VMODE_NONINTERLACED
470 }
471 }
472};
473size_t display_count = ARRAY_SIZE(displays);
474
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200475int board_init(void)
476{
477 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
478
479 /* address of boot parameters */
480 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
481
Heiko Schocher05729822015-05-18 13:32:31 +0200482 setup_board_gpio();
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100483 setup_display();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200484
485 /* GPIO_1 for USB_OTG_ID */
Heiko Schocher05729822015-05-18 13:32:31 +0200486 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200487 return 0;
488}
489
Heiko Schocher54333792019-12-01 11:23:12 +0100490int board_fit_config_name_match(const char *name)
491{
492 if (gd->board_type == BOARD_TYPE_4 &&
493 strchr(name, 0x34))
494 return 0;
495
496 if (gd->board_type == BOARD_TYPE_7 &&
497 strchr(name, 0x37))
498 return 0;
499
500 return -1;
501}
502
503static void do_board_detect(void)
504{
505 int ret;
506 char s[30];
507
508 /* default use board type 7 */
509 gd->board_type = BOARD_TYPE_7;
510 if (env_init())
511 return;
512
513 ret = env_get_f("panel", s, sizeof(s));
514 if (ret < 0)
515 return;
516
517 if (!strncmp("lg4573", s, 6))
518 gd->board_type = BOARD_TYPE_4;
519}
520
521#ifdef CONFIG_DTB_RESELECT
522int embedded_dtb_select(void)
523{
524 int rescan;
525
526 do_board_detect();
527 fdtdec_resetup(&rescan);
528
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200529 return 0;
530}
531#endif
Heiko Schocherab77bef2020-11-30 20:46:05 +0100532
533enum env_location env_get_location(enum env_operation op, int prio)
534{
535 if (op == ENVOP_SAVE || op == ENVOP_ERASE)
536 return ENVL_SPI_FLASH;
537
538 switch (prio) {
539 case 0:
540 return ENVL_NOWHERE;
541
542 case 1:
543 return ENVL_SPI_FLASH;
544
545 default:
546 return ENVL_UNKNOWN;
547 }
548
549 return ENVL_UNKNOWN;
550}