blob: 225c033b08f3fbc4217fc238ec7048b611b8d87b [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>
20#include <linux/errno.h>
21#include <linux/unistd.h>
Andy Fleming00db8182005-07-30 19:31:23 -040022#include <linux/interrupt.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/skbuff.h>
28#include <linux/spinlock.h>
29#include <linux/mm.h>
30#include <linux/module.h>
Andy Fleming00db8182005-07-30 19:31:23 -040031#include <linux/mii.h>
32#include <linux/ethtool.h>
33#include <linux/phy.h>
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +100034#include <linux/marvell_phy.h>
David Daneycf41a512010-11-19 12:13:18 +000035#include <linux/of.h>
Andy Fleming00db8182005-07-30 19:31:23 -040036
Avinash Kumareea3b202013-09-30 09:36:44 +053037#include <linux/io.h>
Andy Fleming00db8182005-07-30 19:31:23 -040038#include <asm/irq.h>
Avinash Kumareea3b202013-09-30 09:36:44 +053039#include <linux/uaccess.h>
Andy Fleming00db8182005-07-30 19:31:23 -040040
David Daney27d916d2010-11-19 11:58:52 +000041#define MII_MARVELL_PHY_PAGE 22
42
Andy Fleming00db8182005-07-30 19:31:23 -040043#define MII_M1011_IEVENT 0x13
44#define MII_M1011_IEVENT_CLEAR 0x0000
45
46#define MII_M1011_IMASK 0x12
47#define MII_M1011_IMASK_INIT 0x6400
48#define MII_M1011_IMASK_CLEAR 0x0000
49
Andy Fleming76884672007-02-09 18:13:58 -060050#define MII_M1011_PHY_SCR 0x10
51#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
52
Vince Bridgers99d881f2014-10-26 14:22:24 -050053#define MII_M1145_PHY_EXT_SR 0x1b
Andy Fleming76884672007-02-09 18:13:58 -060054#define MII_M1145_PHY_EXT_CR 0x14
55#define MII_M1145_RGMII_RX_DELAY 0x0080
56#define MII_M1145_RGMII_TX_DELAY 0x0002
57
Vince Bridgers99d881f2014-10-26 14:22:24 -050058#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
59#define MII_M1145_HWCFG_MODE_MASK 0xf
60#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
61
Andy Fleming76884672007-02-09 18:13:58 -060062#define MII_M1111_PHY_LED_CONTROL 0x18
63#define MII_M1111_PHY_LED_DIRECT 0x4100
64#define MII_M1111_PHY_LED_COMBINE 0x411c
Kim Phillips895ee682007-06-05 18:46:47 +080065#define MII_M1111_PHY_EXT_CR 0x14
66#define MII_M1111_RX_DELAY 0x80
67#define MII_M1111_TX_DELAY 0x2
68#define MII_M1111_PHY_EXT_SR 0x1b
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030069
70#define MII_M1111_HWCFG_MODE_MASK 0xf
71#define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
72#define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
Kapil Juneja4117b5b2007-05-11 18:25:18 -050073#define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +000074#define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030075#define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000
76#define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000
77
78#define MII_M1111_COPPER 0
79#define MII_M1111_FIBER 1
80
Cyril Chemparathyc477d042010-08-02 09:44:53 +000081#define MII_88E1121_PHY_MSCR_PAGE 2
82#define MII_88E1121_PHY_MSCR_REG 21
83#define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
84#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
85#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
86
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -070087#define MII_88E1318S_PHY_MSCR1_REG 16
88#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -070089
Michael Stapelberg3871c382013-03-11 13:56:45 +000090/* Copper Specific Interrupt Enable Register */
91#define MII_88E1318S_PHY_CSIER 0x12
92/* WOL Event Interrupt Enable */
93#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
94
95/* LED Timer Control Register */
96#define MII_88E1318S_PHY_LED_PAGE 0x03
97#define MII_88E1318S_PHY_LED_TCR 0x12
98#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
99#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
100#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
101
102/* Magic Packet MAC address registers */
103#define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
104#define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
105#define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
106
107#define MII_88E1318S_PHY_WOL_PAGE 0x11
108#define MII_88E1318S_PHY_WOL_CTRL 0x10
109#define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
110#define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
111
Sergei Poselenov140bc922009-04-07 02:01:41 +0000112#define MII_88E1121_PHY_LED_CTRL 16
113#define MII_88E1121_PHY_LED_PAGE 3
114#define MII_88E1121_PHY_LED_DEF 0x0030
Sergei Poselenov140bc922009-04-07 02:01:41 +0000115
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300116#define MII_M1011_PHY_STATUS 0x11
117#define MII_M1011_PHY_STATUS_1000 0x8000
118#define MII_M1011_PHY_STATUS_100 0x4000
119#define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
120#define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
121#define MII_M1011_PHY_STATUS_RESOLVED 0x0800
122#define MII_M1011_PHY_STATUS_LINK 0x0400
123
Michal Simek3da09a52013-05-30 20:08:26 +0000124#define MII_M1116R_CONTROL_REG_MAC 21
125
Andy Fleming76884672007-02-09 18:13:58 -0600126
Andy Fleming00db8182005-07-30 19:31:23 -0400127MODULE_DESCRIPTION("Marvell PHY driver");
128MODULE_AUTHOR("Andy Fleming");
129MODULE_LICENSE("GPL");
130
131static int marvell_ack_interrupt(struct phy_device *phydev)
132{
133 int err;
134
135 /* Clear the interrupts by reading the reg */
136 err = phy_read(phydev, MII_M1011_IEVENT);
137
138 if (err < 0)
139 return err;
140
141 return 0;
142}
143
144static int marvell_config_intr(struct phy_device *phydev)
145{
146 int err;
147
Andy Fleming76884672007-02-09 18:13:58 -0600148 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
Andy Fleming00db8182005-07-30 19:31:23 -0400149 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
150 else
151 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
152
153 return err;
154}
155
156static int marvell_config_aneg(struct phy_device *phydev)
157{
158 int err;
159
160 /* The Marvell PHY has an errata which requires
161 * that certain registers get written in order
162 * to restart autonegotiation */
163 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
164
165 if (err < 0)
166 return err;
167
168 err = phy_write(phydev, 0x1d, 0x1f);
169 if (err < 0)
170 return err;
171
172 err = phy_write(phydev, 0x1e, 0x200c);
173 if (err < 0)
174 return err;
175
176 err = phy_write(phydev, 0x1d, 0x5);
177 if (err < 0)
178 return err;
179
180 err = phy_write(phydev, 0x1e, 0);
181 if (err < 0)
182 return err;
183
184 err = phy_write(phydev, 0x1e, 0x100);
185 if (err < 0)
186 return err;
187
Andy Fleming76884672007-02-09 18:13:58 -0600188 err = phy_write(phydev, MII_M1011_PHY_SCR,
189 MII_M1011_PHY_SCR_AUTO_CROSS);
190 if (err < 0)
191 return err;
192
193 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
194 MII_M1111_PHY_LED_DIRECT);
195 if (err < 0)
196 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400197
198 err = genphy_config_aneg(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000199 if (err < 0)
200 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400201
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000202 if (phydev->autoneg != AUTONEG_ENABLE) {
203 int bmcr;
204
205 /*
206 * A write to speed/duplex bits (that is performed by
207 * genphy_config_aneg() call above) must be followed by
208 * a software reset. Otherwise, the write has no effect.
209 */
210 bmcr = phy_read(phydev, MII_BMCR);
211 if (bmcr < 0)
212 return bmcr;
213
214 err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
215 if (err < 0)
216 return err;
217 }
218
219 return 0;
Andy Fleming00db8182005-07-30 19:31:23 -0400220}
221
David Daneycf41a512010-11-19 12:13:18 +0000222#ifdef CONFIG_OF_MDIO
223/*
224 * Set and/or override some configuration registers based on the
225 * marvell,reg-init property stored in the of_node for the phydev.
226 *
227 * marvell,reg-init = <reg-page reg mask value>,...;
228 *
229 * There may be one or more sets of <reg-page reg mask value>:
230 *
231 * reg-page: which register bank to use.
232 * reg: the register.
233 * mask: if non-zero, ANDed with existing register value.
234 * value: ORed with the masked value and written to the regiser.
235 *
236 */
237static int marvell_of_reg_init(struct phy_device *phydev)
238{
239 const __be32 *paddr;
240 int len, i, saved_page, current_page, page_changed, ret;
241
242 if (!phydev->dev.of_node)
243 return 0;
244
245 paddr = of_get_property(phydev->dev.of_node, "marvell,reg-init", &len);
246 if (!paddr || len < (4 * sizeof(*paddr)))
247 return 0;
248
249 saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE);
250 if (saved_page < 0)
251 return saved_page;
252 page_changed = 0;
253 current_page = saved_page;
254
255 ret = 0;
256 len /= sizeof(*paddr);
257 for (i = 0; i < len - 3; i += 4) {
258 u16 reg_page = be32_to_cpup(paddr + i);
259 u16 reg = be32_to_cpup(paddr + i + 1);
260 u16 mask = be32_to_cpup(paddr + i + 2);
261 u16 val_bits = be32_to_cpup(paddr + i + 3);
262 int val;
263
264 if (reg_page != current_page) {
265 current_page = reg_page;
266 page_changed = 1;
267 ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page);
268 if (ret < 0)
269 goto err;
270 }
271
272 val = 0;
273 if (mask) {
274 val = phy_read(phydev, reg);
275 if (val < 0) {
276 ret = val;
277 goto err;
278 }
279 val &= mask;
280 }
281 val |= val_bits;
282
283 ret = phy_write(phydev, reg, val);
284 if (ret < 0)
285 goto err;
286
287 }
288err:
289 if (page_changed) {
290 i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page);
291 if (ret == 0)
292 ret = i;
293 }
294 return ret;
295}
296#else
297static int marvell_of_reg_init(struct phy_device *phydev)
298{
299 return 0;
300}
301#endif /* CONFIG_OF_MDIO */
302
Sergei Poselenov140bc922009-04-07 02:01:41 +0000303static int m88e1121_config_aneg(struct phy_device *phydev)
304{
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000305 int err, oldpage, mscr;
306
David Daney27d916d2010-11-19 11:58:52 +0000307 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000308
David Daney27d916d2010-11-19 11:58:52 +0000309 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000310 MII_88E1121_PHY_MSCR_PAGE);
311 if (err < 0)
312 return err;
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000313
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700314 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
315 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
316 (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
317 (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000318
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700319 mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
320 MII_88E1121_PHY_MSCR_DELAY_MASK;
321
322 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
323 mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
324 MII_88E1121_PHY_MSCR_TX_DELAY);
325 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
326 mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
327 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
328 mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
329
330 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
331 if (err < 0)
332 return err;
333 }
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000334
David Daney27d916d2010-11-19 11:58:52 +0000335 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000336
337 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
338 if (err < 0)
339 return err;
340
341 err = phy_write(phydev, MII_M1011_PHY_SCR,
342 MII_M1011_PHY_SCR_AUTO_CROSS);
343 if (err < 0)
344 return err;
345
David Daney27d916d2010-11-19 11:58:52 +0000346 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000347
David Daney27d916d2010-11-19 11:58:52 +0000348 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000349 phy_write(phydev, MII_88E1121_PHY_LED_CTRL, MII_88E1121_PHY_LED_DEF);
David Daney27d916d2010-11-19 11:58:52 +0000350 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000351
352 err = genphy_config_aneg(phydev);
353
354 return err;
355}
356
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700357static int m88e1318_config_aneg(struct phy_device *phydev)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700358{
359 int err, oldpage, mscr;
360
David Daney27d916d2010-11-19 11:58:52 +0000361 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700362
David Daney27d916d2010-11-19 11:58:52 +0000363 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700364 MII_88E1121_PHY_MSCR_PAGE);
365 if (err < 0)
366 return err;
367
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700368 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
369 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700370
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700371 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700372 if (err < 0)
373 return err;
374
David Daney27d916d2010-11-19 11:58:52 +0000375 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700376 if (err < 0)
377 return err;
378
379 return m88e1121_config_aneg(phydev);
380}
381
Michal Simek10e24caa2013-05-30 20:08:27 +0000382static int m88e1510_config_aneg(struct phy_device *phydev)
383{
384 int err;
385
386 err = m88e1318_config_aneg(phydev);
387 if (err < 0)
388 return err;
389
390 return marvell_of_reg_init(phydev);
391}
392
Michal Simek3da09a52013-05-30 20:08:26 +0000393static int m88e1116r_config_init(struct phy_device *phydev)
394{
395 int temp;
396 int err;
397
398 temp = phy_read(phydev, MII_BMCR);
399 temp |= BMCR_RESET;
400 err = phy_write(phydev, MII_BMCR, temp);
401 if (err < 0)
402 return err;
403
404 mdelay(500);
405
406 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
407 if (err < 0)
408 return err;
409
410 temp = phy_read(phydev, MII_M1011_PHY_SCR);
411 temp |= (7 << 12); /* max number of gigabit attempts */
412 temp |= (1 << 11); /* enable downshift */
413 temp |= MII_M1011_PHY_SCR_AUTO_CROSS;
414 err = phy_write(phydev, MII_M1011_PHY_SCR, temp);
415 if (err < 0)
416 return err;
417
418 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2);
419 if (err < 0)
420 return err;
421 temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC);
422 temp |= (1 << 5);
423 temp |= (1 << 4);
424 err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp);
425 if (err < 0)
426 return err;
427 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
428 if (err < 0)
429 return err;
430
431 temp = phy_read(phydev, MII_BMCR);
432 temp |= BMCR_RESET;
433 err = phy_write(phydev, MII_BMCR, temp);
434 if (err < 0)
435 return err;
436
437 mdelay(500);
438
439 return 0;
440}
441
Kim Phillips895ee682007-06-05 18:46:47 +0800442static int m88e1111_config_init(struct phy_device *phydev)
443{
444 int err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300445 int temp;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300446
Kim Phillips895ee682007-06-05 18:46:47 +0800447 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
Kim Phillips9daf5a72007-11-26 16:17:52 -0600448 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
449 (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
450 (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
Kim Phillips895ee682007-06-05 18:46:47 +0800451
Kim Phillips9daf5a72007-11-26 16:17:52 -0600452 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
453 if (temp < 0)
454 return temp;
455
Kim Phillips895ee682007-06-05 18:46:47 +0800456 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Kim Phillips895ee682007-06-05 18:46:47 +0800457 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
Kim Phillips9daf5a72007-11-26 16:17:52 -0600458 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
459 temp &= ~MII_M1111_TX_DELAY;
460 temp |= MII_M1111_RX_DELAY;
461 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
462 temp &= ~MII_M1111_RX_DELAY;
463 temp |= MII_M1111_TX_DELAY;
Kim Phillips895ee682007-06-05 18:46:47 +0800464 }
465
Kim Phillips9daf5a72007-11-26 16:17:52 -0600466 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
467 if (err < 0)
468 return err;
469
Kim Phillips895ee682007-06-05 18:46:47 +0800470 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
471 if (temp < 0)
472 return temp;
473
474 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300475
Wang Jian7239016d2008-07-16 21:46:20 +0800476 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300477 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
478 else
479 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
Kim Phillips895ee682007-06-05 18:46:47 +0800480
481 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
482 if (err < 0)
483 return err;
484 }
485
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500486 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500487 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
488 if (temp < 0)
489 return temp;
490
491 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
492 temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK;
Haiying Wang32d0c1e2009-06-02 04:04:13 +0000493 temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500494
495 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
496 if (err < 0)
497 return err;
498 }
499
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000500 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
501 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
502 if (temp < 0)
503 return temp;
504 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
505 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
506 if (err < 0)
507 return err;
508
509 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
510 if (temp < 0)
511 return temp;
512 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
513 temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
514 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
515 if (err < 0)
516 return err;
517
518 /* soft reset */
519 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
520 if (err < 0)
521 return err;
522 do
523 temp = phy_read(phydev, MII_BMCR);
524 while (temp & BMCR_RESET);
525
526 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
527 if (temp < 0)
528 return temp;
529 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
530 temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
531 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
532 if (err < 0)
533 return err;
534 }
535
David Daneycf41a512010-11-19 12:13:18 +0000536 err = marvell_of_reg_init(phydev);
537 if (err < 0)
538 return err;
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000539
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000540 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Kim Phillips895ee682007-06-05 18:46:47 +0800541}
542
Ron Madrid605f1962008-11-06 09:05:26 +0000543static int m88e1118_config_aneg(struct phy_device *phydev)
544{
545 int err;
546
547 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
548 if (err < 0)
549 return err;
550
551 err = phy_write(phydev, MII_M1011_PHY_SCR,
552 MII_M1011_PHY_SCR_AUTO_CROSS);
553 if (err < 0)
554 return err;
555
556 err = genphy_config_aneg(phydev);
557 return 0;
558}
559
560static int m88e1118_config_init(struct phy_device *phydev)
561{
562 int err;
563
564 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000565 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
Ron Madrid605f1962008-11-06 09:05:26 +0000566 if (err < 0)
567 return err;
568
569 /* Enable 1000 Mbit */
570 err = phy_write(phydev, 0x15, 0x1070);
571 if (err < 0)
572 return err;
573
574 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000575 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003);
Ron Madrid605f1962008-11-06 09:05:26 +0000576 if (err < 0)
577 return err;
578
579 /* Adjust LED Control */
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000580 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
581 err = phy_write(phydev, 0x10, 0x1100);
582 else
583 err = phy_write(phydev, 0x10, 0x021e);
Ron Madrid605f1962008-11-06 09:05:26 +0000584 if (err < 0)
585 return err;
586
David Daneycf41a512010-11-19 12:13:18 +0000587 err = marvell_of_reg_init(phydev);
588 if (err < 0)
589 return err;
590
Ron Madrid605f1962008-11-06 09:05:26 +0000591 /* Reset address */
David Daney27d916d2010-11-19 11:58:52 +0000592 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
Ron Madrid605f1962008-11-06 09:05:26 +0000593 if (err < 0)
594 return err;
595
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000596 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Ron Madrid605f1962008-11-06 09:05:26 +0000597}
598
David Daney90600732010-11-19 11:58:53 +0000599static int m88e1149_config_init(struct phy_device *phydev)
600{
601 int err;
602
603 /* Change address */
604 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
605 if (err < 0)
606 return err;
607
608 /* Enable 1000 Mbit */
609 err = phy_write(phydev, 0x15, 0x1048);
610 if (err < 0)
611 return err;
612
David Daneycf41a512010-11-19 12:13:18 +0000613 err = marvell_of_reg_init(phydev);
614 if (err < 0)
615 return err;
616
David Daney90600732010-11-19 11:58:53 +0000617 /* Reset address */
618 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
619 if (err < 0)
620 return err;
621
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000622 return phy_write(phydev, MII_BMCR, BMCR_RESET);
David Daney90600732010-11-19 11:58:53 +0000623}
624
Andy Fleming76884672007-02-09 18:13:58 -0600625static int m88e1145_config_init(struct phy_device *phydev)
626{
627 int err;
628
629 /* Take care of errata E0 & E1 */
630 err = phy_write(phydev, 0x1d, 0x001b);
631 if (err < 0)
632 return err;
633
634 err = phy_write(phydev, 0x1e, 0x418f);
635 if (err < 0)
636 return err;
637
638 err = phy_write(phydev, 0x1d, 0x0016);
639 if (err < 0)
640 return err;
641
642 err = phy_write(phydev, 0x1e, 0xa2da);
643 if (err < 0)
644 return err;
645
Kim Phillips895ee682007-06-05 18:46:47 +0800646 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andy Fleming76884672007-02-09 18:13:58 -0600647 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
648 if (temp < 0)
649 return temp;
650
651 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
652
653 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
654 if (err < 0)
655 return err;
656
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000657 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
Andy Fleming76884672007-02-09 18:13:58 -0600658 err = phy_write(phydev, 0x1d, 0x0012);
659 if (err < 0)
660 return err;
661
662 temp = phy_read(phydev, 0x1e);
663 if (temp < 0)
664 return temp;
665
666 temp &= 0xf03f;
667 temp |= 2 << 9; /* 36 ohm */
668 temp |= 2 << 6; /* 39 ohm */
669
670 err = phy_write(phydev, 0x1e, temp);
671 if (err < 0)
672 return err;
673
674 err = phy_write(phydev, 0x1d, 0x3);
675 if (err < 0)
676 return err;
677
678 err = phy_write(phydev, 0x1e, 0x8000);
679 if (err < 0)
680 return err;
681 }
682 }
683
Vince Bridgers99d881f2014-10-26 14:22:24 -0500684 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
685 int temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
686 if (temp < 0)
687 return temp;
688
689 temp &= ~MII_M1145_HWCFG_MODE_MASK;
690 temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
691 temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
692
693 err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
694 if (err < 0)
695 return err;
696 }
697
David Daneycf41a512010-11-19 12:13:18 +0000698 err = marvell_of_reg_init(phydev);
699 if (err < 0)
700 return err;
701
Andy Fleming76884672007-02-09 18:13:58 -0600702 return 0;
703}
Andy Fleming00db8182005-07-30 19:31:23 -0400704
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300705/* marvell_read_status
706 *
707 * Generic status code does not detect Fiber correctly!
Jeff Garzikf0c88f92008-03-25 23:53:24 -0400708 * Description:
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300709 * Check the link, then figure out the current state
710 * by comparing what we advertise with what the link partner
711 * advertises. Start by checking the gigabit possibilities,
712 * then move on to 10/100.
713 */
714static int marvell_read_status(struct phy_device *phydev)
715{
716 int adv;
717 int err;
718 int lpa;
719 int status = 0;
720
721 /* Update the link, but return if there
722 * was an error */
723 err = genphy_update_link(phydev);
724 if (err)
725 return err;
726
727 if (AUTONEG_ENABLE == phydev->autoneg) {
728 status = phy_read(phydev, MII_M1011_PHY_STATUS);
729 if (status < 0)
730 return status;
731
732 lpa = phy_read(phydev, MII_LPA);
733 if (lpa < 0)
734 return lpa;
735
736 adv = phy_read(phydev, MII_ADVERTISE);
737 if (adv < 0)
738 return adv;
739
740 lpa &= adv;
741
742 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
743 phydev->duplex = DUPLEX_FULL;
744 else
745 phydev->duplex = DUPLEX_HALF;
746
747 status = status & MII_M1011_PHY_STATUS_SPD_MASK;
748 phydev->pause = phydev->asym_pause = 0;
749
750 switch (status) {
751 case MII_M1011_PHY_STATUS_1000:
752 phydev->speed = SPEED_1000;
753 break;
754
755 case MII_M1011_PHY_STATUS_100:
756 phydev->speed = SPEED_100;
757 break;
758
759 default:
760 phydev->speed = SPEED_10;
761 break;
762 }
763
764 if (phydev->duplex == DUPLEX_FULL) {
765 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
766 phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
767 }
768 } else {
769 int bmcr = phy_read(phydev, MII_BMCR);
770
771 if (bmcr < 0)
772 return bmcr;
773
774 if (bmcr & BMCR_FULLDPLX)
775 phydev->duplex = DUPLEX_FULL;
776 else
777 phydev->duplex = DUPLEX_HALF;
778
779 if (bmcr & BMCR_SPEED1000)
780 phydev->speed = SPEED_1000;
781 else if (bmcr & BMCR_SPEED100)
782 phydev->speed = SPEED_100;
783 else
784 phydev->speed = SPEED_10;
785
786 phydev->pause = phydev->asym_pause = 0;
787 }
788
789 return 0;
790}
791
Anatolij Gustschindcd07be2009-04-07 02:01:43 +0000792static int m88e1121_did_interrupt(struct phy_device *phydev)
793{
794 int imask;
795
796 imask = phy_read(phydev, MII_M1011_IEVENT);
797
798 if (imask & MII_M1011_IMASK_INIT)
799 return 1;
800
801 return 0;
802}
803
Michael Stapelberg3871c382013-03-11 13:56:45 +0000804static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
805{
806 wol->supported = WAKE_MAGIC;
807 wol->wolopts = 0;
808
809 if (phy_write(phydev, MII_MARVELL_PHY_PAGE,
810 MII_88E1318S_PHY_WOL_PAGE) < 0)
811 return;
812
813 if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) &
814 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
815 wol->wolopts |= WAKE_MAGIC;
816
817 if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0)
818 return;
819}
820
821static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
822{
823 int err, oldpage, temp;
824
825 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
826
827 if (wol->wolopts & WAKE_MAGIC) {
828 /* Explicitly switch to page 0x00, just to be sure */
829 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00);
830 if (err < 0)
831 return err;
832
833 /* Enable the WOL interrupt */
834 temp = phy_read(phydev, MII_88E1318S_PHY_CSIER);
835 temp |= MII_88E1318S_PHY_CSIER_WOL_EIE;
836 err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp);
837 if (err < 0)
838 return err;
839
840 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
841 MII_88E1318S_PHY_LED_PAGE);
842 if (err < 0)
843 return err;
844
845 /* Setup LED[2] as interrupt pin (active low) */
846 temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR);
847 temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT;
848 temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE;
849 temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW;
850 err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp);
851 if (err < 0)
852 return err;
853
854 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
855 MII_88E1318S_PHY_WOL_PAGE);
856 if (err < 0)
857 return err;
858
859 /* Store the device address for the magic packet */
860 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
861 ((phydev->attached_dev->dev_addr[5] << 8) |
862 phydev->attached_dev->dev_addr[4]));
863 if (err < 0)
864 return err;
865 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
866 ((phydev->attached_dev->dev_addr[3] << 8) |
867 phydev->attached_dev->dev_addr[2]));
868 if (err < 0)
869 return err;
870 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
871 ((phydev->attached_dev->dev_addr[1] << 8) |
872 phydev->attached_dev->dev_addr[0]));
873 if (err < 0)
874 return err;
875
876 /* Clear WOL status and enable magic packet matching */
877 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
878 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
879 temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
880 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
881 if (err < 0)
882 return err;
883 } else {
884 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
885 MII_88E1318S_PHY_WOL_PAGE);
886 if (err < 0)
887 return err;
888
889 /* Clear WOL status and disable magic packet matching */
890 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
891 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
892 temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
893 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
894 if (err < 0)
895 return err;
896 }
897
898 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
899 if (err < 0)
900 return err;
901
902 return 0;
903}
904
Olof Johanssone5479232007-07-03 16:23:46 -0500905static struct phy_driver marvell_drivers[] = {
906 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000907 .phy_id = MARVELL_PHY_ID_88E1101,
908 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -0500909 .name = "Marvell 88E1101",
910 .features = PHY_GBIT_FEATURES,
911 .flags = PHY_HAS_INTERRUPT,
912 .config_aneg = &marvell_config_aneg,
913 .read_status = &genphy_read_status,
914 .ack_interrupt = &marvell_ack_interrupt,
915 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100916 .resume = &genphy_resume,
917 .suspend = &genphy_suspend,
Olof Johanssonac8c6352007-11-04 16:08:51 -0600918 .driver = { .owner = THIS_MODULE },
Olof Johanssone5479232007-07-03 16:23:46 -0500919 },
920 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000921 .phy_id = MARVELL_PHY_ID_88E1112,
922 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johansson85cfb532007-07-03 16:24:32 -0500923 .name = "Marvell 88E1112",
924 .features = PHY_GBIT_FEATURES,
925 .flags = PHY_HAS_INTERRUPT,
926 .config_init = &m88e1111_config_init,
927 .config_aneg = &marvell_config_aneg,
928 .read_status = &genphy_read_status,
929 .ack_interrupt = &marvell_ack_interrupt,
930 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100931 .resume = &genphy_resume,
932 .suspend = &genphy_suspend,
Olof Johanssonac8c6352007-11-04 16:08:51 -0600933 .driver = { .owner = THIS_MODULE },
Olof Johansson85cfb532007-07-03 16:24:32 -0500934 },
935 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000936 .phy_id = MARVELL_PHY_ID_88E1111,
937 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -0500938 .name = "Marvell 88E1111",
939 .features = PHY_GBIT_FEATURES,
940 .flags = PHY_HAS_INTERRUPT,
941 .config_init = &m88e1111_config_init,
942 .config_aneg = &marvell_config_aneg,
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300943 .read_status = &marvell_read_status,
Olof Johanssone5479232007-07-03 16:23:46 -0500944 .ack_interrupt = &marvell_ack_interrupt,
945 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100946 .resume = &genphy_resume,
947 .suspend = &genphy_suspend,
Olof Johanssonac8c6352007-11-04 16:08:51 -0600948 .driver = { .owner = THIS_MODULE },
Olof Johanssone5479232007-07-03 16:23:46 -0500949 },
950 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000951 .phy_id = MARVELL_PHY_ID_88E1118,
952 .phy_id_mask = MARVELL_PHY_ID_MASK,
Ron Madrid605f1962008-11-06 09:05:26 +0000953 .name = "Marvell 88E1118",
954 .features = PHY_GBIT_FEATURES,
955 .flags = PHY_HAS_INTERRUPT,
956 .config_init = &m88e1118_config_init,
957 .config_aneg = &m88e1118_config_aneg,
958 .read_status = &genphy_read_status,
959 .ack_interrupt = &marvell_ack_interrupt,
960 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100961 .resume = &genphy_resume,
962 .suspend = &genphy_suspend,
Ron Madrid605f1962008-11-06 09:05:26 +0000963 .driver = {.owner = THIS_MODULE,},
964 },
965 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000966 .phy_id = MARVELL_PHY_ID_88E1121R,
967 .phy_id_mask = MARVELL_PHY_ID_MASK,
Sergei Poselenov140bc922009-04-07 02:01:41 +0000968 .name = "Marvell 88E1121R",
969 .features = PHY_GBIT_FEATURES,
970 .flags = PHY_HAS_INTERRUPT,
971 .config_aneg = &m88e1121_config_aneg,
972 .read_status = &marvell_read_status,
973 .ack_interrupt = &marvell_ack_interrupt,
974 .config_intr = &marvell_config_intr,
Anatolij Gustschindcd07be2009-04-07 02:01:43 +0000975 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100976 .resume = &genphy_resume,
977 .suspend = &genphy_suspend,
Sergei Poselenov140bc922009-04-07 02:01:41 +0000978 .driver = { .owner = THIS_MODULE },
979 },
980 {
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700981 .phy_id = MARVELL_PHY_ID_88E1318S,
Linus Torvalds6ba74012010-08-04 11:47:58 -0700982 .phy_id_mask = MARVELL_PHY_ID_MASK,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700983 .name = "Marvell 88E1318S",
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700984 .features = PHY_GBIT_FEATURES,
985 .flags = PHY_HAS_INTERRUPT,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700986 .config_aneg = &m88e1318_config_aneg,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700987 .read_status = &marvell_read_status,
988 .ack_interrupt = &marvell_ack_interrupt,
989 .config_intr = &marvell_config_intr,
990 .did_interrupt = &m88e1121_did_interrupt,
Michael Stapelberg3871c382013-03-11 13:56:45 +0000991 .get_wol = &m88e1318_get_wol,
992 .set_wol = &m88e1318_set_wol,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +0100993 .resume = &genphy_resume,
994 .suspend = &genphy_suspend,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700995 .driver = { .owner = THIS_MODULE },
996 },
997 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000998 .phy_id = MARVELL_PHY_ID_88E1145,
999 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001000 .name = "Marvell 88E1145",
1001 .features = PHY_GBIT_FEATURES,
1002 .flags = PHY_HAS_INTERRUPT,
1003 .config_init = &m88e1145_config_init,
1004 .config_aneg = &marvell_config_aneg,
1005 .read_status = &genphy_read_status,
1006 .ack_interrupt = &marvell_ack_interrupt,
1007 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001008 .resume = &genphy_resume,
1009 .suspend = &genphy_suspend,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001010 .driver = { .owner = THIS_MODULE },
1011 },
1012 {
David Daney90600732010-11-19 11:58:53 +00001013 .phy_id = MARVELL_PHY_ID_88E1149R,
1014 .phy_id_mask = MARVELL_PHY_ID_MASK,
1015 .name = "Marvell 88E1149R",
1016 .features = PHY_GBIT_FEATURES,
1017 .flags = PHY_HAS_INTERRUPT,
1018 .config_init = &m88e1149_config_init,
1019 .config_aneg = &m88e1118_config_aneg,
1020 .read_status = &genphy_read_status,
1021 .ack_interrupt = &marvell_ack_interrupt,
1022 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001023 .resume = &genphy_resume,
1024 .suspend = &genphy_suspend,
David Daney90600732010-11-19 11:58:53 +00001025 .driver = { .owner = THIS_MODULE },
1026 },
1027 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001028 .phy_id = MARVELL_PHY_ID_88E1240,
1029 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001030 .name = "Marvell 88E1240",
1031 .features = PHY_GBIT_FEATURES,
1032 .flags = PHY_HAS_INTERRUPT,
1033 .config_init = &m88e1111_config_init,
1034 .config_aneg = &marvell_config_aneg,
1035 .read_status = &genphy_read_status,
1036 .ack_interrupt = &marvell_ack_interrupt,
1037 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001038 .resume = &genphy_resume,
1039 .suspend = &genphy_suspend,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001040 .driver = { .owner = THIS_MODULE },
1041 },
Michal Simek3da09a52013-05-30 20:08:26 +00001042 {
1043 .phy_id = MARVELL_PHY_ID_88E1116R,
1044 .phy_id_mask = MARVELL_PHY_ID_MASK,
1045 .name = "Marvell 88E1116R",
1046 .features = PHY_GBIT_FEATURES,
1047 .flags = PHY_HAS_INTERRUPT,
1048 .config_init = &m88e1116r_config_init,
1049 .config_aneg = &genphy_config_aneg,
1050 .read_status = &genphy_read_status,
1051 .ack_interrupt = &marvell_ack_interrupt,
1052 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001053 .resume = &genphy_resume,
1054 .suspend = &genphy_suspend,
Michal Simek3da09a52013-05-30 20:08:26 +00001055 .driver = { .owner = THIS_MODULE },
1056 },
Michal Simek10e24caa2013-05-30 20:08:27 +00001057 {
1058 .phy_id = MARVELL_PHY_ID_88E1510,
1059 .phy_id_mask = MARVELL_PHY_ID_MASK,
1060 .name = "Marvell 88E1510",
1061 .features = PHY_GBIT_FEATURES,
1062 .flags = PHY_HAS_INTERRUPT,
1063 .config_aneg = &m88e1510_config_aneg,
1064 .read_status = &marvell_read_status,
1065 .ack_interrupt = &marvell_ack_interrupt,
1066 .config_intr = &marvell_config_intr,
1067 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001068 .resume = &genphy_resume,
1069 .suspend = &genphy_suspend,
Michal Simek10e24caa2013-05-30 20:08:27 +00001070 .driver = { .owner = THIS_MODULE },
1071 },
Andy Fleming00db8182005-07-30 19:31:23 -04001072};
1073
1074static int __init marvell_init(void)
1075{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +00001076 return phy_drivers_register(marvell_drivers,
1077 ARRAY_SIZE(marvell_drivers));
Andy Fleming00db8182005-07-30 19:31:23 -04001078}
1079
1080static void __exit marvell_exit(void)
1081{
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +00001082 phy_drivers_unregister(marvell_drivers,
1083 ARRAY_SIZE(marvell_drivers));
Andy Fleming00db8182005-07-30 19:31:23 -04001084}
1085
1086module_init(marvell_init);
1087module_exit(marvell_exit);
David Woodhouse4e4f10f2010-04-02 01:05:56 +00001088
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +00001089static struct mdio_device_id __maybe_unused marvell_tbl[] = {
Michal Simekf5e1cab2013-05-30 20:08:25 +00001090 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
1091 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
1092 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
1093 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
1094 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
1095 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
1096 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
1097 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
1098 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
Michal Simek3da09a52013-05-30 20:08:26 +00001099 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
Michal Simek10e24caa2013-05-30 20:08:27 +00001100 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
David Woodhouse4e4f10f2010-04-02 01:05:56 +00001101 { }
1102};
1103
1104MODULE_DEVICE_TABLE(mdio, marvell_tbl);