diff options
author | David Daney <david.daney@cavium.com> | 2012-06-27 03:33:38 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-06-28 00:23:25 -0400 |
commit | e9976d7c96423ac1991396aa82335206ded55bcf (patch) | |
tree | 394e2e0964b90e42e0f638b6fad6c1362a737d14 /drivers/net/phy/bcm87xx.c | |
parent | a30e2c1891296b5ee8de48430a07fdf8b818c661 (diff) |
netdev/phy: Add driver for Broadcom BCM87XX 10G Ethernet PHYs
Add a driver for BCM8706 and BCM8727 devices. These are a 10Gig PHYs
which use MII_ADDR_C45 addressing. They are always 10G full duplex, so
there is no autonegotiation. All we do is report link state and send
interrupts when it changes.
If the PHY has a device tree of_node associated with it, the
"broadcom,c45-reg-init" property is used to supply register
initialization values when config_init() is called.
Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/bcm87xx.c')
-rw-r--r-- | drivers/net/phy/bcm87xx.c | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/drivers/net/phy/bcm87xx.c b/drivers/net/phy/bcm87xx.c new file mode 100644 index 000000000000..f5f0562934db --- /dev/null +++ b/drivers/net/phy/bcm87xx.c | |||
@@ -0,0 +1,238 @@ | |||
1 | /* | ||
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive | ||
4 | * for more details. | ||
5 | * | ||
6 | * Copyright (C) 2011 - 2012 Cavium, Inc. | ||
7 | */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/phy.h> | ||
11 | #include <linux/of.h> | ||
12 | |||
13 | #define PHY_ID_BCM8706 0x0143bdc1 | ||
14 | #define PHY_ID_BCM8727 0x0143bff0 | ||
15 | |||
16 | #define BCM87XX_PMD_RX_SIGNAL_DETECT (MII_ADDR_C45 | 0x1000a) | ||
17 | #define BCM87XX_10GBASER_PCS_STATUS (MII_ADDR_C45 | 0x30020) | ||
18 | #define BCM87XX_XGXS_LANE_STATUS (MII_ADDR_C45 | 0x40018) | ||
19 | |||
20 | #define BCM87XX_LASI_CONTROL (MII_ADDR_C45 | 0x39002) | ||
21 | #define BCM87XX_LASI_STATUS (MII_ADDR_C45 | 0x39005) | ||
22 | |||
23 | #if IS_ENABLED(CONFIG_OF_MDIO) | ||
24 | /* Set and/or override some configuration registers based on the | ||
25 | * marvell,reg-init property stored in the of_node for the phydev. | ||
26 | * | ||
27 | * broadcom,c45-reg-init = <devid reg mask value>,...; | ||
28 | * | ||
29 | * There may be one or more sets of <devid reg mask value>: | ||
30 | * | ||
31 | * devid: which sub-device to use. | ||
32 | * reg: the register. | ||
33 | * mask: if non-zero, ANDed with existing register value. | ||
34 | * value: ORed with the masked value and written to the regiser. | ||
35 | * | ||
36 | */ | ||
37 | static int bcm87xx_of_reg_init(struct phy_device *phydev) | ||
38 | { | ||
39 | const __be32 *paddr; | ||
40 | const __be32 *paddr_end; | ||
41 | int len, ret; | ||
42 | |||
43 | if (!phydev->dev.of_node) | ||
44 | return 0; | ||
45 | |||
46 | paddr = of_get_property(phydev->dev.of_node, | ||
47 | "broadcom,c45-reg-init", &len); | ||
48 | if (!paddr) | ||
49 | return 0; | ||
50 | |||
51 | paddr_end = paddr + (len /= sizeof(*paddr)); | ||
52 | |||
53 | ret = 0; | ||
54 | |||
55 | while (paddr + 3 < paddr_end) { | ||
56 | u16 devid = be32_to_cpup(paddr++); | ||
57 | u16 reg = be32_to_cpup(paddr++); | ||
58 | u16 mask = be32_to_cpup(paddr++); | ||
59 | u16 val_bits = be32_to_cpup(paddr++); | ||
60 | int val; | ||
61 | u32 regnum = MII_ADDR_C45 | (devid << 16) | reg; | ||
62 | val = 0; | ||
63 | if (mask) { | ||
64 | val = phy_read(phydev, regnum); | ||
65 | if (val < 0) { | ||
66 | ret = val; | ||
67 | goto err; | ||
68 | } | ||
69 | val &= mask; | ||
70 | } | ||
71 | val |= val_bits; | ||
72 | |||
73 | ret = phy_write(phydev, regnum, val); | ||
74 | if (ret < 0) | ||
75 | goto err; | ||
76 | } | ||
77 | err: | ||
78 | return ret; | ||
79 | } | ||
80 | #else | ||
81 | static int bcm87xx_of_reg_init(struct phy_device *phydev) | ||
82 | { | ||
83 | return 0; | ||
84 | } | ||
85 | #endif /* CONFIG_OF_MDIO */ | ||
86 | |||
87 | static int bcm87xx_config_init(struct phy_device *phydev) | ||
88 | { | ||
89 | phydev->supported = SUPPORTED_10000baseR_FEC; | ||
90 | phydev->advertising = ADVERTISED_10000baseR_FEC; | ||
91 | phydev->state = PHY_NOLINK; | ||
92 | |||
93 | bcm87xx_of_reg_init(phydev); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static int bcm87xx_config_aneg(struct phy_device *phydev) | ||
99 | { | ||
100 | return -EINVAL; | ||
101 | } | ||
102 | |||
103 | static int bcm87xx_read_status(struct phy_device *phydev) | ||
104 | { | ||
105 | int rx_signal_detect; | ||
106 | int pcs_status; | ||
107 | int xgxs_lane_status; | ||
108 | |||
109 | rx_signal_detect = phy_read(phydev, BCM87XX_PMD_RX_SIGNAL_DETECT); | ||
110 | if (rx_signal_detect < 0) | ||
111 | return rx_signal_detect; | ||
112 | |||
113 | if ((rx_signal_detect & 1) == 0) | ||
114 | goto no_link; | ||
115 | |||
116 | pcs_status = phy_read(phydev, BCM87XX_10GBASER_PCS_STATUS); | ||
117 | if (pcs_status < 0) | ||
118 | return pcs_status; | ||
119 | |||
120 | if ((pcs_status & 1) == 0) | ||
121 | goto no_link; | ||
122 | |||
123 | xgxs_lane_status = phy_read(phydev, BCM87XX_XGXS_LANE_STATUS); | ||
124 | if (xgxs_lane_status < 0) | ||
125 | return xgxs_lane_status; | ||
126 | |||
127 | if ((xgxs_lane_status & 0x1000) == 0) | ||
128 | goto no_link; | ||
129 | |||
130 | phydev->speed = 10000; | ||
131 | phydev->link = 1; | ||
132 | phydev->duplex = 1; | ||
133 | return 0; | ||
134 | |||
135 | no_link: | ||
136 | phydev->link = 0; | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static int bcm87xx_config_intr(struct phy_device *phydev) | ||
141 | { | ||
142 | int reg, err; | ||
143 | |||
144 | reg = phy_read(phydev, BCM87XX_LASI_CONTROL); | ||
145 | |||
146 | if (reg < 0) | ||
147 | return reg; | ||
148 | |||
149 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
150 | reg |= 1; | ||
151 | else | ||
152 | reg &= ~1; | ||
153 | |||
154 | err = phy_write(phydev, BCM87XX_LASI_CONTROL, reg); | ||
155 | return err; | ||
156 | } | ||
157 | |||
158 | static int bcm87xx_did_interrupt(struct phy_device *phydev) | ||
159 | { | ||
160 | int reg; | ||
161 | |||
162 | reg = phy_read(phydev, BCM87XX_LASI_STATUS); | ||
163 | |||
164 | if (reg < 0) { | ||
165 | dev_err(&phydev->dev, | ||
166 | "Error: Read of BCM87XX_LASI_STATUS failed: %d\n", reg); | ||
167 | return 0; | ||
168 | } | ||
169 | return (reg & 1) != 0; | ||
170 | } | ||
171 | |||
172 | static int bcm87xx_ack_interrupt(struct phy_device *phydev) | ||
173 | { | ||
174 | /* Reading the LASI status clears it. */ | ||
175 | bcm87xx_did_interrupt(phydev); | ||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | static int bcm8706_match_phy_device(struct phy_device *phydev) | ||
180 | { | ||
181 | return phydev->c45_ids.device_ids[4] == PHY_ID_BCM8706; | ||
182 | } | ||
183 | |||
184 | static int bcm8727_match_phy_device(struct phy_device *phydev) | ||
185 | { | ||
186 | return phydev->c45_ids.device_ids[4] == PHY_ID_BCM8727; | ||
187 | } | ||
188 | |||
189 | static struct phy_driver bcm8706_driver = { | ||
190 | .phy_id = PHY_ID_BCM8706, | ||
191 | .phy_id_mask = 0xffffffff, | ||
192 | .name = "Broadcom BCM8706", | ||
193 | .flags = PHY_HAS_INTERRUPT, | ||
194 | .config_init = bcm87xx_config_init, | ||
195 | .config_aneg = bcm87xx_config_aneg, | ||
196 | .read_status = bcm87xx_read_status, | ||
197 | .ack_interrupt = bcm87xx_ack_interrupt, | ||
198 | .config_intr = bcm87xx_config_intr, | ||
199 | .did_interrupt = bcm87xx_did_interrupt, | ||
200 | .match_phy_device = bcm8706_match_phy_device, | ||
201 | .driver = { .owner = THIS_MODULE }, | ||
202 | }; | ||
203 | |||
204 | static struct phy_driver bcm8727_driver = { | ||
205 | .phy_id = PHY_ID_BCM8727, | ||
206 | .phy_id_mask = 0xffffffff, | ||
207 | .name = "Broadcom BCM8727", | ||
208 | .flags = PHY_HAS_INTERRUPT, | ||
209 | .config_init = bcm87xx_config_init, | ||
210 | .config_aneg = bcm87xx_config_aneg, | ||
211 | .read_status = bcm87xx_read_status, | ||
212 | .ack_interrupt = bcm87xx_ack_interrupt, | ||
213 | .config_intr = bcm87xx_config_intr, | ||
214 | .did_interrupt = bcm87xx_did_interrupt, | ||
215 | .match_phy_device = bcm8727_match_phy_device, | ||
216 | .driver = { .owner = THIS_MODULE }, | ||
217 | }; | ||
218 | |||
219 | static int __init bcm87xx_init(void) | ||
220 | { | ||
221 | int ret; | ||
222 | |||
223 | ret = phy_driver_register(&bcm8706_driver); | ||
224 | if (ret) | ||
225 | goto err; | ||
226 | |||
227 | ret = phy_driver_register(&bcm8727_driver); | ||
228 | err: | ||
229 | return ret; | ||
230 | } | ||
231 | module_init(bcm87xx_init); | ||
232 | |||
233 | static void __exit bcm87xx_exit(void) | ||
234 | { | ||
235 | phy_driver_unregister(&bcm8706_driver); | ||
236 | phy_driver_unregister(&bcm8727_driver); | ||
237 | } | ||
238 | module_exit(bcm87xx_exit); | ||