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 | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 8 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 10 | #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 Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 14 | #include <env.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 16 | #include <linux/errno.h> |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 17 | #include <linux/libfdt.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 18 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 19 | #include <asm/mach-imx/iomux-v3.h> |
| 20 | #include <asm/mach-imx/boot_mode.h> |
| 21 | #include <asm/mach-imx/video.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 22 | #include <mmc.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 23 | #include <fsl_esdhc_imx.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 24 | #include <miiphy.h> |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 25 | #include <net.h> |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 26 | #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 Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 31 | #include <power/regulator.h> |
| 32 | #include <power/da9063_pmic.h> |
Diego Dorta | 2661c9c | 2017-09-22 12:12:18 -0300 | [diff] [blame] | 33 | #include <input.h> |
Akshay Bhat | 5d64362 | 2016-04-12 18:13:59 -0400 | [diff] [blame] | 34 | #include <pwm.h> |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 35 | #include <version.h> |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 36 | #include <stdlib.h> |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 37 | #include <dm/root.h> |
Sebastian Reichel | 9cad099 | 2020-09-02 19:31:43 +0200 | [diff] [blame] | 38 | #include "../common/ge_rtc.h" |
Martyn Welch | 66697ce | 2017-11-08 15:35:15 +0000 | [diff] [blame] | 39 | #include "../common/vpd_reader.h" |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 40 | #include "../../../drivers/net/e1000.h" |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 41 | #include <pci.h> |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 42 | #include <panel.h> |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 43 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 46 | #define VPD_PRODUCT_B850 1 |
| 47 | #define VPD_PRODUCT_B650 2 |
| 48 | #define VPD_PRODUCT_B450 3 |
| 49 | |
Sebastian Reichel | b8f2cce | 2020-12-15 00:41:57 +0100 | [diff] [blame^] | 50 | #define AR8033_DBG_REG_ADDR 0x1d |
| 51 | #define AR8033_DBG_REG_DATA 0x1e |
| 52 | #define AR8033_SERDES_REG 0x5 |
| 53 | |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 54 | static int productid; /* Default to generic. */ |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 55 | static struct vpd_cache vpd; |
| 56 | |
Justin Waters | ef93fc2 | 2016-04-13 17:03:18 -0400 | [diff] [blame] | 57 | #define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 58 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 59 | PAD_CTL_HYS) |
| 60 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 61 | int dram_init(void) |
| 62 | { |
Fabio Estevam | dd5d4e4 | 2016-07-23 13:23:40 -0300 | [diff] [blame] | 63 | gd->ram_size = imx_ddr_size(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 68 | int board_phy_config(struct phy_device *phydev) |
| 69 | { |
Sebastian Reichel | b8f2cce | 2020-12-15 00:41:57 +0100 | [diff] [blame^] | 70 | /* |
| 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 78 | |
| 79 | if (phydev->drv->config) |
| 80 | phydev->drv->config(phydev); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | #if defined(CONFIG_VIDEO_IPUV3) |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 86 | static 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 100 | |
| 101 | static void do_enable_hdmi(struct display_info_t const *dev) |
| 102 | { |
| 103 | imx_enable_hdmi_phy(); |
| 104 | } |
| 105 | |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 106 | static int is_b850v3(void) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 107 | { |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 108 | return productid == VPD_PRODUCT_B850; |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 109 | } |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 110 | |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 111 | static int detect_lcd(struct display_info_t const *dev) |
| 112 | { |
| 113 | return !is_b850v3(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | struct display_info_t const displays[] = {{ |
| 117 | .bus = -1, |
| 118 | .addr = -1, |
| 119 | .pixfmt = IPU_PIX_FMT_RGB24, |
Ian Ray | f8e4fab | 2018-04-25 16:56:58 +0200 | [diff] [blame] | 120 | .detect = detect_lcd, |
Robert Beckett | b2185d2 | 2020-01-31 15:07:59 +0200 | [diff] [blame] | 121 | .enable = do_enable_backlight, |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 122 | .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 | } } }; |
| 157 | size_t display_count = ARRAY_SIZE(displays); |
| 158 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 159 | static 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 166 | /* 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 Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 177 | 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 181 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1)); |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 182 | |
| 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 Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 200 | static void setup_display_b850v3(void) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 201 | { |
| 202 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 203 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 204 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 205 | enable_videopll(); |
| 206 | |
Ian Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 207 | /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */ |
| 208 | setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV); |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 209 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 210 | imx_setup_hdmi(); |
| 211 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 212 | /* 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 217 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 218 | /* Turn on IPU LDB DI0 clocks */ |
| 219 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK); |
| 220 | |
| 221 | enable_ipu_clock(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 222 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 223 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 234 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 235 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 240 | |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 241 | static 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 245 | |
Ian Ray | 66395e8 | 2018-04-25 16:57:00 +0200 | [diff] [blame] | 246 | enable_videopll(); |
| 247 | |
Akshay Bhat | 66027fe | 2016-04-12 18:14:00 -0400 | [diff] [blame] | 248 | /* 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 Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 255 | /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */ |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 256 | 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 280 | } |
| 281 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 282 | |
| 283 | /* |
| 284 | * Do not overwrite the console |
| 285 | * Use always serial for U-Boot console |
| 286 | */ |
| 287 | int overwrite_console(void) |
| 288 | { |
| 289 | return 1; |
| 290 | } |
| 291 | |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 292 | #define VPD_TYPE_INVALID 0x00 |
| 293 | #define VPD_BLOCK_NETWORK 0x20 |
| 294 | #define VPD_BLOCK_HWID 0x44 |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 295 | #define VPD_HAS_MAC1 0x1 |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 296 | #define VPD_HAS_MAC2 0x2 |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 297 | #define VPD_MAC_ADDRESS_LENGTH 6 |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 298 | |
| 299 | struct vpd_cache { |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 300 | bool is_read; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 301 | u8 product_id; |
| 302 | u8 has; |
| 303 | unsigned char mac1[VPD_MAC_ADDRESS_LENGTH]; |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 304 | unsigned char mac2[VPD_MAC_ADDRESS_LENGTH]; |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | /* |
| 308 | * Extracts MAC and product information from the VPD. |
| 309 | */ |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 310 | 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] | 311 | size_t size, u8 const *data) |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 312 | { |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 313 | if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID && |
| 314 | size >= 1) { |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 315 | vpd->product_id = data[0]; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 316 | } 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 Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 322 | if (size >= 12) { |
| 323 | vpd->has |= VPD_HAS_MAC2; |
| 324 | memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH); |
| 325 | } |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 331 | static void process_vpd(struct vpd_cache *vpd) |
| 332 | { |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 333 | int fec_index = 0; |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 334 | int i210_index = -1; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 335 | |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 336 | if (!vpd->is_read) { |
| 337 | printf("VPD wasn't read"); |
| 338 | return; |
| 339 | } |
| 340 | |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 341 | 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 Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 346 | switch (vpd->product_id) { |
| 347 | case VPD_PRODUCT_B450: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 348 | i210_index = 1; |
Ian Ray | b52e252 | 2018-01-10 20:31:33 +0100 | [diff] [blame] | 349 | break; |
| 350 | case VPD_PRODUCT_B650: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 351 | i210_index = 1; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 352 | break; |
| 353 | case VPD_PRODUCT_B850: |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 354 | i210_index = 2; |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 355 | break; |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 356 | } |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 357 | |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 358 | if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2)) |
| 359 | eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2); |
Ian Ray | c0293da | 2017-08-22 09:03:54 +0300 | [diff] [blame] | 360 | } |
| 361 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 362 | static iomux_v3_cfg_t const misc_pads[] = { |
| 363 | MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Justin Waters | ef93fc2 | 2016-04-13 17:03:18 -0400 | [diff] [blame] | 364 | 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 Welch | 110f5d9 | 2018-01-10 20:31:32 +0100 | [diff] [blame] | 370 | MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL), |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 371 | }; |
| 372 | #define SUS_S3_OUT IMX_GPIO_NR(4, 11) |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 373 | #define PWGIN_IN IMX_GPIO_NR(4, 14) |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 374 | #define WIFI_EN IMX_GPIO_NR(6, 14) |
| 375 | |
| 376 | int board_early_init_f(void) |
| 377 | { |
| 378 | imx_iomux_v3_setup_multiple_pads(misc_pads, |
| 379 | ARRAY_SIZE(misc_pads)); |
| 380 | |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 381 | #if defined(CONFIG_VIDEO_IPUV3) |
Ian Ray | 28540c5 | 2018-10-15 09:59:44 +0200 | [diff] [blame] | 382 | /* Set LDB clock to Video PLL */ |
| 383 | select_ldb_di_clock_source(MXC_PLL5_CLK); |
Akshay Bhat | 3a5b15a | 2016-04-12 18:13:58 -0400 | [diff] [blame] | 384 | #endif |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | int board_init(void) |
| 389 | { |
Sebastian Reichel | 5f05ebc | 2020-09-02 19:31:45 +0200 | [diff] [blame] | 390 | if (!read_i2c_vpd(&vpd, vpd_callback)) { |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 391 | int ret, rescan; |
| 392 | |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 393 | vpd.is_read = true; |
Sebastian Reichel | 3087190 | 2020-11-04 17:18:41 +0100 | [diff] [blame] | 394 | productid = vpd.product_id; |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 395 | |
| 396 | ret = fdtdec_resetup(&rescan); |
| 397 | if (!ret && rescan) { |
| 398 | dm_uninit(); |
| 399 | dm_init_and_scan(false); |
| 400 | } |
Denis Zalevskiy | 22a347d | 2018-10-17 10:33:30 +0200 | [diff] [blame] | 401 | } |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 402 | |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 403 | gpio_request(SUS_S3_OUT, "sus_s3_out"); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 404 | gpio_direction_output(SUS_S3_OUT, 1); |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 405 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 406 | gpio_request(PWGIN_IN, "pwgin_in"); |
| 407 | gpio_direction_input(PWGIN_IN); |
| 408 | |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 409 | gpio_request(WIFI_EN, "wifi_en"); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 410 | gpio_direction_output(WIFI_EN, 1); |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 411 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 412 | #if defined(CONFIG_VIDEO_IPUV3) |
Ian Ray | 6eac23f | 2018-04-25 16:57:02 +0200 | [diff] [blame] | 413 | if (is_b850v3()) |
Akshay Bhat | cc4e4b6 | 2016-04-12 18:13:57 -0400 | [diff] [blame] | 414 | setup_display_b850v3(); |
| 415 | else |
| 416 | setup_display_bx50v3(); |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 417 | #endif |
Ian Ray | 5f1e344 | 2019-01-31 16:21:13 +0200 | [diff] [blame] | 418 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 419 | /* address of boot parameters */ |
| 420 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 421 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | #ifdef CONFIG_CMD_BMODE |
| 426 | static 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 Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 434 | void pmic_init(void) |
| 435 | { |
Robert Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 436 | 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 Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 446 | |
Robert Beckett | 53bab17 | 2020-01-31 15:07:54 +0200 | [diff] [blame] | 447 | for (i = 0; i < ARRAY_SIZE(bucks); i++) { |
| 448 | ret = regulator_get_by_devname(bucks[i], ®); |
| 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 Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 456 | } |
| 457 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 458 | static 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 Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 469 | int board_late_init(void) |
| 470 | { |
Nandor Han | 7a9bb30 | 2018-04-25 16:57:01 +0200 | [diff] [blame] | 471 | process_vpd(&vpd); |
Martyn Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 472 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 473 | #ifdef CONFIG_CMD_BMODE |
| 474 | add_board_boot_modes(board_boot_modes); |
| 475 | #endif |
Andrew Shadura | c26583d | 2016-05-24 15:56:17 +0200 | [diff] [blame] | 476 | |
Ian Ray | d8c6099 | 2018-04-25 16:57:03 +0200 | [diff] [blame] | 477 | if (is_b850v3()) |
| 478 | 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] | 479 | else |
| 480 | env_set("videoargs", "video=LVDS-1:1024x768@65"); |
Ian Ray | d8c6099 | 2018-04-25 16:57:03 +0200 | [diff] [blame] | 481 | |
Ian Ray | a8203cc | 2020-11-04 17:18:43 +0100 | [diff] [blame] | 482 | detect_boot_cause(); |
| 483 | |
Ken Lin | c7219fc | 2016-11-18 12:20:54 -0500 | [diff] [blame] | 484 | /* board specific pmic init */ |
| 485 | pmic_init(); |
| 486 | |
Nandor Han | ae3c6d2 | 2018-01-10 20:31:38 +0100 | [diff] [blame] | 487 | check_time(); |
| 488 | |
Denis Zalevskiy | 0d97471 | 2019-11-12 19:15:17 +0000 | [diff] [blame] | 489 | pci_init(); |
| 490 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 494 | /* |
| 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 | */ |
| 499 | static 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 Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 507 | int last_stage_init(void) |
| 508 | { |
Hannu Lounento | 3787968 | 2018-01-10 20:31:31 +0100 | [diff] [blame] | 509 | 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 Welch | 18c31ea | 2018-01-10 20:31:30 +0100 | [diff] [blame] | 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
Akshay Bhat | 197f987 | 2016-01-29 15:16:40 -0500 | [diff] [blame] | 521 | int checkboard(void) |
| 522 | { |
| 523 | printf("BOARD: %s\n", CONFIG_BOARD_NAME); |
| 524 | return 0; |
| 525 | } |
Ian Ray | 4013368 | 2018-04-04 10:50:17 +0200 | [diff] [blame] | 526 | |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 527 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 528 | int ft_board_setup(void *blob, struct bd_info *bd) |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 529 | { |
Ian Ray | c69217c | 2019-11-12 19:15:18 +0000 | [diff] [blame] | 530 | char *rtc_status = env_get("rtc_status"); |
| 531 | |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 532 | fdt_setprop(blob, 0, "ge,boot-ver", version_string, |
Ian Ray | c69217c | 2019-11-12 19:15:18 +0000 | [diff] [blame] | 533 | strlen(version_string) + 1); |
| 534 | |
| 535 | fdt_setprop(blob, 0, "ge,rtc-status", rtc_status, |
| 536 | strlen(rtc_status) + 1); |
Ian Ray | 6445094 | 2019-01-31 16:21:18 +0200 | [diff] [blame] | 537 | return 0; |
| 538 | } |
| 539 | #endif |
| 540 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 541 | int board_fit_config_name_match(const char *name) |
| 542 | { |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 543 | const char *machine = name; |
| 544 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 545 | if (!vpd.is_read) |
| 546 | return strcmp(name, "imx6q-bx50v3"); |
| 547 | |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 548 | if (!strncmp(machine, "Boot ", 5)) |
| 549 | machine += 5; |
| 550 | if (!strncmp(machine, "imx6q-", 6)) |
| 551 | machine += 6; |
| 552 | |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 553 | switch (vpd.product_id) { |
| 554 | case VPD_PRODUCT_B450: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 555 | return strcasecmp(machine, "b450v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 556 | case VPD_PRODUCT_B650: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 557 | return strcasecmp(machine, "b650v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 558 | case VPD_PRODUCT_B850: |
Sebastian Reichel | 9945390 | 2020-12-15 00:41:56 +0100 | [diff] [blame] | 559 | return strcasecmp(machine, "b850v3"); |
Robert Beckett | f746ab6 | 2019-11-12 19:15:11 +0000 | [diff] [blame] | 560 | default: |
| 561 | return -1; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | int embedded_dtb_select(void) |
| 566 | { |
| 567 | vpd.is_read = false; |
| 568 | return fdtdec_setup(); |
| 569 | } |