netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 2/6] r8152: modify the method of accessing PHY
Date: Fri, 27 Dec 2013 10:34:06 +0800	[thread overview]
Message-ID: <1388111649-1014-3-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1388111649-1014-1-git-send-email-hayeswang@realtek.com>

The old method to access PHY is through mdio channel. Replace it
with the OCP channel.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 52 +++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 79bb553..b8bc3eb 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -98,6 +98,7 @@
 #define OCP_EEE_CONFIG1		0x2080
 #define OCP_EEE_CONFIG2		0x2092
 #define OCP_EEE_CONFIG3		0x2094
+#define OCP_BASE_MII		0xa400
 #define OCP_EEE_AR		0xa41a
 #define OCP_EEE_DATA		0xa41c
 
@@ -653,7 +654,7 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
 	generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
 }
 
-static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
+static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
 {
 	u16 ocp_base, ocp_index;
 
@@ -664,48 +665,31 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
 	}
 
 	ocp_index = (addr & 0x0fff) | 0xb000;
-	ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
+	return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
 }
 
-static void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
 {
-	u32	ocp_data;
-	int	i;
-
-	ocp_data = PHYAR_FLAG | ((reg_addr & 0x1f) << 16) |
-		   (value & 0xffff);
-
-	ocp_write_dword(tp, MCU_TYPE_PLA, PLA_PHYAR, ocp_data);
+	u16 ocp_base, ocp_index;
 
-	for (i = 20; i > 0; i--) {
-		udelay(25);
-		ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_PHYAR);
-		if (!(ocp_data & PHYAR_FLAG))
-			break;
+	ocp_base = addr & 0xf000;
+	if (ocp_base != tp->ocp_base) {
+		ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
+		tp->ocp_base = ocp_base;
 	}
-	udelay(20);
+
+	ocp_index = (addr & 0x0fff) | 0xb000;
+	ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
 }
 
-static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
 {
-	u32	ocp_data;
-	int	i;
-
-	ocp_data = (reg_addr & 0x1f) << 16;
-	ocp_write_dword(tp, MCU_TYPE_PLA, PLA_PHYAR, ocp_data);
-
-	for (i = 20; i > 0; i--) {
-		udelay(25);
-		ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_PHYAR);
-		if (ocp_data & PHYAR_FLAG)
-			break;
-	}
-	udelay(20);
-
-	if (!(ocp_data & PHYAR_FLAG))
-		return -EAGAIN;
+	ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+}
 
-	return (u16)(ocp_data & 0xffff);
+static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+{
+	return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
 }
 
 static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
-- 
1.8.3.1

  parent reply	other threads:[~2013-12-27  2:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-27  2:34 [PATCH net-next 0/6] Support new chip Hayes Wang
     [not found] ` <1388111649-1014-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2013-12-27  2:34   ` [PATCH net-next 1/6] r8152: move rtl8152_unload and ocp_reg_write Hayes Wang
2013-12-27  2:34 ` Hayes Wang [this message]
2013-12-27  2:34 ` [PATCH net-next 3/6] r8152: change some definitions Hayes Wang
2013-12-27 18:57   ` Francois Romieu
2013-12-27  2:34 ` [PATCH net-next 4/6] r8152: add rtl_ops Hayes Wang
2013-12-27 17:28   ` David Miller
2013-12-27  2:34 ` [PATCH net-next 5/6] r8152: split rtl8152_enable Hayes Wang
2013-12-27  2:37 ` [PATCH net-next 6/6] r8152: support RTL8153 Hayes Wang
2013-12-27 19:08   ` Francois Romieu
2014-01-02  3:22 ` [PATCH net-next v2 0/6] support new chip Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 1/6] r8152: move rtl8152_unload and ocp_reg_write Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 2/6] r8152: modify the method of accessing PHY Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 3/6] r8152: change some definitions Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 4/6] r8152: add rtl_ops Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 5/6] r8152: split rtl8152_enable Hayes Wang
2014-01-02  3:25   ` [PATCH net-next v2 6/6] r8152: support RTL8153 Hayes Wang
2014-01-02 14:25     ` Bjørn Mork
2014-01-03  2:56       ` hayeswang
2014-01-03  7:49         ` Bjørn Mork
2014-01-06  3:20           ` hayeswang
2014-01-06  9:21             ` Bjørn Mork
2014-01-07 12:35               ` hayeswang
     [not found]                 ` <749DBDC9792E47BBA5884BEC7CF2D639-Rasf1IRRPZGoECsaD+WFmw@public.gmane.org>
2014-01-08 18:24                   ` Ben Hutchings
     [not found]   ` <1388632963-1341-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-01-02  3:55     ` [PATCH net-next v2 0/6] support new chip David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388111649-1014-3-git-send-email-hayeswang@realtek.com \
    --to=hayeswang@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).