xref: /linux/drivers/ptp/ptp_qoriq_debugfs.c (revision 19df7510d5cf077c2e88a7690fb7617e6d341beb)
1*19df7510SYangbo Lu // SPDX-License-Identifier: GPL-2.0+
2*19df7510SYangbo Lu /* Copyright 2019 NXP
3*19df7510SYangbo Lu  */
4*19df7510SYangbo Lu #include <linux/device.h>
5*19df7510SYangbo Lu #include <linux/debugfs.h>
6*19df7510SYangbo Lu #include <linux/fsl/ptp_qoriq.h>
7*19df7510SYangbo Lu 
8*19df7510SYangbo Lu static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)
9*19df7510SYangbo Lu {
10*19df7510SYangbo Lu 	struct qoriq_ptp *qoriq_ptp = data;
11*19df7510SYangbo Lu 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
12*19df7510SYangbo Lu 	u32 ctrl;
13*19df7510SYangbo Lu 
14*19df7510SYangbo Lu 	ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
15*19df7510SYangbo Lu 	*val = ctrl & PP1L ? 1 : 0;
16*19df7510SYangbo Lu 
17*19df7510SYangbo Lu 	return 0;
18*19df7510SYangbo Lu }
19*19df7510SYangbo Lu 
20*19df7510SYangbo Lu static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
21*19df7510SYangbo Lu {
22*19df7510SYangbo Lu 	struct qoriq_ptp *qoriq_ptp = data;
23*19df7510SYangbo Lu 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
24*19df7510SYangbo Lu 	u32 ctrl;
25*19df7510SYangbo Lu 
26*19df7510SYangbo Lu 	ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
27*19df7510SYangbo Lu 	if (val == 0)
28*19df7510SYangbo Lu 		ctrl &= ~PP1L;
29*19df7510SYangbo Lu 	else
30*19df7510SYangbo Lu 		ctrl |= PP1L;
31*19df7510SYangbo Lu 
32*19df7510SYangbo Lu 	qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl);
33*19df7510SYangbo Lu 	return 0;
34*19df7510SYangbo Lu }
35*19df7510SYangbo Lu 
36*19df7510SYangbo Lu DEFINE_SIMPLE_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
37*19df7510SYangbo Lu 			ptp_qoriq_fiper1_lpbk_set, "%llu\n");
38*19df7510SYangbo Lu 
39*19df7510SYangbo Lu static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
40*19df7510SYangbo Lu {
41*19df7510SYangbo Lu 	struct qoriq_ptp *qoriq_ptp = data;
42*19df7510SYangbo Lu 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
43*19df7510SYangbo Lu 	u32 ctrl;
44*19df7510SYangbo Lu 
45*19df7510SYangbo Lu 	ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
46*19df7510SYangbo Lu 	*val = ctrl & PP2L ? 1 : 0;
47*19df7510SYangbo Lu 
48*19df7510SYangbo Lu 	return 0;
49*19df7510SYangbo Lu }
50*19df7510SYangbo Lu 
51*19df7510SYangbo Lu static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
52*19df7510SYangbo Lu {
53*19df7510SYangbo Lu 	struct qoriq_ptp *qoriq_ptp = data;
54*19df7510SYangbo Lu 	struct qoriq_ptp_registers *regs = &qoriq_ptp->regs;
55*19df7510SYangbo Lu 	u32 ctrl;
56*19df7510SYangbo Lu 
57*19df7510SYangbo Lu 	ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl);
58*19df7510SYangbo Lu 	if (val == 0)
59*19df7510SYangbo Lu 		ctrl &= ~PP2L;
60*19df7510SYangbo Lu 	else
61*19df7510SYangbo Lu 		ctrl |= PP2L;
62*19df7510SYangbo Lu 
63*19df7510SYangbo Lu 	qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl);
64*19df7510SYangbo Lu 	return 0;
65*19df7510SYangbo Lu }
66*19df7510SYangbo Lu 
67*19df7510SYangbo Lu DEFINE_SIMPLE_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
68*19df7510SYangbo Lu 			ptp_qoriq_fiper2_lpbk_set, "%llu\n");
69*19df7510SYangbo Lu 
70*19df7510SYangbo Lu void ptp_qoriq_create_debugfs(struct qoriq_ptp *qoriq_ptp)
71*19df7510SYangbo Lu {
72*19df7510SYangbo Lu 	struct dentry *root;
73*19df7510SYangbo Lu 
74*19df7510SYangbo Lu 	root = debugfs_create_dir(dev_name(qoriq_ptp->dev), NULL);
75*19df7510SYangbo Lu 	if (IS_ERR(root))
76*19df7510SYangbo Lu 		return;
77*19df7510SYangbo Lu 	if (!root)
78*19df7510SYangbo Lu 		goto err_root;
79*19df7510SYangbo Lu 
80*19df7510SYangbo Lu 	qoriq_ptp->debugfs_root = root;
81*19df7510SYangbo Lu 
82*19df7510SYangbo Lu 	if (!debugfs_create_file("fiper1-loopback", 0600, root, qoriq_ptp,
83*19df7510SYangbo Lu 				 &ptp_qoriq_fiper1_fops))
84*19df7510SYangbo Lu 		goto err_node;
85*19df7510SYangbo Lu 	if (!debugfs_create_file("fiper2-loopback", 0600, root, qoriq_ptp,
86*19df7510SYangbo Lu 				 &ptp_qoriq_fiper2_fops))
87*19df7510SYangbo Lu 		goto err_node;
88*19df7510SYangbo Lu 	return;
89*19df7510SYangbo Lu 
90*19df7510SYangbo Lu err_node:
91*19df7510SYangbo Lu 	debugfs_remove_recursive(root);
92*19df7510SYangbo Lu 	qoriq_ptp->debugfs_root = NULL;
93*19df7510SYangbo Lu err_root:
94*19df7510SYangbo Lu 	dev_err(qoriq_ptp->dev, "failed to initialize debugfs\n");
95*19df7510SYangbo Lu }
96*19df7510SYangbo Lu 
97*19df7510SYangbo Lu void ptp_qoriq_remove_debugfs(struct qoriq_ptp *qoriq_ptp)
98*19df7510SYangbo Lu {
99*19df7510SYangbo Lu 	debugfs_remove_recursive(qoriq_ptp->debugfs_root);
100*19df7510SYangbo Lu 	qoriq_ptp->debugfs_root = NULL;
101*19df7510SYangbo Lu }
102