blob: 74d7a17028b3b77848cdd32f0a112b2e27dc4303 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevame2d282a2013-03-15 10:43:48 +00002/*
3 * Copyright (C) 2013 Freescale Semiconductor, Inc.
Otavio Salvador8bc7c482014-05-01 19:02:31 -03004 * Copyright (C) 2014 O.S. Systems Software LTDA.
Fabio Estevame2d282a2013-03-15 10:43:48 +00005 *
6 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevame2d282a2013-03-15 10:43:48 +00007 */
8
9#include <asm/arch/clock.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000010#include <asm/arch/crm_regs.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000011#include <asm/arch/iomux.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/mx6-pins.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000014#include <asm/arch/mxc_hdmi.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020017#include <asm/mach-imx/iomux-v3.h>
18#include <asm/mach-imx/mxc_i2c.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/video.h>
21#include <asm/mach-imx/sata.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000022#include <asm/io.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040023#include <linux/sizes.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000024#include <common.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000025#include <miiphy.h>
26#include <netdev.h>
Fabio Estevam2fb63962014-02-15 14:52:00 -020027#include <phy.h>
Otavio Salvador8bc7c482014-05-01 19:02:31 -030028#include <i2c.h>
Fabio Estevam066d97c2017-10-02 15:47:29 -030029#include <power/pmic.h>
30#include <power/pfuze100_pmic.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000031
32DECLARE_GLOBAL_DATA_PTR;
33
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000034#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
35 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
36 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevame2d282a2013-03-15 10:43:48 +000037
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000038#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
39 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevame2d282a2013-03-15 10:43:48 +000040
Otavio Salvador8bc7c482014-05-01 19:02:31 -030041#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
42 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
43 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
44
Fabio Estevame2d282a2013-03-15 10:43:48 +000045#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
Fabio Estevam066d97c2017-10-02 15:47:29 -030046#define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13)
Fabio Estevam9a8804a2015-05-21 19:24:05 -030047#define REV_DETECTION IMX_GPIO_NR(2, 28)
Fabio Estevame2d282a2013-03-15 10:43:48 +000048
Trent Piephod1337212019-05-08 23:30:01 +000049/* Speed defined in Kconfig is only applicable when not using DM_I2C. */
50#ifdef CONFIG_DM_I2C
51#define I2C1_SPEED_NON_DM 0
52#define I2C2_SPEED_NON_DM 0
53#else
54#define I2C1_SPEED_NON_DM CONFIG_SYS_MXC_I2C1_SPEED
55#define I2C2_SPEED_NON_DM CONFIG_SYS_MXC_I2C2_SPEED
56#endif
57
Fabio Estevam066d97c2017-10-02 15:47:29 -030058static bool with_pmic;
59
Fabio Estevame2d282a2013-03-15 10:43:48 +000060int dram_init(void)
61{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030062 gd->ram_size = imx_ddr_size();
Fabio Estevame2d282a2013-03-15 10:43:48 +000063
64 return 0;
65}
66
67static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -030068 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
69 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000070};
71
Fabio Estevame2d282a2013-03-15 10:43:48 +000072static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -030073 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
83 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
85 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
86 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
87 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000088 /* AR8031 PHY Reset */
Fabio Estevam0d1ea052015-05-11 20:50:22 -030089 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000090};
91
Fabio Estevam066d97c2017-10-02 15:47:29 -030092static iomux_v3_cfg_t const enet_ar8035_power_pads[] = {
93 /* AR8035 POWER */
94 IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
95};
96
Fabio Estevam9a8804a2015-05-21 19:24:05 -030097static iomux_v3_cfg_t const rev_detection_pad[] = {
98 IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
99};
100
Fabio Estevame2d282a2013-03-15 10:43:48 +0000101static void setup_iomux_uart(void)
102{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300103 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000104}
105
106static void setup_iomux_enet(void)
107{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300108 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000109
Fabio Estevam066d97c2017-10-02 15:47:29 -0300110 if (with_pmic) {
111 SETUP_IOMUX_PADS(enet_ar8035_power_pads);
112 /* enable AR8035 POWER */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100113 gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER");
Fabio Estevam066d97c2017-10-02 15:47:29 -0300114 gpio_direction_output(ETH_PHY_AR8035_POWER, 0);
115 }
116 /* wait until 3.3V of PHY and clock become stable */
117 mdelay(10);
118
Fabio Estevame2d282a2013-03-15 10:43:48 +0000119 /* Reset AR8031 PHY */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100120 gpio_request(ETH_PHY_RESET, "PHY_RESET");
Fabio Estevame2d282a2013-03-15 10:43:48 +0000121 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200122 mdelay(10);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000123 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200124 udelay(100);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000125}
126
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200127static int ar8031_phy_fixup(struct phy_device *phydev)
128{
129 unsigned short val;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300130 int mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200131
132 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
133 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
134 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
135 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
136
137 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300138 if (with_pmic)
139 mask = 0xffe7; /* AR8035 */
140 else
141 mask = 0xffe3; /* AR8031 */
142
143 val &= mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200144 val |= 0x18;
145 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
146
147 /* introduce tx clock delay */
148 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
149 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
150 val |= 0x0100;
151 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
152
153 return 0;
154}
155
156int board_phy_config(struct phy_device *phydev)
157{
158 ar8031_phy_fixup(phydev);
159
160 if (phydev->drv->config)
161 phydev->drv->config(phydev);
162
163 return 0;
164}
165
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000166#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300167struct i2c_pads_info mx6q_i2c2_pad_info = {
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300168 .scl = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300169 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300170 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300171 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300172 | MUX_PAD_CTRL(I2C_PAD_CTRL),
173 .gp = IMX_GPIO_NR(4, 12)
174 },
175 .sda = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300176 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300177 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300178 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13
179 | MUX_PAD_CTRL(I2C_PAD_CTRL),
180 .gp = IMX_GPIO_NR(4, 13)
181 }
182};
183
184struct i2c_pads_info mx6dl_i2c2_pad_info = {
185 .scl = {
186 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL
187 | MUX_PAD_CTRL(I2C_PAD_CTRL),
188 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12
189 | MUX_PAD_CTRL(I2C_PAD_CTRL),
190 .gp = IMX_GPIO_NR(4, 12)
191 },
192 .sda = {
193 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA
194 | MUX_PAD_CTRL(I2C_PAD_CTRL),
195 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300196 | MUX_PAD_CTRL(I2C_PAD_CTRL),
197 .gp = IMX_GPIO_NR(4, 13)
198 }
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000199};
200
Fabio Estevam066d97c2017-10-02 15:47:29 -0300201struct i2c_pads_info mx6q_i2c3_pad_info = {
202 .scl = {
203 .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL
204 | MUX_PAD_CTRL(I2C_PAD_CTRL),
205 .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05
206 | MUX_PAD_CTRL(I2C_PAD_CTRL),
207 .gp = IMX_GPIO_NR(1, 5)
208 },
209 .sda = {
210 .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA
211 | MUX_PAD_CTRL(I2C_PAD_CTRL),
212 .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11
213 | MUX_PAD_CTRL(I2C_PAD_CTRL),
214 .gp = IMX_GPIO_NR(7, 11)
215 }
216};
217
218struct i2c_pads_info mx6dl_i2c3_pad_info = {
219 .scl = {
220 .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL
221 | MUX_PAD_CTRL(I2C_PAD_CTRL),
222 .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05
223 | MUX_PAD_CTRL(I2C_PAD_CTRL),
224 .gp = IMX_GPIO_NR(1, 5)
225 },
226 .sda = {
227 .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA
228 | MUX_PAD_CTRL(I2C_PAD_CTRL),
229 .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11
230 | MUX_PAD_CTRL(I2C_PAD_CTRL),
231 .gp = IMX_GPIO_NR(7, 11)
232 }
233};
234
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300235static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300236 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
237 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */
238 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */
239 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */
240 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */
241 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
242 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
243 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
244 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
245 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
246 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
247 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
248 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
249 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
250 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
251 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
252 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
253 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
254 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
255 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
256 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
257 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
258 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
259 IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */
260 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300261};
262
263static void do_enable_hdmi(struct display_info_t const *dev)
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000264{
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500265 imx_enable_hdmi_phy();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000266}
267
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300268static int detect_i2c(struct display_info_t const *dev)
269{
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100270#ifdef CONFIG_DM_I2C
271 struct udevice *bus, *udev;
272 int rc;
273
274 rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus);
275 if (rc)
276 return rc;
277 rc = dm_i2c_probe(bus, dev->addr, 0, &udev);
278 if (rc)
279 return 0;
280 return 1;
281#else
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300282 return (0 == i2c_set_bus_num(dev->bus)) &&
283 (0 == i2c_probe(dev->addr));
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100284#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300285}
286
287static void enable_fwadapt_7wvga(struct display_info_t const *dev)
288{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300289 SETUP_IOMUX_PADS(fwadapt_7wvga_pads);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300290
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100291 gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN");
292 gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300293 gpio_direction_output(IMX_GPIO_NR(2, 10), 1);
294 gpio_direction_output(IMX_GPIO_NR(2, 11), 1);
295}
296
297struct display_info_t const displays[] = {{
298 .bus = -1,
299 .addr = 0,
300 .pixfmt = IPU_PIX_FMT_RGB24,
301 .detect = detect_hdmi,
302 .enable = do_enable_hdmi,
303 .mode = {
304 .name = "HDMI",
305 .refresh = 60,
306 .xres = 1024,
307 .yres = 768,
308 .pixclock = 15385,
309 .left_margin = 220,
310 .right_margin = 40,
311 .upper_margin = 21,
312 .lower_margin = 7,
313 .hsync_len = 60,
314 .vsync_len = 10,
315 .sync = FB_SYNC_EXT,
316 .vmode = FB_VMODE_NONINTERLACED
317} }, {
318 .bus = 1,
319 .addr = 0x10,
320 .pixfmt = IPU_PIX_FMT_RGB666,
321 .detect = detect_i2c,
322 .enable = enable_fwadapt_7wvga,
323 .mode = {
324 .name = "FWBADAPT-LCD-F07A-0102",
325 .refresh = 60,
326 .xres = 800,
327 .yres = 480,
328 .pixclock = 33260,
329 .left_margin = 128,
330 .right_margin = 128,
331 .upper_margin = 22,
332 .lower_margin = 22,
333 .hsync_len = 1,
334 .vsync_len = 1,
335 .sync = 0,
336 .vmode = FB_VMODE_NONINTERLACED
337} } };
338size_t display_count = ARRAY_SIZE(displays);
339
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000340static void setup_display(void)
341{
342 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000343 int reg;
344
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500345 enable_ipu_clock();
346 imx_setup_hdmi();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000347
348 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000349 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500350 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000351 writel(reg, &mxc_ccm->chsccdr);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300352
353 /* Disable LCD backlight */
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300354 SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20);
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100355 gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300356 gpio_direction_input(IMX_GPIO_NR(4, 20));
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000357}
358#endif /* CONFIG_VIDEO_IPUV3 */
359
Fabio Estevame2d282a2013-03-15 10:43:48 +0000360int board_eth_init(bd_t *bis)
361{
Fabio Estevame2d282a2013-03-15 10:43:48 +0000362 setup_iomux_enet();
363
Fabio Estevam14da7592014-01-04 17:36:28 -0200364 return cpu_eth_init(bis);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000365}
366
367int board_early_init_f(void)
368{
369 setup_iomux_uart();
Simon Glass10e40d52017-06-14 21:28:25 -0600370#ifdef CONFIG_SATA
Fabio Estevamd7f7eb72017-10-15 11:21:06 -0200371 setup_sata();
Gilles Chanteperdrixe355eec2016-06-09 10:33:27 +0200372#endif
373
Fabio Estevame2d282a2013-03-15 10:43:48 +0000374 return 0;
375}
376
Fabio Estevam066d97c2017-10-02 15:47:29 -0300377#define PMIC_I2C_BUS 2
378
379int power_init_board(void)
380{
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100381 struct udevice *dev;
382 int reg, ret;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300383
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100384 puts("PMIC: ");
Fabio Estevam066d97c2017-10-02 15:47:29 -0300385
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100386 ret = pmic_get("pfuze100", &dev);
387 if (ret < 0) {
388 printf("pmic_get() ret %d\n", ret);
389 return 0;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300390 }
391
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100392 reg = pmic_reg_read(dev, PFUZE100_DEVICEID);
393 if (reg < 0) {
394 printf("pmic_reg_read() ret %d\n", reg);
395 return 0;
396 }
397 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
398 with_pmic = true;
399
400 /* Set VGEN2 to 1.5V and enable */
401 reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL);
402 reg &= ~(LDO_VOL_MASK);
403 reg |= (LDOA_1_50V | (1 << (LDO_EN)));
404 pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300405 return 0;
406}
407
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000408/*
409 * Do not overwrite the console
410 * Use always serial for U-Boot console
411 */
412int overwrite_console(void)
413{
414 return 1;
415}
416
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000417#ifdef CONFIG_CMD_BMODE
418static const struct boot_mode board_boot_modes[] = {
419 /* 4 bit bus width */
420 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
421 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
422 {NULL, 0},
423};
424#endif
425
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300426static bool is_revc1(void)
427{
428 SETUP_IOMUX_PADS(rev_detection_pad);
429 gpio_direction_input(REV_DETECTION);
430
431 if (gpio_get_value(REV_DETECTION))
432 return true;
433 else
434 return false;
435}
436
Fabio Estevam066d97c2017-10-02 15:47:29 -0300437static bool is_revd1(void)
438{
439 if (with_pmic)
440 return true;
441 else
442 return false;
443}
444
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000445int board_late_init(void)
446{
447#ifdef CONFIG_CMD_BMODE
448 add_board_boot_modes(board_boot_modes);
449#endif
450
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300451#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Fabio Estevame1f07152017-10-14 09:17:54 -0300452 if (is_mx6dqp())
453 env_set("board_rev", "MX6QP");
454 else if (is_mx6dq())
Simon Glass382bee52017-08-03 12:22:09 -0600455 env_set("board_rev", "MX6Q");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300456 else
Simon Glass382bee52017-08-03 12:22:09 -0600457 env_set("board_rev", "MX6DL");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300458
Fabio Estevam066d97c2017-10-02 15:47:29 -0300459 if (is_revd1())
460 env_set("board_name", "D1");
461 else if (is_revc1())
Simon Glass382bee52017-08-03 12:22:09 -0600462 env_set("board_name", "C1");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300463 else
Simon Glass382bee52017-08-03 12:22:09 -0600464 env_set("board_name", "B1");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300465#endif
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000466 return 0;
467}
468
Fabio Estevame2d282a2013-03-15 10:43:48 +0000469int board_init(void)
470{
471 /* address of boot parameters */
472 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
473
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100474#if defined(CONFIG_VIDEO_IPUV3)
Trent Piephod1337212019-05-08 23:30:01 +0000475 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
Fabio Estevame1f07152017-10-14 09:17:54 -0300476 if (is_mx6dq() || is_mx6dqp()) {
Trent Piephod1337212019-05-08 23:30:01 +0000477 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6q_i2c2_pad_info);
478 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6q_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300479 } else {
Trent Piephod1337212019-05-08 23:30:01 +0000480 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
481 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6dl_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300482 }
Fabio Estevam1b853e42017-09-22 23:45:30 -0300483
484 setup_display();
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100485#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300486
Fabio Estevame2d282a2013-03-15 10:43:48 +0000487 return 0;
488}
489
Fabio Estevame2d282a2013-03-15 10:43:48 +0000490int checkboard(void)
491{
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100492 gpio_request(REV_DETECTION, "REV_DETECT");
493
Fabio Estevam066d97c2017-10-02 15:47:29 -0300494 if (is_revd1())
495 puts("Board: Wandboard rev D1\n");
496 else if (is_revc1())
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300497 puts("Board: Wandboard rev C1\n");
498 else
499 puts("Board: Wandboard rev B1\n");
Fabio Estevame2d282a2013-03-15 10:43:48 +0000500
501 return 0;
502}
Fabio Estevam5b858582019-06-12 12:34:40 -0300503
504#ifdef CONFIG_SPL_LOAD_FIT
505int board_fit_config_name_match(const char *name)
506{
507 if (is_mx6dq()) {
508 if (!strcmp(name, "imx6q-wandboard-revb1"))
509 return 0;
510 } else if (is_mx6dqp()) {
511 if (!strcmp(name, "imx6qp-wandboard-revd1"))
512 return 0;
513 } else if (is_mx6dl() || is_mx6solo()) {
514 if (!strcmp(name, "imx6dl-wandboard-revb1"))
515 return 0;
516 }
517
518 return -EINVAL;
519}
520#endif