blob: 21a908c20dd52517b05feef58b1589d652f8eba9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tim Harvey552c3582014-03-06 07:46:30 -08002/*
3 * Copyright (C) 2013 Gateworks Corporation
4 *
5 * Author: Tim Harvey <tharvey@gateworks.com>
Tim Harvey552c3582014-03-06 07:46:30 -08006 */
7
Tim Harvey41377852022-04-13 09:29:16 -07008#include <command.h>
Tim Harvey41377852022-04-13 09:29:16 -07009#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 Harvey552c3582014-03-06 07:46:30 -080015#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070016#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080017#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070018#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080019#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/video.h>
Tim Harvey41377852022-04-13 09:29:16 -070022#include <jffs2/load_kernel.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070023#include <linux/ctype.h>
Simon Glassdbd79542020-05-10 11:40:11 -060024#include <linux/delay.h>
Tim Harvey552c3582014-03-06 07:46:30 -080025
Tim Harvey0cee2242015-05-08 18:28:35 -070026#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080027
28DECLARE_GLOBAL_DATA_PTR;
29
Tim Harvey552c3582014-03-06 07:46:30 -080030/* configure eth0 PHY board-specific LED behavior */
31int board_phy_config(struct phy_device *phydev)
32{
33 unsigned short val;
Tim Harveyb9d23522022-04-29 13:51:02 -070034 ofnode node;
Tim Harvey552c3582014-03-06 07:46:30 -080035
Tim Harveyb9d23522022-04-29 13:51:02 -070036 switch (phydev->phy_id) {
37 case 0x1410dd1:
Tim Harveyb25b7582021-06-11 12:46:26 -070038 puts("MV88E1510");
Tim Harvey552c3582014-03-06 07:46:30 -080039 /*
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 Harveyb9d23522022-04-29 13:51:02 -070050 break;
51 case 0x2000a231:
Tim Harveyb25b7582021-06-11 12:46:26 -070052 puts("TIDP83867 ");
Tim Harvey1662ad32021-06-11 12:46:25 -070053 /* 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 Harvey4533c902017-03-17 07:32:21 -070059 /* 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 Harveyb9d23522022-04-29 13:51:02 -070067 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 Harvey4533c902017-03-17 07:32:21 -070083 }
84
Tim Harvey781f6d82022-11-30 09:42:51 -080085 /* 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 Harvey63537792017-03-17 07:30:38 -070089
Tim Harvey781f6d82022-11-30 09:42:51 -080090 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 Harvey63537792017-03-17 07:30:38 -070094
Tim Harvey781f6d82022-11-30 09:42:51 -080095 /* 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 Harvey63537792017-03-17 07:30:38 -0700102
Tim Harvey781f6d82022-11-30 09:42:51 -0800103 if (phydev->drv->config)
104 phydev->drv->config(phydev);
Tim Harvey63537792017-03-17 07:30:38 -0700105
106 return 0;
107}
Tim Harvey552c3582014-03-06 07:46:30 -0800108
Tim Harveyfb64cc72014-04-25 15:39:07 -0700109#if defined(CONFIG_VIDEO_IPUV3)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700110static void enable_hdmi(struct display_info_t const *dev)
111{
112 imx_enable_hdmi_phy();
113}
114
Tim Harveyceb79f52021-09-29 15:04:21 -0700115static int detect_lvds(struct display_info_t const *dev)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700116{
Tim Harveyceb79f52021-09-29 15:04:21 -0700117 /* 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 Harvey895aace2022-03-07 16:24:00 -0800130 return (i2c_get_dev(dev->bus, dev->addr) ? 1 : 0);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700131}
132
133static void enable_lvds(struct display_info_t const *dev)
134{
Tim Harveyceb79f52021-09-29 15:04:21 -0700135 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harveyfb64cc72014-04-25 15:39:07 -0700136
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 Harveyceb79f52021-09-29 15:04:21 -0700142 /* 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 Harveyf1f41db2015-05-08 18:28:28 -0700162 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700163 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700164 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
165}
166
167struct 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 Harveyceb79f52021-09-29 15:04:21 -0700193 .detect = detect_lvds,
Tim Harveyfb64cc72014-04-25 15:39:07 -0700194 .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 Harveya20bd632015-04-08 12:54:57 -0700209} }, {
210 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800211 .bus = 2,
212 .addr = 0x38,
Tim Harveyceb79f52021-09-29 15:04:21 -0700213 .detect = detect_lvds,
Tim Harveya20bd632015-04-08 12:54:57 -0700214 .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 Harvey87a86452021-06-11 12:46:27 -0700231 /* DLC0700XDP21LF-C-1 */
Tim Harveyceb79f52021-09-29 15:04:21 -0700232 .bus = 2,
233 .addr = 0x38,
234 .detect = detect_lvds,
Tim Harvey87a86452021-06-11 12:46:27 -0700235 .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 Harveya20bd632015-04-08 12:54:57 -0700252 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800253 .bus = 2,
254 .addr = 0x14,
Tim Harveyceb79f52021-09-29 15:04:21 -0700255 .detect = detect_lvds,
Tim Harveya20bd632015-04-08 12:54:57 -0700256 .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 Harveyc34e59e2019-02-04 13:10:51 -0800272} }, {
273 .bus = 2,
274 .addr = 0x5d,
Tim Harveyceb79f52021-09-29 15:04:21 -0700275 .detect = detect_lvds,
Tim Harveyc34e59e2019-02-04 13:10:51 -0800276 .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 Harveyfb64cc72014-04-25 15:39:07 -0700295size_t display_count = ARRAY_SIZE(displays);
296
297static 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 Harveyfb64cc72014-04-25 15:39:07 -0700343}
344#endif /* CONFIG_VIDEO_IPUV3 */
345
Tim Harvey33791d52014-08-07 22:49:57 -0700346/*
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 Harveybfb240a2016-06-17 06:10:41 -0700351#define MAX_PCI_DEVS 32
352struct pci_dev {
353 pci_dev_t devfn;
Tim Harvey6ce10d52021-05-03 11:21:27 -0700354 struct udevice *dev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700355 unsigned short vendor;
356 unsigned short device;
357 unsigned short class;
358 unsigned short busno; /* subbordinate busno */
359 struct pci_dev *ppar;
360};
361struct pci_dev pci_devs[MAX_PCI_DEVS];
362int pci_devno;
363int pci_bridgeno;
364
Tim Harvey6ce10d52021-05-03 11:21:27 -0700365void board_pci_fixup_dev(struct udevice *bus, struct udevice *udev)
Tim Harvey33791d52014-08-07 22:49:57 -0700366{
Tim Harvey6ce10d52021-05-03 11:21:27 -0700367 struct pci_child_plat *pdata = dev_get_parent_plat(udev);
Tim Harveybfb240a2016-06-17 06:10:41 -0700368 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey6ce10d52021-05-03 11:21:27 -0700369 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 Harvey33791d52014-08-07 22:49:57 -0700374
375 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
376 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700377
378 /* store array of devs for later use in device-tree fixup */
Tim Harvey6ce10d52021-05-03 11:21:27 -0700379 pdev->dev = udev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700380 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 Harvey33791d52014-08-07 22:49:57 -0700403 if (vendor == PCI_VENDOR_ID_PLX &&
404 (device & 0xfff0) == 0x8600 &&
405 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
Tim Harvey6ce10d52021-05-03 11:21:27 -0700406 ulong val;
Tim Harvey33791d52014-08-07 22:49:57 -0700407 debug("configuring PLX 860X downstream PERST#\n");
Tim Harvey6ce10d52021-05-03 11:21:27 -0700408 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 Harvey33791d52014-08-07 22:49:57 -0700411
Tim Harvey6ce10d52021-05-03 11:21:27 -0700412 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 Harvey33791d52014-08-07 22:49:57 -0700415
416 mdelay(100);
417 }
418}
Tim Harvey552c3582014-03-06 07:46:30 -0800419
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 */
427void get_board_serial(struct tag_serialnr *serialnr)
428{
Simon Glass64b723f2017-08-03 12:22:12 -0600429 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800430
431 if (serial) {
432 serialnr->high = 0;
Simon Glassff9b9032021-07-24 09:03:30 -0600433 serialnr->low = dectoul(serial, NULL);
Tim Harvey552c3582014-03-06 07:46:30 -0800434 } 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
448int board_early_init_f(void)
449{
Tim Harveyfb64cc72014-04-25 15:39:07 -0700450#if defined(CONFIG_VIDEO_IPUV3)
451 setup_display();
452#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800453 return 0;
454}
455
456int dram_init(void)
457{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700458 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800459 return 0;
460}
461
462int board_init(void)
463{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300464 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800465
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 Harveyba9f2342019-02-04 13:10:52 -0800473 /* read Gateworks EEPROM into global struct (used later) */
Tim Harvey41377852022-04-13 09:29:16 -0700474 board_type = read_eeprom(&ventana_info);
Tim Harveyba9f2342019-02-04 13:10:52 -0800475
Tim Harvey41377852022-04-13 09:29:16 -0700476 setup_iomux_gpio(board_type);
477
478 /* show GSC details */
479 run_command("gsc", 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800480
481 return 0;
482}
483
Tim Harvey948202c2021-03-01 14:33:32 -0800484int 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 Harvey552c3582014-03-06 07:46:30 -0800503#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 */
509int checkboard(void)
510{
511 struct ventana_board_info *info = &ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -0800512 const char *p;
513 int quiet; /* Quiet or minimal output mode */
514
515 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600516 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800517 if (p)
518 quiet = simple_strtol(p, NULL, 10);
519 else
Simon Glass6a38e412017-08-03 12:22:09 -0600520 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800521
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 Harvey552c3582014-03-06 07:46:30 -0800535 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 */
552static 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 Harvey659441b2017-03-17 07:31:02 -0700555 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800556 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800557 { NULL, 0 },
558};
559#endif
560
Tim Harvey55c33cb2022-03-07 16:24:02 -0800561/* setup GPIO pinmux and default configuration per baseboard and env */
562void 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 Schuchardt151462b2022-10-12 18:59:27 +0200621 } else if (hwconfig_subarg_cmp(arg, "mode", "pwm")) {
Tim Harvey55c33cb2022-03-07 16:24:02 -0800622 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 Harvey552c3582014-03-06 07:46:30 -0800645/* late init */
646int misc_init_r(void)
647{
648 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700649 char buf[256];
650 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800651
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 Harvey552c3582014-03-06 07:46:30 -0800657
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 Harveybfa2dae2014-06-02 16:13:27 -0700664 if (is_cpu_type(MXC_CPU_MX6Q) ||
665 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800666 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700667 else if (is_cpu_type(MXC_CPU_MX6DL) ||
668 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800669 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600670 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700671 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600672 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700673 else
Simon Glass6a38e412017-08-03 12:22:09 -0600674 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800675 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 Glass6a38e412017-08-03 12:22:09 -0600678 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600679 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800680 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600681 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800682 }
683 p = strchr(str, '-');
684 if (p) {
685 *p++ = 0;
686
Simon Glass6a38e412017-08-03 12:22:09 -0600687 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700688 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600689 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700690 if (board_type != GW551x &&
691 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700692 board_type != GW553x &&
693 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700694 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800695 str[5] = 'x';
696 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700697 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600698 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800699 }
700
701 /* initialize env from EEPROM */
702 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600703 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600704 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800705 }
706 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600707 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600708 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800709 }
710
711 /* board serial-number */
712 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600713 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700714
715 /* memory MB */
716 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600717 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800718 }
719
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700720 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600721 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700722 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700723 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 Glass6a38e412017-08-03 12:22:09 -0600731 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700732 }
Tim Harvey552c3582014-03-06 07:46:30 -0800733
Tim Harvey0cee2242015-05-08 18:28:35 -0700734 /* setup baseboard specific GPIO based on board and env */
735 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800736
737#ifdef CONFIG_CMD_BMODE
738 add_board_boot_modes(board_boot_modes);
739#endif
740
Tim Harvey40feabb2015-05-08 18:28:36 -0700741 /* disable boot watchdog */
742 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800743
744 return 0;
745}
746
Robert P. J. Day3c757002016-05-19 15:23:12 -0400747#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800748
Tim Harveycf20e552015-04-08 12:55:01 -0700749static 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 Harveybfb240a2016-06-17 06:10:41 -0700785#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 Harveybfb240a2016-06-17 06:10:41 -0700791int 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 */
817int 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 Harvey984aa0d2019-02-04 13:11:00 -0800823 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700824 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 */
849int 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 Harvey984aa0d2019-02-04 13:11:00 -0800860 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700861 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 Harvey77b82a12016-06-17 06:10:42 -0700937/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
938int 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 Glass64b723f2017-08-03 12:22:12 -0600946 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -0700947 if (tmp) {
948 for (j = 0; j < 6; j++) {
949 mac_addr[j] = tmp ?
Simon Glass3ff49ec2021-07-24 09:03:29 -0600950 hextoul(tmp, &end) : 0;
Tim Harvey77b82a12016-06-17 06:10:42 -0700951 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 Harveybfb240a2016-06-17 06:10:41 -0700963/*
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 Yamadaf7ed78b2020-06-26 15:13:33 +0900968void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -0700969{
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 Harvey895aace2022-03-07 16:24:00 -0800982 i2c_get_dev(1, 0x50))
Tim Harveybfb240a2016-06-17 06:10:41 -0700983 {
984 np = fdt_add_pci_path(blob, dev);
985 if (np > 0)
986 fdt_fixup_gw16082(blob, np, dev);
987 }
Tim Harvey77b82a12016-06-17 06:10:42 -0700988
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 Harveybfb240a2016-06-17 06:10:41 -0700997 }
998}
999#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001000
Tim Harvey42874232022-03-07 16:24:03 -08001001#define WDOG1_ADDR 0x20bc000
1002#define WDOG2_ADDR 0x20c0000
1003#define GPIO3_ADDR 0x20a4000
1004#define USDHC3_ADDR 0x2198000
1005static 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
1015void 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 Harvey552c3582014-03-06 07:46:30 -08001147/*
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 Harvey984aa0d2019-02-04 13:11:00 -08001156#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001157int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001158{
Tim Harvey552c3582014-03-06 07:46:30 -08001159 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001160 struct ventana_eeprom_config *cfg;
Tim Harvey8e502172021-07-24 10:40:33 -07001161 static const struct node_info nand_nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001162 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1163 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1164 };
Simon Glass64b723f2017-08-03 12:22:12 -06001165 const char *model = env_get("model");
1166 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001167 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 Harvey552c3582014-03-06 07:46:30 -08001177
Simon Glass64b723f2017-08-03 12:22:12 -06001178 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001179 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001180 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001181 }
1182
Tim Harvey8e502172021-07-24 10:40:33 -07001183 /* 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 Harvey552c3582014-03-06 07:46:30 -08001186
Tim Harveye4af5d32015-04-08 12:54:58 -07001187 /* 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 Harvey552c3582014-03-06 07:46:30 -08001194 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1195
1196 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001197 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1198 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001199
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 Harveycf20e552015-04-08 12:55:01 -07001204 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001205 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001206
Tim Harvey28db4e42021-07-24 10:40:32 -07001207 /* early board/revision ft fixups */
1208 ft_early_fixup(blob, board_type);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001209
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001210 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001211 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001212 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 Harvey984aa0d2019-02-04 13:11:00 -08001220 phys_addr_t addr;
1221 int off;
1222
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001223 printf(" Enabling pwm%d for DIO%d\n",
1224 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001225 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 Harvey8d2d8df2016-05-24 11:03:55 -07001231 }
1232 }
1233
Tim Harveybfb240a2016-06-17 06:10:41 -07001234#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001235 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001236 ft_board_pci_fixup(blob, bd);
1237#endif
1238
Tim Harvey6944ccf2015-04-08 12:54:53 -07001239 /*
Tim Harvey7ad148a2021-09-29 15:04:18 -07001240 * 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 Harvey552c3582014-03-06 07:46:30 -08001248 * Peripheral Config:
1249 * remove nodes by alias path if EEPROM config tells us the
1250 * peripheral is not loaded on the board.
1251 */
Simon Glass64b723f2017-08-03 12:22:12 -06001252 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001253 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001254 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001255 }
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 Harvey552c3582014-03-06 07:46:30 -08001263 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001264
1265 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001266}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001267#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey235c6f12022-09-28 14:00:35 -07001268
1269int board_mmc_get_env_dev(int devno)
1270{
1271 return devno;
1272}