Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/arch/iomux.h> |
Eric Nelson | cfb8b9d | 2013-02-19 10:07:01 +0000 | [diff] [blame] | 14 | #include <asm/arch/mx6q_pins.h> |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 15 | #include <asm/errno.h> |
| 16 | #include <asm/gpio.h> |
| 17 | #include <asm/imx-common/iomux-v3.h> |
Renato Frias | 1957816 | 2013-05-13 18:01:12 +0000 | [diff] [blame] | 18 | #include <asm/imx-common/mxc_i2c.h> |
Otavio Salvador | 85449db | 2013-03-16 08:05:07 +0000 | [diff] [blame] | 19 | #include <asm/imx-common/boot_mode.h> |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 20 | #include <mmc.h> |
| 21 | #include <fsl_esdhc.h> |
Fabio Estevam | fe5ebe9 | 2012-09-25 08:43:57 +0000 | [diff] [blame] | 22 | #include <miiphy.h> |
| 23 | #include <netdev.h> |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 24 | #include <asm/arch/sys_proto.h> |
Renato Frias | 1957816 | 2013-05-13 18:01:12 +0000 | [diff] [blame] | 25 | #include <i2c.h> |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 26 | |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Benoît Thébaudeau | 7e2173c | 2013-04-26 01:34:47 +0000 | [diff] [blame] | 29 | #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 30 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ |
| 31 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 32 | |
Benoît Thébaudeau | 7e2173c | 2013-04-26 01:34:47 +0000 | [diff] [blame] | 33 | #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \ |
| 34 | PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \ |
| 35 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 36 | |
Benoît Thébaudeau | 7e2173c | 2013-04-26 01:34:47 +0000 | [diff] [blame] | 37 | #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 38 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS) |
Fabio Estevam | fe5ebe9 | 2012-09-25 08:43:57 +0000 | [diff] [blame] | 39 | |
Renato Frias | 1957816 | 2013-05-13 18:01:12 +0000 | [diff] [blame] | 40 | #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ |
| 41 | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \ |
| 42 | PAD_CTL_ODE | PAD_CTL_SRE_FAST) |
| 43 | |
| 44 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
| 45 | |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 46 | int dram_init(void) |
| 47 | { |
| 48 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Eric Nelson | 6e14232 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 53 | iomux_v3_cfg_t const uart4_pads[] = { |
Eric Nelson | cfb8b9d | 2013-02-19 10:07:01 +0000 | [diff] [blame] | 54 | MX6_PAD_KEY_COL0__UART4_TXD | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 55 | MX6_PAD_KEY_ROW0__UART4_RXD | MUX_PAD_CTRL(UART_PAD_CTRL), |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Eric Nelson | 6e14232 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 58 | iomux_v3_cfg_t const enet_pads[] = { |
Eric Nelson | cfb8b9d | 2013-02-19 10:07:01 +0000 | [diff] [blame] | 59 | MX6_PAD_KEY_COL1__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 60 | MX6_PAD_KEY_COL2__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 61 | MX6_PAD_RGMII_TXC__ENET_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 62 | MX6_PAD_RGMII_TD0__ENET_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 63 | MX6_PAD_RGMII_TD1__ENET_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 64 | MX6_PAD_RGMII_TD2__ENET_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 65 | MX6_PAD_RGMII_TD3__ENET_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 66 | MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 67 | MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 68 | MX6_PAD_RGMII_RXC__ENET_RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 69 | MX6_PAD_RGMII_RD0__ENET_RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 70 | MX6_PAD_RGMII_RD1__ENET_RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 71 | MX6_PAD_RGMII_RD2__ENET_RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 72 | MX6_PAD_RGMII_RD3__ENET_RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 73 | MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL), |
Fabio Estevam | fe5ebe9 | 2012-09-25 08:43:57 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
Renato Frias | 1957816 | 2013-05-13 18:01:12 +0000 | [diff] [blame] | 76 | /* I2C2 PMIC, iPod, Tuner, Codec, Touch, HDMI EDID, MIPI CSI2 card */ |
| 77 | struct i2c_pads_info i2c_pad_info1 = { |
| 78 | .scl = { |
| 79 | .i2c_mode = MX6_PAD_EIM_EB2__I2C2_SCL | PC, |
| 80 | .gpio_mode = MX6_PAD_EIM_EB2__GPIO_2_30 | PC, |
| 81 | .gp = IMX_GPIO_NR(2, 30) |
| 82 | }, |
| 83 | .sda = { |
| 84 | .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC, |
| 85 | .gpio_mode = MX6_PAD_KEY_ROW3__GPIO_4_13 | PC, |
| 86 | .gp = IMX_GPIO_NR(4, 13) |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * I2C3 MLB, Port Expanders (A, B, C), Video ADC, Light Sensor, |
| 92 | * Compass Sensor, Accelerometer, Res Touch |
| 93 | */ |
| 94 | struct i2c_pads_info i2c_pad_info2 = { |
| 95 | .scl = { |
| 96 | .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC, |
| 97 | .gpio_mode = MX6_PAD_GPIO_3__GPIO_1_3 | PC, |
| 98 | .gp = IMX_GPIO_NR(1, 3) |
| 99 | }, |
| 100 | .sda = { |
| 101 | .i2c_mode = MX6_PAD_EIM_D18__I2C3_SDA | PC, |
| 102 | .gpio_mode = MX6_PAD_EIM_D18__GPIO_3_18 | PC, |
| 103 | .gp = IMX_GPIO_NR(3, 18) |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | iomux_v3_cfg_t const i2c3_pads[] = { |
| 108 | MX6_PAD_EIM_A24__GPIO_5_4 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 109 | }; |
| 110 | |
Renato Frias | a1f6780 | 2013-05-13 18:01:13 +0000 | [diff] [blame] | 111 | iomux_v3_cfg_t const port_exp[] = { |
| 112 | MX6_PAD_SD2_DAT0__GPIO_1_15 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 113 | }; |
| 114 | |
Fabio Estevam | fe5ebe9 | 2012-09-25 08:43:57 +0000 | [diff] [blame] | 115 | static void setup_iomux_enet(void) |
| 116 | { |
| 117 | imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads)); |
| 118 | } |
| 119 | |
Eric Nelson | 6e14232 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 120 | iomux_v3_cfg_t const usdhc3_pads[] = { |
Eric Nelson | cfb8b9d | 2013-02-19 10:07:01 +0000 | [diff] [blame] | 121 | MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 122 | MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 123 | MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 124 | MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 125 | MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 126 | MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 127 | MX6_PAD_SD3_DAT4__USDHC3_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 128 | MX6_PAD_SD3_DAT5__USDHC3_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 129 | MX6_PAD_SD3_DAT6__USDHC3_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 130 | MX6_PAD_SD3_DAT7__USDHC3_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 131 | MX6_PAD_GPIO_18__USDHC3_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 132 | MX6_PAD_NANDF_CS2__GPIO_6_15 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | static void setup_iomux_uart(void) |
| 136 | { |
| 137 | imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads)); |
| 138 | } |
| 139 | |
| 140 | #ifdef CONFIG_FSL_ESDHC |
| 141 | struct fsl_esdhc_cfg usdhc_cfg[1] = { |
| 142 | {USDHC3_BASE_ADDR}, |
| 143 | }; |
| 144 | |
| 145 | int board_mmc_getcd(struct mmc *mmc) |
| 146 | { |
| 147 | gpio_direction_input(IMX_GPIO_NR(6, 15)); |
| 148 | return !gpio_get_value(IMX_GPIO_NR(6, 15)); |
| 149 | } |
| 150 | |
| 151 | int board_mmc_init(bd_t *bis) |
| 152 | { |
| 153 | imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads)); |
| 154 | |
Benoît Thébaudeau | a2ac1b3 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 155 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 156 | return fsl_esdhc_initialize(bis, &usdhc_cfg[0]); |
| 157 | } |
| 158 | #endif |
| 159 | |
Fabio Estevam | fe5ebe9 | 2012-09-25 08:43:57 +0000 | [diff] [blame] | 160 | int mx6_rgmii_rework(struct phy_device *phydev) |
| 161 | { |
| 162 | unsigned short val; |
| 163 | |
| 164 | /* To enable AR8031 ouput a 125MHz clk from CLK_25M */ |
| 165 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7); |
| 166 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016); |
| 167 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007); |
| 168 | |
| 169 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe); |
| 170 | val &= 0xffe3; |
| 171 | val |= 0x18; |
| 172 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val); |
| 173 | |
| 174 | /* introduce tx clock delay */ |
| 175 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5); |
| 176 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e); |
| 177 | val |= 0x0100; |
| 178 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val); |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | int board_phy_config(struct phy_device *phydev) |
| 184 | { |
| 185 | mx6_rgmii_rework(phydev); |
| 186 | |
| 187 | if (phydev->drv->config) |
| 188 | phydev->drv->config(phydev); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | int board_eth_init(bd_t *bis) |
| 194 | { |
| 195 | int ret; |
| 196 | |
| 197 | setup_iomux_enet(); |
| 198 | |
| 199 | ret = cpu_eth_init(bis); |
| 200 | if (ret) |
| 201 | printf("FEC MXC: %s:failed\n", __func__); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 206 | #define BOARD_REV_B 0x200 |
| 207 | #define BOARD_REV_A 0x100 |
| 208 | |
| 209 | static int mx6sabre_rev(void) |
| 210 | { |
| 211 | /* |
| 212 | * Get Board ID information from OCOTP_GP1[15:8] |
| 213 | * i.MX6Q ARD RevA: 0x01 |
| 214 | * i.MX6Q ARD RevB: 0x02 |
| 215 | */ |
| 216 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
Benoît Thébaudeau | 8f3ff11 | 2013-04-23 10:17:38 +0000 | [diff] [blame] | 217 | struct fuse_bank *bank = &ocotp->bank[4]; |
| 218 | struct fuse_bank4_regs *fuse = |
| 219 | (struct fuse_bank4_regs *)bank->fuse_regs; |
| 220 | int reg = readl(&fuse->gp1); |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 221 | int ret; |
| 222 | |
| 223 | switch (reg >> 8 & 0x0F) { |
| 224 | case 0x02: |
| 225 | ret = BOARD_REV_B; |
| 226 | break; |
| 227 | case 0x01: |
| 228 | default: |
| 229 | ret = BOARD_REV_A; |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 236 | u32 get_board_rev(void) |
| 237 | { |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 238 | int rev = mx6sabre_rev(); |
| 239 | |
| 240 | return (get_cpu_rev() & ~(0xF << 8)) | rev; |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | int board_early_init_f(void) |
| 244 | { |
| 245 | setup_iomux_uart(); |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | int board_init(void) |
| 251 | { |
| 252 | /* address of boot parameters */ |
| 253 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 254 | |
Renato Frias | 1957816 | 2013-05-13 18:01:12 +0000 | [diff] [blame] | 255 | /* I2C 2 and 3 setup - I2C 3 hw mux with EIM */ |
| 256 | setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1); |
| 257 | /* I2C 3 Steer */ |
| 258 | gpio_direction_output(IMX_GPIO_NR(5, 4), 1); |
| 259 | imx_iomux_v3_setup_multiple_pads(i2c3_pads, ARRAY_SIZE(i2c3_pads)); |
| 260 | setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2); |
| 261 | |
Renato Frias | a1f6780 | 2013-05-13 18:01:13 +0000 | [diff] [blame] | 262 | gpio_direction_output(IMX_GPIO_NR(1, 15), 1); |
| 263 | imx_iomux_v3_setup_multiple_pads(port_exp, ARRAY_SIZE(port_exp)); |
| 264 | |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
Otavio Salvador | 85449db | 2013-03-16 08:05:07 +0000 | [diff] [blame] | 268 | #ifdef CONFIG_CMD_BMODE |
| 269 | static const struct boot_mode board_boot_modes[] = { |
| 270 | /* 4 bit bus width */ |
| 271 | {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 272 | {NULL, 0}, |
| 273 | }; |
| 274 | #endif |
| 275 | |
| 276 | int board_late_init(void) |
| 277 | { |
| 278 | #ifdef CONFIG_CMD_BMODE |
| 279 | add_board_boot_modes(board_boot_modes); |
| 280 | #endif |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 285 | int checkboard(void) |
| 286 | { |
Fabio Estevam | dce67bd | 2012-10-02 11:20:12 +0000 | [diff] [blame] | 287 | int rev = mx6sabre_rev(); |
| 288 | char *revname; |
| 289 | |
| 290 | switch (rev) { |
| 291 | case BOARD_REV_B: |
| 292 | revname = "B"; |
| 293 | break; |
| 294 | case BOARD_REV_A: |
| 295 | default: |
| 296 | revname = "A"; |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | printf("Board: MX6Q-Sabreauto rev%s\n", revname); |
Fabio Estevam | 7dd6545 | 2012-09-24 08:09:33 +0000 | [diff] [blame] | 301 | |
| 302 | return 0; |
| 303 | } |