From nobody Mon Apr 6 18:29:07 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 8353F1E89C; Wed, 18 Mar 2026 16:38:13 +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=1773851893; cv=none; b=PyelcbXEZf0KkmwaFkJpBVSmyrnsF4S8WDvulh9uCdTFOdh7dzhs4R+lG7FHM7H2vBJ0hn0sFhB5NB68k+v1DQ3exAwtH8dWQ70RtgeTFsBBDVFuOv25twSuk+tNzoeJ7uAADJ7R3ca4cuqeDgMuqAtGuoPzC0CWBQpbItI7nKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773851893; c=relaxed/simple; bh=d+MyLOiuyfRC+NF64EIUpcY9qyHiXTVHxjTblw4Yz08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gv25/6WFCfPvuRdb8u+H4c6pMYLy05cD2FRXHBtaZsLnEwrYg1DGTQylF/UIyivf49m8WIc1SKr/bOyZWBJwxho+itJ19F3xPId+vcFPt3t0dEnaX6nC40ctt7QkcnliUI/HCuGk6fJJjFZE/G8Cy/LczLknxaJ0lY4T/ymmQ/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fkn7TpiM; 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="fkn7TpiM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D2B9C19421; Wed, 18 Mar 2026 16:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773851893; bh=d+MyLOiuyfRC+NF64EIUpcY9qyHiXTVHxjTblw4Yz08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fkn7TpiMaIaZ+pYbCX/aj3GoQOkJbxIDRMWdK8jZWd2tmzSIKxFKRf/WUeg/qzNL9 ZfEh3ddIuvqicK5qekRI0XmL3QtZCUd4WJBGQkJbwiCxdtrgY2WMSgYeT4bNXb63Us IX2owusTSjn6RhjEv3cYmaRXOgNjiAbu4XQ0ALlVo49KvHidjKbPX3LzLp//14ngEP C0D57H/kbnr4Kd9s7X+Q0d9t2EkATNAl1FJvGGSiVeLIscsNJMWSNj1gHcgZvoPYM/ LsAx9j2eqwVFj9SkcxuiBKICJ/dsNdlCYp2JK77zxFK9USaGmObYzjxwgpSqj0YfEl C5wy0opPY1pPQ== 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 Subject: [PATCH net-next v4 04/13] net: macb: rework usrio refclk selection code Date: Wed, 18 Mar 2026 16:37:35 +0000 Message-ID: <20260318-legal-bottling-12622a38d98a@spud> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260318-surpass-puzzle-f94b46aa8808@spud> References: <20260318-surpass-puzzle-f94b46aa8808@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=5400; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=2bAmm8yzB8brPeFan+juq3/KVYptD7voFpcvqp+7QWc=; b=owGbwMvMwCVWscWwfUFT0iXG02pJDJm7rlzMza4sM2s6/0w2Z17Axdk/TR7bCn3VL1Bw3FuWk P3iIfvPjlIWBjEuBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAExkQgHD//p75xsXJHbNNNt1 1XjW3MZ/TH2zJTeGNOZJ3la7t1FQr4Thf8khrSmNV6ZH6GreK1Kfsy7JWcVmg6abxh5f9uWT/y8 O4gMA 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 baf48f02d7e27..9cd565cb87e4c 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1214,6 +1214,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 d908850c59498..1f9e46cf7e1cb 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -4318,12 +4318,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 @@ -4356,9 +4352,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 @@ -4626,8 +4619,36 @@ static int macb_init(struct platform_device *pdev) 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); } @@ -5223,11 +5244,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 @@ -5364,7 +5395,7 @@ static const struct macb_config sama7g5_gem_config = =3D { .dma_burst_length =3D 16, .clk_init =3D macb_clk_init, .init =3D macb_init, - .usrio =3D &sama7g5_usrio, + .usrio =3D &sama7g5_gem_usrio, }; =20 static const struct macb_config sama7g5_emac_config =3D { @@ -5376,7 +5407,7 @@ static const struct macb_config sama7g5_emac_config = =3D { .dma_burst_length =3D 16, .clk_init =3D macb_clk_init, .init =3D macb_init, - .usrio =3D &sama7g5_usrio, + .usrio =3D &sama7g5_emac_usrio, }; =20 static const struct macb_config versal_config =3D { --=20 2.51.0