blob: df2d22b61fe1444617cdfdce2927b7b27d541763 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Akshay Bhat197f9872016-01-29 15:16:40 -05002/*
3 * Copyright 2015 Timesys Corporation
4 * Copyright 2015 General Electric Company
5 * Copyright 2012 Freescale Semiconductor, Inc.
Akshay Bhat197f9872016-01-29 15:16:40 -05006 */
7
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Akshay Bhat197f9872016-01-29 15:16:40 -05009#include <asm/arch/clock.h>
10#include <asm/arch/imx-regs.h>
11#include <asm/arch/iomux.h>
12#include <asm/arch/mx6-pins.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Ian Ray64450942019-01-31 16:21:18 +020015#include <linux/libfdt.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050016#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/mxc_i2c.h>
18#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/video.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050021#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080022#include <fsl_esdhc_imx.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050023#include <miiphy.h>
Martyn Welch18c31ea2018-01-10 20:31:30 +010024#include <net.h>
Akshay Bhat197f9872016-01-29 15:16:40 -050025#include <netdev.h>
26#include <asm/arch/mxc_hdmi.h>
27#include <asm/arch/crm_regs.h>
28#include <asm/io.h>
29#include <asm/arch/sys_proto.h>
30#include <i2c.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030031#include <input.h>
Akshay Bhat5d643622016-04-12 18:13:59 -040032#include <pwm.h>
Ian Ray64450942019-01-31 16:21:18 +020033#include <version.h>
Ian Rayc0293da2017-08-22 09:03:54 +030034#include <stdlib.h>
Robert Beckettf746ab62019-11-12 19:15:11 +000035#include <dm/root.h>
Nandor Hanae3c6d22018-01-10 20:31:38 +010036#include "../common/ge_common.h"
Martyn Welch66697ce2017-11-08 15:35:15 +000037#include "../common/vpd_reader.h"
Hannu Lounento37879682018-01-10 20:31:31 +010038#include "../../../drivers/net/e1000.h"
Akshay Bhat197f9872016-01-29 15:16:40 -050039DECLARE_GLOBAL_DATA_PTR;
40
Robert Beckettf746ab62019-11-12 19:15:11 +000041static int confidx; /* Default to generic. */
Nandor Han7a9bb302018-04-25 16:57:01 +020042static struct vpd_cache vpd;
43
Justin Watersef93fc22016-04-13 17:03:18 -040044#define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
45 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
46 PAD_CTL_HYS)
47
Akshay Bhat197f9872016-01-29 15:16:40 -050048#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
50 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
51
Akshay Bhat197f9872016-01-29 15:16:40 -050052#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
53 PAD_CTL_SPEED_HIGH | PAD_CTL_DSE_48ohm | PAD_CTL_SRE_FAST)
54
55#define ENET_CLK_PAD_CTRL (PAD_CTL_SPEED_MED | \
56 PAD_CTL_DSE_120ohm | PAD_CTL_SRE_FAST)
57
58#define ENET_RX_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
59 PAD_CTL_SPEED_HIGH | PAD_CTL_SRE_FAST)
60
Akshay Bhat197f9872016-01-29 15:16:40 -050061#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
62 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
63 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
64
65#define I2C_PAD MUX_PAD_CTRL(I2C_PAD_CTRL)
66
67int dram_init(void)
68{
Fabio Estevamdd5d4e42016-07-23 13:23:40 -030069 gd->ram_size = imx_ddr_size();
Akshay Bhat197f9872016-01-29 15:16:40 -050070
71 return 0;
72}
73
74static iomux_v3_cfg_t const uart3_pads[] = {
75 MX6_PAD_EIM_D31__UART3_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL),
76 MX6_PAD_EIM_D23__UART3_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL),
77 MX6_PAD_EIM_D24__UART3_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
78 MX6_PAD_EIM_D25__UART3_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
79};
80
81static iomux_v3_cfg_t const uart4_pads[] = {
82 MX6_PAD_KEY_COL0__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
83 MX6_PAD_KEY_ROW0__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
84};
85
86static iomux_v3_cfg_t const enet_pads[] = {
87 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
88 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
89 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
90 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
91 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
92 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
93 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
94 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
95 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),
96 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
97 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
98 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
99 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
100 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
101 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
102 /* AR8033 PHY Reset */
103 MX6_PAD_ENET_TX_EN__GPIO1_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL),
104};
105
106static void setup_iomux_enet(void)
107{
108 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
109
110 /* Reset AR8033 PHY */
Ian Ray5f1e3442019-01-31 16:21:13 +0200111 gpio_request(IMX_GPIO_NR(1, 28), "fec_rst");
Akshay Bhat197f9872016-01-29 15:16:40 -0500112 gpio_direction_output(IMX_GPIO_NR(1, 28), 0);
Yung-Ching LINca3d01c2017-02-21 09:56:55 +0800113 mdelay(10);
Akshay Bhat197f9872016-01-29 15:16:40 -0500114 gpio_set_value(IMX_GPIO_NR(1, 28), 1);
Yung-Ching LINca3d01c2017-02-21 09:56:55 +0800115 mdelay(1);
Akshay Bhat197f9872016-01-29 15:16:40 -0500116}
117
Akshay Bhat197f9872016-01-29 15:16:40 -0500118static struct i2c_pads_info i2c_pad_info1 = {
119 .scl = {
120 .i2c_mode = MX6_PAD_CSI0_DAT9__I2C1_SCL | I2C_PAD,
121 .gpio_mode = MX6_PAD_CSI0_DAT9__GPIO5_IO27 | I2C_PAD,
122 .gp = IMX_GPIO_NR(5, 27)
123 },
124 .sda = {
125 .i2c_mode = MX6_PAD_CSI0_DAT8__I2C1_SDA | I2C_PAD,
126 .gpio_mode = MX6_PAD_CSI0_DAT8__GPIO5_IO26 | I2C_PAD,
127 .gp = IMX_GPIO_NR(5, 26)
128 }
129};
130
131static struct i2c_pads_info i2c_pad_info2 = {
132 .scl = {
133 .i2c_mode = MX6_PAD_KEY_COL3__I2C2_SCL | I2C_PAD,
134 .gpio_mode = MX6_PAD_KEY_COL3__GPIO4_IO12 | I2C_PAD,
135 .gp = IMX_GPIO_NR(4, 12)
136 },
137 .sda = {
138 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | I2C_PAD,
139 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO4_IO13 | I2C_PAD,
140 .gp = IMX_GPIO_NR(4, 13)
141 }
142};
143
144static struct i2c_pads_info i2c_pad_info3 = {
145 .scl = {
146 .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | I2C_PAD,
147 .gpio_mode = MX6_PAD_GPIO_3__GPIO1_IO03 | I2C_PAD,
148 .gp = IMX_GPIO_NR(1, 3)
149 },
150 .sda = {
151 .i2c_mode = MX6_PAD_GPIO_6__I2C3_SDA | I2C_PAD,
152 .gpio_mode = MX6_PAD_GPIO_6__GPIO1_IO06 | I2C_PAD,
153 .gp = IMX_GPIO_NR(1, 6)
154 }
155};
156
Akshay Bhat197f9872016-01-29 15:16:40 -0500157static iomux_v3_cfg_t const pcie_pads[] = {
158 MX6_PAD_GPIO_5__GPIO1_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL),
159 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(NO_PAD_CTRL),
160};
161
162static void setup_pcie(void)
163{
164 imx_iomux_v3_setup_multiple_pads(pcie_pads, ARRAY_SIZE(pcie_pads));
165}
166
167static void setup_iomux_uart(void)
168{
169 imx_iomux_v3_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
170 imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads));
171}
172
Akshay Bhat197f9872016-01-29 15:16:40 -0500173static int mx6_rgmii_rework(struct phy_device *phydev)
174{
175 /* Configure AR8033 to ouput a 125MHz clk from CLK_25M */
176 /* set device address 0x7 */
177 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
178 /* offset 0x8016: CLK_25M Clock Select */
179 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
180 /* enable register write, no post increment, address 0x7 */
181 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
182 /* set to 125 MHz from local PLL source */
183 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x18);
184
185 /* rgmii tx clock delay enable */
186 /* set debug port address: SerDes Test and System Mode Control */
187 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
188 /* enable rgmii tx clock delay */
Yung-Ching LIN48652c82017-02-21 09:56:56 +0800189 /* set the reserved bits to avoid board specific voltage peak issue*/
190 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x3D47);
Akshay Bhat197f9872016-01-29 15:16:40 -0500191
192 return 0;
193}
194
195int board_phy_config(struct phy_device *phydev)
196{
197 mx6_rgmii_rework(phydev);
198
199 if (phydev->drv->config)
200 phydev->drv->config(phydev);
201
202 return 0;
203}
204
205#if defined(CONFIG_VIDEO_IPUV3)
206static iomux_v3_cfg_t const backlight_pads[] = {
207 /* Power for LVDS Display */
208 MX6_PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
209#define LVDS_POWER_GP IMX_GPIO_NR(3, 22)
210 /* Backlight enable for LVDS display */
211 MX6_PAD_GPIO_0__GPIO1_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL),
212#define LVDS_BACKLIGHT_GP IMX_GPIO_NR(1, 0)
Akshay Bhat5d643622016-04-12 18:13:59 -0400213 /* backlight PWM brightness control */
214 MX6_PAD_SD1_DAT3__PWM1_OUT | MUX_PAD_CTRL(NO_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500215};
216
217static void do_enable_hdmi(struct display_info_t const *dev)
218{
219 imx_enable_hdmi_phy();
220}
221
Ian Ray6eac23f2018-04-25 16:57:02 +0200222static int is_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500223{
Ian Ray6eac23f2018-04-25 16:57:02 +0200224 return confidx == 3;
225}
Akshay Bhat197f9872016-01-29 15:16:40 -0500226
Ian Ray6eac23f2018-04-25 16:57:02 +0200227static int detect_lcd(struct display_info_t const *dev)
228{
229 return !is_b850v3();
Akshay Bhat197f9872016-01-29 15:16:40 -0500230}
231
232struct display_info_t const displays[] = {{
233 .bus = -1,
234 .addr = -1,
235 .pixfmt = IPU_PIX_FMT_RGB24,
Ian Rayf8e4fab2018-04-25 16:56:58 +0200236 .detect = detect_lcd,
Akshay Bhat197f9872016-01-29 15:16:40 -0500237 .enable = NULL,
238 .mode = {
239 .name = "G121X1-L03",
240 .refresh = 60,
241 .xres = 1024,
242 .yres = 768,
243 .pixclock = 15385,
244 .left_margin = 20,
245 .right_margin = 300,
246 .upper_margin = 30,
247 .lower_margin = 8,
248 .hsync_len = 1,
249 .vsync_len = 1,
250 .sync = FB_SYNC_EXT,
251 .vmode = FB_VMODE_NONINTERLACED
252} }, {
253 .bus = -1,
254 .addr = 3,
255 .pixfmt = IPU_PIX_FMT_RGB24,
256 .detect = detect_hdmi,
257 .enable = do_enable_hdmi,
258 .mode = {
259 .name = "HDMI",
260 .refresh = 60,
261 .xres = 1024,
262 .yres = 768,
263 .pixclock = 15385,
264 .left_margin = 220,
265 .right_margin = 40,
266 .upper_margin = 21,
267 .lower_margin = 7,
268 .hsync_len = 60,
269 .vsync_len = 10,
270 .sync = FB_SYNC_EXT,
271 .vmode = FB_VMODE_NONINTERLACED
272} } };
273size_t display_count = ARRAY_SIZE(displays);
274
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400275static void enable_videopll(void)
276{
277 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
278 s32 timeout = 100000;
279
280 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
281
Ian Ray28540c52018-10-15 09:59:44 +0200282 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
283 * |
284 * PLL5
285 * |
286 * CS2CDR[LDB_DI0_CLK_SEL]
287 * |
288 * +----> LDB_DI0_SERIAL_CLK_ROOT
289 * |
290 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
291 */
292
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400293 clrsetbits_le32(&ccm->analog_pll_video,
294 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
295 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
296 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
Ian Ray28540c52018-10-15 09:59:44 +0200297 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400298
299 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
300 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
301
302 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
303
304 while (timeout--)
305 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
306 break;
307
308 if (timeout < 0)
309 printf("Warning: video pll lock timeout!\n");
310
311 clrsetbits_le32(&ccm->analog_pll_video,
312 BM_ANADIG_PLL_VIDEO_BYPASS,
313 BM_ANADIG_PLL_VIDEO_ENABLE);
314}
315
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400316static void setup_display_b850v3(void)
Akshay Bhat197f9872016-01-29 15:16:40 -0500317{
318 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
319 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500320
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400321 enable_videopll();
322
Ian Ray28540c52018-10-15 09:59:44 +0200323 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
324 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400325
Akshay Bhat197f9872016-01-29 15:16:40 -0500326 imx_setup_hdmi();
327
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400328 /* Set LDB_DI0 as clock source for IPU_DI0 */
329 clrsetbits_le32(&mxc_ccm->chsccdr,
330 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
331 (CHSCCDR_CLK_SEL_LDB_DI0 <<
332 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500333
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400334 /* Turn on IPU LDB DI0 clocks */
335 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
336
337 enable_ipu_clock();
Akshay Bhat197f9872016-01-29 15:16:40 -0500338
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400339 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
340 IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
341 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
342 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
343 IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT |
344 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
345 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
346 IOMUXC_GPR2_SPLIT_MODE_EN_MASK |
347 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
348 IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0,
349 &iomux->gpr[2]);
Akshay Bhat197f9872016-01-29 15:16:40 -0500350
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400351 clrbits_le32(&iomux->gpr[3],
352 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
353 IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
354 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
355}
Akshay Bhat197f9872016-01-29 15:16:40 -0500356
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400357static void setup_display_bx50v3(void)
358{
359 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
360 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Akshay Bhat197f9872016-01-29 15:16:40 -0500361
Ian Ray66395e82018-04-25 16:57:00 +0200362 enable_videopll();
363
Akshay Bhat66027fe2016-04-12 18:14:00 -0400364 /* When a reset/reboot is performed the display power needs to be turned
365 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
366 * an additional 200ms here. Unfortunately we use external PMIC for
367 * doing the reset, so can not differentiate between POR vs soft reset
368 */
369 mdelay(200);
370
Ian Ray28540c52018-10-15 09:59:44 +0200371 /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400372 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
373
374 /* Set LDB_DI0 as clock source for IPU_DI0 */
375 clrsetbits_le32(&mxc_ccm->chsccdr,
376 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
377 (CHSCCDR_CLK_SEL_LDB_DI0 <<
378 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
379
380 /* Turn on IPU LDB DI0 clocks */
381 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
382
383 enable_ipu_clock();
384
385 writel(IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
386 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
387 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
388 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
389 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
390 &iomux->gpr[2]);
391
392 clrsetbits_le32(&iomux->gpr[3],
393 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
394 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
395 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
Akshay Bhat197f9872016-01-29 15:16:40 -0500396
397 /* backlights off until needed */
398 imx_iomux_v3_setup_multiple_pads(backlight_pads,
399 ARRAY_SIZE(backlight_pads));
Ian Ray5f1e3442019-01-31 16:21:13 +0200400 gpio_request(LVDS_POWER_GP, "lvds_power");
Akshay Bhat197f9872016-01-29 15:16:40 -0500401 gpio_direction_input(LVDS_POWER_GP);
Akshay Bhat197f9872016-01-29 15:16:40 -0500402}
403#endif /* CONFIG_VIDEO_IPUV3 */
404
405/*
406 * Do not overwrite the console
407 * Use always serial for U-Boot console
408 */
409int overwrite_console(void)
410{
411 return 1;
412}
413
Ian Rayc0293da2017-08-22 09:03:54 +0300414#define VPD_TYPE_INVALID 0x00
415#define VPD_BLOCK_NETWORK 0x20
416#define VPD_BLOCK_HWID 0x44
417#define VPD_PRODUCT_B850 1
418#define VPD_PRODUCT_B650 2
419#define VPD_PRODUCT_B450 3
Martyn Welch18c31ea2018-01-10 20:31:30 +0100420#define VPD_HAS_MAC1 0x1
Hannu Lounento37879682018-01-10 20:31:31 +0100421#define VPD_HAS_MAC2 0x2
Martyn Welch18c31ea2018-01-10 20:31:30 +0100422#define VPD_MAC_ADDRESS_LENGTH 6
Ian Rayc0293da2017-08-22 09:03:54 +0300423
424struct vpd_cache {
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200425 bool is_read;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100426 u8 product_id;
427 u8 has;
428 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
Hannu Lounento37879682018-01-10 20:31:31 +0100429 unsigned char mac2[VPD_MAC_ADDRESS_LENGTH];
Ian Rayc0293da2017-08-22 09:03:54 +0300430};
431
432/*
433 * Extracts MAC and product information from the VPD.
434 */
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200435static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
Martyn Welch18c31ea2018-01-10 20:31:30 +0100436 size_t size, u8 const *data)
Ian Rayc0293da2017-08-22 09:03:54 +0300437{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100438 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
439 size >= 1) {
Ian Rayc0293da2017-08-22 09:03:54 +0300440 vpd->product_id = data[0];
Martyn Welch18c31ea2018-01-10 20:31:30 +0100441 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
442 type != VPD_TYPE_INVALID) {
443 if (size >= 6) {
444 vpd->has |= VPD_HAS_MAC1;
445 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
446 }
Hannu Lounento37879682018-01-10 20:31:31 +0100447 if (size >= 12) {
448 vpd->has |= VPD_HAS_MAC2;
449 memcpy(vpd->mac2, data + 6, VPD_MAC_ADDRESS_LENGTH);
450 }
Ian Rayc0293da2017-08-22 09:03:54 +0300451 }
452
453 return 0;
454}
455
Ian Rayc0293da2017-08-22 09:03:54 +0300456static void process_vpd(struct vpd_cache *vpd)
457{
Martyn Welch18c31ea2018-01-10 20:31:30 +0100458 int fec_index = -1;
Hannu Lounento37879682018-01-10 20:31:31 +0100459 int i210_index = -1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100460
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200461 if (!vpd->is_read) {
462 printf("VPD wasn't read");
463 return;
464 }
465
Martyn Welch18c31ea2018-01-10 20:31:30 +0100466 switch (vpd->product_id) {
467 case VPD_PRODUCT_B450:
Ian Rayb52e2522018-01-10 20:31:33 +0100468 env_set("confidx", "1");
Nandor Hanf335ae92018-04-25 16:56:59 +0200469 i210_index = 0;
470 fec_index = 1;
Ian Rayb52e2522018-01-10 20:31:33 +0100471 break;
472 case VPD_PRODUCT_B650:
473 env_set("confidx", "2");
Hannu Lounento37879682018-01-10 20:31:31 +0100474 i210_index = 0;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100475 fec_index = 1;
476 break;
477 case VPD_PRODUCT_B850:
Nandor Hanf335ae92018-04-25 16:56:59 +0200478 env_set("confidx", "3");
Hannu Lounento37879682018-01-10 20:31:31 +0100479 i210_index = 1;
Martyn Welch18c31ea2018-01-10 20:31:30 +0100480 fec_index = 2;
481 break;
Ian Rayc0293da2017-08-22 09:03:54 +0300482 }
Martyn Welch18c31ea2018-01-10 20:31:30 +0100483
484 if (fec_index >= 0 && (vpd->has & VPD_HAS_MAC1))
485 eth_env_set_enetaddr_by_index("eth", fec_index, vpd->mac1);
Hannu Lounento37879682018-01-10 20:31:31 +0100486
487 if (i210_index >= 0 && (vpd->has & VPD_HAS_MAC2))
488 eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2);
Ian Rayc0293da2017-08-22 09:03:54 +0300489}
490
Akshay Bhat197f9872016-01-29 15:16:40 -0500491int board_eth_init(bd_t *bis)
492{
493 setup_iomux_enet();
494 setup_pcie();
495
Hannu Lounento37879682018-01-10 20:31:31 +0100496 e1000_initialize(bis);
497
Akshay Bhat197f9872016-01-29 15:16:40 -0500498 return cpu_eth_init(bis);
499}
500
501static iomux_v3_cfg_t const misc_pads[] = {
502 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
Justin Watersef93fc22016-04-13 17:03:18 -0400503 MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NC_PAD_CTRL),
504 MX6_PAD_EIM_CS0__GPIO2_IO23 | MUX_PAD_CTRL(NC_PAD_CTRL),
505 MX6_PAD_EIM_CS1__GPIO2_IO24 | MUX_PAD_CTRL(NC_PAD_CTRL),
506 MX6_PAD_EIM_OE__GPIO2_IO25 | MUX_PAD_CTRL(NC_PAD_CTRL),
507 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NC_PAD_CTRL),
508 MX6_PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NC_PAD_CTRL),
Martyn Welch110f5d92018-01-10 20:31:32 +0100509 MX6_PAD_GPIO_9__WDOG1_B | MUX_PAD_CTRL(NC_PAD_CTRL),
Akshay Bhat197f9872016-01-29 15:16:40 -0500510};
511#define SUS_S3_OUT IMX_GPIO_NR(4, 11)
512#define WIFI_EN IMX_GPIO_NR(6, 14)
513
514int board_early_init_f(void)
515{
516 imx_iomux_v3_setup_multiple_pads(misc_pads,
517 ARRAY_SIZE(misc_pads));
518
519 setup_iomux_uart();
520
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400521#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray28540c52018-10-15 09:59:44 +0200522 /* Set LDB clock to Video PLL */
523 select_ldb_di_clock_source(MXC_PLL5_CLK);
Akshay Bhat3a5b15a2016-04-12 18:13:58 -0400524#endif
Akshay Bhat197f9872016-01-29 15:16:40 -0500525 return 0;
526}
527
Nandor Han7a9bb302018-04-25 16:57:01 +0200528static void set_confidx(const struct vpd_cache* vpd)
529{
530 switch (vpd->product_id) {
531 case VPD_PRODUCT_B450:
532 confidx = 1;
533 break;
534 case VPD_PRODUCT_B650:
535 confidx = 2;
536 break;
537 case VPD_PRODUCT_B850:
538 confidx = 3;
539 break;
540 }
541}
542
Akshay Bhat197f9872016-01-29 15:16:40 -0500543int board_init(void)
544{
Dan Cimpoca42e8d8f2018-10-15 12:09:56 +0200545 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
546 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
547 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3);
Nandor Han7a9bb302018-04-25 16:57:01 +0200548
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200549 if (!read_vpd(&vpd, vpd_callback)) {
Robert Beckettf746ab62019-11-12 19:15:11 +0000550 int ret, rescan;
551
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200552 vpd.is_read = true;
553 set_confidx(&vpd);
Robert Beckettf746ab62019-11-12 19:15:11 +0000554
555 ret = fdtdec_resetup(&rescan);
556 if (!ret && rescan) {
557 dm_uninit();
558 dm_init_and_scan(false);
559 }
Denis Zalevskiy22a347d2018-10-17 10:33:30 +0200560 }
Nandor Han7a9bb302018-04-25 16:57:01 +0200561
Ian Ray5f1e3442019-01-31 16:21:13 +0200562 gpio_request(SUS_S3_OUT, "sus_s3_out");
Akshay Bhat197f9872016-01-29 15:16:40 -0500563 gpio_direction_output(SUS_S3_OUT, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200564
565 gpio_request(WIFI_EN, "wifi_en");
Akshay Bhat197f9872016-01-29 15:16:40 -0500566 gpio_direction_output(WIFI_EN, 1);
Ian Ray5f1e3442019-01-31 16:21:13 +0200567
Akshay Bhat197f9872016-01-29 15:16:40 -0500568#if defined(CONFIG_VIDEO_IPUV3)
Ian Ray6eac23f2018-04-25 16:57:02 +0200569 if (is_b850v3())
Akshay Bhatcc4e4b62016-04-12 18:13:57 -0400570 setup_display_b850v3();
571 else
572 setup_display_bx50v3();
Ian Ray5f1e3442019-01-31 16:21:13 +0200573
574 gpio_request(LVDS_BACKLIGHT_GP, "lvds_backlight");
575 gpio_direction_input(LVDS_BACKLIGHT_GP);
Akshay Bhat197f9872016-01-29 15:16:40 -0500576#endif
Ian Ray5f1e3442019-01-31 16:21:13 +0200577
Akshay Bhat197f9872016-01-29 15:16:40 -0500578 /* address of boot parameters */
579 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
580
Akshay Bhat197f9872016-01-29 15:16:40 -0500581 return 0;
582}
583
584#ifdef CONFIG_CMD_BMODE
585static const struct boot_mode board_boot_modes[] = {
586 /* 4 bit bus width */
587 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
588 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
589 {NULL, 0},
590};
591#endif
592
Ken Linc7219fc2016-11-18 12:20:54 -0500593void pmic_init(void)
594{
595#define I2C_PMIC 0x2
596#define DA9063_I2C_ADDR 0x58
597#define DA9063_REG_BCORE2_CFG 0x9D
598#define DA9063_REG_BCORE1_CFG 0x9E
599#define DA9063_REG_BPRO_CFG 0x9F
600#define DA9063_REG_BIO_CFG 0xA0
601#define DA9063_REG_BMEM_CFG 0xA1
602#define DA9063_REG_BPERI_CFG 0xA2
603#define DA9063_BUCK_MODE_MASK 0xC0
604#define DA9063_BUCK_MODE_MANUAL 0x00
605#define DA9063_BUCK_MODE_SLEEP 0x40
606#define DA9063_BUCK_MODE_SYNC 0x80
607#define DA9063_BUCK_MODE_AUTO 0xC0
608
609 uchar val;
610
611 i2c_set_bus_num(I2C_PMIC);
612
613 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BCORE2_CFG, 1, &val, 1);
614 val &= ~DA9063_BUCK_MODE_MASK;
615 val |= DA9063_BUCK_MODE_SYNC;
616 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BCORE2_CFG, 1, &val, 1);
617
618 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BCORE1_CFG, 1, &val, 1);
619 val &= ~DA9063_BUCK_MODE_MASK;
620 val |= DA9063_BUCK_MODE_SYNC;
621 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BCORE1_CFG, 1, &val, 1);
622
623 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BPRO_CFG, 1, &val, 1);
624 val &= ~DA9063_BUCK_MODE_MASK;
625 val |= DA9063_BUCK_MODE_SYNC;
626 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BPRO_CFG, 1, &val, 1);
627
628 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BIO_CFG, 1, &val, 1);
629 val &= ~DA9063_BUCK_MODE_MASK;
630 val |= DA9063_BUCK_MODE_SYNC;
631 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BIO_CFG, 1, &val, 1);
632
633 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BMEM_CFG, 1, &val, 1);
634 val &= ~DA9063_BUCK_MODE_MASK;
635 val |= DA9063_BUCK_MODE_SYNC;
636 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BMEM_CFG, 1, &val, 1);
637
638 i2c_read(DA9063_I2C_ADDR, DA9063_REG_BPERI_CFG, 1, &val, 1);
639 val &= ~DA9063_BUCK_MODE_MASK;
640 val |= DA9063_BUCK_MODE_SYNC;
641 i2c_write(DA9063_I2C_ADDR, DA9063_REG_BPERI_CFG, 1, &val, 1);
642}
643
Akshay Bhat197f9872016-01-29 15:16:40 -0500644int board_late_init(void)
645{
Nandor Han7a9bb302018-04-25 16:57:01 +0200646 process_vpd(&vpd);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100647
Akshay Bhat197f9872016-01-29 15:16:40 -0500648#ifdef CONFIG_CMD_BMODE
649 add_board_boot_modes(board_boot_modes);
650#endif
Andrew Shadurac26583d2016-05-24 15:56:17 +0200651
Ian Rayd8c60992018-04-25 16:57:03 +0200652 if (is_b850v3())
653 env_set("videoargs", "video=DP-1:1024x768@60 video=HDMI-A-1:1024x768@60");
Ian Ray476e4e62018-10-15 09:59:45 +0200654 else
655 env_set("videoargs", "video=LVDS-1:1024x768@65");
Ian Rayd8c60992018-04-25 16:57:03 +0200656
Ken Linc7219fc2016-11-18 12:20:54 -0500657 /* board specific pmic init */
658 pmic_init();
659
Nandor Hanae3c6d22018-01-10 20:31:38 +0100660 check_time();
661
Akshay Bhat197f9872016-01-29 15:16:40 -0500662 return 0;
663}
664
Hannu Lounento37879682018-01-10 20:31:31 +0100665/*
666 * Removes the 'eth[0-9]*addr' environment variable with the given index
667 *
668 * @param index [in] the index of the eth_device whose variable is to be removed
669 */
670static void remove_ethaddr_env_var(int index)
671{
672 char env_var_name[9];
673
674 sprintf(env_var_name, index == 0 ? "ethaddr" : "eth%daddr", index);
675 env_set(env_var_name, NULL);
676}
677
Martyn Welch18c31ea2018-01-10 20:31:30 +0100678int last_stage_init(void)
679{
Hannu Lounento37879682018-01-10 20:31:31 +0100680 int i;
681
682 /*
683 * Remove first three ethaddr which may have been created by
684 * function process_vpd().
685 */
686 for (i = 0; i < 3; ++i)
687 remove_ethaddr_env_var(i);
Martyn Welch18c31ea2018-01-10 20:31:30 +0100688
689 return 0;
690}
691
Akshay Bhat197f9872016-01-29 15:16:40 -0500692int checkboard(void)
693{
694 printf("BOARD: %s\n", CONFIG_BOARD_NAME);
695 return 0;
696}
Ian Ray40133682018-04-04 10:50:17 +0200697
Ian Ray64450942019-01-31 16:21:18 +0200698#ifdef CONFIG_OF_BOARD_SETUP
699int ft_board_setup(void *blob, bd_t *bd)
700{
701 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
702 strlen(version_string) + 1);
703 return 0;
704}
705#endif
706
Ian Ray40133682018-04-04 10:50:17 +0200707static int do_backlight_enable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
708{
Ian Rayb7f96252019-11-12 19:15:15 +0000709#if CONFIG_IS_ENABLED(DM_VIDEO)
710 int ret;
711 struct udevice *dev;
712
Ian Ray40133682018-04-04 10:50:17 +0200713#ifdef CONFIG_VIDEO_IPUV3
Ian Ray8f198da2019-11-12 19:15:14 +0000714 if (!is_b850v3()) {
Ian Rayb7f96252019-11-12 19:15:15 +0000715 gpio_direction_output(LVDS_POWER_GP, 1);
716
Ian Ray8f198da2019-11-12 19:15:14 +0000717 /* We need at least 200ms between power on and backlight on
718 * as per specifications from CHI MEI
719 */
720 mdelay(250);
Ian Ray40133682018-04-04 10:50:17 +0200721
Ian Ray8f198da2019-11-12 19:15:14 +0000722 /* enable backlight PWM 1 */
723 pwm_init(0, 0, 0);
Ian Ray40133682018-04-04 10:50:17 +0200724
Ian Ray8f198da2019-11-12 19:15:14 +0000725 /* duty cycle 5000000ns, period: 5000000ns */
726 pwm_config(0, 5000000, 5000000);
Ian Ray40133682018-04-04 10:50:17 +0200727
Ian Ray8f198da2019-11-12 19:15:14 +0000728 /* Backlight Power */
729 gpio_direction_output(LVDS_BACKLIGHT_GP, 1);
Ian Ray40133682018-04-04 10:50:17 +0200730
Ian Ray8f198da2019-11-12 19:15:14 +0000731 pwm_enable(0);
732 }
Ian Ray40133682018-04-04 10:50:17 +0200733#endif
734
Ian Rayb7f96252019-11-12 19:15:15 +0000735 /* Probe, to find a video device to be used to show a message on
736 * the vidconsole.
737 */
738 ret = uclass_get_device(UCLASS_VIDEO, 0, &dev);
739 if (ret)
740 return ret;
741#endif
742
Ian Ray40133682018-04-04 10:50:17 +0200743 return 0;
744}
745
746U_BOOT_CMD(
747 bx50_backlight_enable, 1, 1, do_backlight_enable,
748 "enable Bx50 backlight",
749 ""
750);
Robert Beckettf746ab62019-11-12 19:15:11 +0000751
752int board_fit_config_name_match(const char *name)
753{
754 if (!vpd.is_read)
755 return strcmp(name, "imx6q-bx50v3");
756
757 switch (vpd.product_id) {
758 case VPD_PRODUCT_B450:
759 return strcmp(name, "imx6q-b450v3");
760 case VPD_PRODUCT_B650:
761 return strcmp(name, "imx6q-b650v3");
762 case VPD_PRODUCT_B850:
763 return strcmp(name, "imx6q-b850v3");
764 default:
765 return -1;
766 }
767}
768
769int embedded_dtb_select(void)
770{
771 vpd.is_read = false;
772 return fdtdec_setup();
773}