]> Git Repo - linux.git/blob - drivers/usb/chipidea/debug.c
usb: chipidea: debug: add debug file for controller registers dump
[linux.git] / drivers / usb / chipidea / debug.c
1 #include <linux/kernel.h>
2 #include <linux/device.h>
3 #include <linux/types.h>
4 #include <linux/spinlock.h>
5 #include <linux/debugfs.h>
6 #include <linux/seq_file.h>
7 #include <linux/uaccess.h>
8 #include <linux/usb/ch9.h>
9 #include <linux/usb/gadget.h>
10
11 #include "ci.h"
12 #include "udc.h"
13 #include "bits.h"
14 #include "debug.h"
15 #include "otg.h"
16
17 /**
18  * ci_device_show: prints information about device capabilities and status
19  */
20 static int ci_device_show(struct seq_file *s, void *data)
21 {
22         struct ci_hdrc *ci = s->private;
23         struct usb_gadget *gadget = &ci->gadget;
24
25         seq_printf(s, "speed             = %d\n", gadget->speed);
26         seq_printf(s, "max_speed         = %d\n", gadget->max_speed);
27         seq_printf(s, "is_otg            = %d\n", gadget->is_otg);
28         seq_printf(s, "is_a_peripheral   = %d\n", gadget->is_a_peripheral);
29         seq_printf(s, "b_hnp_enable      = %d\n", gadget->b_hnp_enable);
30         seq_printf(s, "a_hnp_support     = %d\n", gadget->a_hnp_support);
31         seq_printf(s, "a_alt_hnp_support = %d\n", gadget->a_alt_hnp_support);
32         seq_printf(s, "name              = %s\n",
33                    (gadget->name ? gadget->name : ""));
34
35         if (!ci->driver)
36                 return 0;
37
38         seq_printf(s, "gadget function   = %s\n",
39                        (ci->driver->function ? ci->driver->function : ""));
40         seq_printf(s, "gadget max speed  = %d\n", ci->driver->max_speed);
41
42         return 0;
43 }
44
45 static int ci_device_open(struct inode *inode, struct file *file)
46 {
47         return single_open(file, ci_device_show, inode->i_private);
48 }
49
50 static const struct file_operations ci_device_fops = {
51         .open           = ci_device_open,
52         .read           = seq_read,
53         .llseek         = seq_lseek,
54         .release        = single_release,
55 };
56
57 /**
58  * ci_port_test_show: reads port test mode
59  */
60 static int ci_port_test_show(struct seq_file *s, void *data)
61 {
62         struct ci_hdrc *ci = s->private;
63         unsigned long flags;
64         unsigned mode;
65
66         spin_lock_irqsave(&ci->lock, flags);
67         mode = hw_port_test_get(ci);
68         spin_unlock_irqrestore(&ci->lock, flags);
69
70         seq_printf(s, "mode = %u\n", mode);
71
72         return 0;
73 }
74
75 /**
76  * ci_port_test_write: writes port test mode
77  */
78 static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
79                                   size_t count, loff_t *ppos)
80 {
81         struct seq_file *s = file->private_data;
82         struct ci_hdrc *ci = s->private;
83         unsigned long flags;
84         unsigned mode;
85         char buf[32];
86         int ret;
87
88         if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
89                 return -EFAULT;
90
91         if (sscanf(buf, "%u", &mode) != 1)
92                 return -EINVAL;
93
94         spin_lock_irqsave(&ci->lock, flags);
95         ret = hw_port_test_set(ci, mode);
96         spin_unlock_irqrestore(&ci->lock, flags);
97
98         return ret ? ret : count;
99 }
100
101 static int ci_port_test_open(struct inode *inode, struct file *file)
102 {
103         return single_open(file, ci_port_test_show, inode->i_private);
104 }
105
106 static const struct file_operations ci_port_test_fops = {
107         .open           = ci_port_test_open,
108         .write          = ci_port_test_write,
109         .read           = seq_read,
110         .llseek         = seq_lseek,
111         .release        = single_release,
112 };
113
114 /**
115  * ci_qheads_show: DMA contents of all queue heads
116  */
117 static int ci_qheads_show(struct seq_file *s, void *data)
118 {
119         struct ci_hdrc *ci = s->private;
120         unsigned long flags;
121         unsigned i, j;
122
123         if (ci->role != CI_ROLE_GADGET) {
124                 seq_printf(s, "not in gadget mode\n");
125                 return 0;
126         }
127
128         spin_lock_irqsave(&ci->lock, flags);
129         for (i = 0; i < ci->hw_ep_max/2; i++) {
130                 struct ci_hw_ep *hweprx = &ci->ci_hw_ep[i];
131                 struct ci_hw_ep *hweptx =
132                         &ci->ci_hw_ep[i + ci->hw_ep_max/2];
133                 seq_printf(s, "EP=%02i: RX=%08X TX=%08X\n",
134                            i, (u32)hweprx->qh.dma, (u32)hweptx->qh.dma);
135                 for (j = 0; j < (sizeof(struct ci_hw_qh)/sizeof(u32)); j++)
136                         seq_printf(s, " %04X:    %08X    %08X\n", j,
137                                    *((u32 *)hweprx->qh.ptr + j),
138                                    *((u32 *)hweptx->qh.ptr + j));
139         }
140         spin_unlock_irqrestore(&ci->lock, flags);
141
142         return 0;
143 }
144
145 static int ci_qheads_open(struct inode *inode, struct file *file)
146 {
147         return single_open(file, ci_qheads_show, inode->i_private);
148 }
149
150 static const struct file_operations ci_qheads_fops = {
151         .open           = ci_qheads_open,
152         .read           = seq_read,
153         .llseek         = seq_lseek,
154         .release        = single_release,
155 };
156
157 /**
158  * ci_requests_show: DMA contents of all requests currently queued (all endpts)
159  */
160 static int ci_requests_show(struct seq_file *s, void *data)
161 {
162         struct ci_hdrc *ci = s->private;
163         unsigned long flags;
164         struct list_head   *ptr = NULL;
165         struct ci_hw_req *req = NULL;
166         struct td_node *node, *tmpnode;
167         unsigned i, j, qsize = sizeof(struct ci_hw_td)/sizeof(u32);
168
169         if (ci->role != CI_ROLE_GADGET) {
170                 seq_printf(s, "not in gadget mode\n");
171                 return 0;
172         }
173
174         spin_lock_irqsave(&ci->lock, flags);
175         for (i = 0; i < ci->hw_ep_max; i++)
176                 list_for_each(ptr, &ci->ci_hw_ep[i].qh.queue) {
177                         req = list_entry(ptr, struct ci_hw_req, queue);
178
179                         list_for_each_entry_safe(node, tmpnode, &req->tds, td) {
180                                 seq_printf(s, "EP=%02i: TD=%08X %s\n",
181                                            i % (ci->hw_ep_max / 2),
182                                            (u32)node->dma,
183                                            ((i < ci->hw_ep_max/2) ?
184                                            "RX" : "TX"));
185
186                                 for (j = 0; j < qsize; j++)
187                                         seq_printf(s, " %04X:    %08X\n", j,
188                                                    *((u32 *)node->ptr + j));
189                         }
190                 }
191         spin_unlock_irqrestore(&ci->lock, flags);
192
193         return 0;
194 }
195
196 static int ci_requests_open(struct inode *inode, struct file *file)
197 {
198         return single_open(file, ci_requests_show, inode->i_private);
199 }
200
201 static const struct file_operations ci_requests_fops = {
202         .open           = ci_requests_open,
203         .read           = seq_read,
204         .llseek         = seq_lseek,
205         .release        = single_release,
206 };
207
208 static int ci_role_show(struct seq_file *s, void *data)
209 {
210         struct ci_hdrc *ci = s->private;
211
212         seq_printf(s, "%s\n", ci_role(ci)->name);
213
214         return 0;
215 }
216
217 static ssize_t ci_role_write(struct file *file, const char __user *ubuf,
218                              size_t count, loff_t *ppos)
219 {
220         struct seq_file *s = file->private_data;
221         struct ci_hdrc *ci = s->private;
222         enum ci_role role;
223         char buf[8];
224         int ret;
225
226         if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
227                 return -EFAULT;
228
229         for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
230                 if (ci->roles[role] &&
231                     !strncmp(buf, ci->roles[role]->name,
232                              strlen(ci->roles[role]->name)))
233                         break;
234
235         if (role == CI_ROLE_END || role == ci->role)
236                 return -EINVAL;
237
238         ci_role_stop(ci);
239         ret = ci_role_start(ci, role);
240
241         return ret ? ret : count;
242 }
243
244 static int ci_role_open(struct inode *inode, struct file *file)
245 {
246         return single_open(file, ci_role_show, inode->i_private);
247 }
248
249 static const struct file_operations ci_role_fops = {
250         .open           = ci_role_open,
251         .write          = ci_role_write,
252         .read           = seq_read,
253         .llseek         = seq_lseek,
254         .release        = single_release,
255 };
256
257 int ci_registers_show(struct seq_file *s, void *unused)
258 {
259         struct ci_hdrc *ci = s->private;
260         u32 tmp_reg;
261
262         if (!ci)
263                 return 0;
264
265         /* ------ Registers ----- */
266         tmp_reg = hw_read_intr_enable(ci);
267         seq_printf(s, "USBINTR reg: %08x\n", tmp_reg);
268
269         tmp_reg = hw_read_intr_status(ci);
270         seq_printf(s, "USBSTS reg: %08x\n", tmp_reg);
271
272         tmp_reg = hw_read(ci, OP_USBMODE, ~0);
273         seq_printf(s, "USBMODE reg: %08x\n", tmp_reg);
274
275         tmp_reg = hw_read(ci, OP_USBCMD, ~0);
276         seq_printf(s, "USBCMD reg: %08x\n", tmp_reg);
277
278         tmp_reg = hw_read(ci, OP_PORTSC, ~0);
279         seq_printf(s, "PORTSC reg: %08x\n", tmp_reg);
280
281         if (ci->is_otg) {
282                 tmp_reg = hw_read_otgsc(ci, ~0);
283                 seq_printf(s, "OTGSC reg: %08x\n", tmp_reg);
284         }
285
286         return 0;
287 }
288
289 static int ci_registers_open(struct inode *inode, struct file *file)
290 {
291         return single_open(file, ci_registers_show, inode->i_private);
292 }
293
294 static const struct file_operations ci_registers_fops = {
295         .open                   = ci_registers_open,
296         .read                   = seq_read,
297         .llseek                 = seq_lseek,
298         .release                = single_release,
299 };
300
301 /**
302  * dbg_create_files: initializes the attribute interface
303  * @ci: device
304  *
305  * This function returns an error code
306  */
307 int dbg_create_files(struct ci_hdrc *ci)
308 {
309         struct dentry *dent;
310
311         ci->debugfs = debugfs_create_dir(dev_name(ci->dev), NULL);
312         if (!ci->debugfs)
313                 return -ENOMEM;
314
315         dent = debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
316                                    &ci_device_fops);
317         if (!dent)
318                 goto err;
319
320         dent = debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs,
321                                    ci, &ci_port_test_fops);
322         if (!dent)
323                 goto err;
324
325         dent = debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
326                                    &ci_qheads_fops);
327         if (!dent)
328                 goto err;
329
330         dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
331                                    &ci_requests_fops);
332         if (!dent)
333                 goto err;
334
335         dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
336                                    &ci_role_fops);
337         if (!dent)
338                 goto err;
339
340         dent = debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci,
341                                 &ci_registers_fops);
342
343         if (dent)
344                 return 0;
345 err:
346         debugfs_remove_recursive(ci->debugfs);
347         return -ENOMEM;
348 }
349
350 /**
351  * dbg_remove_files: destroys the attribute interface
352  * @ci: device
353  */
354 void dbg_remove_files(struct ci_hdrc *ci)
355 {
356         debugfs_remove_recursive(ci->debugfs);
357 }
This page took 0.056957 seconds and 4 git commands to generate.