2 * drivers/net/phy/lxt.c
4 * Driver for Intel LXT PHYs
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/errno.h>
19 #include <linux/unistd.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/skbuff.h>
26 #include <linux/spinlock.h>
28 #include <linux/module.h>
29 #include <linux/mii.h>
30 #include <linux/ethtool.h>
31 #include <linux/phy.h>
35 #include <asm/uaccess.h>
37 /* The Level one LXT970 is used by many boards */
39 #define MII_LXT970_IER 17 /* Interrupt Enable Register */
41 #define MII_LXT970_IER_IEN 0x0002
43 #define MII_LXT970_ISR 18 /* Interrupt Status Register */
45 #define MII_LXT970_CONFIG 19 /* Configuration Register */
47 /* ------------------------------------------------------------------------- */
48 /* The Level one LXT971 is used on some of my custom boards */
50 /* register definitions for the 971 */
51 #define MII_LXT971_IER 18 /* Interrupt Enable Register */
52 #define MII_LXT971_IER_IEN 0x00f2
54 #define MII_LXT971_ISR 19 /* Interrupt Status Register */
56 /* register definitions for the 973 */
57 #define MII_LXT973_PCR 16 /* Port Configuration Register */
58 #define PCR_FIBER_SELECT 1
60 MODULE_DESCRIPTION("Intel LXT PHY driver");
61 MODULE_AUTHOR("Andy Fleming");
62 MODULE_LICENSE("GPL");
64 static int lxt970_ack_interrupt(struct phy_device
*phydev
)
68 err
= phy_read(phydev
, MII_BMSR
);
73 err
= phy_read(phydev
, MII_LXT970_ISR
);
81 static int lxt970_config_intr(struct phy_device
*phydev
)
83 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
84 return phy_write(phydev
, MII_LXT970_IER
, MII_LXT970_IER_IEN
);
86 return phy_write(phydev
, MII_LXT970_IER
, 0);
89 static int lxt970_config_init(struct phy_device
*phydev
)
93 err
= phy_write(phydev
, MII_LXT970_CONFIG
, 0);
99 static int lxt971_ack_interrupt(struct phy_device
*phydev
)
101 int err
= phy_read(phydev
, MII_LXT971_ISR
);
109 static int lxt971_config_intr(struct phy_device
*phydev
)
111 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
112 return phy_write(phydev
, MII_LXT971_IER
, MII_LXT971_IER_IEN
);
114 return phy_write(phydev
, MII_LXT971_IER
, 0);
118 * A2 version of LXT973 chip has an ERRATA: it randomly return the contents
119 * of the previous even register when you read a odd register regularly
122 static int lxt973a2_update_link(struct phy_device
*phydev
)
126 int retry
= 8; /* we try 8 times */
129 status
= phy_read(phydev
, MII_BMSR
);
134 control
= phy_read(phydev
, MII_BMCR
);
139 /* Read link and autonegotiation status */
140 status
= phy_read(phydev
, MII_BMSR
);
141 } while (status
>= 0 && retry
-- && status
== control
);
146 if ((status
& BMSR_LSTATUS
) == 0)
154 static int lxt973a2_read_status(struct phy_device
*phydev
)
161 /* Update the link, but return if there was an error */
162 err
= lxt973a2_update_link(phydev
);
166 if (AUTONEG_ENABLE
== phydev
->autoneg
) {
169 adv
= phy_read(phydev
, MII_ADVERTISE
);
175 lpa
= phy_read(phydev
, MII_LPA
);
180 /* If both registers are equal, it is suspect but not
181 * impossible, hence a new try
183 } while (lpa
== adv
&& retry
--);
187 phydev
->speed
= SPEED_10
;
188 phydev
->duplex
= DUPLEX_HALF
;
189 phydev
->pause
= phydev
->asym_pause
= 0;
191 if (lpagb
& (LPA_1000FULL
| LPA_1000HALF
)) {
192 phydev
->speed
= SPEED_1000
;
194 if (lpagb
& LPA_1000FULL
)
195 phydev
->duplex
= DUPLEX_FULL
;
196 } else if (lpa
& (LPA_100FULL
| LPA_100HALF
)) {
197 phydev
->speed
= SPEED_100
;
199 if (lpa
& LPA_100FULL
)
200 phydev
->duplex
= DUPLEX_FULL
;
202 if (lpa
& LPA_10FULL
)
203 phydev
->duplex
= DUPLEX_FULL
;
206 if (phydev
->duplex
== DUPLEX_FULL
) {
207 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
208 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
211 int bmcr
= phy_read(phydev
, MII_BMCR
);
216 if (bmcr
& BMCR_FULLDPLX
)
217 phydev
->duplex
= DUPLEX_FULL
;
219 phydev
->duplex
= DUPLEX_HALF
;
221 if (bmcr
& BMCR_SPEED1000
)
222 phydev
->speed
= SPEED_1000
;
223 else if (bmcr
& BMCR_SPEED100
)
224 phydev
->speed
= SPEED_100
;
226 phydev
->speed
= SPEED_10
;
228 phydev
->pause
= phydev
->asym_pause
= 0;
234 static int lxt973_probe(struct phy_device
*phydev
)
236 int val
= phy_read(phydev
, MII_LXT973_PCR
);
238 if (val
& PCR_FIBER_SELECT
) {
240 * If fiber is selected, then the only correct setting
241 * is 100Mbps, full duplex, and auto negotiation off.
243 val
= phy_read(phydev
, MII_BMCR
);
244 val
|= (BMCR_SPEED100
| BMCR_FULLDPLX
);
245 val
&= ~BMCR_ANENABLE
;
246 phy_write(phydev
, MII_BMCR
, val
);
247 /* Remember that the port is in fiber mode. */
248 phydev
->priv
= lxt973_probe
;
255 static int lxt973_config_aneg(struct phy_device
*phydev
)
257 /* Do nothing if port is in fiber mode. */
258 return phydev
->priv
? 0 : genphy_config_aneg(phydev
);
261 static struct phy_driver lxt97x_driver
[] = {
263 .phy_id
= 0x78100000,
265 .phy_id_mask
= 0xfffffff0,
266 .features
= PHY_BASIC_FEATURES
,
267 .flags
= PHY_HAS_INTERRUPT
,
268 .config_init
= lxt970_config_init
,
269 .config_aneg
= genphy_config_aneg
,
270 .read_status
= genphy_read_status
,
271 .ack_interrupt
= lxt970_ack_interrupt
,
272 .config_intr
= lxt970_config_intr
,
274 .phy_id
= 0x001378e0,
276 .phy_id_mask
= 0xfffffff0,
277 .features
= PHY_BASIC_FEATURES
,
278 .flags
= PHY_HAS_INTERRUPT
,
279 .config_aneg
= genphy_config_aneg
,
280 .read_status
= genphy_read_status
,
281 .ack_interrupt
= lxt971_ack_interrupt
,
282 .config_intr
= lxt971_config_intr
,
284 .phy_id
= 0x00137a10,
286 .phy_id_mask
= 0xffffffff,
287 .features
= PHY_BASIC_FEATURES
,
289 .probe
= lxt973_probe
,
290 .config_aneg
= lxt973_config_aneg
,
291 .read_status
= lxt973a2_read_status
,
293 .phy_id
= 0x00137a10,
295 .phy_id_mask
= 0xfffffff0,
296 .features
= PHY_BASIC_FEATURES
,
298 .probe
= lxt973_probe
,
299 .config_aneg
= lxt973_config_aneg
,
300 .read_status
= genphy_read_status
,
303 module_phy_driver(lxt97x_driver
);
305 static struct mdio_device_id __maybe_unused lxt_tbl
[] = {
306 { 0x78100000, 0xfffffff0 },
307 { 0x001378e0, 0xfffffff0 },
308 { 0x00137a10, 0xfffffff0 },
312 MODULE_DEVICE_TABLE(mdio
, lxt_tbl
);