public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Amit Singh Tomar <amittomer25@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v1 3/7] net: phy: realtek: Introduce PHY_RTL8201F_S700_RMII_TIMINGS to adjust rx/tx timings
Date: Sat,  9 May 2020 19:55:11 +0530	[thread overview]
Message-ID: <1589034315-19722-4-git-send-email-amittomer25@gmail.com> (raw)
In-Reply-To: <1589034315-19722-1-git-send-email-amittomer25@gmail.com>

RTL8201F PHY module found on Actions Semi Cubieboard7 seems to have
specific Rx/Tx interface timings requirement for proper PHY operations.
These timing values are not documented anywhere and picked from vendor
code.

This commits lets proper packets to be transmitted over the network.

Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
---
 drivers/net/phy/Kconfig   |  9 +++++++++
 drivers/net/phy/realtek.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index d1f049e62ab7..123c17c04458 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -235,6 +235,15 @@ config RTL8211F_PHY_FORCE_EEE_RXC_ON
 	  Default n, which means that the PHY state is not changed. To work
 	  around the issues, change this setting to y.
 
+config RTL8201F_PHY_S700_RMII_TIMINGS
+	bool "Ethernet PHY RTL8201F: adjust RMII Tx Interface timings"
+	depends on PHY_REALTEK
+	help
+	  This provides an option to configure specific timing requirements (needed
+	  for proper PHY operations) for the PHY module present on ACTION SEMI S700
+	  based cubieboard7. Exact timing requiremnets seems to be SoC specific
+	  (and it's undocumented) that comes from vendor code itself.
+
 config PHY_SMSC
 	bool  "Microchip(SMSC) Ethernet PHYs support"
 
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index b9c373bfe3cc..a549a106876f 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -13,6 +13,7 @@
 #define PHY_RTL8211x_FORCE_MASTER BIT(1)
 #define PHY_RTL8211E_PINE64_GIGABIT_FIX BIT(2)
 #define PHY_RTL8211F_FORCE_EEE_RXC_ON BIT(3)
+#define PHY_RTL8201F_S700_RMII_TIMINGS BIT(4)
 
 #define PHY_AUTONEGOTIATE_TIMEOUT 5000
 
@@ -58,6 +59,15 @@
 #define MIIM_RTL8211F_TX_DELAY		0x100
 #define MIIM_RTL8211F_LCR		0x10
 
+#define RTL8201F_RMSR			0x10
+
+#define RMSR_RX_TIMING_SHIFT		BIT(2)
+#define RMSR_RX_TIMING_MASK		GENMASK(7, 4)
+#define RMSR_RX_TIMING_VAL		0x4
+#define RMSR_TX_TIMING_SHIFT		BIT(3)
+#define RMSR_TX_TIMING_MASK		GENMASK(11, 8)
+#define RMSR_TX_TIMING_VAL		0x5
+
 static int rtl8211f_phy_extread(struct phy_device *phydev, int addr,
 				int devaddr, int regnum)
 {
@@ -112,6 +122,15 @@ static int rtl8211f_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static int rtl8210f_probe(struct phy_device *phydev)
+{
+#ifdef CONFIG_RTL8201F_PHY_S700_RMII_TIMINGS
+	phydev->flags |= PHY_RTL8201F_S700_RMII_TIMINGS;
+#endif
+
+	return 0;
+}
+
 /* RealTek RTL8211x */
 static int rtl8211x_config(struct phy_device *phydev)
 {
@@ -160,6 +179,21 @@ static int rtl8211x_config(struct phy_device *phydev)
 /* RealTek RTL8201F */
 static int rtl8201f_config(struct phy_device *phydev)
 {
+	unsigned int reg;
+
+	if (phydev->flags & PHY_RTL8201F_S700_RMII_TIMINGS) {
+		phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT,
+			  7);
+		reg = phy_read(phydev, MDIO_DEVAD_NONE, RTL8201F_RMSR);
+		reg &= ~(RMSR_RX_TIMING_MASK | RMSR_TX_TIMING_MASK);
+		/* Set the needed Rx/Tx Timings for proper PHY operation */
+		reg |= (RMSR_RX_TIMING_VAL << RMSR_RX_TIMING_SHIFT)
+		       | (RMSR_TX_TIMING_VAL << RMSR_TX_TIMING_SHIFT);
+		phy_write(phydev, MDIO_DEVAD_NONE, RTL8201F_RMSR, reg);
+		phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT,
+			  0);
+	}
+
 	genphy_config_aneg(phydev);
 
 	return 0;
@@ -400,6 +434,7 @@ static struct phy_driver RTL8201F_driver = {
 	.uid = 0x1cc816,
 	.mask = 0xffffff,
 	.features = PHY_BASIC_FEATURES,
+	.probe = &rtl8210f_probe,
 	.config = &rtl8201f_config,
 	.startup = &rtl8211e_startup,
 	.shutdown = &genphy_shutdown,
-- 
2.7.4

  parent reply	other threads:[~2020-05-09 14:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 14:25 [PATCH v1 0/7] add Ethernet support for S700 Amit Singh Tomar
2020-05-09 14:25 ` [PATCH v1 1/7] clk: actions: Add Ethernet clocks Amit Singh Tomar
2020-07-08  3:02   ` Tom Rini
2020-05-09 14:25 ` [PATCH v1 2/7] net: phy: realtek: Add support for RTL8201F PHY module Amit Singh Tomar
2020-07-08  3:02   ` Tom Rini
2020-05-09 14:25 ` Amit Singh Tomar [this message]
2020-07-08  3:02   ` [PATCH v1 3/7] net: phy: realtek: Introduce PHY_RTL8201F_S700_RMII_TIMINGS to adjust rx/tx timings Tom Rini
2020-05-09 14:25 ` [PATCH v1 4/7] net: designware: s700: Add glue code for S700 mac Amit Singh Tomar
2020-07-08  3:03   ` Tom Rini
2020-05-09 14:25 ` [PATCH v1 5/7] arm: dts: s700: add node for ethernet controller Amit Singh Tomar
2020-05-12 14:18   ` André Przywara
2020-05-12 14:25     ` Tom Rini
2020-05-12 14:42       ` Amit Tomer
2020-05-12 14:53         ` Tom Rini
2020-05-12 14:53       ` André Przywara
2020-05-12 15:09         ` Tom Rini
2020-05-12 16:14           ` Amit Tomer
2020-05-12 16:39           ` André Przywara
2020-05-12 19:59             ` Tom Rini
2020-05-12 14:37     ` Amit Tomer
2020-05-12 14:56       ` André Przywara
2020-07-08  3:03   ` Tom Rini
2020-05-09 14:25 ` [PATCH v1 6/7] owl: Kconfig: Enable DM eth for OWL platform Amit Singh Tomar
2020-07-08  3:03   ` Tom Rini
2020-05-09 14:25 ` [PATCH v1 7/7] configs: Enable mac and phy configs Amit Singh Tomar
2020-07-08  3:03   ` Tom Rini

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=1589034315-19722-4-git-send-email-amittomer25@gmail.com \
    --to=amittomer25@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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