1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Realtek RTL838X Ethernet MDIO interface driver
4 * Copyright (C) 2020 B. Koblitz
7 #include <linux/module.h>
8 #include <linux/delay.h>
10 #include <linux/netdevice.h>
11 #include <linux/firmware.h>
12 #include <linux/crc32.h>
14 #include <asm/mach-rtl838x/mach-rtl83xx.h>
15 #include "rtl83xx-phy.h"
18 extern struct rtl83xx_soc_info soc_info
;
19 extern struct mutex smi_lock
;
21 static const struct firmware rtl838x_8380_fw
;
22 static const struct firmware rtl838x_8214fc_fw
;
23 static const struct firmware rtl838x_8218b_fw
;
25 int rtl930x_read_mmd_phy(u32 port
, u32 devnum
, u32 regnum
, u32
*val
);
26 int rtl930x_write_mmd_phy(u32 port
, u32 addr
, u32 reg
, u32 val
);
28 static int read_phy(u32 port
, u32 page
, u32 reg
, u32
*val
)
29 { switch (soc_info
.family
) {
30 case RTL8380_FAMILY_ID
:
31 return rtl838x_read_phy(port
, page
, reg
, val
);
32 case RTL8390_FAMILY_ID
:
33 return rtl839x_read_phy(port
, page
, reg
, val
);
34 case RTL9300_FAMILY_ID
:
35 return rtl930x_read_phy(port
, page
, reg
, val
);
36 case RTL9310_FAMILY_ID
:
37 return rtl931x_read_phy(port
, page
, reg
, val
);
42 static int write_phy(u32 port
, u32 page
, u32 reg
, u32 val
)
44 switch (soc_info
.family
) {
45 case RTL8380_FAMILY_ID
:
46 return rtl838x_write_phy(port
, page
, reg
, val
);
47 case RTL8390_FAMILY_ID
:
48 return rtl839x_write_phy(port
, page
, reg
, val
);
49 case RTL9300_FAMILY_ID
:
50 return rtl930x_write_phy(port
, page
, reg
, val
);
51 case RTL9310_FAMILY_ID
:
52 return rtl931x_write_phy(port
, page
, reg
, val
);
57 static void rtl8380_int_phy_on_off(int mac
, bool on
)
61 read_phy(mac
, 0, 0, &val
);
63 write_phy(mac
, 0, 0, val
& ~BIT(11));
65 write_phy(mac
, 0, 0, val
| BIT(11));
68 static void rtl8380_rtl8214fc_on_off(int mac
, bool on
)
73 write_phy(mac
, 4095, 30, 3);
74 read_phy(mac
, 0, 16, &val
);
76 write_phy(mac
, 0, 16, val
& ~BIT(11));
78 write_phy(mac
, 0, 16, val
| BIT(11));
81 write_phy(mac
, 4095, 30, 1);
82 read_phy(mac
, 0, 16, &val
);
84 write_phy(mac
, 0xa40, 16, val
& ~BIT(11));
86 write_phy(mac
, 0xa40, 16, val
| BIT(11));
89 static void rtl8380_phy_reset(int mac
)
93 read_phy(mac
, 0, 0, &val
);
94 write_phy(mac
, 0, 0, val
| BIT(15));
97 static void rtl8380_sds_rst(int mac
)
99 u32 offset
= (mac
== 24) ? 0 : 0x100;
101 sw_w32_mask(1 << 11, 0, RTL8380_SDS4_FIB_REG0
+ offset
);
102 sw_w32_mask(0x3, 0, RTL838X_SDS4_REG28
+ offset
);
103 sw_w32_mask(0x3, 0x3, RTL838X_SDS4_REG28
+ offset
);
104 sw_w32_mask(0, 0x1 << 6, RTL838X_SDS4_DUMMY0
+ offset
);
105 sw_w32_mask(0x1 << 6, 0, RTL838X_SDS4_DUMMY0
+ offset
);
106 pr_info("SERDES reset: %d\n", mac
);
110 * Reset the SerDes by powering it off and set a new operations mode
111 * of the SerDes. 0x1f is off. Other modes are
112 * 0x01: QSGMII 0x04: 1000BX_FIBER 0x05: FIBER100
113 * 0x06: QSGMII 0x09: RSGMII 0x0d: USXGMII
114 * 0x10: XSGMII 0x12: HISGMII 0x16: 2500Base_X
115 * 0x17: RXAUI_LITE 0x19: RXAUI_PLUS 0x1a: 10G Base-R
116 * 0x1b: 10GR1000BX_AUTO 0x1f: OFF
118 void rtl9300_sds_rst(int sds_num
, u32 mode
)
120 // The access registers for SDS_MODE_SEL and the LSB for each SDS within
121 u16 regs
[] = { 0x0194, 0x0194, 0x0194, 0x0194, 0x02a0, 0x02a0, 0x02a0, 0x02a0,
122 0x02A4, 0x02A4, 0x0198, 0x0198 };
123 u8 lsb
[] = { 0, 6, 12, 18, 0, 6, 12, 18, 0, 6, 0, 6};
125 pr_info("SerDes: %s %d\n", __func__
, mode
);
126 if (sds_num
< 0 || sds_num
> 11) {
127 pr_err("Wrong SerDes number: %d\n", sds_num
);
131 sw_w32_mask(0x1f << lsb
[sds_num
], 0x1f << lsb
[sds_num
], regs
[sds_num
]);
134 sw_w32_mask(0x1f << lsb
[sds_num
], mode
<< lsb
[sds_num
], regs
[sds_num
]);
137 pr_info("SDS: 194:%08x 198:%08x 2a0:%08x 2a4:%08x\n",
138 sw_r32(0x194), sw_r32(0x198), sw_r32(0x2a0), sw_r32(0x2a4));
142 * On the RTL839x family of SoCs with inbuilt SerDes, these SerDes are accessed through
143 * a 2048 bit register that holds the contents of the PHY being simulated by the SoC.
145 int rtl839x_read_sds_phy(int phy_addr
, int phy_reg
)
155 * For the RTL8393 internal SerDes, we simulate a PHY ID in registers 2/3
156 * which would otherwise read as 0.
158 if (soc_info
.id
== 0x8393) {
166 * Register RTL839X_SDS12_13_XSG0 is 2048 bit broad, the MSB (bit 15) of the
167 * 0th PHY register is bit 1023 (in byte 0x80). Because PHY-registers are 16
168 * bit broad, we offset by reg << 1. In the SoC 2 registers are stored in
169 * one 32 bit register.
171 reg
= (phy_reg
<< 1) & 0xfc;
172 val
= sw_r32(RTL839X_SDS12_13_XSG0
+ offset
+ 0x80 + reg
);
175 val
= (val
>> 16) & 0xffff;
182 * On the RTL930x family of SoCs, the internal SerDes are accessed through an IO
183 * register which simulates commands to an internal MDIO bus.
185 int rtl930x_read_sds_phy(int phy_addr
, int page
, int phy_reg
)
188 u32 cmd
= phy_addr
<< 2 | page
<< 7 | phy_reg
<< 13 | 1;
190 pr_info("%s: phy_addr %d, phy_reg: %d\n", __func__
, phy_addr
, phy_reg
);
191 sw_w32(cmd
, RTL930X_SDS_INDACS_CMD
);
193 for (i
= 0; i
< 100; i
++) {
194 if (!(sw_r32(RTL930X_SDS_INDACS_CMD
) & 0x1))
202 pr_info("%s: returning %04x\n", __func__
, sw_r32(RTL930X_SDS_INDACS_DATA
) & 0xffff);
203 return sw_r32(RTL930X_SDS_INDACS_DATA
) & 0xffff;
206 int rtl930x_write_sds_phy(int phy_addr
, int page
, int phy_reg
, u16 v
)
211 sw_w32(v
, RTL930X_SDS_INDACS_DATA
);
212 cmd
= phy_addr
<< 2 | page
<< 7 | phy_reg
<< 13 | 0x3;
214 for (i
= 0; i
< 100; i
++) {
215 if (!(sw_r32(RTL930X_SDS_INDACS_CMD
) & 0x1))
227 * On the RTL838x SoCs, the internal SerDes is accessed through direct access to
228 * standard PHY registers, where a 32 bit register holds a 16 bit word as found
229 * in a standard page 0 of a PHY
231 int rtl838x_read_sds_phy(int phy_addr
, int phy_reg
)
238 val
= sw_r32(RTL838X_SDS4_FIB_REG0
+ offset
+ (phy_reg
<< 2)) & 0xffff;
243 int rtl839x_write_sds_phy(int phy_addr
, int phy_reg
, u16 v
)
252 reg
= (phy_reg
<< 1) & 0xfc;
256 sw_w32_mask(0xffff0000, val
,
257 RTL839X_SDS12_13_XSG0
+ offset
+ 0x80 + reg
);
259 sw_w32_mask(0xffff, val
,
260 RTL839X_SDS12_13_XSG0
+ offset
+ 0x80 + reg
);
266 /* Read the link and speed status of the 2 internal SGMII/1000Base-X
267 * ports of the RTL838x SoCs
269 static int rtl8380_read_status(struct phy_device
*phydev
)
273 err
= genphy_read_status(phydev
);
276 phydev
->speed
= SPEED_1000
;
277 phydev
->duplex
= DUPLEX_FULL
;
283 /* Read the link and speed status of the 2 internal SGMII/1000Base-X
284 * ports of the RTL8393 SoC
286 static int rtl8393_read_status(struct phy_device
*phydev
)
290 int phy_addr
= phydev
->mdio
.addr
;
293 err
= genphy_read_status(phydev
);
298 phydev
->speed
= SPEED_100
;
299 /* Read SPD_RD_00 (bit 13) and SPD_RD_01 (bit 6) out of the internal
302 v
= sw_r32(RTL839X_SDS12_13_XSG0
+ offset
+ 0x80);
303 if (!(v
& (1 << 13)) && (v
& (1 << 6)))
304 phydev
->speed
= SPEED_1000
;
305 phydev
->duplex
= DUPLEX_FULL
;
310 static int rtl8226_read_page(struct phy_device
*phydev
)
312 return __phy_read(phydev
, 0x1f);
315 static int rtl8226_write_page(struct phy_device
*phydev
, int page
)
317 return __phy_write(phydev
, 0x1f, page
);
320 static int rtl8226_read_status(struct phy_device
*phydev
)
324 int port
= phydev
->mdio
.addr
;
326 // TODO: ret = genphy_read_status(phydev);
328 // pr_info("%s: genphy_read_status failed\n", __func__);
332 // Link status must be read twice
333 for (i
= 0; i
< 2; i
++) {
334 rtl930x_read_mmd_phy(port
, MMD_VEND2
, 0xA402, &val
);
336 phydev
->link
= val
& BIT(2) ? 1 : 0;
340 // Read duplex status
341 ret
= rtl930x_read_mmd_phy(port
, MMD_VEND2
, 0xA434, &val
);
344 phydev
->duplex
= !!(val
& BIT(3));
347 ret
= rtl930x_read_mmd_phy(port
, MMD_VEND2
, 0xA434, &val
);
348 switch (val
& 0x0630) {
350 phydev
->speed
= SPEED_10
;
353 phydev
->speed
= SPEED_100
;
356 phydev
->speed
= SPEED_1000
;
359 phydev
->speed
= SPEED_10000
;
362 phydev
->speed
= SPEED_2500
;
365 phydev
->speed
= SPEED_5000
;
374 static int rtl8266_advertise_aneg(struct phy_device
*phydev
)
378 int port
= phydev
->mdio
.addr
;
380 pr_info("In %s\n", __func__
);
382 ret
= rtl930x_read_mmd_phy(port
, MMD_AN
, 16, &v
);
386 v
|= BIT(5); // HD 10M
387 v
|= BIT(6); // FD 10M
388 v
|= BIT(7); // HD 100M
389 v
|= BIT(8); // FD 100M
391 ret
= rtl930x_write_mmd_phy(port
, MMD_AN
, 16, v
);
394 ret
= rtl930x_read_mmd_phy(port
, MMD_VEND2
, 0xA412, &v
);
397 v
|= BIT(9); // FD 1000M
399 ret
= rtl930x_write_mmd_phy(port
, MMD_VEND2
, 0xA412, v
);
404 ret
= rtl930x_read_mmd_phy(port
, MMD_AN
, 32, &v
);
409 ret
= rtl930x_write_mmd_phy(port
, MMD_AN
, 32, v
);
416 static int rtl8226_config_aneg(struct phy_device
*phydev
)
420 int port
= phydev
->mdio
.addr
;
422 pr_info("In %s\n", __func__
);
423 if (phydev
->autoneg
== AUTONEG_ENABLE
) {
424 ret
= rtl8266_advertise_aneg(phydev
);
427 // AutoNegotiationEnable
428 ret
= rtl930x_read_mmd_phy(port
, MMD_AN
, 0, &v
);
432 v
|= BIT(12); // Enable AN
433 ret
= rtl930x_write_mmd_phy(port
, MMD_AN
, 0, v
);
437 // RestartAutoNegotiation
438 ret
= rtl930x_read_mmd_phy(port
, MMD_VEND2
, 0xA400, &v
);
443 ret
= rtl930x_write_mmd_phy(port
, MMD_VEND2
, 0xA400, v
);
446 pr_info("%s: Ret is already: %d\n", __func__
, ret
);
447 // TODO: ret = __genphy_config_aneg(phydev, ret);
450 pr_info("%s: And ret is now: %d\n", __func__
, ret
);
454 static struct fw_header
*rtl838x_request_fw(struct phy_device
*phydev
,
455 const struct firmware
*fw
,
458 struct device
*dev
= &phydev
->mdio
.dev
;
461 uint32_t checksum
, my_checksum
;
463 err
= request_firmware(&fw
, name
, dev
);
467 if (fw
->size
< sizeof(struct fw_header
)) {
468 pr_err("Firmware size too small.\n");
473 h
= (struct fw_header
*) fw
->data
;
474 pr_info("Firmware loaded. Size %d, magic: %08x\n", fw
->size
, h
->magic
);
476 if (h
->magic
!= 0x83808380) {
477 pr_err("Wrong firmware file: MAGIC mismatch.\n");
481 checksum
= h
->checksum
;
483 my_checksum
= ~crc32(0xFFFFFFFFU
, fw
->data
, fw
->size
);
484 if (checksum
!= my_checksum
) {
485 pr_err("Firmware checksum mismatch.\n");
489 h
->checksum
= checksum
;
493 dev_err(dev
, "Unable to load firmware %s (%d)\n", name
, err
);
497 static int rtl8390_configure_generic(struct phy_device
*phydev
)
500 int mac
= phydev
->mdio
.addr
;
502 read_phy(mac
, 0, 2, &val
);
504 read_phy(mac
, 0, 3, &val
);
506 pr_debug("Phy on MAC %d: %x\n", mac
, phy_id
);
508 /* Read internal PHY ID */
509 write_phy(mac
, 31, 27, 0x0002);
510 read_phy(mac
, 31, 28, &val
);
512 /* Internal RTL8218B, version 2 */
513 phydev_info(phydev
, "Detected unknown %x\n", val
);
517 static int rtl8380_configure_int_rtl8218b(struct phy_device
*phydev
)
521 int mac
= phydev
->mdio
.addr
;
523 u32
*rtl838x_6275B_intPhy_perport
;
524 u32
*rtl8218b_6276B_hwEsd_perport
;
527 read_phy(mac
, 0, 2, &val
);
529 read_phy(mac
, 0, 3, &val
);
531 pr_debug("Phy on MAC %d: %x\n", mac
, phy_id
);
533 /* Read internal PHY ID */
534 write_phy(mac
, 31, 27, 0x0002);
535 read_phy(mac
, 31, 28, &val
);
537 phydev_err(phydev
, "Expected internal RTL8218B, found PHY-ID %x\n", val
);
541 /* Internal RTL8218B, version 2 */
542 phydev_info(phydev
, "Detected internal RTL8218B\n");
544 h
= rtl838x_request_fw(phydev
, &rtl838x_8380_fw
, FIRMWARE_838X_8380_1
);
548 if (h
->phy
!= 0x83800000) {
549 phydev_err(phydev
, "Wrong firmware file: PHY mismatch.\n");
553 rtl838x_6275B_intPhy_perport
= (void *)h
+ sizeof(struct fw_header
)
556 rtl8218b_6276B_hwEsd_perport
= (void *)h
+ sizeof(struct fw_header
)
559 if (sw_r32(RTL838X_DMY_REG31
) == 0x1)
562 read_phy(mac
, 0, 0, &val
);
564 rtl8380_int_phy_on_off(mac
, true);
566 rtl8380_phy_reset(mac
);
569 /* Ready PHY for patch */
570 for (p
= 0; p
< 8; p
++) {
571 write_phy(mac
+ p
, 0xfff, 0x1f, 0x0b82);
572 write_phy(mac
+ p
, 0xfff, 0x10, 0x0010);
575 for (p
= 0; p
< 8; p
++) {
576 for (i
= 0; i
< 100 ; i
++) {
577 read_phy(mac
+ p
, 0x0b80, 0x10, &val
);
583 "ERROR: Port %d not ready for patch.\n",
588 for (p
= 0; p
< 8; p
++) {
590 while (rtl838x_6275B_intPhy_perport
[i
* 2]) {
591 write_phy(mac
+ p
, 0xfff,
592 rtl838x_6275B_intPhy_perport
[i
* 2],
593 rtl838x_6275B_intPhy_perport
[i
* 2 + 1]);
597 while (rtl8218b_6276B_hwEsd_perport
[i
* 2]) {
598 write_phy(mac
+ p
, 0xfff,
599 rtl8218b_6276B_hwEsd_perport
[i
* 2],
600 rtl8218b_6276B_hwEsd_perport
[i
* 2 + 1]);
607 static int rtl8380_configure_ext_rtl8218b(struct phy_device
*phydev
)
609 u32 val
, ipd
, phy_id
;
611 int mac
= phydev
->mdio
.addr
;
613 u32
*rtl8380_rtl8218b_perchip
;
614 u32
*rtl8218B_6276B_rtl8380_perport
;
615 u32
*rtl8380_rtl8218b_perport
;
617 if (soc_info
.family
== RTL8380_FAMILY_ID
&& mac
!= 0 && mac
!= 16) {
618 phydev_err(phydev
, "External RTL8218B must have PHY-IDs 0 or 16!\n");
621 read_phy(mac
, 0, 2, &val
);
623 read_phy(mac
, 0, 3, &val
);
625 pr_info("Phy on MAC %d: %x\n", mac
, phy_id
);
627 /* Read internal PHY ID */
628 write_phy(mac
, 31, 27, 0x0002);
629 read_phy(mac
, 31, 28, &val
);
631 phydev_err(phydev
, "Expected external RTL8218B, found PHY-ID %x\n", val
);
634 phydev_info(phydev
, "Detected external RTL8218B\n");
636 h
= rtl838x_request_fw(phydev
, &rtl838x_8218b_fw
, FIRMWARE_838X_8218b_1
);
640 if (h
->phy
!= 0x8218b000) {
641 phydev_err(phydev
, "Wrong firmware file: PHY mismatch.\n");
645 rtl8380_rtl8218b_perchip
= (void *)h
+ sizeof(struct fw_header
)
648 rtl8218B_6276B_rtl8380_perport
= (void *)h
+ sizeof(struct fw_header
)
651 rtl8380_rtl8218b_perport
= (void *)h
+ sizeof(struct fw_header
)
654 read_phy(mac
, 0, 0, &val
);
656 rtl8380_int_phy_on_off(mac
, true);
658 rtl8380_phy_reset(mac
);
661 /* Get Chip revision */
662 write_phy(mac
, 0xfff, 0x1f, 0x0);
663 write_phy(mac
, 0xfff, 0x1b, 0x4);
664 read_phy(mac
, 0xfff, 0x1c, &val
);
667 while (rtl8380_rtl8218b_perchip
[i
* 3]
668 && rtl8380_rtl8218b_perchip
[i
* 3 + 1]) {
669 write_phy(mac
+ rtl8380_rtl8218b_perchip
[i
* 3],
670 0xfff, rtl8380_rtl8218b_perchip
[i
* 3 + 1],
671 rtl8380_rtl8218b_perchip
[i
* 3 + 2]);
676 for (i
= 0; i
< 8; i
++) {
677 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0000);
678 write_phy(mac
+ i
, 0xfff, 0x00, 0x1140);
683 for (i
= 0; i
< 8; i
++) {
684 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0b82);
685 write_phy(mac
+ i
, 0xfff, 0x10, 0x0010);
689 /* Verify patch readiness */
690 for (i
= 0; i
< 8; i
++) {
691 for (l
= 0; l
< 100; l
++) {
692 read_phy(mac
+ i
, 0xb80, 0x10, &val
);
697 phydev_err(phydev
, "Could not patch PHY\n");
702 /* Use Broadcast ID method for patching */
703 write_phy(mac
, 0xfff, 0x1f, 0x0000);
704 write_phy(mac
, 0xfff, 0x1d, 0x0008);
705 write_phy(mac
, 0xfff, 0x1f, 0x0266);
706 write_phy(mac
, 0xfff, 0x16, 0xff00 + mac
);
707 write_phy(mac
, 0xfff, 0x1f, 0x0000);
708 write_phy(mac
, 0xfff, 0x1d, 0x0000);
711 write_phy(mac
, 0xfff, 30, 8);
712 write_phy(mac
, 0x26e, 17, 0xb);
713 write_phy(mac
, 0x26e, 16, 0x2);
715 read_phy(mac
, 0x26e, 19, &ipd
);
716 write_phy(mac
, 0, 30, 0);
717 ipd
= (ipd
>> 4) & 0xf;
720 while (rtl8218B_6276B_rtl8380_perport
[i
* 2]) {
721 write_phy(mac
, 0xfff, rtl8218B_6276B_rtl8380_perport
[i
* 2],
722 rtl8218B_6276B_rtl8380_perport
[i
* 2 + 1]);
726 /*Disable broadcast ID*/
727 write_phy(mac
, 0xfff, 0x1f, 0x0000);
728 write_phy(mac
, 0xfff, 0x1d, 0x0008);
729 write_phy(mac
, 0xfff, 0x1f, 0x0266);
730 write_phy(mac
, 0xfff, 0x16, 0x00 + mac
);
731 write_phy(mac
, 0xfff, 0x1f, 0x0000);
732 write_phy(mac
, 0xfff, 0x1d, 0x0000);
738 static int rtl8218b_ext_match_phy_device(struct phy_device
*phydev
)
740 int addr
= phydev
->mdio
.addr
;
742 /* Both the RTL8214FC and the external RTL8218B have the same
743 * PHY ID. On the RTL838x, the RTL8218B can only be attached_dev
744 * at PHY IDs 0-7, while the RTL8214FC must be attached via
745 * the pair of SGMII/1000Base-X with higher PHY-IDs
747 if (soc_info
.family
== RTL8380_FAMILY_ID
)
748 return phydev
->phy_id
== PHY_ID_RTL8218B_E
&& addr
< 8;
750 return phydev
->phy_id
== PHY_ID_RTL8218B_E
;
754 * Read an mmd register of the PHY
756 static int rtl83xx_read_mmd_phy(u32 port
, u32 addr
, u32 reg
, u32
*val
)
760 mutex_lock(&smi_lock
);
762 if (rtl838x_smi_wait_op(10000))
765 sw_w32(1 << port
, RTL838X_SMI_ACCESS_PHY_CTRL_0
);
768 sw_w32_mask(0xffff0000, port
<< 16, RTL838X_SMI_ACCESS_PHY_CTRL_2
);
770 v
= addr
<< 16 | reg
;
771 sw_w32(v
, RTL838X_SMI_ACCESS_PHY_CTRL_3
);
773 /* mmd-access | read | cmd-start */
774 v
= 1 << 1 | 0 << 2 | 1;
775 sw_w32(v
, RTL838X_SMI_ACCESS_PHY_CTRL_1
);
777 if (rtl838x_smi_wait_op(10000))
780 *val
= sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2
) & 0xffff;
782 mutex_unlock(&smi_lock
);
786 mutex_unlock(&smi_lock
);
791 * Write to an mmd register of the PHY
793 static int rtl838x_write_mmd_phy(u32 port
, u32 addr
, u32 reg
, u32 val
)
797 pr_debug("MMD write: port %d, dev %d, reg %d, val %x\n", port
, addr
, reg
, val
);
799 mutex_lock(&smi_lock
);
801 if (rtl838x_smi_wait_op(10000))
804 sw_w32(1 << port
, RTL838X_SMI_ACCESS_PHY_CTRL_0
);
807 sw_w32_mask(0xffff0000, val
<< 16, RTL838X_SMI_ACCESS_PHY_CTRL_2
);
809 sw_w32_mask(0x1f << 16, addr
<< 16, RTL838X_SMI_ACCESS_PHY_CTRL_3
);
810 sw_w32_mask(0xffff, reg
, RTL838X_SMI_ACCESS_PHY_CTRL_3
);
811 /* mmd-access | write | cmd-start */
812 v
= 1 << 1 | 1 << 2 | 1;
813 sw_w32(v
, RTL838X_SMI_ACCESS_PHY_CTRL_1
);
815 if (rtl838x_smi_wait_op(10000))
818 mutex_unlock(&smi_lock
);
822 mutex_unlock(&smi_lock
);
826 static int rtl8218b_read_mmd(struct phy_device
*phydev
,
827 int devnum
, u16 regnum
)
831 int addr
= phydev
->mdio
.addr
;
833 ret
= rtl83xx_read_mmd_phy(addr
, devnum
, regnum
, &val
);
839 static int rtl8218b_write_mmd(struct phy_device
*phydev
,
840 int devnum
, u16 regnum
, u16 val
)
842 int addr
= phydev
->mdio
.addr
;
844 return rtl838x_write_mmd_phy(addr
, devnum
, regnum
, val
);
847 static int rtl8226_read_mmd(struct phy_device
*phydev
, int devnum
, u16 regnum
)
849 int port
= phydev
->mdio
.addr
; // the SoC translates port addresses to PHY addr
853 err
= rtl930x_read_mmd_phy(port
, devnum
, regnum
, &val
);
860 static int rtl8226_write_mmd(struct phy_device
*phydev
, int devnum
, u16 regnum
, u16 val
)
862 int port
= phydev
->mdio
.addr
; // the SoC translates port addresses to PHY addr
864 return rtl930x_write_mmd_phy(port
, devnum
, regnum
, val
);
867 static void rtl8380_rtl8214fc_media_set(int mac
, bool set_fibre
)
869 int base
= mac
- (mac
% 4);
870 static int reg
[] = {16, 19, 20, 21};
871 int val
, media
, power
;
873 pr_info("%s: port %d, set_fibre: %d\n", __func__
, mac
, set_fibre
);
874 write_phy(base
, 0xfff, 29, 8);
875 read_phy(base
, 0x266, reg
[mac
% 4], &val
);
877 media
= (val
>> 10) & 0x3;
878 pr_info("Current media %x\n", media
);
880 pr_info("Powering off COPPER\n");
881 write_phy(base
, 0xfff, 29, 1);
882 /* Ensure power is off */
883 read_phy(base
, 0xa40, 16, &power
);
884 if (!(power
& (1 << 11)))
885 write_phy(base
, 0xa40, 16, power
| (1 << 11));
887 pr_info("Powering off FIBRE");
888 write_phy(base
, 0xfff, 29, 3);
889 /* Ensure power is off */
890 read_phy(base
, 0xa40, 16, &power
);
891 if (!(power
& (1 << 11)))
892 write_phy(base
, 0xa40, 16, power
| (1 << 11));
902 write_phy(base
, 0xfff, 29, 8);
903 write_phy(base
, 0x266, reg
[mac
% 4], val
);
904 write_phy(base
, 0xfff, 29, 0);
907 pr_info("Powering on FIBRE");
908 write_phy(base
, 0xfff, 29, 3);
909 /* Ensure power is off */
910 read_phy(base
, 0xa40, 16, &power
);
911 if (power
& (1 << 11))
912 write_phy(base
, 0xa40, 16, power
& ~(1 << 11));
914 pr_info("Powering on COPPER\n");
915 write_phy(base
, 0xfff, 29, 1);
916 /* Ensure power is off */
917 read_phy(base
, 0xa40, 16, &power
);
918 if (power
& (1 << 11))
919 write_phy(base
, 0xa40, 16, power
& ~(1 << 11));
922 write_phy(base
, 0xfff, 29, 0);
925 static bool rtl8380_rtl8214fc_media_is_fibre(int mac
)
927 int base
= mac
- (mac
% 4);
928 static int reg
[] = {16, 19, 20, 21};
931 write_phy(base
, 0xfff, 29, 8);
932 read_phy(base
, 0x266, reg
[mac
% 4], &val
);
933 write_phy(base
, 0xfff, 29, 0);
939 static int rtl8214fc_set_port(struct phy_device
*phydev
, int port
)
941 bool is_fibre
= (port
== PORT_FIBRE
? true : false);
942 int addr
= phydev
->mdio
.addr
;
944 pr_debug("%s port %d to %d\n", __func__
, addr
, port
);
946 rtl8380_rtl8214fc_media_set(addr
, is_fibre
);
950 static int rtl8214fc_get_port(struct phy_device
*phydev
)
952 int addr
= phydev
->mdio
.addr
;
954 pr_debug("%s: port %d\n", __func__
, addr
);
955 if (rtl8380_rtl8214fc_media_is_fibre(addr
))
960 static void rtl8218b_eee_set_u_boot(int port
, bool enable
)
965 /* Set GPHY page to copper */
966 write_phy(port
, 0, 30, 0x0001);
967 read_phy(port
, 0, 0, &val
);
968 an_enabled
= val
& (1 << 12);
971 /* 100/1000M EEE Capability */
972 write_phy(port
, 0, 13, 0x0007);
973 write_phy(port
, 0, 14, 0x003C);
974 write_phy(port
, 0, 13, 0x4007);
975 write_phy(port
, 0, 14, 0x0006);
977 read_phy(port
, 0x0A43, 25, &val
);
979 write_phy(port
, 0x0A43, 25, val
);
981 /* 100/1000M EEE Capability */
982 write_phy(port
, 0, 13, 0x0007);
983 write_phy(port
, 0, 14, 0x003C);
984 write_phy(port
, 0, 13, 0x0007);
985 write_phy(port
, 0, 14, 0x0000);
987 read_phy(port
, 0x0A43, 25, &val
);
989 write_phy(port
, 0x0A43, 25, val
);
992 /* Restart AN if enabled */
994 read_phy(port
, 0, 0, &val
);
995 val
|= (1 << 12) | (1 << 9);
996 write_phy(port
, 0, 0, val
);
999 /* GPHY page back to auto*/
1000 write_phy(port
, 0xa42, 29, 0);
1004 void rtl8380_rtl8218b_eee_set(int port
, bool enable
)
1009 pr_debug("In %s %d, enable %d\n", __func__
, port
, enable
);
1010 /* Set GPHY page to copper */
1011 write_phy(port
, 0xa42, 29, 0x0001);
1013 read_phy(port
, 0, 0, &val
);
1014 an_enabled
= val
& (1 << 12);
1017 read_phy(port
, 0xa43, 25, &val
);
1019 write_phy(port
, 0xa43, 25, val
);
1021 /* 100M / 1000M EEE */
1023 rtl838x_write_mmd_phy(port
, 7, 60, 0x6);
1025 rtl838x_write_mmd_phy(port
, 7, 60, 0);
1027 /* 500M EEE ability */
1028 read_phy(port
, 0xa42, 20, &val
);
1033 write_phy(port
, 0xa42, 20, val
);
1035 /* Restart AN if enabled */
1037 read_phy(port
, 0, 0, &val
);
1038 val
|= (1 << 12) | (1 << 9);
1039 write_phy(port
, 0, 0, val
);
1042 /* GPHY page back to auto*/
1043 write_phy(port
, 0xa42, 29, 0);
1046 static int rtl8218b_get_eee(struct phy_device
*phydev
,
1047 struct ethtool_eee
*e
)
1050 int addr
= phydev
->mdio
.addr
;
1052 pr_debug("In %s, port %d\n", __func__
, addr
);
1054 /* Set GPHY page to copper */
1055 write_phy(addr
, 0xa42, 29, 0x0001);
1057 rtl83xx_read_mmd_phy(addr
, 7, 60, &val
);
1058 if (e
->eee_enabled
&& (!!(val
& (1 << 7))))
1059 e
->eee_enabled
= !!(val
& (1 << 7));
1063 /* GPHY page to auto */
1064 write_phy(addr
, 0xa42, 29, 0x0000);
1070 void rtl8380_rtl8218b_green_set(int mac
, bool enable
)
1074 /* Set GPHY page to copper */
1075 write_phy(mac
, 0xa42, 29, 0x0001);
1077 write_phy(mac
, 0, 27, 0x8011);
1078 read_phy(mac
, 0, 28, &val
);
1081 write_phy(mac
, 0, 27, 0x8011);
1082 write_phy(mac
, 0, 28, val
);
1085 write_phy(mac
, 0, 27, 0x8011);
1086 write_phy(mac
, 0, 28, val
);
1089 /* GPHY page to auto */
1090 write_phy(mac
, 0xa42, 29, 0x0000);
1094 int rtl8380_rtl8214fc_get_green(struct phy_device
*phydev
, struct ethtool_eee
*e
)
1097 int addr
= phydev
->mdio
.addr
;
1099 pr_debug("In %s %d\n", __func__
, addr
);
1100 /* Set GPHY page to copper */
1101 write_phy(addr
, 0xa42, 29, 0x0001);
1103 write_phy(addr
, 0, 27, 0x8011);
1104 read_phy(addr
, 0, 28, &val
);
1105 if (e
->eee_enabled
&& (!!(val
& (1 << 9))))
1106 e
->eee_enabled
= !!(val
& (1 << 9));
1110 /* GPHY page to auto */
1111 write_phy(addr
, 0xa42, 29, 0x0000);
1116 static int rtl8214fc_set_eee(struct phy_device
*phydev
,
1117 struct ethtool_eee
*e
)
1120 int addr
= phydev
->mdio
.addr
;
1122 pr_debug("In %s port %d, enabled %d\n", __func__
, addr
, e
->eee_enabled
);
1124 if (rtl8380_rtl8214fc_media_is_fibre(addr
)) {
1125 netdev_err(phydev
->attached_dev
, "Port %d configured for FIBRE", addr
);
1129 pollMask
= sw_r32(RTL838X_SMI_POLL_CTRL
);
1130 sw_w32(0, RTL838X_SMI_POLL_CTRL
);
1131 rtl8218b_eee_set_u_boot(addr
, (bool) e
->eee_enabled
);
1132 sw_w32(pollMask
, RTL838X_SMI_POLL_CTRL
);
1136 static int rtl8214fc_get_eee(struct phy_device
*phydev
,
1137 struct ethtool_eee
*e
)
1139 int addr
= phydev
->mdio
.addr
;
1141 pr_debug("In %s port %d, enabled %d\n", __func__
, addr
, e
->eee_enabled
);
1142 if (rtl8380_rtl8214fc_media_is_fibre(addr
)) {
1143 netdev_err(phydev
->attached_dev
, "Port %d configured for FIBRE", addr
);
1147 return rtl8218b_get_eee(phydev
, e
);
1150 static int rtl8218b_set_eee(struct phy_device
*phydev
,
1151 struct ethtool_eee
*e
)
1154 int addr
= phydev
->mdio
.addr
;
1156 pr_debug("In %s, port %d, enabled %d\n", __func__
, addr
, e
->eee_enabled
);
1158 pollMask
= sw_r32(RTL838X_SMI_POLL_CTRL
);
1159 sw_w32(0, RTL838X_SMI_POLL_CTRL
);
1160 rtl8218b_eee_set_u_boot(addr
, (bool) e
->eee_enabled
);
1161 sw_w32(pollMask
, RTL838X_SMI_POLL_CTRL
);
1166 static int rtl8214c_match_phy_device(struct phy_device
*phydev
)
1168 return phydev
->phy_id
== PHY_ID_RTL8214C
;
1171 static int rtl8380_configure_rtl8214c(struct phy_device
*phydev
)
1174 int mac
= phydev
->mdio
.addr
;
1176 read_phy(mac
, 0, 2, &val
);
1178 read_phy(mac
, 0, 3, &val
);
1180 pr_debug("Phy on MAC %d: %x\n", mac
, phy_id
);
1182 phydev_info(phydev
, "Detected external RTL8214C\n");
1184 /* GPHY auto conf */
1185 write_phy(mac
, 0xa42, 29, 0);
1189 static int rtl8380_configure_rtl8214fc(struct phy_device
*phydev
)
1191 u32 phy_id
, val
, page
= 0;
1193 int mac
= phydev
->mdio
.addr
;
1194 struct fw_header
*h
;
1195 u32
*rtl8380_rtl8214fc_perchip
;
1196 u32
*rtl8380_rtl8214fc_perport
;
1198 read_phy(mac
, 0, 2, &val
);
1200 read_phy(mac
, 0, 3, &val
);
1202 pr_debug("Phy on MAC %d: %x\n", mac
, phy_id
);
1204 /* Read internal PHY id */
1205 write_phy(mac
, 0, 30, 0x0001);
1206 write_phy(mac
, 0, 31, 0x0a42);
1207 write_phy(mac
, 31, 27, 0x0002);
1208 read_phy(mac
, 31, 28, &val
);
1209 if (val
!= 0x6276) {
1210 phydev_err(phydev
, "Expected external RTL8214FC, found PHY-ID %x\n", val
);
1213 phydev_info(phydev
, "Detected external RTL8214FC\n");
1215 h
= rtl838x_request_fw(phydev
, &rtl838x_8214fc_fw
, FIRMWARE_838X_8214FC_1
);
1219 if (h
->phy
!= 0x8214fc00) {
1220 phydev_err(phydev
, "Wrong firmware file: PHY mismatch.\n");
1224 rtl8380_rtl8214fc_perchip
= (void *)h
+ sizeof(struct fw_header
)
1225 + h
->parts
[0].start
;
1227 rtl8380_rtl8214fc_perport
= (void *)h
+ sizeof(struct fw_header
)
1228 + h
->parts
[1].start
;
1230 /* detect phy version */
1231 write_phy(mac
, 0xfff, 27, 0x0004);
1232 read_phy(mac
, 0xfff, 28, &val
);
1234 read_phy(mac
, 0, 16, &val
);
1235 if (val
& (1 << 11))
1236 rtl8380_rtl8214fc_on_off(mac
, true);
1238 rtl8380_phy_reset(mac
);
1241 write_phy(mac
, 0, 30, 0x0001);
1244 while (rtl8380_rtl8214fc_perchip
[i
* 3]
1245 && rtl8380_rtl8214fc_perchip
[i
* 3 + 1]) {
1246 if (rtl8380_rtl8214fc_perchip
[i
* 3 + 1] == 0x1f)
1247 page
= rtl8380_rtl8214fc_perchip
[i
* 3 + 2];
1248 if (rtl8380_rtl8214fc_perchip
[i
* 3 + 1] == 0x13 && page
== 0x260) {
1249 read_phy(mac
+ rtl8380_rtl8214fc_perchip
[i
* 3], 0x260, 13, &val
);
1250 val
= (val
& 0x1f00) | (rtl8380_rtl8214fc_perchip
[i
* 3 + 2]
1252 write_phy(mac
+ rtl8380_rtl8214fc_perchip
[i
* 3],
1253 0xfff, rtl8380_rtl8214fc_perchip
[i
* 3 + 1], val
);
1255 write_phy(mac
+ rtl8380_rtl8214fc_perchip
[i
* 3],
1256 0xfff, rtl8380_rtl8214fc_perchip
[i
* 3 + 1],
1257 rtl8380_rtl8214fc_perchip
[i
* 3 + 2]);
1262 /* Force copper medium */
1263 for (i
= 0; i
< 4; i
++) {
1264 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0000);
1265 write_phy(mac
+ i
, 0xfff, 0x1e, 0x0001);
1269 for (i
= 0; i
< 4; i
++) {
1270 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0000);
1271 write_phy(mac
+ i
, 0xfff, 0x00, 0x1140);
1275 /* Disable Autosensing */
1276 for (i
= 0; i
< 4; i
++) {
1277 for (l
= 0; l
< 100; l
++) {
1278 read_phy(mac
+ i
, 0x0a42, 0x10, &val
);
1279 if ((val
& 0x7) >= 3)
1283 phydev_err(phydev
, "Could not disable autosensing\n");
1289 for (i
= 0; i
< 4; i
++) {
1290 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0b82);
1291 write_phy(mac
+ i
, 0xfff, 0x10, 0x0010);
1295 /* Verify patch readiness */
1296 for (i
= 0; i
< 4; i
++) {
1297 for (l
= 0; l
< 100; l
++) {
1298 read_phy(mac
+ i
, 0xb80, 0x10, &val
);
1303 phydev_err(phydev
, "Could not patch PHY\n");
1308 /* Use Broadcast ID method for patching */
1309 write_phy(mac
, 0xfff, 0x1f, 0x0000);
1310 write_phy(mac
, 0xfff, 0x1d, 0x0008);
1311 write_phy(mac
, 0xfff, 0x1f, 0x0266);
1312 write_phy(mac
, 0xfff, 0x16, 0xff00 + mac
);
1313 write_phy(mac
, 0xfff, 0x1f, 0x0000);
1314 write_phy(mac
, 0xfff, 0x1d, 0x0000);
1318 while (rtl8380_rtl8214fc_perport
[i
* 2]) {
1319 write_phy(mac
, 0xfff, rtl8380_rtl8214fc_perport
[i
* 2],
1320 rtl8380_rtl8214fc_perport
[i
* 2 + 1]);
1324 /*Disable broadcast ID*/
1325 write_phy(mac
, 0xfff, 0x1f, 0x0000);
1326 write_phy(mac
, 0xfff, 0x1d, 0x0008);
1327 write_phy(mac
, 0xfff, 0x1f, 0x0266);
1328 write_phy(mac
, 0xfff, 0x16, 0x00 + mac
);
1329 write_phy(mac
, 0xfff, 0x1f, 0x0000);
1330 write_phy(mac
, 0xfff, 0x1d, 0x0000);
1333 /* Auto medium selection */
1334 for (i
= 0; i
< 4; i
++) {
1335 write_phy(mac
+ i
, 0xfff, 0x1f, 0x0000);
1336 write_phy(mac
+ i
, 0xfff, 0x1e, 0x0000);
1342 static int rtl8214fc_match_phy_device(struct phy_device
*phydev
)
1344 int addr
= phydev
->mdio
.addr
;
1346 return phydev
->phy_id
== PHY_ID_RTL8214FC
&& addr
>= 24;
1349 static int rtl8380_configure_serdes(struct phy_device
*phydev
)
1354 struct fw_header
*h
;
1355 u32
*rtl8380_sds_take_reset
;
1356 u32
*rtl8380_sds_common
;
1357 u32
*rtl8380_sds01_qsgmii_6275b
;
1358 u32
*rtl8380_sds23_qsgmii_6275b
;
1359 u32
*rtl8380_sds4_fiber_6275b
;
1360 u32
*rtl8380_sds5_fiber_6275b
;
1361 u32
*rtl8380_sds_reset
;
1362 u32
*rtl8380_sds_release_reset
;
1364 phydev_info(phydev
, "Detected internal RTL8380 SERDES\n");
1366 h
= rtl838x_request_fw(phydev
, &rtl838x_8218b_fw
, FIRMWARE_838X_8380_1
);
1370 if (h
->magic
!= 0x83808380) {
1371 phydev_err(phydev
, "Wrong firmware file: magic number mismatch.\n");
1375 rtl8380_sds_take_reset
= (void *)h
+ sizeof(struct fw_header
)
1376 + h
->parts
[0].start
;
1378 rtl8380_sds_common
= (void *)h
+ sizeof(struct fw_header
)
1379 + h
->parts
[1].start
;
1381 rtl8380_sds01_qsgmii_6275b
= (void *)h
+ sizeof(struct fw_header
)
1382 + h
->parts
[2].start
;
1384 rtl8380_sds23_qsgmii_6275b
= (void *)h
+ sizeof(struct fw_header
)
1385 + h
->parts
[3].start
;
1387 rtl8380_sds4_fiber_6275b
= (void *)h
+ sizeof(struct fw_header
)
1388 + h
->parts
[4].start
;
1390 rtl8380_sds5_fiber_6275b
= (void *)h
+ sizeof(struct fw_header
)
1391 + h
->parts
[5].start
;
1393 rtl8380_sds_reset
= (void *)h
+ sizeof(struct fw_header
)
1394 + h
->parts
[6].start
;
1396 rtl8380_sds_release_reset
= (void *)h
+ sizeof(struct fw_header
)
1397 + h
->parts
[7].start
;
1399 /* Back up serdes power off value */
1400 sds_conf_value
= sw_r32(RTL838X_SDS_CFG_REG
);
1401 pr_info("SDS power down value: %x\n", sds_conf_value
);
1403 /* take serdes into reset */
1405 while (rtl8380_sds_take_reset
[2 * i
]) {
1406 sw_w32(rtl8380_sds_take_reset
[2 * i
+ 1], rtl8380_sds_take_reset
[2 * i
]);
1411 /* apply common serdes patch */
1413 while (rtl8380_sds_common
[2 * i
]) {
1414 sw_w32(rtl8380_sds_common
[2 * i
+ 1], rtl8380_sds_common
[2 * i
]);
1419 /* internal R/W enable */
1420 sw_w32(3, RTL838X_INT_RW_CTRL
);
1422 /* SerDes ports 4 and 5 are FIBRE ports */
1423 sw_w32_mask(0x7 | 0x38, 1 | (1 << 3), RTL838X_INT_MODE_CTRL
);
1425 /* SerDes module settings, SerDes 0-3 are QSGMII */
1426 v
= 0x6 << 25 | 0x6 << 20 | 0x6 << 15 | 0x6 << 10;
1427 /* SerDes 4 and 5 are 1000BX FIBRE */
1428 v
|= 0x4 << 5 | 0x4;
1429 sw_w32(v
, RTL838X_SDS_MODE_SEL
);
1431 pr_info("PLL control register: %x\n", sw_r32(RTL838X_PLL_CML_CTRL
));
1432 sw_w32_mask(0xfffffff0, 0xaaaaaaaf & 0xf, RTL838X_PLL_CML_CTRL
);
1434 while (rtl8380_sds01_qsgmii_6275b
[2 * i
]) {
1435 sw_w32(rtl8380_sds01_qsgmii_6275b
[2 * i
+ 1],
1436 rtl8380_sds01_qsgmii_6275b
[2 * i
]);
1441 while (rtl8380_sds23_qsgmii_6275b
[2 * i
]) {
1442 sw_w32(rtl8380_sds23_qsgmii_6275b
[2 * i
+ 1], rtl8380_sds23_qsgmii_6275b
[2 * i
]);
1447 while (rtl8380_sds4_fiber_6275b
[2 * i
]) {
1448 sw_w32(rtl8380_sds4_fiber_6275b
[2 * i
+ 1], rtl8380_sds4_fiber_6275b
[2 * i
]);
1453 while (rtl8380_sds5_fiber_6275b
[2 * i
]) {
1454 sw_w32(rtl8380_sds5_fiber_6275b
[2 * i
+ 1], rtl8380_sds5_fiber_6275b
[2 * i
]);
1459 while (rtl8380_sds_reset
[2 * i
]) {
1460 sw_w32(rtl8380_sds_reset
[2 * i
+ 1], rtl8380_sds_reset
[2 * i
]);
1465 while (rtl8380_sds_release_reset
[2 * i
]) {
1466 sw_w32(rtl8380_sds_release_reset
[2 * i
+ 1], rtl8380_sds_release_reset
[2 * i
]);
1470 pr_info("SDS power down value now: %x\n", sw_r32(RTL838X_SDS_CFG_REG
));
1471 sw_w32(sds_conf_value
, RTL838X_SDS_CFG_REG
);
1473 pr_info("Configuration of SERDES done\n");
1477 static int rtl8390_configure_serdes(struct phy_device
*phydev
)
1479 phydev_info(phydev
, "Detected internal RTL8390 SERDES\n");
1481 /* In autoneg state, force link, set SR4_CFG_EN_LINK_FIB1G */
1482 sw_w32_mask(0, 1 << 18, RTL839X_SDS12_13_XSG0
+ 0x0a);
1484 /* Disable EEE: Clear FRE16_EEE_RSG_FIB1G, FRE16_EEE_STD_FIB1G,
1485 * FRE16_C1_PWRSAV_EN_FIB1G, FRE16_C2_PWRSAV_EN_FIB1G
1486 * and FRE16_EEE_QUIET_FIB1G
1488 sw_w32_mask(0x1f << 10, 0, RTL839X_SDS12_13_XSG0
+ 0xe0);
1493 int rtl9300_configure_serdes(struct phy_device
*phydev
)
1495 struct device
*dev
= &phydev
->mdio
.dev
;
1496 int phy_addr
= phydev
->mdio
.addr
;
1500 phydev_info(phydev
, "Configuring internal RTL9300 SERDES\n");
1510 dev_err(dev
, "Not a SerDes PHY\n");
1514 /* Set default Medium to fibre */
1515 v
= rtl930x_read_sds_phy(sds_num
, 0x1f, 11);
1517 dev_err(dev
, "Cannot access SerDes PHY %d\n", phy_addr
);
1521 rtl930x_write_sds_phy(sds_num
, 0x1f, 11, v
);
1523 // TODO: this needs to be configurable via ethtool/.dts
1524 pr_info("Setting 10G/1000BX auto fibre medium\n");
1525 rtl9300_sds_rst(sds_num
, 0x1b);
1527 // TODO: Apply patch set for fibre type
1532 static int rtl8214fc_phy_probe(struct phy_device
*phydev
)
1534 struct device
*dev
= &phydev
->mdio
.dev
;
1535 struct rtl838x_phy_priv
*priv
;
1536 int addr
= phydev
->mdio
.addr
;
1538 /* 839x has internal SerDes */
1539 if (soc_info
.id
== 0x8393)
1542 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1546 priv
->name
= "RTL8214FC";
1548 /* All base addresses of the PHYs start at multiples of 8 */
1550 /* Configuration must be done whil patching still possible */
1551 return rtl8380_configure_rtl8214fc(phydev
);
1556 static int rtl8214c_phy_probe(struct phy_device
*phydev
)
1558 struct device
*dev
= &phydev
->mdio
.dev
;
1559 struct rtl838x_phy_priv
*priv
;
1560 int addr
= phydev
->mdio
.addr
;
1562 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1566 priv
->name
= "RTL8214C";
1568 /* All base addresses of the PHYs start at multiples of 8 */
1570 /* Configuration must be done whil patching still possible */
1571 return rtl8380_configure_rtl8214c(phydev
);
1576 static int rtl8218b_ext_phy_probe(struct phy_device
*phydev
)
1578 struct device
*dev
= &phydev
->mdio
.dev
;
1579 struct rtl838x_phy_priv
*priv
;
1580 int addr
= phydev
->mdio
.addr
;
1582 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1586 priv
->name
= "RTL8218B (external)";
1588 /* All base addresses of the PHYs start at multiples of 8 */
1589 if (!(addr
% 8) && soc_info
.family
== RTL8380_FAMILY_ID
) {
1590 /* Configuration must be done while patching still possible */
1591 return rtl8380_configure_ext_rtl8218b(phydev
);
1596 static int rtl8218b_int_phy_probe(struct phy_device
*phydev
)
1598 struct device
*dev
= &phydev
->mdio
.dev
;
1599 struct rtl838x_phy_priv
*priv
;
1600 int addr
= phydev
->mdio
.addr
;
1602 if (soc_info
.family
!= RTL8380_FAMILY_ID
)
1607 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1611 priv
->name
= "RTL8218B (internal)";
1613 /* All base addresses of the PHYs start at multiples of 8 */
1615 /* Configuration must be done while patching still possible */
1616 return rtl8380_configure_int_rtl8218b(phydev
);
1621 static int rtl8218d_phy_probe(struct phy_device
*phydev
)
1623 struct device
*dev
= &phydev
->mdio
.dev
;
1624 struct rtl838x_phy_priv
*priv
;
1625 int addr
= phydev
->mdio
.addr
;
1627 pr_info("%s: id: %d\n", __func__
, addr
);
1628 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1632 priv
->name
= "RTL8218D";
1634 /* All base addresses of the PHYs start at multiples of 8 */
1636 /* Configuration must be done while patching still possible */
1637 // TODO: return configure_rtl8218d(phydev);
1642 static int rtl8226_phy_probe(struct phy_device
*phydev
)
1644 struct device
*dev
= &phydev
->mdio
.dev
;
1645 struct rtl838x_phy_priv
*priv
;
1646 int addr
= phydev
->mdio
.addr
;
1648 pr_info("%s: id: %d\n", __func__
, addr
);
1649 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1653 priv
->name
= "RTL8226";
1658 static int rtl838x_serdes_probe(struct phy_device
*phydev
)
1660 struct device
*dev
= &phydev
->mdio
.dev
;
1661 struct rtl838x_phy_priv
*priv
;
1662 int addr
= phydev
->mdio
.addr
;
1664 if (soc_info
.family
!= RTL8380_FAMILY_ID
)
1669 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1673 priv
->name
= "RTL8380 Serdes";
1675 /* On the RTL8380M, PHYs 24-27 connect to the internal SerDes */
1676 if (soc_info
.id
== 0x8380) {
1678 return rtl8380_configure_serdes(phydev
);
1684 static int rtl8393_serdes_probe(struct phy_device
*phydev
)
1686 struct device
*dev
= &phydev
->mdio
.dev
;
1687 struct rtl838x_phy_priv
*priv
;
1688 int addr
= phydev
->mdio
.addr
;
1690 pr_info("%s: id: %d\n", __func__
, addr
);
1691 if (soc_info
.family
!= RTL8390_FAMILY_ID
)
1697 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1701 priv
->name
= "RTL8393 Serdes";
1702 return rtl8390_configure_serdes(phydev
);
1705 static int rtl8390_serdes_probe(struct phy_device
*phydev
)
1707 struct device
*dev
= &phydev
->mdio
.dev
;
1708 struct rtl838x_phy_priv
*priv
;
1709 int addr
= phydev
->mdio
.addr
;
1711 if (soc_info
.family
!= RTL8390_FAMILY_ID
)
1717 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1721 priv
->name
= "RTL8390 Serdes";
1722 return rtl8390_configure_generic(phydev
);
1725 static int rtl9300_serdes_probe(struct phy_device
*phydev
)
1727 struct device
*dev
= &phydev
->mdio
.dev
;
1728 struct rtl838x_phy_priv
*priv
;
1729 int addr
= phydev
->mdio
.addr
;
1731 if (soc_info
.family
!= RTL9300_FAMILY_ID
)
1737 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1741 priv
->name
= "RTL9300 Serdes";
1742 return rtl9300_configure_serdes(phydev
);
1745 static struct phy_driver rtl83xx_phy_driver
[] = {
1747 PHY_ID_MATCH_MODEL(PHY_ID_RTL8214C
),
1748 .name
= "Realtek RTL8214C",
1749 .features
= PHY_GBIT_FEATURES
,
1750 .match_phy_device
= rtl8214c_match_phy_device
,
1751 .probe
= rtl8214c_phy_probe
,
1752 .suspend
= genphy_suspend
,
1753 .resume
= genphy_resume
,
1754 .set_loopback
= genphy_loopback
,
1757 PHY_ID_MATCH_MODEL(PHY_ID_RTL8214FC
),
1758 .name
= "Realtek RTL8214FC",
1759 .features
= PHY_GBIT_FIBRE_FEATURES
,
1760 .match_phy_device
= rtl8214fc_match_phy_device
,
1761 .probe
= rtl8214fc_phy_probe
,
1762 .suspend
= genphy_suspend
,
1763 .resume
= genphy_resume
,
1764 .set_loopback
= genphy_loopback
,
1765 .read_mmd
= rtl8218b_read_mmd
,
1766 .write_mmd
= rtl8218b_write_mmd
,
1767 .set_port
= rtl8214fc_set_port
,
1768 .get_port
= rtl8214fc_get_port
,
1769 .set_eee
= rtl8214fc_set_eee
,
1770 .get_eee
= rtl8214fc_get_eee
,
1773 PHY_ID_MATCH_MODEL(PHY_ID_RTL8218B_E
),
1774 .name
= "Realtek RTL8218B (external)",
1775 .features
= PHY_GBIT_FEATURES
,
1776 .match_phy_device
= rtl8218b_ext_match_phy_device
,
1777 .probe
= rtl8218b_ext_phy_probe
,
1778 .suspend
= genphy_suspend
,
1779 .resume
= genphy_resume
,
1780 .set_loopback
= genphy_loopback
,
1781 .read_mmd
= rtl8218b_read_mmd
,
1782 .write_mmd
= rtl8218b_write_mmd
,
1783 .set_eee
= rtl8218b_set_eee
,
1784 .get_eee
= rtl8218b_get_eee
,
1787 PHY_ID_MATCH_MODEL(PHY_ID_RTL8218D
),
1788 .name
= "REALTEK RTL8218D",
1789 .features
= PHY_GBIT_FEATURES
,
1790 .probe
= rtl8218d_phy_probe
,
1791 .suspend
= genphy_suspend
,
1792 .resume
= genphy_resume
,
1793 .set_loopback
= genphy_loopback
,
1795 PHY_ID_MATCH_MODEL(PHY_ID_RTL8226
),
1796 .name
= "REALTEK RTL8226",
1797 .features
= PHY_GBIT_FEATURES
,
1798 .probe
= rtl8226_phy_probe
,
1799 .suspend
= genphy_suspend
,
1800 .resume
= genphy_resume
,
1801 .set_loopback
= genphy_loopback
,
1802 .read_mmd
= rtl8226_read_mmd
,
1803 .write_mmd
= rtl8226_write_mmd
,
1804 .read_page
= rtl8226_read_page
,
1805 .write_page
= rtl8226_write_page
,
1806 .read_status
= rtl8226_read_status
,
1807 .config_aneg
= rtl8226_config_aneg
,
1810 PHY_ID_MATCH_MODEL(PHY_ID_RTL8218B_I
),
1811 .name
= "Realtek RTL8218B (internal)",
1812 .features
= PHY_GBIT_FEATURES
,
1813 .probe
= rtl8218b_int_phy_probe
,
1814 .suspend
= genphy_suspend
,
1815 .resume
= genphy_resume
,
1816 .set_loopback
= genphy_loopback
,
1817 .read_mmd
= rtl8218b_read_mmd
,
1818 .write_mmd
= rtl8218b_write_mmd
,
1819 .set_eee
= rtl8218b_set_eee
,
1820 .get_eee
= rtl8218b_get_eee
,
1823 PHY_ID_MATCH_MODEL(PHY_ID_RTL8218B_I
),
1824 .name
= "Realtek RTL8380 SERDES",
1825 .features
= PHY_GBIT_FIBRE_FEATURES
,
1826 .probe
= rtl838x_serdes_probe
,
1827 .suspend
= genphy_suspend
,
1828 .resume
= genphy_resume
,
1829 .set_loopback
= genphy_loopback
,
1830 .read_mmd
= rtl8218b_read_mmd
,
1831 .write_mmd
= rtl8218b_write_mmd
,
1832 .read_status
= rtl8380_read_status
,
1835 PHY_ID_MATCH_MODEL(PHY_ID_RTL8393_I
),
1836 .name
= "Realtek RTL8393 SERDES",
1837 .features
= PHY_GBIT_FIBRE_FEATURES
,
1838 .probe
= rtl8393_serdes_probe
,
1839 .suspend
= genphy_suspend
,
1840 .resume
= genphy_resume
,
1841 .set_loopback
= genphy_loopback
,
1842 .read_status
= rtl8393_read_status
,
1845 PHY_ID_MATCH_MODEL(PHY_ID_RTL8390_GENERIC
),
1846 .name
= "Realtek RTL8390 Generic",
1847 .features
= PHY_GBIT_FIBRE_FEATURES
,
1848 .probe
= rtl8390_serdes_probe
,
1849 .suspend
= genphy_suspend
,
1850 .resume
= genphy_resume
,
1851 .set_loopback
= genphy_loopback
,
1854 PHY_ID_MATCH_MODEL(PHY_ID_RTL9300_I
),
1855 .name
= "REALTEK RTL9300 SERDES",
1856 .features
= PHY_GBIT_FIBRE_FEATURES
,
1857 .probe
= rtl9300_serdes_probe
,
1858 .suspend
= genphy_suspend
,
1859 .resume
= genphy_resume
,
1860 .set_loopback
= genphy_loopback
,
1864 module_phy_driver(rtl83xx_phy_driver
);
1866 static struct mdio_device_id __maybe_unused rtl83xx_tbl
[] = {
1867 { PHY_ID_MATCH_MODEL(PHY_ID_RTL8214FC
) },
1871 MODULE_DEVICE_TABLE(mdio
, rtl83xx_tbl
);
1873 MODULE_AUTHOR("B. Koblitz");
1874 MODULE_DESCRIPTION("RTL83xx PHY driver");
1875 MODULE_LICENSE("GPL");