Skip to content

Commit 67ac836

Browse files
Wei Fangkuba-moo
authored andcommitted
ptp: netc: add the periodic output signal loopback support
The NETC Timer supports looping back the output pulse signal of Fiper-n into Trigger-n input, so that users can leverage this feature to validate some other features without external hardware support. For example, users can use it to test external trigger stamp (EXTTS). And users can combine EXTTS with loopback mode to check whether the generation time of PPS is aligned with an integral second of PHC, or the periodic output signal (PTP_CLK_REQ_PEROUT) whether is generated at the specified time. Since ptp_clock_info::perout_loopback() has been added to the ptp_clock driver as a generic interface to enable or disable the periodic output signal loopback, therefore, netc_timer_perout_loopback() is added as a callback of ptp_clock_info::perout_loopback(). Test the generation time of PPS event: $ echo 0 1 > /sys/kernel/debug/ptp0/perout_loopback $ echo 1 > /sys/class/ptp/ptp0/pps_enable $ testptp -d /dev/ptp0 -e 3 external time stamp request okay event index 0 at 63.000000017 event index 0 at 64.000000017 event index 0 at 65.000000017 Test the generation time of the periodic output signal: $ echo 0 1 > /sys/kernel/debug/ptp0/perout_loopback $ echo 0 150 0 1 500000000 > /sys/class/ptp/ptp0/period $ testptp -d /dev/ptp0 -e 3 external time stamp request okay event index 0 at 150.000000014 event index 0 at 151.500000015 event index 0 at 153.000000014 Signed-off-by: Wei Fang <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e096a7c commit 67ac836

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/ptp/ptp_netc.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define TMR_ETEP(i) BIT(8 + (i))
2222
#define TMR_COMP_MODE BIT(15)
2323
#define TMR_CTRL_TCLK_PERIOD GENMASK(25, 16)
24+
#define TMR_CTRL_PPL(i) BIT(27 - (i))
2425
#define TMR_CTRL_FS BIT(28)
2526

2627
#define NETC_TMR_TEVENT 0x0084
@@ -609,6 +610,28 @@ static int netc_timer_enable(struct ptp_clock_info *ptp,
609610
}
610611
}
611612

613+
static int netc_timer_perout_loopback(struct ptp_clock_info *ptp,
614+
unsigned int index, int on)
615+
{
616+
struct netc_timer *priv = ptp_to_netc_timer(ptp);
617+
unsigned long flags;
618+
u32 tmr_ctrl;
619+
620+
spin_lock_irqsave(&priv->lock, flags);
621+
622+
tmr_ctrl = netc_timer_rd(priv, NETC_TMR_CTRL);
623+
if (on)
624+
tmr_ctrl |= TMR_CTRL_PPL(index);
625+
else
626+
tmr_ctrl &= ~TMR_CTRL_PPL(index);
627+
628+
netc_timer_wr(priv, NETC_TMR_CTRL, tmr_ctrl);
629+
630+
spin_unlock_irqrestore(&priv->lock, flags);
631+
632+
return 0;
633+
}
634+
612635
static void netc_timer_adjust_period(struct netc_timer *priv, u64 period)
613636
{
614637
u32 fractional_period = lower_32_bits(period);
@@ -717,13 +740,15 @@ static const struct ptp_clock_info netc_timer_ptp_caps = {
717740
.pps = 1,
718741
.n_per_out = 3,
719742
.n_ext_ts = 2,
743+
.n_per_lp = 2,
720744
.supported_extts_flags = PTP_RISING_EDGE | PTP_FALLING_EDGE |
721745
PTP_STRICT_FLAGS,
722746
.adjfine = netc_timer_adjfine,
723747
.adjtime = netc_timer_adjtime,
724748
.gettimex64 = netc_timer_gettimex64,
725749
.settime64 = netc_timer_settime64,
726750
.enable = netc_timer_enable,
751+
.perout_loopback = netc_timer_perout_loopback,
727752
};
728753

729754
static void netc_timer_init(struct netc_timer *priv)

0 commit comments

Comments
 (0)