David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 1 | /* |
| 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, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 15 | * Support : ksz9021 1000/100/10 phy from Micrel |
| 16 | * ks8001, ks8737, ks8721, ks8041, ks8051 100/10 phy |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/phy.h> |
| 22 | |
| 23 | #define PHY_ID_KSZ9021 0x00221611 |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 24 | #define PHY_ID_KS8737 0x00221720 |
| 25 | #define PHY_ID_KS8041 0x00221510 |
| 26 | #define PHY_ID_KS8051 0x00221550 |
| 27 | /* both for ks8001 Rev. A/B, and for ks8721 Rev 3. */ |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 28 | #define PHY_ID_KS8001 0x0022161A |
| 29 | |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 30 | /* general Interrupt control/status reg in vendor specific block. */ |
| 31 | #define MII_KSZPHY_INTCS 0x1B |
| 32 | #define KSZPHY_INTCS_JABBER (1 << 15) |
| 33 | #define KSZPHY_INTCS_RECEIVE_ERR (1 << 14) |
| 34 | #define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13) |
| 35 | #define KSZPHY_INTCS_PARELLEL (1 << 12) |
| 36 | #define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11) |
| 37 | #define KSZPHY_INTCS_LINK_DOWN (1 << 10) |
| 38 | #define KSZPHY_INTCS_REMOTE_FAULT (1 << 9) |
| 39 | #define KSZPHY_INTCS_LINK_UP (1 << 8) |
| 40 | #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\ |
| 41 | KSZPHY_INTCS_LINK_DOWN) |
| 42 | |
| 43 | /* general PHY control reg in vendor specific block. */ |
| 44 | #define MII_KSZPHY_CTRL 0x1F |
| 45 | /* bitmap of PHY register to set interrupt mode */ |
| 46 | #define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9) |
| 47 | #define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14) |
| 48 | #define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14) |
| 49 | |
| 50 | static int kszphy_ack_interrupt(struct phy_device *phydev) |
| 51 | { |
| 52 | /* bit[7..0] int status, which is a read and clear register. */ |
| 53 | int rc; |
| 54 | |
| 55 | rc = phy_read(phydev, MII_KSZPHY_INTCS); |
| 56 | |
| 57 | return (rc < 0) ? rc : 0; |
| 58 | } |
| 59 | |
| 60 | static int kszphy_set_interrupt(struct phy_device *phydev) |
| 61 | { |
| 62 | int temp; |
| 63 | temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ? |
| 64 | KSZPHY_INTCS_ALL : 0; |
| 65 | return phy_write(phydev, MII_KSZPHY_INTCS, temp); |
| 66 | } |
| 67 | |
| 68 | static int kszphy_config_intr(struct phy_device *phydev) |
| 69 | { |
| 70 | int temp, rc; |
| 71 | |
| 72 | /* set the interrupt pin active low */ |
| 73 | temp = phy_read(phydev, MII_KSZPHY_CTRL); |
| 74 | temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH; |
| 75 | phy_write(phydev, MII_KSZPHY_CTRL, temp); |
| 76 | rc = kszphy_set_interrupt(phydev); |
| 77 | return rc < 0 ? rc : 0; |
| 78 | } |
| 79 | |
| 80 | static int ksz9021_config_intr(struct phy_device *phydev) |
| 81 | { |
| 82 | int temp, rc; |
| 83 | |
| 84 | /* set the interrupt pin active low */ |
| 85 | temp = phy_read(phydev, MII_KSZPHY_CTRL); |
| 86 | temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH; |
| 87 | phy_write(phydev, MII_KSZPHY_CTRL, temp); |
| 88 | rc = kszphy_set_interrupt(phydev); |
| 89 | return rc < 0 ? rc : 0; |
| 90 | } |
| 91 | |
| 92 | static int ks8737_config_intr(struct phy_device *phydev) |
| 93 | { |
| 94 | int temp, rc; |
| 95 | |
| 96 | /* set the interrupt pin active low */ |
| 97 | temp = phy_read(phydev, MII_KSZPHY_CTRL); |
| 98 | temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH; |
| 99 | phy_write(phydev, MII_KSZPHY_CTRL, temp); |
| 100 | rc = kszphy_set_interrupt(phydev); |
| 101 | return rc < 0 ? rc : 0; |
| 102 | } |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 103 | |
| 104 | static int kszphy_config_init(struct phy_device *phydev) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 109 | static struct phy_driver ks8737_driver = { |
| 110 | .phy_id = PHY_ID_KS8737, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 111 | .phy_id_mask = 0x00fffff0, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 112 | .name = "Micrel KS8737", |
| 113 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), |
| 114 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 115 | .config_init = kszphy_config_init, |
| 116 | .config_aneg = genphy_config_aneg, |
| 117 | .read_status = genphy_read_status, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 118 | .ack_interrupt = kszphy_ack_interrupt, |
| 119 | .config_intr = ks8737_config_intr, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 120 | .driver = { .owner = THIS_MODULE,}, |
| 121 | }; |
| 122 | |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 123 | static struct phy_driver ks8041_driver = { |
| 124 | .phy_id = PHY_ID_KS8041, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 125 | .phy_id_mask = 0x00fffff0, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 126 | .name = "Micrel KS8041", |
| 127 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 128 | | SUPPORTED_Asym_Pause), |
| 129 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 130 | .config_init = kszphy_config_init, |
| 131 | .config_aneg = genphy_config_aneg, |
| 132 | .read_status = genphy_read_status, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 133 | .ack_interrupt = kszphy_ack_interrupt, |
| 134 | .config_intr = kszphy_config_intr, |
| 135 | .driver = { .owner = THIS_MODULE,}, |
| 136 | }; |
| 137 | |
| 138 | static struct phy_driver ks8051_driver = { |
| 139 | .phy_id = PHY_ID_KS8051, |
| 140 | .phy_id_mask = 0x00fffff0, |
| 141 | .name = "Micrel KS8051", |
| 142 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
| 143 | | SUPPORTED_Asym_Pause), |
| 144 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
| 145 | .config_init = kszphy_config_init, |
| 146 | .config_aneg = genphy_config_aneg, |
| 147 | .read_status = genphy_read_status, |
| 148 | .ack_interrupt = kszphy_ack_interrupt, |
| 149 | .config_intr = kszphy_config_intr, |
| 150 | .driver = { .owner = THIS_MODULE,}, |
| 151 | }; |
| 152 | |
| 153 | static struct phy_driver ks8001_driver = { |
| 154 | .phy_id = PHY_ID_KS8001, |
| 155 | .name = "Micrel KS8001 or KS8721", |
| 156 | .phy_id_mask = 0x00fffff0, |
| 157 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), |
| 158 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
| 159 | .config_init = kszphy_config_init, |
| 160 | .config_aneg = genphy_config_aneg, |
| 161 | .read_status = genphy_read_status, |
| 162 | .ack_interrupt = kszphy_ack_interrupt, |
| 163 | .config_intr = kszphy_config_intr, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 164 | .driver = { .owner = THIS_MODULE,}, |
| 165 | }; |
| 166 | |
| 167 | static struct phy_driver ksz9021_driver = { |
| 168 | .phy_id = PHY_ID_KSZ9021, |
| 169 | .phy_id_mask = 0x000fff10, |
| 170 | .name = "Micrel KSZ9021 Gigabit PHY", |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 171 | .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause |
| 172 | | SUPPORTED_Asym_Pause), |
| 173 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 174 | .config_init = kszphy_config_init, |
| 175 | .config_aneg = genphy_config_aneg, |
| 176 | .read_status = genphy_read_status, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 177 | .ack_interrupt = kszphy_ack_interrupt, |
| 178 | .config_intr = ksz9021_config_intr, |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 179 | .driver = { .owner = THIS_MODULE, }, |
| 180 | }; |
| 181 | |
| 182 | static int __init ksphy_init(void) |
| 183 | { |
| 184 | int ret; |
| 185 | |
| 186 | ret = phy_driver_register(&ks8001_driver); |
| 187 | if (ret) |
| 188 | goto err1; |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 189 | |
| 190 | ret = phy_driver_register(&ksz9021_driver); |
| 191 | if (ret) |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 192 | goto err2; |
| 193 | |
| 194 | ret = phy_driver_register(&ks8737_driver); |
| 195 | if (ret) |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 196 | goto err3; |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 197 | ret = phy_driver_register(&ks8041_driver); |
| 198 | if (ret) |
| 199 | goto err4; |
| 200 | ret = phy_driver_register(&ks8051_driver); |
| 201 | if (ret) |
| 202 | goto err5; |
| 203 | |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 206 | err5: |
| 207 | phy_driver_unregister(&ks8041_driver); |
| 208 | err4: |
| 209 | phy_driver_unregister(&ks8737_driver); |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 210 | err3: |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 211 | phy_driver_unregister(&ksz9021_driver); |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 212 | err2: |
| 213 | phy_driver_unregister(&ks8001_driver); |
| 214 | err1: |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | static void __exit ksphy_exit(void) |
| 219 | { |
| 220 | phy_driver_unregister(&ks8001_driver); |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 221 | phy_driver_unregister(&ks8737_driver); |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 222 | phy_driver_unregister(&ksz9021_driver); |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 223 | phy_driver_unregister(&ks8041_driver); |
| 224 | phy_driver_unregister(&ks8051_driver); |
David J. Choi | d050700 | 2010-04-29 06:12:41 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | module_init(ksphy_init); |
| 228 | module_exit(ksphy_exit); |
| 229 | |
| 230 | MODULE_DESCRIPTION("Micrel PHY driver"); |
| 231 | MODULE_AUTHOR("David J. Choi"); |
| 232 | MODULE_LICENSE("GPL"); |
David S. Miller | 52a60ed | 2010-05-03 15:48:29 -0700 | [diff] [blame] | 233 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 234 | static struct mdio_device_id __maybe_unused micrel_tbl[] = { |
David S. Miller | 52a60ed | 2010-05-03 15:48:29 -0700 | [diff] [blame] | 235 | { PHY_ID_KSZ9021, 0x000fff10 }, |
David S. Miller | 52a60ed | 2010-05-03 15:48:29 -0700 | [diff] [blame] | 236 | { PHY_ID_KS8001, 0x00fffff0 }, |
Choi, David | 51f932c | 2010-06-28 15:23:41 +0000 | [diff] [blame] | 237 | { PHY_ID_KS8737, 0x00fffff0 }, |
| 238 | { PHY_ID_KS8041, 0x00fffff0 }, |
| 239 | { PHY_ID_KS8051, 0x00fffff0 }, |
David S. Miller | 52a60ed | 2010-05-03 15:48:29 -0700 | [diff] [blame] | 240 | { } |
| 241 | }; |
| 242 | |
| 243 | MODULE_DEVICE_TABLE(mdio, micrel_tbl); |