Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Soeren Moch <smoch@web.de> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 6 | #include <init.h> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx-regs.h> |
| 9 | #include <asm/arch/iomux.h> |
| 10 | #include <asm/arch/mx6-pins.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 12 | #include <linux/errno.h> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 13 | #include <asm/gpio.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 14 | #include <asm/mach-imx/iomux-v3.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 15 | #include <asm/mach-imx/boot_mode.h> |
| 16 | #include <asm/mach-imx/video.h> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 17 | #include <mmc.h> |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 18 | #include <fsl_esdhc_imx.h> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 19 | #include <asm/arch/mxc_hdmi.h> |
| 20 | #include <asm/arch/crm_regs.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/arch/sys_proto.h> |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 25 | int dram_init(void) |
| 26 | { |
| 27 | gd->ram_size = 2048ul * 1024 * 1024; |
| 28 | return 0; |
| 29 | } |
| 30 | |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 31 | #ifdef CONFIG_FSL_ESDHC_IMX |
Soeren Moch | a668436 | 2016-02-04 14:41:16 +0100 | [diff] [blame] | 32 | /* set environment device to boot device when booting from SD */ |
| 33 | int board_mmc_get_env_dev(int devno) |
| 34 | { |
| 35 | return devno - 1; |
| 36 | } |
| 37 | |
| 38 | int board_mmc_get_env_part(int devno) |
| 39 | { |
| 40 | return (devno == 3) ? 1 : 0; /* part 0 for SD2 / SD3, part 1 for eMMC */ |
| 41 | } |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 42 | #endif /* CONFIG_FSL_ESDHC_IMX */ |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 43 | |
| 44 | #ifdef CONFIG_VIDEO_IPUV3 |
| 45 | static void do_enable_hdmi(struct display_info_t const *dev) |
| 46 | { |
| 47 | imx_enable_hdmi_phy(); |
| 48 | } |
| 49 | |
| 50 | struct display_info_t const displays[] = {{ |
| 51 | .bus = -1, |
| 52 | .addr = 0, |
| 53 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 54 | .detect = detect_hdmi, |
| 55 | .enable = do_enable_hdmi, |
| 56 | .mode = { |
| 57 | .name = "HDMI", |
| 58 | /* 1024x768@60Hz (VESA)*/ |
| 59 | .refresh = 60, |
| 60 | .xres = 1024, |
| 61 | .yres = 768, |
| 62 | .pixclock = 15384, |
| 63 | .left_margin = 160, |
| 64 | .right_margin = 24, |
| 65 | .upper_margin = 29, |
| 66 | .lower_margin = 3, |
| 67 | .hsync_len = 136, |
| 68 | .vsync_len = 6, |
| 69 | .sync = FB_SYNC_EXT, |
| 70 | .vmode = FB_VMODE_NONINTERLACED |
| 71 | } } }; |
| 72 | size_t display_count = ARRAY_SIZE(displays); |
| 73 | |
| 74 | static void setup_display(void) |
| 75 | { |
| 76 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 77 | int reg; |
| 78 | s32 timeout = 100000; |
| 79 | |
| 80 | enable_ipu_clock(); |
| 81 | imx_setup_hdmi(); |
| 82 | |
| 83 | /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */ |
| 84 | reg = readl(&ccm->analog_pll_video); |
| 85 | reg |= BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 86 | writel(reg, &ccm->analog_pll_video); |
| 87 | |
| 88 | reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT; |
| 89 | reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37); |
| 90 | reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT; |
| 91 | reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1); |
| 92 | writel(reg, &ccm->analog_pll_video); |
| 93 | |
| 94 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num); |
| 95 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom); |
| 96 | |
| 97 | reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN; |
| 98 | writel(reg, &ccm->analog_pll_video); |
| 99 | |
| 100 | while (timeout--) |
| 101 | if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK) |
| 102 | break; |
| 103 | if (timeout < 0) |
| 104 | printf("Warning: video pll lock timeout!\n"); |
| 105 | |
| 106 | reg = readl(&ccm->analog_pll_video); |
| 107 | reg |= BM_ANADIG_PLL_VIDEO_ENABLE; |
| 108 | reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS; |
| 109 | writel(reg, &ccm->analog_pll_video); |
| 110 | |
Soeren Moch | 5df3d19 | 2015-01-23 19:03:37 +0100 | [diff] [blame] | 111 | /* gate ipu1_di0_clk */ |
| 112 | reg = readl(&ccm->CCGR3); |
| 113 | reg &= ~MXC_CCM_CCGR3_LDB_DI0_MASK; |
| 114 | writel(reg, &ccm->CCGR3); |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 115 | |
Soeren Moch | 5df3d19 | 2015-01-23 19:03:37 +0100 | [diff] [blame] | 116 | /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */ |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 117 | reg = readl(&ccm->chsccdr); |
Soeren Moch | 5df3d19 | 2015-01-23 19:03:37 +0100 | [diff] [blame] | 118 | reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK | |
| 119 | MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK | |
| 120 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK); |
| 121 | reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) | |
| 122 | (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) | |
| 123 | (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 124 | writel(reg, &ccm->chsccdr); |
Soeren Moch | 5df3d19 | 2015-01-23 19:03:37 +0100 | [diff] [blame] | 125 | |
| 126 | /* enable ipu1_di0_clk */ |
| 127 | reg = readl(&ccm->CCGR3); |
| 128 | reg |= MXC_CCM_CCGR3_LDB_DI0_MASK; |
| 129 | writel(reg, &ccm->CCGR3); |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 130 | } |
| 131 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 132 | |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 133 | #ifdef CONFIG_CMD_BMODE |
| 134 | static const struct boot_mode board_boot_modes[] = { |
| 135 | /* 4 bit bus width */ |
| 136 | {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 137 | {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 138 | /* 8 bit bus width */ |
Soeren Moch | b112b00 | 2016-02-09 16:53:27 +0100 | [diff] [blame] | 139 | {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)}, |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 140 | {NULL, 0}, |
| 141 | }; |
| 142 | #endif |
| 143 | |
| 144 | int board_init(void) |
| 145 | { |
| 146 | /* address of boot parameters */ |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 147 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 148 | |
| 149 | #ifdef CONFIG_VIDEO_IPUV3 |
| 150 | setup_display(); |
| 151 | #endif |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 152 | #ifdef CONFIG_CMD_BMODE |
| 153 | add_board_boot_modes(board_boot_modes); |
| 154 | #endif |
Soeren Moch | 05d492a | 2014-11-03 13:57:01 +0100 | [diff] [blame] | 155 | return 0; |
| 156 | } |