2 * U-Boot board functions for CompuLab CL-SOM-iMX7 module
4 * (C) Copyright 2017 CompuLab, Ltd. http://www.compulab.com
6 * Author: Uri Mashiach <uri.mashiach@compulab.co.il>
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <environment.h>
16 #include <fsl_esdhc.h>
17 #include <power/pmic.h>
18 #include <power/pfuze3000_pmic.h>
19 #include <asm/mach-imx/mxc_i2c.h>
20 #include <asm/mach-imx/iomux-v3.h>
21 #include <asm/arch-mx7/mx7-pins.h>
22 #include <asm/arch-mx7/sys_proto.h>
23 #include <asm/arch-mx7/clock.h>
24 #include "../common/eeprom.h"
27 DECLARE_GLOBAL_DATA_PTR;
29 #ifdef CONFIG_SYS_I2C_MXC
31 #define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
34 #define CL_SOM_IMX7_GPIO_I2C2_SCL IMX_GPIO_NR(1, 6)
35 #define CL_SOM_IMX7_GPIO_I2C2_SDA IMX_GPIO_NR(1, 7)
37 static struct i2c_pads_info cl_som_imx7_i2c_pad_info2 = {
39 .i2c_mode = MX7D_PAD_GPIO1_IO06__I2C2_SCL |
40 MUX_PAD_CTRL(I2C_PAD_CTRL),
41 .gpio_mode = MX7D_PAD_GPIO1_IO06__GPIO1_IO6 |
42 MUX_PAD_CTRL(I2C_PAD_CTRL),
43 .gp = CL_SOM_IMX7_GPIO_I2C2_SCL,
46 .i2c_mode = MX7D_PAD_GPIO1_IO07__I2C2_SDA |
47 MUX_PAD_CTRL(I2C_PAD_CTRL),
48 .gpio_mode = MX7D_PAD_GPIO1_IO07__GPIO1_IO7 |
49 MUX_PAD_CTRL(I2C_PAD_CTRL),
50 .gp = CL_SOM_IMX7_GPIO_I2C2_SDA,
55 * cl_som_imx7_setup_i2c() - I2C pinmux configuration.
57 static void cl_som_imx7_setup_i2c(void)
59 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &cl_som_imx7_i2c_pad_info2);
61 #else /* !CONFIG_SYS_I2C_MXC */
62 static void cl_som_imx7_setup_i2c(void) {}
63 #endif /* CONFIG_SYS_I2C_MXC */
67 gd->ram_size = imx_ddr_size();
72 #ifdef CONFIG_FSL_ESDHC
74 #define CL_SOM_IMX7_GPIO_USDHC3_PWR IMX_GPIO_NR(6, 11)
76 static struct fsl_esdhc_cfg cl_som_imx7_usdhc_cfg[3] = {
77 {USDHC1_BASE_ADDR, 0, 4},
81 int board_mmc_init(bd_t *bis)
85 * According to the board_mmc_init() the following map is done:
86 * (U-boot device node) (Physical Port)
90 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
93 cl_som_imx7_usdhc1_pads_set();
94 gpio_request(CL_SOM_IMX7_GPIO_USDHC1_CD, "usdhc1_cd");
95 cl_som_imx7_usdhc_cfg[0].sdhc_clk =
96 mxc_get_clock(MXC_ESDHC_CLK);
99 cl_som_imx7_usdhc3_emmc_pads_set();
100 gpio_request(CL_SOM_IMX7_GPIO_USDHC3_PWR, "usdhc3_pwr");
101 gpio_direction_output(CL_SOM_IMX7_GPIO_USDHC3_PWR, 0);
103 gpio_direction_output(CL_SOM_IMX7_GPIO_USDHC3_PWR, 1);
104 cl_som_imx7_usdhc_cfg[1].sdhc_clk =
105 mxc_get_clock(MXC_ESDHC3_CLK);
108 printf("Warning: you configured more USDHC controllers "
109 "(%d) than supported by the board\n", i + 1);
113 ret = fsl_esdhc_initialize(bis, &cl_som_imx7_usdhc_cfg[i]);
120 #endif /* CONFIG_FSL_ESDHC */
122 #ifdef CONFIG_FEC_MXC
124 #define CL_SOM_IMX7_ETH1_PHY_NRST IMX_GPIO_NR(1, 4)
127 * cl_som_imx7_rgmii_rework() - Ethernet PHY configuration.
129 static void cl_som_imx7_rgmii_rework(struct phy_device *phydev)
133 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
134 * which cause ethernet link down/up issue, so disable SmartEEE
136 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
137 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
138 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
139 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
141 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
143 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
144 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
145 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
146 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
148 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
151 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
153 /* introduce tx clock delay */
154 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
155 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
157 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
160 int board_phy_config(struct phy_device *phydev)
162 cl_som_imx7_rgmii_rework(phydev);
164 if (phydev->drv->config)
165 phydev->drv->config(phydev);
171 * cl_som_imx7_handle_mac_address() - set Ethernet MAC address environment.
173 * @env_var: MAC address environment variable
174 * @eeprom_bus: I2C bus of the environment EEPROM
176 * @return: 0 on success, < 0 on failure
178 static int cl_som_imx7_handle_mac_address(char *env_var, uint eeprom_bus)
181 unsigned char enetaddr[6];
183 ret = eth_env_get_enetaddr(env_var, enetaddr);
187 ret = cl_eeprom_read_mac_addr(enetaddr, eeprom_bus);
191 ret = is_valid_ethaddr(enetaddr);
195 return eth_env_set_enetaddr(env_var, enetaddr);
198 #define CL_SOM_IMX7_FEC_DEV_ID_PRI 0
200 int board_eth_init(bd_t *bis)
202 /* set Ethernet MAC address environment */
203 cl_som_imx7_handle_mac_address("ethaddr", CONFIG_SYS_I2C_EEPROM_BUS);
204 /* Ethernet interface pinmux configuration */
205 cl_som_imx7_phy1_rst_pads_set();
206 cl_som_imx7_fec1_pads_set();
208 gpio_request(CL_SOM_IMX7_ETH1_PHY_NRST, "eth1_phy_nrst");
209 gpio_direction_output(CL_SOM_IMX7_ETH1_PHY_NRST, 0);
211 gpio_set_value(CL_SOM_IMX7_ETH1_PHY_NRST, 1);
212 /* MAC initialization */
213 return fecmxc_initialize_multi(bis, CL_SOM_IMX7_FEC_DEV_ID_PRI,
214 CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE);
218 * cl_som_imx7_setup_fec() - Ethernet MAC 1 clock configuration.
219 * - ENET1 reference clock mode select.
220 * - ENET1_TX_CLK output driver is disabled when configured for ALT1.
222 static void cl_som_imx7_setup_fec(void)
224 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
225 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
227 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
228 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
229 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
230 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
232 set_clk_enet(ENET_125MHZ);
234 #else /* !CONFIG_FEC_MXC */
235 static void cl_som_imx7_setup_fec(void) {}
236 #endif /* CONFIG_FEC_MXC */
240 static void cl_som_imx7_spi_init(void)
242 cl_som_imx7_espi1_pads_set();
244 #else /* !CONFIG_SPI */
245 static void cl_som_imx7_spi_init(void) {}
246 #endif /* CONFIG_SPI */
248 int board_early_init_f(void)
250 cl_som_imx7_uart1_pads_set();
251 cl_som_imx7_usb_otg1_pads_set();
258 /* address of boot parameters */
259 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
260 cl_som_imx7_setup_i2c();
261 cl_som_imx7_setup_fec();
262 cl_som_imx7_spi_init();
269 int power_init_board(void)
273 unsigned int reg, rev_id;
275 ret = power_pfuze3000_init(I2C_PMIC);
279 p = pmic_get("PFUZE3000");
284 pmic_reg_read(p, PFUZE3000_DEVICEID, ®);
285 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
286 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
288 /* disable Low Power Mode during standby mode */
289 pmic_reg_write(p, PFUZE3000_LDOGCTL, 0x1);
293 #endif /* CONFIG_POWER */
296 * cl_som_imx7_setup_wdog() - watchdog configuration.
297 * - Output WDOG_B signal to reset external pmic.
298 * - Suspend the watchdog timer during low-power modes.
300 void cl_som_imx7_setup_wdog(void)
302 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
304 cl_som_imx7_wdog_pads_set();
305 set_wdog_reset(wdog);
307 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
308 * since we use PMIC_PWRON to reset the board.
310 clrsetbits_le16(&wdog->wcr, 0, 0x10);
313 int board_late_init(void)
315 env_set("board_name", "CL-SOM-iMX7");
316 cl_som_imx7_setup_wdog();
324 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
329 printf("Board: CL-SOM-iMX7 in %s mode\n", mode);