Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * PHY drivers for the sungem ethernet driver. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * This file could be shared with other drivers. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 6 | * |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 7 | * (c) 2002-2007, Benjamin Herrenscmidt (benh@kernel.crashing.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * TODO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * - Add support for PHYs that provide an IRQ line |
| 11 | * - Eventually moved the entire polling state machine in |
| 12 | * there (out of the eth driver), so that it can easily be |
| 13 | * skipped on PHYs that implement it in hardware. |
| 14 | * - On LXT971 & BCM5201, Apple uses some chip specific regs |
| 15 | * to read the link status. Figure out why and if it makes |
| 16 | * sense to do the same (magic aneg ?) |
| 17 | * - Apple has some additional power management code for some |
| 18 | * Broadcom PHYs that they "hide" from the OpenSource version |
| 19 | * of darwin, still need to reverse engineer that |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <linux/module.h> |
| 24 | |
| 25 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/types.h> |
| 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/mii.h> |
| 30 | #include <linux/ethtool.h> |
| 31 | #include <linux/delay.h> |
| 32 | |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_PPC_PMAC |
| 34 | #include <asm/prom.h> |
| 35 | #endif |
| 36 | |
Stephen Rothwell | ef37d38 | 2011-08-15 21:02:55 -0700 | [diff] [blame] | 37 | #include <linux/sungem_phy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* Link modes of the BCM5400 PHY */ |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 40 | static const int phy_BCM5400_link_table[8][3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { 0, 0, 0 }, /* No link */ |
| 42 | { 0, 0, 0 }, /* 10BT Half Duplex */ |
| 43 | { 1, 0, 0 }, /* 10BT Full Duplex */ |
| 44 | { 0, 1, 0 }, /* 100BT Half Duplex */ |
| 45 | { 0, 1, 0 }, /* 100BT Half Duplex */ |
| 46 | { 1, 1, 0 }, /* 100BT Full Duplex*/ |
| 47 | { 1, 0, 1 }, /* 1000BT */ |
| 48 | { 1, 0, 1 }, /* 1000BT */ |
| 49 | }; |
| 50 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 51 | static inline int __sungem_phy_read(struct mii_phy* phy, int id, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | return phy->mdio_read(phy->dev, id, reg); |
| 54 | } |
| 55 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 56 | static inline void __sungem_phy_write(struct mii_phy* phy, int id, int reg, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | phy->mdio_write(phy->dev, id, reg, val); |
| 59 | } |
| 60 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 61 | static inline int sungem_phy_read(struct mii_phy* phy, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | return phy->mdio_read(phy->dev, phy->mii_id, reg); |
| 64 | } |
| 65 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 66 | static inline void sungem_phy_write(struct mii_phy* phy, int reg, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | phy->mdio_write(phy->dev, phy->mii_id, reg, val); |
| 69 | } |
| 70 | |
| 71 | static int reset_one_mii_phy(struct mii_phy* phy, int phy_id) |
| 72 | { |
| 73 | u16 val; |
| 74 | int limit = 10000; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 75 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 76 | val = __sungem_phy_read(phy, phy_id, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | val &= ~(BMCR_ISOLATE | BMCR_PDOWN); |
| 78 | val |= BMCR_RESET; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 79 | __sungem_phy_write(phy, phy_id, MII_BMCR, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | udelay(100); |
| 82 | |
Roel Kluin | ff01b91 | 2009-02-02 23:19:50 -0800 | [diff] [blame] | 83 | while (--limit) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 84 | val = __sungem_phy_read(phy, phy_id, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if ((val & BMCR_RESET) == 0) |
| 86 | break; |
| 87 | udelay(10); |
| 88 | } |
| 89 | if ((val & BMCR_ISOLATE) && limit > 0) |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 90 | __sungem_phy_write(phy, phy_id, MII_BMCR, val & ~BMCR_ISOLATE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 91 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 92 | return limit <= 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static int bcm5201_init(struct mii_phy* phy) |
| 96 | { |
| 97 | u16 data; |
| 98 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 99 | data = sungem_phy_read(phy, MII_BCM5201_MULTIPHY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | data &= ~MII_BCM5201_MULTIPHY_SUPERISOLATE; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 101 | sungem_phy_write(phy, MII_BCM5201_MULTIPHY, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 103 | sungem_phy_write(phy, MII_BCM5201_INTERRUPT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int bcm5201_suspend(struct mii_phy* phy) |
| 109 | { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 110 | sungem_phy_write(phy, MII_BCM5201_INTERRUPT, 0); |
| 111 | sungem_phy_write(phy, MII_BCM5201_MULTIPHY, MII_BCM5201_MULTIPHY_SUPERISOLATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static int bcm5221_init(struct mii_phy* phy) |
| 117 | { |
| 118 | u16 data; |
| 119 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 120 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 121 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | data | MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 123 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 124 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2); |
| 125 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | data | MII_BCM5221_SHDOW_AUX_STAT2_APD); |
| 127 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 128 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4); |
| 129 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | data | MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR); |
| 131 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 132 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 133 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | data & ~MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int bcm5221_suspend(struct mii_phy* phy) |
| 140 | { |
| 141 | u16 data; |
| 142 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 143 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 144 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | data | MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 146 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 147 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4); |
| 148 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | data | MII_BCM5221_SHDOW_AUX_MODE4_IDDQMODE); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 154 | static int bcm5241_init(struct mii_phy* phy) |
| 155 | { |
| 156 | u16 data; |
| 157 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 158 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 159 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 160 | data | MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 161 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 162 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2); |
| 163 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 164 | data | MII_BCM5221_SHDOW_AUX_STAT2_APD); |
| 165 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 166 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4); |
| 167 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 168 | data & ~MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR); |
| 169 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 170 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 171 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 172 | data & ~MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static int bcm5241_suspend(struct mii_phy* phy) |
| 178 | { |
| 179 | u16 data; |
| 180 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 181 | data = sungem_phy_read(phy, MII_BCM5221_TEST); |
| 182 | sungem_phy_write(phy, MII_BCM5221_TEST, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 183 | data | MII_BCM5221_TEST_ENABLE_SHADOWS); |
| 184 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 185 | data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4); |
| 186 | sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 187 | data | MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static int bcm5400_init(struct mii_phy* phy) |
| 193 | { |
| 194 | u16 data; |
| 195 | |
| 196 | /* Configure for gigabit full duplex */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 197 | data = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | data |= MII_BCM5400_AUXCONTROL_PWR10BASET; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 199 | sungem_phy_write(phy, MII_BCM5400_AUXCONTROL, data); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 200 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 201 | data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 203 | sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | udelay(100); |
| 206 | |
| 207 | /* Reset and configure cascaded 10/100 PHY */ |
| 208 | (void)reset_one_mii_phy(phy, 0x1f); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 209 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 210 | data = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | data |= MII_BCM5201_MULTIPHY_SERIALMODE; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 212 | __sungem_phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 214 | data = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | data &= ~MII_BCM5400_AUXCONTROL_PWR10BASET; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 216 | sungem_phy_write(phy, MII_BCM5400_AUXCONTROL, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int bcm5400_suspend(struct mii_phy* phy) |
| 222 | { |
| 223 | #if 0 /* Commented out in Darwin... someone has those dawn docs ? */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 224 | sungem_phy_write(phy, MII_BMCR, BMCR_PDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | #endif |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int bcm5401_init(struct mii_phy* phy) |
| 230 | { |
| 231 | u16 data; |
| 232 | int rev; |
| 233 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 234 | rev = sungem_phy_read(phy, MII_PHYSID2) & 0x000f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (rev == 0 || rev == 3) { |
| 236 | /* Some revisions of 5401 appear to need this |
| 237 | * initialisation sequence to disable, according |
| 238 | * to OF, "tap power management" |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 239 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * WARNING ! OF and Darwin don't agree on the |
| 241 | * register addresses. OF seem to interpret the |
| 242 | * register numbers below as decimal |
| 243 | * |
| 244 | * Note: This should (and does) match tg3_init_5401phy_dsp |
| 245 | * in the tg3.c driver. -DaveM |
| 246 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 247 | sungem_phy_write(phy, 0x18, 0x0c20); |
| 248 | sungem_phy_write(phy, 0x17, 0x0012); |
| 249 | sungem_phy_write(phy, 0x15, 0x1804); |
| 250 | sungem_phy_write(phy, 0x17, 0x0013); |
| 251 | sungem_phy_write(phy, 0x15, 0x1204); |
| 252 | sungem_phy_write(phy, 0x17, 0x8006); |
| 253 | sungem_phy_write(phy, 0x15, 0x0132); |
| 254 | sungem_phy_write(phy, 0x17, 0x8006); |
| 255 | sungem_phy_write(phy, 0x15, 0x0232); |
| 256 | sungem_phy_write(phy, 0x17, 0x201f); |
| 257 | sungem_phy_write(phy, 0x15, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | /* Configure for gigabit full duplex */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 261 | data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 263 | sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | udelay(10); |
| 266 | |
| 267 | /* Reset and configure cascaded 10/100 PHY */ |
| 268 | (void)reset_one_mii_phy(phy, 0x1f); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 269 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 270 | data = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | data |= MII_BCM5201_MULTIPHY_SERIALMODE; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 272 | __sungem_phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int bcm5401_suspend(struct mii_phy* phy) |
| 278 | { |
| 279 | #if 0 /* Commented out in Darwin... someone has those dawn docs ? */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 280 | sungem_phy_write(phy, MII_BMCR, BMCR_PDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | #endif |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int bcm5411_init(struct mii_phy* phy) |
| 286 | { |
| 287 | u16 data; |
| 288 | |
| 289 | /* Here's some more Apple black magic to setup |
| 290 | * some voltage stuffs. |
| 291 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 292 | sungem_phy_write(phy, 0x1c, 0x8c23); |
| 293 | sungem_phy_write(phy, 0x1c, 0x8ca3); |
| 294 | sungem_phy_write(phy, 0x1c, 0x8c23); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | /* Here, Apple seems to want to reset it, do |
| 297 | * it as well |
| 298 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 299 | sungem_phy_write(phy, MII_BMCR, BMCR_RESET); |
| 300 | sungem_phy_write(phy, MII_BMCR, 0x1340); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 302 | data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 304 | sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | udelay(10); |
| 307 | |
| 308 | /* Reset and configure cascaded 10/100 PHY */ |
| 309 | (void)reset_one_mii_phy(phy, 0x1f); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 314 | static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) |
| 315 | { |
| 316 | u16 ctl, adv; |
| 317 | |
| 318 | phy->autoneg = 1; |
| 319 | phy->speed = SPEED_10; |
| 320 | phy->duplex = DUPLEX_HALF; |
| 321 | phy->pause = 0; |
| 322 | phy->advertising = advertise; |
| 323 | |
| 324 | /* Setup standard advertise */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 325 | adv = sungem_phy_read(phy, MII_ADVERTISE); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 326 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 327 | if (advertise & ADVERTISED_10baseT_Half) |
| 328 | adv |= ADVERTISE_10HALF; |
| 329 | if (advertise & ADVERTISED_10baseT_Full) |
| 330 | adv |= ADVERTISE_10FULL; |
| 331 | if (advertise & ADVERTISED_100baseT_Half) |
| 332 | adv |= ADVERTISE_100HALF; |
| 333 | if (advertise & ADVERTISED_100baseT_Full) |
| 334 | adv |= ADVERTISE_100FULL; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 335 | sungem_phy_write(phy, MII_ADVERTISE, adv); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 336 | |
| 337 | /* Start/Restart aneg */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 338 | ctl = sungem_phy_read(phy, MII_BMCR); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 339 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 340 | sungem_phy_write(phy, MII_BMCR, ctl); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd) |
| 346 | { |
| 347 | u16 ctl; |
| 348 | |
| 349 | phy->autoneg = 0; |
| 350 | phy->speed = speed; |
| 351 | phy->duplex = fd; |
| 352 | phy->pause = 0; |
| 353 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 354 | ctl = sungem_phy_read(phy, MII_BMCR); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 355 | ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_ANENABLE); |
| 356 | |
| 357 | /* First reset the PHY */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 358 | sungem_phy_write(phy, MII_BMCR, ctl | BMCR_RESET); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 359 | |
| 360 | /* Select speed & duplex */ |
| 361 | switch(speed) { |
| 362 | case SPEED_10: |
| 363 | break; |
| 364 | case SPEED_100: |
| 365 | ctl |= BMCR_SPEED100; |
| 366 | break; |
| 367 | case SPEED_1000: |
| 368 | default: |
| 369 | return -EINVAL; |
| 370 | } |
| 371 | if (fd == DUPLEX_FULL) |
| 372 | ctl |= BMCR_FULLDPLX; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 373 | sungem_phy_write(phy, MII_BMCR, ctl); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int genmii_poll_link(struct mii_phy *phy) |
| 379 | { |
| 380 | u16 status; |
| 381 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 382 | (void)sungem_phy_read(phy, MII_BMSR); |
| 383 | status = sungem_phy_read(phy, MII_BMSR); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 384 | if ((status & BMSR_LSTATUS) == 0) |
| 385 | return 0; |
| 386 | if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE)) |
| 387 | return 0; |
| 388 | return 1; |
| 389 | } |
| 390 | |
| 391 | static int genmii_read_link(struct mii_phy *phy) |
| 392 | { |
| 393 | u16 lpa; |
| 394 | |
| 395 | if (phy->autoneg) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 396 | lpa = sungem_phy_read(phy, MII_LPA); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 397 | |
| 398 | if (lpa & (LPA_10FULL | LPA_100FULL)) |
| 399 | phy->duplex = DUPLEX_FULL; |
| 400 | else |
| 401 | phy->duplex = DUPLEX_HALF; |
| 402 | if (lpa & (LPA_100FULL | LPA_100HALF)) |
| 403 | phy->speed = SPEED_100; |
| 404 | else |
| 405 | phy->speed = SPEED_10; |
| 406 | phy->pause = 0; |
| 407 | } |
| 408 | /* On non-aneg, we assume what we put in BMCR is the speed, |
| 409 | * though magic-aneg shouldn't prevent this case from occurring |
| 410 | */ |
| 411 | |
Jean Sacren | 54f0bad | 2021-11-07 23:59:41 -0700 | [diff] [blame] | 412 | return 0; |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 413 | } |
| 414 | |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 415 | static int generic_suspend(struct mii_phy* phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 417 | sungem_phy_write(phy, MII_BMCR, BMCR_PDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int bcm5421_init(struct mii_phy* phy) |
| 423 | { |
| 424 | u16 data; |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 425 | unsigned int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 427 | id = (sungem_phy_read(phy, MII_PHYSID1) << 16 | sungem_phy_read(phy, MII_PHYSID2)); |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 428 | |
| 429 | /* Revision 0 of 5421 needs some fixups */ |
| 430 | if (id == 0x002060e0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* This is borrowed from MacOS |
| 432 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 433 | sungem_phy_write(phy, 0x18, 0x1007); |
| 434 | data = sungem_phy_read(phy, 0x18); |
| 435 | sungem_phy_write(phy, 0x18, data | 0x0400); |
| 436 | sungem_phy_write(phy, 0x18, 0x0007); |
| 437 | data = sungem_phy_read(phy, 0x18); |
| 438 | sungem_phy_write(phy, 0x18, data | 0x0800); |
| 439 | sungem_phy_write(phy, 0x17, 0x000a); |
| 440 | data = sungem_phy_read(phy, 0x15); |
| 441 | sungem_phy_write(phy, 0x15, data | 0x0200); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 444 | /* Pick up some init code from OF for K2 version */ |
| 445 | if ((id & 0xfffffff0) == 0x002062e0) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 446 | sungem_phy_write(phy, 4, 0x01e1); |
| 447 | sungem_phy_write(phy, 9, 0x0300); |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* Check if we can enable automatic low power */ |
| 451 | #ifdef CONFIG_PPC_PMAC |
| 452 | if (phy->platform_data) { |
| 453 | struct device_node *np = of_get_parent(phy->platform_data); |
| 454 | int can_low_power = 1; |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 455 | if (np == NULL || of_get_property(np, "no-autolowpower", NULL)) |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 456 | can_low_power = 0; |
| 457 | if (can_low_power) { |
| 458 | /* Enable automatic low-power */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 459 | sungem_phy_write(phy, 0x1c, 0x9002); |
| 460 | sungem_phy_write(phy, 0x1c, 0xa821); |
| 461 | sungem_phy_write(phy, 0x1c, 0x941d); |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | #endif /* CONFIG_PPC_PMAC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int bcm54xx_setup_aneg(struct mii_phy *phy, u32 advertise) |
| 470 | { |
| 471 | u16 ctl, adv; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | phy->autoneg = 1; |
| 474 | phy->speed = SPEED_10; |
| 475 | phy->duplex = DUPLEX_HALF; |
| 476 | phy->pause = 0; |
| 477 | phy->advertising = advertise; |
| 478 | |
| 479 | /* Setup standard advertise */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 480 | adv = sungem_phy_read(phy, MII_ADVERTISE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 482 | if (advertise & ADVERTISED_10baseT_Half) |
| 483 | adv |= ADVERTISE_10HALF; |
| 484 | if (advertise & ADVERTISED_10baseT_Full) |
| 485 | adv |= ADVERTISE_10FULL; |
| 486 | if (advertise & ADVERTISED_100baseT_Half) |
| 487 | adv |= ADVERTISE_100HALF; |
| 488 | if (advertise & ADVERTISED_100baseT_Full) |
| 489 | adv |= ADVERTISE_100FULL; |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 490 | if (advertise & ADVERTISED_Pause) |
| 491 | adv |= ADVERTISE_PAUSE_CAP; |
| 492 | if (advertise & ADVERTISED_Asym_Pause) |
| 493 | adv |= ADVERTISE_PAUSE_ASYM; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 494 | sungem_phy_write(phy, MII_ADVERTISE, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | /* Setup 1000BT advertise */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 497 | adv = sungem_phy_read(phy, MII_1000BASETCONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP|MII_1000BASETCONTROL_HALFDUPLEXCAP); |
| 499 | if (advertise & SUPPORTED_1000baseT_Half) |
| 500 | adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; |
| 501 | if (advertise & SUPPORTED_1000baseT_Full) |
| 502 | adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 503 | sungem_phy_write(phy, MII_1000BASETCONTROL, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | /* Start/Restart aneg */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 506 | ctl = sungem_phy_read(phy, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 508 | sungem_phy_write(phy, MII_BMCR, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | static int bcm54xx_setup_forced(struct mii_phy *phy, int speed, int fd) |
| 514 | { |
| 515 | u16 ctl; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | phy->autoneg = 0; |
| 518 | phy->speed = speed; |
| 519 | phy->duplex = fd; |
| 520 | phy->pause = 0; |
| 521 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 522 | ctl = sungem_phy_read(phy, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPD2|BMCR_ANENABLE); |
| 524 | |
| 525 | /* First reset the PHY */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 526 | sungem_phy_write(phy, MII_BMCR, ctl | BMCR_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | /* Select speed & duplex */ |
| 529 | switch(speed) { |
| 530 | case SPEED_10: |
| 531 | break; |
| 532 | case SPEED_100: |
| 533 | ctl |= BMCR_SPEED100; |
| 534 | break; |
| 535 | case SPEED_1000: |
| 536 | ctl |= BMCR_SPD2; |
| 537 | } |
| 538 | if (fd == DUPLEX_FULL) |
| 539 | ctl |= BMCR_FULLDPLX; |
| 540 | |
| 541 | // XXX Should we set the sungem to GII now on 1000BT ? |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 542 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 543 | sungem_phy_write(phy, MII_BMCR, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static int bcm54xx_read_link(struct mii_phy *phy) |
| 549 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 550 | int link_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | u16 val; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | if (phy->autoneg) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 554 | val = sungem_phy_read(phy, MII_BCM5400_AUXSTATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | link_mode = ((val & MII_BCM5400_AUXSTATUS_LINKMODE_MASK) >> |
| 556 | MII_BCM5400_AUXSTATUS_LINKMODE_SHIFT); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 557 | phy->duplex = phy_BCM5400_link_table[link_mode][0] ? |
| 558 | DUPLEX_FULL : DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | phy->speed = phy_BCM5400_link_table[link_mode][2] ? |
| 560 | SPEED_1000 : |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 561 | (phy_BCM5400_link_table[link_mode][1] ? |
| 562 | SPEED_100 : SPEED_10); |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 563 | val = sungem_phy_read(phy, MII_LPA); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 564 | phy->pause = (phy->duplex == DUPLEX_FULL) && |
| 565 | ((val & LPA_PAUSE) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | /* On non-aneg, we assume what we put in BMCR is the speed, |
| 568 | * though magic-aneg shouldn't prevent this case from occurring |
| 569 | */ |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 574 | static int marvell88e1111_init(struct mii_phy* phy) |
| 575 | { |
| 576 | u16 rev; |
| 577 | |
| 578 | /* magic init sequence for rev 0 */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 579 | rev = sungem_phy_read(phy, MII_PHYSID2) & 0x000f; |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 580 | if (rev == 0) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 581 | sungem_phy_write(phy, 0x1d, 0x000a); |
| 582 | sungem_phy_write(phy, 0x1e, 0x0821); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 583 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 584 | sungem_phy_write(phy, 0x1d, 0x0006); |
| 585 | sungem_phy_write(phy, 0x1e, 0x8600); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 586 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 587 | sungem_phy_write(phy, 0x1d, 0x000b); |
| 588 | sungem_phy_write(phy, 0x1e, 0x0100); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 589 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 590 | sungem_phy_write(phy, 0x1d, 0x0004); |
| 591 | sungem_phy_write(phy, 0x1e, 0x4850); |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 592 | } |
| 593 | return 0; |
| 594 | } |
| 595 | |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 596 | #define BCM5421_MODE_MASK (1 << 5) |
| 597 | |
| 598 | static int bcm5421_poll_link(struct mii_phy* phy) |
| 599 | { |
| 600 | u32 phy_reg; |
| 601 | int mode; |
| 602 | |
| 603 | /* find out in what mode we are */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 604 | sungem_phy_write(phy, MII_NCONFIG, 0x1000); |
| 605 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 606 | |
| 607 | mode = (phy_reg & BCM5421_MODE_MASK) >> 5; |
| 608 | |
| 609 | if ( mode == BCM54XX_COPPER) |
| 610 | return genmii_poll_link(phy); |
| 611 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 612 | /* try to find out whether we have a link */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 613 | sungem_phy_write(phy, MII_NCONFIG, 0x2000); |
| 614 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 615 | |
| 616 | if (phy_reg & 0x0020) |
| 617 | return 0; |
| 618 | else |
| 619 | return 1; |
| 620 | } |
| 621 | |
| 622 | static int bcm5421_read_link(struct mii_phy* phy) |
| 623 | { |
| 624 | u32 phy_reg; |
| 625 | int mode; |
| 626 | |
| 627 | /* find out in what mode we are */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 628 | sungem_phy_write(phy, MII_NCONFIG, 0x1000); |
| 629 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 630 | |
| 631 | mode = (phy_reg & BCM5421_MODE_MASK ) >> 5; |
| 632 | |
| 633 | if ( mode == BCM54XX_COPPER) |
| 634 | return bcm54xx_read_link(phy); |
| 635 | |
| 636 | phy->speed = SPEED_1000; |
| 637 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 638 | /* find out whether we are running half- or full duplex */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 639 | sungem_phy_write(phy, MII_NCONFIG, 0x2000); |
| 640 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 641 | |
| 642 | if ( (phy_reg & 0x0080) >> 7) |
| 643 | phy->duplex |= DUPLEX_HALF; |
| 644 | else |
| 645 | phy->duplex |= DUPLEX_FULL; |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | static int bcm5421_enable_fiber(struct mii_phy* phy, int autoneg) |
| 651 | { |
| 652 | /* enable fiber mode */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 653 | sungem_phy_write(phy, MII_NCONFIG, 0x9020); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 654 | /* LEDs active in both modes, autosense prio = fiber */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 655 | sungem_phy_write(phy, MII_NCONFIG, 0x945f); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 656 | |
| 657 | if (!autoneg) { |
| 658 | /* switch off fibre autoneg */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 659 | sungem_phy_write(phy, MII_NCONFIG, 0xfc01); |
| 660 | sungem_phy_write(phy, 0x0b, 0x0004); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | phy->autoneg = autoneg; |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | #define BCM5461_FIBER_LINK (1 << 2) |
| 669 | #define BCM5461_MODE_MASK (3 << 1) |
| 670 | |
| 671 | static int bcm5461_poll_link(struct mii_phy* phy) |
| 672 | { |
| 673 | u32 phy_reg; |
| 674 | int mode; |
| 675 | |
| 676 | /* find out in what mode we are */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 677 | sungem_phy_write(phy, MII_NCONFIG, 0x7c00); |
| 678 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 679 | |
| 680 | mode = (phy_reg & BCM5461_MODE_MASK ) >> 1; |
| 681 | |
| 682 | if ( mode == BCM54XX_COPPER) |
| 683 | return genmii_poll_link(phy); |
| 684 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 685 | /* find out whether we have a link */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 686 | sungem_phy_write(phy, MII_NCONFIG, 0x7000); |
| 687 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 688 | |
| 689 | if (phy_reg & BCM5461_FIBER_LINK) |
| 690 | return 1; |
| 691 | else |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | #define BCM5461_FIBER_DUPLEX (1 << 3) |
| 696 | |
| 697 | static int bcm5461_read_link(struct mii_phy* phy) |
| 698 | { |
| 699 | u32 phy_reg; |
| 700 | int mode; |
| 701 | |
| 702 | /* find out in what mode we are */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 703 | sungem_phy_write(phy, MII_NCONFIG, 0x7c00); |
| 704 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 705 | |
| 706 | mode = (phy_reg & BCM5461_MODE_MASK ) >> 1; |
| 707 | |
| 708 | if ( mode == BCM54XX_COPPER) { |
| 709 | return bcm54xx_read_link(phy); |
| 710 | } |
| 711 | |
| 712 | phy->speed = SPEED_1000; |
| 713 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 714 | /* find out whether we are running half- or full duplex */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 715 | sungem_phy_write(phy, MII_NCONFIG, 0x7000); |
| 716 | phy_reg = sungem_phy_read(phy, MII_NCONFIG); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 717 | |
| 718 | if (phy_reg & BCM5461_FIBER_DUPLEX) |
| 719 | phy->duplex |= DUPLEX_FULL; |
| 720 | else |
| 721 | phy->duplex |= DUPLEX_HALF; |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int bcm5461_enable_fiber(struct mii_phy* phy, int autoneg) |
| 727 | { |
| 728 | /* select fiber mode, enable 1000 base-X registers */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 729 | sungem_phy_write(phy, MII_NCONFIG, 0xfc0b); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 730 | |
| 731 | if (autoneg) { |
| 732 | /* enable fiber with no autonegotiation */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 733 | sungem_phy_write(phy, MII_ADVERTISE, 0x01e0); |
| 734 | sungem_phy_write(phy, MII_BMCR, 0x1140); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 735 | } else { |
| 736 | /* enable fiber with autonegotiation */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 737 | sungem_phy_write(phy, MII_BMCR, 0x0140); |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | phy->autoneg = autoneg; |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise) |
| 746 | { |
| 747 | u16 ctl, adv; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | phy->autoneg = 1; |
| 750 | phy->speed = SPEED_10; |
| 751 | phy->duplex = DUPLEX_HALF; |
| 752 | phy->pause = 0; |
| 753 | phy->advertising = advertise; |
| 754 | |
| 755 | /* Setup standard advertise */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 756 | adv = sungem_phy_read(phy, MII_ADVERTISE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 758 | if (advertise & ADVERTISED_10baseT_Half) |
| 759 | adv |= ADVERTISE_10HALF; |
| 760 | if (advertise & ADVERTISED_10baseT_Full) |
| 761 | adv |= ADVERTISE_10FULL; |
| 762 | if (advertise & ADVERTISED_100baseT_Half) |
| 763 | adv |= ADVERTISE_100HALF; |
| 764 | if (advertise & ADVERTISED_100baseT_Full) |
| 765 | adv |= ADVERTISE_100FULL; |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 766 | if (advertise & ADVERTISED_Pause) |
| 767 | adv |= ADVERTISE_PAUSE_CAP; |
| 768 | if (advertise & ADVERTISED_Asym_Pause) |
| 769 | adv |= ADVERTISE_PAUSE_ASYM; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 770 | sungem_phy_write(phy, MII_ADVERTISE, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | /* Setup 1000BT advertise & enable crossover detect |
| 773 | * XXX How do we advertise 1000BT ? Darwin source is |
| 774 | * confusing here, they read from specific control and |
| 775 | * write to control... Someone has specs for those |
| 776 | * beasts ? |
| 777 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 778 | adv = sungem_phy_read(phy, MII_M1011_PHY_SPEC_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | adv |= MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX; |
| 780 | adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP | |
| 781 | MII_1000BASETCONTROL_HALFDUPLEXCAP); |
| 782 | if (advertise & SUPPORTED_1000baseT_Half) |
| 783 | adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; |
| 784 | if (advertise & SUPPORTED_1000baseT_Full) |
| 785 | adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 786 | sungem_phy_write(phy, MII_1000BASETCONTROL, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | /* Start/Restart aneg */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 789 | ctl = sungem_phy_read(phy, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 791 | sungem_phy_write(phy, MII_BMCR, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int marvell_setup_forced(struct mii_phy *phy, int speed, int fd) |
| 797 | { |
| 798 | u16 ctl, ctl2; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | phy->autoneg = 0; |
| 801 | phy->speed = speed; |
| 802 | phy->duplex = fd; |
| 803 | phy->pause = 0; |
| 804 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 805 | ctl = sungem_phy_read(phy, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPD2|BMCR_ANENABLE); |
| 807 | ctl |= BMCR_RESET; |
| 808 | |
| 809 | /* Select speed & duplex */ |
| 810 | switch(speed) { |
| 811 | case SPEED_10: |
| 812 | break; |
| 813 | case SPEED_100: |
| 814 | ctl |= BMCR_SPEED100; |
| 815 | break; |
| 816 | /* I'm not sure about the one below, again, Darwin source is |
| 817 | * quite confusing and I lack chip specs |
| 818 | */ |
| 819 | case SPEED_1000: |
| 820 | ctl |= BMCR_SPD2; |
| 821 | } |
| 822 | if (fd == DUPLEX_FULL) |
| 823 | ctl |= BMCR_FULLDPLX; |
| 824 | |
| 825 | /* Disable crossover. Again, the way Apple does it is strange, |
| 826 | * though I don't assume they are wrong ;) |
| 827 | */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 828 | ctl2 = sungem_phy_read(phy, MII_M1011_PHY_SPEC_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | ctl2 &= ~(MII_M1011_PHY_SPEC_CONTROL_MANUAL_MDIX | |
| 830 | MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX | |
| 831 | MII_1000BASETCONTROL_FULLDUPLEXCAP | |
| 832 | MII_1000BASETCONTROL_HALFDUPLEXCAP); |
| 833 | if (speed == SPEED_1000) |
| 834 | ctl2 |= (fd == DUPLEX_FULL) ? |
| 835 | MII_1000BASETCONTROL_FULLDUPLEXCAP : |
| 836 | MII_1000BASETCONTROL_HALFDUPLEXCAP; |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 837 | sungem_phy_write(phy, MII_1000BASETCONTROL, ctl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | // XXX Should we set the sungem to GII now on 1000BT ? |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 840 | |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 841 | sungem_phy_write(phy, MII_BMCR, ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | static int marvell_read_link(struct mii_phy *phy) |
| 847 | { |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 848 | u16 status, pmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | if (phy->autoneg) { |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 851 | status = sungem_phy_read(phy, MII_M1011_PHY_SPEC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if ((status & MII_M1011_PHY_SPEC_STATUS_RESOLVED) == 0) |
| 853 | return -EAGAIN; |
| 854 | if (status & MII_M1011_PHY_SPEC_STATUS_1000) |
| 855 | phy->speed = SPEED_1000; |
| 856 | else if (status & MII_M1011_PHY_SPEC_STATUS_100) |
| 857 | phy->speed = SPEED_100; |
| 858 | else |
| 859 | phy->speed = SPEED_10; |
| 860 | if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX) |
| 861 | phy->duplex = DUPLEX_FULL; |
| 862 | else |
| 863 | phy->duplex = DUPLEX_HALF; |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 864 | pmask = MII_M1011_PHY_SPEC_STATUS_TX_PAUSE | |
| 865 | MII_M1011_PHY_SPEC_STATUS_RX_PAUSE; |
| 866 | phy->pause = (status & pmask) == pmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | /* On non-aneg, we assume what we put in BMCR is the speed, |
| 869 | * though magic-aneg shouldn't prevent this case from occurring |
| 870 | */ |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 875 | #define MII_BASIC_FEATURES \ |
| 876 | (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \ |
| 877 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ |
| 878 | SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII | \ |
| 879 | SUPPORTED_Pause) |
| 880 | |
| 881 | /* On gigabit capable PHYs, we advertise Pause support but not asym pause |
| 882 | * support for now as I'm not sure it's supported and Darwin doesn't do |
| 883 | * it neither. --BenH. |
| 884 | */ |
| 885 | #define MII_GBIT_FEATURES \ |
| 886 | (MII_BASIC_FEATURES | \ |
| 887 | SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
| 889 | /* Broadcom BCM 5201 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 890 | static const struct mii_phy_ops bcm5201_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | .init = bcm5201_init, |
| 892 | .suspend = bcm5201_suspend, |
| 893 | .setup_aneg = genmii_setup_aneg, |
| 894 | .setup_forced = genmii_setup_forced, |
| 895 | .poll_link = genmii_poll_link, |
| 896 | .read_link = genmii_read_link, |
| 897 | }; |
| 898 | |
| 899 | static struct mii_phy_def bcm5201_phy_def = { |
| 900 | .phy_id = 0x00406210, |
| 901 | .phy_id_mask = 0xfffffff0, |
| 902 | .name = "BCM5201", |
| 903 | .features = MII_BASIC_FEATURES, |
| 904 | .magic_aneg = 1, |
| 905 | .ops = &bcm5201_phy_ops |
| 906 | }; |
| 907 | |
| 908 | /* Broadcom BCM 5221 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 909 | static const struct mii_phy_ops bcm5221_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | .suspend = bcm5221_suspend, |
| 911 | .init = bcm5221_init, |
| 912 | .setup_aneg = genmii_setup_aneg, |
| 913 | .setup_forced = genmii_setup_forced, |
| 914 | .poll_link = genmii_poll_link, |
| 915 | .read_link = genmii_read_link, |
| 916 | }; |
| 917 | |
| 918 | static struct mii_phy_def bcm5221_phy_def = { |
| 919 | .phy_id = 0x004061e0, |
| 920 | .phy_id_mask = 0xfffffff0, |
| 921 | .name = "BCM5221", |
| 922 | .features = MII_BASIC_FEATURES, |
| 923 | .magic_aneg = 1, |
| 924 | .ops = &bcm5221_phy_ops |
| 925 | }; |
| 926 | |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 927 | /* Broadcom BCM 5241 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 928 | static const struct mii_phy_ops bcm5241_phy_ops = { |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 929 | .suspend = bcm5241_suspend, |
| 930 | .init = bcm5241_init, |
| 931 | .setup_aneg = genmii_setup_aneg, |
| 932 | .setup_forced = genmii_setup_forced, |
| 933 | .poll_link = genmii_poll_link, |
| 934 | .read_link = genmii_read_link, |
| 935 | }; |
| 936 | static struct mii_phy_def bcm5241_phy_def = { |
| 937 | .phy_id = 0x0143bc30, |
| 938 | .phy_id_mask = 0xfffffff0, |
| 939 | .name = "BCM5241", |
| 940 | .features = MII_BASIC_FEATURES, |
| 941 | .magic_aneg = 1, |
| 942 | .ops = &bcm5241_phy_ops |
| 943 | }; |
| 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* Broadcom BCM 5400 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 946 | static const struct mii_phy_ops bcm5400_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | .init = bcm5400_init, |
| 948 | .suspend = bcm5400_suspend, |
| 949 | .setup_aneg = bcm54xx_setup_aneg, |
| 950 | .setup_forced = bcm54xx_setup_forced, |
| 951 | .poll_link = genmii_poll_link, |
| 952 | .read_link = bcm54xx_read_link, |
| 953 | }; |
| 954 | |
| 955 | static struct mii_phy_def bcm5400_phy_def = { |
| 956 | .phy_id = 0x00206040, |
| 957 | .phy_id_mask = 0xfffffff0, |
| 958 | .name = "BCM5400", |
| 959 | .features = MII_GBIT_FEATURES, |
| 960 | .magic_aneg = 1, |
| 961 | .ops = &bcm5400_phy_ops |
| 962 | }; |
| 963 | |
| 964 | /* Broadcom BCM 5401 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 965 | static const struct mii_phy_ops bcm5401_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | .init = bcm5401_init, |
| 967 | .suspend = bcm5401_suspend, |
| 968 | .setup_aneg = bcm54xx_setup_aneg, |
| 969 | .setup_forced = bcm54xx_setup_forced, |
| 970 | .poll_link = genmii_poll_link, |
| 971 | .read_link = bcm54xx_read_link, |
| 972 | }; |
| 973 | |
| 974 | static struct mii_phy_def bcm5401_phy_def = { |
| 975 | .phy_id = 0x00206050, |
| 976 | .phy_id_mask = 0xfffffff0, |
| 977 | .name = "BCM5401", |
| 978 | .features = MII_GBIT_FEATURES, |
| 979 | .magic_aneg = 1, |
| 980 | .ops = &bcm5401_phy_ops |
| 981 | }; |
| 982 | |
| 983 | /* Broadcom BCM 5411 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 984 | static const struct mii_phy_ops bcm5411_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | .init = bcm5411_init, |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 986 | .suspend = generic_suspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | .setup_aneg = bcm54xx_setup_aneg, |
| 988 | .setup_forced = bcm54xx_setup_forced, |
| 989 | .poll_link = genmii_poll_link, |
| 990 | .read_link = bcm54xx_read_link, |
| 991 | }; |
| 992 | |
| 993 | static struct mii_phy_def bcm5411_phy_def = { |
| 994 | .phy_id = 0x00206070, |
| 995 | .phy_id_mask = 0xfffffff0, |
| 996 | .name = "BCM5411", |
| 997 | .features = MII_GBIT_FEATURES, |
| 998 | .magic_aneg = 1, |
| 999 | .ops = &bcm5411_phy_ops |
| 1000 | }; |
| 1001 | |
| 1002 | /* Broadcom BCM 5421 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1003 | static const struct mii_phy_ops bcm5421_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | .init = bcm5421_init, |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 1005 | .suspend = generic_suspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | .setup_aneg = bcm54xx_setup_aneg, |
| 1007 | .setup_forced = bcm54xx_setup_forced, |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 1008 | .poll_link = bcm5421_poll_link, |
| 1009 | .read_link = bcm5421_read_link, |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1010 | .enable_fiber = bcm5421_enable_fiber, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | }; |
| 1012 | |
| 1013 | static struct mii_phy_def bcm5421_phy_def = { |
| 1014 | .phy_id = 0x002060e0, |
| 1015 | .phy_id_mask = 0xfffffff0, |
| 1016 | .name = "BCM5421", |
| 1017 | .features = MII_GBIT_FEATURES, |
| 1018 | .magic_aneg = 1, |
| 1019 | .ops = &bcm5421_phy_ops |
| 1020 | }; |
| 1021 | |
| 1022 | /* Broadcom BCM 5421 built-in K2 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1023 | static const struct mii_phy_ops bcm5421k2_phy_ops = { |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 1024 | .init = bcm5421_init, |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 1025 | .suspend = generic_suspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | .setup_aneg = bcm54xx_setup_aneg, |
| 1027 | .setup_forced = bcm54xx_setup_forced, |
| 1028 | .poll_link = genmii_poll_link, |
| 1029 | .read_link = bcm54xx_read_link, |
| 1030 | }; |
| 1031 | |
| 1032 | static struct mii_phy_def bcm5421k2_phy_def = { |
| 1033 | .phy_id = 0x002062e0, |
| 1034 | .phy_id_mask = 0xfffffff0, |
| 1035 | .name = "BCM5421-K2", |
| 1036 | .features = MII_GBIT_FEATURES, |
| 1037 | .magic_aneg = 1, |
| 1038 | .ops = &bcm5421k2_phy_ops |
| 1039 | }; |
| 1040 | |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1041 | static const struct mii_phy_ops bcm5461_phy_ops = { |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1042 | .init = bcm5421_init, |
| 1043 | .suspend = generic_suspend, |
| 1044 | .setup_aneg = bcm54xx_setup_aneg, |
| 1045 | .setup_forced = bcm54xx_setup_forced, |
Jens Osterkamp | eb5b5b2 | 2007-02-20 16:30:50 -0600 | [diff] [blame] | 1046 | .poll_link = bcm5461_poll_link, |
| 1047 | .read_link = bcm5461_read_link, |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1048 | .enable_fiber = bcm5461_enable_fiber, |
| 1049 | }; |
| 1050 | |
| 1051 | static struct mii_phy_def bcm5461_phy_def = { |
| 1052 | .phy_id = 0x002060c0, |
| 1053 | .phy_id_mask = 0xfffffff0, |
| 1054 | .name = "BCM5461", |
| 1055 | .features = MII_GBIT_FEATURES, |
| 1056 | .magic_aneg = 1, |
| 1057 | .ops = &bcm5461_phy_ops |
| 1058 | }; |
| 1059 | |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 1060 | /* Broadcom BCM 5462 built-in Vesta */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1061 | static const struct mii_phy_ops bcm5462V_phy_ops = { |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 1062 | .init = bcm5421_init, |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 1063 | .suspend = generic_suspend, |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 1064 | .setup_aneg = bcm54xx_setup_aneg, |
| 1065 | .setup_forced = bcm54xx_setup_forced, |
| 1066 | .poll_link = genmii_poll_link, |
| 1067 | .read_link = bcm54xx_read_link, |
| 1068 | }; |
| 1069 | |
| 1070 | static struct mii_phy_def bcm5462V_phy_def = { |
| 1071 | .phy_id = 0x002060d0, |
| 1072 | .phy_id_mask = 0xfffffff0, |
| 1073 | .name = "BCM5462-Vesta", |
| 1074 | .features = MII_GBIT_FEATURES, |
| 1075 | .magic_aneg = 1, |
| 1076 | .ops = &bcm5462V_phy_ops |
| 1077 | }; |
| 1078 | |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 1079 | /* Marvell 88E1101 amd 88E1111 */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1080 | static const struct mii_phy_ops marvell88e1101_phy_ops = { |
Johannes Berg | d47f364 | 2006-04-19 15:42:28 -0700 | [diff] [blame] | 1081 | .suspend = generic_suspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | .setup_aneg = marvell_setup_aneg, |
| 1083 | .setup_forced = marvell_setup_forced, |
| 1084 | .poll_link = genmii_poll_link, |
| 1085 | .read_link = marvell_read_link |
| 1086 | }; |
| 1087 | |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1088 | static const struct mii_phy_ops marvell88e1111_phy_ops = { |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 1089 | .init = marvell88e1111_init, |
| 1090 | .suspend = generic_suspend, |
| 1091 | .setup_aneg = marvell_setup_aneg, |
| 1092 | .setup_forced = marvell_setup_forced, |
| 1093 | .poll_link = genmii_poll_link, |
| 1094 | .read_link = marvell_read_link |
| 1095 | }; |
| 1096 | |
| 1097 | /* two revs in darwin for the 88e1101 ... I could use a datasheet |
| 1098 | * to get the proper names... |
| 1099 | */ |
| 1100 | static struct mii_phy_def marvell88e1101v1_phy_def = { |
| 1101 | .phy_id = 0x01410c20, |
| 1102 | .phy_id_mask = 0xfffffff0, |
| 1103 | .name = "Marvell 88E1101v1", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | .features = MII_GBIT_FEATURES, |
| 1105 | .magic_aneg = 1, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 1106 | .ops = &marvell88e1101_phy_ops |
| 1107 | }; |
| 1108 | static struct mii_phy_def marvell88e1101v2_phy_def = { |
| 1109 | .phy_id = 0x01410c60, |
| 1110 | .phy_id_mask = 0xfffffff0, |
| 1111 | .name = "Marvell 88E1101v2", |
| 1112 | .features = MII_GBIT_FEATURES, |
| 1113 | .magic_aneg = 1, |
| 1114 | .ops = &marvell88e1101_phy_ops |
| 1115 | }; |
| 1116 | static struct mii_phy_def marvell88e1111_phy_def = { |
| 1117 | .phy_id = 0x01410cc0, |
| 1118 | .phy_id_mask = 0xfffffff0, |
| 1119 | .name = "Marvell 88E1111", |
| 1120 | .features = MII_GBIT_FEATURES, |
| 1121 | .magic_aneg = 1, |
| 1122 | .ops = &marvell88e1111_phy_ops |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | }; |
| 1124 | |
| 1125 | /* Generic implementation for most 10/100 PHYs */ |
Bhumika Goyal | 7cb6e01 | 2017-06-08 11:30:57 +0530 | [diff] [blame] | 1126 | static const struct mii_phy_ops generic_phy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | .setup_aneg = genmii_setup_aneg, |
| 1128 | .setup_forced = genmii_setup_forced, |
| 1129 | .poll_link = genmii_poll_link, |
| 1130 | .read_link = genmii_read_link |
| 1131 | }; |
| 1132 | |
| 1133 | static struct mii_phy_def genmii_phy_def = { |
| 1134 | .phy_id = 0x00000000, |
| 1135 | .phy_id_mask = 0x00000000, |
| 1136 | .name = "Generic MII", |
| 1137 | .features = MII_BASIC_FEATURES, |
| 1138 | .magic_aneg = 0, |
| 1139 | .ops = &generic_phy_ops |
| 1140 | }; |
| 1141 | |
| 1142 | static struct mii_phy_def* mii_phy_table[] = { |
| 1143 | &bcm5201_phy_def, |
| 1144 | &bcm5221_phy_def, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 1145 | &bcm5241_phy_def, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | &bcm5400_phy_def, |
| 1147 | &bcm5401_phy_def, |
| 1148 | &bcm5411_phy_def, |
| 1149 | &bcm5421_phy_def, |
| 1150 | &bcm5421k2_phy_def, |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1151 | &bcm5461_phy_def, |
Benjamin Herrenschmidt | 3c326fe | 2005-07-07 17:56:09 -0700 | [diff] [blame] | 1152 | &bcm5462V_phy_def, |
Benjamin Herrenschmidt | 63ea998 | 2007-01-03 18:54:43 -0800 | [diff] [blame] | 1153 | &marvell88e1101v1_phy_def, |
| 1154 | &marvell88e1101v2_phy_def, |
| 1155 | &marvell88e1111_phy_def, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | &genmii_phy_def, |
| 1157 | NULL |
| 1158 | }; |
| 1159 | |
David S. Miller | 19e2f6f | 2011-08-15 23:10:39 -0700 | [diff] [blame] | 1160 | int sungem_phy_probe(struct mii_phy *phy, int mii_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
| 1162 | int rc; |
| 1163 | u32 id; |
| 1164 | struct mii_phy_def* def; |
| 1165 | int i; |
| 1166 | |
| 1167 | /* We do not reset the mii_phy structure as the driver |
| 1168 | * may re-probe the PHY regulary |
| 1169 | */ |
| 1170 | phy->mii_id = mii_id; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | /* Take PHY out of isloate mode and reset it. */ |
| 1173 | rc = reset_one_mii_phy(phy, mii_id); |
| 1174 | if (rc) |
| 1175 | goto fail; |
| 1176 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1177 | /* Read ID and find matching entry */ |
David S. Miller | abc4da4 | 2014-08-27 22:59:26 -0700 | [diff] [blame] | 1178 | id = (sungem_phy_read(phy, MII_PHYSID1) << 16 | sungem_phy_read(phy, MII_PHYSID2)); |
Joe Perches | c6c7598 | 2010-08-17 07:55:04 +0000 | [diff] [blame] | 1179 | printk(KERN_DEBUG KBUILD_MODNAME ": " "PHY ID: %x, addr: %x\n", |
| 1180 | id, mii_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | for (i=0; (def = mii_phy_table[i]) != NULL; i++) |
| 1182 | if ((id & def->phy_id_mask) == def->phy_id) |
| 1183 | break; |
| 1184 | /* Should never be NULL (we have a generic entry), but... */ |
| 1185 | if (def == NULL) |
| 1186 | goto fail; |
| 1187 | |
| 1188 | phy->def = def; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | return 0; |
| 1191 | fail: |
| 1192 | phy->speed = 0; |
| 1193 | phy->duplex = 0; |
| 1194 | phy->pause = 0; |
| 1195 | phy->advertising = 0; |
| 1196 | return -ENODEV; |
| 1197 | } |
| 1198 | |
David S. Miller | 19e2f6f | 2011-08-15 23:10:39 -0700 | [diff] [blame] | 1199 | EXPORT_SYMBOL(sungem_phy_probe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | MODULE_LICENSE("GPL"); |