blob: b558a596dff8a9c225c1eb0d0b67d90a73dc4930 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam77e62892012-09-13 03:18:20 +00002/*
3 * Copyright (C) 2012 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevam77e62892012-09-13 03:18:20 +00006 */
7
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Fabio Estevam77e62892012-09-13 03:18:20 +000011#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
Pierre Aubertec10aed2013-06-04 09:00:15 +020014#include <asm/arch/mx6-pins.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Diego Dorta5433ebb2017-09-27 13:12:38 -030016#include <asm/mach-imx/spi.h>
Shiji Yangbb112342023-08-03 09:47:16 +080017#include <asm/sections.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060018#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Fabio Estevam77e62892012-09-13 03:18:20 +000020#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/iomux-v3.h>
22#include <asm/mach-imx/boot_mode.h>
23#include <asm/mach-imx/video.h>
Fabio Estevam77e62892012-09-13 03:18:20 +000024#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080025#include <fsl_esdhc_imx.h>
Fabio Estevam77e62892012-09-13 03:18:20 +000026#include <miiphy.h>
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -050027#include <asm/arch/mxc_hdmi.h>
28#include <asm/arch/crm_regs.h>
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -050029#include <asm/io.h>
30#include <asm/arch/sys_proto.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030031#include <input.h>
Fabio Estevamba92ad62014-05-09 13:15:42 -030032#include <power/pmic.h>
33#include <power/pfuze100_pmic.h>
Ye.Li75e02f92014-11-06 16:29:00 +080034#include "../common/pfuze.h"
Peng Fanc9498fa2014-12-02 09:55:27 +080035#include <usb.h>
Diego Dortade4c6612017-09-27 13:12:40 -030036#include <usb/ehci-ci.h>
John Tobias07491552014-11-12 14:27:45 -080037
Fabio Estevam77e62892012-09-13 03:18:20 +000038DECLARE_GLOBAL_DATA_PTR;
39
Benoît Thébaudeau21670242013-04-26 01:34:47 +000040#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
41 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
42 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam77e62892012-09-13 03:18:20 +000043
Benoît Thébaudeau21670242013-04-26 01:34:47 +000044#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
45 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
46 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam77e62892012-09-13 03:18:20 +000047
Fabio Estevamd82dad42013-11-08 16:20:54 -020048#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
49 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
50
Fabio Estevam0d29cee2014-10-21 21:14:53 -020051#define DISP0_PWR_EN IMX_GPIO_NR(1, 21)
52
Diego Dorta466016e2016-10-11 11:09:27 -030053#define KEY_VOL_UP IMX_GPIO_NR(1, 4)
54
Fabio Estevam77e62892012-09-13 03:18:20 +000055int dram_init(void)
56{
John Tobias07491552014-11-12 14:27:45 -080057 gd->ram_size = imx_ddr_size();
Fabio Estevam77e62892012-09-13 03:18:20 +000058 return 0;
59}
60
Fabio Estevamf533c2e2014-11-06 12:24:25 -020061static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -030062 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
63 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevam77e62892012-09-13 03:18:20 +000064};
65
Fabio Estevamf533c2e2014-11-06 12:24:25 -020066static iomux_v3_cfg_t const usdhc2_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -030067 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
68 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
69 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
70 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
71 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
72 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
73 IOMUX_PADS(PAD_NANDF_D4__SD2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
74 IOMUX_PADS(PAD_NANDF_D5__SD2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
75 IOMUX_PADS(PAD_NANDF_D6__SD2_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
76 IOMUX_PADS(PAD_NANDF_D7__SD2_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
77 IOMUX_PADS(PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* CD */
Shawn Guo7e5e8332012-12-30 14:14:59 +000078};
79
Fabio Estevamf533c2e2014-11-06 12:24:25 -020080static iomux_v3_cfg_t const usdhc3_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -030081 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
82 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
83 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
84 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
85 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
86 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
87 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
88 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
89 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
90 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
91 IOMUX_PADS(PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* CD */
Fabio Estevam77e62892012-09-13 03:18:20 +000092};
93
Fabio Estevamf533c2e2014-11-06 12:24:25 -020094static iomux_v3_cfg_t const usdhc4_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -030095 IOMUX_PADS(PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
96 IOMUX_PADS(PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
97 IOMUX_PADS(PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
98 IOMUX_PADS(PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
99 IOMUX_PADS(PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
100 IOMUX_PADS(PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
101 IOMUX_PADS(PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
102 IOMUX_PADS(PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
103 IOMUX_PADS(PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
104 IOMUX_PADS(PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Shawn Guo7e5e8332012-12-30 14:14:59 +0000105};
106
Fabio Estevamf533c2e2014-11-06 12:24:25 -0200107static iomux_v3_cfg_t const ecspi1_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -0300108 IOMUX_PADS(PAD_KEY_COL0__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
109 IOMUX_PADS(PAD_KEY_COL1__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
110 IOMUX_PADS(PAD_KEY_ROW0__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
111 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevamd82dad42013-11-08 16:20:54 -0200112};
113
Fabio Estevam0d29cee2014-10-21 21:14:53 -0200114static iomux_v3_cfg_t const rgb_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -0300115 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK | MUX_PAD_CTRL(NO_PAD_CTRL)),
116 IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15 | MUX_PAD_CTRL(NO_PAD_CTRL)),
117 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
118 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
119 IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
120 IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
121 IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
122 IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
123 IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
124 IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
125 IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
126 IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
127 IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
128 IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08 | MUX_PAD_CTRL(NO_PAD_CTRL)),
129 IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09 | MUX_PAD_CTRL(NO_PAD_CTRL)),
130 IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10 | MUX_PAD_CTRL(NO_PAD_CTRL)),
131 IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11 | MUX_PAD_CTRL(NO_PAD_CTRL)),
132 IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12 | MUX_PAD_CTRL(NO_PAD_CTRL)),
133 IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13 | MUX_PAD_CTRL(NO_PAD_CTRL)),
134 IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14 | MUX_PAD_CTRL(NO_PAD_CTRL)),
135 IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15 | MUX_PAD_CTRL(NO_PAD_CTRL)),
136 IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16 | MUX_PAD_CTRL(NO_PAD_CTRL)),
137 IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17 | MUX_PAD_CTRL(NO_PAD_CTRL)),
138 IOMUX_PADS(PAD_DISP0_DAT18__IPU1_DISP0_DATA18 | MUX_PAD_CTRL(NO_PAD_CTRL)),
139 IOMUX_PADS(PAD_DISP0_DAT19__IPU1_DISP0_DATA19 | MUX_PAD_CTRL(NO_PAD_CTRL)),
140 IOMUX_PADS(PAD_DISP0_DAT20__IPU1_DISP0_DATA20 | MUX_PAD_CTRL(NO_PAD_CTRL)),
141 IOMUX_PADS(PAD_DISP0_DAT21__IPU1_DISP0_DATA21 | MUX_PAD_CTRL(NO_PAD_CTRL)),
142 IOMUX_PADS(PAD_DISP0_DAT22__IPU1_DISP0_DATA22 | MUX_PAD_CTRL(NO_PAD_CTRL)),
143 IOMUX_PADS(PAD_DISP0_DAT23__IPU1_DISP0_DATA23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Marco Franchi029d07f2016-06-08 15:05:31 -0300144};
145
146static iomux_v3_cfg_t const bl_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -0300147 IOMUX_PADS(PAD_SD1_DAT3__GPIO1_IO21 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevam0d29cee2014-10-21 21:14:53 -0200148};
149
Marco Franchi029d07f2016-06-08 15:05:31 -0300150static void enable_backlight(void)
151{
Fabio Estevamc88f1672017-05-12 12:45:23 -0300152 SETUP_IOMUX_PADS(bl_pads);
Abel Vesa78d974e2019-02-01 16:40:19 +0000153 gpio_request(DISP0_PWR_EN, "Display Power Enable");
Marco Franchi029d07f2016-06-08 15:05:31 -0300154 gpio_direction_output(DISP0_PWR_EN, 1);
155}
156
Fabio Estevam0d29cee2014-10-21 21:14:53 -0200157static void enable_rgb(struct display_info_t const *dev)
158{
Fabio Estevamc88f1672017-05-12 12:45:23 -0300159 SETUP_IOMUX_PADS(rgb_pads);
Marco Franchi029d07f2016-06-08 15:05:31 -0300160 enable_backlight();
161}
162
163static void enable_lvds(struct display_info_t const *dev)
164{
165 enable_backlight();
Fabio Estevam0d29cee2014-10-21 21:14:53 -0200166}
167
Fabio Estevamd82dad42013-11-08 16:20:54 -0200168static void setup_spi(void)
169{
Fabio Estevamc88f1672017-05-12 12:45:23 -0300170 SETUP_IOMUX_PADS(ecspi1_pads);
Fabio Estevamd82dad42013-11-08 16:20:54 -0200171}
172
Fabio Estevamdee3c842013-12-04 01:08:16 -0200173iomux_v3_cfg_t const di0_pads[] = {
Fabio Estevamc88f1672017-05-12 12:45:23 -0300174 IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK), /* DISP0_CLK */
175 IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* DISP0_HSYNC */
176 IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* DISP0_VSYNC */
Fabio Estevamdee3c842013-12-04 01:08:16 -0200177};
178
Fabio Estevam77e62892012-09-13 03:18:20 +0000179static void setup_iomux_uart(void)
180{
Fabio Estevamc88f1672017-05-12 12:45:23 -0300181 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevam77e62892012-09-13 03:18:20 +0000182}
183
Yangbo Lu73340382019-06-21 11:42:28 +0800184#ifdef CONFIG_FSL_ESDHC_IMX
Shawn Guo7e5e8332012-12-30 14:14:59 +0000185struct fsl_esdhc_cfg usdhc_cfg[3] = {
186 {USDHC2_BASE_ADDR},
Fabio Estevam77e62892012-09-13 03:18:20 +0000187 {USDHC3_BASE_ADDR},
Shawn Guo7e5e8332012-12-30 14:14:59 +0000188 {USDHC4_BASE_ADDR},
Fabio Estevam77e62892012-09-13 03:18:20 +0000189};
190
Shawn Guo7e5e8332012-12-30 14:14:59 +0000191#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 2)
192#define USDHC3_CD_GPIO IMX_GPIO_NR(2, 0)
193
Peng Fan03a43df2016-01-28 16:51:27 +0800194int board_mmc_get_env_dev(int devno)
195{
196 return devno - 1;
197}
198
Fabio Estevam77e62892012-09-13 03:18:20 +0000199int board_mmc_getcd(struct mmc *mmc)
200{
Shawn Guo7e5e8332012-12-30 14:14:59 +0000201 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Otavio Salvadorc2bed642013-03-16 08:05:06 +0000202 int ret = 0;
Shawn Guo7e5e8332012-12-30 14:14:59 +0000203
204 switch (cfg->esdhc_base) {
205 case USDHC2_BASE_ADDR:
Otavio Salvadorc2bed642013-03-16 08:05:06 +0000206 ret = !gpio_get_value(USDHC2_CD_GPIO);
207 break;
Shawn Guo7e5e8332012-12-30 14:14:59 +0000208 case USDHC3_BASE_ADDR:
Otavio Salvadorc2bed642013-03-16 08:05:06 +0000209 ret = !gpio_get_value(USDHC3_CD_GPIO);
210 break;
211 case USDHC4_BASE_ADDR:
212 ret = 1; /* eMMC/uSDHC4 is always present */
213 break;
Shawn Guo7e5e8332012-12-30 14:14:59 +0000214 }
Otavio Salvadorc2bed642013-03-16 08:05:06 +0000215
216 return ret;
Fabio Estevam77e62892012-09-13 03:18:20 +0000217}
218
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900219int board_mmc_init(struct bd_info *bis)
Fabio Estevam77e62892012-09-13 03:18:20 +0000220{
Fabio Estevam56cf36a2014-11-18 11:26:06 -0200221 struct src *psrc = (struct src *)SRC_BASE_ADDR;
222 unsigned reg = readl(&psrc->sbmr1) >> 11;
John Tobias07491552014-11-12 14:27:45 -0800223 /*
224 * Upon reading BOOT_CFG register the following map is done:
225 * Bit 11 and 12 of BOOT_CFG register can determine the current
226 * mmc port
227 * 0x1 SD1
228 * 0x2 SD2
229 * 0x3 SD4
230 */
231
232 switch (reg & 0x3) {
233 case 0x1:
Fabio Estevamc88f1672017-05-12 12:45:23 -0300234 SETUP_IOMUX_PADS(usdhc2_pads);
John Tobias07491552014-11-12 14:27:45 -0800235 usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
236 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
237 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
238 break;
239 case 0x2:
Fabio Estevamc88f1672017-05-12 12:45:23 -0300240 SETUP_IOMUX_PADS(usdhc3_pads);
John Tobias07491552014-11-12 14:27:45 -0800241 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
242 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
243 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
244 break;
245 case 0x3:
Fabio Estevamc88f1672017-05-12 12:45:23 -0300246 SETUP_IOMUX_PADS(usdhc4_pads);
John Tobias07491552014-11-12 14:27:45 -0800247 usdhc_cfg[0].esdhc_base = USDHC4_BASE_ADDR;
248 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
249 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
250 break;
251 }
252
253 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
Fabio Estevam77e62892012-09-13 03:18:20 +0000254}
255#endif
256
Fabio Estevam509c06f2016-10-24 10:22:06 -0200257static int ar8031_phy_fixup(struct phy_device *phydev)
258{
259 unsigned short val;
260
261 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
262 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
263 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
264 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
265
266 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
267 val &= 0xffe3;
268 val |= 0x18;
269 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
270
271 /* introduce tx clock delay */
272 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
273 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
274 val |= 0x0100;
275 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
276
277 return 0;
278}
279
280int board_phy_config(struct phy_device *phydev)
281{
282 ar8031_phy_fixup(phydev);
283
284 if (phydev->drv->config)
285 phydev->drv->config(phydev);
286
287 return 0;
288}
289
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500290#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam70f84b52013-11-25 10:34:26 -0200291static void disable_lvds(struct display_info_t const *dev)
292{
293 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
294
295 int reg = readl(&iomux->gpr[2]);
296
297 reg &= ~(IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
298 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
299
300 writel(reg, &iomux->gpr[2]);
301}
302
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300303static void do_enable_hdmi(struct display_info_t const *dev)
304{
Fabio Estevam70f84b52013-11-25 10:34:26 -0200305 disable_lvds(dev);
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300306 imx_enable_hdmi_phy();
307}
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500308
Eric Benardd6cabb22014-04-04 19:05:54 +0200309struct display_info_t const displays[] = {{
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300310 .bus = -1,
311 .addr = 0,
Fabio Estevam7d66d562013-12-04 01:08:17 -0200312 .pixfmt = IPU_PIX_FMT_RGB666,
Fabio Estevam70f84b52013-11-25 10:34:26 -0200313 .detect = NULL,
Marco Franchi029d07f2016-06-08 15:05:31 -0300314 .enable = enable_lvds,
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300315 .mode = {
Fabio Estevam70f84b52013-11-25 10:34:26 -0200316 .name = "Hannstar-XGA",
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300317 .refresh = 60,
318 .xres = 1024,
319 .yres = 768,
Fabio Estevame2b20032016-03-16 12:55:03 -0300320 .pixclock = 15384,
321 .left_margin = 160,
322 .right_margin = 24,
323 .upper_margin = 29,
324 .lower_margin = 3,
325 .hsync_len = 136,
326 .vsync_len = 6,
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300327 .sync = FB_SYNC_EXT,
328 .vmode = FB_VMODE_NONINTERLACED
329} }, {
330 .bus = -1,
331 .addr = 0,
Fabio Estevam70f84b52013-11-25 10:34:26 -0200332 .pixfmt = IPU_PIX_FMT_RGB24,
333 .detect = detect_hdmi,
334 .enable = do_enable_hdmi,
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300335 .mode = {
Fabio Estevam70f84b52013-11-25 10:34:26 -0200336 .name = "HDMI",
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300337 .refresh = 60,
338 .xres = 1024,
339 .yres = 768,
Fabio Estevame2b20032016-03-16 12:55:03 -0300340 .pixclock = 15384,
341 .left_margin = 160,
342 .right_margin = 24,
343 .upper_margin = 29,
344 .lower_margin = 3,
345 .hsync_len = 136,
346 .vsync_len = 6,
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300347 .sync = FB_SYNC_EXT,
348 .vmode = FB_VMODE_NONINTERLACED
Fabio Estevam0d29cee2014-10-21 21:14:53 -0200349} }, {
350 .bus = 0,
351 .addr = 0,
352 .pixfmt = IPU_PIX_FMT_RGB24,
353 .detect = NULL,
354 .enable = enable_rgb,
355 .mode = {
356 .name = "SEIKO-WVGA",
357 .refresh = 60,
358 .xres = 800,
359 .yres = 480,
360 .pixclock = 29850,
361 .left_margin = 89,
362 .right_margin = 164,
363 .upper_margin = 23,
364 .lower_margin = 10,
365 .hsync_len = 10,
366 .vsync_len = 10,
367 .sync = 0,
368 .vmode = FB_VMODE_NONINTERLACED
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300369} } };
Eric Benardd6cabb22014-04-04 19:05:54 +0200370size_t display_count = ARRAY_SIZE(displays);
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500371
372static void setup_display(void)
373{
374 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300375 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500376 int reg;
377
Fabio Estevamdee3c842013-12-04 01:08:16 -0200378 /* Setup HSYNC, VSYNC, DISP_CLK for debugging purposes */
Fabio Estevamc88f1672017-05-12 12:45:23 -0300379 SETUP_IOMUX_PADS(di0_pads);
Fabio Estevamdee3c842013-12-04 01:08:16 -0200380
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500381 enable_ipu_clock();
382 imx_setup_hdmi();
383
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300384 /* Turn on LDB0, LDB1, IPU,IPU DI0 clocks */
Liu Ying6f450632013-11-29 22:38:39 +0800385 reg = readl(&mxc_ccm->CCGR3);
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300386 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK | MXC_CCM_CCGR3_LDB_DI1_MASK;
387 writel(reg, &mxc_ccm->CCGR3);
388
389 /* set LDB0, LDB1 clk select to 011/011 */
390 reg = readl(&mxc_ccm->cs2cdr);
391 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
392 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
393 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
394 | (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
395 writel(reg, &mxc_ccm->cs2cdr);
396
397 reg = readl(&mxc_ccm->cscmr2);
398 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV | MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV;
399 writel(reg, &mxc_ccm->cscmr2);
400
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500401 reg = readl(&mxc_ccm->chsccdr);
402 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
403 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300404 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
405 << MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500406 writel(reg, &mxc_ccm->chsccdr);
Fabio Estevam9e642cd2013-09-04 15:12:38 -0300407
408 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
409 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW
410 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
411 | IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
412 | IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
413 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
414 | IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
415 | IOMUXC_GPR2_LVDS_CH0_MODE_DISABLED
416 | IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0;
417 writel(reg, &iomux->gpr[2]);
418
419 reg = readl(&iomux->gpr[3]);
420 reg = (reg & ~(IOMUXC_GPR3_LVDS1_MUX_CTL_MASK
421 | IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
422 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
423 << IOMUXC_GPR3_LVDS1_MUX_CTL_OFFSET);
424 writel(reg, &iomux->gpr[3]);
Pardeep Kumar Singla0b87ba02013-07-25 12:12:14 -0500425}
426#endif /* CONFIG_VIDEO_IPUV3 */
427
428/*
429 * Do not overwrite the console
430 * Use always serial for U-Boot console
431 */
432int overwrite_console(void)
433{
434 return 1;
435}
436
Peng Fanc9498fa2014-12-02 09:55:27 +0800437#ifdef CONFIG_USB_EHCI_MX6
Peng Fanc9498fa2014-12-02 09:55:27 +0800438static void setup_usb(void)
439{
Peng Fanc9498fa2014-12-02 09:55:27 +0800440 /*
441 * set daisy chain for otg_pin_id on 6q.
442 * for 6dl, this bit is reserved
443 */
444 imx_iomux_set_gpr_register(1, 13, 1, 0);
Peng Fanc9498fa2014-12-02 09:55:27 +0800445}
446#endif
447
Fabio Estevam77e62892012-09-13 03:18:20 +0000448int board_early_init_f(void)
449{
450 setup_iomux_uart();
451
452 return 0;
453}
454
455int board_init(void)
456{
457 /* address of boot parameters */
458 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
459
Fabio Estevamd82dad42013-11-08 16:20:54 -0200460#ifdef CONFIG_MXC_SPI
461 setup_spi();
462#endif
Fabio Estevam1b98b212023-02-16 07:08:49 -0300463
Fabio Estevam6f73a292017-09-22 23:45:28 -0300464#if defined(CONFIG_VIDEO_IPUV3)
465 setup_display();
466#endif
Peng Fanc9498fa2014-12-02 09:55:27 +0800467#ifdef CONFIG_USB_EHCI_MX6
468 setup_usb();
469#endif
470
Fabio Estevamba92ad62014-05-09 13:15:42 -0300471 return 0;
472}
473
Ye.Li75e02f92014-11-06 16:29:00 +0800474int power_init_board(void)
Fabio Estevamba92ad62014-05-09 13:15:42 -0300475{
Fabio Estevam1b98b212023-02-16 07:08:49 -0300476 struct udevice *dev;
Fabio Estevameffbec12015-07-21 20:02:49 -0300477 unsigned int reg;
478 int ret;
Fabio Estevamba92ad62014-05-09 13:15:42 -0300479
Fabio Estevam1b98b212023-02-16 07:08:49 -0300480 ret = pmic_get("pfuze100@8", &dev);
481 if (ret == -ENODEV)
482 return 0;
483
484 if (ret != 0)
485 return ret;
Fabio Estevamba92ad62014-05-09 13:15:42 -0300486
Fabio Estevam1b98b212023-02-16 07:08:49 -0300487 ret = pfuze_mode_init(dev, APS_PFM);
Peng Fane5bcd4d2015-01-27 10:14:04 +0800488 if (ret < 0)
489 return ret;
490
Fabio Estevamba92ad62014-05-09 13:15:42 -0300491 /* Increase VGEN3 from 2.5 to 2.8V */
Fabio Estevam1b98b212023-02-16 07:08:49 -0300492 reg = pmic_reg_read(dev, PFUZE100_VGEN3VOL);
Ye.Li75e02f92014-11-06 16:29:00 +0800493 reg &= ~LDO_VOL_MASK;
494 reg |= LDOB_2_80V;
Fabio Estevam1b98b212023-02-16 07:08:49 -0300495 pmic_reg_write(dev, PFUZE100_VGEN3VOL, reg);
Fabio Estevamba92ad62014-05-09 13:15:42 -0300496
497 /* Increase VGEN5 from 2.8 to 3V */
Fabio Estevam1b98b212023-02-16 07:08:49 -0300498 reg = pmic_reg_read(dev, PFUZE100_VGEN5VOL);
Ye.Li75e02f92014-11-06 16:29:00 +0800499 reg &= ~LDO_VOL_MASK;
500 reg |= LDOB_3_00V;
Fabio Estevam1b98b212023-02-16 07:08:49 -0300501 pmic_reg_write(dev, PFUZE100_VGEN5VOL, reg);
Fabio Estevamba92ad62014-05-09 13:15:42 -0300502
Fabio Estevam77e62892012-09-13 03:18:20 +0000503 return 0;
504}
505
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300506#ifdef CONFIG_MXC_SPI
507int board_spi_cs_gpio(unsigned bus, unsigned cs)
508{
509 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(4, 9)) : -1;
510}
511#endif
512
Otavio Salvador52863372013-03-16 08:05:07 +0000513#ifdef CONFIG_CMD_BMODE
514static const struct boot_mode board_boot_modes[] = {
515 /* 4 bit bus width */
516 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
517 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
518 /* 8 bit bus width */
Ye Li4ea4a9b2016-01-30 11:53:42 +0800519 {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
Otavio Salvador52863372013-03-16 08:05:07 +0000520 {NULL, 0},
521};
522#endif
523
524int board_late_init(void)
525{
526#ifdef CONFIG_CMD_BMODE
527 add_board_boot_modes(board_boot_modes);
528#endif
Peng Fan04321fc2015-07-11 11:38:46 +0800529
530#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Simon Glass6a38e412017-08-03 12:22:09 -0600531 env_set("board_name", "SABRESD");
Peng Fan04321fc2015-07-11 11:38:46 +0800532
Peng Fane27c4db2015-10-15 18:05:59 +0800533 if (is_mx6dqp())
Simon Glass6a38e412017-08-03 12:22:09 -0600534 env_set("board_rev", "MX6QP");
Peng Fan4a597d02016-05-23 18:36:06 +0800535 else if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600536 env_set("board_rev", "MX6Q");
Peng Fan4a597d02016-05-23 18:36:06 +0800537 else if (is_mx6sdl())
Simon Glass6a38e412017-08-03 12:22:09 -0600538 env_set("board_rev", "MX6DL");
Peng Fan04321fc2015-07-11 11:38:46 +0800539#endif
540
Otavio Salvador52863372013-03-16 08:05:07 +0000541 return 0;
542}
543
John Tobias07491552014-11-12 14:27:45 -0800544#ifdef CONFIG_SPL_BUILD
Fabio Estevamc88f1672017-05-12 12:45:23 -0300545#include <asm/arch/mx6-ddr.h>
John Tobias07491552014-11-12 14:27:45 -0800546#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900547#include <linux/libfdt.h>
John Tobias07491552014-11-12 14:27:45 -0800548
Diego Dorta466016e2016-10-11 11:09:27 -0300549#ifdef CONFIG_SPL_OS_BOOT
550int spl_start_uboot(void)
551{
Abel Vesa78d974e2019-02-01 16:40:19 +0000552 gpio_request(KEY_VOL_UP, "KEY Volume UP");
Diego Dorta466016e2016-10-11 11:09:27 -0300553 gpio_direction_input(KEY_VOL_UP);
554
555 /* Only enter in Falcon mode if KEY_VOL_UP is pressed */
556 return gpio_get_value(KEY_VOL_UP);
557}
558#endif
559
Fabio Estevamc6ecd0b2014-11-14 09:36:59 -0200560static void ccgr_init(void)
561{
562 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
563
564 writel(0x00C03F3F, &ccm->CCGR0);
565 writel(0x0030FC03, &ccm->CCGR1);
566 writel(0x0FFFC000, &ccm->CCGR2);
567 writel(0x3FF00000, &ccm->CCGR3);
568 writel(0x00FFF300, &ccm->CCGR4);
569 writel(0x0F0000C3, &ccm->CCGR5);
570 writel(0x000003FF, &ccm->CCGR6);
571}
572
Fabio Estevam9b86c822016-09-26 09:14:25 -0300573static int mx6q_dcd_table[] = {
574 0x020e0798, 0x000C0000,
575 0x020e0758, 0x00000000,
576 0x020e0588, 0x00000030,
577 0x020e0594, 0x00000030,
578 0x020e056c, 0x00000030,
579 0x020e0578, 0x00000030,
580 0x020e074c, 0x00000030,
581 0x020e057c, 0x00000030,
582 0x020e058c, 0x00000000,
583 0x020e059c, 0x00000030,
584 0x020e05a0, 0x00000030,
585 0x020e078c, 0x00000030,
586 0x020e0750, 0x00020000,
587 0x020e05a8, 0x00000030,
588 0x020e05b0, 0x00000030,
589 0x020e0524, 0x00000030,
590 0x020e051c, 0x00000030,
591 0x020e0518, 0x00000030,
592 0x020e050c, 0x00000030,
593 0x020e05b8, 0x00000030,
594 0x020e05c0, 0x00000030,
595 0x020e0774, 0x00020000,
596 0x020e0784, 0x00000030,
597 0x020e0788, 0x00000030,
598 0x020e0794, 0x00000030,
599 0x020e079c, 0x00000030,
600 0x020e07a0, 0x00000030,
601 0x020e07a4, 0x00000030,
602 0x020e07a8, 0x00000030,
603 0x020e0748, 0x00000030,
604 0x020e05ac, 0x00000030,
605 0x020e05b4, 0x00000030,
606 0x020e0528, 0x00000030,
607 0x020e0520, 0x00000030,
608 0x020e0514, 0x00000030,
609 0x020e0510, 0x00000030,
610 0x020e05bc, 0x00000030,
611 0x020e05c4, 0x00000030,
612 0x021b0800, 0xa1390003,
613 0x021b080c, 0x001F001F,
614 0x021b0810, 0x001F001F,
615 0x021b480c, 0x001F001F,
616 0x021b4810, 0x001F001F,
617 0x021b083c, 0x43270338,
618 0x021b0840, 0x03200314,
619 0x021b483c, 0x431A032F,
620 0x021b4840, 0x03200263,
621 0x021b0848, 0x4B434748,
622 0x021b4848, 0x4445404C,
623 0x021b0850, 0x38444542,
624 0x021b4850, 0x4935493A,
625 0x021b081c, 0x33333333,
626 0x021b0820, 0x33333333,
627 0x021b0824, 0x33333333,
628 0x021b0828, 0x33333333,
629 0x021b481c, 0x33333333,
630 0x021b4820, 0x33333333,
631 0x021b4824, 0x33333333,
632 0x021b4828, 0x33333333,
633 0x021b08b8, 0x00000800,
634 0x021b48b8, 0x00000800,
635 0x021b0004, 0x00020036,
636 0x021b0008, 0x09444040,
637 0x021b000c, 0x555A7975,
638 0x021b0010, 0xFF538F64,
639 0x021b0014, 0x01FF00DB,
640 0x021b0018, 0x00001740,
641 0x021b001c, 0x00008000,
642 0x021b002c, 0x000026d2,
643 0x021b0030, 0x005A1023,
644 0x021b0040, 0x00000027,
645 0x021b0000, 0x831A0000,
646 0x021b001c, 0x04088032,
647 0x021b001c, 0x00008033,
648 0x021b001c, 0x00048031,
649 0x021b001c, 0x09408030,
650 0x021b001c, 0x04008040,
651 0x021b0020, 0x00005800,
652 0x021b0818, 0x00011117,
653 0x021b4818, 0x00011117,
654 0x021b0004, 0x00025576,
655 0x021b0404, 0x00011006,
656 0x021b001c, 0x00000000,
657};
658
659static int mx6qp_dcd_table[] = {
660 0x020e0798, 0x000c0000,
661 0x020e0758, 0x00000000,
662 0x020e0588, 0x00000030,
663 0x020e0594, 0x00000030,
664 0x020e056c, 0x00000030,
665 0x020e0578, 0x00000030,
666 0x020e074c, 0x00000030,
667 0x020e057c, 0x00000030,
668 0x020e058c, 0x00000000,
669 0x020e059c, 0x00000030,
670 0x020e05a0, 0x00000030,
671 0x020e078c, 0x00000030,
672 0x020e0750, 0x00020000,
673 0x020e05a8, 0x00000030,
674 0x020e05b0, 0x00000030,
675 0x020e0524, 0x00000030,
676 0x020e051c, 0x00000030,
677 0x020e0518, 0x00000030,
678 0x020e050c, 0x00000030,
679 0x020e05b8, 0x00000030,
680 0x020e05c0, 0x00000030,
681 0x020e0774, 0x00020000,
682 0x020e0784, 0x00000030,
683 0x020e0788, 0x00000030,
684 0x020e0794, 0x00000030,
685 0x020e079c, 0x00000030,
686 0x020e07a0, 0x00000030,
687 0x020e07a4, 0x00000030,
688 0x020e07a8, 0x00000030,
689 0x020e0748, 0x00000030,
690 0x020e05ac, 0x00000030,
691 0x020e05b4, 0x00000030,
692 0x020e0528, 0x00000030,
693 0x020e0520, 0x00000030,
694 0x020e0514, 0x00000030,
695 0x020e0510, 0x00000030,
696 0x020e05bc, 0x00000030,
697 0x020e05c4, 0x00000030,
698 0x021b0800, 0xa1390003,
699 0x021b080c, 0x001b001e,
700 0x021b0810, 0x002e0029,
701 0x021b480c, 0x001b002a,
702 0x021b4810, 0x0019002c,
703 0x021b083c, 0x43240334,
704 0x021b0840, 0x0324031a,
705 0x021b483c, 0x43340344,
706 0x021b4840, 0x03280276,
707 0x021b0848, 0x44383A3E,
708 0x021b4848, 0x3C3C3846,
709 0x021b0850, 0x2e303230,
710 0x021b4850, 0x38283E34,
711 0x021b081c, 0x33333333,
712 0x021b0820, 0x33333333,
713 0x021b0824, 0x33333333,
714 0x021b0828, 0x33333333,
715 0x021b481c, 0x33333333,
716 0x021b4820, 0x33333333,
717 0x021b4824, 0x33333333,
718 0x021b4828, 0x33333333,
719 0x021b08c0, 0x24912249,
720 0x021b48c0, 0x24914289,
721 0x021b08b8, 0x00000800,
722 0x021b48b8, 0x00000800,
723 0x021b0004, 0x00020036,
724 0x021b0008, 0x24444040,
725 0x021b000c, 0x555A7955,
726 0x021b0010, 0xFF320F64,
727 0x021b0014, 0x01ff00db,
728 0x021b0018, 0x00001740,
729 0x021b001c, 0x00008000,
730 0x021b002c, 0x000026d2,
731 0x021b0030, 0x005A1023,
732 0x021b0040, 0x00000027,
733 0x021b0400, 0x14420000,
734 0x021b0000, 0x831A0000,
735 0x021b0890, 0x00400C58,
736 0x00bb0008, 0x00000000,
737 0x00bb000c, 0x2891E41A,
738 0x00bb0038, 0x00000564,
739 0x00bb0014, 0x00000040,
740 0x00bb0028, 0x00000020,
741 0x00bb002c, 0x00000020,
742 0x021b001c, 0x04088032,
743 0x021b001c, 0x00008033,
744 0x021b001c, 0x00048031,
745 0x021b001c, 0x09408030,
746 0x021b001c, 0x04008040,
747 0x021b0020, 0x00005800,
748 0x021b0818, 0x00011117,
749 0x021b4818, 0x00011117,
750 0x021b0004, 0x00025576,
751 0x021b0404, 0x00011006,
752 0x021b001c, 0x00000000,
753};
754
Fabio Estevam15cb6b12017-05-12 12:45:24 -0300755static int mx6dl_dcd_table[] = {
756 0x020e0774, 0x000C0000,
757 0x020e0754, 0x00000000,
758 0x020e04ac, 0x00000030,
759 0x020e04b0, 0x00000030,
760 0x020e0464, 0x00000030,
761 0x020e0490, 0x00000030,
762 0x020e074c, 0x00000030,
763 0x020e0494, 0x00000030,
764 0x020e04a0, 0x00000000,
765 0x020e04b4, 0x00000030,
766 0x020e04b8, 0x00000030,
767 0x020e076c, 0x00000030,
768 0x020e0750, 0x00020000,
769 0x020e04bc, 0x00000030,
770 0x020e04c0, 0x00000030,
771 0x020e04c4, 0x00000030,
772 0x020e04c8, 0x00000030,
773 0x020e04cc, 0x00000030,
774 0x020e04d0, 0x00000030,
775 0x020e04d4, 0x00000030,
776 0x020e04d8, 0x00000030,
777 0x020e0760, 0x00020000,
778 0x020e0764, 0x00000030,
779 0x020e0770, 0x00000030,
780 0x020e0778, 0x00000030,
781 0x020e077c, 0x00000030,
782 0x020e0780, 0x00000030,
783 0x020e0784, 0x00000030,
784 0x020e078c, 0x00000030,
785 0x020e0748, 0x00000030,
786 0x020e0470, 0x00000030,
787 0x020e0474, 0x00000030,
788 0x020e0478, 0x00000030,
789 0x020e047c, 0x00000030,
790 0x020e0480, 0x00000030,
791 0x020e0484, 0x00000030,
792 0x020e0488, 0x00000030,
793 0x020e048c, 0x00000030,
794 0x021b0800, 0xa1390003,
795 0x021b080c, 0x001F001F,
796 0x021b0810, 0x001F001F,
797 0x021b480c, 0x001F001F,
798 0x021b4810, 0x001F001F,
799 0x021b083c, 0x4220021F,
800 0x021b0840, 0x0207017E,
801 0x021b483c, 0x4201020C,
802 0x021b4840, 0x01660172,
803 0x021b0848, 0x4A4D4E4D,
804 0x021b4848, 0x4A4F5049,
805 0x021b0850, 0x3F3C3D31,
806 0x021b4850, 0x3238372B,
807 0x021b081c, 0x33333333,
808 0x021b0820, 0x33333333,
809 0x021b0824, 0x33333333,
810 0x021b0828, 0x33333333,
811 0x021b481c, 0x33333333,
812 0x021b4820, 0x33333333,
813 0x021b4824, 0x33333333,
814 0x021b4828, 0x33333333,
815 0x021b08b8, 0x00000800,
816 0x021b48b8, 0x00000800,
817 0x021b0004, 0x0002002D,
818 0x021b0008, 0x00333030,
819 0x021b000c, 0x3F435313,
820 0x021b0010, 0xB66E8B63,
821 0x021b0014, 0x01FF00DB,
822 0x021b0018, 0x00001740,
823 0x021b001c, 0x00008000,
824 0x021b002c, 0x000026d2,
825 0x021b0030, 0x00431023,
826 0x021b0040, 0x00000027,
827 0x021b0000, 0x831A0000,
828 0x021b001c, 0x04008032,
829 0x021b001c, 0x00008033,
830 0x021b001c, 0x00048031,
831 0x021b001c, 0x05208030,
832 0x021b001c, 0x04008040,
833 0x021b0020, 0x00005800,
834 0x021b0818, 0x00011117,
835 0x021b4818, 0x00011117,
836 0x021b0004, 0x0002556D,
837 0x021b0404, 0x00011006,
838 0x021b001c, 0x00000000,
839};
840
Fabio Estevam9b86c822016-09-26 09:14:25 -0300841static void ddr_init(int *table, int size)
John Tobias07491552014-11-12 14:27:45 -0800842{
Fabio Estevam9b86c822016-09-26 09:14:25 -0300843 int i;
John Tobias07491552014-11-12 14:27:45 -0800844
Fabio Estevam9b86c822016-09-26 09:14:25 -0300845 for (i = 0; i < size / 2 ; i++)
846 writel(table[2 * i + 1], table[2 * i]);
John Tobias07491552014-11-12 14:27:45 -0800847}
848
Fabio Estevam9b86c822016-09-26 09:14:25 -0300849static void spl_dram_init(void)
850{
851 if (is_mx6dq())
852 ddr_init(mx6q_dcd_table, ARRAY_SIZE(mx6q_dcd_table));
853 else if (is_mx6dqp())
854 ddr_init(mx6qp_dcd_table, ARRAY_SIZE(mx6qp_dcd_table));
Fabio Estevam15cb6b12017-05-12 12:45:24 -0300855 else if (is_mx6sdl())
856 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
Fabio Estevam9b86c822016-09-26 09:14:25 -0300857}
858
John Tobias07491552014-11-12 14:27:45 -0800859void board_init_f(ulong dummy)
860{
Fabio Estevam9b86c822016-09-26 09:14:25 -0300861 /* DDR initialization */
862 spl_dram_init();
863
John Tobias07491552014-11-12 14:27:45 -0800864 /* setup AIPS and disable watchdog */
865 arch_cpu_init();
866
Fabio Estevamc6ecd0b2014-11-14 09:36:59 -0200867 ccgr_init();
868 gpr_init();
869
John Tobias07491552014-11-12 14:27:45 -0800870 board_early_init_f();
871
872 /* setup GP timer */
873 timer_init();
874
875 /* UART clocks enabled and gd valid - init serial console */
876 preloader_console_init();
877
John Tobias07491552014-11-12 14:27:45 -0800878 /* Clear the BSS. */
879 memset(__bss_start, 0, __bss_end - __bss_start);
880
881 /* load/boot image from boot device */
882 board_init_r(NULL, 0);
883}
John Tobias07491552014-11-12 14:27:45 -0800884#endif
Abel Vesa4f5bd302019-02-01 16:40:12 +0000885
886#ifdef CONFIG_SPL_LOAD_FIT
887int board_fit_config_name_match(const char *name)
888{
889 if (is_mx6dq()) {
890 if (!strcmp(name, "imx6q-sabresd"))
891 return 0;
892 } else if (is_mx6dqp()) {
893 if (!strcmp(name, "imx6qp-sabresd"))
894 return 0;
895 } else if (is_mx6dl()) {
896 if (!strcmp(name, "imx6dl-sabresd"))
897 return 0;
898 }
899
900 return -1;
901}
902#endif