AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/06 03:04 flow patch-triage
4m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series introduces a dedicated driver for Airoha SoC built-in Gigabit Ethernet PHYs (AN7581, AN7583, EN7528) and refactors common helpers across MediaTek and Airoha SoC PHY drivers. All modified code is strictly confined to drivers/net/phy/mediatek/ and targets internal PHYs integrated into Airoha (ARCH_AIROHA/ECONET, ARM64/MIPS) and MediaTek (ARCH_MEDIATEK) SoCs. On the target architecture (amd64), this SoC-specific hardware is physically absent and not emulated in standard QEMU/GCE environments, making the modified code structurally unreachable.",
  "WorthFuzzing": false
}

1/1 2026/11/06 03:04 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 9e4411c9d6f56e70300a19017e2544f363a38152\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Nov 6 03:04:19 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 09713dc4c6a77d..8a3e84d7eff3e3 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -771,6 +771,14 @@ S:\tMaintained\n F:\tDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml\n F:\tdrivers/net/ethernet/airoha/\n \n+AIROHA ETHERNET PHY DRIVER\n+M:\tChristian Marangi \u003cansuelsmth@gmail.com\u003e\n+L:\tlinux-arm-kernel@lists.infradead.org (moderated for non-subscribers)\n+L:\tlinux-mediatek@lists.infradead.org (moderated for non-subscribers)\n+L:\tnetdev@vger.kernel.org\n+S:\tMaintained\n+F:\tdrivers/net/phy/mediatek/airoha-ge-soc.c\n+\n AIROHA PCIE PHY DRIVER\n M:\tLorenzo Bianconi \u003clorenzo@kernel.org\u003e\n L:\tlinux-arm-kernel@lists.infradead.org (moderated for non-subscribers)\n@@ -16990,6 +16998,7 @@ L:\tnetdev@vger.kernel.org\n S:\tMaintained\n F:\tdrivers/net/phy/mediatek/mtk-2p5ge.c\n F:\tdrivers/net/phy/mediatek/mtk-ge-soc.c\n+F:\tdrivers/net/phy/mediatek/mtk-ge-soc.h\n F:\tdrivers/net/phy/mediatek/mtk-phy-lib.c\n F:\tdrivers/net/phy/mediatek/mtk-ge.c\n F:\tdrivers/net/phy/mediatek/mtk.h\ndiff --git a/drivers/net/phy/mediatek/Kconfig b/drivers/net/phy/mediatek/Kconfig\nindex 3b9cf82c0cb288..5abf782029917d 100644\n--- a/drivers/net/phy/mediatek/Kconfig\n+++ b/drivers/net/phy/mediatek/Kconfig\n@@ -1,4 +1,17 @@\n # SPDX-License-Identifier: GPL-2.0-only\n+config AIROHA_GE_SOC_PHY\n+\ttristate \"Airoha SoC Gigabit Ethernet PHYs\"\n+\tdepends on ARM64 || ECONET || COMPILE_TEST\n+\tdepends on ARCH_AIROHA || ECONET || COMPILE_TEST\n+\tselect MTK_NET_PHYLIB\n+\tselect PHY_PACKAGE\n+\thelp\n+\t  Supports Airoha SoC built-in Gigabit Ethernet PHYs.\n+\n+\t  Include support for built-in Ethernet PHYs which are present in\n+\t  the AN7581 and AN7583 SoCs. These PHYs will dynamically\n+\t  calibrate during startup.\n+\n config MEDIATEK_2P5GE_PHY\n \ttristate \"MediaTek 2.5Gb Ethernet PHYs\"\n \tdepends on (ARM64 \u0026\u0026 ARCH_MEDIATEK) || COMPILE_TEST\n@@ -32,9 +45,8 @@ config MEDIATEK_FE_SOC_PHY\n \n config MEDIATEK_GE_SOC_PHY\n \ttristate \"MediaTek SoC Gigabit Ethernet PHYs\"\n-\tdepends on ARM64 || ECONET || COMPILE_TEST\n-\tdepends on ARCH_AIROHA || (ARCH_MEDIATEK \u0026\u0026 NVMEM_MTK_EFUSE) || \\\n-\t\t   ECONET || COMPILE_TEST\n+\tdepends on ARM64 || COMPILE_TEST\n+\tdepends on (ARCH_MEDIATEK \u0026\u0026 NVMEM_MTK_EFUSE) || COMPILE_TEST\n \tselect MTK_NET_PHYLIB\n \tselect PHY_PACKAGE\n \thelp\ndiff --git a/drivers/net/phy/mediatek/Makefile b/drivers/net/phy/mediatek/Makefile\nindex 6f9cacf7f90657..5594057f51d0f4 100644\n--- a/drivers/net/phy/mediatek/Makefile\n+++ b/drivers/net/phy/mediatek/Makefile\n@@ -1,4 +1,5 @@\n # SPDX-License-Identifier: GPL-2.0\n+obj-$(CONFIG_AIROHA_GE_SOC_PHY)\t\t+= airoha-ge-soc.o\n obj-$(CONFIG_MEDIATEK_2P5GE_PHY)\t+= mtk-2p5ge.o\n obj-$(CONFIG_MEDIATEK_FE_SOC_PHY)\t+= mtk-fe-soc.o\n obj-$(CONFIG_MEDIATEK_GE_PHY)\t\t+= mtk-ge.o\ndiff --git a/drivers/net/phy/mediatek/airoha-ge-soc.c b/drivers/net/phy/mediatek/airoha-ge-soc.c\nnew file mode 100644\nindex 00000000000000..72c2b9fe7ba4a8\n--- /dev/null\n+++ b/drivers/net/phy/mediatek/airoha-ge-soc.c\n@@ -0,0 +1,1882 @@\n+// SPDX-License-Identifier: GPL-2.0+\n+#include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/pinctrl/consumer.h\u003e\n+#include \u003clinux/phy.h\u003e\n+\n+#include \"../phylib.h\"\n+#include \"mtk.h\"\n+#include \"mtk-ge-soc.h\"\n+\n+#define AIROHA_DEFAULT_PORT0_ADDR\t\t0x9\n+#define AIROHA_PHY_MAX_LEDS\t\t\t2\n+\n+enum airoha_mdi_resister_type {\n+\tMDI_0R,\n+\tMDI_5R,\n+\n+\tMDI_TYPE_MAX,\n+};\n+\n+enum airoha_transformer_type {\n+\tDISCRETE,\n+\tTXMR,\n+\n+\tTRANSFORMER_TYPE_MAX,\n+};\n+\n+enum airoha_calib_const_type {\n+\tTX_AMP_TEST_A,\n+\tTX_AMP_TEST_B,\n+\tTX_AMP_TEST_C,\n+\tTX_AMP_TEST_D,\n+\tTX_AMP_1G_A,\n+\tTX_AMP_1G_B,\n+\tTX_AMP_1G_C,\n+\tTX_AMP_1G_D,\n+\tTX_AMP_100M_A,\n+\tTX_AMP_100M_B,\n+\tTX_AMP_10M_A,\n+\tTX_AMP_10M_B,\n+\tR50_A,\n+\tR50_B,\n+\tR50_C,\n+\tR50_D,\n+\n+\tCALIB_CONST_TYPE_MAX,\n+};\n+\n+struct airoha_socphy_shared {\n+\tstruct phy_device *phydev_p0;\n+\tenum airoha_transformer_type transformer_type[4];\n+\tenum airoha_mdi_resister_type mdi_resister_type;\n+\tbool rext_sw_calib_done;\n+\tint (*tx_amp_compensation_tbl)[TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4];\n+\tu8 *r50_cal_tbl;\n+\tu32 soc_pdidr;\n+};\n+\n+/*\n+ * 2 chip revision\n+ * TXMR or discrete\n+ * 2 MDI type\n+ * TX AMP test/TX AMP 1G/TX AMP 100M/TX AMP 10M/R50\n+ * 4 PHY\n+ */\n+static int an7581_tx_amp_compensation_tbl[2][TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4] = {\n+\t{ /* IC version 1 */\n+\t\t[DISCRETE] = {\n+\t\t\t{ },\n+\t\t\t{\n+\t\t\t\t[TX_AMP_TEST_A] = { -9, -7, -7, -5 },\n+\t\t\t\t[TX_AMP_TEST_B] = { -9, -9, -7, -4 },\n+\t\t\t\t[TX_AMP_TEST_C] = { -9, -7, -9, -6 },\n+\t\t\t\t[TX_AMP_TEST_D] = { -11, -9, -10, -8 },\n+\t\t\t\t[TX_AMP_1G_A] = { -9, -7, -7, -5 },\n+\t\t\t\t[TX_AMP_1G_B] = { -9, -8, -7, -4 },\n+\t\t\t\t[TX_AMP_1G_C] = { -9, -7, -9, -6 },\n+\t\t\t\t[TX_AMP_1G_D] = { -11, -8, -10, -8 },\n+\t\t\t\t[TX_AMP_100M_A] = { 4, 3, 4, 4 },\n+\t\t\t\t[TX_AMP_100M_B] = { 4, 4, 5, 4 },\n+\t\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_A] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_B] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_C] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_D] = { 0, 0, 0, 0 },\n+\t\t\t},\n+\t\t},\n+\t\t[TXMR] = {\n+\t\t\t{ },\n+\t\t\t{\n+\t\t\t\t[TX_AMP_TEST_A] = { -12, -11, -9, -6 },\n+\t\t\t\t[TX_AMP_TEST_B] = { -9, -13, -9, -5 },\n+\t\t\t\t[TX_AMP_TEST_C] = { -5, -4, -3, 1 },\n+\t\t\t\t[TX_AMP_TEST_D] = { -9, -8, -7, -5 },\n+\t\t\t\t[TX_AMP_1G_A] = { -12, -11, -9, -6 },\n+\t\t\t\t[TX_AMP_1G_B] = { -9, -13, -9, -5 },\n+\t\t\t\t[TX_AMP_1G_C] = { -5, -4, -3, 1 },\n+\t\t\t\t[TX_AMP_1G_D] = { -9, -8, -7, -5 },\n+\t\t\t\t[TX_AMP_100M_A] = { -2, -2, 0, 2 },\n+\t\t\t\t[TX_AMP_100M_B] = { -2, -2, 1, 1 },\n+\t\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_A] = { 15, 15, 15, 15 },\n+\t\t\t\t[R50_B] = { 15, 15, 18, 15 },\n+\t\t\t\t[R50_C] = { -8, -8, -8, -8 },\n+\t\t\t\t[R50_D] = { -8, -8, -8, -8 },\n+\t\t\t},\n+\t\t},\n+\t},\n+\t{ /* IC version 2 */\n+\t\t[DISCRETE] = {\n+\t\t\t{ },\n+\t\t\t{\n+\t\t\t\t[TX_AMP_TEST_A] = { -11, 11, -12, -7 },\n+\t\t\t\t[TX_AMP_TEST_B] = { -9, -10, -9, -8 },\n+\t\t\t\t[TX_AMP_TEST_C] = { -6, -3, -7, -4 },\n+\t\t\t\t[TX_AMP_TEST_D] = { -7, -8, -10, -7 },\n+\t\t\t\t[TX_AMP_1G_A] = { -11, -11, -12, -7 },\n+\t\t\t\t[TX_AMP_1G_B] = { -9, -10, -9, -8 },\n+\t\t\t\t[TX_AMP_1G_C] = { -6, -3, -7, -4 },\n+\t\t\t\t[TX_AMP_1G_D] = { -7, -8, -10, -7 },\n+\t\t\t\t[TX_AMP_100M_A] = { 2, 2, 1, 2 },\n+\t\t\t\t[TX_AMP_100M_B] = { 3, 3, 3, 3 },\n+\t\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_A] = { 12, 12, 12, 12 },\n+\t\t\t\t[R50_B] = { 7, 7, 7, 7 },\n+\t\t\t\t[R50_C] = { 2, 2, 0, 0 },\n+\t\t\t\t[R50_D] = { 0, 0, 2, 2 },\n+\t\t\t},\n+\t\t},\n+\t\t[TXMR] = {\n+\t\t\t{ },\n+\t\t\t{\n+\t\t\t\t[TX_AMP_TEST_A] = { -10, -12, -12, -11 },\n+\t\t\t\t[TX_AMP_TEST_B] = { -10, -11, -11, -10 },\n+\t\t\t\t[TX_AMP_TEST_C] = { -5, -7, -9, -3 },\n+\t\t\t\t[TX_AMP_TEST_D] = { -8, -10, -7, -8 },\n+\t\t\t\t[TX_AMP_1G_A] = { -12, -6, -6, 4 },\n+\t\t\t\t[TX_AMP_1G_B] = { -10, -5, -5, 1 },\n+\t\t\t\t[TX_AMP_1G_C] = { -5, -3, -4, 11 },\n+\t\t\t\t[TX_AMP_1G_D] = { -8, -3, -3, 4 },\n+\t\t\t\t[TX_AMP_100M_A] = { 2, 1, 0, 3 },\n+\t\t\t\t[TX_AMP_100M_B] = { 0, 0, 0, 3 },\n+\t\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t\t[R50_A] = { 15, 15, 15, 15 },\n+\t\t\t\t[R50_B] = { 15, 15, 18, 15 },\n+\t\t\t\t[R50_C] = { 4, 4, 4, 4 },\n+\t\t\t\t[R50_D] = { 4, 4, 4, 4 },\n+\t\t\t},\n+\t\t},\n+\t},\n+};\n+\n+static u8 an7581_zcal_to_r45ohm[64] = {\n+\t127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,\n+\t127, 127, 127, 127, 127, 127, 127, 127, 123, 119, 115, 112, 108, 104, 100,  96,\n+\t 94,  92,  88,  85,  82,  80,  76,  74,  72,  68,  66,  64,  62,  60,  56,  55,\n+\t 52,  50,  48,  46,  44,  42,  40,  39,  36,  35,  32,  32,  30,  28,  27,  25\n+};\n+\n+/*\n+ * 2 chip revision\n+ * TXMR or discrete\n+ * 2 MDI type\n+ * TX AMP test/TX AMP 1G/TX AMP 100M/TX AMP 10M/R50\n+ * 4 PHY\n+ */\n+static int an7583_tx_amp_compensation_tbl[TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4] = {\n+\t[DISCRETE] = {\n+\t\t[MDI_0R] = {\n+\t\t\t[TX_AMP_TEST_A] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_B] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_C] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_D] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_1G_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_B] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_C] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_D] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_100M_A] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_100M_B] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t[R50_A] = { 4, 4, 4, 4 },\n+\t\t\t[R50_B] = { 4, 4, 4, 4 },\n+\t\t\t[R50_C] = { 6, 6, 6, 6 },\n+\t\t\t[R50_D] = { 4, 4, 4, 4 },\n+\t\t},\n+\t\t[MDI_5R] = {\n+\t\t\t[TX_AMP_TEST_A] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_B] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_C] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_D] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_1G_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_B] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_C] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_D] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_100M_A] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_100M_B] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t[R50_A] = { 0, 0, 0, 0 },\n+\t\t\t[R50_B] = { 0, 0, 0, 0 },\n+\t\t\t[R50_C] = { 0, 0, 0, 0 },\n+\t\t\t[R50_D] = { 0, 0, 0, 0 },\n+\t\t},\n+\t},\n+\t[TXMR] = {\n+\t\t[MDI_0R] = {\n+\t\t\t[TX_AMP_TEST_A] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_B] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_C] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_D] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_1G_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_B] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_C] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_D] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_100M_A] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_100M_B] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t[R50_A] = { 4, 4, 0, 0 },\n+\t\t\t[R50_B] = { 4, 4, 0, 0 },\n+\t\t\t[R50_C] = { 5, 5, 3, 4 },\n+\t\t\t[R50_D] = { 4, 4, 4, 0 },\n+\t\t},\n+\t\t[MDI_5R] = {\n+\t\t\t[TX_AMP_TEST_A] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_B] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_C] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_TEST_D] = { -3, -3, -3, -3 },\n+\t\t\t[TX_AMP_1G_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_B] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_C] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_1G_D] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_100M_A] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_100M_B] = { 4, 4, 4, 4 },\n+\t\t\t[TX_AMP_10M_A] = { 0, 0, 0, 0 },\n+\t\t\t[TX_AMP_10M_B] = { 0, 0, 0, 0 },\n+\t\t\t[R50_A] = { -4, -4, -4, -4 },\n+\t\t\t[R50_B] = { -4, -4, -4, -4 },\n+\t\t\t[R50_C] = { -2, -2, -2, -2 },\n+\t\t\t[R50_D] = { -3, -3, -2, -2 },\n+\t\t},\n+\t},\n+};\n+\n+static u8 an7583_zcal_to_r50ohm_0R[64] = {\n+\t127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,\n+\t127, 127, 127, 122, 118, 114, 110, 106, 102,  98,  96,  92,  88,  85,  82,  80,\n+\t 76,  72,  70,  68,  64,  62,  60,  57,  55,  52,  50,  48,  46,  44,  41,  40,\n+\t 38,  36,  33,  32,  30,  28,  26,  24,  24,  22,  20,  18,  16,  16,  14,  12,\n+};\n+\n+static u8 an7583_zcal_to_r50ohm_5R[64] = {\n+\t127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,\n+\t127, 127, 127, 127, 127, 127, 127, 127, 127, 124, 120, 116, 112, 110, 106, 102,\n+\t 99,  96,  93,  90,  88,  84,  81,  79,  76,  73,  71,  68,  66,  64,  61,  59,\n+\t 56,  54,  52,  50,  48,  46,  44,  42,  40,  39,  37,  36,  33,  32,  31,  29,\n+};\n+\n+static int airoha_cal_cycle(struct phy_device *phydev, int devad,\n+\t\t\t    u32 regnum, u16 mask, u16 cal_val)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\n+\tphy_modify_mmd(phydev, devad, regnum, mask, cal_val);\n+\n+\tret = mtk_cal_cycle_wait(phydev_p0);\n+\tphydev_dbg(phydev, \"cal_val: 0x%x, ret: %d\\n\", cal_val, ret);\n+\n+\treturn ret;\n+}\n+\n+static int airoha_rext_cal_sw(struct phy_device *phydev)\n+{\n+\tint calibration_polarity;\n+\tu8 zcal_ctrl = 32;\n+\tint first_calib;\n+\tint ret;\n+\n+\t/* BG voltage output */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0xc000);\n+\t/* tst_mode2 */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0xff, 0x2);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN |\n+\t\t      MTK_PHY_RG_REXT_CALEN);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0);\n+\n+\tphydev_dbg(phydev, \"Start REXT SW cal.\\n\");\n+\tfirst_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,\n+\t\t\t\t       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);\n+\n+\tif (first_calib \u003c 0) {\n+\t\tphydev_err(phydev, \"REXT SW calibration failed.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* If REXT calibration failed:\n+\t * - increase dB until calibration succeed.\n+\t * If REXT calibration succeeded:\n+\t * - decrease dB until calibration fail to fine tune it.\n+\t */\n+\tif (first_calib == 1)\n+\t\tcalibration_polarity = -1;\n+\telse\n+\t\tcalibration_polarity = 1;\n+\n+\twhile (zcal_ctrl \u003e 0 \u0026\u0026\n+\t       zcal_ctrl \u003c FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {\n+\t\tzcal_ctrl += calibration_polarity;\n+\n+\t\tret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,\n+\t\t\t\t       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);\n+\t\t/* Exit if we either failed or succeeded compared to the\n+\t\t * first calibration result. (aka we finished fine tuning or\n+\t\t * we succeeded with calibration)\n+\t\t */\n+\t\tif (ret != first_calib)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (ret \u003c 0) {\n+\t\tphydev_err(phydev, \"REXT SW calibration failed.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (zcal_ctrl == 0 ||\n+\t    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {\n+\t\tzcal_ctrl = 32;\n+\t\tphydev_err(phydev, \"REXT SW calibration saturation. Defaulting to %x.\\n\",\n+\t\t\t   zcal_ctrl);\n+\t}\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,\n+\t\t       MTK_PHY_RG_REXT_TRIM_MASK,\n+\t\t       FIELD_PREP(MTK_PHY_RG_REXT_TRIM_MASK, zcal_ctrl));\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_RG_BG_RASEL,\n+\t\t       MTK_PHY_RG_BG_RASEL_MASK,\n+\t\t       FIELD_PREP(MTK_PHY_RG_BG_RASEL_MASK, zcal_ctrl \u003e\u003e 3));\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\n+\treturn 0;\n+}\n+\n+static int airoha_tx_offset_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tu16 dev1e_145_tmp, bmcr_tmp;\n+\tint calibration_polarity;\n+\tu16 reg_dac1, reg_dac2;\n+\tint zcal_ctrl = 32;\n+\tint first_calib;\n+\tu16 reg, mask;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\n+\t/* BG voltage output */\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_ANA_CALEN);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t      MTK_PHY_RG_TXVOS_CALEN);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_ANA_CALEN);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t      MTK_PHY_RG_TXVOS_CALEN);\n+\n+\t/* Force 1G full duplex for calibration */\n+\tbmcr_tmp = phy_read(phydev, MII_BMCR);\n+\tphy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);\n+\n+\t/* Force MDI */\n+\tdev1e_145_tmp = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x0145);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, 0x1010);\n+\n+\t/* 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96,\n+\t\t      0x8000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e,\n+\t\t      0xf808);\n+\n+\tswitch (txg_calen_x) {\n+\tcase PAIR_A:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_A;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_A;\n+\t\treg = MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B;\n+\t\tmask = MTK_PHY_CR_TX_AMP_OFFSET_A_MASK;\n+\t\tbreak;\n+\tcase PAIR_B:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(8));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_B;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_B;\n+\t\treg = MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B;\n+\t\tmask = AIROHA_PHY_CR_TX_AMP_OFFSET_B_MASK;\n+\t\tbreak;\n+\tcase PAIR_C:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(4));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_C;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_C;\n+\t\treg = MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D;\n+\t\tmask = MTK_PHY_CR_TX_AMP_OFFSET_C_MASK;\n+\t\tbreak;\n+\tcase PAIR_D:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(0));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_D;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_D;\n+\t\treg = MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D;\n+\t\tmask = AIROHA_PHY_CR_TX_AMP_OFFSET_D_MASK;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac1,\n+\t\t      0x8000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac2,\n+\t\t      0x8000);\n+\n+\tphydev_dbg(phydev, \"Start TX Offset SW cal.\\n\");\n+\n+\tfirst_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg, mask,\n+\t\t\t\t       zcal_ctrl \u003c\u003c __ffs(mask));\n+\n+\t/* If TX Offset calibration failed:\n+\t * - increase dB until calibration succeed.\n+\t * If TX Offset calibration succeeded:\n+\t * - decrease dB until calibration fail to fine tune it.\n+\t */\n+\tif (first_calib == 1)\n+\t\tcalibration_polarity = -1;\n+\telse\n+\t\tcalibration_polarity = 1;\n+\n+\twhile (zcal_ctrl \u003e 0 \u0026\u0026 zcal_ctrl \u003c 63) {\n+\t\tu32 val;\n+\n+\t\tzcal_ctrl += calibration_polarity;\n+\t\tif (zcal_ctrl \u003e= 0)\n+\t\t\tval = zcal_ctrl;\n+\t\telse\n+\t\t\tval = 63;\n+\n+\t\tret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg, mask,\n+\t\t\t\t       val \u003c\u003c __ffs(mask));\n+\t\t/* Exit if we either failed or succeeded compared to the\n+\t\t * first calibration result. (aka we finished fine tuning or\n+\t\t * we succeeded with calibration)\n+\t\t */\n+\t\tif (ret != first_calib)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (ret \u003c 0) {\n+\t\tphydev_err(phydev, \"TX Offset calibration failed.\\n\");\n+\t\tret = -EINVAL;\n+\t}\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0x0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D, 0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96, 0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0);\n+\n+\t/* Restore BMCR */\n+\tphy_write(phydev, MII_BMCR, bmcr_tmp);\n+\n+\t/* Restore MDI */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, dev1e_145_tmp);\n+\n+\treturn ret \u003c 0 ? ret : 0;\n+}\n+\n+static int airoha_tx_amp_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tu16 mask_gbe, mask_tbt, mask_tst, mask_hbt;\n+\tu16 reg, reg_100, reg_dac1, reg_dac2;\n+\tstruct phy_device *phydev_p0;\n+\tint calibration_polarity;\n+\tu8 zcal_ctrl = 32;\n+\tint first_calib;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\n+\t/* BG voltage output */\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x145, 0x1010);\n+\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t      MTK_PHY_RG_TXVOS_CALEN);\n+\n+\t/* select 1V */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);\n+\n+\t/* enable Tx VLD*/\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xf808);\n+\n+\t/* Force 1G full duplex for calibration */\n+\tphy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,\n+\t\t      0x8000 | 0xf0);\n+\n+\tswitch (txg_calen_x) {\n+\tcase PAIR_A:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_A;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_A;\n+\t\treg = MTK_PHY_TXVLD_DA_RG;\n+\t\tmask_gbe = MTK_PHY_DA_TX_I2MPB_A_GBE_MASK;\n+\t\tmask_tbt = MTK_PHY_DA_TX_I2MPB_A_TBT_MASK;\n+\t\treg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_A2;\n+\t\tmask_hbt = MTK_PHY_DA_TX_I2MPB_A_HBT_MASK;\n+\t\tmask_tst = MTK_PHY_DA_TX_I2MPB_A_TST_MASK;\n+\t\tbreak;\n+\tcase PAIR_B:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(8));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_B;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_B;\n+\t\treg = MTK_PHY_TX_I2MPB_TEST_MODE_B1;\n+\t\tmask_gbe = MTK_PHY_DA_TX_I2MPB_B_GBE_MASK;\n+\t\tmask_tbt = MTK_PHY_DA_TX_I2MPB_B_TBT_MASK;\n+\t\treg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_B2;\n+\t\tmask_hbt = MTK_PHY_DA_TX_I2MPB_B_HBT_MASK;\n+\t\tmask_tst = MTK_PHY_DA_TX_I2MPB_B_TST_MASK;\n+\t\tbreak;\n+\tcase PAIR_C:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(4));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_C;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_C;\n+\t\treg = MTK_PHY_TX_I2MPB_TEST_MODE_C1;\n+\t\tmask_gbe = MTK_PHY_DA_TX_I2MPB_C_GBE_MASK;\n+\t\tmask_tbt = MTK_PHY_DA_TX_I2MPB_C_TBT_MASK;\n+\t\treg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_C2;\n+\t\tmask_hbt = MTK_PHY_DA_TX_I2MPB_C_HBT_MASK;\n+\t\tmask_tst = MTK_PHY_DA_TX_I2MPB_C_TST_MASK;\n+\t\tbreak;\n+\tcase PAIR_D:\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(0));\n+\t\treg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_D;\n+\t\treg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_D;\n+\t\treg = MTK_PHY_TX_I2MPB_TEST_MODE_D1;\n+\t\tmask_gbe = MTK_PHY_DA_TX_I2MPB_D_GBE_MASK;\n+\t\tmask_tbt = MTK_PHY_DA_TX_I2MPB_D_TBT_MASK;\n+\t\treg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_D2;\n+\t\tmask_hbt = MTK_PHY_DA_TX_I2MPB_D_HBT_MASK;\n+\t\tmask_tst = MTK_PHY_DA_TX_I2MPB_D_TST_MASK;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac1,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac2,\n+\t\t      0x8000 | 0xf0);\n+\n+\tphydev_dbg(phydev, \"Start TX Amp SW cal.\\n\");\n+\tfirst_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg,\n+\t\t\t\t       mask_gbe, zcal_ctrl \u003c\u003c __ffs(mask_gbe));\n+\n+\t/* If TX Amp calibration failed:\n+\t * - increase dB until calibration succeed.\n+\t * If TX Amp calibration succeeded:\n+\t * - decrease dB until calibration fail to fine tune it.\n+\t */\n+\tif (first_calib == 1)\n+\t\tcalibration_polarity = -1;\n+\telse\n+\t\tcalibration_polarity = 1;\n+\n+\twhile (zcal_ctrl \u003e 0 \u0026\u0026\n+\t       zcal_ctrl \u003c FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {\n+\t\tzcal_ctrl += calibration_polarity;\n+\n+\t\tret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg,\n+\t\t\t\t       mask_gbe, zcal_ctrl \u003c\u003c __ffs(mask_gbe));\n+\t\t/* Exit if we either failed or succeeded compared to the\n+\t\t * first calibration result. (aka we finished fine tuning or\n+\t\t * we succeeded with calibration)\n+\t\t */\n+\t\tif (ret != first_calib)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (ret \u003c 0) {\n+\t\tphydev_err(phydev, \"TX AMP calibration failed.\\n\");\n+\t\tzcal_ctrl = 32;\n+\t\tphy_modify_mmd(phydev, MDIO_MMD_VEND1, reg,\n+\t\t\t       mask_gbe | mask_tbt,\n+\t\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_gbe)) |\n+\t\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_tbt)));\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (zcal_ctrl == 0 ||\n+\t    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK))\n+\t\tphydev_warn(phydev, \"TX AMP SW calibration saturation.\\n\");\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND1, reg,\n+\t\t       mask_gbe | mask_tbt,\n+\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_gbe)) |\n+\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_tbt)));\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND1, reg_100,\n+\t\t       mask_hbt | mask_tst,\n+\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_hbt)) |\n+\t\t       (zcal_ctrl \u003c\u003c __ffs(mask_tst)));\n+\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, 0x145, 0x1000);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0);\n+\n+\t/* Restore AN enable */\n+\tphy_write(phydev, MII_BMCR, BMCR_ANENABLE);\n+\n+\treturn 0;\n+}\n+\n+static int airoha_tx_r50_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tu16 dev1e_145_tmp, bmcr_tmp;\n+\tint calibration_polarity;\n+\tu8 zcal_ctrl = 32;\n+\tint first_calib;\n+\tu16 val;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\n+\t/* BG voltage output */\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);\n+\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\t/* select 1V */\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\t/* select 1V */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);\n+\n+\t/* Force 1G full duplex for calibration */\n+\tbmcr_tmp = phy_read(phydev, MII_BMCR);\n+\tphy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);\n+\n+\t/* Force MDI */\n+\tdev1e_145_tmp = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x0145);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, 0x1010);\n+\n+\t/* disable tx slew control */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0185, 0x0000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00fb, 0x0100);\n+\n+\tswitch (txg_calen_x) {\n+\tcase PAIR_A:\n+\t\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t\t MTK_PHY_RG_ANA_CAL_RG0,\n+\t\t\t\t MTK_PHY_RG_ZCALEN_A);\n+\t\tbreak;\n+\tcase PAIR_B:\n+\t\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t\t MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t\t\t MTK_PHY_RG_ZCALEN_B);\n+\t\tbreak;\n+\tcase PAIR_C:\n+\t\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t\t MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t\t\t MTK_PHY_RG_ZCALEN_C);\n+\t\tbreak;\n+\tcase PAIR_D:\n+\t\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t\t MTK_PHY_RG_ANA_CAL_RG1,\n+\t\t\t\t MTK_PHY_RG_ZCALEN_D);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tphydev_dbg(phydev, \"Start TX r50 SW cal.\\n\");\n+\tfirst_calib = airoha_cal_cycle(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,\n+\t\t\t\t       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);\n+\n+\tif (first_calib \u003c 0) {\n+\t\tphydev_err(phydev, \"TX r50 SW calibration failed.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* If TX r50 calibration failed:\n+\t * - increase dB until calibration succeed.\n+\t * If TX r50 calibration succeeded:\n+\t * - decrease dB until calibration fail to fine tune it.\n+\t */\n+\tif (first_calib == 1)\n+\t\tcalibration_polarity = -1;\n+\telse\n+\t\tcalibration_polarity = 1;\n+\n+\twhile (zcal_ctrl \u003e 0 \u0026\u0026\n+\t       zcal_ctrl \u003c FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {\n+\t\tzcal_ctrl += calibration_polarity;\n+\n+\t\tret = airoha_cal_cycle(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,\n+\t\t\t\t       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);\n+\t\t/* Exit if we either failed or succeeded compared to the\n+\t\t * first calibration result. (aka we finished fine tuning or\n+\t\t * we succeeded with calibration)\n+\t\t */\n+\t\tif (ret != first_calib)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (ret \u003c 0) {\n+\t\tphydev_err(phydev, \"TX r50 SW calibration failed.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (zcal_ctrl == 0 ||\n+\t    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK))\n+\t\tphydev_warn(phydev, \"TX r50 SW calibration saturation.\\n\");\n+\n+\tzcal_ctrl = shared-\u003er50_cal_tbl[zcal_ctrl];\n+\n+\tswitch (txg_calen_x) {\n+\tcase PAIR_A:\n+\t\tval = BIT(15) | FIELD_PREP(AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK, zcal_ctrl);\n+\t\tphy_modify_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t       MTK_PHY_RG_CR_TX_R50_OFFSET_A_B,\n+\t\t\t       BIT(15) | AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK, val);\n+\t\tbreak;\n+\tcase PAIR_B:\n+\t\tval = BIT(7) | FIELD_PREP(MTK_PHY_CR_TX_R50_OFFSET_B_MASK, zcal_ctrl);\n+\t\tphy_modify_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t       MTK_PHY_RG_CR_TX_R50_OFFSET_A_B,\n+\t\t\t       BIT(7) | MTK_PHY_CR_TX_R50_OFFSET_B_MASK, val);\n+\t\tbreak;\n+\tcase PAIR_C:\n+\t\tval = BIT(15) | FIELD_PREP(AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK, zcal_ctrl);\n+\t\tphy_modify_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t       MTK_PHY_RG_CR_TX_R50_OFFSET_C_D,\n+\t\t\t       BIT(15) | AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK, val);\n+\t\tbreak;\n+\tcase PAIR_D:\n+\t\tval = BIT(7) | FIELD_PREP(MTK_PHY_CR_TX_R50_OFFSET_D_MASK, zcal_ctrl);\n+\t\tphy_modify_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t       MTK_PHY_RG_CR_TX_R50_OFFSET_C_D,\n+\t\t\t       BIT(7) | MTK_PHY_CR_TX_R50_OFFSET_D_MASK, val);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);\n+\n+\t/* Enable tx slew control */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0185, 0x0001);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00fb, 0x0000);\n+\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x0);\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x0);\n+\n+\t/* Restore BMCR */\n+\tphy_write(phydev, MII_BMCR, bmcr_tmp);\n+\n+\t/* Restore MDI */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, dev1e_145_tmp);\n+\n+\treturn 0;\n+}\n+\n+static int airoha_rx_offset_cal_sw(struct phy_device *phydev)\n+{\n+\t/* Hw bypass, Fw cal */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96, 0x0);\n+\t/* tx/rx_cal_criteria_value */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x37, 0x0033);\n+\n+\t/* rx offset cal by Hw setup */\n+\tphy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,\n+\t\t\t   BIT(14) | BIT(11));\n+\n+\t/* disable rtune calibration */\n+\tphy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, 0x107,\n+\t\t\t   BIT(12));\n+\n+\t/* bypass tx/rx dc offset cancellation process */\n+\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1, 0x171,\n+\t\t\t BIT(8) | BIT(7));\n+\n+\t/* rx offset calibration start */\n+\tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,\n+\t\t\t BIT(13));\n+\n+\t/* rx offset calibration stop */\n+\tphy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,\n+\t\t\t   BIT(13));\n+\n+\tmdelay(10);\n+\n+\tphy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x171,\n+\t\t\t   BIT(8) | BIT(7));\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x145, 0x1000);\n+\n+\tif (phydev-\u003edrv-\u003ephy_id == AIROHA_GPHY_ID_AN7581)\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1,\n+\t\t\t      MTK_PHY_RG_ANA_CAL_RG6, 0x1);\n+\n+\treturn 0;\n+}\n+\n+static int airoha_cal_sw(struct phy_device *phydev, enum CAL_ITEM cal_item,\n+\t\t\t u8 start_pair, u8 end_pair)\n+{\n+\tu8 pair_n;\n+\tint ret;\n+\n+\tfor (pair_n = start_pair; pair_n \u003c= end_pair; pair_n++) {\n+\t\tswitch (cal_item) {\n+\t\tcase REXT:\n+\t\t\tret = airoha_rext_cal_sw(phydev);\n+\t\t\tbreak;\n+\t\tcase TX_OFFSET:\n+\t\t\tret = airoha_tx_offset_cal_sw(phydev, pair_n);\n+\t\t\tbreak;\n+\t\tcase TX_AMP:\n+\t\t\tret = airoha_tx_amp_cal_sw(phydev, pair_n);\n+\t\t\tbreak;\n+\t\tcase TX_R50:\n+\t\t\tret = airoha_tx_r50_cal_sw(phydev, pair_n);\n+\t\t\tbreak;\n+\t\tcase RX_OFFSET:\n+\t\t\tret = airoha_rx_offset_cal_sw(phydev);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\treturn 0;\n+}\n+\n+static int airoha_start_cal(struct phy_device *phydev, enum CAL_ITEM cal_item,\n+\t\t\t    enum CAL_MODE cal_mode, u8 start_pair,\n+\t\t\t    u8 end_pair, u32 *buf)\n+{\n+\tint ret;\n+\n+\tswitch (cal_mode) {\n+\tcase SW_M:\n+\t\tret = airoha_cal_sw(phydev, cal_item, start_pair, end_pair);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (ret) {\n+\t\tphydev_err(phydev, \"cal %d failed\\n\", cal_item);\n+\t\treturn -EIO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int airoha_phy_calib(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\n+\t/* PreCalibrate Set */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x5c, 0x6666);\n+\n+\tphy_package_lock(phydev);\n+\tif (!shared-\u003erext_sw_calib_done) {\n+\t\tret = airoha_start_cal(phydev, REXT, SW_M, NO_PAIR, NO_PAIR, NULL);\n+\t\tif (ret) {\n+\t\t\tphy_package_unlock(phydev);\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\tshared-\u003erext_sw_calib_done = true;\n+\t}\n+\tphy_package_unlock(phydev);\n+\n+\tret = airoha_start_cal(phydev, TX_R50, SW_M, PAIR_A, PAIR_D, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_start_cal(phydev, TX_OFFSET, SW_M, PAIR_A, PAIR_D, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_start_cal(phydev, TX_AMP, SW_M, PAIR_A, PAIR_D, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_start_cal(phydev, RX_OFFSET, SW_M, NO_PAIR, NO_PAIR, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Gating, short with other pair */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x15, 0x0);\n+\n+\tphy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);\n+\n+\treturn 0;\n+}\n+\n+static int airoha_phy_auto_select_transformer(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tu8 phy_offset;\n+\tu16 bmcr_tmp;\n+\tint oldpage;\n+\tint ret = 0;\n+\tu16 val;\n+\tint i;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\tphy_offset = phydev-\u003emdio.addr - phydev_p0-\u003emdio.addr;\n+\n+\t/* Force 1G full duplex for calibration */\n+\tbmcr_tmp = phy_read(phydev, MII_BMCR);\n+\tphy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x271, GENMASK(4, 0),\n+\t\t       FIELD_PREP(GENMASK(4, 0), 0x3));\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x269, GENMASK(15, 12),\n+\t\t       FIELD_PREP(GENMASK(15, 12), 0x2));\n+\n+\tphy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x26f, GENMASK(14, 12),\n+\t\t       FIELD_PREP(GENMASK(14, 12), 0x0));\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,\n+\t\t      0x8000 | 0xf0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,\n+\t\t      0x8000 | 0xf0);\n+\n+\t/* Force pGA gain */\n+\toldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);\n+\t__mtk_tr_modify(phydev, 0x1, 0xf, 0x10,\n+\t\t\tGENMASK(20, 15),\n+\t\t\tFIELD_PREP(GENMASK(20, 15), 0x1f));\n+\n+\t__mtk_tr_modify(phydev, 0x1, 0xf, 0x11,\n+\t\t\tGENMASK(23, 18) | GENMASK(15, 10) | GENMASK(7, 2),\n+\t\t\tFIELD_PREP(GENMASK(23, 18), 0x1f) |\n+\t\t\tFIELD_PREP(GENMASK(15, 10), 0x1f) |\n+\t\t\tFIELD_PREP(GENMASK(7, 2), 0x1f));\n+\tphy_restore_page(phydev, oldpage, 0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xc9, 0xffff);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x151, 0x12);\n+\n+\tswitch (phy_offset) {\n+\tcase 0:\n+\t\tval = 0x1;\n+\t\tbreak;\n+\tcase 1:\n+\t\tval = 0x3;\n+\t\tbreak;\n+\tcase 2:\n+\t\tval = 0x5;\n+\t\tbreak;\n+\tcase 3:\n+\t\tval = 0x7;\n+\t\tbreak;\n+\tdefault:\n+\t\tret = -EINVAL;\n+\t\tgoto exit;\n+\t}\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x15,\n+\t\t      FIELD_PREP(GENMASK(14, 12), val) | 0x161);\n+\tmdelay(500);\n+\n+\tfor (i = 0; i \u003c 3; i++)\n+\t\tval = phy_read_mmd(phydev, MDIO_MMD_VEND2, 0x1a);\n+\n+\t/* Check the value and report transformer type for later */\n+\tshared-\u003etransformer_type[phy_offset] = val \u003c 0xe0;\n+\n+exit:\n+\t/* Switch to Default */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x15, 0x1000);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0x0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,\n+\t\t      0x0);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,\n+\t\t      0x0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xc9, 0xfff);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x151, 0x0);\n+\n+\toldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);\n+\t__mtk_tr_modify(phydev, 0x1, 0xf, 0x10,\n+\t\t\tGENMASK(20, 15),\n+\t\t\tFIELD_PREP(GENMASK(20, 15), 0x4));\n+\n+\t__mtk_tr_modify(phydev, 0x1, 0xf, 0x11,\n+\t\t\tGENMASK(23, 18) | GENMASK(15, 10) | GENMASK(7, 2),\n+\t\t\tFIELD_PREP(GENMASK(23, 18), 0x0) |\n+\t\t\tFIELD_PREP(GENMASK(15, 10), 0x0) |\n+\t\t\tFIELD_PREP(GENMASK(7, 2), 0x0));\n+\tphy_restore_page(phydev, oldpage, 0);\n+\n+\t/* Restore BMCR */\n+\tphy_write(phydev, MII_BMCR, bmcr_tmp);\n+\n+\treturn ret;\n+}\n+\n+static int airoha_phy_tx_amp_compensation(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\n+\tu16 reg_1e_12_read;\n+\tu16 reg_1e_16_read;\n+\tu16 reg_1e_17_read;\n+\tu16 reg_1e_18_read;\n+\tu16 reg_1e_19_read;\n+\tu16 reg_1e_20_read;\n+\tu16 reg_1e_21_read;\n+\tu16 reg_1e_22_read;\n+\tu16 reg_1e_174_read;\n+\tu16 reg_1e_175_read;\n+\n+\tint reg_1e_12_header;\n+\tint reg_1e_16_header;\n+\tint reg_1e_17_header;\n+\tint reg_1e_18_header;\n+\tint reg_1e_19_header;\n+\tint reg_1e_21_header;\n+\tint reg_1e_174_header;\n+\tint reg_1e_175_header;\n+\n+\tint reg_1e_12_end;\n+\tint reg_1e_16_end;\n+\tint reg_1e_17_end;\n+\tint reg_1e_18_end;\n+\tint reg_1e_20_end;\n+\tint reg_1e_22_end;\n+\tint reg_1e_174_end;\n+\tint reg_1e_175_end;\n+\n+\tstruct phy_device *phydev_p0;\n+\tu8 phy_offset;\n+\n+\tint txamp_low_limit = -3;\n+\tint txamp_high_limit = 0x42;\n+\n+\tint r50_low_limit = -8;\n+\tint r50_high_limit = 0x88;\n+\n+\tbool overflow;\n+\tint (*tx_amp_table)[CALIB_CONST_TYPE_MAX][4];\n+\tint transformer_type, mdi_resister_type;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\tphy_offset = phydev-\u003emdio.addr - phydev_p0-\u003emdio.addr;\n+\n+\ttransformer_type = shared-\u003etransformer_type[phy_offset];\n+\tmdi_resister_type = shared-\u003emdi_resister_type;\n+\ttx_amp_table = \u0026(*shared-\u003etx_amp_compensation_tbl)[transformer_type][mdi_resister_type];\n+\n+\treg_1e_12_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x12);\n+\treg_1e_16_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x16);\n+\treg_1e_17_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x17);\n+\treg_1e_18_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x18);\n+\treg_1e_19_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x19);\n+\treg_1e_20_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x20);\n+\treg_1e_21_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x21);\n+\treg_1e_22_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x22);\n+\treg_1e_174_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x174);\n+\treg_1e_175_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x175);\n+\n+\treg_1e_12_header = ((reg_1e_12_read \u0026 0xfc00) / 1024) + (*tx_amp_table)[TX_AMP_1G_A][phy_offset];\n+\treg_1e_17_header = ((reg_1e_17_read \u0026 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_B][phy_offset];\n+\treg_1e_19_header = ((reg_1e_19_read \u0026 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_C][phy_offset];\n+\treg_1e_21_header = ((reg_1e_21_read \u0026 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_D][phy_offset];\n+\n+\toverflow = false;\n+\tif (reg_1e_12_header \u003c txamp_low_limit ||\n+\t    reg_1e_12_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_17_header \u003c txamp_low_limit ||\n+\t    reg_1e_17_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_19_header \u003c txamp_low_limit ||\n+\t    reg_1e_19_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_21_header \u003c txamp_low_limit ||\n+\t    reg_1e_21_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\n+\tif (overflow) {\n+\t\treg_1e_12_header = 0x20;\n+\t\treg_1e_17_header = 0x20;\n+\t\treg_1e_19_header = 0x20;\n+\t\treg_1e_21_header = 0x20;\n+\t} else {\n+\t\tif (reg_1e_12_header \u003c 0)\n+\t\t\treg_1e_12_header = 0;\n+\t\telse if (reg_1e_12_header \u003e 0x3f)\n+\t\t\treg_1e_12_header = 0x3f;\n+\t\tif (reg_1e_17_header \u003c 0)\n+\t\t\treg_1e_17_header = 0;\n+\t\telse if (reg_1e_17_header \u003e 0x3f)\n+\t\t\treg_1e_17_header = 0x3f;\n+\t\tif (reg_1e_19_header \u003c 0)\n+\t\t\treg_1e_19_header = 0;\n+\t\telse if (reg_1e_19_header \u003e 0x3f)\n+\t\t\treg_1e_19_header = 0x3f;\n+\t\tif (reg_1e_21_header \u003c 0)\n+\t\t\treg_1e_21_header = 0;\n+\t\telse if (reg_1e_21_header \u003e 0x3f)\n+\t\t\treg_1e_21_header = 0x3f;\n+\t}\n+\n+\treg_1e_16_end = (reg_1e_16_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_TEST_A][phy_offset];\n+\treg_1e_18_end = (reg_1e_18_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_TEST_B][phy_offset];\n+\treg_1e_20_end = (reg_1e_20_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_TEST_C][phy_offset];\n+\treg_1e_22_end = (reg_1e_22_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_TEST_D][phy_offset];\n+\n+\toverflow = false;\n+\tif (reg_1e_16_end \u003c txamp_low_limit ||\n+\t    reg_1e_16_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_18_end \u003c txamp_low_limit ||\n+\t    reg_1e_18_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_20_end \u003c txamp_low_limit ||\n+\t    reg_1e_20_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_22_end \u003c txamp_low_limit ||\n+\t    reg_1e_22_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\n+\tif (overflow) {\n+\t\treg_1e_16_end = 0x20;\n+\t\treg_1e_18_end = 0x20;\n+\t\treg_1e_20_end = 0x20;\n+\t\treg_1e_22_end = 0x20;\n+\t} else {\n+\t\tif (reg_1e_16_end \u003c 0)\n+\t\t\treg_1e_16_end = 0;\n+\t\telse if (reg_1e_16_end \u003e 0x3f)\n+\t\t\treg_1e_16_end = 0x3f;\n+\t\tif (reg_1e_18_end \u003c 0)\n+\t\t\treg_1e_18_end = 0;\n+\t\telse if (reg_1e_18_end \u003e 0x3f)\n+\t\t\treg_1e_18_end = 0x3f;\n+\t\tif (reg_1e_20_end \u003c 0)\n+\t\t\treg_1e_20_end = 0;\n+\t\telse if (reg_1e_20_end \u003e 0x3f)\n+\t\t\treg_1e_20_end = 0x3f;\n+\t\tif (reg_1e_22_end \u003c 0)\n+\t\t\treg_1e_22_end = 0;\n+\t\telse if (reg_1e_22_end \u003e 0x3f)\n+\t\t\treg_1e_22_end = 0x3f;\n+\t}\n+\n+\treg_1e_16_header = ((reg_1e_16_read \u0026 0xfc00) / 1024) + (*tx_amp_table)[TX_AMP_100M_A][phy_offset];\n+\treg_1e_18_header = ((reg_1e_18_read \u0026 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_100M_B][phy_offset];\n+\n+\toverflow = false;\n+\tif (reg_1e_16_header \u003c txamp_low_limit ||\n+\t    reg_1e_16_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_18_header \u003c txamp_low_limit ||\n+\t    reg_1e_18_header \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\n+\tif (overflow) {\n+\t\treg_1e_16_header = 0x20;\n+\t\treg_1e_18_header = 0x20;\n+\t} else {\n+\t\tif (reg_1e_16_header \u003c 0)\n+\t\t\treg_1e_16_header = 0;\n+\t\telse if (reg_1e_16_header \u003e 0x3f)\n+\t\t\treg_1e_16_header = 0x3f;\n+\t\tif (reg_1e_18_header \u003c 0)\n+\t\t\treg_1e_18_header = 0;\n+\t\telse if (reg_1e_18_header \u003e 0x3f)\n+\t\t\treg_1e_18_header = 0x3f;\n+\t}\n+\n+\treg_1e_12_end = (reg_1e_12_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_10M_A][phy_offset];\n+\treg_1e_17_end = (reg_1e_17_read \u0026 0x003f) + (*tx_amp_table)[TX_AMP_10M_B][phy_offset];\n+\n+\toverflow = false;\n+\tif (reg_1e_12_end \u003c txamp_low_limit ||\n+\t    reg_1e_12_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_17_end \u003c txamp_low_limit ||\n+\t    reg_1e_17_end \u003e txamp_high_limit)\n+\t\toverflow = true;\n+\n+\tif (overflow) {\n+\t\treg_1e_12_end = 0x20;\n+\t\treg_1e_17_end = 0x20;\n+\t} else {\n+\t\tif (reg_1e_12_end \u003c 0)\n+\t\t\treg_1e_12_end = 0;\n+\t\telse if (reg_1e_12_end \u003e 0x3f)\n+\t\t\treg_1e_12_end = 0x3f;\n+\t\tif (reg_1e_17_end \u003c 0)\n+\t\t\treg_1e_17_end = 0;\n+\t\telse if (reg_1e_17_end \u003e 0x3f)\n+\t\t\treg_1e_17_end = 0x3f;\n+\t}\n+\n+\treg_1e_174_header = ((reg_1e_174_read \u0026 0x7f00) / 256) + (*tx_amp_table)[R50_A][phy_offset];\n+\treg_1e_174_end = (reg_1e_174_read \u0026 0x007f) + (*tx_amp_table)[R50_B][phy_offset];\n+\treg_1e_175_header = ((reg_1e_175_read \u0026 0x7f00) / 256) + (*tx_amp_table)[R50_C][phy_offset];\n+\treg_1e_175_end = (reg_1e_175_read \u0026 0x007f) + (*tx_amp_table)[R50_D][phy_offset];\n+\n+\toverflow = false;\n+\tif (reg_1e_174_header \u003c r50_low_limit ||\n+\t    reg_1e_174_header \u003e r50_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_174_end \u003c r50_low_limit ||\n+\t    reg_1e_174_end \u003e r50_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_175_header \u003c r50_low_limit ||\n+\t    reg_1e_175_header \u003e r50_high_limit)\n+\t\toverflow = true;\n+\tif (reg_1e_175_end \u003c r50_low_limit ||\n+\t    reg_1e_175_end \u003e r50_high_limit)\n+\t\toverflow = true;\n+\n+\tif (overflow) {\n+\t\treg_1e_174_header = 0x34;\n+\t\treg_1e_174_end = 0x34;\n+\t\treg_1e_175_header = 0x34;\n+\t\treg_1e_175_end = 0x34;\n+\t} else {\n+\t\tif (reg_1e_174_header \u003c 0)\n+\t\t\treg_1e_174_header = 0;\n+\t\telse if (reg_1e_174_header \u003e 0x7f)\n+\t\t\treg_1e_174_header = 0x7f;\n+\t\tif (reg_1e_174_end \u003c 0)\n+\t\t\treg_1e_174_end = 0;\n+\t\telse if (reg_1e_174_end \u003e 0x7f)\n+\t\t\treg_1e_174_end = 0x7f;\n+\t\tif (reg_1e_175_header \u003c 0)\n+\t\t\treg_1e_175_header = 0;\n+\t\telse if (reg_1e_175_header \u003e 0x7f)\n+\t\t\treg_1e_175_header = 0x7f;\n+\t\tif (reg_1e_175_end \u003c 0)\n+\t\t\treg_1e_175_end = 0;\n+\t\telse if (reg_1e_175_end \u003e 0x7f)\n+\t\t\treg_1e_175_end = 0x7f;\n+\t}\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x12,\n+\t\t      (reg_1e_12_header * 1024) + reg_1e_12_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x16,\n+\t\t      (reg_1e_16_header * 1024) + reg_1e_16_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x17,\n+\t\t      (reg_1e_17_header * 256) + reg_1e_17_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x18,\n+\t\t      (reg_1e_18_header * 256) + reg_1e_18_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x19,\n+\t\t      (reg_1e_19_read \u0026 0x00ff) + (reg_1e_19_header * 256));\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x20,\n+\t\t      (reg_1e_20_read \u0026 0xff00) + reg_1e_20_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x21,\n+\t\t      (reg_1e_21_read \u0026 0x00ff) + (reg_1e_21_header * 256));\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x22,\n+\t\t      (reg_1e_22_read \u0026 0xff00) + reg_1e_22_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x174,\n+\t\t      0x8080 + (reg_1e_174_header * 256) + reg_1e_174_end);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x175,\n+\t\t      0x8080 + (reg_1e_175_header * 256) + reg_1e_175_end);\n+\n+\treturn 0;\n+}\n+\n+static int an7581_phy_package_config_init_once(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\n+\t/* FIXME: Read SoC PDIDR if available or default to 2 (latest) */\n+\tshared-\u003esoc_pdidr = 2;\n+\n+\tshared-\u003emdi_resister_type = MDI_5R;\n+\tif (shared-\u003esoc_pdidr == 2)\n+\t\tshared-\u003etx_amp_compensation_tbl = \u0026an7581_tx_amp_compensation_tbl[1];\n+\telse\n+\t\tshared-\u003etx_amp_compensation_tbl = \u0026an7581_tx_amp_compensation_tbl[0];\n+\tshared-\u003er50_cal_tbl = an7581_zcal_to_r45ohm;\n+\n+\treturn 0;\n+}\n+\n+static int an7581_phy_config_init(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tu8 phy_offset;\n+\tint oldpage;\n+\tint ret;\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\tphy_offset = phydev-\u003emdio.addr - phydev_p0-\u003emdio.addr;\n+\n+\tif (phy_package_init_once(phydev)) {\n+\t\tret = an7581_phy_package_config_init_once(phydev);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tret = airoha_phy_calib(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_phy_auto_select_transformer(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_phy_tx_amp_compensation(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* RX setting for 5R_TXMR before AN setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe6, 0x1111);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe7, 0x5555);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe9, 0x0001);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xfe, 0x0000);\n+\n+\t/* Long Loop Reach setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x11, 0xff00);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x202, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x203, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x204, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x205, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x206, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x207, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x208, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x209, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20a, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20b, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20e, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20f, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x210, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x211, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x212, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x213, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x214, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x215, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x216, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x217, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21a, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21b, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21c, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21d, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21e, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21f, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x220, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x221, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x222, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x223, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x226, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x227, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x228, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x229, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22a, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22b, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22c, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22d, 0x0025);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22e, 0x2310);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22f, 0x0025);\n+\n+\t/* RX Setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3c, 0xc000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3d, 0x0000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);\n+\n+\t/* EEE setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_AN, 0x3c, 0x0000);\n+\n+\t/* RX */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x41, 0x3333);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x44, 0x00c0);\n+\n+\t/* 10M settings */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a3, 0x00d2);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a4, 0x010e);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27b, 0x1177);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27c, 0x0808);\n+\n+\toldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_1);\n+\t__phy_write(phydev, 0x14, 0x3a18);\n+\tphy_restore_page(phydev, oldpage, 0);\n+\n+\tphy_write(phydev, 0x9, 0x1e00);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x269, 0x2114);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26a, 0x1113);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26f, 0x0000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x2c63);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x272, 0x0c2b);\n+\n+\t/* EEE set because power down can't set tokenring */\n+\toldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);\n+\t__mtk_tr_write(phydev, 0x0, 0x7, 0x15, 0x0055a0);\n+\t__mtk_tr_write(phydev, 0x0, 0x7, 0x17, 0x07ff3f);\n+\t__mtk_tr_write(phydev, 0x1, 0xf, 0x0, 0x00001e);\n+\t__mtk_tr_write(phydev, 0x1, 0xf, 0x1, 0x6fb90a);\n+\t__mtk_tr_write(phydev, 0x1, 0xf, 0x18, 0x0e2f00);\n+\t__mtk_tr_write(phydev, 0x1, 0xd, 0x26, 0x444444);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x3, 0x000004);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x6, 0x2ebaef);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x8, 0x00000b);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0xc, 0x00504d);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0xd, 0x02314f);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0xf, 0x003028);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x10, 0x00000a);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x11, 0x040001);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x14, 0x00024a);\n+\t__mtk_tr_write(phydev, 0x2, 0xd, 0x1c, 0x003210);\n+\tphy_restore_page(phydev, oldpage, 0);\n+\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x120, 0x8014);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x122, 0xffff);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x144, 0x0200);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x14a, 0xee20);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x19b, 0x0111);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x234, 0x1181);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x238, 0x0120);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x239, 0x0117);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x2d1, 0x0733);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x323, 0x0011);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x324, 0x013f);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x326, 0x0037);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x268, 0x07f4);\n+\n+\tif (shared-\u003etransformer_type[phy_offset] == TXMR) {\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0187);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cc);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0109);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x020b);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0202);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03c5);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c2);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0309);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x000e);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0002);\n+\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0880);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0880);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0880);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0880);\n+\t} else {\n+\t\tif (shared-\u003esoc_pdidr == 2) {\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x269, 0x1114);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26a, 0x1113);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26f, 0x2000);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x4c88);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x272, 0x0c2b);\n+\n+\t\t\t/* 100M sharp */\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0190);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01c8);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c0);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0030);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0208);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0000);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0318);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03c8);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c0);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0230);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x0008);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0200);\n+\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0885);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0885);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0885);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0885);\n+\t\t} else {\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0190);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cf);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c0);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0030);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x020f);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0000);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0318);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03cf);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c0);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0230);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x000f);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0200);\n+\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0003);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0003);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0003);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0003);\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int an7581_phy_probe(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared;\n+\tstruct mtk_socphy_priv *priv;\n+\tstruct pinctrl *pinctrl;\n+\tint ret;\n+\n+\t/* Toggle pinctrl to enable PHY LED */\n+\tpinctrl = devm_pinctrl_get_select(\u0026phydev-\u003emdio.dev, \"gbe-led\");\n+\tif (IS_ERR(pinctrl))\n+\t\tdev_err(\u0026phydev-\u003emdio.bus-\u003edev,\n+\t\t\t\"Failed to setup PHY LED pinctrl\\n\");\n+\n+\tret = devm_phy_package_join(\u0026phydev-\u003emdio.dev, phydev, 0,\n+\t\t\t\t    sizeof(struct airoha_socphy_shared));\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tpriv = devm_kzalloc(\u0026phydev-\u003emdio.dev, sizeof(*priv), GFP_KERNEL);\n+\tif (!priv)\n+\t\treturn -ENOMEM;\n+\n+\tshared = phy_package_get_priv(phydev);\n+\tif (phydev-\u003emdio.addr == AIROHA_DEFAULT_PORT0_ADDR)\n+\t\tshared-\u003ephydev_p0 = phydev;\n+\n+\t/*\n+\t * Make sure PHY at port 0 is available for calibration.\n+\t * If port 0 is disabled in DT, probing will eventually fail\n+\t * after exhausting the deferred probe retries.\n+\t */\n+\tif (!shared-\u003ephydev_p0) {\n+\t\tphydev_err(phydev, \"PHY at port 0 is not available yet. (mandatory for calibration)\\n\");\n+\t\treturn -EPROBE_DEFER;\n+\t}\n+\n+\tphydev-\u003epriv = priv;\n+\n+\treturn 0;\n+}\n+\n+static int an7581_phy_led_polarity_set(struct phy_device *phydev, int index,\n+\t\t\t\t       unsigned long modes)\n+{\n+\tu16 val = 0;\n+\tu32 mode;\n+\n+\tif (index \u003e= AIROHA_PHY_MAX_LEDS)\n+\t\treturn -EINVAL;\n+\n+\tfor_each_set_bit(mode, \u0026modes, __PHY_LED_MODES_NUM) {\n+\t\tswitch (mode) {\n+\t\tcase PHY_LED_ACTIVE_LOW:\n+\t\t\tval = MTK_PHY_LED_ON_POLARITY;\n+\t\t\tbreak;\n+\t\tcase PHY_LED_ACTIVE_HIGH:\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n+\treturn phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?\n+\t\t\t      MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL,\n+\t\t\t      MTK_PHY_LED_ON_POLARITY, val);\n+}\n+\n+static int en7528_phy_config_init(struct phy_device *phydev)\n+{\n+\t/* The LED controller of the EN7528 powers up with its external\n+\t * control disabled, leaving the LED pins dark regardless of what is\n+\t * programmed into the LED control registers. Hand the pins over to\n+\t * the LED control registers the same way the air_en8811h driver\n+\t * does; the mode field of this register is already set out of reset.\n+\t */\n+\treturn phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED_BCR,\n+\t\t\t\tMTK_PHY_LED_BCR_CLK_EN |\n+\t\t\t\tMTK_PHY_LED_BCR_EXT_CTRL);\n+}\n+\n+static int an7583_phy_package_config_init_once(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\n+\t/* FIXME: Read SoC MDI Resister Type if available or default to 5R */\n+\tshared-\u003emdi_resister_type = MDI_5R;\n+\n+\tif (shared-\u003emdi_resister_type == MDI_0R)\n+\t\tshared-\u003er50_cal_tbl = an7583_zcal_to_r50ohm_0R;\n+\tif (shared-\u003emdi_resister_type == MDI_5R)\n+\t\tshared-\u003er50_cal_tbl = an7583_zcal_to_r50ohm_5R;\n+\tshared-\u003etx_amp_compensation_tbl = \u0026an7583_tx_amp_compensation_tbl;\n+\n+\treturn 0;\n+}\n+\n+static int an7583_phy_config_init(struct phy_device *phydev)\n+{\n+\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\n+\tstruct phy_device *phydev_p0;\n+\tu8 phy_offset;\n+\tint ret;\n+\n+\t/* BMCR_PDOWN is enabled by default */\n+\tphy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);\n+\n+\tphydev_p0 = shared-\u003ephydev_p0;\n+\tphy_offset = phydev-\u003emdio.addr - phydev_p0-\u003emdio.addr;\n+\n+\tif (phy_package_init_once(phydev)) {\n+\t\tret = an7583_phy_package_config_init_once(phydev);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tret = airoha_phy_calib(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_phy_auto_select_transformer(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = airoha_phy_tx_amp_compensation(phydev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Enable Idle Mode Power Setting */\n+\tif (phy_offset == 0) {\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x268, 0x07F1);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x703, 0x3111);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x3C24);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x701, 0x1023);\n+\t}\n+\n+\tif (shared-\u003etransformer_type[phy_offset] == TXMR) {\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0881);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0881);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0881);\n+\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0881);\n+\n+\t\tif (shared-\u003emdi_resister_type == MDI_5R)\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);\n+\t\telse\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0200);\n+\t} else {\n+\t\tif (shared-\u003emdi_resister_type == MDI_5R) {\n+\t\t\t/* RX setting for 5R_TXMR before AN setting */\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe7, 0x6666);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe9, 0x0003);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xfe, 0x0006);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe6, 0x1111);\n+\t\t\t/* 100M sharp */\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0c86);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0c86);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0c86);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0c86);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cb);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0108);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0211);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03ce);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c8);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0005);\n+\t\t} else {\n+\t\t\t/* 100M sharp */\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0886);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0886);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0886);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0886);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0195);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cb);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0108);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0211);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03ce);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c3);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x0010);\n+\t\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0005);\n+\t\t}\n+\t}\n+\n+\t/* RX Setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3c, 0xc000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3d, 0x0000);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);\n+\n+\t/* EEE setting */\n+\tphy_write_mmd(phydev, MDIO_MMD_AN, 0x3c, 0x0000);\n+\n+\t/* 10M settings */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a3, 0x00d2);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a4, 0x010e);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27b, 0x1177);\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27c, 0x0808);\n+\n+\tphy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_3, 0x14, 0x190);\n+\tphy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_1, 0x14, 0x3a18);\n+\n+\tphy_write(phydev, 0x9, 0x0600);\n+\n+\t/* EEE keep only Pair A ON */\n+\tphy_write_mmd(phydev, MDIO_MMD_VEND1, 0x630, 0x006E);\n+\n+\treturn 0;\n+}\n+\n+static struct phy_driver mtk_socphy_driver[] = {\n+\t{\n+\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528),\n+\t\t.name\t\t= \"EcoNet EN7528 PHY\",\n+\t\t.config_init\t= en7528_phy_config_init,\n+\t\t.probe\t\t= an7581_phy_probe,\n+\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n+\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n+\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n+\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n+\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n+\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n+\t},\n+\t{\n+\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581),\n+\t\t.name\t\t= \"Airoha AN7581 PHY\",\n+\t\t.config_init\t= an7581_phy_config_init,\n+\t\t.config_intr\t= genphy_no_config_intr,\n+\t\t.handle_interrupt = genphy_handle_interrupt_no_ack,\n+\t\t.probe\t\t= an7581_phy_probe,\n+\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n+\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n+\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n+\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n+\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n+\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n+\t\t.read_page\t= mtk_phy_read_page,\n+\t\t.write_page\t= mtk_phy_write_page,\n+\t},\n+\t{\n+\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583),\n+\t\t.name\t\t= \"Airoha AN7583 PHY\",\n+\t\t.config_init\t= an7583_phy_config_init,\n+\t\t.probe\t\t= an7581_phy_probe,\n+\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n+\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n+\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n+\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n+\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n+\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n+\t\t.read_page\t= mtk_phy_read_page,\n+\t\t.write_page\t= mtk_phy_write_page,\n+\t},\n+};\n+\n+module_phy_driver(mtk_socphy_driver);\n+\n+static const struct mdio_device_id __maybe_unused airoha_socphy_tbl[] = {\n+\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528) },\n+\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581) },\n+\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583) },\n+\t{ }\n+};\n+\n+MODULE_DESCRIPTION(\"Airoha SoC Gigabit Ethernet PHY driver\");\n+MODULE_AUTHOR(\"Christian Marangi \u003cansuelsmth@gmail.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\n+MODULE_VERSION(\"01.01.20260306\");\n+\n+MODULE_DEVICE_TABLE(mdio, airoha_socphy_tbl);\ndiff --git a/drivers/net/phy/mediatek/mtk-ge-soc.c b/drivers/net/phy/mediatek/mtk-ge-soc.c\nindex 0041300d4f1013..4132ac40358355 100644\n--- a/drivers/net/phy/mediatek/mtk-ge-soc.c\n+++ b/drivers/net/phy/mediatek/mtk-ge-soc.c\n@@ -11,331 +11,10 @@\n \n #include \"../phylib.h\"\n #include \"mtk.h\"\n+#include \"mtk-ge-soc.h\"\n \n #define MTK_PHY_MAX_LEDS\t\t\t2\n \n-#define MTK_GPHY_ID_MT7981\t\t\t0x03a29461\n-#define MTK_GPHY_ID_MT7988\t\t\t0x03a29481\n-#define MTK_GPHY_ID_EN7528\t\t\t0x03a29491\n-#define MTK_GPHY_ID_AN7581\t\t\t0x03a294c1\n-#define MTK_GPHY_ID_AN7583\t\t\t0xc0ff0420\n-\n-#define MTK_EXT_PAGE_ACCESS\t\t\t0x1f\n-#define MTK_PHY_PAGE_STANDARD\t\t\t0x0000\n-#define MTK_PHY_PAGE_EXTENDED_3\t\t\t0x0003\n-\n-#define MTK_PHY_LPI_REG_14\t\t\t0x14\n-#define MTK_PHY_LPI_WAKE_TIMER_1000_MASK\tGENMASK(8, 0)\n-\n-#define MTK_PHY_LPI_REG_1c\t\t\t0x1c\n-#define MTK_PHY_SMI_DET_ON_THRESH_MASK\t\tGENMASK(13, 8)\n-\n-#define MTK_PHY_PAGE_EXTENDED_2A30\t\t0x2a30\n-\n-/* Registers on Token Ring debug nodes */\n-/* ch_addr = 0x0, node_addr = 0x7, data_addr = 0x15 */\n-/* NormMseLoThresh */\n-#define NORMAL_MSE_LO_THRESH_MASK\t\tGENMASK(15, 8)\n-\n-/* ch_addr = 0x0, node_addr = 0xf, data_addr = 0x3c */\n-/* RemAckCntLimitCtrl */\n-#define REMOTE_ACK_COUNT_LIMIT_CTRL_MASK\tGENMASK(2, 1)\n-\n-/* ch_addr = 0x1, node_addr = 0xd, data_addr = 0x20 */\n-/* VcoSlicerThreshBitsHigh */\n-#define VCO_SLICER_THRESH_HIGH_MASK\t\tGENMASK(23, 0)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x0 */\n-/* DfeTailEnableVgaThresh1000 */\n-#define DFE_TAIL_EANBLE_VGA_TRHESH_1000\t\tGENMASK(5, 1)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x1 */\n-/* MrvlTrFix100Kp */\n-#define MRVL_TR_FIX_100KP_MASK\t\t\tGENMASK(22, 20)\n-/* MrvlTrFix100Kf */\n-#define MRVL_TR_FIX_100KF_MASK\t\t\tGENMASK(19, 17)\n-/* MrvlTrFix1000Kp */\n-#define MRVL_TR_FIX_1000KP_MASK\t\t\tGENMASK(16, 14)\n-/* MrvlTrFix1000Kf */\n-#define MRVL_TR_FIX_1000KF_MASK\t\t\tGENMASK(13, 11)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x12 */\n-/* VgaDecRate */\n-#define VGA_DECIMATION_RATE_MASK\t\tGENMASK(8, 5)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x17 */\n-/* SlvDSPreadyTime */\n-#define SLAVE_DSP_READY_TIME_MASK\t\tGENMASK(22, 15)\n-/* MasDSPreadyTime */\n-#define MASTER_DSP_READY_TIME_MASK\t\tGENMASK(14, 7)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x18 */\n-/* EnabRandUpdTrig */\n-#define ENABLE_RANDOM_UPDOWN_COUNTER_TRIGGER\tBIT(8)\n-\n-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x20 */\n-/* ResetSyncOffset */\n-#define RESET_SYNC_OFFSET_MASK\t\t\tGENMASK(11, 8)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x0 */\n-/* FfeUpdGainForceVal */\n-#define FFE_UPDATE_GAIN_FORCE_VAL_MASK\t\tGENMASK(9, 7)\n-/* FfeUpdGainForce */\n-#define FFE_UPDATE_GAIN_FORCE\t\t\tBIT(6)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x3 */\n-/* TrFreeze */\n-#define TR_FREEZE_MASK\t\t\t\tGENMASK(11, 0)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x6 */\n-/* SS: Steady-state, KP: Proportional Gain */\n-/* SSTrKp100 */\n-#define SS_TR_KP100_MASK\t\t\tGENMASK(21, 19)\n-/* SSTrKf100 */\n-#define SS_TR_KF100_MASK\t\t\tGENMASK(18, 16)\n-/* SSTrKp1000Mas */\n-#define SS_TR_KP1000_MASTER_MASK\t\tGENMASK(15, 13)\n-/* SSTrKf1000Mas */\n-#define SS_TR_KF1000_MASTER_MASK\t\tGENMASK(12, 10)\n-/* SSTrKp1000Slv */\n-#define SS_TR_KP1000_SLAVE_MASK\t\t\tGENMASK(9, 7)\n-/* SSTrKf1000Slv */\n-#define SS_TR_KF1000_SLAVE_MASK\t\t\tGENMASK(6, 4)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x8 */\n-/* clear this bit if wanna select from AFE */\n-/* Regsigdet_sel_1000 */\n-#define EEE1000_SELECT_SIGNAL_DETECTION_FROM_DFE\tBIT(4)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xd */\n-/* RegEEE_st2TrKf1000 */\n-#define EEE1000_STAGE2_TR_KF_MASK\t\tGENMASK(13, 11)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xf */\n-/* RegEEE_slv_waketr_timer_tar */\n-#define SLAVE_WAKETR_TIMER_MASK\t\t\tGENMASK(20, 11)\n-/* RegEEE_slv_remtx_timer_tar */\n-#define SLAVE_REMTX_TIMER_MASK\t\t\tGENMASK(10, 1)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x10 */\n-/* RegEEE_slv_wake_int_timer_tar */\n-#define SLAVE_WAKEINT_TIMER_MASK\t\tGENMASK(10, 1)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x14 */\n-/* RegEEE_trfreeze_timer2 */\n-#define TR_FREEZE_TIMER2_MASK\t\t\tGENMASK(9, 0)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x1c */\n-/* RegEEE100Stg1_tar */\n-#define EEE100_LPSYNC_STAGE1_UPDATE_TIMER_MASK\tGENMASK(8, 0)\n-\n-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x25 */\n-/* REGEEE_wake_slv_tr_wait_dfesigdet_en */\n-#define WAKE_SLAVE_TR_WAIT_DFE_DETECTION_EN\tBIT(11)\n-\n-#define ANALOG_INTERNAL_OPERATION_MAX_US\t20\n-#define TXRESERVE_MIN\t\t\t\t0\n-#define TXRESERVE_MAX\t\t\t\t7\n-\n-#define MTK_PHY_ANARG_RG\t\t\t0x10\n-#define   MTK_PHY_TCLKOFFSET_MASK\t\tGENMASK(12, 8)\n-\n-/* Registers on MDIO_MMD_VEND1 */\n-#define MTK_PHY_TXVLD_DA_RG\t\t\t0x12\n-#define   MTK_PHY_DA_TX_I2MPB_A_GBE_MASK\tGENMASK(15, 10)\n-#define   MTK_PHY_DA_TX_I2MPB_A_TBT_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_A2\t\t0x16\n-#define   MTK_PHY_DA_TX_I2MPB_A_HBT_MASK\tGENMASK(15, 10)\n-#define   MTK_PHY_DA_TX_I2MPB_A_TST_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_B1\t\t0x17\n-#define   MTK_PHY_DA_TX_I2MPB_B_GBE_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_B_TBT_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_B2\t\t0x18\n-#define   MTK_PHY_DA_TX_I2MPB_B_HBT_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_B_TST_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_C1\t\t0x19\n-#define   MTK_PHY_DA_TX_I2MPB_C_GBE_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_C_TBT_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_C2\t\t0x20\n-#define   MTK_PHY_DA_TX_I2MPB_C_HBT_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_C_TST_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_D1\t\t0x21\n-#define   MTK_PHY_DA_TX_I2MPB_D_GBE_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_D_TBT_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_TX_I2MPB_TEST_MODE_D2\t\t0x22\n-#define   MTK_PHY_DA_TX_I2MPB_D_HBT_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_DA_TX_I2MPB_D_TST_MASK\tGENMASK(5, 0)\n-\n-#define MTK_PHY_RXADC_CTRL_RG7\t\t\t0xc6\n-#define   MTK_PHY_DA_AD_BUF_BIAS_LP_MASK\tGENMASK(9, 8)\n-\n-#define MTK_PHY_RXADC_CTRL_RG9\t\t\t0xc8\n-#define   MTK_PHY_DA_RX_PSBN_TBT_MASK\t\tGENMASK(14, 12)\n-#define   MTK_PHY_DA_RX_PSBN_HBT_MASK\t\tGENMASK(10, 8)\n-#define   MTK_PHY_DA_RX_PSBN_GBE_MASK\t\tGENMASK(6, 4)\n-#define   MTK_PHY_DA_RX_PSBN_LP_MASK\t\tGENMASK(2, 0)\n-\n-#define MTK_PHY_LDO_OUTPUT_V\t\t\t0xd7\n-\n-#define MTK_PHY_RG_ANA_CAL_RG0\t\t\t0xdb\n-#define   MTK_PHY_RG_CAL_CKINV\t\t\tBIT(12)\n-#define   MTK_PHY_RG_ANA_CALEN\t\t\tBIT(8)\n-#define   MTK_PHY_RG_ZCALEN_A\t\t\tBIT(0)\n-\n-#define MTK_PHY_RG_ANA_CAL_RG1\t\t\t0xdc\n-#define   MTK_PHY_RG_ZCALEN_B\t\t\tBIT(12)\n-#define   MTK_PHY_RG_ZCALEN_C\t\t\tBIT(8)\n-#define   MTK_PHY_RG_ZCALEN_D\t\t\tBIT(4)\n-#define   MTK_PHY_RG_TXVOS_CALEN\t\tBIT(0)\n-\n-#define MTK_PHY_RG_ANA_CAL_RG5\t\t\t0xe0\n-#define   MTK_PHY_RG_REXT_TRIM_MASK\t\tGENMASK(13, 8)\n-\n-#define MTK_PHY_RG_TX_FILTER\t\t\t0xfe\n-\n-#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG120\t0x120\n-#define   MTK_PHY_LPI_SIG_EN_LO_THRESH1000_MASK\tGENMASK(12, 8)\n-#define   MTK_PHY_LPI_SIG_EN_HI_THRESH1000_MASK\tGENMASK(4, 0)\n-\n-#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG122\t0x122\n-#define   MTK_PHY_LPI_NORM_MSE_HI_THRESH1000_MASK\tGENMASK(7, 0)\n-\n-#define MTK_PHY_RG_TESTMUX_ADC_CTRL\t\t0x144\n-#define   MTK_PHY_RG_TXEN_DIG_MASK\t\tGENMASK(5, 5)\n-\n-#define MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B\t\t0x172\n-#define   MTK_PHY_CR_TX_AMP_OFFSET_A_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_CR_TX_AMP_OFFSET_B_MASK\tGENMASK(6, 0)\n-\n-#define MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D\t\t0x173\n-#define   MTK_PHY_CR_TX_AMP_OFFSET_C_MASK\tGENMASK(13, 8)\n-#define   MTK_PHY_CR_TX_AMP_OFFSET_D_MASK\tGENMASK(6, 0)\n-\n-#define MTK_PHY_RG_AD_CAL_COMP\t\t\t0x17a\n-#define   MTK_PHY_AD_CAL_COMP_OUT_MASK\t\tGENMASK(8, 8)\n-\n-#define MTK_PHY_RG_AD_CAL_CLK\t\t\t0x17b\n-#define   MTK_PHY_DA_CAL_CLK\t\t\tBIT(0)\n-\n-#define MTK_PHY_RG_AD_CALIN\t\t\t0x17c\n-#define   MTK_PHY_DA_CALIN_FLAG\t\t\tBIT(0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN0_A\t\t0x17d\n-#define   MTK_PHY_DASN_DAC_IN0_A_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN0_B\t\t0x17e\n-#define   MTK_PHY_DASN_DAC_IN0_B_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN0_C\t\t0x17f\n-#define   MTK_PHY_DASN_DAC_IN0_C_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN0_D\t\t0x180\n-#define   MTK_PHY_DASN_DAC_IN0_D_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN1_A\t\t0x181\n-#define   MTK_PHY_DASN_DAC_IN1_A_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN1_B\t\t0x182\n-#define   MTK_PHY_DASN_DAC_IN1_B_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN1_C\t\t0x183\n-#define   MTK_PHY_DASN_DAC_IN1_C_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DASN_DAC_IN1_D\t\t0x184\n-#define   MTK_PHY_DASN_DAC_IN1_D_MASK\t\tGENMASK(9, 0)\n-\n-#define MTK_PHY_RG_DEV1E_REG19b\t\t\t0x19b\n-#define   MTK_PHY_BYPASS_DSP_LPI_READY\t\tBIT(8)\n-\n-#define MTK_PHY_RG_LP_IIR2_K1_L\t\t\t0x22a\n-#define MTK_PHY_RG_LP_IIR2_K1_U\t\t\t0x22b\n-#define MTK_PHY_RG_LP_IIR2_K2_L\t\t\t0x22c\n-#define MTK_PHY_RG_LP_IIR2_K2_U\t\t\t0x22d\n-#define MTK_PHY_RG_LP_IIR2_K3_L\t\t\t0x22e\n-#define MTK_PHY_RG_LP_IIR2_K3_U\t\t\t0x22f\n-#define MTK_PHY_RG_LP_IIR2_K4_L\t\t\t0x230\n-#define MTK_PHY_RG_LP_IIR2_K4_U\t\t\t0x231\n-#define MTK_PHY_RG_LP_IIR2_K5_L\t\t\t0x232\n-#define MTK_PHY_RG_LP_IIR2_K5_U\t\t\t0x233\n-\n-#define MTK_PHY_RG_DEV1E_REG234\t\t\t0x234\n-#define   MTK_PHY_TR_OPEN_LOOP_EN_MASK\t\tGENMASK(0, 0)\n-#define   MTK_PHY_LPF_X_AVERAGE_MASK\t\tGENMASK(7, 4)\n-#define   MTK_PHY_TR_LP_IIR_EEE_EN\t\tBIT(12)\n-\n-#define MTK_PHY_RG_LPF_CNT_VAL\t\t\t0x235\n-\n-#define MTK_PHY_RG_DEV1E_REG238\t\t\t0x238\n-#define   MTK_PHY_LPI_SLV_SEND_TX_TIMER_MASK\tGENMASK(8, 0)\n-#define   MTK_PHY_LPI_SLV_SEND_TX_EN\t\tBIT(12)\n-\n-#define MTK_PHY_RG_DEV1E_REG239\t\t\t0x239\n-#define   MTK_PHY_LPI_SEND_LOC_TIMER_MASK\tGENMASK(8, 0)\n-#define   MTK_PHY_LPI_TXPCS_LOC_RCV\t\tBIT(12)\n-\n-#define MTK_PHY_RG_DEV1E_REG27C\t\t\t0x27c\n-#define   MTK_PHY_VGASTATE_FFE_THR_ST1_MASK\tGENMASK(12, 8)\n-#define MTK_PHY_RG_DEV1E_REG27D\t\t\t0x27d\n-#define   MTK_PHY_VGASTATE_FFE_THR_ST2_MASK\tGENMASK(4, 0)\n-\n-#define MTK_PHY_RG_DEV1E_REG2C7\t\t\t0x2c7\n-#define   MTK_PHY_MAX_GAIN_MASK\t\t\tGENMASK(4, 0)\n-#define   MTK_PHY_MIN_GAIN_MASK\t\t\tGENMASK(12, 8)\n-\n-#define MTK_PHY_RG_DEV1E_REG2D1\t\t\t0x2d1\n-#define   MTK_PHY_VCO_SLICER_THRESH_BITS_HIGH_EEE_MASK\tGENMASK(7, 0)\n-#define   MTK_PHY_LPI_SKIP_SD_SLV_TR\t\tBIT(8)\n-#define   MTK_PHY_LPI_TR_READY\t\t\tBIT(9)\n-#define   MTK_PHY_LPI_VCO_EEE_STG0_EN\t\tBIT(10)\n-\n-#define MTK_PHY_RG_DEV1E_REG323\t\t\t0x323\n-#define   MTK_PHY_EEE_WAKE_MAS_INT_DC\t\tBIT(0)\n-#define   MTK_PHY_EEE_WAKE_SLV_INT_DC\t\tBIT(4)\n-\n-#define MTK_PHY_RG_DEV1E_REG324\t\t\t0x324\n-#define   MTK_PHY_SMI_DETCNT_MAX_MASK\t\tGENMASK(5, 0)\n-#define   MTK_PHY_SMI_DET_MAX_EN\t\tBIT(8)\n-\n-#define MTK_PHY_RG_DEV1E_REG326\t\t\t0x326\n-#define   MTK_PHY_LPI_MODE_SD_ON\t\tBIT(0)\n-#define   MTK_PHY_RESET_RANDUPD_CNT\t\tBIT(1)\n-#define   MTK_PHY_TREC_UPDATE_ENAB_CLR\t\tBIT(2)\n-#define   MTK_PHY_LPI_QUIT_WAIT_DFE_SIG_DET_OFF\tBIT(4)\n-#define   MTK_PHY_TR_READY_SKIP_AFE_WAKEUP\tBIT(5)\n-\n-#define MTK_PHY_LDO_PUMP_EN_PAIRAB\t\t0x502\n-#define MTK_PHY_LDO_PUMP_EN_PAIRCD\t\t0x503\n-\n-#define MTK_PHY_DA_TX_R50_PAIR_A\t\t0x53d\n-#define MTK_PHY_DA_TX_R50_PAIR_B\t\t0x53e\n-#define MTK_PHY_DA_TX_R50_PAIR_C\t\t0x53f\n-#define MTK_PHY_DA_TX_R50_PAIR_D\t\t0x540\n-\n-/* Registers on MDIO_MMD_VEND2 */\n-#define MTK_PHY_LED1_DEFAULT_POLARITIES\t\tBIT(1)\n-\n-/* LED basic control register, part of the same LED block as the LED0/LED1\n- * control registers above. The air_en8811h driver describes the same\n- * register as AIR_PHY_LED_BCR.\n- */\n-#define MTK_PHY_LED_BCR\t\t\t\t0x21\n-#define   MTK_PHY_LED_BCR_CLK_EN\t\tBIT(3)\n-#define   MTK_PHY_LED_BCR_EXT_CTRL\t\tBIT(15)\n-\n-#define MTK_PHY_RG_BG_RASEL\t\t\t0x115\n-#define   MTK_PHY_RG_BG_RASEL_MASK\t\tGENMASK(2, 0)\n-\n-/* 'boottrap' register reflecting the configuration of the 4 PHY LEDs */\n-#define RG_GPIO_MISC_TPBANK0\t\t\t0x6f0\n-#define   RG_GPIO_MISC_TPBANK0_BOOTMODE\t\tGENMASK(11, 8)\n-\n /* These macro privides efuse parsing for internal phy. */\n #define EFS_DA_TX_I2MPB_A(x)\t\t\t(((x) \u003e\u003e 0) \u0026 GENMASK(5, 0))\n #define EFS_DA_TX_I2MPB_B(x)\t\t\t(((x) \u003e\u003e 6) \u0026 GENMASK(5, 0))\n@@ -355,51 +34,16 @@\n #define EFS_RG_BG_RASEL(x)\t\t\t(((x) \u003e\u003e 4) \u0026 GENMASK(2, 0))\n #define EFS_RG_REXT_TRIM(x)\t\t\t(((x) \u003e\u003e 7) \u0026 GENMASK(5, 0))\n \n-enum {\n-\tNO_PAIR,\n-\tPAIR_A,\n-\tPAIR_B,\n-\tPAIR_C,\n-\tPAIR_D,\n-};\n-\n-enum calibration_mode {\n-\tEFUSE_K,\n-\tSW_K\n-};\n-\n-enum CAL_ITEM {\n-\tREXT,\n-\tTX_OFFSET,\n-\tTX_AMP,\n-\tTX_R50,\n-\tTX_VCM\n-};\n-\n-enum CAL_MODE {\n-\tEFUSE_M,\n-\tSW_M\n-};\n-\n struct mtk_socphy_shared {\n \tu32\t\t\tboottrap;\n \tstruct mtk_socphy_priv\tpriv[4];\n };\n \n-/* One calibration cycle consists of:\n- * 1.Set DA_CALIN_FLAG high to start calibration. Keep it high\n- *   until AD_CAL_COMP is ready to output calibration result.\n- * 2.Wait until DA_CAL_CLK is available.\n- * 3.Fetch AD_CAL_COMP_OUT.\n- */\n-static int cal_cycle(struct phy_device *phydev, int devad,\n-\t\t     u32 regnum, u16 mask, u16 cal_val)\n+int mtk_cal_cycle_wait(struct phy_device *phydev)\n {\n \tint reg_val;\n \tint ret;\n \n-\tphy_modify_mmd(phydev, devad, regnum,\n-\t\t       mask, cal_val);\n \tphy_set_bits_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_AD_CALIN,\n \t\t\t MTK_PHY_DA_CALIN_FLAG);\n \n@@ -418,7 +62,26 @@ static int cal_cycle(struct phy_device *phydev, int devad,\n \tret = phy_read_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_AD_CAL_COMP);\n \tif (ret \u003c 0)\n \t\treturn ret;\n-\tret = FIELD_GET(MTK_PHY_AD_CAL_COMP_OUT_MASK, ret);\n+\n+\treturn FIELD_GET(MTK_PHY_AD_CAL_COMP_OUT_MASK, ret);\n+}\n+EXPORT_SYMBOL_GPL(mtk_cal_cycle_wait);\n+\n+/* One calibration cycle consists of:\n+ * 1.Set DA_CALIN_FLAG high to start calibration. Keep it high\n+ *   until AD_CAL_COMP is ready to output calibration result.\n+ * 2.Wait until DA_CAL_CLK is available.\n+ * 3.Fetch AD_CAL_COMP_OUT.\n+ */\n+static int cal_cycle(struct phy_device *phydev, int devad,\n+\t\t     u32 regnum, u16 mask, u16 cal_val)\n+{\n+\tint ret;\n+\n+\tphy_modify_mmd(phydev, devad, regnum,\n+\t\t       mask, cal_val);\n+\n+\tret = mtk_cal_cycle_wait(phydev);\n \tphydev_dbg(phydev, \"cal_val: 0x%x, ret: %d\\n\", cal_val, ret);\n \n \treturn ret;\n@@ -1224,73 +887,6 @@ static int mt798x_phy_config_init(struct phy_device *phydev)\n \treturn mt798x_phy_calibration(phydev);\n }\n \n-static int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,\n-\t\t\t\t    unsigned long *delay_on,\n-\t\t\t\t    unsigned long *delay_off)\n-{\n-\tbool blinking = false;\n-\tint err;\n-\n-\terr = mtk_phy_led_num_dly_cfg(index, delay_on, delay_off, \u0026blinking);\n-\tif (err \u003c 0)\n-\t\treturn err;\n-\n-\terr = mtk_phy_hw_led_blink_set(phydev, index, blinking);\n-\tif (err)\n-\t\treturn err;\n-\n-\treturn mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,\n-\t\t\t\t     false);\n-}\n-\n-static int mt798x_phy_led_brightness_set(struct phy_device *phydev,\n-\t\t\t\t\t u8 index, enum led_brightness value)\n-{\n-\tint err;\n-\n-\terr = mtk_phy_hw_led_blink_set(phydev, index, false);\n-\tif (err)\n-\t\treturn err;\n-\n-\treturn mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,\n-\t\t\t\t     (value != LED_OFF));\n-}\n-\n-static const unsigned long supported_triggers =\n-\tBIT(TRIGGER_NETDEV_FULL_DUPLEX) |\n-\tBIT(TRIGGER_NETDEV_HALF_DUPLEX) |\n-\tBIT(TRIGGER_NETDEV_LINK)        |\n-\tBIT(TRIGGER_NETDEV_LINK_10)     |\n-\tBIT(TRIGGER_NETDEV_LINK_100)    |\n-\tBIT(TRIGGER_NETDEV_LINK_1000)   |\n-\tBIT(TRIGGER_NETDEV_RX)          |\n-\tBIT(TRIGGER_NETDEV_TX);\n-\n-static int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,\n-\t\t\t\t\t  unsigned long rules)\n-{\n-\treturn mtk_phy_led_hw_is_supported(phydev, index, rules,\n-\t\t\t\t\t   supported_triggers);\n-}\n-\n-static int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,\n-\t\t\t\t\t unsigned long *rules)\n-{\n-\treturn mtk_phy_led_hw_ctrl_get(phydev, index, rules,\n-\t\t\t\t       MTK_GPHY_LED_ON_SET,\n-\t\t\t\t       MTK_GPHY_LED_RX_BLINK_SET,\n-\t\t\t\t       MTK_GPHY_LED_TX_BLINK_SET);\n-};\n-\n-static int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,\n-\t\t\t\t\t unsigned long rules)\n-{\n-\treturn mtk_phy_led_hw_ctrl_set(phydev, index, rules,\n-\t\t\t\t       MTK_GPHY_LED_ON_SET,\n-\t\t\t\t       MTK_GPHY_LED_RX_BLINK_SET,\n-\t\t\t\t       MTK_GPHY_LED_TX_BLINK_SET);\n-};\n-\n static bool mt7988_phy_led_get_polarity(struct phy_device *phydev, int led_num)\n {\n \tstruct mtk_socphy_shared *priv = phy_package_get_priv(phydev);\n@@ -1427,71 +1023,6 @@ static int mt7981_phy_probe(struct phy_device *phydev)\n \treturn mt798x_phy_calibration(phydev);\n }\n \n-static int an7581_phy_probe(struct phy_device *phydev)\n-{\n-\tstruct mtk_socphy_priv *priv;\n-\tstruct pinctrl *pinctrl;\n-\n-\t/* Toggle pinctrl to enable PHY LED */\n-\tpinctrl = devm_pinctrl_get_select(\u0026phydev-\u003emdio.dev, \"gbe-led\");\n-\tif (IS_ERR(pinctrl))\n-\t\tdev_err(\u0026phydev-\u003emdio.bus-\u003edev,\n-\t\t\t\"Failed to setup PHY LED pinctrl\\n\");\n-\n-\tpriv = devm_kzalloc(\u0026phydev-\u003emdio.dev, sizeof(*priv), GFP_KERNEL);\n-\tif (!priv)\n-\t\treturn -ENOMEM;\n-\n-\tphydev-\u003epriv = priv;\n-\n-\treturn 0;\n-}\n-\n-static int an7581_phy_led_polarity_set(struct phy_device *phydev, int index,\n-\t\t\t\t       unsigned long modes)\n-{\n-\tu16 val = 0;\n-\tu32 mode;\n-\n-\tif (index \u003e= MTK_PHY_MAX_LEDS)\n-\t\treturn -EINVAL;\n-\n-\tfor_each_set_bit(mode, \u0026modes, __PHY_LED_MODES_NUM) {\n-\t\tswitch (mode) {\n-\t\tcase PHY_LED_ACTIVE_LOW:\n-\t\t\tval = MTK_PHY_LED_ON_POLARITY;\n-\t\t\tbreak;\n-\t\tcase PHY_LED_ACTIVE_HIGH:\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\t}\n-\n-\treturn phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?\n-\t\t\t      MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL,\n-\t\t\t      MTK_PHY_LED_ON_POLARITY, val);\n-}\n-\n-static int an7583_phy_config_init(struct phy_device *phydev)\n-{\n-\t/* BMCR_PDOWN is enabled by default */\n-\treturn phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);\n-}\n-\n-static int en7528_phy_config_init(struct phy_device *phydev)\n-{\n-\t/* The LED controller of the EN7528 powers up with its external\n-\t * control disabled, leaving the LED pins dark regardless of what is\n-\t * programmed into the LED control registers. Hand the pins over to\n-\t * the LED control registers the same way the air_en8811h driver\n-\t * does; the mode field of this register is already set out of reset.\n-\t */\n-\treturn phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED_BCR,\n-\t\t\t\tMTK_PHY_LED_BCR_CLK_EN |\n-\t\t\t\tMTK_PHY_LED_BCR_EXT_CTRL);\n-}\n-\n static struct phy_driver mtk_socphy_driver[] = {\n \t{\n \t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981),\n@@ -1527,43 +1058,6 @@ static struct phy_driver mtk_socphy_driver[] = {\n \t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n \t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n \t},\n-\t{\n-\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_EN7528),\n-\t\t.name\t\t= \"EcoNet EN7528 PHY\",\n-\t\t.config_init\t= en7528_phy_config_init,\n-\t\t.probe\t\t= an7581_phy_probe,\n-\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n-\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n-\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n-\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n-\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n-\t},\n-\t{\n-\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7581),\n-\t\t.name\t\t= \"Airoha AN7581 PHY\",\n-\t\t.config_intr\t= genphy_no_config_intr,\n-\t\t.handle_interrupt = genphy_handle_interrupt_no_ack,\n-\t\t.probe\t\t= an7581_phy_probe,\n-\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n-\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n-\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n-\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n-\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n-\t},\n-\t{\n-\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7583),\n-\t\t.name\t\t= \"Airoha AN7583 PHY\",\n-\t\t.config_init\t= an7583_phy_config_init,\n-\t\t.probe\t\t= an7581_phy_probe,\n-\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\n-\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\n-\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\n-\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\n-\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\n-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n-\t},\n };\n \n module_phy_driver(mtk_socphy_driver);\n@@ -1571,9 +1065,6 @@ module_phy_driver(mtk_socphy_driver);\n static const struct mdio_device_id __maybe_unused mtk_socphy_tbl[] = {\n \t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981) },\n \t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7988) },\n-\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_EN7528) },\n-\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7581) },\n-\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7583) },\n \t{ }\n };\n \ndiff --git a/drivers/net/phy/mediatek/mtk-ge-soc.h b/drivers/net/phy/mediatek/mtk-ge-soc.h\nnew file mode 100644\nindex 00000000000000..d6baff245deaea\n--- /dev/null\n+++ b/drivers/net/phy/mediatek/mtk-ge-soc.h\n@@ -0,0 +1,377 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+\n+#ifndef _MTK_GE_SOC_H_\n+#define _MTK_GE_SOC_H_\n+\n+#include \u003clinux/bitfield.h\u003e\n+\n+#define MTK_GPHY_ID_MT7981\t\t\t0x03a29461\n+#define MTK_GPHY_ID_MT7988\t\t\t0x03a29481\n+#define AIROHA_GPHY_ID_EN7528\t\t\t0x03a29491\n+#define AIROHA_GPHY_ID_AN7581\t\t\t0x03a294c1\n+#define AIROHA_GPHY_ID_AN7583\t\t\t0xc0ff0420\n+\n+#define MTK_EXT_PAGE_ACCESS\t\t\t0x1f\n+#define MTK_PHY_PAGE_STANDARD\t\t\t0x0000\n+#define MTK_PHY_PAGE_EXTENDED_1\t\t\t0x0001\n+#define MTK_PHY_PAGE_EXTENDED_3\t\t\t0x0003\n+\n+#define MTK_PHY_LPI_REG_14\t\t\t0x14\n+#define MTK_PHY_LPI_WAKE_TIMER_1000_MASK\tGENMASK(8, 0)\n+\n+#define MTK_PHY_LPI_REG_1c\t\t\t0x1c\n+#define MTK_PHY_SMI_DET_ON_THRESH_MASK\t\tGENMASK(13, 8)\n+\n+#define MTK_PHY_PAGE_EXTENDED_2A30\t\t0x2a30\n+\n+/* Registers on Token Ring debug nodes */\n+/* ch_addr = 0x0, node_addr = 0x7, data_addr = 0x15 */\n+/* NormMseLoThresh */\n+#define NORMAL_MSE_LO_THRESH_MASK\t\tGENMASK(15, 8)\n+\n+/* ch_addr = 0x0, node_addr = 0xf, data_addr = 0x3c */\n+/* RemAckCntLimitCtrl */\n+#define REMOTE_ACK_COUNT_LIMIT_CTRL_MASK\tGENMASK(2, 1)\n+\n+/* ch_addr = 0x1, node_addr = 0xd, data_addr = 0x20 */\n+/* VcoSlicerThreshBitsHigh */\n+#define VCO_SLICER_THRESH_HIGH_MASK\t\tGENMASK(23, 0)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x0 */\n+/* DfeTailEnableVgaThresh1000 */\n+#define DFE_TAIL_EANBLE_VGA_TRHESH_1000\t\tGENMASK(5, 1)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x1 */\n+/* MrvlTrFix100Kp */\n+#define MRVL_TR_FIX_100KP_MASK\t\t\tGENMASK(22, 20)\n+/* MrvlTrFix100Kf */\n+#define MRVL_TR_FIX_100KF_MASK\t\t\tGENMASK(19, 17)\n+/* MrvlTrFix1000Kp */\n+#define MRVL_TR_FIX_1000KP_MASK\t\t\tGENMASK(16, 14)\n+/* MrvlTrFix1000Kf */\n+#define MRVL_TR_FIX_1000KF_MASK\t\t\tGENMASK(13, 11)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x12 */\n+/* VgaDecRate */\n+#define VGA_DECIMATION_RATE_MASK\t\tGENMASK(8, 5)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x17 */\n+/* SlvDSPreadyTime */\n+#define SLAVE_DSP_READY_TIME_MASK\t\tGENMASK(22, 15)\n+/* MasDSPreadyTime */\n+#define MASTER_DSP_READY_TIME_MASK\t\tGENMASK(14, 7)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x18 */\n+/* EnabRandUpdTrig */\n+#define ENABLE_RANDOM_UPDOWN_COUNTER_TRIGGER\tBIT(8)\n+\n+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x20 */\n+/* ResetSyncOffset */\n+#define RESET_SYNC_OFFSET_MASK\t\t\tGENMASK(11, 8)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x0 */\n+/* FfeUpdGainForceVal */\n+#define FFE_UPDATE_GAIN_FORCE_VAL_MASK\t\tGENMASK(9, 7)\n+/* FfeUpdGainForce */\n+#define FFE_UPDATE_GAIN_FORCE\t\t\tBIT(6)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x3 */\n+/* TrFreeze */\n+#define TR_FREEZE_MASK\t\t\t\tGENMASK(11, 0)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x6 */\n+/* SS: Steady-state, KP: Proportional Gain */\n+/* SSTrKp100 */\n+#define SS_TR_KP100_MASK\t\t\tGENMASK(21, 19)\n+/* SSTrKf100 */\n+#define SS_TR_KF100_MASK\t\t\tGENMASK(18, 16)\n+/* SSTrKp1000Mas */\n+#define SS_TR_KP1000_MASTER_MASK\t\tGENMASK(15, 13)\n+/* SSTrKf1000Mas */\n+#define SS_TR_KF1000_MASTER_MASK\t\tGENMASK(12, 10)\n+/* SSTrKp1000Slv */\n+#define SS_TR_KP1000_SLAVE_MASK\t\t\tGENMASK(9, 7)\n+/* SSTrKf1000Slv */\n+#define SS_TR_KF1000_SLAVE_MASK\t\t\tGENMASK(6, 4)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x8 */\n+/* clear this bit if wanna select from AFE */\n+/* Regsigdet_sel_1000 */\n+#define EEE1000_SELECT_SIGNAL_DETECTION_FROM_DFE\tBIT(4)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xd */\n+/* RegEEE_st2TrKf1000 */\n+#define EEE1000_STAGE2_TR_KF_MASK\t\tGENMASK(13, 11)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xf */\n+/* RegEEE_slv_waketr_timer_tar */\n+#define SLAVE_WAKETR_TIMER_MASK\t\t\tGENMASK(20, 11)\n+/* RegEEE_slv_remtx_timer_tar */\n+#define SLAVE_REMTX_TIMER_MASK\t\t\tGENMASK(10, 1)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x10 */\n+/* RegEEE_slv_wake_int_timer_tar */\n+#define SLAVE_WAKEINT_TIMER_MASK\t\tGENMASK(10, 1)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x14 */\n+/* RegEEE_trfreeze_timer2 */\n+#define TR_FREEZE_TIMER2_MASK\t\t\tGENMASK(9, 0)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x1c */\n+/* RegEEE100Stg1_tar */\n+#define EEE100_LPSYNC_STAGE1_UPDATE_TIMER_MASK\tGENMASK(8, 0)\n+\n+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x25 */\n+/* REGEEE_wake_slv_tr_wait_dfesigdet_en */\n+#define WAKE_SLAVE_TR_WAIT_DFE_DETECTION_EN\tBIT(11)\n+\n+#define ANALOG_INTERNAL_OPERATION_MAX_US\t20\n+#define TXRESERVE_MIN\t\t\t\t0\n+#define TXRESERVE_MAX\t\t\t\t7\n+\n+#define MTK_PHY_ANARG_RG\t\t\t0x10\n+#define   MTK_PHY_TCLKOFFSET_MASK\t\tGENMASK(12, 8)\n+\n+/* Registers on MDIO_MMD_VEND1 */\n+#define MTK_PHY_TXVLD_DA_RG\t\t\t0x12\n+#define   MTK_PHY_DA_TX_I2MPB_A_GBE_MASK\tGENMASK(15, 10)\n+#define   MTK_PHY_DA_TX_I2MPB_A_TBT_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_A2\t\t0x16\n+#define   MTK_PHY_DA_TX_I2MPB_A_HBT_MASK\tGENMASK(15, 10)\n+#define   MTK_PHY_DA_TX_I2MPB_A_TST_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_B1\t\t0x17\n+#define   MTK_PHY_DA_TX_I2MPB_B_GBE_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_B_TBT_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_B2\t\t0x18\n+#define   MTK_PHY_DA_TX_I2MPB_B_HBT_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_B_TST_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_C1\t\t0x19\n+#define   MTK_PHY_DA_TX_I2MPB_C_GBE_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_C_TBT_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_C2\t\t0x20\n+#define   MTK_PHY_DA_TX_I2MPB_C_HBT_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_C_TST_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_D1\t\t0x21\n+#define   MTK_PHY_DA_TX_I2MPB_D_GBE_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_D_TBT_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_TX_I2MPB_TEST_MODE_D2\t\t0x22\n+#define   MTK_PHY_DA_TX_I2MPB_D_HBT_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_DA_TX_I2MPB_D_TST_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_RXADC_CTRL_RG7\t\t\t0xc6\n+#define   MTK_PHY_DA_AD_BUF_BIAS_LP_MASK\tGENMASK(9, 8)\n+\n+#define MTK_PHY_RXADC_CTRL_RG9\t\t\t0xc8\n+#define   MTK_PHY_DA_RX_PSBN_TBT_MASK\t\tGENMASK(14, 12)\n+#define   MTK_PHY_DA_RX_PSBN_HBT_MASK\t\tGENMASK(10, 8)\n+#define   MTK_PHY_DA_RX_PSBN_GBE_MASK\t\tGENMASK(6, 4)\n+#define   MTK_PHY_DA_RX_PSBN_LP_MASK\t\tGENMASK(2, 0)\n+\n+#define MTK_PHY_LDO_OUTPUT_V\t\t\t0xd7\n+\n+#define MTK_PHY_RG_ANA_CAL_RG0\t\t\t0xdb\n+#define   MTK_PHY_RG_CAL_CKINV\t\t\tBIT(12)\n+#define   MTK_PHY_RG_ANA_CALEN\t\t\tBIT(8)\n+#define   MTK_PHY_RG_REXT_CALEN\t\t\tBIT(4)\n+#define   MTK_PHY_RG_ZCALEN_A\t\t\tBIT(0)\n+\n+#define MTK_PHY_RG_ANA_CAL_RG1\t\t\t0xdc\n+#define   MTK_PHY_RG_ZCALEN_B\t\t\tBIT(12)\n+#define   MTK_PHY_RG_ZCALEN_C\t\t\tBIT(8)\n+#define   MTK_PHY_RG_ZCALEN_D\t\t\tBIT(4)\n+#define   MTK_PHY_RG_TXVOS_CALEN\t\tBIT(0)\n+\n+#define MTK_PHY_RG_ANA_CAL_RG5\t\t\t0xe0\n+#define   MTK_PHY_RG_REXT_TRIM_MASK\t\tGENMASK(13, 8)\n+#define   MTK_PHY_RG_REXT_ZCAL_CTRL_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_RG_ANA_CAL_RG6\t\t\t0xe1\n+\n+#define MTK_PHY_RG_TX_FILTER\t\t\t0xfe\n+\n+#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG120\t0x120\n+#define   MTK_PHY_LPI_SIG_EN_LO_THRESH1000_MASK\tGENMASK(12, 8)\n+#define   MTK_PHY_LPI_SIG_EN_HI_THRESH1000_MASK\tGENMASK(4, 0)\n+\n+#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG122\t0x122\n+#define   MTK_PHY_LPI_NORM_MSE_HI_THRESH1000_MASK\tGENMASK(7, 0)\n+\n+#define MTK_PHY_RG_TESTMUX_ADC_CTRL\t\t0x144\n+#define   MTK_PHY_RG_TXEN_DIG_MASK\t\tGENMASK(5, 5)\n+\n+#define MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B\t\t0x172\n+#define   MTK_PHY_CR_TX_AMP_OFFSET_A_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_CR_TX_AMP_OFFSET_B_MASK\tGENMASK(6, 0)\n+#define   AIROHA_PHY_CR_TX_AMP_OFFSET_B_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D\t\t0x173\n+#define   MTK_PHY_CR_TX_AMP_OFFSET_C_MASK\tGENMASK(13, 8)\n+#define   MTK_PHY_CR_TX_AMP_OFFSET_D_MASK\tGENMASK(6, 0)\n+#define   AIROHA_PHY_CR_TX_AMP_OFFSET_D_MASK\tGENMASK(5, 0)\n+\n+#define MTK_PHY_RG_CR_TX_R50_OFFSET_A_B\t\t0x174\n+#define   MTK_PHY_CR_TX_R50_OFFSET_A_MASK\tGENMASK(13, 8)\n+#define   AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK\tGENMASK(14, 8)\n+#define   MTK_PHY_CR_TX_R50_OFFSET_B_MASK\tGENMASK(6, 0)\n+\n+#define MTK_PHY_RG_CR_TX_R50_OFFSET_C_D\t\t0x175\n+#define   MTK_PHY_CR_TX_R50_OFFSET_C_MASK\tGENMASK(13, 8)\n+#define   AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK\tGENMASK(14, 8)\n+#define   MTK_PHY_CR_TX_R50_OFFSET_D_MASK\tGENMASK(6, 0)\n+\n+#define MTK_PHY_RG_AD_CAL_COMP\t\t\t0x17a\n+#define   MTK_PHY_AD_CAL_COMP_OUT_MASK\t\tGENMASK(8, 8)\n+\n+#define MTK_PHY_RG_AD_CAL_CLK\t\t\t0x17b\n+#define   MTK_PHY_DA_CAL_CLK\t\t\tBIT(0)\n+\n+#define MTK_PHY_RG_AD_CALIN\t\t\t0x17c\n+#define   MTK_PHY_DA_CALIN_FLAG\t\t\tBIT(0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN0_A\t\t0x17d\n+#define   MTK_PHY_DASN_DAC_IN0_A_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN0_B\t\t0x17e\n+#define   MTK_PHY_DASN_DAC_IN0_B_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN0_C\t\t0x17f\n+#define   MTK_PHY_DASN_DAC_IN0_C_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN0_D\t\t0x180\n+#define   MTK_PHY_DASN_DAC_IN0_D_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN1_A\t\t0x181\n+#define   MTK_PHY_DASN_DAC_IN1_A_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN1_B\t\t0x182\n+#define   MTK_PHY_DASN_DAC_IN1_B_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN1_C\t\t0x183\n+#define   MTK_PHY_DASN_DAC_IN1_C_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DASN_DAC_IN1_D\t\t0x184\n+#define   MTK_PHY_DASN_DAC_IN1_D_MASK\t\tGENMASK(9, 0)\n+\n+#define MTK_PHY_RG_DEV1E_REG19b\t\t\t0x19b\n+#define   MTK_PHY_BYPASS_DSP_LPI_READY\t\tBIT(8)\n+\n+#define MTK_PHY_RG_LP_IIR2_K1_L\t\t\t0x22a\n+#define MTK_PHY_RG_LP_IIR2_K1_U\t\t\t0x22b\n+#define MTK_PHY_RG_LP_IIR2_K2_L\t\t\t0x22c\n+#define MTK_PHY_RG_LP_IIR2_K2_U\t\t\t0x22d\n+#define MTK_PHY_RG_LP_IIR2_K3_L\t\t\t0x22e\n+#define MTK_PHY_RG_LP_IIR2_K3_U\t\t\t0x22f\n+#define MTK_PHY_RG_LP_IIR2_K4_L\t\t\t0x230\n+#define MTK_PHY_RG_LP_IIR2_K4_U\t\t\t0x231\n+#define MTK_PHY_RG_LP_IIR2_K5_L\t\t\t0x232\n+#define MTK_PHY_RG_LP_IIR2_K5_U\t\t\t0x233\n+\n+#define MTK_PHY_RG_DEV1E_REG234\t\t\t0x234\n+#define   MTK_PHY_TR_OPEN_LOOP_EN_MASK\t\tGENMASK(0, 0)\n+#define   MTK_PHY_LPF_X_AVERAGE_MASK\t\tGENMASK(7, 4)\n+#define   MTK_PHY_TR_LP_IIR_EEE_EN\t\tBIT(12)\n+\n+#define MTK_PHY_RG_LPF_CNT_VAL\t\t\t0x235\n+\n+#define MTK_PHY_RG_DEV1E_REG238\t\t\t0x238\n+#define   MTK_PHY_LPI_SLV_SEND_TX_TIMER_MASK\tGENMASK(8, 0)\n+#define   MTK_PHY_LPI_SLV_SEND_TX_EN\t\tBIT(12)\n+\n+#define MTK_PHY_RG_DEV1E_REG239\t\t\t0x239\n+#define   MTK_PHY_LPI_SEND_LOC_TIMER_MASK\tGENMASK(8, 0)\n+#define   MTK_PHY_LPI_TXPCS_LOC_RCV\t\tBIT(12)\n+\n+#define MTK_PHY_RG_DEV1E_REG27C\t\t\t0x27c\n+#define   MTK_PHY_VGASTATE_FFE_THR_ST1_MASK\tGENMASK(12, 8)\n+#define MTK_PHY_RG_DEV1E_REG27D\t\t\t0x27d\n+#define   MTK_PHY_VGASTATE_FFE_THR_ST2_MASK\tGENMASK(4, 0)\n+\n+#define MTK_PHY_RG_DEV1E_REG2C7\t\t\t0x2c7\n+#define   MTK_PHY_MAX_GAIN_MASK\t\t\tGENMASK(4, 0)\n+#define   MTK_PHY_MIN_GAIN_MASK\t\t\tGENMASK(12, 8)\n+\n+#define MTK_PHY_RG_DEV1E_REG2D1\t\t\t0x2d1\n+#define   MTK_PHY_VCO_SLICER_THRESH_BITS_HIGH_EEE_MASK\tGENMASK(7, 0)\n+#define   MTK_PHY_LPI_SKIP_SD_SLV_TR\t\tBIT(8)\n+#define   MTK_PHY_LPI_TR_READY\t\t\tBIT(9)\n+#define   MTK_PHY_LPI_VCO_EEE_STG0_EN\t\tBIT(10)\n+\n+#define MTK_PHY_RG_DEV1E_REG323\t\t\t0x323\n+#define   MTK_PHY_EEE_WAKE_MAS_INT_DC\t\tBIT(0)\n+#define   MTK_PHY_EEE_WAKE_SLV_INT_DC\t\tBIT(4)\n+\n+#define MTK_PHY_RG_DEV1E_REG324\t\t\t0x324\n+#define   MTK_PHY_SMI_DETCNT_MAX_MASK\t\tGENMASK(5, 0)\n+#define   MTK_PHY_SMI_DET_MAX_EN\t\tBIT(8)\n+\n+#define MTK_PHY_RG_DEV1E_REG326\t\t\t0x326\n+#define   MTK_PHY_LPI_MODE_SD_ON\t\tBIT(0)\n+#define   MTK_PHY_RESET_RANDUPD_CNT\t\tBIT(1)\n+#define   MTK_PHY_TREC_UPDATE_ENAB_CLR\t\tBIT(2)\n+#define   MTK_PHY_LPI_QUIT_WAIT_DFE_SIG_DET_OFF\tBIT(4)\n+#define   MTK_PHY_TR_READY_SKIP_AFE_WAKEUP\tBIT(5)\n+\n+#define MTK_PHY_LDO_PUMP_EN_PAIRAB\t\t0x502\n+#define MTK_PHY_LDO_PUMP_EN_PAIRCD\t\t0x503\n+\n+#define MTK_PHY_DA_TX_R50_PAIR_A\t\t0x53d\n+#define MTK_PHY_DA_TX_R50_PAIR_B\t\t0x53e\n+#define MTK_PHY_DA_TX_R50_PAIR_C\t\t0x53f\n+#define MTK_PHY_DA_TX_R50_PAIR_D\t\t0x540\n+\n+/* Registers on MDIO_MMD_VEND2 */\n+#define MTK_PHY_LED1_DEFAULT_POLARITIES\t\tBIT(1)\n+\n+/* LED basic control register, part of the same LED block as the LED0/LED1\n+ * control registers above. The air_en8811h driver describes the same\n+ * register as AIR_PHY_LED_BCR.\n+ */\n+#define MTK_PHY_LED_BCR\t\t\t\t0x21\n+#define   MTK_PHY_LED_BCR_CLK_EN\t\tBIT(3)\n+#define   MTK_PHY_LED_BCR_EXT_CTRL\t\tBIT(15)\n+\n+#define MTK_PHY_RG_BG_RASEL\t\t\t0x115\n+#define   MTK_PHY_RG_BG_RASEL_MASK\t\tGENMASK(2, 0)\n+\n+/* 'boottrap' register reflecting the configuration of the 4 PHY LEDs */\n+#define RG_GPIO_MISC_TPBANK0\t\t\t0x6f0\n+#define   RG_GPIO_MISC_TPBANK0_BOOTMODE\t\tGENMASK(11, 8)\n+\n+enum CAL_ITEM {\n+\tREXT,\n+\tTX_OFFSET,\n+\tTX_AMP,\n+\tTX_R50,\n+\tTX_VCM,\n+\tRX_OFFSET,\n+};\n+\n+enum {\n+\tNO_PAIR,\n+\tPAIR_A,\n+\tPAIR_B,\n+\tPAIR_C,\n+\tPAIR_D,\n+};\n+\n+enum calibration_mode {\n+\tEFUSE_K,\n+\tSW_K\n+};\n+\n+enum CAL_MODE {\n+\tEFUSE_M,\n+\tSW_M\n+};\n+\n+/* MTK GE SoC common functions */\n+int mtk_cal_cycle_wait(struct phy_device *phydev);\n+\n+#endif /* _MTK_GE_SOC_H_ */\ndiff --git a/drivers/net/phy/mediatek/mtk-phy-lib.c b/drivers/net/phy/mediatek/mtk-phy-lib.c\nindex 4c4eca870bde1c..dc4abd95d73fc7 100644\n--- a/drivers/net/phy/mediatek/mtk-phy-lib.c\n+++ b/drivers/net/phy/mediatek/mtk-phy-lib.c\n@@ -36,8 +36,8 @@ static void __mtk_tr_read(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n \t\t*tr_high, *tr_low);\n }\n \n-static void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n-\t\t\t   u8 data_addr, u32 tr_data)\n+void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n+\t\t    u8 data_addr, u32 tr_data)\n {\n \t__phy_write(phydev, 0x11, tr_data \u0026 0xffff);\n \t__phy_write(phydev, 0x12, tr_data \u003e\u003e 16);\n@@ -45,6 +45,7 @@ static void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n \t\ttr_data \u003e\u003e 16, tr_data \u0026 0xffff);\n \t__mtk_tr_access(phydev, false, ch_addr, node_addr, data_addr);\n }\n+EXPORT_SYMBOL_GPL(__mtk_tr_write);\n \n void __mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n \t\t     u8 data_addr, u32 mask, u32 set)\n@@ -338,6 +339,78 @@ void mtk_phy_leds_state_init(struct phy_device *phydev)\n }\n EXPORT_SYMBOL_GPL(mtk_phy_leds_state_init);\n \n+int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,\n+\t\t\t     unsigned long *delay_on,\n+\t\t\t     unsigned long *delay_off)\n+{\n+\tbool blinking = false;\n+\tint err;\n+\n+\terr = mtk_phy_led_num_dly_cfg(index, delay_on, delay_off, \u0026blinking);\n+\tif (err \u003c 0)\n+\t\treturn err;\n+\n+\terr = mtk_phy_hw_led_blink_set(phydev, index, blinking);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,\n+\t\t\t\t     false);\n+}\n+EXPORT_SYMBOL_GPL(mt798x_phy_led_blink_set);\n+\n+int mt798x_phy_led_brightness_set(struct phy_device *phydev,\n+\t\t\t\t  u8 index, enum led_brightness value)\n+{\n+\tint err;\n+\n+\terr = mtk_phy_hw_led_blink_set(phydev, index, false);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,\n+\t\t\t\t     (value != LED_OFF));\n+}\n+EXPORT_SYMBOL_GPL(mt798x_phy_led_brightness_set);\n+\n+static const unsigned long supported_triggers =\n+\tBIT(TRIGGER_NETDEV_FULL_DUPLEX) |\n+\tBIT(TRIGGER_NETDEV_HALF_DUPLEX) |\n+\tBIT(TRIGGER_NETDEV_LINK)        |\n+\tBIT(TRIGGER_NETDEV_LINK_10)     |\n+\tBIT(TRIGGER_NETDEV_LINK_100)    |\n+\tBIT(TRIGGER_NETDEV_LINK_1000)   |\n+\tBIT(TRIGGER_NETDEV_RX)          |\n+\tBIT(TRIGGER_NETDEV_TX);\n+\n+int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,\n+\t\t\t\t   unsigned long rules)\n+{\n+\treturn mtk_phy_led_hw_is_supported(phydev, index, rules,\n+\t\t\t\t\t   supported_triggers);\n+}\n+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_is_supported);\n+\n+int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,\n+\t\t\t\t  unsigned long *rules)\n+{\n+\treturn mtk_phy_led_hw_ctrl_get(phydev, index, rules,\n+\t\t\t\t       MTK_GPHY_LED_ON_SET,\n+\t\t\t\t       MTK_GPHY_LED_RX_BLINK_SET,\n+\t\t\t\t       MTK_GPHY_LED_TX_BLINK_SET);\n+};\n+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_get);\n+\n+int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,\n+\t\t\t\t  unsigned long rules)\n+{\n+\treturn mtk_phy_led_hw_ctrl_set(phydev, index, rules,\n+\t\t\t\t       MTK_GPHY_LED_ON_SET,\n+\t\t\t\t       MTK_GPHY_LED_RX_BLINK_SET,\n+\t\t\t\t       MTK_GPHY_LED_TX_BLINK_SET);\n+};\n+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_set);\n+\n MODULE_DESCRIPTION(\"MediaTek Ethernet PHY driver common\");\n MODULE_AUTHOR(\"Sky Huang \u003cSkyLake.Huang@mediatek.com\u003e\");\n MODULE_AUTHOR(\"Daniel Golle \u003cdaniel@makrotopia.org\u003e\");\ndiff --git a/drivers/net/phy/mediatek/mtk.h b/drivers/net/phy/mediatek/mtk.h\nindex 79e09727b81bcc..608e5e3d754f9a 100644\n--- a/drivers/net/phy/mediatek/mtk.h\n+++ b/drivers/net/phy/mediatek/mtk.h\n@@ -13,6 +13,7 @@\n \n #define MTK_EXT_PAGE_ACCESS\t\t\t0x1f\n #define MTK_PHY_PAGE_EXTENDED_1\t\t\t0x0001\n+#define MTK_PHY_PAGE_EXTENDED_3\t\t\t0x0003\n #define MTK_PHY_PAGE_STANDARD\t\t\t0x0000\n #define MTK_PHY_PAGE_EXTENDED_52B5\t\t0x52b5\n \n@@ -72,6 +73,8 @@ struct mtk_socphy_priv {\n \tunsigned long\t\tled_state;\n };\n \n+void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n+\t\t    u8 data_addr, u32 tr_data);\n void __mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n \t\t     u8 data_addr, u32 mask, u32 set);\n void mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n@@ -101,4 +104,16 @@ int mtk_phy_hw_led_blink_set(struct phy_device *phydev, u8 index,\n \t\t\t     bool blinking);\n void mtk_phy_leds_state_init(struct phy_device *phydev);\n \n+int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,\n+\t\t\t     unsigned long *delay_on,\n+\t\t\t     unsigned long *delay_off);\n+int mt798x_phy_led_brightness_set(struct phy_device *phydev,\n+\t\t\t\t  u8 index, enum led_brightness value);\n+int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,\n+\t\t\t\t   unsigned long rules);\n+int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,\n+\t\t\t\t  unsigned long *rules);\n+int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,\n+\t\t\t\t  unsigned long rules);\n+\n #endif /* _MTK_EPHY_H_ */\n"
}

2/1 2026/11/06 03:04 agent patch-evaluator
4m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series introduces a dedicated driver for Airoha SoC built-in Gigabit Ethernet PHYs (AN7581, AN7583, EN7528) and refactors common helpers across MediaTek and Airoha SoC PHY drivers. All modified code is strictly confined to drivers/net/phy/mediatek/ and targets internal PHYs integrated into Airoha (ARCH_AIROHA/ECONET, ARM64/MIPS) and MediaTek (ARCH_MEDIATEK) SoCs. On the target architecture (amd64), this SoC-specific hardware is physically absent and not emulated in standard QEMU/GCE environments, making the modified code structurally unreachable.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 9e4411c9d6f56e70300a19017e2544f363a38152
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Nov 6 03:04:19 2026 +0000

    syz-cluster: applied patch under review

diff --git a/MAINTAINERS b/MAINTAINERS
index 09713dc4c6a77d..8a3e84d7eff3e3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -771,6 +771,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/airoha,en7581-eth.yaml
 F:	drivers/net/ethernet/airoha/
 
+AIROHA ETHERNET PHY DRIVER
+M:	Christian Marangi <ansuelsmth@gmail.com>
+L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
+L:	linux-mediatek@lists.infradead.org (moderated for non-subscribers)
+L:	netdev@vger.kernel.org
+S:	Maintained
+F:	drivers/net/phy/mediatek/airoha-ge-soc.c
+
 AIROHA PCIE PHY DRIVER
 M:	Lorenzo Bianconi <lorenzo@kernel.org>
 L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -16990,6 +16998,7 @@ L:	netdev@vger.kernel.org
 S:	Maintained
 F:	drivers/net/phy/mediatek/mtk-2p5ge.c
 F:	drivers/net/phy/mediatek/mtk-ge-soc.c
+F:	drivers/net/phy/mediatek/mtk-ge-soc.h
 F:	drivers/net/phy/mediatek/mtk-phy-lib.c
 F:	drivers/net/phy/mediatek/mtk-ge.c
 F:	drivers/net/phy/mediatek/mtk.h
diff --git a/drivers/net/phy/mediatek/Kconfig b/drivers/net/phy/mediatek/Kconfig
index 3b9cf82c0cb288..5abf782029917d 100644
--- a/drivers/net/phy/mediatek/Kconfig
+++ b/drivers/net/phy/mediatek/Kconfig
@@ -1,4 +1,17 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config AIROHA_GE_SOC_PHY
+	tristate "Airoha SoC Gigabit Ethernet PHYs"
+	depends on ARM64 || ECONET || COMPILE_TEST
+	depends on ARCH_AIROHA || ECONET || COMPILE_TEST
+	select MTK_NET_PHYLIB
+	select PHY_PACKAGE
+	help
+	  Supports Airoha SoC built-in Gigabit Ethernet PHYs.
+
+	  Include support for built-in Ethernet PHYs which are present in
+	  the AN7581 and AN7583 SoCs. These PHYs will dynamically
+	  calibrate during startup.
+
 config MEDIATEK_2P5GE_PHY
 	tristate "MediaTek 2.5Gb Ethernet PHYs"
 	depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST
@@ -32,9 +45,8 @@ config MEDIATEK_FE_SOC_PHY
 
 config MEDIATEK_GE_SOC_PHY
 	tristate "MediaTek SoC Gigabit Ethernet PHYs"
-	depends on ARM64 || ECONET || COMPILE_TEST
-	depends on ARCH_AIROHA || (ARCH_MEDIATEK && NVMEM_MTK_EFUSE) || \
-		   ECONET || COMPILE_TEST
+	depends on ARM64 || COMPILE_TEST
+	depends on (ARCH_MEDIATEK && NVMEM_MTK_EFUSE) || COMPILE_TEST
 	select MTK_NET_PHYLIB
 	select PHY_PACKAGE
 	help
diff --git a/drivers/net/phy/mediatek/Makefile b/drivers/net/phy/mediatek/Makefile
index 6f9cacf7f90657..5594057f51d0f4 100644
--- a/drivers/net/phy/mediatek/Makefile
+++ b/drivers/net/phy/mediatek/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_AIROHA_GE_SOC_PHY)		+= airoha-ge-soc.o
 obj-$(CONFIG_MEDIATEK_2P5GE_PHY)	+= mtk-2p5ge.o
 obj-$(CONFIG_MEDIATEK_FE_SOC_PHY)	+= mtk-fe-soc.o
 obj-$(CONFIG_MEDIATEK_GE_PHY)		+= mtk-ge.o
diff --git a/drivers/net/phy/mediatek/airoha-ge-soc.c b/drivers/net/phy/mediatek/airoha-ge-soc.c
new file mode 100644
index 00000000000000..72c2b9fe7ba4a8
--- /dev/null
+++ b/drivers/net/phy/mediatek/airoha-ge-soc.c
@@ -0,0 +1,1882 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <linux/bitfield.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/phy.h>
+
+#include "../phylib.h"
+#include "mtk.h"
+#include "mtk-ge-soc.h"
+
+#define AIROHA_DEFAULT_PORT0_ADDR		0x9
+#define AIROHA_PHY_MAX_LEDS			2
+
+enum airoha_mdi_resister_type {
+	MDI_0R,
+	MDI_5R,
+
+	MDI_TYPE_MAX,
+};
+
+enum airoha_transformer_type {
+	DISCRETE,
+	TXMR,
+
+	TRANSFORMER_TYPE_MAX,
+};
+
+enum airoha_calib_const_type {
+	TX_AMP_TEST_A,
+	TX_AMP_TEST_B,
+	TX_AMP_TEST_C,
+	TX_AMP_TEST_D,
+	TX_AMP_1G_A,
+	TX_AMP_1G_B,
+	TX_AMP_1G_C,
+	TX_AMP_1G_D,
+	TX_AMP_100M_A,
+	TX_AMP_100M_B,
+	TX_AMP_10M_A,
+	TX_AMP_10M_B,
+	R50_A,
+	R50_B,
+	R50_C,
+	R50_D,
+
+	CALIB_CONST_TYPE_MAX,
+};
+
+struct airoha_socphy_shared {
+	struct phy_device *phydev_p0;
+	enum airoha_transformer_type transformer_type[4];
+	enum airoha_mdi_resister_type mdi_resister_type;
+	bool rext_sw_calib_done;
+	int (*tx_amp_compensation_tbl)[TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4];
+	u8 *r50_cal_tbl;
+	u32 soc_pdidr;
+};
+
+/*
+ * 2 chip revision
+ * TXMR or discrete
+ * 2 MDI type
+ * TX AMP test/TX AMP 1G/TX AMP 100M/TX AMP 10M/R50
+ * 4 PHY
+ */
+static int an7581_tx_amp_compensation_tbl[2][TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4] = {
+	{ /* IC version 1 */
+		[DISCRETE] = {
+			{ },
+			{
+				[TX_AMP_TEST_A] = { -9, -7, -7, -5 },
+				[TX_AMP_TEST_B] = { -9, -9, -7, -4 },
+				[TX_AMP_TEST_C] = { -9, -7, -9, -6 },
+				[TX_AMP_TEST_D] = { -11, -9, -10, -8 },
+				[TX_AMP_1G_A] = { -9, -7, -7, -5 },
+				[TX_AMP_1G_B] = { -9, -8, -7, -4 },
+				[TX_AMP_1G_C] = { -9, -7, -9, -6 },
+				[TX_AMP_1G_D] = { -11, -8, -10, -8 },
+				[TX_AMP_100M_A] = { 4, 3, 4, 4 },
+				[TX_AMP_100M_B] = { 4, 4, 5, 4 },
+				[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+				[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+				[R50_A] = { 0, 0, 0, 0 },
+				[R50_B] = { 0, 0, 0, 0 },
+				[R50_C] = { 0, 0, 0, 0 },
+				[R50_D] = { 0, 0, 0, 0 },
+			},
+		},
+		[TXMR] = {
+			{ },
+			{
+				[TX_AMP_TEST_A] = { -12, -11, -9, -6 },
+				[TX_AMP_TEST_B] = { -9, -13, -9, -5 },
+				[TX_AMP_TEST_C] = { -5, -4, -3, 1 },
+				[TX_AMP_TEST_D] = { -9, -8, -7, -5 },
+				[TX_AMP_1G_A] = { -12, -11, -9, -6 },
+				[TX_AMP_1G_B] = { -9, -13, -9, -5 },
+				[TX_AMP_1G_C] = { -5, -4, -3, 1 },
+				[TX_AMP_1G_D] = { -9, -8, -7, -5 },
+				[TX_AMP_100M_A] = { -2, -2, 0, 2 },
+				[TX_AMP_100M_B] = { -2, -2, 1, 1 },
+				[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+				[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+				[R50_A] = { 15, 15, 15, 15 },
+				[R50_B] = { 15, 15, 18, 15 },
+				[R50_C] = { -8, -8, -8, -8 },
+				[R50_D] = { -8, -8, -8, -8 },
+			},
+		},
+	},
+	{ /* IC version 2 */
+		[DISCRETE] = {
+			{ },
+			{
+				[TX_AMP_TEST_A] = { -11, 11, -12, -7 },
+				[TX_AMP_TEST_B] = { -9, -10, -9, -8 },
+				[TX_AMP_TEST_C] = { -6, -3, -7, -4 },
+				[TX_AMP_TEST_D] = { -7, -8, -10, -7 },
+				[TX_AMP_1G_A] = { -11, -11, -12, -7 },
+				[TX_AMP_1G_B] = { -9, -10, -9, -8 },
+				[TX_AMP_1G_C] = { -6, -3, -7, -4 },
+				[TX_AMP_1G_D] = { -7, -8, -10, -7 },
+				[TX_AMP_100M_A] = { 2, 2, 1, 2 },
+				[TX_AMP_100M_B] = { 3, 3, 3, 3 },
+				[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+				[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+				[R50_A] = { 12, 12, 12, 12 },
+				[R50_B] = { 7, 7, 7, 7 },
+				[R50_C] = { 2, 2, 0, 0 },
+				[R50_D] = { 0, 0, 2, 2 },
+			},
+		},
+		[TXMR] = {
+			{ },
+			{
+				[TX_AMP_TEST_A] = { -10, -12, -12, -11 },
+				[TX_AMP_TEST_B] = { -10, -11, -11, -10 },
+				[TX_AMP_TEST_C] = { -5, -7, -9, -3 },
+				[TX_AMP_TEST_D] = { -8, -10, -7, -8 },
+				[TX_AMP_1G_A] = { -12, -6, -6, 4 },
+				[TX_AMP_1G_B] = { -10, -5, -5, 1 },
+				[TX_AMP_1G_C] = { -5, -3, -4, 11 },
+				[TX_AMP_1G_D] = { -8, -3, -3, 4 },
+				[TX_AMP_100M_A] = { 2, 1, 0, 3 },
+				[TX_AMP_100M_B] = { 0, 0, 0, 3 },
+				[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+				[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+				[R50_A] = { 15, 15, 15, 15 },
+				[R50_B] = { 15, 15, 18, 15 },
+				[R50_C] = { 4, 4, 4, 4 },
+				[R50_D] = { 4, 4, 4, 4 },
+			},
+		},
+	},
+};
+
+static u8 an7581_zcal_to_r45ohm[64] = {
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+	127, 127, 127, 127, 127, 127, 127, 127, 123, 119, 115, 112, 108, 104, 100,  96,
+	 94,  92,  88,  85,  82,  80,  76,  74,  72,  68,  66,  64,  62,  60,  56,  55,
+	 52,  50,  48,  46,  44,  42,  40,  39,  36,  35,  32,  32,  30,  28,  27,  25
+};
+
+/*
+ * 2 chip revision
+ * TXMR or discrete
+ * 2 MDI type
+ * TX AMP test/TX AMP 1G/TX AMP 100M/TX AMP 10M/R50
+ * 4 PHY
+ */
+static int an7583_tx_amp_compensation_tbl[TRANSFORMER_TYPE_MAX][MDI_TYPE_MAX][CALIB_CONST_TYPE_MAX][4] = {
+	[DISCRETE] = {
+		[MDI_0R] = {
+			[TX_AMP_TEST_A] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_B] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_C] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_D] = { -3, -3, -3, -3 },
+			[TX_AMP_1G_A] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_B] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_C] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_D] = { 0, 0, 0, 0 },
+			[TX_AMP_100M_A] = { 4, 4, 4, 4 },
+			[TX_AMP_100M_B] = { 4, 4, 4, 4 },
+			[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+			[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+			[R50_A] = { 4, 4, 4, 4 },
+			[R50_B] = { 4, 4, 4, 4 },
+			[R50_C] = { 6, 6, 6, 6 },
+			[R50_D] = { 4, 4, 4, 4 },
+		},
+		[MDI_5R] = {
+			[TX_AMP_TEST_A] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_B] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_C] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_D] = { -3, -3, -3, -3 },
+			[TX_AMP_1G_A] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_B] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_C] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_D] = { 0, 0, 0, 0 },
+			[TX_AMP_100M_A] = { 4, 4, 4, 4 },
+			[TX_AMP_100M_B] = { 4, 4, 4, 4 },
+			[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+			[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+			[R50_A] = { 0, 0, 0, 0 },
+			[R50_B] = { 0, 0, 0, 0 },
+			[R50_C] = { 0, 0, 0, 0 },
+			[R50_D] = { 0, 0, 0, 0 },
+		},
+	},
+	[TXMR] = {
+		[MDI_0R] = {
+			[TX_AMP_TEST_A] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_B] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_C] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_D] = { -3, -3, -3, -3 },
+			[TX_AMP_1G_A] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_B] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_C] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_D] = { 0, 0, 0, 0 },
+			[TX_AMP_100M_A] = { 4, 4, 4, 4 },
+			[TX_AMP_100M_B] = { 4, 4, 4, 4 },
+			[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+			[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+			[R50_A] = { 4, 4, 0, 0 },
+			[R50_B] = { 4, 4, 0, 0 },
+			[R50_C] = { 5, 5, 3, 4 },
+			[R50_D] = { 4, 4, 4, 0 },
+		},
+		[MDI_5R] = {
+			[TX_AMP_TEST_A] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_B] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_C] = { -3, -3, -3, -3 },
+			[TX_AMP_TEST_D] = { -3, -3, -3, -3 },
+			[TX_AMP_1G_A] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_B] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_C] = { 0, 0, 0, 0 },
+			[TX_AMP_1G_D] = { 0, 0, 0, 0 },
+			[TX_AMP_100M_A] = { 4, 4, 4, 4 },
+			[TX_AMP_100M_B] = { 4, 4, 4, 4 },
+			[TX_AMP_10M_A] = { 0, 0, 0, 0 },
+			[TX_AMP_10M_B] = { 0, 0, 0, 0 },
+			[R50_A] = { -4, -4, -4, -4 },
+			[R50_B] = { -4, -4, -4, -4 },
+			[R50_C] = { -2, -2, -2, -2 },
+			[R50_D] = { -3, -3, -2, -2 },
+		},
+	},
+};
+
+static u8 an7583_zcal_to_r50ohm_0R[64] = {
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+	127, 127, 127, 122, 118, 114, 110, 106, 102,  98,  96,  92,  88,  85,  82,  80,
+	 76,  72,  70,  68,  64,  62,  60,  57,  55,  52,  50,  48,  46,  44,  41,  40,
+	 38,  36,  33,  32,  30,  28,  26,  24,  24,  22,  20,  18,  16,  16,  14,  12,
+};
+
+static u8 an7583_zcal_to_r50ohm_5R[64] = {
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 124, 120, 116, 112, 110, 106, 102,
+	 99,  96,  93,  90,  88,  84,  81,  79,  76,  73,  71,  68,  66,  64,  61,  59,
+	 56,  54,  52,  50,  48,  46,  44,  42,  40,  39,  37,  36,  33,  32,  31,  29,
+};
+
+static int airoha_cal_cycle(struct phy_device *phydev, int devad,
+			    u32 regnum, u16 mask, u16 cal_val)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+
+	phy_modify_mmd(phydev, devad, regnum, mask, cal_val);
+
+	ret = mtk_cal_cycle_wait(phydev_p0);
+	phydev_dbg(phydev, "cal_val: 0x%x, ret: %d\n", cal_val, ret);
+
+	return ret;
+}
+
+static int airoha_rext_cal_sw(struct phy_device *phydev)
+{
+	int calibration_polarity;
+	u8 zcal_ctrl = 32;
+	int first_calib;
+	int ret;
+
+	/* BG voltage output */
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0xc000);
+	/* tst_mode2 */
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0xff, 0x2);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN |
+		      MTK_PHY_RG_REXT_CALEN);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0);
+
+	phydev_dbg(phydev, "Start REXT SW cal.\n");
+	first_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
+				       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);
+
+	if (first_calib < 0) {
+		phydev_err(phydev, "REXT SW calibration failed.\n");
+		return -EINVAL;
+	}
+
+	/* If REXT calibration failed:
+	 * - increase dB until calibration succeed.
+	 * If REXT calibration succeeded:
+	 * - decrease dB until calibration fail to fine tune it.
+	 */
+	if (first_calib == 1)
+		calibration_polarity = -1;
+	else
+		calibration_polarity = 1;
+
+	while (zcal_ctrl > 0 &&
+	       zcal_ctrl < FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {
+		zcal_ctrl += calibration_polarity;
+
+		ret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
+				       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);
+		/* Exit if we either failed or succeeded compared to the
+		 * first calibration result. (aka we finished fine tuning or
+		 * we succeeded with calibration)
+		 */
+		if (ret != first_calib)
+			break;
+	}
+
+	if (ret < 0) {
+		phydev_err(phydev, "REXT SW calibration failed.\n");
+		return -EINVAL;
+	}
+
+	if (zcal_ctrl == 0 ||
+	    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {
+		zcal_ctrl = 32;
+		phydev_err(phydev, "REXT SW calibration saturation. Defaulting to %x.\n",
+			   zcal_ctrl);
+	}
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
+		       MTK_PHY_RG_REXT_TRIM_MASK,
+		       FIELD_PREP(MTK_PHY_RG_REXT_TRIM_MASK, zcal_ctrl));
+	phy_modify_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_RG_BG_RASEL,
+		       MTK_PHY_RG_BG_RASEL_MASK,
+		       FIELD_PREP(MTK_PHY_RG_BG_RASEL_MASK, zcal_ctrl >> 3));
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+
+	return 0;
+}
+
+static int airoha_tx_offset_cal_sw(struct phy_device *phydev, u8 txg_calen_x)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	u16 dev1e_145_tmp, bmcr_tmp;
+	int calibration_polarity;
+	u16 reg_dac1, reg_dac2;
+	int zcal_ctrl = 32;
+	int first_calib;
+	u16 reg, mask;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+
+	/* BG voltage output */
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_ANA_CALEN);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,
+		      MTK_PHY_RG_TXVOS_CALEN);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_ANA_CALEN);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,
+		      MTK_PHY_RG_TXVOS_CALEN);
+
+	/* Force 1G full duplex for calibration */
+	bmcr_tmp = phy_read(phydev, MII_BMCR);
+	phy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);
+
+	/* Force MDI */
+	dev1e_145_tmp = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x0145);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, 0x1010);
+
+	/* 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96,
+		      0x8000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e,
+		      0xf808);
+
+	switch (txg_calen_x) {
+	case PAIR_A:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_A;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_A;
+		reg = MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B;
+		mask = MTK_PHY_CR_TX_AMP_OFFSET_A_MASK;
+		break;
+	case PAIR_B:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(8));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_B;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_B;
+		reg = MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B;
+		mask = AIROHA_PHY_CR_TX_AMP_OFFSET_B_MASK;
+		break;
+	case PAIR_C:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(4));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_C;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_C;
+		reg = MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D;
+		mask = MTK_PHY_CR_TX_AMP_OFFSET_C_MASK;
+		break;
+	case PAIR_D:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(0));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_D;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_D;
+		reg = MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D;
+		mask = AIROHA_PHY_CR_TX_AMP_OFFSET_D_MASK;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac1,
+		      0x8000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac2,
+		      0x8000);
+
+	phydev_dbg(phydev, "Start TX Offset SW cal.\n");
+
+	first_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg, mask,
+				       zcal_ctrl << __ffs(mask));
+
+	/* If TX Offset calibration failed:
+	 * - increase dB until calibration succeed.
+	 * If TX Offset calibration succeeded:
+	 * - decrease dB until calibration fail to fine tune it.
+	 */
+	if (first_calib == 1)
+		calibration_polarity = -1;
+	else
+		calibration_polarity = 1;
+
+	while (zcal_ctrl > 0 && zcal_ctrl < 63) {
+		u32 val;
+
+		zcal_ctrl += calibration_polarity;
+		if (zcal_ctrl >= 0)
+			val = zcal_ctrl;
+		else
+			val = 63;
+
+		ret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg, mask,
+				       val << __ffs(mask));
+		/* Exit if we either failed or succeeded compared to the
+		 * first calibration result. (aka we finished fine tuning or
+		 * we succeeded with calibration)
+		 */
+		if (ret != first_calib)
+			break;
+	}
+
+	if (ret < 0) {
+		phydev_err(phydev, "TX Offset calibration failed.\n");
+		ret = -EINVAL;
+	}
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0x0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D, 0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96, 0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0);
+
+	/* Restore BMCR */
+	phy_write(phydev, MII_BMCR, bmcr_tmp);
+
+	/* Restore MDI */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, dev1e_145_tmp);
+
+	return ret < 0 ? ret : 0;
+}
+
+static int airoha_tx_amp_cal_sw(struct phy_device *phydev, u8 txg_calen_x)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	u16 mask_gbe, mask_tbt, mask_tst, mask_hbt;
+	u16 reg, reg_100, reg_dac1, reg_dac2;
+	struct phy_device *phydev_p0;
+	int calibration_polarity;
+	u8 zcal_ctrl = 32;
+	int first_calib;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+
+	/* BG voltage output */
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x145, 0x1010);
+
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1,
+		      MTK_PHY_RG_TXVOS_CALEN);
+
+	/* select 1V */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);
+
+	/* enable Tx VLD*/
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xf808);
+
+	/* Force 1G full duplex for calibration */
+	phy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,
+		      0x8000 | 0xf0);
+
+	switch (txg_calen_x) {
+	case PAIR_A:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_A;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_A;
+		reg = MTK_PHY_TXVLD_DA_RG;
+		mask_gbe = MTK_PHY_DA_TX_I2MPB_A_GBE_MASK;
+		mask_tbt = MTK_PHY_DA_TX_I2MPB_A_TBT_MASK;
+		reg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_A2;
+		mask_hbt = MTK_PHY_DA_TX_I2MPB_A_HBT_MASK;
+		mask_tst = MTK_PHY_DA_TX_I2MPB_A_TST_MASK;
+		break;
+	case PAIR_B:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(8));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_B;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_B;
+		reg = MTK_PHY_TX_I2MPB_TEST_MODE_B1;
+		mask_gbe = MTK_PHY_DA_TX_I2MPB_B_GBE_MASK;
+		mask_tbt = MTK_PHY_DA_TX_I2MPB_B_TBT_MASK;
+		reg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_B2;
+		mask_hbt = MTK_PHY_DA_TX_I2MPB_B_HBT_MASK;
+		mask_tst = MTK_PHY_DA_TX_I2MPB_B_TST_MASK;
+		break;
+	case PAIR_C:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(4));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_C;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_C;
+		reg = MTK_PHY_TX_I2MPB_TEST_MODE_C1;
+		mask_gbe = MTK_PHY_DA_TX_I2MPB_C_GBE_MASK;
+		mask_tbt = MTK_PHY_DA_TX_I2MPB_C_TBT_MASK;
+		reg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_C2;
+		mask_hbt = MTK_PHY_DA_TX_I2MPB_C_HBT_MASK;
+		mask_tst = MTK_PHY_DA_TX_I2MPB_C_TST_MASK;
+		break;
+	case PAIR_D:
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(0));
+		reg_dac1 = MTK_PHY_RG_DASN_DAC_IN0_D;
+		reg_dac2 = MTK_PHY_RG_DASN_DAC_IN1_D;
+		reg = MTK_PHY_TX_I2MPB_TEST_MODE_D1;
+		mask_gbe = MTK_PHY_DA_TX_I2MPB_D_GBE_MASK;
+		mask_tbt = MTK_PHY_DA_TX_I2MPB_D_TBT_MASK;
+		reg_100 = MTK_PHY_TX_I2MPB_TEST_MODE_D2;
+		mask_hbt = MTK_PHY_DA_TX_I2MPB_D_HBT_MASK;
+		mask_tst = MTK_PHY_DA_TX_I2MPB_D_TST_MASK;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac1,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, reg_dac2,
+		      0x8000 | 0xf0);
+
+	phydev_dbg(phydev, "Start TX Amp SW cal.\n");
+	first_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg,
+				       mask_gbe, zcal_ctrl << __ffs(mask_gbe));
+
+	/* If TX Amp calibration failed:
+	 * - increase dB until calibration succeed.
+	 * If TX Amp calibration succeeded:
+	 * - decrease dB until calibration fail to fine tune it.
+	 */
+	if (first_calib == 1)
+		calibration_polarity = -1;
+	else
+		calibration_polarity = 1;
+
+	while (zcal_ctrl > 0 &&
+	       zcal_ctrl < FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {
+		zcal_ctrl += calibration_polarity;
+
+		ret = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, reg,
+				       mask_gbe, zcal_ctrl << __ffs(mask_gbe));
+		/* Exit if we either failed or succeeded compared to the
+		 * first calibration result. (aka we finished fine tuning or
+		 * we succeeded with calibration)
+		 */
+		if (ret != first_calib)
+			break;
+	}
+
+	if (ret < 0) {
+		phydev_err(phydev, "TX AMP calibration failed.\n");
+		zcal_ctrl = 32;
+		phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg,
+			       mask_gbe | mask_tbt,
+			       (zcal_ctrl << __ffs(mask_gbe)) |
+			       (zcal_ctrl << __ffs(mask_tbt)));
+
+		return -EINVAL;
+	}
+
+	if (zcal_ctrl == 0 ||
+	    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK))
+		phydev_warn(phydev, "TX AMP SW calibration saturation.\n");
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg,
+		       mask_gbe | mask_tbt,
+		       (zcal_ctrl << __ffs(mask_gbe)) |
+		       (zcal_ctrl << __ffs(mask_tbt)));
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg_100,
+		       mask_hbt | mask_tst,
+		       (zcal_ctrl << __ffs(mask_hbt)) |
+		       (zcal_ctrl << __ffs(mask_tst)));
+
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, 0x145, 0x1000);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0);
+
+	/* Restore AN enable */
+	phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
+
+	return 0;
+}
+
+static int airoha_tx_r50_cal_sw(struct phy_device *phydev, u8 txg_calen_x)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	u16 dev1e_145_tmp, bmcr_tmp;
+	int calibration_polarity;
+	u8 zcal_ctrl = 32;
+	int first_calib;
+	u16 val;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+
+	/* BG voltage output */
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0xc000);
+
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	/* select 1V */
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0,
+		      MTK_PHY_RG_CAL_CKINV | MTK_PHY_RG_ANA_CALEN);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	/* select 1V */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x10);
+
+	/* Force 1G full duplex for calibration */
+	bmcr_tmp = phy_read(phydev, MII_BMCR);
+	phy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);
+
+	/* Force MDI */
+	dev1e_145_tmp = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x0145);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, 0x1010);
+
+	/* disable tx slew control */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0185, 0x0000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00fb, 0x0100);
+
+	switch (txg_calen_x) {
+	case PAIR_A:
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 MTK_PHY_RG_ANA_CAL_RG0,
+				 MTK_PHY_RG_ZCALEN_A);
+		break;
+	case PAIR_B:
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 MTK_PHY_RG_ANA_CAL_RG1,
+				 MTK_PHY_RG_ZCALEN_B);
+		break;
+	case PAIR_C:
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 MTK_PHY_RG_ANA_CAL_RG1,
+				 MTK_PHY_RG_ZCALEN_C);
+		break;
+	case PAIR_D:
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 MTK_PHY_RG_ANA_CAL_RG1,
+				 MTK_PHY_RG_ZCALEN_D);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	phydev_dbg(phydev, "Start TX r50 SW cal.\n");
+	first_calib = airoha_cal_cycle(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
+				       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);
+
+	if (first_calib < 0) {
+		phydev_err(phydev, "TX r50 SW calibration failed.\n");
+		return -EINVAL;
+	}
+
+	/* If TX r50 calibration failed:
+	 * - increase dB until calibration succeed.
+	 * If TX r50 calibration succeeded:
+	 * - decrease dB until calibration fail to fine tune it.
+	 */
+	if (first_calib == 1)
+		calibration_polarity = -1;
+	else
+		calibration_polarity = 1;
+
+	while (zcal_ctrl > 0 &&
+	       zcal_ctrl < FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK)) {
+		zcal_ctrl += calibration_polarity;
+
+		ret = airoha_cal_cycle(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
+				       MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);
+		/* Exit if we either failed or succeeded compared to the
+		 * first calibration result. (aka we finished fine tuning or
+		 * we succeeded with calibration)
+		 */
+		if (ret != first_calib)
+			break;
+	}
+
+	if (ret < 0) {
+		phydev_err(phydev, "TX r50 SW calibration failed.\n");
+		return -EINVAL;
+	}
+
+	if (zcal_ctrl == 0 ||
+	    zcal_ctrl == FIELD_MAX(MTK_PHY_RG_REXT_ZCAL_CTRL_MASK))
+		phydev_warn(phydev, "TX r50 SW calibration saturation.\n");
+
+	zcal_ctrl = shared->r50_cal_tbl[zcal_ctrl];
+
+	switch (txg_calen_x) {
+	case PAIR_A:
+		val = BIT(15) | FIELD_PREP(AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK, zcal_ctrl);
+		phy_modify_mmd(phydev, MDIO_MMD_VEND1,
+			       MTK_PHY_RG_CR_TX_R50_OFFSET_A_B,
+			       BIT(15) | AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK, val);
+		break;
+	case PAIR_B:
+		val = BIT(7) | FIELD_PREP(MTK_PHY_CR_TX_R50_OFFSET_B_MASK, zcal_ctrl);
+		phy_modify_mmd(phydev, MDIO_MMD_VEND1,
+			       MTK_PHY_RG_CR_TX_R50_OFFSET_A_B,
+			       BIT(7) | MTK_PHY_CR_TX_R50_OFFSET_B_MASK, val);
+		break;
+	case PAIR_C:
+		val = BIT(15) | FIELD_PREP(AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK, zcal_ctrl);
+		phy_modify_mmd(phydev, MDIO_MMD_VEND1,
+			       MTK_PHY_RG_CR_TX_R50_OFFSET_C_D,
+			       BIT(15) | AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK, val);
+		break;
+	case PAIR_D:
+		val = BIT(7) | FIELD_PREP(MTK_PHY_CR_TX_R50_OFFSET_D_MASK, zcal_ctrl);
+		phy_modify_mmd(phydev, MDIO_MMD_VEND1,
+			       MTK_PHY_RG_CR_TX_R50_OFFSET_C_D,
+			       BIT(7) | MTK_PHY_CR_TX_R50_OFFSET_D_MASK, val);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG0, 0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG1, 0);
+
+	/* Enable tx slew control */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0185, 0x0001);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00fb, 0x0000);
+
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x0);
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG6, 0x0);
+
+	/* Restore BMCR */
+	phy_write(phydev, MII_BMCR, bmcr_tmp);
+
+	/* Restore MDI */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0145, dev1e_145_tmp);
+
+	return 0;
+}
+
+static int airoha_rx_offset_cal_sw(struct phy_device *phydev)
+{
+	/* Hw bypass, Fw cal */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x96, 0x0);
+	/* tx/rx_cal_criteria_value */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x37, 0x0033);
+
+	/* rx offset cal by Hw setup */
+	phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,
+			   BIT(14) | BIT(11));
+
+	/* disable rtune calibration */
+	phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, 0x107,
+			   BIT(12));
+
+	/* bypass tx/rx dc offset cancellation process */
+	phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, 0x171,
+			 BIT(8) | BIT(7));
+
+	/* rx offset calibration start */
+	phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,
+			 BIT(13));
+
+	/* rx offset calibration stop */
+	phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x39,
+			   BIT(13));
+
+	mdelay(10);
+
+	phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0x171,
+			   BIT(8) | BIT(7));
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x100, 0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x145, 0x1000);
+
+	if (phydev->drv->phy_id == AIROHA_GPHY_ID_AN7581)
+		phy_write_mmd(phydev, MDIO_MMD_VEND1,
+			      MTK_PHY_RG_ANA_CAL_RG6, 0x1);
+
+	return 0;
+}
+
+static int airoha_cal_sw(struct phy_device *phydev, enum CAL_ITEM cal_item,
+			 u8 start_pair, u8 end_pair)
+{
+	u8 pair_n;
+	int ret;
+
+	for (pair_n = start_pair; pair_n <= end_pair; pair_n++) {
+		switch (cal_item) {
+		case REXT:
+			ret = airoha_rext_cal_sw(phydev);
+			break;
+		case TX_OFFSET:
+			ret = airoha_tx_offset_cal_sw(phydev, pair_n);
+			break;
+		case TX_AMP:
+			ret = airoha_tx_amp_cal_sw(phydev, pair_n);
+			break;
+		case TX_R50:
+			ret = airoha_tx_r50_cal_sw(phydev, pair_n);
+			break;
+		case RX_OFFSET:
+			ret = airoha_rx_offset_cal_sw(phydev);
+			break;
+		default:
+			return -EINVAL;
+		}
+		if (ret)
+			return ret;
+	}
+	return 0;
+}
+
+static int airoha_start_cal(struct phy_device *phydev, enum CAL_ITEM cal_item,
+			    enum CAL_MODE cal_mode, u8 start_pair,
+			    u8 end_pair, u32 *buf)
+{
+	int ret;
+
+	switch (cal_mode) {
+	case SW_M:
+		ret = airoha_cal_sw(phydev, cal_item, start_pair, end_pair);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (ret) {
+		phydev_err(phydev, "cal %d failed\n", cal_item);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int airoha_phy_calib(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+
+	/* PreCalibrate Set */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x5c, 0x6666);
+
+	phy_package_lock(phydev);
+	if (!shared->rext_sw_calib_done) {
+		ret = airoha_start_cal(phydev, REXT, SW_M, NO_PAIR, NO_PAIR, NULL);
+		if (ret) {
+			phy_package_unlock(phydev);
+			return ret;
+		}
+
+		shared->rext_sw_calib_done = true;
+	}
+	phy_package_unlock(phydev);
+
+	ret = airoha_start_cal(phydev, TX_R50, SW_M, PAIR_A, PAIR_D, NULL);
+	if (ret)
+		return ret;
+
+	ret = airoha_start_cal(phydev, TX_OFFSET, SW_M, PAIR_A, PAIR_D, NULL);
+	if (ret)
+		return ret;
+
+	ret = airoha_start_cal(phydev, TX_AMP, SW_M, PAIR_A, PAIR_D, NULL);
+	if (ret)
+		return ret;
+
+	ret = airoha_start_cal(phydev, RX_OFFSET, SW_M, NO_PAIR, NO_PAIR, NULL);
+	if (ret)
+		return ret;
+
+	/* Gating, short with other pair */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x15, 0x0);
+
+	phy_write_mmd(phydev_p0, MDIO_MMD_VEND2, 0x100, 0x0);
+
+	return 0;
+}
+
+static int airoha_phy_auto_select_transformer(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	u8 phy_offset;
+	u16 bmcr_tmp;
+	int oldpage;
+	int ret = 0;
+	u16 val;
+	int i;
+
+	phydev_p0 = shared->phydev_p0;
+	phy_offset = phydev->mdio.addr - phydev_p0->mdio.addr;
+
+	/* Force 1G full duplex for calibration */
+	bmcr_tmp = phy_read(phydev, MII_BMCR);
+	phy_write(phydev, MII_BMCR, BMCR_FULLDPLX | BMCR_SPEED1000);
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x271, GENMASK(4, 0),
+		       FIELD_PREP(GENMASK(4, 0), 0x3));
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x269, GENMASK(15, 12),
+		       FIELD_PREP(GENMASK(15, 12), 0x2));
+
+	phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0x26f, GENMASK(14, 12),
+		       FIELD_PREP(GENMASK(14, 12), 0x0));
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, BIT(12));
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,
+		      0x8000 | 0xf0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,
+		      0x8000 | 0xf0);
+
+	/* Force pGA gain */
+	oldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
+	__mtk_tr_modify(phydev, 0x1, 0xf, 0x10,
+			GENMASK(20, 15),
+			FIELD_PREP(GENMASK(20, 15), 0x1f));
+
+	__mtk_tr_modify(phydev, 0x1, 0xf, 0x11,
+			GENMASK(23, 18) | GENMASK(15, 10) | GENMASK(7, 2),
+			FIELD_PREP(GENMASK(23, 18), 0x1f) |
+			FIELD_PREP(GENMASK(15, 10), 0x1f) |
+			FIELD_PREP(GENMASK(7, 2), 0x1f));
+	phy_restore_page(phydev, oldpage, 0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xc9, 0xffff);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x151, 0x12);
+
+	switch (phy_offset) {
+	case 0:
+		val = 0x1;
+		break;
+	case 1:
+		val = 0x3;
+		break;
+	case 2:
+		val = 0x5;
+		break;
+	case 3:
+		val = 0x7;
+		break;
+	default:
+		ret = -EINVAL;
+		goto exit;
+	}
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x15,
+		      FIELD_PREP(GENMASK(14, 12), val) | 0x161);
+	mdelay(500);
+
+	for (i = 0; i < 3; i++)
+		val = phy_read_mmd(phydev, MDIO_MMD_VEND2, 0x1a);
+
+	/* Check the value and report transformer type for later */
+	shared->transformer_type[phy_offset] = val < 0xe0;
+
+exit:
+	/* Switch to Default */
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x15, 0x1000);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xdd, 0x0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_A,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_A,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_B,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_B,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_C,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_C,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN0_D,
+		      0x0);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DASN_DAC_IN1_D,
+		      0x0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xc9, 0xfff);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x151, 0x0);
+
+	oldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
+	__mtk_tr_modify(phydev, 0x1, 0xf, 0x10,
+			GENMASK(20, 15),
+			FIELD_PREP(GENMASK(20, 15), 0x4));
+
+	__mtk_tr_modify(phydev, 0x1, 0xf, 0x11,
+			GENMASK(23, 18) | GENMASK(15, 10) | GENMASK(7, 2),
+			FIELD_PREP(GENMASK(23, 18), 0x0) |
+			FIELD_PREP(GENMASK(15, 10), 0x0) |
+			FIELD_PREP(GENMASK(7, 2), 0x0));
+	phy_restore_page(phydev, oldpage, 0);
+
+	/* Restore BMCR */
+	phy_write(phydev, MII_BMCR, bmcr_tmp);
+
+	return ret;
+}
+
+static int airoha_phy_tx_amp_compensation(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+
+	u16 reg_1e_12_read;
+	u16 reg_1e_16_read;
+	u16 reg_1e_17_read;
+	u16 reg_1e_18_read;
+	u16 reg_1e_19_read;
+	u16 reg_1e_20_read;
+	u16 reg_1e_21_read;
+	u16 reg_1e_22_read;
+	u16 reg_1e_174_read;
+	u16 reg_1e_175_read;
+
+	int reg_1e_12_header;
+	int reg_1e_16_header;
+	int reg_1e_17_header;
+	int reg_1e_18_header;
+	int reg_1e_19_header;
+	int reg_1e_21_header;
+	int reg_1e_174_header;
+	int reg_1e_175_header;
+
+	int reg_1e_12_end;
+	int reg_1e_16_end;
+	int reg_1e_17_end;
+	int reg_1e_18_end;
+	int reg_1e_20_end;
+	int reg_1e_22_end;
+	int reg_1e_174_end;
+	int reg_1e_175_end;
+
+	struct phy_device *phydev_p0;
+	u8 phy_offset;
+
+	int txamp_low_limit = -3;
+	int txamp_high_limit = 0x42;
+
+	int r50_low_limit = -8;
+	int r50_high_limit = 0x88;
+
+	bool overflow;
+	int (*tx_amp_table)[CALIB_CONST_TYPE_MAX][4];
+	int transformer_type, mdi_resister_type;
+
+	phydev_p0 = shared->phydev_p0;
+	phy_offset = phydev->mdio.addr - phydev_p0->mdio.addr;
+
+	transformer_type = shared->transformer_type[phy_offset];
+	mdi_resister_type = shared->mdi_resister_type;
+	tx_amp_table = &(*shared->tx_amp_compensation_tbl)[transformer_type][mdi_resister_type];
+
+	reg_1e_12_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x12);
+	reg_1e_16_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x16);
+	reg_1e_17_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x17);
+	reg_1e_18_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x18);
+	reg_1e_19_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x19);
+	reg_1e_20_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x20);
+	reg_1e_21_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x21);
+	reg_1e_22_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x22);
+	reg_1e_174_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x174);
+	reg_1e_175_read = phy_read_mmd(phydev, MDIO_MMD_VEND1, 0x175);
+
+	reg_1e_12_header = ((reg_1e_12_read & 0xfc00) / 1024) + (*tx_amp_table)[TX_AMP_1G_A][phy_offset];
+	reg_1e_17_header = ((reg_1e_17_read & 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_B][phy_offset];
+	reg_1e_19_header = ((reg_1e_19_read & 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_C][phy_offset];
+	reg_1e_21_header = ((reg_1e_21_read & 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_1G_D][phy_offset];
+
+	overflow = false;
+	if (reg_1e_12_header < txamp_low_limit ||
+	    reg_1e_12_header > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_17_header < txamp_low_limit ||
+	    reg_1e_17_header > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_19_header < txamp_low_limit ||
+	    reg_1e_19_header > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_21_header < txamp_low_limit ||
+	    reg_1e_21_header > txamp_high_limit)
+		overflow = true;
+
+	if (overflow) {
+		reg_1e_12_header = 0x20;
+		reg_1e_17_header = 0x20;
+		reg_1e_19_header = 0x20;
+		reg_1e_21_header = 0x20;
+	} else {
+		if (reg_1e_12_header < 0)
+			reg_1e_12_header = 0;
+		else if (reg_1e_12_header > 0x3f)
+			reg_1e_12_header = 0x3f;
+		if (reg_1e_17_header < 0)
+			reg_1e_17_header = 0;
+		else if (reg_1e_17_header > 0x3f)
+			reg_1e_17_header = 0x3f;
+		if (reg_1e_19_header < 0)
+			reg_1e_19_header = 0;
+		else if (reg_1e_19_header > 0x3f)
+			reg_1e_19_header = 0x3f;
+		if (reg_1e_21_header < 0)
+			reg_1e_21_header = 0;
+		else if (reg_1e_21_header > 0x3f)
+			reg_1e_21_header = 0x3f;
+	}
+
+	reg_1e_16_end = (reg_1e_16_read & 0x003f) + (*tx_amp_table)[TX_AMP_TEST_A][phy_offset];
+	reg_1e_18_end = (reg_1e_18_read & 0x003f) + (*tx_amp_table)[TX_AMP_TEST_B][phy_offset];
+	reg_1e_20_end = (reg_1e_20_read & 0x003f) + (*tx_amp_table)[TX_AMP_TEST_C][phy_offset];
+	reg_1e_22_end = (reg_1e_22_read & 0x003f) + (*tx_amp_table)[TX_AMP_TEST_D][phy_offset];
+
+	overflow = false;
+	if (reg_1e_16_end < txamp_low_limit ||
+	    reg_1e_16_end > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_18_end < txamp_low_limit ||
+	    reg_1e_18_end > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_20_end < txamp_low_limit ||
+	    reg_1e_20_end > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_22_end < txamp_low_limit ||
+	    reg_1e_22_end > txamp_high_limit)
+		overflow = true;
+
+	if (overflow) {
+		reg_1e_16_end = 0x20;
+		reg_1e_18_end = 0x20;
+		reg_1e_20_end = 0x20;
+		reg_1e_22_end = 0x20;
+	} else {
+		if (reg_1e_16_end < 0)
+			reg_1e_16_end = 0;
+		else if (reg_1e_16_end > 0x3f)
+			reg_1e_16_end = 0x3f;
+		if (reg_1e_18_end < 0)
+			reg_1e_18_end = 0;
+		else if (reg_1e_18_end > 0x3f)
+			reg_1e_18_end = 0x3f;
+		if (reg_1e_20_end < 0)
+			reg_1e_20_end = 0;
+		else if (reg_1e_20_end > 0x3f)
+			reg_1e_20_end = 0x3f;
+		if (reg_1e_22_end < 0)
+			reg_1e_22_end = 0;
+		else if (reg_1e_22_end > 0x3f)
+			reg_1e_22_end = 0x3f;
+	}
+
+	reg_1e_16_header = ((reg_1e_16_read & 0xfc00) / 1024) + (*tx_amp_table)[TX_AMP_100M_A][phy_offset];
+	reg_1e_18_header = ((reg_1e_18_read & 0x3f00) / 256) + (*tx_amp_table)[TX_AMP_100M_B][phy_offset];
+
+	overflow = false;
+	if (reg_1e_16_header < txamp_low_limit ||
+	    reg_1e_16_header > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_18_header < txamp_low_limit ||
+	    reg_1e_18_header > txamp_high_limit)
+		overflow = true;
+
+	if (overflow) {
+		reg_1e_16_header = 0x20;
+		reg_1e_18_header = 0x20;
+	} else {
+		if (reg_1e_16_header < 0)
+			reg_1e_16_header = 0;
+		else if (reg_1e_16_header > 0x3f)
+			reg_1e_16_header = 0x3f;
+		if (reg_1e_18_header < 0)
+			reg_1e_18_header = 0;
+		else if (reg_1e_18_header > 0x3f)
+			reg_1e_18_header = 0x3f;
+	}
+
+	reg_1e_12_end = (reg_1e_12_read & 0x003f) + (*tx_amp_table)[TX_AMP_10M_A][phy_offset];
+	reg_1e_17_end = (reg_1e_17_read & 0x003f) + (*tx_amp_table)[TX_AMP_10M_B][phy_offset];
+
+	overflow = false;
+	if (reg_1e_12_end < txamp_low_limit ||
+	    reg_1e_12_end > txamp_high_limit)
+		overflow = true;
+	if (reg_1e_17_end < txamp_low_limit ||
+	    reg_1e_17_end > txamp_high_limit)
+		overflow = true;
+
+	if (overflow) {
+		reg_1e_12_end = 0x20;
+		reg_1e_17_end = 0x20;
+	} else {
+		if (reg_1e_12_end < 0)
+			reg_1e_12_end = 0;
+		else if (reg_1e_12_end > 0x3f)
+			reg_1e_12_end = 0x3f;
+		if (reg_1e_17_end < 0)
+			reg_1e_17_end = 0;
+		else if (reg_1e_17_end > 0x3f)
+			reg_1e_17_end = 0x3f;
+	}
+
+	reg_1e_174_header = ((reg_1e_174_read & 0x7f00) / 256) + (*tx_amp_table)[R50_A][phy_offset];
+	reg_1e_174_end = (reg_1e_174_read & 0x007f) + (*tx_amp_table)[R50_B][phy_offset];
+	reg_1e_175_header = ((reg_1e_175_read & 0x7f00) / 256) + (*tx_amp_table)[R50_C][phy_offset];
+	reg_1e_175_end = (reg_1e_175_read & 0x007f) + (*tx_amp_table)[R50_D][phy_offset];
+
+	overflow = false;
+	if (reg_1e_174_header < r50_low_limit ||
+	    reg_1e_174_header > r50_high_limit)
+		overflow = true;
+	if (reg_1e_174_end < r50_low_limit ||
+	    reg_1e_174_end > r50_high_limit)
+		overflow = true;
+	if (reg_1e_175_header < r50_low_limit ||
+	    reg_1e_175_header > r50_high_limit)
+		overflow = true;
+	if (reg_1e_175_end < r50_low_limit ||
+	    reg_1e_175_end > r50_high_limit)
+		overflow = true;
+
+	if (overflow) {
+		reg_1e_174_header = 0x34;
+		reg_1e_174_end = 0x34;
+		reg_1e_175_header = 0x34;
+		reg_1e_175_end = 0x34;
+	} else {
+		if (reg_1e_174_header < 0)
+			reg_1e_174_header = 0;
+		else if (reg_1e_174_header > 0x7f)
+			reg_1e_174_header = 0x7f;
+		if (reg_1e_174_end < 0)
+			reg_1e_174_end = 0;
+		else if (reg_1e_174_end > 0x7f)
+			reg_1e_174_end = 0x7f;
+		if (reg_1e_175_header < 0)
+			reg_1e_175_header = 0;
+		else if (reg_1e_175_header > 0x7f)
+			reg_1e_175_header = 0x7f;
+		if (reg_1e_175_end < 0)
+			reg_1e_175_end = 0;
+		else if (reg_1e_175_end > 0x7f)
+			reg_1e_175_end = 0x7f;
+	}
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x12,
+		      (reg_1e_12_header * 1024) + reg_1e_12_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x16,
+		      (reg_1e_16_header * 1024) + reg_1e_16_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x17,
+		      (reg_1e_17_header * 256) + reg_1e_17_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x18,
+		      (reg_1e_18_header * 256) + reg_1e_18_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x19,
+		      (reg_1e_19_read & 0x00ff) + (reg_1e_19_header * 256));
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x20,
+		      (reg_1e_20_read & 0xff00) + reg_1e_20_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x21,
+		      (reg_1e_21_read & 0x00ff) + (reg_1e_21_header * 256));
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x22,
+		      (reg_1e_22_read & 0xff00) + reg_1e_22_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x174,
+		      0x8080 + (reg_1e_174_header * 256) + reg_1e_174_end);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x175,
+		      0x8080 + (reg_1e_175_header * 256) + reg_1e_175_end);
+
+	return 0;
+}
+
+static int an7581_phy_package_config_init_once(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+
+	/* FIXME: Read SoC PDIDR if available or default to 2 (latest) */
+	shared->soc_pdidr = 2;
+
+	shared->mdi_resister_type = MDI_5R;
+	if (shared->soc_pdidr == 2)
+		shared->tx_amp_compensation_tbl = &an7581_tx_amp_compensation_tbl[1];
+	else
+		shared->tx_amp_compensation_tbl = &an7581_tx_amp_compensation_tbl[0];
+	shared->r50_cal_tbl = an7581_zcal_to_r45ohm;
+
+	return 0;
+}
+
+static int an7581_phy_config_init(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	u8 phy_offset;
+	int oldpage;
+	int ret;
+
+	phydev_p0 = shared->phydev_p0;
+	phy_offset = phydev->mdio.addr - phydev_p0->mdio.addr;
+
+	if (phy_package_init_once(phydev)) {
+		ret = an7581_phy_package_config_init_once(phydev);
+		if (ret)
+			return ret;
+	}
+
+	ret = airoha_phy_calib(phydev);
+	if (ret)
+		return ret;
+
+	ret = airoha_phy_auto_select_transformer(phydev);
+	if (ret)
+		return ret;
+
+	ret = airoha_phy_tx_amp_compensation(phydev);
+	if (ret)
+		return ret;
+
+	/* RX setting for 5R_TXMR before AN setting */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe6, 0x1111);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe7, 0x5555);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe9, 0x0001);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xfe, 0x0000);
+
+	/* Long Loop Reach setting */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x11, 0xff00);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x202, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x203, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x204, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x205, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x206, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x207, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x208, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x209, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20a, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20b, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20e, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x20f, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x210, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x211, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x212, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x213, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x214, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x215, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x216, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x217, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21a, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21b, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21c, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21d, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21e, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x21f, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x220, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x221, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x222, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x223, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x226, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x227, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x228, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x229, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22a, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22b, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22c, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22d, 0x0025);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22e, 0x2310);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x22f, 0x0025);
+
+	/* RX Setting */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3c, 0xc000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3d, 0x0000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);
+
+	/* EEE setting */
+	phy_write_mmd(phydev, MDIO_MMD_AN, 0x3c, 0x0000);
+
+	/* RX */
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x41, 0x3333);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x44, 0x00c0);
+
+	/* 10M settings */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a3, 0x00d2);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a4, 0x010e);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27b, 0x1177);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27c, 0x0808);
+
+	oldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_1);
+	__phy_write(phydev, 0x14, 0x3a18);
+	phy_restore_page(phydev, oldpage, 0);
+
+	phy_write(phydev, 0x9, 0x1e00);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x269, 0x2114);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26a, 0x1113);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26f, 0x0000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x2c63);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x272, 0x0c2b);
+
+	/* EEE set because power down can't set tokenring */
+	oldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
+	__mtk_tr_write(phydev, 0x0, 0x7, 0x15, 0x0055a0);
+	__mtk_tr_write(phydev, 0x0, 0x7, 0x17, 0x07ff3f);
+	__mtk_tr_write(phydev, 0x1, 0xf, 0x0, 0x00001e);
+	__mtk_tr_write(phydev, 0x1, 0xf, 0x1, 0x6fb90a);
+	__mtk_tr_write(phydev, 0x1, 0xf, 0x18, 0x0e2f00);
+	__mtk_tr_write(phydev, 0x1, 0xd, 0x26, 0x444444);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x3, 0x000004);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x6, 0x2ebaef);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x8, 0x00000b);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0xc, 0x00504d);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0xd, 0x02314f);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0xf, 0x003028);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x10, 0x00000a);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x11, 0x040001);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x14, 0x00024a);
+	__mtk_tr_write(phydev, 0x2, 0xd, 0x1c, 0x003210);
+	phy_restore_page(phydev, oldpage, 0);
+
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x120, 0x8014);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x122, 0xffff);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x144, 0x0200);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x14a, 0xee20);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x19b, 0x0111);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x234, 0x1181);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x238, 0x0120);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x239, 0x0117);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x2d1, 0x0733);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x323, 0x0011);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x324, 0x013f);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x326, 0x0037);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x268, 0x07f4);
+
+	if (shared->transformer_type[phy_offset] == TXMR) {
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0187);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cc);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0109);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x020b);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0202);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03c5);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c2);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0309);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x000e);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0002);
+
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0880);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0880);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0880);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0880);
+	} else {
+		if (shared->soc_pdidr == 2) {
+			phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x269, 0x1114);
+			phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26a, 0x1113);
+			phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x26f, 0x2000);
+			phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x4c88);
+			phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x272, 0x0c2b);
+
+			/* 100M sharp */
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0190);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01c8);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c0);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0030);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0208);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0000);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0318);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03c8);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c0);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0230);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x0008);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0200);
+
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0885);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0885);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0885);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0885);
+		} else {
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0190);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cf);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c0);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0030);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x020f);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0000);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0318);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03cf);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c0);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x09, 0x0230);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x000f);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0200);
+
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0003);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0003);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0003);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0003);
+		}
+	}
+
+	return 0;
+}
+
+static int an7581_phy_probe(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared;
+	struct mtk_socphy_priv *priv;
+	struct pinctrl *pinctrl;
+	int ret;
+
+	/* Toggle pinctrl to enable PHY LED */
+	pinctrl = devm_pinctrl_get_select(&phydev->mdio.dev, "gbe-led");
+	if (IS_ERR(pinctrl))
+		dev_err(&phydev->mdio.bus->dev,
+			"Failed to setup PHY LED pinctrl\n");
+
+	ret = devm_phy_package_join(&phydev->mdio.dev, phydev, 0,
+				    sizeof(struct airoha_socphy_shared));
+	if (ret)
+		return ret;
+
+	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	shared = phy_package_get_priv(phydev);
+	if (phydev->mdio.addr == AIROHA_DEFAULT_PORT0_ADDR)
+		shared->phydev_p0 = phydev;
+
+	/*
+	 * Make sure PHY at port 0 is available for calibration.
+	 * If port 0 is disabled in DT, probing will eventually fail
+	 * after exhausting the deferred probe retries.
+	 */
+	if (!shared->phydev_p0) {
+		phydev_err(phydev, "PHY at port 0 is not available yet. (mandatory for calibration)\n");
+		return -EPROBE_DEFER;
+	}
+
+	phydev->priv = priv;
+
+	return 0;
+}
+
+static int an7581_phy_led_polarity_set(struct phy_device *phydev, int index,
+				       unsigned long modes)
+{
+	u16 val = 0;
+	u32 mode;
+
+	if (index >= AIROHA_PHY_MAX_LEDS)
+		return -EINVAL;
+
+	for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
+		switch (mode) {
+		case PHY_LED_ACTIVE_LOW:
+			val = MTK_PHY_LED_ON_POLARITY;
+			break;
+		case PHY_LED_ACTIVE_HIGH:
+			break;
+		default:
+			return -EINVAL;
+		}
+	}
+
+	return phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?
+			      MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL,
+			      MTK_PHY_LED_ON_POLARITY, val);
+}
+
+static int en7528_phy_config_init(struct phy_device *phydev)
+{
+	/* The LED controller of the EN7528 powers up with its external
+	 * control disabled, leaving the LED pins dark regardless of what is
+	 * programmed into the LED control registers. Hand the pins over to
+	 * the LED control registers the same way the air_en8811h driver
+	 * does; the mode field of this register is already set out of reset.
+	 */
+	return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED_BCR,
+				MTK_PHY_LED_BCR_CLK_EN |
+				MTK_PHY_LED_BCR_EXT_CTRL);
+}
+
+static int an7583_phy_package_config_init_once(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+
+	/* FIXME: Read SoC MDI Resister Type if available or default to 5R */
+	shared->mdi_resister_type = MDI_5R;
+
+	if (shared->mdi_resister_type == MDI_0R)
+		shared->r50_cal_tbl = an7583_zcal_to_r50ohm_0R;
+	if (shared->mdi_resister_type == MDI_5R)
+		shared->r50_cal_tbl = an7583_zcal_to_r50ohm_5R;
+	shared->tx_amp_compensation_tbl = &an7583_tx_amp_compensation_tbl;
+
+	return 0;
+}
+
+static int an7583_phy_config_init(struct phy_device *phydev)
+{
+	struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
+	struct phy_device *phydev_p0;
+	u8 phy_offset;
+	int ret;
+
+	/* BMCR_PDOWN is enabled by default */
+	phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);
+
+	phydev_p0 = shared->phydev_p0;
+	phy_offset = phydev->mdio.addr - phydev_p0->mdio.addr;
+
+	if (phy_package_init_once(phydev)) {
+		ret = an7583_phy_package_config_init_once(phydev);
+		if (ret)
+			return ret;
+	}
+
+	ret = airoha_phy_calib(phydev);
+	if (ret)
+		return ret;
+
+	ret = airoha_phy_auto_select_transformer(phydev);
+	if (ret)
+		return ret;
+
+	ret = airoha_phy_tx_amp_compensation(phydev);
+	if (ret)
+		return ret;
+
+	/* Enable Idle Mode Power Setting */
+	if (phy_offset == 0) {
+		phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x268, 0x07F1);
+		phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x703, 0x3111);
+		phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x271, 0x3C24);
+		phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x701, 0x1023);
+	}
+
+	if (shared->transformer_type[phy_offset] == TXMR) {
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0881);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0881);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0881);
+		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0881);
+
+		if (shared->mdi_resister_type == MDI_5R)
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);
+		else
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0200);
+	} else {
+		if (shared->mdi_resister_type == MDI_5R) {
+			/* RX setting for 5R_TXMR before AN setting */
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe7, 0x6666);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe9, 0x0003);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xfe, 0x0006);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xe6, 0x1111);
+			/* 100M sharp */
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0c86);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0c86);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0c86);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0c86);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cb);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0108);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0211);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03ce);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c8);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0005);
+		} else {
+			/* 100M sharp */
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x23, 0x0886);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x24, 0x0886);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x25, 0x0886);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x26, 0x0886);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x00, 0x0195);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01, 0x01cb);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x02, 0x01c2);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x03, 0x0108);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x04, 0x0211);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x05, 0x0205);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x06, 0x0387);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x07, 0x03ce);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x08, 0x03c3);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0a, 0x0010);
+			phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x0b, 0x0005);
+		}
+	}
+
+	/* RX Setting */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3c, 0xc000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3d, 0x0000);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x3e, 0xc000);
+
+	/* EEE setting */
+	phy_write_mmd(phydev, MDIO_MMD_AN, 0x3c, 0x0000);
+
+	/* 10M settings */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a3, 0x00d2);
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x1a4, 0x010e);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27b, 0x1177);
+	phy_write_mmd(phydev, MDIO_MMD_VEND2, 0x27c, 0x0808);
+
+	phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_3, 0x14, 0x190);
+	phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_1, 0x14, 0x3a18);
+
+	phy_write(phydev, 0x9, 0x0600);
+
+	/* EEE keep only Pair A ON */
+	phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x630, 0x006E);
+
+	return 0;
+}
+
+static struct phy_driver mtk_socphy_driver[] = {
+	{
+		PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528),
+		.name		= "EcoNet EN7528 PHY",
+		.config_init	= en7528_phy_config_init,
+		.probe		= an7581_phy_probe,
+		.led_blink_set	= mt798x_phy_led_blink_set,
+		.led_brightness_set = mt798x_phy_led_brightness_set,
+		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
+		.led_hw_control_set = mt798x_phy_led_hw_control_set,
+		.led_hw_control_get = mt798x_phy_led_hw_control_get,
+		.led_polarity_set = an7581_phy_led_polarity_set,
+	},
+	{
+		PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581),
+		.name		= "Airoha AN7581 PHY",
+		.config_init	= an7581_phy_config_init,
+		.config_intr	= genphy_no_config_intr,
+		.handle_interrupt = genphy_handle_interrupt_no_ack,
+		.probe		= an7581_phy_probe,
+		.led_blink_set	= mt798x_phy_led_blink_set,
+		.led_brightness_set = mt798x_phy_led_brightness_set,
+		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
+		.led_hw_control_set = mt798x_phy_led_hw_control_set,
+		.led_hw_control_get = mt798x_phy_led_hw_control_get,
+		.led_polarity_set = an7581_phy_led_polarity_set,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
+	},
+	{
+		PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583),
+		.name		= "Airoha AN7583 PHY",
+		.config_init	= an7583_phy_config_init,
+		.probe		= an7581_phy_probe,
+		.led_blink_set	= mt798x_phy_led_blink_set,
+		.led_brightness_set = mt798x_phy_led_brightness_set,
+		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
+		.led_hw_control_set = mt798x_phy_led_hw_control_set,
+		.led_hw_control_get = mt798x_phy_led_hw_control_get,
+		.led_polarity_set = an7581_phy_led_polarity_set,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
+	},
+};
+
+module_phy_driver(mtk_socphy_driver);
+
+static const struct mdio_device_id __maybe_unused airoha_socphy_tbl[] = {
+	{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528) },
+	{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581) },
+	{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583) },
+	{ }
+};
+
+MODULE_DESCRIPTION("Airoha SoC Gigabit Ethernet PHY driver");
+MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("01.01.20260306");
+
+MODULE_DEVICE_TABLE(mdio, airoha_socphy_tbl);
diff --git a/drivers/net/phy/mediatek/mtk-ge-soc.c b/drivers/net/phy/mediatek/mtk-ge-soc.c
index 0041300d4f1013..4132ac40358355 100644
--- a/drivers/net/phy/mediatek/mtk-ge-soc.c
+++ b/drivers/net/phy/mediatek/mtk-ge-soc.c
@@ -11,331 +11,10 @@
 
 #include "../phylib.h"
 #include "mtk.h"
+#include "mtk-ge-soc.h"
 
 #define MTK_PHY_MAX_LEDS			2
 
-#define MTK_GPHY_ID_MT7981			0x03a29461
-#define MTK_GPHY_ID_MT7988			0x03a29481
-#define MTK_GPHY_ID_EN7528			0x03a29491
-#define MTK_GPHY_ID_AN7581			0x03a294c1
-#define MTK_GPHY_ID_AN7583			0xc0ff0420
-
-#define MTK_EXT_PAGE_ACCESS			0x1f
-#define MTK_PHY_PAGE_STANDARD			0x0000
-#define MTK_PHY_PAGE_EXTENDED_3			0x0003
-
-#define MTK_PHY_LPI_REG_14			0x14
-#define MTK_PHY_LPI_WAKE_TIMER_1000_MASK	GENMASK(8, 0)
-
-#define MTK_PHY_LPI_REG_1c			0x1c
-#define MTK_PHY_SMI_DET_ON_THRESH_MASK		GENMASK(13, 8)
-
-#define MTK_PHY_PAGE_EXTENDED_2A30		0x2a30
-
-/* Registers on Token Ring debug nodes */
-/* ch_addr = 0x0, node_addr = 0x7, data_addr = 0x15 */
-/* NormMseLoThresh */
-#define NORMAL_MSE_LO_THRESH_MASK		GENMASK(15, 8)
-
-/* ch_addr = 0x0, node_addr = 0xf, data_addr = 0x3c */
-/* RemAckCntLimitCtrl */
-#define REMOTE_ACK_COUNT_LIMIT_CTRL_MASK	GENMASK(2, 1)
-
-/* ch_addr = 0x1, node_addr = 0xd, data_addr = 0x20 */
-/* VcoSlicerThreshBitsHigh */
-#define VCO_SLICER_THRESH_HIGH_MASK		GENMASK(23, 0)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x0 */
-/* DfeTailEnableVgaThresh1000 */
-#define DFE_TAIL_EANBLE_VGA_TRHESH_1000		GENMASK(5, 1)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x1 */
-/* MrvlTrFix100Kp */
-#define MRVL_TR_FIX_100KP_MASK			GENMASK(22, 20)
-/* MrvlTrFix100Kf */
-#define MRVL_TR_FIX_100KF_MASK			GENMASK(19, 17)
-/* MrvlTrFix1000Kp */
-#define MRVL_TR_FIX_1000KP_MASK			GENMASK(16, 14)
-/* MrvlTrFix1000Kf */
-#define MRVL_TR_FIX_1000KF_MASK			GENMASK(13, 11)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x12 */
-/* VgaDecRate */
-#define VGA_DECIMATION_RATE_MASK		GENMASK(8, 5)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x17 */
-/* SlvDSPreadyTime */
-#define SLAVE_DSP_READY_TIME_MASK		GENMASK(22, 15)
-/* MasDSPreadyTime */
-#define MASTER_DSP_READY_TIME_MASK		GENMASK(14, 7)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x18 */
-/* EnabRandUpdTrig */
-#define ENABLE_RANDOM_UPDOWN_COUNTER_TRIGGER	BIT(8)
-
-/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x20 */
-/* ResetSyncOffset */
-#define RESET_SYNC_OFFSET_MASK			GENMASK(11, 8)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x0 */
-/* FfeUpdGainForceVal */
-#define FFE_UPDATE_GAIN_FORCE_VAL_MASK		GENMASK(9, 7)
-/* FfeUpdGainForce */
-#define FFE_UPDATE_GAIN_FORCE			BIT(6)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x3 */
-/* TrFreeze */
-#define TR_FREEZE_MASK				GENMASK(11, 0)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x6 */
-/* SS: Steady-state, KP: Proportional Gain */
-/* SSTrKp100 */
-#define SS_TR_KP100_MASK			GENMASK(21, 19)
-/* SSTrKf100 */
-#define SS_TR_KF100_MASK			GENMASK(18, 16)
-/* SSTrKp1000Mas */
-#define SS_TR_KP1000_MASTER_MASK		GENMASK(15, 13)
-/* SSTrKf1000Mas */
-#define SS_TR_KF1000_MASTER_MASK		GENMASK(12, 10)
-/* SSTrKp1000Slv */
-#define SS_TR_KP1000_SLAVE_MASK			GENMASK(9, 7)
-/* SSTrKf1000Slv */
-#define SS_TR_KF1000_SLAVE_MASK			GENMASK(6, 4)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x8 */
-/* clear this bit if wanna select from AFE */
-/* Regsigdet_sel_1000 */
-#define EEE1000_SELECT_SIGNAL_DETECTION_FROM_DFE	BIT(4)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xd */
-/* RegEEE_st2TrKf1000 */
-#define EEE1000_STAGE2_TR_KF_MASK		GENMASK(13, 11)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xf */
-/* RegEEE_slv_waketr_timer_tar */
-#define SLAVE_WAKETR_TIMER_MASK			GENMASK(20, 11)
-/* RegEEE_slv_remtx_timer_tar */
-#define SLAVE_REMTX_TIMER_MASK			GENMASK(10, 1)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x10 */
-/* RegEEE_slv_wake_int_timer_tar */
-#define SLAVE_WAKEINT_TIMER_MASK		GENMASK(10, 1)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x14 */
-/* RegEEE_trfreeze_timer2 */
-#define TR_FREEZE_TIMER2_MASK			GENMASK(9, 0)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x1c */
-/* RegEEE100Stg1_tar */
-#define EEE100_LPSYNC_STAGE1_UPDATE_TIMER_MASK	GENMASK(8, 0)
-
-/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x25 */
-/* REGEEE_wake_slv_tr_wait_dfesigdet_en */
-#define WAKE_SLAVE_TR_WAIT_DFE_DETECTION_EN	BIT(11)
-
-#define ANALOG_INTERNAL_OPERATION_MAX_US	20
-#define TXRESERVE_MIN				0
-#define TXRESERVE_MAX				7
-
-#define MTK_PHY_ANARG_RG			0x10
-#define   MTK_PHY_TCLKOFFSET_MASK		GENMASK(12, 8)
-
-/* Registers on MDIO_MMD_VEND1 */
-#define MTK_PHY_TXVLD_DA_RG			0x12
-#define   MTK_PHY_DA_TX_I2MPB_A_GBE_MASK	GENMASK(15, 10)
-#define   MTK_PHY_DA_TX_I2MPB_A_TBT_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_A2		0x16
-#define   MTK_PHY_DA_TX_I2MPB_A_HBT_MASK	GENMASK(15, 10)
-#define   MTK_PHY_DA_TX_I2MPB_A_TST_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_B1		0x17
-#define   MTK_PHY_DA_TX_I2MPB_B_GBE_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_B_TBT_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_B2		0x18
-#define   MTK_PHY_DA_TX_I2MPB_B_HBT_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_B_TST_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_C1		0x19
-#define   MTK_PHY_DA_TX_I2MPB_C_GBE_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_C_TBT_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_C2		0x20
-#define   MTK_PHY_DA_TX_I2MPB_C_HBT_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_C_TST_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_D1		0x21
-#define   MTK_PHY_DA_TX_I2MPB_D_GBE_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_D_TBT_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_TX_I2MPB_TEST_MODE_D2		0x22
-#define   MTK_PHY_DA_TX_I2MPB_D_HBT_MASK	GENMASK(13, 8)
-#define   MTK_PHY_DA_TX_I2MPB_D_TST_MASK	GENMASK(5, 0)
-
-#define MTK_PHY_RXADC_CTRL_RG7			0xc6
-#define   MTK_PHY_DA_AD_BUF_BIAS_LP_MASK	GENMASK(9, 8)
-
-#define MTK_PHY_RXADC_CTRL_RG9			0xc8
-#define   MTK_PHY_DA_RX_PSBN_TBT_MASK		GENMASK(14, 12)
-#define   MTK_PHY_DA_RX_PSBN_HBT_MASK		GENMASK(10, 8)
-#define   MTK_PHY_DA_RX_PSBN_GBE_MASK		GENMASK(6, 4)
-#define   MTK_PHY_DA_RX_PSBN_LP_MASK		GENMASK(2, 0)
-
-#define MTK_PHY_LDO_OUTPUT_V			0xd7
-
-#define MTK_PHY_RG_ANA_CAL_RG0			0xdb
-#define   MTK_PHY_RG_CAL_CKINV			BIT(12)
-#define   MTK_PHY_RG_ANA_CALEN			BIT(8)
-#define   MTK_PHY_RG_ZCALEN_A			BIT(0)
-
-#define MTK_PHY_RG_ANA_CAL_RG1			0xdc
-#define   MTK_PHY_RG_ZCALEN_B			BIT(12)
-#define   MTK_PHY_RG_ZCALEN_C			BIT(8)
-#define   MTK_PHY_RG_ZCALEN_D			BIT(4)
-#define   MTK_PHY_RG_TXVOS_CALEN		BIT(0)
-
-#define MTK_PHY_RG_ANA_CAL_RG5			0xe0
-#define   MTK_PHY_RG_REXT_TRIM_MASK		GENMASK(13, 8)
-
-#define MTK_PHY_RG_TX_FILTER			0xfe
-
-#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG120	0x120
-#define   MTK_PHY_LPI_SIG_EN_LO_THRESH1000_MASK	GENMASK(12, 8)
-#define   MTK_PHY_LPI_SIG_EN_HI_THRESH1000_MASK	GENMASK(4, 0)
-
-#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG122	0x122
-#define   MTK_PHY_LPI_NORM_MSE_HI_THRESH1000_MASK	GENMASK(7, 0)
-
-#define MTK_PHY_RG_TESTMUX_ADC_CTRL		0x144
-#define   MTK_PHY_RG_TXEN_DIG_MASK		GENMASK(5, 5)
-
-#define MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B		0x172
-#define   MTK_PHY_CR_TX_AMP_OFFSET_A_MASK	GENMASK(13, 8)
-#define   MTK_PHY_CR_TX_AMP_OFFSET_B_MASK	GENMASK(6, 0)
-
-#define MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D		0x173
-#define   MTK_PHY_CR_TX_AMP_OFFSET_C_MASK	GENMASK(13, 8)
-#define   MTK_PHY_CR_TX_AMP_OFFSET_D_MASK	GENMASK(6, 0)
-
-#define MTK_PHY_RG_AD_CAL_COMP			0x17a
-#define   MTK_PHY_AD_CAL_COMP_OUT_MASK		GENMASK(8, 8)
-
-#define MTK_PHY_RG_AD_CAL_CLK			0x17b
-#define   MTK_PHY_DA_CAL_CLK			BIT(0)
-
-#define MTK_PHY_RG_AD_CALIN			0x17c
-#define   MTK_PHY_DA_CALIN_FLAG			BIT(0)
-
-#define MTK_PHY_RG_DASN_DAC_IN0_A		0x17d
-#define   MTK_PHY_DASN_DAC_IN0_A_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN0_B		0x17e
-#define   MTK_PHY_DASN_DAC_IN0_B_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN0_C		0x17f
-#define   MTK_PHY_DASN_DAC_IN0_C_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN0_D		0x180
-#define   MTK_PHY_DASN_DAC_IN0_D_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN1_A		0x181
-#define   MTK_PHY_DASN_DAC_IN1_A_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN1_B		0x182
-#define   MTK_PHY_DASN_DAC_IN1_B_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN1_C		0x183
-#define   MTK_PHY_DASN_DAC_IN1_C_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DASN_DAC_IN1_D		0x184
-#define   MTK_PHY_DASN_DAC_IN1_D_MASK		GENMASK(9, 0)
-
-#define MTK_PHY_RG_DEV1E_REG19b			0x19b
-#define   MTK_PHY_BYPASS_DSP_LPI_READY		BIT(8)
-
-#define MTK_PHY_RG_LP_IIR2_K1_L			0x22a
-#define MTK_PHY_RG_LP_IIR2_K1_U			0x22b
-#define MTK_PHY_RG_LP_IIR2_K2_L			0x22c
-#define MTK_PHY_RG_LP_IIR2_K2_U			0x22d
-#define MTK_PHY_RG_LP_IIR2_K3_L			0x22e
-#define MTK_PHY_RG_LP_IIR2_K3_U			0x22f
-#define MTK_PHY_RG_LP_IIR2_K4_L			0x230
-#define MTK_PHY_RG_LP_IIR2_K4_U			0x231
-#define MTK_PHY_RG_LP_IIR2_K5_L			0x232
-#define MTK_PHY_RG_LP_IIR2_K5_U			0x233
-
-#define MTK_PHY_RG_DEV1E_REG234			0x234
-#define   MTK_PHY_TR_OPEN_LOOP_EN_MASK		GENMASK(0, 0)
-#define   MTK_PHY_LPF_X_AVERAGE_MASK		GENMASK(7, 4)
-#define   MTK_PHY_TR_LP_IIR_EEE_EN		BIT(12)
-
-#define MTK_PHY_RG_LPF_CNT_VAL			0x235
-
-#define MTK_PHY_RG_DEV1E_REG238			0x238
-#define   MTK_PHY_LPI_SLV_SEND_TX_TIMER_MASK	GENMASK(8, 0)
-#define   MTK_PHY_LPI_SLV_SEND_TX_EN		BIT(12)
-
-#define MTK_PHY_RG_DEV1E_REG239			0x239
-#define   MTK_PHY_LPI_SEND_LOC_TIMER_MASK	GENMASK(8, 0)
-#define   MTK_PHY_LPI_TXPCS_LOC_RCV		BIT(12)
-
-#define MTK_PHY_RG_DEV1E_REG27C			0x27c
-#define   MTK_PHY_VGASTATE_FFE_THR_ST1_MASK	GENMASK(12, 8)
-#define MTK_PHY_RG_DEV1E_REG27D			0x27d
-#define   MTK_PHY_VGASTATE_FFE_THR_ST2_MASK	GENMASK(4, 0)
-
-#define MTK_PHY_RG_DEV1E_REG2C7			0x2c7
-#define   MTK_PHY_MAX_GAIN_MASK			GENMASK(4, 0)
-#define   MTK_PHY_MIN_GAIN_MASK			GENMASK(12, 8)
-
-#define MTK_PHY_RG_DEV1E_REG2D1			0x2d1
-#define   MTK_PHY_VCO_SLICER_THRESH_BITS_HIGH_EEE_MASK	GENMASK(7, 0)
-#define   MTK_PHY_LPI_SKIP_SD_SLV_TR		BIT(8)
-#define   MTK_PHY_LPI_TR_READY			BIT(9)
-#define   MTK_PHY_LPI_VCO_EEE_STG0_EN		BIT(10)
-
-#define MTK_PHY_RG_DEV1E_REG323			0x323
-#define   MTK_PHY_EEE_WAKE_MAS_INT_DC		BIT(0)
-#define   MTK_PHY_EEE_WAKE_SLV_INT_DC		BIT(4)
-
-#define MTK_PHY_RG_DEV1E_REG324			0x324
-#define   MTK_PHY_SMI_DETCNT_MAX_MASK		GENMASK(5, 0)
-#define   MTK_PHY_SMI_DET_MAX_EN		BIT(8)
-
-#define MTK_PHY_RG_DEV1E_REG326			0x326
-#define   MTK_PHY_LPI_MODE_SD_ON		BIT(0)
-#define   MTK_PHY_RESET_RANDUPD_CNT		BIT(1)
-#define   MTK_PHY_TREC_UPDATE_ENAB_CLR		BIT(2)
-#define   MTK_PHY_LPI_QUIT_WAIT_DFE_SIG_DET_OFF	BIT(4)
-#define   MTK_PHY_TR_READY_SKIP_AFE_WAKEUP	BIT(5)
-
-#define MTK_PHY_LDO_PUMP_EN_PAIRAB		0x502
-#define MTK_PHY_LDO_PUMP_EN_PAIRCD		0x503
-
-#define MTK_PHY_DA_TX_R50_PAIR_A		0x53d
-#define MTK_PHY_DA_TX_R50_PAIR_B		0x53e
-#define MTK_PHY_DA_TX_R50_PAIR_C		0x53f
-#define MTK_PHY_DA_TX_R50_PAIR_D		0x540
-
-/* Registers on MDIO_MMD_VEND2 */
-#define MTK_PHY_LED1_DEFAULT_POLARITIES		BIT(1)
-
-/* LED basic control register, part of the same LED block as the LED0/LED1
- * control registers above. The air_en8811h driver describes the same
- * register as AIR_PHY_LED_BCR.
- */
-#define MTK_PHY_LED_BCR				0x21
-#define   MTK_PHY_LED_BCR_CLK_EN		BIT(3)
-#define   MTK_PHY_LED_BCR_EXT_CTRL		BIT(15)
-
-#define MTK_PHY_RG_BG_RASEL			0x115
-#define   MTK_PHY_RG_BG_RASEL_MASK		GENMASK(2, 0)
-
-/* 'boottrap' register reflecting the configuration of the 4 PHY LEDs */
-#define RG_GPIO_MISC_TPBANK0			0x6f0
-#define   RG_GPIO_MISC_TPBANK0_BOOTMODE		GENMASK(11, 8)
-
 /* These macro privides efuse parsing for internal phy. */
 #define EFS_DA_TX_I2MPB_A(x)			(((x) >> 0) & GENMASK(5, 0))
 #define EFS_DA_TX_I2MPB_B(x)			(((x) >> 6) & GENMASK(5, 0))
@@ -355,51 +34,16 @@
 #define EFS_RG_BG_RASEL(x)			(((x) >> 4) & GENMASK(2, 0))
 #define EFS_RG_REXT_TRIM(x)			(((x) >> 7) & GENMASK(5, 0))
 
-enum {
-	NO_PAIR,
-	PAIR_A,
-	PAIR_B,
-	PAIR_C,
-	PAIR_D,
-};
-
-enum calibration_mode {
-	EFUSE_K,
-	SW_K
-};
-
-enum CAL_ITEM {
-	REXT,
-	TX_OFFSET,
-	TX_AMP,
-	TX_R50,
-	TX_VCM
-};
-
-enum CAL_MODE {
-	EFUSE_M,
-	SW_M
-};
-
 struct mtk_socphy_shared {
 	u32			boottrap;
 	struct mtk_socphy_priv	priv[4];
 };
 
-/* One calibration cycle consists of:
- * 1.Set DA_CALIN_FLAG high to start calibration. Keep it high
- *   until AD_CAL_COMP is ready to output calibration result.
- * 2.Wait until DA_CAL_CLK is available.
- * 3.Fetch AD_CAL_COMP_OUT.
- */
-static int cal_cycle(struct phy_device *phydev, int devad,
-		     u32 regnum, u16 mask, u16 cal_val)
+int mtk_cal_cycle_wait(struct phy_device *phydev)
 {
 	int reg_val;
 	int ret;
 
-	phy_modify_mmd(phydev, devad, regnum,
-		       mask, cal_val);
 	phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_AD_CALIN,
 			 MTK_PHY_DA_CALIN_FLAG);
 
@@ -418,7 +62,26 @@ static int cal_cycle(struct phy_device *phydev, int devad,
 	ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_AD_CAL_COMP);
 	if (ret < 0)
 		return ret;
-	ret = FIELD_GET(MTK_PHY_AD_CAL_COMP_OUT_MASK, ret);
+
+	return FIELD_GET(MTK_PHY_AD_CAL_COMP_OUT_MASK, ret);
+}
+EXPORT_SYMBOL_GPL(mtk_cal_cycle_wait);
+
+/* One calibration cycle consists of:
+ * 1.Set DA_CALIN_FLAG high to start calibration. Keep it high
+ *   until AD_CAL_COMP is ready to output calibration result.
+ * 2.Wait until DA_CAL_CLK is available.
+ * 3.Fetch AD_CAL_COMP_OUT.
+ */
+static int cal_cycle(struct phy_device *phydev, int devad,
+		     u32 regnum, u16 mask, u16 cal_val)
+{
+	int ret;
+
+	phy_modify_mmd(phydev, devad, regnum,
+		       mask, cal_val);
+
+	ret = mtk_cal_cycle_wait(phydev);
 	phydev_dbg(phydev, "cal_val: 0x%x, ret: %d\n", cal_val, ret);
 
 	return ret;
@@ -1224,73 +887,6 @@ static int mt798x_phy_config_init(struct phy_device *phydev)
 	return mt798x_phy_calibration(phydev);
 }
 
-static int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,
-				    unsigned long *delay_on,
-				    unsigned long *delay_off)
-{
-	bool blinking = false;
-	int err;
-
-	err = mtk_phy_led_num_dly_cfg(index, delay_on, delay_off, &blinking);
-	if (err < 0)
-		return err;
-
-	err = mtk_phy_hw_led_blink_set(phydev, index, blinking);
-	if (err)
-		return err;
-
-	return mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,
-				     false);
-}
-
-static int mt798x_phy_led_brightness_set(struct phy_device *phydev,
-					 u8 index, enum led_brightness value)
-{
-	int err;
-
-	err = mtk_phy_hw_led_blink_set(phydev, index, false);
-	if (err)
-		return err;
-
-	return mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,
-				     (value != LED_OFF));
-}
-
-static const unsigned long supported_triggers =
-	BIT(TRIGGER_NETDEV_FULL_DUPLEX) |
-	BIT(TRIGGER_NETDEV_HALF_DUPLEX) |
-	BIT(TRIGGER_NETDEV_LINK)        |
-	BIT(TRIGGER_NETDEV_LINK_10)     |
-	BIT(TRIGGER_NETDEV_LINK_100)    |
-	BIT(TRIGGER_NETDEV_LINK_1000)   |
-	BIT(TRIGGER_NETDEV_RX)          |
-	BIT(TRIGGER_NETDEV_TX);
-
-static int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,
-					  unsigned long rules)
-{
-	return mtk_phy_led_hw_is_supported(phydev, index, rules,
-					   supported_triggers);
-}
-
-static int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,
-					 unsigned long *rules)
-{
-	return mtk_phy_led_hw_ctrl_get(phydev, index, rules,
-				       MTK_GPHY_LED_ON_SET,
-				       MTK_GPHY_LED_RX_BLINK_SET,
-				       MTK_GPHY_LED_TX_BLINK_SET);
-};
-
-static int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,
-					 unsigned long rules)
-{
-	return mtk_phy_led_hw_ctrl_set(phydev, index, rules,
-				       MTK_GPHY_LED_ON_SET,
-				       MTK_GPHY_LED_RX_BLINK_SET,
-				       MTK_GPHY_LED_TX_BLINK_SET);
-};
-
 static bool mt7988_phy_led_get_polarity(struct phy_device *phydev, int led_num)
 {
 	struct mtk_socphy_shared *priv = phy_package_get_priv(phydev);
@@ -1427,71 +1023,6 @@ static int mt7981_phy_probe(struct phy_device *phydev)
 	return mt798x_phy_calibration(phydev);
 }
 
-static int an7581_phy_probe(struct phy_device *phydev)
-{
-	struct mtk_socphy_priv *priv;
-	struct pinctrl *pinctrl;
-
-	/* Toggle pinctrl to enable PHY LED */
-	pinctrl = devm_pinctrl_get_select(&phydev->mdio.dev, "gbe-led");
-	if (IS_ERR(pinctrl))
-		dev_err(&phydev->mdio.bus->dev,
-			"Failed to setup PHY LED pinctrl\n");
-
-	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-
-	phydev->priv = priv;
-
-	return 0;
-}
-
-static int an7581_phy_led_polarity_set(struct phy_device *phydev, int index,
-				       unsigned long modes)
-{
-	u16 val = 0;
-	u32 mode;
-
-	if (index >= MTK_PHY_MAX_LEDS)
-		return -EINVAL;
-
-	for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
-		switch (mode) {
-		case PHY_LED_ACTIVE_LOW:
-			val = MTK_PHY_LED_ON_POLARITY;
-			break;
-		case PHY_LED_ACTIVE_HIGH:
-			break;
-		default:
-			return -EINVAL;
-		}
-	}
-
-	return phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ?
-			      MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL,
-			      MTK_PHY_LED_ON_POLARITY, val);
-}
-
-static int an7583_phy_config_init(struct phy_device *phydev)
-{
-	/* BMCR_PDOWN is enabled by default */
-	return phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);
-}
-
-static int en7528_phy_config_init(struct phy_device *phydev)
-{
-	/* The LED controller of the EN7528 powers up with its external
-	 * control disabled, leaving the LED pins dark regardless of what is
-	 * programmed into the LED control registers. Hand the pins over to
-	 * the LED control registers the same way the air_en8811h driver
-	 * does; the mode field of this register is already set out of reset.
-	 */
-	return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED_BCR,
-				MTK_PHY_LED_BCR_CLK_EN |
-				MTK_PHY_LED_BCR_EXT_CTRL);
-}
-
 static struct phy_driver mtk_socphy_driver[] = {
 	{
 		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981),
@@ -1527,43 +1058,6 @@ static struct phy_driver mtk_socphy_driver[] = {
 		.led_hw_control_set = mt798x_phy_led_hw_control_set,
 		.led_hw_control_get = mt798x_phy_led_hw_control_get,
 	},
-	{
-		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_EN7528),
-		.name		= "EcoNet EN7528 PHY",
-		.config_init	= en7528_phy_config_init,
-		.probe		= an7581_phy_probe,
-		.led_blink_set	= mt798x_phy_led_blink_set,
-		.led_brightness_set = mt798x_phy_led_brightness_set,
-		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
-		.led_hw_control_set = mt798x_phy_led_hw_control_set,
-		.led_hw_control_get = mt798x_phy_led_hw_control_get,
-		.led_polarity_set = an7581_phy_led_polarity_set,
-	},
-	{
-		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7581),
-		.name		= "Airoha AN7581 PHY",
-		.config_intr	= genphy_no_config_intr,
-		.handle_interrupt = genphy_handle_interrupt_no_ack,
-		.probe		= an7581_phy_probe,
-		.led_blink_set	= mt798x_phy_led_blink_set,
-		.led_brightness_set = mt798x_phy_led_brightness_set,
-		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
-		.led_hw_control_set = mt798x_phy_led_hw_control_set,
-		.led_hw_control_get = mt798x_phy_led_hw_control_get,
-		.led_polarity_set = an7581_phy_led_polarity_set,
-	},
-	{
-		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7583),
-		.name		= "Airoha AN7583 PHY",
-		.config_init	= an7583_phy_config_init,
-		.probe		= an7581_phy_probe,
-		.led_blink_set	= mt798x_phy_led_blink_set,
-		.led_brightness_set = mt798x_phy_led_brightness_set,
-		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
-		.led_hw_control_set = mt798x_phy_led_hw_control_set,
-		.led_hw_control_get = mt798x_phy_led_hw_control_get,
-		.led_polarity_set = an7581_phy_led_polarity_set,
-	},
 };
 
 module_phy_driver(mtk_socphy_driver);
@@ -1571,9 +1065,6 @@ module_phy_driver(mtk_socphy_driver);
 static const struct mdio_device_id __maybe_unused mtk_socphy_tbl[] = {
 	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981) },
 	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7988) },
-	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_EN7528) },
-	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7581) },
-	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_AN7583) },
 	{ }
 };
 
diff --git a/drivers/net/phy/mediatek/mtk-ge-soc.h b/drivers/net/phy/mediatek/mtk-ge-soc.h
new file mode 100644
index 00000000000000..d6baff245deaea
--- /dev/null
+++ b/drivers/net/phy/mediatek/mtk-ge-soc.h
@@ -0,0 +1,377 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _MTK_GE_SOC_H_
+#define _MTK_GE_SOC_H_
+
+#include <linux/bitfield.h>
+
+#define MTK_GPHY_ID_MT7981			0x03a29461
+#define MTK_GPHY_ID_MT7988			0x03a29481
+#define AIROHA_GPHY_ID_EN7528			0x03a29491
+#define AIROHA_GPHY_ID_AN7581			0x03a294c1
+#define AIROHA_GPHY_ID_AN7583			0xc0ff0420
+
+#define MTK_EXT_PAGE_ACCESS			0x1f
+#define MTK_PHY_PAGE_STANDARD			0x0000
+#define MTK_PHY_PAGE_EXTENDED_1			0x0001
+#define MTK_PHY_PAGE_EXTENDED_3			0x0003
+
+#define MTK_PHY_LPI_REG_14			0x14
+#define MTK_PHY_LPI_WAKE_TIMER_1000_MASK	GENMASK(8, 0)
+
+#define MTK_PHY_LPI_REG_1c			0x1c
+#define MTK_PHY_SMI_DET_ON_THRESH_MASK		GENMASK(13, 8)
+
+#define MTK_PHY_PAGE_EXTENDED_2A30		0x2a30
+
+/* Registers on Token Ring debug nodes */
+/* ch_addr = 0x0, node_addr = 0x7, data_addr = 0x15 */
+/* NormMseLoThresh */
+#define NORMAL_MSE_LO_THRESH_MASK		GENMASK(15, 8)
+
+/* ch_addr = 0x0, node_addr = 0xf, data_addr = 0x3c */
+/* RemAckCntLimitCtrl */
+#define REMOTE_ACK_COUNT_LIMIT_CTRL_MASK	GENMASK(2, 1)
+
+/* ch_addr = 0x1, node_addr = 0xd, data_addr = 0x20 */
+/* VcoSlicerThreshBitsHigh */
+#define VCO_SLICER_THRESH_HIGH_MASK		GENMASK(23, 0)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x0 */
+/* DfeTailEnableVgaThresh1000 */
+#define DFE_TAIL_EANBLE_VGA_TRHESH_1000		GENMASK(5, 1)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x1 */
+/* MrvlTrFix100Kp */
+#define MRVL_TR_FIX_100KP_MASK			GENMASK(22, 20)
+/* MrvlTrFix100Kf */
+#define MRVL_TR_FIX_100KF_MASK			GENMASK(19, 17)
+/* MrvlTrFix1000Kp */
+#define MRVL_TR_FIX_1000KP_MASK			GENMASK(16, 14)
+/* MrvlTrFix1000Kf */
+#define MRVL_TR_FIX_1000KF_MASK			GENMASK(13, 11)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x12 */
+/* VgaDecRate */
+#define VGA_DECIMATION_RATE_MASK		GENMASK(8, 5)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x17 */
+/* SlvDSPreadyTime */
+#define SLAVE_DSP_READY_TIME_MASK		GENMASK(22, 15)
+/* MasDSPreadyTime */
+#define MASTER_DSP_READY_TIME_MASK		GENMASK(14, 7)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x18 */
+/* EnabRandUpdTrig */
+#define ENABLE_RANDOM_UPDOWN_COUNTER_TRIGGER	BIT(8)
+
+/* ch_addr = 0x1, node_addr = 0xf, data_addr = 0x20 */
+/* ResetSyncOffset */
+#define RESET_SYNC_OFFSET_MASK			GENMASK(11, 8)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x0 */
+/* FfeUpdGainForceVal */
+#define FFE_UPDATE_GAIN_FORCE_VAL_MASK		GENMASK(9, 7)
+/* FfeUpdGainForce */
+#define FFE_UPDATE_GAIN_FORCE			BIT(6)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x3 */
+/* TrFreeze */
+#define TR_FREEZE_MASK				GENMASK(11, 0)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x6 */
+/* SS: Steady-state, KP: Proportional Gain */
+/* SSTrKp100 */
+#define SS_TR_KP100_MASK			GENMASK(21, 19)
+/* SSTrKf100 */
+#define SS_TR_KF100_MASK			GENMASK(18, 16)
+/* SSTrKp1000Mas */
+#define SS_TR_KP1000_MASTER_MASK		GENMASK(15, 13)
+/* SSTrKf1000Mas */
+#define SS_TR_KF1000_MASTER_MASK		GENMASK(12, 10)
+/* SSTrKp1000Slv */
+#define SS_TR_KP1000_SLAVE_MASK			GENMASK(9, 7)
+/* SSTrKf1000Slv */
+#define SS_TR_KF1000_SLAVE_MASK			GENMASK(6, 4)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x8 */
+/* clear this bit if wanna select from AFE */
+/* Regsigdet_sel_1000 */
+#define EEE1000_SELECT_SIGNAL_DETECTION_FROM_DFE	BIT(4)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xd */
+/* RegEEE_st2TrKf1000 */
+#define EEE1000_STAGE2_TR_KF_MASK		GENMASK(13, 11)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0xf */
+/* RegEEE_slv_waketr_timer_tar */
+#define SLAVE_WAKETR_TIMER_MASK			GENMASK(20, 11)
+/* RegEEE_slv_remtx_timer_tar */
+#define SLAVE_REMTX_TIMER_MASK			GENMASK(10, 1)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x10 */
+/* RegEEE_slv_wake_int_timer_tar */
+#define SLAVE_WAKEINT_TIMER_MASK		GENMASK(10, 1)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x14 */
+/* RegEEE_trfreeze_timer2 */
+#define TR_FREEZE_TIMER2_MASK			GENMASK(9, 0)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x1c */
+/* RegEEE100Stg1_tar */
+#define EEE100_LPSYNC_STAGE1_UPDATE_TIMER_MASK	GENMASK(8, 0)
+
+/* ch_addr = 0x2, node_addr = 0xd, data_addr = 0x25 */
+/* REGEEE_wake_slv_tr_wait_dfesigdet_en */
+#define WAKE_SLAVE_TR_WAIT_DFE_DETECTION_EN	BIT(11)
+
+#define ANALOG_INTERNAL_OPERATION_MAX_US	20
+#define TXRESERVE_MIN				0
+#define TXRESERVE_MAX				7
+
+#define MTK_PHY_ANARG_RG			0x10
+#define   MTK_PHY_TCLKOFFSET_MASK		GENMASK(12, 8)
+
+/* Registers on MDIO_MMD_VEND1 */
+#define MTK_PHY_TXVLD_DA_RG			0x12
+#define   MTK_PHY_DA_TX_I2MPB_A_GBE_MASK	GENMASK(15, 10)
+#define   MTK_PHY_DA_TX_I2MPB_A_TBT_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_A2		0x16
+#define   MTK_PHY_DA_TX_I2MPB_A_HBT_MASK	GENMASK(15, 10)
+#define   MTK_PHY_DA_TX_I2MPB_A_TST_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_B1		0x17
+#define   MTK_PHY_DA_TX_I2MPB_B_GBE_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_B_TBT_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_B2		0x18
+#define   MTK_PHY_DA_TX_I2MPB_B_HBT_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_B_TST_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_C1		0x19
+#define   MTK_PHY_DA_TX_I2MPB_C_GBE_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_C_TBT_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_C2		0x20
+#define   MTK_PHY_DA_TX_I2MPB_C_HBT_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_C_TST_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_D1		0x21
+#define   MTK_PHY_DA_TX_I2MPB_D_GBE_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_D_TBT_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_TX_I2MPB_TEST_MODE_D2		0x22
+#define   MTK_PHY_DA_TX_I2MPB_D_HBT_MASK	GENMASK(13, 8)
+#define   MTK_PHY_DA_TX_I2MPB_D_TST_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_RXADC_CTRL_RG7			0xc6
+#define   MTK_PHY_DA_AD_BUF_BIAS_LP_MASK	GENMASK(9, 8)
+
+#define MTK_PHY_RXADC_CTRL_RG9			0xc8
+#define   MTK_PHY_DA_RX_PSBN_TBT_MASK		GENMASK(14, 12)
+#define   MTK_PHY_DA_RX_PSBN_HBT_MASK		GENMASK(10, 8)
+#define   MTK_PHY_DA_RX_PSBN_GBE_MASK		GENMASK(6, 4)
+#define   MTK_PHY_DA_RX_PSBN_LP_MASK		GENMASK(2, 0)
+
+#define MTK_PHY_LDO_OUTPUT_V			0xd7
+
+#define MTK_PHY_RG_ANA_CAL_RG0			0xdb
+#define   MTK_PHY_RG_CAL_CKINV			BIT(12)
+#define   MTK_PHY_RG_ANA_CALEN			BIT(8)
+#define   MTK_PHY_RG_REXT_CALEN			BIT(4)
+#define   MTK_PHY_RG_ZCALEN_A			BIT(0)
+
+#define MTK_PHY_RG_ANA_CAL_RG1			0xdc
+#define   MTK_PHY_RG_ZCALEN_B			BIT(12)
+#define   MTK_PHY_RG_ZCALEN_C			BIT(8)
+#define   MTK_PHY_RG_ZCALEN_D			BIT(4)
+#define   MTK_PHY_RG_TXVOS_CALEN		BIT(0)
+
+#define MTK_PHY_RG_ANA_CAL_RG5			0xe0
+#define   MTK_PHY_RG_REXT_TRIM_MASK		GENMASK(13, 8)
+#define   MTK_PHY_RG_REXT_ZCAL_CTRL_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_RG_ANA_CAL_RG6			0xe1
+
+#define MTK_PHY_RG_TX_FILTER			0xfe
+
+#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG120	0x120
+#define   MTK_PHY_LPI_SIG_EN_LO_THRESH1000_MASK	GENMASK(12, 8)
+#define   MTK_PHY_LPI_SIG_EN_HI_THRESH1000_MASK	GENMASK(4, 0)
+
+#define MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG122	0x122
+#define   MTK_PHY_LPI_NORM_MSE_HI_THRESH1000_MASK	GENMASK(7, 0)
+
+#define MTK_PHY_RG_TESTMUX_ADC_CTRL		0x144
+#define   MTK_PHY_RG_TXEN_DIG_MASK		GENMASK(5, 5)
+
+#define MTK_PHY_RG_CR_TX_AMP_OFFSET_A_B		0x172
+#define   MTK_PHY_CR_TX_AMP_OFFSET_A_MASK	GENMASK(13, 8)
+#define   MTK_PHY_CR_TX_AMP_OFFSET_B_MASK	GENMASK(6, 0)
+#define   AIROHA_PHY_CR_TX_AMP_OFFSET_B_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_RG_CR_TX_AMP_OFFSET_C_D		0x173
+#define   MTK_PHY_CR_TX_AMP_OFFSET_C_MASK	GENMASK(13, 8)
+#define   MTK_PHY_CR_TX_AMP_OFFSET_D_MASK	GENMASK(6, 0)
+#define   AIROHA_PHY_CR_TX_AMP_OFFSET_D_MASK	GENMASK(5, 0)
+
+#define MTK_PHY_RG_CR_TX_R50_OFFSET_A_B		0x174
+#define   MTK_PHY_CR_TX_R50_OFFSET_A_MASK	GENMASK(13, 8)
+#define   AIROHA_PHY_CR_TX_R50_OFFSET_A_MASK	GENMASK(14, 8)
+#define   MTK_PHY_CR_TX_R50_OFFSET_B_MASK	GENMASK(6, 0)
+
+#define MTK_PHY_RG_CR_TX_R50_OFFSET_C_D		0x175
+#define   MTK_PHY_CR_TX_R50_OFFSET_C_MASK	GENMASK(13, 8)
+#define   AIROHA_PHY_CR_TX_R50_OFFSET_C_MASK	GENMASK(14, 8)
+#define   MTK_PHY_CR_TX_R50_OFFSET_D_MASK	GENMASK(6, 0)
+
+#define MTK_PHY_RG_AD_CAL_COMP			0x17a
+#define   MTK_PHY_AD_CAL_COMP_OUT_MASK		GENMASK(8, 8)
+
+#define MTK_PHY_RG_AD_CAL_CLK			0x17b
+#define   MTK_PHY_DA_CAL_CLK			BIT(0)
+
+#define MTK_PHY_RG_AD_CALIN			0x17c
+#define   MTK_PHY_DA_CALIN_FLAG			BIT(0)
+
+#define MTK_PHY_RG_DASN_DAC_IN0_A		0x17d
+#define   MTK_PHY_DASN_DAC_IN0_A_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN0_B		0x17e
+#define   MTK_PHY_DASN_DAC_IN0_B_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN0_C		0x17f
+#define   MTK_PHY_DASN_DAC_IN0_C_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN0_D		0x180
+#define   MTK_PHY_DASN_DAC_IN0_D_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN1_A		0x181
+#define   MTK_PHY_DASN_DAC_IN1_A_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN1_B		0x182
+#define   MTK_PHY_DASN_DAC_IN1_B_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN1_C		0x183
+#define   MTK_PHY_DASN_DAC_IN1_C_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DASN_DAC_IN1_D		0x184
+#define   MTK_PHY_DASN_DAC_IN1_D_MASK		GENMASK(9, 0)
+
+#define MTK_PHY_RG_DEV1E_REG19b			0x19b
+#define   MTK_PHY_BYPASS_DSP_LPI_READY		BIT(8)
+
+#define MTK_PHY_RG_LP_IIR2_K1_L			0x22a
+#define MTK_PHY_RG_LP_IIR2_K1_U			0x22b
+#define MTK_PHY_RG_LP_IIR2_K2_L			0x22c
+#define MTK_PHY_RG_LP_IIR2_K2_U			0x22d
+#define MTK_PHY_RG_LP_IIR2_K3_L			0x22e
+#define MTK_PHY_RG_LP_IIR2_K3_U			0x22f
+#define MTK_PHY_RG_LP_IIR2_K4_L			0x230
+#define MTK_PHY_RG_LP_IIR2_K4_U			0x231
+#define MTK_PHY_RG_LP_IIR2_K5_L			0x232
+#define MTK_PHY_RG_LP_IIR2_K5_U			0x233
+
+#define MTK_PHY_RG_DEV1E_REG234			0x234
+#define   MTK_PHY_TR_OPEN_LOOP_EN_MASK		GENMASK(0, 0)
+#define   MTK_PHY_LPF_X_AVERAGE_MASK		GENMASK(7, 4)
+#define   MTK_PHY_TR_LP_IIR_EEE_EN		BIT(12)
+
+#define MTK_PHY_RG_LPF_CNT_VAL			0x235
+
+#define MTK_PHY_RG_DEV1E_REG238			0x238
+#define   MTK_PHY_LPI_SLV_SEND_TX_TIMER_MASK	GENMASK(8, 0)
+#define   MTK_PHY_LPI_SLV_SEND_TX_EN		BIT(12)
+
+#define MTK_PHY_RG_DEV1E_REG239			0x239
+#define   MTK_PHY_LPI_SEND_LOC_TIMER_MASK	GENMASK(8, 0)
+#define   MTK_PHY_LPI_TXPCS_LOC_RCV		BIT(12)
+
+#define MTK_PHY_RG_DEV1E_REG27C			0x27c
+#define   MTK_PHY_VGASTATE_FFE_THR_ST1_MASK	GENMASK(12, 8)
+#define MTK_PHY_RG_DEV1E_REG27D			0x27d
+#define   MTK_PHY_VGASTATE_FFE_THR_ST2_MASK	GENMASK(4, 0)
+
+#define MTK_PHY_RG_DEV1E_REG2C7			0x2c7
+#define   MTK_PHY_MAX_GAIN_MASK			GENMASK(4, 0)
+#define   MTK_PHY_MIN_GAIN_MASK			GENMASK(12, 8)
+
+#define MTK_PHY_RG_DEV1E_REG2D1			0x2d1
+#define   MTK_PHY_VCO_SLICER_THRESH_BITS_HIGH_EEE_MASK	GENMASK(7, 0)
+#define   MTK_PHY_LPI_SKIP_SD_SLV_TR		BIT(8)
+#define   MTK_PHY_LPI_TR_READY			BIT(9)
+#define   MTK_PHY_LPI_VCO_EEE_STG0_EN		BIT(10)
+
+#define MTK_PHY_RG_DEV1E_REG323			0x323
+#define   MTK_PHY_EEE_WAKE_MAS_INT_DC		BIT(0)
+#define   MTK_PHY_EEE_WAKE_SLV_INT_DC		BIT(4)
+
+#define MTK_PHY_RG_DEV1E_REG324			0x324
+#define   MTK_PHY_SMI_DETCNT_MAX_MASK		GENMASK(5, 0)
+#define   MTK_PHY_SMI_DET_MAX_EN		BIT(8)
+
+#define MTK_PHY_RG_DEV1E_REG326			0x326
+#define   MTK_PHY_LPI_MODE_SD_ON		BIT(0)
+#define   MTK_PHY_RESET_RANDUPD_CNT		BIT(1)
+#define   MTK_PHY_TREC_UPDATE_ENAB_CLR		BIT(2)
+#define   MTK_PHY_LPI_QUIT_WAIT_DFE_SIG_DET_OFF	BIT(4)
+#define   MTK_PHY_TR_READY_SKIP_AFE_WAKEUP	BIT(5)
+
+#define MTK_PHY_LDO_PUMP_EN_PAIRAB		0x502
+#define MTK_PHY_LDO_PUMP_EN_PAIRCD		0x503
+
+#define MTK_PHY_DA_TX_R50_PAIR_A		0x53d
+#define MTK_PHY_DA_TX_R50_PAIR_B		0x53e
+#define MTK_PHY_DA_TX_R50_PAIR_C		0x53f
+#define MTK_PHY_DA_TX_R50_PAIR_D		0x540
+
+/* Registers on MDIO_MMD_VEND2 */
+#define MTK_PHY_LED1_DEFAULT_POLARITIES		BIT(1)
+
+/* LED basic control register, part of the same LED block as the LED0/LED1
+ * control registers above. The air_en8811h driver describes the same
+ * register as AIR_PHY_LED_BCR.
+ */
+#define MTK_PHY_LED_BCR				0x21
+#define   MTK_PHY_LED_BCR_CLK_EN		BIT(3)
+#define   MTK_PHY_LED_BCR_EXT_CTRL		BIT(15)
+
+#define MTK_PHY_RG_BG_RASEL			0x115
+#define   MTK_PHY_RG_BG_RASEL_MASK		GENMASK(2, 0)
+
+/* 'boottrap' register reflecting the configuration of the 4 PHY LEDs */
+#define RG_GPIO_MISC_TPBANK0			0x6f0
+#define   RG_GPIO_MISC_TPBANK0_BOOTMODE		GENMASK(11, 8)
+
+enum CAL_ITEM {
+	REXT,
+	TX_OFFSET,
+	TX_AMP,
+	TX_R50,
+	TX_VCM,
+	RX_OFFSET,
+};
+
+enum {
+	NO_PAIR,
+	PAIR_A,
+	PAIR_B,
+	PAIR_C,
+	PAIR_D,
+};
+
+enum calibration_mode {
+	EFUSE_K,
+	SW_K
+};
+
+enum CAL_MODE {
+	EFUSE_M,
+	SW_M
+};
+
+/* MTK GE SoC common functions */
+int mtk_cal_cycle_wait(struct phy_device *phydev);
+
+#endif /* _MTK_GE_SOC_H_ */
diff --git a/drivers/net/phy/mediatek/mtk-phy-lib.c b/drivers/net/phy/mediatek/mtk-phy-lib.c
index 4c4eca870bde1c..dc4abd95d73fc7 100644
--- a/drivers/net/phy/mediatek/mtk-phy-lib.c
+++ b/drivers/net/phy/mediatek/mtk-phy-lib.c
@@ -36,8 +36,8 @@ static void __mtk_tr_read(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
 		*tr_high, *tr_low);
 }
 
-static void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
-			   u8 data_addr, u32 tr_data)
+void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
+		    u8 data_addr, u32 tr_data)
 {
 	__phy_write(phydev, 0x11, tr_data & 0xffff);
 	__phy_write(phydev, 0x12, tr_data >> 16);
@@ -45,6 +45,7 @@ static void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
 		tr_data >> 16, tr_data & 0xffff);
 	__mtk_tr_access(phydev, false, ch_addr, node_addr, data_addr);
 }
+EXPORT_SYMBOL_GPL(__mtk_tr_write);
 
 void __mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
 		     u8 data_addr, u32 mask, u32 set)
@@ -338,6 +339,78 @@ void mtk_phy_leds_state_init(struct phy_device *phydev)
 }
 EXPORT_SYMBOL_GPL(mtk_phy_leds_state_init);
 
+int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,
+			     unsigned long *delay_on,
+			     unsigned long *delay_off)
+{
+	bool blinking = false;
+	int err;
+
+	err = mtk_phy_led_num_dly_cfg(index, delay_on, delay_off, &blinking);
+	if (err < 0)
+		return err;
+
+	err = mtk_phy_hw_led_blink_set(phydev, index, blinking);
+	if (err)
+		return err;
+
+	return mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,
+				     false);
+}
+EXPORT_SYMBOL_GPL(mt798x_phy_led_blink_set);
+
+int mt798x_phy_led_brightness_set(struct phy_device *phydev,
+				  u8 index, enum led_brightness value)
+{
+	int err;
+
+	err = mtk_phy_hw_led_blink_set(phydev, index, false);
+	if (err)
+		return err;
+
+	return mtk_phy_hw_led_on_set(phydev, index, MTK_GPHY_LED_ON_MASK,
+				     (value != LED_OFF));
+}
+EXPORT_SYMBOL_GPL(mt798x_phy_led_brightness_set);
+
+static const unsigned long supported_triggers =
+	BIT(TRIGGER_NETDEV_FULL_DUPLEX) |
+	BIT(TRIGGER_NETDEV_HALF_DUPLEX) |
+	BIT(TRIGGER_NETDEV_LINK)        |
+	BIT(TRIGGER_NETDEV_LINK_10)     |
+	BIT(TRIGGER_NETDEV_LINK_100)    |
+	BIT(TRIGGER_NETDEV_LINK_1000)   |
+	BIT(TRIGGER_NETDEV_RX)          |
+	BIT(TRIGGER_NETDEV_TX);
+
+int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,
+				   unsigned long rules)
+{
+	return mtk_phy_led_hw_is_supported(phydev, index, rules,
+					   supported_triggers);
+}
+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_is_supported);
+
+int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,
+				  unsigned long *rules)
+{
+	return mtk_phy_led_hw_ctrl_get(phydev, index, rules,
+				       MTK_GPHY_LED_ON_SET,
+				       MTK_GPHY_LED_RX_BLINK_SET,
+				       MTK_GPHY_LED_TX_BLINK_SET);
+};
+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_get);
+
+int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,
+				  unsigned long rules)
+{
+	return mtk_phy_led_hw_ctrl_set(phydev, index, rules,
+				       MTK_GPHY_LED_ON_SET,
+				       MTK_GPHY_LED_RX_BLINK_SET,
+				       MTK_GPHY_LED_TX_BLINK_SET);
+};
+EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_set);
+
 MODULE_DESCRIPTION("MediaTek Ethernet PHY driver common");
 MODULE_AUTHOR("Sky Huang <SkyLake.Huang@mediatek.com>");
 MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
diff --git a/drivers/net/phy/mediatek/mtk.h b/drivers/net/phy/mediatek/mtk.h
index 79e09727b81bcc..608e5e3d754f9a 100644
--- a/drivers/net/phy/mediatek/mtk.h
+++ b/drivers/net/phy/mediatek/mtk.h
@@ -13,6 +13,7 @@
 
 #define MTK_EXT_PAGE_ACCESS			0x1f
 #define MTK_PHY_PAGE_EXTENDED_1			0x0001
+#define MTK_PHY_PAGE_EXTENDED_3			0x0003
 #define MTK_PHY_PAGE_STANDARD			0x0000
 #define MTK_PHY_PAGE_EXTENDED_52B5		0x52b5
 
@@ -72,6 +73,8 @@ struct mtk_socphy_priv {
 	unsigned long		led_state;
 };
 
+void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
+		    u8 data_addr, u32 tr_data);
 void __mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
 		     u8 data_addr, u32 mask, u32 set);
 void mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,
@@ -101,4 +104,16 @@ int mtk_phy_hw_led_blink_set(struct phy_device *phydev, u8 index,
 			     bool blinking);
 void mtk_phy_leds_state_init(struct phy_device *phydev);
 
+int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,
+			     unsigned long *delay_on,
+			     unsigned long *delay_off);
+int mt798x_phy_led_brightness_set(struct phy_device *phydev,
+				  u8 index, enum led_brightness value);
+int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,
+				   unsigned long rules);
+int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,
+				  unsigned long *rules);
+int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,
+				  unsigned long rules);
+
 #endif /* _MTK_EPHY_H_ */

3/2 2026/11/06 03:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58909
							output: 36
							thoughts: 2128
						

Thoughts:
**Analysis of the Ethernet PHY Driver Patch Series**

Okay, so I'm looking at this patch series that introduces and modifies drivers related to Ethernet PHYs. My main concern right now is whether this is something that's worth fuzzing given my current architecture, which is amd64. Let's break down what's going on.

First, it looks like there's a new driver being added specifically for Airoha SoC Gigabit Ethernet PHYs. It's called `airoha-ge-soc.c`, and it implements support for PHYs found on the EN7528, AN7581, and AN7583 SoCs. There's also some refactoring going on, extracting common definitions to a header file (`mtk-ge-soc.h`) and moving around some functions between `mtk-ge-soc.c` and a library file called `mtk-phy-lib.c`. I also see some modifications to the Kconfig and Makefile files, which add configuration options and include the new driver in the build process.

The crucial question is, can I even *reach* this code on an amd64 system in QEMU? Looking at the Kconfig, the `AIROHA_GE_SOC_PHY` configuration depends on `ARM64`, `ECONET`, or `COMPILE_TEST`, and also depends on `ARCH_AIROHA` or `ECONET`. The critical issue here is that `ARCH_AIROHA` points to ARM architecture. This driver is designed for Airoha or Econet SoCs with built-in Ethernet PHYs. These are ARM-based, not x86. So, unless `COMPILE_TEST` somehow allows me to emulate it, there is no way this can be reached on amd64. Even with `COMPILE_TEST` set, do I have the Airoha hardware available in QEMU?

This driver registers a PHY driver using `module_phy_driver`. In Linux, the phylib framework uses the MDIO bus to scan for PHYs. Then, it binds the driver based on device ID or Device Tree. Can I even *create* a MDIO bus or attach a PHY in my amd64 environment with Syzkaller, or is this all tied to specific hardware? Syzkaller doesn't appear to have any built-in MDIO bus emulation, and I need to check to see if this is possible. I need to figure out if there is some kind of a virtual MDIO bus or if these Ethernet PHYs are instantiated through some other mechanism.

Now, looking at the code, it seems like `mtk-ge-soc.c` deals with MediaTek Filogic SoCs (like MT7981, MT7988) while `airoha-ge-soc.c` deals with Airoha/EcoNet SoCs. The common code is being refactored into `mtk-phy-lib.c`. Specifically, functions like `mtk_cal_cycle_wait` have been exposed. More importantly, functions like `an7581_phy_probe`, `an7581_phy_led_polarity_set`, `an7583_phy_config_init`, `en7528_phy_config_init` which were in `mtk-ge-soc.c` have been removed to `airoha-ge-soc.c`.

Again, the million-dollar question is: can *any* of this ever be instantiated or run on amd64 in QEMU, or is it completely tied to specific SoC hardware? I need to check if there are any callers or uses of these drivers outside of the intended hardware. I need to `grep` the kernel sources. Based on the instructions, since this code seems dependent on SoC hardware and likely not available on an amd64 environment, this is likely not worth fuzzing.



4/2 2026/11/06 03:04 tool grepper
0m Args:
{
  "Expression": "AIROHA_GPHY_ID|MTK_GPHY_ID|airoha_socphy"
}

Results:
{
  "Output": "drivers/net/phy/mediatek/airoha-ge-soc.c=27=enum airoha_calib_const_type {\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-47-\ndrivers/net/phy/mediatek/airoha-ge-soc.c:48:struct airoha_socphy_shared {\ndrivers/net/phy/mediatek/airoha-ge-soc.c-49-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=263=static int airoha_cal_cycle(struct phy_device *phydev, int devad,\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-265-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:266:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-267-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=355=static int airoha_tx_offset_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-356-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:357:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-358-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=500=static int airoha_tx_amp_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-501-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:502:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-503-\tu16 mask_gbe, mask_tbt, mask_tst, mask_hbt;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=681=static int airoha_tx_r50_cal_sw(struct phy_device *phydev, u8 txg_calen_x)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-682-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:683:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-684-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=842=static int airoha_rx_offset_cal_sw(struct phy_device *phydev)\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-876-\ndrivers/net/phy/mediatek/airoha-ge-soc.c:877:\tif (phydev-\u003edrv-\u003ephy_id == AIROHA_GPHY_ID_AN7581)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-878-\t\tphy_write_mmd(phydev, MDIO_MMD_VEND1,\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=938=static int airoha_phy_calib(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-939-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:940:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-941-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=985=static int airoha_phy_auto_select_transformer(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-986-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:987:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-988-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1118=static int airoha_phy_tx_amp_compensation(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1119-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1120:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1121-\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1385=static int an7581_phy_package_config_init_once(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1386-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1387:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1388-\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1402=static int an7581_phy_config_init(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1403-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1404:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1405-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1612=static int an7581_phy_probe(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1613-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1614:\tstruct airoha_socphy_shared *shared;\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1615-\tstruct mtk_socphy_priv *priv;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1625-\tret = devm_phy_package_join(\u0026phydev-\u003emdio.dev, phydev, 0,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1626:\t\t\t\t    sizeof(struct airoha_socphy_shared));\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1627-\tif (ret)\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1692=static int an7583_phy_package_config_init_once(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1693-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1694:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1695-\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1708=static int an7583_phy_config_init(struct phy_device *phydev)\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1709-{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1710:\tstruct airoha_socphy_shared *shared = phy_package_get_priv(phydev);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1711-\tstruct phy_device *phydev_p0;\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1823=static struct phy_driver mtk_socphy_driver[] = {\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1824-\t{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1825:\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528),\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1826-\t\t.name\t\t= \"EcoNet EN7528 PHY\",\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1836-\t{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1837:\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581),\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1838-\t\t.name\t\t= \"Airoha AN7581 PHY\",\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1852-\t{\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1853:\t\tPHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583),\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1854-\t\t.name\t\t= \"Airoha AN7583 PHY\",\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1868=module_phy_driver(mtk_socphy_driver);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1869-\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1870:static const struct mdio_device_id __maybe_unused airoha_socphy_tbl[] = {\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1871:\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_EN7528) },\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1872:\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581) },\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1873:\t{ PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7583) },\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1874-\t{ }\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1880=MODULE_VERSION(\"01.01.20260306\");\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1881-\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1882:MODULE_DEVICE_TABLE(mdio, airoha_socphy_tbl);\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=139=static int tx_amp_fill_result(struct phy_device *phydev, u16 *buf)\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-152-\tswitch (phydev-\u003edrv-\u003ephy_id) {\ndrivers/net/phy/mediatek/mtk-ge-soc.c:153:\tcase MTK_GPHY_ID_MT7981:\ndrivers/net/phy/mediatek/mtk-ge-soc.c-154-\t\t/* We add some calibration to efuse values\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-159-\t\tbreak;\ndrivers/net/phy/mediatek/mtk-ge-soc.c:160:\tcase MTK_GPHY_ID_MT7988:\ndrivers/net/phy/mediatek/mtk-ge-soc.c-161-\t\tmemcpy(bias, (const void *)vals_9481, sizeof(bias));\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=257=static int tx_r50_fill_result(struct phy_device *phydev, u16 tx_r50_cal_val,\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-262-\ndrivers/net/phy/mediatek/mtk-ge-soc.c:263:\tif (phydev-\u003edrv-\u003ephy_id == MTK_GPHY_ID_MT7988)\ndrivers/net/phy/mediatek/mtk-ge-soc.c-264-\t\tbias = -1;\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=873=static int mt798x_phy_config_init(struct phy_device *phydev)\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-875-\tswitch (phydev-\u003edrv-\u003ephy_id) {\ndrivers/net/phy/mediatek/mtk-ge-soc.c:876:\tcase MTK_GPHY_ID_MT7981:\ndrivers/net/phy/mediatek/mtk-ge-soc.c-877-\t\tmt7981_phy_finetune(phydev);\ndrivers/net/phy/mediatek/mtk-ge-soc.c-878-\t\tbreak;\ndrivers/net/phy/mediatek/mtk-ge-soc.c:879:\tcase MTK_GPHY_ID_MT7988:\ndrivers/net/phy/mediatek/mtk-ge-soc.c-880-\t\tmt7988_phy_finetune(phydev);\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=1026=static struct phy_driver mtk_socphy_driver[] = {\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1027-\t{\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1028:\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981),\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1029-\t\t.name\t\t= \"MediaTek MT7981 PHY\",\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1044-\t{\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1045:\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7988),\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1046-\t\t.name\t\t= \"MediaTek MT7988 PHY\",\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=1065=static const struct mdio_device_id __maybe_unused mtk_socphy_tbl[] = {\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1066:\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981) },\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1067:\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7988) },\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1068-\t{ }\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.h-7-\ndrivers/net/phy/mediatek/mtk-ge-soc.h:8:#define MTK_GPHY_ID_MT7981\t\t\t0x03a29461\ndrivers/net/phy/mediatek/mtk-ge-soc.h:9:#define MTK_GPHY_ID_MT7988\t\t\t0x03a29481\ndrivers/net/phy/mediatek/mtk-ge-soc.h:10:#define AIROHA_GPHY_ID_EN7528\t\t\t0x03a29491\ndrivers/net/phy/mediatek/mtk-ge-soc.h:11:#define AIROHA_GPHY_ID_AN7581\t\t\t0x03a294c1\ndrivers/net/phy/mediatek/mtk-ge-soc.h:12:#define AIROHA_GPHY_ID_AN7583\t\t\t0xc0ff0420\ndrivers/net/phy/mediatek/mtk-ge-soc.h-13-\n--\ndrivers/net/phy/mediatek/mtk-ge.c-7-\ndrivers/net/phy/mediatek/mtk-ge.c:8:#define MTK_GPHY_ID_MT7530\t\t0x03a29412\ndrivers/net/phy/mediatek/mtk-ge.c:9:#define MTK_GPHY_ID_MT7531\t\t0x03a29441\ndrivers/net/phy/mediatek/mtk-ge.c-10-\n--\ndrivers/net/phy/mediatek/mtk-ge.c=127=static struct phy_driver mtk_gephy_driver[] = {\ndrivers/net/phy/mediatek/mtk-ge.c-128-\t{\ndrivers/net/phy/mediatek/mtk-ge.c:129:\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530),\ndrivers/net/phy/mediatek/mtk-ge.c-130-\t\t.name\t\t= \"MediaTek MT7530 PHY\",\n--\ndrivers/net/phy/mediatek/mtk-ge.c-143-\t{\ndrivers/net/phy/mediatek/mtk-ge.c:144:\t\tPHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7531),\ndrivers/net/phy/mediatek/mtk-ge.c-145-\t\t.name\t\t= \"MediaTek MT7531 PHY\",\n--\ndrivers/net/phy/mediatek/mtk-ge.c=161=static const struct mdio_device_id __maybe_unused mtk_gephy_tbl[] = {\ndrivers/net/phy/mediatek/mtk-ge.c:162:\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530) },\ndrivers/net/phy/mediatek/mtk-ge.c:163:\t{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7531) },\ndrivers/net/phy/mediatek/mtk-ge.c-164-\t{ }\n"
}

5/2 2026/11/06 03:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66931
							output: 26
							thoughts: 151
						

Thoughts:
**My Linux PHY Driver Breakdown**

Okay, let's refresh my understanding of how PHY drivers function within the Linux kernel. First, I recall that a PHY driver gets itself known to the system via `phy_driver_register` or, for multiple drivers, `phy_drivers_register`, usually invoked through `module_phy_driver`. But how does that driver actually connect to a physical PHY device?

Ah, right, it's the `phy_device`. That gets created when an MDIO bus is registered and subsequently scanned. Or, of course, the device tree can describe child PHY nodes on an MDIO bus, facilitating the connection. Now, where do these MDIO buses originate? Typically, they're found within SoC Ethernet MAC drivers, like those I've seen in files like `airoha_eth.c` and `mtk_eth_soc.c`, or directly through MDIO bus controllers. Time to delve into the code and see which MDIO buses or MAC drivers are the most frequent users of these PHYs.



6/2 2026/11/06 03:05 tool grepper
0m Args:
{
  "Expression": "airoha.*eth|an7581.*eth"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 1540 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (10 files in total):\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:12\nMAINTAINERS:1\narch/arm64/boot/dts/airoha/en7581.dtsi:2\ndrivers/net/ethernet/airoha/Makefile:3\ndrivers/net/ethernet/airoha/airoha_eth.c:316\ndrivers/net/ethernet/airoha/airoha_eth.h:24\ndrivers/net/ethernet/airoha/airoha_npu.c:1\ndrivers/net/ethernet/airoha/airoha_ppe.c:72\ndrivers/net/ethernet/airoha/airoha_ppe_debugfs.c:1\ndrivers/net/wireless/mediatek/mt76/npu.c:1\n\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-3----\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:4:$id: http://devicetree.org/schemas/net/airoha,en7581-eth.yaml#\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-5-$schema: http://devicetree.org/meta-schemas/core.yaml#\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml=16=properties:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-18-    enum:\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:19:      - airoha,en7581-eth\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:20:      - airoha,an7583-eth\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-21-\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml=87=allOf:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-93-            enum:\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:94:              - airoha,en7581-eth\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-95-    then:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-107-            enum:\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:108:              - airoha,an7583-eth\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-109-    then:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml=117=patternProperties:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-125-      compatible:\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:126:        const: airoha,eth-mac\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-127-\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-158-                compatible:\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:159:                  const: airoha,eth-port\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-160-\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml=182=examples:\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-192-      eth: ethernet@1fb50000 {\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:193:        compatible = \"airoha,en7581-eth\";\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-194-        reg = \u003c0 0x1fb50000 0 0x2600\u003e,\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-230-        ethernet@1 {\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:231:          compatible = \"airoha,eth-mac\";\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-232-          reg = \u003c1\u003e;\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-235-        ethernet@4 {\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:236:          compatible = \"airoha,eth-mac\";\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-237-          reg = \u003c4\u003e;\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-242-          ethernet@0 {\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:243:            compatible = \"airoha,eth-port\";\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-244-            reg = \u003c0\u003e;\n--\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-247-          ethernet@1 {\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml:248:            compatible = \"airoha,eth-port\";\nDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml-249-            reg = \u003c1\u003e;\n--\nMAINTAINERS=770=S:\tMaintained\nMAINTAINERS:771:F:\tDocumentation/devicetree/bindings/net/airoha,en7581-eth.yaml\nMAINTAINERS-772-F:\tdrivers/net/ethernet/airoha/\n--\narch/arm64/boot/dts/airoha/en7581.dtsi=350=\t\teth: ethernet@1fb50000 {\narch/arm64/boot/dts/airoha/en7581.dtsi:351:\t\t\tcompatible = \"airoha,en7581-eth\";\narch/arm64/boot/dts/airoha/en7581.dtsi-352-\t\t\treg = \u003c0 0x1fb50000 0 0x2600\u003e,\n--\narch/arm64/boot/dts/airoha/en7581.dtsi=385=\t\t\tgdm1: ethernet@1 {\narch/arm64/boot/dts/airoha/en7581.dtsi:386:\t\t\t\tcompatible = \"airoha,eth-mac\";\narch/arm64/boot/dts/airoha/en7581.dtsi-387-\t\t\t\treg = \u003c1\u003e;\n--\ndrivers/net/ethernet/airoha/Makefile-5-\ndrivers/net/ethernet/airoha/Makefile:6:obj-$(CONFIG_NET_AIROHA) += airoha-eth.o\ndrivers/net/ethernet/airoha/Makefile:7:airoha-eth-y := airoha_eth.o airoha_ppe.o\ndrivers/net/ethernet/airoha/Makefile:8:airoha-eth-$(CONFIG_DEBUG_FS) += airoha_ppe_debugfs.o\ndrivers/net/ethernet/airoha/Makefile-9-obj-$(CONFIG_NET_AIROHA_NPU) += airoha_npu.o\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-19-#include \"airoha_regs.h\"\ndrivers/net/ethernet/airoha/airoha_eth.c:20:#include \"airoha_eth.h\"\ndrivers/net/ethernet/airoha/airoha_eth.c-21-\n--\ndrivers/net/ethernet/airoha/airoha_eth.c=76=static int airoha_set_macaddr(struct airoha_gdm_dev *dev, const u8 *addr)\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-78-\tu8 ref_addr[ETH_ALEN] __aligned(2);\ndrivers/net/ethernet/airoha/airoha_eth.c:79:\tstruct airoha_eth *eth = dev-\u003eeth;\ndrivers/net/ethernet/airoha/airoha_eth.c-80-\tu32 reg, val, lmin, lmax;\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-87-\tfor (i = 0; i \u003c ARRAY_SIZE(eth-\u003eports); i++) {\ndrivers/net/ethernet/airoha/airoha_eth.c:88:\t\tstruct airoha_gdm_port *port = eth-\u003eports[i];\ndrivers/net/ethernet/airoha/airoha_eth.c-89-\t\tint j;\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-137-\tval = (addr[0] \u003c\u003c 16) | (addr[1] \u003c\u003c 8) | addr[2];\ndrivers/net/ethernet/airoha/airoha_eth.c:138:\tairoha_fe_wr(eth, reg, val);\ndrivers/net/ethernet/airoha/airoha_eth.c-139-\ndrivers/net/ethernet/airoha/airoha_eth.c:140:\tairoha_fe_wr(eth, REG_FE_MAC_LMIN(reg), lmin);\ndrivers/net/ethernet/airoha/airoha_eth.c:141:\tairoha_fe_wr(eth, REG_FE_MAC_LMAX(reg), lmax);\ndrivers/net/ethernet/airoha/airoha_eth.c-142-\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-147-\ndrivers/net/ethernet/airoha/airoha_eth.c:148:static void airoha_set_gdm_port_fwd_cfg(struct airoha_eth *eth, u32 addr,\ndrivers/net/ethernet/airoha/airoha_eth.c-149-\t\t\t\t\tu32 val)\ndrivers/net/ethernet/airoha/airoha_eth.c-150-{\ndrivers/net/ethernet/airoha/airoha_eth.c:151:\tairoha_fe_rmw(eth, addr, GDM_OCFQ_MASK,\ndrivers/net/ethernet/airoha/airoha_eth.c-152-\t\t      FIELD_PREP(GDM_OCFQ_MASK, val));\ndrivers/net/ethernet/airoha/airoha_eth.c:153:\tairoha_fe_rmw(eth, addr, GDM_MCFQ_MASK,\ndrivers/net/ethernet/airoha/airoha_eth.c-154-\t\t      FIELD_PREP(GDM_MCFQ_MASK, val));\ndrivers/net/ethernet/airoha/airoha_eth.c:155:\tairoha_fe_rmw(eth, addr, GDM_BCFQ_MASK,\ndrivers/net/ethernet/airoha/airoha_eth.c-156-\t\t      FIELD_PREP(GDM_BCFQ_MASK, val));\ndrivers/net/ethernet/airoha/airoha_eth.c:157:\tairoha_fe_rmw(eth, addr, GDM_UCFQ_MASK,\ndrivers/net/ethernet/airoha/airoha_eth.c-158-\t\t      FIELD_PREP(GDM_UCFQ_MASK, val));\n--\ndrivers/net/ethernet/airoha/airoha_eth.c=161=static int airoha_set_vip_for_gdm_port(struct airoha_gdm_dev *dev, bool enable)\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-163-\tstruct airoha_gdm_port *port = dev-\u003eport;\ndrivers/net/ethernet/airoha/airoha_eth.c:164:\tstruct airoha_eth *eth = dev-\u003eeth;\ndrivers/net/ethernet/airoha/airoha_eth.c-165-\tu32 vip_port;\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-168-\tif (enable) {\ndrivers/net/ethernet/airoha/airoha_eth.c:169:\t\tairoha_fe_set(eth, REG_FE_VIP_PORT_EN, vip_port);\ndrivers/net/ethernet/airoha/airoha_eth.c:170:\t\tairoha_fe_set(eth, REG_FE_IFC_PORT_EN, vip_port);\ndrivers/net/ethernet/airoha/airoha_eth.c-171-\t} else {\ndrivers/net/ethernet/airoha/airoha_eth.c:172:\t\tairoha_fe_clear(eth, REG_FE_VIP_PORT_EN, vip_port);\ndrivers/net/ethernet/airoha/airoha_eth.c:173:\t\tairoha_fe_clear(eth, REG_FE_IFC_PORT_EN, vip_port);\ndrivers/net/ethernet/airoha/airoha_eth.c-174-\t}\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-178-\ndrivers/net/ethernet/airoha/airoha_eth.c:179:static void airoha_fe_maccr_init(struct airoha_eth *eth)\ndrivers/net/ethernet/airoha/airoha_eth.c-180-{\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-183-\tfor (p = 1; p \u003c= ARRAY_SIZE(eth-\u003eports); p++) {\ndrivers/net/ethernet/airoha/airoha_eth.c:184:\t\tairoha_fe_set(eth, REG_GDM_FWD_CFG(p),\ndrivers/net/ethernet/airoha/airoha_eth.c-185-\t\t\t      GDM_TCP_CKSUM_MASK | GDM_UDP_CKSUM_MASK |\ndrivers/net/ethernet/airoha/airoha_eth.c-186-\t\t\t      GDM_IP4_CKSUM_MASK | GDM_DROP_CRC_ERR_MASK);\ndrivers/net/ethernet/airoha/airoha_eth.c:187:\t\tairoha_fe_rmw(eth, REG_GDM_LEN_CFG(p),\ndrivers/net/ethernet/airoha/airoha_eth.c-188-\t\t\t      GDM_SHORT_LEN_MASK | GDM_LONG_LEN_MASK,\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-192-\ndrivers/net/ethernet/airoha/airoha_eth.c:193:\tairoha_fe_rmw(eth, REG_CDM_VLAN_CTRL(1), CDM_VLAN_MASK,\ndrivers/net/ethernet/airoha/airoha_eth.c-194-\t\t      FIELD_PREP(CDM_VLAN_MASK, 0x8100));\ndrivers/net/ethernet/airoha/airoha_eth.c-195-\ndrivers/net/ethernet/airoha/airoha_eth.c:196:\tairoha_fe_set(eth, REG_FE_CPORT_CFG, FE_CPORT_PAD);\ndrivers/net/ethernet/airoha/airoha_eth.c-197-}\ndrivers/net/ethernet/airoha/airoha_eth.c-198-\ndrivers/net/ethernet/airoha/airoha_eth.c:199:static void airoha_fe_vip_setup(struct airoha_eth *eth)\ndrivers/net/ethernet/airoha/airoha_eth.c-200-{\ndrivers/net/ethernet/airoha/airoha_eth.c:201:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(3), ETH_P_PPP_DISC);\ndrivers/net/ethernet/airoha/airoha_eth.c:202:\tairoha_fe_wr(eth, REG_FE_VIP_EN(3), PATN_FCPU_EN_MASK | PATN_EN_MASK);\ndrivers/net/ethernet/airoha/airoha_eth.c-203-\ndrivers/net/ethernet/airoha/airoha_eth.c:204:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(4), PPP_LCP);\ndrivers/net/ethernet/airoha/airoha_eth.c:205:\tairoha_fe_wr(eth, REG_FE_VIP_EN(4),\ndrivers/net/ethernet/airoha/airoha_eth.c-206-\t\t     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-208-\ndrivers/net/ethernet/airoha/airoha_eth.c:209:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(6), PPP_IPCP);\ndrivers/net/ethernet/airoha/airoha_eth.c:210:\tairoha_fe_wr(eth, REG_FE_VIP_EN(6),\ndrivers/net/ethernet/airoha/airoha_eth.c-211-\t\t     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-213-\ndrivers/net/ethernet/airoha/airoha_eth.c:214:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(7), PPP_CHAP);\ndrivers/net/ethernet/airoha/airoha_eth.c:215:\tairoha_fe_wr(eth, REG_FE_VIP_EN(7),\ndrivers/net/ethernet/airoha/airoha_eth.c-216-\t\t     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-219-\t/* BOOTP (0x43) */\ndrivers/net/ethernet/airoha/airoha_eth.c:220:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(8), 0x43);\ndrivers/net/ethernet/airoha/airoha_eth.c:221:\tairoha_fe_wr(eth, REG_FE_VIP_EN(8),\ndrivers/net/ethernet/airoha/airoha_eth.c-222-\t\t     PATN_FCPU_EN_MASK | PATN_SP_EN_MASK |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-225-\t/* BOOTP (0x44) */\ndrivers/net/ethernet/airoha/airoha_eth.c:226:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(9), 0x44);\ndrivers/net/ethernet/airoha/airoha_eth.c:227:\tairoha_fe_wr(eth, REG_FE_VIP_EN(9),\ndrivers/net/ethernet/airoha/airoha_eth.c-228-\t\t     PATN_FCPU_EN_MASK | PATN_SP_EN_MASK |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-231-\t/* ISAKMP */\ndrivers/net/ethernet/airoha/airoha_eth.c:232:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(10), 0x1f401f4);\ndrivers/net/ethernet/airoha/airoha_eth.c:233:\tairoha_fe_wr(eth, REG_FE_VIP_EN(10),\ndrivers/net/ethernet/airoha/airoha_eth.c-234-\t\t     PATN_FCPU_EN_MASK | PATN_DP_EN_MASK | PATN_SP_EN_MASK |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-236-\ndrivers/net/ethernet/airoha/airoha_eth.c:237:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(11), PPP_IPV6CP);\ndrivers/net/ethernet/airoha/airoha_eth.c:238:\tairoha_fe_wr(eth, REG_FE_VIP_EN(11),\ndrivers/net/ethernet/airoha/airoha_eth.c-239-\t\t     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-242-\t/* DHCPv6 */\ndrivers/net/ethernet/airoha/airoha_eth.c:243:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(12), 0x2220223);\ndrivers/net/ethernet/airoha/airoha_eth.c:244:\tairoha_fe_wr(eth, REG_FE_VIP_EN(12),\ndrivers/net/ethernet/airoha/airoha_eth.c-245-\t\t     PATN_FCPU_EN_MASK | PATN_DP_EN_MASK | PATN_SP_EN_MASK |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-247-\ndrivers/net/ethernet/airoha/airoha_eth.c:248:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(19), PPP_PAP);\ndrivers/net/ethernet/airoha/airoha_eth.c:249:\tairoha_fe_wr(eth, REG_FE_VIP_EN(19),\ndrivers/net/ethernet/airoha/airoha_eth.c-250-\t\t     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-253-\t/* ETH-\u003eETH_P_1905 (0x893a) */\ndrivers/net/ethernet/airoha/airoha_eth.c:254:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(20), 0x893a);\ndrivers/net/ethernet/airoha/airoha_eth.c:255:\tairoha_fe_wr(eth, REG_FE_VIP_EN(20),\ndrivers/net/ethernet/airoha/airoha_eth.c-256-\t\t     PATN_FCPU_EN_MASK | PATN_EN_MASK);\ndrivers/net/ethernet/airoha/airoha_eth.c-257-\ndrivers/net/ethernet/airoha/airoha_eth.c:258:\tairoha_fe_wr(eth, REG_FE_VIP_PATN(21), ETH_P_LLDP);\ndrivers/net/ethernet/airoha/airoha_eth.c:259:\tairoha_fe_wr(eth, REG_FE_VIP_EN(21),\ndrivers/net/ethernet/airoha/airoha_eth.c-260-\t\t     PATN_FCPU_EN_MASK | PATN_EN_MASK);\n--\ndrivers/net/ethernet/airoha/airoha_eth.c-262-\ndrivers/net/ethernet/airoha/airoha_eth.c:263:static u32 airoha_fe_get_pse_queue_rsv_pages(struct airoha_eth *eth,\ndrivers/net/ethernet/airoha/airoha_eth.c-264-\t\t\t\t\t     u32 port, u32 queue)\ndrivers/net/ethernet/airoha/airoha_eth.c-265-{\ndrivers/net/ethernet/airoha/airoha_eth.c:266:\tairoha_fe_rmw(eth, REG_FE_PSE_QUEUE_CFG_WR,\n\n"
}

7/2 2026/11/06 03:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 73751
							output: 28
							thoughts: 992
						

Thoughts:
**Fuzzing Feasibility Assessment: `airoha_eth.c`**

Okay, let's break this down. My initial thought is to analyze if fuzzing `airoha_eth.c` is worthwhile. This file lives in `drivers/net/ethernet/airoha/airoha_eth.c`. The system uses the `airoha.en7581.dtsi` file, which is in the `arch/arm64/boot/dts/airoha/en7581.dtsi` directory, indicating it's intended for ARM64 architecture.

Now, what is `AIROHA_GE_SOC_PHY`? I quickly checked the `drivers/net/phy/mediatek/Kconfig` and found that it controls the inclusion of the Airoha SoC Gigabit Ethernet PHY support. It depends on `ARM64 || ECONET || COMPILE_TEST` and `ARCH_AIROHA || ECONET || COMPILE_TEST`. This seems like a potential blocker since my target architecture is amd64.

I need to focus on the negative criteria for determining if this code is worth fuzzing. I need to be *certain* that all modifications fall under one of these categories to return `WorthFuzzing=false`. Specifically, the criteria "Code paths exclusive to architectures other than the target architecture" is what catches my eye.

The code depends on `ARM64 || ECONET || COMPILE_TEST` and `ARCH_AIROHA || ECONET || COMPILE_TEST`, meaning without `COMPILE_TEST`, it wouldn't even be selected on amd64 (x86_64). Even with `COMPILE_TEST`, is it hardware-reachable?

Let's investigate the hardware bindings of this PHY driver. It seems to bind to MDIO PHYs with specific IDs: `AIROHA_GPHY_ID_EN7528 (0x03a29491)`, `AIROHA_GPHY_ID_AN7581 (0x03a294c1)`, and `AIROHA_GPHY_ID_AN7583 (0xc0ff0420)`. These are integrated Ethernet PHYs found on Airoha SoCs (AN7581, AN7583, EN7528).

The crucial question is: can an MDIO PHY driver be reached on an amd64 system emulated with standard QEMU? Considering the available network devices in standard QEMU amd64 (e1000, e1000e, rtl8139, virtio-net, etc.), none of them use MediaTek/Airoha SoC internal PHYs. This means the target architecture is likely an ARM64 SoC (specifically Airoha EN7581 / AN7581 / AN7583), which are network processors and router SoCs. Their PHYs are internal.

But, just to be thorough, could an MDIO device be created dynamically, or via USB? Could there be a USB MDIO adapter? I'll do a quick search in `drivers/net/usb` for "mdio".

My conclusion? Based on the dependency on ARM64 or ECONET, and the fact that these are SoC-internal PHYs not present in standard QEMU amd64, I'm leaning heavily towards *not* fuzzing this code. It appears to fall under the "Code paths exclusive to architectures other than the target architecture" negative criterion. It is highly unlikely this is hardware-reachable on an amd64 system in standard QEMU.



8/2 2026/11/06 03:05 tool grepper
0m Args:
{
  "Expression": "mdio",
  "PathPrefixes": [
    "drivers/net/usb"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 1118 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (17 files in total):\ndrivers/net/usb/aqc111.c:1\ndrivers/net/usb/asix.h:7\ndrivers/net/usb/asix_common.c:16\ndrivers/net/usb/asix_devices.c:56\ndrivers/net/usb/ax88172a.c:19\ndrivers/net/usb/ax88179_178a.c:6\ndrivers/net/usb/ch9200.c:4\ndrivers/net/usb/dm9601.c:8\ndrivers/net/usb/lan78xx.c:43\ndrivers/net/usb/mcs7830.c:4\ndrivers/net/usb/pegasus.c:4\ndrivers/net/usb/r8152.c:45\ndrivers/net/usb/r8153_ecm.c:4\ndrivers/net/usb/smsc75xx.c:32\ndrivers/net/usb/smsc95xx.c:40\ndrivers/net/usb/sr9800.c:8\ndrivers/net/usb/usbnet.c:4\n\ndrivers/net/usb/aqc111.c=266=static int aqc111_get_link_ksettings(struct net_device *net,\n--\ndrivers/net/usb/aqc111.c-290-\ndrivers/net/usb/aqc111.c:291:\telk-\u003ebase.mdio_support = 0x00; /*Not supported*/\ndrivers/net/usb/aqc111.c-292-\n--\ndrivers/net/usb/asix.h=178=struct asix_common_private {\n--\ndrivers/net/usb/asix.h-184-\tstruct asix_rx_fixup_info rx_fixup_info;\ndrivers/net/usb/asix.h:185:\tstruct mii_bus *mdio;\ndrivers/net/usb/asix.h-186-\tstruct phy_device *phydev;\n--\ndrivers/net/usb/asix.h=229=void asix_set_multicast(struct net_device *net);\ndrivers/net/usb/asix.h-230-\ndrivers/net/usb/asix.h:231:int asix_mdio_read(struct net_device *netdev, int phy_id, int loc);\ndrivers/net/usb/asix.h:232:void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val);\ndrivers/net/usb/asix.h-233-\ndrivers/net/usb/asix.h:234:int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum);\ndrivers/net/usb/asix.h:235:int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val);\ndrivers/net/usb/asix.h-236-\ndrivers/net/usb/asix.h:237:int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc);\ndrivers/net/usb/asix.h:238:void asix_mdio_write_nopm(struct net_device *netdev, int phy_id, int loc,\ndrivers/net/usb/asix.h-239-\t\t\t  int val);\n--\ndrivers/net/usb/asix_common.c=436=void asix_set_multicast(struct net_device *net)\n--\ndrivers/net/usb/asix_common.c-474-\ndrivers/net/usb/asix_common.c:475:static int __asix_mdio_read(struct net_device *netdev, int phy_id, int loc,\ndrivers/net/usb/asix_common.c-476-\t\t\t    bool in_pm)\n--\ndrivers/net/usb/asix_common.c-498-\ndrivers/net/usb/asix_common.c:499:\tnetdev_dbg(dev-\u003enet, \"asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\\n\",\ndrivers/net/usb/asix_common.c-500-\t\t\tphy_id, loc, le16_to_cpu(res));\n--\ndrivers/net/usb/asix_common.c-504-\ndrivers/net/usb/asix_common.c:505:int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)\ndrivers/net/usb/asix_common.c-506-{\ndrivers/net/usb/asix_common.c:507:\treturn __asix_mdio_read(netdev, phy_id, loc, false);\ndrivers/net/usb/asix_common.c-508-}\ndrivers/net/usb/asix_common.c-509-\ndrivers/net/usb/asix_common.c:510:static int __asix_mdio_write(struct net_device *netdev, int phy_id, int loc,\ndrivers/net/usb/asix_common.c-511-\t\t\t     int val, bool in_pm)\n--\ndrivers/net/usb/asix_common.c-516-\ndrivers/net/usb/asix_common.c:517:\tnetdev_dbg(dev-\u003enet, \"asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\\n\",\ndrivers/net/usb/asix_common.c-518-\t\t\tphy_id, loc, val);\n--\ndrivers/net/usb/asix_common.c-537-\ndrivers/net/usb/asix_common.c:538:void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)\ndrivers/net/usb/asix_common.c-539-{\ndrivers/net/usb/asix_common.c:540:\t__asix_mdio_write(netdev, phy_id, loc, val, false);\ndrivers/net/usb/asix_common.c-541-}\n--\ndrivers/net/usb/asix_common.c-543-/* MDIO read and write wrappers for phylib */\ndrivers/net/usb/asix_common.c:544:int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)\ndrivers/net/usb/asix_common.c-545-{\n--\ndrivers/net/usb/asix_common.c-547-\ndrivers/net/usb/asix_common.c:548:\treturn __asix_mdio_read(priv-\u003enet, phy_id, regnum, false);\ndrivers/net/usb/asix_common.c-549-}\ndrivers/net/usb/asix_common.c-550-\ndrivers/net/usb/asix_common.c:551:int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)\ndrivers/net/usb/asix_common.c-552-{\n--\ndrivers/net/usb/asix_common.c-554-\ndrivers/net/usb/asix_common.c:555:\treturn __asix_mdio_write(priv-\u003enet, phy_id, regnum, val, false);\ndrivers/net/usb/asix_common.c-556-}\ndrivers/net/usb/asix_common.c-557-\ndrivers/net/usb/asix_common.c:558:int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc)\ndrivers/net/usb/asix_common.c-559-{\ndrivers/net/usb/asix_common.c:560:\treturn __asix_mdio_read(netdev, phy_id, loc, true);\ndrivers/net/usb/asix_common.c-561-}\n--\ndrivers/net/usb/asix_common.c=563=void\ndrivers/net/usb/asix_common.c:564:asix_mdio_write_nopm(struct net_device *netdev, int phy_id, int loc, int val)\ndrivers/net/usb/asix_common.c-565-{\ndrivers/net/usb/asix_common.c:566:\t__asix_mdio_write(netdev, phy_id, loc, val, true);\ndrivers/net/usb/asix_common.c-567-}\n--\ndrivers/net/usb/asix_devices.c=70=static u32 asix_get_phyid(struct usbnet *dev)\n--\ndrivers/net/usb/asix_devices.c-77-\tfor (i = 0; i \u003c 100; i++) {\ndrivers/net/usb/asix_devices.c:78:\t\tphy_reg = asix_mdio_read(dev-\u003enet, dev-\u003emii.phy_id, MII_PHYSID1);\ndrivers/net/usb/asix_devices.c-79-\t\tif (phy_reg \u003c 0)\n--\ndrivers/net/usb/asix_devices.c-90-\ndrivers/net/usb/asix_devices.c:91:\tphy_reg = asix_mdio_read(dev-\u003enet, dev-\u003emii.phy_id, MII_PHYSID2);\ndrivers/net/usb/asix_devices.c-92-\tif (phy_reg \u003c 0)\n--\ndrivers/net/usb/asix_devices.c=190=static void asix_phy_reset(struct usbnet *dev, unsigned int reset_bits)\n--\ndrivers/net/usb/asix_devices.c-193-\ndrivers/net/usb/asix_devices.c:194:\tasix_mdio_write(dev-\u003enet, dev-\u003emii.phy_id, MII_BMCR, reset_bits);\ndrivers/net/usb/asix_devices.c-195-\n--\ndrivers/net/usb/asix_devices.c-200-\twhile (timeout--) {\ndrivers/net/usb/asix_devices.c:201:\t\tif (asix_mdio_read(dev-\u003enet, dev-\u003emii.phy_id, MII_BMCR)\ndrivers/net/usb/asix_devices.c-202-\t\t\t\t\t\t\t\u0026 BMCR_RESET)\n--\ndrivers/net/usb/asix_devices.c=212=static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)\n--\ndrivers/net/usb/asix_devices.c-248-\tdev-\u003emii.dev = dev-\u003enet;\ndrivers/net/usb/asix_devices.c:249:\tdev-\u003emii.mdio_read = asix_mdio_read;\ndrivers/net/usb/asix_devices.c:250:\tdev-\u003emii.mdio_write = asix_mdio_write;\ndrivers/net/usb/asix_devices.c-251-\tdev-\u003emii.phy_id_mask = 0x3f;\n--\ndrivers/net/usb/asix_devices.c-263-\tasix_phy_reset(dev, BMCR_RESET);\ndrivers/net/usb/asix_devices.c:264:\tasix_mdio_write(dev-\u003enet, dev-\u003emii.phy_id, MII_ADVERTISE,\ndrivers/net/usb/asix_devices.c-265-\t\tADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);\n--\ndrivers/net/usb/asix_devices.c=362=static int ax88772_hw_reset(struct usbnet *dev, int in_pm)\n--\ndrivers/net/usb/asix_devices.c-406-\ndrivers/net/usb/asix_devices.c:407:\tif (in_pm \u0026\u0026 (!asix_mdio_read_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-408-\t\t\t\t\t   MII_PHYSID1))){\n--\ndrivers/net/usb/asix_devices.c=456=static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)\n--\ndrivers/net/usb/asix_devices.c-496-\ndrivers/net/usb/asix_devices.c:497:\tif (in_pm \u0026\u0026 (!asix_mdio_read_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-498-\t\t\t\t\t   MII_PHYSID1))) {\n--\ndrivers/net/usb/asix_devices.c-512-\t\t/* Check if the PHY registers have default settings */\ndrivers/net/usb/asix_devices.c:513:\t\tphy14h = asix_mdio_read_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-514-\t\t\t\t\t     AX88772A_PHY14H);\ndrivers/net/usb/asix_devices.c:515:\t\tphy15h = asix_mdio_read_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-516-\t\t\t\t\t     AX88772A_PHY15H);\ndrivers/net/usb/asix_devices.c:517:\t\tphy16h = asix_mdio_read_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-518-\t\t\t\t\t     AX88772A_PHY16H);\n--\ndrivers/net/usb/asix_devices.c-525-\t\tif (phy14h != AX88772A_PHY14H_DEFAULT)\ndrivers/net/usb/asix_devices.c:526:\t\t\tasix_mdio_write_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-527-\t\t\t\t\t     AX88772A_PHY14H,\n--\ndrivers/net/usb/asix_devices.c-529-\t\tif (phy15h != AX88772A_PHY15H_DEFAULT)\ndrivers/net/usb/asix_devices.c:530:\t\t\tasix_mdio_write_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-531-\t\t\t\t\t     AX88772A_PHY15H,\n--\ndrivers/net/usb/asix_devices.c-533-\t\tif (phy16h != AX88772A_PHY16H_DEFAULT)\ndrivers/net/usb/asix_devices.c:534:\t\t\tasix_mdio_write_nopm(dev-\u003enet, dev-\u003emii.phy_id,\ndrivers/net/usb/asix_devices.c-535-\t\t\t\t\t     AX88772A_PHY16H,\n--\ndrivers/net/usb/asix_devices.c=658=static int asix_resume(struct usb_interface *intf)\n--\ndrivers/net/usb/asix_devices.c-668-\ndrivers/net/usb/asix_devices.c:669:static int ax88772_init_mdio(struct usbnet *dev)\ndrivers/net/usb/asix_devices.c-670-{\n--\ndrivers/net/usb/asix_devices.c-673-\ndrivers/net/usb/asix_devices.c:674:\tpriv-\u003emdio = mdiobus_alloc();\ndrivers/net/usb/asix_devices.c:675:\tif (!priv-\u003emdio)\ndrivers/net/usb/asix_devices.c-676-\t\treturn -ENOMEM;\ndrivers/net/usb/asix_devices.c-677-\ndrivers/net/usb/asix_devices.c:678:\tpriv-\u003emdio-\u003epriv = dev;\ndrivers/net/usb/asix_devices.c:679:\tpriv-\u003emdio-\u003eread = \u0026asix_mdio_bus_read;\ndrivers/net/usb/asix_devices.c:680:\tpriv-\u003emdio-\u003ewrite = \u0026asix_mdio_bus_write;\ndrivers/net/usb/asix_devices.c:681:\tpriv-\u003emdio-\u003ename = \"Asix MDIO Bus\";\ndrivers/net/usb/asix_devices.c:682:\tpriv-\u003emdio-\u003ephy_mask = ~(BIT(priv-\u003ephy_addr \u0026 0x1f) | BIT(AX_EMBD_PHY_ADDR));\ndrivers/net/usb/asix_devices.c-683-\t/* mii bus name is usb-\u003cusb bus number\u003e-\u003cusb device number\u003e */\ndrivers/net/usb/asix_devices.c:684:\tsnprintf(priv-\u003emdio-\u003eid, MII_BUS_ID_SIZE, \"usb-%03d:%03d\",\ndrivers/net/usb/asix_devices.c-685-\t\t dev-\u003eudev-\u003ebus-\u003ebusnum, dev-\u003eudev-\u003edevnum);\ndrivers/net/usb/asix_devices.c-686-\ndrivers/net/usb/asix_devices.c:687:\tret = mdiobus_register(priv-\u003emdio);\ndrivers/net/usb/asix_devices.c-688-\tif (ret) {\ndrivers/net/usb/asix_devices.c-689-\t\tnetdev_err(dev-\u003enet, \"Could not register MDIO bus (err %d)\\n\", ret);\ndrivers/net/usb/asix_devices.c:690:\t\tmdiobus_free(priv-\u003emdio);\ndrivers/net/usb/asix_devices.c:691:\t\tpriv-\u003emdio = NULL;\ndrivers/net/usb/asix_devices.c-692-\t}\n--\ndrivers/net/usb/asix_devices.c-696-\ndrivers/net/usb/asix_devices.c:697:static void ax88772_mdio_unregister(struct asix_common_private *priv)\ndrivers/net/usb/asix_devices.c-698-{\ndrivers/net/usb/asix_devices.c:699:\tmdiobus_unregister(priv-\u003emdio);\ndrivers/net/usb/asix_devices.c:700:\tmdiobus_free(priv-\u003emdio);\ndrivers/net/usb/asix_devices.c-701-}\n--\ndrivers/net/usb/asix_devices.c=703=static int ax88772_init_phy(struct usbnet *dev)\n--\ndrivers/net/usb/asix_devices.c-707-\ndrivers/net/usb/asix_devices.c:708:\tpriv-\u003ephydev = mdiobus_get_phy(priv-\u003emdio, priv-\u003ephy_addr);\ndrivers/net/usb/asix_devices.c-709-\tif (!priv-\u003ephydev) {\n--\ndrivers/net/usb/asix_devices.c-731-\t */\ndrivers/net/usb/asix_devices.c:732:\tpriv-\u003ephydev_int = mdiobus_get_phy(priv-\u003emdio, AX_EMBD_PHY_ADDR);\ndrivers/net/usb/asix_devices.c-733-\tif (!priv-\u003ephydev_int) {\n--\ndrivers/net/usb/asix_devices.c=829=static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)\n--\ndrivers/net/usb/asix_devices.c-916-\ndrivers/net/usb/asix_devices.c:917:\tret = ax88772_init_mdio(dev);\ndrivers/net/usb/asix_devices.c-918-\tif (ret)\ndrivers/net/usb/asix_devices.c:919:\t\tgoto mdio_err;\ndrivers/net/usb/asix_devices.c-920-\n--\ndrivers/net/usb/asix_devices.c-940-phylink_err:\ndrivers/net/usb/asix_devices.c:941:\tax88772_mdio_unregister(priv);\ndrivers/net/usb/asix_devices.c:942:mdio_err:\ndrivers/net/usb/asix_devices.c-943-\treturn ret;\n--\ndrivers/net/usb/asix_devices.c=955=static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)\n\n"
}

9/2 2026/11/06 03:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 80977
							output: 17
							thoughts: 690
						

Thoughts:
**Diving into the `ax88772` USB Network Device Initialization**

Okay, here we go. I'm looking at the `ax88772` device, and the code jumps right out at me. Specifically, in `ax88772_init_mdio`, that `mdiobus_register(priv->mdio)` call. That's a key point, because that function *scans* the MDIO bus. I need to understand what devices are attached and how that interaction works, and quickly.

Now, what’s `an7581_phy_probe` doing? It seems relevant, given the context. Let me examine its code.

Alright, so `an7581_phy_probe`. It's probing a PHY device, the pinctrl setup to toggle PHY LED caught my eye, but more importantly, it appears to be joining a "package" and allocating a `mtk_socphy_priv`. I see the code is checking for a PHY at a specific address (`AIROHA_DEFAULT_PORT0_ADDR`) and appears to be critical for calibration. It's using the "deferred probe" mechanism which is interesting. It also references `AIROHA_GE_SOC_PHY` in the kconfig, so I need to check how that configuration relates to the `ax88772` device, as the probe seems to be dependant on it. 

Hang on, let's back up to the `AIROHA_GE_SOC_PHY` config. It has dependencies. It’s a tristate option, depends on ARM64, ECONET, or compile-test, and it *selects* `MTK_NET_PHYLIB` and `PHY_PACKAGE`. Now I'm on a target architecture (`amd64`), and that ARM64 dependency is false here. I'm wondering what is that `ECONET` is all about. Time to consult the Kconfig again.



10/2 2026/11/06 03:05 tool grepper
0m Args:
{
  "Expression": "config ECONET"
}

Results:
{
  "Output": "arch/mips/Kconfig=357=config MACH_DECSTATION\n--\narch/mips/Kconfig-393-\narch/mips/Kconfig:394:config ECONET\narch/mips/Kconfig-395-\tbool \"EcoNet MIPS family\"\n--\ndrivers/clocksource/Kconfig=71=config DW_APB_TIMER_OF\n--\ndrivers/clocksource/Kconfig-75-\ndrivers/clocksource/Kconfig:76:config ECONET_EN751221_TIMER\ndrivers/clocksource/Kconfig-77-\tbool \"EcoNet EN751221 High Precision Timer\" if COMPILE_TEST\n--\ndrivers/irqchip/Kconfig=195=config DW_APB_ICTL\n--\ndrivers/irqchip/Kconfig-199-\ndrivers/irqchip/Kconfig:200:config ECONET_EN751221_INTC\ndrivers/irqchip/Kconfig-201-\tbool\n"
}

11/2 2026/11/06 03:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 82372
							output: 20
							thoughts: 50
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:

**Kernel Configuration Decisions**

Alright, let's see, the system's clearly dealing with kernel configuration options. The mention of `ECONET` immediately flags MIPS as the underlying architecture; that's fairly straightforward – `arch/mips/Kconfig` confirms it. Interesting.

Now, the appearance of `ARCH_AIROHA` throws a bit of a curveball. My initial thought process now goes to checking the configuration directly. I need to understand the relationship between `ECONET` and `ARCH_AIROHA`. Is it an enabling option? A dependency? Or are they orthogonal? Time to pull up the relevant `Kconfig` files and dig deeper.



12/2 2026/11/06 03:05 tool grepper
0m Args:
{
  "Expression": "config ARCH_AIROHA"
}

Results:
{
  "Output": "arch/arm/Kconfig.platforms=55=config ARCH_VIRT\n--\narch/arm/Kconfig.platforms-65-\narch/arm/Kconfig.platforms:66:config ARCH_AIROHA\narch/arm/Kconfig.platforms-67-\tbool \"Airoha SoC Support\"\n--\narch/arm64/Kconfig.platforms=4=config ARCH_ACTIONS\n--\narch/arm64/Kconfig.platforms-10-\narch/arm64/Kconfig.platforms:11:config ARCH_AIROHA\narch/arm64/Kconfig.platforms-12-\tbool \"Airoha SoC Support\"\n"
}

13/2 2026/11/06 03:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 82776
							output: 25
							thoughts: 1242
						

Thoughts:
**Analyzing the Airoha SoC PHY and syzkaller's USB Raw Gadget**

Okay, so `ARCH_AIROHA` is ARM/ARM64, and `ECONET` is MIPS, but I'm focusing on the amd64 target. This `AIROHA_GE_SOC_PHY` thing requires `COMPILE_TEST`.  Right, wait, is `COMPILE_TEST` even enabled in syzkaller's amd64 configs?  I don't think it typically *is*, right?  Standard builds usually don't have that enabled.  But even if it *is* enabled...

Hang on, there's that "WorthFuzzing=false" criteria. I remember, I need to check if the changes fall under any of these negative criteria.  It's specifically the "Structurally unreachable hardware" I need to focus on. Stuff like vendor-specific PCIe switches, SmartNICs, GPU drivers that rely on hardware not emulated in standard QEMU. Things that require real physical cards.

Ah, but wait!  Let's consider that "USB devices can emulate any arbitrary PHY ID?"  Let's look at `asix_common.c` and `ax88772`. Ah, the `ax88772` is a USB-to-Ethernet dongle (ASIX AX88772). Does it have an Airoha EN7581 PHY inside? No! It uses its own PHY. But, and here's the key, in the USB raw gadget syzkaller emulation, we can emulate an AX88772. The USB emulation *script* can pretend to be *any* USB device.

Okay, so when syzkaller emulates the AX88772 over USB raw gadget... can syzkaller *control* the MDIO read responses?  We need to find out how `ax88772_init_mdio` reads from MDIO.

Let's look in `asix_common.c`.  There's `asix_mdio_bus_read`:  `return __asix_mdio_read(priv->net, phy_id, regnum, false);`. That calls `__asix_mdio_read` which sends a USB control message `asix_read_cmd(dev, AX_CMD_READ_MII_REG, ...)`.  Perfect! Syzkaller emulates those USB devices, so it can return any USB control transfer response. I can control the response!

Now, the crucial question.  Can an Airoha SoC PHY probe on an AX88772, even though it's emulated? Let's check `an7581_phy_probe`.  Let's look at `devm_phy_package_join`.  What does `devm_phy_package_join` require? We need to dig into how `phy_package_join` is implemented. Okay, let me grep for that function...



14/2 2026/11/06 03:06 tool grepper
0m Args:
{
  "Expression": "int (devm_)?phy_package_join"
}

Results:
{
  "Output": "drivers/net/phy/phy_package.c=202=EXPORT_SYMBOL_GPL(phy_package_probe_once);\n--\ndrivers/net/phy/phy_package.c-231- */\ndrivers/net/phy/phy_package.c:232:int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size)\ndrivers/net/phy/phy_package.c-233-{\n--\ndrivers/net/phy/phy_package.c=366=static void devm_phy_package_leave(struct device *dev, void *res)\n--\ndrivers/net/phy/phy_package.c-382- */\ndrivers/net/phy/phy_package.c:383:int devm_phy_package_join(struct device *dev, struct phy_device *phydev,\ndrivers/net/phy/phy_package.c-384-\t\t\t  int base_addr, size_t priv_size)\n--\ndrivers/net/phy/phylib.h=28=bool phy_package_probe_once(struct phy_device *phydev);\ndrivers/net/phy/phylib.h:29:int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size);\ndrivers/net/phy/phylib.h-30-int of_phy_package_join(struct phy_device *phydev, size_t priv_size);\ndrivers/net/phy/phylib.h=31=void phy_package_leave(struct phy_device *phydev);\ndrivers/net/phy/phylib.h:32:int devm_phy_package_join(struct device *dev, struct phy_device *phydev,\ndrivers/net/phy/phylib.h-33-\t\t\t  int base_addr, size_t priv_size);\n"
}

15/2 2026/11/06 03:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 85167
							output: 39
							thoughts: 29
						

Thoughts:
Okay, here's my interpretation of what's going on, thinking through this code:

**Diving into phy_package.c**

Alright, let's get down to it. I'm going to pull up `drivers/net/phy/phy_package.c`, specifically around line 232. I need to get a close look at this code. This is a crucial file when it comes to PHYs, and I'm guessing this particular section is giving me some clues about the hardware abstraction layer and how the driver interacts with a specific PHY. Knowing that `phy_package.c` is involved suggests this might be related to PHY initialization, configuration, or perhaps even error handling within the PHY package itself. I want to see what assumptions are being made here, what the control flow looks like, and look for any potential areas of concern, or optimisation. I'm expecting to see calls to register and unregister PHYs, handling of interrupt events, or perhaps specific PHY-related configuration functions.



16/2 2026/11/06 03:06 tool read-file
0m Args:
{
  "File": "drivers/net/phy/phy_package.c",
  "FirstLine": 230,
  "LineCount": 50
}

Results:
{
  "Contents": " 230:\t * with the same cookie but a different priv_size is an error.\n 231:\t */\n 232:\tint phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size)\n 233:\t{\n 234:\t\tstruct mii_bus *bus = phydev-\u003emdio.bus;\n 235:\t\tstruct phy_package_shared *shared;\n 236:\t\tint ret;\n 237:\t\n 238:\t\tif (base_addr \u003c 0 || base_addr \u003e= PHY_MAX_ADDR)\n 239:\t\t\treturn -EINVAL;\n 240:\t\n 241:\t\tmutex_lock(\u0026bus-\u003eshared_lock);\n 242:\t\tshared = bus-\u003eshared[base_addr];\n 243:\t\tif (!shared) {\n 244:\t\t\tret = -ENOMEM;\n 245:\t\t\tshared = kzalloc_obj(*shared);\n 246:\t\t\tif (!shared)\n 247:\t\t\t\tgoto err_unlock;\n 248:\t\t\tif (priv_size) {\n 249:\t\t\t\tshared-\u003epriv = kzalloc(priv_size, GFP_KERNEL);\n 250:\t\t\t\tif (!shared-\u003epriv)\n 251:\t\t\t\t\tgoto err_free;\n 252:\t\t\t\tshared-\u003epriv_size = priv_size;\n 253:\t\t\t}\n 254:\t\t\tshared-\u003ebase_addr = base_addr;\n 255:\t\t\tshared-\u003enp = NULL;\n 256:\t\t\trefcount_set(\u0026shared-\u003erefcnt, 1);\n 257:\t\t\tbus-\u003eshared[base_addr] = shared;\n 258:\t\t} else {\n 259:\t\t\tret = -EINVAL;\n 260:\t\t\tif (priv_size \u0026\u0026 priv_size != shared-\u003epriv_size)\n 261:\t\t\t\tgoto err_unlock;\n 262:\t\t\trefcount_inc(\u0026shared-\u003erefcnt);\n 263:\t\t}\n 264:\t\tmutex_unlock(\u0026bus-\u003eshared_lock);\n 265:\t\n 266:\t\tphydev-\u003eshared = shared;\n 267:\t\n 268:\t\treturn 0;\n 269:\t\n 270:\terr_free:\n 271:\t\tkfree(shared);\n 272:\terr_unlock:\n 273:\t\tmutex_unlock(\u0026bus-\u003eshared_lock);\n 274:\t\treturn ret;\n 275:\t}\n 276:\tEXPORT_SYMBOL_GPL(phy_package_join);\n 277:\t\n 278:\t/**\n 279:\t * of_phy_package_join - join a common PHY group in PHY package\n"
}

17/2 2026/11/06 03:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 86161
							output: 31
							thoughts: 1396
						

Thoughts:
**Analyzing Potential Fuzzing Targets in Network PHY Driver Code**

Okay, let's break this down. First, I'm looking at the `an7581_phy_probe` function. It seems to be trying to find a PHY at port 0, specifically with the address `AIROHA_DEFAULT_PORT0_ADDR`, which is `0x9`. It's checking if the PHY at this address is available because it's crucial for calibration. If it isn't, the probe defers. Now, I notice an interesting part: `ax88772_init_mdio` sets a PHY mask. The relevant parts are `AX_EMBD_PHY_ADDR` which has a value of 0x10. I need to understand the implications of this.

Next, I need to check something related to the target architecture being amd64. I'm focusing on `CONFIG_AIROHA_GE_SOC_PHY`. The Kconfig entry says it's for "Airoha SoC Gigabit Ethernet PHYs" and depends on `ARM64 || ECONET || COMPILE_TEST`. It also depends on either `ARCH_AIROHA || ECONET || COMPILE_TEST`. This is the core question: can `CONFIG_AIROHA_GE_SOC_PHY` be enabled on amd64?

Here's where the fuzzing criteria from the instructions come into play. Reachability is key. They clearly state that structurally unreachable code should not be fuzzed. Specifically, I'm looking for "Structurally unreachable hardware." This includes things like vendor-specific PCIe switches, and SmartNICs. I need to determine if this Airoha SoC Gigabit Ethernet PHY falls into that category.

So, what *is* an Airoha SoC Gigabit Ethernet PHY? Based on the commit message and the Kconfig, it seems to be a built-in Ethernet PHY on an Airoha SoC, like the AN7581 or AN7583, or EN7528. These PHYs are meant to calibrate dynamically during startup.

Now, I want more context. I need to understand the origin of this code. Ideally, I'd check the git log for the commit. While I don't have access to the full `git log` tool, I have the commit diff right here. It looks like this commit was applied by a syzkaller cluster. I have a list of changed files too. It includes a new file, `airoha-ge-soc.c`.

Let's carefully examine the changes. I see that `mtk-phy-lib.c` now exports `__mtk_tr_write` as `EXPORT_SYMBOL_GPL`. Additionally, LED-related functions, such as `mt798x_phy_led_*`, have been moved from `mtk-ge-soc.c` to `mtk-phy-lib.c`. This could be important.

My next step is to understand the usage of these moved and modified functions. I need to see who calls `mt798x_phy_led_*` and `__mtk_tr_write` to understand the data flow and how they're used. This is a critical step in assessing if these code paths are reachable on my target architecture.



18/2 2026/11/06 03:06 tool grepper
0m Args:
{
  "Expression": "mt798x_phy_led|__mtk_tr_write"
}

Results:
{
  "Output": "drivers/net/phy/mediatek/airoha-ge-soc.c=1402=static int an7581_phy_config_init(struct phy_device *phydev)\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1511-\toldpage = phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1512:\t__mtk_tr_write(phydev, 0x0, 0x7, 0x15, 0x0055a0);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1513:\t__mtk_tr_write(phydev, 0x0, 0x7, 0x17, 0x07ff3f);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1514:\t__mtk_tr_write(phydev, 0x1, 0xf, 0x0, 0x00001e);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1515:\t__mtk_tr_write(phydev, 0x1, 0xf, 0x1, 0x6fb90a);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1516:\t__mtk_tr_write(phydev, 0x1, 0xf, 0x18, 0x0e2f00);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1517:\t__mtk_tr_write(phydev, 0x1, 0xd, 0x26, 0x444444);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1518:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x3, 0x000004);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1519:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x6, 0x2ebaef);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1520:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x8, 0x00000b);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1521:\t__mtk_tr_write(phydev, 0x2, 0xd, 0xc, 0x00504d);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1522:\t__mtk_tr_write(phydev, 0x2, 0xd, 0xd, 0x02314f);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1523:\t__mtk_tr_write(phydev, 0x2, 0xd, 0xf, 0x003028);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1524:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x10, 0x00000a);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1525:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x11, 0x040001);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1526:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x14, 0x00024a);\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1527:\t__mtk_tr_write(phydev, 0x2, 0xd, 0x1c, 0x003210);\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1528-\tphy_restore_page(phydev, oldpage, 0);\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c=1823=static struct phy_driver mtk_socphy_driver[] = {\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1828-\t\t.probe\t\t= an7581_phy_probe,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1829:\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1830:\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1831:\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1832:\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1833:\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1834-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1842-\t\t.probe\t\t= an7581_phy_probe,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1843:\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1844:\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1845:\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1846:\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1847:\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1848-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n--\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1856-\t\t.probe\t\t= an7581_phy_probe,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1857:\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1858:\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1859:\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1860:\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\ndrivers/net/phy/mediatek/airoha-ge-soc.c:1861:\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\ndrivers/net/phy/mediatek/airoha-ge-soc.c-1862-\t\t.led_polarity_set = an7581_phy_led_polarity_set,\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=1026=static struct phy_driver mtk_socphy_driver[] = {\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1037-\t\t.write_page\t= mtk_phy_write_page,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1038:\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1039:\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1040:\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1041:\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1042:\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1043-\t},\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1054-\t\t.write_page\t= mtk_phy_write_page,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1055:\t\t.led_blink_set\t= mt798x_phy_led_blink_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1056:\t\t.led_brightness_set = mt798x_phy_led_brightness_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1057:\t\t.led_hw_is_supported = mt798x_phy_led_hw_is_supported,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1058:\t\t.led_hw_control_set = mt798x_phy_led_hw_control_set,\ndrivers/net/phy/mediatek/mtk-ge-soc.c:1059:\t\t.led_hw_control_get = mt798x_phy_led_hw_control_get,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-1060-\t},\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c=29=static void __mtk_tr_read(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-38-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:39:void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-40-\t\t    u8 data_addr, u32 tr_data)\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-47-}\ndrivers/net/phy/mediatek/mtk-phy-lib.c:48:EXPORT_SYMBOL_GPL(__mtk_tr_write);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-49-\ndrivers/net/phy/mediatek/mtk-phy-lib.c=50=void __mtk_tr_modify(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-59-\ttr_data = (tr_data \u0026 ~mask) | set;\ndrivers/net/phy/mediatek/mtk-phy-lib.c:60:\t__mtk_tr_write(phydev, ch_addr, node_addr, data_addr, tr_data);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-61-}\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c=340=EXPORT_SYMBOL_GPL(mtk_phy_leds_state_init);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-341-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:342:int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-343-\t\t\t     unsigned long *delay_on,\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-359-}\ndrivers/net/phy/mediatek/mtk-phy-lib.c:360:EXPORT_SYMBOL_GPL(mt798x_phy_led_blink_set);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-361-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:362:int mt798x_phy_led_brightness_set(struct phy_device *phydev,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-363-\t\t\t\t  u8 index, enum led_brightness value)\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-373-}\ndrivers/net/phy/mediatek/mtk-phy-lib.c:374:EXPORT_SYMBOL_GPL(mt798x_phy_led_brightness_set);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-375-\ndrivers/net/phy/mediatek/mtk-phy-lib.c=376=static const unsigned long supported_triggers =\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-385-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:386:int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-387-\t\t\t\t   unsigned long rules)\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-391-}\ndrivers/net/phy/mediatek/mtk-phy-lib.c:392:EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_is_supported);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-393-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:394:int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-395-\t\t\t\t  unsigned long *rules)\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-401-};\ndrivers/net/phy/mediatek/mtk-phy-lib.c:402:EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_get);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-403-\ndrivers/net/phy/mediatek/mtk-phy-lib.c:404:int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk-phy-lib.c-405-\t\t\t\t  unsigned long rules)\n--\ndrivers/net/phy/mediatek/mtk-phy-lib.c-411-};\ndrivers/net/phy/mediatek/mtk-phy-lib.c:412:EXPORT_SYMBOL_GPL(mt798x_phy_led_hw_control_set);\ndrivers/net/phy/mediatek/mtk-phy-lib.c-413-\n--\ndrivers/net/phy/mediatek/mtk.h=72=struct mtk_socphy_priv {\n--\ndrivers/net/phy/mediatek/mtk.h-75-\ndrivers/net/phy/mediatek/mtk.h:76:void __mtk_tr_write(struct phy_device *phydev, u8 ch_addr, u8 node_addr,\ndrivers/net/phy/mediatek/mtk.h-77-\t\t    u8 data_addr, u32 tr_data);\n--\ndrivers/net/phy/mediatek/mtk.h=105=void mtk_phy_leds_state_init(struct phy_device *phydev);\ndrivers/net/phy/mediatek/mtk.h-106-\ndrivers/net/phy/mediatek/mtk.h:107:int mt798x_phy_led_blink_set(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk.h-108-\t\t\t     unsigned long *delay_on,\ndrivers/net/phy/mediatek/mtk.h-109-\t\t\t     unsigned long *delay_off);\ndrivers/net/phy/mediatek/mtk.h:110:int mt798x_phy_led_brightness_set(struct phy_device *phydev,\ndrivers/net/phy/mediatek/mtk.h-111-\t\t\t\t  u8 index, enum led_brightness value);\ndrivers/net/phy/mediatek/mtk.h:112:int mt798x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk.h-113-\t\t\t\t   unsigned long rules);\ndrivers/net/phy/mediatek/mtk.h:114:int mt798x_phy_led_hw_control_get(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk.h-115-\t\t\t\t  unsigned long *rules);\ndrivers/net/phy/mediatek/mtk.h:116:int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,\ndrivers/net/phy/mediatek/mtk.h-117-\t\t\t\t  unsigned long rules);\n"
}

19/2 2026/11/06 03:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 93098
							output: 21
							thoughts: 2000
						

Thoughts:
**Analysis of Airoha and MediaTek SoC PHY Drivers on amd64**

Okay, let's break this down. My immediate concern is whether the MediaTek and Airoha Gigabit Ethernet PHY drivers are even *reachable* on an amd64 system. The prompt highlights the need to determine if code modifications warrant fuzzing. The key lies in identifying "structurally unreachable hardware" and "unreachable execution paths."

First, let's examine the dependencies. The configuration options `MEDIATEK_GE_SOC_PHY` and `AIROHA_GE_SOC_PHY` are specific to MediaTek and Airoha SoCs respectively. Their `Kconfig` files clearly state dependencies on either `ARM64`, `ECONET`, or `COMPILE_TEST`.  The text specifically mentions that Airoha SoCs are ARM64 and MIPS-based.

Now, considering the target architecture is amd64, this becomes critical.  `ARCH_AIROHA` doesn't exist on amd64; it's specific to ARM and ARM64. `ECONET` is a MIPS architecture feature. `ARM64` is, of course, a different architecture. Therefore, unless `COMPILE_TEST` is enabled, these drivers will not even *compile* on amd64. `COMPILE_TEST` is for build testing only and doesn't make the PHY usable.

Even if `COMPILE_TEST` is set, there's a bigger problem: emulation. Can an SoC built-in PHY driver *run* on amd64 within QEMU? The answer is a resounding no. QEMU's amd64 emulation models an x86 PC (i440fx or q35) – it doesn't instantiate any MediaTek or Airoha SoCs, no matter how hard you look. There are no MediaTek or Airoha Ethernet MACs. No internal MDIO bus, no PHYs.  There's no Device Tree on an x86 PC to instantiate these SoC internal MDIO bus or PHY devices.

A thought: could a USB device, perhaps, trigger these drivers? I considered the `ax88772` example, where a USB ethernet adapter creates an MDIO bus. However, the `an7581_phy_probe` routine makes it clear that the drivers rely on specific SoC register access, Device Tree configurations, and pinctrl setup for LEDs (and other SoC-specific hardware). `devm_phy_package_join` is going to fail if the SoC and its internal structures aren't present.

Thinking about the fuzzing context, does syzkaller EVER instantiate these drivers?  No, it doesn't have an MDIO fuzzer, and even the USB gadget drivers are focused on USB interfaces, not arbitrary MDIO bus PHYs behind an ethernet adapter.

Going back to the crucial criteria: "Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories."  Specifically, we need to apply this against the "Code paths exclusive to architectures other than the target architecture" point.

Considering this:

1.  This patch series is inherently exclusive to ARM64 and/or ECONET (MIPS) architectures. `ARCH_AIROHA` and `ECONET` are *not* defined for amd64, without `COMPILE_TEST` they can't be compiled, and the internal PHYs can't be made to execute.
2.  The drivers are *specifically* for SoC-internal PHYs.  They rely on SoC-specific registers, Device Tree configurations, and pinctrl.

Therefore, the hardware is fundamentally unreachable on amd64.  The modifications in `mtk-ge-soc.c` and `mtk-phy-lib.c` will never be exercised.

The conclusion is clear: This modified code falls strictly into the category of "Structurally unreachable hardware" and "Unreachable execution paths." So, `WorthFuzzing=false`.



20/2 2026/11/06 03:07 tool grepper
0m Args:
{
  "Expression": "MTK_NET_PHYLIB"
}

Results:
{
  "Output": "drivers/net/phy/mediatek/Kconfig=2=config AIROHA_GE_SOC_PHY\n--\ndrivers/net/phy/mediatek/Kconfig-5-\tdepends on ARCH_AIROHA || ECONET || COMPILE_TEST\ndrivers/net/phy/mediatek/Kconfig:6:\tselect MTK_NET_PHYLIB\ndrivers/net/phy/mediatek/Kconfig-7-\tselect PHY_PACKAGE\n--\ndrivers/net/phy/mediatek/Kconfig=15=config MEDIATEK_2P5GE_PHY\n--\ndrivers/net/phy/mediatek/Kconfig-17-\tdepends on (ARM64 \u0026\u0026 ARCH_MEDIATEK) || COMPILE_TEST\ndrivers/net/phy/mediatek/Kconfig:18:\tselect MTK_NET_PHYLIB\ndrivers/net/phy/mediatek/Kconfig-19-\thelp\n--\ndrivers/net/phy/mediatek/Kconfig=26=config MEDIATEK_GE_PHY\ndrivers/net/phy/mediatek/Kconfig-27-\ttristate \"MediaTek Gigabit Ethernet PHYs\"\ndrivers/net/phy/mediatek/Kconfig:28:\tselect MTK_NET_PHYLIB\ndrivers/net/phy/mediatek/Kconfig-29-\thelp\n--\ndrivers/net/phy/mediatek/Kconfig=46=config MEDIATEK_GE_SOC_PHY\n--\ndrivers/net/phy/mediatek/Kconfig-49-\tdepends on (ARCH_MEDIATEK \u0026\u0026 NVMEM_MTK_EFUSE) || COMPILE_TEST\ndrivers/net/phy/mediatek/Kconfig:50:\tselect MTK_NET_PHYLIB\ndrivers/net/phy/mediatek/Kconfig-51-\tselect PHY_PACKAGE\n--\ndrivers/net/phy/mediatek/Kconfig-63-\ndrivers/net/phy/mediatek/Kconfig:64:config MTK_NET_PHYLIB\ndrivers/net/phy/mediatek/Kconfig-65-\ttristate\n--\ndrivers/net/phy/mediatek/Makefile=6=obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)\t+= mtk-ge-soc.o\ndrivers/net/phy/mediatek/Makefile:7:obj-$(CONFIG_MTK_NET_PHYLIB)\t\t+= mtk-phy-lib.o\n"
}

21/2 2026/11/06 03:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 96555
							output: 21
							thoughts: 257
						

Thoughts:
**Analyzing MediaTek PHY Driver Configuration**

Okay, let's dive into this `drivers/net/phy/mediatek/Kconfig` file. I see a few MediaTek PHY drivers listed here: `AIROHA_GE_SOC_PHY`, `MEDIATEK_2P5GE_PHY`, `MEDIATEK_FE_SOC_PHY`, `MEDIATEK_GE_SOC_PHY`, and `MEDIATEK_GE_PHY`. Seems pretty standard, different PHY configurations for different target architectures. I'm noting the dependency conditions – `ARM64`, `ECONET`, `RALINK`, `ARCH_AIROHA`, `ARCH_MEDIATEK`, `NVMEM_MTK_EFUSE`, and `COMPILE_TEST`. Seems like the usual suspects for these kinds of drivers – architecture and platform specifics. 

Wait a minute, `MEDIATEK_GE_PHY`... it's a tristate option and it *selects* `MTK_NET_PHYLIB`. I want to understand `MEDIATEK_GE_PHY` better and how it ties into the broader picture of the MediaTek PHY drivers. I should probably go look at the implementation of `MEDIATEK_GE_PHY` and what `mtk-ge.c` is doing.



22/2 2026/11/06 03:07 tool grepper
0m Args:
{
  "Expression": "MEDIATEK_GE_PHY"
}

Results:
{
  "Output": "drivers/net/dsa/Kconfig=43=config NET_DSA_MT7530_MDIO\n--\ndrivers/net/dsa/Kconfig-45-\tdepends on NET_DSA_MT7530\ndrivers/net/dsa/Kconfig:46:\tselect MEDIATEK_GE_PHY\ndrivers/net/dsa/Kconfig-47-\tselect PCS_MTK_LYNXI\n--\ndrivers/net/phy/mediatek/Kconfig=15=config MEDIATEK_2P5GE_PHY\n--\ndrivers/net/phy/mediatek/Kconfig-25-\ndrivers/net/phy/mediatek/Kconfig:26:config MEDIATEK_GE_PHY\ndrivers/net/phy/mediatek/Kconfig-27-\ttristate \"MediaTek Gigabit Ethernet PHYs\"\n--\ndrivers/net/phy/mediatek/Makefile=4=obj-$(CONFIG_MEDIATEK_FE_SOC_PHY)\t+= mtk-fe-soc.o\ndrivers/net/phy/mediatek/Makefile:5:obj-$(CONFIG_MEDIATEK_GE_PHY)\t\t+= mtk-ge.o\ndrivers/net/phy/mediatek/Makefile-6-obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)\t+= mtk-ge-soc.o\n"
}

23/2 2026/11/06 03:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 97441
							output: 54
							thoughts: 73
						

Thoughts:
**Analyzing the Interaction of `MEDIATEK_GE_PHY` and `mtk-ge.c`**

Okay, so `MEDIATEK_GE_PHY` is specifically for those MT7530 and MT7531 switch PHYs – the ones that are managed by `NET_DSA_MT7530_MDIO`. My immediate concern is whether or not the existing `mtk-ge.c` driver code interacts with any of the functions that have been modified as a result of supporting these PHYs. It's crucial to understand the dependency, if any, between these two modules. Time to dig into `mtk-ge.c` and see what's going on. I need to quickly identify any potential conflicts or areas where my changes might impact existing functionality. Let's get to work.



24/2 2026/11/06 03:07 tool grepper
0m Args:
{
  "Expression": "mt798x|mtk_cal|__mtk_tr_write",
  "PathPrefixes": [
    "drivers/net/phy/mediatek/mtk-ge.c"
  ]
}

Results:
{
  "Output": "no matches"
}

25/2 2026/11/06 03:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 97759
							output: 41
							thoughts: 134
						

Thoughts:
Okay, here's my breakdown of what's going on, thinking it through step-by-step:

**Analyzing Function Calls in the MTK GE Codebase**

Alright, I'm starting with the observation that none of the functions I've modified are apparently called within `mtk-ge.c`. That's the starting point. My next step is to trace the call graph to see where this `mtk_cal_cycle_wait` function is actually being used.

First, I see a call to `mtk_cal_cycle_wait(phydev_p0)` in `airoha-ge-soc.c`. Okay, that's one use.

Then, within `mtk-ge-soc.c`, I find `cal_cycle` calling `mtk_cal_cycle_wait(phydev)`.  So `cal_cycle` seems to be a key intermediary.

Now, to understand the control flow better, I *need* to know what calls *`cal_cycle`* within `mtk-ge-soc.c`. That's the missing piece, so I'll need to check the callers of `cal_cycle` in `mtk-ge-soc.c`. I have a feeling the broader context of what's happening will emerge from this.



26/2 2026/11/06 03:08 tool grepper
0m Args:
{
  "Expression": "cal_cycle",
  "PathPrefixes": [
    "drivers/net/phy/mediatek/mtk-ge-soc.c"
  ]
}

Results:
{
  "Output": "drivers/net/phy/mediatek/mtk-ge-soc.c=37=struct mtk_socphy_shared {\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-41-\ndrivers/net/phy/mediatek/mtk-ge-soc.c:42:int mtk_cal_cycle_wait(struct phy_device *phydev)\ndrivers/net/phy/mediatek/mtk-ge-soc.c-43-{\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-67-}\ndrivers/net/phy/mediatek/mtk-ge-soc.c:68:EXPORT_SYMBOL_GPL(mtk_cal_cycle_wait);\ndrivers/net/phy/mediatek/mtk-ge-soc.c-69-\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-75- */\ndrivers/net/phy/mediatek/mtk-ge-soc.c:76:static int cal_cycle(struct phy_device *phydev, int devad,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-77-\t\t     u32 regnum, u16 mask, u16 cal_val)\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-83-\ndrivers/net/phy/mediatek/mtk-ge-soc.c:84:\tret = mtk_cal_cycle_wait(phydev);\ndrivers/net/phy/mediatek/mtk-ge-soc.c-85-\tphydev_dbg(phydev, \"cal_val: 0x%x, ret: %d\\n\", cal_val, ret);\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c=316=static int tx_vcm_cal_sw(struct phy_device *phydev, u8 rg_txreserve_x)\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-384-\t\ttxreserve_val = DIV_ROUND_CLOSEST(lower_idx + upper_idx, 2);\ndrivers/net/phy/mediatek/mtk-ge-soc.c:385:\t\tret = cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RXADC_CTRL_RG9,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-386-\t\t\t\tMTK_PHY_DA_RX_PSBN_TBT_MASK |\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-403-\tif (lower_idx == TXRESERVE_MIN) {\ndrivers/net/phy/mediatek/mtk-ge-soc.c:404:\t\tlower_ret = cal_cycle(phydev, MDIO_MMD_VEND1,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-405-\t\t\t\t      MTK_PHY_RXADC_CTRL_RG9,\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-413-\t} else if (upper_idx == TXRESERVE_MAX) {\ndrivers/net/phy/mediatek/mtk-ge-soc.c:414:\t\tupper_ret = cal_cycle(phydev, MDIO_MMD_VEND1,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-415-\t\t\t\t      MTK_PHY_RXADC_CTRL_RG9,\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-434-\t\t/* Make sure we use upper_idx in our calibration system */\ndrivers/net/phy/mediatek/mtk-ge-soc.c:435:\t\tcal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RXADC_CTRL_RG9,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-436-\t\t\t  MTK_PHY_DA_RX_PSBN_TBT_MASK |\n--\ndrivers/net/phy/mediatek/mtk-ge-soc.c-445-\t\tret = 0;\ndrivers/net/phy/mediatek/mtk-ge-soc.c:446:\t\tcal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RXADC_CTRL_RG9,\ndrivers/net/phy/mediatek/mtk-ge-soc.c-447-\t\t\t  MTK_PHY_DA_RX_PSBN_TBT_MASK |\n"
}

27/2 2026/11/06 03:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 99361
							output: 179
							thoughts: 1667
						

Thoughts:
**Fuzzing Decision for the Patch Series**

Okay, let's break this down systematically. My initial assessment is that `WorthFuzzing` is likely false, but I need to be absolutely certain.

First, I observe that `cal_cycle` in `mtk-ge-soc.c` is only called within that file, specifically during the probe/config_init stage, and that applies only to MT7981 and MT7988. These are MediaTek Filogic ARM64 SoCs. Also, `mt798x_phy_led_*` in `mtk-phy-lib.c` gets called only by `mtk-ge-soc.c` (again, MT7981/MT7988) and `airoha-ge-soc.c` (for EN7528/AN7581/AN7583). Finally, `__mtk_tr_write` in `mtk-phy-lib.c` is used by the existing `__mtk_tr_modify` in the same file *and* the new `airoha-ge-soc.c`.

Now, the target architecture is `amd64`. Time to revisit the fuzzing guidelines.

The guidelines state that fuzzing is only for code that can *execute* in standard environments. Reachability is key. I need to determine if this code meets the negative criteria for skipping fuzzing.

Specifically, I'm focusing on the criteria regarding structurally unreachable hardware and unreachable execution paths. The code here relates to Airoha and MediaTek SoC-integrated Gigabit Ethernet PHYs. These are internal PHY blocks, requiring specific SoC hardware or MDIO buses that are *not* emulated in standard QEMU or GCE amd64 environments.

The new `AIROHA_GE_SOC_PHY` driver depends on `ARM64 || ECONET || COMPILE_TEST` and `ARCH_AIROHA || ECONET || COMPILE_TEST`, while `MEDIATEK_GE_SOC_PHY` depends on `ARM64 || COMPILE_TEST` and `(ARCH_MEDIATEK && NVMEM_MTK_EFUSE) || COMPILE_TEST`. Therefore, these code paths are exclusive to ARM64/ECONET (MIPS) architectures (excluding `COMPILE_TEST`), making them inaccessible on the target `amd64`.

This patch series clearly satisfies *both* criteria for a `WorthFuzzing` of false: structurally unreachable hardware and unreachable execution paths due to architecture constraints.

Let's double-check by reviewing the changes. The changes are entirely contained within `drivers/net/phy/mediatek/`. This excludes any impact on core phylib or core kernel subsystems. The affected drivers are explicitly SoC-internal Ethernet PHY drivers for MediaTek and Airoha for ARM64/MIPS. There's nothing generic or core here. All changes are contained within the `mediatek` subtree. The drivers are unreachable in amd64 environments, confirming my initial assessment.

Therefore, the arguments for `set-results` should be:

*   `WorthFuzzing`: false
*   `Reasoning`: The patch series introduces a new PHY driver for Airoha SoC built-in Gigabit Ethernet PHYs (AN7581, AN7583, EN7528) and refactors shared helper code for MediaTek/Airoha SoC PHYs. These drivers are designed specifically for built-in PHYs in Airoha (ARCH_AIROHA, ARM64/MIPS) and MediaTek (ARCH_MEDIATEK) SoCs. On the target architecture (amd64), this SoC-specific hardware is physically absent and cannot be emulated in standard QEMU/GCE virtualized environments, making the code structurally unreachable for fuzzing.
*   `FocusSymbols`: \[ ]
*   `EnableConfigs`: \[ ]

I'm confident in this decision. Calling `set-results` now.



28/2 2026/11/06 03:08 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch series introduces a dedicated driver for Airoha SoC built-in Gigabit Ethernet PHYs (AN7581, AN7583, EN7528) and refactors common helpers across MediaTek and Airoha SoC PHY drivers. All modified code is strictly confined to drivers/net/phy/mediatek/ and targets internal PHYs integrated into Airoha (ARCH_AIROHA/ECONET, ARM64/MIPS) and MediaTek (ARCH_MEDIATEK) SoCs. On the target architecture (amd64), this SoC-specific hardware is physically absent and not emulated in standard QEMU/GCE environments, making the modified code structurally unreachable.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series introduces a dedicated driver for Airoha SoC built-in Gigabit Ethernet PHYs (AN7581, AN7583, EN7528) and refactors common helpers across MediaTek and Airoha SoC PHY drivers. All modified code is strictly confined to drivers/net/phy/mediatek/ and targets internal PHYs integrated into Airoha (ARCH_AIROHA/ECONET, ARM64/MIPS) and MediaTek (ARCH_MEDIATEK) SoCs. On the target architecture (amd64), this SoC-specific hardware is physically absent and not emulated in standard QEMU/GCE environments, making the modified code structurally unreachable.",
  "WorthFuzzing": false
}

29/1 2026/11/06 03:08 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)