blob: 2ef213ce0f9ae89c17453bbf6d29959d037d790c [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 Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Tim Harvey552c3582014-03-06 07:46:30 -080011#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070012#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080013#include <asm/arch/iomux.h>
14#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070015#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080016#include <asm/arch/sys_proto.h>
17#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/boot_mode.h>
19#include <asm/mach-imx/sata.h>
20#include <asm/mach-imx/spi.h>
21#include <asm/mach-imx/video.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070022#include <asm/io.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060023#include <asm/setup.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070024#include <dm.h>
Tim Harvey67ed7922015-05-08 18:28:29 -070025#include <dm/platform_data/serial_mxc.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>
Yangbo Lu73340382019-06-21 11:42:28 +080030#include <fsl_esdhc_imx.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070031#include <jffs2/load_kernel.h>
32#include <linux/ctype.h>
Tim Harvey552c3582014-03-06 07:46:30 -080033#include <miiphy.h>
Tim Harvey552c3582014-03-06 07:46:30 -080034#include <mtd_node.h>
35#include <netdev.h>
Tim Harvey33791d52014-08-07 22:49:57 -070036#include <pci.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>
43#include <spi_flash.h>
44
45#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070046#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080047
48DECLARE_GLOBAL_DATA_PTR;
49
Tim Harvey26993362014-08-07 22:35:49 -070050
Tim Harvey552c3582014-03-06 07:46:30 -080051/*
52 * EEPROM board info struct populated by read_eeprom so that we only have to
53 * read it once.
54 */
Tim Harvey0da2c522014-08-07 22:35:45 -070055struct ventana_board_info ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -080056
Tim Harvey8b92bdf2015-04-08 12:54:43 -070057static int board_type;
Tim Harvey552c3582014-03-06 07:46:30 -080058
Tim Harvey552c3582014-03-06 07:46:30 -080059/* ENET */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070060static iomux_v3_cfg_t const enet_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070061 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
62 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
63 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
64 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
65 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
66 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
67 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
68 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
69 MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
71 MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
78 MUX_PAD_CTRL(ENET_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080079 /* PHY nRST */
Tim Harvey26993362014-08-07 22:35:49 -070080 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -080081};
82
Tom Rini52a132c2017-05-08 22:14:25 -040083#ifdef CONFIG_CMD_NAND
Tim Harvey8b92bdf2015-04-08 12:54:43 -070084static iomux_v3_cfg_t const nfc_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070085 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
86 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
87 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
88 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
89 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
90 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
91 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
92 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
93 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
95 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
97 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
98 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
99 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800100};
101
Tim Harvey552c3582014-03-06 07:46:30 -0800102static void setup_gpmi_nand(void)
103{
104 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
105
106 /* config gpmi nand iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -0700107 SETUP_IOMUX_PADS(nfc_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800108
109 /* config gpmi and bch clock to 100 MHz */
110 clrsetbits_le32(&mxc_ccm->cs2cdr,
111 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
112 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
113 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
114 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
115 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
116 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
117
118 /* enable gpmi and bch clock gating */
119 setbits_le32(&mxc_ccm->CCGR4,
120 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
121 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
122 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
123 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
124 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
125
126 /* enable apbh clock gating */
127 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
128}
129#endif
130
Tim Harveyf1f41db2015-05-08 18:28:28 -0700131static void setup_iomux_enet(int gpio)
Tim Harvey552c3582014-03-06 07:46:30 -0800132{
Tim Harvey02fb5922014-06-02 16:13:26 -0700133 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800134
135 /* toggle PHY_RST# */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700136 gpio_request(gpio, "phy_rst#");
137 gpio_direction_output(gpio, 0);
Tim Harvey63537792017-03-17 07:30:38 -0700138 mdelay(10);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700139 gpio_set_value(gpio, 1);
Tim Harvey63537792017-03-17 07:30:38 -0700140 mdelay(100);
Tim Harvey552c3582014-03-06 07:46:30 -0800141}
142
Tim Harvey552c3582014-03-06 07:46:30 -0800143#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey8b92bdf2015-04-08 12:54:43 -0700144static iomux_v3_cfg_t const usb_pads[] = {
Tim Harvey26993362014-08-07 22:35:49 -0700145 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
146 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
Tim Harvey02fb5922014-06-02 16:13:26 -0700147 /* OTG PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700148 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800149};
150
151int board_ehci_hcd_init(int port)
152{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700153 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -0800154
Tim Harvey02fb5922014-06-02 16:13:26 -0700155 SETUP_IOMUX_PADS(usb_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800156
Tim Harveydb7edfa2015-05-26 11:04:54 -0700157 /* Reset USB HUB */
158 switch (board_type) {
159 case GW53xx:
160 case GW552x:
Tim Harveyb7c48a92019-02-04 13:10:54 -0800161 case GW5906:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700162 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -0800163 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -0700164 case GW54proto:
165 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700166 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -0800167 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700168 default:
169 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800170 }
171
Tim Harveyf1f41db2015-05-08 18:28:28 -0700172 /* request and toggle hub rst */
173 gpio_request(gpio, "usb_hub_rst#");
174 gpio_direction_output(gpio, 0);
175 mdelay(2);
176 gpio_set_value(gpio, 1);
177
Tim Harvey552c3582014-03-06 07:46:30 -0800178 return 0;
179}
180
181int board_ehci_power(int port, int on)
182{
Tim Harvey9b9e75f2017-03-13 08:51:07 -0700183 /* enable OTG VBUS */
184 if (!port && board_type < GW_UNKNOWN) {
185 if (gpio_cfg[board_type].otgpwr_en)
186 gpio_set_value(gpio_cfg[board_type].otgpwr_en, on);
187 }
Tim Harvey552c3582014-03-06 07:46:30 -0800188 return 0;
189}
190#endif /* CONFIG_USB_EHCI_MX6 */
191
Tim Harvey552c3582014-03-06 07:46:30 -0800192#ifdef CONFIG_MXC_SPI
193iomux_v3_cfg_t const ecspi1_pads[] = {
194 /* SS1 */
Tim Harvey02fb5922014-06-02 16:13:26 -0700195 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
196 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
197 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
198 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800199};
200
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300201int board_spi_cs_gpio(unsigned bus, unsigned cs)
202{
203 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
204}
205
Tim Harvey552c3582014-03-06 07:46:30 -0800206static void setup_spi(void)
207{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700208 gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300209 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
Tim Harvey02fb5922014-06-02 16:13:26 -0700210 SETUP_IOMUX_PADS(ecspi1_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800211}
212#endif
213
214/* configure eth0 PHY board-specific LED behavior */
215int board_phy_config(struct phy_device *phydev)
216{
217 unsigned short val;
218
219 /* Marvel 88E1510 */
220 if (phydev->phy_id == 0x1410dd1) {
221 /*
222 * Page 3, Register 16: LED[2:0] Function Control Register
223 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
224 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
225 */
226 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
227 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
228 val &= 0xff00;
229 val |= 0x0017;
230 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
231 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
232 }
233
Tim Harvey4533c902017-03-17 07:32:21 -0700234 /* TI DP83867 */
235 else if (phydev->phy_id == 0x2000a231) {
236 /* configure register 0x170 for ref CLKOUT */
237 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
238 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
239 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
240 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
241 val &= ~0x1f00;
242 val |= 0x0b00; /* chD tx clock*/
243 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
244 }
245
Tim Harvey552c3582014-03-06 07:46:30 -0800246 if (phydev->drv->config)
247 phydev->drv->config(phydev);
248
249 return 0;
250}
Tim Harvey63537792017-03-17 07:30:38 -0700251
252#ifdef CONFIG_MV88E61XX_SWITCH
253int mv88e61xx_hw_reset(struct phy_device *phydev)
254{
255 struct mii_dev *bus = phydev->bus;
256
257 /* GPIO[0] output, CLK125 */
258 debug("enabling RGMII_REFCLK\n");
259 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
260 0x1a /*MV_SCRATCH_MISC*/,
261 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
262 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
263 0x1a /*MV_SCRATCH_MISC*/,
264 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
265
266 /* RGMII delay - Physical Control register bit[15:14] */
267 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
268 /* forced 1000mbps full-duplex link */
269 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
270 phydev->autoneg = AUTONEG_DISABLE;
271 phydev->speed = SPEED_1000;
272 phydev->duplex = DUPLEX_FULL;
273
Tim Harvey8c9d3932019-02-04 13:10:47 -0800274 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
275 bus->write(bus, 0x10, 0, 0x16, 0x8088);
276 bus->write(bus, 0x11, 0, 0x16, 0x8088);
277 bus->write(bus, 0x12, 0, 0x16, 0x8088);
278 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700279
280 return 0;
281}
282#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800283
284int board_eth_init(bd_t *bis)
285{
Tim Harvey552c3582014-03-06 07:46:30 -0800286#ifdef CONFIG_FEC_MXC
Tim Harvey892068c2016-05-24 11:03:58 -0700287 struct ventana_board_info *info = &ventana_info;
288
289 if (test_bit(EECONFIG_ETH0, info->config)) {
Tim Harveyf1f41db2015-05-08 18:28:28 -0700290 setup_iomux_enet(GP_PHY_RST);
Tim Harvey50581832014-08-20 23:35:14 -0700291 cpu_eth_init(bis);
Tim Harvey85331822015-04-08 12:54:48 -0700292 }
Tim Harvey552c3582014-03-06 07:46:30 -0800293#endif
294
Tim Harvey472884d2015-04-08 12:54:32 -0700295#ifdef CONFIG_E1000
296 e1000_initialize(bis);
297#endif
298
Tim Harvey552c3582014-03-06 07:46:30 -0800299#ifdef CONFIG_CI_UDC
300 /* For otg ethernet*/
301 usb_eth_initialize(bis);
302#endif
303
Tim Harveyfc5ff942015-04-08 12:54:33 -0700304 /* default to the first detected enet dev */
Simon Glass64b723f2017-08-03 12:22:12 -0600305 if (!env_get("ethprime")) {
Tim Harveyfc5ff942015-04-08 12:54:33 -0700306 struct eth_device *dev = eth_get_dev_by_index(0);
307 if (dev) {
Simon Glass6a38e412017-08-03 12:22:09 -0600308 env_set("ethprime", dev->name);
Simon Glass64b723f2017-08-03 12:22:12 -0600309 printf("set ethprime to %s\n", env_get("ethprime"));
Tim Harveyfc5ff942015-04-08 12:54:33 -0700310 }
311 }
312
Tim Harvey552c3582014-03-06 07:46:30 -0800313 return 0;
314}
315
Tim Harveyfb64cc72014-04-25 15:39:07 -0700316#if defined(CONFIG_VIDEO_IPUV3)
317
318static void enable_hdmi(struct display_info_t const *dev)
319{
320 imx_enable_hdmi_phy();
321}
322
323static int detect_i2c(struct display_info_t const *dev)
324{
325 return i2c_set_bus_num(dev->bus) == 0 &&
326 i2c_probe(dev->addr) == 0;
327}
328
329static void enable_lvds(struct display_info_t const *dev)
330{
331 struct iomuxc *iomux = (struct iomuxc *)
332 IOMUXC_BASE_ADDR;
333
334 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
335 u32 reg = readl(&iomux->gpr[2]);
336 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
337 writel(reg, &iomux->gpr[2]);
338
339 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700340 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
341 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700342 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700343 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700344 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
345}
346
347struct display_info_t const displays[] = {{
348 /* HDMI Output */
349 .bus = -1,
350 .addr = 0,
351 .pixfmt = IPU_PIX_FMT_RGB24,
352 .detect = detect_hdmi,
353 .enable = enable_hdmi,
354 .mode = {
355 .name = "HDMI",
356 .refresh = 60,
357 .xres = 1024,
358 .yres = 768,
359 .pixclock = 15385,
360 .left_margin = 220,
361 .right_margin = 40,
362 .upper_margin = 21,
363 .lower_margin = 7,
364 .hsync_len = 60,
365 .vsync_len = 10,
366 .sync = FB_SYNC_EXT,
367 .vmode = FB_VMODE_NONINTERLACED
368} }, {
369 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
370 .bus = 2,
371 .addr = 0x4,
372 .pixfmt = IPU_PIX_FMT_LVDS666,
373 .detect = detect_i2c,
374 .enable = enable_lvds,
375 .mode = {
376 .name = "Hannstar-XGA",
377 .refresh = 60,
378 .xres = 1024,
379 .yres = 768,
380 .pixclock = 15385,
381 .left_margin = 220,
382 .right_margin = 40,
383 .upper_margin = 21,
384 .lower_margin = 7,
385 .hsync_len = 60,
386 .vsync_len = 10,
387 .sync = FB_SYNC_EXT,
388 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700389} }, {
390 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800391 .bus = 2,
392 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700393 .detect = NULL,
394 .enable = enable_lvds,
395 .pixfmt = IPU_PIX_FMT_LVDS666,
396 .mode = {
397 .name = "DLC700JMGT4",
398 .refresh = 60,
399 .xres = 1024, /* 1024x600active pixels */
400 .yres = 600,
401 .pixclock = 15385, /* 64MHz */
402 .left_margin = 220,
403 .right_margin = 40,
404 .upper_margin = 21,
405 .lower_margin = 7,
406 .hsync_len = 60,
407 .vsync_len = 10,
408 .sync = FB_SYNC_EXT,
409 .vmode = FB_VMODE_NONINTERLACED
410} }, {
411 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800412 .bus = 2,
413 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700414 .detect = NULL,
415 .enable = enable_lvds,
416 .pixfmt = IPU_PIX_FMT_LVDS666,
417 .mode = {
418 .name = "DLC800FIGT3",
419 .refresh = 60,
420 .xres = 1024, /* 1024x768 active pixels */
421 .yres = 768,
422 .pixclock = 15385, /* 64MHz */
423 .left_margin = 220,
424 .right_margin = 40,
425 .upper_margin = 21,
426 .lower_margin = 7,
427 .hsync_len = 60,
428 .vsync_len = 10,
429 .sync = FB_SYNC_EXT,
430 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800431} }, {
432 .bus = 2,
433 .addr = 0x5d,
434 .detect = detect_i2c,
435 .enable = enable_lvds,
436 .pixfmt = IPU_PIX_FMT_LVDS666,
437 .mode = {
438 .name = "Z101WX01",
439 .refresh = 60,
440 .xres = 1280,
441 .yres = 800,
442 .pixclock = 15385, /* 64MHz */
443 .left_margin = 220,
444 .right_margin = 40,
445 .upper_margin = 21,
446 .lower_margin = 7,
447 .hsync_len = 60,
448 .vsync_len = 10,
449 .sync = FB_SYNC_EXT,
450 .vmode = FB_VMODE_NONINTERLACED
451 }
452},
453};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700454size_t display_count = ARRAY_SIZE(displays);
455
456static void setup_display(void)
457{
458 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
459 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
460 int reg;
461
462 enable_ipu_clock();
463 imx_setup_hdmi();
464 /* Turn on LDB0,IPU,IPU DI0 clocks */
465 reg = __raw_readl(&mxc_ccm->CCGR3);
466 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
467 writel(reg, &mxc_ccm->CCGR3);
468
469 /* set LDB0, LDB1 clk select to 011/011 */
470 reg = readl(&mxc_ccm->cs2cdr);
471 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
472 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
473 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
474 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
475 writel(reg, &mxc_ccm->cs2cdr);
476
477 reg = readl(&mxc_ccm->cscmr2);
478 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
479 writel(reg, &mxc_ccm->cscmr2);
480
481 reg = readl(&mxc_ccm->chsccdr);
482 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
483 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
484 writel(reg, &mxc_ccm->chsccdr);
485
486 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
487 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
488 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
489 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
490 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
491 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
492 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
493 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
494 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
495 writel(reg, &iomux->gpr[2]);
496
497 reg = readl(&iomux->gpr[3]);
498 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
499 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
500 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
501 writel(reg, &iomux->gpr[3]);
502
Tim Harveya67e07f2016-05-24 11:03:53 -0700503 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700504 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700505 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
506}
507#endif /* CONFIG_VIDEO_IPUV3 */
508
Tim Harvey0dff16f2014-05-05 08:22:25 -0700509/* setup board specific PMIC */
510int power_init_board(void)
511{
Tim Harvey195bc972015-05-08 18:28:37 -0700512 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700513 return 0;
514}
515
Tim Harvey552c3582014-03-06 07:46:30 -0800516#if defined(CONFIG_CMD_PCI)
517int imx6_pcie_toggle_reset(void)
518{
519 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700520 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700521 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700522 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800523 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700524 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800525 }
526 return 0;
527}
Tim Harvey33791d52014-08-07 22:49:57 -0700528
529/*
530 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
531 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
532 * properly and assert reset for 100ms.
533 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700534#define MAX_PCI_DEVS 32
535struct pci_dev {
536 pci_dev_t devfn;
537 unsigned short vendor;
538 unsigned short device;
539 unsigned short class;
540 unsigned short busno; /* subbordinate busno */
541 struct pci_dev *ppar;
542};
543struct pci_dev pci_devs[MAX_PCI_DEVS];
544int pci_devno;
545int pci_bridgeno;
546
Tim Harvey33791d52014-08-07 22:49:57 -0700547void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
548 unsigned short vendor, unsigned short device,
549 unsigned short class)
550{
Tim Harveybfb240a2016-06-17 06:10:41 -0700551 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700552 u32 dw;
Tim Harveybfb240a2016-06-17 06:10:41 -0700553 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey33791d52014-08-07 22:49:57 -0700554
555 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
556 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700557
558 /* store array of devs for later use in device-tree fixup */
559 pdev->devfn = dev;
560 pdev->vendor = vendor;
561 pdev->device = device;
562 pdev->class = class;
563 pdev->ppar = NULL;
564 if (class == PCI_CLASS_BRIDGE_PCI)
565 pdev->busno = ++pci_bridgeno;
566 else
567 pdev->busno = 0;
568
569 /* fixup RC - it should be 00:00.0 not 00:01.0 */
570 if (PCI_BUS(dev) == 0)
571 pdev->devfn = 0;
572
573 /* find dev's parent */
574 for (i = 0; i < pci_devno; i++) {
575 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
576 pdev->ppar = &pci_devs[i];
577 break;
578 }
579 }
580
581 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700582 if (vendor == PCI_VENDOR_ID_PLX &&
583 (device & 0xfff0) == 0x8600 &&
584 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
585 debug("configuring PLX 860X downstream PERST#\n");
586 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
587 dw |= 0xaaa8; /* GPIO1-7 outputs */
588 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
589
590 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
591 dw |= 0xfe; /* GPIO1-7 output high */
592 pci_hose_write_config_dword(hose, dev, 0x644, dw);
593
594 mdelay(100);
595 }
596}
Tim Harvey552c3582014-03-06 07:46:30 -0800597#endif /* CONFIG_CMD_PCI */
598
599#ifdef CONFIG_SERIAL_TAG
600/*
601 * called when setting up ATAGS before booting kernel
602 * populate serialnum from the following (in order of priority):
603 * serial# env var
604 * eeprom
605 */
606void get_board_serial(struct tag_serialnr *serialnr)
607{
Simon Glass64b723f2017-08-03 12:22:12 -0600608 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800609
610 if (serial) {
611 serialnr->high = 0;
612 serialnr->low = simple_strtoul(serial, NULL, 10);
613 } else if (ventana_info.model[0]) {
614 serialnr->high = 0;
615 serialnr->low = ventana_info.serial;
616 } else {
617 serialnr->high = 0;
618 serialnr->low = 0;
619 }
620}
621#endif
622
623/*
624 * Board Support
625 */
626
627int board_early_init_f(void)
628{
629 setup_iomux_uart();
Tim Harveyf1f41db2015-05-08 18:28:28 -0700630
Tim Harveyfb64cc72014-04-25 15:39:07 -0700631#if defined(CONFIG_VIDEO_IPUV3)
632 setup_display();
633#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800634 return 0;
635}
636
637int dram_init(void)
638{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700639 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800640 return 0;
641}
642
643int board_init(void)
644{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300645 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800646
647 clrsetbits_le32(&iomuxc_regs->gpr[1],
648 IOMUXC_GPR1_OTG_ID_MASK,
649 IOMUXC_GPR1_OTG_ID_GPIO1);
650
651 /* address of linux boot parameters */
652 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
653
Tim Harveyba9f2342019-02-04 13:10:52 -0800654 /* read Gateworks EEPROM into global struct (used later) */
655 setup_ventana_i2c(0);
656 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
657
Tim Harvey552c3582014-03-06 07:46:30 -0800658#ifdef CONFIG_CMD_NAND
Tim Harveyba9f2342019-02-04 13:10:52 -0800659 if (gpio_cfg[board_type].nand)
660 setup_gpmi_nand();
Tim Harvey552c3582014-03-06 07:46:30 -0800661#endif
662#ifdef CONFIG_MXC_SPI
663 setup_spi();
664#endif
Tim Harveyd04dc812019-02-04 13:10:49 -0800665 setup_ventana_i2c(1);
666 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800667
Simon Glassab3055a2017-06-14 21:28:25 -0600668#ifdef CONFIG_SATA
Tim Harvey552c3582014-03-06 07:46:30 -0800669 setup_sata();
670#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800671
Tim Harvey0cee2242015-05-08 18:28:35 -0700672 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800673
674 return 0;
675}
676
677#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
678/*
679 * called during late init (after relocation and after board_init())
680 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
681 * EEPROM read.
682 */
683int checkboard(void)
684{
685 struct ventana_board_info *info = &ventana_info;
686 unsigned char buf[4];
687 const char *p;
688 int quiet; /* Quiet or minimal output mode */
689
690 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600691 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800692 if (p)
693 quiet = simple_strtol(p, NULL, 10);
694 else
Simon Glass6a38e412017-08-03 12:22:09 -0600695 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800696
697 puts("\nGateworks Corporation Copyright 2014\n");
698 if (info->model[0]) {
699 printf("Model: %s\n", info->model);
700 printf("MFGDate: %02x-%02x-%02x%02x\n",
701 info->mfgdate[0], info->mfgdate[1],
702 info->mfgdate[2], info->mfgdate[3]);
703 printf("Serial:%d\n", info->serial);
704 } else {
705 puts("Invalid EEPROM - board will not function fully\n");
706 }
707 if (quiet)
708 return 0;
709
710 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700711 gsc_info(0);
712
Tim Harvey552c3582014-03-06 07:46:30 -0800713 /* Display RTC */
714 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
715 printf("RTC: %d\n",
716 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
717 }
718
719 return 0;
720}
721#endif
722
723#ifdef CONFIG_CMD_BMODE
724/*
725 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
726 * see Table 8-11 and Table 5-9
727 * BOOT_CFG1[7] = 1 (boot from NAND)
728 * BOOT_CFG1[5] = 0 - raw NAND
729 * BOOT_CFG1[4] = 0 - default pad settings
730 * BOOT_CFG1[3:2] = 00 - devices = 1
731 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
732 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
733 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
734 * BOOT_CFG2[0] = 0 - Reset time 12ms
735 */
736static const struct boot_mode board_boot_modes[] = {
737 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
738 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700739 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800740 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800741 { NULL, 0 },
742};
743#endif
744
745/* late init */
746int misc_init_r(void)
747{
748 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700749 char buf[256];
750 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800751
752 /* set env vars based on EEPROM data */
753 if (ventana_info.model[0]) {
754 char str[16], fdt[36];
755 char *p;
756 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800757
758 /*
759 * FDT name will be prefixed with CPU type. Three versions
760 * will be created each increasingly generic and bootloader
761 * env scripts will try loading each from most specific to
762 * least.
763 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700764 if (is_cpu_type(MXC_CPU_MX6Q) ||
765 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800766 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700767 else if (is_cpu_type(MXC_CPU_MX6DL) ||
768 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800769 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600770 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700771 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600772 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700773 else
Simon Glass6a38e412017-08-03 12:22:09 -0600774 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800775 memset(str, 0, sizeof(str));
776 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
777 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600778 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600779 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800780 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600781 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800782 }
783 p = strchr(str, '-');
784 if (p) {
785 *p++ = 0;
786
Simon Glass6a38e412017-08-03 12:22:09 -0600787 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700788 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600789 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700790 if (board_type != GW551x &&
791 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700792 board_type != GW553x &&
793 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700794 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800795 str[5] = 'x';
796 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700797 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600798 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800799 }
800
801 /* initialize env from EEPROM */
802 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600803 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600804 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800805 }
806 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600807 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600808 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800809 }
810
811 /* board serial-number */
812 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600813 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700814
815 /* memory MB */
816 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600817 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800818 }
819
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700820 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600821 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700822 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700823 if (gpio_cfg[board_type].rs232_en)
824 strcat(buf, "rs232;");
825 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
826 char buf1[32];
827 sprintf(buf1, "dio%d:mode=gpio;", i);
828 if (strlen(buf) + strlen(buf1) < sizeof(buf))
829 strcat(buf, buf1);
830 }
Simon Glass6a38e412017-08-03 12:22:09 -0600831 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700832 }
Tim Harvey552c3582014-03-06 07:46:30 -0800833
Tim Harvey0cee2242015-05-08 18:28:35 -0700834 /* setup baseboard specific GPIO based on board and env */
835 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800836
837#ifdef CONFIG_CMD_BMODE
838 add_board_boot_modes(board_boot_modes);
839#endif
840
Tim Harvey40feabb2015-05-08 18:28:36 -0700841 /* disable boot watchdog */
842 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800843
844 return 0;
845}
846
Robert P. J. Day3c757002016-05-19 15:23:12 -0400847#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800848
Tim Harveycf20e552015-04-08 12:55:01 -0700849static int ft_sethdmiinfmt(void *blob, char *mode)
850{
851 int off;
852
853 if (!mode)
854 return -EINVAL;
855
856 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
857 if (off < 0)
858 return off;
859
860 if (0 == strcasecmp(mode, "yuv422bt656")) {
861 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
862 0x00, 0x00, 0x00 };
863 mode = "422_ccir";
864 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
865 fdt_setprop_u32(blob, off, "vidout_trc", 1);
866 fdt_setprop_u32(blob, off, "vidout_blc", 1);
867 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
868 printf(" set HDMI input mode to %s\n", mode);
869 } else if (0 == strcasecmp(mode, "yuv422smp")) {
870 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
871 0x82, 0x81, 0x00 };
872 mode = "422_smp";
873 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
874 fdt_setprop_u32(blob, off, "vidout_trc", 0);
875 fdt_setprop_u32(blob, off, "vidout_blc", 0);
876 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
877 printf(" set HDMI input mode to %s\n", mode);
878 } else {
879 return -EINVAL;
880 }
881
882 return 0;
883}
884
Tim Harveybfb240a2016-06-17 06:10:41 -0700885#if defined(CONFIG_CMD_PCI)
886#define PCI_ID(x) ( \
887 (PCI_BUS(x->devfn)<<16)| \
888 (PCI_DEV(x->devfn)<<11)| \
889 (PCI_FUNC(x->devfn)<<8) \
890 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700891int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
892{
893 uint32_t reg[5];
894 char node[32];
895 int np;
896
897 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
898 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
899
900 np = fdt_subnode_offset(blob, par, node);
901 if (np >= 0)
902 return np;
903 np = fdt_add_subnode(blob, par, node);
904 if (np < 0) {
905 printf(" %s failed: no space\n", __func__);
906 return np;
907 }
908
909 memset(reg, 0, sizeof(reg));
910 reg[0] = cpu_to_fdt32(PCI_ID(dev));
911 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
912
913 return np;
914}
915
916/* build a path of nested PCI devs for all bridges passed through */
917int fdt_add_pci_path(void *blob, struct pci_dev *dev)
918{
919 struct pci_dev *bridges[MAX_PCI_DEVS];
920 int k, np;
921
922 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800923 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700924 if (np < 0)
925 return np;
926
927 k = 0;
928 while (dev) {
929 bridges[k++] = dev;
930 dev = dev->ppar;
931 };
932
933 /* now add them the to DT in reverse order */
934 while (k--) {
935 np = fdt_add_pci_node(blob, np, bridges[k]);
936 if (np < 0)
937 break;
938 }
939
940 return np;
941}
942
943/*
944 * The GW16082 has a hardware errata errata such that it's
945 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
946 * of this normal PCI interrupt swizzling will not work so we will
947 * provide an irq-map via device-tree.
948 */
949int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
950{
951 int len;
952 int host;
953 uint32_t imap_new[8*4*4];
954 const uint32_t *imap;
955 uint32_t irq[4];
956 uint32_t reg[4];
957 int i;
958
959 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800960 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700961 if (host < 0) {
962 printf(" %s failed: missing host\n", __func__);
963 return host;
964 }
965
966 /* use interrupt data from root complex's node */
967 imap = fdt_getprop(blob, host, "interrupt-map", &len);
968 if (!imap || len != 128) {
969 printf(" %s failed: invalid interrupt-map\n",
970 __func__);
971 return -FDT_ERR_NOTFOUND;
972 }
973
974 /* obtain irq's of host controller in pin order */
975 for (i = 0; i < 4; i++)
976 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
977
978 /*
979 * determine number of swizzles necessary:
980 * For each bridge we pass through we need to swizzle
981 * the number of the slot we are on.
982 */
983 struct pci_dev *d;
984 int b;
985 b = 0;
986 d = dev->ppar;
987 while(d && d->ppar) {
988 b += PCI_DEV(d->devfn);
989 d = d->ppar;
990 }
991
992 /* create new irq mappings for slots12-15
993 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
994 * J3 AD28 12 INTD INTA
995 * J4 AD29 13 INTC INTD
996 * J5 AD30 14 INTB INTC
997 * J2 AD31 15 INTA INTB
998 */
999 for (i = 0; i < 4; i++) {
1000 /* addr matches bus:dev:func */
1001 u32 addr = dev->busno << 16 | (12+i) << 11;
1002
1003 /* default cells from root complex */
1004 memcpy(&imap_new[i*32], imap, 128);
1005 /* first cell is PCI device address (BDF) */
1006 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
1007 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
1008 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
1009 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
1010 /* third cell is pin */
1011 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
1012 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
1013 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
1014 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
1015 /* sixth cell is relative interrupt */
1016 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
1017 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
1018 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
1019 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
1020 }
1021 fdt_setprop(blob, np, "interrupt-map", imap_new,
1022 sizeof(imap_new));
1023 reg[0] = cpu_to_fdt32(0xfff00);
1024 reg[1] = 0;
1025 reg[2] = 0;
1026 reg[3] = cpu_to_fdt32(0x7);
1027 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
1028 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
1029 fdt_setprop_string(blob, np, "device_type", "pci");
1030 fdt_setprop_cell(blob, np, "#address-cells", 3);
1031 fdt_setprop_cell(blob, np, "#size-cells", 2);
1032 printf(" Added custom interrupt-map for GW16082\n");
1033
1034 return 0;
1035}
1036
Tim Harvey77b82a12016-06-17 06:10:42 -07001037/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
1038int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
1039{
1040 char *tmp, *end;
1041 char mac[16];
1042 unsigned char mac_addr[6];
1043 int j;
1044
1045 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -06001046 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -07001047 if (tmp) {
1048 for (j = 0; j < 6; j++) {
1049 mac_addr[j] = tmp ?
1050 simple_strtoul(tmp, &end,16) : 0;
1051 if (tmp)
1052 tmp = (*end) ? end+1 : end;
1053 }
1054 fdt_setprop(blob, np, "local-mac-address", mac_addr,
1055 sizeof(mac_addr));
1056 printf(" Added mac addr for eth1\n");
1057 return 0;
1058 }
1059
1060 return -1;
1061}
1062
Tim Harveybfb240a2016-06-17 06:10:41 -07001063/*
1064 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
1065 * we will walk the PCI bus and add bridge nodes up to the device receiving
1066 * the fixup.
1067 */
1068void ft_board_pci_fixup(void *blob, bd_t *bd)
1069{
1070 int i, np;
1071 struct pci_dev *dev;
1072
1073 for (i = 0; i < pci_devno; i++) {
1074 dev = &pci_devs[i];
1075
1076 /*
1077 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
1078 * an EEPROM at i2c1-0x50.
1079 */
1080 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1081 (dev->device == 0x8240) &&
1082 (i2c_set_bus_num(1) == 0) &&
1083 (i2c_probe(0x50) == 0))
1084 {
1085 np = fdt_add_pci_path(blob, dev);
1086 if (np > 0)
1087 fdt_fixup_gw16082(blob, np, dev);
1088 }
Tim Harvey77b82a12016-06-17 06:10:42 -07001089
1090 /* ethernet1 mac address */
1091 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1092 (dev->device == 0x4380))
1093 {
1094 np = fdt_add_pci_path(blob, dev);
1095 if (np > 0)
1096 fdt_fixup_sky2(blob, np, dev);
1097 }
Tim Harveybfb240a2016-06-17 06:10:41 -07001098 }
1099}
1100#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001101
Tim Harvey984aa0d2019-02-04 13:11:00 -08001102void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001103{
Tim Harvey984aa0d2019-02-04 13:11:00 -08001104 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1105
1106 if (off) {
1107 fdt_delprop(blob, off, "ext-reset-output");
1108 fdt_delprop(blob, off, "fsl,ext-reset-output");
1109 }
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001110}
1111
Tim Harvey552c3582014-03-06 07:46:30 -08001112/*
1113 * called prior to booting kernel or by 'fdt boardsetup' command
1114 *
1115 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1116 * - mtd partitions based on mtdparts/mtdids env
1117 * - system-serial (board serial num from EEPROM)
1118 * - board (full model from EEPROM)
1119 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1120 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001121#define WDOG1_ADDR 0x20bc000
1122#define WDOG2_ADDR 0x20c0000
1123#define GPIO3_ADDR 0x20a4000
1124#define USDHC3_ADDR 0x2198000
1125#define PWM0_ADDR 0x2080000
Simon Glass2aec3cc2014-10-23 18:58:47 -06001126int ft_board_setup(void *blob, bd_t *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001127{
Tim Harvey552c3582014-03-06 07:46:30 -08001128 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001129 struct ventana_eeprom_config *cfg;
Masahiro Yamada20ead6f2018-07-19 16:28:23 +09001130 static const struct node_info nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001131 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1132 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1133 };
Simon Glass64b723f2017-08-03 12:22:12 -06001134 const char *model = env_get("model");
1135 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001136 int i;
1137 char rev = 0;
1138
1139 /* determine board revision */
1140 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1141 if (ventana_info.model[i] >= 'A') {
1142 rev = ventana_info.model[i];
1143 break;
1144 }
1145 }
Tim Harvey552c3582014-03-06 07:46:30 -08001146
Simon Glass64b723f2017-08-03 12:22:12 -06001147 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001148 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001149 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001150 }
1151
Tim Harveyc9e43e02015-05-26 11:04:58 -07001152 if (test_bit(EECONFIG_NAND, info->config)) {
1153 /* Update partition nodes using info from mtdparts env var */
1154 puts(" Updating MTD partitions...\n");
1155 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1156 }
Tim Harvey552c3582014-03-06 07:46:30 -08001157
Tim Harveye4af5d32015-04-08 12:54:58 -07001158 /* Update display timings from display env var */
1159 if (display) {
1160 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1161 display) >= 0)
1162 printf(" Set display timings for %s...\n", display);
1163 }
1164
Tim Harvey552c3582014-03-06 07:46:30 -08001165 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1166
1167 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001168 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1169 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001170
1171 /* board (model contains model from device-tree) */
1172 fdt_setprop(blob, 0, "board", info->model,
1173 strlen((const char *)info->model) + 1);
1174
Tim Harveycf20e552015-04-08 12:55:01 -07001175 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001176 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001177
Tim Harvey552c3582014-03-06 07:46:30 -08001178 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001179 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001180 */
Tim Harveya1d32222016-07-15 07:16:28 -07001181 switch (board_type) {
1182 case GW51xx:
1183 /*
1184 * disable wdog node for GW51xx-A/B to work around
1185 * errata causing wdog timer to be unreliable.
1186 */
1187 if (rev >= 'A' && rev < 'C') {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001188 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1189 WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001190 if (i)
1191 fdt_status_disabled(blob, i);
1192 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001193
1194 /* GW51xx-E adds WDOG1_B external reset */
1195 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001196 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001197 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001198
Tim Harveya1d32222016-07-15 07:16:28 -07001199 case GW52xx:
1200 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1201 if (info->model[4] == '2') {
1202 u32 handle = 0;
1203 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001204
Tim Harveya1d32222016-07-15 07:16:28 -07001205 i = fdt_node_offset_by_compatible(blob, -1,
1206 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001207 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001208 range = (u32 *)fdt_getprop(blob, i,
1209 "reset-gpio", NULL);
1210
1211 if (range) {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001212 i = fdt_node_offset_by_compat_reg(blob,
1213 "fsl,imx6q-gpio", GPIO3_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001214 if (i)
1215 handle = fdt_get_phandle(blob, i);
1216 if (handle) {
1217 range[0] = cpu_to_fdt32(handle);
1218 range[1] = cpu_to_fdt32(23);
1219 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001220 }
Tim Harveya1d32222016-07-15 07:16:28 -07001221
1222 /* these have broken usd_vsel */
1223 if (strstr((const char *)info->model, "SP318-B") ||
1224 strstr((const char *)info->model, "SP331-B"))
1225 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001226
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001227 /* GW522x-B adds WDOG1_B external reset */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001228 if (rev < 'B')
1229 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Pushpal Sidhud1100562015-04-08 12:55:00 -07001230 }
Tim Harveydc5996a2017-05-15 10:05:06 -07001231
1232 /* GW520x-E adds WDOG1_B external reset */
1233 else if (info->model[4] == '0' && rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001234 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001235 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001236
Tim Harveya1d32222016-07-15 07:16:28 -07001237 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001238 /* GW53xx-E adds WDOG1_B external reset */
1239 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001240 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001241 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001242
Tim Harveya1d32222016-07-15 07:16:28 -07001243 case GW54xx:
1244 /*
1245 * disable serial2 node for GW54xx for compatibility with older
1246 * 3.10.x kernel that improperly had this node enabled in the DT
1247 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001248 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1249 0);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001250
1251 /* GW54xx-E adds WDOG2_B external reset */
1252 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001253 ft_board_wdog_fixup(blob, WDOG2_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001254 break;
1255
1256 case GW551x:
1257 /*
1258 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1259 * causing non functional digital video in (it is not hooked up)
1260 */
1261 if (rev == 'A') {
1262 u32 *range = NULL;
1263 int len;
1264 const u32 *handle = NULL;
1265
1266 i = fdt_node_offset_by_compatible(blob, -1,
1267 "fsl,imx-tda1997x-video");
1268 if (i)
1269 handle = fdt_getprop(blob, i, "pinctrl-0",
1270 NULL);
1271 if (handle)
1272 i = fdt_node_offset_by_phandle(blob,
1273 fdt32_to_cpu(*handle));
1274 if (i)
1275 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1276 &len);
1277 if (range) {
1278 len /= sizeof(u32);
1279 for (i = 0; i < len; i += 6) {
1280 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1281 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1282 /* mux PAD_CSI0_DATA_EN to GPIO */
1283 if (is_cpu_type(MXC_CPU_MX6Q) &&
1284 mux_reg == 0x260 &&
1285 conf_reg == 0x630)
1286 range[i+3] = cpu_to_fdt32(0x5);
1287 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1288 mux_reg == 0x08c &&
1289 conf_reg == 0x3a0)
1290 range[i+3] = cpu_to_fdt32(0x5);
1291 }
1292 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1293 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001294 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001295
Tim Harveya1d32222016-07-15 07:16:28 -07001296 /* set BT656 video format */
1297 ft_sethdmiinfmt(blob, "yuv422bt656");
1298 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001299
1300 /* GW551x-C adds WDOG1_B external reset */
1301 if (rev < 'C')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001302 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001303 break;
Tim Harvey5852a332019-02-04 13:10:58 -08001304 case GW5901:
1305 case GW5902:
1306 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1307 if (rev < 'B')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001308 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harvey5852a332019-02-04 13:10:58 -08001309 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001310 }
1311
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001312 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001313 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001314 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1315 char arg[10];
1316
1317 sprintf(arg, "dio%d", i);
1318 if (!hwconfig(arg))
1319 continue;
1320 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1321 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001322 phys_addr_t addr;
1323 int off;
1324
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001325 printf(" Enabling pwm%d for DIO%d\n",
1326 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001327 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1328 off = fdt_node_offset_by_compat_reg(blob,
1329 "fsl,imx6q-pwm",
1330 addr);
1331 if (off)
1332 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001333 }
1334 }
1335
Tim Harvey147b5762016-05-24 11:03:59 -07001336 /* remove no-1-8-v if UHS-I support is present */
1337 if (gpio_cfg[board_type].usd_vsel) {
1338 debug("Enabling UHS-I support\n");
Tim Harvey984aa0d2019-02-04 13:11:00 -08001339 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1340 USDHC3_ADDR);
1341 if (i)
1342 fdt_delprop(blob, i, "no-1-8-v");
Tim Harvey147b5762016-05-24 11:03:59 -07001343 }
1344
Tim Harveybfb240a2016-06-17 06:10:41 -07001345#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001346 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001347 ft_board_pci_fixup(blob, bd);
1348#endif
1349
Tim Harvey6944ccf2015-04-08 12:54:53 -07001350 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001351 * Peripheral Config:
1352 * remove nodes by alias path if EEPROM config tells us the
1353 * peripheral is not loaded on the board.
1354 */
Simon Glass64b723f2017-08-03 12:22:12 -06001355 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001356 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001357 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001358 }
1359 cfg = econfig;
1360 while (cfg->name) {
1361 if (!test_bit(cfg->bit, info->config)) {
1362 fdt_del_node_and_alias(blob, cfg->dtalias ?
1363 cfg->dtalias : cfg->name);
1364 }
1365 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001366 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001367
1368 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001369}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001370#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey552c3582014-03-06 07:46:30 -08001371
Tim Harvey67ed7922015-05-08 18:28:29 -07001372static struct mxc_serial_platdata ventana_mxc_serial_plat = {
1373 .reg = (struct mxc_uart *)UART2_BASE,
1374};
1375
1376U_BOOT_DEVICE(ventana_serial) = {
1377 .name = "serial_mxc",
1378 .platdata = &ventana_mxc_serial_plat,
1379};