blob: 84d7124e86f6a0a00b08e8904afa4c29a8c5d831 [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>
10#include <asm/io.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
14#include <asm/arch/mx6-pins.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070015#include <asm/arch/mxc_hdmi.h>
Tim Harvey552c3582014-03-06 07:46:30 -080016#include <asm/arch/crm_regs.h>
17#include <asm/arch/sys_proto.h>
18#include <asm/gpio.h>
19#include <asm/imx-common/iomux-v3.h>
20#include <asm/imx-common/mxc_i2c.h>
21#include <asm/imx-common/boot_mode.h>
22#include <asm/imx-common/sata.h>
Eric Nelson16acd1c2014-09-30 15:40:03 -070023#include <asm/imx-common/spi.h>
Tim Harveyfb64cc72014-04-25 15:39:07 -070024#include <asm/imx-common/video.h>
Tim Harvey552c3582014-03-06 07:46:30 -080025#include <jffs2/load_kernel.h>
26#include <hwconfig.h>
27#include <i2c.h>
28#include <linux/ctype.h>
29#include <fdt_support.h>
30#include <fsl_esdhc.h>
31#include <miiphy.h>
32#include <mmc.h>
33#include <mtd_node.h>
34#include <netdev.h>
Tim Harvey33791d52014-08-07 22:49:57 -070035#include <pci.h>
Tim Harvey552c3582014-03-06 07:46:30 -080036#include <power/pmic.h>
Tim Harvey0dff16f2014-05-05 08:22:25 -070037#include <power/ltc3676_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080038#include <power/pfuze100_pmic.h>
Tim Harvey552c3582014-03-06 07:46:30 -080039#include <fdt_support.h>
40#include <jffs2/load_kernel.h>
41#include <spi_flash.h>
42
43#include "gsc.h"
44#include "ventana_eeprom.h"
45
46DECLARE_GLOBAL_DATA_PTR;
47
48/* GPIO's common to all baseboards */
49#define GP_PHY_RST IMX_GPIO_NR(1, 30)
50#define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
51#define GP_SD3_CD IMX_GPIO_NR(7, 0)
52#define GP_RS232_EN IMX_GPIO_NR(2, 11)
53#define GP_MSATA_SEL IMX_GPIO_NR(2, 8)
54
Tim Harvey552c3582014-03-06 07:46:30 -080055#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
56 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
57 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
58
59#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
60 PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
61 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
62
63#define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
64 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
65 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
66
67#define SPI_PAD_CTRL (PAD_CTL_HYS | \
68 PAD_CTL_PUS_100K_DOWN | PAD_CTL_SPEED_MED | \
69 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
70
71#define DIO_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
72 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
73 PAD_CTL_DSE_34ohm | PAD_CTL_HYS | PAD_CTL_SRE_FAST)
74
75#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
76 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
77 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
78
Tim Harvey26993362014-08-07 22:35:49 -070079#define IRQ_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
80 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
81 PAD_CTL_DSE_34ohm | PAD_CTL_HYS | PAD_CTL_SRE_FAST)
82
83#define DIO_PAD_CFG (MUX_PAD_CTRL(DIO_PAD_CTRL) | MUX_MODE_SION)
84
85
Tim Harvey552c3582014-03-06 07:46:30 -080086/*
87 * EEPROM board info struct populated by read_eeprom so that we only have to
88 * read it once.
89 */
Tim Harvey0da2c522014-08-07 22:35:45 -070090struct ventana_board_info ventana_info;
Tim Harvey552c3582014-03-06 07:46:30 -080091
Tim Harvey552c3582014-03-06 07:46:30 -080092int board_type;
93
94/* UART1: Function varies per baseboard */
95iomux_v3_cfg_t const uart1_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -070096 IOMUX_PADS(PAD_SD3_DAT6__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
97 IOMUX_PADS(PAD_SD3_DAT7__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -080098};
99
100/* UART2: Serial Console */
101iomux_v3_cfg_t const uart2_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700102 IOMUX_PADS(PAD_SD4_DAT7__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
103 IOMUX_PADS(PAD_SD4_DAT4__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800104};
105
106#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
107
108/* I2C1: GSC */
Tim Harvey02fb5922014-06-02 16:13:26 -0700109struct i2c_pads_info mx6q_i2c_pad_info0 = {
Tim Harvey552c3582014-03-06 07:46:30 -0800110 .scl = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700111 .i2c_mode = MX6Q_PAD_EIM_D21__I2C1_SCL | PC,
112 .gpio_mode = MX6Q_PAD_EIM_D21__GPIO3_IO21 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800113 .gp = IMX_GPIO_NR(3, 21)
114 },
115 .sda = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700116 .i2c_mode = MX6Q_PAD_EIM_D28__I2C1_SDA | PC,
117 .gpio_mode = MX6Q_PAD_EIM_D28__GPIO3_IO28 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800118 .gp = IMX_GPIO_NR(3, 28)
119 }
120};
Tim Harvey02fb5922014-06-02 16:13:26 -0700121struct i2c_pads_info mx6dl_i2c_pad_info0 = {
122 .scl = {
123 .i2c_mode = MX6DL_PAD_EIM_D21__I2C1_SCL | PC,
124 .gpio_mode = MX6DL_PAD_EIM_D21__GPIO3_IO21 | PC,
125 .gp = IMX_GPIO_NR(3, 21)
126 },
127 .sda = {
128 .i2c_mode = MX6DL_PAD_EIM_D28__I2C1_SDA | PC,
129 .gpio_mode = MX6DL_PAD_EIM_D28__GPIO3_IO28 | PC,
130 .gp = IMX_GPIO_NR(3, 28)
131 }
132};
Tim Harvey552c3582014-03-06 07:46:30 -0800133
134/* I2C2: PMIC/PCIe Switch/PCIe Clock/Mezz */
Tim Harvey02fb5922014-06-02 16:13:26 -0700135struct i2c_pads_info mx6q_i2c_pad_info1 = {
Tim Harvey552c3582014-03-06 07:46:30 -0800136 .scl = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700137 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL | PC,
138 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800139 .gp = IMX_GPIO_NR(4, 12)
140 },
141 .sda = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700142 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA | PC,
143 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800144 .gp = IMX_GPIO_NR(4, 13)
145 }
146};
Tim Harvey02fb5922014-06-02 16:13:26 -0700147struct i2c_pads_info mx6dl_i2c_pad_info1 = {
148 .scl = {
149 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL | PC,
150 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12 | PC,
151 .gp = IMX_GPIO_NR(4, 12)
152 },
153 .sda = {
154 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA | PC,
155 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 | PC,
156 .gp = IMX_GPIO_NR(4, 13)
157 }
158};
Tim Harvey552c3582014-03-06 07:46:30 -0800159
160/* I2C3: Misc/Expansion */
Tim Harvey02fb5922014-06-02 16:13:26 -0700161struct i2c_pads_info mx6q_i2c_pad_info2 = {
162 .scl = {
163 .i2c_mode = MX6Q_PAD_GPIO_3__I2C3_SCL | PC,
164 .gpio_mode = MX6Q_PAD_GPIO_3__GPIO1_IO03 | PC,
165 .gp = IMX_GPIO_NR(1, 3)
166 },
167 .sda = {
168 .i2c_mode = MX6Q_PAD_GPIO_6__I2C3_SDA | PC,
169 .gpio_mode = MX6Q_PAD_GPIO_6__GPIO1_IO06 | PC,
170 .gp = IMX_GPIO_NR(1, 6)
171 }
172};
173struct i2c_pads_info mx6dl_i2c_pad_info2 = {
Tim Harvey552c3582014-03-06 07:46:30 -0800174 .scl = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700175 .i2c_mode = MX6DL_PAD_GPIO_3__I2C3_SCL | PC,
176 .gpio_mode = MX6DL_PAD_GPIO_3__GPIO1_IO03 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800177 .gp = IMX_GPIO_NR(1, 3)
178 },
179 .sda = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700180 .i2c_mode = MX6DL_PAD_GPIO_6__I2C3_SDA | PC,
181 .gpio_mode = MX6DL_PAD_GPIO_6__GPIO1_IO06 | PC,
Tim Harvey552c3582014-03-06 07:46:30 -0800182 .gp = IMX_GPIO_NR(1, 6)
183 }
184};
185
186/* MMC */
187iomux_v3_cfg_t const usdhc3_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700188 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
189 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
190 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
191 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
192 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
193 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
194 /* CD */
Tim Harvey26993362014-08-07 22:35:49 -0700195 IOMUX_PADS(PAD_SD3_DAT5__GPIO7_IO00 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800196};
197
198/* ENET */
199iomux_v3_cfg_t const enet_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700200 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
201 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
202 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
203 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
204 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
205 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
206 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
207 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
208 MUX_PAD_CTRL(ENET_PAD_CTRL)),
209 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
210 MUX_PAD_CTRL(ENET_PAD_CTRL)),
211 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
212 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
213 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
214 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
215 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
216 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
217 MUX_PAD_CTRL(ENET_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800218 /* PHY nRST */
Tim Harvey26993362014-08-07 22:35:49 -0700219 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800220};
221
222/* NAND */
223iomux_v3_cfg_t const nfc_pads[] = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700224 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
225 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
226 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
227 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
228 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
229 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
230 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
231 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
232 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
233 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
234 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
235 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
236 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
237 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
238 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800239};
240
241#ifdef CONFIG_CMD_NAND
242static void setup_gpmi_nand(void)
243{
244 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
245
246 /* config gpmi nand iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -0700247 SETUP_IOMUX_PADS(nfc_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800248
249 /* config gpmi and bch clock to 100 MHz */
250 clrsetbits_le32(&mxc_ccm->cs2cdr,
251 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
252 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
253 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
254 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
255 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
256 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
257
258 /* enable gpmi and bch clock gating */
259 setbits_le32(&mxc_ccm->CCGR4,
260 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
261 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
262 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
263 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
264 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
265
266 /* enable apbh clock gating */
267 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
268}
269#endif
270
271static void setup_iomux_enet(void)
272{
Tim Harvey02fb5922014-06-02 16:13:26 -0700273 SETUP_IOMUX_PADS(enet_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800274
275 /* toggle PHY_RST# */
276 gpio_direction_output(GP_PHY_RST, 0);
277 mdelay(2);
278 gpio_set_value(GP_PHY_RST, 1);
279}
280
281static void setup_iomux_uart(void)
282{
Tim Harvey02fb5922014-06-02 16:13:26 -0700283 SETUP_IOMUX_PADS(uart1_pads);
284 SETUP_IOMUX_PADS(uart2_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800285}
286
287#ifdef CONFIG_USB_EHCI_MX6
288iomux_v3_cfg_t const usb_pads[] = {
Tim Harvey26993362014-08-07 22:35:49 -0700289 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
290 IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
Tim Harvey02fb5922014-06-02 16:13:26 -0700291 /* OTG PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700292 IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800293};
294
295int board_ehci_hcd_init(int port)
296{
297 struct ventana_board_info *info = &ventana_info;
298
Tim Harvey02fb5922014-06-02 16:13:26 -0700299 SETUP_IOMUX_PADS(usb_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800300
301 /* Reset USB HUB (present on GW54xx/GW53xx) */
302 switch (info->model[3]) {
303 case '3': /* GW53xx */
Tim Harvey50581832014-08-20 23:35:14 -0700304 case '5': /* GW552x */
Tim Harvey26993362014-08-07 22:35:49 -0700305 SETUP_IOMUX_PAD(PAD_GPIO_9__GPIO1_IO09 | DIO_PAD_CFG);
Tim Harvey552c3582014-03-06 07:46:30 -0800306 gpio_direction_output(IMX_GPIO_NR(1, 9), 0);
307 mdelay(2);
308 gpio_set_value(IMX_GPIO_NR(1, 9), 1);
309 break;
310 case '4': /* GW54xx */
Tim Harvey26993362014-08-07 22:35:49 -0700311 SETUP_IOMUX_PAD(PAD_SD1_DAT0__GPIO1_IO16 | DIO_PAD_CFG);
Tim Harvey552c3582014-03-06 07:46:30 -0800312 gpio_direction_output(IMX_GPIO_NR(1, 16), 0);
313 mdelay(2);
314 gpio_set_value(IMX_GPIO_NR(1, 16), 1);
315 break;
316 }
317
318 return 0;
319}
320
321int board_ehci_power(int port, int on)
322{
323 if (port)
324 return 0;
325 gpio_set_value(GP_USB_OTG_PWR, on);
326 return 0;
327}
328#endif /* CONFIG_USB_EHCI_MX6 */
329
330#ifdef CONFIG_FSL_ESDHC
331struct fsl_esdhc_cfg usdhc_cfg = { USDHC3_BASE_ADDR };
332
333int board_mmc_getcd(struct mmc *mmc)
334{
335 /* Card Detect */
336 gpio_direction_input(GP_SD3_CD);
337 return !gpio_get_value(GP_SD3_CD);
338}
339
340int board_mmc_init(bd_t *bis)
341{
342 /* Only one USDHC controller on Ventana */
Tim Harvey02fb5922014-06-02 16:13:26 -0700343 SETUP_IOMUX_PADS(usdhc3_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800344 usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
345 usdhc_cfg.max_bus_width = 4;
346
347 return fsl_esdhc_initialize(bis, &usdhc_cfg);
348}
349#endif /* CONFIG_FSL_ESDHC */
350
351#ifdef CONFIG_MXC_SPI
352iomux_v3_cfg_t const ecspi1_pads[] = {
353 /* SS1 */
Tim Harvey02fb5922014-06-02 16:13:26 -0700354 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
355 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
356 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
357 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800358};
359
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300360int board_spi_cs_gpio(unsigned bus, unsigned cs)
361{
362 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
363}
364
Tim Harvey552c3582014-03-06 07:46:30 -0800365static void setup_spi(void)
366{
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300367 gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
Tim Harvey02fb5922014-06-02 16:13:26 -0700368 SETUP_IOMUX_PADS(ecspi1_pads);
Tim Harvey552c3582014-03-06 07:46:30 -0800369}
370#endif
371
372/* configure eth0 PHY board-specific LED behavior */
373int board_phy_config(struct phy_device *phydev)
374{
375 unsigned short val;
376
377 /* Marvel 88E1510 */
378 if (phydev->phy_id == 0x1410dd1) {
379 /*
380 * Page 3, Register 16: LED[2:0] Function Control Register
381 * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
382 * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
383 */
384 phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
385 val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
386 val &= 0xff00;
387 val |= 0x0017;
388 phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
389 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
390 }
391
392 if (phydev->drv->config)
393 phydev->drv->config(phydev);
394
395 return 0;
396}
397
398int board_eth_init(bd_t *bis)
399{
400 setup_iomux_enet();
401
402#ifdef CONFIG_FEC_MXC
Tim Harvey50581832014-08-20 23:35:14 -0700403 if (board_type != GW552x)
404 cpu_eth_init(bis);
Tim Harvey552c3582014-03-06 07:46:30 -0800405#endif
406
Tim Harvey472884d2015-04-08 12:54:32 -0700407#ifdef CONFIG_E1000
408 e1000_initialize(bis);
409#endif
410
Tim Harvey552c3582014-03-06 07:46:30 -0800411#ifdef CONFIG_CI_UDC
412 /* For otg ethernet*/
413 usb_eth_initialize(bis);
414#endif
415
Tim Harveyfc5ff942015-04-08 12:54:33 -0700416 /* default to the first detected enet dev */
417 if (!getenv("ethprime")) {
418 struct eth_device *dev = eth_get_dev_by_index(0);
419 if (dev) {
420 setenv("ethprime", dev->name);
421 printf("set ethprime to %s\n", getenv("ethprime"));
422 }
423 }
424
Tim Harvey552c3582014-03-06 07:46:30 -0800425 return 0;
426}
427
Tim Harveyfb64cc72014-04-25 15:39:07 -0700428#if defined(CONFIG_VIDEO_IPUV3)
429
430static void enable_hdmi(struct display_info_t const *dev)
431{
432 imx_enable_hdmi_phy();
433}
434
435static int detect_i2c(struct display_info_t const *dev)
436{
437 return i2c_set_bus_num(dev->bus) == 0 &&
438 i2c_probe(dev->addr) == 0;
439}
440
441static void enable_lvds(struct display_info_t const *dev)
442{
443 struct iomuxc *iomux = (struct iomuxc *)
444 IOMUXC_BASE_ADDR;
445
446 /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
447 u32 reg = readl(&iomux->gpr[2]);
448 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
449 writel(reg, &iomux->gpr[2]);
450
451 /* Enable Backlight */
Tim Harvey26993362014-08-07 22:35:49 -0700452 SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700453 gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
454}
455
456struct display_info_t const displays[] = {{
457 /* HDMI Output */
458 .bus = -1,
459 .addr = 0,
460 .pixfmt = IPU_PIX_FMT_RGB24,
461 .detect = detect_hdmi,
462 .enable = enable_hdmi,
463 .mode = {
464 .name = "HDMI",
465 .refresh = 60,
466 .xres = 1024,
467 .yres = 768,
468 .pixclock = 15385,
469 .left_margin = 220,
470 .right_margin = 40,
471 .upper_margin = 21,
472 .lower_margin = 7,
473 .hsync_len = 60,
474 .vsync_len = 10,
475 .sync = FB_SYNC_EXT,
476 .vmode = FB_VMODE_NONINTERLACED
477} }, {
478 /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
479 .bus = 2,
480 .addr = 0x4,
481 .pixfmt = IPU_PIX_FMT_LVDS666,
482 .detect = detect_i2c,
483 .enable = enable_lvds,
484 .mode = {
485 .name = "Hannstar-XGA",
486 .refresh = 60,
487 .xres = 1024,
488 .yres = 768,
489 .pixclock = 15385,
490 .left_margin = 220,
491 .right_margin = 40,
492 .upper_margin = 21,
493 .lower_margin = 7,
494 .hsync_len = 60,
495 .vsync_len = 10,
496 .sync = FB_SYNC_EXT,
497 .vmode = FB_VMODE_NONINTERLACED
498} } };
499size_t display_count = ARRAY_SIZE(displays);
500
501static void setup_display(void)
502{
503 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
504 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
505 int reg;
506
507 enable_ipu_clock();
508 imx_setup_hdmi();
509 /* Turn on LDB0,IPU,IPU DI0 clocks */
510 reg = __raw_readl(&mxc_ccm->CCGR3);
511 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
512 writel(reg, &mxc_ccm->CCGR3);
513
514 /* set LDB0, LDB1 clk select to 011/011 */
515 reg = readl(&mxc_ccm->cs2cdr);
516 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
517 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
518 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
519 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
520 writel(reg, &mxc_ccm->cs2cdr);
521
522 reg = readl(&mxc_ccm->cscmr2);
523 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
524 writel(reg, &mxc_ccm->cscmr2);
525
526 reg = readl(&mxc_ccm->chsccdr);
527 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
528 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
529 writel(reg, &mxc_ccm->chsccdr);
530
531 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
532 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
533 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
534 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
535 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
536 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
537 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
538 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
539 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
540 writel(reg, &iomux->gpr[2]);
541
542 reg = readl(&iomux->gpr[3]);
543 reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
544 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
545 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
546 writel(reg, &iomux->gpr[3]);
547
548 /* Backlight CABEN on LVDS connector */
Tim Harvey26993362014-08-07 22:35:49 -0700549 SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
Tim Harveyfb64cc72014-04-25 15:39:07 -0700550 gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
551}
552#endif /* CONFIG_VIDEO_IPUV3 */
553
Tim Harvey552c3582014-03-06 07:46:30 -0800554/*
555 * Baseboard specific GPIO
556 */
557
558/* common to add baseboards */
559static iomux_v3_cfg_t const gw_gpio_pads[] = {
560 /* MSATA_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700561 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800562 /* RS232_EN# */
Tim Harvey26993362014-08-07 22:35:49 -0700563 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800564};
565
566/* prototype */
567static iomux_v3_cfg_t const gwproto_gpio_pads[] = {
568 /* PANLEDG# */
Tim Harvey26993362014-08-07 22:35:49 -0700569 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800570 /* PANLEDR# */
Tim Harvey26993362014-08-07 22:35:49 -0700571 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800572 /* LOCLED# */
Tim Harvey26993362014-08-07 22:35:49 -0700573 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800574 /* RS485_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700575 IOMUX_PADS(PAD_SD3_DAT4__GPIO7_IO01 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800576 /* IOEXP_PWREN# */
Tim Harvey26993362014-08-07 22:35:49 -0700577 IOMUX_PADS(PAD_EIM_A19__GPIO2_IO19 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800578 /* IOEXP_IRQ# */
Tim Harvey26993362014-08-07 22:35:49 -0700579 IOMUX_PADS(PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800580 /* VID_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700581 IOMUX_PADS(PAD_EIM_D31__GPIO3_IO31 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800582 /* DIOI2C_DIS# */
Tim Harvey26993362014-08-07 22:35:49 -0700583 IOMUX_PADS(PAD_GPIO_19__GPIO4_IO05 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800584 /* PCICK_SSON */
Tim Harvey26993362014-08-07 22:35:49 -0700585 IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800586 /* PCI_RST# */
Tim Harvey26993362014-08-07 22:35:49 -0700587 IOMUX_PADS(PAD_ENET_TXD1__GPIO1_IO29 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800588};
589
590static iomux_v3_cfg_t const gw51xx_gpio_pads[] = {
591 /* PANLEDG# */
Tim Harvey26993362014-08-07 22:35:49 -0700592 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800593 /* PANLEDR# */
Tim Harvey26993362014-08-07 22:35:49 -0700594 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800595 /* IOEXP_PWREN# */
Tim Harvey26993362014-08-07 22:35:49 -0700596 IOMUX_PADS(PAD_EIM_A19__GPIO2_IO19 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800597 /* IOEXP_IRQ# */
Tim Harvey26993362014-08-07 22:35:49 -0700598 IOMUX_PADS(PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800599
600 /* GPS_SHDN */
Tim Harvey26993362014-08-07 22:35:49 -0700601 IOMUX_PADS(PAD_GPIO_2__GPIO1_IO02 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800602 /* VID_PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700603 IOMUX_PADS(PAD_CSI0_DATA_EN__GPIO5_IO20 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800604 /* PCI_RST# */
Tim Harvey26993362014-08-07 22:35:49 -0700605 IOMUX_PADS(PAD_GPIO_0__GPIO1_IO00 | DIO_PAD_CFG),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700606 /* PCIESKT_WDIS# */
607 IOMUX_PADS(PAD_GPIO_17__GPIO7_IO12 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800608};
609
610static iomux_v3_cfg_t const gw52xx_gpio_pads[] = {
611 /* PANLEDG# */
Tim Harvey26993362014-08-07 22:35:49 -0700612 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800613 /* PANLEDR# */
Tim Harvey26993362014-08-07 22:35:49 -0700614 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800615 /* IOEXP_PWREN# */
Tim Harvey26993362014-08-07 22:35:49 -0700616 IOMUX_PADS(PAD_EIM_A19__GPIO2_IO19 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800617 /* IOEXP_IRQ# */
Tim Harvey26993362014-08-07 22:35:49 -0700618 IOMUX_PADS(PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800619
620 /* MX6_LOCLED# */
Tim Harvey26993362014-08-07 22:35:49 -0700621 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800622 /* GPS_SHDN */
Tim Harvey26993362014-08-07 22:35:49 -0700623 IOMUX_PADS(PAD_ENET_RXD0__GPIO1_IO27 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800624 /* USBOTG_SEL */
Tim Harvey26993362014-08-07 22:35:49 -0700625 IOMUX_PADS(PAD_GPIO_2__GPIO1_IO02 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800626 /* VID_PWR */
Tim Harvey26993362014-08-07 22:35:49 -0700627 IOMUX_PADS(PAD_EIM_D31__GPIO3_IO31 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800628 /* PCI_RST# */
Tim Harvey26993362014-08-07 22:35:49 -0700629 IOMUX_PADS(PAD_ENET_TXD1__GPIO1_IO29 | DIO_PAD_CFG),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700630 /* PCIESKT_WDIS# */
631 IOMUX_PADS(PAD_GPIO_17__GPIO7_IO12 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800632};
633
634static iomux_v3_cfg_t const gw53xx_gpio_pads[] = {
635 /* PANLEDG# */
Tim Harvey26993362014-08-07 22:35:49 -0700636 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800637 /* PANLEDR# */
Tim Harvey26993362014-08-07 22:35:49 -0700638 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
Tim Harvey50581832014-08-20 23:35:14 -0700639 /* MX6_LOCLED# */
640 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800641 /* IOEXP_PWREN# */
Tim Harvey26993362014-08-07 22:35:49 -0700642 IOMUX_PADS(PAD_EIM_A19__GPIO2_IO19 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800643 /* IOEXP_IRQ# */
Tim Harvey26993362014-08-07 22:35:49 -0700644 IOMUX_PADS(PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey2722ac32014-08-07 22:35:48 -0700645 /* DIOI2C_DIS# */
Tim Harvey26993362014-08-07 22:35:49 -0700646 IOMUX_PADS(PAD_GPIO_19__GPIO4_IO05 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800647 /* GPS_SHDN */
Tim Harvey26993362014-08-07 22:35:49 -0700648 IOMUX_PADS(PAD_ENET_RXD0__GPIO1_IO27 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800649 /* VID_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700650 IOMUX_PADS(PAD_EIM_D31__GPIO3_IO31 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800651 /* PCI_RST# */
Tim Harvey26993362014-08-07 22:35:49 -0700652 IOMUX_PADS(PAD_ENET_TXD1__GPIO1_IO29 | DIO_PAD_CFG),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700653 /* PCIESKT_WDIS# */
654 IOMUX_PADS(PAD_GPIO_17__GPIO7_IO12 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800655};
656
657static iomux_v3_cfg_t const gw54xx_gpio_pads[] = {
658 /* PANLEDG# */
Tim Harvey26993362014-08-07 22:35:49 -0700659 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800660 /* PANLEDR# */
Tim Harvey26993362014-08-07 22:35:49 -0700661 IOMUX_PADS(PAD_KEY_COL2__GPIO4_IO10 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800662 /* MX6_LOCLED# */
Tim Harvey26993362014-08-07 22:35:49 -0700663 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800664 /* MIPI_DIO */
Tim Harvey26993362014-08-07 22:35:49 -0700665 IOMUX_PADS(PAD_SD1_DAT3__GPIO1_IO21 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800666 /* RS485_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700667 IOMUX_PADS(PAD_EIM_D24__GPIO3_IO24 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800668 /* IOEXP_PWREN# */
Tim Harvey26993362014-08-07 22:35:49 -0700669 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800670 /* IOEXP_IRQ# */
Tim Harvey26993362014-08-07 22:35:49 -0700671 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(IRQ_PAD_CTRL)),
Tim Harvey552c3582014-03-06 07:46:30 -0800672 /* DIOI2C_DIS# */
Tim Harvey26993362014-08-07 22:35:49 -0700673 IOMUX_PADS(PAD_GPIO_19__GPIO4_IO05 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800674 /* PCICK_SSON */
Tim Harvey26993362014-08-07 22:35:49 -0700675 IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800676 /* PCI_RST# */
Tim Harvey26993362014-08-07 22:35:49 -0700677 IOMUX_PADS(PAD_ENET_TXD1__GPIO1_IO29 | DIO_PAD_CFG),
Tim Harveyde1ef8e2014-08-07 22:35:46 -0700678 /* VID_EN */
Tim Harvey26993362014-08-07 22:35:49 -0700679 IOMUX_PADS(PAD_EIM_D31__GPIO3_IO31 | DIO_PAD_CFG),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700680 /* PCIESKT_WDIS# */
681 IOMUX_PADS(PAD_DISP0_DAT23__GPIO5_IO17 | DIO_PAD_CFG),
Tim Harvey552c3582014-03-06 07:46:30 -0800682};
683
Tim Harvey50581832014-08-20 23:35:14 -0700684static iomux_v3_cfg_t const gw552x_gpio_pads[] = {
685 /* PANLEDG# */
686 IOMUX_PADS(PAD_KEY_COL0__GPIO4_IO06 | DIO_PAD_CFG),
687 /* PANLEDR# */
688 IOMUX_PADS(PAD_KEY_ROW0__GPIO4_IO07 | DIO_PAD_CFG),
689 /* MX6_LOCLED# */
690 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | DIO_PAD_CFG),
691 /* PCI_RST# */
692 IOMUX_PADS(PAD_ENET_TXD1__GPIO1_IO29 | DIO_PAD_CFG),
693 /* MX6_DIO[4:9] */
694 IOMUX_PADS(PAD_CSI0_PIXCLK__GPIO5_IO18 | DIO_PAD_CFG),
695 IOMUX_PADS(PAD_CSI0_DATA_EN__GPIO5_IO20 | DIO_PAD_CFG),
696 IOMUX_PADS(PAD_CSI0_VSYNC__GPIO5_IO21 | DIO_PAD_CFG),
697 IOMUX_PADS(PAD_CSI0_DAT4__GPIO5_IO22 | DIO_PAD_CFG),
698 IOMUX_PADS(PAD_CSI0_DAT5__GPIO5_IO23 | DIO_PAD_CFG),
699 IOMUX_PADS(PAD_CSI0_DAT7__GPIO5_IO25 | DIO_PAD_CFG),
700 /* PCIEGBE1_OFF# */
701 IOMUX_PADS(PAD_GPIO_1__GPIO1_IO01 | DIO_PAD_CFG),
702 /* PCIEGBE2_OFF# */
703 IOMUX_PADS(PAD_GPIO_2__GPIO1_IO02 | DIO_PAD_CFG),
704 /* PCIESKT_WDIS# */
705 IOMUX_PADS(PAD_GPIO_17__GPIO7_IO12 | DIO_PAD_CFG),
706};
707
Tim Harvey552c3582014-03-06 07:46:30 -0800708/*
709 * each baseboard has 4 user configurable Digital IO lines which can
710 * be pinmuxed as a GPIO or in some cases a PWM
711 */
712struct dio_cfg {
Tim Harvey02fb5922014-06-02 16:13:26 -0700713 iomux_v3_cfg_t gpio_padmux[2];
Tim Harvey552c3582014-03-06 07:46:30 -0800714 unsigned gpio_param;
Tim Harvey02fb5922014-06-02 16:13:26 -0700715 iomux_v3_cfg_t pwm_padmux[2];
Tim Harvey552c3582014-03-06 07:46:30 -0800716 unsigned pwm_param;
717};
718
719struct ventana {
720 /* pinmux */
721 iomux_v3_cfg_t const *gpio_pads;
722 int num_pads;
723 /* DIO pinmux/val */
724 struct dio_cfg dio_cfg[4];
725 /* various gpios (0 if non-existent) */
726 int leds[3];
727 int pcie_rst;
728 int mezz_pwren;
729 int mezz_irq;
730 int rs485en;
731 int gps_shdn;
732 int vidin_en;
733 int dioi2c_en;
734 int pcie_sson;
735 int usb_sel;
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700736 int wdis;
Tim Harvey552c3582014-03-06 07:46:30 -0800737};
738
739struct ventana gpio_cfg[] = {
740 /* GW5400proto */
741 {
742 .gpio_pads = gw54xx_gpio_pads,
Tim Harvey02fb5922014-06-02 16:13:26 -0700743 .num_pads = ARRAY_SIZE(gw54xx_gpio_pads)/2,
Tim Harvey552c3582014-03-06 07:46:30 -0800744 .dio_cfg = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700745 {
746 { IOMUX_PADS(PAD_GPIO_9__GPIO1_IO09) },
747 IMX_GPIO_NR(1, 9),
748 { IOMUX_PADS(PAD_GPIO_9__PWM1_OUT) },
749 1
750 },
751 {
752 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
753 IMX_GPIO_NR(1, 19),
754 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
755 2
756 },
757 {
758 { IOMUX_PADS(PAD_SD4_DAT1__GPIO2_IO09) },
759 IMX_GPIO_NR(2, 9),
760 { IOMUX_PADS(PAD_SD4_DAT1__PWM3_OUT) },
761 3
762 },
763 {
764 { IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10) },
765 IMX_GPIO_NR(2, 10),
766 { IOMUX_PADS(PAD_SD4_DAT2__PWM4_OUT) },
767 4
768 },
Tim Harvey552c3582014-03-06 07:46:30 -0800769 },
770 .leds = {
771 IMX_GPIO_NR(4, 6),
772 IMX_GPIO_NR(4, 10),
773 IMX_GPIO_NR(4, 15),
774 },
775 .pcie_rst = IMX_GPIO_NR(1, 29),
776 .mezz_pwren = IMX_GPIO_NR(4, 7),
777 .mezz_irq = IMX_GPIO_NR(4, 9),
778 .rs485en = IMX_GPIO_NR(3, 24),
779 .dioi2c_en = IMX_GPIO_NR(4, 5),
780 .pcie_sson = IMX_GPIO_NR(1, 20),
781 },
782
783 /* GW51xx */
784 {
785 .gpio_pads = gw51xx_gpio_pads,
Tim Harvey02fb5922014-06-02 16:13:26 -0700786 .num_pads = ARRAY_SIZE(gw51xx_gpio_pads)/2,
Tim Harvey552c3582014-03-06 07:46:30 -0800787 .dio_cfg = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700788 {
789 { IOMUX_PADS(PAD_SD1_DAT0__GPIO1_IO16) },
790 IMX_GPIO_NR(1, 16),
791 { 0, 0 },
792 0
793 },
794 {
795 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
796 IMX_GPIO_NR(1, 19),
797 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
798 2
799 },
800 {
801 { IOMUX_PADS(PAD_SD1_DAT1__GPIO1_IO17) },
802 IMX_GPIO_NR(1, 17),
803 { IOMUX_PADS(PAD_SD1_DAT1__PWM3_OUT) },
804 3
805 },
806 {
807 { IOMUX_PADS(PAD_SD1_CMD__GPIO1_IO18) },
808 IMX_GPIO_NR(1, 18),
809 { IOMUX_PADS(PAD_SD1_CMD__PWM4_OUT) },
810 4
811 },
Tim Harvey552c3582014-03-06 07:46:30 -0800812 },
813 .leds = {
814 IMX_GPIO_NR(4, 6),
815 IMX_GPIO_NR(4, 10),
816 },
817 .pcie_rst = IMX_GPIO_NR(1, 0),
818 .mezz_pwren = IMX_GPIO_NR(2, 19),
819 .mezz_irq = IMX_GPIO_NR(2, 18),
820 .gps_shdn = IMX_GPIO_NR(1, 2),
821 .vidin_en = IMX_GPIO_NR(5, 20),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700822 .wdis = IMX_GPIO_NR(7, 12),
Tim Harvey552c3582014-03-06 07:46:30 -0800823 },
824
825 /* GW52xx */
826 {
827 .gpio_pads = gw52xx_gpio_pads,
Tim Harvey02fb5922014-06-02 16:13:26 -0700828 .num_pads = ARRAY_SIZE(gw52xx_gpio_pads)/2,
Tim Harvey552c3582014-03-06 07:46:30 -0800829 .dio_cfg = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700830 {
831 { IOMUX_PADS(PAD_SD1_DAT0__GPIO1_IO16) },
832 IMX_GPIO_NR(1, 16),
833 { 0, 0 },
834 0
835 },
836 {
837 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
838 IMX_GPIO_NR(1, 19),
839 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
840 2
841 },
842 {
843 { IOMUX_PADS(PAD_SD1_DAT1__GPIO1_IO17) },
844 IMX_GPIO_NR(1, 17),
845 { IOMUX_PADS(PAD_SD1_DAT1__PWM3_OUT) },
846 3
847 },
848 {
849 { IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20) },
850 IMX_GPIO_NR(1, 20),
851 { 0, 0 },
852 0
853 },
Tim Harvey552c3582014-03-06 07:46:30 -0800854 },
855 .leds = {
856 IMX_GPIO_NR(4, 6),
857 IMX_GPIO_NR(4, 7),
858 IMX_GPIO_NR(4, 15),
859 },
860 .pcie_rst = IMX_GPIO_NR(1, 29),
861 .mezz_pwren = IMX_GPIO_NR(2, 19),
862 .mezz_irq = IMX_GPIO_NR(2, 18),
863 .gps_shdn = IMX_GPIO_NR(1, 27),
864 .vidin_en = IMX_GPIO_NR(3, 31),
865 .usb_sel = IMX_GPIO_NR(1, 2),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700866 .wdis = IMX_GPIO_NR(7, 12),
Tim Harvey552c3582014-03-06 07:46:30 -0800867 },
868
869 /* GW53xx */
870 {
871 .gpio_pads = gw53xx_gpio_pads,
Tim Harvey02fb5922014-06-02 16:13:26 -0700872 .num_pads = ARRAY_SIZE(gw53xx_gpio_pads)/2,
Tim Harvey552c3582014-03-06 07:46:30 -0800873 .dio_cfg = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700874 {
875 { IOMUX_PADS(PAD_SD1_DAT0__GPIO1_IO16) },
876 IMX_GPIO_NR(1, 16),
877 { 0, 0 },
878 0
879 },
880 {
881 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
882 IMX_GPIO_NR(1, 19),
883 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
884 2
885 },
886 {
887 { IOMUX_PADS(PAD_SD1_DAT1__GPIO1_IO17) },
888 IMX_GPIO_NR(1, 17),
889 { IOMUX_PADS(PAD_SD1_DAT1__PWM3_OUT) },
890 3
891 },
892 {
893 {IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20) },
894 IMX_GPIO_NR(1, 20),
895 { 0, 0 },
896 0
897 },
Tim Harvey552c3582014-03-06 07:46:30 -0800898 },
899 .leds = {
900 IMX_GPIO_NR(4, 6),
901 IMX_GPIO_NR(4, 7),
902 IMX_GPIO_NR(4, 15),
903 },
904 .pcie_rst = IMX_GPIO_NR(1, 29),
905 .mezz_pwren = IMX_GPIO_NR(2, 19),
906 .mezz_irq = IMX_GPIO_NR(2, 18),
907 .gps_shdn = IMX_GPIO_NR(1, 27),
908 .vidin_en = IMX_GPIO_NR(3, 31),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700909 .wdis = IMX_GPIO_NR(7, 12),
Tim Harvey552c3582014-03-06 07:46:30 -0800910 },
911
912 /* GW54xx */
913 {
914 .gpio_pads = gw54xx_gpio_pads,
Tim Harvey02fb5922014-06-02 16:13:26 -0700915 .num_pads = ARRAY_SIZE(gw54xx_gpio_pads)/2,
Tim Harvey552c3582014-03-06 07:46:30 -0800916 .dio_cfg = {
Tim Harvey02fb5922014-06-02 16:13:26 -0700917 {
918 { IOMUX_PADS(PAD_GPIO_9__GPIO1_IO09) },
919 IMX_GPIO_NR(1, 9),
920 { IOMUX_PADS(PAD_GPIO_9__PWM1_OUT) },
921 1
922 },
923 {
924 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
925 IMX_GPIO_NR(1, 19),
926 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
927 2
928 },
929 {
930 { IOMUX_PADS(PAD_SD4_DAT1__GPIO2_IO09) },
931 IMX_GPIO_NR(2, 9),
932 { IOMUX_PADS(PAD_SD4_DAT1__PWM3_OUT) },
933 3
934 },
935 {
936 { IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10) },
937 IMX_GPIO_NR(2, 10),
938 { IOMUX_PADS(PAD_SD4_DAT2__PWM4_OUT) },
939 4
940 },
Tim Harvey552c3582014-03-06 07:46:30 -0800941 },
942 .leds = {
943 IMX_GPIO_NR(4, 6),
944 IMX_GPIO_NR(4, 7),
945 IMX_GPIO_NR(4, 15),
946 },
947 .pcie_rst = IMX_GPIO_NR(1, 29),
948 .mezz_pwren = IMX_GPIO_NR(2, 19),
949 .mezz_irq = IMX_GPIO_NR(2, 18),
950 .rs485en = IMX_GPIO_NR(7, 1),
951 .vidin_en = IMX_GPIO_NR(3, 31),
952 .dioi2c_en = IMX_GPIO_NR(4, 5),
953 .pcie_sson = IMX_GPIO_NR(1, 20),
Tim Harveyb6eb1d52014-08-07 22:35:50 -0700954 .wdis = IMX_GPIO_NR(5, 17),
Tim Harvey552c3582014-03-06 07:46:30 -0800955 },
Tim Harvey50581832014-08-20 23:35:14 -0700956
957 /* GW552x */
958 {
959 .gpio_pads = gw552x_gpio_pads,
960 .num_pads = ARRAY_SIZE(gw552x_gpio_pads)/2,
961 .dio_cfg = {
962 {
963 { IOMUX_PADS(PAD_SD1_DAT0__GPIO1_IO16) },
964 IMX_GPIO_NR(1, 16),
965 { 0, 0 },
966 0
967 },
968 {
969 { IOMUX_PADS(PAD_SD1_DAT2__GPIO1_IO19) },
970 IMX_GPIO_NR(1, 19),
971 { IOMUX_PADS(PAD_SD1_DAT2__PWM2_OUT) },
972 2
973 },
974 {
975 { IOMUX_PADS(PAD_SD1_DAT1__GPIO1_IO17) },
976 IMX_GPIO_NR(1, 17),
977 { IOMUX_PADS(PAD_SD1_DAT1__PWM3_OUT) },
978 3
979 },
980 {
981 { IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20) },
982 IMX_GPIO_NR(2, 10),
983 { 0, 0 },
984 0
985 },
986 },
987 .leds = {
988 IMX_GPIO_NR(4, 6),
989 IMX_GPIO_NR(4, 7),
990 IMX_GPIO_NR(4, 15),
991 },
992 .pcie_rst = IMX_GPIO_NR(1, 29),
993 },
Tim Harvey552c3582014-03-06 07:46:30 -0800994};
995
Tim Harvey0dff16f2014-05-05 08:22:25 -0700996/* setup board specific PMIC */
997int power_init_board(void)
998{
999 struct pmic *p;
1000 u32 reg;
1001
1002 /* configure PFUZE100 PMIC */
1003 if (board_type == GW54xx || board_type == GW54proto) {
Tim Harvey0da2c522014-08-07 22:35:45 -07001004 power_pfuze100_init(CONFIG_I2C_PMIC);
Fabio Estevamb96df4f2014-08-01 08:50:03 -03001005 p = pmic_get("PFUZE100");
Tim Harvey0dff16f2014-05-05 08:22:25 -07001006 if (p && !pmic_probe(p)) {
1007 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
1008 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
1009
1010 /* Set VGEN1 to 1.5V and enable */
1011 pmic_reg_read(p, PFUZE100_VGEN1VOL, &reg);
1012 reg &= ~(LDO_VOL_MASK);
1013 reg |= (LDOA_1_50V | LDO_EN);
1014 pmic_reg_write(p, PFUZE100_VGEN1VOL, reg);
1015
1016 /* Set SWBST to 5.0V and enable */
1017 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
1018 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
1019 reg |= (SWBST_5_00V | SWBST_MODE_AUTO);
1020 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
1021 }
1022 }
1023
1024 /* configure LTC3676 PMIC */
1025 else {
Tim Harvey0da2c522014-08-07 22:35:45 -07001026 power_ltc3676_init(CONFIG_I2C_PMIC);
Tim Harvey0dff16f2014-05-05 08:22:25 -07001027 p = pmic_get("LTC3676_PMIC");
1028 if (p && !pmic_probe(p)) {
1029 puts("PMIC: LTC3676\n");
1030 /* set board-specific scalar to 1225mV for IMX6Q@1GHz */
1031 if (is_cpu_type(MXC_CPU_MX6Q)) {
1032 /* mask PGOOD during SW1 transition */
1033 reg = 0x1d | LTC3676_PGOOD_MASK;
1034 pmic_reg_write(p, LTC3676_DVB1B, reg);
1035 /* set SW1 (VDD_SOC) to 1259mV */
1036 reg = 0x1d;
1037 pmic_reg_write(p, LTC3676_DVB1A, reg);
1038
1039 /* mask PGOOD during SW3 transition */
1040 reg = 0x1d | LTC3676_PGOOD_MASK;
1041 pmic_reg_write(p, LTC3676_DVB3B, reg);
1042 /*set SW3 (VDD_ARM) to 1259mV */
1043 reg = 0x1d;
1044 pmic_reg_write(p, LTC3676_DVB3A, reg);
1045 }
1046 }
1047 }
1048
1049 return 0;
1050}
1051
Tim Harvey552c3582014-03-06 07:46:30 -08001052/* setup GPIO pinmux and default configuration per baseboard */
1053static void setup_board_gpio(int board)
1054{
1055 struct ventana_board_info *info = &ventana_info;
1056 const char *s;
1057 char arg[10];
1058 size_t len;
1059 int i;
1060 int quiet = simple_strtol(getenv("quiet"), NULL, 10);
1061
1062 if (board >= GW_UNKNOWN)
1063 return;
1064
1065 /* RS232_EN# */
1066 gpio_direction_output(GP_RS232_EN, (hwconfig("rs232")) ? 0 : 1);
1067
1068 /* MSATA Enable */
1069 if (is_cpu_type(MXC_CPU_MX6Q) &&
1070 test_bit(EECONFIG_SATA, info->config)) {
1071 gpio_direction_output(GP_MSATA_SEL,
1072 (hwconfig("msata")) ? 1 : 0);
1073 } else {
1074 gpio_direction_output(GP_MSATA_SEL, 0);
1075 }
1076
Tim Harvey6b0efae2014-08-07 22:35:51 -07001077#if !defined(CONFIG_CMD_PCI)
1078 /* assert PCI_RST# (released by OS when clock is valid) */
Tim Harvey552c3582014-03-06 07:46:30 -08001079 gpio_direction_output(gpio_cfg[board].pcie_rst, 0);
Tim Harvey6b0efae2014-08-07 22:35:51 -07001080#endif
Tim Harvey552c3582014-03-06 07:46:30 -08001081
1082 /* turn off (active-high) user LED's */
Thierry Reding7fcdf282014-08-22 09:46:35 +02001083 for (i = 0; i < ARRAY_SIZE(gpio_cfg[board].leds); i++) {
Tim Harvey552c3582014-03-06 07:46:30 -08001084 if (gpio_cfg[board].leds[i])
1085 gpio_direction_output(gpio_cfg[board].leds[i], 1);
1086 }
1087
1088 /* Expansion Mezzanine IO */
Tim Harvey50581832014-08-20 23:35:14 -07001089 if (gpio_cfg[board].mezz_pwren)
1090 gpio_direction_output(gpio_cfg[board].mezz_pwren, 0);
1091 if (gpio_cfg[board].mezz_irq)
1092 gpio_direction_input(gpio_cfg[board].mezz_irq);
Tim Harvey552c3582014-03-06 07:46:30 -08001093
1094 /* RS485 Transmit Enable */
1095 if (gpio_cfg[board].rs485en)
1096 gpio_direction_output(gpio_cfg[board].rs485en, 0);
1097
1098 /* GPS_SHDN */
1099 if (gpio_cfg[board].gps_shdn)
1100 gpio_direction_output(gpio_cfg[board].gps_shdn, 1);
1101
1102 /* Analog video codec power enable */
1103 if (gpio_cfg[board].vidin_en)
1104 gpio_direction_output(gpio_cfg[board].vidin_en, 1);
1105
1106 /* DIOI2C_DIS# */
1107 if (gpio_cfg[board].dioi2c_en)
1108 gpio_direction_output(gpio_cfg[board].dioi2c_en, 0);
1109
1110 /* PCICK_SSON: disable spread-spectrum clock */
1111 if (gpio_cfg[board].pcie_sson)
1112 gpio_direction_output(gpio_cfg[board].pcie_sson, 0);
1113
1114 /* USBOTG Select (PCISKT or FrontPanel) */
1115 if (gpio_cfg[board].usb_sel)
1116 gpio_direction_output(gpio_cfg[board].usb_sel, 0);
1117
Tim Harveyb6eb1d52014-08-07 22:35:50 -07001118 /* PCISKT_WDIS# (Wireless disable GPIO to miniPCIe sockets) */
1119 if (gpio_cfg[board].wdis)
1120 gpio_direction_output(gpio_cfg[board].wdis, 1);
1121
Tim Harvey552c3582014-03-06 07:46:30 -08001122 /*
1123 * Configure DIO pinmux/padctl registers
1124 * see IMX6DQRM/IMX6SDLRM IOMUXC_SW_PAD_CTL_PAD_* register definitions
1125 */
1126 for (i = 0; i < 4; i++) {
1127 struct dio_cfg *cfg = &gpio_cfg[board].dio_cfg[i];
Tim Harvey26993362014-08-07 22:35:49 -07001128 iomux_v3_cfg_t ctrl = DIO_PAD_CFG;
Tim Harvey02fb5922014-06-02 16:13:26 -07001129 unsigned cputype = is_cpu_type(MXC_CPU_MX6Q) ? 0 : 1;
Tim Harvey552c3582014-03-06 07:46:30 -08001130
1131 sprintf(arg, "dio%d", i);
1132 if (!hwconfig(arg))
1133 continue;
1134 s = hwconfig_subarg(arg, "padctrl", &len);
Tim Harvey26993362014-08-07 22:35:49 -07001135 if (s) {
1136 ctrl = MUX_PAD_CTRL(simple_strtoul(s, NULL, 16)
1137 & 0x1ffff) | MUX_MODE_SION;
1138 }
Tim Harvey552c3582014-03-06 07:46:30 -08001139 if (hwconfig_subarg_cmp(arg, "mode", "gpio")) {
1140 if (!quiet) {
1141 printf("DIO%d: GPIO%d_IO%02d (gpio-%d)\n", i,
1142 (cfg->gpio_param/32)+1,
1143 cfg->gpio_param%32,
1144 cfg->gpio_param);
1145 }
Tim Harvey02fb5922014-06-02 16:13:26 -07001146 imx_iomux_v3_setup_pad(cfg->gpio_padmux[cputype] |
Tim Harvey26993362014-08-07 22:35:49 -07001147 ctrl);
Tim Harvey552c3582014-03-06 07:46:30 -08001148 gpio_direction_input(cfg->gpio_param);
1149 } else if (hwconfig_subarg_cmp("dio2", "mode", "pwm") &&
1150 cfg->pwm_padmux) {
1151 if (!quiet)
1152 printf("DIO%d: pwm%d\n", i, cfg->pwm_param);
Tim Harvey02fb5922014-06-02 16:13:26 -07001153 imx_iomux_v3_setup_pad(cfg->pwm_padmux[cputype] |
Tim Harvey552c3582014-03-06 07:46:30 -08001154 MUX_PAD_CTRL(ctrl));
1155 }
1156 }
1157
1158 if (!quiet) {
1159 if (is_cpu_type(MXC_CPU_MX6Q) &&
1160 (test_bit(EECONFIG_SATA, info->config))) {
1161 printf("MSATA: %s\n", (hwconfig("msata") ?
1162 "enabled" : "disabled"));
1163 }
1164 printf("RS232: %s\n", (hwconfig("rs232")) ?
1165 "enabled" : "disabled");
1166 }
1167}
1168
1169#if defined(CONFIG_CMD_PCI)
1170int imx6_pcie_toggle_reset(void)
1171{
1172 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -07001173 uint pin = gpio_cfg[board_type].pcie_rst;
1174 gpio_direction_output(pin, 0);
Tim Harvey552c3582014-03-06 07:46:30 -08001175 mdelay(50);
Tim Harvey02fb5922014-06-02 16:13:26 -07001176 gpio_direction_output(pin, 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001177 }
1178 return 0;
1179}
Tim Harvey33791d52014-08-07 22:49:57 -07001180
1181/*
1182 * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
1183 * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
1184 * properly and assert reset for 100ms.
1185 */
1186void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
1187 unsigned short vendor, unsigned short device,
1188 unsigned short class)
1189{
1190 u32 dw;
1191
1192 debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
1193 PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
1194 if (vendor == PCI_VENDOR_ID_PLX &&
1195 (device & 0xfff0) == 0x8600 &&
1196 PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
1197 debug("configuring PLX 860X downstream PERST#\n");
1198 pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
1199 dw |= 0xaaa8; /* GPIO1-7 outputs */
1200 pci_hose_write_config_dword(hose, dev, 0x62c, dw);
1201
1202 pci_hose_read_config_dword(hose, dev, 0x644, &dw);
1203 dw |= 0xfe; /* GPIO1-7 output high */
1204 pci_hose_write_config_dword(hose, dev, 0x644, dw);
1205
1206 mdelay(100);
1207 }
1208}
Tim Harvey552c3582014-03-06 07:46:30 -08001209#endif /* CONFIG_CMD_PCI */
1210
1211#ifdef CONFIG_SERIAL_TAG
1212/*
1213 * called when setting up ATAGS before booting kernel
1214 * populate serialnum from the following (in order of priority):
1215 * serial# env var
1216 * eeprom
1217 */
1218void get_board_serial(struct tag_serialnr *serialnr)
1219{
1220 char *serial = getenv("serial#");
1221
1222 if (serial) {
1223 serialnr->high = 0;
1224 serialnr->low = simple_strtoul(serial, NULL, 10);
1225 } else if (ventana_info.model[0]) {
1226 serialnr->high = 0;
1227 serialnr->low = ventana_info.serial;
1228 } else {
1229 serialnr->high = 0;
1230 serialnr->low = 0;
1231 }
1232}
1233#endif
1234
1235/*
1236 * Board Support
1237 */
1238
Tim Harveybfa2dae2014-06-02 16:13:27 -07001239/* called from SPL board_init_f() */
Tim Harvey552c3582014-03-06 07:46:30 -08001240int board_early_init_f(void)
1241{
1242 setup_iomux_uart();
1243 gpio_direction_output(GP_USB_OTG_PWR, 0); /* OTG power off */
1244
Tim Harveyfb64cc72014-04-25 15:39:07 -07001245#if defined(CONFIG_VIDEO_IPUV3)
1246 setup_display();
1247#endif
Tim Harvey552c3582014-03-06 07:46:30 -08001248 return 0;
1249}
1250
1251int dram_init(void)
1252{
Tim Harveybfa2dae2014-06-02 16:13:27 -07001253 gd->ram_size = imx_ddr_size();
Tim Harvey552c3582014-03-06 07:46:30 -08001254 return 0;
1255}
1256
1257int board_init(void)
1258{
Fabio Estevamceb74c42014-07-09 17:59:54 -03001259 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Tim Harvey552c3582014-03-06 07:46:30 -08001260
1261 clrsetbits_le32(&iomuxc_regs->gpr[1],
1262 IOMUXC_GPR1_OTG_ID_MASK,
1263 IOMUXC_GPR1_OTG_ID_GPIO1);
1264
1265 /* address of linux boot parameters */
1266 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
1267
1268#ifdef CONFIG_CMD_NAND
1269 setup_gpmi_nand();
1270#endif
1271#ifdef CONFIG_MXC_SPI
1272 setup_spi();
1273#endif
Tim Harvey02fb5922014-06-02 16:13:26 -07001274 if (is_cpu_type(MXC_CPU_MX6Q)) {
1275 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info0);
1276 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info1);
1277 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info2);
1278 } else {
1279 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info0);
1280 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info1);
1281 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info2);
1282 }
Tim Harvey552c3582014-03-06 07:46:30 -08001283
1284#ifdef CONFIG_CMD_SATA
1285 setup_sata();
1286#endif
1287 /* read Gateworks EEPROM into global struct (used later) */
Tim Harvey0da2c522014-08-07 22:35:45 -07001288 board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
Tim Harvey552c3582014-03-06 07:46:30 -08001289
1290 /* board-specifc GPIO iomux */
Tim Harvey02fb5922014-06-02 16:13:26 -07001291 SETUP_IOMUX_PADS(gw_gpio_pads);
Tim Harvey552c3582014-03-06 07:46:30 -08001292 if (board_type < GW_UNKNOWN) {
Tim Harvey02fb5922014-06-02 16:13:26 -07001293 iomux_v3_cfg_t const *p = gpio_cfg[board_type].gpio_pads;
1294 int count = gpio_cfg[board_type].num_pads;
1295
1296 imx_iomux_v3_setup_multiple_pads(p, count);
Tim Harvey552c3582014-03-06 07:46:30 -08001297 }
1298
1299 return 0;
1300}
1301
1302#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
1303/*
1304 * called during late init (after relocation and after board_init())
1305 * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
1306 * EEPROM read.
1307 */
1308int checkboard(void)
1309{
1310 struct ventana_board_info *info = &ventana_info;
1311 unsigned char buf[4];
1312 const char *p;
1313 int quiet; /* Quiet or minimal output mode */
1314
1315 quiet = 0;
1316 p = getenv("quiet");
1317 if (p)
1318 quiet = simple_strtol(p, NULL, 10);
1319 else
1320 setenv("quiet", "0");
1321
1322 puts("\nGateworks Corporation Copyright 2014\n");
1323 if (info->model[0]) {
1324 printf("Model: %s\n", info->model);
1325 printf("MFGDate: %02x-%02x-%02x%02x\n",
1326 info->mfgdate[0], info->mfgdate[1],
1327 info->mfgdate[2], info->mfgdate[3]);
1328 printf("Serial:%d\n", info->serial);
1329 } else {
1330 puts("Invalid EEPROM - board will not function fully\n");
1331 }
1332 if (quiet)
1333 return 0;
1334
1335 /* Display GSC firmware revision/CRC/status */
Tim Harvey0da2c522014-08-07 22:35:45 -07001336 i2c_set_bus_num(CONFIG_I2C_GSC);
Tim Harvey552c3582014-03-06 07:46:30 -08001337 if (!gsc_i2c_read(GSC_SC_ADDR, GSC_SC_FWVER, 1, buf, 1)) {
1338 printf("GSC: v%d", buf[0]);
1339 if (!gsc_i2c_read(GSC_SC_ADDR, GSC_SC_STATUS, 1, buf, 4)) {
1340 printf(" 0x%04x", buf[2] | buf[3]<<8); /* CRC */
1341 printf(" 0x%02x", buf[0]); /* irq status */
1342 }
1343 puts("\n");
1344 }
1345 /* Display RTC */
1346 if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
1347 printf("RTC: %d\n",
1348 buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
1349 }
1350
1351 return 0;
1352}
1353#endif
1354
1355#ifdef CONFIG_CMD_BMODE
1356/*
1357 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
1358 * see Table 8-11 and Table 5-9
1359 * BOOT_CFG1[7] = 1 (boot from NAND)
1360 * BOOT_CFG1[5] = 0 - raw NAND
1361 * BOOT_CFG1[4] = 0 - default pad settings
1362 * BOOT_CFG1[3:2] = 00 - devices = 1
1363 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
1364 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
1365 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
1366 * BOOT_CFG2[0] = 0 - Reset time 12ms
1367 */
1368static const struct boot_mode board_boot_modes[] = {
1369 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
1370 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
1371 { NULL, 0 },
1372};
1373#endif
1374
1375/* late init */
1376int misc_init_r(void)
1377{
1378 struct ventana_board_info *info = &ventana_info;
1379 unsigned char reg;
1380
1381 /* set env vars based on EEPROM data */
1382 if (ventana_info.model[0]) {
1383 char str[16], fdt[36];
1384 char *p;
1385 const char *cputype = "";
1386 int i;
1387
1388 /*
1389 * FDT name will be prefixed with CPU type. Three versions
1390 * will be created each increasingly generic and bootloader
1391 * env scripts will try loading each from most specific to
1392 * least.
1393 */
Tim Harveybfa2dae2014-06-02 16:13:27 -07001394 if (is_cpu_type(MXC_CPU_MX6Q) ||
1395 is_cpu_type(MXC_CPU_MX6D))
Tim Harvey552c3582014-03-06 07:46:30 -08001396 cputype = "imx6q";
Tim Harveybfa2dae2014-06-02 16:13:27 -07001397 else if (is_cpu_type(MXC_CPU_MX6DL) ||
1398 is_cpu_type(MXC_CPU_MX6SOLO))
Tim Harvey552c3582014-03-06 07:46:30 -08001399 cputype = "imx6dl";
Tim Harveybf942582014-08-07 22:35:42 -07001400 setenv("soctype", cputype);
Tim Harvey06d87432014-08-07 22:35:41 -07001401 if (8 << (ventana_info.nand_flash_size-1) >= 2048)
1402 setenv("flash_layout", "large");
1403 else
1404 setenv("flash_layout", "normal");
Tim Harvey552c3582014-03-06 07:46:30 -08001405 memset(str, 0, sizeof(str));
1406 for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
1407 str[i] = tolower(info->model[i]);
1408 if (!getenv("model"))
1409 setenv("model", str);
1410 if (!getenv("fdt_file")) {
1411 sprintf(fdt, "%s-%s.dtb", cputype, str);
1412 setenv("fdt_file", fdt);
1413 }
1414 p = strchr(str, '-');
1415 if (p) {
1416 *p++ = 0;
1417
1418 setenv("model_base", str);
1419 if (!getenv("fdt_file1")) {
1420 sprintf(fdt, "%s-%s.dtb", cputype, str);
1421 setenv("fdt_file1", fdt);
1422 }
Tim Harvey50581832014-08-20 23:35:14 -07001423 if (board_type != GW552x)
1424 str[4] = 'x';
Tim Harvey552c3582014-03-06 07:46:30 -08001425 str[5] = 'x';
1426 str[6] = 0;
1427 if (!getenv("fdt_file2")) {
1428 sprintf(fdt, "%s-%s.dtb", cputype, str);
1429 setenv("fdt_file2", fdt);
1430 }
1431 }
1432
1433 /* initialize env from EEPROM */
1434 if (test_bit(EECONFIG_ETH0, info->config) &&
1435 !getenv("ethaddr")) {
1436 eth_setenv_enetaddr("ethaddr", info->mac0);
1437 }
1438 if (test_bit(EECONFIG_ETH1, info->config) &&
1439 !getenv("eth1addr")) {
1440 eth_setenv_enetaddr("eth1addr", info->mac1);
1441 }
1442
1443 /* board serial-number */
1444 sprintf(str, "%6d", info->serial);
1445 setenv("serial#", str);
1446 }
1447
Tim Harvey552c3582014-03-06 07:46:30 -08001448
1449 /* setup baseboard specific GPIO pinmux and config */
1450 setup_board_gpio(board_type);
1451
1452#ifdef CONFIG_CMD_BMODE
1453 add_board_boot_modes(board_boot_modes);
1454#endif
1455
1456 /*
1457 * The Gateworks System Controller implements a boot
1458 * watchdog (always enabled) as a workaround for IMX6 boot related
1459 * errata such as:
Tim Harvey2be66142014-08-20 23:30:36 -07001460 * ERR005768 - no fix scheduled
1461 * ERR006282 - fixed in silicon r1.2
Tim Harvey552c3582014-03-06 07:46:30 -08001462 * ERR007117 - fixed in silicon r1.3
1463 * ERR007220 - fixed in silicon r1.3
Tim Harvey2be66142014-08-20 23:30:36 -07001464 * ERR007926 - no fix scheduled
Tim Harvey552c3582014-03-06 07:46:30 -08001465 * see http://cache.freescale.com/files/32bit/doc/errata/IMX6DQCE.pdf
1466 *
1467 * Disable the boot watchdog and display/clear the timeout flag if set
1468 */
Tim Harvey0da2c522014-08-07 22:35:45 -07001469 i2c_set_bus_num(CONFIG_I2C_GSC);
Tim Harvey552c3582014-03-06 07:46:30 -08001470 if (!gsc_i2c_read(GSC_SC_ADDR, GSC_SC_CTRL1, 1, &reg, 1)) {
1471 reg |= (1 << GSC_SC_CTRL1_WDDIS);
1472 if (gsc_i2c_write(GSC_SC_ADDR, GSC_SC_CTRL1, 1, &reg, 1))
1473 puts("Error: could not disable GSC Watchdog\n");
1474 } else {
1475 puts("Error: could not disable GSC Watchdog\n");
1476 }
1477 if (!gsc_i2c_read(GSC_SC_ADDR, GSC_SC_STATUS, 1, &reg, 1)) {
1478 if (reg & (1 << GSC_SC_IRQ_WATCHDOG)) { /* watchdog timeout */
Tim Harveyfc3883a2014-08-07 22:35:47 -07001479 puts("GSC boot watchdog timeout detected\n");
Tim Harvey552c3582014-03-06 07:46:30 -08001480 reg &= ~(1 << GSC_SC_IRQ_WATCHDOG); /* clear flag */
1481 gsc_i2c_write(GSC_SC_ADDR, GSC_SC_STATUS, 1, &reg, 1);
1482 }
1483 }
1484
1485 return 0;
1486}
1487
1488#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1489
Tim Harvey552c3582014-03-06 07:46:30 -08001490/*
1491 * called prior to booting kernel or by 'fdt boardsetup' command
1492 *
1493 * unless 'fdt_noauto' env var is set we will update the following in the DTB:
1494 * - mtd partitions based on mtdparts/mtdids env
1495 * - system-serial (board serial num from EEPROM)
1496 * - board (full model from EEPROM)
1497 * - peripherals removed from DTB if not loaded on board (per EEPROM config)
1498 */
Simon Glass2aec3cc2014-10-23 18:58:47 -06001499int ft_board_setup(void *blob, bd_t *bd)
Tim Harvey552c3582014-03-06 07:46:30 -08001500{
Tim Harvey552c3582014-03-06 07:46:30 -08001501 struct ventana_board_info *info = &ventana_info;
Tim Harvey0da2c522014-08-07 22:35:45 -07001502 struct ventana_eeprom_config *cfg;
Tim Harvey552c3582014-03-06 07:46:30 -08001503 struct node_info nodes[] = {
1504 { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
1505 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
1506 };
1507 const char *model = getenv("model");
1508
1509 if (getenv("fdt_noauto")) {
1510 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001511 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001512 }
1513
1514 /* Update partition nodes using info from mtdparts env var */
1515 puts(" Updating MTD partitions...\n");
1516 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
1517
1518 if (!model) {
1519 puts("invalid board info: Leaving FDT fully enabled\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001520 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001521 }
1522 printf(" Adjusting FDT per EEPROM for %s...\n", model);
1523
1524 /* board serial number */
1525 fdt_setprop(blob, 0, "system-serial", getenv("serial#"),
Tim Harveyae35ded2014-04-25 09:18:33 -07001526 strlen(getenv("serial#")) + 1);
Tim Harvey552c3582014-03-06 07:46:30 -08001527
1528 /* board (model contains model from device-tree) */
1529 fdt_setprop(blob, 0, "board", info->model,
1530 strlen((const char *)info->model) + 1);
1531
1532 /*
1533 * Peripheral Config:
1534 * remove nodes by alias path if EEPROM config tells us the
1535 * peripheral is not loaded on the board.
1536 */
Tim Harvey0da2c522014-08-07 22:35:45 -07001537 if (getenv("fdt_noconfig")) {
1538 puts(" Skiping periperhal config (fdt_noconfig defined)\n");
Simon Glass2aec3cc2014-10-23 18:58:47 -06001539 return 0;
Tim Harvey0da2c522014-08-07 22:35:45 -07001540 }
1541 cfg = econfig;
1542 while (cfg->name) {
1543 if (!test_bit(cfg->bit, info->config)) {
1544 fdt_del_node_and_alias(blob, cfg->dtalias ?
1545 cfg->dtalias : cfg->name);
1546 }
1547 cfg++;
Tim Harvey552c3582014-03-06 07:46:30 -08001548 }
Simon Glass2aec3cc2014-10-23 18:58:47 -06001549
1550 return 0;
Tim Harvey552c3582014-03-06 07:46:30 -08001551}
1552#endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */
1553