Skip to content

Commit 214da63

Browse files
committed
Merge branch 'ptp-add-pulse-signal-loopback-support-for-debugging'
Wei Fang says: ==================== ptp: add pulse signal loopback support for debugging Some PTP devices support looping back the periodic pulse signal for debugging. For example, the PTP device of QorIQ platform and the NETC v4 Timer has the ability to loop back the pulse signal and record the extts events for the loopback signal. So we can make sure that the pulse intervals and their phase alignment are correct from the perspective of the emitting PHC's time base. In addition, we can use this loopback feature as a built-in extts event generator when we have no external equipment which does that. Therefore, add the generic debugfs interfaces to the ptp_clock driver. The first two patch are separated from the previous patch set [1]. The third patch is new added. [1]: https://lore.kernel.org/imx/[email protected]/ #patch 3 and 9 ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents cf71bdf + f316484 commit 214da63

File tree

9 files changed

+128
-118
lines changed

9 files changed

+128
-118
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9817,7 +9817,6 @@ F: drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp*
98179817
F: drivers/net/ethernet/freescale/dpaa2/dprtc*
98189818
F: drivers/net/ethernet/freescale/enetc/enetc_ptp.c
98199819
F: drivers/ptp/ptp_qoriq.c
9820-
F: drivers/ptp/ptp_qoriq_debugfs.c
98219820
F: include/linux/fsl/ptp_qoriq.h
98229821

98239822
FREESCALE QUAD SPI DRIVER

drivers/ptp/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ config PTP_1588_CLOCK_QORIQ
6767
packets using the SO_TIMESTAMPING API.
6868

6969
To compile this driver as a module, choose M here: the module
70-
will be called ptp-qoriq.
70+
will be called ptp_qoriq.
7171

7272
comment "Enable PHYLIB and NETWORK_PHY_TIMESTAMPING to see the additional clocks."
7373
depends on PHYLIB=n || NETWORK_PHY_TIMESTAMPING=n

drivers/ptp/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ obj-$(CONFIG_PTP_1588_CLOCK_INES) += ptp_ines.o
1212
obj-$(CONFIG_PTP_1588_CLOCK_PCH) += ptp_pch.o
1313
obj-$(CONFIG_PTP_1588_CLOCK_KVM) += ptp_kvm.o
1414
obj-$(CONFIG_PTP_1588_CLOCK_VMCLOCK) += ptp_vmclock.o
15-
obj-$(CONFIG_PTP_1588_CLOCK_QORIQ) += ptp-qoriq.o
16-
ptp-qoriq-y += ptp_qoriq.o
17-
ptp-qoriq-$(CONFIG_DEBUG_FS) += ptp_qoriq_debugfs.o
15+
obj-$(CONFIG_PTP_1588_CLOCK_QORIQ) += ptp_qoriq.o
1816
obj-$(CONFIG_PTP_1588_CLOCK_IDTCM) += ptp_clockmatrix.o
1917
obj-$(CONFIG_PTP_1588_CLOCK_FC3W) += ptp_fc3.o
2018
obj-$(CONFIG_PTP_1588_CLOCK_IDT82P33) += ptp_idt82p33.o

drivers/ptp/ptp_clock.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,69 @@ static void ptp_aux_kworker(struct kthread_work *work)
248248
kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay);
249249
}
250250

251+
static ssize_t ptp_n_perout_loopback_read(struct file *filep,
252+
char __user *buffer,
253+
size_t count, loff_t *pos)
254+
{
255+
struct ptp_clock *ptp = filep->private_data;
256+
char buf[12] = {};
257+
258+
snprintf(buf, sizeof(buf), "%d\n", ptp->info->n_per_lp);
259+
260+
return simple_read_from_buffer(buffer, count, pos, buf, strlen(buf));
261+
}
262+
263+
static const struct file_operations ptp_n_perout_loopback_fops = {
264+
.owner = THIS_MODULE,
265+
.open = simple_open,
266+
.read = ptp_n_perout_loopback_read,
267+
};
268+
269+
static ssize_t ptp_perout_loopback_write(struct file *filep,
270+
const char __user *buffer,
271+
size_t count, loff_t *ppos)
272+
{
273+
struct ptp_clock *ptp = filep->private_data;
274+
struct ptp_clock_info *ops = ptp->info;
275+
unsigned int index, enable;
276+
int len, cnt, err;
277+
char buf[32] = {};
278+
279+
if (*ppos || !count)
280+
return -EINVAL;
281+
282+
if (count >= sizeof(buf))
283+
return -ENOSPC;
284+
285+
len = simple_write_to_buffer(buf, sizeof(buf) - 1,
286+
ppos, buffer, count);
287+
if (len < 0)
288+
return len;
289+
290+
buf[len] = '\0';
291+
cnt = sscanf(buf, "%u %u", &index, &enable);
292+
if (cnt != 2)
293+
return -EINVAL;
294+
295+
if (index >= ops->n_per_lp)
296+
return -EINVAL;
297+
298+
if (enable != 0 && enable != 1)
299+
return -EINVAL;
300+
301+
err = ops->perout_loopback(ops, index, enable);
302+
if (err)
303+
return err;
304+
305+
return count;
306+
}
307+
308+
static const struct file_operations ptp_perout_loopback_ops = {
309+
.owner = THIS_MODULE,
310+
.open = simple_open,
311+
.write = ptp_perout_loopback_write,
312+
};
313+
251314
/* public interface */
252315

