blob: 71de80c1b91c51d1326626693706f7aabf371a36 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tim Harvey552c3582014-03-06 07:46:30 -08002/*
3 * Copyright (C) 2013 Gateworks Corporation
4 *
5 * Author: Tim Harvey <tharvey@gateworks.com>
Tim Harvey552c3582014-03-06 07:46:30 -08006 */
7
8#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Tim Harvey552c3582014-03-06 07:46:30 -080012#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070013#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080014#include <asm/arch/iomux.h>
15#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070016#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080017#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Tim Harvey552c3582014-03-06 07:46:30 -080019#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/boot_mode.h>
21#include <asm/mach-imx/sata.h>
22#include <asm/mach-imx/spi.h>
23#include <asm/mach-imx/video.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070024#include <asm/io.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060025#include <asm/setup.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070026#include <dm.h>
Tim Harvey67ed7922015-05-08 18:28:29 -070027#include <dm/platform_data/serial_mxc.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060028#include <env.h>
Tim Harvey8d2d8df2016-05-24 11:03:55 -070029#include <hwconfig.h>
Tim Harvey552c3582014-03-06 07:46:30 -080030#include <i2c.h>
Tim Harvey552c3582014-03-06 07:46:30 -080031#include <fdt_support.h>
Yangbo Lu73340382019-06-21 11:42:28 +080032#include <fsl_esdhc_imx.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070033#include <jffs2/load_kernel.h>
34#include <linux/ctype.h>
Tim Harvey552c3582014-03-06 07:46:30 -080035#include <miiphy.h>
Tim Harvey552c3582014-03-06 07:46:30 -080036#include <mtd_node.h>
37#include <netdev.h>
Tim Harvey33791d52014-08-07 22:49:57 -070038#include <pci.h>
Simon Glassdbd79542020-05-10 11:40:11 -060039#include <linux/delay.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060040#include <linux/libfdt.h>
Tim Harvey552c3582014-03-06 07:46:30 -080041#include <power/pmic.h>
Tim Harvey0dff16f2014-05-05 08:22:25 -070042#include <power/ltc3676_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080043#include <power/pfuze100_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080044#include <fdt_support.h>
45#include <jffs2/load_kernel.h>
46#include <spi_flash.h>
47
48#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070049#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080050
51DECLARE_GLOBAL_DATA_PTR;
52
Tim Harvey26993362014-08-07 22:35:49 -070053
Tim Harvey552c3582014-03-06 07:46:30 -080054/*
55 * EEPROM board info struct populated by read_eeprom so that we only have to
56 * read it once.
57 */
Tim Harvey0da2c522014-08-07 22:35:45 -070058struct ventana_board_info ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -080059
Tim Harvey8b92bdf2015-04-08 12:54:43 -070060static int board_type;
Tim Harvey552c3582014-03-06 07:46:30 -080061
Tim Harvey552c3582014-03-06 07:46:30 -080062/* ENET */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070063static iomux_v3_cfg_t const enet_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070064 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
65 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
66 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
67 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
68 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
69 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
71 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
72 MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
74 MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
81 MUX_PAD_CTRL(ENET_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080082 /* PHY nRST */
Tim Harvey26993362014-08-07 22:35:49 -070083 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -080084};
85
Tom Rini52a132c2017-05-08 22:14:25 -040086#ifdef CONFIG_CMD_NAND
Tim Harvey8b92bdf2015-04-08 12:54:43 -070087static iomux_v3_cfg_t const nfc_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070088 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
89 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
90 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
91 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
92 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
93 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
95 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
97 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
98 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
99 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
100 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
101 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
102 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800103};
104
Tim Harvey552c3582014-03-06 07:46:30 -0800105static void setup_gpmi_nand(void)
106{
107 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
108
109 /* config gpmi nand iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -0700110 SETUP_IOMUX_PADS(nfc_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800111
112 /* config gpmi and bch clock to 100 MHz */
113 clrsetbits_le32(&mxc_ccm->cs2cdr,
114 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
115 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
116 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
117 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
118 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
119 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
120
121 /* enable gpmi and bch clock gating */
122 setbits_le32(&mxc_ccm->CCGR4,
123 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
124 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
125 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
126 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
127 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
128
129 /* enable apbh clock gating */
130 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
131}
132#endif
133
Tim Harveyf1f41db2015-05-08 18:28:28 -0700134static void setup_iomux_enet(int gpio)
Tim Harvey552c3582014-03-06 07:46:30 -0800135{
Tim Harvey02fb5922014-06-02 16:13:26 -0700136 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800137
138 /* toggle PHY_RST# */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700139 gpio_request(gpio, "phy_rst#");
140 gpio_direction_output(gpio, 0);
Tim Harvey63537792017-03-17 07:30:38 -0700141 mdelay(10);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700142 gpio_set_value(gpio, 1);
Tim Harvey63537792017-03-17 07:30:38 -0700143 mdelay(100);
Tim Harvey552c3582014-03-06 07:46:30 -0800144}
145
Tim Harvey552c3582014-03-06 07:46:30 -0800146#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey8b92bdf2015-04-08 12:54:43 -0700147static iomux_v3_cfg_t const usb_pads[] = {
Tim Harvey26993362014-08-07 22:35:49 -0700148 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
149 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
Tim Harvey02fb5922014-06-02 16:13:26 -0700150 /* OTG PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700151 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800152};
153
154int board_ehci_hcd_init(int port)
155{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700156 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -0800157
Tim Harvey02fb5922014-06-02 16:13:26 -0700158 SETUP_IOMUX_PADS(usb_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800159
Tim Harveydb7edfa2015-05-26 11:04:54 -0700160 /* Reset USB HUB */
161 switch (board_type) {
162 case GW53xx:
163 case GW552x:
Tim Harveyb7c48a92019-02-04 13:10:54 -0800164 case GW5906:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700165 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -0800166 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -0700167 case GW54proto:
168 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700169 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -0800170 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700171 default:
172 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800173 }
174
Tim Harveyf1f41db2015-05-08 18:28:28 -0700175 /* request and toggle hub rst */
176 gpio_request(gpio, "usb_hub_rst#");
177 gpio_direction_output(gpio, 0);
178 mdelay(2);
179 gpio_set_value(gpio, 1);
180
Tim Harvey552c3582014-03-06 07:46:30 -0800181 return 0;
182}
183
184int board_ehci_power(int port, int on)
185{
Tim Harvey9b9e75f2017-03-13 08:51:07 -0700186 /* enable OTG VBUS */
187 if (!port && board_type < GW_UNKNOWN) {
188 if (gpio_cfg[board_type].otgpwr_en)
189 gpio_set_value(gpio_cfg[board_type].otgpwr_en, on);
190 }
Tim Harvey552c3582014-03-06 07:46:30 -0800191 return 0;
192}
193#endif /* CONFIG_USB_EHCI_MX6 */
194
Tim Harvey552c3582014-03-06 07:46:30 -0800195#ifdef CONFIG_MXC_SPI
196iomux_v3_cfg_t const ecspi1_pads[] = {
197 /* SS1 */
Tim Harvey02fb5922014-06-02 16:13:26 -0700198 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
199 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
200 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
201 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800202};
203
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300204int board_spi_cs_gpio(unsigned bus, unsigned cs)
205{
206 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
207}
208
Tim Harvey552c3582014-03-06 07:46:30 -0800209static void setup_spi(void)
210{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700211 gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300212 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
Tim Harvey02fb5922014-06-02 16:13:26 -0700213 SETUP_IOMUX_PADS(ecspi1_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800214}
215#endif
216
217/* configure eth0 PHY board-specific LED behavior */
218int board_phy_config(struct phy_device *phydev)
219{
220 unsigned short val;
221
222 /* Marvel 88E1510 */
223 if (phydev->phy_id == 0x1410dd1) {
224 /*
225 * Page 3, Register 16: LED[2:0] Function Control Register
226 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
227 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
228 */
229 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
230 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
231 val &= 0xff00;
232 val |= 0x0017;
233 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
234 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
235 }
236
Tim Harvey4533c902017-03-17 07:32:21 -0700237 /* TI DP83867 */
238 else if (phydev->phy_id == 0x2000a231) {
239 /* configure register 0x170 for ref CLKOUT */
240 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
241 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
242 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
243 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
244 val &= ~0x1f00;
245 val |= 0x0b00; /* chD tx clock*/
246 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
247 }
248
Tim Harvey552c3582014-03-06 07:46:30 -0800249 if (phydev->drv->config)
250 phydev->drv->config(phydev);
251
252 return 0;
253}
Tim Harvey63537792017-03-17 07:30:38 -0700254
255#ifdef CONFIG_MV88E61XX_SWITCH
256int mv88e61xx_hw_reset(struct phy_device *phydev)
257{
258 struct mii_dev *bus = phydev->bus;
259
260 /* GPIO[0] output, CLK125 */
261 debug("enabling RGMII_REFCLK\n");
262 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
263 0x1a /*MV_SCRATCH_MISC*/,
264 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
265 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
266 0x1a /*MV_SCRATCH_MISC*/,
267 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
268
269 /* RGMII delay - Physical Control register bit[15:14] */
270 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
271 /* forced 1000mbps full-duplex link */
272 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
273 phydev->autoneg = AUTONEG_DISABLE;
274 phydev->speed = SPEED_1000;
275 phydev->duplex = DUPLEX_FULL;
276
Tim Harvey8c9d3932019-02-04 13:10:47 -0800277 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
278 bus->write(bus, 0x10, 0, 0x16, 0x8088);
279 bus->write(bus, 0x11, 0, 0x16, 0x8088);
280 bus->write(bus, 0x12, 0, 0x16, 0x8088);
281 bus->write(bus, 0x13, 0, 0x16, 0x8088);
Tim Harvey63537792017-03-17 07:30:38 -0700282
283 return 0;
284}
285#endif // CONFIG_MV88E61XX_SWITCH
Tim Harvey552c3582014-03-06 07:46:30 -0800286
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900287int board_eth_init(struct bd_info *bis)
Tim Harvey552c3582014-03-06 07:46:30 -0800288{
Tim Harvey552c3582014-03-06 07:46:30 -0800289#ifdef CONFIG_FEC_MXC
Tim Harvey892068c2016-05-24 11:03:58 -0700290 struct ventana_board_info *info = &ventana_info;
291
292 if (test_bit(EECONFIG_ETH0, info->config)) {
Tim Harveyf1f41db2015-05-08 18:28:28 -0700293 setup_iomux_enet(GP_PHY_RST);
Tim Harvey50581832014-08-20 23:35:14 -0700294 cpu_eth_init(bis);
Tim Harvey85331822015-04-08 12:54:48 -0700295 }
Tim Harvey552c3582014-03-06 07:46:30 -0800296#endif
297
Tim Harvey472884d2015-04-08 12:54:32 -0700298#ifdef CONFIG_E1000
299 e1000_initialize(bis);
300#endif
301
Tim Harvey552c3582014-03-06 07:46:30 -0800302#ifdef CONFIG_CI_UDC
303 /* For otg ethernet*/
304 usb_eth_initialize(bis);
305#endif
306
Tim Harveyfc5ff942015-04-08 12:54:33 -0700307 /* default to the first detected enet dev */
Simon Glass64b723f2017-08-03 12:22:12 -0600308 if (!env_get("ethprime")) {
Tim Harveyfc5ff942015-04-08 12:54:33 -0700309 struct eth_device *dev = eth_get_dev_by_index(0);
310 if (dev) {
Simon Glass6a38e412017-08-03 12:22:09 -0600311 env_set("ethprime", dev->name);
Simon Glass64b723f2017-08-03 12:22:12 -0600312 printf("set ethprime to %s\n", env_get("ethprime"));
Tim Harveyfc5ff942015-04-08 12:54:33 -0700313 }
314 }
315
Tim Harvey552c3582014-03-06 07:46:30 -0800316 return 0;
317}
318
Tim Harveyfb64cc72014-04-25 15:39:07 -0700319#if defined(CONFIG_VIDEO_IPUV3)
320
321static void enable_hdmi(struct display_info_t const *dev)
322{
323 imx_enable_hdmi_phy();
324}
325
326static int detect_i2c(struct display_info_t const *dev)
327{
328 return i2c_set_bus_num(dev->bus) == 0 &&
329 i2c_probe(dev->addr) == 0;
330}
331
332static void enable_lvds(struct display_info_t const *dev)
333{
334 struct iomuxc *iomux = (struct iomuxc *)
335 IOMUXC_BASE_ADDR;
336
337 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
338 u32 reg = readl(&iomux->gpr[2]);
339 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
340 writel(reg, &iomux->gpr[2]);
341
342 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700343 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
344 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700345 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700346 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700347 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
348}
349
350struct display_info_t const displays[] = {{
351 /* HDMI Output */
352 .bus = -1,
353 .addr = 0,
354 .pixfmt = IPU_PIX_FMT_RGB24,
355 .detect = detect_hdmi,
356 .enable = enable_hdmi,
357 .mode = {
358 .name = "HDMI",
359 .refresh = 60,
360 .xres = 1024,
361 .yres = 768,
362 .pixclock = 15385,
363 .left_margin = 220,
364 .right_margin = 40,
365 .upper_margin = 21,
366 .lower_margin = 7,
367 .hsync_len = 60,
368 .vsync_len = 10,
369 .sync = FB_SYNC_EXT,
370 .vmode = FB_VMODE_NONINTERLACED
371} }, {
372 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
373 .bus = 2,
374 .addr = 0x4,
375 .pixfmt = IPU_PIX_FMT_LVDS666,
376 .detect = detect_i2c,
377 .enable = enable_lvds,
378 .mode = {
379 .name = "Hannstar-XGA",
380 .refresh = 60,
381 .xres = 1024,
382 .yres = 768,
383 .pixclock = 15385,
384 .left_margin = 220,
385 .right_margin = 40,
386 .upper_margin = 21,
387 .lower_margin = 7,
388 .hsync_len = 60,
389 .vsync_len = 10,
390 .sync = FB_SYNC_EXT,
391 .vmode = FB_VMODE_NONINTERLACED
Tim Harveya20bd632015-04-08 12:54:57 -0700392} }, {
393 /* DLC700JMG-T-4 */
Tim Harveybe786e72019-02-04 13:10:53 -0800394 .bus = 2,
395 .addr = 0x38,
Tim Harveya20bd632015-04-08 12:54:57 -0700396 .detect = NULL,
397 .enable = enable_lvds,
398 .pixfmt = IPU_PIX_FMT_LVDS666,
399 .mode = {
400 .name = "DLC700JMGT4",
401 .refresh = 60,
402 .xres = 1024, /* 1024x600active pixels */
403 .yres = 600,
404 .pixclock = 15385, /* 64MHz */
405 .left_margin = 220,
406 .right_margin = 40,
407 .upper_margin = 21,
408 .lower_margin = 7,
409 .hsync_len = 60,
410 .vsync_len = 10,
411 .sync = FB_SYNC_EXT,
412 .vmode = FB_VMODE_NONINTERLACED
413} }, {
414 /* DLC800FIG-T-3 */
Tim Harveybe786e72019-02-04 13:10:53 -0800415 .bus = 2,
416 .addr = 0x14,
Tim Harveya20bd632015-04-08 12:54:57 -0700417 .detect = NULL,
418 .enable = enable_lvds,
419 .pixfmt = IPU_PIX_FMT_LVDS666,
420 .mode = {
421 .name = "DLC800FIGT3",
422 .refresh = 60,
423 .xres = 1024, /* 1024x768 active pixels */
424 .yres = 768,
425 .pixclock = 15385, /* 64MHz */
426 .left_margin = 220,
427 .right_margin = 40,
428 .upper_margin = 21,
429 .lower_margin = 7,
430 .hsync_len = 60,
431 .vsync_len = 10,
432 .sync = FB_SYNC_EXT,
433 .vmode = FB_VMODE_NONINTERLACED
Tim Harveyc34e59e2019-02-04 13:10:51 -0800434} }, {
435 .bus = 2,
436 .addr = 0x5d,
437 .detect = detect_i2c,
438 .enable = enable_lvds,
439 .pixfmt = IPU_PIX_FMT_LVDS666,
440 .mode = {
441 .name = "Z101WX01",
442 .refresh = 60,
443 .xres = 1280,
444 .yres = 800,
445 .pixclock = 15385, /* 64MHz */
446 .left_margin = 220,
447 .right_margin = 40,
448 .upper_margin = 21,
449 .lower_margin = 7,
450 .hsync_len = 60,
451 .vsync_len = 10,
452 .sync = FB_SYNC_EXT,
453 .vmode = FB_VMODE_NONINTERLACED
454 }
455},
456};
Tim Harveyfb64cc72014-04-25 15:39:07 -0700457size_t display_count = ARRAY_SIZE(displays);
458
459static void setup_display(void)
460{
461 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
462 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
463 int reg;
464
465 enable_ipu_clock();
466 imx_setup_hdmi();
467 /* Turn on LDB0,IPU,IPU DI0 clocks */
468 reg = __raw_readl(&mxc_ccm->CCGR3);
469 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
470 writel(reg, &mxc_ccm->CCGR3);
471
472 /* set LDB0, LDB1 clk select to 011/011 */
473 reg = readl(&mxc_ccm->cs2cdr);
474 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
475 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
476 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
477 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
478 writel(reg, &mxc_ccm->cs2cdr);
479
480 reg = readl(&mxc_ccm->cscmr2);
481 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
482 writel(reg, &mxc_ccm->cscmr2);
483
484 reg = readl(&mxc_ccm->chsccdr);
485 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
486 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
487 writel(reg, &mxc_ccm->chsccdr);
488
489 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
490 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
491 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
492 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
493 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
494 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
495 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
496 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
497 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
498 writel(reg, &iomux->gpr[2]);
499
500 reg = readl(&iomux->gpr[3]);
501 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
502 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
503 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
504 writel(reg, &iomux->gpr[3]);
505
Tim Harveya67e07f2016-05-24 11:03:53 -0700506 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700507 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700508 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
509}
510#endif /* CONFIG_VIDEO_IPUV3 */
511
Tim Harvey0dff16f2014-05-05 08:22:25 -0700512/* setup board specific PMIC */
513int power_init_board(void)
514{
Tim Harvey195bc972015-05-08 18:28:37 -0700515 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700516 return 0;
517}
518
Tim Harvey552c3582014-03-06 07:46:30 -0800519#if defined(CONFIG_CMD_PCI)
520int imx6_pcie_toggle_reset(void)
521{
522 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700523 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700524 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700525 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800526 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700527 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800528 }
529 return 0;
530}
Tim Harvey33791d52014-08-07 22:49:57 -0700531
532/*
533 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
534 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
535 * properly and assert reset for 100ms.
536 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700537#define MAX_PCI_DEVS 32
538struct pci_dev {
539 pci_dev_t devfn;
540 unsigned short vendor;
541 unsigned short device;
542 unsigned short class;
543 unsigned short busno; /* subbordinate busno */
544 struct pci_dev *ppar;
545};
546struct pci_dev pci_devs[MAX_PCI_DEVS];
547int pci_devno;
548int pci_bridgeno;
549
Tim Harvey33791d52014-08-07 22:49:57 -0700550void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
551 unsigned short vendor, unsigned short device,
552 unsigned short class)
553{
Tim Harveybfb240a2016-06-17 06:10:41 -0700554 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700555 u32 dw;
Tim Harveybfb240a2016-06-17 06:10:41 -0700556 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey33791d52014-08-07 22:49:57 -0700557
558 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
559 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700560
561 /* store array of devs for later use in device-tree fixup */
562 pdev->devfn = dev;
563 pdev->vendor = vendor;
564 pdev->device = device;
565 pdev->class = class;
566 pdev->ppar = NULL;
567 if (class == PCI_CLASS_BRIDGE_PCI)
568 pdev->busno = ++pci_bridgeno;
569 else
570 pdev->busno = 0;
571
572 /* fixup RC - it should be 00:00.0 not 00:01.0 */
573 if (PCI_BUS(dev) == 0)
574 pdev->devfn = 0;
575
576 /* find dev's parent */
577 for (i = 0; i < pci_devno; i++) {
578 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
579 pdev->ppar = &pci_devs[i];
580 break;
581 }
582 }
583
584 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700585 if (vendor == PCI_VENDOR_ID_PLX &&
586 (device & 0xfff0) == 0x8600 &&
587 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
588 debug("configuring PLX 860X downstream PERST#\n");
589 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
590 dw |= 0xaaa8; /* GPIO1-7 outputs */
591 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
592
593 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
594 dw |= 0xfe; /* GPIO1-7 output high */
595 pci_hose_write_config_dword(hose, dev, 0x644, dw);
596
597 mdelay(100);
598 }
599}
Tim Harvey552c3582014-03-06 07:46:30 -0800600#endif /* CONFIG_CMD_PCI */
601
602#ifdef CONFIG_SERIAL_TAG
603/*
604 * called when setting up ATAGS before booting kernel
605 * populate serialnum from the following (in order of priority):
606 * serial# env var
607 * eeprom
608 */
609void get_board_serial(struct tag_serialnr *serialnr)
610{
Simon Glass64b723f2017-08-03 12:22:12 -0600611 char *serial = env_get("serial#");
Tim Harvey552c3582014-03-06 07:46:30 -0800612
613 if (serial) {
614 serialnr->high = 0;
615 serialnr->low = simple_strtoul(serial, NULL, 10);
616 } else if (ventana_info.model[0]) {
617 serialnr->high = 0;
618 serialnr->low = ventana_info.serial;
619 } else {
620 serialnr->high = 0;
621 serialnr->low = 0;
622 }
623}
624#endif
625
626/*
627 * Board Support
628 */
629
630int board_early_init_f(void)
631{
632 setup_iomux_uart();
Tim Harveyf1f41db2015-05-08 18:28:28 -0700633
Tim Harveyfb64cc72014-04-25 15:39:07 -0700634#if defined(CONFIG_VIDEO_IPUV3)
635 setup_display();
636#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800637 return 0;
638}
639
640int dram_init(void)
641{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700642 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800643 return 0;
644}
645
646int board_init(void)
647{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300648 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800649
650 clrsetbits_le32(&iomuxc_regs->gpr[1],
651 IOMUXC_GPR1_OTG_ID_MASK,
652 IOMUXC_GPR1_OTG_ID_GPIO1);
653
654 /* address of linux boot parameters */
655 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
656
Tim Harveyba9f2342019-02-04 13:10:52 -0800657 /* read Gateworks EEPROM into global struct (used later) */
658 setup_ventana_i2c(0);
659 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
660
Tim Harvey552c3582014-03-06 07:46:30 -0800661#ifdef CONFIG_CMD_NAND
Tim Harveyba9f2342019-02-04 13:10:52 -0800662 if (gpio_cfg[board_type].nand)
663 setup_gpmi_nand();
Tim Harvey552c3582014-03-06 07:46:30 -0800664#endif
665#ifdef CONFIG_MXC_SPI
666 setup_spi();
667#endif
Tim Harveyd04dc812019-02-04 13:10:49 -0800668 setup_ventana_i2c(1);
669 setup_ventana_i2c(2);
Tim Harvey552c3582014-03-06 07:46:30 -0800670
Simon Glassab3055a2017-06-14 21:28:25 -0600671#ifdef CONFIG_SATA
Tim Harvey552c3582014-03-06 07:46:30 -0800672 setup_sata();
673#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800674
Tim Harvey0cee2242015-05-08 18:28:35 -0700675 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800676
677 return 0;
678}
679
680#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
681/*
682 * called during late init (after relocation and after board_init())
683 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
684 * EEPROM read.
685 */
686int checkboard(void)
687{
688 struct ventana_board_info *info = &ventana_info;
689 unsigned char buf[4];
690 const char *p;
691 int quiet; /* Quiet or minimal output mode */
692
693 quiet = 0;
Simon Glass64b723f2017-08-03 12:22:12 -0600694 p = env_get("quiet");
Tim Harvey552c3582014-03-06 07:46:30 -0800695 if (p)
696 quiet = simple_strtol(p, NULL, 10);
697 else
Simon Glass6a38e412017-08-03 12:22:09 -0600698 env_set("quiet", "0");
Tim Harvey552c3582014-03-06 07:46:30 -0800699
700 puts("\nGateworks Corporation Copyright 2014\n");
701 if (info->model[0]) {
702 printf("Model: %s\n", info->model);
703 printf("MFGDate: %02x-%02x-%02x%02x\n",
704 info->mfgdate[0], info->mfgdate[1],
705 info->mfgdate[2], info->mfgdate[3]);
706 printf("Serial:%d\n", info->serial);
707 } else {
708 puts("Invalid EEPROM - board will not function fully\n");
709 }
710 if (quiet)
711 return 0;
712
713 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700714 gsc_info(0);
715
Tim Harvey552c3582014-03-06 07:46:30 -0800716 /* Display RTC */
717 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
718 printf("RTC: %d\n",
719 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
720 }
721
722 return 0;
723}
724#endif
725
726#ifdef CONFIG_CMD_BMODE
727/*
728 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
729 * see Table 8-11 and Table 5-9
730 * BOOT_CFG1[7] = 1 (boot from NAND)
731 * BOOT_CFG1[5] = 0 - raw NAND
732 * BOOT_CFG1[4] = 0 - default pad settings
733 * BOOT_CFG1[3:2] = 00 - devices = 1
734 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
735 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
736 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
737 * BOOT_CFG2[0] = 0 - Reset time 12ms
738 */
739static const struct boot_mode board_boot_modes[] = {
740 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
741 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
Tim Harvey659441b2017-03-17 07:31:02 -0700742 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
Tim Harveya2d24c92019-02-04 13:10:50 -0800743 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
Tim Harvey552c3582014-03-06 07:46:30 -0800744 { NULL, 0 },
745};
746#endif
747
748/* late init */
749int misc_init_r(void)
750{
751 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700752 char buf[256];
753 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800754
755 /* set env vars based on EEPROM data */
756 if (ventana_info.model[0]) {
757 char str[16], fdt[36];
758 char *p;
759 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800760
761 /*
762 * FDT name will be prefixed with CPU type. Three versions
763 * will be created each increasingly generic and bootloader
764 * env scripts will try loading each from most specific to
765 * least.
766 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700767 if (is_cpu_type(MXC_CPU_MX6Q) ||
768 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800769 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700770 else if (is_cpu_type(MXC_CPU_MX6DL) ||
771 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800772 cputype = "imx6dl";
Simon Glass6a38e412017-08-03 12:22:09 -0600773 env_set("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700774 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
Simon Glass6a38e412017-08-03 12:22:09 -0600775 env_set("flash_layout", "large");
Tim Harvey06d87432014-08-07 22:35:41 -0700776 else
Simon Glass6a38e412017-08-03 12:22:09 -0600777 env_set("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800778 memset(str, 0, sizeof(str));
779 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
780 str[i] = tolower(info->model[i]);
Simon Glass6a38e412017-08-03 12:22:09 -0600781 env_set("model", str);
Simon Glass64b723f2017-08-03 12:22:12 -0600782 if (!env_get("fdt_file")) {
Tim Harvey552c3582014-03-06 07:46:30 -0800783 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600784 env_set("fdt_file", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800785 }
786 p = strchr(str, '-');
787 if (p) {
788 *p++ = 0;
789
Simon Glass6a38e412017-08-03 12:22:09 -0600790 env_set("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700791 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600792 env_set("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700793 if (board_type != GW551x &&
794 board_type != GW552x &&
Tim Harvey659441b2017-03-17 07:31:02 -0700795 board_type != GW553x &&
796 board_type != GW560x)
Tim Harvey50581832014-08-20 23:35:14 -0700797 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800798 str[5] = 'x';
799 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700800 sprintf(fdt, "%s-%s.dtb", cputype, str);
Simon Glass6a38e412017-08-03 12:22:09 -0600801 env_set("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800802 }
803
804 /* initialize env from EEPROM */
805 if (test_bit(EECONFIG_ETH0, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600806 !env_get("ethaddr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600807 eth_env_set_enetaddr("ethaddr", info->mac0);
Tim Harvey552c3582014-03-06 07:46:30 -0800808 }
809 if (test_bit(EECONFIG_ETH1, info->config) &&
Simon Glass64b723f2017-08-03 12:22:12 -0600810 !env_get("eth1addr")) {
Simon Glass8551d552017-08-03 12:22:11 -0600811 eth_env_set_enetaddr("eth1addr", info->mac1);
Tim Harvey552c3582014-03-06 07:46:30 -0800812 }
813
814 /* board serial-number */
815 sprintf(str, "%6d", info->serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600816 env_set("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700817
818 /* memory MB */
819 sprintf(str, "%d", (int) (gd->ram_size >> 20));
Simon Glass6a38e412017-08-03 12:22:09 -0600820 env_set("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800821 }
822
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700823 /* Set a non-initialized hwconfig based on board configuration */
Simon Glass64b723f2017-08-03 12:22:12 -0600824 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
Tim Harveyfd6f2392017-03-13 08:51:06 -0700825 buf[0] = 0;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700826 if (gpio_cfg[board_type].rs232_en)
827 strcat(buf, "rs232;");
828 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
829 char buf1[32];
830 sprintf(buf1, "dio%d:mode=gpio;", i);
831 if (strlen(buf) + strlen(buf1) < sizeof(buf))
832 strcat(buf, buf1);
833 }
Simon Glass6a38e412017-08-03 12:22:09 -0600834 env_set("hwconfig", buf);
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700835 }
Tim Harvey552c3582014-03-06 07:46:30 -0800836
Tim Harvey0cee2242015-05-08 18:28:35 -0700837 /* setup baseboard specific GPIO based on board and env */
838 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800839
840#ifdef CONFIG_CMD_BMODE
841 add_board_boot_modes(board_boot_modes);
842#endif
843
Tim Harvey40feabb2015-05-08 18:28:36 -0700844 /* disable boot watchdog */
845 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800846
847 return 0;
848}
849
Robert P. J. Day3c757002016-05-19 15:23:12 -0400850#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800851
Tim Harveycf20e552015-04-08 12:55:01 -0700852static int ft_sethdmiinfmt(void *blob, char *mode)
853{
854 int off;
855
856 if (!mode)
857 return -EINVAL;
858
859 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
860 if (off < 0)
861 return off;
862
863 if (0 == strcasecmp(mode, "yuv422bt656")) {
864 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
865 0x00, 0x00, 0x00 };
866 mode = "422_ccir";
867 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
868 fdt_setprop_u32(blob, off, "vidout_trc", 1);
869 fdt_setprop_u32(blob, off, "vidout_blc", 1);
870 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
871 printf(" set HDMI input mode to %s\n", mode);
872 } else if (0 == strcasecmp(mode, "yuv422smp")) {
873 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
874 0x82, 0x81, 0x00 };
875 mode = "422_smp";
876 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
877 fdt_setprop_u32(blob, off, "vidout_trc", 0);
878 fdt_setprop_u32(blob, off, "vidout_blc", 0);
879 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
880 printf(" set HDMI input mode to %s\n", mode);
881 } else {
882 return -EINVAL;
883 }
884
885 return 0;
886}
887
Tim Harveybfb240a2016-06-17 06:10:41 -0700888#if defined(CONFIG_CMD_PCI)
889#define PCI_ID(x) ( \
890 (PCI_BUS(x->devfn)<<16)| \
891 (PCI_DEV(x->devfn)<<11)| \
892 (PCI_FUNC(x->devfn)<<8) \
893 )
Tim Harveybfb240a2016-06-17 06:10:41 -0700894int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
895{
896 uint32_t reg[5];
897 char node[32];
898 int np;
899
900 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
901 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
902
903 np = fdt_subnode_offset(blob, par, node);
904 if (np >= 0)
905 return np;
906 np = fdt_add_subnode(blob, par, node);
907 if (np < 0) {
908 printf(" %s failed: no space\n", __func__);
909 return np;
910 }
911
912 memset(reg, 0, sizeof(reg));
913 reg[0] = cpu_to_fdt32(PCI_ID(dev));
914 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
915
916 return np;
917}
918
919/* build a path of nested PCI devs for all bridges passed through */
920int fdt_add_pci_path(void *blob, struct pci_dev *dev)
921{
922 struct pci_dev *bridges[MAX_PCI_DEVS];
923 int k, np;
924
925 /* build list of parents */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800926 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700927 if (np < 0)
928 return np;
929
930 k = 0;
931 while (dev) {
932 bridges[k++] = dev;
933 dev = dev->ppar;
934 };
935
936 /* now add them the to DT in reverse order */
937 while (k--) {
938 np = fdt_add_pci_node(blob, np, bridges[k]);
939 if (np < 0)
940 break;
941 }
942
943 return np;
944}
945
946/*
947 * The GW16082 has a hardware errata errata such that it's
948 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
949 * of this normal PCI interrupt swizzling will not work so we will
950 * provide an irq-map via device-tree.
951 */
952int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
953{
954 int len;
955 int host;
956 uint32_t imap_new[8*4*4];
957 const uint32_t *imap;
958 uint32_t irq[4];
959 uint32_t reg[4];
960 int i;
961
962 /* build irq-map based on host controllers map */
Tim Harvey984aa0d2019-02-04 13:11:00 -0800963 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
Tim Harveybfb240a2016-06-17 06:10:41 -0700964 if (host < 0) {
965 printf(" %s failed: missing host\n", __func__);
966 return host;
967 }
968
969 /* use interrupt data from root complex's node */
970 imap = fdt_getprop(blob, host, "interrupt-map", &len);
971 if (!imap || len != 128) {
972 printf(" %s failed: invalid interrupt-map\n",
973 __func__);
974 return -FDT_ERR_NOTFOUND;
975 }
976
977 /* obtain irq's of host controller in pin order */
978 for (i = 0; i < 4; i++)
979 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
980
981 /*
982 * determine number of swizzles necessary:
983 * For each bridge we pass through we need to swizzle
984 * the number of the slot we are on.
985 */
986 struct pci_dev *d;
987 int b;
988 b = 0;
989 d = dev->ppar;
990 while(d && d->ppar) {
991 b += PCI_DEV(d->devfn);
992 d = d->ppar;
993 }
994
995 /* create new irq mappings for slots12-15
996 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
997 * J3 AD28 12 INTD INTA
998 * J4 AD29 13 INTC INTD
999 * J5 AD30 14 INTB INTC
1000 * J2 AD31 15 INTA INTB
1001 */
1002 for (i = 0; i < 4; i++) {
1003 /* addr matches bus:dev:func */
1004 u32 addr = dev->busno << 16 | (12+i) << 11;
1005
1006 /* default cells from root complex */
1007 memcpy(&imap_new[i*32], imap, 128);
1008 /* first cell is PCI device address (BDF) */
1009 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
1010 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
1011 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
1012 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
1013 /* third cell is pin */
1014 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
1015 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
1016 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
1017 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
1018 /* sixth cell is relative interrupt */
1019 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
1020 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
1021 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
1022 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
1023 }
1024 fdt_setprop(blob, np, "interrupt-map", imap_new,
1025 sizeof(imap_new));
1026 reg[0] = cpu_to_fdt32(0xfff00);
1027 reg[1] = 0;
1028 reg[2] = 0;
1029 reg[3] = cpu_to_fdt32(0x7);
1030 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
1031 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
1032 fdt_setprop_string(blob, np, "device_type", "pci");
1033 fdt_setprop_cell(blob, np, "#address-cells", 3);
1034 fdt_setprop_cell(blob, np, "#size-cells", 2);
1035 printf(" Added custom interrupt-map for GW16082\n");
1036
1037 return 0;
1038}
1039
Tim Harvey77b82a12016-06-17 06:10:42 -07001040/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
1041int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
1042{
1043 char *tmp, *end;
1044 char mac[16];
1045 unsigned char mac_addr[6];
1046 int j;
1047
1048 sprintf(mac, "eth1addr");
Simon Glass64b723f2017-08-03 12:22:12 -06001049 tmp = env_get(mac);
Tim Harvey77b82a12016-06-17 06:10:42 -07001050 if (tmp) {
1051 for (j = 0; j < 6; j++) {
1052 mac_addr[j] = tmp ?
1053 simple_strtoul(tmp, &end,16) : 0;
1054 if (tmp)
1055 tmp = (*end) ? end+1 : end;
1056 }
1057 fdt_setprop(blob, np, "local-mac-address", mac_addr,
1058 sizeof(mac_addr));
1059 printf(" Added mac addr for eth1\n");
1060 return 0;
1061 }
1062
1063 return -1;
1064}
1065
Tim Harveybfb240a2016-06-17 06:10:41 -07001066/*
1067 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
1068 * we will walk the PCI bus and add bridge nodes up to the device receiving
1069 * the fixup.
1070 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001071void ft_board_pci_fixup(void *blob, struct bd_info *bd)
Tim Harveybfb240a2016-06-17 06:10:41 -07001072{
1073 int i, np;
1074 struct pci_dev *dev;
1075
1076 for (i = 0; i < pci_devno; i++) {
1077 dev = &pci_devs[i];
1078
1079 /*
1080 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
1081 * an EEPROM at i2c1-0x50.
1082 */
1083 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1084 (dev->device == 0x8240) &&
1085 (i2c_set_bus_num(1) == 0) &&
1086 (i2c_probe(0x50) == 0))
1087 {
1088 np = fdt_add_pci_path(blob, dev);
1089 if (np > 0)
1090 fdt_fixup_gw16082(blob, np, dev);
1091 }
Tim Harvey77b82a12016-06-17 06:10:42 -07001092
1093 /* ethernet1 mac address */
1094 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1095 (dev->device == 0x4380))
1096 {
1097 np = fdt_add_pci_path(blob, dev);
1098 if (np > 0)
1099 fdt_fixup_sky2(blob, np, dev);
1100 }
Tim Harveybfb240a2016-06-17 06:10:41 -07001101 }
1102}
1103#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001104
Tim Harvey984aa0d2019-02-04 13:11:00 -08001105void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001106{
Tim Harvey984aa0d2019-02-04 13:11:00 -08001107 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1108
1109 if (off) {
1110 fdt_delprop(blob, off, "ext-reset-output");
1111 fdt_delprop(blob, off, "fsl,ext-reset-output");
1112 }
Tim Harveyfcabb0b2017-05-15 10:05:07 -07001113}
1114
Tim Harvey552c3582014-03-06 07:46:30 -08001115/*
1116 * called prior to booting kernel or by 'fdt boardsetup' command
1117 *
1118 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1119 * - mtd partitions based on mtdparts/mtdids env
1120 * - system-serial (board serial num from EEPROM)
1121 * - board (full model from EEPROM)
1122 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1123 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001124#define WDOG1_ADDR 0x20bc000
1125#define WDOG2_ADDR 0x20c0000
1126#define GPIO3_ADDR 0x20a4000
1127#define USDHC3_ADDR 0x2198000
1128#define PWM0_ADDR 0x2080000
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001129int ft_board_setup(void *blob, struct bd_info *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001130{
Tim Harvey552c3582014-03-06 07:46:30 -08001131 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001132 struct ventana_eeprom_config *cfg;
Masahiro Yamada20ead6f2018-07-19 16:28:23 +09001133 static const struct node_info nodes[] = {
Tim Harvey552c3582014-03-06 07:46:30 -08001134 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1135 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1136 };
Simon Glass64b723f2017-08-03 12:22:12 -06001137 const char *model = env_get("model");
1138 const char *display = env_get("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001139 int i;
1140 char rev = 0;
1141
1142 /* determine board revision */
1143 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1144 if (ventana_info.model[i] >= 'A') {
1145 rev = ventana_info.model[i];
1146 break;
1147 }
1148 }
Tim Harvey552c3582014-03-06 07:46:30 -08001149
Simon Glass64b723f2017-08-03 12:22:12 -06001150 if (env_get("fdt_noauto")) {
Tim Harvey552c3582014-03-06 07:46:30 -08001151 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001152 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001153 }
1154
Tim Harveyc9e43e02015-05-26 11:04:58 -07001155 if (test_bit(EECONFIG_NAND, info->config)) {
1156 /* Update partition nodes using info from mtdparts env var */
1157 puts(" Updating MTD partitions...\n");
1158 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1159 }
Tim Harvey552c3582014-03-06 07:46:30 -08001160
Tim Harveye4af5d32015-04-08 12:54:58 -07001161 /* Update display timings from display env var */
1162 if (display) {
1163 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1164 display) >= 0)
1165 printf(" Set display timings for %s...\n", display);
1166 }
1167
Tim Harvey552c3582014-03-06 07:46:30 -08001168 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1169
1170 /* board serial number */
Simon Glass64b723f2017-08-03 12:22:12 -06001171 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1172 strlen(env_get("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001173
1174 /* board (model contains model from device-tree) */
1175 fdt_setprop(blob, 0, "board", info->model,
1176 strlen((const char *)info->model) + 1);
1177
Tim Harveycf20e552015-04-08 12:55:01 -07001178 /* set desired digital video capture format */
Simon Glass64b723f2017-08-03 12:22:12 -06001179 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
Tim Harveycf20e552015-04-08 12:55:01 -07001180
Tim Harvey552c3582014-03-06 07:46:30 -08001181 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001182 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001183 */
Tim Harveya1d32222016-07-15 07:16:28 -07001184 switch (board_type) {
1185 case GW51xx:
1186 /*
1187 * disable wdog node for GW51xx-A/B to work around
1188 * errata causing wdog timer to be unreliable.
1189 */
1190 if (rev >= 'A' && rev < 'C') {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001191 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1192 WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001193 if (i)
1194 fdt_status_disabled(blob, i);
1195 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001196
1197 /* GW51xx-E adds WDOG1_B external reset */
1198 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001199 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001200 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001201
Tim Harveya1d32222016-07-15 07:16:28 -07001202 case GW52xx:
1203 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1204 if (info->model[4] == '2') {
1205 u32 handle = 0;
1206 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001207
Tim Harveya1d32222016-07-15 07:16:28 -07001208 i = fdt_node_offset_by_compatible(blob, -1,
1209 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001210 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001211 range = (u32 *)fdt_getprop(blob, i,
1212 "reset-gpio", NULL);
1213
1214 if (range) {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001215 i = fdt_node_offset_by_compat_reg(blob,
1216 "fsl,imx6q-gpio", GPIO3_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001217 if (i)
1218 handle = fdt_get_phandle(blob, i);
1219 if (handle) {
1220 range[0] = cpu_to_fdt32(handle);
1221 range[1] = cpu_to_fdt32(23);
1222 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001223 }
Tim Harveya1d32222016-07-15 07:16:28 -07001224
1225 /* these have broken usd_vsel */
1226 if (strstr((const char *)info->model, "SP318-B") ||
1227 strstr((const char *)info->model, "SP331-B"))
1228 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001229
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001230 /* GW522x-B adds WDOG1_B external reset */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001231 if (rev < 'B')
1232 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Pushpal Sidhud1100562015-04-08 12:55:00 -07001233 }
Tim Harveydc5996a2017-05-15 10:05:06 -07001234
1235 /* GW520x-E adds WDOG1_B external reset */
1236 else if (info->model[4] == '0' && rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001237 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001238 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001239
Tim Harveya1d32222016-07-15 07:16:28 -07001240 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001241 /* GW53xx-E adds WDOG1_B external reset */
1242 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001243 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001244 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001245
Tim Harveya1d32222016-07-15 07:16:28 -07001246 case GW54xx:
1247 /*
1248 * disable serial2 node for GW54xx for compatibility with older
1249 * 3.10.x kernel that improperly had this node enabled in the DT
1250 */
Tim Harvey984aa0d2019-02-04 13:11:00 -08001251 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1252 0);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001253
1254 /* GW54xx-E adds WDOG2_B external reset */
1255 if (rev < 'E')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001256 ft_board_wdog_fixup(blob, WDOG2_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001257 break;
1258
1259 case GW551x:
1260 /*
1261 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1262 * causing non functional digital video in (it is not hooked up)
1263 */
1264 if (rev == 'A') {
1265 u32 *range = NULL;
1266 int len;
1267 const u32 *handle = NULL;
1268
1269 i = fdt_node_offset_by_compatible(blob, -1,
1270 "fsl,imx-tda1997x-video");
1271 if (i)
1272 handle = fdt_getprop(blob, i, "pinctrl-0",
1273 NULL);
1274 if (handle)
1275 i = fdt_node_offset_by_phandle(blob,
1276 fdt32_to_cpu(*handle));
1277 if (i)
1278 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1279 &len);
1280 if (range) {
1281 len /= sizeof(u32);
1282 for (i = 0; i < len; i += 6) {
1283 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1284 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1285 /* mux PAD_CSI0_DATA_EN to GPIO */
1286 if (is_cpu_type(MXC_CPU_MX6Q) &&
1287 mux_reg == 0x260 &&
1288 conf_reg == 0x630)
1289 range[i+3] = cpu_to_fdt32(0x5);
1290 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1291 mux_reg == 0x08c &&
1292 conf_reg == 0x3a0)
1293 range[i+3] = cpu_to_fdt32(0x5);
1294 }
1295 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1296 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001297 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001298
Tim Harveya1d32222016-07-15 07:16:28 -07001299 /* set BT656 video format */
1300 ft_sethdmiinfmt(blob, "yuv422bt656");
1301 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001302
1303 /* GW551x-C adds WDOG1_B external reset */
1304 if (rev < 'C')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001305 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harveya1d32222016-07-15 07:16:28 -07001306 break;
Tim Harvey5852a332019-02-04 13:10:58 -08001307 case GW5901:
1308 case GW5902:
1309 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1310 if (rev < 'B')
Tim Harvey984aa0d2019-02-04 13:11:00 -08001311 ft_board_wdog_fixup(blob, WDOG1_ADDR);
Tim Harvey5852a332019-02-04 13:10:58 -08001312 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001313 }
1314
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001315 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001316 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001317 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1318 char arg[10];
1319
1320 sprintf(arg, "dio%d", i);
1321 if (!hwconfig(arg))
1322 continue;
1323 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1324 {
Tim Harvey984aa0d2019-02-04 13:11:00 -08001325 phys_addr_t addr;
1326 int off;
1327
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001328 printf(" Enabling pwm%d for DIO%d\n",
1329 cfg->pwm_param, i);
Tim Harvey984aa0d2019-02-04 13:11:00 -08001330 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1331 off = fdt_node_offset_by_compat_reg(blob,
1332 "fsl,imx6q-pwm",
1333 addr);
1334 if (off)
1335 fdt_status_okay(blob, off);
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001336 }
1337 }
1338
Tim Harvey147b5762016-05-24 11:03:59 -07001339 /* remove no-1-8-v if UHS-I support is present */
1340 if (gpio_cfg[board_type].usd_vsel) {
1341 debug("Enabling UHS-I support\n");
Tim Harvey984aa0d2019-02-04 13:11:00 -08001342 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1343 USDHC3_ADDR);
1344 if (i)
1345 fdt_delprop(blob, i, "no-1-8-v");
Tim Harvey147b5762016-05-24 11:03:59 -07001346 }
1347
Tim Harveybfb240a2016-06-17 06:10:41 -07001348#if defined(CONFIG_CMD_PCI)
Simon Glass64b723f2017-08-03 12:22:12 -06001349 if (!env_get("nopcifixup"))
Tim Harveybfb240a2016-06-17 06:10:41 -07001350 ft_board_pci_fixup(blob, bd);
1351#endif
1352
Tim Harvey6944ccf2015-04-08 12:54:53 -07001353 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001354 * Peripheral Config:
1355 * remove nodes by alias path if EEPROM config tells us the
1356 * peripheral is not loaded on the board.
1357 */
Simon Glass64b723f2017-08-03 12:22:12 -06001358 if (env_get("fdt_noconfig")) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001359 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001360 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001361 }
1362 cfg = econfig;
1363 while (cfg->name) {
1364 if (!test_bit(cfg->bit, info->config)) {
1365 fdt_del_node_and_alias(blob, cfg->dtalias ?
1366 cfg->dtalias : cfg->name);
1367 }
1368 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001369 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001370
1371 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001372}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001373#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey552c3582014-03-06 07:46:30 -08001374
Simon Glassb75b15b2020-12-03 16:55:23 -07001375static struct mxc_serial_plat ventana_mxc_serial_plat = {
Tim Harvey67ed7922015-05-08 18:28:29 -07001376 .reg = (struct mxc_uart *)UART2_BASE,
1377};
1378
Simon Glass1d8364a2020-12-28 20:34:54 -07001379U_BOOT_DRVINFO(ventana_serial) = {
Tim Harvey67ed7922015-05-08 18:28:29 -07001380 .name = "serial_mxc",
Simon Glass71fa5b42020-12-03 16:55:18 -07001381 .plat = &ventana_mxc_serial_plat,
Tim Harvey67ed7922015-05-08 18:28:29 -07001382};