blob: 64229976ace1a8a977a94901c7cf2a724b5d491c [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
44
Andy Fleming00db8182005-07-30 19:31:23 -040045#define MII_M1011_IEVENT 0x13
46#define MII_M1011_IEVENT_CLEAR 0x0000
47
48#define MII_M1011_IMASK 0x12
49#define MII_M1011_IMASK_INIT 0x6400
50#define MII_M1011_IMASK_CLEAR 0x0000
51
Andy Fleming76884672007-02-09 18:13:58 -060052#define MII_M1011_PHY_SCR 0x10
David Thomson239aa552015-07-10 16:28:25 +120053#define MII_M1011_PHY_SCR_MDI 0x0000
54#define MII_M1011_PHY_SCR_MDI_X 0x0020
Andy Fleming76884672007-02-09 18:13:58 -060055#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
56
Madalin Bucur07151bc2015-08-07 17:07:50 +080057#define MII_M1145_PHY_EXT_ADDR_PAGE 0x16
Viet Nga Daob0224172014-10-23 19:41:53 -070058#define MII_M1145_PHY_EXT_SR 0x1b
Andy Fleming76884672007-02-09 18:13:58 -060059#define MII_M1145_PHY_EXT_CR 0x14
60#define MII_M1145_RGMII_RX_DELAY 0x0080
61#define MII_M1145_RGMII_TX_DELAY 0x0002
Viet Nga Daob0224172014-10-23 19:41:53 -070062#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
63#define MII_M1145_HWCFG_MODE_MASK 0xf
64#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
Andy Fleming76884672007-02-09 18:13:58 -060065
Vince Bridgers99d881f2014-10-26 14:22:24 -050066#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
67#define MII_M1145_HWCFG_MODE_MASK 0xf
68#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
69
Andy Fleming76884672007-02-09 18:13:58 -060070#define MII_M1111_PHY_LED_CONTROL 0x18
71#define MII_M1111_PHY_LED_DIRECT 0x4100
72#define MII_M1111_PHY_LED_COMBINE 0x411c
Kim Phillips895ee682007-06-05 18:46:47 +080073#define MII_M1111_PHY_EXT_CR 0x14
74#define MII_M1111_RX_DELAY 0x80
75#define MII_M1111_TX_DELAY 0x2
76#define MII_M1111_PHY_EXT_SR 0x1b
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030077
78#define MII_M1111_HWCFG_MODE_MASK 0xf
79#define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
80#define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
Kapil Juneja4117b5b2007-05-11 18:25:18 -050081#define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +000082#define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030083#define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000
84#define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000
85
86#define MII_M1111_COPPER 0
87#define MII_M1111_FIBER 1
88
Cyril Chemparathyc477d042010-08-02 09:44:53 +000089#define MII_88E1121_PHY_MSCR_PAGE 2
90#define MII_88E1121_PHY_MSCR_REG 21
91#define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
92#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
93#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
94
Andrew Lunn0b046802017-01-20 01:37:49 +010095#define MII_88E1121_MISC_TEST 0x1a
96#define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00
97#define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8
98#define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7)
99#define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6)
100#define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5)
101#define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f
102
103#define MII_88E1510_TEMP_SENSOR 0x1b
104#define MII_88E1510_TEMP_SENSOR_MASK 0xff
105
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700106#define MII_88E1318S_PHY_MSCR1_REG 16
107#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700108
Michael Stapelberg3871c382013-03-11 13:56:45 +0000109/* Copper Specific Interrupt Enable Register */
110#define MII_88E1318S_PHY_CSIER 0x12
111/* WOL Event Interrupt Enable */
112#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
113
114/* LED Timer Control Register */
115#define MII_88E1318S_PHY_LED_PAGE 0x03
116#define MII_88E1318S_PHY_LED_TCR 0x12
117#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
118#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
119#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
120
121/* Magic Packet MAC address registers */
122#define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
123#define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
124#define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
125
126#define MII_88E1318S_PHY_WOL_PAGE 0x11
127#define MII_88E1318S_PHY_WOL_CTRL 0x10
128#define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
129#define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
130
Sergei Poselenov140bc922009-04-07 02:01:41 +0000131#define MII_88E1121_PHY_LED_CTRL 16
132#define MII_88E1121_PHY_LED_PAGE 3
133#define MII_88E1121_PHY_LED_DEF 0x0030
Sergei Poselenov140bc922009-04-07 02:01:41 +0000134
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300135#define MII_M1011_PHY_STATUS 0x11
136#define MII_M1011_PHY_STATUS_1000 0x8000
137#define MII_M1011_PHY_STATUS_100 0x4000
138#define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
139#define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
140#define MII_M1011_PHY_STATUS_RESOLVED 0x0800
141#define MII_M1011_PHY_STATUS_LINK 0x0400
142
Michal Simek3da09a52013-05-30 20:08:26 +0000143#define MII_M1116R_CONTROL_REG_MAC 21
144
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200145#define MII_88E3016_PHY_SPEC_CTRL 0x10
146#define MII_88E3016_DISABLE_SCRAMBLER 0x0200
147#define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
Andy Fleming76884672007-02-09 18:13:58 -0600148
Stefan Roese930b37e2016-02-18 10:59:07 +0100149#define MII_88E1510_GEN_CTRL_REG_1 0x14
150#define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7
151#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
152#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
153
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200154#define LPA_FIBER_1000HALF 0x40
155#define LPA_FIBER_1000FULL 0x20
156
157#define LPA_PAUSE_FIBER 0x180
158#define LPA_PAUSE_ASYM_FIBER 0x100
159
160#define ADVERTISE_FIBER_1000HALF 0x40
161#define ADVERTISE_FIBER_1000FULL 0x20
162
163#define ADVERTISE_PAUSE_FIBER 0x180
164#define ADVERTISE_PAUSE_ASYM_FIBER 0x100
165
166#define REGISTER_LINK_STATUS 0x400
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200167#define NB_FIBER_STATS 1
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200168
Andy Fleming00db8182005-07-30 19:31:23 -0400169MODULE_DESCRIPTION("Marvell PHY driver");
170MODULE_AUTHOR("Andy Fleming");
171MODULE_LICENSE("GPL");
172
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100173struct marvell_hw_stat {
174 const char *string;
175 u8 page;
176 u8 reg;
177 u8 bits;
178};
179
180static struct marvell_hw_stat marvell_hw_stats[] = {
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200181 { "phy_receive_errors_copper", 0, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100182 { "phy_idle_errors", 0, 10, 8 },
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200183 { "phy_receive_errors_fiber", 1, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100184};
185
186struct marvell_priv {
187 u64 stats[ARRAY_SIZE(marvell_hw_stats)];
Andrew Lunn0b046802017-01-20 01:37:49 +0100188 char *hwmon_name;
189 struct device *hwmon_dev;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100190};
191
Andy Fleming00db8182005-07-30 19:31:23 -0400192static int marvell_ack_interrupt(struct phy_device *phydev)
193{
194 int err;
195
196 /* Clear the interrupts by reading the reg */
197 err = phy_read(phydev, MII_M1011_IEVENT);
198
199 if (err < 0)
200 return err;
201
202 return 0;
203}
204
205static int marvell_config_intr(struct phy_device *phydev)
206{
207 int err;
208
Andy Fleming76884672007-02-09 18:13:58 -0600209 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
Andy Fleming00db8182005-07-30 19:31:23 -0400210 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
211 else
212 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
213
214 return err;
215}
216
David Thomson239aa552015-07-10 16:28:25 +1200217static int marvell_set_polarity(struct phy_device *phydev, int polarity)
218{
219 int reg;
220 int err;
221 int val;
222
223 /* get the current settings */
224 reg = phy_read(phydev, MII_M1011_PHY_SCR);
225 if (reg < 0)
226 return reg;
227
228 val = reg;
229 val &= ~MII_M1011_PHY_SCR_AUTO_CROSS;
230 switch (polarity) {
231 case ETH_TP_MDI:
232 val |= MII_M1011_PHY_SCR_MDI;
233 break;
234 case ETH_TP_MDI_X:
235 val |= MII_M1011_PHY_SCR_MDI_X;
236 break;
237 case ETH_TP_MDI_AUTO:
238 case ETH_TP_MDI_INVALID:
239 default:
240 val |= MII_M1011_PHY_SCR_AUTO_CROSS;
241 break;
242 }
243
244 if (val != reg) {
245 /* Set the new polarity value in the register */
246 err = phy_write(phydev, MII_M1011_PHY_SCR, val);
247 if (err)
248 return err;
249 }
250
251 return 0;
252}
253
Andy Fleming00db8182005-07-30 19:31:23 -0400254static int marvell_config_aneg(struct phy_device *phydev)
255{
256 int err;
257
258 /* The Marvell PHY has an errata which requires
259 * that certain registers get written in order
260 * to restart autonegotiation */
261 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
262
263 if (err < 0)
264 return err;
265
266 err = phy_write(phydev, 0x1d, 0x1f);
267 if (err < 0)
268 return err;
269
270 err = phy_write(phydev, 0x1e, 0x200c);
271 if (err < 0)
272 return err;
273
274 err = phy_write(phydev, 0x1d, 0x5);
275 if (err < 0)
276 return err;
277
278 err = phy_write(phydev, 0x1e, 0);
279 if (err < 0)
280 return err;
281
282 err = phy_write(phydev, 0x1e, 0x100);
283 if (err < 0)
284 return err;
285
Raju Lakkaraju4e26c5c2016-11-29 15:16:49 +0530286 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Andy Fleming76884672007-02-09 18:13:58 -0600287 if (err < 0)
288 return err;
289
290 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
291 MII_M1111_PHY_LED_DIRECT);
292 if (err < 0)
293 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400294
295 err = genphy_config_aneg(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000296 if (err < 0)
297 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400298
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000299 if (phydev->autoneg != AUTONEG_ENABLE) {
300 int bmcr;
301
302 /*
303 * A write to speed/duplex bits (that is performed by
304 * genphy_config_aneg() call above) must be followed by
305 * a software reset. Otherwise, the write has no effect.
306 */
307 bmcr = phy_read(phydev, MII_BMCR);
308 if (bmcr < 0)
309 return bmcr;
310
311 err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
312 if (err < 0)
313 return err;
314 }
315
316 return 0;
Andy Fleming00db8182005-07-30 19:31:23 -0400317}
318
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530319static int m88e1111_config_aneg(struct phy_device *phydev)
320{
321 int err;
322
323 /* The Marvell PHY has an errata which requires
324 * that certain registers get written in order
325 * to restart autonegotiation
326 */
327 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
328
Raju Lakkaraju4e26c5c2016-11-29 15:16:49 +0530329 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530330 if (err < 0)
331 return err;
332
333 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
334 MII_M1111_PHY_LED_DIRECT);
335 if (err < 0)
336 return err;
337
338 err = genphy_config_aneg(phydev);
339 if (err < 0)
340 return err;
341
342 if (phydev->autoneg != AUTONEG_ENABLE) {
343 int bmcr;
344
345 /* A write to speed/duplex bits (that is performed by
346 * genphy_config_aneg() call above) must be followed by
347 * a software reset. Otherwise, the write has no effect.
348 */
349 bmcr = phy_read(phydev, MII_BMCR);
350 if (bmcr < 0)
351 return bmcr;
352
353 err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
354 if (err < 0)
355 return err;
356 }
357
358 return 0;
359}
360
David Daneycf41a512010-11-19 12:13:18 +0000361#ifdef CONFIG_OF_MDIO
362/*
363 * Set and/or override some configuration registers based on the
364 * marvell,reg-init property stored in the of_node for the phydev.
365 *
366 * marvell,reg-init = <reg-page reg mask value>,...;
367 *
368 * There may be one or more sets of <reg-page reg mask value>:
369 *
370 * reg-page: which register bank to use.
371 * reg: the register.
372 * mask: if non-zero, ANDed with existing register value.
373 * value: ORed with the masked value and written to the regiser.
374 *
375 */
376static int marvell_of_reg_init(struct phy_device *phydev)
377{
378 const __be32 *paddr;
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100379 int len, i, saved_page, current_page, ret;
David Daneycf41a512010-11-19 12:13:18 +0000380
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100381 if (!phydev->mdio.dev.of_node)
David Daneycf41a512010-11-19 12:13:18 +0000382 return 0;
383
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100384 paddr = of_get_property(phydev->mdio.dev.of_node,
385 "marvell,reg-init", &len);
David Daneycf41a512010-11-19 12:13:18 +0000386 if (!paddr || len < (4 * sizeof(*paddr)))
387 return 0;
388
389 saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE);
390 if (saved_page < 0)
391 return saved_page;
David Daneycf41a512010-11-19 12:13:18 +0000392 current_page = saved_page;
393
394 ret = 0;
395 len /= sizeof(*paddr);
396 for (i = 0; i < len - 3; i += 4) {
397 u16 reg_page = be32_to_cpup(paddr + i);
398 u16 reg = be32_to_cpup(paddr + i + 1);
399 u16 mask = be32_to_cpup(paddr + i + 2);
400 u16 val_bits = be32_to_cpup(paddr + i + 3);
401 int val;
402
403 if (reg_page != current_page) {
404 current_page = reg_page;
David Daneycf41a512010-11-19 12:13:18 +0000405 ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page);
406 if (ret < 0)
407 goto err;
408 }
409
410 val = 0;
411 if (mask) {
412 val = phy_read(phydev, reg);
413 if (val < 0) {
414 ret = val;
415 goto err;
416 }
417 val &= mask;
418 }
419 val |= val_bits;
420
421 ret = phy_write(phydev, reg, val);
422 if (ret < 0)
423 goto err;
424
425 }
426err:
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100427 if (current_page != saved_page) {
David Daneycf41a512010-11-19 12:13:18 +0000428 i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page);
429 if (ret == 0)
430 ret = i;
431 }
432 return ret;
433}
434#else
435static int marvell_of_reg_init(struct phy_device *phydev)
436{
437 return 0;
438}
439#endif /* CONFIG_OF_MDIO */
440
Sergei Poselenov140bc922009-04-07 02:01:41 +0000441static int m88e1121_config_aneg(struct phy_device *phydev)
442{
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000443 int err, oldpage, mscr;
444
David Daney27d916d2010-11-19 11:58:52 +0000445 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000446
David Daney27d916d2010-11-19 11:58:52 +0000447 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000448 MII_88E1121_PHY_MSCR_PAGE);
449 if (err < 0)
450 return err;
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000451
Florian Fainelli32a64162015-05-26 12:19:59 -0700452 if (phy_interface_is_rgmii(phydev)) {
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000453
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700454 mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
455 MII_88E1121_PHY_MSCR_DELAY_MASK;
456
457 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
458 mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
459 MII_88E1121_PHY_MSCR_TX_DELAY);
460 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
461 mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
462 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
463 mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
464
465 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
466 if (err < 0)
467 return err;
468 }
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000469
David Daney27d916d2010-11-19 11:58:52 +0000470 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000471
472 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
473 if (err < 0)
474 return err;
475
476 err = phy_write(phydev, MII_M1011_PHY_SCR,
477 MII_M1011_PHY_SCR_AUTO_CROSS);
478 if (err < 0)
479 return err;
480
Clemens Gruberfdecf362016-06-11 17:21:26 +0200481 return genphy_config_aneg(phydev);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000482}
483
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700484static int m88e1318_config_aneg(struct phy_device *phydev)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700485{
486 int err, oldpage, mscr;
487
David Daney27d916d2010-11-19 11:58:52 +0000488 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700489
David Daney27d916d2010-11-19 11:58:52 +0000490 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700491 MII_88E1121_PHY_MSCR_PAGE);
492 if (err < 0)
493 return err;
494
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700495 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
496 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700497
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700498 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700499 if (err < 0)
500 return err;
501
David Daney27d916d2010-11-19 11:58:52 +0000502 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700503 if (err < 0)
504 return err;
505
506 return m88e1121_config_aneg(phydev);
507}
508
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200509/**
510 * ethtool_adv_to_fiber_adv_t
511 * @ethadv: the ethtool advertisement settings
512 *
513 * A small helper function that translates ethtool advertisement
514 * settings to phy autonegotiation advertisements for the
515 * MII_ADV register for fiber link.
516 */
517static inline u32 ethtool_adv_to_fiber_adv_t(u32 ethadv)
518{
519 u32 result = 0;
520
521 if (ethadv & ADVERTISED_1000baseT_Half)
522 result |= ADVERTISE_FIBER_1000HALF;
523 if (ethadv & ADVERTISED_1000baseT_Full)
524 result |= ADVERTISE_FIBER_1000FULL;
525
526 if ((ethadv & ADVERTISE_PAUSE_ASYM) && (ethadv & ADVERTISE_PAUSE_CAP))
527 result |= LPA_PAUSE_ASYM_FIBER;
528 else if (ethadv & ADVERTISE_PAUSE_CAP)
529 result |= (ADVERTISE_PAUSE_FIBER
530 & (~ADVERTISE_PAUSE_ASYM_FIBER));
531
532 return result;
533}
534
535/**
536 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR
537 * @phydev: target phy_device struct
538 *
539 * Description: If auto-negotiation is enabled, we configure the
540 * advertising, and then restart auto-negotiation. If it is not
541 * enabled, then we write the BMCR. Adapted for fiber link in
542 * some Marvell's devices.
543 */
544static int marvell_config_aneg_fiber(struct phy_device *phydev)
545{
546 int changed = 0;
547 int err;
548 int adv, oldadv;
549 u32 advertise;
550
551 if (phydev->autoneg != AUTONEG_ENABLE)
552 return genphy_setup_forced(phydev);
553
554 /* Only allow advertising what this PHY supports */
555 phydev->advertising &= phydev->supported;
556 advertise = phydev->advertising;
557
558 /* Setup fiber advertisement */
559 adv = phy_read(phydev, MII_ADVERTISE);
560 if (adv < 0)
561 return adv;
562
563 oldadv = adv;
564 adv &= ~(ADVERTISE_FIBER_1000HALF | ADVERTISE_FIBER_1000FULL
565 | LPA_PAUSE_FIBER);
566 adv |= ethtool_adv_to_fiber_adv_t(advertise);
567
568 if (adv != oldadv) {
569 err = phy_write(phydev, MII_ADVERTISE, adv);
570 if (err < 0)
571 return err;
572
573 changed = 1;
574 }
575
576 if (changed == 0) {
577 /* Advertisement hasn't changed, but maybe aneg was never on to
578 * begin with? Or maybe phy was isolated?
579 */
580 int ctl = phy_read(phydev, MII_BMCR);
581
582 if (ctl < 0)
583 return ctl;
584
585 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
586 changed = 1; /* do restart aneg */
587 }
588
589 /* Only restart aneg if we are advertising something different
590 * than we were before.
591 */
592 if (changed > 0)
593 changed = genphy_restart_aneg(phydev);
594
595 return changed;
596}
597
Michal Simek10e24caa2013-05-30 20:08:27 +0000598static int m88e1510_config_aneg(struct phy_device *phydev)
599{
600 int err;
601
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200602 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
603 if (err < 0)
604 goto error;
605
606 /* Configure the copper link first */
Michal Simek10e24caa2013-05-30 20:08:27 +0000607 err = m88e1318_config_aneg(phydev);
608 if (err < 0)
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200609 goto error;
Michal Simek10e24caa2013-05-30 20:08:27 +0000610
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200611 /* Then the fiber link */
612 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
613 if (err < 0)
614 goto error;
615
616 err = marvell_config_aneg_fiber(phydev);
617 if (err < 0)
618 goto error;
619
620 return phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
621
622error:
623 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
624 return err;
Clemens Gruber79be1a12016-02-15 23:46:45 +0100625}
626
627static int marvell_config_init(struct phy_device *phydev)
628{
629 /* Set registers from marvell,reg-init DT property */
Michal Simek10e24caa2013-05-30 20:08:27 +0000630 return marvell_of_reg_init(phydev);
631}
632
Michal Simek3da09a52013-05-30 20:08:26 +0000633static int m88e1116r_config_init(struct phy_device *phydev)
634{
635 int temp;
636 int err;
637
638 temp = phy_read(phydev, MII_BMCR);
639 temp |= BMCR_RESET;
640 err = phy_write(phydev, MII_BMCR, temp);
641 if (err < 0)
642 return err;
643
644 mdelay(500);
645
646 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
647 if (err < 0)
648 return err;
649
650 temp = phy_read(phydev, MII_M1011_PHY_SCR);
651 temp |= (7 << 12); /* max number of gigabit attempts */
652 temp |= (1 << 11); /* enable downshift */
653 temp |= MII_M1011_PHY_SCR_AUTO_CROSS;
654 err = phy_write(phydev, MII_M1011_PHY_SCR, temp);
655 if (err < 0)
656 return err;
657
658 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2);
659 if (err < 0)
660 return err;
661 temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC);
662 temp |= (1 << 5);
663 temp |= (1 << 4);
664 err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp);
665 if (err < 0)
666 return err;
667 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
668 if (err < 0)
669 return err;
670
671 temp = phy_read(phydev, MII_BMCR);
672 temp |= BMCR_RESET;
673 err = phy_write(phydev, MII_BMCR, temp);
674 if (err < 0)
675 return err;
676
677 mdelay(500);
678
Clemens Gruber79be1a12016-02-15 23:46:45 +0100679 return marvell_config_init(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000680}
681
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200682static int m88e3016_config_init(struct phy_device *phydev)
683{
684 int reg;
685
686 /* Enable Scrambler and Auto-Crossover */
687 reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL);
688 if (reg < 0)
689 return reg;
690
691 reg &= ~MII_88E3016_DISABLE_SCRAMBLER;
692 reg |= MII_88E3016_AUTO_MDIX_CROSSOVER;
693
694 reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg);
695 if (reg < 0)
696 return reg;
697
Clemens Gruber79be1a12016-02-15 23:46:45 +0100698 return marvell_config_init(phydev);
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200699}
700
Kim Phillips895ee682007-06-05 18:46:47 +0800701static int m88e1111_config_init(struct phy_device *phydev)
702{
703 int err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300704 int temp;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300705
Florian Fainelli32a64162015-05-26 12:19:59 -0700706 if (phy_interface_is_rgmii(phydev)) {
Kim Phillips895ee682007-06-05 18:46:47 +0800707
Kim Phillips9daf5a72007-11-26 16:17:52 -0600708 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
709 if (temp < 0)
710 return temp;
711
Kim Phillips895ee682007-06-05 18:46:47 +0800712 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Kim Phillips895ee682007-06-05 18:46:47 +0800713 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
Kim Phillips9daf5a72007-11-26 16:17:52 -0600714 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
715 temp &= ~MII_M1111_TX_DELAY;
716 temp |= MII_M1111_RX_DELAY;
717 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
718 temp &= ~MII_M1111_RX_DELAY;
719 temp |= MII_M1111_TX_DELAY;
Kim Phillips895ee682007-06-05 18:46:47 +0800720 }
721
Kim Phillips9daf5a72007-11-26 16:17:52 -0600722 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
723 if (err < 0)
724 return err;
725
Kim Phillips895ee682007-06-05 18:46:47 +0800726 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
727 if (temp < 0)
728 return temp;
729
730 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300731
Wang Jian7239016d2008-07-16 21:46:20 +0800732 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300733 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
734 else
735 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
Kim Phillips895ee682007-06-05 18:46:47 +0800736
737 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
738 if (err < 0)
739 return err;
740 }
741
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500742 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500743 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
744 if (temp < 0)
745 return temp;
746
747 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
748 temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK;
Haiying Wang32d0c1e2009-06-02 04:04:13 +0000749 temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500750
751 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
752 if (err < 0)
753 return err;
Madalin Bucur07151bc2015-08-07 17:07:50 +0800754
755 /* make sure copper is selected */
756 err = phy_read(phydev, MII_M1145_PHY_EXT_ADDR_PAGE);
757 if (err < 0)
758 return err;
759
760 err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE,
761 err & (~0xff));
762 if (err < 0)
763 return err;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500764 }
765
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000766 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
767 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
768 if (temp < 0)
769 return temp;
770 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
771 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
772 if (err < 0)
773 return err;
774
775 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
776 if (temp < 0)
777 return temp;
778 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
779 temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
780 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
781 if (err < 0)
782 return err;
783
784 /* soft reset */
785 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
786 if (err < 0)
787 return err;
788 do
789 temp = phy_read(phydev, MII_BMCR);
790 while (temp & BMCR_RESET);
791
792 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
793 if (temp < 0)
794 return temp;
795 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
796 temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
797 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
798 if (err < 0)
799 return err;
800 }
801
David Daneycf41a512010-11-19 12:13:18 +0000802 err = marvell_of_reg_init(phydev);
803 if (err < 0)
804 return err;
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000805
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000806 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Kim Phillips895ee682007-06-05 18:46:47 +0800807}
808
Clemens Gruberfdecf362016-06-11 17:21:26 +0200809static int m88e1121_config_init(struct phy_device *phydev)
810{
811 int err, oldpage;
812
813 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
814
815 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE);
816 if (err < 0)
817 return err;
818
819 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
820 err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL,
821 MII_88E1121_PHY_LED_DEF);
822 if (err < 0)
823 return err;
824
825 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
826
827 /* Set marvell,reg-init configuration from device tree */
828 return marvell_config_init(phydev);
829}
830
Clemens Gruber407353e2016-02-23 20:16:58 +0100831static int m88e1510_config_init(struct phy_device *phydev)
832{
833 int err;
834 int temp;
835
836 /* SGMII-to-Copper mode initialization */
837 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
838 /* Select page 18 */
839 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 18);
840 if (err < 0)
841 return err;
842
843 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
844 temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1);
845 temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK;
846 temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII;
847 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
848 if (err < 0)
849 return err;
850
851 /* PHY reset is necessary after changing MODE[2:0] */
852 temp |= MII_88E1510_GEN_CTRL_REG_1_RESET;
853 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
854 if (err < 0)
855 return err;
856
857 /* Reset page selection */
858 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
859 if (err < 0)
860 return err;
861 }
862
Clemens Gruberfdecf362016-06-11 17:21:26 +0200863 return m88e1121_config_init(phydev);
Clemens Gruber407353e2016-02-23 20:16:58 +0100864}
865
Ron Madrid605f1962008-11-06 09:05:26 +0000866static int m88e1118_config_aneg(struct phy_device *phydev)
867{
868 int err;
869
870 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
871 if (err < 0)
872 return err;
873
874 err = phy_write(phydev, MII_M1011_PHY_SCR,
875 MII_M1011_PHY_SCR_AUTO_CROSS);
876 if (err < 0)
877 return err;
878
879 err = genphy_config_aneg(phydev);
880 return 0;
881}
882
883static int m88e1118_config_init(struct phy_device *phydev)
884{
885 int err;
886
887 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000888 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
Ron Madrid605f1962008-11-06 09:05:26 +0000889 if (err < 0)
890 return err;
891
892 /* Enable 1000 Mbit */
893 err = phy_write(phydev, 0x15, 0x1070);
894 if (err < 0)
895 return err;
896
897 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000898 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003);
Ron Madrid605f1962008-11-06 09:05:26 +0000899 if (err < 0)
900 return err;
901
902 /* Adjust LED Control */
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000903 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
904 err = phy_write(phydev, 0x10, 0x1100);
905 else
906 err = phy_write(phydev, 0x10, 0x021e);
Ron Madrid605f1962008-11-06 09:05:26 +0000907 if (err < 0)
908 return err;
909
David Daneycf41a512010-11-19 12:13:18 +0000910 err = marvell_of_reg_init(phydev);
911 if (err < 0)
912 return err;
913
Ron Madrid605f1962008-11-06 09:05:26 +0000914 /* Reset address */
David Daney27d916d2010-11-19 11:58:52 +0000915 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
Ron Madrid605f1962008-11-06 09:05:26 +0000916 if (err < 0)
917 return err;
918
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000919 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Ron Madrid605f1962008-11-06 09:05:26 +0000920}
921
David Daney90600732010-11-19 11:58:53 +0000922static int m88e1149_config_init(struct phy_device *phydev)
923{
924 int err;
925
926 /* Change address */
927 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
928 if (err < 0)
929 return err;
930
931 /* Enable 1000 Mbit */
932 err = phy_write(phydev, 0x15, 0x1048);
933 if (err < 0)
934 return err;
935
David Daneycf41a512010-11-19 12:13:18 +0000936 err = marvell_of_reg_init(phydev);
937 if (err < 0)
938 return err;
939
David Daney90600732010-11-19 11:58:53 +0000940 /* Reset address */
941 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
942 if (err < 0)
943 return err;
944
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000945 return phy_write(phydev, MII_BMCR, BMCR_RESET);
David Daney90600732010-11-19 11:58:53 +0000946}
947
Andy Fleming76884672007-02-09 18:13:58 -0600948static int m88e1145_config_init(struct phy_device *phydev)
949{
950 int err;
Viet Nga Daob0224172014-10-23 19:41:53 -0700951 int temp;
Andy Fleming76884672007-02-09 18:13:58 -0600952
953 /* Take care of errata E0 & E1 */
954 err = phy_write(phydev, 0x1d, 0x001b);
955 if (err < 0)
956 return err;
957
958 err = phy_write(phydev, 0x1e, 0x418f);
959 if (err < 0)
960 return err;
961
962 err = phy_write(phydev, 0x1d, 0x0016);
963 if (err < 0)
964 return err;
965
966 err = phy_write(phydev, 0x1e, 0xa2da);
967 if (err < 0)
968 return err;
969
Kim Phillips895ee682007-06-05 18:46:47 +0800970 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andy Fleming76884672007-02-09 18:13:58 -0600971 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
972 if (temp < 0)
973 return temp;
974
975 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
976
977 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
978 if (err < 0)
979 return err;
980
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000981 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
Andy Fleming76884672007-02-09 18:13:58 -0600982 err = phy_write(phydev, 0x1d, 0x0012);
983 if (err < 0)
984 return err;
985
986 temp = phy_read(phydev, 0x1e);
987 if (temp < 0)
988 return temp;
989
990 temp &= 0xf03f;
991 temp |= 2 << 9; /* 36 ohm */
992 temp |= 2 << 6; /* 39 ohm */
993
994 err = phy_write(phydev, 0x1e, temp);
995 if (err < 0)
996 return err;
997
998 err = phy_write(phydev, 0x1d, 0x3);
999 if (err < 0)
1000 return err;
1001
1002 err = phy_write(phydev, 0x1e, 0x8000);
1003 if (err < 0)
1004 return err;
1005 }
1006 }
1007
Viet Nga Daob0224172014-10-23 19:41:53 -07001008 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1009 temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
1010 if (temp < 0)
1011 return temp;
1012
Vince Bridgers99d881f2014-10-26 14:22:24 -05001013 temp &= ~MII_M1145_HWCFG_MODE_MASK;
Viet Nga Daob0224172014-10-23 19:41:53 -07001014 temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
1015 temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
1016
1017 err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
1018 if (err < 0)
1019 return err;
1020 }
1021
David Daneycf41a512010-11-19 12:13:18 +00001022 err = marvell_of_reg_init(phydev);
1023 if (err < 0)
1024 return err;
1025
Andy Fleming76884672007-02-09 18:13:58 -06001026 return 0;
1027}
Andy Fleming00db8182005-07-30 19:31:23 -04001028
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001029/**
1030 * fiber_lpa_to_ethtool_lpa_t
1031 * @lpa: value of the MII_LPA register for fiber link
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001032 *
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001033 * A small helper function that translates MII_LPA
1034 * bits to ethtool LP advertisement settings.
1035 */
1036static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa)
1037{
1038 u32 result = 0;
1039
1040 if (lpa & LPA_FIBER_1000HALF)
1041 result |= ADVERTISED_1000baseT_Half;
1042 if (lpa & LPA_FIBER_1000FULL)
1043 result |= ADVERTISED_1000baseT_Full;
1044
1045 return result;
1046}
1047
1048/**
1049 * marvell_update_link - update link status in real time in @phydev
1050 * @phydev: target phy_device struct
1051 *
1052 * Description: Update the value in phydev->link to reflect the
1053 * current link value.
1054 */
1055static int marvell_update_link(struct phy_device *phydev, int fiber)
1056{
1057 int status;
1058
1059 /* Use the generic register for copper link, or specific
1060 * register for fiber case */
1061 if (fiber) {
1062 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1063 if (status < 0)
1064 return status;
1065
1066 if ((status & REGISTER_LINK_STATUS) == 0)
1067 phydev->link = 0;
1068 else
1069 phydev->link = 1;
1070 } else {
1071 return genphy_update_link(phydev);
1072 }
1073
1074 return 0;
1075}
1076
1077/* marvell_read_status_page
1078 *
Jeff Garzikf0c88f92008-03-25 23:53:24 -04001079 * Description:
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001080 * Check the link, then figure out the current state
1081 * by comparing what we advertise with what the link partner
1082 * advertises. Start by checking the gigabit possibilities,
1083 * then move on to 10/100.
1084 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001085static int marvell_read_status_page(struct phy_device *phydev, int page)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001086{
1087 int adv;
1088 int err;
1089 int lpa;
Russell King357cd642015-09-24 00:07:17 +01001090 int lpagb;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001091 int status = 0;
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001092 int fiber;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001093
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001094 /* Detect and update the link, but return if there
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001095 * was an error */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001096 if (page == MII_M1111_FIBER)
1097 fiber = 1;
1098 else
1099 fiber = 0;
1100
1101 err = marvell_update_link(phydev, fiber);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001102 if (err)
1103 return err;
1104
1105 if (AUTONEG_ENABLE == phydev->autoneg) {
1106 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1107 if (status < 0)
1108 return status;
1109
1110 lpa = phy_read(phydev, MII_LPA);
1111 if (lpa < 0)
1112 return lpa;
1113
Russell King357cd642015-09-24 00:07:17 +01001114 lpagb = phy_read(phydev, MII_STAT1000);
1115 if (lpagb < 0)
1116 return lpagb;
1117
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001118 adv = phy_read(phydev, MII_ADVERTISE);
1119 if (adv < 0)
1120 return adv;
1121
1122 lpa &= adv;
1123
1124 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
1125 phydev->duplex = DUPLEX_FULL;
1126 else
1127 phydev->duplex = DUPLEX_HALF;
1128
1129 status = status & MII_M1011_PHY_STATUS_SPD_MASK;
1130 phydev->pause = phydev->asym_pause = 0;
1131
1132 switch (status) {
1133 case MII_M1011_PHY_STATUS_1000:
1134 phydev->speed = SPEED_1000;
1135 break;
1136
1137 case MII_M1011_PHY_STATUS_100:
1138 phydev->speed = SPEED_100;
1139 break;
1140
1141 default:
1142 phydev->speed = SPEED_10;
1143 break;
1144 }
1145
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001146 if (!fiber) {
1147 phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) |
1148 mii_lpa_to_ethtool_lpa_t(lpa);
1149
1150 if (phydev->duplex == DUPLEX_FULL) {
1151 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
1152 phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
1153 }
1154 } else {
1155 /* The fiber link is only 1000M capable */
1156 phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa);
1157
1158 if (phydev->duplex == DUPLEX_FULL) {
1159 if (!(lpa & LPA_PAUSE_FIBER)) {
1160 phydev->pause = 0;
1161 phydev->asym_pause = 0;
1162 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) {
1163 phydev->pause = 1;
1164 phydev->asym_pause = 1;
1165 } else {
1166 phydev->pause = 1;
1167 phydev->asym_pause = 0;
1168 }
1169 }
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001170 }
1171 } else {
1172 int bmcr = phy_read(phydev, MII_BMCR);
1173
1174 if (bmcr < 0)
1175 return bmcr;
1176
1177 if (bmcr & BMCR_FULLDPLX)
1178 phydev->duplex = DUPLEX_FULL;
1179 else
1180 phydev->duplex = DUPLEX_HALF;
1181
1182 if (bmcr & BMCR_SPEED1000)
1183 phydev->speed = SPEED_1000;
1184 else if (bmcr & BMCR_SPEED100)
1185 phydev->speed = SPEED_100;
1186 else
1187 phydev->speed = SPEED_10;
1188
1189 phydev->pause = phydev->asym_pause = 0;
Russell King357cd642015-09-24 00:07:17 +01001190 phydev->lp_advertising = 0;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001191 }
1192
1193 return 0;
1194}
1195
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001196/* marvell_read_status
1197 *
1198 * Some Marvell's phys have two modes: fiber and copper.
1199 * Both need status checked.
1200 * Description:
1201 * First, check the fiber link and status.
1202 * If the fiber link is down, check the copper link and status which
1203 * will be the default value if both link are down.
1204 */
1205static int marvell_read_status(struct phy_device *phydev)
1206{
1207 int err;
1208
1209 /* Check the fiber mode first */
Russell Kinga13c06522017-01-10 23:13:45 +00001210 if (phydev->supported & SUPPORTED_FIBRE &&
1211 phydev->interface != PHY_INTERFACE_MODE_SGMII) {
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001212 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1213 if (err < 0)
1214 goto error;
1215
1216 err = marvell_read_status_page(phydev, MII_M1111_FIBER);
1217 if (err < 0)
1218 goto error;
1219
1220 /* If the fiber link is up, it is the selected and used link.
1221 * In this case, we need to stay in the fiber page.
1222 * Please to be careful about that, avoid to restore Copper page
1223 * in other functions which could break the behaviour
1224 * for some fiber phy like 88E1512.
1225 * */
1226 if (phydev->link)
1227 return 0;
1228
1229 /* If fiber link is down, check and save copper mode state */
1230 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1231 if (err < 0)
1232 goto error;
1233 }
1234
1235 return marvell_read_status_page(phydev, MII_M1111_COPPER);
1236
1237error:
1238 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1239 return err;
1240}
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001241
1242/* marvell_suspend
1243 *
1244 * Some Marvell's phys have two modes: fiber and copper.
1245 * Both need to be suspended
1246 */
1247static int marvell_suspend(struct phy_device *phydev)
1248{
1249 int err;
1250
1251 /* Suspend the fiber mode first */
1252 if (!(phydev->supported & SUPPORTED_FIBRE)) {
1253 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1254 if (err < 0)
1255 goto error;
1256
1257 /* With the page set, use the generic suspend */
1258 err = genphy_suspend(phydev);
1259 if (err < 0)
1260 goto error;
1261
1262 /* Then, the copper link */
1263 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1264 if (err < 0)
1265 goto error;
1266 }
1267
1268 /* With the page set, use the generic suspend */
1269 return genphy_suspend(phydev);
1270
1271error:
1272 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1273 return err;
1274}
1275
1276/* marvell_resume
1277 *
1278 * Some Marvell's phys have two modes: fiber and copper.
1279 * Both need to be resumed
1280 */
1281static int marvell_resume(struct phy_device *phydev)
1282{
1283 int err;
1284
1285 /* Resume the fiber mode first */
1286 if (!(phydev->supported & SUPPORTED_FIBRE)) {
1287 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1288 if (err < 0)
1289 goto error;
1290
1291 /* With the page set, use the generic resume */
1292 err = genphy_resume(phydev);
1293 if (err < 0)
1294 goto error;
1295
1296 /* Then, the copper link */
1297 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1298 if (err < 0)
1299 goto error;
1300 }
1301
1302 /* With the page set, use the generic resume */
1303 return genphy_resume(phydev);
1304
1305error:
1306 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1307 return err;
1308}
1309
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001310static int marvell_aneg_done(struct phy_device *phydev)
1311{
1312 int retval = phy_read(phydev, MII_M1011_PHY_STATUS);
1313 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
1314}
1315
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001316static int m88e1121_did_interrupt(struct phy_device *phydev)
1317{
1318 int imask;
1319
1320 imask = phy_read(phydev, MII_M1011_IEVENT);
1321
1322 if (imask & MII_M1011_IMASK_INIT)
1323 return 1;
1324
1325 return 0;
1326}
1327
Michael Stapelberg3871c382013-03-11 13:56:45 +00001328static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1329{
1330 wol->supported = WAKE_MAGIC;
1331 wol->wolopts = 0;
1332
1333 if (phy_write(phydev, MII_MARVELL_PHY_PAGE,
1334 MII_88E1318S_PHY_WOL_PAGE) < 0)
1335 return;
1336
1337 if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) &
1338 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
1339 wol->wolopts |= WAKE_MAGIC;
1340
1341 if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0)
1342 return;
1343}
1344
1345static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1346{
1347 int err, oldpage, temp;
1348
1349 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1350
1351 if (wol->wolopts & WAKE_MAGIC) {
1352 /* Explicitly switch to page 0x00, just to be sure */
1353 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00);
1354 if (err < 0)
1355 return err;
1356
1357 /* Enable the WOL interrupt */
1358 temp = phy_read(phydev, MII_88E1318S_PHY_CSIER);
1359 temp |= MII_88E1318S_PHY_CSIER_WOL_EIE;
1360 err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp);
1361 if (err < 0)
1362 return err;
1363
1364 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1365 MII_88E1318S_PHY_LED_PAGE);
1366 if (err < 0)
1367 return err;
1368
1369 /* Setup LED[2] as interrupt pin (active low) */
1370 temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR);
1371 temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT;
1372 temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE;
1373 temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW;
1374 err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp);
1375 if (err < 0)
1376 return err;
1377
1378 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1379 MII_88E1318S_PHY_WOL_PAGE);
1380 if (err < 0)
1381 return err;
1382
1383 /* Store the device address for the magic packet */
1384 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
1385 ((phydev->attached_dev->dev_addr[5] << 8) |
1386 phydev->attached_dev->dev_addr[4]));
1387 if (err < 0)
1388 return err;
1389 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
1390 ((phydev->attached_dev->dev_addr[3] << 8) |
1391 phydev->attached_dev->dev_addr[2]));
1392 if (err < 0)
1393 return err;
1394 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
1395 ((phydev->attached_dev->dev_addr[1] << 8) |
1396 phydev->attached_dev->dev_addr[0]));
1397 if (err < 0)
1398 return err;
1399
1400 /* Clear WOL status and enable magic packet matching */
1401 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1402 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1403 temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1404 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1405 if (err < 0)
1406 return err;
1407 } else {
1408 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1409 MII_88E1318S_PHY_WOL_PAGE);
1410 if (err < 0)
1411 return err;
1412
1413 /* Clear WOL status and disable magic packet matching */
1414 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1415 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1416 temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1417 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1418 if (err < 0)
1419 return err;
1420 }
1421
1422 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1423 if (err < 0)
1424 return err;
1425
1426 return 0;
1427}
1428
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001429static int marvell_get_sset_count(struct phy_device *phydev)
1430{
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +02001431 if (phydev->supported & SUPPORTED_FIBRE)
1432 return ARRAY_SIZE(marvell_hw_stats);
1433 else
1434 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001435}
1436
1437static void marvell_get_strings(struct phy_device *phydev, u8 *data)
1438{
1439 int i;
1440
1441 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1442 memcpy(data + i * ETH_GSTRING_LEN,
1443 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1444 }
1445}
1446
1447#ifndef UINT64_MAX
1448#define UINT64_MAX (u64)(~((u64)0))
1449#endif
1450static u64 marvell_get_stat(struct phy_device *phydev, int i)
1451{
1452 struct marvell_hw_stat stat = marvell_hw_stats[i];
1453 struct marvell_priv *priv = phydev->priv;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001454 int err, oldpage, val;
1455 u64 ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001456
1457 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1458 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1459 stat.page);
1460 if (err < 0)
1461 return UINT64_MAX;
1462
1463 val = phy_read(phydev, stat.reg);
1464 if (val < 0) {
Andrew Lunn321b4d42016-02-20 00:35:29 +01001465 ret = UINT64_MAX;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001466 } else {
1467 val = val & ((1 << stat.bits) - 1);
1468 priv->stats[i] += val;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001469 ret = priv->stats[i];
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001470 }
1471
1472 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1473
Andrew Lunn321b4d42016-02-20 00:35:29 +01001474 return ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001475}
1476
1477static void marvell_get_stats(struct phy_device *phydev,
1478 struct ethtool_stats *stats, u64 *data)
1479{
1480 int i;
1481
1482 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
1483 data[i] = marvell_get_stat(phydev, i);
1484}
1485
Andrew Lunn0b046802017-01-20 01:37:49 +01001486#ifdef CONFIG_HWMON
1487static int m88e1121_get_temp(struct phy_device *phydev, long *temp)
1488{
1489 int ret;
1490 int val;
1491
1492 *temp = 0;
1493
1494 mutex_lock(&phydev->lock);
1495
1496 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1497 if (ret < 0)
1498 goto error;
1499
1500 /* Enable temperature sensor */
1501 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1502 if (ret < 0)
1503 goto error;
1504
1505 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1506 ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1507 if (ret < 0)
1508 goto error;
1509
1510 /* Wait for temperature to stabilize */
1511 usleep_range(10000, 12000);
1512
1513 val = phy_read(phydev, MII_88E1121_MISC_TEST);
1514 if (val < 0) {
1515 ret = val;
1516 goto error;
1517 }
1518
1519 /* Disable temperature sensor */
1520 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1521 ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1522 if (ret < 0)
1523 goto error;
1524
1525 *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000;
1526
1527error:
1528 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1529 mutex_unlock(&phydev->lock);
1530
1531 return ret;
1532}
1533
1534static int m88e1121_hwmon_read(struct device *dev,
1535 enum hwmon_sensor_types type,
1536 u32 attr, int channel, long *temp)
1537{
1538 struct phy_device *phydev = dev_get_drvdata(dev);
1539 int err;
1540
1541 switch (attr) {
1542 case hwmon_temp_input:
1543 err = m88e1121_get_temp(phydev, temp);
1544 break;
1545 default:
1546 return -EOPNOTSUPP;
1547 }
1548
1549 return err;
1550}
1551
1552static umode_t m88e1121_hwmon_is_visible(const void *data,
1553 enum hwmon_sensor_types type,
1554 u32 attr, int channel)
1555{
1556 if (type != hwmon_temp)
1557 return 0;
1558
1559 switch (attr) {
1560 case hwmon_temp_input:
1561 return 0444;
1562 default:
1563 return 0;
1564 }
1565}
1566
1567static u32 m88e1121_hwmon_chip_config[] = {
1568 HWMON_C_REGISTER_TZ,
1569 0
1570};
1571
1572static const struct hwmon_channel_info m88e1121_hwmon_chip = {
1573 .type = hwmon_chip,
1574 .config = m88e1121_hwmon_chip_config,
1575};
1576
1577static u32 m88e1121_hwmon_temp_config[] = {
1578 HWMON_T_INPUT,
1579 0
1580};
1581
1582static const struct hwmon_channel_info m88e1121_hwmon_temp = {
1583 .type = hwmon_temp,
1584 .config = m88e1121_hwmon_temp_config,
1585};
1586
1587static const struct hwmon_channel_info *m88e1121_hwmon_info[] = {
1588 &m88e1121_hwmon_chip,
1589 &m88e1121_hwmon_temp,
1590 NULL
1591};
1592
1593static const struct hwmon_ops m88e1121_hwmon_hwmon_ops = {
1594 .is_visible = m88e1121_hwmon_is_visible,
1595 .read = m88e1121_hwmon_read,
1596};
1597
1598static const struct hwmon_chip_info m88e1121_hwmon_chip_info = {
1599 .ops = &m88e1121_hwmon_hwmon_ops,
1600 .info = m88e1121_hwmon_info,
1601};
1602
1603static int m88e1510_get_temp(struct phy_device *phydev, long *temp)
1604{
1605 int ret;
1606
1607 *temp = 0;
1608
1609 mutex_lock(&phydev->lock);
1610
1611 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1612 if (ret < 0)
1613 goto error;
1614
1615 ret = phy_read(phydev, MII_88E1510_TEMP_SENSOR);
1616 if (ret < 0)
1617 goto error;
1618
1619 *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000;
1620
1621error:
1622 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1623 mutex_unlock(&phydev->lock);
1624
1625 return ret;
1626}
1627
1628int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp)
1629{
1630 int ret;
1631
1632 *temp = 0;
1633
1634 mutex_lock(&phydev->lock);
1635
1636 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1637 if (ret < 0)
1638 goto error;
1639
1640 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1641 if (ret < 0)
1642 goto error;
1643
1644 *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >>
1645 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25;
1646 /* convert to mC */
1647 *temp *= 1000;
1648
1649error:
1650 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1651 mutex_unlock(&phydev->lock);
1652
1653 return ret;
1654}
1655
1656int m88e1510_set_temp_critical(struct phy_device *phydev, long temp)
1657{
1658 int ret;
1659
1660 mutex_lock(&phydev->lock);
1661
1662 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1663 if (ret < 0)
1664 goto error;
1665
1666 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1667 if (ret < 0)
1668 goto error;
1669
1670 temp = temp / 1000;
1671 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
1672 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1673 (ret & ~MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) |
1674 (temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT));
1675
1676error:
1677 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1678 mutex_unlock(&phydev->lock);
1679
1680 return ret;
1681}
1682
1683int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm)
1684{
1685 int ret;
1686
1687 *alarm = false;
1688
1689 mutex_lock(&phydev->lock);
1690
1691 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1692 if (ret < 0)
1693 goto error;
1694
1695 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1696 if (ret < 0)
1697 goto error;
1698 *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ);
1699
1700error:
1701 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1702 mutex_unlock(&phydev->lock);
1703
1704 return ret;
1705}
1706
1707static int m88e1510_hwmon_read(struct device *dev,
1708 enum hwmon_sensor_types type,
1709 u32 attr, int channel, long *temp)
1710{
1711 struct phy_device *phydev = dev_get_drvdata(dev);
1712 int err;
1713
1714 switch (attr) {
1715 case hwmon_temp_input:
1716 err = m88e1510_get_temp(phydev, temp);
1717 break;
1718 case hwmon_temp_crit:
1719 err = m88e1510_get_temp_critical(phydev, temp);
1720 break;
1721 case hwmon_temp_max_alarm:
1722 err = m88e1510_get_temp_alarm(phydev, temp);
1723 break;
1724 default:
1725 return -EOPNOTSUPP;
1726 }
1727
1728 return err;
1729}
1730
1731static int m88e1510_hwmon_write(struct device *dev,
1732 enum hwmon_sensor_types type,
1733 u32 attr, int channel, long temp)
1734{
1735 struct phy_device *phydev = dev_get_drvdata(dev);
1736 int err;
1737
1738 switch (attr) {
1739 case hwmon_temp_crit:
1740 err = m88e1510_set_temp_critical(phydev, temp);
1741 break;
1742 default:
1743 return -EOPNOTSUPP;
1744 }
1745 return err;
1746}
1747
1748static umode_t m88e1510_hwmon_is_visible(const void *data,
1749 enum hwmon_sensor_types type,
1750 u32 attr, int channel)
1751{
1752 if (type != hwmon_temp)
1753 return 0;
1754
1755 switch (attr) {
1756 case hwmon_temp_input:
1757 case hwmon_temp_max_alarm:
1758 return 0444;
1759 case hwmon_temp_crit:
1760 return 0644;
1761 default:
1762 return 0;
1763 }
1764}
1765
1766static u32 m88e1510_hwmon_temp_config[] = {
1767 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM,
1768 0
1769};
1770
1771static const struct hwmon_channel_info m88e1510_hwmon_temp = {
1772 .type = hwmon_temp,
1773 .config = m88e1510_hwmon_temp_config,
1774};
1775
1776static const struct hwmon_channel_info *m88e1510_hwmon_info[] = {
1777 &m88e1121_hwmon_chip,
1778 &m88e1510_hwmon_temp,
1779 NULL
1780};
1781
1782static const struct hwmon_ops m88e1510_hwmon_hwmon_ops = {
1783 .is_visible = m88e1510_hwmon_is_visible,
1784 .read = m88e1510_hwmon_read,
1785 .write = m88e1510_hwmon_write,
1786};
1787
1788static const struct hwmon_chip_info m88e1510_hwmon_chip_info = {
1789 .ops = &m88e1510_hwmon_hwmon_ops,
1790 .info = m88e1510_hwmon_info,
1791};
1792
1793static int marvell_hwmon_name(struct phy_device *phydev)
1794{
1795 struct marvell_priv *priv = phydev->priv;
1796 struct device *dev = &phydev->mdio.dev;
1797 const char *devname = dev_name(dev);
1798 size_t len = strlen(devname);
1799 int i, j;
1800
1801 priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL);
1802 if (!priv->hwmon_name)
1803 return -ENOMEM;
1804
1805 for (i = j = 0; i < len && devname[i]; i++) {
1806 if (isalnum(devname[i]))
1807 priv->hwmon_name[j++] = devname[i];
1808 }
1809
1810 return 0;
1811}
1812
1813static int marvell_hwmon_probe(struct phy_device *phydev,
1814 const struct hwmon_chip_info *chip)
1815{
1816 struct marvell_priv *priv = phydev->priv;
1817 struct device *dev = &phydev->mdio.dev;
1818 int err;
1819
1820 err = marvell_hwmon_name(phydev);
1821 if (err)
1822 return err;
1823
1824 priv->hwmon_dev = devm_hwmon_device_register_with_info(
1825 dev, priv->hwmon_name, phydev, chip, NULL);
1826
1827 return PTR_ERR_OR_ZERO(priv->hwmon_dev);
1828}
1829
1830static int m88e1121_hwmon_probe(struct phy_device *phydev)
1831{
1832 return marvell_hwmon_probe(phydev, &m88e1121_hwmon_chip_info);
1833}
1834
1835static int m88e1510_hwmon_probe(struct phy_device *phydev)
1836{
1837 return marvell_hwmon_probe(phydev, &m88e1510_hwmon_chip_info);
1838}
1839#else
1840static int m88e1121_hwmon_probe(struct phy_device *phydev)
1841{
1842 return 0;
1843}
1844
1845static int m88e1510_hwmon_probe(struct phy_device *phydev)
1846{
1847 return 0;
1848}
1849#endif
1850
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001851static int marvell_probe(struct phy_device *phydev)
1852{
1853 struct marvell_priv *priv;
1854
Andrew Lunne5a03bf2016-01-06 20:11:16 +01001855 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001856 if (!priv)
1857 return -ENOMEM;
1858
1859 phydev->priv = priv;
1860
1861 return 0;
1862}
1863
Andrew Lunn0b046802017-01-20 01:37:49 +01001864static int m88e1121_probe(struct phy_device *phydev)
1865{
1866 int err;
1867
1868 err = marvell_probe(phydev);
1869 if (err)
1870 return err;
1871
1872 return m88e1121_hwmon_probe(phydev);
1873}
1874
1875static int m88e1510_probe(struct phy_device *phydev)
1876{
1877 int err;
1878
1879 err = marvell_probe(phydev);
1880 if (err)
1881 return err;
1882
1883 return m88e1510_hwmon_probe(phydev);
1884}
1885
1886static void marvell_remove(struct phy_device *phydev)
1887{
1888#ifdef CONFIG_HWMON
1889
1890 struct marvell_priv *priv = phydev->priv;
1891
1892 if (priv && priv->hwmon_dev)
1893 hwmon_device_unregister(priv->hwmon_dev);
1894#endif
1895}
1896
Olof Johanssone5479232007-07-03 16:23:46 -05001897static struct phy_driver marvell_drivers[] = {
1898 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001899 .phy_id = MARVELL_PHY_ID_88E1101,
1900 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001901 .name = "Marvell 88E1101",
1902 .features = PHY_GBIT_FEATURES,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001903 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001904 .flags = PHY_HAS_INTERRUPT,
Clemens Gruber79be1a12016-02-15 23:46:45 +01001905 .config_init = &marvell_config_init,
Olof Johanssone5479232007-07-03 16:23:46 -05001906 .config_aneg = &marvell_config_aneg,
1907 .read_status = &genphy_read_status,
1908 .ack_interrupt = &marvell_ack_interrupt,
1909 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001910 .resume = &genphy_resume,
1911 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001912 .get_sset_count = marvell_get_sset_count,
1913 .get_strings = marvell_get_strings,
1914 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001915 },
1916 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001917 .phy_id = MARVELL_PHY_ID_88E1112,
1918 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johansson85cfb532007-07-03 16:24:32 -05001919 .name = "Marvell 88E1112",
1920 .features = PHY_GBIT_FEATURES,
1921 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001922 .probe = marvell_probe,
Olof Johansson85cfb532007-07-03 16:24:32 -05001923 .config_init = &m88e1111_config_init,
1924 .config_aneg = &marvell_config_aneg,
1925 .read_status = &genphy_read_status,
1926 .ack_interrupt = &marvell_ack_interrupt,
1927 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001928 .resume = &genphy_resume,
1929 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001930 .get_sset_count = marvell_get_sset_count,
1931 .get_strings = marvell_get_strings,
1932 .get_stats = marvell_get_stats,
Olof Johansson85cfb532007-07-03 16:24:32 -05001933 },
1934 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001935 .phy_id = MARVELL_PHY_ID_88E1111,
1936 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001937 .name = "Marvell 88E1111",
1938 .features = PHY_GBIT_FEATURES,
1939 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001940 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001941 .config_init = &m88e1111_config_init,
Harini Katakam3ec0a0f2016-06-27 13:09:59 +05301942 .config_aneg = &m88e1111_config_aneg,
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001943 .read_status = &marvell_read_status,
Olof Johanssone5479232007-07-03 16:23:46 -05001944 .ack_interrupt = &marvell_ack_interrupt,
1945 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001946 .resume = &genphy_resume,
1947 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001948 .get_sset_count = marvell_get_sset_count,
1949 .get_strings = marvell_get_strings,
1950 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001951 },
1952 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001953 .phy_id = MARVELL_PHY_ID_88E1118,
1954 .phy_id_mask = MARVELL_PHY_ID_MASK,
Ron Madrid605f1962008-11-06 09:05:26 +00001955 .name = "Marvell 88E1118",
1956 .features = PHY_GBIT_FEATURES,
1957 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001958 .probe = marvell_probe,
Ron Madrid605f1962008-11-06 09:05:26 +00001959 .config_init = &m88e1118_config_init,
1960 .config_aneg = &m88e1118_config_aneg,
1961 .read_status = &genphy_read_status,
1962 .ack_interrupt = &marvell_ack_interrupt,
1963 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001964 .resume = &genphy_resume,
1965 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001966 .get_sset_count = marvell_get_sset_count,
1967 .get_strings = marvell_get_strings,
1968 .get_stats = marvell_get_stats,
Ron Madrid605f1962008-11-06 09:05:26 +00001969 },
1970 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001971 .phy_id = MARVELL_PHY_ID_88E1121R,
1972 .phy_id_mask = MARVELL_PHY_ID_MASK,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001973 .name = "Marvell 88E1121R",
Andrew Lunn0b046802017-01-20 01:37:49 +01001974 .probe = &m88e1121_probe,
1975 .remove = &marvell_remove,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001976 .features = PHY_GBIT_FEATURES,
1977 .flags = PHY_HAS_INTERRUPT,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001978 .config_init = &m88e1121_config_init,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001979 .config_aneg = &m88e1121_config_aneg,
1980 .read_status = &marvell_read_status,
1981 .ack_interrupt = &marvell_ack_interrupt,
1982 .config_intr = &marvell_config_intr,
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001983 .did_interrupt = &m88e1121_did_interrupt,
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,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001989 },
1990 {
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001991 .phy_id = MARVELL_PHY_ID_88E1318S,
Linus Torvalds6ba74012010-08-04 11:47:58 -07001992 .phy_id_mask = MARVELL_PHY_ID_MASK,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001993 .name = "Marvell 88E1318S",
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001994 .features = PHY_GBIT_FEATURES,
1995 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001996 .probe = marvell_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001997 .config_init = &m88e1121_config_init,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001998 .config_aneg = &m88e1318_config_aneg,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001999 .read_status = &marvell_read_status,
2000 .ack_interrupt = &marvell_ack_interrupt,
2001 .config_intr = &marvell_config_intr,
2002 .did_interrupt = &m88e1121_did_interrupt,
Michael Stapelberg3871c382013-03-11 13:56:45 +00002003 .get_wol = &m88e1318_get_wol,
2004 .set_wol = &m88e1318_set_wol,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002005 .resume = &genphy_resume,
2006 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002007 .get_sset_count = marvell_get_sset_count,
2008 .get_strings = marvell_get_strings,
2009 .get_stats = marvell_get_stats,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07002010 },
2011 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002012 .phy_id = MARVELL_PHY_ID_88E1145,
2013 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05002014 .name = "Marvell 88E1145",
2015 .features = PHY_GBIT_FEATURES,
2016 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002017 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05002018 .config_init = &m88e1145_config_init,
2019 .config_aneg = &marvell_config_aneg,
2020 .read_status = &genphy_read_status,
2021 .ack_interrupt = &marvell_ack_interrupt,
2022 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002023 .resume = &genphy_resume,
2024 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002025 .get_sset_count = marvell_get_sset_count,
2026 .get_strings = marvell_get_strings,
2027 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002028 },
2029 {
David Daney90600732010-11-19 11:58:53 +00002030 .phy_id = MARVELL_PHY_ID_88E1149R,
2031 .phy_id_mask = MARVELL_PHY_ID_MASK,
2032 .name = "Marvell 88E1149R",
2033 .features = PHY_GBIT_FEATURES,
2034 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002035 .probe = marvell_probe,
David Daney90600732010-11-19 11:58:53 +00002036 .config_init = &m88e1149_config_init,
2037 .config_aneg = &m88e1118_config_aneg,
2038 .read_status = &genphy_read_status,
2039 .ack_interrupt = &marvell_ack_interrupt,
2040 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002041 .resume = &genphy_resume,
2042 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002043 .get_sset_count = marvell_get_sset_count,
2044 .get_strings = marvell_get_strings,
2045 .get_stats = marvell_get_stats,
David Daney90600732010-11-19 11:58:53 +00002046 },
2047 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002048 .phy_id = MARVELL_PHY_ID_88E1240,
2049 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002050 .name = "Marvell 88E1240",
2051 .features = PHY_GBIT_FEATURES,
2052 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002053 .probe = marvell_probe,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002054 .config_init = &m88e1111_config_init,
2055 .config_aneg = &marvell_config_aneg,
2056 .read_status = &genphy_read_status,
2057 .ack_interrupt = &marvell_ack_interrupt,
2058 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002059 .resume = &genphy_resume,
2060 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002061 .get_sset_count = marvell_get_sset_count,
2062 .get_strings = marvell_get_strings,
2063 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002064 },
Michal Simek3da09a52013-05-30 20:08:26 +00002065 {
2066 .phy_id = MARVELL_PHY_ID_88E1116R,
2067 .phy_id_mask = MARVELL_PHY_ID_MASK,
2068 .name = "Marvell 88E1116R",
2069 .features = PHY_GBIT_FEATURES,
2070 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002071 .probe = marvell_probe,
Michal Simek3da09a52013-05-30 20:08:26 +00002072 .config_init = &m88e1116r_config_init,
2073 .config_aneg = &genphy_config_aneg,
2074 .read_status = &genphy_read_status,
2075 .ack_interrupt = &marvell_ack_interrupt,
2076 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002077 .resume = &genphy_resume,
2078 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002079 .get_sset_count = marvell_get_sset_count,
2080 .get_strings = marvell_get_strings,
2081 .get_stats = marvell_get_stats,
Michal Simek3da09a52013-05-30 20:08:26 +00002082 },
Michal Simek10e24caa2013-05-30 20:08:27 +00002083 {
2084 .phy_id = MARVELL_PHY_ID_88E1510,
2085 .phy_id_mask = MARVELL_PHY_ID_MASK,
2086 .name = "Marvell 88E1510",
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02002087 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE,
Andrew Lunn0b046802017-01-20 01:37:49 +01002088 .probe = &m88e1510_probe,
2089 .remove = &marvell_remove,
2090 .features = PHY_GBIT_FEATURES,
Michal Simek10e24caa2013-05-30 20:08:27 +00002091 .flags = PHY_HAS_INTERRUPT,
Stefan Roese930b37e2016-02-18 10:59:07 +01002092 .config_init = &m88e1510_config_init,
Michal Simek10e24caa2013-05-30 20:08:27 +00002093 .config_aneg = &m88e1510_config_aneg,
2094 .read_status = &marvell_read_status,
2095 .ack_interrupt = &marvell_ack_interrupt,
2096 .config_intr = &marvell_config_intr,
2097 .did_interrupt = &m88e1121_did_interrupt,
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02002098 .resume = &marvell_resume,
2099 .suspend = &marvell_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002100 .get_sset_count = marvell_get_sset_count,
2101 .get_strings = marvell_get_strings,
2102 .get_stats = marvell_get_stats,
Michal Simek10e24caa2013-05-30 20:08:27 +00002103 },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002104 {
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002105 .phy_id = MARVELL_PHY_ID_88E1540,
2106 .phy_id_mask = MARVELL_PHY_ID_MASK,
2107 .name = "Marvell 88E1540",
Andrew Lunn0b046802017-01-20 01:37:49 +01002108 .probe = m88e1510_probe,
2109 .remove = &marvell_remove,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002110 .features = PHY_GBIT_FEATURES,
2111 .flags = PHY_HAS_INTERRUPT,
Clemens Gruber79be1a12016-02-15 23:46:45 +01002112 .config_init = &marvell_config_init,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002113 .config_aneg = &m88e1510_config_aneg,
2114 .read_status = &marvell_read_status,
2115 .ack_interrupt = &marvell_ack_interrupt,
2116 .config_intr = &marvell_config_intr,
2117 .did_interrupt = &m88e1121_did_interrupt,
2118 .resume = &genphy_resume,
2119 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002120 .get_sset_count = marvell_get_sset_count,
2121 .get_strings = marvell_get_strings,
2122 .get_stats = marvell_get_stats,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002123 },
2124 {
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002125 .phy_id = MARVELL_PHY_ID_88E3016,
2126 .phy_id_mask = MARVELL_PHY_ID_MASK,
2127 .name = "Marvell 88E3016",
2128 .features = PHY_BASIC_FEATURES,
2129 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002130 .probe = marvell_probe,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002131 .config_aneg = &genphy_config_aneg,
2132 .config_init = &m88e3016_config_init,
2133 .aneg_done = &marvell_aneg_done,
2134 .read_status = &marvell_read_status,
2135 .ack_interrupt = &marvell_ack_interrupt,
2136 .config_intr = &marvell_config_intr,
2137 .did_interrupt = &m88e1121_did_interrupt,
2138 .resume = &genphy_resume,
2139 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002140 .get_sset_count = marvell_get_sset_count,
2141 .get_strings = marvell_get_strings,
2142 .get_stats = marvell_get_stats,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002143 },
Andy Fleming00db8182005-07-30 19:31:23 -04002144};
2145
Johan Hovold50fd7152014-11-11 19:45:59 +01002146module_phy_driver(marvell_drivers);
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002147
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +00002148static struct mdio_device_id __maybe_unused marvell_tbl[] = {
Michal Simekf5e1cab2013-05-30 20:08:25 +00002149 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
2150 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
2151 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
2152 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
2153 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
2154 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
2155 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
2156 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
2157 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
Michal Simek3da09a52013-05-30 20:08:26 +00002158 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
Michal Simek10e24caa2013-05-30 20:08:27 +00002159 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002160 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002161 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK },
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002162 { }
2163};
2164
2165MODULE_DEVICE_TABLE(mdio, marvell_tbl);