Merge branch 'drm-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6
[linux-2.6] / drivers / usb / host / ohci-dbg.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6  *
7  * This file is licenced under the GPL.
8  */
9
10 /*-------------------------------------------------------------------------*/
11
12 #ifdef DEBUG
13
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))
22
23 /* debug| print the main components of an URB
24  * small: 0) header + data packets 1) just header
25  */
26 static void __attribute__((unused))
27 urb_print (struct urb * urb, char * str, int small)
28 {
29         unsigned int pipe= urb->pipe;
30
31         if (!urb->dev || !urb->dev->bus) {
32                 dbg("%s URB: no dev", str);
33                 return;
34         }
35
36 #ifndef OHCI_VERBOSE_DEBUG
37         if (urb->status != 0)
38 #endif
39         dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d",
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                     urb->status);
50
51 #ifdef  OHCI_VERBOSE_DEBUG
52         if (!small) {
53                 int i, len;
54
55                 if (usb_pipecontrol (pipe)) {
56                         printk (KERN_DEBUG __FILE__ ": setup(8):");
57                         for (i = 0; i < 8 ; i++)
58                                 printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
59                         printk ("\n");
60                 }
61                 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
62                         printk (KERN_DEBUG __FILE__ ": data(%d/%d):",
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? "...": "", urb->status);
70                 }
71         }
72 #endif
73 }
74
75 #define ohci_dbg_sw(ohci, next, size, format, arg...) \
76         do { \
77         if (next) { \
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);
84
85
86 static void ohci_dump_intr_mask (
87         struct ohci_hcd *ohci,
88         char *label,
89         u32 mask,
90         char **next,
91         unsigned *size)
92 {
93         ohci_dbg_sw (ohci, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s\n",
94                 label,
95                 mask,
96                 (mask & OHCI_INTR_MIE) ? " MIE" : "",
97                 (mask & OHCI_INTR_OC) ? " OC" : "",
98                 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
99                 (mask & OHCI_INTR_FNO) ? " FNO" : "",
100                 (mask & OHCI_INTR_UE) ? " UE" : "",
101                 (mask & OHCI_INTR_RD) ? " RD" : "",
102                 (mask & OHCI_INTR_SF) ? " SF" : "",
103                 (mask & OHCI_INTR_WDH) ? " WDH" : "",
104                 (mask & OHCI_INTR_SO) ? " SO" : ""
105                 );
106 }
107
108 static void maybe_print_eds (
109         struct ohci_hcd *ohci,
110         char *label,
111         u32 value,
112         char **next,
113         unsigned *size)
114 {
115         if (value)
116                 ohci_dbg_sw (ohci, next, size, "%s %08x\n", label, value);
117 }
118
119 static char *hcfs2string (int state)
120 {
121         switch (state) {
122                 case OHCI_USB_RESET:    return "reset";
123                 case OHCI_USB_RESUME:   return "resume";
124                 case OHCI_USB_OPER:     return "operational";
125                 case OHCI_USB_SUSPEND:  return "suspend";
126         }
127         return "?";
128 }
129
130 // dump control and status registers
131 static void
132 ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
133 {
134         struct ohci_regs __iomem *regs = controller->regs;
135         u32                     temp;
136
137         temp = ohci_readl (controller, &regs->revision) & 0xff;
138         ohci_dbg_sw (controller, next, size,
139                 "OHCI %d.%d, %s legacy support registers\n",
140                 0x03 & (temp >> 4), (temp & 0x0f),
141                 (temp & 0x0100) ? "with" : "NO");
142
143         temp = ohci_readl (controller, &regs->control);
144         ohci_dbg_sw (controller, next, size,
145                 "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
146                 temp,
147                 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
148                 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
149                 (temp & OHCI_CTRL_IR) ? " IR" : "",
150                 hcfs2string (temp & OHCI_CTRL_HCFS),
151                 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
152                 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
153                 (temp & OHCI_CTRL_IE) ? " IE" : "",
154                 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
155                 temp & OHCI_CTRL_CBSR
156                 );
157
158         temp = ohci_readl (controller, &regs->cmdstatus);
159         ohci_dbg_sw (controller, next, size,
160                 "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp,
161                 (temp & OHCI_SOC) >> 16,
162                 (temp & OHCI_OCR) ? " OCR" : "",
163                 (temp & OHCI_BLF) ? " BLF" : "",
164                 (temp & OHCI_CLF) ? " CLF" : "",
165                 (temp & OHCI_HCR) ? " HCR" : ""
166                 );
167
168         ohci_dump_intr_mask (controller, "intrstatus",
169                         ohci_readl (controller, &regs->intrstatus),
170                         next, size);
171         ohci_dump_intr_mask (controller, "intrenable",
172                         ohci_readl (controller, &regs->intrenable),
173                         next, size);
174         // intrdisable always same as intrenable
175
176         maybe_print_eds (controller, "ed_periodcurrent",
177                         ohci_readl (controller, &regs->ed_periodcurrent),
178                         next, size);
179
180         maybe_print_eds (controller, "ed_controlhead",
181                         ohci_readl (controller, &regs->ed_controlhead),
182                         next, size);
183         maybe_print_eds (controller, "ed_controlcurrent",
184                         ohci_readl (controller, &regs->ed_controlcurrent),
185                         next, size);
186
187         maybe_print_eds (controller, "ed_bulkhead",
188                         ohci_readl (controller, &regs->ed_bulkhead),
189                         next, size);
190         maybe_print_eds (controller, "ed_bulkcurrent",
191                         ohci_readl (controller, &regs->ed_bulkcurrent),
192                         next, size);
193
194         maybe_print_eds (controller, "donehead",
195                         ohci_readl (controller, &regs->donehead), next, size);
196
197         /* broken fminterval means traffic won't flow! */ 
198         ohci_dbg (controller, "fminterval %08x\n", 
199                         ohci_readl (controller, &regs->fminterval));
200 }
201
202 #define dbg_port_sw(hc,num,value,next,size) \
203         ohci_dbg_sw (hc, next, size, \
204                 "roothub.portstatus [%d] " \
205                 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
206                 num, temp, \
207                 (temp & RH_PS_PRSC) ? " PRSC" : "", \
208                 (temp & RH_PS_OCIC) ? " OCIC" : "", \
209                 (temp & RH_PS_PSSC) ? " PSSC" : "", \
210                 (temp & RH_PS_PESC) ? " PESC" : "", \
211                 (temp & RH_PS_CSC) ? " CSC" : "", \
212                 \
213                 (temp & RH_PS_LSDA) ? " LSDA" : "", \
214                 (temp & RH_PS_PPS) ? " PPS" : "", \
215                 (temp & RH_PS_PRS) ? " PRS" : "", \
216                 (temp & RH_PS_POCI) ? " POCI" : "", \
217                 (temp & RH_PS_PSS) ? " PSS" : "", \
218                 \
219                 (temp & RH_PS_PES) ? " PES" : "", \
220                 (temp & RH_PS_CCS) ? " CCS" : "" \
221                 );
222
223
224 static void
225 ohci_dump_roothub (
226         struct ohci_hcd *controller,
227         int verbose,
228         char **next,
229         unsigned *size)
230 {
231         u32                     temp, ndp, i;
232
233         temp = roothub_a (controller);
234         if (temp == ~(u32)0)
235                 return;
236         ndp = (temp & RH_A_NDP);
237
238         if (verbose) {
239                 ohci_dbg_sw (controller, next, size,
240                         "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d\n", temp,
241                         ((temp & RH_A_POTPGT) >> 24) & 0xff,
242                         (temp & RH_A_NOCP) ? " NOCP" : "",
243                         (temp & RH_A_OCPM) ? " OCPM" : "",
244                         (temp & RH_A_DT) ? " DT" : "",
245                         (temp & RH_A_NPS) ? " NPS" : "",
246                         (temp & RH_A_PSM) ? " PSM" : "",
247                         ndp
248                         );
249                 temp = roothub_b (controller);
250                 ohci_dbg_sw (controller, next, size,
251                         "roothub.b %08x PPCM=%04x DR=%04x\n",
252                         temp,
253                         (temp & RH_B_PPCM) >> 16,
254                         (temp & RH_B_DR)
255                         );
256                 temp = roothub_status (controller);
257                 ohci_dbg_sw (controller, next, size,
258                         "roothub.status %08x%s%s%s%s%s%s\n",
259                         temp,
260                         (temp & RH_HS_CRWE) ? " CRWE" : "",
261                         (temp & RH_HS_OCIC) ? " OCIC" : "",
262                         (temp & RH_HS_LPSC) ? " LPSC" : "",
263                         (temp & RH_HS_DRWE) ? " DRWE" : "",
264                         (temp & RH_HS_OCI) ? " OCI" : "",
265                         (temp & RH_HS_LPS) ? " LPS" : ""
266                         );
267         }
268
269         for (i = 0; i < ndp; i++) {
270                 temp = roothub_portstatus (controller, i);
271                 dbg_port_sw (controller, i, temp, next, size);
272         }
273 }
274
275 static void ohci_dump (struct ohci_hcd *controller, int verbose)
276 {
277         ohci_dbg (controller, "OHCI controller state\n");
278
279         // dumps some of the state we know about
280         ohci_dump_status (controller, NULL, NULL);
281         if (controller->hcca)
282                 ohci_dbg (controller,
283                         "hcca frame #%04x\n", ohci_frame_no(controller));
284         ohci_dump_roothub (controller, 1, NULL, NULL);
285 }
286
287 static const char data0 [] = "DATA0";
288 static const char data1 [] = "DATA1";
289
290 static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label,
291                 const struct td *td)
292 {
293         u32     tmp = hc32_to_cpup (ohci, &td->hwINFO);
294
295         ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x\n",
296                 label, td,
297                 (tmp & TD_DONE) ? " (DONE)" : "",
298                 td->urb, td->index,
299                 hc32_to_cpup (ohci, &td->hwNextTD));
300         if ((tmp & TD_ISO) == 0) {
301                 const char      *toggle, *pid;
302                 u32     cbp, be;
303
304                 switch (tmp & TD_T) {
305                 case TD_T_DATA0: toggle = data0; break;
306                 case TD_T_DATA1: toggle = data1; break;
307                 case TD_T_TOGGLE: toggle = "(CARRY)"; break;
308                 default: toggle = "(?)"; break;
309                 }
310                 switch (tmp & TD_DP) {
311                 case TD_DP_SETUP: pid = "SETUP"; break;
312                 case TD_DP_IN: pid = "IN"; break;
313                 case TD_DP_OUT: pid = "OUT"; break;
314                 default: pid = "(bad pid)"; break;
315                 }
316                 ohci_dbg (ohci, "     info %08x CC=%x %s DI=%d %s %s\n", tmp,
317                         TD_CC_GET(tmp), /* EC, */ toggle,
318                         (tmp & TD_DI) >> 21, pid,
319                         (tmp & TD_R) ? "R" : "");
320                 cbp = hc32_to_cpup (ohci, &td->hwCBP);
321                 be = hc32_to_cpup (ohci, &td->hwBE);
322                 ohci_dbg (ohci, "     cbp %08x be %08x (len %d)\n", cbp, be,
323                         cbp ? (be + 1 - cbp) : 0);
324         } else {
325                 unsigned        i;
326                 ohci_dbg (ohci, "  info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp,
327                         TD_CC_GET(tmp),
328                         (tmp >> 24) & 0x07,
329                         (tmp & TD_DI) >> 21,
330                         tmp & 0x0000ffff);
331                 ohci_dbg (ohci, "  bp0 %08x be %08x\n",
332                         hc32_to_cpup (ohci, &td->hwCBP) & ~0x0fff,
333                         hc32_to_cpup (ohci, &td->hwBE));
334                 for (i = 0; i < MAXPSW; i++) {
335                         u16     psw = ohci_hwPSW (ohci, td, i);
336                         int     cc = (psw >> 12) & 0x0f;
337                         ohci_dbg (ohci, "    psw [%d] = %2x, CC=%x %s=%d\n", i,
338                                 psw, cc,
339                                 (cc >= 0x0e) ? "OFFSET" : "SIZE",
340                                 psw & 0x0fff);
341                 }
342         }
343 }
344
345 /* caller MUST own hcd spinlock if verbose is set! */
346 static void __attribute__((unused))
347 ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
348                 const struct ed *ed, int verbose)
349 {
350         u32     tmp = hc32_to_cpu (ohci, ed->hwINFO);
351         char    *type = "";
352
353         ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
354                 label,
355                 ed, ed->state, edstring (ed->type),
356                 hc32_to_cpup (ohci, &ed->hwNextED));
357         switch (tmp & (ED_IN|ED_OUT)) {
358         case ED_OUT: type = "-OUT"; break;
359         case ED_IN: type = "-IN"; break;
360         /* else from TDs ... control */
361         }
362         ohci_dbg (ohci,
363                 "  info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp,
364                 0x03ff & (tmp >> 16),
365                 (tmp & ED_DEQUEUE) ? " DQ" : "",
366                 (tmp & ED_ISO) ? " ISO" : "",
367                 (tmp & ED_SKIP) ? " SKIP" : "",
368                 (tmp & ED_LOWSPEED) ? " LOW" : "",
369                 0x000f & (tmp >> 7),
370                 type,
371                 0x007f & tmp);
372         tmp = hc32_to_cpup (ohci, &ed->hwHeadP);
373         ohci_dbg (ohci, "  tds: head %08x %s%s tail %08x%s\n",
374                 tmp,
375                 (tmp & ED_C) ? data1 : data0,
376                 (tmp & ED_H) ? " HALT" : "",
377                 hc32_to_cpup (ohci, &ed->hwTailP),
378                 verbose ? "" : " (not listing)");
379         if (verbose) {
380                 struct list_head        *tmp;
381
382                 /* use ed->td_list because HC concurrently modifies
383                  * hwNextTD as it accumulates ed_donelist.
384                  */
385                 list_for_each (tmp, &ed->td_list) {
386                         struct td               *td;
387                         td = list_entry (tmp, struct td, td_list);
388                         ohci_dump_td (ohci, "  ->", td);
389                 }
390         }
391 }
392
393 #else
394 static inline void ohci_dump (struct ohci_hcd *controller, int verbose) {}
395
396 #undef OHCI_VERBOSE_DEBUG
397
398 #endif /* DEBUG */
399
400 /*-------------------------------------------------------------------------*/
401
402 #ifdef STUB_DEBUG_FILES
403
404 static inline void create_debug_files (struct ohci_hcd *bus) { }
405 static inline void remove_debug_files (struct ohci_hcd *bus) { }
406
407 #else
408
409 static ssize_t
410 show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
411 {
412         unsigned                temp, size = count;
413
414         if (!ed)
415                 return 0;
416
417         /* print first --> last */
418         while (ed->ed_prev)
419                 ed = ed->ed_prev;
420
421         /* dump a snapshot of the bulk or control schedule */
422         while (ed) {
423                 u32             info = hc32_to_cpu (ohci, ed->hwINFO);
424                 u32             headp = hc32_to_cpu (ohci, ed->hwHeadP);
425                 struct list_head *entry;
426                 struct td       *td;
427
428                 temp = scnprintf (buf, size,
429                         "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
430                         ed,
431                         (info & ED_LOWSPEED) ? 'l' : 'f',
432                         info & 0x7f,
433                         (info >> 7) & 0xf,
434                         (info & ED_IN) ? "in" : "out",
435                         0x03ff & (info >> 16),
436                         info,
437                         (info & ED_SKIP) ? " s" : "",
438                         (headp & ED_H) ? " H" : "",
439                         (headp & ED_C) ? data1 : data0);
440                 size -= temp;
441                 buf += temp;
442
443                 list_for_each (entry, &ed->td_list) {
444                         u32             cbp, be;
445
446                         td = list_entry (entry, struct td, td_list);
447                         info = hc32_to_cpup (ohci, &td->hwINFO);
448                         cbp = hc32_to_cpup (ohci, &td->hwCBP);
449                         be = hc32_to_cpup (ohci, &td->hwBE);
450                         temp = scnprintf (buf, size,
451                                         "\n\ttd %p %s %d cc=%x urb %p (%08x)",
452                                         td,
453                                         ({ char *pid;
454                                         switch (info & TD_DP) {
455                                         case TD_DP_SETUP: pid = "setup"; break;
456                                         case TD_DP_IN: pid = "in"; break;
457                                         case TD_DP_OUT: pid = "out"; break;
458                                         default: pid = "(?)"; break;
459                                          } pid;}),
460                                         cbp ? (be + 1 - cbp) : 0,
461                                         TD_CC_GET (info), td->urb, info);
462                         size -= temp;
463                         buf += temp;
464                 }
465
466                 temp = scnprintf (buf, size, "\n");
467                 size -= temp;
468                 buf += temp;
469
470                 ed = ed->ed_next;
471         }
472         return count - size;
473 }
474
475 static ssize_t
476 show_async (struct class_device *class_dev, char *buf)
477 {
478         struct usb_bus          *bus;
479         struct usb_hcd          *hcd;
480         struct ohci_hcd         *ohci;
481         size_t                  temp;
482         unsigned long           flags;
483
484         bus = class_get_devdata(class_dev);
485         hcd = bus->hcpriv;
486         ohci = hcd_to_ohci(hcd);
487
488         /* display control and bulk lists together, for simplicity */
489         spin_lock_irqsave (&ohci->lock, flags);
490         temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail);
491         temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail);
492         spin_unlock_irqrestore (&ohci->lock, flags);
493
494         return temp;
495 }
496 static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
497
498
499 #define DBG_SCHED_LIMIT 64
500
501 static ssize_t
502 show_periodic (struct class_device *class_dev, char *buf)
503 {
504         struct usb_bus          *bus;
505         struct usb_hcd          *hcd;
506         struct ohci_hcd         *ohci;
507         struct ed               **seen, *ed;
508         unsigned long           flags;
509         unsigned                temp, size, seen_count;
510         char                    *next;
511         unsigned                i;
512
513         if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
514                 return 0;
515         seen_count = 0;
516
517         bus = class_get_devdata(class_dev);
518         hcd = bus->hcpriv;
519         ohci = hcd_to_ohci(hcd);
520         next = buf;
521         size = PAGE_SIZE;
522
523         temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
524         size -= temp;
525         next += temp;
526
527         /* dump a snapshot of the periodic schedule (and load) */
528         spin_lock_irqsave (&ohci->lock, flags);
529         for (i = 0; i < NUM_INTS; i++) {
530                 if (!(ed = ohci->periodic [i]))
531                         continue;
532
533                 temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
534                 size -= temp;
535                 next += temp;
536
537                 do {
538                         temp = scnprintf (next, size, " ed%d/%p",
539                                 ed->interval, ed);
540                         size -= temp;
541                         next += temp;
542                         for (temp = 0; temp < seen_count; temp++) {
543                                 if (seen [temp] == ed)
544                                         break;
545                         }
546
547                         /* show more info the first time around */
548                         if (temp == seen_count) {
549                                 u32     info = hc32_to_cpu (ohci, ed->hwINFO);
550                                 struct list_head        *entry;
551                                 unsigned                qlen = 0;
552
553                                 /* qlen measured here in TDs, not urbs */
554                                 list_for_each (entry, &ed->td_list)
555                                         qlen++;
556
557                                 temp = scnprintf (next, size,
558                                         " (%cs dev%d ep%d%s-%s qlen %u"
559                                         " max %d %08x%s%s)",
560                                         (info & ED_LOWSPEED) ? 'l' : 'f',
561                                         info & 0x7f,
562                                         (info >> 7) & 0xf,
563                                         (info & ED_IN) ? "in" : "out",
564                                         (info & ED_ISO) ? "iso" : "int",
565                                         qlen,
566                                         0x03ff & (info >> 16),
567                                         info,
568                                         (info & ED_SKIP) ? " K" : "",
569                                         (ed->hwHeadP &
570                                                 cpu_to_hc32(ohci, ED_H)) ?
571                                                         " H" : "");
572                                 size -= temp;
573                                 next += temp;
574
575                                 if (seen_count < DBG_SCHED_LIMIT)
576                                         seen [seen_count++] = ed;
577
578                                 ed = ed->ed_next;
579
580                         } else {
581                                 /* we've seen it and what's after */
582                                 temp = 0;
583                                 ed = NULL;
584                         }
585
586                 } while (ed);
587
588                 temp = scnprintf (next, size, "\n");
589                 size -= temp;
590                 next += temp;
591         }
592         spin_unlock_irqrestore (&ohci->lock, flags);
593         kfree (seen);
594
595         return PAGE_SIZE - size;
596 }
597 static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
598
599
600 #undef DBG_SCHED_LIMIT
601
602 static ssize_t
603 show_registers (struct class_device *class_dev, char *buf)
604 {
605         struct usb_bus          *bus;
606         struct usb_hcd          *hcd;
607         struct ohci_hcd         *ohci;
608         struct ohci_regs __iomem *regs;
609         unsigned long           flags;
610         unsigned                temp, size;
611         char                    *next;
612         u32                     rdata;
613
614         bus = class_get_devdata(class_dev);
615         hcd = bus->hcpriv;
616         ohci = hcd_to_ohci(hcd);
617         regs = ohci->regs;
618         next = buf;
619         size = PAGE_SIZE;
620
621         spin_lock_irqsave (&ohci->lock, flags);
622
623         /* dump driver info, then registers in spec order */
624
625         ohci_dbg_sw (ohci, &next, &size,
626                 "bus %s, device %s\n"
627                 "%s\n"
628                 "%s version " DRIVER_VERSION "\n",
629                 hcd->self.controller->bus->name,
630                 hcd->self.controller->bus_id,
631                 hcd->product_desc,
632                 hcd_name);
633
634         if (bus->controller->power.power_state.event) {
635                 size -= scnprintf (next, size,
636                         "SUSPENDED (no register access)\n");
637                 goto done;
638         }
639
640         ohci_dump_status(ohci, &next, &size);
641
642         /* hcca */
643         if (ohci->hcca)
644                 ohci_dbg_sw (ohci, &next, &size,
645                         "hcca frame 0x%04x\n", ohci_frame_no(ohci));
646
647         /* other registers mostly affect frame timings */
648         rdata = ohci_readl (ohci, &regs->fminterval);
649         temp = scnprintf (next, size,
650                         "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
651                         rdata, (rdata >> 31) ? "FIT " : "",
652                         (rdata >> 16) & 0xefff, rdata & 0xffff);
653         size -= temp;
654         next += temp;
655
656         rdata = ohci_readl (ohci, &regs->fmremaining);
657         temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
658                         rdata, (rdata >> 31) ? "FRT " : "",
659                         rdata & 0x3fff);
660         size -= temp;
661         next += temp;
662
663         rdata = ohci_readl (ohci, &regs->periodicstart);
664         temp = scnprintf (next, size, "periodicstart 0x%04x\n",
665                         rdata & 0x3fff);
666         size -= temp;
667         next += temp;
668
669         rdata = ohci_readl (ohci, &regs->lsthresh);
670         temp = scnprintf (next, size, "lsthresh 0x%04x\n",
671                         rdata & 0x3fff);
672         size -= temp;
673         next += temp;
674
675         /* roothub */
676         ohci_dump_roothub (ohci, 1, &next, &size);
677
678 done:
679         spin_unlock_irqrestore (&ohci->lock, flags);
680         return PAGE_SIZE - size;
681 }
682 static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
683
684
685 static inline void create_debug_files (struct ohci_hcd *ohci)
686 {
687         struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
688
689         class_device_create_file(cldev, &class_device_attr_async);
690         class_device_create_file(cldev, &class_device_attr_periodic);
691         class_device_create_file(cldev, &class_device_attr_registers);
692         ohci_dbg (ohci, "created debug files\n");
693 }
694
695 static inline void remove_debug_files (struct ohci_hcd *ohci)
696 {
697         struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
698
699         class_device_remove_file(cldev, &class_device_attr_async);
700         class_device_remove_file(cldev, &class_device_attr_periodic);
701         class_device_remove_file(cldev, &class_device_attr_registers);
702 }
703
704 #endif
705
706 /*-------------------------------------------------------------------------*/
707