Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Gateworks Corporation |
| 4 | * |
| 5 | * Author: Tim Harvey <tharvey@gateworks.com> |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
Tim Harvey | 4137785 | 2022-04-13 09:29:16 -0700 | [diff] [blame] | 8 | #include <command.h> |
Tim Harvey | 4137785 | 2022-04-13 09:29:16 -0700 | [diff] [blame] | 9 | #include <fdt_support.h> |
| 10 | #include <gsc.h> |
| 11 | #include <hwconfig.h> |
| 12 | #include <i2c.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <mtd_node.h> |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 15 | #include <asm/arch/clock.h> |
Tim Harvey | 0cee224 | 2015-05-08 18:28:35 -0700 | [diff] [blame] | 16 | #include <asm/arch/crm_regs.h> |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 17 | #include <asm/arch/mx6-pins.h> |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 18 | #include <asm/arch/mxc_hdmi.h> |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 19 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 20 | #include <asm/mach-imx/boot_mode.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 21 | #include <asm/mach-imx/video.h> |
Tim Harvey | 4137785 | 2022-04-13 09:29:16 -0700 | [diff] [blame] | 22 | #include <jffs2/load_kernel.h> |
Tim Harvey | 0cee224 | 2015-05-08 18:28:35 -0700 | [diff] [blame] | 23 | #include <linux/ctype.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 25 | |
Tim Harvey | 0cee224 | 2015-05-08 18:28:35 -0700 | [diff] [blame] | 26 | #include "common.h" |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 30 | /* configure eth0 PHY board-specific LED behavior */ |
| 31 | int board_phy_config(struct phy_device *phydev) |
| 32 | { |
| 33 | unsigned short val; |
Tim Harvey | b9d2352 | 2022-04-29 13:51:02 -0700 | [diff] [blame] | 34 | ofnode node; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 35 | |
Tim Harvey | b9d2352 | 2022-04-29 13:51:02 -0700 | [diff] [blame] | 36 | switch (phydev->phy_id) { |
| 37 | case 0x1410dd1: |
Tim Harvey | b25b758 | 2021-06-11 12:46:26 -0700 | [diff] [blame] | 38 | puts("MV88E1510"); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 39 | /* |
| 40 | * Page 3, Register 16: LED[2:0] Function Control Register |
| 41 | * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link |
| 42 | * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity |
| 43 | */ |
| 44 | phy_write(phydev, MDIO_DEVAD_NONE, 22, 3); |
| 45 | val = phy_read(phydev, MDIO_DEVAD_NONE, 16); |
| 46 | val &= 0xff00; |
| 47 | val |= 0x0017; |
| 48 | phy_write(phydev, MDIO_DEVAD_NONE, 16, val); |
| 49 | phy_write(phydev, MDIO_DEVAD_NONE, 22, 0); |
Tim Harvey | b9d2352 | 2022-04-29 13:51:02 -0700 | [diff] [blame] | 50 | break; |
| 51 | case 0x2000a231: |
Tim Harvey | b25b758 | 2021-06-11 12:46:26 -0700 | [diff] [blame] | 52 | puts("TIDP83867 "); |
Tim Harvey | 1662ad3 | 2021-06-11 12:46:25 -0700 | [diff] [blame] | 53 | /* LED configuration */ |
| 54 | val = 0; |
| 55 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 56 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 57 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 58 | |
Tim Harvey | 4533c90 | 2017-03-17 07:32:21 -0700 | [diff] [blame] | 59 | /* configure register 0x170 for ref CLKOUT */ |
| 60 | phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f); |
| 61 | phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170); |
| 62 | phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f); |
| 63 | val = phy_read(phydev, MDIO_DEVAD_NONE, 14); |
| 64 | val &= ~0x1f00; |
| 65 | val |= 0x0b00; /* chD tx clock*/ |
| 66 | phy_write(phydev, MDIO_DEVAD_NONE, 14, val); |
Tim Harvey | b9d2352 | 2022-04-29 13:51:02 -0700 | [diff] [blame] | 67 | break; |
| 68 | case 0xd565a401: |
| 69 | puts("GPY111 "); |
| 70 | node = phy_get_ofnode(phydev); |
| 71 | if (ofnode_valid(node)) { |
| 72 | u32 rx_delay, tx_delay; |
| 73 | |
| 74 | rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000); |
| 75 | tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000); |
| 76 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17); |
| 77 | val &= ~((0x7 << 12) | (0x7 << 8)); |
| 78 | val |= (rx_delay / 500) << 12; |
| 79 | val |= (tx_delay / 500) << 8; |
| 80 | phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val); |
| 81 | } |
| 82 | break; |
Tim Harvey | 4533c90 | 2017-03-17 07:32:21 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Tim Harvey | 781f6d8 | 2022-11-30 09:42:51 -0800 | [diff] [blame] | 85 | /* Fixed PHY: for GW5904/GW5909 this is Marvell 88E6176 GbE Switch */ |
| 86 | if (phydev->phy_id == PHY_FIXED_ID && |
| 87 | (board_type == GW5904 || board_type == GW5909)) { |
| 88 | struct mii_dev *bus = miiphy_get_dev_by_name("mdio"); |
Tim Harvey | 6353779 | 2017-03-17 07:30:38 -0700 | [diff] [blame] | 89 | |
Tim Harvey | 781f6d8 | 2022-11-30 09:42:51 -0800 | [diff] [blame] | 90 | puts("MV88E61XX "); |
| 91 | /* GPIO[0] output CLK125 for RGMII_REFCLK */ |
| 92 | bus->write(bus, 0x1c, 0, 0x1a, (1 << 15) | (0x62 << 8) | 0xfe); |
| 93 | bus->write(bus, 0x1c, 0, 0x1a, (1 << 15) | (0x68 << 8) | 7); |
Tim Harvey | 6353779 | 2017-03-17 07:30:38 -0700 | [diff] [blame] | 94 | |
Tim Harvey | 781f6d8 | 2022-11-30 09:42:51 -0800 | [diff] [blame] | 95 | /* Port 0-3 LED configuration: Table 80/82 */ |
| 96 | /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */ |
| 97 | bus->write(bus, 0x10, 0, 0x16, 0x8088); |
| 98 | bus->write(bus, 0x11, 0, 0x16, 0x8088); |
| 99 | bus->write(bus, 0x12, 0, 0x16, 0x8088); |
| 100 | bus->write(bus, 0x13, 0, 0x16, 0x8088); |
| 101 | } |
Tim Harvey | 6353779 | 2017-03-17 07:30:38 -0700 | [diff] [blame] | 102 | |
Tim Harvey | 781f6d8 | 2022-11-30 09:42:51 -0800 | [diff] [blame] | 103 | if (phydev->drv->config) |
| 104 | phydev->drv->config(phydev); |
Tim Harvey | 6353779 | 2017-03-17 07:30:38 -0700 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 108 | |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 109 | #if defined(CONFIG_VIDEO_IPUV3) |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 110 | static void enable_hdmi(struct display_info_t const *dev) |
| 111 | { |
| 112 | imx_enable_hdmi_phy(); |
| 113 | } |
| 114 | |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 115 | static int detect_lvds(struct display_info_t const *dev) |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 116 | { |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 117 | /* only the following boards support LVDS connectors */ |
| 118 | switch (board_type) { |
| 119 | case GW52xx: |
| 120 | case GW53xx: |
| 121 | case GW54xx: |
| 122 | case GW560x: |
| 123 | case GW5905: |
| 124 | case GW5909: |
| 125 | break; |
| 126 | default: |
| 127 | return 0; |
| 128 | } |
| 129 | |
Tim Harvey | 895aace | 2022-03-07 16:24:00 -0800 | [diff] [blame] | 130 | return (i2c_get_dev(dev->bus, dev->addr) ? 1 : 0); |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static void enable_lvds(struct display_info_t const *dev) |
| 134 | { |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 135 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 136 | |
| 137 | /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */ |
| 138 | u32 reg = readl(&iomux->gpr[2]); |
| 139 | reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT; |
| 140 | writel(reg, &iomux->gpr[2]); |
| 141 | |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 142 | /* Configure GPIO */ |
| 143 | switch (board_type) { |
| 144 | case GW52xx: |
| 145 | case GW53xx: |
| 146 | case GW54xx: |
| 147 | if (!strncmp(dev->mode.name, "Hannstar", 8)) { |
| 148 | SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG); |
| 149 | gpio_request(IMX_GPIO_NR(1, 10), "cabc"); |
| 150 | gpio_direction_output(IMX_GPIO_NR(1, 10), 0); |
| 151 | } else if (!strncmp(dev->mode.name, "DLC", 3)) { |
| 152 | SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG); |
| 153 | gpio_request(IMX_GPIO_NR(1, 10), "touch_rst#"); |
| 154 | gpio_direction_output(IMX_GPIO_NR(1, 10), 1); |
| 155 | } |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | /* Configure backlight */ |
Tim Harvey | f1f41db | 2015-05-08 18:28:28 -0700 | [diff] [blame] | 162 | gpio_request(IMX_GPIO_NR(1, 18), "bklt_en"); |
Tim Harvey | 2699336 | 2014-08-07 22:35:49 -0700 | [diff] [blame] | 163 | SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG); |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 164 | gpio_direction_output(IMX_GPIO_NR(1, 18), 1); |
| 165 | } |
| 166 | |
| 167 | struct display_info_t const displays[] = {{ |
| 168 | /* HDMI Output */ |
| 169 | .bus = -1, |
| 170 | .addr = 0, |
| 171 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 172 | .detect = detect_hdmi, |
| 173 | .enable = enable_hdmi, |
| 174 | .mode = { |
| 175 | .name = "HDMI", |
| 176 | .refresh = 60, |
| 177 | .xres = 1024, |
| 178 | .yres = 768, |
| 179 | .pixclock = 15385, |
| 180 | .left_margin = 220, |
| 181 | .right_margin = 40, |
| 182 | .upper_margin = 21, |
| 183 | .lower_margin = 7, |
| 184 | .hsync_len = 60, |
| 185 | .vsync_len = 10, |
| 186 | .sync = FB_SYNC_EXT, |
| 187 | .vmode = FB_VMODE_NONINTERLACED |
| 188 | } }, { |
| 189 | /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */ |
| 190 | .bus = 2, |
| 191 | .addr = 0x4, |
| 192 | .pixfmt = IPU_PIX_FMT_LVDS666, |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 193 | .detect = detect_lvds, |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 194 | .enable = enable_lvds, |
| 195 | .mode = { |
| 196 | .name = "Hannstar-XGA", |
| 197 | .refresh = 60, |
| 198 | .xres = 1024, |
| 199 | .yres = 768, |
| 200 | .pixclock = 15385, |
| 201 | .left_margin = 220, |
| 202 | .right_margin = 40, |
| 203 | .upper_margin = 21, |
| 204 | .lower_margin = 7, |
| 205 | .hsync_len = 60, |
| 206 | .vsync_len = 10, |
| 207 | .sync = FB_SYNC_EXT, |
| 208 | .vmode = FB_VMODE_NONINTERLACED |
Tim Harvey | a20bd63 | 2015-04-08 12:54:57 -0700 | [diff] [blame] | 209 | } }, { |
| 210 | /* DLC700JMG-T-4 */ |
Tim Harvey | be786e7 | 2019-02-04 13:10:53 -0800 | [diff] [blame] | 211 | .bus = 2, |
| 212 | .addr = 0x38, |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 213 | .detect = detect_lvds, |
Tim Harvey | a20bd63 | 2015-04-08 12:54:57 -0700 | [diff] [blame] | 214 | .enable = enable_lvds, |
| 215 | .pixfmt = IPU_PIX_FMT_LVDS666, |
| 216 | .mode = { |
| 217 | .name = "DLC700JMGT4", |
| 218 | .refresh = 60, |
| 219 | .xres = 1024, /* 1024x600active pixels */ |
| 220 | .yres = 600, |
| 221 | .pixclock = 15385, /* 64MHz */ |
| 222 | .left_margin = 220, |
| 223 | .right_margin = 40, |
| 224 | .upper_margin = 21, |
| 225 | .lower_margin = 7, |
| 226 | .hsync_len = 60, |
| 227 | .vsync_len = 10, |
| 228 | .sync = FB_SYNC_EXT, |
| 229 | .vmode = FB_VMODE_NONINTERLACED |
| 230 | } }, { |
Tim Harvey | 87a8645 | 2021-06-11 12:46:27 -0700 | [diff] [blame] | 231 | /* DLC0700XDP21LF-C-1 */ |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 232 | .bus = 2, |
| 233 | .addr = 0x38, |
| 234 | .detect = detect_lvds, |
Tim Harvey | 87a8645 | 2021-06-11 12:46:27 -0700 | [diff] [blame] | 235 | .enable = enable_lvds, |
| 236 | .pixfmt = IPU_PIX_FMT_LVDS666, |
| 237 | .mode = { |
| 238 | .name = "DLC0700XDP21LF", |
| 239 | .refresh = 60, |
| 240 | .xres = 1024, /* 1024x600active pixels */ |
| 241 | .yres = 600, |
| 242 | .pixclock = 15385, /* 64MHz */ |
| 243 | .left_margin = 220, |
| 244 | .right_margin = 40, |
| 245 | .upper_margin = 21, |
| 246 | .lower_margin = 7, |
| 247 | .hsync_len = 60, |
| 248 | .vsync_len = 10, |
| 249 | .sync = FB_SYNC_EXT, |
| 250 | .vmode = FB_VMODE_NONINTERLACED |
| 251 | } }, { |
Tim Harvey | a20bd63 | 2015-04-08 12:54:57 -0700 | [diff] [blame] | 252 | /* DLC800FIG-T-3 */ |
Tim Harvey | be786e7 | 2019-02-04 13:10:53 -0800 | [diff] [blame] | 253 | .bus = 2, |
| 254 | .addr = 0x14, |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 255 | .detect = detect_lvds, |
Tim Harvey | a20bd63 | 2015-04-08 12:54:57 -0700 | [diff] [blame] | 256 | .enable = enable_lvds, |
| 257 | .pixfmt = IPU_PIX_FMT_LVDS666, |
| 258 | .mode = { |
| 259 | .name = "DLC800FIGT3", |
| 260 | .refresh = 60, |
| 261 | .xres = 1024, /* 1024x768 active pixels */ |
| 262 | .yres = 768, |
| 263 | .pixclock = 15385, /* 64MHz */ |
| 264 | .left_margin = 220, |
| 265 | .right_margin = 40, |
| 266 | .upper_margin = 21, |
| 267 | .lower_margin = 7, |
| 268 | .hsync_len = 60, |
| 269 | .vsync_len = 10, |
| 270 | .sync = FB_SYNC_EXT, |
| 271 | .vmode = FB_VMODE_NONINTERLACED |
Tim Harvey | c34e59e | 2019-02-04 13:10:51 -0800 | [diff] [blame] | 272 | } }, { |
| 273 | .bus = 2, |
| 274 | .addr = 0x5d, |
Tim Harvey | ceb79f5 | 2021-09-29 15:04:21 -0700 | [diff] [blame] | 275 | .detect = detect_lvds, |
Tim Harvey | c34e59e | 2019-02-04 13:10:51 -0800 | [diff] [blame] | 276 | .enable = enable_lvds, |
| 277 | .pixfmt = IPU_PIX_FMT_LVDS666, |
| 278 | .mode = { |
| 279 | .name = "Z101WX01", |
| 280 | .refresh = 60, |
| 281 | .xres = 1280, |
| 282 | .yres = 800, |
| 283 | .pixclock = 15385, /* 64MHz */ |
| 284 | .left_margin = 220, |
| 285 | .right_margin = 40, |
| 286 | .upper_margin = 21, |
| 287 | .lower_margin = 7, |
| 288 | .hsync_len = 60, |
| 289 | .vsync_len = 10, |
| 290 | .sync = FB_SYNC_EXT, |
| 291 | .vmode = FB_VMODE_NONINTERLACED |
| 292 | } |
| 293 | }, |
| 294 | }; |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 295 | size_t display_count = ARRAY_SIZE(displays); |
| 296 | |
| 297 | static void setup_display(void) |
| 298 | { |
| 299 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 300 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 301 | int reg; |
| 302 | |
| 303 | enable_ipu_clock(); |
| 304 | imx_setup_hdmi(); |
| 305 | /* Turn on LDB0,IPU,IPU DI0 clocks */ |
| 306 | reg = __raw_readl(&mxc_ccm->CCGR3); |
| 307 | reg |= MXC_CCM_CCGR3_LDB_DI0_MASK; |
| 308 | writel(reg, &mxc_ccm->CCGR3); |
| 309 | |
| 310 | /* set LDB0, LDB1 clk select to 011/011 */ |
| 311 | reg = readl(&mxc_ccm->cs2cdr); |
| 312 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
| 313 | |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK); |
| 314 | reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
| 315 | |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET); |
| 316 | writel(reg, &mxc_ccm->cs2cdr); |
| 317 | |
| 318 | reg = readl(&mxc_ccm->cscmr2); |
| 319 | reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV; |
| 320 | writel(reg, &mxc_ccm->cscmr2); |
| 321 | |
| 322 | reg = readl(&mxc_ccm->chsccdr); |
| 323 | reg |= (CHSCCDR_CLK_SEL_LDB_DI0 |
| 324 | <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
| 325 | writel(reg, &mxc_ccm->chsccdr); |
| 326 | |
| 327 | reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
| 328 | |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH |
| 329 | |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
| 330 | |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
| 331 | |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT |
| 332 | |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
| 333 | |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
| 334 | |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED |
| 335 | |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0; |
| 336 | writel(reg, &iomux->gpr[2]); |
| 337 | |
| 338 | reg = readl(&iomux->gpr[3]); |
| 339 | reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK) |
| 340 | | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 |
| 341 | <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET); |
| 342 | writel(reg, &iomux->gpr[3]); |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 343 | } |
| 344 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 345 | |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 346 | /* |
| 347 | * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its |
| 348 | * GPIO's as PERST# signals for its downstream ports - configure the GPIO's |
| 349 | * properly and assert reset for 100ms. |
| 350 | */ |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 351 | #define MAX_PCI_DEVS 32 |
| 352 | struct pci_dev { |
| 353 | pci_dev_t devfn; |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 354 | struct udevice *dev; |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 355 | unsigned short vendor; |
| 356 | unsigned short device; |
| 357 | unsigned short class; |
| 358 | unsigned short busno; /* subbordinate busno */ |
| 359 | struct pci_dev *ppar; |
| 360 | }; |
| 361 | struct pci_dev pci_devs[MAX_PCI_DEVS]; |
| 362 | int pci_devno; |
| 363 | int pci_bridgeno; |
| 364 | |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 365 | void board_pci_fixup_dev(struct udevice *bus, struct udevice *udev) |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 366 | { |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 367 | struct pci_child_plat *pdata = dev_get_parent_plat(udev); |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 368 | struct pci_dev *pdev = &pci_devs[pci_devno++]; |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 369 | unsigned short vendor = pdata->vendor; |
| 370 | unsigned short device = pdata->device; |
| 371 | unsigned int class = pdata->class; |
| 372 | pci_dev_t dev = dm_pci_get_bdf(udev); |
| 373 | int i; |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 374 | |
| 375 | debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__, |
| 376 | PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device); |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 377 | |
| 378 | /* store array of devs for later use in device-tree fixup */ |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 379 | pdev->dev = udev; |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 380 | pdev->devfn = dev; |
| 381 | pdev->vendor = vendor; |
| 382 | pdev->device = device; |
| 383 | pdev->class = class; |
| 384 | pdev->ppar = NULL; |
| 385 | if (class == PCI_CLASS_BRIDGE_PCI) |
| 386 | pdev->busno = ++pci_bridgeno; |
| 387 | else |
| 388 | pdev->busno = 0; |
| 389 | |
| 390 | /* fixup RC - it should be 00:00.0 not 00:01.0 */ |
| 391 | if (PCI_BUS(dev) == 0) |
| 392 | pdev->devfn = 0; |
| 393 | |
| 394 | /* find dev's parent */ |
| 395 | for (i = 0; i < pci_devno; i++) { |
| 396 | if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) { |
| 397 | pdev->ppar = &pci_devs[i]; |
| 398 | break; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /* assert downstream PERST# */ |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 403 | if (vendor == PCI_VENDOR_ID_PLX && |
| 404 | (device & 0xfff0) == 0x8600 && |
| 405 | PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) { |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 406 | ulong val; |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 407 | debug("configuring PLX 860X downstream PERST#\n"); |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 408 | pci_bus_read_config(bus, dev, 0x62c, &val, PCI_SIZE_32); |
| 409 | val |= 0xaaa8; /* GPIO1-7 outputs */ |
| 410 | pci_bus_write_config(bus, dev, 0x62c, val, PCI_SIZE_32); |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 411 | |
Tim Harvey | 6ce10d5 | 2021-05-03 11:21:27 -0700 | [diff] [blame] | 412 | pci_bus_read_config(bus, dev, 0x644, &val, PCI_SIZE_32); |
| 413 | val |= 0xfe; /* GPIO1-7 output high */ |
| 414 | pci_bus_write_config(bus, dev, 0x644, val, PCI_SIZE_32); |
Tim Harvey | 33791d5 | 2014-08-07 22:49:57 -0700 | [diff] [blame] | 415 | |
| 416 | mdelay(100); |
| 417 | } |
| 418 | } |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 419 | |
| 420 | #ifdef CONFIG_SERIAL_TAG |
| 421 | /* |
| 422 | * called when setting up ATAGS before booting kernel |
| 423 | * populate serialnum from the following (in order of priority): |
| 424 | * serial# env var |
| 425 | * eeprom |
| 426 | */ |
| 427 | void get_board_serial(struct tag_serialnr *serialnr) |
| 428 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 429 | char *serial = env_get("serial#"); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 430 | |
| 431 | if (serial) { |
| 432 | serialnr->high = 0; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 433 | serialnr->low = dectoul(serial, NULL); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 434 | } else if (ventana_info.model[0]) { |
| 435 | serialnr->high = 0; |
| 436 | serialnr->low = ventana_info.serial; |
| 437 | } else { |
| 438 | serialnr->high = 0; |
| 439 | serialnr->low = 0; |
| 440 | } |
| 441 | } |
| 442 | #endif |
| 443 | |
| 444 | /* |
| 445 | * Board Support |
| 446 | */ |
| 447 | |
| 448 | int board_early_init_f(void) |
| 449 | { |
Tim Harvey | fb64cc7 | 2014-04-25 15:39:07 -0700 | [diff] [blame] | 450 | #if defined(CONFIG_VIDEO_IPUV3) |
| 451 | setup_display(); |
| 452 | #endif |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | int dram_init(void) |
| 457 | { |
Tim Harvey | bfa2dae | 2014-06-02 16:13:27 -0700 | [diff] [blame] | 458 | gd->ram_size = imx_ddr_size(); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | int board_init(void) |
| 463 | { |
Fabio Estevam | ceb74c4 | 2014-07-09 17:59:54 -0300 | [diff] [blame] | 464 | struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 465 | |
| 466 | clrsetbits_le32(&iomuxc_regs->gpr[1], |
| 467 | IOMUXC_GPR1_OTG_ID_MASK, |
| 468 | IOMUXC_GPR1_OTG_ID_GPIO1); |
| 469 | |
| 470 | /* address of linux boot parameters */ |
| 471 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 472 | |
Tim Harvey | ba9f234 | 2019-02-04 13:10:52 -0800 | [diff] [blame] | 473 | /* read Gateworks EEPROM into global struct (used later) */ |
Tim Harvey | 4137785 | 2022-04-13 09:29:16 -0700 | [diff] [blame] | 474 | board_type = read_eeprom(&ventana_info); |
Tim Harvey | ba9f234 | 2019-02-04 13:10:52 -0800 | [diff] [blame] | 475 | |
Tim Harvey | 4137785 | 2022-04-13 09:29:16 -0700 | [diff] [blame] | 476 | setup_iomux_gpio(board_type); |
| 477 | |
| 478 | /* show GSC details */ |
| 479 | run_command("gsc", 0); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Tim Harvey | 948202c | 2021-03-01 14:33:32 -0800 | [diff] [blame] | 484 | int board_fit_config_name_match(const char *name) |
| 485 | { |
| 486 | static char init; |
| 487 | const char *dtb; |
| 488 | char buf[32]; |
| 489 | int i = 0; |
| 490 | |
| 491 | do { |
| 492 | dtb = gsc_get_dtb_name(i++, buf, sizeof(buf)); |
| 493 | if (dtb && !strcmp(dtb, name)) { |
| 494 | if (!init++) |
| 495 | printf("DTB: %s\n", name); |
| 496 | return 0; |
| 497 | } |
| 498 | } while (dtb); |
| 499 | |
| 500 | return -1; |
| 501 | } |
| 502 | |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 503 | #if defined(CONFIG_DISPLAY_BOARDINFO_LATE) |
| 504 | /* |
| 505 | * called during late init (after relocation and after board_init()) |
| 506 | * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and |
| 507 | * EEPROM read. |
| 508 | */ |
| 509 | int checkboard(void) |
| 510 | { |
| 511 | struct ventana_board_info *info = &ventana_info; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 512 | const char *p; |
| 513 | int quiet; /* Quiet or minimal output mode */ |
| 514 | |
| 515 | quiet = 0; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 516 | p = env_get("quiet"); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 517 | if (p) |
| 518 | quiet = simple_strtol(p, NULL, 10); |
| 519 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 520 | env_set("quiet", "0"); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 521 | |
| 522 | puts("\nGateworks Corporation Copyright 2014\n"); |
| 523 | if (info->model[0]) { |
| 524 | printf("Model: %s\n", info->model); |
| 525 | printf("MFGDate: %02x-%02x-%02x%02x\n", |
| 526 | info->mfgdate[0], info->mfgdate[1], |
| 527 | info->mfgdate[2], info->mfgdate[3]); |
| 528 | printf("Serial:%d\n", info->serial); |
| 529 | } else { |
| 530 | puts("Invalid EEPROM - board will not function fully\n"); |
| 531 | } |
| 532 | if (quiet) |
| 533 | return 0; |
| 534 | |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | #endif |
| 538 | |
| 539 | #ifdef CONFIG_CMD_BMODE |
| 540 | /* |
| 541 | * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4 |
| 542 | * see Table 8-11 and Table 5-9 |
| 543 | * BOOT_CFG1[7] = 1 (boot from NAND) |
| 544 | * BOOT_CFG1[5] = 0 - raw NAND |
| 545 | * BOOT_CFG1[4] = 0 - default pad settings |
| 546 | * BOOT_CFG1[3:2] = 00 - devices = 1 |
| 547 | * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3 |
| 548 | * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2 |
| 549 | * BOOT_CFG2[2:1] = 01 - Pages In Block = 64 |
| 550 | * BOOT_CFG2[0] = 0 - Reset time 12ms |
| 551 | */ |
| 552 | static const struct boot_mode board_boot_modes[] = { |
| 553 | /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */ |
| 554 | { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) }, |
Tim Harvey | 659441b | 2017-03-17 07:31:02 -0700 | [diff] [blame] | 555 | { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */ |
Tim Harvey | a2d24c9 | 2019-02-04 13:10:50 -0800 | [diff] [blame] | 556 | { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */ |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 557 | { NULL, 0 }, |
| 558 | }; |
| 559 | #endif |
| 560 | |
Tim Harvey | 55c33cb | 2022-03-07 16:24:02 -0800 | [diff] [blame] | 561 | /* setup GPIO pinmux and default configuration per baseboard and env */ |
| 562 | void setup_board_gpio(int board, struct ventana_board_info *info) |
| 563 | { |
| 564 | const char *s; |
| 565 | char arg[10]; |
| 566 | size_t len; |
| 567 | int i; |
| 568 | int quiet = simple_strtol(env_get("quiet"), NULL, 10); |
| 569 | |
| 570 | if (board >= GW_UNKNOWN) |
| 571 | return; |
| 572 | |
| 573 | /* RS232_EN# */ |
| 574 | if (gpio_cfg[board].rs232_en) { |
| 575 | gpio_direction_output(gpio_cfg[board].rs232_en, |
| 576 | (hwconfig("rs232")) ? 0 : 1); |
| 577 | } |
| 578 | |
| 579 | /* MSATA Enable */ |
| 580 | if (gpio_cfg[board].msata_en && is_cpu_type(MXC_CPU_MX6Q)) { |
| 581 | gpio_direction_output(GP_MSATA_SEL, |
| 582 | (hwconfig("msata")) ? 1 : 0); |
| 583 | } |
| 584 | |
| 585 | /* USBOTG Select (PCISKT or FrontPanel) */ |
| 586 | if (gpio_cfg[board].usb_sel) { |
| 587 | gpio_direction_output(gpio_cfg[board].usb_sel, |
| 588 | (hwconfig("usb_pcisel")) ? 1 : 0); |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * Configure DIO pinmux/padctl registers |
| 593 | * see IMX6DQRM/IMX6SDLRM IOMUXC_SW_PAD_CTL_PAD_* register definitions |
| 594 | */ |
| 595 | for (i = 0; i < gpio_cfg[board].dio_num; i++) { |
| 596 | struct dio_cfg *cfg = &gpio_cfg[board].dio_cfg[i]; |
| 597 | iomux_v3_cfg_t ctrl = DIO_PAD_CFG; |
| 598 | unsigned int cputype = is_cpu_type(MXC_CPU_MX6Q) ? 0 : 1; |
| 599 | |
| 600 | if (!cfg->gpio_padmux[0] && !cfg->gpio_padmux[1]) |
| 601 | continue; |
| 602 | sprintf(arg, "dio%d", i); |
| 603 | if (!hwconfig(arg)) |
| 604 | continue; |
| 605 | s = hwconfig_subarg(arg, "padctrl", &len); |
| 606 | if (s) { |
| 607 | ctrl = MUX_PAD_CTRL(hextoul(s, NULL) |
| 608 | & 0x1ffff) | MUX_MODE_SION; |
| 609 | } |
| 610 | if (hwconfig_subarg_cmp(arg, "mode", "gpio")) { |
| 611 | if (!quiet) { |
| 612 | printf("DIO%d: GPIO%d_IO%02d (gpio-%d)\n", i, |
| 613 | (cfg->gpio_param / 32) + 1, |
| 614 | cfg->gpio_param % 32, |
| 615 | cfg->gpio_param); |
| 616 | } |
| 617 | imx_iomux_v3_setup_pad(cfg->gpio_padmux[cputype] | |
| 618 | ctrl); |
| 619 | gpio_requestf(cfg->gpio_param, "dio%d", i); |
| 620 | gpio_direction_input(cfg->gpio_param); |
Heinrich Schuchardt | 151462b | 2022-10-12 18:59:27 +0200 | [diff] [blame] | 621 | } else if (hwconfig_subarg_cmp(arg, "mode", "pwm")) { |
Tim Harvey | 55c33cb | 2022-03-07 16:24:02 -0800 | [diff] [blame] | 622 | if (!cfg->pwm_param) { |
| 623 | printf("DIO%d: Error: pwm config invalid\n", |
| 624 | i); |
| 625 | continue; |
| 626 | } |
| 627 | if (!quiet) |
| 628 | printf("DIO%d: pwm%d\n", i, cfg->pwm_param); |
| 629 | imx_iomux_v3_setup_pad(cfg->pwm_padmux[cputype] | |
| 630 | MUX_PAD_CTRL(ctrl)); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (!quiet) { |
| 635 | if (gpio_cfg[board].msata_en && is_cpu_type(MXC_CPU_MX6Q)) { |
| 636 | printf("MSATA: %s\n", (hwconfig("msata") ? |
| 637 | "enabled" : "disabled")); |
| 638 | } |
| 639 | if (gpio_cfg[board].rs232_en) { |
| 640 | printf("RS232: %s\n", (hwconfig("rs232")) ? |
| 641 | "enabled" : "disabled"); |
| 642 | } |
| 643 | } |
| 644 | } |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 645 | /* late init */ |
| 646 | int misc_init_r(void) |
| 647 | { |
| 648 | struct ventana_board_info *info = &ventana_info; |
Tim Harvey | 71dbb2c | 2016-07-15 07:14:25 -0700 | [diff] [blame] | 649 | char buf[256]; |
| 650 | int i; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 651 | |
| 652 | /* set env vars based on EEPROM data */ |
| 653 | if (ventana_info.model[0]) { |
| 654 | char str[16], fdt[36]; |
| 655 | char *p; |
| 656 | const char *cputype = ""; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * FDT name will be prefixed with CPU type. Three versions |
| 660 | * will be created each increasingly generic and bootloader |
| 661 | * env scripts will try loading each from most specific to |
| 662 | * least. |
| 663 | */ |
Tim Harvey | bfa2dae | 2014-06-02 16:13:27 -0700 | [diff] [blame] | 664 | if (is_cpu_type(MXC_CPU_MX6Q) || |
| 665 | is_cpu_type(MXC_CPU_MX6D)) |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 666 | cputype = "imx6q"; |
Tim Harvey | bfa2dae | 2014-06-02 16:13:27 -0700 | [diff] [blame] | 667 | else if (is_cpu_type(MXC_CPU_MX6DL) || |
| 668 | is_cpu_type(MXC_CPU_MX6SOLO)) |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 669 | cputype = "imx6dl"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 670 | env_set("soctype", cputype); |
Tim Harvey | 06d8743 | 2014-08-07 22:35:41 -0700 | [diff] [blame] | 671 | if (8 << (ventana_info.nand_flash_size-1) >= 2048) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 672 | env_set("flash_layout", "large"); |
Tim Harvey | 06d8743 | 2014-08-07 22:35:41 -0700 | [diff] [blame] | 673 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 674 | env_set("flash_layout", "normal"); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 675 | memset(str, 0, sizeof(str)); |
| 676 | for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++) |
| 677 | str[i] = tolower(info->model[i]); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 678 | env_set("model", str); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 679 | if (!env_get("fdt_file")) { |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 680 | sprintf(fdt, "%s-%s.dtb", cputype, str); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 681 | env_set("fdt_file", fdt); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 682 | } |
| 683 | p = strchr(str, '-'); |
| 684 | if (p) { |
| 685 | *p++ = 0; |
| 686 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 687 | env_set("model_base", str); |
Tim Harvey | f6db79a | 2015-05-26 11:04:56 -0700 | [diff] [blame] | 688 | sprintf(fdt, "%s-%s.dtb", cputype, str); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 689 | env_set("fdt_file1", fdt); |
Tim Harvey | 892068c | 2016-05-24 11:03:58 -0700 | [diff] [blame] | 690 | if (board_type != GW551x && |
| 691 | board_type != GW552x && |
Tim Harvey | 659441b | 2017-03-17 07:31:02 -0700 | [diff] [blame] | 692 | board_type != GW553x && |
| 693 | board_type != GW560x) |
Tim Harvey | 5058183 | 2014-08-20 23:35:14 -0700 | [diff] [blame] | 694 | str[4] = 'x'; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 695 | str[5] = 'x'; |
| 696 | str[6] = 0; |
Tim Harvey | f6db79a | 2015-05-26 11:04:56 -0700 | [diff] [blame] | 697 | sprintf(fdt, "%s-%s.dtb", cputype, str); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 698 | env_set("fdt_file2", fdt); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /* initialize env from EEPROM */ |
| 702 | if (test_bit(EECONFIG_ETH0, info->config) && |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 703 | !env_get("ethaddr")) { |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 704 | eth_env_set_enetaddr("ethaddr", info->mac0); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 705 | } |
| 706 | if (test_bit(EECONFIG_ETH1, info->config) && |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 707 | !env_get("eth1addr")) { |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 708 | eth_env_set_enetaddr("eth1addr", info->mac1); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* board serial-number */ |
| 712 | sprintf(str, "%6d", info->serial); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 713 | env_set("serial#", str); |
Tim Harvey | 2777082 | 2015-04-08 12:54:51 -0700 | [diff] [blame] | 714 | |
| 715 | /* memory MB */ |
| 716 | sprintf(str, "%d", (int) (gd->ram_size >> 20)); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 717 | env_set("mem_mb", str); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 718 | } |
| 719 | |
Tim Harvey | 71dbb2c | 2016-07-15 07:14:25 -0700 | [diff] [blame] | 720 | /* Set a non-initialized hwconfig based on board configuration */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 721 | if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) { |
Tim Harvey | fd6f239 | 2017-03-13 08:51:06 -0700 | [diff] [blame] | 722 | buf[0] = 0; |
Tim Harvey | 71dbb2c | 2016-07-15 07:14:25 -0700 | [diff] [blame] | 723 | if (gpio_cfg[board_type].rs232_en) |
| 724 | strcat(buf, "rs232;"); |
| 725 | for (i = 0; i < gpio_cfg[board_type].dio_num; i++) { |
| 726 | char buf1[32]; |
| 727 | sprintf(buf1, "dio%d:mode=gpio;", i); |
| 728 | if (strlen(buf) + strlen(buf1) < sizeof(buf)) |
| 729 | strcat(buf, buf1); |
| 730 | } |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 731 | env_set("hwconfig", buf); |
Tim Harvey | 71dbb2c | 2016-07-15 07:14:25 -0700 | [diff] [blame] | 732 | } |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 733 | |
Tim Harvey | 0cee224 | 2015-05-08 18:28:35 -0700 | [diff] [blame] | 734 | /* setup baseboard specific GPIO based on board and env */ |
| 735 | setup_board_gpio(board_type, info); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 736 | |
| 737 | #ifdef CONFIG_CMD_BMODE |
| 738 | add_board_boot_modes(board_boot_modes); |
| 739 | #endif |
| 740 | |
Tim Harvey | 40feabb | 2015-05-08 18:28:36 -0700 | [diff] [blame] | 741 | /* disable boot watchdog */ |
| 742 | gsc_boot_wd_disable(); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 747 | #ifdef CONFIG_OF_BOARD_SETUP |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 748 | |
Tim Harvey | cf20e55 | 2015-04-08 12:55:01 -0700 | [diff] [blame] | 749 | static int ft_sethdmiinfmt(void *blob, char *mode) |
| 750 | { |
| 751 | int off; |
| 752 | |
| 753 | if (!mode) |
| 754 | return -EINVAL; |
| 755 | |
| 756 | off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x"); |
| 757 | if (off < 0) |
| 758 | return off; |
| 759 | |
| 760 | if (0 == strcasecmp(mode, "yuv422bt656")) { |
| 761 | u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00, |
| 762 | 0x00, 0x00, 0x00 }; |
| 763 | mode = "422_ccir"; |
| 764 | fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1); |
| 765 | fdt_setprop_u32(blob, off, "vidout_trc", 1); |
| 766 | fdt_setprop_u32(blob, off, "vidout_blc", 1); |
| 767 | fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg)); |
| 768 | printf(" set HDMI input mode to %s\n", mode); |
| 769 | } else if (0 == strcasecmp(mode, "yuv422smp")) { |
| 770 | u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00, |
| 771 | 0x82, 0x81, 0x00 }; |
| 772 | mode = "422_smp"; |
| 773 | fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1); |
| 774 | fdt_setprop_u32(blob, off, "vidout_trc", 0); |
| 775 | fdt_setprop_u32(blob, off, "vidout_blc", 0); |
| 776 | fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg)); |
| 777 | printf(" set HDMI input mode to %s\n", mode); |
| 778 | } else { |
| 779 | return -EINVAL; |
| 780 | } |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 785 | #if defined(CONFIG_CMD_PCI) |
| 786 | #define PCI_ID(x) ( \ |
| 787 | (PCI_BUS(x->devfn)<<16)| \ |
| 788 | (PCI_DEV(x->devfn)<<11)| \ |
| 789 | (PCI_FUNC(x->devfn)<<8) \ |
| 790 | ) |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 791 | int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev) |
| 792 | { |
| 793 | uint32_t reg[5]; |
| 794 | char node[32]; |
| 795 | int np; |
| 796 | |
| 797 | sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn), |
| 798 | PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn)); |
| 799 | |
| 800 | np = fdt_subnode_offset(blob, par, node); |
| 801 | if (np >= 0) |
| 802 | return np; |
| 803 | np = fdt_add_subnode(blob, par, node); |
| 804 | if (np < 0) { |
| 805 | printf(" %s failed: no space\n", __func__); |
| 806 | return np; |
| 807 | } |
| 808 | |
| 809 | memset(reg, 0, sizeof(reg)); |
| 810 | reg[0] = cpu_to_fdt32(PCI_ID(dev)); |
| 811 | fdt_setprop(blob, np, "reg", reg, sizeof(reg)); |
| 812 | |
| 813 | return np; |
| 814 | } |
| 815 | |
| 816 | /* build a path of nested PCI devs for all bridges passed through */ |
| 817 | int fdt_add_pci_path(void *blob, struct pci_dev *dev) |
| 818 | { |
| 819 | struct pci_dev *bridges[MAX_PCI_DEVS]; |
| 820 | int k, np; |
| 821 | |
| 822 | /* build list of parents */ |
Tim Harvey | 984aa0d | 2019-02-04 13:11:00 -0800 | [diff] [blame] | 823 | np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie"); |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 824 | if (np < 0) |
| 825 | return np; |
| 826 | |
| 827 | k = 0; |
| 828 | while (dev) { |
| 829 | bridges[k++] = dev; |
| 830 | dev = dev->ppar; |
| 831 | }; |
| 832 | |
| 833 | /* now add them the to DT in reverse order */ |
| 834 | while (k--) { |
| 835 | np = fdt_add_pci_node(blob, np, bridges[k]); |
| 836 | if (np < 0) |
| 837 | break; |
| 838 | } |
| 839 | |
| 840 | return np; |
| 841 | } |
| 842 | |
| 843 | /* |
| 844 | * The GW16082 has a hardware errata errata such that it's |
| 845 | * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because |
| 846 | * of this normal PCI interrupt swizzling will not work so we will |
| 847 | * provide an irq-map via device-tree. |
| 848 | */ |
| 849 | int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev) |
| 850 | { |
| 851 | int len; |
| 852 | int host; |
| 853 | uint32_t imap_new[8*4*4]; |
| 854 | const uint32_t *imap; |
| 855 | uint32_t irq[4]; |
| 856 | uint32_t reg[4]; |
| 857 | int i; |
| 858 | |
| 859 | /* build irq-map based on host controllers map */ |
Tim Harvey | 984aa0d | 2019-02-04 13:11:00 -0800 | [diff] [blame] | 860 | host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie"); |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 861 | if (host < 0) { |
| 862 | printf(" %s failed: missing host\n", __func__); |
| 863 | return host; |
| 864 | } |
| 865 | |
| 866 | /* use interrupt data from root complex's node */ |
| 867 | imap = fdt_getprop(blob, host, "interrupt-map", &len); |
| 868 | if (!imap || len != 128) { |
| 869 | printf(" %s failed: invalid interrupt-map\n", |
| 870 | __func__); |
| 871 | return -FDT_ERR_NOTFOUND; |
| 872 | } |
| 873 | |
| 874 | /* obtain irq's of host controller in pin order */ |
| 875 | for (i = 0; i < 4; i++) |
| 876 | irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6]; |
| 877 | |
| 878 | /* |
| 879 | * determine number of swizzles necessary: |
| 880 | * For each bridge we pass through we need to swizzle |
| 881 | * the number of the slot we are on. |
| 882 | */ |
| 883 | struct pci_dev *d; |
| 884 | int b; |
| 885 | b = 0; |
| 886 | d = dev->ppar; |
| 887 | while(d && d->ppar) { |
| 888 | b += PCI_DEV(d->devfn); |
| 889 | d = d->ppar; |
| 890 | } |
| 891 | |
| 892 | /* create new irq mappings for slots12-15 |
| 893 | * <skt> <idsel> <slot> <skt-inta> <skt-intb> |
| 894 | * J3 AD28 12 INTD INTA |
| 895 | * J4 AD29 13 INTC INTD |
| 896 | * J5 AD30 14 INTB INTC |
| 897 | * J2 AD31 15 INTA INTB |
| 898 | */ |
| 899 | for (i = 0; i < 4; i++) { |
| 900 | /* addr matches bus:dev:func */ |
| 901 | u32 addr = dev->busno << 16 | (12+i) << 11; |
| 902 | |
| 903 | /* default cells from root complex */ |
| 904 | memcpy(&imap_new[i*32], imap, 128); |
| 905 | /* first cell is PCI device address (BDF) */ |
| 906 | imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr); |
| 907 | imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr); |
| 908 | imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr); |
| 909 | imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr); |
| 910 | /* third cell is pin */ |
| 911 | imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1); |
| 912 | imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2); |
| 913 | imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3); |
| 914 | imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4); |
| 915 | /* sixth cell is relative interrupt */ |
| 916 | imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4]; |
| 917 | imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4]; |
| 918 | imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4]; |
| 919 | imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4]; |
| 920 | } |
| 921 | fdt_setprop(blob, np, "interrupt-map", imap_new, |
| 922 | sizeof(imap_new)); |
| 923 | reg[0] = cpu_to_fdt32(0xfff00); |
| 924 | reg[1] = 0; |
| 925 | reg[2] = 0; |
| 926 | reg[3] = cpu_to_fdt32(0x7); |
| 927 | fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg)); |
| 928 | fdt_setprop_cell(blob, np, "#interrupt-cells", 1); |
| 929 | fdt_setprop_string(blob, np, "device_type", "pci"); |
| 930 | fdt_setprop_cell(blob, np, "#address-cells", 3); |
| 931 | fdt_setprop_cell(blob, np, "#size-cells", 2); |
| 932 | printf(" Added custom interrupt-map for GW16082\n"); |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
Tim Harvey | 77b82a1 | 2016-06-17 06:10:42 -0700 | [diff] [blame] | 937 | /* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */ |
| 938 | int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev) |
| 939 | { |
| 940 | char *tmp, *end; |
| 941 | char mac[16]; |
| 942 | unsigned char mac_addr[6]; |
| 943 | int j; |
| 944 | |
| 945 | sprintf(mac, "eth1addr"); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 946 | tmp = env_get(mac); |
Tim Harvey | 77b82a1 | 2016-06-17 06:10:42 -0700 | [diff] [blame] | 947 | if (tmp) { |
| 948 | for (j = 0; j < 6; j++) { |
| 949 | mac_addr[j] = tmp ? |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 950 | hextoul(tmp, &end) : 0; |
Tim Harvey | 77b82a1 | 2016-06-17 06:10:42 -0700 | [diff] [blame] | 951 | if (tmp) |
| 952 | tmp = (*end) ? end+1 : end; |
| 953 | } |
| 954 | fdt_setprop(blob, np, "local-mac-address", mac_addr, |
| 955 | sizeof(mac_addr)); |
| 956 | printf(" Added mac addr for eth1\n"); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | return -1; |
| 961 | } |
| 962 | |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 963 | /* |
| 964 | * PCI DT nodes must be nested therefore if we need to apply a DT fixup |
| 965 | * we will walk the PCI bus and add bridge nodes up to the device receiving |
| 966 | * the fixup. |
| 967 | */ |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 968 | void ft_board_pci_fixup(void *blob, struct bd_info *bd) |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 969 | { |
| 970 | int i, np; |
| 971 | struct pci_dev *dev; |
| 972 | |
| 973 | for (i = 0; i < pci_devno; i++) { |
| 974 | dev = &pci_devs[i]; |
| 975 | |
| 976 | /* |
| 977 | * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and |
| 978 | * an EEPROM at i2c1-0x50. |
| 979 | */ |
| 980 | if ((dev->vendor == PCI_VENDOR_ID_TI) && |
| 981 | (dev->device == 0x8240) && |
Tim Harvey | 895aace | 2022-03-07 16:24:00 -0800 | [diff] [blame] | 982 | i2c_get_dev(1, 0x50)) |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 983 | { |
| 984 | np = fdt_add_pci_path(blob, dev); |
| 985 | if (np > 0) |
| 986 | fdt_fixup_gw16082(blob, np, dev); |
| 987 | } |
Tim Harvey | 77b82a1 | 2016-06-17 06:10:42 -0700 | [diff] [blame] | 988 | |
| 989 | /* ethernet1 mac address */ |
| 990 | else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) && |
| 991 | (dev->device == 0x4380)) |
| 992 | { |
| 993 | np = fdt_add_pci_path(blob, dev); |
| 994 | if (np > 0) |
| 995 | fdt_fixup_sky2(blob, np, dev); |
| 996 | } |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | #endif /* if defined(CONFIG_CMD_PCI) */ |
Tim Harvey | 147b576 | 2016-05-24 11:03:59 -0700 | [diff] [blame] | 1000 | |
Tim Harvey | 4287423 | 2022-03-07 16:24:03 -0800 | [diff] [blame] | 1001 | #define WDOG1_ADDR 0x20bc000 |
| 1002 | #define WDOG2_ADDR 0x20c0000 |
| 1003 | #define GPIO3_ADDR 0x20a4000 |
| 1004 | #define USDHC3_ADDR 0x2198000 |
| 1005 | static void ft_board_wdog_fixup(void *blob, phys_addr_t addr) |
| 1006 | { |
| 1007 | int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr); |
| 1008 | |
| 1009 | if (off) { |
| 1010 | fdt_delprop(blob, off, "ext-reset-output"); |
| 1011 | fdt_delprop(blob, off, "fsl,ext-reset-output"); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void ft_early_fixup(void *blob, int board_type) |
| 1016 | { |
| 1017 | struct ventana_board_info *info = &ventana_info; |
| 1018 | char rev = 0; |
| 1019 | int i; |
| 1020 | |
| 1021 | /* determine board revision */ |
| 1022 | for (i = sizeof(ventana_info.model) - 1; i > 0; i--) { |
| 1023 | if (ventana_info.model[i] >= 'A') { |
| 1024 | rev = ventana_info.model[i]; |
| 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | /* |
| 1030 | * Board model specific fixups |
| 1031 | */ |
| 1032 | switch (board_type) { |
| 1033 | case GW51xx: |
| 1034 | /* |
| 1035 | * disable wdog node for GW51xx-A/B to work around |
| 1036 | * errata causing wdog timer to be unreliable. |
| 1037 | */ |
| 1038 | if (rev >= 'A' && rev < 'C') { |
| 1039 | i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", |
| 1040 | WDOG1_ADDR); |
| 1041 | if (i) |
| 1042 | fdt_status_disabled(blob, i); |
| 1043 | } |
| 1044 | |
| 1045 | /* GW51xx-E adds WDOG1_B external reset */ |
| 1046 | if (rev < 'E') |
| 1047 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1048 | break; |
| 1049 | |
| 1050 | case GW52xx: |
| 1051 | /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */ |
| 1052 | if (info->model[4] == '2') { |
| 1053 | u32 handle = 0; |
| 1054 | u32 *range = NULL; |
| 1055 | |
| 1056 | i = fdt_node_offset_by_compatible(blob, -1, |
| 1057 | "fsl,imx6q-pcie"); |
| 1058 | if (i) |
| 1059 | range = (u32 *)fdt_getprop(blob, i, |
| 1060 | "reset-gpio", NULL); |
| 1061 | |
| 1062 | if (range) { |
| 1063 | i = fdt_node_offset_by_compat_reg(blob, |
| 1064 | "fsl,imx6q-gpio", GPIO3_ADDR); |
| 1065 | if (i) |
| 1066 | handle = fdt_get_phandle(blob, i); |
| 1067 | if (handle) { |
| 1068 | range[0] = cpu_to_fdt32(handle); |
| 1069 | range[1] = cpu_to_fdt32(23); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | /* these have broken usd_vsel */ |
| 1074 | if (strstr((const char *)info->model, "SP318-B") || |
| 1075 | strstr((const char *)info->model, "SP331-B")) |
| 1076 | gpio_cfg[board_type].usd_vsel = 0; |
| 1077 | |
| 1078 | /* GW522x-B adds WDOG1_B external reset */ |
| 1079 | if (rev < 'B') |
| 1080 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1081 | } |
| 1082 | |
| 1083 | /* GW520x-E adds WDOG1_B external reset */ |
| 1084 | else if (info->model[4] == '0' && rev < 'E') |
| 1085 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1086 | break; |
| 1087 | |
| 1088 | case GW53xx: |
| 1089 | /* GW53xx-E adds WDOG1_B external reset */ |
| 1090 | if (rev < 'E') |
| 1091 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1092 | |
| 1093 | /* GW53xx-G has an adv7280 instead of an adv7180 */ |
| 1094 | else if (rev > 'F') { |
| 1095 | i = fdt_node_offset_by_compatible(blob, -1, "adi,adv7180"); |
| 1096 | if (i) { |
| 1097 | fdt_setprop_string(blob, i, "compatible", "adi,adv7280"); |
| 1098 | fdt_setprop_empty(blob, i, "adv,force-bt656-4"); |
| 1099 | } |
| 1100 | } |
| 1101 | break; |
| 1102 | |
| 1103 | case GW54xx: |
| 1104 | /* |
| 1105 | * disable serial2 node for GW54xx for compatibility with older |
| 1106 | * 3.10.x kernel that improperly had this node enabled in the DT |
| 1107 | */ |
| 1108 | fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED); |
| 1109 | |
| 1110 | /* GW54xx-E adds WDOG2_B external reset */ |
| 1111 | if (rev < 'E') |
| 1112 | ft_board_wdog_fixup(blob, WDOG2_ADDR); |
| 1113 | |
| 1114 | /* GW54xx-G has an adv7280 instead of an adv7180 */ |
| 1115 | else if (rev > 'F') { |
| 1116 | i = fdt_node_offset_by_compatible(blob, -1, "adi,adv7180"); |
| 1117 | if (i) { |
| 1118 | fdt_setprop_string(blob, i, "compatible", "adi,adv7280"); |
| 1119 | fdt_setprop_empty(blob, i, "adv,force-bt656-4"); |
| 1120 | } |
| 1121 | } |
| 1122 | break; |
| 1123 | |
| 1124 | case GW551x: |
| 1125 | /* GW551x-C adds WDOG1_B external reset */ |
| 1126 | if (rev < 'C') |
| 1127 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1128 | break; |
| 1129 | case GW5901: |
| 1130 | case GW5902: |
| 1131 | /* GW5901/GW5901 revB adds WDOG1_B as an external reset */ |
| 1132 | if (rev < 'B') |
| 1133 | ft_board_wdog_fixup(blob, WDOG1_ADDR); |
| 1134 | break; |
| 1135 | } |
| 1136 | |
| 1137 | /* remove no-1-8-v if UHS-I support is present */ |
| 1138 | if (gpio_cfg[board_type].usd_vsel) { |
| 1139 | debug("Enabling UHS-I support\n"); |
| 1140 | i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc", |
| 1141 | USDHC3_ADDR); |
| 1142 | if (i) |
| 1143 | fdt_delprop(blob, i, "no-1-8-v"); |
| 1144 | } |
| 1145 | } |
| 1146 | |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1147 | /* |
| 1148 | * called prior to booting kernel or by 'fdt boardsetup' command |
| 1149 | * |
| 1150 | * unless 'fdt_noauto' env var is set we will update the following in the DTB: |
| 1151 | * - mtd partitions based on mtdparts/mtdids env |
| 1152 | * - system-serial (board serial num from EEPROM) |
| 1153 | * - board (full model from EEPROM) |
| 1154 | * - peripherals removed from DTB if not loaded on board (per EEPROM config) |
| 1155 | */ |
Tim Harvey | 984aa0d | 2019-02-04 13:11:00 -0800 | [diff] [blame] | 1156 | #define PWM0_ADDR 0x2080000 |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1157 | int ft_board_setup(void *blob, struct bd_info *bd) |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1158 | { |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1159 | struct ventana_board_info *info = &ventana_info; |
Tim Harvey | 0da2c52 | 2014-08-07 22:35:45 -0700 | [diff] [blame] | 1160 | struct ventana_eeprom_config *cfg; |
Tim Harvey | 8e50217 | 2021-07-24 10:40:33 -0700 | [diff] [blame] | 1161 | static const struct node_info nand_nodes[] = { |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1162 | { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */ |
| 1163 | { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */ |
| 1164 | }; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1165 | const char *model = env_get("model"); |
| 1166 | const char *display = env_get("display"); |
Tim Harvey | 16e0eae | 2015-04-08 12:54:44 -0700 | [diff] [blame] | 1167 | int i; |
| 1168 | char rev = 0; |
| 1169 | |
| 1170 | /* determine board revision */ |
| 1171 | for (i = sizeof(ventana_info.model) - 1; i > 0; i--) { |
| 1172 | if (ventana_info.model[i] >= 'A') { |
| 1173 | rev = ventana_info.model[i]; |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1177 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1178 | if (env_get("fdt_noauto")) { |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1179 | puts(" Skiping ft_board_setup (fdt_noauto defined)\n"); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 1180 | return 0; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
Tim Harvey | 8e50217 | 2021-07-24 10:40:33 -0700 | [diff] [blame] | 1183 | /* Update MTD partition nodes using info from mtdparts env var */ |
| 1184 | puts(" Updating MTD partitions...\n"); |
| 1185 | fdt_fixup_mtdparts(blob, nand_nodes, ARRAY_SIZE(nand_nodes)); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1186 | |
Tim Harvey | e4af5d3 | 2015-04-08 12:54:58 -0700 | [diff] [blame] | 1187 | /* Update display timings from display env var */ |
| 1188 | if (display) { |
| 1189 | if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"), |
| 1190 | display) >= 0) |
| 1191 | printf(" Set display timings for %s...\n", display); |
| 1192 | } |
| 1193 | |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1194 | printf(" Adjusting FDT per EEPROM for %s...\n", model); |
| 1195 | |
| 1196 | /* board serial number */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1197 | fdt_setprop(blob, 0, "system-serial", env_get("serial#"), |
| 1198 | strlen(env_get("serial#")) + 1); |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1199 | |
| 1200 | /* board (model contains model from device-tree) */ |
| 1201 | fdt_setprop(blob, 0, "board", info->model, |
| 1202 | strlen((const char *)info->model) + 1); |
| 1203 | |
Tim Harvey | cf20e55 | 2015-04-08 12:55:01 -0700 | [diff] [blame] | 1204 | /* set desired digital video capture format */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1205 | ft_sethdmiinfmt(blob, env_get("hdmiinfmt")); |
Tim Harvey | cf20e55 | 2015-04-08 12:55:01 -0700 | [diff] [blame] | 1206 | |
Tim Harvey | 28db4e4 | 2021-07-24 10:40:32 -0700 | [diff] [blame] | 1207 | /* early board/revision ft fixups */ |
| 1208 | ft_early_fixup(blob, board_type); |
Tim Harvey | 6944ccf | 2015-04-08 12:54:53 -0700 | [diff] [blame] | 1209 | |
Tim Harvey | 8d2d8df | 2016-05-24 11:03:55 -0700 | [diff] [blame] | 1210 | /* Configure DIO */ |
Tim Harvey | 41595b5 | 2016-07-15 07:14:23 -0700 | [diff] [blame] | 1211 | for (i = 0; i < gpio_cfg[board_type].dio_num; i++) { |
Tim Harvey | 8d2d8df | 2016-05-24 11:03:55 -0700 | [diff] [blame] | 1212 | struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i]; |
| 1213 | char arg[10]; |
| 1214 | |
| 1215 | sprintf(arg, "dio%d", i); |
| 1216 | if (!hwconfig(arg)) |
| 1217 | continue; |
| 1218 | if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param) |
| 1219 | { |
Tim Harvey | 984aa0d | 2019-02-04 13:11:00 -0800 | [diff] [blame] | 1220 | phys_addr_t addr; |
| 1221 | int off; |
| 1222 | |
Tim Harvey | 8d2d8df | 2016-05-24 11:03:55 -0700 | [diff] [blame] | 1223 | printf(" Enabling pwm%d for DIO%d\n", |
| 1224 | cfg->pwm_param, i); |
Tim Harvey | 984aa0d | 2019-02-04 13:11:00 -0800 | [diff] [blame] | 1225 | addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1)); |
| 1226 | off = fdt_node_offset_by_compat_reg(blob, |
| 1227 | "fsl,imx6q-pwm", |
| 1228 | addr); |
| 1229 | if (off) |
| 1230 | fdt_status_okay(blob, off); |
Tim Harvey | 8d2d8df | 2016-05-24 11:03:55 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 1234 | #if defined(CONFIG_CMD_PCI) |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1235 | if (!env_get("nopcifixup")) |
Tim Harvey | bfb240a | 2016-06-17 06:10:41 -0700 | [diff] [blame] | 1236 | ft_board_pci_fixup(blob, bd); |
| 1237 | #endif |
| 1238 | |
Tim Harvey | 6944ccf | 2015-04-08 12:54:53 -0700 | [diff] [blame] | 1239 | /* |
Tim Harvey | 7ad148a | 2021-09-29 15:04:18 -0700 | [diff] [blame] | 1240 | * remove reset gpio control as we configure the PHY registers |
| 1241 | * for internal delay, LED config, and clock config in the bootloader |
| 1242 | */ |
| 1243 | i = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-fec"); |
| 1244 | if (i) |
| 1245 | fdt_delprop(blob, i, "phy-reset-gpios"); |
| 1246 | |
| 1247 | /* |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1248 | * Peripheral Config: |
| 1249 | * remove nodes by alias path if EEPROM config tells us the |
| 1250 | * peripheral is not loaded on the board. |
| 1251 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1252 | if (env_get("fdt_noconfig")) { |
Tim Harvey | 0da2c52 | 2014-08-07 22:35:45 -0700 | [diff] [blame] | 1253 | puts(" Skiping periperhal config (fdt_noconfig defined)\n"); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 1254 | return 0; |
Tim Harvey | 0da2c52 | 2014-08-07 22:35:45 -0700 | [diff] [blame] | 1255 | } |
| 1256 | cfg = econfig; |
| 1257 | while (cfg->name) { |
| 1258 | if (!test_bit(cfg->bit, info->config)) { |
| 1259 | fdt_del_node_and_alias(blob, cfg->dtalias ? |
| 1260 | cfg->dtalias : cfg->name); |
| 1261 | } |
| 1262 | cfg++; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1263 | } |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 1264 | |
| 1265 | return 0; |
Tim Harvey | 552c358 | 2014-03-06 07:46:30 -0800 | [diff] [blame] | 1266 | } |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 1267 | #endif /* CONFIG_OF_BOARD_SETUP */ |
Tim Harvey | 235c6f1 | 2022-09-28 14:00:35 -0700 | [diff] [blame] | 1268 | |
| 1269 | int board_mmc_get_env_dev(int devno) |
| 1270 | { |
| 1271 | return devno; |
| 1272 | } |