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
)
85 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
86 err
= phy_write(phydev
, MII_LXT970_IER
, MII_LXT970_IER_IEN
);
88 err
= phy_write(phydev
, MII_LXT970_IER
, 0);
93 static int lxt970_config_init(struct phy_device
*phydev
)
97 err
= phy_write(phydev
, MII_LXT970_CONFIG
, 0);
103 static int lxt971_ack_interrupt(struct phy_device
*phydev
)
105 int err
= phy_read(phydev
, MII_LXT971_ISR
);
113 static int lxt971_config_intr(struct phy_device
*phydev
)
117 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
118 err
= phy_write(phydev
, MII_LXT971_IER
, MII_LXT971_IER_IEN
);
120 err
= phy_write(phydev
, MII_LXT971_IER
, 0);
126 * A2 version of LXT973 chip has an ERRATA: it randomly return the contents
127 * of the previous even register when you read a odd register regularly
130 static int lxt973a2_update_link(struct phy_device
*phydev
)
134 int retry
= 8; /* we try 8 times */
137 status
= phy_read(phydev
, MII_BMSR
);
142 control
= phy_read(phydev
, MII_BMCR
);
147 /* Read link and autonegotiation status */
148 status
= phy_read(phydev
, MII_BMSR
);
149 } while (status
>= 0 && retry
-- && status
== control
);
154 if ((status
& BMSR_LSTATUS
) == 0)
162 static int lxt973a2_read_status(struct phy_device
*phydev
)
169 /* Update the link, but return if there was an error */
170 err
= lxt973a2_update_link(phydev
);
174 if (AUTONEG_ENABLE
== phydev
->autoneg
) {
177 adv
= phy_read(phydev
, MII_ADVERTISE
);
183 lpa
= phy_read(phydev
, MII_LPA
);
188 /* If both registers are equal, it is suspect but not
189 * impossible, hence a new try
191 } while (lpa
== adv
&& retry
--);
195 phydev
->speed
= SPEED_10
;
196 phydev
->duplex
= DUPLEX_HALF
;
197 phydev
->pause
= phydev
->asym_pause
= 0;
199 if (lpagb
& (LPA_1000FULL
| LPA_1000HALF
)) {
200 phydev
->speed
= SPEED_1000
;
202 if (lpagb
& LPA_1000FULL
)
203 phydev
->duplex
= DUPLEX_FULL
;
204 } else if (lpa
& (LPA_100FULL
| LPA_100HALF
)) {
205 phydev
->speed
= SPEED_100
;
207 if (lpa
& LPA_100FULL
)
208 phydev
->duplex
= DUPLEX_FULL
;
210 if (lpa
& LPA_10FULL
)
211 phydev
->duplex
= DUPLEX_FULL
;
214 if (phydev
->duplex
== DUPLEX_FULL
) {
215 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
216 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
219 int bmcr
= phy_read(phydev
, MII_BMCR
);
224 if (bmcr
& BMCR_FULLDPLX
)
225 phydev
->duplex
= DUPLEX_FULL
;
227 phydev
->duplex
= DUPLEX_HALF
;
229 if (bmcr
& BMCR_SPEED1000
)
230 phydev
->speed
= SPEED_1000
;
231 else if (bmcr
& BMCR_SPEED100
)
232 phydev
->speed
= SPEED_100
;
234 phydev
->speed
= SPEED_10
;
236 phydev
->pause
= phydev
->asym_pause
= 0;
242 static int lxt973_probe(struct phy_device
*phydev
)
244 int val
= phy_read(phydev
, MII_LXT973_PCR
);
246 if (val
& PCR_FIBER_SELECT
) {
248 * If fiber is selected, then the only correct setting
249 * is 100Mbps, full duplex, and auto negotiation off.
251 val
= phy_read(phydev
, MII_BMCR
);
252 val
|= (BMCR_SPEED100
| BMCR_FULLDPLX
);
253 val
&= ~BMCR_ANENABLE
;
254 phy_write(phydev
, MII_BMCR
, val
);
255 /* Remember that the port is in fiber mode. */
256 phydev
->priv
= lxt973_probe
;
263 static int lxt973_config_aneg(struct phy_device
*phydev
)
265 /* Do nothing if port is in fiber mode. */
266 return phydev
->priv
? 0 : genphy_config_aneg(phydev
);
269 static struct phy_driver lxt97x_driver
[] = {
271 .phy_id
= 0x78100000,
273 .phy_id_mask
= 0xfffffff0,
274 .features
= PHY_BASIC_FEATURES
,
275 .flags
= PHY_HAS_INTERRUPT
,
276 .config_init
= lxt970_config_init
,
277 .config_aneg
= genphy_config_aneg
,
278 .read_status
= genphy_read_status
,
279 .ack_interrupt
= lxt970_ack_interrupt
,
280 .config_intr
= lxt970_config_intr
,
281 .driver
= { .owner
= THIS_MODULE
,},
283 .phy_id
= 0x001378e0,
285 .phy_id_mask
= 0xfffffff0,
286 .features
= PHY_BASIC_FEATURES
,
287 .flags
= PHY_HAS_INTERRUPT
,
288 .config_aneg
= genphy_config_aneg
,
289 .read_status
= genphy_read_status
,
290 .ack_interrupt
= lxt971_ack_interrupt
,
291 .config_intr
= lxt971_config_intr
,
292 .driver
= { .owner
= THIS_MODULE
,},
294 .phy_id
= 0x00137a10,
296 .phy_id_mask
= 0xffffffff,
297 .features
= PHY_BASIC_FEATURES
,
299 .probe
= lxt973_probe
,
300 .config_aneg
= lxt973_config_aneg
,
301 .read_status
= lxt973a2_read_status
,
302 .driver
= { .owner
= THIS_MODULE
,},
304 .phy_id
= 0x00137a10,
306 .phy_id_mask
= 0xfffffff0,
307 .features
= PHY_BASIC_FEATURES
,
309 .probe
= lxt973_probe
,
310 .config_aneg
= lxt973_config_aneg
,
311 .read_status
= genphy_read_status
,
312 .driver
= { .owner
= THIS_MODULE
,},
315 module_phy_driver(lxt97x_driver
);
317 static struct mdio_device_id __maybe_unused lxt_tbl
[] = {
318 { 0x78100000, 0xfffffff0 },
319 { 0x001378e0, 0xfffffff0 },
320 { 0x00137a10, 0xfffffff0 },
324 MODULE_DEVICE_TABLE(mdio
, lxt_tbl
);