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> |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 30 | #include <linux/ethtool_netlink.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 31 | #include <linux/phy.h> |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 32 | #include <linux/marvell_phy.h> |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 33 | #include <linux/bitfield.h> |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 34 | #include <linux/of.h> |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 35 | #include <linux/sfp.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 36 | |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 37 | #include <linux/io.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 38 | #include <asm/irq.h> |
Avinash Kumar | eea3b20 | 2013-09-30 09:36:44 +0530 | [diff] [blame] | 39 | #include <linux/uaccess.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 40 | |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 41 | #define MII_MARVELL_PHY_PAGE 22 |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 42 | #define MII_MARVELL_COPPER_PAGE 0x00 |
| 43 | #define MII_MARVELL_FIBER_PAGE 0x01 |
| 44 | #define MII_MARVELL_MSCR_PAGE 0x02 |
| 45 | #define MII_MARVELL_LED_PAGE 0x03 |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 46 | #define MII_MARVELL_VCT5_PAGE 0x05 |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 47 | #define MII_MARVELL_MISC_TEST_PAGE 0x06 |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 48 | #define MII_MARVELL_VCT7_PAGE 0x07 |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 49 | #define MII_MARVELL_WOL_PAGE 0x11 |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 50 | #define MII_MARVELL_MODE_PAGE 0x12 |
David Daney | 27d916d | 2010-11-19 11:58:52 +0000 | [diff] [blame] | 51 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 52 | #define MII_M1011_IEVENT 0x13 |
| 53 | #define MII_M1011_IEVENT_CLEAR 0x0000 |
| 54 | |
| 55 | #define MII_M1011_IMASK 0x12 |
| 56 | #define MII_M1011_IMASK_INIT 0x6400 |
| 57 | #define MII_M1011_IMASK_CLEAR 0x0000 |
| 58 | |
Andrew Lunn | fecd5e9 | 2017-07-30 22:41:49 +0200 | [diff] [blame] | 59 | #define MII_M1011_PHY_SCR 0x10 |
| 60 | #define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11) |
Heiner Kallweit | f8d975b | 2019-10-28 20:52:22 +0100 | [diff] [blame] | 61 | #define MII_M1011_PHY_SCR_DOWNSHIFT_MASK GENMASK(14, 12) |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 62 | #define MII_M1011_PHY_SCR_DOWNSHIFT_MAX 8 |
Andrew Lunn | fecd5e9 | 2017-07-30 22:41:49 +0200 | [diff] [blame] | 63 | #define MII_M1011_PHY_SCR_MDI (0x0 << 5) |
| 64 | #define MII_M1011_PHY_SCR_MDI_X (0x1 << 5) |
| 65 | #define MII_M1011_PHY_SCR_AUTO_CROSS (0x3 << 5) |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 66 | |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 67 | #define MII_M1011_PHY_SSR 0x11 |
| 68 | #define MII_M1011_PHY_SSR_DOWNSHIFT BIT(5) |
| 69 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 70 | #define MII_M1111_PHY_LED_CONTROL 0x18 |
| 71 | #define MII_M1111_PHY_LED_DIRECT 0x4100 |
| 72 | #define MII_M1111_PHY_LED_COMBINE 0x411c |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 73 | #define MII_M1111_PHY_EXT_CR 0x14 |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 74 | #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK GENMASK(11, 9) |
| 75 | #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX 8 |
| 76 | #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN BIT(8) |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 77 | #define MII_M1111_RGMII_RX_DELAY BIT(7) |
| 78 | #define MII_M1111_RGMII_TX_DELAY BIT(1) |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 79 | #define MII_M1111_PHY_EXT_SR 0x1b |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 80 | |
| 81 | #define MII_M1111_HWCFG_MODE_MASK 0xf |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 82 | #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3 |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 83 | #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4 |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 84 | #define MII_M1111_HWCFG_MODE_RTBI 0x7 |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 85 | #define MII_M1111_HWCFG_MODE_COPPER_1000X_AN 0x8 |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 86 | #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9 |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 87 | #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 88 | #define MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN 0xc |
| 89 | #define MII_M1111_HWCFG_SERIAL_AN_BYPASS BIT(12) |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 90 | #define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13) |
| 91 | #define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 92 | |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 93 | #define MII_88E1121_PHY_MSCR_REG 21 |
| 94 | #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5) |
| 95 | #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 96 | #define MII_88E1121_PHY_MSCR_DELAY_MASK (BIT(5) | BIT(4)) |
Cyril Chemparathy | c477d04 | 2010-08-02 09:44:53 +0000 | [diff] [blame] | 97 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 98 | #define MII_88E1121_MISC_TEST 0x1a |
| 99 | #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00 |
| 100 | #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8 |
| 101 | #define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7) |
| 102 | #define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6) |
| 103 | #define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5) |
| 104 | #define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f |
| 105 | |
| 106 | #define MII_88E1510_TEMP_SENSOR 0x1b |
| 107 | #define MII_88E1510_TEMP_SENSOR_MASK 0xff |
| 108 | |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 109 | #define MII_88E1540_COPPER_CTRL3 0x1a |
| 110 | #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK GENMASK(11, 10) |
| 111 | #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS 0 |
| 112 | #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS 1 |
| 113 | #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS 2 |
| 114 | #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS 3 |
| 115 | #define MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN BIT(9) |
| 116 | |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 117 | #define MII_88E6390_MISC_TEST 0x1b |
Marek Behún | 4f920c29 | 2021-04-20 09:54:00 +0200 | [diff] [blame] | 118 | #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S (0x0 << 14) |
| 119 | #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE (0x1 << 14) |
| 120 | #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_ONESHOT (0x2 << 14) |
| 121 | #define MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE (0x3 << 14) |
| 122 | #define MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK (0x3 << 14) |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 123 | #define MII_88E6393_MISC_TEST_SAMPLES_2048 (0x0 << 11) |
| 124 | #define MII_88E6393_MISC_TEST_SAMPLES_4096 (0x1 << 11) |
| 125 | #define MII_88E6393_MISC_TEST_SAMPLES_8192 (0x2 << 11) |
| 126 | #define MII_88E6393_MISC_TEST_SAMPLES_16384 (0x3 << 11) |
| 127 | #define MII_88E6393_MISC_TEST_SAMPLES_MASK (0x3 << 11) |
| 128 | #define MII_88E6393_MISC_TEST_RATE_2_3MS (0x5 << 8) |
| 129 | #define MII_88E6393_MISC_TEST_RATE_6_4MS (0x6 << 8) |
| 130 | #define MII_88E6393_MISC_TEST_RATE_11_9MS (0x7 << 8) |
| 131 | #define MII_88E6393_MISC_TEST_RATE_MASK (0x7 << 8) |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 132 | |
| 133 | #define MII_88E6390_TEMP_SENSOR 0x1c |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 134 | #define MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK 0xff00 |
| 135 | #define MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT 8 |
| 136 | #define MII_88E6390_TEMP_SENSOR_MASK 0xff |
| 137 | #define MII_88E6390_TEMP_SENSOR_SAMPLES 10 |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 138 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 139 | #define MII_88E1318S_PHY_MSCR1_REG 16 |
| 140 | #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 141 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 142 | /* Copper Specific Interrupt Enable Register */ |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 143 | #define MII_88E1318S_PHY_CSIER 0x12 |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 144 | /* WOL Event Interrupt Enable */ |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 145 | #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 146 | |
| 147 | /* LED Timer Control Register */ |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 148 | #define MII_88E1318S_PHY_LED_TCR 0x12 |
| 149 | #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15) |
| 150 | #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7) |
| 151 | #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 152 | |
| 153 | /* Magic Packet MAC address registers */ |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 154 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17 |
| 155 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18 |
| 156 | #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19 |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 157 | |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 158 | #define MII_88E1318S_PHY_WOL_CTRL 0x10 |
| 159 | #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12) |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 160 | #define MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE BIT(13) |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 161 | #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 162 | |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 163 | #define MII_PHY_LED_CTRL 16 |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 164 | #define MII_88E1121_PHY_LED_DEF 0x0030 |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 165 | #define MII_88E1510_PHY_LED_DEF 0x1177 |
Jian Shen | a93f7fe | 2019-04-22 21:52:23 +0800 | [diff] [blame] | 166 | #define MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE 0x1040 |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 167 | |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 168 | #define MII_M1011_PHY_STATUS 0x11 |
| 169 | #define MII_M1011_PHY_STATUS_1000 0x8000 |
| 170 | #define MII_M1011_PHY_STATUS_100 0x4000 |
| 171 | #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000 |
| 172 | #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000 |
| 173 | #define MII_M1011_PHY_STATUS_RESOLVED 0x0800 |
| 174 | #define MII_M1011_PHY_STATUS_LINK 0x0400 |
| 175 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 176 | #define MII_88E3016_PHY_SPEC_CTRL 0x10 |
| 177 | #define MII_88E3016_DISABLE_SCRAMBLER 0x0200 |
| 178 | #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030 |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 179 | |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 180 | #define MII_88E1510_GEN_CTRL_REG_1 0x14 |
| 181 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7 |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 182 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII 0x0 /* RGMII to copper */ |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 183 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */ |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 184 | /* RGMII to 1000BASE-X */ |
| 185 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X 0x2 |
| 186 | /* RGMII to 100BASE-FX */ |
| 187 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX 0x3 |
| 188 | /* RGMII to SGMII */ |
| 189 | #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII 0x4 |
Stefan Roese | 930b37e | 2016-02-18 10:59:07 +0100 | [diff] [blame] | 190 | #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */ |
| 191 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 192 | #define MII_VCT5_TX_RX_MDI0_COUPLING 0x10 |
| 193 | #define MII_VCT5_TX_RX_MDI1_COUPLING 0x11 |
| 194 | #define MII_VCT5_TX_RX_MDI2_COUPLING 0x12 |
| 195 | #define MII_VCT5_TX_RX_MDI3_COUPLING 0x13 |
| 196 | #define MII_VCT5_TX_RX_AMPLITUDE_MASK 0x7f00 |
| 197 | #define MII_VCT5_TX_RX_AMPLITUDE_SHIFT 8 |
| 198 | #define MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION BIT(15) |
| 199 | |
| 200 | #define MII_VCT5_CTRL 0x17 |
| 201 | #define MII_VCT5_CTRL_ENABLE BIT(15) |
| 202 | #define MII_VCT5_CTRL_COMPLETE BIT(14) |
| 203 | #define MII_VCT5_CTRL_TX_SAME_CHANNEL (0x0 << 11) |
| 204 | #define MII_VCT5_CTRL_TX0_CHANNEL (0x4 << 11) |
| 205 | #define MII_VCT5_CTRL_TX1_CHANNEL (0x5 << 11) |
| 206 | #define MII_VCT5_CTRL_TX2_CHANNEL (0x6 << 11) |
| 207 | #define MII_VCT5_CTRL_TX3_CHANNEL (0x7 << 11) |
| 208 | #define MII_VCT5_CTRL_SAMPLES_2 (0x0 << 8) |
| 209 | #define MII_VCT5_CTRL_SAMPLES_4 (0x1 << 8) |
| 210 | #define MII_VCT5_CTRL_SAMPLES_8 (0x2 << 8) |
| 211 | #define MII_VCT5_CTRL_SAMPLES_16 (0x3 << 8) |
| 212 | #define MII_VCT5_CTRL_SAMPLES_32 (0x4 << 8) |
| 213 | #define MII_VCT5_CTRL_SAMPLES_64 (0x5 << 8) |
| 214 | #define MII_VCT5_CTRL_SAMPLES_128 (0x6 << 8) |
| 215 | #define MII_VCT5_CTRL_SAMPLES_DEFAULT (0x6 << 8) |
| 216 | #define MII_VCT5_CTRL_SAMPLES_256 (0x7 << 8) |
| 217 | #define MII_VCT5_CTRL_SAMPLES_SHIFT 8 |
| 218 | #define MII_VCT5_CTRL_MODE_MAXIMUM_PEEK (0x0 << 6) |
| 219 | #define MII_VCT5_CTRL_MODE_FIRST_LAST_PEEK (0x1 << 6) |
| 220 | #define MII_VCT5_CTRL_MODE_OFFSET (0x2 << 6) |
| 221 | #define MII_VCT5_CTRL_SAMPLE_POINT (0x3 << 6) |
| 222 | #define MII_VCT5_CTRL_PEEK_HYST_DEFAULT 3 |
| 223 | |
| 224 | #define MII_VCT5_SAMPLE_POINT_DISTANCE 0x18 |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 225 | #define MII_VCT5_SAMPLE_POINT_DISTANCE_MAX 511 |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 226 | #define MII_VCT5_TX_PULSE_CTRL 0x1c |
| 227 | #define MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN BIT(12) |
| 228 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS (0x0 << 10) |
| 229 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_96nS (0x1 << 10) |
| 230 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_64nS (0x2 << 10) |
| 231 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS (0x3 << 10) |
| 232 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_SHIFT 10 |
| 233 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_1000mV (0x0 << 8) |
| 234 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_750mV (0x1 << 8) |
| 235 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_500mV (0x2 << 8) |
| 236 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_250mV (0x3 << 8) |
| 237 | #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_SHIFT 8 |
| 238 | #define MII_VCT5_TX_PULSE_CTRL_MAX_AMP BIT(7) |
| 239 | #define MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV (0x6 << 0) |
| 240 | |
Andrew Lunn | db8668a | 2020-05-27 00:21:43 +0200 | [diff] [blame] | 241 | /* For TDR measurements less than 11 meters, a short pulse should be |
| 242 | * used. |
| 243 | */ |
| 244 | #define TDR_SHORT_CABLE_LENGTH 11 |
| 245 | |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 246 | #define MII_VCT7_PAIR_0_DISTANCE 0x10 |
| 247 | #define MII_VCT7_PAIR_1_DISTANCE 0x11 |
| 248 | #define MII_VCT7_PAIR_2_DISTANCE 0x12 |
| 249 | #define MII_VCT7_PAIR_3_DISTANCE 0x13 |
| 250 | |
| 251 | #define MII_VCT7_RESULTS 0x14 |
| 252 | #define MII_VCT7_RESULTS_PAIR3_MASK 0xf000 |
| 253 | #define MII_VCT7_RESULTS_PAIR2_MASK 0x0f00 |
| 254 | #define MII_VCT7_RESULTS_PAIR1_MASK 0x00f0 |
| 255 | #define MII_VCT7_RESULTS_PAIR0_MASK 0x000f |
| 256 | #define MII_VCT7_RESULTS_PAIR3_SHIFT 12 |
| 257 | #define MII_VCT7_RESULTS_PAIR2_SHIFT 8 |
| 258 | #define MII_VCT7_RESULTS_PAIR1_SHIFT 4 |
| 259 | #define MII_VCT7_RESULTS_PAIR0_SHIFT 0 |
| 260 | #define MII_VCT7_RESULTS_INVALID 0 |
| 261 | #define MII_VCT7_RESULTS_OK 1 |
| 262 | #define MII_VCT7_RESULTS_OPEN 2 |
| 263 | #define MII_VCT7_RESULTS_SAME_SHORT 3 |
| 264 | #define MII_VCT7_RESULTS_CROSS_SHORT 4 |
| 265 | #define MII_VCT7_RESULTS_BUSY 9 |
| 266 | |
| 267 | #define MII_VCT7_CTRL 0x15 |
| 268 | #define MII_VCT7_CTRL_RUN_NOW BIT(15) |
| 269 | #define MII_VCT7_CTRL_RUN_ANEG BIT(14) |
| 270 | #define MII_VCT7_CTRL_DISABLE_CROSS BIT(13) |
| 271 | #define MII_VCT7_CTRL_RUN_AFTER_BREAK_LINK BIT(12) |
| 272 | #define MII_VCT7_CTRL_IN_PROGRESS BIT(11) |
| 273 | #define MII_VCT7_CTRL_METERS BIT(10) |
| 274 | #define MII_VCT7_CTRL_CENTIMETERS 0 |
| 275 | |
Andrew Lunn | 8cf8b87 | 2017-07-30 22:41:44 +0200 | [diff] [blame] | 276 | #define LPA_PAUSE_FIBER 0x180 |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 277 | #define LPA_PAUSE_ASYM_FIBER 0x100 |
| 278 | |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 279 | #define NB_FIBER_STATS 1 |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 280 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 281 | MODULE_DESCRIPTION("Marvell PHY driver"); |
| 282 | MODULE_AUTHOR("Andy Fleming"); |
| 283 | MODULE_LICENSE("GPL"); |
| 284 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 285 | struct marvell_hw_stat { |
| 286 | const char *string; |
| 287 | u8 page; |
| 288 | u8 reg; |
| 289 | u8 bits; |
| 290 | }; |
| 291 | |
| 292 | static struct marvell_hw_stat marvell_hw_stats[] = { |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 293 | { "phy_receive_errors_copper", 0, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 294 | { "phy_idle_errors", 0, 10, 8 }, |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 295 | { "phy_receive_errors_fiber", 1, 21, 16}, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | struct marvell_priv { |
| 299 | u64 stats[ARRAY_SIZE(marvell_hw_stats)]; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 300 | char *hwmon_name; |
| 301 | struct device *hwmon_dev; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 302 | bool cable_test_tdr; |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 303 | u32 first; |
| 304 | u32 last; |
| 305 | u32 step; |
| 306 | s8 pair; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 307 | }; |
| 308 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 309 | static int marvell_read_page(struct phy_device *phydev) |
Andrew Lunn | 6427bb2 | 2017-05-17 03:26:03 +0200 | [diff] [blame] | 310 | { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 311 | return __phy_read(phydev, MII_MARVELL_PHY_PAGE); |
| 312 | } |
| 313 | |
| 314 | static int marvell_write_page(struct phy_device *phydev, int page) |
| 315 | { |
| 316 | return __phy_write(phydev, MII_MARVELL_PHY_PAGE, page); |
Andrew Lunn | 6427bb2 | 2017-05-17 03:26:03 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int marvell_set_page(struct phy_device *phydev, int page) |
| 320 | { |
| 321 | return phy_write(phydev, MII_MARVELL_PHY_PAGE, page); |
| 322 | } |
| 323 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 324 | static int marvell_ack_interrupt(struct phy_device *phydev) |
| 325 | { |
| 326 | int err; |
| 327 | |
| 328 | /* Clear the interrupts by reading the reg */ |
| 329 | err = phy_read(phydev, MII_M1011_IEVENT); |
| 330 | |
| 331 | if (err < 0) |
| 332 | return err; |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int marvell_config_intr(struct phy_device *phydev) |
| 338 | { |
| 339 | int err; |
| 340 | |
Ioana Ciornei | 1f6d0f2 | 2020-11-13 18:52:14 +0200 | [diff] [blame] | 341 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
| 342 | err = marvell_ack_interrupt(phydev); |
| 343 | if (err) |
| 344 | return err; |
| 345 | |
Andrew Lunn | 23beb38 | 2017-05-17 03:26:04 +0200 | [diff] [blame] | 346 | err = phy_write(phydev, MII_M1011_IMASK, |
| 347 | MII_M1011_IMASK_INIT); |
Ioana Ciornei | 1f6d0f2 | 2020-11-13 18:52:14 +0200 | [diff] [blame] | 348 | } else { |
Andrew Lunn | 23beb38 | 2017-05-17 03:26:04 +0200 | [diff] [blame] | 349 | err = phy_write(phydev, MII_M1011_IMASK, |
| 350 | MII_M1011_IMASK_CLEAR); |
Ioana Ciornei | 1f6d0f2 | 2020-11-13 18:52:14 +0200 | [diff] [blame] | 351 | if (err) |
| 352 | return err; |
| 353 | |
| 354 | err = marvell_ack_interrupt(phydev); |
| 355 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 356 | |
| 357 | return err; |
| 358 | } |
| 359 | |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 360 | static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) |
| 361 | { |
| 362 | int irq_status; |
| 363 | |
| 364 | irq_status = phy_read(phydev, MII_M1011_IEVENT); |
| 365 | if (irq_status < 0) { |
| 366 | phy_error(phydev); |
| 367 | return IRQ_NONE; |
| 368 | } |
| 369 | |
| 370 | if (!(irq_status & MII_M1011_IMASK_INIT)) |
| 371 | return IRQ_NONE; |
| 372 | |
| 373 | phy_trigger_machine(phydev); |
| 374 | |
| 375 | return IRQ_HANDLED; |
| 376 | } |
| 377 | |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 378 | static int marvell_set_polarity(struct phy_device *phydev, int polarity) |
| 379 | { |
Russell King | feb938f | 2021-06-03 14:01:10 +0100 | [diff] [blame] | 380 | u16 val; |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 381 | |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 382 | switch (polarity) { |
| 383 | case ETH_TP_MDI: |
Russell King | feb938f | 2021-06-03 14:01:10 +0100 | [diff] [blame] | 384 | val = MII_M1011_PHY_SCR_MDI; |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 385 | break; |
| 386 | case ETH_TP_MDI_X: |
Russell King | feb938f | 2021-06-03 14:01:10 +0100 | [diff] [blame] | 387 | val = MII_M1011_PHY_SCR_MDI_X; |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 388 | break; |
| 389 | case ETH_TP_MDI_AUTO: |
| 390 | case ETH_TP_MDI_INVALID: |
| 391 | default: |
Russell King | feb938f | 2021-06-03 14:01:10 +0100 | [diff] [blame] | 392 | val = MII_M1011_PHY_SCR_AUTO_CROSS; |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 393 | break; |
| 394 | } |
| 395 | |
Russell King | feb938f | 2021-06-03 14:01:10 +0100 | [diff] [blame] | 396 | return phy_modify_changed(phydev, MII_M1011_PHY_SCR, |
| 397 | MII_M1011_PHY_SCR_AUTO_CROSS, val); |
David Thomson | 239aa55 | 2015-07-10 16:28:25 +1200 | [diff] [blame] | 398 | } |
| 399 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 400 | static int marvell_config_aneg(struct phy_device *phydev) |
| 401 | { |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 402 | int changed = 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 403 | int err; |
| 404 | |
Raju Lakkaraju | 4e26c5c | 2016-11-29 15:16:49 +0530 | [diff] [blame] | 405 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 406 | if (err < 0) |
| 407 | return err; |
| 408 | |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 409 | changed = err; |
| 410 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 411 | err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, |
| 412 | MII_M1111_PHY_LED_DIRECT); |
| 413 | if (err < 0) |
| 414 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 415 | |
| 416 | err = genphy_config_aneg(phydev); |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 417 | if (err < 0) |
| 418 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 419 | |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 420 | if (phydev->autoneg != AUTONEG_ENABLE || changed) { |
Andrew Lunn | 0c3439b | 2017-05-17 03:25:59 +0200 | [diff] [blame] | 421 | /* A write to speed/duplex bits (that is performed by |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 422 | * genphy_config_aneg() call above) must be followed by |
| 423 | * a software reset. Otherwise, the write has no effect. |
| 424 | */ |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 425 | err = genphy_soft_reset(phydev); |
Anton Vorontsov | 8ff4498 | 2009-09-09 16:01:30 +0000 | [diff] [blame] | 426 | if (err < 0) |
| 427 | return err; |
| 428 | } |
| 429 | |
| 430 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Andrew Lunn | f289978 | 2017-05-23 17:49:13 +0200 | [diff] [blame] | 433 | static int m88e1101_config_aneg(struct phy_device *phydev) |
| 434 | { |
| 435 | int err; |
| 436 | |
| 437 | /* This Marvell PHY has an errata which requires |
| 438 | * that certain registers get written in order |
| 439 | * to restart autonegotiation |
| 440 | */ |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 441 | err = genphy_soft_reset(phydev); |
Andrew Lunn | f289978 | 2017-05-23 17:49:13 +0200 | [diff] [blame] | 442 | if (err < 0) |
| 443 | return err; |
| 444 | |
| 445 | err = phy_write(phydev, 0x1d, 0x1f); |
| 446 | if (err < 0) |
| 447 | return err; |
| 448 | |
| 449 | err = phy_write(phydev, 0x1e, 0x200c); |
| 450 | if (err < 0) |
| 451 | return err; |
| 452 | |
| 453 | err = phy_write(phydev, 0x1d, 0x5); |
| 454 | if (err < 0) |
| 455 | return err; |
| 456 | |
| 457 | err = phy_write(phydev, 0x1e, 0); |
| 458 | if (err < 0) |
| 459 | return err; |
| 460 | |
| 461 | err = phy_write(phydev, 0x1e, 0x100); |
| 462 | if (err < 0) |
| 463 | return err; |
| 464 | |
| 465 | return marvell_config_aneg(phydev); |
| 466 | } |
| 467 | |
Dan Murphy | 5cd119d | 2020-06-05 09:01:06 -0500 | [diff] [blame] | 468 | #if IS_ENABLED(CONFIG_OF_MDIO) |
Andrew Lunn | 0c3439b | 2017-05-17 03:25:59 +0200 | [diff] [blame] | 469 | /* Set and/or override some configuration registers based on the |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 470 | * marvell,reg-init property stored in the of_node for the phydev. |
| 471 | * |
| 472 | * marvell,reg-init = <reg-page reg mask value>,...; |
| 473 | * |
| 474 | * There may be one or more sets of <reg-page reg mask value>: |
| 475 | * |
| 476 | * reg-page: which register bank to use. |
| 477 | * reg: the register. |
| 478 | * mask: if non-zero, ANDed with existing register value. |
| 479 | * value: ORed with the masked value and written to the regiser. |
| 480 | * |
| 481 | */ |
| 482 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 483 | { |
| 484 | const __be32 *paddr; |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 485 | int len, i, saved_page, current_page, ret = 0; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 486 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 487 | if (!phydev->mdio.dev.of_node) |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 488 | return 0; |
| 489 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 490 | paddr = of_get_property(phydev->mdio.dev.of_node, |
| 491 | "marvell,reg-init", &len); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 492 | if (!paddr || len < (4 * sizeof(*paddr))) |
| 493 | return 0; |
| 494 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 495 | saved_page = phy_save_page(phydev); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 496 | if (saved_page < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 497 | goto err; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 498 | current_page = saved_page; |
| 499 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 500 | len /= sizeof(*paddr); |
| 501 | for (i = 0; i < len - 3; i += 4) { |
Andrew Lunn | 6427bb2 | 2017-05-17 03:26:03 +0200 | [diff] [blame] | 502 | u16 page = be32_to_cpup(paddr + i); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 503 | u16 reg = be32_to_cpup(paddr + i + 1); |
| 504 | u16 mask = be32_to_cpup(paddr + i + 2); |
| 505 | u16 val_bits = be32_to_cpup(paddr + i + 3); |
| 506 | int val; |
| 507 | |
Andrew Lunn | 6427bb2 | 2017-05-17 03:26:03 +0200 | [diff] [blame] | 508 | if (page != current_page) { |
| 509 | current_page = page; |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 510 | ret = marvell_write_page(phydev, page); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 511 | if (ret < 0) |
| 512 | goto err; |
| 513 | } |
| 514 | |
| 515 | val = 0; |
| 516 | if (mask) { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 517 | val = __phy_read(phydev, reg); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 518 | if (val < 0) { |
| 519 | ret = val; |
| 520 | goto err; |
| 521 | } |
| 522 | val &= mask; |
| 523 | } |
| 524 | val |= val_bits; |
| 525 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 526 | ret = __phy_write(phydev, reg, val); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 527 | if (ret < 0) |
| 528 | goto err; |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 529 | } |
| 530 | err: |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 531 | return phy_restore_page(phydev, saved_page, ret); |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 532 | } |
| 533 | #else |
| 534 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 535 | { |
| 536 | return 0; |
| 537 | } |
| 538 | #endif /* CONFIG_OF_MDIO */ |
| 539 | |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 540 | static int m88e1121_config_aneg_rgmii_delays(struct phy_device *phydev) |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 541 | { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 542 | int mscr; |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 543 | |
| 544 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 545 | mscr = MII_88E1121_PHY_MSCR_RX_DELAY | |
| 546 | MII_88E1121_PHY_MSCR_TX_DELAY; |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 547 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 548 | mscr = MII_88E1121_PHY_MSCR_RX_DELAY; |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 549 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 550 | mscr = MII_88E1121_PHY_MSCR_TX_DELAY; |
| 551 | else |
| 552 | mscr = 0; |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 553 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 554 | return phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, |
| 555 | MII_88E1121_PHY_MSCR_REG, |
| 556 | MII_88E1121_PHY_MSCR_DELAY_MASK, mscr); |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static int m88e1121_config_aneg(struct phy_device *phydev) |
| 560 | { |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 561 | int changed = 0; |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 562 | int err = 0; |
| 563 | |
| 564 | if (phy_interface_is_rgmii(phydev)) { |
| 565 | err = m88e1121_config_aneg_rgmii_delays(phydev); |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 566 | if (err < 0) |
Andrew Lunn | 864dc72 | 2017-07-30 22:41:48 +0200 | [diff] [blame] | 567 | return err; |
| 568 | } |
| 569 | |
Andrew Lunn | fecd5e9 | 2017-07-30 22:41:49 +0200 | [diff] [blame] | 570 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 571 | if (err < 0) |
| 572 | return err; |
| 573 | |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 574 | changed = err; |
| 575 | |
| 576 | err = genphy_config_aneg(phydev); |
| 577 | if (err < 0) |
| 578 | return err; |
| 579 | |
David S. Miller | 4b1bd69 | 2018-09-25 22:41:31 -0700 | [diff] [blame] | 580 | if (phydev->autoneg != AUTONEG_ENABLE || changed) { |
Florian Fainelli | d6ab933 | 2018-09-25 11:28:46 -0700 | [diff] [blame] | 581 | /* A software reset is used to ensure a "commit" of the |
| 582 | * changes is done. |
| 583 | */ |
| 584 | err = genphy_soft_reset(phydev); |
| 585 | if (err < 0) |
| 586 | return err; |
| 587 | } |
| 588 | |
| 589 | return 0; |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 592 | static int m88e1318_config_aneg(struct phy_device *phydev) |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 593 | { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 594 | int err; |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 595 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 596 | err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, |
| 597 | MII_88E1318S_PHY_MSCR1_REG, |
| 598 | 0, MII_88E1318S_PHY_MSCR1_PAD_ODD); |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 599 | if (err < 0) |
| 600 | return err; |
| 601 | |
| 602 | return m88e1121_config_aneg(phydev); |
| 603 | } |
| 604 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 605 | /** |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 606 | * linkmode_adv_to_fiber_adv_t |
| 607 | * @advertise: the linkmode advertisement settings |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 608 | * |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 609 | * A small helper function that translates linkmode advertisement |
| 610 | * settings to phy autonegotiation advertisements for the MII_ADV |
| 611 | * register for fiber link. |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 612 | */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 613 | 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] | 614 | { |
| 615 | u32 result = 0; |
| 616 | |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 617 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, advertise)) |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 618 | result |= ADVERTISE_1000XHALF; |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 619 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise)) |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 620 | result |= ADVERTISE_1000XFULL; |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 621 | |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 622 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertise) && |
| 623 | linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise)) |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 624 | result |= ADVERTISE_1000XPSE_ASYM; |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 625 | else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise)) |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 626 | result |= ADVERTISE_1000XPAUSE; |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 627 | |
| 628 | return result; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR |
| 633 | * @phydev: target phy_device struct |
| 634 | * |
| 635 | * Description: If auto-negotiation is enabled, we configure the |
| 636 | * advertising, and then restart auto-negotiation. If it is not |
| 637 | * enabled, then we write the BMCR. Adapted for fiber link in |
| 638 | * some Marvell's devices. |
| 639 | */ |
| 640 | static int marvell_config_aneg_fiber(struct phy_device *phydev) |
| 641 | { |
| 642 | int changed = 0; |
| 643 | int err; |
Russell King | 9f4bae7 | 2019-12-17 13:39:47 +0000 | [diff] [blame] | 644 | u16 adv; |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 645 | |
| 646 | if (phydev->autoneg != AUTONEG_ENABLE) |
| 647 | return genphy_setup_forced(phydev); |
| 648 | |
| 649 | /* Only allow advertising what this PHY supports */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 650 | linkmode_and(phydev->advertising, phydev->advertising, |
| 651 | phydev->supported); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 652 | |
Russell King | 9f4bae7 | 2019-12-17 13:39:47 +0000 | [diff] [blame] | 653 | adv = linkmode_adv_to_fiber_adv_t(phydev->advertising); |
| 654 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 655 | /* Setup fiber advertisement */ |
Russell King | 9f4bae7 | 2019-12-17 13:39:47 +0000 | [diff] [blame] | 656 | err = phy_modify_changed(phydev, MII_ADVERTISE, |
| 657 | ADVERTISE_1000XHALF | ADVERTISE_1000XFULL | |
| 658 | ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM, |
| 659 | adv); |
| 660 | if (err < 0) |
| 661 | return err; |
| 662 | if (err > 0) |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 663 | changed = 1; |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 664 | |
Russell King | b5abac2 | 2019-12-17 13:39:52 +0000 | [diff] [blame] | 665 | return genphy_check_and_restart_aneg(phydev, changed); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 668 | static int m88e1111_config_aneg(struct phy_device *phydev) |
| 669 | { |
| 670 | int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 671 | int err; |
| 672 | |
| 673 | if (extsr < 0) |
| 674 | return extsr; |
| 675 | |
| 676 | /* If not using SGMII or copper 1000BaseX modes, use normal process. |
| 677 | * Steps below are only required for these modes. |
| 678 | */ |
| 679 | if (phydev->interface != PHY_INTERFACE_MODE_SGMII && |
| 680 | (extsr & MII_M1111_HWCFG_MODE_MASK) != |
| 681 | MII_M1111_HWCFG_MODE_COPPER_1000X_AN) |
| 682 | return marvell_config_aneg(phydev); |
| 683 | |
| 684 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
| 685 | if (err < 0) |
| 686 | goto error; |
| 687 | |
| 688 | /* Configure the copper link first */ |
| 689 | err = marvell_config_aneg(phydev); |
| 690 | if (err < 0) |
| 691 | goto error; |
| 692 | |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 693 | /* Then the fiber link */ |
| 694 | err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); |
| 695 | if (err < 0) |
| 696 | goto error; |
| 697 | |
Robert Hancock | 06b334f | 2021-02-16 14:53:30 -0600 | [diff] [blame] | 698 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) |
| 699 | /* Do not touch the fiber advertisement if we're in copper->sgmii mode. |
| 700 | * Just ensure that SGMII-side autonegotiation is enabled. |
| 701 | * If we switched from some other mode to SGMII it may not be. |
| 702 | */ |
| 703 | err = genphy_check_and_restart_aneg(phydev, false); |
| 704 | else |
| 705 | err = marvell_config_aneg_fiber(phydev); |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 706 | if (err < 0) |
| 707 | goto error; |
| 708 | |
| 709 | return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
| 710 | |
| 711 | error: |
| 712 | marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
| 713 | return err; |
| 714 | } |
| 715 | |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 716 | static int m88e1510_config_aneg(struct phy_device *phydev) |
| 717 | { |
| 718 | int err; |
| 719 | |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 720 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 721 | if (err < 0) |
| 722 | goto error; |
| 723 | |
| 724 | /* Configure the copper link first */ |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 725 | err = m88e1318_config_aneg(phydev); |
| 726 | if (err < 0) |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 727 | goto error; |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 728 | |
Russell King | de9c4e0 | 2017-12-13 09:22:03 +0000 | [diff] [blame] | 729 | /* Do not touch the fiber page if we're in copper->sgmii mode */ |
| 730 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) |
| 731 | return 0; |
| 732 | |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 733 | /* Then the fiber link */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 734 | err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 735 | if (err < 0) |
| 736 | goto error; |
| 737 | |
| 738 | err = marvell_config_aneg_fiber(phydev); |
| 739 | if (err < 0) |
| 740 | goto error; |
| 741 | |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 742 | return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 743 | |
| 744 | error: |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 745 | marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 78301eb | 2016-07-19 11:13:12 +0200 | [diff] [blame] | 746 | return err; |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 749 | static void marvell_config_led(struct phy_device *phydev) |
| 750 | { |
| 751 | u16 def_config; |
| 752 | int err; |
| 753 | |
| 754 | switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) { |
| 755 | /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */ |
| 756 | case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R): |
| 757 | case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S): |
| 758 | def_config = MII_88E1121_PHY_LED_DEF; |
| 759 | break; |
| 760 | /* Default PHY LED config: |
| 761 | * LED[0] .. 1000Mbps Link |
| 762 | * LED[1] .. 100Mbps Link |
| 763 | * LED[2] .. Blink, Activity |
| 764 | */ |
| 765 | case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510): |
Jian Shen | a93f7fe | 2019-04-22 21:52:23 +0800 | [diff] [blame] | 766 | if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE) |
| 767 | def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE; |
| 768 | else |
| 769 | def_config = MII_88E1510_PHY_LED_DEF; |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 770 | break; |
| 771 | default: |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, MII_PHY_LED_CTRL, |
| 776 | def_config); |
| 777 | if (err < 0) |
Andrew Lunn | ab2a605 | 2018-09-29 23:04:10 +0200 | [diff] [blame] | 778 | phydev_warn(phydev, "Fail to config marvell phy LED.\n"); |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 781 | static int marvell_config_init(struct phy_device *phydev) |
| 782 | { |
Bhaskar Chowdhury | 85bec4b | 2020-10-29 15:25:25 +0530 | [diff] [blame] | 783 | /* Set default LED */ |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 784 | marvell_config_led(phydev); |
| 785 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 786 | /* Set registers from marvell,reg-init DT property */ |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 787 | return marvell_of_reg_init(phydev); |
| 788 | } |
| 789 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 790 | static int m88e3016_config_init(struct phy_device *phydev) |
| 791 | { |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 792 | int ret; |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 793 | |
| 794 | /* Enable Scrambler and Auto-Crossover */ |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 795 | ret = phy_modify(phydev, MII_88E3016_PHY_SPEC_CTRL, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 796 | MII_88E3016_DISABLE_SCRAMBLER, |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 797 | MII_88E3016_AUTO_MDIX_CROSSOVER); |
| 798 | if (ret < 0) |
| 799 | return ret; |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 800 | |
Clemens Gruber | 79be1a1 | 2016-02-15 23:46:45 +0100 | [diff] [blame] | 801 | return marvell_config_init(phydev); |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 802 | } |
| 803 | |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 804 | static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev, |
| 805 | u16 mode, |
| 806 | int fibre_copper_auto) |
| 807 | { |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 808 | if (fibre_copper_auto) |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 809 | mode |= MII_M1111_HWCFG_FIBER_COPPER_AUTO; |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 810 | |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 811 | return phy_modify(phydev, MII_M1111_PHY_EXT_SR, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 812 | MII_M1111_HWCFG_MODE_MASK | |
| 813 | MII_M1111_HWCFG_FIBER_COPPER_AUTO | |
| 814 | MII_M1111_HWCFG_FIBER_COPPER_RES, |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 815 | mode); |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 816 | } |
| 817 | |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 818 | static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev) |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 819 | { |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 820 | int delay; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 821 | |
Weihang Li | 16d4d65 | 2021-06-16 18:01:26 +0800 | [diff] [blame] | 822 | switch (phydev->interface) { |
| 823 | case PHY_INTERFACE_MODE_RGMII_ID: |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 824 | delay = MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY; |
Weihang Li | 16d4d65 | 2021-06-16 18:01:26 +0800 | [diff] [blame] | 825 | break; |
| 826 | case PHY_INTERFACE_MODE_RGMII_RXID: |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 827 | delay = MII_M1111_RGMII_RX_DELAY; |
Weihang Li | 16d4d65 | 2021-06-16 18:01:26 +0800 | [diff] [blame] | 828 | break; |
| 829 | case PHY_INTERFACE_MODE_RGMII_TXID: |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 830 | delay = MII_M1111_RGMII_TX_DELAY; |
Weihang Li | 16d4d65 | 2021-06-16 18:01:26 +0800 | [diff] [blame] | 831 | break; |
| 832 | default: |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 833 | delay = 0; |
Weihang Li | 16d4d65 | 2021-06-16 18:01:26 +0800 | [diff] [blame] | 834 | break; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 835 | } |
| 836 | |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 837 | return phy_modify(phydev, MII_M1111_PHY_EXT_CR, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 838 | MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY, |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 839 | delay); |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static int m88e1111_config_init_rgmii(struct phy_device *phydev) |
| 843 | { |
| 844 | int temp; |
| 845 | int err; |
| 846 | |
| 847 | err = m88e1111_config_init_rgmii_delays(phydev); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 848 | if (err < 0) |
| 849 | return err; |
| 850 | |
| 851 | temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 852 | if (temp < 0) |
| 853 | return temp; |
| 854 | |
| 855 | temp &= ~(MII_M1111_HWCFG_MODE_MASK); |
| 856 | |
| 857 | if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES) |
| 858 | temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII; |
| 859 | else |
| 860 | temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII; |
| 861 | |
| 862 | return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); |
| 863 | } |
| 864 | |
| 865 | static int m88e1111_config_init_sgmii(struct phy_device *phydev) |
| 866 | { |
| 867 | int err; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 868 | |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 869 | err = m88e1111_config_init_hwcfg_mode( |
| 870 | phydev, |
| 871 | MII_M1111_HWCFG_MODE_SGMII_NO_CLK, |
| 872 | MII_M1111_HWCFG_FIBER_COPPER_AUTO); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 873 | if (err < 0) |
| 874 | return err; |
| 875 | |
| 876 | /* make sure copper is selected */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 877 | return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static int m88e1111_config_init_rtbi(struct phy_device *phydev) |
| 881 | { |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 882 | int err; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 883 | |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 884 | err = m88e1111_config_init_rgmii_delays(phydev); |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 885 | if (err < 0) |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 886 | return err; |
| 887 | |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 888 | err = m88e1111_config_init_hwcfg_mode( |
| 889 | phydev, |
| 890 | MII_M1111_HWCFG_MODE_RTBI, |
| 891 | MII_M1111_HWCFG_FIBER_COPPER_AUTO); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 892 | if (err < 0) |
| 893 | return err; |
| 894 | |
| 895 | /* soft reset */ |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 896 | err = genphy_soft_reset(phydev); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 897 | if (err < 0) |
| 898 | return err; |
| 899 | |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 900 | return m88e1111_config_init_hwcfg_mode( |
| 901 | phydev, |
| 902 | MII_M1111_HWCFG_MODE_RTBI, |
| 903 | MII_M1111_HWCFG_FIBER_COPPER_AUTO); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 904 | } |
| 905 | |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 906 | static int m88e1111_config_init_1000basex(struct phy_device *phydev) |
| 907 | { |
| 908 | int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR); |
| 909 | int err, mode; |
| 910 | |
| 911 | if (extsr < 0) |
| 912 | return extsr; |
| 913 | |
| 914 | /* If using copper mode, ensure 1000BaseX auto-negotiation is enabled */ |
| 915 | mode = extsr & MII_M1111_HWCFG_MODE_MASK; |
| 916 | if (mode == MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN) { |
| 917 | err = phy_modify(phydev, MII_M1111_PHY_EXT_SR, |
| 918 | MII_M1111_HWCFG_MODE_MASK | |
| 919 | MII_M1111_HWCFG_SERIAL_AN_BYPASS, |
| 920 | MII_M1111_HWCFG_MODE_COPPER_1000X_AN | |
| 921 | MII_M1111_HWCFG_SERIAL_AN_BYPASS); |
| 922 | if (err < 0) |
| 923 | return err; |
| 924 | } |
| 925 | return 0; |
| 926 | } |
| 927 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 928 | static int m88e1111_config_init(struct phy_device *phydev) |
| 929 | { |
| 930 | int err; |
| 931 | |
Florian Fainelli | 32a6416 | 2015-05-26 12:19:59 -0700 | [diff] [blame] | 932 | if (phy_interface_is_rgmii(phydev)) { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 933 | err = m88e1111_config_init_rgmii(phydev); |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 934 | if (err < 0) |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 935 | return err; |
| 936 | } |
| 937 | |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 938 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 939 | err = m88e1111_config_init_sgmii(phydev); |
Madalin Bucur | 07151bc | 2015-08-07 17:07:50 +0800 | [diff] [blame] | 940 | if (err < 0) |
| 941 | return err; |
Kapil Juneja | 4117b5b | 2007-05-11 18:25:18 -0500 | [diff] [blame] | 942 | } |
| 943 | |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 944 | if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 945 | err = m88e1111_config_init_rtbi(phydev); |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 946 | if (err < 0) |
| 947 | return err; |
| 948 | } |
| 949 | |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 950 | if (phydev->interface == PHY_INTERFACE_MODE_1000BASEX) { |
| 951 | err = m88e1111_config_init_1000basex(phydev); |
| 952 | if (err < 0) |
| 953 | return err; |
| 954 | } |
| 955 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 956 | err = marvell_of_reg_init(phydev); |
| 957 | if (err < 0) |
| 958 | return err; |
Liu Yu-B13201 | 5f8cbc1 | 2010-01-13 22:13:19 +0000 | [diff] [blame] | 959 | |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 960 | return genphy_soft_reset(phydev); |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 961 | } |
| 962 | |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 963 | static int m88e1111_get_downshift(struct phy_device *phydev, u8 *data) |
| 964 | { |
| 965 | int val, cnt, enable; |
| 966 | |
| 967 | val = phy_read(phydev, MII_M1111_PHY_EXT_CR); |
| 968 | if (val < 0) |
| 969 | return val; |
| 970 | |
| 971 | enable = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN, val); |
| 972 | cnt = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, val) + 1; |
| 973 | |
| 974 | *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE; |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static int m88e1111_set_downshift(struct phy_device *phydev, u8 cnt) |
| 980 | { |
Maxim Kochetkov | e7679c5 | 2021-04-22 13:46:44 +0300 | [diff] [blame] | 981 | int val, err; |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 982 | |
| 983 | if (cnt > MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX) |
| 984 | return -E2BIG; |
| 985 | |
Maxim Kochetkov | e7679c5 | 2021-04-22 13:46:44 +0300 | [diff] [blame] | 986 | if (!cnt) { |
| 987 | err = phy_clear_bits(phydev, MII_M1111_PHY_EXT_CR, |
| 988 | MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN); |
| 989 | } else { |
| 990 | val = MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN; |
| 991 | val |= FIELD_PREP(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, cnt - 1); |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 992 | |
Maxim Kochetkov | e7679c5 | 2021-04-22 13:46:44 +0300 | [diff] [blame] | 993 | err = phy_modify(phydev, MII_M1111_PHY_EXT_CR, |
| 994 | MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN | |
| 995 | MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, |
| 996 | val); |
| 997 | } |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 998 | |
Maxim Kochetkov | e7679c5 | 2021-04-22 13:46:44 +0300 | [diff] [blame] | 999 | if (err < 0) |
| 1000 | return err; |
| 1001 | |
| 1002 | return genphy_soft_reset(phydev); |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static int m88e1111_get_tunable(struct phy_device *phydev, |
| 1006 | struct ethtool_tunable *tuna, void *data) |
| 1007 | { |
| 1008 | switch (tuna->id) { |
| 1009 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1010 | return m88e1111_get_downshift(phydev, data); |
| 1011 | default: |
| 1012 | return -EOPNOTSUPP; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | static int m88e1111_set_tunable(struct phy_device *phydev, |
| 1017 | struct ethtool_tunable *tuna, const void *data) |
| 1018 | { |
| 1019 | switch (tuna->id) { |
| 1020 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1021 | return m88e1111_set_downshift(phydev, *(const u8 *)data); |
| 1022 | default: |
| 1023 | return -EOPNOTSUPP; |
| 1024 | } |
| 1025 | } |
| 1026 | |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1027 | static int m88e1011_get_downshift(struct phy_device *phydev, u8 *data) |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1028 | { |
| 1029 | int val, cnt, enable; |
| 1030 | |
| 1031 | val = phy_read(phydev, MII_M1011_PHY_SCR); |
| 1032 | if (val < 0) |
| 1033 | return val; |
| 1034 | |
| 1035 | enable = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_EN, val); |
Heiner Kallweit | f8d975b | 2019-10-28 20:52:22 +0100 | [diff] [blame] | 1036 | cnt = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, val) + 1; |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1037 | |
| 1038 | *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE; |
| 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1043 | static int m88e1011_set_downshift(struct phy_device *phydev, u8 cnt) |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1044 | { |
Maxim Kochetkov | 990875b | 2021-04-22 13:46:43 +0300 | [diff] [blame] | 1045 | int val, err; |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1046 | |
| 1047 | if (cnt > MII_M1011_PHY_SCR_DOWNSHIFT_MAX) |
| 1048 | return -E2BIG; |
| 1049 | |
Maxim Kochetkov | 990875b | 2021-04-22 13:46:43 +0300 | [diff] [blame] | 1050 | if (!cnt) { |
| 1051 | err = phy_clear_bits(phydev, MII_M1011_PHY_SCR, |
| 1052 | MII_M1011_PHY_SCR_DOWNSHIFT_EN); |
| 1053 | } else { |
| 1054 | val = MII_M1011_PHY_SCR_DOWNSHIFT_EN; |
| 1055 | val |= FIELD_PREP(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, cnt - 1); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1056 | |
Maxim Kochetkov | 990875b | 2021-04-22 13:46:43 +0300 | [diff] [blame] | 1057 | err = phy_modify(phydev, MII_M1011_PHY_SCR, |
| 1058 | MII_M1011_PHY_SCR_DOWNSHIFT_EN | |
| 1059 | MII_M1011_PHY_SCR_DOWNSHIFT_MASK, |
| 1060 | val); |
| 1061 | } |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1062 | |
Maxim Kochetkov | 990875b | 2021-04-22 13:46:43 +0300 | [diff] [blame] | 1063 | if (err < 0) |
| 1064 | return err; |
| 1065 | |
| 1066 | return genphy_soft_reset(phydev); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1069 | static int m88e1011_get_tunable(struct phy_device *phydev, |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1070 | struct ethtool_tunable *tuna, void *data) |
| 1071 | { |
| 1072 | switch (tuna->id) { |
| 1073 | case ETHTOOL_PHY_DOWNSHIFT: |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1074 | return m88e1011_get_downshift(phydev, data); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1075 | default: |
| 1076 | return -EOPNOTSUPP; |
| 1077 | } |
| 1078 | } |
| 1079 | |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1080 | static int m88e1011_set_tunable(struct phy_device *phydev, |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1081 | struct ethtool_tunable *tuna, const void *data) |
| 1082 | { |
| 1083 | switch (tuna->id) { |
| 1084 | case ETHTOOL_PHY_DOWNSHIFT: |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1085 | return m88e1011_set_downshift(phydev, *(const u8 *)data); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1086 | default: |
| 1087 | return -EOPNOTSUPP; |
| 1088 | } |
| 1089 | } |
| 1090 | |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 1091 | static int m88e1112_config_init(struct phy_device *phydev) |
| 1092 | { |
| 1093 | int err; |
| 1094 | |
| 1095 | err = m88e1011_set_downshift(phydev, 3); |
| 1096 | if (err < 0) |
| 1097 | return err; |
| 1098 | |
| 1099 | return m88e1111_config_init(phydev); |
| 1100 | } |
| 1101 | |
| 1102 | static int m88e1111gbe_config_init(struct phy_device *phydev) |
| 1103 | { |
| 1104 | int err; |
| 1105 | |
| 1106 | err = m88e1111_set_downshift(phydev, 3); |
| 1107 | if (err < 0) |
| 1108 | return err; |
| 1109 | |
| 1110 | return m88e1111_config_init(phydev); |
| 1111 | } |
| 1112 | |
| 1113 | static int marvell_1011gbe_config_init(struct phy_device *phydev) |
| 1114 | { |
| 1115 | int err; |
| 1116 | |
| 1117 | err = m88e1011_set_downshift(phydev, 3); |
| 1118 | if (err < 0) |
| 1119 | return err; |
| 1120 | |
| 1121 | return marvell_config_init(phydev); |
| 1122 | } |
Heiner Kallweit | e2d861c | 2019-10-19 15:58:19 +0200 | [diff] [blame] | 1123 | static int m88e1116r_config_init(struct phy_device *phydev) |
| 1124 | { |
| 1125 | int err; |
| 1126 | |
| 1127 | err = genphy_soft_reset(phydev); |
| 1128 | if (err < 0) |
| 1129 | return err; |
| 1130 | |
| 1131 | msleep(500); |
| 1132 | |
| 1133 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
| 1134 | if (err < 0) |
| 1135 | return err; |
| 1136 | |
| 1137 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
| 1138 | if (err < 0) |
| 1139 | return err; |
| 1140 | |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1141 | err = m88e1011_set_downshift(phydev, 8); |
Heiner Kallweit | e2d861c | 2019-10-19 15:58:19 +0200 | [diff] [blame] | 1142 | if (err < 0) |
| 1143 | return err; |
| 1144 | |
| 1145 | if (phy_interface_is_rgmii(phydev)) { |
| 1146 | err = m88e1121_config_aneg_rgmii_delays(phydev); |
| 1147 | if (err < 0) |
| 1148 | return err; |
| 1149 | } |
| 1150 | |
| 1151 | err = genphy_soft_reset(phydev); |
| 1152 | if (err < 0) |
| 1153 | return err; |
| 1154 | |
| 1155 | return marvell_config_init(phydev); |
| 1156 | } |
| 1157 | |
Esben Haabendal | dd9a122 | 2018-04-05 22:40:29 +0200 | [diff] [blame] | 1158 | static int m88e1318_config_init(struct phy_device *phydev) |
| 1159 | { |
| 1160 | if (phy_interrupt_is_valid(phydev)) { |
| 1161 | int err = phy_modify_paged( |
| 1162 | phydev, MII_MARVELL_LED_PAGE, |
| 1163 | MII_88E1318S_PHY_LED_TCR, |
| 1164 | MII_88E1318S_PHY_LED_TCR_FORCE_INT, |
| 1165 | MII_88E1318S_PHY_LED_TCR_INTn_ENABLE | |
| 1166 | MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW); |
| 1167 | if (err < 0) |
| 1168 | return err; |
| 1169 | } |
| 1170 | |
Wang Dongsheng | 0777724 | 2018-07-01 23:15:46 -0700 | [diff] [blame] | 1171 | return marvell_config_init(phydev); |
Esben Haabendal | dd9a122 | 2018-04-05 22:40:29 +0200 | [diff] [blame] | 1172 | } |
| 1173 | |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1174 | static int m88e1510_config_init(struct phy_device *phydev) |
| 1175 | { |
| 1176 | int err; |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1177 | |
| 1178 | /* SGMII-to-Copper mode initialization */ |
| 1179 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 1180 | /* Select page 18 */ |
Andrew Lunn | 6427bb2 | 2017-05-17 03:26:03 +0200 | [diff] [blame] | 1181 | err = marvell_set_page(phydev, 18); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1182 | if (err < 0) |
| 1183 | return err; |
| 1184 | |
| 1185 | /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 1186 | err = phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 1187 | MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 1188 | MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1189 | if (err < 0) |
| 1190 | return err; |
| 1191 | |
| 1192 | /* PHY reset is necessary after changing MODE[2:0] */ |
Yejune Deng | 832913c | 2020-11-30 18:41:35 +0800 | [diff] [blame] | 1193 | err = phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, |
| 1194 | MII_88E1510_GEN_CTRL_REG_1_RESET); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1195 | if (err < 0) |
| 1196 | return err; |
| 1197 | |
| 1198 | /* Reset page selection */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1199 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1200 | if (err < 0) |
| 1201 | return err; |
| 1202 | } |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 1203 | err = m88e1011_set_downshift(phydev, 3); |
| 1204 | if (err < 0) |
| 1205 | return err; |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1206 | |
Esben Haabendal | dd9a122 | 2018-04-05 22:40:29 +0200 | [diff] [blame] | 1207 | return m88e1318_config_init(phydev); |
Clemens Gruber | 407353e | 2016-02-23 20:16:58 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1210 | static int m88e1118_config_aneg(struct phy_device *phydev) |
| 1211 | { |
| 1212 | int err; |
| 1213 | |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 1214 | err = genphy_soft_reset(phydev); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1215 | if (err < 0) |
| 1216 | return err; |
| 1217 | |
Andrew Lunn | fecd5e9 | 2017-07-30 22:41:49 +0200 | [diff] [blame] | 1218 | err = marvell_set_polarity(phydev, phydev->mdix_ctrl); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1219 | if (err < 0) |
| 1220 | return err; |
| 1221 | |
| 1222 | err = genphy_config_aneg(phydev); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int m88e1118_config_init(struct phy_device *phydev) |
| 1227 | { |
Russell King (Oracle) | 5b8f970 | 2022-01-04 16:38:13 +0000 | [diff] [blame^] | 1228 | u16 leds; |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1229 | int err; |
| 1230 | |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1231 | /* Enable 1000 Mbit */ |
Russell King (Oracle) | 5b8f970 | 2022-01-04 16:38:13 +0000 | [diff] [blame^] | 1232 | err = phy_write_paged(phydev, MII_MARVELL_MSCR_PAGE, |
| 1233 | MII_88E1121_PHY_MSCR_REG, 0x1070); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1234 | if (err < 0) |
| 1235 | return err; |
| 1236 | |
| 1237 | /* Adjust LED Control */ |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1238 | if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS) |
Russell King (Oracle) | 5b8f970 | 2022-01-04 16:38:13 +0000 | [diff] [blame^] | 1239 | leds = 0x1100; |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 1240 | else |
Russell King (Oracle) | 5b8f970 | 2022-01-04 16:38:13 +0000 | [diff] [blame^] | 1241 | leds = 0x021e; |
| 1242 | |
| 1243 | err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 0x10, leds); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1244 | if (err < 0) |
| 1245 | return err; |
| 1246 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 1247 | err = marvell_of_reg_init(phydev); |
| 1248 | if (err < 0) |
| 1249 | return err; |
| 1250 | |
Russell King (Oracle) | 5b8f970 | 2022-01-04 16:38:13 +0000 | [diff] [blame^] | 1251 | /* Reset page register */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1252 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1253 | if (err < 0) |
| 1254 | return err; |
| 1255 | |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 1256 | return genphy_soft_reset(phydev); |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1259 | static int m88e1149_config_init(struct phy_device *phydev) |
| 1260 | { |
| 1261 | int err; |
| 1262 | |
| 1263 | /* Change address */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1264 | err = marvell_set_page(phydev, MII_MARVELL_MSCR_PAGE); |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1265 | if (err < 0) |
| 1266 | return err; |
| 1267 | |
| 1268 | /* Enable 1000 Mbit */ |
| 1269 | err = phy_write(phydev, 0x15, 0x1048); |
| 1270 | if (err < 0) |
| 1271 | return err; |
| 1272 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 1273 | err = marvell_of_reg_init(phydev); |
| 1274 | if (err < 0) |
| 1275 | return err; |
| 1276 | |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1277 | /* Reset address */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1278 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1279 | if (err < 0) |
| 1280 | return err; |
| 1281 | |
Andrew Lunn | 3438634 | 2017-07-30 22:41:45 +0200 | [diff] [blame] | 1282 | return genphy_soft_reset(phydev); |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1285 | static int m88e1145_config_init_rgmii(struct phy_device *phydev) |
| 1286 | { |
| 1287 | int err; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1288 | |
Andrew Lunn | 6111159 | 2017-07-30 22:41:46 +0200 | [diff] [blame] | 1289 | err = m88e1111_config_init_rgmii_delays(phydev); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1290 | if (err < 0) |
| 1291 | return err; |
| 1292 | |
| 1293 | if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) { |
| 1294 | err = phy_write(phydev, 0x1d, 0x0012); |
| 1295 | if (err < 0) |
| 1296 | return err; |
| 1297 | |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 1298 | err = phy_modify(phydev, 0x1e, 0x0fc0, |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 1299 | 2 << 9 | /* 36 ohm */ |
| 1300 | 2 << 6); /* 39 ohm */ |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1301 | if (err < 0) |
| 1302 | return err; |
| 1303 | |
| 1304 | err = phy_write(phydev, 0x1d, 0x3); |
| 1305 | if (err < 0) |
| 1306 | return err; |
| 1307 | |
| 1308 | err = phy_write(phydev, 0x1e, 0x8000); |
| 1309 | } |
| 1310 | return err; |
| 1311 | } |
| 1312 | |
| 1313 | static int m88e1145_config_init_sgmii(struct phy_device *phydev) |
| 1314 | { |
Andrew Lunn | 865b813a | 2017-07-30 22:41:47 +0200 | [diff] [blame] | 1315 | return m88e1111_config_init_hwcfg_mode( |
| 1316 | phydev, MII_M1111_HWCFG_MODE_SGMII_NO_CLK, |
| 1317 | MII_M1111_HWCFG_FIBER_COPPER_AUTO); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1318 | } |
| 1319 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 1320 | static int m88e1145_config_init(struct phy_device *phydev) |
| 1321 | { |
| 1322 | int err; |
| 1323 | |
| 1324 | /* Take care of errata E0 & E1 */ |
| 1325 | err = phy_write(phydev, 0x1d, 0x001b); |
| 1326 | if (err < 0) |
| 1327 | return err; |
| 1328 | |
| 1329 | err = phy_write(phydev, 0x1e, 0x418f); |
| 1330 | if (err < 0) |
| 1331 | return err; |
| 1332 | |
| 1333 | err = phy_write(phydev, 0x1d, 0x0016); |
| 1334 | if (err < 0) |
| 1335 | return err; |
| 1336 | |
| 1337 | err = phy_write(phydev, 0x1e, 0xa2da); |
| 1338 | if (err < 0) |
| 1339 | return err; |
| 1340 | |
Kim Phillips | 895ee68 | 2007-06-05 18:46:47 +0800 | [diff] [blame] | 1341 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1342 | err = m88e1145_config_init_rgmii(phydev); |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 1343 | if (err < 0) |
| 1344 | return err; |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 1345 | } |
| 1346 | |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 1347 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1348 | err = m88e1145_config_init_sgmii(phydev); |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 1349 | if (err < 0) |
| 1350 | return err; |
| 1351 | } |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 1352 | err = m88e1111_set_downshift(phydev, 3); |
| 1353 | if (err < 0) |
| 1354 | return err; |
Viet Nga Dao | b022417 | 2014-10-23 19:41:53 -0700 | [diff] [blame] | 1355 | |
David Daney | cf41a51 | 2010-11-19 12:13:18 +0000 | [diff] [blame] | 1356 | err = marvell_of_reg_init(phydev); |
| 1357 | if (err < 0) |
| 1358 | return err; |
| 1359 | |
Andy Fleming | 7688467 | 2007-02-09 18:13:58 -0600 | [diff] [blame] | 1360 | return 0; |
| 1361 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1362 | |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 1363 | static int m88e1540_get_fld(struct phy_device *phydev, u8 *msecs) |
| 1364 | { |
| 1365 | int val; |
| 1366 | |
| 1367 | val = phy_read(phydev, MII_88E1540_COPPER_CTRL3); |
| 1368 | if (val < 0) |
| 1369 | return val; |
| 1370 | |
| 1371 | if (!(val & MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN)) { |
| 1372 | *msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF; |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | val = FIELD_GET(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); |
| 1377 | |
| 1378 | switch (val) { |
| 1379 | case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS: |
| 1380 | *msecs = 0; |
| 1381 | break; |
| 1382 | case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS: |
| 1383 | *msecs = 10; |
| 1384 | break; |
| 1385 | case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS: |
| 1386 | *msecs = 20; |
| 1387 | break; |
| 1388 | case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS: |
| 1389 | *msecs = 40; |
| 1390 | break; |
| 1391 | default: |
| 1392 | return -EINVAL; |
| 1393 | } |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs) |
| 1399 | { |
| 1400 | struct ethtool_eee eee; |
| 1401 | int val, ret; |
| 1402 | |
| 1403 | if (*msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF) |
| 1404 | return phy_clear_bits(phydev, MII_88E1540_COPPER_CTRL3, |
| 1405 | MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN); |
| 1406 | |
| 1407 | /* According to the Marvell data sheet EEE must be disabled for |
| 1408 | * Fast Link Down detection to work properly |
| 1409 | */ |
| 1410 | ret = phy_ethtool_get_eee(phydev, &eee); |
| 1411 | if (!ret && eee.eee_enabled) { |
| 1412 | phydev_warn(phydev, "Fast Link Down detection requires EEE to be disabled!\n"); |
| 1413 | return -EBUSY; |
| 1414 | } |
| 1415 | |
| 1416 | if (*msecs <= 5) |
| 1417 | val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS; |
| 1418 | else if (*msecs <= 15) |
| 1419 | val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS; |
| 1420 | else if (*msecs <= 30) |
| 1421 | val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS; |
| 1422 | else |
| 1423 | val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS; |
| 1424 | |
| 1425 | val = FIELD_PREP(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); |
| 1426 | |
| 1427 | ret = phy_modify(phydev, MII_88E1540_COPPER_CTRL3, |
| 1428 | MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); |
| 1429 | if (ret) |
| 1430 | return ret; |
| 1431 | |
| 1432 | return phy_set_bits(phydev, MII_88E1540_COPPER_CTRL3, |
| 1433 | MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN); |
| 1434 | } |
| 1435 | |
| 1436 | static int m88e1540_get_tunable(struct phy_device *phydev, |
| 1437 | struct ethtool_tunable *tuna, void *data) |
| 1438 | { |
| 1439 | switch (tuna->id) { |
| 1440 | case ETHTOOL_PHY_FAST_LINK_DOWN: |
| 1441 | return m88e1540_get_fld(phydev, data); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1442 | case ETHTOOL_PHY_DOWNSHIFT: |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1443 | return m88e1011_get_downshift(phydev, data); |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 1444 | default: |
| 1445 | return -EOPNOTSUPP; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | static int m88e1540_set_tunable(struct phy_device *phydev, |
| 1450 | struct ethtool_tunable *tuna, const void *data) |
| 1451 | { |
| 1452 | switch (tuna->id) { |
| 1453 | case ETHTOOL_PHY_FAST_LINK_DOWN: |
| 1454 | return m88e1540_set_fld(phydev, data); |
Heiner Kallweit | a3bdfce | 2019-10-19 15:57:33 +0200 | [diff] [blame] | 1455 | case ETHTOOL_PHY_DOWNSHIFT: |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 1456 | return m88e1011_set_downshift(phydev, *(const u8 *)data); |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 1457 | default: |
| 1458 | return -EOPNOTSUPP; |
| 1459 | } |
| 1460 | } |
| 1461 | |
Andrew Lunn | 8cbcdc1 | 2019-01-10 22:48:36 +0100 | [diff] [blame] | 1462 | /* The VOD can be out of specification on link up. Poke an |
| 1463 | * undocumented register, in an undocumented page, with a magic value |
| 1464 | * to fix this. |
| 1465 | */ |
| 1466 | static int m88e6390_errata(struct phy_device *phydev) |
| 1467 | { |
| 1468 | int err; |
| 1469 | |
| 1470 | err = phy_write(phydev, MII_BMCR, |
| 1471 | BMCR_ANENABLE | BMCR_SPEED1000 | BMCR_FULLDPLX); |
| 1472 | if (err) |
| 1473 | return err; |
| 1474 | |
| 1475 | usleep_range(300, 400); |
| 1476 | |
| 1477 | err = phy_write_paged(phydev, 0xf8, 0x08, 0x36); |
| 1478 | if (err) |
| 1479 | return err; |
| 1480 | |
| 1481 | return genphy_soft_reset(phydev); |
| 1482 | } |
| 1483 | |
| 1484 | static int m88e6390_config_aneg(struct phy_device *phydev) |
| 1485 | { |
| 1486 | int err; |
| 1487 | |
| 1488 | err = m88e6390_errata(phydev); |
| 1489 | if (err) |
| 1490 | return err; |
| 1491 | |
| 1492 | return m88e1510_config_aneg(phydev); |
| 1493 | } |
| 1494 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1495 | /** |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1496 | * fiber_lpa_mod_linkmode_lpa_t |
Andrew Lunn | c0ec3c2 | 2018-11-10 23:43:34 +0100 | [diff] [blame] | 1497 | * @advertising: the linkmode advertisement settings |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1498 | * @lpa: value of the MII_LPA register for fiber link |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1499 | * |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1500 | * A small helper function that translates MII_LPA bits to linkmode LP |
| 1501 | * advertisement settings. Other bits in advertising are left |
| 1502 | * unchanged. |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1503 | */ |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1504 | 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] | 1505 | { |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1506 | linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 1507 | advertising, lpa & LPA_1000XHALF); |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1508 | |
| 1509 | linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
Russell King | 20ecf42 | 2019-12-17 13:39:42 +0000 | [diff] [blame] | 1510 | advertising, lpa & LPA_1000XFULL); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1513 | static int marvell_read_status_page_an(struct phy_device *phydev, |
Russell King | d2004e2 | 2019-12-17 13:39:36 +0000 | [diff] [blame] | 1514 | int fiber, int status) |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1515 | { |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1516 | int lpa; |
Russell King | fcf1f59 | 2019-12-17 13:39:21 +0000 | [diff] [blame] | 1517 | int err; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1518 | |
Clemens Gruber | 3b72f84 | 2020-04-11 18:51:25 +0200 | [diff] [blame] | 1519 | if (!(status & MII_M1011_PHY_STATUS_RESOLVED)) { |
| 1520 | phydev->link = 0; |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
| 1524 | if (status & MII_M1011_PHY_STATUS_FULLDUPLEX) |
| 1525 | phydev->duplex = DUPLEX_FULL; |
| 1526 | else |
| 1527 | phydev->duplex = DUPLEX_HALF; |
| 1528 | |
| 1529 | switch (status & MII_M1011_PHY_STATUS_SPD_MASK) { |
| 1530 | case MII_M1011_PHY_STATUS_1000: |
| 1531 | phydev->speed = SPEED_1000; |
| 1532 | break; |
| 1533 | |
| 1534 | case MII_M1011_PHY_STATUS_100: |
| 1535 | phydev->speed = SPEED_100; |
| 1536 | break; |
| 1537 | |
| 1538 | default: |
| 1539 | phydev->speed = SPEED_10; |
| 1540 | break; |
| 1541 | } |
| 1542 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1543 | if (!fiber) { |
Russell King | fcf1f59 | 2019-12-17 13:39:21 +0000 | [diff] [blame] | 1544 | err = genphy_read_lpa(phydev); |
| 1545 | if (err < 0) |
| 1546 | return err; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1547 | |
Russell King | af00624 | 2019-12-17 13:39:06 +0000 | [diff] [blame] | 1548 | phy_resolve_aneg_pause(phydev); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1549 | } else { |
Russell King | fcf1f59 | 2019-12-17 13:39:21 +0000 | [diff] [blame] | 1550 | lpa = phy_read(phydev, MII_LPA); |
| 1551 | if (lpa < 0) |
| 1552 | return lpa; |
| 1553 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1554 | /* The fiber link is only 1000M capable */ |
Andrew Lunn | ab9cb72 | 2018-12-05 21:49:42 +0100 | [diff] [blame] | 1555 | fiber_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1556 | |
| 1557 | if (phydev->duplex == DUPLEX_FULL) { |
| 1558 | if (!(lpa & LPA_PAUSE_FIBER)) { |
| 1559 | phydev->pause = 0; |
| 1560 | phydev->asym_pause = 0; |
| 1561 | } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) { |
| 1562 | phydev->pause = 1; |
| 1563 | phydev->asym_pause = 1; |
| 1564 | } else { |
| 1565 | phydev->pause = 1; |
| 1566 | phydev->asym_pause = 0; |
| 1567 | } |
| 1568 | } |
| 1569 | } |
Russell King | fcf1f59 | 2019-12-17 13:39:21 +0000 | [diff] [blame] | 1570 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1571 | return 0; |
| 1572 | } |
| 1573 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1574 | /* marvell_read_status_page |
| 1575 | * |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 1576 | * Description: |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1577 | * Check the link, then figure out the current state |
| 1578 | * by comparing what we advertise with what the link partner |
| 1579 | * advertises. Start by checking the gigabit possibilities, |
| 1580 | * then move on to 10/100. |
| 1581 | */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1582 | static int marvell_read_status_page(struct phy_device *phydev, int page) |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1583 | { |
Russell King | d2004e2 | 2019-12-17 13:39:36 +0000 | [diff] [blame] | 1584 | int status; |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1585 | int fiber; |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1586 | int err; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1587 | |
Russell King | d2004e2 | 2019-12-17 13:39:36 +0000 | [diff] [blame] | 1588 | status = phy_read(phydev, MII_M1011_PHY_STATUS); |
| 1589 | if (status < 0) |
| 1590 | return status; |
| 1591 | |
| 1592 | /* Use the generic register for copper link status, |
| 1593 | * and the PHY status register for fiber link status. |
Andrew Lunn | 0c3439b | 2017-05-17 03:25:59 +0200 | [diff] [blame] | 1594 | */ |
Russell King | d2004e2 | 2019-12-17 13:39:36 +0000 | [diff] [blame] | 1595 | if (page == MII_MARVELL_FIBER_PAGE) { |
| 1596 | phydev->link = !!(status & MII_M1011_PHY_STATUS_LINK); |
| 1597 | } else { |
| 1598 | err = genphy_update_link(phydev); |
| 1599 | if (err) |
| 1600 | return err; |
| 1601 | } |
| 1602 | |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1603 | if (page == MII_MARVELL_FIBER_PAGE) |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1604 | fiber = 1; |
| 1605 | else |
| 1606 | fiber = 0; |
| 1607 | |
Russell King | 98f9283 | 2019-12-17 13:39:26 +0000 | [diff] [blame] | 1608 | linkmode_zero(phydev->lp_advertising); |
| 1609 | phydev->pause = 0; |
| 1610 | phydev->asym_pause = 0; |
Russell King | b82cf17 | 2020-02-27 09:44:49 +0000 | [diff] [blame] | 1611 | phydev->speed = SPEED_UNKNOWN; |
| 1612 | phydev->duplex = DUPLEX_UNKNOWN; |
Michael Walle | 4217a64 | 2021-02-09 17:38:52 +0100 | [diff] [blame] | 1613 | phydev->port = fiber ? PORT_FIBRE : PORT_TP; |
Russell King | 98f9283 | 2019-12-17 13:39:26 +0000 | [diff] [blame] | 1614 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1615 | if (phydev->autoneg == AUTONEG_ENABLE) |
Russell King | d2004e2 | 2019-12-17 13:39:36 +0000 | [diff] [blame] | 1616 | err = marvell_read_status_page_an(phydev, fiber, status); |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1617 | else |
Russell King | 98f9283 | 2019-12-17 13:39:26 +0000 | [diff] [blame] | 1618 | err = genphy_read_status_fixed(phydev); |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1619 | |
Andrew Lunn | e1dde8d | 2017-05-17 03:26:02 +0200 | [diff] [blame] | 1620 | return err; |
Alexandr Smirnov | be937f1 | 2008-03-19 00:37:24 +0300 | [diff] [blame] | 1621 | } |
| 1622 | |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1623 | /* marvell_read_status |
| 1624 | * |
| 1625 | * Some Marvell's phys have two modes: fiber and copper. |
| 1626 | * Both need status checked. |
| 1627 | * Description: |
| 1628 | * First, check the fiber link and status. |
| 1629 | * If the fiber link is down, check the copper link and status which |
| 1630 | * will be the default value if both link are down. |
| 1631 | */ |
| 1632 | static int marvell_read_status(struct phy_device *phydev) |
| 1633 | { |
| 1634 | int err; |
| 1635 | |
| 1636 | /* Check the fiber mode first */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 1637 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 1638 | phydev->supported) && |
Russell King | a13c0652 | 2017-01-10 23:13:45 +0000 | [diff] [blame] | 1639 | phydev->interface != PHY_INTERFACE_MODE_SGMII) { |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1640 | err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1641 | if (err < 0) |
| 1642 | goto error; |
| 1643 | |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1644 | err = marvell_read_status_page(phydev, MII_MARVELL_FIBER_PAGE); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1645 | if (err < 0) |
| 1646 | goto error; |
| 1647 | |
Andrew Lunn | 0c3439b | 2017-05-17 03:25:59 +0200 | [diff] [blame] | 1648 | /* If the fiber link is up, it is the selected and |
| 1649 | * used link. In this case, we need to stay in the |
| 1650 | * fiber page. Please to be careful about that, avoid |
| 1651 | * to restore Copper page in other functions which |
| 1652 | * could break the behaviour for some fiber phy like |
| 1653 | * 88E1512. |
| 1654 | */ |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1655 | if (phydev->link) |
| 1656 | return 0; |
| 1657 | |
| 1658 | /* If fiber link is down, check and save copper mode state */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1659 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1660 | if (err < 0) |
| 1661 | goto error; |
| 1662 | } |
| 1663 | |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1664 | return marvell_read_status_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1665 | |
| 1666 | error: |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1667 | marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 6cfb3bc | 2016-07-19 11:13:10 +0200 | [diff] [blame] | 1668 | return err; |
| 1669 | } |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1670 | |
| 1671 | /* marvell_suspend |
| 1672 | * |
| 1673 | * Some Marvell's phys have two modes: fiber and copper. |
| 1674 | * Both need to be suspended |
| 1675 | */ |
| 1676 | static int marvell_suspend(struct phy_device *phydev) |
| 1677 | { |
| 1678 | int err; |
| 1679 | |
| 1680 | /* Suspend the fiber mode first */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 1681 | if (!linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 1682 | phydev->supported)) { |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1683 | err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1684 | if (err < 0) |
| 1685 | goto error; |
| 1686 | |
| 1687 | /* With the page set, use the generic suspend */ |
| 1688 | err = genphy_suspend(phydev); |
| 1689 | if (err < 0) |
| 1690 | goto error; |
| 1691 | |
| 1692 | /* Then, the copper link */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1693 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1694 | if (err < 0) |
| 1695 | goto error; |
| 1696 | } |
| 1697 | |
| 1698 | /* With the page set, use the generic suspend */ |
| 1699 | return genphy_suspend(phydev); |
| 1700 | |
| 1701 | error: |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1702 | marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1703 | return err; |
| 1704 | } |
| 1705 | |
| 1706 | /* marvell_resume |
| 1707 | * |
| 1708 | * Some Marvell's phys have two modes: fiber and copper. |
| 1709 | * Both need to be resumed |
| 1710 | */ |
| 1711 | static int marvell_resume(struct phy_device *phydev) |
| 1712 | { |
| 1713 | int err; |
| 1714 | |
| 1715 | /* Resume the fiber mode first */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 1716 | if (!linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 1717 | phydev->supported)) { |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1718 | err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1719 | if (err < 0) |
| 1720 | goto error; |
| 1721 | |
| 1722 | /* With the page set, use the generic resume */ |
| 1723 | err = genphy_resume(phydev); |
| 1724 | if (err < 0) |
| 1725 | goto error; |
| 1726 | |
| 1727 | /* Then, the copper link */ |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1728 | err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1729 | if (err < 0) |
| 1730 | goto error; |
| 1731 | } |
| 1732 | |
| 1733 | /* With the page set, use the generic resume */ |
| 1734 | return genphy_resume(phydev); |
| 1735 | |
| 1736 | error: |
Andrew Lunn | 5229566 | 2017-05-25 21:42:08 +0200 | [diff] [blame] | 1737 | marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); |
Charles-Antoine Couret | 3758be3 | 2016-07-19 11:13:13 +0200 | [diff] [blame] | 1738 | return err; |
| 1739 | } |
| 1740 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1741 | static int marvell_aneg_done(struct phy_device *phydev) |
| 1742 | { |
| 1743 | int retval = phy_read(phydev, MII_M1011_PHY_STATUS); |
Andrew Lunn | e69d9ed | 2017-05-17 03:26:00 +0200 | [diff] [blame] | 1744 | |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 1745 | return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED); |
| 1746 | } |
| 1747 | |
Andrew Lunn | 23beb38 | 2017-05-17 03:26:04 +0200 | [diff] [blame] | 1748 | static void m88e1318_get_wol(struct phy_device *phydev, |
| 1749 | struct ethtool_wolinfo *wol) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1750 | { |
Jisheng Zhang | f4f9dcc | 2020-10-05 17:19:50 +0800 | [diff] [blame] | 1751 | int ret; |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1752 | |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1753 | wol->supported = WAKE_MAGIC | WAKE_PHY; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1754 | wol->wolopts = 0; |
| 1755 | |
Jisheng Zhang | f4f9dcc | 2020-10-05 17:19:50 +0800 | [diff] [blame] | 1756 | ret = phy_read_paged(phydev, MII_MARVELL_WOL_PAGE, |
| 1757 | MII_88E1318S_PHY_WOL_CTRL); |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1758 | if (ret < 0) |
| 1759 | return; |
| 1760 | |
| 1761 | if (ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1762 | wol->wolopts |= WAKE_MAGIC; |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1763 | |
| 1764 | if (ret & MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE) |
| 1765 | wol->wolopts |= WAKE_PHY; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
Andrew Lunn | 23beb38 | 2017-05-17 03:26:04 +0200 | [diff] [blame] | 1768 | static int m88e1318_set_wol(struct phy_device *phydev, |
| 1769 | struct ethtool_wolinfo *wol) |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1770 | { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1771 | int err = 0, oldpage; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1772 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1773 | oldpage = phy_save_page(phydev); |
| 1774 | if (oldpage < 0) |
| 1775 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1776 | |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1777 | if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) { |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1778 | /* Explicitly switch to page 0x00, just to be sure */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1779 | err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1780 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1781 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1782 | |
Jingju Hou | b6a930f | 2018-04-23 15:22:49 +0800 | [diff] [blame] | 1783 | /* If WOL event happened once, the LED[2] interrupt pin |
| 1784 | * will not be cleared unless we reading the interrupt status |
| 1785 | * register. If interrupts are in use, the normal interrupt |
| 1786 | * handling will clear the WOL event. Clear the WOL event |
| 1787 | * before enabling it if !phy_interrupt_is_valid() |
| 1788 | */ |
| 1789 | if (!phy_interrupt_is_valid(phydev)) |
Andrew Lunn | e0a7328 | 2019-01-11 00:15:21 +0100 | [diff] [blame] | 1790 | __phy_read(phydev, MII_M1011_IEVENT); |
Jingju Hou | b6a930f | 2018-04-23 15:22:49 +0800 | [diff] [blame] | 1791 | |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1792 | /* Enable the WOL interrupt */ |
Yejune Deng | 832913c | 2020-11-30 18:41:35 +0800 | [diff] [blame] | 1793 | err = __phy_set_bits(phydev, MII_88E1318S_PHY_CSIER, |
| 1794 | MII_88E1318S_PHY_CSIER_WOL_EIE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1795 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1796 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1797 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1798 | err = marvell_write_page(phydev, MII_MARVELL_LED_PAGE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1799 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1800 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1801 | |
| 1802 | /* Setup LED[2] as interrupt pin (active low) */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1803 | err = __phy_modify(phydev, MII_88E1318S_PHY_LED_TCR, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 1804 | MII_88E1318S_PHY_LED_TCR_FORCE_INT, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1805 | MII_88E1318S_PHY_LED_TCR_INTn_ENABLE | |
| 1806 | MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1807 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1808 | goto error; |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1809 | } |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1810 | |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1811 | if (wol->wolopts & WAKE_MAGIC) { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1812 | err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1813 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1814 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1815 | |
| 1816 | /* Store the device address for the magic packet */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1817 | err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1818 | ((phydev->attached_dev->dev_addr[5] << 8) | |
| 1819 | phydev->attached_dev->dev_addr[4])); |
| 1820 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1821 | goto error; |
| 1822 | err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1823 | ((phydev->attached_dev->dev_addr[3] << 8) | |
| 1824 | phydev->attached_dev->dev_addr[2])); |
| 1825 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1826 | goto error; |
| 1827 | err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0, |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1828 | ((phydev->attached_dev->dev_addr[1] << 8) | |
| 1829 | phydev->attached_dev->dev_addr[0])); |
| 1830 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1831 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1832 | |
| 1833 | /* Clear WOL status and enable magic packet matching */ |
Yejune Deng | 832913c | 2020-11-30 18:41:35 +0800 | [diff] [blame] | 1834 | err = __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL, |
| 1835 | MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS | |
| 1836 | MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1837 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1838 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1839 | } else { |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1840 | err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1841 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1842 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1843 | |
| 1844 | /* Clear WOL status and disable magic packet matching */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1845 | err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 1846 | MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1847 | MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1848 | if (err < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1849 | goto error; |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Song Yoong Siang | 6164659 | 2021-08-13 16:45:08 +0800 | [diff] [blame] | 1852 | if (wol->wolopts & WAKE_PHY) { |
| 1853 | err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); |
| 1854 | if (err < 0) |
| 1855 | goto error; |
| 1856 | |
| 1857 | /* Clear WOL status and enable link up event */ |
| 1858 | err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 0, |
| 1859 | MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS | |
| 1860 | MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE); |
| 1861 | if (err < 0) |
| 1862 | goto error; |
| 1863 | } else { |
| 1864 | err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); |
| 1865 | if (err < 0) |
| 1866 | goto error; |
| 1867 | |
| 1868 | /* Clear WOL status and disable link up event */ |
| 1869 | err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, |
| 1870 | MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE, |
| 1871 | MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS); |
| 1872 | if (err < 0) |
| 1873 | goto error; |
| 1874 | } |
| 1875 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1876 | error: |
| 1877 | return phy_restore_page(phydev, oldpage, err); |
Michael Stapelberg | 3871c38 | 2013-03-11 13:56:45 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1880 | static int marvell_get_sset_count(struct phy_device *phydev) |
| 1881 | { |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 1882 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 1883 | phydev->supported)) |
Charles-Antoine Couret | 2170fef | 2016-07-19 11:13:11 +0200 | [diff] [blame] | 1884 | return ARRAY_SIZE(marvell_hw_stats); |
| 1885 | else |
| 1886 | return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static void marvell_get_strings(struct phy_device *phydev, u8 *data) |
| 1890 | { |
Andrew Lunn | fdfdf86 | 2019-04-25 00:33:00 +0200 | [diff] [blame] | 1891 | int count = marvell_get_sset_count(phydev); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1892 | int i; |
| 1893 | |
Andrew Lunn | fdfdf86 | 2019-04-25 00:33:00 +0200 | [diff] [blame] | 1894 | for (i = 0; i < count; i++) { |
Florian Fainelli | 98409b2 | 2018-03-02 15:08:37 -0800 | [diff] [blame] | 1895 | strlcpy(data + i * ETH_GSTRING_LEN, |
| 1896 | marvell_hw_stats[i].string, ETH_GSTRING_LEN); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1900 | static u64 marvell_get_stat(struct phy_device *phydev, int i) |
| 1901 | { |
| 1902 | struct marvell_hw_stat stat = marvell_hw_stats[i]; |
| 1903 | struct marvell_priv *priv = phydev->priv; |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1904 | int val; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1905 | u64 ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1906 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 1907 | val = phy_read_paged(phydev, stat.page, stat.reg); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1908 | if (val < 0) { |
Jisheng Zhang | 6c3442f | 2018-04-27 16:18:58 +0800 | [diff] [blame] | 1909 | ret = U64_MAX; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1910 | } else { |
| 1911 | val = val & ((1 << stat.bits) - 1); |
| 1912 | priv->stats[i] += val; |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1913 | ret = priv->stats[i]; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1914 | } |
| 1915 | |
Andrew Lunn | 321b4d4 | 2016-02-20 00:35:29 +0100 | [diff] [blame] | 1916 | return ret; |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | static void marvell_get_stats(struct phy_device *phydev, |
| 1920 | struct ethtool_stats *stats, u64 *data) |
| 1921 | { |
Andrew Lunn | fdfdf86 | 2019-04-25 00:33:00 +0200 | [diff] [blame] | 1922 | int count = marvell_get_sset_count(phydev); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1923 | int i; |
| 1924 | |
Andrew Lunn | fdfdf86 | 2019-04-25 00:33:00 +0200 | [diff] [blame] | 1925 | for (i = 0; i < count; i++) |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 1926 | data[i] = marvell_get_stat(phydev, i); |
| 1927 | } |
| 1928 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1929 | static int marvell_vct5_wait_complete(struct phy_device *phydev) |
| 1930 | { |
| 1931 | int i; |
| 1932 | int val; |
| 1933 | |
| 1934 | for (i = 0; i < 32; i++) { |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 1935 | val = __phy_read(phydev, MII_VCT5_CTRL); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1936 | if (val < 0) |
| 1937 | return val; |
| 1938 | |
| 1939 | if (val & MII_VCT5_CTRL_COMPLETE) |
| 1940 | return 0; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | phydev_err(phydev, "Timeout while waiting for cable test to finish\n"); |
| 1944 | return -ETIMEDOUT; |
| 1945 | } |
| 1946 | |
| 1947 | static int marvell_vct5_amplitude(struct phy_device *phydev, int pair) |
| 1948 | { |
| 1949 | int amplitude; |
| 1950 | int val; |
| 1951 | int reg; |
| 1952 | |
| 1953 | reg = MII_VCT5_TX_RX_MDI0_COUPLING + pair; |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 1954 | val = __phy_read(phydev, reg); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1955 | |
| 1956 | if (val < 0) |
| 1957 | return 0; |
| 1958 | |
| 1959 | amplitude = (val & MII_VCT5_TX_RX_AMPLITUDE_MASK) >> |
| 1960 | MII_VCT5_TX_RX_AMPLITUDE_SHIFT; |
| 1961 | |
| 1962 | if (!(val & MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION)) |
| 1963 | amplitude = -amplitude; |
| 1964 | |
| 1965 | return 1000 * amplitude / 128; |
| 1966 | } |
| 1967 | |
| 1968 | static u32 marvell_vct5_distance2cm(int distance) |
| 1969 | { |
| 1970 | return distance * 805 / 10; |
| 1971 | } |
| 1972 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 1973 | static u32 marvell_vct5_cm2distance(int cm) |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1974 | { |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 1975 | return cm * 10 / 805; |
| 1976 | } |
| 1977 | |
| 1978 | static int marvell_vct5_amplitude_distance(struct phy_device *phydev, |
| 1979 | int distance, int pair) |
| 1980 | { |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1981 | u16 reg; |
| 1982 | int err; |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 1983 | int mV; |
| 1984 | int i; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1985 | |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 1986 | err = __phy_write(phydev, MII_VCT5_SAMPLE_POINT_DISTANCE, |
| 1987 | distance); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1988 | if (err) |
| 1989 | return err; |
| 1990 | |
| 1991 | reg = MII_VCT5_CTRL_ENABLE | |
| 1992 | MII_VCT5_CTRL_TX_SAME_CHANNEL | |
| 1993 | MII_VCT5_CTRL_SAMPLES_DEFAULT | |
| 1994 | MII_VCT5_CTRL_SAMPLE_POINT | |
| 1995 | MII_VCT5_CTRL_PEEK_HYST_DEFAULT; |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 1996 | err = __phy_write(phydev, MII_VCT5_CTRL, reg); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 1997 | if (err) |
| 1998 | return err; |
| 1999 | |
| 2000 | err = marvell_vct5_wait_complete(phydev); |
| 2001 | if (err) |
| 2002 | return err; |
| 2003 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2004 | for (i = 0; i < 4; i++) { |
| 2005 | if (pair != PHY_PAIR_ALL && i != pair) |
| 2006 | continue; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2007 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2008 | mV = marvell_vct5_amplitude(phydev, i); |
| 2009 | ethnl_cable_test_amplitude(phydev, i, mV); |
| 2010 | } |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2011 | |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | static int marvell_vct5_amplitude_graph(struct phy_device *phydev) |
| 2016 | { |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2017 | struct marvell_priv *priv = phydev->priv; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2018 | int distance; |
Andrew Lunn | db8668a | 2020-05-27 00:21:43 +0200 | [diff] [blame] | 2019 | u16 width; |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 2020 | int page; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2021 | int err; |
| 2022 | u16 reg; |
| 2023 | |
Andrew Lunn | db8668a | 2020-05-27 00:21:43 +0200 | [diff] [blame] | 2024 | if (priv->first <= TDR_SHORT_CABLE_LENGTH) |
| 2025 | width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS; |
| 2026 | else |
| 2027 | width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS; |
| 2028 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2029 | reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV | |
| 2030 | MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN | |
Andrew Lunn | db8668a | 2020-05-27 00:21:43 +0200 | [diff] [blame] | 2031 | MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width; |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2032 | |
| 2033 | err = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, |
| 2034 | MII_VCT5_TX_PULSE_CTRL, reg); |
| 2035 | if (err) |
| 2036 | return err; |
| 2037 | |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 2038 | /* Reading the TDR data is very MDIO heavy. We need to optimize |
| 2039 | * access to keep the time to a minimum. So lock the bus once, |
| 2040 | * and don't release it until complete. We can then avoid having |
| 2041 | * to change the page for every access, greatly speeding things |
| 2042 | * up. |
| 2043 | */ |
| 2044 | page = phy_select_page(phydev, MII_MARVELL_VCT5_PAGE); |
| 2045 | if (page < 0) |
Dan Carpenter | 830f5ce | 2020-05-29 13:02:07 +0300 | [diff] [blame] | 2046 | goto restore_page; |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 2047 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2048 | for (distance = priv->first; |
| 2049 | distance <= priv->last; |
| 2050 | distance += priv->step) { |
| 2051 | err = marvell_vct5_amplitude_distance(phydev, distance, |
| 2052 | priv->pair); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2053 | if (err) |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 2054 | goto restore_page; |
Andrew Lunn | db8668a | 2020-05-27 00:21:43 +0200 | [diff] [blame] | 2055 | |
| 2056 | if (distance > TDR_SHORT_CABLE_LENGTH && |
| 2057 | width == MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS) { |
| 2058 | width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS; |
| 2059 | reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV | |
| 2060 | MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN | |
| 2061 | MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width; |
| 2062 | err = __phy_write(phydev, MII_VCT5_TX_PULSE_CTRL, reg); |
| 2063 | if (err) |
| 2064 | goto restore_page; |
| 2065 | } |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2066 | } |
| 2067 | |
Andrew Lunn | a618e86d | 2020-05-27 00:21:42 +0200 | [diff] [blame] | 2068 | restore_page: |
| 2069 | return phy_restore_page(phydev, page, err); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | static int marvell_cable_test_start_common(struct phy_device *phydev) |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2073 | { |
| 2074 | int bmcr, bmsr, ret; |
| 2075 | |
| 2076 | /* If auto-negotiation is enabled, but not complete, the cable |
| 2077 | * test never completes. So disable auto-neg. |
| 2078 | */ |
| 2079 | bmcr = phy_read(phydev, MII_BMCR); |
| 2080 | if (bmcr < 0) |
| 2081 | return bmcr; |
| 2082 | |
| 2083 | bmsr = phy_read(phydev, MII_BMSR); |
| 2084 | |
| 2085 | if (bmsr < 0) |
| 2086 | return bmsr; |
| 2087 | |
| 2088 | if (bmcr & BMCR_ANENABLE) { |
Yejune Deng | 832913c | 2020-11-30 18:41:35 +0800 | [diff] [blame] | 2089 | ret = phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE); |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2090 | if (ret < 0) |
| 2091 | return ret; |
| 2092 | ret = genphy_soft_reset(phydev); |
| 2093 | if (ret < 0) |
| 2094 | return ret; |
| 2095 | } |
| 2096 | |
| 2097 | /* If the link is up, allow it some time to go down */ |
| 2098 | if (bmsr & BMSR_LSTATUS) |
| 2099 | msleep(1500); |
| 2100 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2101 | return 0; |
| 2102 | } |
| 2103 | |
| 2104 | static int marvell_vct7_cable_test_start(struct phy_device *phydev) |
| 2105 | { |
| 2106 | struct marvell_priv *priv = phydev->priv; |
| 2107 | int ret; |
| 2108 | |
| 2109 | ret = marvell_cable_test_start_common(phydev); |
| 2110 | if (ret) |
| 2111 | return ret; |
| 2112 | |
| 2113 | priv->cable_test_tdr = false; |
| 2114 | |
| 2115 | /* Reset the VCT5 API control to defaults, otherwise |
| 2116 | * VCT7 does not work correctly. |
| 2117 | */ |
| 2118 | ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, |
| 2119 | MII_VCT5_CTRL, |
| 2120 | MII_VCT5_CTRL_TX_SAME_CHANNEL | |
| 2121 | MII_VCT5_CTRL_SAMPLES_DEFAULT | |
| 2122 | MII_VCT5_CTRL_MODE_MAXIMUM_PEEK | |
| 2123 | MII_VCT5_CTRL_PEEK_HYST_DEFAULT); |
| 2124 | if (ret) |
| 2125 | return ret; |
| 2126 | |
| 2127 | ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, |
| 2128 | MII_VCT5_SAMPLE_POINT_DISTANCE, 0); |
| 2129 | if (ret) |
| 2130 | return ret; |
| 2131 | |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2132 | return phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE, |
| 2133 | MII_VCT7_CTRL, |
| 2134 | MII_VCT7_CTRL_RUN_NOW | |
| 2135 | MII_VCT7_CTRL_CENTIMETERS); |
| 2136 | } |
| 2137 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2138 | static int marvell_vct5_cable_test_tdr_start(struct phy_device *phydev, |
| 2139 | const struct phy_tdr_config *cfg) |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2140 | { |
| 2141 | struct marvell_priv *priv = phydev->priv; |
| 2142 | int ret; |
| 2143 | |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2144 | priv->cable_test_tdr = true; |
| 2145 | priv->first = marvell_vct5_cm2distance(cfg->first); |
| 2146 | priv->last = marvell_vct5_cm2distance(cfg->last); |
| 2147 | priv->step = marvell_vct5_cm2distance(cfg->step); |
| 2148 | priv->pair = cfg->pair; |
| 2149 | |
| 2150 | if (priv->first > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX) |
| 2151 | return -EINVAL; |
| 2152 | |
| 2153 | if (priv->last > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX) |
| 2154 | return -EINVAL; |
| 2155 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2156 | /* Disable VCT7 */ |
| 2157 | ret = phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE, |
| 2158 | MII_VCT7_CTRL, 0); |
| 2159 | if (ret) |
| 2160 | return ret; |
| 2161 | |
| 2162 | ret = marvell_cable_test_start_common(phydev); |
| 2163 | if (ret) |
| 2164 | return ret; |
| 2165 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2166 | ret = ethnl_cable_test_pulse(phydev, 1000); |
| 2167 | if (ret) |
| 2168 | return ret; |
| 2169 | |
| 2170 | return ethnl_cable_test_step(phydev, |
Andrew Lunn | f2bc8ad | 2020-05-27 00:21:41 +0200 | [diff] [blame] | 2171 | marvell_vct5_distance2cm(priv->first), |
| 2172 | marvell_vct5_distance2cm(priv->last), |
| 2173 | marvell_vct5_distance2cm(priv->step)); |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2174 | } |
| 2175 | |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2176 | static int marvell_vct7_distance_to_length(int distance, bool meter) |
| 2177 | { |
| 2178 | if (meter) |
| 2179 | distance *= 100; |
| 2180 | |
| 2181 | return distance; |
| 2182 | } |
| 2183 | |
| 2184 | static bool marvell_vct7_distance_valid(int result) |
| 2185 | { |
| 2186 | switch (result) { |
| 2187 | case MII_VCT7_RESULTS_OPEN: |
| 2188 | case MII_VCT7_RESULTS_SAME_SHORT: |
| 2189 | case MII_VCT7_RESULTS_CROSS_SHORT: |
| 2190 | return true; |
| 2191 | } |
| 2192 | return false; |
| 2193 | } |
| 2194 | |
| 2195 | static int marvell_vct7_report_length(struct phy_device *phydev, |
| 2196 | int pair, bool meter) |
| 2197 | { |
| 2198 | int length; |
| 2199 | int ret; |
| 2200 | |
| 2201 | ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, |
| 2202 | MII_VCT7_PAIR_0_DISTANCE + pair); |
| 2203 | if (ret < 0) |
| 2204 | return ret; |
| 2205 | |
| 2206 | length = marvell_vct7_distance_to_length(ret, meter); |
| 2207 | |
| 2208 | ethnl_cable_test_fault_length(phydev, pair, length); |
| 2209 | |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | static int marvell_vct7_cable_test_report_trans(int result) |
| 2214 | { |
| 2215 | switch (result) { |
| 2216 | case MII_VCT7_RESULTS_OK: |
| 2217 | return ETHTOOL_A_CABLE_RESULT_CODE_OK; |
| 2218 | case MII_VCT7_RESULTS_OPEN: |
| 2219 | return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; |
| 2220 | case MII_VCT7_RESULTS_SAME_SHORT: |
| 2221 | return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; |
| 2222 | case MII_VCT7_RESULTS_CROSS_SHORT: |
| 2223 | return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT; |
| 2224 | default: |
| 2225 | return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | static int marvell_vct7_cable_test_report(struct phy_device *phydev) |
| 2230 | { |
| 2231 | int pair0, pair1, pair2, pair3; |
| 2232 | bool meter; |
| 2233 | int ret; |
| 2234 | |
| 2235 | ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, |
| 2236 | MII_VCT7_RESULTS); |
| 2237 | if (ret < 0) |
| 2238 | return ret; |
| 2239 | |
| 2240 | pair3 = (ret & MII_VCT7_RESULTS_PAIR3_MASK) >> |
| 2241 | MII_VCT7_RESULTS_PAIR3_SHIFT; |
| 2242 | pair2 = (ret & MII_VCT7_RESULTS_PAIR2_MASK) >> |
| 2243 | MII_VCT7_RESULTS_PAIR2_SHIFT; |
| 2244 | pair1 = (ret & MII_VCT7_RESULTS_PAIR1_MASK) >> |
| 2245 | MII_VCT7_RESULTS_PAIR1_SHIFT; |
| 2246 | pair0 = (ret & MII_VCT7_RESULTS_PAIR0_MASK) >> |
| 2247 | MII_VCT7_RESULTS_PAIR0_SHIFT; |
| 2248 | |
| 2249 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, |
| 2250 | marvell_vct7_cable_test_report_trans(pair0)); |
| 2251 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, |
| 2252 | marvell_vct7_cable_test_report_trans(pair1)); |
| 2253 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, |
| 2254 | marvell_vct7_cable_test_report_trans(pair2)); |
| 2255 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, |
| 2256 | marvell_vct7_cable_test_report_trans(pair3)); |
| 2257 | |
| 2258 | ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, MII_VCT7_CTRL); |
| 2259 | if (ret < 0) |
| 2260 | return ret; |
| 2261 | |
| 2262 | meter = ret & MII_VCT7_CTRL_METERS; |
| 2263 | |
| 2264 | if (marvell_vct7_distance_valid(pair0)) |
| 2265 | marvell_vct7_report_length(phydev, 0, meter); |
| 2266 | if (marvell_vct7_distance_valid(pair1)) |
| 2267 | marvell_vct7_report_length(phydev, 1, meter); |
| 2268 | if (marvell_vct7_distance_valid(pair2)) |
| 2269 | marvell_vct7_report_length(phydev, 2, meter); |
| 2270 | if (marvell_vct7_distance_valid(pair3)) |
| 2271 | marvell_vct7_report_length(phydev, 3, meter); |
| 2272 | |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static int marvell_vct7_cable_test_get_status(struct phy_device *phydev, |
| 2277 | bool *finished) |
| 2278 | { |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2279 | struct marvell_priv *priv = phydev->priv; |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2280 | int ret; |
| 2281 | |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 2282 | if (priv->cable_test_tdr) { |
| 2283 | ret = marvell_vct5_amplitude_graph(phydev); |
| 2284 | *finished = true; |
| 2285 | return ret; |
| 2286 | } |
| 2287 | |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 2288 | *finished = false; |
| 2289 | |
| 2290 | ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, |
| 2291 | MII_VCT7_CTRL); |
| 2292 | |
| 2293 | if (ret < 0) |
| 2294 | return ret; |
| 2295 | |
| 2296 | if (!(ret & MII_VCT7_CTRL_IN_PROGRESS)) { |
| 2297 | *finished = true; |
| 2298 | |
| 2299 | return marvell_vct7_cable_test_report(phydev); |
| 2300 | } |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2305 | #ifdef CONFIG_HWMON |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2306 | struct marvell_hwmon_ops { |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 2307 | int (*config)(struct phy_device *phydev); |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2308 | int (*get_temp)(struct phy_device *phydev, long *temp); |
| 2309 | int (*get_temp_critical)(struct phy_device *phydev, long *temp); |
| 2310 | int (*set_temp_critical)(struct phy_device *phydev, long temp); |
| 2311 | int (*get_temp_alarm)(struct phy_device *phydev, long *alarm); |
| 2312 | }; |
| 2313 | |
| 2314 | static const struct marvell_hwmon_ops * |
| 2315 | to_marvell_hwmon_ops(const struct phy_device *phydev) |
| 2316 | { |
| 2317 | return phydev->drv->driver_data; |
| 2318 | } |
| 2319 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2320 | static int m88e1121_get_temp(struct phy_device *phydev, long *temp) |
| 2321 | { |
Andrew Lunn | 975b388 | 2017-05-25 21:42:06 +0200 | [diff] [blame] | 2322 | int oldpage; |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2323 | int ret = 0; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2324 | int val; |
| 2325 | |
| 2326 | *temp = 0; |
| 2327 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2328 | oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE); |
| 2329 | if (oldpage < 0) |
| 2330 | goto error; |
Andrew Lunn | 975b388 | 2017-05-25 21:42:06 +0200 | [diff] [blame] | 2331 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2332 | /* Enable temperature sensor */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2333 | ret = __phy_read(phydev, MII_88E1121_MISC_TEST); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2334 | if (ret < 0) |
| 2335 | goto error; |
| 2336 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2337 | ret = __phy_write(phydev, MII_88E1121_MISC_TEST, |
| 2338 | ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2339 | if (ret < 0) |
| 2340 | goto error; |
| 2341 | |
| 2342 | /* Wait for temperature to stabilize */ |
| 2343 | usleep_range(10000, 12000); |
| 2344 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2345 | val = __phy_read(phydev, MII_88E1121_MISC_TEST); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2346 | if (val < 0) { |
| 2347 | ret = val; |
| 2348 | goto error; |
| 2349 | } |
| 2350 | |
| 2351 | /* Disable temperature sensor */ |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2352 | ret = __phy_write(phydev, MII_88E1121_MISC_TEST, |
| 2353 | ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2354 | if (ret < 0) |
| 2355 | goto error; |
| 2356 | |
| 2357 | *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000; |
| 2358 | |
| 2359 | error: |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2360 | return phy_restore_page(phydev, oldpage, ret); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2361 | } |
| 2362 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2363 | static int m88e1510_get_temp(struct phy_device *phydev, long *temp) |
| 2364 | { |
| 2365 | int ret; |
| 2366 | |
| 2367 | *temp = 0; |
| 2368 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2369 | ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2370 | MII_88E1510_TEMP_SENSOR); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2371 | if (ret < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2372 | return ret; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2373 | |
| 2374 | *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000; |
| 2375 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2376 | return 0; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2377 | } |
| 2378 | |
Colin Ian King | f0a4581 | 2017-06-02 15:13:34 +0100 | [diff] [blame] | 2379 | static int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp) |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2380 | { |
| 2381 | int ret; |
| 2382 | |
| 2383 | *temp = 0; |
| 2384 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2385 | ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2386 | MII_88E1121_MISC_TEST); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2387 | if (ret < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2388 | return ret; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2389 | |
| 2390 | *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >> |
| 2391 | MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25; |
| 2392 | /* convert to mC */ |
| 2393 | *temp *= 1000; |
| 2394 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2395 | return 0; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2396 | } |
| 2397 | |
Colin Ian King | f0a4581 | 2017-06-02 15:13:34 +0100 | [diff] [blame] | 2398 | static int m88e1510_set_temp_critical(struct phy_device *phydev, long temp) |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2399 | { |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2400 | temp = temp / 1000; |
| 2401 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2402 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2403 | return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2404 | MII_88E1121_MISC_TEST, |
| 2405 | MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK, |
| 2406 | temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2407 | } |
| 2408 | |
Colin Ian King | f0a4581 | 2017-06-02 15:13:34 +0100 | [diff] [blame] | 2409 | static int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm) |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2410 | { |
| 2411 | int ret; |
| 2412 | |
| 2413 | *alarm = false; |
| 2414 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2415 | ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2416 | MII_88E1121_MISC_TEST); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2417 | if (ret < 0) |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2418 | return ret; |
| 2419 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2420 | *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ); |
| 2421 | |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2422 | return 0; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2425 | static int m88e6390_get_temp(struct phy_device *phydev, long *temp) |
| 2426 | { |
| 2427 | int sum = 0; |
| 2428 | int oldpage; |
| 2429 | int ret = 0; |
| 2430 | int i; |
| 2431 | |
| 2432 | *temp = 0; |
| 2433 | |
| 2434 | oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE); |
| 2435 | if (oldpage < 0) |
| 2436 | goto error; |
| 2437 | |
| 2438 | /* Enable temperature sensor */ |
| 2439 | ret = __phy_read(phydev, MII_88E6390_MISC_TEST); |
| 2440 | if (ret < 0) |
| 2441 | goto error; |
| 2442 | |
Marek Behún | 0021817 | 2021-04-20 09:54:01 +0200 | [diff] [blame] | 2443 | ret &= ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; |
Marek Behún | 4f920c29 | 2021-04-20 09:54:00 +0200 | [diff] [blame] | 2444 | ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S; |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2445 | |
| 2446 | ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret); |
| 2447 | if (ret < 0) |
| 2448 | goto error; |
| 2449 | |
| 2450 | /* Wait for temperature to stabilize */ |
| 2451 | usleep_range(10000, 12000); |
| 2452 | |
| 2453 | /* Reading the temperature sense has an errata. You need to read |
| 2454 | * a number of times and take an average. |
| 2455 | */ |
| 2456 | for (i = 0; i < MII_88E6390_TEMP_SENSOR_SAMPLES; i++) { |
| 2457 | ret = __phy_read(phydev, MII_88E6390_TEMP_SENSOR); |
| 2458 | if (ret < 0) |
| 2459 | goto error; |
| 2460 | sum += ret & MII_88E6390_TEMP_SENSOR_MASK; |
| 2461 | } |
| 2462 | |
| 2463 | sum /= MII_88E6390_TEMP_SENSOR_SAMPLES; |
| 2464 | *temp = (sum - 75) * 1000; |
| 2465 | |
| 2466 | /* Disable temperature sensor */ |
| 2467 | ret = __phy_read(phydev, MII_88E6390_MISC_TEST); |
| 2468 | if (ret < 0) |
| 2469 | goto error; |
| 2470 | |
Marek Behún | 4f920c29 | 2021-04-20 09:54:00 +0200 | [diff] [blame] | 2471 | ret = ret & ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; |
| 2472 | ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE; |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2473 | |
| 2474 | ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret); |
| 2475 | |
| 2476 | error: |
| 2477 | phy_restore_page(phydev, oldpage, ret); |
| 2478 | |
| 2479 | return ret; |
| 2480 | } |
| 2481 | |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 2482 | static int m88e6393_get_temp(struct phy_device *phydev, long *temp) |
| 2483 | { |
| 2484 | int err; |
| 2485 | |
| 2486 | err = m88e1510_get_temp(phydev, temp); |
| 2487 | |
| 2488 | /* 88E1510 measures T + 25, while the PHY on 88E6393X switch |
| 2489 | * T + 75, so we have to subtract another 50 |
| 2490 | */ |
| 2491 | *temp -= 50000; |
| 2492 | |
| 2493 | return err; |
| 2494 | } |
| 2495 | |
| 2496 | static int m88e6393_get_temp_critical(struct phy_device *phydev, long *temp) |
| 2497 | { |
| 2498 | int ret; |
| 2499 | |
| 2500 | *temp = 0; |
| 2501 | |
| 2502 | ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2503 | MII_88E6390_TEMP_SENSOR); |
| 2504 | if (ret < 0) |
| 2505 | return ret; |
| 2506 | |
| 2507 | *temp = (((ret & MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK) >> |
| 2508 | MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT) - 75) * 1000; |
| 2509 | |
| 2510 | return 0; |
| 2511 | } |
| 2512 | |
| 2513 | static int m88e6393_set_temp_critical(struct phy_device *phydev, long temp) |
| 2514 | { |
| 2515 | temp = (temp / 1000) + 75; |
| 2516 | |
| 2517 | return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2518 | MII_88E6390_TEMP_SENSOR, |
| 2519 | MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK, |
| 2520 | temp << MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT); |
| 2521 | } |
| 2522 | |
| 2523 | static int m88e6393_hwmon_config(struct phy_device *phydev) |
| 2524 | { |
| 2525 | int err; |
| 2526 | |
| 2527 | err = m88e6393_set_temp_critical(phydev, 100000); |
| 2528 | if (err) |
| 2529 | return err; |
| 2530 | |
| 2531 | return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, |
| 2532 | MII_88E6390_MISC_TEST, |
| 2533 | MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK | |
| 2534 | MII_88E6393_MISC_TEST_SAMPLES_MASK | |
| 2535 | MII_88E6393_MISC_TEST_RATE_MASK, |
| 2536 | MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE | |
| 2537 | MII_88E6393_MISC_TEST_SAMPLES_2048 | |
| 2538 | MII_88E6393_MISC_TEST_RATE_2_3MS); |
| 2539 | } |
| 2540 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2541 | static int marvell_hwmon_read(struct device *dev, enum hwmon_sensor_types type, |
| 2542 | u32 attr, int channel, long *temp) |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2543 | { |
| 2544 | struct phy_device *phydev = dev_get_drvdata(dev); |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2545 | const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); |
| 2546 | int err = -EOPNOTSUPP; |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2547 | |
| 2548 | switch (attr) { |
| 2549 | case hwmon_temp_input: |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2550 | if (ops->get_temp) |
| 2551 | err = ops->get_temp(phydev, temp); |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2552 | break; |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2553 | case hwmon_temp_crit: |
| 2554 | if (ops->get_temp_critical) |
| 2555 | err = ops->get_temp_critical(phydev, temp); |
| 2556 | break; |
| 2557 | case hwmon_temp_max_alarm: |
| 2558 | if (ops->get_temp_alarm) |
| 2559 | err = ops->get_temp_alarm(phydev, temp); |
| 2560 | break; |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | return err; |
| 2564 | } |
| 2565 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2566 | static int marvell_hwmon_write(struct device *dev, enum hwmon_sensor_types type, |
| 2567 | u32 attr, int channel, long temp) |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2568 | { |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2569 | struct phy_device *phydev = dev_get_drvdata(dev); |
| 2570 | const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); |
| 2571 | int err = -EOPNOTSUPP; |
| 2572 | |
| 2573 | switch (attr) { |
| 2574 | case hwmon_temp_crit: |
| 2575 | if (ops->set_temp_critical) |
| 2576 | err = ops->set_temp_critical(phydev, temp); |
| 2577 | break; |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | return err; |
| 2581 | } |
| 2582 | |
| 2583 | static umode_t marvell_hwmon_is_visible(const void *data, |
| 2584 | enum hwmon_sensor_types type, |
| 2585 | u32 attr, int channel) |
| 2586 | { |
| 2587 | const struct phy_device *phydev = data; |
| 2588 | const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); |
| 2589 | |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2590 | if (type != hwmon_temp) |
| 2591 | return 0; |
| 2592 | |
| 2593 | switch (attr) { |
| 2594 | case hwmon_temp_input: |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2595 | return ops->get_temp ? 0444 : 0; |
| 2596 | case hwmon_temp_max_alarm: |
| 2597 | return ops->get_temp_alarm ? 0444 : 0; |
| 2598 | case hwmon_temp_crit: |
| 2599 | return (ops->get_temp_critical ? 0444 : 0) | |
| 2600 | (ops->set_temp_critical ? 0200 : 0); |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2601 | default: |
| 2602 | return 0; |
| 2603 | } |
| 2604 | } |
| 2605 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2606 | static u32 marvell_hwmon_chip_config[] = { |
| 2607 | HWMON_C_REGISTER_TZ, |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2608 | 0 |
| 2609 | }; |
| 2610 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2611 | static const struct hwmon_channel_info marvell_hwmon_chip = { |
| 2612 | .type = hwmon_chip, |
| 2613 | .config = marvell_hwmon_chip_config, |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2614 | }; |
| 2615 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2616 | /* we can define HWMON_T_CRIT and HWMON_T_MAX_ALARM even though these are not |
| 2617 | * defined for all PHYs, because the hwmon code checks whether the attributes |
| 2618 | * exists via the .is_visible method |
| 2619 | */ |
| 2620 | static u32 marvell_hwmon_temp_config[] = { |
| 2621 | HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM, |
| 2622 | 0 |
| 2623 | }; |
| 2624 | |
| 2625 | static const struct hwmon_channel_info marvell_hwmon_temp = { |
| 2626 | .type = hwmon_temp, |
| 2627 | .config = marvell_hwmon_temp_config, |
| 2628 | }; |
| 2629 | |
| 2630 | static const struct hwmon_channel_info *marvell_hwmon_info[] = { |
| 2631 | &marvell_hwmon_chip, |
| 2632 | &marvell_hwmon_temp, |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2633 | NULL |
| 2634 | }; |
| 2635 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2636 | static const struct hwmon_ops marvell_hwmon_hwmon_ops = { |
| 2637 | .is_visible = marvell_hwmon_is_visible, |
| 2638 | .read = marvell_hwmon_read, |
| 2639 | .write = marvell_hwmon_write, |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2640 | }; |
| 2641 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2642 | static const struct hwmon_chip_info marvell_hwmon_chip_info = { |
| 2643 | .ops = &marvell_hwmon_hwmon_ops, |
| 2644 | .info = marvell_hwmon_info, |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2645 | }; |
| 2646 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2647 | static int marvell_hwmon_name(struct phy_device *phydev) |
| 2648 | { |
| 2649 | struct marvell_priv *priv = phydev->priv; |
| 2650 | struct device *dev = &phydev->mdio.dev; |
| 2651 | const char *devname = dev_name(dev); |
| 2652 | size_t len = strlen(devname); |
| 2653 | int i, j; |
| 2654 | |
| 2655 | priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL); |
| 2656 | if (!priv->hwmon_name) |
| 2657 | return -ENOMEM; |
| 2658 | |
| 2659 | for (i = j = 0; i < len && devname[i]; i++) { |
| 2660 | if (isalnum(devname[i])) |
| 2661 | priv->hwmon_name[j++] = devname[i]; |
| 2662 | } |
| 2663 | |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2667 | static int marvell_hwmon_probe(struct phy_device *phydev) |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2668 | { |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2669 | const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2670 | struct marvell_priv *priv = phydev->priv; |
| 2671 | struct device *dev = &phydev->mdio.dev; |
| 2672 | int err; |
| 2673 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2674 | if (!ops) |
| 2675 | return 0; |
| 2676 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2677 | err = marvell_hwmon_name(phydev); |
| 2678 | if (err) |
| 2679 | return err; |
| 2680 | |
| 2681 | priv->hwmon_dev = devm_hwmon_device_register_with_info( |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2682 | dev, priv->hwmon_name, phydev, &marvell_hwmon_chip_info, NULL); |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 2683 | if (IS_ERR(priv->hwmon_dev)) |
| 2684 | return PTR_ERR(priv->hwmon_dev); |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2685 | |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 2686 | if (ops->config) |
| 2687 | err = ops->config(phydev); |
| 2688 | |
| 2689 | return err; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2690 | } |
| 2691 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2692 | static const struct marvell_hwmon_ops m88e1121_hwmon_ops = { |
| 2693 | .get_temp = m88e1121_get_temp, |
| 2694 | }; |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2695 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2696 | static const struct marvell_hwmon_ops m88e1510_hwmon_ops = { |
| 2697 | .get_temp = m88e1510_get_temp, |
| 2698 | .get_temp_critical = m88e1510_get_temp_critical, |
| 2699 | .set_temp_critical = m88e1510_set_temp_critical, |
| 2700 | .get_temp_alarm = m88e1510_get_temp_alarm, |
| 2701 | }; |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2702 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2703 | static const struct marvell_hwmon_ops m88e6390_hwmon_ops = { |
| 2704 | .get_temp = m88e6390_get_temp, |
| 2705 | }; |
| 2706 | |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 2707 | static const struct marvell_hwmon_ops m88e6393_hwmon_ops = { |
| 2708 | .config = m88e6393_hwmon_config, |
| 2709 | .get_temp = m88e6393_get_temp, |
| 2710 | .get_temp_critical = m88e6393_get_temp_critical, |
| 2711 | .set_temp_critical = m88e6393_set_temp_critical, |
| 2712 | .get_temp_alarm = m88e1510_get_temp_alarm, |
| 2713 | }; |
| 2714 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2715 | #define DEF_MARVELL_HWMON_OPS(s) (&(s)) |
| 2716 | |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2717 | #else |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2718 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2719 | #define DEF_MARVELL_HWMON_OPS(s) NULL |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2720 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2721 | static int marvell_hwmon_probe(struct phy_device *phydev) |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2722 | { |
| 2723 | return 0; |
| 2724 | } |
Andrew Lunn | 0b04680 | 2017-01-20 01:37:49 +0100 | [diff] [blame] | 2725 | #endif |
| 2726 | |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2727 | static int marvell_probe(struct phy_device *phydev) |
| 2728 | { |
| 2729 | struct marvell_priv *priv; |
| 2730 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 2731 | priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2732 | if (!priv) |
| 2733 | return -ENOMEM; |
| 2734 | |
| 2735 | phydev->priv = priv; |
| 2736 | |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2737 | return marvell_hwmon_probe(phydev); |
Andrew Lunn | fee2d54 | 2018-01-09 22:42:09 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 2740 | static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) |
| 2741 | { |
| 2742 | struct phy_device *phydev = upstream; |
| 2743 | phy_interface_t interface; |
| 2744 | struct device *dev; |
| 2745 | int oldpage; |
| 2746 | int ret = 0; |
| 2747 | u16 mode; |
| 2748 | |
| 2749 | __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, }; |
| 2750 | |
| 2751 | dev = &phydev->mdio.dev; |
| 2752 | |
| 2753 | sfp_parse_support(phydev->sfp_bus, id, supported); |
| 2754 | interface = sfp_select_interface(phydev->sfp_bus, supported); |
| 2755 | |
| 2756 | dev_info(dev, "%s SFP module inserted\n", phy_modes(interface)); |
| 2757 | |
| 2758 | switch (interface) { |
| 2759 | case PHY_INTERFACE_MODE_1000BASEX: |
| 2760 | mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X; |
| 2761 | |
| 2762 | break; |
| 2763 | case PHY_INTERFACE_MODE_100BASEX: |
| 2764 | mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX; |
| 2765 | |
| 2766 | break; |
| 2767 | case PHY_INTERFACE_MODE_SGMII: |
| 2768 | mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII; |
| 2769 | |
| 2770 | break; |
| 2771 | default: |
| 2772 | dev_err(dev, "Incompatible SFP module inserted\n"); |
| 2773 | |
| 2774 | return -EINVAL; |
| 2775 | } |
| 2776 | |
| 2777 | oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE); |
| 2778 | if (oldpage < 0) |
| 2779 | goto error; |
| 2780 | |
| 2781 | ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, |
| 2782 | MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, mode); |
| 2783 | if (ret < 0) |
| 2784 | goto error; |
| 2785 | |
| 2786 | ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, |
| 2787 | MII_88E1510_GEN_CTRL_REG_1_RESET); |
| 2788 | |
| 2789 | error: |
| 2790 | return phy_restore_page(phydev, oldpage, ret); |
| 2791 | } |
| 2792 | |
| 2793 | static void m88e1510_sfp_remove(void *upstream) |
| 2794 | { |
| 2795 | struct phy_device *phydev = upstream; |
| 2796 | int oldpage; |
| 2797 | int ret = 0; |
| 2798 | |
| 2799 | oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE); |
| 2800 | if (oldpage < 0) |
| 2801 | goto error; |
| 2802 | |
| 2803 | ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, |
| 2804 | MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, |
| 2805 | MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII); |
| 2806 | if (ret < 0) |
| 2807 | goto error; |
| 2808 | |
| 2809 | ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, |
| 2810 | MII_88E1510_GEN_CTRL_REG_1_RESET); |
| 2811 | |
| 2812 | error: |
| 2813 | phy_restore_page(phydev, oldpage, ret); |
| 2814 | } |
| 2815 | |
| 2816 | static const struct sfp_upstream_ops m88e1510_sfp_ops = { |
| 2817 | .module_insert = m88e1510_sfp_insert, |
| 2818 | .module_remove = m88e1510_sfp_remove, |
| 2819 | .attach = phy_sfp_attach, |
| 2820 | .detach = phy_sfp_detach, |
| 2821 | }; |
| 2822 | |
| 2823 | static int m88e1510_probe(struct phy_device *phydev) |
| 2824 | { |
| 2825 | int err; |
| 2826 | |
| 2827 | err = marvell_probe(phydev); |
| 2828 | if (err) |
| 2829 | return err; |
| 2830 | |
| 2831 | return phy_sfp_probe(phydev, &m88e1510_sfp_ops); |
| 2832 | } |
| 2833 | |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2834 | static struct phy_driver marvell_drivers[] = { |
| 2835 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2836 | .phy_id = MARVELL_PHY_ID_88E1101, |
| 2837 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2838 | .name = "Marvell 88E1101", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2839 | /* PHY_GBIT_FEATURES */ |
Arnd Bergmann | 1870241 | 2017-01-23 13:18:41 +0100 | [diff] [blame] | 2840 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2841 | .config_init = marvell_config_init, |
| 2842 | .config_aneg = m88e1101_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2843 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2844 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2845 | .resume = genphy_resume, |
| 2846 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2847 | .read_page = marvell_read_page, |
| 2848 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2849 | .get_sset_count = marvell_get_sset_count, |
| 2850 | .get_strings = marvell_get_strings, |
| 2851 | .get_stats = marvell_get_stats, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2852 | }, |
| 2853 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2854 | .phy_id = MARVELL_PHY_ID_88E1112, |
| 2855 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 2856 | .name = "Marvell 88E1112", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2857 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2858 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 2859 | .config_init = m88e1112_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2860 | .config_aneg = marvell_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2861 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2862 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2863 | .resume = genphy_resume, |
| 2864 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2865 | .read_page = marvell_read_page, |
| 2866 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2867 | .get_sset_count = marvell_get_sset_count, |
| 2868 | .get_strings = marvell_get_strings, |
| 2869 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 262caf4 | 2019-10-28 20:54:17 +0100 | [diff] [blame] | 2870 | .get_tunable = m88e1011_get_tunable, |
| 2871 | .set_tunable = m88e1011_set_tunable, |
Olof Johansson | 85cfb53 | 2007-07-03 16:24:32 -0500 | [diff] [blame] | 2872 | }, |
| 2873 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2874 | .phy_id = MARVELL_PHY_ID_88E1111, |
| 2875 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2876 | .name = "Marvell 88E1111", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2877 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2878 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 2879 | .config_init = m88e1111gbe_config_init, |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 2880 | .config_aneg = m88e1111_config_aneg, |
| 2881 | .read_status = marvell_read_status, |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 2882 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2883 | .handle_interrupt = marvell_handle_interrupt, |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 2884 | .resume = genphy_resume, |
| 2885 | .suspend = genphy_suspend, |
| 2886 | .read_page = marvell_read_page, |
| 2887 | .write_page = marvell_write_page, |
| 2888 | .get_sset_count = marvell_get_sset_count, |
| 2889 | .get_strings = marvell_get_strings, |
| 2890 | .get_stats = marvell_get_stats, |
| 2891 | .get_tunable = m88e1111_get_tunable, |
| 2892 | .set_tunable = m88e1111_set_tunable, |
| 2893 | }, |
| 2894 | { |
| 2895 | .phy_id = MARVELL_PHY_ID_88E1111_FINISAR, |
| 2896 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2897 | .name = "Marvell 88E1111 (Finisar)", |
| 2898 | /* PHY_GBIT_FEATURES */ |
| 2899 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 2900 | .config_init = m88e1111gbe_config_init, |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 2901 | .config_aneg = m88e1111_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2902 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2903 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2904 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2905 | .resume = genphy_resume, |
| 2906 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2907 | .read_page = marvell_read_page, |
| 2908 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2909 | .get_sset_count = marvell_get_sset_count, |
| 2910 | .get_strings = marvell_get_strings, |
| 2911 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 5c6bc51 | 2019-10-28 20:53:25 +0100 | [diff] [blame] | 2912 | .get_tunable = m88e1111_get_tunable, |
| 2913 | .set_tunable = m88e1111_set_tunable, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2914 | }, |
| 2915 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2916 | .phy_id = MARVELL_PHY_ID_88E1118, |
| 2917 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 2918 | .name = "Marvell 88E1118", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2919 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2920 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2921 | .config_init = m88e1118_config_init, |
| 2922 | .config_aneg = m88e1118_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2923 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2924 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2925 | .resume = genphy_resume, |
| 2926 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2927 | .read_page = marvell_read_page, |
| 2928 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2929 | .get_sset_count = marvell_get_sset_count, |
| 2930 | .get_strings = marvell_get_strings, |
| 2931 | .get_stats = marvell_get_stats, |
Ron Madrid | 605f196 | 2008-11-06 09:05:26 +0000 | [diff] [blame] | 2932 | }, |
| 2933 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2934 | .phy_id = MARVELL_PHY_ID_88E1121R, |
| 2935 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 2936 | .name = "Marvell 88E1121R", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2937 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1121_hwmon_ops), |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2938 | /* PHY_GBIT_FEATURES */ |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 2939 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 2940 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2941 | .config_aneg = m88e1121_config_aneg, |
| 2942 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2943 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2944 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2945 | .resume = genphy_resume, |
| 2946 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2947 | .read_page = marvell_read_page, |
| 2948 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2949 | .get_sset_count = marvell_get_sset_count, |
| 2950 | .get_strings = marvell_get_strings, |
| 2951 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 911af5e | 2019-10-28 20:52:55 +0100 | [diff] [blame] | 2952 | .get_tunable = m88e1011_get_tunable, |
| 2953 | .set_tunable = m88e1011_set_tunable, |
Sergei Poselenov | 140bc92 | 2009-04-07 02:01:41 +0000 | [diff] [blame] | 2954 | }, |
| 2955 | { |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 2956 | .phy_id = MARVELL_PHY_ID_88E1318S, |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 2957 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Cyril Chemparathy | 337ac9d | 2010-10-29 13:50:25 -0700 | [diff] [blame] | 2958 | .name = "Marvell 88E1318S", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2959 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2960 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2961 | .config_init = m88e1318_config_init, |
| 2962 | .config_aneg = m88e1318_config_aneg, |
| 2963 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2964 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2965 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2966 | .get_wol = m88e1318_get_wol, |
| 2967 | .set_wol = m88e1318_set_wol, |
| 2968 | .resume = genphy_resume, |
| 2969 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2970 | .read_page = marvell_read_page, |
| 2971 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2972 | .get_sset_count = marvell_get_sset_count, |
| 2973 | .get_strings = marvell_get_strings, |
| 2974 | .get_stats = marvell_get_stats, |
Cyril Chemparathy | 3ff1c25 | 2010-08-03 19:36:06 -0700 | [diff] [blame] | 2975 | }, |
| 2976 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 2977 | .phy_id = MARVELL_PHY_ID_88E1145, |
| 2978 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | e547923 | 2007-07-03 16:23:46 -0500 | [diff] [blame] | 2979 | .name = "Marvell 88E1145", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 2980 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2981 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2982 | .config_init = m88e1145_config_init, |
| 2983 | .config_aneg = m88e1101_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2984 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 2985 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 2986 | .resume = genphy_resume, |
| 2987 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 2988 | .read_page = marvell_read_page, |
| 2989 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 2990 | .get_sset_count = marvell_get_sset_count, |
| 2991 | .get_strings = marvell_get_strings, |
| 2992 | .get_stats = marvell_get_stats, |
Heiner Kallweit | a319fb5 | 2019-10-29 20:25:26 +0100 | [diff] [blame] | 2993 | .get_tunable = m88e1111_get_tunable, |
| 2994 | .set_tunable = m88e1111_set_tunable, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 2995 | }, |
| 2996 | { |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 2997 | .phy_id = MARVELL_PHY_ID_88E1149R, |
| 2998 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 2999 | .name = "Marvell 88E1149R", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3000 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3001 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3002 | .config_init = m88e1149_config_init, |
| 3003 | .config_aneg = m88e1118_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3004 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3005 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3006 | .resume = genphy_resume, |
| 3007 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3008 | .read_page = marvell_read_page, |
| 3009 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3010 | .get_sset_count = marvell_get_sset_count, |
| 3011 | .get_strings = marvell_get_strings, |
| 3012 | .get_stats = marvell_get_stats, |
David Daney | 9060073 | 2010-11-19 11:58:53 +0000 | [diff] [blame] | 3013 | }, |
| 3014 | { |
Benjamin Herrenschmidt | 2f495c3 | 2010-06-21 13:20:46 +1000 | [diff] [blame] | 3015 | .phy_id = MARVELL_PHY_ID_88E1240, |
| 3016 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 3017 | .name = "Marvell 88E1240", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3018 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3019 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3020 | .config_init = m88e1112_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3021 | .config_aneg = marvell_config_aneg, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3022 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3023 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3024 | .resume = genphy_resume, |
| 3025 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3026 | .read_page = marvell_read_page, |
| 3027 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3028 | .get_sset_count = marvell_get_sset_count, |
| 3029 | .get_strings = marvell_get_strings, |
| 3030 | .get_stats = marvell_get_stats, |
Maxim Kochetkov | 65ad85f | 2021-04-28 12:53:56 +0300 | [diff] [blame] | 3031 | .get_tunable = m88e1011_get_tunable, |
| 3032 | .set_tunable = m88e1011_set_tunable, |
Olof Johansson | ac8c635 | 2007-11-04 16:08:51 -0600 | [diff] [blame] | 3033 | }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 3034 | { |
| 3035 | .phy_id = MARVELL_PHY_ID_88E1116R, |
| 3036 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3037 | .name = "Marvell 88E1116R", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3038 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3039 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3040 | .config_init = m88e1116r_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3041 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3042 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3043 | .resume = genphy_resume, |
| 3044 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3045 | .read_page = marvell_read_page, |
| 3046 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3047 | .get_sset_count = marvell_get_sset_count, |
| 3048 | .get_strings = marvell_get_strings, |
| 3049 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 262caf4 | 2019-10-28 20:54:17 +0100 | [diff] [blame] | 3050 | .get_tunable = m88e1011_get_tunable, |
| 3051 | .set_tunable = m88e1011_set_tunable, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 3052 | }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 3053 | { |
| 3054 | .phy_id = MARVELL_PHY_ID_88E1510, |
| 3055 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3056 | .name = "Marvell 88E1510", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3057 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
Andrew Lunn | 719655a | 2018-09-29 23:04:16 +0200 | [diff] [blame] | 3058 | .features = PHY_GBIT_FIBRE_FEATURES, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3059 | .flags = PHY_POLL_CABLE_TEST, |
Ivan Bornyakov | b697d9d | 2021-08-12 16:42:56 +0300 | [diff] [blame] | 3060 | .probe = m88e1510_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3061 | .config_init = m88e1510_config_init, |
| 3062 | .config_aneg = m88e1510_config_aneg, |
| 3063 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3064 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3065 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3066 | .get_wol = m88e1318_get_wol, |
| 3067 | .set_wol = m88e1318_set_wol, |
| 3068 | .resume = marvell_resume, |
| 3069 | .suspend = marvell_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3070 | .read_page = marvell_read_page, |
| 3071 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3072 | .get_sset_count = marvell_get_sset_count, |
| 3073 | .get_strings = marvell_get_strings, |
| 3074 | .get_stats = marvell_get_stats, |
Lin Yun Sheng | f0f9b4e | 2017-06-30 17:44:15 +0800 | [diff] [blame] | 3075 | .set_loopback = genphy_loopback, |
Heiner Kallweit | 262caf4 | 2019-10-28 20:54:17 +0100 | [diff] [blame] | 3076 | .get_tunable = m88e1011_get_tunable, |
| 3077 | .set_tunable = m88e1011_set_tunable, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3078 | .cable_test_start = marvell_vct7_cable_test_start, |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 3079 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3080 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 3081 | }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 3082 | { |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 3083 | .phy_id = MARVELL_PHY_ID_88E1540, |
| 3084 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3085 | .name = "Marvell 88E1540", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3086 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3087 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3088 | .flags = PHY_POLL_CABLE_TEST, |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3089 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3090 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3091 | .config_aneg = m88e1510_config_aneg, |
| 3092 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3093 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3094 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3095 | .resume = genphy_resume, |
| 3096 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3097 | .read_page = marvell_read_page, |
| 3098 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3099 | .get_sset_count = marvell_get_sset_count, |
| 3100 | .get_strings = marvell_get_strings, |
| 3101 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 3102 | .get_tunable = m88e1540_get_tunable, |
| 3103 | .set_tunable = m88e1540_set_tunable, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3104 | .cable_test_start = marvell_vct7_cable_test_start, |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 3105 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3106 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 3107 | }, |
| 3108 | { |
Andrew Lunn | 60f06fd | 2017-02-02 00:35:03 +0100 | [diff] [blame] | 3109 | .phy_id = MARVELL_PHY_ID_88E1545, |
| 3110 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3111 | .name = "Marvell 88E1545", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3112 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
| 3113 | .probe = marvell_probe, |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3114 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3115 | .flags = PHY_POLL_CABLE_TEST, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3116 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3117 | .config_aneg = m88e1510_config_aneg, |
| 3118 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3119 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3120 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3121 | .resume = genphy_resume, |
| 3122 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3123 | .read_page = marvell_read_page, |
| 3124 | .write_page = marvell_write_page, |
Andrew Lunn | 60f06fd | 2017-02-02 00:35:03 +0100 | [diff] [blame] | 3125 | .get_sset_count = marvell_get_sset_count, |
| 3126 | .get_strings = marvell_get_strings, |
| 3127 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 262caf4 | 2019-10-28 20:54:17 +0100 | [diff] [blame] | 3128 | .get_tunable = m88e1540_get_tunable, |
| 3129 | .set_tunable = m88e1540_set_tunable, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3130 | .cable_test_start = marvell_vct7_cable_test_start, |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 3131 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3132 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
Andrew Lunn | 60f06fd | 2017-02-02 00:35:03 +0100 | [diff] [blame] | 3133 | }, |
| 3134 | { |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 3135 | .phy_id = MARVELL_PHY_ID_88E3016, |
| 3136 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3137 | .name = "Marvell 88E3016", |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3138 | /* PHY_BASIC_FEATURES */ |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3139 | .probe = marvell_probe, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3140 | .config_init = m88e3016_config_init, |
| 3141 | .aneg_done = marvell_aneg_done, |
| 3142 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3143 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3144 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3145 | .resume = genphy_resume, |
| 3146 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3147 | .read_page = marvell_read_page, |
| 3148 | .write_page = marvell_write_page, |
Andrew Lunn | d2fa47d | 2015-12-30 16:28:26 +0100 | [diff] [blame] | 3149 | .get_sset_count = marvell_get_sset_count, |
| 3150 | .get_strings = marvell_get_strings, |
| 3151 | .get_stats = marvell_get_stats, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 3152 | }, |
Andrew Lunn | e4cf8a3 | 2017-02-01 03:40:06 +0100 | [diff] [blame] | 3153 | { |
Pali Rohár | 1fe976d | 2021-04-12 18:57:39 +0200 | [diff] [blame] | 3154 | .phy_id = MARVELL_PHY_ID_88E6341_FAMILY, |
Andrew Lunn | e4cf8a3 | 2017-02-01 03:40:06 +0100 | [diff] [blame] | 3155 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
Pali Rohár | 1fe976d | 2021-04-12 18:57:39 +0200 | [diff] [blame] | 3156 | .name = "Marvell 88E6341 Family", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3157 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
Pali Rohár | 1fe976d | 2021-04-12 18:57:39 +0200 | [diff] [blame] | 3158 | /* PHY_GBIT_FEATURES */ |
| 3159 | .flags = PHY_POLL_CABLE_TEST, |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3160 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3161 | .config_init = marvell_1011gbe_config_init, |
Pali Rohár | 1fe976d | 2021-04-12 18:57:39 +0200 | [diff] [blame] | 3162 | .config_aneg = m88e6390_config_aneg, |
| 3163 | .read_status = marvell_read_status, |
| 3164 | .config_intr = marvell_config_intr, |
| 3165 | .handle_interrupt = marvell_handle_interrupt, |
| 3166 | .resume = genphy_resume, |
| 3167 | .suspend = genphy_suspend, |
| 3168 | .read_page = marvell_read_page, |
| 3169 | .write_page = marvell_write_page, |
| 3170 | .get_sset_count = marvell_get_sset_count, |
| 3171 | .get_strings = marvell_get_strings, |
| 3172 | .get_stats = marvell_get_stats, |
| 3173 | .get_tunable = m88e1540_get_tunable, |
| 3174 | .set_tunable = m88e1540_set_tunable, |
| 3175 | .cable_test_start = marvell_vct7_cable_test_start, |
| 3176 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
| 3177 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
| 3178 | }, |
| 3179 | { |
| 3180 | .phy_id = MARVELL_PHY_ID_88E6390_FAMILY, |
| 3181 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3182 | .name = "Marvell 88E6390 Family", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3183 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e6390_hwmon_ops), |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 3184 | /* PHY_GBIT_FEATURES */ |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3185 | .flags = PHY_POLL_CABLE_TEST, |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3186 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3187 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3188 | .config_aneg = m88e6390_config_aneg, |
| 3189 | .read_status = marvell_read_status, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3190 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3191 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | ef0f954 | 2020-06-21 10:59:50 +0300 | [diff] [blame] | 3192 | .resume = genphy_resume, |
| 3193 | .suspend = genphy_suspend, |
Russell King | 424ca4c | 2018-01-02 10:58:48 +0000 | [diff] [blame] | 3194 | .read_page = marvell_read_page, |
| 3195 | .write_page = marvell_write_page, |
Andrew Lunn | e4cf8a3 | 2017-02-01 03:40:06 +0100 | [diff] [blame] | 3196 | .get_sset_count = marvell_get_sset_count, |
| 3197 | .get_strings = marvell_get_strings, |
| 3198 | .get_stats = marvell_get_stats, |
Heiner Kallweit | 69f42be | 2019-03-25 19:35:41 +0100 | [diff] [blame] | 3199 | .get_tunable = m88e1540_get_tunable, |
| 3200 | .set_tunable = m88e1540_set_tunable, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3201 | .cable_test_start = marvell_vct7_cable_test_start, |
Andrew Lunn | 0c9bcc1 | 2020-05-27 00:21:40 +0200 | [diff] [blame] | 3202 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
Andrew Lunn | fc879f7 | 2020-05-10 21:12:38 +0200 | [diff] [blame] | 3203 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
Andrew Lunn | e4cf8a3 | 2017-02-01 03:40:06 +0100 | [diff] [blame] | 3204 | }, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3205 | { |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 3206 | .phy_id = MARVELL_PHY_ID_88E6393_FAMILY, |
| 3207 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3208 | .name = "Marvell 88E6393 Family", |
| 3209 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e6393_hwmon_ops), |
| 3210 | /* PHY_GBIT_FEATURES */ |
| 3211 | .flags = PHY_POLL_CABLE_TEST, |
| 3212 | .probe = marvell_probe, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3213 | .config_init = marvell_1011gbe_config_init, |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 3214 | .config_aneg = m88e1510_config_aneg, |
| 3215 | .read_status = marvell_read_status, |
| 3216 | .config_intr = marvell_config_intr, |
| 3217 | .handle_interrupt = marvell_handle_interrupt, |
| 3218 | .resume = genphy_resume, |
| 3219 | .suspend = genphy_suspend, |
| 3220 | .read_page = marvell_read_page, |
| 3221 | .write_page = marvell_write_page, |
| 3222 | .get_sset_count = marvell_get_sset_count, |
| 3223 | .get_strings = marvell_get_strings, |
| 3224 | .get_stats = marvell_get_stats, |
| 3225 | .get_tunable = m88e1540_get_tunable, |
| 3226 | .set_tunable = m88e1540_set_tunable, |
| 3227 | .cable_test_start = marvell_vct7_cable_test_start, |
| 3228 | .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, |
| 3229 | .cable_test_get_status = marvell_vct7_cable_test_get_status, |
| 3230 | }, |
| 3231 | { |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3232 | .phy_id = MARVELL_PHY_ID_88E1340S, |
| 3233 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3234 | .name = "Marvell 88E1340S", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3235 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
| 3236 | .probe = marvell_probe, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3237 | /* PHY_GBIT_FEATURES */ |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3238 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3239 | .config_aneg = m88e1510_config_aneg, |
| 3240 | .read_status = marvell_read_status, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3241 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3242 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3243 | .resume = genphy_resume, |
| 3244 | .suspend = genphy_suspend, |
| 3245 | .read_page = marvell_read_page, |
| 3246 | .write_page = marvell_write_page, |
| 3247 | .get_sset_count = marvell_get_sset_count, |
| 3248 | .get_strings = marvell_get_strings, |
| 3249 | .get_stats = marvell_get_stats, |
| 3250 | .get_tunable = m88e1540_get_tunable, |
| 3251 | .set_tunable = m88e1540_set_tunable, |
| 3252 | }, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3253 | { |
| 3254 | .phy_id = MARVELL_PHY_ID_88E1548P, |
| 3255 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 3256 | .name = "Marvell 88E1548P", |
Marek Behún | 41d26bf | 2021-04-20 09:53:59 +0200 | [diff] [blame] | 3257 | .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), |
| 3258 | .probe = marvell_probe, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3259 | .features = PHY_GBIT_FIBRE_FEATURES, |
Maxim Kochetkov | 8385b1f | 2021-04-30 07:57:33 +0300 | [diff] [blame] | 3260 | .config_init = marvell_1011gbe_config_init, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3261 | .config_aneg = m88e1510_config_aneg, |
| 3262 | .read_status = marvell_read_status, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3263 | .config_intr = marvell_config_intr, |
Ioana Ciornei | a0723b3 | 2020-11-13 18:52:13 +0200 | [diff] [blame] | 3264 | .handle_interrupt = marvell_handle_interrupt, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3265 | .resume = genphy_resume, |
| 3266 | .suspend = genphy_suspend, |
| 3267 | .read_page = marvell_read_page, |
| 3268 | .write_page = marvell_write_page, |
| 3269 | .get_sset_count = marvell_get_sset_count, |
| 3270 | .get_strings = marvell_get_strings, |
| 3271 | .get_stats = marvell_get_stats, |
| 3272 | .get_tunable = m88e1540_get_tunable, |
| 3273 | .set_tunable = m88e1540_set_tunable, |
| 3274 | }, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 3275 | }; |
| 3276 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 3277 | module_phy_driver(marvell_drivers); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 3278 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 3279 | static struct mdio_device_id __maybe_unused marvell_tbl[] = { |
Michal Simek | f5e1cab | 2013-05-30 20:08:25 +0000 | [diff] [blame] | 3280 | { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK }, |
| 3281 | { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK }, |
| 3282 | { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK }, |
Robert Hancock | 1887023 | 2020-10-28 11:15:40 -0600 | [diff] [blame] | 3283 | { MARVELL_PHY_ID_88E1111_FINISAR, MARVELL_PHY_ID_MASK }, |
Michal Simek | f5e1cab | 2013-05-30 20:08:25 +0000 | [diff] [blame] | 3284 | { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK }, |
| 3285 | { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK }, |
| 3286 | { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK }, |
| 3287 | { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK }, |
| 3288 | { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK }, |
| 3289 | { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK }, |
Michal Simek | 3da09a5 | 2013-05-30 20:08:26 +0000 | [diff] [blame] | 3290 | { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK }, |
Michal Simek | 10e24caa | 2013-05-30 20:08:27 +0000 | [diff] [blame] | 3291 | { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK }, |
Andrew Lunn | 819ec8e | 2015-11-16 23:34:41 +0100 | [diff] [blame] | 3292 | { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK }, |
Andrew Lunn | 60f06fd | 2017-02-02 00:35:03 +0100 | [diff] [blame] | 3293 | { MARVELL_PHY_ID_88E1545, MARVELL_PHY_ID_MASK }, |
Sebastian Hesselbarth | 6b358ae | 2014-10-22 20:26:44 +0200 | [diff] [blame] | 3294 | { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK }, |
Pali Rohár | 1fe976d | 2021-04-12 18:57:39 +0200 | [diff] [blame] | 3295 | { MARVELL_PHY_ID_88E6341_FAMILY, MARVELL_PHY_ID_MASK }, |
| 3296 | { MARVELL_PHY_ID_88E6390_FAMILY, MARVELL_PHY_ID_MASK }, |
Marek Behún | a978f7c | 2021-04-20 09:54:03 +0200 | [diff] [blame] | 3297 | { MARVELL_PHY_ID_88E6393_FAMILY, MARVELL_PHY_ID_MASK }, |
Maxim Kochetkov | a602ea8 | 2020-06-21 10:59:51 +0300 | [diff] [blame] | 3298 | { MARVELL_PHY_ID_88E1340S, MARVELL_PHY_ID_MASK }, |
Maxim Kochetkov | f59babf | 2020-06-21 10:59:52 +0300 | [diff] [blame] | 3299 | { MARVELL_PHY_ID_88E1548P, MARVELL_PHY_ID_MASK }, |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 3300 | { } |
| 3301 | }; |
| 3302 | |
| 3303 | MODULE_DEVICE_TABLE(mdio, marvell_tbl); |