blob: 48914450a294061ca515328b5e3a1aa95c895fcc [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 Glass4d72caa2020-05-10 11:40:01 -060010#include <image.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000013#include <asm/arch/clock.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000014#include <asm/arch/crm_regs.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000015#include <asm/arch/iomux.h>
16#include <asm/arch/imx-regs.h>
17#include <asm/arch/mx6-pins.h>
Fabio Estevam7bcb9832013-05-23 07:50:23 +000018#include <asm/arch/mxc_hdmi.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000019#include <asm/arch/sys_proto.h>
Simon Glass401d1c42020-10-30 21:38:53 -060020#include <asm/global_data.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000021#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020022#include <asm/mach-imx/iomux-v3.h>
23#include <asm/mach-imx/mxc_i2c.h>
24#include <asm/mach-imx/boot_mode.h>
25#include <asm/mach-imx/video.h>
26#include <asm/mach-imx/sata.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000027#include <asm/io.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060028#include <env.h>
Simon Glassc05ed002020-05-10 11:40:11 -060029#include <linux/delay.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040030#include <linux/sizes.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000031#include <common.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000032#include <miiphy.h>
33#include <netdev.h>
Fabio Estevam2fb63962014-02-15 14:52:00 -020034#include <phy.h>
Otavio Salvador8bc7c482014-05-01 19:02:31 -030035#include <i2c.h>
Fabio Estevam066d97c2017-10-02 15:47:29 -030036#include <power/pmic.h>
37#include <power/pfuze100_pmic.h>
Fabio Estevame2d282a2013-03-15 10:43:48 +000038
39DECLARE_GLOBAL_DATA_PTR;
40
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000041#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)
Fabio Estevame2d282a2013-03-15 10:43:48 +000044
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000045#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
46 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevame2d282a2013-03-15 10:43:48 +000047
Otavio Salvador8bc7c482014-05-01 19:02:31 -030048#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
50 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
51
Fabio Estevame2d282a2013-03-15 10:43:48 +000052#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
Fabio Estevam066d97c2017-10-02 15:47:29 -030053#define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13)
Fabio Estevam9a8804a2015-05-21 19:24:05 -030054#define REV_DETECTION IMX_GPIO_NR(2, 28)
Fabio Estevame2d282a2013-03-15 10:43:48 +000055
Trent Piephod1337212019-05-08 23:30:01 +000056/* Speed defined in Kconfig is only applicable when not using DM_I2C. */
Igor Opaniuk2147a162021-02-09 13:52:45 +020057#if CONFIG_IS_ENABLED(DM_I2C)
Trent Piephod1337212019-05-08 23:30:01 +000058#define I2C1_SPEED_NON_DM 0
59#define I2C2_SPEED_NON_DM 0
60#else
61#define I2C1_SPEED_NON_DM CONFIG_SYS_MXC_I2C1_SPEED
62#define I2C2_SPEED_NON_DM CONFIG_SYS_MXC_I2C2_SPEED
63#endif
64
Fabio Estevam066d97c2017-10-02 15:47:29 -030065static bool with_pmic;
66
Fabio Estevame2d282a2013-03-15 10:43:48 +000067int dram_init(void)
68{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030069 gd->ram_size = imx_ddr_size();
Fabio Estevame2d282a2013-03-15 10:43:48 +000070
71 return 0;
72}
73
74static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -030075 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
76 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000077};
78
Fabio Estevame2d282a2013-03-15 10:43:48 +000079static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevame2d282a2013-03-15 10:43:48 +000080 /* AR8031 PHY Reset */
Fabio Estevam0d1ea052015-05-11 20:50:22 -030081 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevame2d282a2013-03-15 10:43:48 +000082};
83
Fabio Estevam066d97c2017-10-02 15:47:29 -030084static iomux_v3_cfg_t const enet_ar8035_power_pads[] = {
85 /* AR8035 POWER */
86 IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
87};
88
Fabio Estevam9a8804a2015-05-21 19:24:05 -030089static iomux_v3_cfg_t const rev_detection_pad[] = {
90 IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
91};
92
Fabio Estevame2d282a2013-03-15 10:43:48 +000093static void setup_iomux_uart(void)
94{
Fabio Estevam0d1ea052015-05-11 20:50:22 -030095 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +000096}
97
98static void setup_iomux_enet(void)
99{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300100 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000101
Fabio Estevam066d97c2017-10-02 15:47:29 -0300102 if (with_pmic) {
103 SETUP_IOMUX_PADS(enet_ar8035_power_pads);
104 /* enable AR8035 POWER */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100105 gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER");
Fabio Estevam066d97c2017-10-02 15:47:29 -0300106 gpio_direction_output(ETH_PHY_AR8035_POWER, 0);
107 }
108 /* wait until 3.3V of PHY and clock become stable */
109 mdelay(10);
110
Fabio Estevame2d282a2013-03-15 10:43:48 +0000111 /* Reset AR8031 PHY */
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100112 gpio_request(ETH_PHY_RESET, "PHY_RESET");
Fabio Estevame2d282a2013-03-15 10:43:48 +0000113 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200114 mdelay(10);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000115 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam59a6ca52016-01-05 17:02:54 -0200116 udelay(100);
Fabio Estevame2d282a2013-03-15 10:43:48 +0000117}
118
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200119static int ar8031_phy_fixup(struct phy_device *phydev)
120{
121 unsigned short val;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300122 int mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200123
124 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
125 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
126 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
127 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
128
129 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300130 if (with_pmic)
131 mask = 0xffe7; /* AR8035 */
132 else
133 mask = 0xffe3; /* AR8031 */
134
135 val &= mask;
Fabio Estevamdac09fc2016-11-01 14:58:16 -0200136 val |= 0x18;
137 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
138
139 /* introduce tx clock delay */
140 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
141 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
142 val |= 0x0100;
143 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
144
145 return 0;
146}
147
148int board_phy_config(struct phy_device *phydev)
149{
150 ar8031_phy_fixup(phydev);
151
152 if (phydev->drv->config)
153 phydev->drv->config(phydev);
154
155 return 0;
156}
157
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000158#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300159struct i2c_pads_info mx6q_i2c2_pad_info = {
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300160 .scl = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300161 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300162 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300163 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300164 | MUX_PAD_CTRL(I2C_PAD_CTRL),
165 .gp = IMX_GPIO_NR(4, 12)
166 },
167 .sda = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300168 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300169 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300170 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13
171 | MUX_PAD_CTRL(I2C_PAD_CTRL),
172 .gp = IMX_GPIO_NR(4, 13)
173 }
174};
175
176struct i2c_pads_info mx6dl_i2c2_pad_info = {
177 .scl = {
178 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL
179 | MUX_PAD_CTRL(I2C_PAD_CTRL),
180 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12
181 | MUX_PAD_CTRL(I2C_PAD_CTRL),
182 .gp = IMX_GPIO_NR(4, 12)
183 },
184 .sda = {
185 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA
186 | MUX_PAD_CTRL(I2C_PAD_CTRL),
187 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300188 | MUX_PAD_CTRL(I2C_PAD_CTRL),
189 .gp = IMX_GPIO_NR(4, 13)
190 }
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000191};
192
Fabio Estevam066d97c2017-10-02 15:47:29 -0300193struct i2c_pads_info mx6q_i2c3_pad_info = {
194 .scl = {
195 .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL
196 | MUX_PAD_CTRL(I2C_PAD_CTRL),
197 .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05
198 | MUX_PAD_CTRL(I2C_PAD_CTRL),
199 .gp = IMX_GPIO_NR(1, 5)
200 },
201 .sda = {
202 .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA
203 | MUX_PAD_CTRL(I2C_PAD_CTRL),
204 .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11
205 | MUX_PAD_CTRL(I2C_PAD_CTRL),
206 .gp = IMX_GPIO_NR(7, 11)
207 }
208};
209
210struct i2c_pads_info mx6dl_i2c3_pad_info = {
211 .scl = {
212 .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL
213 | MUX_PAD_CTRL(I2C_PAD_CTRL),
214 .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05
215 | MUX_PAD_CTRL(I2C_PAD_CTRL),
216 .gp = IMX_GPIO_NR(1, 5)
217 },
218 .sda = {
219 .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA
220 | MUX_PAD_CTRL(I2C_PAD_CTRL),
221 .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11
222 | MUX_PAD_CTRL(I2C_PAD_CTRL),
223 .gp = IMX_GPIO_NR(7, 11)
224 }
225};
226
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300227static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = {
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300228 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
229 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */
230 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */
231 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */
232 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */
233 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
234 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
235 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
236 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
237 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
238 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
239 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
240 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
241 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
242 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
243 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
244 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
245 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
246 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
247 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
248 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
249 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
250 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
251 IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */
252 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300253};
254
255static void do_enable_hdmi(struct display_info_t const *dev)
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000256{
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500257 imx_enable_hdmi_phy();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000258}
259
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300260static int detect_i2c(struct display_info_t const *dev)
261{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200262#if CONFIG_IS_ENABLED(DM_I2C)
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100263 struct udevice *bus, *udev;
264 int rc;
265
266 rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus);
267 if (rc)
268 return rc;
269 rc = dm_i2c_probe(bus, dev->addr, 0, &udev);
270 if (rc)
271 return 0;
272 return 1;
273#else
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300274 return (0 == i2c_set_bus_num(dev->bus)) &&
275 (0 == i2c_probe(dev->addr));
Anatolij Gustschinc6095422019-03-18 23:29:46 +0100276#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300277}
278
279static void enable_fwadapt_7wvga(struct display_info_t const *dev)
280{
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300281 SETUP_IOMUX_PADS(fwadapt_7wvga_pads);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300282
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100283 gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN");
284 gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300285 gpio_direction_output(IMX_GPIO_NR(2, 10), 1);
286 gpio_direction_output(IMX_GPIO_NR(2, 11), 1);
287}
288
289struct display_info_t const displays[] = {{
290 .bus = -1,
291 .addr = 0,
292 .pixfmt = IPU_PIX_FMT_RGB24,
293 .detect = detect_hdmi,
294 .enable = do_enable_hdmi,
295 .mode = {
296 .name = "HDMI",
297 .refresh = 60,
298 .xres = 1024,
299 .yres = 768,
300 .pixclock = 15385,
301 .left_margin = 220,
302 .right_margin = 40,
303 .upper_margin = 21,
304 .lower_margin = 7,
305 .hsync_len = 60,
306 .vsync_len = 10,
307 .sync = FB_SYNC_EXT,
308 .vmode = FB_VMODE_NONINTERLACED
309} }, {
310 .bus = 1,
311 .addr = 0x10,
312 .pixfmt = IPU_PIX_FMT_RGB666,
313 .detect = detect_i2c,
314 .enable = enable_fwadapt_7wvga,
315 .mode = {
316 .name = "FWBADAPT-LCD-F07A-0102",
317 .refresh = 60,
318 .xres = 800,
319 .yres = 480,
320 .pixclock = 33260,
321 .left_margin = 128,
322 .right_margin = 128,
323 .upper_margin = 22,
324 .lower_margin = 22,
325 .hsync_len = 1,
326 .vsync_len = 1,
327 .sync = 0,
328 .vmode = FB_VMODE_NONINTERLACED
329} } };
330size_t display_count = ARRAY_SIZE(displays);
331
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000332static void setup_display(void)
333{
334 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000335 int reg;
336
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500337 enable_ipu_clock();
338 imx_setup_hdmi();
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000339
340 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000341 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500342 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000343 writel(reg, &mxc_ccm->chsccdr);
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300344
345 /* Disable LCD backlight */
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300346 SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20);
Anatolij Gustschina23ade62019-03-18 23:29:42 +0100347 gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN");
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300348 gpio_direction_input(IMX_GPIO_NR(4, 20));
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000349}
350#endif /* CONFIG_VIDEO_IPUV3 */
351
Fabio Estevame2d282a2013-03-15 10:43:48 +0000352int board_early_init_f(void)
353{
354 setup_iomux_uart();
Troy Kisky32af1c02023-03-13 14:31:41 -0700355 if (CONFIG_IS_ENABLED(SATA))
356 setup_sata();
Gilles Chanteperdrixe355eec2016-06-09 10:33:27 +0200357
Fabio Estevame2d282a2013-03-15 10:43:48 +0000358 return 0;
359}
360
Fabio Estevam066d97c2017-10-02 15:47:29 -0300361#define PMIC_I2C_BUS 2
362
363int power_init_board(void)
364{
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100365 struct udevice *dev;
366 int reg, ret;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300367
Fabio Estevam21f77b72019-12-10 06:32:59 -0300368 ret = pmic_get("pfuze100@8", &dev);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100369 if (ret < 0) {
Fabio Estevam274a5522020-01-08 22:05:05 -0300370 debug("pmic_get() ret %d\n", ret);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100371 return 0;
Fabio Estevam066d97c2017-10-02 15:47:29 -0300372 }
373
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100374 reg = pmic_reg_read(dev, PFUZE100_DEVICEID);
375 if (reg < 0) {
Fabio Estevamb8e74fc2020-04-17 09:27:11 -0300376 debug("pmic_reg_read() ret %d\n", reg);
Anatolij Gustschinec837c82019-03-18 23:29:45 +0100377 return 0;
378 }
379 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
380 with_pmic = true;
381
382 /* Set VGEN2 to 1.5V and enable */
383 reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL);
384 reg &= ~(LDO_VOL_MASK);
385 reg |= (LDOA_1_50V | (1 << (LDO_EN)));
386 pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300387 return 0;
388}
389
Fabio Estevam7bcb9832013-05-23 07:50:23 +0000390/*
391 * Do not overwrite the console
392 * Use always serial for U-Boot console
393 */
394int overwrite_console(void)
395{
396 return 1;
397}
398
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000399#ifdef CONFIG_CMD_BMODE
400static const struct boot_mode board_boot_modes[] = {
401 /* 4 bit bus width */
402 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
403 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
404 {NULL, 0},
405};
406#endif
407
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300408static bool is_revc1(void)
409{
410 SETUP_IOMUX_PADS(rev_detection_pad);
Fabio Estevamfe2f4322020-04-17 09:27:13 -0300411 gpio_request(REV_DETECTION, "REV_DETECT");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300412 gpio_direction_input(REV_DETECTION);
413
414 if (gpio_get_value(REV_DETECTION))
415 return true;
416 else
417 return false;
418}
419
Fabio Estevam066d97c2017-10-02 15:47:29 -0300420static bool is_revd1(void)
421{
422 if (with_pmic)
423 return true;
424 else
425 return false;
426}
427
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000428int board_late_init(void)
429{
430#ifdef CONFIG_CMD_BMODE
431 add_board_boot_modes(board_boot_modes);
432#endif
433
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300434#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Fabio Estevame1f07152017-10-14 09:17:54 -0300435 if (is_mx6dqp())
436 env_set("board_rev", "MX6QP");
437 else if (is_mx6dq())
Simon Glass382bee52017-08-03 12:22:09 -0600438 env_set("board_rev", "MX6Q");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300439 else
Simon Glass382bee52017-08-03 12:22:09 -0600440 env_set("board_rev", "MX6DL");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300441
Fabio Estevam066d97c2017-10-02 15:47:29 -0300442 if (is_revd1())
443 env_set("board_name", "D1");
444 else if (is_revc1())
Simon Glass382bee52017-08-03 12:22:09 -0600445 env_set("board_name", "C1");
Fabio Estevam9a8804a2015-05-21 19:24:05 -0300446 else
Simon Glass382bee52017-08-03 12:22:09 -0600447 env_set("board_name", "B1");
Fabio Estevam0d1ea052015-05-11 20:50:22 -0300448#endif
Anatolij Gustschine4b91f02019-09-20 22:49:06 +0200449 setup_iomux_enet();
Fabio Estevamfe2f4322020-04-17 09:27:13 -0300450
451 if (is_revd1())
452 puts("Board: Wandboard rev D1\n");
453 else if (is_revc1())
454 puts("Board: Wandboard rev C1\n");
455 else
456 puts("Board: Wandboard rev B1\n");
457
Otavio Salvadoreaffaa22013-04-19 03:42:03 +0000458 return 0;
459}
460
Fabio Estevame2d282a2013-03-15 10:43:48 +0000461int board_init(void)
462{
463 /* address of boot parameters */
464 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
465
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100466#if defined(CONFIG_VIDEO_IPUV3)
Trent Piephod1337212019-05-08 23:30:01 +0000467 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
Fabio Estevame1f07152017-10-14 09:17:54 -0300468 if (is_mx6dq() || is_mx6dqp()) {
Trent Piephod1337212019-05-08 23:30:01 +0000469 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6q_i2c2_pad_info);
470 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6q_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300471 } else {
Trent Piephod1337212019-05-08 23:30:01 +0000472 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
473 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6dl_i2c3_pad_info);
Fabio Estevam066d97c2017-10-02 15:47:29 -0300474 }
Fabio Estevam1b853e42017-09-22 23:45:30 -0300475
476 setup_display();
Sven Ebenfeld36c06272016-11-25 21:42:53 +0100477#endif
Otavio Salvador8bc7c482014-05-01 19:02:31 -0300478
Fabio Estevame2d282a2013-03-15 10:43:48 +0000479 return 0;
480}
481
Fabio Estevam5b858582019-06-12 12:34:40 -0300482#ifdef CONFIG_SPL_LOAD_FIT
483int board_fit_config_name_match(const char *name)
484{
485 if (is_mx6dq()) {
Fabio Estevam4c13a4d2020-04-17 09:27:09 -0300486 if (!strcmp(name, "imx6q-wandboard-revd1"))
Fabio Estevam5b858582019-06-12 12:34:40 -0300487 return 0;
488 } else if (is_mx6dqp()) {
489 if (!strcmp(name, "imx6qp-wandboard-revd1"))
490 return 0;
491 } else if (is_mx6dl() || is_mx6solo()) {
Fabio Estevam4c13a4d2020-04-17 09:27:09 -0300492 if (!strcmp(name, "imx6dl-wandboard-revd1"))
Fabio Estevam5b858582019-06-12 12:34:40 -0300493 return 0;
494 }
495
496 return -EINVAL;
497}
498#endif