blob: 1fb3c69edeb529c12c61355095b7a8074ac07ea1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam1d97a592015-04-20 14:48:57 -03002/*
3 * Copyright (C) 2015 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
6 *
7 * Copyright (C) 2013 Jon Nettleton <jon.nettleton@gmail.com>
8 *
9 * Based on SPL code from Solidrun tree, which is:
10 * Author: Tungyi Lin <tungyilin1127@gmail.com>
11 *
12 * Derived from EDM_CF_IMX6 code by TechNexion,Inc
13 * Ported to SolidRun microSOM by Rabeeh Khoury <rabeeh@solid-run.com>
Fabio Estevam1d97a592015-04-20 14:48:57 -030014 */
15
16#include <asm/arch/clock.h>
17#include <asm/arch/imx-regs.h>
18#include <asm/arch/iomux.h>
19#include <asm/arch/mx6-pins.h>
Fabio Estevam239fd312015-04-29 22:28:09 -030020#include <asm/arch/mxc_hdmi.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090021#include <linux/errno.h>
Fabio Estevam1d97a592015-04-20 14:48:57 -030022#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020023#include <asm/mach-imx/iomux-v3.h>
24#include <asm/mach-imx/sata.h>
25#include <asm/mach-imx/video.h>
Fabio Estevam1d97a592015-04-20 14:48:57 -030026#include <mmc.h>
27#include <fsl_esdhc.h>
Fabio Estevam444f0012015-05-04 11:22:55 -030028#include <malloc.h>
Fabio Estevam1d97a592015-04-20 14:48:57 -030029#include <miiphy.h>
30#include <netdev.h>
31#include <asm/arch/crm_regs.h>
32#include <asm/io.h>
33#include <asm/arch/sys_proto.h>
Fabio Estevam1d97a592015-04-20 14:48:57 -030034#include <spl.h>
Fabio Estevam729bbb82015-04-29 22:28:10 -030035#include <usb.h>
Mateusz Kulikowski3add69e2016-03-31 23:12:23 +020036#include <usb/ehci-ci.h>
Fabio Estevam1d97a592015-04-20 14:48:57 -030037
38DECLARE_GLOBAL_DATA_PTR;
39
40#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)
43
44#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)
47
48#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
50
51#define ENET_PAD_CTRL_PD (PAD_CTL_PUS_100K_DOWN | \
52 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
53
54#define ENET_PAD_CTRL_CLK ((PAD_CTL_PUS_100K_UP & ~PAD_CTL_PKE) | \
55 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
56
57#define ETH_PHY_RESET IMX_GPIO_NR(4, 15)
Fabio Estevam729bbb82015-04-29 22:28:10 -030058#define USB_H1_VBUS IMX_GPIO_NR(1, 0)
Fabio Estevam1d97a592015-04-20 14:48:57 -030059
60int dram_init(void)
61{
62 gd->ram_size = imx_ddr_size();
63 return 0;
64}
65
66static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevam5f402c42015-04-25 18:47:17 -030067 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
68 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevam1d97a592015-04-20 14:48:57 -030069};
70
71static iomux_v3_cfg_t const usdhc2_pads[] = {
Fabio Estevam5f402c42015-04-25 18:47:17 -030072 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
73 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
74 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
75 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
76 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
77 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Fabio Estevam1d97a592015-04-20 14:48:57 -030078};
79
Fabio Estevam7a2f9cd2015-04-25 18:47:19 -030080static iomux_v3_cfg_t const hb_cbi_sense[] = {
81 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
82 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(UART_PAD_CTRL)),
83 IOMUX_PADS(PAD_EIM_DA4__GPIO3_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
84};
85
Fabio Estevam729bbb82015-04-29 22:28:10 -030086static iomux_v3_cfg_t const usb_pads[] = {
87 IOMUX_PADS(PAD_GPIO_0__GPIO1_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
88};
89
Fabio Estevam1d97a592015-04-20 14:48:57 -030090static void setup_iomux_uart(void)
91{
Fabio Estevam5f402c42015-04-25 18:47:17 -030092 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevam1d97a592015-04-20 14:48:57 -030093}
94
95static struct fsl_esdhc_cfg usdhc_cfg[1] = {
96 {USDHC2_BASE_ADDR},
97};
98
99int board_mmc_getcd(struct mmc *mmc)
100{
101 return 1; /* uSDHC2 is always present */
102}
103
104int board_mmc_init(bd_t *bis)
105{
Fabio Estevam5f402c42015-04-25 18:47:17 -0300106 SETUP_IOMUX_PADS(usdhc2_pads);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300107 usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
108 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
109 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
110
111 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
112}
113
114static iomux_v3_cfg_t const enet_pads[] = {
Fabio Estevam5f402c42015-04-25 18:47:17 -0300115 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
116 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevam1d97a592015-04-20 14:48:57 -0300117 /* AR8035 reset */
Fabio Estevam5f402c42015-04-25 18:47:17 -0300118 IOMUX_PADS(PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
Fabio Estevam1d97a592015-04-20 14:48:57 -0300119 /* AR8035 interrupt */
Fabio Estevam5f402c42015-04-25 18:47:17 -0300120 IOMUX_PADS(PAD_DI0_PIN2__GPIO4_IO18 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Fabio Estevam1d97a592015-04-20 14:48:57 -0300121 /* GPIO16 -> AR8035 25MHz */
Fabio Estevam5f402c42015-04-25 18:47:17 -0300122 IOMUX_PADS(PAD_GPIO_16__ENET_REF_CLK | MUX_PAD_CTRL(NO_PAD_CTRL)),
123 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(NO_PAD_CTRL)),
124 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
125 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
126 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
127 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
128 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Fabio Estevam1d97a592015-04-20 14:48:57 -0300129 /* AR8035 CLK_25M --> ENET_REF_CLK (V22) */
Fabio Estevam5f402c42015-04-25 18:47:17 -0300130 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL_CLK)),
131 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
132 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
133 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
134 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
135 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
136 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
Fabio Estevama6aac042015-05-04 11:22:56 -0300137 IOMUX_PADS(PAD_ENET_RXD0__GPIO1_IO27 | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
138 IOMUX_PADS(PAD_ENET_RXD1__GPIO1_IO26 | MUX_PAD_CTRL(ENET_PAD_CTRL_PD)),
Fabio Estevam1d97a592015-04-20 14:48:57 -0300139};
140
141static void setup_iomux_enet(void)
142{
Fabio Estevam5f402c42015-04-25 18:47:17 -0300143 SETUP_IOMUX_PADS(enet_pads);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300144
145 gpio_direction_output(ETH_PHY_RESET, 0);
Fabio Estevam355b28f2016-01-04 21:38:08 -0200146 mdelay(10);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300147 gpio_set_value(ETH_PHY_RESET, 1);
Fabio Estevam355b28f2016-01-04 21:38:08 -0200148 udelay(100);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300149}
150
151int board_phy_config(struct phy_device *phydev)
152{
153 if (phydev->drv->config)
154 phydev->drv->config(phydev);
155
156 return 0;
157}
158
Fabio Estevam444f0012015-05-04 11:22:55 -0300159/* On Cuboxi Ethernet PHY can be located at addresses 0x0 or 0x4 */
160#define ETH_PHY_MASK ((1 << 0x0) | (1 << 0x4))
161
Fabio Estevam1d97a592015-04-20 14:48:57 -0300162int board_eth_init(bd_t *bis)
163{
164 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam444f0012015-05-04 11:22:55 -0300165 struct mii_dev *bus;
166 struct phy_device *phydev;
Fabio Estevam1d97a592015-04-20 14:48:57 -0300167
Peng Fan967a83b2015-08-12 17:46:50 +0800168 int ret = enable_fec_anatop_clock(0, ENET_25MHZ);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300169 if (ret)
170 return ret;
171
172 /* set gpr1[ENET_CLK_SEL] */
173 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
174
175 setup_iomux_enet();
176
Fabio Estevam444f0012015-05-04 11:22:55 -0300177 bus = fec_get_miibus(IMX_FEC_BASE, -1);
178 if (!bus)
179 return -EINVAL;
180
181 phydev = phy_find_by_mask(bus, ETH_PHY_MASK, PHY_INTERFACE_MODE_RGMII);
182 if (!phydev) {
183 ret = -EINVAL;
184 goto free_bus;
185 }
186
187 debug("using phy at address %d\n", phydev->addr);
188 ret = fec_probe(bis, -1, IMX_FEC_BASE, bus, phydev);
189 if (ret)
190 goto free_phydev;
191
192 return 0;
193
194free_phydev:
195 free(phydev);
196free_bus:
197 free(bus);
198 return ret;
Fabio Estevam1d97a592015-04-20 14:48:57 -0300199}
200
Fabio Estevam239fd312015-04-29 22:28:09 -0300201#ifdef CONFIG_VIDEO_IPUV3
202static void do_enable_hdmi(struct display_info_t const *dev)
203{
204 imx_enable_hdmi_phy();
205}
206
207struct display_info_t const displays[] = {
208 {
209 .bus = -1,
210 .addr = 0,
211 .pixfmt = IPU_PIX_FMT_RGB24,
212 .detect = detect_hdmi,
213 .enable = do_enable_hdmi,
214 .mode = {
215 .name = "HDMI",
216 /* 1024x768@60Hz (VESA)*/
217 .refresh = 60,
218 .xres = 1024,
219 .yres = 768,
220 .pixclock = 15384,
221 .left_margin = 160,
222 .right_margin = 24,
223 .upper_margin = 29,
224 .lower_margin = 3,
225 .hsync_len = 136,
226 .vsync_len = 6,
227 .sync = FB_SYNC_EXT,
228 .vmode = FB_VMODE_NONINTERLACED
229 }
230 }
231};
232
233size_t display_count = ARRAY_SIZE(displays);
234
235static int setup_display(void)
236{
237 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
238 int reg;
239 int timeout = 100000;
240
241 enable_ipu_clock();
242 imx_setup_hdmi();
243
244 /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */
245 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
246
247 reg = readl(&ccm->analog_pll_video);
248 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
249 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37);
250 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
251 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1);
252 writel(reg, &ccm->analog_pll_video);
253
254 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
255 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
256
257 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
258 writel(reg, &ccm->analog_pll_video);
259
260 while (timeout--)
261 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
262 break;
263 if (timeout < 0) {
264 printf("Warning: video pll lock timeout!\n");
265 return -ETIMEDOUT;
266 }
267
268 reg = readl(&ccm->analog_pll_video);
269 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
270 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
271 writel(reg, &ccm->analog_pll_video);
272
273 /* gate ipu1_di0_clk */
274 clrbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
275
276 /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */
277 reg = readl(&ccm->chsccdr);
278 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK |
279 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK |
280 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
281 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) |
282 (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
283 (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
284 writel(reg, &ccm->chsccdr);
285
286 /* enable ipu1_di0_clk */
287 setbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
288
289 return 0;
290}
291#endif /* CONFIG_VIDEO_IPUV3 */
292
Fabio Estevam729bbb82015-04-29 22:28:10 -0300293#ifdef CONFIG_USB_EHCI_MX6
294static void setup_usb(void)
295{
296 SETUP_IOMUX_PADS(usb_pads);
297}
298
299int board_ehci_hcd_init(int port)
300{
301 if (port == 1)
302 gpio_direction_output(USB_H1_VBUS, 1);
303
304 return 0;
305}
306#endif
307
Fabio Estevam1d97a592015-04-20 14:48:57 -0300308int board_early_init_f(void)
309{
310 setup_iomux_uart();
Fabio Estevam239fd312015-04-29 22:28:09 -0300311
Peter Robinson8576fbc2017-07-01 18:44:03 +0100312#ifdef CONFIG_CMD_SATA
313 setup_sata();
314#endif
315
Fabio Estevam729bbb82015-04-29 22:28:10 -0300316#ifdef CONFIG_USB_EHCI_MX6
317 setup_usb();
318#endif
Fabio Estevamf82f20c2017-09-22 23:45:31 -0300319 return 0;
Fabio Estevam1d97a592015-04-20 14:48:57 -0300320}
321
322int board_init(void)
323{
Fabio Estevamf82f20c2017-09-22 23:45:31 -0300324 int ret = 0;
325
Fabio Estevam1d97a592015-04-20 14:48:57 -0300326 /* address of boot parameters */
327 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
328
Fabio Estevamf82f20c2017-09-22 23:45:31 -0300329#ifdef CONFIG_VIDEO_IPUV3
330 ret = setup_display();
331#endif
332
333 return ret;
Fabio Estevam1d97a592015-04-20 14:48:57 -0300334}
335
Fabio Estevam7a2f9cd2015-04-25 18:47:19 -0300336static bool is_hummingboard(void)
337{
338 int val1, val2;
339
340 SETUP_IOMUX_PADS(hb_cbi_sense);
341
342 gpio_direction_input(IMX_GPIO_NR(4, 9));
343 gpio_direction_input(IMX_GPIO_NR(3, 4));
344
345 val1 = gpio_get_value(IMX_GPIO_NR(4, 9));
346 val2 = gpio_get_value(IMX_GPIO_NR(3, 4));
347
348 /*
349 * Machine selection -
350 * Machine val1, val2
351 * -------------------------
Dennis Gilmore52e61ba2017-08-24 10:49:43 -0500352 * HB2 x x
Fabio Estevam7a2f9cd2015-04-25 18:47:19 -0300353 * HB rev 3.x x 0
354 * CBi 0 1
355 * HB 1 1
356 */
357
358 if (val2 == 0)
359 return true;
360 else if (val1 == 0)
361 return false;
362 else
363 return true;
364}
365
Dennis Gilmore52e61ba2017-08-24 10:49:43 -0500366static bool is_hummingboard2(void)
367{
368 int val1;
369
370 SETUP_IOMUX_PADS(hb_cbi_sense);
371
372 gpio_direction_input(IMX_GPIO_NR(2, 8));
373
374 val1 = gpio_get_value(IMX_GPIO_NR(2, 8));
375
376 /*
377 * Machine selection -
378 * Machine val1
379 * -------------------
380 * HB2 0
381 * HB rev 3.x x
382 * CBi x
383 * HB x
384 */
385
386 if (val1 == 0)
387 return true;
388 else
389 return false;
390}
391
Fabio Estevam1d97a592015-04-20 14:48:57 -0300392int checkboard(void)
393{
Dennis Gilmore52e61ba2017-08-24 10:49:43 -0500394 if (is_hummingboard2())
395 puts("Board: MX6 Hummingboard2\n");
396 else if (is_hummingboard())
Fabio Estevam7a2f9cd2015-04-25 18:47:19 -0300397 puts("Board: MX6 Hummingboard\n");
398 else
399 puts("Board: MX6 Cubox-i\n");
400
Fabio Estevam1d97a592015-04-20 14:48:57 -0300401 return 0;
402}
403
Fabio Estevam9887c1a2015-04-25 18:47:21 -0300404int board_late_init(void)
405{
406#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Dennis Gilmore52e61ba2017-08-24 10:49:43 -0500407 if (is_hummingboard2())
408 env_set("board_name", "HUMMINGBOARD2");
409 else if (is_hummingboard())
Simon Glass6a38e412017-08-03 12:22:09 -0600410 env_set("board_name", "HUMMINGBOARD");
Fabio Estevam9887c1a2015-04-25 18:47:21 -0300411 else
Simon Glass6a38e412017-08-03 12:22:09 -0600412 env_set("board_name", "CUBOXI");
Fabio Estevam9887c1a2015-04-25 18:47:21 -0300413
Breno Limaba776122016-07-22 09:11:30 -0300414 if (is_mx6dq())
Simon Glass6a38e412017-08-03 12:22:09 -0600415 env_set("board_rev", "MX6Q");
Fabio Estevam9887c1a2015-04-25 18:47:21 -0300416 else
Simon Glass6a38e412017-08-03 12:22:09 -0600417 env_set("board_rev", "MX6DL");
Fabio Estevam9887c1a2015-04-25 18:47:21 -0300418#endif
419
420 return 0;
421}
422
Fabio Estevam1d97a592015-04-20 14:48:57 -0300423#ifdef CONFIG_SPL_BUILD
Fabio Estevam5f402c42015-04-25 18:47:17 -0300424#include <asm/arch/mx6-ddr.h>
Fabio Estevamcb601912015-04-25 18:47:18 -0300425static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {
Fabio Estevam1d97a592015-04-20 14:48:57 -0300426 .dram_sdclk_0 = 0x00020030,
427 .dram_sdclk_1 = 0x00020030,
428 .dram_cas = 0x00020030,
429 .dram_ras = 0x00020030,
Jon Nettletoncd2020d2018-04-10 17:05:35 -0300430 .dram_reset = 0x000c0030,
Fabio Estevam1d97a592015-04-20 14:48:57 -0300431 .dram_sdcke0 = 0x00003000,
432 .dram_sdcke1 = 0x00003000,
433 .dram_sdba2 = 0x00000000,
434 .dram_sdodt0 = 0x00003030,
435 .dram_sdodt1 = 0x00003030,
436 .dram_sdqs0 = 0x00000030,
437 .dram_sdqs1 = 0x00000030,
438 .dram_sdqs2 = 0x00000030,
439 .dram_sdqs3 = 0x00000030,
440 .dram_sdqs4 = 0x00000030,
441 .dram_sdqs5 = 0x00000030,
442 .dram_sdqs6 = 0x00000030,
443 .dram_sdqs7 = 0x00000030,
444 .dram_dqm0 = 0x00020030,
445 .dram_dqm1 = 0x00020030,
446 .dram_dqm2 = 0x00020030,
447 .dram_dqm3 = 0x00020030,
448 .dram_dqm4 = 0x00020030,
449 .dram_dqm5 = 0x00020030,
450 .dram_dqm6 = 0x00020030,
451 .dram_dqm7 = 0x00020030,
452};
453
Fabio Estevamcb601912015-04-25 18:47:18 -0300454static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = {
455 .dram_sdclk_0 = 0x00000028,
456 .dram_sdclk_1 = 0x00000028,
457 .dram_cas = 0x00000028,
458 .dram_ras = 0x00000028,
459 .dram_reset = 0x000c0028,
460 .dram_sdcke0 = 0x00003000,
461 .dram_sdcke1 = 0x00003000,
462 .dram_sdba2 = 0x00000000,
463 .dram_sdodt0 = 0x00003030,
464 .dram_sdodt1 = 0x00003030,
465 .dram_sdqs0 = 0x00000028,
466 .dram_sdqs1 = 0x00000028,
467 .dram_sdqs2 = 0x00000028,
468 .dram_sdqs3 = 0x00000028,
469 .dram_sdqs4 = 0x00000028,
470 .dram_sdqs5 = 0x00000028,
471 .dram_sdqs6 = 0x00000028,
472 .dram_sdqs7 = 0x00000028,
473 .dram_dqm0 = 0x00000028,
474 .dram_dqm1 = 0x00000028,
475 .dram_dqm2 = 0x00000028,
476 .dram_dqm3 = 0x00000028,
477 .dram_dqm4 = 0x00000028,
478 .dram_dqm5 = 0x00000028,
479 .dram_dqm6 = 0x00000028,
480 .dram_dqm7 = 0x00000028,
481};
482
483static const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = {
Fabio Estevam1d97a592015-04-20 14:48:57 -0300484 .grp_ddr_type = 0x000C0000,
485 .grp_ddrmode_ctl = 0x00020000,
486 .grp_ddrpke = 0x00000000,
487 .grp_addds = 0x00000030,
488 .grp_ctlds = 0x00000030,
489 .grp_ddrmode = 0x00020000,
490 .grp_b0ds = 0x00000030,
491 .grp_b1ds = 0x00000030,
492 .grp_b2ds = 0x00000030,
493 .grp_b3ds = 0x00000030,
494 .grp_b4ds = 0x00000030,
495 .grp_b5ds = 0x00000030,
496 .grp_b6ds = 0x00000030,
497 .grp_b7ds = 0x00000030,
498};
499
Fabio Estevamcb601912015-04-25 18:47:18 -0300500static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
501 .grp_ddr_type = 0x000c0000,
502 .grp_ddrmode_ctl = 0x00020000,
503 .grp_ddrpke = 0x00000000,
504 .grp_addds = 0x00000028,
505 .grp_ctlds = 0x00000028,
506 .grp_ddrmode = 0x00020000,
507 .grp_b0ds = 0x00000028,
508 .grp_b1ds = 0x00000028,
509 .grp_b2ds = 0x00000028,
510 .grp_b3ds = 0x00000028,
511 .grp_b4ds = 0x00000028,
512 .grp_b5ds = 0x00000028,
513 .grp_b6ds = 0x00000028,
514 .grp_b7ds = 0x00000028,
515};
516
517/* microSOM with Dual processor and 1GB memory */
518static const struct mx6_mmdc_calibration mx6q_1g_mmcd_calib = {
519 .p0_mpwldectrl0 = 0x00000000,
520 .p0_mpwldectrl1 = 0x00000000,
521 .p1_mpwldectrl0 = 0x00000000,
522 .p1_mpwldectrl1 = 0x00000000,
523 .p0_mpdgctrl0 = 0x0314031c,
524 .p0_mpdgctrl1 = 0x023e0304,
525 .p1_mpdgctrl0 = 0x03240330,
526 .p1_mpdgctrl1 = 0x03180260,
527 .p0_mprddlctl = 0x3630323c,
528 .p1_mprddlctl = 0x3436283a,
529 .p0_mpwrdlctl = 0x36344038,
530 .p1_mpwrdlctl = 0x422a423c,
531};
532
533/* microSOM with Quad processor and 2GB memory */
534static const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = {
Fabio Estevam1d97a592015-04-20 14:48:57 -0300535 .p0_mpwldectrl0 = 0x00000000,
536 .p0_mpwldectrl1 = 0x00000000,
537 .p1_mpwldectrl0 = 0x00000000,
538 .p1_mpwldectrl1 = 0x00000000,
539 .p0_mpdgctrl0 = 0x0314031c,
540 .p0_mpdgctrl1 = 0x023e0304,
541 .p1_mpdgctrl0 = 0x03240330,
542 .p1_mpdgctrl1 = 0x03180260,
543 .p0_mprddlctl = 0x3630323c,
544 .p1_mprddlctl = 0x3436283a,
545 .p0_mpwrdlctl = 0x36344038,
546 .p1_mpwrdlctl = 0x422a423c,
547};
548
Fabio Estevamcb601912015-04-25 18:47:18 -0300549/* microSOM with Solo processor and 512MB memory */
550static const struct mx6_mmdc_calibration mx6dl_512m_mmcd_calib = {
551 .p0_mpwldectrl0 = 0x0045004D,
552 .p0_mpwldectrl1 = 0x003A0047,
553 .p0_mpdgctrl0 = 0x023C0224,
554 .p0_mpdgctrl1 = 0x02000220,
555 .p0_mprddlctl = 0x44444846,
556 .p0_mpwrdlctl = 0x32343032,
557};
558
559/* microSOM with Dual lite processor and 1GB memory */
560static const struct mx6_mmdc_calibration mx6dl_1g_mmcd_calib = {
561 .p0_mpwldectrl0 = 0x0045004D,
562 .p0_mpwldectrl1 = 0x003A0047,
563 .p1_mpwldectrl0 = 0x001F001F,
564 .p1_mpwldectrl1 = 0x00210035,
565 .p0_mpdgctrl0 = 0x023C0224,
566 .p0_mpdgctrl1 = 0x02000220,
567 .p1_mpdgctrl0 = 0x02200220,
Fabio Estevam4461e1e2015-05-29 13:00:36 -0300568 .p1_mpdgctrl1 = 0x02040208,
Fabio Estevamcb601912015-04-25 18:47:18 -0300569 .p0_mprddlctl = 0x44444846,
570 .p1_mprddlctl = 0x4042463C,
571 .p0_mpwrdlctl = 0x32343032,
572 .p1_mpwrdlctl = 0x36363430,
573};
574
575static struct mx6_ddr3_cfg mem_ddr_2g = {
Fabio Estevam1d97a592015-04-20 14:48:57 -0300576 .mem_speed = 1600,
577 .density = 2,
578 .width = 16,
579 .banks = 8,
580 .rowaddr = 14,
581 .coladdr = 10,
582 .pagesz = 2,
583 .trcd = 1375,
584 .trcmin = 4875,
585 .trasmin = 3500,
Fabio Estevam1d97a592015-04-20 14:48:57 -0300586};
587
Fabio Estevamcb601912015-04-25 18:47:18 -0300588static struct mx6_ddr3_cfg mem_ddr_4g = {
589 .mem_speed = 1600,
590 .density = 4,
591 .width = 16,
592 .banks = 8,
593 .rowaddr = 15,
594 .coladdr = 10,
595 .pagesz = 2,
596 .trcd = 1375,
597 .trcmin = 4875,
598 .trasmin = 3500,
599};
600
Fabio Estevam1d97a592015-04-20 14:48:57 -0300601static void ccgr_init(void)
602{
603 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
604
605 writel(0x00C03F3F, &ccm->CCGR0);
606 writel(0x0030FC03, &ccm->CCGR1);
607 writel(0x0FFFC000, &ccm->CCGR2);
608 writel(0x3FF00000, &ccm->CCGR3);
609 writel(0x00FFF300, &ccm->CCGR4);
610 writel(0x0F0000C3, &ccm->CCGR5);
611 writel(0x000003FF, &ccm->CCGR6);
612}
613
Fabio Estevamcb601912015-04-25 18:47:18 -0300614static void spl_dram_init(int width)
Fabio Estevam1d97a592015-04-20 14:48:57 -0300615{
616 struct mx6_ddr_sysinfo sysinfo = {
617 /* width of data bus: 0=16, 1=32, 2=64 */
Fabio Estevamcb601912015-04-25 18:47:18 -0300618 .dsize = width / 32,
Fabio Estevam1d97a592015-04-20 14:48:57 -0300619 /* config for full 4GB range so that get_mem_size() works */
620 .cs_density = 32, /* 32Gb per CS */
621 .ncs = 1, /* single chip select */
622 .cs1_mirror = 0,
623 .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
624 .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
625 .walat = 1, /* Write additional latency */
626 .ralat = 5, /* Read additional latency */
627 .mif3_mode = 3, /* Command prediction working mode */
628 .bi_on = 1, /* Bank interleaving enabled */
629 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
630 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
Peng Fan77e86952015-08-17 16:11:03 +0800631 .ddr_type = DDR_TYPE_DDR3,
Fabio Estevamcb3c1212016-08-29 20:37:15 -0300632 .refsel = 1, /* Refresh cycles at 32KHz */
633 .refr = 7, /* 8 refresh commands per refresh cycle */
Fabio Estevam1d97a592015-04-20 14:48:57 -0300634 };
635
Breno Limaba776122016-07-22 09:11:30 -0300636 if (is_mx6dq())
Fabio Estevamcb601912015-04-25 18:47:18 -0300637 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
638 else
639 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
640
641 if (is_cpu_type(MXC_CPU_MX6D))
642 mx6_dram_cfg(&sysinfo, &mx6q_1g_mmcd_calib, &mem_ddr_2g);
643 else if (is_cpu_type(MXC_CPU_MX6Q))
644 mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g);
645 else if (is_cpu_type(MXC_CPU_MX6DL))
Fabio Estevam4461e1e2015-05-29 13:00:36 -0300646 mx6_dram_cfg(&sysinfo, &mx6dl_1g_mmcd_calib, &mem_ddr_2g);
Fabio Estevamcb601912015-04-25 18:47:18 -0300647 else if (is_cpu_type(MXC_CPU_MX6SOLO))
648 mx6_dram_cfg(&sysinfo, &mx6dl_512m_mmcd_calib, &mem_ddr_2g);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300649}
650
651void board_init_f(ulong dummy)
652{
653 /* setup AIPS and disable watchdog */
654 arch_cpu_init();
655
656 ccgr_init();
657 gpr_init();
658
659 /* iomux and setup of i2c */
660 board_early_init_f();
661
662 /* setup GP timer */
663 timer_init();
664
665 /* UART clocks enabled and gd valid - init serial console */
666 preloader_console_init();
667
668 /* DDR initialization */
Fabio Estevamcb601912015-04-25 18:47:18 -0300669 if (is_cpu_type(MXC_CPU_MX6SOLO))
670 spl_dram_init(32);
671 else
672 spl_dram_init(64);
Fabio Estevam1d97a592015-04-20 14:48:57 -0300673
674 /* Clear the BSS. */
675 memset(__bss_start, 0, __bss_end - __bss_start);
676
677 /* load/boot image from boot device */
678 board_init_r(NULL, 0);
679}
680#endif