Skip to content

Commit b845bac

Browse files
hkallweitdavem330
authored andcommitted
r8169: factor out redundant RTL8168d PHY config functionality to rtl8168d_1_common()
rtl8168d_2_hw_phy_config() shares quite some functionality with rtl8168d_1_hw_phy_config(), so let's factor out the common part to a new function rtl8168d_1_common(). In addition improve the code a little. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7d9b1b5 commit b845bac

File tree

1 file changed

+25
-46
lines changed

1 file changed

+25
-46
lines changed

drivers/net/ethernet/realtek/r8169_phy_config.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,6 @@ static const struct phy_reg rtl8168d_1_phy_reg_init_0[] = {
429429
{ 0x0d, 0xf880 }
430430
};
431431

432-
static const struct phy_reg rtl8168d_1_phy_reg_init_1[] = {
433-
{ 0x1f, 0x0002 },
434-
{ 0x05, 0x669a },
435-
{ 0x1f, 0x0005 },
436-
{ 0x05, 0x8330 },
437-
{ 0x06, 0x669a },
438-
{ 0x1f, 0x0002 }
439-
};
440-
441432
static void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp,
442433
struct phy_device *phydev,
443434
u16 val)
@@ -455,6 +446,29 @@ static void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp,
455446
r8169_apply_firmware(tp);
456447
}
457448

449+
static 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+
458472
static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp,
459473
struct phy_device *phydev)
460474
{
@@ -469,25 +483,7 @@ static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp,
469483
phy_modify(phydev, 0x0c, 0x5d00, 0xa200);
470484

471485
if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
472-
int val;
473-
474-
rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_1);
475-
476-
val = phy_read(phydev, 0x0d);
477-
478-
if ((val & 0x00ff) != 0x006c) {
479-
static const u32 set[] = {
480-
0x0065, 0x0066, 0x0067, 0x0068,
481-
0x0069, 0x006a, 0x006b, 0x006c
482-
};
483-
int i;
484-
485-
phy_write(phydev, 0x1f, 0x0002);
486-
487-
val &= 0xff00;
488-
for (i = 0; i < ARRAY_SIZE(set); i++)
489-
phy_write(phydev, 0x0d, val | set[i]);
490-
}
486+
rtl8168d_1_common(phydev);
491487
} else {
492488
phy_write_paged(phydev, 0x0002, 0x05, 0x6662);
493489
r8168d_phy_param(phydev, 0x8330, 0xffff, 0x6662);
@@ -513,24 +509,7 @@ static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp,
513509
rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
514510

515511
if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
516-
int val;
517-
518-
rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_1);
519-
520-
val = phy_read(phydev, 0x0d);
521-
if ((val & 0x00ff) != 0x006c) {
522-
static const u32 set[] = {
523-
0x0065, 0x0066, 0x0067, 0x0068,
524-
0x0069, 0x006a, 0x006b, 0x006c
525-
};
526-
int i;
527-
528-
phy_write(phydev, 0x1f, 0x0002);
529-
530-
val &= 0xff00;
531-
for (i = 0; i < ARRAY_SIZE(set); i++)
532-
phy_write(phydev, 0x0d, val | set[i]);
533-
}
512+
rtl8168d_1_common(phydev);
534513
} else {
535514
phy_write_paged(phydev, 0x0002, 0x05, 0x2642);
536515
r8168d_phy_param(phydev, 0x8330, 0xffff, 0x2642);

0 commit comments

Comments
 (0)