1 // SPDX-License-Identifier: GPL-2.0-only
3 * r8169_phy_config.c: RealTek 8169/8168/8101 ethernet driver.
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.
9 * See MAINTAINERS file for support contact information.
12 #include <linux/delay.h>
13 #include <linux/phy.h>
17 typedef void (*rtl_phy_cfg_fct
)(struct rtl8169_private
*tp
,
18 struct phy_device
*phydev
);
20 static void r8168d_modify_extpage(struct phy_device
*phydev
, int extpage
,
21 int reg
, u16 mask
, u16 val
)
23 int oldpage
= phy_select_page(phydev
, 0x0007);
25 __phy_write(phydev
, 0x1e, extpage
);
26 __phy_modify(phydev
, reg
, mask
, val
);
28 phy_restore_page(phydev
, oldpage
, 0);
31 static void r8168d_phy_param(struct phy_device
*phydev
, u16 parm
,
34 int oldpage
= phy_select_page(phydev
, 0x0005);
36 __phy_write(phydev
, 0x05, parm
);
37 __phy_modify(phydev
, 0x06, mask
, val
);
39 phy_restore_page(phydev
, oldpage
, 0);
42 static void r8168g_phy_param(struct phy_device
*phydev
, u16 parm
,
45 int oldpage
= phy_select_page(phydev
, 0x0a43);
47 __phy_write(phydev
, 0x13, parm
);
48 __phy_modify(phydev
, 0x14, mask
, val
);
50 phy_restore_page(phydev
, oldpage
, 0);
58 static void __rtl_writephy_batch(struct phy_device
*phydev
,
59 const struct phy_reg
*regs
, int len
)
61 phy_lock_mdio_bus(phydev
);
64 __phy_write(phydev
, regs
->reg
, regs
->val
);
68 phy_unlock_mdio_bus(phydev
);
71 #define rtl_writephy_batch(p, a) __rtl_writephy_batch(p, a, ARRAY_SIZE(a))
73 static void rtl8168f_config_eee_phy(struct phy_device
*phydev
)
75 r8168d_modify_extpage(phydev
, 0x0020, 0x15, 0, BIT(8));
76 r8168d_phy_param(phydev
, 0x8b85, 0, BIT(13));
79 static void rtl8168g_config_eee_phy(struct phy_device
*phydev
)
81 phy_modify_paged(phydev
, 0x0a43, 0x11, 0, BIT(4));
84 static void rtl8168h_config_eee_phy(struct phy_device
*phydev
)
86 rtl8168g_config_eee_phy(phydev
);
88 phy_modify_paged(phydev
, 0xa4a, 0x11, 0x0000, 0x0200);
89 phy_modify_paged(phydev
, 0xa42, 0x14, 0x0000, 0x0080);
92 static void rtl8125_common_config_eee_phy(struct phy_device
*phydev
)
94 phy_modify_paged(phydev
, 0xa6d, 0x14, 0x0010, 0x0000);
95 phy_modify_paged(phydev
, 0xa42, 0x14, 0x0080, 0x0000);
96 phy_modify_paged(phydev
, 0xa4a, 0x11, 0x0200, 0x0000);
99 static void rtl8125_config_eee_phy(struct phy_device
*phydev
)
101 rtl8168g_config_eee_phy(phydev
);
102 rtl8125_common_config_eee_phy(phydev
);
105 static void rtl8169s_hw_phy_config(struct rtl8169_private
*tp
,
106 struct phy_device
*phydev
)
108 static const struct phy_reg phy_reg_init
[] = {
170 rtl_writephy_batch(phydev
, phy_reg_init
);
173 static void rtl8169sb_hw_phy_config(struct rtl8169_private
*tp
,
174 struct phy_device
*phydev
)
176 phy_write_paged(phydev
, 0x0002, 0x01, 0x90d0);
179 static void rtl8169scd_hw_phy_config(struct rtl8169_private
*tp
,
180 struct phy_device
*phydev
)
182 static const struct phy_reg phy_reg_init
[] = {
222 rtl_writephy_batch(phydev
, phy_reg_init
);
225 static void rtl8169sce_hw_phy_config(struct rtl8169_private
*tp
,
226 struct phy_device
*phydev
)
228 static const struct phy_reg phy_reg_init
[] = {
276 rtl_writephy_batch(phydev
, phy_reg_init
);
279 static void rtl8168bb_hw_phy_config(struct rtl8169_private
*tp
,
280 struct phy_device
*phydev
)
282 phy_write(phydev
, 0x1f, 0x0001);
283 phy_set_bits(phydev
, 0x16, BIT(0));
284 phy_write(phydev
, 0x10, 0xf41b);
285 phy_write(phydev
, 0x1f, 0x0000);
288 static void rtl8168bef_hw_phy_config(struct rtl8169_private
*tp
,
289 struct phy_device
*phydev
)
291 phy_write_paged(phydev
, 0x0001, 0x10, 0xf41b);
294 static void rtl8168cp_1_hw_phy_config(struct rtl8169_private
*tp
,
295 struct phy_device
*phydev
)
297 phy_write(phydev
, 0x1d, 0x0f00);
298 phy_write_paged(phydev
, 0x0002, 0x0c, 0x1ec8);
301 static void rtl8168cp_2_hw_phy_config(struct rtl8169_private
*tp
,
302 struct phy_device
*phydev
)
304 phy_set_bits(phydev
, 0x14, BIT(5));
305 phy_set_bits(phydev
, 0x0d, BIT(5));
306 phy_write_paged(phydev
, 0x0001, 0x1d, 0x3d98);
309 static void rtl8168c_1_hw_phy_config(struct rtl8169_private
*tp
,
310 struct phy_device
*phydev
)
312 static const struct phy_reg phy_reg_init
[] = {
332 rtl_writephy_batch(phydev
, phy_reg_init
);
334 phy_set_bits(phydev
, 0x14, BIT(5));
335 phy_set_bits(phydev
, 0x0d, BIT(5));
338 static void rtl8168c_2_hw_phy_config(struct rtl8169_private
*tp
,
339 struct phy_device
*phydev
)
341 static const struct phy_reg phy_reg_init
[] = {
359 rtl_writephy_batch(phydev
, phy_reg_init
);
361 phy_set_bits(phydev
, 0x16, BIT(0));
362 phy_set_bits(phydev
, 0x14, BIT(5));
363 phy_set_bits(phydev
, 0x0d, BIT(5));
366 static void rtl8168c_3_hw_phy_config(struct rtl8169_private
*tp
,
367 struct phy_device
*phydev
)
369 static const struct phy_reg phy_reg_init
[] = {
381 rtl_writephy_batch(phydev
, phy_reg_init
);
383 phy_set_bits(phydev
, 0x16, BIT(0));
384 phy_set_bits(phydev
, 0x14, BIT(5));
385 phy_set_bits(phydev
, 0x0d, BIT(5));
388 static const struct phy_reg rtl8168d_1_phy_reg_init_0
[] = {
389 /* Channel Estimation */
410 * Enhance line driver power
419 * Can not link to 1Gbps with bad cable
420 * Decrease SNR threshold form 21.07dB to 19.04dB
429 static void rtl8168d_apply_firmware_cond(struct rtl8169_private
*tp
,
430 struct phy_device
*phydev
,
435 phy_write(phydev
, 0x1f, 0x0005);
436 phy_write(phydev
, 0x05, 0x001b);
437 reg_val
= phy_read(phydev
, 0x06);
438 phy_write(phydev
, 0x1f, 0x0000);
441 phydev_warn(phydev
, "chipset not ready for firmware\n");
443 r8169_apply_firmware(tp
);
446 static void rtl8168d_1_common(struct phy_device
*phydev
)
450 phy_write_paged(phydev
, 0x0002, 0x05, 0x669a);
451 r8168d_phy_param(phydev
, 0x8330, 0xffff, 0x669a);
452 phy_write(phydev
, 0x1f, 0x0002);
454 val
= phy_read(phydev
, 0x0d);
456 if ((val
& 0x00ff) != 0x006c) {
457 static const u16 set
[] = {
458 0x0065, 0x0066, 0x0067, 0x0068,
459 0x0069, 0x006a, 0x006b, 0x006c
464 for (i
= 0; i
< ARRAY_SIZE(set
); i
++)
465 phy_write(phydev
, 0x0d, val
| set
[i
]);
469 static void rtl8168d_1_hw_phy_config(struct rtl8169_private
*tp
,
470 struct phy_device
*phydev
)
472 rtl_writephy_batch(phydev
, rtl8168d_1_phy_reg_init_0
);
476 * Fine Tune Switching regulator parameter
478 phy_write(phydev
, 0x1f, 0x0002);
479 phy_modify(phydev
, 0x0b, 0x00ef, 0x0010);
480 phy_modify(phydev
, 0x0c, 0x5d00, 0xa200);
482 if (rtl8168d_efuse_read(tp
, 0x01) == 0xb1) {
483 rtl8168d_1_common(phydev
);
485 phy_write_paged(phydev
, 0x0002, 0x05, 0x6662);
486 r8168d_phy_param(phydev
, 0x8330, 0xffff, 0x6662);
489 /* RSET couple improve */
490 phy_write(phydev
, 0x1f, 0x0002);
491 phy_set_bits(phydev
, 0x0d, 0x0300);
492 phy_set_bits(phydev
, 0x0f, 0x0010);
494 /* Fine tune PLL performance */
495 phy_write(phydev
, 0x1f, 0x0002);
496 phy_modify(phydev
, 0x02, 0x0600, 0x0100);
497 phy_clear_bits(phydev
, 0x03, 0xe000);
498 phy_write(phydev
, 0x1f, 0x0000);
500 rtl8168d_apply_firmware_cond(tp
, phydev
, 0xbf00);
503 static void rtl8168d_2_hw_phy_config(struct rtl8169_private
*tp
,
504 struct phy_device
*phydev
)
506 rtl_writephy_batch(phydev
, rtl8168d_1_phy_reg_init_0
);
508 if (rtl8168d_efuse_read(tp
, 0x01) == 0xb1) {
509 rtl8168d_1_common(phydev
);
511 phy_write_paged(phydev
, 0x0002, 0x05, 0x2642);
512 r8168d_phy_param(phydev
, 0x8330, 0xffff, 0x2642);
515 /* Fine tune PLL performance */
516 phy_write(phydev
, 0x1f, 0x0002);
517 phy_modify(phydev
, 0x02, 0x0600, 0x0100);
518 phy_clear_bits(phydev
, 0x03, 0xe000);
519 phy_write(phydev
, 0x1f, 0x0000);
521 /* Switching regulator Slew rate */
522 phy_modify_paged(phydev
, 0x0002, 0x0f, 0x0000, 0x0017);
524 rtl8168d_apply_firmware_cond(tp
, phydev
, 0xb300);
527 static void rtl8168d_4_hw_phy_config(struct rtl8169_private
*tp
,
528 struct phy_device
*phydev
)
530 phy_write_paged(phydev
, 0x0001, 0x17, 0x0cc0);
531 r8168d_modify_extpage(phydev
, 0x002d, 0x18, 0xffff, 0x0040);
532 phy_set_bits(phydev
, 0x0d, BIT(5));
535 static void rtl8168e_1_hw_phy_config(struct rtl8169_private
*tp
,
536 struct phy_device
*phydev
)
538 static const struct phy_reg phy_reg_init
[] = {
539 /* Channel estimation fine tune */
549 r8169_apply_firmware(tp
);
551 /* Enable Delay cap */
552 r8168d_phy_param(phydev
, 0x8b80, 0xffff, 0xc896);
554 rtl_writephy_batch(phydev
, phy_reg_init
);
556 /* Update PFM & 10M TX idle timer */
557 r8168d_modify_extpage(phydev
, 0x002f, 0x15, 0xffff, 0x1919);
559 r8168d_modify_extpage(phydev
, 0x00ac, 0x18, 0xffff, 0x0006);
561 /* DCO enable for 10M IDLE Power */
562 r8168d_modify_extpage(phydev
, 0x0023, 0x17, 0x0000, 0x0006);
564 /* For impedance matching */
565 phy_modify_paged(phydev
, 0x0002, 0x08, 0x7f00, 0x8000);
567 /* PHY auto speed down */
568 r8168d_modify_extpage(phydev
, 0x002d, 0x18, 0x0000, 0x0050);
569 phy_set_bits(phydev
, 0x14, BIT(15));
571 r8168d_phy_param(phydev
, 0x8b86, 0x0000, 0x0001);
572 r8168d_phy_param(phydev
, 0x8b85, 0x2000, 0x0000);
574 r8168d_modify_extpage(phydev
, 0x0020, 0x15, 0x1100, 0x0000);
575 phy_write_paged(phydev
, 0x0006, 0x00, 0x5a00);
577 phy_write_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_EEE_ADV
, 0x0000);
580 static void rtl8168e_2_hw_phy_config(struct rtl8169_private
*tp
,
581 struct phy_device
*phydev
)
583 r8169_apply_firmware(tp
);
585 /* Enable Delay cap */
586 r8168d_modify_extpage(phydev
, 0x00ac, 0x18, 0xffff, 0x0006);
588 /* Channel estimation fine tune */
589 phy_write_paged(phydev
, 0x0003, 0x09, 0xa20f);
592 r8168d_phy_param(phydev
, 0x8b5b, 0xffff, 0x9222);
593 r8168d_phy_param(phydev
, 0x8b6d, 0xffff, 0x8000);
594 r8168d_phy_param(phydev
, 0x8b76, 0xffff, 0x8000);
596 /* For 4-corner performance improve */
597 phy_write(phydev
, 0x1f, 0x0005);
598 phy_write(phydev
, 0x05, 0x8b80);
599 phy_set_bits(phydev
, 0x17, 0x0006);
600 phy_write(phydev
, 0x1f, 0x0000);
602 /* PHY auto speed down */
603 r8168d_modify_extpage(phydev
, 0x002d, 0x18, 0x0000, 0x0010);
604 phy_set_bits(phydev
, 0x14, BIT(15));
606 /* improve 10M EEE waveform */
607 r8168d_phy_param(phydev
, 0x8b86, 0x0000, 0x0001);
609 /* Improve 2-pair detection performance */
610 r8168d_phy_param(phydev
, 0x8b85, 0x0000, 0x4000);
612 rtl8168f_config_eee_phy(phydev
);
615 phy_write(phydev
, 0x1f, 0x0003);
616 phy_set_bits(phydev
, 0x19, BIT(0));
617 phy_set_bits(phydev
, 0x10, BIT(10));
618 phy_write(phydev
, 0x1f, 0x0000);
619 phy_modify_paged(phydev
, 0x0005, 0x01, 0, BIT(8));
622 static void rtl8168f_hw_phy_config(struct rtl8169_private
*tp
,
623 struct phy_device
*phydev
)
625 /* For 4-corner performance improve */
626 r8168d_phy_param(phydev
, 0x8b80, 0x0000, 0x0006);
628 /* PHY auto speed down */
629 r8168d_modify_extpage(phydev
, 0x002d, 0x18, 0x0000, 0x0010);
630 phy_set_bits(phydev
, 0x14, BIT(15));
632 /* Improve 10M EEE waveform */
633 r8168d_phy_param(phydev
, 0x8b86, 0x0000, 0x0001);
635 rtl8168f_config_eee_phy(phydev
);
638 static void rtl8168f_1_hw_phy_config(struct rtl8169_private
*tp
,
639 struct phy_device
*phydev
)
641 r8169_apply_firmware(tp
);
643 /* Channel estimation fine tune */
644 phy_write_paged(phydev
, 0x0003, 0x09, 0xa20f);
646 /* Modify green table for giga & fnet */
647 r8168d_phy_param(phydev
, 0x8b55, 0xffff, 0x0000);
648 r8168d_phy_param(phydev
, 0x8b5e, 0xffff, 0x0000);
649 r8168d_phy_param(phydev
, 0x8b67, 0xffff, 0x0000);
650 r8168d_phy_param(phydev
, 0x8b70, 0xffff, 0x0000);
651 r8168d_modify_extpage(phydev
, 0x0078, 0x17, 0xffff, 0x0000);
652 r8168d_modify_extpage(phydev
, 0x0078, 0x19, 0xffff, 0x00fb);
654 /* Modify green table for 10M */
655 r8168d_phy_param(phydev
, 0x8b79, 0xffff, 0xaa00);
657 /* Disable hiimpedance detection (RTCT) */
658 phy_write_paged(phydev
, 0x0003, 0x01, 0x328a);
660 rtl8168f_hw_phy_config(tp
, phydev
);
662 /* Improve 2-pair detection performance */
663 r8168d_phy_param(phydev
, 0x8b85, 0x0000, 0x4000);
666 static void rtl8168f_2_hw_phy_config(struct rtl8169_private
*tp
,
667 struct phy_device
*phydev
)
669 r8169_apply_firmware(tp
);
671 rtl8168f_hw_phy_config(tp
, phydev
);
674 static void rtl8411_hw_phy_config(struct rtl8169_private
*tp
,
675 struct phy_device
*phydev
)
677 r8169_apply_firmware(tp
);
679 rtl8168f_hw_phy_config(tp
, phydev
);
681 /* Improve 2-pair detection performance */
682 r8168d_phy_param(phydev
, 0x8b85, 0x0000, 0x4000);
684 /* Channel estimation fine tune */
685 phy_write_paged(phydev
, 0x0003, 0x09, 0xa20f);
687 /* Modify green table for giga & fnet */
688 r8168d_phy_param(phydev
, 0x8b55, 0xffff, 0x0000);
689 r8168d_phy_param(phydev
, 0x8b5e, 0xffff, 0x0000);
690 r8168d_phy_param(phydev
, 0x8b67, 0xffff, 0x0000);
691 r8168d_phy_param(phydev
, 0x8b70, 0xffff, 0x0000);
692 r8168d_modify_extpage(phydev
, 0x0078, 0x17, 0xffff, 0x0000);
693 r8168d_modify_extpage(phydev
, 0x0078, 0x19, 0xffff, 0x00aa);
695 /* Modify green table for 10M */
696 r8168d_phy_param(phydev
, 0x8b79, 0xffff, 0xaa00);
698 /* Disable hiimpedance detection (RTCT) */
699 phy_write_paged(phydev
, 0x0003, 0x01, 0x328a);
701 /* Modify green table for giga */
702 r8168d_phy_param(phydev
, 0x8b54, 0x0800, 0x0000);
703 r8168d_phy_param(phydev
, 0x8b5d, 0x0800, 0x0000);
704 r8168d_phy_param(phydev
, 0x8a7c, 0x0100, 0x0000);
705 r8168d_phy_param(phydev
, 0x8a7f, 0x0000, 0x0100);
706 r8168d_phy_param(phydev
, 0x8a82, 0x0100, 0x0000);
707 r8168d_phy_param(phydev
, 0x8a85, 0x0100, 0x0000);
708 r8168d_phy_param(phydev
, 0x8a88, 0x0100, 0x0000);
710 /* uc same-seed solution */
711 r8168d_phy_param(phydev
, 0x8b85, 0x0000, 0x8000);
714 phy_write(phydev
, 0x1f, 0x0003);
715 phy_clear_bits(phydev
, 0x19, BIT(0));
716 phy_clear_bits(phydev
, 0x10, BIT(10));
717 phy_write(phydev
, 0x1f, 0x0000);
720 static void rtl8168g_disable_aldps(struct phy_device
*phydev
)
722 phy_modify_paged(phydev
, 0x0a43, 0x10, BIT(2), 0);
725 static void rtl8168g_enable_gphy_10m(struct phy_device
*phydev
)
727 phy_modify_paged(phydev
, 0x0a44, 0x11, 0, BIT(11));
730 static void rtl8168g_phy_adjust_10m_aldps(struct phy_device
*phydev
)
732 phy_modify_paged(phydev
, 0x0bcc, 0x14, BIT(8), 0);
733 phy_modify_paged(phydev
, 0x0a44, 0x11, 0, BIT(7) | BIT(6));
734 r8168g_phy_param(phydev
, 0x8084, 0x6000, 0x0000);
735 phy_modify_paged(phydev
, 0x0a43, 0x10, 0x0000, 0x1003);
738 static void rtl8168g_1_hw_phy_config(struct rtl8169_private
*tp
,
739 struct phy_device
*phydev
)
743 r8169_apply_firmware(tp
);
745 ret
= phy_read_paged(phydev
, 0x0a46, 0x10);
747 phy_modify_paged(phydev
, 0x0bcc, 0x12, BIT(15), 0);
749 phy_modify_paged(phydev
, 0x0bcc, 0x12, 0, BIT(15));
751 ret
= phy_read_paged(phydev
, 0x0a46, 0x13);
753 phy_modify_paged(phydev
, 0x0c41, 0x15, 0, BIT(1));
755 phy_modify_paged(phydev
, 0x0c41, 0x15, BIT(1), 0);
757 /* Enable PHY auto speed down */
758 phy_modify_paged(phydev
, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
760 rtl8168g_phy_adjust_10m_aldps(phydev
);
762 /* EEE auto-fallback function */
763 phy_modify_paged(phydev
, 0x0a4b, 0x11, 0, BIT(2));
765 /* Enable UC LPF tune function */
766 r8168g_phy_param(phydev
, 0x8012, 0x0000, 0x8000);
768 phy_modify_paged(phydev
, 0x0c42, 0x11, BIT(13), BIT(14));
770 /* Improve SWR Efficiency */
771 phy_write(phydev
, 0x1f, 0x0bcd);
772 phy_write(phydev
, 0x14, 0x5065);
773 phy_write(phydev
, 0x14, 0xd065);
774 phy_write(phydev
, 0x1f, 0x0bc8);
775 phy_write(phydev
, 0x11, 0x5655);
776 phy_write(phydev
, 0x1f, 0x0bcd);
777 phy_write(phydev
, 0x14, 0x1065);
778 phy_write(phydev
, 0x14, 0x9065);
779 phy_write(phydev
, 0x14, 0x1065);
780 phy_write(phydev
, 0x1f, 0x0000);
782 rtl8168g_disable_aldps(phydev
);
783 rtl8168g_config_eee_phy(phydev
);
786 static void rtl8168g_2_hw_phy_config(struct rtl8169_private
*tp
,
787 struct phy_device
*phydev
)
789 r8169_apply_firmware(tp
);
790 rtl8168g_config_eee_phy(phydev
);
793 static void rtl8168h_2_hw_phy_config(struct rtl8169_private
*tp
,
794 struct phy_device
*phydev
)
799 r8169_apply_firmware(tp
);
801 /* CHIN EST parameter update */
802 r8168g_phy_param(phydev
, 0x808a, 0x003f, 0x000a);
804 /* enable R-tune & PGA-retune function */
805 r8168g_phy_param(phydev
, 0x0811, 0x0000, 0x0800);
806 phy_modify_paged(phydev
, 0x0a42, 0x16, 0x0000, 0x0002);
808 rtl8168g_enable_gphy_10m(phydev
);
810 ioffset
= rtl8168h_2_get_adc_bias_ioffset(tp
);
811 if (ioffset
!= 0xffff)
812 phy_write_paged(phydev
, 0x0bcf, 0x16, ioffset
);
814 /* Modify rlen (TX LPF corner frequency) level */
815 data
= phy_read_paged(phydev
, 0x0bcd, 0x16);
820 data
= rlen
| (rlen
<< 4) | (rlen
<< 8) | (rlen
<< 12);
821 phy_write_paged(phydev
, 0x0bcd, 0x17, data
);
823 /* disable phy pfm mode */
824 phy_modify_paged(phydev
, 0x0a44, 0x11, BIT(7), 0);
826 /* disable 10m pll off */
827 phy_modify_paged(phydev
, 0x0a43, 0x10, BIT(0), 0);
829 rtl8168g_disable_aldps(phydev
);
830 rtl8168g_config_eee_phy(phydev
);
833 static void rtl8168ep_2_hw_phy_config(struct rtl8169_private
*tp
,
834 struct phy_device
*phydev
)
836 rtl8168g_phy_adjust_10m_aldps(phydev
);
838 /* Enable UC LPF tune function */
839 r8168g_phy_param(phydev
, 0x8012, 0x0000, 0x8000);
841 /* Set rg_sel_sdm_rate */
842 phy_modify_paged(phydev
, 0x0c42, 0x11, BIT(13), BIT(14));
844 /* Channel estimation parameters */
845 r8168g_phy_param(phydev
, 0x80f3, 0xff00, 0x8b00);
846 r8168g_phy_param(phydev
, 0x80f0, 0xff00, 0x3a00);
847 r8168g_phy_param(phydev
, 0x80ef, 0xff00, 0x0500);
848 r8168g_phy_param(phydev
, 0x80f6, 0xff00, 0x6e00);
849 r8168g_phy_param(phydev
, 0x80ec, 0xff00, 0x6800);
850 r8168g_phy_param(phydev
, 0x80ed, 0xff00, 0x7c00);
851 r8168g_phy_param(phydev
, 0x80f2, 0xff00, 0xf400);
852 r8168g_phy_param(phydev
, 0x80f4, 0xff00, 0x8500);
853 r8168g_phy_param(phydev
, 0x8110, 0xff00, 0xa800);
854 r8168g_phy_param(phydev
, 0x810f, 0xff00, 0x1d00);
855 r8168g_phy_param(phydev
, 0x8111, 0xff00, 0xf500);
856 r8168g_phy_param(phydev
, 0x8113, 0xff00, 0x6100);
857 r8168g_phy_param(phydev
, 0x8115, 0xff00, 0x9200);
858 r8168g_phy_param(phydev
, 0x810e, 0xff00, 0x0400);
859 r8168g_phy_param(phydev
, 0x810c, 0xff00, 0x7c00);
860 r8168g_phy_param(phydev
, 0x810b, 0xff00, 0x5a00);
861 r8168g_phy_param(phydev
, 0x80d1, 0xff00, 0xff00);
862 r8168g_phy_param(phydev
, 0x80cd, 0xff00, 0x9e00);
863 r8168g_phy_param(phydev
, 0x80d3, 0xff00, 0x0e00);
864 r8168g_phy_param(phydev
, 0x80d5, 0xff00, 0xca00);
865 r8168g_phy_param(phydev
, 0x80d7, 0xff00, 0x8400);
868 phy_write(phydev
, 0x1f, 0x0bcd);
869 phy_write(phydev
, 0x14, 0x5065);
870 phy_write(phydev
, 0x14, 0xd065);
871 phy_write(phydev
, 0x1f, 0x0bc8);
872 phy_write(phydev
, 0x12, 0x00ed);
873 phy_write(phydev
, 0x1f, 0x0bcd);
874 phy_write(phydev
, 0x14, 0x1065);
875 phy_write(phydev
, 0x14, 0x9065);
876 phy_write(phydev
, 0x14, 0x1065);
877 phy_write(phydev
, 0x1f, 0x0000);
879 rtl8168g_disable_aldps(phydev
);
880 rtl8168g_config_eee_phy(phydev
);
883 static void rtl8117_hw_phy_config(struct rtl8169_private
*tp
,
884 struct phy_device
*phydev
)
886 /* CHN EST parameters adjust - fnet */
887 r8168g_phy_param(phydev
, 0x808e, 0xff00, 0x4800);
888 r8168g_phy_param(phydev
, 0x8090, 0xff00, 0xcc00);
889 r8168g_phy_param(phydev
, 0x8092, 0xff00, 0xb000);
891 r8168g_phy_param(phydev
, 0x8088, 0xff00, 0x6000);
892 r8168g_phy_param(phydev
, 0x808b, 0x3f00, 0x0b00);
893 r8168g_phy_param(phydev
, 0x808d, 0x1f00, 0x0600);
894 r8168g_phy_param(phydev
, 0x808c, 0xff00, 0xb000);
895 r8168g_phy_param(phydev
, 0x80a0, 0xff00, 0x2800);
896 r8168g_phy_param(phydev
, 0x80a2, 0xff00, 0x5000);
897 r8168g_phy_param(phydev
, 0x809b, 0xf800, 0xb000);
898 r8168g_phy_param(phydev
, 0x809a, 0xff00, 0x4b00);
899 r8168g_phy_param(phydev
, 0x809d, 0x3f00, 0x0800);
900 r8168g_phy_param(phydev
, 0x80a1, 0xff00, 0x7000);
901 r8168g_phy_param(phydev
, 0x809f, 0x1f00, 0x0300);
902 r8168g_phy_param(phydev
, 0x809e, 0xff00, 0x8800);
903 r8168g_phy_param(phydev
, 0x80b2, 0xff00, 0x2200);
904 r8168g_phy_param(phydev
, 0x80ad, 0xf800, 0x9800);
905 r8168g_phy_param(phydev
, 0x80af, 0x3f00, 0x0800);
906 r8168g_phy_param(phydev
, 0x80b3, 0xff00, 0x6f00);
907 r8168g_phy_param(phydev
, 0x80b1, 0x1f00, 0x0300);
908 r8168g_phy_param(phydev
, 0x80b0, 0xff00, 0x9300);
910 r8168g_phy_param(phydev
, 0x8011, 0x0000, 0x0800);
912 rtl8168g_enable_gphy_10m(phydev
);
914 r8168g_phy_param(phydev
, 0x8016, 0x0000, 0x0400);
916 rtl8168g_disable_aldps(phydev
);
917 rtl8168h_config_eee_phy(phydev
);
920 static void rtl8102e_hw_phy_config(struct rtl8169_private
*tp
,
921 struct phy_device
*phydev
)
923 static const struct phy_reg phy_reg_init
[] = {
930 phy_set_bits(phydev
, 0x11, BIT(12));
931 phy_set_bits(phydev
, 0x19, BIT(13));
932 phy_set_bits(phydev
, 0x10, BIT(15));
934 rtl_writephy_batch(phydev
, phy_reg_init
);
937 static void rtl8401_hw_phy_config(struct rtl8169_private
*tp
,
938 struct phy_device
*phydev
)
940 phy_set_bits(phydev
, 0x11, BIT(12));
941 phy_modify_paged(phydev
, 0x0002, 0x0f, 0x0000, 0x0003);
944 static void rtl8105e_hw_phy_config(struct rtl8169_private
*tp
,
945 struct phy_device
*phydev
)
947 /* Disable ALDPS before ram code */
948 phy_write(phydev
, 0x18, 0x0310);
951 r8169_apply_firmware(tp
);
953 phy_write_paged(phydev
, 0x0005, 0x1a, 0x0000);
954 phy_write_paged(phydev
, 0x0004, 0x1c, 0x0000);
955 phy_write_paged(phydev
, 0x0001, 0x15, 0x7701);
958 static void rtl8402_hw_phy_config(struct rtl8169_private
*tp
,
959 struct phy_device
*phydev
)
961 /* Disable ALDPS before setting firmware */
962 phy_write(phydev
, 0x18, 0x0310);
965 r8169_apply_firmware(tp
);
968 phy_write(phydev
, 0x1f, 0x0004);
969 phy_write(phydev
, 0x10, 0x401f);
970 phy_write(phydev
, 0x19, 0x7030);
971 phy_write(phydev
, 0x1f, 0x0000);
974 static void rtl8106e_hw_phy_config(struct rtl8169_private
*tp
,
975 struct phy_device
*phydev
)
977 static const struct phy_reg phy_reg_init
[] = {
984 /* Disable ALDPS before ram code */
985 phy_write(phydev
, 0x18, 0x0310);
988 r8169_apply_firmware(tp
);
990 rtl_writephy_batch(phydev
, phy_reg_init
);
993 static void rtl8125_legacy_force_mode(struct phy_device
*phydev
)
995 phy_modify_paged(phydev
, 0xa5b, 0x12, BIT(15), 0);
998 static void rtl8125a_2_hw_phy_config(struct rtl8169_private
*tp
,
999 struct phy_device
*phydev
)
1003 phy_modify_paged(phydev
, 0xad4, 0x17, 0x0000, 0x0010);
1004 phy_modify_paged(phydev
, 0xad1, 0x13, 0x03ff, 0x03ff);
1005 phy_modify_paged(phydev
, 0xad3, 0x11, 0x003f, 0x0006);
1006 phy_modify_paged(phydev
, 0xac0, 0x14, 0x1100, 0x0000);
1007 phy_modify_paged(phydev
, 0xacc, 0x10, 0x0003, 0x0002);
1008 phy_modify_paged(phydev
, 0xad4, 0x10, 0x00e7, 0x0044);
1009 phy_modify_paged(phydev
, 0xac1, 0x12, 0x0080, 0x0000);
1010 phy_modify_paged(phydev
, 0xac8, 0x10, 0x0300, 0x0000);
1011 phy_modify_paged(phydev
, 0xac5, 0x17, 0x0007, 0x0002);
1012 phy_write_paged(phydev
, 0xad4, 0x16, 0x00a8);
1013 phy_write_paged(phydev
, 0xac5, 0x16, 0x01ff);
1014 phy_modify_paged(phydev
, 0xac8, 0x15, 0x00f0, 0x0030);
1016 phy_write(phydev
, 0x1f, 0x0b87);
1017 phy_write(phydev
, 0x16, 0x80a2);
1018 phy_write(phydev
, 0x17, 0x0153);
1019 phy_write(phydev
, 0x16, 0x809c);
1020 phy_write(phydev
, 0x17, 0x0153);
1021 phy_write(phydev
, 0x1f, 0x0000);
1023 phy_write(phydev
, 0x1f, 0x0a43);
1024 phy_write(phydev
, 0x13, 0x81B3);
1025 phy_write(phydev
, 0x14, 0x0043);
1026 phy_write(phydev
, 0x14, 0x00A7);
1027 phy_write(phydev
, 0x14, 0x00D6);
1028 phy_write(phydev
, 0x14, 0x00EC);
1029 phy_write(phydev
, 0x14, 0x00F6);
1030 phy_write(phydev
, 0x14, 0x00FB);
1031 phy_write(phydev
, 0x14, 0x00FD);
1032 phy_write(phydev
, 0x14, 0x00FF);
1033 phy_write(phydev
, 0x14, 0x00BB);
1034 phy_write(phydev
, 0x14, 0x0058);
1035 phy_write(phydev
, 0x14, 0x0029);
1036 phy_write(phydev
, 0x14, 0x0013);
1037 phy_write(phydev
, 0x14, 0x0009);
1038 phy_write(phydev
, 0x14, 0x0004);
1039 phy_write(phydev
, 0x14, 0x0002);
1040 for (i
= 0; i
< 25; i
++)
1041 phy_write(phydev
, 0x14, 0x0000);
1042 phy_write(phydev
, 0x1f, 0x0000);
1044 r8168g_phy_param(phydev
, 0x8257, 0xffff, 0x020F);
1045 r8168g_phy_param(phydev
, 0x80ea, 0xffff, 0x7843);
1047 r8169_apply_firmware(tp
);
1049 phy_modify_paged(phydev
, 0xd06, 0x14, 0x0000, 0x2000);
1051 r8168g_phy_param(phydev
, 0x81a2, 0x0000, 0x0100);
1053 phy_modify_paged(phydev
, 0xb54, 0x16, 0xff00, 0xdb00);
1054 phy_modify_paged(phydev
, 0xa45, 0x12, 0x0001, 0x0000);
1055 phy_modify_paged(phydev
, 0xa5d, 0x12, 0x0000, 0x0020);
1056 phy_modify_paged(phydev
, 0xad4, 0x17, 0x0010, 0x0000);
1057 phy_modify_paged(phydev
, 0xa86, 0x15, 0x0001, 0x0000);
1058 rtl8168g_enable_gphy_10m(phydev
);
1060 rtl8168g_disable_aldps(phydev
);
1061 rtl8125_config_eee_phy(phydev
);
1064 static void rtl8125b_hw_phy_config(struct rtl8169_private
*tp
,
1065 struct phy_device
*phydev
)
1067 r8169_apply_firmware(tp
);
1068 rtl8168g_enable_gphy_10m(phydev
);
1070 phy_modify_paged(phydev
, 0xac4, 0x13, 0x00f0, 0x0090);
1071 phy_modify_paged(phydev
, 0xad3, 0x10, 0x0003, 0x0001);
1073 phy_write(phydev
, 0x1f, 0x0b87);
1074 phy_write(phydev
, 0x16, 0x80f5);
1075 phy_write(phydev
, 0x17, 0x760e);
1076 phy_write(phydev
, 0x16, 0x8107);
1077 phy_write(phydev
, 0x17, 0x360e);
1078 phy_write(phydev
, 0x16, 0x8551);
1079 phy_modify(phydev
, 0x17, 0xff00, 0x0800);
1080 phy_write(phydev
, 0x1f, 0x0000);
1082 phy_modify_paged(phydev
, 0xbf0, 0x10, 0xe000, 0xa000);
1083 phy_modify_paged(phydev
, 0xbf4, 0x13, 0x0f00, 0x0300);
1085 r8168g_phy_param(phydev
, 0x8044, 0xffff, 0x2417);
1086 r8168g_phy_param(phydev
, 0x804a, 0xffff, 0x2417);
1087 r8168g_phy_param(phydev
, 0x8050, 0xffff, 0x2417);
1088 r8168g_phy_param(phydev
, 0x8056, 0xffff, 0x2417);
1089 r8168g_phy_param(phydev
, 0x805c, 0xffff, 0x2417);
1090 r8168g_phy_param(phydev
, 0x8062, 0xffff, 0x2417);
1091 r8168g_phy_param(phydev
, 0x8068, 0xffff, 0x2417);
1092 r8168g_phy_param(phydev
, 0x806e, 0xffff, 0x2417);
1093 r8168g_phy_param(phydev
, 0x8074, 0xffff, 0x2417);
1094 r8168g_phy_param(phydev
, 0x807a, 0xffff, 0x2417);
1096 phy_modify_paged(phydev
, 0xa4c, 0x15, 0x0000, 0x0040);
1097 phy_modify_paged(phydev
, 0xbf8, 0x12, 0xe000, 0xa000);
1099 rtl8125_legacy_force_mode(phydev
);
1100 rtl8168g_disable_aldps(phydev
);
1101 rtl8125_config_eee_phy(phydev
);
1104 static void rtl8125d_hw_phy_config(struct rtl8169_private
*tp
,
1105 struct phy_device
*phydev
)
1107 r8169_apply_firmware(tp
);
1108 rtl8168g_enable_gphy_10m(phydev
);
1109 rtl8125_legacy_force_mode(phydev
);
1110 rtl8168g_disable_aldps(phydev
);
1111 rtl8125_config_eee_phy(phydev
);
1114 static void rtl8126a_hw_phy_config(struct rtl8169_private
*tp
,
1115 struct phy_device
*phydev
)
1117 r8169_apply_firmware(tp
);
1118 rtl8168g_enable_gphy_10m(phydev
);
1119 rtl8125_legacy_force_mode(phydev
);
1120 rtl8168g_disable_aldps(phydev
);
1121 rtl8125_common_config_eee_phy(phydev
);
1124 void r8169_hw_phy_config(struct rtl8169_private
*tp
, struct phy_device
*phydev
,
1125 enum mac_version ver
)
1127 static const rtl_phy_cfg_fct phy_configs
[] = {
1129 [RTL_GIGA_MAC_VER_02
] = rtl8169s_hw_phy_config
,
1130 [RTL_GIGA_MAC_VER_03
] = rtl8169s_hw_phy_config
,
1131 [RTL_GIGA_MAC_VER_04
] = rtl8169sb_hw_phy_config
,
1132 [RTL_GIGA_MAC_VER_05
] = rtl8169scd_hw_phy_config
,
1133 [RTL_GIGA_MAC_VER_06
] = rtl8169sce_hw_phy_config
,
1134 /* PCI-E devices. */
1135 [RTL_GIGA_MAC_VER_07
] = rtl8102e_hw_phy_config
,
1136 [RTL_GIGA_MAC_VER_08
] = rtl8102e_hw_phy_config
,
1137 [RTL_GIGA_MAC_VER_09
] = rtl8102e_hw_phy_config
,
1138 [RTL_GIGA_MAC_VER_10
] = NULL
,
1139 [RTL_GIGA_MAC_VER_11
] = rtl8168bb_hw_phy_config
,
1140 [RTL_GIGA_MAC_VER_14
] = rtl8401_hw_phy_config
,
1141 [RTL_GIGA_MAC_VER_17
] = rtl8168bef_hw_phy_config
,
1142 [RTL_GIGA_MAC_VER_18
] = rtl8168cp_1_hw_phy_config
,
1143 [RTL_GIGA_MAC_VER_19
] = rtl8168c_1_hw_phy_config
,
1144 [RTL_GIGA_MAC_VER_20
] = rtl8168c_2_hw_phy_config
,
1145 [RTL_GIGA_MAC_VER_21
] = rtl8168c_3_hw_phy_config
,
1146 [RTL_GIGA_MAC_VER_22
] = rtl8168c_3_hw_phy_config
,
1147 [RTL_GIGA_MAC_VER_23
] = rtl8168cp_2_hw_phy_config
,
1148 [RTL_GIGA_MAC_VER_24
] = rtl8168cp_2_hw_phy_config
,
1149 [RTL_GIGA_MAC_VER_25
] = rtl8168d_1_hw_phy_config
,
1150 [RTL_GIGA_MAC_VER_26
] = rtl8168d_2_hw_phy_config
,
1151 [RTL_GIGA_MAC_VER_28
] = rtl8168d_4_hw_phy_config
,
1152 [RTL_GIGA_MAC_VER_29
] = rtl8105e_hw_phy_config
,
1153 [RTL_GIGA_MAC_VER_30
] = rtl8105e_hw_phy_config
,
1154 [RTL_GIGA_MAC_VER_31
] = NULL
,
1155 [RTL_GIGA_MAC_VER_32
] = rtl8168e_1_hw_phy_config
,
1156 [RTL_GIGA_MAC_VER_33
] = rtl8168e_1_hw_phy_config
,
1157 [RTL_GIGA_MAC_VER_34
] = rtl8168e_2_hw_phy_config
,
1158 [RTL_GIGA_MAC_VER_35
] = rtl8168f_1_hw_phy_config
,
1159 [RTL_GIGA_MAC_VER_36
] = rtl8168f_2_hw_phy_config
,
1160 [RTL_GIGA_MAC_VER_37
] = rtl8402_hw_phy_config
,
1161 [RTL_GIGA_MAC_VER_38
] = rtl8411_hw_phy_config
,
1162 [RTL_GIGA_MAC_VER_39
] = rtl8106e_hw_phy_config
,
1163 [RTL_GIGA_MAC_VER_40
] = rtl8168g_1_hw_phy_config
,
1164 [RTL_GIGA_MAC_VER_42
] = rtl8168g_2_hw_phy_config
,
1165 [RTL_GIGA_MAC_VER_43
] = rtl8168g_2_hw_phy_config
,
1166 [RTL_GIGA_MAC_VER_44
] = rtl8168g_2_hw_phy_config
,
1167 [RTL_GIGA_MAC_VER_46
] = rtl8168h_2_hw_phy_config
,
1168 [RTL_GIGA_MAC_VER_48
] = rtl8168h_2_hw_phy_config
,
1169 [RTL_GIGA_MAC_VER_51
] = rtl8168ep_2_hw_phy_config
,
1170 [RTL_GIGA_MAC_VER_52
] = rtl8117_hw_phy_config
,
1171 [RTL_GIGA_MAC_VER_53
] = rtl8117_hw_phy_config
,
1172 [RTL_GIGA_MAC_VER_61
] = rtl8125a_2_hw_phy_config
,
1173 [RTL_GIGA_MAC_VER_63
] = rtl8125b_hw_phy_config
,
1174 [RTL_GIGA_MAC_VER_64
] = rtl8125d_hw_phy_config
,
1175 [RTL_GIGA_MAC_VER_65
] = rtl8126a_hw_phy_config
,
1176 [RTL_GIGA_MAC_VER_66
] = rtl8126a_hw_phy_config
,
1179 if (phy_configs
[ver
])
1180 phy_configs
[ver
](tp
, phydev
);