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