Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Timesys Corporation |
| 4 | * Copyright 2015 General Electric Company |
| 5 | * Copyright 2012 Freescale Semiconductor, Inc. |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 8 | #include <event.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 11 | #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 Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 15 | #include <env.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 18 | #include <linux/errno.h> |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 19 | #include <linux/libfdt.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 20 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 21 | #include <asm/mach-imx/iomux-v3.h> |
| 22 | #include <asm/mach-imx/boot_mode.h> |
| 23 | #include <asm/mach-imx/video.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 24 | #include <mmc.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 25 | #include <fsl_esdhc_imx.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 26 | #include <miiphy.h> |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 27 | #include <net.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 28 | #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 Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 33 | #include <power/regulator.h> |
| 34 | #include <power/da9063_pmic.h> |
Sebastian Reichel | 1b620ce | 2021-04-23 16:15:07 +0200 | [diff] [blame] | 35 | #include <power/pmic.h> |
Diego Dorta | 2661c9c | 2017-09-22 12:12:18 -0300 | [diff] [blame] | 36 | #include <input.h> |
Akshay Bhat | 5d64362 | 2016-04-12 18:13:59 -0400 | [diff] [blame] | 37 | #include <pwm.h> |
Pali Rohár | ba87ddf | 2021-08-02 15:18:31 +0200 | [diff] [blame] | 38 | #include <version_string.h> |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 39 | #include <stdlib.h> |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 40 | #include <dm/root.h> |
Sebastian Reichel | 9cad099 | 2020-09-02 19:31:43 +0200 | [diff] [blame] | 41 | #include "../common/ge_rtc.h" |
Martyn Welch | 66697ce | 2017-11-08 15:35:15 +0000 | [diff] [blame] | 42 | #include "../common/vpd_reader.h" |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 43 | #include "../../../drivers/net/e1000.h" |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 44 | #include <pci.h> |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 45 | #include <panel.h> |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 46 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 47 | DECLARE_GLOBAL_DATA_PTR; |
| 48 | |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 49 | #define VPD_PRODUCT_B850 1 |
| 50 | #define VPD_PRODUCT_B650 2 |
| 51 | #define VPD_PRODUCT_B450 3 |
| 52 | |
Sebastian Reichel | b8f2cce | 2020-12-15 00:41:57 +0100 | [diff] [blame] | 53 | #define AR8033_DBG_REG_ADDR 0x1d |
| 54 | #define AR8033_DBG_REG_DATA 0x1e |
| 55 | #define AR8033_SERDES_REG 0x5 |
| 56 | |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 57 | static int productid; /* Default to generic. */ |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 58 | static struct vpd_cache vpd; |
| 59 | |
Justin Waters | ef93fc2 | 2016-04-13 17:03:18 -0400 | [diff] [blame] | 60 | #define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 61 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 62 | PAD_CTL_HYS) |
| 63 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 64 | int dram_init(void) |
| 65 | { |
Fabio Estevam | dd5d4e4 | 2016-07-23 13:23:40 -0300 | [diff] [blame] | 66 | gd->ram_size = imx_ddr_size(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 71 | int board_phy_config(struct phy_device *phydev) |
| 72 | { |
Sebastian Reichel | b8f2cce | 2020-12-15 00:41:57 +0100 | [diff] [blame] | 73 | /* |
| 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 81 | |
| 82 | if (phydev->drv->config) |
| 83 | phydev->drv->config(phydev); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | #if defined(CONFIG_VIDEO_IPUV3) |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 89 | static 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 103 | |
| 104 | static void do_enable_hdmi(struct display_info_t const *dev) |
| 105 | { |
| 106 | imx_enable_hdmi_phy(); |
| 107 | } |
| 108 | |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 109 | static int is_b850v3(void) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 110 | { |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 111 | return productid == VPD_PRODUCT_B850; |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 112 | } |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 113 | |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 114 | static int detect_lcd(struct display_info_t const *dev) |
| 115 | { |
| 116 | return !is_b850v3(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct display_info_t const displays[] = {{ |
| 120 | .bus = -1, |
| 121 | .addr = -1, |
| 122 | .pixfmt = IPU_PIX_FMT_RGB24, |
Ian Ray | f8e4fab | 2018-04-25 16:56:58 +0200 | [diff] [blame] | 123 | .detect = detect_lcd, |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 124 | .enable = do_enable_backlight, |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 125 | .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 | } } }; |
| 160 | size_t display_count = ARRAY_SIZE(displays); |
| 161 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 162 | static 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 169 | /* 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 Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 180 | 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 184 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1)); |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 185 | |
| 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 Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 203 | static void setup_display_b850v3(void) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 204 | { |
| 205 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 206 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 207 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 208 | enable_videopll(); |
| 209 | |
Ian Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 210 | /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */ |
| 211 | setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV); |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 212 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 213 | imx_setup_hdmi(); |
| 214 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 215 | /* 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 220 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 221 | /* Turn on IPU LDB DI0 clocks */ |
| 222 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK); |
| 223 | |
| 224 | enable_ipu_clock(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 225 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 226 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 237 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 238 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 243 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 244 | static 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 248 | |
Ian Ray | 66395e8 | 2018-04-25 16:57:00 +0200 | [diff] [blame] | 249 | enable_videopll(); |
| 250 | |
Akshay Bhat | 66027fe | 2016-04-12 18:14:00 -0400 | [diff] [blame] | 251 | /* 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 258 | /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */ |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 259 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 283 | } |
| 284 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 285 | |
| 286 | /* |
| 287 | * Do not overwrite the console |
| 288 | * Use always serial for U-Boot console |
| 289 | */ |
| 290 | int overwrite_console(void) |
| 291 | { |
| 292 | return 1; |
| 293 | } |
| 294 | |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 295 | #define VPD_TYPE_INVALID 0x00 |
| 296 | #define VPD_BLOCK_NETWORK 0x20 |
| 297 | #define VPD_BLOCK_HWID 0x44 |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 298 | #define VPD_HAS_MAC1 0x1 |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 299 | #define VPD_HAS_MAC2 0x2 |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 300 | #define VPD_MAC_ADDRESS_LENGTH 6 |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 301 | |
| 302 | struct vpd_cache { |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 303 | bool is_read; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 304 | u8 product_id; |
| 305 | u8 has; |
| 306 | unsigned char mac1[VPD_MAC_ADDRESS_LENGTH]; |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 307 | unsigned char mac2[VPD_MAC_ADDRESS_LENGTH]; |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | /* |
| 311 | * Extracts MAC and product information from the VPD. |
| 312 | */ |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 313 | static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type, |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 314 | size_t size, u8 const *data) |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 315 | { |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 316 | if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID && |
| 317 | size >= 1) { |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 318 | vpd->product_id = data[0]; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 319 | } 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 Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 325 | if (size >= 12) { |
| 326 | vpd->has |= VPD_HAS_MAC2; |
| 327 | memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH); |
| 328 | } |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 334 | static void process_vpd(struct vpd_cache *vpd) |
| 335 | { |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 336 | int fec_index = 0; |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 337 | int i210_index = -1; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 338 | |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 339 | if (!vpd->is_read) { |
| 340 | printf("VPD wasn't read"); |
| 341 | return; |
| 342 | } |
| 343 | |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 344 | 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 Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 349 | switch (vpd->product_id) { |
| 350 | case VPD_PRODUCT_B450: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 351 | i210_index = 1; |
Ian Ray | b52e252 | 2018-01-10 20:31:33 +0100 | [diff] [blame] | 352 | break; |
| 353 | case VPD_PRODUCT_B650: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 354 | i210_index = 1; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 355 | break; |
| 356 | case VPD_PRODUCT_B850: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 357 | i210_index = 2; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 358 | break; |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 359 | } |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 360 | |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 361 | if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2)) |
| 362 | eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2); |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 363 | } |
| 364 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 365 | static iomux_v3_cfg_t const misc_pads[] = { |
| 366 | MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Justin Waters | ef93fc2 | 2016-04-13 17:03:18 -0400 | [diff] [blame] | 367 | 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 Welch | 110f5d9 | 2018-01-10 20:31:32 +0100 | [diff] [blame] | 373 | MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL), |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 374 | }; |
| 375 | #define SUS_S3_OUT IMX_GPIO_NR(4, 11) |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 376 | #define PWGIN_IN IMX_GPIO_NR(4, 14) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 377 | #define WIFI_EN IMX_GPIO_NR(6, 14) |
| 378 | |
| 379 | int board_early_init_f(void) |
| 380 | { |
| 381 | imx_iomux_v3_setup_multiple_pads(misc_pads, |
| 382 | ARRAY_SIZE(misc_pads)); |
| 383 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 384 | #if defined(CONFIG_VIDEO_IPUV3) |
Ian Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 385 | /* Set LDB clock to Video PLL */ |
| 386 | select_ldb_di_clock_source(MXC_PLL5_CLK); |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 387 | #endif |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | int board_init(void) |
| 392 | { |
Sebastian Reichel | 5f05ebc | 2020-09-02 19:31:45 +0200 | [diff] [blame] | 393 | if (!read_i2c_vpd(&vpd, vpd_callback)) { |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 394 | int ret, rescan; |
| 395 | |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 396 | vpd.is_read = true; |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 397 | productid = vpd.product_id; |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 398 | |
| 399 | ret = fdtdec_resetup(&rescan); |
| 400 | if (!ret && rescan) { |
| 401 | dm_uninit(); |
| 402 | dm_init_and_scan(false); |
| 403 | } |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 404 | } |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 405 | |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 406 | gpio_request(SUS_S3_OUT, "sus_s3_out"); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 407 | gpio_direction_output(SUS_S3_OUT, 1); |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 408 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 409 | gpio_request(PWGIN_IN, "pwgin_in"); |
| 410 | gpio_direction_input(PWGIN_IN); |
| 411 | |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 412 | gpio_request(WIFI_EN, "wifi_en"); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 413 | gpio_direction_output(WIFI_EN, 1); |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 414 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 415 | #if defined(CONFIG_VIDEO_IPUV3) |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 416 | if (is_b850v3()) |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 417 | setup_display_b850v3(); |
| 418 | else |
| 419 | setup_display_bx50v3(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 420 | #endif |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 421 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 422 | /* address of boot parameters */ |
| 423 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 424 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | #ifdef CONFIG_CMD_BMODE |
| 429 | static 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 Reichel | 1b620ce | 2021-04-23 16:15:07 +0200 | [diff] [blame] | 437 | |
| 438 | /* |
| 439 | * The SoM used by these boards has XTAL not connected despite datasheet |
| 440 | * suggesting connecting unused XTAL pins to ground. Without explicitly |
| 441 | * clearing the CRYSTAL bit the system runs unstable and sometimes reboots |
| 442 | * unexpectedly. |
| 443 | */ |
| 444 | static void pmic_crystal_fix(void) |
| 445 | { |
| 446 | struct udevice *pmic; |
| 447 | static const uint EN_32K_CRYSTAL = (1 << 3); |
| 448 | |
| 449 | if (pmic_get("pmic@58", &pmic)) { |
| 450 | puts("failed to get device for PMIC\n"); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | if (pmic_clrsetbits(pmic, DA9063_REG_EN_32K, EN_32K_CRYSTAL, 0) < 0) { |
| 455 | puts("failed to clear CRYSTAL bit\n"); |
| 456 | return; |
| 457 | } |
| 458 | } |
| 459 | |
Ken Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 460 | void pmic_init(void) |
| 461 | { |
Robert Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 462 | struct udevice *reg; |
| 463 | int ret, i; |
| 464 | static const char * const bucks[] = { |
| 465 | "bcore1", |
| 466 | "bcore2", |
| 467 | "bpro", |
| 468 | "bmem", |
| 469 | "bio", |
| 470 | "bperi", |
| 471 | }; |
Ken Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 472 | |
Sebastian Reichel | 1b620ce | 2021-04-23 16:15:07 +0200 | [diff] [blame] | 473 | pmic_crystal_fix(); |
| 474 | |
Robert Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 475 | for (i = 0; i < ARRAY_SIZE(bucks); i++) { |
| 476 | ret = regulator_get_by_devname(bucks[i], ®); |
| 477 | if (reg < 0) { |
| 478 | printf("%s(): Unable to get regulator %s: %d\n", |
| 479 | __func__, bucks[i], ret); |
| 480 | continue; |
| 481 | } |
| 482 | regulator_set_mode(reg, DA9063_BUCKMODE_SYNC); |
| 483 | } |
Ken Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 484 | } |
| 485 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 486 | static void detect_boot_cause(void) |
| 487 | { |
| 488 | const char *cause = "POR"; |
| 489 | |
| 490 | if (is_b850v3()) |
| 491 | if (!gpio_get_value(PWGIN_IN)) |
| 492 | cause = "PM_WDOG"; |
| 493 | |
| 494 | env_set("bootcause", cause); |
| 495 | } |
| 496 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 497 | int board_late_init(void) |
| 498 | { |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 499 | process_vpd(&vpd); |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 500 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 501 | #ifdef CONFIG_CMD_BMODE |
| 502 | add_board_boot_modes(board_boot_modes); |
| 503 | #endif |
Andrew Shadura | c26583d | 2016-05-24 15:56:17 +0200 | [diff] [blame] | 504 | |
Ian Ray | d8c6099 | 2018-04-25 16:57:03 +0200 | [diff] [blame] | 505 | if (is_b850v3()) |
| 506 | env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60"); |
Ian Ray | 476e4e6 | 2018-10-15 09:59:45 +0200 | [diff] [blame] | 507 | else |
| 508 | env_set("videoargs", "video=LVDS-1:1024x768@65"); |
Ian Ray | d8c6099 | 2018-04-25 16:57:03 +0200 | [diff] [blame] | 509 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 510 | detect_boot_cause(); |
| 511 | |
Ken Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 512 | /* board specific pmic init */ |
| 513 | pmic_init(); |
| 514 | |
Nandor Han | ae3c6d2 | 2018-01-10 20:31:38 +0100 | [diff] [blame] | 515 | check_time(); |
| 516 | |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 517 | pci_init(); |
| 518 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 519 | return 0; |
| 520 | } |
| 521 | |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 522 | /* |
| 523 | * Removes the 'eth[0-9]*addr' environment variable with the given index |
| 524 | * |
| 525 | * @param index [in] the index of the eth_device whose variable is to be removed |
| 526 | */ |
| 527 | static void remove_ethaddr_env_var(int index) |
| 528 | { |
| 529 | char env_var_name[9]; |
| 530 | |
| 531 | sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index); |
| 532 | env_set(env_var_name, NULL); |
| 533 | } |
| 534 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 535 | static int last_stage_init(void) |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 536 | { |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 537 | int i; |
| 538 | |
| 539 | /* |
| 540 | * Remove first three ethaddr which may have been created by |
| 541 | * function process_vpd(). |
| 542 | */ |
| 543 | for (i = 0; i < 3; ++i) |
| 544 | remove_ethaddr_env_var(i); |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 545 | |
| 546 | return 0; |
| 547 | } |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 548 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 549 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 550 | int checkboard(void) |
| 551 | { |
Tom Rini | 272eb5b | 2022-03-21 21:33:32 -0400 | [diff] [blame] | 552 | printf("BOARD: General Electric Bx50v3\n"); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 553 | return 0; |
| 554 | } |
Ian Ray | 4013368 | 2018-04-04 10:50:17 +0200 | [diff] [blame] | 555 | |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 556 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 557 | int ft_board_setup(void *blob, struct bd_info *bd) |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 558 | { |
Ian Ray | c69217c | 2019-11-12 19:15:18 +0000 | [diff] [blame] | 559 | char *rtc_status = env_get("rtc_status"); |
| 560 | |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 561 | fdt_setprop(blob, 0, "ge,boot-ver", version_string, |
Ian Ray | c69217c | 2019-11-12 19:15:18 +0000 | [diff] [blame] | 562 | strlen(version_string) + 1); |
| 563 | |
| 564 | fdt_setprop(blob, 0, "ge,rtc-status", rtc_status, |
| 565 | strlen(rtc_status) + 1); |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | #endif |
| 569 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 570 | int board_fit_config_name_match(const char *name) |
| 571 | { |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 572 | const char *machine = name; |
| 573 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 574 | if (!vpd.is_read) |
| 575 | return strcmp(name, "imx6q-bx50v3"); |
| 576 | |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 577 | if (!strncmp(machine, "Boot ", 5)) |
| 578 | machine += 5; |
| 579 | if (!strncmp(machine, "imx6q-", 6)) |
| 580 | machine += 6; |
| 581 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 582 | switch (vpd.product_id) { |
| 583 | case VPD_PRODUCT_B450: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 584 | return strcasecmp(machine, "b450v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 585 | case VPD_PRODUCT_B650: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 586 | return strcasecmp(machine, "b650v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 587 | case VPD_PRODUCT_B850: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 588 | return strcasecmp(machine, "b850v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 589 | default: |
| 590 | return -1; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | int embedded_dtb_select(void) |
| 595 | { |
| 596 | vpd.is_read = false; |
| 597 | return fdtdec_setup(); |
| 598 | } |