15d6050fdSStefan Roese /* 25d6050fdSStefan Roese * Copyright (C) 2014, Barco (www.barco.com) 35d6050fdSStefan Roese * Copyright (C) 2014 Stefan Roese <sr@denx.de> 45d6050fdSStefan Roese * 55d6050fdSStefan Roese * SPDX-License-Identifier: GPL-2.0+ 65d6050fdSStefan Roese */ 75d6050fdSStefan Roese 85d6050fdSStefan Roese #include <common.h> 95d6050fdSStefan Roese #include <asm/gpio.h> 105d6050fdSStefan Roese #include <asm/io.h> 115d6050fdSStefan Roese #include <asm/arch/clock.h> 125d6050fdSStefan Roese #include <asm/arch/iomux.h> 135d6050fdSStefan Roese #include <asm/arch/mx6-pins.h> 145d6050fdSStefan Roese #include <asm/imx-common/iomux-v3.h> 155d6050fdSStefan Roese #include <asm/imx-common/mxc_i2c.h> 165d6050fdSStefan Roese #include <i2c.h> 175d6050fdSStefan Roese #include <miiphy.h> 185d6050fdSStefan Roese 195d6050fdSStefan Roese #include "platinum.h" 205d6050fdSStefan Roese 215d6050fdSStefan Roese #define GPIO_IP_NCONFIG IMX_GPIO_NR(5, 18) 225d6050fdSStefan Roese #define GPIO_HK_NCONFIG IMX_GPIO_NR(7, 13) 235d6050fdSStefan Roese #define GPIO_LS_NCONFIG IMX_GPIO_NR(5, 19) 245d6050fdSStefan Roese 255d6050fdSStefan Roese #define GPIO_I2C0_SEL0 IMX_GPIO_NR(5, 2) 265d6050fdSStefan Roese #define GPIO_I2C0_SEL1 IMX_GPIO_NR(1, 11) 275d6050fdSStefan Roese #define GPIO_I2C0_ENBN IMX_GPIO_NR(1, 13) 285d6050fdSStefan Roese 295d6050fdSStefan Roese #define GPIO_I2C2_SEL0 IMX_GPIO_NR(1, 17) 305d6050fdSStefan Roese #define GPIO_I2C2_SEL1 IMX_GPIO_NR(1, 20) 315d6050fdSStefan Roese #define GPIO_I2C2_ENBN IMX_GPIO_NR(1, 14) 325d6050fdSStefan Roese 335d6050fdSStefan Roese #define GPIO_USB_RESET IMX_GPIO_NR(1, 5) 345d6050fdSStefan Roese 355d6050fdSStefan Roese iomux_v3_cfg_t const ecspi1_pads[] = { 365d6050fdSStefan Roese MX6_PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(ECSPI1_PAD_CLK), 375d6050fdSStefan Roese MX6_PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(ECSPI_PAD_MISO), 385d6050fdSStefan Roese MX6_PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(ECSPI_PAD_MOSI), 395d6050fdSStefan Roese MX6_PAD_CSI0_DAT7__ECSPI1_SS0 | MUX_PAD_CTRL(ECSPI_PAD_SS), 405d6050fdSStefan Roese MX6_PAD_EIM_D24__ECSPI1_SS2 | MUX_PAD_CTRL(ECSPI_PAD_SS), 415d6050fdSStefan Roese MX6_PAD_EIM_D25__ECSPI1_SS3 | MUX_PAD_CTRL(ECSPI_PAD_SS), 425d6050fdSStefan Roese }; 435d6050fdSStefan Roese 445d6050fdSStefan Roese iomux_v3_cfg_t const ecspi2_pads[] = { 455d6050fdSStefan Roese MX6_PAD_EIM_CS0__ECSPI2_SCLK | MUX_PAD_CTRL(ECSPI2_PAD_CLK), 465d6050fdSStefan Roese MX6_PAD_EIM_OE__ECSPI2_MISO | MUX_PAD_CTRL(ECSPI_PAD_MISO), 475d6050fdSStefan Roese MX6_PAD_EIM_CS1__ECSPI2_MOSI | MUX_PAD_CTRL(ECSPI_PAD_MOSI), 485d6050fdSStefan Roese MX6_PAD_EIM_RW__ECSPI2_SS0 | MUX_PAD_CTRL(ECSPI_PAD_SS), 495d6050fdSStefan Roese MX6_PAD_EIM_LBA__ECSPI2_SS1 | MUX_PAD_CTRL(ECSPI_PAD_SS), 505d6050fdSStefan Roese }; 515d6050fdSStefan Roese 525d6050fdSStefan Roese iomux_v3_cfg_t const enet_pads[] = { 535d6050fdSStefan Roese MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL), 545d6050fdSStefan Roese MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL), 555d6050fdSStefan Roese MX6_PAD_ENET_CRS_DV__ENET_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL), 565d6050fdSStefan Roese MX6_PAD_GPIO_16__ENET_REF_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL), 575d6050fdSStefan Roese MX6_PAD_ENET_RX_ER__ENET_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL), 585d6050fdSStefan Roese MX6_PAD_ENET_RXD0__ENET_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL), 595d6050fdSStefan Roese MX6_PAD_ENET_RXD1__ENET_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL), 605d6050fdSStefan Roese MX6_PAD_ENET_TX_EN__ENET_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL), 615d6050fdSStefan Roese MX6_PAD_ENET_TXD0__ENET_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL), 625d6050fdSStefan Roese MX6_PAD_ENET_TXD1__ENET_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL), 635d6050fdSStefan Roese }; 645d6050fdSStefan Roese 655d6050fdSStefan Roese /* PHY nRESET */ 665d6050fdSStefan Roese iomux_v3_cfg_t const phy_reset_pad = { 675d6050fdSStefan Roese MX6_PAD_SD1_DAT2__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL), 685d6050fdSStefan Roese }; 695d6050fdSStefan Roese 705d6050fdSStefan Roese iomux_v3_cfg_t const uart1_pads[] = { 715d6050fdSStefan Roese MX6_PAD_SD3_DAT6__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 725d6050fdSStefan Roese MX6_PAD_SD3_DAT7__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 735d6050fdSStefan Roese }; 745d6050fdSStefan Roese 755d6050fdSStefan Roese iomux_v3_cfg_t const uart4_pads[] = { 765d6050fdSStefan Roese MX6_PAD_CSI0_DAT12__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 775d6050fdSStefan Roese MX6_PAD_CSI0_DAT13__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 785d6050fdSStefan Roese MX6_PAD_CSI0_DAT16__UART4_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL), 795d6050fdSStefan Roese MX6_PAD_CSI0_DAT17__UART4_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL), 805d6050fdSStefan Roese }; 815d6050fdSStefan Roese 825d6050fdSStefan Roese iomux_v3_cfg_t const uart5_pads[] = { 835d6050fdSStefan Roese MX6_PAD_CSI0_DAT14__UART5_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 845d6050fdSStefan Roese MX6_PAD_CSI0_DAT15__UART5_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL), 855d6050fdSStefan Roese MX6_PAD_CSI0_DAT18__UART5_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL), 865d6050fdSStefan Roese MX6_PAD_CSI0_DAT19__UART5_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL), 875d6050fdSStefan Roese }; 885d6050fdSStefan Roese 895d6050fdSStefan Roese iomux_v3_cfg_t const i2c0_mux_pads[] = { 905d6050fdSStefan Roese MX6_PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), 915d6050fdSStefan Roese MX6_PAD_SD2_CMD__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), 925d6050fdSStefan Roese MX6_PAD_SD2_DAT2__GPIO1_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL), 935d6050fdSStefan Roese }; 945d6050fdSStefan Roese 955d6050fdSStefan Roese iomux_v3_cfg_t const i2c2_mux_pads[] = { 965d6050fdSStefan Roese MX6_PAD_SD1_DAT1__GPIO1_IO17 | MUX_PAD_CTRL(NO_PAD_CTRL), 975d6050fdSStefan Roese MX6_PAD_SD1_CLK__GPIO1_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL), 985d6050fdSStefan Roese MX6_PAD_SD2_DAT1__GPIO1_IO14 | MUX_PAD_CTRL(NO_PAD_CTRL), 995d6050fdSStefan Roese }; 1005d6050fdSStefan Roese 1015d6050fdSStefan Roese struct i2c_pads_info i2c_pad_info0 = { 1025d6050fdSStefan Roese .scl = { 1035d6050fdSStefan Roese .i2c_mode = MX6_PAD_CSI0_DAT9__I2C1_SCL | PC_SCL, 1045d6050fdSStefan Roese .gpio_mode = MX6_PAD_CSI0_DAT9__GPIO5_IO27 | PC_SCL, 1055d6050fdSStefan Roese .gp = IMX_GPIO_NR(5, 27) 1065d6050fdSStefan Roese }, 1075d6050fdSStefan Roese .sda = { 1085d6050fdSStefan Roese .i2c_mode = MX6_PAD_CSI0_DAT8__I2C1_SDA | PC, 1095d6050fdSStefan Roese .gpio_mode = MX6_PAD_CSI0_DAT8__GPIO5_IO26 | PC, 1105d6050fdSStefan Roese .gp = IMX_GPIO_NR(5, 26) 1115d6050fdSStefan Roese } 1125d6050fdSStefan Roese }; 1135d6050fdSStefan Roese 1145d6050fdSStefan Roese struct i2c_pads_info i2c_pad_info2 = { 1155d6050fdSStefan Roese .scl = { 1165d6050fdSStefan Roese .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC_SCL, 1175d6050fdSStefan Roese .gpio_mode = MX6_PAD_GPIO_3__GPIO1_IO03 | PC_SCL, 1185d6050fdSStefan Roese .gp = IMX_GPIO_NR(1, 3) 1195d6050fdSStefan Roese }, 1205d6050fdSStefan Roese .sda = { 1215d6050fdSStefan Roese .i2c_mode = MX6_PAD_GPIO_6__I2C3_SDA | PC, 1225d6050fdSStefan Roese .gpio_mode = MX6_PAD_GPIO_6__GPIO1_IO06 | PC, 1235d6050fdSStefan Roese .gp = IMX_GPIO_NR(1, 6) 1245d6050fdSStefan Roese } 1255d6050fdSStefan Roese }; 1265d6050fdSStefan Roese 1275d6050fdSStefan Roese /* 1285d6050fdSStefan Roese * This enet related pin-muxing and GPIO handling is done 1295d6050fdSStefan Roese * in SPL U-Boot. For early initialization. And to give the 1305d6050fdSStefan Roese * PHY some time to come out of reset before the U-Boot 1315d6050fdSStefan Roese * ethernet driver tries to access its registers via MDIO. 1325d6050fdSStefan Roese */ 1335d6050fdSStefan Roese int platinum_setup_enet(void) 1345d6050fdSStefan Roese { 1355d6050fdSStefan Roese struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; 1365d6050fdSStefan Roese unsigned phy_reset = IMX_GPIO_NR(1, 19); 1375d6050fdSStefan Roese 1385d6050fdSStefan Roese /* First configure PHY reset GPIO pin */ 1395d6050fdSStefan Roese imx_iomux_v3_setup_pad(phy_reset_pad); 1405d6050fdSStefan Roese 1415d6050fdSStefan Roese /* Reconfigure enet muxing while PHY is in reset */ 1425d6050fdSStefan Roese gpio_direction_output(phy_reset, 0); 1435d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads)); 1445d6050fdSStefan Roese mdelay(10); 1455d6050fdSStefan Roese gpio_set_value(phy_reset, 1); 1465d6050fdSStefan Roese udelay(100); 1475d6050fdSStefan Roese 1485d6050fdSStefan Roese /* set GPIO_16 as ENET_REF_CLK_OUT */ 1495d6050fdSStefan Roese setbits_le32(&iomux->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK); 1505d6050fdSStefan Roese 151*6d97dc10SPeng Fan return enable_fec_anatop_clock(0, ENET_50MHZ); 1525d6050fdSStefan Roese } 1535d6050fdSStefan Roese 1545d6050fdSStefan Roese int platinum_setup_i2c(void) 1555d6050fdSStefan Roese { 1565d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(i2c0_mux_pads, 1575d6050fdSStefan Roese ARRAY_SIZE(i2c0_mux_pads)); 1585d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(i2c2_mux_pads, 1595d6050fdSStefan Roese ARRAY_SIZE(i2c2_mux_pads)); 1605d6050fdSStefan Roese 1615d6050fdSStefan Roese mdelay(10); 1625d6050fdSStefan Roese 1635d6050fdSStefan Roese /* Disable i2c mux 0 */ 1645d6050fdSStefan Roese gpio_direction_output(GPIO_I2C0_SEL0, 0); 1655d6050fdSStefan Roese gpio_direction_output(GPIO_I2C0_SEL1, 0); 1665d6050fdSStefan Roese gpio_direction_output(GPIO_I2C0_ENBN, 1); 1675d6050fdSStefan Roese 1685d6050fdSStefan Roese /* Disable i2c mux 1 */ 1695d6050fdSStefan Roese gpio_direction_output(GPIO_I2C2_SEL0, 0); 1705d6050fdSStefan Roese gpio_direction_output(GPIO_I2C2_SEL1, 0); 1715d6050fdSStefan Roese gpio_direction_output(GPIO_I2C2_ENBN, 1); 1725d6050fdSStefan Roese 1735d6050fdSStefan Roese udelay(10); 1745d6050fdSStefan Roese 1755d6050fdSStefan Roese setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0); 1765d6050fdSStefan Roese setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2); 1775d6050fdSStefan Roese 1785d6050fdSStefan Roese /* Disable all leds */ 1795d6050fdSStefan Roese i2c_set_bus_num(0); 1805d6050fdSStefan Roese i2c_reg_write(0x60, 0x05, 0x55); 1815d6050fdSStefan Roese 1825d6050fdSStefan Roese return 0; 1835d6050fdSStefan Roese } 1845d6050fdSStefan Roese 1855d6050fdSStefan Roese int platinum_setup_spi(void) 1865d6050fdSStefan Roese { 1875d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads)); 1885d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(ecspi2_pads, ARRAY_SIZE(ecspi2_pads)); 1895d6050fdSStefan Roese 1905d6050fdSStefan Roese return 0; 1915d6050fdSStefan Roese } 1925d6050fdSStefan Roese 1935d6050fdSStefan Roese int platinum_setup_uart(void) 1945d6050fdSStefan Roese { 1955d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); 1965d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads)); 1975d6050fdSStefan Roese imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads)); 1985d6050fdSStefan Roese 1995d6050fdSStefan Roese return 0; 2005d6050fdSStefan Roese } 2015d6050fdSStefan Roese 2025d6050fdSStefan Roese int platinum_phy_config(struct phy_device *phydev) 2035d6050fdSStefan Roese { 2045d6050fdSStefan Roese /* Use generic infrastructure, no specific setup */ 2055d6050fdSStefan Roese if (phydev->drv->config) 2065d6050fdSStefan Roese phydev->drv->config(phydev); 2075d6050fdSStefan Roese 2085d6050fdSStefan Roese return 0; 2095d6050fdSStefan Roese } 2105d6050fdSStefan Roese 2115d6050fdSStefan Roese int platinum_init_gpio(void) 2125d6050fdSStefan Roese { 2135d6050fdSStefan Roese /* Reset FPGA's */ 2145d6050fdSStefan Roese gpio_direction_output(GPIO_IP_NCONFIG, 0); 2155d6050fdSStefan Roese gpio_direction_output(GPIO_HK_NCONFIG, 0); 2165d6050fdSStefan Roese gpio_direction_output(GPIO_LS_NCONFIG, 0); 2175d6050fdSStefan Roese udelay(3); 2185d6050fdSStefan Roese gpio_set_value(GPIO_IP_NCONFIG, 1); 2195d6050fdSStefan Roese gpio_set_value(GPIO_HK_NCONFIG, 1); 2205d6050fdSStefan Roese gpio_set_value(GPIO_LS_NCONFIG, 1); 2215d6050fdSStefan Roese 2225d6050fdSStefan Roese /* no dmd configuration yet */ 2235d6050fdSStefan Roese 2245d6050fdSStefan Roese return 0; 2255d6050fdSStefan Roese } 2265d6050fdSStefan Roese 2275d6050fdSStefan Roese int platinum_init_usb(void) 2285d6050fdSStefan Roese { 2295d6050fdSStefan Roese /* Reset usb hub */ 2305d6050fdSStefan Roese gpio_direction_output(GPIO_USB_RESET, 0); 2315d6050fdSStefan Roese udelay(100); 2325d6050fdSStefan Roese gpio_set_value(GPIO_USB_RESET, 1); 2335d6050fdSStefan Roese 2345d6050fdSStefan Roese return 0; 2355d6050fdSStefan Roese } 2365d6050fdSStefan Roese 2375d6050fdSStefan Roese int platinum_init_finished(void) 2385d6050fdSStefan Roese { 2395d6050fdSStefan Roese /* Enable led 0 */ 2405d6050fdSStefan Roese i2c_set_bus_num(0); 2415d6050fdSStefan Roese i2c_reg_write(0x60, 0x05, 0x54); 2425d6050fdSStefan Roese 2435d6050fdSStefan Roese return 0; 2445d6050fdSStefan Roese } 245