102 lines · c
1// SPDX-License-Identifier: GPL-2.0+2/* Copyright 2019 NXP3 */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 ptp_qoriq *ptp_qoriq = data;11 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;12 u32 ctrl;13 14 ctrl = ptp_qoriq->read(®s->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 ptp_qoriq *ptp_qoriq = data;23 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;24 u32 ctrl;25 26 ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl);27 if (val == 0)28 ctrl &= ~PP1L;29 else30 ctrl |= PP1L;31 32 ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl);33 return 0;34}35 36DEFINE_DEBUGFS_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 ptp_qoriq *ptp_qoriq = data;42 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;43 u32 ctrl;44 45 ctrl = ptp_qoriq->read(®s->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 ptp_qoriq *ptp_qoriq = data;54 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;55 u32 ctrl;56 57 ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl);58 if (val == 0)59 ctrl &= ~PP2L;60 else61 ctrl |= PP2L;62 63 ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl);64 return 0;65}66 67DEFINE_DEBUGFS_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 ptp_qoriq *ptp_qoriq)71{72 struct dentry *root;73 74 root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL);75 if (IS_ERR(root))76 return;77 if (!root)78 goto err_root;79 80 ptp_qoriq->debugfs_root = root;81 82 if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root,83 ptp_qoriq, &ptp_qoriq_fiper1_fops))84 goto err_node;85 if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root,86 ptp_qoriq, &ptp_qoriq_fiper2_fops))87 goto err_node;88 return;89 90err_node:91 debugfs_remove_recursive(root);92 ptp_qoriq->debugfs_root = NULL;93err_root:94 dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n");95}96 97void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)98{99 debugfs_remove_recursive(ptp_qoriq->debugfs_root);100 ptp_qoriq->debugfs_root = NULL;101}102