1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2011 - 2012 Cavium, Inc.
6 #include <linux/module.h>
10 #define PHY_ID_BCM8706 0x0143bdc1
11 #define PHY_ID_BCM8727 0x0143bff0
13 #define BCM87XX_PMD_RX_SIGNAL_DETECT 0x000a
14 #define BCM87XX_10GBASER_PCS_STATUS 0x0020
15 #define BCM87XX_XGXS_LANE_STATUS 0x0018
17 #define BCM87XX_LASI_CONTROL 0x9002
18 #define BCM87XX_LASI_STATUS 0x9005
20 #if IS_ENABLED(CONFIG_OF_MDIO)
21 /* Set and/or override some configuration registers based on the
22 * broadcom,c45-reg-init property stored in the of_node for the phydev.
24 * broadcom,c45-reg-init = <devid reg mask value>,...;
26 * There may be one or more sets of <devid reg mask value>:
28 * devid: which sub-device to use.
30 * mask: if non-zero, ANDed with existing register value.
31 * value: ORed with the masked value and written to the regiser.
34 static int bcm87xx_of_reg_init(struct phy_device
*phydev
)
37 const __be32
*paddr_end
;
40 if (!phydev
->mdio
.dev
.of_node
)
43 paddr
= of_get_property(phydev
->mdio
.dev
.of_node
,
44 "broadcom,c45-reg-init", &len
);
48 paddr_end
= paddr
+ (len
/= sizeof(*paddr
));
52 while (paddr
+ 3 < paddr_end
) {
53 u16 devid
= be32_to_cpup(paddr
++);
54 u16 reg
= be32_to_cpup(paddr
++);
55 u16 mask
= be32_to_cpup(paddr
++);
56 u16 val_bits
= be32_to_cpup(paddr
++);
60 val
= phy_read_mmd(phydev
, devid
, reg
);
69 ret
= phy_write_mmd(phydev
, devid
, reg
, val
);
77 static int bcm87xx_of_reg_init(struct phy_device
*phydev
)
81 #endif /* CONFIG_OF_MDIO */
83 static int bcm87xx_get_features(struct phy_device
*phydev
)
85 linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseR_FEC_BIT
,
90 static int bcm87xx_config_init(struct phy_device
*phydev
)
92 return bcm87xx_of_reg_init(phydev
);
95 static int bcm87xx_config_aneg(struct phy_device
*phydev
)
100 static int bcm87xx_read_status(struct phy_device
*phydev
)
102 int rx_signal_detect
;
104 int xgxs_lane_status
;
106 rx_signal_detect
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
,
107 BCM87XX_PMD_RX_SIGNAL_DETECT
);
108 if (rx_signal_detect
< 0)
109 return rx_signal_detect
;
111 if ((rx_signal_detect
& 1) == 0)
114 pcs_status
= phy_read_mmd(phydev
, MDIO_MMD_PCS
,
115 BCM87XX_10GBASER_PCS_STATUS
);
119 if ((pcs_status
& 1) == 0)
122 xgxs_lane_status
= phy_read_mmd(phydev
, MDIO_MMD_PHYXS
,
123 BCM87XX_XGXS_LANE_STATUS
);
124 if (xgxs_lane_status
< 0)
125 return xgxs_lane_status
;
127 if ((xgxs_lane_status
& 0x1000) == 0)
130 phydev
->speed
= 10000;
140 static int bcm87xx_config_intr(struct phy_device
*phydev
)
144 reg
= phy_read_mmd(phydev
, MDIO_MMD_PCS
, BCM87XX_LASI_CONTROL
);
149 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
) {
150 err
= phy_read_mmd(phydev
, MDIO_MMD_PCS
, BCM87XX_LASI_STATUS
);
155 err
= phy_write_mmd(phydev
, MDIO_MMD_PCS
,
156 BCM87XX_LASI_CONTROL
, reg
);
159 err
= phy_write_mmd(phydev
, MDIO_MMD_PCS
,
160 BCM87XX_LASI_CONTROL
, reg
);
164 err
= phy_read_mmd(phydev
, MDIO_MMD_PCS
, BCM87XX_LASI_STATUS
);
170 static irqreturn_t
bcm87xx_handle_interrupt(struct phy_device
*phydev
)
174 irq_status
= phy_read(phydev
, BCM87XX_LASI_STATUS
);
175 if (irq_status
< 0) {
183 phy_trigger_machine(phydev
);
188 static int bcm8706_match_phy_device(struct phy_device
*phydev
)
190 return phydev
->c45_ids
.device_ids
[4] == PHY_ID_BCM8706
;
193 static int bcm8727_match_phy_device(struct phy_device
*phydev
)
195 return phydev
->c45_ids
.device_ids
[4] == PHY_ID_BCM8727
;
198 static struct phy_driver bcm87xx_driver
[] = {
200 .phy_id
= PHY_ID_BCM8706
,
201 .phy_id_mask
= 0xffffffff,
202 .name
= "Broadcom BCM8706",
203 .get_features
= bcm87xx_get_features
,
204 .config_init
= bcm87xx_config_init
,
205 .config_aneg
= bcm87xx_config_aneg
,
206 .read_status
= bcm87xx_read_status
,
207 .config_intr
= bcm87xx_config_intr
,
208 .handle_interrupt
= bcm87xx_handle_interrupt
,
209 .match_phy_device
= bcm8706_match_phy_device
,
211 .phy_id
= PHY_ID_BCM8727
,
212 .phy_id_mask
= 0xffffffff,
213 .name
= "Broadcom BCM8727",
214 .get_features
= bcm87xx_get_features
,
215 .config_init
= bcm87xx_config_init
,
216 .config_aneg
= bcm87xx_config_aneg
,
217 .read_status
= bcm87xx_read_status
,
218 .config_intr
= bcm87xx_config_intr
,
219 .handle_interrupt
= bcm87xx_handle_interrupt
,
220 .match_phy_device
= bcm8727_match_phy_device
,
223 module_phy_driver(bcm87xx_driver
);
225 MODULE_LICENSE("GPL v2");
226 MODULE_DESCRIPTION("Broadcom BCM87xx PHY driver");