blob: 0fd1678bc5a928eac50ec9862567ed2019f5bb4b [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 *
8 * Copyright (c) 2010 Micrel, 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 *
Choi, David51f932c2010-06-28 15:23:41 +000015 * Support : ksz9021 1000/100/10 phy from Micrel
16 * ks8001, ks8737, ks8721, ks8041, ks8051 100/10 phy
David J. Choid0507002010-04-29 06:12:41 +000017 */
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/phy.h>
22
23#define PHY_ID_KSZ9021 0x00221611
Choi, David51f932c2010-06-28 15:23:41 +000024#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. */
David J. Choid0507002010-04-29 06:12:41 +000028#define PHY_ID_KS8001 0x0022161A
29
Choi, David51f932c2010-06-28 15:23:41 +000030/* 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)
42
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)
49
50static int kszphy_ack_interrupt(struct phy_device *phydev)
51{
52 /* bit[7..0] int status, which is a read and clear register. */
53 int rc;
54
55 rc = phy_read(phydev, MII_KSZPHY_INTCS);
56
57 return (rc < 0) ? rc : 0;
58}
59
60static int kszphy_set_interrupt(struct phy_device *phydev)
61{
62 int temp;
63 temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
64 KSZPHY_INTCS_ALL : 0;
65 return phy_write(phydev, MII_KSZPHY_INTCS, temp);
66}
67
68static int kszphy_config_intr(struct phy_device *phydev)
69{
70 int temp, rc;
71
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;
78}
79
80static int ksz9021_config_intr(struct phy_device *phydev)
81{
82 int temp, rc;
83
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;
90}
91
92static int ks8737_config_intr(struct phy_device *phydev)
93{
94 int temp, rc;
95
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;
102}
David J. Choid0507002010-04-29 06:12:41 +0000103
104static int kszphy_config_init(struct phy_device *phydev)
105{
106 return 0;
107}
108
Choi, David51f932c2010-06-28 15:23:41 +0000109static struct phy_driver ks8737_driver = {
110 .phy_id = PHY_ID_KS8737,
David J. Choid0507002010-04-29 06:12:41 +0000111 .phy_id_mask = 0x00fffff0,
Choi, David51f932c2010-06-28 15:23:41 +0000112 .name = "Micrel KS8737",
113 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
114 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000115 .config_init = kszphy_config_init,
116 .config_aneg = genphy_config_aneg,
117 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000118 .ack_interrupt = kszphy_ack_interrupt,
119 .config_intr = ks8737_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000120 .driver = { .owner = THIS_MODULE,},
121};
122
Choi, David51f932c2010-06-28 15:23:41 +0000123static struct phy_driver ks8041_driver = {
124 .phy_id = PHY_ID_KS8041,
David J. Choid0507002010-04-29 06:12:41 +0000125 .phy_id_mask = 0x00fffff0,
Choi, David51f932c2010-06-28 15:23:41 +0000126 .name = "Micrel KS8041",
127 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
128 | SUPPORTED_Asym_Pause),
129 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000130 .config_init = kszphy_config_init,
131 .config_aneg = genphy_config_aneg,
132 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000133 .ack_interrupt = kszphy_ack_interrupt,
134 .config_intr = kszphy_config_intr,
135 .driver = { .owner = THIS_MODULE,},
136};
137
138static 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,},
151};
152
153static 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,
David J. Choid0507002010-04-29 06:12:41 +0000164 .driver = { .owner = THIS_MODULE,},
165};
166
167static struct phy_driver ksz9021_driver = {
168 .phy_id = PHY_ID_KSZ9021,
169 .phy_id_mask = 0x000fff10,
170 .name = "Micrel KSZ9021 Gigabit PHY",
Choi, David51f932c2010-06-28 15:23:41 +0000171 .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause
172 | SUPPORTED_Asym_Pause),
173 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000174 .config_init = kszphy_config_init,
175 .config_aneg = genphy_config_aneg,
176 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000177 .ack_interrupt = kszphy_ack_interrupt,
178 .config_intr = ksz9021_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000179 .driver = { .owner = THIS_MODULE, },
180};
181
182static int __init ksphy_init(void)
183{
184 int ret;
185
186 ret = phy_driver_register(&ks8001_driver);
187 if (ret)
188 goto err1;
David J. Choid0507002010-04-29 06:12:41 +0000189
190 ret = phy_driver_register(&ksz9021_driver);
191 if (ret)
Choi, David51f932c2010-06-28 15:23:41 +0000192 goto err2;
193
194 ret = phy_driver_register(&ks8737_driver);
195 if (ret)
David J. Choid0507002010-04-29 06:12:41 +0000196 goto err3;
Choi, David51f932c2010-06-28 15:23:41 +0000197 ret = phy_driver_register(&ks8041_driver);
198 if (ret)
199 goto err4;
200 ret = phy_driver_register(&ks8051_driver);
201 if (ret)
202 goto err5;
203
David J. Choid0507002010-04-29 06:12:41 +0000204 return 0;
205
Choi, David51f932c2010-06-28 15:23:41 +0000206err5:
207 phy_driver_unregister(&ks8041_driver);
208err4:
209 phy_driver_unregister(&ks8737_driver);
David J. Choid0507002010-04-29 06:12:41 +0000210err3:
Choi, David51f932c2010-06-28 15:23:41 +0000211 phy_driver_unregister(&ksz9021_driver);
David J. Choid0507002010-04-29 06:12:41 +0000212err2:
213 phy_driver_unregister(&ks8001_driver);
214err1:
215 return ret;
216}
217
218static void __exit ksphy_exit(void)
219{
220 phy_driver_unregister(&ks8001_driver);
Choi, David51f932c2010-06-28 15:23:41 +0000221 phy_driver_unregister(&ks8737_driver);
David J. Choid0507002010-04-29 06:12:41 +0000222 phy_driver_unregister(&ksz9021_driver);
Choi, David51f932c2010-06-28 15:23:41 +0000223 phy_driver_unregister(&ks8041_driver);
224 phy_driver_unregister(&ks8051_driver);
David J. Choid0507002010-04-29 06:12:41 +0000225}
226
227module_init(ksphy_init);
228module_exit(ksphy_exit);
229
230MODULE_DESCRIPTION("Micrel PHY driver");
231MODULE_AUTHOR("David J. Choi");
232MODULE_LICENSE("GPL");
David S. Miller52a60ed2010-05-03 15:48:29 -0700233
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000234static struct mdio_device_id __maybe_unused micrel_tbl[] = {
David S. Miller52a60ed2010-05-03 15:48:29 -0700235 { PHY_ID_KSZ9021, 0x000fff10 },
David S. Miller52a60ed2010-05-03 15:48:29 -0700236 { PHY_ID_KS8001, 0x00fffff0 },
Choi, David51f932c2010-06-28 15:23:41 +0000237 { PHY_ID_KS8737, 0x00fffff0 },
238 { PHY_ID_KS8041, 0x00fffff0 },
239 { PHY_ID_KS8051, 0x00fffff0 },
David S. Miller52a60ed2010-05-03 15:48:29 -0700240 { }
241};
242
243MODULE_DEVICE_TABLE(mdio, micrel_tbl);