Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /* Copyright 2019 NXP
0003  */
0004 #include <linux/device.h>
0005 #include <linux/debugfs.h>
0006 #include <linux/fsl/ptp_qoriq.h>
0007 
0008 static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)
0009 {
0010     struct ptp_qoriq *ptp_qoriq = data;
0011     struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
0012     u32 ctrl;
0013 
0014     ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
0015     *val = ctrl & PP1L ? 1 : 0;
0016 
0017     return 0;
0018 }
0019 
0020 static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
0021 {
0022     struct ptp_qoriq *ptp_qoriq = data;
0023     struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
0024     u32 ctrl;
0025 
0026     ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
0027     if (val == 0)
0028         ctrl &= ~PP1L;
0029     else
0030         ctrl |= PP1L;
0031 
0032     ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
0033     return 0;
0034 }
0035 
0036 DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
0037              ptp_qoriq_fiper1_lpbk_set, "%llu\n");
0038 
0039 static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
0040 {
0041     struct ptp_qoriq *ptp_qoriq = data;
0042     struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
0043     u32 ctrl;
0044 
0045     ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
0046     *val = ctrl & PP2L ? 1 : 0;
0047 
0048     return 0;
0049 }
0050 
0051 static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
0052 {
0053     struct ptp_qoriq *ptp_qoriq = data;
0054     struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
0055     u32 ctrl;
0056 
0057     ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
0058     if (val == 0)
0059         ctrl &= ~PP2L;
0060     else
0061         ctrl |= PP2L;
0062 
0063     ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
0064     return 0;
0065 }
0066 
0067 DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
0068              ptp_qoriq_fiper2_lpbk_set, "%llu\n");
0069 
0070 void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
0071 {
0072     struct dentry *root;
0073 
0074     root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL);
0075     if (IS_ERR(root))
0076         return;
0077     if (!root)
0078         goto err_root;
0079 
0080     ptp_qoriq->debugfs_root = root;
0081 
0082     if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root,
0083                     ptp_qoriq, &ptp_qoriq_fiper1_fops))
0084         goto err_node;
0085     if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root,
0086                     ptp_qoriq, &ptp_qoriq_fiper2_fops))
0087         goto err_node;
0088     return;
0089 
0090 err_node:
0091     debugfs_remove_recursive(root);
0092     ptp_qoriq->debugfs_root = NULL;
0093 err_root:
0094     dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n");
0095 }
0096 
0097 void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
0098 {
0099     debugfs_remove_recursive(ptp_qoriq->debugfs_root);
0100     ptp_qoriq->debugfs_root = NULL;
0101 }