Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/phy/marvell.c |
| 3 | * |
| 4 | * Driver for Marvell PHYs |
| 5 | * |
| 6 | * Author: Andy Fleming |
| 7 | * |
| 8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. |
| 9 | * |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 10 | * Copyright (c) 2013 Michael Stapelberg <michael@stapelberg.de> |
| 11 | * |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | */ |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 19 | #include <linux/string.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/unistd.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/netdevice.h> |
| 26 | #include <linux/etherdevice.h> |
| 27 | #include <linux/skbuff.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/mm.h> |
| 30 | #include <linux/module.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 31 | #include <linux/mii.h> |
| 32 | #include <linux/ethtool.h> |
| 33 | #include <linux/phy.h> |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 34 | #include <linux/marvell_phy.h> |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 35 | #include <linux/of.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 36 | |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 37 | #include <linux/io.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 38 | #include <asm/irq.h> |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 39 | #include <linux/uaccess.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 40 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 41 | #define MII_MARVELL_PHY_PAGE 22 |
| 42 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 43 | #define MII_M1011_IEVENT 0x13 |
| 44 | #define MII_M1011_IEVENT_CLEAR 0x0000 |
| 45 | |
| 46 | #define MII_M1011_IMASK 0x12 |
| 47 | #define MII_M1011_IMASK_INIT 0x6400 |
| 48 | #define MII_M1011_IMASK_CLEAR 0x0000 |
| 49 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 50 | #define MII_M1011_PHY_SCR 0x10 |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 51 | #define MII_M1011_PHY_SCR_MDI 0x0000 |
| 52 | #define MII_M1011_PHY_SCR_MDI_X 0x0020 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 53 | #define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060 |
| 54 | |
Madalin Bucur | 07151bc | 2015-08-07 17:07:50 +0800 | [diff] [blame] | 55 | #define MII_M1145_PHY_EXT_ADDR_PAGE 0x16 |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 56 | #define MII_M1145_PHY_EXT_SR 0x1b |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 57 | #define MII_M1145_PHY_EXT_CR 0x14 |
| 58 | #define MII_M1145_RGMII_RX_DELAY 0x0080 |
| 59 | #define MII_M1145_RGMII_TX_DELAY 0x0002 |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 60 | #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4 |
| 61 | #define MII_M1145_HWCFG_MODE_MASK 0xf |
| 62 | #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 63 | |
Vince Bridgers | 99d881f | 2014-10-26 14:22:24 -0500 | [diff] [blame] | 64 | #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4 |
| 65 | #define MII_M1145_HWCFG_MODE_MASK 0xf |
| 66 | #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000 |
| 67 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 68 | #define MII_M1111_PHY_LED_CONTROL 0x18 |
| 69 | #define MII_M1111_PHY_LED_DIRECT 0x4100 |
| 70 | #define MII_M1111_PHY_LED_COMBINE 0x411c |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 71 | #define MII_M1111_PHY_EXT_CR 0x14 |
| 72 | #define MII_M1111_RX_DELAY 0x80 |
| 73 | #define MII_M1111_TX_DELAY 0x2 |
| 74 | #define MII_M1111_PHY_EXT_SR 0x1b |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 75 | |
| 76 | #define MII_M1111_HWCFG_MODE_MASK 0xf |
| 77 | #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb |
| 78 | #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3 |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 79 | #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4 |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 80 | #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9 |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 81 | #define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000 |
| 82 | #define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000 |
| 83 | |
| 84 | #define MII_M1111_COPPER 0 |
| 85 | #define MII_M1111_FIBER 1 |
| 86 | |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 87 | #define MII_88E1121_PHY_MSCR_PAGE 2 |
| 88 | #define MII_88E1121_PHY_MSCR_REG 21 |
| 89 | #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5) |
| 90 | #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4) |
| 91 | #define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4)) |
| 92 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 93 | #define MII_88E1318S_PHY_MSCR1_REG 16 |
| 94 | #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 95 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 96 | /* Copper Specific Interrupt Enable Register */ |
| 97 | #define MII_88E1318S_PHY_CSIER 0x12 |
| 98 | /* WOL Event Interrupt Enable */ |
| 99 | #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) |
| 100 | |
| 101 | /* LED Timer Control Register */ |
| 102 | #define MII_88E1318S_PHY_LED_PAGE 0x03 |
| 103 | #define MII_88E1318S_PHY_LED_TCR 0x12 |
| 104 | #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15) |
| 105 | #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7) |
| 106 | #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11) |
| 107 | |
| 108 | /* Magic Packet MAC address registers */ |
| 109 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17 |
| 110 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18 |
| 111 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19 |
| 112 | |
| 113 | #define MII_88E1318S_PHY_WOL_PAGE 0x11 |
| 114 | #define MII_88E1318S_PHY_WOL_CTRL 0x10 |
| 115 | #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12) |
| 116 | #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14) |
| 117 | |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 118 | #define MII_88E1121_PHY_LED_CTRL 16 |
| 119 | #define MII_88E1121_PHY_LED_PAGE 3 |
| 120 | #define MII_88E1121_PHY_LED_DEF 0x0030 |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 121 | |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 122 | #define MII_M1011_PHY_STATUS 0x11 |
| 123 | #define MII_M1011_PHY_STATUS_1000 0x8000 |
| 124 | #define MII_M1011_PHY_STATUS_100 0x4000 |
| 125 | #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000 |
| 126 | #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000 |
| 127 | #define MII_M1011_PHY_STATUS_RESOLVED 0x0800 |
| 128 | #define MII_M1011_PHY_STATUS_LINK 0x0400 |
| 129 | |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 130 | #define MII_M1116R_CONTROL_REG_MAC 21 |
| 131 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 132 | #define MII_88E3016_PHY_SPEC_CTRL 0x10 |
| 133 | #define MII_88E3016_DISABLE_SCRAMBLER 0x0200 |
| 134 | #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 135 | |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 136 | #define MII_88E1510_GEN_CTRL_REG_1 0x14 |
| 137 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7 |
| 138 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */ |
| 139 | #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */ |
| 140 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 141 | #define LPA_FIBER_1000HALF 0x40 |
| 142 | #define LPA_FIBER_1000FULL 0x20 |
| 143 | |
| 144 | #define LPA_PAUSE_FIBER 0x180 |
| 145 | #define LPA_PAUSE_ASYM_FIBER 0x100 |
| 146 | |
| 147 | #define ADVERTISE_FIBER_1000HALF 0x40 |
| 148 | #define ADVERTISE_FIBER_1000FULL 0x20 |
| 149 | |
| 150 | #define ADVERTISE_PAUSE_FIBER 0x180 |
| 151 | #define ADVERTISE_PAUSE_ASYM_FIBER 0x100 |
| 152 | |
| 153 | #define REGISTER_LINK_STATUS 0x400 |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame^] | 154 | #define NB_FIBER_STATS 1 |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 155 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 156 | MODULE_DESCRIPTION("Marvell PHY driver"); |
| 157 | MODULE_AUTHOR("Andy Fleming"); |
| 158 | MODULE_LICENSE("GPL"); |
| 159 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 160 | struct marvell_hw_stat { |
| 161 | const char *string; |
| 162 | u8 page; |
| 163 | u8 reg; |
| 164 | u8 bits; |
| 165 | }; |
| 166 | |
| 167 | static struct marvell_hw_stat marvell_hw_stats[] = { |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame^] | 168 | { "phy_receive_errors_copper", 0, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 169 | { "phy_idle_errors", 0, 10, 8 }, |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame^] | 170 | { "phy_receive_errors_fiber", 1, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | struct marvell_priv { |
| 174 | u64 stats[ARRAY_SIZE(marvell_hw_stats)]; |
| 175 | }; |
| 176 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 177 | static int marvell_ack_interrupt(struct phy_device *phydev) |
| 178 | { |
| 179 | int err; |
| 180 | |
| 181 | /* Clear the interrupts by reading the reg */ |
| 182 | err = phy_read(phydev, MII_M1011_IEVENT); |
| 183 | |
| 184 | if (err < 0) |
| 185 | return err; |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int marvell_config_intr(struct phy_device *phydev) |
| 191 | { |
| 192 | int err; |
| 193 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 194 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 195 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); |
| 196 | else |
| 197 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); |
| 198 | |
| 199 | return err; |
| 200 | } |
| 201 | |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 202 | static int marvell_set_polarity(struct phy_device *phydev, int polarity) |
| 203 | { |
| 204 | int reg; |
| 205 | int err; |
| 206 | int val; |
| 207 | |
| 208 | /* get the current settings */ |
| 209 | reg = phy_read(phydev, MII_M1011_PHY_SCR); |
| 210 | if (reg < 0) |
| 211 | return reg; |
| 212 | |
| 213 | val = reg; |
| 214 | val &= ~MII_M1011_PHY_SCR_AUTO_CROSS; |
| 215 | switch (polarity) { |
| 216 | case ETH_TP_MDI: |
| 217 | val |= MII_M1011_PHY_SCR_MDI; |
| 218 | break; |
| 219 | case ETH_TP_MDI_X: |
| 220 | val |= MII_M1011_PHY_SCR_MDI_X; |
| 221 | break; |
| 222 | case ETH_TP_MDI_AUTO: |
| 223 | case ETH_TP_MDI_INVALID: |
| 224 | default: |
| 225 | val |= MII_M1011_PHY_SCR_AUTO_CROSS; |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | if (val != reg) { |
| 230 | /* Set the new polarity value in the register */ |
| 231 | err = phy_write(phydev, MII_M1011_PHY_SCR, val); |
| 232 | if (err) |
| 233 | return err; |
| 234 | } |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 239 | static int marvell_config_aneg(struct phy_device *phydev) |
| 240 | { |
| 241 | int err; |
| 242 | |
| 243 | /* The Marvell PHY has an errata which requires |
| 244 | * that certain registers get written in order |
| 245 | * to restart autonegotiation */ |
| 246 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 247 | |
| 248 | if (err < 0) |
| 249 | return err; |
| 250 | |
| 251 | err = phy_write(phydev, 0x1d, 0x1f); |
| 252 | if (err < 0) |
| 253 | return err; |
| 254 | |
| 255 | err = phy_write(phydev, 0x1e, 0x200c); |
| 256 | if (err < 0) |
| 257 | return err; |
| 258 | |
| 259 | err = phy_write(phydev, 0x1d, 0x5); |
| 260 | if (err < 0) |
| 261 | return err; |
| 262 | |
| 263 | err = phy_write(phydev, 0x1e, 0); |
| 264 | if (err < 0) |
| 265 | return err; |
| 266 | |
| 267 | err = phy_write(phydev, 0x1e, 0x100); |
| 268 | if (err < 0) |
| 269 | return err; |
| 270 | |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 271 | err = marvell_set_polarity(phydev, phydev->mdix); |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 272 | if (err < 0) |
| 273 | return err; |
| 274 | |
| 275 | err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, |
| 276 | MII_M1111_PHY_LED_DIRECT); |
| 277 | if (err < 0) |
| 278 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 279 | |
| 280 | err = genphy_config_aneg(phydev); |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 281 | if (err < 0) |
| 282 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 283 | |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 284 | if (phydev->autoneg != AUTONEG_ENABLE) { |
| 285 | int bmcr; |
| 286 | |
| 287 | /* |
| 288 | * A write to speed/duplex bits (that is performed by |
| 289 | * genphy_config_aneg() call above) must be followed by |
| 290 | * a software reset. Otherwise, the write has no effect. |
| 291 | */ |
| 292 | bmcr = phy_read(phydev, MII_BMCR); |
| 293 | if (bmcr < 0) |
| 294 | return bmcr; |
| 295 | |
| 296 | err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET); |
| 297 | if (err < 0) |
| 298 | return err; |
| 299 | } |
| 300 | |
| 301 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 302 | } |
| 303 | |
Harini Katakam | 3ec0a0f | 2016-06-27 13:09:59 +0530 | [diff] [blame] | 304 | static int m88e1111_config_aneg(struct phy_device *phydev) |
| 305 | { |
| 306 | int err; |
| 307 | |
| 308 | /* The Marvell PHY has an errata which requires |
| 309 | * that certain registers get written in order |
| 310 | * to restart autonegotiation |
| 311 | */ |
| 312 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 313 | |
| 314 | err = marvell_set_polarity(phydev, phydev->mdix); |
| 315 | if (err < 0) |
| 316 | return err; |
| 317 | |
| 318 | err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, |
| 319 | MII_M1111_PHY_LED_DIRECT); |
| 320 | if (err < 0) |
| 321 | return err; |
| 322 | |
| 323 | err = genphy_config_aneg(phydev); |
| 324 | if (err < 0) |
| 325 | return err; |
| 326 | |
| 327 | if (phydev->autoneg != AUTONEG_ENABLE) { |
| 328 | int bmcr; |
| 329 | |
| 330 | /* A write to speed/duplex bits (that is performed by |
| 331 | * genphy_config_aneg() call above) must be followed by |
| 332 | * a software reset. Otherwise, the write has no effect. |
| 333 | */ |
| 334 | bmcr = phy_read(phydev, MII_BMCR); |
| 335 | if (bmcr < 0) |
| 336 | return bmcr; |
| 337 | |
| 338 | err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET); |
| 339 | if (err < 0) |
| 340 | return err; |
| 341 | } |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 346 | #ifdef CONFIG_OF_MDIO |
| 347 | /* |
| 348 | * Set and/or override some configuration registers based on the |
| 349 | * marvell,reg-init property stored in the of_node for the phydev. |
| 350 | * |
| 351 | * marvell,reg-init = <reg-page reg mask value>,...; |
| 352 | * |
| 353 | * There may be one or more sets of <reg-page reg mask value>: |
| 354 | * |
| 355 | * reg-page: which register bank to use. |
| 356 | * reg: the register. |
| 357 | * mask: if non-zero, ANDed with existing register value. |
| 358 | * value: ORed with the masked value and written to the regiser. |
| 359 | * |
| 360 | */ |
| 361 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 362 | { |
| 363 | const __be32 *paddr; |
| 364 | int len, i, saved_page, current_page, page_changed, ret; |
| 365 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 366 | if (!phydev->mdio.dev.of_node) |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 367 | return 0; |
| 368 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 369 | paddr = of_get_property(phydev->mdio.dev.of_node, |
| 370 | "marvell,reg-init", &len); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 371 | if (!paddr || len < (4 * sizeof(*paddr))) |
| 372 | return 0; |
| 373 | |
| 374 | saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 375 | if (saved_page < 0) |
| 376 | return saved_page; |
| 377 | page_changed = 0; |
| 378 | current_page = saved_page; |
| 379 | |
| 380 | ret = 0; |
| 381 | len /= sizeof(*paddr); |
| 382 | for (i = 0; i < len - 3; i += 4) { |
| 383 | u16 reg_page = be32_to_cpup(paddr + i); |
| 384 | u16 reg = be32_to_cpup(paddr + i + 1); |
| 385 | u16 mask = be32_to_cpup(paddr + i + 2); |
| 386 | u16 val_bits = be32_to_cpup(paddr + i + 3); |
| 387 | int val; |
| 388 | |
| 389 | if (reg_page != current_page) { |
| 390 | current_page = reg_page; |
| 391 | page_changed = 1; |
| 392 | ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page); |
| 393 | if (ret < 0) |
| 394 | goto err; |
| 395 | } |
| 396 | |
| 397 | val = 0; |
| 398 | if (mask) { |
| 399 | val = phy_read(phydev, reg); |
| 400 | if (val < 0) { |
| 401 | ret = val; |
| 402 | goto err; |
| 403 | } |
| 404 | val &= mask; |
| 405 | } |
| 406 | val |= val_bits; |
| 407 | |
| 408 | ret = phy_write(phydev, reg, val); |
| 409 | if (ret < 0) |
| 410 | goto err; |
| 411 | |
| 412 | } |
| 413 | err: |
| 414 | if (page_changed) { |
| 415 | i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page); |
| 416 | if (ret == 0) |
| 417 | ret = i; |
| 418 | } |
| 419 | return ret; |
| 420 | } |
| 421 | #else |
| 422 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 423 | { |
| 424 | return 0; |
| 425 | } |
| 426 | #endif /* CONFIG_OF_MDIO */ |
| 427 | |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 428 | static int m88e1121_config_aneg(struct phy_device *phydev) |
| 429 | { |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 430 | int err, oldpage, mscr; |
| 431 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 432 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 433 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 434 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 435 | MII_88E1121_PHY_MSCR_PAGE); |
| 436 | if (err < 0) |
| 437 | return err; |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 438 | |
Florian Fainelli | 32a6416 | 2015-05-26 12:19:59 -0700 | [diff] [blame] | 439 | if (phy_interface_is_rgmii(phydev)) { |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 440 | |
Arnaud Patard | be8c648 | 2010-10-21 03:59:57 -0700 | [diff] [blame] | 441 | mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) & |
| 442 | MII_88E1121_PHY_MSCR_DELAY_MASK; |
| 443 | |
| 444 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 445 | mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY | |
| 446 | MII_88E1121_PHY_MSCR_TX_DELAY); |
| 447 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 448 | mscr |= MII_88E1121_PHY_MSCR_RX_DELAY; |
| 449 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 450 | mscr |= MII_88E1121_PHY_MSCR_TX_DELAY; |
| 451 | |
| 452 | err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr); |
| 453 | if (err < 0) |
| 454 | return err; |
| 455 | } |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 456 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 457 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 458 | |
| 459 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 460 | if (err < 0) |
| 461 | return err; |
| 462 | |
| 463 | err = phy_write(phydev, MII_M1011_PHY_SCR, |
| 464 | MII_M1011_PHY_SCR_AUTO_CROSS); |
| 465 | if (err < 0) |
| 466 | return err; |
| 467 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 468 | return genphy_config_aneg(phydev); |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 471 | static int m88e1318_config_aneg(struct phy_device *phydev) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 472 | { |
| 473 | int err, oldpage, mscr; |
| 474 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 475 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 476 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 477 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 478 | MII_88E1121_PHY_MSCR_PAGE); |
| 479 | if (err < 0) |
| 480 | return err; |
| 481 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 482 | mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG); |
| 483 | mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD; |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 484 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 485 | err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 486 | if (err < 0) |
| 487 | return err; |
| 488 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 489 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 490 | if (err < 0) |
| 491 | return err; |
| 492 | |
| 493 | return m88e1121_config_aneg(phydev); |
| 494 | } |
| 495 | |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 496 | static int m88e1510_config_aneg(struct phy_device *phydev) |
| 497 | { |
| 498 | int err; |
| 499 | |
| 500 | err = m88e1318_config_aneg(phydev); |
| 501 | if (err < 0) |
| 502 | return err; |
| 503 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static int marvell_config_init(struct phy_device *phydev) |
| 508 | { |
| 509 | /* Set registers from marvell,reg-init DT property */ |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 510 | return marvell_of_reg_init(phydev); |
| 511 | } |
| 512 | |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 513 | static int m88e1116r_config_init(struct phy_device *phydev) |
| 514 | { |
| 515 | int temp; |
| 516 | int err; |
| 517 | |
| 518 | temp = phy_read(phydev, MII_BMCR); |
| 519 | temp |= BMCR_RESET; |
| 520 | err = phy_write(phydev, MII_BMCR, temp); |
| 521 | if (err < 0) |
| 522 | return err; |
| 523 | |
| 524 | mdelay(500); |
| 525 | |
| 526 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 527 | if (err < 0) |
| 528 | return err; |
| 529 | |
| 530 | temp = phy_read(phydev, MII_M1011_PHY_SCR); |
| 531 | temp |= (7 << 12); /* max number of gigabit attempts */ |
| 532 | temp |= (1 << 11); /* enable downshift */ |
| 533 | temp |= MII_M1011_PHY_SCR_AUTO_CROSS; |
| 534 | err = phy_write(phydev, MII_M1011_PHY_SCR, temp); |
| 535 | if (err < 0) |
| 536 | return err; |
| 537 | |
| 538 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2); |
| 539 | if (err < 0) |
| 540 | return err; |
| 541 | temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC); |
| 542 | temp |= (1 << 5); |
| 543 | temp |= (1 << 4); |
| 544 | err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp); |
| 545 | if (err < 0) |
| 546 | return err; |
| 547 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 548 | if (err < 0) |
| 549 | return err; |
| 550 | |
| 551 | temp = phy_read(phydev, MII_BMCR); |
| 552 | temp |= BMCR_RESET; |
| 553 | err = phy_write(phydev, MII_BMCR, temp); |
| 554 | if (err < 0) |
| 555 | return err; |
| 556 | |
| 557 | mdelay(500); |
| 558 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 559 | return marvell_config_init(phydev); |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 562 | static int m88e3016_config_init(struct phy_device *phydev) |
| 563 | { |
| 564 | int reg; |
| 565 | |
| 566 | /* Enable Scrambler and Auto-Crossover */ |
| 567 | reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL); |
| 568 | if (reg < 0) |
| 569 | return reg; |
| 570 | |
| 571 | reg &= ~MII_88E3016_DISABLE_SCRAMBLER; |
| 572 | reg |= MII_88E3016_AUTO_MDIX_CROSSOVER; |
| 573 | |
| 574 | reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg); |
| 575 | if (reg < 0) |
| 576 | return reg; |
| 577 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 578 | return marvell_config_init(phydev); |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 581 | static int m88e1111_config_init(struct phy_device *phydev) |
| 582 | { |
| 583 | int err; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 584 | int temp; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 585 | |
Florian Fainelli | 32a6416 | 2015-05-26 12:19:59 -0700 | [diff] [blame] | 586 | if (phy_interface_is_rgmii(phydev)) { |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 587 | |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 588 | temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); |
| 589 | if (temp < 0) |
| 590 | return temp; |
| 591 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 592 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 593 | temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 594 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { |
| 595 | temp &= ~MII_M1111_TX_DELAY; |
| 596 | temp |= MII_M1111_RX_DELAY; |
| 597 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { |
| 598 | temp &= ~MII_M1111_RX_DELAY; |
| 599 | temp |= MII_M1111_TX_DELAY; |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 600 | } |
| 601 | |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 602 | err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); |
| 603 | if (err < 0) |
| 604 | return err; |
| 605 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 606 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 607 | if (temp < 0) |
| 608 | return temp; |
| 609 | |
| 610 | temp &= ~(MII_M1111_HWCFG_MODE_MASK); |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 611 | |
Wang Jian | 7239016d | 2008-07-16 21:46:20 +0800 | [diff] [blame] | 612 | if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 613 | temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII; |
| 614 | else |
| 615 | temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII; |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 616 | |
| 617 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 618 | if (err < 0) |
| 619 | return err; |
| 620 | } |
| 621 | |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 622 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 623 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 624 | if (temp < 0) |
| 625 | return temp; |
| 626 | |
| 627 | temp &= ~(MII_M1111_HWCFG_MODE_MASK); |
| 628 | temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK; |
Haiying Wang | 32d0c1e | 2009-06-02 04:04:13 +0000 | [diff] [blame] | 629 | temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 630 | |
| 631 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 632 | if (err < 0) |
| 633 | return err; |
Madalin Bucur | 07151bc | 2015-08-07 17:07:50 +0800 | [diff] [blame] | 634 | |
| 635 | /* make sure copper is selected */ |
| 636 | err = phy_read(phydev, MII_M1145_PHY_EXT_ADDR_PAGE); |
| 637 | if (err < 0) |
| 638 | return err; |
| 639 | |
| 640 | err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, |
| 641 | err & (~0xff)); |
| 642 | if (err < 0) |
| 643 | return err; |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 646 | if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { |
| 647 | temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); |
| 648 | if (temp < 0) |
| 649 | return temp; |
| 650 | temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); |
| 651 | err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); |
| 652 | if (err < 0) |
| 653 | return err; |
| 654 | |
| 655 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 656 | if (temp < 0) |
| 657 | return temp; |
| 658 | temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES); |
| 659 | temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
| 660 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 661 | if (err < 0) |
| 662 | return err; |
| 663 | |
| 664 | /* soft reset */ |
| 665 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 666 | if (err < 0) |
| 667 | return err; |
| 668 | do |
| 669 | temp = phy_read(phydev, MII_BMCR); |
| 670 | while (temp & BMCR_RESET); |
| 671 | |
| 672 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 673 | if (temp < 0) |
| 674 | return temp; |
| 675 | temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES); |
| 676 | temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
| 677 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 678 | if (err < 0) |
| 679 | return err; |
| 680 | } |
| 681 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 682 | err = marvell_of_reg_init(phydev); |
| 683 | if (err < 0) |
| 684 | return err; |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 685 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 686 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 687 | } |
| 688 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 689 | static int m88e1121_config_init(struct phy_device *phydev) |
| 690 | { |
| 691 | int err, oldpage; |
| 692 | |
| 693 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 694 | |
| 695 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE); |
| 696 | if (err < 0) |
| 697 | return err; |
| 698 | |
| 699 | /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */ |
| 700 | err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL, |
| 701 | MII_88E1121_PHY_LED_DEF); |
| 702 | if (err < 0) |
| 703 | return err; |
| 704 | |
| 705 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 706 | |
| 707 | /* Set marvell,reg-init configuration from device tree */ |
| 708 | return marvell_config_init(phydev); |
| 709 | } |
| 710 | |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 711 | static int m88e1510_config_init(struct phy_device *phydev) |
| 712 | { |
| 713 | int err; |
| 714 | int temp; |
| 715 | |
| 716 | /* SGMII-to-Copper mode initialization */ |
| 717 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 718 | /* Select page 18 */ |
| 719 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 18); |
| 720 | if (err < 0) |
| 721 | return err; |
| 722 | |
| 723 | /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ |
| 724 | temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1); |
| 725 | temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK; |
| 726 | temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII; |
| 727 | err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp); |
| 728 | if (err < 0) |
| 729 | return err; |
| 730 | |
| 731 | /* PHY reset is necessary after changing MODE[2:0] */ |
| 732 | temp |= MII_88E1510_GEN_CTRL_REG_1_RESET; |
| 733 | err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp); |
| 734 | if (err < 0) |
| 735 | return err; |
| 736 | |
| 737 | /* Reset page selection */ |
| 738 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 739 | if (err < 0) |
| 740 | return err; |
| 741 | } |
| 742 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 743 | return m88e1121_config_init(phydev); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 746 | static int m88e1118_config_aneg(struct phy_device *phydev) |
| 747 | { |
| 748 | int err; |
| 749 | |
| 750 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 751 | if (err < 0) |
| 752 | return err; |
| 753 | |
| 754 | err = phy_write(phydev, MII_M1011_PHY_SCR, |
| 755 | MII_M1011_PHY_SCR_AUTO_CROSS); |
| 756 | if (err < 0) |
| 757 | return err; |
| 758 | |
| 759 | err = genphy_config_aneg(phydev); |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static int m88e1118_config_init(struct phy_device *phydev) |
| 764 | { |
| 765 | int err; |
| 766 | |
| 767 | /* Change address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 768 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 769 | if (err < 0) |
| 770 | return err; |
| 771 | |
| 772 | /* Enable 1000 Mbit */ |
| 773 | err = phy_write(phydev, 0x15, 0x1070); |
| 774 | if (err < 0) |
| 775 | return err; |
| 776 | |
| 777 | /* Change address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 778 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 779 | if (err < 0) |
| 780 | return err; |
| 781 | |
| 782 | /* Adjust LED Control */ |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 783 | if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS) |
| 784 | err = phy_write(phydev, 0x10, 0x1100); |
| 785 | else |
| 786 | err = phy_write(phydev, 0x10, 0x021e); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 787 | if (err < 0) |
| 788 | return err; |
| 789 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 790 | err = marvell_of_reg_init(phydev); |
| 791 | if (err < 0) |
| 792 | return err; |
| 793 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 794 | /* Reset address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 795 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 796 | if (err < 0) |
| 797 | return err; |
| 798 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 799 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 800 | } |
| 801 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 802 | static int m88e1149_config_init(struct phy_device *phydev) |
| 803 | { |
| 804 | int err; |
| 805 | |
| 806 | /* Change address */ |
| 807 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002); |
| 808 | if (err < 0) |
| 809 | return err; |
| 810 | |
| 811 | /* Enable 1000 Mbit */ |
| 812 | err = phy_write(phydev, 0x15, 0x1048); |
| 813 | if (err < 0) |
| 814 | return err; |
| 815 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 816 | err = marvell_of_reg_init(phydev); |
| 817 | if (err < 0) |
| 818 | return err; |
| 819 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 820 | /* Reset address */ |
| 821 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0); |
| 822 | if (err < 0) |
| 823 | return err; |
| 824 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 825 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 828 | static int m88e1145_config_init(struct phy_device *phydev) |
| 829 | { |
| 830 | int err; |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 831 | int temp; |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 832 | |
| 833 | /* Take care of errata E0 & E1 */ |
| 834 | err = phy_write(phydev, 0x1d, 0x001b); |
| 835 | if (err < 0) |
| 836 | return err; |
| 837 | |
| 838 | err = phy_write(phydev, 0x1e, 0x418f); |
| 839 | if (err < 0) |
| 840 | return err; |
| 841 | |
| 842 | err = phy_write(phydev, 0x1d, 0x0016); |
| 843 | if (err < 0) |
| 844 | return err; |
| 845 | |
| 846 | err = phy_write(phydev, 0x1e, 0xa2da); |
| 847 | if (err < 0) |
| 848 | return err; |
| 849 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 850 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 851 | int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR); |
| 852 | if (temp < 0) |
| 853 | return temp; |
| 854 | |
| 855 | temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY); |
| 856 | |
| 857 | err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp); |
| 858 | if (err < 0) |
| 859 | return err; |
| 860 | |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 861 | if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) { |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 862 | err = phy_write(phydev, 0x1d, 0x0012); |
| 863 | if (err < 0) |
| 864 | return err; |
| 865 | |
| 866 | temp = phy_read(phydev, 0x1e); |
| 867 | if (temp < 0) |
| 868 | return temp; |
| 869 | |
| 870 | temp &= 0xf03f; |
| 871 | temp |= 2 << 9; /* 36 ohm */ |
| 872 | temp |= 2 << 6; /* 39 ohm */ |
| 873 | |
| 874 | err = phy_write(phydev, 0x1e, temp); |
| 875 | if (err < 0) |
| 876 | return err; |
| 877 | |
| 878 | err = phy_write(phydev, 0x1d, 0x3); |
| 879 | if (err < 0) |
| 880 | return err; |
| 881 | |
| 882 | err = phy_write(phydev, 0x1e, 0x8000); |
| 883 | if (err < 0) |
| 884 | return err; |
| 885 | } |
| 886 | } |
| 887 | |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 888 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 889 | temp = phy_read(phydev, MII_M1145_PHY_EXT_SR); |
| 890 | if (temp < 0) |
| 891 | return temp; |
| 892 | |
Vince Bridgers | 99d881f | 2014-10-26 14:22:24 -0500 | [diff] [blame] | 893 | temp &= ~MII_M1145_HWCFG_MODE_MASK; |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 894 | temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK; |
| 895 | temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO; |
| 896 | |
| 897 | err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp); |
| 898 | if (err < 0) |
| 899 | return err; |
| 900 | } |
| 901 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 902 | err = marvell_of_reg_init(phydev); |
| 903 | if (err < 0) |
| 904 | return err; |
| 905 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 906 | return 0; |
| 907 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 908 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 909 | /** |
| 910 | * fiber_lpa_to_ethtool_lpa_t |
| 911 | * @lpa: value of the MII_LPA register for fiber link |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 912 | * |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 913 | * A small helper function that translates MII_LPA |
| 914 | * bits to ethtool LP advertisement settings. |
| 915 | */ |
| 916 | static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa) |
| 917 | { |
| 918 | u32 result = 0; |
| 919 | |
| 920 | if (lpa & LPA_FIBER_1000HALF) |
| 921 | result |= ADVERTISED_1000baseT_Half; |
| 922 | if (lpa & LPA_FIBER_1000FULL) |
| 923 | result |= ADVERTISED_1000baseT_Full; |
| 924 | |
| 925 | return result; |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * marvell_update_link - update link status in real time in @phydev |
| 930 | * @phydev: target phy_device struct |
| 931 | * |
| 932 | * Description: Update the value in phydev->link to reflect the |
| 933 | * current link value. |
| 934 | */ |
| 935 | static int marvell_update_link(struct phy_device *phydev, int fiber) |
| 936 | { |
| 937 | int status; |
| 938 | |
| 939 | /* Use the generic register for copper link, or specific |
| 940 | * register for fiber case */ |
| 941 | if (fiber) { |
| 942 | status = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 943 | if (status < 0) |
| 944 | return status; |
| 945 | |
| 946 | if ((status & REGISTER_LINK_STATUS) == 0) |
| 947 | phydev->link = 0; |
| 948 | else |
| 949 | phydev->link = 1; |
| 950 | } else { |
| 951 | return genphy_update_link(phydev); |
| 952 | } |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | /* marvell_read_status_page |
| 958 | * |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 959 | * Description: |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 960 | * Check the link, then figure out the current state |
| 961 | * by comparing what we advertise with what the link partner |
| 962 | * advertises. Start by checking the gigabit possibilities, |
| 963 | * then move on to 10/100. |
| 964 | */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 965 | static int marvell_read_status_page(struct phy_device *phydev, int page) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 966 | { |
| 967 | int adv; |
| 968 | int err; |
| 969 | int lpa; |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 970 | int lpagb; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 971 | int status = 0; |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 972 | int fiber; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 973 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 974 | /* Detect and update the link, but return if there |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 975 | * was an error */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 976 | if (page == MII_M1111_FIBER) |
| 977 | fiber = 1; |
| 978 | else |
| 979 | fiber = 0; |
| 980 | |
| 981 | err = marvell_update_link(phydev, fiber); |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 982 | if (err) |
| 983 | return err; |
| 984 | |
| 985 | if (AUTONEG_ENABLE == phydev->autoneg) { |
| 986 | status = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 987 | if (status < 0) |
| 988 | return status; |
| 989 | |
| 990 | lpa = phy_read(phydev, MII_LPA); |
| 991 | if (lpa < 0) |
| 992 | return lpa; |
| 993 | |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 994 | lpagb = phy_read(phydev, MII_STAT1000); |
| 995 | if (lpagb < 0) |
| 996 | return lpagb; |
| 997 | |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 998 | adv = phy_read(phydev, MII_ADVERTISE); |
| 999 | if (adv < 0) |
| 1000 | return adv; |
| 1001 | |
| 1002 | lpa &= adv; |
| 1003 | |
| 1004 | if (status & MII_M1011_PHY_STATUS_FULLDUPLEX) |
| 1005 | phydev->duplex = DUPLEX_FULL; |
| 1006 | else |
| 1007 | phydev->duplex = DUPLEX_HALF; |
| 1008 | |
| 1009 | status = status & MII_M1011_PHY_STATUS_SPD_MASK; |
| 1010 | phydev->pause = phydev->asym_pause = 0; |
| 1011 | |
| 1012 | switch (status) { |
| 1013 | case MII_M1011_PHY_STATUS_1000: |
| 1014 | phydev->speed = SPEED_1000; |
| 1015 | break; |
| 1016 | |
| 1017 | case MII_M1011_PHY_STATUS_100: |
| 1018 | phydev->speed = SPEED_100; |
| 1019 | break; |
| 1020 | |
| 1021 | default: |
| 1022 | phydev->speed = SPEED_10; |
| 1023 | break; |
| 1024 | } |
| 1025 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1026 | if (!fiber) { |
| 1027 | phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) | |
| 1028 | mii_lpa_to_ethtool_lpa_t(lpa); |
| 1029 | |
| 1030 | if (phydev->duplex == DUPLEX_FULL) { |
| 1031 | phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; |
| 1032 | phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; |
| 1033 | } |
| 1034 | } else { |
| 1035 | /* The fiber link is only 1000M capable */ |
| 1036 | phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa); |
| 1037 | |
| 1038 | if (phydev->duplex == DUPLEX_FULL) { |
| 1039 | if (!(lpa & LPA_PAUSE_FIBER)) { |
| 1040 | phydev->pause = 0; |
| 1041 | phydev->asym_pause = 0; |
| 1042 | } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) { |
| 1043 | phydev->pause = 1; |
| 1044 | phydev->asym_pause = 1; |
| 1045 | } else { |
| 1046 | phydev->pause = 1; |
| 1047 | phydev->asym_pause = 0; |
| 1048 | } |
| 1049 | } |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1050 | } |
| 1051 | } else { |
| 1052 | int bmcr = phy_read(phydev, MII_BMCR); |
| 1053 | |
| 1054 | if (bmcr < 0) |
| 1055 | return bmcr; |
| 1056 | |
| 1057 | if (bmcr & BMCR_FULLDPLX) |
| 1058 | phydev->duplex = DUPLEX_FULL; |
| 1059 | else |
| 1060 | phydev->duplex = DUPLEX_HALF; |
| 1061 | |
| 1062 | if (bmcr & BMCR_SPEED1000) |
| 1063 | phydev->speed = SPEED_1000; |
| 1064 | else if (bmcr & BMCR_SPEED100) |
| 1065 | phydev->speed = SPEED_100; |
| 1066 | else |
| 1067 | phydev->speed = SPEED_10; |
| 1068 | |
| 1069 | phydev->pause = phydev->asym_pause = 0; |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 1070 | phydev->lp_advertising = 0; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1076 | /* marvell_read_status |
| 1077 | * |
| 1078 | * Some Marvell's phys have two modes: fiber and copper. |
| 1079 | * Both need status checked. |
| 1080 | * Description: |
| 1081 | * First, check the fiber link and status. |
| 1082 | * If the fiber link is down, check the copper link and status which |
| 1083 | * will be the default value if both link are down. |
| 1084 | */ |
| 1085 | static int marvell_read_status(struct phy_device *phydev) |
| 1086 | { |
| 1087 | int err; |
| 1088 | |
| 1089 | /* Check the fiber mode first */ |
| 1090 | if (phydev->supported & SUPPORTED_FIBRE) { |
| 1091 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER); |
| 1092 | if (err < 0) |
| 1093 | goto error; |
| 1094 | |
| 1095 | err = marvell_read_status_page(phydev, MII_M1111_FIBER); |
| 1096 | if (err < 0) |
| 1097 | goto error; |
| 1098 | |
| 1099 | /* If the fiber link is up, it is the selected and used link. |
| 1100 | * In this case, we need to stay in the fiber page. |
| 1101 | * Please to be careful about that, avoid to restore Copper page |
| 1102 | * in other functions which could break the behaviour |
| 1103 | * for some fiber phy like 88E1512. |
| 1104 | * */ |
| 1105 | if (phydev->link) |
| 1106 | return 0; |
| 1107 | |
| 1108 | /* If fiber link is down, check and save copper mode state */ |
| 1109 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1110 | if (err < 0) |
| 1111 | goto error; |
| 1112 | } |
| 1113 | |
| 1114 | return marvell_read_status_page(phydev, MII_M1111_COPPER); |
| 1115 | |
| 1116 | error: |
| 1117 | phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1118 | return err; |
| 1119 | } |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1120 | static int marvell_aneg_done(struct phy_device *phydev) |
| 1121 | { |
| 1122 | int retval = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 1123 | return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED); |
| 1124 | } |
| 1125 | |
Anatolij Gustschin | dcd07be | 2009-04-07 02:01:43 +0000 | [diff] [blame] | 1126 | static int m88e1121_did_interrupt(struct phy_device *phydev) |
| 1127 | { |
| 1128 | int imask; |
| 1129 | |
| 1130 | imask = phy_read(phydev, MII_M1011_IEVENT); |
| 1131 | |
| 1132 | if (imask & MII_M1011_IMASK_INIT) |
| 1133 | return 1; |
| 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1138 | static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1139 | { |
| 1140 | wol->supported = WAKE_MAGIC; |
| 1141 | wol->wolopts = 0; |
| 1142 | |
| 1143 | if (phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1144 | MII_88E1318S_PHY_WOL_PAGE) < 0) |
| 1145 | return; |
| 1146 | |
| 1147 | if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) & |
| 1148 | MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE) |
| 1149 | wol->wolopts |= WAKE_MAGIC; |
| 1150 | |
| 1151 | if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0) |
| 1152 | return; |
| 1153 | } |
| 1154 | |
| 1155 | static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1156 | { |
| 1157 | int err, oldpage, temp; |
| 1158 | |
| 1159 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 1160 | |
| 1161 | if (wol->wolopts & WAKE_MAGIC) { |
| 1162 | /* Explicitly switch to page 0x00, just to be sure */ |
| 1163 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00); |
| 1164 | if (err < 0) |
| 1165 | return err; |
| 1166 | |
| 1167 | /* Enable the WOL interrupt */ |
| 1168 | temp = phy_read(phydev, MII_88E1318S_PHY_CSIER); |
| 1169 | temp |= MII_88E1318S_PHY_CSIER_WOL_EIE; |
| 1170 | err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp); |
| 1171 | if (err < 0) |
| 1172 | return err; |
| 1173 | |
| 1174 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1175 | MII_88E1318S_PHY_LED_PAGE); |
| 1176 | if (err < 0) |
| 1177 | return err; |
| 1178 | |
| 1179 | /* Setup LED[2] as interrupt pin (active low) */ |
| 1180 | temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR); |
| 1181 | temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT; |
| 1182 | temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE; |
| 1183 | temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW; |
| 1184 | err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp); |
| 1185 | if (err < 0) |
| 1186 | return err; |
| 1187 | |
| 1188 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1189 | MII_88E1318S_PHY_WOL_PAGE); |
| 1190 | if (err < 0) |
| 1191 | return err; |
| 1192 | |
| 1193 | /* Store the device address for the magic packet */ |
| 1194 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2, |
| 1195 | ((phydev->attached_dev->dev_addr[5] << 8) | |
| 1196 | phydev->attached_dev->dev_addr[4])); |
| 1197 | if (err < 0) |
| 1198 | return err; |
| 1199 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1, |
| 1200 | ((phydev->attached_dev->dev_addr[3] << 8) | |
| 1201 | phydev->attached_dev->dev_addr[2])); |
| 1202 | if (err < 0) |
| 1203 | return err; |
| 1204 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0, |
| 1205 | ((phydev->attached_dev->dev_addr[1] << 8) | |
| 1206 | phydev->attached_dev->dev_addr[0])); |
| 1207 | if (err < 0) |
| 1208 | return err; |
| 1209 | |
| 1210 | /* Clear WOL status and enable magic packet matching */ |
| 1211 | temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL); |
| 1212 | temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS; |
| 1213 | temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE; |
| 1214 | err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp); |
| 1215 | if (err < 0) |
| 1216 | return err; |
| 1217 | } else { |
| 1218 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1219 | MII_88E1318S_PHY_WOL_PAGE); |
| 1220 | if (err < 0) |
| 1221 | return err; |
| 1222 | |
| 1223 | /* Clear WOL status and disable magic packet matching */ |
| 1224 | temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL); |
| 1225 | temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS; |
| 1226 | temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE; |
| 1227 | err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp); |
| 1228 | if (err < 0) |
| 1229 | return err; |
| 1230 | } |
| 1231 | |
| 1232 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 1233 | if (err < 0) |
| 1234 | return err; |
| 1235 | |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1239 | static int marvell_get_sset_count(struct phy_device *phydev) |
| 1240 | { |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame^] | 1241 | if (phydev->supported & SUPPORTED_FIBRE) |
| 1242 | return ARRAY_SIZE(marvell_hw_stats); |
| 1243 | else |
| 1244 | return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static void marvell_get_strings(struct phy_device *phydev, u8 *data) |
| 1248 | { |
| 1249 | int i; |
| 1250 | |
| 1251 | for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) { |
| 1252 | memcpy(data + i * ETH_GSTRING_LEN, |
| 1253 | marvell_hw_stats[i].string, ETH_GSTRING_LEN); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | #ifndef UINT64_MAX |
| 1258 | #define UINT64_MAX (u64)(~((u64)0)) |
| 1259 | #endif |
| 1260 | static u64 marvell_get_stat(struct phy_device *phydev, int i) |
| 1261 | { |
| 1262 | struct marvell_hw_stat stat = marvell_hw_stats[i]; |
| 1263 | struct marvell_priv *priv = phydev->priv; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1264 | int err, oldpage, val; |
| 1265 | u64 ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1266 | |
| 1267 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 1268 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1269 | stat.page); |
| 1270 | if (err < 0) |
| 1271 | return UINT64_MAX; |
| 1272 | |
| 1273 | val = phy_read(phydev, stat.reg); |
| 1274 | if (val < 0) { |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1275 | ret = UINT64_MAX; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1276 | } else { |
| 1277 | val = val & ((1 << stat.bits) - 1); |
| 1278 | priv->stats[i] += val; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1279 | ret = priv->stats[i]; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 1283 | |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1284 | return ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | static void marvell_get_stats(struct phy_device *phydev, |
| 1288 | struct ethtool_stats *stats, u64 *data) |
| 1289 | { |
| 1290 | int i; |
| 1291 | |
| 1292 | for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) |
| 1293 | data[i] = marvell_get_stat(phydev, i); |
| 1294 | } |
| 1295 | |
| 1296 | static int marvell_probe(struct phy_device *phydev) |
| 1297 | { |
| 1298 | struct marvell_priv *priv; |
| 1299 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 1300 | priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1301 | if (!priv) |
| 1302 | return -ENOMEM; |
| 1303 | |
| 1304 | phydev->priv = priv; |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1309 | static struct phy_driver marvell_drivers[] = { |
| 1310 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1311 | .phy_id = MARVELL_PHY_ID_88E1101, |
| 1312 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1313 | .name = "Marvell 88E1101", |
| 1314 | .features = PHY_GBIT_FEATURES, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1315 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1316 | .flags = PHY_HAS_INTERRUPT, |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 1317 | .config_init = &marvell_config_init, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1318 | .config_aneg = &marvell_config_aneg, |
| 1319 | .read_status = &genphy_read_status, |
| 1320 | .ack_interrupt = &marvell_ack_interrupt, |
| 1321 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1322 | .resume = &genphy_resume, |
| 1323 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1324 | .get_sset_count = marvell_get_sset_count, |
| 1325 | .get_strings = marvell_get_strings, |
| 1326 | .get_stats = marvell_get_stats, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1327 | }, |
| 1328 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1329 | .phy_id = MARVELL_PHY_ID_88E1112, |
| 1330 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1331 | .name = "Marvell 88E1112", |
| 1332 | .features = PHY_GBIT_FEATURES, |
| 1333 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1334 | .probe = marvell_probe, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1335 | .config_init = &m88e1111_config_init, |
| 1336 | .config_aneg = &marvell_config_aneg, |
| 1337 | .read_status = &genphy_read_status, |
| 1338 | .ack_interrupt = &marvell_ack_interrupt, |
| 1339 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1340 | .resume = &genphy_resume, |
| 1341 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1342 | .get_sset_count = marvell_get_sset_count, |
| 1343 | .get_strings = marvell_get_strings, |
| 1344 | .get_stats = marvell_get_stats, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1345 | }, |
| 1346 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1347 | .phy_id = MARVELL_PHY_ID_88E1111, |
| 1348 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1349 | .name = "Marvell 88E1111", |
| 1350 | .features = PHY_GBIT_FEATURES, |
| 1351 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1352 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1353 | .config_init = &m88e1111_config_init, |
Harini Katakam | 3ec0a0f | 2016-06-27 13:09:59 +0530 | [diff] [blame] | 1354 | .config_aneg = &m88e1111_config_aneg, |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1355 | .read_status = &marvell_read_status, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1356 | .ack_interrupt = &marvell_ack_interrupt, |
| 1357 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1358 | .resume = &genphy_resume, |
| 1359 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1360 | .get_sset_count = marvell_get_sset_count, |
| 1361 | .get_strings = marvell_get_strings, |
| 1362 | .get_stats = marvell_get_stats, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1363 | }, |
| 1364 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1365 | .phy_id = MARVELL_PHY_ID_88E1118, |
| 1366 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1367 | .name = "Marvell 88E1118", |
| 1368 | .features = PHY_GBIT_FEATURES, |
| 1369 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1370 | .probe = marvell_probe, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1371 | .config_init = &m88e1118_config_init, |
| 1372 | .config_aneg = &m88e1118_config_aneg, |
| 1373 | .read_status = &genphy_read_status, |
| 1374 | .ack_interrupt = &marvell_ack_interrupt, |
| 1375 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1376 | .resume = &genphy_resume, |
| 1377 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1378 | .get_sset_count = marvell_get_sset_count, |
| 1379 | .get_strings = marvell_get_strings, |
| 1380 | .get_stats = marvell_get_stats, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1381 | }, |
| 1382 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1383 | .phy_id = MARVELL_PHY_ID_88E1121R, |
| 1384 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1385 | .name = "Marvell 88E1121R", |
| 1386 | .features = PHY_GBIT_FEATURES, |
| 1387 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1388 | .probe = marvell_probe, |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 1389 | .config_init = &m88e1121_config_init, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1390 | .config_aneg = &m88e1121_config_aneg, |
| 1391 | .read_status = &marvell_read_status, |
| 1392 | .ack_interrupt = &marvell_ack_interrupt, |
| 1393 | .config_intr = &marvell_config_intr, |
Anatolij Gustschin | dcd07be | 2009-04-07 02:01:43 +0000 | [diff] [blame] | 1394 | .did_interrupt = &m88e1121_did_interrupt, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1395 | .resume = &genphy_resume, |
| 1396 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1397 | .get_sset_count = marvell_get_sset_count, |
| 1398 | .get_strings = marvell_get_strings, |
| 1399 | .get_stats = marvell_get_stats, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1400 | }, |
| 1401 | { |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1402 | .phy_id = MARVELL_PHY_ID_88E1318S, |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 1403 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1404 | .name = "Marvell 88E1318S", |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 1405 | .features = PHY_GBIT_FEATURES, |
| 1406 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1407 | .probe = marvell_probe, |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 1408 | .config_init = &m88e1121_config_init, |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1409 | .config_aneg = &m88e1318_config_aneg, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 1410 | .read_status = &marvell_read_status, |
| 1411 | .ack_interrupt = &marvell_ack_interrupt, |
| 1412 | .config_intr = &marvell_config_intr, |
| 1413 | .did_interrupt = &m88e1121_did_interrupt, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1414 | .get_wol = &m88e1318_get_wol, |
| 1415 | .set_wol = &m88e1318_set_wol, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1416 | .resume = &genphy_resume, |
| 1417 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1418 | .get_sset_count = marvell_get_sset_count, |
| 1419 | .get_strings = marvell_get_strings, |
| 1420 | .get_stats = marvell_get_stats, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 1421 | }, |
| 1422 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1423 | .phy_id = MARVELL_PHY_ID_88E1145, |
| 1424 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1425 | .name = "Marvell 88E1145", |
| 1426 | .features = PHY_GBIT_FEATURES, |
| 1427 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1428 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1429 | .config_init = &m88e1145_config_init, |
| 1430 | .config_aneg = &marvell_config_aneg, |
| 1431 | .read_status = &genphy_read_status, |
| 1432 | .ack_interrupt = &marvell_ack_interrupt, |
| 1433 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1434 | .resume = &genphy_resume, |
| 1435 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1436 | .get_sset_count = marvell_get_sset_count, |
| 1437 | .get_strings = marvell_get_strings, |
| 1438 | .get_stats = marvell_get_stats, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 1439 | }, |
| 1440 | { |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1441 | .phy_id = MARVELL_PHY_ID_88E1149R, |
| 1442 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 1443 | .name = "Marvell 88E1149R", |
| 1444 | .features = PHY_GBIT_FEATURES, |
| 1445 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1446 | .probe = marvell_probe, |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1447 | .config_init = &m88e1149_config_init, |
| 1448 | .config_aneg = &m88e1118_config_aneg, |
| 1449 | .read_status = &genphy_read_status, |
| 1450 | .ack_interrupt = &marvell_ack_interrupt, |
| 1451 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1452 | .resume = &genphy_resume, |
| 1453 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1454 | .get_sset_count = marvell_get_sset_count, |
| 1455 | .get_strings = marvell_get_strings, |
| 1456 | .get_stats = marvell_get_stats, |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1457 | }, |
| 1458 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1459 | .phy_id = MARVELL_PHY_ID_88E1240, |
| 1460 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 1461 | .name = "Marvell 88E1240", |
| 1462 | .features = PHY_GBIT_FEATURES, |
| 1463 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1464 | .probe = marvell_probe, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 1465 | .config_init = &m88e1111_config_init, |
| 1466 | .config_aneg = &marvell_config_aneg, |
| 1467 | .read_status = &genphy_read_status, |
| 1468 | .ack_interrupt = &marvell_ack_interrupt, |
| 1469 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1470 | .resume = &genphy_resume, |
| 1471 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1472 | .get_sset_count = marvell_get_sset_count, |
| 1473 | .get_strings = marvell_get_strings, |
| 1474 | .get_stats = marvell_get_stats, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 1475 | }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 1476 | { |
| 1477 | .phy_id = MARVELL_PHY_ID_88E1116R, |
| 1478 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 1479 | .name = "Marvell 88E1116R", |
| 1480 | .features = PHY_GBIT_FEATURES, |
| 1481 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1482 | .probe = marvell_probe, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 1483 | .config_init = &m88e1116r_config_init, |
| 1484 | .config_aneg = &genphy_config_aneg, |
| 1485 | .read_status = &genphy_read_status, |
| 1486 | .ack_interrupt = &marvell_ack_interrupt, |
| 1487 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1488 | .resume = &genphy_resume, |
| 1489 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1490 | .get_sset_count = marvell_get_sset_count, |
| 1491 | .get_strings = marvell_get_strings, |
| 1492 | .get_stats = marvell_get_stats, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 1493 | }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 1494 | { |
| 1495 | .phy_id = MARVELL_PHY_ID_88E1510, |
| 1496 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 1497 | .name = "Marvell 88E1510", |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1498 | .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 1499 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1500 | .probe = marvell_probe, |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 1501 | .config_init = &m88e1510_config_init, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 1502 | .config_aneg = &m88e1510_config_aneg, |
| 1503 | .read_status = &marvell_read_status, |
| 1504 | .ack_interrupt = &marvell_ack_interrupt, |
| 1505 | .config_intr = &marvell_config_intr, |
| 1506 | .did_interrupt = &m88e1121_did_interrupt, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1507 | .resume = &genphy_resume, |
| 1508 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1509 | .get_sset_count = marvell_get_sset_count, |
| 1510 | .get_strings = marvell_get_strings, |
| 1511 | .get_stats = marvell_get_stats, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 1512 | }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1513 | { |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 1514 | .phy_id = MARVELL_PHY_ID_88E1540, |
| 1515 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 1516 | .name = "Marvell 88E1540", |
| 1517 | .features = PHY_GBIT_FEATURES, |
| 1518 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1519 | .probe = marvell_probe, |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 1520 | .config_init = &marvell_config_init, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 1521 | .config_aneg = &m88e1510_config_aneg, |
| 1522 | .read_status = &marvell_read_status, |
| 1523 | .ack_interrupt = &marvell_ack_interrupt, |
| 1524 | .config_intr = &marvell_config_intr, |
| 1525 | .did_interrupt = &m88e1121_did_interrupt, |
| 1526 | .resume = &genphy_resume, |
| 1527 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1528 | .get_sset_count = marvell_get_sset_count, |
| 1529 | .get_strings = marvell_get_strings, |
| 1530 | .get_stats = marvell_get_stats, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 1531 | }, |
| 1532 | { |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1533 | .phy_id = MARVELL_PHY_ID_88E3016, |
| 1534 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 1535 | .name = "Marvell 88E3016", |
| 1536 | .features = PHY_BASIC_FEATURES, |
| 1537 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1538 | .probe = marvell_probe, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1539 | .config_aneg = &genphy_config_aneg, |
| 1540 | .config_init = &m88e3016_config_init, |
| 1541 | .aneg_done = &marvell_aneg_done, |
| 1542 | .read_status = &marvell_read_status, |
| 1543 | .ack_interrupt = &marvell_ack_interrupt, |
| 1544 | .config_intr = &marvell_config_intr, |
| 1545 | .did_interrupt = &m88e1121_did_interrupt, |
| 1546 | .resume = &genphy_resume, |
| 1547 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1548 | .get_sset_count = marvell_get_sset_count, |
| 1549 | .get_strings = marvell_get_strings, |
| 1550 | .get_stats = marvell_get_stats, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1551 | }, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1552 | }; |
| 1553 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 1554 | module_phy_driver(marvell_drivers); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 1555 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 1556 | static struct mdio_device_id __maybe_unused marvell_tbl[] = { |
Michal Simek | f5e1cab | 2013-05-30 20:08:25 +0000 | [diff] [blame] | 1557 | { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK }, |
| 1558 | { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK }, |
| 1559 | { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK }, |
| 1560 | { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK }, |
| 1561 | { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK }, |
| 1562 | { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK }, |
| 1563 | { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK }, |
| 1564 | { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK }, |
| 1565 | { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 1566 | { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 1567 | { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK }, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 1568 | { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1569 | { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK }, |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 1570 | { } |
| 1571 | }; |
| 1572 | |
| 1573 | MODULE_DEVICE_TABLE(mdio, marvell_tbl); |