Linux 2.6.20.7
[linux/fpc-iii.git] / drivers / net / phy / lxt.c
blob69d2325f848c7ee55690f3dc7074cd7bd9142726
1 /*
2 * drivers/net/phy/lxt.c
4 * Driver for Intel LXT PHYs
6 * Author: Andy Fleming
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/sched.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
20 #include <linux/unistd.h>
21 #include <linux/slab.h>
22 #include <linux/interrupt.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/spinlock.h>
29 #include <linux/mm.h>
30 #include <linux/module.h>
31 #include <linux/mii.h>
32 #include <linux/ethtool.h>
33 #include <linux/phy.h>
35 #include <asm/io.h>
36 #include <asm/irq.h>
37 #include <asm/uaccess.h>
39 /* The Level one LXT970 is used by many boards */
41 #define MII_LXT970_IER 17 /* Interrupt Enable Register */
43 #define MII_LXT970_IER_IEN 0x0002
45 #define MII_LXT970_ISR 18 /* Interrupt Status Register */
47 #define MII_LXT970_CONFIG 19 /* Configuration Register */
49 /* ------------------------------------------------------------------------- */
50 /* The Level one LXT971 is used on some of my custom boards */
52 /* register definitions for the 971 */
53 #define MII_LXT971_IER 18 /* Interrupt Enable Register */
54 #define MII_LXT971_IER_IEN 0x00f2
56 #define MII_LXT971_ISR 19 /* Interrupt Status Register */
59 MODULE_DESCRIPTION("Intel LXT PHY driver");
60 MODULE_AUTHOR("Andy Fleming");
61 MODULE_LICENSE("GPL");
63 static int lxt970_ack_interrupt(struct phy_device *phydev)
65 int err;
67 err = phy_read(phydev, MII_BMSR);
69 if (err < 0)
70 return err;
72 err = phy_read(phydev, MII_LXT970_ISR);
74 if (err < 0)
75 return err;
77 return 0;
80 static int lxt970_config_intr(struct phy_device *phydev)
82 int err;
84 if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
85 err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN);
86 else
87 err = phy_write(phydev, MII_LXT970_IER, 0);
89 return err;
92 static int lxt970_config_init(struct phy_device *phydev)
94 int err;
96 err = phy_write(phydev, MII_LXT970_CONFIG, 0);
98 return err;
102 static int lxt971_ack_interrupt(struct phy_device *phydev)
104 int err = phy_read(phydev, MII_LXT971_ISR);
106 if (err < 0)
107 return err;
109 return 0;
112 static int lxt971_config_intr(struct phy_device *phydev)
114 int err;
116 if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
117 err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN);
118 else
119 err = phy_write(phydev, MII_LXT971_IER, 0);
121 return err;
124 static struct phy_driver lxt970_driver = {
125 .phy_id = 0x78100000,
126 .name = "LXT970",
127 .phy_id_mask = 0xfffffff0,
128 .features = PHY_BASIC_FEATURES,
129 .flags = PHY_HAS_INTERRUPT,
130 .config_init = lxt970_config_init,
131 .config_aneg = genphy_config_aneg,
132 .read_status = genphy_read_status,
133 .ack_interrupt = lxt970_ack_interrupt,
134 .config_intr = lxt970_config_intr,
135 .driver = { .owner = THIS_MODULE,},
138 static struct phy_driver lxt971_driver = {
139 .phy_id = 0x001378e0,
140 .name = "LXT971",
141 .phy_id_mask = 0xfffffff0,
142 .features = PHY_BASIC_FEATURES,
143 .flags = PHY_HAS_INTERRUPT,
144 .config_aneg = genphy_config_aneg,
145 .read_status = genphy_read_status,
146 .ack_interrupt = lxt971_ack_interrupt,
147 .config_intr = lxt971_config_intr,
148 .driver = { .owner = THIS_MODULE,},
151 static int __init lxt_init(void)
153 int ret;
155 ret = phy_driver_register(&lxt970_driver);
156 if (ret)
157 goto err1;
159 ret = phy_driver_register(&lxt971_driver);
160 if (ret)
161 goto err2;
162 return 0;
164 err2:
165 phy_driver_unregister(&lxt970_driver);
166 err1:
167 return ret;
170 static void __exit lxt_exit(void)
172 phy_driver_unregister(&lxt970_driver);
173 phy_driver_unregister(&lxt971_driver);
176 module_init(lxt_init);
177 module_exit(lxt_exit);