2 * drivers/net/phy/realtek.c
4 * Driver for Realtek PHYs
6 * Author: Johnson Leung <r58129@freescale.com>
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/phy.h>
17 #include <linux/module.h>
19 #define RTL821x_PHYSR 0x11
20 #define RTL821x_PHYSR_DUPLEX 0x2000
21 #define RTL821x_PHYSR_SPEED 0xc000
22 #define RTL821x_INER 0x12
23 #define RTL821x_INER_INIT 0x6400
24 #define RTL821x_INSR 0x13
25 #define RTL8211E_INER_LINK_STATUS 0x400
27 #define RTL8211F_INER_LINK_STATUS 0x0010
28 #define RTL8211F_INSR 0x1d
29 #define RTL8211F_PAGE_SELECT 0x1f
30 #define RTL8211F_TX_DELAY 0x100
32 MODULE_DESCRIPTION("Realtek PHY driver");
33 MODULE_AUTHOR("Johnson Leung");
34 MODULE_LICENSE("GPL");
36 static int rtl821x_ack_interrupt(struct phy_device *phydev)
40 err = phy_read(phydev, RTL821x_INSR);
42 return (err < 0) ? err : 0;
45 static int rtl8211f_ack_interrupt(struct phy_device *phydev)
49 phy_write(phydev, RTL8211F_PAGE_SELECT, 0xa43);
50 err = phy_read(phydev, RTL8211F_INSR);
51 /* restore to default page 0 */
52 phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
54 return (err < 0) ? err : 0;
57 static int rtl8211b_config_intr(struct phy_device *phydev)
61 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
62 err = phy_write(phydev, RTL821x_INER,
65 err = phy_write(phydev, RTL821x_INER, 0);
70 static int rtl8211e_config_intr(struct phy_device *phydev)
74 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
75 err = phy_write(phydev, RTL821x_INER,
76 RTL8211E_INER_LINK_STATUS);
78 err = phy_write(phydev, RTL821x_INER, 0);
83 static int rtl8211f_config_intr(struct phy_device *phydev)
87 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
88 err = phy_write(phydev, RTL821x_INER,
89 RTL8211F_INER_LINK_STATUS);
91 err = phy_write(phydev, RTL821x_INER, 0);
96 static int rtl8211f_config_init(struct phy_device *phydev)
101 ret = genphy_config_init(phydev);
105 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
107 phy_write(phydev, RTL8211F_PAGE_SELECT, 0xd08);
108 reg = phy_read(phydev, 0x11);
109 reg |= RTL8211F_TX_DELAY;
110 phy_write(phydev, 0x11, reg);
111 /* restore to default page 0 */
112 phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
118 static struct phy_driver realtek_drvs[] = {
120 .phy_id = 0x00008201,
121 .name = "RTL8201CP Ethernet",
122 .phy_id_mask = 0x0000ffff,
123 .features = PHY_BASIC_FEATURES,
124 .flags = PHY_HAS_INTERRUPT,
125 .config_aneg = &genphy_config_aneg,
126 .read_status = &genphy_read_status,
127 .driver = { .owner = THIS_MODULE,},
129 .phy_id = 0x001cc912,
130 .name = "RTL8211B Gigabit Ethernet",
131 .phy_id_mask = 0x001fffff,
132 .features = PHY_GBIT_FEATURES,
133 .flags = PHY_HAS_INTERRUPT,
134 .config_aneg = &genphy_config_aneg,
135 .read_status = &genphy_read_status,
136 .ack_interrupt = &rtl821x_ack_interrupt,
137 .config_intr = &rtl8211b_config_intr,
138 .driver = { .owner = THIS_MODULE,},
140 .phy_id = 0x001cc915,
141 .name = "RTL8211E Gigabit Ethernet",
142 .phy_id_mask = 0x001fffff,
143 .features = PHY_GBIT_FEATURES,
144 .flags = PHY_HAS_INTERRUPT,
145 .config_aneg = &genphy_config_aneg,
146 .read_status = &genphy_read_status,
147 .ack_interrupt = &rtl821x_ack_interrupt,
148 .config_intr = &rtl8211e_config_intr,
149 .suspend = genphy_suspend,
150 .resume = genphy_resume,
151 .driver = { .owner = THIS_MODULE,},
153 .phy_id = 0x001cc916,
154 .name = "RTL8211F Gigabit Ethernet",
155 .phy_id_mask = 0x001fffff,
156 .features = PHY_GBIT_FEATURES,
157 .flags = PHY_HAS_INTERRUPT,
158 .config_aneg = &genphy_config_aneg,
159 .config_init = &rtl8211f_config_init,
160 .read_status = &genphy_read_status,
161 .ack_interrupt = &rtl8211f_ack_interrupt,
162 .config_intr = &rtl8211f_config_intr,
163 .suspend = genphy_suspend,
164 .resume = genphy_resume,
165 .driver = { .owner = THIS_MODULE },
169 module_phy_driver(realtek_drvs);
171 static struct mdio_device_id __maybe_unused realtek_tbl[] = {
172 { 0x001cc912, 0x001fffff },
173 { 0x001cc915, 0x001fffff },
174 { 0x001cc916, 0x001fffff },
178 MODULE_DEVICE_TABLE(mdio, realtek_tbl);