blob: 51bbbc4cdf270fc7f84c07608c635a7bc4cd3412 [file] [log] [blame]
Fabio Estevamafe20bf2012-09-24 08:09:33 +00001/*
2 * Copyright (C) 2012 Freescale Semiconductor, Inc.
3 *
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Fabio Estevamafe20bf2012-09-24 08:09:33 +00007 */
8
9#include <common.h>
10#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>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Fabio Estevamafe20bf2012-09-24 08:09:33 +000016#include <asm/gpio.h>
17#include <asm/imx-common/iomux-v3.h>
Renato Friasbf084322013-05-13 18:01:12 +000018#include <asm/imx-common/mxc_i2c.h>
Otavio Salvador52863372013-03-16 08:05:07 +000019#include <asm/imx-common/boot_mode.h>
Eric Nelson16acd1c2014-09-30 15:40:03 -070020#include <asm/imx-common/spi.h>
Fabio Estevamafe20bf2012-09-24 08:09:33 +000021#include <mmc.h>
22#include <fsl_esdhc.h>
Fabio Estevambe59b6a2012-09-25 08:43:57 +000023#include <miiphy.h>
24#include <netdev.h>
Fabio Estevam96ad33d2012-10-02 11:20:12 +000025#include <asm/arch/sys_proto.h>
Renato Friasbf084322013-05-13 18:01:12 +000026#include <i2c.h>
Fabio Estevam5a6c8c42014-09-22 13:55:52 -030027#include <asm/arch/mxc_hdmi.h>
28#include <asm/imx-common/video.h>
29#include <asm/arch/crm_regs.h>
Ye.Li700020e2014-10-30 18:53:49 +080030#include <pca953x.h>
Ye.Licfaa23b2014-11-06 16:29:02 +080031#include <power/pmic.h>
Peng Fane5bcd4d2015-01-27 10:14:04 +080032#include <power/pfuze100_pmic.h>
Ye.Licfaa23b2014-11-06 16:29:02 +080033#include "../common/pfuze.h"
Fabio Estevam96ad33d2012-10-02 11:20:12 +000034
Fabio Estevamafe20bf2012-09-24 08:09:33 +000035DECLARE_GLOBAL_DATA_PTR;
36
Benoît Thébaudeau21670242013-04-26 01:34:47 +000037#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
38 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
39 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevamafe20bf2012-09-24 08:09:33 +000040
Benoît Thébaudeau21670242013-04-26 01:34:47 +000041#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
42 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
43 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevamafe20bf2012-09-24 08:09:33 +000044
Benoît Thébaudeau21670242013-04-26 01:34:47 +000045#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
46 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevambe59b6a2012-09-25 08:43:57 +000047
Renato Friasbf084322013-05-13 18:01:12 +000048#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
50 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
51
Ye.Li4a1f9222014-11-12 14:02:05 +080052#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
53#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
54 PAD_CTL_SRE_FAST)
55#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
56
Renato Friasbf084322013-05-13 18:01:12 +000057#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
58
Fabio Estevam2623cb12014-11-14 11:27:23 -020059#define WEIM_NOR_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
60 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
61 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
62
Ye.Licfaa23b2014-11-06 16:29:02 +080063#define I2C_PMIC 1
64
Fabio Estevamafe20bf2012-09-24 08:09:33 +000065int dram_init(void)
66{
Vanessa Maegima627c0e52016-06-08 15:17:54 -030067 gd->ram_size = imx_ddr_size();
Fabio Estevamafe20bf2012-09-24 08:09:33 +000068
69 return 0;
70}
71
Fabio Estevam6bfdb102014-09-13 18:21:36 -030072static iomux_v3_cfg_t const uart4_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -070073 MX6_PAD_KEY_COL0__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
74 MX6_PAD_KEY_ROW0__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Fabio Estevamafe20bf2012-09-24 08:09:33 +000075};
76
Fabio Estevam6bfdb102014-09-13 18:21:36 -030077static iomux_v3_cfg_t const enet_pads[] = {
Eric Nelsonafea2ba2013-02-19 10:07:01 +000078 MX6_PAD_KEY_COL1__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
79 MX6_PAD_KEY_COL2__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson3d3be0a2013-11-04 17:00:51 -070080 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
81 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
82 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
83 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
84 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsonafea2ba2013-02-19 10:07:01 +000085 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
86 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson3d3be0a2013-11-04 17:00:51 -070087 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
88 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
89 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
90 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
91 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsonafea2ba2013-02-19 10:07:01 +000092 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
Fabio Estevambe59b6a2012-09-25 08:43:57 +000093};
94
Renato Friasbf084322013-05-13 18:01:12 +000095/* I2C2 PMIC, iPod, Tuner, Codec, Touch, HDMI EDID, MIPI CSI2 card */
Fabio Estevam6bfdb102014-09-13 18:21:36 -030096static struct i2c_pads_info i2c_pad_info1 = {
Renato Friasbf084322013-05-13 18:01:12 +000097 .scl = {
98 .i2c_mode = MX6_PAD_EIM_EB2__I2C2_SCL | PC,
Eric Nelson3d3be0a2013-11-04 17:00:51 -070099 .gpio_mode = MX6_PAD_EIM_EB2__GPIO2_IO30 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000100 .gp = IMX_GPIO_NR(2, 30)
101 },
102 .sda = {
103 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC,
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700104 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO4_IO13 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000105 .gp = IMX_GPIO_NR(4, 13)
106 }
107};
108
Fabio Estevam2623cb12014-11-14 11:27:23 -0200109#ifndef CONFIG_SYS_FLASH_CFI
Renato Friasbf084322013-05-13 18:01:12 +0000110/*
111 * I2C3 MLB, Port Expanders (A, B, C), Video ADC, Light Sensor,
112 * Compass Sensor, Accelerometer, Res Touch
113 */
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300114static struct i2c_pads_info i2c_pad_info2 = {
Renato Friasbf084322013-05-13 18:01:12 +0000115 .scl = {
116 .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC,
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700117 .gpio_mode = MX6_PAD_GPIO_3__GPIO1_IO03 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000118 .gp = IMX_GPIO_NR(1, 3)
119 },
120 .sda = {
121 .i2c_mode = MX6_PAD_EIM_D18__I2C3_SDA | PC,
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700122 .gpio_mode = MX6_PAD_EIM_D18__GPIO3_IO18 | PC,
Renato Friasbf084322013-05-13 18:01:12 +0000123 .gp = IMX_GPIO_NR(3, 18)
124 }
125};
Fabio Estevam2623cb12014-11-14 11:27:23 -0200126#endif
Renato Friasbf084322013-05-13 18:01:12 +0000127
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300128static iomux_v3_cfg_t const i2c3_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700129 MX6_PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL),
Renato Friasbf084322013-05-13 18:01:12 +0000130};
131
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300132static iomux_v3_cfg_t const port_exp[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700133 MX6_PAD_SD2_DAT0__GPIO1_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
Renato Frias7cbaae82013-05-13 18:01:13 +0000134};
135
Ye.Li700020e2014-10-30 18:53:49 +0800136/*Define for building port exp gpio, pin starts from 0*/
137#define PORTEXP_IO_NR(chip, pin) \
138 ((chip << 5) + pin)
139
140/*Get the chip addr from a ioexp gpio*/
141#define PORTEXP_IO_TO_CHIP(gpio_nr) \
142 (gpio_nr >> 5)
143
144/*Get the pin number from a ioexp gpio*/
145#define PORTEXP_IO_TO_PIN(gpio_nr) \
146 (gpio_nr & 0x1f)
147
148static int port_exp_direction_output(unsigned gpio, int value)
149{
150 int ret;
151
152 i2c_set_bus_num(2);
153 ret = i2c_probe(PORTEXP_IO_TO_CHIP(gpio));
154 if (ret)
155 return ret;
156
157 ret = pca953x_set_dir(PORTEXP_IO_TO_CHIP(gpio),
158 (1 << PORTEXP_IO_TO_PIN(gpio)),
159 (PCA953X_DIR_OUT << PORTEXP_IO_TO_PIN(gpio)));
160
161 if (ret)
162 return ret;
163
164 ret = pca953x_set_val(PORTEXP_IO_TO_CHIP(gpio),
165 (1 << PORTEXP_IO_TO_PIN(gpio)),
166 (value << PORTEXP_IO_TO_PIN(gpio)));
167
168 if (ret)
169 return ret;
170
171 return 0;
172}
173
Fabio Estevam2623cb12014-11-14 11:27:23 -0200174static iomux_v3_cfg_t const eimnor_pads[] = {
175 MX6_PAD_EIM_D16__EIM_DATA16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
176 MX6_PAD_EIM_D17__EIM_DATA17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
177 MX6_PAD_EIM_D18__EIM_DATA18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
178 MX6_PAD_EIM_D19__EIM_DATA19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
179 MX6_PAD_EIM_D20__EIM_DATA20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
180 MX6_PAD_EIM_D21__EIM_DATA21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
181 MX6_PAD_EIM_D22__EIM_DATA22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
182 MX6_PAD_EIM_D23__EIM_DATA23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
183 MX6_PAD_EIM_D24__EIM_DATA24 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
184 MX6_PAD_EIM_D25__EIM_DATA25 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
185 MX6_PAD_EIM_D26__EIM_DATA26 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
186 MX6_PAD_EIM_D27__EIM_DATA27 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
187 MX6_PAD_EIM_D28__EIM_DATA28 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
188 MX6_PAD_EIM_D29__EIM_DATA29 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
189 MX6_PAD_EIM_D30__EIM_DATA30 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
190 MX6_PAD_EIM_D31__EIM_DATA31 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
191 MX6_PAD_EIM_DA0__EIM_AD00 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
192 MX6_PAD_EIM_DA1__EIM_AD01 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
193 MX6_PAD_EIM_DA2__EIM_AD02 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
194 MX6_PAD_EIM_DA3__EIM_AD03 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
195 MX6_PAD_EIM_DA4__EIM_AD04 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
196 MX6_PAD_EIM_DA5__EIM_AD05 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
197 MX6_PAD_EIM_DA6__EIM_AD06 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
198 MX6_PAD_EIM_DA7__EIM_AD07 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
199 MX6_PAD_EIM_DA8__EIM_AD08 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
200 MX6_PAD_EIM_DA9__EIM_AD09 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
201 MX6_PAD_EIM_DA10__EIM_AD10 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
202 MX6_PAD_EIM_DA11__EIM_AD11 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL) ,
203 MX6_PAD_EIM_DA12__EIM_AD12 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
204 MX6_PAD_EIM_DA13__EIM_AD13 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
205 MX6_PAD_EIM_DA14__EIM_AD14 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
206 MX6_PAD_EIM_DA15__EIM_AD15 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
207 MX6_PAD_EIM_A16__EIM_ADDR16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
208 MX6_PAD_EIM_A17__EIM_ADDR17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
209 MX6_PAD_EIM_A18__EIM_ADDR18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
210 MX6_PAD_EIM_A19__EIM_ADDR19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
211 MX6_PAD_EIM_A20__EIM_ADDR20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
212 MX6_PAD_EIM_A21__EIM_ADDR21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
213 MX6_PAD_EIM_A22__EIM_ADDR22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
214 MX6_PAD_EIM_A23__EIM_ADDR23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL),
215 MX6_PAD_EIM_OE__EIM_OE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
216 MX6_PAD_EIM_RW__EIM_RW | MUX_PAD_CTRL(NO_PAD_CTRL),
217 MX6_PAD_EIM_CS0__EIM_CS0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
218};
219
220static void eimnor_cs_setup(void)
221{
222 struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
223
224 writel(0x00020181, &weim_regs->cs0gcr1);
225 writel(0x00000001, &weim_regs->cs0gcr2);
226 writel(0x0a020000, &weim_regs->cs0rcr1);
227 writel(0x0000c000, &weim_regs->cs0rcr2);
228 writel(0x0804a240, &weim_regs->cs0wcr1);
229 writel(0x00000120, &weim_regs->wcr);
230
231 set_chipselect_size(CS0_128);
232}
233
Fabio Estevame795b6d2016-12-26 23:04:41 -0200234static void eim_clk_setup(void)
235{
236 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
237 int cscmr1, ccgr6;
238
239
240 /* Turn off EIM clock */
241 ccgr6 = readl(&imx_ccm->CCGR6);
242 ccgr6 &= ~(0x3 << 10);
243 writel(ccgr6, &imx_ccm->CCGR6);
244
245 /*
246 * Configure clk_eim_slow_sel = 00 --> derive clock from AXI clk root
247 * and aclk_eim_slow_podf = 01 --> divide by 2
248 * so that we can have EIM at the maximum clock of 132MHz
249 */
250 cscmr1 = readl(&imx_ccm->cscmr1);
251 cscmr1 &= ~(MXC_CCM_CSCMR1_ACLK_EMI_SLOW_MASK |
252 MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_MASK);
253 cscmr1 |= (1 << MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_OFFSET);
254 writel(cscmr1, &imx_ccm->cscmr1);
255
256 /* Turn on EIM clock */
257 ccgr6 |= (0x3 << 10);
258 writel(ccgr6, &imx_ccm->CCGR6);
259}
260
Fabio Estevam2623cb12014-11-14 11:27:23 -0200261static void setup_iomux_eimnor(void)
262{
263 imx_iomux_v3_setup_multiple_pads(eimnor_pads, ARRAY_SIZE(eimnor_pads));
264
265 gpio_direction_output(IMX_GPIO_NR(5, 4), 0);
266
267 eimnor_cs_setup();
268}
269
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000270static void setup_iomux_enet(void)
271{
272 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
273}
274
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300275static iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -0700276 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
277 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
278 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
279 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
280 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
281 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
282 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
283 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
284 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
285 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
286 MX6_PAD_GPIO_18__SD3_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL),
287 MX6_PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000288};
289
290static void setup_iomux_uart(void)
291{
292 imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads));
293}
294
295#ifdef CONFIG_FSL_ESDHC
Fabio Estevam6bfdb102014-09-13 18:21:36 -0300296static struct fsl_esdhc_cfg usdhc_cfg[1] = {
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000297 {USDHC3_BASE_ADDR},
298};
299
300int board_mmc_getcd(struct mmc *mmc)
301{
302 gpio_direction_input(IMX_GPIO_NR(6, 15));
303 return !gpio_get_value(IMX_GPIO_NR(6, 15));
304}
305
306int board_mmc_init(bd_t *bis)
307{
308 imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
309
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000310 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000311 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
312}
313#endif
314
Ye.Li4a1f9222014-11-12 14:02:05 +0800315#ifdef CONFIG_NAND_MXS
316static iomux_v3_cfg_t gpmi_pads[] = {
317 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
318 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
319 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
320 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL0),
321 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
322 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
323 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
324 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
325 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
326 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
327 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
328 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
329 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
330 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
331 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
332 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(GPMI_PAD_CTRL1),
333};
334
335static void setup_gpmi_nand(void)
336{
337 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
338
339 /* config gpmi nand iomux */
340 imx_iomux_v3_setup_multiple_pads(gpmi_pads, ARRAY_SIZE(gpmi_pads));
341
Ye.Li2dea0402015-01-12 17:37:13 +0800342 setup_gpmi_io_clk((MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
Ye.Li4a1f9222014-11-12 14:02:05 +0800343 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
Ye.Li2dea0402015-01-12 17:37:13 +0800344 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3)));
Ye.Li4a1f9222014-11-12 14:02:05 +0800345
346 /* enable apbh clock gating */
347 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
348}
349#endif
350
Peng Fand4947e32015-07-11 11:38:47 +0800351static void setup_fec(void)
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000352{
Peng Fand4947e32015-07-11 11:38:47 +0800353 if (is_mx6dqp()) {
354 /*
355 * select ENET MAC0 TX clock from PLL
356 */
357 imx_iomux_set_gpr_register(5, 9, 1, 1);
Peng Fan967a83b2015-08-12 17:46:50 +0800358 enable_fec_anatop_clock(0, ENET_125MHZ);
Peng Fand4947e32015-07-11 11:38:47 +0800359 }
360
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000361 setup_iomux_enet();
Peng Fand4947e32015-07-11 11:38:47 +0800362}
363
364int board_eth_init(bd_t *bis)
365{
366 setup_fec();
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000367
Fabio Estevamc0575842014-01-04 17:36:31 -0200368 return cpu_eth_init(bis);
Fabio Estevambe59b6a2012-09-25 08:43:57 +0000369}
370
Fabio Estevam96ad33d2012-10-02 11:20:12 +0000371#define BOARD_REV_B 0x200
372#define BOARD_REV_A 0x100
373
374static int mx6sabre_rev(void)
375{
376 /*
377 * Get Board ID information from OCOTP_GP1[15:8]
378 * i.MX6Q ARD RevA: 0x01
379 * i.MX6Q ARD RevB: 0x02
380 */
381 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Benoît Thébaudeaufa7e3952013-04-23 10:17:38 +0000382 struct fuse_bank *bank = &ocotp->bank[4];
383 struct fuse_bank4_regs *fuse =
384 (struct fuse_bank4_regs *)bank->fuse_regs;
385 int reg = readl(&fuse->gp1);
Fabio Estevam96ad33d2012-10-02 11:20:12 +0000386 int ret;
387
388 switch (reg >> 8 & 0x0F) {
389 case 0x02:
390 ret = BOARD_REV_B;
391 break;
392 case 0x01:
393 default:
394 ret = BOARD_REV_A;
395 break;
396 }
397
398 return ret;
399}
400
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000401u32 get_board_rev(void)
402{
Fabio Estevam96ad33d2012-10-02 11:20:12 +0000403 int rev = mx6sabre_rev();
404
405 return (get_cpu_rev() & ~(0xF << 8)) | rev;
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000406}
407
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300408#if defined(CONFIG_VIDEO_IPUV3)
Peng Fan03f8d152015-12-15 16:27:18 +0800409static void disable_lvds(struct display_info_t const *dev)
410{
411 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
412
413 clrbits_le32(&iomux->gpr[2],
414 IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
415 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
416}
417
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300418static void do_enable_hdmi(struct display_info_t const *dev)
419{
Peng Fan03f8d152015-12-15 16:27:18 +0800420 disable_lvds(dev);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300421 imx_enable_hdmi_phy();
422}
423
424struct display_info_t const displays[] = {{
425 .bus = -1,
426 .addr = 0,
Peng Fan03f8d152015-12-15 16:27:18 +0800427 .pixfmt = IPU_PIX_FMT_RGB666,
428 .detect = NULL,
429 .enable = NULL,
430 .mode = {
431 .name = "Hannstar-XGA",
432 .refresh = 60,
433 .xres = 1024,
434 .yres = 768,
435 .pixclock = 15385,
436 .left_margin = 220,
437 .right_margin = 40,
438 .upper_margin = 21,
439 .lower_margin = 7,
440 .hsync_len = 60,
441 .vsync_len = 10,
442 .sync = FB_SYNC_EXT,
443 .vmode = FB_VMODE_NONINTERLACED
444} }, {
445 .bus = -1,
446 .addr = 0,
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300447 .pixfmt = IPU_PIX_FMT_RGB24,
448 .detect = detect_hdmi,
449 .enable = do_enable_hdmi,
450 .mode = {
451 .name = "HDMI",
452 .refresh = 60,
453 .xres = 1024,
454 .yres = 768,
455 .pixclock = 15385,
456 .left_margin = 220,
457 .right_margin = 40,
458 .upper_margin = 21,
459 .lower_margin = 7,
460 .hsync_len = 60,
461 .vsync_len = 10,
462 .sync = FB_SYNC_EXT,
463 .vmode = FB_VMODE_NONINTERLACED,
464} } };
465size_t display_count = ARRAY_SIZE(displays);
466
Peng Fan03f8d152015-12-15 16:27:18 +0800467iomux_v3_cfg_t const backlight_pads[] = {
468 MX6_PAD_SD4_DAT1__GPIO2_IO09 | MUX_PAD_CTRL(ENET_PAD_CTRL),
469};
470
471static void setup_iomux_backlight(void)
472{
473 gpio_direction_output(IMX_GPIO_NR(2, 9), 1);
474 imx_iomux_v3_setup_multiple_pads(backlight_pads,
475 ARRAY_SIZE(backlight_pads));
476}
477
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300478static void setup_display(void)
479{
480 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan03f8d152015-12-15 16:27:18 +0800481 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300482 int reg;
483
Peng Fan03f8d152015-12-15 16:27:18 +0800484 setup_iomux_backlight();
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300485 enable_ipu_clock();
486 imx_setup_hdmi();
487
Peng Fan03f8d152015-12-15 16:27:18 +0800488 /* Turn on LDB_DI0 and LDB_DI1 clocks */
489 reg = readl(&mxc_ccm->CCGR3);
490 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK | MXC_CCM_CCGR3_LDB_DI1_MASK;
491 writel(reg, &mxc_ccm->CCGR3);
492
493 /* Set LDB_DI0 and LDB_DI1 clk select to 3b'011 */
494 reg = readl(&mxc_ccm->cs2cdr);
495 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
496 MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
497 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
498 (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
499 writel(reg, &mxc_ccm->cs2cdr);
500
501 reg = readl(&mxc_ccm->cscmr2);
502 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV | MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV;
503 writel(reg, &mxc_ccm->cscmr2);
504
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300505 reg = readl(&mxc_ccm->chsccdr);
506 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
507 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Peng Fan03f8d152015-12-15 16:27:18 +0800508 reg |= (CHSCCDR_CLK_SEL_LDB_DI0 <<
509 MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300510 writel(reg, &mxc_ccm->chsccdr);
Peng Fan03f8d152015-12-15 16:27:18 +0800511
512 reg = IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW |
513 IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
514 IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
515 IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT |
516 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
517 IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
518 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0 |
519 IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED;
520 writel(reg, &iomux->gpr[2]);
521
522 reg = readl(&iomux->gpr[3]);
523 reg &= ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
524 IOMUXC_GPR3_HDMI_MUX_CTL_MASK);
525 reg |= (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
526 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET) |
527 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
528 IOMUXC_GPR3_HDMI_MUX_CTL_OFFSET);
529 writel(reg, &iomux->gpr[3]);
Fabio Estevam5a6c8c42014-09-22 13:55:52 -0300530}
531#endif /* CONFIG_VIDEO_IPUV3 */
532
533/*
534 * Do not overwrite the console
535 * Use always serial for U-Boot console
536 */
537int overwrite_console(void)
538{
539 return 1;
540}
541
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000542int board_early_init_f(void)
543{
544 setup_iomux_uart();
Ye.Li4a1f9222014-11-12 14:02:05 +0800545
546#ifdef CONFIG_NAND_MXS
547 setup_gpmi_nand();
548#endif
Fabio Estevame795b6d2016-12-26 23:04:41 -0200549 eim_clk_setup();
Fabio Estevam2623cb12014-11-14 11:27:23 -0200550
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000551 return 0;
552}
553
554int board_init(void)
555{
556 /* address of boot parameters */
557 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
558
Renato Friasbf084322013-05-13 18:01:12 +0000559 /* I2C 2 and 3 setup - I2C 3 hw mux with EIM */
560 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
561 /* I2C 3 Steer */
562 gpio_direction_output(IMX_GPIO_NR(5, 4), 1);
563 imx_iomux_v3_setup_multiple_pads(i2c3_pads, ARRAY_SIZE(i2c3_pads));
Fabio Estevam2623cb12014-11-14 11:27:23 -0200564#ifndef CONFIG_SYS_FLASH_CFI
Renato Friasbf084322013-05-13 18:01:12 +0000565 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
Fabio Estevam2623cb12014-11-14 11:27:23 -0200566#endif
Renato Frias7cbaae82013-05-13 18:01:13 +0000567 gpio_direction_output(IMX_GPIO_NR(1, 15), 1);
568 imx_iomux_v3_setup_multiple_pads(port_exp, ARRAY_SIZE(port_exp));
569
Peng Fan03f8d152015-12-15 16:27:18 +0800570#ifdef CONFIG_VIDEO_IPUV3
571 setup_display();
572#endif
Fabio Estevam2623cb12014-11-14 11:27:23 -0200573 setup_iomux_eimnor();
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000574 return 0;
575}
576
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300577#ifdef CONFIG_MXC_SPI
578int board_spi_cs_gpio(unsigned bus, unsigned cs)
579{
580 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(4, 9)) : -1;
581}
582#endif
583
Ye.Licfaa23b2014-11-06 16:29:02 +0800584int power_init_board(void)
585{
586 struct pmic *p;
Peng Fand4947e32015-07-11 11:38:47 +0800587 unsigned int value;
Ye.Licfaa23b2014-11-06 16:29:02 +0800588
589 p = pfuze_common_init(I2C_PMIC);
590 if (!p)
591 return -ENODEV;
592
Peng Fand4947e32015-07-11 11:38:47 +0800593 if (is_mx6dqp()) {
594 /* set SW2 staby volatage 0.975V*/
595 pmic_reg_read(p, PFUZE100_SW2STBY, &value);
596 value &= ~0x3f;
597 value |= 0x17;
598 pmic_reg_write(p, PFUZE100_SW2STBY, value);
599 }
Peng Fane5bcd4d2015-01-27 10:14:04 +0800600
Peng Fand4947e32015-07-11 11:38:47 +0800601 return pfuze_mode_init(p, APS_PFM);
Ye.Licfaa23b2014-11-06 16:29:02 +0800602}
603
Otavio Salvador52863372013-03-16 08:05:07 +0000604#ifdef CONFIG_CMD_BMODE
605static const struct boot_mode board_boot_modes[] = {
606 /* 4 bit bus width */
607 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
608 {NULL, 0},
609};
610#endif
611
612int board_late_init(void)
613{
614#ifdef CONFIG_CMD_BMODE
615 add_board_boot_modes(board_boot_modes);
616#endif
617
Peng Fan04321fc2015-07-11 11:38:46 +0800618#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
619 setenv("board_name", "SABREAUTO");
620
Peng Fand4947e32015-07-11 11:38:47 +0800621 if (is_mx6dqp())
622 setenv("board_rev", "MX6QP");
Peng Fan4a597d02016-05-23 18:36:06 +0800623 else if (is_mx6dq())
Peng Fan04321fc2015-07-11 11:38:46 +0800624 setenv("board_rev", "MX6Q");
Peng Fan4a597d02016-05-23 18:36:06 +0800625 else if (is_mx6sdl())
Peng Fan04321fc2015-07-11 11:38:46 +0800626 setenv("board_rev", "MX6DL");
627#endif
628
Otavio Salvador52863372013-03-16 08:05:07 +0000629 return 0;
630}
631
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000632int checkboard(void)
633{
Fabio Estevam96ad33d2012-10-02 11:20:12 +0000634 int rev = mx6sabre_rev();
635 char *revname;
636
637 switch (rev) {
638 case BOARD_REV_B:
639 revname = "B";
640 break;
641 case BOARD_REV_A:
642 default:
643 revname = "A";
644 break;
645 }
646
647 printf("Board: MX6Q-Sabreauto rev%s\n", revname);
Fabio Estevamafe20bf2012-09-24 08:09:33 +0000648
649 return 0;
650}
Ye.Li700020e2014-10-30 18:53:49 +0800651
652#ifdef CONFIG_USB_EHCI_MX6
653#define USB_HOST1_PWR PORTEXP_IO_NR(0x32, 7)
654#define USB_OTG_PWR PORTEXP_IO_NR(0x34, 1)
655
656iomux_v3_cfg_t const usb_otg_pads[] = {
657 MX6_PAD_ENET_RX_ER__USB_OTG_ID | MUX_PAD_CTRL(NO_PAD_CTRL),
658};
659
660int board_ehci_hcd_init(int port)
661{
662 switch (port) {
663 case 0:
664 imx_iomux_v3_setup_multiple_pads(usb_otg_pads,
665 ARRAY_SIZE(usb_otg_pads));
666
667 /*
668 * Set daisy chain for otg_pin_id on 6q.
669 * For 6dl, this bit is reserved.
670 */
671 imx_iomux_set_gpr_register(1, 13, 1, 0);
672 break;
673 case 1:
674 break;
675 default:
676 printf("MXC USB port %d not yet supported\n", port);
677 return -EINVAL;
678 }
679 return 0;
680}
681
682int board_ehci_power(int port, int on)
683{
684 switch (port) {
685 case 0:
686 if (on)
687 port_exp_direction_output(USB_OTG_PWR, 1);
688 else
689 port_exp_direction_output(USB_OTG_PWR, 0);
690 break;
691 case 1:
692 if (on)
693 port_exp_direction_output(USB_HOST1_PWR, 1);
694 else
695 port_exp_direction_output(USB_HOST1_PWR, 0);
696 break;
697 default:
698 printf("MXC USB port %d not yet supported\n", port);
699 return -EINVAL;
700 }
701
702 return 0;
703}
704#endif