1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <common.h>
28#include <asm/io.h>
29
30#include <usbdevice.h>
31#include "ep0.h"
32#include <usb/spr_udc.h>
33#include <asm/arch/hardware.h>
34#include <asm/arch/spr_misc.h>
35
36#define UDC_INIT_MDELAY 80
37
38
39#ifndef DEBUG_SPRUSBTTY
40#define UDCDBG(str)
41#define UDCDBGA(fmt, args...)
42#else
43#define UDCDBG(str) serial_printf(str "\n")
44#define UDCDBGA(fmt, args...) serial_printf(fmt "\n", ##args)
45#endif
46
47static struct urb *ep0_urb;
48static struct usb_device_instance *udc_device;
49
50static struct plug_regs *const plug_regs_p =
51 (struct plug_regs * const)CONFIG_SYS_PLUG_BASE;
52static struct udc_regs *const udc_regs_p =
53 (struct udc_regs * const)CONFIG_SYS_USBD_BASE;
54static struct udc_endp_regs *const outep_regs_p =
55 &((struct udc_regs * const)CONFIG_SYS_USBD_BASE)->out_regs[0];
56static struct udc_endp_regs *const inep_regs_p =
57 &((struct udc_regs * const)CONFIG_SYS_USBD_BASE)->in_regs[0];
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107static void udc_state_transition(usb_device_state_t initial,
108 usb_device_state_t final)
109{
110 if (initial < final) {
111 switch (initial) {
112 case STATE_ATTACHED:
113 usbd_device_event_irq(udc_device,
114 DEVICE_HUB_CONFIGURED, 0);
115 if (final == STATE_POWERED)
116 break;
117 case STATE_POWERED:
118 usbd_device_event_irq(udc_device, DEVICE_RESET, 0);
119 if (final == STATE_DEFAULT)
120 break;
121 case STATE_DEFAULT:
122 usbd_device_event_irq(udc_device,
123 DEVICE_ADDRESS_ASSIGNED, 0);
124 if (final == STATE_ADDRESSED)
125 break;
126 case STATE_ADDRESSED:
127 usbd_device_event_irq(udc_device, DEVICE_CONFIGURED, 0);
128 case STATE_CONFIGURED:
129 break;
130 default:
131 break;
132 }
133 } else if (initial > final) {
134 switch (initial) {
135 case STATE_CONFIGURED:
136 usbd_device_event_irq(udc_device,
137 DEVICE_DE_CONFIGURED, 0);
138 if (final == STATE_ADDRESSED)
139 break;
140 case STATE_ADDRESSED:
141 usbd_device_event_irq(udc_device, DEVICE_RESET, 0);
142 if (final == STATE_DEFAULT)
143 break;
144 case STATE_DEFAULT:
145 usbd_device_event_irq(udc_device,
146 DEVICE_POWER_INTERRUPTION, 0);
147 if (final == STATE_POWERED)
148 break;
149 case STATE_POWERED:
150 usbd_device_event_irq(udc_device, DEVICE_HUB_RESET, 0);
151 case STATE_ATTACHED:
152 break;
153 default:
154 break;
155 }
156 }
157}
158
159
160static void udc_stall_ep(u32 ep_num)
161{
162 writel(readl(&inep_regs_p[ep_num].endp_cntl) | ENDP_CNTL_STALL,
163 &inep_regs_p[ep_num].endp_cntl);
164
165 writel(readl(&outep_regs_p[ep_num].endp_cntl) | ENDP_CNTL_STALL,
166 &outep_regs_p[ep_num].endp_cntl);
167}
168
169static void *get_fifo(int ep_num, int in)
170{
171 u32 *fifo_ptr = (u32 *)CONFIG_SYS_FIFO_BASE;
172
173 switch (ep_num) {
174 case UDC_EP3:
175 fifo_ptr += readl(&inep_regs_p[1].endp_bsorfn);
176
177
178 case UDC_EP1:
179 fifo_ptr += readl(&inep_regs_p[0].endp_bsorfn);
180
181
182 case UDC_EP0:
183 default:
184 if (in) {
185 fifo_ptr +=
186 readl(&outep_regs_p[2].endp_maxpacksize) >> 16;
187
188 } else {
189 break;
190 }
191
192 case UDC_EP2:
193 fifo_ptr += readl(&outep_regs_p[0].endp_maxpacksize) >> 16;
194
195 }
196
197 return (void *)fifo_ptr;
198}
199
200static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len)
201{
202 u8 *fifo_ptr = (u8 *)get_fifo(epNum, 0);
203 u32 i, nw, nb;
204 u32 *wrdp;
205 u8 *bytp;
206
207 if (readl(&udc_regs_p->dev_stat) & DEV_STAT_RXFIFO_EMPTY)
208 return -1;
209
210 nw = len / sizeof(u32);
211 nb = len % sizeof(u32);
212
213 wrdp = (u32 *)bufp;
214 for (i = 0; i < nw; i++) {
215 writel(readl(fifo_ptr), wrdp);
216 wrdp++;
217 }
218
219 bytp = (u8 *)wrdp;
220 for (i = 0; i < nb; i++) {
221 writeb(readb(fifo_ptr), bytp);
222 fifo_ptr++;
223 bytp++;
224 }
225 readl(&outep_regs_p[epNum].write_done);
226
227 return 0;
228}
229
230static void usbputpcktofifo(int epNum, u8 *bufp, u32 len)
231{
232 u32 i, nw, nb;
233 u32 *wrdp;
234 u8 *bytp;
235 u8 *fifo_ptr = get_fifo(epNum, 1);
236
237 nw = len / sizeof(int);
238 nb = len % sizeof(int);
239 wrdp = (u32 *)bufp;
240 for (i = 0; i < nw; i++) {
241 writel(*wrdp, fifo_ptr);
242 wrdp++;
243 }
244
245 bytp = (u8 *)wrdp;
246 for (i = 0; i < nb; i++) {
247 writeb(*bytp, fifo_ptr);
248 fifo_ptr++;
249 bytp++;
250 }
251}
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266static void spear_write_noniso_tx_fifo(struct usb_endpoint_instance
267 *endpoint)
268{
269 struct urb *urb = endpoint->tx_urb;
270 int align;
271
272 if (urb) {
273 u32 last;
274
275 UDCDBGA("urb->buffer %p, buffer_length %d, actual_length %d",
276 urb->buffer, urb->buffer_length, urb->actual_length);
277
278 last = MIN(urb->actual_length - endpoint->sent,
279 endpoint->tx_packetSize);
280
281 if (last) {
282 u8 *cp = urb->buffer + endpoint->sent;
283
284
285
286
287
288
289
290
291
292 align = ((ulong)cp % sizeof(int));
293 if (align)
294 last = MIN(last, sizeof(int) - align);
295
296 UDCDBGA("endpoint->sent %d, tx_packetSize %d, last %d",
297 endpoint->sent, endpoint->tx_packetSize, last);
298
299 usbputpcktofifo(endpoint->endpoint_address &
300 USB_ENDPOINT_NUMBER_MASK, cp, last);
301 }
302 endpoint->last = last;
303 }
304}
305
306
307
308
309
310static void spear_udc_setup(struct usb_endpoint_instance *endpoint)
311{
312 u8 *datap = (u8 *)&ep0_urb->device_request;
313 int ep_addr = endpoint->endpoint_address;
314
315 UDCDBG("-> Entering device setup");
316 usbgetpckfromfifo(ep_addr, datap, 8);
317
318
319 if (ep0_recv_setup(ep0_urb)) {
320
321 udc_stall_ep(0);
322 UDCDBG("can't parse setup packet, still waiting for setup");
323 return;
324 }
325
326
327 if ((ep0_urb->device_request.bmRequestType & USB_REQ_DIRECTION_MASK)
328 == USB_REQ_HOST2DEVICE) {
329 UDCDBG("control write on EP0");
330 if (le16_to_cpu(ep0_urb->device_request.wLength)) {
331
332 UDCDBG("Stalling unsupported EP0 control write data "
333 "stage.");
334 udc_stall_ep(0);
335 }
336 } else {
337
338 UDCDBG("control read on EP0");
339
340
341
342
343
344 endpoint->tx_urb = ep0_urb;
345 endpoint->sent = 0;
346
347
348
349
350
351 spear_write_noniso_tx_fifo(endpoint);
352
353 writel(0x0, &inep_regs_p[ep_addr].write_done);
354 }
355
356 udc_unset_nak(endpoint->endpoint_address);
357
358 UDCDBG("<- Leaving device setup");
359}
360
361
362
363
364static void spear_udc_ep0_rx(struct usb_endpoint_instance *endpoint)
365{
366 u8 dummy[64];
367
368 UDCDBG("RX on EP0");
369
370
371 if ((ep0_urb->device_request.bmRequestType
372 & USB_REQ_DIRECTION_MASK) == USB_REQ_HOST2DEVICE) {
373
374
375
376
377
378
379
380
381 UDCDBG("Stalling unexpected EP0 control write "
382 "data stage packet");
383 udc_stall_ep(0);
384 } else {
385
386
387
388
389 UDCDBG("ACK on EP0 control read status stage packet");
390 u32 len = (readl(&outep_regs_p[0].endp_status) >> 11) & 0xfff;
391 usbgetpckfromfifo(0, dummy, len);
392 }
393}
394
395
396
397
398static void spear_udc_ep0_tx(struct usb_endpoint_instance *endpoint)
399{
400 struct usb_device_request *request = &ep0_urb->device_request;
401 int ep_addr;
402
403 UDCDBG("TX on EP0");
404
405
406 if ((request->bmRequestType & USB_REQ_DIRECTION_MASK) ==
407 USB_REQ_HOST2DEVICE) {
408
409
410
411
412 UDCDBG("ACK on EP0 control write status stage packet");
413 } else {
414
415
416
417
418 int wLength = le16_to_cpu(request->wLength);
419
420
421
422
423
424 endpoint->sent += endpoint->last;
425
426
427
428
429
430
431
432
433
434
435 if ((endpoint->sent == ep0_urb->actual_length) &&
436 ((ep0_urb->actual_length == wLength) ||
437 (endpoint->last != endpoint->tx_packetSize))) {
438
439 UDCDBG("control read data stage complete");
440 } else {
441
442
443
444
445
446 UDCDBG("ACK control read data stage packet");
447 spear_write_noniso_tx_fifo(endpoint);
448
449 ep_addr = endpoint->endpoint_address;
450 writel(0x0, &inep_regs_p[ep_addr].write_done);
451 }
452 }
453}
454
455static struct usb_endpoint_instance *spear_find_ep(int ep)
456{
457 int i;
458
459 for (i = 0; i < udc_device->bus->max_endpoints; i++) {
460 if ((udc_device->bus->endpoint_array[i].endpoint_address &
461 USB_ENDPOINT_NUMBER_MASK) == ep)
462 return &udc_device->bus->endpoint_array[i];
463 }
464 return NULL;
465}
466
467
468
469
470
471
472static void spear_udc_epn_rx(int ep)
473{
474 int nbytes = 0;
475 struct urb *urb;
476 struct usb_endpoint_instance *endpoint = spear_find_ep(ep);
477
478 if (endpoint) {
479 urb = endpoint->rcv_urb;
480
481 if (urb) {
482 u8 *cp = urb->buffer + urb->actual_length;
483
484 nbytes = (readl(&outep_regs_p[ep].endp_status) >> 11) &
485 0xfff;
486 usbgetpckfromfifo(ep, cp, nbytes);
487 usbd_rcv_complete(endpoint, nbytes, 0);
488 }
489 }
490}
491
492
493
494
495
496
497static void spear_udc_epn_tx(int ep)
498{
499 struct usb_endpoint_instance *endpoint = spear_find_ep(ep);
500
501
502
503
504
505
506 if (endpoint && endpoint->tx_urb && endpoint->tx_urb->actual_length) {
507 if (endpoint->last == endpoint->tx_packetSize) {
508
509 writel(0x0, &inep_regs_p[ep].write_done);
510 }
511
512 usbd_tx_complete(endpoint);
513
514
515
516
517 if (endpoint->tx_urb && endpoint->tx_urb->actual_length) {
518
519 spear_write_noniso_tx_fifo(endpoint);
520 writel(0x0, &inep_regs_p[ep].write_done);
521
522 } else if (endpoint->tx_urb
523 && (endpoint->tx_urb->actual_length == 0)) {
524
525 }
526 }
527}
528
529
530
531
532
533
534int udc_endpoint_write(struct usb_endpoint_instance *endpoint)
535{
536 udc_unset_nak(endpoint->endpoint_address & USB_ENDPOINT_NUMBER_MASK);
537 return 0;
538}
539
540
541int udc_init(void)
542{
543 int i;
544 u32 plug_st;
545
546 udc_device = NULL;
547
548 UDCDBG("starting");
549
550 readl(&plug_regs_p->plug_pending);
551
552 udc_disconnect();
553
554 for (i = 0; i < UDC_INIT_MDELAY; i++)
555 udelay(1000);
556
557 plug_st = readl(&plug_regs_p->plug_state);
558 writel(plug_st | PLUG_STATUS_EN, &plug_regs_p->plug_state);
559
560 writel(~0x0, &udc_regs_p->endp_int);
561 writel(~0x0, &udc_regs_p->dev_int_mask);
562 writel(~0x0, &udc_regs_p->endp_int_mask);
563
564 writel(DEV_CONF_FS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
565
566 DEV_CONF_PHYINT_16, &udc_regs_p->dev_conf);
567
568 writel(0x0, &udc_regs_p->dev_cntl);
569
570
571 writel(DEV_INT_MSK, &udc_regs_p->dev_int);
572
573 return 0;
574}
575
576
577
578
579
580void udc_setup_ep(struct usb_device_instance *device,
581 u32 ep, struct usb_endpoint_instance *endpoint)
582{
583 UDCDBGA("setting up endpoint addr %x", endpoint->endpoint_address);
584 int ep_addr;
585 int ep_num, ep_type;
586 int packet_size;
587 int buffer_size;
588 int attributes;
589 char *tt;
590 u32 endp_intmask;
591
592 tt = getenv("usbtty");
593 if (!tt)
594 tt = "generic";
595
596 ep_addr = endpoint->endpoint_address;
597 ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK;
598
599 if ((ep_addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
600
601 packet_size = endpoint->tx_packetSize;
602 buffer_size = packet_size * 2;
603 attributes = endpoint->tx_attributes;
604 } else {
605
606 packet_size = endpoint->rcv_packetSize;
607 buffer_size = packet_size * 2;
608 attributes = endpoint->rcv_attributes;
609 }
610
611 switch (attributes & USB_ENDPOINT_XFERTYPE_MASK) {
612 case USB_ENDPOINT_XFER_CONTROL:
613 ep_type = ENDP_EPTYPE_CNTL;
614 break;
615 case USB_ENDPOINT_XFER_BULK:
616 default:
617 ep_type = ENDP_EPTYPE_BULK;
618 break;
619 case USB_ENDPOINT_XFER_INT:
620 ep_type = ENDP_EPTYPE_INT;
621 break;
622 case USB_ENDPOINT_XFER_ISOC:
623 ep_type = ENDP_EPTYPE_ISO;
624 break;
625 }
626
627 struct udc_endp_regs *out_p = &outep_regs_p[ep_num];
628 struct udc_endp_regs *in_p = &inep_regs_p[ep_num];
629
630 if (!ep_addr) {
631
632 buffer_size = packet_size;
633
634 writel(readl(&in_p->endp_cntl) | ENDP_CNTL_CNAK,
635 &in_p->endp_cntl);
636
637 writel(readl(&out_p->endp_cntl) | ENDP_CNTL_CNAK,
638 &out_p->endp_cntl);
639
640 writel(ENDP_CNTL_CONTROL | ENDP_CNTL_FLUSH, &in_p->endp_cntl);
641
642 writel(buffer_size / sizeof(int), &in_p->endp_bsorfn);
643
644 writel(packet_size, &in_p->endp_maxpacksize);
645
646 writel(ENDP_CNTL_CONTROL | ENDP_CNTL_RRDY, &out_p->endp_cntl);
647
648 writel(packet_size | ((buffer_size / sizeof(int)) << 16),
649 &out_p->endp_maxpacksize);
650
651 writel((packet_size << 19) | ENDP_EPTYPE_CNTL,
652 &udc_regs_p->udc_endp_reg[ep_num]);
653
654 } else if ((ep_addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
655
656 writel(0x0, &in_p->endp_status);
657 writel((ep_type << 4) | ENDP_CNTL_RRDY, &in_p->endp_cntl);
658 writel(buffer_size / sizeof(int), &in_p->endp_bsorfn);
659 writel(packet_size, &in_p->endp_maxpacksize);
660
661 if (!strcmp(tt, "cdc_acm")) {
662 if (ep_type == ENDP_EPTYPE_INT) {
663
664 writel((packet_size << 19) |
665 ENDP_EPDIR_IN | (1 << 7) |
666 (0 << 11) | (ep_type << 5) | ep_num,
667 &udc_regs_p->udc_endp_reg[ep_num]);
668 } else {
669
670 writel((packet_size << 19) |
671 ENDP_EPDIR_IN | (1 << 7) |
672 (1 << 11) | (ep_type << 5) | ep_num,
673 &udc_regs_p->udc_endp_reg[ep_num]);
674 }
675 } else {
676
677 writel((packet_size << 19) |
678 ENDP_EPDIR_IN | (1 << 7) |
679 (0 << 11) | (ep_type << 5) | ep_num,
680 &udc_regs_p->udc_endp_reg[ep_num]);
681 }
682
683 } else {
684
685 writel(0x0, &out_p->endp_status);
686 writel((ep_type << 4) | ENDP_CNTL_RRDY, &out_p->endp_cntl);
687 writel(packet_size | ((buffer_size / sizeof(int)) << 16),
688 &out_p->endp_maxpacksize);
689
690 if (!strcmp(tt, "cdc_acm")) {
691 writel((packet_size << 19) |
692 ENDP_EPDIR_OUT | (1 << 7) |
693 (1 << 11) | (ep_type << 5) | ep_num,
694 &udc_regs_p->udc_endp_reg[ep_num]);
695 } else {
696 writel((packet_size << 19) |
697 ENDP_EPDIR_OUT | (1 << 7) |
698 (0 << 11) | (ep_type << 5) | ep_num,
699 &udc_regs_p->udc_endp_reg[ep_num]);
700 }
701
702 }
703
704 endp_intmask = readl(&udc_regs_p->endp_int_mask);
705 endp_intmask &= ~((1 << ep_num) | 0x10000 << ep_num);
706 writel(endp_intmask, &udc_regs_p->endp_int_mask);
707}
708
709
710void udc_connect(void)
711{
712 u32 plug_st;
713
714 plug_st = readl(&plug_regs_p->plug_state);
715 plug_st &= ~(PLUG_STATUS_PHY_RESET | PLUG_STATUS_PHY_MODE);
716 writel(plug_st, &plug_regs_p->plug_state);
717}
718
719
720void udc_disconnect(void)
721{
722 u32 plug_st;
723
724 plug_st = readl(&plug_regs_p->plug_state);
725 plug_st |= (PLUG_STATUS_PHY_RESET | PLUG_STATUS_PHY_MODE);
726 writel(plug_st, &plug_regs_p->plug_state);
727}
728
729
730void udc_enable(struct usb_device_instance *device)
731{
732 UDCDBGA("enable device %p, status %d", device, device->status);
733
734
735 udc_device = device;
736
737
738 if (!ep0_urb) {
739 ep0_urb =
740 usbd_alloc_urb(udc_device, udc_device->bus->endpoint_array);
741 } else {
742 serial_printf("udc_enable: ep0_urb already allocated %p\n",
743 ep0_urb);
744 }
745
746 writel(DEV_INT_SOF, &udc_regs_p->dev_int_mask);
747}
748
749
750
751
752void udc_startup_events(struct usb_device_instance *device)
753{
754
755 usbd_device_event_irq(device, DEVICE_INIT, 0);
756
757
758
759
760
761 usbd_device_event_irq(device, DEVICE_CREATE, 0);
762
763
764
765
766
767
768
769
770
771
772
773 udc_enable(device);
774}
775
776
777
778
779void spear_udc_plug_irq(void)
780{
781 if (readl(&plug_regs_p->plug_state) & PLUG_STATUS_ATTACHED) {
782
783
784
785
786
787 udc_connect();
788 writel(DEV_INT_SOF, &udc_regs_p->dev_int_mask);
789
790 UDCDBG("device attached and powered");
791 udc_state_transition(udc_device->device_state, STATE_POWERED);
792 } else {
793
794
795
796
797 udc_disconnect();
798 writel(~0x0, &udc_regs_p->dev_int_mask);
799
800 UDCDBG("device detached or unpowered");
801 udc_state_transition(udc_device->device_state, STATE_ATTACHED);
802 }
803}
804
805
806
807
808void spear_udc_dev_irq(void)
809{
810 if (readl(&udc_regs_p->dev_int) & DEV_INT_USBRESET) {
811 writel(~0x0, &udc_regs_p->endp_int_mask);
812
813 udc_connect();
814
815 writel(readl(&inep_regs_p[0].endp_cntl) | ENDP_CNTL_FLUSH,
816 &inep_regs_p[0].endp_cntl);
817
818 writel(DEV_INT_USBRESET, &udc_regs_p->dev_int);
819
820 UDCDBG("device reset in progess");
821 udc_state_transition(udc_device->device_state, STATE_DEFAULT);
822 }
823
824
825 if (readl(&udc_regs_p->dev_int) & DEV_INT_ENUM) {
826 writel(DEV_INT_ENUM, &udc_regs_p->dev_int);
827
828
829 writel(readl(&udc_regs_p->endp_int_mask) & ~0x10001,
830 &udc_regs_p->endp_int_mask);
831
832 UDCDBG("default -> addressed");
833 udc_state_transition(udc_device->device_state, STATE_ADDRESSED);
834 }
835
836
837 if (readl(&udc_regs_p->dev_int) & DEV_INT_INACTIVE) {
838 writel(DEV_INT_INACTIVE, &udc_regs_p->dev_int);
839
840 UDCDBG("entering inactive state");
841
842 }
843
844
845 if (readl(&udc_regs_p->dev_int) & DEV_INT_SETCFG) {
846 writel(DEV_INT_SETCFG, &udc_regs_p->dev_int);
847
848 UDCDBG("entering configured state");
849 udc_state_transition(udc_device->device_state,
850 STATE_CONFIGURED);
851 }
852
853
854 if (readl(&udc_regs_p->dev_int) & DEV_INT_SETINTF)
855 writel(DEV_INT_SETINTF, &udc_regs_p->dev_int);
856
857
858 if (readl(&udc_regs_p->dev_int) & DEV_INT_SUSPUSB) {
859 writel(DEV_INT_SUSPUSB, &udc_regs_p->dev_int);
860
861 UDCDBG("entering suspended state");
862 usbd_device_event_irq(udc_device, DEVICE_BUS_INACTIVE, 0);
863 }
864
865
866 if (readl(&udc_regs_p->dev_int) & DEV_INT_SOF)
867 writel(DEV_INT_SOF, &udc_regs_p->dev_int);
868}
869
870
871
872
873void spear_udc_endpoint_irq(void)
874{
875 while (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLOUT) {
876
877 writel(ENDP0_INT_CTRLOUT, &udc_regs_p->endp_int);
878
879 if ((readl(&outep_regs_p[0].endp_status) & ENDP_STATUS_OUTMSK)
880 == ENDP_STATUS_OUT_SETUP) {
881 spear_udc_setup(udc_device->bus->endpoint_array + 0);
882 writel(ENDP_STATUS_OUT_SETUP,
883 &outep_regs_p[0].endp_status);
884
885 } else if ((readl(&outep_regs_p[0].endp_status) &
886 ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_DATA) {
887 spear_udc_ep0_rx(udc_device->bus->endpoint_array + 0);
888 writel(ENDP_STATUS_OUT_DATA,
889 &outep_regs_p[0].endp_status);
890
891 } else if ((readl(&outep_regs_p[0].endp_status) &
892 ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_NONE) {
893
894 }
895
896 writel(0x0, &outep_regs_p[0].endp_status);
897 }
898
899 if (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLIN) {
900 spear_udc_ep0_tx(udc_device->bus->endpoint_array + 0);
901
902 writel(ENDP_STATUS_IN, &inep_regs_p[0].endp_status);
903 writel(ENDP0_INT_CTRLIN, &udc_regs_p->endp_int);
904 }
905
906 while (readl(&udc_regs_p->endp_int) & ENDP_INT_NONISOOUT_MSK) {
907 u32 epnum = 0;
908 u32 ep_int = readl(&udc_regs_p->endp_int) &
909 ENDP_INT_NONISOOUT_MSK;
910
911 ep_int >>= 16;
912 while (0x0 == (ep_int & 0x1)) {
913 ep_int >>= 1;
914 epnum++;
915 }
916
917 writel((1 << 16) << epnum, &udc_regs_p->endp_int);
918
919 if ((readl(&outep_regs_p[epnum].endp_status) &
920 ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_DATA) {
921
922 spear_udc_epn_rx(epnum);
923 writel(ENDP_STATUS_OUT_DATA,
924 &outep_regs_p[epnum].endp_status);
925 } else if ((readl(&outep_regs_p[epnum].endp_status) &
926 ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_NONE) {
927 writel(0x0, &outep_regs_p[epnum].endp_status);
928 }
929 }
930
931 if (readl(&udc_regs_p->endp_int) & ENDP_INT_NONISOIN_MSK) {
932 u32 epnum = 0;
933 u32 ep_int = readl(&udc_regs_p->endp_int) &
934 ENDP_INT_NONISOIN_MSK;
935
936 while (0x0 == (ep_int & 0x1)) {
937 ep_int >>= 1;
938 epnum++;
939 }
940
941 if (readl(&inep_regs_p[epnum].endp_status) & ENDP_STATUS_IN) {
942 writel(ENDP_STATUS_IN,
943 &outep_regs_p[epnum].endp_status);
944 spear_udc_epn_tx(epnum);
945
946 writel(ENDP_STATUS_IN,
947 &outep_regs_p[epnum].endp_status);
948 }
949
950 writel((1 << epnum), &udc_regs_p->endp_int);
951 }
952}
953
954
955
956
957void udc_irq(void)
958{
959
960
961
962
963
964
965 while (readl(&plug_regs_p->plug_pending))
966 spear_udc_plug_irq();
967
968 while (readl(&udc_regs_p->dev_int))
969 spear_udc_dev_irq();
970
971 if (readl(&udc_regs_p->endp_int))
972 spear_udc_endpoint_irq();
973}
974
975
976void udc_set_nak(int epid)
977{
978 writel(readl(&inep_regs_p[epid].endp_cntl) | ENDP_CNTL_SNAK,
979 &inep_regs_p[epid].endp_cntl);
980
981 writel(readl(&outep_regs_p[epid].endp_cntl) | ENDP_CNTL_SNAK,
982 &outep_regs_p[epid].endp_cntl);
983}
984
985void udc_unset_nak(int epid)
986{
987 u32 val;
988
989 val = readl(&inep_regs_p[epid].endp_cntl);
990 val &= ~ENDP_CNTL_SNAK;
991 val |= ENDP_CNTL_CNAK;
992 writel(val, &inep_regs_p[epid].endp_cntl);
993
994 val = readl(&outep_regs_p[epid].endp_cntl);
995 val &= ~ENDP_CNTL_SNAK;
996 val |= ENDP_CNTL_CNAK;
997 writel(val, &outep_regs_p[epid].endp_cntl);
998}
999