Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 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 <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 Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 15 | * Support added for SMSC LAN8187 and LAN8700 by steve.glendinning@smsc.com |
| 16 | * |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 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 | |
| 26 | #define MII_LAN83C185_ISF 29 /* Interrupt Source Flags */ |
| 27 | #define MII_LAN83C185_IM 30 /* Interrupt Mask */ |
| 28 | |
| 29 | #define MII_LAN83C185_ISF_INT1 (1<<1) /* Auto-Negotiation Page Received */ |
| 30 | #define MII_LAN83C185_ISF_INT2 (1<<2) /* Parallel Detection Fault */ |
| 31 | #define MII_LAN83C185_ISF_INT3 (1<<3) /* Auto-Negotiation LP Ack */ |
| 32 | #define MII_LAN83C185_ISF_INT4 (1<<4) /* Link Down */ |
| 33 | #define MII_LAN83C185_ISF_INT5 (1<<5) /* Remote Fault Detected */ |
| 34 | #define MII_LAN83C185_ISF_INT6 (1<<6) /* Auto-Negotiation complete */ |
| 35 | #define MII_LAN83C185_ISF_INT7 (1<<7) /* ENERGYON */ |
| 36 | |
| 37 | #define MII_LAN83C185_ISF_INT_ALL (0x0e) |
| 38 | |
| 39 | #define MII_LAN83C185_ISF_INT_PHYLIB_EVENTS \ |
| 40 | (MII_LAN83C185_ISF_INT6 | MII_LAN83C185_ISF_INT4) |
| 41 | |
| 42 | |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 43 | static int smsc_phy_config_intr(struct phy_device *phydev) |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 44 | { |
| 45 | int rc = phy_write (phydev, MII_LAN83C185_IM, |
| 46 | ((PHY_INTERRUPT_ENABLED == phydev->interrupts) |
| 47 | ? MII_LAN83C185_ISF_INT_PHYLIB_EVENTS |
| 48 | : 0)); |
| 49 | |
| 50 | return rc < 0 ? rc : 0; |
| 51 | } |
| 52 | |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 53 | static int smsc_phy_ack_interrupt(struct phy_device *phydev) |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 54 | { |
| 55 | int rc = phy_read (phydev, MII_LAN83C185_ISF); |
| 56 | |
| 57 | return rc < 0 ? rc : 0; |
| 58 | } |
| 59 | |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 60 | static int smsc_phy_config_init(struct phy_device *phydev) |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 61 | { |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 62 | return smsc_phy_ack_interrupt (phydev); |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | static struct phy_driver lan83c185_driver = { |
| 67 | .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */ |
| 68 | .phy_id_mask = 0xfffffff0, |
| 69 | .name = "SMSC LAN83C185", |
| 70 | |
| 71 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 72 | | SUPPORTED_Asym_Pause), |
| 73 | .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG, |
| 74 | |
| 75 | /* basic functions */ |
| 76 | .config_aneg = genphy_config_aneg, |
| 77 | .read_status = genphy_read_status, |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 78 | .config_init = smsc_phy_config_init, |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 79 | |
| 80 | /* IRQ related */ |
Steve Glendinning | 48c41b9 | 2008-04-28 18:36:46 +0100 | [diff] [blame] | 81 | .ack_interrupt = smsc_phy_ack_interrupt, |
| 82 | .config_intr = smsc_phy_config_intr, |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 83 | |
Steve Glendinning | c64d2a9 | 2009-01-22 14:07:43 -0800 | [diff] [blame^] | 84 | .suspend = genphy_suspend, |
| 85 | .resume = genphy_resume, |
| 86 | |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 87 | .driver = { .owner = THIS_MODULE, } |
| 88 | }; |
| 89 | |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 90 | static struct phy_driver lan8187_driver = { |
| 91 | .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */ |
| 92 | .phy_id_mask = 0xfffffff0, |
| 93 | .name = "SMSC LAN8187", |
| 94 | |
| 95 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 96 | | SUPPORTED_Asym_Pause), |
| 97 | .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG, |
| 98 | |
| 99 | /* basic functions */ |
| 100 | .config_aneg = genphy_config_aneg, |
| 101 | .read_status = genphy_read_status, |
| 102 | .config_init = smsc_phy_config_init, |
| 103 | |
| 104 | /* IRQ related */ |
| 105 | .ack_interrupt = smsc_phy_ack_interrupt, |
| 106 | .config_intr = smsc_phy_config_intr, |
| 107 | |
Steve Glendinning | c64d2a9 | 2009-01-22 14:07:43 -0800 | [diff] [blame^] | 108 | .suspend = genphy_suspend, |
| 109 | .resume = genphy_resume, |
| 110 | |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 111 | .driver = { .owner = THIS_MODULE, } |
| 112 | }; |
| 113 | |
| 114 | static struct phy_driver lan8700_driver = { |
| 115 | .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */ |
| 116 | .phy_id_mask = 0xfffffff0, |
| 117 | .name = "SMSC LAN8700", |
| 118 | |
| 119 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 120 | | SUPPORTED_Asym_Pause), |
| 121 | .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG, |
| 122 | |
| 123 | /* basic functions */ |
| 124 | .config_aneg = genphy_config_aneg, |
| 125 | .read_status = genphy_read_status, |
| 126 | .config_init = smsc_phy_config_init, |
| 127 | |
| 128 | /* IRQ related */ |
| 129 | .ack_interrupt = smsc_phy_ack_interrupt, |
| 130 | .config_intr = smsc_phy_config_intr, |
| 131 | |
Steve Glendinning | c64d2a9 | 2009-01-22 14:07:43 -0800 | [diff] [blame^] | 132 | .suspend = genphy_suspend, |
| 133 | .resume = genphy_resume, |
| 134 | |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 135 | .driver = { .owner = THIS_MODULE, } |
| 136 | }; |
| 137 | |
Steve Glendinning | fd9abb3 | 2008-11-05 00:35:37 +0000 | [diff] [blame] | 138 | static struct phy_driver lan911x_int_driver = { |
| 139 | .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */ |
| 140 | .phy_id_mask = 0xfffffff0, |
| 141 | .name = "SMSC LAN911x Internal PHY", |
| 142 | |
| 143 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 144 | | SUPPORTED_Asym_Pause), |
| 145 | .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG, |
| 146 | |
| 147 | /* basic functions */ |
| 148 | .config_aneg = genphy_config_aneg, |
| 149 | .read_status = genphy_read_status, |
| 150 | .config_init = smsc_phy_config_init, |
| 151 | |
| 152 | /* IRQ related */ |
| 153 | .ack_interrupt = smsc_phy_ack_interrupt, |
| 154 | .config_intr = smsc_phy_config_intr, |
| 155 | |
Steve Glendinning | c64d2a9 | 2009-01-22 14:07:43 -0800 | [diff] [blame^] | 156 | .suspend = genphy_suspend, |
| 157 | .resume = genphy_resume, |
| 158 | |
Steve Glendinning | fd9abb3 | 2008-11-05 00:35:37 +0000 | [diff] [blame] | 159 | .driver = { .owner = THIS_MODULE, } |
| 160 | }; |
| 161 | |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 162 | static int __init smsc_init(void) |
| 163 | { |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 164 | int ret; |
| 165 | |
| 166 | ret = phy_driver_register (&lan83c185_driver); |
| 167 | if (ret) |
| 168 | goto err1; |
| 169 | |
| 170 | ret = phy_driver_register (&lan8187_driver); |
| 171 | if (ret) |
| 172 | goto err2; |
| 173 | |
| 174 | ret = phy_driver_register (&lan8700_driver); |
| 175 | if (ret) |
| 176 | goto err3; |
| 177 | |
Steve Glendinning | fd9abb3 | 2008-11-05 00:35:37 +0000 | [diff] [blame] | 178 | ret = phy_driver_register (&lan911x_int_driver); |
| 179 | if (ret) |
| 180 | goto err4; |
| 181 | |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 182 | return 0; |
| 183 | |
Steve Glendinning | fd9abb3 | 2008-11-05 00:35:37 +0000 | [diff] [blame] | 184 | err4: |
| 185 | phy_driver_unregister (&lan8700_driver); |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 186 | err3: |
| 187 | phy_driver_unregister (&lan8187_driver); |
| 188 | err2: |
| 189 | phy_driver_unregister (&lan83c185_driver); |
| 190 | err1: |
| 191 | return ret; |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void __exit smsc_exit(void) |
| 195 | { |
Steve Glendinning | fd9abb3 | 2008-11-05 00:35:37 +0000 | [diff] [blame] | 196 | phy_driver_unregister (&lan911x_int_driver); |
Steve Glendinning | 4d9b1a0 | 2008-04-28 18:37:29 +0100 | [diff] [blame] | 197 | phy_driver_unregister (&lan8700_driver); |
| 198 | phy_driver_unregister (&lan8187_driver); |
Herbert Valerio Riedel | c9e055a | 2006-05-07 23:22:53 +0200 | [diff] [blame] | 199 | phy_driver_unregister (&lan83c185_driver); |
| 200 | } |
| 201 | |
| 202 | MODULE_DESCRIPTION("SMSC PHY driver"); |
| 203 | MODULE_AUTHOR("Herbert Valerio Riedel"); |
| 204 | MODULE_LICENSE("GPL"); |
| 205 | |
| 206 | module_init(smsc_init); |
| 207 | module_exit(smsc_exit); |