blob: 5095cf65d1391cb6305649ae0c9715cf8ed85a15 [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 Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020013#include <asm/arch/clock.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/iomux.h>
16#include <asm/arch/mx6-pins.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090017#include <linux/errno.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020018#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020019#include <asm/mach-imx/iomux-v3.h>
20#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/video.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020022#include <asm/arch/crm_regs.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020023#include <asm/io.h>
24#include <asm/arch/sys_proto.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010025#include <bmp_logo.h>
Heiko Schocher54333792019-12-01 11:23:12 +010026#include <dm/root.h>
Heiko Schochera051ee92019-12-01 11:23:11 +010027#include <env.h>
Heiko Schocherc6729682019-12-01 11:23:23 +010028#include <i2c_eeprom.h>
29#include <i2c.h>
Heiko Schochera051ee92019-12-01 11:23:11 +010030#include <micrel.h>
Heiko Schocher441b0542019-12-01 11:23:18 +010031#include <miiphy.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010032#include <lcd.h>
Heiko Schocher495956b2019-12-01 11:23:15 +010033#include <led.h>
Heiko Schocherf5210a92020-03-02 09:44:03 +010034#include <power/pmic.h>
35#include <power/regulator.h>
36#include <power/da9063_pmic.h>
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010037#include <splash.h>
38#include <video_fb.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020039
40DECLARE_GLOBAL_DATA_PTR;
41
Heiko Schocher54333792019-12-01 11:23:12 +010042enum {
43 BOARD_TYPE_4 = 4,
44 BOARD_TYPE_7 = 7,
45};
46
47#define ARI_BT_4 "aristainetos2_4@2"
48#define ARI_BT_7 "aristainetos2_7@1"
49
Heiko Schochera051ee92019-12-01 11:23:11 +010050int board_phy_config(struct phy_device *phydev)
51{
52 /* control data pad skew - devaddr = 0x02, register = 0x04 */
53 ksz9031_phy_extended_write(phydev, 0x02,
54 MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
55 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
56 /* rx data pad skew - devaddr = 0x02, register = 0x05 */
57 ksz9031_phy_extended_write(phydev, 0x02,
58 MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
59 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
60 /* tx data pad skew - devaddr = 0x02, register = 0x06 */
61 ksz9031_phy_extended_write(phydev, 0x02,
62 MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
63 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
64 /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */
65 ksz9031_phy_extended_write(phydev, 0x02,
66 MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
67 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF);
68
69 if (phydev->drv->config)
70 phydev->drv->config(phydev);
71
72 return 0;
73}
74
Heiko Schochera051ee92019-12-01 11:23:11 +010075static int rotate_logo_one(unsigned char *out, unsigned char *in)
76{
77 int i, j;
78
79 for (i = 0; i < BMP_LOGO_WIDTH; i++)
80 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
81 out[j * BMP_LOGO_WIDTH + BMP_LOGO_HEIGHT - 1 - i] =
82 in[i * BMP_LOGO_WIDTH + j];
83 return 0;
84}
85
86/*
87 * Rotate the BMP_LOGO (only)
88 * Will only work, if the logo is square, as
89 * BMP_LOGO_HEIGHT and BMP_LOGO_WIDTH are defines, not variables
90 */
91void rotate_logo(int rotations)
92{
93 unsigned char out_logo[BMP_LOGO_WIDTH * BMP_LOGO_HEIGHT];
Heiko Schocher8f4a1b92019-12-01 11:23:19 +010094 struct bmp_header *header;
Heiko Schochera051ee92019-12-01 11:23:11 +010095 unsigned char *in_logo;
96 int i, j;
97
98 if (BMP_LOGO_WIDTH != BMP_LOGO_HEIGHT)
99 return;
100
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100101 header = (struct bmp_header *)bmp_logo_bitmap;
102 in_logo = bmp_logo_bitmap + header->data_offset;
Heiko Schochera051ee92019-12-01 11:23:11 +0100103
104 /* one 90 degree rotation */
105 if (rotations == 1 || rotations == 2 || rotations == 3)
106 rotate_logo_one(out_logo, in_logo);
107
108 /* second 90 degree rotation */
109 if (rotations == 2 || rotations == 3)
110 rotate_logo_one(in_logo, out_logo);
111
112 /* third 90 degree rotation */
113 if (rotations == 3)
114 rotate_logo_one(out_logo, in_logo);
115
116 /* copy result back to original array */
117 if (rotations == 1 || rotations == 3)
118 for (i = 0; i < BMP_LOGO_WIDTH; i++)
119 for (j = 0; j < BMP_LOGO_HEIGHT; j++)
120 in_logo[i * BMP_LOGO_WIDTH + j] =
121 out_logo[i * BMP_LOGO_WIDTH + j];
122}
123
Heiko Schochera051ee92019-12-01 11:23:11 +0100124static void enable_lvds(struct display_info_t const *dev)
125{
126 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
127 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
128 int reg;
129 s32 timeout = 100000;
130
131 /* set PLL5 clock */
132 reg = readl(&ccm->analog_pll_video);
133 reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN;
134 writel(reg, &ccm->analog_pll_video);
135
136 /* set PLL5 to 232720000Hz */
137 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
138 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x26);
139 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
140 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
141 writel(reg, &ccm->analog_pll_video);
142
143 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xC0238),
144 &ccm->analog_pll_video_num);
145 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xF4240),
146 &ccm->analog_pll_video_denom);
147
148 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
149 writel(reg, &ccm->analog_pll_video);
150
151 while (timeout--)
152 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
153 break;
154 if (timeout < 0)
155 printf("Warning: video pll lock timeout!\n");
156
157 reg = readl(&ccm->analog_pll_video);
158 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
159 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
160 writel(reg, &ccm->analog_pll_video);
161
162 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
163 reg = readl(&ccm->cs2cdr);
164 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
165 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
166 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
167 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
168 writel(reg, &ccm->cs2cdr);
169
170 reg = readl(&ccm->cscmr2);
171 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
172 writel(reg, &ccm->cscmr2);
173
174 reg = readl(&ccm->chsccdr);
175 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
176 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
177 writel(reg, &ccm->chsccdr);
178
179 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
180 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
181 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
182 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
183 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
184 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
185 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
186 writel(reg, &iomux->gpr[2]);
187
188 reg = readl(&iomux->gpr[3]);
189 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
190 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
191 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
192 writel(reg, &iomux->gpr[3]);
193}
194
195static void enable_spi_display(struct display_info_t const *dev)
196{
197 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
198 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
199 int reg;
200 s32 timeout = 100000;
201
202#if defined(CONFIG_VIDEO_BMP_LOGO)
203 rotate_logo(3); /* portrait display in landscape mode */
204#endif
205
Heiko Schochera051ee92019-12-01 11:23:11 +0100206 reg = readl(&ccm->cs2cdr);
207
208 /* select pll 5 clock */
209 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
210 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
211 writel(reg, &ccm->cs2cdr);
212
213 /* set PLL5 to 197994996Hz */
214 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
215 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(0x21);
216 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
217 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0);
218 writel(reg, &ccm->analog_pll_video);
219
220 writel(BF_ANADIG_PLL_VIDEO_NUM_A(0xfbf4),
221 &ccm->analog_pll_video_num);
222 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(0xf4240),
223 &ccm->analog_pll_video_denom);
224
225 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
226 writel(reg, &ccm->analog_pll_video);
227
228 while (timeout--)
229 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
230 break;
231 if (timeout < 0)
232 printf("Warning: video pll lock timeout!\n");
233
234 reg = readl(&ccm->analog_pll_video);
235 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
236 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
237 writel(reg, &ccm->analog_pll_video);
238
239 /* set LDB0, LDB1 clk select to 000/000 (PLL5 clock) */
240 reg = readl(&ccm->cs2cdr);
241 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
242 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
243 reg |= (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
244 | (0 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
245 writel(reg, &ccm->cs2cdr);
246
247 reg = readl(&ccm->cscmr2);
248 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
249 writel(reg, &ccm->cscmr2);
250
251 reg = readl(&ccm->chsccdr);
252 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
253 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
254 reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK;
255 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET);
256 reg &= ~MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK;
257 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
258 writel(reg, &ccm->chsccdr);
259
260 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
261 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
262 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH
263 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
264 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
265 | IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
266 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
267 writel(reg, &iomux->gpr[2]);
268
269 reg = readl(&iomux->gpr[3]);
270 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
271 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
272 << IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
273 writel(reg, &iomux->gpr[3]);
Heiko Schochera051ee92019-12-01 11:23:11 +0100274}
275
276static void setup_display(void)
277{
278 enable_ipu_clock();
Heiko Schochera051ee92019-12-01 11:23:11 +0100279}
280
Heiko Schochera051ee92019-12-01 11:23:11 +0100281static void set_gpr_register(void)
282{
283 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
284
285 writel(IOMUXC_GPR1_APP_CLK_REQ_N | IOMUXC_GPR1_PCIE_RDY_L23 |
286 IOMUXC_GPR1_EXC_MON_SLVE |
287 (2 << IOMUXC_GPR1_ADDRS0_OFFSET) |
288 IOMUXC_GPR1_ACT_CS0,
289 &iomuxc_regs->gpr[1]);
290 writel(0x0, &iomuxc_regs->gpr[8]);
291 writel(IOMUXC_GPR12_ARMP_IPG_CLK_EN | IOMUXC_GPR12_ARMP_AHB_CLK_EN |
292 IOMUXC_GPR12_ARMP_ATB_CLK_EN | IOMUXC_GPR12_ARMP_APB_CLK_EN,
293 &iomuxc_regs->gpr[12]);
294}
295
Heiko Schocher54333792019-12-01 11:23:12 +0100296extern char __bss_start[], __bss_end[];
Heiko Schochera051ee92019-12-01 11:23:11 +0100297int board_early_init_f(void)
298{
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100299 select_ldb_di_clock_source(MXC_PLL5_CLK);
Heiko Schochera051ee92019-12-01 11:23:11 +0100300 set_gpr_register();
Heiko Schocher54333792019-12-01 11:23:12 +0100301
302 /*
303 * clear bss here, so we can use spi driver
304 * before relocation and read Environment
305 * from spi flash.
306 */
307 memset(__bss_start, 0x00, __bss_end - __bss_start);
308
Heiko Schochera051ee92019-12-01 11:23:11 +0100309 return 0;
310}
311
Heiko Schocher495956b2019-12-01 11:23:15 +0100312static void setup_one_led(char *label, int state)
Heiko Schochera051ee92019-12-01 11:23:11 +0100313{
Heiko Schocher495956b2019-12-01 11:23:15 +0100314 struct udevice *dev;
315 int ret;
Heiko Schochera051ee92019-12-01 11:23:11 +0100316
Heiko Schocher495956b2019-12-01 11:23:15 +0100317 ret = led_get_by_label(label, &dev);
318 if (ret == 0)
319 led_set_state(dev, state);
320}
321
322static void setup_board_gpio(void)
323{
324 setup_one_led("led_ena", LEDST_ON);
Heiko Schochera051ee92019-12-01 11:23:11 +0100325 /* switch off Status LEDs */
Heiko Schocher495956b2019-12-01 11:23:15 +0100326 setup_one_led("led_yellow", LEDST_OFF);
327 setup_one_led("led_red", LEDST_OFF);
328 setup_one_led("led_green", LEDST_OFF);
329 setup_one_led("led_blue", LEDST_OFF);
Heiko Schochera051ee92019-12-01 11:23:11 +0100330}
331
Heiko Schocherc6729682019-12-01 11:23:23 +0100332#define ARI_RESC_FMT "setenv rescue_reason setenv bootargs \\${bootargs}" \
333 " rescueReason=%d "
334
335static void aristainetos_run_rescue_command(int reason)
336{
337 char rescue_reason_command[80];
338
339 sprintf(rescue_reason_command, ARI_RESC_FMT, reason);
340 run_command(rescue_reason_command, 0);
341}
342
343static int aristainetos_eeprom(void)
344{
345 struct udevice *dev;
346 int off;
347 int ret;
348 u8 data[0x10];
349 u8 rescue_reason;
350
351 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
352 if (off < 0) {
353 printf("%s: No eeprom0 path offset\n", __func__);
354 return off;
355 }
356
357 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
358 if (ret) {
359 printf("%s: Could not find EEPROM\n", __func__);
360 return ret;
361 }
362
363 ret = i2c_set_chip_offset_len(dev, 2);
364 if (ret)
365 return ret;
366
367 ret = i2c_eeprom_read(dev, 0x1ff0, (uint8_t *)data, 6);
368 if (ret) {
369 printf("%s: Could not read EEPROM\n", __func__);
370 return ret;
371 }
372
373 if (strncmp((char *)&data[3], "ReScUe", 6) == 0) {
374 rescue_reason = *(uint8_t *)&data[9];
375 memset(&data[3], 0xff, 7);
376 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)&data[3], 7);
377 printf("\nBooting into Rescue System (EEPROM)\n");
378 aristainetos_run_rescue_command(rescue_reason);
379 run_command("run rescue_load_fit rescueboot", 0);
380 } else if (strncmp((char *)data, "DeF", 3) == 0) {
381 memset(data, 0xff, 3);
382 i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)data, 3);
383 printf("\nClear u-boot environment (set back to defaults)\n");
384 run_command("run default_env; saveenv; saveenv", 0);
385 }
386
387 return 0;
388};
389
Heiko Schochere3379da2019-12-01 11:23:26 +0100390static void aristainetos_bootmode_settings(void)
Heiko Schochera051ee92019-12-01 11:23:11 +0100391{
Heiko Schochere3379da2019-12-01 11:23:26 +0100392 struct gpio_desc *desc;
393 struct src *psrc = (struct src *)SRC_BASE_ADDR;
394 unsigned int sbmr1 = readl(&psrc->sbmr1);
Heiko Schochera051ee92019-12-01 11:23:11 +0100395 char *my_bootdelay;
396 char bootmode = 0;
Heiko Schocher495956b2019-12-01 11:23:15 +0100397 int ret;
Heiko Schochera051ee92019-12-01 11:23:11 +0100398
399 /*
400 * Check the boot-source. If booting from NOR Flash,
401 * disable bootdelay
402 */
Heiko Schochere3379da2019-12-01 11:23:26 +0100403 ret = gpio_hog_lookup_name("bootsel0", &desc);
404 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100405 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 0;
Heiko Schochere3379da2019-12-01 11:23:26 +0100406 ret = gpio_hog_lookup_name("bootsel1", &desc);
407 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100408 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 1;
Heiko Schochere3379da2019-12-01 11:23:26 +0100409 ret = gpio_hog_lookup_name("bootsel2", &desc);
410 if (!ret)
Heiko Schocher495956b2019-12-01 11:23:15 +0100411 bootmode |= (dm_gpio_get_value(desc) ? 1 : 0) << 2;
Heiko Schochera051ee92019-12-01 11:23:11 +0100412
413 if (bootmode == 7) {
414 my_bootdelay = env_get("nor_bootdelay");
Heiko Schochere3379da2019-12-01 11:23:26 +0100415 if (my_bootdelay)
Heiko Schochera051ee92019-12-01 11:23:11 +0100416 env_set("bootdelay", my_bootdelay);
417 else
418 env_set("bootdelay", "-2");
419 }
420
Heiko Schochere3379da2019-12-01 11:23:26 +0100421 if (sbmr1 & 0x40) {
422 env_set("bootmode", "1");
423 printf("SD bootmode jumper set!\n");
424 } else {
425 env_set("bootmode", "0");
426 }
427
Heiko Schocher495956b2019-12-01 11:23:15 +0100428 /* read out some jumper values*/
429 ret = gpio_hog_lookup_name("env_reset", &desc);
430 if (!ret) {
431 if (dm_gpio_get_value(desc)) {
432 printf("\nClear env (set back to defaults)\n");
433 run_command("run default_env; saveenv; saveenv", 0);
434 }
435 }
436 ret = gpio_hog_lookup_name("boot_rescue", &desc);
437 if (!ret) {
438 if (dm_gpio_get_value(desc)) {
439 aristainetos_run_rescue_command(16);
440 run_command("run rescue_xload_boot", 0);
441 }
442 }
Heiko Schochere3379da2019-12-01 11:23:26 +0100443}
444
Heiko Schocherf5210a92020-03-02 09:44:03 +0100445#if defined(CONFIG_DM_PMIC_DA9063)
446/*
447 * On the aristainetos2c boards the PMIC needs to be initialized,
448 * because the Ethernet PHY uses a different regulator that is not
449 * setup per hardware default. This does not influence the other versions
450 * as this regulator isn't used there at all.
451 *
452 * Unfortunately we have not yet a interface to setup all
453 * values we need.
454 */
455static int setup_pmic_voltages(void)
456{
457 struct udevice *dev;
458 int off;
459 int ret;
460
461 off = fdt_path_offset(gd->fdt_blob, "pmic0");
462 if (off < 0) {
463 printf("%s: No pmic path offset\n", __func__);
464 return off;
465 }
466
467 ret = uclass_get_device_by_of_offset(UCLASS_PMIC, off, &dev);
468 if (ret) {
469 printf("%s: Could not find PMIC\n", __func__);
470 return ret;
471 }
472
473 pmic_reg_write(dev, DA9063_REG_PAGE_CON, 0x01);
474 pmic_reg_write(dev, DA9063_REG_BPRO_CFG, 0xc1);
475 ret = pmic_reg_read(dev, DA9063_REG_BUCK_ILIM_B);
476 if (ret < 0) {
477 printf("%s: error %d get register\n", __func__, ret);
478 return ret;
479 }
480 ret &= 0xf0;
481 ret |= 0x09;
482 pmic_reg_write(dev, DA9063_REG_BUCK_ILIM_B, ret);
483 pmic_reg_write(dev, DA9063_REG_VBPRO_A, 0x43);
484 pmic_reg_write(dev, DA9063_REG_VBPRO_B, 0xc3);
485
486 return 0;
487}
488#else
489static int setup_pmic_voltages(void)
490{
491 return 0;
492}
493#endif
494
Heiko Schochere3379da2019-12-01 11:23:26 +0100495int board_late_init(void)
496{
497 int x, y;
498
499 led_default_state();
500 splash_get_pos(&x, &y);
501 bmp_display((ulong)&bmp_logo_bitmap[0], x, y);
502
503 aristainetos_bootmode_settings();
Heiko Schocher495956b2019-12-01 11:23:15 +0100504
Heiko Schocherc6729682019-12-01 11:23:23 +0100505 /* eeprom work */
506 aristainetos_eeprom();
507
Heiko Schocher54333792019-12-01 11:23:12 +0100508 /* set board_type */
509 if (gd->board_type == BOARD_TYPE_4)
510 env_set("board_type", ARI_BT_4);
511 else
512 env_set("board_type", ARI_BT_7);
Heiko Schochere3379da2019-12-01 11:23:26 +0100513
Heiko Schocherf5210a92020-03-02 09:44:03 +0100514 if (setup_pmic_voltages())
515 printf("Error setup PMIC\n");
516
Heiko Schochera051ee92019-12-01 11:23:11 +0100517 return 0;
518}
Heiko Schocher05729822015-05-18 13:32:31 +0200519
Heiko Schocher05729822015-05-18 13:32:31 +0200520int dram_init(void)
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200521{
Fabio Estevam1b23fe52016-07-23 13:23:39 -0300522 gd->ram_size = imx_ddr_size();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200523
Heiko Schocher05729822015-05-18 13:32:31 +0200524 return 0;
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200525}
526
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200527struct display_info_t const displays[] = {
528 {
529 .bus = -1,
530 .addr = 0,
531 .pixfmt = IPU_PIX_FMT_RGB24,
532 .detect = NULL,
533 .enable = enable_lvds,
534 .mode = {
535 .name = "lb07wv8",
536 .refresh = 60,
537 .xres = 800,
538 .yres = 480,
Heiko Schocher27813292015-08-11 08:09:44 +0200539 .pixclock = 30066,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200540 .left_margin = 88,
541 .right_margin = 88,
Heiko Schocher27813292015-08-11 08:09:44 +0200542 .upper_margin = 20,
543 .lower_margin = 20,
Heiko Schocher69f0e442015-01-20 10:06:18 +0100544 .hsync_len = 80,
Heiko Schocher27813292015-08-11 08:09:44 +0200545 .vsync_len = 5,
546 .sync = FB_SYNC_EXT,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200547 .vmode = FB_VMODE_NONINTERLACED
548 }
549 }
Heiko Schocherfbe7e2f2019-12-01 11:23:31 +0100550#if ((CONFIG_SYS_BOARD_VERSION == 2) || \
551 (CONFIG_SYS_BOARD_VERSION == 3) || \
Heiko Schocher74758a92019-12-01 11:23:32 +0100552 (CONFIG_SYS_BOARD_VERSION == 4) || \
553 (CONFIG_SYS_BOARD_VERSION == 5))
Heiko Schocher05729822015-05-18 13:32:31 +0200554 , {
555 .bus = -1,
556 .addr = 0,
557 .pixfmt = IPU_PIX_FMT_RGB24,
558 .detect = NULL,
559 .enable = enable_spi_display,
560 .mode = {
561 .name = "lg4573",
Heiko Schocher27813292015-08-11 08:09:44 +0200562 .refresh = 57,
Heiko Schocher05729822015-05-18 13:32:31 +0200563 .xres = 480,
564 .yres = 800,
565 .pixclock = 37037,
566 .left_margin = 59,
567 .right_margin = 10,
568 .upper_margin = 15,
569 .lower_margin = 15,
570 .hsync_len = 10,
571 .vsync_len = 15,
572 .sync = FB_SYNC_EXT | FB_SYNC_HOR_HIGH_ACT |
573 FB_SYNC_VERT_HIGH_ACT,
574 .vmode = FB_VMODE_NONINTERLACED
575 }
576 }
577#endif
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200578};
579size_t display_count = ARRAY_SIZE(displays);
580
Heiko Schocher0517d232020-01-30 14:10:05 +0100581#if defined(CONFIG_MTD_RAW_NAND)
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200582iomux_v3_cfg_t nfc_pads[] = {
583 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
584 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
585 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL),
586 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL),
587 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200588 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
589 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
590 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL),
591 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL),
592 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL),
593 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL),
594 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL),
595 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL),
596 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL),
597 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL),
598 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
599};
600
601static void setup_gpmi_nand(void)
602{
603 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
604
605 /* config gpmi nand iomux */
606 imx_iomux_v3_setup_multiple_pads(nfc_pads,
607 ARRAY_SIZE(nfc_pads));
608
Heiko Schocher05729822015-05-18 13:32:31 +0200609 /* gate ENFC_CLK_ROOT clock first,before clk source switch */
610 clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
611
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200612 /* config gpmi and bch clock to 100 MHz */
613 clrsetbits_le32(&mxc_ccm->cs2cdr,
614 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
615 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
616 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
617 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
618 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
619 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
620
Heiko Schocher05729822015-05-18 13:32:31 +0200621 /* enable ENFC_CLK_ROOT clock */
622 setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
623
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200624 /* enable gpmi and bch clock gating */
625 setbits_le32(&mxc_ccm->CCGR4,
626 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
627 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
628 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
629 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
630 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
631
632 /* enable apbh clock gating */
633 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
634}
Heiko Schocher74758a92019-12-01 11:23:32 +0100635#else
636static void setup_gpmi_nand(void)
637{
638}
639#endif
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200640
641int board_init(void)
642{
643 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
644
645 /* address of boot parameters */
646 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
647
Heiko Schocher05729822015-05-18 13:32:31 +0200648 setup_board_gpio();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200649 setup_gpmi_nand();
Heiko Schocher8f4a1b92019-12-01 11:23:19 +0100650 setup_display();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200651
652 /* GPIO_1 for USB_OTG_ID */
Heiko Schocher05729822015-05-18 13:32:31 +0200653 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200654 return 0;
655}
656
Heiko Schocher54333792019-12-01 11:23:12 +0100657int board_fit_config_name_match(const char *name)
658{
659 if (gd->board_type == BOARD_TYPE_4 &&
660 strchr(name, 0x34))
661 return 0;
662
663 if (gd->board_type == BOARD_TYPE_7 &&
664 strchr(name, 0x37))
665 return 0;
666
667 return -1;
668}
669
670static void do_board_detect(void)
671{
672 int ret;
673 char s[30];
674
675 /* default use board type 7 */
676 gd->board_type = BOARD_TYPE_7;
677 if (env_init())
678 return;
679
680 ret = env_get_f("panel", s, sizeof(s));
681 if (ret < 0)
682 return;
683
684 if (!strncmp("lg4573", s, 6))
685 gd->board_type = BOARD_TYPE_4;
686}
687
688#ifdef CONFIG_DTB_RESELECT
689int embedded_dtb_select(void)
690{
691 int rescan;
692
693 do_board_detect();
694 fdtdec_resetup(&rescan);
695
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200696 return 0;
697}
698#endif