From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88D7330E84E for ; Mon, 2 Feb 2026 20:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770062666; cv=none; b=c5Tqe9T7TDr9to2ZXoSHcVwv5Z49VQTi2nk4+HDwF5umItb+4YMgW8qeZLXV8s5fBILec4lsDzMgpNHohA1y/QLFLBL6EYUvvszESuVm3DUguXW2ZgI3/Kyf5+udbOk62/EImyXpJnV6x6k0vovUk9sIgCPX/XGfHnRYLIMnlDc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770062666; c=relaxed/simple; bh=FQWd66idNIPPBt7TUF6kuXek5+OLh0Gsn4zYraBgsdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fOB3ebP4CPQp/uN98kZyG+R2Ls1Iw/rwxzrS6ECLIrnt3BQ3t3v04nuvuDSouYlSwKtRvOwUXfUuPSpy9GrGfh9yHeY/fBhUdGo6kjoEv5akTflSofRs4XMuPDRBmwpO7BDHPtBLOaOiY+w7EMVxAvybf+h9xk/stj5FKok3Y2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=isDCH0k6; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="isDCH0k6" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-481188b7760so32362215e9.0 for ; Mon, 02 Feb 2026 12:04:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770062663; x=1770667463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GQ3Xd1JUldaEb0EE6XNzb7a8EiRdMWPdAN1y5gE4vRE=; b=isDCH0k6XqQRIo1V9owXcGM1UoI8I98Dv1GfPduWf0zKO/AmEkJnkRzOXD6eC/nwXj PdYrFBYp463gRj9czFGdUtTD/1/RWk2K0Y2A1yQMejk65RXtTa2qLTrkUWWRa30H0bPN Al4Md68jqgAAnVgB3FDcxgzubLzaEh7WLBHEnXMlVFFrMzNxI4zfKrptVdMQ3T741Pcv tEbbqGgtzE8WdmKvT+cpgdUABLGCBZGpBsUk1lDKXVxZVf3iUtX9/ZJaV5LbPlhSc9df Fx6Q7wD9KOnaDEitSs9NMof9HvoOmCvagsLGWuQgThtMPQRqV3bFVIQypgohZFfW/eYa okiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770062663; x=1770667463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GQ3Xd1JUldaEb0EE6XNzb7a8EiRdMWPdAN1y5gE4vRE=; b=FFJqY2lc1Vnh+rzx8jZ5pqytE+S1ITn7KH1CfcNzhWicvJo8mLQMAZwWUSPvugzQQ3 ftt/56Vh/q25hF3EwLCefojN/r/GhLHYhcU3tQk70Kt5W3/d5zYlCyzqhEETFVWtP2vP E7qbxp5Po0+2EvXt9N0Wyd2jazE3w3oWFwvgQxz3LGDD+62DYT/STbFtO1cCQbhYwC3a sDbWMWyLzMNNzTdSgbUhedP4WKsdy7vBPQ2OhQJHImklxED+7Lytsblx9qoHzBUVjDnM UIoc7y1oxUcvjbPi9O8hVr2eNLC+rtARtSl4qBliZ62zbCjBW97Aa47mthCNgnLaO3ax iItA== X-Forwarded-Encrypted: i=1; AJvYcCV1hmJ31vhREFFsFiqamyPIKxPz+EFTZUyRs6TXnbxkjzX06F7E3uYOJ6dC5hi3vKNhxkDBHoDQtW+VFzw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3dFzt/rZ3t+YH15y1Y7UbQGPBuFrMGFjD7ncy02MBBtVTz6kw XWjJF6tXX0FMLZBBBPmDXHaYlKziD3J46VZ1FKAqcQcjck5gTYL0Ub4Jtj/wbO9L X-Gm-Gg: AZuq6aKSS4UkuvJIXNAaO9vZ68dZ6M8gD/vTaR+589P0tFuzAdiiUEDaCFhGV4p6sBG 8IZh7WGwbuWV+q4UcBvaEdw49PT3OxaB3hkat+m37nzLgx0Qnt41Aqyh2YdE7WsXAKlfsvhUWqV kAWmz38dSZg48OofKIe1Plrj6lXnS2qQNQc8Ielu1dwaI9dnrCX3XlWQ8kFHhhNsf2TRi6FKEWd 8hIOrki/K9p/YIJrWoYYSoW17rMjpCaq0ARRa7DaR1qiuUqK8DgcZXr+LDJ9W1xiDy4xna21/Nm R+IJbdC5gzn0U9xMUu1qPJAi6on0ne0WYYDoChqSIfC4dMI++nU2cZsl+WCzCEEyWDMl44H8iNr LAk79zGuNhaQDwJYOAtntd9ei/kvq2zP69Su6OnBupDMI9aXXaOrMNfq0YtYOq7kUVJl6Gn0a2q 6pdLNHoQH7XVg= X-Received: by 2002:a05:600c:b99:b0:480:1e40:3d2 with SMTP id 5b1f17b1804b1-482db49a4a6mr185536155e9.29.1770062662900; Mon, 02 Feb 2026 12:04:22 -0800 (PST) Received: from nas.local ([2001:912:1ac0:1e00:c662:37ff:fe09:93df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482dbd3953esm120842955e9.4.2026.02.02.12.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 12:04:22 -0800 (PST) From: Damien Dejean To: andrew@lunn.ch, krzk+dt@kernel.org, robh@kernel.org, kuba@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, edumazet@google.com, davem@davemloft.net, pabeni@redhat.com, hkallweit1@gmail.com, Damien Dejean Subject: [PATCH v5 2/4] net: phy: realtek: add RTL8224 pair order support Date: Mon, 2 Feb 2026 21:04:09 +0100 Message-ID: <20260202200411.373161-2-dam.dejean@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260202200411.373161-1-dam.dejean@gmail.com> References: <20260202200411.373161-1-dam.dejean@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The RTL8224 has a register to configure a pair swap (from ABCD order to DCBA) providing PCB designers more flexbility when wiring the chip. The swap parameter has to be set correctly for each of the 4 ports before the chip can detect a link. After a reset, this register is (unfortunately) left in a random state, thus it has to be initialized. On most of the devices the bootloader does it once for all and we can rely on the value set, on some other it is not and the kernel has to do it. The MDI pair swap can be set in the device tree using the property enet-phy-lane-order. The property is set to 0 to keep the default order (ABCD), or 1 to reverse the pairs (DCBA). Signed-off-by: Damien Dejean --- drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 55 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/net/phy/realtek/Kconfig b/drivers/net/phy/realtek/Kconfig index b05c2a1e9024..a741b34d193e 100644 --- a/drivers/net/phy/realtek/Kconfig +++ b/drivers/net/phy/realtek/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config REALTEK_PHY tristate "Realtek PHYs" + select PHY_PACKAGE help Currently supports RTL821x/RTL822x and fast ethernet PHYs diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 75565fbdbf6d..85e928a0d3dc 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -171,6 +171,8 @@ #define RTL8224_SRAM_RTCT_LEN(pair) (0x8028 + (pair) * 4) +#define RTL8224_VND1_MDI_PAIR_SWAP 0xa90 + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -1820,6 +1822,57 @@ static int rtl8224_cable_test_get_status(struct phy_device *phydev, bool *finish return rtl8224_cable_test_report(phydev, finished); } +static int rtl8224_mdi_config_order(struct phy_device *phydev) +{ + struct device_node *np = phydev->mdio.dev.of_node; + u8 port_offset = phydev->mdio.addr & 3; + u32 order = 0; + int ret, val; + + ret = of_property_read_u32(np, "enet-phy-lane-order", &order); + + /* Do nothing in case the property is not present */ + if (ret == -EINVAL) + return 0; + + if (ret) + return ret; + + if (order & ~1) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1, + RTL8224_VND1_MDI_PAIR_SWAP); + if (val < 0) { + ret = val; + goto exit; + } + + if (order) + val |= (1 << port_offset); + else + val &= ~(1 << port_offset); + + ret = __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1, + RTL8224_VND1_MDI_PAIR_SWAP, val); +exit: + phy_unlock_mdio_bus(phydev); + return ret; +} + +static int rtl8224_config_init(struct phy_device *phydev) +{ + return rtl8224_mdi_config_order(phydev); +} + +static int rtl8224_probe(struct phy_device *phydev) +{ + /* Chip exposes 4 ports, join all of them in the same package */ + return devm_phy_package_join(&phydev->mdio.dev, phydev, + phydev->mdio.addr & ~3, 0); +} + static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) { int val; @@ -2392,6 +2445,8 @@ static struct phy_driver realtek_drvs[] = { PHY_ID_MATCH_EXACT(0x001ccad0), .name = "RTL8224 2.5Gbps PHY", .flags = PHY_POLL_CABLE_TEST, + .probe = rtl8224_probe, + .config_init = rtl8224_config_init, .get_features = rtl822x_c45_get_features, .config_aneg = rtl822x_c45_config_aneg, .read_status = rtl822x_c45_read_status, -- 2.47.3