blob: 860342dd4a634c4c560a425af02a23d26304482d [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
8#include <common.h>
Tim Harvey552c3582014-03-06 07:46:30 -08009#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070010#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080011#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070012#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080013#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Tim Harvey552c3582014-03-06 07:46:30 -080015#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020016#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/video.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060018#include <asm/setup.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060019#include <env.h>
Tim Harvey8d2d8df2016-05-24 11:03:55 -070020#include <hwconfig.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070021#include <linux/ctype.h>
Tim Harvey552c3582014-03-06 07:46:30 -080022#include <miiphy.h>
Tim Harvey552c3582014-03-06 07:46:30 -080023#include <mtd_node.h>
Simon Glassdbd79542020-05-10 11:40:11 -060024#include <linux/delay.h>
Tim Harvey552c3582014-03-06 07:46:30 -080025#include <power/pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080026#include <fdt_support.h>
27#include <jffs2/load_kernel.h>
Tim Harvey552c3582014-03-06 07:46:30 -080028
29#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070030#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080031
32DECLARE_GLOBAL_DATA_PTR;
33
Tim Harvey26993362014-08-07 22:35:49 -070034
Tim Harvey552c3582014-03-06 07:46:30 -080035/*
36 * EEPROM board info struct populated by read_eeprom so that we only have to
37 * read it once.
38 */
Tim Harvey0da2c522014-08-07 22:35:45 -070039struct ventana_board_info ventana_info;
Tim Harvey8b92bdf2015-04-08 12:54:43 -070040static int board_type;
Tim Harvey552c3582014-03-06 07:46:30 -080041
Tim Harvey552c3582014-03-06 07:46:30 -080042#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey1112b4e2021-03-01 14:33:34 -080043/* toggle USB_HUB_RST# for boards that have it; it is not defined in dt */
Tim Harvey552c3582014-03-06 07:46:30 -080044int board_ehci_hcd_init(int port)
45{
Tim Harveyf1f41db2015-05-08 18:28:28 -070046 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -080047
Tim Harvey1112b4e2021-03-01 14:33:34 -080048 /* USB HUB is always on P1 */
49 if (port == 0)
50 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -080051
Tim Harveydb7edfa2015-05-26 11:04:54 -070052 /* Reset USB HUB */
53 switch (board_type) {
54 case GW53xx:
55 case GW552x:
Tim Harveyb7c48a92019-02-04 13:10:54 -080056 case GW5906:
Tim Harveyf1f41db2015-05-08 18:28:28 -070057 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -080058 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -070059 case GW54proto:
60 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -070061 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -080062 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -070063 default:
64 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -080065 }
66
Tim Harveyf1f41db2015-05-08 18:28:28 -070067 /* request and toggle hub rst */
68 gpio_request(gpio, "usb_hub_rst#");
69 gpio_direction_output(gpio, 0);
70 mdelay(2);
71 gpio_set_value(gpio, 1);
72
Tim Harvey552c3582014-03-06 07:46:30 -080073 return 0;
74}
Tim Harvey552c3582014-03-06 07:46:30 -080075#endif /* CONFIG_USB_EHCI_MX6 */
76
Tim Harvey552c3582014-03-06 07:46:30 -080077/* configure eth0 PHY board-specific LED behavior */
78int board_phy_config(struct phy_device *phydev)
79{
80 unsigned short val;
81
82 /* Marvel 88E1510 */
83 if (phydev->phy_id == 0x1410dd1) {
84 /*
85 * Page 3, Register 16: LED[2:0] Function Control Register
86 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
87 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
88 */
89 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
90 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
91 val &= 0xff00;
92 val |= 0x0017;
93 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
94 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
95 }
96
Tim Harvey4533c902017-03-17 07:32:21 -070097 /* TI DP83867 */
98 else if (phydev->phy_id == 0x2000a231) {
Tim Harvey1662ad32021-06-11 12:46:25 -070099 /* LED configuration */
100 val = 0;
101 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
102 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
103 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
104
Tim Harvey4533c902017-03-17 07:32:21 -0700105 /* configure register 0x170 for ref CLKOUT */
106 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
107 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
108 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
109 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
110 val &= ~0x1f00;
111 val |= 0x0b00; /* chD tx clock*/
112 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
113 }
114
Tim Harvey552c3582014-03-06 07:46:30 -0800115 if (phydev->drv->config)
116 phydev->drv->config(phydev);
117
118 return 0;
119}
Tim Harvey63537792017-03-17 07:30:38 -0700120
121#ifdef CONFIG_MV88E61XX_SWITCH
122int mv88e61xx_hw_reset(struct phy_device *phydev)
123{
124 struct mii_dev *bus = phydev->bus;
125
126 /* GPIO[0] output, CLK125 */
127 debug("enabling RGMII_REFCLK\n");
128 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
129 0x1a /*MV_SCRATCH_MISC*/,
130 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
131 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
132 0x1a /*MV_SCRATCH_MISC*/,
133 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
134
135 /* RGMII delay - Physical Control register bit[15:14] */
136 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
137 /* forced 1000mbps full-duplex link */
138 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
139 phydev->autoneg = AUTONEG_DISABLE;
140 phydev->speed = SPEED_1000;
141 phydev->duplex = DUPLEX_FULL;
142
Tim Harvey8c9d3932019-02-04 13:10:47 -0800143 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
144 bus->write(bus, 0x10, 0, 0x16, 0x8088);
145 bus->write(bus, 0x11, 0, 0x16, 0x8088);
146 bus->write(bus, 0x12, 0, 0x16, 0x8088);
147 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700148
149 return 0;
150}
151#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800152
Tim Harveyfb64cc72014-04-25 15:39:07 -0700153#if defined(CONFIG_VIDEO_IPUV3)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700154static void enable_hdmi(struct display_info_t const *dev)
155{
156 imx_enable_hdmi_phy();
157}
158
159static int detect_i2c(struct display_info_t const *dev)
160{
161 return i2c_set_bus_num(dev->bus) == 0 &&
162 i2c_probe(dev->addr) == 0;
163}
164
165static void enable_lvds(struct display_info_t const *dev)
166{
167 struct iomuxc *iomux = (struct iomuxc *)
168 IOMUXC_BASE_ADDR;
169
170 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
171 u32 reg = readl(&iomux->gpr[2]);
172 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
173 writel(reg, &iomux->gpr[2]);
174
175 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700176 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
177 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700178 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700179 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700180 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
181}
182
183struct display_info_t const displays[] = {{
184 /* HDMI Output */
185 .bus = -1,
186 .addr = 0,
187 .pixfmt = IPU_PIX_FMT_RGB24,
188 .detect = detect_hdmi,
189 .enable = enable_hdmi,
190 .mode = {
191 .name = "HDMI",
192 .refresh = 60,
193 .xres = 1024,
194 .yres = 768,
195 .pixclock = 15385,
196 .left_margin = 220,
197 .right_margin = 40,
198 .upper_margin = 21,
199 .lower_margin = 7,
200 .hsync_len = 60,
201 .vsync_len = 10,
202 .sync = FB_SYNC_EXT,
203 .vmode = FB_VMODE_NONINTERLACED
204} }, {
205 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
206 .bus = 2,
207 .addr = 0x4,
208 .pixfmt = IPU_PIX_FMT_LVDS666,
209 .detect = detect_i2c,
210 .enable = enable_lvds,
211 .mode = {
212 .name = "Hannstar-XGA",
213 .refresh = 60,
214 .xres = 1024,
215 .yres = 768,
216 .pixclock = 15385,
217 .left_margin = 220,
218 .right_margin = 40,
219 .upper_margin = 21,
220 .lower_margin = 7,
221 .hsync_len = 60,
222 .vsync_len = 10,
223 .sync = FB_SYNC_EXT,
224 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700225} }, {
226 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800227 .bus = 2,
228 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700229 .detect = NULL,
230 .enable = enable_lvds,
231 .pixfmt = IPU_PIX_FMT_LVDS666,
232 .mode = {
233 .name = "DLC700JMGT4",
234 .refresh = 60,
235 .xres = 1024, /* 1024x600active pixels */
236 .yres = 600,
237 .pixclock = 15385, /* 64MHz */
238 .left_margin = 220,
239 .right_margin = 40,
240 .upper_margin = 21,
241 .lower_margin = 7,
242 .hsync_len = 60,
243 .vsync_len = 10,
244 .sync = FB_SYNC_EXT,
245 .vmode = FB_VMODE_NONINTERLACED
246} }, {
247 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800248 .bus = 2,
249 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700250 .detect = NULL,
251 .enable = enable_lvds,
252 .pixfmt = IPU_PIX_FMT_LVDS666,
253 .mode = {
254 .name = "DLC800FIGT3",
255 .refresh = 60,
256 .xres = 1024, /* 1024x768 active pixels */
257 .yres = 768,
258 .pixclock = 15385, /* 64MHz */
259 .left_margin = 220,
260 .right_margin = 40,
261 .upper_margin = 21,
262 .lower_margin = 7,
263 .hsync_len = 60,
264 .vsync_len = 10,
265 .sync = FB_SYNC_EXT,
266 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800267} }, {
268 .bus = 2,
269 .addr = 0x5d,
270 .detect = detect_i2c,
271 .enable = enable_lvds,
272 .pixfmt = IPU_PIX_FMT_LVDS666,
273 .mode = {
274 .name = "Z101WX01",
275 .refresh = 60,
276 .xres = 1280,
277 .yres = 800,
278 .pixclock = 15385, /* 64MHz */
279 .left_margin = 220,
280 .right_margin = 40,
281 .upper_margin = 21,
282 .lower_margin = 7,
283 .hsync_len = 60,
284 .vsync_len = 10,
285 .sync = FB_SYNC_EXT,
286 .vmode = FB_VMODE_NONINTERLACED
287 }
288},
289};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700290size_t display_count = ARRAY_SIZE(displays);
291
292static void setup_display(void)
293{
294 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
295 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
296 int reg;
297
298 enable_ipu_clock();
299 imx_setup_hdmi();
300 /* Turn on LDB0,IPU,IPU DI0 clocks */
301 reg = __raw_readl(&mxc_ccm->CCGR3);
302 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
303 writel(reg, &mxc_ccm->CCGR3);
304
305 /* set LDB0, LDB1 clk select to 011/011 */
306 reg = readl(&mxc_ccm->cs2cdr);
307 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
308 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
309 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
310 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
311 writel(reg, &mxc_ccm->cs2cdr);
312
313 reg = readl(&mxc_ccm->cscmr2);
314 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
315 writel(reg, &mxc_ccm->cscmr2);
316
317 reg = readl(&mxc_ccm->chsccdr);
318 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
319 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
320 writel(reg, &mxc_ccm->chsccdr);
321
322 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
323 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
324 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
325 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
326 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
327 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
328 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
329 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
330 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
331 writel(reg, &iomux->gpr[2]);
332
333 reg = readl(&iomux->gpr[3]);
334 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
335 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
336 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
337 writel(reg, &iomux->gpr[3]);
338
Tim Harveya67e07f2016-05-24 11:03:53 -0700339 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700340 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700341 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
342}
343#endif /* CONFIG_VIDEO_IPUV3 */
344
Tim Harvey0dff16f2014-05-05 08:22:25 -0700345/* setup board specific PMIC */
346int power_init_board(void)
347{
Tim Harvey195bc972015-05-08 18:28:37 -0700348 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700349 return 0;
350}
351
Tim Harvey552c3582014-03-06 07:46:30 -0800352int imx6_pcie_toggle_reset(void)
353{
354 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700355 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700356 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700357 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800358 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700359 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800360 }
361 return 0;
362}
Tim Harvey33791d52014-08-07 22:49:57 -0700363
364/*
365 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
366 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
367 * properly and assert reset for 100ms.
368 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700369#define MAX_PCI_DEVS 32
370struct pci_dev {
371 pci_dev_t devfn;
Tim Harvey6ce10d52021-05-03 11:21:27 -0700372 struct udevice *dev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700373 unsigned short vendor;
374 unsigned short device;
375 unsigned short class;
376 unsigned short busno; /* subbordinate busno */
377 struct pci_dev *ppar;
378};
379struct pci_dev pci_devs[MAX_PCI_DEVS];
380int pci_devno;
381int pci_bridgeno;
382
Tim Harvey6ce10d52021-05-03 11:21:27 -0700383void board_pci_fixup_dev(struct udevice *bus, struct udevice *udev)
Tim Harvey33791d52014-08-07 22:49:57 -0700384{
Tim Harvey6ce10d52021-05-03 11:21:27 -0700385 struct pci_child_plat *pdata = dev_get_parent_plat(udev);
Tim Harveybfb240a2016-06-17 06:10:41 -0700386 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey6ce10d52021-05-03 11:21:27 -0700387 unsigned short vendor = pdata->vendor;
388 unsigned short device = pdata->device;
389 unsigned int class = pdata->class;
390 pci_dev_t dev = dm_pci_get_bdf(udev);
391 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700392
393 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
394 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700395
396 /* store array of devs for later use in device-tree fixup */
Tim Harvey6ce10d52021-05-03 11:21:27 -0700397 pdev->dev = udev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700398 pdev->devfn = dev;
399 pdev->vendor = vendor;
400 pdev->device = device;
401 pdev->class = class;
402 pdev->ppar = NULL;
403 if (class == PCI_CLASS_BRIDGE_PCI)
404 pdev->busno = ++pci_bridgeno;
405 else
406 pdev->busno = 0;
407
408 /* fixup RC - it should be 00:00.0 not 00:01.0 */
409 if (PCI_BUS(dev) == 0)
410 pdev->devfn = 0;
411
412 /* find dev's parent */
413 for (i = 0; i < pci_devno; i++) {
414 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
415 pdev->ppar = &pci_devs[i];
416 break;
417 }
418 }
419
420 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700421 if (vendor == PCI_VENDOR_ID_PLX &&
422 (device & 0xfff0) == 0x8600 &&
423 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
Tim Harvey6ce10d52021-05-03 11:21:27 -0700424 ulong val;
Tim Harvey33791d52014-08-07 22:49:57 -0700425 debug("configuring PLX 860X downstream PERST#\n");
Tim Harvey6ce10d52021-05-03 11:21:27 -0700426 pci_bus_read_config(bus, dev, 0x62c, &val, PCI_SIZE_32);
427 val |= 0xaaa8; /* GPIO1-7 outputs */
428 pci_bus_write_config(bus, dev, 0x62c, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700429
Tim Harvey6ce10d52021-05-03 11:21:27 -0700430 pci_bus_read_config(bus, dev, 0x644, &val, PCI_SIZE_32);
431 val |= 0xfe; /* GPIO1-7 output high */
432 pci_bus_write_config(bus, dev, 0x644, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700433
434 mdelay(100);
435 }
436}
Tim Harvey552c3582014-03-06 07:46:30 -0800437
438#ifdef CONFIG_SERIAL_TAG
439/*
440 * called when setting up ATAGS before booting kernel
441 * populate serialnum from the following (in order of priority):
442 * serial# env var
443 * eeprom
444 */
445void get_board_serial(struct tag_serialnr *serialnr)
446{
Simon Glass64b723f2017-08-03 12:22:12 -0600447 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800448
449 if (serial) {
450 serialnr->high = 0;
451 serialnr->low = simple_strtoul(serial, NULL, 10);
452 } else if (ventana_info.model[0]) {
453 serialnr->high = 0;
454 serialnr->low = ventana_info.serial;
455 } else {
456 serialnr->high = 0;
457 serialnr->low = 0;
458 }
459}
460#endif
461
462/*
463 * Board Support
464 */
465
466int board_early_init_f(void)
467{
Tim Harveyfb64cc72014-04-25 15:39:07 -0700468#if defined(CONFIG_VIDEO_IPUV3)
469 setup_display();
470#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800471 return 0;
472}
473
474int dram_init(void)
475{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700476 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800477 return 0;
478}
479
480int board_init(void)
481{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300482 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800483
484 clrsetbits_le32(&iomuxc_regs->gpr[1],
485 IOMUXC_GPR1_OTG_ID_MASK,
486 IOMUXC_GPR1_OTG_ID_GPIO1);
487
488 /* address of linux boot parameters */
489 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
490
Tim Harveyba9f2342019-02-04 13:10:52 -0800491 /* read Gateworks EEPROM into global struct (used later) */
492 setup_ventana_i2c(0);
493 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
494
Tim Harveyd04dc812019-02-04 13:10:49 -0800495 setup_ventana_i2c(1);
496 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800497
Tim Harvey0cee2242015-05-08 18:28:35 -0700498 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800499
500 return 0;
501}
502
Tim Harvey948202c2021-03-01 14:33:32 -0800503int board_fit_config_name_match(const char *name)
504{
505 static char init;
506 const char *dtb;
507 char buf[32];
508 int i = 0;
509
510 do {
511 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
512 if (dtb && !strcmp(dtb, name)) {
513 if (!init++)
514 printf("DTB: %s\n", name);
515 return 0;
516 }
517 } while (dtb);
518
519 return -1;
520}
521
Tim Harvey552c3582014-03-06 07:46:30 -0800522#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
523/*
524 * called during late init (after relocation and after board_init())
525 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
526 * EEPROM read.
527 */
528int checkboard(void)
529{
530 struct ventana_board_info *info = &ventana_info;
531 unsigned char buf[4];
532 const char *p;
533 int quiet; /* Quiet or minimal output mode */
534
535 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600536 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800537 if (p)
538 quiet = simple_strtol(p, NULL, 10);
539 else
Simon Glass6a38e412017-08-03 12:22:09 -0600540 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800541
542 puts("\nGateworks Corporation Copyright 2014\n");
543 if (info->model[0]) {
544 printf("Model: %s\n", info->model);
545 printf("MFGDate: %02x-%02x-%02x%02x\n",
546 info->mfgdate[0], info->mfgdate[1],
547 info->mfgdate[2], info->mfgdate[3]);
548 printf("Serial:%d\n", info->serial);
549 } else {
550 puts("Invalid EEPROM - board will not function fully\n");
551 }
552 if (quiet)
553 return 0;
554
555 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700556 gsc_info(0);
557
Tim Harvey552c3582014-03-06 07:46:30 -0800558 /* Display RTC */
559 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
560 printf("RTC: %d\n",
561 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
562 }
563
564 return 0;
565}
566#endif
567
568#ifdef CONFIG_CMD_BMODE
569/*
570 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
571 * see Table 8-11 and Table 5-9
572 * BOOT_CFG1[7] = 1 (boot from NAND)
573 * BOOT_CFG1[5] = 0 - raw NAND
574 * BOOT_CFG1[4] = 0 - default pad settings
575 * BOOT_CFG1[3:2] = 00 - devices = 1
576 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
577 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
578 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
579 * BOOT_CFG2[0] = 0 - Reset time 12ms
580 */
581static const struct boot_mode board_boot_modes[] = {
582 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
583 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700584 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800585 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800586 { NULL, 0 },
587};
588#endif
589
590/* late init */
591int misc_init_r(void)
592{
593 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700594 char buf[256];
595 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800596
597 /* set env vars based on EEPROM data */
598 if (ventana_info.model[0]) {
599 char str[16], fdt[36];
600 char *p;
601 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800602
603 /*
604 * FDT name will be prefixed with CPU type. Three versions
605 * will be created each increasingly generic and bootloader
606 * env scripts will try loading each from most specific to
607 * least.
608 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700609 if (is_cpu_type(MXC_CPU_MX6Q) ||
610 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800611 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700612 else if (is_cpu_type(MXC_CPU_MX6DL) ||
613 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800614 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600615 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700616 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600617 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700618 else
Simon Glass6a38e412017-08-03 12:22:09 -0600619 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800620 memset(str, 0, sizeof(str));
621 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
622 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600623 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600624 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800625 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600626 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800627 }
628 p = strchr(str, '-');
629 if (p) {
630 *p++ = 0;
631
Simon Glass6a38e412017-08-03 12:22:09 -0600632 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700633 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600634 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700635 if (board_type != GW551x &&
636 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700637 board_type != GW553x &&
638 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700639 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800640 str[5] = 'x';
641 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700642 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600643 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800644 }
645
646 /* initialize env from EEPROM */
647 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600648 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600649 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800650 }
651 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600652 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600653 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800654 }
655
656 /* board serial-number */
657 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600658 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700659
660 /* memory MB */
661 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600662 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800663 }
664
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700665 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600666 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700667 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700668 if (gpio_cfg[board_type].rs232_en)
669 strcat(buf, "rs232;");
670 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
671 char buf1[32];
672 sprintf(buf1, "dio%d:mode=gpio;", i);
673 if (strlen(buf) + strlen(buf1) < sizeof(buf))
674 strcat(buf, buf1);
675 }
Simon Glass6a38e412017-08-03 12:22:09 -0600676 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700677 }
Tim Harvey552c3582014-03-06 07:46:30 -0800678
Tim Harvey0cee2242015-05-08 18:28:35 -0700679 /* setup baseboard specific GPIO based on board and env */
680 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800681
682#ifdef CONFIG_CMD_BMODE
683 add_board_boot_modes(board_boot_modes);
684#endif
685
Tim Harvey40feabb2015-05-08 18:28:36 -0700686 /* disable boot watchdog */
687 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800688
689 return 0;
690}
691
Robert P. J. Day3c757002016-05-19 15:23:12 -0400692#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800693
Tim Harveycf20e552015-04-08 12:55:01 -0700694static int ft_sethdmiinfmt(void *blob, char *mode)
695{
696 int off;
697
698 if (!mode)
699 return -EINVAL;
700
701 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
702 if (off < 0)
703 return off;
704
705 if (0 == strcasecmp(mode, "yuv422bt656")) {
706 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
707 0x00, 0x00, 0x00 };
708 mode = "422_ccir";
709 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
710 fdt_setprop_u32(blob, off, "vidout_trc", 1);
711 fdt_setprop_u32(blob, off, "vidout_blc", 1);
712 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
713 printf(" set HDMI input mode to %s\n", mode);
714 } else if (0 == strcasecmp(mode, "yuv422smp")) {
715 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
716 0x82, 0x81, 0x00 };
717 mode = "422_smp";
718 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
719 fdt_setprop_u32(blob, off, "vidout_trc", 0);
720 fdt_setprop_u32(blob, off, "vidout_blc", 0);
721 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
722 printf(" set HDMI input mode to %s\n", mode);
723 } else {
724 return -EINVAL;
725 }
726
727 return 0;
728}
729
Tim Harveybfb240a2016-06-17 06:10:41 -0700730#if defined(CONFIG_CMD_PCI)
731#define PCI_ID(x) ( \
732 (PCI_BUS(x->devfn)<<16)| \
733 (PCI_DEV(x->devfn)<<11)| \
734 (PCI_FUNC(x->devfn)<<8) \
735 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700736int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
737{
738 uint32_t reg[5];
739 char node[32];
740 int np;
741
742 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
743 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
744
745 np = fdt_subnode_offset(blob, par, node);
746 if (np >= 0)
747 return np;
748 np = fdt_add_subnode(blob, par, node);
749 if (np < 0) {
750 printf(" %s failed: no space\n", __func__);
751 return np;
752 }
753
754 memset(reg, 0, sizeof(reg));
755 reg[0] = cpu_to_fdt32(PCI_ID(dev));
756 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
757
758 return np;
759}
760
761/* build a path of nested PCI devs for all bridges passed through */
762int fdt_add_pci_path(void *blob, struct pci_dev *dev)
763{
764 struct pci_dev *bridges[MAX_PCI_DEVS];
765 int k, np;
766
767 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800768 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700769 if (np < 0)
770 return np;
771
772 k = 0;
773 while (dev) {
774 bridges[k++] = dev;
775 dev = dev->ppar;
776 };
777
778 /* now add them the to DT in reverse order */
779 while (k--) {
780 np = fdt_add_pci_node(blob, np, bridges[k]);
781 if (np < 0)
782 break;
783 }
784
785 return np;
786}
787
788/*
789 * The GW16082 has a hardware errata errata such that it's
790 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
791 * of this normal PCI interrupt swizzling will not work so we will
792 * provide an irq-map via device-tree.
793 */
794int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
795{
796 int len;
797 int host;
798 uint32_t imap_new[8*4*4];
799 const uint32_t *imap;
800 uint32_t irq[4];
801 uint32_t reg[4];
802 int i;
803
804 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800805 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700806 if (host < 0) {
807 printf(" %s failed: missing host\n", __func__);
808 return host;
809 }
810
811 /* use interrupt data from root complex's node */
812 imap = fdt_getprop(blob, host, "interrupt-map", &len);
813 if (!imap || len != 128) {
814 printf(" %s failed: invalid interrupt-map\n",
815 __func__);
816 return -FDT_ERR_NOTFOUND;
817 }
818
819 /* obtain irq's of host controller in pin order */
820 for (i = 0; i < 4; i++)
821 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
822
823 /*
824 * determine number of swizzles necessary:
825 * For each bridge we pass through we need to swizzle
826 * the number of the slot we are on.
827 */
828 struct pci_dev *d;
829 int b;
830 b = 0;
831 d = dev->ppar;
832 while(d && d->ppar) {
833 b += PCI_DEV(d->devfn);
834 d = d->ppar;
835 }
836
837 /* create new irq mappings for slots12-15
838 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
839 * J3 AD28 12 INTD INTA
840 * J4 AD29 13 INTC INTD
841 * J5 AD30 14 INTB INTC
842 * J2 AD31 15 INTA INTB
843 */
844 for (i = 0; i < 4; i++) {
845 /* addr matches bus:dev:func */
846 u32 addr = dev->busno << 16 | (12+i) << 11;
847
848 /* default cells from root complex */
849 memcpy(&imap_new[i*32], imap, 128);
850 /* first cell is PCI device address (BDF) */
851 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
852 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
853 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
854 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
855 /* third cell is pin */
856 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
857 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
858 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
859 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
860 /* sixth cell is relative interrupt */
861 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
862 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
863 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
864 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
865 }
866 fdt_setprop(blob, np, "interrupt-map", imap_new,
867 sizeof(imap_new));
868 reg[0] = cpu_to_fdt32(0xfff00);
869 reg[1] = 0;
870 reg[2] = 0;
871 reg[3] = cpu_to_fdt32(0x7);
872 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
873 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
874 fdt_setprop_string(blob, np, "device_type", "pci");
875 fdt_setprop_cell(blob, np, "#address-cells", 3);
876 fdt_setprop_cell(blob, np, "#size-cells", 2);
877 printf(" Added custom interrupt-map for GW16082\n");
878
879 return 0;
880}
881
Tim Harvey77b82a12016-06-17 06:10:42 -0700882/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
883int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
884{
885 char *tmp, *end;
886 char mac[16];
887 unsigned char mac_addr[6];
888 int j;
889
890 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -0600891 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -0700892 if (tmp) {
893 for (j = 0; j < 6; j++) {
894 mac_addr[j] = tmp ?
895 simple_strtoul(tmp, &end,16) : 0;
896 if (tmp)
897 tmp = (*end) ? end+1 : end;
898 }
899 fdt_setprop(blob, np, "local-mac-address", mac_addr,
900 sizeof(mac_addr));
901 printf(" Added mac addr for eth1\n");
902 return 0;
903 }
904
905 return -1;
906}
907
Tim Harveybfb240a2016-06-17 06:10:41 -0700908/*
909 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
910 * we will walk the PCI bus and add bridge nodes up to the device receiving
911 * the fixup.
912 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900913void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -0700914{
915 int i, np;
916 struct pci_dev *dev;
917
918 for (i = 0; i < pci_devno; i++) {
919 dev = &pci_devs[i];
920
921 /*
922 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
923 * an EEPROM at i2c1-0x50.
924 */
925 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
926 (dev->device == 0x8240) &&
927 (i2c_set_bus_num(1) == 0) &&
928 (i2c_probe(0x50) == 0))
929 {
930 np = fdt_add_pci_path(blob, dev);
931 if (np > 0)
932 fdt_fixup_gw16082(blob, np, dev);
933 }
Tim Harvey77b82a12016-06-17 06:10:42 -0700934
935 /* ethernet1 mac address */
936 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
937 (dev->device == 0x4380))
938 {
939 np = fdt_add_pci_path(blob, dev);
940 if (np > 0)
941 fdt_fixup_sky2(blob, np, dev);
942 }
Tim Harveybfb240a2016-06-17 06:10:41 -0700943 }
944}
945#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -0700946
Tim Harvey984aa0d2019-02-04 13:11:00 -0800947void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
Tim Harveyfcabb0b2017-05-15 10:05:07 -0700948{
Tim Harvey984aa0d2019-02-04 13:11:00 -0800949 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
950
951 if (off) {
952 fdt_delprop(blob, off, "ext-reset-output");
953 fdt_delprop(blob, off, "fsl,ext-reset-output");
954 }
Tim Harveyfcabb0b2017-05-15 10:05:07 -0700955}
956
Tim Harvey552c3582014-03-06 07:46:30 -0800957/*
958 * called prior to booting kernel or by 'fdt boardsetup' command
959 *
960 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
961 * - mtd partitions based on mtdparts/mtdids env
962 * - system-serial (board serial num from EEPROM)
963 * - board (full model from EEPROM)
964 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
965 */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800966#define WDOG1_ADDR 0x20bc000
967#define WDOG2_ADDR 0x20c0000
968#define GPIO3_ADDR 0x20a4000
969#define USDHC3_ADDR 0x2198000
970#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900971int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -0800972{
Tim Harvey552c3582014-03-06 07:46:30 -0800973 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -0700974 struct ventana_eeprom_config *cfg;
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900975 static const struct node_info nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -0800976 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
977 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
978 };
Simon Glass64b723f2017-08-03 12:22:12 -0600979 const char *model = env_get("model");
980 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -0700981 int i;
982 char rev = 0;
983
984 /* determine board revision */
985 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
986 if (ventana_info.model[i] >= 'A') {
987 rev = ventana_info.model[i];
988 break;
989 }
990 }
Tim Harvey552c3582014-03-06 07:46:30 -0800991
Simon Glass64b723f2017-08-03 12:22:12 -0600992 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800993 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -0600994 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800995 }
996
Tim Harveyc9e43e02015-05-26 11:04:58 -0700997 if (test_bit(EECONFIG_NAND, info->config)) {
998 /* Update partition nodes using info from mtdparts env var */
999 puts(" Updating MTD partitions...\n");
1000 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1001 }
Tim Harvey552c3582014-03-06 07:46:30 -08001002
Tim Harveye4af5d32015-04-08 12:54:58 -07001003 /* Update display timings from display env var */
1004 if (display) {
1005 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1006 display) >= 0)
1007 printf(" Set display timings for %s...\n", display);
1008 }
1009
Tim Harvey552c3582014-03-06 07:46:30 -08001010 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1011
1012 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001013 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1014 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001015
1016 /* board (model contains model from device-tree) */
1017 fdt_setprop(blob, 0, "board", info->model,
1018 strlen((const char *)info->model) + 1);
1019
Tim Harveycf20e552015-04-08 12:55:01 -07001020 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001021 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001022
Tim Harvey552c3582014-03-06 07:46:30 -08001023 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001024 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001025 */
Tim Harveya1d32222016-07-15 07:16:28 -07001026 switch (board_type) {
1027 case GW51xx:
1028 /*
1029 * disable wdog node for GW51xx-A/B to work around
1030 * errata causing wdog timer to be unreliable.
1031 */
1032 if (rev >= 'A' && rev < 'C') {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001033 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1034 WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001035 if (i)
1036 fdt_status_disabled(blob, i);
1037 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001038
1039 /* GW51xx-E adds WDOG1_B external reset */
1040 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001041 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001042 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001043
Tim Harveya1d32222016-07-15 07:16:28 -07001044 case GW52xx:
1045 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1046 if (info->model[4] == '2') {
1047 u32 handle = 0;
1048 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001049
Tim Harveya1d32222016-07-15 07:16:28 -07001050 i = fdt_node_offset_by_compatible(blob, -1,
1051 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001052 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001053 range = (u32 *)fdt_getprop(blob, i,
1054 "reset-gpio", NULL);
1055
1056 if (range) {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001057 i = fdt_node_offset_by_compat_reg(blob,
1058 "fsl,imx6q-gpio", GPIO3_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001059 if (i)
1060 handle = fdt_get_phandle(blob, i);
1061 if (handle) {
1062 range[0] = cpu_to_fdt32(handle);
1063 range[1] = cpu_to_fdt32(23);
1064 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001065 }
Tim Harveya1d32222016-07-15 07:16:28 -07001066
1067 /* these have broken usd_vsel */
1068 if (strstr((const char *)info->model, "SP318-B") ||
1069 strstr((const char *)info->model, "SP331-B"))
1070 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001071
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001072 /* GW522x-B adds WDOG1_B external reset */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001073 if (rev < 'B')
1074 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Pushpal Sidhud1100562015-04-08 12:55:00 -07001075 }
Tim Harveydc5996a2017-05-15 10:05:06 -07001076
1077 /* GW520x-E adds WDOG1_B external reset */
1078 else if (info->model[4] == '0' && rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001079 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001080 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001081
Tim Harveya1d32222016-07-15 07:16:28 -07001082 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001083 /* GW53xx-E adds WDOG1_B external reset */
1084 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001085 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001086 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001087
Tim Harveya1d32222016-07-15 07:16:28 -07001088 case GW54xx:
1089 /*
1090 * disable serial2 node for GW54xx for compatibility with older
1091 * 3.10.x kernel that improperly had this node enabled in the DT
1092 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001093 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1094 0);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001095
1096 /* GW54xx-E adds WDOG2_B external reset */
1097 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001098 ft_board_wdog_fixup(blob, WDOG2_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001099 break;
1100
1101 case GW551x:
1102 /*
1103 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1104 * causing non functional digital video in (it is not hooked up)
1105 */
1106 if (rev == 'A') {
1107 u32 *range = NULL;
1108 int len;
1109 const u32 *handle = NULL;
1110
1111 i = fdt_node_offset_by_compatible(blob, -1,
1112 "fsl,imx-tda1997x-video");
1113 if (i)
1114 handle = fdt_getprop(blob, i, "pinctrl-0",
1115 NULL);
1116 if (handle)
1117 i = fdt_node_offset_by_phandle(blob,
1118 fdt32_to_cpu(*handle));
1119 if (i)
1120 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1121 &len);
1122 if (range) {
1123 len /= sizeof(u32);
1124 for (i = 0; i < len; i += 6) {
1125 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1126 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1127 /* mux PAD_CSI0_DATA_EN to GPIO */
1128 if (is_cpu_type(MXC_CPU_MX6Q) &&
1129 mux_reg == 0x260 &&
1130 conf_reg == 0x630)
1131 range[i+3] = cpu_to_fdt32(0x5);
1132 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1133 mux_reg == 0x08c &&
1134 conf_reg == 0x3a0)
1135 range[i+3] = cpu_to_fdt32(0x5);
1136 }
1137 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1138 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001139 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001140
Tim Harveya1d32222016-07-15 07:16:28 -07001141 /* set BT656 video format */
1142 ft_sethdmiinfmt(blob, "yuv422bt656");
1143 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001144
1145 /* GW551x-C adds WDOG1_B external reset */
1146 if (rev < 'C')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001147 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001148 break;
Tim Harvey5852a332019-02-04 13:10:58 -08001149 case GW5901:
1150 case GW5902:
1151 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1152 if (rev < 'B')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001153 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harvey5852a332019-02-04 13:10:58 -08001154 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001155 }
1156
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001157 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001158 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001159 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1160 char arg[10];
1161
1162 sprintf(arg, "dio%d", i);
1163 if (!hwconfig(arg))
1164 continue;
1165 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1166 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001167 phys_addr_t addr;
1168 int off;
1169
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001170 printf(" Enabling pwm%d for DIO%d\n",
1171 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001172 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1173 off = fdt_node_offset_by_compat_reg(blob,
1174 "fsl,imx6q-pwm",
1175 addr);
1176 if (off)
1177 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001178 }
1179 }
1180
Tim Harvey147b5762016-05-24 11:03:59 -07001181 /* remove no-1-8-v if UHS-I support is present */
1182 if (gpio_cfg[board_type].usd_vsel) {
1183 debug("Enabling UHS-I support\n");
Tim Harvey984aa0d2019-02-04 13:11:00 -08001184 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1185 USDHC3_ADDR);
1186 if (i)
1187 fdt_delprop(blob, i, "no-1-8-v");
Tim Harvey147b5762016-05-24 11:03:59 -07001188 }
1189
Tim Harveybfb240a2016-06-17 06:10:41 -07001190#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001191 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001192 ft_board_pci_fixup(blob, bd);
1193#endif
1194
Tim Harvey6944ccf2015-04-08 12:54:53 -07001195 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001196 * Peripheral Config:
1197 * remove nodes by alias path if EEPROM config tells us the
1198 * peripheral is not loaded on the board.
1199 */
Simon Glass64b723f2017-08-03 12:22:12 -06001200 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001201 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001202 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001203 }
1204 cfg = econfig;
1205 while (cfg->name) {
1206 if (!test_bit(cfg->bit, info->config)) {
1207 fdt_del_node_and_alias(blob, cfg->dtalias ?
1208 cfg->dtalias : cfg->name);
1209 }
1210 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001211 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001212
1213 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001214}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001215#endif /* CONFIG_OF_BOARD_SETUP */