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