From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 6922D2D46A2 for ; Sat, 7 Feb 2026 09:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770456352; cv=none; b=LeWbrHE1MC8N7gD/8i6K6s7SVqHkFlNbrbrDZ0BgQleunKnD7Kz0hntt0FGAV0WBDbuVEHn14IcAvur5grNvwLvRoMOo5zzo8+JDgglyOiNg7gUTUH9dE3ouMmcNc0J3PZXQa+GYMUcLSZefCva8YrDCZeRC/AouHbtav1jQdzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770456352; c=relaxed/simple; bh=RU92uS+DYv5bSLkinoz7UBqkLFdl0Unma/HtnFQ0nEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhSIAk3WCloMH8yl8bx6B7rRO52g8GVOs7AOGoRFg833GZjKhZt2ymkQQokDmkszHU85XzX9axcPuYIqixsoDLRYig9EJwu4MtUX7dHfMLLeTC1ZGzGXu/Y6/cRYblg3apCt6R8uIHH2FnvyG1J1ndKsecZuCSY2p123pL/zOqM= 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=dELeeCst; arc=none smtp.client-ip=209.85.128.53 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="dELeeCst" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-47edd9024b1so16323225e9.3 for ; Sat, 07 Feb 2026 01:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770456351; x=1771061151; 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=6UtSzjb69Xa+hs2qYvlVH5KlrXvEWqJEp4fy3uEo+g4=; b=dELeeCst4UuDJI0g0CyGVwnnU27eEjk9ym/RyRg9hH8jC4KoClI46fnVx2sl/uRU6C nlu6OU93Pkm1l5jeMpu8USFNuGJmIn8WI8qOZvpVCK/cgrfN7dlhe3mz7iFAFI2UDoWt DVzCnNsv7yjUfC/gUhECNTrj8YUS5Y/7afY1KHnyE9peAEl6QSqwzypF0l0Z1JZnOMNq 3BSOXnW6ghXrNiEEWYse9EsxCXoHntQZwsWZbl9W03QpFkU5p6JDiNEk/xNzwH329MEZ 4khRjWgsdxfz3si2P5e911fUdjN/YMBrL8BKIxNlc20OXDuGWFipESxOYbukixNMyf5r 41IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770456351; x=1771061151; 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=6UtSzjb69Xa+hs2qYvlVH5KlrXvEWqJEp4fy3uEo+g4=; b=Fg2xBp+SjX70u0DH1h8ClCRNJ7HGPNAITEeqDu396SvUAumBYv7xtZxvwinE8yVXRU D68pnI2MwGnGIFrX/JYX3Q8GtzA6ZLoOtzJkXS7RoSqpjIzQF7u9CIzOTCwSw6Bty86U DQpoWW/7pSzyF9jD0r6YAL1rIe8To0PLD9mmp9fCIRbtGg6aXJRNKdAjziaQQwN5l+aT gChB4LZB28aoWLyR/3xHf+zOuYbZS+TS/FjZDewMpDSqTuOSTKbw1xxlB5nxyeVGAYmz QwGeri4SCCW5WlOw+m6WGeB6NBMwNXkVqJeS8P/QvtBU1Dw5GoUkh0yocOmSM+/6kYBV QR8g== X-Forwarded-Encrypted: i=1; AJvYcCUWN+Y2YDmhSButzs9iswXJWfMa7U7os/egIGSjsQjIKMLK1dBomQkD4VNS8Bs7vIL9lkQd5hw0C8SM/uU=@vger.kernel.org X-Gm-Message-State: AOJu0YxnDrEUlIS00twnzGu1dIktZ9iceu/cDMedeioPtxJe2jLpOdd2 BSrdc7qCTkK+bpFoGvMRoDHEkBeBdsvlLwiAE/AkCYG75PolgU3eQEO0 X-Gm-Gg: AZuq6aJePlLNiDe0Jc4GxnS/nDZSdGAIWL3F4pc+mAsG66LmtN8EhSVxeYXOK/Nz1a7 ScrC7HxVAPU5xdjFN7fqeTl5tD28a6/4nQFyLqnBfMEWRF208bKfWtHJLn8Ps7DEHbC5vvMGTDV Dmd2jV55KLFNCRNRB/ZeAseW6Ue/kKgFVtko9/A1zCNuq55CpLFlZPgj9kJnMTdDf8l/QZ68Dvh MYxhC+Z1ZhnbdDrhZq9oreG+i+GGuq+46xuhuzThd61yRPdsV49oDG09eQWoGTQkXKbq/X4cVd4 tnhrUvRWn85l5ox8hk74y/HBzc/tDtqZf6VR83Yq8F/AZOAp8YeWy/XFoqNWn+1n9HwXwwxHCXB X+EvRjFXSYoxAJ4GDmdUZTWl9v7dOtdlf8hK8paPSIdRzmdBCbH/lWB19A8uQj+BnUifNgQ0QhC d5zsx4YHtW22M= X-Received: by 2002:a05:600c:314a:b0:475:dd8d:2f52 with SMTP id 5b1f17b1804b1-48320226715mr65253035e9.32.1770456350495; Sat, 07 Feb 2026 01:25:50 -0800 (PST) Received: from nas.local ([2001:912:1ac0:1e00:c662:37ff:fe09:93df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48320736953sm101034545e9.15.2026.02.07.01.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Feb 2026 01:25:50 -0800 (PST) From: Damien Dejean To: andrew@lunn.ch, krzk+dt@kernel.org, robh@kernel.org, kuba@kernel.org, maxime.chevallier@bootlin.com 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 v6 2/4] net: phy: realtek: add RTL8224 pair order support Date: Sat, 7 Feb 2026 10:25:37 +0100 Message-ID: <20260207092539.647768-2-dam.dejean@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260207092539.647768-1-dam.dejean@gmail.com> References: <20260207092539.647768-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-pair-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..4f0c1b72f7e0 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-pair-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