Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010-2013 Freescale Semiconductor, Inc. |
| 4 | * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com> |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 5 | * Copyright (C) 2014-2019, Toradex AG |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 6 | * copied from nitrogen6x |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 18 | |
Marcel Ziswiler | d8f7838 | 2019-02-08 18:12:14 +0100 | [diff] [blame] | 19 | #include <ahci.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 20 | #include <asm/arch/clock.h> |
| 21 | #include <asm/arch/crm_regs.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 22 | #include <asm/arch/imx-regs.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 23 | #include <asm/arch/mx6-ddr.h> |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 24 | #include <asm/arch/mx6-pins.h> |
| 25 | #include <asm/arch/mxc_hdmi.h> |
| 26 | #include <asm/arch/sys_proto.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 27 | #include <asm/bootm.h> |
| 28 | #include <asm/gpio.h> |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 29 | #include <asm/mach-imx/boot_mode.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 30 | #include <asm/mach-imx/iomux-v3.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 31 | #include <asm/mach-imx/sata.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 32 | #include <asm/mach-imx/video.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 33 | #include <asm/sections.h> |
Marcel Ziswiler | d8f7838 | 2019-02-08 18:12:14 +0100 | [diff] [blame] | 34 | #include <dm/device-internal.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 35 | #include <dm/platform_data/serial_mxc.h> |
Marcel Ziswiler | d8f7838 | 2019-02-08 18:12:14 +0100 | [diff] [blame] | 36 | #include <dwc_ahsata.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 37 | #include <env.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 38 | #include <fsl_esdhc_imx.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 39 | #include <imx_thermal.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 40 | #include <micrel.h> |
| 41 | #include <miiphy.h> |
| 42 | #include <netdev.h> |
| 43 | |
| 44 | #include "../common/tdx-cfg-block.h" |
| 45 | #ifdef CONFIG_TDX_CMD_IMX_MFGR |
| 46 | #include "pf0100.h" |
| 47 | #endif |
| 48 | |
| 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
| 51 | #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 52 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 53 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 54 | |
| 55 | #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \ |
Max Krummenacher | b685d20 | 2019-02-08 18:12:19 +0100 | [diff] [blame] | 56 | PAD_CTL_SPEED_LOW | PAD_CTL_DSE_40ohm | \ |
| 57 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 58 | |
| 59 | #define USDHC_EMMC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 60 | PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \ |
| 61 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 62 | |
| 63 | #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 64 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS) |
| 65 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 66 | #define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \ |
| 67 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \ |
| 68 | PAD_CTL_SRE_SLOW) |
| 69 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 70 | #define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \ |
| 71 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 72 | PAD_CTL_HYS | PAD_CTL_SRE_SLOW) |
| 73 | |
| 74 | #define TRISTATE (PAD_CTL_HYS | PAD_CTL_SPEED_MED) |
| 75 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 76 | #define OUTPUT_RGB (PAD_CTL_SPEED_MED|PAD_CTL_DSE_60ohm|PAD_CTL_SRE_FAST) |
| 77 | |
Marcel Ziswiler | d8f7838 | 2019-02-08 18:12:14 +0100 | [diff] [blame] | 78 | #define APALIS_IMX6_SATA_INIT_RETRIES 10 |
| 79 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 80 | int dram_init(void) |
| 81 | { |
| 82 | /* use the DDR controllers configured size */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 83 | gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 84 | (ulong)imx_ddr_size()); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* Apalis UART1 */ |
| 90 | iomux_v3_cfg_t const uart1_pads_dce[] = { |
| 91 | MX6_PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 92 | MX6_PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 93 | }; |
| 94 | iomux_v3_cfg_t const uart1_pads_dte[] = { |
| 95 | MX6_PAD_CSI0_DAT10__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 96 | MX6_PAD_CSI0_DAT11__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 97 | }; |
| 98 | |
Ricardo Salveti | 81d1e61 | 2019-09-02 18:12:02 -0300 | [diff] [blame] | 99 | #if defined(CONFIG_FSL_ESDHC_IMX) && defined(CONFIG_SPL_BUILD) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 100 | /* Apalis MMC1 */ |
| 101 | iomux_v3_cfg_t const usdhc1_pads[] = { |
| 102 | MX6_PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 103 | MX6_PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 104 | MX6_PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 105 | MX6_PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 106 | MX6_PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 107 | MX6_PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 108 | MX6_PAD_NANDF_D0__SD1_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 109 | MX6_PAD_NANDF_D1__SD1_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 110 | MX6_PAD_NANDF_D2__SD1_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 111 | MX6_PAD_NANDF_D3__SD1_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 112 | MX6_PAD_DI0_PIN4__GPIO4_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */ |
| 113 | # define GPIO_MMC_CD IMX_GPIO_NR(4, 20) |
| 114 | }; |
| 115 | |
| 116 | /* Apalis SD1 */ |
| 117 | iomux_v3_cfg_t const usdhc2_pads[] = { |
| 118 | MX6_PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 119 | MX6_PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 120 | MX6_PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 121 | MX6_PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 122 | MX6_PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 123 | MX6_PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 124 | MX6_PAD_NANDF_CS1__GPIO6_IO14 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */ |
| 125 | # define GPIO_SD_CD IMX_GPIO_NR(6, 14) |
| 126 | }; |
| 127 | |
| 128 | /* eMMC */ |
| 129 | iomux_v3_cfg_t const usdhc3_pads[] = { |
Max Krummenacher | b685d20 | 2019-02-08 18:12:19 +0100 | [diff] [blame] | 130 | MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 131 | MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 132 | MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 133 | MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 134 | MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 135 | MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 136 | MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 137 | MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 138 | MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
| 139 | MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL), |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 140 | MX6_PAD_SD3_RST__GPIO7_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 141 | }; |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 142 | #endif /* CONFIG_FSL_ESDHC_IMX & CONFIG_SPL_BUILD */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 143 | |
| 144 | int mx6_rgmii_rework(struct phy_device *phydev) |
| 145 | { |
Philippe Schenker | 2242ad5 | 2020-03-11 11:59:26 +0100 | [diff] [blame] | 146 | int tmp; |
| 147 | |
| 148 | switch (ksz9xx1_phy_get_id(phydev) & MII_KSZ9x31_SILICON_REV_MASK) { |
| 149 | case PHY_ID_KSZ9131: |
| 150 | /* read rxc dll control - devaddr = 0x02, register = 0x4c */ |
| 151 | tmp = ksz9031_phy_extended_read(phydev, 0x02, |
| 152 | MII_KSZ9131_EXT_RGMII_2NS_SKEW_RXDLL, |
| 153 | MII_KSZ9031_MOD_DATA_NO_POST_INC); |
| 154 | /* disable rxdll bypass (enable 2ns skew delay on RXC) */ |
| 155 | tmp &= ~MII_KSZ9131_RXTXDLL_BYPASS; |
| 156 | /* rxc data pad skew 2ns - devaddr = 0x02, register = 0x4c */ |
| 157 | ksz9031_phy_extended_write(phydev, 0x02, |
| 158 | MII_KSZ9131_EXT_RGMII_2NS_SKEW_RXDLL, |
| 159 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 160 | tmp); |
| 161 | /* read txc dll control - devaddr = 0x02, register = 0x4d */ |
| 162 | tmp = ksz9031_phy_extended_read(phydev, 0x02, |
| 163 | MII_KSZ9131_EXT_RGMII_2NS_SKEW_TXDLL, |
| 164 | MII_KSZ9031_MOD_DATA_NO_POST_INC); |
| 165 | /* disable rxdll bypass (enable 2ns skew delay on TXC) */ |
| 166 | tmp &= ~MII_KSZ9131_RXTXDLL_BYPASS; |
| 167 | /* txc data pad skew 2ns - devaddr = 0x02, register = 0x4d */ |
| 168 | ksz9031_phy_extended_write(phydev, 0x02, |
| 169 | MII_KSZ9131_EXT_RGMII_2NS_SKEW_TXDLL, |
| 170 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 171 | tmp); |
| 172 | |
| 173 | /* control data pad skew - devaddr = 0x02, register = 0x04 */ |
| 174 | ksz9031_phy_extended_write(phydev, 0x02, |
| 175 | MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, |
| 176 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 177 | 0x007d); |
| 178 | /* rx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 179 | ksz9031_phy_extended_write(phydev, 0x02, |
| 180 | MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, |
| 181 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 182 | 0x7777); |
| 183 | /* tx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 184 | ksz9031_phy_extended_write(phydev, 0x02, |
| 185 | MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, |
| 186 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 187 | 0xdddd); |
| 188 | /* gtx and rx clock pad skew - devaddr = 0x02,register = 0x08 */ |
| 189 | ksz9031_phy_extended_write(phydev, 0x02, |
| 190 | MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, |
| 191 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 192 | 0x0007); |
| 193 | break; |
| 194 | case PHY_ID_KSZ9031: |
| 195 | default: |
| 196 | /* control data pad skew - devaddr = 0x02, register = 0x04 */ |
| 197 | ksz9031_phy_extended_write(phydev, 0x02, |
| 198 | MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, |
| 199 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 200 | 0x0000); |
| 201 | /* rx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 202 | ksz9031_phy_extended_write(phydev, 0x02, |
| 203 | MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, |
| 204 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 205 | 0x0000); |
| 206 | /* tx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 207 | ksz9031_phy_extended_write(phydev, 0x02, |
| 208 | MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, |
| 209 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 210 | 0x0000); |
| 211 | /* gtx and rx clock pad skew - devaddr = 0x02,register = 0x08 */ |
| 212 | ksz9031_phy_extended_write(phydev, 0x02, |
| 213 | MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, |
| 214 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 215 | 0x03FF); |
| 216 | break; |
| 217 | } |
| 218 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | iomux_v3_cfg_t const enet_pads[] = { |
| 223 | MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 224 | MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 225 | MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 226 | MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 227 | MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 228 | MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 229 | MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 230 | MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 231 | MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 232 | MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 233 | MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 234 | MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 235 | MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 236 | MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 237 | MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 238 | /* KSZ9031 PHY Reset */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 239 | MX6_PAD_ENET_CRS_DV__GPIO1_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL) | |
| 240 | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 241 | # define GPIO_ENET_PHY_RESET IMX_GPIO_NR(1, 25) |
| 242 | }; |
| 243 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 244 | /* mux the Apalis GPIO pins, so they can be used from the U-Boot cmdline */ |
| 245 | iomux_v3_cfg_t const gpio_pads[] = { |
| 246 | /* Apalis GPIO1 - GPIO8 */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 247 | MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 248 | MUX_MODE_SION, |
| 249 | MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 250 | MUX_MODE_SION, |
| 251 | MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 252 | MUX_MODE_SION, |
| 253 | MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 254 | MUX_MODE_SION, |
| 255 | MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 256 | MUX_MODE_SION, |
| 257 | MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 258 | MUX_MODE_SION, |
| 259 | MX6_PAD_GPIO_2__GPIO1_IO02 | MUX_PAD_CTRL(WEAK_PULLDOWN) | |
| 260 | MUX_MODE_SION, |
| 261 | MX6_PAD_GPIO_6__GPIO1_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 262 | MUX_MODE_SION, |
| 263 | MX6_PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) | |
| 264 | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | static void setup_iomux_gpio(void) |
| 268 | { |
| 269 | imx_iomux_v3_setup_multiple_pads(gpio_pads, ARRAY_SIZE(gpio_pads)); |
| 270 | } |
| 271 | |
| 272 | iomux_v3_cfg_t const usb_pads[] = { |
| 273 | /* USBH_EN */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 274 | MX6_PAD_GPIO_0__GPIO1_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 275 | # define GPIO_USBH_EN IMX_GPIO_NR(1, 0) |
| 276 | /* USB_VBUS_DET */ |
| 277 | MX6_PAD_EIM_D28__GPIO3_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 278 | # define GPIO_USB_VBUS_DET IMX_GPIO_NR(3, 28) |
| 279 | /* USBO1_ID */ |
| 280 | MX6_PAD_ENET_RX_ER__USB_OTG_ID | MUX_PAD_CTRL(WEAK_PULLUP), |
| 281 | /* USBO1_EN */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 282 | MX6_PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 283 | # define GPIO_USBO_EN IMX_GPIO_NR(3, 22) |
| 284 | }; |
| 285 | |
| 286 | /* |
| 287 | * UARTs are used in DTE mode, switch the mode on all UARTs before |
| 288 | * any pinmuxing connects a (DCE) output to a transceiver output. |
| 289 | */ |
Max Krummenacher | baeabe0 | 2019-02-08 18:12:21 +0100 | [diff] [blame] | 290 | #define UCR3 0x88 /* FIFO Control Register */ |
| 291 | #define UCR3_RI BIT(8) /* RIDELT DTE mode */ |
| 292 | #define UCR3_DCD BIT(9) /* DCDDELT DTE mode */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 293 | #define UFCR 0x90 /* FIFO Control Register */ |
Max Krummenacher | baeabe0 | 2019-02-08 18:12:21 +0100 | [diff] [blame] | 294 | #define UFCR_DCEDTE BIT(6) /* DCE=0 */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 295 | |
| 296 | static void setup_dtemode_uart(void) |
| 297 | { |
| 298 | setbits_le32((u32 *)(UART1_BASE + UFCR), UFCR_DCEDTE); |
| 299 | setbits_le32((u32 *)(UART2_BASE + UFCR), UFCR_DCEDTE); |
| 300 | setbits_le32((u32 *)(UART4_BASE + UFCR), UFCR_DCEDTE); |
| 301 | setbits_le32((u32 *)(UART5_BASE + UFCR), UFCR_DCEDTE); |
Max Krummenacher | baeabe0 | 2019-02-08 18:12:21 +0100 | [diff] [blame] | 302 | |
| 303 | clrbits_le32((u32 *)(UART1_BASE + UCR3), UCR3_DCD | UCR3_RI); |
| 304 | clrbits_le32((u32 *)(UART2_BASE + UCR3), UCR3_DCD | UCR3_RI); |
| 305 | clrbits_le32((u32 *)(UART4_BASE + UCR3), UCR3_DCD | UCR3_RI); |
| 306 | clrbits_le32((u32 *)(UART5_BASE + UCR3), UCR3_DCD | UCR3_RI); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 307 | } |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 308 | |
| 309 | static void setup_iomux_dte_uart(void) |
| 310 | { |
| 311 | setup_dtemode_uart(); |
| 312 | imx_iomux_v3_setup_multiple_pads(uart1_pads_dte, |
| 313 | ARRAY_SIZE(uart1_pads_dte)); |
| 314 | } |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 315 | |
| 316 | #ifdef CONFIG_USB_EHCI_MX6 |
| 317 | int board_ehci_hcd_init(int port) |
| 318 | { |
| 319 | imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads)); |
| 320 | return 0; |
| 321 | } |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 322 | #endif |
| 323 | |
Ricardo Salveti | 81d1e61 | 2019-09-02 18:12:02 -0300 | [diff] [blame] | 324 | #if defined(CONFIG_FSL_ESDHC_IMX) && defined(CONFIG_SPL_BUILD) |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 325 | /* use the following sequence: eMMC, MMC1, SD1 */ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 326 | struct fsl_esdhc_cfg usdhc_cfg[CFG_SYS_FSL_USDHC_NUM] = { |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 327 | {USDHC3_BASE_ADDR}, |
| 328 | {USDHC1_BASE_ADDR}, |
| 329 | {USDHC2_BASE_ADDR}, |
| 330 | }; |
| 331 | |
| 332 | int board_mmc_getcd(struct mmc *mmc) |
| 333 | { |
| 334 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 335 | int ret = true; /* default: assume inserted */ |
| 336 | |
| 337 | switch (cfg->esdhc_base) { |
| 338 | case USDHC1_BASE_ADDR: |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 339 | gpio_request(GPIO_MMC_CD, "MMC_CD"); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 340 | gpio_direction_input(GPIO_MMC_CD); |
| 341 | ret = !gpio_get_value(GPIO_MMC_CD); |
| 342 | break; |
| 343 | case USDHC2_BASE_ADDR: |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 344 | gpio_request(GPIO_MMC_CD, "SD_CD"); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 345 | gpio_direction_input(GPIO_SD_CD); |
| 346 | ret = !gpio_get_value(GPIO_SD_CD); |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | return ret; |
| 351 | } |
| 352 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 353 | int board_mmc_init(struct bd_info *bis) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 354 | { |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 355 | struct src *psrc = (struct src *)SRC_BASE_ADDR; |
| 356 | unsigned reg = readl(&psrc->sbmr1) >> 11; |
| 357 | /* |
| 358 | * Upon reading BOOT_CFG register the following map is done: |
| 359 | * Bit 11 and 12 of BOOT_CFG register can determine the current |
| 360 | * mmc port |
| 361 | * 0x1 SD1 |
| 362 | * 0x2 SD2 |
| 363 | * 0x3 SD4 |
| 364 | */ |
| 365 | |
| 366 | switch (reg & 0x3) { |
| 367 | case 0x0: |
| 368 | imx_iomux_v3_setup_multiple_pads( |
| 369 | usdhc1_pads, ARRAY_SIZE(usdhc1_pads)); |
| 370 | usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR; |
| 371 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 372 | gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk; |
| 373 | break; |
| 374 | case 0x1: |
| 375 | imx_iomux_v3_setup_multiple_pads( |
| 376 | usdhc2_pads, ARRAY_SIZE(usdhc2_pads)); |
| 377 | usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR; |
| 378 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 379 | gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk; |
| 380 | break; |
| 381 | case 0x2: |
| 382 | imx_iomux_v3_setup_multiple_pads( |
| 383 | usdhc3_pads, ARRAY_SIZE(usdhc3_pads)); |
| 384 | usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR; |
| 385 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
| 386 | gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk; |
| 387 | break; |
| 388 | default: |
| 389 | puts("MMC boot device not available"); |
| 390 | } |
| 391 | |
| 392 | return fsl_esdhc_initialize(bis, &usdhc_cfg[0]); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 393 | } |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 394 | #endif /* CONFIG_FSL_ESDHC_IMX & CONFIG_SPL_BUILD */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 395 | |
| 396 | int board_phy_config(struct phy_device *phydev) |
| 397 | { |
| 398 | mx6_rgmii_rework(phydev); |
| 399 | if (phydev->drv->config) |
| 400 | phydev->drv->config(phydev); |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 405 | static iomux_v3_cfg_t const pwr_intb_pads[] = { |
| 406 | /* |
| 407 | * the bootrom sets the iomux to vselect, potentially connecting |
| 408 | * two outputs. Set this back to GPIO |
| 409 | */ |
| 410 | MX6_PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL) |
| 411 | }; |
| 412 | |
| 413 | #if defined(CONFIG_VIDEO_IPUV3) |
| 414 | |
| 415 | static iomux_v3_cfg_t const backlight_pads[] = { |
| 416 | /* Backlight on RGB connector: J15 */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 417 | MX6_PAD_EIM_DA13__GPIO3_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL) | |
| 418 | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 419 | #define RGB_BACKLIGHT_GP IMX_GPIO_NR(3, 13) |
| 420 | /* additional CPU pin on BKL_PWM, keep in tristate */ |
| 421 | MX6_PAD_EIM_DA14__GPIO3_IO14 | MUX_PAD_CTRL(TRISTATE), |
| 422 | /* Backlight PWM, used as GPIO in U-Boot */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 423 | MX6_PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL) | |
| 424 | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 425 | #define RGB_BACKLIGHTPWM_GP IMX_GPIO_NR(2, 10) |
| 426 | /* buffer output enable 0: buffer enabled */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 427 | MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(WEAK_PULLUP) | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 428 | #define RGB_BACKLIGHTPWM_OE IMX_GPIO_NR(5, 2) |
| 429 | /* PSAVE# integrated VDAC */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 430 | MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL) | |
| 431 | MUX_MODE_SION, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 432 | #define VGA_PSAVE_NOT_GP IMX_GPIO_NR(6, 31) |
| 433 | }; |
| 434 | |
| 435 | static iomux_v3_cfg_t const rgb_pads[] = { |
| 436 | MX6_PAD_EIM_A16__IPU1_DI1_DISP_CLK | MUX_PAD_CTRL(OUTPUT_RGB), |
| 437 | MX6_PAD_EIM_DA10__IPU1_DI1_PIN15 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 438 | MX6_PAD_EIM_DA11__IPU1_DI1_PIN02 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 439 | MX6_PAD_EIM_DA12__IPU1_DI1_PIN03 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 440 | MX6_PAD_EIM_DA9__IPU1_DISP1_DATA00 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 441 | MX6_PAD_EIM_DA8__IPU1_DISP1_DATA01 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 442 | MX6_PAD_EIM_DA7__IPU1_DISP1_DATA02 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 443 | MX6_PAD_EIM_DA6__IPU1_DISP1_DATA03 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 444 | MX6_PAD_EIM_DA5__IPU1_DISP1_DATA04 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 445 | MX6_PAD_EIM_DA4__IPU1_DISP1_DATA05 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 446 | MX6_PAD_EIM_DA3__IPU1_DISP1_DATA06 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 447 | MX6_PAD_EIM_DA2__IPU1_DISP1_DATA07 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 448 | MX6_PAD_EIM_DA1__IPU1_DISP1_DATA08 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 449 | MX6_PAD_EIM_DA0__IPU1_DISP1_DATA09 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 450 | MX6_PAD_EIM_EB1__IPU1_DISP1_DATA10 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 451 | MX6_PAD_EIM_EB0__IPU1_DISP1_DATA11 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 452 | MX6_PAD_EIM_A17__IPU1_DISP1_DATA12 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 453 | MX6_PAD_EIM_A18__IPU1_DISP1_DATA13 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 454 | MX6_PAD_EIM_A19__IPU1_DISP1_DATA14 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 455 | MX6_PAD_EIM_A20__IPU1_DISP1_DATA15 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 456 | MX6_PAD_EIM_A21__IPU1_DISP1_DATA16 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 457 | MX6_PAD_EIM_A22__IPU1_DISP1_DATA17 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 458 | MX6_PAD_EIM_A23__IPU1_DISP1_DATA18 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 459 | MX6_PAD_EIM_A24__IPU1_DISP1_DATA19 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 460 | MX6_PAD_EIM_D26__IPU1_DISP1_DATA22 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 461 | MX6_PAD_EIM_D27__IPU1_DISP1_DATA23 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 462 | MX6_PAD_EIM_D30__IPU1_DISP1_DATA21 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 463 | MX6_PAD_EIM_D31__IPU1_DISP1_DATA20 | MUX_PAD_CTRL(OUTPUT_RGB), |
| 464 | }; |
| 465 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 466 | static void do_enable_hdmi(struct display_info_t const *dev) |
| 467 | { |
| 468 | imx_enable_hdmi_phy(); |
| 469 | } |
| 470 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 471 | static void enable_lvds(struct display_info_t const *dev) |
| 472 | { |
| 473 | struct iomuxc *iomux = (struct iomuxc *) |
| 474 | IOMUXC_BASE_ADDR; |
| 475 | u32 reg = readl(&iomux->gpr[2]); |
| 476 | reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT; |
| 477 | writel(reg, &iomux->gpr[2]); |
| 478 | gpio_direction_output(RGB_BACKLIGHT_GP, 1); |
| 479 | gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0); |
| 480 | gpio_direction_output(RGB_BACKLIGHTPWM_OE, 0); |
| 481 | } |
| 482 | |
| 483 | static void enable_rgb(struct display_info_t const *dev) |
| 484 | { |
| 485 | imx_iomux_v3_setup_multiple_pads( |
| 486 | rgb_pads, |
| 487 | ARRAY_SIZE(rgb_pads)); |
| 488 | gpio_direction_output(RGB_BACKLIGHT_GP, 1); |
| 489 | gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0); |
| 490 | gpio_direction_output(RGB_BACKLIGHTPWM_OE, 0); |
| 491 | } |
| 492 | |
| 493 | static int detect_default(struct display_info_t const *dev) |
| 494 | { |
| 495 | (void) dev; |
| 496 | return 1; |
| 497 | } |
| 498 | |
| 499 | struct display_info_t const displays[] = {{ |
| 500 | .bus = -1, |
| 501 | .addr = 0, |
| 502 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 503 | .detect = detect_hdmi, |
| 504 | .enable = do_enable_hdmi, |
| 505 | .mode = { |
| 506 | .name = "HDMI", |
| 507 | .refresh = 60, |
| 508 | .xres = 1024, |
| 509 | .yres = 768, |
| 510 | .pixclock = 15385, |
| 511 | .left_margin = 220, |
| 512 | .right_margin = 40, |
| 513 | .upper_margin = 21, |
| 514 | .lower_margin = 7, |
| 515 | .hsync_len = 60, |
| 516 | .vsync_len = 10, |
| 517 | .sync = FB_SYNC_EXT, |
| 518 | .vmode = FB_VMODE_NONINTERLACED |
| 519 | } }, { |
| 520 | .bus = -1, |
| 521 | .addr = 0, |
| 522 | .di = 1, |
| 523 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 524 | .detect = detect_default, |
| 525 | .enable = enable_rgb, |
| 526 | .mode = { |
| 527 | .name = "vga-rgb", |
| 528 | .refresh = 60, |
| 529 | .xres = 640, |
| 530 | .yres = 480, |
| 531 | .pixclock = 33000, |
| 532 | .left_margin = 48, |
| 533 | .right_margin = 16, |
| 534 | .upper_margin = 31, |
| 535 | .lower_margin = 11, |
| 536 | .hsync_len = 96, |
| 537 | .vsync_len = 2, |
| 538 | .sync = 0, |
| 539 | .vmode = FB_VMODE_NONINTERLACED |
| 540 | } }, { |
| 541 | .bus = -1, |
| 542 | .addr = 0, |
| 543 | .di = 1, |
| 544 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 545 | .enable = enable_rgb, |
| 546 | .mode = { |
| 547 | .name = "wvga-rgb", |
| 548 | .refresh = 60, |
| 549 | .xres = 800, |
| 550 | .yres = 480, |
| 551 | .pixclock = 25000, |
| 552 | .left_margin = 40, |
| 553 | .right_margin = 88, |
| 554 | .upper_margin = 33, |
| 555 | .lower_margin = 10, |
| 556 | .hsync_len = 128, |
| 557 | .vsync_len = 2, |
| 558 | .sync = 0, |
| 559 | .vmode = FB_VMODE_NONINTERLACED |
| 560 | } }, { |
| 561 | .bus = -1, |
| 562 | .addr = 0, |
| 563 | .pixfmt = IPU_PIX_FMT_LVDS666, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 564 | .enable = enable_lvds, |
| 565 | .mode = { |
| 566 | .name = "wsvga-lvds", |
| 567 | .refresh = 60, |
| 568 | .xres = 1024, |
| 569 | .yres = 600, |
| 570 | .pixclock = 15385, |
| 571 | .left_margin = 220, |
| 572 | .right_margin = 40, |
| 573 | .upper_margin = 21, |
| 574 | .lower_margin = 7, |
| 575 | .hsync_len = 60, |
| 576 | .vsync_len = 10, |
| 577 | .sync = FB_SYNC_EXT, |
| 578 | .vmode = FB_VMODE_NONINTERLACED |
| 579 | } } }; |
| 580 | size_t display_count = ARRAY_SIZE(displays); |
| 581 | |
| 582 | static void setup_display(void) |
| 583 | { |
| 584 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 585 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 586 | int reg; |
| 587 | |
| 588 | enable_ipu_clock(); |
| 589 | imx_setup_hdmi(); |
| 590 | /* Turn on LDB0,IPU,IPU DI0 clocks */ |
| 591 | reg = __raw_readl(&mxc_ccm->CCGR3); |
| 592 | reg |= MXC_CCM_CCGR3_LDB_DI0_MASK; |
| 593 | writel(reg, &mxc_ccm->CCGR3); |
| 594 | |
| 595 | /* set LDB0, LDB1 clk select to 011/011 */ |
| 596 | reg = readl(&mxc_ccm->cs2cdr); |
| 597 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
| 598 | |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK); |
| 599 | reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
| 600 | |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET); |
| 601 | writel(reg, &mxc_ccm->cs2cdr); |
| 602 | |
| 603 | reg = readl(&mxc_ccm->cscmr2); |
| 604 | reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV; |
| 605 | writel(reg, &mxc_ccm->cscmr2); |
| 606 | |
| 607 | reg = readl(&mxc_ccm->chsccdr); |
| 608 | reg |= (CHSCCDR_CLK_SEL_LDB_DI0 |
| 609 | <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
| 610 | writel(reg, &mxc_ccm->chsccdr); |
| 611 | |
| 612 | reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
| 613 | |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH |
| 614 | |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
| 615 | |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
| 616 | |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT |
| 617 | |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
| 618 | |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
| 619 | |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED |
| 620 | |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0; |
| 621 | writel(reg, &iomux->gpr[2]); |
| 622 | |
| 623 | reg = readl(&iomux->gpr[3]); |
| 624 | reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK |
| 625 | |IOMUXC_GPR3_HDMI_MUX_CTL_MASK)) |
| 626 | | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 |
| 627 | <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET); |
| 628 | writel(reg, &iomux->gpr[3]); |
| 629 | |
| 630 | /* backlight unconditionally on for now */ |
| 631 | imx_iomux_v3_setup_multiple_pads(backlight_pads, |
| 632 | ARRAY_SIZE(backlight_pads)); |
| 633 | /* use 0 for EDT 7", use 1 for LG fullHD panel */ |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 634 | gpio_request(RGB_BACKLIGHTPWM_GP, "BKL1_PWM"); |
| 635 | gpio_request(RGB_BACKLIGHTPWM_OE, "BKL1_PWM_EN"); |
| 636 | gpio_request(RGB_BACKLIGHT_GP, "BKL1_ON"); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 637 | gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0); |
| 638 | gpio_direction_output(RGB_BACKLIGHTPWM_OE, 0); |
| 639 | gpio_direction_output(RGB_BACKLIGHT_GP, 1); |
| 640 | } |
Gerard Salvatella | 108d739 | 2018-11-19 15:54:10 +0100 | [diff] [blame] | 641 | |
| 642 | /* |
| 643 | * Backlight off before OS handover |
| 644 | */ |
| 645 | void board_preboot_os(void) |
| 646 | { |
| 647 | gpio_direction_output(RGB_BACKLIGHTPWM_GP, 1); |
| 648 | gpio_direction_output(RGB_BACKLIGHT_GP, 0); |
| 649 | } |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 650 | #endif /* defined(CONFIG_VIDEO_IPUV3) */ |
| 651 | |
| 652 | int board_early_init_f(void) |
| 653 | { |
| 654 | imx_iomux_v3_setup_multiple_pads(pwr_intb_pads, |
| 655 | ARRAY_SIZE(pwr_intb_pads)); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 656 | setup_iomux_dte_uart(); |
Marcel Ziswiler | 5d9d11f | 2022-04-13 11:33:34 +0200 | [diff] [blame] | 657 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * Do not overwrite the console |
| 663 | * Use always serial for U-Boot console |
| 664 | */ |
| 665 | int overwrite_console(void) |
| 666 | { |
| 667 | return 1; |
| 668 | } |
| 669 | |
| 670 | int board_init(void) |
| 671 | { |
| 672 | /* address of boot parameters */ |
| 673 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 674 | |
Fabio Estevam | 7a8abc6 | 2017-09-22 23:45:32 -0300 | [diff] [blame] | 675 | #if defined(CONFIG_VIDEO_IPUV3) |
| 676 | setup_display(); |
| 677 | #endif |
| 678 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 679 | #ifdef CONFIG_TDX_CMD_IMX_MFGR |
| 680 | (void) pmic_init(); |
| 681 | #endif |
| 682 | |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 683 | #ifdef CONFIG_SATA |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 684 | setup_sata(); |
| 685 | #endif |
| 686 | |
| 687 | setup_iomux_gpio(); |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | #ifdef CONFIG_BOARD_LATE_INIT |
| 693 | int board_late_init(void) |
| 694 | { |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 695 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 696 | char env_str[256]; |
| 697 | u32 rev; |
| 698 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 699 | rev = get_board_revision(); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 700 | snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 701 | env_set("board_rev", env_str); |
Marcel Ziswiler | 5d9d11f | 2022-04-13 11:33:34 +0200 | [diff] [blame] | 702 | #endif /* CONFIG_BOARD_LATE_INIT */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 703 | |
Hiago De Franco | c361582 | 2023-11-09 13:24:01 -0300 | [diff] [blame] | 704 | if (IS_ENABLED(CONFIG_USB) && is_boot_from_usb()) { |
Stefan Agner | 84bb2cf | 2019-02-08 18:12:24 +0100 | [diff] [blame] | 705 | env_set("bootdelay", "0"); |
Hiago De Franco | c361582 | 2023-11-09 13:24:01 -0300 | [diff] [blame] | 706 | if (IS_ENABLED(CONFIG_CMD_USB_SDP)) { |
| 707 | printf("Serial Downloader recovery mode, using sdp command\n"); |
| 708 | env_set("bootcmd", "sdp 0"); |
| 709 | } else if (IS_ENABLED(CONFIG_CMD_FASTBOOT)) { |
| 710 | printf("Fastboot recovery mode, using fastboot command\n"); |
| 711 | env_set("bootcmd", "fastboot usb 0"); |
| 712 | } |
Stefan Agner | 84bb2cf | 2019-02-08 18:12:24 +0100 | [diff] [blame] | 713 | } |
Stefan Agner | 84bb2cf | 2019-02-08 18:12:24 +0100 | [diff] [blame] | 714 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 715 | return 0; |
| 716 | } |
| 717 | #endif /* CONFIG_BOARD_LATE_INIT */ |
| 718 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 719 | int checkboard(void) |
| 720 | { |
| 721 | char it[] = " IT"; |
| 722 | int minc, maxc; |
| 723 | |
| 724 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 725 | case TEMP_AUTOMOTIVE: |
| 726 | case TEMP_INDUSTRIAL: |
| 727 | break; |
| 728 | case TEMP_EXTCOMMERCIAL: |
| 729 | default: |
| 730 | it[0] = 0; |
| 731 | }; |
| 732 | printf("Model: Toradex Apalis iMX6 %s %s%s\n", |
| 733 | is_cpu_type(MXC_CPU_MX6D) ? "Dual" : "Quad", |
| 734 | (gd->ram_size == 0x80000000) ? "2GB" : |
| 735 | (gd->ram_size == 0x40000000) ? "1GB" : "512MB", it); |
Simon Glass | d44a110 | 2023-11-12 19:58:25 -0700 | [diff] [blame] | 736 | |
| 737 | return tdx_checkboard(); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 741 | int ft_board_setup(void *blob, struct bd_info *bd) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 742 | { |
| 743 | return ft_common_board_setup(blob, bd); |
| 744 | } |
| 745 | #endif |
| 746 | |
| 747 | #ifdef CONFIG_CMD_BMODE |
| 748 | static const struct boot_mode board_boot_modes[] = { |
| 749 | /* 4-bit bus width */ |
| 750 | {"mmc", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)}, |
| 751 | {"sd", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 752 | {NULL, 0}, |
| 753 | }; |
| 754 | #endif |
| 755 | |
| 756 | int misc_init_r(void) |
| 757 | { |
| 758 | #ifdef CONFIG_CMD_BMODE |
| 759 | add_board_boot_modes(board_boot_modes); |
| 760 | #endif |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | #ifdef CONFIG_LDO_BYPASS_CHECK |
| 765 | /* TODO, use external pmic, for now always ldo_enable */ |
| 766 | void ldo_mode_set(int ldo_bypass) |
| 767 | { |
| 768 | return; |
| 769 | } |
| 770 | #endif |
| 771 | |
| 772 | #ifdef CONFIG_SPL_BUILD |
| 773 | #include <spl.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 774 | #include <linux/libfdt.h> |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 775 | #include "asm/arch/mx6q-ddr.h" |
| 776 | #include "asm/arch/iomux.h" |
| 777 | #include "asm/arch/crm_regs.h" |
| 778 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 779 | static void ccgr_init(void) |
| 780 | { |
| 781 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 782 | |
| 783 | writel(0x00C03F3F, &ccm->CCGR0); |
| 784 | writel(0x0030FC03, &ccm->CCGR1); |
| 785 | writel(0x0FFFFFF3, &ccm->CCGR2); |
| 786 | writel(0x3FF0300F, &ccm->CCGR3); |
| 787 | writel(0x00FFF300, &ccm->CCGR4); |
| 788 | writel(0x0F0000F3, &ccm->CCGR5); |
| 789 | writel(0x000003FF, &ccm->CCGR6); |
| 790 | |
| 791 | /* |
| 792 | * Setup CCM_CCOSR register as follows: |
| 793 | * |
Francesco Dolcini | 1fb0713 | 2022-06-24 11:52:19 +0200 | [diff] [blame] | 794 | * clko2_en = 1 --> CKO2 enabled |
| 795 | * clko2_div = 000 --> divide by 1 |
| 796 | * clko2_sel = 01110 --> osc_clk (24MHz) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 797 | * |
Francesco Dolcini | 1fb0713 | 2022-06-24 11:52:19 +0200 | [diff] [blame] | 798 | * clk_out_sel = 1 --> Output CKO2 to CKO1 |
| 799 | * |
| 800 | * This sets both CLKO2/CLKO1 output to 24MHz, |
| 801 | * CLKO1 configuration not relevant because of clk_out_sel |
| 802 | * (CLKO1 set to default) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 803 | */ |
Francesco Dolcini | 1fb0713 | 2022-06-24 11:52:19 +0200 | [diff] [blame] | 804 | writel(0x010E0101, &ccm->ccosr); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 807 | |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 808 | #define PAD_CTL_INPUT_DDR BIT(17) |
| 809 | |
| 810 | struct mx6dq_iomux_ddr_regs mx6_ddr_ioregs = { |
| 811 | /* Differential input, 40 ohm DSE */ |
| 812 | .dram_sdclk_0 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 813 | .dram_sdclk_1 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 814 | .dram_cas = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 815 | .dram_ras = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 816 | .dram_reset = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 817 | |
| 818 | /* SDKE[0:1]: BIT(12) and BIT(13) are reserved and set at reset */ |
| 819 | .dram_sdcke0 = 0x00003000, |
| 820 | .dram_sdcke1 = 0x00003000, |
| 821 | |
| 822 | .dram_sdba2 = 0x00000000, |
| 823 | |
| 824 | /* ODT[0:1]: 40 ohm DSE, BIT(12) and BIT(13) are reserved and set at reset */ |
| 825 | .dram_sdodt0 = PAD_CTL_DSE_40ohm | 0x00003000, |
| 826 | .dram_sdodt1 = PAD_CTL_DSE_40ohm | 0x00003000, |
| 827 | |
| 828 | /* SDQS[0:7]: 40 ohm DSE, Pull/Keeper Disabled, ODT Disabled */ |
| 829 | .dram_sdqs0 = PAD_CTL_DSE_40ohm, |
| 830 | .dram_sdqs1 = PAD_CTL_DSE_40ohm, |
| 831 | .dram_sdqs2 = PAD_CTL_DSE_40ohm, |
| 832 | .dram_sdqs3 = PAD_CTL_DSE_40ohm, |
| 833 | .dram_sdqs4 = PAD_CTL_DSE_40ohm, |
| 834 | .dram_sdqs5 = PAD_CTL_DSE_40ohm, |
| 835 | .dram_sdqs6 = PAD_CTL_DSE_40ohm, |
| 836 | .dram_sdqs7 = PAD_CTL_DSE_40ohm, |
| 837 | |
| 838 | /* DQM[0:7]: Differential input, 40 ohm DSE, Pull/Keeper Disabled, ODT Disabled */ |
| 839 | .dram_dqm0 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 840 | .dram_dqm1 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 841 | .dram_dqm2 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 842 | .dram_dqm3 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 843 | .dram_dqm4 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 844 | .dram_dqm5 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 845 | .dram_dqm6 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 846 | .dram_dqm7 = PAD_CTL_DSE_40ohm | PAD_CTL_INPUT_DDR, |
| 847 | }; |
| 848 | |
| 849 | struct mx6dq_iomux_grp_regs mx6_grp_ioregs = { |
| 850 | /* DDR3 */ |
| 851 | .grp_ddr_type = 0x000C0000, |
| 852 | |
| 853 | /* SDQS[0:7]: Differential input */ |
| 854 | .grp_ddrmode_ctl = PAD_CTL_INPUT_DDR, |
| 855 | |
| 856 | /* DATA[0:63]: Pull/Keeper disabled */ |
| 857 | .grp_ddrpke = 0, |
| 858 | |
| 859 | /* ADDR[0:16], SDBA[0:1]: 40 ohm DSE */ |
| 860 | .grp_addds = PAD_CTL_DSE_40ohm, |
| 861 | |
| 862 | /* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm DSE */ |
| 863 | .grp_ctlds = PAD_CTL_DSE_40ohm, |
| 864 | |
| 865 | /* DATA[0:63]: Differential input */ |
| 866 | .grp_ddrmode = PAD_CTL_INPUT_DDR, |
| 867 | |
| 868 | /* DATA[0:63]: 40 ohm DSE */ |
| 869 | .grp_b0ds = PAD_CTL_DSE_40ohm, |
| 870 | .grp_b1ds = PAD_CTL_DSE_40ohm, |
| 871 | .grp_b2ds = PAD_CTL_DSE_40ohm, |
| 872 | .grp_b3ds = PAD_CTL_DSE_40ohm, |
| 873 | .grp_b4ds = PAD_CTL_DSE_40ohm, |
| 874 | .grp_b5ds = PAD_CTL_DSE_40ohm, |
| 875 | .grp_b6ds = PAD_CTL_DSE_40ohm, |
| 876 | .grp_b7ds = PAD_CTL_DSE_40ohm, |
| 877 | }; |
| 878 | |
| 879 | struct mx6_ddr_sysinfo sysinfo = { |
| 880 | .dsize = 2, /* width of data bus: 2=64 */ |
| 881 | .cs_density = 32, /* full range so that get_mem_size() works, 32Gb per CS */ |
| 882 | .ncs = 1, |
| 883 | .cs1_mirror = 0, |
| 884 | .rtt_wr = 2, /* Dynamic ODT, RZQ/2 */ |
| 885 | .rtt_nom = 0, /* Disabled */ |
| 886 | .walat = 0, /* Write additional latency */ |
| 887 | .ralat = 5, /* Read additional latency */ |
| 888 | .mif3_mode = 3, /* Command prediction working mode */ |
| 889 | .bi_on = 1, /* Bank interleaving enabled */ |
| 890 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 891 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
| 892 | .pd_fast_exit = 1, /* enable precharge power-down fast exit */ |
| 893 | .ddr_type = DDR_TYPE_DDR3, |
| 894 | .refsel = 1, /* Refresh cycles at 32KHz */ |
| 895 | .refr = 3, /* 4 refresh commands per refresh cycle */ |
| 896 | }; |
| 897 | |
| 898 | static const struct mx6_mmdc_calibration mx6_mmdc_calib = { |
| 899 | .p0_mpwldectrl0 = 0x0009000E, |
| 900 | .p0_mpwldectrl1 = 0x0018000B, |
| 901 | .p1_mpwldectrl0 = 0x00060015, |
| 902 | .p1_mpwldectrl1 = 0x0006000E, |
| 903 | .p0_mpdgctrl0 = 0x432A0338, |
| 904 | .p0_mpdgctrl1 = 0x03260324, |
| 905 | .p1_mpdgctrl0 = 0x43340344, |
| 906 | .p1_mpdgctrl1 = 0x031E027C, |
| 907 | .p0_mprddlctl = 0x33272D2E, |
| 908 | .p1_mprddlctl = 0x2F312B37, |
| 909 | .p0_mpwrdlctl = 0x3A35433C, |
| 910 | .p1_mpwrdlctl = 0x4336453F, |
| 911 | }; |
| 912 | |
| 913 | static const struct mx6_ddr3_cfg ddr3_cfg = { |
| 914 | .mem_speed = 1066, |
| 915 | .density = 2, |
| 916 | .width = 16, |
| 917 | .banks = 8, |
| 918 | .rowaddr = 14, |
| 919 | .coladdr = 10, |
| 920 | .pagesz = 2, |
| 921 | .trcd = 1312, |
| 922 | .trcmin = 4812, |
| 923 | .trasmin = 3500, |
| 924 | .SRT = 0, |
| 925 | }; |
| 926 | |
| 927 | struct mx6_ddr_sysinfo sysinfo_it = { |
| 928 | .dsize = 2, /* width of data bus: 2=64 */ |
| 929 | .cs_density = 32, /* full range so that get_mem_size() works, 32Gb per CS */ |
| 930 | .ncs = 1, |
| 931 | .cs1_mirror = 0, |
| 932 | .rtt_wr = 1, /* Dynamic ODT, RZQ/4 */ |
| 933 | .rtt_nom = 1, /* RZQ/4 */ |
| 934 | .walat = 0, /* Write additional latency */ |
| 935 | .ralat = 5, /* Read additional latency */ |
| 936 | .mif3_mode = 3, /* Command prediction working mode */ |
| 937 | .bi_on = 1, /* Bank interleaving enabled */ |
| 938 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 939 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
| 940 | .pd_fast_exit = 1, /* enable precharge power-down fast exit */ |
| 941 | .ddr_type = DDR_TYPE_DDR3, |
| 942 | .refsel = 1, /* Refresh cycles at 32KHz */ |
| 943 | .refr = 7, /* 8 refresh commands per refresh cycle */ |
| 944 | }; |
| 945 | |
| 946 | static const struct mx6_mmdc_calibration mx6_mmdc_calib_it = { |
| 947 | .p0_mpwldectrl0 = 0x0009000E, |
| 948 | .p0_mpwldectrl1 = 0x0018000B, |
| 949 | .p1_mpwldectrl0 = 0x00060015, |
| 950 | .p1_mpwldectrl1 = 0x0006000E, |
| 951 | .p0_mpdgctrl0 = 0x03300338, |
| 952 | .p0_mpdgctrl1 = 0x03240324, |
| 953 | .p1_mpdgctrl0 = 0x03440350, |
| 954 | .p1_mpdgctrl1 = 0x032C0308, |
| 955 | .p0_mprddlctl = 0x40363C3E, |
| 956 | .p1_mprddlctl = 0x3C3E3C46, |
| 957 | .p0_mpwrdlctl = 0x403E463E, |
| 958 | .p1_mpwrdlctl = 0x4A384C46, |
| 959 | }; |
| 960 | |
| 961 | static const struct mx6_ddr3_cfg ddr3_cfg_it = { |
| 962 | .mem_speed = 1066, |
| 963 | .density = 4, |
| 964 | .width = 16, |
| 965 | .banks = 8, |
| 966 | .rowaddr = 15, |
| 967 | .coladdr = 10, |
| 968 | .pagesz = 2, |
| 969 | .trcd = 1312, |
| 970 | .trcmin = 4812, |
| 971 | .trasmin = 3500, |
| 972 | .SRT = 1, |
| 973 | }; |
| 974 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 975 | |
Francesco Dolcini | 54ef549 | 2021-08-31 11:46:06 +0200 | [diff] [blame] | 976 | /* Perform DDR DRAM calibration */ |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 977 | static void spl_dram_perform_cal(const struct mx6_ddr_sysinfo *ddr_sysinfo) |
Francesco Dolcini | 54ef549 | 2021-08-31 11:46:06 +0200 | [diff] [blame] | 978 | { |
| 979 | #ifdef CONFIG_MX6_DDRCAL |
| 980 | int err; |
Francesco Dolcini | 54ef549 | 2021-08-31 11:46:06 +0200 | [diff] [blame] | 981 | |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 982 | err = mmdc_do_write_level_calibration(ddr_sysinfo); |
Francesco Dolcini | 54ef549 | 2021-08-31 11:46:06 +0200 | [diff] [blame] | 983 | if (err) |
| 984 | printf("error %d from write level calibration\n", err); |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 985 | err = mmdc_do_dqs_calibration(ddr_sysinfo); |
Francesco Dolcini | 54ef549 | 2021-08-31 11:46:06 +0200 | [diff] [blame] | 986 | if (err) |
| 987 | printf("error %d from dqs calibration\n", err); |
| 988 | #endif |
| 989 | } |
| 990 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 991 | static void spl_dram_init(void) |
| 992 | { |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 993 | bool temp_grade_it; |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 994 | |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 995 | switch (get_cpu_temp_grade(NULL, NULL)) { |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 996 | case TEMP_COMMERCIAL: |
| 997 | case TEMP_EXTCOMMERCIAL: |
| 998 | puts("Commercial temperature grade DDR3 timings.\n"); |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 999 | temp_grade_it = false; |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1000 | break; |
| 1001 | case TEMP_INDUSTRIAL: |
| 1002 | case TEMP_AUTOMOTIVE: |
| 1003 | default: |
| 1004 | puts("Industrial temperature grade DDR3 timings.\n"); |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 1005 | temp_grade_it = true; |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1006 | break; |
| 1007 | }; |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 1008 | |
| 1009 | mx6dq_dram_iocfg(64, &mx6_ddr_ioregs, &mx6_grp_ioregs); |
| 1010 | |
| 1011 | if (temp_grade_it) |
| 1012 | mx6_dram_cfg(&sysinfo_it, &mx6_mmdc_calib_it, &ddr3_cfg_it); |
| 1013 | else |
| 1014 | mx6_dram_cfg(&sysinfo, &mx6_mmdc_calib, &ddr3_cfg); |
| 1015 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1016 | udelay(100); |
Francesco Dolcini | afa5831 | 2022-06-24 12:33:36 +0200 | [diff] [blame] | 1017 | |
| 1018 | if (temp_grade_it) |
| 1019 | spl_dram_perform_cal(&sysinfo_it); |
| 1020 | else |
| 1021 | spl_dram_perform_cal(&sysinfo); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | void board_init_f(ulong dummy) |
| 1025 | { |
| 1026 | /* setup AIPS and disable watchdog */ |
| 1027 | arch_cpu_init(); |
| 1028 | |
| 1029 | ccgr_init(); |
| 1030 | gpr_init(); |
| 1031 | |
Marcel Ziswiler | a22d71c | 2019-02-08 18:12:12 +0100 | [diff] [blame] | 1032 | /* iomux */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1033 | board_early_init_f(); |
| 1034 | |
| 1035 | /* setup GP timer */ |
| 1036 | timer_init(); |
| 1037 | |
| 1038 | /* UART clocks enabled and gd valid - init serial console */ |
| 1039 | preloader_console_init(); |
| 1040 | |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1041 | /* Make sure we use dte mode */ |
| 1042 | setup_dtemode_uart(); |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1043 | |
| 1044 | /* DDR initialization */ |
| 1045 | spl_dram_init(); |
| 1046 | |
| 1047 | /* Clear the BSS. */ |
| 1048 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 1049 | |
| 1050 | /* load/boot image from boot device */ |
| 1051 | board_init_r(NULL, 0); |
| 1052 | } |
| 1053 | |
Ricardo Salveti | 1a0b435 | 2019-09-02 18:23:27 -0300 | [diff] [blame] | 1054 | #ifdef CONFIG_SPL_LOAD_FIT |
| 1055 | int board_fit_config_name_match(const char *name) |
| 1056 | { |
| 1057 | if (!strcmp(name, "imx6-apalis")) |
| 1058 | return 0; |
| 1059 | |
| 1060 | return -1; |
| 1061 | } |
| 1062 | #endif |
| 1063 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 1064 | void reset_cpu(void) |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1065 | { |
| 1066 | } |
| 1067 | |
Marcel Ziswiler | 64bbd6a | 2019-02-08 18:12:10 +0100 | [diff] [blame] | 1068 | #endif /* CONFIG_SPL_BUILD */ |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1069 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1070 | static struct mxc_serial_plat mxc_serial_plat = { |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1071 | .reg = (struct mxc_uart *)UART1_BASE, |
| 1072 | .use_dte = true, |
| 1073 | }; |
| 1074 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1075 | U_BOOT_DRVINFO(mxc_serial) = { |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1076 | .name = "serial_mxc", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1077 | .plat = &mxc_serial_plat, |
Max Krummenacher | 3b74ccf | 2016-11-30 19:43:08 +0100 | [diff] [blame] | 1078 | }; |