119df7510SYangbo Lu // SPDX-License-Identifier: GPL-2.0+ 219df7510SYangbo Lu /* Copyright 2019 NXP 319df7510SYangbo Lu */ 419df7510SYangbo Lu #include <linux/device.h> 519df7510SYangbo Lu #include <linux/debugfs.h> 619df7510SYangbo Lu #include <linux/fsl/ptp_qoriq.h> 719df7510SYangbo Lu 819df7510SYangbo Lu static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val) 919df7510SYangbo Lu { 101e562c81SYangbo Lu struct ptp_qoriq *ptp_qoriq = data; 111e562c81SYangbo Lu struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 1219df7510SYangbo Lu u32 ctrl; 1319df7510SYangbo Lu 14*f038ddf2SYangbo Lu ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); 1519df7510SYangbo Lu *val = ctrl & PP1L ? 1 : 0; 1619df7510SYangbo Lu 1719df7510SYangbo Lu return 0; 1819df7510SYangbo Lu } 1919df7510SYangbo Lu 2019df7510SYangbo Lu static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val) 2119df7510SYangbo Lu { 221e562c81SYangbo Lu struct ptp_qoriq *ptp_qoriq = data; 231e562c81SYangbo Lu struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 2419df7510SYangbo Lu u32 ctrl; 2519df7510SYangbo Lu 26*f038ddf2SYangbo Lu ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); 2719df7510SYangbo Lu if (val == 0) 2819df7510SYangbo Lu ctrl &= ~PP1L; 2919df7510SYangbo Lu else 3019df7510SYangbo Lu ctrl |= PP1L; 3119df7510SYangbo Lu 32*f038ddf2SYangbo Lu ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl); 3319df7510SYangbo Lu return 0; 3419df7510SYangbo Lu } 3519df7510SYangbo Lu 3684239b44SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get, 3719df7510SYangbo Lu ptp_qoriq_fiper1_lpbk_set, "%llu\n"); 3819df7510SYangbo Lu 3919df7510SYangbo Lu static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val) 4019df7510SYangbo Lu { 411e562c81SYangbo Lu struct ptp_qoriq *ptp_qoriq = data; 421e562c81SYangbo Lu struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 4319df7510SYangbo Lu u32 ctrl; 4419df7510SYangbo Lu 45*f038ddf2SYangbo Lu ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); 4619df7510SYangbo Lu *val = ctrl & PP2L ? 1 : 0; 4719df7510SYangbo Lu 4819df7510SYangbo Lu return 0; 4919df7510SYangbo Lu } 5019df7510SYangbo Lu 5119df7510SYangbo Lu static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val) 5219df7510SYangbo Lu { 531e562c81SYangbo Lu struct ptp_qoriq *ptp_qoriq = data; 541e562c81SYangbo Lu struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 5519df7510SYangbo Lu u32 ctrl; 5619df7510SYangbo Lu 57*f038ddf2SYangbo Lu ctrl = ptp_qoriq->read(®s->ctrl_regs->tmr_ctrl); 5819df7510SYangbo Lu if (val == 0) 5919df7510SYangbo Lu ctrl &= ~PP2L; 6019df7510SYangbo Lu else 6119df7510SYangbo Lu ctrl |= PP2L; 6219df7510SYangbo Lu 63*f038ddf2SYangbo Lu ptp_qoriq->write(®s->ctrl_regs->tmr_ctrl, ctrl); 6419df7510SYangbo Lu return 0; 6519df7510SYangbo Lu } 6619df7510SYangbo Lu 6784239b44SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get, 6819df7510SYangbo Lu ptp_qoriq_fiper2_lpbk_set, "%llu\n"); 6919df7510SYangbo Lu 701e562c81SYangbo Lu void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq) 7119df7510SYangbo Lu { 7219df7510SYangbo Lu struct dentry *root; 7319df7510SYangbo Lu 741e562c81SYangbo Lu root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL); 7519df7510SYangbo Lu if (IS_ERR(root)) 7619df7510SYangbo Lu return; 7719df7510SYangbo Lu if (!root) 7819df7510SYangbo Lu goto err_root; 7919df7510SYangbo Lu 801e562c81SYangbo Lu ptp_qoriq->debugfs_root = root; 8119df7510SYangbo Lu 8284239b44SYueHaibing if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root, 831e562c81SYangbo Lu ptp_qoriq, &ptp_qoriq_fiper1_fops)) 8419df7510SYangbo Lu goto err_node; 8584239b44SYueHaibing if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root, 861e562c81SYangbo Lu ptp_qoriq, &ptp_qoriq_fiper2_fops)) 8719df7510SYangbo Lu goto err_node; 8819df7510SYangbo Lu return; 8919df7510SYangbo Lu 9019df7510SYangbo Lu err_node: 9119df7510SYangbo Lu debugfs_remove_recursive(root); 921e562c81SYangbo Lu ptp_qoriq->debugfs_root = NULL; 9319df7510SYangbo Lu err_root: 941e562c81SYangbo Lu dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n"); 9519df7510SYangbo Lu } 9619df7510SYangbo Lu 971e562c81SYangbo Lu void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq) 9819df7510SYangbo Lu { 991e562c81SYangbo Lu debugfs_remove_recursive(ptp_qoriq->debugfs_root); 1001e562c81SYangbo Lu ptp_qoriq->debugfs_root = NULL; 10119df7510SYangbo Lu } 102