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