blob: 8561f2d4443bfc00670630e74e8c28f44442843a [file] [log] [blame]
Andrew Lunn5f857572019-01-21 19:10:19 +01001// SPDX-License-Identifier: GPL-2.0
Dan Murphy753c66e2020-09-03 14:51:12 -05002/* Driver for the Texas Instruments DP83867 PHY
Dan Murphy2a101542015-06-02 09:34:37 -05003 *
4 * Copyright (C) 2015 Texas Instruments Inc.
Dan Murphy2a101542015-06-02 09:34:37 -05005 */
6
7#include <linux/ethtool.h>
8#include <linux/kernel.h>
9#include <linux/mii.h>
10#include <linux/module.h>
11#include <linux/of.h>
12#include <linux/phy.h>
Max Uvarov72a7d452019-02-25 12:15:10 +030013#include <linux/delay.h>
Thomas Haemmerlecaabee52019-10-28 08:08:14 +000014#include <linux/netdevice.h>
15#include <linux/etherdevice.h>
Dan Murphycd26d722020-02-18 08:11:30 -060016#include <linux/bitfield.h>
Dan Murphy2a101542015-06-02 09:34:37 -050017
18#include <dt-bindings/net/ti-dp83867.h>
19
20#define DP83867_PHY_ID 0x2000a231
21#define DP83867_DEVADDR 0x1f
22
23#define MII_DP83867_PHYCTRL 0x10
Dan Murphycd26d722020-02-18 08:11:30 -060024#define MII_DP83867_PHYSTS 0x11
Dan Murphy2a101542015-06-02 09:34:37 -050025#define MII_DP83867_MICR 0x12
26#define MII_DP83867_ISR 0x13
Thomas Haemmerlecaabee52019-10-28 08:08:14 +000027#define DP83867_CFG2 0x14
Grygorii Strashko5ca7d1c2017-01-05 14:48:07 -060028#define DP83867_CFG3 0x1e
Thomas Haemmerlecaabee52019-10-28 08:08:14 +000029#define DP83867_CTRL 0x1f
Dan Murphy2a101542015-06-02 09:34:37 -050030
31/* Extended Registers */
Grygorii Strashko749f6f62020-03-17 20:04:54 +020032#define DP83867_FLD_THR_CFG 0x002e
33#define DP83867_CFG4 0x0031
Max Uvarov1a97a472019-05-28 13:00:50 +030034#define DP83867_CFG4_SGMII_ANEG_MASK (BIT(5) | BIT(6))
35#define DP83867_CFG4_SGMII_ANEG_TIMER_11MS (3 << 5)
36#define DP83867_CFG4_SGMII_ANEG_TIMER_800US (2 << 5)
37#define DP83867_CFG4_SGMII_ANEG_TIMER_2US (1 << 5)
38#define DP83867_CFG4_SGMII_ANEG_TIMER_16MS (0 << 5)
39
Dan Murphy2a101542015-06-02 09:34:37 -050040#define DP83867_RGMIICTL 0x0032
Lukasz Majewskiac6e0582017-02-07 06:20:24 +010041#define DP83867_STRAP_STS1 0x006E
Trent Piephoc11669a2019-05-22 18:43:23 +000042#define DP83867_STRAP_STS2 0x006f
Dan Murphy2a101542015-06-02 09:34:37 -050043#define DP83867_RGMIIDCTL 0x0086
Thomas Haemmerlecaabee52019-10-28 08:08:14 +000044#define DP83867_RXFCFG 0x0134
45#define DP83867_RXFPMD1 0x0136
46#define DP83867_RXFPMD2 0x0137
47#define DP83867_RXFPMD3 0x0138
48#define DP83867_RXFSOP1 0x0139
49#define DP83867_RXFSOP2 0x013A
50#define DP83867_RXFSOP3 0x013B
Mugunthan V Ned838fe2016-10-18 16:50:18 +053051#define DP83867_IO_MUX_CFG 0x0170
Vitaly Gaiduk507ddd52019-09-09 20:19:24 +030052#define DP83867_SGMIICTL 0x00D3
Max Uvarov333061b2019-05-28 13:00:49 +030053#define DP83867_10M_SGMII_CFG 0x016F
54#define DP83867_10M_SGMII_RATE_ADAPT_MASK BIT(7)
Dan Murphy2a101542015-06-02 09:34:37 -050055
56#define DP83867_SW_RESET BIT(15)
57#define DP83867_SW_RESTART BIT(14)
58
59/* MICR Interrupt bits */
60#define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15)
61#define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14)
62#define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13)
63#define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12)
64#define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11)
65#define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10)
66#define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8)
67#define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4)
68#define MII_DP83867_MICR_WOL_INT_EN BIT(3)
69#define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2)
70#define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1)
71#define MII_DP83867_MICR_JABBER_INT_EN BIT(0)
72
73/* RGMIICTL bits */
74#define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1)
75#define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0)
76
Vitaly Gaiduk507ddd52019-09-09 20:19:24 +030077/* SGMIICTL bits */
78#define DP83867_SGMII_TYPE BIT(14)
79
Thomas Haemmerlecaabee52019-10-28 08:08:14 +000080/* RXFCFG bits*/
81#define DP83867_WOL_MAGIC_EN BIT(0)
82#define DP83867_WOL_BCAST_EN BIT(2)
83#define DP83867_WOL_UCAST_EN BIT(4)
84#define DP83867_WOL_SEC_EN BIT(5)
85#define DP83867_WOL_ENH_MAC BIT(7)
86
Lukasz Majewskiac6e0582017-02-07 06:20:24 +010087/* STRAP_STS1 bits */
88#define DP83867_STRAP_STS1_RESERVED BIT(11)
89
Trent Piephoc11669a2019-05-22 18:43:23 +000090/* STRAP_STS2 bits */
91#define DP83867_STRAP_STS2_CLK_SKEW_TX_MASK GENMASK(6, 4)
92#define DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT 4
93#define DP83867_STRAP_STS2_CLK_SKEW_RX_MASK GENMASK(2, 0)
94#define DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT 0
95#define DP83867_STRAP_STS2_CLK_SKEW_NONE BIT(2)
Grygorii Strashko749f6f62020-03-17 20:04:54 +020096#define DP83867_STRAP_STS2_STRAP_FLD BIT(10)
Trent Piephoc11669a2019-05-22 18:43:23 +000097
Dan Murphy2a101542015-06-02 09:34:37 -050098/* PHY CTRL bits */
Dan Murphye02d1812019-12-09 14:10:25 -060099#define DP83867_PHYCR_TX_FIFO_DEPTH_SHIFT 14
100#define DP83867_PHYCR_RX_FIFO_DEPTH_SHIFT 12
Trent Piephof8bbf412019-05-22 18:43:26 +0000101#define DP83867_PHYCR_FIFO_DEPTH_MAX 0x03
Dan Murphye02d1812019-12-09 14:10:25 -0600102#define DP83867_PHYCR_TX_FIFO_DEPTH_MASK GENMASK(15, 14)
103#define DP83867_PHYCR_RX_FIFO_DEPTH_MASK GENMASK(13, 12)
Lukasz Majewskiac6e0582017-02-07 06:20:24 +0100104#define DP83867_PHYCR_RESERVED_MASK BIT(11)
Michael Grzeschik86ffe922020-01-16 14:16:31 +0100105#define DP83867_PHYCR_FORCE_LINK_GOOD BIT(10)
Dan Murphy2a101542015-06-02 09:34:37 -0500106
107/* RGMIIDCTL bits */
Trent Piephoc11669a2019-05-22 18:43:23 +0000108#define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf
Dan Murphy2a101542015-06-02 09:34:37 -0500109#define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200110#define DP83867_RGMII_TX_CLK_DELAY_INV (DP83867_RGMII_TX_CLK_DELAY_MAX + 1)
Trent Piephoc11669a2019-05-22 18:43:23 +0000111#define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf
112#define DP83867_RGMII_RX_CLK_DELAY_SHIFT 0
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200113#define DP83867_RGMII_RX_CLK_DELAY_INV (DP83867_RGMII_RX_CLK_DELAY_MAX + 1)
114
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530115/* IO_MUX_CFG bits */
Trent Piepho27708eb2019-05-22 18:43:25 +0000116#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MASK 0x1f
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530117#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0
118#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f
Trent Piepho13c83cf2019-05-22 18:43:22 +0000119#define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6)
Wadim Egorov9708fb62018-02-14 17:07:11 +0100120#define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK (0x1f << 8)
121#define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530122
Dan Murphycd26d722020-02-18 08:11:30 -0600123/* PHY STS bits */
124#define DP83867_PHYSTS_1000 BIT(15)
125#define DP83867_PHYSTS_100 BIT(14)
126#define DP83867_PHYSTS_DUPLEX BIT(13)
127#define DP83867_PHYSTS_LINK BIT(10)
128
129/* CFG2 bits */
130#define DP83867_DOWNSHIFT_EN (BIT(8) | BIT(9))
131#define DP83867_DOWNSHIFT_ATTEMPT_MASK (BIT(10) | BIT(11))
132#define DP83867_DOWNSHIFT_1_COUNT_VAL 0
133#define DP83867_DOWNSHIFT_2_COUNT_VAL 1
134#define DP83867_DOWNSHIFT_4_COUNT_VAL 2
135#define DP83867_DOWNSHIFT_8_COUNT_VAL 3
136#define DP83867_DOWNSHIFT_1_COUNT 1
137#define DP83867_DOWNSHIFT_2_COUNT 2
138#define DP83867_DOWNSHIFT_4_COUNT 4
139#define DP83867_DOWNSHIFT_8_COUNT 8
140
Grygorii Strashko5a7f08c2019-10-23 17:48:45 +0300141/* CFG3 bits */
142#define DP83867_CFG3_INT_OE BIT(7)
143#define DP83867_CFG3_ROBUST_AUTO_MDIX BIT(9)
144
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100145/* CFG4 bits */
146#define DP83867_CFG4_PORT_MIRROR_EN BIT(0)
147
Grygorii Strashko749f6f62020-03-17 20:04:54 +0200148/* FLD_THR_CFG */
149#define DP83867_FLD_THR_CFG_ENERGY_LOST_THR_MASK 0x7
150
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100151enum {
152 DP83867_PORT_MIRROING_KEEP,
153 DP83867_PORT_MIRROING_EN,
154 DP83867_PORT_MIRROING_DIS,
155};
156
Dan Murphy2a101542015-06-02 09:34:37 -0500157struct dp83867_private {
Trent Piepho1b9b2952019-05-22 18:43:24 +0000158 u32 rx_id_delay;
159 u32 tx_id_delay;
Dan Murphye02d1812019-12-09 14:10:25 -0600160 u32 tx_fifo_depth;
161 u32 rx_fifo_depth;
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530162 int io_impedance;
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100163 int port_mirroring;
Murali Karicheri37144472017-07-04 16:23:24 +0530164 bool rxctrl_strap_quirk;
Trent Piepho13c83cf2019-05-22 18:43:22 +0000165 bool set_clk_output;
166 u32 clk_output_sel;
Vitaly Gaiduk507ddd52019-09-09 20:19:24 +0300167 bool sgmii_ref_clk_en;
Dan Murphy2a101542015-06-02 09:34:37 -0500168};
169
170static int dp83867_ack_interrupt(struct phy_device *phydev)
171{
172 int err = phy_read(phydev, MII_DP83867_ISR);
173
174 if (err < 0)
175 return err;
176
177 return 0;
178}
179
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000180static int dp83867_set_wol(struct phy_device *phydev,
181 struct ethtool_wolinfo *wol)
182{
183 struct net_device *ndev = phydev->attached_dev;
184 u16 val_rxcfg, val_micr;
Jakub Kicinski86466cb2021-10-22 16:20:58 -0700185 const u8 *mac;
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000186
187 val_rxcfg = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RXFCFG);
188 val_micr = phy_read(phydev, MII_DP83867_MICR);
189
190 if (wol->wolopts & (WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_UCAST |
191 WAKE_BCAST)) {
192 val_rxcfg |= DP83867_WOL_ENH_MAC;
193 val_micr |= MII_DP83867_MICR_WOL_INT_EN;
194
195 if (wol->wolopts & WAKE_MAGIC) {
Jakub Kicinski86466cb2021-10-22 16:20:58 -0700196 mac = (const u8 *)ndev->dev_addr;
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000197
198 if (!is_valid_ether_addr(mac))
199 return -EINVAL;
200
201 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFPMD1,
202 (mac[1] << 8 | mac[0]));
203 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFPMD2,
204 (mac[3] << 8 | mac[2]));
205 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFPMD3,
206 (mac[5] << 8 | mac[4]));
207
208 val_rxcfg |= DP83867_WOL_MAGIC_EN;
209 } else {
210 val_rxcfg &= ~DP83867_WOL_MAGIC_EN;
211 }
212
213 if (wol->wolopts & WAKE_MAGICSECURE) {
214 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFSOP1,
215 (wol->sopass[1] << 8) | wol->sopass[0]);
Dan Murphy8b4a11c2020-09-02 14:27:04 -0500216 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFSOP2,
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000217 (wol->sopass[3] << 8) | wol->sopass[2]);
Dan Murphy8b4a11c2020-09-02 14:27:04 -0500218 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFSOP3,
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000219 (wol->sopass[5] << 8) | wol->sopass[4]);
220
221 val_rxcfg |= DP83867_WOL_SEC_EN;
222 } else {
223 val_rxcfg &= ~DP83867_WOL_SEC_EN;
224 }
225
226 if (wol->wolopts & WAKE_UCAST)
227 val_rxcfg |= DP83867_WOL_UCAST_EN;
228 else
229 val_rxcfg &= ~DP83867_WOL_UCAST_EN;
230
231 if (wol->wolopts & WAKE_BCAST)
232 val_rxcfg |= DP83867_WOL_BCAST_EN;
233 else
234 val_rxcfg &= ~DP83867_WOL_BCAST_EN;
235 } else {
236 val_rxcfg &= ~DP83867_WOL_ENH_MAC;
237 val_micr &= ~MII_DP83867_MICR_WOL_INT_EN;
238 }
239
240 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RXFCFG, val_rxcfg);
241 phy_write(phydev, MII_DP83867_MICR, val_micr);
242
243 return 0;
244}
245
246static void dp83867_get_wol(struct phy_device *phydev,
247 struct ethtool_wolinfo *wol)
248{
249 u16 value, sopass_val;
250
251 wol->supported = (WAKE_UCAST | WAKE_BCAST | WAKE_MAGIC |
252 WAKE_MAGICSECURE);
253 wol->wolopts = 0;
254
255 value = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RXFCFG);
256
257 if (value & DP83867_WOL_UCAST_EN)
258 wol->wolopts |= WAKE_UCAST;
259
260 if (value & DP83867_WOL_BCAST_EN)
261 wol->wolopts |= WAKE_BCAST;
262
263 if (value & DP83867_WOL_MAGIC_EN)
264 wol->wolopts |= WAKE_MAGIC;
265
266 if (value & DP83867_WOL_SEC_EN) {
267 sopass_val = phy_read_mmd(phydev, DP83867_DEVADDR,
268 DP83867_RXFSOP1);
269 wol->sopass[0] = (sopass_val & 0xff);
270 wol->sopass[1] = (sopass_val >> 8);
271
272 sopass_val = phy_read_mmd(phydev, DP83867_DEVADDR,
273 DP83867_RXFSOP2);
274 wol->sopass[2] = (sopass_val & 0xff);
275 wol->sopass[3] = (sopass_val >> 8);
276
277 sopass_val = phy_read_mmd(phydev, DP83867_DEVADDR,
278 DP83867_RXFSOP3);
279 wol->sopass[4] = (sopass_val & 0xff);
280 wol->sopass[5] = (sopass_val >> 8);
281
282 wol->wolopts |= WAKE_MAGICSECURE;
283 }
284
285 if (!(value & DP83867_WOL_ENH_MAC))
286 wol->wolopts = 0;
287}
288
Dan Murphy2a101542015-06-02 09:34:37 -0500289static int dp83867_config_intr(struct phy_device *phydev)
290{
Ioana Ciorneiaa2d6032020-11-23 17:38:14 +0200291 int micr_status, err;
Dan Murphy2a101542015-06-02 09:34:37 -0500292
293 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
Ioana Ciorneiaa2d6032020-11-23 17:38:14 +0200294 err = dp83867_ack_interrupt(phydev);
295 if (err)
296 return err;
297
Dan Murphy2a101542015-06-02 09:34:37 -0500298 micr_status = phy_read(phydev, MII_DP83867_MICR);
299 if (micr_status < 0)
300 return micr_status;
301
302 micr_status |=
303 (MII_DP83867_MICR_AN_ERR_INT_EN |
304 MII_DP83867_MICR_SPEED_CHNG_INT_EN |
Grygorii Strashko5ca7d1c2017-01-05 14:48:07 -0600305 MII_DP83867_MICR_AUTONEG_COMP_INT_EN |
306 MII_DP83867_MICR_LINK_STS_CHNG_INT_EN |
Dan Murphy2a101542015-06-02 09:34:37 -0500307 MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN |
308 MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN);
309
Ioana Ciorneiaa2d6032020-11-23 17:38:14 +0200310 err = phy_write(phydev, MII_DP83867_MICR, micr_status);
311 } else {
312 micr_status = 0x0;
313 err = phy_write(phydev, MII_DP83867_MICR, micr_status);
314 if (err)
315 return err;
316
317 err = dp83867_ack_interrupt(phydev);
Dan Murphy2a101542015-06-02 09:34:37 -0500318 }
319
Ioana Ciorneiaa2d6032020-11-23 17:38:14 +0200320 return err;
Dan Murphy2a101542015-06-02 09:34:37 -0500321}
322
Ioana Ciornei1d1ae3c2020-11-23 17:38:13 +0200323static irqreturn_t dp83867_handle_interrupt(struct phy_device *phydev)
324{
325 int irq_status, irq_enabled;
326
327 irq_status = phy_read(phydev, MII_DP83867_ISR);
328 if (irq_status < 0) {
329 phy_error(phydev);
330 return IRQ_NONE;
331 }
332
333 irq_enabled = phy_read(phydev, MII_DP83867_MICR);
334 if (irq_enabled < 0) {
335 phy_error(phydev);
336 return IRQ_NONE;
337 }
338
339 if (!(irq_status & irq_enabled))
340 return IRQ_NONE;
341
342 phy_trigger_machine(phydev);
343
344 return IRQ_HANDLED;
345}
346
Dan Murphycd26d722020-02-18 08:11:30 -0600347static int dp83867_read_status(struct phy_device *phydev)
348{
349 int status = phy_read(phydev, MII_DP83867_PHYSTS);
350 int ret;
351
352 ret = genphy_read_status(phydev);
353 if (ret)
354 return ret;
355
356 if (status < 0)
357 return status;
358
359 if (status & DP83867_PHYSTS_DUPLEX)
360 phydev->duplex = DUPLEX_FULL;
361 else
362 phydev->duplex = DUPLEX_HALF;
363
364 if (status & DP83867_PHYSTS_1000)
365 phydev->speed = SPEED_1000;
366 else if (status & DP83867_PHYSTS_100)
367 phydev->speed = SPEED_100;
368 else
369 phydev->speed = SPEED_10;
370
371 return 0;
372}
373
374static int dp83867_get_downshift(struct phy_device *phydev, u8 *data)
375{
376 int val, cnt, enable, count;
377
378 val = phy_read(phydev, DP83867_CFG2);
379 if (val < 0)
380 return val;
381
382 enable = FIELD_GET(DP83867_DOWNSHIFT_EN, val);
383 cnt = FIELD_GET(DP83867_DOWNSHIFT_ATTEMPT_MASK, val);
384
385 switch (cnt) {
386 case DP83867_DOWNSHIFT_1_COUNT_VAL:
387 count = DP83867_DOWNSHIFT_1_COUNT;
388 break;
389 case DP83867_DOWNSHIFT_2_COUNT_VAL:
390 count = DP83867_DOWNSHIFT_2_COUNT;
391 break;
392 case DP83867_DOWNSHIFT_4_COUNT_VAL:
393 count = DP83867_DOWNSHIFT_4_COUNT;
394 break;
395 case DP83867_DOWNSHIFT_8_COUNT_VAL:
396 count = DP83867_DOWNSHIFT_8_COUNT;
397 break;
398 default:
399 return -EINVAL;
Zheng Bindce38b72020-04-24 17:08:50 +0800400 }
Dan Murphycd26d722020-02-18 08:11:30 -0600401
402 *data = enable ? count : DOWNSHIFT_DEV_DISABLE;
403
404 return 0;
405}
406
407static int dp83867_set_downshift(struct phy_device *phydev, u8 cnt)
408{
409 int val, count;
410
411 if (cnt > DP83867_DOWNSHIFT_8_COUNT)
412 return -E2BIG;
413
414 if (!cnt)
415 return phy_clear_bits(phydev, DP83867_CFG2,
416 DP83867_DOWNSHIFT_EN);
417
418 switch (cnt) {
Dan Murphy753c66e2020-09-03 14:51:12 -0500419 case DP83867_DOWNSHIFT_1_COUNT:
420 count = DP83867_DOWNSHIFT_1_COUNT_VAL;
421 break;
422 case DP83867_DOWNSHIFT_2_COUNT:
423 count = DP83867_DOWNSHIFT_2_COUNT_VAL;
424 break;
425 case DP83867_DOWNSHIFT_4_COUNT:
426 count = DP83867_DOWNSHIFT_4_COUNT_VAL;
427 break;
428 case DP83867_DOWNSHIFT_8_COUNT:
429 count = DP83867_DOWNSHIFT_8_COUNT_VAL;
430 break;
431 default:
432 phydev_err(phydev,
433 "Downshift count must be 1, 2, 4 or 8\n");
434 return -EINVAL;
Zheng Bindce38b72020-04-24 17:08:50 +0800435 }
Dan Murphycd26d722020-02-18 08:11:30 -0600436
437 val = DP83867_DOWNSHIFT_EN;
438 val |= FIELD_PREP(DP83867_DOWNSHIFT_ATTEMPT_MASK, count);
439
440 return phy_modify(phydev, DP83867_CFG2,
441 DP83867_DOWNSHIFT_EN | DP83867_DOWNSHIFT_ATTEMPT_MASK,
442 val);
443}
444
445static int dp83867_get_tunable(struct phy_device *phydev,
Dan Murphy753c66e2020-09-03 14:51:12 -0500446 struct ethtool_tunable *tuna, void *data)
Dan Murphycd26d722020-02-18 08:11:30 -0600447{
448 switch (tuna->id) {
449 case ETHTOOL_PHY_DOWNSHIFT:
450 return dp83867_get_downshift(phydev, data);
451 default:
452 return -EOPNOTSUPP;
453 }
454}
455
456static int dp83867_set_tunable(struct phy_device *phydev,
Dan Murphy753c66e2020-09-03 14:51:12 -0500457 struct ethtool_tunable *tuna, const void *data)
Dan Murphycd26d722020-02-18 08:11:30 -0600458{
459 switch (tuna->id) {
460 case ETHTOOL_PHY_DOWNSHIFT:
461 return dp83867_set_downshift(phydev, *(const u8 *)data);
462 default:
463 return -EOPNOTSUPP;
464 }
465}
466
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100467static int dp83867_config_port_mirroring(struct phy_device *phydev)
468{
469 struct dp83867_private *dp83867 =
470 (struct dp83867_private *)phydev->priv;
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100471
472 if (dp83867->port_mirroring == DP83867_PORT_MIRROING_EN)
Heiner Kallweitb52c0182019-02-06 07:38:43 +0100473 phy_set_bits_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4,
474 DP83867_CFG4_PORT_MIRROR_EN);
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100475 else
Heiner Kallweitb52c0182019-02-06 07:38:43 +0100476 phy_clear_bits_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4,
477 DP83867_CFG4_PORT_MIRROR_EN);
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100478 return 0;
479}
480
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200481static int dp83867_verify_rgmii_cfg(struct phy_device *phydev)
482{
483 struct dp83867_private *dp83867 = phydev->priv;
484
485 /* Existing behavior was to use default pin strapping delay in rgmii
486 * mode, but rgmii should have meant no delay. Warn existing users.
487 */
488 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
489 const u16 val = phy_read_mmd(phydev, DP83867_DEVADDR,
490 DP83867_STRAP_STS2);
491 const u16 txskew = (val & DP83867_STRAP_STS2_CLK_SKEW_TX_MASK) >>
492 DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT;
493 const u16 rxskew = (val & DP83867_STRAP_STS2_CLK_SKEW_RX_MASK) >>
494 DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT;
495
496 if (txskew != DP83867_STRAP_STS2_CLK_SKEW_NONE ||
497 rxskew != DP83867_STRAP_STS2_CLK_SKEW_NONE)
498 phydev_warn(phydev,
499 "PHY has delays via pin strapping, but phy-mode = 'rgmii'\n"
500 "Should be 'rgmii-id' to use internal delays txskew:%x rxskew:%x\n",
501 txskew, rxskew);
502 }
503
504 /* RX delay *must* be specified if internal delay of RX is used. */
505 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
506 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) &&
507 dp83867->rx_id_delay == DP83867_RGMII_RX_CLK_DELAY_INV) {
508 phydev_err(phydev, "ti,rx-internal-delay must be specified\n");
509 return -EINVAL;
510 }
511
512 /* TX delay *must* be specified if internal delay of TX is used. */
513 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
514 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) &&
515 dp83867->tx_id_delay == DP83867_RGMII_TX_CLK_DELAY_INV) {
516 phydev_err(phydev, "ti,tx-internal-delay must be specified\n");
517 return -EINVAL;
518 }
519
520 return 0;
521}
522
Dan Murphy506de002020-06-05 09:01:05 -0500523#if IS_ENABLED(CONFIG_OF_MDIO)
Dan Murphy2a101542015-06-02 09:34:37 -0500524static int dp83867_of_init(struct phy_device *phydev)
525{
526 struct dp83867_private *dp83867 = phydev->priv;
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100527 struct device *dev = &phydev->mdio.dev;
Dan Murphy2a101542015-06-02 09:34:37 -0500528 struct device_node *of_node = dev->of_node;
529 int ret;
530
Andrew Lunn7bf9ae02015-12-07 04:38:58 +0100531 if (!of_node)
Dan Murphy2a101542015-06-02 09:34:37 -0500532 return -ENODEV;
533
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530534 /* Optional configuration */
Wadim Egorov9708fb62018-02-14 17:07:11 +0100535 ret = of_property_read_u32(of_node, "ti,clk-output-sel",
536 &dp83867->clk_output_sel);
Trent Piepho13c83cf2019-05-22 18:43:22 +0000537 /* If not set, keep default */
538 if (!ret) {
539 dp83867->set_clk_output = true;
540 /* Valid values are 0 to DP83867_CLK_O_SEL_REF_CLK or
541 * DP83867_CLK_O_SEL_OFF.
Wadim Egorov9708fb62018-02-14 17:07:11 +0100542 */
Trent Piepho13c83cf2019-05-22 18:43:22 +0000543 if (dp83867->clk_output_sel > DP83867_CLK_O_SEL_REF_CLK &&
544 dp83867->clk_output_sel != DP83867_CLK_O_SEL_OFF) {
545 phydev_err(phydev, "ti,clk-output-sel value %u out of range\n",
546 dp83867->clk_output_sel);
547 return -EINVAL;
548 }
549 }
Wadim Egorov9708fb62018-02-14 17:07:11 +0100550
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530551 if (of_property_read_bool(of_node, "ti,max-output-impedance"))
552 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
553 else if (of_property_read_bool(of_node, "ti,min-output-impedance"))
554 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
Trent Piepho27708eb2019-05-22 18:43:25 +0000555 else
556 dp83867->io_impedance = -1; /* leave at default */
Mugunthan V Ned838fe2016-10-18 16:50:18 +0530557
Murali Karicheri37144472017-07-04 16:23:24 +0530558 dp83867->rxctrl_strap_quirk = of_property_read_bool(of_node,
Dan Murphy753c66e2020-09-03 14:51:12 -0500559 "ti,dp83867-rxctrl-strap-quirk");
Murali Karicheri37144472017-07-04 16:23:24 +0530560
Vitaly Gaiduk507ddd52019-09-09 20:19:24 +0300561 dp83867->sgmii_ref_clk_en = of_property_read_bool(of_node,
Dan Murphy753c66e2020-09-03 14:51:12 -0500562 "ti,sgmii-ref-clock-output-enable");
Dan Murphy2a101542015-06-02 09:34:37 -0500563
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200564 dp83867->rx_id_delay = DP83867_RGMII_RX_CLK_DELAY_INV;
565 ret = of_property_read_u32(of_node, "ti,rx-internal-delay",
566 &dp83867->rx_id_delay);
567 if (!ret && dp83867->rx_id_delay > DP83867_RGMII_RX_CLK_DELAY_MAX) {
568 phydev_err(phydev,
569 "ti,rx-internal-delay value of %u out of range\n",
570 dp83867->rx_id_delay);
571 return -EINVAL;
Trent Piephoc11669a2019-05-22 18:43:23 +0000572 }
573
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200574 dp83867->tx_id_delay = DP83867_RGMII_TX_CLK_DELAY_INV;
575 ret = of_property_read_u32(of_node, "ti,tx-internal-delay",
576 &dp83867->tx_id_delay);
577 if (!ret && dp83867->tx_id_delay > DP83867_RGMII_TX_CLK_DELAY_MAX) {
578 phydev_err(phydev,
579 "ti,tx-internal-delay value of %u out of range\n",
580 dp83867->tx_id_delay);
581 return -EINVAL;
Trent Piephoc11669a2019-05-22 18:43:23 +0000582 }
Dan Murphy2a101542015-06-02 09:34:37 -0500583
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100584 if (of_property_read_bool(of_node, "enet-phy-lane-swap"))
585 dp83867->port_mirroring = DP83867_PORT_MIRROING_EN;
586
587 if (of_property_read_bool(of_node, "enet-phy-lane-no-swap"))
588 dp83867->port_mirroring = DP83867_PORT_MIRROING_DIS;
589
Trent Piephof8bbf412019-05-22 18:43:26 +0000590 ret = of_property_read_u32(of_node, "ti,fifo-depth",
Dan Murphye02d1812019-12-09 14:10:25 -0600591 &dp83867->tx_fifo_depth);
Trent Piephof8bbf412019-05-22 18:43:26 +0000592 if (ret) {
Dan Murphye02d1812019-12-09 14:10:25 -0600593 ret = of_property_read_u32(of_node, "tx-fifo-depth",
594 &dp83867->tx_fifo_depth);
595 if (ret)
596 dp83867->tx_fifo_depth =
597 DP83867_PHYCR_FIFO_DEPTH_4_B_NIB;
Trent Piephof8bbf412019-05-22 18:43:26 +0000598 }
Dan Murphye02d1812019-12-09 14:10:25 -0600599
600 if (dp83867->tx_fifo_depth > DP83867_PHYCR_FIFO_DEPTH_MAX) {
601 phydev_err(phydev, "tx-fifo-depth value %u out of range\n",
602 dp83867->tx_fifo_depth);
Trent Piephof8bbf412019-05-22 18:43:26 +0000603 return -EINVAL;
604 }
Dan Murphye02d1812019-12-09 14:10:25 -0600605
606 ret = of_property_read_u32(of_node, "rx-fifo-depth",
607 &dp83867->rx_fifo_depth);
608 if (ret)
609 dp83867->rx_fifo_depth = DP83867_PHYCR_FIFO_DEPTH_4_B_NIB;
610
611 if (dp83867->rx_fifo_depth > DP83867_PHYCR_FIFO_DEPTH_MAX) {
612 phydev_err(phydev, "rx-fifo-depth value %u out of range\n",
613 dp83867->rx_fifo_depth);
614 return -EINVAL;
615 }
616
Trent Piephof8bbf412019-05-22 18:43:26 +0000617 return 0;
Dan Murphy2a101542015-06-02 09:34:37 -0500618}
619#else
620static int dp83867_of_init(struct phy_device *phydev)
621{
Lay, Kuan Loon4dc08dc2021-10-13 14:59:41 +0800622 struct dp83867_private *dp83867 = phydev->priv;
623 u16 delay;
624
625 /* For non-OF device, the RX and TX ID values are either strapped
626 * or take from default value. So, we init RX & TX ID values here
627 * so that the RGMIIDCTL is configured correctly later in
628 * dp83867_config_init();
629 */
630 delay = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIIDCTL);
631 dp83867->rx_id_delay = delay & DP83867_RGMII_RX_CLK_DELAY_MAX;
632 dp83867->tx_id_delay = (delay >> DP83867_RGMII_TX_CLK_DELAY_SHIFT) &
633 DP83867_RGMII_TX_CLK_DELAY_MAX;
634
635 /* Per datasheet, IO impedance is default to 50-ohm, so we set the
636 * same here or else the default '0' means highest IO impedance
637 * which is wrong.
638 */
639 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN / 2;
640
Dan Murphy2a101542015-06-02 09:34:37 -0500641 return 0;
642}
643#endif /* CONFIG_OF_MDIO */
644
Trent Piepho565d9d22019-05-22 18:43:27 +0000645static int dp83867_probe(struct phy_device *phydev)
Dan Murphy2a101542015-06-02 09:34:37 -0500646{
647 struct dp83867_private *dp83867;
Trent Piepho565d9d22019-05-22 18:43:27 +0000648
649 dp83867 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83867),
650 GFP_KERNEL);
651 if (!dp83867)
652 return -ENOMEM;
653
654 phydev->priv = dp83867;
655
Grygorii Strashkoef87f7d2019-10-23 17:48:46 +0300656 return dp83867_of_init(phydev);
Trent Piepho565d9d22019-05-22 18:43:27 +0000657}
658
659static int dp83867_config_init(struct phy_device *phydev)
660{
661 struct dp83867_private *dp83867 = phydev->priv;
Lukasz Majewskiac6e0582017-02-07 06:20:24 +0100662 int ret, val, bs;
Stefan Hauserb291c412016-07-01 22:35:03 +0200663 u16 delay;
Dan Murphy2a101542015-06-02 09:34:37 -0500664
Dan Murphycd26d722020-02-18 08:11:30 -0600665 /* Force speed optimization for the PHY even if it strapped */
666 ret = phy_modify(phydev, DP83867_CFG2, DP83867_DOWNSHIFT_EN,
667 DP83867_DOWNSHIFT_EN);
668 if (ret)
669 return ret;
670
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200671 ret = dp83867_verify_rgmii_cfg(phydev);
672 if (ret)
673 return ret;
674
Murali Karicheri37144472017-07-04 16:23:24 +0530675 /* RX_DV/RX_CTRL strapped in mode 1 or mode 2 workaround */
Heiner Kallweitb52c0182019-02-06 07:38:43 +0100676 if (dp83867->rxctrl_strap_quirk)
677 phy_clear_bits_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4,
678 BIT(7));
Murali Karicheri37144472017-07-04 16:23:24 +0530679
Grygorii Strashko749f6f62020-03-17 20:04:54 +0200680 bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS2);
681 if (bs & DP83867_STRAP_STS2_STRAP_FLD) {
682 /* When using strap to enable FLD, the ENERGY_LOST_FLD_THR will
683 * be set to 0x2. This may causes the PHY link to be unstable -
684 * the default value 0x1 need to be restored.
685 */
686 ret = phy_modify_mmd(phydev, DP83867_DEVADDR,
687 DP83867_FLD_THR_CFG,
688 DP83867_FLD_THR_CFG_ENERGY_LOST_THR_MASK,
689 0x1);
690 if (ret)
691 return ret;
692 }
693
Dan Murphye02d1812019-12-09 14:10:25 -0600694 if (phy_interface_is_rgmii(phydev) ||
695 phydev->interface == PHY_INTERFACE_MODE_SGMII) {
696 val = phy_read(phydev, MII_DP83867_PHYCTRL);
697 if (val < 0)
698 return val;
699
700 val &= ~DP83867_PHYCR_TX_FIFO_DEPTH_MASK;
701 val |= (dp83867->tx_fifo_depth <<
702 DP83867_PHYCR_TX_FIFO_DEPTH_SHIFT);
703
704 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
705 val &= ~DP83867_PHYCR_RX_FIFO_DEPTH_MASK;
706 val |= (dp83867->rx_fifo_depth <<
707 DP83867_PHYCR_RX_FIFO_DEPTH_SHIFT);
708 }
709
710 ret = phy_write(phydev, MII_DP83867_PHYCTRL, val);
711 if (ret)
712 return ret;
713 }
714
Dan Murphy2a101542015-06-02 09:34:37 -0500715 if (phy_interface_is_rgmii(phydev)) {
Stefan Hauserb291c412016-07-01 22:35:03 +0200716 val = phy_read(phydev, MII_DP83867_PHYCTRL);
717 if (val < 0)
718 return val;
Lukasz Majewskiac6e0582017-02-07 06:20:24 +0100719
720 /* The code below checks if "port mirroring" N/A MODE4 has been
721 * enabled during power on bootstrap.
722 *
723 * Such N/A mode enabled by mistake can put PHY IC in some
724 * internal testing mode and disable RGMII transmission.
725 *
726 * In this particular case one needs to check STRAP_STS1
727 * register's bit 11 (marked as RESERVED).
728 */
729
Russell Kinga6d99fc2017-03-21 16:36:53 +0000730 bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS1);
Lukasz Majewskiac6e0582017-02-07 06:20:24 +0100731 if (bs & DP83867_STRAP_STS1_RESERVED)
732 val &= ~DP83867_PHYCR_RESERVED_MASK;
733
Stefan Hauserb291c412016-07-01 22:35:03 +0200734 ret = phy_write(phydev, MII_DP83867_PHYCTRL, val);
Dan Murphy2a101542015-06-02 09:34:37 -0500735 if (ret)
736 return ret;
Dan Murphy2a101542015-06-02 09:34:37 -0500737
David S. Millerb4b12b02019-05-31 10:49:43 -0700738 /* If rgmii mode with no internal delay is selected, we do NOT use
739 * aligned mode as one might expect. Instead we use the PHY's default
740 * based on pin strapping. And the "mode 0" default is to *use*
741 * internal delay with a value of 7 (2.00 ns).
742 *
743 * Set up RGMII delays
744 */
Russell Kinga6d99fc2017-03-21 16:36:53 +0000745 val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL);
Dan Murphy2a101542015-06-02 09:34:37 -0500746
Trent Piephoc11669a2019-05-22 18:43:23 +0000747 val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN | DP83867_RGMII_RX_CLK_DELAY_EN);
Dan Murphy2a101542015-06-02 09:34:37 -0500748 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
749 val |= (DP83867_RGMII_TX_CLK_DELAY_EN | DP83867_RGMII_RX_CLK_DELAY_EN);
750
751 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
752 val |= DP83867_RGMII_TX_CLK_DELAY_EN;
753
754 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
755 val |= DP83867_RGMII_RX_CLK_DELAY_EN;
756
Russell Kinga6d99fc2017-03-21 16:36:53 +0000757 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL, val);
Dan Murphy2a101542015-06-02 09:34:37 -0500758
Grygorii Strashkofafc5db2019-12-06 14:34:32 +0200759 delay = 0;
760 if (dp83867->rx_id_delay != DP83867_RGMII_RX_CLK_DELAY_INV)
761 delay |= dp83867->rx_id_delay;
762 if (dp83867->tx_id_delay != DP83867_RGMII_TX_CLK_DELAY_INV)
763 delay |= dp83867->tx_id_delay <<
764 DP83867_RGMII_TX_CLK_DELAY_SHIFT;
Dan Murphy2a101542015-06-02 09:34:37 -0500765
Russell Kinga6d99fc2017-03-21 16:36:53 +0000766 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIIDCTL,
767 delay);
Dan Murphy2a101542015-06-02 09:34:37 -0500768 }
769
Trent Piepho27708eb2019-05-22 18:43:25 +0000770 /* If specified, set io impedance */
771 if (dp83867->io_impedance >= 0)
772 phy_modify_mmd(phydev, DP83867_DEVADDR, DP83867_IO_MUX_CFG,
773 DP83867_IO_MUX_CFG_IO_IMPEDANCE_MASK,
774 dp83867->io_impedance);
775
Max Uvarov333061b2019-05-28 13:00:49 +0300776 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
777 /* For support SPEED_10 in SGMII mode
778 * DP83867_10M_SGMII_RATE_ADAPT bit
779 * has to be cleared by software. That
780 * does not affect SPEED_100 and
781 * SPEED_1000.
782 */
783 ret = phy_modify_mmd(phydev, DP83867_DEVADDR,
784 DP83867_10M_SGMII_CFG,
785 DP83867_10M_SGMII_RATE_ADAPT_MASK,
786 0);
787 if (ret)
788 return ret;
Max Uvarov1a97a472019-05-28 13:00:50 +0300789
790 /* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
791 * are 01). That is not enough to finalize autoneg on some
792 * devices. Increase this timer duration to maximum 16ms.
793 */
794 ret = phy_modify_mmd(phydev, DP83867_DEVADDR,
795 DP83867_CFG4,
796 DP83867_CFG4_SGMII_ANEG_MASK,
797 DP83867_CFG4_SGMII_ANEG_TIMER_16MS);
798
799 if (ret)
800 return ret;
Vitaly Gaiduk507ddd52019-09-09 20:19:24 +0300801
802 val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_SGMIICTL);
803 /* SGMII type is set to 4-wire mode by default.
804 * If we place appropriate property in dts (see above)
805 * switch on 6-wire mode.
806 */
807 if (dp83867->sgmii_ref_clk_en)
808 val |= DP83867_SGMII_TYPE;
809 else
810 val &= ~DP83867_SGMII_TYPE;
811 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_SGMIICTL, val);
Max Uvarov333061b2019-05-28 13:00:49 +0300812 }
813
Grygorii Strashko5a7f08c2019-10-23 17:48:45 +0300814 val = phy_read(phydev, DP83867_CFG3);
Grygorii Strashko5ca7d1c2017-01-05 14:48:07 -0600815 /* Enable Interrupt output INT_OE in CFG3 register */
Grygorii Strashko5a7f08c2019-10-23 17:48:45 +0300816 if (phy_interrupt_is_valid(phydev))
817 val |= DP83867_CFG3_INT_OE;
818
819 val |= DP83867_CFG3_ROBUST_AUTO_MDIX;
820 phy_write(phydev, DP83867_CFG3, val);
Grygorii Strashko5ca7d1c2017-01-05 14:48:07 -0600821
Lukasz Majewskifc6d39c2017-02-07 06:20:23 +0100822 if (dp83867->port_mirroring != DP83867_PORT_MIRROING_KEEP)
823 dp83867_config_port_mirroring(phydev);
824
Wadim Egorov9708fb62018-02-14 17:07:11 +0100825 /* Clock output selection if muxing property is set */
Trent Piepho13c83cf2019-05-22 18:43:22 +0000826 if (dp83867->set_clk_output) {
827 u16 mask = DP83867_IO_MUX_CFG_CLK_O_DISABLE;
828
829 if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) {
830 val = DP83867_IO_MUX_CFG_CLK_O_DISABLE;
831 } else {
832 mask |= DP83867_IO_MUX_CFG_CLK_O_SEL_MASK;
833 val = dp83867->clk_output_sel <<
834 DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT;
835 }
836
Heiner Kallweitb52c0182019-02-06 07:38:43 +0100837 phy_modify_mmd(phydev, DP83867_DEVADDR, DP83867_IO_MUX_CFG,
Trent Piepho13c83cf2019-05-22 18:43:22 +0000838 mask, val);
839 }
Wadim Egorov9708fb62018-02-14 17:07:11 +0100840
Dan Murphy2a101542015-06-02 09:34:37 -0500841 return 0;
842}
843
844static int dp83867_phy_reset(struct phy_device *phydev)
845{
846 int err;
847
Praneeth Bajjurida9ef502021-06-09 19:43:42 -0500848 err = phy_write(phydev, DP83867_CTRL, DP83867_SW_RESTART);
Dan Murphy2a101542015-06-02 09:34:37 -0500849 if (err < 0)
850 return err;
851
Max Uvarov72a7d452019-02-25 12:15:10 +0300852 usleep_range(10, 20);
853
Michael Grzeschik86ffe922020-01-16 14:16:31 +0100854 return phy_modify(phydev, MII_DP83867_PHYCTRL,
855 DP83867_PHYCR_FORCE_LINK_GOOD, 0);
Dan Murphy2a101542015-06-02 09:34:37 -0500856}
857
858static struct phy_driver dp83867_driver[] = {
859 {
860 .phy_id = DP83867_PHY_ID,
861 .phy_id_mask = 0xfffffff0,
862 .name = "TI DP83867",
Heiner Kallweitdcdecdc2019-04-12 20:47:03 +0200863 /* PHY_GBIT_FEATURES */
Dan Murphy2a101542015-06-02 09:34:37 -0500864
Trent Piepho565d9d22019-05-22 18:43:27 +0000865 .probe = dp83867_probe,
Dan Murphy2a101542015-06-02 09:34:37 -0500866 .config_init = dp83867_config_init,
867 .soft_reset = dp83867_phy_reset,
868
Dan Murphycd26d722020-02-18 08:11:30 -0600869 .read_status = dp83867_read_status,
870 .get_tunable = dp83867_get_tunable,
871 .set_tunable = dp83867_set_tunable,
872
Thomas Haemmerlecaabee52019-10-28 08:08:14 +0000873 .get_wol = dp83867_get_wol,
874 .set_wol = dp83867_set_wol,
875
Dan Murphy2a101542015-06-02 09:34:37 -0500876 /* IRQ related */
Dan Murphy2a101542015-06-02 09:34:37 -0500877 .config_intr = dp83867_config_intr,
Ioana Ciornei1d1ae3c2020-11-23 17:38:13 +0200878 .handle_interrupt = dp83867_handle_interrupt,
Dan Murphy2a101542015-06-02 09:34:37 -0500879
Dan Murphy2a101542015-06-02 09:34:37 -0500880 .suspend = genphy_suspend,
881 .resume = genphy_resume,
Dan Murphy2a101542015-06-02 09:34:37 -0500882 },
883};
884module_phy_driver(dp83867_driver);
885
886static struct mdio_device_id __maybe_unused dp83867_tbl[] = {
887 { DP83867_PHY_ID, 0xfffffff0 },
888 { }
889};
890
891MODULE_DEVICE_TABLE(mdio, dp83867_tbl);
892
893MODULE_DESCRIPTION("Texas Instruments DP83867 PHY driver");
894MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com");
Andrew Lunn5f857572019-01-21 19:10:19 +0100895MODULE_LICENSE("GPL v2");