[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ddf12809-eabc-0e0f-f878-beebd6e15ef4@gmail.com>
Date: Tue, 12 Nov 2019 22:23:53 +0100
From: Heiner Kallweit <hkallweit1@...il.com>
To: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
David Miller <davem@...emloft.net>,
Realtek linux nic maintainers <nic_swsd@...ltek.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: [PATCH net-next 1/3] net: phy: realtek: export rtl821x_modify_extpage
Certain Realtek PHY's support a proprietary "extended page" access mode
that is used in the Realtek PHY driver and in r8169 network driver.
Let's implement it properly in the Realtek PHY driver and export it for
use in other drivers like r8169.
Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
drivers/net/phy/realtek.c | 36 ++++++++++++++++++++++--------------
include/linux/realtek_phy.h | 8 ++++++++
2 files changed, 30 insertions(+), 14 deletions(-)
create mode 100644 include/linux/realtek_phy.h
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index 677c45985..89f125191 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -11,6 +11,7 @@
#include <linux/bitops.h>
#include <linux/phy.h>
#include <linux/module.h>
+#include <linux/realtek_phy.h>
#define RTL821x_PHYSR 0x11
#define RTL821x_PHYSR_DUPLEX BIT(13)
@@ -63,6 +64,24 @@ static int rtl821x_write_page(struct phy_device *phydev, int page)
return __phy_write(phydev, RTL821x_PAGE_SELECT, page);
}
+int rtl821x_modify_extpage(struct phy_device *phydev, int extpage, int reg,
+ u16 mask, u16 val)
+{
+ int oldpage = phy_select_page(phydev, 0x0007), ret = 0;
+
+ if (oldpage < 0)
+ goto out;
+
+ ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, extpage);
+ if (ret)
+ goto out;
+
+ ret = __phy_modify(phydev, reg, mask, val);
+out:
+ return phy_restore_page(phydev, oldpage, ret);
+}
+EXPORT_SYMBOL(rtl821x_modify_extpage);
+
static int rtl8201_ack_interrupt(struct phy_device *phydev)
{
int err;
@@ -194,7 +213,6 @@ static int rtl8211f_config_init(struct phy_device *phydev)
static int rtl8211e_config_init(struct phy_device *phydev)
{
- int ret = 0, oldpage;
u16 val;
/* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */
@@ -223,19 +241,9 @@ static int rtl8211e_config_init(struct phy_device *phydev)
* 2 = RX Delay, 1 = TX Delay, 0 = SELRGV (see original PHY datasheet
* for details).
*/
- oldpage = phy_select_page(phydev, 0x7);
- if (oldpage < 0)
- goto err_restore_page;
-
- ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4);
- if (ret)
- goto err_restore_page;
-
- ret = __phy_modify(phydev, 0x1c, RTL8211E_TX_DELAY | RTL8211E_RX_DELAY,
- val);
-
-err_restore_page:
- return phy_restore_page(phydev, oldpage, ret);
+ return rtl821x_modify_extpage(phydev, 0xa4, 0x1c,
+ RTL8211E_TX_DELAY | RTL8211E_RX_DELAY,
+ val);
}
static int rtl8211b_suspend(struct phy_device *phydev)
diff --git a/include/linux/realtek_phy.h b/include/linux/realtek_phy.h
new file mode 100644
index 000000000..dd9eee56f
--- /dev/null
+++ b/include/linux/realtek_phy.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _REALTEK_PHY_H
+#define _REALTEK_PHY_H
+
+int rtl821x_modify_extpage(struct phy_device *phydev, int extpage,
+ int reg, u16 mask, u16 val);
+
+#endif /* _REALTEK_PHY_H */
--
2.24.0
Powered by blists - more mailing lists