blob: 5237f2dac431806dec79de08c98df8f31551502b [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>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Tim Harvey552c3582014-03-06 07:46:30 -080012#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070013#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080014#include <asm/arch/iomux.h>
15#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070016#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080017#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Tim Harvey552c3582014-03-06 07:46:30 -080019#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/boot_mode.h>
21#include <asm/mach-imx/sata.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020022#include <asm/mach-imx/video.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070023#include <asm/io.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060024#include <asm/setup.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070025#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060026#include <env.h>
Tim Harvey8d2d8df2016-05-24 11:03:55 -070027#include <hwconfig.h>
Tim Harvey552c3582014-03-06 07:46:30 -080028#include <i2c.h>
Tim Harvey552c3582014-03-06 07:46:30 -080029#include <fdt_support.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070030#include <jffs2/load_kernel.h>
31#include <linux/ctype.h>
Tim Harvey552c3582014-03-06 07:46:30 -080032#include <miiphy.h>
Tim Harvey552c3582014-03-06 07:46:30 -080033#include <mtd_node.h>
34#include <netdev.h>
Tim Harvey33791d52014-08-07 22:49:57 -070035#include <pci.h>
Simon Glassdbd79542020-05-10 11:40:11 -060036#include <linux/delay.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060037#include <linux/libfdt.h>
Tim Harvey552c3582014-03-06 07:46:30 -080038#include <power/pmic.h>
Tim Harvey0dff16f2014-05-05 08:22:25 -070039#include <power/ltc3676_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080040#include <power/pfuze100_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080041#include <fdt_support.h>
42#include <jffs2/load_kernel.h>
Tim Harvey552c3582014-03-06 07:46:30 -080043
44#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070045#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080046
47DECLARE_GLOBAL_DATA_PTR;
48
Tim Harvey26993362014-08-07 22:35:49 -070049
Tim Harvey552c3582014-03-06 07:46:30 -080050/*
51 * EEPROM board info struct populated by read_eeprom so that we only have to
52 * read it once.
53 */
Tim Harvey0da2c522014-08-07 22:35:45 -070054struct ventana_board_info ventana_info;
Tim Harvey8b92bdf2015-04-08 12:54:43 -070055static int board_type;
Tim Harvey552c3582014-03-06 07:46:30 -080056
Tim Harvey552c3582014-03-06 07:46:30 -080057/* ENET */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070058static iomux_v3_cfg_t const enet_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070059 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
60 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
61 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
62 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
63 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
64 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
65 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
66 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
67 MUX_PAD_CTRL(ENET_PAD_CTRL)),
68 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
69 MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
71 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
76 MUX_PAD_CTRL(ENET_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080077 /* PHY nRST */
Tim Harvey26993362014-08-07 22:35:49 -070078 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -080079};
80
Tim Harveyf1f41db2015-05-08 18:28:28 -070081static void setup_iomux_enet(int gpio)
Tim Harvey552c3582014-03-06 07:46:30 -080082{
Tim Harvey02fb5922014-06-02 16:13:26 -070083 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -080084
85 /* toggle PHY_RST# */
Tim Harveyf1f41db2015-05-08 18:28:28 -070086 gpio_request(gpio, "phy_rst#");
87 gpio_direction_output(gpio, 0);
Tim Harvey63537792017-03-17 07:30:38 -070088 mdelay(10);
Tim Harveyf1f41db2015-05-08 18:28:28 -070089 gpio_set_value(gpio, 1);
Tim Harvey63537792017-03-17 07:30:38 -070090 mdelay(100);
Tim Harvey552c3582014-03-06 07:46:30 -080091}
92
Tim Harvey552c3582014-03-06 07:46:30 -080093#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey1112b4e2021-03-01 14:33:34 -080094/* toggle USB_HUB_RST# for boards that have it; it is not defined in dt */
Tim Harvey552c3582014-03-06 07:46:30 -080095int board_ehci_hcd_init(int port)
96{
Tim Harveyf1f41db2015-05-08 18:28:28 -070097 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -080098
Tim Harvey1112b4e2021-03-01 14:33:34 -080099 /* USB HUB is always on P1 */
100 if (port == 0)
101 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800102
Tim Harveydb7edfa2015-05-26 11:04:54 -0700103 /* Reset USB HUB */
104 switch (board_type) {
105 case GW53xx:
106 case GW552x:
Tim Harveyb7c48a92019-02-04 13:10:54 -0800107 case GW5906:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700108 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -0800109 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -0700110 case GW54proto:
111 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700112 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -0800113 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700114 default:
115 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800116 }
117
Tim Harveyf1f41db2015-05-08 18:28:28 -0700118 /* request and toggle hub rst */
119 gpio_request(gpio, "usb_hub_rst#");
120 gpio_direction_output(gpio, 0);
121 mdelay(2);
122 gpio_set_value(gpio, 1);
123
Tim Harvey552c3582014-03-06 07:46:30 -0800124 return 0;
125}
Tim Harvey552c3582014-03-06 07:46:30 -0800126#endif /* CONFIG_USB_EHCI_MX6 */
127
Tim Harvey552c3582014-03-06 07:46:30 -0800128/* configure eth0 PHY board-specific LED behavior */
129int board_phy_config(struct phy_device *phydev)
130{
131 unsigned short val;
132
133 /* Marvel 88E1510 */
134 if (phydev->phy_id == 0x1410dd1) {
135 /*
136 * Page 3, Register 16: LED[2:0] Function Control Register
137 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
138 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
139 */
140 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
141 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
142 val &= 0xff00;
143 val |= 0x0017;
144 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
145 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
146 }
147
Tim Harvey4533c902017-03-17 07:32:21 -0700148 /* TI DP83867 */
149 else if (phydev->phy_id == 0x2000a231) {
150 /* configure register 0x170 for ref CLKOUT */
151 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
152 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
153 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
154 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
155 val &= ~0x1f00;
156 val |= 0x0b00; /* chD tx clock*/
157 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
158 }
159
Tim Harvey552c3582014-03-06 07:46:30 -0800160 if (phydev->drv->config)
161 phydev->drv->config(phydev);
162
163 return 0;
164}
Tim Harvey63537792017-03-17 07:30:38 -0700165
166#ifdef CONFIG_MV88E61XX_SWITCH
167int mv88e61xx_hw_reset(struct phy_device *phydev)
168{
169 struct mii_dev *bus = phydev->bus;
170
171 /* GPIO[0] output, CLK125 */
172 debug("enabling RGMII_REFCLK\n");
173 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
174 0x1a /*MV_SCRATCH_MISC*/,
175 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
176 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
177 0x1a /*MV_SCRATCH_MISC*/,
178 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
179
180 /* RGMII delay - Physical Control register bit[15:14] */
181 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
182 /* forced 1000mbps full-duplex link */
183 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
184 phydev->autoneg = AUTONEG_DISABLE;
185 phydev->speed = SPEED_1000;
186 phydev->duplex = DUPLEX_FULL;
187
Tim Harvey8c9d3932019-02-04 13:10:47 -0800188 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
189 bus->write(bus, 0x10, 0, 0x16, 0x8088);
190 bus->write(bus, 0x11, 0, 0x16, 0x8088);
191 bus->write(bus, 0x12, 0, 0x16, 0x8088);
192 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700193
194 return 0;
195}
196#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800197
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900198int board_eth_init(struct bd_info *bis)
Tim Harvey552c3582014-03-06 07:46:30 -0800199{
Tim Harvey552c3582014-03-06 07:46:30 -0800200#ifdef CONFIG_FEC_MXC
Tim Harvey892068c2016-05-24 11:03:58 -0700201 struct ventana_board_info *info = &ventana_info;
202
203 if (test_bit(EECONFIG_ETH0, info->config)) {
Tim Harveyf1f41db2015-05-08 18:28:28 -0700204 setup_iomux_enet(GP_PHY_RST);
Tim Harvey50581832014-08-20 23:35:14 -0700205 cpu_eth_init(bis);
Tim Harvey85331822015-04-08 12:54:48 -0700206 }
Tim Harvey552c3582014-03-06 07:46:30 -0800207#endif
208
Tim Harvey472884d2015-04-08 12:54:32 -0700209#ifdef CONFIG_E1000
210 e1000_initialize(bis);
211#endif
212
Tim Harvey552c3582014-03-06 07:46:30 -0800213#ifdef CONFIG_CI_UDC
214 /* For otg ethernet*/
215 usb_eth_initialize(bis);
216#endif
217
Tim Harveyfc5ff942015-04-08 12:54:33 -0700218 /* default to the first detected enet dev */
Simon Glass64b723f2017-08-03 12:22:12 -0600219 if (!env_get("ethprime")) {
Tim Harveyfc5ff942015-04-08 12:54:33 -0700220 struct eth_device *dev = eth_get_dev_by_index(0);
221 if (dev) {
Simon Glass6a38e412017-08-03 12:22:09 -0600222 env_set("ethprime", dev->name);
Simon Glass64b723f2017-08-03 12:22:12 -0600223 printf("set ethprime to %s\n", env_get("ethprime"));
Tim Harveyfc5ff942015-04-08 12:54:33 -0700224 }
225 }
226
Tim Harvey552c3582014-03-06 07:46:30 -0800227 return 0;
228}
229
Tim Harveyfb64cc72014-04-25 15:39:07 -0700230#if defined(CONFIG_VIDEO_IPUV3)
231
232static void enable_hdmi(struct display_info_t const *dev)
233{
234 imx_enable_hdmi_phy();
235}
236
237static int detect_i2c(struct display_info_t const *dev)
238{
239 return i2c_set_bus_num(dev->bus) == 0 &&
240 i2c_probe(dev->addr) == 0;
241}
242
243static void enable_lvds(struct display_info_t const *dev)
244{
245 struct iomuxc *iomux = (struct iomuxc *)
246 IOMUXC_BASE_ADDR;
247
248 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
249 u32 reg = readl(&iomux->gpr[2]);
250 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
251 writel(reg, &iomux->gpr[2]);
252
253 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700254 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
255 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700256 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700257 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700258 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
259}
260
261struct display_info_t const displays[] = {{
262 /* HDMI Output */
263 .bus = -1,
264 .addr = 0,
265 .pixfmt = IPU_PIX_FMT_RGB24,
266 .detect = detect_hdmi,
267 .enable = enable_hdmi,
268 .mode = {
269 .name = "HDMI",
270 .refresh = 60,
271 .xres = 1024,
272 .yres = 768,
273 .pixclock = 15385,
274 .left_margin = 220,
275 .right_margin = 40,
276 .upper_margin = 21,
277 .lower_margin = 7,
278 .hsync_len = 60,
279 .vsync_len = 10,
280 .sync = FB_SYNC_EXT,
281 .vmode = FB_VMODE_NONINTERLACED
282} }, {
283 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
284 .bus = 2,
285 .addr = 0x4,
286 .pixfmt = IPU_PIX_FMT_LVDS666,
287 .detect = detect_i2c,
288 .enable = enable_lvds,
289 .mode = {
290 .name = "Hannstar-XGA",
291 .refresh = 60,
292 .xres = 1024,
293 .yres = 768,
294 .pixclock = 15385,
295 .left_margin = 220,
296 .right_margin = 40,
297 .upper_margin = 21,
298 .lower_margin = 7,
299 .hsync_len = 60,
300 .vsync_len = 10,
301 .sync = FB_SYNC_EXT,
302 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700303} }, {
304 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800305 .bus = 2,
306 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700307 .detect = NULL,
308 .enable = enable_lvds,
309 .pixfmt = IPU_PIX_FMT_LVDS666,
310 .mode = {
311 .name = "DLC700JMGT4",
312 .refresh = 60,
313 .xres = 1024, /* 1024x600active pixels */
314 .yres = 600,
315 .pixclock = 15385, /* 64MHz */
316 .left_margin = 220,
317 .right_margin = 40,
318 .upper_margin = 21,
319 .lower_margin = 7,
320 .hsync_len = 60,
321 .vsync_len = 10,
322 .sync = FB_SYNC_EXT,
323 .vmode = FB_VMODE_NONINTERLACED
324} }, {
325 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800326 .bus = 2,
327 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700328 .detect = NULL,
329 .enable = enable_lvds,
330 .pixfmt = IPU_PIX_FMT_LVDS666,
331 .mode = {
332 .name = "DLC800FIGT3",
333 .refresh = 60,
334 .xres = 1024, /* 1024x768 active pixels */
335 .yres = 768,
336 .pixclock = 15385, /* 64MHz */
337 .left_margin = 220,
338 .right_margin = 40,
339 .upper_margin = 21,
340 .lower_margin = 7,
341 .hsync_len = 60,
342 .vsync_len = 10,
343 .sync = FB_SYNC_EXT,
344 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800345} }, {
346 .bus = 2,
347 .addr = 0x5d,
348 .detect = detect_i2c,
349 .enable = enable_lvds,
350 .pixfmt = IPU_PIX_FMT_LVDS666,
351 .mode = {
352 .name = "Z101WX01",
353 .refresh = 60,
354 .xres = 1280,
355 .yres = 800,
356 .pixclock = 15385, /* 64MHz */
357 .left_margin = 220,
358 .right_margin = 40,
359 .upper_margin = 21,
360 .lower_margin = 7,
361 .hsync_len = 60,
362 .vsync_len = 10,
363 .sync = FB_SYNC_EXT,
364 .vmode = FB_VMODE_NONINTERLACED
365 }
366},
367};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700368size_t display_count = ARRAY_SIZE(displays);
369
370static void setup_display(void)
371{
372 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
373 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
374 int reg;
375
376 enable_ipu_clock();
377 imx_setup_hdmi();
378 /* Turn on LDB0,IPU,IPU DI0 clocks */
379 reg = __raw_readl(&mxc_ccm->CCGR3);
380 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
381 writel(reg, &mxc_ccm->CCGR3);
382
383 /* set LDB0, LDB1 clk select to 011/011 */
384 reg = readl(&mxc_ccm->cs2cdr);
385 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
386 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
387 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
388 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
389 writel(reg, &mxc_ccm->cs2cdr);
390
391 reg = readl(&mxc_ccm->cscmr2);
392 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
393 writel(reg, &mxc_ccm->cscmr2);
394
395 reg = readl(&mxc_ccm->chsccdr);
396 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
397 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
398 writel(reg, &mxc_ccm->chsccdr);
399
400 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
401 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
402 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
403 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
404 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
405 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
406 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
407 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
408 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
409 writel(reg, &iomux->gpr[2]);
410
411 reg = readl(&iomux->gpr[3]);
412 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
413 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
414 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
415 writel(reg, &iomux->gpr[3]);
416
Tim Harveya67e07f2016-05-24 11:03:53 -0700417 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700418 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700419 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
420}
421#endif /* CONFIG_VIDEO_IPUV3 */
422
Tim Harvey0dff16f2014-05-05 08:22:25 -0700423/* setup board specific PMIC */
424int power_init_board(void)
425{
Tim Harvey195bc972015-05-08 18:28:37 -0700426 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700427 return 0;
428}
429
Tim Harvey552c3582014-03-06 07:46:30 -0800430#if defined(CONFIG_CMD_PCI)
431int imx6_pcie_toggle_reset(void)
432{
433 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700434 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700435 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700436 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800437 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700438 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800439 }
440 return 0;
441}
Tim Harvey33791d52014-08-07 22:49:57 -0700442
443/*
444 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
445 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
446 * properly and assert reset for 100ms.
447 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700448#define MAX_PCI_DEVS 32
449struct pci_dev {
450 pci_dev_t devfn;
451 unsigned short vendor;
452 unsigned short device;
453 unsigned short class;
454 unsigned short busno; /* subbordinate busno */
455 struct pci_dev *ppar;
456};
457struct pci_dev pci_devs[MAX_PCI_DEVS];
458int pci_devno;
459int pci_bridgeno;
460
Tim Harvey33791d52014-08-07 22:49:57 -0700461void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
462 unsigned short vendor, unsigned short device,
463 unsigned short class)
464{
Tim Harveybfb240a2016-06-17 06:10:41 -0700465 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700466 u32 dw;
Tim Harveybfb240a2016-06-17 06:10:41 -0700467 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey33791d52014-08-07 22:49:57 -0700468
469 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
470 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700471
472 /* store array of devs for later use in device-tree fixup */
473 pdev->devfn = dev;
474 pdev->vendor = vendor;
475 pdev->device = device;
476 pdev->class = class;
477 pdev->ppar = NULL;
478 if (class == PCI_CLASS_BRIDGE_PCI)
479 pdev->busno = ++pci_bridgeno;
480 else
481 pdev->busno = 0;
482
483 /* fixup RC - it should be 00:00.0 not 00:01.0 */
484 if (PCI_BUS(dev) == 0)
485 pdev->devfn = 0;
486
487 /* find dev's parent */
488 for (i = 0; i < pci_devno; i++) {
489 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
490 pdev->ppar = &pci_devs[i];
491 break;
492 }
493 }
494
495 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700496 if (vendor == PCI_VENDOR_ID_PLX &&
497 (device & 0xfff0) == 0x8600 &&
498 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
499 debug("configuring PLX 860X downstream PERST#\n");
500 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
501 dw |= 0xaaa8; /* GPIO1-7 outputs */
502 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
503
504 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
505 dw |= 0xfe; /* GPIO1-7 output high */
506 pci_hose_write_config_dword(hose, dev, 0x644, dw);
507
508 mdelay(100);
509 }
510}
Tim Harvey552c3582014-03-06 07:46:30 -0800511#endif /* CONFIG_CMD_PCI */
512
513#ifdef CONFIG_SERIAL_TAG
514/*
515 * called when setting up ATAGS before booting kernel
516 * populate serialnum from the following (in order of priority):
517 * serial# env var
518 * eeprom
519 */
520void get_board_serial(struct tag_serialnr *serialnr)
521{
Simon Glass64b723f2017-08-03 12:22:12 -0600522 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800523
524 if (serial) {
525 serialnr->high = 0;
526 serialnr->low = simple_strtoul(serial, NULL, 10);
527 } else if (ventana_info.model[0]) {
528 serialnr->high = 0;
529 serialnr->low = ventana_info.serial;
530 } else {
531 serialnr->high = 0;
532 serialnr->low = 0;
533 }
534}
535#endif
536
537/*
538 * Board Support
539 */
540
541int board_early_init_f(void)
542{
Tim Harveyfb64cc72014-04-25 15:39:07 -0700543#if defined(CONFIG_VIDEO_IPUV3)
544 setup_display();
545#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800546 return 0;
547}
548
549int dram_init(void)
550{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700551 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800552 return 0;
553}
554
555int board_init(void)
556{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300557 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800558
559 clrsetbits_le32(&iomuxc_regs->gpr[1],
560 IOMUXC_GPR1_OTG_ID_MASK,
561 IOMUXC_GPR1_OTG_ID_GPIO1);
562
563 /* address of linux boot parameters */
564 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
565
Tim Harveyba9f2342019-02-04 13:10:52 -0800566 /* read Gateworks EEPROM into global struct (used later) */
567 setup_ventana_i2c(0);
568 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
569
Tim Harveyd04dc812019-02-04 13:10:49 -0800570 setup_ventana_i2c(1);
571 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800572
Tim Harvey0cee2242015-05-08 18:28:35 -0700573 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800574
575 return 0;
576}
577
Tim Harvey948202c2021-03-01 14:33:32 -0800578int board_fit_config_name_match(const char *name)
579{
580 static char init;
581 const char *dtb;
582 char buf[32];
583 int i = 0;
584
585 do {
586 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
587 if (dtb && !strcmp(dtb, name)) {
588 if (!init++)
589 printf("DTB: %s\n", name);
590 return 0;
591 }
592 } while (dtb);
593
594 return -1;
595}
596
Tim Harvey552c3582014-03-06 07:46:30 -0800597#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
598/*
599 * called during late init (after relocation and after board_init())
600 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
601 * EEPROM read.
602 */
603int checkboard(void)
604{
605 struct ventana_board_info *info = &ventana_info;
606 unsigned char buf[4];
607 const char *p;
608 int quiet; /* Quiet or minimal output mode */
609
610 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600611 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800612 if (p)
613 quiet = simple_strtol(p, NULL, 10);
614 else
Simon Glass6a38e412017-08-03 12:22:09 -0600615 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800616
617 puts("\nGateworks Corporation Copyright 2014\n");
618 if (info->model[0]) {
619 printf("Model: %s\n", info->model);
620 printf("MFGDate: %02x-%02x-%02x%02x\n",
621 info->mfgdate[0], info->mfgdate[1],
622 info->mfgdate[2], info->mfgdate[3]);
623 printf("Serial:%d\n", info->serial);
624 } else {
625 puts("Invalid EEPROM - board will not function fully\n");
626 }
627 if (quiet)
628 return 0;
629
630 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700631 gsc_info(0);
632
Tim Harvey552c3582014-03-06 07:46:30 -0800633 /* Display RTC */
634 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
635 printf("RTC: %d\n",
636 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
637 }
638
639 return 0;
640}
641#endif
642
643#ifdef CONFIG_CMD_BMODE
644/*
645 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
646 * see Table 8-11 and Table 5-9
647 * BOOT_CFG1[7] = 1 (boot from NAND)
648 * BOOT_CFG1[5] = 0 - raw NAND
649 * BOOT_CFG1[4] = 0 - default pad settings
650 * BOOT_CFG1[3:2] = 00 - devices = 1
651 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
652 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
653 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
654 * BOOT_CFG2[0] = 0 - Reset time 12ms
655 */
656static const struct boot_mode board_boot_modes[] = {
657 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
658 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700659 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800660 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800661 { NULL, 0 },
662};
663#endif
664
665/* late init */
666int misc_init_r(void)
667{
668 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700669 char buf[256];
670 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800671
672 /* set env vars based on EEPROM data */
673 if (ventana_info.model[0]) {
674 char str[16], fdt[36];
675 char *p;
676 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800677
678 /*
679 * FDT name will be prefixed with CPU type. Three versions
680 * will be created each increasingly generic and bootloader
681 * env scripts will try loading each from most specific to
682 * least.
683 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700684 if (is_cpu_type(MXC_CPU_MX6Q) ||
685 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800686 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700687 else if (is_cpu_type(MXC_CPU_MX6DL) ||
688 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800689 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600690 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700691 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600692 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700693 else
Simon Glass6a38e412017-08-03 12:22:09 -0600694 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800695 memset(str, 0, sizeof(str));
696 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
697 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600698 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600699 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800700 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600701 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800702 }
703 p = strchr(str, '-');
704 if (p) {
705 *p++ = 0;
706
Simon Glass6a38e412017-08-03 12:22:09 -0600707 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700708 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600709 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700710 if (board_type != GW551x &&
711 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700712 board_type != GW553x &&
713 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700714 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800715 str[5] = 'x';
716 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700717 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600718 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800719 }
720
721 /* initialize env from EEPROM */
722 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600723 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600724 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800725 }
726 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600727 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600728 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800729 }
730
731 /* board serial-number */
732 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600733 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700734
735 /* memory MB */
736 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600737 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800738 }
739
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700740 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600741 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700742 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700743 if (gpio_cfg[board_type].rs232_en)
744 strcat(buf, "rs232;");
745 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
746 char buf1[32];
747 sprintf(buf1, "dio%d:mode=gpio;", i);
748 if (strlen(buf) + strlen(buf1) < sizeof(buf))
749 strcat(buf, buf1);
750 }
Simon Glass6a38e412017-08-03 12:22:09 -0600751 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700752 }
Tim Harvey552c3582014-03-06 07:46:30 -0800753
Tim Harvey0cee2242015-05-08 18:28:35 -0700754 /* setup baseboard specific GPIO based on board and env */
755 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800756
757#ifdef CONFIG_CMD_BMODE
758 add_board_boot_modes(board_boot_modes);
759#endif
760
Tim Harvey40feabb2015-05-08 18:28:36 -0700761 /* disable boot watchdog */
762 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800763
764 return 0;
765}
766
Robert P. J. Day3c757002016-05-19 15:23:12 -0400767#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800768
Tim Harveycf20e552015-04-08 12:55:01 -0700769static int ft_sethdmiinfmt(void *blob, char *mode)
770{
771 int off;
772
773 if (!mode)
774 return -EINVAL;
775
776 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
777 if (off < 0)
778 return off;
779
780 if (0 == strcasecmp(mode, "yuv422bt656")) {
781 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
782 0x00, 0x00, 0x00 };
783 mode = "422_ccir";
784 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
785 fdt_setprop_u32(blob, off, "vidout_trc", 1);
786 fdt_setprop_u32(blob, off, "vidout_blc", 1);
787 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
788 printf(" set HDMI input mode to %s\n", mode);
789 } else if (0 == strcasecmp(mode, "yuv422smp")) {
790 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
791 0x82, 0x81, 0x00 };
792 mode = "422_smp";
793 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
794 fdt_setprop_u32(blob, off, "vidout_trc", 0);
795 fdt_setprop_u32(blob, off, "vidout_blc", 0);
796 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
797 printf(" set HDMI input mode to %s\n", mode);
798 } else {
799 return -EINVAL;
800 }
801
802 return 0;
803}
804
Tim Harveybfb240a2016-06-17 06:10:41 -0700805#if defined(CONFIG_CMD_PCI)
806#define PCI_ID(x) ( \
807 (PCI_BUS(x->devfn)<<16)| \
808 (PCI_DEV(x->devfn)<<11)| \
809 (PCI_FUNC(x->devfn)<<8) \
810 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700811int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
812{
813 uint32_t reg[5];
814 char node[32];
815 int np;
816
817 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
818 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
819
820 np = fdt_subnode_offset(blob, par, node);
821 if (np >= 0)
822 return np;
823 np = fdt_add_subnode(blob, par, node);
824 if (np < 0) {
825 printf(" %s failed: no space\n", __func__);
826 return np;
827 }
828
829 memset(reg, 0, sizeof(reg));
830 reg[0] = cpu_to_fdt32(PCI_ID(dev));
831 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
832
833 return np;
834}
835
836/* build a path of nested PCI devs for all bridges passed through */
837int fdt_add_pci_path(void *blob, struct pci_dev *dev)
838{
839 struct pci_dev *bridges[MAX_PCI_DEVS];
840 int k, np;
841
842 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800843 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700844 if (np < 0)
845 return np;
846
847 k = 0;
848 while (dev) {
849 bridges[k++] = dev;
850 dev = dev->ppar;
851 };
852
853 /* now add them the to DT in reverse order */
854 while (k--) {
855 np = fdt_add_pci_node(blob, np, bridges[k]);
856 if (np < 0)
857 break;
858 }
859
860 return np;
861}
862
863/*
864 * The GW16082 has a hardware errata errata such that it's
865 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
866 * of this normal PCI interrupt swizzling will not work so we will
867 * provide an irq-map via device-tree.
868 */
869int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
870{
871 int len;
872 int host;
873 uint32_t imap_new[8*4*4];
874 const uint32_t *imap;
875 uint32_t irq[4];
876 uint32_t reg[4];
877 int i;
878
879 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800880 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700881 if (host < 0) {
882 printf(" %s failed: missing host\n", __func__);
883 return host;
884 }
885
886 /* use interrupt data from root complex's node */
887 imap = fdt_getprop(blob, host, "interrupt-map", &len);
888 if (!imap || len != 128) {
889 printf(" %s failed: invalid interrupt-map\n",
890 __func__);
891 return -FDT_ERR_NOTFOUND;
892 }
893
894 /* obtain irq's of host controller in pin order */
895 for (i = 0; i < 4; i++)
896 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
897
898 /*
899 * determine number of swizzles necessary:
900 * For each bridge we pass through we need to swizzle
901 * the number of the slot we are on.
902 */
903 struct pci_dev *d;
904 int b;
905 b = 0;
906 d = dev->ppar;
907 while(d && d->ppar) {
908 b += PCI_DEV(d->devfn);
909 d = d->ppar;
910 }
911
912 /* create new irq mappings for slots12-15
913 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
914 * J3 AD28 12 INTD INTA
915 * J4 AD29 13 INTC INTD
916 * J5 AD30 14 INTB INTC
917 * J2 AD31 15 INTA INTB
918 */
919 for (i = 0; i < 4; i++) {
920 /* addr matches bus:dev:func */
921 u32 addr = dev->busno << 16 | (12+i) << 11;
922
923 /* default cells from root complex */
924 memcpy(&imap_new[i*32], imap, 128);
925 /* first cell is PCI device address (BDF) */
926 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
927 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
928 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
929 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
930 /* third cell is pin */
931 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
932 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
933 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
934 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
935 /* sixth cell is relative interrupt */
936 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
937 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
938 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
939 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
940 }
941 fdt_setprop(blob, np, "interrupt-map", imap_new,
942 sizeof(imap_new));
943 reg[0] = cpu_to_fdt32(0xfff00);
944 reg[1] = 0;
945 reg[2] = 0;
946 reg[3] = cpu_to_fdt32(0x7);
947 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
948 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
949 fdt_setprop_string(blob, np, "device_type", "pci");
950 fdt_setprop_cell(blob, np, "#address-cells", 3);
951 fdt_setprop_cell(blob, np, "#size-cells", 2);
952 printf(" Added custom interrupt-map for GW16082\n");
953
954 return 0;
955}
956
Tim Harvey77b82a12016-06-17 06:10:42 -0700957/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
958int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
959{
960 char *tmp, *end;
961 char mac[16];
962 unsigned char mac_addr[6];
963 int j;
964
965 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -0600966 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -0700967 if (tmp) {
968 for (j = 0; j < 6; j++) {
969 mac_addr[j] = tmp ?
970 simple_strtoul(tmp, &end,16) : 0;
971 if (tmp)
972 tmp = (*end) ? end+1 : end;
973 }
974 fdt_setprop(blob, np, "local-mac-address", mac_addr,
975 sizeof(mac_addr));
976 printf(" Added mac addr for eth1\n");
977 return 0;
978 }
979
980 return -1;
981}
982
Tim Harveybfb240a2016-06-17 06:10:41 -0700983/*
984 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
985 * we will walk the PCI bus and add bridge nodes up to the device receiving
986 * the fixup.
987 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900988void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -0700989{
990 int i, np;
991 struct pci_dev *dev;
992
993 for (i = 0; i < pci_devno; i++) {
994 dev = &pci_devs[i];
995
996 /*
997 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
998 * an EEPROM at i2c1-0x50.
999 */
1000 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1001 (dev->device == 0x8240) &&
1002 (i2c_set_bus_num(1) == 0) &&
1003 (i2c_probe(0x50) == 0))
1004 {
1005 np = fdt_add_pci_path(blob, dev);
1006 if (np > 0)
1007 fdt_fixup_gw16082(blob, np, dev);
1008 }
Tim Harvey77b82a12016-06-17 06:10:42 -07001009
1010 /* ethernet1 mac address */
1011 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1012 (dev->device == 0x4380))
1013 {
1014 np = fdt_add_pci_path(blob, dev);
1015 if (np > 0)
1016 fdt_fixup_sky2(blob, np, dev);
1017 }
Tim Harveybfb240a2016-06-17 06:10:41 -07001018 }
1019}
1020#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001021
Tim Harvey984aa0d2019-02-04 13:11:00 -08001022void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001023{
Tim Harvey984aa0d2019-02-04 13:11:00 -08001024 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1025
1026 if (off) {
1027 fdt_delprop(blob, off, "ext-reset-output");
1028 fdt_delprop(blob, off, "fsl,ext-reset-output");
1029 }
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001030}
1031
Tim Harvey552c3582014-03-06 07:46:30 -08001032/*
1033 * called prior to booting kernel or by 'fdt boardsetup' command
1034 *
1035 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1036 * - mtd partitions based on mtdparts/mtdids env
1037 * - system-serial (board serial num from EEPROM)
1038 * - board (full model from EEPROM)
1039 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1040 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001041#define WDOG1_ADDR 0x20bc000
1042#define WDOG2_ADDR 0x20c0000
1043#define GPIO3_ADDR 0x20a4000
1044#define USDHC3_ADDR 0x2198000
1045#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001046int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001047{
Tim Harvey552c3582014-03-06 07:46:30 -08001048 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001049 struct ventana_eeprom_config *cfg;
Masahiro Yamada20ead6f2018-07-19 16:28:23 +09001050 static const struct node_info nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001051 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1052 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1053 };
Simon Glass64b723f2017-08-03 12:22:12 -06001054 const char *model = env_get("model");
1055 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001056 int i;
1057 char rev = 0;
1058
1059 /* determine board revision */
1060 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1061 if (ventana_info.model[i] >= 'A') {
1062 rev = ventana_info.model[i];
1063 break;
1064 }
1065 }
Tim Harvey552c3582014-03-06 07:46:30 -08001066
Simon Glass64b723f2017-08-03 12:22:12 -06001067 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001068 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001069 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001070 }
1071
Tim Harveyc9e43e02015-05-26 11:04:58 -07001072 if (test_bit(EECONFIG_NAND, info->config)) {
1073 /* Update partition nodes using info from mtdparts env var */
1074 puts(" Updating MTD partitions...\n");
1075 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1076 }
Tim Harvey552c3582014-03-06 07:46:30 -08001077
Tim Harveye4af5d32015-04-08 12:54:58 -07001078 /* Update display timings from display env var */
1079 if (display) {
1080 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1081 display) >= 0)
1082 printf(" Set display timings for %s...\n", display);
1083 }
1084
Tim Harvey552c3582014-03-06 07:46:30 -08001085 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1086
1087 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001088 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1089 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001090
1091 /* board (model contains model from device-tree) */
1092 fdt_setprop(blob, 0, "board", info->model,
1093 strlen((const char *)info->model) + 1);
1094
Tim Harveycf20e552015-04-08 12:55:01 -07001095 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001096 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001097
Tim Harvey552c3582014-03-06 07:46:30 -08001098 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001099 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001100 */
Tim Harveya1d32222016-07-15 07:16:28 -07001101 switch (board_type) {
1102 case GW51xx:
1103 /*
1104 * disable wdog node for GW51xx-A/B to work around
1105 * errata causing wdog timer to be unreliable.
1106 */
1107 if (rev >= 'A' && rev < 'C') {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001108 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1109 WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001110 if (i)
1111 fdt_status_disabled(blob, i);
1112 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001113
1114 /* GW51xx-E adds WDOG1_B external reset */
1115 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001116 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001117 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001118
Tim Harveya1d32222016-07-15 07:16:28 -07001119 case GW52xx:
1120 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1121 if (info->model[4] == '2') {
1122 u32 handle = 0;
1123 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001124
Tim Harveya1d32222016-07-15 07:16:28 -07001125 i = fdt_node_offset_by_compatible(blob, -1,
1126 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001127 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001128 range = (u32 *)fdt_getprop(blob, i,
1129 "reset-gpio", NULL);
1130
1131 if (range) {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001132 i = fdt_node_offset_by_compat_reg(blob,
1133 "fsl,imx6q-gpio", GPIO3_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001134 if (i)
1135 handle = fdt_get_phandle(blob, i);
1136 if (handle) {
1137 range[0] = cpu_to_fdt32(handle);
1138 range[1] = cpu_to_fdt32(23);
1139 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001140 }
Tim Harveya1d32222016-07-15 07:16:28 -07001141
1142 /* these have broken usd_vsel */
1143 if (strstr((const char *)info->model, "SP318-B") ||
1144 strstr((const char *)info->model, "SP331-B"))
1145 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001146
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001147 /* GW522x-B adds WDOG1_B external reset */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001148 if (rev < 'B')
1149 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Pushpal Sidhud1100562015-04-08 12:55:00 -07001150 }
Tim Harveydc5996a2017-05-15 10:05:06 -07001151
1152 /* GW520x-E adds WDOG1_B external reset */
1153 else if (info->model[4] == '0' && rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001154 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001155 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001156
Tim Harveya1d32222016-07-15 07:16:28 -07001157 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001158 /* GW53xx-E adds WDOG1_B external reset */
1159 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001160 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001161 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001162
Tim Harveya1d32222016-07-15 07:16:28 -07001163 case GW54xx:
1164 /*
1165 * disable serial2 node for GW54xx for compatibility with older
1166 * 3.10.x kernel that improperly had this node enabled in the DT
1167 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001168 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1169 0);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001170
1171 /* GW54xx-E adds WDOG2_B external reset */
1172 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001173 ft_board_wdog_fixup(blob, WDOG2_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001174 break;
1175
1176 case GW551x:
1177 /*
1178 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1179 * causing non functional digital video in (it is not hooked up)
1180 */
1181 if (rev == 'A') {
1182 u32 *range = NULL;
1183 int len;
1184 const u32 *handle = NULL;
1185
1186 i = fdt_node_offset_by_compatible(blob, -1,
1187 "fsl,imx-tda1997x-video");
1188 if (i)
1189 handle = fdt_getprop(blob, i, "pinctrl-0",
1190 NULL);
1191 if (handle)
1192 i = fdt_node_offset_by_phandle(blob,
1193 fdt32_to_cpu(*handle));
1194 if (i)
1195 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1196 &len);
1197 if (range) {
1198 len /= sizeof(u32);
1199 for (i = 0; i < len; i += 6) {
1200 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1201 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1202 /* mux PAD_CSI0_DATA_EN to GPIO */
1203 if (is_cpu_type(MXC_CPU_MX6Q) &&
1204 mux_reg == 0x260 &&
1205 conf_reg == 0x630)
1206 range[i+3] = cpu_to_fdt32(0x5);
1207 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1208 mux_reg == 0x08c &&
1209 conf_reg == 0x3a0)
1210 range[i+3] = cpu_to_fdt32(0x5);
1211 }
1212 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1213 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001214 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001215
Tim Harveya1d32222016-07-15 07:16:28 -07001216 /* set BT656 video format */
1217 ft_sethdmiinfmt(blob, "yuv422bt656");
1218 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001219
1220 /* GW551x-C adds WDOG1_B external reset */
1221 if (rev < 'C')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001222 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001223 break;
Tim Harvey5852a332019-02-04 13:10:58 -08001224 case GW5901:
1225 case GW5902:
1226 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1227 if (rev < 'B')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001228 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harvey5852a332019-02-04 13:10:58 -08001229 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001230 }
1231
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001232 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001233 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001234 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1235 char arg[10];
1236
1237 sprintf(arg, "dio%d", i);
1238 if (!hwconfig(arg))
1239 continue;
1240 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1241 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001242 phys_addr_t addr;
1243 int off;
1244
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001245 printf(" Enabling pwm%d for DIO%d\n",
1246 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001247 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1248 off = fdt_node_offset_by_compat_reg(blob,
1249 "fsl,imx6q-pwm",
1250 addr);
1251 if (off)
1252 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001253 }
1254 }
1255
Tim Harvey147b5762016-05-24 11:03:59 -07001256 /* remove no-1-8-v if UHS-I support is present */
1257 if (gpio_cfg[board_type].usd_vsel) {
1258 debug("Enabling UHS-I support\n");
Tim Harvey984aa0d2019-02-04 13:11:00 -08001259 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1260 USDHC3_ADDR);
1261 if (i)
1262 fdt_delprop(blob, i, "no-1-8-v");
Tim Harvey147b5762016-05-24 11:03:59 -07001263 }
1264
Tim Harveybfb240a2016-06-17 06:10:41 -07001265#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001266 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001267 ft_board_pci_fixup(blob, bd);
1268#endif
1269
Tim Harvey6944ccf2015-04-08 12:54:53 -07001270 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001271 * Peripheral Config:
1272 * remove nodes by alias path if EEPROM config tells us the
1273 * peripheral is not loaded on the board.
1274 */
Simon Glass64b723f2017-08-03 12:22:12 -06001275 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001276 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001277 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001278 }
1279 cfg = econfig;
1280 while (cfg->name) {
1281 if (!test_bit(cfg->bit, info->config)) {
1282 fdt_del_node_and_alias(blob, cfg->dtalias ?
1283 cfg->dtalias : cfg->name);
1284 }
1285 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001286 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001287
1288 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001289}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001290#endif /* CONFIG_OF_BOARD_SETUP */