Skip to contentSkip to conversation

External trigger stamp fifo support for ptp_qoriq

PATCH Superseded Yangbo Lu 2 participants 11 messages Jan 17, 2019 – Jan 18, 2019

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yangbo Lu

author maintainer
#0 lore raw

v2 cover External trigger stamp fifo support for ptp_qoriq

This patch-set is to add external trigger stamp fifo support by a new binding "fsl,extts-fifo", and to add fiper pulse loopback support which is very useful for validating trigger without external hardware. Also fixed issues in interrupt enabling/handling.

"fsl,extts-fifo" is required to be added into 1588 timer dts node whose hardware uses it. The work will be done for some QorIQ platforms dts in the near future.

Yangbo Lu (5):
ptp_qoriq: fix interrupt enabling and handling
ptp_qoriq: support external trigger stamp FIFO
dt-binding: ptp_qoriq: document "fsl,extts-fifo" property
ARM: dts: ls1021a: add 1588 external trigger stamp fifo support
ptp_qoriq: add fiper pulse loopback support

 .../devicetree/bindings/ptp/ptp-qoriq.txt          |    1 +
 arch/arm/boot/dts/ls1021a.dtsi                     |    1 +
 drivers/ptp/Kconfig                                |   18 +++
 drivers/ptp/ptp_qoriq.c                            |  133 +++++++++++++-------
 include/linux/fsl/ptp_qoriq.h                      |    3 +
 5 files changed, 112 insertions(+), 44 deletions(-)
author maintainer
#1 lore raw

PATCH v2 1/5 ptp_qoriq: fix interrupt enabling and handling

The tmr_tevent register would update event bits no matter tmr_temask bits were set or not. So we should get interrupts by tmr_tevent & tmr_temask, and clean up interrupts in tmr_tevent before enabling them.

---
Changes for v2:
- Remove useless lock/register operations.

---
 drivers/ptp/ptp_qoriq.c |   62 +++++++++++++++++++++++-----------------------
 1 files changed, 31 insertions(+), 31 deletions(-)
drivers/ptp/ptp_qoriq.c +31 -31
index fdd49c2..2743214 100644
@@ -98,11 +98,18 @@ static irqreturn_t isr(int irq, void *priv)
 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
 	struct ptp_clock_event event;
 	u64 ns;
-	u32 ack = 0, lo, hi, mask, val;
+	u32 ack = 0, lo, hi, mask, val, irqs;
+
+	spin_lock(&qoriq_ptp->lock);
 
 	val = qoriq_read(&regs->ctrl_regs->tmr_tevent);
+	mask = qoriq_read(&regs->ctrl_regs->tmr_temask);
+
+	spin_unlock(&qoriq_ptp->lock);
+
+	irqs = val & mask;
 
