blob: 69fbc8b690797a658aa117d5d29040effc447428 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam11027402013-03-15 10:43:48 +00002/*
3 * Copyright (C) 2013 Freescale Semiconductor, Inc.
Otavio Salvador1d744d92014-05-01 19:02:31 -03004 * Copyright (C) 2014 O.S. Systems Software LTDA.
Fabio Estevam11027402013-03-15 10:43:48 +00005 *
6 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevam11027402013-03-15 10:43:48 +00007 */
8
9#include <asm/arch/clock.h>
Fabio Estevam0296f282013-05-23 07:50:23 +000010#include <asm/arch/crm_regs.h>
Fabio Estevam11027402013-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 Estevam0296f282013-05-23 07:50:23 +000014#include <asm/arch/mxc_hdmi.h>
Fabio Estevam11027402013-03-15 10:43:48 +000015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
Stefano Babic33731bc2017-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 Estevam11027402013-03-15 10:43:48 +000022#include <asm/io.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040023#include <linux/sizes.h>
Fabio Estevam11027402013-03-15 10:43:48 +000024#include <common.h>
Fabio Estevam11027402013-03-15 10:43:48 +000025#include <miiphy.h>
26#include <netdev.h>
Fabio Estevam55e0f192014-02-15 14:52:00 -020027#include <phy.h>
Otavio Salvador1d744d92014-05-01 19:02:31 -030028#include <i2c.h>
Fabio Estevame40cb552017-10-02 15:47:29 -030029#include <power/pmic.h>
30#include <power/pfuze100_pmic.h>
Fabio Estevam11027402013-03-15 10:43:48 +000031
32DECLARE_GLOBAL_DATA_PTR;
33
Benoît Thébaudeau21670242013-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 Estevam11027402013-03-15 10:43:48 +000037
Benoît Thébaudeau21670242013-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 Estevam11027402013-03-15 10:43:48 +000040
Otavio Salvador1d744d92014-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 Estevam11027402013-03-15 10:43:48 +000045#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
Fabio Estevame40cb552017-10-02 15:47:29 -030046#define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13)
Fabio Estevamaec72fb2015-05-21 19:24:05 -030047#define REV_DETECTION IMX_GPIO_NR(2, 28)
Fabio Estevam11027402013-03-15 10:43:48 +000048
Fabio Estevame40cb552017-10-02 15:47:29 -030049static bool with_pmic;
50
Fabio Estevam11027402013-03-15 10:43:48 +000051int dram_init(void)
52{
Fabio Estevam1fa64862015-05-11 20:50:22 -030053 gd->ram_size = imx_ddr_size();
Fabio Estevam11027402013-03-15 10:43:48 +000054
55 return 0;
56}
57
58static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam1fa64862015-05-11 20:50:22 -030059 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
60 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000061};
62
Fabio Estevam11027402013-03-15 10:43:48 +000063static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevam1fa64862015-05-11 20:50:22 -030064 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
65 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
66 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
67 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
68 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
69 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
70 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
71 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000079 /* AR8031 PHY Reset */
Fabio Estevam1fa64862015-05-11 20:50:22 -030080 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000081};
82
Fabio Estevame40cb552017-10-02 15:47:29 -030083static iomux_v3_cfg_t const enet_ar8035_power_pads[] = {
84 /* AR8035 POWER */
85 IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
86};
87
Fabio Estevamaec72fb2015-05-21 19:24:05 -030088static iomux_v3_cfg_t const rev_detection_pad[] = {
89 IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
90};
91
Fabio Estevam11027402013-03-15 10:43:48 +000092static void setup_iomux_uart(void)
93{
Fabio Estevam1fa64862015-05-11 20:50:22 -030094 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevam11027402013-03-15 10:43:48 +000095}
96
97static void setup_iomux_enet(void)
98{
Fabio Estevam1fa64862015-05-11 20:50:22 -030099 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevam11027402013-03-15 10:43:48 +0000100
Fabio Estevame40cb552017-10-02 15:47:29 -0300101 if (with_pmic) {
102 SETUP_IOMUX_PADS(enet_ar8035_power_pads);
103 /* enable AR8035 POWER */
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100104 gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER");
Fabio Estevame40cb552017-10-02 15:47:29 -0300105 gpio_direction_output(ETH_PHY_AR8035_POWER, 0);
106 }
107 /* wait until 3.3V of PHY and clock become stable */
108 mdelay(10);
109
Fabio Estevam11027402013-03-15 10:43:48 +0000110 /* Reset AR8031 PHY */
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100111 gpio_request(ETH_PHY_RESET, "PHY_RESET");
Fabio Estevam11027402013-03-15 10:43:48 +0000112 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam9f4c2522016-01-05 17:02:54 -0200113 mdelay(10);
Fabio Estevam11027402013-03-15 10:43:48 +0000114 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam9f4c2522016-01-05 17:02:54 -0200115 udelay(100);
Fabio Estevam11027402013-03-15 10:43:48 +0000116}
117
Fabio Estevam89303132016-11-01 14:58:16 -0200118static int ar8031_phy_fixup(struct phy_device *phydev)
119{
120 unsigned short val;
Fabio Estevame40cb552017-10-02 15:47:29 -0300121 int mask;
Fabio Estevam89303132016-11-01 14:58:16 -0200122
123 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
124 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
125 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
126 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
127
128 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
Fabio Estevame40cb552017-10-02 15:47:29 -0300129 if (with_pmic)
130 mask = 0xffe7; /* AR8035 */
131 else
132 mask = 0xffe3; /* AR8031 */
133
134 val &= mask;
Fabio Estevam89303132016-11-01 14:58:16 -0200135 val |= 0x18;
136 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
137
138 /* introduce tx clock delay */
139 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
140 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
141 val |= 0x0100;
142 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
143
144 return 0;
145}
146
147int board_phy_config(struct phy_device *phydev)
148{
149 ar8031_phy_fixup(phydev);
150
151 if (phydev->drv->config)
152 phydev->drv->config(phydev);
153
154 return 0;
155}
156
Fabio Estevam0296f282013-05-23 07:50:23 +0000157#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam1fa64862015-05-11 20:50:22 -0300158struct i2c_pads_info mx6q_i2c2_pad_info = {
Otavio Salvador1d744d92014-05-01 19:02:31 -0300159 .scl = {
Fabio Estevam1fa64862015-05-11 20:50:22 -0300160 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL
Otavio Salvador1d744d92014-05-01 19:02:31 -0300161 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam1fa64862015-05-11 20:50:22 -0300162 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12
Otavio Salvador1d744d92014-05-01 19:02:31 -0300163 | MUX_PAD_CTRL(I2C_PAD_CTRL),
164 .gp = IMX_GPIO_NR(4, 12)
165 },
166 .sda = {
Fabio Estevam1fa64862015-05-11 20:50:22 -0300167 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA
Otavio Salvador1d744d92014-05-01 19:02:31 -0300168 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam1fa64862015-05-11 20:50:22 -0300169 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13
Otavio Salvador1d744d92014-05-01 19:02:31 -0300170 | MUX_PAD_CTRL(I2C_PAD_CTRL),
171 .gp = IMX_GPIO_NR(4, 13)
172 }
Fabio Estevam0296f282013-05-23 07:50:23 +0000173};
174
Fabio Estevam1fa64862015-05-11 20:50:22 -0300175struct i2c_pads_info mx6dl_i2c2_pad_info = {
176 .scl = {
177 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL
178 | MUX_PAD_CTRL(I2C_PAD_CTRL),
179 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12
180 | MUX_PAD_CTRL(I2C_PAD_CTRL),
181 .gp = IMX_GPIO_NR(4, 12)
182 },
183 .sda = {
184 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA
185 | MUX_PAD_CTRL(I2C_PAD_CTRL),
186 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13
187 | MUX_PAD_CTRL(I2C_PAD_CTRL),
188 .gp = IMX_GPIO_NR(4, 13)
189 }
190};
Fabio Estevam0296f282013-05-23 07:50:23 +0000191
Fabio Estevame40cb552017-10-02 15:47:29 -0300192struct i2c_pads_info mx6q_i2c3_pad_info = {
193 .scl = {
194 .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL
195 | MUX_PAD_CTRL(I2C_PAD_CTRL),
196 .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05
197 | MUX_PAD_CTRL(I2C_PAD_CTRL),
198 .gp = IMX_GPIO_NR(1, 5)
199 },
200 .sda = {
201 .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA
202 | MUX_PAD_CTRL(I2C_PAD_CTRL),
203 .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11
204 | MUX_PAD_CTRL(I2C_PAD_CTRL),
205 .gp = IMX_GPIO_NR(7, 11)
206 }
207};
208
209struct i2c_pads_info mx6dl_i2c3_pad_info = {
210 .scl = {
211 .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL
212 | MUX_PAD_CTRL(I2C_PAD_CTRL),
213 .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05
214 | MUX_PAD_CTRL(I2C_PAD_CTRL),
215 .gp = IMX_GPIO_NR(1, 5)
216 },
217 .sda = {
218 .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA
219 | MUX_PAD_CTRL(I2C_PAD_CTRL),
220 .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11
221 | MUX_PAD_CTRL(I2C_PAD_CTRL),
222 .gp = IMX_GPIO_NR(7, 11)
223 }
224};
225
Fabio Estevam1fa64862015-05-11 20:50:22 -0300226static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = {
227 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
228 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */
229 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */
230 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */
231 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */
232 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
233 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
234 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
235 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
236 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
237 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
238 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
239 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
240 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
241 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
242 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
243 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
244 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
245 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
246 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
247 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
248 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
249 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
250 IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */
251 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */
Otavio Salvador1d744d92014-05-01 19:02:31 -0300252};
Fabio Estevam0296f282013-05-23 07:50:23 +0000253
Otavio Salvador1d744d92014-05-01 19:02:31 -0300254static void do_enable_hdmi(struct display_info_t const *dev)
255{
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500256 imx_enable_hdmi_phy();
Otavio Salvador1d744d92014-05-01 19:02:31 -0300257}
Fabio Estevam0296f282013-05-23 07:50:23 +0000258
Otavio Salvador1d744d92014-05-01 19:02:31 -0300259static int detect_i2c(struct display_info_t const *dev)
260{
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100261#ifdef CONFIG_DM_I2C
262 struct udevice *bus, *udev;
263 int rc;
264
265 rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus);
266 if (rc)
267 return rc;
268 rc = dm_i2c_probe(bus, dev->addr, 0, &udev);
269 if (rc)
270 return 0;
271 return 1;
272#else
Otavio Salvador1d744d92014-05-01 19:02:31 -0300273 return (0 == i2c_set_bus_num(dev->bus)) &&
274 (0 == i2c_probe(dev->addr));
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100275#endif
Otavio Salvador1d744d92014-05-01 19:02:31 -0300276}
277
278static void enable_fwadapt_7wvga(struct display_info_t const *dev)
279{
Fabio Estevam1fa64862015-05-11 20:50:22 -0300280 SETUP_IOMUX_PADS(fwadapt_7wvga_pads);
Otavio Salvador1d744d92014-05-01 19:02:31 -0300281
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100282 gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN");
283 gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN");
Otavio Salvador1d744d92014-05-01 19:02:31 -0300284 gpio_direction_output(IMX_GPIO_NR(2, 10), 1);
285 gpio_direction_output(IMX_GPIO_NR(2, 11), 1);
Fabio Estevam0296f282013-05-23 07:50:23 +0000286}
287
Otavio Salvador1d744d92014-05-01 19:02:31 -0300288struct display_info_t const displays[] = {{
289 .bus = -1,
290 .addr = 0,
291 .pixfmt = IPU_PIX_FMT_RGB24,
292 .detect = detect_hdmi,
293 .enable = do_enable_hdmi,
294 .mode = {
295 .name = "HDMI",
296 .refresh = 60,
297 .xres = 1024,
298 .yres = 768,
299 .pixclock = 15385,
300 .left_margin = 220,
301 .right_margin = 40,
302 .upper_margin = 21,
303 .lower_margin = 7,
304 .hsync_len = 60,
305 .vsync_len = 10,
306 .sync = FB_SYNC_EXT,
307 .vmode = FB_VMODE_NONINTERLACED
308} }, {
309 .bus = 1,
310 .addr = 0x10,
311 .pixfmt = IPU_PIX_FMT_RGB666,
312 .detect = detect_i2c,
313 .enable = enable_fwadapt_7wvga,
314 .mode = {
315 .name = "FWBADAPT-LCD-F07A-0102",
316 .refresh = 60,
317 .xres = 800,
318 .yres = 480,
319 .pixclock = 33260,
320 .left_margin = 128,
321 .right_margin = 128,
322 .upper_margin = 22,
323 .lower_margin = 22,
324 .hsync_len = 1,
325 .vsync_len = 1,
326 .sync = 0,
327 .vmode = FB_VMODE_NONINTERLACED
328} } };
329size_t display_count = ARRAY_SIZE(displays);
330
Fabio Estevam0296f282013-05-23 07:50:23 +0000331static void setup_display(void)
332{
333 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam0296f282013-05-23 07:50:23 +0000334 int reg;
335
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500336 enable_ipu_clock();
337 imx_setup_hdmi();
Fabio Estevam0296f282013-05-23 07:50:23 +0000338
339 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam0296f282013-05-23 07:50:23 +0000340 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500341 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam0296f282013-05-23 07:50:23 +0000342 writel(reg, &mxc_ccm->chsccdr);
Otavio Salvador1d744d92014-05-01 19:02:31 -0300343
344 /* Disable LCD backlight */
Fabio Estevam1fa64862015-05-11 20:50:22 -0300345 SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20);
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100346 gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN");
Otavio Salvador1d744d92014-05-01 19:02:31 -0300347 gpio_direction_input(IMX_GPIO_NR(4, 20));
Fabio Estevam0296f282013-05-23 07:50:23 +0000348}
349#endif /* CONFIG_VIDEO_IPUV3 */
350
Fabio Estevam11027402013-03-15 10:43:48 +0000351int board_eth_init(bd_t *bis)
352{
Fabio Estevam11027402013-03-15 10:43:48 +0000353 setup_iomux_enet();
354
Fabio Estevamc3cc3052014-01-04 17:36:28 -0200355 return cpu_eth_init(bis);
Fabio Estevam11027402013-03-15 10:43:48 +0000356}
357
358int board_early_init_f(void)
359{
360 setup_iomux_uart();
Simon Glassab3055a2017-06-14 21:28:25 -0600361#ifdef CONFIG_SATA
Fabio Estevama7d45152017-10-15 11:21:06 -0200362 setup_sata();
Gilles Chanteperdrixb99d6642016-06-09 10:33:27 +0200363#endif
364
Fabio Estevam11027402013-03-15 10:43:48 +0000365 return 0;
366}
367
Fabio Estevame40cb552017-10-02 15:47:29 -0300368#define PMIC_I2C_BUS 2
369
370int power_init_board(void)
371{
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100372 struct udevice *dev;
373 int reg, ret;
Fabio Estevame40cb552017-10-02 15:47:29 -0300374
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100375 puts("PMIC: ");
Fabio Estevame40cb552017-10-02 15:47:29 -0300376
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100377 ret = pmic_get("pfuze100", &dev);
378 if (ret < 0) {
379 printf("pmic_get() ret %d\n", ret);
380 return 0;
Fabio Estevame40cb552017-10-02 15:47:29 -0300381 }
382
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100383 reg = pmic_reg_read(dev, PFUZE100_DEVICEID);
384 if (reg < 0) {
385 printf("pmic_reg_read() ret %d\n", reg);
386 return 0;
387 }
388 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
389 with_pmic = true;
390
391 /* Set VGEN2 to 1.5V and enable */
392 reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL);
393 reg &= ~(LDO_VOL_MASK);
394 reg |= (LDOA_1_50V | (1 << (LDO_EN)));
395 pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg);
Fabio Estevame40cb552017-10-02 15:47:29 -0300396 return 0;
397}
398
Fabio Estevam0296f282013-05-23 07:50:23 +0000399/*
400 * Do not overwrite the console
401 * Use always serial for U-Boot console
402 */
403int overwrite_console(void)
404{
405 return 1;
406}
407
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000408#ifdef CONFIG_CMD_BMODE
409static const struct boot_mode board_boot_modes[] = {
410 /* 4 bit bus width */
411 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
412 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
413 {NULL, 0},
414};
415#endif
416
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300417static bool is_revc1(void)
418{
419 SETUP_IOMUX_PADS(rev_detection_pad);
420 gpio_direction_input(REV_DETECTION);
421
422 if (gpio_get_value(REV_DETECTION))
423 return true;
424 else
425 return false;
426}
427
Fabio Estevame40cb552017-10-02 15:47:29 -0300428static bool is_revd1(void)
429{
430 if (with_pmic)
431 return true;
432 else
433 return false;
434}
435
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000436int board_late_init(void)
437{
438#ifdef CONFIG_CMD_BMODE
439 add_board_boot_modes(board_boot_modes);
440#endif
441
Fabio Estevam1fa64862015-05-11 20:50:22 -0300442#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Fabio Estevama48538c2017-10-14 09:17:54 -0300443 if (is_mx6dqp())
444 env_set("board_rev", "MX6QP");
445 else if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600446 env_set("board_rev", "MX6Q");
Fabio Estevam1fa64862015-05-11 20:50:22 -0300447 else
Simon Glass6a38e412017-08-03 12:22:09 -0600448 env_set("board_rev", "MX6DL");
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300449
Fabio Estevame40cb552017-10-02 15:47:29 -0300450 if (is_revd1())
451 env_set("board_name", "D1");
452 else if (is_revc1())
Simon Glass6a38e412017-08-03 12:22:09 -0600453 env_set("board_name", "C1");
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300454 else
Simon Glass6a38e412017-08-03 12:22:09 -0600455 env_set("board_name", "B1");
Fabio Estevam1fa64862015-05-11 20:50:22 -0300456#endif
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000457 return 0;
458}
459
Fabio Estevam11027402013-03-15 10:43:48 +0000460int board_init(void)
461{
462 /* address of boot parameters */
463 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
464
Sven Ebenfeld4747d152016-11-25 21:42:53 +0100465#if defined(CONFIG_VIDEO_IPUV3)
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100466 setup_i2c(1, CONFIG_SYS_MXC_I2C1_SPEED, 0x7f, &mx6dl_i2c2_pad_info);
Fabio Estevama48538c2017-10-14 09:17:54 -0300467 if (is_mx6dq() || is_mx6dqp()) {
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100468 setup_i2c(1, CONFIG_SYS_MXC_I2C1_SPEED, 0x7f, &mx6q_i2c2_pad_info);
469 setup_i2c(2, CONFIG_SYS_MXC_I2C2_SPEED, 0x7f, &mx6q_i2c3_pad_info);
Fabio Estevame40cb552017-10-02 15:47:29 -0300470 } else {
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100471 setup_i2c(1, CONFIG_SYS_MXC_I2C1_SPEED, 0x7f, &mx6dl_i2c2_pad_info);
472 setup_i2c(2, CONFIG_SYS_MXC_I2C2_SPEED, 0x7f, &mx6dl_i2c3_pad_info);
Fabio Estevame40cb552017-10-02 15:47:29 -0300473 }
Fabio Estevamf7c09722017-09-22 23:45:30 -0300474
475 setup_display();
Sven Ebenfeld4747d152016-11-25 21:42:53 +0100476#endif
Otavio Salvador1d744d92014-05-01 19:02:31 -0300477
Fabio Estevam11027402013-03-15 10:43:48 +0000478 return 0;
479}
480
Fabio Estevam11027402013-03-15 10:43:48 +0000481int checkboard(void)
482{
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100483 gpio_request(REV_DETECTION, "REV_DETECT");
484
Fabio Estevame40cb552017-10-02 15:47:29 -0300485 if (is_revd1())
486 puts("Board: Wandboard rev D1\n");
487 else if (is_revc1())
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300488 puts("Board: Wandboard rev C1\n");
489 else
490 puts("Board: Wandboard rev B1\n");
Fabio Estevam11027402013-03-15 10:43:48 +0000491
492 return 0;
493}