-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlan865x_debug_patch.patch
More file actions
131 lines (124 loc) · 4.22 KB
/
Copy pathlan865x_debug_patch.patch
File metadata and controls
131 lines (124 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
--- a/drivers/net/ethernet/microchip/lan865x.c
+++ b/drivers/net/ethernet/microchip/lan865x.c
@@ -12,6 +12,8 @@
#include <linux/phy.h>
#include <linux/oa_tc6.h>
#include <linux/of.h>
+#include <linux/debugfs.h>
+#include <linux/proc_fs.h>
#define DRV_NAME "lan865x"
@@ -50,6 +52,10 @@ struct lan865x_priv {
struct work_struct multicast_work;
struct net_device *netdev;
struct spi_device *spi;
+
+ /* Debug interface for register access */
+ struct dentry *debugfs_dir;
+ struct proc_dir_entry *proc_entry;
};
static int lan865x_set_hw_macaddr(struct net_device *netdev,
@@ -257,6 +263,89 @@ static const struct net_device_ops lan865x_netdev_ops = {
.ndo_get_stats64 = lan865x_get_stats64,
};
+/* Debugfs interface for register access */
+static ssize_t lan865x_debugfs_reg_read(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct lan865x_priv *priv = file->private_data;
+ char buf[64];
+ int len;
+
+ /* This would show the last register read result */
+ len = snprintf(buf, sizeof(buf), "Use: echo 'read 0x10000' > reg_access\n");
+
+ return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t lan865x_debugfs_reg_write(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct lan865x_priv *priv = file->private_data;
+ char buf[128];
+ char cmd[16];
+ u32 address, value;
+ int ret;
+
+ if (count >= sizeof(buf))
+ return -EINVAL;
+
+ if (copy_from_user(buf, user_buf, count))
+ return -EFAULT;
+
+ buf[count] = '\0';
+
+ if (sscanf(buf, "%15s 0x%x 0x%x", cmd, &address, &value) == 3) {
+ if (strcmp(cmd, "write") == 0) {
+ /* Write register via TC6 */
+ ret = oa_tc6_write_register(priv->tc6, address, value);
+ if (ret)
+ return ret;
+
+ dev_info(&priv->spi->dev, "REG WRITE 0x%08x = 0x%08x\n",
+ address, value);
+ }
+ } else if (sscanf(buf, "%15s 0x%x", cmd, &address) == 2) {
+ if (strcmp(cmd, "read") == 0) {
+ /* Read register via TC6 */
+ ret = oa_tc6_read_register(priv->tc6, address, &value);
+ if (ret)
+ return ret;
+
+ dev_info(&priv->spi->dev, "REG READ 0x%08x = 0x%08x\n",
+ address, value);
+ }
+ } else {
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static const struct file_operations lan865x_debugfs_reg_fops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = lan865x_debugfs_reg_read,
+ .write = lan865x_debugfs_reg_write,
+};
+
+static void lan865x_create_debugfs(struct lan865x_priv *priv)
+{
+ priv->debugfs_dir = debugfs_create_dir("lan865x", NULL);
+ if (!priv->debugfs_dir)
+ return;
+
+ debugfs_create_file("reg_access", 0600, priv->debugfs_dir, priv,
+ &lan865x_debugfs_reg_fops);
+}
+
+static void lan865x_remove_debugfs(struct lan865x_priv *priv)
+{
+ if (priv->debugfs_dir) {
+ debugfs_remove_recursive(priv->debugfs_dir);
+ priv->debugfs_dir = NULL;
+ }
+}
+
static int lan865x_probe(struct spi_device *spi)
{
struct net_device *netdev;
@@ -310,6 +399,9 @@ static int lan865x_probe(struct spi_device *spi)
if (ret)
goto err_register_netdev;
+ /* Create debug interface */
+ lan865x_create_debugfs(priv);
+
return 0;
err_register_netdev:
@@ -323,6 +415,7 @@ static void lan865x_remove(struct spi_device *spi)
{
struct lan865x_priv *priv = spi_get_drvdata(spi);
+ lan865x_remove_debugfs(priv);
unregister_netdev(priv->netdev);
oa_tc6_exit(priv->tc6);
}