History

ptp: add debugfs support for ptp_qoriq

This patch is to add debugfs support for ptp_qoriq. Current debugfs supports to control fiper1/fiper2 loopback mode. If the loopback mode is enabled, the fiper1/fiper2 pulse is looped back into trigger1/ trigger2 input. This is very useful for validating hardware and driver without external hardware. Below is an example to enable fiper1 loopback. echo 1 > /sys/kernel/debug/2d10e00.ptp_clock/fiper1-loopback

Yangbo Lu committed 7 years ago

Commit 19df7511 parent 47205e25 files · +120 −2Browse files

Unified · Split

5 files
  1. drivers/ptp/Kconfig +1 −1
  2. drivers/ptp/Makefile +3 −1
  3. drivers/ptp/ptp_qoriq.c +3 −0
  4. drivers/ptp/ptp_qoriq_debugfs.c +101 −0
  5. include/linux/fsl/ptp_qoriq.h +12 −0
drivers/ptp/Kconfig+1−1
@@ -53,7 +53,7 @@ config PTP_1588_CLOCK_QORIQ · 52 unmodified lines
53 packets using the SO_TIMESTAMPING API.53 packets using the SO_TIMESTAMPING API.
54 54
55 To compile this driver as a module, choose M here: the module55 To compile this driver as a module, choose M here: the module
56 will be called ptp_qoriq.56 will be called ptp-qoriq.
57 57
58config PTP_1588_CLOCK_IXP46X58config PTP_1588_CLOCK_IXP46X
59 tristate "Intel IXP46x as PTP clock"59 tristate "Intel IXP46x as PTP clock"
drivers/ptp/Makefile+3−1
@@ -9,4 +9,6 @@ obj-$(CONFIG_PTP_1588_CLOCK_DTE) += ptp_dte.o · 8 unmodified lines
9obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o9obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
10obj-$(CONFIG_PTP_1588_CLOCK_PCH) += ptp_pch.o10obj-$(CONFIG_PTP_1588_CLOCK_PCH) += ptp_pch.o
11obj-$(CONFIG_PTP_1588_CLOCK_KVM) += ptp_kvm.o11obj-$(CONFIG_PTP_1588_CLOCK_KVM) += ptp_kvm.o
12obj-$(CONFIG_PTP_1588_CLOCK_QORIQ) += ptp_qoriq.o12obj-$(CONFIG_PTP_1588_CLOCK_QORIQ) += ptp-qoriq.o
13ptp-qoriq-y += ptp_qoriq.o
14ptp-qoriq-$(CONFIG_DEBUG_FS) += ptp_qoriq_debugfs.o
drivers/ptp/ptp_qoriq.c+3−0
@@ -471,6 +471,7 @@ static int qoriq_ptp_probe(struct platform_device *dev) · 470 unmodified lines
471 471
472 err = -EINVAL;472 err = -EINVAL;
473 473
474 qoriq_ptp->dev = &dev->dev;
474 qoriq_ptp->caps = ptp_qoriq_caps;475 qoriq_ptp->caps = ptp_qoriq_caps;
475 476
476 if (of_property_read_u32(node, "fsl,cksel", &qoriq_ptp->cksel))477 if (of_property_read_u32(node, "fsl,cksel", &qoriq_ptp->cksel))
@@ -572,6 +573,7 @@ static int qoriq_ptp_probe(struct platform_device *dev) · 95 unmodified lines
572 }573 }
573 qoriq_ptp->phc_index = ptp_clock_index(qoriq_ptp->clock);574 qoriq_ptp->phc_index = ptp_clock_index(qoriq_ptp->clock);
574 575
576 ptp_qoriq_create_debugfs(qoriq_ptp);
575 platform_set_drvdata(dev, qoriq_ptp);577 platform_set_drvdata(dev, qoriq_ptp);
576 578
577 return 0;579 return 0;
@@ -597,6 +599,7 @@ static int qoriq_ptp_remove(struct platform_device *dev) · 19 unmodified lines
597 qoriq_write(&regs->ctrl_regs->tmr_temask, 0);599 qoriq_write(&regs->ctrl_regs->tmr_temask, 0);
598 qoriq_write(&regs->ctrl_regs->tmr_ctrl, 0);600 qoriq_write(&regs->ctrl_regs->tmr_ctrl, 0);
599 601
602 ptp_qoriq_remove_debugfs(qoriq_ptp);
600 ptp_clock_unregister(qoriq_ptp->clock);603 ptp_clock_unregister(qoriq_ptp->clock);
601 iounmap(qoriq_ptp->base);604 iounmap(qoriq_ptp->base);
602 release_resource(qoriq_ptp->rsrc);605 release_resource(qoriq_ptp->rsrc);
drivers/ptp/ptp_qoriq_debugfs.c+101−0
@@ -0,0 +1,101 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* Copyright 2019 NXP
3 */
4#include <linux/device.h>
5#include <linux/debugfs.h>
6#include <linux/fsl/ptp_qoriq.h>
7
8static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)
9{
10 struct qoriq_ptp *qoriq_ptp = data;
11 struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
12 u32 ctrl;
13
14 ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
15 *val = ctrl & PP1L ? 1 : 0;
16
17 return 0;
18}
19
20static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
21{
22 struct qoriq_ptp *qoriq_ptp = data;
23 struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
24 u32 ctrl;
25
26 ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
27 if (val == 0)
28 ctrl &= ~PP1L;
29 else
30 ctrl |= PP1L;
31
32 qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl);
33 return 0;
34}
35
36DEFINE_SIMPLE_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
37 ptp_qoriq_fiper1_lpbk_set, "%llu\n");
38
39static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
40{
41 struct qoriq_ptp *qoriq_ptp = data;
42 struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
43 u32 ctrl;
44
45 ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
46 *val = ctrl & PP2L ? 1 : 0;
47
48 return 0;
49}
50
51static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
52{
53 struct qoriq_ptp *qoriq_ptp = data;
54 struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
55 u32 ctrl;
56
57 ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
58 if (val == 0)
59 ctrl &= ~PP2L;
60 else
61 ctrl |= PP2L;
62
63 qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl);
64 return 0;
65}
66
67DEFINE_SIMPLE_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
68 ptp_qoriq_fiper2_lpbk_set, "%llu\n");
69
70void ptp_qoriq_create_debugfs(struct qoriq_ptp *qoriq_ptp)
71{
72 struct dentry *root;
73
74 root = debugfs_create_dir(dev_name(qoriq_ptp->dev), NULL);
75 if (IS_ERR(root))
76 return;
77 if (!root)
78 goto err_root;
79
80 qoriq_ptp->debugfs_root = root;
81
82 if (!debugfs_create_file("fiper1-loopback", 0600, root, qoriq_ptp,
83 &ptp_qoriq_fiper1_fops))
84 goto err_node;
85 if (!debugfs_create_file("fiper2-loopback", 0600, root, qoriq_ptp,
86 &ptp_qoriq_fiper2_fops))
87 goto err_node;
88 return;
89
90err_node:
91 debugfs_remove_recursive(root);
92 qoriq_ptp->debugfs_root = NULL;
93err_root:
94 dev_err(qoriq_ptp->dev, "failed to initialize debugfs\n");
95}
96
97void ptp_qoriq_remove_debugfs(struct qoriq_ptp *qoriq_ptp)
98{
99 debugfs_remove_recursive(qoriq_ptp->debugfs_root);
100 qoriq_ptp->debugfs_root = NULL;
101}
include/linux/fsl/ptp_qoriq.h+12−0
@@ -143,6 +143,8 @@ struct qoriq_ptp { · 142 unmodified lines
143 struct ptp_clock *clock;143 struct ptp_clock *clock;
144 struct ptp_clock_info caps;144 struct ptp_clock_info caps;
145 struct resource *rsrc;145 struct resource *rsrc;
146 struct dentry *debugfs_root;
147 struct device *dev;
146 bool extts_fifo_support;148 bool extts_fifo_support;
147 int irq;149 int irq;
148 int phc_index;150 int phc_index;
@@ -169,4 +171,14 @@ static inline void qoriq_write(unsigned __iomem *addr, u32 val) · 20 unmodified lines
169 iowrite32be(val, addr);171 iowrite32be(val, addr);
170}172}
171 173
174#ifdef CONFIG_DEBUG_FS
175void ptp_qoriq_create_debugfs(struct qoriq_ptp *qoriq_ptp);
176void ptp_qoriq_remove_debugfs(struct qoriq_ptp *qoriq_ptp);
177#else
178static inline void ptp_qoriq_create_debugfs(struct qoriq_ptp *qoriq_ptp)
179{ }
180static inline void ptp_qoriq_remove_debugfs(struct qoriq_ptp *qoriq_ptp)
181{ }
182#endif
183
172#endif184#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t