Commit | Line | Data |
---|---|---|
00db8189 AF |
1 | /* |
2 | * drivers/net/phy/lxt.c | |
3 | * | |
4 | * Driver for Intel LXT PHYs | |
5 | * | |
6 | * Author: Andy Fleming | |
7 | * | |
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | |
9 | * | |
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. | |
14 | * | |
15 | */ | |
16 | #include <linux/config.h> | |
17 | #include <linux/kernel.h> | |
18 | #include <linux/sched.h> | |
19 | #include <linux/string.h> | |
20 | #include <linux/errno.h> | |
21 | #include <linux/unistd.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/interrupt.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/netdevice.h> | |
27 | #include <linux/etherdevice.h> | |
28 | #include <linux/skbuff.h> | |
29 | #include <linux/spinlock.h> | |
30 | #include <linux/mm.h> | |
31 | #include <linux/module.h> | |
00db8189 AF |
32 | #include <linux/mii.h> |
33 | #include <linux/ethtool.h> | |
34 | #include <linux/phy.h> | |
35 | ||
36 | #include <asm/io.h> | |
37 | #include <asm/irq.h> | |
38 | #include <asm/uaccess.h> | |
39 | ||
40 | /* The Level one LXT970 is used by many boards */ | |
41 | ||
42 | #define MII_LXT970_IER 17 /* Interrupt Enable Register */ | |
43 | ||
44 | #define MII_LXT970_IER_IEN 0x0002 | |
45 | ||
46 | #define MII_LXT970_ISR 18 /* Interrupt Status Register */ | |
47 | ||
48 | #define MII_LXT970_CONFIG 19 /* Configuration Register */ | |
49 | ||
50 | /* ------------------------------------------------------------------------- */ | |
51 | /* The Level one LXT971 is used on some of my custom boards */ | |
52 | ||
53 | /* register definitions for the 971 */ | |
54 | #define MII_LXT971_IER 18 /* Interrupt Enable Register */ | |
55 | #define MII_LXT971_IER_IEN 0x00f2 | |
56 | ||
57 | #define MII_LXT971_ISR 19 /* Interrupt Status Register */ | |
58 | ||
59 | ||
60 | MODULE_DESCRIPTION("Intel LXT PHY driver"); | |
61 | MODULE_AUTHOR("Andy Fleming"); | |
62 | MODULE_LICENSE("GPL"); | |
63 | ||
64 | static int lxt970_ack_interrupt(struct phy_device *phydev) | |
65 | { | |
66 | int err; | |
67 | ||
68 | err = phy_read(phydev, MII_BMSR); | |
69 | ||
70 | if (err < 0) | |
71 | return err; | |
72 | ||
73 | err = phy_read(phydev, MII_LXT970_ISR); | |
74 | ||
75 | if (err < 0) | |
76 | return err; | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static int lxt970_config_intr(struct phy_device *phydev) | |
82 | { | |
83 | int err; | |
84 | ||
85 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | |
86 | err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN); | |
87 | else | |
88 | err = phy_write(phydev, MII_LXT970_IER, 0); | |
89 | ||
90 | return err; | |
91 | } | |
92 | ||
93 | static int lxt970_config_init(struct phy_device *phydev) | |
94 | { | |
95 | int err; | |
96 | ||
97 | err = phy_write(phydev, MII_LXT970_CONFIG, 0); | |
98 | ||
99 | return err; | |
100 | } | |
101 | ||
102 | ||
103 | static int lxt971_ack_interrupt(struct phy_device *phydev) | |
104 | { | |
105 | int err = phy_read(phydev, MII_LXT971_ISR); | |
106 | ||
107 | if (err < 0) | |
108 | return err; | |
109 | ||
110 | return 0; | |
111 | } | |
112 | ||
113 | static int lxt971_config_intr(struct phy_device *phydev) | |
114 | { | |
115 | int err; | |
116 | ||
117 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | |
118 | err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN); | |
119 | else | |
120 | err = phy_write(phydev, MII_LXT971_IER, 0); | |
121 | ||
122 | return err; | |
123 | } | |
124 | ||
125 | static struct phy_driver lxt970_driver = { | |
126 | .phy_id = 0x07810000, | |
127 | .name = "LXT970", | |
128 | .phy_id_mask = 0x0fffffff, | |
129 | .features = PHY_BASIC_FEATURES, | |
130 | .flags = PHY_HAS_INTERRUPT, | |
131 | .config_init = lxt970_config_init, | |
132 | .config_aneg = genphy_config_aneg, | |
133 | .read_status = genphy_read_status, | |
134 | .ack_interrupt = lxt970_ack_interrupt, | |
135 | .config_intr = lxt970_config_intr, | |
136 | .driver = { .owner = THIS_MODULE,}, | |
137 | }; | |
138 | ||
139 | static struct phy_driver lxt971_driver = { | |
140 | .phy_id = 0x0001378e, | |
141 | .name = "LXT971", | |
142 | .phy_id_mask = 0x0fffffff, | |
143 | .features = PHY_BASIC_FEATURES, | |
144 | .flags = PHY_HAS_INTERRUPT, | |
145 | .config_aneg = genphy_config_aneg, | |
146 | .read_status = genphy_read_status, | |
147 | .ack_interrupt = lxt971_ack_interrupt, | |
148 | .config_intr = lxt971_config_intr, | |
149 | .driver = { .owner = THIS_MODULE,}, | |
150 | }; | |
151 | ||
152 | static int __init lxt_init(void) | |
153 | { | |
154 | int ret; | |
155 | ||
156 | ret = phy_driver_register(&lxt970_driver); | |
157 | if (ret) | |
158 | goto err1; | |
159 | ||
160 | ret = phy_driver_register(&lxt971_driver); | |
161 | if (ret) | |
162 | goto err2; | |
163 | return 0; | |
164 | ||
165 | err2: | |
166 | phy_driver_unregister(&lxt970_driver); | |
167 | err1: | |
168 | return ret; | |
169 | } | |
170 | ||
171 | static void __exit lxt_exit(void) | |
172 | { | |
173 | phy_driver_unregister(&lxt970_driver); | |
174 | phy_driver_unregister(&lxt971_driver); | |
175 | } | |
176 | ||
177 | module_init(lxt_init); | |
178 | module_exit(lxt_exit); |