From patchwork Wed Jan 22 17:42:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13947623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14C75C02181 for ; Wed, 22 Jan 2025 17:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UUKo6BYvxcPfoyKKjL5MJ7dl67C2+j1DdwgoDsRw0Hk=; b=1mVzqz/pwhGrfzydGY85u9uaoa hu8zrC0gASpfqwl8yFTaQK8DkjQfCpeSzAeEl2UeJju+dxRnNpnHfiuBc6y9h+V7yyhQ/OZAqkFjD dryp9JP08i45xd/j0GERDwQaBfiLQXZZkzuHuK+tLLfS4Wqhf3SqqiP3hBTm27vfTsAssCzocXia0 q6M79hzdRSG5NX5iNr4EKVzjV6N645X4srZmiBdDkwecb0uEri3D9NG/HL56jUNixmbLLPf2yKIJ3 Ve3dBXXKRO0pO9wIxzaU9uc/yF/dHPydcZK3XaRzRcZt2HNfcG4kEXhyMlyjbOopIS9Oa0YK0I7sa EnvYDR3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taesN-0000000AvR3-3YWc; Wed, 22 Jan 2025 17:50:51 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taekq-0000000Atdi-0U9Y for linux-arm-kernel@lists.infradead.org; Wed, 22 Jan 2025 17:43:05 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 9A8131BF20E; Wed, 22 Jan 2025 17:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737567782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UUKo6BYvxcPfoyKKjL5MJ7dl67C2+j1DdwgoDsRw0Hk=; b=C4oixmsVpErHQrmshmyIPCFZiBeiUXek8W39f3Z9HoMZrYpuxFS2uGZ2qf9gEvBuZrLLdA oHW4gDCOCG+v7cdvG338fYPbkBMbV+flL7jf253UAO2JU+v+FY4AhxfRYd7xmFdYavYyyc lRbCZf/Zuzt8R5Uv+qmpgiYPmv10GGZxPAOcj+19kfL0a0xstDpeiPRBzEcUw9Z9kntJwO tpaXMmXAjHIt6L/LHSJaTb5gcFO+Sch8bUY0tgh0jh+HSKeJZmmA3rnxzNz072EzH+83PI gl011qF12EW0bhzRBo2jfElddNAicvNrX944Lb+agK4ZvEdyubnfHoQ5u6tM1A== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?K=C3=B6ry_Maincent?= , =?utf-8?q?Marek?= =?utf-8?q?_Beh=C3=BAn?= , Oleksij Rempel , =?utf-8?q?Nicol=C3=B2_Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , Rob Herring , Krzysztof Kozlowski , Conor Dooley Subject: [PATCH net-next RFC v2 5/6] net: phy: dp83822: Add support for phy_port representation Date: Wed, 22 Jan 2025 18:42:50 +0100 Message-ID: <20250122174252.82730-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122174252.82730-1-maxime.chevallier@bootlin.com> References: <20250122174252.82730-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250122_094304_413423_F70811A2 X-CRM114-Status: GOOD ( 19.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With the phy_port representation intrduced, we can use .attach_port to populate the port information based on either the straps or the ti,fiber-mode property. This allows simplifying the probe function and allow users to override the strapping configuration. Signed-off-by: Maxime Chevallier --- RFC V2: Addressd a warning for an unused variable drivers/net/phy/dp83822.c | 63 ++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c index 6599feca1967..a1ddb7791452 100644 --- a/drivers/net/phy/dp83822.c +++ b/drivers/net/phy/dp83822.c @@ -781,17 +781,6 @@ static int dp83822_of_init(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; const char *of_val; - /* Signal detection for the PHY is only enabled if the FX_EN and the - * SD_EN pins are strapped. Signal detection can only enabled if FX_EN - * is strapped otherwise signal detection is disabled for the PHY. - */ - if (dp83822->fx_enabled && dp83822->fx_sd_enable) - dp83822->fx_signal_det_low = device_property_present(dev, - "ti,link-loss-low"); - if (!dp83822->fx_enabled) - dp83822->fx_enabled = device_property_present(dev, - "ti,fiber-mode"); - if (!device_property_read_string(dev, "ti,gpio2-clk-out", &of_val)) { if (strcmp(of_val, "mac-if") == 0) { dp83822->gpio2_clk_out = DP83822_CLK_SRC_MAC_IF; @@ -884,6 +873,43 @@ static int dp83822_read_straps(struct phy_device *phydev) return 0; } +static int dp83822_attach_port(struct phy_device *phydev, struct phy_port *port) +{ + struct dp83822_private *dp83822 = phydev->priv; + int ret; + + if (port->mediums) { + if (phy_port_is_fiber(port) || + port->mediums & BIT(ETHTOOL_LINK_MEDIUM_BASEX)) + dp83822->fx_enabled = true; + } else { + ret = dp83822_read_straps(phydev); + if (ret) + return ret; + +#ifdef CONFIG_OF_MDIO + if (dp83822->fx_enabled && dp83822->fx_sd_enable) + dp83822->fx_signal_det_low = + device_property_present(dev, "ti,link-loss-low"); + if (!dp83822->fx_enabled) + dp83822->fx_enabled = + device_property_present(dev, "ti,fiber-mode"); +#endif + + if (dp83822->fx_enabled) { + port->lanes = 1; + port->mediums = BIT(ETHTOOL_LINK_MEDIUM_BASEF) | + BIT(ETHTOOL_LINK_MEDIUM_BASEX); + } else { + /* This PHY can only to 100BaseTX max, so on 2 lanes */ + port->lanes = 2; + port->mediums = BIT(ETHTOOL_LINK_MEDIUM_BASET); + } + } + + return 0; +} + static int dp8382x_probe(struct phy_device *phydev) { struct dp83822_private *dp83822; @@ -900,25 +926,13 @@ static int dp8382x_probe(struct phy_device *phydev) static int dp83822_probe(struct phy_device *phydev) { - struct dp83822_private *dp83822; int ret; ret = dp8382x_probe(phydev); if (ret) return ret; - dp83822 = phydev->priv; - - ret = dp83822_read_straps(phydev); - if (ret) - return ret; - - ret = dp83822_of_init(phydev); - if (ret) - return ret; - - if (dp83822->fx_enabled) - phydev->port = PORT_FIBRE; + dp83822_of_init(phydev); return 0; } @@ -1104,6 +1118,7 @@ static int dp83822_led_hw_control_get(struct phy_device *phydev, u8 index, .led_hw_is_supported = dp83822_led_hw_is_supported, \ .led_hw_control_set = dp83822_led_hw_control_set, \ .led_hw_control_get = dp83822_led_hw_control_get, \ + .attach_port = dp83822_attach_port \ } #define DP83825_PHY_DRIVER(_id, _name) \