1 From 1416a9b2ba710d31954131c06d46f298e340aa2c Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Sat, 11 Jan 2025 21:50:19 +0100
4 Subject: [PATCH] net: phy: move realtek PHY driver to its own subdirectory
6 In preparation of adding a source file with hwmon support, move the
7 Realtek PHY driver to its own subdirectory and rename realtek.c to
10 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Link: https://patch.msgid.link/c566551b-c915-4e34-9b33-129a6ddd6e4c@gmail.com
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
15 drivers/net/phy/Kconfig | 5 +----
16 drivers/net/phy/Makefile | 2 +-
17 drivers/net/phy/realtek/Kconfig | 5 +++++
18 drivers/net/phy/realtek/Makefile | 3 +++
19 drivers/net/phy/{realtek.c => realtek/realtek_main.c} | 0
20 5 files changed, 10 insertions(+), 5 deletions(-)
21 create mode 100644 drivers/net/phy/realtek/Kconfig
22 create mode 100644 drivers/net/phy/realtek/Makefile
23 rename drivers/net/phy/{realtek.c => realtek/realtek_main.c} (100%)
25 --- a/drivers/net/phy/Kconfig
26 +++ b/drivers/net/phy/Kconfig
27 @@ -325,10 +325,7 @@ config QSEMI_PHY
29 Currently supports the qs6612
32 - tristate "Realtek PHYs"
34 - Supports the Realtek 821x PHY.
35 +source "drivers/net/phy/realtek/Kconfig"
38 tristate "Renesas PHYs"
39 --- a/drivers/net/phy/Makefile
40 +++ b/drivers/net/phy/Makefile
41 @@ -83,7 +83,7 @@ obj-$(CONFIG_NXP_CBTX_PHY) += nxp-cbtx.o
42 obj-$(CONFIG_NXP_TJA11XX_PHY) += nxp-tja11xx.o
44 obj-$(CONFIG_QSEMI_PHY) += qsemi.o
45 -obj-$(CONFIG_REALTEK_PHY) += realtek.o
46 +obj-$(CONFIG_REALTEK_PHY) += realtek/
47 obj-$(CONFIG_RENESAS_PHY) += uPD60620.o
48 obj-$(CONFIG_ROCKCHIP_PHY) += rockchip.o
49 obj-$(CONFIG_SMSC_PHY) += smsc.o
51 +++ b/drivers/net/phy/realtek/Kconfig
53 +# SPDX-License-Identifier: GPL-2.0-only
55 + tristate "Realtek PHYs"
57 + Currently supports RTL821x/RTL822x and fast ethernet PHYs
59 +++ b/drivers/net/phy/realtek/Makefile
61 +# SPDX-License-Identifier: GPL-2.0
62 +realtek-y += realtek_main.o
63 +obj-$(CONFIG_REALTEK_PHY) += realtek.o
64 --- a/drivers/net/phy/realtek.c
67 -// SPDX-License-Identifier: GPL-2.0+
68 -/* drivers/net/phy/realtek.c
70 - * Driver for Realtek PHYs
72 - * Author: Johnson Leung <r58129@freescale.com>
74 - * Copyright (c) 2004 Freescale Semiconductor, Inc.
76 -#include <linux/bitops.h>
77 -#include <linux/of.h>
78 -#include <linux/phy.h>
79 -#include <linux/module.h>
80 -#include <linux/delay.h>
81 -#include <linux/clk.h>
83 -#define RTL821x_PHYSR 0x11
84 -#define RTL821x_PHYSR_DUPLEX BIT(13)
85 -#define RTL821x_PHYSR_SPEED GENMASK(15, 14)
87 -#define RTL821x_INER 0x12
88 -#define RTL8211B_INER_INIT 0x6400
89 -#define RTL8211E_INER_LINK_STATUS BIT(10)
90 -#define RTL8211F_INER_LINK_STATUS BIT(4)
92 -#define RTL821x_INSR 0x13
94 -#define RTL821x_EXT_PAGE_SELECT 0x1e
95 -#define RTL821x_PAGE_SELECT 0x1f
97 -#define RTL8211F_PHYCR1 0x18
98 -#define RTL8211F_PHYCR2 0x19
99 -#define RTL8211F_INSR 0x1d
101 -#define RTL8211F_LEDCR 0x10
102 -#define RTL8211F_LEDCR_MODE BIT(15)
103 -#define RTL8211F_LEDCR_ACT_TXRX BIT(4)
104 -#define RTL8211F_LEDCR_LINK_1000 BIT(3)
105 -#define RTL8211F_LEDCR_LINK_100 BIT(1)
106 -#define RTL8211F_LEDCR_LINK_10 BIT(0)
107 -#define RTL8211F_LEDCR_MASK GENMASK(4, 0)
108 -#define RTL8211F_LEDCR_SHIFT 5
110 -#define RTL8211F_TX_DELAY BIT(8)
111 -#define RTL8211F_RX_DELAY BIT(3)
113 -#define RTL8211F_ALDPS_PLL_OFF BIT(1)
114 -#define RTL8211F_ALDPS_ENABLE BIT(2)
115 -#define RTL8211F_ALDPS_XTAL_OFF BIT(12)
117 -#define RTL8211E_CTRL_DELAY BIT(13)
118 -#define RTL8211E_TX_DELAY BIT(12)
119 -#define RTL8211E_RX_DELAY BIT(11)
121 -#define RTL8211F_CLKOUT_EN BIT(0)
123 -#define RTL8201F_ISR 0x1e
124 -#define RTL8201F_ISR_ANERR BIT(15)
125 -#define RTL8201F_ISR_DUPLEX BIT(13)
126 -#define RTL8201F_ISR_LINK BIT(11)
127 -#define RTL8201F_ISR_MASK (RTL8201F_ISR_ANERR | \
128 - RTL8201F_ISR_DUPLEX | \
130 -#define RTL8201F_IER 0x13
132 -#define RTL822X_VND1_SERDES_OPTION 0x697a
133 -#define RTL822X_VND1_SERDES_OPTION_MODE_MASK GENMASK(5, 0)
134 -#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII 0
135 -#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX 2
137 -#define RTL822X_VND1_SERDES_CTRL3 0x7580
138 -#define RTL822X_VND1_SERDES_CTRL3_MODE_MASK GENMASK(5, 0)
139 -#define RTL822X_VND1_SERDES_CTRL3_MODE_SGMII 0x02
140 -#define RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX 0x16
142 -/* RTL822X_VND2_XXXXX registers are only accessible when phydev->is_c45
143 - * is set, they cannot be accessed by C45-over-C22.
145 -#define RTL822X_VND2_GBCR 0xa412
147 -#define RTL822X_VND2_GANLPAR 0xa414
149 -#define RTL8366RB_POWER_SAVE 0x15
150 -#define RTL8366RB_POWER_SAVE_ON BIT(12)
152 -#define RTL9000A_GINMR 0x14
153 -#define RTL9000A_GINMR_LINK_STATUS BIT(4)
155 -#define RTL_VND2_PHYSR 0xa434
156 -#define RTL_VND2_PHYSR_DUPLEX BIT(3)
157 -#define RTL_VND2_PHYSR_SPEEDL GENMASK(5, 4)
158 -#define RTL_VND2_PHYSR_SPEEDH GENMASK(10, 9)
159 -#define RTL_VND2_PHYSR_MASTER BIT(11)
160 -#define RTL_VND2_PHYSR_SPEED_MASK (RTL_VND2_PHYSR_SPEEDL | RTL_VND2_PHYSR_SPEEDH)
162 -#define RTL_GENERIC_PHYID 0x001cc800
163 -#define RTL_8211FVD_PHYID 0x001cc878
164 -#define RTL_8221B 0x001cc840
165 -#define RTL_8221B_VB_CG 0x001cc849
166 -#define RTL_8221B_VN_CG 0x001cc84a
167 -#define RTL_8251B 0x001cc862
169 -#define RTL8211F_LED_COUNT 3
171 -MODULE_DESCRIPTION("Realtek PHY driver");
172 -MODULE_AUTHOR("Johnson Leung");
173 -MODULE_LICENSE("GPL");
175 -struct rtl821x_priv {
182 -static int rtl821x_read_page(struct phy_device *phydev)
184 - return __phy_read(phydev, RTL821x_PAGE_SELECT);
187 -static int rtl821x_write_page(struct phy_device *phydev, int page)
189 - return __phy_write(phydev, RTL821x_PAGE_SELECT, page);
192 -static int rtl821x_probe(struct phy_device *phydev)
194 - struct device *dev = &phydev->mdio.dev;
195 - struct rtl821x_priv *priv;
196 - u32 phy_id = phydev->drv->phy_id;
199 - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
203 - priv->clk = devm_clk_get_optional_enabled(dev, NULL);
204 - if (IS_ERR(priv->clk))
205 - return dev_err_probe(dev, PTR_ERR(priv->clk),
206 - "failed to get phy clock\n");
208 - ret = phy_read_paged(phydev, 0xa43, RTL8211F_PHYCR1);
212 - priv->phycr1 = ret & (RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF);
213 - if (of_property_read_bool(dev->of_node, "realtek,aldps-enable"))
214 - priv->phycr1 |= RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF;
216 - priv->has_phycr2 = !(phy_id == RTL_8211FVD_PHYID);
217 - if (priv->has_phycr2) {
218 - ret = phy_read_paged(phydev, 0xa43, RTL8211F_PHYCR2);
222 - priv->phycr2 = ret & RTL8211F_CLKOUT_EN;
223 - if (of_property_read_bool(dev->of_node, "realtek,clkout-disable"))
224 - priv->phycr2 &= ~RTL8211F_CLKOUT_EN;
227 - phydev->priv = priv;
232 -static int rtl8201_ack_interrupt(struct phy_device *phydev)
236 - err = phy_read(phydev, RTL8201F_ISR);
238 - return (err < 0) ? err : 0;
241 -static int rtl821x_ack_interrupt(struct phy_device *phydev)
245 - err = phy_read(phydev, RTL821x_INSR);
247 - return (err < 0) ? err : 0;
250 -static int rtl8211f_ack_interrupt(struct phy_device *phydev)
254 - err = phy_read_paged(phydev, 0xa43, RTL8211F_INSR);
256 - return (err < 0) ? err : 0;
259 -static int rtl8201_config_intr(struct phy_device *phydev)
264 - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
265 - err = rtl8201_ack_interrupt(phydev);
269 - val = BIT(13) | BIT(12) | BIT(11);
270 - err = phy_write_paged(phydev, 0x7, RTL8201F_IER, val);
273 - err = phy_write_paged(phydev, 0x7, RTL8201F_IER, val);
277 - err = rtl8201_ack_interrupt(phydev);
283 -static int rtl8211b_config_intr(struct phy_device *phydev)
287 - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
288 - err = rtl821x_ack_interrupt(phydev);
292 - err = phy_write(phydev, RTL821x_INER,
293 - RTL8211B_INER_INIT);
295 - err = phy_write(phydev, RTL821x_INER, 0);
299 - err = rtl821x_ack_interrupt(phydev);
305 -static int rtl8211e_config_intr(struct phy_device *phydev)
309 - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
310 - err = rtl821x_ack_interrupt(phydev);
314 - err = phy_write(phydev, RTL821x_INER,
315 - RTL8211E_INER_LINK_STATUS);
317 - err = phy_write(phydev, RTL821x_INER, 0);
321 - err = rtl821x_ack_interrupt(phydev);
327 -static int rtl8211f_config_intr(struct phy_device *phydev)
332 - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
333 - err = rtl8211f_ack_interrupt(phydev);
337 - val = RTL8211F_INER_LINK_STATUS;
338 - err = phy_write_paged(phydev, 0xa42, RTL821x_INER, val);
341 - err = phy_write_paged(phydev, 0xa42, RTL821x_INER, val);
345 - err = rtl8211f_ack_interrupt(phydev);
351 -static irqreturn_t rtl8201_handle_interrupt(struct phy_device *phydev)
355 - irq_status = phy_read(phydev, RTL8201F_ISR);
356 - if (irq_status < 0) {
361 - if (!(irq_status & RTL8201F_ISR_MASK))
364 - phy_trigger_machine(phydev);
366 - return IRQ_HANDLED;
369 -static irqreturn_t rtl821x_handle_interrupt(struct phy_device *phydev)
371 - int irq_status, irq_enabled;
373 - irq_status = phy_read(phydev, RTL821x_INSR);
374 - if (irq_status < 0) {
379 - irq_enabled = phy_read(phydev, RTL821x_INER);
380 - if (irq_enabled < 0) {
385 - if (!(irq_status & irq_enabled))
388 - phy_trigger_machine(phydev);
390 - return IRQ_HANDLED;
393 -static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev)
397 - irq_status = phy_read_paged(phydev, 0xa43, RTL8211F_INSR);
398 - if (irq_status < 0) {
403 - if (!(irq_status & RTL8211F_INER_LINK_STATUS))
406 - phy_trigger_machine(phydev);
408 - return IRQ_HANDLED;
411 -static int rtl8211_config_aneg(struct phy_device *phydev)
415 - ret = genphy_config_aneg(phydev);
419 - /* Quirk was copied from vendor driver. Unfortunately it includes no
420 - * description of the magic numbers.
422 - if (phydev->speed == SPEED_100 && phydev->autoneg == AUTONEG_DISABLE) {
423 - phy_write(phydev, 0x17, 0x2138);
424 - phy_write(phydev, 0x0e, 0x0260);
426 - phy_write(phydev, 0x17, 0x2108);
427 - phy_write(phydev, 0x0e, 0x0000);
433 -static int rtl8211c_config_init(struct phy_device *phydev)
435 - /* RTL8211C has an issue when operating in Gigabit slave mode */
436 - return phy_set_bits(phydev, MII_CTRL1000,
437 - CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
440 -static int rtl8211f_config_init(struct phy_device *phydev)
442 - struct rtl821x_priv *priv = phydev->priv;
443 - struct device *dev = &phydev->mdio.dev;
444 - u16 val_txdly, val_rxdly;
447 - ret = phy_modify_paged_changed(phydev, 0xa43, RTL8211F_PHYCR1,
448 - RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF,
451 - dev_err(dev, "aldps mode configuration failed: %pe\n",
456 - switch (phydev->interface) {
457 - case PHY_INTERFACE_MODE_RGMII:
462 - case PHY_INTERFACE_MODE_RGMII_RXID:
464 - val_rxdly = RTL8211F_RX_DELAY;
467 - case PHY_INTERFACE_MODE_RGMII_TXID:
468 - val_txdly = RTL8211F_TX_DELAY;
472 - case PHY_INTERFACE_MODE_RGMII_ID:
473 - val_txdly = RTL8211F_TX_DELAY;
474 - val_rxdly = RTL8211F_RX_DELAY;
477 - default: /* the rest of the modes imply leaving delay as is. */
481 - ret = phy_modify_paged_changed(phydev, 0xd08, 0x11, RTL8211F_TX_DELAY,
484 - dev_err(dev, "Failed to update the TX delay register\n");
488 - "%s 2ns TX delay (and changing the value from pin-strapping RXD1 or the bootloader)\n",
489 - val_txdly ? "Enabling" : "Disabling");
492 - "2ns TX delay was already %s (by pin-strapping RXD1 or bootloader configuration)\n",
493 - val_txdly ? "enabled" : "disabled");
496 - ret = phy_modify_paged_changed(phydev, 0xd08, 0x15, RTL8211F_RX_DELAY,
499 - dev_err(dev, "Failed to update the RX delay register\n");
503 - "%s 2ns RX delay (and changing the value from pin-strapping RXD0 or the bootloader)\n",
504 - val_rxdly ? "Enabling" : "Disabling");
507 - "2ns RX delay was already %s (by pin-strapping RXD0 or bootloader configuration)\n",
508 - val_rxdly ? "enabled" : "disabled");
511 - if (priv->has_phycr2) {
512 - ret = phy_modify_paged(phydev, 0xa43, RTL8211F_PHYCR2,
513 - RTL8211F_CLKOUT_EN, priv->phycr2);
515 - dev_err(dev, "clkout configuration failed: %pe\n",
520 - return genphy_soft_reset(phydev);
526 -static int rtl821x_suspend(struct phy_device *phydev)
528 - struct rtl821x_priv *priv = phydev->priv;
531 - if (!phydev->wol_enabled) {
532 - ret = genphy_suspend(phydev);
537 - clk_disable_unprepare(priv->clk);
543 -static int rtl821x_resume(struct phy_device *phydev)
545 - struct rtl821x_priv *priv = phydev->priv;
548 - if (!phydev->wol_enabled)
549 - clk_prepare_enable(priv->clk);
551 - ret = genphy_resume(phydev);
560 -static int rtl8211f_led_hw_is_supported(struct phy_device *phydev, u8 index,
561 - unsigned long rules)
563 - const unsigned long mask = BIT(TRIGGER_NETDEV_LINK_10) |
564 - BIT(TRIGGER_NETDEV_LINK_100) |
565 - BIT(TRIGGER_NETDEV_LINK_1000) |
566 - BIT(TRIGGER_NETDEV_RX) |
567 - BIT(TRIGGER_NETDEV_TX);
569 - /* The RTL8211F PHY supports these LED settings on up to three LEDs:
570 - * - Link: Configurable subset of 10/100/1000 link rates
571 - * - Active: Blink on activity, RX or TX is not differentiated
572 - * The Active option has two modes, A and B:
573 - * - A: Link and Active indication at configurable, but matching,
574 - * subset of 10/100/1000 link rates
575 - * - B: Link indication at configurable subset of 10/100/1000 link
576 - * rates and Active indication always at all three 10+100+1000
578 - * This code currently uses mode B only.
581 - if (index >= RTL8211F_LED_COUNT)
584 - /* Filter out any other unsupported triggers. */
586 - return -EOPNOTSUPP;
588 - /* RX and TX are not differentiated, either both are set or not set. */
589 - if (!(rules & BIT(TRIGGER_NETDEV_RX)) ^ !(rules & BIT(TRIGGER_NETDEV_TX)))
590 - return -EOPNOTSUPP;
595 -static int rtl8211f_led_hw_control_get(struct phy_device *phydev, u8 index,
596 - unsigned long *rules)
600 - if (index >= RTL8211F_LED_COUNT)
603 - val = phy_read_paged(phydev, 0xd04, RTL8211F_LEDCR);
607 - val >>= RTL8211F_LEDCR_SHIFT * index;
608 - val &= RTL8211F_LEDCR_MASK;
610 - if (val & RTL8211F_LEDCR_LINK_10)
611 - set_bit(TRIGGER_NETDEV_LINK_10, rules);
613 - if (val & RTL8211F_LEDCR_LINK_100)
614 - set_bit(TRIGGER_NETDEV_LINK_100, rules);
616 - if (val & RTL8211F_LEDCR_LINK_1000)
617 - set_bit(TRIGGER_NETDEV_LINK_1000, rules);
619 - if (val & RTL8211F_LEDCR_ACT_TXRX) {
620 - set_bit(TRIGGER_NETDEV_RX, rules);
621 - set_bit(TRIGGER_NETDEV_TX, rules);
627 -static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index,
628 - unsigned long rules)
630 - const u16 mask = RTL8211F_LEDCR_MASK << (RTL8211F_LEDCR_SHIFT * index);
633 - if (index >= RTL8211F_LED_COUNT)
636 - if (test_bit(TRIGGER_NETDEV_LINK_10, &rules))
637 - reg |= RTL8211F_LEDCR_LINK_10;
639 - if (test_bit(TRIGGER_NETDEV_LINK_100, &rules))
640 - reg |= RTL8211F_LEDCR_LINK_100;
642 - if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules))
643 - reg |= RTL8211F_LEDCR_LINK_1000;
645 - if (test_bit(TRIGGER_NETDEV_RX, &rules) ||
646 - test_bit(TRIGGER_NETDEV_TX, &rules)) {
647 - reg |= RTL8211F_LEDCR_ACT_TXRX;
650 - reg <<= RTL8211F_LEDCR_SHIFT * index;
651 - reg |= RTL8211F_LEDCR_MODE; /* Mode B */
653 - return phy_modify_paged(phydev, 0xd04, RTL8211F_LEDCR, mask, reg);
656 -static int rtl8211e_config_init(struct phy_device *phydev)
658 - int ret = 0, oldpage;
661 - /* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */
662 - switch (phydev->interface) {
663 - case PHY_INTERFACE_MODE_RGMII:
664 - val = RTL8211E_CTRL_DELAY | 0;
666 - case PHY_INTERFACE_MODE_RGMII_ID:
667 - val = RTL8211E_CTRL_DELAY | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY;
669 - case PHY_INTERFACE_MODE_RGMII_RXID:
670 - val = RTL8211E_CTRL_DELAY | RTL8211E_RX_DELAY;
672 - case PHY_INTERFACE_MODE_RGMII_TXID:
673 - val = RTL8211E_CTRL_DELAY | RTL8211E_TX_DELAY;
675 - default: /* the rest of the modes imply leaving delays as is. */
679 - /* According to a sample driver there is a 0x1c config register on the
680 - * 0xa4 extension page (0x7) layout. It can be used to disable/enable
681 - * the RX/TX delays otherwise controlled by RXDLY/TXDLY pins.
682 - * The configuration register definition:
684 - * 13 = Force Tx RX Delay controlled by bit12 bit11,
685 - * 12 = RX Delay, 11 = TX Delay
686 - * 10:0 = Test && debug settings reserved by realtek
688 - oldpage = phy_select_page(phydev, 0x7);
690 - goto err_restore_page;
692 - ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4);
694 - goto err_restore_page;
696 - ret = __phy_modify(phydev, 0x1c, RTL8211E_CTRL_DELAY
697 - | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY,
701 - return phy_restore_page(phydev, oldpage, ret);
704 -static int rtl8211b_suspend(struct phy_device *phydev)
706 - phy_write(phydev, MII_MMD_DATA, BIT(9));
708 - return genphy_suspend(phydev);
711 -static int rtl8211b_resume(struct phy_device *phydev)
713 - phy_write(phydev, MII_MMD_DATA, 0);
715 - return genphy_resume(phydev);
718 -static int rtl8366rb_config_init(struct phy_device *phydev)
722 - ret = phy_set_bits(phydev, RTL8366RB_POWER_SAVE,
723 - RTL8366RB_POWER_SAVE_ON);
725 - dev_err(&phydev->mdio.dev,
726 - "error enabling power management\n");
732 -/* get actual speed to cover the downshift case */
733 -static void rtlgen_decode_physr(struct phy_device *phydev, int val)
739 - if (val & RTL_VND2_PHYSR_DUPLEX)
740 - phydev->duplex = DUPLEX_FULL;
742 - phydev->duplex = DUPLEX_HALF;
744 - switch (val & RTL_VND2_PHYSR_SPEED_MASK) {
746 - phydev->speed = SPEED_10;
749 - phydev->speed = SPEED_100;
752 - phydev->speed = SPEED_1000;
755 - phydev->speed = SPEED_10000;
758 - phydev->speed = SPEED_2500;
761 - phydev->speed = SPEED_5000;
771 - if (phydev->speed >= 1000) {
772 - if (val & RTL_VND2_PHYSR_MASTER)
773 - phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
775 - phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
777 - phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED;
781 -static int rtlgen_read_status(struct phy_device *phydev)
785 - ret = genphy_read_status(phydev);
792 - val = phy_read_paged(phydev, 0xa43, 0x12);
796 - rtlgen_decode_physr(phydev, val);
801 -static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
805 - if (devnum == MDIO_MMD_VEND2) {
806 - rtl821x_write_page(phydev, regnum >> 4);
807 - ret = __phy_read(phydev, 0x10 + ((regnum & 0xf) >> 1));
808 - rtl821x_write_page(phydev, 0);
809 - } else if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE) {
810 - rtl821x_write_page(phydev, 0xa5c);
811 - ret = __phy_read(phydev, 0x12);
812 - rtl821x_write_page(phydev, 0);
813 - } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
814 - rtl821x_write_page(phydev, 0xa5d);
815 - ret = __phy_read(phydev, 0x10);
816 - rtl821x_write_page(phydev, 0);
817 - } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_LPABLE) {
818 - rtl821x_write_page(phydev, 0xa5d);
819 - ret = __phy_read(phydev, 0x11);
820 - rtl821x_write_page(phydev, 0);
828 -static int rtlgen_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
833 - if (devnum == MDIO_MMD_VEND2) {
834 - rtl821x_write_page(phydev, regnum >> 4);
835 - ret = __phy_write(phydev, 0x10 + ((regnum & 0xf) >> 1), val);
836 - rtl821x_write_page(phydev, 0);
837 - } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
838 - rtl821x_write_page(phydev, 0xa5d);
839 - ret = __phy_write(phydev, 0x10, val);
840 - rtl821x_write_page(phydev, 0);
848 -static int rtl822x_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
850 - int ret = rtlgen_read_mmd(phydev, devnum, regnum);
852 - if (ret != -EOPNOTSUPP)
855 - if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE2) {
856 - rtl821x_write_page(phydev, 0xa6e);
857 - ret = __phy_read(phydev, 0x16);
858 - rtl821x_write_page(phydev, 0);
859 - } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV2) {
860 - rtl821x_write_page(phydev, 0xa6d);
861 - ret = __phy_read(phydev, 0x12);
862 - rtl821x_write_page(phydev, 0);
863 - } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_LPABLE2) {
864 - rtl821x_write_page(phydev, 0xa6d);
865 - ret = __phy_read(phydev, 0x10);
866 - rtl821x_write_page(phydev, 0);
872 -static int rtl822x_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
875 - int ret = rtlgen_write_mmd(phydev, devnum, regnum, val);
877 - if (ret != -EOPNOTSUPP)
880 - if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV2) {
881 - rtl821x_write_page(phydev, 0xa6d);
882 - ret = __phy_write(phydev, 0x12, val);
883 - rtl821x_write_page(phydev, 0);
889 -static int rtl822xb_config_init(struct phy_device *phydev)
891 - bool has_2500, has_sgmii;
895 - has_2500 = test_bit(PHY_INTERFACE_MODE_2500BASEX,
896 - phydev->host_interfaces) ||
897 - phydev->interface == PHY_INTERFACE_MODE_2500BASEX;
899 - has_sgmii = test_bit(PHY_INTERFACE_MODE_SGMII,
900 - phydev->host_interfaces) ||
901 - phydev->interface == PHY_INTERFACE_MODE_SGMII;
903 - /* fill in possible interfaces */
904 - __assign_bit(PHY_INTERFACE_MODE_2500BASEX, phydev->possible_interfaces,
906 - __assign_bit(PHY_INTERFACE_MODE_SGMII, phydev->possible_interfaces,
909 - if (!has_2500 && !has_sgmii)
912 - /* determine SerDes option mode */
913 - if (has_2500 && !has_sgmii) {
914 - mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX;
915 - phydev->rate_matching = RATE_MATCH_PAUSE;
917 - mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII;
918 - phydev->rate_matching = RATE_MATCH_NONE;
921 - /* the following sequence with magic numbers sets up the SerDes
924 - ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x75f3, 0);
928 - ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND1,
929 - RTL822X_VND1_SERDES_OPTION,
930 - RTL822X_VND1_SERDES_OPTION_MODE_MASK,
935 - ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6a04, 0x0503);
939 - ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f10, 0xd455);
943 - return phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f11, 0x8020);
946 -static int rtl822xb_get_rate_matching(struct phy_device *phydev,
947 - phy_interface_t iface)
951 - /* Only rate matching at 2500base-x */
952 - if (iface != PHY_INTERFACE_MODE_2500BASEX)
953 - return RATE_MATCH_NONE;
955 - val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_OPTION);
959 - if ((val & RTL822X_VND1_SERDES_OPTION_MODE_MASK) ==
960 - RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX)
961 - return RATE_MATCH_PAUSE;
963 - /* RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII */
964 - return RATE_MATCH_NONE;
967 -static int rtl822x_get_features(struct phy_device *phydev)
971 - val = phy_read_paged(phydev, 0xa61, 0x13);
975 - linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
976 - phydev->supported, val & MDIO_PMA_SPEED_2_5G);
977 - linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
978 - phydev->supported, val & MDIO_PMA_SPEED_5G);
979 - linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
980 - phydev->supported, val & MDIO_SPEED_10G);
982 - return genphy_read_abilities(phydev);
985 -static int rtl822x_config_aneg(struct phy_device *phydev)
989 - if (phydev->autoneg == AUTONEG_ENABLE) {
990 - u16 adv = linkmode_adv_to_mii_10gbt_adv_t(phydev->advertising);
992 - ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
993 - MDIO_AN_10GBT_CTRL_ADV2_5G |
994 - MDIO_AN_10GBT_CTRL_ADV5G,
1000 - return __genphy_config_aneg(phydev, ret);
1003 -static void rtl822xb_update_interface(struct phy_device *phydev)
1007 - if (!phydev->link)
1010 - /* Change interface according to serdes mode */
1011 - val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_CTRL3);
1015 - switch (val & RTL822X_VND1_SERDES_CTRL3_MODE_MASK) {
1016 - case RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX:
1017 - phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
1019 - case RTL822X_VND1_SERDES_CTRL3_MODE_SGMII:
1020 - phydev->interface = PHY_INTERFACE_MODE_SGMII;
1025 -static int rtl822x_read_status(struct phy_device *phydev)
1029 - ret = rtlgen_read_status(phydev);
1033 - if (phydev->autoneg == AUTONEG_DISABLE ||
1034 - !phydev->autoneg_complete) {
1035 - mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
1039 - lpadv = phy_read_paged(phydev, 0xa5d, 0x13);
1043 - mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, lpadv);
1048 -static int rtl822xb_read_status(struct phy_device *phydev)
1052 - ret = rtl822x_read_status(phydev);
1056 - rtl822xb_update_interface(phydev);
1061 -static int rtl822x_c45_get_features(struct phy_device *phydev)
1063 - linkmode_set_bit(ETHTOOL_LINK_MODE_TP_BIT,
1064 - phydev->supported);
1066 - return genphy_c45_pma_read_abilities(phydev);
1069 -static int rtl822x_c45_config_aneg(struct phy_device *phydev)
1071 - bool changed = false;
1074 - if (phydev->autoneg == AUTONEG_DISABLE)
1075 - return genphy_c45_pma_setup_forced(phydev);
1077 - ret = genphy_c45_an_config_aneg(phydev);
1083 - val = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
1085 - /* Vendor register as C45 has no standardized support for 1000BaseT */
1086 - ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, RTL822X_VND2_GBCR,
1087 - ADVERTISE_1000FULL, val);
1093 - return genphy_c45_check_and_restart_aneg(phydev, changed);
1096 -static int rtl822x_c45_read_status(struct phy_device *phydev)
1100 - ret = genphy_c45_read_status(phydev);
1104 - if (phydev->autoneg == AUTONEG_DISABLE ||
1105 - !genphy_c45_aneg_done(phydev))
1106 - mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
1108 - /* Vendor register as C45 has no standardized support for 1000BaseT */
1109 - if (phydev->autoneg == AUTONEG_ENABLE) {
1110 - val = phy_read_mmd(phydev, MDIO_MMD_VEND2,
1111 - RTL822X_VND2_GANLPAR);
1115 - mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
1118 - if (!phydev->link)
1121 - /* Read actual speed from vendor register. */
1122 - val = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL_VND2_PHYSR);
1126 - rtlgen_decode_physr(phydev, val);
1131 -static int rtl822xb_c45_read_status(struct phy_device *phydev)
1135 - ret = rtl822x_c45_read_status(phydev);
1139 - rtl822xb_update_interface(phydev);
1144 -static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
1148 - phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61);
1149 - val = phy_read(phydev, 0x13);
1150 - phy_write(phydev, RTL821x_PAGE_SELECT, 0);
1152 - return val >= 0 && val & MDIO_PMA_SPEED_2_5G;
1155 -/* On internal PHY's MMD reads over C22 always return 0.
1156 - * Check a MMD register which is known to be non-zero.
1158 -static bool rtlgen_supports_mmd(struct phy_device *phydev)
1162 - phy_lock_mdio_bus(phydev);
1163 - __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS);
1164 - __phy_write(phydev, MII_MMD_DATA, MDIO_PCS_EEE_ABLE);
1165 - __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS | MII_MMD_CTRL_NOINCR);
1166 - val = __phy_read(phydev, MII_MMD_DATA);
1167 - phy_unlock_mdio_bus(phydev);
1172 -static int rtlgen_match_phy_device(struct phy_device *phydev)
1174 - return phydev->phy_id == RTL_GENERIC_PHYID &&
1175 - !rtlgen_supports_2_5gbps(phydev);
1178 -static int rtl8226_match_phy_device(struct phy_device *phydev)
1180 - return phydev->phy_id == RTL_GENERIC_PHYID &&
1181 - rtlgen_supports_2_5gbps(phydev) &&
1182 - rtlgen_supports_mmd(phydev);
1185 -static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,
1188 - if (phydev->is_c45)
1189 - return is_c45 && (id == phydev->c45_ids.device_ids[1]);
1191 - return !is_c45 && (id == phydev->phy_id);
1194 -static int rtl8221b_match_phy_device(struct phy_device *phydev)
1196 - return phydev->phy_id == RTL_8221B && rtlgen_supports_mmd(phydev);
1199 -static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev)
1201 - return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false);
1204 -static int rtl8221b_vb_cg_c45_match_phy_device(struct phy_device *phydev)
1206 - return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, true);
1209 -static int rtl8221b_vn_cg_c22_match_phy_device(struct phy_device *phydev)
1211 - return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, false);
1214 -static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev)
1216 - return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true);
1219 -static int rtl_internal_nbaset_match_phy_device(struct phy_device *phydev)
1221 - if (phydev->is_c45)
1224 - switch (phydev->phy_id) {
1225 - case RTL_GENERIC_PHYID:
1234 - return rtlgen_supports_2_5gbps(phydev) && !rtlgen_supports_mmd(phydev);
1237 -static int rtl8251b_c45_match_phy_device(struct phy_device *phydev)
1239 - return rtlgen_is_c45_match(phydev, RTL_8251B, true);
1242 -static int rtlgen_resume(struct phy_device *phydev)
1244 - int ret = genphy_resume(phydev);
1246 - /* Internal PHY's from RTL8168h up may not be instantly ready */
1252 -static int rtlgen_c45_resume(struct phy_device *phydev)
1254 - int ret = genphy_c45_pma_resume(phydev);
1261 -static int rtl9000a_config_init(struct phy_device *phydev)
1263 - phydev->autoneg = AUTONEG_DISABLE;
1264 - phydev->speed = SPEED_100;
1265 - phydev->duplex = DUPLEX_FULL;
1270 -static int rtl9000a_config_aneg(struct phy_device *phydev)
1275 - switch (phydev->master_slave_set) {
1276 - case MASTER_SLAVE_CFG_MASTER_FORCE:
1277 - ctl |= CTL1000_AS_MASTER;
1279 - case MASTER_SLAVE_CFG_SLAVE_FORCE:
1281 - case MASTER_SLAVE_CFG_UNKNOWN:
1282 - case MASTER_SLAVE_CFG_UNSUPPORTED:
1285 - phydev_warn(phydev, "Unsupported Master/Slave mode\n");
1286 - return -EOPNOTSUPP;
1289 - ret = phy_modify_changed(phydev, MII_CTRL1000, CTL1000_AS_MASTER, ctl);
1291 - ret = genphy_soft_reset(phydev);
1296 -static int rtl9000a_read_status(struct phy_device *phydev)
1300 - phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN;
1301 - phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
1303 - ret = genphy_update_link(phydev);
1307 - ret = phy_read(phydev, MII_CTRL1000);
1310 - if (ret & CTL1000_AS_MASTER)
1311 - phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
1313 - phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_FORCE;
1315 - ret = phy_read(phydev, MII_STAT1000);
1318 - if (ret & LPA_1000MSRES)
1319 - phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
1321 - phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
1326 -static int rtl9000a_ack_interrupt(struct phy_device *phydev)
1330 - err = phy_read(phydev, RTL8211F_INSR);
1332 - return (err < 0) ? err : 0;
1335 -static int rtl9000a_config_intr(struct phy_device *phydev)
1340 - if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1341 - err = rtl9000a_ack_interrupt(phydev);
1345 - val = (u16)~RTL9000A_GINMR_LINK_STATUS;
1346 - err = phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
1349 - err = phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
1353 - err = rtl9000a_ack_interrupt(phydev);
1356 - return phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
1359 -static irqreturn_t rtl9000a_handle_interrupt(struct phy_device *phydev)
1363 - irq_status = phy_read(phydev, RTL8211F_INSR);
1364 - if (irq_status < 0) {
1365 - phy_error(phydev);
1369 - if (!(irq_status & RTL8211F_INER_LINK_STATUS))
1372 - phy_trigger_machine(phydev);
1374 - return IRQ_HANDLED;
1377 -static struct phy_driver realtek_drvs[] = {
1379 - PHY_ID_MATCH_EXACT(0x00008201),
1380 - .name = "RTL8201CP Ethernet",
1381 - .read_page = rtl821x_read_page,
1382 - .write_page = rtl821x_write_page,
1384 - PHY_ID_MATCH_EXACT(0x001cc816),
1385 - .name = "RTL8201F Fast Ethernet",
1386 - .config_intr = &rtl8201_config_intr,
1387 - .handle_interrupt = rtl8201_handle_interrupt,
1388 - .suspend = genphy_suspend,
1389 - .resume = genphy_resume,
1390 - .read_page = rtl821x_read_page,
1391 - .write_page = rtl821x_write_page,
1393 - PHY_ID_MATCH_MODEL(0x001cc880),
1394 - .name = "RTL8208 Fast Ethernet",
1395 - .read_mmd = genphy_read_mmd_unsupported,
1396 - .write_mmd = genphy_write_mmd_unsupported,
1397 - .suspend = genphy_suspend,
1398 - .resume = genphy_resume,
1399 - .read_page = rtl821x_read_page,
1400 - .write_page = rtl821x_write_page,
1402 - PHY_ID_MATCH_EXACT(0x001cc910),
1403 - .name = "RTL8211 Gigabit Ethernet",
1404 - .config_aneg = rtl8211_config_aneg,
1405 - .read_mmd = &genphy_read_mmd_unsupported,
1406 - .write_mmd = &genphy_write_mmd_unsupported,
1407 - .read_page = rtl821x_read_page,
1408 - .write_page = rtl821x_write_page,
1410 - PHY_ID_MATCH_EXACT(0x001cc912),
1411 - .name = "RTL8211B Gigabit Ethernet",
1412 - .config_intr = &rtl8211b_config_intr,
1413 - .handle_interrupt = rtl821x_handle_interrupt,
1414 - .read_mmd = &genphy_read_mmd_unsupported,
1415 - .write_mmd = &genphy_write_mmd_unsupported,
1416 - .suspend = rtl8211b_suspend,
1417 - .resume = rtl8211b_resume,
1418 - .read_page = rtl821x_read_page,
1419 - .write_page = rtl821x_write_page,
1421 - PHY_ID_MATCH_EXACT(0x001cc913),
1422 - .name = "RTL8211C Gigabit Ethernet",
1423 - .config_init = rtl8211c_config_init,
1424 - .read_mmd = &genphy_read_mmd_unsupported,
1425 - .write_mmd = &genphy_write_mmd_unsupported,
1426 - .read_page = rtl821x_read_page,
1427 - .write_page = rtl821x_write_page,
1429 - PHY_ID_MATCH_EXACT(0x001cc914),
1430 - .name = "RTL8211DN Gigabit Ethernet",
1431 - .config_intr = rtl8211e_config_intr,
1432 - .handle_interrupt = rtl821x_handle_interrupt,
1433 - .suspend = genphy_suspend,
1434 - .resume = genphy_resume,
1435 - .read_page = rtl821x_read_page,
1436 - .write_page = rtl821x_write_page,
1438 - PHY_ID_MATCH_EXACT(0x001cc915),
1439 - .name = "RTL8211E Gigabit Ethernet",
1440 - .config_init = &rtl8211e_config_init,
1441 - .config_intr = &rtl8211e_config_intr,
1442 - .handle_interrupt = rtl821x_handle_interrupt,
1443 - .suspend = genphy_suspend,
1444 - .resume = genphy_resume,
1445 - .read_page = rtl821x_read_page,
1446 - .write_page = rtl821x_write_page,
1448 - PHY_ID_MATCH_EXACT(0x001cc916),
1449 - .name = "RTL8211F Gigabit Ethernet",
1450 - .probe = rtl821x_probe,
1451 - .config_init = &rtl8211f_config_init,
1452 - .read_status = rtlgen_read_status,
1453 - .config_intr = &rtl8211f_config_intr,
1454 - .handle_interrupt = rtl8211f_handle_interrupt,
1455 - .suspend = rtl821x_suspend,
1456 - .resume = rtl821x_resume,
1457 - .read_page = rtl821x_read_page,
1458 - .write_page = rtl821x_write_page,
1459 - .flags = PHY_ALWAYS_CALL_SUSPEND,
1460 - .led_hw_is_supported = rtl8211f_led_hw_is_supported,
1461 - .led_hw_control_get = rtl8211f_led_hw_control_get,
1462 - .led_hw_control_set = rtl8211f_led_hw_control_set,
1464 - PHY_ID_MATCH_EXACT(RTL_8211FVD_PHYID),
1465 - .name = "RTL8211F-VD Gigabit Ethernet",
1466 - .probe = rtl821x_probe,
1467 - .config_init = &rtl8211f_config_init,
1468 - .read_status = rtlgen_read_status,
1469 - .config_intr = &rtl8211f_config_intr,
1470 - .handle_interrupt = rtl8211f_handle_interrupt,
1471 - .suspend = rtl821x_suspend,
1472 - .resume = rtl821x_resume,
1473 - .read_page = rtl821x_read_page,
1474 - .write_page = rtl821x_write_page,
1475 - .flags = PHY_ALWAYS_CALL_SUSPEND,
1477 - .name = "Generic FE-GE Realtek PHY",
1478 - .match_phy_device = rtlgen_match_phy_device,
1479 - .read_status = rtlgen_read_status,
1480 - .suspend = genphy_suspend,
1481 - .resume = rtlgen_resume,
1482 - .read_page = rtl821x_read_page,
1483 - .write_page = rtl821x_write_page,
1484 - .read_mmd = rtlgen_read_mmd,
1485 - .write_mmd = rtlgen_write_mmd,
1487 - .name = "RTL8226 2.5Gbps PHY",
1488 - .match_phy_device = rtl8226_match_phy_device,
1489 - .get_features = rtl822x_get_features,
1490 - .config_aneg = rtl822x_config_aneg,
1491 - .read_status = rtl822x_read_status,
1492 - .suspend = genphy_suspend,
1493 - .resume = rtlgen_resume,
1494 - .read_page = rtl821x_read_page,
1495 - .write_page = rtl821x_write_page,
1497 - .match_phy_device = rtl8221b_match_phy_device,
1498 - .name = "RTL8226B_RTL8221B 2.5Gbps PHY",
1499 - .get_features = rtl822x_get_features,
1500 - .config_aneg = rtl822x_config_aneg,
1501 - .config_init = rtl822xb_config_init,
1502 - .get_rate_matching = rtl822xb_get_rate_matching,
1503 - .read_status = rtl822xb_read_status,
1504 - .suspend = genphy_suspend,
1505 - .resume = rtlgen_resume,
1506 - .read_page = rtl821x_read_page,
1507 - .write_page = rtl821x_write_page,
1509 - PHY_ID_MATCH_EXACT(0x001cc838),
1510 - .name = "RTL8226-CG 2.5Gbps PHY",
1511 - .get_features = rtl822x_get_features,
1512 - .config_aneg = rtl822x_config_aneg,
1513 - .read_status = rtl822x_read_status,
1514 - .suspend = genphy_suspend,
1515 - .resume = rtlgen_resume,
1516 - .read_page = rtl821x_read_page,
1517 - .write_page = rtl821x_write_page,
1519 - PHY_ID_MATCH_EXACT(0x001cc848),
1520 - .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY",
1521 - .get_features = rtl822x_get_features,
1522 - .config_aneg = rtl822x_config_aneg,
1523 - .config_init = rtl822xb_config_init,
1524 - .get_rate_matching = rtl822xb_get_rate_matching,
1525 - .read_status = rtl822xb_read_status,
1526 - .suspend = genphy_suspend,
1527 - .resume = rtlgen_resume,
1528 - .read_page = rtl821x_read_page,
1529 - .write_page = rtl821x_write_page,
1531 - .match_phy_device = rtl8221b_vb_cg_c22_match_phy_device,
1532 - .name = "RTL8221B-VB-CG 2.5Gbps PHY (C22)",
1533 - .get_features = rtl822x_get_features,
1534 - .config_aneg = rtl822x_config_aneg,
1535 - .config_init = rtl822xb_config_init,
1536 - .get_rate_matching = rtl822xb_get_rate_matching,
1537 - .read_status = rtl822xb_read_status,
1538 - .suspend = genphy_suspend,
1539 - .resume = rtlgen_resume,
1540 - .read_page = rtl821x_read_page,
1541 - .write_page = rtl821x_write_page,
1543 - .match_phy_device = rtl8221b_vb_cg_c45_match_phy_device,
1544 - .name = "RTL8221B-VB-CG 2.5Gbps PHY (C45)",
1545 - .config_init = rtl822xb_config_init,
1546 - .get_rate_matching = rtl822xb_get_rate_matching,
1547 - .get_features = rtl822x_c45_get_features,
1548 - .config_aneg = rtl822x_c45_config_aneg,
1549 - .read_status = rtl822xb_c45_read_status,
1550 - .suspend = genphy_c45_pma_suspend,
1551 - .resume = rtlgen_c45_resume,
1553 - .match_phy_device = rtl8221b_vn_cg_c22_match_phy_device,
1554 - .name = "RTL8221B-VM-CG 2.5Gbps PHY (C22)",
1555 - .get_features = rtl822x_get_features,
1556 - .config_aneg = rtl822x_config_aneg,
1557 - .config_init = rtl822xb_config_init,
1558 - .get_rate_matching = rtl822xb_get_rate_matching,
1559 - .read_status = rtl822xb_read_status,
1560 - .suspend = genphy_suspend,
1561 - .resume = rtlgen_resume,
1562 - .read_page = rtl821x_read_page,
1563 - .write_page = rtl821x_write_page,
1565 - .match_phy_device = rtl8221b_vn_cg_c45_match_phy_device,
1566 - .name = "RTL8221B-VN-CG 2.5Gbps PHY (C45)",
1567 - .config_init = rtl822xb_config_init,
1568 - .get_rate_matching = rtl822xb_get_rate_matching,
1569 - .get_features = rtl822x_c45_get_features,
1570 - .config_aneg = rtl822x_c45_config_aneg,
1571 - .read_status = rtl822xb_c45_read_status,
1572 - .suspend = genphy_c45_pma_suspend,
1573 - .resume = rtlgen_c45_resume,
1575 - .match_phy_device = rtl8251b_c45_match_phy_device,
1576 - .name = "RTL8251B 5Gbps PHY",
1577 - .get_features = rtl822x_get_features,
1578 - .config_aneg = rtl822x_config_aneg,
1579 - .read_status = rtl822x_read_status,
1580 - .suspend = genphy_suspend,
1581 - .resume = rtlgen_resume,
1582 - .read_page = rtl821x_read_page,
1583 - .write_page = rtl821x_write_page,
1585 - .match_phy_device = rtl_internal_nbaset_match_phy_device,
1586 - .name = "Realtek Internal NBASE-T PHY",
1587 - .flags = PHY_IS_INTERNAL,
1588 - .get_features = rtl822x_get_features,
1589 - .config_aneg = rtl822x_config_aneg,
1590 - .read_status = rtl822x_read_status,
1591 - .suspend = genphy_suspend,
1592 - .resume = rtlgen_resume,
1593 - .read_page = rtl821x_read_page,
1594 - .write_page = rtl821x_write_page,
1595 - .read_mmd = rtl822x_read_mmd,
1596 - .write_mmd = rtl822x_write_mmd,
1598 - PHY_ID_MATCH_EXACT(0x001ccad0),
1599 - .name = "RTL8224 2.5Gbps PHY",
1600 - .get_features = rtl822x_c45_get_features,
1601 - .config_aneg = rtl822x_c45_config_aneg,
1602 - .read_status = rtl822x_c45_read_status,
1603 - .suspend = genphy_c45_pma_suspend,
1604 - .resume = rtlgen_c45_resume,
1606 - PHY_ID_MATCH_EXACT(0x001cc961),
1607 - .name = "RTL8366RB Gigabit Ethernet",
1608 - .config_init = &rtl8366rb_config_init,
1609 - /* These interrupts are handled by the irq controller
1610 - * embedded inside the RTL8366RB, they get unmasked when the
1611 - * irq is requested and ACKed by reading the status register,
1612 - * which is done by the irqchip code.
1614 - .config_intr = genphy_no_config_intr,
1615 - .handle_interrupt = genphy_handle_interrupt_no_ack,
1616 - .suspend = genphy_suspend,
1617 - .resume = genphy_resume,
1619 - PHY_ID_MATCH_EXACT(0x001ccb00),
1620 - .name = "RTL9000AA_RTL9000AN Ethernet",
1621 - .features = PHY_BASIC_T1_FEATURES,
1622 - .config_init = rtl9000a_config_init,
1623 - .config_aneg = rtl9000a_config_aneg,
1624 - .read_status = rtl9000a_read_status,
1625 - .config_intr = rtl9000a_config_intr,
1626 - .handle_interrupt = rtl9000a_handle_interrupt,
1627 - .suspend = genphy_suspend,
1628 - .resume = genphy_resume,
1629 - .read_page = rtl821x_read_page,
1630 - .write_page = rtl821x_write_page,
1632 - PHY_ID_MATCH_EXACT(0x001cc942),
1633 - .name = "RTL8365MB-VC Gigabit Ethernet",
1634 - /* Interrupt handling analogous to RTL8366RB */
1635 - .config_intr = genphy_no_config_intr,
1636 - .handle_interrupt = genphy_handle_interrupt_no_ack,
1637 - .suspend = genphy_suspend,
1638 - .resume = genphy_resume,
1640 - PHY_ID_MATCH_EXACT(0x001cc960),
1641 - .name = "RTL8366S Gigabit Ethernet",
1642 - .suspend = genphy_suspend,
1643 - .resume = genphy_resume,
1644 - .read_mmd = genphy_read_mmd_unsupported,
1645 - .write_mmd = genphy_write_mmd_unsupported,
1649 -module_phy_driver(realtek_drvs);
1651 -static const struct mdio_device_id __maybe_unused realtek_tbl[] = {
1652 - { PHY_ID_MATCH_VENDOR(0x001cc800) },
1656 -MODULE_DEVICE_TABLE(mdio, realtek_tbl);
1658 +++ b/drivers/net/phy/realtek/realtek_main.c
1660 +// SPDX-License-Identifier: GPL-2.0+
1661 +/* drivers/net/phy/realtek.c
1663 + * Driver for Realtek PHYs
1665 + * Author: Johnson Leung <r58129@freescale.com>
1667 + * Copyright (c) 2004 Freescale Semiconductor, Inc.
1669 +#include <linux/bitops.h>
1670 +#include <linux/of.h>
1671 +#include <linux/phy.h>
1672 +#include <linux/module.h>
1673 +#include <linux/delay.h>
1674 +#include <linux/clk.h>
1676 +#define RTL821x_PHYSR 0x11
1677 +#define RTL821x_PHYSR_DUPLEX BIT(13)
1678 +#define RTL821x_PHYSR_SPEED GENMASK(15, 14)
1680 +#define RTL821x_INER 0x12
1681 +#define RTL8211B_INER_INIT 0x6400
1682 +#define RTL8211E_INER_LINK_STATUS BIT(10)
1683 +#define RTL8211F_INER_LINK_STATUS BIT(4)
1685 +#define RTL821x_INSR 0x13
1687 +#define RTL821x_EXT_PAGE_SELECT 0x1e
1688 +#define RTL821x_PAGE_SELECT 0x1f
1690 +#define RTL8211F_PHYCR1 0x18
1691 +#define RTL8211F_PHYCR2 0x19
1692 +#define RTL8211F_INSR 0x1d
1694 +#define RTL8211F_LEDCR 0x10
1695 +#define RTL8211F_LEDCR_MODE BIT(15)
1696 +#define RTL8211F_LEDCR_ACT_TXRX BIT(4)
1697 +#define RTL8211F_LEDCR_LINK_1000 BIT(3)
1698 +#define RTL8211F_LEDCR_LINK_100 BIT(1)
1699 +#define RTL8211F_LEDCR_LINK_10 BIT(0)
1700 +#define RTL8211F_LEDCR_MASK GENMASK(4, 0)
1701 +#define RTL8211F_LEDCR_SHIFT 5
1703 +#define RTL8211F_TX_DELAY BIT(8)
1704 +#define RTL8211F_RX_DELAY BIT(3)
1706 +#define RTL8211F_ALDPS_PLL_OFF BIT(1)
1707 +#define RTL8211F_ALDPS_ENABLE BIT(2)
1708 +#define RTL8211F_ALDPS_XTAL_OFF BIT(12)
1710 +#define RTL8211E_CTRL_DELAY BIT(13)
1711 +#define RTL8211E_TX_DELAY BIT(12)
1712 +#define RTL8211E_RX_DELAY BIT(11)
1714 +#define RTL8211F_CLKOUT_EN BIT(0)
1716 +#define RTL8201F_ISR 0x1e
1717 +#define RTL8201F_ISR_ANERR BIT(15)
1718 +#define RTL8201F_ISR_DUPLEX BIT(13)
1719 +#define RTL8201F_ISR_LINK BIT(11)
1720 +#define RTL8201F_ISR_MASK (RTL8201F_ISR_ANERR | \
1721 + RTL8201F_ISR_DUPLEX | \
1722 + RTL8201F_ISR_LINK)
1723 +#define RTL8201F_IER 0x13
1725 +#define RTL822X_VND1_SERDES_OPTION 0x697a
1726 +#define RTL822X_VND1_SERDES_OPTION_MODE_MASK GENMASK(5, 0)
1727 +#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII 0
1728 +#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX 2
1730 +#define RTL822X_VND1_SERDES_CTRL3 0x7580
1731 +#define RTL822X_VND1_SERDES_CTRL3_MODE_MASK GENMASK(5, 0)
1732 +#define RTL822X_VND1_SERDES_CTRL3_MODE_SGMII 0x02
1733 +#define RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX 0x16
1735 +/* RTL822X_VND2_XXXXX registers are only accessible when phydev->is_c45
1736 + * is set, they cannot be accessed by C45-over-C22.
1738 +#define RTL822X_VND2_GBCR 0xa412
1740 +#define RTL822X_VND2_GANLPAR 0xa414
1742 +#define RTL8366RB_POWER_SAVE 0x15
1743 +#define RTL8366RB_POWER_SAVE_ON BIT(12)
1745 +#define RTL9000A_GINMR 0x14
1746 +#define RTL9000A_GINMR_LINK_STATUS BIT(4)
1748 +#define RTL_VND2_PHYSR 0xa434
1749 +#define RTL_VND2_PHYSR_DUPLEX BIT(3)
1750 +#define RTL_VND2_PHYSR_SPEEDL GENMASK(5, 4)
1751 +#define RTL_VND2_PHYSR_SPEEDH GENMASK(10, 9)
1752 +#define RTL_VND2_PHYSR_MASTER BIT(11)
1753 +#define RTL_VND2_PHYSR_SPEED_MASK (RTL_VND2_PHYSR_SPEEDL | RTL_VND2_PHYSR_SPEEDH)
1755 +#define RTL_GENERIC_PHYID 0x001cc800
1756 +#define RTL_8211FVD_PHYID 0x001cc878
1757 +#define RTL_8221B 0x001cc840
1758 +#define RTL_8221B_VB_CG 0x001cc849
1759 +#define RTL_8221B_VN_CG 0x001cc84a
1760 +#define RTL_8251B 0x001cc862
1762 +#define RTL8211F_LED_COUNT 3
1764 +MODULE_DESCRIPTION("Realtek PHY driver");
1765 +MODULE_AUTHOR("Johnson Leung");
1766 +MODULE_LICENSE("GPL");
1768 +struct rtl821x_priv {
1775 +static int rtl821x_read_page(struct phy_device *phydev)
1777 + return __phy_read(phydev, RTL821x_PAGE_SELECT);
1780 +static int rtl821x_write_page(struct phy_device *phydev, int page)
1782 + return __phy_write(phydev, RTL821x_PAGE_SELECT, page);
1785 +static int rtl821x_probe(struct phy_device *phydev)
1787 + struct device *dev = &phydev->mdio.dev;
1788 + struct rtl821x_priv *priv;
1789 + u32 phy_id = phydev->drv->phy_id;
1792 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1796 + priv->clk = devm_clk_get_optional_enabled(dev, NULL);
1797 + if (IS_ERR(priv->clk))
1798 + return dev_err_probe(dev, PTR_ERR(priv->clk),
1799 + "failed to get phy clock\n");
1801 + ret = phy_read_paged(phydev, 0xa43, RTL8211F_PHYCR1);
1805 + priv->phycr1 = ret & (RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF);
1806 + if (of_property_read_bool(dev->of_node, "realtek,aldps-enable"))
1807 + priv->phycr1 |= RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF;
1809 + priv->has_phycr2 = !(phy_id == RTL_8211FVD_PHYID);
1810 + if (priv->has_phycr2) {
1811 + ret = phy_read_paged(phydev, 0xa43, RTL8211F_PHYCR2);
1815 + priv->phycr2 = ret & RTL8211F_CLKOUT_EN;
1816 + if (of_property_read_bool(dev->of_node, "realtek,clkout-disable"))
1817 + priv->phycr2 &= ~RTL8211F_CLKOUT_EN;
1820 + phydev->priv = priv;
1825 +static int rtl8201_ack_interrupt(struct phy_device *phydev)
1829 + err = phy_read(phydev, RTL8201F_ISR);
1831 + return (err < 0) ? err : 0;
1834 +static int rtl821x_ack_interrupt(struct phy_device *phydev)
1838 + err = phy_read(phydev, RTL821x_INSR);
1840 + return (err < 0) ? err : 0;
1843 +static int rtl8211f_ack_interrupt(struct phy_device *phydev)
1847 + err = phy_read_paged(phydev, 0xa43, RTL8211F_INSR);
1849 + return (err < 0) ? err : 0;
1852 +static int rtl8201_config_intr(struct phy_device *phydev)
1857 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1858 + err = rtl8201_ack_interrupt(phydev);
1862 + val = BIT(13) | BIT(12) | BIT(11);
1863 + err = phy_write_paged(phydev, 0x7, RTL8201F_IER, val);
1866 + err = phy_write_paged(phydev, 0x7, RTL8201F_IER, val);
1870 + err = rtl8201_ack_interrupt(phydev);
1876 +static int rtl8211b_config_intr(struct phy_device *phydev)
1880 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1881 + err = rtl821x_ack_interrupt(phydev);
1885 + err = phy_write(phydev, RTL821x_INER,
1886 + RTL8211B_INER_INIT);
1888 + err = phy_write(phydev, RTL821x_INER, 0);
1892 + err = rtl821x_ack_interrupt(phydev);
1898 +static int rtl8211e_config_intr(struct phy_device *phydev)
1902 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1903 + err = rtl821x_ack_interrupt(phydev);
1907 + err = phy_write(phydev, RTL821x_INER,
1908 + RTL8211E_INER_LINK_STATUS);
1910 + err = phy_write(phydev, RTL821x_INER, 0);
1914 + err = rtl821x_ack_interrupt(phydev);
1920 +static int rtl8211f_config_intr(struct phy_device *phydev)
1925 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1926 + err = rtl8211f_ack_interrupt(phydev);
1930 + val = RTL8211F_INER_LINK_STATUS;
1931 + err = phy_write_paged(phydev, 0xa42, RTL821x_INER, val);
1934 + err = phy_write_paged(phydev, 0xa42, RTL821x_INER, val);
1938 + err = rtl8211f_ack_interrupt(phydev);
1944 +static irqreturn_t rtl8201_handle_interrupt(struct phy_device *phydev)
1948 + irq_status = phy_read(phydev, RTL8201F_ISR);
1949 + if (irq_status < 0) {
1950 + phy_error(phydev);
1954 + if (!(irq_status & RTL8201F_ISR_MASK))
1957 + phy_trigger_machine(phydev);
1959 + return IRQ_HANDLED;
1962 +static irqreturn_t rtl821x_handle_interrupt(struct phy_device *phydev)
1964 + int irq_status, irq_enabled;
1966 + irq_status = phy_read(phydev, RTL821x_INSR);
1967 + if (irq_status < 0) {
1968 + phy_error(phydev);
1972 + irq_enabled = phy_read(phydev, RTL821x_INER);
1973 + if (irq_enabled < 0) {
1974 + phy_error(phydev);
1978 + if (!(irq_status & irq_enabled))
1981 + phy_trigger_machine(phydev);
1983 + return IRQ_HANDLED;
1986 +static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev)
1990 + irq_status = phy_read_paged(phydev, 0xa43, RTL8211F_INSR);
1991 + if (irq_status < 0) {
1992 + phy_error(phydev);
1996 + if (!(irq_status & RTL8211F_INER_LINK_STATUS))
1999 + phy_trigger_machine(phydev);
2001 + return IRQ_HANDLED;
2004 +static int rtl8211_config_aneg(struct phy_device *phydev)
2008 + ret = genphy_config_aneg(phydev);
2012 + /* Quirk was copied from vendor driver. Unfortunately it includes no
2013 + * description of the magic numbers.
2015 + if (phydev->speed == SPEED_100 && phydev->autoneg == AUTONEG_DISABLE) {
2016 + phy_write(phydev, 0x17, 0x2138);
2017 + phy_write(phydev, 0x0e, 0x0260);
2019 + phy_write(phydev, 0x17, 0x2108);
2020 + phy_write(phydev, 0x0e, 0x0000);
2026 +static int rtl8211c_config_init(struct phy_device *phydev)
2028 + /* RTL8211C has an issue when operating in Gigabit slave mode */
2029 + return phy_set_bits(phydev, MII_CTRL1000,
2030 + CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
2033 +static int rtl8211f_config_init(struct phy_device *phydev)
2035 + struct rtl821x_priv *priv = phydev->priv;
2036 + struct device *dev = &phydev->mdio.dev;
2037 + u16 val_txdly, val_rxdly;
2040 + ret = phy_modify_paged_changed(phydev, 0xa43, RTL8211F_PHYCR1,
2041 + RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF,
2044 + dev_err(dev, "aldps mode configuration failed: %pe\n",
2049 + switch (phydev->interface) {
2050 + case PHY_INTERFACE_MODE_RGMII:
2055 + case PHY_INTERFACE_MODE_RGMII_RXID:
2057 + val_rxdly = RTL8211F_RX_DELAY;
2060 + case PHY_INTERFACE_MODE_RGMII_TXID:
2061 + val_txdly = RTL8211F_TX_DELAY;
2065 + case PHY_INTERFACE_MODE_RGMII_ID:
2066 + val_txdly = RTL8211F_TX_DELAY;
2067 + val_rxdly = RTL8211F_RX_DELAY;
2070 + default: /* the rest of the modes imply leaving delay as is. */
2074 + ret = phy_modify_paged_changed(phydev, 0xd08, 0x11, RTL8211F_TX_DELAY,
2077 + dev_err(dev, "Failed to update the TX delay register\n");
2081 + "%s 2ns TX delay (and changing the value from pin-strapping RXD1 or the bootloader)\n",
2082 + val_txdly ? "Enabling" : "Disabling");
2085 + "2ns TX delay was already %s (by pin-strapping RXD1 or bootloader configuration)\n",
2086 + val_txdly ? "enabled" : "disabled");
2089 + ret = phy_modify_paged_changed(phydev, 0xd08, 0x15, RTL8211F_RX_DELAY,
2092 + dev_err(dev, "Failed to update the RX delay register\n");
2096 + "%s 2ns RX delay (and changing the value from pin-strapping RXD0 or the bootloader)\n",
2097 + val_rxdly ? "Enabling" : "Disabling");
2100 + "2ns RX delay was already %s (by pin-strapping RXD0 or bootloader configuration)\n",
2101 + val_rxdly ? "enabled" : "disabled");
2104 + if (priv->has_phycr2) {
2105 + ret = phy_modify_paged(phydev, 0xa43, RTL8211F_PHYCR2,
2106 + RTL8211F_CLKOUT_EN, priv->phycr2);
2108 + dev_err(dev, "clkout configuration failed: %pe\n",
2113 + return genphy_soft_reset(phydev);
2119 +static int rtl821x_suspend(struct phy_device *phydev)
2121 + struct rtl821x_priv *priv = phydev->priv;
2124 + if (!phydev->wol_enabled) {
2125 + ret = genphy_suspend(phydev);
2130 + clk_disable_unprepare(priv->clk);
2136 +static int rtl821x_resume(struct phy_device *phydev)
2138 + struct rtl821x_priv *priv = phydev->priv;
2141 + if (!phydev->wol_enabled)
2142 + clk_prepare_enable(priv->clk);
2144 + ret = genphy_resume(phydev);
2153 +static int rtl8211f_led_hw_is_supported(struct phy_device *phydev, u8 index,
2154 + unsigned long rules)
2156 + const unsigned long mask = BIT(TRIGGER_NETDEV_LINK_10) |
2157 + BIT(TRIGGER_NETDEV_LINK_100) |
2158 + BIT(TRIGGER_NETDEV_LINK_1000) |
2159 + BIT(TRIGGER_NETDEV_RX) |
2160 + BIT(TRIGGER_NETDEV_TX);
2162 + /* The RTL8211F PHY supports these LED settings on up to three LEDs:
2163 + * - Link: Configurable subset of 10/100/1000 link rates
2164 + * - Active: Blink on activity, RX or TX is not differentiated
2165 + * The Active option has two modes, A and B:
2166 + * - A: Link and Active indication at configurable, but matching,
2167 + * subset of 10/100/1000 link rates
2168 + * - B: Link indication at configurable subset of 10/100/1000 link
2169 + * rates and Active indication always at all three 10+100+1000
2171 + * This code currently uses mode B only.
2174 + if (index >= RTL8211F_LED_COUNT)
2177 + /* Filter out any other unsupported triggers. */
2178 + if (rules & ~mask)
2179 + return -EOPNOTSUPP;
2181 + /* RX and TX are not differentiated, either both are set or not set. */
2182 + if (!(rules & BIT(TRIGGER_NETDEV_RX)) ^ !(rules & BIT(TRIGGER_NETDEV_TX)))
2183 + return -EOPNOTSUPP;
2188 +static int rtl8211f_led_hw_control_get(struct phy_device *phydev, u8 index,
2189 + unsigned long *rules)
2193 + if (index >= RTL8211F_LED_COUNT)
2196 + val = phy_read_paged(phydev, 0xd04, RTL8211F_LEDCR);
2200 + val >>= RTL8211F_LEDCR_SHIFT * index;
2201 + val &= RTL8211F_LEDCR_MASK;
2203 + if (val & RTL8211F_LEDCR_LINK_10)
2204 + set_bit(TRIGGER_NETDEV_LINK_10, rules);
2206 + if (val & RTL8211F_LEDCR_LINK_100)
2207 + set_bit(TRIGGER_NETDEV_LINK_100, rules);
2209 + if (val & RTL8211F_LEDCR_LINK_1000)
2210 + set_bit(TRIGGER_NETDEV_LINK_1000, rules);
2212 + if (val & RTL8211F_LEDCR_ACT_TXRX) {
2213 + set_bit(TRIGGER_NETDEV_RX, rules);
2214 + set_bit(TRIGGER_NETDEV_TX, rules);
2220 +static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index,
2221 + unsigned long rules)
2223 + const u16 mask = RTL8211F_LEDCR_MASK << (RTL8211F_LEDCR_SHIFT * index);
2226 + if (index >= RTL8211F_LED_COUNT)
2229 + if (test_bit(TRIGGER_NETDEV_LINK_10, &rules))
2230 + reg |= RTL8211F_LEDCR_LINK_10;
2232 + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules))
2233 + reg |= RTL8211F_LEDCR_LINK_100;
2235 + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules))
2236 + reg |= RTL8211F_LEDCR_LINK_1000;
2238 + if (test_bit(TRIGGER_NETDEV_RX, &rules) ||
2239 + test_bit(TRIGGER_NETDEV_TX, &rules)) {
2240 + reg |= RTL8211F_LEDCR_ACT_TXRX;
2243 + reg <<= RTL8211F_LEDCR_SHIFT * index;
2244 + reg |= RTL8211F_LEDCR_MODE; /* Mode B */
2246 + return phy_modify_paged(phydev, 0xd04, RTL8211F_LEDCR, mask, reg);
2249 +static int rtl8211e_config_init(struct phy_device *phydev)
2251 + int ret = 0, oldpage;
2254 + /* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */
2255 + switch (phydev->interface) {
2256 + case PHY_INTERFACE_MODE_RGMII:
2257 + val = RTL8211E_CTRL_DELAY | 0;
2259 + case PHY_INTERFACE_MODE_RGMII_ID:
2260 + val = RTL8211E_CTRL_DELAY | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY;
2262 + case PHY_INTERFACE_MODE_RGMII_RXID:
2263 + val = RTL8211E_CTRL_DELAY | RTL8211E_RX_DELAY;
2265 + case PHY_INTERFACE_MODE_RGMII_TXID:
2266 + val = RTL8211E_CTRL_DELAY | RTL8211E_TX_DELAY;
2268 + default: /* the rest of the modes imply leaving delays as is. */
2272 + /* According to a sample driver there is a 0x1c config register on the
2273 + * 0xa4 extension page (0x7) layout. It can be used to disable/enable
2274 + * the RX/TX delays otherwise controlled by RXDLY/TXDLY pins.
2275 + * The configuration register definition:
2277 + * 13 = Force Tx RX Delay controlled by bit12 bit11,
2278 + * 12 = RX Delay, 11 = TX Delay
2279 + * 10:0 = Test && debug settings reserved by realtek
2281 + oldpage = phy_select_page(phydev, 0x7);
2283 + goto err_restore_page;
2285 + ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4);
2287 + goto err_restore_page;
2289 + ret = __phy_modify(phydev, 0x1c, RTL8211E_CTRL_DELAY
2290 + | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY,
2294 + return phy_restore_page(phydev, oldpage, ret);
2297 +static int rtl8211b_suspend(struct phy_device *phydev)
2299 + phy_write(phydev, MII_MMD_DATA, BIT(9));
2301 + return genphy_suspend(phydev);
2304 +static int rtl8211b_resume(struct phy_device *phydev)
2306 + phy_write(phydev, MII_MMD_DATA, 0);
2308 + return genphy_resume(phydev);
2311 +static int rtl8366rb_config_init(struct phy_device *phydev)
2315 + ret = phy_set_bits(phydev, RTL8366RB_POWER_SAVE,
2316 + RTL8366RB_POWER_SAVE_ON);
2318 + dev_err(&phydev->mdio.dev,
2319 + "error enabling power management\n");
2325 +/* get actual speed to cover the downshift case */
2326 +static void rtlgen_decode_physr(struct phy_device *phydev, int val)
2332 + if (val & RTL_VND2_PHYSR_DUPLEX)
2333 + phydev->duplex = DUPLEX_FULL;
2335 + phydev->duplex = DUPLEX_HALF;
2337 + switch (val & RTL_VND2_PHYSR_SPEED_MASK) {
2339 + phydev->speed = SPEED_10;
2342 + phydev->speed = SPEED_100;
2345 + phydev->speed = SPEED_1000;
2348 + phydev->speed = SPEED_10000;
2351 + phydev->speed = SPEED_2500;
2354 + phydev->speed = SPEED_5000;
2364 + if (phydev->speed >= 1000) {
2365 + if (val & RTL_VND2_PHYSR_MASTER)
2366 + phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
2368 + phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
2370 + phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED;
2374 +static int rtlgen_read_status(struct phy_device *phydev)
2378 + ret = genphy_read_status(phydev);
2382 + if (!phydev->link)
2385 + val = phy_read_paged(phydev, 0xa43, 0x12);
2389 + rtlgen_decode_physr(phydev, val);
2394 +static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
2398 + if (devnum == MDIO_MMD_VEND2) {
2399 + rtl821x_write_page(phydev, regnum >> 4);
2400 + ret = __phy_read(phydev, 0x10 + ((regnum & 0xf) >> 1));
2401 + rtl821x_write_page(phydev, 0);
2402 + } else if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE) {
2403 + rtl821x_write_page(phydev, 0xa5c);
2404 + ret = __phy_read(phydev, 0x12);
2405 + rtl821x_write_page(phydev, 0);
2406 + } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
2407 + rtl821x_write_page(phydev, 0xa5d);
2408 + ret = __phy_read(phydev, 0x10);
2409 + rtl821x_write_page(phydev, 0);
2410 + } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_LPABLE) {
2411 + rtl821x_write_page(phydev, 0xa5d);
2412 + ret = __phy_read(phydev, 0x11);
2413 + rtl821x_write_page(phydev, 0);
2415 + ret = -EOPNOTSUPP;
2421 +static int rtlgen_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
2426 + if (devnum == MDIO_MMD_VEND2) {
2427 + rtl821x_write_page(phydev, regnum >> 4);
2428 + ret = __phy_write(phydev, 0x10 + ((regnum & 0xf) >> 1), val);
2429 + rtl821x_write_page(phydev, 0);
2430 + } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
2431 + rtl821x_write_page(phydev, 0xa5d);
2432 + ret = __phy_write(phydev, 0x10, val);
2433 + rtl821x_write_page(phydev, 0);
2435 + ret = -EOPNOTSUPP;
2441 +static int rtl822x_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
2443 + int ret = rtlgen_read_mmd(phydev, devnum, regnum);
2445 + if (ret != -EOPNOTSUPP)
2448 + if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE2) {
2449 + rtl821x_write_page(phydev, 0xa6e);
2450 + ret = __phy_read(phydev, 0x16);
2451 + rtl821x_write_page(phydev, 0);
2452 + } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV2) {
2453 + rtl821x_write_page(phydev, 0xa6d);
2454 + ret = __phy_read(phydev, 0x12);
2455 + rtl821x_write_page(phydev, 0);
2456 + } else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_LPABLE2) {
2457 + rtl821x_write_page(phydev, 0xa6d);
2458 + ret = __phy_read(phydev, 0x10);
2459 + rtl821x_write_page(phydev, 0);
2465 +static int rtl822x_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
2468 + int ret = rtlgen_write_mmd(phydev, devnum, regnum, val);
2470 + if (ret != -EOPNOTSUPP)
2473 + if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV2) {
2474 + rtl821x_write_page(phydev, 0xa6d);
2475 + ret = __phy_write(phydev, 0x12, val);
2476 + rtl821x_write_page(phydev, 0);
2482 +static int rtl822xb_config_init(struct phy_device *phydev)
2484 + bool has_2500, has_sgmii;
2488 + has_2500 = test_bit(PHY_INTERFACE_MODE_2500BASEX,
2489 + phydev->host_interfaces) ||
2490 + phydev->interface == PHY_INTERFACE_MODE_2500BASEX;
2492 + has_sgmii = test_bit(PHY_INTERFACE_MODE_SGMII,
2493 + phydev->host_interfaces) ||
2494 + phydev->interface == PHY_INTERFACE_MODE_SGMII;
2496 + /* fill in possible interfaces */
2497 + __assign_bit(PHY_INTERFACE_MODE_2500BASEX, phydev->possible_interfaces,
2499 + __assign_bit(PHY_INTERFACE_MODE_SGMII, phydev->possible_interfaces,
2502 + if (!has_2500 && !has_sgmii)
2505 + /* determine SerDes option mode */
2506 + if (has_2500 && !has_sgmii) {
2507 + mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX;
2508 + phydev->rate_matching = RATE_MATCH_PAUSE;
2510 + mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII;
2511 + phydev->rate_matching = RATE_MATCH_NONE;
2514 + /* the following sequence with magic numbers sets up the SerDes
2517 + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x75f3, 0);
2521 + ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND1,
2522 + RTL822X_VND1_SERDES_OPTION,
2523 + RTL822X_VND1_SERDES_OPTION_MODE_MASK,
2528 + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6a04, 0x0503);
2532 + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f10, 0xd455);
2536 + return phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f11, 0x8020);
2539 +static int rtl822xb_get_rate_matching(struct phy_device *phydev,
2540 + phy_interface_t iface)
2544 + /* Only rate matching at 2500base-x */
2545 + if (iface != PHY_INTERFACE_MODE_2500BASEX)
2546 + return RATE_MATCH_NONE;
2548 + val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_OPTION);
2552 + if ((val & RTL822X_VND1_SERDES_OPTION_MODE_MASK) ==
2553 + RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX)
2554 + return RATE_MATCH_PAUSE;
2556 + /* RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII */
2557 + return RATE_MATCH_NONE;
2560 +static int rtl822x_get_features(struct phy_device *phydev)
2564 + val = phy_read_paged(phydev, 0xa61, 0x13);
2568 + linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
2569 + phydev->supported, val & MDIO_PMA_SPEED_2_5G);
2570 + linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
2571 + phydev->supported, val & MDIO_PMA_SPEED_5G);
2572 + linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
2573 + phydev->supported, val & MDIO_SPEED_10G);
2575 + return genphy_read_abilities(phydev);
2578 +static int rtl822x_config_aneg(struct phy_device *phydev)
2582 + if (phydev->autoneg == AUTONEG_ENABLE) {
2583 + u16 adv = linkmode_adv_to_mii_10gbt_adv_t(phydev->advertising);
2585 + ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
2586 + MDIO_AN_10GBT_CTRL_ADV2_5G |
2587 + MDIO_AN_10GBT_CTRL_ADV5G,
2593 + return __genphy_config_aneg(phydev, ret);
2596 +static void rtl822xb_update_interface(struct phy_device *phydev)
2600 + if (!phydev->link)
2603 + /* Change interface according to serdes mode */
2604 + val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_CTRL3);
2608 + switch (val & RTL822X_VND1_SERDES_CTRL3_MODE_MASK) {
2609 + case RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX:
2610 + phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
2612 + case RTL822X_VND1_SERDES_CTRL3_MODE_SGMII:
2613 + phydev->interface = PHY_INTERFACE_MODE_SGMII;
2618 +static int rtl822x_read_status(struct phy_device *phydev)
2622 + ret = rtlgen_read_status(phydev);
2626 + if (phydev->autoneg == AUTONEG_DISABLE ||
2627 + !phydev->autoneg_complete) {
2628 + mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
2632 + lpadv = phy_read_paged(phydev, 0xa5d, 0x13);
2636 + mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, lpadv);
2641 +static int rtl822xb_read_status(struct phy_device *phydev)
2645 + ret = rtl822x_read_status(phydev);
2649 + rtl822xb_update_interface(phydev);
2654 +static int rtl822x_c45_get_features(struct phy_device *phydev)
2656 + linkmode_set_bit(ETHTOOL_LINK_MODE_TP_BIT,
2657 + phydev->supported);
2659 + return genphy_c45_pma_read_abilities(phydev);
2662 +static int rtl822x_c45_config_aneg(struct phy_device *phydev)
2664 + bool changed = false;
2667 + if (phydev->autoneg == AUTONEG_DISABLE)
2668 + return genphy_c45_pma_setup_forced(phydev);
2670 + ret = genphy_c45_an_config_aneg(phydev);
2676 + val = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
2678 + /* Vendor register as C45 has no standardized support for 1000BaseT */
2679 + ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, RTL822X_VND2_GBCR,
2680 + ADVERTISE_1000FULL, val);
2686 + return genphy_c45_check_and_restart_aneg(phydev, changed);
2689 +static int rtl822x_c45_read_status(struct phy_device *phydev)
2693 + ret = genphy_c45_read_status(phydev);
2697 + if (phydev->autoneg == AUTONEG_DISABLE ||
2698 + !genphy_c45_aneg_done(phydev))
2699 + mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
2701 + /* Vendor register as C45 has no standardized support for 1000BaseT */
2702 + if (phydev->autoneg == AUTONEG_ENABLE) {
2703 + val = phy_read_mmd(phydev, MDIO_MMD_VEND2,
2704 + RTL822X_VND2_GANLPAR);
2708 + mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
2711 + if (!phydev->link)
2714 + /* Read actual speed from vendor register. */
2715 + val = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL_VND2_PHYSR);
2719 + rtlgen_decode_physr(phydev, val);
2724 +static int rtl822xb_c45_read_status(struct phy_device *phydev)
2728 + ret = rtl822x_c45_read_status(phydev);
2732 + rtl822xb_update_interface(phydev);
2737 +static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
2741 + phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61);
2742 + val = phy_read(phydev, 0x13);
2743 + phy_write(phydev, RTL821x_PAGE_SELECT, 0);
2745 + return val >= 0 && val & MDIO_PMA_SPEED_2_5G;
2748 +/* On internal PHY's MMD reads over C22 always return 0.
2749 + * Check a MMD register which is known to be non-zero.
2751 +static bool rtlgen_supports_mmd(struct phy_device *phydev)
2755 + phy_lock_mdio_bus(phydev);
2756 + __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS);
2757 + __phy_write(phydev, MII_MMD_DATA, MDIO_PCS_EEE_ABLE);
2758 + __phy_write(phydev, MII_MMD_CTRL, MDIO_MMD_PCS | MII_MMD_CTRL_NOINCR);
2759 + val = __phy_read(phydev, MII_MMD_DATA);
2760 + phy_unlock_mdio_bus(phydev);
2765 +static int rtlgen_match_phy_device(struct phy_device *phydev)
2767 + return phydev->phy_id == RTL_GENERIC_PHYID &&
2768 + !rtlgen_supports_2_5gbps(phydev);
2771 +static int rtl8226_match_phy_device(struct phy_device *phydev)
2773 + return phydev->phy_id == RTL_GENERIC_PHYID &&
2774 + rtlgen_supports_2_5gbps(phydev) &&
2775 + rtlgen_supports_mmd(phydev);
2778 +static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,
2781 + if (phydev->is_c45)
2782 + return is_c45 && (id == phydev->c45_ids.device_ids[1]);
2784 + return !is_c45 && (id == phydev->phy_id);
2787 +static int rtl8221b_match_phy_device(struct phy_device *phydev)
2789 + return phydev->phy_id == RTL_8221B && rtlgen_supports_mmd(phydev);
2792 +static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev)
2794 + return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false);
2797 +static int rtl8221b_vb_cg_c45_match_phy_device(struct phy_device *phydev)
2799 + return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, true);
2802 +static int rtl8221b_vn_cg_c22_match_phy_device(struct phy_device *phydev)
2804 + return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, false);
2807 +static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev)
2809 + return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true);
2812 +static int rtl_internal_nbaset_match_phy_device(struct phy_device *phydev)
2814 + if (phydev->is_c45)
2817 + switch (phydev->phy_id) {
2818 + case RTL_GENERIC_PHYID:
2827 + return rtlgen_supports_2_5gbps(phydev) && !rtlgen_supports_mmd(phydev);
2830 +static int rtl8251b_c45_match_phy_device(struct phy_device *phydev)
2832 + return rtlgen_is_c45_match(phydev, RTL_8251B, true);
2835 +static int rtlgen_resume(struct phy_device *phydev)
2837 + int ret = genphy_resume(phydev);
2839 + /* Internal PHY's from RTL8168h up may not be instantly ready */
2845 +static int rtlgen_c45_resume(struct phy_device *phydev)
2847 + int ret = genphy_c45_pma_resume(phydev);
2854 +static int rtl9000a_config_init(struct phy_device *phydev)
2856 + phydev->autoneg = AUTONEG_DISABLE;
2857 + phydev->speed = SPEED_100;
2858 + phydev->duplex = DUPLEX_FULL;
2863 +static int rtl9000a_config_aneg(struct phy_device *phydev)
2868 + switch (phydev->master_slave_set) {
2869 + case MASTER_SLAVE_CFG_MASTER_FORCE:
2870 + ctl |= CTL1000_AS_MASTER;
2872 + case MASTER_SLAVE_CFG_SLAVE_FORCE:
2874 + case MASTER_SLAVE_CFG_UNKNOWN:
2875 + case MASTER_SLAVE_CFG_UNSUPPORTED:
2878 + phydev_warn(phydev, "Unsupported Master/Slave mode\n");
2879 + return -EOPNOTSUPP;
2882 + ret = phy_modify_changed(phydev, MII_CTRL1000, CTL1000_AS_MASTER, ctl);
2884 + ret = genphy_soft_reset(phydev);
2889 +static int rtl9000a_read_status(struct phy_device *phydev)
2893 + phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN;
2894 + phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
2896 + ret = genphy_update_link(phydev);
2900 + ret = phy_read(phydev, MII_CTRL1000);
2903 + if (ret & CTL1000_AS_MASTER)
2904 + phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
2906 + phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_FORCE;
2908 + ret = phy_read(phydev, MII_STAT1000);
2911 + if (ret & LPA_1000MSRES)
2912 + phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
2914 + phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
2919 +static int rtl9000a_ack_interrupt(struct phy_device *phydev)
2923 + err = phy_read(phydev, RTL8211F_INSR);
2925 + return (err < 0) ? err : 0;
2928 +static int rtl9000a_config_intr(struct phy_device *phydev)
2933 + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
2934 + err = rtl9000a_ack_interrupt(phydev);
2938 + val = (u16)~RTL9000A_GINMR_LINK_STATUS;
2939 + err = phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
2942 + err = phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
2946 + err = rtl9000a_ack_interrupt(phydev);
2949 + return phy_write_paged(phydev, 0xa42, RTL9000A_GINMR, val);
2952 +static irqreturn_t rtl9000a_handle_interrupt(struct phy_device *phydev)
2956 + irq_status = phy_read(phydev, RTL8211F_INSR);
2957 + if (irq_status < 0) {
2958 + phy_error(phydev);
2962 + if (!(irq_status & RTL8211F_INER_LINK_STATUS))
2965 + phy_trigger_machine(phydev);
2967 + return IRQ_HANDLED;
2970 +static struct phy_driver realtek_drvs[] = {
2972 + PHY_ID_MATCH_EXACT(0x00008201),
2973 + .name = "RTL8201CP Ethernet",
2974 + .read_page = rtl821x_read_page,
2975 + .write_page = rtl821x_write_page,
2977 + PHY_ID_MATCH_EXACT(0x001cc816),
2978 + .name = "RTL8201F Fast Ethernet",
2979 + .config_intr = &rtl8201_config_intr,
2980 + .handle_interrupt = rtl8201_handle_interrupt,
2981 + .suspend = genphy_suspend,
2982 + .resume = genphy_resume,
2983 + .read_page = rtl821x_read_page,
2984 + .write_page = rtl821x_write_page,
2986 + PHY_ID_MATCH_MODEL(0x001cc880),
2987 + .name = "RTL8208 Fast Ethernet",
2988 + .read_mmd = genphy_read_mmd_unsupported,
2989 + .write_mmd = genphy_write_mmd_unsupported,
2990 + .suspend = genphy_suspend,
2991 + .resume = genphy_resume,
2992 + .read_page = rtl821x_read_page,
2993 + .write_page = rtl821x_write_page,
2995 + PHY_ID_MATCH_EXACT(0x001cc910),
2996 + .name = "RTL8211 Gigabit Ethernet",
2997 + .config_aneg = rtl8211_config_aneg,
2998 + .read_mmd = &genphy_read_mmd_unsupported,
2999 + .write_mmd = &genphy_write_mmd_unsupported,
3000 + .read_page = rtl821x_read_page,
3001 + .write_page = rtl821x_write_page,
3003 + PHY_ID_MATCH_EXACT(0x001cc912),
3004 + .name = "RTL8211B Gigabit Ethernet",
3005 + .config_intr = &rtl8211b_config_intr,
3006 + .handle_interrupt = rtl821x_handle_interrupt,
3007 + .read_mmd = &genphy_read_mmd_unsupported,
3008 + .write_mmd = &genphy_write_mmd_unsupported,
3009 + .suspend = rtl8211b_suspend,
3010 + .resume = rtl8211b_resume,
3011 + .read_page = rtl821x_read_page,
3012 + .write_page = rtl821x_write_page,
3014 + PHY_ID_MATCH_EXACT(0x001cc913),
3015 + .name = "RTL8211C Gigabit Ethernet",
3016 + .config_init = rtl8211c_config_init,
3017 + .read_mmd = &genphy_read_mmd_unsupported,
3018 + .write_mmd = &genphy_write_mmd_unsupported,
3019 + .read_page = rtl821x_read_page,
3020 + .write_page = rtl821x_write_page,
3022 + PHY_ID_MATCH_EXACT(0x001cc914),
3023 + .name = "RTL8211DN Gigabit Ethernet",
3024 + .config_intr = rtl8211e_config_intr,
3025 + .handle_interrupt = rtl821x_handle_interrupt,
3026 + .suspend = genphy_suspend,
3027 + .resume = genphy_resume,
3028 + .read_page = rtl821x_read_page,
3029 + .write_page = rtl821x_write_page,
3031 + PHY_ID_MATCH_EXACT(0x001cc915),
3032 + .name = "RTL8211E Gigabit Ethernet",
3033 + .config_init = &rtl8211e_config_init,
3034 + .config_intr = &rtl8211e_config_intr,
3035 + .handle_interrupt = rtl821x_handle_interrupt,
3036 + .suspend = genphy_suspend,
3037 + .resume = genphy_resume,
3038 + .read_page = rtl821x_read_page,
3039 + .write_page = rtl821x_write_page,
3041 + PHY_ID_MATCH_EXACT(0x001cc916),
3042 + .name = "RTL8211F Gigabit Ethernet",
3043 + .probe = rtl821x_probe,
3044 + .config_init = &rtl8211f_config_init,
3045 + .read_status = rtlgen_read_status,
3046 + .config_intr = &rtl8211f_config_intr,
3047 + .handle_interrupt = rtl8211f_handle_interrupt,
3048 + .suspend = rtl821x_suspend,
3049 + .resume = rtl821x_resume,
3050 + .read_page = rtl821x_read_page,
3051 + .write_page = rtl821x_write_page,
3052 + .flags = PHY_ALWAYS_CALL_SUSPEND,
3053 + .led_hw_is_supported = rtl8211f_led_hw_is_supported,
3054 + .led_hw_control_get = rtl8211f_led_hw_control_get,
3055 + .led_hw_control_set = rtl8211f_led_hw_control_set,
3057 + PHY_ID_MATCH_EXACT(RTL_8211FVD_PHYID),
3058 + .name = "RTL8211F-VD Gigabit Ethernet",
3059 + .probe = rtl821x_probe,
3060 + .config_init = &rtl8211f_config_init,
3061 + .read_status = rtlgen_read_status,
3062 + .config_intr = &rtl8211f_config_intr,
3063 + .handle_interrupt = rtl8211f_handle_interrupt,
3064 + .suspend = rtl821x_suspend,
3065 + .resume = rtl821x_resume,
3066 + .read_page = rtl821x_read_page,
3067 + .write_page = rtl821x_write_page,
3068 + .flags = PHY_ALWAYS_CALL_SUSPEND,
3070 + .name = "Generic FE-GE Realtek PHY",
3071 + .match_phy_device = rtlgen_match_phy_device,
3072 + .read_status = rtlgen_read_status,
3073 + .suspend = genphy_suspend,
3074 + .resume = rtlgen_resume,
3075 + .read_page = rtl821x_read_page,
3076 + .write_page = rtl821x_write_page,
3077 + .read_mmd = rtlgen_read_mmd,
3078 + .write_mmd = rtlgen_write_mmd,
3080 + .name = "RTL8226 2.5Gbps PHY",
3081 + .match_phy_device = rtl8226_match_phy_device,
3082 + .get_features = rtl822x_get_features,
3083 + .config_aneg = rtl822x_config_aneg,
3084 + .read_status = rtl822x_read_status,
3085 + .suspend = genphy_suspend,
3086 + .resume = rtlgen_resume,
3087 + .read_page = rtl821x_read_page,
3088 + .write_page = rtl821x_write_page,
3090 + .match_phy_device = rtl8221b_match_phy_device,
3091 + .name = "RTL8226B_RTL8221B 2.5Gbps PHY",
3092 + .get_features = rtl822x_get_features,
3093 + .config_aneg = rtl822x_config_aneg,
3094 + .config_init = rtl822xb_config_init,
3095 + .get_rate_matching = rtl822xb_get_rate_matching,
3096 + .read_status = rtl822xb_read_status,
3097 + .suspend = genphy_suspend,
3098 + .resume = rtlgen_resume,
3099 + .read_page = rtl821x_read_page,
3100 + .write_page = rtl821x_write_page,
3102 + PHY_ID_MATCH_EXACT(0x001cc838),
3103 + .name = "RTL8226-CG 2.5Gbps PHY",
3104 + .get_features = rtl822x_get_features,
3105 + .config_aneg = rtl822x_config_aneg,
3106 + .read_status = rtl822x_read_status,
3107 + .suspend = genphy_suspend,
3108 + .resume = rtlgen_resume,
3109 + .read_page = rtl821x_read_page,
3110 + .write_page = rtl821x_write_page,
3112 + PHY_ID_MATCH_EXACT(0x001cc848),
3113 + .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY",
3114 + .get_features = rtl822x_get_features,
3115 + .config_aneg = rtl822x_config_aneg,
3116 + .config_init = rtl822xb_config_init,
3117 + .get_rate_matching = rtl822xb_get_rate_matching,
3118 + .read_status = rtl822xb_read_status,
3119 + .suspend = genphy_suspend,
3120 + .resume = rtlgen_resume,
3121 + .read_page = rtl821x_read_page,
3122 + .write_page = rtl821x_write_page,
3124 + .match_phy_device = rtl8221b_vb_cg_c22_match_phy_device,
3125 + .name = "RTL8221B-VB-CG 2.5Gbps PHY (C22)",
3126 + .get_features = rtl822x_get_features,
3127 + .config_aneg = rtl822x_config_aneg,
3128 + .config_init = rtl822xb_config_init,
3129 + .get_rate_matching = rtl822xb_get_rate_matching,
3130 + .read_status = rtl822xb_read_status,
3131 + .suspend = genphy_suspend,
3132 + .resume = rtlgen_resume,
3133 + .read_page = rtl821x_read_page,
3134 + .write_page = rtl821x_write_page,
3136 + .match_phy_device = rtl8221b_vb_cg_c45_match_phy_device,
3137 + .name = "RTL8221B-VB-CG 2.5Gbps PHY (C45)",
3138 + .config_init = rtl822xb_config_init,
3139 + .get_rate_matching = rtl822xb_get_rate_matching,
3140 + .get_features = rtl822x_c45_get_features,
3141 + .config_aneg = rtl822x_c45_config_aneg,
3142 + .read_status = rtl822xb_c45_read_status,
3143 + .suspend = genphy_c45_pma_suspend,
3144 + .resume = rtlgen_c45_resume,
3146 + .match_phy_device = rtl8221b_vn_cg_c22_match_phy_device,
3147 + .name = "RTL8221B-VM-CG 2.5Gbps PHY (C22)",
3148 + .get_features = rtl822x_get_features,
3149 + .config_aneg = rtl822x_config_aneg,
3150 + .config_init = rtl822xb_config_init,
3151 + .get_rate_matching = rtl822xb_get_rate_matching,
3152 + .read_status = rtl822xb_read_status,
3153 + .suspend = genphy_suspend,
3154 + .resume = rtlgen_resume,
3155 + .read_page = rtl821x_read_page,
3156 + .write_page = rtl821x_write_page,
3158 + .match_phy_device = rtl8221b_vn_cg_c45_match_phy_device,
3159 + .name = "RTL8221B-VN-CG 2.5Gbps PHY (C45)",
3160 + .config_init = rtl822xb_config_init,
3161 + .get_rate_matching = rtl822xb_get_rate_matching,
3162 + .get_features = rtl822x_c45_get_features,
3163 + .config_aneg = rtl822x_c45_config_aneg,
3164 + .read_status = rtl822xb_c45_read_status,
3165 + .suspend = genphy_c45_pma_suspend,
3166 + .resume = rtlgen_c45_resume,
3168 + .match_phy_device = rtl8251b_c45_match_phy_device,
3169 + .name = "RTL8251B 5Gbps PHY",
3170 + .get_features = rtl822x_get_features,
3171 + .config_aneg = rtl822x_config_aneg,
3172 + .read_status = rtl822x_read_status,
3173 + .suspend = genphy_suspend,
3174 + .resume = rtlgen_resume,
3175 + .read_page = rtl821x_read_page,
3176 + .write_page = rtl821x_write_page,
3178 + .match_phy_device = rtl_internal_nbaset_match_phy_device,
3179 + .name = "Realtek Internal NBASE-T PHY",
3180 + .flags = PHY_IS_INTERNAL,
3181 + .get_features = rtl822x_get_features,
3182 + .config_aneg = rtl822x_config_aneg,
3183 + .read_status = rtl822x_read_status,
3184 + .suspend = genphy_suspend,
3185 + .resume = rtlgen_resume,
3186 + .read_page = rtl821x_read_page,
3187 + .write_page = rtl821x_write_page,
3188 + .read_mmd = rtl822x_read_mmd,
3189 + .write_mmd = rtl822x_write_mmd,
3191 + PHY_ID_MATCH_EXACT(0x001ccad0),
3192 + .name = "RTL8224 2.5Gbps PHY",
3193 + .get_features = rtl822x_c45_get_features,
3194 + .config_aneg = rtl822x_c45_config_aneg,
3195 + .read_status = rtl822x_c45_read_status,
3196 + .suspend = genphy_c45_pma_suspend,
3197 + .resume = rtlgen_c45_resume,
3199 + PHY_ID_MATCH_EXACT(0x001cc961),
3200 + .name = "RTL8366RB Gigabit Ethernet",
3201 + .config_init = &rtl8366rb_config_init,
3202 + /* These interrupts are handled by the irq controller
3203 + * embedded inside the RTL8366RB, they get unmasked when the
3204 + * irq is requested and ACKed by reading the status register,
3205 + * which is done by the irqchip code.
3207 + .config_intr = genphy_no_config_intr,
3208 + .handle_interrupt = genphy_handle_interrupt_no_ack,
3209 + .suspend = genphy_suspend,
3210 + .resume = genphy_resume,
3212 + PHY_ID_MATCH_EXACT(0x001ccb00),
3213 + .name = "RTL9000AA_RTL9000AN Ethernet",
3214 + .features = PHY_BASIC_T1_FEATURES,
3215 + .config_init = rtl9000a_config_init,
3216 + .config_aneg = rtl9000a_config_aneg,
3217 + .read_status = rtl9000a_read_status,
3218 + .config_intr = rtl9000a_config_intr,
3219 + .handle_interrupt = rtl9000a_handle_interrupt,
3220 + .suspend = genphy_suspend,
3221 + .resume = genphy_resume,
3222 + .read_page = rtl821x_read_page,
3223 + .write_page = rtl821x_write_page,
3225 + PHY_ID_MATCH_EXACT(0x001cc942),
3226 + .name = "RTL8365MB-VC Gigabit Ethernet",
3227 + /* Interrupt handling analogous to RTL8366RB */
3228 + .config_intr = genphy_no_config_intr,
3229 + .handle_interrupt = genphy_handle_interrupt_no_ack,
3230 + .suspend = genphy_suspend,
3231 + .resume = genphy_resume,
3233 + PHY_ID_MATCH_EXACT(0x001cc960),
3234 + .name = "RTL8366S Gigabit Ethernet",
3235 + .suspend = genphy_suspend,
3236 + .resume = genphy_resume,
3237 + .read_mmd = genphy_read_mmd_unsupported,
3238 + .write_mmd = genphy_write_mmd_unsupported,
3242 +module_phy_driver(realtek_drvs);
3244 +static const struct mdio_device_id __maybe_unused realtek_tbl[] = {
3245 + { PHY_ID_MATCH_VENDOR(0x001cc800) },
3249 +MODULE_DEVICE_TABLE(mdio, realtek_tbl);