Blame view

drivers/ptp/ptp_qoriq_debugfs.c 2.32 KB
19df7510d   Yangbo Lu   ptp: add debugfs ...
1
2
3
4
5
6
7
8
9
  // SPDX-License-Identifier: GPL-2.0+
  /* Copyright 2019 NXP
   */
  #include <linux/device.h>
  #include <linux/debugfs.h>
  #include <linux/fsl/ptp_qoriq.h>
  
  static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)
  {
1e562c815   Yangbo Lu   ptp_qoriq: make s...
10
11
  	struct ptp_qoriq *ptp_qoriq = data;
  	struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
19df7510d   Yangbo Lu   ptp: add debugfs ...
12
  	u32 ctrl;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
13
  	ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
14
15
16
17
18
19
20
  	*val = ctrl & PP1L ? 1 : 0;
  
  	return 0;
  }
  
  static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
  {
1e562c815   Yangbo Lu   ptp_qoriq: make s...
21
22
  	struct ptp_qoriq *ptp_qoriq = data;
  	struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
19df7510d   Yangbo Lu   ptp: add debugfs ...
23
  	u32 ctrl;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
24
  	ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
25
26
27
28
  	if (val == 0)
  		ctrl &= ~PP1L;
  	else
  		ctrl |= PP1L;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
29
  	ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
30
31
  	return 0;
  }
84239b445   YueHaibing   ptp: fix debugfs_...
32
33
34
  DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
  			 ptp_qoriq_fiper1_lpbk_set, "%llu
  ");
19df7510d   Yangbo Lu   ptp: add debugfs ...
35
36
37
  
  static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
  {
1e562c815   Yangbo Lu   ptp_qoriq: make s...
38
39
  	struct ptp_qoriq *ptp_qoriq = data;
  	struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
19df7510d   Yangbo Lu   ptp: add debugfs ...
40
  	u32 ctrl;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
41
  	ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
42
43
44
45
46
47
48
  	*val = ctrl & PP2L ? 1 : 0;
  
  	return 0;
  }
  
  static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
  {
1e562c815   Yangbo Lu   ptp_qoriq: make s...
49
50
  	struct ptp_qoriq *ptp_qoriq = data;
  	struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
19df7510d   Yangbo Lu   ptp: add debugfs ...
51
  	u32 ctrl;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
52
  	ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
53
54
55
56
  	if (val == 0)
  		ctrl &= ~PP2L;
  	else
  		ctrl |= PP2L;
f038ddf25   Yangbo Lu   ptp_qoriq: add li...
57
  	ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
19df7510d   Yangbo Lu   ptp: add debugfs ...
58
59
  	return 0;
  }
84239b445   YueHaibing   ptp: fix debugfs_...
60
61
62
  DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
  			 ptp_qoriq_fiper2_lpbk_set, "%llu
  ");
19df7510d   Yangbo Lu   ptp: add debugfs ...
63

1e562c815   Yangbo Lu   ptp_qoriq: make s...
64
  void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
19df7510d   Yangbo Lu   ptp: add debugfs ...
65
66
  {
  	struct dentry *root;
1e562c815   Yangbo Lu   ptp_qoriq: make s...
67
  	root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL);
19df7510d   Yangbo Lu   ptp: add debugfs ...
68
69
70
71
  	if (IS_ERR(root))
  		return;
  	if (!root)
  		goto err_root;
1e562c815   Yangbo Lu   ptp_qoriq: make s...
72
  	ptp_qoriq->debugfs_root = root;
19df7510d   Yangbo Lu   ptp: add debugfs ...
73

84239b445   YueHaibing   ptp: fix debugfs_...
74
  	if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root,
1e562c815   Yangbo Lu   ptp_qoriq: make s...
75
  					ptp_qoriq, &ptp_qoriq_fiper1_fops))
19df7510d   Yangbo Lu   ptp: add debugfs ...
76
  		goto err_node;
84239b445   YueHaibing   ptp: fix debugfs_...
77
  	if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root,
1e562c815   Yangbo Lu   ptp_qoriq: make s...
78
  					ptp_qoriq, &ptp_qoriq_fiper2_fops))
19df7510d   Yangbo Lu   ptp: add debugfs ...
79
80
81
82
83
  		goto err_node;
  	return;
  
  err_node:
  	debugfs_remove_recursive(root);
1e562c815   Yangbo Lu   ptp_qoriq: make s...
84
  	ptp_qoriq->debugfs_root = NULL;
19df7510d   Yangbo Lu   ptp: add debugfs ...
85
  err_root:
1e562c815   Yangbo Lu   ptp_qoriq: make s...
86
87
  	dev_err(ptp_qoriq->dev, "failed to initialize debugfs
  ");
19df7510d   Yangbo Lu   ptp: add debugfs ...
88
  }
1e562c815   Yangbo Lu   ptp_qoriq: make s...
89
  void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
19df7510d   Yangbo Lu   ptp: add debugfs ...
90
  {
1e562c815   Yangbo Lu   ptp_qoriq: make s...
91
92
  	debugfs_remove_recursive(ptp_qoriq->debugfs_root);
  	ptp_qoriq->debugfs_root = NULL;
19df7510d   Yangbo Lu   ptp: add debugfs ...
93
  }