blob: a89a15ca746a36b7631f4a51097c8ba90a16c347 [file] [log] [blame]
Eric Nelsond67b0d92013-03-11 08:44:53 +00001/*
2 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
3 * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
4 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
Eric Nelsond67b0d92013-03-11 08:44:53 +00006 */
7
8#include <common.h>
9#include <asm/io.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/sys_proto.h>
14#include <malloc.h>
15#include <asm/arch/mx6-pins.h>
16#include <asm/errno.h>
17#include <asm/gpio.h>
18#include <asm/imx-common/iomux-v3.h>
19#include <asm/imx-common/mxc_i2c.h>
Giuseppe Pagano164d9842013-11-28 12:32:48 +010020#include <asm/imx-common/sata.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000021#include <asm/imx-common/boot_mode.h>
Eric Benarda47e4492014-04-04 19:05:53 +020022#include <asm/imx-common/video.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000023#include <mmc.h>
24#include <fsl_esdhc.h>
25#include <micrel.h>
26#include <miiphy.h>
27#include <netdev.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000028#include <asm/arch/crm_regs.h>
29#include <asm/arch/mxc_hdmi.h>
30#include <i2c.h>
Eric Nelson9fc42522014-10-02 12:16:27 -070031#include <input.h>
32#include <netdev.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000033
34DECLARE_GLOBAL_DATA_PTR;
Troy Kisky08ce0742013-09-25 18:41:17 -070035#define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
Eric Nelsond67b0d92013-03-11 08:44:53 +000036
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000037#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
38 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
39 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000040
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000041#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
42 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
43 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000044
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000045#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
46 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000047
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000048#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000049 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
50
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000051#define BUTTON_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
52 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000053
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000054#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
55 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000056 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
57
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000058#define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \
59 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000060 PAD_CTL_SRE_SLOW)
61
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000062#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
63 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
64 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
Eric Nelsond67b0d92013-03-11 08:44:53 +000065
66#define OUTPUT_40OHM (PAD_CTL_SPEED_MED|PAD_CTL_DSE_40ohm)
67
68int dram_init(void)
69{
fabio.estevam@freescale.com19a0f7f2013-03-14 02:32:55 +000070 gd->ram_size = ((ulong)CONFIG_DDR_MB * 1024 * 1024);
Eric Nelsond67b0d92013-03-11 08:44:53 +000071
72 return 0;
73}
74
Eric Nelson9fc42522014-10-02 12:16:27 -070075static iomux_v3_cfg_t const uart1_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070076 MX6_PAD_SD3_DAT6__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
77 MX6_PAD_SD3_DAT7__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +000078};
79
Eric Nelson9fc42522014-10-02 12:16:27 -070080static iomux_v3_cfg_t const uart2_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070081 MX6_PAD_EIM_D26__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
82 MX6_PAD_EIM_D27__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +000083};
84
85#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
86
87/* I2C1, SGTL5000 */
Eric Nelson9fc42522014-10-02 12:16:27 -070088static struct i2c_pads_info i2c_pad_info0 = {
Eric Nelsond67b0d92013-03-11 08:44:53 +000089 .scl = {
90 .i2c_mode = MX6_PAD_EIM_D21__I2C1_SCL | PC,
Eric Nelson10fda482013-11-04 17:00:51 -070091 .gpio_mode = MX6_PAD_EIM_D21__GPIO3_IO21 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +000092 .gp = IMX_GPIO_NR(3, 21)
93 },
94 .sda = {
95 .i2c_mode = MX6_PAD_EIM_D28__I2C1_SDA | PC,
Eric Nelson10fda482013-11-04 17:00:51 -070096 .gpio_mode = MX6_PAD_EIM_D28__GPIO3_IO28 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +000097 .gp = IMX_GPIO_NR(3, 28)
98 }
99};
100
101/* I2C2 Camera, MIPI */
Eric Nelson9fc42522014-10-02 12:16:27 -0700102static struct i2c_pads_info i2c_pad_info1 = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000103 .scl = {
104 .i2c_mode = MX6_PAD_KEY_COL3__I2C2_SCL | PC,
Eric Nelson10fda482013-11-04 17:00:51 -0700105 .gpio_mode = MX6_PAD_KEY_COL3__GPIO4_IO12 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000106 .gp = IMX_GPIO_NR(4, 12)
107 },
108 .sda = {
109 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC,
Eric Nelson10fda482013-11-04 17:00:51 -0700110 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO4_IO13 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000111 .gp = IMX_GPIO_NR(4, 13)
112 }
113};
114
115/* I2C3, J15 - RGB connector */
Eric Nelson9fc42522014-10-02 12:16:27 -0700116static struct i2c_pads_info i2c_pad_info2 = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000117 .scl = {
118 .i2c_mode = MX6_PAD_GPIO_5__I2C3_SCL | PC,
Eric Nelson10fda482013-11-04 17:00:51 -0700119 .gpio_mode = MX6_PAD_GPIO_5__GPIO1_IO05 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000120 .gp = IMX_GPIO_NR(1, 5)
121 },
122 .sda = {
123 .i2c_mode = MX6_PAD_GPIO_16__I2C3_SDA | PC,
Eric Nelson10fda482013-11-04 17:00:51 -0700124 .gpio_mode = MX6_PAD_GPIO_16__GPIO7_IO11 | PC,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000125 .gp = IMX_GPIO_NR(7, 11)
126 }
127};
128
Eric Nelson41612472014-10-02 12:16:24 -0700129static iomux_v3_cfg_t const usdhc2_pads[] = {
130 MX6_PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
131 MX6_PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
132 MX6_PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
133 MX6_PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
134 MX6_PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
135 MX6_PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
136};
137
Eric Nelson9fc42522014-10-02 12:16:27 -0700138static iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700139 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
140 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
141 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
142 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
143 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
144 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
145 MX6_PAD_SD3_DAT5__GPIO7_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Eric Nelsond67b0d92013-03-11 08:44:53 +0000146};
147
Eric Nelson9fc42522014-10-02 12:16:27 -0700148static iomux_v3_cfg_t const usdhc4_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700149 MX6_PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
150 MX6_PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
151 MX6_PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
152 MX6_PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
153 MX6_PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
154 MX6_PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
155 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Eric Nelsond67b0d92013-03-11 08:44:53 +0000156};
157
Eric Nelson9fc42522014-10-02 12:16:27 -0700158static iomux_v3_cfg_t const enet_pads1[] = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000159 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
160 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson10fda482013-11-04 17:00:51 -0700161 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
162 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
163 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
164 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
165 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000166 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
167 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
168 /* pin 35 - 1 (PHY_AD2) on reset */
Eric Nelson10fda482013-11-04 17:00:51 -0700169 MX6_PAD_RGMII_RXC__GPIO6_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000170 /* pin 32 - 1 - (MODE0) all */
Eric Nelson10fda482013-11-04 17:00:51 -0700171 MX6_PAD_RGMII_RD0__GPIO6_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000172 /* pin 31 - 1 - (MODE1) all */
Eric Nelson10fda482013-11-04 17:00:51 -0700173 MX6_PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000174 /* pin 28 - 1 - (MODE2) all */
Eric Nelson10fda482013-11-04 17:00:51 -0700175 MX6_PAD_RGMII_RD2__GPIO6_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000176 /* pin 27 - 1 - (MODE3) all */
Eric Nelson10fda482013-11-04 17:00:51 -0700177 MX6_PAD_RGMII_RD3__GPIO6_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000178 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
Eric Nelson10fda482013-11-04 17:00:51 -0700179 MX6_PAD_RGMII_RX_CTL__GPIO6_IO24 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000180 /* pin 42 PHY nRST */
Eric Nelson10fda482013-11-04 17:00:51 -0700181 MX6_PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL),
182 MX6_PAD_ENET_RXD0__GPIO1_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000183};
184
Eric Nelson9fc42522014-10-02 12:16:27 -0700185static iomux_v3_cfg_t const enet_pads2[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700186 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
187 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
188 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
189 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
190 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000191 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
192};
193
Troy Kisky08ce0742013-09-25 18:41:17 -0700194static iomux_v3_cfg_t const misc_pads[] = {
195 MX6_PAD_GPIO_1__USB_OTG_ID | MUX_PAD_CTRL(WEAK_PULLUP),
Eric Nelson10fda482013-11-04 17:00:51 -0700196 MX6_PAD_KEY_COL4__USB_OTG_OC | MUX_PAD_CTRL(WEAK_PULLUP),
197 MX6_PAD_EIM_D30__USB_H1_OC | MUX_PAD_CTRL(WEAK_PULLUP),
Troy Kisky08ce0742013-09-25 18:41:17 -0700198 /* OTG Power enable */
Eric Nelson10fda482013-11-04 17:00:51 -0700199 MX6_PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(OUTPUT_40OHM),
Troy Kisky08ce0742013-09-25 18:41:17 -0700200};
201
Eric Nelsond67b0d92013-03-11 08:44:53 +0000202/* wl1271 pads on nitrogen6x */
Eric Nelson9fc42522014-10-02 12:16:27 -0700203static iomux_v3_cfg_t const wl12xx_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700204 (MX6_PAD_NANDF_CS1__GPIO6_IO14 & ~MUX_PAD_CTRL_MASK)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000205 | MUX_PAD_CTRL(WEAK_PULLDOWN),
Eric Nelson10fda482013-11-04 17:00:51 -0700206 (MX6_PAD_NANDF_CS2__GPIO6_IO15 & ~MUX_PAD_CTRL_MASK)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000207 | MUX_PAD_CTRL(OUTPUT_40OHM),
Eric Nelson10fda482013-11-04 17:00:51 -0700208 (MX6_PAD_NANDF_CS3__GPIO6_IO16 & ~MUX_PAD_CTRL_MASK)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000209 | MUX_PAD_CTRL(OUTPUT_40OHM),
210};
211#define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
212#define WL12XX_WL_ENABLE_GP IMX_GPIO_NR(6, 15)
213#define WL12XX_BT_ENABLE_GP IMX_GPIO_NR(6, 16)
214
215/* Button assignments for J14 */
216static iomux_v3_cfg_t const button_pads[] = {
217 /* Menu */
Eric Nelson10fda482013-11-04 17:00:51 -0700218 MX6_PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000219 /* Back */
Eric Nelson10fda482013-11-04 17:00:51 -0700220 MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000221 /* Labelled Search (mapped to Power under Android) */
Eric Nelson10fda482013-11-04 17:00:51 -0700222 MX6_PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000223 /* Home */
Eric Nelson10fda482013-11-04 17:00:51 -0700224 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000225 /* Volume Down */
Eric Nelson10fda482013-11-04 17:00:51 -0700226 MX6_PAD_GPIO_19__GPIO4_IO05 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000227 /* Volume Up */
Eric Nelson10fda482013-11-04 17:00:51 -0700228 MX6_PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000229};
230
231static void setup_iomux_enet(void)
232{
233 gpio_direction_output(IMX_GPIO_NR(3, 23), 0); /* SABRE Lite PHY rst */
234 gpio_direction_output(IMX_GPIO_NR(1, 27), 0); /* Nitrogen6X PHY rst */
235 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
236 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
237 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
238 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
239 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
240 imx_iomux_v3_setup_multiple_pads(enet_pads1, ARRAY_SIZE(enet_pads1));
241 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
242
243 /* Need delay 10ms according to KSZ9021 spec */
244 udelay(1000 * 10);
245 gpio_set_value(IMX_GPIO_NR(3, 23), 1); /* SABRE Lite PHY reset */
246 gpio_set_value(IMX_GPIO_NR(1, 27), 1); /* Nitrogen6X PHY reset */
247
248 imx_iomux_v3_setup_multiple_pads(enet_pads2, ARRAY_SIZE(enet_pads2));
Troy Kiskyadc4a2b2014-10-02 12:16:29 -0700249 udelay(100); /* Wait 100 us before using mii interface */
Eric Nelsond67b0d92013-03-11 08:44:53 +0000250}
251
Eric Nelson9fc42522014-10-02 12:16:27 -0700252static iomux_v3_cfg_t const usb_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700253 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000254};
255
256static void setup_iomux_uart(void)
257{
258 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
259 imx_iomux_v3_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
260}
261
262#ifdef CONFIG_USB_EHCI_MX6
263int board_ehci_hcd_init(int port)
264{
265 imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads));
266
267 /* Reset USB hub */
268 gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
269 mdelay(2);
270 gpio_set_value(IMX_GPIO_NR(7, 12), 1);
271
272 return 0;
273}
Troy Kisky08ce0742013-09-25 18:41:17 -0700274
275int board_ehci_power(int port, int on)
276{
277 if (port)
278 return 0;
279 gpio_set_value(GP_USB_OTG_PWR, on);
280 return 0;
281}
282
Eric Nelsond67b0d92013-03-11 08:44:53 +0000283#endif
284
285#ifdef CONFIG_FSL_ESDHC
Eric Nelson9fc42522014-10-02 12:16:27 -0700286static struct fsl_esdhc_cfg usdhc_cfg[2] = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000287 {USDHC3_BASE_ADDR},
288 {USDHC4_BASE_ADDR},
289};
290
291int board_mmc_getcd(struct mmc *mmc)
292{
293 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Troy Kisky213e9e32014-10-02 12:16:23 -0700294 int gp_cd = (cfg->esdhc_base == USDHC3_BASE_ADDR) ? IMX_GPIO_NR(7, 0) :
295 IMX_GPIO_NR(2, 6);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000296
Troy Kisky213e9e32014-10-02 12:16:23 -0700297 gpio_direction_input(gp_cd);
298 return !gpio_get_value(gp_cd);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000299}
300
301int board_mmc_init(bd_t *bis)
302{
303 s32 status = 0;
304 u32 index = 0;
305
306 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
307 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
308
Abbas Razaaad46592013-03-25 09:13:34 +0000309 usdhc_cfg[0].max_bus_width = 4;
310 usdhc_cfg[1].max_bus_width = 4;
311
Eric Nelsond67b0d92013-03-11 08:44:53 +0000312 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
313 switch (index) {
314 case 0:
315 imx_iomux_v3_setup_multiple_pads(
316 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
317 break;
318 case 1:
319 imx_iomux_v3_setup_multiple_pads(
320 usdhc4_pads, ARRAY_SIZE(usdhc4_pads));
321 break;
322 default:
323 printf("Warning: you configured more USDHC controllers"
324 "(%d) then supported by the board (%d)\n",
325 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
326 return status;
327 }
328
329 status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
330 }
331
332 return status;
333}
334#endif
335
Eric Nelsond67b0d92013-03-11 08:44:53 +0000336#ifdef CONFIG_MXC_SPI
Eric Nelson9fc42522014-10-02 12:16:27 -0700337static iomux_v3_cfg_t const ecspi1_pads[] = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000338 /* SS1 */
Fabio Estevam3b316052014-04-11 17:43:53 -0300339 MX6_PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000340 MX6_PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
341 MX6_PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
342 MX6_PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
343};
344
Eric Nelson9fc42522014-10-02 12:16:27 -0700345static void setup_spi(void)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000346{
Eric Nelsond67b0d92013-03-11 08:44:53 +0000347 imx_iomux_v3_setup_multiple_pads(ecspi1_pads,
348 ARRAY_SIZE(ecspi1_pads));
349}
350#endif
351
352int board_phy_config(struct phy_device *phydev)
353{
354 /* min rx data delay */
355 ksz9021_phy_extended_write(phydev,
356 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
357 /* min tx data delay */
358 ksz9021_phy_extended_write(phydev,
359 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
360 /* max rx/tx clock delay, min rx/tx control */
361 ksz9021_phy_extended_write(phydev,
362 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
363 if (phydev->drv->config)
364 phydev->drv->config(phydev);
365
366 return 0;
367}
368
369int board_eth_init(bd_t *bis)
370{
371 uint32_t base = IMX_FEC_BASE;
372 struct mii_dev *bus = NULL;
373 struct phy_device *phydev = NULL;
374 int ret;
375
376 setup_iomux_enet();
377
378#ifdef CONFIG_FEC_MXC
379 bus = fec_get_miibus(base, -1);
380 if (!bus)
381 return 0;
382 /* scan phy 4,5,6,7 */
383 phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
384 if (!phydev) {
385 free(bus);
386 return 0;
387 }
388 printf("using phy at %d\n", phydev->addr);
389 ret = fec_probe(bis, -1, base, bus, phydev);
390 if (ret) {
391 printf("FEC MXC: %s:failed\n", __func__);
392 free(phydev);
393 free(bus);
394 }
395#endif
Troy Kisky08ce0742013-09-25 18:41:17 -0700396
Marek Vasutf016f8c2014-02-06 02:43:45 +0100397#ifdef CONFIG_CI_UDC
Troy Kisky08ce0742013-09-25 18:41:17 -0700398 /* For otg ethernet*/
399 usb_eth_initialize(bis);
400#endif
Eric Nelsond67b0d92013-03-11 08:44:53 +0000401 return 0;
402}
403
404static void setup_buttons(void)
405{
406 imx_iomux_v3_setup_multiple_pads(button_pads,
407 ARRAY_SIZE(button_pads));
408}
409
Eric Nelsond67b0d92013-03-11 08:44:53 +0000410#if defined(CONFIG_VIDEO_IPUV3)
411
412static iomux_v3_cfg_t const backlight_pads[] = {
413 /* Backlight on RGB connector: J15 */
Eric Nelson10fda482013-11-04 17:00:51 -0700414 MX6_PAD_SD1_DAT3__GPIO1_IO21 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000415#define RGB_BACKLIGHT_GP IMX_GPIO_NR(1, 21)
416
417 /* Backlight on LVDS connector: J6 */
Eric Nelson10fda482013-11-04 17:00:51 -0700418 MX6_PAD_SD1_CMD__GPIO1_IO18 | MUX_PAD_CTRL(NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000419#define LVDS_BACKLIGHT_GP IMX_GPIO_NR(1, 18)
420};
421
422static iomux_v3_cfg_t const rgb_pads[] = {
423 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK,
424 MX6_PAD_DI0_PIN15__IPU1_DI0_PIN15,
Eric Nelson10fda482013-11-04 17:00:51 -0700425 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN02,
426 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN03,
427 MX6_PAD_DI0_PIN4__GPIO4_IO20,
428 MX6_PAD_DISP0_DAT0__IPU1_DISP0_DATA00,
429 MX6_PAD_DISP0_DAT1__IPU1_DISP0_DATA01,
430 MX6_PAD_DISP0_DAT2__IPU1_DISP0_DATA02,
431 MX6_PAD_DISP0_DAT3__IPU1_DISP0_DATA03,
432 MX6_PAD_DISP0_DAT4__IPU1_DISP0_DATA04,
433 MX6_PAD_DISP0_DAT5__IPU1_DISP0_DATA05,
434 MX6_PAD_DISP0_DAT6__IPU1_DISP0_DATA06,
435 MX6_PAD_DISP0_DAT7__IPU1_DISP0_DATA07,
436 MX6_PAD_DISP0_DAT8__IPU1_DISP0_DATA08,
437 MX6_PAD_DISP0_DAT9__IPU1_DISP0_DATA09,
438 MX6_PAD_DISP0_DAT10__IPU1_DISP0_DATA10,
439 MX6_PAD_DISP0_DAT11__IPU1_DISP0_DATA11,
440 MX6_PAD_DISP0_DAT12__IPU1_DISP0_DATA12,
441 MX6_PAD_DISP0_DAT13__IPU1_DISP0_DATA13,
442 MX6_PAD_DISP0_DAT14__IPU1_DISP0_DATA14,
443 MX6_PAD_DISP0_DAT15__IPU1_DISP0_DATA15,
444 MX6_PAD_DISP0_DAT16__IPU1_DISP0_DATA16,
445 MX6_PAD_DISP0_DAT17__IPU1_DISP0_DATA17,
446 MX6_PAD_DISP0_DAT18__IPU1_DISP0_DATA18,
447 MX6_PAD_DISP0_DAT19__IPU1_DISP0_DATA19,
448 MX6_PAD_DISP0_DAT20__IPU1_DISP0_DATA20,
449 MX6_PAD_DISP0_DAT21__IPU1_DISP0_DATA21,
450 MX6_PAD_DISP0_DAT22__IPU1_DISP0_DATA22,
451 MX6_PAD_DISP0_DAT23__IPU1_DISP0_DATA23,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000452};
453
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500454static void do_enable_hdmi(struct display_info_t const *dev)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000455{
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500456 imx_enable_hdmi_phy();
Eric Nelsond67b0d92013-03-11 08:44:53 +0000457}
458
459static int detect_i2c(struct display_info_t const *dev)
460{
461 return ((0 == i2c_set_bus_num(dev->bus))
462 &&
463 (0 == i2c_probe(dev->addr)));
464}
465
466static void enable_lvds(struct display_info_t const *dev)
467{
468 struct iomuxc *iomux = (struct iomuxc *)
469 IOMUXC_BASE_ADDR;
470 u32 reg = readl(&iomux->gpr[2]);
471 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
472 writel(reg, &iomux->gpr[2]);
473 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
474}
475
476static void enable_rgb(struct display_info_t const *dev)
477{
478 imx_iomux_v3_setup_multiple_pads(
479 rgb_pads,
480 ARRAY_SIZE(rgb_pads));
481 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
482}
483
Eric Benarda47e4492014-04-04 19:05:53 +0200484struct display_info_t const displays[] = {{
Eric Nelsond67b0d92013-03-11 08:44:53 +0000485 .bus = -1,
486 .addr = 0,
487 .pixfmt = IPU_PIX_FMT_RGB24,
488 .detect = detect_hdmi,
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500489 .enable = do_enable_hdmi,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000490 .mode = {
491 .name = "HDMI",
492 .refresh = 60,
493 .xres = 1024,
494 .yres = 768,
495 .pixclock = 15385,
496 .left_margin = 220,
497 .right_margin = 40,
498 .upper_margin = 21,
499 .lower_margin = 7,
500 .hsync_len = 60,
501 .vsync_len = 10,
502 .sync = FB_SYNC_EXT,
503 .vmode = FB_VMODE_NONINTERLACED
504} }, {
505 .bus = 2,
506 .addr = 0x4,
507 .pixfmt = IPU_PIX_FMT_LVDS666,
508 .detect = detect_i2c,
509 .enable = enable_lvds,
510 .mode = {
511 .name = "Hannstar-XGA",
512 .refresh = 60,
513 .xres = 1024,
514 .yres = 768,
515 .pixclock = 15385,
516 .left_margin = 220,
517 .right_margin = 40,
518 .upper_margin = 21,
519 .lower_margin = 7,
520 .hsync_len = 60,
521 .vsync_len = 10,
522 .sync = FB_SYNC_EXT,
523 .vmode = FB_VMODE_NONINTERLACED
524} }, {
525 .bus = 2,
526 .addr = 0x38,
527 .pixfmt = IPU_PIX_FMT_LVDS666,
528 .detect = detect_i2c,
529 .enable = enable_lvds,
530 .mode = {
531 .name = "wsvga-lvds",
532 .refresh = 60,
533 .xres = 1024,
534 .yres = 600,
535 .pixclock = 15385,
536 .left_margin = 220,
537 .right_margin = 40,
538 .upper_margin = 21,
539 .lower_margin = 7,
540 .hsync_len = 60,
541 .vsync_len = 10,
542 .sync = FB_SYNC_EXT,
543 .vmode = FB_VMODE_NONINTERLACED
544} }, {
545 .bus = 2,
546 .addr = 0x48,
547 .pixfmt = IPU_PIX_FMT_RGB666,
548 .detect = detect_i2c,
549 .enable = enable_rgb,
550 .mode = {
551 .name = "wvga-rgb",
552 .refresh = 57,
553 .xres = 800,
554 .yres = 480,
555 .pixclock = 37037,
556 .left_margin = 40,
557 .right_margin = 60,
558 .upper_margin = 10,
559 .lower_margin = 10,
560 .hsync_len = 20,
561 .vsync_len = 10,
562 .sync = 0,
563 .vmode = FB_VMODE_NONINTERLACED
564} } };
Eric Benarda47e4492014-04-04 19:05:53 +0200565size_t display_count = ARRAY_SIZE(displays);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000566
Eric Nelsonc9c86bd2014-10-02 12:16:22 -0700567int board_cfb_skip(void)
568{
569 return NULL != getenv("novideo");
570}
571
Eric Nelsond67b0d92013-03-11 08:44:53 +0000572static void setup_display(void)
573{
574 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000575 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000576 int reg;
577
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500578 enable_ipu_clock();
579 imx_setup_hdmi();
Eric Nelsond67b0d92013-03-11 08:44:53 +0000580 /* Turn on LDB0,IPU,IPU DI0 clocks */
581 reg = __raw_readl(&mxc_ccm->CCGR3);
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500582 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000583 writel(reg, &mxc_ccm->CCGR3);
584
Eric Nelsond67b0d92013-03-11 08:44:53 +0000585 /* set LDB0, LDB1 clk select to 011/011 */
586 reg = readl(&mxc_ccm->cs2cdr);
587 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
588 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
589 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
590 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
591 writel(reg, &mxc_ccm->cs2cdr);
592
593 reg = readl(&mxc_ccm->cscmr2);
594 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
595 writel(reg, &mxc_ccm->cscmr2);
596
597 reg = readl(&mxc_ccm->chsccdr);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000598 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500599 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000600 writel(reg, &mxc_ccm->chsccdr);
601
602 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
603 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
604 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
605 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
606 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
607 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
608 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
609 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
610 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
611 writel(reg, &iomux->gpr[2]);
612
613 reg = readl(&iomux->gpr[3]);
Eric Nelson8907c2c2013-08-20 11:44:43 -0700614 reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK
615 |IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
Eric Nelsond67b0d92013-03-11 08:44:53 +0000616 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
617 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
618 writel(reg, &iomux->gpr[3]);
619
620 /* backlights off until needed */
621 imx_iomux_v3_setup_multiple_pads(backlight_pads,
622 ARRAY_SIZE(backlight_pads));
623 gpio_direction_input(LVDS_BACKLIGHT_GP);
624 gpio_direction_input(RGB_BACKLIGHT_GP);
625}
626#endif
627
Eric Nelsona3b527a2014-10-02 12:16:25 -0700628static iomux_v3_cfg_t const init_pads[] = {
Troy Kisky693cccf2014-10-02 12:16:26 -0700629 /* SGTL5000 sys_mclk */
630 NEW_PAD_CTRL(MX6_PAD_GPIO_0__CCM_CLKO1, OUTPUT_40OHM),
631
632 /* J5 - Camera MCLK */
633 NEW_PAD_CTRL(MX6_PAD_GPIO_3__CCM_CLKO2, OUTPUT_40OHM),
634
635 /* wl1271 pads on nitrogen6x */
Eric Nelsona3b527a2014-10-02 12:16:25 -0700636 /* WL12XX_WL_IRQ_GP */
637 NEW_PAD_CTRL(MX6_PAD_NANDF_CS1__GPIO6_IO14, WEAK_PULLDOWN),
638 /* WL12XX_WL_ENABLE_GP */
639 NEW_PAD_CTRL(MX6_PAD_NANDF_CS2__GPIO6_IO15, OUTPUT_40OHM),
640 /* WL12XX_BT_ENABLE_GP */
641 NEW_PAD_CTRL(MX6_PAD_NANDF_CS3__GPIO6_IO16, OUTPUT_40OHM),
642 /* USB otg power */
643 NEW_PAD_CTRL(MX6_PAD_EIM_D22__GPIO3_IO22, OUTPUT_40OHM),
644 NEW_PAD_CTRL(MX6_PAD_NANDF_D5__GPIO2_IO05, OUTPUT_40OHM),
645 NEW_PAD_CTRL(MX6_PAD_NANDF_WP_B__GPIO6_IO09, OUTPUT_40OHM),
646 NEW_PAD_CTRL(MX6_PAD_GPIO_8__GPIO1_IO08, OUTPUT_40OHM),
647 NEW_PAD_CTRL(MX6_PAD_GPIO_6__GPIO1_IO06, OUTPUT_40OHM),
648};
649
650#define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
651
652static unsigned gpios_out_low[] = {
653 /* Disable wl1271 */
654 IMX_GPIO_NR(6, 15), /* disable wireless */
655 IMX_GPIO_NR(6, 16), /* disable bluetooth */
656 IMX_GPIO_NR(3, 22), /* disable USB otg power */
657 IMX_GPIO_NR(2, 5), /* ov5640 mipi camera reset */
658 IMX_GPIO_NR(1, 8), /* ov5642 reset */
659};
660
661static unsigned gpios_out_high[] = {
662 IMX_GPIO_NR(1, 6), /* ov5642 powerdown */
663 IMX_GPIO_NR(6, 9), /* ov5640 mipi camera power down */
664};
665
666static void set_gpios(unsigned *p, int cnt, int val)
667{
668 int i;
669
670 for (i = 0; i < cnt; i++)
671 gpio_direction_output(*p++, val);
672}
673
Eric Nelsond67b0d92013-03-11 08:44:53 +0000674int board_early_init_f(void)
675{
676 setup_iomux_uart();
677
Eric Nelsona3b527a2014-10-02 12:16:25 -0700678 set_gpios(gpios_out_high, ARRAY_SIZE(gpios_out_high), 1);
679 set_gpios(gpios_out_low, ARRAY_SIZE(gpios_out_low), 0);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000680 gpio_direction_input(WL12XX_WL_IRQ_GP);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000681
682 imx_iomux_v3_setup_multiple_pads(wl12xx_pads, ARRAY_SIZE(wl12xx_pads));
Eric Nelsona3b527a2014-10-02 12:16:25 -0700683 imx_iomux_v3_setup_multiple_pads(init_pads, ARRAY_SIZE(init_pads));
Eric Nelsond67b0d92013-03-11 08:44:53 +0000684 setup_buttons();
685
686#if defined(CONFIG_VIDEO_IPUV3)
687 setup_display();
688#endif
689 return 0;
690}
691
692/*
693 * Do not overwrite the console
694 * Use always serial for U-Boot console
695 */
696int overwrite_console(void)
697{
698 return 1;
699}
700
701int board_init(void)
702{
Fabio Estevam0a11d6f2014-07-09 17:59:54 -0300703 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Troy Kisky71328692013-09-25 18:41:16 -0700704
705 clrsetbits_le32(&iomuxc_regs->gpr[1],
706 IOMUXC_GPR1_OTG_ID_MASK,
707 IOMUXC_GPR1_OTG_ID_GPIO1);
708
Troy Kisky08ce0742013-09-25 18:41:17 -0700709 imx_iomux_v3_setup_multiple_pads(misc_pads, ARRAY_SIZE(misc_pads));
710
Eric Nelsond67b0d92013-03-11 08:44:53 +0000711 /* address of boot parameters */
712 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
713
714#ifdef CONFIG_MXC_SPI
715 setup_spi();
716#endif
Eric Nelson41612472014-10-02 12:16:24 -0700717 imx_iomux_v3_setup_multiple_pads(
718 usdhc2_pads, ARRAY_SIZE(usdhc2_pads));
Eric Nelsond67b0d92013-03-11 08:44:53 +0000719 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0);
720 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
721 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
722
723#ifdef CONFIG_CMD_SATA
724 setup_sata();
725#endif
726
727 return 0;
728}
729
730int checkboard(void)
731{
732 if (gpio_get_value(WL12XX_WL_IRQ_GP))
733 puts("Board: Nitrogen6X\n");
734 else
735 puts("Board: SABRE Lite\n");
736
737 return 0;
738}
739
740struct button_key {
741 char const *name;
742 unsigned gpnum;
743 char ident;
744};
745
746static struct button_key const buttons[] = {
747 {"back", IMX_GPIO_NR(2, 2), 'B'},
748 {"home", IMX_GPIO_NR(2, 4), 'H'},
749 {"menu", IMX_GPIO_NR(2, 1), 'M'},
750 {"search", IMX_GPIO_NR(2, 3), 'S'},
751 {"volup", IMX_GPIO_NR(7, 13), 'V'},
752 {"voldown", IMX_GPIO_NR(4, 5), 'v'},
753};
754
755/*
756 * generate a null-terminated string containing the buttons pressed
757 * returns number of keys pressed
758 */
759static int read_keys(char *buf)
760{
761 int i, numpressed = 0;
762 for (i = 0; i < ARRAY_SIZE(buttons); i++) {
763 if (!gpio_get_value(buttons[i].gpnum))
764 buf[numpressed++] = buttons[i].ident;
765 }
766 buf[numpressed] = '\0';
767 return numpressed;
768}
769
770static int do_kbd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
771{
772 char envvalue[ARRAY_SIZE(buttons)+1];
773 int numpressed = read_keys(envvalue);
774 setenv("keybd", envvalue);
775 return numpressed == 0;
776}
777
778U_BOOT_CMD(
779 kbd, 1, 1, do_kbd,
780 "Tests for keypresses, sets 'keybd' environment variable",
781 "Returns 0 (true) to shell if key is pressed."
782);
783
784#ifdef CONFIG_PREBOOT
785static char const kbd_magic_prefix[] = "key_magic";
786static char const kbd_command_prefix[] = "key_cmd";
787
788static void preboot_keys(void)
789{
790 int numpressed;
791 char keypress[ARRAY_SIZE(buttons)+1];
792 numpressed = read_keys(keypress);
793 if (numpressed) {
794 char *kbd_magic_keys = getenv("magic_keys");
795 char *suffix;
796 /*
797 * loop over all magic keys
798 */
799 for (suffix = kbd_magic_keys; *suffix; ++suffix) {
800 char *keys;
801 char magic[sizeof(kbd_magic_prefix) + 1];
802 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
803 keys = getenv(magic);
804 if (keys) {
805 if (!strcmp(keys, keypress))
806 break;
807 }
808 }
809 if (*suffix) {
810 char cmd_name[sizeof(kbd_command_prefix) + 1];
811 char *cmd;
812 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
813 cmd = getenv(cmd_name);
814 if (cmd) {
815 setenv("preboot", cmd);
816 return;
817 }
818 }
819 }
820}
821#endif
822
823#ifdef CONFIG_CMD_BMODE
824static const struct boot_mode board_boot_modes[] = {
825 /* 4 bit bus width */
826 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
827 {"mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
828 {NULL, 0},
829};
830#endif
831
832int misc_init_r(void)
833{
834#ifdef CONFIG_PREBOOT
835 preboot_keys();
836#endif
837
838#ifdef CONFIG_CMD_BMODE
839 add_board_boot_modes(board_boot_modes);
840#endif
841 return 0;
842}