blob: fc3e7e96c88c64a3c9979a96596a6f0e016778ab [file] [log] [blame]
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +02001/*
2 * drivers/net/phy/smsc.c
3 *
4 * Driver for SMSC PHYs
5 *
6 * Author: Herbert Valerio Riedel
7 *
8 * Copyright (c) 2006 Herbert Valerio Riedel <hvr@gnu.org>
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 *
Steve Glendinning4d9b1a02008-04-28 18:37:29 +010015 * Support added for SMSC LAN8187 and LAN8700 by steve.glendinning@smsc.com
16 *
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020017 */
18
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020019#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/mii.h>
22#include <linux/ethtool.h>
23#include <linux/phy.h>
24#include <linux/netdevice.h>
Javier Martinez Canillas43c67592012-01-03 20:23:18 -050025#include <linux/smscphy.h>
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020026
Steve Glendinning48c41b92008-04-28 18:36:46 +010027static int smsc_phy_config_intr(struct phy_device *phydev)
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020028{
29 int rc = phy_write (phydev, MII_LAN83C185_IM,
30 ((PHY_INTERRUPT_ENABLED == phydev->interrupts)
31 ? MII_LAN83C185_ISF_INT_PHYLIB_EVENTS
32 : 0));
33
34 return rc < 0 ? rc : 0;
35}
36
Steve Glendinning48c41b92008-04-28 18:36:46 +010037static int smsc_phy_ack_interrupt(struct phy_device *phydev)
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020038{
39 int rc = phy_read (phydev, MII_LAN83C185_ISF);
40
41 return rc < 0 ? rc : 0;
42}
43
Steve Glendinning48c41b92008-04-28 18:36:46 +010044static int smsc_phy_config_init(struct phy_device *phydev)
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020045{
Giuseppe Cavallaro698244a2010-01-06 20:35:14 -080046 int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
47 if (rc < 0)
48 return rc;
49
50 /* Enable energy detect mode for this SMSC Transceivers */
51 rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
52 rc | MII_LAN83C185_EDPWRDOWN);
53 if (rc < 0)
54 return rc;
55
Steve Glendinning48c41b92008-04-28 18:36:46 +010056 return smsc_phy_ack_interrupt (phydev);
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020057}
58
Giuseppe Cavallaro698244a2010-01-06 20:35:14 -080059static int lan911x_config_init(struct phy_device *phydev)
60{
61 return smsc_phy_ack_interrupt(phydev);
62}
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020063
64static struct phy_driver lan83c185_driver = {
65 .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
66 .phy_id_mask = 0xfffffff0,
67 .name = "SMSC LAN83C185",
68
69 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
70 | SUPPORTED_Asym_Pause),
71 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
72
73 /* basic functions */
74 .config_aneg = genphy_config_aneg,
75 .read_status = genphy_read_status,
Steve Glendinning48c41b92008-04-28 18:36:46 +010076 .config_init = smsc_phy_config_init,
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020077
78 /* IRQ related */
Steve Glendinning48c41b92008-04-28 18:36:46 +010079 .ack_interrupt = smsc_phy_ack_interrupt,
80 .config_intr = smsc_phy_config_intr,
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020081
Steve Glendinningc64d2a92009-01-22 14:07:43 -080082 .suspend = genphy_suspend,
83 .resume = genphy_resume,
84
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020085 .driver = { .owner = THIS_MODULE, }
86};
87
Steve Glendinning4d9b1a02008-04-28 18:37:29 +010088static struct phy_driver lan8187_driver = {
89 .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
90 .phy_id_mask = 0xfffffff0,
91 .name = "SMSC LAN8187",
92
93 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
94 | SUPPORTED_Asym_Pause),
95 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
96
97 /* basic functions */
98 .config_aneg = genphy_config_aneg,
99 .read_status = genphy_read_status,
100 .config_init = smsc_phy_config_init,
101
102 /* IRQ related */
103 .ack_interrupt = smsc_phy_ack_interrupt,
104 .config_intr = smsc_phy_config_intr,
105
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800106 .suspend = genphy_suspend,
107 .resume = genphy_resume,
108
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100109 .driver = { .owner = THIS_MODULE, }
110};
111
112static struct phy_driver lan8700_driver = {
113 .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
114 .phy_id_mask = 0xfffffff0,
115 .name = "SMSC LAN8700",
116
117 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
118 | SUPPORTED_Asym_Pause),
119 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
120
121 /* basic functions */
122 .config_aneg = genphy_config_aneg,
123 .read_status = genphy_read_status,
124 .config_init = smsc_phy_config_init,
125
126 /* IRQ related */
127 .ack_interrupt = smsc_phy_ack_interrupt,
128 .config_intr = smsc_phy_config_intr,
129
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800130 .suspend = genphy_suspend,
131 .resume = genphy_resume,
132
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100133 .driver = { .owner = THIS_MODULE, }
134};
135
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000136static struct phy_driver lan911x_int_driver = {
137 .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
138 .phy_id_mask = 0xfffffff0,
139 .name = "SMSC LAN911x Internal PHY",
140
141 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
142 | SUPPORTED_Asym_Pause),
143 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
144
145 /* basic functions */
146 .config_aneg = genphy_config_aneg,
147 .read_status = genphy_read_status,
Giuseppe Cavallaro698244a2010-01-06 20:35:14 -0800148 .config_init = lan911x_config_init,
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000149
150 /* IRQ related */
151 .ack_interrupt = smsc_phy_ack_interrupt,
152 .config_intr = smsc_phy_config_intr,
153
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800154 .suspend = genphy_suspend,
155 .resume = genphy_resume,
156
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000157 .driver = { .owner = THIS_MODULE, }
158};
159
Steve Glendinninge072b632009-03-23 15:17:31 -0700160static struct phy_driver lan8710_driver = {
161 .phy_id = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
162 .phy_id_mask = 0xfffffff0,
163 .name = "SMSC LAN8710/LAN8720",
164
165 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
166 | SUPPORTED_Asym_Pause),
167 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
168
169 /* basic functions */
170 .config_aneg = genphy_config_aneg,
171 .read_status = genphy_read_status,
172 .config_init = smsc_phy_config_init,
173
174 /* IRQ related */
175 .ack_interrupt = smsc_phy_ack_interrupt,
176 .config_intr = smsc_phy_config_intr,
177
178 .suspend = genphy_suspend,
179 .resume = genphy_resume,
180
181 .driver = { .owner = THIS_MODULE, }
182};
183
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200184static int __init smsc_init(void)
185{
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100186 int ret;
187
188 ret = phy_driver_register (&lan83c185_driver);
189 if (ret)
190 goto err1;
191
192 ret = phy_driver_register (&lan8187_driver);
193 if (ret)
194 goto err2;
195
196 ret = phy_driver_register (&lan8700_driver);
197 if (ret)
198 goto err3;
199
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000200 ret = phy_driver_register (&lan911x_int_driver);
201 if (ret)
202 goto err4;
203
Steve Glendinninge072b632009-03-23 15:17:31 -0700204 ret = phy_driver_register (&lan8710_driver);
205 if (ret)
206 goto err5;
207
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100208 return 0;
209
Steve Glendinninge072b632009-03-23 15:17:31 -0700210err5:
211 phy_driver_unregister (&lan911x_int_driver);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000212err4:
213 phy_driver_unregister (&lan8700_driver);
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100214err3:
215 phy_driver_unregister (&lan8187_driver);
216err2:
217 phy_driver_unregister (&lan83c185_driver);
218err1:
219 return ret;
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200220}
221
222static void __exit smsc_exit(void)
223{
Steve Glendinninge072b632009-03-23 15:17:31 -0700224 phy_driver_unregister (&lan8710_driver);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000225 phy_driver_unregister (&lan911x_int_driver);
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100226 phy_driver_unregister (&lan8700_driver);
227 phy_driver_unregister (&lan8187_driver);
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200228 phy_driver_unregister (&lan83c185_driver);
229}
230
231MODULE_DESCRIPTION("SMSC PHY driver");
232MODULE_AUTHOR("Herbert Valerio Riedel");
233MODULE_LICENSE("GPL");
234
235module_init(smsc_init);
236module_exit(smsc_exit);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000237
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000238static struct mdio_device_id __maybe_unused smsc_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000239 { 0x0007c0a0, 0xfffffff0 },
240 { 0x0007c0b0, 0xfffffff0 },
241 { 0x0007c0c0, 0xfffffff0 },
242 { 0x0007c0d0, 0xfffffff0 },
243 { 0x0007c0f0, 0xfffffff0 },
244 { }
245};
246
247MODULE_DEVICE_TABLE(mdio, smsc_tbl);