-	if (val & ETS1) {
+	if (irqs & ETS1) {
 		ack |= ETS1;
 		hi = qoriq_read(&regs->etts_regs->tmr_etts1_h);
 		lo = qoriq_read(&regs->etts_regs->tmr_etts1_l);
@@ -113,7 +120,7 @@ static irqreturn_t isr(int irq, void *priv)
 		ptp_clock_event(qoriq_ptp->clock, &event);
 	}
 
-	if (val & ETS2) {
+	if (irqs & ETS2) {
 		ack |= ETS2;
 		hi = qoriq_read(&regs->etts_regs->tmr_etts2_h);
 		lo = qoriq_read(&regs->etts_regs->tmr_etts2_l);
@@ -124,7 +131,7 @@ static irqreturn_t isr(int irq, void *priv)
 		ptp_clock_event(qoriq_ptp->clock, &event);
 	}
 
-	if (val & ALM2) {
+	if (irqs & ALM2) {
 		ack |= ALM2;
 		if (qoriq_ptp->alarm_value) {
 			event.type = PTP_CLOCK_ALARM;
@@ -136,13 +143,10 @@ static irqreturn_t isr(int irq, void *priv)
 			ns = qoriq_ptp->alarm_value + qoriq_ptp->alarm_interval;
 			hi = ns >> 32;
 			lo = ns & 0xffffffff;
-			spin_lock(&qoriq_ptp->lock);
 			qoriq_write(&regs->alarm_regs->tmr_alarm2_l, lo);
 			qoriq_write(&regs->alarm_regs->tmr_alarm2_h, hi);
-			spin_unlock(&qoriq_ptp->lock);
 			qoriq_ptp->alarm_value = ns;
 		} else {
-			qoriq_write(&regs->ctrl_regs->tmr_tevent, ALM2);
 			spin_lock(&qoriq_ptp->lock);
 			mask = qoriq_read(&regs->ctrl_regs->tmr_temask);
 			mask &= ~ALM2EN;
@@ -153,7 +157,7 @@ static irqreturn_t isr(int irq, void *priv)
 		}
 	}
 
-	if (val & PP1) {
+	if (irqs & PP1) {
 		ack |= PP1;
 		event.type = PTP_CLOCK_PPS;
 		ptp_clock_event(qoriq_ptp->clock, &event);
@@ -260,7 +264,7 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp,
 	struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps);
 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
 	unsigned long flags;
-	u32 bit, mask;
+	u32 bit, mask = 0;
 
 	switch (rq->type) {
 	case PTP_CLK_REQ_EXTTS:
@@ -274,32 +278,28 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp,
 		default:
 			return -EINVAL;
 		}
-		spin_lock_irqsave(&qoriq_ptp->lock, flags);
-		mask = qoriq_read(&regs->ctrl_regs->tmr_temask);
-		if (on)
-			mask |= bit;
-		else
-			mask &= ~bit;
-		qoriq_write(&regs->ctrl_regs->tmr_temask, mask);
-		spin_unlock_irqrestore(&qoriq_ptp->lock, flags);
-		return 0;
-
+		break;
 	case PTP_CLK_REQ_PPS:
-		spin_lock_irqsave(&qoriq_ptp->lock, flags);
-		mask = qoriq_read(&regs->ctrl_regs->tmr_temask);
-		if (on)
-			mask |= PP1EN;
-		else
-			mask &= ~PP1EN;
-		qoriq_write(&regs->ctrl_regs->tmr_temask, mask);
-		spin_unlock_irqrestore(&qoriq_ptp->lock, flags);
-		return 0;
-
-	default:
+		bit = PP1EN;
 		break;
+	default:
+		return -EOPNOTSUPP;
 	}
 
-	return -EOPNOTSUPP;
+	spin_lock_irqsave(&qoriq_ptp->lock, flags);
+
+	mask = qoriq_read(&regs->ctrl_regs->tmr_temask);
+	if (on) {
+		mask |= bit;
+		qoriq_write(&regs->ctrl_regs->tmr_tevent, bit);
+	} else {
+		mask &= ~bit;
+	}
+
+	qoriq_write(&regs->ctrl_regs->tmr_temask, mask);
+
+	spin_unlock_irqrestore(&qoriq_ptp->lock, flags);
+	return 0;
 }
 
 static const struct ptp_clock_info ptp_qoriq_caps = {
Signature · 1 line
1.7.1
author maintainer
#2 lore raw

PATCH v2 2/5 ptp_qoriq: support external trigger stamp FIFO

In reply to Yangbo Lu

The external trigger stamp FIFO was introduced as a new feature for QorIQ 1588 timer IP block. This patch is to support it by adding a new dts property "fsl,extts-fifo". Any QorIQ 1588 timer supporting this feature is required to add this property in its dts node.

In addition, the FIFO should be cleaned up before enabling external trigger interrupts. Otherwise, there will be interrupts immediately just after enabling external trigger interrupts.

---
Changes for v2:
- Converted to use extts_clean_up instead.

---
 drivers/ptp/ptp_qoriq.c       |   68 ++++++++++++++++++++++++++++++++--------
 include/linux/fsl/ptp_qoriq.h |    3 ++
 2 files changed, 57 insertions(+), 14 deletions(-)
drivers/ptp/ptp_qoriq.c +54 -14
index 2743214..a2e7702 100644
@@ -88,6 +88,49 @@ static void set_fipers(struct qoriq_ptp *qoriq_ptp)
 	qoriq_write(&regs->fiper_regs->tmr_fiper2, qoriq_ptp->tmr_fiper2);
 }
 
+static int extts_clean_up(struct qoriq_ptp *qoriq_ptp, int index,
+			  bool update_event)
+{
+	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
+	struct ptp_clock_event event;
+	void __iomem *reg_etts_l;
+	void __iomem *reg_etts_h;
+	u32 valid, stat, lo, hi;
+
+	switch (index) {
+	case 0:
+		valid = ETS1_VLD;
+		reg_etts_l = &regs->etts_regs->tmr_etts1_l;
+		reg_etts_h = &regs->etts_regs->tmr_etts1_h;
+		break;
+	case 1:
+		valid = ETS2_VLD;
+		reg_etts_l = &regs->etts_regs->tmr_etts2_l;
+		reg_etts_h = &regs->etts_regs->tmr_etts2_h;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	event.type = PTP_CLOCK_EXTTS;
+	event.index = index;
+
+	do {
+		lo = qoriq_read(reg_etts_l);
+		hi = qoriq_read(reg_etts_h);
+
+		if (update_event) {
+			event.timestamp = ((u64) hi) << 32;
+			event.timestamp |= lo;
+			ptp_clock_event(qoriq_ptp->clock, &event);
+		}
+
+		stat = qoriq_read(&regs->ctrl_regs->tmr_stat);
+	} while (qoriq_ptp->extts_fifo_support && (stat & valid));
+
+	return 0;
+}
+
 /*
  * Interrupt service routine
  */
@@ -111,24 +154,12 @@ static irqreturn_t isr(int irq, void *priv)
 
 	if (irqs & ETS1) {
 		ack |= ETS1;
-		hi = qoriq_read(&regs->etts_regs->tmr_etts1_h);
-		lo = qoriq_read(&regs->etts_regs->tmr_etts1_l);
-		event.type = PTP_CLOCK_EXTTS;
-		event.index = 0;
-		event.timestamp = ((u64) hi) << 32;
-		event.timestamp |= lo;
-		ptp_clock_event(qoriq_ptp->clock, &event);
+		extts_clean_up(qoriq_ptp, 0, true);
 	}
 
 	if (irqs & ETS2) {
 		ack |= ETS2;
-		hi = qoriq_read(&regs->etts_regs->tmr_etts2_h);
-		lo = qoriq_read(&regs->etts_regs->tmr_etts2_l);
-		event.type = PTP_CLOCK_EXTTS;
-		event.index = 1;
-		event.timestamp = ((u64) hi) << 32;
-		event.timestamp |= lo;
-		ptp_clock_event(qoriq_ptp->clock, &event);
+		extts_clean_up(qoriq_ptp, 1, true);
 	}
 
 	if (irqs & ALM2) {
@@ -278,6 +309,10 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp,
 		default:
 			return -EINVAL;
 		}
+
+		if (on)
+			extts_clean_up(qoriq_ptp, rq->extts.index, false);
+
 		break;
 	case PTP_CLK_REQ_PPS:
 		bit = PP1EN;
@@ -441,6 +476,11 @@ static int qoriq_ptp_probe(struct platform_device *dev)
 	if (of_property_read_u32(node, "fsl,cksel", &qoriq_ptp->cksel))
 		qoriq_ptp->cksel = DEFAULT_CKSEL;
 
+	if (of_property_read_bool(node, "fsl,extts-fifo"))
+		qoriq_ptp->extts_fifo_support = true;
+	else
+		qoriq_ptp->extts_fifo_support = false;
+
 	if (of_property_read_u32(node,
 				 "fsl,tclk-period", &qoriq_ptp->tclk_period) ||
 	    of_property_read_u32(node,
include/linux/fsl/ptp_qoriq.h +3 -0
index c1f003a..43b4b44 100644
@@ -120,6 +120,8 @@ struct qoriq_ptp_registers {
 /* Bit definitions for the TMR_STAT register */
 #define STAT_VEC_SHIFT        (0) /* Timer general purpose status vector */
 #define STAT_VEC_MASK         (0x3f)
+#define ETS1_VLD              (1<<24)
+#define ETS2_VLD              (1<<25)
 
 /* Bit definitions for the TMR_PRSC register */
 #define PRSC_OCK_SHIFT        (0) /* Output clock division/prescale factor. */
@@ -141,6 +143,7 @@ struct qoriq_ptp {
 	struct ptp_clock *clock;
 	struct ptp_clock_info caps;
 	struct resource *rsrc;
+	bool extts_fifo_support;
 	int irq;
 	int phc_index;
 	u64 alarm_interval; /* for periodic alarm */
Signature · 1 line
1.7.1
author maintainer
#3 lore raw

PATCH v2 3/5 dt-binding: ptp_qoriq: document "fsl,extts-fifo" property

In reply to Yangbo Lu

Documented "fsl,extts-fifo" property.

---
Changes for v2:
- Modified binding description.

---
 .../devicetree/bindings/ptp/ptp-qoriq.txt          |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +1 -0
index c5d0e79..101fe5f 100644
@@ -17,6 +17,7 @@ Clock Properties:
   - fsl,tmr-fiper1   Fixed interval period pulse generator.
   - fsl,tmr-fiper2   Fixed interval period pulse generator.
   - fsl,max-adj      Maximum frequency adjustment in parts per billion.
+  - fsl,extts-fifo   Required if hardware uses external trigger stamp FIFO.
 
   These properties set the operational parameters for the PTP
   clock. You must choose these carefully for the clock to work right.
Signature · 1 line
1.7.1
maintainer
#4 lore raw

Re: [v2, 3/5] dt-binding: ptp_qoriq: document "fsl,extts-fifo" property

Quoted 15 lines · Yangbo Lu

Documented "fsl,extts-fifo" property.

---
Changes for v2:
- Modified binding description.

---
 .../devicetree/bindings/ptp/ptp-qoriq.txt          |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +0 -0
index c5d0e79..101fe5f 100644

Documentation/devicetree/bindings/ptp/ptp-qoriq.txt Clock Properties: · line 20

Quoted 4 lines
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +1 -0
@@ -17,6 +17,7 @@ Clock Properties:
   - fsl,tmr-fiper1   Fixed interval period pulse generator.
   - fsl,tmr-fiper2   Fixed interval period pulse generator.
   - fsl,max-adj      Maximum frequency adjustment in parts per billion.
+  - fsl,extts-fifo   Required if hardware uses external trigger stamp FIFO.

Does this take a Boolean value? Please explain the semantics.

Thanks,
Richard

maintainer
#5 lore raw

Re: [v2, 3/5] dt-binding: ptp_qoriq: document "fsl,extts-fifo" property

Quoted 7 lines · Richard Cochran

Documentation/devicetree/bindings/ptp/ptp-qoriq.txt Clock Properties: · line 20

Quoted 5 lines
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +1 -0
@@ -17,6 +17,7 @@ Clock Properties:
   - fsl,tmr-fiper1   Fixed interval period pulse generator.
   - fsl,tmr-fiper2   Fixed interval period pulse generator.
   - fsl,max-adj      Maximum frequency adjustment in parts per billion.
+  - fsl,extts-fifo   Required if hardware uses external trigger stamp FIFO.

Does this take a Boolean value? Please explain the semantics.

How about this instead?

The presence of this property indicates hardware support for the external trigger stamp FIFO.

Thanks,
Richard

author maintainer
#6 lore raw

RE: [v2, 3/5] dt-binding: ptp_qoriq: document "fsl,extts-fifo" property

Hi,

Quoted 18 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Friday, January 18, 2019 9:39 AM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; David S . Miller <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>
Subject: Re: [v2, 3/5] dt-binding: ptp_qoriq: document "fsl,extts-fifo" property

Quoted 7 lines · Richard Cochran

Documentation/devicetree/bindings/ptp/ptp-qoriq.txt Clock Properties: · line 20

Quoted 5 lines
Documentation/devicetree/bindings/ptp/ptp-qoriq.txt +1 -0
@@ -17,6 +17,7 @@ Clock Properties:
   - fsl,tmr-fiper1   Fixed interval period pulse generator.
   - fsl,tmr-fiper2   Fixed interval period pulse generator.
   - fsl,max-adj      Maximum frequency adjustment in parts per billion.
+  - fsl,extts-fifo   Required if hardware uses external trigger stamp FIFO.

Does this take a Boolean value? Please explain the semantics.

Quoted 4 lines

How about this instead?

The presence of this property indicates hardware support for the external trigger stamp FIFO.

[Y.b. Lu] Yes. This is a Boolean value.
Thanks for good suggestion and I will use this instead.

Quoted 4 lines

Thanks,
Richard

author maintainer
#7 lore raw

PATCH v2 4/5 ARM: dts: ls1021a: add 1588 external trigger stamp fifo support

In reply to Yangbo Lu

This patch is to add external trigger stamp fifo support for 1588 timer.

---
Changes for v2:
- None.

---
 arch/arm/boot/dts/ls1021a.dtsi |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/boot/dts/ls1021a.dtsi +1 -0
index bdd6e66..0fbeca2 100644
@@ -608,6 +608,7 @@
 			fsl,tmr-fiper1  = <999999995>;
 			fsl,tmr-fiper2  = <99990>;
 			fsl,max-adj     = <499999999>;
+			fsl,extts-fifo;
 		};
 
 		enet0: ethernet@2d10000 {
Signature · 1 line
1.7.1
author maintainer
#8 lore raw

PATCH v2 5/5 ptp_qoriq: add fiper pulse loopback support

In reply to Yangbo Lu

This patch is to add Kconfig options to support fiper pulse loopback mode. This is very useful for validating hardware and driver without external hardware.

---
Changes for v2:
- None.

---
 drivers/ptp/Kconfig     |   18 ++++++++++++++++++
 drivers/ptp/ptp_qoriq.c |    7 ++++++-
 2 files changed, 24 insertions(+), 1 deletions(-)
drivers/ptp/Kconfig +18 -0
index d137c48..561d797 100644
@@ -55,6 +55,24 @@ config PTP_1588_CLOCK_QORIQ
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_qoriq.
 
+config PTP_1588_CLOCK_QORIQ_FIPER1_LOOPBACK
+	bool "Fiper1 pulse loopback"
+	depends on PTP_1588_CLOCK_QORIQ
+	default n
+	help
+	  Enable fiper1 pulse loopback mode. If choose y, fiper1 pulse is
+	  looped back into trigger1 input. In default, trigger1 input is
+	  based upon normal external trigger input.
+
+config PTP_1588_CLOCK_QORIQ_FIPER2_LOOPBACK
+	bool "Fiper2 pulse loopback"
+	depends on PTP_1588_CLOCK_QORIQ
+	default n
+	help
+	  Enable fiper2 pulse loopback mode. If choose y, fiper2 pulse is
+	  looped back into trigger2 input. In default, trigger2 input is
+	  based upon normal external trigger input.
+
 config PTP_1588_CLOCK_IXP46X
 	tristate "Intel IXP46x as PTP clock"
 	depends on IXP4XX_ETH
drivers/ptp/ptp_qoriq.c +6 -1
index a2e7702..5294475 100644
@@ -551,7 +551,12 @@ static int qoriq_ptp_probe(struct platform_device *dev)
 	tmr_ctrl =
 	  (qoriq_ptp->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT |
 	  (qoriq_ptp->cksel & CKSEL_MASK) << CKSEL_SHIFT;
-
+#ifdef CONFIG_PTP_1588_CLOCK_QORIQ_FIPER1_LOOPBACK
+	tmr_ctrl |= PP1L;
+#endif
+#ifdef CONFIG_PTP_1588_CLOCK_QORIQ_FIPER2_LOOPBACK
+	tmr_ctrl |= PP2L;
+#endif
 	spin_lock_irqsave(&qoriq_ptp->lock, flags);
 
 	regs = &qoriq_ptp->regs;
Signature · 1 line
1.7.1
maintainer
#9 lore raw

Re: [v2, 5/5] ptp_qoriq: add fiper pulse loopback support

Quoted 3 lines · Yangbo Lu

This patch is to add Kconfig options to support fiper pulse loopback mode. This is very useful for validating hardware and driver without external hardware.

To me this feature makes more sense as a debugf-fs option.

Thanks,
Richard

author maintainer
#10 lore raw

RE: [v2, 5/5] ptp_qoriq: add fiper pulse loopback support

Hi,

Quoted 9 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Friday, January 18, 2019 9:44 AM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; David S . Miller <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>
Subject: Re: [v2, 5/5] ptp_qoriq: add fiper pulse loopback support

Quoted 6 lines
Quoted 3 lines · Yangbo Lu

This patch is to add Kconfig options to support fiper pulse loopback mode. This is very useful for validating hardware and driver without external hardware.

To me this feature makes more sense as a debugf-fs option.

[Y.b. Lu] Let me try debug-fs and update the patch-set. Thanks for your suggestion.

Quoted 3 lines

Thanks,
Richard