blob: 590f902deb6ba29f348c78dad429275cac23a276 [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>
Baruch Siachd606ef32011-02-14 02:05:33 +000022#include <linux/micrel_phy.h>
David J. Choid0507002010-04-29 06:12:41 +000023
Choi, David51f932c2010-06-28 15:23:41 +000024/* general Interrupt control/status reg in vendor specific block. */
25#define MII_KSZPHY_INTCS 0x1B
26#define KSZPHY_INTCS_JABBER (1 << 15)
27#define KSZPHY_INTCS_RECEIVE_ERR (1 << 14)
28#define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13)
29#define KSZPHY_INTCS_PARELLEL (1 << 12)
30#define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11)
31#define KSZPHY_INTCS_LINK_DOWN (1 << 10)
32#define KSZPHY_INTCS_REMOTE_FAULT (1 << 9)
33#define KSZPHY_INTCS_LINK_UP (1 << 8)
34#define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\
35 KSZPHY_INTCS_LINK_DOWN)
36
37/* general PHY control reg in vendor specific block. */
38#define MII_KSZPHY_CTRL 0x1F
39/* bitmap of PHY register to set interrupt mode */
40#define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9)
41#define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14)
42#define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14)
Baruch Siachd606ef32011-02-14 02:05:33 +000043#define KSZ8051_RMII_50MHZ_CLK (1 << 7)
Choi, David51f932c2010-06-28 15:23:41 +000044
45static int kszphy_ack_interrupt(struct phy_device *phydev)
46{
47 /* bit[7..0] int status, which is a read and clear register. */
48 int rc;
49
50 rc = phy_read(phydev, MII_KSZPHY_INTCS);
51
52 return (rc < 0) ? rc : 0;
53}
54
55static int kszphy_set_interrupt(struct phy_device *phydev)
56{
57 int temp;
58 temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
59 KSZPHY_INTCS_ALL : 0;
60 return phy_write(phydev, MII_KSZPHY_INTCS, temp);
61}
62
63static int kszphy_config_intr(struct phy_device *phydev)
64{
65 int temp, rc;
66
67 /* set the interrupt pin active low */
68 temp = phy_read(phydev, MII_KSZPHY_CTRL);
69 temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH;
70 phy_write(phydev, MII_KSZPHY_CTRL, temp);
71 rc = kszphy_set_interrupt(phydev);
72 return rc < 0 ? rc : 0;
73}
74
75static int ksz9021_config_intr(struct phy_device *phydev)
76{
77 int temp, rc;
78
79 /* set the interrupt pin active low */
80 temp = phy_read(phydev, MII_KSZPHY_CTRL);
81 temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH;
82 phy_write(phydev, MII_KSZPHY_CTRL, temp);
83 rc = kszphy_set_interrupt(phydev);
84 return rc < 0 ? rc : 0;
85}
86
87static int ks8737_config_intr(struct phy_device *phydev)
88{
89 int temp, rc;
90
91 /* set the interrupt pin active low */
92 temp = phy_read(phydev, MII_KSZPHY_CTRL);
93 temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH;
94 phy_write(phydev, MII_KSZPHY_CTRL, temp);
95 rc = kszphy_set_interrupt(phydev);
96 return rc < 0 ? rc : 0;
97}
David J. Choid0507002010-04-29 06:12:41 +000098
99static int kszphy_config_init(struct phy_device *phydev)
100{
101 return 0;
102}
103
Baruch Siachd606ef32011-02-14 02:05:33 +0000104static int ks8051_config_init(struct phy_device *phydev)
105{
106 int regval;
107
108 if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
109 regval = phy_read(phydev, MII_KSZPHY_CTRL);
110 regval |= KSZ8051_RMII_50MHZ_CLK;
111 phy_write(phydev, MII_KSZPHY_CTRL, regval);
112 }
113
114 return 0;
115}
116
Choi, David51f932c2010-06-28 15:23:41 +0000117static struct phy_driver ks8737_driver = {
118 .phy_id = PHY_ID_KS8737,
David J. Choid0507002010-04-29 06:12:41 +0000119 .phy_id_mask = 0x00fffff0,
Choi, David51f932c2010-06-28 15:23:41 +0000120 .name = "Micrel KS8737",
121 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
122 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000123 .config_init = kszphy_config_init,
124 .config_aneg = genphy_config_aneg,
125 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000126 .ack_interrupt = kszphy_ack_interrupt,
127 .config_intr = ks8737_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000128 .driver = { .owner = THIS_MODULE,},
129};
130
Choi, David51f932c2010-06-28 15:23:41 +0000131static struct phy_driver ks8041_driver = {
132 .phy_id = PHY_ID_KS8041,
David J. Choid0507002010-04-29 06:12:41 +0000133 .phy_id_mask = 0x00fffff0,
Choi, David51f932c2010-06-28 15:23:41 +0000134 .name = "Micrel KS8041",
135 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
136 | SUPPORTED_Asym_Pause),
137 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000138 .config_init = kszphy_config_init,
139 .config_aneg = genphy_config_aneg,
140 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000141 .ack_interrupt = kszphy_ack_interrupt,
142 .config_intr = kszphy_config_intr,
143 .driver = { .owner = THIS_MODULE,},
144};
145
146static struct phy_driver ks8051_driver = {
147 .phy_id = PHY_ID_KS8051,
148 .phy_id_mask = 0x00fffff0,
149 .name = "Micrel KS8051",
150 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
151 | SUPPORTED_Asym_Pause),
152 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
Baruch Siachd606ef32011-02-14 02:05:33 +0000153 .config_init = ks8051_config_init,
Choi, David51f932c2010-06-28 15:23:41 +0000154 .config_aneg = genphy_config_aneg,
155 .read_status = genphy_read_status,
156 .ack_interrupt = kszphy_ack_interrupt,
157 .config_intr = kszphy_config_intr,
158 .driver = { .owner = THIS_MODULE,},
159};
160
161static struct phy_driver ks8001_driver = {
162 .phy_id = PHY_ID_KS8001,
163 .name = "Micrel KS8001 or KS8721",
164 .phy_id_mask = 0x00fffff0,
165 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
166 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
167 .config_init = kszphy_config_init,
168 .config_aneg = genphy_config_aneg,
169 .read_status = genphy_read_status,
170 .ack_interrupt = kszphy_ack_interrupt,
171 .config_intr = kszphy_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000172 .driver = { .owner = THIS_MODULE,},
173};
174
175static struct phy_driver ksz9021_driver = {
176 .phy_id = PHY_ID_KSZ9021,
177 .phy_id_mask = 0x000fff10,
178 .name = "Micrel KSZ9021 Gigabit PHY",
Choi, David51f932c2010-06-28 15:23:41 +0000179 .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause
180 | SUPPORTED_Asym_Pause),
181 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
David J. Choid0507002010-04-29 06:12:41 +0000182 .config_init = kszphy_config_init,
183 .config_aneg = genphy_config_aneg,
184 .read_status = genphy_read_status,
Choi, David51f932c2010-06-28 15:23:41 +0000185 .ack_interrupt = kszphy_ack_interrupt,
186 .config_intr = ksz9021_config_intr,
David J. Choid0507002010-04-29 06:12:41 +0000187 .driver = { .owner = THIS_MODULE, },
188};
189
190static int __init ksphy_init(void)
191{
192 int ret;
193
194 ret = phy_driver_register(&ks8001_driver);
195 if (ret)
196 goto err1;
David J. Choid0507002010-04-29 06:12:41 +0000197
198 ret = phy_driver_register(&ksz9021_driver);
199 if (ret)
Choi, David51f932c2010-06-28 15:23:41 +0000200 goto err2;
201
202 ret = phy_driver_register(&ks8737_driver);
203 if (ret)
David J. Choid0507002010-04-29 06:12:41 +0000204 goto err3;
Choi, David51f932c2010-06-28 15:23:41 +0000205 ret = phy_driver_register(&ks8041_driver);
206 if (ret)
207 goto err4;
208 ret = phy_driver_register(&ks8051_driver);
209 if (ret)
210 goto err5;
211
David J. Choid0507002010-04-29 06:12:41 +0000212 return 0;
213
Choi, David51f932c2010-06-28 15:23:41 +0000214err5:
215 phy_driver_unregister(&ks8041_driver);
216err4:
217 phy_driver_unregister(&ks8737_driver);
David J. Choid0507002010-04-29 06:12:41 +0000218err3:
Choi, David51f932c2010-06-28 15:23:41 +0000219 phy_driver_unregister(&ksz9021_driver);
David J. Choid0507002010-04-29 06:12:41 +0000220err2:
221 phy_driver_unregister(&ks8001_driver);
222err1:
223 return ret;
224}
225
226static void __exit ksphy_exit(void)
227{
228 phy_driver_unregister(&ks8001_driver);
Choi, David51f932c2010-06-28 15:23:41 +0000229 phy_driver_unregister(&ks8737_driver);
David J. Choid0507002010-04-29 06:12:41 +0000230 phy_driver_unregister(&ksz9021_driver);
Choi, David51f932c2010-06-28 15:23:41 +0000231 phy_driver_unregister(&ks8041_driver);
232 phy_driver_unregister(&ks8051_driver);
David J. Choid0507002010-04-29 06:12:41 +0000233}
234
235module_init(ksphy_init);
236module_exit(ksphy_exit);
237
238MODULE_DESCRIPTION("Micrel PHY driver");
239MODULE_AUTHOR("David J. Choi");
240MODULE_LICENSE("GPL");
David S. Miller52a60ed2010-05-03 15:48:29 -0700241
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000242static struct mdio_device_id __maybe_unused micrel_tbl[] = {
David S. Miller52a60ed2010-05-03 15:48:29 -0700243 { PHY_ID_KSZ9021, 0x000fff10 },
David S. Miller52a60ed2010-05-03 15:48:29 -0700244 { PHY_ID_KS8001, 0x00fffff0 },
Choi, David51f932c2010-06-28 15:23:41 +0000245 { PHY_ID_KS8737, 0x00fffff0 },
246 { PHY_ID_KS8041, 0x00fffff0 },
247 { PHY_ID_KS8051, 0x00fffff0 },
David S. Miller52a60ed2010-05-03 15:48:29 -0700248 { }
249};
250
251MODULE_DEVICE_TABLE(mdio, micrel_tbl);