staticchar *decode_ep0stage(u8 stage)
{ switch (stage) { case MUSB_EP0_STAGE_IDLE: return"idle"; case MUSB_EP0_STAGE_SETUP: return"setup"; case MUSB_EP0_STAGE_TX: return"in"; case MUSB_EP0_STAGE_RX: return"out"; case MUSB_EP0_STAGE_ACKWAIT: return"wait"; case MUSB_EP0_STAGE_STATUSIN: return"in/status"; case MUSB_EP0_STAGE_STATUSOUT: return"out/status"; default: return"?";
}
}
/* the gadget driver handles everything except what we MUST handle */ if ((ctrlrequest->bRequestType & USB_TYPE_MASK)
== USB_TYPE_STANDARD) { switch (ctrlrequest->bRequest) { case USB_REQ_SET_ADDRESS: /* change it after the status stage */
musb->set_address = true;
musb->address = (u8) (ctrlrequest->wValue & 0x7f);
handled = 1; break;
case USB_REQ_CLEAR_FEATURE: switch (recip) { case USB_RECIP_DEVICE: if (ctrlrequest->wValue
!= USB_DEVICE_REMOTE_WAKEUP) break;
musb->may_wakeup = 0;
handled = 1; break; case USB_RECIP_INTERFACE: break; case USB_RECIP_ENDPOINT:{ const u8 epnum =
ctrlrequest->wIndex & 0x0f; struct musb_ep *musb_ep; struct musb_hw_ep *ep; struct musb_request *request; void __iomem *regs; int is_in;
u16 csr;
/* Maybe start the first request in the queue */
request = next_request(musb_ep); if (!musb_ep->busy && request) {
musb_dbg(musb, "restarting the request");
musb_ep_restart(musb, request);
}
/* read packet and ack; or stall because of gadget driver bug: *shouldhaveprovidedtherxbufferbeforesetup()returned.
*/ if (req) { void *buf = req->buf + req->actual; unsigned len = req->length - req->actual;
/* Completion handler may choose to stall, e.g. because the *messagejustreceivedholdsinvaliddata.
*/ if (req) {
musb->ackpend = csr;
musb_g_ep0_giveback(musb, req); if (!musb->ackpend) return;
musb->ackpend = 0;
}
musb_ep_select(musb->mregs, 0);
musb_writew(regs, MUSB_CSR0, csr);
}
/* report completions as soon as the fifo's loaded; there's no *wininwaitingtillthislastpacketgetsacked.(otherthan *veryprecisefaultreporting,neededbyUSBTMC;possiblewith *thishardware,butnotusablefromportablegadgetdrivers.)
*/ if (request) {
musb->ackpend = csr;
musb_g_ep0_giveback(musb, request); if (!musb->ackpend) return;
musb->ackpend = 0;
}
/* send it out, triggering a "txpktrdy cleared" irq */
musb_ep_select(musb->mregs, 0);
musb_writew(regs, MUSB_CSR0, csr);
}
/* I sent a stall.. need to acknowledge it now.. */ if (csr & MUSB_CSR0_P_SENTSTALL) {
musb_writew(regs, MUSB_CSR0,
csr & ~MUSB_CSR0_P_SENTSTALL);
retval = IRQ_HANDLED;
musb->ep0_state = MUSB_EP0_STAGE_IDLE;
csr = musb_readw(regs, MUSB_CSR0);
}
/* request ended "early" */ if (csr & MUSB_CSR0_P_SETUPEND) {
musb_writew(regs, MUSB_CSR0, MUSB_CSR0_P_SVDSETUPEND);
retval = IRQ_HANDLED; /* Transition into the early status phase */ switch (musb->ep0_state) { case MUSB_EP0_STAGE_TX:
musb->ep0_state = MUSB_EP0_STAGE_STATUSOUT; break; case MUSB_EP0_STAGE_RX:
musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; break; default:
ERR("SetupEnd came in a wrong ep0stage %s\n",
decode_ep0stage(musb->ep0_state));
}
csr = musb_readw(regs, MUSB_CSR0); /* NOTE: request may need completion */
}
/* docs from Mentor only describe tx, rx, and idle/setup states. *weneedtohandlenuancesaroundstatusstages,andalsothe *casewherestatusandsetupstagescomeback-to-back...
*/ switch (musb->ep0_state) {
case MUSB_EP0_STAGE_TX: /* irq on clearing txpktrdy */ if ((csr & MUSB_CSR0_TXPKTRDY) == 0) {
ep0_txstate(musb);
retval = IRQ_HANDLED;
} break;
case MUSB_EP0_STAGE_RX: /* irq on set rxpktrdy */ if (csr & MUSB_CSR0_RXPKTRDY) {
ep0_rxstate(musb);
retval = IRQ_HANDLED;
} break;
case MUSB_EP0_STAGE_STATUSIN: /* end of sequence #2 (OUT/RX state) or #3 (no data) */
/* update address (if needed) only @ the end of the *statusphaseperusbspec,whichalsoguarantees *weget10msectoreceivethisirq...untilthis *isdonewewon'tseethenextpacket.
*/ if (musb->set_address) {
musb->set_address = false;
musb_writeb(mbase, MUSB_FADDR, musb->address);
}
/* enter test mode if needed (exit by reset) */ elseif (musb->test_mode) {
musb_dbg(musb, "entering TESTMODE");
if (MUSB_TEST_PACKET == musb->test_mode_nr)
musb_load_testpacket(musb);
/* sequence #3 (no data stage), includes requests *wecan'tforward(notablySET_ADDRESSandthe *device/endpointfeatureset/clearoperations) *plusSET_CONFIGURATIONandotherswemust
*/ case MUSB_EP0_STAGE_ACKWAIT:
handled = service_zero_data_request(
musb, &setup);
/* unless we need to delegate this to the gadget *driver,weknowhowtowrapthisup:csr0has *notyetbeenwritten.
*/ if (handled < 0) goto stall; elseif (handled > 0) goto finish;
case MUSB_EP0_STAGE_ACKWAIT: /* This should not happen. But happens with tusb6010 with *g_file_storageandhighspeed.Donothing.
*/
retval = IRQ_HANDLED; break;
if (!list_empty(&ep->req_list)) {
status = -EBUSY; goto cleanup;
}
switch (musb->ep0_state) { case MUSB_EP0_STAGE_RX: /* control-OUT data */ case MUSB_EP0_STAGE_TX: /* control-IN data */ case MUSB_EP0_STAGE_ACKWAIT: /* zero-length data */
status = 0; break; default:
musb_dbg(musb, "ep0 request queued in state %d",
musb->ep0_state);
status = -EINVAL; goto cleanup;
}
/* add request to the list */
list_add_tail(&req->list, &ep->req_list);
ep = to_musb_ep(e);
musb = ep->musb;
base = musb->mregs;
regs = musb->control_ep->regs;
status = 0;
spin_lock_irqsave(&musb->lock, flags);
if (!list_empty(&ep->req_list)) {
status = -EBUSY; goto cleanup;
}
musb_ep_select(base, 0);
csr = musb->ackpend;
switch (musb->ep0_state) {
/* Stalls are usually issued after parsing SETUP packet, either *directlyinirqcontextfromsetup()orelselater.
*/ case MUSB_EP0_STAGE_TX: /* control-IN data */ case MUSB_EP0_STAGE_ACKWAIT: /* STALL for zero-length data */ case MUSB_EP0_STAGE_RX: /* control-OUT data */
csr = musb_readw(regs, MUSB_CSR0);
fallthrough;
/* It's also OK to issue stalls during callbacks when a non-empty *DATAstagebufferhasbeenread(orevenwritten).
*/ case MUSB_EP0_STAGE_STATUSIN: /* control-OUT status */ case MUSB_EP0_STAGE_STATUSOUT: /* control-IN status */
csr |= MUSB_CSR0_P_SENDSTALL;
musb_writew(regs, MUSB_CSR0, csr);
musb->ep0_state = MUSB_EP0_STAGE_IDLE;
musb->ackpend = 0; break; default:
musb_dbg(musb, "ep0 can't halt in state %d", musb->ep0_state);
status = -EINVAL;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.21Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.