blob: e1d08475e9492d81fdc4962b4e70fb9d25da3b86 [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 Glass1cedca12023-08-21 21:17:01 -06008#include <event.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06009#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050011#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
14#include <asm/arch/mx6-pins.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060015#include <env.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060017#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090018#include <linux/errno.h>
Ian Ray64450942019-01-31 16:21:18 +020019#include <linux/libfdt.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050020#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/iomux-v3.h>
22#include <asm/mach-imx/boot_mode.h>
23#include <asm/mach-imx/video.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050024#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080025#include <fsl_esdhc_imx.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050026#include <miiphy.h>
Martyn Welch18c31ea2018-01-10 20:31:30 +010027#include <net.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050028#include <netdev.h>
29#include <asm/arch/mxc_hdmi.h>
30#include <asm/arch/crm_regs.h>
31#include <asm/io.h>
32#include <asm/arch/sys_proto.h>
Robert Beckett53bab172020-01-31 15:07:54 +020033#include <power/regulator.h>
34#include <power/da9063_pmic.h>
Sebastian Reichel1b620ce2021-04-23 16:15:07 +020035#include <power/pmic.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030036#include <input.h>
Akshay Bhat5d643622016-04-12 18:13:59 -040037#include <pwm.h>
Pali Rohárba87ddf2021-08-02 15:18:31 +020038#include <version_string.h>
Ian Rayc0293da2017-08-22 09:03:54 +030039#include <stdlib.h>
Robert Beckettf746ab62019-11-12 19:15:11 +000040#include <dm/root.h>
Sebastian Reichel9cad0992020-09-02 19:31:43 +020041#include "../common/ge_rtc.h"
Martyn Welch66697ce2017-11-08 15:35:15 +000042#include "../common/vpd_reader.h"
Hannu Lounento37879682018-01-10 20:31:31 +010043#include "../../../drivers/net/e1000.h"
Denis Zalevskiy0d974712019-11-12 19:15:17 +000044#include <pci.h>
Robert Beckettb2185d22020-01-31 15:07:59 +020045#include <panel.h>
Denis Zalevskiy0d974712019-11-12 19:15:17 +000046
Akshay Bhat197f9872016-01-29 15:16:40 -050047DECLARE_GLOBAL_DATA_PTR;
48
Sebastian Reichel30871902020-11-04 17:18:41 +010049#define VPD_PRODUCT_B850 1
50#define VPD_PRODUCT_B650 2
51#define VPD_PRODUCT_B450 3
52
Sebastian Reichelb8f2cce2020-12-15 00:41:57 +010053#define AR8033_DBG_REG_ADDR 0x1d
54#define AR8033_DBG_REG_DATA 0x1e
55#define AR8033_SERDES_REG 0x5
56
Sebastian Reichel30871902020-11-04 17:18:41 +010057static int productid; /* Default to generic. */
Nandor Han7a9bb302018-04-25 16:57:01 +020058static struct vpd_cache vpd;
59
Justin Watersef93fc22016-04-13 17:03:18 -040060#define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
61 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
62 PAD_CTL_HYS)
63
Akshay Bhat197f9872016-01-29 15:16:40 -050064int dram_init(void)
65{
Fabio Estevamdd5d4e42016-07-23 13:23:40 -030066 gd->ram_size = imx_ddr_size();
Akshay Bhat197f9872016-01-29 15:16:40 -050067
68 return 0;
69}
70
Akshay Bhat197f9872016-01-29 15:16:40 -050071int board_phy_config(struct phy_device *phydev)
72{
Sebastian Reichelb8f2cce2020-12-15 00:41:57 +010073 /*
74 * Set reserved bits to avoid board specific voltage peak issue. The
75 * value is a magic number provided directly by Qualcomm. Note, that
76 * PHY driver will take control of BIT(8) in this register to control
77 * TX clock delay, so we do not initialize that bit here.
78 */
79 phy_write(phydev, MDIO_DEVAD_NONE, AR8033_DBG_REG_ADDR, AR8033_SERDES_REG);
80 phy_write(phydev, MDIO_DEVAD_NONE, AR8033_DBG_REG_DATA, 0x3c47);
Akshay Bhat197f9872016-01-29 15:16:40 -050081
82 if (phydev->drv->config)
83 phydev->drv->config(phydev);
84
85 return 0;
86}
87
88#if defined(CONFIG_VIDEO_IPUV3)
Robert Beckettb2185d22020-01-31 15:07:59 +020089static void do_enable_backlight(struct display_info_t const *dev)
90{
91 struct udevice *panel;
92 int ret;
93
94 ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
95 if (ret) {
96 printf("Could not find panel: %d\n", ret);
97 return;
98 }
99
100 panel_set_backlight(panel, 100);
101 panel_enable_backlight(panel);
102}
Akshay Bhat197f9872016-01-29 15:16:40 -0500103
104static void do_enable_hdmi(struct display_info_t const *dev)
105{
106 imx_enable_hdmi_phy();
107}
108
Ian Ray6eac23f2018-04-25 16:57:02 +0200109static int is_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500110{
Sebastian Reichel30871902020-11-04 17:18:41 +0100111 return productid == VPD_PRODUCT_B850;
Ian Ray6eac23f2018-04-25 16:57:02 +0200112}
Akshay Bhat197f9872016-01-29 15:16:40 -0500113
Ian Ray6eac23f2018-04-25 16:57:02 +0200114static int detect_lcd(struct display_info_t const *dev)
115{
116 return !is_b850v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500117}
118
119struct display_info_t const displays[] = {{
120 .bus = -1,
121 .addr = -1,
122 .pixfmt = IPU_PIX_FMT_RGB24,
Ian Rayf8e4fab2018-04-25 16:56:58 +0200123 .detect = detect_lcd,
Robert Beckettb2185d22020-01-31 15:07:59 +0200124 .enable = do_enable_backlight,
Akshay Bhat197f9872016-01-29 15:16:40 -0500125 .mode = {
126 .name = "G121X1-L03",
127 .refresh = 60,
128 .xres = 1024,
129 .yres = 768,
130 .pixclock = 15385,
131 .left_margin = 20,
132 .right_margin = 300,
133 .upper_margin = 30,
134 .lower_margin = 8,
135 .hsync_len = 1,
136 .vsync_len = 1,
137 .sync = FB_SYNC_EXT,
138 .vmode = FB_VMODE_NONINTERLACED
139} }, {
140 .bus = -1,
141 .addr = 3,
142 .pixfmt = IPU_PIX_FMT_RGB24,
143 .detect = detect_hdmi,
144 .enable = do_enable_hdmi,
145 .mode = {
146 .name = "HDMI",
147 .refresh = 60,
148 .xres = 1024,
149 .yres = 768,
150 .pixclock = 15385,
151 .left_margin = 220,
152 .right_margin = 40,
153 .upper_margin = 21,
154 .lower_margin = 7,
155 .hsync_len = 60,
156 .vsync_len = 10,
157 .sync = FB_SYNC_EXT,
158 .vmode = FB_VMODE_NONINTERLACED
159} } };
160size_t display_count = ARRAY_SIZE(displays);
161
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400162static void enable_videopll(void)
163{
164 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
165 s32 timeout = 100000;
166
167 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
168
Ian Ray28540c52018-10-15 09:59:44 +0200169 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
170 * |
171 * PLL5
172 * |
173 * CS2CDR[LDB_DI0_CLK_SEL]
174 * |
175 * +----> LDB_DI0_SERIAL_CLK_ROOT
176 * |
177 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
178 */
179
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400180 clrsetbits_le32(&ccm->analog_pll_video,
181 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
182 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
183 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
Ian Ray28540c52018-10-15 09:59:44 +0200184 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400185
186 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
187 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
188
189 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
190
191 while (timeout--)
192 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
193 break;
194
195 if (timeout < 0)
196 printf("Warning: video pll lock timeout!\n");
197
198 clrsetbits_le32(&ccm->analog_pll_video,
199 BM_ANADIG_PLL_VIDEO_BYPASS,
200 BM_ANADIG_PLL_VIDEO_ENABLE);
201}
202
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400203static void setup_display_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500204{
205 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
206 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500207
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400208 enable_videopll();
209
Ian Ray28540c52018-10-15 09:59:44 +0200210 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
211 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400212
Akshay Bhat197f9872016-01-29 15:16:40 -0500213 imx_setup_hdmi();
214
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400215 /* Set LDB_DI0 as clock source for IPU_DI0 */
216 clrsetbits_le32(&mxc_ccm->chsccdr,
217 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
218 (CHSCCDR_CLK_SEL_LDB_DI0 <<
219 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500220
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400221 /* Turn on IPU LDB DI0 clocks */
222 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
223
224 enable_ipu_clock();
Akshay Bhat197f9872016-01-29 15:16:40 -0500225
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400226 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
227 IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
228 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
229 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
230 IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT |
231 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
232 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
233 IOMUXC_GPR2_SPLIT_MODE_EN_MASK |
234 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
235 IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0,
236 &iomux->gpr[2]);
Akshay Bhat197f9872016-01-29 15:16:40 -0500237
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400238 clrbits_le32(&iomux->gpr[3],
239 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
240 IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
241 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
242}
Akshay Bhat197f9872016-01-29 15:16:40 -0500243
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400244static void setup_display_bx50v3(void)
245{
246 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
247 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500248
Ian Ray66395e82018-04-25 16:57:00 +0200249 enable_videopll();
250
Akshay Bhat66027fe2016-04-12 18:14:00 -0400251 /* When a reset/reboot is performed the display power needs to be turned
252 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
253 * an additional 200ms here. Unfortunately we use external PMIC for
254 * doing the reset, so can not differentiate between POR vs soft reset
255 */
256 mdelay(200);
257
Ian Ray28540c52018-10-15 09:59:44 +0200258 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400259 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
260
261 /* Set LDB_DI0 as clock source for IPU_DI0 */
262 clrsetbits_le32(&mxc_ccm->chsccdr,
263 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
264 (CHSCCDR_CLK_SEL_LDB_DI0 <<
265 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
266
267 /* Turn on IPU LDB DI0 clocks */
268 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
269
270 enable_ipu_clock();
271
272 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
273 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
274 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
275 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
276 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
277 &iomux->gpr[2]);
278
279 clrsetbits_le32(&iomux->gpr[3],
280 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
281 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
282 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500283}
284#endif /* CONFIG_VIDEO_IPUV3 */
285
286/*
287 * Do not overwrite the console
288 * Use always serial for U-Boot console
289 */
290int overwrite_console(void)
291{
292 return 1;
293}
294
Ian Rayc0293da2017-08-22 09:03:54 +0300295#define VPD_TYPE_INVALID 0x00
296#define VPD_BLOCK_NETWORK 0x20
297#define VPD_BLOCK_HWID 0x44
Martyn Welch18c31ea2018-01-10 20:31:30 +0100298#define VPD_HAS_MAC1 0x1
Hannu Lounento37879682018-01-10 20:31:31 +0100299#define VPD_HAS_MAC2 0x2
Martyn Welch18c31ea2018-01-10 20:31:30 +0100300#define VPD_MAC_ADDRESS_LENGTH 6
Ian Rayc0293da2017-08-22 09:03:54 +0300301
302struct vpd_cache {
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200303 bool is_read;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100304 u8 product_id;
305 u8 has;
306 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
Hannu Lounento37879682018-01-10 20:31:31 +0100307 unsigned char mac2[VPD_MAC_ADDRESS_LENGTH];
Ian Rayc0293da2017-08-22 09:03:54 +0300308};
309
310/*
311 * Extracts MAC and product information from the VPD.
312 */
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200313static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
Martyn Welch18c31ea2018-01-10 20:31:30 +0100314 size_t size, u8 const *data)
Ian Rayc0293da2017-08-22 09:03:54 +0300315{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100316 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
317 size >= 1) {
Ian Rayc0293da2017-08-22 09:03:54 +0300318 vpd->product_id = data[0];
Martyn Welch18c31ea2018-01-10 20:31:30 +0100319 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
320 type != VPD_TYPE_INVALID) {
321 if (size >= 6) {
322 vpd->has |= VPD_HAS_MAC1;
323 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
324 }
Hannu Lounento37879682018-01-10 20:31:31 +0100325 if (size >= 12) {
326 vpd->has |= VPD_HAS_MAC2;
327 memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH);
328 }
Ian Rayc0293da2017-08-22 09:03:54 +0300329 }
330
331 return 0;
332}
333
Ian Rayc0293da2017-08-22 09:03:54 +0300334static void process_vpd(struct vpd_cache *vpd)
335{
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000336 int fec_index = 0;
Hannu Lounento37879682018-01-10 20:31:31 +0100337 int i210_index = -1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100338
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200339 if (!vpd->is_read) {
340 printf("VPD wasn't read");
341 return;
342 }
343
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000344 if (vpd->has & VPD_HAS_MAC1)
345 eth_env_set_enetaddr_by_index("eth", fec_index, vpd->mac1);
346
347 env_set("ethact", "eth0");
348
Martyn Welch18c31ea2018-01-10 20:31:30 +0100349 switch (vpd->product_id) {
350 case VPD_PRODUCT_B450:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000351 i210_index = 1;
Ian Rayb52e2522018-01-10 20:31:33 +0100352 break;
353 case VPD_PRODUCT_B650:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000354 i210_index = 1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100355 break;
356 case VPD_PRODUCT_B850:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000357 i210_index = 2;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100358 break;
Ian Rayc0293da2017-08-22 09:03:54 +0300359 }
Martyn Welch18c31ea2018-01-10 20:31:30 +0100360
Hannu Lounento37879682018-01-10 20:31:31 +0100361 if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2))
362 eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2);
Ian Rayc0293da2017-08-22 09:03:54 +0300363}
364
Akshay Bhat197f9872016-01-29 15:16:40 -0500365static iomux_v3_cfg_t const misc_pads[] = {
366 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
Justin Watersef93fc22016-04-13 17:03:18 -0400367 MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NC_PAD_CTRL),
368 MX6_PAD_EIM_CS0__GPIO2_IO23 | MUX_PAD_CTRL(NC_PAD_CTRL),
369 MX6_PAD_EIM_CS1__GPIO2_IO24 | MUX_PAD_CTRL(NC_PAD_CTRL),
370 MX6_PAD_EIM_OE__GPIO2_IO25 | MUX_PAD_CTRL(NC_PAD_CTRL),
371 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NC_PAD_CTRL),
372 MX6_PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NC_PAD_CTRL),
Martyn Welch110f5d92018-01-10 20:31:32 +0100373 MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500374};
375#define SUS_S3_OUT IMX_GPIO_NR(4, 11)
Ian Raya8203cc2020-11-04 17:18:43 +0100376#define PWGIN_IN IMX_GPIO_NR(4, 14)
Akshay Bhat197f9872016-01-29 15:16:40 -0500377#define WIFI_EN IMX_GPIO_NR(6, 14)
378
379int board_early_init_f(void)
380{
381 imx_iomux_v3_setup_multiple_pads(misc_pads,
382 ARRAY_SIZE(misc_pads));
383
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400384#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray28540c52018-10-15 09:59:44 +0200385 /* Set LDB clock to Video PLL */
386 select_ldb_di_clock_source(MXC_PLL5_CLK);
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400387#endif
Akshay Bhat197f9872016-01-29 15:16:40 -0500388 return 0;
389}
390
391int board_init(void)
392{
Sebastian Reichel5f05ebc2020-09-02 19:31:45 +0200393 if (!read_i2c_vpd(&vpd, vpd_callback)) {
Robert Beckettf746ab62019-11-12 19:15:11 +0000394 int ret, rescan;
395
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200396 vpd.is_read = true;
Sebastian Reichel30871902020-11-04 17:18:41 +0100397 productid = vpd.product_id;
Robert Beckettf746ab62019-11-12 19:15:11 +0000398
399 ret = fdtdec_resetup(&rescan);
400 if (!ret && rescan) {
401 dm_uninit();
402 dm_init_and_scan(false);
403 }
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200404 }
Nandor Han7a9bb302018-04-25 16:57:01 +0200405
Ian Ray5f1e3442019-01-31 16:21:13 +0200406 gpio_request(SUS_S3_OUT, "sus_s3_out");
Akshay Bhat197f9872016-01-29 15:16:40 -0500407 gpio_direction_output(SUS_S3_OUT, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200408
Ian Raya8203cc2020-11-04 17:18:43 +0100409 gpio_request(PWGIN_IN, "pwgin_in");
410 gpio_direction_input(PWGIN_IN);
411
Ian Ray5f1e3442019-01-31 16:21:13 +0200412 gpio_request(WIFI_EN, "wifi_en");
Akshay Bhat197f9872016-01-29 15:16:40 -0500413 gpio_direction_output(WIFI_EN, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200414
Akshay Bhat197f9872016-01-29 15:16:40 -0500415#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray6eac23f2018-04-25 16:57:02 +0200416 if (is_b850v3())
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400417 setup_display_b850v3();
418 else
419 setup_display_bx50v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500420#endif
Ian Ray5f1e3442019-01-31 16:21:13 +0200421
Akshay Bhat197f9872016-01-29 15:16:40 -0500422 /* address of boot parameters */
423 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
424
Akshay Bhat197f9872016-01-29 15:16:40 -0500425 return 0;
426}
427
428#ifdef CONFIG_CMD_BMODE
429static const struct boot_mode board_boot_modes[] = {
430 /* 4 bit bus width */
431 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
432 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
433 {NULL, 0},
434};
435#endif
436
Sebastian Reichel1b620ce2021-04-23 16:15:07 +0200437/*
438 * The SoM used by these boards has XTAL not connected despite datasheet
439 * suggesting connecting unused XTAL pins to ground. Without explicitly
440 * clearing the CRYSTAL bit the system runs unstable and sometimes reboots
441 * unexpectedly.
442 */
443static void pmic_crystal_fix(void)
444{
445 struct udevice *pmic;
446 static const uint EN_32K_CRYSTAL = (1 << 3);
447
448 if (pmic_get("pmic@58", &pmic)) {
449 puts("failed to get device for PMIC\n");
450 return;
451 }
452
453 if (pmic_clrsetbits(pmic, DA9063_REG_EN_32K, EN_32K_CRYSTAL, 0) < 0) {
454 puts("failed to clear CRYSTAL bit\n");
455 return;
456 }
457}
458
Ken Linc7219fc2016-11-18 12:20:54 -0500459void pmic_init(void)
460{
Robert Beckett53bab172020-01-31 15:07:54 +0200461 struct udevice *reg;
462 int ret, i;
463 static const char * const bucks[] = {
464 "bcore1",
465 "bcore2",
466 "bpro",
467 "bmem",
468 "bio",
469 "bperi",
470 };
Ken Linc7219fc2016-11-18 12:20:54 -0500471
Sebastian Reichel1b620ce2021-04-23 16:15:07 +0200472 pmic_crystal_fix();
473
Robert Beckett53bab172020-01-31 15:07:54 +0200474 for (i = 0; i < ARRAY_SIZE(bucks); i++) {
475 ret = regulator_get_by_devname(bucks[i], &reg);
476 if (reg < 0) {
477 printf("%s(): Unable to get regulator %s: %d\n",
478 __func__, bucks[i], ret);
479 continue;
480 }
481 regulator_set_mode(reg, DA9063_BUCKMODE_SYNC);
482 }
Ken Linc7219fc2016-11-18 12:20:54 -0500483}
484
Ian Raya8203cc2020-11-04 17:18:43 +0100485static void detect_boot_cause(void)
486{
487 const char *cause = "POR";
488
489 if (is_b850v3())
490 if (!gpio_get_value(PWGIN_IN))
491 cause = "PM_WDOG";
492
493 env_set("bootcause", cause);
494}
495
Akshay Bhat197f9872016-01-29 15:16:40 -0500496int board_late_init(void)
497{
Nandor Han7a9bb302018-04-25 16:57:01 +0200498 process_vpd(&vpd);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100499
Akshay Bhat197f9872016-01-29 15:16:40 -0500500#ifdef CONFIG_CMD_BMODE
501 add_board_boot_modes(board_boot_modes);
502#endif
Andrew Shadurac26583d2016-05-24 15:56:17 +0200503
Ian Rayd8c60992018-04-25 16:57:03 +0200504 if (is_b850v3())
505 env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60");
Ian Ray476e4e62018-10-15 09:59:45 +0200506 else
507 env_set("videoargs", "video=LVDS-1:1024x768@65");
Ian Rayd8c60992018-04-25 16:57:03 +0200508
Ian Raya8203cc2020-11-04 17:18:43 +0100509 detect_boot_cause();
510
Ken Linc7219fc2016-11-18 12:20:54 -0500511 /* board specific pmic init */
512 pmic_init();
513
Nandor Hanae3c6d22018-01-10 20:31:38 +0100514 check_time();
515
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000516 pci_init();
517
Akshay Bhat197f9872016-01-29 15:16:40 -0500518 return 0;
519}
520
Hannu Lounento37879682018-01-10 20:31:31 +0100521/*
522 * Removes the 'eth[0-9]*addr' environment variable with the given index
523 *
524 * @param index [in] the index of the eth_device whose variable is to be removed
525 */
526static void remove_ethaddr_env_var(int index)
527{
528 char env_var_name[9];
529
530 sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index);
531 env_set(env_var_name, NULL);
532}
533
Simon Glass1cedca12023-08-21 21:17:01 -0600534static int last_stage_init(void)
Martyn Welch18c31ea2018-01-10 20:31:30 +0100535{
Hannu Lounento37879682018-01-10 20:31:31 +0100536 int i;
537
538 /*
539 * Remove first three ethaddr which may have been created by
540 * function process_vpd().
541 */
542 for (i = 0; i < 3; ++i)
543 remove_ethaddr_env_var(i);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100544
545 return 0;
546}
Simon Glass1cedca12023-08-21 21:17:01 -0600547EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100548
Akshay Bhat197f9872016-01-29 15:16:40 -0500549int checkboard(void)
550{
Tom Rini272eb5b2022-03-21 21:33:32 -0400551 printf("BOARD: General Electric Bx50v3\n");
Akshay Bhat197f9872016-01-29 15:16:40 -0500552 return 0;
553}
Ian Ray40133682018-04-04 10:50:17 +0200554
Ian Ray64450942019-01-31 16:21:18 +0200555#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900556int ft_board_setup(void *blob, struct bd_info *bd)
Ian Ray64450942019-01-31 16:21:18 +0200557{
Ian Rayc69217c2019-11-12 19:15:18 +0000558 char *rtc_status = env_get("rtc_status");
559
Ian Ray64450942019-01-31 16:21:18 +0200560 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
Ian Rayc69217c2019-11-12 19:15:18 +0000561 strlen(version_string) + 1);
562
563 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
564 strlen(rtc_status) + 1);
Ian Ray64450942019-01-31 16:21:18 +0200565 return 0;
566}
567#endif
568
Robert Beckettf746ab62019-11-12 19:15:11 +0000569int board_fit_config_name_match(const char *name)
570{
Sebastian Reichel99453902020-12-15 00:41:56 +0100571 const char *machine = name;
572
Robert Beckettf746ab62019-11-12 19:15:11 +0000573 if (!vpd.is_read)
574 return strcmp(name, "imx6q-bx50v3");
575
Sebastian Reichel99453902020-12-15 00:41:56 +0100576 if (!strncmp(machine, "Boot ", 5))
577 machine += 5;
578 if (!strncmp(machine, "imx6q-", 6))
579 machine += 6;
580
Robert Beckettf746ab62019-11-12 19:15:11 +0000581 switch (vpd.product_id) {
582 case VPD_PRODUCT_B450:
Sebastian Reichel99453902020-12-15 00:41:56 +0100583 return strcasecmp(machine, "b450v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000584 case VPD_PRODUCT_B650:
Sebastian Reichel99453902020-12-15 00:41:56 +0100585 return strcasecmp(machine, "b650v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000586 case VPD_PRODUCT_B850:
Sebastian Reichel99453902020-12-15 00:41:56 +0100587 return strcasecmp(machine, "b850v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000588 default:
589 return -1;
590 }
591}
592
593int embedded_dtb_select(void)
594{
595 vpd.is_read = false;
596 return fdtdec_setup();
597}