[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250527175558.2738342-2-james.hilliard1@gmail.com>
Date: Tue, 27 May 2025 11:55:55 -0600
From: James Hilliard <james.hilliard1@...il.com>
To: netdev@...r.kernel.org
Cc: linux-sunxi@...ts.linux.dev,
James Hilliard <james.hilliard1@...il.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Chen-Yu Tsai <wens@...e.org>,
Jernej Skrabec <jernej.skrabec@...il.com>,
Samuel Holland <samuel@...lland.org>,
Maxime Coquelin <mcoquelin.stm32@...il.com>,
Alexandre Torgue <alexandre.torgue@...s.st.com>,
Yinggang Gu <guyinggang@...ngson.cn>,
Huacai Chen <chenhuacai@...nel.org>,
Yanteng Si <si.yanteng@...ux.dev>,
"Russell King (Oracle)" <rmk+kernel@...linux.org.uk>,
Uwe Kleine-König <u.kleine-koenig@...libre.com>,
Jinjie Ruan <ruanjinjie@...wei.com>,
Paul Kocialkowski <paulk@...-base.io>,
linux-arm-kernel@...ts.infradead.org,
linux-stm32@...md-mailman.stormreply.com,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 2/3] net: stmmac: dwmac-sun8i: Allow runtime AC200/AC300 phy selection
The Allwinner H616 ships with two different copackaged phy variants,
in order to determine the phy being used we need to read an efuse and
then select the appropriate PHY based on the AC300 bit.
By defining an emac node without a phy-handle we can override the
default PHY selection logic in stmmac by passing a specific phy_node
selected based on the ac200 and ac300 names in a phys list.
This allows us to have a device tree that defines both PHY variants
even though only one will actually end up being used at runtime
based on the ac300 nvmem efuse bit.
Signed-off-by: James Hilliard <james.hilliard1@...il.com>
---
.../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 6c7e8655a7eb..50d37876fabf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -11,6 +11,7 @@
#include <linux/mdio-mux.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
@@ -280,6 +281,8 @@ static const struct emac_variant emac_variant_h6 = {
#define SYSCON_ETCS_EXT_GMII 0x1
#define SYSCON_ETCS_INT_GMII 0x2
+#define AC300_KEY BIT(8) /* 1: AC300 PHY, 0: AC200 PHY */
+
/* sun8i_dwmac_dma_reset() - reset the EMAC
* Called from stmmac via stmmac_dma_ops->reset
*/
@@ -1149,6 +1152,35 @@ static struct regmap *sun8i_dwmac_get_syscon_from_dev(struct device_node *node)
return regmap;
}
+/* H616 SoCs can contain either an AC200 PHY (needs i2c init) or an AC300
+ * PHY (no i2c). The silicon variant is flagged by the AC300_KEY efuse.
+ */
+static int sun8i_dwmac_get_ac300_phy(struct device *dev,
+ struct plat_stmmacenet_data *plat_dat)
+{
+ u16 val;
+
+ /* If the nvmem cell is absent, use normal phy selection. */
+ if (nvmem_cell_read_u16(dev, "ac300", &val))
+ return 0;
+
+ const char *phy_name = (val & AC300_KEY) ? "ac300" : "ac200";
+ int index = of_property_match_string(dev->of_node, "phy-names",
+ phy_name);
+ if (index < 0) {
+ dev_err(dev, "PHY name not found in device tree\n");
+ return -EINVAL;
+ }
+
+ plat_dat->phy_node = of_parse_phandle(dev->of_node, "phys", index);
+ if (!plat_dat->phy_node) {
+ dev_err(dev, "Failed to get PHY node from phys property\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int sun8i_dwmac_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
@@ -1222,6 +1254,10 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);
+ ret = sun8i_dwmac_get_ac300_phy(dev, plat_dat);
+ if (ret)
+ return ret;
+
/* platform data specifying hardware features and callbacks.
* hardware features were copied from Allwinner drivers.
*/
--
2.34.1
Powered by blists - more mailing lists