blob: 382c01ddf4e017c68c0610eed50c5ca520d1d444 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eric Nelsond67b0d92013-03-11 08:44:53 +00002/*
3 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
4 * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
Eric Nelsond67b0d92013-03-11 08:44:53 +00005 */
6
7#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06009#include <env.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <net.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000013#include <asm/io.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/imx-regs.h>
16#include <asm/arch/iomux.h>
17#include <asm/arch/sys_proto.h>
18#include <malloc.h>
19#include <asm/arch/mx6-pins.h>
Simon Glassc05ed002020-05-10 11:40:11 -060020#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090021#include <linux/errno.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000022#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020023#include <asm/mach-imx/iomux-v3.h>
24#include <asm/mach-imx/mxc_i2c.h>
25#include <asm/mach-imx/sata.h>
26#include <asm/mach-imx/spi.h>
27#include <asm/mach-imx/boot_mode.h>
28#include <asm/mach-imx/video.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080029#include <fsl_esdhc_imx.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000030#include <micrel.h>
31#include <miiphy.h>
32#include <netdev.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000033#include <asm/arch/crm_regs.h>
34#include <asm/arch/mxc_hdmi.h>
35#include <i2c.h>
Eric Nelson9fc42522014-10-02 12:16:27 -070036#include <input.h>
37#include <netdev.h>
Mateusz Kulikowskie162c6b2016-03-31 23:12:23 +020038#include <usb/ehci-ci.h>
Eric Nelsond67b0d92013-03-11 08:44:53 +000039
40DECLARE_GLOBAL_DATA_PTR;
Troy Kisky08ce0742013-09-25 18:41:17 -070041#define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
Eric Nelsond67b0d92013-03-11 08:44:53 +000042
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000043#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
44 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
45 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000046
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000047#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
48 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
49 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000050
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000051#define ENET_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 SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000055 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
56
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000057#define BUTTON_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
58 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Eric Nelsond67b0d92013-03-11 08:44:53 +000059
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000060#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
61 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000062 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
63
Troy Kiskyc30c3602019-11-03 18:20:04 -080064#define RGB_PAD_CTRL PAD_CTL_DSE_120ohm
65
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000066#define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \
67 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
Eric Nelsond67b0d92013-03-11 08:44:53 +000068 PAD_CTL_SRE_SLOW)
69
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000070#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
71 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
72 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
Eric Nelsond67b0d92013-03-11 08:44:53 +000073
74#define OUTPUT_40OHM (PAD_CTL_SPEED_MED|PAD_CTL_DSE_40ohm)
75
Troy Kiskyc30c3602019-11-03 18:20:04 -080076/* Prevent compiler error if gpio number 08 or 09 is used */
77#define not_octal(gp) ((((0x##gp >> 4) & 0xf) * 10) + ((0x##gp & 0xf)))
78
79#define _I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
80 sda_pad, sda_bank, sda_gp, pad_ctrl, join_io) { \
81 .scl = { \
82 .i2c_mode = NEW_PAD_CTRL(cpu##_PAD_##scl_pad##__##i2cnum##_SCL,\
83 pad_ctrl), \
84 .gpio_mode = NEW_PAD_CTRL( \
85 cpu##_PAD_##scl_pad##__GPIO##scl_bank##join_io##scl_gp,\
86 pad_ctrl), \
87 .gp = IMX_GPIO_NR(scl_bank, not_octal(scl_gp)) \
88 }, \
89 .sda = { \
90 .i2c_mode = NEW_PAD_CTRL(cpu##_PAD_##sda_pad##__##i2cnum##_SDA,\
91 pad_ctrl), \
92 .gpio_mode = NEW_PAD_CTRL( \
93 cpu##_PAD_##sda_pad##__GPIO##sda_bank##join_io##sda_gp,\
94 pad_ctrl), \
95 .gp = IMX_GPIO_NR(sda_bank, not_octal(sda_gp)) \
96 } \
97}
98
99#define I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
100 sda_pad, sda_bank, sda_gp, pad_ctrl) \
101 _I2C_PADS_INFO_CPU(cpu, i2cnum, scl_pad, scl_bank, scl_gp, \
102 sda_pad, sda_bank, sda_gp, pad_ctrl, _IO)
103
104#if defined(CONFIG_MX6QDL)
105#define I2C_PADS_INFO_ENTRY(i2cnum, scl_pad, scl_bank, scl_gp, \
106 sda_pad, sda_bank, sda_gp, pad_ctrl) \
107 I2C_PADS_INFO_CPU(MX6Q, i2cnum, scl_pad, scl_bank, scl_gp, \
108 sda_pad, sda_bank, sda_gp, pad_ctrl), \
109 I2C_PADS_INFO_CPU(MX6DL, i2cnum, scl_pad, scl_bank, scl_gp, \
110 sda_pad, sda_bank, sda_gp, pad_ctrl)
111#define I2C_PADS_INFO_ENTRY_SPACING 2
112
113#define IOMUX_PAD_CTRL(name, pad_ctrl) \
114 NEW_PAD_CTRL(MX6Q_PAD_##name, pad_ctrl), \
115 NEW_PAD_CTRL(MX6DL_PAD_##name, pad_ctrl)
116#else
117#define I2C_PADS_INFO_ENTRY(i2cnum, scl_pad, scl_bank, scl_gp, \
118 sda_pad, sda_bank, sda_gp, pad_ctrl) \
119 I2C_PADS_INFO_CPU(MX6, i2cnum, scl_pad, scl_bank, scl_gp, \
120 sda_pad, sda_bank, sda_gp, pad_ctrl)
121#define I2C_PADS_INFO_ENTRY_SPACING 1
122
123#define IOMUX_PAD_CTRL(name, pad_ctrl) NEW_PAD_CTRL(MX6_PAD_##name, pad_ctrl)
124#endif
125
Eric Nelsond67b0d92013-03-11 08:44:53 +0000126int dram_init(void)
127{
fabio.estevam@freescale.com19a0f7f2013-03-14 02:32:55 +0000128 gd->ram_size = ((ulong)CONFIG_DDR_MB * 1024 * 1024);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000129
130 return 0;
131}
132
Eric Nelson9fc42522014-10-02 12:16:27 -0700133static iomux_v3_cfg_t const uart1_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800134 IOMUX_PAD_CTRL(SD3_DAT6__UART1_RX_DATA, UART_PAD_CTRL),
135 IOMUX_PAD_CTRL(SD3_DAT7__UART1_TX_DATA, UART_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000136};
137
Eric Nelson9fc42522014-10-02 12:16:27 -0700138static iomux_v3_cfg_t const uart2_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800139 IOMUX_PAD_CTRL(EIM_D26__UART2_TX_DATA, UART_PAD_CTRL),
140 IOMUX_PAD_CTRL(EIM_D27__UART2_RX_DATA, UART_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000141};
142
Troy Kiskyc30c3602019-11-03 18:20:04 -0800143static struct i2c_pads_info i2c_pads[] = {
144 /* I2C1, SGTL5000 */
145 I2C_PADS_INFO_ENTRY(I2C1, EIM_D21, 3, 21, EIM_D28, 3, 28, I2C_PAD_CTRL),
146 /* I2C2 Camera, MIPI */
147 I2C_PADS_INFO_ENTRY(I2C2, KEY_COL3, 4, 12, KEY_ROW3, 4, 13,
148 I2C_PAD_CTRL),
149 /* I2C3, J15 - RGB connector */
150 I2C_PADS_INFO_ENTRY(I2C3, GPIO_5, 1, 05, GPIO_16, 7, 11, I2C_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000151};
152
Troy Kiskyc30c3602019-11-03 18:20:04 -0800153#define I2C_BUS_CNT 3
Eric Nelsond67b0d92013-03-11 08:44:53 +0000154
Eric Nelson41612472014-10-02 12:16:24 -0700155static iomux_v3_cfg_t const usdhc2_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800156 IOMUX_PAD_CTRL(SD2_CLK__SD2_CLK, USDHC_PAD_CTRL),
157 IOMUX_PAD_CTRL(SD2_CMD__SD2_CMD, USDHC_PAD_CTRL),
158 IOMUX_PAD_CTRL(SD2_DAT0__SD2_DATA0, USDHC_PAD_CTRL),
159 IOMUX_PAD_CTRL(SD2_DAT1__SD2_DATA1, USDHC_PAD_CTRL),
160 IOMUX_PAD_CTRL(SD2_DAT2__SD2_DATA2, USDHC_PAD_CTRL),
161 IOMUX_PAD_CTRL(SD2_DAT3__SD2_DATA3, USDHC_PAD_CTRL),
Eric Nelson41612472014-10-02 12:16:24 -0700162};
163
Eric Nelson9fc42522014-10-02 12:16:27 -0700164static iomux_v3_cfg_t const enet_pads1[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800165 IOMUX_PAD_CTRL(ENET_MDIO__ENET_MDIO, ENET_PAD_CTRL),
166 IOMUX_PAD_CTRL(ENET_MDC__ENET_MDC, ENET_PAD_CTRL),
167 IOMUX_PAD_CTRL(RGMII_TXC__RGMII_TXC, ENET_PAD_CTRL),
168 IOMUX_PAD_CTRL(RGMII_TD0__RGMII_TD0, ENET_PAD_CTRL),
169 IOMUX_PAD_CTRL(RGMII_TD1__RGMII_TD1, ENET_PAD_CTRL),
170 IOMUX_PAD_CTRL(RGMII_TD2__RGMII_TD2, ENET_PAD_CTRL),
171 IOMUX_PAD_CTRL(RGMII_TD3__RGMII_TD3, ENET_PAD_CTRL),
172 IOMUX_PAD_CTRL(RGMII_TX_CTL__RGMII_TX_CTL, ENET_PAD_CTRL),
173 IOMUX_PAD_CTRL(ENET_REF_CLK__ENET_TX_CLK, ENET_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000174 /* pin 35 - 1 (PHY_AD2) on reset */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800175 IOMUX_PAD_CTRL(RGMII_RXC__GPIO6_IO30, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000176 /* pin 32 - 1 - (MODE0) all */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800177 IOMUX_PAD_CTRL(RGMII_RD0__GPIO6_IO25, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000178 /* pin 31 - 1 - (MODE1) all */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800179 IOMUX_PAD_CTRL(RGMII_RD1__GPIO6_IO27, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000180 /* pin 28 - 1 - (MODE2) all */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800181 IOMUX_PAD_CTRL(RGMII_RD2__GPIO6_IO28, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000182 /* pin 27 - 1 - (MODE3) all */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800183 IOMUX_PAD_CTRL(RGMII_RD3__GPIO6_IO29, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000184 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800185 IOMUX_PAD_CTRL(RGMII_RX_CTL__GPIO6_IO24, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000186 /* pin 42 PHY nRST */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800187 IOMUX_PAD_CTRL(EIM_D23__GPIO3_IO23, NO_PAD_CTRL),
188 IOMUX_PAD_CTRL(ENET_RXD0__GPIO1_IO27, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000189};
190
Eric Nelson9fc42522014-10-02 12:16:27 -0700191static iomux_v3_cfg_t const enet_pads2[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800192 IOMUX_PAD_CTRL(RGMII_RXC__RGMII_RXC, ENET_PAD_CTRL),
193 IOMUX_PAD_CTRL(RGMII_RD0__RGMII_RD0, ENET_PAD_CTRL),
194 IOMUX_PAD_CTRL(RGMII_RD1__RGMII_RD1, ENET_PAD_CTRL),
195 IOMUX_PAD_CTRL(RGMII_RD2__RGMII_RD2, ENET_PAD_CTRL),
196 IOMUX_PAD_CTRL(RGMII_RD3__RGMII_RD3, ENET_PAD_CTRL),
197 IOMUX_PAD_CTRL(RGMII_RX_CTL__RGMII_RX_CTL, ENET_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000198};
199
Troy Kisky08ce0742013-09-25 18:41:17 -0700200static iomux_v3_cfg_t const misc_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800201 IOMUX_PAD_CTRL(GPIO_1__USB_OTG_ID, WEAK_PULLUP),
202 IOMUX_PAD_CTRL(KEY_COL4__USB_OTG_OC, WEAK_PULLUP),
203 IOMUX_PAD_CTRL(EIM_D30__USB_H1_OC, WEAK_PULLUP),
Troy Kisky08ce0742013-09-25 18:41:17 -0700204 /* OTG Power enable */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800205 IOMUX_PAD_CTRL(EIM_D22__GPIO3_IO22, OUTPUT_40OHM),
Troy Kisky08ce0742013-09-25 18:41:17 -0700206};
207
Eric Nelsond67b0d92013-03-11 08:44:53 +0000208/* wl1271 pads on nitrogen6x */
Eric Nelson9fc42522014-10-02 12:16:27 -0700209static iomux_v3_cfg_t const wl12xx_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800210 IOMUX_PAD_CTRL(NANDF_CS1__GPIO6_IO14, WEAK_PULLDOWN),
211 IOMUX_PAD_CTRL(NANDF_CS2__GPIO6_IO15, OUTPUT_40OHM),
212 IOMUX_PAD_CTRL(NANDF_CS3__GPIO6_IO16, OUTPUT_40OHM),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000213};
214#define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
215#define WL12XX_WL_ENABLE_GP IMX_GPIO_NR(6, 15)
216#define WL12XX_BT_ENABLE_GP IMX_GPIO_NR(6, 16)
217
218/* Button assignments for J14 */
219static iomux_v3_cfg_t const button_pads[] = {
220 /* Menu */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800221 IOMUX_PAD_CTRL(NANDF_D1__GPIO2_IO01, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000222 /* Back */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800223 IOMUX_PAD_CTRL(NANDF_D2__GPIO2_IO02, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000224 /* Labelled Search (mapped to Power under Android) */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800225 IOMUX_PAD_CTRL(NANDF_D3__GPIO2_IO03, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000226 /* Home */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800227 IOMUX_PAD_CTRL(NANDF_D4__GPIO2_IO04, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000228 /* Volume Down */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800229 IOMUX_PAD_CTRL(GPIO_19__GPIO4_IO05, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000230 /* Volume Up */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800231 IOMUX_PAD_CTRL(GPIO_18__GPIO7_IO13, BUTTON_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000232};
233
234static void setup_iomux_enet(void)
235{
236 gpio_direction_output(IMX_GPIO_NR(3, 23), 0); /* SABRE Lite PHY rst */
237 gpio_direction_output(IMX_GPIO_NR(1, 27), 0); /* Nitrogen6X PHY rst */
238 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
239 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
240 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
241 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
242 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
Troy Kiskyc30c3602019-11-03 18:20:04 -0800243 SETUP_IOMUX_PADS(enet_pads1);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000244 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
245
246 /* Need delay 10ms according to KSZ9021 spec */
247 udelay(1000 * 10);
248 gpio_set_value(IMX_GPIO_NR(3, 23), 1); /* SABRE Lite PHY reset */
249 gpio_set_value(IMX_GPIO_NR(1, 27), 1); /* Nitrogen6X PHY reset */
250
Troy Kiskyc30c3602019-11-03 18:20:04 -0800251 SETUP_IOMUX_PADS(enet_pads2);
Troy Kiskyadc4a2b2014-10-02 12:16:29 -0700252 udelay(100); /* Wait 100 us before using mii interface */
Eric Nelsond67b0d92013-03-11 08:44:53 +0000253}
254
Eric Nelson9fc42522014-10-02 12:16:27 -0700255static iomux_v3_cfg_t const usb_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800256 IOMUX_PAD_CTRL(GPIO_17__GPIO7_IO12, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000257};
258
259static void setup_iomux_uart(void)
260{
Troy Kiskyc30c3602019-11-03 18:20:04 -0800261 SETUP_IOMUX_PADS(uart1_pads);
262 SETUP_IOMUX_PADS(uart2_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000263}
264
265#ifdef CONFIG_USB_EHCI_MX6
266int board_ehci_hcd_init(int port)
267{
Troy Kiskyc30c3602019-11-03 18:20:04 -0800268 SETUP_IOMUX_PADS(usb_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000269
270 /* Reset USB hub */
271 gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
272 mdelay(2);
273 gpio_set_value(IMX_GPIO_NR(7, 12), 1);
274
275 return 0;
276}
Troy Kisky08ce0742013-09-25 18:41:17 -0700277
278int board_ehci_power(int port, int on)
279{
280 if (port)
281 return 0;
282 gpio_set_value(GP_USB_OTG_PWR, on);
283 return 0;
284}
285
Eric Nelsond67b0d92013-03-11 08:44:53 +0000286#endif
287
Eric Nelsond67b0d92013-03-11 08:44:53 +0000288#ifdef CONFIG_MXC_SPI
Nikita Kiryanov155fa9a2014-08-20 15:08:50 +0300289int board_spi_cs_gpio(unsigned bus, unsigned cs)
290{
291 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
292}
293
Eric Nelson9fc42522014-10-02 12:16:27 -0700294static iomux_v3_cfg_t const ecspi1_pads[] = {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000295 /* SS1 */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800296 IOMUX_PAD_CTRL(EIM_D19__GPIO3_IO19, NO_PAD_CTRL),
297 IOMUX_PAD_CTRL(EIM_D17__ECSPI1_MISO, SPI_PAD_CTRL),
298 IOMUX_PAD_CTRL(EIM_D18__ECSPI1_MOSI, SPI_PAD_CTRL),
299 IOMUX_PAD_CTRL(EIM_D16__ECSPI1_SCLK, SPI_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000300};
301
Eric Nelson9fc42522014-10-02 12:16:27 -0700302static void setup_spi(void)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000303{
Troy Kiskyc30c3602019-11-03 18:20:04 -0800304 SETUP_IOMUX_PADS(ecspi1_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000305}
306#endif
307
308int board_phy_config(struct phy_device *phydev)
309{
310 /* min rx data delay */
311 ksz9021_phy_extended_write(phydev,
312 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
313 /* min tx data delay */
314 ksz9021_phy_extended_write(phydev,
315 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
316 /* max rx/tx clock delay, min rx/tx control */
317 ksz9021_phy_extended_write(phydev,
318 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
319 if (phydev->drv->config)
320 phydev->drv->config(phydev);
321
322 return 0;
323}
324
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900325int board_eth_init(struct bd_info *bis)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000326{
327 uint32_t base = IMX_FEC_BASE;
328 struct mii_dev *bus = NULL;
329 struct phy_device *phydev = NULL;
330 int ret;
331
Troy Kisky1b51e5f2019-07-29 12:15:56 -0700332 gpio_request(WL12XX_WL_IRQ_GP, "wifi_irq");
333 gpio_request(IMX_GPIO_NR(6, 30), "rgmii_rxc");
334 gpio_request(IMX_GPIO_NR(6, 25), "rgmii_rd0");
335 gpio_request(IMX_GPIO_NR(6, 27), "rgmii_rd1");
336 gpio_request(IMX_GPIO_NR(6, 28), "rgmii_rd2");
337 gpio_request(IMX_GPIO_NR(6, 29), "rgmii_rd3");
338 gpio_request(IMX_GPIO_NR(6, 24), "rgmii_rx_ctl");
339 gpio_request(IMX_GPIO_NR(3, 23), "rgmii_reset_sabrelite");
340 gpio_request(IMX_GPIO_NR(1, 27), "rgmii_reset_nitrogen6x");
Eric Nelsond67b0d92013-03-11 08:44:53 +0000341 setup_iomux_enet();
342
343#ifdef CONFIG_FEC_MXC
344 bus = fec_get_miibus(base, -1);
345 if (!bus)
Fabio Estevam747472b2015-09-11 00:53:51 -0300346 return -EINVAL;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000347 /* scan phy 4,5,6,7 */
Marek Behúne24b58f2022-04-07 00:33:08 +0200348 phydev = phy_find_by_mask(bus, (0xf << 4));
Eric Nelsond67b0d92013-03-11 08:44:53 +0000349 if (!phydev) {
Fabio Estevam747472b2015-09-11 00:53:51 -0300350 ret = -EINVAL;
351 goto free_bus;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000352 }
353 printf("using phy at %d\n", phydev->addr);
354 ret = fec_probe(bis, -1, base, bus, phydev);
Fabio Estevam747472b2015-09-11 00:53:51 -0300355 if (ret)
356 goto free_phydev;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000357#endif
Troy Kisky08ce0742013-09-25 18:41:17 -0700358
Eric Nelsond67b0d92013-03-11 08:44:53 +0000359 return 0;
Fabio Estevam747472b2015-09-11 00:53:51 -0300360
361free_phydev:
362 free(phydev);
363free_bus:
364 free(bus);
365 return ret;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000366}
367
368static void setup_buttons(void)
369{
Troy Kiskyc30c3602019-11-03 18:20:04 -0800370 SETUP_IOMUX_PADS(button_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000371}
372
Eric Nelsond67b0d92013-03-11 08:44:53 +0000373#if defined(CONFIG_VIDEO_IPUV3)
374
375static iomux_v3_cfg_t const backlight_pads[] = {
376 /* Backlight on RGB connector: J15 */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800377 IOMUX_PAD_CTRL(SD1_DAT3__GPIO1_IO21, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000378#define RGB_BACKLIGHT_GP IMX_GPIO_NR(1, 21)
379
380 /* Backlight on LVDS connector: J6 */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800381 IOMUX_PAD_CTRL(SD1_CMD__GPIO1_IO18, NO_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000382#define LVDS_BACKLIGHT_GP IMX_GPIO_NR(1, 18)
383};
384
385static iomux_v3_cfg_t const rgb_pads[] = {
Troy Kiskyc30c3602019-11-03 18:20:04 -0800386 IOMUX_PAD_CTRL(DI0_DISP_CLK__IPU1_DI0_DISP_CLK, RGB_PAD_CTRL),
387 IOMUX_PAD_CTRL(DI0_PIN15__IPU1_DI0_PIN15, RGB_PAD_CTRL),
388 IOMUX_PAD_CTRL(DI0_PIN2__IPU1_DI0_PIN02, RGB_PAD_CTRL),
389 IOMUX_PAD_CTRL(DI0_PIN3__IPU1_DI0_PIN03, RGB_PAD_CTRL),
390 IOMUX_PAD_CTRL(DI0_PIN4__GPIO4_IO20, RGB_PAD_CTRL),
391 IOMUX_PAD_CTRL(DISP0_DAT0__IPU1_DISP0_DATA00, RGB_PAD_CTRL),
392 IOMUX_PAD_CTRL(DISP0_DAT1__IPU1_DISP0_DATA01, RGB_PAD_CTRL),
393 IOMUX_PAD_CTRL(DISP0_DAT2__IPU1_DISP0_DATA02, RGB_PAD_CTRL),
394 IOMUX_PAD_CTRL(DISP0_DAT3__IPU1_DISP0_DATA03, RGB_PAD_CTRL),
395 IOMUX_PAD_CTRL(DISP0_DAT4__IPU1_DISP0_DATA04, RGB_PAD_CTRL),
396 IOMUX_PAD_CTRL(DISP0_DAT5__IPU1_DISP0_DATA05, RGB_PAD_CTRL),
397 IOMUX_PAD_CTRL(DISP0_DAT6__IPU1_DISP0_DATA06, RGB_PAD_CTRL),
398 IOMUX_PAD_CTRL(DISP0_DAT7__IPU1_DISP0_DATA07, RGB_PAD_CTRL),
399 IOMUX_PAD_CTRL(DISP0_DAT8__IPU1_DISP0_DATA08, RGB_PAD_CTRL),
400 IOMUX_PAD_CTRL(DISP0_DAT9__IPU1_DISP0_DATA09, RGB_PAD_CTRL),
401 IOMUX_PAD_CTRL(DISP0_DAT10__IPU1_DISP0_DATA10, RGB_PAD_CTRL),
402 IOMUX_PAD_CTRL(DISP0_DAT11__IPU1_DISP0_DATA11, RGB_PAD_CTRL),
403 IOMUX_PAD_CTRL(DISP0_DAT12__IPU1_DISP0_DATA12, RGB_PAD_CTRL),
404 IOMUX_PAD_CTRL(DISP0_DAT13__IPU1_DISP0_DATA13, RGB_PAD_CTRL),
405 IOMUX_PAD_CTRL(DISP0_DAT14__IPU1_DISP0_DATA14, RGB_PAD_CTRL),
406 IOMUX_PAD_CTRL(DISP0_DAT15__IPU1_DISP0_DATA15, RGB_PAD_CTRL),
407 IOMUX_PAD_CTRL(DISP0_DAT16__IPU1_DISP0_DATA16, RGB_PAD_CTRL),
408 IOMUX_PAD_CTRL(DISP0_DAT17__IPU1_DISP0_DATA17, RGB_PAD_CTRL),
409 IOMUX_PAD_CTRL(DISP0_DAT18__IPU1_DISP0_DATA18, RGB_PAD_CTRL),
410 IOMUX_PAD_CTRL(DISP0_DAT19__IPU1_DISP0_DATA19, RGB_PAD_CTRL),
411 IOMUX_PAD_CTRL(DISP0_DAT20__IPU1_DISP0_DATA20, RGB_PAD_CTRL),
412 IOMUX_PAD_CTRL(DISP0_DAT21__IPU1_DISP0_DATA21, RGB_PAD_CTRL),
413 IOMUX_PAD_CTRL(DISP0_DAT22__IPU1_DISP0_DATA22, RGB_PAD_CTRL),
414 IOMUX_PAD_CTRL(DISP0_DAT23__IPU1_DISP0_DATA23, RGB_PAD_CTRL),
Eric Nelsond67b0d92013-03-11 08:44:53 +0000415};
416
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500417static void do_enable_hdmi(struct display_info_t const *dev)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000418{
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500419 imx_enable_hdmi_phy();
Eric Nelsond67b0d92013-03-11 08:44:53 +0000420}
421
422static int detect_i2c(struct display_info_t const *dev)
423{
424 return ((0 == i2c_set_bus_num(dev->bus))
425 &&
426 (0 == i2c_probe(dev->addr)));
427}
428
429static void enable_lvds(struct display_info_t const *dev)
430{
431 struct iomuxc *iomux = (struct iomuxc *)
432 IOMUXC_BASE_ADDR;
433 u32 reg = readl(&iomux->gpr[2]);
434 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
435 writel(reg, &iomux->gpr[2]);
436 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
437}
438
Robert Winkler4328fb02014-10-02 12:16:31 -0700439static void enable_lvds_jeida(struct display_info_t const *dev)
440{
441 struct iomuxc *iomux = (struct iomuxc *)
442 IOMUXC_BASE_ADDR;
443 u32 reg = readl(&iomux->gpr[2]);
444 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT
445 |IOMUXC_GPR2_BIT_MAPPING_CH0_JEIDA;
446 writel(reg, &iomux->gpr[2]);
447 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
448}
449
Eric Nelsond67b0d92013-03-11 08:44:53 +0000450static void enable_rgb(struct display_info_t const *dev)
451{
Troy Kiskyc30c3602019-11-03 18:20:04 -0800452 SETUP_IOMUX_PADS(rgb_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000453 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
454}
455
Eric Benarda47e4492014-04-04 19:05:53 +0200456struct display_info_t const displays[] = {{
Eric Nelsonce9507b2014-10-02 12:16:39 -0700457 .bus = 1,
458 .addr = 0x50,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000459 .pixfmt = IPU_PIX_FMT_RGB24,
Eric Nelsonce9507b2014-10-02 12:16:39 -0700460 .detect = detect_i2c,
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500461 .enable = do_enable_hdmi,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000462 .mode = {
463 .name = "HDMI",
464 .refresh = 60,
465 .xres = 1024,
466 .yres = 768,
467 .pixclock = 15385,
468 .left_margin = 220,
469 .right_margin = 40,
470 .upper_margin = 21,
471 .lower_margin = 7,
472 .hsync_len = 60,
473 .vsync_len = 10,
474 .sync = FB_SYNC_EXT,
475 .vmode = FB_VMODE_NONINTERLACED
476} }, {
Robert Winkler4328fb02014-10-02 12:16:31 -0700477 .bus = 0,
478 .addr = 0,
479 .pixfmt = IPU_PIX_FMT_RGB24,
480 .detect = NULL,
481 .enable = enable_lvds_jeida,
482 .mode = {
483 .name = "LDB-WXGA",
484 .refresh = 60,
485 .xres = 1280,
486 .yres = 800,
487 .pixclock = 14065,
488 .left_margin = 40,
489 .right_margin = 40,
490 .upper_margin = 3,
491 .lower_margin = 80,
492 .hsync_len = 10,
493 .vsync_len = 10,
494 .sync = FB_SYNC_EXT,
495 .vmode = FB_VMODE_NONINTERLACED
496} }, {
Eric Nelsond6949e32014-10-02 12:16:34 -0700497 .bus = 0,
498 .addr = 0,
499 .pixfmt = IPU_PIX_FMT_RGB24,
500 .detect = NULL,
501 .enable = enable_lvds,
502 .mode = {
503 .name = "LDB-WXGA-S",
504 .refresh = 60,
505 .xres = 1280,
506 .yres = 800,
507 .pixclock = 14065,
508 .left_margin = 40,
509 .right_margin = 40,
510 .upper_margin = 3,
511 .lower_margin = 80,
512 .hsync_len = 10,
513 .vsync_len = 10,
514 .sync = FB_SYNC_EXT,
515 .vmode = FB_VMODE_NONINTERLACED
516} }, {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000517 .bus = 2,
518 .addr = 0x4,
519 .pixfmt = IPU_PIX_FMT_LVDS666,
520 .detect = detect_i2c,
521 .enable = enable_lvds,
522 .mode = {
523 .name = "Hannstar-XGA",
524 .refresh = 60,
525 .xres = 1024,
526 .yres = 768,
527 .pixclock = 15385,
528 .left_margin = 220,
529 .right_margin = 40,
530 .upper_margin = 21,
531 .lower_margin = 7,
532 .hsync_len = 60,
533 .vsync_len = 10,
534 .sync = FB_SYNC_EXT,
535 .vmode = FB_VMODE_NONINTERLACED
536} }, {
Eric Nelson4adc1122014-10-02 12:16:33 -0700537 .bus = 0,
538 .addr = 0,
539 .pixfmt = IPU_PIX_FMT_LVDS666,
540 .detect = NULL,
541 .enable = enable_lvds,
542 .mode = {
543 .name = "LG-9.7",
544 .refresh = 60,
545 .xres = 1024,
546 .yres = 768,
547 .pixclock = 15385, /* ~65MHz */
548 .left_margin = 480,
549 .right_margin = 260,
550 .upper_margin = 16,
551 .lower_margin = 6,
552 .hsync_len = 250,
553 .vsync_len = 10,
554 .sync = FB_SYNC_EXT,
555 .vmode = FB_VMODE_NONINTERLACED
556} }, {
Eric Nelsond67b0d92013-03-11 08:44:53 +0000557 .bus = 2,
558 .addr = 0x38,
559 .pixfmt = IPU_PIX_FMT_LVDS666,
560 .detect = detect_i2c,
561 .enable = enable_lvds,
562 .mode = {
563 .name = "wsvga-lvds",
564 .refresh = 60,
565 .xres = 1024,
566 .yres = 600,
567 .pixclock = 15385,
568 .left_margin = 220,
569 .right_margin = 40,
570 .upper_margin = 21,
571 .lower_margin = 7,
572 .hsync_len = 60,
573 .vsync_len = 10,
574 .sync = FB_SYNC_EXT,
575 .vmode = FB_VMODE_NONINTERLACED
576} }, {
577 .bus = 2,
Eric Nelson04edda22014-10-02 12:16:35 -0700578 .addr = 0x10,
579 .pixfmt = IPU_PIX_FMT_RGB666,
580 .detect = detect_i2c,
581 .enable = enable_rgb,
582 .mode = {
583 .name = "fusion7",
584 .refresh = 60,
585 .xres = 800,
586 .yres = 480,
587 .pixclock = 33898,
588 .left_margin = 96,
589 .right_margin = 24,
590 .upper_margin = 3,
591 .lower_margin = 10,
592 .hsync_len = 72,
593 .vsync_len = 7,
594 .sync = 0x40000002,
595 .vmode = FB_VMODE_NONINTERLACED
596} }, {
Eric Nelson13566302014-10-02 12:16:36 -0700597 .bus = 0,
598 .addr = 0,
599 .pixfmt = IPU_PIX_FMT_RGB666,
600 .detect = NULL,
601 .enable = enable_rgb,
602 .mode = {
603 .name = "svga",
604 .refresh = 60,
605 .xres = 800,
606 .yres = 600,
607 .pixclock = 15385,
608 .left_margin = 220,
609 .right_margin = 40,
610 .upper_margin = 21,
611 .lower_margin = 7,
612 .hsync_len = 60,
613 .vsync_len = 10,
614 .sync = 0,
615 .vmode = FB_VMODE_NONINTERLACED
616} }, {
Eric Nelson04edda22014-10-02 12:16:35 -0700617 .bus = 2,
Eric Nelson865aa302014-10-02 12:16:37 -0700618 .addr = 0x41,
619 .pixfmt = IPU_PIX_FMT_LVDS666,
620 .detect = detect_i2c,
621 .enable = enable_lvds,
622 .mode = {
623 .name = "amp1024x600",
624 .refresh = 60,
625 .xres = 1024,
626 .yres = 600,
627 .pixclock = 15385,
628 .left_margin = 220,
629 .right_margin = 40,
630 .upper_margin = 21,
631 .lower_margin = 7,
632 .hsync_len = 60,
633 .vsync_len = 10,
634 .sync = FB_SYNC_EXT,
635 .vmode = FB_VMODE_NONINTERLACED
636} }, {
Eric Nelsonc745de72014-10-02 12:16:38 -0700637 .bus = 0,
638 .addr = 0,
639 .pixfmt = IPU_PIX_FMT_LVDS666,
640 .detect = 0,
641 .enable = enable_lvds,
642 .mode = {
643 .name = "wvga-lvds",
644 .refresh = 57,
645 .xres = 800,
646 .yres = 480,
647 .pixclock = 15385,
648 .left_margin = 220,
649 .right_margin = 40,
650 .upper_margin = 21,
651 .lower_margin = 7,
652 .hsync_len = 60,
653 .vsync_len = 10,
654 .sync = FB_SYNC_EXT,
655 .vmode = FB_VMODE_NONINTERLACED
656} }, {
Eric Nelson865aa302014-10-02 12:16:37 -0700657 .bus = 2,
Eric Nelsond67b0d92013-03-11 08:44:53 +0000658 .addr = 0x48,
659 .pixfmt = IPU_PIX_FMT_RGB666,
660 .detect = detect_i2c,
661 .enable = enable_rgb,
662 .mode = {
663 .name = "wvga-rgb",
664 .refresh = 57,
665 .xres = 800,
666 .yres = 480,
667 .pixclock = 37037,
668 .left_margin = 40,
669 .right_margin = 60,
670 .upper_margin = 10,
671 .lower_margin = 10,
672 .hsync_len = 20,
673 .vsync_len = 10,
674 .sync = 0,
675 .vmode = FB_VMODE_NONINTERLACED
Eric Nelson443d4d12014-10-02 12:16:32 -0700676} }, {
677 .bus = 0,
678 .addr = 0,
679 .pixfmt = IPU_PIX_FMT_RGB24,
680 .detect = NULL,
681 .enable = enable_rgb,
682 .mode = {
683 .name = "qvga",
684 .refresh = 60,
685 .xres = 320,
686 .yres = 240,
687 .pixclock = 37037,
688 .left_margin = 38,
689 .right_margin = 37,
690 .upper_margin = 16,
691 .lower_margin = 15,
692 .hsync_len = 30,
693 .vsync_len = 3,
694 .sync = 0,
695 .vmode = FB_VMODE_NONINTERLACED
Eric Nelsond67b0d92013-03-11 08:44:53 +0000696} } };
Eric Benarda47e4492014-04-04 19:05:53 +0200697size_t display_count = ARRAY_SIZE(displays);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000698
Eric Nelsonc9c86bd2014-10-02 12:16:22 -0700699int board_cfb_skip(void)
700{
Simon Glass00caae62017-08-03 12:22:12 -0600701 return NULL != env_get("novideo");
Eric Nelsonc9c86bd2014-10-02 12:16:22 -0700702}
703
Eric Nelsond67b0d92013-03-11 08:44:53 +0000704static void setup_display(void)
705{
706 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000707 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000708 int reg;
709
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500710 enable_ipu_clock();
711 imx_setup_hdmi();
Eric Nelsond67b0d92013-03-11 08:44:53 +0000712 /* Turn on LDB0,IPU,IPU DI0 clocks */
713 reg = __raw_readl(&mxc_ccm->CCGR3);
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500714 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
Eric Nelsond67b0d92013-03-11 08:44:53 +0000715 writel(reg, &mxc_ccm->CCGR3);
716
Eric Nelsond67b0d92013-03-11 08:44:53 +0000717 /* set LDB0, LDB1 clk select to 011/011 */
718 reg = readl(&mxc_ccm->cs2cdr);
719 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
720 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
721 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
722 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
723 writel(reg, &mxc_ccm->cs2cdr);
724
725 reg = readl(&mxc_ccm->cscmr2);
726 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
727 writel(reg, &mxc_ccm->cscmr2);
728
729 reg = readl(&mxc_ccm->chsccdr);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000730 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500731 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000732 writel(reg, &mxc_ccm->chsccdr);
733
734 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
735 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
736 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
737 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
738 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
739 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
740 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
741 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
742 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
743 writel(reg, &iomux->gpr[2]);
744
745 reg = readl(&iomux->gpr[3]);
Eric Nelson8907c2c2013-08-20 11:44:43 -0700746 reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK
747 |IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
Eric Nelsond67b0d92013-03-11 08:44:53 +0000748 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
749 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
750 writel(reg, &iomux->gpr[3]);
751
752 /* backlights off until needed */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800753 SETUP_IOMUX_PADS(backlight_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000754 gpio_direction_input(LVDS_BACKLIGHT_GP);
755 gpio_direction_input(RGB_BACKLIGHT_GP);
756}
757#endif
758
Eric Nelsona3b527a2014-10-02 12:16:25 -0700759static iomux_v3_cfg_t const init_pads[] = {
Troy Kisky693cccf2014-10-02 12:16:26 -0700760 /* SGTL5000 sys_mclk */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800761 IOMUX_PAD_CTRL(GPIO_0__CCM_CLKO1, OUTPUT_40OHM),
Troy Kisky693cccf2014-10-02 12:16:26 -0700762
763 /* J5 - Camera MCLK */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800764 IOMUX_PAD_CTRL(GPIO_3__CCM_CLKO2, OUTPUT_40OHM),
Troy Kisky693cccf2014-10-02 12:16:26 -0700765
766 /* wl1271 pads on nitrogen6x */
Eric Nelsona3b527a2014-10-02 12:16:25 -0700767 /* WL12XX_WL_IRQ_GP */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800768 IOMUX_PAD_CTRL(NANDF_CS1__GPIO6_IO14, WEAK_PULLDOWN),
Eric Nelsona3b527a2014-10-02 12:16:25 -0700769 /* WL12XX_WL_ENABLE_GP */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800770 IOMUX_PAD_CTRL(NANDF_CS2__GPIO6_IO15, OUTPUT_40OHM),
Eric Nelsona3b527a2014-10-02 12:16:25 -0700771 /* WL12XX_BT_ENABLE_GP */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800772 IOMUX_PAD_CTRL(NANDF_CS3__GPIO6_IO16, OUTPUT_40OHM),
Eric Nelsona3b527a2014-10-02 12:16:25 -0700773 /* USB otg power */
Troy Kiskyc30c3602019-11-03 18:20:04 -0800774 IOMUX_PAD_CTRL(EIM_D22__GPIO3_IO22, OUTPUT_40OHM),
775 IOMUX_PAD_CTRL(NANDF_D5__GPIO2_IO05, OUTPUT_40OHM),
776 IOMUX_PAD_CTRL(NANDF_WP_B__GPIO6_IO09, OUTPUT_40OHM),
777 IOMUX_PAD_CTRL(GPIO_8__GPIO1_IO08, OUTPUT_40OHM),
778 IOMUX_PAD_CTRL(GPIO_6__GPIO1_IO06, OUTPUT_40OHM),
Eric Nelsona3b527a2014-10-02 12:16:25 -0700779};
780
781#define WL12XX_WL_IRQ_GP IMX_GPIO_NR(6, 14)
782
783static unsigned gpios_out_low[] = {
784 /* Disable wl1271 */
785 IMX_GPIO_NR(6, 15), /* disable wireless */
786 IMX_GPIO_NR(6, 16), /* disable bluetooth */
787 IMX_GPIO_NR(3, 22), /* disable USB otg power */
788 IMX_GPIO_NR(2, 5), /* ov5640 mipi camera reset */
789 IMX_GPIO_NR(1, 8), /* ov5642 reset */
790};
791
792static unsigned gpios_out_high[] = {
793 IMX_GPIO_NR(1, 6), /* ov5642 powerdown */
794 IMX_GPIO_NR(6, 9), /* ov5640 mipi camera power down */
795};
796
797static void set_gpios(unsigned *p, int cnt, int val)
798{
799 int i;
800
801 for (i = 0; i < cnt; i++)
802 gpio_direction_output(*p++, val);
803}
804
Eric Nelsond67b0d92013-03-11 08:44:53 +0000805int board_early_init_f(void)
806{
807 setup_iomux_uart();
808
Eric Nelsona3b527a2014-10-02 12:16:25 -0700809 set_gpios(gpios_out_high, ARRAY_SIZE(gpios_out_high), 1);
810 set_gpios(gpios_out_low, ARRAY_SIZE(gpios_out_low), 0);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000811 gpio_direction_input(WL12XX_WL_IRQ_GP);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000812
Troy Kiskyc30c3602019-11-03 18:20:04 -0800813 SETUP_IOMUX_PADS(wl12xx_pads);
814 SETUP_IOMUX_PADS(init_pads);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000815 setup_buttons();
816
817#if defined(CONFIG_VIDEO_IPUV3)
818 setup_display();
819#endif
820 return 0;
821}
822
823/*
824 * Do not overwrite the console
825 * Use always serial for U-Boot console
826 */
827int overwrite_console(void)
828{
829 return 1;
830}
831
832int board_init(void)
833{
Fabio Estevam0a11d6f2014-07-09 17:59:54 -0300834 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Troy Kiskyc30c3602019-11-03 18:20:04 -0800835 struct i2c_pads_info *p = i2c_pads;
836 int i;
837 int stride = 1;
Troy Kisky71328692013-09-25 18:41:16 -0700838
Troy Kiskyc30c3602019-11-03 18:20:04 -0800839#if defined(CONFIG_MX6QDL)
840 stride = 2;
841 if (!is_mx6dq() && !is_mx6dqp())
842 p += 1;
843#endif
Troy Kisky71328692013-09-25 18:41:16 -0700844 clrsetbits_le32(&iomuxc_regs->gpr[1],
845 IOMUXC_GPR1_OTG_ID_MASK,
846 IOMUXC_GPR1_OTG_ID_GPIO1);
847
Troy Kiskyc30c3602019-11-03 18:20:04 -0800848 SETUP_IOMUX_PADS(misc_pads);
Troy Kisky08ce0742013-09-25 18:41:17 -0700849
Eric Nelsond67b0d92013-03-11 08:44:53 +0000850 /* address of boot parameters */
851 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
852
853#ifdef CONFIG_MXC_SPI
854 setup_spi();
855#endif
Troy Kiskyc30c3602019-11-03 18:20:04 -0800856 SETUP_IOMUX_PADS(usdhc2_pads);
857 for (i = 0; i < I2C_BUS_CNT; i++) {
858 setup_i2c(i, CONFIG_SYS_I2C_SPEED, 0x7f, p);
859 p += stride;
860 }
Eric Nelsond67b0d92013-03-11 08:44:53 +0000861
Simon Glass10e40d52017-06-14 21:28:25 -0600862#ifdef CONFIG_SATA
Eric Nelsond67b0d92013-03-11 08:44:53 +0000863 setup_sata();
864#endif
865
866 return 0;
867}
868
869int checkboard(void)
870{
Troy Kisky1b51e5f2019-07-29 12:15:56 -0700871 int ret = gpio_get_value(WL12XX_WL_IRQ_GP);
872
873 if (ret < 0) {
874 /* The gpios have not been probed yet. Read it myself */
875 struct gpio_regs *regs = (struct gpio_regs *)GPIO6_BASE_ADDR;
876 int gpio = WL12XX_WL_IRQ_GP & 0x1f;
877
878 ret = (readl(&regs->gpio_psr) >> gpio) & 0x01;
879 }
880 if (ret)
Eric Nelsond67b0d92013-03-11 08:44:53 +0000881 puts("Board: Nitrogen6X\n");
882 else
883 puts("Board: SABRE Lite\n");
884
885 return 0;
886}
887
888struct button_key {
889 char const *name;
890 unsigned gpnum;
891 char ident;
892};
893
894static struct button_key const buttons[] = {
895 {"back", IMX_GPIO_NR(2, 2), 'B'},
896 {"home", IMX_GPIO_NR(2, 4), 'H'},
897 {"menu", IMX_GPIO_NR(2, 1), 'M'},
898 {"search", IMX_GPIO_NR(2, 3), 'S'},
899 {"volup", IMX_GPIO_NR(7, 13), 'V'},
900 {"voldown", IMX_GPIO_NR(4, 5), 'v'},
901};
902
903/*
904 * generate a null-terminated string containing the buttons pressed
905 * returns number of keys pressed
906 */
907static int read_keys(char *buf)
908{
909 int i, numpressed = 0;
910 for (i = 0; i < ARRAY_SIZE(buttons); i++) {
911 if (!gpio_get_value(buttons[i].gpnum))
912 buf[numpressed++] = buttons[i].ident;
913 }
914 buf[numpressed] = '\0';
915 return numpressed;
916}
917
Simon Glass09140112020-05-10 11:40:03 -0600918static int do_kbd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Eric Nelsond67b0d92013-03-11 08:44:53 +0000919{
920 char envvalue[ARRAY_SIZE(buttons)+1];
921 int numpressed = read_keys(envvalue);
Simon Glass382bee52017-08-03 12:22:09 -0600922 env_set("keybd", envvalue);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000923 return numpressed == 0;
924}
925
926U_BOOT_CMD(
927 kbd, 1, 1, do_kbd,
928 "Tests for keypresses, sets 'keybd' environment variable",
929 "Returns 0 (true) to shell if key is pressed."
930);
931
Pali Rohár2827c2f2022-07-10 13:42:55 +0200932#ifdef CONFIG_USE_PREBOOT
Eric Nelsond67b0d92013-03-11 08:44:53 +0000933static char const kbd_magic_prefix[] = "key_magic";
934static char const kbd_command_prefix[] = "key_cmd";
935
936static void preboot_keys(void)
937{
938 int numpressed;
939 char keypress[ARRAY_SIZE(buttons)+1];
940 numpressed = read_keys(keypress);
941 if (numpressed) {
Simon Glass00caae62017-08-03 12:22:12 -0600942 char *kbd_magic_keys = env_get("magic_keys");
Eric Nelsond67b0d92013-03-11 08:44:53 +0000943 char *suffix;
944 /*
945 * loop over all magic keys
946 */
947 for (suffix = kbd_magic_keys; *suffix; ++suffix) {
948 char *keys;
949 char magic[sizeof(kbd_magic_prefix) + 1];
950 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
Simon Glass00caae62017-08-03 12:22:12 -0600951 keys = env_get(magic);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000952 if (keys) {
953 if (!strcmp(keys, keypress))
954 break;
955 }
956 }
957 if (*suffix) {
958 char cmd_name[sizeof(kbd_command_prefix) + 1];
959 char *cmd;
960 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
Simon Glass00caae62017-08-03 12:22:12 -0600961 cmd = env_get(cmd_name);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000962 if (cmd) {
Simon Glass382bee52017-08-03 12:22:09 -0600963 env_set("preboot", cmd);
Eric Nelsond67b0d92013-03-11 08:44:53 +0000964 return;
965 }
966 }
967 }
968}
969#endif
970
971#ifdef CONFIG_CMD_BMODE
972static const struct boot_mode board_boot_modes[] = {
973 /* 4 bit bus width */
974 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
975 {"mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
976 {NULL, 0},
977};
978#endif
979
980int misc_init_r(void)
981{
Troy Kisky1b51e5f2019-07-29 12:15:56 -0700982 gpio_request(RGB_BACKLIGHT_GP, "lvds backlight");
983 gpio_request(LVDS_BACKLIGHT_GP, "lvds backlight");
984 gpio_request(GP_USB_OTG_PWR, "usbotg power");
985 gpio_request(IMX_GPIO_NR(7, 12), "usbh1 hub reset");
986 gpio_request(IMX_GPIO_NR(2, 2), "back");
987 gpio_request(IMX_GPIO_NR(2, 4), "home");
988 gpio_request(IMX_GPIO_NR(2, 1), "menu");
989 gpio_request(IMX_GPIO_NR(2, 3), "search");
990 gpio_request(IMX_GPIO_NR(7, 13), "volup");
991 gpio_request(IMX_GPIO_NR(4, 5), "voldown");
Pali Rohár2827c2f2022-07-10 13:42:55 +0200992#ifdef CONFIG_USE_PREBOOT
Eric Nelsond67b0d92013-03-11 08:44:53 +0000993 preboot_keys();
994#endif
995
996#ifdef CONFIG_CMD_BMODE
997 add_board_boot_modes(board_boot_modes);
998#endif
Simon Glass018f5302017-08-03 12:22:10 -0600999 env_set_hex("reset_cause", get_imx_reset_cause());
Eric Nelsond67b0d92013-03-11 08:44:53 +00001000 return 0;
1001}