2 * drivers/net/phy/marvell.c
4 * Driver for Marvell PHYs
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
20 #include <linux/unistd.h>
21 #include <linux/slab.h>
22 #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>
30 #include <linux/module.h>
31 #include <linux/mii.h>
32 #include <linux/ethtool.h>
33 #include <linux/phy.h>
37 #include <asm/uaccess.h>
39 #define MII_M1011_IEVENT 0x13
40 #define MII_M1011_IEVENT_CLEAR 0x0000
42 #define MII_M1011_IMASK 0x12
43 #define MII_M1011_IMASK_INIT 0x6400
44 #define MII_M1011_IMASK_CLEAR 0x0000
46 #define MII_M1011_PHY_SCR 0x10
47 #define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
49 #define MII_M1145_PHY_EXT_CR 0x14
50 #define MII_M1145_RGMII_RX_DELAY 0x0080
51 #define MII_M1145_RGMII_TX_DELAY 0x0002
53 #define M1145_DEV_FLAGS_RESISTANCE 0x00000001
55 #define MII_M1111_PHY_LED_CONTROL 0x18
56 #define MII_M1111_PHY_LED_DIRECT 0x4100
57 #define MII_M1111_PHY_LED_COMBINE 0x411c
59 MODULE_DESCRIPTION("Marvell PHY driver");
60 MODULE_AUTHOR("Andy Fleming");
61 MODULE_LICENSE("GPL");
63 static int marvell_ack_interrupt(struct phy_device *phydev)
67 /* Clear the interrupts by reading the reg */
68 err = phy_read(phydev, MII_M1011_IEVENT);
76 static int marvell_config_intr(struct phy_device *phydev)
80 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
81 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
83 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
88 static int marvell_config_aneg(struct phy_device *phydev)
92 /* The Marvell PHY has an errata which requires
93 * that certain registers get written in order
94 * to restart autonegotiation */
95 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
100 err = phy_write(phydev, 0x1d, 0x1f);
104 err = phy_write(phydev, 0x1e, 0x200c);
108 err = phy_write(phydev, 0x1d, 0x5);
112 err = phy_write(phydev, 0x1e, 0);
116 err = phy_write(phydev, 0x1e, 0x100);
120 err = phy_write(phydev, MII_M1011_PHY_SCR,
121 MII_M1011_PHY_SCR_AUTO_CROSS);
125 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
126 MII_M1111_PHY_LED_DIRECT);
130 err = genphy_config_aneg(phydev);
135 static int m88e1145_config_init(struct phy_device *phydev)
139 /* Take care of errata E0 & E1 */
140 err = phy_write(phydev, 0x1d, 0x001b);
144 err = phy_write(phydev, 0x1e, 0x418f);
148 err = phy_write(phydev, 0x1d, 0x0016);
152 err = phy_write(phydev, 0x1e, 0xa2da);
156 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
157 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
161 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
163 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
167 if (phydev->dev_flags & M1145_DEV_FLAGS_RESISTANCE) {
168 err = phy_write(phydev, 0x1d, 0x0012);
172 temp = phy_read(phydev, 0x1e);
177 temp |= 2 << 9; /* 36 ohm */
178 temp |= 2 << 6; /* 39 ohm */
180 err = phy_write(phydev, 0x1e, temp);
184 err = phy_write(phydev, 0x1d, 0x3);
188 err = phy_write(phydev, 0x1e, 0x8000);
197 static struct phy_driver m88e1101_driver = {
198 .phy_id = 0x01410c60,
199 .phy_id_mask = 0xfffffff0,
200 .name = "Marvell 88E1101",
201 .features = PHY_GBIT_FEATURES,
202 .flags = PHY_HAS_INTERRUPT,
203 .config_aneg = &marvell_config_aneg,
204 .read_status = &genphy_read_status,
205 .ack_interrupt = &marvell_ack_interrupt,
206 .config_intr = &marvell_config_intr,
207 .driver = {.owner = THIS_MODULE,},
210 static struct phy_driver m88e1111s_driver = {
211 .phy_id = 0x01410cc0,
212 .phy_id_mask = 0xfffffff0,
213 .name = "Marvell 88E1111",
214 .features = PHY_GBIT_FEATURES,
215 .flags = PHY_HAS_INTERRUPT,
216 .config_aneg = &marvell_config_aneg,
217 .read_status = &genphy_read_status,
218 .ack_interrupt = &marvell_ack_interrupt,
219 .config_intr = &marvell_config_intr,
220 .driver = {.owner = THIS_MODULE,},
223 static struct phy_driver m88e1145_driver = {
224 .phy_id = 0x01410cd0,
225 .phy_id_mask = 0xfffffff0,
226 .name = "Marvell 88E1145",
227 .features = PHY_GBIT_FEATURES,
228 .flags = PHY_HAS_INTERRUPT,
229 .config_init = &m88e1145_config_init,
230 .config_aneg = &marvell_config_aneg,
231 .read_status = &genphy_read_status,
232 .ack_interrupt = &marvell_ack_interrupt,
233 .config_intr = &marvell_config_intr,
234 .driver = {.owner = THIS_MODULE,},
237 static int __init marvell_init(void)
241 ret = phy_driver_register(&m88e1101_driver);
245 ret = phy_driver_register(&m88e1111s_driver);
249 ret = phy_driver_register(&m88e1145_driver);
256 phy_driver_unregister(&m88e1111s_driver);
258 phy_driver_unregister(&m88e1101_driver);
262 static void __exit marvell_exit(void)
264 phy_driver_unregister(&m88e1101_driver);
265 phy_driver_unregister(&m88e1111s_driver);
266 phy_driver_unregister(&m88e1145_driver);
269 module_init(marvell_init);
270 module_exit(marvell_exit);