From nobody Fri Apr 3 03:00:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D46C13FB043; Wed, 25 Mar 2026 16:29:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774456159; cv=none; b=fMbysx0HvGuKpn0I5/0iPV+mFzKQm/b5f1gPxdV1ml2CPKWyxchAGLeomGs8xyJhE2aXYGdMb7KC77yZ4LjlzGmy6FP3fV66DcN5i+tUrteOhxj6glUBnO3lZSdm1iVR/q5Xdt+lobeaIyHkGftik2gpNnX8OuLnnzXcvy3eiOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774456159; c=relaxed/simple; bh=mignoRYRLHHjX6SoWI2N00JC2HYzX1D05cl4aW7C2tI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vDMLRArMe+YP24KnAsOX9lKS+4Gv5BkBos2u6dlhH6Z01MiXFWhnhUuhbl5IdBqx8uOYevgcI42WGCJjnBEB//RiKQp4nB1lgkUfr5PjqvYhA4XHLd7GQmLajqWSJxs6aH6eV8TXc7BJpx3YFlFI6MVTWsBKxLjXCHB4yMA2/uc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZWaqqXR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZWaqqXR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AF36C4CEF7; Wed, 25 Mar 2026 16:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774456159; bh=mignoRYRLHHjX6SoWI2N00JC2HYzX1D05cl4aW7C2tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZWaqqXRtM1Zpz9+5WAz2NTimIltca+VqNPf+FXtspLv6JsN2gzoUPPiGu1l8Hj5F sYs1w/+geL4GAmvsxiyCujjqRhgdKTZtNe9Gp2cMWdvkAPACTV4bv/fcu7Vf/qgKcw 6KUkuebGc/jBeeCfVqRygmS7ov7tBZM9VpbJW/ZDBzG+QcV4wsrWtQERCme7VVpMBx p+Y0hAWOXcYe80cTdYrEhKmhTBEPHxr0asNWWRYsQLkD9HeEs8N0sNGKP2N0VFceaa FOWBEPdHgtkaur44vdZmUFhODtuhwTkz+x5LM3QTzdX+HaGKhIVg9tli/fSb6b8SqH WfkQXhA+7gUew== From: Conor Dooley To: netdev@vger.kernel.org Cc: conor@kernel.org, Conor Dooley , Valentina.FernandezAlanis@microchip.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Daire McNamara , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Ferre , Claudiu Beznea , Richard Cochran , Samuel Holland , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Dave Stevenson , Sean Anderson , Vineeth Karumanchi , Abin Joseph , =?UTF-8?q?Th=C3=A9o=20Lebrun?= , Ryan.Wanner@microchip.com, Kevin Hao Subject: [PATCH net-next v5 05/14] net: macb: rework usrio refclk selection code Date: Wed, 25 Mar 2026 16:28:09 +0000 Message-ID: <20260325-tarantula-bullring-6ac44b39dd52@spud> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260325-unsterile-flail-4c7729750dc4@spud> References: <20260325-unsterile-flail-4c7729750dc4@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5438; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=ycgYzkRjtwYgivLvrVnZHFBsUBSJrE0ZCfPhkRXsTQU=; b=owGbwMvMwCVWscWwfUFT0iXG02pJDJlHeE3vRe5euGKW3gUfX+YzIv2XViwN1G29t++ldIPBm ngN5XyHjlIWBjEuBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAEyk6gvD/1oRd8sNOavC1lSm PZytqNT1Vk48Nue2WvXLv/VXHj4T5GT4w/snN2qiCpfscbnLIS7belgOqgm0fG2Szby2xLx87iV TBgA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Conor Dooley The USRIO based refclk selection code abuses a capability flag to set the refclk to an external source based on match data/compatible on sama7g5-emac and use an internal source for the gmac. Ryan previously added a property in an attempt to decouple the refclk source from the compatible, because this is not fixed by compatible and there's variance based on the choices made by board designers. Originally when Ryan added it, he removed the capability flag entirely from match data, but this changed the default for the sama7g5-emac and the removal had to be reverted for these devices. Because these devices default to an external refclk, and the current property is only capable of communicating external refclks, there's no way to make the sama7g5-emac use an internal refclk. Additionally, this property has no limiting based on compatible, and if used on a platform with an external refclk that is not controlled by USRIO the capability would be erroneously set. Because of the reuse of the at91_default_usrio struct by non-at91 devices, this could cause the refclk bit to be set in error, on a system where the refclk is externally provided without usrio settings being required. Change the new capability flag so that it actually represents the hardware being capable of controlling the refclk source via USRIO, and move the selection of default behaviour into the macb_usrio_config struct provided as part of match data. Modify the devicetree code to support a new property, "cdns,refclk-source" which will support devices with either default, retaining support for "cdns,refclk-external" for compatibility reasons. Signed-off-by: Conor Dooley --- drivers/net/ethernet/cadence/macb.h | 1 + drivers/net/ethernet/cadence/macb_main.c | 55 ++++++++++++++++++------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cad= ence/macb.h index 35b7129d7c1ee..1bdbe66b05590 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1229,6 +1229,7 @@ struct macb_usrio_config { u32 refclk; u32 clken; u32 hdfctlen; + bool refclk_default_external; }; =20 struct macb_config { diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 859d03502666a..a436521460683 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -4576,12 +4576,8 @@ static const struct net_device_ops macb_netdev_ops = =3D { static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_conf) { - struct device_node *np =3D bp->pdev->dev.of_node; - bool refclk_ext; u32 dcfg; =20 - refclk_ext =3D of_property_read_bool(np, "cdns,refclk-ext"); - if (dt_conf) bp->caps =3D dt_conf->caps; =20 @@ -4614,9 +4610,6 @@ static void macb_configure_caps(struct macb *bp, } } =20 - if (refclk_ext) - bp->caps |=3D MACB_CAPS_USRIO_HAS_REFCLK_SOURCE; - dev_dbg(&bp->pdev->dev, "Cadence caps 0x%08x\n", bp->caps); } =20 @@ -4897,8 +4890,36 @@ static int macb_init_dflt(struct platform_device *pd= ev) if (bp->caps & MACB_CAPS_USRIO_HAS_CLKEN) val |=3D bp->usrio->clken; =20 - if (bp->caps & MACB_CAPS_USRIO_HAS_REFCLK_SOURCE) - val |=3D bp->usrio->refclk; + if (bp->caps & MACB_CAPS_USRIO_HAS_REFCLK_SOURCE) { + const char *prop; + bool refclk_ext; + int ret; + + /* Default to whatever was set in the match data for + * this device. There's two properties for refclk + * control, but the boolean one is deprecated so is + * a lower priority to check, no device should have + * both. + */ + refclk_ext =3D bp->usrio->refclk_default_external; + + ret =3D of_property_read_string(pdev->dev.of_node, + "cdns,refclk-source", &prop); + if (!ret) { + if (!strcmp(prop, "external")) + refclk_ext =3D true; + else + refclk_ext =3D false; + } else { + ret =3D of_property_read_bool(pdev->dev.of_node, + "cdns,refclk-ext"); + if (ret) + refclk_ext =3D true; + } + + if (refclk_ext) + val |=3D bp->usrio->refclk; + } =20 macb_or_gem_writel(bp, USRIO, val); } @@ -5503,11 +5524,21 @@ static const struct macb_usrio_config at91_default_= usrio =3D { .clken =3D MACB_BIT(CLKEN), }; =20 -static const struct macb_usrio_config sama7g5_usrio =3D { +static const struct macb_usrio_config sama7g5_gem_usrio =3D { .mii =3D 0, .rmii =3D 1, .rgmii =3D 2, .refclk =3D BIT(2), + .refclk_default_external =3D false, + .hdfctlen =3D BIT(6), +}; + +static const struct macb_usrio_config sama7g5_emac_usrio =3D { + .mii =3D 0, + .rmii =3D 1, + .rgmii =3D 2, + .refclk =3D BIT(2), + .refclk_default_external =3D true, .hdfctlen =3D BIT(6), }; =20 @@ -5622,7 +5653,7 @@ static const struct macb_config sama7g5_gem_config = =3D { MACB_CAPS_MIIONRGMII | MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_USRIO_HAS_MII, .dma_burst_length =3D 16, - .usrio =3D &sama7g5_usrio, + .usrio =3D &sama7g5_gem_usrio, }; =20 static const struct macb_config sama7g5_emac_config =3D { @@ -5632,7 +5663,7 @@ static const struct macb_config sama7g5_emac_config = =3D { MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_USRIO_HAS_MII, .dma_burst_length =3D 16, - .usrio =3D &sama7g5_usrio, + .usrio =3D &sama7g5_emac_usrio, }; =20 static const struct macb_config versal_config =3D { --=20 2.53.0