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 <asm/arch/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() && ep->current_epnum) {
147 unsigned cppi = ep->current_epnum - 1;
148 void __iomem *base = ep->musb->ctrl_base;
149 unsigned off1 = cppi << 2;
150 void __iomem *ram = base;
154 ram += DAVINCI_TXCPPI_STATERAM_OFFSET(cppi);
157 ram += DAVINCI_RXCPPI_STATERAM_OFFSET(cppi);
158 snprintf(tmp, sizeof tmp, "%d left, ",
160 DAVINCI_RXCPPI_BUFCNT0_REG + off1));
163 code = snprintf(buf, max, "%cX DMA%d: %s"
164 "%08x %08x, %08x %08x; "
165 "%08x %08x %08x .. %08x\n",
166 ep->is_in ? 'T' : 'R',
167 ep->current_epnum - 1, tmp,
168 musb_readl(ram, 0 * 4),
169 musb_readl(ram, 1 * 4),
170 musb_readl(ram, 2 * 4),
171 musb_readl(ram, 3 * 4),
172 musb_readl(ram, 4 * 4),
173 musb_readl(ram, 5 * 4),
174 musb_readl(ram, 6 * 4),
175 musb_readl(ram, 7 * 4));
178 code = min(code, (int) max);
183 if (list_empty(&ep->req_list)) {
184 code = snprintf(buf, max, "\t(queue empty)\n");
187 code = min(code, (int) max);
192 list_for_each_entry(req, &ep->req_list, list) {
193 code = snprintf(buf, max, "\treq %p, %s%s%d/%d\n",
195 req->zero ? "zero, " : "",
196 req->short_not_ok ? "!short, " : "",
197 req->actual, req->length);
200 code = min(code, (int) max);
210 dump_end_info(struct musb *musb, u8 epnum, char *aBuffer, unsigned max)
214 struct musb_hw_ep *hw_ep = &musb->endpoints[epnum];
217 musb_ep_select(musb->mregs, epnum);
218 #ifdef CONFIG_USB_MUSB_HDRC_HCD
219 if (is_host_active(musb)) {
220 int dump_rx, dump_tx;
221 void __iomem *regs = hw_ep->regs;
223 /* TEMPORARY (!) until we have a real periodic
227 /* control is shared, uses RX queue
228 * but (mostly) shadowed tx registers
230 dump_tx = !list_empty(&musb->control);
232 } else if (hw_ep == musb->bulk_ep) {
233 dump_tx = !list_empty(&musb->out_bulk);
234 dump_rx = !list_empty(&musb->in_bulk);
235 } else if (musb->periodic[epnum]) {
236 struct usb_host_endpoint *hep;
238 hep = musb->periodic[epnum]->hep;
239 dump_rx = hep->desc.bEndpointAddress
240 & USB_ENDPOINT_DIR_MASK;
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()
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 (musb->periodic[epnum]) {
325 code = dump_qh(musb->periodic[epnum],
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()
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 (musb->periodic[epnum]) {
416 code = dump_qh(musb->periodic[epnum],
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() && musb->dma_controller) {
572 code = sprintf(buffer,
573 "CPPI: txcr=%d txsrc=%01x txena=%01x; "
574 "rxcr=%d rxsrc=%01x rxena=%01x "
576 musb_readl(musb->ctrl_base,
577 DAVINCI_TXCPPI_CTRL_REG),
578 musb_readl(musb->ctrl_base,
579 DAVINCI_TXCPPI_RAW_REG),
580 musb_readl(musb->ctrl_base,
581 DAVINCI_TXCPPI_INTENAB_REG),
582 musb_readl(musb->ctrl_base,
583 DAVINCI_RXCPPI_CTRL_REG),
584 musb_readl(musb->ctrl_base,
585 DAVINCI_RXCPPI_RAW_REG),
586 musb_readl(musb->ctrl_base,
587 DAVINCI_RXCPPI_INTENAB_REG));
594 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
595 if (is_peripheral_enabled(musb)) {
596 code = sprintf(buffer, "Gadget driver: %s\n",
598 ? musb->gadget_driver->driver.name
618 * F force session (OTG-unfriendly)
619 * E rElinquish bus (OTG)
620 * H request host mode
621 * h cancel host request
622 * T start sending TEST_PACKET
623 * D<num> set/query the debug level
625 static int musb_proc_write(struct file *file, const char __user *buffer,
626 unsigned long count, void *data)
630 struct musb *musb = (struct musb *)data;
631 void __iomem *mbase = musb->mregs;
633 /* MOD_INC_USE_COUNT; */
635 if (unlikely(copy_from_user(&cmd, buffer, 1)))
641 reg = musb_readb(mbase, MUSB_POWER)
642 | MUSB_POWER_SOFTCONN;
643 musb_writeb(mbase, MUSB_POWER, reg);
649 reg = musb_readb(mbase, MUSB_POWER)
650 & ~MUSB_POWER_SOFTCONN;
651 musb_writeb(mbase, MUSB_POWER, reg);
657 reg = musb_readb(mbase, MUSB_POWER)
659 musb_writeb(mbase, MUSB_POWER, reg);
665 reg = musb_readb(mbase, MUSB_POWER)
666 & ~MUSB_POWER_HSENAB;
667 musb_writeb(mbase, MUSB_POWER, reg);
672 reg = musb_readb(mbase, MUSB_DEVCTL);
673 reg |= MUSB_DEVCTL_SESSION;
674 musb_writeb(mbase, MUSB_DEVCTL, reg);
679 reg = musb_readb(mbase, MUSB_DEVCTL);
680 reg |= MUSB_DEVCTL_HR;
681 musb_writeb(mbase, MUSB_DEVCTL, reg);
682 /* MUSB_HST_MODE( ((struct musb*)data) ); */
683 /* WARNING("Host Mode\n"); */
689 reg = musb_readb(mbase, MUSB_DEVCTL);
690 reg &= ~MUSB_DEVCTL_HR;
691 musb_writeb(mbase, MUSB_DEVCTL, reg);
697 musb_load_testpacket(musb);
698 musb_writeb(mbase, MUSB_TESTMODE,
704 /* set/read debug level */
707 char digits[8], *p = digits;
708 int i = 0, level = 0, sign = 1;
709 int len = min(count - 1, (unsigned long)8);
711 if (copy_from_user(&digits, &buffer[1], len))
722 while (i++ < len && *p > '0' && *p < '9') {
723 level = level * 10 + (*p - '0');
728 DBG(1, "debug level %d\n", level);
736 INFO("?: you are seeing it\n");
737 INFO("C/c: soft connect enable/disable\n");
738 INFO("I/i: hispeed enable/disable\n");
739 INFO("F: force session start\n");
740 INFO("H: host mode\n");
741 INFO("T: start sending TEST_PACKET\n");
742 INFO("D: set/read dbug level\n");
747 ERR("Command %c not implemented\n", cmd);
751 musb_platform_try_idle(musb, 0);
756 static int musb_proc_read(char *page, char **start,
757 off_t off, int count, int *eof, void *data)
762 struct musb *musb = data;
766 count -= 1; /* for NUL at end */
770 spin_lock_irqsave(&musb->lock, flags);
772 code = dump_header_stats(musb, buffer);
778 /* generate the report for the end points */
779 /* REVISIT ... not unless something's connected! */
780 for (epnum = 0; count >= 0 && epnum < musb->nr_endpoints;
782 code = dump_end_info(musb, epnum, buffer, count);
789 musb_platform_try_idle(musb, 0);
791 spin_unlock_irqrestore(&musb->lock, flags);
794 return buffer - page;
797 void __devexit musb_debug_delete(char *name, struct musb *musb)
799 if (musb->proc_entry)
800 remove_proc_entry(name, NULL);
803 struct proc_dir_entry *__init
804 musb_debug_create(char *name, struct musb *data)
806 struct proc_dir_entry *pde;
808 /* FIXME convert everything to seq_file; then later, debugfs */
813 pde = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, NULL);
814 data->proc_entry = pde;
817 /* pde->owner = THIS_MODULE; */
819 pde->read_proc = musb_proc_read;
820 pde->write_proc = musb_proc_write;
824 pr_debug("Registered /proc/%s\n", name);
826 pr_debug("Cannot create a valid proc file entry");