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> |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 20 | #include <linux/ctype.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <linux/unistd.h> |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 23 | #include <linux/hwmon.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/module.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 33 | #include <linux/mii.h> |
| 34 | #include <linux/ethtool.h> |
| 35 | #include <linux/phy.h> |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 36 | #include <linux/marvell_phy.h> |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 37 | #include <linux/of.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 38 | |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 39 | #include <linux/io.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 40 | #include <asm/irq.h> |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 41 | #include <linux/uaccess.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 42 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 43 | #define MII_MARVELL_PHY_PAGE 22 |
| 44 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 45 | #define MII_M1011_IEVENT 0x13 |
| 46 | #define MII_M1011_IEVENT_CLEAR 0x0000 |
| 47 | |
| 48 | #define MII_M1011_IMASK 0x12 |
| 49 | #define MII_M1011_IMASK_INIT 0x6400 |
| 50 | #define MII_M1011_IMASK_CLEAR 0x0000 |
| 51 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 52 | #define MII_M1011_PHY_SCR 0x10 |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 53 | #define MII_M1011_PHY_SCR_MDI 0x0000 |
| 54 | #define MII_M1011_PHY_SCR_MDI_X 0x0020 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 55 | #define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060 |
| 56 | |
Madalin Bucur | 07151bc | 2015-08-07 17:07:50 +0800 | [diff] [blame] | 57 | #define MII_M1145_PHY_EXT_ADDR_PAGE 0x16 |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 58 | #define MII_M1145_PHY_EXT_SR 0x1b |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 59 | #define MII_M1145_PHY_EXT_CR 0x14 |
| 60 | #define MII_M1145_RGMII_RX_DELAY 0x0080 |
| 61 | #define MII_M1145_RGMII_TX_DELAY 0x0002 |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 62 | #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4 |
| 63 | #define MII_M1145_HWCFG_MODE_MASK 0xf |
| 64 | #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 65 | |
Vince Bridgers | 99d881f | 2014-10-26 14:22:24 -0500 | [diff] [blame] | 66 | #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4 |
| 67 | #define MII_M1145_HWCFG_MODE_MASK 0xf |
| 68 | #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000 |
| 69 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 70 | #define MII_M1111_PHY_LED_CONTROL 0x18 |
| 71 | #define MII_M1111_PHY_LED_DIRECT 0x4100 |
| 72 | #define MII_M1111_PHY_LED_COMBINE 0x411c |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 73 | #define MII_M1111_PHY_EXT_CR 0x14 |
| 74 | #define MII_M1111_RX_DELAY 0x80 |
| 75 | #define MII_M1111_TX_DELAY 0x2 |
| 76 | #define MII_M1111_PHY_EXT_SR 0x1b |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 77 | |
| 78 | #define MII_M1111_HWCFG_MODE_MASK 0xf |
| 79 | #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb |
| 80 | #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3 |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 81 | #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4 |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 82 | #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9 |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 83 | #define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000 |
| 84 | #define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000 |
| 85 | |
| 86 | #define MII_M1111_COPPER 0 |
| 87 | #define MII_M1111_FIBER 1 |
| 88 | |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 89 | #define MII_88E1121_PHY_MSCR_PAGE 2 |
| 90 | #define MII_88E1121_PHY_MSCR_REG 21 |
| 91 | #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5) |
| 92 | #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4) |
| 93 | #define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4)) |
| 94 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 95 | #define MII_88E1121_MISC_TEST 0x1a |
| 96 | #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00 |
| 97 | #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8 |
| 98 | #define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7) |
| 99 | #define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6) |
| 100 | #define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5) |
| 101 | #define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f |
| 102 | |
| 103 | #define MII_88E1510_TEMP_SENSOR 0x1b |
| 104 | #define MII_88E1510_TEMP_SENSOR_MASK 0xff |
| 105 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 106 | #define MII_88E1318S_PHY_MSCR1_REG 16 |
| 107 | #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 108 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 109 | /* Copper Specific Interrupt Enable Register */ |
| 110 | #define MII_88E1318S_PHY_CSIER 0x12 |
| 111 | /* WOL Event Interrupt Enable */ |
| 112 | #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) |
| 113 | |
| 114 | /* LED Timer Control Register */ |
| 115 | #define MII_88E1318S_PHY_LED_PAGE 0x03 |
| 116 | #define MII_88E1318S_PHY_LED_TCR 0x12 |
| 117 | #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15) |
| 118 | #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7) |
| 119 | #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11) |
| 120 | |
| 121 | /* Magic Packet MAC address registers */ |
| 122 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17 |
| 123 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18 |
| 124 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19 |
| 125 | |
| 126 | #define MII_88E1318S_PHY_WOL_PAGE 0x11 |
| 127 | #define MII_88E1318S_PHY_WOL_CTRL 0x10 |
| 128 | #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12) |
| 129 | #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14) |
| 130 | |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 131 | #define MII_88E1121_PHY_LED_CTRL 16 |
| 132 | #define MII_88E1121_PHY_LED_PAGE 3 |
| 133 | #define MII_88E1121_PHY_LED_DEF 0x0030 |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 134 | |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 135 | #define MII_M1011_PHY_STATUS 0x11 |
| 136 | #define MII_M1011_PHY_STATUS_1000 0x8000 |
| 137 | #define MII_M1011_PHY_STATUS_100 0x4000 |
| 138 | #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000 |
| 139 | #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000 |
| 140 | #define MII_M1011_PHY_STATUS_RESOLVED 0x0800 |
| 141 | #define MII_M1011_PHY_STATUS_LINK 0x0400 |
| 142 | |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 143 | #define MII_M1116R_CONTROL_REG_MAC 21 |
| 144 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 145 | #define MII_88E3016_PHY_SPEC_CTRL 0x10 |
| 146 | #define MII_88E3016_DISABLE_SCRAMBLER 0x0200 |
| 147 | #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 148 | |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 149 | #define MII_88E1510_GEN_CTRL_REG_1 0x14 |
| 150 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7 |
| 151 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */ |
| 152 | #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */ |
| 153 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 154 | #define LPA_FIBER_1000HALF 0x40 |
| 155 | #define LPA_FIBER_1000FULL 0x20 |
| 156 | |
| 157 | #define LPA_PAUSE_FIBER 0x180 |
| 158 | #define LPA_PAUSE_ASYM_FIBER 0x100 |
| 159 | |
| 160 | #define ADVERTISE_FIBER_1000HALF 0x40 |
| 161 | #define ADVERTISE_FIBER_1000FULL 0x20 |
| 162 | |
| 163 | #define ADVERTISE_PAUSE_FIBER 0x180 |
| 164 | #define ADVERTISE_PAUSE_ASYM_FIBER 0x100 |
| 165 | |
| 166 | #define REGISTER_LINK_STATUS 0x400 |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 167 | #define NB_FIBER_STATS 1 |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 168 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 169 | MODULE_DESCRIPTION("Marvell PHY driver"); |
| 170 | MODULE_AUTHOR("Andy Fleming"); |
| 171 | MODULE_LICENSE("GPL"); |
| 172 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 173 | struct marvell_hw_stat { |
| 174 | const char *string; |
| 175 | u8 page; |
| 176 | u8 reg; |
| 177 | u8 bits; |
| 178 | }; |
| 179 | |
| 180 | static struct marvell_hw_stat marvell_hw_stats[] = { |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 181 | { "phy_receive_errors_copper", 0, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 182 | { "phy_idle_errors", 0, 10, 8 }, |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 183 | { "phy_receive_errors_fiber", 1, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | struct marvell_priv { |
| 187 | u64 stats[ARRAY_SIZE(marvell_hw_stats)]; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 188 | char *hwmon_name; |
| 189 | struct device *hwmon_dev; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 192 | static int marvell_ack_interrupt(struct phy_device *phydev) |
| 193 | { |
| 194 | int err; |
| 195 | |
| 196 | /* Clear the interrupts by reading the reg */ |
| 197 | err = phy_read(phydev, MII_M1011_IEVENT); |
| 198 | |
| 199 | if (err < 0) |
| 200 | return err; |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int marvell_config_intr(struct phy_device *phydev) |
| 206 | { |
| 207 | int err; |
| 208 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 209 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 210 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); |
| 211 | else |
| 212 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); |
| 213 | |
| 214 | return err; |
| 215 | } |
| 216 | |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 217 | static int marvell_set_polarity(struct phy_device *phydev, int polarity) |
| 218 | { |
| 219 | int reg; |
| 220 | int err; |
| 221 | int val; |
| 222 | |
| 223 | /* get the current settings */ |
| 224 | reg = phy_read(phydev, MII_M1011_PHY_SCR); |
| 225 | if (reg < 0) |
| 226 | return reg; |
| 227 | |
| 228 | val = reg; |
| 229 | val &= ~MII_M1011_PHY_SCR_AUTO_CROSS; |
| 230 | switch (polarity) { |
| 231 | case ETH_TP_MDI: |
| 232 | val |= MII_M1011_PHY_SCR_MDI; |
| 233 | break; |
| 234 | case ETH_TP_MDI_X: |
| 235 | val |= MII_M1011_PHY_SCR_MDI_X; |
| 236 | break; |
| 237 | case ETH_TP_MDI_AUTO: |
| 238 | case ETH_TP_MDI_INVALID: |
| 239 | default: |
| 240 | val |= MII_M1011_PHY_SCR_AUTO_CROSS; |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | if (val != reg) { |
| 245 | /* Set the new polarity value in the register */ |
| 246 | err = phy_write(phydev, MII_M1011_PHY_SCR, val); |
| 247 | if (err) |
| 248 | return err; |
| 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 254 | static int marvell_config_aneg(struct phy_device *phydev) |
| 255 | { |
| 256 | int err; |
| 257 | |
| 258 | /* The Marvell PHY has an errata which requires |
| 259 | * that certain registers get written in order |
| 260 | * to restart autonegotiation */ |
| 261 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 262 | |
| 263 | if (err < 0) |
| 264 | return err; |
| 265 | |
| 266 | err = phy_write(phydev, 0x1d, 0x1f); |
| 267 | if (err < 0) |
| 268 | return err; |
| 269 | |
| 270 | err = phy_write(phydev, 0x1e, 0x200c); |
| 271 | if (err < 0) |
| 272 | return err; |
| 273 | |
| 274 | err = phy_write(phydev, 0x1d, 0x5); |
| 275 | if (err < 0) |
| 276 | return err; |
| 277 | |
| 278 | err = phy_write(phydev, 0x1e, 0); |
| 279 | if (err < 0) |
| 280 | return err; |
| 281 | |
| 282 | err = phy_write(phydev, 0x1e, 0x100); |
| 283 | if (err < 0) |
| 284 | return err; |
| 285 | |
Raju Lakkaraju | 4e26c5c | 2016-11-29 15:16:49 +0530 | [diff] [blame] | 286 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 287 | if (err < 0) |
| 288 | return err; |
| 289 | |
| 290 | err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, |
| 291 | MII_M1111_PHY_LED_DIRECT); |
| 292 | if (err < 0) |
| 293 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 294 | |
| 295 | err = genphy_config_aneg(phydev); |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 296 | if (err < 0) |
| 297 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 298 | |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 299 | if (phydev->autoneg != AUTONEG_ENABLE) { |
| 300 | int bmcr; |
| 301 | |
| 302 | /* |
| 303 | * A write to speed/duplex bits (that is performed by |
| 304 | * genphy_config_aneg() call above) must be followed by |
| 305 | * a software reset. Otherwise, the write has no effect. |
| 306 | */ |
| 307 | bmcr = phy_read(phydev, MII_BMCR); |
| 308 | if (bmcr < 0) |
| 309 | return bmcr; |
| 310 | |
| 311 | err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET); |
| 312 | if (err < 0) |
| 313 | return err; |
| 314 | } |
| 315 | |
| 316 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Harini Katakam | 3ec0a0f | 2016-06-27 13:09:59 +0530 | [diff] [blame] | 319 | static int m88e1111_config_aneg(struct phy_device *phydev) |
| 320 | { |
| 321 | int err; |
| 322 | |
| 323 | /* The Marvell PHY has an errata which requires |
| 324 | * that certain registers get written in order |
| 325 | * to restart autonegotiation |
| 326 | */ |
| 327 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 328 | |
Raju Lakkaraju | 4e26c5c | 2016-11-29 15:16:49 +0530 | [diff] [blame] | 329 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
Harini Katakam | 3ec0a0f | 2016-06-27 13:09:59 +0530 | [diff] [blame] | 330 | if (err < 0) |
| 331 | return err; |
| 332 | |
| 333 | err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, |
| 334 | MII_M1111_PHY_LED_DIRECT); |
| 335 | if (err < 0) |
| 336 | return err; |
| 337 | |
| 338 | err = genphy_config_aneg(phydev); |
| 339 | if (err < 0) |
| 340 | return err; |
| 341 | |
| 342 | if (phydev->autoneg != AUTONEG_ENABLE) { |
| 343 | int bmcr; |
| 344 | |
| 345 | /* A write to speed/duplex bits (that is performed by |
| 346 | * genphy_config_aneg() call above) must be followed by |
| 347 | * a software reset. Otherwise, the write has no effect. |
| 348 | */ |
| 349 | bmcr = phy_read(phydev, MII_BMCR); |
| 350 | if (bmcr < 0) |
| 351 | return bmcr; |
| 352 | |
| 353 | err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET); |
| 354 | if (err < 0) |
| 355 | return err; |
| 356 | } |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 361 | #ifdef CONFIG_OF_MDIO |
| 362 | /* |
| 363 | * Set and/or override some configuration registers based on the |
| 364 | * marvell,reg-init property stored in the of_node for the phydev. |
| 365 | * |
| 366 | * marvell,reg-init = <reg-page reg mask value>,...; |
| 367 | * |
| 368 | * There may be one or more sets of <reg-page reg mask value>: |
| 369 | * |
| 370 | * reg-page: which register bank to use. |
| 371 | * reg: the register. |
| 372 | * mask: if non-zero, ANDed with existing register value. |
| 373 | * value: ORed with the masked value and written to the regiser. |
| 374 | * |
| 375 | */ |
| 376 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 377 | { |
| 378 | const __be32 *paddr; |
Uwe Kleine-König | b5718b5 | 2016-11-10 15:03:01 +0100 | [diff] [blame] | 379 | int len, i, saved_page, current_page, ret; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 380 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 381 | if (!phydev->mdio.dev.of_node) |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 382 | return 0; |
| 383 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 384 | paddr = of_get_property(phydev->mdio.dev.of_node, |
| 385 | "marvell,reg-init", &len); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 386 | if (!paddr || len < (4 * sizeof(*paddr))) |
| 387 | return 0; |
| 388 | |
| 389 | saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 390 | if (saved_page < 0) |
| 391 | return saved_page; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 392 | current_page = saved_page; |
| 393 | |
| 394 | ret = 0; |
| 395 | len /= sizeof(*paddr); |
| 396 | for (i = 0; i < len - 3; i += 4) { |
| 397 | u16 reg_page = be32_to_cpup(paddr + i); |
| 398 | u16 reg = be32_to_cpup(paddr + i + 1); |
| 399 | u16 mask = be32_to_cpup(paddr + i + 2); |
| 400 | u16 val_bits = be32_to_cpup(paddr + i + 3); |
| 401 | int val; |
| 402 | |
| 403 | if (reg_page != current_page) { |
| 404 | current_page = reg_page; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 405 | ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page); |
| 406 | if (ret < 0) |
| 407 | goto err; |
| 408 | } |
| 409 | |
| 410 | val = 0; |
| 411 | if (mask) { |
| 412 | val = phy_read(phydev, reg); |
| 413 | if (val < 0) { |
| 414 | ret = val; |
| 415 | goto err; |
| 416 | } |
| 417 | val &= mask; |
| 418 | } |
| 419 | val |= val_bits; |
| 420 | |
| 421 | ret = phy_write(phydev, reg, val); |
| 422 | if (ret < 0) |
| 423 | goto err; |
| 424 | |
| 425 | } |
| 426 | err: |
Uwe Kleine-König | b5718b5 | 2016-11-10 15:03:01 +0100 | [diff] [blame] | 427 | if (current_page != saved_page) { |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 428 | i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page); |
| 429 | if (ret == 0) |
| 430 | ret = i; |
| 431 | } |
| 432 | return ret; |
| 433 | } |
| 434 | #else |
| 435 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 436 | { |
| 437 | return 0; |
| 438 | } |
| 439 | #endif /* CONFIG_OF_MDIO */ |
| 440 | |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 441 | static int m88e1121_config_aneg(struct phy_device *phydev) |
| 442 | { |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 443 | int err, oldpage, mscr; |
| 444 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 445 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 446 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 447 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 448 | MII_88E1121_PHY_MSCR_PAGE); |
| 449 | if (err < 0) |
| 450 | return err; |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 451 | |
Florian Fainelli | 32a6416 | 2015-05-26 12:19:59 -0700 | [diff] [blame] | 452 | if (phy_interface_is_rgmii(phydev)) { |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 453 | |
Arnaud Patard | be8c648 | 2010-10-21 03:59:57 -0700 | [diff] [blame] | 454 | mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) & |
| 455 | MII_88E1121_PHY_MSCR_DELAY_MASK; |
| 456 | |
| 457 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 458 | mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY | |
| 459 | MII_88E1121_PHY_MSCR_TX_DELAY); |
| 460 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 461 | mscr |= MII_88E1121_PHY_MSCR_RX_DELAY; |
| 462 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 463 | mscr |= MII_88E1121_PHY_MSCR_TX_DELAY; |
| 464 | |
| 465 | err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr); |
| 466 | if (err < 0) |
| 467 | return err; |
| 468 | } |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 469 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 470 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 471 | |
| 472 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 473 | if (err < 0) |
| 474 | return err; |
| 475 | |
| 476 | err = phy_write(phydev, MII_M1011_PHY_SCR, |
| 477 | MII_M1011_PHY_SCR_AUTO_CROSS); |
| 478 | if (err < 0) |
| 479 | return err; |
| 480 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 481 | return genphy_config_aneg(phydev); |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 484 | static int m88e1318_config_aneg(struct phy_device *phydev) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 485 | { |
| 486 | int err, oldpage, mscr; |
| 487 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 488 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 489 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 490 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 491 | MII_88E1121_PHY_MSCR_PAGE); |
| 492 | if (err < 0) |
| 493 | return err; |
| 494 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 495 | mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG); |
| 496 | mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD; |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 497 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 498 | err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 499 | if (err < 0) |
| 500 | return err; |
| 501 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 502 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 503 | if (err < 0) |
| 504 | return err; |
| 505 | |
| 506 | return m88e1121_config_aneg(phydev); |
| 507 | } |
| 508 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 509 | /** |
| 510 | * ethtool_adv_to_fiber_adv_t |
| 511 | * @ethadv: the ethtool advertisement settings |
| 512 | * |
| 513 | * A small helper function that translates ethtool advertisement |
| 514 | * settings to phy autonegotiation advertisements for the |
| 515 | * MII_ADV register for fiber link. |
| 516 | */ |
| 517 | static inline u32 ethtool_adv_to_fiber_adv_t(u32 ethadv) |
| 518 | { |
| 519 | u32 result = 0; |
| 520 | |
| 521 | if (ethadv & ADVERTISED_1000baseT_Half) |
| 522 | result |= ADVERTISE_FIBER_1000HALF; |
| 523 | if (ethadv & ADVERTISED_1000baseT_Full) |
| 524 | result |= ADVERTISE_FIBER_1000FULL; |
| 525 | |
| 526 | if ((ethadv & ADVERTISE_PAUSE_ASYM) && (ethadv & ADVERTISE_PAUSE_CAP)) |
| 527 | result |= LPA_PAUSE_ASYM_FIBER; |
| 528 | else if (ethadv & ADVERTISE_PAUSE_CAP) |
| 529 | result |= (ADVERTISE_PAUSE_FIBER |
| 530 | & (~ADVERTISE_PAUSE_ASYM_FIBER)); |
| 531 | |
| 532 | return result; |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR |
| 537 | * @phydev: target phy_device struct |
| 538 | * |
| 539 | * Description: If auto-negotiation is enabled, we configure the |
| 540 | * advertising, and then restart auto-negotiation. If it is not |
| 541 | * enabled, then we write the BMCR. Adapted for fiber link in |
| 542 | * some Marvell's devices. |
| 543 | */ |
| 544 | static int marvell_config_aneg_fiber(struct phy_device *phydev) |
| 545 | { |
| 546 | int changed = 0; |
| 547 | int err; |
| 548 | int adv, oldadv; |
| 549 | u32 advertise; |
| 550 | |
| 551 | if (phydev->autoneg != AUTONEG_ENABLE) |
| 552 | return genphy_setup_forced(phydev); |
| 553 | |
| 554 | /* Only allow advertising what this PHY supports */ |
| 555 | phydev->advertising &= phydev->supported; |
| 556 | advertise = phydev->advertising; |
| 557 | |
| 558 | /* Setup fiber advertisement */ |
| 559 | adv = phy_read(phydev, MII_ADVERTISE); |
| 560 | if (adv < 0) |
| 561 | return adv; |
| 562 | |
| 563 | oldadv = adv; |
| 564 | adv &= ~(ADVERTISE_FIBER_1000HALF | ADVERTISE_FIBER_1000FULL |
| 565 | | LPA_PAUSE_FIBER); |
| 566 | adv |= ethtool_adv_to_fiber_adv_t(advertise); |
| 567 | |
| 568 | if (adv != oldadv) { |
| 569 | err = phy_write(phydev, MII_ADVERTISE, adv); |
| 570 | if (err < 0) |
| 571 | return err; |
| 572 | |
| 573 | changed = 1; |
| 574 | } |
| 575 | |
| 576 | if (changed == 0) { |
| 577 | /* Advertisement hasn't changed, but maybe aneg was never on to |
| 578 | * begin with? Or maybe phy was isolated? |
| 579 | */ |
| 580 | int ctl = phy_read(phydev, MII_BMCR); |
| 581 | |
| 582 | if (ctl < 0) |
| 583 | return ctl; |
| 584 | |
| 585 | if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) |
| 586 | changed = 1; /* do restart aneg */ |
| 587 | } |
| 588 | |
| 589 | /* Only restart aneg if we are advertising something different |
| 590 | * than we were before. |
| 591 | */ |
| 592 | if (changed > 0) |
| 593 | changed = genphy_restart_aneg(phydev); |
| 594 | |
| 595 | return changed; |
| 596 | } |
| 597 | |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 598 | static int m88e1510_config_aneg(struct phy_device *phydev) |
| 599 | { |
| 600 | int err; |
| 601 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 602 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 603 | if (err < 0) |
| 604 | goto error; |
| 605 | |
| 606 | /* Configure the copper link first */ |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 607 | err = m88e1318_config_aneg(phydev); |
| 608 | if (err < 0) |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 609 | goto error; |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 610 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 611 | /* Then the fiber link */ |
| 612 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER); |
| 613 | if (err < 0) |
| 614 | goto error; |
| 615 | |
| 616 | err = marvell_config_aneg_fiber(phydev); |
| 617 | if (err < 0) |
| 618 | goto error; |
| 619 | |
| 620 | return phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 621 | |
| 622 | error: |
| 623 | phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 624 | return err; |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static int marvell_config_init(struct phy_device *phydev) |
| 628 | { |
| 629 | /* Set registers from marvell,reg-init DT property */ |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 630 | return marvell_of_reg_init(phydev); |
| 631 | } |
| 632 | |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 633 | static int m88e1116r_config_init(struct phy_device *phydev) |
| 634 | { |
| 635 | int temp; |
| 636 | int err; |
| 637 | |
| 638 | temp = phy_read(phydev, MII_BMCR); |
| 639 | temp |= BMCR_RESET; |
| 640 | err = phy_write(phydev, MII_BMCR, temp); |
| 641 | if (err < 0) |
| 642 | return err; |
| 643 | |
| 644 | mdelay(500); |
| 645 | |
| 646 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 647 | if (err < 0) |
| 648 | return err; |
| 649 | |
| 650 | temp = phy_read(phydev, MII_M1011_PHY_SCR); |
| 651 | temp |= (7 << 12); /* max number of gigabit attempts */ |
| 652 | temp |= (1 << 11); /* enable downshift */ |
| 653 | temp |= MII_M1011_PHY_SCR_AUTO_CROSS; |
| 654 | err = phy_write(phydev, MII_M1011_PHY_SCR, temp); |
| 655 | if (err < 0) |
| 656 | return err; |
| 657 | |
| 658 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2); |
| 659 | if (err < 0) |
| 660 | return err; |
| 661 | temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC); |
| 662 | temp |= (1 << 5); |
| 663 | temp |= (1 << 4); |
| 664 | err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp); |
| 665 | if (err < 0) |
| 666 | return err; |
| 667 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 668 | if (err < 0) |
| 669 | return err; |
| 670 | |
| 671 | temp = phy_read(phydev, MII_BMCR); |
| 672 | temp |= BMCR_RESET; |
| 673 | err = phy_write(phydev, MII_BMCR, temp); |
| 674 | if (err < 0) |
| 675 | return err; |
| 676 | |
| 677 | mdelay(500); |
| 678 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 679 | return marvell_config_init(phydev); |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 682 | static int m88e3016_config_init(struct phy_device *phydev) |
| 683 | { |
| 684 | int reg; |
| 685 | |
| 686 | /* Enable Scrambler and Auto-Crossover */ |
| 687 | reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL); |
| 688 | if (reg < 0) |
| 689 | return reg; |
| 690 | |
| 691 | reg &= ~MII_88E3016_DISABLE_SCRAMBLER; |
| 692 | reg |= MII_88E3016_AUTO_MDIX_CROSSOVER; |
| 693 | |
| 694 | reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg); |
| 695 | if (reg < 0) |
| 696 | return reg; |
| 697 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 698 | return marvell_config_init(phydev); |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 701 | static int m88e1111_config_init(struct phy_device *phydev) |
| 702 | { |
| 703 | int err; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 704 | int temp; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 705 | |
Florian Fainelli | 32a6416 | 2015-05-26 12:19:59 -0700 | [diff] [blame] | 706 | if (phy_interface_is_rgmii(phydev)) { |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 707 | |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 708 | temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); |
| 709 | if (temp < 0) |
| 710 | return temp; |
| 711 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 712 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 713 | temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 714 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { |
| 715 | temp &= ~MII_M1111_TX_DELAY; |
| 716 | temp |= MII_M1111_RX_DELAY; |
| 717 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { |
| 718 | temp &= ~MII_M1111_RX_DELAY; |
| 719 | temp |= MII_M1111_TX_DELAY; |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 720 | } |
| 721 | |
Kim Phillips | 9daf5a7 | 2007-11-26 16:17:52 -0600 | [diff] [blame] | 722 | err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); |
| 723 | if (err < 0) |
| 724 | return err; |
| 725 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 726 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 727 | if (temp < 0) |
| 728 | return temp; |
| 729 | |
| 730 | temp &= ~(MII_M1111_HWCFG_MODE_MASK); |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 731 | |
Wang Jian | 7239016d | 2008-07-16 21:46:20 +0800 | [diff] [blame] | 732 | if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 733 | temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII; |
| 734 | else |
| 735 | temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII; |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 736 | |
| 737 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 738 | if (err < 0) |
| 739 | return err; |
| 740 | } |
| 741 | |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 742 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 743 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 744 | if (temp < 0) |
| 745 | return temp; |
| 746 | |
| 747 | temp &= ~(MII_M1111_HWCFG_MODE_MASK); |
| 748 | temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK; |
Haiying Wang | 32d0c1e | 2009-06-02 04:04:13 +0000 | [diff] [blame] | 749 | temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 750 | |
| 751 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 752 | if (err < 0) |
| 753 | return err; |
Madalin Bucur | 07151bc | 2015-08-07 17:07:50 +0800 | [diff] [blame] | 754 | |
| 755 | /* make sure copper is selected */ |
| 756 | err = phy_read(phydev, MII_M1145_PHY_EXT_ADDR_PAGE); |
| 757 | if (err < 0) |
| 758 | return err; |
| 759 | |
| 760 | err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, |
| 761 | err & (~0xff)); |
| 762 | if (err < 0) |
| 763 | return err; |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 764 | } |
| 765 | |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 766 | if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { |
| 767 | temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); |
| 768 | if (temp < 0) |
| 769 | return temp; |
| 770 | temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); |
| 771 | err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); |
| 772 | if (err < 0) |
| 773 | return err; |
| 774 | |
| 775 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 776 | if (temp < 0) |
| 777 | return temp; |
| 778 | temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES); |
| 779 | temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
| 780 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 781 | if (err < 0) |
| 782 | return err; |
| 783 | |
| 784 | /* soft reset */ |
| 785 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 786 | if (err < 0) |
| 787 | return err; |
| 788 | do |
| 789 | temp = phy_read(phydev, MII_BMCR); |
| 790 | while (temp & BMCR_RESET); |
| 791 | |
| 792 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 793 | if (temp < 0) |
| 794 | return temp; |
| 795 | temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES); |
| 796 | temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
| 797 | err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 798 | if (err < 0) |
| 799 | return err; |
| 800 | } |
| 801 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 802 | err = marvell_of_reg_init(phydev); |
| 803 | if (err < 0) |
| 804 | return err; |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 805 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 806 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 807 | } |
| 808 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 809 | static int m88e1121_config_init(struct phy_device *phydev) |
| 810 | { |
| 811 | int err, oldpage; |
| 812 | |
| 813 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 814 | |
| 815 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE); |
| 816 | if (err < 0) |
| 817 | return err; |
| 818 | |
| 819 | /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */ |
| 820 | err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL, |
| 821 | MII_88E1121_PHY_LED_DEF); |
| 822 | if (err < 0) |
| 823 | return err; |
| 824 | |
| 825 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 826 | |
| 827 | /* Set marvell,reg-init configuration from device tree */ |
| 828 | return marvell_config_init(phydev); |
| 829 | } |
| 830 | |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 831 | static int m88e1510_config_init(struct phy_device *phydev) |
| 832 | { |
| 833 | int err; |
| 834 | int temp; |
| 835 | |
| 836 | /* SGMII-to-Copper mode initialization */ |
| 837 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 838 | /* Select page 18 */ |
| 839 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 18); |
| 840 | if (err < 0) |
| 841 | return err; |
| 842 | |
| 843 | /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ |
| 844 | temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1); |
| 845 | temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK; |
| 846 | temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII; |
| 847 | err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp); |
| 848 | if (err < 0) |
| 849 | return err; |
| 850 | |
| 851 | /* PHY reset is necessary after changing MODE[2:0] */ |
| 852 | temp |= MII_88E1510_GEN_CTRL_REG_1_RESET; |
| 853 | err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp); |
| 854 | if (err < 0) |
| 855 | return err; |
| 856 | |
| 857 | /* Reset page selection */ |
| 858 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0); |
| 859 | if (err < 0) |
| 860 | return err; |
| 861 | } |
| 862 | |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 863 | return m88e1121_config_init(phydev); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 866 | static int m88e1118_config_aneg(struct phy_device *phydev) |
| 867 | { |
| 868 | int err; |
| 869 | |
| 870 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); |
| 871 | if (err < 0) |
| 872 | return err; |
| 873 | |
| 874 | err = phy_write(phydev, MII_M1011_PHY_SCR, |
| 875 | MII_M1011_PHY_SCR_AUTO_CROSS); |
| 876 | if (err < 0) |
| 877 | return err; |
| 878 | |
| 879 | err = genphy_config_aneg(phydev); |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static int m88e1118_config_init(struct phy_device *phydev) |
| 884 | { |
| 885 | int err; |
| 886 | |
| 887 | /* Change address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 888 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 889 | if (err < 0) |
| 890 | return err; |
| 891 | |
| 892 | /* Enable 1000 Mbit */ |
| 893 | err = phy_write(phydev, 0x15, 0x1070); |
| 894 | if (err < 0) |
| 895 | return err; |
| 896 | |
| 897 | /* Change address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 898 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 899 | if (err < 0) |
| 900 | return err; |
| 901 | |
| 902 | /* Adjust LED Control */ |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 903 | if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS) |
| 904 | err = phy_write(phydev, 0x10, 0x1100); |
| 905 | else |
| 906 | err = phy_write(phydev, 0x10, 0x021e); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 907 | if (err < 0) |
| 908 | return err; |
| 909 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 910 | err = marvell_of_reg_init(phydev); |
| 911 | if (err < 0) |
| 912 | return err; |
| 913 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 914 | /* Reset address */ |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 915 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 916 | if (err < 0) |
| 917 | return err; |
| 918 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 919 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 920 | } |
| 921 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 922 | static int m88e1149_config_init(struct phy_device *phydev) |
| 923 | { |
| 924 | int err; |
| 925 | |
| 926 | /* Change address */ |
| 927 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002); |
| 928 | if (err < 0) |
| 929 | return err; |
| 930 | |
| 931 | /* Enable 1000 Mbit */ |
| 932 | err = phy_write(phydev, 0x15, 0x1048); |
| 933 | if (err < 0) |
| 934 | return err; |
| 935 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 936 | err = marvell_of_reg_init(phydev); |
| 937 | if (err < 0) |
| 938 | return err; |
| 939 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 940 | /* Reset address */ |
| 941 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0); |
| 942 | if (err < 0) |
| 943 | return err; |
| 944 | |
Srinivas Kandagatla | cc90cb3 | 2012-04-02 06:25:24 +0000 | [diff] [blame] | 945 | return phy_write(phydev, MII_BMCR, BMCR_RESET); |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 948 | static int m88e1145_config_init(struct phy_device *phydev) |
| 949 | { |
| 950 | int err; |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 951 | int temp; |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 952 | |
| 953 | /* Take care of errata E0 & E1 */ |
| 954 | err = phy_write(phydev, 0x1d, 0x001b); |
| 955 | if (err < 0) |
| 956 | return err; |
| 957 | |
| 958 | err = phy_write(phydev, 0x1e, 0x418f); |
| 959 | if (err < 0) |
| 960 | return err; |
| 961 | |
| 962 | err = phy_write(phydev, 0x1d, 0x0016); |
| 963 | if (err < 0) |
| 964 | return err; |
| 965 | |
| 966 | err = phy_write(phydev, 0x1e, 0xa2da); |
| 967 | if (err < 0) |
| 968 | return err; |
| 969 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 970 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 971 | int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR); |
| 972 | if (temp < 0) |
| 973 | return temp; |
| 974 | |
| 975 | temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY); |
| 976 | |
| 977 | err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp); |
| 978 | if (err < 0) |
| 979 | return err; |
| 980 | |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 981 | if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) { |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 982 | err = phy_write(phydev, 0x1d, 0x0012); |
| 983 | if (err < 0) |
| 984 | return err; |
| 985 | |
| 986 | temp = phy_read(phydev, 0x1e); |
| 987 | if (temp < 0) |
| 988 | return temp; |
| 989 | |
| 990 | temp &= 0xf03f; |
| 991 | temp |= 2 << 9; /* 36 ohm */ |
| 992 | temp |= 2 << 6; /* 39 ohm */ |
| 993 | |
| 994 | err = phy_write(phydev, 0x1e, temp); |
| 995 | if (err < 0) |
| 996 | return err; |
| 997 | |
| 998 | err = phy_write(phydev, 0x1d, 0x3); |
| 999 | if (err < 0) |
| 1000 | return err; |
| 1001 | |
| 1002 | err = phy_write(phydev, 0x1e, 0x8000); |
| 1003 | if (err < 0) |
| 1004 | return err; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 1008 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 1009 | temp = phy_read(phydev, MII_M1145_PHY_EXT_SR); |
| 1010 | if (temp < 0) |
| 1011 | return temp; |
| 1012 | |
Vince Bridgers | 99d881f | 2014-10-26 14:22:24 -0500 | [diff] [blame] | 1013 | temp &= ~MII_M1145_HWCFG_MODE_MASK; |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 1014 | temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK; |
| 1015 | temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO; |
| 1016 | |
| 1017 | err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp); |
| 1018 | if (err < 0) |
| 1019 | return err; |
| 1020 | } |
| 1021 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 1022 | err = marvell_of_reg_init(phydev); |
| 1023 | if (err < 0) |
| 1024 | return err; |
| 1025 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1028 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1029 | /** |
| 1030 | * fiber_lpa_to_ethtool_lpa_t |
| 1031 | * @lpa: value of the MII_LPA register for fiber link |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1032 | * |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1033 | * A small helper function that translates MII_LPA |
| 1034 | * bits to ethtool LP advertisement settings. |
| 1035 | */ |
| 1036 | static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa) |
| 1037 | { |
| 1038 | u32 result = 0; |
| 1039 | |
| 1040 | if (lpa & LPA_FIBER_1000HALF) |
| 1041 | result |= ADVERTISED_1000baseT_Half; |
| 1042 | if (lpa & LPA_FIBER_1000FULL) |
| 1043 | result |= ADVERTISED_1000baseT_Full; |
| 1044 | |
| 1045 | return result; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * marvell_update_link - update link status in real time in @phydev |
| 1050 | * @phydev: target phy_device struct |
| 1051 | * |
| 1052 | * Description: Update the value in phydev->link to reflect the |
| 1053 | * current link value. |
| 1054 | */ |
| 1055 | static int marvell_update_link(struct phy_device *phydev, int fiber) |
| 1056 | { |
| 1057 | int status; |
| 1058 | |
| 1059 | /* Use the generic register for copper link, or specific |
| 1060 | * register for fiber case */ |
| 1061 | if (fiber) { |
| 1062 | status = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 1063 | if (status < 0) |
| 1064 | return status; |
| 1065 | |
| 1066 | if ((status & REGISTER_LINK_STATUS) == 0) |
| 1067 | phydev->link = 0; |
| 1068 | else |
| 1069 | phydev->link = 1; |
| 1070 | } else { |
| 1071 | return genphy_update_link(phydev); |
| 1072 | } |
| 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
| 1077 | /* marvell_read_status_page |
| 1078 | * |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 1079 | * Description: |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1080 | * Check the link, then figure out the current state |
| 1081 | * by comparing what we advertise with what the link partner |
| 1082 | * advertises. Start by checking the gigabit possibilities, |
| 1083 | * then move on to 10/100. |
| 1084 | */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1085 | static int marvell_read_status_page(struct phy_device *phydev, int page) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1086 | { |
| 1087 | int adv; |
| 1088 | int err; |
| 1089 | int lpa; |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 1090 | int lpagb; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1091 | int status = 0; |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1092 | int fiber; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1093 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1094 | /* Detect and update the link, but return if there |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1095 | * was an error */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1096 | if (page == MII_M1111_FIBER) |
| 1097 | fiber = 1; |
| 1098 | else |
| 1099 | fiber = 0; |
| 1100 | |
| 1101 | err = marvell_update_link(phydev, fiber); |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1102 | if (err) |
| 1103 | return err; |
| 1104 | |
| 1105 | if (AUTONEG_ENABLE == phydev->autoneg) { |
| 1106 | status = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 1107 | if (status < 0) |
| 1108 | return status; |
| 1109 | |
| 1110 | lpa = phy_read(phydev, MII_LPA); |
| 1111 | if (lpa < 0) |
| 1112 | return lpa; |
| 1113 | |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 1114 | lpagb = phy_read(phydev, MII_STAT1000); |
| 1115 | if (lpagb < 0) |
| 1116 | return lpagb; |
| 1117 | |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1118 | adv = phy_read(phydev, MII_ADVERTISE); |
| 1119 | if (adv < 0) |
| 1120 | return adv; |
| 1121 | |
| 1122 | lpa &= adv; |
| 1123 | |
| 1124 | if (status & MII_M1011_PHY_STATUS_FULLDUPLEX) |
| 1125 | phydev->duplex = DUPLEX_FULL; |
| 1126 | else |
| 1127 | phydev->duplex = DUPLEX_HALF; |
| 1128 | |
| 1129 | status = status & MII_M1011_PHY_STATUS_SPD_MASK; |
| 1130 | phydev->pause = phydev->asym_pause = 0; |
| 1131 | |
| 1132 | switch (status) { |
| 1133 | case MII_M1011_PHY_STATUS_1000: |
| 1134 | phydev->speed = SPEED_1000; |
| 1135 | break; |
| 1136 | |
| 1137 | case MII_M1011_PHY_STATUS_100: |
| 1138 | phydev->speed = SPEED_100; |
| 1139 | break; |
| 1140 | |
| 1141 | default: |
| 1142 | phydev->speed = SPEED_10; |
| 1143 | break; |
| 1144 | } |
| 1145 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1146 | if (!fiber) { |
| 1147 | phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) | |
| 1148 | mii_lpa_to_ethtool_lpa_t(lpa); |
| 1149 | |
| 1150 | if (phydev->duplex == DUPLEX_FULL) { |
| 1151 | phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; |
| 1152 | phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; |
| 1153 | } |
| 1154 | } else { |
| 1155 | /* The fiber link is only 1000M capable */ |
| 1156 | phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa); |
| 1157 | |
| 1158 | if (phydev->duplex == DUPLEX_FULL) { |
| 1159 | if (!(lpa & LPA_PAUSE_FIBER)) { |
| 1160 | phydev->pause = 0; |
| 1161 | phydev->asym_pause = 0; |
| 1162 | } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) { |
| 1163 | phydev->pause = 1; |
| 1164 | phydev->asym_pause = 1; |
| 1165 | } else { |
| 1166 | phydev->pause = 1; |
| 1167 | phydev->asym_pause = 0; |
| 1168 | } |
| 1169 | } |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1170 | } |
| 1171 | } else { |
| 1172 | int bmcr = phy_read(phydev, MII_BMCR); |
| 1173 | |
| 1174 | if (bmcr < 0) |
| 1175 | return bmcr; |
| 1176 | |
| 1177 | if (bmcr & BMCR_FULLDPLX) |
| 1178 | phydev->duplex = DUPLEX_FULL; |
| 1179 | else |
| 1180 | phydev->duplex = DUPLEX_HALF; |
| 1181 | |
| 1182 | if (bmcr & BMCR_SPEED1000) |
| 1183 | phydev->speed = SPEED_1000; |
| 1184 | else if (bmcr & BMCR_SPEED100) |
| 1185 | phydev->speed = SPEED_100; |
| 1186 | else |
| 1187 | phydev->speed = SPEED_10; |
| 1188 | |
| 1189 | phydev->pause = phydev->asym_pause = 0; |
Russell King | 357cd64 | 2015-09-24 00:07:17 +0100 | [diff] [blame] | 1190 | phydev->lp_advertising = 0; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1196 | /* marvell_read_status |
| 1197 | * |
| 1198 | * Some Marvell's phys have two modes: fiber and copper. |
| 1199 | * Both need status checked. |
| 1200 | * Description: |
| 1201 | * First, check the fiber link and status. |
| 1202 | * If the fiber link is down, check the copper link and status which |
| 1203 | * will be the default value if both link are down. |
| 1204 | */ |
| 1205 | static int marvell_read_status(struct phy_device *phydev) |
| 1206 | { |
| 1207 | int err; |
| 1208 | |
| 1209 | /* Check the fiber mode first */ |
Russell King | a13c0652 | 2017-01-10 23:13:45 +0000 | [diff] [blame] | 1210 | if (phydev->supported & SUPPORTED_FIBRE && |
| 1211 | phydev->interface != PHY_INTERFACE_MODE_SGMII) { |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1212 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER); |
| 1213 | if (err < 0) |
| 1214 | goto error; |
| 1215 | |
| 1216 | err = marvell_read_status_page(phydev, MII_M1111_FIBER); |
| 1217 | if (err < 0) |
| 1218 | goto error; |
| 1219 | |
| 1220 | /* If the fiber link is up, it is the selected and used link. |
| 1221 | * In this case, we need to stay in the fiber page. |
| 1222 | * Please to be careful about that, avoid to restore Copper page |
| 1223 | * in other functions which could break the behaviour |
| 1224 | * for some fiber phy like 88E1512. |
| 1225 | * */ |
| 1226 | if (phydev->link) |
| 1227 | return 0; |
| 1228 | |
| 1229 | /* If fiber link is down, check and save copper mode state */ |
| 1230 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1231 | if (err < 0) |
| 1232 | goto error; |
| 1233 | } |
| 1234 | |
| 1235 | return marvell_read_status_page(phydev, MII_M1111_COPPER); |
| 1236 | |
| 1237 | error: |
| 1238 | phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1239 | return err; |
| 1240 | } |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1241 | |
| 1242 | /* marvell_suspend |
| 1243 | * |
| 1244 | * Some Marvell's phys have two modes: fiber and copper. |
| 1245 | * Both need to be suspended |
| 1246 | */ |
| 1247 | static int marvell_suspend(struct phy_device *phydev) |
| 1248 | { |
| 1249 | int err; |
| 1250 | |
| 1251 | /* Suspend the fiber mode first */ |
| 1252 | if (!(phydev->supported & SUPPORTED_FIBRE)) { |
| 1253 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER); |
| 1254 | if (err < 0) |
| 1255 | goto error; |
| 1256 | |
| 1257 | /* With the page set, use the generic suspend */ |
| 1258 | err = genphy_suspend(phydev); |
| 1259 | if (err < 0) |
| 1260 | goto error; |
| 1261 | |
| 1262 | /* Then, the copper link */ |
| 1263 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1264 | if (err < 0) |
| 1265 | goto error; |
| 1266 | } |
| 1267 | |
| 1268 | /* With the page set, use the generic suspend */ |
| 1269 | return genphy_suspend(phydev); |
| 1270 | |
| 1271 | error: |
| 1272 | phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1273 | return err; |
| 1274 | } |
| 1275 | |
| 1276 | /* marvell_resume |
| 1277 | * |
| 1278 | * Some Marvell's phys have two modes: fiber and copper. |
| 1279 | * Both need to be resumed |
| 1280 | */ |
| 1281 | static int marvell_resume(struct phy_device *phydev) |
| 1282 | { |
| 1283 | int err; |
| 1284 | |
| 1285 | /* Resume the fiber mode first */ |
| 1286 | if (!(phydev->supported & SUPPORTED_FIBRE)) { |
| 1287 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER); |
| 1288 | if (err < 0) |
| 1289 | goto error; |
| 1290 | |
| 1291 | /* With the page set, use the generic resume */ |
| 1292 | err = genphy_resume(phydev); |
| 1293 | if (err < 0) |
| 1294 | goto error; |
| 1295 | |
| 1296 | /* Then, the copper link */ |
| 1297 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1298 | if (err < 0) |
| 1299 | goto error; |
| 1300 | } |
| 1301 | |
| 1302 | /* With the page set, use the generic resume */ |
| 1303 | return genphy_resume(phydev); |
| 1304 | |
| 1305 | error: |
| 1306 | phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER); |
| 1307 | return err; |
| 1308 | } |
| 1309 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1310 | static int marvell_aneg_done(struct phy_device *phydev) |
| 1311 | { |
| 1312 | int retval = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 1313 | return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED); |
| 1314 | } |
| 1315 | |
Anatolij Gustschin | dcd07be | 2009-04-07 02:01:43 +0000 | [diff] [blame] | 1316 | static int m88e1121_did_interrupt(struct phy_device *phydev) |
| 1317 | { |
| 1318 | int imask; |
| 1319 | |
| 1320 | imask = phy_read(phydev, MII_M1011_IEVENT); |
| 1321 | |
| 1322 | if (imask & MII_M1011_IMASK_INIT) |
| 1323 | return 1; |
| 1324 | |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1328 | static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1329 | { |
| 1330 | wol->supported = WAKE_MAGIC; |
| 1331 | wol->wolopts = 0; |
| 1332 | |
| 1333 | if (phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1334 | MII_88E1318S_PHY_WOL_PAGE) < 0) |
| 1335 | return; |
| 1336 | |
| 1337 | if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) & |
| 1338 | MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE) |
| 1339 | wol->wolopts |= WAKE_MAGIC; |
| 1340 | |
| 1341 | if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0) |
| 1342 | return; |
| 1343 | } |
| 1344 | |
| 1345 | static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1346 | { |
| 1347 | int err, oldpage, temp; |
| 1348 | |
| 1349 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 1350 | |
| 1351 | if (wol->wolopts & WAKE_MAGIC) { |
| 1352 | /* Explicitly switch to page 0x00, just to be sure */ |
| 1353 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00); |
| 1354 | if (err < 0) |
| 1355 | return err; |
| 1356 | |
| 1357 | /* Enable the WOL interrupt */ |
| 1358 | temp = phy_read(phydev, MII_88E1318S_PHY_CSIER); |
| 1359 | temp |= MII_88E1318S_PHY_CSIER_WOL_EIE; |
| 1360 | err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp); |
| 1361 | if (err < 0) |
| 1362 | return err; |
| 1363 | |
| 1364 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1365 | MII_88E1318S_PHY_LED_PAGE); |
| 1366 | if (err < 0) |
| 1367 | return err; |
| 1368 | |
| 1369 | /* Setup LED[2] as interrupt pin (active low) */ |
| 1370 | temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR); |
| 1371 | temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT; |
| 1372 | temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE; |
| 1373 | temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW; |
| 1374 | err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp); |
| 1375 | if (err < 0) |
| 1376 | return err; |
| 1377 | |
| 1378 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1379 | MII_88E1318S_PHY_WOL_PAGE); |
| 1380 | if (err < 0) |
| 1381 | return err; |
| 1382 | |
| 1383 | /* Store the device address for the magic packet */ |
| 1384 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2, |
| 1385 | ((phydev->attached_dev->dev_addr[5] << 8) | |
| 1386 | phydev->attached_dev->dev_addr[4])); |
| 1387 | if (err < 0) |
| 1388 | return err; |
| 1389 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1, |
| 1390 | ((phydev->attached_dev->dev_addr[3] << 8) | |
| 1391 | phydev->attached_dev->dev_addr[2])); |
| 1392 | if (err < 0) |
| 1393 | return err; |
| 1394 | err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0, |
| 1395 | ((phydev->attached_dev->dev_addr[1] << 8) | |
| 1396 | phydev->attached_dev->dev_addr[0])); |
| 1397 | if (err < 0) |
| 1398 | return err; |
| 1399 | |
| 1400 | /* Clear WOL status and enable magic packet matching */ |
| 1401 | temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL); |
| 1402 | temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS; |
| 1403 | temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE; |
| 1404 | err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp); |
| 1405 | if (err < 0) |
| 1406 | return err; |
| 1407 | } else { |
| 1408 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1409 | MII_88E1318S_PHY_WOL_PAGE); |
| 1410 | if (err < 0) |
| 1411 | return err; |
| 1412 | |
| 1413 | /* Clear WOL status and disable magic packet matching */ |
| 1414 | temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL); |
| 1415 | temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS; |
| 1416 | temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE; |
| 1417 | err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp); |
| 1418 | if (err < 0) |
| 1419 | return err; |
| 1420 | } |
| 1421 | |
| 1422 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 1423 | if (err < 0) |
| 1424 | return err; |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1429 | static int marvell_get_sset_count(struct phy_device *phydev) |
| 1430 | { |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 1431 | if (phydev->supported & SUPPORTED_FIBRE) |
| 1432 | return ARRAY_SIZE(marvell_hw_stats); |
| 1433 | else |
| 1434 | return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static void marvell_get_strings(struct phy_device *phydev, u8 *data) |
| 1438 | { |
| 1439 | int i; |
| 1440 | |
| 1441 | for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) { |
| 1442 | memcpy(data + i * ETH_GSTRING_LEN, |
| 1443 | marvell_hw_stats[i].string, ETH_GSTRING_LEN); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | #ifndef UINT64_MAX |
| 1448 | #define UINT64_MAX (u64)(~((u64)0)) |
| 1449 | #endif |
| 1450 | static u64 marvell_get_stat(struct phy_device *phydev, int i) |
| 1451 | { |
| 1452 | struct marvell_hw_stat stat = marvell_hw_stats[i]; |
| 1453 | struct marvell_priv *priv = phydev->priv; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1454 | int err, oldpage, val; |
| 1455 | u64 ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1456 | |
| 1457 | oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 1458 | err = phy_write(phydev, MII_MARVELL_PHY_PAGE, |
| 1459 | stat.page); |
| 1460 | if (err < 0) |
| 1461 | return UINT64_MAX; |
| 1462 | |
| 1463 | val = phy_read(phydev, stat.reg); |
| 1464 | if (val < 0) { |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1465 | ret = UINT64_MAX; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1466 | } else { |
| 1467 | val = val & ((1 << stat.bits) - 1); |
| 1468 | priv->stats[i] += val; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1469 | ret = priv->stats[i]; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage); |
| 1473 | |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1474 | return ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | static void marvell_get_stats(struct phy_device *phydev, |
| 1478 | struct ethtool_stats *stats, u64 *data) |
| 1479 | { |
| 1480 | int i; |
| 1481 | |
| 1482 | for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) |
| 1483 | data[i] = marvell_get_stat(phydev, i); |
| 1484 | } |
| 1485 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 1486 | #ifdef CONFIG_HWMON |
| 1487 | static int m88e1121_get_temp(struct phy_device *phydev, long *temp) |
| 1488 | { |
| 1489 | int ret; |
| 1490 | int val; |
| 1491 | |
| 1492 | *temp = 0; |
| 1493 | |
| 1494 | mutex_lock(&phydev->lock); |
| 1495 | |
| 1496 | ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6); |
| 1497 | if (ret < 0) |
| 1498 | goto error; |
| 1499 | |
| 1500 | /* Enable temperature sensor */ |
| 1501 | ret = phy_read(phydev, MII_88E1121_MISC_TEST); |
| 1502 | if (ret < 0) |
| 1503 | goto error; |
| 1504 | |
| 1505 | ret = phy_write(phydev, MII_88E1121_MISC_TEST, |
| 1506 | ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); |
| 1507 | if (ret < 0) |
| 1508 | goto error; |
| 1509 | |
| 1510 | /* Wait for temperature to stabilize */ |
| 1511 | usleep_range(10000, 12000); |
| 1512 | |
| 1513 | val = phy_read(phydev, MII_88E1121_MISC_TEST); |
| 1514 | if (val < 0) { |
| 1515 | ret = val; |
| 1516 | goto error; |
| 1517 | } |
| 1518 | |
| 1519 | /* Disable temperature sensor */ |
| 1520 | ret = phy_write(phydev, MII_88E1121_MISC_TEST, |
| 1521 | ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); |
| 1522 | if (ret < 0) |
| 1523 | goto error; |
| 1524 | |
| 1525 | *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000; |
| 1526 | |
| 1527 | error: |
| 1528 | phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0); |
| 1529 | mutex_unlock(&phydev->lock); |
| 1530 | |
| 1531 | return ret; |
| 1532 | } |
| 1533 | |
| 1534 | static int m88e1121_hwmon_read(struct device *dev, |
| 1535 | enum hwmon_sensor_types type, |
| 1536 | u32 attr, int channel, long *temp) |
| 1537 | { |
| 1538 | struct phy_device *phydev = dev_get_drvdata(dev); |
| 1539 | int err; |
| 1540 | |
| 1541 | switch (attr) { |
| 1542 | case hwmon_temp_input: |
| 1543 | err = m88e1121_get_temp(phydev, temp); |
| 1544 | break; |
| 1545 | default: |
| 1546 | return -EOPNOTSUPP; |
| 1547 | } |
| 1548 | |
| 1549 | return err; |
| 1550 | } |
| 1551 | |
| 1552 | static umode_t m88e1121_hwmon_is_visible(const void *data, |
| 1553 | enum hwmon_sensor_types type, |
| 1554 | u32 attr, int channel) |
| 1555 | { |
| 1556 | if (type != hwmon_temp) |
| 1557 | return 0; |
| 1558 | |
| 1559 | switch (attr) { |
| 1560 | case hwmon_temp_input: |
| 1561 | return 0444; |
| 1562 | default: |
| 1563 | return 0; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | static u32 m88e1121_hwmon_chip_config[] = { |
| 1568 | HWMON_C_REGISTER_TZ, |
| 1569 | 0 |
| 1570 | }; |
| 1571 | |
| 1572 | static const struct hwmon_channel_info m88e1121_hwmon_chip = { |
| 1573 | .type = hwmon_chip, |
| 1574 | .config = m88e1121_hwmon_chip_config, |
| 1575 | }; |
| 1576 | |
| 1577 | static u32 m88e1121_hwmon_temp_config[] = { |
| 1578 | HWMON_T_INPUT, |
| 1579 | 0 |
| 1580 | }; |
| 1581 | |
| 1582 | static const struct hwmon_channel_info m88e1121_hwmon_temp = { |
| 1583 | .type = hwmon_temp, |
| 1584 | .config = m88e1121_hwmon_temp_config, |
| 1585 | }; |
| 1586 | |
| 1587 | static const struct hwmon_channel_info *m88e1121_hwmon_info[] = { |
| 1588 | &m88e1121_hwmon_chip, |
| 1589 | &m88e1121_hwmon_temp, |
| 1590 | NULL |
| 1591 | }; |
| 1592 | |
| 1593 | static const struct hwmon_ops m88e1121_hwmon_hwmon_ops = { |
| 1594 | .is_visible = m88e1121_hwmon_is_visible, |
| 1595 | .read = m88e1121_hwmon_read, |
| 1596 | }; |
| 1597 | |
| 1598 | static const struct hwmon_chip_info m88e1121_hwmon_chip_info = { |
| 1599 | .ops = &m88e1121_hwmon_hwmon_ops, |
| 1600 | .info = m88e1121_hwmon_info, |
| 1601 | }; |
| 1602 | |
| 1603 | static int m88e1510_get_temp(struct phy_device *phydev, long *temp) |
| 1604 | { |
| 1605 | int ret; |
| 1606 | |
| 1607 | *temp = 0; |
| 1608 | |
| 1609 | mutex_lock(&phydev->lock); |
| 1610 | |
| 1611 | ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6); |
| 1612 | if (ret < 0) |
| 1613 | goto error; |
| 1614 | |
| 1615 | ret = phy_read(phydev, MII_88E1510_TEMP_SENSOR); |
| 1616 | if (ret < 0) |
| 1617 | goto error; |
| 1618 | |
| 1619 | *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000; |
| 1620 | |
| 1621 | error: |
| 1622 | phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0); |
| 1623 | mutex_unlock(&phydev->lock); |
| 1624 | |
| 1625 | return ret; |
| 1626 | } |
| 1627 | |
| 1628 | int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp) |
| 1629 | { |
| 1630 | int ret; |
| 1631 | |
| 1632 | *temp = 0; |
| 1633 | |
| 1634 | mutex_lock(&phydev->lock); |
| 1635 | |
| 1636 | ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6); |
| 1637 | if (ret < 0) |
| 1638 | goto error; |
| 1639 | |
| 1640 | ret = phy_read(phydev, MII_88E1121_MISC_TEST); |
| 1641 | if (ret < 0) |
| 1642 | goto error; |
| 1643 | |
| 1644 | *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >> |
| 1645 | MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25; |
| 1646 | /* convert to mC */ |
| 1647 | *temp *= 1000; |
| 1648 | |
| 1649 | error: |
| 1650 | phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0); |
| 1651 | mutex_unlock(&phydev->lock); |
| 1652 | |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
| 1656 | int m88e1510_set_temp_critical(struct phy_device *phydev, long temp) |
| 1657 | { |
| 1658 | int ret; |
| 1659 | |
| 1660 | mutex_lock(&phydev->lock); |
| 1661 | |
| 1662 | ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6); |
| 1663 | if (ret < 0) |
| 1664 | goto error; |
| 1665 | |
| 1666 | ret = phy_read(phydev, MII_88E1121_MISC_TEST); |
| 1667 | if (ret < 0) |
| 1668 | goto error; |
| 1669 | |
| 1670 | temp = temp / 1000; |
| 1671 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
| 1672 | ret = phy_write(phydev, MII_88E1121_MISC_TEST, |
| 1673 | (ret & ~MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) | |
| 1674 | (temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT)); |
| 1675 | |
| 1676 | error: |
| 1677 | phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0); |
| 1678 | mutex_unlock(&phydev->lock); |
| 1679 | |
| 1680 | return ret; |
| 1681 | } |
| 1682 | |
| 1683 | int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm) |
| 1684 | { |
| 1685 | int ret; |
| 1686 | |
| 1687 | *alarm = false; |
| 1688 | |
| 1689 | mutex_lock(&phydev->lock); |
| 1690 | |
| 1691 | ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6); |
| 1692 | if (ret < 0) |
| 1693 | goto error; |
| 1694 | |
| 1695 | ret = phy_read(phydev, MII_88E1121_MISC_TEST); |
| 1696 | if (ret < 0) |
| 1697 | goto error; |
| 1698 | *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ); |
| 1699 | |
| 1700 | error: |
| 1701 | phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0); |
| 1702 | mutex_unlock(&phydev->lock); |
| 1703 | |
| 1704 | return ret; |
| 1705 | } |
| 1706 | |
| 1707 | static int m88e1510_hwmon_read(struct device *dev, |
| 1708 | enum hwmon_sensor_types type, |
| 1709 | u32 attr, int channel, long *temp) |
| 1710 | { |
| 1711 | struct phy_device *phydev = dev_get_drvdata(dev); |
| 1712 | int err; |
| 1713 | |
| 1714 | switch (attr) { |
| 1715 | case hwmon_temp_input: |
| 1716 | err = m88e1510_get_temp(phydev, temp); |
| 1717 | break; |
| 1718 | case hwmon_temp_crit: |
| 1719 | err = m88e1510_get_temp_critical(phydev, temp); |
| 1720 | break; |
| 1721 | case hwmon_temp_max_alarm: |
| 1722 | err = m88e1510_get_temp_alarm(phydev, temp); |
| 1723 | break; |
| 1724 | default: |
| 1725 | return -EOPNOTSUPP; |
| 1726 | } |
| 1727 | |
| 1728 | return err; |
| 1729 | } |
| 1730 | |
| 1731 | static int m88e1510_hwmon_write(struct device *dev, |
| 1732 | enum hwmon_sensor_types type, |
| 1733 | u32 attr, int channel, long temp) |
| 1734 | { |
| 1735 | struct phy_device *phydev = dev_get_drvdata(dev); |
| 1736 | int err; |
| 1737 | |
| 1738 | switch (attr) { |
| 1739 | case hwmon_temp_crit: |
| 1740 | err = m88e1510_set_temp_critical(phydev, temp); |
| 1741 | break; |
| 1742 | default: |
| 1743 | return -EOPNOTSUPP; |
| 1744 | } |
| 1745 | return err; |
| 1746 | } |
| 1747 | |
| 1748 | static umode_t m88e1510_hwmon_is_visible(const void *data, |
| 1749 | enum hwmon_sensor_types type, |
| 1750 | u32 attr, int channel) |
| 1751 | { |
| 1752 | if (type != hwmon_temp) |
| 1753 | return 0; |
| 1754 | |
| 1755 | switch (attr) { |
| 1756 | case hwmon_temp_input: |
| 1757 | case hwmon_temp_max_alarm: |
| 1758 | return 0444; |
| 1759 | case hwmon_temp_crit: |
| 1760 | return 0644; |
| 1761 | default: |
| 1762 | return 0; |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | static u32 m88e1510_hwmon_temp_config[] = { |
| 1767 | HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM, |
| 1768 | 0 |
| 1769 | }; |
| 1770 | |
| 1771 | static const struct hwmon_channel_info m88e1510_hwmon_temp = { |
| 1772 | .type = hwmon_temp, |
| 1773 | .config = m88e1510_hwmon_temp_config, |
| 1774 | }; |
| 1775 | |
| 1776 | static const struct hwmon_channel_info *m88e1510_hwmon_info[] = { |
| 1777 | &m88e1121_hwmon_chip, |
| 1778 | &m88e1510_hwmon_temp, |
| 1779 | NULL |
| 1780 | }; |
| 1781 | |
| 1782 | static const struct hwmon_ops m88e1510_hwmon_hwmon_ops = { |
| 1783 | .is_visible = m88e1510_hwmon_is_visible, |
| 1784 | .read = m88e1510_hwmon_read, |
| 1785 | .write = m88e1510_hwmon_write, |
| 1786 | }; |
| 1787 | |
| 1788 | static const struct hwmon_chip_info m88e1510_hwmon_chip_info = { |
| 1789 | .ops = &m88e1510_hwmon_hwmon_ops, |
| 1790 | .info = m88e1510_hwmon_info, |
| 1791 | }; |
| 1792 | |
| 1793 | static int marvell_hwmon_name(struct phy_device *phydev) |
| 1794 | { |
| 1795 | struct marvell_priv *priv = phydev->priv; |
| 1796 | struct device *dev = &phydev->mdio.dev; |
| 1797 | const char *devname = dev_name(dev); |
| 1798 | size_t len = strlen(devname); |
| 1799 | int i, j; |
| 1800 | |
| 1801 | priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL); |
| 1802 | if (!priv->hwmon_name) |
| 1803 | return -ENOMEM; |
| 1804 | |
| 1805 | for (i = j = 0; i < len && devname[i]; i++) { |
| 1806 | if (isalnum(devname[i])) |
| 1807 | priv->hwmon_name[j++] = devname[i]; |
| 1808 | } |
| 1809 | |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
| 1813 | static int marvell_hwmon_probe(struct phy_device *phydev, |
| 1814 | const struct hwmon_chip_info *chip) |
| 1815 | { |
| 1816 | struct marvell_priv *priv = phydev->priv; |
| 1817 | struct device *dev = &phydev->mdio.dev; |
| 1818 | int err; |
| 1819 | |
| 1820 | err = marvell_hwmon_name(phydev); |
| 1821 | if (err) |
| 1822 | return err; |
| 1823 | |
| 1824 | priv->hwmon_dev = devm_hwmon_device_register_with_info( |
| 1825 | dev, priv->hwmon_name, phydev, chip, NULL); |
| 1826 | |
| 1827 | return PTR_ERR_OR_ZERO(priv->hwmon_dev); |
| 1828 | } |
| 1829 | |
| 1830 | static int m88e1121_hwmon_probe(struct phy_device *phydev) |
| 1831 | { |
| 1832 | return marvell_hwmon_probe(phydev, &m88e1121_hwmon_chip_info); |
| 1833 | } |
| 1834 | |
| 1835 | static int m88e1510_hwmon_probe(struct phy_device *phydev) |
| 1836 | { |
| 1837 | return marvell_hwmon_probe(phydev, &m88e1510_hwmon_chip_info); |
| 1838 | } |
| 1839 | #else |
| 1840 | static int m88e1121_hwmon_probe(struct phy_device *phydev) |
| 1841 | { |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | static int m88e1510_hwmon_probe(struct phy_device *phydev) |
| 1846 | { |
| 1847 | return 0; |
| 1848 | } |
| 1849 | #endif |
| 1850 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1851 | static int marvell_probe(struct phy_device *phydev) |
| 1852 | { |
| 1853 | struct marvell_priv *priv; |
| 1854 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 1855 | priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1856 | if (!priv) |
| 1857 | return -ENOMEM; |
| 1858 | |
| 1859 | phydev->priv = priv; |
| 1860 | |
| 1861 | return 0; |
| 1862 | } |
| 1863 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 1864 | static int m88e1121_probe(struct phy_device *phydev) |
| 1865 | { |
| 1866 | int err; |
| 1867 | |
| 1868 | err = marvell_probe(phydev); |
| 1869 | if (err) |
| 1870 | return err; |
| 1871 | |
| 1872 | return m88e1121_hwmon_probe(phydev); |
| 1873 | } |
| 1874 | |
| 1875 | static int m88e1510_probe(struct phy_device *phydev) |
| 1876 | { |
| 1877 | int err; |
| 1878 | |
| 1879 | err = marvell_probe(phydev); |
| 1880 | if (err) |
| 1881 | return err; |
| 1882 | |
| 1883 | return m88e1510_hwmon_probe(phydev); |
| 1884 | } |
| 1885 | |
| 1886 | static void marvell_remove(struct phy_device *phydev) |
| 1887 | { |
| 1888 | #ifdef CONFIG_HWMON |
| 1889 | |
| 1890 | struct marvell_priv *priv = phydev->priv; |
| 1891 | |
| 1892 | if (priv && priv->hwmon_dev) |
| 1893 | hwmon_device_unregister(priv->hwmon_dev); |
| 1894 | #endif |
| 1895 | } |
| 1896 | |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1897 | static struct phy_driver marvell_drivers[] = { |
| 1898 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1899 | .phy_id = MARVELL_PHY_ID_88E1101, |
| 1900 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1901 | .name = "Marvell 88E1101", |
| 1902 | .features = PHY_GBIT_FEATURES, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1903 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1904 | .flags = PHY_HAS_INTERRUPT, |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 1905 | .config_init = &marvell_config_init, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1906 | .config_aneg = &marvell_config_aneg, |
| 1907 | .read_status = &genphy_read_status, |
| 1908 | .ack_interrupt = &marvell_ack_interrupt, |
| 1909 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1910 | .resume = &genphy_resume, |
| 1911 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1912 | .get_sset_count = marvell_get_sset_count, |
| 1913 | .get_strings = marvell_get_strings, |
| 1914 | .get_stats = marvell_get_stats, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1915 | }, |
| 1916 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1917 | .phy_id = MARVELL_PHY_ID_88E1112, |
| 1918 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1919 | .name = "Marvell 88E1112", |
| 1920 | .features = PHY_GBIT_FEATURES, |
| 1921 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1922 | .probe = marvell_probe, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1923 | .config_init = &m88e1111_config_init, |
| 1924 | .config_aneg = &marvell_config_aneg, |
| 1925 | .read_status = &genphy_read_status, |
| 1926 | .ack_interrupt = &marvell_ack_interrupt, |
| 1927 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1928 | .resume = &genphy_resume, |
| 1929 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1930 | .get_sset_count = marvell_get_sset_count, |
| 1931 | .get_strings = marvell_get_strings, |
| 1932 | .get_stats = marvell_get_stats, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 1933 | }, |
| 1934 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1935 | .phy_id = MARVELL_PHY_ID_88E1111, |
| 1936 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1937 | .name = "Marvell 88E1111", |
| 1938 | .features = PHY_GBIT_FEATURES, |
| 1939 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1940 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1941 | .config_init = &m88e1111_config_init, |
Harini Katakam | 3ec0a0f | 2016-06-27 13:09:59 +0530 | [diff] [blame] | 1942 | .config_aneg = &m88e1111_config_aneg, |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1943 | .read_status = &marvell_read_status, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1944 | .ack_interrupt = &marvell_ack_interrupt, |
| 1945 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1946 | .resume = &genphy_resume, |
| 1947 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1948 | .get_sset_count = marvell_get_sset_count, |
| 1949 | .get_strings = marvell_get_strings, |
| 1950 | .get_stats = marvell_get_stats, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 1951 | }, |
| 1952 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1953 | .phy_id = MARVELL_PHY_ID_88E1118, |
| 1954 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1955 | .name = "Marvell 88E1118", |
| 1956 | .features = PHY_GBIT_FEATURES, |
| 1957 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1958 | .probe = marvell_probe, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1959 | .config_init = &m88e1118_config_init, |
| 1960 | .config_aneg = &m88e1118_config_aneg, |
| 1961 | .read_status = &genphy_read_status, |
| 1962 | .ack_interrupt = &marvell_ack_interrupt, |
| 1963 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1964 | .resume = &genphy_resume, |
| 1965 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1966 | .get_sset_count = marvell_get_sset_count, |
| 1967 | .get_strings = marvell_get_strings, |
| 1968 | .get_stats = marvell_get_stats, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1969 | }, |
| 1970 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1971 | .phy_id = MARVELL_PHY_ID_88E1121R, |
| 1972 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1973 | .name = "Marvell 88E1121R", |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 1974 | .probe = &m88e1121_probe, |
| 1975 | .remove = &marvell_remove, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1976 | .features = PHY_GBIT_FEATURES, |
| 1977 | .flags = PHY_HAS_INTERRUPT, |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 1978 | .config_init = &m88e1121_config_init, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1979 | .config_aneg = &m88e1121_config_aneg, |
| 1980 | .read_status = &marvell_read_status, |
| 1981 | .ack_interrupt = &marvell_ack_interrupt, |
| 1982 | .config_intr = &marvell_config_intr, |
Anatolij Gustschin | dcd07be | 2009-04-07 02:01:43 +0000 | [diff] [blame] | 1983 | .did_interrupt = &m88e1121_did_interrupt, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 1984 | .resume = &genphy_resume, |
| 1985 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1986 | .get_sset_count = marvell_get_sset_count, |
| 1987 | .get_strings = marvell_get_strings, |
| 1988 | .get_stats = marvell_get_stats, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 1989 | }, |
| 1990 | { |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1991 | .phy_id = MARVELL_PHY_ID_88E1318S, |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 1992 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1993 | .name = "Marvell 88E1318S", |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 1994 | .features = PHY_GBIT_FEATURES, |
| 1995 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1996 | .probe = marvell_probe, |
Clemens Gruber | fdecf36 | 2016-06-11 17:21:26 +0200 | [diff] [blame] | 1997 | .config_init = &m88e1121_config_init, |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 1998 | .config_aneg = &m88e1318_config_aneg, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 1999 | .read_status = &marvell_read_status, |
| 2000 | .ack_interrupt = &marvell_ack_interrupt, |
| 2001 | .config_intr = &marvell_config_intr, |
| 2002 | .did_interrupt = &m88e1121_did_interrupt, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 2003 | .get_wol = &m88e1318_get_wol, |
| 2004 | .set_wol = &m88e1318_set_wol, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 2005 | .resume = &genphy_resume, |
| 2006 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2007 | .get_sset_count = marvell_get_sset_count, |
| 2008 | .get_strings = marvell_get_strings, |
| 2009 | .get_stats = marvell_get_stats, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 2010 | }, |
| 2011 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2012 | .phy_id = MARVELL_PHY_ID_88E1145, |
| 2013 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2014 | .name = "Marvell 88E1145", |
| 2015 | .features = PHY_GBIT_FEATURES, |
| 2016 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2017 | .probe = marvell_probe, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2018 | .config_init = &m88e1145_config_init, |
| 2019 | .config_aneg = &marvell_config_aneg, |
| 2020 | .read_status = &genphy_read_status, |
| 2021 | .ack_interrupt = &marvell_ack_interrupt, |
| 2022 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 2023 | .resume = &genphy_resume, |
| 2024 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2025 | .get_sset_count = marvell_get_sset_count, |
| 2026 | .get_strings = marvell_get_strings, |
| 2027 | .get_stats = marvell_get_stats, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 2028 | }, |
| 2029 | { |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 2030 | .phy_id = MARVELL_PHY_ID_88E1149R, |
| 2031 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2032 | .name = "Marvell 88E1149R", |
| 2033 | .features = PHY_GBIT_FEATURES, |
| 2034 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2035 | .probe = marvell_probe, |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 2036 | .config_init = &m88e1149_config_init, |
| 2037 | .config_aneg = &m88e1118_config_aneg, |
| 2038 | .read_status = &genphy_read_status, |
| 2039 | .ack_interrupt = &marvell_ack_interrupt, |
| 2040 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 2041 | .resume = &genphy_resume, |
| 2042 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2043 | .get_sset_count = marvell_get_sset_count, |
| 2044 | .get_strings = marvell_get_strings, |
| 2045 | .get_stats = marvell_get_stats, |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 2046 | }, |
| 2047 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2048 | .phy_id = MARVELL_PHY_ID_88E1240, |
| 2049 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 2050 | .name = "Marvell 88E1240", |
| 2051 | .features = PHY_GBIT_FEATURES, |
| 2052 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2053 | .probe = marvell_probe, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 2054 | .config_init = &m88e1111_config_init, |
| 2055 | .config_aneg = &marvell_config_aneg, |
| 2056 | .read_status = &genphy_read_status, |
| 2057 | .ack_interrupt = &marvell_ack_interrupt, |
| 2058 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 2059 | .resume = &genphy_resume, |
| 2060 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2061 | .get_sset_count = marvell_get_sset_count, |
| 2062 | .get_strings = marvell_get_strings, |
| 2063 | .get_stats = marvell_get_stats, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 2064 | }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 2065 | { |
| 2066 | .phy_id = MARVELL_PHY_ID_88E1116R, |
| 2067 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2068 | .name = "Marvell 88E1116R", |
| 2069 | .features = PHY_GBIT_FEATURES, |
| 2070 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2071 | .probe = marvell_probe, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 2072 | .config_init = &m88e1116r_config_init, |
| 2073 | .config_aneg = &genphy_config_aneg, |
| 2074 | .read_status = &genphy_read_status, |
| 2075 | .ack_interrupt = &marvell_ack_interrupt, |
| 2076 | .config_intr = &marvell_config_intr, |
Sebastian Hesselbarth | 0898b44 | 2013-12-13 10:20:26 +0100 | [diff] [blame] | 2077 | .resume = &genphy_resume, |
| 2078 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2079 | .get_sset_count = marvell_get_sset_count, |
| 2080 | .get_strings = marvell_get_strings, |
| 2081 | .get_stats = marvell_get_stats, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 2082 | }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 2083 | { |
| 2084 | .phy_id = MARVELL_PHY_ID_88E1510, |
| 2085 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2086 | .name = "Marvell 88E1510", |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 2087 | .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE, |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 2088 | .probe = &m88e1510_probe, |
| 2089 | .remove = &marvell_remove, |
| 2090 | .features = PHY_GBIT_FEATURES, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 2091 | .flags = PHY_HAS_INTERRUPT, |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 2092 | .config_init = &m88e1510_config_init, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 2093 | .config_aneg = &m88e1510_config_aneg, |
| 2094 | .read_status = &marvell_read_status, |
| 2095 | .ack_interrupt = &marvell_ack_interrupt, |
| 2096 | .config_intr = &marvell_config_intr, |
| 2097 | .did_interrupt = &m88e1121_did_interrupt, |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 2098 | .resume = &marvell_resume, |
| 2099 | .suspend = &marvell_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2100 | .get_sset_count = marvell_get_sset_count, |
| 2101 | .get_strings = marvell_get_strings, |
| 2102 | .get_stats = marvell_get_stats, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 2103 | }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 2104 | { |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 2105 | .phy_id = MARVELL_PHY_ID_88E1540, |
| 2106 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2107 | .name = "Marvell 88E1540", |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame^] | 2108 | .probe = m88e1510_probe, |
| 2109 | .remove = &marvell_remove, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 2110 | .features = PHY_GBIT_FEATURES, |
| 2111 | .flags = PHY_HAS_INTERRUPT, |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 2112 | .config_init = &marvell_config_init, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 2113 | .config_aneg = &m88e1510_config_aneg, |
| 2114 | .read_status = &marvell_read_status, |
| 2115 | .ack_interrupt = &marvell_ack_interrupt, |
| 2116 | .config_intr = &marvell_config_intr, |
| 2117 | .did_interrupt = &m88e1121_did_interrupt, |
| 2118 | .resume = &genphy_resume, |
| 2119 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2120 | .get_sset_count = marvell_get_sset_count, |
| 2121 | .get_strings = marvell_get_strings, |
| 2122 | .get_stats = marvell_get_stats, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 2123 | }, |
| 2124 | { |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 2125 | .phy_id = MARVELL_PHY_ID_88E3016, |
| 2126 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2127 | .name = "Marvell 88E3016", |
| 2128 | .features = PHY_BASIC_FEATURES, |
| 2129 | .flags = PHY_HAS_INTERRUPT, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2130 | .probe = marvell_probe, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 2131 | .config_aneg = &genphy_config_aneg, |
| 2132 | .config_init = &m88e3016_config_init, |
| 2133 | .aneg_done = &marvell_aneg_done, |
| 2134 | .read_status = &marvell_read_status, |
| 2135 | .ack_interrupt = &marvell_ack_interrupt, |
| 2136 | .config_intr = &marvell_config_intr, |
| 2137 | .did_interrupt = &m88e1121_did_interrupt, |
| 2138 | .resume = &genphy_resume, |
| 2139 | .suspend = &genphy_suspend, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2140 | .get_sset_count = marvell_get_sset_count, |
| 2141 | .get_strings = marvell_get_strings, |
| 2142 | .get_stats = marvell_get_stats, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 2143 | }, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 2144 | }; |
| 2145 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 2146 | module_phy_driver(marvell_drivers); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 2147 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 2148 | static struct mdio_device_id __maybe_unused marvell_tbl[] = { |
Michal Simek | f5e1cab | 2013-05-30 20:08:25 +0000 | [diff] [blame] | 2149 | { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK }, |
| 2150 | { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK }, |
| 2151 | { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK }, |
| 2152 | { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK }, |
| 2153 | { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK }, |
| 2154 | { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK }, |
| 2155 | { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK }, |
| 2156 | { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK }, |
| 2157 | { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 2158 | { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 2159 | { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK }, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 2160 | { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 2161 | { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK }, |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 2162 | { } |
| 2163 | }; |
| 2164 | |
| 2165 | MODULE_DEVICE_TABLE(mdio, marvell_tbl); |