Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 1 | /* |
| 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 Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 18 | |
| 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 CAVALLARO | 8b64fd6 | 2013-08-19 08:48:34 +0200 | [diff] [blame] | 26 | #define RTL8211E_INER_LINK_STATUS 0x400 |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 27 | |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 28 | MODULE_DESCRIPTION("Realtek PHY driver"); |
| 29 | MODULE_AUTHOR("Johnson Leung"); |
| 30 | MODULE_LICENSE("GPL"); |
| 31 | |
| 32 | static 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 CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 41 | static int rtl8211b_config_intr(struct phy_device *phydev) |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 42 | { |
| 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 CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 54 | static 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 CAVALLARO | 8b64fd6 | 2013-08-19 08:48:34 +0200 | [diff] [blame] | 60 | RTL8211E_INER_LINK_STATUS); |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 61 | else |
| 62 | err = phy_write(phydev, RTL821x_INER, 0); |
| 63 | |
| 64 | return err; |
| 65 | } |
| 66 | |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 67 | /* RTL8211B */ |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 68 | static struct phy_driver rtl8211b_driver = { |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 69 | .phy_id = 0x001cc912, |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 70 | .name = "RTL8211B Gigabit Ethernet", |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 71 | .phy_id_mask = 0x001fffff, |
| 72 | .features = PHY_GBIT_FEATURES, |
| 73 | .flags = PHY_HAS_INTERRUPT, |
| 74 | .config_aneg = &genphy_config_aneg, |
| 75 | .read_status = &genphy_read_status, |
| 76 | .ack_interrupt = &rtl821x_ack_interrupt, |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 77 | .config_intr = &rtl8211b_config_intr, |
| 78 | .driver = { .owner = THIS_MODULE,}, |
| 79 | }; |
| 80 | |
| 81 | /* RTL8211E */ |
| 82 | static struct phy_driver rtl8211e_driver = { |
| 83 | .phy_id = 0x001cc915, |
| 84 | .name = "RTL8211E Gigabit Ethernet", |
| 85 | .phy_id_mask = 0x001fffff, |
| 86 | .features = PHY_GBIT_FEATURES, |
| 87 | .flags = PHY_HAS_INTERRUPT, |
| 88 | .config_aneg = &genphy_config_aneg, |
| 89 | .read_status = &genphy_read_status, |
| 90 | .ack_interrupt = &rtl821x_ack_interrupt, |
| 91 | .config_intr = &rtl8211e_config_intr, |
| 92 | .suspend = genphy_suspend, |
| 93 | .resume = genphy_resume, |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 94 | .driver = { .owner = THIS_MODULE,}, |
| 95 | }; |
| 96 | |
| 97 | static int __init realtek_init(void) |
| 98 | { |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 99 | int ret; |
| 100 | |
| 101 | ret = phy_driver_register(&rtl8211b_driver); |
| 102 | if (ret < 0) |
| 103 | return -ENODEV; |
| 104 | return phy_driver_register(&rtl8211e_driver); |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void __exit realtek_exit(void) |
| 108 | { |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 109 | phy_driver_unregister(&rtl8211b_driver); |
| 110 | phy_driver_unregister(&rtl8211e_driver); |
Johnson Leung | 097c2aa | 2008-02-03 03:50:54 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | module_init(realtek_init); |
| 114 | module_exit(realtek_exit); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 115 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 116 | static struct mdio_device_id __maybe_unused realtek_tbl[] = { |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 117 | { 0x001cc912, 0x001fffff }, |
Giuseppe CAVALLARO | ef3d904 | 2013-01-23 00:30:03 +0000 | [diff] [blame] | 118 | { 0x001cc915, 0x001fffff }, |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 119 | { } |
| 120 | }; |
| 121 | |
| 122 | MODULE_DEVICE_TABLE(mdio, realtek_tbl); |