cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

r8169_phy_config.c (36482B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 * r8169_phy_config.c: RealTek 8169/8168/8101 ethernet driver.
      4 *
      5 * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
      6 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
      7 * Copyright (c) a lot of people too. Please respect their work.
      8 *
      9 * See MAINTAINERS file for support contact information.
     10 */
     11
     12#include <linux/delay.h>
     13#include <linux/phy.h>
     14
     15#include "r8169.h"
     16
     17typedef void (*rtl_phy_cfg_fct)(struct rtl8169_private *tp,
     18				struct phy_device *phydev);
     19
     20static void r8168d_modify_extpage(struct phy_device *phydev, int extpage,
     21				  int reg, u16 mask, u16 val)
     22{
     23	int oldpage = phy_select_page(phydev, 0x0007);
     24
     25	__phy_write(phydev, 0x1e, extpage);
     26	__phy_modify(phydev, reg, mask, val);
     27
     28	phy_restore_page(phydev, oldpage, 0);
     29}
     30
     31static void r8168d_phy_param(struct phy_device *phydev, u16 parm,
     32			     u16 mask, u16 val)
     33{
     34	int oldpage = phy_select_page(phydev, 0x0005);
     35
     36	__phy_write(phydev, 0x05, parm);
     37	__phy_modify(phydev, 0x06, mask, val);
     38
     39	phy_restore_page(phydev, oldpage, 0);
     40}
     41
     42static void r8168g_phy_param(struct phy_device *phydev, u16 parm,
     43			     u16 mask, u16 val)
     44{
     45	int oldpage = phy_select_page(phydev, 0x0a43);
     46
     47	__phy_write(phydev, 0x13, parm);
     48	__phy_modify(phydev, 0x14, mask, val);
     49
     50	phy_restore_page(phydev, oldpage, 0);
     51}
     52
     53struct phy_reg {
     54	u16 reg;
     55	u16 val;
     56};
     57
     58static void __rtl_writephy_batch(struct phy_device *phydev,
     59				 const struct phy_reg *regs, int len)
     60{
     61	phy_lock_mdio_bus(phydev);
     62
     63	while (len-- > 0) {
     64		__phy_write(phydev, regs->reg, regs->val);
     65		regs++;
     66	}
     67
     68	phy_unlock_mdio_bus(phydev);
     69}
     70
     71#define rtl_writephy_batch(p, a) __rtl_writephy_batch(p, a, ARRAY_SIZE(a))
     72
     73static void rtl8168f_config_eee_phy(struct phy_device *phydev)
     74{
     75	r8168d_modify_extpage(phydev, 0x0020, 0x15, 0, BIT(8));
     76	r8168d_phy_param(phydev, 0x8b85, 0, BIT(13));
     77}
     78
     79static void rtl8168g_config_eee_phy(struct phy_device *phydev)
     80{
     81	phy_modify_paged(phydev, 0x0a43, 0x11, 0, BIT(4));
     82}
     83
     84static void rtl8168h_config_eee_phy(struct phy_device *phydev)
     85{
     86	rtl8168g_config_eee_phy(phydev);
     87
     88	phy_modify_paged(phydev, 0xa4a, 0x11, 0x0000, 0x0200);
     89	phy_modify_paged(phydev, 0xa42, 0x14, 0x0000, 0x0080);
     90}
     91
     92static void rtl8125a_config_eee_phy(struct phy_device *phydev)
     93{
     94	rtl8168h_config_eee_phy(phydev);
     95
     96	phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
     97	phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
     98}
     99
    100static void rtl8125b_config_eee_phy(struct phy_device *phydev)
    101{
    102	phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
    103	phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
    104	phy_modify_paged(phydev, 0xa42, 0x14, 0x0080, 0x0000);
    105	phy_modify_paged(phydev, 0xa4a, 0x11, 0x0200, 0x0000);
    106}
    107
    108static void rtl8169s_hw_phy_config(struct rtl8169_private *tp,
    109				   struct phy_device *phydev)
    110{
    111	static const struct phy_reg phy_reg_init[] = {
    112		{ 0x1f, 0x0001 },
    113		{ 0x06, 0x006e },
    114		{ 0x08, 0x0708 },
    115		{ 0x15, 0x4000 },
    116		{ 0x18, 0x65c7 },
    117
    118		{ 0x1f, 0x0001 },
    119		{ 0x03, 0x00a1 },
    120		{ 0x02, 0x0008 },
    121		{ 0x01, 0x0120 },
    122		{ 0x00, 0x1000 },
    123		{ 0x04, 0x0800 },
    124		{ 0x04, 0x0000 },
    125
    126		{ 0x03, 0xff41 },
    127		{ 0x02, 0xdf60 },
    128		{ 0x01, 0x0140 },
    129		{ 0x00, 0x0077 },
    130		{ 0x04, 0x7800 },
    131		{ 0x04, 0x7000 },
    132
    133		{ 0x03, 0x802f },
    134		{ 0x02, 0x4f02 },
    135		{ 0x01, 0x0409 },
    136		{ 0x00, 0xf0f9 },
    137		{ 0x04, 0x9800 },
    138		{ 0x04, 0x9000 },
    139
    140		{ 0x03, 0xdf01 },
    141		{ 0x02, 0xdf20 },
    142		{ 0x01, 0xff95 },
    143		{ 0x00, 0xba00 },
    144		{ 0x04, 0xa800 },
    145		{ 0x04, 0xa000 },
    146
    147		{ 0x03, 0xff41 },
    148		{ 0x02, 0xdf20 },
    149		{ 0x01, 0x0140 },
    150		{ 0x00, 0x00bb },
    151		{ 0x04, 0xb800 },
    152		{ 0x04, 0xb000 },
    153
    154		{ 0x03, 0xdf41 },
    155		{ 0x02, 0xdc60 },
    156		{ 0x01, 0x6340 },
    157		{ 0x00, 0x007d },
    158		{ 0x04, 0xd800 },
    159		{ 0x04, 0xd000 },
    160
    161		{ 0x03, 0xdf01 },
    162		{ 0x02, 0xdf20 },
    163		{ 0x01, 0x100a },
    164		{ 0x00, 0xa0ff },
    165		{ 0x04, 0xf800 },
    166		{ 0x04, 0xf000 },
    167
    168		{ 0x1f, 0x0000 },
    169		{ 0x0b, 0x0000 },
    170		{ 0x00, 0x9200 }
    171	};
    172
    173	rtl_writephy_batch(phydev, phy_reg_init);
    174}
    175
    176static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp,
    177				    struct phy_device *phydev)
    178{
    179	phy_write_paged(phydev, 0x0002, 0x01, 0x90d0);
    180}
    181
    182static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp,
    183				     struct phy_device *phydev)
    184{
    185	static const struct phy_reg phy_reg_init[] = {
    186		{ 0x1f, 0x0001 },
    187		{ 0x04, 0x0000 },
    188		{ 0x03, 0x00a1 },
    189		{ 0x02, 0x0008 },
    190		{ 0x01, 0x0120 },
    191		{ 0x00, 0x1000 },
    192		{ 0x04, 0x0800 },
    193		{ 0x04, 0x9000 },
    194		{ 0x03, 0x802f },
    195		{ 0x02, 0x4f02 },
    196		{ 0x01, 0x0409 },
    197		{ 0x00, 0xf099 },
    198		{ 0x04, 0x9800 },
    199		{ 0x04, 0xa000 },
    200		{ 0x03, 0xdf01 },
    201		{ 0x02, 0xdf20 },
    202		{ 0x01, 0xff95 },
    203		{ 0x00, 0xba00 },
    204		{ 0x04, 0xa800 },
    205		{ 0x04, 0xf000 },
    206		{ 0x03, 0xdf01 },
    207		{ 0x02, 0xdf20 },
    208		{ 0x01, 0x101a },
    209		{ 0x00, 0xa0ff },
    210		{ 0x04, 0xf800 },
    211		{ 0x04, 0x0000 },
    212		{ 0x1f, 0x0000 },
    213
    214		{ 0x1f, 0x0001 },
    215		{ 0x10, 0xf41b },
    216		{ 0x14, 0xfb54 },
    217		{ 0x18, 0xf5c7 },
    218		{ 0x1f, 0x0000 },
    219
    220		{ 0x1f, 0x0001 },
    221		{ 0x17, 0x0cc0 },
    222		{ 0x1f, 0x0000 }
    223	};
    224
    225	rtl_writephy_batch(phydev, phy_reg_init);
    226}
    227
    228static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp,
    229				     struct phy_device *phydev)
    230{
    231	static const struct phy_reg phy_reg_init[] = {
    232		{ 0x1f, 0x0001 },
    233		{ 0x04, 0x0000 },
    234		{ 0x03, 0x00a1 },
    235		{ 0x02, 0x0008 },
    236		{ 0x01, 0x0120 },
    237		{ 0x00, 0x1000 },
    238		{ 0x04, 0x0800 },
    239		{ 0x04, 0x9000 },
    240		{ 0x03, 0x802f },
    241		{ 0x02, 0x4f02 },
    242		{ 0x01, 0x0409 },
    243		{ 0x00, 0xf099 },
    244		{ 0x04, 0x9800 },
    245		{ 0x04, 0xa000 },
    246		{ 0x03, 0xdf01 },
    247		{ 0x02, 0xdf20 },
    248		{ 0x01, 0xff95 },
    249		{ 0x00, 0xba00 },
    250		{ 0x04, 0xa800 },
    251		{ 0x04, 0xf000 },
    252		{ 0x03, 0xdf01 },
    253		{ 0x02, 0xdf20 },
    254		{ 0x01, 0x101a },
    255		{ 0x00, 0xa0ff },
    256		{ 0x04, 0xf800 },
    257		{ 0x04, 0x0000 },
    258		{ 0x1f, 0x0000 },
    259
    260		{ 0x1f, 0x0001 },
    261		{ 0x0b, 0x8480 },
    262		{ 0x1f, 0x0000 },
    263
    264		{ 0x1f, 0x0001 },
    265		{ 0x18, 0x67c7 },
    266		{ 0x04, 0x2000 },
    267		{ 0x03, 0x002f },
    268		{ 0x02, 0x4360 },
    269		{ 0x01, 0x0109 },
    270		{ 0x00, 0x3022 },
    271		{ 0x04, 0x2800 },
    272		{ 0x1f, 0x0000 },
    273
    274		{ 0x1f, 0x0001 },
    275		{ 0x17, 0x0cc0 },
    276		{ 0x1f, 0x0000 }
    277	};
    278
    279	rtl_writephy_batch(phydev, phy_reg_init);
    280}
    281
    282static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp,
    283				    struct phy_device *phydev)
    284{
    285	phy_write(phydev, 0x1f, 0x0001);
    286	phy_set_bits(phydev, 0x16, BIT(0));
    287	phy_write(phydev, 0x10, 0xf41b);
    288	phy_write(phydev, 0x1f, 0x0000);
    289}
    290
    291static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp,
    292				     struct phy_device *phydev)
    293{
    294	phy_write_paged(phydev, 0x0001, 0x10, 0xf41b);
    295}
    296
    297static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp,
    298				      struct phy_device *phydev)
    299{
    300	phy_write(phydev, 0x1d, 0x0f00);
    301	phy_write_paged(phydev, 0x0002, 0x0c, 0x1ec8);
    302}
    303
    304static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp,
    305				      struct phy_device *phydev)
    306{
    307	phy_set_bits(phydev, 0x14, BIT(5));
    308	phy_set_bits(phydev, 0x0d, BIT(5));
    309	phy_write_paged(phydev, 0x0001, 0x1d, 0x3d98);
    310}
    311
    312static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp,
    313				     struct phy_device *phydev)
    314{
    315	static const struct phy_reg phy_reg_init[] = {
    316		{ 0x1f, 0x0001 },
    317		{ 0x12, 0x2300 },
    318		{ 0x1f, 0x0002 },
    319		{ 0x00, 0x88d4 },
    320		{ 0x01, 0x82b1 },
    321		{ 0x03, 0x7002 },
    322		{ 0x08, 0x9e30 },
    323		{ 0x09, 0x01f0 },
    324		{ 0x0a, 0x5500 },
    325		{ 0x0c, 0x00c8 },
    326		{ 0x1f, 0x0003 },
    327		{ 0x12, 0xc096 },
    328		{ 0x16, 0x000a },
    329		{ 0x1f, 0x0000 },
    330		{ 0x1f, 0x0000 },
    331		{ 0x09, 0x2000 },
    332		{ 0x09, 0x0000 }
    333	};
    334
    335	rtl_writephy_batch(phydev, phy_reg_init);
    336
    337	phy_set_bits(phydev, 0x14, BIT(5));
    338	phy_set_bits(phydev, 0x0d, BIT(5));
    339}
    340
    341static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp,
    342				     struct phy_device *phydev)
    343{
    344	static const struct phy_reg phy_reg_init[] = {
    345		{ 0x1f, 0x0001 },
    346		{ 0x12, 0x2300 },
    347		{ 0x03, 0x802f },
    348		{ 0x02, 0x4f02 },
    349		{ 0x01, 0x0409 },
    350		{ 0x00, 0xf099 },
    351		{ 0x04, 0x9800 },
    352		{ 0x04, 0x9000 },
    353		{ 0x1d, 0x3d98 },
    354		{ 0x1f, 0x0002 },
    355		{ 0x0c, 0x7eb8 },
    356		{ 0x06, 0x0761 },
    357		{ 0x1f, 0x0003 },
    358		{ 0x16, 0x0f0a },
    359		{ 0x1f, 0x0000 }
    360	};
    361
    362	rtl_writephy_batch(phydev, phy_reg_init);
    363
    364	phy_set_bits(phydev, 0x16, BIT(0));
    365	phy_set_bits(phydev, 0x14, BIT(5));
    366	phy_set_bits(phydev, 0x0d, BIT(5));
    367}
    368
    369static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp,
    370				     struct phy_device *phydev)
    371{
    372	static const struct phy_reg phy_reg_init[] = {
    373		{ 0x1f, 0x0001 },
    374		{ 0x12, 0x2300 },
    375		{ 0x1d, 0x3d98 },
    376		{ 0x1f, 0x0002 },
    377		{ 0x0c, 0x7eb8 },
    378		{ 0x06, 0x5461 },
    379		{ 0x1f, 0x0003 },
    380		{ 0x16, 0x0f0a },
    381		{ 0x1f, 0x0000 }
    382	};
    383
    384	rtl_writephy_batch(phydev, phy_reg_init);
    385
    386	phy_set_bits(phydev, 0x16, BIT(0));
    387	phy_set_bits(phydev, 0x14, BIT(5));
    388	phy_set_bits(phydev, 0x0d, BIT(5));
    389}
    390
    391static const struct phy_reg rtl8168d_1_phy_reg_init_0[] = {
    392	/* Channel Estimation */
    393	{ 0x1f, 0x0001 },
    394	{ 0x06, 0x4064 },
    395	{ 0x07, 0x2863 },
    396	{ 0x08, 0x059c },
    397	{ 0x09, 0x26b4 },
    398	{ 0x0a, 0x6a19 },
    399	{ 0x0b, 0xdcc8 },
    400	{ 0x10, 0xf06d },
    401	{ 0x14, 0x7f68 },
    402	{ 0x18, 0x7fd9 },
    403	{ 0x1c, 0xf0ff },
    404	{ 0x1d, 0x3d9c },
    405	{ 0x1f, 0x0003 },
    406	{ 0x12, 0xf49f },
    407	{ 0x13, 0x070b },
    408	{ 0x1a, 0x05ad },
    409	{ 0x14, 0x94c0 },
    410
    411	/*
    412	 * Tx Error Issue
    413	 * Enhance line driver power
    414	 */
    415	{ 0x1f, 0x0002 },
    416	{ 0x06, 0x5561 },
    417	{ 0x1f, 0x0005 },
    418	{ 0x05, 0x8332 },
    419	{ 0x06, 0x5561 },
    420
    421	/*
    422	 * Can not link to 1Gbps with bad cable
    423	 * Decrease SNR threshold form 21.07dB to 19.04dB
    424	 */
    425	{ 0x1f, 0x0001 },
    426	{ 0x17, 0x0cc0 },
    427
    428	{ 0x1f, 0x0000 },
    429	{ 0x0d, 0xf880 }
    430};
    431
    432static void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp,
    433					 struct phy_device *phydev,
    434					 u16 val)
    435{
    436	u16 reg_val;
    437
    438	phy_write(phydev, 0x1f, 0x0005);
    439	phy_write(phydev, 0x05, 0x001b);
    440	reg_val = phy_read(phydev, 0x06);
    441	phy_write(phydev, 0x1f, 0x0000);
    442
    443	if (reg_val != val)
    444		phydev_warn(phydev, "chipset not ready for firmware\n");
    445	else
    446		r8169_apply_firmware(tp);
    447}
    448
    449static void rtl8168d_1_common(struct phy_device *phydev)
    450{
    451	u16 val;
    452
    453	phy_write_paged(phydev, 0x0002, 0x05, 0x669a);
    454	r8168d_phy_param(phydev, 0x8330, 0xffff, 0x669a);
    455	phy_write(phydev, 0x1f, 0x0002);
    456
    457	val = phy_read(phydev, 0x0d);
    458
    459	if ((val & 0x00ff) != 0x006c) {
    460		static const u16 set[] = {
    461			0x0065, 0x0066, 0x0067, 0x0068,
    462			0x0069, 0x006a, 0x006b, 0x006c
    463		};
    464		int i;
    465
    466		val &= 0xff00;
    467		for (i = 0; i < ARRAY_SIZE(set); i++)
    468			phy_write(phydev, 0x0d, val | set[i]);
    469	}
    470}
    471
    472static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp,
    473				     struct phy_device *phydev)
    474{
    475	rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
    476
    477	/*
    478	 * Rx Error Issue
    479	 * Fine Tune Switching regulator parameter
    480	 */
    481	phy_write(phydev, 0x1f, 0x0002);
    482	phy_modify(phydev, 0x0b, 0x00ef, 0x0010);
    483	phy_modify(phydev, 0x0c, 0x5d00, 0xa200);
    484
    485	if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
    486		rtl8168d_1_common(phydev);
    487	} else {
    488		phy_write_paged(phydev, 0x0002, 0x05, 0x6662);
    489		r8168d_phy_param(phydev, 0x8330, 0xffff, 0x6662);
    490	}
    491
    492	/* RSET couple improve */
    493	phy_write(phydev, 0x1f, 0x0002);
    494	phy_set_bits(phydev, 0x0d, 0x0300);
    495	phy_set_bits(phydev, 0x0f, 0x0010);
    496
    497	/* Fine tune PLL performance */
    498	phy_write(phydev, 0x1f, 0x0002);
    499	phy_modify(phydev, 0x02, 0x0600, 0x0100);
    500	phy_clear_bits(phydev, 0x03, 0xe000);
    501	phy_write(phydev, 0x1f, 0x0000);
    502
    503	rtl8168d_apply_firmware_cond(tp, phydev, 0xbf00);
    504}
    505
    506static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp,
    507				     struct phy_device *phydev)
    508{
    509	rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
    510
    511	if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
    512		rtl8168d_1_common(phydev);
    513	} else {
    514		phy_write_paged(phydev, 0x0002, 0x05, 0x2642);
    515		r8168d_phy_param(phydev, 0x8330, 0xffff, 0x2642);
    516	}
    517
    518	/* Fine tune PLL performance */
    519	phy_write(phydev, 0x1f, 0x0002);
    520	phy_modify(phydev, 0x02, 0x0600, 0x0100);
    521	phy_clear_bits(phydev, 0x03, 0xe000);
    522	phy_write(phydev, 0x1f, 0x0000);
    523
    524	/* Switching regulator Slew rate */
    525	phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0017);
    526
    527	rtl8168d_apply_firmware_cond(tp, phydev, 0xb300);
    528}
    529
    530static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp,
    531				     struct phy_device *phydev)
    532{
    533	phy_write_paged(phydev, 0x0001, 0x17, 0x0cc0);
    534	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0xffff, 0x0040);
    535	phy_set_bits(phydev, 0x0d, BIT(5));
    536}
    537
    538static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp,
    539				     struct phy_device *phydev)
    540{
    541	static const struct phy_reg phy_reg_init[] = {
    542		/* Channel estimation fine tune */
    543		{ 0x1f, 0x0001 },
    544		{ 0x0b, 0x6c20 },
    545		{ 0x07, 0x2872 },
    546		{ 0x1c, 0xefff },
    547		{ 0x1f, 0x0003 },
    548		{ 0x14, 0x6420 },
    549		{ 0x1f, 0x0000 },
    550	};
    551
    552	r8169_apply_firmware(tp);
    553
    554	/* Enable Delay cap */
    555	r8168d_phy_param(phydev, 0x8b80, 0xffff, 0xc896);
    556
    557	rtl_writephy_batch(phydev, phy_reg_init);
    558
    559	/* Update PFM & 10M TX idle timer */
    560	r8168d_modify_extpage(phydev, 0x002f, 0x15, 0xffff, 0x1919);
    561
    562	r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
    563
    564	/* DCO enable for 10M IDLE Power */
    565	r8168d_modify_extpage(phydev, 0x0023, 0x17, 0x0000, 0x0006);
    566
    567	/* For impedance matching */
    568	phy_modify_paged(phydev, 0x0002, 0x08, 0x7f00, 0x8000);
    569
    570	/* PHY auto speed down */
    571	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0050);
    572	phy_set_bits(phydev, 0x14, BIT(15));
    573
    574	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
    575	r8168d_phy_param(phydev, 0x8b85, 0x2000, 0x0000);
    576
    577	r8168d_modify_extpage(phydev, 0x0020, 0x15, 0x1100, 0x0000);
    578	phy_write_paged(phydev, 0x0006, 0x00, 0x5a00);
    579
    580	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0000);
    581}
    582
    583static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp,
    584				     struct phy_device *phydev)
    585{
    586	r8169_apply_firmware(tp);
    587
    588	/* Enable Delay cap */
    589	r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
    590
    591	/* Channel estimation fine tune */
    592	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
    593
    594	/* Green Setting */
    595	r8168d_phy_param(phydev, 0x8b5b, 0xffff, 0x9222);
    596	r8168d_phy_param(phydev, 0x8b6d, 0xffff, 0x8000);
    597	r8168d_phy_param(phydev, 0x8b76, 0xffff, 0x8000);
    598
    599	/* For 4-corner performance improve */
    600	phy_write(phydev, 0x1f, 0x0005);
    601	phy_write(phydev, 0x05, 0x8b80);
    602	phy_set_bits(phydev, 0x17, 0x0006);
    603	phy_write(phydev, 0x1f, 0x0000);
    604
    605	/* PHY auto speed down */
    606	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
    607	phy_set_bits(phydev, 0x14, BIT(15));
    608
    609	/* improve 10M EEE waveform */
    610	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
    611
    612	/* Improve 2-pair detection performance */
    613	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
    614
    615	rtl8168f_config_eee_phy(phydev);
    616
    617	/* Green feature */
    618	phy_write(phydev, 0x1f, 0x0003);
    619	phy_set_bits(phydev, 0x19, BIT(0));
    620	phy_set_bits(phydev, 0x10, BIT(10));
    621	phy_write(phydev, 0x1f, 0x0000);
    622	phy_modify_paged(phydev, 0x0005, 0x01, 0, BIT(8));
    623}
    624
    625static void rtl8168f_hw_phy_config(struct rtl8169_private *tp,
    626				   struct phy_device *phydev)
    627{
    628	/* For 4-corner performance improve */
    629	r8168d_phy_param(phydev, 0x8b80, 0x0000, 0x0006);
    630
    631	/* PHY auto speed down */
    632	r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
    633	phy_set_bits(phydev, 0x14, BIT(15));
    634
    635	/* Improve 10M EEE waveform */
    636	r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
    637
    638	rtl8168f_config_eee_phy(phydev);
    639}
    640
    641static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp,
    642				     struct phy_device *phydev)
    643{
    644	r8169_apply_firmware(tp);
    645
    646	/* Channel estimation fine tune */
    647	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
    648
    649	/* Modify green table for giga & fnet */
    650	r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
    651	r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
    652	r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
    653	r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
    654	r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
    655	r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00fb);
    656
    657	/* Modify green table for 10M */
    658	r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
    659
    660	/* Disable hiimpedance detection (RTCT) */
    661	phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
    662
    663	rtl8168f_hw_phy_config(tp, phydev);
    664
    665	/* Improve 2-pair detection performance */
    666	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
    667}
    668
    669static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp,
    670				     struct phy_device *phydev)
    671{
    672	r8169_apply_firmware(tp);
    673
    674	rtl8168f_hw_phy_config(tp, phydev);
    675}
    676
    677static void rtl8411_hw_phy_config(struct rtl8169_private *tp,
    678				  struct phy_device *phydev)
    679{
    680	r8169_apply_firmware(tp);
    681
    682	rtl8168f_hw_phy_config(tp, phydev);
    683
    684	/* Improve 2-pair detection performance */
    685	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
    686
    687	/* Channel estimation fine tune */
    688	phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
    689
    690	/* Modify green table for giga & fnet */
    691	r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
    692	r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
    693	r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
    694	r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
    695	r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
    696	r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00aa);
    697
    698	/* Modify green table for 10M */
    699	r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
    700
    701	/* Disable hiimpedance detection (RTCT) */
    702	phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
    703
    704	/* Modify green table for giga */
    705	r8168d_phy_param(phydev, 0x8b54, 0x0800, 0x0000);
    706	r8168d_phy_param(phydev, 0x8b5d, 0x0800, 0x0000);
    707	r8168d_phy_param(phydev, 0x8a7c, 0x0100, 0x0000);
    708	r8168d_phy_param(phydev, 0x8a7f, 0x0000, 0x0100);
    709	r8168d_phy_param(phydev, 0x8a82, 0x0100, 0x0000);
    710	r8168d_phy_param(phydev, 0x8a85, 0x0100, 0x0000);
    711	r8168d_phy_param(phydev, 0x8a88, 0x0100, 0x0000);
    712
    713	/* uc same-seed solution */
    714	r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x8000);
    715
    716	/* Green feature */
    717	phy_write(phydev, 0x1f, 0x0003);
    718	phy_clear_bits(phydev, 0x19, BIT(0));
    719	phy_clear_bits(phydev, 0x10, BIT(10));
    720	phy_write(phydev, 0x1f, 0x0000);
    721}
    722
    723static void rtl8168g_disable_aldps(struct phy_device *phydev)
    724{
    725	phy_modify_paged(phydev, 0x0a43, 0x10, BIT(2), 0);
    726}
    727
    728static void rtl8168g_enable_gphy_10m(struct phy_device *phydev)
    729{
    730	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(11));
    731}
    732
    733static void rtl8168g_phy_adjust_10m_aldps(struct phy_device *phydev)
    734{
    735	phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0);
    736	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6));
    737	r8168g_phy_param(phydev, 0x8084, 0x6000, 0x0000);
    738	phy_modify_paged(phydev, 0x0a43, 0x10, 0x0000, 0x1003);
    739}
    740
    741static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp,
    742				     struct phy_device *phydev)
    743{
    744	int ret;
    745
    746	r8169_apply_firmware(tp);
    747
    748	ret = phy_read_paged(phydev, 0x0a46, 0x10);
    749	if (ret & BIT(8))
    750		phy_modify_paged(phydev, 0x0bcc, 0x12, BIT(15), 0);
    751	else
    752		phy_modify_paged(phydev, 0x0bcc, 0x12, 0, BIT(15));
    753
    754	ret = phy_read_paged(phydev, 0x0a46, 0x13);
    755	if (ret & BIT(8))
    756		phy_modify_paged(phydev, 0x0c41, 0x15, 0, BIT(1));
    757	else
    758		phy_modify_paged(phydev, 0x0c41, 0x15, BIT(1), 0);
    759
    760	/* Enable PHY auto speed down */
    761	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
    762
    763	rtl8168g_phy_adjust_10m_aldps(phydev);
    764
    765	/* EEE auto-fallback function */
    766	phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2));
    767
    768	/* Enable UC LPF tune function */
    769	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
    770
    771	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
    772
    773	/* Improve SWR Efficiency */
    774	phy_write(phydev, 0x1f, 0x0bcd);
    775	phy_write(phydev, 0x14, 0x5065);
    776	phy_write(phydev, 0x14, 0xd065);
    777	phy_write(phydev, 0x1f, 0x0bc8);
    778	phy_write(phydev, 0x11, 0x5655);
    779	phy_write(phydev, 0x1f, 0x0bcd);
    780	phy_write(phydev, 0x14, 0x1065);
    781	phy_write(phydev, 0x14, 0x9065);
    782	phy_write(phydev, 0x14, 0x1065);
    783	phy_write(phydev, 0x1f, 0x0000);
    784
    785	rtl8168g_disable_aldps(phydev);
    786	rtl8168g_config_eee_phy(phydev);
    787}
    788
    789static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp,
    790				     struct phy_device *phydev)
    791{
    792	r8169_apply_firmware(tp);
    793	rtl8168g_config_eee_phy(phydev);
    794}
    795
    796static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp,
    797				     struct phy_device *phydev)
    798{
    799	u16 dout_tapbin;
    800	u32 data;
    801
    802	r8169_apply_firmware(tp);
    803
    804	/* CHN EST parameters adjust - giga master */
    805	r8168g_phy_param(phydev, 0x809b, 0xf800, 0x8000);
    806	r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x8000);
    807	r8168g_phy_param(phydev, 0x80a4, 0xff00, 0x8500);
    808	r8168g_phy_param(phydev, 0x809c, 0xff00, 0xbd00);
    809
    810	/* CHN EST parameters adjust - giga slave */
    811	r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x7000);
    812	r8168g_phy_param(phydev, 0x80b4, 0xff00, 0x5000);
    813	r8168g_phy_param(phydev, 0x80ac, 0xff00, 0x4000);
    814
    815	/* CHN EST parameters adjust - fnet */
    816	r8168g_phy_param(phydev, 0x808e, 0xff00, 0x1200);
    817	r8168g_phy_param(phydev, 0x8090, 0xff00, 0xe500);
    818	r8168g_phy_param(phydev, 0x8092, 0xff00, 0x9f00);
    819
    820	/* enable R-tune & PGA-retune function */
    821	dout_tapbin = 0;
    822	data = phy_read_paged(phydev, 0x0a46, 0x13);
    823	data &= 3;
    824	data <<= 2;
    825	dout_tapbin |= data;
    826	data = phy_read_paged(phydev, 0x0a46, 0x12);
    827	data &= 0xc000;
    828	data >>= 14;
    829	dout_tapbin |= data;
    830	dout_tapbin = ~(dout_tapbin ^ 0x08);
    831	dout_tapbin <<= 12;
    832	dout_tapbin &= 0xf000;
    833
    834	r8168g_phy_param(phydev, 0x827a, 0xf000, dout_tapbin);
    835	r8168g_phy_param(phydev, 0x827b, 0xf000, dout_tapbin);
    836	r8168g_phy_param(phydev, 0x827c, 0xf000, dout_tapbin);
    837	r8168g_phy_param(phydev, 0x827d, 0xf000, dout_tapbin);
    838	r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800);
    839	phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002);
    840
    841	rtl8168g_enable_gphy_10m(phydev);
    842
    843	/* SAR ADC performance */
    844	phy_modify_paged(phydev, 0x0bca, 0x17, BIT(12) | BIT(13), BIT(14));
    845
    846	r8168g_phy_param(phydev, 0x803f, 0x3000, 0x0000);
    847	r8168g_phy_param(phydev, 0x8047, 0x3000, 0x0000);
    848	r8168g_phy_param(phydev, 0x804f, 0x3000, 0x0000);
    849	r8168g_phy_param(phydev, 0x8057, 0x3000, 0x0000);
    850	r8168g_phy_param(phydev, 0x805f, 0x3000, 0x0000);
    851	r8168g_phy_param(phydev, 0x8067, 0x3000, 0x0000);
    852	r8168g_phy_param(phydev, 0x806f, 0x3000, 0x0000);
    853
    854	/* disable phy pfm mode */
    855	phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
    856
    857	rtl8168g_disable_aldps(phydev);
    858	rtl8168h_config_eee_phy(phydev);
    859}
    860
    861static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp,
    862				     struct phy_device *phydev)
    863{
    864	u16 ioffset, rlen;
    865	u32 data;
    866
    867	r8169_apply_firmware(tp);
    868
    869	/* CHIN EST parameter update */
    870	r8168g_phy_param(phydev, 0x808a, 0x003f, 0x000a);
    871
    872	/* enable R-tune & PGA-retune function */
    873	r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800);
    874	phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002);
    875
    876	rtl8168g_enable_gphy_10m(phydev);
    877
    878	ioffset = rtl8168h_2_get_adc_bias_ioffset(tp);
    879	if (ioffset != 0xffff)
    880		phy_write_paged(phydev, 0x0bcf, 0x16, ioffset);
    881
    882	/* Modify rlen (TX LPF corner frequency) level */
    883	data = phy_read_paged(phydev, 0x0bcd, 0x16);
    884	data &= 0x000f;
    885	rlen = 0;
    886	if (data > 3)
    887		rlen = data - 3;
    888	data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12);
    889	phy_write_paged(phydev, 0x0bcd, 0x17, data);
    890
    891	/* disable phy pfm mode */
    892	phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
    893
    894	rtl8168g_disable_aldps(phydev);
    895	rtl8168g_config_eee_phy(phydev);
    896}
    897
    898static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp,
    899				      struct phy_device *phydev)
    900{
    901	/* Enable PHY auto speed down */
    902	phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
    903
    904	rtl8168g_phy_adjust_10m_aldps(phydev);
    905
    906	/* Enable EEE auto-fallback function */
    907	phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2));
    908
    909	/* Enable UC LPF tune function */
    910	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
    911
    912	/* set rg_sel_sdm_rate */
    913	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
    914
    915	rtl8168g_disable_aldps(phydev);
    916	rtl8168g_config_eee_phy(phydev);
    917}
    918
    919static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp,
    920				      struct phy_device *phydev)
    921{
    922	rtl8168g_phy_adjust_10m_aldps(phydev);
    923
    924	/* Enable UC LPF tune function */
    925	r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
    926
    927	/* Set rg_sel_sdm_rate */
    928	phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
    929
    930	/* Channel estimation parameters */
    931	r8168g_phy_param(phydev, 0x80f3, 0xff00, 0x8b00);
    932	r8168g_phy_param(phydev, 0x80f0, 0xff00, 0x3a00);
    933	r8168g_phy_param(phydev, 0x80ef, 0xff00, 0x0500);
    934	r8168g_phy_param(phydev, 0x80f6, 0xff00, 0x6e00);
    935	r8168g_phy_param(phydev, 0x80ec, 0xff00, 0x6800);
    936	r8168g_phy_param(phydev, 0x80ed, 0xff00, 0x7c00);
    937	r8168g_phy_param(phydev, 0x80f2, 0xff00, 0xf400);
    938	r8168g_phy_param(phydev, 0x80f4, 0xff00, 0x8500);
    939	r8168g_phy_param(phydev, 0x8110, 0xff00, 0xa800);
    940	r8168g_phy_param(phydev, 0x810f, 0xff00, 0x1d00);
    941	r8168g_phy_param(phydev, 0x8111, 0xff00, 0xf500);
    942	r8168g_phy_param(phydev, 0x8113, 0xff00, 0x6100);
    943	r8168g_phy_param(phydev, 0x8115, 0xff00, 0x9200);
    944	r8168g_phy_param(phydev, 0x810e, 0xff00, 0x0400);
    945	r8168g_phy_param(phydev, 0x810c, 0xff00, 0x7c00);
    946	r8168g_phy_param(phydev, 0x810b, 0xff00, 0x5a00);
    947	r8168g_phy_param(phydev, 0x80d1, 0xff00, 0xff00);
    948	r8168g_phy_param(phydev, 0x80cd, 0xff00, 0x9e00);
    949	r8168g_phy_param(phydev, 0x80d3, 0xff00, 0x0e00);
    950	r8168g_phy_param(phydev, 0x80d5, 0xff00, 0xca00);
    951	r8168g_phy_param(phydev, 0x80d7, 0xff00, 0x8400);
    952
    953	/* Force PWM-mode */
    954	phy_write(phydev, 0x1f, 0x0bcd);
    955	phy_write(phydev, 0x14, 0x5065);
    956	phy_write(phydev, 0x14, 0xd065);
    957	phy_write(phydev, 0x1f, 0x0bc8);
    958	phy_write(phydev, 0x12, 0x00ed);
    959	phy_write(phydev, 0x1f, 0x0bcd);
    960	phy_write(phydev, 0x14, 0x1065);
    961	phy_write(phydev, 0x14, 0x9065);
    962	phy_write(phydev, 0x14, 0x1065);
    963	phy_write(phydev, 0x1f, 0x0000);
    964
    965	rtl8168g_disable_aldps(phydev);
    966	rtl8168g_config_eee_phy(phydev);
    967}
    968
    969static void rtl8117_hw_phy_config(struct rtl8169_private *tp,
    970				  struct phy_device *phydev)
    971{
    972	/* CHN EST parameters adjust - fnet */
    973	r8168g_phy_param(phydev, 0x808e, 0xff00, 0x4800);
    974	r8168g_phy_param(phydev, 0x8090, 0xff00, 0xcc00);
    975	r8168g_phy_param(phydev, 0x8092, 0xff00, 0xb000);
    976
    977	r8168g_phy_param(phydev, 0x8088, 0xff00, 0x6000);
    978	r8168g_phy_param(phydev, 0x808b, 0x3f00, 0x0b00);
    979	r8168g_phy_param(phydev, 0x808d, 0x1f00, 0x0600);
    980	r8168g_phy_param(phydev, 0x808c, 0xff00, 0xb000);
    981	r8168g_phy_param(phydev, 0x80a0, 0xff00, 0x2800);
    982	r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x5000);
    983	r8168g_phy_param(phydev, 0x809b, 0xf800, 0xb000);
    984	r8168g_phy_param(phydev, 0x809a, 0xff00, 0x4b00);
    985	r8168g_phy_param(phydev, 0x809d, 0x3f00, 0x0800);
    986	r8168g_phy_param(phydev, 0x80a1, 0xff00, 0x7000);
    987	r8168g_phy_param(phydev, 0x809f, 0x1f00, 0x0300);
    988	r8168g_phy_param(phydev, 0x809e, 0xff00, 0x8800);
    989	r8168g_phy_param(phydev, 0x80b2, 0xff00, 0x2200);
    990	r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x9800);
    991	r8168g_phy_param(phydev, 0x80af, 0x3f00, 0x0800);
    992	r8168g_phy_param(phydev, 0x80b3, 0xff00, 0x6f00);
    993	r8168g_phy_param(phydev, 0x80b1, 0x1f00, 0x0300);
    994	r8168g_phy_param(phydev, 0x80b0, 0xff00, 0x9300);
    995
    996	r8168g_phy_param(phydev, 0x8011, 0x0000, 0x0800);
    997
    998	rtl8168g_enable_gphy_10m(phydev);
    999
   1000	r8168g_phy_param(phydev, 0x8016, 0x0000, 0x0400);
   1001
   1002	rtl8168g_disable_aldps(phydev);
   1003	rtl8168h_config_eee_phy(phydev);
   1004}
   1005
   1006static void rtl8102e_hw_phy_config(struct rtl8169_private *tp,
   1007				   struct phy_device *phydev)
   1008{
   1009	static const struct phy_reg phy_reg_init[] = {
   1010		{ 0x1f, 0x0003 },
   1011		{ 0x08, 0x441d },
   1012		{ 0x01, 0x9100 },
   1013		{ 0x1f, 0x0000 }
   1014	};
   1015
   1016	phy_set_bits(phydev, 0x11, BIT(12));
   1017	phy_set_bits(phydev, 0x19, BIT(13));
   1018	phy_set_bits(phydev, 0x10, BIT(15));
   1019
   1020	rtl_writephy_batch(phydev, phy_reg_init);
   1021}
   1022
   1023static void rtl8401_hw_phy_config(struct rtl8169_private *tp,
   1024				  struct phy_device *phydev)
   1025{
   1026	phy_set_bits(phydev, 0x11, BIT(12));
   1027	phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0003);
   1028}
   1029
   1030static void rtl8105e_hw_phy_config(struct rtl8169_private *tp,
   1031				   struct phy_device *phydev)
   1032{
   1033	/* Disable ALDPS before ram code */
   1034	phy_write(phydev, 0x18, 0x0310);
   1035	msleep(100);
   1036
   1037	r8169_apply_firmware(tp);
   1038
   1039	phy_write_paged(phydev, 0x0005, 0x1a, 0x0000);
   1040	phy_write_paged(phydev, 0x0004, 0x1c, 0x0000);
   1041	phy_write_paged(phydev, 0x0001, 0x15, 0x7701);
   1042}
   1043
   1044static void rtl8402_hw_phy_config(struct rtl8169_private *tp,
   1045				  struct phy_device *phydev)
   1046{
   1047	/* Disable ALDPS before setting firmware */
   1048	phy_write(phydev, 0x18, 0x0310);
   1049	msleep(20);
   1050
   1051	r8169_apply_firmware(tp);
   1052
   1053	/* EEE setting */
   1054	phy_write(phydev, 0x1f, 0x0004);
   1055	phy_write(phydev, 0x10, 0x401f);
   1056	phy_write(phydev, 0x19, 0x7030);
   1057	phy_write(phydev, 0x1f, 0x0000);
   1058}
   1059
   1060static void rtl8106e_hw_phy_config(struct rtl8169_private *tp,
   1061				   struct phy_device *phydev)
   1062{
   1063	static const struct phy_reg phy_reg_init[] = {
   1064		{ 0x1f, 0x0004 },
   1065		{ 0x10, 0xc07f },
   1066		{ 0x19, 0x7030 },
   1067		{ 0x1f, 0x0000 }
   1068	};
   1069
   1070	/* Disable ALDPS before ram code */
   1071	phy_write(phydev, 0x18, 0x0310);
   1072	msleep(100);
   1073
   1074	r8169_apply_firmware(tp);
   1075
   1076	rtl_writephy_batch(phydev, phy_reg_init);
   1077}
   1078
   1079static void rtl8125_legacy_force_mode(struct phy_device *phydev)
   1080{
   1081	phy_modify_paged(phydev, 0xa5b, 0x12, BIT(15), 0);
   1082}
   1083
   1084static void rtl8125a_1_hw_phy_config(struct rtl8169_private *tp,
   1085				     struct phy_device *phydev)
   1086{
   1087	phy_modify_paged(phydev, 0xad4, 0x10, 0x03ff, 0x0084);
   1088	phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010);
   1089	phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x0006);
   1090	phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006);
   1091	phy_modify_paged(phydev, 0xac0, 0x14, 0x0000, 0x1100);
   1092	phy_modify_paged(phydev, 0xac8, 0x15, 0xf000, 0x7000);
   1093	phy_modify_paged(phydev, 0xad1, 0x14, 0x0000, 0x0400);
   1094	phy_modify_paged(phydev, 0xad1, 0x15, 0x0000, 0x03ff);
   1095	phy_modify_paged(phydev, 0xad1, 0x16, 0x0000, 0x03ff);
   1096
   1097	r8168g_phy_param(phydev, 0x80ea, 0xff00, 0xc400);
   1098	r8168g_phy_param(phydev, 0x80eb, 0x0700, 0x0300);
   1099	r8168g_phy_param(phydev, 0x80f8, 0xff00, 0x1c00);
   1100	r8168g_phy_param(phydev, 0x80f1, 0xff00, 0x3000);
   1101	r8168g_phy_param(phydev, 0x80fe, 0xff00, 0xa500);
   1102	r8168g_phy_param(phydev, 0x8102, 0xff00, 0x5000);
   1103	r8168g_phy_param(phydev, 0x8105, 0xff00, 0x3300);
   1104	r8168g_phy_param(phydev, 0x8100, 0xff00, 0x7000);
   1105	r8168g_phy_param(phydev, 0x8104, 0xff00, 0xf000);
   1106	r8168g_phy_param(phydev, 0x8106, 0xff00, 0x6500);
   1107	r8168g_phy_param(phydev, 0x80dc, 0xff00, 0xed00);
   1108	r8168g_phy_param(phydev, 0x80df, 0x0000, 0x0100);
   1109	r8168g_phy_param(phydev, 0x80e1, 0x0100, 0x0000);
   1110
   1111	phy_modify_paged(phydev, 0xbf0, 0x13, 0x003f, 0x0038);
   1112	r8168g_phy_param(phydev, 0x819f, 0xffff, 0xd0b6);
   1113
   1114	phy_write_paged(phydev, 0xbc3, 0x12, 0x5555);
   1115	phy_modify_paged(phydev, 0xbf0, 0x15, 0x0e00, 0x0a00);
   1116	phy_modify_paged(phydev, 0xa5c, 0x10, 0x0400, 0x0000);
   1117	rtl8168g_enable_gphy_10m(phydev);
   1118
   1119	rtl8125a_config_eee_phy(phydev);
   1120}
   1121
   1122static void rtl8125a_2_hw_phy_config(struct rtl8169_private *tp,
   1123				     struct phy_device *phydev)
   1124{
   1125	int i;
   1126
   1127	phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010);
   1128	phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x03ff);
   1129	phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006);
   1130	phy_modify_paged(phydev, 0xac0, 0x14, 0x1100, 0x0000);
   1131	phy_modify_paged(phydev, 0xacc, 0x10, 0x0003, 0x0002);
   1132	phy_modify_paged(phydev, 0xad4, 0x10, 0x00e7, 0x0044);
   1133	phy_modify_paged(phydev, 0xac1, 0x12, 0x0080, 0x0000);
   1134	phy_modify_paged(phydev, 0xac8, 0x10, 0x0300, 0x0000);
   1135	phy_modify_paged(phydev, 0xac5, 0x17, 0x0007, 0x0002);
   1136	phy_write_paged(phydev, 0xad4, 0x16, 0x00a8);
   1137	phy_write_paged(phydev, 0xac5, 0x16, 0x01ff);
   1138	phy_modify_paged(phydev, 0xac8, 0x15, 0x00f0, 0x0030);
   1139
   1140	phy_write(phydev, 0x1f, 0x0b87);
   1141	phy_write(phydev, 0x16, 0x80a2);
   1142	phy_write(phydev, 0x17, 0x0153);
   1143	phy_write(phydev, 0x16, 0x809c);
   1144	phy_write(phydev, 0x17, 0x0153);
   1145	phy_write(phydev, 0x1f, 0x0000);
   1146
   1147	phy_write(phydev, 0x1f, 0x0a43);
   1148	phy_write(phydev, 0x13, 0x81B3);
   1149	phy_write(phydev, 0x14, 0x0043);
   1150	phy_write(phydev, 0x14, 0x00A7);
   1151	phy_write(phydev, 0x14, 0x00D6);
   1152	phy_write(phydev, 0x14, 0x00EC);
   1153	phy_write(phydev, 0x14, 0x00F6);
   1154	phy_write(phydev, 0x14, 0x00FB);
   1155	phy_write(phydev, 0x14, 0x00FD);
   1156	phy_write(phydev, 0x14, 0x00FF);
   1157	phy_write(phydev, 0x14, 0x00BB);
   1158	phy_write(phydev, 0x14, 0x0058);
   1159	phy_write(phydev, 0x14, 0x0029);
   1160	phy_write(phydev, 0x14, 0x0013);
   1161	phy_write(phydev, 0x14, 0x0009);
   1162	phy_write(phydev, 0x14, 0x0004);
   1163	phy_write(phydev, 0x14, 0x0002);
   1164	for (i = 0; i < 25; i++)
   1165		phy_write(phydev, 0x14, 0x0000);
   1166	phy_write(phydev, 0x1f, 0x0000);
   1167
   1168	r8168g_phy_param(phydev, 0x8257, 0xffff, 0x020F);
   1169	r8168g_phy_param(phydev, 0x80ea, 0xffff, 0x7843);
   1170
   1171	r8169_apply_firmware(tp);
   1172
   1173	phy_modify_paged(phydev, 0xd06, 0x14, 0x0000, 0x2000);
   1174
   1175	r8168g_phy_param(phydev, 0x81a2, 0x0000, 0x0100);
   1176
   1177	phy_modify_paged(phydev, 0xb54, 0x16, 0xff00, 0xdb00);
   1178	phy_modify_paged(phydev, 0xa45, 0x12, 0x0001, 0x0000);
   1179	phy_modify_paged(phydev, 0xa5d, 0x12, 0x0000, 0x0020);
   1180	phy_modify_paged(phydev, 0xad4, 0x17, 0x0010, 0x0000);
   1181	phy_modify_paged(phydev, 0xa86, 0x15, 0x0001, 0x0000);
   1182	rtl8168g_enable_gphy_10m(phydev);
   1183
   1184	rtl8125a_config_eee_phy(phydev);
   1185}
   1186
   1187static void rtl8125b_hw_phy_config(struct rtl8169_private *tp,
   1188				   struct phy_device *phydev)
   1189{
   1190	r8169_apply_firmware(tp);
   1191
   1192	phy_modify_paged(phydev, 0xa44, 0x11, 0x0000, 0x0800);
   1193	phy_modify_paged(phydev, 0xac4, 0x13, 0x00f0, 0x0090);
   1194	phy_modify_paged(phydev, 0xad3, 0x10, 0x0003, 0x0001);
   1195
   1196	phy_write(phydev, 0x1f, 0x0b87);
   1197	phy_write(phydev, 0x16, 0x80f5);
   1198	phy_write(phydev, 0x17, 0x760e);
   1199	phy_write(phydev, 0x16, 0x8107);
   1200	phy_write(phydev, 0x17, 0x360e);
   1201	phy_write(phydev, 0x16, 0x8551);
   1202	phy_modify(phydev, 0x17, 0xff00, 0x0800);
   1203	phy_write(phydev, 0x1f, 0x0000);
   1204
   1205	phy_modify_paged(phydev, 0xbf0, 0x10, 0xe000, 0xa000);
   1206	phy_modify_paged(phydev, 0xbf4, 0x13, 0x0f00, 0x0300);
   1207
   1208	r8168g_phy_param(phydev, 0x8044, 0xffff, 0x2417);
   1209	r8168g_phy_param(phydev, 0x804a, 0xffff, 0x2417);
   1210	r8168g_phy_param(phydev, 0x8050, 0xffff, 0x2417);
   1211	r8168g_phy_param(phydev, 0x8056, 0xffff, 0x2417);
   1212	r8168g_phy_param(phydev, 0x805c, 0xffff, 0x2417);
   1213	r8168g_phy_param(phydev, 0x8062, 0xffff, 0x2417);
   1214	r8168g_phy_param(phydev, 0x8068, 0xffff, 0x2417);
   1215	r8168g_phy_param(phydev, 0x806e, 0xffff, 0x2417);
   1216	r8168g_phy_param(phydev, 0x8074, 0xffff, 0x2417);
   1217	r8168g_phy_param(phydev, 0x807a, 0xffff, 0x2417);
   1218
   1219	phy_modify_paged(phydev, 0xa4c, 0x15, 0x0000, 0x0040);
   1220	phy_modify_paged(phydev, 0xbf8, 0x12, 0xe000, 0xa000);
   1221
   1222	rtl8125_legacy_force_mode(phydev);
   1223	rtl8125b_config_eee_phy(phydev);
   1224}
   1225
   1226void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
   1227			 enum mac_version ver)
   1228{
   1229	static const rtl_phy_cfg_fct phy_configs[] = {
   1230		/* PCI devices. */
   1231		[RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config,
   1232		[RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config,
   1233		[RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config,
   1234		[RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config,
   1235		[RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config,
   1236		/* PCI-E devices. */
   1237		[RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config,
   1238		[RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config,
   1239		[RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config,
   1240		[RTL_GIGA_MAC_VER_10] = NULL,
   1241		[RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config,
   1242		[RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config,
   1243		[RTL_GIGA_MAC_VER_13] = NULL,
   1244		[RTL_GIGA_MAC_VER_14] = rtl8401_hw_phy_config,
   1245		[RTL_GIGA_MAC_VER_16] = NULL,
   1246		[RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config,
   1247		[RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config,
   1248		[RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config,
   1249		[RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config,
   1250		[RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config,
   1251		[RTL_GIGA_MAC_VER_22] = rtl8168c_3_hw_phy_config,
   1252		[RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config,
   1253		[RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config,
   1254		[RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config,
   1255		[RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config,
   1256		[RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config,
   1257		[RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config,
   1258		[RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config,
   1259		[RTL_GIGA_MAC_VER_31] = NULL,
   1260		[RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config,
   1261		[RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config,
   1262		[RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config,
   1263		[RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config,
   1264		[RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config,
   1265		[RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config,
   1266		[RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config,
   1267		[RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config,
   1268		[RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config,
   1269		[RTL_GIGA_MAC_VER_41] = NULL,
   1270		[RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config,
   1271		[RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config,
   1272		[RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config,
   1273		[RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config,
   1274		[RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config,
   1275		[RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config,
   1276		[RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config,
   1277		[RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config,
   1278		[RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config,
   1279		[RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config,
   1280		[RTL_GIGA_MAC_VER_52] = rtl8117_hw_phy_config,
   1281		[RTL_GIGA_MAC_VER_53] = rtl8117_hw_phy_config,
   1282		[RTL_GIGA_MAC_VER_60] = rtl8125a_1_hw_phy_config,
   1283		[RTL_GIGA_MAC_VER_61] = rtl8125a_2_hw_phy_config,
   1284		[RTL_GIGA_MAC_VER_63] = rtl8125b_hw_phy_config,
   1285	};
   1286
   1287	if (phy_configs[ver])
   1288		phy_configs[ver](tp, phydev);
   1289}