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