blob: 2aacbf8e0eb3bdc28378c1d5920308e76652cfc2 [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
Andrew Lunn0c3439b2017-05-17 03:25:59 +0200260 * to restart autonegotiation
261 */
Andy Fleming00db8182005-07-30 19:31:23 -0400262 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
263
264 if (err < 0)
265 return err;
266
267 err = phy_write(phydev, 0x1d, 0x1f);
268 if (err < 0)
269 return err;
270
271 err = phy_write(phydev, 0x1e, 0x200c);
272 if (err < 0)
273 return err;
274
275 err = phy_write(phydev, 0x1d, 0x5);
276 if (err < 0)
277 return err;
278
279 err = phy_write(phydev, 0x1e, 0);
280 if (err < 0)
281 return err;
282
283 err = phy_write(phydev, 0x1e, 0x100);
284 if (err < 0)
285 return err;
286
Raju Lakkaraju4e26c5c2016-11-29 15:16:49 +0530287 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
Andy Fleming76884672007-02-09 18:13:58 -0600288 if (err < 0)
289 return err;
290
291 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
292 MII_M1111_PHY_LED_DIRECT);
293 if (err < 0)
294 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400295
296 err = genphy_config_aneg(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000297 if (err < 0)
298 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400299
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000300 if (phydev->autoneg != AUTONEG_ENABLE) {
301 int bmcr;
302
Andrew Lunn0c3439b2017-05-17 03:25:59 +0200303 /* A write to speed/duplex bits (that is performed by
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000304 * 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
Andrew Lunn0c3439b2017-05-17 03:25:59 +0200362/* Set and/or override some configuration registers based on the
David Daneycf41a512010-11-19 12:13:18 +0000363 * marvell,reg-init property stored in the of_node for the phydev.
364 *
365 * marvell,reg-init = <reg-page reg mask value>,...;
366 *
367 * There may be one or more sets of <reg-page reg mask value>:
368 *
369 * reg-page: which register bank to use.
370 * reg: the register.
371 * mask: if non-zero, ANDed with existing register value.
372 * value: ORed with the masked value and written to the regiser.
373 *
374 */
375static int marvell_of_reg_init(struct phy_device *phydev)
376{
377 const __be32 *paddr;
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100378 int len, i, saved_page, current_page, ret;
David Daneycf41a512010-11-19 12:13:18 +0000379
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100380 if (!phydev->mdio.dev.of_node)
David Daneycf41a512010-11-19 12:13:18 +0000381 return 0;
382
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100383 paddr = of_get_property(phydev->mdio.dev.of_node,
384 "marvell,reg-init", &len);
David Daneycf41a512010-11-19 12:13:18 +0000385 if (!paddr || len < (4 * sizeof(*paddr)))
386 return 0;
387
388 saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE);
389 if (saved_page < 0)
390 return saved_page;
David Daneycf41a512010-11-19 12:13:18 +0000391 current_page = saved_page;
392
393 ret = 0;
394 len /= sizeof(*paddr);
395 for (i = 0; i < len - 3; i += 4) {
396 u16 reg_page = be32_to_cpup(paddr + i);
397 u16 reg = be32_to_cpup(paddr + i + 1);
398 u16 mask = be32_to_cpup(paddr + i + 2);
399 u16 val_bits = be32_to_cpup(paddr + i + 3);
400 int val;
401
402 if (reg_page != current_page) {
403 current_page = reg_page;
David Daneycf41a512010-11-19 12:13:18 +0000404 ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page);
405 if (ret < 0)
406 goto err;
407 }
408
409 val = 0;
410 if (mask) {
411 val = phy_read(phydev, reg);
412 if (val < 0) {
413 ret = val;
414 goto err;
415 }
416 val &= mask;
417 }
418 val |= val_bits;
419
420 ret = phy_write(phydev, reg, val);
421 if (ret < 0)
422 goto err;
423
424 }
425err:
Uwe Kleine-Königb5718b52016-11-10 15:03:01 +0100426 if (current_page != saved_page) {
David Daneycf41a512010-11-19 12:13:18 +0000427 i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page);
428 if (ret == 0)
429 ret = i;
430 }
431 return ret;
432}
433#else
434static int marvell_of_reg_init(struct phy_device *phydev)
435{
436 return 0;
437}
438#endif /* CONFIG_OF_MDIO */
439
Sergei Poselenov140bc922009-04-07 02:01:41 +0000440static int m88e1121_config_aneg(struct phy_device *phydev)
441{
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000442 int err, oldpage, mscr;
443
David Daney27d916d2010-11-19 11:58:52 +0000444 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000445
David Daney27d916d2010-11-19 11:58:52 +0000446 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000447 MII_88E1121_PHY_MSCR_PAGE);
448 if (err < 0)
449 return err;
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000450
Florian Fainelli32a64162015-05-26 12:19:59 -0700451 if (phy_interface_is_rgmii(phydev)) {
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000452
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700453 mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
454 MII_88E1121_PHY_MSCR_DELAY_MASK;
455
456 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
457 mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
458 MII_88E1121_PHY_MSCR_TX_DELAY);
459 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
460 mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
461 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
462 mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
463
464 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
465 if (err < 0)
466 return err;
467 }
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000468
David Daney27d916d2010-11-19 11:58:52 +0000469 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000470
471 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
472 if (err < 0)
473 return err;
474
475 err = phy_write(phydev, MII_M1011_PHY_SCR,
476 MII_M1011_PHY_SCR_AUTO_CROSS);
477 if (err < 0)
478 return err;
479
Clemens Gruberfdecf362016-06-11 17:21:26 +0200480 return genphy_config_aneg(phydev);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000481}
482
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700483static int m88e1318_config_aneg(struct phy_device *phydev)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700484{
485 int err, oldpage, mscr;
486
David Daney27d916d2010-11-19 11:58:52 +0000487 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700488
David Daney27d916d2010-11-19 11:58:52 +0000489 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700490 MII_88E1121_PHY_MSCR_PAGE);
491 if (err < 0)
492 return err;
493
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700494 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
495 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700496
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700497 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700498 if (err < 0)
499 return err;
500
David Daney27d916d2010-11-19 11:58:52 +0000501 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700502 if (err < 0)
503 return err;
504
505 return m88e1121_config_aneg(phydev);
506}
507
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200508/**
509 * ethtool_adv_to_fiber_adv_t
510 * @ethadv: the ethtool advertisement settings
511 *
512 * A small helper function that translates ethtool advertisement
513 * settings to phy autonegotiation advertisements for the
514 * MII_ADV register for fiber link.
515 */
516static inline u32 ethtool_adv_to_fiber_adv_t(u32 ethadv)
517{
518 u32 result = 0;
519
520 if (ethadv & ADVERTISED_1000baseT_Half)
521 result |= ADVERTISE_FIBER_1000HALF;
522 if (ethadv & ADVERTISED_1000baseT_Full)
523 result |= ADVERTISE_FIBER_1000FULL;
524
525 if ((ethadv & ADVERTISE_PAUSE_ASYM) && (ethadv & ADVERTISE_PAUSE_CAP))
526 result |= LPA_PAUSE_ASYM_FIBER;
527 else if (ethadv & ADVERTISE_PAUSE_CAP)
528 result |= (ADVERTISE_PAUSE_FIBER
529 & (~ADVERTISE_PAUSE_ASYM_FIBER));
530
531 return result;
532}
533
534/**
535 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR
536 * @phydev: target phy_device struct
537 *
538 * Description: If auto-negotiation is enabled, we configure the
539 * advertising, and then restart auto-negotiation. If it is not
540 * enabled, then we write the BMCR. Adapted for fiber link in
541 * some Marvell's devices.
542 */
543static int marvell_config_aneg_fiber(struct phy_device *phydev)
544{
545 int changed = 0;
546 int err;
547 int adv, oldadv;
548 u32 advertise;
549
550 if (phydev->autoneg != AUTONEG_ENABLE)
551 return genphy_setup_forced(phydev);
552
553 /* Only allow advertising what this PHY supports */
554 phydev->advertising &= phydev->supported;
555 advertise = phydev->advertising;
556
557 /* Setup fiber advertisement */
558 adv = phy_read(phydev, MII_ADVERTISE);
559 if (adv < 0)
560 return adv;
561
562 oldadv = adv;
563 adv &= ~(ADVERTISE_FIBER_1000HALF | ADVERTISE_FIBER_1000FULL
564 | LPA_PAUSE_FIBER);
565 adv |= ethtool_adv_to_fiber_adv_t(advertise);
566
567 if (adv != oldadv) {
568 err = phy_write(phydev, MII_ADVERTISE, adv);
569 if (err < 0)
570 return err;
571
572 changed = 1;
573 }
574
575 if (changed == 0) {
576 /* Advertisement hasn't changed, but maybe aneg was never on to
577 * begin with? Or maybe phy was isolated?
578 */
579 int ctl = phy_read(phydev, MII_BMCR);
580
581 if (ctl < 0)
582 return ctl;
583
584 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
585 changed = 1; /* do restart aneg */
586 }
587
588 /* Only restart aneg if we are advertising something different
589 * than we were before.
590 */
591 if (changed > 0)
592 changed = genphy_restart_aneg(phydev);
593
594 return changed;
595}
596
Michal Simek10e24caa2013-05-30 20:08:27 +0000597static int m88e1510_config_aneg(struct phy_device *phydev)
598{
599 int err;
600
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200601 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
602 if (err < 0)
603 goto error;
604
605 /* Configure the copper link first */
Michal Simek10e24caa2013-05-30 20:08:27 +0000606 err = m88e1318_config_aneg(phydev);
607 if (err < 0)
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200608 goto error;
Michal Simek10e24caa2013-05-30 20:08:27 +0000609
Charles-Antoine Couret78301eb2016-07-19 11:13:12 +0200610 /* Then the fiber link */
611 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
612 if (err < 0)
613 goto error;
614
615 err = marvell_config_aneg_fiber(phydev);
616 if (err < 0)
617 goto error;
618
619 return phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
620
621error:
622 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
623 return err;
Clemens Gruber79be1a12016-02-15 23:46:45 +0100624}
625
626static int marvell_config_init(struct phy_device *phydev)
627{
628 /* Set registers from marvell,reg-init DT property */
Michal Simek10e24caa2013-05-30 20:08:27 +0000629 return marvell_of_reg_init(phydev);
630}
631
Michal Simek3da09a52013-05-30 20:08:26 +0000632static int m88e1116r_config_init(struct phy_device *phydev)
633{
634 int temp;
635 int err;
636
637 temp = phy_read(phydev, MII_BMCR);
638 temp |= BMCR_RESET;
639 err = phy_write(phydev, MII_BMCR, temp);
640 if (err < 0)
641 return err;
642
643 mdelay(500);
644
645 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
646 if (err < 0)
647 return err;
648
649 temp = phy_read(phydev, MII_M1011_PHY_SCR);
650 temp |= (7 << 12); /* max number of gigabit attempts */
651 temp |= (1 << 11); /* enable downshift */
652 temp |= MII_M1011_PHY_SCR_AUTO_CROSS;
653 err = phy_write(phydev, MII_M1011_PHY_SCR, temp);
654 if (err < 0)
655 return err;
656
657 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2);
658 if (err < 0)
659 return err;
660 temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC);
661 temp |= (1 << 5);
662 temp |= (1 << 4);
663 err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp);
664 if (err < 0)
665 return err;
666 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
667 if (err < 0)
668 return err;
669
670 temp = phy_read(phydev, MII_BMCR);
671 temp |= BMCR_RESET;
672 err = phy_write(phydev, MII_BMCR, temp);
673 if (err < 0)
674 return err;
675
676 mdelay(500);
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
Kim Phillips895ee682007-06-05 18:46:47 +0800700static int m88e1111_config_init(struct phy_device *phydev)
701{
702 int err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300703 int temp;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300704
Florian Fainelli32a64162015-05-26 12:19:59 -0700705 if (phy_interface_is_rgmii(phydev)) {
Kim Phillips895ee682007-06-05 18:46:47 +0800706
Kim Phillips9daf5a72007-11-26 16:17:52 -0600707 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
708 if (temp < 0)
709 return temp;
710
Kim Phillips895ee682007-06-05 18:46:47 +0800711 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Kim Phillips895ee682007-06-05 18:46:47 +0800712 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
Kim Phillips9daf5a72007-11-26 16:17:52 -0600713 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
714 temp &= ~MII_M1111_TX_DELAY;
715 temp |= MII_M1111_RX_DELAY;
716 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
717 temp &= ~MII_M1111_RX_DELAY;
718 temp |= MII_M1111_TX_DELAY;
Kim Phillips895ee682007-06-05 18:46:47 +0800719 }
720
Kim Phillips9daf5a72007-11-26 16:17:52 -0600721 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
722 if (err < 0)
723 return err;
724
Kim Phillips895ee682007-06-05 18:46:47 +0800725 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
726 if (temp < 0)
727 return temp;
728
729 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300730
Wang Jian7239016d2008-07-16 21:46:20 +0800731 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300732 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
733 else
734 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
Kim Phillips895ee682007-06-05 18:46:47 +0800735
736 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
737 if (err < 0)
738 return err;
739 }
740
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500741 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500742 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
743 if (temp < 0)
744 return temp;
745
746 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
747 temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK;
Haiying Wang32d0c1e2009-06-02 04:04:13 +0000748 temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500749
750 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
751 if (err < 0)
752 return err;
Madalin Bucur07151bc2015-08-07 17:07:50 +0800753
754 /* make sure copper is selected */
755 err = phy_read(phydev, MII_M1145_PHY_EXT_ADDR_PAGE);
756 if (err < 0)
757 return err;
758
759 err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE,
760 err & (~0xff));
761 if (err < 0)
762 return err;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500763 }
764
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000765 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
766 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
767 if (temp < 0)
768 return temp;
769 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
770 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
771 if (err < 0)
772 return err;
773
774 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
775 if (temp < 0)
776 return temp;
777 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
778 temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
779 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
780 if (err < 0)
781 return err;
782
783 /* soft reset */
784 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
785 if (err < 0)
786 return err;
787 do
788 temp = phy_read(phydev, MII_BMCR);
789 while (temp & BMCR_RESET);
790
791 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
792 if (temp < 0)
793 return temp;
794 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
795 temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
796 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
797 if (err < 0)
798 return err;
799 }
800
David Daneycf41a512010-11-19 12:13:18 +0000801 err = marvell_of_reg_init(phydev);
802 if (err < 0)
803 return err;
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000804
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000805 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Kim Phillips895ee682007-06-05 18:46:47 +0800806}
807
Clemens Gruberfdecf362016-06-11 17:21:26 +0200808static int m88e1121_config_init(struct phy_device *phydev)
809{
810 int err, oldpage;
811
812 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
813
814 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE);
815 if (err < 0)
816 return err;
817
818 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
819 err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL,
820 MII_88E1121_PHY_LED_DEF);
821 if (err < 0)
822 return err;
823
824 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
825
826 /* Set marvell,reg-init configuration from device tree */
827 return marvell_config_init(phydev);
828}
829
Clemens Gruber407353e2016-02-23 20:16:58 +0100830static int m88e1510_config_init(struct phy_device *phydev)
831{
832 int err;
833 int temp;
834
835 /* SGMII-to-Copper mode initialization */
836 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
837 /* Select page 18 */
838 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 18);
839 if (err < 0)
840 return err;
841
842 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
843 temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1);
844 temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK;
845 temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII;
846 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
847 if (err < 0)
848 return err;
849
850 /* PHY reset is necessary after changing MODE[2:0] */
851 temp |= MII_88E1510_GEN_CTRL_REG_1_RESET;
852 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
853 if (err < 0)
854 return err;
855
856 /* Reset page selection */
857 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
858 if (err < 0)
859 return err;
860 }
861
Clemens Gruberfdecf362016-06-11 17:21:26 +0200862 return m88e1121_config_init(phydev);
Clemens Gruber407353e2016-02-23 20:16:58 +0100863}
864
Ron Madrid605f1962008-11-06 09:05:26 +0000865static int m88e1118_config_aneg(struct phy_device *phydev)
866{
867 int err;
868
869 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
870 if (err < 0)
871 return err;
872
873 err = phy_write(phydev, MII_M1011_PHY_SCR,
874 MII_M1011_PHY_SCR_AUTO_CROSS);
875 if (err < 0)
876 return err;
877
878 err = genphy_config_aneg(phydev);
879 return 0;
880}
881
882static int m88e1118_config_init(struct phy_device *phydev)
883{
884 int err;
885
886 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000887 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
Ron Madrid605f1962008-11-06 09:05:26 +0000888 if (err < 0)
889 return err;
890
891 /* Enable 1000 Mbit */
892 err = phy_write(phydev, 0x15, 0x1070);
893 if (err < 0)
894 return err;
895
896 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000897 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003);
Ron Madrid605f1962008-11-06 09:05:26 +0000898 if (err < 0)
899 return err;
900
901 /* Adjust LED Control */
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000902 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
903 err = phy_write(phydev, 0x10, 0x1100);
904 else
905 err = phy_write(phydev, 0x10, 0x021e);
Ron Madrid605f1962008-11-06 09:05:26 +0000906 if (err < 0)
907 return err;
908
David Daneycf41a512010-11-19 12:13:18 +0000909 err = marvell_of_reg_init(phydev);
910 if (err < 0)
911 return err;
912
Ron Madrid605f1962008-11-06 09:05:26 +0000913 /* Reset address */
David Daney27d916d2010-11-19 11:58:52 +0000914 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
Ron Madrid605f1962008-11-06 09:05:26 +0000915 if (err < 0)
916 return err;
917
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000918 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Ron Madrid605f1962008-11-06 09:05:26 +0000919}
920
David Daney90600732010-11-19 11:58:53 +0000921static int m88e1149_config_init(struct phy_device *phydev)
922{
923 int err;
924
925 /* Change address */
926 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
927 if (err < 0)
928 return err;
929
930 /* Enable 1000 Mbit */
931 err = phy_write(phydev, 0x15, 0x1048);
932 if (err < 0)
933 return err;
934
David Daneycf41a512010-11-19 12:13:18 +0000935 err = marvell_of_reg_init(phydev);
936 if (err < 0)
937 return err;
938
David Daney90600732010-11-19 11:58:53 +0000939 /* Reset address */
940 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
941 if (err < 0)
942 return err;
943
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000944 return phy_write(phydev, MII_BMCR, BMCR_RESET);
David Daney90600732010-11-19 11:58:53 +0000945}
946
Andy Fleming76884672007-02-09 18:13:58 -0600947static int m88e1145_config_init(struct phy_device *phydev)
948{
949 int err;
Viet Nga Daob0224172014-10-23 19:41:53 -0700950 int temp;
Andy Fleming76884672007-02-09 18:13:58 -0600951
952 /* Take care of errata E0 & E1 */
953 err = phy_write(phydev, 0x1d, 0x001b);
954 if (err < 0)
955 return err;
956
957 err = phy_write(phydev, 0x1e, 0x418f);
958 if (err < 0)
959 return err;
960
961 err = phy_write(phydev, 0x1d, 0x0016);
962 if (err < 0)
963 return err;
964
965 err = phy_write(phydev, 0x1e, 0xa2da);
966 if (err < 0)
967 return err;
968
Kim Phillips895ee682007-06-05 18:46:47 +0800969 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andy Fleming76884672007-02-09 18:13:58 -0600970 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
971 if (temp < 0)
972 return temp;
973
974 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
975
976 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
977 if (err < 0)
978 return err;
979
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000980 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
Andy Fleming76884672007-02-09 18:13:58 -0600981 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 if (err < 0)
1003 return err;
1004 }
1005 }
1006
Viet Nga Daob0224172014-10-23 19:41:53 -07001007 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1008 temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
1009 if (temp < 0)
1010 return temp;
1011
Vince Bridgers99d881f2014-10-26 14:22:24 -05001012 temp &= ~MII_M1145_HWCFG_MODE_MASK;
Viet Nga Daob0224172014-10-23 19:41:53 -07001013 temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
1014 temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
1015
1016 err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
1017 if (err < 0)
1018 return err;
1019 }
1020
David Daneycf41a512010-11-19 12:13:18 +00001021 err = marvell_of_reg_init(phydev);
1022 if (err < 0)
1023 return err;
1024
Andy Fleming76884672007-02-09 18:13:58 -06001025 return 0;
1026}
Andy Fleming00db8182005-07-30 19:31:23 -04001027
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001028/**
1029 * fiber_lpa_to_ethtool_lpa_t
1030 * @lpa: value of the MII_LPA register for fiber link
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001031 *
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001032 * A small helper function that translates MII_LPA
1033 * bits to ethtool LP advertisement settings.
1034 */
1035static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa)
1036{
1037 u32 result = 0;
1038
1039 if (lpa & LPA_FIBER_1000HALF)
1040 result |= ADVERTISED_1000baseT_Half;
1041 if (lpa & LPA_FIBER_1000FULL)
1042 result |= ADVERTISED_1000baseT_Full;
1043
1044 return result;
1045}
1046
1047/**
1048 * marvell_update_link - update link status in real time in @phydev
1049 * @phydev: target phy_device struct
1050 *
1051 * Description: Update the value in phydev->link to reflect the
1052 * current link value.
1053 */
1054static int marvell_update_link(struct phy_device *phydev, int fiber)
1055{
1056 int status;
1057
1058 /* Use the generic register for copper link, or specific
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001059 * register for fiber case
1060 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001061 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
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001095 * was an error
1096 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001097 if (page == MII_M1111_FIBER)
1098 fiber = 1;
1099 else
1100 fiber = 0;
1101
1102 err = marvell_update_link(phydev, fiber);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001103 if (err)
1104 return err;
1105
1106 if (AUTONEG_ENABLE == phydev->autoneg) {
1107 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1108 if (status < 0)
1109 return status;
1110
1111 lpa = phy_read(phydev, MII_LPA);
1112 if (lpa < 0)
1113 return lpa;
1114
Russell King357cd642015-09-24 00:07:17 +01001115 lpagb = phy_read(phydev, MII_STAT1000);
1116 if (lpagb < 0)
1117 return lpagb;
1118
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001119 adv = phy_read(phydev, MII_ADVERTISE);
1120 if (adv < 0)
1121 return adv;
1122
1123 lpa &= adv;
1124
1125 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
1126 phydev->duplex = DUPLEX_FULL;
1127 else
1128 phydev->duplex = DUPLEX_HALF;
1129
1130 status = status & MII_M1011_PHY_STATUS_SPD_MASK;
1131 phydev->pause = phydev->asym_pause = 0;
1132
1133 switch (status) {
1134 case MII_M1011_PHY_STATUS_1000:
1135 phydev->speed = SPEED_1000;
1136 break;
1137
1138 case MII_M1011_PHY_STATUS_100:
1139 phydev->speed = SPEED_100;
1140 break;
1141
1142 default:
1143 phydev->speed = SPEED_10;
1144 break;
1145 }
1146
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001147 if (!fiber) {
1148 phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) |
1149 mii_lpa_to_ethtool_lpa_t(lpa);
1150
1151 if (phydev->duplex == DUPLEX_FULL) {
1152 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
1153 phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
1154 }
1155 } else {
1156 /* The fiber link is only 1000M capable */
1157 phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa);
1158
1159 if (phydev->duplex == DUPLEX_FULL) {
1160 if (!(lpa & LPA_PAUSE_FIBER)) {
1161 phydev->pause = 0;
1162 phydev->asym_pause = 0;
1163 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) {
1164 phydev->pause = 1;
1165 phydev->asym_pause = 1;
1166 } else {
1167 phydev->pause = 1;
1168 phydev->asym_pause = 0;
1169 }
1170 }
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001171 }
1172 } else {
1173 int bmcr = phy_read(phydev, MII_BMCR);
1174
1175 if (bmcr < 0)
1176 return bmcr;
1177
1178 if (bmcr & BMCR_FULLDPLX)
1179 phydev->duplex = DUPLEX_FULL;
1180 else
1181 phydev->duplex = DUPLEX_HALF;
1182
1183 if (bmcr & BMCR_SPEED1000)
1184 phydev->speed = SPEED_1000;
1185 else if (bmcr & BMCR_SPEED100)
1186 phydev->speed = SPEED_100;
1187 else
1188 phydev->speed = SPEED_10;
1189
1190 phydev->pause = phydev->asym_pause = 0;
Russell King357cd642015-09-24 00:07:17 +01001191 phydev->lp_advertising = 0;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001192 }
1193
1194 return 0;
1195}
1196
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001197/* marvell_read_status
1198 *
1199 * Some Marvell's phys have two modes: fiber and copper.
1200 * Both need status checked.
1201 * Description:
1202 * First, check the fiber link and status.
1203 * If the fiber link is down, check the copper link and status which
1204 * will be the default value if both link are down.
1205 */
1206static int marvell_read_status(struct phy_device *phydev)
1207{
1208 int err;
1209
1210 /* Check the fiber mode first */
Russell Kinga13c06522017-01-10 23:13:45 +00001211 if (phydev->supported & SUPPORTED_FIBRE &&
1212 phydev->interface != PHY_INTERFACE_MODE_SGMII) {
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001213 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1214 if (err < 0)
1215 goto error;
1216
1217 err = marvell_read_status_page(phydev, MII_M1111_FIBER);
1218 if (err < 0)
1219 goto error;
1220
Andrew Lunn0c3439b2017-05-17 03:25:59 +02001221 /* If the fiber link is up, it is the selected and
1222 * used link. In this case, we need to stay in the
1223 * fiber page. Please to be careful about that, avoid
1224 * to restore Copper page in other functions which
1225 * could break the behaviour for some fiber phy like
1226 * 88E1512.
1227 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001228 if (phydev->link)
1229 return 0;
1230
1231 /* If fiber link is down, check and save copper mode state */
1232 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1233 if (err < 0)
1234 goto error;
1235 }
1236
1237 return marvell_read_status_page(phydev, MII_M1111_COPPER);
1238
1239error:
1240 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1241 return err;
1242}
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02001243
1244/* marvell_suspend
1245 *
1246 * Some Marvell's phys have two modes: fiber and copper.
1247 * Both need to be suspended
1248 */
1249static int marvell_suspend(struct phy_device *phydev)
1250{
1251 int err;
1252
1253 /* Suspend the fiber mode first */
1254 if (!(phydev->supported & SUPPORTED_FIBRE)) {
1255 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1256 if (err < 0)
1257 goto error;
1258
1259 /* With the page set, use the generic suspend */
1260 err = genphy_suspend(phydev);
1261 if (err < 0)
1262 goto error;
1263
1264 /* Then, the copper link */
1265 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1266 if (err < 0)
1267 goto error;
1268 }
1269
1270 /* With the page set, use the generic suspend */
1271 return genphy_suspend(phydev);
1272
1273error:
1274 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1275 return err;
1276}
1277
1278/* marvell_resume
1279 *
1280 * Some Marvell's phys have two modes: fiber and copper.
1281 * Both need to be resumed
1282 */
1283static int marvell_resume(struct phy_device *phydev)
1284{
1285 int err;
1286
1287 /* Resume the fiber mode first */
1288 if (!(phydev->supported & SUPPORTED_FIBRE)) {
1289 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1290 if (err < 0)
1291 goto error;
1292
1293 /* With the page set, use the generic resume */
1294 err = genphy_resume(phydev);
1295 if (err < 0)
1296 goto error;
1297
1298 /* Then, the copper link */
1299 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1300 if (err < 0)
1301 goto error;
1302 }
1303
1304 /* With the page set, use the generic resume */
1305 return genphy_resume(phydev);
1306
1307error:
1308 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1309 return err;
1310}
1311
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001312static int marvell_aneg_done(struct phy_device *phydev)
1313{
1314 int retval = phy_read(phydev, MII_M1011_PHY_STATUS);
1315 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
1316}
1317
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001318static int m88e1121_did_interrupt(struct phy_device *phydev)
1319{
1320 int imask;
1321
1322 imask = phy_read(phydev, MII_M1011_IEVENT);
1323
1324 if (imask & MII_M1011_IMASK_INIT)
1325 return 1;
1326
1327 return 0;
1328}
1329
Michael Stapelberg3871c382013-03-11 13:56:45 +00001330static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1331{
1332 wol->supported = WAKE_MAGIC;
1333 wol->wolopts = 0;
1334
1335 if (phy_write(phydev, MII_MARVELL_PHY_PAGE,
1336 MII_88E1318S_PHY_WOL_PAGE) < 0)
1337 return;
1338
1339 if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) &
1340 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
1341 wol->wolopts |= WAKE_MAGIC;
1342
1343 if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0)
1344 return;
1345}
1346
1347static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1348{
1349 int err, oldpage, temp;
1350
1351 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1352
1353 if (wol->wolopts & WAKE_MAGIC) {
1354 /* Explicitly switch to page 0x00, just to be sure */
1355 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00);
1356 if (err < 0)
1357 return err;
1358
1359 /* Enable the WOL interrupt */
1360 temp = phy_read(phydev, MII_88E1318S_PHY_CSIER);
1361 temp |= MII_88E1318S_PHY_CSIER_WOL_EIE;
1362 err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp);
1363 if (err < 0)
1364 return err;
1365
1366 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1367 MII_88E1318S_PHY_LED_PAGE);
1368 if (err < 0)
1369 return err;
1370
1371 /* Setup LED[2] as interrupt pin (active low) */
1372 temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR);
1373 temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT;
1374 temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE;
1375 temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW;
1376 err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp);
1377 if (err < 0)
1378 return err;
1379
1380 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1381 MII_88E1318S_PHY_WOL_PAGE);
1382 if (err < 0)
1383 return err;
1384
1385 /* Store the device address for the magic packet */
1386 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
1387 ((phydev->attached_dev->dev_addr[5] << 8) |
1388 phydev->attached_dev->dev_addr[4]));
1389 if (err < 0)
1390 return err;
1391 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
1392 ((phydev->attached_dev->dev_addr[3] << 8) |
1393 phydev->attached_dev->dev_addr[2]));
1394 if (err < 0)
1395 return err;
1396 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
1397 ((phydev->attached_dev->dev_addr[1] << 8) |
1398 phydev->attached_dev->dev_addr[0]));
1399 if (err < 0)
1400 return err;
1401
1402 /* Clear WOL status and enable magic packet matching */
1403 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1404 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1405 temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1406 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1407 if (err < 0)
1408 return err;
1409 } else {
1410 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1411 MII_88E1318S_PHY_WOL_PAGE);
1412 if (err < 0)
1413 return err;
1414
1415 /* Clear WOL status and disable magic packet matching */
1416 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1417 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1418 temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1419 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1420 if (err < 0)
1421 return err;
1422 }
1423
1424 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1425 if (err < 0)
1426 return err;
1427
1428 return 0;
1429}
1430
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001431static int marvell_get_sset_count(struct phy_device *phydev)
1432{
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +02001433 if (phydev->supported & SUPPORTED_FIBRE)
1434 return ARRAY_SIZE(marvell_hw_stats);
1435 else
1436 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001437}
1438
1439static void marvell_get_strings(struct phy_device *phydev, u8 *data)
1440{
1441 int i;
1442
1443 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1444 memcpy(data + i * ETH_GSTRING_LEN,
1445 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1446 }
1447}
1448
1449#ifndef UINT64_MAX
1450#define UINT64_MAX (u64)(~((u64)0))
1451#endif
1452static u64 marvell_get_stat(struct phy_device *phydev, int i)
1453{
1454 struct marvell_hw_stat stat = marvell_hw_stats[i];
1455 struct marvell_priv *priv = phydev->priv;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001456 int err, oldpage, val;
1457 u64 ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001458
1459 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1460 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1461 stat.page);
1462 if (err < 0)
1463 return UINT64_MAX;
1464
1465 val = phy_read(phydev, stat.reg);
1466 if (val < 0) {
Andrew Lunn321b4d42016-02-20 00:35:29 +01001467 ret = UINT64_MAX;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001468 } else {
1469 val = val & ((1 << stat.bits) - 1);
1470 priv->stats[i] += val;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001471 ret = priv->stats[i];
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001472 }
1473
1474 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1475
Andrew Lunn321b4d42016-02-20 00:35:29 +01001476 return ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001477}
1478
1479static void marvell_get_stats(struct phy_device *phydev,
1480 struct ethtool_stats *stats, u64 *data)
1481{
1482 int i;
1483
1484 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
1485 data[i] = marvell_get_stat(phydev, i);
1486}
1487
Andrew Lunn0b046802017-01-20 01:37:49 +01001488#ifdef CONFIG_HWMON
1489static int m88e1121_get_temp(struct phy_device *phydev, long *temp)
1490{
1491 int ret;
1492 int val;
1493
1494 *temp = 0;
1495
1496 mutex_lock(&phydev->lock);
1497
1498 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1499 if (ret < 0)
1500 goto error;
1501
1502 /* Enable temperature sensor */
1503 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1504 if (ret < 0)
1505 goto error;
1506
1507 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1508 ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1509 if (ret < 0)
1510 goto error;
1511
1512 /* Wait for temperature to stabilize */
1513 usleep_range(10000, 12000);
1514
1515 val = phy_read(phydev, MII_88E1121_MISC_TEST);
1516 if (val < 0) {
1517 ret = val;
1518 goto error;
1519 }
1520
1521 /* Disable temperature sensor */
1522 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1523 ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
1524 if (ret < 0)
1525 goto error;
1526
1527 *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000;
1528
1529error:
1530 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1531 mutex_unlock(&phydev->lock);
1532
1533 return ret;
1534}
1535
1536static int m88e1121_hwmon_read(struct device *dev,
1537 enum hwmon_sensor_types type,
1538 u32 attr, int channel, long *temp)
1539{
1540 struct phy_device *phydev = dev_get_drvdata(dev);
1541 int err;
1542
1543 switch (attr) {
1544 case hwmon_temp_input:
1545 err = m88e1121_get_temp(phydev, temp);
1546 break;
1547 default:
1548 return -EOPNOTSUPP;
1549 }
1550
1551 return err;
1552}
1553
1554static umode_t m88e1121_hwmon_is_visible(const void *data,
1555 enum hwmon_sensor_types type,
1556 u32 attr, int channel)
1557{
1558 if (type != hwmon_temp)
1559 return 0;
1560
1561 switch (attr) {
1562 case hwmon_temp_input:
1563 return 0444;
1564 default:
1565 return 0;
1566 }
1567}
1568
1569static u32 m88e1121_hwmon_chip_config[] = {
1570 HWMON_C_REGISTER_TZ,
1571 0
1572};
1573
1574static const struct hwmon_channel_info m88e1121_hwmon_chip = {
1575 .type = hwmon_chip,
1576 .config = m88e1121_hwmon_chip_config,
1577};
1578
1579static u32 m88e1121_hwmon_temp_config[] = {
1580 HWMON_T_INPUT,
1581 0
1582};
1583
1584static const struct hwmon_channel_info m88e1121_hwmon_temp = {
1585 .type = hwmon_temp,
1586 .config = m88e1121_hwmon_temp_config,
1587};
1588
1589static const struct hwmon_channel_info *m88e1121_hwmon_info[] = {
1590 &m88e1121_hwmon_chip,
1591 &m88e1121_hwmon_temp,
1592 NULL
1593};
1594
1595static const struct hwmon_ops m88e1121_hwmon_hwmon_ops = {
1596 .is_visible = m88e1121_hwmon_is_visible,
1597 .read = m88e1121_hwmon_read,
1598};
1599
1600static const struct hwmon_chip_info m88e1121_hwmon_chip_info = {
1601 .ops = &m88e1121_hwmon_hwmon_ops,
1602 .info = m88e1121_hwmon_info,
1603};
1604
1605static int m88e1510_get_temp(struct phy_device *phydev, long *temp)
1606{
1607 int ret;
1608
1609 *temp = 0;
1610
1611 mutex_lock(&phydev->lock);
1612
1613 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1614 if (ret < 0)
1615 goto error;
1616
1617 ret = phy_read(phydev, MII_88E1510_TEMP_SENSOR);
1618 if (ret < 0)
1619 goto error;
1620
1621 *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000;
1622
1623error:
1624 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1625 mutex_unlock(&phydev->lock);
1626
1627 return ret;
1628}
1629
1630int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp)
1631{
1632 int ret;
1633
1634 *temp = 0;
1635
1636 mutex_lock(&phydev->lock);
1637
1638 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1639 if (ret < 0)
1640 goto error;
1641
1642 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1643 if (ret < 0)
1644 goto error;
1645
1646 *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >>
1647 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25;
1648 /* convert to mC */
1649 *temp *= 1000;
1650
1651error:
1652 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1653 mutex_unlock(&phydev->lock);
1654
1655 return ret;
1656}
1657
1658int m88e1510_set_temp_critical(struct phy_device *phydev, long temp)
1659{
1660 int ret;
1661
1662 mutex_lock(&phydev->lock);
1663
1664 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1665 if (ret < 0)
1666 goto error;
1667
1668 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1669 if (ret < 0)
1670 goto error;
1671
1672 temp = temp / 1000;
1673 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
1674 ret = phy_write(phydev, MII_88E1121_MISC_TEST,
1675 (ret & ~MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) |
1676 (temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT));
1677
1678error:
1679 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1680 mutex_unlock(&phydev->lock);
1681
1682 return ret;
1683}
1684
1685int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm)
1686{
1687 int ret;
1688
1689 *alarm = false;
1690
1691 mutex_lock(&phydev->lock);
1692
1693 ret = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x6);
1694 if (ret < 0)
1695 goto error;
1696
1697 ret = phy_read(phydev, MII_88E1121_MISC_TEST);
1698 if (ret < 0)
1699 goto error;
1700 *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ);
1701
1702error:
1703 phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, 0x0);
1704 mutex_unlock(&phydev->lock);
1705
1706 return ret;
1707}
1708
1709static int m88e1510_hwmon_read(struct device *dev,
1710 enum hwmon_sensor_types type,
1711 u32 attr, int channel, long *temp)
1712{
1713 struct phy_device *phydev = dev_get_drvdata(dev);
1714 int err;
1715
1716 switch (attr) {
1717 case hwmon_temp_input:
1718 err = m88e1510_get_temp(phydev, temp);
1719 break;
1720 case hwmon_temp_crit:
1721 err = m88e1510_get_temp_critical(phydev, temp);
1722 break;
1723 case hwmon_temp_max_alarm:
1724 err = m88e1510_get_temp_alarm(phydev, temp);
1725 break;
1726 default:
1727 return -EOPNOTSUPP;
1728 }
1729
1730 return err;
1731}
1732
1733static int m88e1510_hwmon_write(struct device *dev,
1734 enum hwmon_sensor_types type,
1735 u32 attr, int channel, long temp)
1736{
1737 struct phy_device *phydev = dev_get_drvdata(dev);
1738 int err;
1739
1740 switch (attr) {
1741 case hwmon_temp_crit:
1742 err = m88e1510_set_temp_critical(phydev, temp);
1743 break;
1744 default:
1745 return -EOPNOTSUPP;
1746 }
1747 return err;
1748}
1749
1750static umode_t m88e1510_hwmon_is_visible(const void *data,
1751 enum hwmon_sensor_types type,
1752 u32 attr, int channel)
1753{
1754 if (type != hwmon_temp)
1755 return 0;
1756
1757 switch (attr) {
1758 case hwmon_temp_input:
1759 case hwmon_temp_max_alarm:
1760 return 0444;
1761 case hwmon_temp_crit:
1762 return 0644;
1763 default:
1764 return 0;
1765 }
1766}
1767
1768static u32 m88e1510_hwmon_temp_config[] = {
1769 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM,
1770 0
1771};
1772
1773static const struct hwmon_channel_info m88e1510_hwmon_temp = {
1774 .type = hwmon_temp,
1775 .config = m88e1510_hwmon_temp_config,
1776};
1777
1778static const struct hwmon_channel_info *m88e1510_hwmon_info[] = {
1779 &m88e1121_hwmon_chip,
1780 &m88e1510_hwmon_temp,
1781 NULL
1782};
1783
1784static const struct hwmon_ops m88e1510_hwmon_hwmon_ops = {
1785 .is_visible = m88e1510_hwmon_is_visible,
1786 .read = m88e1510_hwmon_read,
1787 .write = m88e1510_hwmon_write,
1788};
1789
1790static const struct hwmon_chip_info m88e1510_hwmon_chip_info = {
1791 .ops = &m88e1510_hwmon_hwmon_ops,
1792 .info = m88e1510_hwmon_info,
1793};
1794
1795static int marvell_hwmon_name(struct phy_device *phydev)
1796{
1797 struct marvell_priv *priv = phydev->priv;
1798 struct device *dev = &phydev->mdio.dev;
1799 const char *devname = dev_name(dev);
1800 size_t len = strlen(devname);
1801 int i, j;
1802
1803 priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL);
1804 if (!priv->hwmon_name)
1805 return -ENOMEM;
1806
1807 for (i = j = 0; i < len && devname[i]; i++) {
1808 if (isalnum(devname[i]))
1809 priv->hwmon_name[j++] = devname[i];
1810 }
1811
1812 return 0;
1813}
1814
1815static int marvell_hwmon_probe(struct phy_device *phydev,
1816 const struct hwmon_chip_info *chip)
1817{
1818 struct marvell_priv *priv = phydev->priv;
1819 struct device *dev = &phydev->mdio.dev;
1820 int err;
1821
1822 err = marvell_hwmon_name(phydev);
1823 if (err)
1824 return err;
1825
1826 priv->hwmon_dev = devm_hwmon_device_register_with_info(
1827 dev, priv->hwmon_name, phydev, chip, NULL);
1828
1829 return PTR_ERR_OR_ZERO(priv->hwmon_dev);
1830}
1831
1832static int m88e1121_hwmon_probe(struct phy_device *phydev)
1833{
1834 return marvell_hwmon_probe(phydev, &m88e1121_hwmon_chip_info);
1835}
1836
1837static int m88e1510_hwmon_probe(struct phy_device *phydev)
1838{
1839 return marvell_hwmon_probe(phydev, &m88e1510_hwmon_chip_info);
1840}
1841#else
1842static int m88e1121_hwmon_probe(struct phy_device *phydev)
1843{
1844 return 0;
1845}
1846
1847static int m88e1510_hwmon_probe(struct phy_device *phydev)
1848{
1849 return 0;
1850}
1851#endif
1852
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001853static int marvell_probe(struct phy_device *phydev)
1854{
1855 struct marvell_priv *priv;
1856
Andrew Lunne5a03bf2016-01-06 20:11:16 +01001857 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001858 if (!priv)
1859 return -ENOMEM;
1860
1861 phydev->priv = priv;
1862
1863 return 0;
1864}
1865
Andrew Lunn0b046802017-01-20 01:37:49 +01001866static int m88e1121_probe(struct phy_device *phydev)
1867{
1868 int err;
1869
1870 err = marvell_probe(phydev);
1871 if (err)
1872 return err;
1873
1874 return m88e1121_hwmon_probe(phydev);
1875}
1876
1877static int m88e1510_probe(struct phy_device *phydev)
1878{
1879 int err;
1880
1881 err = marvell_probe(phydev);
1882 if (err)
1883 return err;
1884
1885 return m88e1510_hwmon_probe(phydev);
1886}
1887
Olof Johanssone5479232007-07-03 16:23:46 -05001888static struct phy_driver marvell_drivers[] = {
1889 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001890 .phy_id = MARVELL_PHY_ID_88E1101,
1891 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001892 .name = "Marvell 88E1101",
1893 .features = PHY_GBIT_FEATURES,
1894 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01001895 .probe = marvell_probe,
Clemens Gruber79be1a12016-02-15 23:46:45 +01001896 .config_init = &marvell_config_init,
Olof Johanssone5479232007-07-03 16:23:46 -05001897 .config_aneg = &marvell_config_aneg,
1898 .read_status = &genphy_read_status,
1899 .ack_interrupt = &marvell_ack_interrupt,
1900 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001901 .resume = &genphy_resume,
1902 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001903 .get_sset_count = marvell_get_sset_count,
1904 .get_strings = marvell_get_strings,
1905 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001906 },
1907 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001908 .phy_id = MARVELL_PHY_ID_88E1112,
1909 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johansson85cfb532007-07-03 16:24:32 -05001910 .name = "Marvell 88E1112",
1911 .features = PHY_GBIT_FEATURES,
1912 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001913 .probe = marvell_probe,
Olof Johansson85cfb532007-07-03 16:24:32 -05001914 .config_init = &m88e1111_config_init,
1915 .config_aneg = &marvell_config_aneg,
1916 .read_status = &genphy_read_status,
1917 .ack_interrupt = &marvell_ack_interrupt,
1918 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001919 .resume = &genphy_resume,
1920 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001921 .get_sset_count = marvell_get_sset_count,
1922 .get_strings = marvell_get_strings,
1923 .get_stats = marvell_get_stats,
Olof Johansson85cfb532007-07-03 16:24:32 -05001924 },
1925 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001926 .phy_id = MARVELL_PHY_ID_88E1111,
1927 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001928 .name = "Marvell 88E1111",
1929 .features = PHY_GBIT_FEATURES,
1930 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001931 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001932 .config_init = &m88e1111_config_init,
Harini Katakam3ec0a0f2016-06-27 13:09:59 +05301933 .config_aneg = &m88e1111_config_aneg,
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001934 .read_status = &marvell_read_status,
Olof Johanssone5479232007-07-03 16:23:46 -05001935 .ack_interrupt = &marvell_ack_interrupt,
1936 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001937 .resume = &genphy_resume,
1938 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001939 .get_sset_count = marvell_get_sset_count,
1940 .get_strings = marvell_get_strings,
1941 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001942 },
1943 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001944 .phy_id = MARVELL_PHY_ID_88E1118,
1945 .phy_id_mask = MARVELL_PHY_ID_MASK,
Ron Madrid605f1962008-11-06 09:05:26 +00001946 .name = "Marvell 88E1118",
1947 .features = PHY_GBIT_FEATURES,
1948 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001949 .probe = marvell_probe,
Ron Madrid605f1962008-11-06 09:05:26 +00001950 .config_init = &m88e1118_config_init,
1951 .config_aneg = &m88e1118_config_aneg,
1952 .read_status = &genphy_read_status,
1953 .ack_interrupt = &marvell_ack_interrupt,
1954 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001955 .resume = &genphy_resume,
1956 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001957 .get_sset_count = marvell_get_sset_count,
1958 .get_strings = marvell_get_strings,
1959 .get_stats = marvell_get_stats,
Ron Madrid605f1962008-11-06 09:05:26 +00001960 },
1961 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001962 .phy_id = MARVELL_PHY_ID_88E1121R,
1963 .phy_id_mask = MARVELL_PHY_ID_MASK,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001964 .name = "Marvell 88E1121R",
1965 .features = PHY_GBIT_FEATURES,
1966 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01001967 .probe = &m88e1121_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001968 .config_init = &m88e1121_config_init,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001969 .config_aneg = &m88e1121_config_aneg,
1970 .read_status = &marvell_read_status,
1971 .ack_interrupt = &marvell_ack_interrupt,
1972 .config_intr = &marvell_config_intr,
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001973 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001974 .resume = &genphy_resume,
1975 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001976 .get_sset_count = marvell_get_sset_count,
1977 .get_strings = marvell_get_strings,
1978 .get_stats = marvell_get_stats,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001979 },
1980 {
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001981 .phy_id = MARVELL_PHY_ID_88E1318S,
Linus Torvalds6ba74012010-08-04 11:47:58 -07001982 .phy_id_mask = MARVELL_PHY_ID_MASK,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001983 .name = "Marvell 88E1318S",
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001984 .features = PHY_GBIT_FEATURES,
1985 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001986 .probe = marvell_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001987 .config_init = &m88e1121_config_init,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001988 .config_aneg = &m88e1318_config_aneg,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001989 .read_status = &marvell_read_status,
1990 .ack_interrupt = &marvell_ack_interrupt,
1991 .config_intr = &marvell_config_intr,
1992 .did_interrupt = &m88e1121_did_interrupt,
Michael Stapelberg3871c382013-03-11 13:56:45 +00001993 .get_wol = &m88e1318_get_wol,
1994 .set_wol = &m88e1318_set_wol,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001995 .resume = &genphy_resume,
1996 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001997 .get_sset_count = marvell_get_sset_count,
1998 .get_strings = marvell_get_strings,
1999 .get_stats = marvell_get_stats,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07002000 },
2001 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002002 .phy_id = MARVELL_PHY_ID_88E1145,
2003 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05002004 .name = "Marvell 88E1145",
2005 .features = PHY_GBIT_FEATURES,
2006 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002007 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05002008 .config_init = &m88e1145_config_init,
2009 .config_aneg = &marvell_config_aneg,
2010 .read_status = &genphy_read_status,
2011 .ack_interrupt = &marvell_ack_interrupt,
2012 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002013 .resume = &genphy_resume,
2014 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002015 .get_sset_count = marvell_get_sset_count,
2016 .get_strings = marvell_get_strings,
2017 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002018 },
2019 {
David Daney90600732010-11-19 11:58:53 +00002020 .phy_id = MARVELL_PHY_ID_88E1149R,
2021 .phy_id_mask = MARVELL_PHY_ID_MASK,
2022 .name = "Marvell 88E1149R",
2023 .features = PHY_GBIT_FEATURES,
2024 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002025 .probe = marvell_probe,
David Daney90600732010-11-19 11:58:53 +00002026 .config_init = &m88e1149_config_init,
2027 .config_aneg = &m88e1118_config_aneg,
2028 .read_status = &genphy_read_status,
2029 .ack_interrupt = &marvell_ack_interrupt,
2030 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002031 .resume = &genphy_resume,
2032 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002033 .get_sset_count = marvell_get_sset_count,
2034 .get_strings = marvell_get_strings,
2035 .get_stats = marvell_get_stats,
David Daney90600732010-11-19 11:58:53 +00002036 },
2037 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10002038 .phy_id = MARVELL_PHY_ID_88E1240,
2039 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002040 .name = "Marvell 88E1240",
2041 .features = PHY_GBIT_FEATURES,
2042 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002043 .probe = marvell_probe,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002044 .config_init = &m88e1111_config_init,
2045 .config_aneg = &marvell_config_aneg,
2046 .read_status = &genphy_read_status,
2047 .ack_interrupt = &marvell_ack_interrupt,
2048 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002049 .resume = &genphy_resume,
2050 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002051 .get_sset_count = marvell_get_sset_count,
2052 .get_strings = marvell_get_strings,
2053 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06002054 },
Michal Simek3da09a52013-05-30 20:08:26 +00002055 {
2056 .phy_id = MARVELL_PHY_ID_88E1116R,
2057 .phy_id_mask = MARVELL_PHY_ID_MASK,
2058 .name = "Marvell 88E1116R",
2059 .features = PHY_GBIT_FEATURES,
2060 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002061 .probe = marvell_probe,
Michal Simek3da09a52013-05-30 20:08:26 +00002062 .config_init = &m88e1116r_config_init,
2063 .config_aneg = &genphy_config_aneg,
2064 .read_status = &genphy_read_status,
2065 .ack_interrupt = &marvell_ack_interrupt,
2066 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01002067 .resume = &genphy_resume,
2068 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002069 .get_sset_count = marvell_get_sset_count,
2070 .get_strings = marvell_get_strings,
2071 .get_stats = marvell_get_stats,
Michal Simek3da09a52013-05-30 20:08:26 +00002072 },
Michal Simek10e24caa2013-05-30 20:08:27 +00002073 {
2074 .phy_id = MARVELL_PHY_ID_88E1510,
2075 .phy_id_mask = MARVELL_PHY_ID_MASK,
2076 .name = "Marvell 88E1510",
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02002077 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE,
Arnd Bergmann18702412017-01-23 13:18:41 +01002078 .flags = PHY_HAS_INTERRUPT,
Andrew Lunn0b046802017-01-20 01:37:49 +01002079 .probe = &m88e1510_probe,
Stefan Roese930b37e2016-02-18 10:59:07 +01002080 .config_init = &m88e1510_config_init,
Michal Simek10e24caa2013-05-30 20:08:27 +00002081 .config_aneg = &m88e1510_config_aneg,
2082 .read_status = &marvell_read_status,
2083 .ack_interrupt = &marvell_ack_interrupt,
2084 .config_intr = &marvell_config_intr,
2085 .did_interrupt = &m88e1121_did_interrupt,
Jingju Houf39aac72017-01-22 18:20:56 +08002086 .get_wol = &m88e1318_get_wol,
2087 .set_wol = &m88e1318_set_wol,
Charles-Antoine Couret3758be32016-07-19 11:13:13 +02002088 .resume = &marvell_resume,
2089 .suspend = &marvell_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002090 .get_sset_count = marvell_get_sset_count,
2091 .get_strings = marvell_get_strings,
2092 .get_stats = marvell_get_stats,
Michal Simek10e24caa2013-05-30 20:08:27 +00002093 },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002094 {
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002095 .phy_id = MARVELL_PHY_ID_88E1540,
2096 .phy_id_mask = MARVELL_PHY_ID_MASK,
2097 .name = "Marvell 88E1540",
2098 .features = PHY_GBIT_FEATURES,
2099 .flags = PHY_HAS_INTERRUPT,
Arnd Bergmann18702412017-01-23 13:18:41 +01002100 .probe = m88e1510_probe,
Clemens Gruber79be1a12016-02-15 23:46:45 +01002101 .config_init = &marvell_config_init,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002102 .config_aneg = &m88e1510_config_aneg,
2103 .read_status = &marvell_read_status,
2104 .ack_interrupt = &marvell_ack_interrupt,
2105 .config_intr = &marvell_config_intr,
2106 .did_interrupt = &m88e1121_did_interrupt,
2107 .resume = &genphy_resume,
2108 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002109 .get_sset_count = marvell_get_sset_count,
2110 .get_strings = marvell_get_strings,
2111 .get_stats = marvell_get_stats,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002112 },
2113 {
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002114 .phy_id = MARVELL_PHY_ID_88E1545,
2115 .phy_id_mask = MARVELL_PHY_ID_MASK,
2116 .name = "Marvell 88E1545",
2117 .probe = m88e1510_probe,
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002118 .features = PHY_GBIT_FEATURES,
2119 .flags = PHY_HAS_INTERRUPT,
2120 .config_init = &marvell_config_init,
2121 .config_aneg = &m88e1510_config_aneg,
2122 .read_status = &marvell_read_status,
2123 .ack_interrupt = &marvell_ack_interrupt,
2124 .config_intr = &marvell_config_intr,
2125 .did_interrupt = &m88e1121_did_interrupt,
2126 .resume = &genphy_resume,
2127 .suspend = &genphy_suspend,
2128 .get_sset_count = marvell_get_sset_count,
2129 .get_strings = marvell_get_strings,
2130 .get_stats = marvell_get_stats,
2131 },
2132 {
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002133 .phy_id = MARVELL_PHY_ID_88E3016,
2134 .phy_id_mask = MARVELL_PHY_ID_MASK,
2135 .name = "Marvell 88E3016",
2136 .features = PHY_BASIC_FEATURES,
2137 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002138 .probe = marvell_probe,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002139 .config_aneg = &genphy_config_aneg,
2140 .config_init = &m88e3016_config_init,
2141 .aneg_done = &marvell_aneg_done,
2142 .read_status = &marvell_read_status,
2143 .ack_interrupt = &marvell_ack_interrupt,
2144 .config_intr = &marvell_config_intr,
2145 .did_interrupt = &m88e1121_did_interrupt,
2146 .resume = &genphy_resume,
2147 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01002148 .get_sset_count = marvell_get_sset_count,
2149 .get_strings = marvell_get_strings,
2150 .get_stats = marvell_get_stats,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002151 },
Andrew Lunne4cf8a32017-02-01 03:40:06 +01002152 {
2153 .phy_id = MARVELL_PHY_ID_88E6390,
2154 .phy_id_mask = MARVELL_PHY_ID_MASK,
2155 .name = "Marvell 88E6390",
2156 .features = PHY_GBIT_FEATURES,
2157 .flags = PHY_HAS_INTERRUPT,
2158 .probe = m88e1510_probe,
2159 .config_init = &marvell_config_init,
2160 .config_aneg = &m88e1510_config_aneg,
2161 .read_status = &marvell_read_status,
2162 .ack_interrupt = &marvell_ack_interrupt,
2163 .config_intr = &marvell_config_intr,
2164 .did_interrupt = &m88e1121_did_interrupt,
2165 .resume = &genphy_resume,
2166 .suspend = &genphy_suspend,
2167 .get_sset_count = marvell_get_sset_count,
2168 .get_strings = marvell_get_strings,
2169 .get_stats = marvell_get_stats,
2170 },
Andy Fleming00db8182005-07-30 19:31:23 -04002171};
2172
Johan Hovold50fd7152014-11-11 19:45:59 +01002173module_phy_driver(marvell_drivers);
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002174
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +00002175static struct mdio_device_id __maybe_unused marvell_tbl[] = {
Michal Simekf5e1cab2013-05-30 20:08:25 +00002176 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
2177 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
2178 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
2179 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
2180 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
2181 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
2182 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
2183 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
2184 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
Michal Simek3da09a52013-05-30 20:08:26 +00002185 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
Michal Simek10e24caa2013-05-30 20:08:27 +00002186 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
Andrew Lunn819ec8e2015-11-16 23:34:41 +01002187 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK },
Andrew Lunn60f06fd2017-02-02 00:35:03 +01002188 { MARVELL_PHY_ID_88E1545, MARVELL_PHY_ID_MASK },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02002189 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK },
Andrew Lunne4cf8a32017-02-01 03:40:06 +01002190 { MARVELL_PHY_ID_88E6390, MARVELL_PHY_ID_MASK },
David Woodhouse4e4f10f2010-04-02 01:05:56 +00002191 { }
2192};
2193
2194MODULE_DEVICE_TABLE(mdio, marvell_tbl);