blob: 16468060f759c33bfa4ec8d20c843e414e4e7637 [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) {
Tim Harveyb25b7582021-06-11 12:46:26 -070084 puts("MV88E1510");
Tim Harvey552c3582014-03-06 07:46:30 -080085 /*
86 * Page 3, Register 16: LED[2:0] Function Control Register
87 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
88 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
89 */
90 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
91 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
92 val &= 0xff00;
93 val |= 0x0017;
94 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
95 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
96 }
97
Tim Harvey4533c902017-03-17 07:32:21 -070098 /* TI DP83867 */
99 else if (phydev->phy_id == 0x2000a231) {
Tim Harveyb25b7582021-06-11 12:46:26 -0700100 puts("TIDP83867 ");
Tim Harvey1662ad32021-06-11 12:46:25 -0700101 /* LED configuration */
102 val = 0;
103 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
104 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
105 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
106
Tim Harvey4533c902017-03-17 07:32:21 -0700107 /* configure register 0x170 for ref CLKOUT */
108 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
109 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
110 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
111 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
112 val &= ~0x1f00;
113 val |= 0x0b00; /* chD tx clock*/
114 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
115 }
116
Tim Harvey552c3582014-03-06 07:46:30 -0800117 if (phydev->drv->config)
118 phydev->drv->config(phydev);
119
120 return 0;
121}
Tim Harvey63537792017-03-17 07:30:38 -0700122
123#ifdef CONFIG_MV88E61XX_SWITCH
124int mv88e61xx_hw_reset(struct phy_device *phydev)
125{
126 struct mii_dev *bus = phydev->bus;
127
128 /* GPIO[0] output, CLK125 */
129 debug("enabling RGMII_REFCLK\n");
130 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
131 0x1a /*MV_SCRATCH_MISC*/,
132 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
133 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
134 0x1a /*MV_SCRATCH_MISC*/,
135 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
136
137 /* RGMII delay - Physical Control register bit[15:14] */
138 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
139 /* forced 1000mbps full-duplex link */
140 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
141 phydev->autoneg = AUTONEG_DISABLE;
142 phydev->speed = SPEED_1000;
143 phydev->duplex = DUPLEX_FULL;
144
Tim Harvey8c9d3932019-02-04 13:10:47 -0800145 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
146 bus->write(bus, 0x10, 0, 0x16, 0x8088);
147 bus->write(bus, 0x11, 0, 0x16, 0x8088);
148 bus->write(bus, 0x12, 0, 0x16, 0x8088);
149 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700150
151 return 0;
152}
153#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800154
Tim Harveyfb64cc72014-04-25 15:39:07 -0700155#if defined(CONFIG_VIDEO_IPUV3)
Tim Harveyfb64cc72014-04-25 15:39:07 -0700156static void enable_hdmi(struct display_info_t const *dev)
157{
158 imx_enable_hdmi_phy();
159}
160
161static int detect_i2c(struct display_info_t const *dev)
162{
163 return i2c_set_bus_num(dev->bus) == 0 &&
164 i2c_probe(dev->addr) == 0;
165}
166
167static void enable_lvds(struct display_info_t const *dev)
168{
169 struct iomuxc *iomux = (struct iomuxc *)
170 IOMUXC_BASE_ADDR;
171
172 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
173 u32 reg = readl(&iomux->gpr[2]);
174 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
175 writel(reg, &iomux->gpr[2]);
176
177 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700178 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
179 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700180 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700181 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700182 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
183}
184
185struct display_info_t const displays[] = {{
186 /* HDMI Output */
187 .bus = -1,
188 .addr = 0,
189 .pixfmt = IPU_PIX_FMT_RGB24,
190 .detect = detect_hdmi,
191 .enable = enable_hdmi,
192 .mode = {
193 .name = "HDMI",
194 .refresh = 60,
195 .xres = 1024,
196 .yres = 768,
197 .pixclock = 15385,
198 .left_margin = 220,
199 .right_margin = 40,
200 .upper_margin = 21,
201 .lower_margin = 7,
202 .hsync_len = 60,
203 .vsync_len = 10,
204 .sync = FB_SYNC_EXT,
205 .vmode = FB_VMODE_NONINTERLACED
206} }, {
207 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
208 .bus = 2,
209 .addr = 0x4,
210 .pixfmt = IPU_PIX_FMT_LVDS666,
211 .detect = detect_i2c,
212 .enable = enable_lvds,
213 .mode = {
214 .name = "Hannstar-XGA",
215 .refresh = 60,
216 .xres = 1024,
217 .yres = 768,
218 .pixclock = 15385,
219 .left_margin = 220,
220 .right_margin = 40,
221 .upper_margin = 21,
222 .lower_margin = 7,
223 .hsync_len = 60,
224 .vsync_len = 10,
225 .sync = FB_SYNC_EXT,
226 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700227} }, {
228 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800229 .bus = 2,
230 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700231 .detect = NULL,
232 .enable = enable_lvds,
233 .pixfmt = IPU_PIX_FMT_LVDS666,
234 .mode = {
235 .name = "DLC700JMGT4",
236 .refresh = 60,
237 .xres = 1024, /* 1024x600active pixels */
238 .yres = 600,
239 .pixclock = 15385, /* 64MHz */
240 .left_margin = 220,
241 .right_margin = 40,
242 .upper_margin = 21,
243 .lower_margin = 7,
244 .hsync_len = 60,
245 .vsync_len = 10,
246 .sync = FB_SYNC_EXT,
247 .vmode = FB_VMODE_NONINTERLACED
248} }, {
Tim Harvey87a86452021-06-11 12:46:27 -0700249 /* DLC0700XDP21LF-C-1 */
250 .bus = 0,
251 .addr = 0,
252 .detect = NULL,
253 .enable = enable_lvds,
254 .pixfmt = IPU_PIX_FMT_LVDS666,
255 .mode = {
256 .name = "DLC0700XDP21LF",
257 .refresh = 60,
258 .xres = 1024, /* 1024x600active pixels */
259 .yres = 600,
260 .pixclock = 15385, /* 64MHz */
261 .left_margin = 220,
262 .right_margin = 40,
263 .upper_margin = 21,
264 .lower_margin = 7,
265 .hsync_len = 60,
266 .vsync_len = 10,
267 .sync = FB_SYNC_EXT,
268 .vmode = FB_VMODE_NONINTERLACED
269} }, {
Tim Harveya20bd632015-04-08 12:54:57 -0700270 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800271 .bus = 2,
272 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700273 .detect = NULL,
274 .enable = enable_lvds,
275 .pixfmt = IPU_PIX_FMT_LVDS666,
276 .mode = {
277 .name = "DLC800FIGT3",
278 .refresh = 60,
279 .xres = 1024, /* 1024x768 active pixels */
280 .yres = 768,
281 .pixclock = 15385, /* 64MHz */
282 .left_margin = 220,
283 .right_margin = 40,
284 .upper_margin = 21,
285 .lower_margin = 7,
286 .hsync_len = 60,
287 .vsync_len = 10,
288 .sync = FB_SYNC_EXT,
289 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800290} }, {
291 .bus = 2,
292 .addr = 0x5d,
293 .detect = detect_i2c,
294 .enable = enable_lvds,
295 .pixfmt = IPU_PIX_FMT_LVDS666,
296 .mode = {
297 .name = "Z101WX01",
298 .refresh = 60,
299 .xres = 1280,
300 .yres = 800,
301 .pixclock = 15385, /* 64MHz */
302 .left_margin = 220,
303 .right_margin = 40,
304 .upper_margin = 21,
305 .lower_margin = 7,
306 .hsync_len = 60,
307 .vsync_len = 10,
308 .sync = FB_SYNC_EXT,
309 .vmode = FB_VMODE_NONINTERLACED
310 }
311},
312};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700313size_t display_count = ARRAY_SIZE(displays);
314
315static void setup_display(void)
316{
317 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
318 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
319 int reg;
320
321 enable_ipu_clock();
322 imx_setup_hdmi();
323 /* Turn on LDB0,IPU,IPU DI0 clocks */
324 reg = __raw_readl(&mxc_ccm->CCGR3);
325 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
326 writel(reg, &mxc_ccm->CCGR3);
327
328 /* set LDB0, LDB1 clk select to 011/011 */
329 reg = readl(&mxc_ccm->cs2cdr);
330 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
331 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
332 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
333 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
334 writel(reg, &mxc_ccm->cs2cdr);
335
336 reg = readl(&mxc_ccm->cscmr2);
337 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
338 writel(reg, &mxc_ccm->cscmr2);
339
340 reg = readl(&mxc_ccm->chsccdr);
341 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
342 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
343 writel(reg, &mxc_ccm->chsccdr);
344
345 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
346 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
347 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
348 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
349 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
350 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
351 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
352 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
353 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
354 writel(reg, &iomux->gpr[2]);
355
356 reg = readl(&iomux->gpr[3]);
357 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
358 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
359 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
360 writel(reg, &iomux->gpr[3]);
361
Tim Harveya67e07f2016-05-24 11:03:53 -0700362 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700363 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700364 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
365}
366#endif /* CONFIG_VIDEO_IPUV3 */
367
Tim Harvey0dff16f2014-05-05 08:22:25 -0700368/* setup board specific PMIC */
369int power_init_board(void)
370{
Tim Harvey195bc972015-05-08 18:28:37 -0700371 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700372 return 0;
373}
374
Tim Harvey33791d52014-08-07 22:49:57 -0700375/*
376 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
377 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
378 * properly and assert reset for 100ms.
379 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700380#define MAX_PCI_DEVS 32
381struct pci_dev {
382 pci_dev_t devfn;
Tim Harvey6ce10d52021-05-03 11:21:27 -0700383 struct udevice *dev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700384 unsigned short vendor;
385 unsigned short device;
386 unsigned short class;
387 unsigned short busno; /* subbordinate busno */
388 struct pci_dev *ppar;
389};
390struct pci_dev pci_devs[MAX_PCI_DEVS];
391int pci_devno;
392int pci_bridgeno;
393
Tim Harvey6ce10d52021-05-03 11:21:27 -0700394void board_pci_fixup_dev(struct udevice *bus, struct udevice *udev)
Tim Harvey33791d52014-08-07 22:49:57 -0700395{
Tim Harvey6ce10d52021-05-03 11:21:27 -0700396 struct pci_child_plat *pdata = dev_get_parent_plat(udev);
Tim Harveybfb240a2016-06-17 06:10:41 -0700397 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey6ce10d52021-05-03 11:21:27 -0700398 unsigned short vendor = pdata->vendor;
399 unsigned short device = pdata->device;
400 unsigned int class = pdata->class;
401 pci_dev_t dev = dm_pci_get_bdf(udev);
402 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700403
404 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
405 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700406
407 /* store array of devs for later use in device-tree fixup */
Tim Harvey6ce10d52021-05-03 11:21:27 -0700408 pdev->dev = udev;
Tim Harveybfb240a2016-06-17 06:10:41 -0700409 pdev->devfn = dev;
410 pdev->vendor = vendor;
411 pdev->device = device;
412 pdev->class = class;
413 pdev->ppar = NULL;
414 if (class == PCI_CLASS_BRIDGE_PCI)
415 pdev->busno = ++pci_bridgeno;
416 else
417 pdev->busno = 0;
418
419 /* fixup RC - it should be 00:00.0 not 00:01.0 */
420 if (PCI_BUS(dev) == 0)
421 pdev->devfn = 0;
422
423 /* find dev's parent */
424 for (i = 0; i < pci_devno; i++) {
425 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
426 pdev->ppar = &pci_devs[i];
427 break;
428 }
429 }
430
431 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700432 if (vendor == PCI_VENDOR_ID_PLX &&
433 (device & 0xfff0) == 0x8600 &&
434 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
Tim Harvey6ce10d52021-05-03 11:21:27 -0700435 ulong val;
Tim Harvey33791d52014-08-07 22:49:57 -0700436 debug("configuring PLX 860X downstream PERST#\n");
Tim Harvey6ce10d52021-05-03 11:21:27 -0700437 pci_bus_read_config(bus, dev, 0x62c, &val, PCI_SIZE_32);
438 val |= 0xaaa8; /* GPIO1-7 outputs */
439 pci_bus_write_config(bus, dev, 0x62c, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700440
Tim Harvey6ce10d52021-05-03 11:21:27 -0700441 pci_bus_read_config(bus, dev, 0x644, &val, PCI_SIZE_32);
442 val |= 0xfe; /* GPIO1-7 output high */
443 pci_bus_write_config(bus, dev, 0x644, val, PCI_SIZE_32);
Tim Harvey33791d52014-08-07 22:49:57 -0700444
445 mdelay(100);
446 }
447}
Tim Harvey552c3582014-03-06 07:46:30 -0800448
449#ifdef CONFIG_SERIAL_TAG
450/*
451 * called when setting up ATAGS before booting kernel
452 * populate serialnum from the following (in order of priority):
453 * serial# env var
454 * eeprom
455 */
456void get_board_serial(struct tag_serialnr *serialnr)
457{
Simon Glass64b723f2017-08-03 12:22:12 -0600458 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800459
460 if (serial) {
461 serialnr->high = 0;
Simon Glassff9b9032021-07-24 09:03:30 -0600462 serialnr->low = dectoul(serial, NULL);
Tim Harvey552c3582014-03-06 07:46:30 -0800463 } else if (ventana_info.model[0]) {
464 serialnr->high = 0;
465 serialnr->low = ventana_info.serial;
466 } else {
467 serialnr->high = 0;
468 serialnr->low = 0;
469 }
470}
471#endif
472
473/*
474 * Board Support
475 */
476
477int board_early_init_f(void)
478{
Tim Harveyfb64cc72014-04-25 15:39:07 -0700479#if defined(CONFIG_VIDEO_IPUV3)
480 setup_display();
481#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800482 return 0;
483}
484
485int dram_init(void)
486{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700487 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800488 return 0;
489}
490
491int board_init(void)
492{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300493 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800494
495 clrsetbits_le32(&iomuxc_regs->gpr[1],
496 IOMUXC_GPR1_OTG_ID_MASK,
497 IOMUXC_GPR1_OTG_ID_GPIO1);
498
499 /* address of linux boot parameters */
500 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
501
Tim Harveyba9f2342019-02-04 13:10:52 -0800502 /* read Gateworks EEPROM into global struct (used later) */
503 setup_ventana_i2c(0);
504 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
505
Tim Harveyd04dc812019-02-04 13:10:49 -0800506 setup_ventana_i2c(1);
507 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800508
Tim Harvey0cee2242015-05-08 18:28:35 -0700509 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800510
511 return 0;
512}
513
Tim Harvey948202c2021-03-01 14:33:32 -0800514int board_fit_config_name_match(const char *name)
515{
516 static char init;
517 const char *dtb;
518 char buf[32];
519 int i = 0;
520
521 do {
522 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
523 if (dtb && !strcmp(dtb, name)) {
524 if (!init++)
525 printf("DTB: %s\n", name);
526 return 0;
527 }
528 } while (dtb);
529
530 return -1;
531}
532
Tim Harvey552c3582014-03-06 07:46:30 -0800533#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
534/*
535 * called during late init (after relocation and after board_init())
536 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
537 * EEPROM read.
538 */
539int checkboard(void)
540{
541 struct ventana_board_info *info = &ventana_info;
542 unsigned char buf[4];
543 const char *p;
544 int quiet; /* Quiet or minimal output mode */
545
546 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600547 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800548 if (p)
549 quiet = simple_strtol(p, NULL, 10);
550 else
Simon Glass6a38e412017-08-03 12:22:09 -0600551 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800552
553 puts("\nGateworks Corporation Copyright 2014\n");
554 if (info->model[0]) {
555 printf("Model: %s\n", info->model);
556 printf("MFGDate: %02x-%02x-%02x%02x\n",
557 info->mfgdate[0], info->mfgdate[1],
558 info->mfgdate[2], info->mfgdate[3]);
559 printf("Serial:%d\n", info->serial);
560 } else {
561 puts("Invalid EEPROM - board will not function fully\n");
562 }
563 if (quiet)
564 return 0;
565
566 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700567 gsc_info(0);
568
Tim Harvey552c3582014-03-06 07:46:30 -0800569 /* Display RTC */
570 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
571 printf("RTC: %d\n",
572 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
573 }
574
575 return 0;
576}
577#endif
578
579#ifdef CONFIG_CMD_BMODE
580/*
581 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
582 * see Table 8-11 and Table 5-9
583 * BOOT_CFG1[7] = 1 (boot from NAND)
584 * BOOT_CFG1[5] = 0 - raw NAND
585 * BOOT_CFG1[4] = 0 - default pad settings
586 * BOOT_CFG1[3:2] = 00 - devices = 1
587 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
588 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
589 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
590 * BOOT_CFG2[0] = 0 - Reset time 12ms
591 */
592static const struct boot_mode board_boot_modes[] = {
593 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
594 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700595 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800596 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800597 { NULL, 0 },
598};
599#endif
600
601/* late init */
602int misc_init_r(void)
603{
604 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700605 char buf[256];
606 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800607
608 /* set env vars based on EEPROM data */
609 if (ventana_info.model[0]) {
610 char str[16], fdt[36];
611 char *p;
612 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800613
614 /*
615 * FDT name will be prefixed with CPU type. Three versions
616 * will be created each increasingly generic and bootloader
617 * env scripts will try loading each from most specific to
618 * least.
619 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700620 if (is_cpu_type(MXC_CPU_MX6Q) ||
621 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800622 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700623 else if (is_cpu_type(MXC_CPU_MX6DL) ||
624 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800625 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600626 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700627 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600628 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700629 else
Simon Glass6a38e412017-08-03 12:22:09 -0600630 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800631 memset(str, 0, sizeof(str));
632 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
633 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600634 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600635 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800636 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600637 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800638 }
639 p = strchr(str, '-');
640 if (p) {
641 *p++ = 0;
642
Simon Glass6a38e412017-08-03 12:22:09 -0600643 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700644 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600645 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700646 if (board_type != GW551x &&
647 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700648 board_type != GW553x &&
649 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700650 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800651 str[5] = 'x';
652 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700653 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600654 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800655 }
656
657 /* initialize env from EEPROM */
658 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600659 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600660 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800661 }
662 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600663 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600664 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800665 }
666
667 /* board serial-number */
668 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600669 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700670
671 /* memory MB */
672 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600673 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800674 }
675
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700676 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600677 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700678 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700679 if (gpio_cfg[board_type].rs232_en)
680 strcat(buf, "rs232;");
681 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
682 char buf1[32];
683 sprintf(buf1, "dio%d:mode=gpio;", i);
684 if (strlen(buf) + strlen(buf1) < sizeof(buf))
685 strcat(buf, buf1);
686 }
Simon Glass6a38e412017-08-03 12:22:09 -0600687 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700688 }
Tim Harvey552c3582014-03-06 07:46:30 -0800689
Tim Harvey0cee2242015-05-08 18:28:35 -0700690 /* setup baseboard specific GPIO based on board and env */
691 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800692
693#ifdef CONFIG_CMD_BMODE
694 add_board_boot_modes(board_boot_modes);
695#endif
696
Tim Harvey40feabb2015-05-08 18:28:36 -0700697 /* disable boot watchdog */
698 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800699
700 return 0;
701}
702
Robert P. J. Day3c757002016-05-19 15:23:12 -0400703#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800704
Tim Harveycf20e552015-04-08 12:55:01 -0700705static int ft_sethdmiinfmt(void *blob, char *mode)
706{
707 int off;
708
709 if (!mode)
710 return -EINVAL;
711
712 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
713 if (off < 0)
714 return off;
715
716 if (0 == strcasecmp(mode, "yuv422bt656")) {
717 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
718 0x00, 0x00, 0x00 };
719 mode = "422_ccir";
720 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
721 fdt_setprop_u32(blob, off, "vidout_trc", 1);
722 fdt_setprop_u32(blob, off, "vidout_blc", 1);
723 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
724 printf(" set HDMI input mode to %s\n", mode);
725 } else if (0 == strcasecmp(mode, "yuv422smp")) {
726 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
727 0x82, 0x81, 0x00 };
728 mode = "422_smp";
729 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
730 fdt_setprop_u32(blob, off, "vidout_trc", 0);
731 fdt_setprop_u32(blob, off, "vidout_blc", 0);
732 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
733 printf(" set HDMI input mode to %s\n", mode);
734 } else {
735 return -EINVAL;
736 }
737
738 return 0;
739}
740
Tim Harveybfb240a2016-06-17 06:10:41 -0700741#if defined(CONFIG_CMD_PCI)
742#define PCI_ID(x) ( \
743 (PCI_BUS(x->devfn)<<16)| \
744 (PCI_DEV(x->devfn)<<11)| \
745 (PCI_FUNC(x->devfn)<<8) \
746 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700747int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
748{
749 uint32_t reg[5];
750 char node[32];
751 int np;
752
753 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
754 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
755
756 np = fdt_subnode_offset(blob, par, node);
757 if (np >= 0)
758 return np;
759 np = fdt_add_subnode(blob, par, node);
760 if (np < 0) {
761 printf(" %s failed: no space\n", __func__);
762 return np;
763 }
764
765 memset(reg, 0, sizeof(reg));
766 reg[0] = cpu_to_fdt32(PCI_ID(dev));
767 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
768
769 return np;
770}
771
772/* build a path of nested PCI devs for all bridges passed through */
773int fdt_add_pci_path(void *blob, struct pci_dev *dev)
774{
775 struct pci_dev *bridges[MAX_PCI_DEVS];
776 int k, np;
777
778 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800779 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700780 if (np < 0)
781 return np;
782
783 k = 0;
784 while (dev) {
785 bridges[k++] = dev;
786 dev = dev->ppar;
787 };
788
789 /* now add them the to DT in reverse order */
790 while (k--) {
791 np = fdt_add_pci_node(blob, np, bridges[k]);
792 if (np < 0)
793 break;
794 }
795
796 return np;
797}
798
799/*
800 * The GW16082 has a hardware errata errata such that it's
801 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
802 * of this normal PCI interrupt swizzling will not work so we will
803 * provide an irq-map via device-tree.
804 */
805int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
806{
807 int len;
808 int host;
809 uint32_t imap_new[8*4*4];
810 const uint32_t *imap;
811 uint32_t irq[4];
812 uint32_t reg[4];
813 int i;
814
815 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800816 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700817 if (host < 0) {
818 printf(" %s failed: missing host\n", __func__);
819 return host;
820 }
821
822 /* use interrupt data from root complex's node */
823 imap = fdt_getprop(blob, host, "interrupt-map", &len);
824 if (!imap || len != 128) {
825 printf(" %s failed: invalid interrupt-map\n",
826 __func__);
827 return -FDT_ERR_NOTFOUND;
828 }
829
830 /* obtain irq's of host controller in pin order */
831 for (i = 0; i < 4; i++)
832 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
833
834 /*
835 * determine number of swizzles necessary:
836 * For each bridge we pass through we need to swizzle
837 * the number of the slot we are on.
838 */
839 struct pci_dev *d;
840 int b;
841 b = 0;
842 d = dev->ppar;
843 while(d && d->ppar) {
844 b += PCI_DEV(d->devfn);
845 d = d->ppar;
846 }
847
848 /* create new irq mappings for slots12-15
849 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
850 * J3 AD28 12 INTD INTA
851 * J4 AD29 13 INTC INTD
852 * J5 AD30 14 INTB INTC
853 * J2 AD31 15 INTA INTB
854 */
855 for (i = 0; i < 4; i++) {
856 /* addr matches bus:dev:func */
857 u32 addr = dev->busno << 16 | (12+i) << 11;
858
859 /* default cells from root complex */
860 memcpy(&imap_new[i*32], imap, 128);
861 /* first cell is PCI device address (BDF) */
862 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
863 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
864 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
865 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
866 /* third cell is pin */
867 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
868 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
869 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
870 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
871 /* sixth cell is relative interrupt */
872 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
873 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
874 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
875 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
876 }
877 fdt_setprop(blob, np, "interrupt-map", imap_new,
878 sizeof(imap_new));
879 reg[0] = cpu_to_fdt32(0xfff00);
880 reg[1] = 0;
881 reg[2] = 0;
882 reg[3] = cpu_to_fdt32(0x7);
883 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
884 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
885 fdt_setprop_string(blob, np, "device_type", "pci");
886 fdt_setprop_cell(blob, np, "#address-cells", 3);
887 fdt_setprop_cell(blob, np, "#size-cells", 2);
888 printf(" Added custom interrupt-map for GW16082\n");
889
890 return 0;
891}
892
Tim Harvey77b82a12016-06-17 06:10:42 -0700893/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
894int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
895{
896 char *tmp, *end;
897 char mac[16];
898 unsigned char mac_addr[6];
899 int j;
900
901 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -0600902 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -0700903 if (tmp) {
904 for (j = 0; j < 6; j++) {
905 mac_addr[j] = tmp ?
Simon Glass3ff49ec2021-07-24 09:03:29 -0600906 hextoul(tmp, &end) : 0;
Tim Harvey77b82a12016-06-17 06:10:42 -0700907 if (tmp)
908 tmp = (*end) ? end+1 : end;
909 }
910 fdt_setprop(blob, np, "local-mac-address", mac_addr,
911 sizeof(mac_addr));
912 printf(" Added mac addr for eth1\n");
913 return 0;
914 }
915
916 return -1;
917}
918
Tim Harveybfb240a2016-06-17 06:10:41 -0700919/*
920 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
921 * we will walk the PCI bus and add bridge nodes up to the device receiving
922 * the fixup.
923 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900924void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -0700925{
926 int i, np;
927 struct pci_dev *dev;
928
929 for (i = 0; i < pci_devno; i++) {
930 dev = &pci_devs[i];
931
932 /*
933 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
934 * an EEPROM at i2c1-0x50.
935 */
936 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
937 (dev->device == 0x8240) &&
938 (i2c_set_bus_num(1) == 0) &&
939 (i2c_probe(0x50) == 0))
940 {
941 np = fdt_add_pci_path(blob, dev);
942 if (np > 0)
943 fdt_fixup_gw16082(blob, np, dev);
944 }
Tim Harvey77b82a12016-06-17 06:10:42 -0700945
946 /* ethernet1 mac address */
947 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
948 (dev->device == 0x4380))
949 {
950 np = fdt_add_pci_path(blob, dev);
951 if (np > 0)
952 fdt_fixup_sky2(blob, np, dev);
953 }
Tim Harveybfb240a2016-06-17 06:10:41 -0700954 }
955}
956#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -0700957
Tim Harvey552c3582014-03-06 07:46:30 -0800958/*
959 * called prior to booting kernel or by 'fdt boardsetup' command
960 *
961 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
962 * - mtd partitions based on mtdparts/mtdids env
963 * - system-serial (board serial num from EEPROM)
964 * - board (full model from EEPROM)
965 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
966 */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800967#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900968int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -0800969{
Tim Harvey552c3582014-03-06 07:46:30 -0800970 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -0700971 struct ventana_eeprom_config *cfg;
Tim Harvey8e502172021-07-24 10:40:33 -0700972 static const struct node_info nand_nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -0800973 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
974 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
975 };
Simon Glass64b723f2017-08-03 12:22:12 -0600976 const char *model = env_get("model");
977 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -0700978 int i;
979 char rev = 0;
980
981 /* determine board revision */
982 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
983 if (ventana_info.model[i] >= 'A') {
984 rev = ventana_info.model[i];
985 break;
986 }
987 }
Tim Harvey552c3582014-03-06 07:46:30 -0800988
Simon Glass64b723f2017-08-03 12:22:12 -0600989 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800990 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -0600991 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800992 }
993
Tim Harvey8e502172021-07-24 10:40:33 -0700994 /* Update MTD partition nodes using info from mtdparts env var */
995 puts(" Updating MTD partitions...\n");
996 fdt_fixup_mtdparts(blob, nand_nodes, ARRAY_SIZE(nand_nodes));
Tim Harvey552c3582014-03-06 07:46:30 -0800997
Tim Harveye4af5d32015-04-08 12:54:58 -0700998 /* Update display timings from display env var */
999 if (display) {
1000 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1001 display) >= 0)
1002 printf(" Set display timings for %s...\n", display);
1003 }
1004
Tim Harvey552c3582014-03-06 07:46:30 -08001005 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1006
1007 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001008 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1009 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001010
1011 /* board (model contains model from device-tree) */
1012 fdt_setprop(blob, 0, "board", info->model,
1013 strlen((const char *)info->model) + 1);
1014
Tim Harveycf20e552015-04-08 12:55:01 -07001015 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001016 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001017
Tim Harvey28db4e42021-07-24 10:40:32 -07001018 /* early board/revision ft fixups */
1019 ft_early_fixup(blob, board_type);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001020
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001021 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001022 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001023 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1024 char arg[10];
1025
1026 sprintf(arg, "dio%d", i);
1027 if (!hwconfig(arg))
1028 continue;
1029 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1030 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001031 phys_addr_t addr;
1032 int off;
1033
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001034 printf(" Enabling pwm%d for DIO%d\n",
1035 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001036 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1037 off = fdt_node_offset_by_compat_reg(blob,
1038 "fsl,imx6q-pwm",
1039 addr);
1040 if (off)
1041 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001042 }
1043 }
1044
Tim Harveybfb240a2016-06-17 06:10:41 -07001045#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001046 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001047 ft_board_pci_fixup(blob, bd);
1048#endif
1049
Tim Harvey6944ccf2015-04-08 12:54:53 -07001050 /*
Tim Harvey7ad148a2021-09-29 15:04:18 -07001051 * remove reset gpio control as we configure the PHY registers
1052 * for internal delay, LED config, and clock config in the bootloader
1053 */
1054 i = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-fec");
1055 if (i)
1056 fdt_delprop(blob, i, "phy-reset-gpios");
1057
1058 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001059 * Peripheral Config:
1060 * remove nodes by alias path if EEPROM config tells us the
1061 * peripheral is not loaded on the board.
1062 */
Simon Glass64b723f2017-08-03 12:22:12 -06001063 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001064 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001065 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001066 }
1067 cfg = econfig;
1068 while (cfg->name) {
1069 if (!test_bit(cfg->bit, info->config)) {
1070 fdt_del_node_and_alias(blob, cfg->dtalias ?
1071 cfg->dtalias : cfg->name);
1072 }
1073 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001074 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001075
1076 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001077}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001078#endif /* CONFIG_OF_BOARD_SETUP */