blob: 49c731f89119972143c2ac638543cc9f9d1241ad [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
SARTRE Leodce71762013-06-03 23:30:36 +00002/*
3 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
4 * Based on mx6qsabrelite.c file
5 * Copyright (C) 2013, Adeneo Embedded <www.adeneo-embedded.com>
6 * Leo Sartre, <lsartre@adeneo-embedded.com>
SARTRE Leodce71762013-06-03 23:30:36 +00007 */
8
9#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
SARTRE Leodce71762013-06-03 23:30:36 +000011#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/iomux.h>
15#include <asm/arch/mx6-pins.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/sata.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/mxc_i2c.h>
Otavio Salvadore186b182015-11-19 19:02:36 -020021#include <asm/arch/sys_proto.h>
Otavio Salvador6c46cd12015-07-23 11:02:30 -030022#include <asm/arch/mxc_hdmi.h>
23#include <asm/arch/crm_regs.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060024#include <env.h>
SARTRE Leodce71762013-06-03 23:30:36 +000025#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080026#include <fsl_esdhc_imx.h>
Otavio Salvador0378d632015-07-23 11:02:28 -030027#include <i2c.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030028#include <input.h>
Otavio Salvador0378d632015-07-23 11:02:28 -030029#include <power/pmic.h>
30#include <power/pfuze100_pmic.h>
Otavio Salvador6c46cd12015-07-23 11:02:30 -030031#include <linux/fb.h>
32#include <ipu_pixfmt.h>
Otavio Salvadore6b47822015-07-28 20:24:41 -030033#include <malloc.h>
34#include <miiphy.h>
35#include <netdev.h>
36#include <micrel.h>
Otavio Salvadore186b182015-11-19 19:02:36 -020037#include <spi_flash.h>
38#include <spi.h>
SARTRE Leodce71762013-06-03 23:30:36 +000039
40DECLARE_GLOBAL_DATA_PTR;
41
42#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED |\
43 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
44
45#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW |\
46 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
47
Otavio Salvador0378d632015-07-23 11:02:28 -030048#define I2C_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
49 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
50 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
51 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
52
Otavio Salvadorf594b552015-11-19 19:02:33 -020053#define SPI_PAD_CTRL (PAD_CTL_HYS | \
54 PAD_CTL_SPEED_MED | \
55 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
56
Otavio Salvador0378d632015-07-23 11:02:28 -030057#define MX6Q_QMX6_PFUZE_MUX IMX_GPIO_NR(6, 9)
58
Otavio Salvadore6b47822015-07-28 20:24:41 -030059
60#define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
61 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
62 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
63
SARTRE Leodce71762013-06-03 23:30:36 +000064int dram_init(void)
65{
Otavio Salvadore186b182015-11-19 19:02:36 -020066 gd->ram_size = imx_ddr_size();
SARTRE Leodce71762013-06-03 23:30:36 +000067
68 return 0;
69}
70
Otavio Salvadord08683f2015-07-23 11:02:21 -030071static iomux_v3_cfg_t const uart2_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -020072 IOMUX_PADS(PAD_EIM_D26__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
73 IOMUX_PADS(PAD_EIM_D27__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
SARTRE Leodce71762013-06-03 23:30:36 +000074};
75
Tom Rinif2915762017-05-08 22:14:22 -040076#ifndef CONFIG_SPL_BUILD
Otavio Salvadord08683f2015-07-23 11:02:21 -030077static iomux_v3_cfg_t const usdhc2_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -020078 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
79 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
80 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
81 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
82 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
83 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
84 IOMUX_PADS(PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
SARTRE Leodce71762013-06-03 23:30:36 +000085};
86
Otavio Salvadordff4c302015-07-23 11:02:24 -030087static iomux_v3_cfg_t const usdhc3_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -020088 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
89 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
90 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
91 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
92 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
93 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
94 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
95 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
96 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
97 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
98 IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Otavio Salvadordff4c302015-07-23 11:02:24 -030099};
Tom Rinif2915762017-05-08 22:14:22 -0400100#endif
Otavio Salvadordff4c302015-07-23 11:02:24 -0300101
Otavio Salvadord08683f2015-07-23 11:02:21 -0300102static iomux_v3_cfg_t const usdhc4_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200103 IOMUX_PADS(PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
104 IOMUX_PADS(PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
105 IOMUX_PADS(PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
106 IOMUX_PADS(PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
107 IOMUX_PADS(PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
108 IOMUX_PADS(PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
109 IOMUX_PADS(PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
110 IOMUX_PADS(PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
111 IOMUX_PADS(PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
112 IOMUX_PADS(PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
113 IOMUX_PADS(PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
SARTRE Leodce71762013-06-03 23:30:36 +0000114};
115
Otavio Salvadorc8762d02015-07-23 11:02:29 -0300116static iomux_v3_cfg_t const usb_otg_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200117 IOMUX_PADS(PAD_EIM_D22__USB_OTG_PWR | MUX_PAD_CTRL(NO_PAD_CTRL)),
118 IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | MUX_PAD_CTRL(NO_PAD_CTRL)),
Otavio Salvadorc8762d02015-07-23 11:02:29 -0300119};
120
Otavio Salvadore6b47822015-07-28 20:24:41 -0300121static iomux_v3_cfg_t enet_pads_ksz9031[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200122 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
123 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
124 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
125 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
126 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
127 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
128 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
129 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
130 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
131 IOMUX_PADS(PAD_RGMII_RXC__GPIO6_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
132 IOMUX_PADS(PAD_RGMII_RD0__GPIO6_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL)),
133 IOMUX_PADS(PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL)),
134 IOMUX_PADS(PAD_RGMII_RD2__GPIO6_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
135 IOMUX_PADS(PAD_RGMII_RD3__GPIO6_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
136 IOMUX_PADS(PAD_RGMII_RX_CTL__GPIO6_IO24 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Otavio Salvadore6b47822015-07-28 20:24:41 -0300137};
138
139static iomux_v3_cfg_t enet_pads_final_ksz9031[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200140 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
141 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
142 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
143 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
144 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
145 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Otavio Salvadore6b47822015-07-28 20:24:41 -0300146};
147
148static iomux_v3_cfg_t enet_pads_ar8035[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200149 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
150 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
151 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
152 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
153 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
154 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
155 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
156 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
157 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
158 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
159 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
160 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
161 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
162 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
163 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Otavio Salvadore6b47822015-07-28 20:24:41 -0300164};
165
Otavio Salvadorf594b552015-11-19 19:02:33 -0200166static iomux_v3_cfg_t const ecspi1_pads[] = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200167 IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
168 IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
169 IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
170 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Otavio Salvadorf594b552015-11-19 19:02:33 -0200171};
172
Otavio Salvador0378d632015-07-23 11:02:28 -0300173#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
Otavio Salvadore186b182015-11-19 19:02:36 -0200174struct i2c_pads_info mx6q_i2c_pad_info1 = {
Otavio Salvador0378d632015-07-23 11:02:28 -0300175 .scl = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200176 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL | PC,
177 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12 | PC,
Otavio Salvador0378d632015-07-23 11:02:28 -0300178 .gp = IMX_GPIO_NR(4, 12)
179 },
180 .sda = {
Otavio Salvadore186b182015-11-19 19:02:36 -0200181 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA | PC,
182 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 | PC,
Otavio Salvador0378d632015-07-23 11:02:28 -0300183 .gp = IMX_GPIO_NR(4, 13)
184 }
185};
186
Otavio Salvadore186b182015-11-19 19:02:36 -0200187struct i2c_pads_info mx6dl_i2c_pad_info1 = {
188 .scl = {
189 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL | PC,
190 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12 | PC,
191 .gp = IMX_GPIO_NR(4, 12)
192 },
193 .sda = {
194 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA | PC,
195 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 | PC,
196 .gp = IMX_GPIO_NR(4, 13)
197 }
198};
199
Otavio Salvador0378d632015-07-23 11:02:28 -0300200#define I2C_PMIC 1 /* I2C2 port is used to connect to the PMIC */
201
202struct interface_level {
203 char *name;
204 uchar value;
205};
206
207static struct interface_level mipi_levels[] = {
208 {"0V0", 0x00},
209 {"2V5", 0x17},
210};
211
212/* setup board specific PMIC */
213int power_init_board(void)
214{
215 struct pmic *p;
216 u32 id1, id2, i;
217 int ret;
218 char const *lv_mipi;
219
220 /* configure I2C multiplexer */
221 gpio_direction_output(MX6Q_QMX6_PFUZE_MUX, 1);
222
223 power_pfuze100_init(I2C_PMIC);
224 p = pmic_get("PFUZE100");
225 if (!p)
226 return -EINVAL;
227
228 ret = pmic_probe(p);
229 if (ret)
230 return ret;
231
232 pmic_reg_read(p, PFUZE100_DEVICEID, &id1);
233 pmic_reg_read(p, PFUZE100_REVID, &id2);
234 printf("PFUZE100 Rev. [%02x/%02x] detected\n", id1, id2);
235
236 if (id2 >= 0x20)
237 return 0;
238
239 /* set level of MIPI if specified */
Simon Glass64b723f2017-08-03 12:22:12 -0600240 lv_mipi = env_get("lv_mipi");
Otavio Salvador0378d632015-07-23 11:02:28 -0300241 if (lv_mipi)
242 return 0;
243
244 for (i = 0; i < ARRAY_SIZE(mipi_levels); i++) {
245 if (!strcmp(mipi_levels[i].name, lv_mipi)) {
Otavio Salvador6cfffff2015-09-17 15:13:18 -0300246 printf("set MIPI level %s\n", mipi_levels[i].name);
Otavio Salvador0378d632015-07-23 11:02:28 -0300247 ret = pmic_reg_write(p, PFUZE100_VGEN4VOL,
248 mipi_levels[i].value);
249 if (ret)
250 return ret;
251 }
252 }
253
Otavio Salvadore6b47822015-07-28 20:24:41 -0300254 return 0;
255}
256
257int board_eth_init(bd_t *bis)
258{
259 struct phy_device *phydev;
260 struct mii_dev *bus;
261 unsigned short id1, id2;
262 int ret;
263
Otavio Salvadore6b47822015-07-28 20:24:41 -0300264 /* check whether KSZ9031 or AR8035 has to be configured */
Otavio Salvadore186b182015-11-19 19:02:36 -0200265 SETUP_IOMUX_PADS(enet_pads_ar8035);
Otavio Salvadore6b47822015-07-28 20:24:41 -0300266
267 /* phy reset */
268 gpio_direction_output(IMX_GPIO_NR(3, 23), 0);
269 udelay(2000);
270 gpio_set_value(IMX_GPIO_NR(3, 23), 1);
271 udelay(500);
272
273 bus = fec_get_miibus(IMX_FEC_BASE, -1);
274 if (!bus)
275 return -EINVAL;
276 phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
277 if (!phydev) {
278 printf("Error: phy device not found.\n");
279 ret = -ENODEV;
280 goto free_bus;
281 }
282
283 /* get the PHY id */
284 id1 = phy_read(phydev, MDIO_DEVAD_NONE, 2);
285 id2 = phy_read(phydev, MDIO_DEVAD_NONE, 3);
286
287 if ((id1 == 0x22) && ((id2 & 0xFFF0) == 0x1620)) {
288 /* re-configure for Micrel KSZ9031 */
289 printf("configure Micrel KSZ9031 Ethernet Phy at address %d\n",
290 phydev->addr);
291
292 /* phy reset: gpio3-23 */
293 gpio_set_value(IMX_GPIO_NR(3, 23), 0);
294 gpio_set_value(IMX_GPIO_NR(6, 30), (phydev->addr >> 2));
295 gpio_set_value(IMX_GPIO_NR(6, 25), 1);
296 gpio_set_value(IMX_GPIO_NR(6, 27), 1);
297 gpio_set_value(IMX_GPIO_NR(6, 28), 1);
298 gpio_set_value(IMX_GPIO_NR(6, 29), 1);
Otavio Salvadore186b182015-11-19 19:02:36 -0200299 SETUP_IOMUX_PADS(enet_pads_ksz9031);
Otavio Salvadore6b47822015-07-28 20:24:41 -0300300 gpio_set_value(IMX_GPIO_NR(6, 24), 1);
301 udelay(500);
302 gpio_set_value(IMX_GPIO_NR(3, 23), 1);
Otavio Salvadore186b182015-11-19 19:02:36 -0200303 SETUP_IOMUX_PADS(enet_pads_final_ksz9031);
Otavio Salvadore6b47822015-07-28 20:24:41 -0300304 } else if ((id1 == 0x004d) && (id2 == 0xd072)) {
305 /* configure Atheros AR8035 - actually nothing to do */
306 printf("configure Atheros AR8035 Ethernet Phy at address %d\n",
307 phydev->addr);
308 } else {
309 printf("Unknown Ethernet-Phy: 0x%04x 0x%04x\n", id1, id2);
310 ret = -EINVAL;
311 goto free_phydev;
312 }
313
314 ret = fec_probe(bis, -1, IMX_FEC_BASE, bus, phydev);
315 if (ret)
316 goto free_phydev;
317
318 return 0;
319
320free_phydev:
321 free(phydev);
322free_bus:
323 free(bus);
324 return ret;
325}
326
327int mx6_rgmii_rework(struct phy_device *phydev)
328{
329 unsigned short id1, id2;
330 unsigned short val;
331
332 /* check whether KSZ9031 or AR8035 has to be configured */
333 id1 = phy_read(phydev, MDIO_DEVAD_NONE, 2);
334 id2 = phy_read(phydev, MDIO_DEVAD_NONE, 3);
335
336 if ((id1 == 0x22) && ((id2 & 0xFFF0) == 0x1620)) {
337 /* finalize phy configuration for Micrel KSZ9031 */
338 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 2);
339 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 4);
340 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_POST_INC_W | 0x2);
341 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x0000);
342
343 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 2);
344 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 5);
345 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_POST_INC_W | 0x2);
346 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, MII_KSZ9031_MOD_REG);
347
348 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 2);
349 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 6);
350 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_POST_INC_W | 0x2);
351 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0xFFFF);
352
353 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 2);
354 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 8);
355 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_POST_INC_W | 0x2);
356 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x3FFF);
357
358 /* fix KSZ9031 link up issue */
359 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 0x0);
360 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x4);
361 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_NO_POST_INC);
362 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x6);
363 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_REG);
364 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x3);
365 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_NO_POST_INC);
366 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, 0x1A80);
367 }
368
369 if ((id1 == 0x004d) && (id2 == 0xd072)) {
370 /* enable AR8035 ouput a 125MHz clk from CLK_25M */
371 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, 0x7);
372 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, MII_KSZ9031_MOD_DATA_POST_INC_RW | 0x16);
373 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_CONTROL, MII_KSZ9031_MOD_DATA_NO_POST_INC | 0x7);
374 val = phy_read(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA);
375 val &= 0xfe63;
376 val |= 0x18;
377 phy_write(phydev, MDIO_DEVAD_NONE, MMD_ACCESS_REG_DATA, val);
378
379 /* introduce tx clock delay */
380 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
381 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
382 val |= 0x0100;
383 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
384
385 /* disable hibernation */
386 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0xb);
387 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
388 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x3c40);
389 }
390 return 0;
391}
392
393int board_phy_config(struct phy_device *phydev)
394{
395 mx6_rgmii_rework(phydev);
396
397 if (phydev->drv->config)
398 phydev->drv->config(phydev);
399
Otavio Salvador0378d632015-07-23 11:02:28 -0300400 return 0;
401}
402
SARTRE Leodce71762013-06-03 23:30:36 +0000403static void setup_iomux_uart(void)
404{
Otavio Salvadore186b182015-11-19 19:02:36 -0200405 SETUP_IOMUX_PADS(uart2_pads);
SARTRE Leodce71762013-06-03 23:30:36 +0000406}
Otavio Salvadorf594b552015-11-19 19:02:33 -0200407
408#ifdef CONFIG_MXC_SPI
409static void setup_spi(void)
410{
Michael Schanzbdf18fa2015-12-10 09:58:35 +0100411 SETUP_IOMUX_PADS(ecspi1_pads);
Otavio Salvadorf594b552015-11-19 19:02:33 -0200412 gpio_direction_output(IMX_GPIO_NR(3, 19), 0);
413}
414#endif
SARTRE Leodce71762013-06-03 23:30:36 +0000415
Yangbo Lu73340382019-06-21 11:42:28 +0800416#ifdef CONFIG_FSL_ESDHC_IMX
Otavio Salvadord08683f2015-07-23 11:02:21 -0300417static struct fsl_esdhc_cfg usdhc_cfg[] = {
SARTRE Leodce71762013-06-03 23:30:36 +0000418 {USDHC2_BASE_ADDR},
Otavio Salvadordff4c302015-07-23 11:02:24 -0300419 {USDHC3_BASE_ADDR},
SARTRE Leodce71762013-06-03 23:30:36 +0000420 {USDHC4_BASE_ADDR},
421};
422
423int board_mmc_getcd(struct mmc *mmc)
424{
425 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
426 int ret = 0;
427
428 switch (cfg->esdhc_base) {
429 case USDHC2_BASE_ADDR:
430 gpio_direction_input(IMX_GPIO_NR(1, 4));
431 ret = !gpio_get_value(IMX_GPIO_NR(1, 4));
432 break;
Otavio Salvadordff4c302015-07-23 11:02:24 -0300433 case USDHC3_BASE_ADDR:
434 ret = 1; /* eMMC is always present */
435 break;
SARTRE Leodce71762013-06-03 23:30:36 +0000436 case USDHC4_BASE_ADDR:
437 gpio_direction_input(IMX_GPIO_NR(2, 6));
438 ret = !gpio_get_value(IMX_GPIO_NR(2, 6));
439 break;
440 default:
441 printf("Bad USDHC interface\n");
442 }
443
444 return ret;
445}
446
447int board_mmc_init(bd_t *bis)
448{
Otavio Salvadore186b182015-11-19 19:02:36 -0200449#ifndef CONFIG_SPL_BUILD
SARTRE Leodce71762013-06-03 23:30:36 +0000450 s32 status = 0;
Otavio Salvador7b4a64b2015-07-23 11:02:22 -0300451 int i;
SARTRE Leodce71762013-06-03 23:30:36 +0000452
453 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
Otavio Salvadordff4c302015-07-23 11:02:24 -0300454 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
455 usdhc_cfg[2].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
SARTRE Leodce71762013-06-03 23:30:36 +0000456
Otavio Salvadore186b182015-11-19 19:02:36 -0200457 SETUP_IOMUX_PADS(usdhc2_pads);
458 SETUP_IOMUX_PADS(usdhc3_pads);
459 SETUP_IOMUX_PADS(usdhc4_pads);
SARTRE Leodce71762013-06-03 23:30:36 +0000460
Otavio Salvador7b4a64b2015-07-23 11:02:22 -0300461 for (i = 0; i < ARRAY_SIZE(usdhc_cfg); i++) {
462 status = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
463 if (status)
464 return status;
465 }
SARTRE Leodce71762013-06-03 23:30:36 +0000466
Otavio Salvador7b4a64b2015-07-23 11:02:22 -0300467 return 0;
Otavio Salvadore186b182015-11-19 19:02:36 -0200468#else
469 SETUP_IOMUX_PADS(usdhc4_pads);
470 usdhc_cfg[0].esdhc_base = USDHC4_BASE_ADDR;
471 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
472 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
473
474 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
475#endif
SARTRE Leodce71762013-06-03 23:30:36 +0000476}
477#endif
478
Otavio Salvadorc8762d02015-07-23 11:02:29 -0300479int board_ehci_hcd_init(int port)
480{
481 switch (port) {
482 case 0:
Otavio Salvadore186b182015-11-19 19:02:36 -0200483 SETUP_IOMUX_PADS(usb_otg_pads);
Otavio Salvadorc8762d02015-07-23 11:02:29 -0300484 /*
485 * set daisy chain for otg_pin_id on 6q.
486 * for 6dl, this bit is reserved
487 */
488 imx_iomux_set_gpr_register(1, 13, 1, 1);
489 break;
490 case 1:
491 /* nothing to do */
492 break;
493 default:
494 printf("Invalid USB port: %d\n", port);
495 return -EINVAL;
496 }
497
498 return 0;
499}
500
501int board_ehci_power(int port, int on)
502{
503 switch (port) {
504 case 0:
505 break;
506 case 1:
507 gpio_direction_output(IMX_GPIO_NR(5, 5), on);
508 break;
509 default:
510 printf("Invalid USB port: %d\n", port);
511 return -EINVAL;
512 }
513
514 return 0;
515}
516
Otavio Salvador6c46cd12015-07-23 11:02:30 -0300517struct display_info_t {
518 int bus;
519 int addr;
520 int pixfmt;
521 int (*detect)(struct display_info_t const *dev);
522 void (*enable)(struct display_info_t const *dev);
523 struct fb_videomode mode;
524};
525
526static void disable_lvds(struct display_info_t const *dev)
527{
528 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
529
530 clrbits_le32(&iomux->gpr[2], IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
531 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
532}
533
534static void do_enable_hdmi(struct display_info_t const *dev)
535{
536 disable_lvds(dev);
537 imx_enable_hdmi_phy();
538}
539
540static struct display_info_t const displays[] = {
541{
542 .bus = -1,
543 .addr = 0,
544 .pixfmt = IPU_PIX_FMT_RGB666,
545 .detect = NULL,
546 .enable = NULL,
547 .mode = {
548 .name =
549 "Hannstar-XGA",
550 .refresh = 60,
551 .xres = 1024,
552 .yres = 768,
553 .pixclock = 15385,
554 .left_margin = 220,
555 .right_margin = 40,
556 .upper_margin = 21,
557 .lower_margin = 7,
558 .hsync_len = 60,
559 .vsync_len = 10,
560 .sync = FB_SYNC_EXT,
561 .vmode = FB_VMODE_NONINTERLACED } },
562{
563 .bus = -1,
564 .addr = 0,
565 .pixfmt = IPU_PIX_FMT_RGB24,
566 .detect = NULL,
567 .enable = do_enable_hdmi,
568 .mode = {
569 .name = "HDMI",
570 .refresh = 60,
571 .xres = 1024,
572 .yres = 768,
573 .pixclock = 15385,
574 .left_margin = 220,
575 .right_margin = 40,
576 .upper_margin = 21,
577 .lower_margin = 7,
578 .hsync_len = 60,
579 .vsync_len = 10,
580 .sync = FB_SYNC_EXT,
581 .vmode = FB_VMODE_NONINTERLACED } }
582};
583
584int board_video_skip(void)
585{
586 int i;
587 int ret;
Simon Glass64b723f2017-08-03 12:22:12 -0600588 char const *panel = env_get("panel");
Otavio Salvador6c46cd12015-07-23 11:02:30 -0300589 if (!panel) {
590 for (i = 0; i < ARRAY_SIZE(displays); i++) {
591 struct display_info_t const *dev = displays + i;
592 if (dev->detect && dev->detect(dev)) {
593 panel = dev->mode.name;
594 printf("auto-detected panel %s\n", panel);
595 break;
596 }
597 }
598 if (!panel) {
599 panel = displays[0].mode.name;
600 printf("No panel detected: default to %s\n", panel);
601 i = 0;
602 }
603 } else {
604 for (i = 0; i < ARRAY_SIZE(displays); i++) {
605 if (!strcmp(panel, displays[i].mode.name))
606 break;
607 }
608 }
609 if (i < ARRAY_SIZE(displays)) {
610 ret = ipuv3_fb_init(&displays[i].mode, 0, displays[i].pixfmt);
611 if (!ret) {
612 if (displays[i].enable)
613 displays[i].enable(displays + i);
614 printf("Display: %s (%ux%u)\n",
615 displays[i].mode.name, displays[i].mode.xres,
616 displays[i].mode.yres);
617 } else
618 printf("LCD %s cannot be configured: %d\n",
619 displays[i].mode.name, ret);
620 } else {
621 printf("unsupported panel %s\n", panel);
622 return -EINVAL;
623 }
624
625 return 0;
626}
627
628static void setup_display(void)
629{
630 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
631 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
632 int reg;
633
634 enable_ipu_clock();
635 imx_setup_hdmi();
636
637 /* Turn on LDB0, LDB1, IPU,IPU DI0 clocks */
638 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK |
639 MXC_CCM_CCGR3_LDB_DI1_MASK);
640
641 /* set LDB0, LDB1 clk select to 011/011 */
642 reg = readl(&mxc_ccm->cs2cdr);
643 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
644 MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
645 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
646 (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
647 writel(reg, &mxc_ccm->cs2cdr);
648
649 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV |
650 MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV);
651
652 setbits_le32(&mxc_ccm->chsccdr, CHSCCDR_CLK_SEL_LDB_DI0 <<
653 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET |
654 CHSCCDR_CLK_SEL_LDB_DI0 <<
655 MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
656
657 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
658 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW
659 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
660 | IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
661 | IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
662 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
663 | IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
664 | IOMUXC_GPR2_LVDS_CH0_MODE_DISABLED
665 | IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0;
666 writel(reg, &iomux->gpr[2]);
667
668 reg = readl(&iomux->gpr[3]);
669 reg = (reg & ~(IOMUXC_GPR3_LVDS1_MUX_CTL_MASK |
670 IOMUXC_GPR3_HDMI_MUX_CTL_MASK)) |
671 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
672 IOMUXC_GPR3_LVDS1_MUX_CTL_OFFSET);
673 writel(reg, &iomux->gpr[3]);
674}
675
676/*
677 * Do not overwrite the console
678 * Use always serial for U-Boot console
679 */
680int overwrite_console(void)
681{
682 return 1;
683}
684
SARTRE Leodce71762013-06-03 23:30:36 +0000685int board_early_init_f(void)
686{
687 setup_iomux_uart();
Otavio Salvadorf594b552015-11-19 19:02:33 -0200688#ifdef CONFIG_MXC_SPI
689 setup_spi();
690#endif
SARTRE Leodce71762013-06-03 23:30:36 +0000691 return 0;
692}
693
694int board_init(void)
695{
696 /* address of boot parameters */
697 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
698
Otavio Salvadore186b182015-11-19 19:02:36 -0200699
Breno Limacc4aac32016-07-22 09:12:12 -0300700 if (is_mx6dq())
Otavio Salvadore186b182015-11-19 19:02:36 -0200701 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6q_i2c_pad_info1);
702 else
703 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &mx6dl_i2c_pad_info1);
Otavio Salvador0378d632015-07-23 11:02:28 -0300704
Fabio Estevamddce0222017-09-22 23:45:29 -0300705 setup_display();
706
Simon Glassab3055a2017-06-14 21:28:25 -0600707#ifdef CONFIG_SATA
Otavio Salvadordf82d002015-07-23 11:02:31 -0300708 setup_sata();
709#endif
710
SARTRE Leodce71762013-06-03 23:30:36 +0000711 return 0;
712}
713
714int checkboard(void)
715{
Otavio Salvadore186b182015-11-19 19:02:36 -0200716 char *type = "unknown";
717
718 if (is_cpu_type(MXC_CPU_MX6Q))
719 type = "Quad";
720 else if (is_cpu_type(MXC_CPU_MX6D))
721 type = "Dual";
722 else if (is_cpu_type(MXC_CPU_MX6DL))
723 type = "Dual-Lite";
724 else if (is_cpu_type(MXC_CPU_MX6SOLO))
725 type = "Solo";
726
727 printf("Board: conga-QMX6 %s\n", type);
SARTRE Leodce71762013-06-03 23:30:36 +0000728
729 return 0;
730}
Otavio Salvadorf594b552015-11-19 19:02:33 -0200731
732#ifdef CONFIG_MXC_SPI
733int board_spi_cs_gpio(unsigned bus, unsigned cs)
734{
735 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -EINVAL;
736}
737#endif
SARTRE Leodce71762013-06-03 23:30:36 +0000738
739#ifdef CONFIG_CMD_BMODE
740static const struct boot_mode board_boot_modes[] = {
741 /* 4 bit bus width */
742 {"mmc0", MAKE_CFGVAL(0x50, 0x20, 0x00, 0x00)},
743 {"mmc1", MAKE_CFGVAL(0x50, 0x38, 0x00, 0x00)},
744 {NULL, 0},
745};
746#endif
747
748int misc_init_r(void)
749{
750#ifdef CONFIG_CMD_BMODE
751 add_board_boot_modes(board_boot_modes);
752#endif
Otavio Salvadore186b182015-11-19 19:02:36 -0200753 return 0;
754}
755
756int board_late_init(void)
757{
758#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Breno Limacc4aac32016-07-22 09:12:12 -0300759 if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600760 env_set("board_rev", "MX6Q");
Otavio Salvadore186b182015-11-19 19:02:36 -0200761 else
Simon Glass6a38e412017-08-03 12:22:09 -0600762 env_set("board_rev", "MX6DL");
Otavio Salvadore186b182015-11-19 19:02:36 -0200763#endif
764
SARTRE Leodce71762013-06-03 23:30:36 +0000765 return 0;
766}
Otavio Salvadore186b182015-11-19 19:02:36 -0200767
768#ifdef CONFIG_SPL_BUILD
769#include <asm/arch/mx6-ddr.h>
770#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900771#include <linux/libfdt.h>
Otavio Salvadore186b182015-11-19 19:02:36 -0200772#include <spi_flash.h>
773#include <spi.h>
774
775const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {
776 .dram_sdclk_0 = 0x00000030,
777 .dram_sdclk_1 = 0x00000030,
778 .dram_cas = 0x00000030,
779 .dram_ras = 0x00000030,
780 .dram_reset = 0x00000030,
781 .dram_sdcke0 = 0x00003000,
782 .dram_sdcke1 = 0x00003000,
783 .dram_sdba2 = 0x00000000,
784 .dram_sdodt0 = 0x00000030,
785 .dram_sdodt1 = 0x00000030,
786 .dram_sdqs0 = 0x00000030,
787 .dram_sdqs1 = 0x00000030,
788 .dram_sdqs2 = 0x00000030,
789 .dram_sdqs3 = 0x00000030,
790 .dram_sdqs4 = 0x00000030,
791 .dram_sdqs5 = 0x00000030,
792 .dram_sdqs6 = 0x00000030,
793 .dram_sdqs7 = 0x00000030,
794 .dram_dqm0 = 0x00000030,
795 .dram_dqm1 = 0x00000030,
796 .dram_dqm2 = 0x00000030,
797 .dram_dqm3 = 0x00000030,
798 .dram_dqm4 = 0x00000030,
799 .dram_dqm5 = 0x00000030,
800 .dram_dqm6 = 0x00000030,
801 .dram_dqm7 = 0x00000030,
802};
803
804static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = {
805 .dram_sdclk_0 = 0x00000030,
806 .dram_sdclk_1 = 0x00000030,
807 .dram_cas = 0x00000030,
808 .dram_ras = 0x00000030,
809 .dram_reset = 0x00000030,
810 .dram_sdcke0 = 0x00003000,
811 .dram_sdcke1 = 0x00003000,
812 .dram_sdba2 = 0x00000000,
813 .dram_sdodt0 = 0x00000030,
814 .dram_sdodt1 = 0x00000030,
815 .dram_sdqs0 = 0x00000030,
816 .dram_sdqs1 = 0x00000030,
817 .dram_sdqs2 = 0x00000030,
818 .dram_sdqs3 = 0x00000030,
819 .dram_sdqs4 = 0x00000030,
820 .dram_sdqs5 = 0x00000030,
821 .dram_sdqs6 = 0x00000030,
822 .dram_sdqs7 = 0x00000030,
823 .dram_dqm0 = 0x00000030,
824 .dram_dqm1 = 0x00000030,
825 .dram_dqm2 = 0x00000030,
826 .dram_dqm3 = 0x00000030,
827 .dram_dqm4 = 0x00000030,
828 .dram_dqm5 = 0x00000030,
829 .dram_dqm6 = 0x00000030,
830 .dram_dqm7 = 0x00000030,
831};
832
833const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = {
834 .grp_ddr_type = 0x000C0000,
835 .grp_ddrmode_ctl = 0x00020000,
836 .grp_ddrpke = 0x00000000,
837 .grp_addds = 0x00000030,
838 .grp_ctlds = 0x00000030,
839 .grp_ddrmode = 0x00020000,
840 .grp_b0ds = 0x00000030,
841 .grp_b1ds = 0x00000030,
842 .grp_b2ds = 0x00000030,
843 .grp_b3ds = 0x00000030,
844 .grp_b4ds = 0x00000030,
845 .grp_b5ds = 0x00000030,
846 .grp_b6ds = 0x00000030,
847 .grp_b7ds = 0x00000030,
848};
849
850static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
851 .grp_ddr_type = 0x000c0000,
852 .grp_ddrmode_ctl = 0x00020000,
853 .grp_ddrpke = 0x00000000,
854 .grp_addds = 0x00000030,
855 .grp_ctlds = 0x00000030,
856 .grp_ddrmode = 0x00020000,
857 .grp_b0ds = 0x00000030,
858 .grp_b1ds = 0x00000030,
859 .grp_b2ds = 0x00000030,
860 .grp_b3ds = 0x00000030,
861 .grp_b4ds = 0x00000030,
862 .grp_b5ds = 0x00000030,
863 .grp_b6ds = 0x00000030,
864 .grp_b7ds = 0x00000030,
865};
866
867const struct mx6_mmdc_calibration mx6q_mmcd_calib = {
868 .p0_mpwldectrl0 = 0x0016001A,
869 .p0_mpwldectrl1 = 0x0023001C,
870 .p1_mpwldectrl0 = 0x0028003A,
871 .p1_mpwldectrl1 = 0x001F002C,
872 .p0_mpdgctrl0 = 0x43440354,
873 .p0_mpdgctrl1 = 0x033C033C,
874 .p1_mpdgctrl0 = 0x43300368,
875 .p1_mpdgctrl1 = 0x03500330,
876 .p0_mprddlctl = 0x3228242E,
877 .p1_mprddlctl = 0x2C2C2636,
878 .p0_mpwrdlctl = 0x36323A38,
879 .p1_mpwrdlctl = 0x42324440,
880};
881
882const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = {
883 .p0_mpwldectrl0 = 0x00080016,
884 .p0_mpwldectrl1 = 0x001D0016,
885 .p1_mpwldectrl0 = 0x0018002C,
886 .p1_mpwldectrl1 = 0x000D001D,
887 .p0_mpdgctrl0 = 0x43200334,
888 .p0_mpdgctrl1 = 0x0320031C,
889 .p1_mpdgctrl0 = 0x0344034C,
890 .p1_mpdgctrl1 = 0x03380314,
891 .p0_mprddlctl = 0x3E36383A,
892 .p1_mprddlctl = 0x38363240,
893 .p0_mpwrdlctl = 0x36364238,
894 .p1_mpwrdlctl = 0x4230423E,
895};
896
897static const struct mx6_mmdc_calibration mx6s_mmcd_calib = {
898 .p0_mpwldectrl0 = 0x00480049,
899 .p0_mpwldectrl1 = 0x00410044,
900 .p0_mpdgctrl0 = 0x42480248,
901 .p0_mpdgctrl1 = 0x023C023C,
902 .p0_mprddlctl = 0x40424644,
903 .p0_mpwrdlctl = 0x34323034,
904};
905
906const struct mx6_mmdc_calibration mx6dl_mmcd_calib = {
907 .p0_mpwldectrl0 = 0x0043004B,
908 .p0_mpwldectrl1 = 0x003A003E,
909 .p1_mpwldectrl0 = 0x0047004F,
910 .p1_mpwldectrl1 = 0x004E0061,
911 .p0_mpdgctrl0 = 0x42500250,
912 .p0_mpdgctrl1 = 0x0238023C,
913 .p1_mpdgctrl0 = 0x42640264,
914 .p1_mpdgctrl1 = 0x02500258,
915 .p0_mprddlctl = 0x40424846,
916 .p1_mprddlctl = 0x46484842,
917 .p0_mpwrdlctl = 0x38382C30,
918 .p1_mpwrdlctl = 0x34343430,
919};
920
921static struct mx6_ddr3_cfg mem_ddr_2g = {
922 .mem_speed = 1600,
923 .density = 2,
924 .width = 16,
925 .banks = 8,
926 .rowaddr = 14,
927 .coladdr = 10,
928 .pagesz = 2,
929 .trcd = 1310,
930 .trcmin = 4875,
931 .trasmin = 3500,
932};
933
934static struct mx6_ddr3_cfg mem_ddr_4g = {
935 .mem_speed = 1600,
936 .density = 4,
937 .width = 16,
938 .banks = 8,
939 .rowaddr = 15,
940 .coladdr = 10,
941 .pagesz = 2,
942 .trcd = 1310,
943 .trcmin = 4875,
944 .trasmin = 3500,
945};
946
947static void ccgr_init(void)
948{
949 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
950
951 writel(0x00C03F3F, &ccm->CCGR0);
952 writel(0x0030FC03, &ccm->CCGR1);
953 writel(0x0FFFC000, &ccm->CCGR2);
954 writel(0x3FF00000, &ccm->CCGR3);
955 writel(0x00FFF300, &ccm->CCGR4);
956 writel(0x0F0000C3, &ccm->CCGR5);
957 writel(0x000003FF, &ccm->CCGR6);
958}
959
Otavio Salvadore186b182015-11-19 19:02:36 -0200960/* Define a minimal structure so that the part number can be read via SPL */
961struct mfgdata {
962 unsigned char tsize;
963 /* size of checksummed part in bytes */
964 unsigned char ckcnt;
965 /* checksum corrected byte */
966 unsigned char cksum;
967 /* decimal serial number, packed BCD */
968 unsigned char serial[6];
969 /* part number, right justified, ASCII */
970 unsigned char pn[16];
971};
972
973static void conv_ascii(unsigned char *dst, unsigned char *src, int len)
974{
975 int remain = len;
976 unsigned char *sptr = src;
977 unsigned char *dptr = dst;
978
979 while (remain) {
980 if (*sptr) {
981 *dptr = *sptr;
982 dptr++;
983 }
984 sptr++;
985 remain--;
986 }
987 *dptr = 0x0;
988}
989
990#define CFG_MFG_ADDR_OFFSET (spi->size - SZ_16K)
991static bool is_2gb(void)
992{
993 struct spi_flash *spi;
994 int ret;
995 char buf[sizeof(struct mfgdata)];
996 struct mfgdata *data = (struct mfgdata *)buf;
997 unsigned char outbuf[32];
998
999 spi = spi_flash_probe(CONFIG_ENV_SPI_BUS,
1000 CONFIG_ENV_SPI_CS,
1001 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
1002 ret = spi_flash_read(spi, CFG_MFG_ADDR_OFFSET, sizeof(struct mfgdata),
1003 buf);
1004 if (ret)
1005 return false;
1006
1007 /* Congatec Part Numbers 104 and 105 have 2GiB of RAM */
1008 conv_ascii(outbuf, data->pn, sizeof(data->pn));
1009 if (!memcmp(outbuf, "016104", 6) || !memcmp(outbuf, "016105", 6))
1010 return true;
1011 else
1012 return false;
1013}
1014
1015static void spl_dram_init(int width)
1016{
1017 struct mx6_ddr_sysinfo sysinfo = {
1018 /* width of data bus:0=16,1=32,2=64 */
1019 .dsize = width / 32,
1020 /* config for full 4GB range so that get_mem_size() works */
1021 .cs_density = 32, /* 32Gb per CS */
1022 /* single chip select */
1023 .ncs = 1,
1024 .cs1_mirror = 0,
1025 .rtt_wr = 2,
1026 .rtt_nom = 2,
1027 .walat = 0,
1028 .ralat = 5,
1029 .mif3_mode = 3,
1030 .bi_on = 1,
1031 .sde_to_rst = 0x0d,
1032 .rst_to_cke = 0x20,
Fabio Estevamcb3c1212016-08-29 20:37:15 -03001033 .refsel = 1, /* Refresh cycles at 32KHz */
1034 .refr = 7, /* 8 refresh commands per refresh cycle */
Otavio Salvadore186b182015-11-19 19:02:36 -02001035 };
1036
1037 if (is_cpu_type(MXC_CPU_MX6Q) && is_2gb()) {
1038 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
1039 mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g);
1040 return;
1041 }
1042
Breno Limacc4aac32016-07-22 09:12:12 -03001043 if (is_mx6dq()) {
Otavio Salvadore186b182015-11-19 19:02:36 -02001044 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
1045 mx6_dram_cfg(&sysinfo, &mx6q_mmcd_calib, &mem_ddr_2g);
1046 } else if (is_cpu_type(MXC_CPU_MX6SOLO)) {
1047 sysinfo.walat = 1;
1048 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
1049 mx6_dram_cfg(&sysinfo, &mx6s_mmcd_calib, &mem_ddr_4g);
1050 } else if (is_cpu_type(MXC_CPU_MX6DL)) {
1051 sysinfo.walat = 1;
1052 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
1053 mx6_dram_cfg(&sysinfo, &mx6dl_mmcd_calib, &mem_ddr_2g);
1054 }
1055}
1056
1057void board_init_f(ulong dummy)
1058{
1059 /* setup AIPS and disable watchdog */
1060 arch_cpu_init();
1061
1062 ccgr_init();
1063 gpr_init();
1064
1065 /* iomux and setup of i2c */
1066 board_early_init_f();
1067
1068 /* setup GP timer */
1069 timer_init();
1070
1071 /* UART clocks enabled and gd valid - init serial console */
1072 preloader_console_init();
1073
1074 /* Needed for malloc() to work in SPL prior to board_init_r() */
1075 spl_init();
1076
1077 /* DDR initialization */
1078 if (is_cpu_type(MXC_CPU_MX6SOLO))
1079 spl_dram_init(32);
1080 else
1081 spl_dram_init(64);
1082
1083 /* Clear the BSS. */
1084 memset(__bss_start, 0, __bss_end - __bss_start);
1085
1086 /* load/boot image from boot device */
1087 board_init_r(NULL, 0);
1088}
1089#endif