blob: abf7b6153d00b8527b997e4e947b48a63449af4b [file] [log] [blame]
David J. Choid0507002010-04-29 06:12:41 +00001/*
2 * drivers/net/phy/micrel.c
3 *
4 * Driver for Micrel PHYs
5 *
6 * Author: David J. Choi
7 *
David J. Choi7ab59dc2013-01-23 14:05:15 +00008 * Copyright (c) 2010-2013 Micrel, Inc.
David J. Choid0507002010-04-29 06:12:41 +00009 *
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 *
David J. Choi7ab59dc2013-01-23 14:05:15 +000015 * Support : Micrel Phys:
16 * Giga phys: ksz9021, ksz9031
17 * 100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041
18 * ksz8021, ksz8031, ksz8051,
19 * ksz8081, ksz8091,
20 * ksz8061,
21 * Switch : ksz8873, ksz886x
David J. Choid0507002010-04-29 06:12:41 +000022 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/phy.h>
Baruch Siachd606ef32011-02-14 02:05:33 +000027#include <linux/micrel_phy.h>
David J. Choid0507002010-04-29 06:12:41 +000028
Marek Vasut212ea992012-09-23 16:58:49 +000029/* Operation Mode Strap Override */
30#define MII_KSZPHY_OMSO 0x16
31#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
32#define KSZPHY_OMSO_RMII_OVERRIDE (1 << 1)
33#define KSZPHY_OMSO_MII_OVERRIDE (1 << 0)
34
Choi, David51f932c2010-06-28 15:23:41 +000035/* general Interrupt control/status reg in vendor specific block. */
36#define MII_KSZPHY_INTCS 0x1B
37#define KSZPHY_INTCS_JABBER (1 << 15)
38#define KSZPHY_INTCS_RECEIVE_ERR (1 << 14)
39#define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13)
40#define KSZPHY_INTCS_PARELLEL (1 << 12)
41#define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11)
42#define KSZPHY_INTCS_LINK_DOWN (1 << 10)
43#define KSZPHY_INTCS_REMOTE_FAULT (1 << 9)
44#define KSZPHY_INTCS_LINK_UP (1 << 8)
45#define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\
46 KSZPHY_INTCS_LINK_DOWN)
47
48/* general PHY control reg in vendor specific block. */
49#define MII_KSZPHY_CTRL 0x1F
50/* bitmap of PHY register to set interrupt mode */
51#define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9)
52#define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14)
53#define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14)
Baruch Siachd606ef32011-02-14 02:05:33 +000054#define KSZ8051_RMII_50MHZ_CLK (1 << 7)
Choi, David51f932c2010-06-28 15:23:41 +000055
56static int kszphy_ack_interrupt(struct phy_device *phydev)
57{
58 /* bit[7..0] int status, which is a read and clear register. */
59 int rc;
60
61 rc = phy_read(phydev, MII_KSZPHY_INTCS);
62
63 return (rc < 0) ? rc : 0;
64}
65
66static int kszphy_set_interrupt(struct phy_device *phydev)
67{
68 int temp;
69 temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
70 KSZPHY_INTCS_ALL : 0;
71 return phy_write(phydev, MII_KSZPHY_INTCS, temp);
72}
73
74static int kszphy_config_intr(struct phy_device *phydev)
75{
76 int temp, rc;
77
78 /* set the interrupt pin active low */
79 temp = phy_read(phydev, MII_KSZPHY_CTRL);
80 temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH;
81 phy_write(phydev, MII_KSZPHY_CTRL, temp);
82 rc = kszphy_set_interrupt(phydev);
83 return rc < 0 ? rc : 0;
84}
85
86static int ksz9021_config_intr(struct phy_device *phydev)
87{
88 int temp, rc;
89
90 /* set the interrupt pin active low */
91 temp = phy_read(phydev, MII_KSZPHY_CTRL);
92 temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH;
93 phy_write(phydev, MII_KSZPHY_CTRL, temp);
94 rc = kszphy_set_interrupt(phydev);
95 return rc < 0 ? rc : 0;
96}
97
98static int ks8737_config_intr(struct phy_device *phydev)
99{
100 int temp, rc;
101
102 /* set the interrupt pin active low */
103 temp = phy_read(phydev, MII_KSZPHY_CTRL);
104 temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH;
105 phy_write(phydev, MII_KSZPHY_CTRL, temp);
106 rc = kszphy_set_interrupt(phydev);
107 return rc < 0 ? rc : 0;
108}
David J. Choid0507002010-04-29 06:12:41 +0000109
110static int kszphy_config_init(struct phy_device *phydev)
111{
112 return 0;
113}
114
Marek Vasut212ea992012-09-23 16:58:49 +0000115static int ksz8021_config_init(struct phy_device *phydev)
116{
117 const u16 val = KSZPHY_OMSO_B_CAST_OFF | KSZPHY_OMSO_RMII_OVERRIDE;
118 phy_write(phydev, MII_KSZPHY_OMSO, val);
119 return 0;
120}
121
Baruch Siachd606ef32011-02-14 02:05:33 +0000122static int ks8051_config_init(struct phy_device *phydev)
123{
124 int regval;
125
126 if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
127 regval = phy_read(phydev, MII_KSZPHY_CTRL);
128 regval |= KSZ8051_RMII_50MHZ_CLK;
129 phy_write(phydev, MII_KSZPHY_CTRL, regval);
130 }
131
132 return 0;
133}
134
Jean-Christophe PLAGNIOL-VILLARD93272e02012-11-21 05:38:07 +0000135#define KSZ8873MLL_GLOBAL_CONTROL_4 0x06
136#define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX (1 << 6)
137#define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED (1 << 4)
138int ksz8873mll_read_status(struct phy_device *phydev)
139{
140 int regval;
141
142 /* dummy read */
143 regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
144
145 regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4);
146
147 if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX)
148 phydev->duplex = DUPLEX_HALF;
149 else
150 phydev->duplex = DUPLEX_FULL;
151
152 if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED)
153 phydev->speed = SPEED_10;
154 else
155 phydev->speed = SPEED_100;
156
157 phydev->link = 1;
158 phydev->pause = phydev->asym_pause = 0;
159
160 return 0;
161}
162
163static int ksz8873mll_config_aneg(struct phy_device *phydev)
164{
165 return 0;
166}
167
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000168static struct phy_driver ksphy_driver[] = {
169{
Choi, David51f932c2010-06-28 15:23:41 +0000170 .phy_id = PHY_ID_KS8737,
David J. Choid0507002010-04-29 06:12:41 +0000171 .phy_id_mask = 0x00fffff0,
Choi, David51f932c2010-06-28 15:23:41 +0000172 .name = "Micrel KS8737",
173 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
174 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000175 .config_init = kszphy_config_init,
176 .config_aneg = genphy_config_aneg,
177 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000178 .ack_interrupt = kszphy_ack_interrupt,
179 .config_intr = ks8737_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000180 .driver = { .owner = THIS_MODULE,},
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000181}, {
Marek Vasut212ea992012-09-23 16:58:49 +0000182 .phy_id = PHY_ID_KSZ8021,
183 .phy_id_mask = 0x00ffffff,
David J. Choi7ab59dc2013-01-23 14:05:15 +0000184 .name = "Micrel KSZ8021 or KSZ8031",
Marek Vasut212ea992012-09-23 16:58:49 +0000185 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
186 SUPPORTED_Asym_Pause),
187 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
188 .config_init = ksz8021_config_init,
189 .config_aneg = genphy_config_aneg,
190 .read_status = genphy_read_status,
191 .ack_interrupt = kszphy_ack_interrupt,
192 .config_intr = kszphy_config_intr,
193 .driver = { .owner = THIS_MODULE,},
194}, {
Marek Vasut510d5732012-09-23 16:58:50 +0000195 .phy_id = PHY_ID_KSZ8041,
David J. Choid0507002010-04-29 06:12:41 +0000196 .phy_id_mask = 0x00fffff0,
Marek Vasut510d5732012-09-23 16:58:50 +0000197 .name = "Micrel KSZ8041",
Choi, David51f932c2010-06-28 15:23:41 +0000198 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
199 | SUPPORTED_Asym_Pause),
200 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000201 .config_init = kszphy_config_init,
202 .config_aneg = genphy_config_aneg,
203 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000204 .ack_interrupt = kszphy_ack_interrupt,
205 .config_intr = kszphy_config_intr,
206 .driver = { .owner = THIS_MODULE,},
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000207}, {
Marek Vasut510d5732012-09-23 16:58:50 +0000208 .phy_id = PHY_ID_KSZ8051,
Choi, David51f932c2010-06-28 15:23:41 +0000209 .phy_id_mask = 0x00fffff0,
Marek Vasut510d5732012-09-23 16:58:50 +0000210 .name = "Micrel KSZ8051",
Choi, David51f932c2010-06-28 15:23:41 +0000211 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
212 | SUPPORTED_Asym_Pause),
213 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
Baruch Siachd606ef32011-02-14 02:05:33 +0000214 .config_init = ks8051_config_init,
Choi, David51f932c2010-06-28 15:23:41 +0000215 .config_aneg = genphy_config_aneg,
216 .read_status = genphy_read_status,
217 .ack_interrupt = kszphy_ack_interrupt,
218 .config_intr = kszphy_config_intr,
219 .driver = { .owner = THIS_MODULE,},
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000220}, {
Marek Vasut510d5732012-09-23 16:58:50 +0000221 .phy_id = PHY_ID_KSZ8001,
222 .name = "Micrel KSZ8001 or KS8721",
Jason Wang48d7d0a2012-06-17 22:52:09 +0000223 .phy_id_mask = 0x00ffffff,
Choi, David51f932c2010-06-28 15:23:41 +0000224 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
225 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
226 .config_init = kszphy_config_init,
227 .config_aneg = genphy_config_aneg,
228 .read_status = genphy_read_status,
229 .ack_interrupt = kszphy_ack_interrupt,
230 .config_intr = kszphy_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000231 .driver = { .owner = THIS_MODULE,},
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000232}, {
David J. Choi7ab59dc2013-01-23 14:05:15 +0000233 .phy_id = PHY_ID_KSZ8081,
234 .name = "Micrel KSZ8081 or KSZ8091",
235 .phy_id_mask = 0x00fffff0,
236 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
237 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
238 .config_init = kszphy_config_init,
239 .config_aneg = genphy_config_aneg,
240 .read_status = genphy_read_status,
241 .ack_interrupt = kszphy_ack_interrupt,
242 .config_intr = kszphy_config_intr,
243 .driver = { .owner = THIS_MODULE,},
244}, {
245 .phy_id = PHY_ID_KSZ8061,
246 .name = "Micrel KSZ8061",
247 .phy_id_mask = 0x00fffff0,
248 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
249 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
250 .config_init = kszphy_config_init,
251 .config_aneg = genphy_config_aneg,
252 .read_status = genphy_read_status,
253 .ack_interrupt = kszphy_ack_interrupt,
254 .config_intr = kszphy_config_intr,
255 .driver = { .owner = THIS_MODULE,},
256}, {
David J. Choid0507002010-04-29 06:12:41 +0000257 .phy_id = PHY_ID_KSZ9021,
Jason Wang48d7d0a2012-06-17 22:52:09 +0000258 .phy_id_mask = 0x000ffffe,
David J. Choid0507002010-04-29 06:12:41 +0000259 .name = "Micrel KSZ9021 Gigabit PHY",
Vlastimil Kosar32fcafb2013-02-28 08:45:22 +0000260 .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
Choi, David51f932c2010-06-28 15:23:41 +0000261 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000262 .config_init = kszphy_config_init,
263 .config_aneg = genphy_config_aneg,
264 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000265 .ack_interrupt = kszphy_ack_interrupt,
266 .config_intr = ksz9021_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000267 .driver = { .owner = THIS_MODULE, },
Jean-Christophe PLAGNIOL-VILLARD93272e02012-11-21 05:38:07 +0000268}, {
David J. Choi7ab59dc2013-01-23 14:05:15 +0000269 .phy_id = PHY_ID_KSZ9031,
270 .phy_id_mask = 0x00fffff0,
271 .name = "Micrel KSZ9031 Gigabit PHY",
272 .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause
273 | SUPPORTED_Asym_Pause),
274 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
275 .config_init = kszphy_config_init,
276 .config_aneg = genphy_config_aneg,
277 .read_status = genphy_read_status,
278 .ack_interrupt = kszphy_ack_interrupt,
279 .config_intr = ksz9021_config_intr,
280 .driver = { .owner = THIS_MODULE, },
281}, {
Jean-Christophe PLAGNIOL-VILLARD93272e02012-11-21 05:38:07 +0000282 .phy_id = PHY_ID_KSZ8873MLL,
283 .phy_id_mask = 0x00fffff0,
284 .name = "Micrel KSZ8873MLL Switch",
285 .features = (SUPPORTED_Pause | SUPPORTED_Asym_Pause),
286 .flags = PHY_HAS_MAGICANEG,
287 .config_init = kszphy_config_init,
288 .config_aneg = ksz8873mll_config_aneg,
289 .read_status = ksz8873mll_read_status,
290 .driver = { .owner = THIS_MODULE, },
David J. Choi7ab59dc2013-01-23 14:05:15 +0000291}, {
292 .phy_id = PHY_ID_KSZ886X,
293 .phy_id_mask = 0x00fffff0,
294 .name = "Micrel KSZ886X Switch",
295 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
296 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
297 .config_init = kszphy_config_init,
298 .config_aneg = genphy_config_aneg,
299 .read_status = genphy_read_status,
300 .driver = { .owner = THIS_MODULE, },
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000301} };
David J. Choid0507002010-04-29 06:12:41 +0000302
303static int __init ksphy_init(void)
304{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000305 return phy_drivers_register(ksphy_driver,
306 ARRAY_SIZE(ksphy_driver));
David J. Choid0507002010-04-29 06:12:41 +0000307}
308
309static void __exit ksphy_exit(void)
310{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000311 phy_drivers_unregister(ksphy_driver,
312 ARRAY_SIZE(ksphy_driver));
David J. Choid0507002010-04-29 06:12:41 +0000313}
314
315module_init(ksphy_init);
316module_exit(ksphy_exit);
317
318MODULE_DESCRIPTION("Micrel PHY driver");
319MODULE_AUTHOR("David J. Choi");
320MODULE_LICENSE("GPL");
David S. Miller52a60ed2010-05-03 15:48:29 -0700321
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000322static struct mdio_device_id __maybe_unused micrel_tbl[] = {
Jason Wang48d7d0a2012-06-17 22:52:09 +0000323 { PHY_ID_KSZ9021, 0x000ffffe },
David J. Choi7ab59dc2013-01-23 14:05:15 +0000324 { PHY_ID_KSZ9031, 0x00fffff0 },
Marek Vasut510d5732012-09-23 16:58:50 +0000325 { PHY_ID_KSZ8001, 0x00ffffff },
Choi, David51f932c2010-06-28 15:23:41 +0000326 { PHY_ID_KS8737, 0x00fffff0 },
Marek Vasut212ea992012-09-23 16:58:49 +0000327 { PHY_ID_KSZ8021, 0x00ffffff },
Marek Vasut510d5732012-09-23 16:58:50 +0000328 { PHY_ID_KSZ8041, 0x00fffff0 },
329 { PHY_ID_KSZ8051, 0x00fffff0 },
David J. Choi7ab59dc2013-01-23 14:05:15 +0000330 { PHY_ID_KSZ8061, 0x00fffff0 },
331 { PHY_ID_KSZ8081, 0x00fffff0 },
Jean-Christophe PLAGNIOL-VILLARD93272e02012-11-21 05:38:07 +0000332 { PHY_ID_KSZ8873MLL, 0x00fffff0 },
David J. Choi7ab59dc2013-01-23 14:05:15 +0000333 { PHY_ID_KSZ886X, 0x00fffff0 },
David S. Miller52a60ed2010-05-03 15:48:29 -0700334 { }
335};
336
337MODULE_DEVICE_TABLE(mdio, micrel_tbl);