musb_procfs.c
来自「omap3 linux 2.6 用nocc去除了冗余代码」· C语言 代码 · 共 763 行 · 第 1/2 页
C
763 行
buf += code; max -= code; if (is_cppi_enabled() && bEnd && pEnd->tx_channel) { unsigned cppi = bEnd - 1; void __iomem *base; void __iomem *ram; base = pThis->ctrl_base; ram = DAVINCI_RXCPPI_STATERAM_OFFSET( cppi) + base; code = snprintf(buf, max, " tx dma%d: " "%08x %08x, %08x %08x; " "%08x %08x %08x .. %08x\n", cppi, musb_readl(ram, 0 * 4), musb_readl(ram, 1 * 4), musb_readl(ram, 2 * 4), musb_readl(ram, 3 * 4), musb_readl(ram, 4 * 4), musb_readl(ram, 5 * 4), musb_readl(ram, 6 * 4), musb_readl(ram, 7 * 4)); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } if (pEnd == pThis->control_ep && !list_empty( &pThis->control)) { code = dump_queue(&pThis->control, buf, max); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } else if (pEnd == pThis->bulk_ep && !list_empty( &pThis->out_bulk)) { code = dump_queue(&pThis->out_bulk, buf, max); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } else if (pThis->periodic[bEnd]) { code = dump_qh(pThis->periodic[bEnd], buf, max); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } } } if (is_peripheral_active(pThis)) { code = 0; if (pEnd->ep_in.desc || !bEnd) { code = dump_ep(&pEnd->ep_in, buf, max); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } if (pEnd->ep_out.desc) { code = dump_ep(&pEnd->ep_out, buf, max); if (code <= 0) break; code = min(code, (int) max); buf += code; max -= code; } } } while (0); return buf - aBuffer;}/** Dump the current status and compile options. * @param pThis the device driver instance * @param buffer where to dump the status; it must be big enough hold the * result otherwise "BAD THINGS HAPPENS(TM)". */static int dump_header_stats(struct musb *pThis, char *buffer){ int code, count = 0; const void __iomem *pBase = pThis->pRegs; *buffer = 0; count = sprintf(buffer, "Status: %sHDRC, Mode=%s " "(Power=%02x, DevCtl=%02x)\n", (pThis->bIsMultipoint ? "M" : ""), MUSB_MODE(pThis), musb_readb(pBase, MGC_O_HDRC_POWER), musb_readb(pBase, MGC_O_HDRC_DEVCTL)); if (count <= 0) return 0; buffer += count; code = sprintf(buffer, "OTG state: %s; %sactive\n", otg_state_string(pThis), pThis->is_active ? "" : "in"); if (code <= 0) goto done; buffer += code; count += code; code = sprintf(buffer, "Options: " "pio" ", " "otg (peripheral+host)" ", debug=%d [eps=%d]\n", debug, pThis->bEndCount); if (code <= 0) goto done; count += code; buffer += code; code = sprintf(buffer, "Peripheral address: %02x\n", musb_readb(pThis, MGC_O_HDRC_FADDR)); if (code <= 0) goto done; buffer += code; count += code; code = sprintf(buffer, "Root port status: %08x\n", pThis->port1_status); if (code <= 0) goto done; buffer += code; count += code; if (is_cppi_enabled() && pThis->pDmaController) { code = sprintf(buffer, "CPPI: txcr=%d txsrc=%01x txena=%01x; " "rxcr=%d rxsrc=%01x rxena=%01x " "\n", musb_readl(pThis->ctrl_base, DAVINCI_TXCPPI_CTRL_REG), musb_readl(pThis->ctrl_base, DAVINCI_TXCPPI_RAW_REG), musb_readl(pThis->ctrl_base, DAVINCI_TXCPPI_INTENAB_REG), musb_readl(pThis->ctrl_base, DAVINCI_RXCPPI_CTRL_REG), musb_readl(pThis->ctrl_base, DAVINCI_RXCPPI_RAW_REG), musb_readl(pThis->ctrl_base, DAVINCI_RXCPPI_INTENAB_REG)); if (code <= 0) goto done; count += code; buffer += code; } if (is_peripheral_enabled(pThis)) { code = sprintf(buffer, "Gadget driver: %s\n", pThis->pGadgetDriver ? pThis->pGadgetDriver->driver.name : "(none)"); if (code <= 0) goto done; count += code; buffer += code; }done: return count;}/* Write to ProcFS * * C soft-connect * c soft-disconnect * I enable HS * i disable HS * s stop session * F force session (OTG-unfriendly) * E rElinquish bus (OTG) * H request host mode * h cancel host request * T start sending TEST_PACKET * D<num> set/query the debug level */static int musb_proc_write(struct file *file, const char __user *buffer, unsigned long count, void *data){ char cmd; u8 bReg; struct musb *musb = (struct musb *)data; void __iomem *pBase = musb->pRegs; /* MOD_INC_USE_COUNT; */ if (unlikely(copy_from_user(&cmd, buffer, 1))) return -EFAULT; switch (cmd) { case 'C': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_POWER) | MGC_M_POWER_SOFTCONN; musb_writeb(pBase, MGC_O_HDRC_POWER, bReg); } break; case 'c': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_POWER) & ~MGC_M_POWER_SOFTCONN; musb_writeb(pBase, MGC_O_HDRC_POWER, bReg); } break; case 'I': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_POWER) | MGC_M_POWER_HSENAB; musb_writeb(pBase, MGC_O_HDRC_POWER, bReg); } break; case 'i': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_POWER) & ~MGC_M_POWER_HSENAB; musb_writeb(pBase, MGC_O_HDRC_POWER, bReg); } break; case 'F': case 'S': bReg = musb_readb(pBase, MGC_O_HDRC_DEVCTL); bReg |= MGC_M_DEVCTL_SESSION; musb_writeb(pBase, MGC_O_HDRC_DEVCTL, bReg); /* following is a workaround for Triton2 */ mdelay(100); if (!(musb_readb(pBase, MGC_O_HDRC_DEVCTL) & MGC_M_DEVCTL_SESSION)) musb_writeb(pBase, MGC_O_HDRC_DEVCTL, bReg); break; case 'H': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_DEVCTL); bReg |= MGC_M_DEVCTL_HR; musb_writeb(pBase, MGC_O_HDRC_DEVCTL, bReg); //MUSB_HST_MODE( ((struct musb*)data) ); //WARN("Host Mode\n"); } break; case 'h': if (pBase) { bReg = musb_readb(pBase, MGC_O_HDRC_DEVCTL); bReg &= ~MGC_M_DEVCTL_HR; musb_writeb(pBase, MGC_O_HDRC_DEVCTL, bReg); } break; case 'T': if (pBase) { musb_load_testpacket(musb); musb_writeb(pBase, MGC_O_HDRC_TESTMODE, MGC_M_TEST_PACKET); } break; case '?': INFO("?: you are seeing it\n"); INFO("C/c: soft connect enable/disable\n"); INFO("I/i: hispeed enable/disable\n"); INFO("F: force session start\n"); INFO("H: host mode\n"); INFO("T: start sending TEST_PACKET\n"); INFO("D: set/read dbug level\n"); INFO("R: dump all registers\n"); break; default: ERR("Command %c not implemented\n", cmd); break; } musb_platform_try_idle(musb, 0); return count;}static int musb_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data){ char *buffer = page; int code = 0; unsigned long flags; struct musb *pThis = data; unsigned bEnd; count -= off; count -= 1; /* for NUL at end */ if (count <= 0) return -EINVAL; spin_lock_irqsave(&pThis->Lock, flags); code = dump_header_stats(pThis, buffer); if (code > 0) { buffer += code; count -= code; } /* generate the report for the end points */ // REVISIT ... not unless something's connected! for (bEnd = 0; count >= 0 && bEnd < pThis->bEndCount; bEnd++) { code = dump_end_info(pThis, bEnd, buffer, count); if (code > 0) { buffer += code; count -= code; } } musb_platform_try_idle(pThis, 0); spin_unlock_irqrestore(&pThis->Lock, flags); *eof = 1; return buffer - page;}void __devexit musb_debug_delete(char *name, struct musb *musb){ if (musb->pProcEntry) remove_proc_entry(name, NULL);}struct proc_dir_entry *__initmusb_debug_create(char *name, struct musb *data){ struct proc_dir_entry *pde; /* FIXME convert everything to seq_file; then later, debugfs */ if (!name) return NULL; data->pProcEntry = pde = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, NULL); if (pde) { pde->data = data; // pde->owner = THIS_MODULE; pde->read_proc = musb_proc_read; pde->write_proc = musb_proc_write; pde->size = 0; pr_debug("Registered /proc/%s\n", name); } else { pr_debug("Cannot create a valid proc file entry"); } return pde;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?