Merge https://gitlab.denx.de/u-boot/custodians/u-boot-x86
[oweals/u-boot.git] / board / toradex / verdin-imx8mm / verdin-imx8mm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2020 Toradex
4  */
5
6 #include <common.h>
7 #include <asm/arch/clock.h>
8 #include <asm/io.h>
9 #include <miiphy.h>
10 #include <netdev.h>
11
12 DECLARE_GLOBAL_DATA_PTR;
13
14 int dram_init(void)
15 {
16         gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
17
18         return 0;
19 }
20
21 #if IS_ENABLED(CONFIG_FEC_MXC)
22 static int setup_fec(void)
23 {
24         struct iomuxc_gpr_base_regs *gpr =
25                 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
26
27         /* Use 125M anatop REF_CLK1 for ENET1, not from external */
28         clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
29
30         return 0;
31 }
32
33 int board_phy_config(struct phy_device *phydev)
34 {
35         /* enable rgmii rxc skew and phy mode select to RGMII copper */
36         phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
37         phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
38
39         phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
40         phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
41         phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
42         phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
43
44         if (phydev->drv->config)
45                 phydev->drv->config(phydev);
46         return 0;
47 }
48 #endif
49
50 int board_init(void)
51 {
52         if (IS_ENABLED(CONFIG_FEC_MXC))
53                 setup_fec();
54
55         return 0;
56 }
57
58 int board_mmc_get_env_dev(int devno)
59 {
60         return devno;
61 }
62
63 int board_late_init(void)
64 {
65         return 0;
66 }
67
68 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
69 int ft_board_setup(void *blob, bd_t *bd)
70 {
71         return 0;
72 }
73 #endif