blob: e8dddcedf288a6291e9333f78b962415430b7726 [file] [log] [blame]
Yangbo Lu19df7512019-01-21 18:41:42 +08001// 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{
Yangbo Lu1e562c82019-02-12 12:23:56 +080010 struct ptp_qoriq *ptp_qoriq = data;
11 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
Yangbo Lu19df7512019-01-21 18:41:42 +080012 u32 ctrl;
13
Yangbo Luf038ddf2019-02-12 12:23:59 +080014 ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080015 *val = ctrl & PP1L ? 1 : 0;
16
17 return 0;
18}
19
20static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
21{
Yangbo Lu1e562c82019-02-12 12:23:56 +080022 struct ptp_qoriq *ptp_qoriq = data;
23 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
Yangbo Lu19df7512019-01-21 18:41:42 +080024 u32 ctrl;
25
Yangbo Luf038ddf2019-02-12 12:23:59 +080026 ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080027 if (val == 0)
28 ctrl &= ~PP1L;
29 else
30 ctrl |= PP1L;
31
Yangbo Luf038ddf2019-02-12 12:23:59 +080032 ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080033 return 0;
34}
35
YueHaibing84239b42019-01-25 02:28:59 +000036DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
37 ptp_qoriq_fiper1_lpbk_set, "%llu\n");
Yangbo Lu19df7512019-01-21 18:41:42 +080038
39static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
40{
Yangbo Lu1e562c82019-02-12 12:23:56 +080041 struct ptp_qoriq *ptp_qoriq = data;
42 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
Yangbo Lu19df7512019-01-21 18:41:42 +080043 u32 ctrl;
44
Yangbo Luf038ddf2019-02-12 12:23:59 +080045 ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080046 *val = ctrl & PP2L ? 1 : 0;
47
48 return 0;
49}
50
51static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
52{
Yangbo Lu1e562c82019-02-12 12:23:56 +080053 struct ptp_qoriq *ptp_qoriq = data;
54 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
Yangbo Lu19df7512019-01-21 18:41:42 +080055 u32 ctrl;
56
Yangbo Luf038ddf2019-02-12 12:23:59 +080057 ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080058 if (val == 0)
59 ctrl &= ~PP2L;
60 else
61 ctrl |= PP2L;
62
Yangbo Luf038ddf2019-02-12 12:23:59 +080063 ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
Yangbo Lu19df7512019-01-21 18:41:42 +080064 return 0;
65}
66
YueHaibing84239b42019-01-25 02:28:59 +000067DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
68 ptp_qoriq_fiper2_lpbk_set, "%llu\n");
Yangbo Lu19df7512019-01-21 18:41:42 +080069
Yangbo Lu1e562c82019-02-12 12:23:56 +080070void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
Yangbo Lu19df7512019-01-21 18:41:42 +080071{
72 struct dentry *root;
73
Yangbo Lu1e562c82019-02-12 12:23:56 +080074 root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL);
Yangbo Lu19df7512019-01-21 18:41:42 +080075 if (IS_ERR(root))
76 return;
77 if (!root)
78 goto err_root;
79
Yangbo Lu1e562c82019-02-12 12:23:56 +080080 ptp_qoriq->debugfs_root = root;
Yangbo Lu19df7512019-01-21 18:41:42 +080081
YueHaibing84239b42019-01-25 02:28:59 +000082 if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root,
Yangbo Lu1e562c82019-02-12 12:23:56 +080083 ptp_qoriq, &ptp_qoriq_fiper1_fops))
Yangbo Lu19df7512019-01-21 18:41:42 +080084 goto err_node;
YueHaibing84239b42019-01-25 02:28:59 +000085 if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root,
Yangbo Lu1e562c82019-02-12 12:23:56 +080086 ptp_qoriq, &ptp_qoriq_fiper2_fops))
Yangbo Lu19df7512019-01-21 18:41:42 +080087 goto err_node;
88 return;
89
90err_node:
91 debugfs_remove_recursive(root);
Yangbo Lu1e562c82019-02-12 12:23:56 +080092 ptp_qoriq->debugfs_root = NULL;
Yangbo Lu19df7512019-01-21 18:41:42 +080093err_root:
Yangbo Lu1e562c82019-02-12 12:23:56 +080094 dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n");
Yangbo Lu19df7512019-01-21 18:41:42 +080095}
96
Yangbo Lu1e562c82019-02-12 12:23:56 +080097void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
Yangbo Lu19df7512019-01-21 18:41:42 +080098{
Yangbo Lu1e562c82019-02-12 12:23:56 +080099 debugfs_remove_recursive(ptp_qoriq->debugfs_root);
100 ptp_qoriq->debugfs_root = NULL;
Yangbo Lu19df7512019-01-21 18:41:42 +0800101}