2 * MUSB OTG driver debug support
4 * Copyright 2005 Mentor Graphics Corporation
5 * Copyright (C) 2005-2006 by Texas Instruments
6 * Copyright (C) 2006-2007 Nokia Corporation
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
25 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <linux/kernel.h>
36 #include <linux/proc_fs.h>
37 #include <linux/seq_file.h>
38 #include <linux/uaccess.h> /* FIXME remove procfs writes */
39 #include <mach/hardware.h>
41 #include "musb_core.h"
45 #ifdef CONFIG_USB_MUSB_HDRC_HCD
47 static int dump_qh(struct musb_qh
*qh
, char *buf
, unsigned max
)
51 struct usb_host_endpoint
*hep
= qh
->hep
;
54 count
= snprintf(buf
, max
, " qh %p dev%d ep%d%s max%d\n",
55 qh
, qh
->dev
->devnum
, qh
->epnum
,
56 ({ char *s
; switch (qh
->type
) {
57 case USB_ENDPOINT_XFER_BULK
:
59 case USB_ENDPOINT_XFER_INT
:
61 case USB_ENDPOINT_XFER_CONTROL
:
72 list_for_each_entry(urb
, &hep
->urb_list
, urb_list
) {
73 tmp
= snprintf(buf
, max
, "\t%s urb %p %d/%d\n",
74 usb_pipein(urb
->pipe
) ? "in" : "out",
75 urb
, urb
->actual_length
,
76 urb
->transfer_buffer_length
);
79 tmp
= min(tmp
, (int)max
);
88 dump_queue(struct list_head
*q
, char *buf
, unsigned max
)
93 list_for_each_entry(qh
, q
, ring
) {
96 tmp
= dump_qh(qh
, buf
, max
);
99 tmp
= min(tmp
, (int)max
);
109 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
110 static int dump_ep(struct musb_ep
*ep
, char *buffer
, unsigned max
)
114 void __iomem
*regs
= ep
->hw_ep
->regs
;
118 if (ep
->hw_ep
->tx_double_buffered
)
121 if (ep
->hw_ep
->rx_double_buffered
)
126 struct usb_request
*req
;
128 code
= snprintf(buf
, max
,
129 "\n%s (hw%d): %s%s, csr %04x maxp %04x\n",
130 ep
->name
, ep
->current_epnum
,
131 mode
, ep
->dma
? " dma" : "",
133 (ep
->is_in
|| !ep
->current_epnum
)
136 musb_readw(regs
, ep
->is_in
142 code
= min(code
, (int) max
);
146 if ((is_cppi_enabled() || is_cppi41_enabled())
147 && ep
->current_epnum
) {
148 unsigned cppi
= ep
->current_epnum
- 1;
149 void __iomem
*base
= ep
->musb
->ctrl_base
;
150 unsigned off1
= cppi
<< 2;
151 void __iomem
*ram
= base
;
155 ram
+= DAVINCI_TXCPPI_STATERAM_OFFSET(cppi
);
158 ram
+= DAVINCI_RXCPPI_STATERAM_OFFSET(cppi
);
159 snprintf(tmp
, sizeof tmp
, "%d left, ",
161 DAVINCI_RXCPPI_BUFCNT0_REG
+ off1
));
164 code
= snprintf(buf
, max
, "%cX DMA%d: %s"
165 "%08x %08x, %08x %08x; "
166 "%08x %08x %08x .. %08x\n",
167 ep
->is_in
? 'T' : 'R',
168 ep
->current_epnum
- 1, tmp
,
169 musb_readl(ram
, 0 * 4),
170 musb_readl(ram
, 1 * 4),
171 musb_readl(ram
, 2 * 4),
172 musb_readl(ram
, 3 * 4),
173 musb_readl(ram
, 4 * 4),
174 musb_readl(ram
, 5 * 4),
175 musb_readl(ram
, 6 * 4),
176 musb_readl(ram
, 7 * 4));
179 code
= min(code
, (int) max
);
184 if (list_empty(&ep
->req_list
)) {
185 code
= snprintf(buf
, max
, "\t(queue empty)\n");
188 code
= min(code
, (int) max
);
193 list_for_each_entry(req
, &ep
->req_list
, list
) {
194 code
= snprintf(buf
, max
, "\treq %p, %s%s%d/%d\n",
196 req
->zero
? "zero, " : "",
197 req
->short_not_ok
? "!short, " : "",
198 req
->actual
, req
->length
);
201 code
= min(code
, (int) max
);
211 dump_end_info(struct musb
*musb
, u8 epnum
, char *aBuffer
, unsigned max
)
215 struct musb_hw_ep
*hw_ep
= &musb
->endpoints
[epnum
];
218 musb_ep_select(musb
->mregs
, epnum
);
219 #ifdef CONFIG_USB_MUSB_HDRC_HCD
220 if (is_host_active(musb
)) {
221 int dump_rx
, dump_tx
;
222 void __iomem
*regs
= hw_ep
->regs
;
224 /* TEMPORARY (!) until we have a real periodic
228 /* control is shared, uses RX queue
229 * but (mostly) shadowed tx registers
231 dump_tx
= !list_empty(&musb
->control
);
233 } else if (hw_ep
== musb
->bulk_ep
) {
234 dump_tx
= !list_empty(&musb
->out_bulk
);
235 dump_rx
= !list_empty(&musb
->in_bulk
);
236 } else if (hw_ep
->in_qh
|| hw_ep
->out_qh
) {
248 code
= snprintf(buf
, max
,
249 "\nRX%d: %s rxcsr %04x interval %02x "
250 "max %04x type %02x; "
251 "dev %d hub %d port %d"
254 hw_ep
->rx_double_buffered
256 musb_readw(regs
, MUSB_RXCSR
),
257 musb_readb(regs
, MUSB_RXINTERVAL
),
258 musb_readw(regs
, MUSB_RXMAXP
),
259 musb_readb(regs
, MUSB_RXTYPE
),
260 /* FIXME: assumes multipoint */
261 musb_readb(musb
->mregs
,
262 MUSB_BUSCTL_OFFSET(epnum
,
264 musb_readb(musb
->mregs
,
265 MUSB_BUSCTL_OFFSET(epnum
,
267 musb_readb(musb
->mregs
,
268 MUSB_BUSCTL_OFFSET(epnum
,
273 code
= min(code
, (int) max
);
277 if ((is_cppi_enabled() || is_cppi41_enabled())
279 && hw_ep
->rx_channel
) {
280 unsigned cppi
= epnum
- 1;
281 unsigned off1
= cppi
<< 2;
286 base
= musb
->ctrl_base
;
287 ram
= DAVINCI_RXCPPI_STATERAM_OFFSET(
289 snprintf(tmp
, sizeof tmp
, "%d left, ",
291 DAVINCI_RXCPPI_BUFCNT0_REG
294 code
= snprintf(buf
, max
,
296 "%08x %08x, %08x %08x; "
297 "%08x %08x %08x .. %08x\n",
299 musb_readl(ram
, 0 * 4),
300 musb_readl(ram
, 1 * 4),
301 musb_readl(ram
, 2 * 4),
302 musb_readl(ram
, 3 * 4),
303 musb_readl(ram
, 4 * 4),
304 musb_readl(ram
, 5 * 4),
305 musb_readl(ram
, 6 * 4),
306 musb_readl(ram
, 7 * 4));
309 code
= min(code
, (int) max
);
314 if (hw_ep
== musb
->bulk_ep
317 code
= dump_queue(&musb
->in_bulk
,
321 code
= min(code
, (int) max
);
324 } else if (hw_ep
->in_qh
) {
325 code
= dump_qh(hw_ep
->in_qh
,
329 code
= min(code
, (int) max
);
336 code
= snprintf(buf
, max
,
337 "\nTX%d: %s txcsr %04x interval %02x "
338 "max %04x type %02x; "
339 "dev %d hub %d port %d"
342 hw_ep
->tx_double_buffered
344 musb_readw(regs
, MUSB_TXCSR
),
345 musb_readb(regs
, MUSB_TXINTERVAL
),
346 musb_readw(regs
, MUSB_TXMAXP
),
347 musb_readb(regs
, MUSB_TXTYPE
),
348 /* FIXME: assumes multipoint */
349 musb_readb(musb
->mregs
,
350 MUSB_BUSCTL_OFFSET(epnum
,
352 musb_readb(musb
->mregs
,
353 MUSB_BUSCTL_OFFSET(epnum
,
355 musb_readb(musb
->mregs
,
356 MUSB_BUSCTL_OFFSET(epnum
,
361 code
= min(code
, (int) max
);
365 if ((is_cppi_enabled() || is_cppi41_enabled())
367 && hw_ep
->tx_channel
) {
368 unsigned cppi
= epnum
- 1;
372 base
= musb
->ctrl_base
;
373 ram
= DAVINCI_RXCPPI_STATERAM_OFFSET(
375 code
= snprintf(buf
, max
,
377 "%08x %08x, %08x %08x; "
378 "%08x %08x %08x .. %08x\n",
380 musb_readl(ram
, 0 * 4),
381 musb_readl(ram
, 1 * 4),
382 musb_readl(ram
, 2 * 4),
383 musb_readl(ram
, 3 * 4),
384 musb_readl(ram
, 4 * 4),
385 musb_readl(ram
, 5 * 4),
386 musb_readl(ram
, 6 * 4),
387 musb_readl(ram
, 7 * 4));
390 code
= min(code
, (int) max
);
395 if (hw_ep
== musb
->control_ep
398 code
= dump_queue(&musb
->control
,
402 code
= min(code
, (int) max
);
405 } else if (hw_ep
== musb
->bulk_ep
408 code
= dump_queue(&musb
->out_bulk
,
412 code
= min(code
, (int) max
);
415 } else if (hw_ep
->out_qh
) {
416 code
= dump_qh(hw_ep
->out_qh
,
420 code
= min(code
, (int) max
);
427 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
428 if (is_peripheral_active(musb
)) {
431 if (hw_ep
->ep_in
.desc
|| !epnum
) {
432 code
= dump_ep(&hw_ep
->ep_in
, buf
, max
);
435 code
= min(code
, (int) max
);
439 if (hw_ep
->ep_out
.desc
) {
440 code
= dump_ep(&hw_ep
->ep_out
, buf
, max
);
443 code
= min(code
, (int) max
);
451 return buf
- aBuffer
;
454 /* Dump the current status and compile options.
455 * @param musb the device driver instance
456 * @param buffer where to dump the status; it must be big enough to hold the
457 * result otherwise "BAD THINGS HAPPENS(TM)".
459 static int dump_header_stats(struct musb
*musb
, char *buffer
)
462 const void __iomem
*mbase
= musb
->mregs
;
465 count
= sprintf(buffer
, "Status: %sHDRC, Mode=%s "
466 "(Power=%02x, DevCtl=%02x)\n",
467 (musb
->is_multipoint
? "M" : ""), MUSB_MODE(musb
),
468 musb_readb(mbase
, MUSB_POWER
),
469 musb_readb(mbase
, MUSB_DEVCTL
));
474 code
= sprintf(buffer
, "OTG state: %s; %sactive\n",
475 otg_state_string(musb
),
476 musb
->is_active
? "" : "in");
482 code
= sprintf(buffer
,
484 #ifdef CONFIG_MUSB_PIO_ONLY
486 #elif defined(CONFIG_USB_TI_CPPI_DMA)
488 #elif defined(CONFIG_USB_INVENTRA_DMA)
490 #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
496 #ifdef CONFIG_USB_MUSB_OTG
497 "otg (peripheral+host)"
498 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
500 #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
503 ", debug=%d [eps=%d]\n",
511 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
512 code
= sprintf(buffer
, "Peripheral address: %02x\n",
513 musb_readb(musb
->ctrl_base
, MUSB_FADDR
));
520 #ifdef CONFIG_USB_MUSB_HDRC_HCD
521 code
= sprintf(buffer
, "Root port status: %08x\n",
529 #ifdef CONFIG_ARCH_DAVINCI
530 code
= sprintf(buffer
,
531 "DaVinci: ctrl=%02x stat=%1x phy=%03x\n"
532 "\trndis=%05x auto=%04x intsrc=%08x intmsk=%08x"
534 musb_readl(musb
->ctrl_base
, DAVINCI_USB_CTRL_REG
),
535 musb_readl(musb
->ctrl_base
, DAVINCI_USB_STAT_REG
),
536 __raw_readl((void __force __iomem
*)
537 IO_ADDRESS(USBPHY_CTL_PADDR
)),
538 musb_readl(musb
->ctrl_base
, DAVINCI_RNDIS_REG
),
539 musb_readl(musb
->ctrl_base
, DAVINCI_AUTOREQ_REG
),
540 musb_readl(musb
->ctrl_base
,
541 DAVINCI_USB_INT_SOURCE_REG
),
542 musb_readl(musb
->ctrl_base
,
543 DAVINCI_USB_INT_MASK_REG
));
550 #ifdef CONFIG_USB_TUSB6010
551 code
= sprintf(buffer
,
552 "TUSB6010: devconf %08x, phy enable %08x drive %08x"
553 "\n\totg %03x timer %08x"
554 "\n\tprcm conf %08x mgmt %08x; int src %08x mask %08x"
556 musb_readl(musb
->ctrl_base
, TUSB_DEV_CONF
),
557 musb_readl(musb
->ctrl_base
, TUSB_PHY_OTG_CTRL_ENABLE
),
558 musb_readl(musb
->ctrl_base
, TUSB_PHY_OTG_CTRL
),
559 musb_readl(musb
->ctrl_base
, TUSB_DEV_OTG_STAT
),
560 musb_readl(musb
->ctrl_base
, TUSB_DEV_OTG_TIMER
),
561 musb_readl(musb
->ctrl_base
, TUSB_PRCM_CONF
),
562 musb_readl(musb
->ctrl_base
, TUSB_PRCM_MNGMT
),
563 musb_readl(musb
->ctrl_base
, TUSB_INT_SRC
),
564 musb_readl(musb
->ctrl_base
, TUSB_INT_MASK
));
571 if ((is_cppi_enabled() || is_cppi41_enabled())
572 && musb
->dma_controller
) {
573 code
= sprintf(buffer
,
574 "CPPI: txcr=%d txsrc=%01x txena=%01x; "
575 "rxcr=%d rxsrc=%01x rxena=%01x "
577 musb_readl(musb
->ctrl_base
,
578 DAVINCI_TXCPPI_CTRL_REG
),
579 musb_readl(musb
->ctrl_base
,
580 DAVINCI_TXCPPI_RAW_REG
),
581 musb_readl(musb
->ctrl_base
,
582 DAVINCI_TXCPPI_INTENAB_REG
),
583 musb_readl(musb
->ctrl_base
,
584 DAVINCI_RXCPPI_CTRL_REG
),
585 musb_readl(musb
->ctrl_base
,
586 DAVINCI_RXCPPI_RAW_REG
),
587 musb_readl(musb
->ctrl_base
,
588 DAVINCI_RXCPPI_INTENAB_REG
));
595 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
596 if (is_peripheral_enabled(musb
)) {
597 code
= sprintf(buffer
, "Gadget driver: %s\n",
599 ? musb
->gadget_driver
->driver
.name
619 * F force session (OTG-unfriendly)
620 * E rElinquish bus (OTG)
621 * H request host mode
622 * h cancel host request
623 * T start sending TEST_PACKET
624 * D<num> set/query the debug level
626 static int musb_proc_write(struct file
*file
, const char __user
*buffer
,
627 unsigned long count
, void *data
)
631 struct musb
*musb
= (struct musb
*)data
;
632 void __iomem
*mbase
= musb
->mregs
;
634 /* MOD_INC_USE_COUNT; */
636 if (unlikely(copy_from_user(&cmd
, buffer
, 1)))
642 reg
= musb_readb(mbase
, MUSB_POWER
)
643 | MUSB_POWER_SUSPENDM
;
644 musb_writeb(mbase
, MUSB_POWER
, reg
);
650 reg
= musb_readb(mbase
, MUSB_POWER
)
651 | MUSB_POWER_SOFTCONN
;
652 musb_writeb(mbase
, MUSB_POWER
, reg
);
658 reg
= musb_readb(mbase
, MUSB_POWER
)
659 & ~MUSB_POWER_SOFTCONN
;
660 musb_writeb(mbase
, MUSB_POWER
, reg
);
666 reg
= musb_readb(mbase
, MUSB_POWER
)
668 musb_writeb(mbase
, MUSB_POWER
, reg
);
674 reg
= musb_readb(mbase
, MUSB_POWER
)
675 & ~MUSB_POWER_HSENAB
;
676 musb_writeb(mbase
, MUSB_POWER
, reg
);
681 reg
= musb_readb(mbase
, MUSB_DEVCTL
);
682 reg
|= MUSB_DEVCTL_SESSION
;
683 musb_writeb(mbase
, MUSB_DEVCTL
, reg
);
688 reg
= musb_readb(mbase
, MUSB_DEVCTL
);
689 reg
|= MUSB_DEVCTL_HR
;
690 musb_writeb(mbase
, MUSB_DEVCTL
, reg
);
691 /* MUSB_HST_MODE( ((struct musb*)data) ); */
692 /* WARNING("Host Mode\n"); */
698 reg
= musb_readb(mbase
, MUSB_DEVCTL
);
699 reg
&= ~MUSB_DEVCTL_HR
;
700 musb_writeb(mbase
, MUSB_DEVCTL
, reg
);
706 musb_load_testpacket(musb
);
707 musb_writeb(mbase
, MUSB_TESTMODE
,
712 #if (CONFIG_USB_MUSB_DEBUG > 0)
713 /* set/read debug level */
716 char digits
[8], *p
= digits
;
717 int i
= 0, level
= 0, sign
= 1;
718 int len
= min(count
- 1, (unsigned long)8);
720 if (copy_from_user(&digits
, &buffer
[1], len
))
731 while (i
++ < len
&& *p
> '0' && *p
< '9') {
732 level
= level
* 10 + (*p
- '0');
737 DBG(1, "debug level %d\n", level
);
745 INFO("?: you are seeing it\n");
746 INFO("S: suspend the usb bus\n");
747 INFO("C/c: soft connect enable/disable\n");
748 INFO("I/i: hispeed enable/disable\n");
749 INFO("F: force session start\n");
750 INFO("H: host mode\n");
751 INFO("T: start sending TEST_PACKET\n");
752 INFO("D: set/read dbug level\n");
757 ERR("Command %c not implemented\n", cmd
);
761 musb_platform_try_idle(musb
, 0);
766 static int musb_proc_read(char *page
, char **start
,
767 off_t off
, int count
, int *eof
, void *data
)
772 struct musb
*musb
= data
;
776 count
-= 1; /* for NUL at end */
780 spin_lock_irqsave(&musb
->lock
, flags
);
782 code
= dump_header_stats(musb
, buffer
);
788 /* generate the report for the end points */
789 /* REVISIT ... not unless something's connected! */
790 for (epnum
= 0; count
>= 0 && epnum
< musb
->nr_endpoints
;
792 code
= dump_end_info(musb
, epnum
, buffer
, count
);
799 musb_platform_try_idle(musb
, 0);
801 spin_unlock_irqrestore(&musb
->lock
, flags
);
804 return buffer
- page
;
807 void __devexit
musb_debug_delete(char *name
, struct musb
*musb
)
809 if (musb
->proc_entry
)
810 remove_proc_entry(name
, NULL
);
813 struct proc_dir_entry
*__init
814 musb_debug_create(char *name
, struct musb
*data
)
816 struct proc_dir_entry
*pde
;
818 /* FIXME convert everything to seq_file; then later, debugfs */
823 pde
= create_proc_entry(name
, S_IFREG
| S_IRUGO
| S_IWUSR
, NULL
);
824 data
->proc_entry
= pde
;
827 /* pde->owner = THIS_MODULE; */
829 pde
->read_proc
= musb_proc_read
;
830 pde
->write_proc
= musb_proc_write
;
834 pr_debug("Registered /proc/%s\n", name
);
836 pr_debug("Cannot create a valid proc file entry");