netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Radu Pirea (NXP OSS)" <radu-nicolae.pirea@oss.nxp.com>
To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, richardcochran@gmail.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	sebastian.tobuschat@nxp.com,
	"Radu Pirea (NXP OSS)" <radu-nicolae.pirea@oss.nxp.com>
Subject: [PATCH net-next v1 08/14] net: phy: nxp-c45-tja11xx: enable LTC sampling on both ext_ts edges
Date: Fri, 16 Jun 2023 16:53:17 +0300	[thread overview]
Message-ID: <20230616135323.98215-9-radu-nicolae.pirea@oss.nxp.com> (raw)
In-Reply-To: <20230616135323.98215-1-radu-nicolae.pirea@oss.nxp.com>

The external trigger configuration for TJA1120 has changed. The PHY
supports sampling of the LTC on rising and on falling edge.

Signed-off-by: Radu Pirea (NXP OSS) <radu-nicolae.pirea@oss.nxp.com>
---
 drivers/net/phy/nxp-c45-tja11xx.c | 64 +++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c
index 2160b9f8940c..6aa738396daf 100644
--- a/drivers/net/phy/nxp-c45-tja11xx.c
+++ b/drivers/net/phy/nxp-c45-tja11xx.c
@@ -104,6 +104,10 @@
 #define VEND1_PTP_CONFIG		0x1102
 #define EXT_TRG_EDGE			BIT(1)
 
+#define TJA1120_SYNC_TRIG_FILTER	0x1010
+#define PTP_TRIG_RISE_TS		BIT(3)
+#define PTP_TRIG_FALLING_TS		BIT(2)
+
 #define CLK_RATE_ADJ_LD			BIT(15)
 #define CLK_RATE_ADJ_DIR		BIT(14)
 
