blob: 140f24459d75fb2dee3f8bb43ee987a361c0c550 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevamafe20bf2012-09-24 08:09:33 +00002/*
3 * Copyright (C) 2012 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevamafe20bf2012-09-24 08:09:33 +00006 */
7
8#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Fabio Estevamafe20bf2012-09-24 08:09:33 +000010#include <asm/io.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
Eric Nelson24ded0c2013-11-13 16:36:19 -070014#include <asm/arch/mx6-pins.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060015#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Fabio Estevamafe20bf2012-09-24 08:09:33 +000017#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/mxc_i2c.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/mach-imx/spi.h>
Fabio Estevamafe20bf2012-09-24 08:09:33 +000022#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Fabio Estevambe59b6a2012-09-25 08:43:57 +000024#include <miiphy.h>
25#include <netdev.h>
Fabio Estevam96ad33d2012-10-02 11:20:12 +000026#include <asm/arch/sys_proto.h>
Renato Friasbf084322013-05-13 18:01:12 +000027#include <i2c.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030028#include <input.h>
Fabio Estevam5a6c8c42014-09-22 13:55:52 -030029#include <asm/arch/mxc_hdmi.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020030#include <asm/mach-imx/video.h>
Fabio Estevam5a6c8c42014-09-22 13:55:52 -030031#include <asm/arch/crm_regs.h>
Ye.Li700020e2014-10-30 18:53:49 +080032#include <pca953x.h>
Ye.Licfaa23b2014-11-06 16:29:02 +080033#include <power/pmic.h>
Peng Fane5bcd4d2015-01-27 10:14:04 +080034#include <power/pfuze100_pmic.h>
Ye.Licfaa23b2014-11-06 16:29:02 +080035#include "../common/pfuze.h"
Fabio Estevam96ad33d2012-10-02 11:20:12 +000036
Fabio Estevamafe20bf2012-09-24 08:09:33 +000037DECLARE_GLOBAL_DATA_PTR;
38
Benoît Thébaudeau21670242013-04-26 01:34:47 +000039#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
40 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
41 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevamafe20bf2012-09-24 08:09:33 +000042
Benoît Thébaudeau21670242013-04-26 01:34:47 +000043#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
44 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
45 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevamafe20bf2012-09-24 08:09:33 +000046
Benoît Thébaudeau21670242013-04-26 01:34:47 +000047#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
48 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevambe59b6a2012-09-25 08:43:57 +000049
Renato Friasbf084322013-05-13 18:01:12 +000050#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
51 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
52 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
53
Ye.Li4a1f9222014-11-12 14:02:05 +080054#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
55#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
56 PAD_CTL_SRE_FAST)
57#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
58
Renato Friasbf084322013-05-13 18:01:12 +000059#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
60
Fabio Estevam2623cb12014-11-14 11:27:23 -020061#define WEIM_NOR_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
62 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
63 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
64
Ye.Licfaa23b2014-11-06 16:29:02 +080065#define I2C_PMIC 1
66
Fabio Estevamafe20bf2012-09-24 08:09:33 +000067int dram_init(void)
68{
Vanessa Maegima627c0e52016-06-08 15:17:54 -030069 gd->ram_size = imx_ddr_size();
Fabio Estevamafe20bf2012-09-24 08:09:33 +000070
71 return 0;
72}
73
Fabio Estevam6bfdb102014-09-13 18:21:36 -030074static iomux_v3_cfg_t const uart4_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -030075 IOMUX_PADS(PAD_KEY_COL0__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
76 IOMUX_PADS(PAD_KEY_ROW0__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevamafe20bf2012-09-24 08:09:33 +000077};
78
Fabio Estevam6bfdb102014-09-13 18:21:36 -030079static iomux_v3_cfg_t const enet_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -030080 IOMUX_PADS(PAD_KEY_COL1__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_KEY_COL2__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
83 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
85 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
86 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
87 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
88 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
89 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
90 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
91 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
92 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
93 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
94 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevambe59b6a2012-09-25 08:43:57 +000095};
96
Renato Friasbf084322013-05-13 18:01:12 +000097/* I2C2 PMIC, iPod, Tuner, Codec, Touch, HDMI EDID, MIPI CSI2 card */
Vanessa Maegima65779d32017-06-29 09:33:45 -030098static struct i2c_pads_info mx6q_i2c_pad_info1 = {
Renato Friasbf084322013-05-13 18:01:12 +000099 .scl = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300100 .i2c_mode = MX6Q_PAD_EIM_EB2__I2C2_SCL | PC,
101 .gpio_mode = MX6Q_PAD_EIM_EB2__GPIO2_IO30 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000102 .gp = IMX_GPIO_NR(2, 30)
103 },
104 .sda = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300105 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA | PC,
106 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000107 .gp = IMX_GPIO_NR(4, 13)
108 }
109};
110
Vanessa Maegima65779d32017-06-29 09:33:45 -0300111static struct i2c_pads_info mx6dl_i2c_pad_info1 = {
112 .scl = {
113 .i2c_mode = MX6DL_PAD_EIM_EB2__I2C2_SCL | PC,
114 .gpio_mode = MX6DL_PAD_EIM_EB2__GPIO2_IO30 | PC,
115 .gp = IMX_GPIO_NR(2, 30)
116 },
117 .sda = {
118 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA | PC,
119 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 | PC,
120 .gp = IMX_GPIO_NR(4, 13)
121 }
122};
123
Fabio Estevam2623cb12014-11-14 11:27:23 -0200124#ifndef CONFIG_SYS_FLASH_CFI
Renato Friasbf084322013-05-13 18:01:12 +0000125/*
126 * I2C3 MLB, Port Expanders (A, B, C), Video ADC, Light Sensor,
127 * Compass Sensor, Accelerometer, Res Touch
128 */
Vanessa Maegima65779d32017-06-29 09:33:45 -0300129static struct i2c_pads_info mx6q_i2c_pad_info2 = {
Renato Friasbf084322013-05-13 18:01:12 +0000130 .scl = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300131 .i2c_mode = MX6Q_PAD_GPIO_3__I2C3_SCL | PC,
132 .gpio_mode = MX6Q_PAD_GPIO_3__GPIO1_IO03 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000133 .gp = IMX_GPIO_NR(1, 3)
134 },
135 .sda = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300136 .i2c_mode = MX6Q_PAD_EIM_D18__I2C3_SDA | PC,
137 .gpio_mode = MX6Q_PAD_EIM_D18__GPIO3_IO18 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000138 .gp = IMX_GPIO_NR(3, 18)
139 }
140};
Vanessa Maegima65779d32017-06-29 09:33:45 -0300141
142static struct i2c_pads_info mx6dl_i2c_pad_info2 = {
143 .scl = {
144 .i2c_mode = MX6DL_PAD_GPIO_3__I2C3_SCL | PC,
145 .gpio_mode = MX6DL_PAD_GPIO_3__GPIO1_IO03 | PC,
146 .gp = IMX_GPIO_NR(1, 3)
147 },
148 .sda = {
149 .i2c_mode = MX6DL_PAD_EIM_D18__I2C3_SDA | PC,
150 .gpio_mode = MX6DL_PAD_EIM_D18__GPIO3_IO18 | PC,
151 .gp = IMX_GPIO_NR(3, 18)
152 }
153};
Fabio Estevam2623cb12014-11-14 11:27:23 -0200154#endif
Renato Friasbf084322013-05-13 18:01:12 +0000155
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300156static iomux_v3_cfg_t const i2c3_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300157 IOMUX_PADS(PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Renato Friasbf084322013-05-13 18:01:12 +0000158};
159
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300160static iomux_v3_cfg_t const port_exp[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300161 IOMUX_PADS(PAD_SD2_DAT0__GPIO1_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Renato Frias7cbaae82013-05-13 18:01:13 +0000162};
163
Fabio Estevama03035f2017-07-10 15:59:11 -0300164#ifdef CONFIG_MTD_NOR_FLASH
Fabio Estevam2623cb12014-11-14 11:27:23 -0200165static iomux_v3_cfg_t const eimnor_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300166 IOMUX_PADS(PAD_EIM_D16__EIM_DATA16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
167 IOMUX_PADS(PAD_EIM_D17__EIM_DATA17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
168 IOMUX_PADS(PAD_EIM_D18__EIM_DATA18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
169 IOMUX_PADS(PAD_EIM_D19__EIM_DATA19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
170 IOMUX_PADS(PAD_EIM_D20__EIM_DATA20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
171 IOMUX_PADS(PAD_EIM_D21__EIM_DATA21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
172 IOMUX_PADS(PAD_EIM_D22__EIM_DATA22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
173 IOMUX_PADS(PAD_EIM_D23__EIM_DATA23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
174 IOMUX_PADS(PAD_EIM_D24__EIM_DATA24 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
175 IOMUX_PADS(PAD_EIM_D25__EIM_DATA25 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
176 IOMUX_PADS(PAD_EIM_D26__EIM_DATA26 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
177 IOMUX_PADS(PAD_EIM_D27__EIM_DATA27 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
178 IOMUX_PADS(PAD_EIM_D28__EIM_DATA28 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
179 IOMUX_PADS(PAD_EIM_D29__EIM_DATA29 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
180 IOMUX_PADS(PAD_EIM_D30__EIM_DATA30 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
181 IOMUX_PADS(PAD_EIM_D31__EIM_DATA31 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
182 IOMUX_PADS(PAD_EIM_DA0__EIM_AD00 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
183 IOMUX_PADS(PAD_EIM_DA1__EIM_AD01 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
184 IOMUX_PADS(PAD_EIM_DA2__EIM_AD02 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
185 IOMUX_PADS(PAD_EIM_DA3__EIM_AD03 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
186 IOMUX_PADS(PAD_EIM_DA4__EIM_AD04 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
187 IOMUX_PADS(PAD_EIM_DA5__EIM_AD05 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
188 IOMUX_PADS(PAD_EIM_DA6__EIM_AD06 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
189 IOMUX_PADS(PAD_EIM_DA7__EIM_AD07 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
190 IOMUX_PADS(PAD_EIM_DA8__EIM_AD08 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
191 IOMUX_PADS(PAD_EIM_DA9__EIM_AD09 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
192 IOMUX_PADS(PAD_EIM_DA10__EIM_AD10 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
193 IOMUX_PADS(PAD_EIM_DA11__EIM_AD11 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
194 IOMUX_PADS(PAD_EIM_DA12__EIM_AD12 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
195 IOMUX_PADS(PAD_EIM_DA13__EIM_AD13 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
196 IOMUX_PADS(PAD_EIM_DA14__EIM_AD14 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
197 IOMUX_PADS(PAD_EIM_DA15__EIM_AD15 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
198 IOMUX_PADS(PAD_EIM_A16__EIM_ADDR16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
199 IOMUX_PADS(PAD_EIM_A17__EIM_ADDR17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
200 IOMUX_PADS(PAD_EIM_A18__EIM_ADDR18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
201 IOMUX_PADS(PAD_EIM_A19__EIM_ADDR19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
202 IOMUX_PADS(PAD_EIM_A20__EIM_ADDR20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
203 IOMUX_PADS(PAD_EIM_A21__EIM_ADDR21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
204 IOMUX_PADS(PAD_EIM_A22__EIM_ADDR22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
205 IOMUX_PADS(PAD_EIM_A23__EIM_ADDR23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
206 IOMUX_PADS(PAD_EIM_OE__EIM_OE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
207 IOMUX_PADS(PAD_EIM_RW__EIM_RW | MUX_PAD_CTRL(NO_PAD_CTRL)),
208 IOMUX_PADS(PAD_EIM_CS0__EIM_CS0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevam2623cb12014-11-14 11:27:23 -0200209};
210
211static void eimnor_cs_setup(void)
212{
213 struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
214
215 writel(0x00020181, &weim_regs->cs0gcr1);
216 writel(0x00000001, &weim_regs->cs0gcr2);
217 writel(0x0a020000, &weim_regs->cs0rcr1);
218 writel(0x0000c000, &weim_regs->cs0rcr2);
219 writel(0x0804a240, &weim_regs->cs0wcr1);
220 writel(0x00000120, &weim_regs->wcr);
221
222 set_chipselect_size(CS0_128);
223}
224
Fabio Estevame795b6d2016-12-26 23:04:41 -0200225static void eim_clk_setup(void)
226{
227 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
228 int cscmr1, ccgr6;
229
230
231 /* Turn off EIM clock */
232 ccgr6 = readl(&imx_ccm->CCGR6);
233 ccgr6 &= ~(0x3 << 10);
234 writel(ccgr6, &imx_ccm->CCGR6);
235
236 /*
237 * Configure clk_eim_slow_sel = 00 --> derive clock from AXI clk root
238 * and aclk_eim_slow_podf = 01 --> divide by 2
239 * so that we can have EIM at the maximum clock of 132MHz
240 */
241 cscmr1 = readl(&imx_ccm->cscmr1);
242 cscmr1 &= ~(MXC_CCM_CSCMR1_ACLK_EMI_SLOW_MASK |
243 MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_MASK);
244 cscmr1 |= (1 << MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_OFFSET);
245 writel(cscmr1, &imx_ccm->cscmr1);
246
247 /* Turn on EIM clock */
248 ccgr6 |= (0x3 << 10);
249 writel(ccgr6, &imx_ccm->CCGR6);
250}
251
Fabio Estevam2623cb12014-11-14 11:27:23 -0200252static void setup_iomux_eimnor(void)
253{
Vanessa Maegima65779d32017-06-29 09:33:45 -0300254 SETUP_IOMUX_PADS(eimnor_pads);
Fabio Estevam2623cb12014-11-14 11:27:23 -0200255
256 gpio_direction_output(IMX_GPIO_NR(5, 4), 0);
257
258 eimnor_cs_setup();
259}
Fabio Estevama03035f2017-07-10 15:59:11 -0300260#endif
Fabio Estevam2623cb12014-11-14 11:27:23 -0200261
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000262static void setup_iomux_enet(void)
263{
Vanessa Maegima65779d32017-06-29 09:33:45 -0300264 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000265}
266
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300267static iomux_v3_cfg_t const usdhc3_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300268 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
269 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
270 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
271 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
272 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
273 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
274 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
275 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
276 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
277 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
278 IOMUX_PADS(PAD_GPIO_18__SD3_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
279 IOMUX_PADS(PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000280};
281
282static void setup_iomux_uart(void)
283{
Vanessa Maegima65779d32017-06-29 09:33:45 -0300284 SETUP_IOMUX_PADS(uart4_pads);
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000285}
286
Yangbo Lu73340382019-06-21 11:42:28 +0800287#ifdef CONFIG_FSL_ESDHC_IMX
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300288static struct fsl_esdhc_cfg usdhc_cfg[1] = {
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000289 {USDHC3_BASE_ADDR},
290};
291
292int board_mmc_getcd(struct mmc *mmc)
293{
294 gpio_direction_input(IMX_GPIO_NR(6, 15));
295 return !gpio_get_value(IMX_GPIO_NR(6, 15));
296}
297
298int board_mmc_init(bd_t *bis)
299{
Vanessa Maegima65779d32017-06-29 09:33:45 -0300300 SETUP_IOMUX_PADS(usdhc3_pads);
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000301
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000302 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000303 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
304}
305#endif
306
Ye.Li4a1f9222014-11-12 14:02:05 +0800307#ifdef CONFIG_NAND_MXS
308static iomux_v3_cfg_t gpmi_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300309 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
310 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
311 IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
312 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL0)),
313 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
314 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
315 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
316 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
317 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
318 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
319 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
320 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
321 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
322 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
323 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
324 IOMUX_PADS(PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(GPMI_PAD_CTRL1)),
Ye.Li4a1f9222014-11-12 14:02:05 +0800325};
326
327static void setup_gpmi_nand(void)
328{
329 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
330
331 /* config gpmi nand iomux */
Vanessa Maegima65779d32017-06-29 09:33:45 -0300332 SETUP_IOMUX_PADS(gpmi_pads);
Ye.Li4a1f9222014-11-12 14:02:05 +0800333
Ye.Li2dea0402015-01-12 17:37:13 +0800334 setup_gpmi_io_clk((MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
Ye.Li4a1f9222014-11-12 14:02:05 +0800335 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
Ye.Li2dea0402015-01-12 17:37:13 +0800336 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3)));
Ye.Li4a1f9222014-11-12 14:02:05 +0800337
338 /* enable apbh clock gating */
339 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
340}
341#endif
342
Peng Fand4947e32015-07-11 11:38:47 +0800343static void setup_fec(void)
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000344{
Peng Fand4947e32015-07-11 11:38:47 +0800345 if (is_mx6dqp()) {
346 /*
347 * select ENET MAC0 TX clock from PLL
348 */
349 imx_iomux_set_gpr_register(5, 9, 1, 1);
Peng Fan967a83b2015-08-12 17:46:50 +0800350 enable_fec_anatop_clock(0, ENET_125MHZ);
Peng Fand4947e32015-07-11 11:38:47 +0800351 }
352
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000353 setup_iomux_enet();
Peng Fand4947e32015-07-11 11:38:47 +0800354}
355
356int board_eth_init(bd_t *bis)
357{
358 setup_fec();
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000359
Fabio Estevamc0575842014-01-04 17:36:31 -0200360 return cpu_eth_init(bis);
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000361}
362
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000363u32 get_board_rev(void)
364{
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200365 int rev = nxp_board_rev();
Fabio Estevam96ad33d2012-10-02 11:20:12 +0000366
367 return (get_cpu_rev() & ~(0xF << 8)) | rev;
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000368}
369
Fabio Estevam9af078f2017-07-12 18:31:45 -0300370static int ar8031_phy_fixup(struct phy_device *phydev)
371{
372 unsigned short val;
373
374 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
375 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
376 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
377 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
378
379 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
380 val &= 0xffe3;
381 val |= 0x18;
382 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
383
384 /* introduce tx clock delay */
385 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
386 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
387 val |= 0x0100;
388 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
389
390 return 0;
391}
392
393int board_phy_config(struct phy_device *phydev)
394{
395 ar8031_phy_fixup(phydev);
396
397 if (phydev->drv->config)
398 phydev->drv->config(phydev);
399
400 return 0;
401}
402
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300403#if defined(CONFIG_VIDEO_IPUV3)
Peng Fan03f8d152015-12-15 16:27:18 +0800404static void disable_lvds(struct display_info_t const *dev)
405{
406 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
407
408 clrbits_le32(&iomux->gpr[2],
409 IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
410 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
411}
412
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300413static void do_enable_hdmi(struct display_info_t const *dev)
414{
Peng Fan03f8d152015-12-15 16:27:18 +0800415 disable_lvds(dev);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300416 imx_enable_hdmi_phy();
417}
418
419struct display_info_t const displays[] = {{
420 .bus = -1,
421 .addr = 0,
Peng Fan03f8d152015-12-15 16:27:18 +0800422 .pixfmt = IPU_PIX_FMT_RGB666,
423 .detect = NULL,
424 .enable = NULL,
425 .mode = {
426 .name = "Hannstar-XGA",
427 .refresh = 60,
428 .xres = 1024,
429 .yres = 768,
430 .pixclock = 15385,
431 .left_margin = 220,
432 .right_margin = 40,
433 .upper_margin = 21,
434 .lower_margin = 7,
435 .hsync_len = 60,
436 .vsync_len = 10,
437 .sync = FB_SYNC_EXT,
438 .vmode = FB_VMODE_NONINTERLACED
439} }, {
440 .bus = -1,
441 .addr = 0,
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300442 .pixfmt = IPU_PIX_FMT_RGB24,
443 .detect = detect_hdmi,
444 .enable = do_enable_hdmi,
445 .mode = {
446 .name = "HDMI",
447 .refresh = 60,
448 .xres = 1024,
449 .yres = 768,
450 .pixclock = 15385,
451 .left_margin = 220,
452 .right_margin = 40,
453 .upper_margin = 21,
454 .lower_margin = 7,
455 .hsync_len = 60,
456 .vsync_len = 10,
457 .sync = FB_SYNC_EXT,
458 .vmode = FB_VMODE_NONINTERLACED,
459} } };
460size_t display_count = ARRAY_SIZE(displays);
461
Peng Fan03f8d152015-12-15 16:27:18 +0800462iomux_v3_cfg_t const backlight_pads[] = {
Vanessa Maegima65779d32017-06-29 09:33:45 -0300463 IOMUX_PADS(PAD_SD4_DAT1__GPIO2_IO09 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Peng Fan03f8d152015-12-15 16:27:18 +0800464};
465
466static void setup_iomux_backlight(void)
467{
Abel Vesa5d6f33d2019-02-01 16:40:19 +0000468 gpio_request(IMX_GPIO_NR(2, 9), "backlight");
Peng Fan03f8d152015-12-15 16:27:18 +0800469 gpio_direction_output(IMX_GPIO_NR(2, 9), 1);
Vanessa Maegima65779d32017-06-29 09:33:45 -0300470 SETUP_IOMUX_PADS(backlight_pads);
Peng Fan03f8d152015-12-15 16:27:18 +0800471}
472
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300473static void setup_display(void)
474{
475 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan03f8d152015-12-15 16:27:18 +0800476 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300477 int reg;
478
Peng Fan03f8d152015-12-15 16:27:18 +0800479 setup_iomux_backlight();
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300480 enable_ipu_clock();
481 imx_setup_hdmi();
482
Peng Fan03f8d152015-12-15 16:27:18 +0800483 /* Turn on LDB_DI0 and LDB_DI1 clocks */
484 reg = readl(&mxc_ccm->CCGR3);
485 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK | MXC_CCM_CCGR3_LDB_DI1_MASK;
486 writel(reg, &mxc_ccm->CCGR3);
487
488 /* Set LDB_DI0 and LDB_DI1 clk select to 3b'011 */
489 reg = readl(&mxc_ccm->cs2cdr);
490 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
491 MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
492 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
493 (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
494 writel(reg, &mxc_ccm->cs2cdr);
495
496 reg = readl(&mxc_ccm->cscmr2);
497 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV | MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV;
498 writel(reg, &mxc_ccm->cscmr2);
499
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300500 reg = readl(&mxc_ccm->chsccdr);
501 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
502 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Peng Fan03f8d152015-12-15 16:27:18 +0800503 reg |= (CHSCCDR_CLK_SEL_LDB_DI0 <<
504 MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300505 writel(reg, &mxc_ccm->chsccdr);
Peng Fan03f8d152015-12-15 16:27:18 +0800506
507 reg = IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
508 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
509 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
510 IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT |
511 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
512 IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
513 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
514 IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED;
515 writel(reg, &iomux->gpr[2]);
516
517 reg = readl(&iomux->gpr[3]);
518 reg &= ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
519 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
520 reg |= (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
521 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET) |
522 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
523 IOMUXC_GPR3_HDMI_MUX_CTL_OFFSET);
524 writel(reg, &iomux->gpr[3]);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300525}
526#endif /* CONFIG_VIDEO_IPUV3 */
527
528/*
529 * Do not overwrite the console
530 * Use always serial for U-Boot console
531 */
532int overwrite_console(void)
533{
534 return 1;
535}
536
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000537int board_early_init_f(void)
538{
539 setup_iomux_uart();
Ye.Li4a1f9222014-11-12 14:02:05 +0800540
541#ifdef CONFIG_NAND_MXS
542 setup_gpmi_nand();
543#endif
Fabio Estevam2623cb12014-11-14 11:27:23 -0200544
Fabio Estevama03035f2017-07-10 15:59:11 -0300545#ifdef CONFIG_MTD_NOR_FLASH
546 eim_clk_setup();
547#endif
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000548 return 0;
549}
550
551int board_init(void)
552{
553 /* address of boot parameters */
554 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
555
Renato Friasbf084322013-05-13 18:01:12 +0000556 /* I2C 2 and 3 setup - I2C 3 hw mux with EIM */
Vanessa Maegima65779d32017-06-29 09:33:45 -0300557 if (is_mx6dq() || is_mx6dqp())
558 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info1);
559 else
560 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info1);
Renato Friasbf084322013-05-13 18:01:12 +0000561 /* I2C 3 Steer */
Abel Vesa5d6f33d2019-02-01 16:40:19 +0000562 gpio_request(IMX_GPIO_NR(5, 4), "steer logic");
Renato Friasbf084322013-05-13 18:01:12 +0000563 gpio_direction_output(IMX_GPIO_NR(5, 4), 1);
Vanessa Maegima65779d32017-06-29 09:33:45 -0300564 SETUP_IOMUX_PADS(i2c3_pads);
Fabio Estevam2623cb12014-11-14 11:27:23 -0200565#ifndef CONFIG_SYS_FLASH_CFI
Vanessa Maegima65779d32017-06-29 09:33:45 -0300566 if (is_mx6dq() || is_mx6dqp())
567 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info2);
568 else
569 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info2);
Fabio Estevam2623cb12014-11-14 11:27:23 -0200570#endif
Abel Vesa5d6f33d2019-02-01 16:40:19 +0000571 gpio_request(IMX_GPIO_NR(1, 15), "expander en");
Renato Frias7cbaae82013-05-13 18:01:13 +0000572 gpio_direction_output(IMX_GPIO_NR(1, 15), 1);
Vanessa Maegima65779d32017-06-29 09:33:45 -0300573 SETUP_IOMUX_PADS(port_exp);
Renato Frias7cbaae82013-05-13 18:01:13 +0000574
Peng Fan03f8d152015-12-15 16:27:18 +0800575#ifdef CONFIG_VIDEO_IPUV3
576 setup_display();
577#endif
Fabio Estevama03035f2017-07-10 15:59:11 -0300578
579#ifdef CONFIG_MTD_NOR_FLASH
Fabio Estevam2623cb12014-11-14 11:27:23 -0200580 setup_iomux_eimnor();
Fabio Estevama03035f2017-07-10 15:59:11 -0300581#endif
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000582 return 0;
583}
584
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300585#ifdef CONFIG_MXC_SPI
586int board_spi_cs_gpio(unsigned bus, unsigned cs)
587{
588 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(4, 9)) : -1;
589}
590#endif
591
Ye.Licfaa23b2014-11-06 16:29:02 +0800592int power_init_board(void)
593{
594 struct pmic *p;
Peng Fand4947e32015-07-11 11:38:47 +0800595 unsigned int value;
Ye.Licfaa23b2014-11-06 16:29:02 +0800596
597 p = pfuze_common_init(I2C_PMIC);
598 if (!p)
599 return -ENODEV;
600
Peng Fand4947e32015-07-11 11:38:47 +0800601 if (is_mx6dqp()) {
602 /* set SW2 staby volatage 0.975V*/
603 pmic_reg_read(p, PFUZE100_SW2STBY, &value);
604 value &= ~0x3f;
605 value |= 0x17;
606 pmic_reg_write(p, PFUZE100_SW2STBY, value);
607 }
Peng Fane5bcd4d2015-01-27 10:14:04 +0800608
Peng Fand4947e32015-07-11 11:38:47 +0800609 return pfuze_mode_init(p, APS_PFM);
Ye.Licfaa23b2014-11-06 16:29:02 +0800610}
611
Otavio Salvador52863372013-03-16 08:05:07 +0000612#ifdef CONFIG_CMD_BMODE
613static const struct boot_mode board_boot_modes[] = {
614 /* 4 bit bus width */
615 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
616 {NULL, 0},
617};
618#endif
619
620int board_late_init(void)
621{
622#ifdef CONFIG_CMD_BMODE
623 add_board_boot_modes(board_boot_modes);
624#endif
625
Peng Fan04321fc2015-07-11 11:38:46 +0800626#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Simon Glass6a38e412017-08-03 12:22:09 -0600627 env_set("board_name", "SABREAUTO");
Peng Fan04321fc2015-07-11 11:38:46 +0800628
Peng Fand4947e32015-07-11 11:38:47 +0800629 if (is_mx6dqp())
Simon Glass6a38e412017-08-03 12:22:09 -0600630 env_set("board_rev", "MX6QP");
Peng Fan4a597d02016-05-23 18:36:06 +0800631 else if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600632 env_set("board_rev", "MX6Q");
Peng Fan4a597d02016-05-23 18:36:06 +0800633 else if (is_mx6sdl())
Simon Glass6a38e412017-08-03 12:22:09 -0600634 env_set("board_rev", "MX6DL");
Peng Fan04321fc2015-07-11 11:38:46 +0800635#endif
636
Otavio Salvador52863372013-03-16 08:05:07 +0000637 return 0;
638}
639
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000640int checkboard(void)
641{
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200642 printf("Board: MX6Q-Sabreauto rev%c\n", nxp_board_rev_string());
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000643
644 return 0;
645}
Ye.Li700020e2014-10-30 18:53:49 +0800646
647#ifdef CONFIG_USB_EHCI_MX6
Ye.Li700020e2014-10-30 18:53:49 +0800648int board_ehci_hcd_init(int port)
649{
650 switch (port) {
651 case 0:
Ye.Li700020e2014-10-30 18:53:49 +0800652 /*
653 * Set daisy chain for otg_pin_id on 6q.
654 * For 6dl, this bit is reserved.
655 */
656 imx_iomux_set_gpr_register(1, 13, 1, 0);
657 break;
658 case 1:
659 break;
660 default:
661 printf("MXC USB port %d not yet supported\n", port);
662 return -EINVAL;
663 }
664 return 0;
665}
Ye.Li700020e2014-10-30 18:53:49 +0800666#endif
Vanessa Maegima65779d32017-06-29 09:33:45 -0300667
668#ifdef CONFIG_SPL_BUILD
669#include <asm/arch/mx6-ddr.h>
670#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900671#include <linux/libfdt.h>
Vanessa Maegima65779d32017-06-29 09:33:45 -0300672
Diego Dorta614c2832017-07-07 15:38:34 -0300673#ifdef CONFIG_SPL_OS_BOOT
674int spl_start_uboot(void)
675{
676 return 0;
677}
678#endif
679
Vanessa Maegima65779d32017-06-29 09:33:45 -0300680static void ccgr_init(void)
681{
682 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
683
684 writel(0x00C03F3F, &ccm->CCGR0);
685 writel(0x0030FC03, &ccm->CCGR1);
686 writel(0x0FFFC000, &ccm->CCGR2);
687 writel(0x3FF00000, &ccm->CCGR3);
688 writel(0x00FFF300, &ccm->CCGR4);
689 writel(0x0F0000C3, &ccm->CCGR5);
690 writel(0x000003FF, &ccm->CCGR6);
691}
692
Vanessa Maegima65779d32017-06-29 09:33:45 -0300693static int mx6q_dcd_table[] = {
694 0x020e0798, 0x000C0000,
695 0x020e0758, 0x00000000,
696 0x020e0588, 0x00000030,
697 0x020e0594, 0x00000030,
698 0x020e056c, 0x00000030,
699 0x020e0578, 0x00000030,
700 0x020e074c, 0x00000030,
701 0x020e057c, 0x00000030,
702 0x020e058c, 0x00000000,
703 0x020e059c, 0x00000030,
704 0x020e05a0, 0x00000030,
705 0x020e078c, 0x00000030,
706 0x020e0750, 0x00020000,
707 0x020e05a8, 0x00000028,
708 0x020e05b0, 0x00000028,
709 0x020e0524, 0x00000028,
710 0x020e051c, 0x00000028,
711 0x020e0518, 0x00000028,
712 0x020e050c, 0x00000028,
713 0x020e05b8, 0x00000028,
714 0x020e05c0, 0x00000028,
715 0x020e0774, 0x00020000,
716 0x020e0784, 0x00000028,
717 0x020e0788, 0x00000028,
718 0x020e0794, 0x00000028,
719 0x020e079c, 0x00000028,
720 0x020e07a0, 0x00000028,
721 0x020e07a4, 0x00000028,
722 0x020e07a8, 0x00000028,
723 0x020e0748, 0x00000028,
724 0x020e05ac, 0x00000028,
725 0x020e05b4, 0x00000028,
726 0x020e0528, 0x00000028,
727 0x020e0520, 0x00000028,
728 0x020e0514, 0x00000028,
729 0x020e0510, 0x00000028,
730 0x020e05bc, 0x00000028,
731 0x020e05c4, 0x00000028,
732 0x021b0800, 0xa1390003,
733 0x021b080c, 0x001F001F,
734 0x021b0810, 0x001F001F,
735 0x021b480c, 0x001F001F,
736 0x021b4810, 0x001F001F,
737 0x021b083c, 0x43260335,
738 0x021b0840, 0x031A030B,
739 0x021b483c, 0x4323033B,
740 0x021b4840, 0x0323026F,
741 0x021b0848, 0x483D4545,
742 0x021b4848, 0x44433E48,
743 0x021b0850, 0x41444840,
744 0x021b4850, 0x4835483E,
745 0x021b081c, 0x33333333,
746 0x021b0820, 0x33333333,
747 0x021b0824, 0x33333333,
748 0x021b0828, 0x33333333,
749 0x021b481c, 0x33333333,
750 0x021b4820, 0x33333333,
751 0x021b4824, 0x33333333,
752 0x021b4828, 0x33333333,
753 0x021b08b8, 0x00000800,
754 0x021b48b8, 0x00000800,
755 0x021b0004, 0x00020036,
756 0x021b0008, 0x09444040,
757 0x021b000c, 0x8A8F7955,
758 0x021b0010, 0xFF328F64,
759 0x021b0014, 0x01FF00DB,
760 0x021b0018, 0x00001740,
761 0x021b001c, 0x00008000,
762 0x021b002c, 0x000026d2,
763 0x021b0030, 0x008F1023,
764 0x021b0040, 0x00000047,
765 0x021b0000, 0x841A0000,
766 0x021b001c, 0x04088032,
767 0x021b001c, 0x00008033,
768 0x021b001c, 0x00048031,
769 0x021b001c, 0x09408030,
770 0x021b001c, 0x04008040,
771 0x021b0020, 0x00005800,
772 0x021b0818, 0x00011117,
773 0x021b4818, 0x00011117,
774 0x021b0004, 0x00025576,
775 0x021b0404, 0x00011006,
776 0x021b001c, 0x00000000,
777 0x020c4068, 0x00C03F3F,
778 0x020c406c, 0x0030FC03,
779 0x020c4070, 0x0FFFC000,
780 0x020c4074, 0x3FF00000,
781 0x020c4078, 0xFFFFF300,
782 0x020c407c, 0x0F0000F3,
783 0x020c4080, 0x00000FFF,
784 0x020e0010, 0xF00000CF,
785 0x020e0018, 0x007F007F,
786 0x020e001c, 0x007F007F,
787};
788
789static int mx6qp_dcd_table[] = {
790 0x020e0798, 0x000C0000,
791 0x020e0758, 0x00000000,
792 0x020e0588, 0x00000030,
793 0x020e0594, 0x00000030,
794 0x020e056c, 0x00000030,
795 0x020e0578, 0x00000030,
796 0x020e074c, 0x00000030,
797 0x020e057c, 0x00000030,
798 0x020e058c, 0x00000000,
799 0x020e059c, 0x00000030,
800 0x020e05a0, 0x00000030,
801 0x020e078c, 0x00000030,
802 0x020e0750, 0x00020000,
803 0x020e05a8, 0x00000030,
804 0x020e05b0, 0x00000030,
805 0x020e0524, 0x00000030,
806 0x020e051c, 0x00000030,
807 0x020e0518, 0x00000030,
808 0x020e050c, 0x00000030,
809 0x020e05b8, 0x00000030,
810 0x020e05c0, 0x00000030,
811 0x020e0774, 0x00020000,
812 0x020e0784, 0x00000030,
813 0x020e0788, 0x00000030,
814 0x020e0794, 0x00000030,
815 0x020e079c, 0x00000030,
816 0x020e07a0, 0x00000030,
817 0x020e07a4, 0x00000030,
818 0x020e07a8, 0x00000030,
819 0x020e0748, 0x00000030,
820 0x020e05ac, 0x00000030,
821 0x020e05b4, 0x00000030,
822 0x020e0528, 0x00000030,
823 0x020e0520, 0x00000030,
824 0x020e0514, 0x00000030,
825 0x020e0510, 0x00000030,
826 0x020e05bc, 0x00000030,
827 0x020e05c4, 0x00000030,
828 0x021b0800, 0xa1390003,
829 0x021b080c, 0x001b001e,
830 0x021b0810, 0x002e0029,
831 0x021b480c, 0x001b002a,
832 0x021b4810, 0x0019002c,
833 0x021b083c, 0x43240334,
834 0x021b0840, 0x0324031a,
835 0x021b483c, 0x43340344,
836 0x021b4840, 0x03280276,
837 0x021b0848, 0x44383A3E,
838 0x021b4848, 0x3C3C3846,
839 0x021b0850, 0x2e303230,
840 0x021b4850, 0x38283E34,
841 0x021b081c, 0x33333333,
842 0x021b0820, 0x33333333,
843 0x021b0824, 0x33333333,
844 0x021b0828, 0x33333333,
845 0x021b481c, 0x33333333,
846 0x021b4820, 0x33333333,
847 0x021b4824, 0x33333333,
848 0x021b4828, 0x33333333,
849 0x021b08c0, 0x24912492,
850 0x021b48c0, 0x24912492,
851 0x021b08b8, 0x00000800,
852 0x021b48b8, 0x00000800,
853 0x021b0004, 0x00020036,
854 0x021b0008, 0x09444040,
855 0x021b000c, 0x898E7955,
856 0x021b0010, 0xFF328F64,
857 0x021b0014, 0x01FF00DB,
858 0x021b0018, 0x00001740,
859 0x021b001c, 0x00008000,
860 0x021b002c, 0x000026d2,
861 0x021b0030, 0x008E1023,
862 0x021b0040, 0x00000047,
863 0x021b0400, 0x14420000,
864 0x021b0000, 0x841A0000,
865 0x00bb0008, 0x00000004,
866 0x00bb000c, 0x2891E41A,
867 0x00bb0038, 0x00000564,
868 0x00bb0014, 0x00000040,
869 0x00bb0028, 0x00000020,
870 0x00bb002c, 0x00000020,
871 0x021b001c, 0x04088032,
872 0x021b001c, 0x00008033,
873 0x021b001c, 0x00048031,
874 0x021b001c, 0x09408030,
875 0x021b001c, 0x04008040,
876 0x021b0020, 0x00005800,
877 0x021b0818, 0x00011117,
878 0x021b4818, 0x00011117,
879 0x021b0004, 0x00025576,
880 0x021b0404, 0x00011006,
881 0x021b001c, 0x00000000,
882 0x020c4068, 0x00C03F3F,
883 0x020c406c, 0x0030FC03,
884 0x020c4070, 0x0FFFC000,
885 0x020c4074, 0x3FF00000,
886 0x020c4078, 0xFFFFF300,
887 0x020c407c, 0x0F0000F3,
888 0x020c4080, 0x00000FFF,
889 0x020e0010, 0xF00000CF,
890 0x020e0018, 0x77177717,
891 0x020e001c, 0x77177717,
892};
893
894static int mx6dl_dcd_table[] = {
895 0x020e0774, 0x000C0000,
896 0x020e0754, 0x00000000,
897 0x020e04ac, 0x00000030,
898 0x020e04b0, 0x00000030,
899 0x020e0464, 0x00000030,
900 0x020e0490, 0x00000030,
901 0x020e074c, 0x00000030,
902 0x020e0494, 0x00000030,
903 0x020e04a0, 0x00000000,
904 0x020e04b4, 0x00000030,
905 0x020e04b8, 0x00000030,
906 0x020e076c, 0x00000030,
907 0x020e0750, 0x00020000,
908 0x020e04bc, 0x00000028,
909 0x020e04c0, 0x00000028,
910 0x020e04c4, 0x00000028,
911 0x020e04c8, 0x00000028,
912 0x020e04cc, 0x00000028,
913 0x020e04d0, 0x00000028,
914 0x020e04d4, 0x00000028,
915 0x020e04d8, 0x00000028,
916 0x020e0760, 0x00020000,
917 0x020e0764, 0x00000028,
918 0x020e0770, 0x00000028,
919 0x020e0778, 0x00000028,
920 0x020e077c, 0x00000028,
921 0x020e0780, 0x00000028,
922 0x020e0784, 0x00000028,
923 0x020e078c, 0x00000028,
924 0x020e0748, 0x00000028,
925 0x020e0470, 0x00000028,
926 0x020e0474, 0x00000028,
927 0x020e0478, 0x00000028,
928 0x020e047c, 0x00000028,
929 0x020e0480, 0x00000028,
930 0x020e0484, 0x00000028,
931 0x020e0488, 0x00000028,
932 0x020e048c, 0x00000028,
933 0x021b0800, 0xa1390003,
934 0x021b080c, 0x001F001F,
935 0x021b0810, 0x001F001F,
936 0x021b480c, 0x001F001F,
937 0x021b4810, 0x001F001F,
938 0x021b083c, 0x42190217,
939 0x021b0840, 0x017B017B,
940 0x021b483c, 0x4176017B,
941 0x021b4840, 0x015F016C,
942 0x021b0848, 0x4C4C4D4C,
943 0x021b4848, 0x4A4D4C48,
944 0x021b0850, 0x3F3F3F40,
945 0x021b4850, 0x3538382E,
946 0x021b081c, 0x33333333,
947 0x021b0820, 0x33333333,
948 0x021b0824, 0x33333333,
949 0x021b0828, 0x33333333,
950 0x021b481c, 0x33333333,
951 0x021b4820, 0x33333333,
952 0x021b4824, 0x33333333,
953 0x021b4828, 0x33333333,
954 0x021b08b8, 0x00000800,
955 0x021b48b8, 0x00000800,
956 0x021b0004, 0x00020025,
957 0x021b0008, 0x00333030,
958 0x021b000c, 0x676B5313,
959 0x021b0010, 0xB66E8B63,
960 0x021b0014, 0x01FF00DB,
961 0x021b0018, 0x00001740,
962 0x021b001c, 0x00008000,
963 0x021b002c, 0x000026d2,
964 0x021b0030, 0x006B1023,
965 0x021b0040, 0x00000047,
966 0x021b0000, 0x841A0000,
967 0x021b001c, 0x04008032,
968 0x021b001c, 0x00008033,
969 0x021b001c, 0x00048031,
970 0x021b001c, 0x05208030,
971 0x021b001c, 0x04008040,
972 0x021b0020, 0x00005800,
973 0x021b0818, 0x00011117,
974 0x021b4818, 0x00011117,
975 0x021b0004, 0x00025565,
976 0x021b0404, 0x00011006,
977 0x021b001c, 0x00000000,
978 0x020c4068, 0x00C03F3F,
979 0x020c406c, 0x0030FC03,
980 0x020c4070, 0x0FFFC000,
981 0x020c4074, 0x3FF00000,
982 0x020c4078, 0xFFFFF300,
983 0x020c407c, 0x0F0000C3,
984 0x020c4080, 0x00000FFF,
985 0x020e0010, 0xF00000CF,
986 0x020e0018, 0x007F007F,
987 0x020e001c, 0x007F007F,
988};
989
990static void ddr_init(int *table, int size)
991{
992 int i;
993
994 for (i = 0; i < size / 2 ; i++)
995 writel(table[2 * i + 1], table[2 * i]);
996}
997
998static void spl_dram_init(void)
999{
1000 if (is_mx6dq())
1001 ddr_init(mx6q_dcd_table, ARRAY_SIZE(mx6q_dcd_table));
1002 else if (is_mx6dqp())
1003 ddr_init(mx6qp_dcd_table, ARRAY_SIZE(mx6qp_dcd_table));
1004 else if (is_mx6sdl())
1005 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
1006}
1007
1008void board_init_f(ulong dummy)
1009{
1010 /* DDR initialization */
1011 spl_dram_init();
1012
1013 /* setup AIPS and disable watchdog */
1014 arch_cpu_init();
1015
1016 ccgr_init();
1017 gpr_init();
1018
1019 /* iomux and setup of i2c */
1020 board_early_init_f();
1021
1022 /* setup GP timer */
1023 timer_init();
1024
1025 /* UART clocks enabled and gd valid - init serial console */
1026 preloader_console_init();
1027
1028 /* Clear the BSS. */
1029 memset(__bss_start, 0, __bss_end - __bss_start);
1030
1031 /* load/boot image from boot device */
1032 board_init_r(NULL, 0);
1033}
1034#endif
Abel Vesa9fe4c852019-02-01 16:40:13 +00001035
1036#ifdef CONFIG_SPL_LOAD_FIT
1037int board_fit_config_name_match(const char *name)
1038{
1039 if (is_mx6dq()) {
1040 if (!strcmp(name, "imx6q-sabreauto"))
1041 return 0;
1042 } else if (is_mx6dqp()) {
1043 if (!strcmp(name, "imx6qp-sabreauto"))
1044 return 0;
1045 } else if (is_mx6dl()) {
1046 if (!strcmp(name, "imx6dl-sabreauto"))
1047 return 0;
1048 }
1049
1050 return -1;
1051}
1052#endif