Skip to content

Commit 0ba83aa

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: the PTP_CLK extts input reacts on both edges
It looks like the sja1105 external timestamping input is not as generic as we thought. When fed a signal with 50% duty cycle, it will timestamp both the rising and the falling edge. When fed a short pulse signal, only the timestamp of the falling edge will be seen in the PTPSYNCTS register, because that of the rising edge had been overwritten. So the moral is: don't feed it short pulse inputs. Luckily this is not a complete deal breaker, as we can still work with 1 Hz square waves. But the problem is that the extts polling period was not dimensioned enough for this input signal. If we leave the period at half a second, we risk losing timestamps due to jitter in the measuring process. So we need to increase it to 4 times per second. Also, the very least we can do to inform the user is to deny any other flags combination than with PTP_RISING_EDGE and PTP_FALLING_EDGE both set. Fixes: 747e5eb ("net: dsa: sja1105: configure the PTP_CLK pin as EXT_TS or PER_OUT") Signed-off-by: Vladimir Oltean <[email protected]> Acked-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a847241 commit 0ba83aa

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

drivers/net/dsa/sja1105/sja1105_ptp.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
/* PTPSYNCTS has no interrupt or update mechanism, because the intended
1818
* hardware use case is for the timestamp to be collected synchronously,
19-
* immediately after the CAS_MASTER SJA1105 switch has triggered a CASSYNC
20-
* pulse on the PTP_CLK pin. When used as a generic extts source, it needs
21-
* polling and a comparison with the old value. The polling interval is just
22-
* the Nyquist rate of a canonical PPS input (e.g. from a GPS module).
23-
* Anything of higher frequency than 1 Hz will be lost, since there is no
24-
* timestamp FIFO.
19+
* immediately after the CAS_MASTER SJA1105 switch has performed a CASSYNC
20+
* one-shot toggle (no return to level) on the PTP_CLK pin. When used as a
21+
* generic extts source, the PTPSYNCTS register needs polling and a comparison
22+
* with the old value. The polling interval is configured as the Nyquist rate
23+
* of a signal with 50% duty cycle and 1Hz frequency, which is sadly all that
24+
* this hardware can do (but may be enough for some setups). Anything of higher
25+
* frequency than 1 Hz will be lost, since there is no timestamp FIFO.
2526
*/
26-
#define SJA1105_EXTTS_INTERVAL (HZ / 2)
27+
#define SJA1105_EXTTS_INTERVAL (HZ / 4)
2728

2829
/* This range is actually +/- SJA1105_MAX_ADJ_PPB
2930
* divided by 1000 (ppb -> ppm) and with a 16-bit
@@ -754,7 +755,16 @@ static int sja1105_extts_enable(struct sja1105_private *priv,
754755
return -EOPNOTSUPP;
755756

756757
/* Reject requests with unsupported flags */
757-
if (extts->flags)
758+
if (extts->flags & ~(PTP_ENABLE_FEATURE |
759+
PTP_RISING_EDGE |
760+
PTP_FALLING_EDGE |
761+
PTP_STRICT_FLAGS))
762+
return -EOPNOTSUPP;
763+
764+
/* We can only enable time stamping on both edges, sadly. */
765+
if ((extts->flags & PTP_STRICT_FLAGS) &&
766+
(extts->flags & PTP_ENABLE_FEATURE) &&
767+
(extts->flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
758768
return -EOPNOTSUPP;
759769

760770
rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);

0 commit comments

Comments
 (0)