blob: 3ea9425fd1ea92d51086fff588daeb0cd35f9ac0 [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
Sebastian Reichelb8f2cce2020-12-15 00:41:57 +010050#define AR8033_DBG_REG_ADDR 0x1d
51#define AR8033_DBG_REG_DATA 0x1e
52#define AR8033_SERDES_REG 0x5
53
Sebastian Reichel30871902020-11-04 17:18:41 +010054static int productid; /* Default to generic. */
Nandor Han7a9bb302018-04-25 16:57:01 +020055static struct vpd_cache vpd;
56
Justin Watersef93fc22016-04-13 17:03:18 -040057#define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
58 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
59 PAD_CTL_HYS)
60
Akshay Bhat197f9872016-01-29 15:16:40 -050061int dram_init(void)
62{
Fabio Estevamdd5d4e42016-07-23 13:23:40 -030063 gd->ram_size = imx_ddr_size();
Akshay Bhat197f9872016-01-29 15:16:40 -050064
65 return 0;
66}
67
Akshay Bhat197f9872016-01-29 15:16:40 -050068int board_phy_config(struct phy_device *phydev)
69{
Sebastian Reichelb8f2cce2020-12-15 00:41:57 +010070 /*
71 * Set reserved bits to avoid board specific voltage peak issue. The
72 * value is a magic number provided directly by Qualcomm. Note, that
73 * PHY driver will take control of BIT(8) in this register to control
74 * TX clock delay, so we do not initialize that bit here.
75 */
76 phy_write(phydev, MDIO_DEVAD_NONE, AR8033_DBG_REG_ADDR, AR8033_SERDES_REG);
77 phy_write(phydev, MDIO_DEVAD_NONE, AR8033_DBG_REG_DATA, 0x3c47);
Akshay Bhat197f9872016-01-29 15:16:40 -050078
79 if (phydev->drv->config)
80 phydev->drv->config(phydev);
81
82 return 0;
83}
84
85#if defined(CONFIG_VIDEO_IPUV3)
Robert Beckettb2185d22020-01-31 15:07:59 +020086static void do_enable_backlight(struct display_info_t const *dev)
87{
88 struct udevice *panel;
89 int ret;
90
91 ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
92 if (ret) {
93 printf("Could not find panel: %d\n", ret);
94 return;
95 }
96
97 panel_set_backlight(panel, 100);
98 panel_enable_backlight(panel);
99}
Akshay Bhat197f9872016-01-29 15:16:40 -0500100
101static void do_enable_hdmi(struct display_info_t const *dev)
102{
103 imx_enable_hdmi_phy();
104}
105
Ian Ray6eac23f2018-04-25 16:57:02 +0200106static int is_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500107{
Sebastian Reichel30871902020-11-04 17:18:41 +0100108 return productid == VPD_PRODUCT_B850;
Ian Ray6eac23f2018-04-25 16:57:02 +0200109}
Akshay Bhat197f9872016-01-29 15:16:40 -0500110
Ian Ray6eac23f2018-04-25 16:57:02 +0200111static int detect_lcd(struct display_info_t const *dev)
112{
113 return !is_b850v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500114}
115
116struct display_info_t const displays[] = {{
117 .bus = -1,
118 .addr = -1,
119 .pixfmt = IPU_PIX_FMT_RGB24,
Ian Rayf8e4fab2018-04-25 16:56:58 +0200120 .detect = detect_lcd,
Robert Beckettb2185d22020-01-31 15:07:59 +0200121 .enable = do_enable_backlight,
Akshay Bhat197f9872016-01-29 15:16:40 -0500122 .mode = {
123 .name = "G121X1-L03",
124 .refresh = 60,
125 .xres = 1024,
126 .yres = 768,
127 .pixclock = 15385,
128 .left_margin = 20,
129 .right_margin = 300,
130 .upper_margin = 30,
131 .lower_margin = 8,
132 .hsync_len = 1,
133 .vsync_len = 1,
134 .sync = FB_SYNC_EXT,
135 .vmode = FB_VMODE_NONINTERLACED
136} }, {
137 .bus = -1,
138 .addr = 3,
139 .pixfmt = IPU_PIX_FMT_RGB24,
140 .detect = detect_hdmi,
141 .enable = do_enable_hdmi,
142 .mode = {
143 .name = "HDMI",
144 .refresh = 60,
145 .xres = 1024,
146 .yres = 768,
147 .pixclock = 15385,
148 .left_margin = 220,
149 .right_margin = 40,
150 .upper_margin = 21,
151 .lower_margin = 7,
152 .hsync_len = 60,
153 .vsync_len = 10,
154 .sync = FB_SYNC_EXT,
155 .vmode = FB_VMODE_NONINTERLACED
156} } };
157size_t display_count = ARRAY_SIZE(displays);
158
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400159static void enable_videopll(void)
160{
161 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
162 s32 timeout = 100000;
163
164 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
165
Ian Ray28540c52018-10-15 09:59:44 +0200166 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
167 * |
168 * PLL5
169 * |
170 * CS2CDR[LDB_DI0_CLK_SEL]
171 * |
172 * +----> LDB_DI0_SERIAL_CLK_ROOT
173 * |
174 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
175 */
176
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400177 clrsetbits_le32(&ccm->analog_pll_video,
178 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
179 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
180 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
Ian Ray28540c52018-10-15 09:59:44 +0200181 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400182
183 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
184 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
185
186 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
187
188 while (timeout--)
189 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
190 break;
191
192 if (timeout < 0)
193 printf("Warning: video pll lock timeout!\n");
194
195 clrsetbits_le32(&ccm->analog_pll_video,
196 BM_ANADIG_PLL_VIDEO_BYPASS,
197 BM_ANADIG_PLL_VIDEO_ENABLE);
198}
199
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400200static void setup_display_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500201{
202 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
203 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500204
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400205 enable_videopll();
206
Ian Ray28540c52018-10-15 09:59:44 +0200207 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
208 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400209
Akshay Bhat197f9872016-01-29 15:16:40 -0500210 imx_setup_hdmi();
211
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400212 /* Set LDB_DI0 as clock source for IPU_DI0 */
213 clrsetbits_le32(&mxc_ccm->chsccdr,
214 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
215 (CHSCCDR_CLK_SEL_LDB_DI0 <<
216 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500217
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400218 /* Turn on IPU LDB DI0 clocks */
219 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
220
221 enable_ipu_clock();
Akshay Bhat197f9872016-01-29 15:16:40 -0500222
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400223 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
224 IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
225 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
226 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
227 IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT |
228 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
229 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
230 IOMUXC_GPR2_SPLIT_MODE_EN_MASK |
231 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
232 IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0,
233 &iomux->gpr[2]);
Akshay Bhat197f9872016-01-29 15:16:40 -0500234
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400235 clrbits_le32(&iomux->gpr[3],
236 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
237 IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
238 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
239}
Akshay Bhat197f9872016-01-29 15:16:40 -0500240
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400241static void setup_display_bx50v3(void)
242{
243 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
244 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500245
Ian Ray66395e82018-04-25 16:57:00 +0200246 enable_videopll();
247
Akshay Bhat66027fe2016-04-12 18:14:00 -0400248 /* When a reset/reboot is performed the display power needs to be turned
249 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
250 * an additional 200ms here. Unfortunately we use external PMIC for
251 * doing the reset, so can not differentiate between POR vs soft reset
252 */
253 mdelay(200);
254
Ian Ray28540c52018-10-15 09:59:44 +0200255 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400256 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
257
258 /* Set LDB_DI0 as clock source for IPU_DI0 */
259 clrsetbits_le32(&mxc_ccm->chsccdr,
260 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
261 (CHSCCDR_CLK_SEL_LDB_DI0 <<
262 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
263
264 /* Turn on IPU LDB DI0 clocks */
265 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
266
267 enable_ipu_clock();
268
269 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
270 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
271 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
272 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
273 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
274 &iomux->gpr[2]);
275
276 clrsetbits_le32(&iomux->gpr[3],
277 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
278 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
279 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500280}
281#endif /* CONFIG_VIDEO_IPUV3 */
282
283/*
284 * Do not overwrite the console
285 * Use always serial for U-Boot console
286 */
287int overwrite_console(void)
288{
289 return 1;
290}
291
Ian Rayc0293da2017-08-22 09:03:54 +0300292#define VPD_TYPE_INVALID 0x00
293#define VPD_BLOCK_NETWORK 0x20
294#define VPD_BLOCK_HWID 0x44
Martyn Welch18c31ea2018-01-10 20:31:30 +0100295#define VPD_HAS_MAC1 0x1
Hannu Lounento37879682018-01-10 20:31:31 +0100296#define VPD_HAS_MAC2 0x2
Martyn Welch18c31ea2018-01-10 20:31:30 +0100297#define VPD_MAC_ADDRESS_LENGTH 6
Ian Rayc0293da2017-08-22 09:03:54 +0300298
299struct vpd_cache {
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200300 bool is_read;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100301 u8 product_id;
302 u8 has;
303 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
Hannu Lounento37879682018-01-10 20:31:31 +0100304 unsigned char mac2[VPD_MAC_ADDRESS_LENGTH];
Ian Rayc0293da2017-08-22 09:03:54 +0300305};
306
307/*
308 * Extracts MAC and product information from the VPD.
309 */
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200310static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
Martyn Welch18c31ea2018-01-10 20:31:30 +0100311 size_t size, u8 const *data)
Ian Rayc0293da2017-08-22 09:03:54 +0300312{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100313 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
314 size >= 1) {
Ian Rayc0293da2017-08-22 09:03:54 +0300315 vpd->product_id = data[0];
Martyn Welch18c31ea2018-01-10 20:31:30 +0100316 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
317 type != VPD_TYPE_INVALID) {
318 if (size >= 6) {
319 vpd->has |= VPD_HAS_MAC1;
320 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
321 }
Hannu Lounento37879682018-01-10 20:31:31 +0100322 if (size >= 12) {
323 vpd->has |= VPD_HAS_MAC2;
324 memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH);
325 }
Ian Rayc0293da2017-08-22 09:03:54 +0300326 }
327
328 return 0;
329}
330
Ian Rayc0293da2017-08-22 09:03:54 +0300331static void process_vpd(struct vpd_cache *vpd)
332{
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000333 int fec_index = 0;
Hannu Lounento37879682018-01-10 20:31:31 +0100334 int i210_index = -1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100335
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200336 if (!vpd->is_read) {
337 printf("VPD wasn't read");
338 return;
339 }
340
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000341 if (vpd->has & VPD_HAS_MAC1)
342 eth_env_set_enetaddr_by_index("eth", fec_index, vpd->mac1);
343
344 env_set("ethact", "eth0");
345
Martyn Welch18c31ea2018-01-10 20:31:30 +0100346 switch (vpd->product_id) {
347 case VPD_PRODUCT_B450:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000348 i210_index = 1;
Ian Rayb52e2522018-01-10 20:31:33 +0100349 break;
350 case VPD_PRODUCT_B650:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000351 i210_index = 1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100352 break;
353 case VPD_PRODUCT_B850:
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000354 i210_index = 2;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100355 break;
Ian Rayc0293da2017-08-22 09:03:54 +0300356 }
Martyn Welch18c31ea2018-01-10 20:31:30 +0100357
Hannu Lounento37879682018-01-10 20:31:31 +0100358 if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2))
359 eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2);
Ian Rayc0293da2017-08-22 09:03:54 +0300360}
361
Akshay Bhat197f9872016-01-29 15:16:40 -0500362static iomux_v3_cfg_t const misc_pads[] = {
363 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
Justin Watersef93fc22016-04-13 17:03:18 -0400364 MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NC_PAD_CTRL),
365 MX6_PAD_EIM_CS0__GPIO2_IO23 | MUX_PAD_CTRL(NC_PAD_CTRL),
366 MX6_PAD_EIM_CS1__GPIO2_IO24 | MUX_PAD_CTRL(NC_PAD_CTRL),
367 MX6_PAD_EIM_OE__GPIO2_IO25 | MUX_PAD_CTRL(NC_PAD_CTRL),
368 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NC_PAD_CTRL),
369 MX6_PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NC_PAD_CTRL),
Martyn Welch110f5d92018-01-10 20:31:32 +0100370 MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500371};
372#define SUS_S3_OUT IMX_GPIO_NR(4, 11)
Ian Raya8203cc2020-11-04 17:18:43 +0100373#define PWGIN_IN IMX_GPIO_NR(4, 14)
Akshay Bhat197f9872016-01-29 15:16:40 -0500374#define WIFI_EN IMX_GPIO_NR(6, 14)
375
376int board_early_init_f(void)
377{
378 imx_iomux_v3_setup_multiple_pads(misc_pads,
379 ARRAY_SIZE(misc_pads));
380
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400381#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray28540c52018-10-15 09:59:44 +0200382 /* Set LDB clock to Video PLL */
383 select_ldb_di_clock_source(MXC_PLL5_CLK);
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400384#endif
Akshay Bhat197f9872016-01-29 15:16:40 -0500385 return 0;
386}
387
388int board_init(void)
389{
Sebastian Reichel5f05ebc2020-09-02 19:31:45 +0200390 if (!read_i2c_vpd(&vpd, vpd_callback)) {
Robert Beckettf746ab62019-11-12 19:15:11 +0000391 int ret, rescan;
392
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200393 vpd.is_read = true;
Sebastian Reichel30871902020-11-04 17:18:41 +0100394 productid = vpd.product_id;
Robert Beckettf746ab62019-11-12 19:15:11 +0000395
396 ret = fdtdec_resetup(&rescan);
397 if (!ret && rescan) {
398 dm_uninit();
399 dm_init_and_scan(false);
400 }
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200401 }
Nandor Han7a9bb302018-04-25 16:57:01 +0200402
Ian Ray5f1e3442019-01-31 16:21:13 +0200403 gpio_request(SUS_S3_OUT, "sus_s3_out");
Akshay Bhat197f9872016-01-29 15:16:40 -0500404 gpio_direction_output(SUS_S3_OUT, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200405
Ian Raya8203cc2020-11-04 17:18:43 +0100406 gpio_request(PWGIN_IN, "pwgin_in");
407 gpio_direction_input(PWGIN_IN);
408
Ian Ray5f1e3442019-01-31 16:21:13 +0200409 gpio_request(WIFI_EN, "wifi_en");
Akshay Bhat197f9872016-01-29 15:16:40 -0500410 gpio_direction_output(WIFI_EN, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200411
Akshay Bhat197f9872016-01-29 15:16:40 -0500412#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray6eac23f2018-04-25 16:57:02 +0200413 if (is_b850v3())
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400414 setup_display_b850v3();
415 else
416 setup_display_bx50v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500417#endif
Ian Ray5f1e3442019-01-31 16:21:13 +0200418
Akshay Bhat197f9872016-01-29 15:16:40 -0500419 /* address of boot parameters */
420 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
421
Akshay Bhat197f9872016-01-29 15:16:40 -0500422 return 0;
423}
424
425#ifdef CONFIG_CMD_BMODE
426static const struct boot_mode board_boot_modes[] = {
427 /* 4 bit bus width */
428 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
429 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
430 {NULL, 0},
431};
432#endif
433
Ken Linc7219fc2016-11-18 12:20:54 -0500434void pmic_init(void)
435{
Robert Beckett53bab172020-01-31 15:07:54 +0200436 struct udevice *reg;
437 int ret, i;
438 static const char * const bucks[] = {
439 "bcore1",
440 "bcore2",
441 "bpro",
442 "bmem",
443 "bio",
444 "bperi",
445 };
Ken Linc7219fc2016-11-18 12:20:54 -0500446
Robert Beckett53bab172020-01-31 15:07:54 +0200447 for (i = 0; i < ARRAY_SIZE(bucks); i++) {
448 ret = regulator_get_by_devname(bucks[i], &reg);
449 if (reg < 0) {
450 printf("%s(): Unable to get regulator %s: %d\n",
451 __func__, bucks[i], ret);
452 continue;
453 }
454 regulator_set_mode(reg, DA9063_BUCKMODE_SYNC);
455 }
Ken Linc7219fc2016-11-18 12:20:54 -0500456}
457
Ian Raya8203cc2020-11-04 17:18:43 +0100458static void detect_boot_cause(void)
459{
460 const char *cause = "POR";
461
462 if (is_b850v3())
463 if (!gpio_get_value(PWGIN_IN))
464 cause = "PM_WDOG";
465
466 env_set("bootcause", cause);
467}
468
Akshay Bhat197f9872016-01-29 15:16:40 -0500469int board_late_init(void)
470{
Nandor Han7a9bb302018-04-25 16:57:01 +0200471 process_vpd(&vpd);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100472
Akshay Bhat197f9872016-01-29 15:16:40 -0500473#ifdef CONFIG_CMD_BMODE
474 add_board_boot_modes(board_boot_modes);
475#endif
Andrew Shadurac26583d2016-05-24 15:56:17 +0200476
Ian Rayd8c60992018-04-25 16:57:03 +0200477 if (is_b850v3())
478 env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60");
Ian Ray476e4e62018-10-15 09:59:45 +0200479 else
480 env_set("videoargs", "video=LVDS-1:1024x768@65");
Ian Rayd8c60992018-04-25 16:57:03 +0200481
Ian Raya8203cc2020-11-04 17:18:43 +0100482 detect_boot_cause();
483
Ken Linc7219fc2016-11-18 12:20:54 -0500484 /* board specific pmic init */
485 pmic_init();
486
Nandor Hanae3c6d22018-01-10 20:31:38 +0100487 check_time();
488
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000489 pci_init();
490
Akshay Bhat197f9872016-01-29 15:16:40 -0500491 return 0;
492}
493
Hannu Lounento37879682018-01-10 20:31:31 +0100494/*
495 * Removes the 'eth[0-9]*addr' environment variable with the given index
496 *
497 * @param index [in] the index of the eth_device whose variable is to be removed
498 */
499static void remove_ethaddr_env_var(int index)
500{
501 char env_var_name[9];
502
503 sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index);
504 env_set(env_var_name, NULL);
505}
506
Martyn Welch18c31ea2018-01-10 20:31:30 +0100507int last_stage_init(void)
508{
Hannu Lounento37879682018-01-10 20:31:31 +0100509 int i;
510
511 /*
512 * Remove first three ethaddr which may have been created by
513 * function process_vpd().
514 */
515 for (i = 0; i < 3; ++i)
516 remove_ethaddr_env_var(i);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100517
518 return 0;
519}
520
Akshay Bhat197f9872016-01-29 15:16:40 -0500521int checkboard(void)
522{
523 printf("BOARD: %s\n", CONFIG_BOARD_NAME);
524 return 0;
525}
Ian Ray40133682018-04-04 10:50:17 +0200526
Ian Ray64450942019-01-31 16:21:18 +0200527#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900528int ft_board_setup(void *blob, struct bd_info *bd)
Ian Ray64450942019-01-31 16:21:18 +0200529{
Ian Rayc69217c2019-11-12 19:15:18 +0000530 char *rtc_status = env_get("rtc_status");
531
Ian Ray64450942019-01-31 16:21:18 +0200532 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
Ian Rayc69217c2019-11-12 19:15:18 +0000533 strlen(version_string) + 1);
534
535 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
536 strlen(rtc_status) + 1);
Ian Ray64450942019-01-31 16:21:18 +0200537 return 0;
538}
539#endif
540
Robert Beckettf746ab62019-11-12 19:15:11 +0000541int board_fit_config_name_match(const char *name)
542{
Sebastian Reichel99453902020-12-15 00:41:56 +0100543 const char *machine = name;
544
Robert Beckettf746ab62019-11-12 19:15:11 +0000545 if (!vpd.is_read)
546 return strcmp(name, "imx6q-bx50v3");
547
Sebastian Reichel99453902020-12-15 00:41:56 +0100548 if (!strncmp(machine, "Boot ", 5))
549 machine += 5;
550 if (!strncmp(machine, "imx6q-", 6))
551 machine += 6;
552
Robert Beckettf746ab62019-11-12 19:15:11 +0000553 switch (vpd.product_id) {
554 case VPD_PRODUCT_B450:
Sebastian Reichel99453902020-12-15 00:41:56 +0100555 return strcasecmp(machine, "b450v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000556 case VPD_PRODUCT_B650:
Sebastian Reichel99453902020-12-15 00:41:56 +0100557 return strcasecmp(machine, "b650v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000558 case VPD_PRODUCT_B850:
Sebastian Reichel99453902020-12-15 00:41:56 +0100559 return strcasecmp(machine, "b850v3");
Robert Beckettf746ab62019-11-12 19:15:11 +0000560 default:
561 return -1;
562 }
563}
564
565int embedded_dtb_select(void)
566{
567 vpd.is_read = false;
568 return fdtdec_setup();
569}