aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosua Mayer <josua@solid-run.com>2022-05-19 12:31:59 +0300
committerStefano Babic <sbabic@denx.de>2022-06-14 21:25:26 +0200
commit741ce3084efffee6b43b88a389caf0f64eaf80e8 (patch)
tree758cd69f2a7187088148bac10b98644a049f6046
parent17baba4682001cc11446ff8406c63850b46edf72 (diff)
downloadu-boot-741ce3084efffee6b43b88a389caf0f64eaf80e8.zip
u-boot-741ce3084efffee6b43b88a389caf0f64eaf80e8.tar.gz
u-boot-741ce3084efffee6b43b88a389caf0f64eaf80e8.tar.bz2
mx6cuboxi: fixup dtb ethernet phy nodes before booting an OS
SoM revision 1.9 has replaced the ar8035 phy address 0 with an adin1300 at address 1. Because early SoMs had a hardware flaw, the ar8035 can also appear at address 4 - making it a total of 3 phy nodes in the DTB. To avoid confusing Linux with probe errors, fixup the dtb to only enable the phy node that is detected at runtime. Signed-off-by: Josua Mayer <josua@solid-run.com>
-rw-r--r--board/solidrun/mx6cuboxi/mx6cuboxi.c78
-rw-r--r--configs/mx6cuboxi_defconfig1
2 files changed, 79 insertions, 0 deletions
diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c b/board/solidrun/mx6cuboxi/mx6cuboxi.c
index 6207bf8..42aa5cb 100644
--- a/board/solidrun/mx6cuboxi/mx6cuboxi.c
+++ b/board/solidrun/mx6cuboxi/mx6cuboxi.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+
/*
+ * Copyright (C) 2022 Josua Mayer <josua@solid-run.com>
+ *
* Copyright (C) 2015 Freescale Semiconductor, Inc.
*
* Author: Fabio Estevam <fabio.estevam@freescale.com>
@@ -39,6 +41,8 @@
#include <spl.h>
#include <usb.h>
#include <usb/ehci-ci.h>
+#include <netdev.h>
+#include <phy.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -407,6 +411,80 @@ out:
return 0;
}
+static int find_ethernet_phy(void)
+{
+ struct mii_dev *bus = NULL;
+ struct phy_device *phydev = NULL;
+ int phy_addr = -ENOENT;
+
+#ifdef CONFIG_FEC_MXC
+ bus = fec_get_miibus(ENET_BASE_ADDR, -1);
+ if (!bus)
+ return -ENOENT;
+
+ // scan address 0, 1, 4
+ phydev = phy_find_by_mask(bus, 0b00010011);
+ if (!phydev) {
+ free(bus);
+ return -ENOENT;
+ }
+ pr_debug("%s: detected ethernet phy at address %d\n", __func__, phydev->addr);
+ phy_addr = phydev->addr;
+
+ free(phydev);
+#endif
+
+ return phy_addr;
+}
+
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
+/*
+ * Configure the correct ethernet PHYs nodes in device-tree:
+ * - AR8035 at addresses 0 or 4: Cubox
+ * - AR8035 at address 0: HummingBoard, HummingBoard 2
+ * - ADIN1300 at address 1: since SoM rev 1.9
+ */
+int ft_board_setup(void *fdt, struct bd_info *bd)
+{
+ int node_phy0, node_phy1, node_phy4;
+ int ret, phy;
+ bool enable_phy0 = false, enable_phy1 = false, enable_phy4 = false;
+
+ // detect phy
+ phy = find_ethernet_phy();
+ if (phy == 0 || phy == 4) {
+ enable_phy0 = true;
+ switch (board_type()) {
+ case CUBOXI:
+ case UNKNOWN:
+ default:
+ enable_phy4 = true;
+ }
+ } else if (phy == 1) {
+ enable_phy1 = true;
+ } else {
+ pr_err("%s: couldn't detect ethernet phy, not patching dtb!\n", __func__);
+ return 0;
+ }
+
+ // update all phy nodes status
+ node_phy0 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@0");
+ ret = fdt_setprop_string(fdt, node_phy0, "status", enable_phy0 ? "okay" : "disabled");
+ if (ret < 0 && enable_phy0)
+ pr_err("%s: failed to enable ethernet phy at address 0 in dtb!\n", __func__);
+ node_phy1 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@1");
+ ret = fdt_setprop_string(fdt, node_phy1, "status", enable_phy1 ? "okay" : "disabled");
+ if (ret < 0 && enable_phy1)
+ pr_err("%s: failed to enable ethernet phy at address 1 in dtb!\n", __func__);
+ node_phy4 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@4");
+ ret = fdt_setprop_string(fdt, node_phy4, "status", enable_phy4 ? "okay" : "disabled");
+ if (ret < 0 && enable_phy4)
+ pr_err("%s: failed to enable ethernet phy at address 4 in dtb!\n", __func__);
+
+ return 0;
+}
+#endif
+
/* Override the default implementation, DT model is not accurate */
int show_board_info(void)
{
diff --git a/configs/mx6cuboxi_defconfig b/configs/mx6cuboxi_defconfig
index 1e2e332..d3ac8ee 100644
--- a/configs/mx6cuboxi_defconfig
+++ b/configs/mx6cuboxi_defconfig
@@ -22,6 +22,7 @@ CONFIG_CMD_HDMIDETECT=y
CONFIG_AHCI=y
CONFIG_DISTRO_DEFAULTS=y
CONFIG_FIT=y
+CONFIG_OF_BOARD_SETUP=y
CONFIG_BOOTCOMMAND="run findfdt; run finduuid; run distro_bootcmd"
CONFIG_USE_PREBOOT=y
CONFIG_PREBOOT="if hdmidet; then usb start; setenv stdin serial,usbkbd; setenv stdout serial,vidconsole; setenv stderr serial,vidconsole; else setenv stdin serial; setenv stdout serial; setenv stderr serial; fi;"