@@ -240,6 +244,7 @@ struct nxp_c45_phy_data {
 	const struct nxp_c45_phy_stats *stats;
 	int n_stats;
 	u8 ptp_clk_period;
+	bool ext_ts_both_edges;
 	void (*counters_enable)(struct phy_device *phydev);
 	void (*ptp_init)(struct phy_device *phydev);
 	void (*ptp_enable)(struct phy_device *phydev, bool enable);
@@ -682,9 +687,52 @@ static int nxp_c45_perout_enable(struct nxp_c45_phy *priv,
 	return 0;
 }
 
+static void nxp_c45_set_rising_or_falling(struct phy_device *phydev,
+					  struct ptp_extts_request *extts)
+{
+	/* Some enable request has only the PTP_ENABLE_FEATURE flag set and in
+	 * this case external ts should be enabled on rising edge.
+	 */
+	if (extts->flags & PTP_RISING_EDGE ||
+	    extts->flags == PTP_ENABLE_FEATURE)
+		phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1,
+				   VEND1_PTP_CONFIG, EXT_TRG_EDGE);
+
+	if (extts->flags & PTP_FALLING_EDGE)
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 VEND1_PTP_CONFIG, EXT_TRG_EDGE);
+}
+
+static void nxp_c45_set_rising_and_falling(struct phy_device *phydev,
+					   struct ptp_extts_request *extts)
+{
+	/* Some enable request has only the PTP_ENABLE_FEATURE flag set and in
+	 * this case external ts should be enabled on rising edge.
+	 */
+	if (extts->flags & PTP_RISING_EDGE ||
+	    extts->flags == PTP_ENABLE_FEATURE)
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 TJA1120_SYNC_TRIG_FILTER,
+				 PTP_TRIG_RISE_TS);
+	else
+		phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1,
+				   TJA1120_SYNC_TRIG_FILTER,
+				   PTP_TRIG_RISE_TS);
+
+	if (extts->flags & PTP_FALLING_EDGE)
+		phy_set_bits_mmd(phydev, MDIO_MMD_VEND1,
+				 TJA1120_SYNC_TRIG_FILTER,
+				 PTP_TRIG_FALLING_TS);
+	else
+		phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1,
+				   TJA1120_SYNC_TRIG_FILTER,
+				   PTP_TRIG_FALLING_TS);
+}
+
 static int nxp_c45_extts_enable(struct nxp_c45_phy *priv,
 				struct ptp_extts_request *extts, int on)
 {
+	const struct nxp_c45_phy_data *data = nxp_c45_get_data(priv->phydev);
 	int pin;
 
 	if (extts->flags & ~(PTP_ENABLE_FEATURE |
@@ -695,7 +743,8 @@ static int nxp_c45_extts_enable(struct nxp_c45_phy *priv,
 
 	/* Sampling on both edges is not supported */
 	if ((extts->flags & PTP_RISING_EDGE) &&
-	    (extts->flags & PTP_FALLING_EDGE))
+	    (extts->flags & PTP_FALLING_EDGE) &&
+	    !data->ext_ts_both_edges)
 		return -EOPNOTSUPP;
 
 	pin = ptp_find_pin(priv->ptp_clock, PTP_PF_EXTTS, extts->index);
@@ -709,13 +758,10 @@ static int nxp_c45_extts_enable(struct nxp_c45_phy *priv,
 		return 0;
 	}
 
-	if (extts->flags & PTP_RISING_EDGE)
-		phy_clear_bits_mmd(priv->phydev, MDIO_MMD_VEND1,
-				   VEND1_PTP_CONFIG, EXT_TRG_EDGE);
-
-	if (extts->flags & PTP_FALLING_EDGE)
-		phy_set_bits_mmd(priv->phydev, MDIO_MMD_VEND1,
-				 VEND1_PTP_CONFIG, EXT_TRG_EDGE);
+	if (data->ext_ts_both_edges)
+		nxp_c45_set_rising_and_falling(priv->phydev, extts);
+	else
+		nxp_c45_set_rising_or_falling(priv->phydev, extts);
 
 	nxp_c45_gpio_config(priv, pin, GPIO_EXTTS_OUT_CFG);
 	priv->extts = true;
@@ -1551,6 +1597,7 @@ static const struct nxp_c45_phy_data tja1103_phy_data = {
 	.stats = tja1103_hw_stats,
 	.n_stats = ARRAY_SIZE(tja1103_hw_stats),
 	.ptp_clk_period = PTP_CLK_PERIOD_100BT1,
+	.ext_ts_both_edges = false,
 	.counters_enable = tja1103_counters_enable,
 	.ptp_init = tja1103_ptp_init,
 	.ptp_enable = tja1103_ptp_enable,
@@ -1646,6 +1693,7 @@ static const struct nxp_c45_phy_data tja1120_phy_data = {
 	.stats = tja1120_hw_stats,
 	.n_stats = ARRAY_SIZE(tja1120_hw_stats),
 	.ptp_clk_period = PTP_CLK_PERIOD_1000BT1,
+	.ext_ts_both_edges = true,
 	.counters_enable = tja1120_counters_enable,
 	.ptp_init = tja1120_ptp_init,
 	.ptp_enable = tja1120_ptp_enable,
-- 
2.34.1


  parent reply	other threads:[~2023-06-16 13:54 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 13:53 [PATCH net-next v1 00/14] Add TJA1120 support Radu Pirea (NXP OSS)
2023-06-16 13:53 ` [PATCH net-next v1 01/14] net: phy: nxp-c45-tja11xx: fix the PTP interrupt enablig/disabling Radu Pirea (NXP OSS)
2023-06-16 20:36   ` Andrew Lunn
2023-06-19  8:42     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 02/14] net: phy: nxp-c45-tja11xx: use phylib master/slave implementation Radu Pirea (NXP OSS)
2023-06-16 20:37   ` Andrew Lunn
2023-06-16 13:53 ` [PATCH net-next v1 03/14] net: phy: nxp-c45-tja11xx: remove RX BIST frame counters Radu Pirea (NXP OSS)
2023-06-16 20:39   ` Andrew Lunn
2023-06-22 12:21     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 04/14] net: phy: nxp-c45-tja11xx: add *_reg_field functions Radu Pirea (NXP OSS)
2023-06-16 20:42   ` Andrew Lunn
2023-06-16 13:53 ` [PATCH net-next v1 05/14] net: phy: nxp-c45-tja11xx: prepare the ground for TJA1120 Radu Pirea (NXP OSS)
2023-06-16 19:35   ` Simon Horman
2023-06-19  7:53   ` Horatiu Vultur
2023-06-16 13:53 ` [PATCH net-next v1 06/14] net: phy: add 1000baseT1 to phy_basic_t1_features Radu Pirea (NXP OSS)
2023-06-16 20:49   ` Andrew Lunn
2023-06-19 11:01     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 07/14] net: phy: nxp-c45-tja11xx: add TJA1120 support Radu Pirea (NXP OSS)
2023-06-16 13:53 ` Radu Pirea (NXP OSS) [this message]
2023-06-19  8:10   ` [PATCH net-next v1 08/14] net: phy: nxp-c45-tja11xx: enable LTC sampling on both ext_ts edges Horatiu Vultur
2023-06-19  8:36     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 09/14] net: phy: nxp-c45-tja11xx: read egress ts on TJA1120 Radu Pirea (NXP OSS)
2023-06-16 13:53 ` [PATCH net-next v1 10/14] net: phy: nxp-c45-tja11xx: handle FUSA irq Radu Pirea (NXP OSS)
2023-06-16 20:55   ` Andrew Lunn
2023-06-19  6:31     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 11/14] net: phy: nxp-c45-tja11xx: run cable test with the PHY in test mode Radu Pirea (NXP OSS)
2023-06-16 13:53 ` [PATCH net-next v1 12/14] net: phy: nxp-c45-tja11xx: read ext trig ts TJA1120 Radu Pirea (NXP OSS)
2023-06-19  8:49   ` Horatiu Vultur
2023-06-19 10:07     ` Radu Pirea (OSS)
2023-06-19 10:48       ` Horatiu Vultur
2023-06-20 14:31         ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 13/14] net: phy: nxp-c45-tja11xx: reset PCS if the link goes down Radu Pirea (NXP OSS)
2023-06-16 21:00   ` Andrew Lunn
2023-06-19  6:17     ` Radu Pirea (OSS)
2023-06-16 13:53 ` [PATCH net-next v1 14/14] net: phy: nxp-c45-tja11xx: timestamp reading workaround for TJA1120 Radu Pirea (NXP OSS)
2023-06-19  8:58   ` Horatiu Vultur
2023-06-19  9:46     ` Radu Pirea (OSS)

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=20230616135323.98215-9-radu-nicolae.pirea@oss.nxp.com \
    --to=radu-nicolae.pirea@oss.nxp.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=sebastian.tobuschat@nxp.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).