blob: 5d871ceed91a882db6f4cd6ac8418335f96d541b [file] [log] [blame]
Tim Harvey552c3582014-03-06 07:46:30 -08001/*
2 * Copyright (C) 2013 Gateworks Corporation
3 *
4 * Author: Tim Harvey <tharvey@gateworks.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
Tim Harvey552c3582014-03-06 07:46:30 -080010#include <asm/arch/clock.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070011#include <asm/arch/crm_regs.h>
Tim Harvey552c3582014-03-06 07:46:30 -080012#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070014#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
Tim Harvey552c3582014-03-06 07:46:30 -080017#include <asm/imx-common/boot_mode.h>
18#include <asm/imx-common/sata.h>
Eric Nelson16acd1c2014-09-30 15:40:03 -070019#include <asm/imx-common/spi.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070020#include <asm/imx-common/video.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070021#include <asm/io.h>
22#include <dm.h>
Tim Harvey67ed7922015-05-08 18:28:29 -070023#include <dm/platform_data/serial_mxc.h>
Tim Harvey8d2d8df2016-05-24 11:03:55 -070024#include <hwconfig.h>
Tim Harvey552c3582014-03-06 07:46:30 -080025#include <i2c.h>
Tim Harvey552c3582014-03-06 07:46:30 -080026#include <fdt_support.h>
27#include <fsl_esdhc.h>
Tim Harvey0cee2242015-05-08 18:28:35 -070028#include <jffs2/load_kernel.h>
29#include <linux/ctype.h>
Tim Harvey552c3582014-03-06 07:46:30 -080030#include <miiphy.h>
Tim Harvey552c3582014-03-06 07:46:30 -080031#include <mtd_node.h>
32#include <netdev.h>
Tim Harvey33791d52014-08-07 22:49:57 -070033#include <pci.h>
Tim Harvey552c3582014-03-06 07:46:30 -080034#include <power/pmic.h>
Tim Harvey0dff16f2014-05-05 08:22:25 -070035#include <power/ltc3676_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080036#include <power/pfuze100_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080037#include <fdt_support.h>
38#include <jffs2/load_kernel.h>
39#include <spi_flash.h>
40
41#include "gsc.h"
Tim Harvey0cee2242015-05-08 18:28:35 -070042#include "common.h"
Tim Harvey552c3582014-03-06 07:46:30 -080043
44DECLARE_GLOBAL_DATA_PTR;
45
Tim Harvey26993362014-08-07 22:35:49 -070046
Tim Harvey552c3582014-03-06 07:46:30 -080047/*
48 * EEPROM board info struct populated by read_eeprom so that we only have to
49 * read it once.
50 */
Tim Harvey0da2c522014-08-07 22:35:45 -070051struct ventana_board_info ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -080052
Tim Harvey8b92bdf2015-04-08 12:54:43 -070053static int board_type;
Tim Harvey552c3582014-03-06 07:46:30 -080054
Tim Harvey552c3582014-03-06 07:46:30 -080055/* MMC */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070056static iomux_v3_cfg_t const usdhc3_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070057 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
58 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
59 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
60 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
61 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
62 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Tim Harvey147b5762016-05-24 11:03:59 -070063 IOMUX_PADS(PAD_SD3_DAT5__GPIO7_IO00 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080064};
65
66/* ENET */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070067static iomux_v3_cfg_t const enet_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070068 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
69 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
71 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
76 MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
78 MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
83 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
85 MUX_PAD_CTRL(ENET_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080086 /* PHY nRST */
Tim Harvey26993362014-08-07 22:35:49 -070087 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -080088};
89
90/* NAND */
Tim Harvey8b92bdf2015-04-08 12:54:43 -070091static iomux_v3_cfg_t const nfc_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070092 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
93 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
95 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
97 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
98 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
99 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
100 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
101 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
102 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
103 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
104 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
105 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
106 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800107};
108
109#ifdef CONFIG_CMD_NAND
110static void setup_gpmi_nand(void)
111{
112 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
113
114 /* config gpmi nand iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -0700115 SETUP_IOMUX_PADS(nfc_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800116
117 /* config gpmi and bch clock to 100 MHz */
118 clrsetbits_le32(&mxc_ccm->cs2cdr,
119 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
120 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
121 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
122 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
123 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
124 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
125
126 /* enable gpmi and bch clock gating */
127 setbits_le32(&mxc_ccm->CCGR4,
128 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
129 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
130 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
131 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
132 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
133
134 /* enable apbh clock gating */
135 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
136}
137#endif
138
Tim Harveyf1f41db2015-05-08 18:28:28 -0700139static void setup_iomux_enet(int gpio)
Tim Harvey552c3582014-03-06 07:46:30 -0800140{
Tim Harvey02fb5922014-06-02 16:13:26 -0700141 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800142
143 /* toggle PHY_RST# */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700144 gpio_request(gpio, "phy_rst#");
145 gpio_direction_output(gpio, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800146 mdelay(2);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700147 gpio_set_value(gpio, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800148}
149
Tim Harvey552c3582014-03-06 07:46:30 -0800150#ifdef CONFIG_USB_EHCI_MX6
Tim Harvey8b92bdf2015-04-08 12:54:43 -0700151static iomux_v3_cfg_t const usb_pads[] = {
Tim Harvey26993362014-08-07 22:35:49 -0700152 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
153 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
Tim Harvey02fb5922014-06-02 16:13:26 -0700154 /* OTG PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700155 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800156};
157
158int board_ehci_hcd_init(int port)
159{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700160 int gpio;
Tim Harvey552c3582014-03-06 07:46:30 -0800161
Tim Harvey02fb5922014-06-02 16:13:26 -0700162 SETUP_IOMUX_PADS(usb_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800163
Tim Harveydb7edfa2015-05-26 11:04:54 -0700164 /* Reset USB HUB */
165 switch (board_type) {
166 case GW53xx:
167 case GW552x:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700168 gpio = (IMX_GPIO_NR(1, 9));
Tim Harvey552c3582014-03-06 07:46:30 -0800169 break;
Tim Harveydb7edfa2015-05-26 11:04:54 -0700170 case GW54proto:
171 case GW54xx:
Tim Harveyf1f41db2015-05-08 18:28:28 -0700172 gpio = (IMX_GPIO_NR(1, 16));
Tim Harvey552c3582014-03-06 07:46:30 -0800173 break;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700174 default:
175 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -0800176 }
177
Tim Harveyf1f41db2015-05-08 18:28:28 -0700178 /* request and toggle hub rst */
179 gpio_request(gpio, "usb_hub_rst#");
180 gpio_direction_output(gpio, 0);
181 mdelay(2);
182 gpio_set_value(gpio, 1);
183
Tim Harvey552c3582014-03-06 07:46:30 -0800184 return 0;
185}
186
187int board_ehci_power(int port, int on)
188{
189 if (port)
190 return 0;
191 gpio_set_value(GP_USB_OTG_PWR, on);
192 return 0;
193}
194#endif /* CONFIG_USB_EHCI_MX6 */
195
196#ifdef CONFIG_FSL_ESDHC
Tim Harvey8b92bdf2015-04-08 12:54:43 -0700197static struct fsl_esdhc_cfg usdhc_cfg = { USDHC3_BASE_ADDR };
Tim Harvey552c3582014-03-06 07:46:30 -0800198
199int board_mmc_getcd(struct mmc *mmc)
200{
201 /* Card Detect */
Tim Harveyf1f41db2015-05-08 18:28:28 -0700202 gpio_request(GP_SD3_CD, "sd_cd");
Tim Harvey552c3582014-03-06 07:46:30 -0800203 gpio_direction_input(GP_SD3_CD);
204 return !gpio_get_value(GP_SD3_CD);
205}
206
207int board_mmc_init(bd_t *bis)
208{
209 /* Only one USDHC controller on Ventana */
Tim Harvey02fb5922014-06-02 16:13:26 -0700210 SETUP_IOMUX_PADS(usdhc3_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800211 usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
212 usdhc_cfg.max_bus_width = 4;
213
214 return fsl_esdhc_initialize(bis, &usdhc_cfg);
215}
216#endif /* CONFIG_FSL_ESDHC */
217
218#ifdef CONFIG_MXC_SPI
219iomux_v3_cfg_t const ecspi1_pads[] = {
220 /* SS1 */
Tim Harvey02fb5922014-06-02 16:13:26 -0700221 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
222 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
223 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
224 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800225};
226
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300227int board_spi_cs_gpio(unsigned bus, unsigned cs)
228{
229 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
230}
231
Tim Harvey552c3582014-03-06 07:46:30 -0800232static void setup_spi(void)
233{
Tim Harveyf1f41db2015-05-08 18:28:28 -0700234 gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300235 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
Tim Harvey02fb5922014-06-02 16:13:26 -0700236 SETUP_IOMUX_PADS(ecspi1_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800237}
238#endif
239
240/* configure eth0 PHY board-specific LED behavior */
241int board_phy_config(struct phy_device *phydev)
242{
243 unsigned short val;
244
245 /* Marvel 88E1510 */
246 if (phydev->phy_id == 0x1410dd1) {
247 /*
248 * Page 3, Register 16: LED[2:0] Function Control Register
249 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
250 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
251 */
252 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
253 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
254 val &= 0xff00;
255 val |= 0x0017;
256 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
257 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
258 }
259
260 if (phydev->drv->config)
261 phydev->drv->config(phydev);
262
263 return 0;
264}
265
266int board_eth_init(bd_t *bis)
267{
Tim Harvey552c3582014-03-06 07:46:30 -0800268#ifdef CONFIG_FEC_MXC
Tim Harvey892068c2016-05-24 11:03:58 -0700269 struct ventana_board_info *info = &ventana_info;
270
271 if (test_bit(EECONFIG_ETH0, info->config)) {
Tim Harveyf1f41db2015-05-08 18:28:28 -0700272 setup_iomux_enet(GP_PHY_RST);
Tim Harvey50581832014-08-20 23:35:14 -0700273 cpu_eth_init(bis);
Tim Harvey85331822015-04-08 12:54:48 -0700274 }
Tim Harvey552c3582014-03-06 07:46:30 -0800275#endif
276
Tim Harvey472884d2015-04-08 12:54:32 -0700277#ifdef CONFIG_E1000
278 e1000_initialize(bis);
279#endif
280
Tim Harvey552c3582014-03-06 07:46:30 -0800281#ifdef CONFIG_CI_UDC
282 /* For otg ethernet*/
283 usb_eth_initialize(bis);
284#endif
285
Tim Harveyfc5ff942015-04-08 12:54:33 -0700286 /* default to the first detected enet dev */
287 if (!getenv("ethprime")) {
288 struct eth_device *dev = eth_get_dev_by_index(0);
289 if (dev) {
290 setenv("ethprime", dev->name);
291 printf("set ethprime to %s\n", getenv("ethprime"));
292 }
293 }
294
Tim Harvey552c3582014-03-06 07:46:30 -0800295 return 0;
296}
297
Tim Harveyfb64cc72014-04-25 15:39:07 -0700298#if defined(CONFIG_VIDEO_IPUV3)
299
300static void enable_hdmi(struct display_info_t const *dev)
301{
302 imx_enable_hdmi_phy();
303}
304
305static int detect_i2c(struct display_info_t const *dev)
306{
307 return i2c_set_bus_num(dev->bus) == 0 &&
308 i2c_probe(dev->addr) == 0;
309}
310
311static void enable_lvds(struct display_info_t const *dev)
312{
313 struct iomuxc *iomux = (struct iomuxc *)
314 IOMUXC_BASE_ADDR;
315
316 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
317 u32 reg = readl(&iomux->gpr[2]);
318 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
319 writel(reg, &iomux->gpr[2]);
320
321 /* Enable Backlight */
Tim Harveya67e07f2016-05-24 11:03:53 -0700322 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
323 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
Tim Harveyf1f41db2015-05-08 18:28:28 -0700324 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
Tim Harvey26993362014-08-07 22:35:49 -0700325 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700326 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
327}
328
329struct display_info_t const displays[] = {{
330 /* HDMI Output */
331 .bus = -1,
332 .addr = 0,
333 .pixfmt = IPU_PIX_FMT_RGB24,
334 .detect = detect_hdmi,
335 .enable = enable_hdmi,
336 .mode = {
337 .name = "HDMI",
338 .refresh = 60,
339 .xres = 1024,
340 .yres = 768,
341 .pixclock = 15385,
342 .left_margin = 220,
343 .right_margin = 40,
344 .upper_margin = 21,
345 .lower_margin = 7,
346 .hsync_len = 60,
347 .vsync_len = 10,
348 .sync = FB_SYNC_EXT,
349 .vmode = FB_VMODE_NONINTERLACED
350} }, {
351 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
352 .bus = 2,
353 .addr = 0x4,
354 .pixfmt = IPU_PIX_FMT_LVDS666,
355 .detect = detect_i2c,
356 .enable = enable_lvds,
357 .mode = {
358 .name = "Hannstar-XGA",
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
Tim Harveya20bd632015-04-08 12:54:57 -0700371} }, {
372 /* DLC700JMG-T-4 */
373 .bus = 0,
374 .addr = 0,
375 .detect = NULL,
376 .enable = enable_lvds,
377 .pixfmt = IPU_PIX_FMT_LVDS666,
378 .mode = {
379 .name = "DLC700JMGT4",
380 .refresh = 60,
381 .xres = 1024, /* 1024x600active pixels */
382 .yres = 600,
383 .pixclock = 15385, /* 64MHz */
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
392} }, {
393 /* DLC800FIG-T-3 */
394 .bus = 0,
395 .addr = 0,
396 .detect = NULL,
397 .enable = enable_lvds,
398 .pixfmt = IPU_PIX_FMT_LVDS666,
399 .mode = {
400 .name = "DLC800FIGT3",
401 .refresh = 60,
402 .xres = 1024, /* 1024x768 active pixels */
403 .yres = 768,
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
Tim Harveyfb64cc72014-04-25 15:39:07 -0700413} } };
414size_t display_count = ARRAY_SIZE(displays);
415
416static void setup_display(void)
417{
418 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
419 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
420 int reg;
421
422 enable_ipu_clock();
423 imx_setup_hdmi();
424 /* Turn on LDB0,IPU,IPU DI0 clocks */
425 reg = __raw_readl(&mxc_ccm->CCGR3);
426 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
427 writel(reg, &mxc_ccm->CCGR3);
428
429 /* set LDB0, LDB1 clk select to 011/011 */
430 reg = readl(&mxc_ccm->cs2cdr);
431 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
432 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
433 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
434 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
435 writel(reg, &mxc_ccm->cs2cdr);
436
437 reg = readl(&mxc_ccm->cscmr2);
438 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
439 writel(reg, &mxc_ccm->cscmr2);
440
441 reg = readl(&mxc_ccm->chsccdr);
442 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
443 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
444 writel(reg, &mxc_ccm->chsccdr);
445
446 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
447 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
448 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
449 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
450 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
451 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
452 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
453 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
454 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
455 writel(reg, &iomux->gpr[2]);
456
457 reg = readl(&iomux->gpr[3]);
458 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
459 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
460 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
461 writel(reg, &iomux->gpr[3]);
462
Tim Harveya67e07f2016-05-24 11:03:53 -0700463 /* LVDS Backlight GPIO on LVDS connector - output low */
Tim Harvey26993362014-08-07 22:35:49 -0700464 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700465 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
466}
467#endif /* CONFIG_VIDEO_IPUV3 */
468
Tim Harvey0dff16f2014-05-05 08:22:25 -0700469/* setup board specific PMIC */
470int power_init_board(void)
471{
Tim Harvey195bc972015-05-08 18:28:37 -0700472 setup_pmic();
Tim Harvey0dff16f2014-05-05 08:22:25 -0700473 return 0;
474}
475
Tim Harvey552c3582014-03-06 07:46:30 -0800476#if defined(CONFIG_CMD_PCI)
477int imx6_pcie_toggle_reset(void)
478{
479 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -0700480 uint pin = gpio_cfg[board_type].pcie_rst;
Tim Harveyf1f41db2015-05-08 18:28:28 -0700481 gpio_request(pin, "pci_rst#");
Tim Harvey02fb5922014-06-02 16:13:26 -0700482 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -0800483 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -0700484 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -0800485 }
486 return 0;
487}
Tim Harvey33791d52014-08-07 22:49:57 -0700488
489/*
490 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
491 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
492 * properly and assert reset for 100ms.
493 */
Tim Harveybfb240a2016-06-17 06:10:41 -0700494#define MAX_PCI_DEVS 32
495struct pci_dev {
496 pci_dev_t devfn;
497 unsigned short vendor;
498 unsigned short device;
499 unsigned short class;
500 unsigned short busno; /* subbordinate busno */
501 struct pci_dev *ppar;
502};
503struct pci_dev pci_devs[MAX_PCI_DEVS];
504int pci_devno;
505int pci_bridgeno;
506
Tim Harvey33791d52014-08-07 22:49:57 -0700507void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
508 unsigned short vendor, unsigned short device,
509 unsigned short class)
510{
Tim Harveybfb240a2016-06-17 06:10:41 -0700511 int i;
Tim Harvey33791d52014-08-07 22:49:57 -0700512 u32 dw;
Tim Harveybfb240a2016-06-17 06:10:41 -0700513 struct pci_dev *pdev = &pci_devs[pci_devno++];
Tim Harvey33791d52014-08-07 22:49:57 -0700514
515 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
516 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
Tim Harveybfb240a2016-06-17 06:10:41 -0700517
518 /* store array of devs for later use in device-tree fixup */
519 pdev->devfn = dev;
520 pdev->vendor = vendor;
521 pdev->device = device;
522 pdev->class = class;
523 pdev->ppar = NULL;
524 if (class == PCI_CLASS_BRIDGE_PCI)
525 pdev->busno = ++pci_bridgeno;
526 else
527 pdev->busno = 0;
528
529 /* fixup RC - it should be 00:00.0 not 00:01.0 */
530 if (PCI_BUS(dev) == 0)
531 pdev->devfn = 0;
532
533 /* find dev's parent */
534 for (i = 0; i < pci_devno; i++) {
535 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
536 pdev->ppar = &pci_devs[i];
537 break;
538 }
539 }
540
541 /* assert downstream PERST# */
Tim Harvey33791d52014-08-07 22:49:57 -0700542 if (vendor == PCI_VENDOR_ID_PLX &&
543 (device & 0xfff0) == 0x8600 &&
544 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
545 debug("configuring PLX 860X downstream PERST#\n");
546 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
547 dw |= 0xaaa8; /* GPIO1-7 outputs */
548 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
549
550 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
551 dw |= 0xfe; /* GPIO1-7 output high */
552 pci_hose_write_config_dword(hose, dev, 0x644, dw);
553
554 mdelay(100);
555 }
556}
Tim Harvey552c3582014-03-06 07:46:30 -0800557#endif /* CONFIG_CMD_PCI */
558
559#ifdef CONFIG_SERIAL_TAG
560/*
561 * called when setting up ATAGS before booting kernel
562 * populate serialnum from the following (in order of priority):
563 * serial# env var
564 * eeprom
565 */
566void get_board_serial(struct tag_serialnr *serialnr)
567{
568 char *serial = getenv("serial#");
569
570 if (serial) {
571 serialnr->high = 0;
572 serialnr->low = simple_strtoul(serial, NULL, 10);
573 } else if (ventana_info.model[0]) {
574 serialnr->high = 0;
575 serialnr->low = ventana_info.serial;
576 } else {
577 serialnr->high = 0;
578 serialnr->low = 0;
579 }
580}
581#endif
582
583/*
584 * Board Support
585 */
586
587int board_early_init_f(void)
588{
589 setup_iomux_uart();
Tim Harveyf1f41db2015-05-08 18:28:28 -0700590
Tim Harveyfb64cc72014-04-25 15:39:07 -0700591#if defined(CONFIG_VIDEO_IPUV3)
592 setup_display();
593#endif
Tim Harvey552c3582014-03-06 07:46:30 -0800594 return 0;
595}
596
597int dram_init(void)
598{
Tim Harveybfa2dae2014-06-02 16:13:27 -0700599 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -0800600 return 0;
601}
602
603int board_init(void)
604{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300605 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -0800606
607 clrsetbits_le32(&iomuxc_regs->gpr[1],
608 IOMUXC_GPR1_OTG_ID_MASK,
609 IOMUXC_GPR1_OTG_ID_GPIO1);
610
611 /* address of linux boot parameters */
612 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
613
614#ifdef CONFIG_CMD_NAND
615 setup_gpmi_nand();
616#endif
617#ifdef CONFIG_MXC_SPI
618 setup_spi();
619#endif
Tim Harvey0cee2242015-05-08 18:28:35 -0700620 setup_ventana_i2c();
Tim Harvey552c3582014-03-06 07:46:30 -0800621
622#ifdef CONFIG_CMD_SATA
623 setup_sata();
624#endif
625 /* read Gateworks EEPROM into global struct (used later) */
Tim Harvey0da2c522014-08-07 22:35:45 -0700626 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800627
Tim Harvey0cee2242015-05-08 18:28:35 -0700628 setup_iomux_gpio(board_type, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -0800629
630 return 0;
631}
632
633#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
634/*
635 * called during late init (after relocation and after board_init())
636 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
637 * EEPROM read.
638 */
639int checkboard(void)
640{
641 struct ventana_board_info *info = &ventana_info;
642 unsigned char buf[4];
643 const char *p;
644 int quiet; /* Quiet or minimal output mode */
645
646 quiet = 0;
647 p = getenv("quiet");
648 if (p)
649 quiet = simple_strtol(p, NULL, 10);
650 else
651 setenv("quiet", "0");
652
653 puts("\nGateworks Corporation Copyright 2014\n");
654 if (info->model[0]) {
655 printf("Model: %s\n", info->model);
656 printf("MFGDate: %02x-%02x-%02x%02x\n",
657 info->mfgdate[0], info->mfgdate[1],
658 info->mfgdate[2], info->mfgdate[3]);
659 printf("Serial:%d\n", info->serial);
660 } else {
661 puts("Invalid EEPROM - board will not function fully\n");
662 }
663 if (quiet)
664 return 0;
665
666 /* Display GSC firmware revision/CRC/status */
Tim Harvey92e3d842015-04-08 12:54:59 -0700667 gsc_info(0);
668
Tim Harvey552c3582014-03-06 07:46:30 -0800669 /* Display RTC */
670 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
671 printf("RTC: %d\n",
672 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
673 }
674
675 return 0;
676}
677#endif
678
679#ifdef CONFIG_CMD_BMODE
680/*
681 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
682 * see Table 8-11 and Table 5-9
683 * BOOT_CFG1[7] = 1 (boot from NAND)
684 * BOOT_CFG1[5] = 0 - raw NAND
685 * BOOT_CFG1[4] = 0 - default pad settings
686 * BOOT_CFG1[3:2] = 00 - devices = 1
687 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
688 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
689 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
690 * BOOT_CFG2[0] = 0 - Reset time 12ms
691 */
692static const struct boot_mode board_boot_modes[] = {
693 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
694 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
695 { NULL, 0 },
696};
697#endif
698
699/* late init */
700int misc_init_r(void)
701{
702 struct ventana_board_info *info = &ventana_info;
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700703 char buf[256];
704 int i;
Tim Harvey552c3582014-03-06 07:46:30 -0800705
706 /* set env vars based on EEPROM data */
707 if (ventana_info.model[0]) {
708 char str[16], fdt[36];
709 char *p;
710 const char *cputype = "";
Tim Harvey552c3582014-03-06 07:46:30 -0800711
712 /*
713 * FDT name will be prefixed with CPU type. Three versions
714 * will be created each increasingly generic and bootloader
715 * env scripts will try loading each from most specific to
716 * least.
717 */
Tim Harveybfa2dae2014-06-02 16:13:27 -0700718 if (is_cpu_type(MXC_CPU_MX6Q) ||
719 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -0800720 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -0700721 else if (is_cpu_type(MXC_CPU_MX6DL) ||
722 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -0800723 cputype = "imx6dl";
Tim Harveybf942582014-08-07 22:35:42 -0700724 setenv("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -0700725 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
726 setenv("flash_layout", "large");
727 else
728 setenv("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -0800729 memset(str, 0, sizeof(str));
730 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
731 str[i] = tolower(info->model[i]);
Tim Harvey0f9327d2015-05-26 11:04:55 -0700732 setenv("model", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800733 if (!getenv("fdt_file")) {
734 sprintf(fdt, "%s-%s.dtb", cputype, str);
735 setenv("fdt_file", fdt);
736 }
737 p = strchr(str, '-');
738 if (p) {
739 *p++ = 0;
740
741 setenv("model_base", str);
Tim Harveyf6db79a2015-05-26 11:04:56 -0700742 sprintf(fdt, "%s-%s.dtb", cputype, str);
743 setenv("fdt_file1", fdt);
Tim Harvey892068c2016-05-24 11:03:58 -0700744 if (board_type != GW551x &&
745 board_type != GW552x &&
746 board_type != GW553x)
Tim Harvey50581832014-08-20 23:35:14 -0700747 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -0800748 str[5] = 'x';
749 str[6] = 0;
Tim Harveyf6db79a2015-05-26 11:04:56 -0700750 sprintf(fdt, "%s-%s.dtb", cputype, str);
751 setenv("fdt_file2", fdt);
Tim Harvey552c3582014-03-06 07:46:30 -0800752 }
753
754 /* initialize env from EEPROM */
755 if (test_bit(EECONFIG_ETH0, info->config) &&
756 !getenv("ethaddr")) {
757 eth_setenv_enetaddr("ethaddr", info->mac0);
758 }
759 if (test_bit(EECONFIG_ETH1, info->config) &&
760 !getenv("eth1addr")) {
761 eth_setenv_enetaddr("eth1addr", info->mac1);
762 }
763
764 /* board serial-number */
765 sprintf(str, "%6d", info->serial);
766 setenv("serial#", str);
Tim Harvey27770822015-04-08 12:54:51 -0700767
768 /* memory MB */
769 sprintf(str, "%d", (int) (gd->ram_size >> 20));
770 setenv("mem_mb", str);
Tim Harvey552c3582014-03-06 07:46:30 -0800771 }
772
Tim Harvey71dbb2c2016-07-15 07:14:25 -0700773 /* Set a non-initialized hwconfig based on board configuration */
774 if (!strcmp(getenv("hwconfig"), "_UNKNOWN_")) {
775 sprintf(buf, "hwconfig=");
776 if (gpio_cfg[board_type].rs232_en)
777 strcat(buf, "rs232;");
778 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
779 char buf1[32];
780 sprintf(buf1, "dio%d:mode=gpio;", i);
781 if (strlen(buf) + strlen(buf1) < sizeof(buf))
782 strcat(buf, buf1);
783 }
784 setenv("hwconfig", buf);
785 }
Tim Harvey552c3582014-03-06 07:46:30 -0800786
Tim Harvey0cee2242015-05-08 18:28:35 -0700787 /* setup baseboard specific GPIO based on board and env */
788 setup_board_gpio(board_type, info);
Tim Harvey552c3582014-03-06 07:46:30 -0800789
790#ifdef CONFIG_CMD_BMODE
791 add_board_boot_modes(board_boot_modes);
792#endif
793
Tim Harvey40feabb2015-05-08 18:28:36 -0700794 /* disable boot watchdog */
795 gsc_boot_wd_disable();
Tim Harvey552c3582014-03-06 07:46:30 -0800796
797 return 0;
798}
799
Robert P. J. Day3c757002016-05-19 15:23:12 -0400800#ifdef CONFIG_OF_BOARD_SETUP
Tim Harvey552c3582014-03-06 07:46:30 -0800801
Tim Harveycf20e552015-04-08 12:55:01 -0700802static int ft_sethdmiinfmt(void *blob, char *mode)
803{
804 int off;
805
806 if (!mode)
807 return -EINVAL;
808
809 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
810 if (off < 0)
811 return off;
812
813 if (0 == strcasecmp(mode, "yuv422bt656")) {
814 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
815 0x00, 0x00, 0x00 };
816 mode = "422_ccir";
817 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
818 fdt_setprop_u32(blob, off, "vidout_trc", 1);
819 fdt_setprop_u32(blob, off, "vidout_blc", 1);
820 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
821 printf(" set HDMI input mode to %s\n", mode);
822 } else if (0 == strcasecmp(mode, "yuv422smp")) {
823 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
824 0x82, 0x81, 0x00 };
825 mode = "422_smp";
826 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
827 fdt_setprop_u32(blob, off, "vidout_trc", 0);
828 fdt_setprop_u32(blob, off, "vidout_blc", 0);
829 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
830 printf(" set HDMI input mode to %s\n", mode);
831 } else {
832 return -EINVAL;
833 }
834
835 return 0;
836}
837
Tim Harvey8d2d8df2016-05-24 11:03:55 -0700838/* enable a property of a node if the node is found */
839static inline void ft_enable_path(void *blob, const char *path)
840{
841 int i = fdt_path_offset(blob, path);
842 if (i >= 0) {
843 debug("enabling %s\n", path);
844 fdt_status_okay(blob, i);
845 }
846}
847
Tim Harvey147b5762016-05-24 11:03:59 -0700848/* remove a property of a node if the node is found */
849static inline void ft_delprop_path(void *blob, const char *path,
850 const char *name)
851{
852 int i = fdt_path_offset(blob, path);
853 if (i) {
854 debug("removing %s/%s\n", path, name);
855 fdt_delprop(blob, i, name);
856 }
857}
Tim Harveybfb240a2016-06-17 06:10:41 -0700858
859#if defined(CONFIG_CMD_PCI)
860#define PCI_ID(x) ( \
861 (PCI_BUS(x->devfn)<<16)| \
862 (PCI_DEV(x->devfn)<<11)| \
863 (PCI_FUNC(x->devfn)<<8) \
864 )
865#define PCIE_PATH "/soc/pcie@0x01000000"
866int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
867{
868 uint32_t reg[5];
869 char node[32];
870 int np;
871
872 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
873 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
874
875 np = fdt_subnode_offset(blob, par, node);
876 if (np >= 0)
877 return np;
878 np = fdt_add_subnode(blob, par, node);
879 if (np < 0) {
880 printf(" %s failed: no space\n", __func__);
881 return np;
882 }
883
884 memset(reg, 0, sizeof(reg));
885 reg[0] = cpu_to_fdt32(PCI_ID(dev));
886 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
887
888 return np;
889}
890
891/* build a path of nested PCI devs for all bridges passed through */
892int fdt_add_pci_path(void *blob, struct pci_dev *dev)
893{
894 struct pci_dev *bridges[MAX_PCI_DEVS];
895 int k, np;
896
897 /* build list of parents */
898 np = fdt_path_offset(blob, PCIE_PATH);
899 if (np < 0)
900 return np;
901
902 k = 0;
903 while (dev) {
904 bridges[k++] = dev;
905 dev = dev->ppar;
906 };
907
908 /* now add them the to DT in reverse order */
909 while (k--) {
910 np = fdt_add_pci_node(blob, np, bridges[k]);
911 if (np < 0)
912 break;
913 }
914
915 return np;
916}
917
918/*
919 * The GW16082 has a hardware errata errata such that it's
920 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
921 * of this normal PCI interrupt swizzling will not work so we will
922 * provide an irq-map via device-tree.
923 */
924int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
925{
926 int len;
927 int host;
928 uint32_t imap_new[8*4*4];
929 const uint32_t *imap;
930 uint32_t irq[4];
931 uint32_t reg[4];
932 int i;
933
934 /* build irq-map based on host controllers map */
935 host = fdt_path_offset(blob, PCIE_PATH);
936 if (host < 0) {
937 printf(" %s failed: missing host\n", __func__);
938 return host;
939 }
940
941 /* use interrupt data from root complex's node */
942 imap = fdt_getprop(blob, host, "interrupt-map", &len);
943 if (!imap || len != 128) {
944 printf(" %s failed: invalid interrupt-map\n",
945 __func__);
946 return -FDT_ERR_NOTFOUND;
947 }
948
949 /* obtain irq's of host controller in pin order */
950 for (i = 0; i < 4; i++)
951 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
952
953 /*
954 * determine number of swizzles necessary:
955 * For each bridge we pass through we need to swizzle
956 * the number of the slot we are on.
957 */
958 struct pci_dev *d;
959 int b;
960 b = 0;
961 d = dev->ppar;
962 while(d && d->ppar) {
963 b += PCI_DEV(d->devfn);
964 d = d->ppar;
965 }
966
967 /* create new irq mappings for slots12-15
968 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
969 * J3 AD28 12 INTD INTA
970 * J4 AD29 13 INTC INTD
971 * J5 AD30 14 INTB INTC
972 * J2 AD31 15 INTA INTB
973 */
974 for (i = 0; i < 4; i++) {
975 /* addr matches bus:dev:func */
976 u32 addr = dev->busno << 16 | (12+i) << 11;
977
978 /* default cells from root complex */
979 memcpy(&imap_new[i*32], imap, 128);
980 /* first cell is PCI device address (BDF) */
981 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
982 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
983 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
984 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
985 /* third cell is pin */
986 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
987 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
988 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
989 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
990 /* sixth cell is relative interrupt */
991 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
992 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
993 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
994 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
995 }
996 fdt_setprop(blob, np, "interrupt-map", imap_new,
997 sizeof(imap_new));
998 reg[0] = cpu_to_fdt32(0xfff00);
999 reg[1] = 0;
1000 reg[2] = 0;
1001 reg[3] = cpu_to_fdt32(0x7);
1002 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
1003 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
1004 fdt_setprop_string(blob, np, "device_type", "pci");
1005 fdt_setprop_cell(blob, np, "#address-cells", 3);
1006 fdt_setprop_cell(blob, np, "#size-cells", 2);
1007 printf(" Added custom interrupt-map for GW16082\n");
1008
1009 return 0;
1010}
1011
Tim Harvey77b82a12016-06-17 06:10:42 -07001012/* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
1013int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
1014{
1015 char *tmp, *end;
1016 char mac[16];
1017 unsigned char mac_addr[6];
1018 int j;
1019
1020 sprintf(mac, "eth1addr");
1021 tmp = getenv(mac);
1022 if (tmp) {
1023 for (j = 0; j < 6; j++) {
1024 mac_addr[j] = tmp ?
1025 simple_strtoul(tmp, &end,16) : 0;
1026 if (tmp)
1027 tmp = (*end) ? end+1 : end;
1028 }
1029 fdt_setprop(blob, np, "local-mac-address", mac_addr,
1030 sizeof(mac_addr));
1031 printf(" Added mac addr for eth1\n");
1032 return 0;
1033 }
1034
1035 return -1;
1036}
1037
Tim Harveybfb240a2016-06-17 06:10:41 -07001038/*
1039 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
1040 * we will walk the PCI bus and add bridge nodes up to the device receiving
1041 * the fixup.
1042 */
1043void ft_board_pci_fixup(void *blob, bd_t *bd)
1044{
1045 int i, np;
1046 struct pci_dev *dev;
1047
1048 for (i = 0; i < pci_devno; i++) {
1049 dev = &pci_devs[i];
1050
1051 /*
1052 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
1053 * an EEPROM at i2c1-0x50.
1054 */
1055 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1056 (dev->device == 0x8240) &&
1057 (i2c_set_bus_num(1) == 0) &&
1058 (i2c_probe(0x50) == 0))
1059 {
1060 np = fdt_add_pci_path(blob, dev);
1061 if (np > 0)
1062 fdt_fixup_gw16082(blob, np, dev);
1063 }
Tim Harvey77b82a12016-06-17 06:10:42 -07001064
1065 /* ethernet1 mac address */
1066 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1067 (dev->device == 0x4380))
1068 {
1069 np = fdt_add_pci_path(blob, dev);
1070 if (np > 0)
1071 fdt_fixup_sky2(blob, np, dev);
1072 }
Tim Harveybfb240a2016-06-17 06:10:41 -07001073 }
1074}
1075#endif /* if defined(CONFIG_CMD_PCI) */
Tim Harvey147b5762016-05-24 11:03:59 -07001076
Tim Harvey552c3582014-03-06 07:46:30 -08001077/*
1078 * called prior to booting kernel or by 'fdt boardsetup' command
1079 *
1080 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1081 * - mtd partitions based on mtdparts/mtdids env
1082 * - system-serial (board serial num from EEPROM)
1083 * - board (full model from EEPROM)
1084 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1085 */
Tim Harveya1d32222016-07-15 07:16:28 -07001086#define UART1_PATH "/soc/aips-bus@02100000/serial@021ec000"
1087#define WDOG1_PATH "/soc/aips-bus@02000000/wdog@020bc000"
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001088#define WDOG2_PATH "/soc/aips-bus@02000000/wdog@020c0000"
Tim Harveya1d32222016-07-15 07:16:28 -07001089#define GPIO3_PATH "/soc/aips-bus@02000000/gpio@020a4000"
Simon Glass2aec3cc2014-10-23 18:58:47 -06001090int ft_board_setup(void *blob, bd_t *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001091{
Tim Harvey552c3582014-03-06 07:46:30 -08001092 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001093 struct ventana_eeprom_config *cfg;
Tim Harvey552c3582014-03-06 07:46:30 -08001094 struct node_info nodes[] = {
1095 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1096 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1097 };
1098 const char *model = getenv("model");
Tim Harveye4af5d32015-04-08 12:54:58 -07001099 const char *display = getenv("display");
Tim Harvey16e0eae2015-04-08 12:54:44 -07001100 int i;
1101 char rev = 0;
1102
1103 /* determine board revision */
1104 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1105 if (ventana_info.model[i] >= 'A') {
1106 rev = ventana_info.model[i];
1107 break;
1108 }
1109 }
Tim Harvey552c3582014-03-06 07:46:30 -08001110
1111 if (getenv("fdt_noauto")) {
1112 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001113 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001114 }
1115
Tim Harveyc9e43e02015-05-26 11:04:58 -07001116 if (test_bit(EECONFIG_NAND, info->config)) {
1117 /* Update partition nodes using info from mtdparts env var */
1118 puts(" Updating MTD partitions...\n");
1119 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1120 }
Tim Harvey552c3582014-03-06 07:46:30 -08001121
Tim Harveye4af5d32015-04-08 12:54:58 -07001122 /* Update display timings from display env var */
1123 if (display) {
1124 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1125 display) >= 0)
1126 printf(" Set display timings for %s...\n", display);
1127 }
1128
Tim Harvey552c3582014-03-06 07:46:30 -08001129 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1130
1131 /* board serial number */
1132 fdt_setprop(blob, 0, "system-serial", getenv("serial#"),
Tim Harveyae35ded2014-04-25 09:18:33 -07001133 strlen(getenv("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001134
1135 /* board (model contains model from device-tree) */
1136 fdt_setprop(blob, 0, "board", info->model,
1137 strlen((const char *)info->model) + 1);
1138
Tim Harveycf20e552015-04-08 12:55:01 -07001139 /* set desired digital video capture format */
1140 ft_sethdmiinfmt(blob, getenv("hdmiinfmt"));
1141
Tim Harvey552c3582014-03-06 07:46:30 -08001142 /*
Tim Harveya1d32222016-07-15 07:16:28 -07001143 * Board model specific fixups
Tim Harvey865dc9c2015-04-08 12:54:56 -07001144 */
Tim Harveya1d32222016-07-15 07:16:28 -07001145 switch (board_type) {
1146 case GW51xx:
1147 /*
1148 * disable wdog node for GW51xx-A/B to work around
1149 * errata causing wdog timer to be unreliable.
1150 */
1151 if (rev >= 'A' && rev < 'C') {
1152 i = fdt_path_offset(blob, WDOG1_PATH);
1153 if (i)
1154 fdt_status_disabled(blob, i);
1155 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001156
1157 /* GW51xx-E adds WDOG1_B external reset */
1158 if (rev < 'E')
1159 ft_delprop_path(blob, WDOG1_PATH,
1160 "fsl,ext-reset-output");
Tim Harveya1d32222016-07-15 07:16:28 -07001161 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001162
Tim Harveya1d32222016-07-15 07:16:28 -07001163 case GW52xx:
1164 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1165 if (info->model[4] == '2') {
1166 u32 handle = 0;
1167 u32 *range = NULL;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001168
Tim Harveya1d32222016-07-15 07:16:28 -07001169 i = fdt_node_offset_by_compatible(blob, -1,
1170 "fsl,imx6q-pcie");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001171 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001172 range = (u32 *)fdt_getprop(blob, i,
1173 "reset-gpio", NULL);
1174
1175 if (range) {
1176 i = fdt_path_offset(blob, GPIO3_PATH);
1177 if (i)
1178 handle = fdt_get_phandle(blob, i);
1179 if (handle) {
1180 range[0] = cpu_to_fdt32(handle);
1181 range[1] = cpu_to_fdt32(23);
1182 }
Pushpal Sidhud1100562015-04-08 12:55:00 -07001183 }
Tim Harveya1d32222016-07-15 07:16:28 -07001184
1185 /* these have broken usd_vsel */
1186 if (strstr((const char *)info->model, "SP318-B") ||
1187 strstr((const char *)info->model, "SP331-B"))
1188 gpio_cfg[board_type].usd_vsel = 0;
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001189
1190 /* GW520x-E adds WDOG1_B external reset */
1191 if (info->model[4] == '0' && rev < 'E')
1192 ft_delprop_path(blob, WDOG1_PATH,
1193 "fsl,ext-reset-output");
1194
1195 /* GW522x-B adds WDOG1_B external reset */
1196 if (info->model[4] == '2' && rev < 'B')
1197 ft_delprop_path(blob, WDOG1_PATH,
1198 "fsl,ext-reset-output");
Pushpal Sidhud1100562015-04-08 12:55:00 -07001199 }
Tim Harveya1d32222016-07-15 07:16:28 -07001200 break;
Tim Harvey147b5762016-05-24 11:03:59 -07001201
Tim Harveya1d32222016-07-15 07:16:28 -07001202 case GW53xx:
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001203 /* GW53xx-E adds WDOG1_B external reset */
1204 if (rev < 'E')
1205 ft_delprop_path(blob, WDOG1_PATH,
1206 "fsl,ext-reset-output");
Tim Harveya1d32222016-07-15 07:16:28 -07001207 break;
Pushpal Sidhud1100562015-04-08 12:55:00 -07001208
Tim Harveya1d32222016-07-15 07:16:28 -07001209 case GW54xx:
1210 /*
1211 * disable serial2 node for GW54xx for compatibility with older
1212 * 3.10.x kernel that improperly had this node enabled in the DT
1213 */
1214 i = fdt_path_offset(blob, UART1_PATH);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001215 if (i)
Tim Harveya1d32222016-07-15 07:16:28 -07001216 fdt_del_node(blob, i);
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001217
1218 /* GW54xx-E adds WDOG2_B external reset */
1219 if (rev < 'E')
1220 ft_delprop_path(blob, WDOG2_PATH,
1221 "fsl,ext-reset-output");
Tim Harveya1d32222016-07-15 07:16:28 -07001222 break;
1223
1224 case GW551x:
1225 /*
1226 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1227 * causing non functional digital video in (it is not hooked up)
1228 */
1229 if (rev == 'A') {
1230 u32 *range = NULL;
1231 int len;
1232 const u32 *handle = NULL;
1233
1234 i = fdt_node_offset_by_compatible(blob, -1,
1235 "fsl,imx-tda1997x-video");
1236 if (i)
1237 handle = fdt_getprop(blob, i, "pinctrl-0",
1238 NULL);
1239 if (handle)
1240 i = fdt_node_offset_by_phandle(blob,
1241 fdt32_to_cpu(*handle));
1242 if (i)
1243 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1244 &len);
1245 if (range) {
1246 len /= sizeof(u32);
1247 for (i = 0; i < len; i += 6) {
1248 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1249 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1250 /* mux PAD_CSI0_DATA_EN to GPIO */
1251 if (is_cpu_type(MXC_CPU_MX6Q) &&
1252 mux_reg == 0x260 &&
1253 conf_reg == 0x630)
1254 range[i+3] = cpu_to_fdt32(0x5);
1255 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1256 mux_reg == 0x08c &&
1257 conf_reg == 0x3a0)
1258 range[i+3] = cpu_to_fdt32(0x5);
1259 }
1260 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1261 len);
Tim Harvey6944ccf2015-04-08 12:54:53 -07001262 }
Tim Harveydc8b5e62015-04-08 12:55:02 -07001263
Tim Harveya1d32222016-07-15 07:16:28 -07001264 /* set BT656 video format */
1265 ft_sethdmiinfmt(blob, "yuv422bt656");
1266 }
Tim Harvey8d76d0d2016-07-15 07:16:29 -07001267
1268 /* GW551x-C adds WDOG1_B external reset */
1269 if (rev < 'C')
1270 ft_delprop_path(blob, WDOG1_PATH,
1271 "fsl,ext-reset-output");
Tim Harveya1d32222016-07-15 07:16:28 -07001272 break;
Tim Harvey6944ccf2015-04-08 12:54:53 -07001273 }
1274
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001275 /* Configure DIO */
Tim Harvey41595b52016-07-15 07:14:23 -07001276 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
Tim Harvey8d2d8df2016-05-24 11:03:55 -07001277 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1278 char arg[10];
1279
1280 sprintf(arg, "dio%d", i);
1281 if (!hwconfig(arg))
1282 continue;
1283 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1284 {
1285 char path[48];
1286 sprintf(path, "/soc/aips-bus@02000000/pwm@%08x",
1287 0x02080000 + (0x4000 * (cfg->pwm_param - 1)));
1288 printf(" Enabling pwm%d for DIO%d\n",
1289 cfg->pwm_param, i);
1290 ft_enable_path(blob, path);
1291 }
1292 }
1293
Tim Harvey147b5762016-05-24 11:03:59 -07001294 /* remove no-1-8-v if UHS-I support is present */
1295 if (gpio_cfg[board_type].usd_vsel) {
1296 debug("Enabling UHS-I support\n");
1297 ft_delprop_path(blob, "/soc/aips-bus@02100000/usdhc@02198000",
1298 "no-1-8-v");
1299 }
1300
Tim Harveybfb240a2016-06-17 06:10:41 -07001301#if defined(CONFIG_CMD_PCI)
1302 if (!getenv("nopcifixup"))
1303 ft_board_pci_fixup(blob, bd);
1304#endif
1305
Tim Harvey6944ccf2015-04-08 12:54:53 -07001306 /*
Tim Harvey552c3582014-03-06 07:46:30 -08001307 * Peripheral Config:
1308 * remove nodes by alias path if EEPROM config tells us the
1309 * peripheral is not loaded on the board.
1310 */
Tim Harvey0da2c522014-08-07 22:35:45 -07001311 if (getenv("fdt_noconfig")) {
1312 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001313 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001314 }
1315 cfg = econfig;
1316 while (cfg->name) {
1317 if (!test_bit(cfg->bit, info->config)) {
1318 fdt_del_node_and_alias(blob, cfg->dtalias ?
1319 cfg->dtalias : cfg->name);
1320 }
1321 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001322 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001323
1324 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001325}
Robert P. J. Day3c757002016-05-19 15:23:12 -04001326#endif /* CONFIG_OF_BOARD_SETUP */
Tim Harvey552c3582014-03-06 07:46:30 -08001327
Tim Harvey67ed7922015-05-08 18:28:29 -07001328static struct mxc_serial_platdata ventana_mxc_serial_plat = {
1329 .reg = (struct mxc_uart *)UART2_BASE,
1330};
1331
1332U_BOOT_DEVICE(ventana_serial) = {
1333 .name = "serial_mxc",
1334 .platdata = &ventana_mxc_serial_plat,
1335};