Commit | Line | Data |
---|---|---|
19df7510 YL |
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 | ||
8 | static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val) | |
9 | { | |
1e562c81 YL |
10 | struct ptp_qoriq *ptp_qoriq = data; |
11 | struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; | |
19df7510 YL |
12 | u32 ctrl; |
13 | ||
f038ddf2 | 14 | ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); |
19df7510 YL |
15 | *val = ctrl & PP1L ? 1 : 0; |
16 | ||
17 | return 0; | |
18 | } | |
19 | ||
20 | static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val) | |
21 | { | |
1e562c81 YL |
22 | struct ptp_qoriq *ptp_qoriq = data; |
23 | struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; | |
19df7510 YL |
24 | u32 ctrl; |
25 | ||
f038ddf2 | 26 | ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); |
19df7510 YL |
27 | if (val == 0) |
28 | ctrl &= ~PP1L; | |
29 | else | |
30 | ctrl |= PP1L; | |
31 | ||
f038ddf2 | 32 | ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl); |
19df7510 YL |
33 | return 0; |
34 | } | |
35 | ||
84239b44 Y |
36 | DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get, |
37 | ptp_qoriq_fiper1_lpbk_set, "%llu\n"); | |
19df7510 YL |
38 | |
39 | static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val) | |
40 | { | |
1e562c81 YL |
41 | struct ptp_qoriq *ptp_qoriq = data; |
42 | struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; | |
19df7510 YL |
43 | u32 ctrl; |
44 | ||
f038ddf2 | 45 | ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); |
19df7510 YL |
46 | *val = ctrl & PP2L ? 1 : 0; |
47 | ||
48 | return 0; | |
49 | } | |
50 | ||
51 | static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val) | |
52 | { | |
1e562c81 YL |
53 | struct ptp_qoriq *ptp_qoriq = data; |
54 | struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; | |
19df7510 YL |
55 | u32 ctrl; |
56 | ||
f038ddf2 | 57 | ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); |
19df7510 YL |
58 | if (val == 0) |
59 | ctrl &= ~PP2L; | |
60 | else | |
61 | ctrl |= PP2L; | |
62 | ||
f038ddf2 | 63 | ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl); |
19df7510 YL |
64 | return 0; |
65 | } | |
66 | ||
84239b44 Y |
67 | DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get, |
68 | ptp_qoriq_fiper2_lpbk_set, "%llu\n"); | |
19df7510 | 69 | |
1e562c81 | 70 | void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq) |
19df7510 YL |
71 | { |
72 | struct dentry *root; | |
73 | ||
1e562c81 | 74 | root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL); |
19df7510 YL |
75 | if (IS_ERR(root)) |
76 | return; | |
77 | if (!root) | |
78 | goto err_root; | |
79 | ||
1e562c81 | 80 | ptp_qoriq->debugfs_root = root; |
19df7510 | 81 | |
84239b44 | 82 | if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root, |
1e562c81 | 83 | ptp_qoriq, &ptp_qoriq_fiper1_fops)) |
19df7510 | 84 | goto err_node; |
84239b44 | 85 | if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root, |
1e562c81 | 86 | ptp_qoriq, &ptp_qoriq_fiper2_fops)) |
19df7510 YL |
87 | goto err_node; |
88 | return; | |
89 | ||
90 | err_node: | |
91 | debugfs_remove_recursive(root); | |
1e562c81 | 92 | ptp_qoriq->debugfs_root = NULL; |
19df7510 | 93 | err_root: |
1e562c81 | 94 | dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n"); |
19df7510 YL |
95 | } |
96 | ||
1e562c81 | 97 | void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq) |
19df7510 | 98 | { |
1e562c81 YL |
99 | debugfs_remove_recursive(ptp_qoriq->debugfs_root); |
100 | ptp_qoriq->debugfs_root = NULL; | |
19df7510 | 101 | } |