blob: 69cdf3e9c96b18b7d15ac77816bc7faeb55c6ebb [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>
Simon Glass5e6201b2019-08-01 09:46:51 -060023#include <env.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040024#include <linux/sizes.h>
Fabio Estevam11027402013-03-15 10:43:48 +000025#include <common.h>
Fabio Estevam11027402013-03-15 10:43:48 +000026#include <miiphy.h>
27#include <netdev.h>
Fabio Estevam55e0f192014-02-15 14:52:00 -020028#include <phy.h>
Otavio Salvador1d744d92014-05-01 19:02:31 -030029#include <i2c.h>
Fabio Estevame40cb552017-10-02 15:47:29 -030030#include <power/pmic.h>
31#include <power/pfuze100_pmic.h>
Fabio Estevam11027402013-03-15 10:43:48 +000032
33DECLARE_GLOBAL_DATA_PTR;
34
Benoît Thébaudeau21670242013-04-26 01:34:47 +000035#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
36 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
37 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam11027402013-03-15 10:43:48 +000038
Benoît Thébaudeau21670242013-04-26 01:34:47 +000039#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
40 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevam11027402013-03-15 10:43:48 +000041
Otavio Salvador1d744d92014-05-01 19:02:31 -030042#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
43 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
44 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
45
Fabio Estevam11027402013-03-15 10:43:48 +000046#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
Fabio Estevame40cb552017-10-02 15:47:29 -030047#define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13)
Fabio Estevamaec72fb2015-05-21 19:24:05 -030048#define REV_DETECTION IMX_GPIO_NR(2, 28)
Fabio Estevam11027402013-03-15 10:43:48 +000049
Trent Piephobcbf1ac2019-05-08 23:30:01 +000050/* Speed defined in Kconfig is only applicable when not using DM_I2C. */
51#ifdef CONFIG_DM_I2C
52#define I2C1_SPEED_NON_DM 0
53#define I2C2_SPEED_NON_DM 0
54#else
55#define I2C1_SPEED_NON_DM CONFIG_SYS_MXC_I2C1_SPEED
56#define I2C2_SPEED_NON_DM CONFIG_SYS_MXC_I2C2_SPEED
57#endif
58
Fabio Estevame40cb552017-10-02 15:47:29 -030059static bool with_pmic;
60
Fabio Estevam11027402013-03-15 10:43:48 +000061int dram_init(void)
62{
Fabio Estevam1fa64862015-05-11 20:50:22 -030063 gd->ram_size = imx_ddr_size();
Fabio Estevam11027402013-03-15 10:43:48 +000064
65 return 0;
66}
67
68static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam1fa64862015-05-11 20:50:22 -030069 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
70 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000071};
72
Fabio Estevam11027402013-03-15 10:43:48 +000073static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevam1fa64862015-05-11 20:50:22 -030074 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
83 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
85 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
86 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
87 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
88 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000089 /* AR8031 PHY Reset */
Fabio Estevam1fa64862015-05-11 20:50:22 -030090 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevam11027402013-03-15 10:43:48 +000091};
92
Fabio Estevame40cb552017-10-02 15:47:29 -030093static iomux_v3_cfg_t const enet_ar8035_power_pads[] = {
94 /* AR8035 POWER */
95 IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96};
97
Fabio Estevamaec72fb2015-05-21 19:24:05 -030098static iomux_v3_cfg_t const rev_detection_pad[] = {
99 IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
100};
101
Fabio Estevam11027402013-03-15 10:43:48 +0000102static void setup_iomux_uart(void)
103{
Fabio Estevam1fa64862015-05-11 20:50:22 -0300104 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevam11027402013-03-15 10:43:48 +0000105}
106
107static void setup_iomux_enet(void)
108{
Fabio Estevam1fa64862015-05-11 20:50:22 -0300109 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevam11027402013-03-15 10:43:48 +0000110
Fabio Estevame40cb552017-10-02 15:47:29 -0300111 if (with_pmic) {
112 SETUP_IOMUX_PADS(enet_ar8035_power_pads);
113 /* enable AR8035 POWER */
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100114 gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER");
Fabio Estevame40cb552017-10-02 15:47:29 -0300115 gpio_direction_output(ETH_PHY_AR8035_POWER, 0);
116 }
117 /* wait until 3.3V of PHY and clock become stable */
118 mdelay(10);
119
Fabio Estevam11027402013-03-15 10:43:48 +0000120 /* Reset AR8031 PHY */
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100121 gpio_request(ETH_PHY_RESET, "PHY_RESET");
Fabio Estevam11027402013-03-15 10:43:48 +0000122 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam9f4c2522016-01-05 17:02:54 -0200123 mdelay(10);
Fabio Estevam11027402013-03-15 10:43:48 +0000124 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam9f4c2522016-01-05 17:02:54 -0200125 udelay(100);
Fabio Estevam11027402013-03-15 10:43:48 +0000126}
127
Fabio Estevam89303132016-11-01 14:58:16 -0200128static int ar8031_phy_fixup(struct phy_device *phydev)
129{
130 unsigned short val;
Fabio Estevame40cb552017-10-02 15:47:29 -0300131 int mask;
Fabio Estevam89303132016-11-01 14:58:16 -0200132
133 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
134 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
135 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
136 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
137
138 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
Fabio Estevame40cb552017-10-02 15:47:29 -0300139 if (with_pmic)
140 mask = 0xffe7; /* AR8035 */
141 else
142 mask = 0xffe3; /* AR8031 */
143
144 val &= mask;
Fabio Estevam89303132016-11-01 14:58:16 -0200145 val |= 0x18;
146 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
147
148 /* introduce tx clock delay */
149 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
150 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
151 val |= 0x0100;
152 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
153
154 return 0;
155}
156
157int board_phy_config(struct phy_device *phydev)
158{
159 ar8031_phy_fixup(phydev);
160
161 if (phydev->drv->config)
162 phydev->drv->config(phydev);
163
164 return 0;
165}
166
Fabio Estevam0296f282013-05-23 07:50:23 +0000167#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam1fa64862015-05-11 20:50:22 -0300168struct i2c_pads_info mx6q_i2c2_pad_info = {
Otavio Salvador1d744d92014-05-01 19:02:31 -0300169 .scl = {
Fabio Estevam1fa64862015-05-11 20:50:22 -0300170 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL
Otavio Salvador1d744d92014-05-01 19:02:31 -0300171 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam1fa64862015-05-11 20:50:22 -0300172 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12
Otavio Salvador1d744d92014-05-01 19:02:31 -0300173 | MUX_PAD_CTRL(I2C_PAD_CTRL),
174 .gp = IMX_GPIO_NR(4, 12)
175 },
176 .sda = {
Fabio Estevam1fa64862015-05-11 20:50:22 -0300177 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA
Otavio Salvador1d744d92014-05-01 19:02:31 -0300178 | MUX_PAD_CTRL(I2C_PAD_CTRL),
Fabio Estevam1fa64862015-05-11 20:50:22 -0300179 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13
Otavio Salvador1d744d92014-05-01 19:02:31 -0300180 | MUX_PAD_CTRL(I2C_PAD_CTRL),
181 .gp = IMX_GPIO_NR(4, 13)
182 }
Fabio Estevam0296f282013-05-23 07:50:23 +0000183};
184
Fabio Estevam1fa64862015-05-11 20:50:22 -0300185struct i2c_pads_info mx6dl_i2c2_pad_info = {
186 .scl = {
187 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL
188 | MUX_PAD_CTRL(I2C_PAD_CTRL),
189 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12
190 | MUX_PAD_CTRL(I2C_PAD_CTRL),
191 .gp = IMX_GPIO_NR(4, 12)
192 },
193 .sda = {
194 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA
195 | MUX_PAD_CTRL(I2C_PAD_CTRL),
196 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13
197 | MUX_PAD_CTRL(I2C_PAD_CTRL),
198 .gp = IMX_GPIO_NR(4, 13)
199 }
200};
Fabio Estevam0296f282013-05-23 07:50:23 +0000201
Fabio Estevame40cb552017-10-02 15:47:29 -0300202struct i2c_pads_info mx6q_i2c3_pad_info = {
203 .scl = {
204 .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL
205 | MUX_PAD_CTRL(I2C_PAD_CTRL),
206 .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05
207 | MUX_PAD_CTRL(I2C_PAD_CTRL),
208 .gp = IMX_GPIO_NR(1, 5)
209 },
210 .sda = {
211 .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA
212 | MUX_PAD_CTRL(I2C_PAD_CTRL),
213 .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11
214 | MUX_PAD_CTRL(I2C_PAD_CTRL),
215 .gp = IMX_GPIO_NR(7, 11)
216 }
217};
218
219struct i2c_pads_info mx6dl_i2c3_pad_info = {
220 .scl = {
221 .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL
222 | MUX_PAD_CTRL(I2C_PAD_CTRL),
223 .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05
224 | MUX_PAD_CTRL(I2C_PAD_CTRL),
225 .gp = IMX_GPIO_NR(1, 5)
226 },
227 .sda = {
228 .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA
229 | MUX_PAD_CTRL(I2C_PAD_CTRL),
230 .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11
231 | MUX_PAD_CTRL(I2C_PAD_CTRL),
232 .gp = IMX_GPIO_NR(7, 11)
233 }
234};
235
Fabio Estevam1fa64862015-05-11 20:50:22 -0300236static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = {
237 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
238 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */
239 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */
240 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */
241 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */
242 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
243 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
244 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
245 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
246 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
247 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
248 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
249 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
250 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
251 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
252 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
253 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
254 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
255 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
256 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
257 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
258 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
259 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
260 IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */
261 IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */
Otavio Salvador1d744d92014-05-01 19:02:31 -0300262};
Fabio Estevam0296f282013-05-23 07:50:23 +0000263
Otavio Salvador1d744d92014-05-01 19:02:31 -0300264static void do_enable_hdmi(struct display_info_t const *dev)
265{
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500266 imx_enable_hdmi_phy();
Otavio Salvador1d744d92014-05-01 19:02:31 -0300267}
Fabio Estevam0296f282013-05-23 07:50:23 +0000268
Otavio Salvador1d744d92014-05-01 19:02:31 -0300269static int detect_i2c(struct display_info_t const *dev)
270{
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100271#ifdef CONFIG_DM_I2C
272 struct udevice *bus, *udev;
273 int rc;
274
275 rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus);
276 if (rc)
277 return rc;
278 rc = dm_i2c_probe(bus, dev->addr, 0, &udev);
279 if (rc)
280 return 0;
281 return 1;
282#else
Otavio Salvador1d744d92014-05-01 19:02:31 -0300283 return (0 == i2c_set_bus_num(dev->bus)) &&
284 (0 == i2c_probe(dev->addr));
Anatolij Gustschin23e5eb72019-03-18 23:29:46 +0100285#endif
Otavio Salvador1d744d92014-05-01 19:02:31 -0300286}
287
288static void enable_fwadapt_7wvga(struct display_info_t const *dev)
289{
Fabio Estevam1fa64862015-05-11 20:50:22 -0300290 SETUP_IOMUX_PADS(fwadapt_7wvga_pads);
Otavio Salvador1d744d92014-05-01 19:02:31 -0300291
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100292 gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN");
293 gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN");
Otavio Salvador1d744d92014-05-01 19:02:31 -0300294 gpio_direction_output(IMX_GPIO_NR(2, 10), 1);
295 gpio_direction_output(IMX_GPIO_NR(2, 11), 1);
Fabio Estevam0296f282013-05-23 07:50:23 +0000296}
297
Otavio Salvador1d744d92014-05-01 19:02:31 -0300298struct display_info_t const displays[] = {{
299 .bus = -1,
300 .addr = 0,
301 .pixfmt = IPU_PIX_FMT_RGB24,
302 .detect = detect_hdmi,
303 .enable = do_enable_hdmi,
304 .mode = {
305 .name = "HDMI",
306 .refresh = 60,
307 .xres = 1024,
308 .yres = 768,
309 .pixclock = 15385,
310 .left_margin = 220,
311 .right_margin = 40,
312 .upper_margin = 21,
313 .lower_margin = 7,
314 .hsync_len = 60,
315 .vsync_len = 10,
316 .sync = FB_SYNC_EXT,
317 .vmode = FB_VMODE_NONINTERLACED
318} }, {
319 .bus = 1,
320 .addr = 0x10,
321 .pixfmt = IPU_PIX_FMT_RGB666,
322 .detect = detect_i2c,
323 .enable = enable_fwadapt_7wvga,
324 .mode = {
325 .name = "FWBADAPT-LCD-F07A-0102",
326 .refresh = 60,
327 .xres = 800,
328 .yres = 480,
329 .pixclock = 33260,
330 .left_margin = 128,
331 .right_margin = 128,
332 .upper_margin = 22,
333 .lower_margin = 22,
334 .hsync_len = 1,
335 .vsync_len = 1,
336 .sync = 0,
337 .vmode = FB_VMODE_NONINTERLACED
338} } };
339size_t display_count = ARRAY_SIZE(displays);
340
Fabio Estevam0296f282013-05-23 07:50:23 +0000341static void setup_display(void)
342{
343 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam0296f282013-05-23 07:50:23 +0000344 int reg;
345
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500346 enable_ipu_clock();
347 imx_setup_hdmi();
Fabio Estevam0296f282013-05-23 07:50:23 +0000348
349 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam0296f282013-05-23 07:50:23 +0000350 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500351 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam0296f282013-05-23 07:50:23 +0000352 writel(reg, &mxc_ccm->chsccdr);
Otavio Salvador1d744d92014-05-01 19:02:31 -0300353
354 /* Disable LCD backlight */
Fabio Estevam1fa64862015-05-11 20:50:22 -0300355 SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20);
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100356 gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN");
Otavio Salvador1d744d92014-05-01 19:02:31 -0300357 gpio_direction_input(IMX_GPIO_NR(4, 20));
Fabio Estevam0296f282013-05-23 07:50:23 +0000358}
359#endif /* CONFIG_VIDEO_IPUV3 */
360
Fabio Estevam11027402013-03-15 10:43:48 +0000361int board_eth_init(bd_t *bis)
362{
Fabio Estevam11027402013-03-15 10:43:48 +0000363 setup_iomux_enet();
364
Fabio Estevamc3cc3052014-01-04 17:36:28 -0200365 return cpu_eth_init(bis);
Fabio Estevam11027402013-03-15 10:43:48 +0000366}
367
368int board_early_init_f(void)
369{
370 setup_iomux_uart();
Simon Glassab3055a2017-06-14 21:28:25 -0600371#ifdef CONFIG_SATA
Fabio Estevama7d45152017-10-15 11:21:06 -0200372 setup_sata();
Gilles Chanteperdrixb99d6642016-06-09 10:33:27 +0200373#endif
374
Fabio Estevam11027402013-03-15 10:43:48 +0000375 return 0;
376}
377
Fabio Estevame40cb552017-10-02 15:47:29 -0300378#define PMIC_I2C_BUS 2
379
380int power_init_board(void)
381{
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100382 struct udevice *dev;
383 int reg, ret;
Fabio Estevame40cb552017-10-02 15:47:29 -0300384
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100385 puts("PMIC: ");
Fabio Estevame40cb552017-10-02 15:47:29 -0300386
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100387 ret = pmic_get("pfuze100", &dev);
388 if (ret < 0) {
389 printf("pmic_get() ret %d\n", ret);
390 return 0;
Fabio Estevame40cb552017-10-02 15:47:29 -0300391 }
392
Anatolij Gustschina0e9e842019-03-18 23:29:45 +0100393 reg = pmic_reg_read(dev, PFUZE100_DEVICEID);
394 if (reg < 0) {
395 printf("pmic_reg_read() ret %d\n", reg);
396 return 0;
397 }
398 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
399 with_pmic = true;
400
401 /* Set VGEN2 to 1.5V and enable */
402 reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL);
403 reg &= ~(LDO_VOL_MASK);
404 reg |= (LDOA_1_50V | (1 << (LDO_EN)));
405 pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg);
Fabio Estevame40cb552017-10-02 15:47:29 -0300406 return 0;
407}
408
Fabio Estevam0296f282013-05-23 07:50:23 +0000409/*
410 * Do not overwrite the console
411 * Use always serial for U-Boot console
412 */
413int overwrite_console(void)
414{
415 return 1;
416}
417
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000418#ifdef CONFIG_CMD_BMODE
419static const struct boot_mode board_boot_modes[] = {
420 /* 4 bit bus width */
421 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
422 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
423 {NULL, 0},
424};
425#endif
426
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300427static bool is_revc1(void)
428{
429 SETUP_IOMUX_PADS(rev_detection_pad);
430 gpio_direction_input(REV_DETECTION);
431
432 if (gpio_get_value(REV_DETECTION))
433 return true;
434 else
435 return false;
436}
437
Fabio Estevame40cb552017-10-02 15:47:29 -0300438static bool is_revd1(void)
439{
440 if (with_pmic)
441 return true;
442 else
443 return false;
444}
445
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000446int board_late_init(void)
447{
448#ifdef CONFIG_CMD_BMODE
449 add_board_boot_modes(board_boot_modes);
450#endif
451
Fabio Estevam1fa64862015-05-11 20:50:22 -0300452#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Fabio Estevama48538c2017-10-14 09:17:54 -0300453 if (is_mx6dqp())
454 env_set("board_rev", "MX6QP");
455 else if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600456 env_set("board_rev", "MX6Q");
Fabio Estevam1fa64862015-05-11 20:50:22 -0300457 else
Simon Glass6a38e412017-08-03 12:22:09 -0600458 env_set("board_rev", "MX6DL");
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300459
Fabio Estevame40cb552017-10-02 15:47:29 -0300460 if (is_revd1())
461 env_set("board_name", "D1");
462 else if (is_revc1())
Simon Glass6a38e412017-08-03 12:22:09 -0600463 env_set("board_name", "C1");
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300464 else
Simon Glass6a38e412017-08-03 12:22:09 -0600465 env_set("board_name", "B1");
Fabio Estevam1fa64862015-05-11 20:50:22 -0300466#endif
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000467 return 0;
468}
469
Fabio Estevam11027402013-03-15 10:43:48 +0000470int board_init(void)
471{
472 /* address of boot parameters */
473 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
474
Sven Ebenfeld4747d152016-11-25 21:42:53 +0100475#if defined(CONFIG_VIDEO_IPUV3)
Trent Piephobcbf1ac2019-05-08 23:30:01 +0000476 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
Fabio Estevama48538c2017-10-14 09:17:54 -0300477 if (is_mx6dq() || is_mx6dqp()) {
Trent Piephobcbf1ac2019-05-08 23:30:01 +0000478 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6q_i2c2_pad_info);
479 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6q_i2c3_pad_info);
Fabio Estevame40cb552017-10-02 15:47:29 -0300480 } else {
Trent Piephobcbf1ac2019-05-08 23:30:01 +0000481 setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info);
482 setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6dl_i2c3_pad_info);
Fabio Estevame40cb552017-10-02 15:47:29 -0300483 }
Fabio Estevamf7c09722017-09-22 23:45:30 -0300484
485 setup_display();
Sven Ebenfeld4747d152016-11-25 21:42:53 +0100486#endif
Otavio Salvador1d744d92014-05-01 19:02:31 -0300487
Fabio Estevam11027402013-03-15 10:43:48 +0000488 return 0;
489}
490
Fabio Estevam11027402013-03-15 10:43:48 +0000491int checkboard(void)
492{
Anatolij Gustschinf396e2c2019-03-18 23:29:42 +0100493 gpio_request(REV_DETECTION, "REV_DETECT");
494
Fabio Estevame40cb552017-10-02 15:47:29 -0300495 if (is_revd1())
496 puts("Board: Wandboard rev D1\n");
497 else if (is_revc1())
Fabio Estevamaec72fb2015-05-21 19:24:05 -0300498 puts("Board: Wandboard rev C1\n");
499 else
500 puts("Board: Wandboard rev B1\n");
Fabio Estevam11027402013-03-15 10:43:48 +0000501
502 return 0;
503}
Fabio Estevamdc180c72019-06-12 12:34:40 -0300504
505#ifdef CONFIG_SPL_LOAD_FIT
506int board_fit_config_name_match(const char *name)
507{
508 if (is_mx6dq()) {
509 if (!strcmp(name, "imx6q-wandboard-revb1"))
510 return 0;
511 } else if (is_mx6dqp()) {
512 if (!strcmp(name, "imx6qp-wandboard-revd1"))
513 return 0;
514 } else if (is_mx6dl() || is_mx6solo()) {
515 if (!strcmp(name, "imx6dl-wandboard-revb1"))
516 return 0;
517 }
518
519 return -EINVAL;
520}
521#endif