Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 2 | /* |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 3 | * Copyright (C) 2022 Josua Mayer <josua@solid-run.com> |
| 4 | * |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 5 | * Copyright (C) 2015 Freescale Semiconductor, Inc. |
| 6 | * |
| 7 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
| 8 | * |
| 9 | * Copyright (C) 2013 Jon Nettleton <jon.nettleton@gmail.com> |
| 10 | * |
| 11 | * Based on SPL code from Solidrun tree, which is: |
| 12 | * Author: Tungyi Lin <tungyilin1127@gmail.com> |
| 13 | * |
| 14 | * Derived from EDM_CF_IMX6 code by TechNexion,Inc |
| 15 | * Ported to SolidRun microSOM by Rabeeh Khoury <rabeeh@solid-run.com> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 16 | */ |
| 17 | |
Simon Glass | 1e26864 | 2020-05-10 11:39:55 -0600 | [diff] [blame] | 18 | #include <common.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 19 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 20 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 21 | #include <log.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 22 | #include <asm/arch/clock.h> |
| 23 | #include <asm/arch/imx-regs.h> |
| 24 | #include <asm/arch/iomux.h> |
| 25 | #include <asm/arch/mx6-pins.h> |
Fabio Estevam | 239fd31 | 2015-04-29 22:28:09 -0300 | [diff] [blame] | 26 | #include <asm/arch/mxc_hdmi.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 27 | #include <env.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 28 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 29 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 30 | #include <linux/errno.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 31 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 32 | #include <asm/mach-imx/iomux-v3.h> |
| 33 | #include <asm/mach-imx/sata.h> |
| 34 | #include <asm/mach-imx/video.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 35 | #include <asm/sections.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 36 | #include <mmc.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 37 | #include <fsl_esdhc_imx.h> |
Fabio Estevam | 444f001 | 2015-05-04 11:22:55 -0300 | [diff] [blame] | 38 | #include <malloc.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 39 | #include <asm/arch/crm_regs.h> |
| 40 | #include <asm/io.h> |
| 41 | #include <asm/arch/sys_proto.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 42 | #include <spl.h> |
Fabio Estevam | 729bbb8 | 2015-04-29 22:28:10 -0300 | [diff] [blame] | 43 | #include <usb.h> |
Mateusz Kulikowski | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 44 | #include <usb/ehci-ci.h> |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 45 | #include <netdev.h> |
| 46 | #include <phy.h> |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 47 | |
| 48 | DECLARE_GLOBAL_DATA_PTR; |
| 49 | |
| 50 | #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 51 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 52 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 53 | |
| 54 | #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \ |
| 55 | PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \ |
| 56 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 57 | |
Fabio Estevam | 729bbb8 | 2015-04-29 22:28:10 -0300 | [diff] [blame] | 58 | #define USB_H1_VBUS IMX_GPIO_NR(1, 0) |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 59 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 60 | enum board_type { |
| 61 | CUBOXI = 0x00, |
| 62 | HUMMINGBOARD = 0x01, |
| 63 | HUMMINGBOARD2 = 0x02, |
| 64 | UNKNOWN = 0x03, |
| 65 | }; |
| 66 | |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 67 | static struct gpio_desc board_detect_desc[5]; |
| 68 | |
Jon Nettleton | dfe7fab | 2018-06-07 16:17:37 +0300 | [diff] [blame] | 69 | #define MEM_STRIDE 0x4000000 |
| 70 | static u32 get_ram_size_stride_test(u32 *base, u32 maxsize) |
| 71 | { |
| 72 | volatile u32 *addr; |
| 73 | u32 save[64]; |
| 74 | u32 cnt; |
| 75 | u32 size; |
| 76 | int i = 0; |
| 77 | |
| 78 | /* First save the data */ |
| 79 | for (cnt = 0; cnt < maxsize; cnt += MEM_STRIDE) { |
| 80 | addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */ |
| 81 | sync (); |
| 82 | save[i++] = *addr; |
| 83 | sync (); |
| 84 | } |
| 85 | |
| 86 | /* First write a signature */ |
| 87 | * (volatile u32 *)base = 0x12345678; |
| 88 | for (size = MEM_STRIDE; size < maxsize; size += MEM_STRIDE) { |
| 89 | * (volatile u32 *)((u32)base + size) = size; |
| 90 | sync (); |
| 91 | if (* (volatile u32 *)((u32)base) == size) { /* We reached the overlapping address */ |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* Restore the data */ |
| 97 | for (cnt = (maxsize - MEM_STRIDE); i > 0; cnt -= MEM_STRIDE) { |
| 98 | addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */ |
| 99 | sync (); |
| 100 | *addr = save[i--]; |
| 101 | sync (); |
| 102 | } |
| 103 | |
| 104 | return (size); |
| 105 | } |
| 106 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 107 | int dram_init(void) |
| 108 | { |
Jon Nettleton | dfe7fab | 2018-06-07 16:17:37 +0300 | [diff] [blame] | 109 | u32 max_size = imx_ddr_size(); |
| 110 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 111 | gd->ram_size = get_ram_size_stride_test((u32 *) CFG_SYS_SDRAM_BASE, |
Jon Nettleton | dfe7fab | 2018-06-07 16:17:37 +0300 | [diff] [blame] | 112 | (u32)max_size); |
| 113 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static iomux_v3_cfg_t const uart1_pads[] = { |
Fabio Estevam | 5f402c4 | 2015-04-25 18:47:17 -0300 | [diff] [blame] | 118 | IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 119 | IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static iomux_v3_cfg_t const usdhc2_pads[] = { |
Fabio Estevam | 5f402c4 | 2015-04-25 18:47:17 -0300 | [diff] [blame] | 123 | IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 124 | IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 125 | IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 126 | IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 127 | IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 128 | IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 129 | }; |
| 130 | |
Jon Nettleton | 08d38cb | 2018-06-11 15:26:20 +0300 | [diff] [blame] | 131 | static iomux_v3_cfg_t const usdhc3_pads[] = { |
| 132 | IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 133 | IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 134 | IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 135 | IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 136 | IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 137 | IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 138 | IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 139 | IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 140 | IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 141 | IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 142 | IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)), |
| 143 | }; |
| 144 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 145 | static iomux_v3_cfg_t const board_detect[] = { |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 146 | /* These pins are for sensing if it is a CuBox-i or a HummingBoard */ |
| 147 | IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 148 | IOMUX_PADS(PAD_EIM_DA4__GPIO3_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)), |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 149 | IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 150 | }; |
| 151 | |
| 152 | static iomux_v3_cfg_t const som_rev_detect[] = { |
| 153 | /* These pins are for sensing if it is a CuBox-i or a HummingBoard */ |
| 154 | IOMUX_PADS(PAD_CSI0_DAT14__GPIO6_IO00 | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 155 | IOMUX_PADS(PAD_CSI0_DAT18__GPIO6_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)), |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 156 | }; |
| 157 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 158 | static void setup_iomux_uart(void) |
| 159 | { |
Fabio Estevam | 5f402c4 | 2015-04-25 18:47:17 -0300 | [diff] [blame] | 160 | SETUP_IOMUX_PADS(uart1_pads); |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 161 | } |
| 162 | |
Jon Nettleton | 08d38cb | 2018-06-11 15:26:20 +0300 | [diff] [blame] | 163 | int board_mmc_get_env_dev(int devno) |
| 164 | { |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 165 | return devno; |
Jon Nettleton | 08d38cb | 2018-06-11 15:26:20 +0300 | [diff] [blame] | 166 | } |
| 167 | |
Fabio Estevam | 239fd31 | 2015-04-29 22:28:09 -0300 | [diff] [blame] | 168 | #ifdef CONFIG_VIDEO_IPUV3 |
| 169 | static void do_enable_hdmi(struct display_info_t const *dev) |
| 170 | { |
| 171 | imx_enable_hdmi_phy(); |
| 172 | } |
| 173 | |
| 174 | struct display_info_t const displays[] = { |
| 175 | { |
| 176 | .bus = -1, |
| 177 | .addr = 0, |
| 178 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 179 | .detect = detect_hdmi, |
| 180 | .enable = do_enable_hdmi, |
| 181 | .mode = { |
| 182 | .name = "HDMI", |
| 183 | /* 1024x768@60Hz (VESA)*/ |
| 184 | .refresh = 60, |
| 185 | .xres = 1024, |
| 186 | .yres = 768, |
| 187 | .pixclock = 15384, |
| 188 | .left_margin = 160, |
| 189 | .right_margin = 24, |
| 190 | .upper_margin = 29, |
| 191 | .lower_margin = 3, |
| 192 | .hsync_len = 136, |
| 193 | .vsync_len = 6, |
| 194 | .sync = FB_SYNC_EXT, |
| 195 | .vmode = FB_VMODE_NONINTERLACED |
| 196 | } |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | size_t display_count = ARRAY_SIZE(displays); |
| 201 | |
| 202 | static int setup_display(void) |
| 203 | { |
| 204 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 205 | int reg; |
| 206 | int timeout = 100000; |
| 207 | |
| 208 | enable_ipu_clock(); |
| 209 | imx_setup_hdmi(); |
| 210 | |
| 211 | /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */ |
| 212 | setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN); |
| 213 | |
| 214 | reg = readl(&ccm->analog_pll_video); |
| 215 | reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT; |
| 216 | reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37); |
| 217 | reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT; |
| 218 | reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1); |
| 219 | writel(reg, &ccm->analog_pll_video); |
| 220 | |
| 221 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num); |
| 222 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom); |
| 223 | |
| 224 | reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 225 | writel(reg, &ccm->analog_pll_video); |
| 226 | |
| 227 | while (timeout--) |
| 228 | if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK) |
| 229 | break; |
| 230 | if (timeout < 0) { |
| 231 | printf("Warning: video pll lock timeout!\n"); |
| 232 | return -ETIMEDOUT; |
| 233 | } |
| 234 | |
| 235 | reg = readl(&ccm->analog_pll_video); |
| 236 | reg |= BM_ANADIG_PLL_VIDEO_ENABLE; |
| 237 | reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS; |
| 238 | writel(reg, &ccm->analog_pll_video); |
| 239 | |
| 240 | /* gate ipu1_di0_clk */ |
| 241 | clrbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK); |
| 242 | |
| 243 | /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */ |
| 244 | reg = readl(&ccm->chsccdr); |
| 245 | reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK | |
| 246 | MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK | |
| 247 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK); |
| 248 | reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) | |
| 249 | (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) | |
| 250 | (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
| 251 | writel(reg, &ccm->chsccdr); |
| 252 | |
| 253 | /* enable ipu1_di0_clk */ |
| 254 | setbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 259 | |
Fabio Estevam | 4bc9de5 | 2020-06-18 20:21:20 -0300 | [diff] [blame] | 260 | static int setup_fec(void) |
| 261 | { |
| 262 | struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 263 | int ret; |
| 264 | |
| 265 | ret = enable_fec_anatop_clock(0, ENET_25MHZ); |
| 266 | if (ret) |
| 267 | return ret; |
| 268 | |
| 269 | /* set gpr1[ENET_CLK_SEL] */ |
| 270 | setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 275 | int board_early_init_f(void) |
| 276 | { |
| 277 | setup_iomux_uart(); |
Fabio Estevam | 239fd31 | 2015-04-29 22:28:09 -0300 | [diff] [blame] | 278 | |
Troy Kisky | d64485e | 2023-03-13 14:31:40 -0700 | [diff] [blame] | 279 | if (CONFIG_IS_ENABLED(SATA)) |
| 280 | setup_sata(); |
Fabio Estevam | 4bc9de5 | 2020-06-18 20:21:20 -0300 | [diff] [blame] | 281 | setup_fec(); |
| 282 | |
Fabio Estevam | f82f20c | 2017-09-22 23:45:31 -0300 | [diff] [blame] | 283 | return 0; |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int board_init(void) |
| 287 | { |
Fabio Estevam | f82f20c | 2017-09-22 23:45:31 -0300 | [diff] [blame] | 288 | int ret = 0; |
| 289 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 290 | /* address of boot parameters */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 291 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 292 | |
Fabio Estevam | f82f20c | 2017-09-22 23:45:31 -0300 | [diff] [blame] | 293 | #ifdef CONFIG_VIDEO_IPUV3 |
| 294 | ret = setup_display(); |
| 295 | #endif |
| 296 | |
| 297 | return ret; |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 298 | } |
| 299 | |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 300 | static int request_detect_gpios(void) |
| 301 | { |
| 302 | int node; |
| 303 | int ret; |
| 304 | |
| 305 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, |
| 306 | "solidrun,hummingboard-detect"); |
| 307 | if (node < 0) |
| 308 | return -ENODEV; |
| 309 | |
| 310 | ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node), |
| 311 | "detect-gpios", board_detect_desc, |
| 312 | ARRAY_SIZE(board_detect_desc), GPIOD_IS_IN); |
| 313 | |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | static int free_detect_gpios(void) |
| 318 | { |
| 319 | return gpio_free_list_nodev(board_detect_desc, |
| 320 | ARRAY_SIZE(board_detect_desc)); |
| 321 | } |
| 322 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 323 | static enum board_type board_type(void) |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 324 | { |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 325 | int val1, val2, val3; |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 326 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 327 | SETUP_IOMUX_PADS(board_detect); |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 328 | |
| 329 | /* |
| 330 | * Machine selection - |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 331 | * Machine val1, val2, val3 |
| 332 | * ---------------------------- |
| 333 | * HB2 x x 0 |
| 334 | * HB rev 3.x x 0 x |
| 335 | * CBi 0 1 x |
| 336 | * HB 1 1 x |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 337 | */ |
| 338 | |
Fabio Estevam | 3339d07 | 2024-03-27 08:49:59 -0300 | [diff] [blame^] | 339 | val3 = !!dm_gpio_get_value(&board_detect_desc[0]); |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 340 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 341 | if (val3 == 0) |
| 342 | return HUMMINGBOARD2; |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 343 | |
Fabio Estevam | 3339d07 | 2024-03-27 08:49:59 -0300 | [diff] [blame^] | 344 | val2 = !!dm_gpio_get_value(&board_detect_desc[1]); |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 345 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 346 | if (val2 == 0) |
| 347 | return HUMMINGBOARD; |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 348 | |
Fabio Estevam | 3339d07 | 2024-03-27 08:49:59 -0300 | [diff] [blame^] | 349 | val1 = !!dm_gpio_get_value(&board_detect_desc[2]); |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 350 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 351 | if (val1 == 0) { |
| 352 | return CUBOXI; |
| 353 | } else { |
| 354 | return HUMMINGBOARD; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static bool is_rev_15_som(void) |
| 359 | { |
| 360 | int val1, val2; |
| 361 | SETUP_IOMUX_PADS(som_rev_detect); |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 362 | |
Fabio Estevam | 3339d07 | 2024-03-27 08:49:59 -0300 | [diff] [blame^] | 363 | val1 = !!dm_gpio_get_value(&board_detect_desc[3]); |
| 364 | val2 = !!dm_gpio_get_value(&board_detect_desc[4]); |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 365 | |
| 366 | if (val1 == 1 && val2 == 0) |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 367 | return true; |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 368 | |
| 369 | return false; |
Dennis Gilmore | 52e61ba | 2017-08-24 10:49:43 -0500 | [diff] [blame] | 370 | } |
| 371 | |
Jon Nettleton | 5118211 | 2018-06-11 15:26:22 +0300 | [diff] [blame] | 372 | static bool has_emmc(void) |
| 373 | { |
| 374 | struct mmc *mmc; |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 375 | mmc = find_mmc_device(2); |
Jon Nettleton | 5118211 | 2018-06-11 15:26:22 +0300 | [diff] [blame] | 376 | if (!mmc) |
| 377 | return 0; |
Pali Rohár | 7c63962 | 2021-07-14 16:37:29 +0200 | [diff] [blame] | 378 | return (mmc_get_op_cond(mmc, true) < 0) ? 0 : 1; |
Jon Nettleton | 5118211 | 2018-06-11 15:26:22 +0300 | [diff] [blame] | 379 | } |
| 380 | |
Simon Glass | 55c73c9 | 2023-11-12 19:58:24 -0700 | [diff] [blame] | 381 | /* Override the default implementation, DT model is not accurate */ |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 382 | int checkboard(void) |
| 383 | { |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 384 | request_detect_gpios(); |
| 385 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 386 | switch (board_type()) { |
| 387 | case CUBOXI: |
| 388 | puts("Board: MX6 Cubox-i"); |
| 389 | break; |
| 390 | case HUMMINGBOARD: |
| 391 | puts("Board: MX6 HummingBoard"); |
| 392 | break; |
| 393 | case HUMMINGBOARD2: |
| 394 | puts("Board: MX6 HummingBoard2"); |
| 395 | break; |
| 396 | case UNKNOWN: |
| 397 | default: |
| 398 | puts("Board: Unknown\n"); |
| 399 | goto out; |
| 400 | } |
| 401 | |
| 402 | if (is_rev_15_som()) |
| 403 | puts(" (som rev 1.5)\n"); |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 404 | else |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 405 | puts("\n"); |
Fabio Estevam | 7a2f9cd | 2015-04-25 18:47:19 -0300 | [diff] [blame] | 406 | |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 407 | free_detect_gpios(); |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 408 | out: |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 412 | static int find_ethernet_phy(void) |
| 413 | { |
| 414 | struct mii_dev *bus = NULL; |
| 415 | struct phy_device *phydev = NULL; |
| 416 | int phy_addr = -ENOENT; |
| 417 | |
| 418 | #ifdef CONFIG_FEC_MXC |
| 419 | bus = fec_get_miibus(ENET_BASE_ADDR, -1); |
| 420 | if (!bus) |
| 421 | return -ENOENT; |
| 422 | |
| 423 | // scan address 0, 1, 4 |
| 424 | phydev = phy_find_by_mask(bus, 0b00010011); |
| 425 | if (!phydev) { |
| 426 | free(bus); |
| 427 | return -ENOENT; |
| 428 | } |
| 429 | pr_debug("%s: detected ethernet phy at address %d\n", __func__, phydev->addr); |
| 430 | phy_addr = phydev->addr; |
| 431 | |
| 432 | free(phydev); |
| 433 | #endif |
| 434 | |
| 435 | return phy_addr; |
| 436 | } |
| 437 | |
| 438 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 439 | /* |
| 440 | * Configure the correct ethernet PHYs nodes in device-tree: |
| 441 | * - AR8035 at addresses 0 or 4: Cubox |
| 442 | * - AR8035 at address 0: HummingBoard, HummingBoard 2 |
| 443 | * - ADIN1300 at address 1: since SoM rev 1.9 |
| 444 | */ |
| 445 | int ft_board_setup(void *fdt, struct bd_info *bd) |
| 446 | { |
| 447 | int node_phy0, node_phy1, node_phy4; |
| 448 | int ret, phy; |
| 449 | bool enable_phy0 = false, enable_phy1 = false, enable_phy4 = false; |
Josua Mayer | 5674e4c | 2022-06-16 11:40:15 +0300 | [diff] [blame] | 450 | enum board_type board; |
| 451 | |
| 452 | // detect device |
| 453 | request_detect_gpios(); |
| 454 | board = board_type(); |
| 455 | free_detect_gpios(); |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 456 | |
| 457 | // detect phy |
| 458 | phy = find_ethernet_phy(); |
| 459 | if (phy == 0 || phy == 4) { |
| 460 | enable_phy0 = true; |
Josua Mayer | 5674e4c | 2022-06-16 11:40:15 +0300 | [diff] [blame] | 461 | switch (board) { |
| 462 | case HUMMINGBOARD: |
| 463 | case HUMMINGBOARD2: |
| 464 | /* atheros phy may appear only at address 0 */ |
| 465 | break; |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 466 | case CUBOXI: |
| 467 | case UNKNOWN: |
| 468 | default: |
Josua Mayer | 5674e4c | 2022-06-16 11:40:15 +0300 | [diff] [blame] | 469 | /* atheros phy may appear at either address 0 or 4 */ |
Josua Mayer | 101237a | 2022-05-19 12:31:59 +0300 | [diff] [blame] | 470 | enable_phy4 = true; |
| 471 | } |
| 472 | } else if (phy == 1) { |
| 473 | enable_phy1 = true; |
| 474 | } else { |
| 475 | pr_err("%s: couldn't detect ethernet phy, not patching dtb!\n", __func__); |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | // update all phy nodes status |
| 480 | node_phy0 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@0"); |
| 481 | ret = fdt_setprop_string(fdt, node_phy0, "status", enable_phy0 ? "okay" : "disabled"); |
| 482 | if (ret < 0 && enable_phy0) |
| 483 | pr_err("%s: failed to enable ethernet phy at address 0 in dtb!\n", __func__); |
| 484 | node_phy1 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@1"); |
| 485 | ret = fdt_setprop_string(fdt, node_phy1, "status", enable_phy1 ? "okay" : "disabled"); |
| 486 | if (ret < 0 && enable_phy1) |
| 487 | pr_err("%s: failed to enable ethernet phy at address 1 in dtb!\n", __func__); |
| 488 | node_phy4 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@4"); |
| 489 | ret = fdt_setprop_string(fdt, node_phy4, "status", enable_phy4 ? "okay" : "disabled"); |
| 490 | if (ret < 0 && enable_phy4) |
| 491 | pr_err("%s: failed to enable ethernet phy at address 4 in dtb!\n", __func__); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | #endif |
| 496 | |
Fabio Estevam | 9887c1a | 2015-04-25 18:47:21 -0300 | [diff] [blame] | 497 | int board_late_init(void) |
| 498 | { |
| 499 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 500 | request_detect_gpios(); |
| 501 | |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 502 | switch (board_type()) { |
| 503 | case CUBOXI: |
| 504 | env_set("board_name", "CUBOXI"); |
| 505 | break; |
| 506 | case HUMMINGBOARD: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 507 | env_set("board_name", "HUMMINGBOARD"); |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 508 | break; |
| 509 | case HUMMINGBOARD2: |
| 510 | env_set("board_name", "HUMMINGBOARD2"); |
| 511 | break; |
| 512 | case UNKNOWN: |
| 513 | default: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 514 | env_set("board_name", "CUBOXI"); |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 515 | } |
Fabio Estevam | 9887c1a | 2015-04-25 18:47:21 -0300 | [diff] [blame] | 516 | |
Breno Lima | ba77612 | 2016-07-22 09:11:30 -0300 | [diff] [blame] | 517 | if (is_mx6dq()) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 518 | env_set("board_rev", "MX6Q"); |
Fabio Estevam | 9887c1a | 2015-04-25 18:47:21 -0300 | [diff] [blame] | 519 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 520 | env_set("board_rev", "MX6DL"); |
Jon Nettleton | 30cba09 | 2018-06-07 16:17:36 +0300 | [diff] [blame] | 521 | |
| 522 | if (is_rev_15_som()) |
| 523 | env_set("som_rev", "V15"); |
Jon Nettleton | 5118211 | 2018-06-11 15:26:22 +0300 | [diff] [blame] | 524 | |
| 525 | if (has_emmc()) |
| 526 | env_set("has_emmc", "yes"); |
| 527 | |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 528 | free_detect_gpios(); |
Fabio Estevam | 9887c1a | 2015-04-25 18:47:21 -0300 | [diff] [blame] | 529 | #endif |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Baruch Siach | 6d3f68c | 2019-11-10 14:38:07 +0200 | [diff] [blame] | 534 | /* |
| 535 | * This is not a perfect match. Avoid dependency on the DM GPIO driver needed |
| 536 | * for accurate board detection. Hummingboard2 DT is good enough for U-Boot on |
| 537 | * all Hummingboard/Cubox-i platforms. |
| 538 | */ |
| 539 | int board_fit_config_name_match(const char *name) |
| 540 | { |
| 541 | char tmp_name[36]; |
| 542 | |
| 543 | snprintf(tmp_name, sizeof(tmp_name), "%s-hummingboard2-emmc-som-v15", |
| 544 | is_mx6dq() ? "imx6q" : "imx6dl"); |
| 545 | |
| 546 | return strcmp(name, tmp_name); |
| 547 | } |
| 548 | |
Walter Lozano | f74f7e8 | 2020-05-19 15:24:22 -0300 | [diff] [blame] | 549 | void board_boot_order(u32 *spl_boot_list) |
| 550 | { |
| 551 | struct src *psrc = (struct src *)SRC_BASE_ADDR; |
| 552 | unsigned int reg = readl(&psrc->sbmr1) >> 11; |
| 553 | u32 boot_mode = imx6_src_get_boot_mode() & IMX6_BMODE_MASK; |
| 554 | unsigned int bmode = readl(&src_base->sbmr2); |
| 555 | |
| 556 | /* If bmode is serial or USB phy is active, return serial */ |
| 557 | if (((bmode >> 24) & 0x03) == 0x01 || is_usbotg_phy_active()) { |
| 558 | spl_boot_list[0] = BOOT_DEVICE_BOARD; |
| 559 | return; |
| 560 | } |
| 561 | |
| 562 | switch (boot_mode >> IMX6_BMODE_SHIFT) { |
| 563 | case IMX6_BMODE_SD: |
| 564 | case IMX6_BMODE_ESD: |
| 565 | case IMX6_BMODE_MMC: |
| 566 | case IMX6_BMODE_EMMC: |
| 567 | /* |
| 568 | * Upon reading BOOT_CFG register the following map is done: |
| 569 | * Bit 11 and 12 of BOOT_CFG register can determine the current |
| 570 | * mmc port |
| 571 | * 0x1 SD2 |
| 572 | * 0x2 SD3 |
| 573 | */ |
| 574 | |
| 575 | reg &= 0x3; /* Only care about bottom 2 bits */ |
| 576 | switch (reg) { |
| 577 | case 1: |
| 578 | SETUP_IOMUX_PADS(usdhc2_pads); |
| 579 | spl_boot_list[0] = BOOT_DEVICE_MMC1; |
| 580 | break; |
| 581 | case 2: |
| 582 | SETUP_IOMUX_PADS(usdhc3_pads); |
| 583 | spl_boot_list[0] = BOOT_DEVICE_MMC2; |
| 584 | break; |
| 585 | } |
| 586 | break; |
| 587 | default: |
| 588 | /* By default use USB downloader */ |
| 589 | spl_boot_list[0] = BOOT_DEVICE_BOARD; |
| 590 | break; |
| 591 | } |
| 592 | |
| 593 | /* As a last resort, use serial downloader */ |
| 594 | spl_boot_list[1] = BOOT_DEVICE_BOARD; |
| 595 | } |
| 596 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 597 | #ifdef CONFIG_SPL_BUILD |
Fabio Estevam | 5f402c4 | 2015-04-25 18:47:17 -0300 | [diff] [blame] | 598 | #include <asm/arch/mx6-ddr.h> |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 599 | static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = { |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 600 | .dram_sdclk_0 = 0x00020030, |
| 601 | .dram_sdclk_1 = 0x00020030, |
| 602 | .dram_cas = 0x00020030, |
| 603 | .dram_ras = 0x00020030, |
Jon Nettleton | cd2020d | 2018-04-10 17:05:35 -0300 | [diff] [blame] | 604 | .dram_reset = 0x000c0030, |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 605 | .dram_sdcke0 = 0x00003000, |
| 606 | .dram_sdcke1 = 0x00003000, |
| 607 | .dram_sdba2 = 0x00000000, |
| 608 | .dram_sdodt0 = 0x00003030, |
| 609 | .dram_sdodt1 = 0x00003030, |
| 610 | .dram_sdqs0 = 0x00000030, |
| 611 | .dram_sdqs1 = 0x00000030, |
| 612 | .dram_sdqs2 = 0x00000030, |
| 613 | .dram_sdqs3 = 0x00000030, |
| 614 | .dram_sdqs4 = 0x00000030, |
| 615 | .dram_sdqs5 = 0x00000030, |
| 616 | .dram_sdqs6 = 0x00000030, |
| 617 | .dram_sdqs7 = 0x00000030, |
| 618 | .dram_dqm0 = 0x00020030, |
| 619 | .dram_dqm1 = 0x00020030, |
| 620 | .dram_dqm2 = 0x00020030, |
| 621 | .dram_dqm3 = 0x00020030, |
| 622 | .dram_dqm4 = 0x00020030, |
| 623 | .dram_dqm5 = 0x00020030, |
| 624 | .dram_dqm6 = 0x00020030, |
| 625 | .dram_dqm7 = 0x00020030, |
| 626 | }; |
| 627 | |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 628 | static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = { |
| 629 | .dram_sdclk_0 = 0x00000028, |
| 630 | .dram_sdclk_1 = 0x00000028, |
| 631 | .dram_cas = 0x00000028, |
| 632 | .dram_ras = 0x00000028, |
| 633 | .dram_reset = 0x000c0028, |
| 634 | .dram_sdcke0 = 0x00003000, |
| 635 | .dram_sdcke1 = 0x00003000, |
| 636 | .dram_sdba2 = 0x00000000, |
| 637 | .dram_sdodt0 = 0x00003030, |
| 638 | .dram_sdodt1 = 0x00003030, |
| 639 | .dram_sdqs0 = 0x00000028, |
| 640 | .dram_sdqs1 = 0x00000028, |
| 641 | .dram_sdqs2 = 0x00000028, |
| 642 | .dram_sdqs3 = 0x00000028, |
| 643 | .dram_sdqs4 = 0x00000028, |
| 644 | .dram_sdqs5 = 0x00000028, |
| 645 | .dram_sdqs6 = 0x00000028, |
| 646 | .dram_sdqs7 = 0x00000028, |
| 647 | .dram_dqm0 = 0x00000028, |
| 648 | .dram_dqm1 = 0x00000028, |
| 649 | .dram_dqm2 = 0x00000028, |
| 650 | .dram_dqm3 = 0x00000028, |
| 651 | .dram_dqm4 = 0x00000028, |
| 652 | .dram_dqm5 = 0x00000028, |
| 653 | .dram_dqm6 = 0x00000028, |
| 654 | .dram_dqm7 = 0x00000028, |
| 655 | }; |
| 656 | |
| 657 | static const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = { |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 658 | .grp_ddr_type = 0x000C0000, |
| 659 | .grp_ddrmode_ctl = 0x00020000, |
| 660 | .grp_ddrpke = 0x00000000, |
| 661 | .grp_addds = 0x00000030, |
| 662 | .grp_ctlds = 0x00000030, |
| 663 | .grp_ddrmode = 0x00020000, |
| 664 | .grp_b0ds = 0x00000030, |
| 665 | .grp_b1ds = 0x00000030, |
| 666 | .grp_b2ds = 0x00000030, |
| 667 | .grp_b3ds = 0x00000030, |
| 668 | .grp_b4ds = 0x00000030, |
| 669 | .grp_b5ds = 0x00000030, |
| 670 | .grp_b6ds = 0x00000030, |
| 671 | .grp_b7ds = 0x00000030, |
| 672 | }; |
| 673 | |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 674 | static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = { |
| 675 | .grp_ddr_type = 0x000c0000, |
| 676 | .grp_ddrmode_ctl = 0x00020000, |
| 677 | .grp_ddrpke = 0x00000000, |
| 678 | .grp_addds = 0x00000028, |
| 679 | .grp_ctlds = 0x00000028, |
| 680 | .grp_ddrmode = 0x00020000, |
| 681 | .grp_b0ds = 0x00000028, |
| 682 | .grp_b1ds = 0x00000028, |
| 683 | .grp_b2ds = 0x00000028, |
| 684 | .grp_b3ds = 0x00000028, |
| 685 | .grp_b4ds = 0x00000028, |
| 686 | .grp_b5ds = 0x00000028, |
| 687 | .grp_b6ds = 0x00000028, |
| 688 | .grp_b7ds = 0x00000028, |
| 689 | }; |
| 690 | |
| 691 | /* microSOM with Dual processor and 1GB memory */ |
| 692 | static const struct mx6_mmdc_calibration mx6q_1g_mmcd_calib = { |
| 693 | .p0_mpwldectrl0 = 0x00000000, |
| 694 | .p0_mpwldectrl1 = 0x00000000, |
| 695 | .p1_mpwldectrl0 = 0x00000000, |
| 696 | .p1_mpwldectrl1 = 0x00000000, |
| 697 | .p0_mpdgctrl0 = 0x0314031c, |
| 698 | .p0_mpdgctrl1 = 0x023e0304, |
| 699 | .p1_mpdgctrl0 = 0x03240330, |
| 700 | .p1_mpdgctrl1 = 0x03180260, |
| 701 | .p0_mprddlctl = 0x3630323c, |
| 702 | .p1_mprddlctl = 0x3436283a, |
| 703 | .p0_mpwrdlctl = 0x36344038, |
| 704 | .p1_mpwrdlctl = 0x422a423c, |
| 705 | }; |
| 706 | |
| 707 | /* microSOM with Quad processor and 2GB memory */ |
| 708 | static const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = { |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 709 | .p0_mpwldectrl0 = 0x00000000, |
| 710 | .p0_mpwldectrl1 = 0x00000000, |
| 711 | .p1_mpwldectrl0 = 0x00000000, |
| 712 | .p1_mpwldectrl1 = 0x00000000, |
| 713 | .p0_mpdgctrl0 = 0x0314031c, |
| 714 | .p0_mpdgctrl1 = 0x023e0304, |
| 715 | .p1_mpdgctrl0 = 0x03240330, |
| 716 | .p1_mpdgctrl1 = 0x03180260, |
| 717 | .p0_mprddlctl = 0x3630323c, |
| 718 | .p1_mprddlctl = 0x3436283a, |
| 719 | .p0_mpwrdlctl = 0x36344038, |
| 720 | .p1_mpwrdlctl = 0x422a423c, |
| 721 | }; |
| 722 | |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 723 | /* microSOM with Solo processor and 512MB memory */ |
| 724 | static const struct mx6_mmdc_calibration mx6dl_512m_mmcd_calib = { |
| 725 | .p0_mpwldectrl0 = 0x0045004D, |
| 726 | .p0_mpwldectrl1 = 0x003A0047, |
| 727 | .p0_mpdgctrl0 = 0x023C0224, |
| 728 | .p0_mpdgctrl1 = 0x02000220, |
| 729 | .p0_mprddlctl = 0x44444846, |
| 730 | .p0_mpwrdlctl = 0x32343032, |
| 731 | }; |
| 732 | |
| 733 | /* microSOM with Dual lite processor and 1GB memory */ |
| 734 | static const struct mx6_mmdc_calibration mx6dl_1g_mmcd_calib = { |
| 735 | .p0_mpwldectrl0 = 0x0045004D, |
| 736 | .p0_mpwldectrl1 = 0x003A0047, |
| 737 | .p1_mpwldectrl0 = 0x001F001F, |
| 738 | .p1_mpwldectrl1 = 0x00210035, |
| 739 | .p0_mpdgctrl0 = 0x023C0224, |
| 740 | .p0_mpdgctrl1 = 0x02000220, |
| 741 | .p1_mpdgctrl0 = 0x02200220, |
Fabio Estevam | 4461e1e | 2015-05-29 13:00:36 -0300 | [diff] [blame] | 742 | .p1_mpdgctrl1 = 0x02040208, |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 743 | .p0_mprddlctl = 0x44444846, |
| 744 | .p1_mprddlctl = 0x4042463C, |
| 745 | .p0_mpwrdlctl = 0x32343032, |
| 746 | .p1_mpwrdlctl = 0x36363430, |
| 747 | }; |
| 748 | |
| 749 | static struct mx6_ddr3_cfg mem_ddr_2g = { |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 750 | .mem_speed = 1600, |
| 751 | .density = 2, |
| 752 | .width = 16, |
| 753 | .banks = 8, |
| 754 | .rowaddr = 14, |
| 755 | .coladdr = 10, |
| 756 | .pagesz = 2, |
| 757 | .trcd = 1375, |
| 758 | .trcmin = 4875, |
| 759 | .trasmin = 3500, |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 760 | }; |
| 761 | |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 762 | static struct mx6_ddr3_cfg mem_ddr_4g = { |
| 763 | .mem_speed = 1600, |
| 764 | .density = 4, |
| 765 | .width = 16, |
| 766 | .banks = 8, |
Jon Nettleton | dfe7fab | 2018-06-07 16:17:37 +0300 | [diff] [blame] | 767 | .rowaddr = 16, |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 768 | .coladdr = 10, |
| 769 | .pagesz = 2, |
| 770 | .trcd = 1375, |
| 771 | .trcmin = 4875, |
| 772 | .trasmin = 3500, |
| 773 | }; |
| 774 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 775 | static void ccgr_init(void) |
| 776 | { |
| 777 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 778 | |
| 779 | writel(0x00C03F3F, &ccm->CCGR0); |
| 780 | writel(0x0030FC03, &ccm->CCGR1); |
| 781 | writel(0x0FFFC000, &ccm->CCGR2); |
| 782 | writel(0x3FF00000, &ccm->CCGR3); |
| 783 | writel(0x00FFF300, &ccm->CCGR4); |
| 784 | writel(0x0F0000C3, &ccm->CCGR5); |
| 785 | writel(0x000003FF, &ccm->CCGR6); |
| 786 | } |
| 787 | |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 788 | static void spl_dram_init(int width) |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 789 | { |
| 790 | struct mx6_ddr_sysinfo sysinfo = { |
| 791 | /* width of data bus: 0=16, 1=32, 2=64 */ |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 792 | .dsize = width / 32, |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 793 | /* config for full 4GB range so that get_mem_size() works */ |
| 794 | .cs_density = 32, /* 32Gb per CS */ |
| 795 | .ncs = 1, /* single chip select */ |
| 796 | .cs1_mirror = 0, |
| 797 | .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */ |
| 798 | .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */ |
| 799 | .walat = 1, /* Write additional latency */ |
| 800 | .ralat = 5, /* Read additional latency */ |
| 801 | .mif3_mode = 3, /* Command prediction working mode */ |
| 802 | .bi_on = 1, /* Bank interleaving enabled */ |
| 803 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 804 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
Peng Fan | 77e8695 | 2015-08-17 16:11:03 +0800 | [diff] [blame] | 805 | .ddr_type = DDR_TYPE_DDR3, |
Fabio Estevam | cb3c121 | 2016-08-29 20:37:15 -0300 | [diff] [blame] | 806 | .refsel = 1, /* Refresh cycles at 32KHz */ |
| 807 | .refr = 7, /* 8 refresh commands per refresh cycle */ |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 808 | }; |
| 809 | |
Breno Lima | ba77612 | 2016-07-22 09:11:30 -0300 | [diff] [blame] | 810 | if (is_mx6dq()) |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 811 | mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs); |
| 812 | else |
| 813 | mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs); |
| 814 | |
| 815 | if (is_cpu_type(MXC_CPU_MX6D)) |
| 816 | mx6_dram_cfg(&sysinfo, &mx6q_1g_mmcd_calib, &mem_ddr_2g); |
| 817 | else if (is_cpu_type(MXC_CPU_MX6Q)) |
| 818 | mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g); |
| 819 | else if (is_cpu_type(MXC_CPU_MX6DL)) |
Fabio Estevam | 4461e1e | 2015-05-29 13:00:36 -0300 | [diff] [blame] | 820 | mx6_dram_cfg(&sysinfo, &mx6dl_1g_mmcd_calib, &mem_ddr_2g); |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 821 | else if (is_cpu_type(MXC_CPU_MX6SOLO)) |
| 822 | mx6_dram_cfg(&sysinfo, &mx6dl_512m_mmcd_calib, &mem_ddr_2g); |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | void board_init_f(ulong dummy) |
| 826 | { |
| 827 | /* setup AIPS and disable watchdog */ |
| 828 | arch_cpu_init(); |
| 829 | |
| 830 | ccgr_init(); |
| 831 | gpr_init(); |
| 832 | |
| 833 | /* iomux and setup of i2c */ |
| 834 | board_early_init_f(); |
| 835 | |
| 836 | /* setup GP timer */ |
| 837 | timer_init(); |
| 838 | |
Baruch Siach | ad5944d | 2022-11-03 18:03:38 +0200 | [diff] [blame] | 839 | /* Enable device tree and early DM support*/ |
| 840 | spl_early_init(); |
| 841 | |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 842 | /* UART clocks enabled and gd valid - init serial console */ |
| 843 | preloader_console_init(); |
| 844 | |
| 845 | /* DDR initialization */ |
Fabio Estevam | cb60191 | 2015-04-25 18:47:18 -0300 | [diff] [blame] | 846 | if (is_cpu_type(MXC_CPU_MX6SOLO)) |
| 847 | spl_dram_init(32); |
| 848 | else |
| 849 | spl_dram_init(64); |
Fabio Estevam | 1d97a59 | 2015-04-20 14:48:57 -0300 | [diff] [blame] | 850 | |
| 851 | /* Clear the BSS. */ |
| 852 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 853 | |
| 854 | /* load/boot image from boot device */ |
| 855 | board_init_r(NULL, 0); |
| 856 | } |
| 857 | #endif |