netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Hagan <mnhagan88@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Matthew Hagan <mnhagan88@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	linux@armlinux.org.uk, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, John Crispin <john@phrozen.org>,
	Jonathan McDowell <noodles@earth.li>
Subject: [PATCH 1/2] net: dsa: qca8k: Add additional PORT0_PAD_CTRL options
Date: Mon, 13 Jul 2020 21:50:25 +0100	[thread overview]
Message-ID: <2e1776f997441792a44cd35a16f1e69f848816ce.1594668793.git.mnhagan88@gmail.com> (raw)

A number of devices require additional PORT0_PAD configuration that cannot
otherwise be inferred. This patch is based on John Crispin's "net: dsa:
qca8k: allow swapping of mac0 and mac6", adding the ability to swap mac0
and mac6, as well as to set the transmit and receive clock phase to falling
edge.

To keep things tidy, a function has been added to handle these device tree
properties. However this handling could be moved to the
qca8k_phylink_mac_config function if preferred.

Signed-off-by: Matthew Hagan <mnhagan88@gmail.com>
---
 drivers/net/dsa/qca8k.c | 42 +++++++++++++++++++++++++++++++++++------
 drivers/net/dsa/qca8k.h |  3 +++
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 4acad5fa0c84..1443f97dd348 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -587,6 +587,28 @@ qca8k_setup_mdio_bus(struct qca8k_priv *priv)
 	return 0;
 }
 
+static void
+qca8k_setup_port_pad_ctrl_reg(struct qca8k_priv *priv)
+{
+	u32 val = qca8k_read(priv, QCA8K_REG_PORT0_PAD_CTRL);
+
+	/* Swap MAC0-MAC6 */
+	if (of_property_read_bool(priv->dev->of_node,
+				  "qca,exchange-mac0-mac6"))
+		val |= QCA8K_PORT0_PAD_CTRL_MAC06_EXCHG;
+
+	/* SGMII Clock phase configuration */
+	if (of_property_read_bool(priv->dev->of_node,
+				  "qca,sgmii-rxclk-falling-edge"))
+		val |= QCA8K_PORT0_PAD_SGMII_RXCLK_FALLING_EDGE;
+
+	if (of_property_read_bool(priv->dev->of_node,
+				  "qca,sgmii-txclk-falling-edge"))
+		val |= QCA8K_PORT0_PAD_SGMII_TXCLK_FALLING_EDGE;
+
+	qca8k_write(priv, QCA8K_REG_PORT0_PAD_CTRL, val);
+}
+
 static int
 qca8k_setup(struct dsa_switch *ds)
 {
@@ -611,6 +633,9 @@ qca8k_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
+	/* Configure additional port pad properties */
+	qca8k_setup_port_pad_ctrl_reg(priv);
+
 	/* Enable CPU Port */
 	qca8k_reg_set(priv, QCA8K_REG_GLOBAL_FW_CTRL0,
 		      QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN);
@@ -722,27 +747,32 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
 		return;
 	}
 
