18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * r8169_phy_config.c: RealTek 8169/8168/8101 ethernet driver.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
68c2ecf20Sopenharmony_ci * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
78c2ecf20Sopenharmony_ci * Copyright (c) a lot of people too. Please respect their work.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * See MAINTAINERS file for support contact information.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/delay.h>
138c2ecf20Sopenharmony_ci#include <linux/phy.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "r8169.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_citypedef void (*rtl_phy_cfg_fct)(struct rtl8169_private *tp,
188c2ecf20Sopenharmony_ci				struct phy_device *phydev);
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic void r8168d_modify_extpage(struct phy_device *phydev, int extpage,
218c2ecf20Sopenharmony_ci				  int reg, u16 mask, u16 val)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	int oldpage = phy_select_page(phydev, 0x0007);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	__phy_write(phydev, 0x1e, extpage);
268c2ecf20Sopenharmony_ci	__phy_modify(phydev, reg, mask, val);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	phy_restore_page(phydev, oldpage, 0);
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic void r8168d_phy_param(struct phy_device *phydev, u16 parm,
328c2ecf20Sopenharmony_ci			     u16 mask, u16 val)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	int oldpage = phy_select_page(phydev, 0x0005);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	__phy_write(phydev, 0x05, parm);
378c2ecf20Sopenharmony_ci	__phy_modify(phydev, 0x06, mask, val);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	phy_restore_page(phydev, oldpage, 0);
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic void r8168g_phy_param(struct phy_device *phydev, u16 parm,
438c2ecf20Sopenharmony_ci			     u16 mask, u16 val)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	int oldpage = phy_select_page(phydev, 0x0a43);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	__phy_write(phydev, 0x13, parm);
488c2ecf20Sopenharmony_ci	__phy_modify(phydev, 0x14, mask, val);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	phy_restore_page(phydev, oldpage, 0);
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct phy_reg {
548c2ecf20Sopenharmony_ci	u16 reg;
558c2ecf20Sopenharmony_ci	u16 val;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic void __rtl_writephy_batch(struct phy_device *phydev,
598c2ecf20Sopenharmony_ci				 const struct phy_reg *regs, int len)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	phy_lock_mdio_bus(phydev);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	while (len-- > 0) {
648c2ecf20Sopenharmony_ci		__phy_write(phydev, regs->reg, regs->val);
658c2ecf20Sopenharmony_ci		regs++;
668c2ecf20Sopenharmony_ci	}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	phy_unlock_mdio_bus(phydev);
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define rtl_writephy_batch(p, a) __rtl_writephy_batch(p, a, ARRAY_SIZE(a))
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic void rtl8168f_config_eee_phy(struct phy_device *phydev)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0020, 0x15, 0, BIT(8));
768c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0, BIT(13));
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic void rtl8168g_config_eee_phy(struct phy_device *phydev)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a43, 0x11, 0, BIT(4));
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic void rtl8168h_config_eee_phy(struct phy_device *phydev)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa4a, 0x11, 0x0000, 0x0200);
898c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa42, 0x14, 0x0000, 0x0080);
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic void rtl8125a_config_eee_phy(struct phy_device *phydev)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	rtl8168h_config_eee_phy(phydev);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
978c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic void rtl8125b_config_eee_phy(struct phy_device *phydev)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
1038c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
1048c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa42, 0x14, 0x0080, 0x0000);
1058c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa4a, 0x11, 0x0200, 0x0000);
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic void rtl8169s_hw_phy_config(struct rtl8169_private *tp,
1098c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
1128c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
1138c2ecf20Sopenharmony_ci		{ 0x06, 0x006e },
1148c2ecf20Sopenharmony_ci		{ 0x08, 0x0708 },
1158c2ecf20Sopenharmony_ci		{ 0x15, 0x4000 },
1168c2ecf20Sopenharmony_ci		{ 0x18, 0x65c7 },
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
1198c2ecf20Sopenharmony_ci		{ 0x03, 0x00a1 },
1208c2ecf20Sopenharmony_ci		{ 0x02, 0x0008 },
1218c2ecf20Sopenharmony_ci		{ 0x01, 0x0120 },
1228c2ecf20Sopenharmony_ci		{ 0x00, 0x1000 },
1238c2ecf20Sopenharmony_ci		{ 0x04, 0x0800 },
1248c2ecf20Sopenharmony_ci		{ 0x04, 0x0000 },
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci		{ 0x03, 0xff41 },
1278c2ecf20Sopenharmony_ci		{ 0x02, 0xdf60 },
1288c2ecf20Sopenharmony_ci		{ 0x01, 0x0140 },
1298c2ecf20Sopenharmony_ci		{ 0x00, 0x0077 },
1308c2ecf20Sopenharmony_ci		{ 0x04, 0x7800 },
1318c2ecf20Sopenharmony_ci		{ 0x04, 0x7000 },
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci		{ 0x03, 0x802f },
1348c2ecf20Sopenharmony_ci		{ 0x02, 0x4f02 },
1358c2ecf20Sopenharmony_ci		{ 0x01, 0x0409 },
1368c2ecf20Sopenharmony_ci		{ 0x00, 0xf0f9 },
1378c2ecf20Sopenharmony_ci		{ 0x04, 0x9800 },
1388c2ecf20Sopenharmony_ci		{ 0x04, 0x9000 },
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
1418c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
1428c2ecf20Sopenharmony_ci		{ 0x01, 0xff95 },
1438c2ecf20Sopenharmony_ci		{ 0x00, 0xba00 },
1448c2ecf20Sopenharmony_ci		{ 0x04, 0xa800 },
1458c2ecf20Sopenharmony_ci		{ 0x04, 0xa000 },
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci		{ 0x03, 0xff41 },
1488c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
1498c2ecf20Sopenharmony_ci		{ 0x01, 0x0140 },
1508c2ecf20Sopenharmony_ci		{ 0x00, 0x00bb },
1518c2ecf20Sopenharmony_ci		{ 0x04, 0xb800 },
1528c2ecf20Sopenharmony_ci		{ 0x04, 0xb000 },
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci		{ 0x03, 0xdf41 },
1558c2ecf20Sopenharmony_ci		{ 0x02, 0xdc60 },
1568c2ecf20Sopenharmony_ci		{ 0x01, 0x6340 },
1578c2ecf20Sopenharmony_ci		{ 0x00, 0x007d },
1588c2ecf20Sopenharmony_ci		{ 0x04, 0xd800 },
1598c2ecf20Sopenharmony_ci		{ 0x04, 0xd000 },
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
1628c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
1638c2ecf20Sopenharmony_ci		{ 0x01, 0x100a },
1648c2ecf20Sopenharmony_ci		{ 0x00, 0xa0ff },
1658c2ecf20Sopenharmony_ci		{ 0x04, 0xf800 },
1668c2ecf20Sopenharmony_ci		{ 0x04, 0xf000 },
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
1698c2ecf20Sopenharmony_ci		{ 0x0b, 0x0000 },
1708c2ecf20Sopenharmony_ci		{ 0x00, 0x9200 }
1718c2ecf20Sopenharmony_ci	};
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
1748c2ecf20Sopenharmony_ci}
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistatic void rtl8169sb_hw_phy_config(struct rtl8169_private *tp,
1778c2ecf20Sopenharmony_ci				    struct phy_device *phydev)
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0002, 0x01, 0x90d0);
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic void rtl8169scd_hw_phy_config(struct rtl8169_private *tp,
1838c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
1868c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
1878c2ecf20Sopenharmony_ci		{ 0x04, 0x0000 },
1888c2ecf20Sopenharmony_ci		{ 0x03, 0x00a1 },
1898c2ecf20Sopenharmony_ci		{ 0x02, 0x0008 },
1908c2ecf20Sopenharmony_ci		{ 0x01, 0x0120 },
1918c2ecf20Sopenharmony_ci		{ 0x00, 0x1000 },
1928c2ecf20Sopenharmony_ci		{ 0x04, 0x0800 },
1938c2ecf20Sopenharmony_ci		{ 0x04, 0x9000 },
1948c2ecf20Sopenharmony_ci		{ 0x03, 0x802f },
1958c2ecf20Sopenharmony_ci		{ 0x02, 0x4f02 },
1968c2ecf20Sopenharmony_ci		{ 0x01, 0x0409 },
1978c2ecf20Sopenharmony_ci		{ 0x00, 0xf099 },
1988c2ecf20Sopenharmony_ci		{ 0x04, 0x9800 },
1998c2ecf20Sopenharmony_ci		{ 0x04, 0xa000 },
2008c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
2018c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
2028c2ecf20Sopenharmony_ci		{ 0x01, 0xff95 },
2038c2ecf20Sopenharmony_ci		{ 0x00, 0xba00 },
2048c2ecf20Sopenharmony_ci		{ 0x04, 0xa800 },
2058c2ecf20Sopenharmony_ci		{ 0x04, 0xf000 },
2068c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
2078c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
2088c2ecf20Sopenharmony_ci		{ 0x01, 0x101a },
2098c2ecf20Sopenharmony_ci		{ 0x00, 0xa0ff },
2108c2ecf20Sopenharmony_ci		{ 0x04, 0xf800 },
2118c2ecf20Sopenharmony_ci		{ 0x04, 0x0000 },
2128c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2158c2ecf20Sopenharmony_ci		{ 0x10, 0xf41b },
2168c2ecf20Sopenharmony_ci		{ 0x14, 0xfb54 },
2178c2ecf20Sopenharmony_ci		{ 0x18, 0xf5c7 },
2188c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2218c2ecf20Sopenharmony_ci		{ 0x17, 0x0cc0 },
2228c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
2238c2ecf20Sopenharmony_ci	};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic void rtl8169sce_hw_phy_config(struct rtl8169_private *tp,
2298c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
2328c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2338c2ecf20Sopenharmony_ci		{ 0x04, 0x0000 },
2348c2ecf20Sopenharmony_ci		{ 0x03, 0x00a1 },
2358c2ecf20Sopenharmony_ci		{ 0x02, 0x0008 },
2368c2ecf20Sopenharmony_ci		{ 0x01, 0x0120 },
2378c2ecf20Sopenharmony_ci		{ 0x00, 0x1000 },
2388c2ecf20Sopenharmony_ci		{ 0x04, 0x0800 },
2398c2ecf20Sopenharmony_ci		{ 0x04, 0x9000 },
2408c2ecf20Sopenharmony_ci		{ 0x03, 0x802f },
2418c2ecf20Sopenharmony_ci		{ 0x02, 0x4f02 },
2428c2ecf20Sopenharmony_ci		{ 0x01, 0x0409 },
2438c2ecf20Sopenharmony_ci		{ 0x00, 0xf099 },
2448c2ecf20Sopenharmony_ci		{ 0x04, 0x9800 },
2458c2ecf20Sopenharmony_ci		{ 0x04, 0xa000 },
2468c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
2478c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
2488c2ecf20Sopenharmony_ci		{ 0x01, 0xff95 },
2498c2ecf20Sopenharmony_ci		{ 0x00, 0xba00 },
2508c2ecf20Sopenharmony_ci		{ 0x04, 0xa800 },
2518c2ecf20Sopenharmony_ci		{ 0x04, 0xf000 },
2528c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
2538c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
2548c2ecf20Sopenharmony_ci		{ 0x01, 0x101a },
2558c2ecf20Sopenharmony_ci		{ 0x00, 0xa0ff },
2568c2ecf20Sopenharmony_ci		{ 0x04, 0xf800 },
2578c2ecf20Sopenharmony_ci		{ 0x04, 0x0000 },
2588c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2618c2ecf20Sopenharmony_ci		{ 0x0b, 0x8480 },
2628c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2658c2ecf20Sopenharmony_ci		{ 0x18, 0x67c7 },
2668c2ecf20Sopenharmony_ci		{ 0x04, 0x2000 },
2678c2ecf20Sopenharmony_ci		{ 0x03, 0x002f },
2688c2ecf20Sopenharmony_ci		{ 0x02, 0x4360 },
2698c2ecf20Sopenharmony_ci		{ 0x01, 0x0109 },
2708c2ecf20Sopenharmony_ci		{ 0x00, 0x3022 },
2718c2ecf20Sopenharmony_ci		{ 0x04, 0x2800 },
2728c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
2758c2ecf20Sopenharmony_ci		{ 0x17, 0x0cc0 },
2768c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
2778c2ecf20Sopenharmony_ci	};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
2808c2ecf20Sopenharmony_ci}
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistatic void rtl8168bb_hw_phy_config(struct rtl8169_private *tp,
2838c2ecf20Sopenharmony_ci				    struct phy_device *phydev)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0001);
2868c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x16, BIT(0));
2878c2ecf20Sopenharmony_ci	phy_write(phydev, 0x10, 0xf41b);
2888c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
2898c2ecf20Sopenharmony_ci}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_cistatic void rtl8168bef_hw_phy_config(struct rtl8169_private *tp,
2928c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
2938c2ecf20Sopenharmony_ci{
2948c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0001, 0x10, 0xf41b);
2958c2ecf20Sopenharmony_ci}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistatic void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp,
2988c2ecf20Sopenharmony_ci				      struct phy_device *phydev)
2998c2ecf20Sopenharmony_ci{
3008c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1d, 0x0f00);
3018c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0002, 0x0c, 0x1ec8);
3028c2ecf20Sopenharmony_ci}
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistatic void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp,
3058c2ecf20Sopenharmony_ci				      struct phy_device *phydev)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(5));
3088c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, BIT(5));
3098c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0001, 0x1d, 0x3d98);
3108c2ecf20Sopenharmony_ci}
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistatic void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp,
3138c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
3148c2ecf20Sopenharmony_ci{
3158c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
3168c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
3178c2ecf20Sopenharmony_ci		{ 0x12, 0x2300 },
3188c2ecf20Sopenharmony_ci		{ 0x1f, 0x0002 },
3198c2ecf20Sopenharmony_ci		{ 0x00, 0x88d4 },
3208c2ecf20Sopenharmony_ci		{ 0x01, 0x82b1 },
3218c2ecf20Sopenharmony_ci		{ 0x03, 0x7002 },
3228c2ecf20Sopenharmony_ci		{ 0x08, 0x9e30 },
3238c2ecf20Sopenharmony_ci		{ 0x09, 0x01f0 },
3248c2ecf20Sopenharmony_ci		{ 0x0a, 0x5500 },
3258c2ecf20Sopenharmony_ci		{ 0x0c, 0x00c8 },
3268c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
3278c2ecf20Sopenharmony_ci		{ 0x12, 0xc096 },
3288c2ecf20Sopenharmony_ci		{ 0x16, 0x000a },
3298c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
3308c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
3318c2ecf20Sopenharmony_ci		{ 0x09, 0x2000 },
3328c2ecf20Sopenharmony_ci		{ 0x09, 0x0000 }
3338c2ecf20Sopenharmony_ci	};
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(5));
3388c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, BIT(5));
3398c2ecf20Sopenharmony_ci}
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_cistatic void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp,
3428c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
3438c2ecf20Sopenharmony_ci{
3448c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
3458c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
3468c2ecf20Sopenharmony_ci		{ 0x12, 0x2300 },
3478c2ecf20Sopenharmony_ci		{ 0x03, 0x802f },
3488c2ecf20Sopenharmony_ci		{ 0x02, 0x4f02 },
3498c2ecf20Sopenharmony_ci		{ 0x01, 0x0409 },
3508c2ecf20Sopenharmony_ci		{ 0x00, 0xf099 },
3518c2ecf20Sopenharmony_ci		{ 0x04, 0x9800 },
3528c2ecf20Sopenharmony_ci		{ 0x04, 0x9000 },
3538c2ecf20Sopenharmony_ci		{ 0x1d, 0x3d98 },
3548c2ecf20Sopenharmony_ci		{ 0x1f, 0x0002 },
3558c2ecf20Sopenharmony_ci		{ 0x0c, 0x7eb8 },
3568c2ecf20Sopenharmony_ci		{ 0x06, 0x0761 },
3578c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
3588c2ecf20Sopenharmony_ci		{ 0x16, 0x0f0a },
3598c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
3608c2ecf20Sopenharmony_ci	};
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x16, BIT(0));
3658c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(5));
3668c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, BIT(5));
3678c2ecf20Sopenharmony_ci}
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp,
3708c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
3738c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
3748c2ecf20Sopenharmony_ci		{ 0x12, 0x2300 },
3758c2ecf20Sopenharmony_ci		{ 0x1d, 0x3d98 },
3768c2ecf20Sopenharmony_ci		{ 0x1f, 0x0002 },
3778c2ecf20Sopenharmony_ci		{ 0x0c, 0x7eb8 },
3788c2ecf20Sopenharmony_ci		{ 0x06, 0x5461 },
3798c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
3808c2ecf20Sopenharmony_ci		{ 0x16, 0x0f0a },
3818c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
3828c2ecf20Sopenharmony_ci	};
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x16, BIT(0));
3878c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(5));
3888c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, BIT(5));
3898c2ecf20Sopenharmony_ci}
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_cistatic const struct phy_reg rtl8168d_1_phy_reg_init_0[] = {
3928c2ecf20Sopenharmony_ci	/* Channel Estimation */
3938c2ecf20Sopenharmony_ci	{ 0x1f, 0x0001 },
3948c2ecf20Sopenharmony_ci	{ 0x06, 0x4064 },
3958c2ecf20Sopenharmony_ci	{ 0x07, 0x2863 },
3968c2ecf20Sopenharmony_ci	{ 0x08, 0x059c },
3978c2ecf20Sopenharmony_ci	{ 0x09, 0x26b4 },
3988c2ecf20Sopenharmony_ci	{ 0x0a, 0x6a19 },
3998c2ecf20Sopenharmony_ci	{ 0x0b, 0xdcc8 },
4008c2ecf20Sopenharmony_ci	{ 0x10, 0xf06d },
4018c2ecf20Sopenharmony_ci	{ 0x14, 0x7f68 },
4028c2ecf20Sopenharmony_ci	{ 0x18, 0x7fd9 },
4038c2ecf20Sopenharmony_ci	{ 0x1c, 0xf0ff },
4048c2ecf20Sopenharmony_ci	{ 0x1d, 0x3d9c },
4058c2ecf20Sopenharmony_ci	{ 0x1f, 0x0003 },
4068c2ecf20Sopenharmony_ci	{ 0x12, 0xf49f },
4078c2ecf20Sopenharmony_ci	{ 0x13, 0x070b },
4088c2ecf20Sopenharmony_ci	{ 0x1a, 0x05ad },
4098c2ecf20Sopenharmony_ci	{ 0x14, 0x94c0 },
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	/*
4128c2ecf20Sopenharmony_ci	 * Tx Error Issue
4138c2ecf20Sopenharmony_ci	 * Enhance line driver power
4148c2ecf20Sopenharmony_ci	 */
4158c2ecf20Sopenharmony_ci	{ 0x1f, 0x0002 },
4168c2ecf20Sopenharmony_ci	{ 0x06, 0x5561 },
4178c2ecf20Sopenharmony_ci	{ 0x1f, 0x0005 },
4188c2ecf20Sopenharmony_ci	{ 0x05, 0x8332 },
4198c2ecf20Sopenharmony_ci	{ 0x06, 0x5561 },
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	/*
4228c2ecf20Sopenharmony_ci	 * Can not link to 1Gbps with bad cable
4238c2ecf20Sopenharmony_ci	 * Decrease SNR threshold form 21.07dB to 19.04dB
4248c2ecf20Sopenharmony_ci	 */
4258c2ecf20Sopenharmony_ci	{ 0x1f, 0x0001 },
4268c2ecf20Sopenharmony_ci	{ 0x17, 0x0cc0 },
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	{ 0x1f, 0x0000 },
4298c2ecf20Sopenharmony_ci	{ 0x0d, 0xf880 }
4308c2ecf20Sopenharmony_ci};
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic const struct phy_reg rtl8168d_1_phy_reg_init_1[] = {
4338c2ecf20Sopenharmony_ci	{ 0x1f, 0x0002 },
4348c2ecf20Sopenharmony_ci	{ 0x05, 0x669a },
4358c2ecf20Sopenharmony_ci	{ 0x1f, 0x0005 },
4368c2ecf20Sopenharmony_ci	{ 0x05, 0x8330 },
4378c2ecf20Sopenharmony_ci	{ 0x06, 0x669a },
4388c2ecf20Sopenharmony_ci	{ 0x1f, 0x0002 }
4398c2ecf20Sopenharmony_ci};
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp,
4428c2ecf20Sopenharmony_ci					 struct phy_device *phydev,
4438c2ecf20Sopenharmony_ci					 u16 val)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	u16 reg_val;
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0005);
4488c2ecf20Sopenharmony_ci	phy_write(phydev, 0x05, 0x001b);
4498c2ecf20Sopenharmony_ci	reg_val = phy_read(phydev, 0x06);
4508c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	if (reg_val != val)
4538c2ecf20Sopenharmony_ci		phydev_warn(phydev, "chipset not ready for firmware\n");
4548c2ecf20Sopenharmony_ci	else
4558c2ecf20Sopenharmony_ci		r8169_apply_firmware(tp);
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp,
4598c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
4608c2ecf20Sopenharmony_ci{
4618c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	/*
4648c2ecf20Sopenharmony_ci	 * Rx Error Issue
4658c2ecf20Sopenharmony_ci	 * Fine Tune Switching regulator parameter
4668c2ecf20Sopenharmony_ci	 */
4678c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0002);
4688c2ecf20Sopenharmony_ci	phy_modify(phydev, 0x0b, 0x00ef, 0x0010);
4698c2ecf20Sopenharmony_ci	phy_modify(phydev, 0x0c, 0x5d00, 0xa200);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
4728c2ecf20Sopenharmony_ci		int val;
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci		rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_1);
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci		val = phy_read(phydev, 0x0d);
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci		if ((val & 0x00ff) != 0x006c) {
4798c2ecf20Sopenharmony_ci			static const u32 set[] = {
4808c2ecf20Sopenharmony_ci				0x0065, 0x0066, 0x0067, 0x0068,
4818c2ecf20Sopenharmony_ci				0x0069, 0x006a, 0x006b, 0x006c
4828c2ecf20Sopenharmony_ci			};
4838c2ecf20Sopenharmony_ci			int i;
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci			phy_write(phydev, 0x1f, 0x0002);
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci			val &= 0xff00;
4888c2ecf20Sopenharmony_ci			for (i = 0; i < ARRAY_SIZE(set); i++)
4898c2ecf20Sopenharmony_ci				phy_write(phydev, 0x0d, val | set[i]);
4908c2ecf20Sopenharmony_ci		}
4918c2ecf20Sopenharmony_ci	} else {
4928c2ecf20Sopenharmony_ci		phy_write_paged(phydev, 0x0002, 0x05, 0x6662);
4938c2ecf20Sopenharmony_ci		r8168d_phy_param(phydev, 0x8330, 0xffff, 0x6662);
4948c2ecf20Sopenharmony_ci	}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	/* RSET couple improve */
4978c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0002);
4988c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, 0x0300);
4998c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0f, 0x0010);
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	/* Fine tune PLL performance */
5028c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0002);
5038c2ecf20Sopenharmony_ci	phy_modify(phydev, 0x02, 0x0600, 0x0100);
5048c2ecf20Sopenharmony_ci	phy_clear_bits(phydev, 0x03, 0xe000);
5058c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	rtl8168d_apply_firmware_cond(tp, phydev, 0xbf00);
5088c2ecf20Sopenharmony_ci}
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cistatic void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp,
5118c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
5128c2ecf20Sopenharmony_ci{
5138c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
5168c2ecf20Sopenharmony_ci		int val;
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci		rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_1);
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci		val = phy_read(phydev, 0x0d);
5218c2ecf20Sopenharmony_ci		if ((val & 0x00ff) != 0x006c) {
5228c2ecf20Sopenharmony_ci			static const u32 set[] = {
5238c2ecf20Sopenharmony_ci				0x0065, 0x0066, 0x0067, 0x0068,
5248c2ecf20Sopenharmony_ci				0x0069, 0x006a, 0x006b, 0x006c
5258c2ecf20Sopenharmony_ci			};
5268c2ecf20Sopenharmony_ci			int i;
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci			phy_write(phydev, 0x1f, 0x0002);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci			val &= 0xff00;
5318c2ecf20Sopenharmony_ci			for (i = 0; i < ARRAY_SIZE(set); i++)
5328c2ecf20Sopenharmony_ci				phy_write(phydev, 0x0d, val | set[i]);
5338c2ecf20Sopenharmony_ci		}
5348c2ecf20Sopenharmony_ci	} else {
5358c2ecf20Sopenharmony_ci		phy_write_paged(phydev, 0x0002, 0x05, 0x2642);
5368c2ecf20Sopenharmony_ci		r8168d_phy_param(phydev, 0x8330, 0xffff, 0x2642);
5378c2ecf20Sopenharmony_ci	}
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	/* Fine tune PLL performance */
5408c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0002);
5418c2ecf20Sopenharmony_ci	phy_modify(phydev, 0x02, 0x0600, 0x0100);
5428c2ecf20Sopenharmony_ci	phy_clear_bits(phydev, 0x03, 0xe000);
5438c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci	/* Switching regulator Slew rate */
5468c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0017);
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	rtl8168d_apply_firmware_cond(tp, phydev, 0xb300);
5498c2ecf20Sopenharmony_ci}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_cistatic void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp,
5528c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
5538c2ecf20Sopenharmony_ci{
5548c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
5558c2ecf20Sopenharmony_ci		{ 0x1f, 0x0002 },
5568c2ecf20Sopenharmony_ci		{ 0x10, 0x0008 },
5578c2ecf20Sopenharmony_ci		{ 0x0d, 0x006c },
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
5608c2ecf20Sopenharmony_ci		{ 0x0d, 0xf880 },
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
5638c2ecf20Sopenharmony_ci		{ 0x17, 0x0cc0 },
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
5668c2ecf20Sopenharmony_ci		{ 0x0b, 0xa4d8 },
5678c2ecf20Sopenharmony_ci		{ 0x09, 0x281c },
5688c2ecf20Sopenharmony_ci		{ 0x07, 0x2883 },
5698c2ecf20Sopenharmony_ci		{ 0x0a, 0x6b35 },
5708c2ecf20Sopenharmony_ci		{ 0x1d, 0x3da4 },
5718c2ecf20Sopenharmony_ci		{ 0x1c, 0xeffd },
5728c2ecf20Sopenharmony_ci		{ 0x14, 0x7f52 },
5738c2ecf20Sopenharmony_ci		{ 0x18, 0x7fc6 },
5748c2ecf20Sopenharmony_ci		{ 0x08, 0x0601 },
5758c2ecf20Sopenharmony_ci		{ 0x06, 0x4063 },
5768c2ecf20Sopenharmony_ci		{ 0x10, 0xf074 },
5778c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
5788c2ecf20Sopenharmony_ci		{ 0x13, 0x0789 },
5798c2ecf20Sopenharmony_ci		{ 0x12, 0xf4bd },
5808c2ecf20Sopenharmony_ci		{ 0x1a, 0x04fd },
5818c2ecf20Sopenharmony_ci		{ 0x14, 0x84b0 },
5828c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
5838c2ecf20Sopenharmony_ci		{ 0x00, 0x9200 },
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci		{ 0x1f, 0x0005 },
5868c2ecf20Sopenharmony_ci		{ 0x01, 0x0340 },
5878c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
5888c2ecf20Sopenharmony_ci		{ 0x04, 0x4000 },
5898c2ecf20Sopenharmony_ci		{ 0x03, 0x1d21 },
5908c2ecf20Sopenharmony_ci		{ 0x02, 0x0c32 },
5918c2ecf20Sopenharmony_ci		{ 0x01, 0x0200 },
5928c2ecf20Sopenharmony_ci		{ 0x00, 0x5554 },
5938c2ecf20Sopenharmony_ci		{ 0x04, 0x4800 },
5948c2ecf20Sopenharmony_ci		{ 0x04, 0x4000 },
5958c2ecf20Sopenharmony_ci		{ 0x04, 0xf000 },
5968c2ecf20Sopenharmony_ci		{ 0x03, 0xdf01 },
5978c2ecf20Sopenharmony_ci		{ 0x02, 0xdf20 },
5988c2ecf20Sopenharmony_ci		{ 0x01, 0x101a },
5998c2ecf20Sopenharmony_ci		{ 0x00, 0xa0ff },
6008c2ecf20Sopenharmony_ci		{ 0x04, 0xf800 },
6018c2ecf20Sopenharmony_ci		{ 0x04, 0xf000 },
6028c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
6038c2ecf20Sopenharmony_ci	};
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
6068c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0023, 0x16, 0xffff, 0x0000);
6078c2ecf20Sopenharmony_ci}
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_cistatic void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp,
6108c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
6118c2ecf20Sopenharmony_ci{
6128c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0001, 0x17, 0x0cc0);
6138c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0xffff, 0x0040);
6148c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x0d, BIT(5));
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp,
6188c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
6198c2ecf20Sopenharmony_ci{
6208c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
6218c2ecf20Sopenharmony_ci		/* Channel estimation fine tune */
6228c2ecf20Sopenharmony_ci		{ 0x1f, 0x0001 },
6238c2ecf20Sopenharmony_ci		{ 0x0b, 0x6c20 },
6248c2ecf20Sopenharmony_ci		{ 0x07, 0x2872 },
6258c2ecf20Sopenharmony_ci		{ 0x1c, 0xefff },
6268c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
6278c2ecf20Sopenharmony_ci		{ 0x14, 0x6420 },
6288c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 },
6298c2ecf20Sopenharmony_ci	};
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	/* Enable Delay cap */
6348c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b80, 0xffff, 0xc896);
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	/* Update PFM & 10M TX idle timer */
6398c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x002f, 0x15, 0xffff, 0x1919);
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	/* DCO enable for 10M IDLE Power */
6448c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0023, 0x17, 0x0000, 0x0006);
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci	/* For impedance matching */
6478c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0002, 0x08, 0x7f00, 0x8000);
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	/* PHY auto speed down */
6508c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0050);
6518c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(15));
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
6548c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0x2000, 0x0000);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0020, 0x15, 0x1100, 0x0000);
6578c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0006, 0x00, 0x5a00);
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0000);
6608c2ecf20Sopenharmony_ci}
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_cistatic void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp,
6638c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
6648c2ecf20Sopenharmony_ci{
6658c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci	/* Enable Delay cap */
6688c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_ci	/* Channel estimation fine tune */
6718c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	/* Green Setting */
6748c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b5b, 0xffff, 0x9222);
6758c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b6d, 0xffff, 0x8000);
6768c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b76, 0xffff, 0x8000);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	/* For 4-corner performance improve */
6798c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0005);
6808c2ecf20Sopenharmony_ci	phy_write(phydev, 0x05, 0x8b80);
6818c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x17, 0x0006);
6828c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	/* PHY auto speed down */
6858c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
6868c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(15));
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	/* improve 10M EEE waveform */
6898c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	/* Improve 2-pair detection performance */
6928c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	rtl8168f_config_eee_phy(phydev);
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	/* Green feature */
6978c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0003);
6988c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x19, BIT(0));
6998c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x10, BIT(10));
7008c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
7018c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0005, 0x01, 0, BIT(8));
7028c2ecf20Sopenharmony_ci}
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_cistatic void rtl8168f_hw_phy_config(struct rtl8169_private *tp,
7058c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
7068c2ecf20Sopenharmony_ci{
7078c2ecf20Sopenharmony_ci	/* For 4-corner performance improve */
7088c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b80, 0x0000, 0x0006);
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	/* PHY auto speed down */
7118c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
7128c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x14, BIT(15));
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	/* Improve 10M EEE waveform */
7158c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci	rtl8168f_config_eee_phy(phydev);
7188c2ecf20Sopenharmony_ci}
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp,
7218c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
7228c2ecf20Sopenharmony_ci{
7238c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	/* Channel estimation fine tune */
7268c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	/* Modify green table for giga & fnet */
7298c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
7308c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
7318c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
7328c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
7338c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
7348c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00fb);
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	/* Modify green table for 10M */
7378c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	/* Disable hiimpedance detection (RTCT) */
7408c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci	rtl8168f_hw_phy_config(tp, phydev);
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	/* Improve 2-pair detection performance */
7458c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
7468c2ecf20Sopenharmony_ci}
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_cistatic void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp,
7498c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
7508c2ecf20Sopenharmony_ci{
7518c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	rtl8168f_hw_phy_config(tp, phydev);
7548c2ecf20Sopenharmony_ci}
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_cistatic void rtl8411_hw_phy_config(struct rtl8169_private *tp,
7578c2ecf20Sopenharmony_ci				  struct phy_device *phydev)
7588c2ecf20Sopenharmony_ci{
7598c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci	rtl8168f_hw_phy_config(tp, phydev);
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci	/* Improve 2-pair detection performance */
7648c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci	/* Channel estimation fine tune */
7678c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci	/* Modify green table for giga & fnet */
7708c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
7718c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
7728c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
7738c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
7748c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
7758c2ecf20Sopenharmony_ci	r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00aa);
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	/* Modify green table for 10M */
7788c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci	/* Disable hiimpedance detection (RTCT) */
7818c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	/* Modify green table for giga */
7848c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b54, 0x0800, 0x0000);
7858c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b5d, 0x0800, 0x0000);
7868c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8a7c, 0x0100, 0x0000);
7878c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8a7f, 0x0000, 0x0100);
7888c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8a82, 0x0100, 0x0000);
7898c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8a85, 0x0100, 0x0000);
7908c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8a88, 0x0100, 0x0000);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	/* uc same-seed solution */
7938c2ecf20Sopenharmony_ci	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x8000);
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci	/* Green feature */
7968c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0003);
7978c2ecf20Sopenharmony_ci	phy_clear_bits(phydev, 0x19, BIT(0));
7988c2ecf20Sopenharmony_ci	phy_clear_bits(phydev, 0x10, BIT(10));
7998c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
8008c2ecf20Sopenharmony_ci}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_cistatic void rtl8168g_disable_aldps(struct phy_device *phydev)
8038c2ecf20Sopenharmony_ci{
8048c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a43, 0x10, BIT(2), 0);
8058c2ecf20Sopenharmony_ci}
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_cistatic void rtl8168g_enable_gphy_10m(struct phy_device *phydev)
8088c2ecf20Sopenharmony_ci{
8098c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(11));
8108c2ecf20Sopenharmony_ci}
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_cistatic void rtl8168g_phy_adjust_10m_aldps(struct phy_device *phydev)
8138c2ecf20Sopenharmony_ci{
8148c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0);
8158c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6));
8168c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8084, 0x6000, 0x0000);
8178c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a43, 0x10, 0x0000, 0x1003);
8188c2ecf20Sopenharmony_ci}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cistatic void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp,
8218c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
8228c2ecf20Sopenharmony_ci{
8238c2ecf20Sopenharmony_ci	int ret;
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ci	ret = phy_read_paged(phydev, 0x0a46, 0x10);
8288c2ecf20Sopenharmony_ci	if (ret & BIT(8))
8298c2ecf20Sopenharmony_ci		phy_modify_paged(phydev, 0x0bcc, 0x12, BIT(15), 0);
8308c2ecf20Sopenharmony_ci	else
8318c2ecf20Sopenharmony_ci		phy_modify_paged(phydev, 0x0bcc, 0x12, 0, BIT(15));
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci	ret = phy_read_paged(phydev, 0x0a46, 0x13);
8348c2ecf20Sopenharmony_ci	if (ret & BIT(8))
8358c2ecf20Sopenharmony_ci		phy_modify_paged(phydev, 0x0c41, 0x15, 0, BIT(1));
8368c2ecf20Sopenharmony_ci	else
8378c2ecf20Sopenharmony_ci		phy_modify_paged(phydev, 0x0c41, 0x15, BIT(1), 0);
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	/* Enable PHY auto speed down */
8408c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	rtl8168g_phy_adjust_10m_aldps(phydev);
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	/* EEE auto-fallback function */
8458c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2));
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	/* Enable UC LPF tune function */
8488c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci	/* Improve SWR Efficiency */
8538c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bcd);
8548c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x5065);
8558c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0xd065);
8568c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bc8);
8578c2ecf20Sopenharmony_ci	phy_write(phydev, 0x11, 0x5655);
8588c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bcd);
8598c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x1065);
8608c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x9065);
8618c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x1065);
8628c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
8658c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
8668c2ecf20Sopenharmony_ci}
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_cistatic void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp,
8698c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
8708c2ecf20Sopenharmony_ci{
8718c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
8728c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
8738c2ecf20Sopenharmony_ci}
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_cistatic void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp,
8768c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
8778c2ecf20Sopenharmony_ci{
8788c2ecf20Sopenharmony_ci	u16 dout_tapbin;
8798c2ecf20Sopenharmony_ci	u32 data;
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci	/* CHN EST parameters adjust - giga master */
8848c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809b, 0xf800, 0x8000);
8858c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x8000);
8868c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80a4, 0xff00, 0x8500);
8878c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809c, 0xff00, 0xbd00);
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci	/* CHN EST parameters adjust - giga slave */
8908c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x7000);
8918c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80b4, 0xff00, 0x5000);
8928c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ac, 0xff00, 0x4000);
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci	/* CHN EST parameters adjust - fnet */
8958c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808e, 0xff00, 0x1200);
8968c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8090, 0xff00, 0xe500);
8978c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8092, 0xff00, 0x9f00);
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	/* enable R-tune & PGA-retune function */
9008c2ecf20Sopenharmony_ci	dout_tapbin = 0;
9018c2ecf20Sopenharmony_ci	data = phy_read_paged(phydev, 0x0a46, 0x13);
9028c2ecf20Sopenharmony_ci	data &= 3;
9038c2ecf20Sopenharmony_ci	data <<= 2;
9048c2ecf20Sopenharmony_ci	dout_tapbin |= data;
9058c2ecf20Sopenharmony_ci	data = phy_read_paged(phydev, 0x0a46, 0x12);
9068c2ecf20Sopenharmony_ci	data &= 0xc000;
9078c2ecf20Sopenharmony_ci	data >>= 14;
9088c2ecf20Sopenharmony_ci	dout_tapbin |= data;
9098c2ecf20Sopenharmony_ci	dout_tapbin = ~(dout_tapbin ^ 0x08);
9108c2ecf20Sopenharmony_ci	dout_tapbin <<= 12;
9118c2ecf20Sopenharmony_ci	dout_tapbin &= 0xf000;
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x827a, 0xf000, dout_tapbin);
9148c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x827b, 0xf000, dout_tapbin);
9158c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x827c, 0xf000, dout_tapbin);
9168c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x827d, 0xf000, dout_tapbin);
9178c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800);
9188c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002);
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci	rtl8168g_enable_gphy_10m(phydev);
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	/* SAR ADC performance */
9238c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0bca, 0x17, BIT(12) | BIT(13), BIT(14));
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x803f, 0x3000, 0x0000);
9268c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8047, 0x3000, 0x0000);
9278c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x804f, 0x3000, 0x0000);
9288c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8057, 0x3000, 0x0000);
9298c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x805f, 0x3000, 0x0000);
9308c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8067, 0x3000, 0x0000);
9318c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x806f, 0x3000, 0x0000);
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	/* disable phy pfm mode */
9348c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
9378c2ecf20Sopenharmony_ci	rtl8168h_config_eee_phy(phydev);
9388c2ecf20Sopenharmony_ci}
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_cistatic void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp,
9418c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
9428c2ecf20Sopenharmony_ci{
9438c2ecf20Sopenharmony_ci	u16 ioffset, rlen;
9448c2ecf20Sopenharmony_ci	u32 data;
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	/* CHIN EST parameter update */
9498c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808a, 0x003f, 0x000a);
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	/* enable R-tune & PGA-retune function */
9528c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800);
9538c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002);
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_ci	rtl8168g_enable_gphy_10m(phydev);
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	ioffset = rtl8168h_2_get_adc_bias_ioffset(tp);
9588c2ecf20Sopenharmony_ci	if (ioffset != 0xffff)
9598c2ecf20Sopenharmony_ci		phy_write_paged(phydev, 0x0bcf, 0x16, ioffset);
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	/* Modify rlen (TX LPF corner frequency) level */
9628c2ecf20Sopenharmony_ci	data = phy_read_paged(phydev, 0x0bcd, 0x16);
9638c2ecf20Sopenharmony_ci	data &= 0x000f;
9648c2ecf20Sopenharmony_ci	rlen = 0;
9658c2ecf20Sopenharmony_ci	if (data > 3)
9668c2ecf20Sopenharmony_ci		rlen = data - 3;
9678c2ecf20Sopenharmony_ci	data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12);
9688c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0bcd, 0x17, data);
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	/* disable phy pfm mode */
9718c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci	/* disable 10m pll off */
9748c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a43, 0x10, BIT(0), 0);
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
9778c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
9788c2ecf20Sopenharmony_ci}
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_cistatic void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp,
9818c2ecf20Sopenharmony_ci				      struct phy_device *phydev)
9828c2ecf20Sopenharmony_ci{
9838c2ecf20Sopenharmony_ci	/* Enable PHY auto speed down */
9848c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_ci	rtl8168g_phy_adjust_10m_aldps(phydev);
9878c2ecf20Sopenharmony_ci
9888c2ecf20Sopenharmony_ci	/* Enable EEE auto-fallback function */
9898c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2));
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci	/* Enable UC LPF tune function */
9928c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci	/* set rg_sel_sdm_rate */
9958c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
9988c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
9998c2ecf20Sopenharmony_ci}
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_cistatic void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp,
10028c2ecf20Sopenharmony_ci				      struct phy_device *phydev)
10038c2ecf20Sopenharmony_ci{
10048c2ecf20Sopenharmony_ci	rtl8168g_phy_adjust_10m_aldps(phydev);
10058c2ecf20Sopenharmony_ci
10068c2ecf20Sopenharmony_ci	/* Enable UC LPF tune function */
10078c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci	/* Set rg_sel_sdm_rate */
10108c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci	/* Channel estimation parameters */
10138c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f3, 0xff00, 0x8b00);
10148c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f0, 0xff00, 0x3a00);
10158c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ef, 0xff00, 0x0500);
10168c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f6, 0xff00, 0x6e00);
10178c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ec, 0xff00, 0x6800);
10188c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ed, 0xff00, 0x7c00);
10198c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f2, 0xff00, 0xf400);
10208c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f4, 0xff00, 0x8500);
10218c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8110, 0xff00, 0xa800);
10228c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x810f, 0xff00, 0x1d00);
10238c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8111, 0xff00, 0xf500);
10248c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8113, 0xff00, 0x6100);
10258c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8115, 0xff00, 0x9200);
10268c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x810e, 0xff00, 0x0400);
10278c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x810c, 0xff00, 0x7c00);
10288c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x810b, 0xff00, 0x5a00);
10298c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80d1, 0xff00, 0xff00);
10308c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80cd, 0xff00, 0x9e00);
10318c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80d3, 0xff00, 0x0e00);
10328c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80d5, 0xff00, 0xca00);
10338c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80d7, 0xff00, 0x8400);
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_ci	/* Force PWM-mode */
10368c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bcd);
10378c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x5065);
10388c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0xd065);
10398c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bc8);
10408c2ecf20Sopenharmony_ci	phy_write(phydev, 0x12, 0x00ed);
10418c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0bcd);
10428c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x1065);
10438c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x9065);
10448c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x1065);
10458c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
10488c2ecf20Sopenharmony_ci	rtl8168g_config_eee_phy(phydev);
10498c2ecf20Sopenharmony_ci}
10508c2ecf20Sopenharmony_ci
10518c2ecf20Sopenharmony_cistatic void rtl8117_hw_phy_config(struct rtl8169_private *tp,
10528c2ecf20Sopenharmony_ci				  struct phy_device *phydev)
10538c2ecf20Sopenharmony_ci{
10548c2ecf20Sopenharmony_ci	/* CHN EST parameters adjust - fnet */
10558c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808e, 0xff00, 0x4800);
10568c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8090, 0xff00, 0xcc00);
10578c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8092, 0xff00, 0xb000);
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8088, 0xff00, 0x6000);
10608c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808b, 0x3f00, 0x0b00);
10618c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808d, 0x1f00, 0x0600);
10628c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x808c, 0xff00, 0xb000);
10638c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80a0, 0xff00, 0x2800);
10648c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x5000);
10658c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809b, 0xf800, 0xb000);
10668c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809a, 0xff00, 0x4b00);
10678c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809d, 0x3f00, 0x0800);
10688c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80a1, 0xff00, 0x7000);
10698c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809f, 0x1f00, 0x0300);
10708c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x809e, 0xff00, 0x8800);
10718c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80b2, 0xff00, 0x2200);
10728c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x9800);
10738c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80af, 0x3f00, 0x0800);
10748c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80b3, 0xff00, 0x6f00);
10758c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80b1, 0x1f00, 0x0300);
10768c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80b0, 0xff00, 0x9300);
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8011, 0x0000, 0x0800);
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci	rtl8168g_enable_gphy_10m(phydev);
10818c2ecf20Sopenharmony_ci
10828c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8016, 0x0000, 0x0400);
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	rtl8168g_disable_aldps(phydev);
10858c2ecf20Sopenharmony_ci	rtl8168h_config_eee_phy(phydev);
10868c2ecf20Sopenharmony_ci}
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_cistatic void rtl8102e_hw_phy_config(struct rtl8169_private *tp,
10898c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
10908c2ecf20Sopenharmony_ci{
10918c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
10928c2ecf20Sopenharmony_ci		{ 0x1f, 0x0003 },
10938c2ecf20Sopenharmony_ci		{ 0x08, 0x441d },
10948c2ecf20Sopenharmony_ci		{ 0x01, 0x9100 },
10958c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
10968c2ecf20Sopenharmony_ci	};
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x11, BIT(12));
10998c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x19, BIT(13));
11008c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x10, BIT(15));
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
11038c2ecf20Sopenharmony_ci}
11048c2ecf20Sopenharmony_ci
11058c2ecf20Sopenharmony_cistatic void rtl8401_hw_phy_config(struct rtl8169_private *tp,
11068c2ecf20Sopenharmony_ci				  struct phy_device *phydev)
11078c2ecf20Sopenharmony_ci{
11088c2ecf20Sopenharmony_ci	phy_set_bits(phydev, 0x11, BIT(12));
11098c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0003);
11108c2ecf20Sopenharmony_ci}
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_cistatic void rtl8105e_hw_phy_config(struct rtl8169_private *tp,
11138c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
11148c2ecf20Sopenharmony_ci{
11158c2ecf20Sopenharmony_ci	/* Disable ALDPS before ram code */
11168c2ecf20Sopenharmony_ci	phy_write(phydev, 0x18, 0x0310);
11178c2ecf20Sopenharmony_ci	msleep(100);
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
11208c2ecf20Sopenharmony_ci
11218c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0005, 0x1a, 0x0000);
11228c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0004, 0x1c, 0x0000);
11238c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0x0001, 0x15, 0x7701);
11248c2ecf20Sopenharmony_ci}
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_cistatic void rtl8402_hw_phy_config(struct rtl8169_private *tp,
11278c2ecf20Sopenharmony_ci				  struct phy_device *phydev)
11288c2ecf20Sopenharmony_ci{
11298c2ecf20Sopenharmony_ci	/* Disable ALDPS before setting firmware */
11308c2ecf20Sopenharmony_ci	phy_write(phydev, 0x18, 0x0310);
11318c2ecf20Sopenharmony_ci	msleep(20);
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
11348c2ecf20Sopenharmony_ci
11358c2ecf20Sopenharmony_ci	/* EEE setting */
11368c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0004);
11378c2ecf20Sopenharmony_ci	phy_write(phydev, 0x10, 0x401f);
11388c2ecf20Sopenharmony_ci	phy_write(phydev, 0x19, 0x7030);
11398c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
11408c2ecf20Sopenharmony_ci}
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_cistatic void rtl8106e_hw_phy_config(struct rtl8169_private *tp,
11438c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
11448c2ecf20Sopenharmony_ci{
11458c2ecf20Sopenharmony_ci	static const struct phy_reg phy_reg_init[] = {
11468c2ecf20Sopenharmony_ci		{ 0x1f, 0x0004 },
11478c2ecf20Sopenharmony_ci		{ 0x10, 0xc07f },
11488c2ecf20Sopenharmony_ci		{ 0x19, 0x7030 },
11498c2ecf20Sopenharmony_ci		{ 0x1f, 0x0000 }
11508c2ecf20Sopenharmony_ci	};
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci	/* Disable ALDPS before ram code */
11538c2ecf20Sopenharmony_ci	phy_write(phydev, 0x18, 0x0310);
11548c2ecf20Sopenharmony_ci	msleep(100);
11558c2ecf20Sopenharmony_ci
11568c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
11578c2ecf20Sopenharmony_ci
11588c2ecf20Sopenharmony_ci	rtl_writephy_batch(phydev, phy_reg_init);
11598c2ecf20Sopenharmony_ci}
11608c2ecf20Sopenharmony_ci
11618c2ecf20Sopenharmony_cistatic void rtl8125_legacy_force_mode(struct phy_device *phydev)
11628c2ecf20Sopenharmony_ci{
11638c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa5b, 0x12, BIT(15), 0);
11648c2ecf20Sopenharmony_ci}
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_cistatic void rtl8125a_1_hw_phy_config(struct rtl8169_private *tp,
11678c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
11688c2ecf20Sopenharmony_ci{
11698c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad4, 0x10, 0x03ff, 0x0084);
11708c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010);
11718c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x0006);
11728c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006);
11738c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac0, 0x14, 0x0000, 0x1100);
11748c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac8, 0x15, 0xf000, 0x7000);
11758c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad1, 0x14, 0x0000, 0x0400);
11768c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad1, 0x15, 0x0000, 0x03ff);
11778c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad1, 0x16, 0x0000, 0x03ff);
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ea, 0xff00, 0xc400);
11808c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80eb, 0x0700, 0x0300);
11818c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f8, 0xff00, 0x1c00);
11828c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80f1, 0xff00, 0x3000);
11838c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80fe, 0xff00, 0xa500);
11848c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8102, 0xff00, 0x5000);
11858c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8105, 0xff00, 0x3300);
11868c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8100, 0xff00, 0x7000);
11878c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8104, 0xff00, 0xf000);
11888c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8106, 0xff00, 0x6500);
11898c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80dc, 0xff00, 0xed00);
11908c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80df, 0x0000, 0x0100);
11918c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80e1, 0x0100, 0x0000);
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xbf0, 0x13, 0x003f, 0x0038);
11948c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x819f, 0xffff, 0xd0b6);
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0xbc3, 0x12, 0x5555);
11978c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xbf0, 0x15, 0x0e00, 0x0a00);
11988c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa5c, 0x10, 0x0400, 0x0000);
11998c2ecf20Sopenharmony_ci	rtl8168g_enable_gphy_10m(phydev);
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	rtl8125a_config_eee_phy(phydev);
12028c2ecf20Sopenharmony_ci}
12038c2ecf20Sopenharmony_ci
12048c2ecf20Sopenharmony_cistatic void rtl8125a_2_hw_phy_config(struct rtl8169_private *tp,
12058c2ecf20Sopenharmony_ci				     struct phy_device *phydev)
12068c2ecf20Sopenharmony_ci{
12078c2ecf20Sopenharmony_ci	int i;
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010);
12108c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x03ff);
12118c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006);
12128c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac0, 0x14, 0x1100, 0x0000);
12138c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xacc, 0x10, 0x0003, 0x0002);
12148c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad4, 0x10, 0x00e7, 0x0044);
12158c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac1, 0x12, 0x0080, 0x0000);
12168c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac8, 0x10, 0x0300, 0x0000);
12178c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac5, 0x17, 0x0007, 0x0002);
12188c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0xad4, 0x16, 0x00a8);
12198c2ecf20Sopenharmony_ci	phy_write_paged(phydev, 0xac5, 0x16, 0x01ff);
12208c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac8, 0x15, 0x00f0, 0x0030);
12218c2ecf20Sopenharmony_ci
12228c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0b87);
12238c2ecf20Sopenharmony_ci	phy_write(phydev, 0x16, 0x80a2);
12248c2ecf20Sopenharmony_ci	phy_write(phydev, 0x17, 0x0153);
12258c2ecf20Sopenharmony_ci	phy_write(phydev, 0x16, 0x809c);
12268c2ecf20Sopenharmony_ci	phy_write(phydev, 0x17, 0x0153);
12278c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
12288c2ecf20Sopenharmony_ci
12298c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0a43);
12308c2ecf20Sopenharmony_ci	phy_write(phydev, 0x13, 0x81B3);
12318c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0043);
12328c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00A7);
12338c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00D6);
12348c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00EC);
12358c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00F6);
12368c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00FB);
12378c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00FD);
12388c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00FF);
12398c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x00BB);
12408c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0058);
12418c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0029);
12428c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0013);
12438c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0009);
12448c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0004);
12458c2ecf20Sopenharmony_ci	phy_write(phydev, 0x14, 0x0002);
12468c2ecf20Sopenharmony_ci	for (i = 0; i < 25; i++)
12478c2ecf20Sopenharmony_ci		phy_write(phydev, 0x14, 0x0000);
12488c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8257, 0xffff, 0x020F);
12518c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x80ea, 0xffff, 0x7843);
12528c2ecf20Sopenharmony_ci
12538c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xd06, 0x14, 0x0000, 0x2000);
12568c2ecf20Sopenharmony_ci
12578c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x81a2, 0x0000, 0x0100);
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xb54, 0x16, 0xff00, 0xdb00);
12608c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa45, 0x12, 0x0001, 0x0000);
12618c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa5d, 0x12, 0x0000, 0x0020);
12628c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad4, 0x17, 0x0010, 0x0000);
12638c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa86, 0x15, 0x0001, 0x0000);
12648c2ecf20Sopenharmony_ci	rtl8168g_enable_gphy_10m(phydev);
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci	rtl8125a_config_eee_phy(phydev);
12678c2ecf20Sopenharmony_ci}
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_cistatic void rtl8125b_hw_phy_config(struct rtl8169_private *tp,
12708c2ecf20Sopenharmony_ci				   struct phy_device *phydev)
12718c2ecf20Sopenharmony_ci{
12728c2ecf20Sopenharmony_ci	r8169_apply_firmware(tp);
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa44, 0x11, 0x0000, 0x0800);
12758c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xac4, 0x13, 0x00f0, 0x0090);
12768c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xad3, 0x10, 0x0003, 0x0001);
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0b87);
12798c2ecf20Sopenharmony_ci	phy_write(phydev, 0x16, 0x80f5);
12808c2ecf20Sopenharmony_ci	phy_write(phydev, 0x17, 0x760e);
12818c2ecf20Sopenharmony_ci	phy_write(phydev, 0x16, 0x8107);
12828c2ecf20Sopenharmony_ci	phy_write(phydev, 0x17, 0x360e);
12838c2ecf20Sopenharmony_ci	phy_write(phydev, 0x16, 0x8551);
12848c2ecf20Sopenharmony_ci	phy_modify(phydev, 0x17, 0xff00, 0x0800);
12858c2ecf20Sopenharmony_ci	phy_write(phydev, 0x1f, 0x0000);
12868c2ecf20Sopenharmony_ci
12878c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xbf0, 0x10, 0xe000, 0xa000);
12888c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xbf4, 0x13, 0x0f00, 0x0300);
12898c2ecf20Sopenharmony_ci
12908c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8044, 0xffff, 0x2417);
12918c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x804a, 0xffff, 0x2417);
12928c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8050, 0xffff, 0x2417);
12938c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8056, 0xffff, 0x2417);
12948c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x805c, 0xffff, 0x2417);
12958c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8062, 0xffff, 0x2417);
12968c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8068, 0xffff, 0x2417);
12978c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x806e, 0xffff, 0x2417);
12988c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x8074, 0xffff, 0x2417);
12998c2ecf20Sopenharmony_ci	r8168g_phy_param(phydev, 0x807a, 0xffff, 0x2417);
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xa4c, 0x15, 0x0000, 0x0040);
13028c2ecf20Sopenharmony_ci	phy_modify_paged(phydev, 0xbf8, 0x12, 0xe000, 0xa000);
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci	rtl8125_legacy_force_mode(phydev);
13058c2ecf20Sopenharmony_ci	rtl8125b_config_eee_phy(phydev);
13068c2ecf20Sopenharmony_ci}
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_civoid r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
13098c2ecf20Sopenharmony_ci			 enum mac_version ver)
13108c2ecf20Sopenharmony_ci{
13118c2ecf20Sopenharmony_ci	static const rtl_phy_cfg_fct phy_configs[] = {
13128c2ecf20Sopenharmony_ci		/* PCI devices. */
13138c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config,
13148c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config,
13158c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config,
13168c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config,
13178c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config,
13188c2ecf20Sopenharmony_ci		/* PCI-E devices. */
13198c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config,
13208c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config,
13218c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config,
13228c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_10] = NULL,
13238c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config,
13248c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config,
13258c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_13] = NULL,
13268c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_14] = rtl8401_hw_phy_config,
13278c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_16] = NULL,
13288c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config,
13298c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config,
13308c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config,
13318c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config,
13328c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config,
13338c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_22] = rtl8168c_3_hw_phy_config,
13348c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config,
13358c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config,
13368c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config,
13378c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config,
13388c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_27] = rtl8168d_3_hw_phy_config,
13398c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config,
13408c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config,
13418c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config,
13428c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_31] = NULL,
13438c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config,
13448c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config,
13458c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config,
13468c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config,
13478c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config,
13488c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config,
13498c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config,
13508c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config,
13518c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config,
13528c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_41] = NULL,
13538c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config,
13548c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config,
13558c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config,
13568c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config,
13578c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config,
13588c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config,
13598c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config,
13608c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config,
13618c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config,
13628c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config,
13638c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_52] = rtl8117_hw_phy_config,
13648c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_60] = rtl8125a_1_hw_phy_config,
13658c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_61] = rtl8125a_2_hw_phy_config,
13668c2ecf20Sopenharmony_ci		[RTL_GIGA_MAC_VER_63] = rtl8125b_hw_phy_config,
13678c2ecf20Sopenharmony_ci	};
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci	if (phy_configs[ver])
13708c2ecf20Sopenharmony_ci		phy_configs[ver](tp, phydev);
13718c2ecf20Sopenharmony_ci}
1372