blob: 5ad265af8a72a412c4df1f06e68000d26fe86d91 [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
Robert Beckettf746ab62019-11-12 19:15:11 +000046static int confidx; /* Default to generic. */
Nandor Han7a9bb302018-04-25 16:57:01 +020047static struct vpd_cache vpd;
48
Justin Watersef93fc22016-04-13 17:03:18 -040049#define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
50 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
51 PAD_CTL_HYS)
52
Akshay Bhat197f9872016-01-29 15:16:40 -050053int dram_init(void)
54{
Fabio Estevamdd5d4e42016-07-23 13:23:40 -030055 gd->ram_size = imx_ddr_size();
Akshay Bhat197f9872016-01-29 15:16:40 -050056
57 return 0;
58}
59
Akshay Bhat197f9872016-01-29 15:16:40 -050060static int mx6_rgmii_rework(struct phy_device *phydev)
61{
62 /* Configure AR8033 to ouput a 125MHz clk from CLK_25M */
63 /* set device address 0x7 */
64 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
65 /* offset 0x8016: CLK_25M Clock Select */
66 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
67 /* enable register write, no post increment, address 0x7 */
68 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
69 /* set to 125 MHz from local PLL source */
70 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x18);
71
72 /* rgmii tx clock delay enable */
73 /* set debug port address: SerDes Test and System Mode Control */
74 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
75 /* enable rgmii tx clock delay */
Yung-Ching LIN48652c82017-02-21 09:56:56 +080076 /* set the reserved bits to avoid board specific voltage peak issue*/
77 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x3D47);
Akshay Bhat197f9872016-01-29 15:16:40 -050078
79 return 0;
80}
81
82int board_phy_config(struct phy_device *phydev)
83{
84 mx6_rgmii_rework(phydev);
85
86 if (phydev->drv->config)
87 phydev->drv->config(phydev);
88
89 return 0;
90}
91
92#if defined(CONFIG_VIDEO_IPUV3)
Robert Beckettb2185d22020-01-31 15:07:59 +020093static void do_enable_backlight(struct display_info_t const *dev)
94{
95 struct udevice *panel;
96 int ret;
97
98 ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
99 if (ret) {
100 printf("Could not find panel: %d\n", ret);
101 return;
102 }
103
104 panel_set_backlight(panel, 100);
105 panel_enable_backlight(panel);
106}
Akshay Bhat197f9872016-01-29 15:16:40 -0500107
108static void do_enable_hdmi(struct display_info_t const *dev)
109{
110 imx_enable_hdmi_phy();
111}
112
Ian Ray6eac23f2018-04-25 16:57:02 +0200113static int is_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500114{
Ian Ray6eac23f2018-04-25 16:57:02 +0200115 return confidx == 3;
116}
Akshay Bhat197f9872016-01-29 15:16:40 -0500117
Ian Ray6eac23f2018-04-25 16:57:02 +0200118static int detect_lcd(struct display_info_t const *dev)
119{
120 return !is_b850v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500121}
122
123struct display_info_t const displays[] = {{
124 .bus = -1,
125 .addr = -1,
126 .pixfmt = IPU_PIX_FMT_RGB24,
Ian Rayf8e4fab2018-04-25 16:56:58 +0200127 .detect = detect_lcd,
Robert Beckettb2185d22020-01-31 15:07:59 +0200128 .enable = do_enable_backlight,
Akshay Bhat197f9872016-01-29 15:16:40 -0500129 .mode = {
130 .name = "G121X1-L03",
131 .refresh = 60,
132 .xres = 1024,
133 .yres = 768,
134 .pixclock = 15385,
135 .left_margin = 20,
136 .right_margin = 300,
137 .upper_margin = 30,
138 .lower_margin = 8,
139 .hsync_len = 1,
140 .vsync_len = 1,
141 .sync = FB_SYNC_EXT,
142 .vmode = FB_VMODE_NONINTERLACED
143} }, {
144 .bus = -1,
145 .addr = 3,
146 .pixfmt = IPU_PIX_FMT_RGB24,
147 .detect = detect_hdmi,
148 .enable = do_enable_hdmi,
149 .mode = {
150 .name = "HDMI",
151 .refresh = 60,
152 .xres = 1024,
153 .yres = 768,
154 .pixclock = 15385,
155 .left_margin = 220,
156 .right_margin = 40,
157 .upper_margin = 21,
158 .lower_margin = 7,
159 .hsync_len = 60,
160 .vsync_len = 10,
161 .sync = FB_SYNC_EXT,
162 .vmode = FB_VMODE_NONINTERLACED
163} } };
164size_t display_count = ARRAY_SIZE(displays);
165
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400166static void enable_videopll(void)
167{
168 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
169 s32 timeout = 100000;
170
171 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
172
Ian Ray28540c52018-10-15 09:59:44 +0200173 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
174 * |
175 * PLL5
176 * |
177 * CS2CDR[LDB_DI0_CLK_SEL]
178 * |
179 * +----> LDB_DI0_SERIAL_CLK_ROOT
180 * |
181 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
182 */
183
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400184 clrsetbits_le32(&ccm->analog_pll_video,
185 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
186 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
187 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
Ian Ray28540c52018-10-15 09:59:44 +0200188 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400189
190 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
191 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
192
193 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
194
195 while (timeout--)
196 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
197 break;
198
199 if (timeout < 0)
200 printf("Warning: video pll lock timeout!\n");
201
202 clrsetbits_le32(&ccm->analog_pll_video,
203 BM_ANADIG_PLL_VIDEO_BYPASS,
204 BM_ANADIG_PLL_VIDEO_ENABLE);
205}
206
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400207static void setup_display_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500208{
209 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
210 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500211
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400212 enable_videopll();
213
Ian Ray28540c52018-10-15 09:59:44 +0200214 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
215 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400216
Akshay Bhat197f9872016-01-29 15:16:40 -0500217 imx_setup_hdmi();
218
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400219 /* Set LDB_DI0 as clock source for IPU_DI0 */
220 clrsetbits_le32(&mxc_ccm->chsccdr,
221 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
222 (CHSCCDR_CLK_SEL_LDB_DI0 <<
223 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500224
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400225 /* Turn on IPU LDB DI0 clocks */
226 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
227
228 enable_ipu_clock();
Akshay Bhat197f9872016-01-29 15:16:40 -0500229
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400230 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
231 IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
232 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
233 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
234 IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT |
235 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
236 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
237 IOMUXC_GPR2_SPLIT_MODE_EN_MASK |
238 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
239 IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0,
240 &iomux->gpr[2]);
Akshay Bhat197f9872016-01-29 15:16:40 -0500241
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400242 clrbits_le32(&iomux->gpr[3],
243 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
244 IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
245 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
246}
Akshay Bhat197f9872016-01-29 15:16:40 -0500247
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400248static void setup_display_bx50v3(void)
249{
250 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
251 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500252
Ian Ray66395e82018-04-25 16:57:00 +0200253 enable_videopll();
254
Akshay Bhat66027fe2016-04-12 18:14:00 -0400255 /* When a reset/reboot is performed the display power needs to be turned
256 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
257 * an additional 200ms here. Unfortunately we use external PMIC for
258 * doing the reset, so can not differentiate between POR vs soft reset
259 */
260 mdelay(200);
261
Ian Ray28540c52018-10-15 09:59:44 +0200262 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400263 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
264
265 /* Set LDB_DI0 as clock source for IPU_DI0 */
266 clrsetbits_le32(&mxc_ccm->chsccdr,
267 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
268 (CHSCCDR_CLK_SEL_LDB_DI0 <<
269 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
270
271 /* Turn on IPU LDB DI0 clocks */
272 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
273
274 enable_ipu_clock();
275
276 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
277 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
278 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
279 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
280 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
281 &iomux->gpr[2]);
282
283 clrsetbits_le32(&iomux->gpr[3],
284 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
285 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
286 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500287}
288#endif /* CONFIG_VIDEO_IPUV3 */
289
290/*
291 * Do not overwrite the console
292 * Use always serial for U-Boot console
293 */
294int overwrite_console(void)
295{
296 return 1;
297}
298
Ian Rayc0293da2017-08-22 09:03:54 +0300299#define VPD_TYPE_INVALID 0x00
300#define VPD_BLOCK_NETWORK 0x20
301#define VPD_BLOCK_HWID 0x44
302#define VPD_PRODUCT_B850 1
303#define VPD_PRODUCT_B650 2
304#define VPD_PRODUCT_B450 3
Martyn Welch18c31ea2018-01-10 20:31:30 +0100305#define VPD_HAS_MAC1 0x1
Hannu Lounento37879682018-01-10 20:31:31 +0100306#define VPD_HAS_MAC2 0x2
Martyn Welch18c31ea2018-01-10 20:31:30 +0100307#define VPD_MAC_ADDRESS_LENGTH 6
Ian Rayc0293da2017-08-22 09:03:54 +0300308
309struct vpd_cache {
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200310 bool is_read;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100311 u8 product_id;
312 u8 has;
313 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
Hannu Lounento37879682018-01-10 20:31:31 +0100314 unsigned char mac2[VPD_MAC_ADDRESS_LENGTH];
Ian Rayc0293da2017-08-22 09:03:54 +0300315};
316
317/*
318 * Extracts MAC and product information from the VPD.
319 */
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200320static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
Martyn Welch18c31ea2018-01-10 20:31:30 +0100321 size_t size, u8 const *data)
Ian Rayc0293da2017-08-22 09:03:54 +0300322{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100323 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
324 size >= 1) {
Ian Rayc0293da2017-08-22 09:03:54 +0300325 vpd->product_id = data[0];
Martyn Welch18c31ea2018-01-10 20:31:30 +0100326 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
327 type != VPD_TYPE_INVALID) {
328 if (size >= 6) {
329 vpd->has |= VPD_HAS_MAC1;
330 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
331 }
Hannu Lounento37879682018-01-10 20:31:31 +0100332 if (size >= 12) {
333 vpd->has |= VPD_HAS_MAC2;
334 memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH);
335 }
Ian Rayc0293da2017-08-22 09:03:54 +0300336 }
337
338 return 0;
339}
340
Ian Rayc0293da2017-08-22 09:03:54 +0300341static void process_vpd(struct vpd_cache *vpd)
342{
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000343 int fec_index = 0;
Hannu Lounento37879682018-01-10 20:31:31 +0100344 int i210_index = -1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100345
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200346 if (!vpd->is_read) {
347 printf("VPD wasn't read");
348 return;
349 }
350
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000351 if (vpd->has & VPD_HAS_MAC1)
352 eth_env_set_enetaddr_by_index("eth", fec_index, vpd->mac1);
353
354 env_set("ethact", "eth0");
355
Martyn Welch18c31ea2018-01-10 20:31:30 +0100356 switch (vpd->product_id) {
357 case VPD_PRODUCT_B450:
Ian Rayb52e2522018-01-10 20:31:33 +0100358 env_set("confidx", "1");
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:
362 env_set("confidx", "2");
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000363 i210_index = 1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100364 break;
365 case VPD_PRODUCT_B850:
Nandor Hanf335ae92018-04-25 16:56:59 +0200366 env_set("confidx", "3");
Denis Zalevskiy0d974712019-11-12 19:15:17 +0000367 i210_index = 2;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100368 break;
Ian Rayc0293da2017-08-22 09:03:54 +0300369 }
Martyn Welch18c31ea2018-01-10 20:31:30 +0100370
Hannu Lounento37879682018-01-10 20:31:31 +0100371 if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2))
372 eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2);
Ian Rayc0293da2017-08-22 09:03:54 +0300373}
374
Akshay Bhat197f9872016-01-29 15:16:40 -0500375static iomux_v3_cfg_t const misc_pads[] = {
376 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
Justin Watersef93fc22016-04-13 17:03:18 -0400377 MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NC_PAD_CTRL),
378 MX6_PAD_EIM_CS0__GPIO2_IO23 | MUX_PAD_CTRL(NC_PAD_CTRL),
379 MX6_PAD_EIM_CS1__GPIO2_IO24 | MUX_PAD_CTRL(NC_PAD_CTRL),
380 MX6_PAD_EIM_OE__GPIO2_IO25 | MUX_PAD_CTRL(NC_PAD_CTRL),
381 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NC_PAD_CTRL),
382 MX6_PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NC_PAD_CTRL),
Martyn Welch110f5d92018-01-10 20:31:32 +0100383 MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500384};
385#define SUS_S3_OUT IMX_GPIO_NR(4, 11)
386#define WIFI_EN IMX_GPIO_NR(6, 14)
387
388int board_early_init_f(void)
389{
390 imx_iomux_v3_setup_multiple_pads(misc_pads,
391 ARRAY_SIZE(misc_pads));
392
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400393#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray28540c52018-10-15 09:59:44 +0200394 /* Set LDB clock to Video PLL */
395 select_ldb_di_clock_source(MXC_PLL5_CLK);
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400396#endif
Akshay Bhat197f9872016-01-29 15:16:40 -0500397 return 0;
398}
399
Nandor Han7a9bb302018-04-25 16:57:01 +0200400static void set_confidx(const struct vpd_cache* vpd)
401{
402 switch (vpd->product_id) {
403 case VPD_PRODUCT_B450:
404 confidx = 1;
405 break;
406 case VPD_PRODUCT_B650:
407 confidx = 2;
408 break;
409 case VPD_PRODUCT_B850:
410 confidx = 3;
411 break;
412 }
413}
414
Akshay Bhat197f9872016-01-29 15:16:40 -0500415int board_init(void)
416{
Sebastian Reichel5f05ebc2020-09-02 19:31:45 +0200417 if (!read_i2c_vpd(&vpd, vpd_callback)) {
Robert Beckettf746ab62019-11-12 19:15:11 +0000418 int ret, rescan;
419
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200420 vpd.is_read = true;
421 set_confidx(&vpd);
Robert Beckettf746ab62019-11-12 19:15:11 +0000422
423 ret = fdtdec_resetup(&rescan);
424 if (!ret && rescan) {
425 dm_uninit();
426 dm_init_and_scan(false);
427 }
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200428 }
Nandor Han7a9bb302018-04-25 16:57:01 +0200429
Ian Ray5f1e3442019-01-31 16:21:13 +0200430 gpio_request(SUS_S3_OUT, "sus_s3_out");
Akshay Bhat197f9872016-01-29 15:16:40 -0500431 gpio_direction_output(SUS_S3_OUT, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200432
433 gpio_request(WIFI_EN, "wifi_en");
Akshay Bhat197f9872016-01-29 15:16:40 -0500434 gpio_direction_output(WIFI_EN, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200435
Akshay Bhat197f9872016-01-29 15:16:40 -0500436#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray6eac23f2018-04-25 16:57:02 +0200437 if (is_b850v3())
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400438 setup_display_b850v3();
439 else
440 setup_display_bx50v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500441#endif
Ian Ray5f1e3442019-01-31 16:21:13 +0200442
Akshay Bhat197f9872016-01-29 15:16:40 -0500443 /* address of boot parameters */
444 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
445
Akshay Bhat197f9872016-01-29 15:16:40 -0500446 return 0;
447}
448
449#ifdef CONFIG_CMD_BMODE
450static const struct boot_mode board_boot_modes[] = {
451 /* 4 bit bus width */
452 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
453 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
454 {NULL, 0},
455};
456#endif
457
Ken Linc7219fc2016-11-18 12:20:54 -0500458void pmic_init(void)
459{
Robert Beckett53bab172020-01-31 15:07:54 +0200460 struct udevice *reg;
461 int ret, i;
462 static const char * const bucks[] = {
463 "bcore1",
464 "bcore2",
465 "bpro",
466 "bmem",
467 "bio",
468 "bperi",
469 };
Ken Linc7219fc2016-11-18 12:20:54 -0500470
Robert Beckett53bab172020-01-31 15:07:54 +0200471 for (i = 0; i < ARRAY_SIZE(bucks); i++) {
472 ret = regulator_get_by_devname(bucks[i], &reg);
473 if (reg < 0) {
474 printf("%s(): Unable to get regulator %s: %d\n",
475 __func__, bucks[i], ret);
476 continue;
477 }
478 regulator_set_mode(reg, DA9063_BUCKMODE_SYNC);
479 }
Ken Linc7219fc2016-11-18 12:20:54 -0500480}
481
Akshay Bhat197f9872016-01-29 15:16:40 -0500482int board_late_init(void)
483{
Nandor Han7a9bb302018-04-25 16:57:01 +0200484 process_vpd(&vpd);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100485
Akshay Bhat197f9872016-01-29 15:16:40 -0500486#ifdef CONFIG_CMD_BMODE
487 add_board_boot_modes(board_boot_modes);
488#endif
Andrew Shadurac26583d2016-05-24 15:56:17 +0200489
Ian Rayd8c60992018-04-25 16:57:03 +0200490 if (is_b850v3())
491 env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60");
Ian Ray476e4e62018-10-15 09:59:45 +0200492 else
493 env_set("videoargs", "video=LVDS-1:1024x768@65");
Ian Rayd8c60992018-04-25 16:57:03 +0200494
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{
554 if (!vpd.is_read)
555 return strcmp(name, "imx6q-bx50v3");
556
557 switch (vpd.product_id) {
558 case VPD_PRODUCT_B450:
559 return strcmp(name, "imx6q-b450v3");
560 case VPD_PRODUCT_B650:
561 return strcmp(name, "imx6q-b650v3");
562 case VPD_PRODUCT_B850:
563 return strcmp(name, "imx6q-b850v3");
564 default:
565 return -1;
566 }
567}
568
569int embedded_dtb_select(void)
570{
571 vpd.is_read = false;
572 return fdtdec_setup();
573}