blob: f1d5cc6655236841bc6c749bcbbe9f509d7c23d8 [file] [log] [blame]
Stefan Agner7b852342018-05-30 19:01:48 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Toradex AG
4 */
5#include <common.h>
6#include <asm/arch/clock.h>
7#include <asm/arch/crm_regs.h>
8#include <asm/arch/imx-regs.h>
9#include <asm/arch-mx6/clock.h>
10#include <asm/arch-mx6/imx-regs.h>
11#include <asm/arch-mx6/mx6ull_pins.h>
12#include <asm/arch/sys_proto.h>
13#include <asm/gpio.h>
14#include <asm/mach-imx/boot_mode.h>
15#include <asm/mach-imx/iomux-v3.h>
16#include <asm/io.h>
17#include <common.h>
18#include <dm.h>
19#include <dm/platform_data/serial_mxc.h>
20#include <fdt_support.h>
21#include <fsl_esdhc.h>
22#include <imx_thermal.h>
23#include <jffs2/load_kernel.h>
24#include <linux/sizes.h>
25#include <mmc.h>
26#include <miiphy.h>
27#include <mtd_node.h>
28#include <netdev.h>
29#include <usb.h>
30#include <usb/ehci-ci.h>
31#include "../common/tdx-common.h"
Stefan Agnerbf1f2892019-04-09 17:24:09 +020032#include "../common/tdx-cfg-block.h"
Stefan Agner7b852342018-05-30 19:01:48 +020033
34DECLARE_GLOBAL_DATA_PTR;
35
36#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
37 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
38 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
39
40#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
41 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_40ohm | \
42 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
43
44#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
45 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
46#define ENET_PAD_CTRL_MII (PAD_CTL_DSE_40ohm)
47
48#define ENET_RX_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_DSE_48ohm)
49
50#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \
51 PAD_CTL_DSE_48ohm)
52
Philippe Schenkerde51f532019-04-09 17:24:12 +020053#define MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR 0x2290040
54
Stefan Agner7b852342018-05-30 19:01:48 +020055#define NAND_PAD_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
56
57#define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_PUS_22K_UP)
58
59#define USB_CDET_GPIO IMX_GPIO_NR(7, 14)
60
61int dram_init(void)
62{
63 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
64
65 return 0;
66}
67
68static iomux_v3_cfg_t const uart1_pads[] = {
69 MX6_PAD_UART1_TX_DATA__UART1_DTE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
70 MX6_PAD_UART1_RX_DATA__UART1_DTE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
71 MX6_PAD_UART1_RTS_B__UART1_DTE_CTS | MUX_PAD_CTRL(UART_PAD_CTRL),
72 MX6_PAD_UART1_CTS_B__UART1_DTE_RTS | MUX_PAD_CTRL(UART_PAD_CTRL),
73};
74
75#ifdef CONFIG_FSL_ESDHC
76static iomux_v3_cfg_t const usdhc1_pads[] = {
77 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
78 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
79 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
80 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
81 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
82 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
83
84 MX6_PAD_SNVS_TAMPER0__GPIO5_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL),
85};
86#endif
87
88static iomux_v3_cfg_t const usb_cdet_pads[] = {
89 MX6_PAD_SNVS_TAMPER2__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
90};
91
92#ifdef CONFIG_NAND_MXS
93static iomux_v3_cfg_t const gpmi_pads[] = {
94 MX6_PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(NAND_PAD_CTRL),
95 MX6_PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(NAND_PAD_CTRL),
96 MX6_PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(NAND_PAD_CTRL),
97 MX6_PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(NAND_PAD_CTRL),
98 MX6_PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(NAND_PAD_CTRL),
99 MX6_PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(NAND_PAD_CTRL),
100 MX6_PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(NAND_PAD_CTRL),
101 MX6_PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(NAND_PAD_CTRL),
102 MX6_PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(NAND_PAD_CTRL),
103 MX6_PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(NAND_PAD_CTRL),
104 MX6_PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
105 MX6_PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
106 MX6_PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
107 MX6_PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(NAND_PAD_READY0_CTRL),
108};
109
110static void setup_gpmi_nand(void)
111{
112 imx_iomux_v3_setup_multiple_pads(gpmi_pads, ARRAY_SIZE(gpmi_pads));
113
114 setup_gpmi_io_clk((3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
115 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
116}
117#endif
118
119#ifdef CONFIG_VIDEO_MXS
120static iomux_v3_cfg_t const lcd_pads[] = {
121 MX6_PAD_LCD_CLK__LCDIF_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
122 MX6_PAD_LCD_ENABLE__LCDIF_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL),
123 MX6_PAD_LCD_HSYNC__LCDIF_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
124 MX6_PAD_LCD_CLK__LCDIF_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
125 MX6_PAD_LCD_DATA00__LCDIF_DATA00 | MUX_PAD_CTRL(LCD_PAD_CTRL),
126 MX6_PAD_LCD_DATA01__LCDIF_DATA01 | MUX_PAD_CTRL(LCD_PAD_CTRL),
127 MX6_PAD_LCD_DATA02__LCDIF_DATA02 | MUX_PAD_CTRL(LCD_PAD_CTRL),
128 MX6_PAD_LCD_DATA03__LCDIF_DATA03 | MUX_PAD_CTRL(LCD_PAD_CTRL),
129 MX6_PAD_LCD_DATA04__LCDIF_DATA04 | MUX_PAD_CTRL(LCD_PAD_CTRL),
130 MX6_PAD_LCD_DATA05__LCDIF_DATA05 | MUX_PAD_CTRL(LCD_PAD_CTRL),
131 MX6_PAD_LCD_DATA06__LCDIF_DATA06 | MUX_PAD_CTRL(LCD_PAD_CTRL),
132 MX6_PAD_LCD_DATA07__LCDIF_DATA07 | MUX_PAD_CTRL(LCD_PAD_CTRL),
133 MX6_PAD_LCD_DATA08__LCDIF_DATA08 | MUX_PAD_CTRL(LCD_PAD_CTRL),
134 MX6_PAD_LCD_DATA09__LCDIF_DATA09 | MUX_PAD_CTRL(LCD_PAD_CTRL),
135 MX6_PAD_LCD_DATA10__LCDIF_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
136 MX6_PAD_LCD_DATA11__LCDIF_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
137 MX6_PAD_LCD_DATA12__LCDIF_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
138 MX6_PAD_LCD_DATA13__LCDIF_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
139 MX6_PAD_LCD_DATA14__LCDIF_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
140 MX6_PAD_LCD_DATA15__LCDIF_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
141 MX6_PAD_LCD_DATA16__LCDIF_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
142 MX6_PAD_LCD_DATA17__LCDIF_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
143};
144
145static iomux_v3_cfg_t const backlight_pads[] = {
146 /* Backlight On */
147 MX6_PAD_JTAG_TMS__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
148 /* Backlight PWM<A> (multiplexed pin) */
149 MX6_PAD_NAND_WP_B__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
150};
151
152#define GPIO_BL_ON IMX_GPIO_NR(1, 11)
153#define GPIO_PWM_A IMX_GPIO_NR(4, 11)
154
155static int setup_lcd(void)
156{
157 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
158
159 imx_iomux_v3_setup_multiple_pads(backlight_pads, ARRAY_SIZE(backlight_pads));
160
161 /* Set BL_ON */
162 gpio_request(GPIO_BL_ON, "BL_ON");
163 gpio_direction_output(GPIO_BL_ON, 1);
164
165 /* Set PWM<A> to full brightness (assuming inversed polarity) */
166 gpio_request(GPIO_PWM_A, "PWM<A>");
167 gpio_direction_output(GPIO_PWM_A, 0);
168
169 return 0;
170}
171#endif
172
173#ifdef CONFIG_FEC_MXC
174static iomux_v3_cfg_t const fec2_pads[] = {
175 MX6_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 | MUX_PAD_CTRL(ENET_PAD_CTRL) | MUX_MODE_SION,
176 MX6_PAD_GPIO1_IO06__ENET2_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
177 MX6_PAD_GPIO1_IO07__ENET2_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
178 MX6_PAD_ENET2_RX_DATA0__ENET2_RDATA00 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
179 MX6_PAD_ENET2_RX_DATA1__ENET2_RDATA01 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
180 MX6_PAD_ENET2_RX_ER__ENET2_RX_ER | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
181 MX6_PAD_ENET2_RX_EN__ENET2_RX_EN | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
182 MX6_PAD_ENET2_TX_DATA0__ENET2_TDATA00 | MUX_PAD_CTRL(ENET_PAD_CTRL),
183 MX6_PAD_ENET2_TX_DATA1__ENET2_TDATA01 | MUX_PAD_CTRL(ENET_PAD_CTRL),
184 MX6_PAD_ENET2_TX_EN__ENET2_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
185};
186
187static void setup_iomux_fec(void)
188{
189 imx_iomux_v3_setup_multiple_pads(fec2_pads, ARRAY_SIZE(fec2_pads));
190}
191#endif
192
193static void setup_iomux_uart(void)
194{
195 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
196}
197
198#ifdef CONFIG_FSL_ESDHC
199
200#define USDHC1_CD_GPIO IMX_GPIO_NR(5, 0)
201
202static struct fsl_esdhc_cfg usdhc_cfg[] = {
203 {USDHC1_BASE_ADDR, 0, 4},
204};
205
206int board_mmc_getcd(struct mmc *mmc)
207{
208 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
209 int ret = 0;
210
211 switch (cfg->esdhc_base) {
212 case USDHC1_BASE_ADDR:
213 ret = !gpio_get_value(USDHC1_CD_GPIO);
214 break;
215 }
216
217 return ret;
218}
219
220int board_mmc_init(bd_t *bis)
221{
222 int i, ret;
223
224 /* USDHC1 is mmc0 */
225 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
226 switch (i) {
227 case 0:
228 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
229 ARRAY_SIZE(usdhc1_pads));
230 gpio_request(USDHC1_CD_GPIO, "usdhc1_cd");
231 gpio_direction_input(USDHC1_CD_GPIO);
232 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
233 break;
234 default:
235 printf("Warning: you configured more USDHC controllers"
236 "(%d) than supported by the board\n", i + 1);
237 return -EINVAL;
238 }
239
240 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
241 if (ret)
242 return ret;
243 }
244
245 return 0;
246}
247#endif
248
249#ifdef CONFIG_FEC_MXC
250
251static int setup_fec(void)
252{
253 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
254 int ret;
255
256 setup_iomux_fec();
257
258 /* provide the PHY clock from the i.MX 6 */
259 ret = enable_fec_anatop_clock(1, ENET_50MHZ);
260 if (ret)
261 return ret;
262
263 /* Use 50M anatop REF_CLK and output it on the ENET2_TX_CLK */
264 clrsetbits_le32(&iomuxc_regs->gpr[1],
265 IOMUX_GPR1_FEC2_CLOCK_MUX2_SEL_MASK,
266 IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK);
267
Marcel Ziswiler561d1372019-04-09 17:24:11 +0200268 /* give new Ethernet PHY power save mode circuitry time to settle */
269 mdelay(300);
270
Stefan Agner7b852342018-05-30 19:01:48 +0200271 return 0;
272}
273
274int board_phy_config(struct phy_device *phydev)
275{
276 if (phydev->drv->config)
277 phydev->drv->config(phydev);
278 return 0;
279}
280#endif
281
282int board_early_init_f(void)
283{
284 setup_iomux_uart();
285
286 return 0;
287}
288
289int board_init(void)
290{
291 /* address of boot parameters */
292 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
293
294#ifdef CONFIG_FEC_MXC
295 setup_fec();
296#endif
297
298#ifdef CONFIG_NAND_MXS
299 setup_gpmi_nand();
300#endif
301
302#ifdef CONFIG_VIDEO_MXS
303 setup_lcd();
304#endif
305
306#ifdef CONFIG_USB_EHCI_MX6
307 imx_iomux_v3_setup_multiple_pads(usb_cdet_pads, ARRAY_SIZE(usb_cdet_pads));
308 gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
309#endif
310
311 return 0;
312}
313
314#ifdef CONFIG_CMD_BMODE
315/* TODO */
316static const struct boot_mode board_boot_modes[] = {
317 /* 4 bit bus width */
318 {"nand", MAKE_CFGVAL(0x40, 0x34, 0x00, 0x00)},
319 {"sd1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
320 {NULL, 0},
321};
322#endif
323
324int board_late_init(void)
325{
Stefan Agnerbf1f2892019-04-09 17:24:09 +0200326#ifdef CONFIG_TDX_CFG_BLOCK
327 /*
328 * If we have a valid config block and it says we are a module with
329 * Wi-Fi/Bluetooth make sure we use the -wifi device tree.
330 */
331 if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
332 tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT)
Stefan Agner7b852342018-05-30 19:01:48 +0200333 env_set("variant", "-wifi");
Stefan Agnerbf1f2892019-04-09 17:24:09 +0200334#endif
Stefan Agner7b852342018-05-30 19:01:48 +0200335
Philippe Schenkerde51f532019-04-09 17:24:12 +0200336 /*
337 * Disable output driver of PAD CCM_PMIC_STBY_REQ. This prevents the
338 * SOC to request for a lower voltage during sleep. This is necessary
339 * because the voltage is changing too slow for the SOC to wake up
340 * properly.
341 */
342 __raw_writel(0x8080, MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR);
343
Stefan Agner7b852342018-05-30 19:01:48 +0200344#ifdef CONFIG_CMD_BMODE
345 add_board_boot_modes(board_boot_modes);
346#endif
347
348#ifdef CONFIG_CMD_USB_SDP
349 if (is_boot_from_usb()) {
350 printf("Serial Downloader recovery mode, using sdp command\n");
351 env_set("bootdelay", "0");
352 env_set("bootcmd", "sdp 0");
353 }
354#endif /* CONFIG_CMD_USB_SDP */
355
356 return 0;
357}
358
359int checkboard(void)
360{
361 printf("Model: Toradex Colibri iMX6ULL\n");
362
363 return 0;
364}
365
366#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
367int ft_board_setup(void *blob, bd_t *bd)
368{
369#if defined(CONFIG_FDT_FIXUP_PARTITIONS)
370 static struct node_info nodes[] = {
371 { "fsl,imx6ull-gpmi-nand", MTD_DEV_TYPE_NAND, },
372 { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, },
373 };
374
375 /* Update partition nodes using info from mtdparts env var */
376 puts(" Updating MTD partitions...\n");
377 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
378#endif
379
380 return ft_common_board_setup(blob, bd);
381}
382#endif
383
384#ifdef CONFIG_USB_EHCI_MX6
385static iomux_v3_cfg_t const usb_otg2_pads[] = {
386 MX6_PAD_GPIO1_IO02__GPIO1_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
387};
388
389int board_ehci_hcd_init(int port)
390{
391 switch (port) {
392 case 0:
393 break;
394 case 1:
395 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
396 ARRAY_SIZE(usb_otg2_pads));
397 break;
398 default:
399 return -EINVAL;
400 }
401 return 0;
402}
403
404int board_usb_phy_mode(int port)
405{
406 switch (port) {
407 case 0:
408 if (gpio_get_value(USB_CDET_GPIO))
409 return USB_INIT_DEVICE;
410 else
411 return USB_INIT_HOST;
412 case 1:
413 default:
414 return USB_INIT_HOST;
415 }
416}
417#endif
418
419static struct mxc_serial_platdata mxc_serial_plat = {
420 .reg = (struct mxc_uart *)UART1_BASE,
421 .use_dte = 1,
422};
423
424U_BOOT_DEVICE(mxc_serial) = {
425 .name = "serial_mxc",
426 .platdata = &mxc_serial_plat,
427};