blob: 96a0f0fab3caca1cf9b315b35d6f0e75cd3f13a3 [file] [log] [blame]
Johnson Leung097c2aa2008-02-03 03:50:54 -08001/*
2 * drivers/net/phy/realtek.c
3 *
4 * Driver for Realtek PHYs
5 *
6 * Author: Johnson Leung <r58129@freescale.com>
7 *
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
9 *
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.
14 *
15 */
16#include <linux/phy.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040017#include <linux/module.h>
Johnson Leung097c2aa2008-02-03 03:50:54 -080018
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
Giuseppe CAVALLARO8b64fd62013-08-19 08:48:34 +020026#define RTL8211E_INER_LINK_STATUS 0x400
Giuseppe CAVALLAROef3d9042013-01-23 00:30:03 +000027
Johnson Leung097c2aa2008-02-03 03:50:54 -080028MODULE_DESCRIPTION("Realtek PHY driver");
29MODULE_AUTHOR("Johnson Leung");
30MODULE_LICENSE("GPL");
31
32static int rtl821x_ack_interrupt(struct phy_device *phydev)
33{
34 int err;
35
36 err = phy_read(phydev, RTL821x_INSR);
37
38 return (err < 0) ? err : 0;
39}
40
Giuseppe CAVALLAROef3d9042013-01-23 00:30:03 +000041static int rtl8211b_config_intr(struct phy_device *phydev)
Johnson Leung097c2aa2008-02-03 03:50:54 -080042{
43 int err;
44
45 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
46 err = phy_write(phydev, RTL821x_INER,
47 RTL821x_INER_INIT);
48 else
49 err = phy_write(phydev, RTL821x_INER, 0);
50
51 return err;
52}
53
Giuseppe CAVALLAROef3d9042013-01-23 00:30:03 +000054static int rtl8211e_config_intr(struct phy_device *phydev)
55{
56 int err;
57
58 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
59 err = phy_write(phydev, RTL821x_INER,
Giuseppe CAVALLARO8b64fd62013-08-19 08:48:34 +020060 RTL8211E_INER_LINK_STATUS);
Giuseppe CAVALLAROef3d9042013-01-23 00:30:03 +000061 else
62 err = phy_write(phydev, RTL821x_INER, 0);
63
64 return err;
65}
66
Jongsung Kim71b9c4a82014-06-10 12:50:12 +090067static struct phy_driver realtek_drvs[] = {
68 {
69 .phy_id = 0x00008201,
70 .name = "RTL8201CP Ethernet",
71 .phy_id_mask = 0x0000ffff,
72 .features = PHY_BASIC_FEATURES,
73 .flags = PHY_HAS_INTERRUPT,
74 .config_aneg = &genphy_config_aneg,
75 .read_status = &genphy_read_status,
76 .driver = { .owner = THIS_MODULE,},
77 }, {
78 .phy_id = 0x001cc912,
79 .name = "RTL8211B Gigabit Ethernet",
80 .phy_id_mask = 0x001fffff,
81 .features = PHY_GBIT_FEATURES,
82 .flags = PHY_HAS_INTERRUPT,
83 .config_aneg = &genphy_config_aneg,
84 .read_status = &genphy_read_status,
85 .ack_interrupt = &rtl821x_ack_interrupt,
86 .config_intr = &rtl8211b_config_intr,
87 .driver = { .owner = THIS_MODULE,},
88 }, {
89 .phy_id = 0x001cc915,
90 .name = "RTL8211E Gigabit Ethernet",
91 .phy_id_mask = 0x001fffff,
92 .features = PHY_GBIT_FEATURES,
93 .flags = PHY_HAS_INTERRUPT,
94 .config_aneg = &genphy_config_aneg,
95 .read_status = &genphy_read_status,
96 .ack_interrupt = &rtl821x_ack_interrupt,
97 .config_intr = &rtl8211e_config_intr,
98 .suspend = genphy_suspend,
99 .resume = genphy_resume,
100 .driver = { .owner = THIS_MODULE,},
101 },
Johnson Leung097c2aa2008-02-03 03:50:54 -0800102};
103
Johan Hovold50fd7152014-11-11 19:45:59 +0100104module_phy_driver(realtek_drvs);
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000105
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +0000106static struct mdio_device_id __maybe_unused realtek_tbl[] = {
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000107 { 0x001cc912, 0x001fffff },
Giuseppe CAVALLAROef3d9042013-01-23 00:30:03 +0000108 { 0x001cc915, 0x001fffff },
David Woodhouse4e4f10f2010-04-02 01:05:56 +0000109 { }
110};
111
112MODULE_DEVICE_TABLE(mdio, realtek_tbl);