Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Freescale Semiconductor, Inc. |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 4 | * Copyright (C) 2014 O.S. Systems Software LTDA. |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 5 | * |
| 6 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <asm/arch/clock.h> |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 10 | #include <asm/arch/crm_regs.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 11 | #include <asm/arch/iomux.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/arch/mx6-pins.h> |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 14 | #include <asm/arch/mxc_hdmi.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <asm/gpio.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 17 | #include <asm/mach-imx/iomux-v3.h> |
| 18 | #include <asm/mach-imx/mxc_i2c.h> |
| 19 | #include <asm/mach-imx/boot_mode.h> |
| 20 | #include <asm/mach-imx/video.h> |
| 21 | #include <asm/mach-imx/sata.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 22 | #include <asm/io.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 23 | #include <env.h> |
Alexey Brodkin | 1ace402 | 2014-02-26 17:47:58 +0400 | [diff] [blame] | 24 | #include <linux/sizes.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 25 | #include <common.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 26 | #include <miiphy.h> |
| 27 | #include <netdev.h> |
Fabio Estevam | 2fb6396 | 2014-02-15 14:52:00 -0200 | [diff] [blame] | 28 | #include <phy.h> |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 29 | #include <i2c.h> |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 30 | #include <power/pmic.h> |
| 31 | #include <power/pfuze100_pmic.h> |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Benoît Thébaudeau | 7e2173c | 2013-04-26 01:34:47 +0000 | [diff] [blame] | 35 | #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 36 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 37 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 38 | |
Benoît Thébaudeau | 7e2173c | 2013-04-26 01:34:47 +0000 | [diff] [blame] | 39 | #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 40 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS) |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 41 | |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 42 | #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 43 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \ |
| 44 | PAD_CTL_ODE | PAD_CTL_SRE_FAST) |
| 45 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 46 | #define ETH_PHY_RESET IMX_GPIO_NR(3, 29) |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 47 | #define ETH_PHY_AR8035_POWER IMX_GPIO_NR(7, 13) |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 48 | #define REV_DETECTION IMX_GPIO_NR(2, 28) |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 49 | |
Trent Piepho | d133721 | 2019-05-08 23:30:01 +0000 | [diff] [blame] | 50 | /* Speed defined in Kconfig is only applicable when not using DM_I2C. */ |
| 51 | #ifdef CONFIG_DM_I2C |
| 52 | #define I2C1_SPEED_NON_DM 0 |
| 53 | #define I2C2_SPEED_NON_DM 0 |
| 54 | #else |
| 55 | #define I2C1_SPEED_NON_DM CONFIG_SYS_MXC_I2C1_SPEED |
| 56 | #define I2C2_SPEED_NON_DM CONFIG_SYS_MXC_I2C2_SPEED |
| 57 | #endif |
| 58 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 59 | static bool with_pmic; |
| 60 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 61 | int dram_init(void) |
| 62 | { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 63 | gd->ram_size = imx_ddr_size(); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static iomux_v3_cfg_t const uart1_pads[] = { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 69 | IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
| 70 | IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)), |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 73 | static iomux_v3_cfg_t const enet_pads[] = { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 74 | IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 75 | IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 76 | IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 77 | IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 78 | IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 79 | IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 80 | IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 81 | IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 82 | IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 83 | IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 84 | IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 85 | IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 86 | IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 87 | IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
| 88 | IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)), |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 89 | /* AR8031 PHY Reset */ |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 90 | IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)), |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 93 | static iomux_v3_cfg_t const enet_ar8035_power_pads[] = { |
| 94 | /* AR8035 POWER */ |
| 95 | IOMUX_PADS(PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)), |
| 96 | }; |
| 97 | |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 98 | static iomux_v3_cfg_t const rev_detection_pad[] = { |
| 99 | IOMUX_PADS(PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)), |
| 100 | }; |
| 101 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 102 | static void setup_iomux_uart(void) |
| 103 | { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 104 | SETUP_IOMUX_PADS(uart1_pads); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void setup_iomux_enet(void) |
| 108 | { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 109 | SETUP_IOMUX_PADS(enet_pads); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 110 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 111 | if (with_pmic) { |
| 112 | SETUP_IOMUX_PADS(enet_ar8035_power_pads); |
| 113 | /* enable AR8035 POWER */ |
Anatolij Gustschin | a23ade6 | 2019-03-18 23:29:42 +0100 | [diff] [blame] | 114 | gpio_request(ETH_PHY_AR8035_POWER, "PHY_POWER"); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 115 | gpio_direction_output(ETH_PHY_AR8035_POWER, 0); |
| 116 | } |
| 117 | /* wait until 3.3V of PHY and clock become stable */ |
| 118 | mdelay(10); |
| 119 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 120 | /* Reset AR8031 PHY */ |
Anatolij Gustschin | a23ade6 | 2019-03-18 23:29:42 +0100 | [diff] [blame] | 121 | gpio_request(ETH_PHY_RESET, "PHY_RESET"); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 122 | gpio_direction_output(ETH_PHY_RESET, 0); |
Fabio Estevam | 59a6ca5 | 2016-01-05 17:02:54 -0200 | [diff] [blame] | 123 | mdelay(10); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 124 | gpio_set_value(ETH_PHY_RESET, 1); |
Fabio Estevam | 59a6ca5 | 2016-01-05 17:02:54 -0200 | [diff] [blame] | 125 | udelay(100); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Fabio Estevam | dac09fc | 2016-11-01 14:58:16 -0200 | [diff] [blame] | 128 | static int ar8031_phy_fixup(struct phy_device *phydev) |
| 129 | { |
| 130 | unsigned short val; |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 131 | int mask; |
Fabio Estevam | dac09fc | 2016-11-01 14:58:16 -0200 | [diff] [blame] | 132 | |
| 133 | /* To enable AR8031 ouput a 125MHz clk from CLK_25M */ |
| 134 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7); |
| 135 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016); |
| 136 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007); |
| 137 | |
| 138 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 139 | if (with_pmic) |
| 140 | mask = 0xffe7; /* AR8035 */ |
| 141 | else |
| 142 | mask = 0xffe3; /* AR8031 */ |
| 143 | |
| 144 | val &= mask; |
Fabio Estevam | dac09fc | 2016-11-01 14:58:16 -0200 | [diff] [blame] | 145 | val |= 0x18; |
| 146 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val); |
| 147 | |
| 148 | /* introduce tx clock delay */ |
| 149 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5); |
| 150 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e); |
| 151 | val |= 0x0100; |
| 152 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | int board_phy_config(struct phy_device *phydev) |
| 158 | { |
| 159 | ar8031_phy_fixup(phydev); |
| 160 | |
| 161 | if (phydev->drv->config) |
| 162 | phydev->drv->config(phydev); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 167 | #if defined(CONFIG_VIDEO_IPUV3) |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 168 | struct i2c_pads_info mx6q_i2c2_pad_info = { |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 169 | .scl = { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 170 | .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 171 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 172 | .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12 |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 173 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 174 | .gp = IMX_GPIO_NR(4, 12) |
| 175 | }, |
| 176 | .sda = { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 177 | .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 178 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 179 | .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 |
| 180 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 181 | .gp = IMX_GPIO_NR(4, 13) |
| 182 | } |
| 183 | }; |
| 184 | |
| 185 | struct i2c_pads_info mx6dl_i2c2_pad_info = { |
| 186 | .scl = { |
| 187 | .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL |
| 188 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 189 | .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12 |
| 190 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 191 | .gp = IMX_GPIO_NR(4, 12) |
| 192 | }, |
| 193 | .sda = { |
| 194 | .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA |
| 195 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 196 | .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 197 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 198 | .gp = IMX_GPIO_NR(4, 13) |
| 199 | } |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 202 | struct i2c_pads_info mx6q_i2c3_pad_info = { |
| 203 | .scl = { |
| 204 | .i2c_mode = MX6Q_PAD_GPIO_5__I2C3_SCL |
| 205 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 206 | .gpio_mode = MX6Q_PAD_GPIO_5__GPIO1_IO05 |
| 207 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 208 | .gp = IMX_GPIO_NR(1, 5) |
| 209 | }, |
| 210 | .sda = { |
| 211 | .i2c_mode = MX6Q_PAD_GPIO_16__I2C3_SDA |
| 212 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 213 | .gpio_mode = MX6Q_PAD_GPIO_16__GPIO7_IO11 |
| 214 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 215 | .gp = IMX_GPIO_NR(7, 11) |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | struct i2c_pads_info mx6dl_i2c3_pad_info = { |
| 220 | .scl = { |
| 221 | .i2c_mode = MX6DL_PAD_GPIO_5__I2C3_SCL |
| 222 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 223 | .gpio_mode = MX6DL_PAD_GPIO_5__GPIO1_IO05 |
| 224 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 225 | .gp = IMX_GPIO_NR(1, 5) |
| 226 | }, |
| 227 | .sda = { |
| 228 | .i2c_mode = MX6DL_PAD_GPIO_16__I2C3_SDA |
| 229 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 230 | .gpio_mode = MX6DL_PAD_GPIO_16__GPIO7_IO11 |
| 231 | | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 232 | .gp = IMX_GPIO_NR(7, 11) |
| 233 | } |
| 234 | }; |
| 235 | |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 236 | static iomux_v3_cfg_t const fwadapt_7wvga_pads[] = { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 237 | IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK), |
| 238 | IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02), /* HSync */ |
| 239 | IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03), /* VSync */ |
| 240 | IOMUX_PADS(PAD_DI0_PIN4__IPU1_DI0_PIN04 | MUX_PAD_CTRL(PAD_CTL_DSE_120ohm)), /* Contrast */ |
| 241 | IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15), /* DISP0_DRDY */ |
| 242 | IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00), |
| 243 | IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01), |
| 244 | IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02), |
| 245 | IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03), |
| 246 | IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04), |
| 247 | IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05), |
| 248 | IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06), |
| 249 | IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07), |
| 250 | IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08), |
| 251 | IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09), |
| 252 | IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10), |
| 253 | IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11), |
| 254 | IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12), |
| 255 | IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13), |
| 256 | IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14), |
| 257 | IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15), |
| 258 | IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16), |
| 259 | IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17), |
| 260 | IOMUX_PADS(PAD_SD4_DAT2__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_BKLEN */ |
| 261 | IOMUX_PADS(PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* DISP0_VDDEN */ |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | static void do_enable_hdmi(struct display_info_t const *dev) |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 265 | { |
Pardeep Kumar Singla | 5ea7f0e | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 266 | imx_enable_hdmi_phy(); |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 269 | static int detect_i2c(struct display_info_t const *dev) |
| 270 | { |
Anatolij Gustschin | c609542 | 2019-03-18 23:29:46 +0100 | [diff] [blame] | 271 | #ifdef CONFIG_DM_I2C |
| 272 | struct udevice *bus, *udev; |
| 273 | int rc; |
| 274 | |
| 275 | rc = uclass_get_device_by_seq(UCLASS_I2C, dev->bus, &bus); |
| 276 | if (rc) |
| 277 | return rc; |
| 278 | rc = dm_i2c_probe(bus, dev->addr, 0, &udev); |
| 279 | if (rc) |
| 280 | return 0; |
| 281 | return 1; |
| 282 | #else |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 283 | return (0 == i2c_set_bus_num(dev->bus)) && |
| 284 | (0 == i2c_probe(dev->addr)); |
Anatolij Gustschin | c609542 | 2019-03-18 23:29:46 +0100 | [diff] [blame] | 285 | #endif |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static void enable_fwadapt_7wvga(struct display_info_t const *dev) |
| 289 | { |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 290 | SETUP_IOMUX_PADS(fwadapt_7wvga_pads); |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 291 | |
Anatolij Gustschin | a23ade6 | 2019-03-18 23:29:42 +0100 | [diff] [blame] | 292 | gpio_request(IMX_GPIO_NR(2, 10), "DISP0_BKLEN"); |
| 293 | gpio_request(IMX_GPIO_NR(2, 11), "DISP0_VDDEN"); |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 294 | gpio_direction_output(IMX_GPIO_NR(2, 10), 1); |
| 295 | gpio_direction_output(IMX_GPIO_NR(2, 11), 1); |
| 296 | } |
| 297 | |
| 298 | struct display_info_t const displays[] = {{ |
| 299 | .bus = -1, |
| 300 | .addr = 0, |
| 301 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 302 | .detect = detect_hdmi, |
| 303 | .enable = do_enable_hdmi, |
| 304 | .mode = { |
| 305 | .name = "HDMI", |
| 306 | .refresh = 60, |
| 307 | .xres = 1024, |
| 308 | .yres = 768, |
| 309 | .pixclock = 15385, |
| 310 | .left_margin = 220, |
| 311 | .right_margin = 40, |
| 312 | .upper_margin = 21, |
| 313 | .lower_margin = 7, |
| 314 | .hsync_len = 60, |
| 315 | .vsync_len = 10, |
| 316 | .sync = FB_SYNC_EXT, |
| 317 | .vmode = FB_VMODE_NONINTERLACED |
| 318 | } }, { |
| 319 | .bus = 1, |
| 320 | .addr = 0x10, |
| 321 | .pixfmt = IPU_PIX_FMT_RGB666, |
| 322 | .detect = detect_i2c, |
| 323 | .enable = enable_fwadapt_7wvga, |
| 324 | .mode = { |
| 325 | .name = "FWBADAPT-LCD-F07A-0102", |
| 326 | .refresh = 60, |
| 327 | .xres = 800, |
| 328 | .yres = 480, |
| 329 | .pixclock = 33260, |
| 330 | .left_margin = 128, |
| 331 | .right_margin = 128, |
| 332 | .upper_margin = 22, |
| 333 | .lower_margin = 22, |
| 334 | .hsync_len = 1, |
| 335 | .vsync_len = 1, |
| 336 | .sync = 0, |
| 337 | .vmode = FB_VMODE_NONINTERLACED |
| 338 | } } }; |
| 339 | size_t display_count = ARRAY_SIZE(displays); |
| 340 | |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 341 | static void setup_display(void) |
| 342 | { |
| 343 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 344 | int reg; |
| 345 | |
Pardeep Kumar Singla | 5ea7f0e | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 346 | enable_ipu_clock(); |
| 347 | imx_setup_hdmi(); |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 348 | |
| 349 | reg = readl(&mxc_ccm->chsccdr); |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 350 | reg |= (CHSCCDR_CLK_SEL_LDB_DI0 |
Pardeep Kumar Singla | 5ea7f0e | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 351 | << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET); |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 352 | writel(reg, &mxc_ccm->chsccdr); |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 353 | |
| 354 | /* Disable LCD backlight */ |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 355 | SETUP_IOMUX_PAD(PAD_DI0_PIN4__GPIO4_IO20); |
Anatolij Gustschin | a23ade6 | 2019-03-18 23:29:42 +0100 | [diff] [blame] | 356 | gpio_request(IMX_GPIO_NR(4, 20), "LCD_BKLEN"); |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 357 | gpio_direction_input(IMX_GPIO_NR(4, 20)); |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 358 | } |
| 359 | #endif /* CONFIG_VIDEO_IPUV3 */ |
| 360 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 361 | int board_eth_init(bd_t *bis) |
| 362 | { |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 363 | setup_iomux_enet(); |
| 364 | |
Fabio Estevam | 14da759 | 2014-01-04 17:36:28 -0200 | [diff] [blame] | 365 | return cpu_eth_init(bis); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | int board_early_init_f(void) |
| 369 | { |
| 370 | setup_iomux_uart(); |
Simon Glass | 10e40d5 | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 371 | #ifdef CONFIG_SATA |
Fabio Estevam | d7f7eb7 | 2017-10-15 11:21:06 -0200 | [diff] [blame] | 372 | setup_sata(); |
Gilles Chanteperdrix | e355eec | 2016-06-09 10:33:27 +0200 | [diff] [blame] | 373 | #endif |
| 374 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 378 | #define PMIC_I2C_BUS 2 |
| 379 | |
| 380 | int power_init_board(void) |
| 381 | { |
Anatolij Gustschin | ec837c8 | 2019-03-18 23:29:45 +0100 | [diff] [blame] | 382 | struct udevice *dev; |
| 383 | int reg, ret; |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 384 | |
Anatolij Gustschin | ec837c8 | 2019-03-18 23:29:45 +0100 | [diff] [blame] | 385 | puts("PMIC: "); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 386 | |
Anatolij Gustschin | ec837c8 | 2019-03-18 23:29:45 +0100 | [diff] [blame] | 387 | ret = pmic_get("pfuze100", &dev); |
| 388 | if (ret < 0) { |
| 389 | printf("pmic_get() ret %d\n", ret); |
| 390 | return 0; |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 391 | } |
| 392 | |
Anatolij Gustschin | ec837c8 | 2019-03-18 23:29:45 +0100 | [diff] [blame] | 393 | reg = pmic_reg_read(dev, PFUZE100_DEVICEID); |
| 394 | if (reg < 0) { |
| 395 | printf("pmic_reg_read() ret %d\n", reg); |
| 396 | return 0; |
| 397 | } |
| 398 | printf("PMIC: PFUZE100 ID=0x%02x\n", reg); |
| 399 | with_pmic = true; |
| 400 | |
| 401 | /* Set VGEN2 to 1.5V and enable */ |
| 402 | reg = pmic_reg_read(dev, PFUZE100_VGEN2VOL); |
| 403 | reg &= ~(LDO_VOL_MASK); |
| 404 | reg |= (LDOA_1_50V | (1 << (LDO_EN))); |
| 405 | pmic_reg_write(dev, PFUZE100_VGEN2VOL, reg); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
Fabio Estevam | 7bcb983 | 2013-05-23 07:50:23 +0000 | [diff] [blame] | 409 | /* |
| 410 | * Do not overwrite the console |
| 411 | * Use always serial for U-Boot console |
| 412 | */ |
| 413 | int overwrite_console(void) |
| 414 | { |
| 415 | return 1; |
| 416 | } |
| 417 | |
Otavio Salvador | eaffaa2 | 2013-04-19 03:42:03 +0000 | [diff] [blame] | 418 | #ifdef CONFIG_CMD_BMODE |
| 419 | static const struct boot_mode board_boot_modes[] = { |
| 420 | /* 4 bit bus width */ |
| 421 | {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 422 | {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)}, |
| 423 | {NULL, 0}, |
| 424 | }; |
| 425 | #endif |
| 426 | |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 427 | static bool is_revc1(void) |
| 428 | { |
| 429 | SETUP_IOMUX_PADS(rev_detection_pad); |
| 430 | gpio_direction_input(REV_DETECTION); |
| 431 | |
| 432 | if (gpio_get_value(REV_DETECTION)) |
| 433 | return true; |
| 434 | else |
| 435 | return false; |
| 436 | } |
| 437 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 438 | static bool is_revd1(void) |
| 439 | { |
| 440 | if (with_pmic) |
| 441 | return true; |
| 442 | else |
| 443 | return false; |
| 444 | } |
| 445 | |
Otavio Salvador | eaffaa2 | 2013-04-19 03:42:03 +0000 | [diff] [blame] | 446 | int board_late_init(void) |
| 447 | { |
| 448 | #ifdef CONFIG_CMD_BMODE |
| 449 | add_board_boot_modes(board_boot_modes); |
| 450 | #endif |
| 451 | |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 452 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Fabio Estevam | e1f0715 | 2017-10-14 09:17:54 -0300 | [diff] [blame] | 453 | if (is_mx6dqp()) |
| 454 | env_set("board_rev", "MX6QP"); |
| 455 | else if (is_mx6dq()) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 456 | env_set("board_rev", "MX6Q"); |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 457 | else |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 458 | env_set("board_rev", "MX6DL"); |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 459 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 460 | if (is_revd1()) |
| 461 | env_set("board_name", "D1"); |
| 462 | else if (is_revc1()) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 463 | env_set("board_name", "C1"); |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 464 | else |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 465 | env_set("board_name", "B1"); |
Fabio Estevam | 0d1ea05 | 2015-05-11 20:50:22 -0300 | [diff] [blame] | 466 | #endif |
Otavio Salvador | eaffaa2 | 2013-04-19 03:42:03 +0000 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 470 | int board_init(void) |
| 471 | { |
| 472 | /* address of boot parameters */ |
| 473 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 474 | |
Sven Ebenfeld | 36c0627 | 2016-11-25 21:42:53 +0100 | [diff] [blame] | 475 | #if defined(CONFIG_VIDEO_IPUV3) |
Trent Piepho | d133721 | 2019-05-08 23:30:01 +0000 | [diff] [blame] | 476 | setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info); |
Fabio Estevam | e1f0715 | 2017-10-14 09:17:54 -0300 | [diff] [blame] | 477 | if (is_mx6dq() || is_mx6dqp()) { |
Trent Piepho | d133721 | 2019-05-08 23:30:01 +0000 | [diff] [blame] | 478 | setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6q_i2c2_pad_info); |
| 479 | setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6q_i2c3_pad_info); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 480 | } else { |
Trent Piepho | d133721 | 2019-05-08 23:30:01 +0000 | [diff] [blame] | 481 | setup_i2c(1, I2C1_SPEED_NON_DM, 0x7f, &mx6dl_i2c2_pad_info); |
| 482 | setup_i2c(2, I2C2_SPEED_NON_DM, 0x7f, &mx6dl_i2c3_pad_info); |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 483 | } |
Fabio Estevam | 1b853e4 | 2017-09-22 23:45:30 -0300 | [diff] [blame] | 484 | |
| 485 | setup_display(); |
Sven Ebenfeld | 36c0627 | 2016-11-25 21:42:53 +0100 | [diff] [blame] | 486 | #endif |
Otavio Salvador | 8bc7c48 | 2014-05-01 19:02:31 -0300 | [diff] [blame] | 487 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 491 | int checkboard(void) |
| 492 | { |
Anatolij Gustschin | a23ade6 | 2019-03-18 23:29:42 +0100 | [diff] [blame] | 493 | gpio_request(REV_DETECTION, "REV_DETECT"); |
| 494 | |
Fabio Estevam | 066d97c | 2017-10-02 15:47:29 -0300 | [diff] [blame] | 495 | if (is_revd1()) |
| 496 | puts("Board: Wandboard rev D1\n"); |
| 497 | else if (is_revc1()) |
Fabio Estevam | 9a8804a | 2015-05-21 19:24:05 -0300 | [diff] [blame] | 498 | puts("Board: Wandboard rev C1\n"); |
| 499 | else |
| 500 | puts("Board: Wandboard rev B1\n"); |
Fabio Estevam | e2d282a | 2013-03-15 10:43:48 +0000 | [diff] [blame] | 501 | |
| 502 | return 0; |
| 503 | } |
Fabio Estevam | 5b85858 | 2019-06-12 12:34:40 -0300 | [diff] [blame] | 504 | |
| 505 | #ifdef CONFIG_SPL_LOAD_FIT |
| 506 | int board_fit_config_name_match(const char *name) |
| 507 | { |
| 508 | if (is_mx6dq()) { |
| 509 | if (!strcmp(name, "imx6q-wandboard-revb1")) |
| 510 | return 0; |
| 511 | } else if (is_mx6dqp()) { |
| 512 | if (!strcmp(name, "imx6qp-wandboard-revd1")) |
| 513 | return 0; |
| 514 | } else if (is_mx6dl() || is_mx6solo()) { |
| 515 | if (!strcmp(name, "imx6dl-wandboard-revb1")) |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | #endif |