2 * drivers/net/phy/micrel.c
4 * Driver for Micrel PHYs
6 * Author: David J. Choi
8 * Copyright (c) 2010 Micrel, 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.
15 * Support : ksz9021 1000/100/10 phy from Micrel
16 * ks8001, ks8737, ks8721, ks8041, ks8051 100/10 phy
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/phy.h>
23 #define PHY_ID_KSZ9021 0x00221611
24 #define PHY_ID_KS8737 0x00221720
25 #define PHY_ID_KS8041 0x00221510
26 #define PHY_ID_KS8051 0x00221550
27 /* both for ks8001 Rev. A/B, and for ks8721 Rev 3. */
28 #define PHY_ID_KS8001 0x0022161A
30 /* general Interrupt control/status reg in vendor specific block. */
31 #define MII_KSZPHY_INTCS 0x1B
32 #define KSZPHY_INTCS_JABBER (1 << 15)
33 #define KSZPHY_INTCS_RECEIVE_ERR (1 << 14)
34 #define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13)
35 #define KSZPHY_INTCS_PARELLEL (1 << 12)
36 #define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11)
37 #define KSZPHY_INTCS_LINK_DOWN (1 << 10)
38 #define KSZPHY_INTCS_REMOTE_FAULT (1 << 9)
39 #define KSZPHY_INTCS_LINK_UP (1 << 8)
40 #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\
41 KSZPHY_INTCS_LINK_DOWN)
43 /* general PHY control reg in vendor specific block. */
44 #define MII_KSZPHY_CTRL 0x1F
45 /* bitmap of PHY register to set interrupt mode */
46 #define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9)
47 #define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14)
48 #define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14)
50 static int kszphy_ack_interrupt(struct phy_device
*phydev
)
52 /* bit[7..0] int status, which is a read and clear register. */
55 rc
= phy_read(phydev
, MII_KSZPHY_INTCS
);
57 return (rc
< 0) ? rc
: 0;
60 static int kszphy_set_interrupt(struct phy_device
*phydev
)
63 temp
= (PHY_INTERRUPT_ENABLED
== phydev
->interrupts
) ?
65 return phy_write(phydev
, MII_KSZPHY_INTCS
, temp
);
68 static int kszphy_config_intr(struct phy_device
*phydev
)
72 /* set the interrupt pin active low */
73 temp
= phy_read(phydev
, MII_KSZPHY_CTRL
);
74 temp
&= ~KSZPHY_CTRL_INT_ACTIVE_HIGH
;
75 phy_write(phydev
, MII_KSZPHY_CTRL
, temp
);
76 rc
= kszphy_set_interrupt(phydev
);
77 return rc
< 0 ? rc
: 0;
80 static int ksz9021_config_intr(struct phy_device
*phydev
)
84 /* set the interrupt pin active low */
85 temp
= phy_read(phydev
, MII_KSZPHY_CTRL
);
86 temp
&= ~KSZ9021_CTRL_INT_ACTIVE_HIGH
;
87 phy_write(phydev
, MII_KSZPHY_CTRL
, temp
);
88 rc
= kszphy_set_interrupt(phydev
);
89 return rc
< 0 ? rc
: 0;
92 static int ks8737_config_intr(struct phy_device
*phydev
)
96 /* set the interrupt pin active low */
97 temp
= phy_read(phydev
, MII_KSZPHY_CTRL
);
98 temp
&= ~KS8737_CTRL_INT_ACTIVE_HIGH
;
99 phy_write(phydev
, MII_KSZPHY_CTRL
, temp
);
100 rc
= kszphy_set_interrupt(phydev
);
101 return rc
< 0 ? rc
: 0;
104 static int kszphy_config_init(struct phy_device
*phydev
)
109 static struct phy_driver ks8737_driver
= {
110 .phy_id
= PHY_ID_KS8737
,
111 .phy_id_mask
= 0x00fffff0,
112 .name
= "Micrel KS8737",
113 .features
= (PHY_BASIC_FEATURES
| SUPPORTED_Pause
),
114 .flags
= PHY_HAS_MAGICANEG
| PHY_HAS_INTERRUPT
,
115 .config_init
= kszphy_config_init
,
116 .config_aneg
= genphy_config_aneg
,
117 .read_status
= genphy_read_status
,
118 .ack_interrupt
= kszphy_ack_interrupt
,
119 .config_intr
= ks8737_config_intr
,
120 .driver
= { .owner
= THIS_MODULE
,},
123 static struct phy_driver ks8041_driver
= {
124 .phy_id
= PHY_ID_KS8041
,
125 .phy_id_mask
= 0x00fffff0,
126 .name
= "Micrel KS8041",
127 .features
= (PHY_BASIC_FEATURES
| SUPPORTED_Pause
128 | SUPPORTED_Asym_Pause
),
129 .flags
= PHY_HAS_MAGICANEG
| PHY_HAS_INTERRUPT
,
130 .config_init
= kszphy_config_init
,
131 .config_aneg
= genphy_config_aneg
,
132 .read_status
= genphy_read_status
,
133 .ack_interrupt
= kszphy_ack_interrupt
,
134 .config_intr
= kszphy_config_intr
,
135 .driver
= { .owner
= THIS_MODULE
,},
138 static struct phy_driver ks8051_driver
= {
139 .phy_id
= PHY_ID_KS8051
,
140 .phy_id_mask
= 0x00fffff0,
141 .name
= "Micrel KS8051",
142 .features
= (PHY_BASIC_FEATURES
| SUPPORTED_Pause
143 | SUPPORTED_Asym_Pause
),
144 .flags
= PHY_HAS_MAGICANEG
| PHY_HAS_INTERRUPT
,
145 .config_init
= kszphy_config_init
,
146 .config_aneg
= genphy_config_aneg
,
147 .read_status
= genphy_read_status
,
148 .ack_interrupt
= kszphy_ack_interrupt
,
149 .config_intr
= kszphy_config_intr
,
150 .driver
= { .owner
= THIS_MODULE
,},
153 static struct phy_driver ks8001_driver
= {
154 .phy_id
= PHY_ID_KS8001
,
155 .name
= "Micrel KS8001 or KS8721",
156 .phy_id_mask
= 0x00fffff0,
157 .features
= (PHY_BASIC_FEATURES
| SUPPORTED_Pause
),
158 .flags
= PHY_HAS_MAGICANEG
| PHY_HAS_INTERRUPT
,
159 .config_init
= kszphy_config_init
,
160 .config_aneg
= genphy_config_aneg
,
161 .read_status
= genphy_read_status
,
162 .ack_interrupt
= kszphy_ack_interrupt
,
163 .config_intr
= kszphy_config_intr
,
164 .driver
= { .owner
= THIS_MODULE
,},
167 static struct phy_driver ksz9021_driver
= {
168 .phy_id
= PHY_ID_KSZ9021
,
169 .phy_id_mask
= 0x000fff10,
170 .name
= "Micrel KSZ9021 Gigabit PHY",
171 .features
= (PHY_GBIT_FEATURES
| SUPPORTED_Pause
172 | SUPPORTED_Asym_Pause
),
173 .flags
= PHY_HAS_MAGICANEG
| PHY_HAS_INTERRUPT
,
174 .config_init
= kszphy_config_init
,
175 .config_aneg
= genphy_config_aneg
,
176 .read_status
= genphy_read_status
,
177 .ack_interrupt
= kszphy_ack_interrupt
,
178 .config_intr
= ksz9021_config_intr
,
179 .driver
= { .owner
= THIS_MODULE
, },
182 static int __init
ksphy_init(void)
186 ret
= phy_driver_register(&ks8001_driver
);
190 ret
= phy_driver_register(&ksz9021_driver
);
194 ret
= phy_driver_register(&ks8737_driver
);
197 ret
= phy_driver_register(&ks8041_driver
);
200 ret
= phy_driver_register(&ks8051_driver
);
207 phy_driver_unregister(&ks8041_driver
);
209 phy_driver_unregister(&ks8737_driver
);
211 phy_driver_unregister(&ksz9021_driver
);
213 phy_driver_unregister(&ks8001_driver
);
218 static void __exit
ksphy_exit(void)
220 phy_driver_unregister(&ks8001_driver
);
221 phy_driver_unregister(&ks8737_driver
);
222 phy_driver_unregister(&ksz9021_driver
);
223 phy_driver_unregister(&ks8041_driver
);
224 phy_driver_unregister(&ks8051_driver
);
227 module_init(ksphy_init
);
228 module_exit(ksphy_exit
);
230 MODULE_DESCRIPTION("Micrel PHY driver");
231 MODULE_AUTHOR("David J. Choi");
232 MODULE_LICENSE("GPL");
234 static struct mdio_device_id __maybe_unused micrel_tbl
[] = {
235 { PHY_ID_KSZ9021
, 0x000fff10 },
236 { PHY_ID_KS8001
, 0x00fffff0 },
237 { PHY_ID_KS8737
, 0x00fffff0 },
238 { PHY_ID_KS8041
, 0x00fffff0 },
239 { PHY_ID_KS8051
, 0x00fffff0 },
243 MODULE_DEVICE_TABLE(mdio
, micrel_tbl
);