linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net: dsa: qca8k: Add additional PORT0_PAD_CTRL options
@ 2020-07-13 20:50 Matthew Hagan
  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 ` [PATCH 1/2] net: dsa: qca8k: Add additional PORT0_PAD_CTRL options Jakub Kicinski
  0 siblings, 2 replies; 20+ messages in thread
From: Matthew Hagan @ 2020-07-13 20:50 UTC (permalink / raw)
  Cc: Matthew Hagan, Andrew Lunn, Vivien Didelot, Florian Fainelli,
	David S. Miller, Jakub Kicinski, linux, netdev, linux-kernel,
	John Crispin, Jonathan McDowell

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


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-07-21  1:59 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 20:50 [PATCH 1/2] net: dsa: qca8k: Add additional PORT0_PAD_CTRL options Matthew Hagan
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

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).