1 // SPDX-License-Identifier: GPL-2.0+
3 * U-Boot board functions for CompuLab CL-SOM-iMX7 module
5 * (C) Copyright 2017 CompuLab, Ltd. http://www.compulab.com
7 * Author: Uri Mashiach <uri.mashiach@compulab.co.il>
11 #include <environment.h>
15 #include <fsl_esdhc_imx.h>
16 #include <power/pmic.h>
17 #include <power/pfuze3000_pmic.h>
18 #include <asm/mach-imx/mxc_i2c.h>
19 #include <asm/mach-imx/iomux-v3.h>
20 #include <asm/arch-mx7/mx7-pins.h>
21 #include <asm/arch-mx7/sys_proto.h>
22 #include <asm/arch-mx7/clock.h>
23 #include "../common/eeprom.h"
26 DECLARE_GLOBAL_DATA_PTR;
28 #ifdef CONFIG_SYS_I2C_MXC
30 #define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
33 #define CL_SOM_IMX7_GPIO_I2C2_SCL IMX_GPIO_NR(1, 6)
34 #define CL_SOM_IMX7_GPIO_I2C2_SDA IMX_GPIO_NR(1, 7)
36 static struct i2c_pads_info cl_som_imx7_i2c_pad_info2 = {
38 .i2c_mode = MX7D_PAD_GPIO1_IO06__I2C2_SCL |
39 MUX_PAD_CTRL(I2C_PAD_CTRL),
40 .gpio_mode = MX7D_PAD_GPIO1_IO06__GPIO1_IO6 |
41 MUX_PAD_CTRL(I2C_PAD_CTRL),
42 .gp = CL_SOM_IMX7_GPIO_I2C2_SCL,
45 .i2c_mode = MX7D_PAD_GPIO1_IO07__I2C2_SDA |
46 MUX_PAD_CTRL(I2C_PAD_CTRL),
47 .gpio_mode = MX7D_PAD_GPIO1_IO07__GPIO1_IO7 |
48 MUX_PAD_CTRL(I2C_PAD_CTRL),
49 .gp = CL_SOM_IMX7_GPIO_I2C2_SDA,
54 * cl_som_imx7_setup_i2c() - I2C pinmux configuration.
56 static void cl_som_imx7_setup_i2c(void)
58 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &cl_som_imx7_i2c_pad_info2);
60 #else /* !CONFIG_SYS_I2C_MXC */
61 static void cl_som_imx7_setup_i2c(void) {}
62 #endif /* CONFIG_SYS_I2C_MXC */
66 gd->ram_size = imx_ddr_size();
71 #ifdef CONFIG_FSL_ESDHC_IMX
73 #define CL_SOM_IMX7_GPIO_USDHC3_PWR IMX_GPIO_NR(6, 11)
75 static struct fsl_esdhc_cfg cl_som_imx7_usdhc_cfg[3] = {
76 {USDHC1_BASE_ADDR, 0, 4},
80 int board_mmc_init(bd_t *bis)
84 * According to the board_mmc_init() the following map is done:
85 * (U-boot device node) (Physical Port)
89 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
92 cl_som_imx7_usdhc1_pads_set();
93 gpio_request(CL_SOM_IMX7_GPIO_USDHC1_CD, "usdhc1_cd");
94 cl_som_imx7_usdhc_cfg[0].sdhc_clk =
95 mxc_get_clock(MXC_ESDHC_CLK);
98 cl_som_imx7_usdhc3_emmc_pads_set();
99 gpio_request(CL_SOM_IMX7_GPIO_USDHC3_PWR, "usdhc3_pwr");
100 gpio_direction_output(CL_SOM_IMX7_GPIO_USDHC3_PWR, 0);
102 gpio_direction_output(CL_SOM_IMX7_GPIO_USDHC3_PWR, 1);
103 cl_som_imx7_usdhc_cfg[1].sdhc_clk =
104 mxc_get_clock(MXC_ESDHC3_CLK);
107 printf("Warning: you configured more USDHC controllers "
108 "(%d) than supported by the board\n", i + 1);
112 ret = fsl_esdhc_initialize(bis, &cl_som_imx7_usdhc_cfg[i]);
119 #endif /* CONFIG_FSL_ESDHC_IMX */
121 #ifdef CONFIG_FEC_MXC
123 #define CL_SOM_IMX7_ETH1_PHY_NRST IMX_GPIO_NR(1, 4)
126 * cl_som_imx7_rgmii_rework() - Ethernet PHY configuration.
128 static void cl_som_imx7_rgmii_rework(struct phy_device *phydev)
132 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
133 * which cause ethernet link down/up issue, so disable SmartEEE
135 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
136 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
137 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
138 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
140 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
142 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
143 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
144 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
145 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
147 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
150 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
152 /* introduce tx clock delay */
153 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
154 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
156 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
159 int board_phy_config(struct phy_device *phydev)
161 cl_som_imx7_rgmii_rework(phydev);
163 if (phydev->drv->config)
164 phydev->drv->config(phydev);
170 * cl_som_imx7_handle_mac_address() - set Ethernet MAC address environment.
172 * @env_var: MAC address environment variable
173 * @eeprom_bus: I2C bus of the environment EEPROM
175 * @return: 0 on success, < 0 on failure
177 static int cl_som_imx7_handle_mac_address(char *env_var, uint eeprom_bus)
180 unsigned char enetaddr[6];
182 ret = eth_env_get_enetaddr(env_var, enetaddr);
186 ret = cl_eeprom_read_mac_addr(enetaddr, eeprom_bus);
190 ret = is_valid_ethaddr(enetaddr);
194 return eth_env_set_enetaddr(env_var, enetaddr);
197 #define CL_SOM_IMX7_FEC_DEV_ID_PRI 0
199 int board_eth_init(bd_t *bis)
201 /* set Ethernet MAC address environment */
202 cl_som_imx7_handle_mac_address("ethaddr", CONFIG_SYS_I2C_EEPROM_BUS);
203 /* Ethernet interface pinmux configuration */
204 cl_som_imx7_phy1_rst_pads_set();
205 cl_som_imx7_fec1_pads_set();
207 gpio_request(CL_SOM_IMX7_ETH1_PHY_NRST, "eth1_phy_nrst");
208 gpio_direction_output(CL_SOM_IMX7_ETH1_PHY_NRST, 0);
210 gpio_set_value(CL_SOM_IMX7_ETH1_PHY_NRST, 1);
211 /* MAC initialization */
212 return fecmxc_initialize_multi(bis, CL_SOM_IMX7_FEC_DEV_ID_PRI,
213 CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE);
217 * cl_som_imx7_setup_fec() - Ethernet MAC 1 clock configuration.
218 * - ENET1 reference clock mode select.
219 * - ENET1_TX_CLK output driver is disabled when configured for ALT1.
221 static void cl_som_imx7_setup_fec(void)
223 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
224 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
226 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
227 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
228 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
229 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
231 set_clk_enet(ENET_125MHZ);
233 #else /* !CONFIG_FEC_MXC */
234 static void cl_som_imx7_setup_fec(void) {}
235 #endif /* CONFIG_FEC_MXC */
239 static void cl_som_imx7_spi_init(void)
241 cl_som_imx7_espi1_pads_set();
243 #else /* !CONFIG_SPI */
244 static void cl_som_imx7_spi_init(void) {}
245 #endif /* CONFIG_SPI */
247 int board_early_init_f(void)
249 cl_som_imx7_uart1_pads_set();
250 cl_som_imx7_usb_otg1_pads_set();
257 /* address of boot parameters */
258 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
259 cl_som_imx7_setup_i2c();
260 cl_som_imx7_setup_fec();
261 cl_som_imx7_spi_init();
268 int power_init_board(void)
272 unsigned int reg, rev_id;
274 ret = power_pfuze3000_init(I2C_PMIC);
278 p = pmic_get("PFUZE3000");
283 pmic_reg_read(p, PFUZE3000_DEVICEID, ®);
284 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
285 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
287 /* disable Low Power Mode during standby mode */
288 pmic_reg_write(p, PFUZE3000_LDOGCTL, 0x1);
292 #endif /* CONFIG_POWER */
295 * cl_som_imx7_setup_wdog() - watchdog configuration.
296 * - Output WDOG_B signal to reset external pmic.
297 * - Suspend the watchdog timer during low-power modes.
299 void cl_som_imx7_setup_wdog(void)
301 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
303 cl_som_imx7_wdog_pads_set();
304 set_wdog_reset(wdog);
306 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
307 * since we use PMIC_PWRON to reset the board.
309 clrsetbits_le16(&wdog->wcr, 0, 0x10);
312 int board_late_init(void)
314 env_set("board_name", "CL-SOM-iMX7");
315 cl_som_imx7_setup_wdog();
323 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
328 printf("Board: CL-SOM-iMX7 in %s mode\n", mode);