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/bitops.h>
17 #include <linux/phy.h>
18 #include <linux/module.h>
20 #define RTL821x_PHYSR 0x11
21 #define RTL821x_PHYSR_DUPLEX BIT(13)
22 #define RTL821x_PHYSR_SPEED GENMASK(15, 14)
24 #define RTL821x_INER 0x12
25 #define RTL8211B_INER_INIT 0x6400
26 #define RTL8211E_INER_LINK_STATUS BIT(10)
27 #define RTL8211F_INER_LINK_STATUS BIT(4)
29 #define RTL821x_INSR 0x13
31 #define RTL821x_PAGE_SELECT 0x1f
33 #define RTL8211F_INSR 0x1d
35 #define RTL8211F_TX_DELAY BIT(8)
37 #define RTL8201F_ISR 0x1e
38 #define RTL8201F_IER 0x13
40 #define RTL8366RB_POWER_SAVE 0x15
41 #define RTL8366RB_POWER_SAVE_ON BIT(12)
43 MODULE_DESCRIPTION("Realtek PHY driver");
44 MODULE_AUTHOR("Johnson Leung");
45 MODULE_LICENSE("GPL");
47 static int rtl821x_read_page(struct phy_device
*phydev
)
49 return __phy_read(phydev
, RTL821x_PAGE_SELECT
);
52 static int rtl821x_write_page(struct phy_device
*phydev
, int page
)
54 return __phy_write(phydev
, RTL821x_PAGE_SELECT
, page
);
57 static int rtl8201_ack_interrupt(struct phy_device
*phydev
)
61 err
= phy_read(phydev
, RTL8201F_ISR
);
63 return (err
< 0) ? err
: 0;
66 static int rtl821x_ack_interrupt(struct phy_device
*phydev
)
70 err
= phy_read(phydev
, RTL821x_INSR
);
72 return (err
< 0) ? err
: 0;
75 static int rtl8211f_ack_interrupt(struct phy_device
*phydev
)
79 err
= phy_read_paged(phydev
, 0xa43, RTL8211F_INSR
);
81 return (err
< 0) ? err
: 0;
84 static int rtl8201_config_intr(struct phy_device
*phydev
)
88 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
89 val
= BIT(13) | BIT(12) | BIT(11);
93 return phy_write_paged(phydev
, 0x7, RTL8201F_IER
, val
);
96 static int rtl8211b_config_intr(struct phy_device
*phydev
)
100 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
101 err
= phy_write(phydev
, RTL821x_INER
,
104 err
= phy_write(phydev
, RTL821x_INER
, 0);
109 static int rtl8211e_config_intr(struct phy_device
*phydev
)
113 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
114 err
= phy_write(phydev
, RTL821x_INER
,
115 RTL8211E_INER_LINK_STATUS
);
117 err
= phy_write(phydev
, RTL821x_INER
, 0);
122 static int rtl8211f_config_intr(struct phy_device
*phydev
)
126 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
127 val
= RTL8211F_INER_LINK_STATUS
;
131 return phy_write_paged(phydev
, 0xa42, RTL821x_INER
, val
);
134 static int rtl8211_config_aneg(struct phy_device
*phydev
)
138 ret
= genphy_config_aneg(phydev
);
142 /* Quirk was copied from vendor driver. Unfortunately it includes no
143 * description of the magic numbers.
145 if (phydev
->speed
== SPEED_100
&& phydev
->autoneg
== AUTONEG_DISABLE
) {
146 phy_write(phydev
, 0x17, 0x2138);
147 phy_write(phydev
, 0x0e, 0x0260);
149 phy_write(phydev
, 0x17, 0x2108);
150 phy_write(phydev
, 0x0e, 0x0000);
156 static int rtl8211c_config_init(struct phy_device
*phydev
)
158 /* RTL8211C has an issue when operating in Gigabit slave mode */
159 phy_set_bits(phydev
, MII_CTRL1000
,
160 CTL1000_ENABLE_MASTER
| CTL1000_AS_MASTER
);
162 return genphy_config_init(phydev
);
165 static int rtl8211f_config_init(struct phy_device
*phydev
)
170 ret
= genphy_config_init(phydev
);
174 /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */
175 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
||
176 phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)
177 val
= RTL8211F_TX_DELAY
;
179 return phy_modify_paged(phydev
, 0xd08, 0x11, RTL8211F_TX_DELAY
, val
);
182 static int rtl8211b_suspend(struct phy_device
*phydev
)
184 phy_write(phydev
, MII_MMD_DATA
, BIT(9));
186 return genphy_suspend(phydev
);
189 static int rtl8211b_resume(struct phy_device
*phydev
)
191 phy_write(phydev
, MII_MMD_DATA
, 0);
193 return genphy_resume(phydev
);
196 static int rtl8366rb_config_init(struct phy_device
*phydev
)
200 ret
= genphy_config_init(phydev
);
204 ret
= phy_set_bits(phydev
, RTL8366RB_POWER_SAVE
,
205 RTL8366RB_POWER_SAVE_ON
);
207 dev_err(&phydev
->mdio
.dev
,
208 "error enabling power management\n");
214 static struct phy_driver realtek_drvs
[] = {
216 .phy_id
= 0x00008201,
217 .name
= "RTL8201CP Ethernet",
218 .phy_id_mask
= 0x0000ffff,
219 .features
= PHY_BASIC_FEATURES
,
220 .flags
= PHY_HAS_INTERRUPT
,
222 .phy_id
= 0x001cc816,
223 .name
= "RTL8201F Fast Ethernet",
224 .phy_id_mask
= 0x001fffff,
225 .features
= PHY_BASIC_FEATURES
,
226 .flags
= PHY_HAS_INTERRUPT
,
227 .ack_interrupt
= &rtl8201_ack_interrupt
,
228 .config_intr
= &rtl8201_config_intr
,
229 .suspend
= genphy_suspend
,
230 .resume
= genphy_resume
,
231 .read_page
= rtl821x_read_page
,
232 .write_page
= rtl821x_write_page
,
234 .phy_id
= 0x001cc910,
235 .name
= "RTL8211 Gigabit Ethernet",
236 .phy_id_mask
= 0x001fffff,
237 .features
= PHY_GBIT_FEATURES
,
238 .config_aneg
= rtl8211_config_aneg
,
239 .read_mmd
= &genphy_read_mmd_unsupported
,
240 .write_mmd
= &genphy_write_mmd_unsupported
,
242 .phy_id
= 0x001cc912,
243 .name
= "RTL8211B Gigabit Ethernet",
244 .phy_id_mask
= 0x001fffff,
245 .features
= PHY_GBIT_FEATURES
,
246 .flags
= PHY_HAS_INTERRUPT
,
247 .ack_interrupt
= &rtl821x_ack_interrupt
,
248 .config_intr
= &rtl8211b_config_intr
,
249 .read_mmd
= &genphy_read_mmd_unsupported
,
250 .write_mmd
= &genphy_write_mmd_unsupported
,
251 .suspend
= rtl8211b_suspend
,
252 .resume
= rtl8211b_resume
,
254 .phy_id
= 0x001cc913,
255 .name
= "RTL8211C Gigabit Ethernet",
256 .phy_id_mask
= 0x001fffff,
257 .features
= PHY_GBIT_FEATURES
,
258 .config_init
= rtl8211c_config_init
,
259 .read_mmd
= &genphy_read_mmd_unsupported
,
260 .write_mmd
= &genphy_write_mmd_unsupported
,
262 .phy_id
= 0x001cc914,
263 .name
= "RTL8211DN Gigabit Ethernet",
264 .phy_id_mask
= 0x001fffff,
265 .features
= PHY_GBIT_FEATURES
,
266 .flags
= PHY_HAS_INTERRUPT
,
267 .ack_interrupt
= rtl821x_ack_interrupt
,
268 .config_intr
= rtl8211e_config_intr
,
269 .suspend
= genphy_suspend
,
270 .resume
= genphy_resume
,
272 .phy_id
= 0x001cc915,
273 .name
= "RTL8211E Gigabit Ethernet",
274 .phy_id_mask
= 0x001fffff,
275 .features
= PHY_GBIT_FEATURES
,
276 .flags
= PHY_HAS_INTERRUPT
,
277 .ack_interrupt
= &rtl821x_ack_interrupt
,
278 .config_intr
= &rtl8211e_config_intr
,
279 .suspend
= genphy_suspend
,
280 .resume
= genphy_resume
,
282 .phy_id
= 0x001cc916,
283 .name
= "RTL8211F Gigabit Ethernet",
284 .phy_id_mask
= 0x001fffff,
285 .features
= PHY_GBIT_FEATURES
,
286 .flags
= PHY_HAS_INTERRUPT
,
287 .config_init
= &rtl8211f_config_init
,
288 .ack_interrupt
= &rtl8211f_ack_interrupt
,
289 .config_intr
= &rtl8211f_config_intr
,
290 .suspend
= genphy_suspend
,
291 .resume
= genphy_resume
,
292 .read_page
= rtl821x_read_page
,
293 .write_page
= rtl821x_write_page
,
295 .phy_id
= 0x001cc961,
296 .name
= "RTL8366RB Gigabit Ethernet",
297 .phy_id_mask
= 0x001fffff,
298 .features
= PHY_GBIT_FEATURES
,
299 .flags
= PHY_HAS_INTERRUPT
,
300 .config_init
= &rtl8366rb_config_init
,
301 .suspend
= genphy_suspend
,
302 .resume
= genphy_resume
,
306 module_phy_driver(realtek_drvs
);
308 static struct mdio_device_id __maybe_unused realtek_tbl
[] = {
309 { 0x001cc816, 0x001fffff },
310 { 0x001cc910, 0x001fffff },
311 { 0x001cc912, 0x001fffff },
312 { 0x001cc913, 0x001fffff },
313 { 0x001cc914, 0x001fffff },
314 { 0x001cc915, 0x001fffff },
315 { 0x001cc916, 0x001fffff },
316 { 0x001cc961, 0x001fffff },
320 MODULE_DEVICE_TABLE(mdio
, realtek_tbl
);