blob: 683def7e9f71123080de996415465e0e6d211de5 [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 Harvey552c3582014-03-06 07:46:30 -08009#include <common.h>
Tim Harvey41377852022-04-13 09:29:16 -070010#include <fdt_support.h>
11#include <gsc.h>
12#include <hwconfig.h>
13#include <i2c.h>
14#include <miiphy.h>
15#include <mtd_node.h>
Tim Harvey552c3582014-03-06 07:46:30 -080016#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070017#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080018#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070019#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080020#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020022#include <asm/mach-imx/video.h>
Tim Harvey41377852022-04-13 09:29:16 -070023#include <jffs2/load_kernel.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070024#include <linux/ctype.h>
Simon Glassdbd79542020-05-10 11:40:11 -060025#include <linux/delay.h>
Tim Harvey552c3582014-03-06 07:46:30 -080026
Tim Harvey0cee2242015-05-08 18:28:35 -070027#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080028
29DECLARE_GLOBAL_DATA_PTR;
30
Tim Harvey552c3582014-03-06 07:46:30 -080031/* configure eth0 PHY board-specific LED behavior */
32int board_phy_config(struct phy_device *phydev)
33{
34 unsigned short val;
Tim Harveyb9d23522022-04-29 13:51:02 -070035 ofnode node;
Tim Harvey552c3582014-03-06 07:46:30 -080036
Tim Harveyb9d23522022-04-29 13:51:02 -070037 switch (phydev->phy_id) {
38 case 0x1410dd1:
Tim Harveyb25b7582021-06-11 12:46:26 -070039 puts("MV88E1510");
Tim Harvey552c3582014-03-06 07:46:30 -080040 /*
41 * Page 3, Register 16: LED[2:0] Function Control Register
42 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
43 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
44 */
45 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
46 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
47 val &= 0xff00;
48 val |= 0x0017;
49 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
50 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
Tim Harveyb9d23522022-04-29 13:51:02 -070051 break;
52 case 0x2000a231:
Tim Harveyb25b7582021-06-11 12:46:26 -070053 puts("TIDP83867 ");
Tim Harvey1662ad32021-06-11 12:46:25 -070054 /* LED configuration */
55 val = 0;
56 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
57 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
58 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
59
Tim Harvey4533c902017-03-17 07:32:21 -070060 /* configure register 0x170 for ref CLKOUT */
61 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
62 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
63 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
64 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
65 val &= ~0x1f00;
66 val |= 0x0b00; /* chD tx clock*/
67 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
Tim Harveyb9d23522022-04-29 13:51:02 -070068 break;
69 case 0xd565a401:
70 puts("GPY111 ");
71 node = phy_get_ofnode(phydev);
72 if (ofnode_valid(node)) {
73 u32 rx_delay, tx_delay;
74
75 rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000);
76 tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000);
77 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17);
78 val &= ~((0x7 << 12) | (0x7 << 8));
79 val |= (rx_delay / 500) << 12;
80 val |= (tx_delay / 500) << 8;
81 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val);
82 }
83 break;
Tim Harvey4533c902017-03-17 07:32:21 -070084 }
85
Tim Harvey781f6d82022-11-30 09:42:51 -080086 /* Fixed PHY: for GW5904/GW5909 this is Marvell 88E6176 GbE Switch */
87 if (phydev->phy_id == PHY_FIXED_ID &&
88 (board_type == GW5904 || board_type == GW5909)) {
89 struct mii_dev *bus = miiphy_get_dev_by_name("mdio");
Tim Harvey63537792017-03-17 07:30:38 -070090
Tim Harvey781f6d82022-11-30 09:42:51 -080091 puts("MV88E61XX ");
92 /* GPIO[0] output CLK125 for RGMII_REFCLK */
93 bus->write(bus, 0x1c, 0, 0x1a, (1 << 15) | (0x62 << 8) | 0xfe);
94 bus->write(bus, 0x1c, 0, 0x1a, (1 << 15) | (0x68 << 8) | 7);
Tim Harvey63537792017-03-17 07:30:38 -070095
Tim Harvey781f6d82022-11-30 09:42:51 -080096 /* Port 0-3 LED configuration: Table 80/82 */
97 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
98 bus->write(bus, 0x10, 0, 0x16, 0x8088);
99 bus->write(bus, 0x11, 0, 0x16, 0x8088);
100 bus->write(bus, 0x12, 0, 0x16, 0x8088);
101 bus->write(bus, 0x13, 0, 0x16, 0x8088);
102 }
Tim Harvey63537792017-03-17 07:30:38 -0700103
Tim Harvey781f6d82022-11-30 09:42:51 -0800104 if (phydev->drv->config)
105 phydev->drv->config(phydev);
Tim Harvey63537792017-03-17 07:30:38 -0700106
107 return 0;
108}
Tim Harvey552c3582014-03-06 07:46:30 -0800109
Tim Harveyfb64cc72014-04-25 15:39:07 -0700110#if defined(CONFIG_VIDEO_IPUV3)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700111static void enable_hdmi(struct display_info_t const *dev)
112{
113 imx_enable_hdmi_phy();
114}
115
Tim Harveyceb79f52021-09-29 15:04:21 -0700116static int detect_lvds(struct display_info_t const *dev)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700117{
Tim Harveyceb79f52021-09-29 15:04:21 -0700118 /* only the following boards support LVDS connectors */
119 switch (board_type) {
120 case GW52xx:
121 case GW53xx:
122 case GW54xx:
123 case GW560x:
124 case GW5905:
125 case GW5909:
126 break;
127 default:
128 return 0;
129 }
130
Tim Harvey895aace2022-03-07 16:24:00 -0800131 return (i2c_get_dev(dev->bus, dev->addr) ? 1 : 0);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700132}
133
134static void enable_lvds(struct display_info_t const *dev)
135{
Tim Harveyceb79f52021-09-29 15:04:21 -0700136 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harveyfb64cc72014-04-25 15:39:07 -0700137
138 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
139 u32 reg = readl(&iomux->gpr[2]);
140 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
141 writel(reg, &iomux->gpr[2]);
142
Tim Harveyceb79f52021-09-29 15:04:21 -0700143 /* Configure GPIO */
144 switch (board_type) {
145 case GW52xx:
146 case GW53xx:
147 case GW54xx:
148 if (!strncmp(dev->mode.name, "Hannstar", 8)) {
149 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
150 gpio_request(IMX_GPIO_NR(1, 10), "cabc");
151 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
152 } else if (!strncmp(dev->mode.name, "DLC", 3)) {
153 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
154 gpio_request(IMX_GPIO_NR(1, 10), "touch_rst#");
155 gpio_direction_output(IMX_GPIO_NR(1, 10), 1);
156 }
157 break;
158 default:
159 break;
160 }
161
162 /* Configure backlight */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700163 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700164 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700165 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
166}
167
168struct display_info_t const displays[] = {{
169 /* HDMI Output */
170 .bus = -1,
171 .addr = 0,
172 .pixfmt = IPU_PIX_FMT_RGB24,
173 .detect = detect_hdmi,
174 .enable = enable_hdmi,
175 .mode = {
176 .name = "HDMI",
177 .refresh = 60,
178 .xres = 1024,
179 .yres = 768,
180 .pixclock = 15385,
181 .left_margin = 220,
182 .right_margin = 40,
183 .upper_margin = 21,
184 .lower_margin = 7,
185 .hsync_len = 60,
186 .vsync_len = 10,
187 .sync = FB_SYNC_EXT,
188 .vmode = FB_VMODE_NONINTERLACED
189} }, {
190 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
191 .bus = 2,
192 .addr = 0x4,
193 .pixfmt = IPU_PIX_FMT_LVDS666,
Tim Harveyceb79f52021-09-29 15:04:21 -0700194 .detect = detect_lvds,
Tim Harveyfb64cc72014-04-25 15:39:07 -0700195 .enable = enable_lvds,
196 .mode = {
197 .name = "Hannstar-XGA",
198 .refresh = 60,
199 .xres = 1024,
200 .yres = 768,
201 .pixclock = 15385,
202 .left_margin = 220,
203 .right_margin = 40,
204 .upper_margin = 21,
205 .lower_margin = 7,
206 .hsync_len = 60,
207 .vsync_len = 10,
208 .sync = FB_SYNC_EXT,
209 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700210} }, {
211 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800212 .bus = 2,
213 .addr = 0x38,
Tim Harveyceb79f52021-09-29 15:04:21 -0700214 .detect = detect_lvds,
Tim Harveya20bd632015-04-08 12:54:57 -0700215 .enable = enable_lvds,
216 .pixfmt = IPU_PIX_FMT_LVDS666,
217 .mode = {
218 .name = "DLC700JMGT4",
219 .refresh = 60,
220 .xres = 1024, /* 1024x600active pixels */
221 .yres = 600,
222 .pixclock = 15385, /* 64MHz */
223 .left_margin = 220,
224 .right_margin = 40,
225 .upper_margin = 21,
226 .lower_margin = 7,
227 .hsync_len = 60,
228 .vsync_len = 10,
229 .sync = FB_SYNC_EXT,
230 .vmode = FB_VMODE_NONINTERLACED
231} }, {
Tim Harvey87a86452021-06-11 12:46:27 -0700232 /* DLC0700XDP21LF-C-1 */
Tim Harveyceb79f52021-09-29 15:04:21 -0700233 .bus = 2,
234 .addr = 0x38,
235 .detect = detect_lvds,
Tim Harvey87a86452021-06-11 12:46:27 -0700236 .enable = enable_lvds,
237 .pixfmt = IPU_PIX_FMT_LVDS666,
238 .mode = {
239 .name = "DLC0700XDP21LF",
240 .refresh = 60,
241 .xres = 1024, /* 1024x600active pixels */
242 .yres = 600,
243 .pixclock = 15385, /* 64MHz */
244 .left_margin = 220,
245 .right_margin = 40,
246 .upper_margin = 21,
247 .lower_margin = 7,
248 .hsync_len = 60,
249 .vsync_len = 10,
250 .sync = FB_SYNC_EXT,
251 .vmode = FB_VMODE_NONINTERLACED
252} }, {
Tim Harveya20bd632015-04-08 12:54:57 -0700253 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800254 .bus = 2,
255 .addr = 0x14,
Tim Harveyceb79f52021-09-29 15:04:21 -0700256 .detect = detect_lvds,
Tim Harveya20bd632015-04-08 12:54:57 -0700257 .enable = enable_lvds,
258 .pixfmt = IPU_PIX_FMT_LVDS666,
259 .mode = {
260 .name = "DLC800FIGT3",
261 .refresh = 60,
262 .xres = 1024, /* 1024x768 active pixels */
263 .yres = 768,
264 .pixclock = 15385, /* 64MHz */
265 .left_margin = 220,
266 .right_margin = 40,
267 .upper_margin = 21,
268 .lower_margin = 7,
269 .hsync_len = 60,
270 .vsync_len = 10,
271 .sync = FB_SYNC_EXT,
272 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800273} }, {
274 .bus = 2,
275 .addr = 0x5d,
Tim Harveyceb79f52021-09-29 15:04:21 -0700276 .detect = detect_lvds,
Tim Harveyc34e59e2019-02-04 13:10:51 -0800277 .enable = enable_lvds,
278 .pixfmt = IPU_PIX_FMT_LVDS666,
279 .mode = {
280 .name = "Z101WX01",
281 .refresh = 60,
282 .xres = 1280,
283 .yres = 800,
284 .pixclock = 15385, /* 64MHz */
285 .left_margin = 220,
286 .right_margin = 40,
287 .upper_margin = 21,
288 .lower_margin = 7,
289 .hsync_len = 60,
290 .vsync_len = 10,
291 .sync = FB_SYNC_EXT,
292 .vmode = FB_VMODE_NONINTERLACED
293 }
294},
295};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700296size_t display_count = ARRAY_SIZE(displays);
297
298static void setup_display(void)
299{
300 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
301 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
302 int reg;
303
304 enable_ipu_clock();
305 imx_setup_hdmi();
306 /* Turn on LDB0,IPU,IPU DI0 clocks */
307 reg = __raw_readl(&mxc_ccm->CCGR3);
308 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
309 writel(reg, &mxc_ccm->CCGR3);
310
311 /* set LDB0, LDB1 clk select to 011/011 */
312 reg = readl(&mxc_ccm->cs2cdr);
313 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
314 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
315 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
316 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
317 writel(reg, &mxc_ccm->cs2cdr);
318
319 reg = readl(&mxc_ccm->cscmr2);
320 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
321 writel(reg, &mxc_ccm->cscmr2);
322
323 reg = readl(&mxc_ccm->chsccdr);
324 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
325 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
326 writel(reg, &mxc_ccm->chsccdr);
327
328 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
329 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
330 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
331 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
332 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
333 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
334 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
335 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
336 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
337 writel(reg, &iomux->gpr[2]);
338
339 reg = readl(&iomux->gpr[3]);
340 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
341 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
342 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
343 writel(reg, &iomux->gpr[3]);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700344}
345#endif /* CONFIG_VIDEO_IPUV3 */
346
Tim Harvey33791d52014-08-07 22:49:57 -0700347/*
348 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
349 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
350 * properly and assert reset for 100ms.
351 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700352#define MAX_PCI_DEVS 32
353struct pci_dev {
354 pci_dev_t devfn;
Tim Harvey6ce10d52021-05-03 11:21:27 -0700355 struct udevice *dev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700356 unsigned short vendor;
357 unsigned short device;
358 unsigned short class;
359 unsigned short busno; /* subbordinate busno */
360 struct pci_dev *ppar;
361};
362struct pci_dev pci_devs[MAX_PCI_DEVS];
363int pci_devno;
364int pci_bridgeno;
365
Tim Harvey6ce10d52021-05-03 11:21:27 -0700366void board_pci_fixup_dev(struct udevice *bus, struct udevice *udev)
Tim Harvey33791d52014-08-07 22:49:57 -0700367{
Tim Harvey6ce10d52021-05-03 11:21:27 -0700368 struct pci_child_plat *pdata = dev_get_parent_plat(udev);
Tim Harveybfb240a2016-06-17 06:10:41 -0700369 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey6ce10d52021-05-03 11:21:27 -0700370 unsigned short vendor = pdata->vendor;
371 unsigned short device = pdata->device;
372 unsigned int class = pdata->class;
373 pci_dev_t dev = dm_pci_get_bdf(udev);
374 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700375
376 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
377 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700378
379 /* store array of devs for later use in device-tree fixup */
Tim Harvey6ce10d52021-05-03 11:21:27 -0700380 pdev->dev = udev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700381 pdev->devfn = dev;
382 pdev->vendor = vendor;
383 pdev->device = device;
384 pdev->class = class;
385 pdev->ppar = NULL;
386 if (class == PCI_CLASS_BRIDGE_PCI)
387 pdev->busno = ++pci_bridgeno;
388 else
389 pdev->busno = 0;
390
391 /* fixup RC - it should be 00:00.0 not 00:01.0 */
392 if (PCI_BUS(dev) == 0)
393 pdev->devfn = 0;
394
395 /* find dev's parent */
396 for (i = 0; i < pci_devno; i++) {
397 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
398 pdev->ppar = &pci_devs[i];
399 break;
400 }
401 }
402
403 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700404 if (vendor == PCI_VENDOR_ID_PLX &&
405 (device & 0xfff0) == 0x8600 &&
406 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
Tim Harvey6ce10d52021-05-03 11:21:27 -0700407 ulong val;
Tim Harvey33791d52014-08-07 22:49:57 -0700408 debug("configuring PLX 860X downstream PERST#\n");
Tim Harvey6ce10d52021-05-03 11:21:27 -0700409 pci_bus_read_config(bus, dev, 0x62c, &val, PCI_SIZE_32);
410 val |= 0xaaa8; /* GPIO1-7 outputs */
411 pci_bus_write_config(bus, dev, 0x62c, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700412
Tim Harvey6ce10d52021-05-03 11:21:27 -0700413 pci_bus_read_config(bus, dev, 0x644, &val, PCI_SIZE_32);
414 val |= 0xfe; /* GPIO1-7 output high */
415 pci_bus_write_config(bus, dev, 0x644, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700416
417 mdelay(100);
418 }
419}
Tim Harvey552c3582014-03-06 07:46:30 -0800420
421#ifdef CONFIG_SERIAL_TAG
422/*
423 * called when setting up ATAGS before booting kernel
424 * populate serialnum from the following (in order of priority):
425 * serial# env var
426 * eeprom
427 */
428void get_board_serial(struct tag_serialnr *serialnr)
429{
Simon Glass64b723f2017-08-03 12:22:12 -0600430 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800431
432 if (serial) {
433 serialnr->high = 0;
Simon Glassff9b9032021-07-24 09:03:30 -0600434 serialnr->low = dectoul(serial, NULL);
Tim Harvey552c3582014-03-06 07:46:30 -0800435 } else if (ventana_info.model[0]) {
436 serialnr->high = 0;
437 serialnr->low = ventana_info.serial;
438 } else {
439 serialnr->high = 0;
440 serialnr->low = 0;
441 }
442}
443#endif
444
445/*
446 * Board Support
447 */
448
449int board_early_init_f(void)
450{
Tim Harveyfb64cc72014-04-25 15:39:07 -0700451#if defined(CONFIG_VIDEO_IPUV3)
452 setup_display();
453#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800454 return 0;
455}
456
457int dram_init(void)
458{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700459 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800460 return 0;
461}
462
463int board_init(void)
464{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300465 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800466
467 clrsetbits_le32(&iomuxc_regs->gpr[1],
468 IOMUXC_GPR1_OTG_ID_MASK,
469 IOMUXC_GPR1_OTG_ID_GPIO1);
470
471 /* address of linux boot parameters */
472 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
473
Tim Harveyba9f2342019-02-04 13:10:52 -0800474 /* read Gateworks EEPROM into global struct (used later) */
Tim Harvey41377852022-04-13 09:29:16 -0700475 board_type = read_eeprom(&ventana_info);
Tim Harveyba9f2342019-02-04 13:10:52 -0800476
Tim Harvey41377852022-04-13 09:29:16 -0700477 setup_iomux_gpio(board_type);
478
479 /* show GSC details */
480 run_command("gsc", 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800481
482 return 0;
483}
484
Tim Harvey948202c2021-03-01 14:33:32 -0800485int board_fit_config_name_match(const char *name)
486{
487 static char init;
488 const char *dtb;
489 char buf[32];
490 int i = 0;
491
492 do {
493 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
494 if (dtb && !strcmp(dtb, name)) {
495 if (!init++)
496 printf("DTB: %s\n", name);
497 return 0;
498 }
499 } while (dtb);
500
501 return -1;
502}
503
Tim Harvey552c3582014-03-06 07:46:30 -0800504#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
505/*
506 * called during late init (after relocation and after board_init())
507 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
508 * EEPROM read.
509 */
510int checkboard(void)
511{
512 struct ventana_board_info *info = &ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -0800513 const char *p;
514 int quiet; /* Quiet or minimal output mode */
515
516 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600517 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800518 if (p)
519 quiet = simple_strtol(p, NULL, 10);
520 else
Simon Glass6a38e412017-08-03 12:22:09 -0600521 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800522
523 puts("\nGateworks Corporation Copyright 2014\n");
524 if (info->model[0]) {
525 printf("Model: %s\n", info->model);
526 printf("MFGDate: %02x-%02x-%02x%02x\n",
527 info->mfgdate[0], info->mfgdate[1],
528 info->mfgdate[2], info->mfgdate[3]);
529 printf("Serial:%d\n", info->serial);
530 } else {
531 puts("Invalid EEPROM - board will not function fully\n");
532 }
533 if (quiet)
534 return 0;
535
Tim Harvey552c3582014-03-06 07:46:30 -0800536 return 0;
537}
538#endif
539
540#ifdef CONFIG_CMD_BMODE
541/*
542 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
543 * see Table 8-11 and Table 5-9
544 * BOOT_CFG1[7] = 1 (boot from NAND)
545 * BOOT_CFG1[5] = 0 - raw NAND
546 * BOOT_CFG1[4] = 0 - default pad settings
547 * BOOT_CFG1[3:2] = 00 - devices = 1
548 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
549 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
550 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
551 * BOOT_CFG2[0] = 0 - Reset time 12ms
552 */
553static const struct boot_mode board_boot_modes[] = {
554 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
555 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700556 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800557 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800558 { NULL, 0 },
559};
560#endif
561
Tim Harvey55c33cb2022-03-07 16:24:02 -0800562/* setup GPIO pinmux and default configuration per baseboard and env */
563void setup_board_gpio(int board, struct ventana_board_info *info)
564{
565 const char *s;
566 char arg[10];
567 size_t len;
568 int i;
569 int quiet = simple_strtol(env_get("quiet"), NULL, 10);
570
571 if (board >= GW_UNKNOWN)
572 return;
573
574 /* RS232_EN# */
575 if (gpio_cfg[board].rs232_en) {
576 gpio_direction_output(gpio_cfg[board].rs232_en,
577 (hwconfig("rs232")) ? 0 : 1);
578 }
579
580 /* MSATA Enable */
581 if (gpio_cfg[board].msata_en && is_cpu_type(MXC_CPU_MX6Q)) {
582 gpio_direction_output(GP_MSATA_SEL,
583 (hwconfig("msata")) ? 1 : 0);
584 }
585
586 /* USBOTG Select (PCISKT or FrontPanel) */
587 if (gpio_cfg[board].usb_sel) {
588 gpio_direction_output(gpio_cfg[board].usb_sel,
589 (hwconfig("usb_pcisel")) ? 1 : 0);
590 }
591
592 /*
593 * Configure DIO pinmux/padctl registers
594 * see IMX6DQRM/IMX6SDLRM IOMUXC_SW_PAD_CTL_PAD_* register definitions
595 */
596 for (i = 0; i < gpio_cfg[board].dio_num; i++) {
597 struct dio_cfg *cfg = &gpio_cfg[board].dio_cfg[i];
598 iomux_v3_cfg_t ctrl = DIO_PAD_CFG;
599 unsigned int cputype = is_cpu_type(MXC_CPU_MX6Q) ? 0 : 1;
600
601 if (!cfg->gpio_padmux[0] && !cfg->gpio_padmux[1])
602 continue;
603 sprintf(arg, "dio%d", i);
604 if (!hwconfig(arg))
605 continue;
606 s = hwconfig_subarg(arg, "padctrl", &len);
607 if (s) {
608 ctrl = MUX_PAD_CTRL(hextoul(s, NULL)
609 & 0x1ffff) | MUX_MODE_SION;
610 }
611 if (hwconfig_subarg_cmp(arg, "mode", "gpio")) {
612 if (!quiet) {
613 printf("DIO%d: GPIO%d_IO%02d (gpio-%d)\n", i,
614 (cfg->gpio_param / 32) + 1,
615 cfg->gpio_param % 32,
616 cfg->gpio_param);
617 }
618 imx_iomux_v3_setup_pad(cfg->gpio_padmux[cputype] |
619 ctrl);
620 gpio_requestf(cfg->gpio_param, "dio%d", i);
621 gpio_direction_input(cfg->gpio_param);
Heinrich Schuchardt151462b2022-10-12 18:59:27 +0200622 } else if (hwconfig_subarg_cmp(arg, "mode", "pwm")) {
Tim Harvey55c33cb2022-03-07 16:24:02 -0800623 if (!cfg->pwm_param) {
624 printf("DIO%d: Error: pwm config invalid\n",
625 i);
626 continue;
627 }
628 if (!quiet)
629 printf("DIO%d: pwm%d\n", i, cfg->pwm_param);
630 imx_iomux_v3_setup_pad(cfg->pwm_padmux[cputype] |
631 MUX_PAD_CTRL(ctrl));
632 }
633 }
634
635 if (!quiet) {
636 if (gpio_cfg[board].msata_en && is_cpu_type(MXC_CPU_MX6Q)) {
637 printf("MSATA: %s\n", (hwconfig("msata") ?
638 "enabled" : "disabled"));
639 }
640 if (gpio_cfg[board].rs232_en) {
641 printf("RS232: %s\n", (hwconfig("rs232")) ?
642 "enabled" : "disabled");
643 }
644 }
645}
Tim Harvey552c3582014-03-06 07:46:30 -0800646/* late init */
647int misc_init_r(void)
648{
649 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700650 char buf[256];
651 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800652
653 /* set env vars based on EEPROM data */
654 if (ventana_info.model[0]) {
655 char str[16], fdt[36];
656 char *p;
657 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800658
659 /*
660 * FDT name will be prefixed with CPU type. Three versions
661 * will be created each increasingly generic and bootloader
662 * env scripts will try loading each from most specific to
663 * least.
664 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700665 if (is_cpu_type(MXC_CPU_MX6Q) ||
666 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800667 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700668 else if (is_cpu_type(MXC_CPU_MX6DL) ||
669 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800670 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600671 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700672 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600673 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700674 else
Simon Glass6a38e412017-08-03 12:22:09 -0600675 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800676 memset(str, 0, sizeof(str));
677 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
678 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600679 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600680 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800681 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600682 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800683 }
684 p = strchr(str, '-');
685 if (p) {
686 *p++ = 0;
687
Simon Glass6a38e412017-08-03 12:22:09 -0600688 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700689 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600690 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700691 if (board_type != GW551x &&
692 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700693 board_type != GW553x &&
694 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700695 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800696 str[5] = 'x';
697 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700698 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600699 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800700 }
701
702 /* initialize env from EEPROM */
703 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600704 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600705 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800706 }
707 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600708 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600709 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800710 }
711
712 /* board serial-number */
713 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600714 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700715
716 /* memory MB */
717 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600718 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800719 }
720
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700721 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600722 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700723 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700724 if (gpio_cfg[board_type].rs232_en)
725 strcat(buf, "rs232;");
726 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
727 char buf1[32];
728 sprintf(buf1, "dio%d:mode=gpio;", i);
729 if (strlen(buf) + strlen(buf1) < sizeof(buf))
730 strcat(buf, buf1);
731 }
Simon Glass6a38e412017-08-03 12:22:09 -0600732 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700733 }
Tim Harvey552c3582014-03-06 07:46:30 -0800734
Tim Harvey0cee2242015-05-08 18:28:35 -0700735 /* setup baseboard specific GPIO based on board and env */
736 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800737
738#ifdef CONFIG_CMD_BMODE
739 add_board_boot_modes(board_boot_modes);
740#endif
741
Tim Harvey40feabb2015-05-08 18:28:36 -0700742 /* disable boot watchdog */
743 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800744
745 return 0;
746}
747
Robert P. J. Day3c757002016-05-19 15:23:12 -0400748#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800749
Tim Harveycf20e552015-04-08 12:55:01 -0700750static int ft_sethdmiinfmt(void *blob, char *mode)
751{
752 int off;
753
754 if (!mode)
755 return -EINVAL;
756
757 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
758 if (off < 0)
759 return off;
760
761 if (0 == strcasecmp(mode, "yuv422bt656")) {
762 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
763 0x00, 0x00, 0x00 };
764 mode = "422_ccir";
765 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
766 fdt_setprop_u32(blob, off, "vidout_trc", 1);
767 fdt_setprop_u32(blob, off, "vidout_blc", 1);
768 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
769 printf(" set HDMI input mode to %s\n", mode);
770 } else if (0 == strcasecmp(mode, "yuv422smp")) {
771 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
772 0x82, 0x81, 0x00 };
773 mode = "422_smp";
774 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
775 fdt_setprop_u32(blob, off, "vidout_trc", 0);
776 fdt_setprop_u32(blob, off, "vidout_blc", 0);
777 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
778 printf(" set HDMI input mode to %s\n", mode);
779 } else {
780 return -EINVAL;
781 }
782
783 return 0;
784}
785
Tim Harveybfb240a2016-06-17 06:10:41 -0700786#if defined(CONFIG_CMD_PCI)
787#define PCI_ID(x) ( \
788 (PCI_BUS(x->devfn)<<16)| \
789 (PCI_DEV(x->devfn)<<11)| \
790 (PCI_FUNC(x->devfn)<<8) \
791 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700792int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
793{
794 uint32_t reg[5];
795 char node[32];
796 int np;
797
798 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
799 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
800
801 np = fdt_subnode_offset(blob, par, node);
802 if (np >= 0)
803 return np;
804 np = fdt_add_subnode(blob, par, node);
805 if (np < 0) {
806 printf(" %s failed: no space\n", __func__);
807 return np;
808 }
809
810 memset(reg, 0, sizeof(reg));
811 reg[0] = cpu_to_fdt32(PCI_ID(dev));
812 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
813
814 return np;
815}
816
817/* build a path of nested PCI devs for all bridges passed through */
818int fdt_add_pci_path(void *blob, struct pci_dev *dev)
819{
820 struct pci_dev *bridges[MAX_PCI_DEVS];
821 int k, np;
822
823 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800824 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700825 if (np < 0)
826 return np;
827
828 k = 0;
829 while (dev) {
830 bridges[k++] = dev;
831 dev = dev->ppar;
832 };
833
834 /* now add them the to DT in reverse order */
835 while (k--) {
836 np = fdt_add_pci_node(blob, np, bridges[k]);
837 if (np < 0)
838 break;
839 }
840
841 return np;
842}
843
844/*
845 * The GW16082 has a hardware errata errata such that it's
846 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
847 * of this normal PCI interrupt swizzling will not work so we will
848 * provide an irq-map via device-tree.
849 */
850int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
851{
852 int len;
853 int host;
854 uint32_t imap_new[8*4*4];
855 const uint32_t *imap;
856 uint32_t irq[4];
857 uint32_t reg[4];
858 int i;
859
860 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800861 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700862 if (host < 0) {
863 printf(" %s failed: missing host\n", __func__);
864 return host;
865 }
866
867 /* use interrupt data from root complex's node */
868 imap = fdt_getprop(blob, host, "interrupt-map", &len);
869 if (!imap || len != 128) {
870 printf(" %s failed: invalid interrupt-map\n",
871 __func__);
872 return -FDT_ERR_NOTFOUND;
873 }
874
875 /* obtain irq's of host controller in pin order */
876 for (i = 0; i < 4; i++)
877 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
878
879 /*
880 * determine number of swizzles necessary:
881 * For each bridge we pass through we need to swizzle
882 * the number of the slot we are on.
883 */
884 struct pci_dev *d;
885 int b;
886 b = 0;
887 d = dev->ppar;
888 while(d && d->ppar) {
889 b += PCI_DEV(d->devfn);
890 d = d->ppar;
891 }
892
893 /* create new irq mappings for slots12-15
894 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
895 * J3 AD28 12 INTD INTA
896 * J4 AD29 13 INTC INTD
897 * J5 AD30 14 INTB INTC
898 * J2 AD31 15 INTA INTB
899 */
900 for (i = 0; i < 4; i++) {
901 /* addr matches bus:dev:func */
902 u32 addr = dev->busno << 16 | (12+i) << 11;
903
904 /* default cells from root complex */
905 memcpy(&imap_new[i*32], imap, 128);
906 /* first cell is PCI device address (BDF) */
907 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
908 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
909 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
910 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
911 /* third cell is pin */
912 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
913 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
914 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
915 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
916 /* sixth cell is relative interrupt */
917 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
918 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
919 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
920 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
921 }
922 fdt_setprop(blob, np, "interrupt-map", imap_new,
923 sizeof(imap_new));
924 reg[0] = cpu_to_fdt32(0xfff00);
925 reg[1] = 0;
926 reg[2] = 0;
927 reg[3] = cpu_to_fdt32(0x7);
928 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
929 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
930 fdt_setprop_string(blob, np, "device_type", "pci");
931 fdt_setprop_cell(blob, np, "#address-cells", 3);
932 fdt_setprop_cell(blob, np, "#size-cells", 2);
933 printf(" Added custom interrupt-map for GW16082\n");
934
935 return 0;
936}
937
Tim Harvey77b82a12016-06-17 06:10:42 -0700938/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
939int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
940{
941 char *tmp, *end;
942 char mac[16];
943 unsigned char mac_addr[6];
944 int j;
945
946 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -0600947 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -0700948 if (tmp) {
949 for (j = 0; j < 6; j++) {
950 mac_addr[j] = tmp ?
Simon Glass3ff49ec2021-07-24 09:03:29 -0600951 hextoul(tmp, &end) : 0;
Tim Harvey77b82a12016-06-17 06:10:42 -0700952 if (tmp)
953 tmp = (*end) ? end+1 : end;
954 }
955 fdt_setprop(blob, np, "local-mac-address", mac_addr,
956 sizeof(mac_addr));
957 printf(" Added mac addr for eth1\n");
958 return 0;
959 }
960
961 return -1;
962}
963
Tim Harveybfb240a2016-06-17 06:10:41 -0700964/*
965 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
966 * we will walk the PCI bus and add bridge nodes up to the device receiving
967 * the fixup.
968 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900969void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -0700970{
971 int i, np;
972 struct pci_dev *dev;
973
974 for (i = 0; i < pci_devno; i++) {
975 dev = &pci_devs[i];
976
977 /*
978 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
979 * an EEPROM at i2c1-0x50.
980 */
981 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
982 (dev->device == 0x8240) &&
Tim Harvey895aace2022-03-07 16:24:00 -0800983 i2c_get_dev(1, 0x50))
Tim Harveybfb240a2016-06-17 06:10:41 -0700984 {
985 np = fdt_add_pci_path(blob, dev);
986 if (np > 0)
987 fdt_fixup_gw16082(blob, np, dev);
988 }
Tim Harvey77b82a12016-06-17 06:10:42 -0700989
990 /* ethernet1 mac address */
991 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
992 (dev->device == 0x4380))
993 {
994 np = fdt_add_pci_path(blob, dev);
995 if (np > 0)
996 fdt_fixup_sky2(blob, np, dev);
997 }
Tim Harveybfb240a2016-06-17 06:10:41 -0700998 }
999}
1000#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001001
Tim Harvey42874232022-03-07 16:24:03 -08001002#define WDOG1_ADDR 0x20bc000
1003#define WDOG2_ADDR 0x20c0000
1004#define GPIO3_ADDR 0x20a4000
1005#define USDHC3_ADDR 0x2198000
1006static void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
1007{
1008 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1009
1010 if (off) {
1011 fdt_delprop(blob, off, "ext-reset-output");
1012 fdt_delprop(blob, off, "fsl,ext-reset-output");
1013 }
1014}
1015
1016void ft_early_fixup(void *blob, int board_type)
1017{
1018 struct ventana_board_info *info = &ventana_info;
1019 char rev = 0;
1020 int i;
1021
1022 /* determine board revision */
1023 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1024 if (ventana_info.model[i] >= 'A') {
1025 rev = ventana_info.model[i];
1026 break;
1027 }
1028 }
1029
1030 /*
1031 * Board model specific fixups
1032 */
1033 switch (board_type) {
1034 case GW51xx:
1035 /*
1036 * disable wdog node for GW51xx-A/B to work around
1037 * errata causing wdog timer to be unreliable.
1038 */
1039 if (rev >= 'A' && rev < 'C') {
1040 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1041 WDOG1_ADDR);
1042 if (i)
1043 fdt_status_disabled(blob, i);
1044 }
1045
1046 /* GW51xx-E adds WDOG1_B external reset */
1047 if (rev < 'E')
1048 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1049 break;
1050
1051 case GW52xx:
1052 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1053 if (info->model[4] == '2') {
1054 u32 handle = 0;
1055 u32 *range = NULL;
1056
1057 i = fdt_node_offset_by_compatible(blob, -1,
1058 "fsl,imx6q-pcie");
1059 if (i)
1060 range = (u32 *)fdt_getprop(blob, i,
1061 "reset-gpio", NULL);
1062
1063 if (range) {
1064 i = fdt_node_offset_by_compat_reg(blob,
1065 "fsl,imx6q-gpio", GPIO3_ADDR);
1066 if (i)
1067 handle = fdt_get_phandle(blob, i);
1068 if (handle) {
1069 range[0] = cpu_to_fdt32(handle);
1070 range[1] = cpu_to_fdt32(23);
1071 }
1072 }
1073
1074 /* these have broken usd_vsel */
1075 if (strstr((const char *)info->model, "SP318-B") ||
1076 strstr((const char *)info->model, "SP331-B"))
1077 gpio_cfg[board_type].usd_vsel = 0;
1078
1079 /* GW522x-B adds WDOG1_B external reset */
1080 if (rev < 'B')
1081 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1082 }
1083
1084 /* GW520x-E adds WDOG1_B external reset */
1085 else if (info->model[4] == '0' && rev < 'E')
1086 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1087 break;
1088
1089 case GW53xx:
1090 /* GW53xx-E adds WDOG1_B external reset */
1091 if (rev < 'E')
1092 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1093
1094 /* GW53xx-G has an adv7280 instead of an adv7180 */
1095 else if (rev > 'F') {
1096 i = fdt_node_offset_by_compatible(blob, -1, "adi,adv7180");
1097 if (i) {
1098 fdt_setprop_string(blob, i, "compatible", "adi,adv7280");
1099 fdt_setprop_empty(blob, i, "adv,force-bt656-4");
1100 }
1101 }
1102 break;
1103
1104 case GW54xx:
1105 /*
1106 * disable serial2 node for GW54xx for compatibility with older
1107 * 3.10.x kernel that improperly had this node enabled in the DT
1108 */
1109 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED);
1110
1111 /* GW54xx-E adds WDOG2_B external reset */
1112 if (rev < 'E')
1113 ft_board_wdog_fixup(blob, WDOG2_ADDR);
1114
1115 /* GW54xx-G has an adv7280 instead of an adv7180 */
1116 else if (rev > 'F') {
1117 i = fdt_node_offset_by_compatible(blob, -1, "adi,adv7180");
1118 if (i) {
1119 fdt_setprop_string(blob, i, "compatible", "adi,adv7280");
1120 fdt_setprop_empty(blob, i, "adv,force-bt656-4");
1121 }
1122 }
1123 break;
1124
1125 case GW551x:
1126 /* GW551x-C adds WDOG1_B external reset */
1127 if (rev < 'C')
1128 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1129 break;
1130 case GW5901:
1131 case GW5902:
1132 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1133 if (rev < 'B')
1134 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1135 break;
1136 }
1137
1138 /* remove no-1-8-v if UHS-I support is present */
1139 if (gpio_cfg[board_type].usd_vsel) {
1140 debug("Enabling UHS-I support\n");
1141 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1142 USDHC3_ADDR);
1143 if (i)
1144 fdt_delprop(blob, i, "no-1-8-v");
1145 }
1146}
1147
Tim Harvey552c3582014-03-06 07:46:30 -08001148/*
1149 * called prior to booting kernel or by 'fdt boardsetup' command
1150 *
1151 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1152 * - mtd partitions based on mtdparts/mtdids env
1153 * - system-serial (board serial num from EEPROM)
1154 * - board (full model from EEPROM)
1155 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1156 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001157#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001158int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001159{
Tim Harvey552c3582014-03-06 07:46:30 -08001160 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001161 struct ventana_eeprom_config *cfg;
Tim Harvey8e502172021-07-24 10:40:33 -07001162 static const struct node_info nand_nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001163 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1164 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1165 };
Simon Glass64b723f2017-08-03 12:22:12 -06001166 const char *model = env_get("model");
1167 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001168 int i;
1169 char rev = 0;
1170
1171 /* determine board revision */
1172 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1173 if (ventana_info.model[i] >= 'A') {
1174 rev = ventana_info.model[i];
1175 break;
1176 }
1177 }
Tim Harvey552c3582014-03-06 07:46:30 -08001178
Simon Glass64b723f2017-08-03 12:22:12 -06001179 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001180 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001181 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001182 }
1183
Tim Harvey8e502172021-07-24 10:40:33 -07001184 /* Update MTD partition nodes using info from mtdparts env var */
1185 puts(" Updating MTD partitions...\n");
1186 fdt_fixup_mtdparts(blob, nand_nodes, ARRAY_SIZE(nand_nodes));
Tim Harvey552c3582014-03-06 07:46:30 -08001187
Tim Harveye4af5d32015-04-08 12:54:58 -07001188 /* Update display timings from display env var */
1189 if (display) {
1190 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1191 display) >= 0)
1192 printf(" Set display timings for %s...\n", display);
1193 }
1194
Tim Harvey552c3582014-03-06 07:46:30 -08001195 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1196
1197 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001198 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1199 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001200
1201 /* board (model contains model from device-tree) */
1202 fdt_setprop(blob, 0, "board", info->model,
1203 strlen((const char *)info->model) + 1);
1204
Tim Harveycf20e552015-04-08 12:55:01 -07001205 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001206 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001207
Tim Harvey28db4e42021-07-24 10:40:32 -07001208 /* early board/revision ft fixups */
1209 ft_early_fixup(blob, board_type);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001210
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001211 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001212 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001213 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1214 char arg[10];
1215
1216 sprintf(arg, "dio%d", i);
1217 if (!hwconfig(arg))
1218 continue;
1219 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1220 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001221 phys_addr_t addr;
1222 int off;
1223
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001224 printf(" Enabling pwm%d for DIO%d\n",
1225 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001226 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1227 off = fdt_node_offset_by_compat_reg(blob,
1228 "fsl,imx6q-pwm",
1229 addr);
1230 if (off)
1231 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001232 }
1233 }
1234
Tim Harveybfb240a2016-06-17 06:10:41 -07001235#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001236 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001237 ft_board_pci_fixup(blob, bd);
1238#endif
1239
Tim Harvey6944ccf2015-04-08 12:54:53 -07001240 /*
Tim Harvey7ad148a2021-09-29 15:04:18 -07001241 * remove reset gpio control as we configure the PHY registers
1242 * for internal delay, LED config, and clock config in the bootloader
1243 */
1244 i = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-fec");
1245 if (i)
1246 fdt_delprop(blob, i, "phy-reset-gpios");
1247
1248 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001249 * Peripheral Config:
1250 * remove nodes by alias path if EEPROM config tells us the
1251 * peripheral is not loaded on the board.
1252 */
Simon Glass64b723f2017-08-03 12:22:12 -06001253 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001254 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001255 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001256 }
1257 cfg = econfig;
1258 while (cfg->name) {
1259 if (!test_bit(cfg->bit, info->config)) {
1260 fdt_del_node_and_alias(blob, cfg->dtalias ?
1261 cfg->dtalias : cfg->name);
1262 }
1263 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001264 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001265
1266 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001267}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001268#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey235c6f12022-09-28 14:00:35 -07001269
1270int board_mmc_get_env_dev(int devno)
1271{
1272 return devno;
1273}