+	/* Read port pad ctrl reg */
+	val = qca8k_read(priv, reg);
+
 	switch (state->interface) {
 	case PHY_INTERFACE_MODE_RGMII:
 		/* RGMII mode means no delay so don't enable the delay */
-		qca8k_write(priv, reg, QCA8K_PORT_PAD_RGMII_EN);
+		val |= QCA8K_PORT_PAD_RGMII_EN;
+		qca8k_write(priv, reg, val);
 		break;
 	case PHY_INTERFACE_MODE_RGMII_ID:
 		/* RGMII_ID needs internal delay. This is enabled through
 		 * PORT5_PAD_CTRL for all ports, rather than individual port
 		 * registers
 		 */
-		qca8k_write(priv, reg,
-			    QCA8K_PORT_PAD_RGMII_EN |
-			    QCA8K_PORT_PAD_RGMII_TX_DELAY(QCA8K_MAX_DELAY) |
-			    QCA8K_PORT_PAD_RGMII_RX_DELAY(QCA8K_MAX_DELAY));
+		val |= QCA8K_PORT_PAD_RGMII_EN |
+		       QCA8K_PORT_PAD_RGMII_TX_DELAY(QCA8K_MAX_DELAY) |
+		       QCA8K_PORT_PAD_RGMII_RX_DELAY(QCA8K_MAX_DELAY);
+		qca8k_write(priv, reg, val);
 		qca8k_write(priv, QCA8K_REG_PORT5_PAD_CTRL,
 			    QCA8K_PORT_PAD_RGMII_RX_DELAY_EN);
 		break;
 	case PHY_INTERFACE_MODE_SGMII:
 	case PHY_INTERFACE_MODE_1000BASEX:
 		/* Enable SGMII on the port */
-		qca8k_write(priv, reg, QCA8K_PORT_PAD_SGMII_EN);
+		val |= QCA8K_PORT_PAD_SGMII_EN;
+		qca8k_write(priv, reg, val);
 
 		/* Enable/disable SerDes auto-negotiation as necessary */
 		val = qca8k_read(priv, QCA8K_REG_PWS);
diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
index 10ef2bca2cde..4e115557e571 100644
--- a/drivers/net/dsa/qca8k.h
+++ b/drivers/net/dsa/qca8k.h
@@ -26,6 +26,9 @@
 #define   QCA8K_MASK_CTRL_ID_M				0xff
 #define   QCA8K_MASK_CTRL_ID_S				8
 #define QCA8K_REG_PORT0_PAD_CTRL			0x004
+#define   QCA8K_PORT0_PAD_CTRL_MAC06_EXCHG		BIT(31)
+#define   QCA8K_PORT0_PAD_SGMII_RXCLK_FALLING_EDGE	BIT(19)
+#define   QCA8K_PORT0_PAD_SGMII_TXCLK_FALLING_EDGE	BIT(18)
 #define QCA8K_REG_PORT5_PAD_CTRL			0x008
 #define QCA8K_REG_PORT6_PAD_CTRL			0x00c
 #define   QCA8K_PORT_PAD_RGMII_EN			BIT(26)
-- 
2.25.4


             reply	other threads:[~2020-07-13 20:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 20:50 Matthew Hagan [this message]
2020-07-13 20:50 ` [PATCH 2/2] dt-bindings: net: dsa: qca8k: Add PORT0_PAD_CTRL properties Matthew Hagan
2020-07-16 22:09   ` Jakub Kicinski
2020-07-16 22:32     ` Andrew Lunn
2020-07-17 19:26       ` Matthew Hagan
2020-07-17 20:02         ` Florian Fainelli
2020-07-18 13:00         ` Vladimir Oltean
2020-07-21  1:59         ` Rob Herring
2020-07-16 22:38     ` Vladimir Oltean
2020-07-17  7:49       ` Jonathan McDowell
2020-07-17 20:29     ` Matthew Hagan
2020-07-17 20:39       ` Florian Fainelli
2020-07-17 20:48         ` John Crispin
2020-07-17 20:44       ` John Crispin
2020-07-18 13:20         ` Russell King - ARM Linux admin
2020-07-18 14:44           ` Andrew Lunn
2020-07-18 15:08             ` Russell King - ARM Linux admin
2020-07-18 15:34           ` Matthew Hagan
2020-07-16 22:19   ` Florian Fainelli
2020-07-16 22:09 ` [PATCH 1/2] net: dsa: qca8k: Add additional PORT0_PAD_CTRL options Jakub Kicinski

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=2e1776f997441792a44cd35a16f1e69f848816ce.1594668793.git.mnhagan88@gmail.com \
    --to=mnhagan88@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=john@phrozen.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=noodles@earth.li \
    --cc=vivien.didelot@gmail.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).