1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
4 * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/iomux.h>
15 #include <asm/arch/sys_proto.h>
17 #include <asm/arch/mx6-pins.h>
18 #include <linux/errno.h>
20 #include <asm/mach-imx/iomux-v3.h>
21 #include <asm/mach-imx/mxc_i2c.h>
22 #include <asm/mach-imx/sata.h>
23 #include <asm/mach-imx/spi.h>
24 #include <asm/mach-imx/boot_mode.h>
25 #include <asm/mach-imx/video.h>
27 #include <fsl_esdhc_imx.h>
31 #include <asm/arch/crm_regs.h>
32 #include <asm/arch/mxc_hdmi.h>
36 #include <usb/ehci-ci.h>
38 DECLARE_GLOBAL_DATA_PTR;
39 #define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
41 #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
42 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
43 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
45 #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
46 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
47 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
49 #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
50 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
52 #define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
53 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
55 #define BUTTON_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
56 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
58 #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
59 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
60 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
62 #define RGB_PAD_CTRL PAD_CTL_DSE_120ohm
64 #define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \
65 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
68 #define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
69 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
70 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
72 #define OUTPUT_40OHM (PAD_CTL_SPEED_MED|PAD_CTL_DSE_40ohm)
74 /* Prevent compiler error if gpio number 08 or 09 is used */
75 #define not_octal(gp) ((((0x##gp >> 4) & 0xf) * 10) + ((0x##gp & 0xf)))
77 #define _I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
78 sda_pad, sda_bank, sda_gp, pad_ctrl, join_io) { \
80 .i2c_mode = NEW_PAD_CTRL(cpu##_PAD_##scl_pad##__##i2cnum##_SCL,\
82 .gpio_mode = NEW_PAD_CTRL( \
83 cpu##_PAD_##scl_pad##__GPIO##scl_bank##join_io##scl_gp,\
85 .gp = IMX_GPIO_NR(scl_bank, not_octal(scl_gp)) \
88 .i2c_mode = NEW_PAD_CTRL(cpu##_PAD_##sda_pad##__##i2cnum##_SDA,\
90 .gpio_mode = NEW_PAD_CTRL( \
91 cpu##_PAD_##sda_pad##__GPIO##sda_bank##join_io##sda_gp,\
93 .gp = IMX_GPIO_NR(sda_bank, not_octal(sda_gp)) \
97 #define I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
98 sda_pad, sda_bank, sda_gp, pad_ctrl) \
99 _I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
100 sda_pad, sda_bank, sda_gp, pad_ctrl, _IO)
102 #if defined(CONFIG_MX6QDL)
103 #define I2C_PADS_INFO_ENTRY(i2cnum, scl_pad, scl_bank, scl_gp, \
104 sda_pad, sda_bank, sda_gp, pad_ctrl) \
105 I2C_PADS_INFO_CPU(MX6Q, i2cnum, scl_pad, scl_bank, scl_gp, \
106 sda_pad, sda_bank, sda_gp, pad_ctrl), \
107 I2C_PADS_INFO_CPU(MX6DL, i2cnum, scl_pad, scl_bank, scl_gp, \
108 sda_pad, sda_bank, sda_gp, pad_ctrl)
109 #define I2C_PADS_INFO_ENTRY_SPACING 2
111 #define IOMUX_PAD_CTRL(name, pad_ctrl) \
112 NEW_PAD_CTRL(MX6Q_PAD_##name, pad_ctrl), \
113 NEW_PAD_CTRL(MX6DL_PAD_##name, pad_ctrl)
115 #define I2C_PADS_INFO_ENTRY(i2cnum, scl_pad, scl_bank, scl_gp, \
116 sda_pad, sda_bank, sda_gp, pad_ctrl) \
117 I2C_PADS_INFO_CPU(MX6, i2cnum, scl_pad, scl_bank, scl_gp, \
118 sda_pad, sda_bank, sda_gp, pad_ctrl)
119 #define I2C_PADS_INFO_ENTRY_SPACING 1
121 #define IOMUX_PAD_CTRL(name, pad_ctrl) NEW_PAD_CTRL(MX6_PAD_##name, pad_ctrl)
126 gd->ram_size = ((ulong)CONFIG_DDR_MB * 1024 * 1024);
131 static iomux_v3_cfg_t const uart1_pads[] = {
132 IOMUX_PAD_CTRL(SD3_DAT6__UART1_RX_DATA, UART_PAD_CTRL),
133 IOMUX_PAD_CTRL(SD3_DAT7__UART1_TX_DATA, UART_PAD_CTRL),
136 static iomux_v3_cfg_t const uart2_pads[] = {
137 IOMUX_PAD_CTRL(EIM_D26__UART2_TX_DATA, UART_PAD_CTRL),
138 IOMUX_PAD_CTRL(EIM_D27__UART2_RX_DATA, UART_PAD_CTRL),
141 static struct i2c_pads_info i2c_pads[] = {
143 I2C_PADS_INFO_ENTRY(I2C1, EIM_D21, 3, 21, EIM_D28, 3, 28, I2C_PAD_CTRL),
144 /* I2C2 Camera, MIPI */
145 I2C_PADS_INFO_ENTRY(I2C2, KEY_COL3, 4, 12, KEY_ROW3, 4, 13,
147 /* I2C3, J15 - RGB connector */
148 I2C_PADS_INFO_ENTRY(I2C3, GPIO_5, 1, 05, GPIO_16, 7, 11, I2C_PAD_CTRL),
151 #define I2C_BUS_CNT 3
153 static iomux_v3_cfg_t const usdhc2_pads[] = {
154 IOMUX_PAD_CTRL(SD2_CLK__SD2_CLK, USDHC_PAD_CTRL),
155 IOMUX_PAD_CTRL(SD2_CMD__SD2_CMD, USDHC_PAD_CTRL),
156 IOMUX_PAD_CTRL(SD2_DAT0__SD2_DATA0, USDHC_PAD_CTRL),
157 IOMUX_PAD_CTRL(SD2_DAT1__SD2_DATA1, USDHC_PAD_CTRL),
158 IOMUX_PAD_CTRL(SD2_DAT2__SD2_DATA2, USDHC_PAD_CTRL),
159 IOMUX_PAD_CTRL(SD2_DAT3__SD2_DATA3, USDHC_PAD_CTRL),
162 static iomux_v3_cfg_t const usdhc3_pads[] = {
163 IOMUX_PAD_CTRL(SD3_CLK__SD3_CLK, USDHC_PAD_CTRL),
164 IOMUX_PAD_CTRL(SD3_CMD__SD3_CMD, USDHC_PAD_CTRL),
165 IOMUX_PAD_CTRL(SD3_DAT0__SD3_DATA0, USDHC_PAD_CTRL),
166 IOMUX_PAD_CTRL(SD3_DAT1__SD3_DATA1, USDHC_PAD_CTRL),
167 IOMUX_PAD_CTRL(SD3_DAT2__SD3_DATA2, USDHC_PAD_CTRL),
168 IOMUX_PAD_CTRL(SD3_DAT3__SD3_DATA3, USDHC_PAD_CTRL),
169 IOMUX_PAD_CTRL(SD3_DAT5__GPIO7_IO00, NO_PAD_CTRL), /* CD */
172 static iomux_v3_cfg_t const usdhc4_pads[] = {
173 IOMUX_PAD_CTRL(SD4_CLK__SD4_CLK, USDHC_PAD_CTRL),
174 IOMUX_PAD_CTRL(SD4_CMD__SD4_CMD, USDHC_PAD_CTRL),
175 IOMUX_PAD_CTRL(SD4_DAT0__SD4_DATA0, USDHC_PAD_CTRL),
176 IOMUX_PAD_CTRL(SD4_DAT1__SD4_DATA1, USDHC_PAD_CTRL),
177 IOMUX_PAD_CTRL(SD4_DAT2__SD4_DATA2, USDHC_PAD_CTRL),
178 IOMUX_PAD_CTRL(SD4_DAT3__SD4_DATA3, USDHC_PAD_CTRL),
179 IOMUX_PAD_CTRL(NANDF_D6__GPIO2_IO06, NO_PAD_CTRL), /* CD */
182 static iomux_v3_cfg_t const enet_pads1[] = {
183 IOMUX_PAD_CTRL(ENET_MDIO__ENET_MDIO, ENET_PAD_CTRL),
184 IOMUX_PAD_CTRL(ENET_MDC__ENET_MDC, ENET_PAD_CTRL),
185 IOMUX_PAD_CTRL(RGMII_TXC__RGMII_TXC, ENET_PAD_CTRL),
186 IOMUX_PAD_CTRL(RGMII_TD0__RGMII_TD0, ENET_PAD_CTRL),
187 IOMUX_PAD_CTRL(RGMII_TD1__RGMII_TD1, ENET_PAD_CTRL),
188 IOMUX_PAD_CTRL(RGMII_TD2__RGMII_TD2, ENET_PAD_CTRL),
189 IOMUX_PAD_CTRL(RGMII_TD3__RGMII_TD3, ENET_PAD_CTRL),
190 IOMUX_PAD_CTRL(RGMII_TX_CTL__RGMII_TX_CTL, ENET_PAD_CTRL),
191 IOMUX_PAD_CTRL(ENET_REF_CLK__ENET_TX_CLK, ENET_PAD_CTRL),
192 /* pin 35 - 1 (PHY_AD2) on reset */
193 IOMUX_PAD_CTRL(RGMII_RXC__GPIO6_IO30, NO_PAD_CTRL),
194 /* pin 32 - 1 - (MODE0) all */
195 IOMUX_PAD_CTRL(RGMII_RD0__GPIO6_IO25, NO_PAD_CTRL),
196 /* pin 31 - 1 - (MODE1) all */
197 IOMUX_PAD_CTRL(RGMII_RD1__GPIO6_IO27, NO_PAD_CTRL),
198 /* pin 28 - 1 - (MODE2) all */
199 IOMUX_PAD_CTRL(RGMII_RD2__GPIO6_IO28, NO_PAD_CTRL),
200 /* pin 27 - 1 - (MODE3) all */
201 IOMUX_PAD_CTRL(RGMII_RD3__GPIO6_IO29, NO_PAD_CTRL),
202 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
203 IOMUX_PAD_CTRL(RGMII_RX_CTL__GPIO6_IO24, NO_PAD_CTRL),
204 /* pin 42 PHY nRST */
205 IOMUX_PAD_CTRL(EIM_D23__GPIO3_IO23, NO_PAD_CTRL),
206 IOMUX_PAD_CTRL(ENET_RXD0__GPIO1_IO27, NO_PAD_CTRL),
209 static iomux_v3_cfg_t const enet_pads2[] = {
210 IOMUX_PAD_CTRL(RGMII_RXC__RGMII_RXC, ENET_PAD_CTRL),
211 IOMUX_PAD_CTRL(RGMII_RD0__RGMII_RD0, ENET_PAD_CTRL),
212 IOMUX_PAD_CTRL(RGMII_RD1__RGMII_RD1, ENET_PAD_CTRL),
213 IOMUX_PAD_CTRL(RGMII_RD2__RGMII_RD2, ENET_PAD_CTRL),
214 IOMUX_PAD_CTRL(RGMII_RD3__RGMII_RD3, ENET_PAD_CTRL),
215 IOMUX_PAD_CTRL(RGMII_RX_CTL__RGMII_RX_CTL, ENET_PAD_CTRL),
218 static iomux_v3_cfg_t const misc_pads[] = {
219 IOMUX_PAD_CTRL(GPIO_1__USB_OTG_ID, WEAK_PULLUP),
220 IOMUX_PAD_CTRL(KEY_COL4__USB_OTG_OC, WEAK_PULLUP),
221 IOMUX_PAD_CTRL(EIM_D30__USB_H1_OC, WEAK_PULLUP),
222 /* OTG Power enable */
223 IOMUX_PAD_CTRL(EIM_D22__GPIO3_IO22, OUTPUT_40OHM),
226 /* wl1271 pads on nitrogen6x */
227 static iomux_v3_cfg_t const wl12xx_pads[] = {
228 IOMUX_PAD_CTRL(NANDF_CS1__GPIO6_IO14, WEAK_PULLDOWN),
229 IOMUX_PAD_CTRL(NANDF_CS2__GPIO6_IO15, OUTPUT_40OHM),
230 IOMUX_PAD_CTRL(NANDF_CS3__GPIO6_IO16, OUTPUT_40OHM),
232 #define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
233 #define WL12XX_WL_ENABLE_GP IMX_GPIO_NR(6, 15)
234 #define WL12XX_BT_ENABLE_GP IMX_GPIO_NR(6, 16)
236 /* Button assignments for J14 */
237 static iomux_v3_cfg_t const button_pads[] = {
239 IOMUX_PAD_CTRL(NANDF_D1__GPIO2_IO01, BUTTON_PAD_CTRL),
241 IOMUX_PAD_CTRL(NANDF_D2__GPIO2_IO02, BUTTON_PAD_CTRL),
242 /* Labelled Search (mapped to Power under Android) */
243 IOMUX_PAD_CTRL(NANDF_D3__GPIO2_IO03, BUTTON_PAD_CTRL),
245 IOMUX_PAD_CTRL(NANDF_D4__GPIO2_IO04, BUTTON_PAD_CTRL),
247 IOMUX_PAD_CTRL(GPIO_19__GPIO4_IO05, BUTTON_PAD_CTRL),
249 IOMUX_PAD_CTRL(GPIO_18__GPIO7_IO13, BUTTON_PAD_CTRL),
252 static void setup_iomux_enet(void)
254 gpio_direction_output(IMX_GPIO_NR(3, 23), 0); /* SABRE Lite PHY rst */
255 gpio_direction_output(IMX_GPIO_NR(1, 27), 0); /* Nitrogen6X PHY rst */
256 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
257 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
258 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
259 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
260 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
261 SETUP_IOMUX_PADS(enet_pads1);
262 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
264 /* Need delay 10ms according to KSZ9021 spec */
266 gpio_set_value(IMX_GPIO_NR(3, 23), 1); /* SABRE Lite PHY reset */
267 gpio_set_value(IMX_GPIO_NR(1, 27), 1); /* Nitrogen6X PHY reset */
269 SETUP_IOMUX_PADS(enet_pads2);
270 udelay(100); /* Wait 100 us before using mii interface */
273 static iomux_v3_cfg_t const usb_pads[] = {
274 IOMUX_PAD_CTRL(GPIO_17__GPIO7_IO12, NO_PAD_CTRL),
277 static void setup_iomux_uart(void)
279 SETUP_IOMUX_PADS(uart1_pads);
280 SETUP_IOMUX_PADS(uart2_pads);
283 #ifdef CONFIG_USB_EHCI_MX6
284 int board_ehci_hcd_init(int port)
286 SETUP_IOMUX_PADS(usb_pads);
289 gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
291 gpio_set_value(IMX_GPIO_NR(7, 12), 1);
296 int board_ehci_power(int port, int on)
300 gpio_set_value(GP_USB_OTG_PWR, on);
306 #ifdef CONFIG_FSL_ESDHC_IMX
307 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
312 int board_mmc_getcd(struct mmc *mmc)
314 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
315 int gp_cd = (cfg->esdhc_base == USDHC3_BASE_ADDR) ? IMX_GPIO_NR(7, 0) :
318 gpio_direction_input(gp_cd);
319 return !gpio_get_value(gp_cd);
322 int board_mmc_init(bd_t *bis)
327 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
328 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
330 usdhc_cfg[0].max_bus_width = 4;
331 usdhc_cfg[1].max_bus_width = 4;
333 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
336 SETUP_IOMUX_PADS(usdhc3_pads);
339 SETUP_IOMUX_PADS(usdhc4_pads);
342 printf("Warning: you configured more USDHC controllers"
343 "(%d) then supported by the board (%d)\n",
344 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
348 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
357 #ifdef CONFIG_MXC_SPI
358 int board_spi_cs_gpio(unsigned bus, unsigned cs)
360 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
363 static iomux_v3_cfg_t const ecspi1_pads[] = {
365 IOMUX_PAD_CTRL(EIM_D19__GPIO3_IO19, NO_PAD_CTRL),
366 IOMUX_PAD_CTRL(EIM_D17__ECSPI1_MISO, SPI_PAD_CTRL),
367 IOMUX_PAD_CTRL(EIM_D18__ECSPI1_MOSI, SPI_PAD_CTRL),
368 IOMUX_PAD_CTRL(EIM_D16__ECSPI1_SCLK, SPI_PAD_CTRL),
371 static void setup_spi(void)
373 SETUP_IOMUX_PADS(ecspi1_pads);
377 int board_phy_config(struct phy_device *phydev)
379 /* min rx data delay */
380 ksz9021_phy_extended_write(phydev,
381 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
382 /* min tx data delay */
383 ksz9021_phy_extended_write(phydev,
384 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
385 /* max rx/tx clock delay, min rx/tx control */
386 ksz9021_phy_extended_write(phydev,
387 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
388 if (phydev->drv->config)
389 phydev->drv->config(phydev);
394 int board_eth_init(bd_t *bis)
396 uint32_t base = IMX_FEC_BASE;
397 struct mii_dev *bus = NULL;
398 struct phy_device *phydev = NULL;
401 gpio_request(WL12XX_WL_IRQ_GP, "wifi_irq");
402 gpio_request(IMX_GPIO_NR(6, 30), "rgmii_rxc");
403 gpio_request(IMX_GPIO_NR(6, 25), "rgmii_rd0");
404 gpio_request(IMX_GPIO_NR(6, 27), "rgmii_rd1");
405 gpio_request(IMX_GPIO_NR(6, 28), "rgmii_rd2");
406 gpio_request(IMX_GPIO_NR(6, 29), "rgmii_rd3");
407 gpio_request(IMX_GPIO_NR(6, 24), "rgmii_rx_ctl");
408 gpio_request(IMX_GPIO_NR(3, 23), "rgmii_reset_sabrelite");
409 gpio_request(IMX_GPIO_NR(1, 27), "rgmii_reset_nitrogen6x");
412 #ifdef CONFIG_FEC_MXC
413 bus = fec_get_miibus(base, -1);
416 /* scan phy 4,5,6,7 */
417 phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
422 printf("using phy at %d\n", phydev->addr);
423 ret = fec_probe(bis, -1, base, bus, phydev);
429 /* For otg ethernet*/
430 usb_eth_initialize(bis);
441 static void setup_buttons(void)
443 SETUP_IOMUX_PADS(button_pads);
446 #if defined(CONFIG_VIDEO_IPUV3)
448 static iomux_v3_cfg_t const backlight_pads[] = {
449 /* Backlight on RGB connector: J15 */
450 IOMUX_PAD_CTRL(SD1_DAT3__GPIO1_IO21, NO_PAD_CTRL),
451 #define RGB_BACKLIGHT_GP IMX_GPIO_NR(1, 21)
453 /* Backlight on LVDS connector: J6 */
454 IOMUX_PAD_CTRL(SD1_CMD__GPIO1_IO18, NO_PAD_CTRL),
455 #define LVDS_BACKLIGHT_GP IMX_GPIO_NR(1, 18)
458 static iomux_v3_cfg_t const rgb_pads[] = {
459 IOMUX_PAD_CTRL(DI0_DISP_CLK__IPU1_DI0_DISP_CLK, RGB_PAD_CTRL),
460 IOMUX_PAD_CTRL(DI0_PIN15__IPU1_DI0_PIN15, RGB_PAD_CTRL),
461 IOMUX_PAD_CTRL(DI0_PIN2__IPU1_DI0_PIN02, RGB_PAD_CTRL),
462 IOMUX_PAD_CTRL(DI0_PIN3__IPU1_DI0_PIN03, RGB_PAD_CTRL),
463 IOMUX_PAD_CTRL(DI0_PIN4__GPIO4_IO20, RGB_PAD_CTRL),
464 IOMUX_PAD_CTRL(DISP0_DAT0__IPU1_DISP0_DATA00, RGB_PAD_CTRL),
465 IOMUX_PAD_CTRL(DISP0_DAT1__IPU1_DISP0_DATA01, RGB_PAD_CTRL),
466 IOMUX_PAD_CTRL(DISP0_DAT2__IPU1_DISP0_DATA02, RGB_PAD_CTRL),
467 IOMUX_PAD_CTRL(DISP0_DAT3__IPU1_DISP0_DATA03, RGB_PAD_CTRL),
468 IOMUX_PAD_CTRL(DISP0_DAT4__IPU1_DISP0_DATA04, RGB_PAD_CTRL),
469 IOMUX_PAD_CTRL(DISP0_DAT5__IPU1_DISP0_DATA05, RGB_PAD_CTRL),
470 IOMUX_PAD_CTRL(DISP0_DAT6__IPU1_DISP0_DATA06, RGB_PAD_CTRL),
471 IOMUX_PAD_CTRL(DISP0_DAT7__IPU1_DISP0_DATA07, RGB_PAD_CTRL),
472 IOMUX_PAD_CTRL(DISP0_DAT8__IPU1_DISP0_DATA08, RGB_PAD_CTRL),
473 IOMUX_PAD_CTRL(DISP0_DAT9__IPU1_DISP0_DATA09, RGB_PAD_CTRL),
474 IOMUX_PAD_CTRL(DISP0_DAT10__IPU1_DISP0_DATA10, RGB_PAD_CTRL),
475 IOMUX_PAD_CTRL(DISP0_DAT11__IPU1_DISP0_DATA11, RGB_PAD_CTRL),
476 IOMUX_PAD_CTRL(DISP0_DAT12__IPU1_DISP0_DATA12, RGB_PAD_CTRL),
477 IOMUX_PAD_CTRL(DISP0_DAT13__IPU1_DISP0_DATA13, RGB_PAD_CTRL),
478 IOMUX_PAD_CTRL(DISP0_DAT14__IPU1_DISP0_DATA14, RGB_PAD_CTRL),
479 IOMUX_PAD_CTRL(DISP0_DAT15__IPU1_DISP0_DATA15, RGB_PAD_CTRL),
480 IOMUX_PAD_CTRL(DISP0_DAT16__IPU1_DISP0_DATA16, RGB_PAD_CTRL),
481 IOMUX_PAD_CTRL(DISP0_DAT17__IPU1_DISP0_DATA17, RGB_PAD_CTRL),
482 IOMUX_PAD_CTRL(DISP0_DAT18__IPU1_DISP0_DATA18, RGB_PAD_CTRL),
483 IOMUX_PAD_CTRL(DISP0_DAT19__IPU1_DISP0_DATA19, RGB_PAD_CTRL),
484 IOMUX_PAD_CTRL(DISP0_DAT20__IPU1_DISP0_DATA20, RGB_PAD_CTRL),
485 IOMUX_PAD_CTRL(DISP0_DAT21__IPU1_DISP0_DATA21, RGB_PAD_CTRL),
486 IOMUX_PAD_CTRL(DISP0_DAT22__IPU1_DISP0_DATA22, RGB_PAD_CTRL),
487 IOMUX_PAD_CTRL(DISP0_DAT23__IPU1_DISP0_DATA23, RGB_PAD_CTRL),
490 static void do_enable_hdmi(struct display_info_t const *dev)
492 imx_enable_hdmi_phy();
495 static int detect_i2c(struct display_info_t const *dev)
497 return ((0 == i2c_set_bus_num(dev->bus))
499 (0 == i2c_probe(dev->addr)));
502 static void enable_lvds(struct display_info_t const *dev)
504 struct iomuxc *iomux = (struct iomuxc *)
506 u32 reg = readl(&iomux->gpr[2]);
507 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
508 writel(reg, &iomux->gpr[2]);
509 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
512 static void enable_lvds_jeida(struct display_info_t const *dev)
514 struct iomuxc *iomux = (struct iomuxc *)
516 u32 reg = readl(&iomux->gpr[2]);
517 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
518 |IOMUXC_GPR2_BIT_MAPPING_CH0_JEIDA;
519 writel(reg, &iomux->gpr[2]);
520 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
523 static void enable_rgb(struct display_info_t const *dev)
525 SETUP_IOMUX_PADS(rgb_pads);
526 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
529 struct display_info_t const displays[] = {{
532 .pixfmt = IPU_PIX_FMT_RGB24,
533 .detect = detect_i2c,
534 .enable = do_enable_hdmi,
548 .vmode = FB_VMODE_NONINTERLACED
552 .pixfmt = IPU_PIX_FMT_RGB24,
554 .enable = enable_lvds_jeida,
568 .vmode = FB_VMODE_NONINTERLACED
572 .pixfmt = IPU_PIX_FMT_RGB24,
574 .enable = enable_lvds,
576 .name = "LDB-WXGA-S",
588 .vmode = FB_VMODE_NONINTERLACED
592 .pixfmt = IPU_PIX_FMT_LVDS666,
593 .detect = detect_i2c,
594 .enable = enable_lvds,
596 .name = "Hannstar-XGA",
608 .vmode = FB_VMODE_NONINTERLACED
612 .pixfmt = IPU_PIX_FMT_LVDS666,
614 .enable = enable_lvds,
620 .pixclock = 15385, /* ~65MHz */
628 .vmode = FB_VMODE_NONINTERLACED
632 .pixfmt = IPU_PIX_FMT_LVDS666,
633 .detect = detect_i2c,
634 .enable = enable_lvds,
636 .name = "wsvga-lvds",
648 .vmode = FB_VMODE_NONINTERLACED
652 .pixfmt = IPU_PIX_FMT_RGB666,
653 .detect = detect_i2c,
654 .enable = enable_rgb,
668 .vmode = FB_VMODE_NONINTERLACED
672 .pixfmt = IPU_PIX_FMT_RGB666,
674 .enable = enable_rgb,
688 .vmode = FB_VMODE_NONINTERLACED
692 .pixfmt = IPU_PIX_FMT_LVDS666,
693 .detect = detect_i2c,
694 .enable = enable_lvds,
696 .name = "amp1024x600",
708 .vmode = FB_VMODE_NONINTERLACED
712 .pixfmt = IPU_PIX_FMT_LVDS666,
714 .enable = enable_lvds,
728 .vmode = FB_VMODE_NONINTERLACED
732 .pixfmt = IPU_PIX_FMT_RGB666,
733 .detect = detect_i2c,
734 .enable = enable_rgb,
748 .vmode = FB_VMODE_NONINTERLACED
752 .pixfmt = IPU_PIX_FMT_RGB24,
754 .enable = enable_rgb,
768 .vmode = FB_VMODE_NONINTERLACED
770 size_t display_count = ARRAY_SIZE(displays);
772 int board_cfb_skip(void)
774 return NULL != env_get("novideo");
777 static void setup_display(void)
779 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
780 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
785 /* Turn on LDB0,IPU,IPU DI0 clocks */
786 reg = __raw_readl(&mxc_ccm->CCGR3);
787 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
788 writel(reg, &mxc_ccm->CCGR3);
790 /* set LDB0, LDB1 clk select to 011/011 */
791 reg = readl(&mxc_ccm->cs2cdr);
792 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
793 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
794 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
795 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
796 writel(reg, &mxc_ccm->cs2cdr);
798 reg = readl(&mxc_ccm->cscmr2);
799 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
800 writel(reg, &mxc_ccm->cscmr2);
802 reg = readl(&mxc_ccm->chsccdr);
803 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
804 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
805 writel(reg, &mxc_ccm->chsccdr);
807 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
808 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
809 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
810 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
811 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
812 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
813 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
814 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
815 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
816 writel(reg, &iomux->gpr[2]);
818 reg = readl(&iomux->gpr[3]);
819 reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK
820 |IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
821 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
822 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
823 writel(reg, &iomux->gpr[3]);
825 /* backlights off until needed */
826 SETUP_IOMUX_PADS(backlight_pads);
827 gpio_direction_input(LVDS_BACKLIGHT_GP);
828 gpio_direction_input(RGB_BACKLIGHT_GP);
832 static iomux_v3_cfg_t const init_pads[] = {
833 /* SGTL5000 sys_mclk */
834 IOMUX_PAD_CTRL(GPIO_0__CCM_CLKO1, OUTPUT_40OHM),
836 /* J5 - Camera MCLK */
837 IOMUX_PAD_CTRL(GPIO_3__CCM_CLKO2, OUTPUT_40OHM),
839 /* wl1271 pads on nitrogen6x */
840 /* WL12XX_WL_IRQ_GP */
841 IOMUX_PAD_CTRL(NANDF_CS1__GPIO6_IO14, WEAK_PULLDOWN),
842 /* WL12XX_WL_ENABLE_GP */
843 IOMUX_PAD_CTRL(NANDF_CS2__GPIO6_IO15, OUTPUT_40OHM),
844 /* WL12XX_BT_ENABLE_GP */
845 IOMUX_PAD_CTRL(NANDF_CS3__GPIO6_IO16, OUTPUT_40OHM),
847 IOMUX_PAD_CTRL(EIM_D22__GPIO3_IO22, OUTPUT_40OHM),
848 IOMUX_PAD_CTRL(NANDF_D5__GPIO2_IO05, OUTPUT_40OHM),
849 IOMUX_PAD_CTRL(NANDF_WP_B__GPIO6_IO09, OUTPUT_40OHM),
850 IOMUX_PAD_CTRL(GPIO_8__GPIO1_IO08, OUTPUT_40OHM),
851 IOMUX_PAD_CTRL(GPIO_6__GPIO1_IO06, OUTPUT_40OHM),
854 #define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
856 static unsigned gpios_out_low[] = {
858 IMX_GPIO_NR(6, 15), /* disable wireless */
859 IMX_GPIO_NR(6, 16), /* disable bluetooth */
860 IMX_GPIO_NR(3, 22), /* disable USB otg power */
861 IMX_GPIO_NR(2, 5), /* ov5640 mipi camera reset */
862 IMX_GPIO_NR(1, 8), /* ov5642 reset */
865 static unsigned gpios_out_high[] = {
866 IMX_GPIO_NR(1, 6), /* ov5642 powerdown */
867 IMX_GPIO_NR(6, 9), /* ov5640 mipi camera power down */
870 static void set_gpios(unsigned *p, int cnt, int val)
874 for (i = 0; i < cnt; i++)
875 gpio_direction_output(*p++, val);
878 int board_early_init_f(void)
882 set_gpios(gpios_out_high, ARRAY_SIZE(gpios_out_high), 1);
883 set_gpios(gpios_out_low, ARRAY_SIZE(gpios_out_low), 0);
884 gpio_direction_input(WL12XX_WL_IRQ_GP);
886 SETUP_IOMUX_PADS(wl12xx_pads);
887 SETUP_IOMUX_PADS(init_pads);
890 #if defined(CONFIG_VIDEO_IPUV3)
897 * Do not overwrite the console
898 * Use always serial for U-Boot console
900 int overwrite_console(void)
907 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
908 struct i2c_pads_info *p = i2c_pads;
912 #if defined(CONFIG_MX6QDL)
914 if (!is_mx6dq() && !is_mx6dqp())
917 clrsetbits_le32(&iomuxc_regs->gpr[1],
918 IOMUXC_GPR1_OTG_ID_MASK,
919 IOMUXC_GPR1_OTG_ID_GPIO1);
921 SETUP_IOMUX_PADS(misc_pads);
923 /* address of boot parameters */
924 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
926 #ifdef CONFIG_MXC_SPI
929 SETUP_IOMUX_PADS(usdhc2_pads);
930 for (i = 0; i < I2C_BUS_CNT; i++) {
931 setup_i2c(i, CONFIG_SYS_I2C_SPEED, 0x7f, p);
944 int ret = gpio_get_value(WL12XX_WL_IRQ_GP);
947 /* The gpios have not been probed yet. Read it myself */
948 struct gpio_regs *regs = (struct gpio_regs *)GPIO6_BASE_ADDR;
949 int gpio = WL12XX_WL_IRQ_GP & 0x1f;
951 ret = (readl(®s->gpio_psr) >> gpio) & 0x01;
954 puts("Board: Nitrogen6X\n");
956 puts("Board: SABRE Lite\n");
967 static struct button_key const buttons[] = {
968 {"back", IMX_GPIO_NR(2, 2), 'B'},
969 {"home", IMX_GPIO_NR(2, 4), 'H'},
970 {"menu", IMX_GPIO_NR(2, 1), 'M'},
971 {"search", IMX_GPIO_NR(2, 3), 'S'},
972 {"volup", IMX_GPIO_NR(7, 13), 'V'},
973 {"voldown", IMX_GPIO_NR(4, 5), 'v'},
977 * generate a null-terminated string containing the buttons pressed
978 * returns number of keys pressed
980 static int read_keys(char *buf)
982 int i, numpressed = 0;
983 for (i = 0; i < ARRAY_SIZE(buttons); i++) {
984 if (!gpio_get_value(buttons[i].gpnum))
985 buf[numpressed++] = buttons[i].ident;
987 buf[numpressed] = '\0';
991 static int do_kbd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
993 char envvalue[ARRAY_SIZE(buttons)+1];
994 int numpressed = read_keys(envvalue);
995 env_set("keybd", envvalue);
996 return numpressed == 0;
1001 "Tests for keypresses, sets 'keybd' environment variable",
1002 "Returns 0 (true) to shell if key is pressed."
1005 #ifdef CONFIG_PREBOOT
1006 static char const kbd_magic_prefix[] = "key_magic";
1007 static char const kbd_command_prefix[] = "key_cmd";
1009 static void preboot_keys(void)
1012 char keypress[ARRAY_SIZE(buttons)+1];
1013 numpressed = read_keys(keypress);
1015 char *kbd_magic_keys = env_get("magic_keys");
1018 * loop over all magic keys
1020 for (suffix = kbd_magic_keys; *suffix; ++suffix) {
1022 char magic[sizeof(kbd_magic_prefix) + 1];
1023 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
1024 keys = env_get(magic);
1026 if (!strcmp(keys, keypress))
1031 char cmd_name[sizeof(kbd_command_prefix) + 1];
1033 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
1034 cmd = env_get(cmd_name);
1036 env_set("preboot", cmd);
1044 #ifdef CONFIG_CMD_BMODE
1045 static const struct boot_mode board_boot_modes[] = {
1046 /* 4 bit bus width */
1047 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
1048 {"mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
1053 int misc_init_r(void)
1055 gpio_request(RGB_BACKLIGHT_GP, "lvds backlight");
1056 gpio_request(LVDS_BACKLIGHT_GP, "lvds backlight");
1057 gpio_request(GP_USB_OTG_PWR, "usbotg power");
1058 gpio_request(IMX_GPIO_NR(7, 12), "usbh1 hub reset");
1059 gpio_request(IMX_GPIO_NR(2, 2), "back");
1060 gpio_request(IMX_GPIO_NR(2, 4), "home");
1061 gpio_request(IMX_GPIO_NR(2, 1), "menu");
1062 gpio_request(IMX_GPIO_NR(2, 3), "search");
1063 gpio_request(IMX_GPIO_NR(7, 13), "volup");
1064 gpio_request(IMX_GPIO_NR(4, 5), "voldown");
1065 #ifdef CONFIG_PREBOOT
1069 #ifdef CONFIG_CMD_BMODE
1070 add_board_boot_modes(board_boot_modes);
1072 env_set_hex("reset_cause", get_imx_reset_cause());