1
2
3
4
5
6
7
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/types.h>
11#include <linux/errno.h>
12#include <linux/err.h>
13#include <linux/platform_device.h>
14#include <linux/delay.h>
15#include <linux/list.h>
16#include <linux/interrupt.h>
17#include <linux/proc_fs.h>
18#include <linux/clk.h>
19#include <linux/irq.h>
20#include <linux/gpio.h>
21#include <linux/gpio/consumer.h>
22#include <linux/slab.h>
23#include <linux/prefetch.h>
24#include <linux/byteorder/generic.h>
25#include <linux/platform_data/pxa2xx_udc.h>
26#include <linux/of_device.h>
27#include <linux/of_gpio.h>
28
29#include <linux/usb.h>
30#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h>
32#include <linux/usb/phy.h>
33
34#include "pxa27x_udc.h"
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73#define DRIVER_VERSION "2008-04-18"
74#define DRIVER_DESC "PXA 27x USB Device Controller driver"
75
76static const char driver_name[] = "pxa27x_udc";
77static struct pxa_udc *the_controller;
78
79static void handle_ep(struct pxa_ep *ep);
80
81
82
83
84#ifdef CONFIG_USB_GADGET_DEBUG_FS
85
86#include <linux/debugfs.h>
87#include <linux/uaccess.h>
88#include <linux/seq_file.h>
89
90static int state_dbg_show(struct seq_file *s, void *p)
91{
92 struct pxa_udc *udc = s->private;
93 u32 tmp;
94
95 if (!udc->driver)
96 return -ENODEV;
97
98
99 seq_printf(s, DRIVER_DESC "\n"
100 "%s version: %s\n"
101 "Gadget driver: %s\n",
102 driver_name, DRIVER_VERSION,
103 udc->driver ? udc->driver->driver.name : "(none)");
104
105 tmp = udc_readl(udc, UDCCR);
106 seq_printf(s,
107 "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), con=%d,inter=%d,altinter=%d\n",
108 tmp,
109 (tmp & UDCCR_OEN) ? " oen":"",
110 (tmp & UDCCR_AALTHNP) ? " aalthnp":"",
111 (tmp & UDCCR_AHNP) ? " rem" : "",
112 (tmp & UDCCR_BHNP) ? " rstir" : "",
113 (tmp & UDCCR_DWRE) ? " dwre" : "",
114 (tmp & UDCCR_SMAC) ? " smac" : "",
115 (tmp & UDCCR_EMCE) ? " emce" : "",
116 (tmp & UDCCR_UDR) ? " udr" : "",
117 (tmp & UDCCR_UDA) ? " uda" : "",
118 (tmp & UDCCR_UDE) ? " ude" : "",
119 (tmp & UDCCR_ACN) >> UDCCR_ACN_S,
120 (tmp & UDCCR_AIN) >> UDCCR_AIN_S,
121 (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S);
122
123 seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n",
124 udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1));
125 seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n",
126 udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1));
127 seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR));
128 seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, reconfig=%lu\n",
129 udc->stats.irqs_reset, udc->stats.irqs_suspend,
130 udc->stats.irqs_resume, udc->stats.irqs_reconfig);
131
132 return 0;
133}
134
135static int queues_dbg_show(struct seq_file *s, void *p)
136{
137 struct pxa_udc *udc = s->private;
138 struct pxa_ep *ep;
139 struct pxa27x_request *req;
140 int i, maxpkt;
141
142 if (!udc->driver)
143 return -ENODEV;
144
145
146 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
147 ep = &udc->pxa_ep[i];
148 maxpkt = ep->fifo_size;
149 seq_printf(s, "%-12s max_pkt=%d %s\n",
150 EPNAME(ep), maxpkt, "pio");
151
152 if (list_empty(&ep->queue)) {
153 seq_puts(s, "\t(nothing queued)\n");
154 continue;
155 }
156
157 list_for_each_entry(req, &ep->queue, queue) {
158 seq_printf(s, "\treq %p len %d/%d buf %p\n",
159 &req->req, req->req.actual,
160 req->req.length, req->req.buf);
161 }
162 }
163
164 return 0;
165}
166
167static int eps_dbg_show(struct seq_file *s, void *p)
168{
169 struct pxa_udc *udc = s->private;
170 struct pxa_ep *ep;
171 int i;
172 u32 tmp;
173
174 if (!udc->driver)
175 return -ENODEV;
176
177 ep = &udc->pxa_ep[0];
178 tmp = udc_ep_readl(ep, UDCCSR);
179 seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n",
180 tmp,
181 (tmp & UDCCSR0_SA) ? " sa" : "",
182 (tmp & UDCCSR0_RNE) ? " rne" : "",
183 (tmp & UDCCSR0_FST) ? " fst" : "",
184 (tmp & UDCCSR0_SST) ? " sst" : "",
185 (tmp & UDCCSR0_DME) ? " dme" : "",
186 (tmp & UDCCSR0_IPR) ? " ipr" : "",
187 (tmp & UDCCSR0_OPC) ? " opc" : "");
188 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
189 ep = &udc->pxa_ep[i];
190 tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR);
191 seq_printf(s, "%-12s: IN %lu(%lu reqs), OUT %lu(%lu reqs), irqs=%lu, udccr=0x%08x, udccsr=0x%03x, udcbcr=%d\n",
192 EPNAME(ep),
193 ep->stats.in_bytes, ep->stats.in_ops,
194 ep->stats.out_bytes, ep->stats.out_ops,
195 ep->stats.irqs,
196 tmp, udc_ep_readl(ep, UDCCSR),
197 udc_ep_readl(ep, UDCBCR));
198 }
199
200 return 0;
201}
202
203static int eps_dbg_open(struct inode *inode, struct file *file)
204{
205 return single_open(file, eps_dbg_show, inode->i_private);
206}
207
208static int queues_dbg_open(struct inode *inode, struct file *file)
209{
210 return single_open(file, queues_dbg_show, inode->i_private);
211}
212
213static int state_dbg_open(struct inode *inode, struct file *file)
214{
215 return single_open(file, state_dbg_show, inode->i_private);
216}
217
218static const struct file_operations state_dbg_fops = {
219 .owner = THIS_MODULE,
220 .open = state_dbg_open,
221 .llseek = seq_lseek,
222 .read = seq_read,
223 .release = single_release,
224};
225
226static const struct file_operations queues_dbg_fops = {
227 .owner = THIS_MODULE,
228 .open = queues_dbg_open,
229 .llseek = seq_lseek,
230 .read = seq_read,
231 .release = single_release,
232};
233
234static const struct file_operations eps_dbg_fops = {
235 .owner = THIS_MODULE,
236 .open = eps_dbg_open,
237 .llseek = seq_lseek,
238 .read = seq_read,
239 .release = single_release,
240};
241
242static void pxa_init_debugfs(struct pxa_udc *udc)
243{
244 struct dentry *root, *state, *queues, *eps;
245
246 root = debugfs_create_dir(udc->gadget.name, NULL);
247 if (IS_ERR(root) || !root)
248 goto err_root;
249
250 state = debugfs_create_file("udcstate", 0400, root, udc,
251 &state_dbg_fops);
252 if (!state)
253 goto err_state;
254 queues = debugfs_create_file("queues", 0400, root, udc,
255 &queues_dbg_fops);
256 if (!queues)
257 goto err_queues;
258 eps = debugfs_create_file("epstate", 0400, root, udc,
259 &eps_dbg_fops);
260 if (!eps)
261 goto err_eps;
262
263 udc->debugfs_root = root;
264 udc->debugfs_state = state;
265 udc->debugfs_queues = queues;
266 udc->debugfs_eps = eps;
267 return;
268err_eps:
269 debugfs_remove(eps);
270err_queues:
271 debugfs_remove(queues);
272err_state:
273 debugfs_remove(root);
274err_root:
275 dev_err(udc->dev, "debugfs is not available\n");
276}
277
278static void pxa_cleanup_debugfs(struct pxa_udc *udc)
279{
280 debugfs_remove(udc->debugfs_eps);
281 debugfs_remove(udc->debugfs_queues);
282 debugfs_remove(udc->debugfs_state);
283 debugfs_remove(udc->debugfs_root);
284 udc->debugfs_eps = NULL;
285 udc->debugfs_queues = NULL;
286 udc->debugfs_state = NULL;
287 udc->debugfs_root = NULL;
288}
289
290#else
291static inline void pxa_init_debugfs(struct pxa_udc *udc)
292{
293}
294
295static inline void pxa_cleanup_debugfs(struct pxa_udc *udc)
296{
297}
298#endif
299
300
301
302
303
304
305
306
307
308
309
310static int is_match_usb_pxa(struct udc_usb_ep *udc_usb_ep, struct pxa_ep *ep,
311 int config, int interface, int altsetting)
312{
313 if (usb_endpoint_num(&udc_usb_ep->desc) != ep->addr)
314 return 0;
315 if (usb_endpoint_dir_in(&udc_usb_ep->desc) != ep->dir_in)
316 return 0;
317 if (usb_endpoint_type(&udc_usb_ep->desc) != ep->type)
318 return 0;
319 if ((ep->config != config) || (ep->interface != interface)
320 || (ep->alternate != altsetting))
321 return 0;
322 return 1;
323}
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350static struct pxa_ep *find_pxa_ep(struct pxa_udc *udc,
351 struct udc_usb_ep *udc_usb_ep)
352{
353 int i;
354 struct pxa_ep *ep;
355 int cfg = udc->config;
356 int iface = udc->last_interface;
357 int alt = udc->last_alternate;
358
359 if (udc_usb_ep == &udc->udc_usb_ep[0])
360 return &udc->pxa_ep[0];
361
362 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
363 ep = &udc->pxa_ep[i];
364 if (is_match_usb_pxa(udc_usb_ep, ep, cfg, iface, alt))
365 return ep;
366 }
367 return NULL;
368}
369
370
371
372
373
374
375
376
377
378
379
380static void update_pxa_ep_matches(struct pxa_udc *udc)
381{
382 int i;
383 struct udc_usb_ep *udc_usb_ep;
384
385 for (i = 1; i < NR_USB_ENDPOINTS; i++) {
386 udc_usb_ep = &udc->udc_usb_ep[i];
387 if (udc_usb_ep->pxa_ep)
388 udc_usb_ep->pxa_ep = find_pxa_ep(udc, udc_usb_ep);
389 }
390}
391
392
393
394
395
396static void pio_irq_enable(struct pxa_ep *ep)
397{
398 struct pxa_udc *udc = ep->dev;
399 int index = EPIDX(ep);
400 u32 udcicr0 = udc_readl(udc, UDCICR0);
401 u32 udcicr1 = udc_readl(udc, UDCICR1);
402
403 if (index < 16)
404 udc_writel(udc, UDCICR0, udcicr0 | (3 << (index * 2)));
405 else
406 udc_writel(udc, UDCICR1, udcicr1 | (3 << ((index - 16) * 2)));
407}
408
409
410
411
412
413static void pio_irq_disable(struct pxa_ep *ep)
414{
415 struct pxa_udc *udc = ep->dev;
416 int index = EPIDX(ep);
417 u32 udcicr0 = udc_readl(udc, UDCICR0);
418 u32 udcicr1 = udc_readl(udc, UDCICR1);
419
420 if (index < 16)
421 udc_writel(udc, UDCICR0, udcicr0 & ~(3 << (index * 2)));
422 else
423 udc_writel(udc, UDCICR1, udcicr1 & ~(3 << ((index - 16) * 2)));
424}
425
426
427
428
429
430
431
432
433static inline void udc_set_mask_UDCCR(struct pxa_udc *udc, int mask)
434{
435 u32 udccr = udc_readl(udc, UDCCR);
436 udc_writel(udc, UDCCR,
437 (udccr & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS));
438}
439
440
441
442
443
444
445
446
447static inline void udc_clear_mask_UDCCR(struct pxa_udc *udc, int mask)
448{
449 u32 udccr = udc_readl(udc, UDCCR);
450 udc_writel(udc, UDCCR,
451 (udccr & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS));
452}
453
454
455
456
457
458
459
460
461
462
463
464static inline void ep_write_UDCCSR(struct pxa_ep *ep, int mask)
465{
466 if (is_ep0(ep))
467 mask |= UDCCSR0_ACM;
468 udc_ep_writel(ep, UDCCSR, mask);
469}
470
471
472
473
474
475
476
477static int ep_count_bytes_remain(struct pxa_ep *ep)
478{
479 if (ep->dir_in)
480 return -EOPNOTSUPP;
481 return udc_ep_readl(ep, UDCBCR) & 0x3ff;
482}
483
484
485
486
487
488
489
490
491
492
493
494static int ep_is_empty(struct pxa_ep *ep)
495{
496 int ret;
497
498 if (!is_ep0(ep) && ep->dir_in)
499 return -EOPNOTSUPP;
500 if (is_ep0(ep))
501 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR0_RNE);
502 else
503 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNE);
504 return ret;
505}
506
507
508
509
510
511
512
513
514
515
516static int ep_is_full(struct pxa_ep *ep)
517{
518 if (is_ep0(ep))
519 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_IPR);
520 if (!ep->dir_in)
521 return -EOPNOTSUPP;
522 return (!(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNF));
523}
524
525
526
527
528
529
530
531static int epout_has_pkt(struct pxa_ep *ep)
532{
533 if (!is_ep0(ep) && ep->dir_in)
534 return -EOPNOTSUPP;
535 if (is_ep0(ep))
536 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_OPC);
537 return (udc_ep_readl(ep, UDCCSR) & UDCCSR_PC);
538}
539
540
541
542
543
544
545static void set_ep0state(struct pxa_udc *udc, int state)
546{
547 struct pxa_ep *ep = &udc->pxa_ep[0];
548 char *old_stname = EP0_STNAME(udc);
549
550 udc->ep0state = state;
551 ep_dbg(ep, "state=%s->%s, udccsr0=0x%03x, udcbcr=%d\n", old_stname,
552 EP0_STNAME(udc), udc_ep_readl(ep, UDCCSR),
553 udc_ep_readl(ep, UDCBCR));
554}
555
556
557
558
559
560static void ep0_idle(struct pxa_udc *dev)
561{
562 set_ep0state(dev, WAIT_FOR_SETUP);
563}
564
565
566
567
568
569
570
571
572static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in)
573{
574 if (is_in)
575 ep->stats.in_ops++;
576 else
577 ep->stats.out_ops++;
578}
579
580
581
582
583
584
585
586static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
587{
588 if (is_in)
589 ep->stats.in_bytes += count;
590 else
591 ep->stats.out_bytes += count;
592}
593
594
595
596
597
598
599
600static void pxa_ep_setup(struct pxa_ep *ep)
601{
602 u32 new_udccr;
603
604 new_udccr = ((ep->config << UDCCONR_CN_S) & UDCCONR_CN)
605 | ((ep->interface << UDCCONR_IN_S) & UDCCONR_IN)
606 | ((ep->alternate << UDCCONR_AISN_S) & UDCCONR_AISN)
607 | ((EPADDR(ep) << UDCCONR_EN_S) & UDCCONR_EN)
608 | ((EPXFERTYPE(ep) << UDCCONR_ET_S) & UDCCONR_ET)
609 | ((ep->dir_in) ? UDCCONR_ED : 0)
610 | ((ep->fifo_size << UDCCONR_MPS_S) & UDCCONR_MPS)
611 | UDCCONR_EE;
612
613 udc_ep_writel(ep, UDCCR, new_udccr);
614}
615
616
617
618
619
620
621
622static void pxa_eps_setup(struct pxa_udc *dev)
623{
624 unsigned int i;
625
626 dev_dbg(dev->dev, "%s: dev=%p\n", __func__, dev);
627
628 for (i = 1; i < NR_PXA_ENDPOINTS; i++)
629 pxa_ep_setup(&dev->pxa_ep[i]);
630}
631
632
633
634
635
636
637
638
639
640
641static struct usb_request *
642pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
643{
644 struct pxa27x_request *req;
645
646 req = kzalloc(sizeof *req, gfp_flags);
647 if (!req)
648 return NULL;
649
650 INIT_LIST_HEAD(&req->queue);
651 req->in_use = 0;
652 req->udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
653
654 return &req->req;
655}
656
657
658
659
660
661
662
663
664static void pxa_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
665{
666 struct pxa27x_request *req;
667
668 req = container_of(_req, struct pxa27x_request, req);
669 WARN_ON(!list_empty(&req->queue));
670 kfree(req);
671}
672
673
674
675
676
677
678
679
680
681
682
683static void ep_add_request(struct pxa_ep *ep, struct pxa27x_request *req)
684{
685 if (unlikely(!req))
686 return;
687 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
688 req->req.length, udc_ep_readl(ep, UDCCSR));
689
690 req->in_use = 1;
691 list_add_tail(&req->queue, &ep->queue);
692 pio_irq_enable(ep);
693}
694
695
696
697
698
699
700
701
702
703
704
705
706static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req)
707{
708 if (unlikely(!req))
709 return;
710 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
711 req->req.length, udc_ep_readl(ep, UDCCSR));
712
713 list_del_init(&req->queue);
714 req->in_use = 0;
715 if (!is_ep0(ep) && list_empty(&ep->queue))
716 pio_irq_disable(ep);
717}
718
719
720
721
722
723
724
725
726
727
728
729
730static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
731 unsigned long *pflags)
732{
733 unsigned long flags;
734
735 ep_del_request(ep, req);
736 if (likely(req->req.status == -EINPROGRESS))
737 req->req.status = status;
738 else
739 status = req->req.status;
740
741 if (status && status != -ESHUTDOWN)
742 ep_dbg(ep, "complete req %p stat %d len %u/%u\n",
743 &req->req, status,
744 req->req.actual, req->req.length);
745
746 if (pflags)
747 spin_unlock_irqrestore(&ep->lock, *pflags);
748 local_irq_save(flags);
749 usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req);
750 local_irq_restore(flags);
751 if (pflags)
752 spin_lock_irqsave(&ep->lock, *pflags);
753}
754
755
756
757
758
759
760
761
762
763
764
765static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
766 unsigned long *pflags)
767{
768 inc_ep_stats_reqs(ep, !USB_DIR_IN);
769 req_done(ep, req, 0, pflags);
770}
771
772
773
774
775
776
777
778
779
780
781
782
783static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
784 unsigned long *pflags)
785{
786 set_ep0state(ep->dev, OUT_STATUS_STAGE);
787 ep_end_out_req(ep, req, pflags);
788 ep0_idle(ep->dev);
789}
790
791
792
793
794
795
796
797
798
799
800
801static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
802 unsigned long *pflags)
803{
804 inc_ep_stats_reqs(ep, USB_DIR_IN);
805 req_done(ep, req, 0, pflags);
806}
807
808
809
810
811
812
813
814
815
816
817
818
819static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
820 unsigned long *pflags)
821{
822 set_ep0state(ep->dev, IN_STATUS_STAGE);
823 ep_end_in_req(ep, req, pflags);
824}
825
826
827
828
829
830
831
832
833
834
835
836static void nuke(struct pxa_ep *ep, int status)
837{
838 struct pxa27x_request *req;
839 unsigned long flags;
840
841 spin_lock_irqsave(&ep->lock, flags);
842 while (!list_empty(&ep->queue)) {
843 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
844 req_done(ep, req, status, &flags);
845 }
846 spin_unlock_irqrestore(&ep->lock, flags);
847}
848
849
850
851
852
853
854
855
856
857
858
859
860static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
861{
862 u32 *buf;
863 int bytes_ep, bufferspace, count, i;
864
865 bytes_ep = ep_count_bytes_remain(ep);
866 bufferspace = req->req.length - req->req.actual;
867
868 buf = (u32 *)(req->req.buf + req->req.actual);
869 prefetchw(buf);
870
871 if (likely(!ep_is_empty(ep)))
872 count = min(bytes_ep, bufferspace);
873 else
874 count = 0;
875
876 for (i = count; i > 0; i -= 4)
877 *buf++ = udc_ep_readl(ep, UDCDR);
878 req->req.actual += count;
879
880 ep_write_UDCCSR(ep, UDCCSR_PC);
881
882 return count;
883}
884
885
886
887
888
889
890
891
892
893
894
895
896
897static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req,
898 unsigned int max)
899{
900 int length, count, remain, i;
901 u32 *buf;
902 u8 *buf_8;
903
904 buf = (u32 *)(req->req.buf + req->req.actual);
905 prefetch(buf);
906
907 length = min(req->req.length - req->req.actual, max);
908 req->req.actual += length;
909
910 remain = length & 0x3;
911 count = length & ~(0x3);
912 for (i = count; i > 0 ; i -= 4)
913 udc_ep_writel(ep, UDCDR, *buf++);
914
915 buf_8 = (u8 *)buf;
916 for (i = remain; i > 0; i--)
917 udc_ep_writeb(ep, UDCDR, *buf_8++);
918
919 ep_vdbg(ep, "length=%d+%d, udccsr=0x%03x\n", count, remain,
920 udc_ep_readl(ep, UDCCSR));
921
922 return length;
923}
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939static int read_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
940{
941 int count, is_short, completed = 0;
942
943 while (epout_has_pkt(ep)) {
944 count = read_packet(ep, req);
945 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
946
947 is_short = (count < ep->fifo_size);
948 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
949 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
950 &req->req, req->req.actual, req->req.length);
951
952
953 if (is_short || req->req.actual == req->req.length) {
954 completed = 1;
955 break;
956 }
957
958 }
959 return completed;
960}
961
962
963
964
965
966
967
968
969
970
971
972
973
974static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
975{
976 unsigned max;
977 int count, is_short, is_last = 0, completed = 0, totcount = 0;
978 u32 udccsr;
979
980 max = ep->fifo_size;
981 do {
982 is_short = 0;
983
984 udccsr = udc_ep_readl(ep, UDCCSR);
985 if (udccsr & UDCCSR_PC) {
986 ep_vdbg(ep, "Clearing Transmit Complete, udccsr=%x\n",
987 udccsr);
988 ep_write_UDCCSR(ep, UDCCSR_PC);
989 }
990 if (udccsr & UDCCSR_TRN) {
991 ep_vdbg(ep, "Clearing Underrun on, udccsr=%x\n",
992 udccsr);
993 ep_write_UDCCSR(ep, UDCCSR_TRN);
994 }
995
996 count = write_packet(ep, req, max);
997 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
998 totcount += count;
999
1000
1001 if (unlikely(count < max)) {
1002 is_last = 1;
1003 is_short = 1;
1004 } else {
1005 if (likely(req->req.length > req->req.actual)
1006 || req->req.zero)
1007 is_last = 0;
1008 else
1009 is_last = 1;
1010
1011 is_short = unlikely(max < ep->fifo_size);
1012 }
1013
1014 if (is_short)
1015 ep_write_UDCCSR(ep, UDCCSR_SP);
1016
1017
1018 if (is_last) {
1019 completed = 1;
1020 break;
1021 }
1022 } while (!ep_is_full(ep));
1023
1024 ep_dbg(ep, "wrote count:%d bytes%s%s, left:%d req=%p\n",
1025 totcount, is_last ? "/L" : "", is_short ? "/S" : "",
1026 req->req.length - req->req.actual, &req->req);
1027
1028 return completed;
1029}
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1043{
1044 int count, is_short, completed = 0;
1045
1046 while (epout_has_pkt(ep)) {
1047 count = read_packet(ep, req);
1048 ep_write_UDCCSR(ep, UDCCSR0_OPC);
1049 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
1050
1051 is_short = (count < ep->fifo_size);
1052 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
1053 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
1054 &req->req, req->req.actual, req->req.length);
1055
1056 if (is_short || req->req.actual >= req->req.length) {
1057 completed = 1;
1058 break;
1059 }
1060 }
1061
1062 return completed;
1063}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080static int write_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1081{
1082 unsigned count;
1083 int is_last, is_short;
1084
1085 count = write_packet(ep, req, EP0_FIFO_SIZE);
1086 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
1087
1088 is_short = (count < EP0_FIFO_SIZE);
1089 is_last = ((count == 0) || (count < EP0_FIFO_SIZE));
1090
1091
1092 if (unlikely(is_short))
1093 ep_write_UDCCSR(ep, UDCCSR0_IPR);
1094
1095 ep_dbg(ep, "in %d bytes%s%s, %d left, req=%p, udccsr0=0x%03x\n",
1096 count, is_short ? "/S" : "", is_last ? "/L" : "",
1097 req->req.length - req->req.actual,
1098 &req->req, udc_ep_readl(ep, UDCCSR));
1099
1100 return is_last;
1101}
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1116 gfp_t gfp_flags)
1117{
1118 struct udc_usb_ep *udc_usb_ep;
1119 struct pxa_ep *ep;
1120 struct pxa27x_request *req;
1121 struct pxa_udc *dev;
1122 unsigned long flags;
1123 int rc = 0;
1124 int is_first_req;
1125 unsigned length;
1126 int recursion_detected;
1127
1128 req = container_of(_req, struct pxa27x_request, req);
1129 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1130
1131 if (unlikely(!_req || !_req->complete || !_req->buf))
1132 return -EINVAL;
1133
1134 if (unlikely(!_ep))
1135 return -EINVAL;
1136
1137 dev = udc_usb_ep->dev;
1138 ep = udc_usb_ep->pxa_ep;
1139 if (unlikely(!ep))
1140 return -EINVAL;
1141
1142 dev = ep->dev;
1143 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1144 ep_dbg(ep, "bogus device state\n");
1145 return -ESHUTDOWN;
1146 }
1147
1148
1149
1150
1151 if (unlikely(EPXFERTYPE_is_ISO(ep)
1152 && req->req.length > ep->fifo_size))
1153 return -EMSGSIZE;
1154
1155 spin_lock_irqsave(&ep->lock, flags);
1156 recursion_detected = ep->in_handle_ep;
1157
1158 is_first_req = list_empty(&ep->queue);
1159 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n",
1160 _req, is_first_req ? "yes" : "no",
1161 _req->length, _req->buf);
1162
1163 if (!ep->enabled) {
1164 _req->status = -ESHUTDOWN;
1165 rc = -ESHUTDOWN;
1166 goto out_locked;
1167 }
1168
1169 if (req->in_use) {
1170 ep_err(ep, "refusing to queue req %p (already queued)\n", req);
1171 goto out_locked;
1172 }
1173
1174 length = _req->length;
1175 _req->status = -EINPROGRESS;
1176 _req->actual = 0;
1177
1178 ep_add_request(ep, req);
1179 spin_unlock_irqrestore(&ep->lock, flags);
1180
1181 if (is_ep0(ep)) {
1182 switch (dev->ep0state) {
1183 case WAIT_ACK_SET_CONF_INTERF:
1184 if (length == 0) {
1185 ep_end_in_req(ep, req, NULL);
1186 } else {
1187 ep_err(ep, "got a request of %d bytes while"
1188 "in state WAIT_ACK_SET_CONF_INTERF\n",
1189 length);
1190 ep_del_request(ep, req);
1191 rc = -EL2HLT;
1192 }
1193 ep0_idle(ep->dev);
1194 break;
1195 case IN_DATA_STAGE:
1196 if (!ep_is_full(ep))
1197 if (write_ep0_fifo(ep, req))
1198 ep0_end_in_req(ep, req, NULL);
1199 break;
1200 case OUT_DATA_STAGE:
1201 if ((length == 0) || !epout_has_pkt(ep))
1202 if (read_ep0_fifo(ep, req))
1203 ep0_end_out_req(ep, req, NULL);
1204 break;
1205 default:
1206 ep_err(ep, "odd state %s to send me a request\n",
1207 EP0_STNAME(ep->dev));
1208 ep_del_request(ep, req);
1209 rc = -EL2HLT;
1210 break;
1211 }
1212 } else {
1213 if (!recursion_detected)
1214 handle_ep(ep);
1215 }
1216
1217out:
1218 return rc;
1219out_locked:
1220 spin_unlock_irqrestore(&ep->lock, flags);
1221 goto out;
1222}
1223
1224
1225
1226
1227
1228
1229
1230
1231static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1232{
1233 struct pxa_ep *ep;
1234 struct udc_usb_ep *udc_usb_ep;
1235 struct pxa27x_request *req;
1236 unsigned long flags;
1237 int rc = -EINVAL;
1238
1239 if (!_ep)
1240 return rc;
1241 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1242 ep = udc_usb_ep->pxa_ep;
1243 if (!ep || is_ep0(ep))
1244 return rc;
1245
1246 spin_lock_irqsave(&ep->lock, flags);
1247
1248
1249 list_for_each_entry(req, &ep->queue, queue) {
1250 if (&req->req == _req) {
1251 rc = 0;
1252 break;
1253 }
1254 }
1255
1256 spin_unlock_irqrestore(&ep->lock, flags);
1257 if (!rc)
1258 req_done(ep, req, -ECONNRESET, NULL);
1259 return rc;
1260}
1261
1262
1263
1264
1265
1266
1267
1268
1269static int pxa_ep_set_halt(struct usb_ep *_ep, int value)
1270{
1271 struct pxa_ep *ep;
1272 struct udc_usb_ep *udc_usb_ep;
1273 unsigned long flags;
1274 int rc;
1275
1276
1277 if (!_ep)
1278 return -EINVAL;
1279 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1280 ep = udc_usb_ep->pxa_ep;
1281 if (!ep || is_ep0(ep))
1282 return -EINVAL;
1283
1284 if (value == 0) {
1285
1286
1287
1288
1289
1290
1291 ep_dbg(ep, "only host can clear halt\n");
1292 return -EROFS;
1293 }
1294
1295 spin_lock_irqsave(&ep->lock, flags);
1296
1297 rc = -EAGAIN;
1298 if (ep->dir_in && (ep_is_full(ep) || !list_empty(&ep->queue)))
1299 goto out;
1300
1301
1302 rc = 0;
1303 ep_write_UDCCSR(ep, UDCCSR_FST | UDCCSR_FEF);
1304 if (is_ep0(ep))
1305 set_ep0state(ep->dev, STALL);
1306
1307out:
1308 spin_unlock_irqrestore(&ep->lock, flags);
1309 return rc;
1310}
1311
1312
1313
1314
1315
1316
1317
1318static int pxa_ep_fifo_status(struct usb_ep *_ep)
1319{
1320 struct pxa_ep *ep;
1321 struct udc_usb_ep *udc_usb_ep;
1322
1323 if (!_ep)
1324 return -ENODEV;
1325 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1326 ep = udc_usb_ep->pxa_ep;
1327 if (!ep || is_ep0(ep))
1328 return -ENODEV;
1329
1330 if (ep->dir_in)
1331 return -EOPNOTSUPP;
1332 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN || ep_is_empty(ep))
1333 return 0;
1334 else
1335 return ep_count_bytes_remain(ep) + 1;
1336}
1337
1338
1339
1340
1341
1342
1343
1344static void pxa_ep_fifo_flush(struct usb_ep *_ep)
1345{
1346 struct pxa_ep *ep;
1347 struct udc_usb_ep *udc_usb_ep;
1348 unsigned long flags;
1349
1350 if (!_ep)
1351 return;
1352 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1353 ep = udc_usb_ep->pxa_ep;
1354 if (!ep || is_ep0(ep))
1355 return;
1356
1357 spin_lock_irqsave(&ep->lock, flags);
1358
1359 if (unlikely(!list_empty(&ep->queue)))
1360 ep_dbg(ep, "called while queue list not empty\n");
1361 ep_dbg(ep, "called\n");
1362
1363
1364 if (!ep->dir_in) {
1365 while (!ep_is_empty(ep))
1366 udc_ep_readl(ep, UDCDR);
1367 } else {
1368
1369 ep_write_UDCCSR(ep,
1370 UDCCSR_PC | UDCCSR_FEF | UDCCSR_TRN
1371 | (EPXFERTYPE_is_ISO(ep) ? 0 : UDCCSR_SST));
1372 }
1373
1374 spin_unlock_irqrestore(&ep->lock, flags);
1375}
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387static int pxa_ep_enable(struct usb_ep *_ep,
1388 const struct usb_endpoint_descriptor *desc)
1389{
1390 struct pxa_ep *ep;
1391 struct udc_usb_ep *udc_usb_ep;
1392 struct pxa_udc *udc;
1393
1394 if (!_ep || !desc)
1395 return -EINVAL;
1396
1397 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1398 if (udc_usb_ep->pxa_ep) {
1399 ep = udc_usb_ep->pxa_ep;
1400 ep_warn(ep, "usb_ep %s already enabled, doing nothing\n",
1401 _ep->name);
1402 } else {
1403 ep = find_pxa_ep(udc_usb_ep->dev, udc_usb_ep);
1404 }
1405
1406 if (!ep || is_ep0(ep)) {
1407 dev_err(udc_usb_ep->dev->dev,
1408 "unable to match pxa_ep for ep %s\n",
1409 _ep->name);
1410 return -EINVAL;
1411 }
1412
1413 if ((desc->bDescriptorType != USB_DT_ENDPOINT)
1414 || (ep->type != usb_endpoint_type(desc))) {
1415 ep_err(ep, "type mismatch\n");
1416 return -EINVAL;
1417 }
1418
1419 if (ep->fifo_size < usb_endpoint_maxp(desc)) {
1420 ep_err(ep, "bad maxpacket\n");
1421 return -ERANGE;
1422 }
1423
1424 udc_usb_ep->pxa_ep = ep;
1425 udc = ep->dev;
1426
1427 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
1428 ep_err(ep, "bogus device state\n");
1429 return -ESHUTDOWN;
1430 }
1431
1432 ep->enabled = 1;
1433
1434
1435 pxa_ep_fifo_flush(_ep);
1436
1437 ep_dbg(ep, "enabled\n");
1438 return 0;
1439}
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449static int pxa_ep_disable(struct usb_ep *_ep)
1450{
1451 struct pxa_ep *ep;
1452 struct udc_usb_ep *udc_usb_ep;
1453
1454 if (!_ep)
1455 return -EINVAL;
1456
1457 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1458 ep = udc_usb_ep->pxa_ep;
1459 if (!ep || is_ep0(ep) || !list_empty(&ep->queue))
1460 return -EINVAL;
1461
1462 ep->enabled = 0;
1463 nuke(ep, -ESHUTDOWN);
1464
1465 pxa_ep_fifo_flush(_ep);
1466 udc_usb_ep->pxa_ep = NULL;
1467
1468 ep_dbg(ep, "disabled\n");
1469 return 0;
1470}
1471
1472static const struct usb_ep_ops pxa_ep_ops = {
1473 .enable = pxa_ep_enable,
1474 .disable = pxa_ep_disable,
1475
1476 .alloc_request = pxa_ep_alloc_request,
1477 .free_request = pxa_ep_free_request,
1478
1479 .queue = pxa_ep_queue,
1480 .dequeue = pxa_ep_dequeue,
1481
1482 .set_halt = pxa_ep_set_halt,
1483 .fifo_status = pxa_ep_fifo_status,
1484 .fifo_flush = pxa_ep_fifo_flush,
1485};
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496static void dplus_pullup(struct pxa_udc *udc, int on)
1497{
1498 if (udc->gpiod) {
1499 gpiod_set_value(udc->gpiod, on);
1500 } else if (udc->udc_command) {
1501 if (on)
1502 udc->udc_command(PXA2XX_UDC_CMD_CONNECT);
1503 else
1504 udc->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1505 }
1506 udc->pullup_on = on;
1507}
1508
1509
1510
1511
1512
1513static int pxa_udc_get_frame(struct usb_gadget *_gadget)
1514{
1515 struct pxa_udc *udc = to_gadget_udc(_gadget);
1516
1517 return (udc_readl(udc, UDCFNR) & 0x7ff);
1518}
1519
1520
1521
1522
1523
1524
1525
1526static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1527{
1528 struct pxa_udc *udc = to_gadget_udc(_gadget);
1529
1530
1531 if ((udc_readl(udc, UDCCR) & UDCCR_DWRE) == 0)
1532 return -EHOSTUNREACH;
1533 udc_set_mask_UDCCR(udc, UDCCR_UDR);
1534 return 0;
1535}
1536
1537static void udc_enable(struct pxa_udc *udc);
1538static void udc_disable(struct pxa_udc *udc);
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553static int should_enable_udc(struct pxa_udc *udc)
1554{
1555 int put_on;
1556
1557 put_on = ((udc->pullup_on) && (udc->driver));
1558 put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL(udc->transceiver)));
1559 return put_on;
1560}
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574static int should_disable_udc(struct pxa_udc *udc)
1575{
1576 int put_off;
1577
1578 put_off = ((!udc->pullup_on) || (!udc->driver));
1579 put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL(udc->transceiver)));
1580 return put_off;
1581}
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active)
1592{
1593 struct pxa_udc *udc = to_gadget_udc(_gadget);
1594
1595 if (!udc->gpiod && !udc->udc_command)
1596 return -EOPNOTSUPP;
1597
1598 dplus_pullup(udc, is_active);
1599
1600 if (should_enable_udc(udc))
1601 udc_enable(udc);
1602 if (should_disable_udc(udc))
1603 udc_disable(udc);
1604 return 0;
1605}
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1618{
1619 struct pxa_udc *udc = to_gadget_udc(_gadget);
1620
1621 udc->vbus_sensed = is_active;
1622 if (should_enable_udc(udc))
1623 udc_enable(udc);
1624 if (should_disable_udc(udc))
1625 udc_disable(udc);
1626
1627 return 0;
1628}
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1643{
1644 struct pxa_udc *udc;
1645
1646 udc = to_gadget_udc(_gadget);
1647 if (!IS_ERR_OR_NULL(udc->transceiver))
1648 return usb_phy_set_power(udc->transceiver, mA);
1649 return -EOPNOTSUPP;
1650}
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662static int pxa_udc_phy_event(struct notifier_block *nb, unsigned long action,
1663 void *data)
1664{
1665 struct usb_gadget *gadget = data;
1666
1667 switch (action) {
1668 case USB_EVENT_VBUS:
1669 usb_gadget_vbus_connect(gadget);
1670 return NOTIFY_OK;
1671 case USB_EVENT_NONE:
1672 usb_gadget_vbus_disconnect(gadget);
1673 return NOTIFY_OK;
1674 default:
1675 return NOTIFY_DONE;
1676 }
1677}
1678
1679static struct notifier_block pxa27x_udc_phy = {
1680 .notifier_call = pxa_udc_phy_event,
1681};
1682
1683static int pxa27x_udc_start(struct usb_gadget *g,
1684 struct usb_gadget_driver *driver);
1685static int pxa27x_udc_stop(struct usb_gadget *g);
1686
1687static const struct usb_gadget_ops pxa_udc_ops = {
1688 .get_frame = pxa_udc_get_frame,
1689 .wakeup = pxa_udc_wakeup,
1690 .pullup = pxa_udc_pullup,
1691 .vbus_session = pxa_udc_vbus_session,
1692 .vbus_draw = pxa_udc_vbus_draw,
1693 .udc_start = pxa27x_udc_start,
1694 .udc_stop = pxa27x_udc_stop,
1695};
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705static void udc_disable(struct pxa_udc *udc)
1706{
1707 if (!udc->enabled)
1708 return;
1709
1710 udc_writel(udc, UDCICR0, 0);
1711 udc_writel(udc, UDCICR1, 0);
1712
1713 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1714
1715 ep0_idle(udc);
1716 udc->gadget.speed = USB_SPEED_UNKNOWN;
1717 clk_disable(udc->clk);
1718
1719 udc->enabled = 0;
1720}
1721
1722
1723
1724
1725
1726
1727
1728
1729static void udc_init_data(struct pxa_udc *dev)
1730{
1731 int i;
1732 struct pxa_ep *ep;
1733
1734
1735 INIT_LIST_HEAD(&dev->gadget.ep_list);
1736 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1737 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0];
1738 dev->gadget.quirk_altset_not_supp = 1;
1739 ep0_idle(dev);
1740
1741
1742 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
1743 ep = &dev->pxa_ep[i];
1744
1745 ep->enabled = is_ep0(ep);
1746 INIT_LIST_HEAD(&ep->queue);
1747 spin_lock_init(&ep->lock);
1748 }
1749
1750
1751 for (i = 1; i < NR_USB_ENDPOINTS; i++) {
1752 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list,
1753 &dev->gadget.ep_list);
1754 usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep,
1755 dev->udc_usb_ep[i].usb_ep.maxpacket);
1756 }
1757}
1758
1759
1760
1761
1762
1763
1764
1765
1766static void udc_enable(struct pxa_udc *udc)
1767{
1768 if (udc->enabled)
1769 return;
1770
1771 clk_enable(udc->clk);
1772 udc_writel(udc, UDCICR0, 0);
1773 udc_writel(udc, UDCICR1, 0);
1774 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1775
1776 ep0_idle(udc);
1777 udc->gadget.speed = USB_SPEED_FULL;
1778 memset(&udc->stats, 0, sizeof(udc->stats));
1779
1780 pxa_eps_setup(udc);
1781 udc_set_mask_UDCCR(udc, UDCCR_UDE);
1782 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM);
1783 udelay(2);
1784 if (udc_readl(udc, UDCCR) & UDCCR_EMCE)
1785 dev_err(udc->dev, "Configuration errors, udc disabled\n");
1786
1787
1788
1789
1790 msleep(100);
1791
1792
1793 udc_writel(udc, UDCICR1,
1794 UDCICR1_IECC | UDCICR1_IERU
1795 | UDCICR1_IESU | UDCICR1_IERS);
1796
1797
1798 pio_irq_enable(&udc->pxa_ep[0]);
1799
1800 udc->enabled = 1;
1801}
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818static int pxa27x_udc_start(struct usb_gadget *g,
1819 struct usb_gadget_driver *driver)
1820{
1821 struct pxa_udc *udc = to_pxa(g);
1822 int retval;
1823
1824
1825 udc->driver = driver;
1826
1827 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1828 retval = otg_set_peripheral(udc->transceiver->otg,
1829 &udc->gadget);
1830 if (retval) {
1831 dev_err(udc->dev, "can't bind to transceiver\n");
1832 goto fail;
1833 }
1834 }
1835
1836 if (should_enable_udc(udc))
1837 udc_enable(udc);
1838 return 0;
1839
1840fail:
1841 udc->driver = NULL;
1842 return retval;
1843}
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853static void stop_activity(struct pxa_udc *udc)
1854{
1855 int i;
1856
1857 udc->gadget.speed = USB_SPEED_UNKNOWN;
1858
1859 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1860 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep);
1861}
1862
1863
1864
1865
1866
1867
1868
1869static int pxa27x_udc_stop(struct usb_gadget *g)
1870{
1871 struct pxa_udc *udc = to_pxa(g);
1872
1873 stop_activity(udc);
1874 udc_disable(udc);
1875
1876 udc->driver = NULL;
1877
1878 if (!IS_ERR_OR_NULL(udc->transceiver))
1879 return otg_set_peripheral(udc->transceiver->otg, NULL);
1880 return 0;
1881}
1882
1883
1884
1885
1886
1887
1888static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1889 struct pxa27x_request *req)
1890{
1891 struct pxa_ep *ep = &udc->pxa_ep[0];
1892 union {
1893 struct usb_ctrlrequest r;
1894 u32 word[2];
1895 } u;
1896 int i;
1897 int have_extrabytes = 0;
1898 unsigned long flags;
1899
1900 nuke(ep, -EPROTO);
1901 spin_lock_irqsave(&ep->lock, flags);
1902
1903
1904
1905
1906
1907
1908
1909 if (epout_has_pkt(ep) && (ep_count_bytes_remain(ep) == 0))
1910 ep_write_UDCCSR(ep, UDCCSR0_OPC);
1911
1912
1913 for (i = 0; i < 2; i++) {
1914 if (unlikely(ep_is_empty(ep)))
1915 goto stall;
1916 u.word[i] = udc_ep_readl(ep, UDCDR);
1917 }
1918
1919 have_extrabytes = !ep_is_empty(ep);
1920 while (!ep_is_empty(ep)) {
1921 i = udc_ep_readl(ep, UDCDR);
1922 ep_err(ep, "wrong to have extra bytes for setup : 0x%08x\n", i);
1923 }
1924
1925 ep_dbg(ep, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1926 u.r.bRequestType, u.r.bRequest,
1927 le16_to_cpu(u.r.wValue), le16_to_cpu(u.r.wIndex),
1928 le16_to_cpu(u.r.wLength));
1929 if (unlikely(have_extrabytes))
1930 goto stall;
1931
1932 if (u.r.bRequestType & USB_DIR_IN)
1933 set_ep0state(udc, IN_DATA_STAGE);
1934 else
1935 set_ep0state(udc, OUT_DATA_STAGE);
1936
1937
1938 ep_write_UDCCSR(ep, UDCCSR0_SA | UDCCSR0_OPC);
1939
1940 spin_unlock_irqrestore(&ep->lock, flags);
1941 i = udc->driver->setup(&udc->gadget, &u.r);
1942 spin_lock_irqsave(&ep->lock, flags);
1943 if (i < 0)
1944 goto stall;
1945out:
1946 spin_unlock_irqrestore(&ep->lock, flags);
1947 return;
1948stall:
1949 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n",
1950 udc_ep_readl(ep, UDCCSR), i);
1951 ep_write_UDCCSR(ep, UDCCSR0_FST | UDCCSR0_FTF);
1952 set_ep0state(udc, STALL);
1953 goto out;
1954}
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2005{
2006 u32 udccsr0;
2007 struct pxa_ep *ep = &udc->pxa_ep[0];
2008 struct pxa27x_request *req = NULL;
2009 int completed = 0;
2010
2011 if (!list_empty(&ep->queue))
2012 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
2013
2014 udccsr0 = udc_ep_readl(ep, UDCCSR);
2015 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n",
2016 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR),
2017 (fifo_irq << 1 | opc_irq));
2018
2019 if (udccsr0 & UDCCSR0_SST) {
2020 ep_dbg(ep, "clearing stall status\n");
2021 nuke(ep, -EPIPE);
2022 ep_write_UDCCSR(ep, UDCCSR0_SST);
2023 ep0_idle(udc);
2024 }
2025
2026 if (udccsr0 & UDCCSR0_SA) {
2027 nuke(ep, 0);
2028 set_ep0state(udc, SETUP_STAGE);
2029 }
2030
2031 switch (udc->ep0state) {
2032 case WAIT_FOR_SETUP:
2033
2034
2035
2036
2037
2038
2039 break;
2040 case SETUP_STAGE:
2041 udccsr0 &= UDCCSR0_CTRL_REQ_MASK;
2042 if (likely(udccsr0 == UDCCSR0_CTRL_REQ_MASK))
2043 handle_ep0_ctrl_req(udc, req);
2044 break;
2045 case IN_DATA_STAGE:
2046 if (epout_has_pkt(ep))
2047 ep_write_UDCCSR(ep, UDCCSR0_OPC);
2048 if (req && !ep_is_full(ep))
2049 completed = write_ep0_fifo(ep, req);
2050 if (completed)
2051 ep0_end_in_req(ep, req, NULL);
2052 break;
2053 case OUT_DATA_STAGE:
2054 if (epout_has_pkt(ep) && req)
2055 completed = read_ep0_fifo(ep, req);
2056 if (completed)
2057 ep0_end_out_req(ep, req, NULL);
2058 break;
2059 case STALL:
2060 ep_write_UDCCSR(ep, UDCCSR0_FST);
2061 break;
2062 case IN_STATUS_STAGE:
2063
2064
2065
2066
2067
2068 if (opc_irq)
2069 ep0_idle(udc);
2070 break;
2071 case OUT_STATUS_STAGE:
2072 case WAIT_ACK_SET_CONF_INTERF:
2073 ep_warn(ep, "should never get in %s state here!!!\n",
2074 EP0_STNAME(ep->dev));
2075 ep0_idle(udc);
2076 break;
2077 }
2078}
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089static void handle_ep(struct pxa_ep *ep)
2090{
2091 struct pxa27x_request *req;
2092 int completed;
2093 u32 udccsr;
2094 int is_in = ep->dir_in;
2095 int loop = 0;
2096 unsigned long flags;
2097
2098 spin_lock_irqsave(&ep->lock, flags);
2099 if (ep->in_handle_ep)
2100 goto recursion_detected;
2101 ep->in_handle_ep = 1;
2102
2103 do {
2104 completed = 0;
2105 udccsr = udc_ep_readl(ep, UDCCSR);
2106
2107 if (likely(!list_empty(&ep->queue)))
2108 req = list_entry(ep->queue.next,
2109 struct pxa27x_request, queue);
2110 else
2111 req = NULL;
2112
2113 ep_dbg(ep, "req:%p, udccsr 0x%03x loop=%d\n",
2114 req, udccsr, loop++);
2115
2116 if (unlikely(udccsr & (UDCCSR_SST | UDCCSR_TRN)))
2117 udc_ep_writel(ep, UDCCSR,
2118 udccsr & (UDCCSR_SST | UDCCSR_TRN));
2119 if (!req)
2120 break;
2121
2122 if (unlikely(is_in)) {
2123 if (likely(!ep_is_full(ep)))
2124 completed = write_fifo(ep, req);
2125 } else {
2126 if (likely(epout_has_pkt(ep)))
2127 completed = read_fifo(ep, req);
2128 }
2129
2130 if (completed) {
2131 if (is_in)
2132 ep_end_in_req(ep, req, &flags);
2133 else
2134 ep_end_out_req(ep, req, &flags);
2135 }
2136 } while (completed);
2137
2138 ep->in_handle_ep = 0;
2139recursion_detected:
2140 spin_unlock_irqrestore(&ep->lock, flags);
2141}
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151static void pxa27x_change_configuration(struct pxa_udc *udc, int config)
2152{
2153 struct usb_ctrlrequest req ;
2154
2155 dev_dbg(udc->dev, "config=%d\n", config);
2156
2157 udc->config = config;
2158 udc->last_interface = 0;
2159 udc->last_alternate = 0;
2160
2161 req.bRequestType = 0;
2162 req.bRequest = USB_REQ_SET_CONFIGURATION;
2163 req.wValue = config;
2164 req.wIndex = 0;
2165 req.wLength = 0;
2166
2167 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2168 udc->driver->setup(&udc->gadget, &req);
2169 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN);
2170}
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181static void pxa27x_change_interface(struct pxa_udc *udc, int iface, int alt)
2182{
2183 struct usb_ctrlrequest req;
2184
2185 dev_dbg(udc->dev, "interface=%d, alternate setting=%d\n", iface, alt);
2186
2187 udc->last_interface = iface;
2188 udc->last_alternate = alt;
2189
2190 req.bRequestType = USB_RECIP_INTERFACE;
2191 req.bRequest = USB_REQ_SET_INTERFACE;
2192 req.wValue = alt;
2193 req.wIndex = iface;
2194 req.wLength = 0;
2195
2196 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2197 udc->driver->setup(&udc->gadget, &req);
2198 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN);
2199}
2200
2201
2202
2203
2204
2205
2206
2207
2208static void irq_handle_data(int irq, struct pxa_udc *udc)
2209{
2210 int i;
2211 struct pxa_ep *ep;
2212 u32 udcisr0 = udc_readl(udc, UDCISR0) & UDCCISR0_EP_MASK;
2213 u32 udcisr1 = udc_readl(udc, UDCISR1) & UDCCISR1_EP_MASK;
2214
2215 if (udcisr0 & UDCISR_INT_MASK) {
2216 udc->pxa_ep[0].stats.irqs++;
2217 udc_writel(udc, UDCISR0, UDCISR_INT(0, UDCISR_INT_MASK));
2218 handle_ep0(udc, !!(udcisr0 & UDCICR_FIFOERR),
2219 !!(udcisr0 & UDCICR_PKTCOMPL));
2220 }
2221
2222 udcisr0 >>= 2;
2223 for (i = 1; udcisr0 != 0 && i < 16; udcisr0 >>= 2, i++) {
2224 if (!(udcisr0 & UDCISR_INT_MASK))
2225 continue;
2226
2227 udc_writel(udc, UDCISR0, UDCISR_INT(i, UDCISR_INT_MASK));
2228
2229 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep));
2230 if (i < ARRAY_SIZE(udc->pxa_ep)) {
2231 ep = &udc->pxa_ep[i];
2232 ep->stats.irqs++;
2233 handle_ep(ep);
2234 }
2235 }
2236
2237 for (i = 16; udcisr1 != 0 && i < 24; udcisr1 >>= 2, i++) {
2238 udc_writel(udc, UDCISR1, UDCISR_INT(i - 16, UDCISR_INT_MASK));
2239 if (!(udcisr1 & UDCISR_INT_MASK))
2240 continue;
2241
2242 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep));
2243 if (i < ARRAY_SIZE(udc->pxa_ep)) {
2244 ep = &udc->pxa_ep[i];
2245 ep->stats.irqs++;
2246 handle_ep(ep);
2247 }
2248 }
2249
2250}
2251
2252
2253
2254
2255
2256static void irq_udc_suspend(struct pxa_udc *udc)
2257{
2258 udc_writel(udc, UDCISR1, UDCISR1_IRSU);
2259 udc->stats.irqs_suspend++;
2260
2261 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2262 && udc->driver && udc->driver->suspend)
2263 udc->driver->suspend(&udc->gadget);
2264 ep0_idle(udc);
2265}
2266
2267
2268
2269
2270
2271static void irq_udc_resume(struct pxa_udc *udc)
2272{
2273 udc_writel(udc, UDCISR1, UDCISR1_IRRU);
2274 udc->stats.irqs_resume++;
2275
2276 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2277 && udc->driver && udc->driver->resume)
2278 udc->driver->resume(&udc->gadget);
2279}
2280
2281
2282
2283
2284
2285static void irq_udc_reconfig(struct pxa_udc *udc)
2286{
2287 unsigned config, interface, alternate, config_change;
2288 u32 udccr = udc_readl(udc, UDCCR);
2289
2290 udc_writel(udc, UDCISR1, UDCISR1_IRCC);
2291 udc->stats.irqs_reconfig++;
2292
2293 config = (udccr & UDCCR_ACN) >> UDCCR_ACN_S;
2294 config_change = (config != udc->config);
2295 pxa27x_change_configuration(udc, config);
2296
2297 interface = (udccr & UDCCR_AIN) >> UDCCR_AIN_S;
2298 alternate = (udccr & UDCCR_AAISN) >> UDCCR_AAISN_S;
2299 pxa27x_change_interface(udc, interface, alternate);
2300
2301 if (config_change)
2302 update_pxa_ep_matches(udc);
2303 udc_set_mask_UDCCR(udc, UDCCR_SMAC);
2304}
2305
2306
2307
2308
2309
2310static void irq_udc_reset(struct pxa_udc *udc)
2311{
2312 u32 udccr = udc_readl(udc, UDCCR);
2313 struct pxa_ep *ep = &udc->pxa_ep[0];
2314
2315 dev_info(udc->dev, "USB reset\n");
2316 udc_writel(udc, UDCISR1, UDCISR1_IRRS);
2317 udc->stats.irqs_reset++;
2318
2319 if ((udccr & UDCCR_UDA) == 0) {
2320 dev_dbg(udc->dev, "USB reset start\n");
2321 stop_activity(udc);
2322 }
2323 udc->gadget.speed = USB_SPEED_FULL;
2324 memset(&udc->stats, 0, sizeof udc->stats);
2325
2326 nuke(ep, -EPROTO);
2327 ep_write_UDCCSR(ep, UDCCSR0_FTF | UDCCSR0_OPC);
2328 ep0_idle(udc);
2329}
2330
2331
2332
2333
2334
2335
2336
2337
2338static irqreturn_t pxa_udc_irq(int irq, void *_dev)
2339{
2340 struct pxa_udc *udc = _dev;
2341 u32 udcisr0 = udc_readl(udc, UDCISR0);
2342 u32 udcisr1 = udc_readl(udc, UDCISR1);
2343 u32 udccr = udc_readl(udc, UDCCR);
2344 u32 udcisr1_spec;
2345
2346 dev_vdbg(udc->dev, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, "
2347 "UDCCR:0x%08x\n", udcisr0, udcisr1, udccr);
2348
2349 udcisr1_spec = udcisr1 & 0xf8000000;
2350 if (unlikely(udcisr1_spec & UDCISR1_IRSU))
2351 irq_udc_suspend(udc);
2352 if (unlikely(udcisr1_spec & UDCISR1_IRRU))
2353 irq_udc_resume(udc);
2354 if (unlikely(udcisr1_spec & UDCISR1_IRCC))
2355 irq_udc_reconfig(udc);
2356 if (unlikely(udcisr1_spec & UDCISR1_IRRS))
2357 irq_udc_reset(udc);
2358
2359 if ((udcisr0 & UDCCISR0_EP_MASK) | (udcisr1 & UDCCISR1_EP_MASK))
2360 irq_handle_data(irq, udc);
2361
2362 return IRQ_HANDLED;
2363}
2364
2365static struct pxa_udc memory = {
2366 .gadget = {
2367 .ops = &pxa_udc_ops,
2368 .ep0 = &memory.udc_usb_ep[0].usb_ep,
2369 .name = driver_name,
2370 .dev = {
2371 .init_name = "gadget",
2372 },
2373 },
2374
2375 .udc_usb_ep = {
2376 USB_EP_CTRL,
2377 USB_EP_OUT_BULK(1),
2378 USB_EP_IN_BULK(2),
2379 USB_EP_IN_ISO(3),
2380 USB_EP_OUT_ISO(4),
2381 USB_EP_IN_INT(5),
2382 },
2383
2384 .pxa_ep = {
2385 PXA_EP_CTRL,
2386
2387 PXA_EP_OUT_BULK(1, 1, 3, 0, 0),
2388 PXA_EP_IN_BULK(2, 2, 3, 0, 0),
2389
2390 PXA_EP_OUT_BULK(3, 1, 1, 0, 0),
2391 PXA_EP_IN_BULK(4, 2, 1, 0, 0),
2392 PXA_EP_IN_ISO(5, 3, 1, 0, 0),
2393 PXA_EP_OUT_ISO(6, 4, 1, 0, 0),
2394 PXA_EP_IN_INT(7, 5, 1, 0, 0),
2395
2396 PXA_EP_OUT_BULK(8, 1, 2, 0, 0),
2397 PXA_EP_IN_BULK(9, 2, 2, 0, 0),
2398 PXA_EP_IN_INT(10, 5, 2, 0, 0),
2399
2400
2401
2402
2403
2404 PXA_EP_OUT_BULK(11, 1, 2, 1, 0),
2405 PXA_EP_IN_BULK(12, 2, 2, 1, 0),
2406
2407 PXA_EP_OUT_BULK(13, 1, 1, 1, 1),
2408 PXA_EP_IN_BULK(14, 2, 1, 1, 1),
2409 }
2410};
2411
2412#if defined(CONFIG_OF)
2413static const struct of_device_id udc_pxa_dt_ids[] = {
2414 { .compatible = "marvell,pxa270-udc" },
2415 {}
2416};
2417MODULE_DEVICE_TABLE(of, udc_pxa_dt_ids);
2418#endif
2419
2420
2421
2422
2423
2424
2425
2426
2427static int pxa_udc_probe(struct platform_device *pdev)
2428{
2429 struct resource *regs;
2430 struct pxa_udc *udc = &memory;
2431 int retval = 0, gpio;
2432 struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev);
2433 unsigned long gpio_flags;
2434
2435 if (mach) {
2436 gpio_flags = mach->gpio_pullup_inverted ? GPIOF_ACTIVE_LOW : 0;
2437 gpio = mach->gpio_pullup;
2438 if (gpio_is_valid(gpio)) {
2439 retval = devm_gpio_request_one(&pdev->dev, gpio,
2440 gpio_flags,
2441 "USB D+ pullup");
2442 if (retval)
2443 return retval;
2444 udc->gpiod = gpio_to_desc(mach->gpio_pullup);
2445 }
2446 udc->udc_command = mach->udc_command;
2447 } else {
2448 udc->gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_ASIS);
2449 }
2450
2451 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2452 udc->regs = devm_ioremap_resource(&pdev->dev, regs);
2453 if (IS_ERR(udc->regs))
2454 return PTR_ERR(udc->regs);
2455 udc->irq = platform_get_irq(pdev, 0);
2456 if (udc->irq < 0)
2457 return udc->irq;
2458
2459 udc->dev = &pdev->dev;
2460 if (of_have_populated_dt()) {
2461 udc->transceiver =
2462 devm_usb_get_phy_by_phandle(udc->dev, "phys", 0);
2463 if (IS_ERR(udc->transceiver))
2464 return PTR_ERR(udc->transceiver);
2465 } else {
2466 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2467 }
2468
2469 if (IS_ERR(udc->gpiod)) {
2470 dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n",
2471 PTR_ERR(udc->gpiod));
2472 return PTR_ERR(udc->gpiod);
2473 }
2474 if (udc->gpiod)
2475 gpiod_direction_output(udc->gpiod, 0);
2476
2477 udc->clk = devm_clk_get(&pdev->dev, NULL);
2478 if (IS_ERR(udc->clk))
2479 return PTR_ERR(udc->clk);
2480
2481 retval = clk_prepare(udc->clk);
2482 if (retval)
2483 return retval;
2484
2485 udc->vbus_sensed = 0;
2486
2487 the_controller = udc;
2488 platform_set_drvdata(pdev, udc);
2489 udc_init_data(udc);
2490
2491
2492 retval = devm_request_irq(&pdev->dev, udc->irq, pxa_udc_irq,
2493 IRQF_SHARED, driver_name, udc);
2494 if (retval != 0) {
2495 dev_err(udc->dev, "%s: can't get irq %i, err %d\n",
2496 driver_name, udc->irq, retval);
2497 goto err;
2498 }
2499
2500 if (!IS_ERR_OR_NULL(udc->transceiver))
2501 usb_register_notifier(udc->transceiver, &pxa27x_udc_phy);
2502 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2503 if (retval)
2504 goto err_add_gadget;
2505
2506 pxa_init_debugfs(udc);
2507 if (should_enable_udc(udc))
2508 udc_enable(udc);
2509 return 0;
2510
2511err_add_gadget:
2512 if (!IS_ERR_OR_NULL(udc->transceiver))
2513 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy);
2514err:
2515 clk_unprepare(udc->clk);
2516 return retval;
2517}
2518
2519
2520
2521
2522
2523static int pxa_udc_remove(struct platform_device *_dev)
2524{
2525 struct pxa_udc *udc = platform_get_drvdata(_dev);
2526
2527 usb_del_gadget_udc(&udc->gadget);
2528 pxa_cleanup_debugfs(udc);
2529
2530 if (!IS_ERR_OR_NULL(udc->transceiver)) {
2531 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy);
2532 usb_put_phy(udc->transceiver);
2533 }
2534
2535 udc->transceiver = NULL;
2536 the_controller = NULL;
2537 clk_unprepare(udc->clk);
2538
2539 return 0;
2540}
2541
2542static void pxa_udc_shutdown(struct platform_device *_dev)
2543{
2544 struct pxa_udc *udc = platform_get_drvdata(_dev);
2545
2546 if (udc_readl(udc, UDCCR) & UDCCR_UDE)
2547 udc_disable(udc);
2548}
2549
2550#ifdef CONFIG_PXA27x
2551extern void pxa27x_clear_otgph(void);
2552#else
2553#define pxa27x_clear_otgph() do {} while (0)
2554#endif
2555
2556#ifdef CONFIG_PM
2557
2558
2559
2560
2561
2562
2563
2564
2565static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state)
2566{
2567 struct pxa_udc *udc = platform_get_drvdata(_dev);
2568 struct pxa_ep *ep;
2569
2570 ep = &udc->pxa_ep[0];
2571 udc->udccsr0 = udc_ep_readl(ep, UDCCSR);
2572
2573 udc_disable(udc);
2574 udc->pullup_resume = udc->pullup_on;
2575 dplus_pullup(udc, 0);
2576
2577 if (udc->driver)
2578 udc->driver->disconnect(&udc->gadget);
2579
2580 return 0;
2581}
2582
2583
2584
2585
2586
2587
2588
2589
2590static int pxa_udc_resume(struct platform_device *_dev)
2591{
2592 struct pxa_udc *udc = platform_get_drvdata(_dev);
2593 struct pxa_ep *ep;
2594
2595 ep = &udc->pxa_ep[0];
2596 udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME));
2597
2598 dplus_pullup(udc, udc->pullup_resume);
2599 if (should_enable_udc(udc))
2600 udc_enable(udc);
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610 pxa27x_clear_otgph();
2611
2612 return 0;
2613}
2614#endif
2615
2616
2617MODULE_ALIAS("platform:pxa27x-udc");
2618
2619static struct platform_driver udc_driver = {
2620 .driver = {
2621 .name = "pxa27x-udc",
2622 .of_match_table = of_match_ptr(udc_pxa_dt_ids),
2623 },
2624 .probe = pxa_udc_probe,
2625 .remove = pxa_udc_remove,
2626 .shutdown = pxa_udc_shutdown,
2627#ifdef CONFIG_PM
2628 .suspend = pxa_udc_suspend,
2629 .resume = pxa_udc_resume
2630#endif
2631};
2632
2633module_platform_driver(udc_driver);
2634
2635MODULE_DESCRIPTION(DRIVER_DESC);
2636MODULE_AUTHOR("Robert Jarzmik");
2637MODULE_LICENSE("GPL");
2638