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