1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Gateworks Corporation
5 * Author: Tim Harvey <tharvey@gateworks.com>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/crm_regs.h>
14 #include <asm/arch/iomux.h>
15 #include <asm/arch/mx6-pins.h>
16 #include <asm/arch/mxc_hdmi.h>
17 #include <asm/arch/sys_proto.h>
19 #include <asm/mach-imx/boot_mode.h>
20 #include <asm/mach-imx/sata.h>
21 #include <asm/mach-imx/spi.h>
22 #include <asm/mach-imx/video.h>
24 #include <asm/setup.h>
26 #include <dm/platform_data/serial_mxc.h>
30 #include <fdt_support.h>
31 #include <fsl_esdhc_imx.h>
32 #include <jffs2/load_kernel.h>
33 #include <linux/ctype.h>
38 #include <linux/delay.h>
39 #include <linux/libfdt.h>
40 #include <power/pmic.h>
41 #include <power/ltc3676_pmic.h>
42 #include <power/pfuze100_pmic.h>
43 #include <fdt_support.h>
44 #include <jffs2/load_kernel.h>
45 #include <spi_flash.h>
50 DECLARE_GLOBAL_DATA_PTR;
54 * EEPROM board info struct populated by read_eeprom so that we only have to
57 struct ventana_board_info ventana_info;
59 static int board_type;
62 static iomux_v3_cfg_t const enet_pads[] = {
63 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
64 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
65 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
66 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
67 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
68 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
69 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
71 MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
73 MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
80 MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
85 #ifdef CONFIG_CMD_NAND
86 static iomux_v3_cfg_t const nfc_pads[] = {
87 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
88 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
89 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
90 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
91 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
92 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
93 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
95 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
97 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
98 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
99 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
100 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
101 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
104 static void setup_gpmi_nand(void)
106 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
108 /* config gpmi nand iomux */
109 SETUP_IOMUX_PADS(nfc_pads);
111 /* config gpmi and bch clock to 100 MHz */
112 clrsetbits_le32(&mxc_ccm->cs2cdr,
113 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
114 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
115 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
116 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
117 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
118 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
120 /* enable gpmi and bch clock gating */
121 setbits_le32(&mxc_ccm->CCGR4,
122 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
123 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
124 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
125 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
126 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
128 /* enable apbh clock gating */
129 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
133 static void setup_iomux_enet(int gpio)
135 SETUP_IOMUX_PADS(enet_pads);
137 /* toggle PHY_RST# */
138 gpio_request(gpio, "phy_rst#");
139 gpio_direction_output(gpio, 0);
141 gpio_set_value(gpio, 1);
145 #ifdef CONFIG_USB_EHCI_MX6
146 static iomux_v3_cfg_t const usb_pads[] = {
147 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
148 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
150 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
153 int board_ehci_hcd_init(int port)
157 SETUP_IOMUX_PADS(usb_pads);
160 switch (board_type) {
164 gpio = (IMX_GPIO_NR(1, 9));
168 gpio = (IMX_GPIO_NR(1, 16));
174 /* request and toggle hub rst */
175 gpio_request(gpio, "usb_hub_rst#");
176 gpio_direction_output(gpio, 0);
178 gpio_set_value(gpio, 1);
183 int board_ehci_power(int port, int on)
185 /* enable OTG VBUS */
186 if (!port && board_type < GW_UNKNOWN) {
187 if (gpio_cfg[board_type].otgpwr_en)
188 gpio_set_value(gpio_cfg[board_type].otgpwr_en, on);
192 #endif /* CONFIG_USB_EHCI_MX6 */
194 #ifdef CONFIG_MXC_SPI
195 iomux_v3_cfg_t const ecspi1_pads[] = {
197 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
198 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
199 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
200 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
203 int board_spi_cs_gpio(unsigned bus, unsigned cs)
205 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
208 static void setup_spi(void)
210 gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
211 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
212 SETUP_IOMUX_PADS(ecspi1_pads);
216 /* configure eth0 PHY board-specific LED behavior */
217 int board_phy_config(struct phy_device *phydev)
222 if (phydev->phy_id == 0x1410dd1) {
224 * Page 3, Register 16: LED[2:0] Function Control Register
225 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
226 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
228 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
229 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
232 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
233 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
237 else if (phydev->phy_id == 0x2000a231) {
238 /* configure register 0x170 for ref CLKOUT */
239 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
240 phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
241 phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
242 val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
244 val |= 0x0b00; /* chD tx clock*/
245 phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
248 if (phydev->drv->config)
249 phydev->drv->config(phydev);
254 #ifdef CONFIG_MV88E61XX_SWITCH
255 int mv88e61xx_hw_reset(struct phy_device *phydev)
257 struct mii_dev *bus = phydev->bus;
259 /* GPIO[0] output, CLK125 */
260 debug("enabling RGMII_REFCLK\n");
261 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
262 0x1a /*MV_SCRATCH_MISC*/,
263 (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
264 bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
265 0x1a /*MV_SCRATCH_MISC*/,
266 (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
268 /* RGMII delay - Physical Control register bit[15:14] */
269 debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
270 /* forced 1000mbps full-duplex link */
271 bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
272 phydev->autoneg = AUTONEG_DISABLE;
273 phydev->speed = SPEED_1000;
274 phydev->duplex = DUPLEX_FULL;
276 /* LED configuration: 7:4-green (8=Activity) 3:0 amber (8=Link) */
277 bus->write(bus, 0x10, 0, 0x16, 0x8088);
278 bus->write(bus, 0x11, 0, 0x16, 0x8088);
279 bus->write(bus, 0x12, 0, 0x16, 0x8088);
280 bus->write(bus, 0x13, 0, 0x16, 0x8088);
284 #endif // CONFIG_MV88E61XX_SWITCH
286 int board_eth_init(bd_t *bis)
288 #ifdef CONFIG_FEC_MXC
289 struct ventana_board_info *info = &ventana_info;
291 if (test_bit(EECONFIG_ETH0, info->config)) {
292 setup_iomux_enet(GP_PHY_RST);
298 e1000_initialize(bis);
302 /* For otg ethernet*/
303 usb_eth_initialize(bis);
306 /* default to the first detected enet dev */
307 if (!env_get("ethprime")) {
308 struct eth_device *dev = eth_get_dev_by_index(0);
310 env_set("ethprime", dev->name);
311 printf("set ethprime to %s\n", env_get("ethprime"));
318 #if defined(CONFIG_VIDEO_IPUV3)
320 static void enable_hdmi(struct display_info_t const *dev)
322 imx_enable_hdmi_phy();
325 static int detect_i2c(struct display_info_t const *dev)
327 return i2c_set_bus_num(dev->bus) == 0 &&
328 i2c_probe(dev->addr) == 0;
331 static void enable_lvds(struct display_info_t const *dev)
333 struct iomuxc *iomux = (struct iomuxc *)
336 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
337 u32 reg = readl(&iomux->gpr[2]);
338 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
339 writel(reg, &iomux->gpr[2]);
341 /* Enable Backlight */
342 gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
343 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
344 gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
345 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
346 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
349 struct display_info_t const displays[] = {{
353 .pixfmt = IPU_PIX_FMT_RGB24,
354 .detect = detect_hdmi,
355 .enable = enable_hdmi,
369 .vmode = FB_VMODE_NONINTERLACED
371 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
374 .pixfmt = IPU_PIX_FMT_LVDS666,
375 .detect = detect_i2c,
376 .enable = enable_lvds,
378 .name = "Hannstar-XGA",
390 .vmode = FB_VMODE_NONINTERLACED
396 .enable = enable_lvds,
397 .pixfmt = IPU_PIX_FMT_LVDS666,
399 .name = "DLC700JMGT4",
401 .xres = 1024, /* 1024x600active pixels */
403 .pixclock = 15385, /* 64MHz */
411 .vmode = FB_VMODE_NONINTERLACED
417 .enable = enable_lvds,
418 .pixfmt = IPU_PIX_FMT_LVDS666,
420 .name = "DLC800FIGT3",
422 .xres = 1024, /* 1024x768 active pixels */
424 .pixclock = 15385, /* 64MHz */
432 .vmode = FB_VMODE_NONINTERLACED
436 .detect = detect_i2c,
437 .enable = enable_lvds,
438 .pixfmt = IPU_PIX_FMT_LVDS666,
444 .pixclock = 15385, /* 64MHz */
452 .vmode = FB_VMODE_NONINTERLACED
456 size_t display_count = ARRAY_SIZE(displays);
458 static void setup_display(void)
460 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
461 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
466 /* Turn on LDB0,IPU,IPU DI0 clocks */
467 reg = __raw_readl(&mxc_ccm->CCGR3);
468 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
469 writel(reg, &mxc_ccm->CCGR3);
471 /* set LDB0, LDB1 clk select to 011/011 */
472 reg = readl(&mxc_ccm->cs2cdr);
473 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
474 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
475 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
476 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
477 writel(reg, &mxc_ccm->cs2cdr);
479 reg = readl(&mxc_ccm->cscmr2);
480 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
481 writel(reg, &mxc_ccm->cscmr2);
483 reg = readl(&mxc_ccm->chsccdr);
484 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
485 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
486 writel(reg, &mxc_ccm->chsccdr);
488 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
489 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
490 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
491 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
492 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
493 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
494 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
495 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
496 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
497 writel(reg, &iomux->gpr[2]);
499 reg = readl(&iomux->gpr[3]);
500 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
501 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
502 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
503 writel(reg, &iomux->gpr[3]);
505 /* LVDS Backlight GPIO on LVDS connector - output low */
506 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
507 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
509 #endif /* CONFIG_VIDEO_IPUV3 */
511 /* setup board specific PMIC */
512 int power_init_board(void)
518 #if defined(CONFIG_CMD_PCI)
519 int imx6_pcie_toggle_reset(void)
521 if (board_type < GW_UNKNOWN) {
522 uint pin = gpio_cfg[board_type].pcie_rst;
523 gpio_request(pin, "pci_rst#");
524 gpio_direction_output(pin, 0);
526 gpio_direction_output(pin, 1);
532 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
533 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
534 * properly and assert reset for 100ms.
536 #define MAX_PCI_DEVS 32
539 unsigned short vendor;
540 unsigned short device;
541 unsigned short class;
542 unsigned short busno; /* subbordinate busno */
543 struct pci_dev *ppar;
545 struct pci_dev pci_devs[MAX_PCI_DEVS];
549 void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
550 unsigned short vendor, unsigned short device,
551 unsigned short class)
555 struct pci_dev *pdev = &pci_devs[pci_devno++];
557 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
558 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
560 /* store array of devs for later use in device-tree fixup */
562 pdev->vendor = vendor;
563 pdev->device = device;
566 if (class == PCI_CLASS_BRIDGE_PCI)
567 pdev->busno = ++pci_bridgeno;
571 /* fixup RC - it should be 00:00.0 not 00:01.0 */
572 if (PCI_BUS(dev) == 0)
575 /* find dev's parent */
576 for (i = 0; i < pci_devno; i++) {
577 if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
578 pdev->ppar = &pci_devs[i];
583 /* assert downstream PERST# */
584 if (vendor == PCI_VENDOR_ID_PLX &&
585 (device & 0xfff0) == 0x8600 &&
586 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
587 debug("configuring PLX 860X downstream PERST#\n");
588 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
589 dw |= 0xaaa8; /* GPIO1-7 outputs */
590 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
592 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
593 dw |= 0xfe; /* GPIO1-7 output high */
594 pci_hose_write_config_dword(hose, dev, 0x644, dw);
599 #endif /* CONFIG_CMD_PCI */
601 #ifdef CONFIG_SERIAL_TAG
603 * called when setting up ATAGS before booting kernel
604 * populate serialnum from the following (in order of priority):
608 void get_board_serial(struct tag_serialnr *serialnr)
610 char *serial = env_get("serial#");
614 serialnr->low = simple_strtoul(serial, NULL, 10);
615 } else if (ventana_info.model[0]) {
617 serialnr->low = ventana_info.serial;
629 int board_early_init_f(void)
633 #if defined(CONFIG_VIDEO_IPUV3)
641 gd->ram_size = imx_ddr_size();
647 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
649 clrsetbits_le32(&iomuxc_regs->gpr[1],
650 IOMUXC_GPR1_OTG_ID_MASK,
651 IOMUXC_GPR1_OTG_ID_GPIO1);
653 /* address of linux boot parameters */
654 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
656 /* read Gateworks EEPROM into global struct (used later) */
657 setup_ventana_i2c(0);
658 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
660 #ifdef CONFIG_CMD_NAND
661 if (gpio_cfg[board_type].nand)
664 #ifdef CONFIG_MXC_SPI
667 setup_ventana_i2c(1);
668 setup_ventana_i2c(2);
674 setup_iomux_gpio(board_type, &ventana_info);
679 #if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
681 * called during late init (after relocation and after board_init())
682 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
687 struct ventana_board_info *info = &ventana_info;
688 unsigned char buf[4];
690 int quiet; /* Quiet or minimal output mode */
693 p = env_get("quiet");
695 quiet = simple_strtol(p, NULL, 10);
697 env_set("quiet", "0");
699 puts("\nGateworks Corporation Copyright 2014\n");
700 if (info->model[0]) {
701 printf("Model: %s\n", info->model);
702 printf("MFGDate: %02x-%02x-%02x%02x\n",
703 info->mfgdate[0], info->mfgdate[1],
704 info->mfgdate[2], info->mfgdate[3]);
705 printf("Serial:%d\n", info->serial);
707 puts("Invalid EEPROM - board will not function fully\n");
712 /* Display GSC firmware revision/CRC/status */
716 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
718 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
725 #ifdef CONFIG_CMD_BMODE
727 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
728 * see Table 8-11 and Table 5-9
729 * BOOT_CFG1[7] = 1 (boot from NAND)
730 * BOOT_CFG1[5] = 0 - raw NAND
731 * BOOT_CFG1[4] = 0 - default pad settings
732 * BOOT_CFG1[3:2] = 00 - devices = 1
733 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
734 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
735 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
736 * BOOT_CFG2[0] = 0 - Reset time 12ms
738 static const struct boot_mode board_boot_modes[] = {
739 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
740 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
741 { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
742 { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/4/5 */
748 int misc_init_r(void)
750 struct ventana_board_info *info = &ventana_info;
754 /* set env vars based on EEPROM data */
755 if (ventana_info.model[0]) {
756 char str[16], fdt[36];
758 const char *cputype = "";
761 * FDT name will be prefixed with CPU type. Three versions
762 * will be created each increasingly generic and bootloader
763 * env scripts will try loading each from most specific to
766 if (is_cpu_type(MXC_CPU_MX6Q) ||
767 is_cpu_type(MXC_CPU_MX6D))
769 else if (is_cpu_type(MXC_CPU_MX6DL) ||
770 is_cpu_type(MXC_CPU_MX6SOLO))
772 env_set("soctype", cputype);
773 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
774 env_set("flash_layout", "large");
776 env_set("flash_layout", "normal");
777 memset(str, 0, sizeof(str));
778 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
779 str[i] = tolower(info->model[i]);
780 env_set("model", str);
781 if (!env_get("fdt_file")) {
782 sprintf(fdt, "%s-%s.dtb", cputype, str);
783 env_set("fdt_file", fdt);
785 p = strchr(str, '-');
789 env_set("model_base", str);
790 sprintf(fdt, "%s-%s.dtb", cputype, str);
791 env_set("fdt_file1", fdt);
792 if (board_type != GW551x &&
793 board_type != GW552x &&
794 board_type != GW553x &&
795 board_type != GW560x)
799 sprintf(fdt, "%s-%s.dtb", cputype, str);
800 env_set("fdt_file2", fdt);
803 /* initialize env from EEPROM */
804 if (test_bit(EECONFIG_ETH0, info->config) &&
805 !env_get("ethaddr")) {
806 eth_env_set_enetaddr("ethaddr", info->mac0);
808 if (test_bit(EECONFIG_ETH1, info->config) &&
809 !env_get("eth1addr")) {
810 eth_env_set_enetaddr("eth1addr", info->mac1);
813 /* board serial-number */
814 sprintf(str, "%6d", info->serial);
815 env_set("serial#", str);
818 sprintf(str, "%d", (int) (gd->ram_size >> 20));
819 env_set("mem_mb", str);
822 /* Set a non-initialized hwconfig based on board configuration */
823 if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
825 if (gpio_cfg[board_type].rs232_en)
826 strcat(buf, "rs232;");
827 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
829 sprintf(buf1, "dio%d:mode=gpio;", i);
830 if (strlen(buf) + strlen(buf1) < sizeof(buf))
833 env_set("hwconfig", buf);
836 /* setup baseboard specific GPIO based on board and env */
837 setup_board_gpio(board_type, info);
839 #ifdef CONFIG_CMD_BMODE
840 add_board_boot_modes(board_boot_modes);
843 /* disable boot watchdog */
844 gsc_boot_wd_disable();
849 #ifdef CONFIG_OF_BOARD_SETUP
851 static int ft_sethdmiinfmt(void *blob, char *mode)
858 off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
862 if (0 == strcasecmp(mode, "yuv422bt656")) {
863 u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
866 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
867 fdt_setprop_u32(blob, off, "vidout_trc", 1);
868 fdt_setprop_u32(blob, off, "vidout_blc", 1);
869 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
870 printf(" set HDMI input mode to %s\n", mode);
871 } else if (0 == strcasecmp(mode, "yuv422smp")) {
872 u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
875 fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
876 fdt_setprop_u32(blob, off, "vidout_trc", 0);
877 fdt_setprop_u32(blob, off, "vidout_blc", 0);
878 fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
879 printf(" set HDMI input mode to %s\n", mode);
887 #if defined(CONFIG_CMD_PCI)
888 #define PCI_ID(x) ( \
889 (PCI_BUS(x->devfn)<<16)| \
890 (PCI_DEV(x->devfn)<<11)| \
891 (PCI_FUNC(x->devfn)<<8) \
893 int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
899 sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
900 PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
902 np = fdt_subnode_offset(blob, par, node);
905 np = fdt_add_subnode(blob, par, node);
907 printf(" %s failed: no space\n", __func__);
911 memset(reg, 0, sizeof(reg));
912 reg[0] = cpu_to_fdt32(PCI_ID(dev));
913 fdt_setprop(blob, np, "reg", reg, sizeof(reg));
918 /* build a path of nested PCI devs for all bridges passed through */
919 int fdt_add_pci_path(void *blob, struct pci_dev *dev)
921 struct pci_dev *bridges[MAX_PCI_DEVS];
924 /* build list of parents */
925 np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
935 /* now add them the to DT in reverse order */
937 np = fdt_add_pci_node(blob, np, bridges[k]);
946 * The GW16082 has a hardware errata errata such that it's
947 * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
948 * of this normal PCI interrupt swizzling will not work so we will
949 * provide an irq-map via device-tree.
951 int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
955 uint32_t imap_new[8*4*4];
956 const uint32_t *imap;
961 /* build irq-map based on host controllers map */
962 host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
964 printf(" %s failed: missing host\n", __func__);
968 /* use interrupt data from root complex's node */
969 imap = fdt_getprop(blob, host, "interrupt-map", &len);
970 if (!imap || len != 128) {
971 printf(" %s failed: invalid interrupt-map\n",
973 return -FDT_ERR_NOTFOUND;
976 /* obtain irq's of host controller in pin order */
977 for (i = 0; i < 4; i++)
978 irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
981 * determine number of swizzles necessary:
982 * For each bridge we pass through we need to swizzle
983 * the number of the slot we are on.
989 while(d && d->ppar) {
990 b += PCI_DEV(d->devfn);
994 /* create new irq mappings for slots12-15
995 * <skt> <idsel> <slot> <skt-inta> <skt-intb>
996 * J3 AD28 12 INTD INTA
997 * J4 AD29 13 INTC INTD
998 * J5 AD30 14 INTB INTC
999 * J2 AD31 15 INTA INTB
1001 for (i = 0; i < 4; i++) {
1002 /* addr matches bus:dev:func */
1003 u32 addr = dev->busno << 16 | (12+i) << 11;
1005 /* default cells from root complex */
1006 memcpy(&imap_new[i*32], imap, 128);
1007 /* first cell is PCI device address (BDF) */
1008 imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
1009 imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
1010 imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
1011 imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
1012 /* third cell is pin */
1013 imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
1014 imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
1015 imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
1016 imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
1017 /* sixth cell is relative interrupt */
1018 imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
1019 imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
1020 imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
1021 imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
1023 fdt_setprop(blob, np, "interrupt-map", imap_new,
1025 reg[0] = cpu_to_fdt32(0xfff00);
1028 reg[3] = cpu_to_fdt32(0x7);
1029 fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
1030 fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
1031 fdt_setprop_string(blob, np, "device_type", "pci");
1032 fdt_setprop_cell(blob, np, "#address-cells", 3);
1033 fdt_setprop_cell(blob, np, "#size-cells", 2);
1034 printf(" Added custom interrupt-map for GW16082\n");
1039 /* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
1040 int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
1044 unsigned char mac_addr[6];
1047 sprintf(mac, "eth1addr");
1050 for (j = 0; j < 6; j++) {
1052 simple_strtoul(tmp, &end,16) : 0;
1054 tmp = (*end) ? end+1 : end;
1056 fdt_setprop(blob, np, "local-mac-address", mac_addr,
1058 printf(" Added mac addr for eth1\n");
1066 * PCI DT nodes must be nested therefore if we need to apply a DT fixup
1067 * we will walk the PCI bus and add bridge nodes up to the device receiving
1070 void ft_board_pci_fixup(void *blob, bd_t *bd)
1073 struct pci_dev *dev;
1075 for (i = 0; i < pci_devno; i++) {
1079 * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
1080 * an EEPROM at i2c1-0x50.
1082 if ((dev->vendor == PCI_VENDOR_ID_TI) &&
1083 (dev->device == 0x8240) &&
1084 (i2c_set_bus_num(1) == 0) &&
1085 (i2c_probe(0x50) == 0))
1087 np = fdt_add_pci_path(blob, dev);
1089 fdt_fixup_gw16082(blob, np, dev);
1092 /* ethernet1 mac address */
1093 else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
1094 (dev->device == 0x4380))
1096 np = fdt_add_pci_path(blob, dev);
1098 fdt_fixup_sky2(blob, np, dev);
1102 #endif /* if defined(CONFIG_CMD_PCI) */
1104 void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
1106 int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
1109 fdt_delprop(blob, off, "ext-reset-output");
1110 fdt_delprop(blob, off, "fsl,ext-reset-output");
1115 * called prior to booting kernel or by 'fdt boardsetup' command
1117 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1118 * - mtd partitions based on mtdparts/mtdids env
1119 * - system-serial (board serial num from EEPROM)
1120 * - board (full model from EEPROM)
1121 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1123 #define WDOG1_ADDR 0x20bc000
1124 #define WDOG2_ADDR 0x20c0000
1125 #define GPIO3_ADDR 0x20a4000
1126 #define USDHC3_ADDR 0x2198000
1127 #define PWM0_ADDR 0x2080000
1128 int ft_board_setup(void *blob, bd_t *bd)
1130 struct ventana_board_info *info = &ventana_info;
1131 struct ventana_eeprom_config *cfg;
1132 static const struct node_info nodes[] = {
1133 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1134 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1136 const char *model = env_get("model");
1137 const char *display = env_get("display");
1141 /* determine board revision */
1142 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
1143 if (ventana_info.model[i] >= 'A') {
1144 rev = ventana_info.model[i];
1149 if (env_get("fdt_noauto")) {
1150 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
1154 if (test_bit(EECONFIG_NAND, info->config)) {
1155 /* Update partition nodes using info from mtdparts env var */
1156 puts(" Updating MTD partitions...\n");
1157 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1160 /* Update display timings from display env var */
1162 if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
1164 printf(" Set display timings for %s...\n", display);
1167 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1169 /* board serial number */
1170 fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
1171 strlen(env_get("serial#")) + 1);
1173 /* board (model contains model from device-tree) */
1174 fdt_setprop(blob, 0, "board", info->model,
1175 strlen((const char *)info->model) + 1);
1177 /* set desired digital video capture format */
1178 ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
1181 * Board model specific fixups
1183 switch (board_type) {
1186 * disable wdog node for GW51xx-A/B to work around
1187 * errata causing wdog timer to be unreliable.
1189 if (rev >= 'A' && rev < 'C') {
1190 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
1193 fdt_status_disabled(blob, i);
1196 /* GW51xx-E adds WDOG1_B external reset */
1198 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1202 /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
1203 if (info->model[4] == '2') {
1207 i = fdt_node_offset_by_compatible(blob, -1,
1210 range = (u32 *)fdt_getprop(blob, i,
1211 "reset-gpio", NULL);
1214 i = fdt_node_offset_by_compat_reg(blob,
1215 "fsl,imx6q-gpio", GPIO3_ADDR);
1217 handle = fdt_get_phandle(blob, i);
1219 range[0] = cpu_to_fdt32(handle);
1220 range[1] = cpu_to_fdt32(23);
1224 /* these have broken usd_vsel */
1225 if (strstr((const char *)info->model, "SP318-B") ||
1226 strstr((const char *)info->model, "SP331-B"))
1227 gpio_cfg[board_type].usd_vsel = 0;
1229 /* GW522x-B adds WDOG1_B external reset */
1231 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1234 /* GW520x-E adds WDOG1_B external reset */
1235 else if (info->model[4] == '0' && rev < 'E')
1236 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1240 /* GW53xx-E adds WDOG1_B external reset */
1242 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1247 * disable serial2 node for GW54xx for compatibility with older
1248 * 3.10.x kernel that improperly had this node enabled in the DT
1250 fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
1253 /* GW54xx-E adds WDOG2_B external reset */
1255 ft_board_wdog_fixup(blob, WDOG2_ADDR);
1260 * isolate CSI0_DATA_EN for GW551x-A to work around errata
1261 * causing non functional digital video in (it is not hooked up)
1266 const u32 *handle = NULL;
1268 i = fdt_node_offset_by_compatible(blob, -1,
1269 "fsl,imx-tda1997x-video");
1271 handle = fdt_getprop(blob, i, "pinctrl-0",
1274 i = fdt_node_offset_by_phandle(blob,
1275 fdt32_to_cpu(*handle));
1277 range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
1281 for (i = 0; i < len; i += 6) {
1282 u32 mux_reg = fdt32_to_cpu(range[i+0]);
1283 u32 conf_reg = fdt32_to_cpu(range[i+1]);
1284 /* mux PAD_CSI0_DATA_EN to GPIO */
1285 if (is_cpu_type(MXC_CPU_MX6Q) &&
1288 range[i+3] = cpu_to_fdt32(0x5);
1289 else if (!is_cpu_type(MXC_CPU_MX6Q) &&
1292 range[i+3] = cpu_to_fdt32(0x5);
1294 fdt_setprop_inplace(blob, i, "fsl,pins", range,
1298 /* set BT656 video format */
1299 ft_sethdmiinfmt(blob, "yuv422bt656");
1302 /* GW551x-C adds WDOG1_B external reset */
1304 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1308 /* GW5901/GW5901 revB adds WDOG1_B as an external reset */
1310 ft_board_wdog_fixup(blob, WDOG1_ADDR);
1315 for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
1316 struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
1319 sprintf(arg, "dio%d", i);
1322 if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
1327 printf(" Enabling pwm%d for DIO%d\n",
1329 addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
1330 off = fdt_node_offset_by_compat_reg(blob,
1334 fdt_status_okay(blob, off);
1338 /* remove no-1-8-v if UHS-I support is present */
1339 if (gpio_cfg[board_type].usd_vsel) {
1340 debug("Enabling UHS-I support\n");
1341 i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
1344 fdt_delprop(blob, i, "no-1-8-v");
1347 #if defined(CONFIG_CMD_PCI)
1348 if (!env_get("nopcifixup"))
1349 ft_board_pci_fixup(blob, bd);
1353 * Peripheral Config:
1354 * remove nodes by alias path if EEPROM config tells us the
1355 * peripheral is not loaded on the board.
1357 if (env_get("fdt_noconfig")) {
1358 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
1363 if (!test_bit(cfg->bit, info->config)) {
1364 fdt_del_node_and_alias(blob, cfg->dtalias ?
1365 cfg->dtalias : cfg->name);
1372 #endif /* CONFIG_OF_BOARD_SETUP */
1374 static struct mxc_serial_platdata ventana_mxc_serial_plat = {
1375 .reg = (struct mxc_uart *)UART2_BASE,
1378 U_BOOT_DEVICE(ventana_serial) = {
1379 .name = "serial_mxc",
1380 .platdata = &ventana_mxc_serial_plat,