1 // SPDX-License-Identifier: GPL-2.0
2 /* Driver for the Texas Instruments DP83869 PHY
3 * Copyright (C) 2019 Texas Instruments Inc.
6 #include <linux/ethtool.h>
7 #include <linux/etherdevice.h>
8 #include <linux/kernel.h>
10 #include <linux/module.h>
12 #include <linux/phy.h>
13 #include <linux/delay.h>
14 #include <linux/bitfield.h>
16 #include <dt-bindings/net/ti-dp83869.h>
18 #define DP83869_PHY_ID 0x2000a0f1
19 #define DP83561_PHY_ID 0x2000a1a4
20 #define DP83869_DEVADDR 0x1f
22 #define MII_DP83869_PHYCTRL 0x10
23 #define MII_DP83869_MICR 0x12
24 #define MII_DP83869_ISR 0x13
25 #define DP83869_CFG2 0x14
26 #define DP83869_CTRL 0x1f
27 #define DP83869_CFG4 0x1e
29 /* Extended Registers */
30 #define DP83869_GEN_CFG3 0x0031
31 #define DP83869_RGMIICTL 0x0032
32 #define DP83869_STRAP_STS1 0x006e
33 #define DP83869_RGMIIDCTL 0x0086
34 #define DP83869_RXFCFG 0x0134
35 #define DP83869_RXFPMD1 0x0136
36 #define DP83869_RXFPMD2 0x0137
37 #define DP83869_RXFPMD3 0x0138
38 #define DP83869_RXFSOP1 0x0139
39 #define DP83869_RXFSOP2 0x013A
40 #define DP83869_RXFSOP3 0x013B
41 #define DP83869_IO_MUX_CFG 0x0170
42 #define DP83869_OP_MODE 0x01df
43 #define DP83869_FX_CTRL 0x0c00
45 #define DP83869_SW_RESET BIT(15)
46 #define DP83869_SW_RESTART BIT(14)
48 /* MICR Interrupt bits */
49 #define MII_DP83869_MICR_AN_ERR_INT_EN BIT(15)
50 #define MII_DP83869_MICR_SPEED_CHNG_INT_EN BIT(14)
51 #define MII_DP83869_MICR_DUP_MODE_CHNG_INT_EN BIT(13)
52 #define MII_DP83869_MICR_PAGE_RXD_INT_EN BIT(12)
53 #define MII_DP83869_MICR_AUTONEG_COMP_INT_EN BIT(11)
54 #define MII_DP83869_MICR_LINK_STS_CHNG_INT_EN BIT(10)
55 #define MII_DP83869_MICR_FALSE_CARRIER_INT_EN BIT(8)
56 #define MII_DP83869_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4)
57 #define MII_DP83869_MICR_WOL_INT_EN BIT(3)
58 #define MII_DP83869_MICR_XGMII_ERR_INT_EN BIT(2)
59 #define MII_DP83869_MICR_POL_CHNG_INT_EN BIT(1)
60 #define MII_DP83869_MICR_JABBER_INT_EN BIT(0)
62 #define MII_DP83869_BMCR_DEFAULT (BMCR_ANENABLE | \
66 #define MII_DP83869_FIBER_ADVERTISE (ADVERTISED_FIBRE | \
68 ADVERTISED_Asym_Pause)
70 /* This is the same bit mask as the BMCR so re-use the BMCR default */
71 #define DP83869_FX_CTRL_DEFAULT MII_DP83869_BMCR_DEFAULT
74 #define DP83869_CFG1_DEFAULT (ADVERTISE_1000HALF | \
75 ADVERTISE_1000FULL | \
79 #define DP83869_RGMII_TX_CLK_DELAY_EN BIT(1)
80 #define DP83869_RGMII_RX_CLK_DELAY_EN BIT(0)
83 #define DP83869_RGMII_CLK_DELAY_SHIFT 4
84 #define DP83869_CLK_DELAY_DEF 7
87 #define DP83869_STRAP_OP_MODE_MASK GENMASK(2, 0)
88 #define DP83869_STRAP_STS1_RESERVED BIT(11)
89 #define DP83869_STRAP_MIRROR_ENABLED BIT(12)
92 #define DP83869_RX_FIFO_SHIFT 12
93 #define DP83869_TX_FIFO_SHIFT 14
95 /* PHY_CTRL lower bytes 0x48 are declared as reserved */
96 #define DP83869_PHY_CTRL_DEFAULT 0x48
97 #define DP83869_PHYCR_FIFO_DEPTH_MASK GENMASK(15, 12)
98 #define DP83869_PHYCR_RESERVED_MASK BIT(11)
100 /* IO_MUX_CFG bits */
101 #define DP83869_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f
103 #define DP83869_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0
104 #define DP83869_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f
105 #define DP83869_IO_MUX_CFG_CLK_O_SEL_MASK (0x1f << 8)
106 #define DP83869_IO_MUX_CFG_CLK_O_SEL_SHIFT 8
109 #define DP83869_CFG3_PORT_MIRROR_EN BIT(0)
112 #define DP83869_INT_OE BIT(7)
115 #define DP83869_OP_MODE_MII BIT(5)
116 #define DP83869_SGMII_RGMII_BRIDGE BIT(6)
119 #define DP83869_WOL_MAGIC_EN BIT(0)
120 #define DP83869_WOL_PATTERN_EN BIT(1)
121 #define DP83869_WOL_BCAST_EN BIT(2)
122 #define DP83869_WOL_UCAST_EN BIT(4)
123 #define DP83869_WOL_SEC_EN BIT(5)
124 #define DP83869_WOL_ENH_MAC BIT(7)
127 #define DP83869_DOWNSHIFT_EN (BIT(8) | BIT(9))
128 #define DP83869_DOWNSHIFT_ATTEMPT_MASK (BIT(10) | BIT(11))
129 #define DP83869_DOWNSHIFT_1_COUNT_VAL 0
130 #define DP83869_DOWNSHIFT_2_COUNT_VAL 1
131 #define DP83869_DOWNSHIFT_4_COUNT_VAL 2
132 #define DP83869_DOWNSHIFT_8_COUNT_VAL 3
133 #define DP83869_DOWNSHIFT_1_COUNT 1
134 #define DP83869_DOWNSHIFT_2_COUNT 2
135 #define DP83869_DOWNSHIFT_4_COUNT 4
136 #define DP83869_DOWNSHIFT_8_COUNT 8
139 DP83869_PORT_MIRRORING_KEEP
,
140 DP83869_PORT_MIRRORING_EN
,
141 DP83869_PORT_MIRRORING_DIS
,
144 struct dp83869_private
{
151 bool rxctrl_strap_quirk
;
156 static int dp83869_config_aneg(struct phy_device
*phydev
)
158 struct dp83869_private
*dp83869
= phydev
->priv
;
160 if (dp83869
->mode
!= DP83869_RGMII_1000_BASE
)
161 return genphy_config_aneg(phydev
);
163 return genphy_c37_config_aneg(phydev
);
166 static int dp83869_read_status(struct phy_device
*phydev
)
168 struct dp83869_private
*dp83869
= phydev
->priv
;
172 if (dp83869
->mode
== DP83869_RGMII_1000_BASE
)
173 return genphy_c37_read_status(phydev
, &changed
);
175 ret
= genphy_read_status(phydev
);
179 if (dp83869
->mode
== DP83869_RGMII_100_BASE
) {
181 phydev
->speed
= SPEED_100
;
183 phydev
->speed
= SPEED_UNKNOWN
;
184 phydev
->duplex
= DUPLEX_UNKNOWN
;
191 static int dp83869_ack_interrupt(struct phy_device
*phydev
)
193 int err
= phy_read(phydev
, MII_DP83869_ISR
);
201 static int dp83869_config_intr(struct phy_device
*phydev
)
203 int micr_status
= 0, err
;
205 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
) {
206 err
= dp83869_ack_interrupt(phydev
);
210 micr_status
= phy_read(phydev
, MII_DP83869_MICR
);
215 (MII_DP83869_MICR_AN_ERR_INT_EN
|
216 MII_DP83869_MICR_SPEED_CHNG_INT_EN
|
217 MII_DP83869_MICR_AUTONEG_COMP_INT_EN
|
218 MII_DP83869_MICR_LINK_STS_CHNG_INT_EN
|
219 MII_DP83869_MICR_DUP_MODE_CHNG_INT_EN
|
220 MII_DP83869_MICR_SLEEP_MODE_CHNG_INT_EN
);
222 err
= phy_write(phydev
, MII_DP83869_MICR
, micr_status
);
224 err
= phy_write(phydev
, MII_DP83869_MICR
, micr_status
);
228 err
= dp83869_ack_interrupt(phydev
);
234 static irqreturn_t
dp83869_handle_interrupt(struct phy_device
*phydev
)
236 int irq_status
, irq_enabled
;
238 irq_status
= phy_read(phydev
, MII_DP83869_ISR
);
239 if (irq_status
< 0) {
244 irq_enabled
= phy_read(phydev
, MII_DP83869_MICR
);
245 if (irq_enabled
< 0) {
250 if (!(irq_status
& irq_enabled
))
253 phy_trigger_machine(phydev
);
258 static int dp83869_set_wol(struct phy_device
*phydev
,
259 struct ethtool_wolinfo
*wol
)
261 struct net_device
*ndev
= phydev
->attached_dev
;
262 int val_rxcfg
, val_micr
;
266 val_rxcfg
= phy_read_mmd(phydev
, DP83869_DEVADDR
, DP83869_RXFCFG
);
270 val_micr
= phy_read(phydev
, MII_DP83869_MICR
);
274 if (wol
->wolopts
& (WAKE_MAGIC
| WAKE_MAGICSECURE
| WAKE_UCAST
|
276 val_rxcfg
|= DP83869_WOL_ENH_MAC
;
277 val_micr
|= MII_DP83869_MICR_WOL_INT_EN
;
279 if (wol
->wolopts
& WAKE_MAGIC
||
280 wol
->wolopts
& WAKE_MAGICSECURE
) {
281 mac
= (const u8
*)ndev
->dev_addr
;
283 if (!is_valid_ether_addr(mac
))
286 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
288 mac
[1] << 8 | mac
[0]);
292 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
294 mac
[3] << 8 | mac
[2]);
298 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
300 mac
[5] << 8 | mac
[4]);
304 val_rxcfg
|= DP83869_WOL_MAGIC_EN
;
306 val_rxcfg
&= ~DP83869_WOL_MAGIC_EN
;
309 if (wol
->wolopts
& WAKE_MAGICSECURE
) {
310 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
312 (wol
->sopass
[1] << 8) | wol
->sopass
[0]);
316 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
318 (wol
->sopass
[3] << 8) | wol
->sopass
[2]);
321 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
323 (wol
->sopass
[5] << 8) | wol
->sopass
[4]);
327 val_rxcfg
|= DP83869_WOL_SEC_EN
;
329 val_rxcfg
&= ~DP83869_WOL_SEC_EN
;
332 if (wol
->wolopts
& WAKE_UCAST
)
333 val_rxcfg
|= DP83869_WOL_UCAST_EN
;
335 val_rxcfg
&= ~DP83869_WOL_UCAST_EN
;
337 if (wol
->wolopts
& WAKE_BCAST
)
338 val_rxcfg
|= DP83869_WOL_BCAST_EN
;
340 val_rxcfg
&= ~DP83869_WOL_BCAST_EN
;
342 val_rxcfg
&= ~DP83869_WOL_ENH_MAC
;
343 val_micr
&= ~MII_DP83869_MICR_WOL_INT_EN
;
346 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
, DP83869_RXFCFG
, val_rxcfg
);
350 return phy_write(phydev
, MII_DP83869_MICR
, val_micr
);
353 static void dp83869_get_wol(struct phy_device
*phydev
,
354 struct ethtool_wolinfo
*wol
)
356 int value
, sopass_val
;
358 wol
->supported
= (WAKE_UCAST
| WAKE_BCAST
| WAKE_MAGIC
|
362 value
= phy_read_mmd(phydev
, DP83869_DEVADDR
, DP83869_RXFCFG
);
364 phydev_err(phydev
, "Failed to read RX CFG\n");
368 if (value
& DP83869_WOL_UCAST_EN
)
369 wol
->wolopts
|= WAKE_UCAST
;
371 if (value
& DP83869_WOL_BCAST_EN
)
372 wol
->wolopts
|= WAKE_BCAST
;
374 if (value
& DP83869_WOL_MAGIC_EN
)
375 wol
->wolopts
|= WAKE_MAGIC
;
377 if (value
& DP83869_WOL_SEC_EN
) {
378 sopass_val
= phy_read_mmd(phydev
, DP83869_DEVADDR
,
380 if (sopass_val
< 0) {
381 phydev_err(phydev
, "Failed to read RX SOP 1\n");
385 wol
->sopass
[0] = (sopass_val
& 0xff);
386 wol
->sopass
[1] = (sopass_val
>> 8);
388 sopass_val
= phy_read_mmd(phydev
, DP83869_DEVADDR
,
390 if (sopass_val
< 0) {
391 phydev_err(phydev
, "Failed to read RX SOP 2\n");
395 wol
->sopass
[2] = (sopass_val
& 0xff);
396 wol
->sopass
[3] = (sopass_val
>> 8);
398 sopass_val
= phy_read_mmd(phydev
, DP83869_DEVADDR
,
400 if (sopass_val
< 0) {
401 phydev_err(phydev
, "Failed to read RX SOP 3\n");
405 wol
->sopass
[4] = (sopass_val
& 0xff);
406 wol
->sopass
[5] = (sopass_val
>> 8);
408 wol
->wolopts
|= WAKE_MAGICSECURE
;
411 if (!(value
& DP83869_WOL_ENH_MAC
))
415 static int dp83869_get_downshift(struct phy_device
*phydev
, u8
*data
)
417 int val
, cnt
, enable
, count
;
419 val
= phy_read(phydev
, DP83869_CFG2
);
423 enable
= FIELD_GET(DP83869_DOWNSHIFT_EN
, val
);
424 cnt
= FIELD_GET(DP83869_DOWNSHIFT_ATTEMPT_MASK
, val
);
427 case DP83869_DOWNSHIFT_1_COUNT_VAL
:
428 count
= DP83869_DOWNSHIFT_1_COUNT
;
430 case DP83869_DOWNSHIFT_2_COUNT_VAL
:
431 count
= DP83869_DOWNSHIFT_2_COUNT
;
433 case DP83869_DOWNSHIFT_4_COUNT_VAL
:
434 count
= DP83869_DOWNSHIFT_4_COUNT
;
436 case DP83869_DOWNSHIFT_8_COUNT_VAL
:
437 count
= DP83869_DOWNSHIFT_8_COUNT
;
443 *data
= enable
? count
: DOWNSHIFT_DEV_DISABLE
;
448 static int dp83869_set_downshift(struct phy_device
*phydev
, u8 cnt
)
452 if (cnt
> DP83869_DOWNSHIFT_8_COUNT
)
456 return phy_clear_bits(phydev
, DP83869_CFG2
,
457 DP83869_DOWNSHIFT_EN
);
460 case DP83869_DOWNSHIFT_1_COUNT
:
461 count
= DP83869_DOWNSHIFT_1_COUNT_VAL
;
463 case DP83869_DOWNSHIFT_2_COUNT
:
464 count
= DP83869_DOWNSHIFT_2_COUNT_VAL
;
466 case DP83869_DOWNSHIFT_4_COUNT
:
467 count
= DP83869_DOWNSHIFT_4_COUNT_VAL
;
469 case DP83869_DOWNSHIFT_8_COUNT
:
470 count
= DP83869_DOWNSHIFT_8_COUNT_VAL
;
474 "Downshift count must be 1, 2, 4 or 8\n");
478 val
= DP83869_DOWNSHIFT_EN
;
479 val
|= FIELD_PREP(DP83869_DOWNSHIFT_ATTEMPT_MASK
, count
);
481 return phy_modify(phydev
, DP83869_CFG2
,
482 DP83869_DOWNSHIFT_EN
| DP83869_DOWNSHIFT_ATTEMPT_MASK
,
486 static int dp83869_get_tunable(struct phy_device
*phydev
,
487 struct ethtool_tunable
*tuna
, void *data
)
490 case ETHTOOL_PHY_DOWNSHIFT
:
491 return dp83869_get_downshift(phydev
, data
);
497 static int dp83869_set_tunable(struct phy_device
*phydev
,
498 struct ethtool_tunable
*tuna
, const void *data
)
501 case ETHTOOL_PHY_DOWNSHIFT
:
502 return dp83869_set_downshift(phydev
, *(const u8
*)data
);
508 static int dp83869_config_port_mirroring(struct phy_device
*phydev
)
510 struct dp83869_private
*dp83869
= phydev
->priv
;
512 if (dp83869
->port_mirroring
== DP83869_PORT_MIRRORING_EN
)
513 return phy_set_bits_mmd(phydev
, DP83869_DEVADDR
,
515 DP83869_CFG3_PORT_MIRROR_EN
);
517 return phy_clear_bits_mmd(phydev
, DP83869_DEVADDR
,
519 DP83869_CFG3_PORT_MIRROR_EN
);
522 static int dp83869_set_strapped_mode(struct phy_device
*phydev
)
524 struct dp83869_private
*dp83869
= phydev
->priv
;
527 val
= phy_read_mmd(phydev
, DP83869_DEVADDR
, DP83869_STRAP_STS1
);
531 dp83869
->mode
= val
& DP83869_STRAP_OP_MODE_MASK
;
536 #if IS_ENABLED(CONFIG_OF_MDIO)
537 static const int dp83869_internal_delay
[] = {250, 500, 750, 1000, 1250, 1500,
538 1750, 2000, 2250, 2500, 2750, 3000,
539 3250, 3500, 3750, 4000};
541 static int dp83869_of_init(struct phy_device
*phydev
)
543 struct dp83869_private
*dp83869
= phydev
->priv
;
544 struct device
*dev
= &phydev
->mdio
.dev
;
545 struct device_node
*of_node
= dev
->of_node
;
546 int delay_size
= ARRAY_SIZE(dp83869_internal_delay
);
552 dp83869
->io_impedance
= -EINVAL
;
554 /* Optional configuration */
555 ret
= of_property_read_u32(of_node
, "ti,clk-output-sel",
556 &dp83869
->clk_output_sel
);
557 if (ret
|| dp83869
->clk_output_sel
> DP83869_CLK_O_SEL_REF_CLK
)
558 dp83869
->clk_output_sel
= DP83869_CLK_O_SEL_REF_CLK
;
560 ret
= of_property_read_u32(of_node
, "ti,op-mode", &dp83869
->mode
);
562 if (dp83869
->mode
< DP83869_RGMII_COPPER_ETHERNET
||
563 dp83869
->mode
> DP83869_SGMII_COPPER_ETHERNET
)
566 ret
= dp83869_set_strapped_mode(phydev
);
571 if (of_property_read_bool(of_node
, "ti,max-output-impedance"))
572 dp83869
->io_impedance
= DP83869_IO_MUX_CFG_IO_IMPEDANCE_MAX
;
573 else if (of_property_read_bool(of_node
, "ti,min-output-impedance"))
574 dp83869
->io_impedance
= DP83869_IO_MUX_CFG_IO_IMPEDANCE_MIN
;
576 if (of_property_read_bool(of_node
, "enet-phy-lane-swap")) {
577 dp83869
->port_mirroring
= DP83869_PORT_MIRRORING_EN
;
579 /* If the lane swap is not in the DT then check the straps */
580 ret
= phy_read_mmd(phydev
, DP83869_DEVADDR
, DP83869_STRAP_STS1
);
584 if (ret
& DP83869_STRAP_MIRROR_ENABLED
)
585 dp83869
->port_mirroring
= DP83869_PORT_MIRRORING_EN
;
587 dp83869
->port_mirroring
= DP83869_PORT_MIRRORING_DIS
;
592 if (of_property_read_u32(of_node
, "rx-fifo-depth",
593 &dp83869
->rx_fifo_depth
))
594 dp83869
->rx_fifo_depth
= DP83869_PHYCR_FIFO_DEPTH_4_B_NIB
;
596 if (of_property_read_u32(of_node
, "tx-fifo-depth",
597 &dp83869
->tx_fifo_depth
))
598 dp83869
->tx_fifo_depth
= DP83869_PHYCR_FIFO_DEPTH_4_B_NIB
;
600 dp83869
->rx_int_delay
= phy_get_internal_delay(phydev
, dev
,
601 &dp83869_internal_delay
[0],
603 if (dp83869
->rx_int_delay
< 0)
604 dp83869
->rx_int_delay
= DP83869_CLK_DELAY_DEF
;
606 dp83869
->tx_int_delay
= phy_get_internal_delay(phydev
, dev
,
607 &dp83869_internal_delay
[0],
609 if (dp83869
->tx_int_delay
< 0)
610 dp83869
->tx_int_delay
= DP83869_CLK_DELAY_DEF
;
615 static int dp83869_of_init(struct phy_device
*phydev
)
617 return dp83869_set_strapped_mode(phydev
);
619 #endif /* CONFIG_OF_MDIO */
621 static int dp83869_configure_rgmii(struct phy_device
*phydev
,
622 struct dp83869_private
*dp83869
)
626 if (phy_interface_is_rgmii(phydev
)) {
627 val
= phy_read(phydev
, MII_DP83869_PHYCTRL
);
631 val
&= ~DP83869_PHYCR_FIFO_DEPTH_MASK
;
632 val
|= (dp83869
->tx_fifo_depth
<< DP83869_TX_FIFO_SHIFT
);
633 val
|= (dp83869
->rx_fifo_depth
<< DP83869_RX_FIFO_SHIFT
);
635 ret
= phy_write(phydev
, MII_DP83869_PHYCTRL
, val
);
640 if (dp83869
->io_impedance
>= 0)
641 ret
= phy_modify_mmd(phydev
, DP83869_DEVADDR
,
643 DP83869_IO_MUX_CFG_IO_IMPEDANCE_CTRL
,
644 dp83869
->io_impedance
&
645 DP83869_IO_MUX_CFG_IO_IMPEDANCE_CTRL
);
650 static int dp83869_configure_fiber(struct phy_device
*phydev
,
651 struct dp83869_private
*dp83869
)
656 /* Only allow advertising what this PHY supports */
657 linkmode_and(phydev
->advertising
, phydev
->advertising
,
660 linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT
, phydev
->supported
);
662 if (dp83869
->mode
== DP83869_RGMII_1000_BASE
) {
663 linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT
,
666 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseFX_Full_BIT
,
668 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseFX_Half_BIT
,
671 /* Auto neg is not supported in 100base FX mode */
672 bmcr
= phy_read(phydev
, MII_BMCR
);
676 phydev
->autoneg
= AUTONEG_DISABLE
;
677 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->supported
);
678 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->advertising
);
680 if (bmcr
& BMCR_ANENABLE
) {
681 ret
= phy_modify(phydev
, MII_BMCR
, BMCR_ANENABLE
, 0);
687 /* Update advertising from supported */
688 linkmode_or(phydev
->advertising
, phydev
->advertising
,
694 static int dp83869_configure_mode(struct phy_device
*phydev
,
695 struct dp83869_private
*dp83869
)
700 if (dp83869
->mode
< DP83869_RGMII_COPPER_ETHERNET
||
701 dp83869
->mode
> DP83869_SGMII_COPPER_ETHERNET
)
704 /* Below init sequence for each operational mode is defined in
705 * section 9.4.8 of the datasheet.
707 phy_ctrl_val
= dp83869
->mode
;
708 if (phydev
->interface
== PHY_INTERFACE_MODE_MII
) {
709 if (dp83869
->mode
== DP83869_100M_MEDIA_CONVERT
||
710 dp83869
->mode
== DP83869_RGMII_100_BASE
||
711 dp83869
->mode
== DP83869_RGMII_COPPER_ETHERNET
) {
712 phy_ctrl_val
|= DP83869_OP_MODE_MII
;
714 phydev_err(phydev
, "selected op-mode is not valid with MII mode\n");
719 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
, DP83869_OP_MODE
,
724 ret
= phy_write(phydev
, MII_BMCR
, MII_DP83869_BMCR_DEFAULT
);
728 phy_ctrl_val
= (dp83869
->rx_fifo_depth
<< DP83869_RX_FIFO_SHIFT
|
729 dp83869
->tx_fifo_depth
<< DP83869_TX_FIFO_SHIFT
|
730 DP83869_PHY_CTRL_DEFAULT
);
732 switch (dp83869
->mode
) {
733 case DP83869_RGMII_COPPER_ETHERNET
:
734 ret
= phy_write(phydev
, MII_DP83869_PHYCTRL
,
739 ret
= phy_write(phydev
, MII_CTRL1000
, DP83869_CFG1_DEFAULT
);
743 ret
= dp83869_configure_rgmii(phydev
, dp83869
);
747 case DP83869_RGMII_SGMII_BRIDGE
:
748 ret
= phy_modify_mmd(phydev
, DP83869_DEVADDR
, DP83869_OP_MODE
,
749 DP83869_SGMII_RGMII_BRIDGE
,
750 DP83869_SGMII_RGMII_BRIDGE
);
754 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
755 DP83869_FX_CTRL
, DP83869_FX_CTRL_DEFAULT
);
760 case DP83869_1000M_MEDIA_CONVERT
:
761 ret
= phy_write(phydev
, MII_DP83869_PHYCTRL
,
766 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
767 DP83869_FX_CTRL
, DP83869_FX_CTRL_DEFAULT
);
771 case DP83869_100M_MEDIA_CONVERT
:
772 ret
= phy_write(phydev
, MII_DP83869_PHYCTRL
,
777 case DP83869_SGMII_COPPER_ETHERNET
:
778 ret
= phy_write(phydev
, MII_DP83869_PHYCTRL
,
783 ret
= phy_write(phydev
, MII_CTRL1000
, DP83869_CFG1_DEFAULT
);
787 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
,
788 DP83869_FX_CTRL
, DP83869_FX_CTRL_DEFAULT
);
793 case DP83869_RGMII_1000_BASE
:
794 case DP83869_RGMII_100_BASE
:
795 ret
= dp83869_configure_fiber(phydev
, dp83869
);
804 static int dp83869_config_init(struct phy_device
*phydev
)
806 struct dp83869_private
*dp83869
= phydev
->priv
;
809 /* Force speed optimization for the PHY even if it strapped */
810 ret
= phy_modify(phydev
, DP83869_CFG2
, DP83869_DOWNSHIFT_EN
,
811 DP83869_DOWNSHIFT_EN
);
815 ret
= dp83869_configure_mode(phydev
, dp83869
);
819 /* Enable Interrupt output INT_OE in CFG4 register */
820 if (phy_interrupt_is_valid(phydev
)) {
821 val
= phy_read(phydev
, DP83869_CFG4
);
822 val
|= DP83869_INT_OE
;
823 phy_write(phydev
, DP83869_CFG4
, val
);
826 if (dp83869
->port_mirroring
!= DP83869_PORT_MIRRORING_KEEP
)
827 dp83869_config_port_mirroring(phydev
);
829 /* Clock output selection if muxing property is set */
830 if (dp83869
->clk_output_sel
!= DP83869_CLK_O_SEL_REF_CLK
)
831 ret
= phy_modify_mmd(phydev
,
832 DP83869_DEVADDR
, DP83869_IO_MUX_CFG
,
833 DP83869_IO_MUX_CFG_CLK_O_SEL_MASK
,
834 dp83869
->clk_output_sel
<<
835 DP83869_IO_MUX_CFG_CLK_O_SEL_SHIFT
);
837 if (phy_interface_is_rgmii(phydev
)) {
838 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
, DP83869_RGMIIDCTL
,
839 dp83869
->rx_int_delay
|
840 dp83869
->tx_int_delay
<< DP83869_RGMII_CLK_DELAY_SHIFT
);
844 val
= phy_read_mmd(phydev
, DP83869_DEVADDR
, DP83869_RGMIICTL
);
845 val
|= (DP83869_RGMII_TX_CLK_DELAY_EN
|
846 DP83869_RGMII_RX_CLK_DELAY_EN
);
848 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
)
849 val
&= ~(DP83869_RGMII_TX_CLK_DELAY_EN
|
850 DP83869_RGMII_RX_CLK_DELAY_EN
);
852 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)
853 val
&= ~DP83869_RGMII_TX_CLK_DELAY_EN
;
855 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
)
856 val
&= ~DP83869_RGMII_RX_CLK_DELAY_EN
;
858 ret
= phy_write_mmd(phydev
, DP83869_DEVADDR
, DP83869_RGMIICTL
,
865 static int dp83869_probe(struct phy_device
*phydev
)
867 struct dp83869_private
*dp83869
;
870 dp83869
= devm_kzalloc(&phydev
->mdio
.dev
, sizeof(*dp83869
),
875 phydev
->priv
= dp83869
;
877 ret
= dp83869_of_init(phydev
);
881 if (dp83869
->mode
== DP83869_RGMII_100_BASE
||
882 dp83869
->mode
== DP83869_RGMII_1000_BASE
)
883 phydev
->port
= PORT_FIBRE
;
885 return dp83869_config_init(phydev
);
888 static int dp83869_phy_reset(struct phy_device
*phydev
)
892 ret
= phy_write(phydev
, DP83869_CTRL
, DP83869_SW_RESET
);
896 usleep_range(10, 20);
898 /* Global sw reset sets all registers to default.
899 * Need to set the registers in the PHY to the right config.
901 return dp83869_config_init(phydev
);
905 #define DP83869_PHY_DRIVER(_id, _name) \
907 PHY_ID_MATCH_MODEL(_id), \
909 .probe = dp83869_probe, \
910 .config_init = dp83869_config_init, \
911 .soft_reset = dp83869_phy_reset, \
912 .config_intr = dp83869_config_intr, \
913 .handle_interrupt = dp83869_handle_interrupt, \
914 .config_aneg = dp83869_config_aneg, \
915 .read_status = dp83869_read_status, \
916 .get_tunable = dp83869_get_tunable, \
917 .set_tunable = dp83869_set_tunable, \
918 .get_wol = dp83869_get_wol, \
919 .set_wol = dp83869_set_wol, \
920 .suspend = genphy_suspend, \
921 .resume = genphy_resume, \
924 static struct phy_driver dp83869_driver
[] = {
925 DP83869_PHY_DRIVER(DP83869_PHY_ID
, "TI DP83869"),
926 DP83869_PHY_DRIVER(DP83561_PHY_ID
, "TI DP83561-SP"),
929 module_phy_driver(dp83869_driver
);
931 static struct mdio_device_id __maybe_unused dp83869_tbl
[] = {
932 { PHY_ID_MATCH_MODEL(DP83869_PHY_ID
) },
933 { PHY_ID_MATCH_MODEL(DP83561_PHY_ID
) },
936 MODULE_DEVICE_TABLE(mdio
, dp83869_tbl
);
938 MODULE_DESCRIPTION("Texas Instruments DP83869 PHY driver");
939 MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com");
940 MODULE_LICENSE("GPL v2");