2 * Fusb300 UDC (USB gadget)
4 * Copyright (C) 2010 Faraday Technology Corp.
6 * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 #include <linux/dma-mapping.h>
13 #include <linux/err.h>
14 #include <linux/interrupt.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/usb/ch9.h>
19 #include <linux/usb/gadget.h>
21 #include "fusb300_udc.h"
23 MODULE_DESCRIPTION("FUSB300 USB gadget driver");
24 MODULE_LICENSE("GPL");
25 MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>");
26 MODULE_ALIAS("platform:fusb300_udc");
28 #define DRIVER_VERSION "20 October 2010"
30 static const char udc_name
[] = "fusb300_udc";
31 static const char * const fusb300_ep_name
[] = {
32 "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", "ep8", "ep9",
33 "ep10", "ep11", "ep12", "ep13", "ep14", "ep15"
36 static void done(struct fusb300_ep
*ep
, struct fusb300_request
*req
,
39 static void fusb300_enable_bit(struct fusb300
*fusb300
, u32 offset
,
42 u32 reg
= ioread32(fusb300
->reg
+ offset
);
45 iowrite32(reg
, fusb300
->reg
+ offset
);
48 static void fusb300_disable_bit(struct fusb300
*fusb300
, u32 offset
,
51 u32 reg
= ioread32(fusb300
->reg
+ offset
);
54 iowrite32(reg
, fusb300
->reg
+ offset
);
58 static void fusb300_ep_setting(struct fusb300_ep
*ep
,
59 struct fusb300_ep_info info
)
61 ep
->epnum
= info
.epnum
;
65 static int fusb300_ep_release(struct fusb300_ep
*ep
)
75 static void fusb300_set_fifo_entry(struct fusb300
*fusb300
,
78 u32 val
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
80 val
&= ~FUSB300_EPSET1_FIFOENTRY_MSK
;
81 val
|= FUSB300_EPSET1_FIFOENTRY(FUSB300_FIFO_ENTRY_NUM
);
82 iowrite32(val
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
85 static void fusb300_set_start_entry(struct fusb300
*fusb300
,
88 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
89 u32 start_entry
= fusb300
->fifo_entry_num
* FUSB300_FIFO_ENTRY_NUM
;
91 reg
&= ~FUSB300_EPSET1_START_ENTRY_MSK
;
92 reg
|= FUSB300_EPSET1_START_ENTRY(start_entry
);
93 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
94 if (fusb300
->fifo_entry_num
== FUSB300_MAX_FIFO_ENTRY
) {
95 fusb300
->fifo_entry_num
= 0;
97 pr_err("fifo entry is over the maximum number!\n");
99 fusb300
->fifo_entry_num
++;
102 /* set fusb300_set_start_entry first before fusb300_set_epaddrofs */
103 static void fusb300_set_epaddrofs(struct fusb300
*fusb300
,
104 struct fusb300_ep_info info
)
106 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET2(info
.epnum
));
108 reg
&= ~FUSB300_EPSET2_ADDROFS_MSK
;
109 reg
|= FUSB300_EPSET2_ADDROFS(fusb300
->addrofs
);
110 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET2(info
.epnum
));
111 fusb300
->addrofs
+= (info
.maxpacket
+ 7) / 8 * FUSB300_FIFO_ENTRY_NUM
;
114 static void ep_fifo_setting(struct fusb300
*fusb300
,
115 struct fusb300_ep_info info
)
117 fusb300_set_fifo_entry(fusb300
, info
.epnum
);
118 fusb300_set_start_entry(fusb300
, info
.epnum
);
119 fusb300_set_epaddrofs(fusb300
, info
);
122 static void fusb300_set_eptype(struct fusb300
*fusb300
,
123 struct fusb300_ep_info info
)
125 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
127 reg
&= ~FUSB300_EPSET1_TYPE_MSK
;
128 reg
|= FUSB300_EPSET1_TYPE(info
.type
);
129 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
132 static void fusb300_set_epdir(struct fusb300
*fusb300
,
133 struct fusb300_ep_info info
)
139 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
140 reg
&= ~FUSB300_EPSET1_DIR_MSK
;
141 reg
|= FUSB300_EPSET1_DIRIN
;
142 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
145 static void fusb300_set_ep_active(struct fusb300
*fusb300
,
148 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
150 reg
|= FUSB300_EPSET1_ACTEN
;
151 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(ep
));
154 static void fusb300_set_epmps(struct fusb300
*fusb300
,
155 struct fusb300_ep_info info
)
157 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET2(info
.epnum
));
159 reg
&= ~FUSB300_EPSET2_MPS_MSK
;
160 reg
|= FUSB300_EPSET2_MPS(info
.maxpacket
);
161 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET2(info
.epnum
));
164 static void fusb300_set_interval(struct fusb300
*fusb300
,
165 struct fusb300_ep_info info
)
167 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
169 reg
&= ~FUSB300_EPSET1_INTERVAL(0x7);
170 reg
|= FUSB300_EPSET1_INTERVAL(info
.interval
);
171 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
174 static void fusb300_set_bwnum(struct fusb300
*fusb300
,
175 struct fusb300_ep_info info
)
177 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
179 reg
&= ~FUSB300_EPSET1_BWNUM(0x3);
180 reg
|= FUSB300_EPSET1_BWNUM(info
.bw_num
);
181 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET1(info
.epnum
));
184 static void set_ep_reg(struct fusb300
*fusb300
,
185 struct fusb300_ep_info info
)
187 fusb300_set_eptype(fusb300
, info
);
188 fusb300_set_epdir(fusb300
, info
);
189 fusb300_set_epmps(fusb300
, info
);
192 fusb300_set_interval(fusb300
, info
);
195 fusb300_set_bwnum(fusb300
, info
);
197 fusb300_set_ep_active(fusb300
, info
.epnum
);
200 static int config_ep(struct fusb300_ep
*ep
,
201 const struct usb_endpoint_descriptor
*desc
)
203 struct fusb300
*fusb300
= ep
->fusb300
;
204 struct fusb300_ep_info info
;
212 info
.type
= desc
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
;
213 info
.dir_in
= (desc
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) ? 1 : 0;
214 info
.maxpacket
= usb_endpoint_maxp(desc
);
215 info
.epnum
= desc
->bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
;
217 if ((info
.type
== USB_ENDPOINT_XFER_INT
) ||
218 (info
.type
== USB_ENDPOINT_XFER_ISOC
)) {
219 info
.interval
= desc
->bInterval
;
220 if (info
.type
== USB_ENDPOINT_XFER_ISOC
)
221 info
.bw_num
= ((desc
->wMaxPacketSize
& 0x1800) >> 11);
224 ep_fifo_setting(fusb300
, info
);
226 set_ep_reg(fusb300
, info
);
228 fusb300_ep_setting(ep
, info
);
230 fusb300
->ep
[info
.epnum
] = ep
;
235 static int fusb300_enable(struct usb_ep
*_ep
,
236 const struct usb_endpoint_descriptor
*desc
)
238 struct fusb300_ep
*ep
;
240 ep
= container_of(_ep
, struct fusb300_ep
, ep
);
242 if (ep
->fusb300
->reenum
) {
243 ep
->fusb300
->fifo_entry_num
= 0;
244 ep
->fusb300
->addrofs
= 0;
245 ep
->fusb300
->reenum
= 0;
248 return config_ep(ep
, desc
);
251 static int fusb300_disable(struct usb_ep
*_ep
)
253 struct fusb300_ep
*ep
;
254 struct fusb300_request
*req
;
257 ep
= container_of(_ep
, struct fusb300_ep
, ep
);
261 while (!list_empty(&ep
->queue
)) {
262 req
= list_entry(ep
->queue
.next
, struct fusb300_request
, queue
);
263 spin_lock_irqsave(&ep
->fusb300
->lock
, flags
);
264 done(ep
, req
, -ECONNRESET
);
265 spin_unlock_irqrestore(&ep
->fusb300
->lock
, flags
);
268 return fusb300_ep_release(ep
);
271 static struct usb_request
*fusb300_alloc_request(struct usb_ep
*_ep
,
274 struct fusb300_request
*req
;
276 req
= kzalloc(sizeof(struct fusb300_request
), gfp_flags
);
279 INIT_LIST_HEAD(&req
->queue
);
284 static void fusb300_free_request(struct usb_ep
*_ep
, struct usb_request
*_req
)
286 struct fusb300_request
*req
;
288 req
= container_of(_req
, struct fusb300_request
, req
);
292 static int enable_fifo_int(struct fusb300_ep
*ep
)
294 struct fusb300
*fusb300
= ep
->fusb300
;
297 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_IGER0
,
298 FUSB300_IGER0_EEPn_FIFO_INT(ep
->epnum
));
300 pr_err("can't enable_fifo_int ep0\n");
307 static int disable_fifo_int(struct fusb300_ep
*ep
)
309 struct fusb300
*fusb300
= ep
->fusb300
;
312 fusb300_disable_bit(fusb300
, FUSB300_OFFSET_IGER0
,
313 FUSB300_IGER0_EEPn_FIFO_INT(ep
->epnum
));
315 pr_err("can't disable_fifo_int ep0\n");
322 static void fusb300_set_cxlen(struct fusb300
*fusb300
, u32 length
)
326 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CSR
);
327 reg
&= ~FUSB300_CSR_LEN_MSK
;
328 reg
|= FUSB300_CSR_LEN(length
);
329 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_CSR
);
332 /* write data to cx fifo */
333 static void fusb300_wrcxf(struct fusb300_ep
*ep
,
334 struct fusb300_request
*req
)
339 struct fusb300
*fusb300
= ep
->fusb300
;
340 u32 length
= req
->req
.length
- req
->req
.actual
;
342 tmp
= req
->req
.buf
+ req
->req
.actual
;
344 if (length
> SS_CTL_MAX_PACKET_SIZE
) {
345 fusb300_set_cxlen(fusb300
, SS_CTL_MAX_PACKET_SIZE
);
346 for (i
= (SS_CTL_MAX_PACKET_SIZE
>> 2); i
> 0; i
--) {
347 data
= *tmp
| *(tmp
+ 1) << 8 | *(tmp
+ 2) << 16 |
349 iowrite32(data
, fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
352 req
->req
.actual
+= SS_CTL_MAX_PACKET_SIZE
;
353 } else { /* length is less than max packet size */
354 fusb300_set_cxlen(fusb300
, length
);
355 for (i
= length
>> 2; i
> 0; i
--) {
356 data
= *tmp
| *(tmp
+ 1) << 8 | *(tmp
+ 2) << 16 |
358 printk(KERN_DEBUG
" 0x%x\n", data
);
359 iowrite32(data
, fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
362 switch (length
% 4) {
365 printk(KERN_DEBUG
" 0x%x\n", data
);
366 iowrite32(data
, fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
369 data
= *tmp
| *(tmp
+ 1) << 8;
370 printk(KERN_DEBUG
" 0x%x\n", data
);
371 iowrite32(data
, fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
374 data
= *tmp
| *(tmp
+ 1) << 8 | *(tmp
+ 2) << 16;
375 printk(KERN_DEBUG
" 0x%x\n", data
);
376 iowrite32(data
, fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
381 req
->req
.actual
+= length
;
385 static void fusb300_set_epnstall(struct fusb300
*fusb300
, u8 ep
)
387 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_EPSET0(ep
),
391 static void fusb300_clear_epnstall(struct fusb300
*fusb300
, u8 ep
)
393 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET0(ep
));
395 if (reg
& FUSB300_EPSET0_STL
) {
396 printk(KERN_DEBUG
"EP%d stall... Clear!!\n", ep
);
397 reg
|= FUSB300_EPSET0_STL_CLR
;
398 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_EPSET0(ep
));
402 static void ep0_queue(struct fusb300_ep
*ep
, struct fusb300_request
*req
)
404 if (ep
->fusb300
->ep0_dir
) { /* if IN */
405 if (req
->req
.length
) {
406 fusb300_wrcxf(ep
, req
);
408 printk(KERN_DEBUG
"%s : req->req.length = 0x%x\n",
409 __func__
, req
->req
.length
);
410 if ((req
->req
.length
== req
->req
.actual
) ||
411 (req
->req
.actual
< ep
->ep
.maxpacket
))
414 if (!req
->req
.length
)
417 fusb300_enable_bit(ep
->fusb300
, FUSB300_OFFSET_IGER1
,
418 FUSB300_IGER1_CX_OUT_INT
);
422 static int fusb300_queue(struct usb_ep
*_ep
, struct usb_request
*_req
,
425 struct fusb300_ep
*ep
;
426 struct fusb300_request
*req
;
430 ep
= container_of(_ep
, struct fusb300_ep
, ep
);
431 req
= container_of(_req
, struct fusb300_request
, req
);
433 if (ep
->fusb300
->gadget
.speed
== USB_SPEED_UNKNOWN
)
436 spin_lock_irqsave(&ep
->fusb300
->lock
, flags
);
438 if (list_empty(&ep
->queue
))
441 list_add_tail(&req
->queue
, &ep
->queue
);
444 req
->req
.status
= -EINPROGRESS
;
446 if (ep
->ep
.desc
== NULL
) /* ep0 */
448 else if (request
&& !ep
->stall
)
451 spin_unlock_irqrestore(&ep
->fusb300
->lock
, flags
);
456 static int fusb300_dequeue(struct usb_ep
*_ep
, struct usb_request
*_req
)
458 struct fusb300_ep
*ep
;
459 struct fusb300_request
*req
;
462 ep
= container_of(_ep
, struct fusb300_ep
, ep
);
463 req
= container_of(_req
, struct fusb300_request
, req
);
465 spin_lock_irqsave(&ep
->fusb300
->lock
, flags
);
466 if (!list_empty(&ep
->queue
))
467 done(ep
, req
, -ECONNRESET
);
468 spin_unlock_irqrestore(&ep
->fusb300
->lock
, flags
);
473 static int fusb300_set_halt_and_wedge(struct usb_ep
*_ep
, int value
, int wedge
)
475 struct fusb300_ep
*ep
;
476 struct fusb300
*fusb300
;
480 ep
= container_of(_ep
, struct fusb300_ep
, ep
);
482 fusb300
= ep
->fusb300
;
484 spin_lock_irqsave(&ep
->fusb300
->lock
, flags
);
486 if (!list_empty(&ep
->queue
)) {
492 fusb300_set_epnstall(fusb300
, ep
->epnum
);
497 fusb300_clear_epnstall(fusb300
, ep
->epnum
);
503 spin_unlock_irqrestore(&ep
->fusb300
->lock
, flags
);
507 static int fusb300_set_halt(struct usb_ep
*_ep
, int value
)
509 return fusb300_set_halt_and_wedge(_ep
, value
, 0);
512 static int fusb300_set_wedge(struct usb_ep
*_ep
)
514 return fusb300_set_halt_and_wedge(_ep
, 1, 1);
517 static void fusb300_fifo_flush(struct usb_ep
*_ep
)
521 static struct usb_ep_ops fusb300_ep_ops
= {
522 .enable
= fusb300_enable
,
523 .disable
= fusb300_disable
,
525 .alloc_request
= fusb300_alloc_request
,
526 .free_request
= fusb300_free_request
,
528 .queue
= fusb300_queue
,
529 .dequeue
= fusb300_dequeue
,
531 .set_halt
= fusb300_set_halt
,
532 .fifo_flush
= fusb300_fifo_flush
,
533 .set_wedge
= fusb300_set_wedge
,
536 /*****************************************************************************/
537 static void fusb300_clear_int(struct fusb300
*fusb300
, u32 offset
,
540 iowrite32(value
, fusb300
->reg
+ offset
);
543 static void fusb300_reset(void)
547 static void fusb300_set_cxstall(struct fusb300
*fusb300
)
549 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_CSR
,
553 static void fusb300_set_cxdone(struct fusb300
*fusb300
)
555 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_CSR
,
559 /* read data from cx fifo */
560 static void fusb300_rdcxf(struct fusb300
*fusb300
,
561 u8
*buffer
, u32 length
)
569 for (i
= (length
>> 2); i
> 0; i
--) {
570 data
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
571 printk(KERN_DEBUG
" 0x%x\n", data
);
573 *(tmp
+ 1) = (data
>> 8) & 0xFF;
574 *(tmp
+ 2) = (data
>> 16) & 0xFF;
575 *(tmp
+ 3) = (data
>> 24) & 0xFF;
579 switch (length
% 4) {
581 data
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
582 printk(KERN_DEBUG
" 0x%x\n", data
);
586 data
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
587 printk(KERN_DEBUG
" 0x%x\n", data
);
589 *(tmp
+ 1) = (data
>> 8) & 0xFF;
592 data
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CXPORT
);
593 printk(KERN_DEBUG
" 0x%x\n", data
);
595 *(tmp
+ 1) = (data
>> 8) & 0xFF;
596 *(tmp
+ 2) = (data
>> 16) & 0xFF;
603 static void fusb300_rdfifo(struct fusb300_ep
*ep
,
604 struct fusb300_request
*req
,
610 struct fusb300
*fusb300
= ep
->fusb300
;
612 tmp
= req
->req
.buf
+ req
->req
.actual
;
613 req
->req
.actual
+= length
;
615 if (req
->req
.actual
> req
->req
.length
)
616 printk(KERN_DEBUG
"req->req.actual > req->req.length\n");
618 for (i
= (length
>> 2); i
> 0; i
--) {
619 data
= ioread32(fusb300
->reg
+
620 FUSB300_OFFSET_EPPORT(ep
->epnum
));
622 *(tmp
+ 1) = (data
>> 8) & 0xFF;
623 *(tmp
+ 2) = (data
>> 16) & 0xFF;
624 *(tmp
+ 3) = (data
>> 24) & 0xFF;
628 switch (length
% 4) {
630 data
= ioread32(fusb300
->reg
+
631 FUSB300_OFFSET_EPPORT(ep
->epnum
));
635 data
= ioread32(fusb300
->reg
+
636 FUSB300_OFFSET_EPPORT(ep
->epnum
));
638 *(tmp
+ 1) = (data
>> 8) & 0xFF;
641 data
= ioread32(fusb300
->reg
+
642 FUSB300_OFFSET_EPPORT(ep
->epnum
));
644 *(tmp
+ 1) = (data
>> 8) & 0xFF;
645 *(tmp
+ 2) = (data
>> 16) & 0xFF;
652 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGR1
);
653 reg
&= FUSB300_IGR1_SYNF0_EMPTY_INT
;
655 printk(KERN_INFO
"sync fifo is not empty!\n");
660 static u8
fusb300_get_epnstall(struct fusb300
*fusb300
, u8 ep
)
663 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPSET0(ep
));
665 value
= reg
& FUSB300_EPSET0_STL
;
670 static u8
fusb300_get_cxstall(struct fusb300
*fusb300
)
673 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_CSR
);
675 value
= (reg
& FUSB300_CSR_STL
) >> 1;
680 static void request_error(struct fusb300
*fusb300
)
682 fusb300_set_cxstall(fusb300
);
683 printk(KERN_DEBUG
"request error!!\n");
686 static void get_status(struct fusb300
*fusb300
, struct usb_ctrlrequest
*ctrl
)
687 __releases(fusb300
->lock
)
688 __acquires(fusb300
->lock
)
692 u16 w_index
= ctrl
->wIndex
;
694 switch (ctrl
->bRequestType
& USB_RECIP_MASK
) {
695 case USB_RECIP_DEVICE
:
696 status
= 1 << USB_DEVICE_SELF_POWERED
;
698 case USB_RECIP_INTERFACE
:
701 case USB_RECIP_ENDPOINT
:
702 ep
= w_index
& USB_ENDPOINT_NUMBER_MASK
;
704 if (fusb300_get_epnstall(fusb300
, ep
))
705 status
= 1 << USB_ENDPOINT_HALT
;
707 if (fusb300_get_cxstall(fusb300
))
713 request_error(fusb300
);
717 fusb300
->ep0_data
= cpu_to_le16(status
);
718 fusb300
->ep0_req
->buf
= &fusb300
->ep0_data
;
719 fusb300
->ep0_req
->length
= 2;
721 spin_unlock(&fusb300
->lock
);
722 fusb300_queue(fusb300
->gadget
.ep0
, fusb300
->ep0_req
, GFP_KERNEL
);
723 spin_lock(&fusb300
->lock
);
726 static void set_feature(struct fusb300
*fusb300
, struct usb_ctrlrequest
*ctrl
)
730 switch (ctrl
->bRequestType
& USB_RECIP_MASK
) {
731 case USB_RECIP_DEVICE
:
732 fusb300_set_cxdone(fusb300
);
734 case USB_RECIP_INTERFACE
:
735 fusb300_set_cxdone(fusb300
);
737 case USB_RECIP_ENDPOINT
: {
738 u16 w_index
= le16_to_cpu(ctrl
->wIndex
);
740 ep
= w_index
& USB_ENDPOINT_NUMBER_MASK
;
742 fusb300_set_epnstall(fusb300
, ep
);
744 fusb300_set_cxstall(fusb300
);
745 fusb300_set_cxdone(fusb300
);
749 request_error(fusb300
);
754 static void fusb300_clear_seqnum(struct fusb300
*fusb300
, u8 ep
)
756 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_EPSET0(ep
),
757 FUSB300_EPSET0_CLRSEQNUM
);
760 static void clear_feature(struct fusb300
*fusb300
, struct usb_ctrlrequest
*ctrl
)
762 struct fusb300_ep
*ep
=
763 fusb300
->ep
[ctrl
->wIndex
& USB_ENDPOINT_NUMBER_MASK
];
765 switch (ctrl
->bRequestType
& USB_RECIP_MASK
) {
766 case USB_RECIP_DEVICE
:
767 fusb300_set_cxdone(fusb300
);
769 case USB_RECIP_INTERFACE
:
770 fusb300_set_cxdone(fusb300
);
772 case USB_RECIP_ENDPOINT
:
773 if (ctrl
->wIndex
& USB_ENDPOINT_NUMBER_MASK
) {
775 fusb300_set_cxdone(fusb300
);
780 fusb300_clear_seqnum(fusb300
, ep
->epnum
);
781 fusb300_clear_epnstall(fusb300
, ep
->epnum
);
782 if (!list_empty(&ep
->queue
))
786 fusb300_set_cxdone(fusb300
);
789 request_error(fusb300
);
794 static void fusb300_set_dev_addr(struct fusb300
*fusb300
, u16 addr
)
796 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_DAR
);
798 reg
&= ~FUSB300_DAR_DRVADDR_MSK
;
799 reg
|= FUSB300_DAR_DRVADDR(addr
);
801 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_DAR
);
804 static void set_address(struct fusb300
*fusb300
, struct usb_ctrlrequest
*ctrl
)
806 if (ctrl
->wValue
>= 0x0100)
807 request_error(fusb300
);
809 fusb300_set_dev_addr(fusb300
, ctrl
->wValue
);
810 fusb300_set_cxdone(fusb300
);
814 #define UVC_COPY_DESCRIPTORS(mem, src) \
816 const struct usb_descriptor_header * const *__src; \
817 for (__src = src; *__src; ++__src) { \
818 memcpy(mem, *__src, (*__src)->bLength); \
819 mem += (*__src)->bLength; \
823 static int setup_packet(struct fusb300
*fusb300
, struct usb_ctrlrequest
*ctrl
)
829 fusb300_rdcxf(fusb300
, p
, 8);
830 fusb300
->ep0_dir
= ctrl
->bRequestType
& USB_DIR_IN
;
831 fusb300
->ep0_length
= ctrl
->wLength
;
834 if ((ctrl
->bRequestType
& USB_TYPE_MASK
) == USB_TYPE_STANDARD
) {
835 switch (ctrl
->bRequest
) {
836 case USB_REQ_GET_STATUS
:
837 get_status(fusb300
, ctrl
);
839 case USB_REQ_CLEAR_FEATURE
:
840 clear_feature(fusb300
, ctrl
);
842 case USB_REQ_SET_FEATURE
:
843 set_feature(fusb300
, ctrl
);
845 case USB_REQ_SET_ADDRESS
:
846 set_address(fusb300
, ctrl
);
848 case USB_REQ_SET_CONFIGURATION
:
849 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_DAR
,
850 FUSB300_DAR_SETCONFG
);
851 /* clear sequence number */
852 for (i
= 1; i
<= FUSB300_MAX_NUM_EP
; i
++)
853 fusb300_clear_seqnum(fusb300
, i
);
867 static void done(struct fusb300_ep
*ep
, struct fusb300_request
*req
,
870 list_del_init(&req
->queue
);
872 /* don't modify queue heads during completion callback */
873 if (ep
->fusb300
->gadget
.speed
== USB_SPEED_UNKNOWN
)
874 req
->req
.status
= -ESHUTDOWN
;
876 req
->req
.status
= status
;
878 spin_unlock(&ep
->fusb300
->lock
);
879 usb_gadget_giveback_request(&ep
->ep
, &req
->req
);
880 spin_lock(&ep
->fusb300
->lock
);
883 disable_fifo_int(ep
);
884 if (!list_empty(&ep
->queue
))
887 fusb300_set_cxdone(ep
->fusb300
);
890 static void fusb300_fill_idma_prdtbl(struct fusb300_ep
*ep
, dma_addr_t d
,
898 reg
= ioread32(ep
->fusb300
->reg
+
899 FUSB300_OFFSET_EPPRD_W0(ep
->epnum
));
900 reg
&= FUSB300_EPPRD0_H
;
903 iowrite32(d
, ep
->fusb300
->reg
+ FUSB300_OFFSET_EPPRD_W1(ep
->epnum
));
905 value
= FUSB300_EPPRD0_BTC(len
) | FUSB300_EPPRD0_H
|
906 FUSB300_EPPRD0_F
| FUSB300_EPPRD0_L
| FUSB300_EPPRD0_I
;
907 iowrite32(value
, ep
->fusb300
->reg
+ FUSB300_OFFSET_EPPRD_W0(ep
->epnum
));
909 iowrite32(0x0, ep
->fusb300
->reg
+ FUSB300_OFFSET_EPPRD_W2(ep
->epnum
));
911 fusb300_enable_bit(ep
->fusb300
, FUSB300_OFFSET_EPPRDRDY
,
912 FUSB300_EPPRDR_EP_PRD_RDY(ep
->epnum
));
915 static void fusb300_wait_idma_finished(struct fusb300_ep
*ep
)
920 reg
= ioread32(ep
->fusb300
->reg
+ FUSB300_OFFSET_IGR1
);
921 if ((reg
& FUSB300_IGR1_VBUS_CHG_INT
) ||
922 (reg
& FUSB300_IGR1_WARM_RST_INT
) ||
923 (reg
& FUSB300_IGR1_HOT_RST_INT
) ||
924 (reg
& FUSB300_IGR1_USBRST_INT
)
927 reg
= ioread32(ep
->fusb300
->reg
+ FUSB300_OFFSET_IGR0
);
928 reg
&= FUSB300_IGR0_EPn_PRD_INT(ep
->epnum
);
931 fusb300_clear_int(ep
->fusb300
, FUSB300_OFFSET_IGR0
,
932 FUSB300_IGR0_EPn_PRD_INT(ep
->epnum
));
936 reg
= ioread32(ep
->fusb300
->reg
+ FUSB300_OFFSET_IGER0
);
937 reg
&= ~FUSB300_IGER0_EEPn_PRD_INT(ep
->epnum
);
938 iowrite32(reg
, ep
->fusb300
->reg
+ FUSB300_OFFSET_IGER0
);
941 static void fusb300_set_idma(struct fusb300_ep
*ep
,
942 struct fusb300_request
*req
)
946 ret
= usb_gadget_map_request(&ep
->fusb300
->gadget
,
947 &req
->req
, DMA_TO_DEVICE
);
951 fusb300_enable_bit(ep
->fusb300
, FUSB300_OFFSET_IGER0
,
952 FUSB300_IGER0_EEPn_PRD_INT(ep
->epnum
));
954 fusb300_fill_idma_prdtbl(ep
, req
->req
.dma
, req
->req
.length
);
955 /* check idma is done */
956 fusb300_wait_idma_finished(ep
);
958 usb_gadget_unmap_request(&ep
->fusb300
->gadget
,
959 &req
->req
, DMA_TO_DEVICE
);
962 static void in_ep_fifo_handler(struct fusb300_ep
*ep
)
964 struct fusb300_request
*req
= list_entry(ep
->queue
.next
,
965 struct fusb300_request
, queue
);
968 fusb300_set_idma(ep
, req
);
972 static void out_ep_fifo_handler(struct fusb300_ep
*ep
)
974 struct fusb300
*fusb300
= ep
->fusb300
;
975 struct fusb300_request
*req
= list_entry(ep
->queue
.next
,
976 struct fusb300_request
, queue
);
977 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_EPFFR(ep
->epnum
));
978 u32 length
= reg
& FUSB300_FFR_BYCNT
;
980 fusb300_rdfifo(ep
, req
, length
);
982 /* finish out transfer */
983 if ((req
->req
.length
== req
->req
.actual
) || (length
< ep
->ep
.maxpacket
))
987 static void check_device_mode(struct fusb300
*fusb300
)
989 u32 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_GCR
);
991 switch (reg
& FUSB300_GCR_DEVEN_MSK
) {
992 case FUSB300_GCR_DEVEN_SS
:
993 fusb300
->gadget
.speed
= USB_SPEED_SUPER
;
995 case FUSB300_GCR_DEVEN_HS
:
996 fusb300
->gadget
.speed
= USB_SPEED_HIGH
;
998 case FUSB300_GCR_DEVEN_FS
:
999 fusb300
->gadget
.speed
= USB_SPEED_FULL
;
1002 fusb300
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1005 printk(KERN_INFO
"dev_mode = %d\n", (reg
& FUSB300_GCR_DEVEN_MSK
));
1009 static void fusb300_ep0out(struct fusb300
*fusb300
)
1011 struct fusb300_ep
*ep
= fusb300
->ep
[0];
1014 if (!list_empty(&ep
->queue
)) {
1015 struct fusb300_request
*req
;
1017 req
= list_first_entry(&ep
->queue
,
1018 struct fusb300_request
, queue
);
1019 if (req
->req
.length
)
1020 fusb300_rdcxf(ep
->fusb300
, req
->req
.buf
,
1023 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGER1
);
1024 reg
&= ~FUSB300_IGER1_CX_OUT_INT
;
1025 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_IGER1
);
1027 pr_err("%s : empty queue\n", __func__
);
1030 static void fusb300_ep0in(struct fusb300
*fusb300
)
1032 struct fusb300_request
*req
;
1033 struct fusb300_ep
*ep
= fusb300
->ep
[0];
1035 if ((!list_empty(&ep
->queue
)) && (fusb300
->ep0_dir
)) {
1036 req
= list_entry(ep
->queue
.next
,
1037 struct fusb300_request
, queue
);
1038 if (req
->req
.length
)
1039 fusb300_wrcxf(ep
, req
);
1040 if ((req
->req
.length
- req
->req
.actual
) < ep
->ep
.maxpacket
)
1043 fusb300_set_cxdone(fusb300
);
1046 static void fusb300_grp2_handler(void)
1050 static void fusb300_grp3_handler(void)
1054 static void fusb300_grp4_handler(void)
1058 static void fusb300_grp5_handler(void)
1062 static irqreturn_t
fusb300_irq(int irq
, void *_fusb300
)
1064 struct fusb300
*fusb300
= _fusb300
;
1065 u32 int_grp1
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGR1
);
1066 u32 int_grp1_en
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGER1
);
1067 u32 int_grp0
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGR0
);
1068 u32 int_grp0_en
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_IGER0
);
1069 struct usb_ctrlrequest ctrl
;
1074 spin_lock(&fusb300
->lock
);
1076 int_grp1
&= int_grp1_en
;
1077 int_grp0
&= int_grp0_en
;
1079 if (int_grp1
& FUSB300_IGR1_WARM_RST_INT
) {
1080 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1081 FUSB300_IGR1_WARM_RST_INT
);
1082 printk(KERN_INFO
"fusb300_warmreset\n");
1086 if (int_grp1
& FUSB300_IGR1_HOT_RST_INT
) {
1087 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1088 FUSB300_IGR1_HOT_RST_INT
);
1089 printk(KERN_INFO
"fusb300_hotreset\n");
1093 if (int_grp1
& FUSB300_IGR1_USBRST_INT
) {
1094 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1095 FUSB300_IGR1_USBRST_INT
);
1098 /* COMABT_INT has a highest priority */
1100 if (int_grp1
& FUSB300_IGR1_CX_COMABT_INT
) {
1101 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1102 FUSB300_IGR1_CX_COMABT_INT
);
1103 printk(KERN_INFO
"fusb300_ep0abt\n");
1106 if (int_grp1
& FUSB300_IGR1_VBUS_CHG_INT
) {
1107 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1108 FUSB300_IGR1_VBUS_CHG_INT
);
1109 printk(KERN_INFO
"fusb300_vbus_change\n");
1112 if (int_grp1
& FUSB300_IGR1_U3_EXIT_FAIL_INT
) {
1113 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1114 FUSB300_IGR1_U3_EXIT_FAIL_INT
);
1117 if (int_grp1
& FUSB300_IGR1_U2_EXIT_FAIL_INT
) {
1118 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1119 FUSB300_IGR1_U2_EXIT_FAIL_INT
);
1122 if (int_grp1
& FUSB300_IGR1_U1_EXIT_FAIL_INT
) {
1123 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1124 FUSB300_IGR1_U1_EXIT_FAIL_INT
);
1127 if (int_grp1
& FUSB300_IGR1_U2_ENTRY_FAIL_INT
) {
1128 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1129 FUSB300_IGR1_U2_ENTRY_FAIL_INT
);
1132 if (int_grp1
& FUSB300_IGR1_U1_ENTRY_FAIL_INT
) {
1133 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1134 FUSB300_IGR1_U1_ENTRY_FAIL_INT
);
1137 if (int_grp1
& FUSB300_IGR1_U3_EXIT_INT
) {
1138 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1139 FUSB300_IGR1_U3_EXIT_INT
);
1140 printk(KERN_INFO
"FUSB300_IGR1_U3_EXIT_INT\n");
1143 if (int_grp1
& FUSB300_IGR1_U2_EXIT_INT
) {
1144 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1145 FUSB300_IGR1_U2_EXIT_INT
);
1146 printk(KERN_INFO
"FUSB300_IGR1_U2_EXIT_INT\n");
1149 if (int_grp1
& FUSB300_IGR1_U1_EXIT_INT
) {
1150 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1151 FUSB300_IGR1_U1_EXIT_INT
);
1152 printk(KERN_INFO
"FUSB300_IGR1_U1_EXIT_INT\n");
1155 if (int_grp1
& FUSB300_IGR1_U3_ENTRY_INT
) {
1156 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1157 FUSB300_IGR1_U3_ENTRY_INT
);
1158 printk(KERN_INFO
"FUSB300_IGR1_U3_ENTRY_INT\n");
1159 fusb300_enable_bit(fusb300
, FUSB300_OFFSET_SSCR1
,
1160 FUSB300_SSCR1_GO_U3_DONE
);
1163 if (int_grp1
& FUSB300_IGR1_U2_ENTRY_INT
) {
1164 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1165 FUSB300_IGR1_U2_ENTRY_INT
);
1166 printk(KERN_INFO
"FUSB300_IGR1_U2_ENTRY_INT\n");
1169 if (int_grp1
& FUSB300_IGR1_U1_ENTRY_INT
) {
1170 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1171 FUSB300_IGR1_U1_ENTRY_INT
);
1172 printk(KERN_INFO
"FUSB300_IGR1_U1_ENTRY_INT\n");
1175 if (int_grp1
& FUSB300_IGR1_RESM_INT
) {
1176 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1177 FUSB300_IGR1_RESM_INT
);
1178 printk(KERN_INFO
"fusb300_resume\n");
1181 if (int_grp1
& FUSB300_IGR1_SUSP_INT
) {
1182 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1183 FUSB300_IGR1_SUSP_INT
);
1184 printk(KERN_INFO
"fusb300_suspend\n");
1187 if (int_grp1
& FUSB300_IGR1_HS_LPM_INT
) {
1188 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1189 FUSB300_IGR1_HS_LPM_INT
);
1190 printk(KERN_INFO
"fusb300_HS_LPM_INT\n");
1193 if (int_grp1
& FUSB300_IGR1_DEV_MODE_CHG_INT
) {
1194 fusb300_clear_int(fusb300
, FUSB300_OFFSET_IGR1
,
1195 FUSB300_IGR1_DEV_MODE_CHG_INT
);
1196 check_device_mode(fusb300
);
1199 if (int_grp1
& FUSB300_IGR1_CX_COMFAIL_INT
) {
1200 fusb300_set_cxstall(fusb300
);
1201 printk(KERN_INFO
"fusb300_ep0fail\n");
1204 if (int_grp1
& FUSB300_IGR1_CX_SETUP_INT
) {
1205 printk(KERN_INFO
"fusb300_ep0setup\n");
1206 if (setup_packet(fusb300
, &ctrl
)) {
1207 spin_unlock(&fusb300
->lock
);
1208 if (fusb300
->driver
->setup(&fusb300
->gadget
, &ctrl
) < 0)
1209 fusb300_set_cxstall(fusb300
);
1210 spin_lock(&fusb300
->lock
);
1214 if (int_grp1
& FUSB300_IGR1_CX_CMDEND_INT
)
1215 printk(KERN_INFO
"fusb300_cmdend\n");
1218 if (int_grp1
& FUSB300_IGR1_CX_OUT_INT
) {
1219 printk(KERN_INFO
"fusb300_cxout\n");
1220 fusb300_ep0out(fusb300
);
1223 if (int_grp1
& FUSB300_IGR1_CX_IN_INT
) {
1224 printk(KERN_INFO
"fusb300_cxin\n");
1225 fusb300_ep0in(fusb300
);
1228 if (int_grp1
& FUSB300_IGR1_INTGRP5
)
1229 fusb300_grp5_handler();
1231 if (int_grp1
& FUSB300_IGR1_INTGRP4
)
1232 fusb300_grp4_handler();
1234 if (int_grp1
& FUSB300_IGR1_INTGRP3
)
1235 fusb300_grp3_handler();
1237 if (int_grp1
& FUSB300_IGR1_INTGRP2
)
1238 fusb300_grp2_handler();
1241 for (i
= 1; i
< FUSB300_MAX_NUM_EP
; i
++) {
1242 if (int_grp0
& FUSB300_IGR0_EPn_FIFO_INT(i
)) {
1243 reg
= ioread32(fusb300
->reg
+
1244 FUSB300_OFFSET_EPSET1(i
));
1245 in
= (reg
& FUSB300_EPSET1_DIRIN
) ? 1 : 0;
1247 in_ep_fifo_handler(fusb300
->ep
[i
]);
1249 out_ep_fifo_handler(fusb300
->ep
[i
]);
1254 spin_unlock(&fusb300
->lock
);
1259 static void fusb300_set_u2_timeout(struct fusb300
*fusb300
,
1264 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_TT
);
1266 reg
|= FUSB300_SSCR2_U2TIMEOUT(time
);
1268 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_TT
);
1271 static void fusb300_set_u1_timeout(struct fusb300
*fusb300
,
1276 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_TT
);
1277 reg
&= ~(0xff << 8);
1278 reg
|= FUSB300_SSCR2_U1TIMEOUT(time
);
1280 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_TT
);
1283 static void init_controller(struct fusb300
*fusb300
)
1290 mask
= val
= FUSB300_AHBBCR_S0_SPLIT_ON
| FUSB300_AHBBCR_S1_SPLIT_ON
;
1291 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_AHBCR
);
1294 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_AHBCR
);
1296 /* enable high-speed LPM */
1297 mask
= val
= FUSB300_HSCR_HS_LPM_PERMIT
;
1298 reg
= ioread32(fusb300
->reg
+ FUSB300_OFFSET_HSCR
);
1301 iowrite32(reg
, fusb300
->reg
+ FUSB300_OFFSET_HSCR
);
1303 /*set u1 u2 timmer*/
1304 fusb300_set_u2_timeout(fusb300
, 0xff);
1305 fusb300_set_u1_timeout(fusb300
, 0xff);
1307 /* enable all grp1 interrupt */
1308 iowrite32(0xcfffff9f, fusb300
->reg
+ FUSB300_OFFSET_IGER1
);
1310 /*------------------------------------------------------------------------*/
1311 static int fusb300_udc_start(struct usb_gadget
*g
,
1312 struct usb_gadget_driver
*driver
)
1314 struct fusb300
*fusb300
= to_fusb300(g
);
1316 /* hook up the driver */
1317 driver
->driver
.bus
= NULL
;
1318 fusb300
->driver
= driver
;
1323 static int fusb300_udc_stop(struct usb_gadget
*g
)
1325 struct fusb300
*fusb300
= to_fusb300(g
);
1327 init_controller(fusb300
);
1328 fusb300
->driver
= NULL
;
1332 /*--------------------------------------------------------------------------*/
1334 static int fusb300_udc_pullup(struct usb_gadget
*_gadget
, int is_active
)
1339 static const struct usb_gadget_ops fusb300_gadget_ops
= {
1340 .pullup
= fusb300_udc_pullup
,
1341 .udc_start
= fusb300_udc_start
,
1342 .udc_stop
= fusb300_udc_stop
,
1345 static int fusb300_remove(struct platform_device
*pdev
)
1347 struct fusb300
*fusb300
= platform_get_drvdata(pdev
);
1349 usb_del_gadget_udc(&fusb300
->gadget
);
1350 iounmap(fusb300
->reg
);
1351 free_irq(platform_get_irq(pdev
, 0), fusb300
);
1353 fusb300_free_request(&fusb300
->ep
[0]->ep
, fusb300
->ep0_req
);
1359 static int fusb300_probe(struct platform_device
*pdev
)
1361 struct resource
*res
, *ires
, *ires1
;
1362 void __iomem
*reg
= NULL
;
1363 struct fusb300
*fusb300
= NULL
;
1364 struct fusb300_ep
*_ep
[FUSB300_MAX_NUM_EP
];
1368 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1371 pr_err("platform_get_resource error.\n");
1375 ires
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1379 "platform_get_resource IORESOURCE_IRQ error.\n");
1383 ires1
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1387 "platform_get_resource IORESOURCE_IRQ 1 error.\n");
1391 reg
= ioremap(res
->start
, resource_size(res
));
1394 pr_err("ioremap error.\n");
1398 /* initialize udc */
1399 fusb300
= kzalloc(sizeof(struct fusb300
), GFP_KERNEL
);
1400 if (fusb300
== NULL
) {
1405 for (i
= 0; i
< FUSB300_MAX_NUM_EP
; i
++) {
1406 _ep
[i
] = kzalloc(sizeof(struct fusb300_ep
), GFP_KERNEL
);
1407 if (_ep
[i
] == NULL
) {
1411 fusb300
->ep
[i
] = _ep
[i
];
1414 spin_lock_init(&fusb300
->lock
);
1416 platform_set_drvdata(pdev
, fusb300
);
1418 fusb300
->gadget
.ops
= &fusb300_gadget_ops
;
1420 fusb300
->gadget
.max_speed
= USB_SPEED_HIGH
;
1421 fusb300
->gadget
.name
= udc_name
;
1424 ret
= request_irq(ires
->start
, fusb300_irq
, IRQF_SHARED
,
1427 pr_err("request_irq error (%d)\n", ret
);
1431 ret
= request_irq(ires1
->start
, fusb300_irq
,
1432 IRQF_SHARED
, udc_name
, fusb300
);
1434 pr_err("request_irq1 error (%d)\n", ret
);
1438 INIT_LIST_HEAD(&fusb300
->gadget
.ep_list
);
1440 for (i
= 0; i
< FUSB300_MAX_NUM_EP
; i
++) {
1441 struct fusb300_ep
*ep
= fusb300
->ep
[i
];
1444 INIT_LIST_HEAD(&fusb300
->ep
[i
]->ep
.ep_list
);
1445 list_add_tail(&fusb300
->ep
[i
]->ep
.ep_list
,
1446 &fusb300
->gadget
.ep_list
);
1448 ep
->fusb300
= fusb300
;
1449 INIT_LIST_HEAD(&ep
->queue
);
1450 ep
->ep
.name
= fusb300_ep_name
[i
];
1451 ep
->ep
.ops
= &fusb300_ep_ops
;
1452 usb_ep_set_maxpacket_limit(&ep
->ep
, HS_BULK_MAX_PACKET_SIZE
);
1455 ep
->ep
.caps
.type_control
= true;
1457 ep
->ep
.caps
.type_iso
= true;
1458 ep
->ep
.caps
.type_bulk
= true;
1459 ep
->ep
.caps
.type_int
= true;
1462 ep
->ep
.caps
.dir_in
= true;
1463 ep
->ep
.caps
.dir_out
= true;
1465 usb_ep_set_maxpacket_limit(&fusb300
->ep
[0]->ep
, HS_CTL_MAX_PACKET_SIZE
);
1466 fusb300
->ep
[0]->epnum
= 0;
1467 fusb300
->gadget
.ep0
= &fusb300
->ep
[0]->ep
;
1468 INIT_LIST_HEAD(&fusb300
->gadget
.ep0
->ep_list
);
1470 fusb300
->ep0_req
= fusb300_alloc_request(&fusb300
->ep
[0]->ep
,
1472 if (fusb300
->ep0_req
== NULL
) {
1477 init_controller(fusb300
);
1478 ret
= usb_add_gadget_udc(&pdev
->dev
, &fusb300
->gadget
);
1482 dev_info(&pdev
->dev
, "version %s\n", DRIVER_VERSION
);
1487 fusb300_free_request(&fusb300
->ep
[0]->ep
, fusb300
->ep0_req
);
1490 free_irq(ires
->start
, fusb300
);
1494 if (fusb300
->ep0_req
)
1495 fusb300_free_request(&fusb300
->ep
[0]->ep
,
1505 static struct platform_driver fusb300_driver
= {
1506 .remove
= fusb300_remove
,
1508 .name
= (char *) udc_name
,
1512 module_platform_driver_probe(fusb300_driver
, fusb300_probe
);