mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / usb / host / ohci-dbg.c
blob17e698f918f7445b846c691546eee5e5965801f1
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under the GPL.
8 */
10 /*-------------------------------------------------------------------------*/
12 #ifdef DEBUG
14 #define edstring(ed_type) ({ char *temp; \
15 switch (ed_type) { \
16 case PIPE_CONTROL: temp = "ctrl"; break; \
17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \
20 }; temp;})
21 #define pipestring(pipe) edstring(usb_pipetype(pipe))
23 /* debug| print the main components of an URB
24 * small: 0) header + data packets 1) just header
26 static void __maybe_unused
27 urb_print(struct urb * urb, char * str, int small, int status)
29 unsigned int pipe= urb->pipe;
31 if (!urb->dev || !urb->dev->bus) {
32 printk(KERN_DEBUG "%s URB: no dev\n", str);
33 return;
36 #ifndef OHCI_VERBOSE_DEBUG
37 if (status != 0)
38 #endif
39 printk(KERN_DEBUG "%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d\n",
40 str,
41 urb,
42 usb_pipedevice (pipe),
43 usb_pipeendpoint (pipe),
44 usb_pipeout (pipe)? "out" : "in",
45 pipestring (pipe),
46 urb->transfer_flags,
47 urb->actual_length,
48 urb->transfer_buffer_length,
49 status);
51 #ifdef OHCI_VERBOSE_DEBUG
52 if (!small) {
53 int i, len;
55 if (usb_pipecontrol (pipe)) {
56 printk (KERN_DEBUG "%s: setup(8):", __FILE__);
57 for (i = 0; i < 8 ; i++)
58 printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
59 printk ("\n");
61 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
62 printk (KERN_DEBUG "%s: data(%d/%d):", __FILE__,
63 urb->actual_length,
64 urb->transfer_buffer_length);
65 len = usb_pipeout (pipe)?
66 urb->transfer_buffer_length: urb->actual_length;
67 for (i = 0; i < 16 && i < len; i++)
68 printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]);
69 printk ("%s stat:%d\n", i < len? "...": "", status);
72 #endif
75 #define ohci_dbg_sw(ohci, next, size, format, arg...) \
76 do { \
77 if (next != NULL) { \
78 unsigned s_len; \
79 s_len = scnprintf (*next, *size, format, ## arg ); \
80 *size -= s_len; *next += s_len; \
81 } else \
82 ohci_dbg(ohci,format, ## arg ); \
83 } while (0);
85 /* Version for use where "next" is the address of a local variable */
86 #define ohci_dbg_nosw(ohci, next, size, format, arg...) \
87 do { \
88 unsigned s_len; \
89 s_len = scnprintf(*next, *size, format, ## arg); \
90 *size -= s_len; *next += s_len; \
91 } while (0);
94 static void ohci_dump_intr_mask (
95 struct ohci_hcd *ohci,
96 char *label,
97 u32 mask,
98 char **next,
99 unsigned *size)
101 ohci_dbg_sw (ohci, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s\n",
102 label,
103 mask,
104 (mask & OHCI_INTR_MIE) ? " MIE" : "",
105 (mask & OHCI_INTR_OC) ? " OC" : "",
106 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
107 (mask & OHCI_INTR_FNO) ? " FNO" : "",
108 (mask & OHCI_INTR_UE) ? " UE" : "",
109 (mask & OHCI_INTR_RD) ? " RD" : "",
110 (mask & OHCI_INTR_SF) ? " SF" : "",
111 (mask & OHCI_INTR_WDH) ? " WDH" : "",
112 (mask & OHCI_INTR_SO) ? " SO" : ""
116 static void maybe_print_eds (
117 struct ohci_hcd *ohci,
118 char *label,
119 u32 value,
120 char **next,
121 unsigned *size)
123 if (value)
124 ohci_dbg_sw (ohci, next, size, "%s %08x\n", label, value);
127 static char *hcfs2string (int state)
129 switch (state) {
130 case OHCI_USB_RESET: return "reset";
131 case OHCI_USB_RESUME: return "resume";
132 case OHCI_USB_OPER: return "operational";
133 case OHCI_USB_SUSPEND: return "suspend";
135 return "?";
138 static const char *rh_state_string(struct ohci_hcd *ohci)
140 switch (ohci->rh_state) {
141 case OHCI_RH_HALTED:
142 return "halted";
143 case OHCI_RH_SUSPENDED:
144 return "suspended";
145 case OHCI_RH_RUNNING:
146 return "running";
148 return "?";
151 // dump control and status registers
152 static void
153 ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
155 struct ohci_regs __iomem *regs = controller->regs;
156 u32 temp;
158 temp = ohci_readl (controller, &regs->revision) & 0xff;
159 ohci_dbg_sw (controller, next, size,
160 "OHCI %d.%d, %s legacy support registers, rh state %s\n",
161 0x03 & (temp >> 4), (temp & 0x0f),
162 (temp & 0x0100) ? "with" : "NO",
163 rh_state_string(controller));
165 temp = ohci_readl (controller, &regs->control);
166 ohci_dbg_sw (controller, next, size,
167 "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
168 temp,
169 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
170 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
171 (temp & OHCI_CTRL_IR) ? " IR" : "",
172 hcfs2string (temp & OHCI_CTRL_HCFS),
173 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
174 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
175 (temp & OHCI_CTRL_IE) ? " IE" : "",
176 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
177 temp & OHCI_CTRL_CBSR
180 temp = ohci_readl (controller, &regs->cmdstatus);
181 ohci_dbg_sw (controller, next, size,
182 "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp,
183 (temp & OHCI_SOC) >> 16,
184 (temp & OHCI_OCR) ? " OCR" : "",
185 (temp & OHCI_BLF) ? " BLF" : "",
186 (temp & OHCI_CLF) ? " CLF" : "",
187 (temp & OHCI_HCR) ? " HCR" : ""
190 ohci_dump_intr_mask (controller, "intrstatus",
191 ohci_readl (controller, &regs->intrstatus),
192 next, size);
193 ohci_dump_intr_mask (controller, "intrenable",
194 ohci_readl (controller, &regs->intrenable),
195 next, size);
196 // intrdisable always same as intrenable
198 maybe_print_eds (controller, "ed_periodcurrent",
199 ohci_readl (controller, &regs->ed_periodcurrent),
200 next, size);
202 maybe_print_eds (controller, "ed_controlhead",
203 ohci_readl (controller, &regs->ed_controlhead),
204 next, size);
205 maybe_print_eds (controller, "ed_controlcurrent",
206 ohci_readl (controller, &regs->ed_controlcurrent),
207 next, size);
209 maybe_print_eds (controller, "ed_bulkhead",
210 ohci_readl (controller, &regs->ed_bulkhead),
211 next, size);
212 maybe_print_eds (controller, "ed_bulkcurrent",
213 ohci_readl (controller, &regs->ed_bulkcurrent),
214 next, size);
216 maybe_print_eds (controller, "donehead",
217 ohci_readl (controller, &regs->donehead), next, size);
220 #define dbg_port_sw(hc,num,value,next,size) \
221 ohci_dbg_sw (hc, next, size, \
222 "roothub.portstatus [%d] " \
223 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
224 num, temp, \
225 (temp & RH_PS_PRSC) ? " PRSC" : "", \
226 (temp & RH_PS_OCIC) ? " OCIC" : "", \
227 (temp & RH_PS_PSSC) ? " PSSC" : "", \
228 (temp & RH_PS_PESC) ? " PESC" : "", \
229 (temp & RH_PS_CSC) ? " CSC" : "", \
231 (temp & RH_PS_LSDA) ? " LSDA" : "", \
232 (temp & RH_PS_PPS) ? " PPS" : "", \
233 (temp & RH_PS_PRS) ? " PRS" : "", \
234 (temp & RH_PS_POCI) ? " POCI" : "", \
235 (temp & RH_PS_PSS) ? " PSS" : "", \
237 (temp & RH_PS_PES) ? " PES" : "", \
238 (temp & RH_PS_CCS) ? " CCS" : "" \
242 static void
243 ohci_dump_roothub (
244 struct ohci_hcd *controller,
245 int verbose,
246 char **next,
247 unsigned *size)
249 u32 temp, i;
251 temp = roothub_a (controller);
252 if (temp == ~(u32)0)
253 return;
255 if (verbose) {
256 ohci_dbg_sw (controller, next, size,
257 "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d(%d)\n", temp,
258 ((temp & RH_A_POTPGT) >> 24) & 0xff,
259 (temp & RH_A_NOCP) ? " NOCP" : "",
260 (temp & RH_A_OCPM) ? " OCPM" : "",
261 (temp & RH_A_DT) ? " DT" : "",
262 (temp & RH_A_NPS) ? " NPS" : "",
263 (temp & RH_A_PSM) ? " PSM" : "",
264 (temp & RH_A_NDP), controller->num_ports
266 temp = roothub_b (controller);
267 ohci_dbg_sw (controller, next, size,
268 "roothub.b %08x PPCM=%04x DR=%04x\n",
269 temp,
270 (temp & RH_B_PPCM) >> 16,
271 (temp & RH_B_DR)
273 temp = roothub_status (controller);
274 ohci_dbg_sw (controller, next, size,
275 "roothub.status %08x%s%s%s%s%s%s\n",
276 temp,
277 (temp & RH_HS_CRWE) ? " CRWE" : "",
278 (temp & RH_HS_OCIC) ? " OCIC" : "",
279 (temp & RH_HS_LPSC) ? " LPSC" : "",
280 (temp & RH_HS_DRWE) ? " DRWE" : "",
281 (temp & RH_HS_OCI) ? " OCI" : "",
282 (temp & RH_HS_LPS) ? " LPS" : ""
286 for (i = 0; i < controller->num_ports; i++) {
287 temp = roothub_portstatus (controller, i);
288 dbg_port_sw (controller, i, temp, next, size);
292 static void ohci_dump(struct ohci_hcd *controller)
294 ohci_dbg (controller, "OHCI controller state\n");
296 // dumps some of the state we know about
297 ohci_dump_status (controller, NULL, NULL);
298 if (controller->hcca)
299 ohci_dbg (controller,
300 "hcca frame #%04x\n", ohci_frame_no(controller));
301 ohci_dump_roothub (controller, 1, NULL, NULL);
304 static const char data0 [] = "DATA0";
305 static const char data1 [] = "DATA1";
307 static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label,
308 const struct td *td)
310 u32 tmp = hc32_to_cpup (ohci, &td->hwINFO);
312 ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x\n",
313 label, td,
314 (tmp & TD_DONE) ? " (DONE)" : "",
315 td->urb, td->index,
316 hc32_to_cpup (ohci, &td->hwNextTD));
317 if ((tmp & TD_ISO) == 0) {
318 const char *toggle, *pid;
319 u32 cbp, be;
321 switch (tmp & TD_T) {
322 case TD_T_DATA0: toggle = data0; break;
323 case TD_T_DATA1: toggle = data1; break;
324 case TD_T_TOGGLE: toggle = "(CARRY)"; break;
325 default: toggle = "(?)"; break;
327 switch (tmp & TD_DP) {
328 case TD_DP_SETUP: pid = "SETUP"; break;
329 case TD_DP_IN: pid = "IN"; break;
330 case TD_DP_OUT: pid = "OUT"; break;
331 default: pid = "(bad pid)"; break;
333 ohci_dbg (ohci, " info %08x CC=%x %s DI=%d %s %s\n", tmp,
334 TD_CC_GET(tmp), /* EC, */ toggle,
335 (tmp & TD_DI) >> 21, pid,
336 (tmp & TD_R) ? "R" : "");
337 cbp = hc32_to_cpup (ohci, &td->hwCBP);
338 be = hc32_to_cpup (ohci, &td->hwBE);
339 ohci_dbg (ohci, " cbp %08x be %08x (len %d)\n", cbp, be,
340 cbp ? (be + 1 - cbp) : 0);
341 } else {
342 unsigned i;
343 ohci_dbg (ohci, " info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp,
344 TD_CC_GET(tmp),
345 (tmp >> 24) & 0x07,
346 (tmp & TD_DI) >> 21,
347 tmp & 0x0000ffff);
348 ohci_dbg (ohci, " bp0 %08x be %08x\n",
349 hc32_to_cpup (ohci, &td->hwCBP) & ~0x0fff,
350 hc32_to_cpup (ohci, &td->hwBE));
351 for (i = 0; i < MAXPSW; i++) {
352 u16 psw = ohci_hwPSW (ohci, td, i);
353 int cc = (psw >> 12) & 0x0f;
354 ohci_dbg (ohci, " psw [%d] = %2x, CC=%x %s=%d\n", i,
355 psw, cc,
356 (cc >= 0x0e) ? "OFFSET" : "SIZE",
357 psw & 0x0fff);
362 /* caller MUST own hcd spinlock if verbose is set! */
363 static void __maybe_unused
364 ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
365 const struct ed *ed, int verbose)
367 u32 tmp = hc32_to_cpu (ohci, ed->hwINFO);
368 char *type = "";
370 ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
371 label,
372 ed, ed->state, edstring (ed->type),
373 hc32_to_cpup (ohci, &ed->hwNextED));
374 switch (tmp & (ED_IN|ED_OUT)) {
375 case ED_OUT: type = "-OUT"; break;
376 case ED_IN: type = "-IN"; break;
377 /* else from TDs ... control */
379 ohci_dbg (ohci,
380 " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp,
381 0x03ff & (tmp >> 16),
382 (tmp & ED_DEQUEUE) ? " DQ" : "",
383 (tmp & ED_ISO) ? " ISO" : "",
384 (tmp & ED_SKIP) ? " SKIP" : "",
385 (tmp & ED_LOWSPEED) ? " LOW" : "",
386 0x000f & (tmp >> 7),
387 type,
388 0x007f & tmp);
389 tmp = hc32_to_cpup (ohci, &ed->hwHeadP);
390 ohci_dbg (ohci, " tds: head %08x %s%s tail %08x%s\n",
391 tmp,
392 (tmp & ED_C) ? data1 : data0,
393 (tmp & ED_H) ? " HALT" : "",
394 hc32_to_cpup (ohci, &ed->hwTailP),
395 verbose ? "" : " (not listing)");
396 if (verbose) {
397 struct list_head *tmp;
399 /* use ed->td_list because HC concurrently modifies
400 * hwNextTD as it accumulates ed_donelist.
402 list_for_each (tmp, &ed->td_list) {
403 struct td *td;
404 td = list_entry (tmp, struct td, td_list);
405 ohci_dump_td (ohci, " ->", td);
410 #else
411 static inline void ohci_dump (struct ohci_hcd *controller) {}
413 #undef OHCI_VERBOSE_DEBUG
415 #endif /* DEBUG */
417 /*-------------------------------------------------------------------------*/
419 #ifdef STUB_DEBUG_FILES
421 static inline void create_debug_files (struct ohci_hcd *bus) { }
422 static inline void remove_debug_files (struct ohci_hcd *bus) { }
424 #else
426 static int debug_async_open(struct inode *, struct file *);
427 static int debug_periodic_open(struct inode *, struct file *);
428 static int debug_registers_open(struct inode *, struct file *);
429 static int debug_async_open(struct inode *, struct file *);
430 static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
431 static int debug_close(struct inode *, struct file *);
433 static const struct file_operations debug_async_fops = {
434 .owner = THIS_MODULE,
435 .open = debug_async_open,
436 .read = debug_output,
437 .release = debug_close,
438 .llseek = default_llseek,
440 static const struct file_operations debug_periodic_fops = {
441 .owner = THIS_MODULE,
442 .open = debug_periodic_open,
443 .read = debug_output,
444 .release = debug_close,
445 .llseek = default_llseek,
447 static const struct file_operations debug_registers_fops = {
448 .owner = THIS_MODULE,
449 .open = debug_registers_open,
450 .read = debug_output,
451 .release = debug_close,
452 .llseek = default_llseek,
455 static struct dentry *ohci_debug_root;
457 struct debug_buffer {
458 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
459 struct ohci_hcd *ohci;
460 struct mutex mutex; /* protect filling of buffer */
461 size_t count; /* number of characters filled into buffer */
462 char *page;
465 static ssize_t
466 show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
468 unsigned temp, size = count;
470 if (!ed)
471 return 0;
473 /* print first --> last */
474 while (ed->ed_prev)
475 ed = ed->ed_prev;
477 /* dump a snapshot of the bulk or control schedule */
478 while (ed) {
479 u32 info = hc32_to_cpu (ohci, ed->hwINFO);
480 u32 headp = hc32_to_cpu (ohci, ed->hwHeadP);
481 struct list_head *entry;
482 struct td *td;
484 temp = scnprintf (buf, size,
485 "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
487 (info & ED_LOWSPEED) ? 'l' : 'f',
488 info & 0x7f,
489 (info >> 7) & 0xf,
490 (info & ED_IN) ? "in" : "out",
491 0x03ff & (info >> 16),
492 info,
493 (info & ED_SKIP) ? " s" : "",
494 (headp & ED_H) ? " H" : "",
495 (headp & ED_C) ? data1 : data0);
496 size -= temp;
497 buf += temp;
499 list_for_each (entry, &ed->td_list) {
500 u32 cbp, be;
502 td = list_entry (entry, struct td, td_list);
503 info = hc32_to_cpup (ohci, &td->hwINFO);
504 cbp = hc32_to_cpup (ohci, &td->hwCBP);
505 be = hc32_to_cpup (ohci, &td->hwBE);
506 temp = scnprintf (buf, size,
507 "\n\ttd %p %s %d cc=%x urb %p (%08x)",
509 ({ char *pid;
510 switch (info & TD_DP) {
511 case TD_DP_SETUP: pid = "setup"; break;
512 case TD_DP_IN: pid = "in"; break;
513 case TD_DP_OUT: pid = "out"; break;
514 default: pid = "(?)"; break;
515 } pid;}),
516 cbp ? (be + 1 - cbp) : 0,
517 TD_CC_GET (info), td->urb, info);
518 size -= temp;
519 buf += temp;
522 temp = scnprintf (buf, size, "\n");
523 size -= temp;
524 buf += temp;
526 ed = ed->ed_next;
528 return count - size;
531 static ssize_t fill_async_buffer(struct debug_buffer *buf)
533 struct ohci_hcd *ohci;
534 size_t temp, size;
535 unsigned long flags;
537 ohci = buf->ohci;
538 size = PAGE_SIZE;
540 /* display control and bulk lists together, for simplicity */
541 spin_lock_irqsave (&ohci->lock, flags);
542 temp = show_list(ohci, buf->page, size, ohci->ed_controltail);
543 temp += show_list(ohci, buf->page + temp, size - temp,
544 ohci->ed_bulktail);
545 spin_unlock_irqrestore (&ohci->lock, flags);
547 return temp;
550 #define DBG_SCHED_LIMIT 64
552 static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
554 struct ohci_hcd *ohci;
555 struct ed **seen, *ed;
556 unsigned long flags;
557 unsigned temp, size, seen_count;
558 char *next;
559 unsigned i;
561 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
562 return 0;
563 seen_count = 0;
565 ohci = buf->ohci;
566 next = buf->page;
567 size = PAGE_SIZE;
569 temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
570 size -= temp;
571 next += temp;
573 /* dump a snapshot of the periodic schedule (and load) */
574 spin_lock_irqsave (&ohci->lock, flags);
575 for (i = 0; i < NUM_INTS; i++) {
576 if (!(ed = ohci->periodic [i]))
577 continue;
579 temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
580 size -= temp;
581 next += temp;
583 do {
584 temp = scnprintf (next, size, " ed%d/%p",
585 ed->interval, ed);
586 size -= temp;
587 next += temp;
588 for (temp = 0; temp < seen_count; temp++) {
589 if (seen [temp] == ed)
590 break;
593 /* show more info the first time around */
594 if (temp == seen_count) {
595 u32 info = hc32_to_cpu (ohci, ed->hwINFO);
596 struct list_head *entry;
597 unsigned qlen = 0;
599 /* qlen measured here in TDs, not urbs */
600 list_for_each (entry, &ed->td_list)
601 qlen++;
603 temp = scnprintf (next, size,
604 " (%cs dev%d ep%d%s-%s qlen %u"
605 " max %d %08x%s%s)",
606 (info & ED_LOWSPEED) ? 'l' : 'f',
607 info & 0x7f,
608 (info >> 7) & 0xf,
609 (info & ED_IN) ? "in" : "out",
610 (info & ED_ISO) ? "iso" : "int",
611 qlen,
612 0x03ff & (info >> 16),
613 info,
614 (info & ED_SKIP) ? " K" : "",
615 (ed->hwHeadP &
616 cpu_to_hc32(ohci, ED_H)) ?
617 " H" : "");
618 size -= temp;
619 next += temp;
621 if (seen_count < DBG_SCHED_LIMIT)
622 seen [seen_count++] = ed;
624 ed = ed->ed_next;
626 } else {
627 /* we've seen it and what's after */
628 temp = 0;
629 ed = NULL;
632 } while (ed);
634 temp = scnprintf (next, size, "\n");
635 size -= temp;
636 next += temp;
638 spin_unlock_irqrestore (&ohci->lock, flags);
639 kfree (seen);
641 return PAGE_SIZE - size;
643 #undef DBG_SCHED_LIMIT
645 static ssize_t fill_registers_buffer(struct debug_buffer *buf)
647 struct usb_hcd *hcd;
648 struct ohci_hcd *ohci;
649 struct ohci_regs __iomem *regs;
650 unsigned long flags;
651 unsigned temp, size;
652 char *next;
653 u32 rdata;
655 ohci = buf->ohci;
656 hcd = ohci_to_hcd(ohci);
657 regs = ohci->regs;
658 next = buf->page;
659 size = PAGE_SIZE;
661 spin_lock_irqsave (&ohci->lock, flags);
663 /* dump driver info, then registers in spec order */
665 ohci_dbg_nosw(ohci, &next, &size,
666 "bus %s, device %s\n"
667 "%s\n"
668 "%s\n",
669 hcd->self.controller->bus->name,
670 dev_name(hcd->self.controller),
671 hcd->product_desc,
672 hcd_name);
674 if (!HCD_HW_ACCESSIBLE(hcd)) {
675 size -= scnprintf (next, size,
676 "SUSPENDED (no register access)\n");
677 goto done;
680 ohci_dump_status(ohci, &next, &size);
682 /* hcca */
683 if (ohci->hcca)
684 ohci_dbg_nosw(ohci, &next, &size,
685 "hcca frame 0x%04x\n", ohci_frame_no(ohci));
687 /* other registers mostly affect frame timings */
688 rdata = ohci_readl (ohci, &regs->fminterval);
689 temp = scnprintf (next, size,
690 "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
691 rdata, (rdata >> 31) ? "FIT " : "",
692 (rdata >> 16) & 0xefff, rdata & 0xffff);
693 size -= temp;
694 next += temp;
696 rdata = ohci_readl (ohci, &regs->fmremaining);
697 temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
698 rdata, (rdata >> 31) ? "FRT " : "",
699 rdata & 0x3fff);
700 size -= temp;
701 next += temp;
703 rdata = ohci_readl (ohci, &regs->periodicstart);
704 temp = scnprintf (next, size, "periodicstart 0x%04x\n",
705 rdata & 0x3fff);
706 size -= temp;
707 next += temp;
709 rdata = ohci_readl (ohci, &regs->lsthresh);
710 temp = scnprintf (next, size, "lsthresh 0x%04x\n",
711 rdata & 0x3fff);
712 size -= temp;
713 next += temp;
715 temp = scnprintf (next, size, "hub poll timer %s\n",
716 HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
717 size -= temp;
718 next += temp;
720 /* roothub */
721 ohci_dump_roothub (ohci, 1, &next, &size);
723 done:
724 spin_unlock_irqrestore (&ohci->lock, flags);
726 return PAGE_SIZE - size;
729 static struct debug_buffer *alloc_buffer(struct ohci_hcd *ohci,
730 ssize_t (*fill_func)(struct debug_buffer *))
732 struct debug_buffer *buf;
734 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
736 if (buf) {
737 buf->ohci = ohci;
738 buf->fill_func = fill_func;
739 mutex_init(&buf->mutex);
742 return buf;
745 static int fill_buffer(struct debug_buffer *buf)
747 int ret = 0;
749 if (!buf->page)
750 buf->page = (char *)get_zeroed_page(GFP_KERNEL);
752 if (!buf->page) {
753 ret = -ENOMEM;
754 goto out;
757 ret = buf->fill_func(buf);
759 if (ret >= 0) {
760 buf->count = ret;
761 ret = 0;
764 out:
765 return ret;
768 static ssize_t debug_output(struct file *file, char __user *user_buf,
769 size_t len, loff_t *offset)
771 struct debug_buffer *buf = file->private_data;
772 int ret = 0;
774 mutex_lock(&buf->mutex);
775 if (buf->count == 0) {
776 ret = fill_buffer(buf);
777 if (ret != 0) {
778 mutex_unlock(&buf->mutex);
779 goto out;
782 mutex_unlock(&buf->mutex);
784 ret = simple_read_from_buffer(user_buf, len, offset,
785 buf->page, buf->count);
787 out:
788 return ret;
792 static int debug_close(struct inode *inode, struct file *file)
794 struct debug_buffer *buf = file->private_data;
796 if (buf) {
797 if (buf->page)
798 free_page((unsigned long)buf->page);
799 kfree(buf);
802 return 0;
804 static int debug_async_open(struct inode *inode, struct file *file)
806 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
808 return file->private_data ? 0 : -ENOMEM;
811 static int debug_periodic_open(struct inode *inode, struct file *file)
813 file->private_data = alloc_buffer(inode->i_private,
814 fill_periodic_buffer);
816 return file->private_data ? 0 : -ENOMEM;
819 static int debug_registers_open(struct inode *inode, struct file *file)
821 file->private_data = alloc_buffer(inode->i_private,
822 fill_registers_buffer);
824 return file->private_data ? 0 : -ENOMEM;
826 static inline void create_debug_files (struct ohci_hcd *ohci)
828 struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
830 ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
831 if (!ohci->debug_dir)
832 goto dir_error;
834 ohci->debug_async = debugfs_create_file("async", S_IRUGO,
835 ohci->debug_dir, ohci,
836 &debug_async_fops);
837 if (!ohci->debug_async)
838 goto async_error;
840 ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
841 ohci->debug_dir, ohci,
842 &debug_periodic_fops);
843 if (!ohci->debug_periodic)
844 goto periodic_error;
846 ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
847 ohci->debug_dir, ohci,
848 &debug_registers_fops);
849 if (!ohci->debug_registers)
850 goto registers_error;
852 ohci_dbg (ohci, "created debug files\n");
853 return;
855 registers_error:
856 debugfs_remove(ohci->debug_periodic);
857 periodic_error:
858 debugfs_remove(ohci->debug_async);
859 async_error:
860 debugfs_remove(ohci->debug_dir);
861 dir_error:
862 ohci->debug_periodic = NULL;
863 ohci->debug_async = NULL;
864 ohci->debug_dir = NULL;
867 static inline void remove_debug_files (struct ohci_hcd *ohci)
869 debugfs_remove(ohci->debug_registers);
870 debugfs_remove(ohci->debug_periodic);
871 debugfs_remove(ohci->debug_async);
872 debugfs_remove(ohci->debug_dir);
875 #endif
877 /*-------------------------------------------------------------------------*/