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);
125 static int lxt973_probe(struct phy_device
*phydev
)
127 int val
= phy_read(phydev
, MII_LXT973_PCR
);
129 if (val
& PCR_FIBER_SELECT
) {
131 * If fiber is selected, then the only correct setting
132 * is 100Mbps, full duplex, and auto negotiation off.
134 val
= phy_read(phydev
, MII_BMCR
);
135 val
|= (BMCR_SPEED100
| BMCR_FULLDPLX
);
136 val
&= ~BMCR_ANENABLE
;
137 phy_write(phydev
, MII_BMCR
, val
);
138 /* Remember that the port is in fiber mode. */
139 phydev
->priv
= lxt973_probe
;
146 static int lxt973_config_aneg(struct phy_device
*phydev
)
148 /* Do nothing if port is in fiber mode. */
149 return phydev
->priv
? 0 : genphy_config_aneg(phydev
);
152 static struct phy_driver lxt970_driver
= {
153 .phy_id
= 0x78100000,
155 .phy_id_mask
= 0xfffffff0,
156 .features
= PHY_BASIC_FEATURES
,
157 .flags
= PHY_HAS_INTERRUPT
,
158 .config_init
= lxt970_config_init
,
159 .config_aneg
= genphy_config_aneg
,
160 .read_status
= genphy_read_status
,
161 .ack_interrupt
= lxt970_ack_interrupt
,
162 .config_intr
= lxt970_config_intr
,
163 .driver
= { .owner
= THIS_MODULE
,},
166 static struct phy_driver lxt971_driver
= {
167 .phy_id
= 0x001378e0,
169 .phy_id_mask
= 0xfffffff0,
170 .features
= PHY_BASIC_FEATURES
,
171 .flags
= PHY_HAS_INTERRUPT
,
172 .config_aneg
= genphy_config_aneg
,
173 .read_status
= genphy_read_status
,
174 .ack_interrupt
= lxt971_ack_interrupt
,
175 .config_intr
= lxt971_config_intr
,
176 .driver
= { .owner
= THIS_MODULE
,},
179 static struct phy_driver lxt973_driver
= {
180 .phy_id
= 0x00137a10,
182 .phy_id_mask
= 0xfffffff0,
183 .features
= PHY_BASIC_FEATURES
,
185 .probe
= lxt973_probe
,
186 .config_aneg
= lxt973_config_aneg
,
187 .read_status
= genphy_read_status
,
188 .driver
= { .owner
= THIS_MODULE
,},
191 static int __init
lxt_init(void)
195 ret
= phy_driver_register(&lxt970_driver
);
199 ret
= phy_driver_register(&lxt971_driver
);
203 ret
= phy_driver_register(&lxt973_driver
);
209 phy_driver_unregister(&lxt971_driver
);
211 phy_driver_unregister(&lxt970_driver
);
216 static void __exit
lxt_exit(void)
218 phy_driver_unregister(&lxt970_driver
);
219 phy_driver_unregister(&lxt971_driver
);
220 phy_driver_unregister(&lxt973_driver
);
223 module_init(lxt_init
);
224 module_exit(lxt_exit
);
226 static struct mdio_device_id __maybe_unused lxt_tbl
[] = {
227 { 0x78100000, 0xfffffff0 },
228 { 0x001378e0, 0xfffffff0 },
229 { 0x00137a10, 0xfffffff0 },
233 MODULE_DEVICE_TABLE(mdio
, lxt_tbl
);