blob: 9705a1d8e392c97bc48c75ce144670e527d8da12 [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
Simon Glassc3dc39a2020-05-10 11:39:55 -06009#include <common.h>
Simon Glass52559322019-11-14 12:57:46 -070010#include <init.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000011#include <asm/arch/clock.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000012#include <asm/arch/crm_regs.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000013#include <asm/arch/iomux.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/mx6-pins.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000016#include <asm/arch/mxc_hdmi.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000017#include <asm/arch/sys_proto.h>
18#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020019#include <asm/mach-imx/iomux-v3.h>
20#include <asm/mach-imx/mxc_i2c.h>
21#include <asm/mach-imx/boot_mode.h>
22#include <asm/mach-imx/video.h>
23#include <asm/mach-imx/sata.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000024#include <asm/io.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060025#include <env.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040026#include <linux/sizes.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000027#include <common.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000028#include <miiphy.h>
29#include <netdev.h>
Fabio Estevam2fb63962014-02-15 14:52:00 -020030#include <phy.h>
Otavio Salvador8bc7c482014-05-01 19:02:31 -030031#include <i2c.h>
Fabio Estevam066d97c2017-10-02 15:47:29 -030032#include <power/pmic.h>
33#include <power/pfuze100_pmic.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000034
35DECLARE_GLOBAL_DATA_PTR;
36
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)
Fabio Estevame2d282a2013-03-15 10:43:48 +000040
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000041#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
42 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevame2d282a2013-03-15 10:43:48 +000043
Otavio Salvador8bc7c482014-05-01 19:02:31 -030044#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
45 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
46 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
47
Fabio Estevame2d282a2013-03-15 10:43:48 +000048#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
Fabio Estevam066d97c2017-10-02 15:47:29 -030049#define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13)
Fabio Estevam9a8804a2015-05-21 19:24:05 -030050#define REV_DETECTION IMX_GPIO_NR(2, 28)
Fabio Estevame2d282a2013-03-15 10:43:48 +000051
Trent Piephod1337212019-05-08 23:30:01 +000052/* Speed defined in Kconfig is only applicable when not using DM_I2C. */
53#ifdef CONFIG_DM_I2C
54#define I2C1_SPEED_NON_DM 0
55#define I2C2_SPEED_NON_DM 0
56#else
57#define I2C1_SPEED_NON_DM CONFIG_SYS_MXC_I2C1_SPEED
58#define I2C2_SPEED_NON_DM CONFIG_SYS_MXC_I2C2_SPEED
59#endif
60
Fabio Estevam066d97c2017-10-02 15:47:29 -030061static bool with_pmic;
62
Fabio Estevame2d282a2013-03-15 10:43:48 +000063int dram_init(void)
64{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030065 gd->ram_size = imx_ddr_size();
Fabio Estevame2d282a2013-03-15 10:43:48 +000066
67 return 0;
68}
69
70static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -030071 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
72 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000073};
74
Fabio Estevame2d282a2013-03-15 10:43:48 +000075static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevame2d282a2013-03-15 10:43:48 +000076 /* AR8031 PHY Reset */
Fabio Estevam0d1ea052015-05-11 20:50:22 -030077 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000078};
79
Fabio Estevam066d97c2017-10-02 15:47:29 -030080static iomux_v3_cfg_t const enet_ar8035_power_pads[] = {
81 /* AR8035 POWER */
82 IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
83};
84
Fabio Estevam9a8804a2015-05-21 19:24:05 -030085static iomux_v3_cfg_t const rev_detection_pad[] = {
86 IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
87};
88
Fabio Estevame2d282a2013-03-15 10:43:48 +000089static void setup_iomux_uart(void)
90{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030091 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +000092}
93
94static void setup_iomux_enet(void)
95{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030096 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +000097
Fabio Estevam066d97c2017-10-02 15:47:29 -030098 if (with_pmic) {
99 SETUP_IOMUX_PADS(enet_ar8035_power_pads);
100 /* enable AR8035 POWER */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100101 gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER");
Fabio Estevam066d97c2017-10-02 15:47:29 -0300102 gpio_direction_output(ETH_PHY_AR8035_POWER, 0);
103 }
104 /* wait until 3.3V of PHY and clock become stable */
105 mdelay(10);
106
Fabio Estevame2d282a2013-03-15 10:43:48 +0000107 /* Reset AR8031 PHY */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100108 gpio_request(ETH_PHY_RESET, "PHY_RESET");
Fabio Estevame2d282a2013-03-15 10:43:48 +0000109 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200110 mdelay(10);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000111 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200112 udelay(100);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000113}
114
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200115static int ar8031_phy_fixup(struct phy_device *phydev)
116{
117 unsigned short val;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300118 int mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200119
120 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
121 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
122 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
123 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
124
125 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300126 if (with_pmic)
127 mask = 0xffe7; /* AR8035 */
128 else
129 mask = 0xffe3; /* AR8031 */
130
131 val &= mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200132 val |= 0x18;
133 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
134
135 /* introduce tx clock delay */
136 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
137 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
138 val |= 0x0100;
139 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
140
141 return 0;
142}
143
144int board_phy_config(struct phy_device *phydev)
145{
146 ar8031_phy_fixup(phydev);
147
148 if (phydev->drv->config)
149 phydev->drv->config(phydev);
150
151 return 0;
152}
153
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000154#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300155struct i2c_pads_info mx6q_i2c2_pad_info = {
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300156 .scl = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300157 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300158 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300159 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300160 | MUX_PAD_CTRL(I2C_PAD_CTRL),
161 .gp = IMX_GPIO_NR(4, 12)
162 },
163 .sda = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300164 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300165 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300166 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13
167 | MUX_PAD_CTRL(I2C_PAD_CTRL),
168 .gp = IMX_GPIO_NR(4, 13)
169 }
170};
171
172struct i2c_pads_info mx6dl_i2c2_pad_info = {
173 .scl = {
174 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL
175 | MUX_PAD_CTRL(I2C_PAD_CTRL),
176 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12
177 | MUX_PAD_CTRL(I2C_PAD_CTRL),
178 .gp = IMX_GPIO_NR(4, 12)
179 },
180 .sda = {
181 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA
182 | MUX_PAD_CTRL(I2C_PAD_CTRL),
183 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300184 | MUX_PAD_CTRL(I2C_PAD_CTRL),
185 .gp = IMX_GPIO_NR(4, 13)
186 }
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000187};
188
Fabio Estevam066d97c2017-10-02 15:47:29 -0300189struct i2c_pads_info mx6q_i2c3_pad_info = {
190 .scl = {
191 .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL
192 | MUX_PAD_CTRL(I2C_PAD_CTRL),
193 .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05
194 | MUX_PAD_CTRL(I2C_PAD_CTRL),
195 .gp = IMX_GPIO_NR(1, 5)
196 },
197 .sda = {
198 .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA
199 | MUX_PAD_CTRL(I2C_PAD_CTRL),
200 .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11
201 | MUX_PAD_CTRL(I2C_PAD_CTRL),
202 .gp = IMX_GPIO_NR(7, 11)
203 }
204};
205
206struct i2c_pads_info mx6dl_i2c3_pad_info = {
207 .scl = {
208 .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL
209 | MUX_PAD_CTRL(I2C_PAD_CTRL),
210 .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05
211 | MUX_PAD_CTRL(I2C_PAD_CTRL),
212 .gp = IMX_GPIO_NR(1, 5)
213 },
214 .sda = {
215 .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA
216 | MUX_PAD_CTRL(I2C_PAD_CTRL),
217 .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11
218 | MUX_PAD_CTRL(I2C_PAD_CTRL),
219 .gp = IMX_GPIO_NR(7, 11)
220 }
221};
222
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300223static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300224 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
225 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */
226 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */
227 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */
228 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */
229 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
230 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
231 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
232 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
233 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
234 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
235 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
236 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
237 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
238 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
239 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
240 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
241 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
242 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
243 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
244 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
245 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
246 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
247 IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */
248 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300249};
250
251static void do_enable_hdmi(struct display_info_t const *dev)
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000252{
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500253 imx_enable_hdmi_phy();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000254}
255
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300256static int detect_i2c(struct display_info_t const *dev)
257{
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100258#ifdef CONFIG_DM_I2C
259 struct udevice *bus, *udev;
260 int rc;
261
262 rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus);
263 if (rc)
264 return rc;
265 rc = dm_i2c_probe(bus, dev->addr, 0, &udev);
266 if (rc)
267 return 0;
268 return 1;
269#else
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300270 return (0 == i2c_set_bus_num(dev->bus)) &&
271 (0 == i2c_probe(dev->addr));
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100272#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300273}
274
275static void enable_fwadapt_7wvga(struct display_info_t const *dev)
276{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300277 SETUP_IOMUX_PADS(fwadapt_7wvga_pads);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300278
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100279 gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN");
280 gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300281 gpio_direction_output(IMX_GPIO_NR(2, 10), 1);
282 gpio_direction_output(IMX_GPIO_NR(2, 11), 1);
283}
284
285struct display_info_t const displays[] = {{
286 .bus = -1,
287 .addr = 0,
288 .pixfmt = IPU_PIX_FMT_RGB24,
289 .detect = detect_hdmi,
290 .enable = do_enable_hdmi,
291 .mode = {
292 .name = "HDMI",
293 .refresh = 60,
294 .xres = 1024,
295 .yres = 768,
296 .pixclock = 15385,
297 .left_margin = 220,
298 .right_margin = 40,
299 .upper_margin = 21,
300 .lower_margin = 7,
301 .hsync_len = 60,
302 .vsync_len = 10,
303 .sync = FB_SYNC_EXT,
304 .vmode = FB_VMODE_NONINTERLACED
305} }, {
306 .bus = 1,
307 .addr = 0x10,
308 .pixfmt = IPU_PIX_FMT_RGB666,
309 .detect = detect_i2c,
310 .enable = enable_fwadapt_7wvga,
311 .mode = {
312 .name = "FWBADAPT-LCD-F07A-0102",
313 .refresh = 60,
314 .xres = 800,
315 .yres = 480,
316 .pixclock = 33260,
317 .left_margin = 128,
318 .right_margin = 128,
319 .upper_margin = 22,
320 .lower_margin = 22,
321 .hsync_len = 1,
322 .vsync_len = 1,
323 .sync = 0,
324 .vmode = FB_VMODE_NONINTERLACED
325} } };
326size_t display_count = ARRAY_SIZE(displays);
327
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000328static void setup_display(void)
329{
330 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000331 int reg;
332
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500333 enable_ipu_clock();
334 imx_setup_hdmi();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000335
336 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000337 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500338 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000339 writel(reg, &mxc_ccm->chsccdr);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300340
341 /* Disable LCD backlight */
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300342 SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20);
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100343 gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300344 gpio_direction_input(IMX_GPIO_NR(4, 20));
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000345}
346#endif /* CONFIG_VIDEO_IPUV3 */
347
Fabio Estevame2d282a2013-03-15 10:43:48 +0000348int board_early_init_f(void)
349{
350 setup_iomux_uart();
Simon Glass10e40d52017-06-14 21:28:25 -0600351#ifdef CONFIG_SATA
Fabio Estevamd7f7eb72017-10-15 11:21:06 -0200352 setup_sata();
Gilles Chanteperdrixe355eec2016-06-09 10:33:27 +0200353#endif
354
Fabio Estevame2d282a2013-03-15 10:43:48 +0000355 return 0;
356}
357
Fabio Estevam066d97c2017-10-02 15:47:29 -0300358#define PMIC_I2C_BUS 2
359
360int power_init_board(void)
361{
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100362 struct udevice *dev;
363 int reg, ret;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300364
Fabio Estevam21f77b72019-12-10 06:32:59 -0300365 ret = pmic_get("pfuze100@8", &dev);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100366 if (ret < 0) {
Fabio Estevam274a5522020-01-08 22:05:05 -0300367 debug("pmic_get() ret %d\n", ret);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100368 return 0;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300369 }
370
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100371 reg = pmic_reg_read(dev, PFUZE100_DEVICEID);
372 if (reg < 0) {
Fabio Estevamb8e74fc2020-04-17 09:27:11 -0300373 debug("pmic_reg_read() ret %d\n", reg);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100374 return 0;
375 }
376 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
377 with_pmic = true;
378
379 /* Set VGEN2 to 1.5V and enable */
380 reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL);
381 reg &= ~(LDO_VOL_MASK);
382 reg |= (LDOA_1_50V | (1 << (LDO_EN)));
383 pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300384 return 0;
385}
386
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000387/*
388 * Do not overwrite the console
389 * Use always serial for U-Boot console
390 */
391int overwrite_console(void)
392{
393 return 1;
394}
395
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000396#ifdef CONFIG_CMD_BMODE
397static const struct boot_mode board_boot_modes[] = {
398 /* 4 bit bus width */
399 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
400 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
401 {NULL, 0},
402};
403#endif
404
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300405static bool is_revc1(void)
406{
407 SETUP_IOMUX_PADS(rev_detection_pad);
Fabio Estevamfe2f4322020-04-17 09:27:13 -0300408 gpio_request(REV_DETECTION, "REV_DETECT");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300409 gpio_direction_input(REV_DETECTION);
410
411 if (gpio_get_value(REV_DETECTION))
412 return true;
413 else
414 return false;
415}
416
Fabio Estevam066d97c2017-10-02 15:47:29 -0300417static bool is_revd1(void)
418{
419 if (with_pmic)
420 return true;
421 else
422 return false;
423}
424
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000425int board_late_init(void)
426{
427#ifdef CONFIG_CMD_BMODE
428 add_board_boot_modes(board_boot_modes);
429#endif
430
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300431#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Fabio Estevame1f07152017-10-14 09:17:54 -0300432 if (is_mx6dqp())
433 env_set("board_rev", "MX6QP");
434 else if (is_mx6dq())
Simon Glass382bee52017-08-03 12:22:09 -0600435 env_set("board_rev", "MX6Q");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300436 else
Simon Glass382bee52017-08-03 12:22:09 -0600437 env_set("board_rev", "MX6DL");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300438
Fabio Estevam066d97c2017-10-02 15:47:29 -0300439 if (is_revd1())
440 env_set("board_name", "D1");
441 else if (is_revc1())
Simon Glass382bee52017-08-03 12:22:09 -0600442 env_set("board_name", "C1");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300443 else
Simon Glass382bee52017-08-03 12:22:09 -0600444 env_set("board_name", "B1");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300445#endif
Anatolij Gustschine4b91f02019-09-20 22:49:06 +0200446 setup_iomux_enet();
Fabio Estevamfe2f4322020-04-17 09:27:13 -0300447
448 if (is_revd1())
449 puts("Board: Wandboard rev D1\n");
450 else if (is_revc1())
451 puts("Board: Wandboard rev C1\n");
452 else
453 puts("Board: Wandboard rev B1\n");
454
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000455 return 0;
456}
457
Fabio Estevame2d282a2013-03-15 10:43:48 +0000458int board_init(void)
459{
460 /* address of boot parameters */
461 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
462
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100463#if defined(CONFIG_VIDEO_IPUV3)
Trent Piephod1337212019-05-08 23:30:01 +0000464 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
Fabio Estevame1f07152017-10-14 09:17:54 -0300465 if (is_mx6dq() || is_mx6dqp()) {
Trent Piephod1337212019-05-08 23:30:01 +0000466 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6q_i2c2_pad_info);
467 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6q_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300468 } else {
Trent Piephod1337212019-05-08 23:30:01 +0000469 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
470 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6dl_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300471 }
Fabio Estevam1b853e42017-09-22 23:45:30 -0300472
473 setup_display();
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100474#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300475
Fabio Estevame2d282a2013-03-15 10:43:48 +0000476 return 0;
477}
478
Fabio Estevam5b858582019-06-12 12:34:40 -0300479#ifdef CONFIG_SPL_LOAD_FIT
480int board_fit_config_name_match(const char *name)
481{
482 if (is_mx6dq()) {
Fabio Estevam4c13a4d2020-04-17 09:27:09 -0300483 if (!strcmp(name, "imx6q-wandboard-revd1"))
Fabio Estevam5b858582019-06-12 12:34:40 -0300484 return 0;
485 } else if (is_mx6dqp()) {
486 if (!strcmp(name, "imx6qp-wandboard-revd1"))
487 return 0;
488 } else if (is_mx6dl() || is_mx6solo()) {
Fabio Estevam4c13a4d2020-04-17 09:27:09 -0300489 if (!strcmp(name, "imx6dl-wandboard-revd1"))
Fabio Estevam5b858582019-06-12 12:34:40 -0300490 return 0;
491 }
492
493 return -EINVAL;
494}
495#endif