blob: 34fd15b904e7065a2c0f97fcf3ec38c71793936d [file] [log] [blame]
Andy Fleming00db8182005-07-30 19:31:23 -04001/*
2 * drivers/net/phy/marvell.c
3 *
4 * Driver for Marvell PHYs
5 *
6 * Author: Andy Fleming
7 *
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
9 *
Michael Stapelberg3871c382013-03-11 13:56:45 +000010 * Copyright (c) 2013 Michael Stapelberg <michael@stapelberg.de>
11 *
Andy Fleming00db8182005-07-30 19:31:23 -040012 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
Andy Fleming00db8182005-07-30 19:31:23 -040018#include <linux/kernel.h>
Andy Fleming00db8182005-07-30 19:31:23 -040019#include <linux/string.h>
Andrew Lunn0b046802017-01-20 01:37:49 +010020#include <linux/ctype.h>
Andy Fleming00db8182005-07-30 19:31:23 -040021#include <linux/errno.h>
22#include <linux/unistd.h>
Andrew Lunn0b046802017-01-20 01:37:49 +010023#include <linux/hwmon.h>
Andy Fleming00db8182005-07-30 19:31:23 -040024#include <linux/interrupt.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/netdevice.h>
28#include <linux/etherdevice.h>
29#include <linux/skbuff.h>
30#include <linux/spinlock.h>
31#include <linux/mm.h>
32#include <linux/module.h>
Andy Fleming00db8182005-07-30 19:31:23 -040033#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/phy.h>
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +100036#include <linux/marvell_phy.h>
David Daneycf41a512010-11-19 12:13:18 +000037#include <linux/of.h>
Andy Fleming00db8182005-07-30 19:31:23 -040038
Avinash Kumareea3b202013-09-30 09:36:44 +053039#include <linux/io.h>
Andy Fleming00db8182005-07-30 19:31:23 -040040#include <asm/irq.h>
Avinash Kumareea3b202013-09-30 09:36:44 +053041#include <linux/uaccess.h>
Andy Fleming00db8182005-07-30 19:31:23 -040042
David Daney27d916d2010-11-19 11:58:52 +000043#define MII_MARVELL_PHY_PAGE 22
Andrew Lunn52295662017-05-25 21:42:08 +020044#define MII_MARVELL_COPPER_PAGE 0x00
45#define MII_MARVELL_FIBER_PAGE 0x01
46#define MII_MARVELL_MSCR_PAGE 0x02
47#define MII_MARVELL_LED_PAGE 0x03
48#define MII_MARVELL_MISC_TEST_PAGE 0x06
49#define MII_MARVELL_WOL_PAGE 0x11
David Daney27d916d2010-11-19 11:58:52 +000050
Andy Fleming00db8182005-07-30 19:31:23 -040051#define MII_M1011_IEVENT 0x13
52#define MII_M1011_IEVENT_CLEAR 0x0000
53
54#define MII_M1011_IMASK 0x12
55#define MII_M1011_IMASK_INIT 0x6400
56#define MII_M1011_IMASK_CLEAR 0x0000
57
Andrew Lunnfecd5e92017-07-30 22:41:49 +020058#define MII_M1011_PHY_SCR 0x10
59#define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11)
60#define MII_M1011_PHY_SCR_DOWNSHIFT_SHIFT 12
61#define MII_M1011_PHY_SCR_MDI (0x0 << 5)
62#define MII_M1011_PHY_SCR_MDI_X (0x1 << 5)
63#define MII_M1011_PHY_SCR_AUTO_CROSS (0x3 << 5)
Andy Fleming76884672007-02-09 18:13:58 -060064
Andy Fleming76884672007-02-09 18:13:58 -060065#define MII_M1111_PHY_LED_CONTROL 0x18
66#define MII_M1111_PHY_LED_DIRECT 0x4100
67#define MII_M1111_PHY_LED_COMBINE 0x411c
Kim Phillips895ee682007-06-05 18:46:47 +080068#define MII_M1111_PHY_EXT_CR 0x14
Andrew Lunn61111592017-07-30 22:41:46 +020069#define MII_M1111_RGMII_RX_DELAY BIT(7)
70#define MII_M1111_RGMII_TX_DELAY BIT(1)
Kim Phillips895ee682007-06-05 18:46:47 +080071#define MII_M1111_PHY_EXT_SR 0x1b
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030072
73#define MII_M1111_HWCFG_MODE_MASK 0xf
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030074#define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
Kapil Juneja4117b5b2007-05-11 18:25:18 -050075#define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
Andrew Lunn865b813a2017-07-30 22:41:47 +020076#define MII_M1111_HWCFG_MODE_RTBI 0x7
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +000077#define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
Andrew Lunn865b813a2017-07-30 22:41:47 +020078#define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
79#define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13)
80#define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030081
Cyril Chemparathyc477d042010-08-02 09:44:53 +000082#define MII_88E1121_PHY_MSCR_REG 21
83#define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
84#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
Andrew Lunn864dc722017-07-30 22:41:48 +020085#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(BIT(5) || BIT(4)))
Cyril Chemparathyc477d042010-08-02 09:44:53 +000086
Andrew Lunn0b046802017-01-20 01:37:49 +010087#define MII_88E1121_MISC_TEST 0x1a
88#define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00
89#define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8
90#define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7)
91#define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6)
92#define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5)
93#define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f
94
95#define MII_88E1510_TEMP_SENSOR 0x1b
96#define MII_88E1510_TEMP_SENSOR_MASK 0xff
97
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -070098#define MII_88E1318S_PHY_MSCR1_REG 16
99#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700100
Michael Stapelberg3871c382013-03-11 13:56:45 +0000101/* Copper Specific Interrupt Enable Register */
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200102#define MII_88E1318S_PHY_CSIER 0x12
Michael Stapelberg3871c382013-03-11 13:56:45 +0000103/* WOL Event Interrupt Enable */
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200104#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
Michael Stapelberg3871c382013-03-11 13:56:45 +0000105
106/* LED Timer Control Register */
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200107#define MII_88E1318S_PHY_LED_TCR 0x12
108#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
109#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
110#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
Michael Stapelberg3871c382013-03-11 13:56:45 +0000111
112/* Magic Packet MAC address registers */
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200113#define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
114#define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
115#define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
Michael Stapelberg3871c382013-03-11 13:56:45 +0000116
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200117#define MII_88E1318S_PHY_WOL_CTRL 0x10
118#define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
119#define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
Michael Stapelberg3871c382013-03-11 13:56:45 +0000120
Sergei Poselenov140bc922009-04-07 02:01:41 +0000121#define MII_88E1121_PHY_LED_CTRL 16
Sergei Poselenov140bc922009-04-07 02:01:41 +0000122#define MII_88E1121_PHY_LED_DEF 0x0030
Sergei Poselenov140bc922009-04-07 02:01:41 +0000123
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300124#define MII_M1011_PHY_STATUS 0x11
125#define MII_M1011_PHY_STATUS_1000 0x8000
126#define MII_M1011_PHY_STATUS_100 0x4000
127#define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
128#define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
129#define MII_M1011_PHY_STATUS_RESOLVED 0x0800
130#define MII_M1011_PHY_STATUS_LINK 0x0400
131
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200132#define MII_88E3016_PHY_SPEC_CTRL 0x10
133#define MII_88E3016_DISABLE_SCRAMBLER 0x0200
134#define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
Andy Fleming76884672007-02-09 18:13:58 -0600135
Stefan Roese930b37e2016-02-18 10:59:07 +0100136#define MII_88E1510_GEN_CTRL_REG_1 0x14
137#define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7
138#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
139#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
140
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200141#define LPA_FIBER_1000HALF 0x40
142#define LPA_FIBER_1000FULL 0x20
143
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200144#define LPA_PAUSE_FIBER 0x180
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200145#define LPA_PAUSE_ASYM_FIBER 0x100
146
147#define ADVERTISE_FIBER_1000HALF 0x40
148#define ADVERTISE_FIBER_1000FULL 0x20
149
150#define ADVERTISE_PAUSE_FIBER 0x180
151#define ADVERTISE_PAUSE_ASYM_FIBER 0x100
152
153#define REGISTER_LINK_STATUS 0x400
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200154#define NB_FIBER_STATS 1
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200155
Andy Fleming00db8182005-07-30 19:31:23 -0400156MODULE_DESCRIPTION("Marvell PHY driver");
157MODULE_AUTHOR("Andy Fleming");
158MODULE_LICENSE("GPL");
159
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100160struct marvell_hw_stat {
161 const char *string;
162 u8 page;
163 u8 reg;
164 u8 bits;
165};
166
167static struct marvell_hw_stat marvell_hw_stats[] = {
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200168 { "phy_receive_errors_copper", 0, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100169 { "phy_idle_errors", 0, 10, 8 },
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200170 { "phy_receive_errors_fiber", 1, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100171};
172
173struct marvell_priv {
174 u64 stats[ARRAY_SIZE(marvell_hw_stats)];
Andrew Lunn0b046802017-01-20 01:37:49 +0100175 char *hwmon_name;
176 struct device *hwmon_dev;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100177};
178
Andrew Lunn6427bb22017-05-17 03:26:03 +0200179static int marvell_get_page(struct phy_device *phydev)
180{
181 return phy_read(phydev, MII_MARVELL_PHY_PAGE);
182}
183
184static int marvell_set_page(struct phy_device *phydev, int page)
185{
186 return phy_write(phydev, MII_MARVELL_PHY_PAGE, page);
187}
188
Andrew Lunn53798322017-05-25 21:42:07 +0200189static int marvell_get_set_page(struct phy_device *phydev, int page)
190{
191 int oldpage = marvell_get_page(phydev);
192
193 if (oldpage < 0)
194 return oldpage;
195
196 if (page != oldpage)
197 return marvell_set_page(phydev, page);
198
199 return 0;
200}
201
Andy Fleming00db8182005-07-30 19:31:23 -0400202static int marvell_ack_interrupt(struct phy_device *phydev)
203{
204 int err;
205
206 /* Clear the interrupts by reading the reg */
207 err = phy_read(phydev, MII_M1011_IEVENT);
208
209 if (err < 0)
210 return err;
211
212 return 0;
213}
214
215static int marvell_config_intr(struct phy_device *phydev)
216{
217 int err;
218
Andy Fleming76884672007-02-09 18:13:58 -0600219 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
Andrew Lunn23beb382017-05-17 03:26:04 +0200220 err = phy_write(phydev, MII_M1011_IMASK,
221 MII_M1011_IMASK_INIT);
Andy Fleming00db8182005-07-30 19:31:23 -0400222 else
Andrew Lunn23beb382017-05-17 03:26:04 +0200223 err = phy_write(phydev, MII_M1011_IMASK,
224 MII_M1011_IMASK_CLEAR);
Andy Fleming00db8182005-07-30 19:31:23 -0400225
226 return err;
227}
228
David Thomson239aa552015-07-10 16:28:25 +1200229static int marvell_set_polarity(struct phy_device *phydev, int polarity)
230{
231 int reg;
232 int err;
233 int val;
234
235 /* get the current settings */
236 reg = phy_read(phydev, MII_M1011_PHY_SCR);
237 if (reg < 0)
238 return reg;
239
240 val = reg;
241 val &= ~MII_M1011_PHY_SCR_AUTO_CROSS;
242 switch (polarity) {
243 case ETH_TP_MDI:
244 val |= MII_M1011_PHY_SCR_MDI;
245 break;
246 case ETH_TP_MDI_X:
247 val |= MII_M1011_PHY_SCR_MDI_X;
248 break;
249 case ETH_TP_MDI_AUTO:
250 case ETH_TP_MDI_INVALID:
251 default:
252 val |= MII_M1011_PHY_SCR_AUTO_CROSS;
253 break;
254 }
255
256 if (val != reg) {
257 /* Set the new polarity value in the register */
258 err = phy_write(phydev, MII_M1011_PHY_SCR, val);
259 if (err)
260 return err;
261 }
262
263 return 0;
264}
265
Andy Fleming00db8182005-07-30 19:31:23 -0400266static int marvell_config_aneg(struct phy_device *phydev)
267{
268 int err;
269
Raju Lakkaraju4e26c5c2016-11-29 15:16:49 +0530270 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Andy Fleming76884672007-02-09 18:13:58 -0600271 if (err < 0)
272 return err;
273
274 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
275 MII_M1111_PHY_LED_DIRECT);
276 if (err < 0)
277 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400278
279 err = genphy_config_aneg(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000280 if (err < 0)
281 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400282
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000283 if (phydev->autoneg != AUTONEG_ENABLE) {
Andrew Lunn0c3439b2017-05-17 03:25:59 +0200284 /* A write to speed/duplex bits (that is performed by
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000285 * genphy_config_aneg() call above) must be followed by
286 * a software reset. Otherwise, the write has no effect.
287 */
Andrew Lunn34386342017-07-30 22:41:45 +0200288 err = genphy_soft_reset(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000289 if (err < 0)
290 return err;
291 }
292
293 return 0;
Andy Fleming00db8182005-07-30 19:31:23 -0400294}
295
Andrew Lunnf2899782017-05-23 17:49:13 +0200296static int m88e1101_config_aneg(struct phy_device *phydev)
297{
298 int err;
299
300 /* This Marvell PHY has an errata which requires
301 * that certain registers get written in order
302 * to restart autonegotiation
303 */
Andrew Lunn34386342017-07-30 22:41:45 +0200304 err = genphy_soft_reset(phydev);
Andrew Lunnf2899782017-05-23 17:49:13 +0200305 if (err < 0)
306 return err;
307
308 err = phy_write(phydev, 0x1d, 0x1f);
309 if (err < 0)
310 return err;
311
312 err = phy_write(phydev, 0x1e, 0x200c);
313 if (err < 0)
314 return err;
315
316 err = phy_write(phydev, 0x1d, 0x5);
317 if (err < 0)
318 return err;
319
320 err = phy_write(phydev, 0x1e, 0);
321 if (err < 0)
322 return err;
323
324 err = phy_write(phydev, 0x1e, 0x100);
325 if (err < 0)
326 return err;
327
328 return marvell_config_aneg(phydev);
329}
330
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530331static int m88e1111_config_aneg(struct phy_device *phydev)
332{
333 int err;
334
335 /* The Marvell PHY has an errata which requires
336 * that certain registers get written in order
337 * to restart autonegotiation
338 */
Andrew Lunn34386342017-07-30 22:41:45 +0200339 err = genphy_soft_reset(phydev);
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530340
Raju Lakkaraju4e26c5c2016-11-29 15:16:49 +0530341 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530342 if (err < 0)
343 return err;
344
345 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
346 MII_M1111_PHY_LED_DIRECT);
347 if (err < 0)
348 return err;
349
350 err = genphy_config_aneg(phydev);
351 if (err < 0)
352 return err;
353
354 if (phydev->autoneg != AUTONEG_ENABLE) {
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530355 /* A write to speed/duplex bits (that is performed by
356 * genphy_config_aneg() call above) must be followed by
357 * a software reset. Otherwise, the write has no effect.
358 */
Andrew Lunn34386342017-07-30 22:41:45 +0200359 err = genphy_soft_reset(phydev);
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530360 if (err < 0)
361 return err;
362 }
363
364 return 0;
365}
366
David Daneycf41a512010-11-19 12:13:18 +0000367#ifdef CONFIG_OF_MDIO
Andrew Lunn0c3439b2017-05-17 03:25:59 +0200368/* Set and/or override some configuration registers based on the
David Daneycf41a512010-11-19 12:13:18 +0000369 * marvell,reg-init property stored in the of_node for the phydev.
370 *
371 * marvell,reg-init = <reg-page reg mask value>,...;
372 *
373 * There may be one or more sets of <reg-page reg mask value>:
374 *
375 * reg-page: which register bank to use.
376 * reg: the register.
377 * mask: if non-zero, ANDed with existing register value.
378 * value: ORed with the masked value and written to the regiser.
379 *
380 */
381static int marvell_of_reg_init(struct phy_device *phydev)
382{
383 const __be32 *paddr;
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100384 int len, i, saved_page, current_page, ret;
David Daneycf41a512010-11-19 12:13:18 +0000385
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100386 if (!phydev->mdio.dev.of_node)
David Daneycf41a512010-11-19 12:13:18 +0000387 return 0;
388
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100389 paddr = of_get_property(phydev->mdio.dev.of_node,
390 "marvell,reg-init", &len);
David Daneycf41a512010-11-19 12:13:18 +0000391 if (!paddr || len < (4 * sizeof(*paddr)))
392 return 0;
393
Andrew Lunn6427bb22017-05-17 03:26:03 +0200394 saved_page = marvell_get_page(phydev);
David Daneycf41a512010-11-19 12:13:18 +0000395 if (saved_page < 0)
396 return saved_page;
David Daneycf41a512010-11-19 12:13:18 +0000397 current_page = saved_page;
398
399 ret = 0;
400 len /= sizeof(*paddr);
401 for (i = 0; i < len - 3; i += 4) {
Andrew Lunn6427bb22017-05-17 03:26:03 +0200402 u16 page = be32_to_cpup(paddr + i);
David Daneycf41a512010-11-19 12:13:18 +0000403 u16 reg = be32_to_cpup(paddr + i + 1);
404 u16 mask = be32_to_cpup(paddr + i + 2);
405 u16 val_bits = be32_to_cpup(paddr + i + 3);
406 int val;
407
Andrew Lunn6427bb22017-05-17 03:26:03 +0200408 if (page != current_page) {
409 current_page = page;
410 ret = marvell_set_page(phydev, page);
David Daneycf41a512010-11-19 12:13:18 +0000411 if (ret < 0)
412 goto err;
413 }
414
415 val = 0;
416 if (mask) {
417 val = phy_read(phydev, reg);
418 if (val < 0) {
419 ret = val;
420 goto err;
421 }
422 val &= mask;
423 }
424 val |= val_bits;
425
426 ret = phy_write(phydev, reg, val);
427 if (ret < 0)
428 goto err;
David Daneycf41a512010-11-19 12:13:18 +0000429 }
430err:
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100431 if (current_page != saved_page) {
Andrew Lunn6427bb22017-05-17 03:26:03 +0200432 i = marvell_set_page(phydev, saved_page);
David Daneycf41a512010-11-19 12:13:18 +0000433 if (ret == 0)
434 ret = i;
435 }
436 return ret;
437}
438#else
439static int marvell_of_reg_init(struct phy_device *phydev)
440{
441 return 0;
442}
443#endif /* CONFIG_OF_MDIO */
444
Andrew Lunn864dc722017-07-30 22:41:48 +0200445static int m88e1121_config_aneg_rgmii_delays(struct phy_device *phydev)
Sergei Poselenov140bc922009-04-07 02:01:41 +0000446{
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000447 int err, oldpage, mscr;
448
Andrew Lunn52295662017-05-25 21:42:08 +0200449 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MSCR_PAGE);
Andrew Lunn53798322017-05-25 21:42:07 +0200450 if (oldpage < 0)
451 return oldpage;
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000452
Andrew Lunn864dc722017-07-30 22:41:48 +0200453 mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG);
454 if (mscr < 0) {
455 err = mscr;
456 goto out;
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700457 }
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000458
Andrew Lunn864dc722017-07-30 22:41:48 +0200459 mscr &= MII_88E1121_PHY_MSCR_DELAY_MASK;
460
461 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
462 mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
463 MII_88E1121_PHY_MSCR_TX_DELAY);
464 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
465 mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
466 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
467 mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
468
469 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
470
471out:
Andrew Lunn6427bb22017-05-17 03:26:03 +0200472 marvell_set_page(phydev, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000473
Andrew Lunn864dc722017-07-30 22:41:48 +0200474 return err;
475}
476
477static int m88e1121_config_aneg(struct phy_device *phydev)
478{
479 int err = 0;
480
481 if (phy_interface_is_rgmii(phydev)) {
482 err = m88e1121_config_aneg_rgmii_delays(phydev);
483 if (err)
484 return err;
485 }
486
Andrew Lunn34386342017-07-30 22:41:45 +0200487 err = genphy_soft_reset(phydev);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000488 if (err < 0)
489 return err;
490
Andrew Lunnfecd5e92017-07-30 22:41:49 +0200491 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000492 if (err < 0)
493 return err;
494
Clemens Gruberfdecf362016-06-11 17:21:26 +0200495 return genphy_config_aneg(phydev);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000496}
497
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700498static int m88e1318_config_aneg(struct phy_device *phydev)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700499{
500 int err, oldpage, mscr;
501
Andrew Lunn52295662017-05-25 21:42:08 +0200502 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MSCR_PAGE);
Andrew Lunn53798322017-05-25 21:42:07 +0200503 if (oldpage < 0)
504 return oldpage;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700505
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700506 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
507 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700508
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700509 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700510 if (err < 0)
511 return err;
512
Andrew Lunn6427bb22017-05-17 03:26:03 +0200513 err = marvell_set_page(phydev, oldpage);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700514 if (err < 0)
515 return err;
516
517 return m88e1121_config_aneg(phydev);
518}
519
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200520/**
521 * ethtool_adv_to_fiber_adv_t
522 * @ethadv: the ethtool advertisement settings
523 *
524 * A small helper function that translates ethtool advertisement
525 * settings to phy autonegotiation advertisements for the
526 * MII_ADV register for fiber link.
527 */
528static inline u32 ethtool_adv_to_fiber_adv_t(u32 ethadv)
529{
530 u32 result = 0;
531
532 if (ethadv & ADVERTISED_1000baseT_Half)
533 result |= ADVERTISE_FIBER_1000HALF;
534 if (ethadv & ADVERTISED_1000baseT_Full)
535 result |= ADVERTISE_FIBER_1000FULL;
536
537 if ((ethadv & ADVERTISE_PAUSE_ASYM) && (ethadv & ADVERTISE_PAUSE_CAP))
538 result |= LPA_PAUSE_ASYM_FIBER;
539 else if (ethadv & ADVERTISE_PAUSE_CAP)
540 result |= (ADVERTISE_PAUSE_FIBER
541 & (~ADVERTISE_PAUSE_ASYM_FIBER));
542
543 return result;
544}
545
546/**
547 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR
548 * @phydev: target phy_device struct
549 *
550 * Description: If auto-negotiation is enabled, we configure the
551 * advertising, and then restart auto-negotiation. If it is not
552 * enabled, then we write the BMCR. Adapted for fiber link in
553 * some Marvell's devices.
554 */
555static int marvell_config_aneg_fiber(struct phy_device *phydev)
556{
557 int changed = 0;
558 int err;
559 int adv, oldadv;
560 u32 advertise;
561
562 if (phydev->autoneg != AUTONEG_ENABLE)
563 return genphy_setup_forced(phydev);
564
565 /* Only allow advertising what this PHY supports */
566 phydev->advertising &= phydev->supported;
567 advertise = phydev->advertising;
568
569 /* Setup fiber advertisement */
570 adv = phy_read(phydev, MII_ADVERTISE);
571 if (adv < 0)
572 return adv;
573
574 oldadv = adv;
575 adv &= ~(ADVERTISE_FIBER_1000HALF | ADVERTISE_FIBER_1000FULL
576 | LPA_PAUSE_FIBER);
577 adv |= ethtool_adv_to_fiber_adv_t(advertise);
578
579 if (adv != oldadv) {
580 err = phy_write(phydev, MII_ADVERTISE, adv);
581 if (err < 0)
582 return err;
583
584 changed = 1;
585 }
586
587 if (changed == 0) {
588 /* Advertisement hasn't changed, but maybe aneg was never on to
Andrew Lunn8cf8b872017-07-30 22:41:44 +0200589 * begin with? Or maybe phy was isolated?
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200590 */
591 int ctl = phy_read(phydev, MII_BMCR);
592
593 if (ctl < 0)
594 return ctl;
595
596 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
597 changed = 1; /* do restart aneg */
598 }
599
600 /* Only restart aneg if we are advertising something different
601 * than we were before.
602 */
603 if (changed > 0)
604 changed = genphy_restart_aneg(phydev);
605
606 return changed;
607}
608
Michal Simek10e24caa2013-05-30 20:08:27 +0000609static int m88e1510_config_aneg(struct phy_device *phydev)
610{
611 int err;
612
Andrew Lunn52295662017-05-25 21:42:08 +0200613 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200614 if (err < 0)
615 goto error;
616
617 /* Configure the copper link first */
Michal Simek10e24caa2013-05-30 20:08:27 +0000618 err = m88e1318_config_aneg(phydev);
619 if (err < 0)
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200620 goto error;
Michal Simek10e24caa2013-05-30 20:08:27 +0000621
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200622 /* Then the fiber link */
Andrew Lunn52295662017-05-25 21:42:08 +0200623 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200624 if (err < 0)
625 goto error;
626
627 err = marvell_config_aneg_fiber(phydev);
628 if (err < 0)
629 goto error;
630
Andrew Lunn52295662017-05-25 21:42:08 +0200631 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200632
633error:
Andrew Lunn52295662017-05-25 21:42:08 +0200634 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200635 return err;
Clemens Gruber79be1a12016-02-15 23:46:45 +0100636}
637
638static int marvell_config_init(struct phy_device *phydev)
639{
640 /* Set registers from marvell,reg-init DT property */
Michal Simek10e24caa2013-05-30 20:08:27 +0000641 return marvell_of_reg_init(phydev);
642}
643
Michal Simek3da09a52013-05-30 20:08:26 +0000644static int m88e1116r_config_init(struct phy_device *phydev)
645{
646 int temp;
647 int err;
648
Andrew Lunn34386342017-07-30 22:41:45 +0200649 err = genphy_soft_reset(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000650 if (err < 0)
651 return err;
652
653 mdelay(500);
654
Andrew Lunn52295662017-05-25 21:42:08 +0200655 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Michal Simek3da09a52013-05-30 20:08:26 +0000656 if (err < 0)
657 return err;
658
Andrew Lunnfecd5e92017-07-30 22:41:49 +0200659 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
660 if (err < 0)
661 return err;
662
Michal Simek3da09a52013-05-30 20:08:26 +0000663 temp = phy_read(phydev, MII_M1011_PHY_SCR);
Andrew Lunnfecd5e92017-07-30 22:41:49 +0200664 temp |= (7 << MII_M1011_PHY_SCR_DOWNSHIFT_SHIFT);
665 temp |= MII_M1011_PHY_SCR_DOWNSHIFT_EN;
Michal Simek3da09a52013-05-30 20:08:26 +0000666 err = phy_write(phydev, MII_M1011_PHY_SCR, temp);
667 if (err < 0)
668 return err;
669
Andrew Lunn864dc722017-07-30 22:41:48 +0200670 err = m88e1121_config_aneg_rgmii_delays(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000671 if (err < 0)
672 return err;
673
Andrew Lunn34386342017-07-30 22:41:45 +0200674 err = genphy_soft_reset(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000675 if (err < 0)
676 return err;
677
Clemens Gruber79be1a12016-02-15 23:46:45 +0100678 return marvell_config_init(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000679}
680
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200681static int m88e3016_config_init(struct phy_device *phydev)
682{
683 int reg;
684
685 /* Enable Scrambler and Auto-Crossover */
686 reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL);
687 if (reg < 0)
688 return reg;
689
690 reg &= ~MII_88E3016_DISABLE_SCRAMBLER;
691 reg |= MII_88E3016_AUTO_MDIX_CROSSOVER;
692
693 reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg);
694 if (reg < 0)
695 return reg;
696
Clemens Gruber79be1a12016-02-15 23:46:45 +0100697 return marvell_config_init(phydev);
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200698}
699
Andrew Lunn865b813a2017-07-30 22:41:47 +0200700static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev,
701 u16 mode,
702 int fibre_copper_auto)
703{
704 int temp;
705
706 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
707 if (temp < 0)
708 return temp;
709
710 temp &= ~(MII_M1111_HWCFG_MODE_MASK |
711 MII_M1111_HWCFG_FIBER_COPPER_AUTO |
712 MII_M1111_HWCFG_FIBER_COPPER_RES);
713 temp |= mode;
714
715 if (fibre_copper_auto)
716 temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
717
718 return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
719}
720
Andrew Lunn61111592017-07-30 22:41:46 +0200721static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev)
Kim Phillips895ee682007-06-05 18:46:47 +0800722{
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300723 int temp;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300724
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200725 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
726 if (temp < 0)
727 return temp;
728
729 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andrew Lunn61111592017-07-30 22:41:46 +0200730 temp |= (MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200731 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
Andrew Lunn61111592017-07-30 22:41:46 +0200732 temp &= ~MII_M1111_RGMII_TX_DELAY;
733 temp |= MII_M1111_RGMII_RX_DELAY;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200734 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
Andrew Lunn61111592017-07-30 22:41:46 +0200735 temp &= ~MII_M1111_RGMII_RX_DELAY;
736 temp |= MII_M1111_RGMII_TX_DELAY;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200737 }
738
Andrew Lunn61111592017-07-30 22:41:46 +0200739 return phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
740}
741
742static int m88e1111_config_init_rgmii(struct phy_device *phydev)
743{
744 int temp;
745 int err;
746
747 err = m88e1111_config_init_rgmii_delays(phydev);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200748 if (err < 0)
749 return err;
750
751 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
752 if (temp < 0)
753 return temp;
754
755 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
756
757 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
758 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
759 else
760 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
761
762 return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
763}
764
765static int m88e1111_config_init_sgmii(struct phy_device *phydev)
766{
767 int err;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200768
Andrew Lunn865b813a2017-07-30 22:41:47 +0200769 err = m88e1111_config_init_hwcfg_mode(
770 phydev,
771 MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
772 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200773 if (err < 0)
774 return err;
775
776 /* make sure copper is selected */
Andrew Lunn52295662017-05-25 21:42:08 +0200777 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200778}
779
780static int m88e1111_config_init_rtbi(struct phy_device *phydev)
781{
Andrew Lunn61111592017-07-30 22:41:46 +0200782 int err;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200783
Andrew Lunn61111592017-07-30 22:41:46 +0200784 err = m88e1111_config_init_rgmii_delays(phydev);
785 if (err)
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200786 return err;
787
Andrew Lunn865b813a2017-07-30 22:41:47 +0200788 err = m88e1111_config_init_hwcfg_mode(
789 phydev,
790 MII_M1111_HWCFG_MODE_RTBI,
791 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200792 if (err < 0)
793 return err;
794
795 /* soft reset */
Andrew Lunn34386342017-07-30 22:41:45 +0200796 err = genphy_soft_reset(phydev);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200797 if (err < 0)
798 return err;
799
Andrew Lunn865b813a2017-07-30 22:41:47 +0200800 return m88e1111_config_init_hwcfg_mode(
801 phydev,
802 MII_M1111_HWCFG_MODE_RTBI,
803 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200804}
805
806static int m88e1111_config_init(struct phy_device *phydev)
807{
808 int err;
809
Florian Fainelli32a64162015-05-26 12:19:59 -0700810 if (phy_interface_is_rgmii(phydev)) {
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200811 err = m88e1111_config_init_rgmii(phydev);
812 if (err)
Kim Phillips895ee682007-06-05 18:46:47 +0800813 return err;
814 }
815
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500816 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200817 err = m88e1111_config_init_sgmii(phydev);
Madalin Bucur07151bc2015-08-07 17:07:50 +0800818 if (err < 0)
819 return err;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500820 }
821
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000822 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200823 err = m88e1111_config_init_rtbi(phydev);
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000824 if (err < 0)
825 return err;
826 }
827
David Daneycf41a512010-11-19 12:13:18 +0000828 err = marvell_of_reg_init(phydev);
829 if (err < 0)
830 return err;
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000831
Andrew Lunn34386342017-07-30 22:41:45 +0200832 return genphy_soft_reset(phydev);
Kim Phillips895ee682007-06-05 18:46:47 +0800833}
834
Clemens Gruberfdecf362016-06-11 17:21:26 +0200835static int m88e1121_config_init(struct phy_device *phydev)
836{
837 int err, oldpage;
838
Andrew Lunn52295662017-05-25 21:42:08 +0200839 oldpage = marvell_get_set_page(phydev, MII_MARVELL_LED_PAGE);
Andrew Lunn53798322017-05-25 21:42:07 +0200840 if (oldpage < 0)
841 return oldpage;
Clemens Gruberfdecf362016-06-11 17:21:26 +0200842
843 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
844 err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL,
845 MII_88E1121_PHY_LED_DEF);
846 if (err < 0)
847 return err;
848
Andrew Lunn6427bb22017-05-17 03:26:03 +0200849 marvell_set_page(phydev, oldpage);
Clemens Gruberfdecf362016-06-11 17:21:26 +0200850
851 /* Set marvell,reg-init configuration from device tree */
852 return marvell_config_init(phydev);
853}
854
Clemens Gruber407353e2016-02-23 20:16:58 +0100855static int m88e1510_config_init(struct phy_device *phydev)
856{
857 int err;
858 int temp;
859
860 /* SGMII-to-Copper mode initialization */
861 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
862 /* Select page 18 */
Andrew Lunn6427bb22017-05-17 03:26:03 +0200863 err = marvell_set_page(phydev, 18);
Clemens Gruber407353e2016-02-23 20:16:58 +0100864 if (err < 0)
865 return err;
866
867 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
868 temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1);
869 temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK;
870 temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII;
871 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
872 if (err < 0)
873 return err;
874
875 /* PHY reset is necessary after changing MODE[2:0] */
876 temp |= MII_88E1510_GEN_CTRL_REG_1_RESET;
877 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
878 if (err < 0)
879 return err;
880
881 /* Reset page selection */
Andrew Lunn52295662017-05-25 21:42:08 +0200882 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Clemens Gruber407353e2016-02-23 20:16:58 +0100883 if (err < 0)
884 return err;
885 }
886
Clemens Gruberfdecf362016-06-11 17:21:26 +0200887 return m88e1121_config_init(phydev);
Clemens Gruber407353e2016-02-23 20:16:58 +0100888}
889
Ron Madrid605f1962008-11-06 09:05:26 +0000890static int m88e1118_config_aneg(struct phy_device *phydev)
891{
892 int err;
893
Andrew Lunn34386342017-07-30 22:41:45 +0200894 err = genphy_soft_reset(phydev);
Ron Madrid605f1962008-11-06 09:05:26 +0000895 if (err < 0)
896 return err;
897
Andrew Lunnfecd5e92017-07-30 22:41:49 +0200898 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Ron Madrid605f1962008-11-06 09:05:26 +0000899 if (err < 0)
900 return err;
901
902 err = genphy_config_aneg(phydev);
903 return 0;
904}
905
906static int m88e1118_config_init(struct phy_device *phydev)
907{
908 int err;
909
910 /* Change address */
Andrew Lunn52295662017-05-25 21:42:08 +0200911 err = marvell_set_page(phydev, MII_MARVELL_MSCR_PAGE);
Ron Madrid605f1962008-11-06 09:05:26 +0000912 if (err < 0)
913 return err;
914
915 /* Enable 1000 Mbit */
916 err = phy_write(phydev, 0x15, 0x1070);
917 if (err < 0)
918 return err;
919
920 /* Change address */
Andrew Lunn52295662017-05-25 21:42:08 +0200921 err = marvell_set_page(phydev, MII_MARVELL_LED_PAGE);
Ron Madrid605f1962008-11-06 09:05:26 +0000922 if (err < 0)
923 return err;
924
925 /* Adjust LED Control */
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000926 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
927 err = phy_write(phydev, 0x10, 0x1100);
928 else
929 err = phy_write(phydev, 0x10, 0x021e);
Ron Madrid605f1962008-11-06 09:05:26 +0000930 if (err < 0)
931 return err;
932
David Daneycf41a512010-11-19 12:13:18 +0000933 err = marvell_of_reg_init(phydev);
934 if (err < 0)
935 return err;
936
Ron Madrid605f1962008-11-06 09:05:26 +0000937 /* Reset address */
Andrew Lunn52295662017-05-25 21:42:08 +0200938 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Ron Madrid605f1962008-11-06 09:05:26 +0000939 if (err < 0)
940 return err;
941
Andrew Lunn34386342017-07-30 22:41:45 +0200942 return genphy_soft_reset(phydev);
Ron Madrid605f1962008-11-06 09:05:26 +0000943}
944
David Daney90600732010-11-19 11:58:53 +0000945static int m88e1149_config_init(struct phy_device *phydev)
946{
947 int err;
948
949 /* Change address */
Andrew Lunn52295662017-05-25 21:42:08 +0200950 err = marvell_set_page(phydev, MII_MARVELL_MSCR_PAGE);
David Daney90600732010-11-19 11:58:53 +0000951 if (err < 0)
952 return err;
953
954 /* Enable 1000 Mbit */
955 err = phy_write(phydev, 0x15, 0x1048);
956 if (err < 0)
957 return err;
958
David Daneycf41a512010-11-19 12:13:18 +0000959 err = marvell_of_reg_init(phydev);
960 if (err < 0)
961 return err;
962
David Daney90600732010-11-19 11:58:53 +0000963 /* Reset address */
Andrew Lunn52295662017-05-25 21:42:08 +0200964 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
David Daney90600732010-11-19 11:58:53 +0000965 if (err < 0)
966 return err;
967
Andrew Lunn34386342017-07-30 22:41:45 +0200968 return genphy_soft_reset(phydev);
David Daney90600732010-11-19 11:58:53 +0000969}
970
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200971static int m88e1145_config_init_rgmii(struct phy_device *phydev)
972{
Andrew Lunn61111592017-07-30 22:41:46 +0200973 int temp;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200974 int err;
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200975
Andrew Lunn61111592017-07-30 22:41:46 +0200976 err = m88e1111_config_init_rgmii_delays(phydev);
Andrew Lunne1dde8d2017-05-17 03:26:02 +0200977 if (err < 0)
978 return err;
979
980 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
981 err = phy_write(phydev, 0x1d, 0x0012);
982 if (err < 0)
983 return err;
984
985 temp = phy_read(phydev, 0x1e);
986 if (temp < 0)
987 return temp;
988
989 temp &= 0xf03f;
990 temp |= 2 << 9; /* 36 ohm */
991 temp |= 2 << 6; /* 39 ohm */
992
993 err = phy_write(phydev, 0x1e, temp);
994 if (err < 0)
995 return err;
996
997 err = phy_write(phydev, 0x1d, 0x3);
998 if (err < 0)
999 return err;
1000
1001 err = phy_write(phydev, 0x1e, 0x8000);
1002 }
1003 return err;
1004}
1005
1006static int m88e1145_config_init_sgmii(struct phy_device *phydev)
1007{
Andrew Lunn865b813a2017-07-30 22:41:47 +02001008 return m88e1111_config_init_hwcfg_mode(
1009 phydev, MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
1010 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001011}
1012
Andy Fleming76884672007-02-09 18:13:58 -06001013static int m88e1145_config_init(struct phy_device *phydev)
1014{
1015 int err;
1016
1017 /* Take care of errata E0 & E1 */
1018 err = phy_write(phydev, 0x1d, 0x001b);
1019 if (err < 0)
1020 return err;
1021
1022 err = phy_write(phydev, 0x1e, 0x418f);
1023 if (err < 0)
1024 return err;
1025
1026 err = phy_write(phydev, 0x1d, 0x0016);
1027 if (err < 0)
1028 return err;
1029
1030 err = phy_write(phydev, 0x1e, 0xa2da);
1031 if (err < 0)
1032 return err;
1033
Kim Phillips895ee682007-06-05 18:46:47 +08001034 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001035 err = m88e1145_config_init_rgmii(phydev);
Andy Fleming76884672007-02-09 18:13:58 -06001036 if (err < 0)
1037 return err;
Andy Fleming76884672007-02-09 18:13:58 -06001038 }
1039
Viet Nga Daob0224172014-10-23 19:41:53 -07001040 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001041 err = m88e1145_config_init_sgmii(phydev);
Viet Nga Daob0224172014-10-23 19:41:53 -07001042 if (err < 0)
1043 return err;
1044 }
1045
David Daneycf41a512010-11-19 12:13:18 +00001046 err = marvell_of_reg_init(phydev);
1047 if (err < 0)
1048 return err;
1049
Andy Fleming76884672007-02-09 18:13:58 -06001050 return 0;
1051}
Andy Fleming00db8182005-07-30 19:31:23 -04001052
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001053/**
1054 * fiber_lpa_to_ethtool_lpa_t
1055 * @lpa: value of the MII_LPA register for fiber link
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001056 *
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001057 * A small helper function that translates MII_LPA
1058 * bits to ethtool LP advertisement settings.
1059 */
1060static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa)
1061{
1062 u32 result = 0;
1063
1064 if (lpa & LPA_FIBER_1000HALF)
1065 result |= ADVERTISED_1000baseT_Half;
1066 if (lpa & LPA_FIBER_1000FULL)
1067 result |= ADVERTISED_1000baseT_Full;
1068
1069 return result;
1070}
1071
1072/**
1073 * marvell_update_link - update link status in real time in @phydev
1074 * @phydev: target phy_device struct
1075 *
1076 * Description: Update the value in phydev->link to reflect the
1077 * current link value.
1078 */
1079static int marvell_update_link(struct phy_device *phydev, int fiber)
1080{
1081 int status;
1082
1083 /* Use the generic register for copper link, or specific
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001084 * register for fiber case
1085 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001086 if (fiber) {
1087 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1088 if (status < 0)
1089 return status;
1090
1091 if ((status & REGISTER_LINK_STATUS) == 0)
1092 phydev->link = 0;
1093 else
1094 phydev->link = 1;
1095 } else {
1096 return genphy_update_link(phydev);
1097 }
1098
1099 return 0;
1100}
1101
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001102static int marvell_read_status_page_an(struct phy_device *phydev,
1103 int fiber)
1104{
1105 int status;
1106 int lpa;
1107 int lpagb;
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001108
1109 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1110 if (status < 0)
1111 return status;
1112
1113 lpa = phy_read(phydev, MII_LPA);
1114 if (lpa < 0)
1115 return lpa;
1116
1117 lpagb = phy_read(phydev, MII_STAT1000);
1118 if (lpagb < 0)
1119 return lpagb;
1120
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001121 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
1122 phydev->duplex = DUPLEX_FULL;
1123 else
1124 phydev->duplex = DUPLEX_HALF;
1125
1126 status = status & MII_M1011_PHY_STATUS_SPD_MASK;
1127 phydev->pause = 0;
1128 phydev->asym_pause = 0;
1129
1130 switch (status) {
1131 case MII_M1011_PHY_STATUS_1000:
1132 phydev->speed = SPEED_1000;
1133 break;
1134
1135 case MII_M1011_PHY_STATUS_100:
1136 phydev->speed = SPEED_100;
1137 break;
1138
1139 default:
1140 phydev->speed = SPEED_10;
1141 break;
1142 }
1143
1144 if (!fiber) {
1145 phydev->lp_advertising =
1146 mii_stat1000_to_ethtool_lpa_t(lpagb) |
1147 mii_lpa_to_ethtool_lpa_t(lpa);
1148
1149 if (phydev->duplex == DUPLEX_FULL) {
1150 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
1151 phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
1152 }
1153 } else {
1154 /* The fiber link is only 1000M capable */
1155 phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa);
1156
1157 if (phydev->duplex == DUPLEX_FULL) {
1158 if (!(lpa & LPA_PAUSE_FIBER)) {
1159 phydev->pause = 0;
1160 phydev->asym_pause = 0;
1161 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) {
1162 phydev->pause = 1;
1163 phydev->asym_pause = 1;
1164 } else {
1165 phydev->pause = 1;
1166 phydev->asym_pause = 0;
1167 }
1168 }
1169 }
1170 return 0;
1171}
1172
1173static int marvell_read_status_page_fixed(struct phy_device *phydev)
1174{
1175 int bmcr = phy_read(phydev, MII_BMCR);
1176
1177 if (bmcr < 0)
1178 return bmcr;
1179
1180 if (bmcr & BMCR_FULLDPLX)
1181 phydev->duplex = DUPLEX_FULL;
1182 else
1183 phydev->duplex = DUPLEX_HALF;
1184
1185 if (bmcr & BMCR_SPEED1000)
1186 phydev->speed = SPEED_1000;
1187 else if (bmcr & BMCR_SPEED100)
1188 phydev->speed = SPEED_100;
1189 else
1190 phydev->speed = SPEED_10;
1191
1192 phydev->pause = 0;
1193 phydev->asym_pause = 0;
1194 phydev->lp_advertising = 0;
1195
1196 return 0;
1197}
1198
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001199/* marvell_read_status_page
1200 *
Jeff Garzikf0c88f92008-03-25 23:53:24 -04001201 * Description:
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001202 * Check the link, then figure out the current state
1203 * by comparing what we advertise with what the link partner
1204 * advertises. Start by checking the gigabit possibilities,
1205 * then move on to 10/100.
1206 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001207static int marvell_read_status_page(struct phy_device *phydev, int page)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001208{
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001209 int fiber;
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001210 int err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001211
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001212 /* Detect and update the link, but return if there
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001213 * was an error
1214 */
Andrew Lunn52295662017-05-25 21:42:08 +02001215 if (page == MII_MARVELL_FIBER_PAGE)
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001216 fiber = 1;
1217 else
1218 fiber = 0;
1219
1220 err = marvell_update_link(phydev, fiber);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001221 if (err)
1222 return err;
1223
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001224 if (phydev->autoneg == AUTONEG_ENABLE)
1225 err = marvell_read_status_page_an(phydev, fiber);
1226 else
1227 err = marvell_read_status_page_fixed(phydev);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001228
Andrew Lunne1dde8d2017-05-17 03:26:02 +02001229 return err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001230}
1231
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001232/* marvell_read_status
1233 *
1234 * Some Marvell's phys have two modes: fiber and copper.
1235 * Both need status checked.
1236 * Description:
1237 * First, check the fiber link and status.
1238 * If the fiber link is down, check the copper link and status which
1239 * will be the default value if both link are down.
1240 */
1241static int marvell_read_status(struct phy_device *phydev)
1242{
1243 int err;
1244
1245 /* Check the fiber mode first */
Russell Kinga13c06522017-01-10 23:13:45 +00001246 if (phydev->supported & SUPPORTED_FIBRE &&
1247 phydev->interface != PHY_INTERFACE_MODE_SGMII) {
Andrew Lunn52295662017-05-25 21:42:08 +02001248 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001249 if (err < 0)
1250 goto error;
1251
Andrew Lunn52295662017-05-25 21:42:08 +02001252 err = marvell_read_status_page(phydev, MII_MARVELL_FIBER_PAGE);
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001253 if (err < 0)
1254 goto error;
1255
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001256 /* If the fiber link is up, it is the selected and
1257 * used link. In this case, we need to stay in the
1258 * fiber page. Please to be careful about that, avoid
1259 * to restore Copper page in other functions which
1260 * could break the behaviour for some fiber phy like
1261 * 88E1512.
1262 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001263 if (phydev->link)
1264 return 0;
1265
1266 /* If fiber link is down, check and save copper mode state */
Andrew Lunn52295662017-05-25 21:42:08 +02001267 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001268 if (err < 0)
1269 goto error;
1270 }
1271
Andrew Lunn52295662017-05-25 21:42:08 +02001272 return marvell_read_status_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001273
1274error:
Andrew Lunn52295662017-05-25 21:42:08 +02001275 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001276 return err;
1277}
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001278
1279/* marvell_suspend
1280 *
1281 * Some Marvell's phys have two modes: fiber and copper.
1282 * Both need to be suspended
1283 */
1284static int marvell_suspend(struct phy_device *phydev)
1285{
1286 int err;
1287
1288 /* Suspend the fiber mode first */
1289 if (!(phydev->supported & SUPPORTED_FIBRE)) {
Andrew Lunn52295662017-05-25 21:42:08 +02001290 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001291 if (err < 0)
1292 goto error;
1293
1294 /* With the page set, use the generic suspend */
1295 err = genphy_suspend(phydev);
1296 if (err < 0)
1297 goto error;
1298
1299 /* Then, the copper link */
Andrew Lunn52295662017-05-25 21:42:08 +02001300 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001301 if (err < 0)
1302 goto error;
1303 }
1304
1305 /* With the page set, use the generic suspend */
1306 return genphy_suspend(phydev);
1307
1308error:
Andrew Lunn52295662017-05-25 21:42:08 +02001309 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001310 return err;
1311}
1312
1313/* marvell_resume
1314 *
1315 * Some Marvell's phys have two modes: fiber and copper.
1316 * Both need to be resumed
1317 */
1318static int marvell_resume(struct phy_device *phydev)
1319{
1320 int err;
1321
1322 /* Resume the fiber mode first */
1323 if (!(phydev->supported & SUPPORTED_FIBRE)) {
Andrew Lunn52295662017-05-25 21:42:08 +02001324 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001325 if (err < 0)
1326 goto error;
1327
1328 /* With the page set, use the generic resume */
1329 err = genphy_resume(phydev);
1330 if (err < 0)
1331 goto error;
1332
1333 /* Then, the copper link */
Andrew Lunn52295662017-05-25 21:42:08 +02001334 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001335 if (err < 0)
1336 goto error;
1337 }
1338
1339 /* With the page set, use the generic resume */
1340 return genphy_resume(phydev);
1341
1342error:
Andrew Lunn52295662017-05-25 21:42:08 +02001343 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001344 return err;
1345}
1346
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001347static int marvell_aneg_done(struct phy_device *phydev)
1348{
1349 int retval = phy_read(phydev, MII_M1011_PHY_STATUS);
Andrew Lunne69d9ed2017-05-17 03:26:00 +02001350
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001351 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
1352}
1353
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001354static int m88e1121_did_interrupt(struct phy_device *phydev)
1355{
1356 int imask;
1357
1358 imask = phy_read(phydev, MII_M1011_IEVENT);
1359
1360 if (imask & MII_M1011_IMASK_INIT)
1361 return 1;
1362
1363 return 0;
1364}
1365
Andrew Lunn23beb382017-05-17 03:26:04 +02001366static void m88e1318_get_wol(struct phy_device *phydev,
1367 struct ethtool_wolinfo *wol)
Michael Stapelberg3871c382013-03-11 13:56:45 +00001368{
1369 wol->supported = WAKE_MAGIC;
1370 wol->wolopts = 0;
1371
Andrew Lunn52295662017-05-25 21:42:08 +02001372 if (marvell_set_page(phydev, MII_MARVELL_WOL_PAGE) < 0)
Michael Stapelberg3871c382013-03-11 13:56:45 +00001373 return;
1374
1375 if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) &
1376 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
1377 wol->wolopts |= WAKE_MAGIC;
1378
Andrew Lunn52295662017-05-25 21:42:08 +02001379 if (marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE) < 0)
Michael Stapelberg3871c382013-03-11 13:56:45 +00001380 return;
1381}
1382
Andrew Lunn23beb382017-05-17 03:26:04 +02001383static int m88e1318_set_wol(struct phy_device *phydev,
1384 struct ethtool_wolinfo *wol)
Michael Stapelberg3871c382013-03-11 13:56:45 +00001385{
1386 int err, oldpage, temp;
1387
Andrew Lunn6427bb22017-05-17 03:26:03 +02001388 oldpage = marvell_get_page(phydev);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001389
1390 if (wol->wolopts & WAKE_MAGIC) {
1391 /* Explicitly switch to page 0x00, just to be sure */
Andrew Lunn52295662017-05-25 21:42:08 +02001392 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001393 if (err < 0)
1394 return err;
1395
1396 /* Enable the WOL interrupt */
1397 temp = phy_read(phydev, MII_88E1318S_PHY_CSIER);
1398 temp |= MII_88E1318S_PHY_CSIER_WOL_EIE;
1399 err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp);
1400 if (err < 0)
1401 return err;
1402
Andrew Lunn52295662017-05-25 21:42:08 +02001403 err = marvell_set_page(phydev, MII_MARVELL_LED_PAGE);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001404 if (err < 0)
1405 return err;
1406
1407 /* Setup LED[2] as interrupt pin (active low) */
1408 temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR);
1409 temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT;
1410 temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE;
1411 temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW;
1412 err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp);
1413 if (err < 0)
1414 return err;
1415
Andrew Lunn52295662017-05-25 21:42:08 +02001416 err = marvell_set_page(phydev, MII_MARVELL_WOL_PAGE);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001417 if (err < 0)
1418 return err;
1419
1420 /* Store the device address for the magic packet */
1421 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
1422 ((phydev->attached_dev->dev_addr[5] << 8) |
1423 phydev->attached_dev->dev_addr[4]));
1424 if (err < 0)
1425 return err;
1426 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
1427 ((phydev->attached_dev->dev_addr[3] << 8) |
1428 phydev->attached_dev->dev_addr[2]));
1429 if (err < 0)
1430 return err;
1431 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
1432 ((phydev->attached_dev->dev_addr[1] << 8) |
1433 phydev->attached_dev->dev_addr[0]));
1434 if (err < 0)
1435 return err;
1436
1437 /* Clear WOL status and enable magic packet matching */
1438 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1439 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1440 temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1441 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1442 if (err < 0)
1443 return err;
1444 } else {
Andrew Lunn52295662017-05-25 21:42:08 +02001445 err = marvell_set_page(phydev, MII_MARVELL_WOL_PAGE);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001446 if (err < 0)
1447 return err;
1448
1449 /* Clear WOL status and disable magic packet matching */
1450 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1451 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1452 temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1453 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1454 if (err < 0)
1455 return err;
1456 }
1457
Andrew Lunn6427bb22017-05-17 03:26:03 +02001458 err = marvell_set_page(phydev, oldpage);
Michael Stapelberg3871c382013-03-11 13:56:45 +00001459 if (err < 0)
1460 return err;
1461
1462 return 0;
1463}
1464
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001465static int marvell_get_sset_count(struct phy_device *phydev)
1466{
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +02001467 if (phydev->supported & SUPPORTED_FIBRE)
1468 return ARRAY_SIZE(marvell_hw_stats);
1469 else
1470 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001471}
1472
1473static void marvell_get_strings(struct phy_device *phydev, u8 *data)
1474{
1475 int i;
1476
1477 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1478 memcpy(data + i * ETH_GSTRING_LEN,
1479 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1480 }
1481}
1482
1483#ifndef UINT64_MAX
Andrew Lunn8cf8b872017-07-30 22:41:44 +02001484#define UINT64_MAX (u64)(~((u64)0))
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001485#endif
1486static u64 marvell_get_stat(struct phy_device *phydev, int i)
1487{
1488 struct marvell_hw_stat stat = marvell_hw_stats[i];
1489 struct marvell_priv *priv = phydev->priv;
Andrew Lunn53798322017-05-25 21:42:07 +02001490 int oldpage, val;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001491 u64 ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001492
Andrew Lunn53798322017-05-25 21:42:07 +02001493 oldpage = marvell_get_set_page(phydev, stat.page);
1494 if (oldpage < 0)
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001495 return UINT64_MAX;
1496
1497 val = phy_read(phydev, stat.reg);
1498 if (val < 0) {
Andrew Lunn321b4d42016-02-20 00:35:29 +01001499 ret = UINT64_MAX;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001500 } else {
1501 val = val & ((1 << stat.bits) - 1);
1502 priv->stats[i] += val;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001503 ret = priv->stats[i];
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001504 }
1505
Andrew Lunn6427bb22017-05-17 03:26:03 +02001506 marvell_set_page(phydev, oldpage);
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001507
Andrew Lunn321b4d42016-02-20 00:35:29 +01001508 return ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001509}
1510
1511static void marvell_get_stats(struct phy_device *phydev,
1512 struct ethtool_stats *stats, u64 *data)
1513{
1514 int i;
1515
1516 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
1517 data[i] = marvell_get_stat(phydev, i);
1518}
1519
Andrew Lunn0b046802017-01-20 01:37:49 +01001520#ifdef CONFIG_HWMON
1521static int m88e1121_get_temp(struct phy_device *phydev, long *temp)
1522{
Andrew Lunn975b3882017-05-25 21:42:06 +02001523 int oldpage;
Andrew Lunn0b046802017-01-20 01:37:49 +01001524 int ret;
1525 int val;
1526
1527 *temp = 0;
1528
1529 mutex_lock(&phydev->lock);
1530
Andrew Lunn52295662017-05-25 21:42:08 +02001531 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
Andrew Lunn975b3882017-05-25 21:42:06 +02001532 if (oldpage < 0) {
1533 mutex_unlock(&phydev->lock);
1534 return oldpage;
1535 }
1536
Andrew Lunn0b046802017-01-20 01:37:49 +01001537 /* Enable temperature sensor */
1538 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1539 if (ret < 0)
1540 goto error;
1541
1542 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1543 ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1544 if (ret < 0)
1545 goto error;
1546
1547 /* Wait for temperature to stabilize */
1548 usleep_range(10000, 12000);
1549
1550 val = phy_read(phydev, MII_88E1121_MISC_TEST);
1551 if (val < 0) {
1552 ret = val;
1553 goto error;
1554 }
1555
1556 /* Disable temperature sensor */
1557 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1558 ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1559 if (ret < 0)
1560 goto error;
1561
1562 *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000;
1563
1564error:
Andrew Lunn975b3882017-05-25 21:42:06 +02001565 marvell_set_page(phydev, oldpage);
Andrew Lunn0b046802017-01-20 01:37:49 +01001566 mutex_unlock(&phydev->lock);
1567
1568 return ret;
1569}
1570
1571static int m88e1121_hwmon_read(struct device *dev,
1572 enum hwmon_sensor_types type,
1573 u32 attr, int channel, long *temp)
1574{
1575 struct phy_device *phydev = dev_get_drvdata(dev);
1576 int err;
1577
1578 switch (attr) {
1579 case hwmon_temp_input:
1580 err = m88e1121_get_temp(phydev, temp);
1581 break;
1582 default:
1583 return -EOPNOTSUPP;
1584 }
1585
1586 return err;
1587}
1588
1589static umode_t m88e1121_hwmon_is_visible(const void *data,
1590 enum hwmon_sensor_types type,
1591 u32 attr, int channel)
1592{
1593 if (type != hwmon_temp)
1594 return 0;
1595
1596 switch (attr) {
1597 case hwmon_temp_input:
1598 return 0444;
1599 default:
1600 return 0;
1601 }
1602}
1603
1604static u32 m88e1121_hwmon_chip_config[] = {
1605 HWMON_C_REGISTER_TZ,
1606 0
1607};
1608
1609static const struct hwmon_channel_info m88e1121_hwmon_chip = {
1610 .type = hwmon_chip,
1611 .config = m88e1121_hwmon_chip_config,
1612};
1613
1614static u32 m88e1121_hwmon_temp_config[] = {
1615 HWMON_T_INPUT,
1616 0
1617};
1618
1619static const struct hwmon_channel_info m88e1121_hwmon_temp = {
1620 .type = hwmon_temp,
1621 .config = m88e1121_hwmon_temp_config,
1622};
1623
1624static const struct hwmon_channel_info *m88e1121_hwmon_info[] = {
1625 &m88e1121_hwmon_chip,
1626 &m88e1121_hwmon_temp,
1627 NULL
1628};
1629
1630static const struct hwmon_ops m88e1121_hwmon_hwmon_ops = {
1631 .is_visible = m88e1121_hwmon_is_visible,
1632 .read = m88e1121_hwmon_read,
1633};
1634
1635static const struct hwmon_chip_info m88e1121_hwmon_chip_info = {
1636 .ops = &m88e1121_hwmon_hwmon_ops,
1637 .info = m88e1121_hwmon_info,
1638};
1639
1640static int m88e1510_get_temp(struct phy_device *phydev, long *temp)
1641{
Andrew Lunn975b3882017-05-25 21:42:06 +02001642 int oldpage;
Andrew Lunn0b046802017-01-20 01:37:49 +01001643 int ret;
1644
1645 *temp = 0;
1646
1647 mutex_lock(&phydev->lock);
1648
Andrew Lunn52295662017-05-25 21:42:08 +02001649 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
Andrew Lunn975b3882017-05-25 21:42:06 +02001650 if (oldpage < 0) {
1651 mutex_unlock(&phydev->lock);
1652 return oldpage;
1653 }
1654
Andrew Lunn0b046802017-01-20 01:37:49 +01001655 ret = phy_read(phydev, MII_88E1510_TEMP_SENSOR);
1656 if (ret < 0)
1657 goto error;
1658
1659 *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000;
1660
1661error:
Andrew Lunn975b3882017-05-25 21:42:06 +02001662 marvell_set_page(phydev, oldpage);
Andrew Lunn0b046802017-01-20 01:37:49 +01001663 mutex_unlock(&phydev->lock);
1664
1665 return ret;
1666}
1667
Colin Ian Kingf0a45812017-06-02 15:13:34 +01001668static int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp)
Andrew Lunn0b046802017-01-20 01:37:49 +01001669{
Andrew Lunn975b3882017-05-25 21:42:06 +02001670 int oldpage;
Andrew Lunn0b046802017-01-20 01:37:49 +01001671 int ret;
1672
1673 *temp = 0;
1674
1675 mutex_lock(&phydev->lock);
Andrew Lunn53798322017-05-25 21:42:07 +02001676
Andrew Lunn52295662017-05-25 21:42:08 +02001677 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
Andrew Lunn975b3882017-05-25 21:42:06 +02001678 if (oldpage < 0) {
1679 mutex_unlock(&phydev->lock);
1680 return oldpage;
1681 }
Andrew Lunn0b046802017-01-20 01:37:49 +01001682
Andrew Lunn0b046802017-01-20 01:37:49 +01001683 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1684 if (ret < 0)
1685 goto error;
1686
1687 *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >>
1688 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25;
1689 /* convert to mC */
1690 *temp *= 1000;
1691
1692error:
Andrew Lunn975b3882017-05-25 21:42:06 +02001693 marvell_set_page(phydev, oldpage);
Andrew Lunn0b046802017-01-20 01:37:49 +01001694 mutex_unlock(&phydev->lock);
1695
1696 return ret;
1697}
1698
Colin Ian Kingf0a45812017-06-02 15:13:34 +01001699static int m88e1510_set_temp_critical(struct phy_device *phydev, long temp)
Andrew Lunn0b046802017-01-20 01:37:49 +01001700{
Andrew Lunn975b3882017-05-25 21:42:06 +02001701 int oldpage;
Andrew Lunn0b046802017-01-20 01:37:49 +01001702 int ret;
1703
1704 mutex_lock(&phydev->lock);
1705
Andrew Lunn52295662017-05-25 21:42:08 +02001706 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
Andrew Lunn975b3882017-05-25 21:42:06 +02001707 if (oldpage < 0) {
1708 mutex_unlock(&phydev->lock);
1709 return oldpage;
1710 }
1711
Andrew Lunn0b046802017-01-20 01:37:49 +01001712 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1713 if (ret < 0)
1714 goto error;
1715
1716 temp = temp / 1000;
1717 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
1718 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1719 (ret & ~MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) |
1720 (temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT));
1721
1722error:
Andrew Lunn975b3882017-05-25 21:42:06 +02001723 marvell_set_page(phydev, oldpage);
Andrew Lunn0b046802017-01-20 01:37:49 +01001724 mutex_unlock(&phydev->lock);
1725
1726 return ret;
1727}
1728
Colin Ian Kingf0a45812017-06-02 15:13:34 +01001729static int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm)
Andrew Lunn0b046802017-01-20 01:37:49 +01001730{
Andrew Lunn975b3882017-05-25 21:42:06 +02001731 int oldpage;
Andrew Lunn0b046802017-01-20 01:37:49 +01001732 int ret;
1733
1734 *alarm = false;
1735
1736 mutex_lock(&phydev->lock);
1737
Andrew Lunn52295662017-05-25 21:42:08 +02001738 oldpage = marvell_get_set_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
Andrew Lunn975b3882017-05-25 21:42:06 +02001739 if (oldpage < 0) {
1740 mutex_unlock(&phydev->lock);
1741 return oldpage;
1742 }
1743
Andrew Lunn0b046802017-01-20 01:37:49 +01001744 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1745 if (ret < 0)
1746 goto error;
1747 *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ);
1748
1749error:
Andrew Lunn975b3882017-05-25 21:42:06 +02001750 marvell_set_page(phydev, oldpage);
Andrew Lunn0b046802017-01-20 01:37:49 +01001751 mutex_unlock(&phydev->lock);
1752
1753 return ret;
1754}
1755
1756static int m88e1510_hwmon_read(struct device *dev,
1757 enum hwmon_sensor_types type,
1758 u32 attr, int channel, long *temp)
1759{
1760 struct phy_device *phydev = dev_get_drvdata(dev);
1761 int err;
1762
1763 switch (attr) {
1764 case hwmon_temp_input:
1765 err = m88e1510_get_temp(phydev, temp);
1766 break;
1767 case hwmon_temp_crit:
1768 err = m88e1510_get_temp_critical(phydev, temp);
1769 break;
1770 case hwmon_temp_max_alarm:
1771 err = m88e1510_get_temp_alarm(phydev, temp);
1772 break;
1773 default:
1774 return -EOPNOTSUPP;
1775 }
1776
1777 return err;
1778}
1779
1780static int m88e1510_hwmon_write(struct device *dev,
1781 enum hwmon_sensor_types type,
1782 u32 attr, int channel, long temp)
1783{
1784 struct phy_device *phydev = dev_get_drvdata(dev);
1785 int err;
1786
1787 switch (attr) {
1788 case hwmon_temp_crit:
1789 err = m88e1510_set_temp_critical(phydev, temp);
1790 break;
1791 default:
1792 return -EOPNOTSUPP;
1793 }
1794 return err;
1795}
1796
1797static umode_t m88e1510_hwmon_is_visible(const void *data,
1798 enum hwmon_sensor_types type,
1799 u32 attr, int channel)
1800{
1801 if (type != hwmon_temp)
1802 return 0;
1803
1804 switch (attr) {
1805 case hwmon_temp_input:
1806 case hwmon_temp_max_alarm:
1807 return 0444;
1808 case hwmon_temp_crit:
1809 return 0644;
1810 default:
1811 return 0;
1812 }
1813}
1814
1815static u32 m88e1510_hwmon_temp_config[] = {
1816 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM,
1817 0
1818};
1819
1820static const struct hwmon_channel_info m88e1510_hwmon_temp = {
1821 .type = hwmon_temp,
1822 .config = m88e1510_hwmon_temp_config,
1823};
1824
1825static const struct hwmon_channel_info *m88e1510_hwmon_info[] = {
1826 &m88e1121_hwmon_chip,
1827 &m88e1510_hwmon_temp,
1828 NULL
1829};
1830
1831static const struct hwmon_ops m88e1510_hwmon_hwmon_ops = {
1832 .is_visible = m88e1510_hwmon_is_visible,
1833 .read = m88e1510_hwmon_read,
1834 .write = m88e1510_hwmon_write,
1835};
1836
1837static const struct hwmon_chip_info m88e1510_hwmon_chip_info = {
1838 .ops = &m88e1510_hwmon_hwmon_ops,
1839 .info = m88e1510_hwmon_info,
1840};
1841
1842static int marvell_hwmon_name(struct phy_device *phydev)
1843{
1844 struct marvell_priv *priv = phydev->priv;
1845 struct device *dev = &phydev->mdio.dev;
1846 const char *devname = dev_name(dev);
1847 size_t len = strlen(devname);
1848 int i, j;
1849
1850 priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL);
1851 if (!priv->hwmon_name)
1852 return -ENOMEM;
1853
1854 for (i = j = 0; i < len && devname[i]; i++) {
1855 if (isalnum(devname[i]))
1856 priv->hwmon_name[j++] = devname[i];
1857 }
1858
1859 return 0;
1860}
1861
1862static int marvell_hwmon_probe(struct phy_device *phydev,
1863 const struct hwmon_chip_info *chip)
1864{
1865 struct marvell_priv *priv = phydev->priv;
1866 struct device *dev = &phydev->mdio.dev;
1867 int err;
1868
1869 err = marvell_hwmon_name(phydev);
1870 if (err)
1871 return err;
1872
1873 priv->hwmon_dev = devm_hwmon_device_register_with_info(
1874 dev, priv->hwmon_name, phydev, chip, NULL);
1875
1876 return PTR_ERR_OR_ZERO(priv->hwmon_dev);
1877}
1878
1879static int m88e1121_hwmon_probe(struct phy_device *phydev)
1880{
1881 return marvell_hwmon_probe(phydev, &m88e1121_hwmon_chip_info);
1882}
1883
1884static int m88e1510_hwmon_probe(struct phy_device *phydev)
1885{
1886 return marvell_hwmon_probe(phydev, &m88e1510_hwmon_chip_info);
1887}
1888#else
1889static int m88e1121_hwmon_probe(struct phy_device *phydev)
1890{
1891 return 0;
1892}
1893
1894static int m88e1510_hwmon_probe(struct phy_device *phydev)
1895{
1896 return 0;
1897}
1898#endif
1899
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001900static int marvell_probe(struct phy_device *phydev)
1901{
1902 struct marvell_priv *priv;
1903
Andrew Lunne5a03bf2016-01-06 20:11:16 +01001904 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001905 if (!priv)
1906 return -ENOMEM;
1907
1908 phydev->priv = priv;
1909
1910 return 0;
1911}
1912
Andrew Lunn0b046802017-01-20 01:37:49 +01001913static int m88e1121_probe(struct phy_device *phydev)
1914{
1915 int err;
1916
1917 err = marvell_probe(phydev);
1918 if (err)
1919 return err;
1920
1921 return m88e1121_hwmon_probe(phydev);
1922}
1923
1924static int m88e1510_probe(struct phy_device *phydev)
1925{
1926 int err;
1927
1928 err = marvell_probe(phydev);
1929 if (err)
1930 return err;
1931
1932 return m88e1510_hwmon_probe(phydev);
1933}
1934
Olof Johanssone5479232007-07-03 16:23:46 -05001935static struct phy_driver marvell_drivers[] = {
1936 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001937 .phy_id = MARVELL_PHY_ID_88E1101,
1938 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001939 .name = "Marvell 88E1101",
1940 .features = PHY_GBIT_FEATURES,
1941 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01001942 .probe = marvell_probe,
Clemens Gruber79be1a12016-02-15 23:46:45 +01001943 .config_init = &marvell_config_init,
Andrew Lunnf2899782017-05-23 17:49:13 +02001944 .config_aneg = &m88e1101_config_aneg,
Olof Johanssone5479232007-07-03 16:23:46 -05001945 .read_status = &genphy_read_status,
1946 .ack_interrupt = &marvell_ack_interrupt,
1947 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001948 .resume = &genphy_resume,
1949 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001950 .get_sset_count = marvell_get_sset_count,
1951 .get_strings = marvell_get_strings,
1952 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001953 },
1954 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001955 .phy_id = MARVELL_PHY_ID_88E1112,
1956 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johansson85cfb532007-07-03 16:24:32 -05001957 .name = "Marvell 88E1112",
1958 .features = PHY_GBIT_FEATURES,
1959 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001960 .probe = marvell_probe,
Olof Johansson85cfb532007-07-03 16:24:32 -05001961 .config_init = &m88e1111_config_init,
1962 .config_aneg = &marvell_config_aneg,
1963 .read_status = &genphy_read_status,
1964 .ack_interrupt = &marvell_ack_interrupt,
1965 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001966 .resume = &genphy_resume,
1967 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001968 .get_sset_count = marvell_get_sset_count,
1969 .get_strings = marvell_get_strings,
1970 .get_stats = marvell_get_stats,
Olof Johansson85cfb532007-07-03 16:24:32 -05001971 },
1972 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001973 .phy_id = MARVELL_PHY_ID_88E1111,
1974 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001975 .name = "Marvell 88E1111",
1976 .features = PHY_GBIT_FEATURES,
1977 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001978 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001979 .config_init = &m88e1111_config_init,
Harini Katakam3ec0a0f2016-06-27 13:09:59 +05301980 .config_aneg = &m88e1111_config_aneg,
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001981 .read_status = &marvell_read_status,
Olof Johanssone5479232007-07-03 16:23:46 -05001982 .ack_interrupt = &marvell_ack_interrupt,
1983 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001984 .resume = &genphy_resume,
1985 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001986 .get_sset_count = marvell_get_sset_count,
1987 .get_strings = marvell_get_strings,
1988 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001989 },
1990 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001991 .phy_id = MARVELL_PHY_ID_88E1118,
1992 .phy_id_mask = MARVELL_PHY_ID_MASK,
Ron Madrid605f1962008-11-06 09:05:26 +00001993 .name = "Marvell 88E1118",
1994 .features = PHY_GBIT_FEATURES,
1995 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001996 .probe = marvell_probe,
Ron Madrid605f1962008-11-06 09:05:26 +00001997 .config_init = &m88e1118_config_init,
1998 .config_aneg = &m88e1118_config_aneg,
1999 .read_status = &genphy_read_status,
2000 .ack_interrupt = &marvell_ack_interrupt,
2001 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002002 .resume = &genphy_resume,
2003 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002004 .get_sset_count = marvell_get_sset_count,
2005 .get_strings = marvell_get_strings,
2006 .get_stats = marvell_get_stats,
Ron Madrid605f1962008-11-06 09:05:26 +00002007 },
2008 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002009 .phy_id = MARVELL_PHY_ID_88E1121R,
2010 .phy_id_mask = MARVELL_PHY_ID_MASK,
Sergei Poselenov140bc922009-04-07 02:01:41 +00002011 .name = "Marvell 88E1121R",
2012 .features = PHY_GBIT_FEATURES,
2013 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01002014 .probe = &m88e1121_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02002015 .config_init = &m88e1121_config_init,
Sergei Poselenov140bc922009-04-07 02:01:41 +00002016 .config_aneg = &m88e1121_config_aneg,
2017 .read_status = &marvell_read_status,
2018 .ack_interrupt = &marvell_ack_interrupt,
2019 .config_intr = &marvell_config_intr,
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00002020 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002021 .resume = &genphy_resume,
2022 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002023 .get_sset_count = marvell_get_sset_count,
2024 .get_strings = marvell_get_strings,
2025 .get_stats = marvell_get_stats,
Sergei Poselenov140bc922009-04-07 02:01:41 +00002026 },
2027 {
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07002028 .phy_id = MARVELL_PHY_ID_88E1318S,
Linus Torvalds6ba74012010-08-04 11:47:58 -07002029 .phy_id_mask = MARVELL_PHY_ID_MASK,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07002030 .name = "Marvell 88E1318S",
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07002031 .features = PHY_GBIT_FEATURES,
2032 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002033 .probe = marvell_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02002034 .config_init = &m88e1121_config_init,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07002035 .config_aneg = &m88e1318_config_aneg,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07002036 .read_status = &marvell_read_status,
2037 .ack_interrupt = &marvell_ack_interrupt,
2038 .config_intr = &marvell_config_intr,
2039 .did_interrupt = &m88e1121_did_interrupt,
Michael Stapelberg3871c382013-03-11 13:56:45 +00002040 .get_wol = &m88e1318_get_wol,
2041 .set_wol = &m88e1318_set_wol,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002042 .resume = &genphy_resume,
2043 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002044 .get_sset_count = marvell_get_sset_count,
2045 .get_strings = marvell_get_strings,
2046 .get_stats = marvell_get_stats,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07002047 },
2048 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002049 .phy_id = MARVELL_PHY_ID_88E1145,
2050 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05002051 .name = "Marvell 88E1145",
2052 .features = PHY_GBIT_FEATURES,
2053 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002054 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05002055 .config_init = &m88e1145_config_init,
2056 .config_aneg = &marvell_config_aneg,
2057 .read_status = &genphy_read_status,
2058 .ack_interrupt = &marvell_ack_interrupt,
2059 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002060 .resume = &genphy_resume,
2061 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002062 .get_sset_count = marvell_get_sset_count,
2063 .get_strings = marvell_get_strings,
2064 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002065 },
2066 {
David Daney90600732010-11-19 11:58:53 +00002067 .phy_id = MARVELL_PHY_ID_88E1149R,
2068 .phy_id_mask = MARVELL_PHY_ID_MASK,
2069 .name = "Marvell 88E1149R",
2070 .features = PHY_GBIT_FEATURES,
2071 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002072 .probe = marvell_probe,
David Daney90600732010-11-19 11:58:53 +00002073 .config_init = &m88e1149_config_init,
2074 .config_aneg = &m88e1118_config_aneg,
2075 .read_status = &genphy_read_status,
2076 .ack_interrupt = &marvell_ack_interrupt,
2077 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002078 .resume = &genphy_resume,
2079 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002080 .get_sset_count = marvell_get_sset_count,
2081 .get_strings = marvell_get_strings,
2082 .get_stats = marvell_get_stats,
David Daney90600732010-11-19 11:58:53 +00002083 },
2084 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002085 .phy_id = MARVELL_PHY_ID_88E1240,
2086 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002087 .name = "Marvell 88E1240",
2088 .features = PHY_GBIT_FEATURES,
2089 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002090 .probe = marvell_probe,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002091 .config_init = &m88e1111_config_init,
2092 .config_aneg = &marvell_config_aneg,
2093 .read_status = &genphy_read_status,
2094 .ack_interrupt = &marvell_ack_interrupt,
2095 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002096 .resume = &genphy_resume,
2097 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002098 .get_sset_count = marvell_get_sset_count,
2099 .get_strings = marvell_get_strings,
2100 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002101 },
Michal Simek3da09a52013-05-30 20:08:26 +00002102 {
2103 .phy_id = MARVELL_PHY_ID_88E1116R,
2104 .phy_id_mask = MARVELL_PHY_ID_MASK,
2105 .name = "Marvell 88E1116R",
2106 .features = PHY_GBIT_FEATURES,
2107 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002108 .probe = marvell_probe,
Michal Simek3da09a52013-05-30 20:08:26 +00002109 .config_init = &m88e1116r_config_init,
2110 .config_aneg = &genphy_config_aneg,
2111 .read_status = &genphy_read_status,
2112 .ack_interrupt = &marvell_ack_interrupt,
2113 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002114 .resume = &genphy_resume,
2115 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002116 .get_sset_count = marvell_get_sset_count,
2117 .get_strings = marvell_get_strings,
2118 .get_stats = marvell_get_stats,
Michal Simek3da09a52013-05-30 20:08:26 +00002119 },
Michal Simek10e24caa2013-05-30 20:08:27 +00002120 {
2121 .phy_id = MARVELL_PHY_ID_88E1510,
2122 .phy_id_mask = MARVELL_PHY_ID_MASK,
2123 .name = "Marvell 88E1510",
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02002124 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE,
Arnd Bergmann18702412017-01-23 13:18:41 +01002125 .flags = PHY_HAS_INTERRUPT,
Andrew Lunn0b046802017-01-20 01:37:49 +01002126 .probe = &m88e1510_probe,
Stefan Roese930b37e2016-02-18 10:59:07 +01002127 .config_init = &m88e1510_config_init,
Michal Simek10e24caa2013-05-30 20:08:27 +00002128 .config_aneg = &m88e1510_config_aneg,
2129 .read_status = &marvell_read_status,
2130 .ack_interrupt = &marvell_ack_interrupt,
2131 .config_intr = &marvell_config_intr,
2132 .did_interrupt = &m88e1121_did_interrupt,
Jingju Houf39aac72017-01-22 18:20:56 +08002133 .get_wol = &m88e1318_get_wol,
2134 .set_wol = &m88e1318_set_wol,
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02002135 .resume = &marvell_resume,
2136 .suspend = &marvell_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002137 .get_sset_count = marvell_get_sset_count,
2138 .get_strings = marvell_get_strings,
2139 .get_stats = marvell_get_stats,
Lin Yun Shengf0f9b4e2017-06-30 17:44:15 +08002140 .set_loopback = genphy_loopback,
Michal Simek10e24caa2013-05-30 20:08:27 +00002141 },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002142 {
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002143 .phy_id = MARVELL_PHY_ID_88E1540,
2144 .phy_id_mask = MARVELL_PHY_ID_MASK,
2145 .name = "Marvell 88E1540",
2146 .features = PHY_GBIT_FEATURES,
2147 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01002148 .probe = m88e1510_probe,
Clemens Gruber79be1a12016-02-15 23:46:45 +01002149 .config_init = &marvell_config_init,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002150 .config_aneg = &m88e1510_config_aneg,
2151 .read_status = &marvell_read_status,
2152 .ack_interrupt = &marvell_ack_interrupt,
2153 .config_intr = &marvell_config_intr,
2154 .did_interrupt = &m88e1121_did_interrupt,
2155 .resume = &genphy_resume,
2156 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002157 .get_sset_count = marvell_get_sset_count,
2158 .get_strings = marvell_get_strings,
2159 .get_stats = marvell_get_stats,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002160 },
2161 {
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002162 .phy_id = MARVELL_PHY_ID_88E1545,
2163 .phy_id_mask = MARVELL_PHY_ID_MASK,
2164 .name = "Marvell 88E1545",
2165 .probe = m88e1510_probe,
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002166 .features = PHY_GBIT_FEATURES,
2167 .flags = PHY_HAS_INTERRUPT,
2168 .config_init = &marvell_config_init,
2169 .config_aneg = &m88e1510_config_aneg,
2170 .read_status = &marvell_read_status,
2171 .ack_interrupt = &marvell_ack_interrupt,
2172 .config_intr = &marvell_config_intr,
2173 .did_interrupt = &m88e1121_did_interrupt,
2174 .resume = &genphy_resume,
2175 .suspend = &genphy_suspend,
2176 .get_sset_count = marvell_get_sset_count,
2177 .get_strings = marvell_get_strings,
2178 .get_stats = marvell_get_stats,
2179 },
2180 {
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002181 .phy_id = MARVELL_PHY_ID_88E3016,
2182 .phy_id_mask = MARVELL_PHY_ID_MASK,
2183 .name = "Marvell 88E3016",
2184 .features = PHY_BASIC_FEATURES,
2185 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002186 .probe = marvell_probe,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002187 .config_aneg = &genphy_config_aneg,
2188 .config_init = &m88e3016_config_init,
2189 .aneg_done = &marvell_aneg_done,
2190 .read_status = &marvell_read_status,
2191 .ack_interrupt = &marvell_ack_interrupt,
2192 .config_intr = &marvell_config_intr,
2193 .did_interrupt = &m88e1121_did_interrupt,
2194 .resume = &genphy_resume,
2195 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002196 .get_sset_count = marvell_get_sset_count,
2197 .get_strings = marvell_get_strings,
2198 .get_stats = marvell_get_stats,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002199 },
Andrew Lunne4cf8a32017-02-01 03:40:06 +01002200 {
2201 .phy_id = MARVELL_PHY_ID_88E6390,
2202 .phy_id_mask = MARVELL_PHY_ID_MASK,
2203 .name = "Marvell 88E6390",
2204 .features = PHY_GBIT_FEATURES,
2205 .flags = PHY_HAS_INTERRUPT,
2206 .probe = m88e1510_probe,
2207 .config_init = &marvell_config_init,
2208 .config_aneg = &m88e1510_config_aneg,
2209 .read_status = &marvell_read_status,
2210 .ack_interrupt = &marvell_ack_interrupt,
2211 .config_intr = &marvell_config_intr,
2212 .did_interrupt = &m88e1121_did_interrupt,
2213 .resume = &genphy_resume,
2214 .suspend = &genphy_suspend,
2215 .get_sset_count = marvell_get_sset_count,
2216 .get_strings = marvell_get_strings,
2217 .get_stats = marvell_get_stats,
2218 },
Andy Fleming00db8182005-07-30 19:31:23 -04002219};
2220
Johan Hovold50fd7152014-11-11 19:45:59 +01002221module_phy_driver(marvell_drivers);
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002222
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +00002223static struct mdio_device_id __maybe_unused marvell_tbl[] = {
Michal Simekf5e1cab2013-05-30 20:08:25 +00002224 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
2225 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
2226 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
2227 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
2228 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
2229 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
2230 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
2231 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
2232 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
Michal Simek3da09a52013-05-30 20:08:26 +00002233 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
Michal Simek10e24caa2013-05-30 20:08:27 +00002234 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002235 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK },
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002236 { MARVELL_PHY_ID_88E1545, MARVELL_PHY_ID_MASK },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002237 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK },
Andrew Lunne4cf8a32017-02-01 03:40:06 +01002238 { MARVELL_PHY_ID_88E6390, MARVELL_PHY_ID_MASK },
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002239 { }
2240};
2241
2242MODULE_DEVICE_TABLE(mdio, marvell_tbl);