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