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