blob: 6c818643192836a08c12ed91d1f163cd19cf59b9 [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 Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Tim Harvey552c3582014-03-06 07:46:30 -080010#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070011#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080012#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070014#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/boot_mode.h>
18#include <asm/mach-imx/sata.h>
19#include <asm/mach-imx/spi.h>
20#include <asm/mach-imx/video.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070021#include <asm/io.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060022#include <asm/setup.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070023#include <dm.h>
Tim Harvey67ed7922015-05-08 18:28:29 -070024#include <dm/platform_data/serial_mxc.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060025#include <env.h>
Tim Harvey8d2d8df2016-05-24 11:03:55 -070026#include <hwconfig.h>
Tim Harvey552c3582014-03-06 07:46:30 -080027#include <i2c.h>
Tim Harvey552c3582014-03-06 07:46:30 -080028#include <fdt_support.h>
Yangbo Lu73340382019-06-21 11:42:28 +080029#include <fsl_esdhc_imx.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>
Tim Harvey552c3582014-03-06 07:46:30 -080036#include <power/pmic.h>
Tim Harvey0dff16f2014-05-05 08:22:25 -070037#include <power/ltc3676_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080038#include <power/pfuze100_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080039#include <fdt_support.h>
40#include <jffs2/load_kernel.h>
41#include <spi_flash.h>
42
43#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070044#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080045
46DECLARE_GLOBAL_DATA_PTR;
47
Tim Harvey26993362014-08-07 22:35:49 -070048
Tim Harvey552c3582014-03-06 07:46:30 -080049/*
50 * EEPROM board info struct populated by read_eeprom so that we only have to
51 * read it once.
52 */
Tim Harvey0da2c522014-08-07 22:35:45 -070053struct ventana_board_info ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -080054
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
Tom Rini52a132c2017-05-08 22:14:25 -040081#ifdef CONFIG_CMD_NAND
Tim Harvey8b92bdf2015-04-08 12:54:43 -070082static iomux_v3_cfg_t const nfc_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070083 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
84 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
85 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
86 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
87 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
88 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
89 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
90 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
91 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
92 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
93 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
95 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
97 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080098};
99
Tim Harvey552c3582014-03-06 07:46:30 -0800100static void setup_gpmi_nand(void)
101{
102 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
103
104 /* config gpmi nand iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -0700105 SETUP_IOMUX_PADS(nfc_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800106
107 /* config gpmi and bch clock to 100 MHz */
108 clrsetbits_le32(&mxc_ccm->cs2cdr,
109 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
110 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
111 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
112 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
113 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
114 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
115
116 /* enable gpmi and bch clock gating */
117 setbits_le32(&mxc_ccm->CCGR4,
118 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
119 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
120 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
121 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
122 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
123
124 /* enable apbh clock gating */
125 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
126}
127#endif
128
Tim Harveyf1f41db2015-05-08 18:28:28 -0700129static void setup_iomux_enet(int gpio)
Tim Harvey552c3582014-03-06 07:46:30 -0800130{
Tim Harvey02fb5922014-06-02 16:13:26 -0700131 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800132
133 /* toggle PHY_RST# */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700134 gpio_request(gpio, "phy_rst#");
135 gpio_direction_output(gpio, 0);
Tim Harvey63537792017-03-17 07:30:38 -0700136 mdelay(10);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700137 gpio_set_value(gpio, 1);
Tim Harvey63537792017-03-17 07:30:38 -0700138 mdelay(100);
Tim Harvey552c3582014-03-06 07:46:30 -0800139}
140
Tim Harvey552c3582014-03-06 07:46:30 -0800141#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey8b92bdf2015-04-08 12:54:43 -0700142static iomux_v3_cfg_t const usb_pads[] = {
Tim Harvey26993362014-08-07 22:35:49 -0700143 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
144 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
Tim Harvey02fb5922014-06-02 16:13:26 -0700145 /* OTG PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700146 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800147};
148
149int board_ehci_hcd_init(int port)
150{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700151 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -0800152
Tim Harvey02fb5922014-06-02 16:13:26 -0700153 SETUP_IOMUX_PADS(usb_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800154
Tim Harveydb7edfa2015-05-26 11:04:54 -0700155 /* Reset USB HUB */
156 switch (board_type) {
157 case GW53xx:
158 case GW552x:
Tim Harveyb7c48a92019-02-04 13:10:54 -0800159 case GW5906:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700160 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -0800161 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -0700162 case GW54proto:
163 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700164 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -0800165 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700166 default:
167 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800168 }
169
Tim Harveyf1f41db2015-05-08 18:28:28 -0700170 /* request and toggle hub rst */
171 gpio_request(gpio, "usb_hub_rst#");
172 gpio_direction_output(gpio, 0);
173 mdelay(2);
174 gpio_set_value(gpio, 1);
175
Tim Harvey552c3582014-03-06 07:46:30 -0800176 return 0;
177}
178
179int board_ehci_power(int port, int on)
180{
Tim Harvey9b9e75f2017-03-13 08:51:07 -0700181 /* enable OTG VBUS */
182 if (!port && board_type < GW_UNKNOWN) {
183 if (gpio_cfg[board_type].otgpwr_en)
184 gpio_set_value(gpio_cfg[board_type].otgpwr_en, on);
185 }
Tim Harvey552c3582014-03-06 07:46:30 -0800186 return 0;
187}
188#endif /* CONFIG_USB_EHCI_MX6 */
189
Tim Harvey552c3582014-03-06 07:46:30 -0800190#ifdef CONFIG_MXC_SPI
191iomux_v3_cfg_t const ecspi1_pads[] = {
192 /* SS1 */
Tim Harvey02fb5922014-06-02 16:13:26 -0700193 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
194 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
195 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
196 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800197};
198
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300199int board_spi_cs_gpio(unsigned bus, unsigned cs)
200{
201 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
202}
203
Tim Harvey552c3582014-03-06 07:46:30 -0800204static void setup_spi(void)
205{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700206 gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300207 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
Tim Harvey02fb5922014-06-02 16:13:26 -0700208 SETUP_IOMUX_PADS(ecspi1_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800209}
210#endif
211
212/* configure eth0 PHY board-specific LED behavior */
213int board_phy_config(struct phy_device *phydev)
214{
215 unsigned short val;
216
217 /* Marvel 88E1510 */
218 if (phydev->phy_id == 0x1410dd1) {
219 /*
220 * Page 3, Register 16: LED[2:0] Function Control Register
221 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
222 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
223 */
224 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
225 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
226 val &= 0xff00;
227 val |= 0x0017;
228 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
229 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
230 }
231
Tim Harvey4533c902017-03-17 07:32:21 -0700232 /* TI DP83867 */
233 else if (phydev->phy_id == 0x2000a231) {
234 /* configure register 0x170 for ref CLKOUT */
235 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
236 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
237 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
238 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
239 val &= ~0x1f00;
240 val |= 0x0b00; /* chD tx clock*/
241 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
242 }
243
Tim Harvey552c3582014-03-06 07:46:30 -0800244 if (phydev->drv->config)
245 phydev->drv->config(phydev);
246
247 return 0;
248}
Tim Harvey63537792017-03-17 07:30:38 -0700249
250#ifdef CONFIG_MV88E61XX_SWITCH
251int mv88e61xx_hw_reset(struct phy_device *phydev)
252{
253 struct mii_dev *bus = phydev->bus;
254
255 /* GPIO[0] output, CLK125 */
256 debug("enabling RGMII_REFCLK\n");
257 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
258 0x1a /*MV_SCRATCH_MISC*/,
259 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
260 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
261 0x1a /*MV_SCRATCH_MISC*/,
262 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
263
264 /* RGMII delay - Physical Control register bit[15:14] */
265 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
266 /* forced 1000mbps full-duplex link */
267 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
268 phydev->autoneg = AUTONEG_DISABLE;
269 phydev->speed = SPEED_1000;
270 phydev->duplex = DUPLEX_FULL;
271
Tim Harvey8c9d3932019-02-04 13:10:47 -0800272 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
273 bus->write(bus, 0x10, 0, 0x16, 0x8088);
274 bus->write(bus, 0x11, 0, 0x16, 0x8088);
275 bus->write(bus, 0x12, 0, 0x16, 0x8088);
276 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700277
278 return 0;
279}
280#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800281
282int board_eth_init(bd_t *bis)
283{
Tim Harvey552c3582014-03-06 07:46:30 -0800284#ifdef CONFIG_FEC_MXC
Tim Harvey892068c2016-05-24 11:03:58 -0700285 struct ventana_board_info *info = &ventana_info;
286
287 if (test_bit(EECONFIG_ETH0, info->config)) {
Tim Harveyf1f41db2015-05-08 18:28:28 -0700288 setup_iomux_enet(GP_PHY_RST);
Tim Harvey50581832014-08-20 23:35:14 -0700289 cpu_eth_init(bis);
Tim Harvey85331822015-04-08 12:54:48 -0700290 }
Tim Harvey552c3582014-03-06 07:46:30 -0800291#endif
292
Tim Harvey472884d2015-04-08 12:54:32 -0700293#ifdef CONFIG_E1000
294 e1000_initialize(bis);
295#endif
296
Tim Harvey552c3582014-03-06 07:46:30 -0800297#ifdef CONFIG_CI_UDC
298 /* For otg ethernet*/
299 usb_eth_initialize(bis);
300#endif
301
Tim Harveyfc5ff942015-04-08 12:54:33 -0700302 /* default to the first detected enet dev */
Simon Glass64b723f2017-08-03 12:22:12 -0600303 if (!env_get("ethprime")) {
Tim Harveyfc5ff942015-04-08 12:54:33 -0700304 struct eth_device *dev = eth_get_dev_by_index(0);
305 if (dev) {
Simon Glass6a38e412017-08-03 12:22:09 -0600306 env_set("ethprime", dev->name);
Simon Glass64b723f2017-08-03 12:22:12 -0600307 printf("set ethprime to %s\n", env_get("ethprime"));
Tim Harveyfc5ff942015-04-08 12:54:33 -0700308 }
309 }
310
Tim Harvey552c3582014-03-06 07:46:30 -0800311 return 0;
312}
313
Tim Harveyfb64cc72014-04-25 15:39:07 -0700314#if defined(CONFIG_VIDEO_IPUV3)
315
316static void enable_hdmi(struct display_info_t const *dev)
317{
318 imx_enable_hdmi_phy();
319}
320
321static int detect_i2c(struct display_info_t const *dev)
322{
323 return i2c_set_bus_num(dev->bus) == 0 &&
324 i2c_probe(dev->addr) == 0;
325}
326
327static void enable_lvds(struct display_info_t const *dev)
328{
329 struct iomuxc *iomux = (struct iomuxc *)
330 IOMUXC_BASE_ADDR;
331
332 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
333 u32 reg = readl(&iomux->gpr[2]);
334 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
335 writel(reg, &iomux->gpr[2]);
336
337 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700338 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
339 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700340 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700341 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700342 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
343}
344
345struct display_info_t const displays[] = {{
346 /* HDMI Output */
347 .bus = -1,
348 .addr = 0,
349 .pixfmt = IPU_PIX_FMT_RGB24,
350 .detect = detect_hdmi,
351 .enable = enable_hdmi,
352 .mode = {
353 .name = "HDMI",
354 .refresh = 60,
355 .xres = 1024,
356 .yres = 768,
357 .pixclock = 15385,
358 .left_margin = 220,
359 .right_margin = 40,
360 .upper_margin = 21,
361 .lower_margin = 7,
362 .hsync_len = 60,
363 .vsync_len = 10,
364 .sync = FB_SYNC_EXT,
365 .vmode = FB_VMODE_NONINTERLACED
366} }, {
367 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
368 .bus = 2,
369 .addr = 0x4,
370 .pixfmt = IPU_PIX_FMT_LVDS666,
371 .detect = detect_i2c,
372 .enable = enable_lvds,
373 .mode = {
374 .name = "Hannstar-XGA",
375 .refresh = 60,
376 .xres = 1024,
377 .yres = 768,
378 .pixclock = 15385,
379 .left_margin = 220,
380 .right_margin = 40,
381 .upper_margin = 21,
382 .lower_margin = 7,
383 .hsync_len = 60,
384 .vsync_len = 10,
385 .sync = FB_SYNC_EXT,
386 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700387} }, {
388 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800389 .bus = 2,
390 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700391 .detect = NULL,
392 .enable = enable_lvds,
393 .pixfmt = IPU_PIX_FMT_LVDS666,
394 .mode = {
395 .name = "DLC700JMGT4",
396 .refresh = 60,
397 .xres = 1024, /* 1024x600active pixels */
398 .yres = 600,
399 .pixclock = 15385, /* 64MHz */
400 .left_margin = 220,
401 .right_margin = 40,
402 .upper_margin = 21,
403 .lower_margin = 7,
404 .hsync_len = 60,
405 .vsync_len = 10,
406 .sync = FB_SYNC_EXT,
407 .vmode = FB_VMODE_NONINTERLACED
408} }, {
409 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800410 .bus = 2,
411 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700412 .detect = NULL,
413 .enable = enable_lvds,
414 .pixfmt = IPU_PIX_FMT_LVDS666,
415 .mode = {
416 .name = "DLC800FIGT3",
417 .refresh = 60,
418 .xres = 1024, /* 1024x768 active pixels */
419 .yres = 768,
420 .pixclock = 15385, /* 64MHz */
421 .left_margin = 220,
422 .right_margin = 40,
423 .upper_margin = 21,
424 .lower_margin = 7,
425 .hsync_len = 60,
426 .vsync_len = 10,
427 .sync = FB_SYNC_EXT,
428 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800429} }, {
430 .bus = 2,
431 .addr = 0x5d,
432 .detect = detect_i2c,
433 .enable = enable_lvds,
434 .pixfmt = IPU_PIX_FMT_LVDS666,
435 .mode = {
436 .name = "Z101WX01",
437 .refresh = 60,
438 .xres = 1280,
439 .yres = 800,
440 .pixclock = 15385, /* 64MHz */
441 .left_margin = 220,
442 .right_margin = 40,
443 .upper_margin = 21,
444 .lower_margin = 7,
445 .hsync_len = 60,
446 .vsync_len = 10,
447 .sync = FB_SYNC_EXT,
448 .vmode = FB_VMODE_NONINTERLACED
449 }
450},
451};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700452size_t display_count = ARRAY_SIZE(displays);
453
454static void setup_display(void)
455{
456 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
457 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
458 int reg;
459
460 enable_ipu_clock();
461 imx_setup_hdmi();
462 /* Turn on LDB0,IPU,IPU DI0 clocks */
463 reg = __raw_readl(&mxc_ccm->CCGR3);
464 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
465 writel(reg, &mxc_ccm->CCGR3);
466
467 /* set LDB0, LDB1 clk select to 011/011 */
468 reg = readl(&mxc_ccm->cs2cdr);
469 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
470 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
471 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
472 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
473 writel(reg, &mxc_ccm->cs2cdr);
474
475 reg = readl(&mxc_ccm->cscmr2);
476 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
477 writel(reg, &mxc_ccm->cscmr2);
478
479 reg = readl(&mxc_ccm->chsccdr);
480 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
481 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
482 writel(reg, &mxc_ccm->chsccdr);
483
484 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
485 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
486 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
487 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
488 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
489 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
490 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
491 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
492 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
493 writel(reg, &iomux->gpr[2]);
494
495 reg = readl(&iomux->gpr[3]);
496 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
497 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
498 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
499 writel(reg, &iomux->gpr[3]);
500
Tim Harveya67e07f2016-05-24 11:03:53 -0700501 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700502 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700503 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
504}
505#endif /* CONFIG_VIDEO_IPUV3 */
506
Tim Harvey0dff16f2014-05-05 08:22:25 -0700507/* setup board specific PMIC */
508int power_init_board(void)
509{
Tim Harvey195bc972015-05-08 18:28:37 -0700510 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700511 return 0;
512}
513
Tim Harvey552c3582014-03-06 07:46:30 -0800514#if defined(CONFIG_CMD_PCI)
515int imx6_pcie_toggle_reset(void)
516{
517 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700518 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700519 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700520 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800521 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700522 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800523 }
524 return 0;
525}
Tim Harvey33791d52014-08-07 22:49:57 -0700526
527/*
528 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
529 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
530 * properly and assert reset for 100ms.
531 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700532#define MAX_PCI_DEVS 32
533struct pci_dev {
534 pci_dev_t devfn;
535 unsigned short vendor;
536 unsigned short device;
537 unsigned short class;
538 unsigned short busno; /* subbordinate busno */
539 struct pci_dev *ppar;
540};
541struct pci_dev pci_devs[MAX_PCI_DEVS];
542int pci_devno;
543int pci_bridgeno;
544
Tim Harvey33791d52014-08-07 22:49:57 -0700545void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
546 unsigned short vendor, unsigned short device,
547 unsigned short class)
548{
Tim Harveybfb240a2016-06-17 06:10:41 -0700549 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700550 u32 dw;
Tim Harveybfb240a2016-06-17 06:10:41 -0700551 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey33791d52014-08-07 22:49:57 -0700552
553 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
554 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700555
556 /* store array of devs for later use in device-tree fixup */
557 pdev->devfn = dev;
558 pdev->vendor = vendor;
559 pdev->device = device;
560 pdev->class = class;
561 pdev->ppar = NULL;
562 if (class == PCI_CLASS_BRIDGE_PCI)
563 pdev->busno = ++pci_bridgeno;
564 else
565 pdev->busno = 0;
566
567 /* fixup RC - it should be 00:00.0 not 00:01.0 */
568 if (PCI_BUS(dev) == 0)
569 pdev->devfn = 0;
570
571 /* find dev's parent */
572 for (i = 0; i < pci_devno; i++) {
573 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
574 pdev->ppar = &pci_devs[i];
575 break;
576 }
577 }
578
579 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700580 if (vendor == PCI_VENDOR_ID_PLX &&
581 (device & 0xfff0) == 0x8600 &&
582 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
583 debug("configuring PLX 860X downstream PERST#\n");
584 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
585 dw |= 0xaaa8; /* GPIO1-7 outputs */
586 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
587
588 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
589 dw |= 0xfe; /* GPIO1-7 output high */
590 pci_hose_write_config_dword(hose, dev, 0x644, dw);
591
592 mdelay(100);
593 }
594}
Tim Harvey552c3582014-03-06 07:46:30 -0800595#endif /* CONFIG_CMD_PCI */
596
597#ifdef CONFIG_SERIAL_TAG
598/*
599 * called when setting up ATAGS before booting kernel
600 * populate serialnum from the following (in order of priority):
601 * serial# env var
602 * eeprom
603 */
604void get_board_serial(struct tag_serialnr *serialnr)
605{
Simon Glass64b723f2017-08-03 12:22:12 -0600606 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800607
608 if (serial) {
609 serialnr->high = 0;
610 serialnr->low = simple_strtoul(serial, NULL, 10);
611 } else if (ventana_info.model[0]) {
612 serialnr->high = 0;
613 serialnr->low = ventana_info.serial;
614 } else {
615 serialnr->high = 0;
616 serialnr->low = 0;
617 }
618}
619#endif
620
621/*
622 * Board Support
623 */
624
625int board_early_init_f(void)
626{
627 setup_iomux_uart();
Tim Harveyf1f41db2015-05-08 18:28:28 -0700628
Tim Harveyfb64cc72014-04-25 15:39:07 -0700629#if defined(CONFIG_VIDEO_IPUV3)
630 setup_display();
631#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800632 return 0;
633}
634
635int dram_init(void)
636{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700637 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800638 return 0;
639}
640
641int board_init(void)
642{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300643 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800644
645 clrsetbits_le32(&iomuxc_regs->gpr[1],
646 IOMUXC_GPR1_OTG_ID_MASK,
647 IOMUXC_GPR1_OTG_ID_GPIO1);
648
649 /* address of linux boot parameters */
650 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
651
Tim Harveyba9f2342019-02-04 13:10:52 -0800652 /* read Gateworks EEPROM into global struct (used later) */
653 setup_ventana_i2c(0);
654 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
655
Tim Harvey552c3582014-03-06 07:46:30 -0800656#ifdef CONFIG_CMD_NAND
Tim Harveyba9f2342019-02-04 13:10:52 -0800657 if (gpio_cfg[board_type].nand)
658 setup_gpmi_nand();
Tim Harvey552c3582014-03-06 07:46:30 -0800659#endif
660#ifdef CONFIG_MXC_SPI
661 setup_spi();
662#endif
Tim Harveyd04dc812019-02-04 13:10:49 -0800663 setup_ventana_i2c(1);
664 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800665
Simon Glassab3055a2017-06-14 21:28:25 -0600666#ifdef CONFIG_SATA
Tim Harvey552c3582014-03-06 07:46:30 -0800667 setup_sata();
668#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800669
Tim Harvey0cee2242015-05-08 18:28:35 -0700670 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800671
672 return 0;
673}
674
675#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
676/*
677 * called during late init (after relocation and after board_init())
678 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
679 * EEPROM read.
680 */
681int checkboard(void)
682{
683 struct ventana_board_info *info = &ventana_info;
684 unsigned char buf[4];
685 const char *p;
686 int quiet; /* Quiet or minimal output mode */
687
688 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600689 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800690 if (p)
691 quiet = simple_strtol(p, NULL, 10);
692 else
Simon Glass6a38e412017-08-03 12:22:09 -0600693 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800694
695 puts("\nGateworks Corporation Copyright 2014\n");
696 if (info->model[0]) {
697 printf("Model: %s\n", info->model);
698 printf("MFGDate: %02x-%02x-%02x%02x\n",
699 info->mfgdate[0], info->mfgdate[1],
700 info->mfgdate[2], info->mfgdate[3]);
701 printf("Serial:%d\n", info->serial);
702 } else {
703 puts("Invalid EEPROM - board will not function fully\n");
704 }
705 if (quiet)
706 return 0;
707
708 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700709 gsc_info(0);
710
Tim Harvey552c3582014-03-06 07:46:30 -0800711 /* Display RTC */
712 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
713 printf("RTC: %d\n",
714 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
715 }
716
717 return 0;
718}
719#endif
720
721#ifdef CONFIG_CMD_BMODE
722/*
723 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
724 * see Table 8-11 and Table 5-9
725 * BOOT_CFG1[7] = 1 (boot from NAND)
726 * BOOT_CFG1[5] = 0 - raw NAND
727 * BOOT_CFG1[4] = 0 - default pad settings
728 * BOOT_CFG1[3:2] = 00 - devices = 1
729 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
730 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
731 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
732 * BOOT_CFG2[0] = 0 - Reset time 12ms
733 */
734static const struct boot_mode board_boot_modes[] = {
735 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
736 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700737 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800738 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800739 { NULL, 0 },
740};
741#endif
742
743/* late init */
744int misc_init_r(void)
745{
746 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700747 char buf[256];
748 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800749
750 /* set env vars based on EEPROM data */
751 if (ventana_info.model[0]) {
752 char str[16], fdt[36];
753 char *p;
754 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800755
756 /*
757 * FDT name will be prefixed with CPU type. Three versions
758 * will be created each increasingly generic and bootloader
759 * env scripts will try loading each from most specific to
760 * least.
761 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700762 if (is_cpu_type(MXC_CPU_MX6Q) ||
763 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800764 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700765 else if (is_cpu_type(MXC_CPU_MX6DL) ||
766 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800767 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600768 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700769 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600770 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700771 else
Simon Glass6a38e412017-08-03 12:22:09 -0600772 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800773 memset(str, 0, sizeof(str));
774 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
775 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600776 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600777 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800778 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600779 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800780 }
781 p = strchr(str, '-');
782 if (p) {
783 *p++ = 0;
784
Simon Glass6a38e412017-08-03 12:22:09 -0600785 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700786 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600787 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700788 if (board_type != GW551x &&
789 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700790 board_type != GW553x &&
791 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700792 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800793 str[5] = 'x';
794 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700795 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600796 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800797 }
798
799 /* initialize env from EEPROM */
800 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600801 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600802 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800803 }
804 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600805 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600806 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800807 }
808
809 /* board serial-number */
810 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600811 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700812
813 /* memory MB */
814 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600815 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800816 }
817
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700818 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600819 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700820 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700821 if (gpio_cfg[board_type].rs232_en)
822 strcat(buf, "rs232;");
823 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
824 char buf1[32];
825 sprintf(buf1, "dio%d:mode=gpio;", i);
826 if (strlen(buf) + strlen(buf1) < sizeof(buf))
827 strcat(buf, buf1);
828 }
Simon Glass6a38e412017-08-03 12:22:09 -0600829 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700830 }
Tim Harvey552c3582014-03-06 07:46:30 -0800831
Tim Harvey0cee2242015-05-08 18:28:35 -0700832 /* setup baseboard specific GPIO based on board and env */
833 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800834
835#ifdef CONFIG_CMD_BMODE
836 add_board_boot_modes(board_boot_modes);
837#endif
838
Tim Harvey40feabb2015-05-08 18:28:36 -0700839 /* disable boot watchdog */
840 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800841
842 return 0;
843}
844
Robert P. J. Day3c757002016-05-19 15:23:12 -0400845#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800846
Tim Harveycf20e552015-04-08 12:55:01 -0700847static int ft_sethdmiinfmt(void *blob, char *mode)
848{
849 int off;
850
851 if (!mode)
852 return -EINVAL;
853
854 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
855 if (off < 0)
856 return off;
857
858 if (0 == strcasecmp(mode, "yuv422bt656")) {
859 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
860 0x00, 0x00, 0x00 };
861 mode = "422_ccir";
862 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
863 fdt_setprop_u32(blob, off, "vidout_trc", 1);
864 fdt_setprop_u32(blob, off, "vidout_blc", 1);
865 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
866 printf(" set HDMI input mode to %s\n", mode);
867 } else if (0 == strcasecmp(mode, "yuv422smp")) {
868 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
869 0x82, 0x81, 0x00 };
870 mode = "422_smp";
871 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
872 fdt_setprop_u32(blob, off, "vidout_trc", 0);
873 fdt_setprop_u32(blob, off, "vidout_blc", 0);
874 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
875 printf(" set HDMI input mode to %s\n", mode);
876 } else {
877 return -EINVAL;
878 }
879
880 return 0;
881}
882
Tim Harveybfb240a2016-06-17 06:10:41 -0700883#if defined(CONFIG_CMD_PCI)
884#define PCI_ID(x) ( \
885 (PCI_BUS(x->devfn)<<16)| \
886 (PCI_DEV(x->devfn)<<11)| \
887 (PCI_FUNC(x->devfn)<<8) \
888 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700889int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
890{
891 uint32_t reg[5];
892 char node[32];
893 int np;
894
895 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
896 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
897
898 np = fdt_subnode_offset(blob, par, node);
899 if (np >= 0)
900 return np;
901 np = fdt_add_subnode(blob, par, node);
902 if (np < 0) {
903 printf(" %s failed: no space\n", __func__);
904 return np;
905 }
906
907 memset(reg, 0, sizeof(reg));
908 reg[0] = cpu_to_fdt32(PCI_ID(dev));
909 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
910
911 return np;
912}
913
914/* build a path of nested PCI devs for all bridges passed through */
915int fdt_add_pci_path(void *blob, struct pci_dev *dev)
916{
917 struct pci_dev *bridges[MAX_PCI_DEVS];
918 int k, np;
919
920 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800921 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700922 if (np < 0)
923 return np;
924
925 k = 0;
926 while (dev) {
927 bridges[k++] = dev;
928 dev = dev->ppar;
929 };
930
931 /* now add them the to DT in reverse order */
932 while (k--) {
933 np = fdt_add_pci_node(blob, np, bridges[k]);
934 if (np < 0)
935 break;
936 }
937
938 return np;
939}
940
941/*
942 * The GW16082 has a hardware errata errata such that it's
943 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
944 * of this normal PCI interrupt swizzling will not work so we will
945 * provide an irq-map via device-tree.
946 */
947int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
948{
949 int len;
950 int host;
951 uint32_t imap_new[8*4*4];
952 const uint32_t *imap;
953 uint32_t irq[4];
954 uint32_t reg[4];
955 int i;
956
957 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800958 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700959 if (host < 0) {
960 printf(" %s failed: missing host\n", __func__);
961 return host;
962 }
963
964 /* use interrupt data from root complex's node */
965 imap = fdt_getprop(blob, host, "interrupt-map", &len);
966 if (!imap || len != 128) {
967 printf(" %s failed: invalid interrupt-map\n",
968 __func__);
969 return -FDT_ERR_NOTFOUND;
970 }
971
972 /* obtain irq's of host controller in pin order */
973 for (i = 0; i < 4; i++)
974 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
975
976 /*
977 * determine number of swizzles necessary:
978 * For each bridge we pass through we need to swizzle
979 * the number of the slot we are on.
980 */
981 struct pci_dev *d;
982 int b;
983 b = 0;
984 d = dev->ppar;
985 while(d && d->ppar) {
986 b += PCI_DEV(d->devfn);
987 d = d->ppar;
988 }
989
990 /* create new irq mappings for slots12-15
991 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
992 * J3 AD28 12 INTD INTA
993 * J4 AD29 13 INTC INTD
994 * J5 AD30 14 INTB INTC
995 * J2 AD31 15 INTA INTB
996 */
997 for (i = 0; i < 4; i++) {
998 /* addr matches bus:dev:func */
999 u32 addr = dev->busno << 16 | (12+i) << 11;
1000
1001 /* default cells from root complex */
1002 memcpy(&imap_new[i*32], imap, 128);
1003 /* first cell is PCI device address (BDF) */
1004 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
1005 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
1006 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
1007 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
1008 /* third cell is pin */
1009 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
1010 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
1011 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
1012 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
1013 /* sixth cell is relative interrupt */
1014 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
1015 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
1016 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
1017 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
1018 }
1019 fdt_setprop(blob, np, "interrupt-map", imap_new,
1020 sizeof(imap_new));
1021 reg[0] = cpu_to_fdt32(0xfff00);
1022 reg[1] = 0;
1023 reg[2] = 0;
1024 reg[3] = cpu_to_fdt32(0x7);
1025 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
1026 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
1027 fdt_setprop_string(blob, np, "device_type", "pci");
1028 fdt_setprop_cell(blob, np, "#address-cells", 3);
1029 fdt_setprop_cell(blob, np, "#size-cells", 2);
1030 printf(" Added custom interrupt-map for GW16082\n");
1031
1032 return 0;
1033}
1034
Tim Harvey77b82a12016-06-17 06:10:42 -07001035/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
1036int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
1037{
1038 char *tmp, *end;
1039 char mac[16];
1040 unsigned char mac_addr[6];
1041 int j;
1042
1043 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -06001044 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -07001045 if (tmp) {
1046 for (j = 0; j < 6; j++) {
1047 mac_addr[j] = tmp ?
1048 simple_strtoul(tmp, &end,16) : 0;
1049 if (tmp)
1050 tmp = (*end) ? end+1 : end;
1051 }
1052 fdt_setprop(blob, np, "local-mac-address", mac_addr,
1053 sizeof(mac_addr));
1054 printf(" Added mac addr for eth1\n");
1055 return 0;
1056 }
1057
1058 return -1;
1059}
1060
Tim Harveybfb240a2016-06-17 06:10:41 -07001061/*
1062 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
1063 * we will walk the PCI bus and add bridge nodes up to the device receiving
1064 * the fixup.
1065 */
1066void ft_board_pci_fixup(void *blob, bd_t *bd)
1067{
1068 int i, np;
1069 struct pci_dev *dev;
1070
1071 for (i = 0; i < pci_devno; i++) {
1072 dev = &pci_devs[i];
1073
1074 /*
1075 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
1076 * an EEPROM at i2c1-0x50.
1077 */
1078 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1079 (dev->device == 0x8240) &&
1080 (i2c_set_bus_num(1) == 0) &&
1081 (i2c_probe(0x50) == 0))
1082 {
1083 np = fdt_add_pci_path(blob, dev);
1084 if (np > 0)
1085 fdt_fixup_gw16082(blob, np, dev);
1086 }
Tim Harvey77b82a12016-06-17 06:10:42 -07001087
1088 /* ethernet1 mac address */
1089 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1090 (dev->device == 0x4380))
1091 {
1092 np = fdt_add_pci_path(blob, dev);
1093 if (np > 0)
1094 fdt_fixup_sky2(blob, np, dev);
1095 }
Tim Harveybfb240a2016-06-17 06:10:41 -07001096 }
1097}
1098#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001099
Tim Harvey984aa0d2019-02-04 13:11:00 -08001100void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001101{
Tim Harvey984aa0d2019-02-04 13:11:00 -08001102 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1103
1104 if (off) {
1105 fdt_delprop(blob, off, "ext-reset-output");
1106 fdt_delprop(blob, off, "fsl,ext-reset-output");
1107 }
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001108}
1109
Tim Harvey552c3582014-03-06 07:46:30 -08001110/*
1111 * called prior to booting kernel or by 'fdt boardsetup' command
1112 *
1113 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1114 * - mtd partitions based on mtdparts/mtdids env
1115 * - system-serial (board serial num from EEPROM)
1116 * - board (full model from EEPROM)
1117 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1118 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001119#define WDOG1_ADDR 0x20bc000
1120#define WDOG2_ADDR 0x20c0000
1121#define GPIO3_ADDR 0x20a4000
1122#define USDHC3_ADDR 0x2198000
1123#define PWM0_ADDR 0x2080000
Simon Glass2aec3cc2014-10-23 18:58:47 -06001124int ft_board_setup(void *blob, bd_t *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001125{
Tim Harvey552c3582014-03-06 07:46:30 -08001126 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001127 struct ventana_eeprom_config *cfg;
Masahiro Yamada20ead6f2018-07-19 16:28:23 +09001128 static const struct node_info nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001129 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1130 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1131 };
Simon Glass64b723f2017-08-03 12:22:12 -06001132 const char *model = env_get("model");
1133 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001134 int i;
1135 char rev = 0;
1136
1137 /* determine board revision */
1138 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1139 if (ventana_info.model[i] >= 'A') {
1140 rev = ventana_info.model[i];
1141 break;
1142 }
1143 }
Tim Harvey552c3582014-03-06 07:46:30 -08001144
Simon Glass64b723f2017-08-03 12:22:12 -06001145 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001146 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001147 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001148 }
1149
Tim Harveyc9e43e02015-05-26 11:04:58 -07001150 if (test_bit(EECONFIG_NAND, info->config)) {
1151 /* Update partition nodes using info from mtdparts env var */
1152 puts(" Updating MTD partitions...\n");
1153 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1154 }
Tim Harvey552c3582014-03-06 07:46:30 -08001155
Tim Harveye4af5d32015-04-08 12:54:58 -07001156 /* Update display timings from display env var */
1157 if (display) {
1158 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1159 display) >= 0)
1160 printf(" Set display timings for %s...\n", display);
1161 }
1162
Tim Harvey552c3582014-03-06 07:46:30 -08001163 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1164
1165 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001166 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1167 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001168
1169 /* board (model contains model from device-tree) */
1170 fdt_setprop(blob, 0, "board", info->model,
1171 strlen((const char *)info->model) + 1);
1172
Tim Harveycf20e552015-04-08 12:55:01 -07001173 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001174 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001175
Tim Harvey552c3582014-03-06 07:46:30 -08001176 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001177 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001178 */
Tim Harveya1d32222016-07-15 07:16:28 -07001179 switch (board_type) {
1180 case GW51xx:
1181 /*
1182 * disable wdog node for GW51xx-A/B to work around
1183 * errata causing wdog timer to be unreliable.
1184 */
1185 if (rev >= 'A' && rev < 'C') {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001186 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1187 WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001188 if (i)
1189 fdt_status_disabled(blob, i);
1190 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001191
1192 /* GW51xx-E adds WDOG1_B external reset */
1193 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001194 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001195 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001196
Tim Harveya1d32222016-07-15 07:16:28 -07001197 case GW52xx:
1198 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1199 if (info->model[4] == '2') {
1200 u32 handle = 0;
1201 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001202
Tim Harveya1d32222016-07-15 07:16:28 -07001203 i = fdt_node_offset_by_compatible(blob, -1,
1204 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001205 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001206 range = (u32 *)fdt_getprop(blob, i,
1207 "reset-gpio", NULL);
1208
1209 if (range) {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001210 i = fdt_node_offset_by_compat_reg(blob,
1211 "fsl,imx6q-gpio", GPIO3_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001212 if (i)
1213 handle = fdt_get_phandle(blob, i);
1214 if (handle) {
1215 range[0] = cpu_to_fdt32(handle);
1216 range[1] = cpu_to_fdt32(23);
1217 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001218 }
Tim Harveya1d32222016-07-15 07:16:28 -07001219
1220 /* these have broken usd_vsel */
1221 if (strstr((const char *)info->model, "SP318-B") ||
1222 strstr((const char *)info->model, "SP331-B"))
1223 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001224
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001225 /* GW522x-B adds WDOG1_B external reset */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001226 if (rev < 'B')
1227 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Pushpal Sidhud1100562015-04-08 12:55:00 -07001228 }
Tim Harveydc5996a2017-05-15 10:05:06 -07001229
1230 /* GW520x-E adds WDOG1_B external reset */
1231 else if (info->model[4] == '0' && rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001232 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001233 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001234
Tim Harveya1d32222016-07-15 07:16:28 -07001235 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001236 /* GW53xx-E adds WDOG1_B external reset */
1237 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001238 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001239 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001240
Tim Harveya1d32222016-07-15 07:16:28 -07001241 case GW54xx:
1242 /*
1243 * disable serial2 node for GW54xx for compatibility with older
1244 * 3.10.x kernel that improperly had this node enabled in the DT
1245 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001246 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1247 0);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001248
1249 /* GW54xx-E adds WDOG2_B external reset */
1250 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001251 ft_board_wdog_fixup(blob, WDOG2_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001252 break;
1253
1254 case GW551x:
1255 /*
1256 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1257 * causing non functional digital video in (it is not hooked up)
1258 */
1259 if (rev == 'A') {
1260 u32 *range = NULL;
1261 int len;
1262 const u32 *handle = NULL;
1263
1264 i = fdt_node_offset_by_compatible(blob, -1,
1265 "fsl,imx-tda1997x-video");
1266 if (i)
1267 handle = fdt_getprop(blob, i, "pinctrl-0",
1268 NULL);
1269 if (handle)
1270 i = fdt_node_offset_by_phandle(blob,
1271 fdt32_to_cpu(*handle));
1272 if (i)
1273 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1274 &len);
1275 if (range) {
1276 len /= sizeof(u32);
1277 for (i = 0; i < len; i += 6) {
1278 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1279 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1280 /* mux PAD_CSI0_DATA_EN to GPIO */
1281 if (is_cpu_type(MXC_CPU_MX6Q) &&
1282 mux_reg == 0x260 &&
1283 conf_reg == 0x630)
1284 range[i+3] = cpu_to_fdt32(0x5);
1285 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1286 mux_reg == 0x08c &&
1287 conf_reg == 0x3a0)
1288 range[i+3] = cpu_to_fdt32(0x5);
1289 }
1290 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1291 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001292 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001293
Tim Harveya1d32222016-07-15 07:16:28 -07001294 /* set BT656 video format */
1295 ft_sethdmiinfmt(blob, "yuv422bt656");
1296 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001297
1298 /* GW551x-C adds WDOG1_B external reset */
1299 if (rev < 'C')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001300 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001301 break;
Tim Harvey5852a332019-02-04 13:10:58 -08001302 case GW5901:
1303 case GW5902:
1304 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1305 if (rev < 'B')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001306 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harvey5852a332019-02-04 13:10:58 -08001307 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001308 }
1309
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001310 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001311 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001312 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1313 char arg[10];
1314
1315 sprintf(arg, "dio%d", i);
1316 if (!hwconfig(arg))
1317 continue;
1318 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1319 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001320 phys_addr_t addr;
1321 int off;
1322
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001323 printf(" Enabling pwm%d for DIO%d\n",
1324 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001325 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1326 off = fdt_node_offset_by_compat_reg(blob,
1327 "fsl,imx6q-pwm",
1328 addr);
1329 if (off)
1330 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001331 }
1332 }
1333
Tim Harvey147b5762016-05-24 11:03:59 -07001334 /* remove no-1-8-v if UHS-I support is present */
1335 if (gpio_cfg[board_type].usd_vsel) {
1336 debug("Enabling UHS-I support\n");
Tim Harvey984aa0d2019-02-04 13:11:00 -08001337 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1338 USDHC3_ADDR);
1339 if (i)
1340 fdt_delprop(blob, i, "no-1-8-v");
Tim Harvey147b5762016-05-24 11:03:59 -07001341 }
1342
Tim Harveybfb240a2016-06-17 06:10:41 -07001343#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001344 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001345 ft_board_pci_fixup(blob, bd);
1346#endif
1347
Tim Harvey6944ccf2015-04-08 12:54:53 -07001348 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001349 * Peripheral Config:
1350 * remove nodes by alias path if EEPROM config tells us the
1351 * peripheral is not loaded on the board.
1352 */
Simon Glass64b723f2017-08-03 12:22:12 -06001353 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001354 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001355 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001356 }
1357 cfg = econfig;
1358 while (cfg->name) {
1359 if (!test_bit(cfg->bit, info->config)) {
1360 fdt_del_node_and_alias(blob, cfg->dtalias ?
1361 cfg->dtalias : cfg->name);
1362 }
1363 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001364 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001365
1366 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001367}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001368#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey552c3582014-03-06 07:46:30 -08001369
Tim Harvey67ed7922015-05-08 18:28:29 -07001370static struct mxc_serial_platdata ventana_mxc_serial_plat = {
1371 .reg = (struct mxc_uart *)UART2_BASE,
1372};
1373
1374U_BOOT_DEVICE(ventana_serial) = {
1375 .name = "serial_mxc",
1376 .platdata = &ventana_mxc_serial_plat,
1377};