blob: 88e3991464e7e1531934bcb562718e97abcbfb9b [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 Glendinning90b24cf2012-04-16 12:13:29 +010015 * Support added for SMSC LAN8187 and LAN8700 by steve.glendinning@shawell.net
Steve Glendinning4d9b1a02008-04-28 18:37:29 +010016 *
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
Marek Vasutb6298202012-09-25 10:17:42 +000059static int lan87xx_config_init(struct phy_device *phydev)
60{
61 /*
62 * Make sure the EDPWRDOWN bit is NOT set. Setting this bit on
63 * LAN8710/LAN8720 PHY causes the PHY to misbehave, likely due
64 * to a bug on the chip.
65 *
66 * When the system is powered on with the network cable being
67 * disconnected all the way until after ifconfig ethX up is
68 * issued for the LAN port with this PHY, connecting the cable
69 * afterwards does not cause LINK change detection, while the
70 * expected behavior is the Link UP being detected.
71 */
72 int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
73 if (rc < 0)
74 return rc;
75
76 rc &= ~MII_LAN83C185_EDPWRDOWN;
77
78 rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS, rc);
79 if (rc < 0)
80 return rc;
81
82 return smsc_phy_ack_interrupt(phydev);
83}
84
Giuseppe Cavallaro698244a2010-01-06 20:35:14 -080085static int lan911x_config_init(struct phy_device *phydev)
86{
87 return smsc_phy_ack_interrupt(phydev);
88}
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020089
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +000090static struct phy_driver smsc_phy_driver[] = {
91{
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +020092 .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
93 .phy_id_mask = 0xfffffff0,
94 .name = "SMSC LAN83C185",
95
96 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
97 | SUPPORTED_Asym_Pause),
98 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
99
100 /* basic functions */
101 .config_aneg = genphy_config_aneg,
102 .read_status = genphy_read_status,
Steve Glendinning48c41b92008-04-28 18:36:46 +0100103 .config_init = smsc_phy_config_init,
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200104
105 /* IRQ related */
Steve Glendinning48c41b92008-04-28 18:36:46 +0100106 .ack_interrupt = smsc_phy_ack_interrupt,
107 .config_intr = smsc_phy_config_intr,
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200108
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800109 .suspend = genphy_suspend,
110 .resume = genphy_resume,
111
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200112 .driver = { .owner = THIS_MODULE, }
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000113}, {
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100114 .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
115 .phy_id_mask = 0xfffffff0,
116 .name = "SMSC LAN8187",
117
118 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
119 | SUPPORTED_Asym_Pause),
120 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
121
122 /* basic functions */
123 .config_aneg = genphy_config_aneg,
124 .read_status = genphy_read_status,
125 .config_init = smsc_phy_config_init,
126
127 /* IRQ related */
128 .ack_interrupt = smsc_phy_ack_interrupt,
129 .config_intr = smsc_phy_config_intr,
130
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800131 .suspend = genphy_suspend,
132 .resume = genphy_resume,
133
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100134 .driver = { .owner = THIS_MODULE, }
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000135}, {
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100136 .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
137 .phy_id_mask = 0xfffffff0,
138 .name = "SMSC LAN8700",
139
140 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
141 | SUPPORTED_Asym_Pause),
142 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
143
144 /* basic functions */
145 .config_aneg = genphy_config_aneg,
146 .read_status = genphy_read_status,
147 .config_init = smsc_phy_config_init,
148
149 /* IRQ related */
150 .ack_interrupt = smsc_phy_ack_interrupt,
151 .config_intr = smsc_phy_config_intr,
152
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800153 .suspend = genphy_suspend,
154 .resume = genphy_resume,
155
Steve Glendinning4d9b1a02008-04-28 18:37:29 +0100156 .driver = { .owner = THIS_MODULE, }
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000157}, {
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000158 .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
159 .phy_id_mask = 0xfffffff0,
160 .name = "SMSC LAN911x Internal PHY",
161
162 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
163 | SUPPORTED_Asym_Pause),
164 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
165
166 /* basic functions */
167 .config_aneg = genphy_config_aneg,
168 .read_status = genphy_read_status,
Giuseppe Cavallaro698244a2010-01-06 20:35:14 -0800169 .config_init = lan911x_config_init,
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000170
171 /* IRQ related */
172 .ack_interrupt = smsc_phy_ack_interrupt,
173 .config_intr = smsc_phy_config_intr,
174
Steve Glendinningc64d2a92009-01-22 14:07:43 -0800175 .suspend = genphy_suspend,
176 .resume = genphy_resume,
177
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000178 .driver = { .owner = THIS_MODULE, }
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000179}, {
Steve Glendinninge072b632009-03-23 15:17:31 -0700180 .phy_id = 0x0007c0f0, /* OUI=0x00800f, Model#=0x0f */
181 .phy_id_mask = 0xfffffff0,
182 .name = "SMSC LAN8710/LAN8720",
183
184 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
185 | SUPPORTED_Asym_Pause),
186 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
187
188 /* basic functions */
189 .config_aneg = genphy_config_aneg,
190 .read_status = genphy_read_status,
Marek Vasutb6298202012-09-25 10:17:42 +0000191 .config_init = lan87xx_config_init,
Steve Glendinninge072b632009-03-23 15:17:31 -0700192
193 /* IRQ related */
194 .ack_interrupt = smsc_phy_ack_interrupt,
195 .config_intr = smsc_phy_config_intr,
196
197 .suspend = genphy_suspend,
198 .resume = genphy_resume,
199
200 .driver = { .owner = THIS_MODULE, }
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000201} };
Steve Glendinninge072b632009-03-23 15:17:31 -0700202
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200203static int __init smsc_init(void)
204{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000205 return phy_drivers_register(smsc_phy_driver,
206 ARRAY_SIZE(smsc_phy_driver));
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200207}
208
209static void __exit smsc_exit(void)
210{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000211 return phy_drivers_unregister(smsc_phy_driver,
212 ARRAY_SIZE(smsc_phy_driver));
Herbert Valerio Riedelc9e055a2006-05-07 23:22:53 +0200213}
214
215MODULE_DESCRIPTION("SMSC PHY driver");
216MODULE_AUTHOR("Herbert Valerio Riedel");
217MODULE_LICENSE("GPL");
218
219module_init(smsc_init);
220module_exit(smsc_exit);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000221
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000222static struct mdio_device_id __maybe_unused smsc_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000223 { 0x0007c0a0, 0xfffffff0 },
224 { 0x0007c0b0, 0xfffffff0 },
225 { 0x0007c0c0, 0xfffffff0 },
226 { 0x0007c0d0, 0xfffffff0 },
227 { 0x0007c0f0, 0xfffffff0 },
228 { }
229};
230
231MODULE_DEVICE_TABLE(mdio, smsc_tbl);