Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 6 | #include <init.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/crm_regs.h> |
| 9 | #include <asm/arch/imx-regs.h> |
| 10 | #include <asm/arch/mx7-pins.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 13 | #include <asm/mach-imx/iomux-v3.h> |
| 14 | #include <asm/mach-imx/mxc_i2c.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <common.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 17 | #include <i2c.h> |
| 18 | #include <miiphy.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 19 | #include <netdev.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 20 | #include <power/pmic.h> |
| 21 | #include <power/pfuze3000_pmic.h> |
| 22 | #include "../../freescale/common/pfuze.h" |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | #define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \ |
| 27 | PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS) |
| 28 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 29 | #define ENET_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM) |
| 30 | #define ENET_PAD_CTRL_MII (PAD_CTL_DSE_3P3V_32OHM) |
| 31 | |
| 32 | #define ENET_RX_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM) |
| 33 | |
| 34 | #define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \ |
| 35 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU100KOHM) |
| 36 | |
| 37 | #ifdef CONFIG_SYS_I2C_MXC |
| 38 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 39 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 40 | /* I2C4 for PMIC */ |
| 41 | static struct i2c_pads_info i2c_pad_info4 = { |
| 42 | .scl = { |
| 43 | .i2c_mode = MX7D_PAD_SAI1_RX_SYNC__I2C4_SCL | PC, |
| 44 | .gpio_mode = MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16 | PC, |
| 45 | .gp = IMX_GPIO_NR(6, 16), |
| 46 | }, |
| 47 | .sda = { |
| 48 | .i2c_mode = MX7D_PAD_SAI1_RX_BCLK__I2C4_SDA | PC, |
| 49 | .gpio_mode = MX7D_PAD_SAI1_RX_BCLK__GPIO6_IO17 | PC, |
| 50 | .gp = IMX_GPIO_NR(6, 17), |
| 51 | }, |
| 52 | }; |
| 53 | #endif |
| 54 | |
| 55 | int dram_init(void) |
| 56 | { |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 57 | gd->ram_size = imx_ddr_size(); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 58 | |
Jun Nie | feb1344 | 2019-05-08 14:38:32 +0800 | [diff] [blame] | 59 | /* Subtract the defined OPTEE runtime firmware length */ |
| 60 | #ifdef CONFIG_OPTEE_TZDRAM_SIZE |
| 61 | gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE; |
| 62 | #endif |
| 63 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | #ifdef CONFIG_POWER |
| 68 | #define I2C_PMIC 3 |
| 69 | int power_init_board(void) |
| 70 | { |
| 71 | struct pmic *p; |
| 72 | int ret; |
| 73 | unsigned int reg, rev_id; |
| 74 | |
| 75 | ret = power_pfuze3000_init(I2C_PMIC); |
| 76 | if (ret) |
| 77 | return ret; |
| 78 | |
| 79 | p = pmic_get("PFUZE3000"); |
| 80 | ret = pmic_probe(p); |
Jun Nie | 8600eef | 2019-05-08 14:38:36 +0800 | [diff] [blame] | 81 | if (ret) { |
| 82 | printf("Warning: Cannot find PMIC PFUZE3000\n"); |
| 83 | printf("\tPower consumption is not optimized.\n"); |
| 84 | return 0; |
| 85 | } |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 86 | |
| 87 | pmic_reg_read(p, PFUZE3000_DEVICEID, ®); |
| 88 | pmic_reg_read(p, PFUZE3000_REVID, &rev_id); |
| 89 | printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id); |
| 90 | |
| 91 | /* disable Low Power Mode during standby mode */ |
| 92 | pmic_reg_read(p, PFUZE3000_LDOGCTL, ®); |
| 93 | reg |= 0x1; |
| 94 | pmic_reg_write(p, PFUZE3000_LDOGCTL, reg); |
| 95 | |
| 96 | /* SW1A/1B mode set to APS/APS */ |
| 97 | reg = 0x8; |
| 98 | pmic_reg_write(p, PFUZE3000_SW1AMODE, reg); |
| 99 | pmic_reg_write(p, PFUZE3000_SW1BMODE, reg); |
| 100 | |
| 101 | /* SW1A/1B standby voltage set to 1.025V */ |
| 102 | reg = 0xd; |
| 103 | pmic_reg_write(p, PFUZE3000_SW1ASTBY, reg); |
| 104 | pmic_reg_write(p, PFUZE3000_SW1BSTBY, reg); |
| 105 | |
| 106 | /* decrease SW1B normal voltage to 0.975V */ |
| 107 | pmic_reg_read(p, PFUZE3000_SW1BVOLT, ®); |
| 108 | reg &= ~0x1f; |
| 109 | reg |= PFUZE3000_SW1AB_SETP(975); |
| 110 | pmic_reg_write(p, PFUZE3000_SW1BVOLT, reg); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 117 | MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 118 | }; |
| 119 | |
| 120 | static iomux_v3_cfg_t const uart5_pads[] = { |
| 121 | MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 122 | MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 123 | }; |
| 124 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 125 | #ifdef CONFIG_FEC_MXC |
| 126 | static iomux_v3_cfg_t const fec1_pads[] = { |
| 127 | MX7D_PAD_SD2_CD_B__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL_MII), |
| 128 | MX7D_PAD_SD2_WP__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL_MII), |
| 129 | MX7D_PAD_ENET1_RGMII_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 130 | MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 131 | MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 132 | MX7D_PAD_ENET1_RGMII_TD2__ENET1_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 133 | MX7D_PAD_ENET1_RGMII_TD3__ENET1_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 134 | MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL), |
| 135 | MX7D_PAD_ENET1_RGMII_RXC__ENET1_RGMII_RXC | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 136 | MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 137 | MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 138 | MX7D_PAD_ENET1_RGMII_RD2__ENET1_RGMII_RD2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 139 | MX7D_PAD_ENET1_RGMII_RD3__ENET1_RGMII_RD3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 140 | MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL | MUX_PAD_CTRL(ENET_RX_PAD_CTRL), |
| 141 | MX7D_PAD_SD3_STROBE__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 142 | MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 143 | }; |
| 144 | |
| 145 | #define FEC1_RST_GPIO IMX_GPIO_NR(6, 11) |
| 146 | |
| 147 | static void setup_iomux_fec(void) |
| 148 | { |
| 149 | imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads)); |
Joris Offouga | 0dc6a40e | 2019-04-04 14:00:54 +0200 | [diff] [blame] | 150 | gpio_request(FEC1_RST_GPIO, "phy_rst"); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 151 | gpio_direction_output(FEC1_RST_GPIO, 0); |
| 152 | udelay(500); |
| 153 | gpio_set_value(FEC1_RST_GPIO, 1); |
| 154 | } |
| 155 | |
| 156 | int board_eth_init(bd_t *bis) |
| 157 | { |
| 158 | setup_iomux_fec(); |
| 159 | |
| 160 | return fecmxc_initialize_multi(bis, 0, |
| 161 | CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE); |
| 162 | } |
| 163 | |
| 164 | static int setup_fec(void) |
| 165 | { |
| 166 | struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs |
| 167 | = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 168 | |
| 169 | /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */ |
| 170 | clrsetbits_le32(&iomuxc_gpr_regs->gpr[1], |
| 171 | (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK | |
| 172 | IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0); |
| 173 | |
Eric Nelson | eadd732 | 2017-08-31 08:34:23 -0700 | [diff] [blame] | 174 | return set_clk_enet(ENET_125MHZ); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | int board_phy_config(struct phy_device *phydev) |
| 178 | { |
| 179 | unsigned short val; |
| 180 | |
| 181 | /* To enable AR8035 ouput a 125MHz clk from CLK_25M */ |
| 182 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7); |
| 183 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016); |
| 184 | phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007); |
| 185 | |
| 186 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe); |
| 187 | val &= 0xffe7; |
| 188 | val |= 0x18; |
| 189 | phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val); |
| 190 | |
| 191 | /* introduce tx clock delay */ |
| 192 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5); |
| 193 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e); |
| 194 | val |= 0x0100; |
| 195 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val); |
| 196 | |
| 197 | if (phydev->drv->config) |
| 198 | phydev->drv->config(phydev); |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | #endif |
| 203 | |
| 204 | static void setup_iomux_uart(void) |
| 205 | { |
| 206 | imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads)); |
| 207 | } |
| 208 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 209 | int board_early_init_f(void) |
| 210 | { |
| 211 | setup_iomux_uart(); |
| 212 | |
| 213 | #ifdef CONFIG_SYS_I2C_MXC |
| 214 | setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4); |
| 215 | #endif |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Joris Offouga | daf2be1 | 2019-08-30 14:44:36 +0200 | [diff] [blame] | 220 | #ifdef CONFIG_DM_VIDEO |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 221 | void setup_lcd(void) |
| 222 | { |
Joris Offouga | 0dc6a40e | 2019-04-04 14:00:54 +0200 | [diff] [blame] | 223 | gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness"); |
| 224 | gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable"); |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 225 | /* Set Brightness to high */ |
| 226 | gpio_direction_output(IMX_GPIO_NR(1, 11) , 1); |
| 227 | /* Set LCD enable to high */ |
| 228 | gpio_direction_output(IMX_GPIO_NR(1, 6) , 1); |
| 229 | } |
| 230 | #endif |
| 231 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 232 | int board_init(void) |
| 233 | { |
| 234 | /* address of boot parameters */ |
| 235 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 236 | |
Joris Offouga | daf2be1 | 2019-08-30 14:44:36 +0200 | [diff] [blame] | 237 | #ifdef CONFIG_DM_VIDEO |
Joris Offouga | daf2be1 | 2019-08-30 14:44:36 +0200 | [diff] [blame] | 238 | |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 239 | setup_lcd(); |
Joris Offouga | daf2be1 | 2019-08-30 14:44:36 +0200 | [diff] [blame] | 240 | |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 241 | #endif |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 242 | #ifdef CONFIG_FEC_MXC |
| 243 | setup_fec(); |
| 244 | #endif |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | int board_late_init(void) |
| 250 | { |
| 251 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 252 | |
| 253 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 254 | |
| 255 | set_wdog_reset(wdog); |
| 256 | |
| 257 | /* |
| 258 | * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4), |
| 259 | * since we use PMIC_PWRON to reset the board. |
| 260 | */ |
| 261 | clrsetbits_le16(&wdog->wcr, 0, 0x10); |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | int checkboard(void) |
| 267 | { |
| 268 | puts("Board: i.MX7D PICOSOM\n"); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Fabio Estevam | 7d8a02a | 2018-09-28 11:22:39 -0300 | [diff] [blame] | 273 | static iomux_v3_cfg_t const usb_otg2_pads[] = { |
| 274 | MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 275 | }; |
| 276 | |
| 277 | int board_ehci_hcd_init(int port) |
| 278 | { |
| 279 | switch (port) { |
| 280 | case 0: |
| 281 | break; |
| 282 | case 1: |
| 283 | imx_iomux_v3_setup_multiple_pads(usb_otg2_pads, |
| 284 | ARRAY_SIZE(usb_otg2_pads)); |
| 285 | break; |
| 286 | default: |
| 287 | return -EINVAL; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |