Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
smsc.c
Go to the documentation of this file.
1 /*
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 <[email protected]>
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  *
15  * Support added for SMSC LAN8187 and LAN8700 by [email protected]
16  *
17  */
18 
19 #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>
25 #include <linux/smscphy.h>
26 
27 static int smsc_phy_config_intr(struct phy_device *phydev)
28 {
29  int rc = phy_write (phydev, MII_LAN83C185_IM,
30  ((PHY_INTERRUPT_ENABLED == phydev->interrupts)
32  : 0));
33 
34  return rc < 0 ? rc : 0;
35 }
36 
37 static int smsc_phy_ack_interrupt(struct phy_device *phydev)
38 {
39  int rc = phy_read (phydev, MII_LAN83C185_ISF);
40 
41  return rc < 0 ? rc : 0;
42 }
43 
44 static int smsc_phy_config_init(struct phy_device *phydev)
45 {
46  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 */
53  if (rc < 0)
54  return rc;
55 
56  return smsc_phy_ack_interrupt (phydev);
57 }
58 
59 static 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 
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 
85 static int lan911x_config_init(struct phy_device *phydev)
86 {
87  return smsc_phy_ack_interrupt(phydev);
88 }
89 
90 static struct phy_driver smsc_phy_driver[] = {
91 {
92  .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
93  .phy_id_mask = 0xfffffff0,
94  .name = "SMSC LAN83C185",
95 
96  .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
99 
100  /* basic functions */
103  .config_init = smsc_phy_config_init,
104 
105  /* IRQ related */
106  .ack_interrupt = smsc_phy_ack_interrupt,
107  .config_intr = smsc_phy_config_intr,
108 
111 
112  .driver = { .owner = THIS_MODULE, }
113 }, {
114  .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
115  .phy_id_mask = 0xfffffff0,
116  .name = "SMSC LAN8187",
117 
118  .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
121 
122  /* basic functions */
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 
133 
134  .driver = { .owner = THIS_MODULE, }
135 }, {
136  .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
137  .phy_id_mask = 0xfffffff0,
138  .name = "SMSC LAN8700",
139 
140  .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
143 
144  /* basic functions */
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 
155 
156  .driver = { .owner = THIS_MODULE, }
157 }, {
158  .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
165 
166  /* basic functions */
169  .config_init = lan911x_config_init,
170 
171  /* IRQ related */
172  .ack_interrupt = smsc_phy_ack_interrupt,
173  .config_intr = smsc_phy_config_intr,
174 
177 
178  .driver = { .owner = THIS_MODULE, }
179 }, {
180  .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
187 
188  /* basic functions */
191  .config_init = lan87xx_config_init,
192 
193  /* IRQ related */
194  .ack_interrupt = smsc_phy_ack_interrupt,
195  .config_intr = smsc_phy_config_intr,
196 
199 
200  .driver = { .owner = THIS_MODULE, }
201 } };
202 
203 static int __init smsc_init(void)
204 {
205  return phy_drivers_register(smsc_phy_driver,
206  ARRAY_SIZE(smsc_phy_driver));
207 }
208 
209 static void __exit smsc_exit(void)
210 {
211  return phy_drivers_unregister(smsc_phy_driver,
212  ARRAY_SIZE(smsc_phy_driver));
213 }
214 
215 MODULE_DESCRIPTION("SMSC PHY driver");
216 MODULE_AUTHOR("Herbert Valerio Riedel");
217 MODULE_LICENSE("GPL");
218 
219 module_init(smsc_init);
220 module_exit(smsc_exit);
221 
222 static struct mdio_device_id __maybe_unused smsc_tbl[] = {
223  { 0x0007c0a0, 0xfffffff0 },
224  { 0x0007c0b0, 0xfffffff0 },
225  { 0x0007c0c0, 0xfffffff0 },
226  { 0x0007c0d0, 0xfffffff0 },
227  { 0x0007c0f0, 0xfffffff0 },
228  { }
229 };
230 
231 MODULE_DEVICE_TABLE(mdio, smsc_tbl);