1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the Texas Instruments DP83848 PHY
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
8 #include <linux/module.h>
11 #define TI_DP83848C_PHY_ID 0x20005ca0
12 #define TI_DP83620_PHY_ID 0x20005ce0
13 #define NS_DP83848C_PHY_ID 0x20005c90
14 #define TLK10X_PHY_ID 0x2000a210
17 #define DP83848_MICR 0x11 /* MII Interrupt Control Register */
18 #define DP83848_MISR 0x12 /* MII Interrupt Status Register */
20 /* MICR Register Fields */
21 #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */
22 #define DP83848_MICR_INTEN BIT(1) /* Interrupt Enable */
24 /* MISR Register Fields */
25 #define DP83848_MISR_RHF_INT_EN BIT(0) /* Receive Error Counter */
26 #define DP83848_MISR_FHF_INT_EN BIT(1) /* False Carrier Counter */
27 #define DP83848_MISR_ANC_INT_EN BIT(2) /* Auto-negotiation complete */
28 #define DP83848_MISR_DUP_INT_EN BIT(3) /* Duplex Status */
29 #define DP83848_MISR_SPD_INT_EN BIT(4) /* Speed status */
30 #define DP83848_MISR_LINK_INT_EN BIT(5) /* Link status */
31 #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */
32 #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */
34 #define DP83848_INT_EN_MASK \
35 (DP83848_MISR_ANC_INT_EN | \
36 DP83848_MISR_DUP_INT_EN | \
37 DP83848_MISR_SPD_INT_EN | \
38 DP83848_MISR_LINK_INT_EN)
40 static int dp83848_ack_interrupt(struct phy_device
*phydev
)
42 int err
= phy_read(phydev
, DP83848_MISR
);
44 return err
< 0 ? err
: 0;
47 static int dp83848_config_intr(struct phy_device
*phydev
)
51 control
= phy_read(phydev
, DP83848_MICR
);
55 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
) {
56 control
|= DP83848_MICR_INT_OE
;
57 control
|= DP83848_MICR_INTEN
;
59 ret
= phy_write(phydev
, DP83848_MISR
, DP83848_INT_EN_MASK
);
63 control
&= ~DP83848_MICR_INTEN
;
66 return phy_write(phydev
, DP83848_MICR
, control
);
69 static int dp83848_config_init(struct phy_device
*phydev
)
74 err
= genphy_config_init(phydev
);
78 /* DP83620 always reports Auto Negotiation Ability on BMSR. Instead,
79 * we check initial value of BMCR Auto negotiation enable bit
81 val
= phy_read(phydev
, MII_BMCR
);
82 if (!(val
& BMCR_ANENABLE
))
83 phydev
->autoneg
= AUTONEG_DISABLE
;
88 static struct mdio_device_id __maybe_unused dp83848_tbl
[] = {
89 { TI_DP83848C_PHY_ID
, 0xfffffff0 },
90 { NS_DP83848C_PHY_ID
, 0xfffffff0 },
91 { TI_DP83620_PHY_ID
, 0xfffffff0 },
92 { TLK10X_PHY_ID
, 0xfffffff0 },
95 MODULE_DEVICE_TABLE(mdio
, dp83848_tbl
);
97 #define DP83848_PHY_DRIVER(_id, _name, _config_init) \
100 .phy_id_mask = 0xfffffff0, \
102 /* PHY_BASIC_FEATURES */ \
104 .soft_reset = genphy_soft_reset, \
105 .config_init = _config_init, \
106 .suspend = genphy_suspend, \
107 .resume = genphy_resume, \
110 .ack_interrupt = dp83848_ack_interrupt, \
111 .config_intr = dp83848_config_intr, \
114 static struct phy_driver dp83848_driver
[] = {
115 DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID
, "TI DP83848C 10/100 Mbps PHY",
117 DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID
, "NS DP83848C 10/100 Mbps PHY",
119 DP83848_PHY_DRIVER(TI_DP83620_PHY_ID
, "TI DP83620 10/100 Mbps PHY",
120 dp83848_config_init
),
121 DP83848_PHY_DRIVER(TLK10X_PHY_ID
, "TI TLK10X 10/100 Mbps PHY",
124 module_phy_driver(dp83848_driver
);
126 MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver");
127 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
128 MODULE_LICENSE("GPL v2");