blob: a3ae037a82ef10ca35173a07961611513fedfd60 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Akshay Bhat197f9872016-01-29 15:16:40 -05002/*
3 * Copyright 2015 Timesys Corporation
4 * Copyright 2015 General Electric Company
5 * Copyright 2012 Freescale Semiconductor, Inc.
Akshay Bhat197f9872016-01-29 15:16:40 -05006 */
7
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060014#include <env.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Ian Ray64450942019-01-31 16:21:18 +020017#include <linux/libfdt.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050018#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>
21#include <asm/mach-imx/video.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050022#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050024#include <miiphy.h>
Martyn Welch18c31ea2018-01-10 20:31:30 +010025#include <net.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050026#include <netdev.h>
27#include <asm/arch/mxc_hdmi.h>
28#include <asm/arch/crm_regs.h>
29#include <asm/io.h>
30#include <asm/arch/sys_proto.h>
Robert Beckett53bab172020-01-31 15:07:54 +020031#include <power/regulator.h>
32#include <power/da9063_pmic.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030033#include <input.h>
Akshay Bhat5d643622016-04-12 18:13:59 -040034#include <pwm.h>
Ian Ray64450942019-01-31 16:21:18 +020035#include <version.h>
Ian Rayc0293da2017-08-22 09:03:54 +030036#include <stdlib.h>
Robert Beckettf746ab62019-11-12 19:15:11 +000037#include <dm/root.h>
Sebastian Reichel9cad0992020-09-02 19:31:43 +020038#include "../common/ge_rtc.h"
Martyn Welch66697ce2017-11-08 15:35:15 +000039#include "../common/vpd_reader.h"
Hannu Lounento37879682018-01-10 20:31:31 +010040#include "../../../drivers/net/e1000.h"
Denis Zalevskiy0d974712019-11-12 19:15:17 +000041#include <pci.h>
Robert Beckettb2185d22020-01-31 15:07:59 +020042#include <panel.h>
Denis Zalevskiy0d974712019-11-12 19:15:17 +000043
Akshay Bhat197f9872016-01-29 15:16:40 -050044DECLARE_GLOBAL_DATA_PTR;
45
Sebastian Reichel30871902020-11-04 17:18:41 +010046#define VPD_PRODUCT_B850 1
47#define VPD_PRODUCT_B650 2
48#define VPD_PRODUCT_B450 3
49
50static int productid; /* Default to generic. */
Nandor Han7a9bb302018-04-25 16:57:01 +020051static struct vpd_cache vpd;
52
Justin Watersef93fc22016-04-13 17:03:18 -040053#define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
54 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
55 PAD_CTL_HYS)
56
Akshay Bhat197f9872016-01-29 15:16:40 -050057int dram_init(void)
58{
Fabio Estevamdd5d4e42016-07-23 13:23:40 -030059 gd->ram_size = imx_ddr_size();
Akshay Bhat197f9872016-01-29 15:16:40 -050060
61 return 0;
62}
63
Akshay Bhat197f9872016-01-29 15:16:40 -050064static int mx6_rgmii_rework(struct phy_device *phydev)
65{
66 /* Configure AR8033 to ouput a 125MHz clk from CLK_25M */
67 /* set device address 0x7 */
68 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
69 /* offset 0x8016: CLK_25M Clock Select */
70 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
71 /* enable register write, no post increment, address 0x7 */
72 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
73 /* set to 125 MHz from local PLL source */
74 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x18);
75
76 /* rgmii tx clock delay enable */
77 /* set debug port address: SerDes Test and System Mode Control */
78 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
79 /* enable rgmii tx clock delay */
Yung-Ching LIN48652c82017-02-21 09:56:56 +080080 /* set the reserved bits to avoid board specific voltage peak issue*/
81 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x3D47);
Akshay Bhat197f9872016-01-29 15:16:40 -050082
83 return 0;
84}
85
86int board_phy_config(struct phy_device *phydev)
87{
88 mx6_rgmii_rework(phydev);
89
90 if (phydev->drv->config)
91 phydev->drv->config(phydev);
92
93 return 0;
94}
95
96#if defined(CONFIG_VIDEO_IPUV3)
Robert Beckettb2185d22020-01-31 15:07:59 +020097static void do_enable_backlight(struct display_info_t const *dev)
98{
99 struct udevice *panel;
100 int ret;
101
102 ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
103 if (ret) {
104 printf("Could not find panel: %d\n", ret);
105 return;
106 }
107
108 panel_set_backlight(panel, 100);
109 panel_enable_backlight(panel);
110}
Akshay Bhat197f9872016-01-29 15:16:40 -0500111
112static void do_enable_hdmi(struct display_info_t const *dev)
113{
114 imx_enable_hdmi_phy();
115}
116
Ian Ray6eac23f2018-04-25 16:57:02 +0200117static int is_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500118{
Sebastian Reichel30871902020-11-04 17:18:41 +0100119 return productid == VPD_PRODUCT_B850;
Ian Ray6eac23f2018-04-25 16:57:02 +0200120}
Akshay Bhat197f9872016-01-29 15:16:40 -0500121
Ian Ray6eac23f2018-04-25 16:57:02 +0200122static int detect_lcd(struct display_info_t const *dev)
123{
124 return !is_b850v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500125}
126
127struct display_info_t const displays[] = {{
128 .bus = -1,
129 .addr = -1,
130 .pixfmt = IPU_PIX_FMT_RGB24,
Ian Rayf8e4fab2018-04-25 16:56:58 +0200131 .detect = detect_lcd,
Robert Beckettb2185d22020-01-31 15:07:59 +0200132 .enable = do_enable_backlight,
Akshay Bhat197f9872016-01-29 15:16:40 -0500133 .mode = {
134 .name = "G121X1-L03",
135 .refresh = 60,
136 .xres = 1024,
137 .yres = 768,
138 .pixclock = 15385,
139 .left_margin = 20,
140 .right_margin = 300,
141 .upper_margin = 30,
142 .lower_margin = 8,
143 .hsync_len = 1,
144 .vsync_len = 1,
145 .sync = FB_SYNC_EXT,
146 .vmode = FB_VMODE_NONINTERLACED
147} }, {
148 .bus = -1,
149 .addr = 3,
150 .pixfmt = IPU_PIX_FMT_RGB24,
151 .detect = detect_hdmi,
152 .enable = do_enable_hdmi,
153 .mode = {
154 .name = "HDMI",
155 .refresh = 60,
156 .xres = 1024,
157 .yres = 768,
158 .pixclock = 15385,
159 .left_margin = 220,
160 .right_margin = 40,
161 .upper_margin = 21,
162 .lower_margin = 7,
163 .hsync_len = 60,
164 .vsync_len = 10,
165 .sync = FB_SYNC_EXT,
166 .vmode = FB_VMODE_NONINTERLACED
167} } };
168size_t display_count = ARRAY_SIZE(displays);
169
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400170static void enable_videopll(void)
171{
172 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
173 s32 timeout = 100000;
174
175 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
176
Ian Ray28540c52018-10-15 09:59:44 +0200177 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
178 * |
179 * PLL5
180 * |
181 * CS2CDR[LDB_DI0_CLK_SEL]
182 * |
183 * +----> LDB_DI0_SERIAL_CLK_ROOT
184 * |
185 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
186 */
187
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400188 clrsetbits_le32(&ccm->analog_pll_video,
189 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
190 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
191 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
Ian Ray28540c52018-10-15 09:59:44 +0200192 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400193
194 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
195 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
196
197 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
198
199 while (timeout--)
200 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
201 break;
202
203 if (timeout < 0)
204 printf("Warning: video pll lock timeout!\n");
205
206 clrsetbits_le32(&ccm->analog_pll_video,
207 BM_ANADIG_PLL_VIDEO_BYPASS,
208 BM_ANADIG_PLL_VIDEO_ENABLE);
209}
210
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400211static void setup_display_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500212{
213 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
214 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500215
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400216 enable_videopll();
217
Ian Ray28540c52018-10-15 09:59:44 +0200218 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
219 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400220
Akshay Bhat197f9872016-01-29 15:16:40 -0500221 imx_setup_hdmi();
222
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400223 /* Set LDB_DI0 as clock source for IPU_DI0 */
224 clrsetbits_le32(&mxc_ccm->chsccdr,
225 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
226 (CHSCCDR_CLK_SEL_LDB_DI0 <<
227 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500228
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400229 /* Turn on IPU LDB DI0 clocks */
230 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
231
232 enable_ipu_clock();
Akshay Bhat197f9872016-01-29 15:16:40 -0500233
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400234 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
235 IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
236 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
237 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
238 IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT |
239 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
240 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
241 IOMUXC_GPR2_SPLIT_MODE_EN_MASK |
242 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
243 IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0,
244 &iomux->gpr[2]);
Akshay Bhat197f9872016-01-29 15:16:40 -0500245
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400246 clrbits_le32(&iomux->gpr[3],
247 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
248 IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
249 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
250}
Akshay Bhat197f9872016-01-29 15:16:40 -0500251
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400252static void setup_display_bx50v3(void)
253{
254 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
255 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500256
Ian Ray66395e82018-04-25 16:57:00 +0200257 enable_videopll();
258
Akshay Bhat66027fe2016-04-12 18:14:00 -0400259 /* When a reset/reboot is performed the display power needs to be turned
260 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
261 * an additional 200ms here. Unfortunately we use external PMIC for
262 * doing the reset, so can not differentiate between POR vs soft reset
263 */
264 mdelay(200);
265
Ian Ray28540c52018-10-15 09:59:44 +0200266 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400267 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
268
269 /* Set LDB_DI0 as clock source for IPU_DI0 */
270 clrsetbits_le32(&mxc_ccm->chsccdr,
271 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
272 (CHSCCDR_CLK_SEL_LDB_DI0 <<
273 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
274
275 /* Turn on IPU LDB DI0 clocks */
276 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
277
278 enable_ipu_clock();
279
280 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
281 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
282 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
283 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
284 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
285 &iomux->gpr[2]);
286
287 clrsetbits_le32(&iomux->gpr[3],
288 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
289 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
290 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500291}
292#endif /* CONFIG_VIDEO_IPUV3 */
293
294/*
295 * Do not overwrite the console
296 * Use always serial for U-Boot console
297 */
298int overwrite_console(void)
299{
300 return 1;
301}
302
Ian Rayc0293da2017-08-22 09:03:54 +0300303#define VPD_TYPE_INVALID 0x00
304#define VPD_BLOCK_NETWORK 0x20
305#define VPD_BLOCK_HWID 0x44
Martyn Welch18c31ea2018-01-10 20:31:30 +0100306#define VPD_HAS_MAC1 0x1
Hannu Lounento37879682018-01-10 20:31:31 +0100307#define VPD_HAS_MAC2 0x2
Martyn Welch18c31ea2018-01-10 20:31:30 +0100308#define VPD_MAC_ADDRESS_LENGTH 6
Ian Rayc0293da2017-08-22 09:03:54 +0300309
310struct vpd_cache {
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200311 bool is_read;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100312 u8 product_id;
313 u8 has;
314 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
Hannu Lounento37879682018-01-10 20:31:31 +0100315 unsigned char mac2[VPD_MAC_ADDRESS_LENGTH];
Ian Rayc0293da2017-08-22 09:03:54 +0300316};
317
318/*
319 * Extracts MAC and product information from the VPD.
320 */
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200321static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
Martyn Welch18c31ea2018-01-10 20:31:30 +0100322 size_t size, u8 const *data)
Ian Rayc0293da2017-08-22 09:03:54 +0300323{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100324 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
325 size >= 1) {
Ian Rayc0293da2017-08-22 09:03:54 +0300326 vpd->product_id = data[0];
Martyn Welch18c31ea2018-01-10 20:31:30 +0100327 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
328 type != VPD_TYPE_INVALID) {
329 if (size >= 6) {
330 vpd->has |= VPD_HAS_MAC1;
331 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
332 }
Hannu Lounento37879682018-01-10 20:31:31 +0100333 if (size >= 12) {
334 vpd->has |= VPD_HAS_MAC2;
335 memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH);
336 }
Ian Rayc0293da2017-08-22 09:03:54 +0300337 }
338
339 return 0;
340}
341
Ian Rayc0293da2017-08-22 09:03:54 +0300342static void process_vpd(struct vpd_cache *vpd)
343{
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000344 int fec_index = 0;
Hannu Lounento37879682018-01-10 20:31:31 +0100345 int i210_index = -1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100346
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200347 if (!vpd->is_read) {
348 printf("VPD wasn't read");
349 return;
350 }
351
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000352 if (vpd->has & VPD_HAS_MAC1)
353 eth_env_set_enetaddr_by_index("eth", fec_index, vpd->mac1);
354
355 env_set("ethact", "eth0");
356
Martyn Welch18c31ea2018-01-10 20:31:30 +0100357 switch (vpd->product_id) {
358 case VPD_PRODUCT_B450:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000359 i210_index = 1;
Ian Rayb52e2522018-01-10 20:31:33 +0100360 break;
361 case VPD_PRODUCT_B650:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000362 i210_index = 1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100363 break;
364 case VPD_PRODUCT_B850:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000365 i210_index = 2;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100366 break;
Ian Rayc0293da2017-08-22 09:03:54 +0300367 }
Martyn Welch18c31ea2018-01-10 20:31:30 +0100368
Hannu Lounento37879682018-01-10 20:31:31 +0100369 if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2))
370 eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2);
Ian Rayc0293da2017-08-22 09:03:54 +0300371}
372
Akshay Bhat197f9872016-01-29 15:16:40 -0500373static iomux_v3_cfg_t const misc_pads[] = {
374 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
Justin Watersef93fc22016-04-13 17:03:18 -0400375 MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NC_PAD_CTRL),
376 MX6_PAD_EIM_CS0__GPIO2_IO23 | MUX_PAD_CTRL(NC_PAD_CTRL),
377 MX6_PAD_EIM_CS1__GPIO2_IO24 | MUX_PAD_CTRL(NC_PAD_CTRL),
378 MX6_PAD_EIM_OE__GPIO2_IO25 | MUX_PAD_CTRL(NC_PAD_CTRL),
379 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NC_PAD_CTRL),
380 MX6_PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NC_PAD_CTRL),
Martyn Welch110f5d92018-01-10 20:31:32 +0100381 MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500382};
383#define SUS_S3_OUT IMX_GPIO_NR(4, 11)
Ian Raya8203cc2020-11-04 17:18:43 +0100384#define PWGIN_IN IMX_GPIO_NR(4, 14)
Akshay Bhat197f9872016-01-29 15:16:40 -0500385#define WIFI_EN IMX_GPIO_NR(6, 14)
386
387int board_early_init_f(void)
388{
389 imx_iomux_v3_setup_multiple_pads(misc_pads,
390 ARRAY_SIZE(misc_pads));
391
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400392#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray28540c52018-10-15 09:59:44 +0200393 /* Set LDB clock to Video PLL */
394 select_ldb_di_clock_source(MXC_PLL5_CLK);
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400395#endif
Akshay Bhat197f9872016-01-29 15:16:40 -0500396 return 0;
397}
398
399int board_init(void)
400{
Sebastian Reichel5f05ebc2020-09-02 19:31:45 +0200401 if (!read_i2c_vpd(&vpd, vpd_callback)) {
Robert Beckettf746ab62019-11-12 19:15:11 +0000402 int ret, rescan;
403
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200404 vpd.is_read = true;
Sebastian Reichel30871902020-11-04 17:18:41 +0100405 productid = vpd.product_id;
Robert Beckettf746ab62019-11-12 19:15:11 +0000406
407 ret = fdtdec_resetup(&rescan);
408 if (!ret && rescan) {
409 dm_uninit();
410 dm_init_and_scan(false);
411 }
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200412 }
Nandor Han7a9bb302018-04-25 16:57:01 +0200413
Ian Ray5f1e3442019-01-31 16:21:13 +0200414 gpio_request(SUS_S3_OUT, "sus_s3_out");
Akshay Bhat197f9872016-01-29 15:16:40 -0500415 gpio_direction_output(SUS_S3_OUT, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200416
Ian Raya8203cc2020-11-04 17:18:43 +0100417 gpio_request(PWGIN_IN, "pwgin_in");
418 gpio_direction_input(PWGIN_IN);
419
Ian Ray5f1e3442019-01-31 16:21:13 +0200420 gpio_request(WIFI_EN, "wifi_en");
Akshay Bhat197f9872016-01-29 15:16:40 -0500421 gpio_direction_output(WIFI_EN, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200422
Akshay Bhat197f9872016-01-29 15:16:40 -0500423#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray6eac23f2018-04-25 16:57:02 +0200424 if (is_b850v3())
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400425 setup_display_b850v3();
426 else
427 setup_display_bx50v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500428#endif
Ian Ray5f1e3442019-01-31 16:21:13 +0200429
Akshay Bhat197f9872016-01-29 15:16:40 -0500430 /* address of boot parameters */
431 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
432
Akshay Bhat197f9872016-01-29 15:16:40 -0500433 return 0;
434}
435
436#ifdef CONFIG_CMD_BMODE
437static const struct boot_mode board_boot_modes[] = {
438 /* 4 bit bus width */
439 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
440 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
441 {NULL, 0},
442};
443#endif
444
Ken Linc7219fc2016-11-18 12:20:54 -0500445void pmic_init(void)
446{
Robert Beckett53bab172020-01-31 15:07:54 +0200447 struct udevice *reg;
448 int ret, i;
449 static const char * const bucks[] = {
450 "bcore1",
451 "bcore2",
452 "bpro",
453 "bmem",
454 "bio",
455 "bperi",
456 };
Ken Linc7219fc2016-11-18 12:20:54 -0500457
Robert Beckett53bab172020-01-31 15:07:54 +0200458 for (i = 0; i < ARRAY_SIZE(bucks); i++) {
459 ret = regulator_get_by_devname(bucks[i], &reg);
460 if (reg < 0) {
461 printf("%s(): Unable to get regulator %s: %d\n",
462 __func__, bucks[i], ret);
463 continue;
464 }
465 regulator_set_mode(reg, DA9063_BUCKMODE_SYNC);
466 }
Ken Linc7219fc2016-11-18 12:20:54 -0500467}
468
Ian Raya8203cc2020-11-04 17:18:43 +0100469static void detect_boot_cause(void)
470{
471 const char *cause = "POR";
472
473 if (is_b850v3())
474 if (!gpio_get_value(PWGIN_IN))
475 cause = "PM_WDOG";
476
477 env_set("bootcause", cause);
478}
479
Akshay Bhat197f9872016-01-29 15:16:40 -0500480int board_late_init(void)
481{
Nandor Han7a9bb302018-04-25 16:57:01 +0200482 process_vpd(&vpd);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100483
Akshay Bhat197f9872016-01-29 15:16:40 -0500484#ifdef CONFIG_CMD_BMODE
485 add_board_boot_modes(board_boot_modes);
486#endif
Andrew Shadurac26583d2016-05-24 15:56:17 +0200487
Ian Rayd8c60992018-04-25 16:57:03 +0200488 if (is_b850v3())
489 env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60");
Ian Ray476e4e62018-10-15 09:59:45 +0200490 else
491 env_set("videoargs", "video=LVDS-1:1024x768@65");
Ian Rayd8c60992018-04-25 16:57:03 +0200492
Ian Raya8203cc2020-11-04 17:18:43 +0100493 detect_boot_cause();
494
Ken Linc7219fc2016-11-18 12:20:54 -0500495 /* board specific pmic init */
496 pmic_init();
497
Nandor Hanae3c6d22018-01-10 20:31:38 +0100498 check_time();
499
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000500 pci_init();
501
Akshay Bhat197f9872016-01-29 15:16:40 -0500502 return 0;
503}
504
Hannu Lounento37879682018-01-10 20:31:31 +0100505/*
506 * Removes the 'eth[0-9]*addr' environment variable with the given index
507 *
508 * @param index [in] the index of the eth_device whose variable is to be removed
509 */
510static void remove_ethaddr_env_var(int index)
511{
512 char env_var_name[9];
513
514 sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index);
515 env_set(env_var_name, NULL);
516}
517
Martyn Welch18c31ea2018-01-10 20:31:30 +0100518int last_stage_init(void)
519{
Hannu Lounento37879682018-01-10 20:31:31 +0100520 int i;
521
522 /*
523 * Remove first three ethaddr which may have been created by
524 * function process_vpd().
525 */
526 for (i = 0; i < 3; ++i)
527 remove_ethaddr_env_var(i);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100528
529 return 0;
530}
531
Akshay Bhat197f9872016-01-29 15:16:40 -0500532int checkboard(void)
533{
534 printf("BOARD: %s\n", CONFIG_BOARD_NAME);
535 return 0;
536}
Ian Ray40133682018-04-04 10:50:17 +0200537
Ian Ray64450942019-01-31 16:21:18 +0200538#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900539int ft_board_setup(void *blob, struct bd_info *bd)
Ian Ray64450942019-01-31 16:21:18 +0200540{
Ian Rayc69217c2019-11-12 19:15:18 +0000541 char *rtc_status = env_get("rtc_status");
542
Ian Ray64450942019-01-31 16:21:18 +0200543 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
Ian Rayc69217c2019-11-12 19:15:18 +0000544 strlen(version_string) + 1);
545
546 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
547 strlen(rtc_status) + 1);
Ian Ray64450942019-01-31 16:21:18 +0200548 return 0;
549}
550#endif
551
Robert Beckettf746ab62019-11-12 19:15:11 +0000552int board_fit_config_name_match(const char *name)
553{
Sebastian Reichel99453902020-12-15 00:41:56 +0100554 const char *machine = name;
555
Robert Beckettf746ab62019-11-12 19:15:11 +0000556 if (!vpd.is_read)
557 return strcmp(name, "imx6q-bx50v3");
558
Sebastian Reichel99453902020-12-15 00:41:56 +0100559 if (!strncmp(machine, "Boot ", 5))
560 machine += 5;
561 if (!strncmp(machine, "imx6q-", 6))
562 machine += 6;
563
Robert Beckettf746ab62019-11-12 19:15:11 +0000564 switch (vpd.product_id) {
565 case VPD_PRODUCT_B450:
Sebastian Reichel99453902020-12-15 00:41:56 +0100566 return strcasecmp(machine, "b450v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000567 case VPD_PRODUCT_B650:
Sebastian Reichel99453902020-12-15 00:41:56 +0100568 return strcasecmp(machine, "b650v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000569 case VPD_PRODUCT_B850:
Sebastian Reichel99453902020-12-15 00:41:56 +0100570 return strcasecmp(machine, "b850v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000571 default:
572 return -1;
573 }
574}
575
576int embedded_dtb_select(void)
577{
578 vpd.is_read = false;
579 return fdtdec_setup();
580}