253316
struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
@@ -389,6 +452,12 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
389452
/* Debugfs initialization */
390453
snprintf(debugfsname, sizeof(debugfsname), "ptp%d", ptp->index);
391454
ptp->debugfs_root = debugfs_create_dir(debugfsname, NULL);
455+
if (info->n_per_lp > 0 && info->perout_loopback) {
456+
debugfs_create_file("n_perout_loopback", 0400, ptp->debugfs_root,
457+
ptp, &ptp_n_perout_loopback_fops);
458+
debugfs_create_file("perout_loopback", 0200, ptp->debugfs_root,
459+
ptp, &ptp_perout_loopback_ops);
460+
}
392461

393462
return ptp;
394463

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)

drivers/ptp/ptp_qoriq.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,25 @@ static int ptp_qoriq_auto_config(struct ptp_qoriq *ptp_qoriq,
465465
return 0;
466466
}
467467

468+
static int ptp_qoriq_perout_loopback(struct ptp_clock_info *ptp,
469+
unsigned int index, int on)
470+
{
471+
struct ptp_qoriq *ptp_qoriq = container_of(ptp, struct ptp_qoriq, caps);
472+
struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
473+
u32 loopback_bit = index ? PP2L : PP1L;
474+
u32 tmr_ctrl;
475+
476+
tmr_ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
477+
if (on)
478+
tmr_ctrl |= loopback_bit;
479+
else
480+
tmr_ctrl &= ~loopback_bit;
481+
482+
ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, tmr_ctrl);
483+
484+
return 0;
485+
}
486+
468487
int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
469488
const struct ptp_clock_info *caps)
470489
{
@@ -479,6 +498,8 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
479498

480499
ptp_qoriq->base = base;
481500
ptp_qoriq->caps = *caps;
501+
ptp_qoriq->caps.n_per_lp = 2;
502+
ptp_qoriq->caps.perout_loopback = ptp_qoriq_perout_loopback;
482503

483504
if (of_property_read_u32(node, "fsl,cksel", &ptp_qoriq->cksel))
484505
ptp_qoriq->cksel = DEFAULT_CKSEL;
@@ -568,7 +589,7 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
568589
return PTR_ERR(ptp_qoriq->clock);
569590

570591
ptp_qoriq->phc_index = ptp_clock_index(ptp_qoriq->clock);
571-
ptp_qoriq_create_debugfs(ptp_qoriq);
592+
572593
return 0;
573594
}
574595
EXPORT_SYMBOL_GPL(ptp_qoriq_init);
@@ -580,7 +601,6 @@ void ptp_qoriq_free(struct ptp_qoriq *ptp_qoriq)
580601
ptp_qoriq->write(&regs->ctrl_regs->tmr_temask, 0);
581602
ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, 0);
582603

583-
ptp_qoriq_remove_debugfs(ptp_qoriq);
584604
ptp_clock_unregister(ptp_qoriq->clock);
585605
iounmap(ptp_qoriq->base);
586606
free_irq(ptp_qoriq->irq, ptp_qoriq);

drivers/ptp/ptp_qoriq_debugfs.c

Lines changed: 0 additions & 101 deletions
This file was deleted.

include/linux/fsl/ptp_qoriq.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ struct ptp_qoriq {
145145
struct ptp_clock *clock;
146146
struct ptp_clock_info caps;
147147
struct resource *rsrc;
148-
struct dentry *debugfs_root;
149148
struct device *dev;
150149
bool extts_fifo_support;
151150
bool fiper3_support;
@@ -195,14 +194,5 @@ int ptp_qoriq_settime(struct ptp_clock_info *ptp,
195194
int ptp_qoriq_enable(struct ptp_clock_info *ptp,
196195
struct ptp_clock_request *rq, int on);
197196
int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index, bool update_event);
198-
#ifdef CONFIG_DEBUG_FS
199-
void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq);
200-
void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq);
201-
#else
202-
static inline void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
203-
{ }
204-
static inline void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
205-
{ }
206-
#endif
207197

208198
#endif

include/linux/ptp_clock_kernel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct ptp_system_timestamp {
6767
* @n_ext_ts: The number of external time stamp channels.
6868
* @n_per_out: The number of programmable periodic signals.
6969
* @n_pins: The number of programmable pins.
70+
* @n_per_lp: The number of channels that support loopback the periodic
71+
* output signal.
7072
* @pps: Indicates whether the clock supports a PPS callback.
7173
*
7274
* @supported_perout_flags: The set of flags the driver supports for the
@@ -175,6 +177,11 @@ struct ptp_system_timestamp {
175177
* scheduling time (>=0) or negative value in case further
176178
* scheduling is not required.
177179
*
180+
* @perout_loopback: Request driver to enable or disable the periodic output
181+
* signal loopback.
182+
* parameter index: index of the periodic output signal channel.
183+
* parameter on: caller passes one to enable or zero to disable.
184+
*
178185
* Drivers should embed their ptp_clock_info within a private
179186
* structure, obtaining a reference to it using container_of().
180187
*
@@ -189,6 +196,7 @@ struct ptp_clock_info {
189196
int n_ext_ts;
190197
int n_per_out;
191198
int n_pins;
199+
int n_per_lp;
192200
int pps;
193201
unsigned int supported_perout_flags;
194202
unsigned int supported_extts_flags;
@@ -213,6 +221,8 @@ struct ptp_clock_info {
213221
int (*verify)(struct ptp_clock_info *ptp, unsigned int pin,
214222
enum ptp_pin_function func, unsigned int chan);
215223
long (*do_aux_work)(struct ptp_clock_info *ptp);
224+
int (*perout_loopback)(struct ptp_clock_info *ptp, unsigned int index,
225+
int on);
216226
};
217227

218228
struct ptp_clock;

0 commit comments

Comments
 (0)