Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <asm/arch/clock.h> |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 9 | #include <asm/arch/crm_regs.h> |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 10 | #include <asm/arch/iomux.h> |
| 11 | #include <asm/arch/imx-regs.h> |
| 12 | #include <asm/arch/mx6-pins.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 15 | #include <asm/mach-imx/iomux-v3.h> |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 16 | #include <asm/io.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 17 | #include <asm/mach-imx/mxc_i2c.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 18 | #include <env.h> |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 19 | #include <linux/sizes.h> |
| 20 | #include <common.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 21 | #include <fsl_esdhc_imx.h> |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 22 | #include <mmc.h> |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 23 | #include <i2c.h> |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 24 | #include <miiphy.h> |
| 25 | #include <netdev.h> |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 26 | #include <power/pmic.h> |
| 27 | #include <power/pfuze100_pmic.h> |
Ye.Li | c61e5b1 | 2014-11-06 16:29:01 +0800 | [diff] [blame] | 28 | #include "../common/pfuze.h" |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | #define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \ |
| 33 | PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \ |
| 34 | PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 35 | |
| 36 | #define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \ |
| 37 | PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \ |
| 38 | PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 39 | |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 40 | #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \ |
| 41 | PAD_CTL_SPEED_HIGH | \ |
| 42 | PAD_CTL_DSE_48ohm | PAD_CTL_SRE_FAST) |
| 43 | |
| 44 | #define ENET_CLK_PAD_CTRL (PAD_CTL_SPEED_MED | \ |
| 45 | PAD_CTL_DSE_120ohm | PAD_CTL_SRE_FAST) |
| 46 | |
| 47 | #define ENET_RX_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \ |
| 48 | PAD_CTL_SPEED_HIGH | PAD_CTL_SRE_FAST) |
| 49 | |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 50 | #define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \ |
| 51 | PAD_CTL_PKE | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm) |
| 52 | |
Peng Fan | c622a1b | 2018-01-02 09:32:09 +0800 | [diff] [blame] | 53 | #define WDOG_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_PKE | PAD_CTL_SPEED_MED | \ |
| 54 | PAD_CTL_DSE_40ohm) |
| 55 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 56 | int dram_init(void) |
| 57 | { |
Vanessa Maegima | 788236f | 2016-06-09 15:28:33 -0300 | [diff] [blame] | 58 | gd->ram_size = imx_ddr_size(); |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static iomux_v3_cfg_t const uart1_pads[] = { |
| 64 | MX6_PAD_GPIO1_IO04__UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 65 | MX6_PAD_GPIO1_IO05__UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 66 | }; |
| 67 | |
Peng Fan | c622a1b | 2018-01-02 09:32:09 +0800 | [diff] [blame] | 68 | static iomux_v3_cfg_t const wdog_b_pad = { |
| 69 | MX6_PAD_GPIO1_IO13__GPIO1_IO_13 | MUX_PAD_CTRL(WDOG_PAD_CTRL), |
| 70 | }; |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 71 | static iomux_v3_cfg_t const fec1_pads[] = { |
| 72 | MX6_PAD_ENET1_MDC__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 73 | MX6_PAD_ENET1_MDIO__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 74 | MX6_PAD_RGMII1_RX_CTL__ENET1_RX_EN | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 75 | MX6_PAD_RGMII1_RD0__ENET1_RX_DATA_0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 76 | MX6_PAD_RGMII1_RD1__ENET1_RX_DATA_1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 77 | MX6_PAD_RGMII1_RD2__ENET1_RX_DATA_2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 78 | MX6_PAD_RGMII1_RD3__ENET1_RX_DATA_3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 79 | MX6_PAD_RGMII1_RXC__ENET1_RX_CLK | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 80 | MX6_PAD_RGMII1_TX_CTL__ENET1_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 81 | MX6_PAD_RGMII1_TD0__ENET1_TX_DATA_0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 82 | MX6_PAD_RGMII1_TD1__ENET1_TX_DATA_1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 83 | MX6_PAD_RGMII1_TD2__ENET1_TX_DATA_2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 84 | MX6_PAD_RGMII1_TD3__ENET1_TX_DATA_3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 85 | MX6_PAD_RGMII1_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 86 | }; |
| 87 | |
| 88 | static iomux_v3_cfg_t const peri_3v3_pads[] = { |
| 89 | MX6_PAD_QSPI1A_DATA0__GPIO4_IO_16 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 90 | }; |
| 91 | |
| 92 | static iomux_v3_cfg_t const phy_control_pads[] = { |
| 93 | /* 25MHz Ethernet PHY Clock */ |
| 94 | MX6_PAD_ENET2_RX_CLK__ENET2_REF_CLK_25M | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL), |
| 95 | |
| 96 | /* ENET PHY Power */ |
| 97 | MX6_PAD_ENET2_COL__GPIO2_IO_6 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 98 | |
| 99 | /* AR8031 PHY Reset */ |
| 100 | MX6_PAD_ENET2_CRS__GPIO2_IO_7 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 101 | }; |
| 102 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 103 | static void setup_iomux_uart(void) |
| 104 | { |
| 105 | imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); |
| 106 | } |
| 107 | |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 108 | static int setup_fec(void) |
| 109 | { |
| 110 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 111 | struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; |
Fabio Estevam | 6b51797 | 2015-11-23 16:18:02 -0200 | [diff] [blame] | 112 | int reg, ret; |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 113 | |
| 114 | /* Use 125MHz anatop loopback REF_CLK1 for ENET1 */ |
| 115 | clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC1_MASK, 0); |
| 116 | |
Fabio Estevam | 6b51797 | 2015-11-23 16:18:02 -0200 | [diff] [blame] | 117 | ret = enable_fec_anatop_clock(0, ENET_125MHZ); |
| 118 | if (ret) |
| 119 | return ret; |
| 120 | |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 121 | imx_iomux_v3_setup_multiple_pads(phy_control_pads, |
| 122 | ARRAY_SIZE(phy_control_pads)); |
| 123 | |
| 124 | /* Enable the ENET power, active low */ |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 125 | gpio_request(IMX_GPIO_NR(2, 6), "enet_rst"); |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 126 | gpio_direction_output(IMX_GPIO_NR(2, 6) , 0); |
| 127 | |
| 128 | /* Reset AR8031 PHY */ |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 129 | gpio_request(IMX_GPIO_NR(2, 7), "phy_rst"); |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 130 | gpio_direction_output(IMX_GPIO_NR(2, 7) , 0); |
Fabio Estevam | 6b51797 | 2015-11-23 16:18:02 -0200 | [diff] [blame] | 131 | mdelay(10); |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 132 | gpio_set_value(IMX_GPIO_NR(2, 7), 1); |
| 133 | |
| 134 | reg = readl(&anatop->pll_enet); |
| 135 | reg |= BM_ANADIG_PLL_ENET_REF_25M_ENABLE; |
| 136 | writel(reg, &anatop->pll_enet); |
| 137 | |
Fabio Estevam | 6b51797 | 2015-11-23 16:18:02 -0200 | [diff] [blame] | 138 | return 0; |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | int board_eth_init(bd_t *bis) |
| 142 | { |
| 143 | imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads)); |
| 144 | setup_fec(); |
| 145 | |
| 146 | return cpu_eth_init(bis); |
| 147 | } |
| 148 | |
Ye.Li | c61e5b1 | 2014-11-06 16:29:01 +0800 | [diff] [blame] | 149 | int power_init_board(void) |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 150 | { |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 151 | struct udevice *dev; |
Fabio Estevam | 40517ec | 2015-07-21 20:37:22 -0300 | [diff] [blame] | 152 | unsigned int reg; |
| 153 | int ret; |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 154 | |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 155 | dev = pfuze_common_init(); |
| 156 | if (!dev) |
Ye.Li | c61e5b1 | 2014-11-06 16:29:01 +0800 | [diff] [blame] | 157 | return -ENODEV; |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 158 | |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 159 | ret = pfuze_mode_init(dev, APS_PFM); |
Peng Fan | e5bcd4d | 2015-01-27 10:14:04 +0800 | [diff] [blame] | 160 | if (ret < 0) |
| 161 | return ret; |
| 162 | |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 163 | /* Enable power of VGEN5 3V3, needed for SD3 */ |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 164 | reg = pmic_reg_read(dev, PFUZE100_VGEN5VOL); |
Ye.Li | c61e5b1 | 2014-11-06 16:29:01 +0800 | [diff] [blame] | 165 | reg &= ~LDO_VOL_MASK; |
| 166 | reg |= (LDOB_3_30V | (1 << LDO_EN)); |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 167 | pmic_reg_write(dev, PFUZE100_VGEN5VOL, reg); |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 172 | int board_phy_config(struct phy_device *phydev) |
| 173 | { |
| 174 | /* |
| 175 | * Enable 1.8V(SEL_1P5_1P8_POS_REG) on |
| 176 | * Phy control debug reg 0 |
| 177 | */ |
| 178 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f); |
| 179 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8); |
| 180 | |
| 181 | /* rgmii tx clock delay enable */ |
| 182 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05); |
| 183 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 184 | |
| 185 | if (phydev->drv->config) |
| 186 | phydev->drv->config(phydev); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 191 | int board_early_init_f(void) |
| 192 | { |
| 193 | setup_iomux_uart(); |
Fabio Estevam | cc175cf | 2014-07-09 16:13:30 -0300 | [diff] [blame] | 194 | |
Fabio Estevam | 3bc9bc1 | 2014-08-15 00:24:29 -0300 | [diff] [blame] | 195 | /* Enable PERI_3V3, which is used by SD2, ENET, LVDS, BT */ |
| 196 | imx_iomux_v3_setup_multiple_pads(peri_3v3_pads, |
| 197 | ARRAY_SIZE(peri_3v3_pads)); |
| 198 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Peng Fan | 03a43df | 2016-01-28 16:51:27 +0800 | [diff] [blame] | 202 | int board_mmc_get_env_dev(int devno) |
| 203 | { |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 204 | return devno; |
Peng Fan | 03a43df | 2016-01-28 16:51:27 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Peng Fan | 724de24 | 2014-12-31 11:01:40 +0800 | [diff] [blame] | 207 | #ifdef CONFIG_FSL_QSPI |
| 208 | |
Peng Fan | 724de24 | 2014-12-31 11:01:40 +0800 | [diff] [blame] | 209 | int board_qspi_init(void) |
| 210 | { |
Peng Fan | 724de24 | 2014-12-31 11:01:40 +0800 | [diff] [blame] | 211 | /* Set the clock */ |
| 212 | enable_qspi_clk(1); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | #endif |
| 217 | |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 218 | #ifdef CONFIG_VIDEO_MXS |
| 219 | static iomux_v3_cfg_t const lcd_pads[] = { |
| 220 | MX6_PAD_LCD1_CLK__LCDIF1_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 221 | MX6_PAD_LCD1_ENABLE__LCDIF1_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 222 | MX6_PAD_LCD1_HSYNC__LCDIF1_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 223 | MX6_PAD_LCD1_VSYNC__LCDIF1_VSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 224 | MX6_PAD_LCD1_DATA00__LCDIF1_DATA_0 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 225 | MX6_PAD_LCD1_DATA01__LCDIF1_DATA_1 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 226 | MX6_PAD_LCD1_DATA02__LCDIF1_DATA_2 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 227 | MX6_PAD_LCD1_DATA03__LCDIF1_DATA_3 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 228 | MX6_PAD_LCD1_DATA04__LCDIF1_DATA_4 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 229 | MX6_PAD_LCD1_DATA05__LCDIF1_DATA_5 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 230 | MX6_PAD_LCD1_DATA06__LCDIF1_DATA_6 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 231 | MX6_PAD_LCD1_DATA07__LCDIF1_DATA_7 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 232 | MX6_PAD_LCD1_DATA08__LCDIF1_DATA_8 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 233 | MX6_PAD_LCD1_DATA09__LCDIF1_DATA_9 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 234 | MX6_PAD_LCD1_DATA10__LCDIF1_DATA_10 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 235 | MX6_PAD_LCD1_DATA11__LCDIF1_DATA_11 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 236 | MX6_PAD_LCD1_DATA12__LCDIF1_DATA_12 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 237 | MX6_PAD_LCD1_DATA13__LCDIF1_DATA_13 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 238 | MX6_PAD_LCD1_DATA14__LCDIF1_DATA_14 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 239 | MX6_PAD_LCD1_DATA15__LCDIF1_DATA_15 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 240 | MX6_PAD_LCD1_DATA16__LCDIF1_DATA_16 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 241 | MX6_PAD_LCD1_DATA17__LCDIF1_DATA_17 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 242 | MX6_PAD_LCD1_DATA18__LCDIF1_DATA_18 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 243 | MX6_PAD_LCD1_DATA19__LCDIF1_DATA_19 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 244 | MX6_PAD_LCD1_DATA20__LCDIF1_DATA_20 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 245 | MX6_PAD_LCD1_DATA21__LCDIF1_DATA_21 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 246 | MX6_PAD_LCD1_DATA22__LCDIF1_DATA_22 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 247 | MX6_PAD_LCD1_DATA23__LCDIF1_DATA_23 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 248 | MX6_PAD_LCD1_RESET__GPIO3_IO_27 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 249 | |
| 250 | /* Use GPIO for Brightness adjustment, duty cycle = period */ |
| 251 | MX6_PAD_SD1_DATA2__GPIO6_IO_4 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 252 | }; |
| 253 | |
| 254 | static int setup_lcd(void) |
| 255 | { |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 256 | enable_lcdif_clock(LCDIF1_BASE_ADDR, 1); |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 257 | |
| 258 | imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads)); |
| 259 | |
| 260 | /* Reset the LCD */ |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 261 | gpio_request(IMX_GPIO_NR(3, 27), "lcd_rst"); |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 262 | gpio_direction_output(IMX_GPIO_NR(3, 27) , 0); |
| 263 | udelay(500); |
| 264 | gpio_direction_output(IMX_GPIO_NR(3, 27) , 1); |
| 265 | |
| 266 | /* Set Brightness to high */ |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 267 | gpio_request(IMX_GPIO_NR(6, 4), "lcd_bright"); |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 268 | gpio_direction_output(IMX_GPIO_NR(6, 4) , 1); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | #endif |
| 273 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 274 | int board_init(void) |
| 275 | { |
| 276 | /* Address of boot parameters */ |
| 277 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 278 | |
Peng Fan | c622a1b | 2018-01-02 09:32:09 +0800 | [diff] [blame] | 279 | /* |
| 280 | * Because kernel set WDOG_B mux before pad with the common pinctrl |
| 281 | * framwork now and wdog reset will be triggered once set WDOG_B mux |
| 282 | * with default pad setting, we set pad setting here to workaround this. |
| 283 | * Since imx_iomux_v3_setup_pad also set mux before pad setting, we set |
| 284 | * as GPIO mux firstly here to workaround it. |
| 285 | */ |
| 286 | imx_iomux_v3_setup_pad(wdog_b_pad); |
| 287 | |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 288 | /* Active high for ncp692 */ |
| 289 | gpio_request(IMX_GPIO_NR(4, 16), "ncp692_en"); |
| 290 | gpio_direction_output(IMX_GPIO_NR(4, 16), 1); |
Peng Fan | 93fb63f | 2014-10-31 11:08:06 +0800 | [diff] [blame] | 291 | |
Peng Fan | 724de24 | 2014-12-31 11:01:40 +0800 | [diff] [blame] | 292 | #ifdef CONFIG_FSL_QSPI |
| 293 | board_qspi_init(); |
| 294 | #endif |
| 295 | |
Ye Li | 5956592 | 2016-01-26 22:09:40 +0800 | [diff] [blame] | 296 | #ifdef CONFIG_VIDEO_MXS |
| 297 | setup_lcd(); |
| 298 | #endif |
| 299 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Fabio Estevam | 8f60c3f | 2017-11-27 10:25:10 -0200 | [diff] [blame] | 303 | static bool is_reva(void) |
| 304 | { |
| 305 | return (nxp_board_rev() == 1); |
| 306 | } |
| 307 | |
| 308 | int board_late_init(void) |
| 309 | { |
| 310 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 311 | if (is_reva()) |
| 312 | env_set("board_rev", "REVA"); |
| 313 | #endif |
| 314 | return 0; |
| 315 | } |
| 316 | |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 317 | int checkboard(void) |
| 318 | { |
Fabio Estevam | 8f60c3f | 2017-11-27 10:25:10 -0200 | [diff] [blame] | 319 | printf("Board: MX6SX SABRE SDB rev%c\n", nxp_board_rev_string()); |
Fabio Estevam | b6936d7 | 2014-06-24 17:41:01 -0300 | [diff] [blame] | 320 | |
| 321 | return 0; |
| 322 | } |
Peng Fan | c843664 | 2014-12-30 17:24:03 +0800 | [diff] [blame] | 323 | |
| 324 | #ifdef CONFIG_SPL_BUILD |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 325 | #include <linux/libfdt.h> |
Peng Fan | c843664 | 2014-12-30 17:24:03 +0800 | [diff] [blame] | 326 | #include <spl.h> |
| 327 | #include <asm/arch/mx6-ddr.h> |
| 328 | |
Peng Fan | 48d1dd1 | 2018-01-02 09:32:08 +0800 | [diff] [blame] | 329 | static struct fsl_esdhc_cfg usdhc_cfg[3] = { |
| 330 | {USDHC2_BASE_ADDR, 0, 4}, |
| 331 | {USDHC3_BASE_ADDR}, |
| 332 | {USDHC4_BASE_ADDR}, |
| 333 | }; |
| 334 | |
| 335 | #define USDHC3_CD_GPIO IMX_GPIO_NR(2, 10) |
| 336 | #define USDHC3_PWR_GPIO IMX_GPIO_NR(2, 11) |
| 337 | #define USDHC4_CD_GPIO IMX_GPIO_NR(6, 21) |
| 338 | |
| 339 | static iomux_v3_cfg_t const usdhc2_pads[] = { |
| 340 | MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 341 | MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 342 | MX6_PAD_SD2_DATA0__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 343 | MX6_PAD_SD2_DATA1__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 344 | MX6_PAD_SD2_DATA2__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 345 | MX6_PAD_SD2_DATA3__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 346 | }; |
| 347 | |
| 348 | static iomux_v3_cfg_t const usdhc3_pads[] = { |
| 349 | MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 350 | MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 351 | MX6_PAD_SD3_DATA0__USDHC3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 352 | MX6_PAD_SD3_DATA1__USDHC3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 353 | MX6_PAD_SD3_DATA2__USDHC3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 354 | MX6_PAD_SD3_DATA3__USDHC3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 355 | MX6_PAD_SD3_DATA4__USDHC3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 356 | MX6_PAD_SD3_DATA5__USDHC3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 357 | MX6_PAD_SD3_DATA6__USDHC3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 358 | MX6_PAD_SD3_DATA7__USDHC3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 359 | |
| 360 | /* CD pin */ |
| 361 | MX6_PAD_KEY_COL0__GPIO2_IO_10 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 362 | |
| 363 | /* RST_B, used for power reset cycle */ |
| 364 | MX6_PAD_KEY_COL1__GPIO2_IO_11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 365 | }; |
| 366 | |
| 367 | static iomux_v3_cfg_t const usdhc4_pads[] = { |
| 368 | MX6_PAD_SD4_CLK__USDHC4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 369 | MX6_PAD_SD4_CMD__USDHC4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 370 | MX6_PAD_SD4_DATA0__USDHC4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 371 | MX6_PAD_SD4_DATA1__USDHC4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 372 | MX6_PAD_SD4_DATA2__USDHC4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 373 | MX6_PAD_SD4_DATA3__USDHC4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 374 | MX6_PAD_SD4_DATA7__GPIO6_IO_21 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 375 | }; |
| 376 | |
| 377 | int board_mmc_init(bd_t *bis) |
| 378 | { |
| 379 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 380 | u32 val; |
| 381 | u32 port; |
| 382 | |
| 383 | val = readl(&src_regs->sbmr1); |
| 384 | |
| 385 | if ((val & 0xc0) != 0x40) { |
| 386 | printf("Not boot from USDHC!\n"); |
| 387 | return -EINVAL; |
| 388 | } |
| 389 | |
| 390 | port = (val >> 11) & 0x3; |
| 391 | printf("port %d\n", port); |
| 392 | switch (port) { |
| 393 | case 1: |
| 394 | imx_iomux_v3_setup_multiple_pads( |
| 395 | usdhc2_pads, ARRAY_SIZE(usdhc2_pads)); |
| 396 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 397 | usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR; |
| 398 | break; |
| 399 | case 2: |
| 400 | imx_iomux_v3_setup_multiple_pads( |
| 401 | usdhc3_pads, ARRAY_SIZE(usdhc3_pads)); |
| 402 | gpio_direction_input(USDHC3_CD_GPIO); |
| 403 | gpio_direction_output(USDHC3_PWR_GPIO, 1); |
| 404 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
| 405 | usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR; |
| 406 | break; |
| 407 | case 3: |
| 408 | imx_iomux_v3_setup_multiple_pads( |
| 409 | usdhc4_pads, ARRAY_SIZE(usdhc4_pads)); |
| 410 | gpio_direction_input(USDHC4_CD_GPIO); |
| 411 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK); |
| 412 | usdhc_cfg[0].esdhc_base = USDHC4_BASE_ADDR; |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk; |
| 417 | return fsl_esdhc_initialize(bis, &usdhc_cfg[0]); |
| 418 | } |
| 419 | |
| 420 | int board_mmc_getcd(struct mmc *mmc) |
| 421 | { |
| 422 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 423 | int ret = 0; |
| 424 | |
| 425 | switch (cfg->esdhc_base) { |
| 426 | case USDHC2_BASE_ADDR: |
| 427 | ret = 1; /* Assume uSDHC2 is always present */ |
| 428 | break; |
| 429 | case USDHC3_BASE_ADDR: |
| 430 | ret = !gpio_get_value(USDHC3_CD_GPIO); |
| 431 | break; |
| 432 | case USDHC4_BASE_ADDR: |
| 433 | ret = !gpio_get_value(USDHC4_CD_GPIO); |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | return ret; |
| 438 | } |
| 439 | |
Peng Fan | c843664 | 2014-12-30 17:24:03 +0800 | [diff] [blame] | 440 | const struct mx6sx_iomux_ddr_regs mx6_ddr_ioregs = { |
| 441 | .dram_dqm0 = 0x00000028, |
| 442 | .dram_dqm1 = 0x00000028, |
| 443 | .dram_dqm2 = 0x00000028, |
| 444 | .dram_dqm3 = 0x00000028, |
| 445 | .dram_ras = 0x00000020, |
| 446 | .dram_cas = 0x00000020, |
| 447 | .dram_odt0 = 0x00000020, |
| 448 | .dram_odt1 = 0x00000020, |
| 449 | .dram_sdba2 = 0x00000000, |
| 450 | .dram_sdcke0 = 0x00003000, |
| 451 | .dram_sdcke1 = 0x00003000, |
| 452 | .dram_sdclk_0 = 0x00000030, |
| 453 | .dram_sdqs0 = 0x00000028, |
| 454 | .dram_sdqs1 = 0x00000028, |
| 455 | .dram_sdqs2 = 0x00000028, |
| 456 | .dram_sdqs3 = 0x00000028, |
| 457 | .dram_reset = 0x00000020, |
| 458 | }; |
| 459 | |
| 460 | const struct mx6sx_iomux_grp_regs mx6_grp_ioregs = { |
| 461 | .grp_addds = 0x00000020, |
| 462 | .grp_ddrmode_ctl = 0x00020000, |
| 463 | .grp_ddrpke = 0x00000000, |
| 464 | .grp_ddrmode = 0x00020000, |
| 465 | .grp_b0ds = 0x00000028, |
| 466 | .grp_b1ds = 0x00000028, |
| 467 | .grp_ctlds = 0x00000020, |
| 468 | .grp_ddr_type = 0x000c0000, |
| 469 | .grp_b2ds = 0x00000028, |
| 470 | .grp_b3ds = 0x00000028, |
| 471 | }; |
| 472 | |
| 473 | const struct mx6_mmdc_calibration mx6_mmcd_calib = { |
| 474 | .p0_mpwldectrl0 = 0x00290025, |
| 475 | .p0_mpwldectrl1 = 0x00220022, |
| 476 | .p0_mpdgctrl0 = 0x41480144, |
| 477 | .p0_mpdgctrl1 = 0x01340130, |
| 478 | .p0_mprddlctl = 0x3C3E4244, |
| 479 | .p0_mpwrdlctl = 0x34363638, |
| 480 | }; |
| 481 | |
| 482 | static struct mx6_ddr3_cfg mem_ddr = { |
| 483 | .mem_speed = 1600, |
| 484 | .density = 4, |
| 485 | .width = 32, |
| 486 | .banks = 8, |
| 487 | .rowaddr = 15, |
| 488 | .coladdr = 10, |
| 489 | .pagesz = 2, |
| 490 | .trcd = 1375, |
| 491 | .trcmin = 4875, |
| 492 | .trasmin = 3500, |
| 493 | }; |
| 494 | |
| 495 | static void ccgr_init(void) |
| 496 | { |
| 497 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 498 | |
| 499 | writel(0xFFFFFFFF, &ccm->CCGR0); |
| 500 | writel(0xFFFFFFFF, &ccm->CCGR1); |
| 501 | writel(0xFFFFFFFF, &ccm->CCGR2); |
| 502 | writel(0xFFFFFFFF, &ccm->CCGR3); |
| 503 | writel(0xFFFFFFFF, &ccm->CCGR4); |
| 504 | writel(0xFFFFFFFF, &ccm->CCGR5); |
| 505 | writel(0xFFFFFFFF, &ccm->CCGR6); |
| 506 | writel(0xFFFFFFFF, &ccm->CCGR7); |
| 507 | } |
| 508 | |
| 509 | static void spl_dram_init(void) |
| 510 | { |
| 511 | struct mx6_ddr_sysinfo sysinfo = { |
| 512 | .dsize = mem_ddr.width/32, |
| 513 | .cs_density = 24, |
| 514 | .ncs = 1, |
| 515 | .cs1_mirror = 0, |
| 516 | .rtt_wr = 2, |
| 517 | .rtt_nom = 2, /* RTT_Nom = RZQ/2 */ |
| 518 | .walat = 1, /* Write additional latency */ |
| 519 | .ralat = 5, /* Read additional latency */ |
| 520 | .mif3_mode = 3, /* Command prediction working mode */ |
| 521 | .bi_on = 1, /* Bank interleaving enabled */ |
| 522 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 523 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
Peng Fan | 77e8695 | 2015-08-17 16:11:03 +0800 | [diff] [blame] | 524 | .ddr_type = DDR_TYPE_DDR3, |
Fabio Estevam | cb3c121 | 2016-08-29 20:37:15 -0300 | [diff] [blame] | 525 | .refsel = 1, /* Refresh cycles at 32KHz */ |
| 526 | .refr = 7, /* 8 refresh commands per refresh cycle */ |
Peng Fan | c843664 | 2014-12-30 17:24:03 +0800 | [diff] [blame] | 527 | }; |
| 528 | |
| 529 | mx6sx_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs); |
| 530 | mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr); |
| 531 | } |
| 532 | |
| 533 | void board_init_f(ulong dummy) |
| 534 | { |
| 535 | /* setup AIPS and disable watchdog */ |
| 536 | arch_cpu_init(); |
| 537 | |
| 538 | ccgr_init(); |
| 539 | |
| 540 | /* iomux and setup of i2c */ |
| 541 | board_early_init_f(); |
| 542 | |
| 543 | /* setup GP timer */ |
| 544 | timer_init(); |
| 545 | |
| 546 | /* UART clocks enabled and gd valid - init serial console */ |
| 547 | preloader_console_init(); |
| 548 | |
| 549 | /* DDR initialization */ |
| 550 | spl_dram_init(); |
| 551 | |
| 552 | /* Clear the BSS. */ |
| 553 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 554 | |
| 555 | /* load/boot image from boot device */ |
| 556 | board_init_r(NULL, 0); |
| 557 | } |
Peng Fan | c843664 | 2014-12-30 17:24:03 +0800 | [diff] [blame] | 558 | #endif |