/* waits until tx ep is ready. Returns 1 when ep is ready and 0 on error.  */
static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
/* waits until tx ep is ready. Returns 1 when ep is ready and 0 on error.  */
static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
{
	u16 csr;
	int timeout = CONFIG_MUSB_TIMEOUT;
	do {
		if (check_stall(ep, 1)) {
			dev->status = USB_ST_STALLED;
			return 0;
		}
		csr = readw(&musbr->txcsr);
		if (csr & MUSB_TXCSR_H_ERROR) {
			dev->status = USB_ST_CRC_ERR;
			return 0;
		}
		if (--timeout)
			udelay(1);
		else {
			dev->status = USB_ST_CRC_ERR;
			return -1;
		}
	} while (csr & MUSB_TXCSR_TXPKTRDY);
	return 1;
}