1 From 07667014469b0e1464d1cd77d0b42d523fd3ad46 Mon Sep 17 00:00:00 2001
2 From: Raghuram Chary J <raghuramchary.jallipalli@microchip.com>
3 Date: Wed, 11 Apr 2018 20:36:36 +0530
4 Subject: [PATCH 296/454] lan78xx: PHY DSP registers initialization to address
5 EEE link drop issues with long cables
7 commit 1c2734b31d72316e3faaad88c0c9c46fa92a4b20 upstream.
9 The patch is to configure DSP registers of PHY device
10 to handle Gbe-EEE failures with >40m cable length.
12 Fixes: 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")
13 Signed-off-by: Raghuram Chary J <raghuramchary.jallipalli@microchip.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/phy/microchip.c | 178 ++++++++++++++++++++++++++++++++++-
17 include/linux/microchipphy.h | 8 ++
18 2 files changed, 185 insertions(+), 1 deletion(-)
20 --- a/drivers/net/phy/microchip.c
21 +++ b/drivers/net/phy/microchip.c
23 #include <linux/ethtool.h>
24 #include <linux/phy.h>
25 #include <linux/microchipphy.h>
26 +#include <linux/delay.h>
28 #define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
29 #define DRIVER_DESC "Microchip LAN88XX PHY driver"
30 @@ -30,6 +31,16 @@ struct lan88xx_priv {
34 +static int lan88xx_read_page(struct phy_device *phydev)
36 + return __phy_read(phydev, LAN88XX_EXT_PAGE_ACCESS);
39 +static int lan88xx_write_page(struct phy_device *phydev, int page)
41 + return __phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, page);
44 static int lan88xx_phy_config_intr(struct phy_device *phydev)
47 @@ -66,6 +77,150 @@ static int lan88xx_suspend(struct phy_de
51 +static int lan88xx_TR_reg_set(struct phy_device *phydev, u16 regaddr,
54 + int val, save_page, ret = 0;
57 + /* Save current page */
58 + save_page = phy_save_page(phydev);
59 + if (save_page < 0) {
60 + pr_warn("Failed to get current page\n");
64 + /* Switch to TR page */
65 + lan88xx_write_page(phydev, LAN88XX_EXT_PAGE_ACCESS_TR);
67 + ret = __phy_write(phydev, LAN88XX_EXT_PAGE_TR_LOW_DATA,
70 + pr_warn("Failed to write TR low data\n");
74 + ret = __phy_write(phydev, LAN88XX_EXT_PAGE_TR_HIGH_DATA,
75 + (data & 0x00FF0000) >> 16);
77 + pr_warn("Failed to write TR high data\n");
81 + /* Config control bits [15:13] of register */
82 + buf = (regaddr & ~(0x3 << 13));/* Clr [14:13] to write data in reg */
83 + buf |= 0x8000; /* Set [15] to Packet transmit */
85 + ret = __phy_write(phydev, LAN88XX_EXT_PAGE_TR_CR, buf);
87 + pr_warn("Failed to write data in reg\n");
91 + usleep_range(1000, 2000);/* Wait for Data to be written */
92 + val = __phy_read(phydev, LAN88XX_EXT_PAGE_TR_CR);
93 + if (!(val & 0x8000))
94 + pr_warn("TR Register[0x%X] configuration failed\n", regaddr);
96 + return phy_restore_page(phydev, save_page, ret);
99 +static void lan88xx_config_TR_regs(struct phy_device *phydev)
103 + /* Get access to Channel 0x1, Node 0xF , Register 0x01.
104 + * Write 24-bit value 0x12B00A to register. Setting MrvlTrFix1000Kf,
105 + * MrvlTrFix1000Kp, MasterEnableTR bits.
107 + err = lan88xx_TR_reg_set(phydev, 0x0F82, 0x12B00A);
109 + pr_warn("Failed to Set Register[0x0F82]\n");
111 + /* Get access to Channel b'10, Node b'1101, Register 0x06.
112 + * Write 24-bit value 0xD2C46F to register. Setting SSTrKf1000Slv,
113 + * SSTrKp1000Mas bits.
115 + err = lan88xx_TR_reg_set(phydev, 0x168C, 0xD2C46F);
117 + pr_warn("Failed to Set Register[0x168C]\n");
119 + /* Get access to Channel b'10, Node b'1111, Register 0x11.
120 + * Write 24-bit value 0x620 to register. Setting rem_upd_done_thresh
123 + err = lan88xx_TR_reg_set(phydev, 0x17A2, 0x620);
125 + pr_warn("Failed to Set Register[0x17A2]\n");
127 + /* Get access to Channel b'10, Node b'1101, Register 0x10.
128 + * Write 24-bit value 0xEEFFDD to register. Setting
129 + * eee_TrKp1Long_1000, eee_TrKp2Long_1000, eee_TrKp3Long_1000,
130 + * eee_TrKp1Short_1000,eee_TrKp2Short_1000, eee_TrKp3Short_1000 bits.
132 + err = lan88xx_TR_reg_set(phydev, 0x16A0, 0xEEFFDD);
134 + pr_warn("Failed to Set Register[0x16A0]\n");
136 + /* Get access to Channel b'10, Node b'1101, Register 0x13.
137 + * Write 24-bit value 0x071448 to register. Setting
138 + * slv_lpi_tr_tmr_val1, slv_lpi_tr_tmr_val2 bits.
140 + err = lan88xx_TR_reg_set(phydev, 0x16A6, 0x071448);
142 + pr_warn("Failed to Set Register[0x16A6]\n");
144 + /* Get access to Channel b'10, Node b'1101, Register 0x12.
145 + * Write 24-bit value 0x13132F to register. Setting
146 + * slv_sigdet_timer_val1, slv_sigdet_timer_val2 bits.
148 + err = lan88xx_TR_reg_set(phydev, 0x16A4, 0x13132F);
150 + pr_warn("Failed to Set Register[0x16A4]\n");
152 + /* Get access to Channel b'10, Node b'1101, Register 0x14.
153 + * Write 24-bit value 0x0 to register. Setting eee_3level_delay,
154 + * eee_TrKf_freeze_delay bits.
156 + err = lan88xx_TR_reg_set(phydev, 0x16A8, 0x0);
158 + pr_warn("Failed to Set Register[0x16A8]\n");
160 + /* Get access to Channel b'01, Node b'1111, Register 0x34.
161 + * Write 24-bit value 0x91B06C to register. Setting
162 + * FastMseSearchThreshLong1000, FastMseSearchThreshShort1000,
163 + * FastMseSearchUpdGain1000 bits.
165 + err = lan88xx_TR_reg_set(phydev, 0x0FE8, 0x91B06C);
167 + pr_warn("Failed to Set Register[0x0FE8]\n");
169 + /* Get access to Channel b'01, Node b'1111, Register 0x3E.
170 + * Write 24-bit value 0xC0A028 to register. Setting
171 + * FastMseKp2ThreshLong1000, FastMseKp2ThreshShort1000,
172 + * FastMseKp2UpdGain1000, FastMseKp2ExitEn1000 bits.
174 + err = lan88xx_TR_reg_set(phydev, 0x0FFC, 0xC0A028);
176 + pr_warn("Failed to Set Register[0x0FFC]\n");
178 + /* Get access to Channel b'01, Node b'1111, Register 0x35.
179 + * Write 24-bit value 0x041600 to register. Setting
180 + * FastMseSearchPhShNum1000, FastMseSearchClksPerPh1000,
181 + * FastMsePhChangeDelay1000 bits.
183 + err = lan88xx_TR_reg_set(phydev, 0x0FEA, 0x041600);
185 + pr_warn("Failed to Set Register[0x0FEA]\n");
187 + /* Get access to Channel b'10, Node b'1101, Register 0x03.
188 + * Write 24-bit value 0x000004 to register. Setting TrFreeze bits.
190 + err = lan88xx_TR_reg_set(phydev, 0x1686, 0x000004);
192 + pr_warn("Failed to Set Register[0x1686]\n");
195 static int lan88xx_probe(struct phy_device *phydev)
197 struct device *dev = &phydev->mdio.dev;
198 @@ -132,6 +287,25 @@ static void lan88xx_set_mdix(struct phy_
199 phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_0);
202 +static int lan88xx_config_init(struct phy_device *phydev)
206 + genphy_config_init(phydev);
207 + /*Zerodetect delay enable */
208 + val = phy_read_mmd(phydev, MDIO_MMD_PCS,
209 + PHY_ARDENNES_MMD_DEV_3_PHY_CFG);
210 + val |= PHY_ARDENNES_MMD_DEV_3_PHY_CFG_ZD_DLY_EN_;
212 + phy_write_mmd(phydev, MDIO_MMD_PCS, PHY_ARDENNES_MMD_DEV_3_PHY_CFG,
215 + /* Config DSP registers */
216 + lan88xx_config_TR_regs(phydev);
221 static int lan88xx_config_aneg(struct phy_device *phydev)
223 lan88xx_set_mdix(phydev);
224 @@ -151,7 +325,7 @@ static struct phy_driver microchip_phy_d
225 .probe = lan88xx_probe,
226 .remove = lan88xx_remove,
228 - .config_init = genphy_config_init,
229 + .config_init = lan88xx_config_init,
230 .config_aneg = lan88xx_config_aneg,
231 .read_status = genphy_read_status,
233 @@ -161,6 +335,8 @@ static struct phy_driver microchip_phy_d
234 .suspend = lan88xx_suspend,
235 .resume = genphy_resume,
236 .set_wol = lan88xx_set_wol,
237 + .read_page = lan88xx_read_page,
238 + .write_page = lan88xx_write_page,
241 module_phy_driver(microchip_phy_driver);
242 --- a/include/linux/microchipphy.h
243 +++ b/include/linux/microchipphy.h
245 #define LAN88XX_MMD3_CHIP_ID (32877)
246 #define LAN88XX_MMD3_CHIP_REV (32878)
249 +#define PHY_ARDENNES_MMD_DEV_3_PHY_CFG (0x806A)
250 +#define PHY_ARDENNES_MMD_DEV_3_PHY_CFG_ZD_DLY_EN_ (0x2000)
251 +#define LAN88XX_EXT_PAGE_ACCESS_TR (0x52B5)
252 +#define LAN88XX_EXT_PAGE_TR_CR 16
253 +#define LAN88XX_EXT_PAGE_TR_LOW_DATA 17
254 +#define LAN88XX_EXT_PAGE_TR_HIGH_DATA 18
256 #endif /* _MICROCHIPPHY_H */