summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2008-10-03 22:43:16 +0000
committerFrank Gevaerts <frank@gevaerts.be>2008-10-03 22:43:16 +0000
commit478fc5baed82e5573938041aed0f1a4f73f32128 (patch)
treeb7115cb1200101075bf93d93f61bd0be65ff9d42 /firmware/target
parent6219f4c862919367972e497c47324121fe48f3f6 (diff)
downloadrockbox-478fc5baed82e5573938041aed0f1a4f73f32128.tar.gz
rockbox-478fc5baed82e5573938041aed0f1a4f73f32128.zip
reorganise the USB stack a bit to allow for easier integration of non-ARC controller drivers
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18703 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/usb-drv-arc.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/firmware/target/arm/usb-drv-arc.c b/firmware/target/arm/usb-drv-arc.c
index a30e1c5139..529f6cf7f8 100644
--- a/firmware/target/arm/usb-drv-arc.c
+++ b/firmware/target/arm/usb-drv-arc.c
@@ -363,6 +363,8 @@ static const unsigned int pipe2mask[] = {
363 0x10, 0x100000, 363 0x10, 0x100000,
364}; 364};
365 365
366static char ep_allocation[NUM_ENDPOINTS];
367
366/*-------------------------------------------------------------------------*/ 368/*-------------------------------------------------------------------------*/
367static void transfer_completed(void); 369static void transfer_completed(void);
368static void control_received(void); 370static void control_received(void);
@@ -534,23 +536,23 @@ void usb_drv_int(void)
534bool usb_drv_stalled(int endpoint,bool in) 536bool usb_drv_stalled(int endpoint,bool in)
535{ 537{
536 if(in) { 538 if(in) {
537 return ((REG_ENDPTCTRL(endpoint) & EPCTRL_TX_EP_STALL)!=0); 539 return ((REG_ENDPTCTRL(endpoint&0x7f) & EPCTRL_TX_EP_STALL)!=0);
538 } 540 }
539 else { 541 else {
540 return ((REG_ENDPTCTRL(endpoint) & EPCTRL_RX_EP_STALL)!=0); 542 return ((REG_ENDPTCTRL(endpoint&0x7f) & EPCTRL_RX_EP_STALL)!=0);
541 } 543 }
542 544
543} 545}
544void usb_drv_stall(int endpoint, bool stall,bool in) 546void usb_drv_stall(int endpoint, bool stall,bool in)
545{ 547{
546 logf("%sstall %d", stall?"":"un", endpoint); 548 logf("%sstall %d", stall?"":"un", endpoint&0x7f);
547 549
548 if(in) { 550 if(in) {
549 if (stall) { 551 if (stall) {
550 REG_ENDPTCTRL(endpoint) |= EPCTRL_TX_EP_STALL; 552 REG_ENDPTCTRL(endpoint&0x7f) |= EPCTRL_TX_EP_STALL;
551 } 553 }
552 else { 554 else {
553 REG_ENDPTCTRL(endpoint) &= ~EPCTRL_TX_EP_STALL; 555 REG_ENDPTCTRL(endpoint&0x7f) &= ~EPCTRL_TX_EP_STALL;
554 } 556 }
555 } 557 }
556 else { 558 else {
@@ -565,23 +567,23 @@ void usb_drv_stall(int endpoint, bool stall,bool in)
565 567
566int usb_drv_send_nonblocking(int endpoint, void* ptr, int length) 568int usb_drv_send_nonblocking(int endpoint, void* ptr, int length)
567{ 569{
568 return prime_transfer(endpoint, ptr, length, true, false); 570 return prime_transfer(endpoint&0x7f, ptr, length, true, false);
569} 571}
570 572
571int usb_drv_send(int endpoint, void* ptr, int length) 573int usb_drv_send(int endpoint, void* ptr, int length)
572{ 574{
573 return prime_transfer(endpoint, ptr, length, true, true); 575 return prime_transfer(endpoint&0x7f, ptr, length, true, true);
574} 576}
575 577
576int usb_drv_recv(int endpoint, void* ptr, int length) 578int usb_drv_recv(int endpoint, void* ptr, int length)
577{ 579{
578 //logf("usbrecv(%x, %d)", ptr, length); 580 //logf("usbrecv(%x, %d)", ptr, length);
579 return prime_transfer(endpoint, ptr, length, false, false); 581 return prime_transfer(endpoint&0x7f, ptr, length, false, false);
580} 582}
581 583
582void usb_drv_wait(int endpoint, bool send) 584void usb_drv_wait(int endpoint, bool send)
583{ 585{
584 int pipe = endpoint * 2 + (send ? 1 : 0); 586 int pipe = (endpoint&0x7f) * 2 + (send ? 1 : 0);
585 struct queue_head* qh = &qh_array[pipe]; 587 struct queue_head* qh = &qh_array[pipe];
586 588
587 while (qh->dtd.size_ioc_sts & QH_STATUS_ACTIVE) { 589 while (qh->dtd.size_ioc_sts & QH_STATUS_ACTIVE) {
@@ -609,7 +611,7 @@ void usb_drv_set_address(int address)
609 611
610void usb_drv_reset_endpoint(int endpoint, bool send) 612void usb_drv_reset_endpoint(int endpoint, bool send)
611{ 613{
612 int pipe = endpoint * 2 + (send ? 1 : 0); 614 int pipe = (endpoint&0x7f) * 2 + (send ? 1 : 0);
613 unsigned int mask = pipe2mask[pipe]; 615 unsigned int mask = pipe2mask[pipe];
614 REG_ENDPTFLUSH = mask; 616 REG_ENDPTFLUSH = mask;
615 while (REG_ENDPTFLUSH & mask); 617 while (REG_ENDPTFLUSH & mask);
@@ -753,6 +755,29 @@ void usb_drv_cancel_all_transfers(void)
753 } 755 }
754} 756}
755 757
758int usb_drv_request_endpoint(int dir)
759{
760 int i, bit;
761
762 bit=(dir & USB_DIR_IN)? 2:1;
763
764 for (i=1; i < NUM_ENDPOINTS; i++) {
765 if((ep_allocation[i] & bit)!=0)
766 continue;
767 ep_allocation[i] |= bit;
768 return i | dir;
769 }
770
771 return -1;
772}
773
774void usb_drv_release_endpoint(int ep)
775{
776 int mask = (ep & USB_DIR_IN)? ~2:~1;
777 ep_allocation[ep & 0x7f] &= mask;
778}
779
780
756static void prepare_td(struct transfer_descriptor* td, 781static void prepare_td(struct transfer_descriptor* td,
757 struct transfer_descriptor* previous_td, 782 struct transfer_descriptor* previous_td,
758 void *ptr, int len,int pipe) 783 void *ptr, int len,int pipe)
@@ -831,7 +856,7 @@ static void transfer_completed(void)
831 qh->wait=0; 856 qh->wait=0;
832 wakeup_signal(&transfer_completion_signal[pipe]); 857 wakeup_signal(&transfer_completion_signal[pipe]);
833 } 858 }
834 usb_core_transfer_complete(ep, dir, qh->status, qh->length); 859 usb_core_transfer_complete(ep, dir?USB_DIR_IN:USB_DIR_OUT, qh->status, qh->length);
835 } 860 }
836 } 861 }
837 } 862 }
@@ -900,6 +925,7 @@ static void init_bulk_queue_heads(void)
900 rx_packetsize = 64; 925 rx_packetsize = 64;
901 tx_packetsize = 64; 926 tx_packetsize = 64;
902 } 927 }
928 /* TODO: this should take ep_allocation into account */
903 929
904 /*** bulk ***/ 930 /*** bulk ***/
905 for(i=1;i<NUM_ENDPOINTS;i++) { 931 for(i=1;i<NUM_ENDPOINTS;i++) {
@@ -913,6 +939,7 @@ static void init_bulk_queue_heads(void)
913static void init_endpoints(void) 939static void init_endpoints(void)
914{ 940{
915 int i; 941 int i;
942 /* TODO: this should take ep_allocation into account */
916 /* bulk */ 943 /* bulk */
917 for(i=1;i<NUM_ENDPOINTS;i++) { 944 for(i=1;i<NUM_ENDPOINTS;i++) {
918 REG_ENDPTCTRL(i) = 945 REG_ENDPTCTRL(i) =