Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Driver for ICPlus PHYs |
| 3 | * |
| 4 | * Copyright (c) 2007 Freescale Semiconductor, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/unistd.h> |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/netdevice.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/mii.h> |
| 26 | #include <linux/ethtool.h> |
| 27 | #include <linux/phy.h> |
| 28 | |
| 29 | #include <asm/io.h> |
| 30 | #include <asm/irq.h> |
| 31 | #include <asm/uaccess.h> |
| 32 | |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 33 | MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers"); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 34 | MODULE_AUTHOR("Michael Barkowski"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 37 | /* IP101A/G - IP1001 */ |
| 38 | #define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */ |
Stuart Menefy | b4a4963 | 2013-01-23 00:22:36 +0000 | [diff] [blame] | 39 | #define IP1001_RXPHASE_SEL (1<<0) /* Add delay on RX_CLK */ |
| 40 | #define IP1001_TXPHASE_SEL (1<<1) /* Add delay on TX_CLK */ |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 41 | #define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */ |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 42 | #define IP1001_APS_ON 11 /* IP1001 APS Mode bit */ |
| 43 | #define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */ |
Giuseppe CAVALLARO | 996f739 | 2012-04-17 21:16:40 +0000 | [diff] [blame] | 44 | #define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */ |
Giuseppe CAVALLARO | 9ec0db7 | 2012-06-04 05:51:18 +0000 | [diff] [blame] | 45 | #define IP101A_G_IRQ_PIN_USED (1<<15) /* INTR pin used */ |
| 46 | #define IP101A_G_IRQ_DEFAULT IP101A_G_IRQ_PIN_USED |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 47 | |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 48 | static int ip175c_config_init(struct phy_device *phydev) |
| 49 | { |
| 50 | int err, i; |
| 51 | static int full_reset_performed = 0; |
| 52 | |
| 53 | if (full_reset_performed == 0) { |
| 54 | |
| 55 | /* master reset */ |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 56 | err = mdiobus_write(phydev->bus, 30, 0, 0x175c); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 57 | if (err < 0) |
| 58 | return err; |
| 59 | |
| 60 | /* ensure no bus delays overlap reset period */ |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 61 | err = mdiobus_read(phydev->bus, 30, 0); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 62 | |
| 63 | /* data sheet specifies reset period is 2 msec */ |
| 64 | mdelay(2); |
| 65 | |
| 66 | /* enable IP175C mode */ |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 67 | err = mdiobus_write(phydev->bus, 29, 31, 0x175c); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 68 | if (err < 0) |
| 69 | return err; |
| 70 | |
| 71 | /* Set MII0 speed and duplex (in PHY mode) */ |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 72 | err = mdiobus_write(phydev->bus, 29, 22, 0x420); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 73 | if (err < 0) |
| 74 | return err; |
| 75 | |
| 76 | /* reset switch ports */ |
| 77 | for (i = 0; i < 5; i++) { |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 78 | err = mdiobus_write(phydev->bus, i, |
| 79 | MII_BMCR, BMCR_RESET); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 80 | if (err < 0) |
| 81 | return err; |
| 82 | } |
| 83 | |
| 84 | for (i = 0; i < 5; i++) |
David Daney | 76231e0 | 2011-09-30 12:17:48 +0000 | [diff] [blame] | 85 | err = mdiobus_read(phydev->bus, i, MII_BMCR); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 86 | |
| 87 | mdelay(2); |
| 88 | |
| 89 | full_reset_performed = 1; |
| 90 | } |
| 91 | |
| 92 | if (phydev->addr != 4) { |
| 93 | phydev->state = PHY_RUNNING; |
| 94 | phydev->speed = SPEED_100; |
| 95 | phydev->duplex = DUPLEX_FULL; |
| 96 | phydev->link = 1; |
| 97 | netif_carrier_on(phydev->attached_dev); |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 103 | static int ip1xx_reset(struct phy_device *phydev) |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 104 | { |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 105 | int bmcr; |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 106 | |
| 107 | /* Software Reset PHY */ |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 108 | bmcr = phy_read(phydev, MII_BMCR); |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 109 | if (bmcr < 0) |
| 110 | return bmcr; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 111 | bmcr |= BMCR_RESET; |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 112 | bmcr = phy_write(phydev, MII_BMCR, bmcr); |
| 113 | if (bmcr < 0) |
| 114 | return bmcr; |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 115 | |
| 116 | do { |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 117 | bmcr = phy_read(phydev, MII_BMCR); |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 118 | if (bmcr < 0) |
| 119 | return bmcr; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 120 | } while (bmcr & BMCR_RESET); |
| 121 | |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 122 | return 0; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int ip1001_config_init(struct phy_device *phydev) |
| 126 | { |
| 127 | int c; |
| 128 | |
| 129 | c = ip1xx_reset(phydev); |
| 130 | if (c < 0) |
| 131 | return c; |
| 132 | |
| 133 | /* Enable Auto Power Saving mode */ |
| 134 | c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2); |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 135 | if (c < 0) |
| 136 | return c; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 137 | c |= IP1001_APS_ON; |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 138 | c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c); |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 139 | if (c < 0) |
| 140 | return c; |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 141 | |
Stuart Menefy | b4a4963 | 2013-01-23 00:22:36 +0000 | [diff] [blame] | 142 | if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) || |
| 143 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) || |
| 144 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) || |
| 145 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) { |
| 146 | |
Giuseppe CAVALLARO | a4886d5 | 2011-10-10 21:37:56 +0000 | [diff] [blame] | 147 | c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS); |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 148 | if (c < 0) |
| 149 | return c; |
| 150 | |
Stuart Menefy | b4a4963 | 2013-01-23 00:22:36 +0000 | [diff] [blame] | 151 | c &= ~(IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL); |
| 152 | |
| 153 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 154 | c |= (IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL); |
| 155 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 156 | c |= IP1001_RXPHASE_SEL; |
| 157 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 158 | c |= IP1001_TXPHASE_SEL; |
| 159 | |
Giuseppe CAVALLARO | a4886d5 | 2011-10-10 21:37:56 +0000 | [diff] [blame] | 160 | c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c); |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 161 | if (c < 0) |
| 162 | return c; |
Giuseppe CAVALLARO | a4886d5 | 2011-10-10 21:37:56 +0000 | [diff] [blame] | 163 | } |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 164 | |
David McKay | b8e3995 | 2012-02-21 21:24:57 +0000 | [diff] [blame] | 165 | return 0; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 168 | static int ip101a_g_config_init(struct phy_device *phydev) |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 169 | { |
| 170 | int c; |
| 171 | |
| 172 | c = ip1xx_reset(phydev); |
| 173 | if (c < 0) |
| 174 | return c; |
| 175 | |
Giuseppe CAVALLARO | 014f2ff | 2013-01-23 00:22:37 +0000 | [diff] [blame] | 176 | /* INTR pin used: speed/link/duplex will cause an interrupt */ |
| 177 | c = phy_write(phydev, IP101A_G_IRQ_CONF_STATUS, IP101A_G_IRQ_DEFAULT); |
| 178 | if (c < 0) |
| 179 | return c; |
| 180 | |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 181 | /* Enable Auto Power Saving mode */ |
| 182 | c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS); |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 183 | c |= IP101A_G_APS_ON; |
Srinivas Kandagatla | b330014 | 2012-04-02 00:02:09 +0000 | [diff] [blame] | 184 | |
| 185 | return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c); |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 188 | static int ip175c_read_status(struct phy_device *phydev) |
| 189 | { |
| 190 | if (phydev->addr == 4) /* WAN port */ |
| 191 | genphy_read_status(phydev); |
| 192 | else |
| 193 | /* Don't need to read status for switch ports */ |
| 194 | phydev->irq = PHY_IGNORE_INTERRUPT; |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int ip175c_config_aneg(struct phy_device *phydev) |
| 200 | { |
| 201 | if (phydev->addr == 4) /* WAN port */ |
| 202 | genphy_config_aneg(phydev); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Giuseppe CAVALLARO | 996f739 | 2012-04-17 21:16:40 +0000 | [diff] [blame] | 207 | static int ip101a_g_ack_interrupt(struct phy_device *phydev) |
| 208 | { |
| 209 | int err = phy_read(phydev, IP101A_G_IRQ_CONF_STATUS); |
| 210 | if (err < 0) |
| 211 | return err; |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 216 | static struct phy_driver icplus_driver[] = { |
| 217 | { |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 218 | .phy_id = 0x02430d80, |
| 219 | .name = "ICPlus IP175C", |
| 220 | .phy_id_mask = 0x0ffffff0, |
| 221 | .features = PHY_BASIC_FEATURES, |
| 222 | .config_init = &ip175c_config_init, |
| 223 | .config_aneg = &ip175c_config_aneg, |
| 224 | .read_status = &ip175c_read_status, |
Giuseppe Cavallaro | dab1086 | 2010-07-20 13:24:25 -0700 | [diff] [blame] | 225 | .suspend = genphy_suspend, |
| 226 | .resume = genphy_resume, |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 227 | .driver = { .owner = THIS_MODULE,}, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 228 | }, { |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 229 | .phy_id = 0x02430d90, |
| 230 | .name = "ICPlus IP1001", |
| 231 | .phy_id_mask = 0x0ffffff0, |
| 232 | .features = PHY_GBIT_FEATURES | SUPPORTED_Pause | |
| 233 | SUPPORTED_Asym_Pause, |
| 234 | .config_init = &ip1001_config_init, |
| 235 | .config_aneg = &genphy_config_aneg, |
| 236 | .read_status = &genphy_read_status, |
| 237 | .suspend = genphy_suspend, |
| 238 | .resume = genphy_resume, |
| 239 | .driver = { .owner = THIS_MODULE,}, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 240 | }, { |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 241 | .phy_id = 0x02430c54, |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 242 | .name = "ICPlus IP101A/G", |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 243 | .phy_id_mask = 0x0ffffff0, |
| 244 | .features = PHY_BASIC_FEATURES | SUPPORTED_Pause | |
| 245 | SUPPORTED_Asym_Pause, |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 246 | .flags = PHY_HAS_INTERRUPT, |
Giuseppe CAVALLARO | 996f739 | 2012-04-17 21:16:40 +0000 | [diff] [blame] | 247 | .ack_interrupt = ip101a_g_ack_interrupt, |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 248 | .config_init = &ip101a_g_config_init, |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 249 | .config_aneg = &genphy_config_aneg, |
| 250 | .read_status = &genphy_read_status, |
| 251 | .suspend = genphy_suspend, |
| 252 | .resume = genphy_resume, |
| 253 | .driver = { .owner = THIS_MODULE,}, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 254 | } }; |
Giuseppe CAVALLARO | 9c9b1f2 | 2011-09-06 20:14:50 +0000 | [diff] [blame] | 255 | |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 256 | static int __init icplus_init(void) |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 257 | { |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 258 | return phy_drivers_register(icplus_driver, |
| 259 | ARRAY_SIZE(icplus_driver)); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 260 | } |
| 261 | |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 262 | static void __exit icplus_exit(void) |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 263 | { |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 264 | phy_drivers_unregister(icplus_driver, |
| 265 | ARRAY_SIZE(icplus_driver)); |
Michael Barkowski | 0cefeeb | 2007-05-11 18:24:51 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 268 | module_init(icplus_init); |
| 269 | module_exit(icplus_exit); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 270 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 271 | static struct mdio_device_id __maybe_unused icplus_tbl[] = { |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 272 | { 0x02430d80, 0x0ffffff0 }, |
Giuseppe CAVALLARO | 377ecca | 2010-12-08 23:05:13 +0000 | [diff] [blame] | 273 | { 0x02430d90, 0x0ffffff0 }, |
Giuseppe CAVALLARO | e3e09f2 | 2012-02-21 21:26:28 +0000 | [diff] [blame] | 274 | { 0x02430c54, 0x0ffffff0 }, |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 275 | { } |
| 276 | }; |
| 277 | |
| 278 | MODULE_DEVICE_TABLE(mdio, icplus_tbl); |