forked from len0rd/rockbox
Revert "hwstub: rework usb driver for atj213x"
This reverts commit 0e2b4908d0
.
Although I swear it was tested it apparently broke hwstub on atj.
I will need to investigate more whats going on. Revert for now.
Change-Id: I2ff3adf8c72bb0e53be7d81b975382adfb700eab
This commit is contained in:
parent
3b7e7cb535
commit
f2da975be6
1 changed files with 104 additions and 142 deletions
|
@ -31,17 +31,6 @@
|
||||||
volatile bool setup_data_valid = false;
|
volatile bool setup_data_valid = false;
|
||||||
volatile int udc_speed = USB_FULL_SPEED;
|
volatile int udc_speed = USB_FULL_SPEED;
|
||||||
|
|
||||||
struct endpoint_t
|
|
||||||
{
|
|
||||||
void *buf;
|
|
||||||
int length;
|
|
||||||
bool zlp;
|
|
||||||
bool finished;
|
|
||||||
};
|
|
||||||
|
|
||||||
static volatile struct endpoint_t ep0in = {NULL,0,false,false};
|
|
||||||
static volatile struct endpoint_t ep0out = {NULL,0,false,false};
|
|
||||||
|
|
||||||
static void usb_copy_from(void *ptr, volatile void *reg, size_t sz)
|
static void usb_copy_from(void *ptr, volatile void *reg, size_t sz)
|
||||||
{
|
{
|
||||||
uint32_t *p = ptr;
|
uint32_t *p = ptr;
|
||||||
|
@ -78,6 +67,65 @@ static void usb_copy_to(volatile void *reg, void *ptr, size_t sz)
|
||||||
*rp++ = *p++;
|
*rp++ = *p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INT_UDC(void)
|
||||||
|
{
|
||||||
|
/* get possible sources */
|
||||||
|
unsigned int usbirq = OTG_USBIRQ;
|
||||||
|
unsigned int otgirq = OTG_OTGIRQ;
|
||||||
|
#if 0
|
||||||
|
unsigned int usbeirq = OTG_USBEIRQ;
|
||||||
|
unsigned int epinirq = OTG_IN04IRQ;
|
||||||
|
unsigned int epoutirq = OTG_OUT04IRQ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* HS, Reset, Setup */
|
||||||
|
if (usbirq)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (usbirq & (1<<5))
|
||||||
|
{
|
||||||
|
/* HS irq */
|
||||||
|
udc_speed = USB_HIGH_SPEED;
|
||||||
|
}
|
||||||
|
else if (usbirq & (1<<4))
|
||||||
|
{
|
||||||
|
/* Reset */
|
||||||
|
udc_speed = USB_FULL_SPEED;
|
||||||
|
|
||||||
|
/* clear all pending irqs */
|
||||||
|
OTG_OUT04IRQ = 0xff;
|
||||||
|
OTG_IN04IRQ = 0xff;
|
||||||
|
}
|
||||||
|
else if (usbirq & (1<<0))
|
||||||
|
{
|
||||||
|
/* Setup data valid */
|
||||||
|
setup_data_valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clear irq flags */
|
||||||
|
OTG_USBIRQ = usbirq;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (epoutirq)
|
||||||
|
{
|
||||||
|
OTG_OUT04IRQ = epoutirq;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (epinirq)
|
||||||
|
{
|
||||||
|
OTG_IN04IRQ = epinirq;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (otgirq)
|
||||||
|
{
|
||||||
|
OTG_OTGIRQ = otgirq;
|
||||||
|
}
|
||||||
|
|
||||||
|
OTG_USBEIRQ = 0x50;
|
||||||
|
}
|
||||||
|
|
||||||
void usb_drv_init(void)
|
void usb_drv_init(void)
|
||||||
{
|
{
|
||||||
OTG_USBCS |= 0x40; /* soft disconnect */
|
OTG_USBCS |= 0x40; /* soft disconnect */
|
||||||
|
@ -96,9 +144,9 @@ void usb_drv_init(void)
|
||||||
OTG_USBIEN = (1<<5) | (1<<4) | (1<<0); /* HS, Reset, Setup_data */
|
OTG_USBIEN = (1<<5) | (1<<4) | (1<<0); /* HS, Reset, Setup_data */
|
||||||
OTG_OTGIEN = 0;
|
OTG_OTGIEN = 0;
|
||||||
|
|
||||||
/* enable interrupts from ep0 */
|
/* disable interrupts from ep0 */
|
||||||
OTG_IN04IEN = 1;
|
OTG_IN04IEN = 0;
|
||||||
OTG_OUT04IEN = 1;
|
OTG_OUT04IEN = 0;
|
||||||
|
|
||||||
/* unmask UDC interrupt in interrupt controller */
|
/* unmask UDC interrupt in interrupt controller */
|
||||||
INTC_MSK = (1<<4);
|
INTC_MSK = (1<<4);
|
||||||
|
@ -135,75 +183,71 @@ void usb_drv_set_address(int address)
|
||||||
/* UDC sets this automaticaly */
|
/* UDC sets this automaticaly */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ep0_write(void)
|
|
||||||
{
|
|
||||||
int xfer_size = MIN(ep0in.length, 64);
|
|
||||||
|
|
||||||
/* copy data to UDC buffer */
|
|
||||||
usb_copy_to(&OTG_EP0INDAT, ep0in.buf, xfer_size);
|
|
||||||
ep0in.buf += xfer_size;
|
|
||||||
ep0in.length -= xfer_size;
|
|
||||||
|
|
||||||
/* this marks data as ready to send */
|
|
||||||
OTG_IN0BC = xfer_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Maybe adapt to irq scheme */
|
/* TODO: Maybe adapt to irq scheme */
|
||||||
int usb_drv_send(int endpoint, void *ptr, int length)
|
int usb_drv_send(int endpoint, void *ptr, int length)
|
||||||
{
|
{
|
||||||
(void)endpoint;
|
(void)endpoint;
|
||||||
|
|
||||||
if (length)
|
int xfer_size, cnt = length;
|
||||||
|
|
||||||
|
while (cnt)
|
||||||
{
|
{
|
||||||
ep0in.length = length;
|
xfer_size = MIN(cnt, 64);
|
||||||
ep0in.buf = ptr;
|
|
||||||
ep0in.zlp = (length % 64 == 0) ? true : false;
|
|
||||||
ep0in.finished = false;
|
|
||||||
|
|
||||||
ep0_write();
|
/* copy data to ep0in buffer */
|
||||||
|
usb_copy_to(&OTG_EP0INDAT, ptr, xfer_size);
|
||||||
|
|
||||||
while(!ep0in.finished)
|
/* this marks data as ready to send */
|
||||||
|
OTG_IN0BC = xfer_size;
|
||||||
|
|
||||||
|
/* wait for the transfer end */
|
||||||
|
while(OTG_EP0CS & 0x04)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
cnt -= xfer_size;
|
||||||
|
ptr += xfer_size;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
/* ZLP stage */
|
||||||
|
if((length % 64) == 0)
|
||||||
OTG_EP0CS = 2;
|
OTG_EP0CS = 2;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ep0_read(void)
|
|
||||||
{
|
|
||||||
int xfer_size = OTG_OUT0BC;
|
|
||||||
usb_copy_from(ep0out.buf, &OTG_EP0OUTDAT, xfer_size);
|
|
||||||
ep0out.buf += xfer_size;
|
|
||||||
ep0out.length -= xfer_size;
|
|
||||||
|
|
||||||
return xfer_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Maybe adapt to irq scheme */
|
/* TODO: Maybe adapt to irq scheme */
|
||||||
int usb_drv_recv(int endpoint, void* ptr, int length)
|
int usb_drv_recv(int endpoint, void* ptr, int length)
|
||||||
{
|
{
|
||||||
(void)endpoint;
|
(void)endpoint;
|
||||||
|
int xfer_size, cnt = 0;
|
||||||
|
|
||||||
ep0out.length = length;
|
while (cnt < length)
|
||||||
ep0out.buf = ptr;
|
{
|
||||||
ep0out.zlp = (length == 0) ? true : false;
|
/* Arm receiving buffer by writing
|
||||||
ep0out.finished = false;
|
* any value to OUT0BC. This sets
|
||||||
|
* OUT_BUSY bit in EP0CS until the data
|
||||||
|
* are correctly received and ACK'd
|
||||||
|
*/
|
||||||
|
OTG_OUT0BC = 0;
|
||||||
|
|
||||||
/* Arm receiving buffer by writing
|
while (OTG_EP0CS & 0x08)
|
||||||
* any value to OUT0BC. This sets
|
;
|
||||||
* OUT_BUSY bit in EP0CS until the data
|
|
||||||
* are correctly received and ACK'd
|
|
||||||
*/
|
|
||||||
OTG_OUT0BC = 0;
|
|
||||||
|
|
||||||
while (!ep0out.finished)
|
xfer_size = OTG_OUT0BC;
|
||||||
;
|
|
||||||
|
|
||||||
return (length - ep0out.length);
|
usb_copy_from(ptr, &OTG_EP0OUTDAT, xfer_size);
|
||||||
|
cnt += xfer_size;
|
||||||
|
ptr += xfer_size;
|
||||||
|
|
||||||
|
if (xfer_size < 64)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ZLP stage */
|
||||||
|
if (length == 0)
|
||||||
|
OTG_EP0CS = 2;
|
||||||
|
|
||||||
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_drv_stall(int endpoint, bool stall, bool in)
|
void usb_drv_stall(int endpoint, bool stall, bool in)
|
||||||
|
@ -221,85 +265,3 @@ void usb_drv_stall(int endpoint, bool stall, bool in)
|
||||||
void usb_drv_exit(void)
|
void usb_drv_exit(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void INT_UDC(void)
|
|
||||||
{
|
|
||||||
/* get possible sources */
|
|
||||||
unsigned int usbirq = OTG_USBIRQ;
|
|
||||||
unsigned int otgirq = OTG_OTGIRQ;
|
|
||||||
unsigned int epinirq = OTG_IN04IRQ;
|
|
||||||
unsigned int epoutirq = OTG_OUT04IRQ;
|
|
||||||
|
|
||||||
/* HS, Reset, Setup */
|
|
||||||
if (usbirq)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (usbirq & (1<<5))
|
|
||||||
{
|
|
||||||
/* HS irq */
|
|
||||||
udc_speed = USB_HIGH_SPEED;
|
|
||||||
}
|
|
||||||
else if (usbirq & (1<<4))
|
|
||||||
{
|
|
||||||
/* Reset */
|
|
||||||
udc_speed = USB_FULL_SPEED;
|
|
||||||
|
|
||||||
/* clear all pending irqs */
|
|
||||||
OTG_OUT04IRQ = 0xff;
|
|
||||||
OTG_IN04IRQ = 0xff;
|
|
||||||
}
|
|
||||||
else if (usbirq & (1<<0))
|
|
||||||
{
|
|
||||||
/* Setup data valid */
|
|
||||||
setup_data_valid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clear irq flags */
|
|
||||||
OTG_USBIRQ = usbirq;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (epoutirq)
|
|
||||||
{
|
|
||||||
if (ep0_read() == 64)
|
|
||||||
{
|
|
||||||
/* rearm receive buffer */
|
|
||||||
OTG_OUT0BC = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ep0out.length == 0 && ep0out.zlp)
|
|
||||||
{
|
|
||||||
OTG_EP0CS = 2;
|
|
||||||
}
|
|
||||||
ep0out.finished = true;
|
|
||||||
}
|
|
||||||
OTG_OUT04IRQ = epoutirq;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (epinirq)
|
|
||||||
{
|
|
||||||
if (ep0in.length)
|
|
||||||
{
|
|
||||||
ep0_write();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ep0in.zlp)
|
|
||||||
{
|
|
||||||
OTG_EP0CS = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
ep0in.finished = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ack interrupt */
|
|
||||||
OTG_IN04IRQ = epinirq;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otgirq)
|
|
||||||
{
|
|
||||||
OTG_OTGIRQ = otgirq;
|
|
||||||
}
|
|
||||||
|
|
||||||
OTG_USBEIRQ = 0x50;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue