blob: 873b354db80404b2c6f94446876fa0b058678a37 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherf853c6c2014-07-18 06:07:22 +02002/*
3 * (C) Copyright 2014
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 *
6 * Based on:
7 * Copyright (C) 2012 Freescale Semiconductor, Inc.
8 *
9 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020010 */
11
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>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020017#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/mxc_i2c.h>
21#include <asm/mach-imx/video.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020022#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020024#include <miiphy.h>
25#include <netdev.h>
26#include <asm/arch/mxc_hdmi.h>
27#include <asm/arch/crm_regs.h>
28#include <linux/fb.h>
29#include <ipu_pixfmt.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030030#include <input.h>
Heiko Schocherf853c6c2014-07-18 06:07:22 +020031#include <asm/io.h>
32#include <asm/arch/sys_proto.h>
33#include <pwm.h>
34
35DECLARE_GLOBAL_DATA_PTR;
36
37#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)
40
41#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)
44
45#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
46 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
47
48#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
49 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
50
51#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
52 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
53 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
54
55#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
56
57#define DISP_PAD_CTRL (0x10)
58
59#define ECSPI4_CS1 IMX_GPIO_NR(5, 2)
60
Heiko Schocher50196992019-12-01 11:23:04 +010061#if ((CONFIG_SYS_BOARD_VERSION == 2) || (CONFIG_SYS_BOARD_VERSION == 3))
Heiko Schocher05729822015-05-18 13:32:31 +020062#include "./aristainetos-v2.c"
63#endif
64
65
Heiko Schocherf853c6c2014-07-18 06:07:22 +020066struct i2c_pads_info i2c_pad_info1 = {
67 .scl = {
68 .i2c_mode = MX6_PAD_CSI0_DAT9__I2C1_SCL | PC,
69 .gpio_mode = MX6_PAD_CSI0_DAT9__GPIO5_IO27 | PC,
70 .gp = IMX_GPIO_NR(5, 27)
71 },
72 .sda = {
73 .i2c_mode = MX6_PAD_CSI0_DAT8__I2C1_SDA | PC,
74 .gpio_mode = MX6_PAD_CSI0_DAT8__GPIO5_IO26 | PC,
75 .gp = IMX_GPIO_NR(5, 26)
76 }
77};
78
79struct i2c_pads_info i2c_pad_info2 = {
80 .scl = {
81 .i2c_mode = MX6_PAD_KEY_COL3__I2C2_SCL | PC,
82 .gpio_mode = MX6_PAD_KEY_COL3__GPIO4_IO12 | PC,
83 .gp = IMX_GPIO_NR(4, 12)
84 },
85 .sda = {
86 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC,
87 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO4_IO13 | PC,
88 .gp = IMX_GPIO_NR(4, 13)
89 }
90};
91
Heiko Schocherf853c6c2014-07-18 06:07:22 +020092iomux_v3_cfg_t const usdhc1_pads[] = {
93 MX6_PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97 MX6_PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
98 MX6_PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
99};
100
Heiko Schocher05729822015-05-18 13:32:31 +0200101int dram_init(void)
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200102{
Fabio Estevam1b23fe52016-07-23 13:23:39 -0300103 gd->ram_size = imx_ddr_size();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200104
Heiko Schocher05729822015-05-18 13:32:31 +0200105 return 0;
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200106}
107
Yangbo Lu73340382019-06-21 11:42:28 +0800108#ifdef CONFIG_FSL_ESDHC_IMX
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200109struct fsl_esdhc_cfg usdhc_cfg[2] = {
110 {USDHC1_BASE_ADDR},
111 {USDHC2_BASE_ADDR},
112};
113
114int board_mmc_getcd(struct mmc *mmc)
115{
116 return 1;
117}
118
119int board_mmc_init(bd_t *bis)
120{
121 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200122 imx_iomux_v3_setup_multiple_pads(usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
Heiko Schocher05729822015-05-18 13:32:31 +0200123#if (CONFIG_SYS_BOARD_VERSION == 2)
124 /*
125 * usdhc2 has a levelshifter on the carrier board Rev. DV1,
126 * that will automatically detect the driving direction.
127 * During initialisation this isn't working correctly,
128 * which causes DAT3 to be driven low towards the SD-card.
129 * This causes a SD-card enetring the SPI-Mode
130 * and therefore getting inaccessible until next power cycle.
131 * As workaround we drive the DAT3 line as GPIO and set it high.
132 * This makes usdhc2 unusable in u-boot, but works for the
133 * initialisation in Linux
134 */
135 imx_iomux_v3_setup_pad(MX6_PAD_SD2_DAT3__GPIO1_IO12 |
136 MUX_PAD_CTRL(NO_PAD_CTRL));
137 gpio_direction_output(IMX_GPIO_NR(1, 12) , 1);
138#endif
139 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200140}
141#endif
142
143/*
144 * Do not overwrite the console
145 * Use always serial for U-Boot console
146 */
147int overwrite_console(void)
148{
149 return 1;
150}
151
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200152struct display_info_t const displays[] = {
153 {
154 .bus = -1,
155 .addr = 0,
156 .pixfmt = IPU_PIX_FMT_RGB24,
157 .detect = NULL,
158 .enable = enable_lvds,
159 .mode = {
160 .name = "lb07wv8",
161 .refresh = 60,
162 .xres = 800,
163 .yres = 480,
Heiko Schocher27813292015-08-11 08:09:44 +0200164 .pixclock = 30066,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200165 .left_margin = 88,
166 .right_margin = 88,
Heiko Schocher27813292015-08-11 08:09:44 +0200167 .upper_margin = 20,
168 .lower_margin = 20,
Heiko Schocher69f0e442015-01-20 10:06:18 +0100169 .hsync_len = 80,
Heiko Schocher27813292015-08-11 08:09:44 +0200170 .vsync_len = 5,
171 .sync = FB_SYNC_EXT,
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200172 .vmode = FB_VMODE_NONINTERLACED
173 }
174 }
Heiko Schocher8fb9f3f2015-08-24 11:36:40 +0200175#if ((CONFIG_SYS_BOARD_VERSION == 2) || (CONFIG_SYS_BOARD_VERSION == 3))
Heiko Schocher05729822015-05-18 13:32:31 +0200176 , {
177 .bus = -1,
178 .addr = 0,
179 .pixfmt = IPU_PIX_FMT_RGB24,
180 .detect = NULL,
181 .enable = enable_spi_display,
182 .mode = {
183 .name = "lg4573",
Heiko Schocher27813292015-08-11 08:09:44 +0200184 .refresh = 57,
Heiko Schocher05729822015-05-18 13:32:31 +0200185 .xres = 480,
186 .yres = 800,
187 .pixclock = 37037,
188 .left_margin = 59,
189 .right_margin = 10,
190 .upper_margin = 15,
191 .lower_margin = 15,
192 .hsync_len = 10,
193 .vsync_len = 15,
194 .sync = FB_SYNC_EXT | FB_SYNC_HOR_HIGH_ACT |
195 FB_SYNC_VERT_HIGH_ACT,
196 .vmode = FB_VMODE_NONINTERLACED
197 }
198 }
199#endif
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200200};
201size_t display_count = ARRAY_SIZE(displays);
202
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200203/* no console on this board */
204int board_cfb_skip(void)
205{
206 return 1;
207}
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200208
209iomux_v3_cfg_t nfc_pads[] = {
210 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
211 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
212 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL),
213 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL),
214 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200215 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
216 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
217 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL),
218 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL),
219 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL),
220 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL),
221 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL),
222 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL),
223 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL),
224 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL),
225 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
226};
227
228static void setup_gpmi_nand(void)
229{
230 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
231
232 /* config gpmi nand iomux */
233 imx_iomux_v3_setup_multiple_pads(nfc_pads,
234 ARRAY_SIZE(nfc_pads));
235
Heiko Schocher05729822015-05-18 13:32:31 +0200236 /* gate ENFC_CLK_ROOT clock first,before clk source switch */
237 clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
238
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200239 /* config gpmi and bch clock to 100 MHz */
240 clrsetbits_le32(&mxc_ccm->cs2cdr,
241 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
242 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
243 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
244 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
245 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
246 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
247
Heiko Schocher05729822015-05-18 13:32:31 +0200248 /* enable ENFC_CLK_ROOT clock */
249 setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
250
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200251 /* enable gpmi and bch clock gating */
252 setbits_le32(&mxc_ccm->CCGR4,
253 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
254 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
255 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
256 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
257 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
258
259 /* enable apbh clock gating */
260 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
261}
262
263int board_init(void)
264{
265 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
266
267 /* address of boot parameters */
268 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
269
270 setup_spi();
271
272 setup_i2c(0, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE,
273 &i2c_pad_info1);
274 setup_i2c(1, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE,
275 &i2c_pad_info2);
276 setup_i2c(2, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE,
277 &i2c_pad_info3);
Heiko Schocher05729822015-05-18 13:32:31 +0200278 setup_i2c4();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200279
280 /* SPI NOR Flash read only */
281 gpio_request(CONFIG_GPIO_ENABLE_SPI_FLASH, "ena_spi_nor");
282 gpio_direction_output(CONFIG_GPIO_ENABLE_SPI_FLASH, 0);
283 gpio_free(CONFIG_GPIO_ENABLE_SPI_FLASH);
284
Heiko Schocher05729822015-05-18 13:32:31 +0200285 setup_board_gpio();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200286 setup_gpmi_nand();
Heiko Schocher05729822015-05-18 13:32:31 +0200287 setup_board_spi();
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200288
289 /* GPIO_1 for USB_OTG_ID */
Heiko Schocher05729822015-05-18 13:32:31 +0200290 clrsetbits_le32(&iomux->gpr[1], IOMUXC_GPR1_USB_OTG_ID_SEL_MASK, 0);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200291 imx_iomux_v3_setup_multiple_pads(misc_pads, ARRAY_SIZE(misc_pads));
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200292 return 0;
293}
294
295int checkboard(void)
296{
Heiko Schocher05729822015-05-18 13:32:31 +0200297 printf("Board: %s\n", CONFIG_BOARDNAME);
Heiko Schocherf853c6c2014-07-18 06:07:22 +0200298 return 0;
299}
300
301#ifdef CONFIG_USB_EHCI_MX6
302int board_ehci_hcd_init(int port)
303{
304 int ret;
305
306 ret = gpio_request(ARISTAINETOS_USB_H1_PWR, "usb-h1-pwr");
307 if (!ret)
308 gpio_direction_output(ARISTAINETOS_USB_H1_PWR, 1);
309 ret = gpio_request(ARISTAINETOS_USB_OTG_PWR, "usb-OTG-pwr");
310 if (!ret)
311 gpio_direction_output(ARISTAINETOS_USB_OTG_PWR, 1);
312 return 0;
313}
314
315int board_ehci_power(int port, int on)
316{
317 if (port)
318 gpio_set_value(ARISTAINETOS_USB_OTG_PWR, on);
319 else
320 gpio_set_value(ARISTAINETOS_USB_H1_PWR, on);
321 return 0;
322}
323#endif