blob: 88090799a6de75f26f7733f4218f776d32ab12d2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schochere379c032014-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 Schochere379c032014-07-18 06:07:22 +020010 */
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 Yamada1221ce42016-09-21 11:28:55 +090016#include <linux/errno.h>
Heiko Schochere379c032014-07-18 06:07:22 +020017#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/boot_mode.h>
Stefano Babic552a8482017-06-29 10:16:06 +020020#include <asm/mach-imx/video.h>
Heiko Schochere379c032014-07-18 06:07:22 +020021#include <asm/arch/crm_regs.h>
Heiko Schochere379c032014-07-18 06:07:22 +020022#include <asm/io.h>
23#include <asm/arch/sys_proto.h>
Heiko Schocher621ff132019-12-01 11:23:19 +010024#include <bmp_logo.h>
Heiko Schocherccc75952019-12-01 11:23:12 +010025#include <dm/root.h>
Heiko Schocher0f1130b2019-12-01 11:23:11 +010026#include <env.h>
Heiko Schocherf7cf76f2019-12-01 11:23:23 +010027#include <i2c_eeprom.h>
28#include <i2c.h>
Heiko Schocher0f1130b2019-12-01 11:23:11 +010029#include <micrel.h>
Heiko Schocher5e654962019-12-01 11:23:18 +010030#include <miiphy.h>
Heiko Schocher621ff132019-12-01 11:23:19 +010031#include <lcd.h>
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +010032#include <led.h>
Heiko Schocher621ff132019-12-01 11:23:19 +010033#include <splash.h>
34#include <video_fb.h>
Heiko Schochere379c032014-07-18 06:07:22 +020035
36DECLARE_GLOBAL_DATA_PTR;
37
Heiko Schocherccc75952019-12-01 11:23:12 +010038enum {
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 Schocher0f1130b2019-12-01 11:23:11 +010046int 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 Schocher0f1130b2019-12-01 11:23:11 +010071static 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 */
87void rotate_logo(int rotations)
88{
89 unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT];
Heiko Schocher621ff132019-12-01 11:23:19 +010090 struct bmp_header *header;
Heiko Schocher0f1130b2019-12-01 11:23:11 +010091 unsigned char *in_logo;
92 int i, j;
93
94 if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT)
95 return;
96
Heiko Schocher621ff132019-12-01 11:23:19 +010097 header = (struct bmp_header *)bmp_logo_bitmap;
98 in_logo = bmp_logo_bitmap + header->data_offset;
Heiko Schocher0f1130b2019-12-01 11:23:11 +010099
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 Schocher0f1130b2019-12-01 11:23:11 +0100120static 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
191static 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 Schocher0f1130b2019-12-01 11:23:11 +0100202 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 Schocher0f1130b2019-12-01 11:23:11 +0100270}
271
272static void setup_display(void)
273{
274 enable_ipu_clock();
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100275}
276
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100277static 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 Schocherccc75952019-12-01 11:23:12 +0100292extern char __bss_start[], __bss_end[];
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100293int board_early_init_f(void)
294{
Heiko Schocher621ff132019-12-01 11:23:19 +0100295 select_ldb_di_clock_source(MXC_PLL5_CLK);
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100296 set_gpr_register();
Heiko Schocherccc75952019-12-01 11:23:12 +0100297
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 Schocher0f1130b2019-12-01 11:23:11 +0100305 return 0;
306}
307
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100308static 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 Schocher0f1130b2019-12-01 11:23:11 +0100318static void setup_board_gpio(void)
319{
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100320 setup_one_led("led_ena", LEDST_ON);
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100321 /* switch off Status LEDs */
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100322 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 Schocher0f1130b2019-12-01 11:23:11 +0100326}
327
Heiko Schocherf7cf76f2019-12-01 11:23:23 +0100328#define ARI_RESC_FMT "setenv rescue_reason setenv bootargs \\${bootargs}" \
329 " rescueReason=%d "
330
331static 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
339static 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 Schocher0ed133a2019-12-01 11:23:26 +0100386static void aristainetos_bootmode_settings(void)
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100387{
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100388 struct gpio_desc *desc;
389 struct src *psrc = (struct src *)SRC_BASE_ADDR;
390 unsigned int sbmr1 = readl(&psrc->sbmr1);
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100391 char *my_bootdelay;
392 char bootmode = 0;
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100393 int ret;
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100394
395 /*
396 * Check the boot-source. If booting from NOR Flash,
397 * disable bootdelay
398 */
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100399 ret = gpio_hog_lookup_name("bootsel0", &desc);
400 if (!ret)
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100401 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0;
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100402 ret = gpio_hog_lookup_name("bootsel1", &desc);
403 if (!ret)
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100404 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1;
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100405 ret = gpio_hog_lookup_name("bootsel2", &desc);
406 if (!ret)
Heiko Schocherfc7e3cc2019-12-01 11:23:15 +0100407 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2;
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100408
409 if (bootmode == 7) {
410 my_bootdelay = env_get("nor_bootdelay");
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100411 if (my_bootdelay)
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100412 env_set("bootdelay", my_bootdelay);
413 else
414 env_set("bootdelay", "-2");
415 }
416
Heiko Schocher0ed133a2019-12-01 11:23:26 +0100417 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 Schocherfc7e3cc2019-12-01 11:23:15 +0100424 /* 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 Schocher0ed133a2019-12-01 11:23:26 +0100439}
440
441int 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 Schocherfc7e3cc2019-12-01 11:23:15 +0100450
Heiko Schocherf7cf76f2019-12-01 11:23:23 +0100451 /* eeprom work */
452 aristainetos_eeprom();
453
Heiko Schocherccc75952019-12-01 11:23:12 +0100454 /* 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 Schocher0ed133a2019-12-01 11:23:26 +0100459
Heiko Schocher0f1130b2019-12-01 11:23:11 +0100460 return 0;
461}
Heiko Schocher7254d922015-05-18 13:32:31 +0200462
Heiko Schocher7254d922015-05-18 13:32:31 +0200463int dram_init(void)
Heiko Schocher2f6bb0a2014-10-30 13:14:03 +0100464{
Fabio Estevam84c51682016-07-23 13:23:39 -0300465 gd->ram_size = imx_ddr_size();
Heiko Schocher2f6bb0a2014-10-30 13:14:03 +0100466
Heiko Schocher7254d922015-05-18 13:32:31 +0200467 return 0;
Heiko Schochere379c032014-07-18 06:07:22 +0200468}
469
Heiko Schochere379c032014-07-18 06:07:22 +0200470struct 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 Schocherd0d005b2015-08-11 08:09:44 +0200482 .pixclock = 30066,
Heiko Schochere379c032014-07-18 06:07:22 +0200483 .left_margin = 88,
484 .right_margin = 88,
Heiko Schocherd0d005b2015-08-11 08:09:44 +0200485 .upper_margin = 20,
486 .lower_margin = 20,
Heiko Schocherb4b39a72015-01-20 10:06:18 +0100487 .hsync_len = 80,
Heiko Schocherd0d005b2015-08-11 08:09:44 +0200488 .vsync_len = 5,
489 .sync = FB_SYNC_EXT,
Heiko Schochere379c032014-07-18 06:07:22 +0200490 .vmode = FB_VMODE_NONINTERLACED
491 }
492 }
Heiko Schocherc08aa772019-12-01 11:23:31 +0100493#if ((CONFIG_SYS_BOARD_VERSION == 2) || \
494 (CONFIG_SYS_BOARD_VERSION == 3) || \
495 (CONFIG_SYS_BOARD_VERSION == 4))
Heiko Schocher7254d922015-05-18 13:32:31 +0200496 , {
497 .bus = -1,
498 .addr = 0,
499 .pixfmt = IPU_PIX_FMT_RGB24,
500 .detect = NULL,
501 .enable = enable_spi_display,
502 .mode = {
503 .name = "lg4573",
Heiko Schocherd0d005b2015-08-11 08:09:44 +0200504 .refresh = 57,
Heiko Schocher7254d922015-05-18 13:32:31 +0200505 .xres = 480,
506 .yres = 800,
507 .pixclock = 37037,
508 .left_margin = 59,
509 .right_margin = 10,
510 .upper_margin = 15,
511 .lower_margin = 15,
512 .hsync_len = 10,
513 .vsync_len = 15,
514 .sync = FB_SYNC_EXT | FB_SYNC_HOR_HIGH_ACT |
515 FB_SYNC_VERT_HIGH_ACT,
516 .vmode = FB_VMODE_NONINTERLACED
517 }
518 }
519#endif
Heiko Schochere379c032014-07-18 06:07:22 +0200520};
521size_t display_count = ARRAY_SIZE(displays);
522
Heiko Schochere379c032014-07-18 06:07:22 +0200523iomux_v3_cfg_t nfc_pads[] = {
524 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
525 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
526 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL),
527 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL),
528 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
Heiko Schochere379c032014-07-18 06:07:22 +0200529 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
530 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
531 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL),
532 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL),
533 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL),
534 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL),
535 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL),
536 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL),
537 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL),
538 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL),
539 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
540};
541
542static void setup_gpmi_nand(void)
543{
544 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
545
546 /* config gpmi nand iomux */
547 imx_iomux_v3_setup_multiple_pads(nfc_pads,
548 ARRAY_SIZE(nfc_pads));
549
Heiko Schocher7254d922015-05-18 13:32:31 +0200550 /* gate ENFC_CLK_ROOT clock first,before clk source switch */
551 clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
552
Heiko Schochere379c032014-07-18 06:07:22 +0200553 /* config gpmi and bch clock to 100 MHz */
554 clrsetbits_le32(&mxc_ccm->cs2cdr,
555 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
556 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
557 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
558 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
559 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
560 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
561
Heiko Schocher7254d922015-05-18 13:32:31 +0200562 /* enable ENFC_CLK_ROOT clock */
563 setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
564
Heiko Schochere379c032014-07-18 06:07:22 +0200565 /* enable gpmi and bch clock gating */
566 setbits_le32(&mxc_ccm->CCGR4,
567 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
568 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
569 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
570 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
571 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
572
573 /* enable apbh clock gating */
574 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
575}
576
577int board_init(void)
578{
579 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
580
581 /* address of boot parameters */
582 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
583
Heiko Schocher7254d922015-05-18 13:32:31 +0200584 setup_board_gpio();
Heiko Schochere379c032014-07-18 06:07:22 +0200585 setup_gpmi_nand();
Heiko Schocher621ff132019-12-01 11:23:19 +0100586 setup_display();
Heiko Schochere379c032014-07-18 06:07:22 +0200587
588 /* GPIO_1 for USB_OTG_ID */
Heiko Schocher7254d922015-05-18 13:32:31 +0200589 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
Heiko Schochere379c032014-07-18 06:07:22 +0200590 return 0;
591}
592
Heiko Schocherccc75952019-12-01 11:23:12 +0100593int board_fit_config_name_match(const char *name)
594{
595 if (gd->board_type == BOARD_TYPE_4 &&
596 strchr(name, 0x34))
597 return 0;
598
599 if (gd->board_type == BOARD_TYPE_7 &&
600 strchr(name, 0x37))
601 return 0;
602
603 return -1;
604}
605
606static void do_board_detect(void)
607{
608 int ret;
609 char s[30];
610
611 /* default use board type 7 */
612 gd->board_type = BOARD_TYPE_7;
613 if (env_init())
614 return;
615
616 ret = env_get_f("panel", s, sizeof(s));
617 if (ret < 0)
618 return;
619
620 if (!strncmp("lg4573", s, 6))
621 gd->board_type = BOARD_TYPE_4;
622}
623
624#ifdef CONFIG_DTB_RESELECT
625int embedded_dtb_select(void)
626{
627 int rescan;
628
629 do_board_detect();
630 fdtdec_resetup(&rescan);
631
Heiko Schochere379c032014-07-18 06:07:22 +0200632 return 0;
633}
634#endif