/*--- Dispatcher ---*/ int32 USBHost::dispatch(uint32 fncode) { int32 ret; D(bug("USBHost: dispatch(%u)", fncode)); ret = EINVFN; switch(fncode) { case GET_VERSION: D(bug("USBHost: getVersion")); ret = USBHOST_NFAPI_VERSION; break; case USBHOST_INTLEVEL: D(bug("USBHost: getINTlevel")); ret = INTLEVEL; break; case USBHOST_RH_PORT_STATUS: ret = rh_port_status(getParameter(0)); break; case USBHOST_LOWLEVEL_INIT: ret = usb_lowlevel_init(); break; case USBHOST_LOWLEVEL_STOP: ret = usb_lowlevel_stop(); break; case USBHOST_SUBMIT_CONTROL_MSG: ret = submit_control_msg(getParameter(0), getParameter(1), getParameter(2), getParameter(3)); break; case USBHOST_SUBMIT_INT_MSG: ret = submit_int_msg(getParameter(0), getParameter(1), getParameter(2), getParameter(3)); break; case USBHOST_SUBMIT_BULK_MSG: ret = submit_bulk_msg(getParameter(0), getParameter(1), getParameter(2)); break; default: D(bug("USBHost: unimplemented function #%d", fncode)); break; } D(bug("USBHost: function returning with 0x%08x", ret)); return ret; }
/*------------------------------------------------------------------- * submits bulk message, and waits for completion. returns 0 if Ok or * -1 if Error. * synchronous behavior */ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) { if (len < 0) return -1; dev->status=USB_ST_NOT_PROC; /*not yet processed */ if (usb_flag == usb_ehci_flag) submit_bulk_msg(dev,pipe,data,len); else if (usb_flag == usb_uhci_flag) submit_uhci_bulk_msg(dev,pipe,data,len); else return -1; *actual_length=dev->act_len; return 0; }
/*------------------------------------------------------------------- * submits bulk message, and waits for completion. returns 0 if Ok or * -1 if Error. * synchronous behavior */ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) { if (len < 0) return -1; dev->status = USB_ST_NOT_PROC; /*not yet processed */ submit_bulk_msg(dev, pipe, data, len); while (timeout--) { if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC)) break; wait_ms(1); } *actual_length = dev->act_len; if (dev->status == 0) return 0; else return -1; }
int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int len, int interval) { unsigned long timeout; int ret; /* FIXME: what is interval? */ timeout = get_timer(0) + USB_TIMEOUT_MS(pipe); for (;;) { if (get_timer(0) > timeout) { printf("Timeout poll on interrupt endpoint\n"); return -ETIMEDOUT; } ret = submit_bulk_msg(dev, pipe, buffer, len); if (ret != -EAGAIN) return ret; } }
/*------------------------------------------------------------------- * submits bulk message, and waits for completion. returns 0 if Ok or * -1 if Error. * synchronous behavior */ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) { if (len < 0) return -1; dev->status = USB_ST_NOT_PROC; /*not yet processed */ submit_bulk_msg(dev, pipe, data, len); if (USB_ST_DISCONNECT==dev->status) return -3; //USB_STOR_TRANSPORT_NODEV while(timeout>0) { if(!(dev->status & USB_ST_NOT_PROC)) break; wait_ms(1); timeout--; } *actual_length = dev->act_len; if (dev->status == 0) return 0; else return -1; }
/*------------------------------------------------------------------- * submits bulk message, and waits for completion. returns 0 if Ok or * negative if Error. * synchronous behavior */ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) { int ret = -1; if (len < 0) { return -EINVAL; } dev->status = USB_ST_NOT_PROC; /*not yet processed */ ret = submit_bulk_msg(dev, pipe, data, len); *actual_length = dev->act_len; return ret; /* * The following code is obsoluted. */ #if 0 if (ret < 0) { return ret; } while (timeout--) { if (!(dev->status & USB_ST_NOT_PROC)) break; mdelay(1); } *actual_length = dev->act_len; if (dev->status == 0) return 0; else return -EIO; #endif }