blob: 846a99804a6c9fc65d380440d451aa3aa79bb710 [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
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 Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020017#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/video.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020021#include <asm/arch/crm_regs.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020022#include <asm/io.h>
23#include <asm/arch/sys_proto.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010024#include <bmp_logo.h>
Heiko Schocher54333792019-12-01 11:23:12 +010025#include <dm/root.h>
Heiko Schochera051ee92019-12-01 11:23:11 +010026#include <env.h>
27#include <micrel.h>
Heiko Schocher441b0542019-12-01 11:23:18 +010028#include <miiphy.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010029#include <lcd.h>
Heiko Schocher495956b2019-12-01 11:23:15 +010030#include <led.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010031#include <splash.h>
32#include <video_fb.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020033
34DECLARE_GLOBAL_DATA_PTR;
35
Heiko Schocher54333792019-12-01 11:23:12 +010036enum {
37 BOARD_TYPE_4 = 4,
38 BOARD_TYPE_7 = 7,
39};
40
41#define ARI_BT_4 "aristainetos2_4@2"
42#define ARI_BT_7 "aristainetos2_7@1"
43
Heiko Schochera051ee92019-12-01 11:23:11 +010044int board_phy_config(struct phy_device *phydev)
45{
46 /* control data pad skew - devaddr = 0x02, register = 0x04 */
47 ksz9031_phy_extended_write(phydev, 0x02,
48 MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
49 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
50 /* rx data pad skew - devaddr = 0x02, register = 0x05 */
51 ksz9031_phy_extended_write(phydev, 0x02,
52 MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
53 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
54 /* tx data pad skew - devaddr = 0x02, register = 0x06 */
55 ksz9031_phy_extended_write(phydev, 0x02,
56 MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
57 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
58 /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */
59 ksz9031_phy_extended_write(phydev, 0x02,
60 MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
61 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF);
62
63 if (phydev->drv->config)
64 phydev->drv->config(phydev);
65
66 return 0;
67}
68
Heiko Schochera051ee92019-12-01 11:23:11 +010069static int rotate_logo_one(unsigned char *out, unsigned char *in)
70{
71 int i, j;
72
73 for (i = 0; i < BMP_LOGO_WIDTH; i++)
74 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
75 out[j * BMP_LOGO_WIDTH + BMP_LOGO_HEIGHT - 1 - i] =
76 in[i * BMP_LOGO_WIDTH + j];
77 return 0;
78}
79
80/*
81 * Rotate the BMP_LOGO (only)
82 * Will only work, if the logo is square, as
83 * BMP_LOGO_HEIGHT and BMP_LOGO_WIDTH are defines, not variables
84 */
85void rotate_logo(int rotations)
86{
87 unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT];
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010088 struct bmp_header *header;
Heiko Schochera051ee92019-12-01 11:23:11 +010089 unsigned char *in_logo;
90 int i, j;
91
92 if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT)
93 return;
94
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010095 header = (struct bmp_header *)bmp_logo_bitmap;
96 in_logo = bmp_logo_bitmap + header->data_offset;
Heiko Schochera051ee92019-12-01 11:23:11 +010097
98 /* one 90 degree rotation */
99 if (rotations == 1 || rotations == 2 || rotations == 3)
100 rotate_logo_one(out_logo, in_logo);
101
102 /* second 90 degree rotation */
103 if (rotations == 2 || rotations == 3)
104 rotate_logo_one(in_logo, out_logo);
105
106 /* third 90 degree rotation */
107 if (rotations == 3)
108 rotate_logo_one(out_logo, in_logo);
109
110 /* copy result back to original array */
111 if (rotations == 1 || rotations == 3)
112 for (i = 0; i < BMP_LOGO_WIDTH; i++)
113 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
114 in_logo[i * BMP_LOGO_WIDTH + j] =
115 out_logo[i * BMP_LOGO_WIDTH + j];
116}
117
Heiko Schochera051ee92019-12-01 11:23:11 +0100118static void enable_lvds(struct display_info_t const *dev)
119{
120 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
121 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
122 int reg;
123 s32 timeout = 100000;
124
125 /* set PLL5 clock */
126 reg = readl(&ccm->analog_pll_video);
127 reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN;
128 writel(reg, &ccm->analog_pll_video);
129
130 /* set PLL5 to 232720000Hz */
131 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
132 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x26);
133 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
134 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
135 writel(reg, &ccm->analog_pll_video);
136
137 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xC0238),
138 &ccm->analog_pll_video_num);
139 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xF4240),
140 &ccm->analog_pll_video_denom);
141
142 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
143 writel(reg, &ccm->analog_pll_video);
144
145 while (timeout--)
146 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
147 break;
148 if (timeout < 0)
149 printf("Warning: video pll lock timeout!\n");
150
151 reg = readl(&ccm->analog_pll_video);
152 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
153 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
154 writel(reg, &ccm->analog_pll_video);
155
156 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
157 reg = readl(&ccm->cs2cdr);
158 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
159 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
160 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
161 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
162 writel(reg, &ccm->cs2cdr);
163
164 reg = readl(&ccm->cscmr2);
165 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
166 writel(reg, &ccm->cscmr2);
167
168 reg = readl(&ccm->chsccdr);
169 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
170 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
171 writel(reg, &ccm->chsccdr);
172
173 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
174 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
175 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
176 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
177 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
178 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
179 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
180 writel(reg, &iomux->gpr[2]);
181
182 reg = readl(&iomux->gpr[3]);
183 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
184 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
185 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
186 writel(reg, &iomux->gpr[3]);
187}
188
189static void enable_spi_display(struct display_info_t const *dev)
190{
191 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
192 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
193 int reg;
194 s32 timeout = 100000;
195
196#if defined(CONFIG_VIDEO_BMP_LOGO)
197 rotate_logo(3); /* portrait display in landscape mode */
198#endif
199
Heiko Schochera051ee92019-12-01 11:23:11 +0100200 reg = readl(&ccm->cs2cdr);
201
202 /* select pll 5 clock */
203 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
204 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
205 writel(reg, &ccm->cs2cdr);
206
207 /* set PLL5 to 197994996Hz */
208 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
209 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x21);
210 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
211 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
212 writel(reg, &ccm->analog_pll_video);
213
214 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xfbf4),
215 &ccm->analog_pll_video_num);
216 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xf4240),
217 &ccm->analog_pll_video_denom);
218
219 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
220 writel(reg, &ccm->analog_pll_video);
221
222 while (timeout--)
223 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
224 break;
225 if (timeout < 0)
226 printf("Warning: video pll lock timeout!\n");
227
228 reg = readl(&ccm->analog_pll_video);
229 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
230 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
231 writel(reg, &ccm->analog_pll_video);
232
233 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
234 reg = readl(&ccm->cs2cdr);
235 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
236 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
237 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
238 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
239 writel(reg, &ccm->cs2cdr);
240
241 reg = readl(&ccm->cscmr2);
242 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
243 writel(reg, &ccm->cscmr2);
244
245 reg = readl(&ccm->chsccdr);
246 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
247 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
248 reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK;
249 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET);
250 reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK;
251 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
252 writel(reg, &ccm->chsccdr);
253
254 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
255 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
256 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
257 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
258 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
259 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
260 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
261 writel(reg, &iomux->gpr[2]);
262
263 reg = readl(&iomux->gpr[3]);
264 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
265 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
266 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
267 writel(reg, &iomux->gpr[3]);
Heiko Schochera051ee92019-12-01 11:23:11 +0100268}
269
270static void setup_display(void)
271{
272 enable_ipu_clock();
Heiko Schochera051ee92019-12-01 11:23:11 +0100273}
274
Heiko Schochera051ee92019-12-01 11:23:11 +0100275static void set_gpr_register(void)
276{
277 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
278
279 writel(IOMUXC_GPR1_APP_CLK_REQ_N | IOMUXC_GPR1_PCIE_RDY_L23 |
280 IOMUXC_GPR1_EXC_MON_SLVE |
281 (2 << IOMUXC_GPR1_ADDRS0_OFFSET) |
282 IOMUXC_GPR1_ACT_CS0,
283 &iomuxc_regs->gpr[1]);
284 writel(0x0, &iomuxc_regs->gpr[8]);
285 writel(IOMUXC_GPR12_ARMP_IPG_CLK_EN | IOMUXC_GPR12_ARMP_AHB_CLK_EN |
286 IOMUXC_GPR12_ARMP_ATB_CLK_EN | IOMUXC_GPR12_ARMP_APB_CLK_EN,
287 &iomuxc_regs->gpr[12]);
288}
289
Heiko Schocher54333792019-12-01 11:23:12 +0100290extern char __bss_start[], __bss_end[];
Heiko Schochera051ee92019-12-01 11:23:11 +0100291int board_early_init_f(void)
292{
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100293 select_ldb_di_clock_source(MXC_PLL5_CLK);
Heiko Schochera051ee92019-12-01 11:23:11 +0100294 set_gpr_register();
Heiko Schocher54333792019-12-01 11:23:12 +0100295
296 /*
297 * clear bss here, so we can use spi driver
298 * before relocation and read Environment
299 * from spi flash.
300 */
301 memset(__bss_start, 0x00, __bss_end - __bss_start);
302
Heiko Schochera051ee92019-12-01 11:23:11 +0100303 return 0;
304}
305
Heiko Schocher495956b2019-12-01 11:23:15 +0100306static void setup_one_led(char *label, int state)
Heiko Schochera051ee92019-12-01 11:23:11 +0100307{
Heiko Schocher495956b2019-12-01 11:23:15 +0100308 struct udevice *dev;
309 int ret;
Heiko Schochera051ee92019-12-01 11:23:11 +0100310
Heiko Schocher495956b2019-12-01 11:23:15 +0100311 ret = led_get_by_label(label, &dev);
312 if (ret == 0)
313 led_set_state(dev, state);
314}
315
316static void setup_board_gpio(void)
317{
318 setup_one_led("led_ena", LEDST_ON);
Heiko Schochera051ee92019-12-01 11:23:11 +0100319 /* switch off Status LEDs */
Heiko Schocher495956b2019-12-01 11:23:15 +0100320 setup_one_led("led_yellow", LEDST_OFF);
321 setup_one_led("led_red", LEDST_OFF);
322 setup_one_led("led_green", LEDST_OFF);
323 setup_one_led("led_blue", LEDST_OFF);
Heiko Schochera051ee92019-12-01 11:23:11 +0100324}
325
Heiko Schochera051ee92019-12-01 11:23:11 +0100326int board_late_init(void)
327{
328 char *my_bootdelay;
329 char bootmode = 0;
Heiko Schocher495956b2019-12-01 11:23:15 +0100330 struct gpio_desc *desc;
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100331 int x, y;
Heiko Schocher495956b2019-12-01 11:23:15 +0100332 int ret;
Heiko Schochera051ee92019-12-01 11:23:11 +0100333
Heiko Schocher495956b2019-12-01 11:23:15 +0100334 led_default_state();
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100335 splash_get_pos(&x, &y);
336 bmp_display((ulong)&bmp_logo_bitmap[0], x, y);
Heiko Schochera051ee92019-12-01 11:23:11 +0100337 /*
338 * Check the boot-source. If booting from NOR Flash,
339 * disable bootdelay
340 */
Heiko Schocher495956b2019-12-01 11:23:15 +0100341 desc = gpio_hog_lookup_name("bootsel0");
342 if (desc)
343 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0;
344 desc = gpio_hog_lookup_name("bootsel1");
345 if (desc)
346 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1;
347 desc = gpio_hog_lookup_name("bootsel2");
348 if (desc)
349 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2;
Heiko Schochera051ee92019-12-01 11:23:11 +0100350
351 if (bootmode == 7) {
352 my_bootdelay = env_get("nor_bootdelay");
353 if (my_bootdelay != NULL)
354 env_set("bootdelay", my_bootdelay);
355 else
356 env_set("bootdelay", "-2");
357 }
358
Heiko Schocher495956b2019-12-01 11:23:15 +0100359 /* read out some jumper values*/
360 ret = gpio_hog_lookup_name("env_reset", &desc);
361 if (!ret) {
362 if (dm_gpio_get_value(desc)) {
363 printf("\nClear env (set back to defaults)\n");
364 run_command("run default_env; saveenv; saveenv", 0);
365 }
366 }
367 ret = gpio_hog_lookup_name("boot_rescue", &desc);
368 if (!ret) {
369 if (dm_gpio_get_value(desc)) {
370 aristainetos_run_rescue_command(16);
371 run_command("run rescue_xload_boot", 0);
372 }
373 }
374
Heiko Schocher54333792019-12-01 11:23:12 +0100375 /* set board_type */
376 if (gd->board_type == BOARD_TYPE_4)
377 env_set("board_type", ARI_BT_4);
378 else
379 env_set("board_type", ARI_BT_7);
380
Heiko Schochera051ee92019-12-01 11:23:11 +0100381 return 0;
382}
Heiko Schocher05729822015-05-18 13:32:31 +0200383
Heiko Schocher05729822015-05-18 13:32:31 +0200384int dram_init(void)
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200385{
Fabio Estevam1b23fe52016-07-23 13:23:39 -0300386 gd->ram_size = imx_ddr_size();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200387
Heiko Schocher05729822015-05-18 13:32:31 +0200388 return 0;
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200389}
390
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200391struct display_info_t const displays[] = {
392 {
393 .bus = -1,
394 .addr = 0,
395 .pixfmt = IPU_PIX_FMT_RGB24,
396 .detect = NULL,
397 .enable = enable_lvds,
398 .mode = {
399 .name = "lb07wv8",
400 .refresh = 60,
401 .xres = 800,
402 .yres = 480,
Heiko Schocher27813292015-08-11 08:09:44 +0200403 .pixclock = 30066,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200404 .left_margin = 88,
405 .right_margin = 88,
Heiko Schocher27813292015-08-11 08:09:44 +0200406 .upper_margin = 20,
407 .lower_margin = 20,
Heiko Schocher69f0e442015-01-20 10:06:18 +0100408 .hsync_len = 80,
Heiko Schocher27813292015-08-11 08:09:44 +0200409 .vsync_len = 5,
410 .sync = FB_SYNC_EXT,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200411 .vmode = FB_VMODE_NONINTERLACED
412 }
413 }
Heiko Schocher8fb9f3f2015-08-24 11:36:40 +0200414#if ((CONFIG_SYS_BOARD_VERSION == 2) || (CONFIG_SYS_BOARD_VERSION == 3))
Heiko Schocher05729822015-05-18 13:32:31 +0200415 , {
416 .bus = -1,
417 .addr = 0,
418 .pixfmt = IPU_PIX_FMT_RGB24,
419 .detect = NULL,
420 .enable = enable_spi_display,
421 .mode = {
422 .name = "lg4573",
Heiko Schocher27813292015-08-11 08:09:44 +0200423 .refresh = 57,
Heiko Schocher05729822015-05-18 13:32:31 +0200424 .xres = 480,
425 .yres = 800,
426 .pixclock = 37037,
427 .left_margin = 59,
428 .right_margin = 10,
429 .upper_margin = 15,
430 .lower_margin = 15,
431 .hsync_len = 10,
432 .vsync_len = 15,
433 .sync = FB_SYNC_EXT | FB_SYNC_HOR_HIGH_ACT |
434 FB_SYNC_VERT_HIGH_ACT,
435 .vmode = FB_VMODE_NONINTERLACED
436 }
437 }
438#endif
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200439};
440size_t display_count = ARRAY_SIZE(displays);
441
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200442iomux_v3_cfg_t nfc_pads[] = {
443 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
444 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
445 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL),
446 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL),
447 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200448 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
449 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
450 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL),
451 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL),
452 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL),
453 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL),
454 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL),
455 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL),
456 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL),
457 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL),
458 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
459};
460
461static void setup_gpmi_nand(void)
462{
463 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
464
465 /* config gpmi nand iomux */
466 imx_iomux_v3_setup_multiple_pads(nfc_pads,
467 ARRAY_SIZE(nfc_pads));
468
Heiko Schocher05729822015-05-18 13:32:31 +0200469 /* gate ENFC_CLK_ROOT clock first,before clk source switch */
470 clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
471
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200472 /* config gpmi and bch clock to 100 MHz */
473 clrsetbits_le32(&mxc_ccm->cs2cdr,
474 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
475 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
476 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
477 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
478 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
479 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
480
Heiko Schocher05729822015-05-18 13:32:31 +0200481 /* enable ENFC_CLK_ROOT clock */
482 setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
483
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200484 /* enable gpmi and bch clock gating */
485 setbits_le32(&mxc_ccm->CCGR4,
486 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
487 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
488 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
489 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
490 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
491
492 /* enable apbh clock gating */
493 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
494}
495
496int board_init(void)
497{
498 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
499
500 /* address of boot parameters */
501 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
502
Heiko Schocher05729822015-05-18 13:32:31 +0200503 setup_board_gpio();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200504 setup_gpmi_nand();
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100505 setup_display();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200506
507 /* GPIO_1 for USB_OTG_ID */
Heiko Schocher05729822015-05-18 13:32:31 +0200508 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200509 return 0;
510}
511
Heiko Schocher54333792019-12-01 11:23:12 +0100512int board_fit_config_name_match(const char *name)
513{
514 if (gd->board_type == BOARD_TYPE_4 &&
515 strchr(name, 0x34))
516 return 0;
517
518 if (gd->board_type == BOARD_TYPE_7 &&
519 strchr(name, 0x37))
520 return 0;
521
522 return -1;
523}
524
525static void do_board_detect(void)
526{
527 int ret;
528 char s[30];
529
530 /* default use board type 7 */
531 gd->board_type = BOARD_TYPE_7;
532 if (env_init())
533 return;
534
535 ret = env_get_f("panel", s, sizeof(s));
536 if (ret < 0)
537 return;
538
539 if (!strncmp("lg4573", s, 6))
540 gd->board_type = BOARD_TYPE_4;
541}
542
543#ifdef CONFIG_DTB_RESELECT
544int embedded_dtb_select(void)
545{
546 int rescan;
547
548 do_board_detect();
549 fdtdec_resetup(&rescan);
550
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200551 return 0;
552}
553#endif