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 17 typedef void (*rtl_phy_cfg_fct)(struct rtl8169_private *tp, 18 struct phy_device *phydev); 19 20 static 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 31 static 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 42 static 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 53 struct phy_reg { 54 u16 reg; 55 u16 val; 56 }; 57 58 static 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 73 static 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 79 static void rtl8168g_config_eee_phy(struct phy_device *phydev) 80 { 81 phy_modify_paged(phydev, 0x0a43, 0x11, 0, BIT(4)); 82 } 83 84 static 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 92 static 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 100 static 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 108 static 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 176 static 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 182 static 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 228 static 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 282 static 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 291 static 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 297 static 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 304 static 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 312 static 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 341 static 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 369 static 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 391 static 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 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 441 static void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp, 442 struct phy_device *phydev, 443 u16 val) 444 { 445 u16 reg_val; 446 447 phy_write(phydev, 0x1f, 0x0005); 448 phy_write(phydev, 0x05, 0x001b); 449 reg_val = phy_read(phydev, 0x06); 450 phy_write(phydev, 0x1f, 0x0000); 451 452 if (reg_val != val) 453 phydev_warn(phydev, "chipset not ready for firmware\n"); 454 else 455 r8169_apply_firmware(tp); 456 } 457 458 static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp, 459 struct phy_device *phydev) 460 { 461 rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0); 462 463 /* 464 * Rx Error Issue 465 * Fine Tune Switching regulator parameter 466 */ 467 phy_write(phydev, 0x1f, 0x0002); 468 phy_modify(phydev, 0x0b, 0x00ef, 0x0010); 469 phy_modify(phydev, 0x0c, 0x5d00, 0xa200); 470 471 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 } 491 } else { 492 phy_write_paged(phydev, 0x0002, 0x05, 0x6662); 493 r8168d_phy_param(phydev, 0x8330, 0xffff, 0x6662); 494 } 495 496 /* RSET couple improve */ 497 phy_write(phydev, 0x1f, 0x0002); 498 phy_set_bits(phydev, 0x0d, 0x0300); 499 phy_set_bits(phydev, 0x0f, 0x0010); 500 501 /* Fine tune PLL performance */ 502 phy_write(phydev, 0x1f, 0x0002); 503 phy_modify(phydev, 0x02, 0x0600, 0x0100); 504 phy_clear_bits(phydev, 0x03, 0xe000); 505 phy_write(phydev, 0x1f, 0x0000); 506 507 rtl8168d_apply_firmware_cond(tp, phydev, 0xbf00); 508 } 509 510 static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp, 511 struct phy_device *phydev) 512 { 513 rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0); 514 515 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 } 534 } else { 535 phy_write_paged(phydev, 0x0002, 0x05, 0x2642); 536 r8168d_phy_param(phydev, 0x8330, 0xffff, 0x2642); 537 } 538 539 /* Fine tune PLL performance */ 540 phy_write(phydev, 0x1f, 0x0002); 541 phy_modify(phydev, 0x02, 0x0600, 0x0100); 542 phy_clear_bits(phydev, 0x03, 0xe000); 543 phy_write(phydev, 0x1f, 0x0000); 544 545 /* Switching regulator Slew rate */ 546 phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0017); 547 548 rtl8168d_apply_firmware_cond(tp, phydev, 0xb300); 549 } 550 551 static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp, 552 struct phy_device *phydev) 553 { 554 phy_write_paged(phydev, 0x0001, 0x17, 0x0cc0); 555 r8168d_modify_extpage(phydev, 0x002d, 0x18, 0xffff, 0x0040); 556 phy_set_bits(phydev, 0x0d, BIT(5)); 557 } 558 559 static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp, 560 struct phy_device *phydev) 561 { 562 static const struct phy_reg phy_reg_init[] = { 563 /* Channel estimation fine tune */ 564 { 0x1f, 0x0001 }, 565 { 0x0b, 0x6c20 }, 566 { 0x07, 0x2872 }, 567 { 0x1c, 0xefff }, 568 { 0x1f, 0x0003 }, 569 { 0x14, 0x6420 }, 570 { 0x1f, 0x0000 }, 571 }; 572 573 r8169_apply_firmware(tp); 574 575 /* Enable Delay cap */ 576 r8168d_phy_param(phydev, 0x8b80, 0xffff, 0xc896); 577 578 rtl_writephy_batch(phydev, phy_reg_init); 579 580 /* Update PFM & 10M TX idle timer */ 581 r8168d_modify_extpage(phydev, 0x002f, 0x15, 0xffff, 0x1919); 582 583 r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006); 584 585 /* DCO enable for 10M IDLE Power */ 586 r8168d_modify_extpage(phydev, 0x0023, 0x17, 0x0000, 0x0006); 587 588 /* For impedance matching */ 589 phy_modify_paged(phydev, 0x0002, 0x08, 0x7f00, 0x8000); 590 591 /* PHY auto speed down */ 592 r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0050); 593 phy_set_bits(phydev, 0x14, BIT(15)); 594 595 r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001); 596 r8168d_phy_param(phydev, 0x8b85, 0x2000, 0x0000); 597 598 r8168d_modify_extpage(phydev, 0x0020, 0x15, 0x1100, 0x0000); 599 phy_write_paged(phydev, 0x0006, 0x00, 0x5a00); 600 601 phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0000); 602 } 603 604 static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp, 605 struct phy_device *phydev) 606 { 607 r8169_apply_firmware(tp); 608 609 /* Enable Delay cap */ 610 r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006); 611 612 /* Channel estimation fine tune */ 613 phy_write_paged(phydev, 0x0003, 0x09, 0xa20f); 614 615 /* Green Setting */ 616 r8168d_phy_param(phydev, 0x8b5b, 0xffff, 0x9222); 617 r8168d_phy_param(phydev, 0x8b6d, 0xffff, 0x8000); 618 r8168d_phy_param(phydev, 0x8b76, 0xffff, 0x8000); 619 620 /* For 4-corner performance improve */ 621 phy_write(phydev, 0x1f, 0x0005); 622 phy_write(phydev, 0x05, 0x8b80); 623 phy_set_bits(phydev, 0x17, 0x0006); 624 phy_write(phydev, 0x1f, 0x0000); 625 626 /* PHY auto speed down */ 627 r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010); 628 phy_set_bits(phydev, 0x14, BIT(15)); 629 630 /* improve 10M EEE waveform */ 631 r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001); 632 633 /* Improve 2-pair detection performance */ 634 r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000); 635 636 rtl8168f_config_eee_phy(phydev); 637 638 /* Green feature */ 639 phy_write(phydev, 0x1f, 0x0003); 640 phy_set_bits(phydev, 0x19, BIT(0)); 641 phy_set_bits(phydev, 0x10, BIT(10)); 642 phy_write(phydev, 0x1f, 0x0000); 643 phy_modify_paged(phydev, 0x0005, 0x01, 0, BIT(8)); 644 } 645 646 static void rtl8168f_hw_phy_config(struct rtl8169_private *tp, 647 struct phy_device *phydev) 648 { 649 /* For 4-corner performance improve */ 650 r8168d_phy_param(phydev, 0x8b80, 0x0000, 0x0006); 651 652 /* PHY auto speed down */ 653 r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010); 654 phy_set_bits(phydev, 0x14, BIT(15)); 655 656 /* Improve 10M EEE waveform */ 657 r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001); 658 659 rtl8168f_config_eee_phy(phydev); 660 } 661 662 static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp, 663 struct phy_device *phydev) 664 { 665 r8169_apply_firmware(tp); 666 667 /* Channel estimation fine tune */ 668 phy_write_paged(phydev, 0x0003, 0x09, 0xa20f); 669 670 /* Modify green table for giga & fnet */ 671 r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000); 672 r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000); 673 r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000); 674 r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000); 675 r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000); 676 r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00fb); 677 678 /* Modify green table for 10M */ 679 r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00); 680 681 /* Disable hiimpedance detection (RTCT) */ 682 phy_write_paged(phydev, 0x0003, 0x01, 0x328a); 683 684 rtl8168f_hw_phy_config(tp, phydev); 685 686 /* Improve 2-pair detection performance */ 687 r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000); 688 } 689 690 static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp, 691 struct phy_device *phydev) 692 { 693 r8169_apply_firmware(tp); 694 695 rtl8168f_hw_phy_config(tp, phydev); 696 } 697 698 static void rtl8411_hw_phy_config(struct rtl8169_private *tp, 699 struct phy_device *phydev) 700 { 701 r8169_apply_firmware(tp); 702 703 rtl8168f_hw_phy_config(tp, phydev); 704 705 /* Improve 2-pair detection performance */ 706 r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000); 707 708 /* Channel estimation fine tune */ 709 phy_write_paged(phydev, 0x0003, 0x09, 0xa20f); 710 711 /* Modify green table for giga & fnet */ 712 r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000); 713 r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000); 714 r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000); 715 r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000); 716 r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000); 717 r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00aa); 718 719 /* Modify green table for 10M */ 720 r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00); 721 722 /* Disable hiimpedance detection (RTCT) */ 723 phy_write_paged(phydev, 0x0003, 0x01, 0x328a); 724 725 /* Modify green table for giga */ 726 r8168d_phy_param(phydev, 0x8b54, 0x0800, 0x0000); 727 r8168d_phy_param(phydev, 0x8b5d, 0x0800, 0x0000); 728 r8168d_phy_param(phydev, 0x8a7c, 0x0100, 0x0000); 729 r8168d_phy_param(phydev, 0x8a7f, 0x0000, 0x0100); 730 r8168d_phy_param(phydev, 0x8a82, 0x0100, 0x0000); 731 r8168d_phy_param(phydev, 0x8a85, 0x0100, 0x0000); 732 r8168d_phy_param(phydev, 0x8a88, 0x0100, 0x0000); 733 734 /* uc same-seed solution */ 735 r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x8000); 736 737 /* Green feature */ 738 phy_write(phydev, 0x1f, 0x0003); 739 phy_clear_bits(phydev, 0x19, BIT(0)); 740 phy_clear_bits(phydev, 0x10, BIT(10)); 741 phy_write(phydev, 0x1f, 0x0000); 742 } 743 744 static void rtl8168g_disable_aldps(struct phy_device *phydev) 745 { 746 phy_modify_paged(phydev, 0x0a43, 0x10, BIT(2), 0); 747 } 748 749 static void rtl8168g_enable_gphy_10m(struct phy_device *phydev) 750 { 751 phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(11)); 752 } 753 754 static void rtl8168g_phy_adjust_10m_aldps(struct phy_device *phydev) 755 { 756 phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0); 757 phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6)); 758 r8168g_phy_param(phydev, 0x8084, 0x6000, 0x0000); 759 phy_modify_paged(phydev, 0x0a43, 0x10, 0x0000, 0x1003); 760 } 761 762 static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp, 763 struct phy_device *phydev) 764 { 765 int ret; 766 767 r8169_apply_firmware(tp); 768 769 ret = phy_read_paged(phydev, 0x0a46, 0x10); 770 if (ret & BIT(8)) 771 phy_modify_paged(phydev, 0x0bcc, 0x12, BIT(15), 0); 772 else 773 phy_modify_paged(phydev, 0x0bcc, 0x12, 0, BIT(15)); 774 775 ret = phy_read_paged(phydev, 0x0a46, 0x13); 776 if (ret & BIT(8)) 777 phy_modify_paged(phydev, 0x0c41, 0x15, 0, BIT(1)); 778 else 779 phy_modify_paged(phydev, 0x0c41, 0x15, BIT(1), 0); 780 781 /* Enable PHY auto speed down */ 782 phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2)); 783 784 rtl8168g_phy_adjust_10m_aldps(phydev); 785 786 /* EEE auto-fallback function */ 787 phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2)); 788 789 /* Enable UC LPF tune function */ 790 r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000); 791 792 phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14)); 793 794 /* Improve SWR Efficiency */ 795 phy_write(phydev, 0x1f, 0x0bcd); 796 phy_write(phydev, 0x14, 0x5065); 797 phy_write(phydev, 0x14, 0xd065); 798 phy_write(phydev, 0x1f, 0x0bc8); 799 phy_write(phydev, 0x11, 0x5655); 800 phy_write(phydev, 0x1f, 0x0bcd); 801 phy_write(phydev, 0x14, 0x1065); 802 phy_write(phydev, 0x14, 0x9065); 803 phy_write(phydev, 0x14, 0x1065); 804 phy_write(phydev, 0x1f, 0x0000); 805 806 rtl8168g_disable_aldps(phydev); 807 rtl8168g_config_eee_phy(phydev); 808 } 809 810 static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp, 811 struct phy_device *phydev) 812 { 813 r8169_apply_firmware(tp); 814 rtl8168g_config_eee_phy(phydev); 815 } 816 817 static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp, 818 struct phy_device *phydev) 819 { 820 u16 dout_tapbin; 821 u32 data; 822 823 r8169_apply_firmware(tp); 824 825 /* CHN EST parameters adjust - giga master */ 826 r8168g_phy_param(phydev, 0x809b, 0xf800, 0x8000); 827 r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x8000); 828 r8168g_phy_param(phydev, 0x80a4, 0xff00, 0x8500); 829 r8168g_phy_param(phydev, 0x809c, 0xff00, 0xbd00); 830 831 /* CHN EST parameters adjust - giga slave */ 832 r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x7000); 833 r8168g_phy_param(phydev, 0x80b4, 0xff00, 0x5000); 834 r8168g_phy_param(phydev, 0x80ac, 0xff00, 0x4000); 835 836 /* CHN EST parameters adjust - fnet */ 837 r8168g_phy_param(phydev, 0x808e, 0xff00, 0x1200); 838 r8168g_phy_param(phydev, 0x8090, 0xff00, 0xe500); 839 r8168g_phy_param(phydev, 0x8092, 0xff00, 0x9f00); 840 841 /* enable R-tune & PGA-retune function */ 842 dout_tapbin = 0; 843 data = phy_read_paged(phydev, 0x0a46, 0x13); 844 data &= 3; 845 data <<= 2; 846 dout_tapbin |= data; 847 data = phy_read_paged(phydev, 0x0a46, 0x12); 848 data &= 0xc000; 849 data >>= 14; 850 dout_tapbin |= data; 851 dout_tapbin = ~(dout_tapbin ^ 0x08); 852 dout_tapbin <<= 12; 853 dout_tapbin &= 0xf000; 854 855 r8168g_phy_param(phydev, 0x827a, 0xf000, dout_tapbin); 856 r8168g_phy_param(phydev, 0x827b, 0xf000, dout_tapbin); 857 r8168g_phy_param(phydev, 0x827c, 0xf000, dout_tapbin); 858 r8168g_phy_param(phydev, 0x827d, 0xf000, dout_tapbin); 859 r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800); 860 phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002); 861 862 rtl8168g_enable_gphy_10m(phydev); 863 864 /* SAR ADC performance */ 865 phy_modify_paged(phydev, 0x0bca, 0x17, BIT(12) | BIT(13), BIT(14)); 866 867 r8168g_phy_param(phydev, 0x803f, 0x3000, 0x0000); 868 r8168g_phy_param(phydev, 0x8047, 0x3000, 0x0000); 869 r8168g_phy_param(phydev, 0x804f, 0x3000, 0x0000); 870 r8168g_phy_param(phydev, 0x8057, 0x3000, 0x0000); 871 r8168g_phy_param(phydev, 0x805f, 0x3000, 0x0000); 872 r8168g_phy_param(phydev, 0x8067, 0x3000, 0x0000); 873 r8168g_phy_param(phydev, 0x806f, 0x3000, 0x0000); 874 875 /* disable phy pfm mode */ 876 phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0); 877 878 rtl8168g_disable_aldps(phydev); 879 rtl8168h_config_eee_phy(phydev); 880 } 881 882 static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp, 883 struct phy_device *phydev) 884 { 885 u16 ioffset, rlen; 886 u32 data; 887 888 r8169_apply_firmware(tp); 889 890 /* CHIN EST parameter update */ 891 r8168g_phy_param(phydev, 0x808a, 0x003f, 0x000a); 892 893 /* enable R-tune & PGA-retune function */ 894 r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800); 895 phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002); 896 897 rtl8168g_enable_gphy_10m(phydev); 898 899 ioffset = rtl8168h_2_get_adc_bias_ioffset(tp); 900 if (ioffset != 0xffff) 901 phy_write_paged(phydev, 0x0bcf, 0x16, ioffset); 902 903 /* Modify rlen (TX LPF corner frequency) level */ 904 data = phy_read_paged(phydev, 0x0bcd, 0x16); 905 data &= 0x000f; 906 rlen = 0; 907 if (data > 3) 908 rlen = data - 3; 909 data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12); 910 phy_write_paged(phydev, 0x0bcd, 0x17, data); 911 912 /* disable phy pfm mode */ 913 phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0); 914 915 rtl8168g_disable_aldps(phydev); 916 rtl8168g_config_eee_phy(phydev); 917 } 918 919 static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp, 920 struct phy_device *phydev) 921 { 922 /* Enable PHY auto speed down */ 923 phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2)); 924 925 rtl8168g_phy_adjust_10m_aldps(phydev); 926 927 /* Enable EEE auto-fallback function */ 928 phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2)); 929 930 /* Enable UC LPF tune function */ 931 r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000); 932 933 /* set rg_sel_sdm_rate */ 934 phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14)); 935 936 rtl8168g_disable_aldps(phydev); 937 rtl8168g_config_eee_phy(phydev); 938 } 939 940 static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp, 941 struct phy_device *phydev) 942 { 943 rtl8168g_phy_adjust_10m_aldps(phydev); 944 945 /* Enable UC LPF tune function */ 946 r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000); 947 948 /* Set rg_sel_sdm_rate */ 949 phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14)); 950 951 /* Channel estimation parameters */ 952 r8168g_phy_param(phydev, 0x80f3, 0xff00, 0x8b00); 953 r8168g_phy_param(phydev, 0x80f0, 0xff00, 0x3a00); 954 r8168g_phy_param(phydev, 0x80ef, 0xff00, 0x0500); 955 r8168g_phy_param(phydev, 0x80f6, 0xff00, 0x6e00); 956 r8168g_phy_param(phydev, 0x80ec, 0xff00, 0x6800); 957 r8168g_phy_param(phydev, 0x80ed, 0xff00, 0x7c00); 958 r8168g_phy_param(phydev, 0x80f2, 0xff00, 0xf400); 959 r8168g_phy_param(phydev, 0x80f4, 0xff00, 0x8500); 960 r8168g_phy_param(phydev, 0x8110, 0xff00, 0xa800); 961 r8168g_phy_param(phydev, 0x810f, 0xff00, 0x1d00); 962 r8168g_phy_param(phydev, 0x8111, 0xff00, 0xf500); 963 r8168g_phy_param(phydev, 0x8113, 0xff00, 0x6100); 964 r8168g_phy_param(phydev, 0x8115, 0xff00, 0x9200); 965 r8168g_phy_param(phydev, 0x810e, 0xff00, 0x0400); 966 r8168g_phy_param(phydev, 0x810c, 0xff00, 0x7c00); 967 r8168g_phy_param(phydev, 0x810b, 0xff00, 0x5a00); 968 r8168g_phy_param(phydev, 0x80d1, 0xff00, 0xff00); 969 r8168g_phy_param(phydev, 0x80cd, 0xff00, 0x9e00); 970 r8168g_phy_param(phydev, 0x80d3, 0xff00, 0x0e00); 971 r8168g_phy_param(phydev, 0x80d5, 0xff00, 0xca00); 972 r8168g_phy_param(phydev, 0x80d7, 0xff00, 0x8400); 973 974 /* Force PWM-mode */ 975 phy_write(phydev, 0x1f, 0x0bcd); 976 phy_write(phydev, 0x14, 0x5065); 977 phy_write(phydev, 0x14, 0xd065); 978 phy_write(phydev, 0x1f, 0x0bc8); 979 phy_write(phydev, 0x12, 0x00ed); 980 phy_write(phydev, 0x1f, 0x0bcd); 981 phy_write(phydev, 0x14, 0x1065); 982 phy_write(phydev, 0x14, 0x9065); 983 phy_write(phydev, 0x14, 0x1065); 984 phy_write(phydev, 0x1f, 0x0000); 985 986 rtl8168g_disable_aldps(phydev); 987 rtl8168g_config_eee_phy(phydev); 988 } 989 990 static void rtl8117_hw_phy_config(struct rtl8169_private *tp, 991 struct phy_device *phydev) 992 { 993 /* CHN EST parameters adjust - fnet */ 994 r8168g_phy_param(phydev, 0x808e, 0xff00, 0x4800); 995 r8168g_phy_param(phydev, 0x8090, 0xff00, 0xcc00); 996 r8168g_phy_param(phydev, 0x8092, 0xff00, 0xb000); 997 998 r8168g_phy_param(phydev, 0x8088, 0xff00, 0x6000); 999 r8168g_phy_param(phydev, 0x808b, 0x3f00, 0x0b00); 1000 r8168g_phy_param(phydev, 0x808d, 0x1f00, 0x0600); 1001 r8168g_phy_param(phydev, 0x808c, 0xff00, 0xb000); 1002 r8168g_phy_param(phydev, 0x80a0, 0xff00, 0x2800); 1003 r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x5000); 1004 r8168g_phy_param(phydev, 0x809b, 0xf800, 0xb000); 1005 r8168g_phy_param(phydev, 0x809a, 0xff00, 0x4b00); 1006 r8168g_phy_param(phydev, 0x809d, 0x3f00, 0x0800); 1007 r8168g_phy_param(phydev, 0x80a1, 0xff00, 0x7000); 1008 r8168g_phy_param(phydev, 0x809f, 0x1f00, 0x0300); 1009 r8168g_phy_param(phydev, 0x809e, 0xff00, 0x8800); 1010 r8168g_phy_param(phydev, 0x80b2, 0xff00, 0x2200); 1011 r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x9800); 1012 r8168g_phy_param(phydev, 0x80af, 0x3f00, 0x0800); 1013 r8168g_phy_param(phydev, 0x80b3, 0xff00, 0x6f00); 1014 r8168g_phy_param(phydev, 0x80b1, 0x1f00, 0x0300); 1015 r8168g_phy_param(phydev, 0x80b0, 0xff00, 0x9300); 1016 1017 r8168g_phy_param(phydev, 0x8011, 0x0000, 0x0800); 1018 1019 rtl8168g_enable_gphy_10m(phydev); 1020 1021 r8168g_phy_param(phydev, 0x8016, 0x0000, 0x0400); 1022 1023 rtl8168g_disable_aldps(phydev); 1024 rtl8168h_config_eee_phy(phydev); 1025 } 1026 1027 static void rtl8102e_hw_phy_config(struct rtl8169_private *tp, 1028 struct phy_device *phydev) 1029 { 1030 static const struct phy_reg phy_reg_init[] = { 1031 { 0x1f, 0x0003 }, 1032 { 0x08, 0x441d }, 1033 { 0x01, 0x9100 }, 1034 { 0x1f, 0x0000 } 1035 }; 1036 1037 phy_set_bits(phydev, 0x11, BIT(12)); 1038 phy_set_bits(phydev, 0x19, BIT(13)); 1039 phy_set_bits(phydev, 0x10, BIT(15)); 1040 1041 rtl_writephy_batch(phydev, phy_reg_init); 1042 } 1043 1044 static void rtl8401_hw_phy_config(struct rtl8169_private *tp, 1045 struct phy_device *phydev) 1046 { 1047 phy_set_bits(phydev, 0x11, BIT(12)); 1048 phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0003); 1049 } 1050 1051 static void rtl8105e_hw_phy_config(struct rtl8169_private *tp, 1052 struct phy_device *phydev) 1053 { 1054 /* Disable ALDPS before ram code */ 1055 phy_write(phydev, 0x18, 0x0310); 1056 msleep(100); 1057 1058 r8169_apply_firmware(tp); 1059 1060 phy_write_paged(phydev, 0x0005, 0x1a, 0x0000); 1061 phy_write_paged(phydev, 0x0004, 0x1c, 0x0000); 1062 phy_write_paged(phydev, 0x0001, 0x15, 0x7701); 1063 } 1064 1065 static void rtl8402_hw_phy_config(struct rtl8169_private *tp, 1066 struct phy_device *phydev) 1067 { 1068 /* Disable ALDPS before setting firmware */ 1069 phy_write(phydev, 0x18, 0x0310); 1070 msleep(20); 1071 1072 r8169_apply_firmware(tp); 1073 1074 /* EEE setting */ 1075 phy_write(phydev, 0x1f, 0x0004); 1076 phy_write(phydev, 0x10, 0x401f); 1077 phy_write(phydev, 0x19, 0x7030); 1078 phy_write(phydev, 0x1f, 0x0000); 1079 } 1080 1081 static void rtl8106e_hw_phy_config(struct rtl8169_private *tp, 1082 struct phy_device *phydev) 1083 { 1084 static const struct phy_reg phy_reg_init[] = { 1085 { 0x1f, 0x0004 }, 1086 { 0x10, 0xc07f }, 1087 { 0x19, 0x7030 }, 1088 { 0x1f, 0x0000 } 1089 }; 1090 1091 /* Disable ALDPS before ram code */ 1092 phy_write(phydev, 0x18, 0x0310); 1093 msleep(100); 1094 1095 r8169_apply_firmware(tp); 1096 1097 rtl_writephy_batch(phydev, phy_reg_init); 1098 } 1099 1100 static void rtl8125_legacy_force_mode(struct phy_device *phydev) 1101 { 1102 phy_modify_paged(phydev, 0xa5b, 0x12, BIT(15), 0); 1103 } 1104 1105 static void rtl8125a_1_hw_phy_config(struct rtl8169_private *tp, 1106 struct phy_device *phydev) 1107 { 1108 phy_modify_paged(phydev, 0xad4, 0x10, 0x03ff, 0x0084); 1109 phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010); 1110 phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x0006); 1111 phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006); 1112 phy_modify_paged(phydev, 0xac0, 0x14, 0x0000, 0x1100); 1113 phy_modify_paged(phydev, 0xac8, 0x15, 0xf000, 0x7000); 1114 phy_modify_paged(phydev, 0xad1, 0x14, 0x0000, 0x0400); 1115 phy_modify_paged(phydev, 0xad1, 0x15, 0x0000, 0x03ff); 1116 phy_modify_paged(phydev, 0xad1, 0x16, 0x0000, 0x03ff); 1117 1118 r8168g_phy_param(phydev, 0x80ea, 0xff00, 0xc400); 1119 r8168g_phy_param(phydev, 0x80eb, 0x0700, 0x0300); 1120 r8168g_phy_param(phydev, 0x80f8, 0xff00, 0x1c00); 1121 r8168g_phy_param(phydev, 0x80f1, 0xff00, 0x3000); 1122 r8168g_phy_param(phydev, 0x80fe, 0xff00, 0xa500); 1123 r8168g_phy_param(phydev, 0x8102, 0xff00, 0x5000); 1124 r8168g_phy_param(phydev, 0x8105, 0xff00, 0x3300); 1125 r8168g_phy_param(phydev, 0x8100, 0xff00, 0x7000); 1126 r8168g_phy_param(phydev, 0x8104, 0xff00, 0xf000); 1127 r8168g_phy_param(phydev, 0x8106, 0xff00, 0x6500); 1128 r8168g_phy_param(phydev, 0x80dc, 0xff00, 0xed00); 1129 r8168g_phy_param(phydev, 0x80df, 0x0000, 0x0100); 1130 r8168g_phy_param(phydev, 0x80e1, 0x0100, 0x0000); 1131 1132 phy_modify_paged(phydev, 0xbf0, 0x13, 0x003f, 0x0038); 1133 r8168g_phy_param(phydev, 0x819f, 0xffff, 0xd0b6); 1134 1135 phy_write_paged(phydev, 0xbc3, 0x12, 0x5555); 1136 phy_modify_paged(phydev, 0xbf0, 0x15, 0x0e00, 0x0a00); 1137 phy_modify_paged(phydev, 0xa5c, 0x10, 0x0400, 0x0000); 1138 rtl8168g_enable_gphy_10m(phydev); 1139 1140 rtl8125a_config_eee_phy(phydev); 1141 } 1142 1143 static void rtl8125a_2_hw_phy_config(struct rtl8169_private *tp, 1144 struct phy_device *phydev) 1145 { 1146 int i; 1147 1148 phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010); 1149 phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x03ff); 1150 phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006); 1151 phy_modify_paged(phydev, 0xac0, 0x14, 0x1100, 0x0000); 1152 phy_modify_paged(phydev, 0xacc, 0x10, 0x0003, 0x0002); 1153 phy_modify_paged(phydev, 0xad4, 0x10, 0x00e7, 0x0044); 1154 phy_modify_paged(phydev, 0xac1, 0x12, 0x0080, 0x0000); 1155 phy_modify_paged(phydev, 0xac8, 0x10, 0x0300, 0x0000); 1156 phy_modify_paged(phydev, 0xac5, 0x17, 0x0007, 0x0002); 1157 phy_write_paged(phydev, 0xad4, 0x16, 0x00a8); 1158 phy_write_paged(phydev, 0xac5, 0x16, 0x01ff); 1159 phy_modify_paged(phydev, 0xac8, 0x15, 0x00f0, 0x0030); 1160 1161 phy_write(phydev, 0x1f, 0x0b87); 1162 phy_write(phydev, 0x16, 0x80a2); 1163 phy_write(phydev, 0x17, 0x0153); 1164 phy_write(phydev, 0x16, 0x809c); 1165 phy_write(phydev, 0x17, 0x0153); 1166 phy_write(phydev, 0x1f, 0x0000); 1167 1168 phy_write(phydev, 0x1f, 0x0a43); 1169 phy_write(phydev, 0x13, 0x81B3); 1170 phy_write(phydev, 0x14, 0x0043); 1171 phy_write(phydev, 0x14, 0x00A7); 1172 phy_write(phydev, 0x14, 0x00D6); 1173 phy_write(phydev, 0x14, 0x00EC); 1174 phy_write(phydev, 0x14, 0x00F6); 1175 phy_write(phydev, 0x14, 0x00FB); 1176 phy_write(phydev, 0x14, 0x00FD); 1177 phy_write(phydev, 0x14, 0x00FF); 1178 phy_write(phydev, 0x14, 0x00BB); 1179 phy_write(phydev, 0x14, 0x0058); 1180 phy_write(phydev, 0x14, 0x0029); 1181 phy_write(phydev, 0x14, 0x0013); 1182 phy_write(phydev, 0x14, 0x0009); 1183 phy_write(phydev, 0x14, 0x0004); 1184 phy_write(phydev, 0x14, 0x0002); 1185 for (i = 0; i < 25; i++) 1186 phy_write(phydev, 0x14, 0x0000); 1187 phy_write(phydev, 0x1f, 0x0000); 1188 1189 r8168g_phy_param(phydev, 0x8257, 0xffff, 0x020F); 1190 r8168g_phy_param(phydev, 0x80ea, 0xffff, 0x7843); 1191 1192 r8169_apply_firmware(tp); 1193 1194 phy_modify_paged(phydev, 0xd06, 0x14, 0x0000, 0x2000); 1195 1196 r8168g_phy_param(phydev, 0x81a2, 0x0000, 0x0100); 1197 1198 phy_modify_paged(phydev, 0xb54, 0x16, 0xff00, 0xdb00); 1199 phy_modify_paged(phydev, 0xa45, 0x12, 0x0001, 0x0000); 1200 phy_modify_paged(phydev, 0xa5d, 0x12, 0x0000, 0x0020); 1201 phy_modify_paged(phydev, 0xad4, 0x17, 0x0010, 0x0000); 1202 phy_modify_paged(phydev, 0xa86, 0x15, 0x0001, 0x0000); 1203 rtl8168g_enable_gphy_10m(phydev); 1204 1205 rtl8125a_config_eee_phy(phydev); 1206 } 1207 1208 static void rtl8125b_hw_phy_config(struct rtl8169_private *tp, 1209 struct phy_device *phydev) 1210 { 1211 r8169_apply_firmware(tp); 1212 1213 phy_modify_paged(phydev, 0xa44, 0x11, 0x0000, 0x0800); 1214 phy_modify_paged(phydev, 0xac4, 0x13, 0x00f0, 0x0090); 1215 phy_modify_paged(phydev, 0xad3, 0x10, 0x0003, 0x0001); 1216 1217 phy_write(phydev, 0x1f, 0x0b87); 1218 phy_write(phydev, 0x16, 0x80f5); 1219 phy_write(phydev, 0x17, 0x760e); 1220 phy_write(phydev, 0x16, 0x8107); 1221 phy_write(phydev, 0x17, 0x360e); 1222 phy_write(phydev, 0x16, 0x8551); 1223 phy_modify(phydev, 0x17, 0xff00, 0x0800); 1224 phy_write(phydev, 0x1f, 0x0000); 1225 1226 phy_modify_paged(phydev, 0xbf0, 0x10, 0xe000, 0xa000); 1227 phy_modify_paged(phydev, 0xbf4, 0x13, 0x0f00, 0x0300); 1228 1229 r8168g_phy_param(phydev, 0x8044, 0xffff, 0x2417); 1230 r8168g_phy_param(phydev, 0x804a, 0xffff, 0x2417); 1231 r8168g_phy_param(phydev, 0x8050, 0xffff, 0x2417); 1232 r8168g_phy_param(phydev, 0x8056, 0xffff, 0x2417); 1233 r8168g_phy_param(phydev, 0x805c, 0xffff, 0x2417); 1234 r8168g_phy_param(phydev, 0x8062, 0xffff, 0x2417); 1235 r8168g_phy_param(phydev, 0x8068, 0xffff, 0x2417); 1236 r8168g_phy_param(phydev, 0x806e, 0xffff, 0x2417); 1237 r8168g_phy_param(phydev, 0x8074, 0xffff, 0x2417); 1238 r8168g_phy_param(phydev, 0x807a, 0xffff, 0x2417); 1239 1240 phy_modify_paged(phydev, 0xa4c, 0x15, 0x0000, 0x0040); 1241 phy_modify_paged(phydev, 0xbf8, 0x12, 0xe000, 0xa000); 1242 1243 rtl8125_legacy_force_mode(phydev); 1244 rtl8125b_config_eee_phy(phydev); 1245 } 1246 1247 void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev, 1248 enum mac_version ver) 1249 { 1250 static const rtl_phy_cfg_fct phy_configs[] = { 1251 /* PCI devices. */ 1252 [RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config, 1253 [RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config, 1254 [RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config, 1255 [RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config, 1256 [RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config, 1257 /* PCI-E devices. */ 1258 [RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config, 1259 [RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config, 1260 [RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config, 1261 [RTL_GIGA_MAC_VER_10] = NULL, 1262 [RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config, 1263 [RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config, 1264 [RTL_GIGA_MAC_VER_13] = NULL, 1265 [RTL_GIGA_MAC_VER_14] = rtl8401_hw_phy_config, 1266 [RTL_GIGA_MAC_VER_16] = NULL, 1267 [RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config, 1268 [RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config, 1269 [RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config, 1270 [RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config, 1271 [RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config, 1272 [RTL_GIGA_MAC_VER_22] = rtl8168c_3_hw_phy_config, 1273 [RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config, 1274 [RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config, 1275 [RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config, 1276 [RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config, 1277 [RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config, 1278 [RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config, 1279 [RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config, 1280 [RTL_GIGA_MAC_VER_31] = NULL, 1281 [RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config, 1282 [RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config, 1283 [RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config, 1284 [RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config, 1285 [RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config, 1286 [RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config, 1287 [RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config, 1288 [RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config, 1289 [RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config, 1290 [RTL_GIGA_MAC_VER_41] = NULL, 1291 [RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config, 1292 [RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config, 1293 [RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config, 1294 [RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config, 1295 [RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config, 1296 [RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config, 1297 [RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config, 1298 [RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config, 1299 [RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config, 1300 [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config, 1301 [RTL_GIGA_MAC_VER_52] = rtl8117_hw_phy_config, 1302 [RTL_GIGA_MAC_VER_53] = rtl8117_hw_phy_config, 1303 [RTL_GIGA_MAC_VER_60] = rtl8125a_1_hw_phy_config, 1304 [RTL_GIGA_MAC_VER_61] = rtl8125a_2_hw_phy_config, 1305 [RTL_GIGA_MAC_VER_63] = rtl8125b_hw_phy_config, 1306 }; 1307 1308 if (phy_configs[ver]) 1309 phy_configs[ver](tp, phydev); 1310 } 1311