2 * R8A66597 UDC (USB gadget)
4 * Copyright (C) 2006-2009 Renesas Solutions Corp.
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.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 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <linux/platform_device.h>
29 #include <linux/usb/ch9.h>
30 #include <linux/usb/gadget.h>
32 #include "r8a66597-udc.h"
34 #define DRIVER_VERSION "2009-08-18"
36 static const char udc_name[] = "r8a66597_udc";
37 static const char *r8a66597_ep_name[] = {
38 "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7",
42 static void disable_controller(struct r8a66597 *r8a66597);
43 static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req);
44 static void irq_packet_write(struct r8a66597_ep *ep,
45 struct r8a66597_request *req);
46 static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req,
49 static void transfer_complete(struct r8a66597_ep *ep,
50 struct r8a66597_request *req, int status);
52 /*-------------------------------------------------------------------------*/
53 static inline u16 get_usb_speed(struct r8a66597 *r8a66597)
55 return r8a66597_read(r8a66597, DVSTCTR0) & RHST;
58 static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
63 tmp = r8a66597_read(r8a66597, INTENB0);
64 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE,
66 r8a66597_bset(r8a66597, (1 << pipenum), reg);
67 r8a66597_write(r8a66597, tmp, INTENB0);
70 static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
75 tmp = r8a66597_read(r8a66597, INTENB0);
76 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE,
78 r8a66597_bclr(r8a66597, (1 << pipenum), reg);
79 r8a66597_write(r8a66597, tmp, INTENB0);
82 static void r8a66597_usb_connect(struct r8a66597 *r8a66597)
84 r8a66597_bset(r8a66597, CTRE, INTENB0);
85 r8a66597_bset(r8a66597, BEMPE | BRDYE, INTENB0);
87 r8a66597_bset(r8a66597, DPRPU, SYSCFG0);
90 static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597)
91 __releases(r8a66597->lock)
92 __acquires(r8a66597->lock)
94 r8a66597_bclr(r8a66597, CTRE, INTENB0);
95 r8a66597_bclr(r8a66597, BEMPE | BRDYE, INTENB0);
96 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
98 r8a66597->gadget.speed = USB_SPEED_UNKNOWN;
99 spin_unlock(&r8a66597->lock);
100 r8a66597->driver->disconnect(&r8a66597->gadget);
101 spin_lock(&r8a66597->lock);
103 disable_controller(r8a66597);
104 INIT_LIST_HEAD(&r8a66597->ep[0].queue);
107 static inline u16 control_reg_get_pid(struct r8a66597 *r8a66597, u16 pipenum)
110 unsigned long offset;
113 pid = r8a66597_read(r8a66597, DCPCTR) & PID;
114 else if (pipenum < R8A66597_MAX_NUM_PIPE) {
115 offset = get_pipectr_addr(pipenum);
116 pid = r8a66597_read(r8a66597, offset) & PID;
118 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
123 static inline void control_reg_set_pid(struct r8a66597 *r8a66597, u16 pipenum,
126 unsigned long offset;
129 r8a66597_mdfy(r8a66597, pid, PID, DCPCTR);
130 else if (pipenum < R8A66597_MAX_NUM_PIPE) {
131 offset = get_pipectr_addr(pipenum);
132 r8a66597_mdfy(r8a66597, pid, PID, offset);
134 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
137 static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum)
139 control_reg_set_pid(r8a66597, pipenum, PID_BUF);
142 static inline void pipe_stop(struct r8a66597 *r8a66597, u16 pipenum)
144 control_reg_set_pid(r8a66597, pipenum, PID_NAK);
147 static inline void pipe_stall(struct r8a66597 *r8a66597, u16 pipenum)
149 control_reg_set_pid(r8a66597, pipenum, PID_STALL);
152 static inline u16 control_reg_get(struct r8a66597 *r8a66597, u16 pipenum)
155 unsigned long offset;
158 ret = r8a66597_read(r8a66597, DCPCTR);
159 else if (pipenum < R8A66597_MAX_NUM_PIPE) {
160 offset = get_pipectr_addr(pipenum);
161 ret = r8a66597_read(r8a66597, offset);
163 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
168 static inline void control_reg_sqclr(struct r8a66597 *r8a66597, u16 pipenum)
170 unsigned long offset;
172 pipe_stop(r8a66597, pipenum);
175 r8a66597_bset(r8a66597, SQCLR, DCPCTR);
176 else if (pipenum < R8A66597_MAX_NUM_PIPE) {
177 offset = get_pipectr_addr(pipenum);
178 r8a66597_bset(r8a66597, SQCLR, offset);
180 printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum);
183 static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum)
189 tmp = r8a66597_read(r8a66597, DCPCFG);
190 if ((tmp & R8A66597_CNTMD) != 0)
193 tmp = r8a66597_read(r8a66597, DCPMAXP);
197 r8a66597_write(r8a66597, pipenum, PIPESEL);
198 tmp = r8a66597_read(r8a66597, PIPECFG);
199 if ((tmp & R8A66597_CNTMD) != 0) {
200 tmp = r8a66597_read(r8a66597, PIPEBUF);
201 size = ((tmp >> 10) + 1) * 64;
203 tmp = r8a66597_read(r8a66597, PIPEMAXP);
211 static inline unsigned short mbw_value(struct r8a66597 *r8a66597)
213 if (r8a66597->pdata->on_chip)
219 static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum)
221 struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum];
226 r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel);
230 r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel);
233 static int pipe_buffer_setting(struct r8a66597 *r8a66597,
234 struct r8a66597_pipe_info *info)
236 u16 bufnum = 0, buf_bsize = 0;
242 r8a66597_write(r8a66597, info->pipe, PIPESEL);
245 pipecfg |= R8A66597_DIR;
246 pipecfg |= info->type;
247 pipecfg |= info->epnum;
248 switch (info->type) {
250 bufnum = 4 + (info->pipe - R8A66597_BASE_PIPENUM_INT);
254 bufnum = r8a66597->bi_bufnum +
255 (info->pipe - R8A66597_BASE_PIPENUM_BULK) * 16;
256 r8a66597->bi_bufnum += 16;
258 pipecfg |= R8A66597_DBLB;
260 pipecfg |= R8A66597_SHTNAK;
263 bufnum = r8a66597->bi_bufnum +
264 (info->pipe - R8A66597_BASE_PIPENUM_ISOC) * 16;
265 r8a66597->bi_bufnum += 16;
269 if (r8a66597->bi_bufnum > R8A66597_MAX_BUFNUM) {
270 printk(KERN_ERR "r8a66597 pipe memory is insufficient(%d)\n",
271 r8a66597->bi_bufnum);
275 r8a66597_write(r8a66597, pipecfg, PIPECFG);
276 r8a66597_write(r8a66597, (buf_bsize << 10) | (bufnum), PIPEBUF);
277 r8a66597_write(r8a66597, info->maxpacket, PIPEMAXP);
280 r8a66597_write(r8a66597, info->interval, PIPEPERI);
285 static void pipe_buffer_release(struct r8a66597 *r8a66597,
286 struct r8a66597_pipe_info *info)
291 switch (info->type) {
293 if (is_bulk_pipe(info->pipe))
294 r8a66597->bi_bufnum -= 16;
297 if (is_isoc_pipe(info->pipe))
298 r8a66597->bi_bufnum -= 16;
302 if (is_bulk_pipe(info->pipe))
304 else if (is_interrupt_pipe(info->pipe))
305 r8a66597->interrupt--;
306 else if (is_isoc_pipe(info->pipe)) {
307 r8a66597->isochronous--;
308 if (info->type == R8A66597_BULK)
311 printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n",
315 static void pipe_initialize(struct r8a66597_ep *ep)
317 struct r8a66597 *r8a66597 = ep->r8a66597;
319 r8a66597_mdfy(r8a66597, 0, CURPIPE, ep->fifosel);
321 r8a66597_write(r8a66597, ACLRM, ep->pipectr);
322 r8a66597_write(r8a66597, 0, ep->pipectr);
323 r8a66597_write(r8a66597, SQCLR, ep->pipectr);
325 r8a66597_mdfy(r8a66597, ep->pipenum, CURPIPE, ep->fifosel);
329 r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel);
333 static void r8a66597_ep_setting(struct r8a66597 *r8a66597,
334 struct r8a66597_ep *ep,
335 const struct usb_endpoint_descriptor *desc,
336 u16 pipenum, int dma)
339 ep->fifoaddr = CFIFO;
340 ep->fifosel = CFIFOSEL;
341 ep->fifoctr = CFIFOCTR;
344 ep->pipectr = get_pipectr_addr(pipenum);
345 ep->pipenum = pipenum;
346 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
347 r8a66597->pipenum2ep[pipenum] = ep;
348 r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK]
350 INIT_LIST_HEAD(&ep->queue);
353 static void r8a66597_ep_release(struct r8a66597_ep *ep)
355 struct r8a66597 *r8a66597 = ep->r8a66597;
356 u16 pipenum = ep->pipenum;
368 static int alloc_pipe_config(struct r8a66597_ep *ep,
369 const struct usb_endpoint_descriptor *desc)
371 struct r8a66597 *r8a66597 = ep->r8a66597;
372 struct r8a66597_pipe_info info;
374 unsigned char *counter;
379 if (ep->pipenum) /* already allocated pipe */
382 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
383 case USB_ENDPOINT_XFER_BULK:
384 if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) {
385 if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) {
386 printk(KERN_ERR "bulk pipe is insufficient\n");
389 info.pipe = R8A66597_BASE_PIPENUM_ISOC
390 + r8a66597->isochronous;
391 counter = &r8a66597->isochronous;
394 info.pipe = R8A66597_BASE_PIPENUM_BULK + r8a66597->bulk;
395 counter = &r8a66597->bulk;
397 info.type = R8A66597_BULK;
400 case USB_ENDPOINT_XFER_INT:
401 if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) {
402 printk(KERN_ERR "interrupt pipe is insufficient\n");
405 info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt;
406 info.type = R8A66597_INT;
407 counter = &r8a66597->interrupt;
409 case USB_ENDPOINT_XFER_ISOC:
410 if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) {
411 printk(KERN_ERR "isochronous pipe is insufficient\n");
414 info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous;
415 info.type = R8A66597_ISO;
416 counter = &r8a66597->isochronous;
419 printk(KERN_ERR "unexpect xfer type\n");
422 ep->type = info.type;
424 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
425 info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
426 info.interval = desc->bInterval;
427 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
432 ret = pipe_buffer_setting(r8a66597, &info);
434 printk(KERN_ERR "pipe_buffer_setting fail\n");
439 if ((counter == &r8a66597->isochronous) && info.type == R8A66597_BULK)
442 r8a66597_ep_setting(r8a66597, ep, desc, info.pipe, dma);
448 static int free_pipe_config(struct r8a66597_ep *ep)
450 struct r8a66597 *r8a66597 = ep->r8a66597;
451 struct r8a66597_pipe_info info;
453 info.pipe = ep->pipenum;
454 info.type = ep->type;
455 pipe_buffer_release(r8a66597, &info);
456 r8a66597_ep_release(ep);
461 /*-------------------------------------------------------------------------*/
462 static void pipe_irq_enable(struct r8a66597 *r8a66597, u16 pipenum)
464 enable_irq_ready(r8a66597, pipenum);
465 enable_irq_nrdy(r8a66597, pipenum);
468 static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
470 disable_irq_ready(r8a66597, pipenum);
471 disable_irq_nrdy(r8a66597, pipenum);
474 /* if complete is true, gadget driver complete function is not call */
475 static void control_end(struct r8a66597 *r8a66597, unsigned ccpl)
477 r8a66597->ep[0].internal_ccpl = ccpl;
478 pipe_start(r8a66597, 0);
479 r8a66597_bset(r8a66597, CCPL, DCPCTR);
482 static void start_ep0_write(struct r8a66597_ep *ep,
483 struct r8a66597_request *req)
485 struct r8a66597 *r8a66597 = ep->r8a66597;
487 pipe_change(r8a66597, ep->pipenum);
488 r8a66597_mdfy(r8a66597, ISEL, (ISEL | CURPIPE), CFIFOSEL);
489 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
490 if (req->req.length == 0) {
491 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
492 pipe_start(r8a66597, 0);
493 transfer_complete(ep, req, 0);
495 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
496 irq_ep0_write(ep, req);
500 static void start_packet_write(struct r8a66597_ep *ep,
501 struct r8a66597_request *req)
503 struct r8a66597 *r8a66597 = ep->r8a66597;
506 pipe_change(r8a66597, ep->pipenum);
507 disable_irq_empty(r8a66597, ep->pipenum);
508 pipe_start(r8a66597, ep->pipenum);
510 tmp = r8a66597_read(r8a66597, ep->fifoctr);
511 if (unlikely((tmp & FRDY) == 0))
512 pipe_irq_enable(r8a66597, ep->pipenum);
514 irq_packet_write(ep, req);
517 static void start_packet_read(struct r8a66597_ep *ep,
518 struct r8a66597_request *req)
520 struct r8a66597 *r8a66597 = ep->r8a66597;
521 u16 pipenum = ep->pipenum;
523 if (ep->pipenum == 0) {
524 r8a66597_mdfy(r8a66597, 0, (ISEL | CURPIPE), CFIFOSEL);
525 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
526 pipe_start(r8a66597, pipenum);
527 pipe_irq_enable(r8a66597, pipenum);
530 r8a66597_bset(r8a66597, TRCLR, ep->fifosel);
531 pipe_change(r8a66597, pipenum);
532 r8a66597_bset(r8a66597, TRENB, ep->fifosel);
533 r8a66597_write(r8a66597,
534 (req->req.length + ep->ep.maxpacket - 1)
538 pipe_start(r8a66597, pipenum); /* trigger once */
539 pipe_irq_enable(r8a66597, pipenum);
543 static void start_packet(struct r8a66597_ep *ep, struct r8a66597_request *req)
545 if (ep->desc->bEndpointAddress & USB_DIR_IN)
546 start_packet_write(ep, req);
548 start_packet_read(ep, req);
551 static void start_ep0(struct r8a66597_ep *ep, struct r8a66597_request *req)
555 ctsq = r8a66597_read(ep->r8a66597, INTSTS0) & CTSQ;
559 start_ep0_write(ep, req);
562 start_packet_read(ep, req);
566 control_end(ep->r8a66597, 0);
569 printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq);
574 static void init_controller(struct r8a66597 *r8a66597)
576 u16 vif = r8a66597->pdata->vif ? LDRV : 0;
577 u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0;
578 u16 endian = r8a66597->pdata->endian ? BIGEND : 0;
580 if (r8a66597->pdata->on_chip) {
581 r8a66597_bset(r8a66597, 0x04, SYSCFG1);
582 r8a66597_bset(r8a66597, HSE, SYSCFG0);
584 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
585 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
586 r8a66597_bset(r8a66597, USBE, SYSCFG0);
588 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
590 r8a66597_bset(r8a66597, irq_sense, INTENB1);
591 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR,
594 r8a66597_bset(r8a66597, vif | endian, PINCFG);
595 r8a66597_bset(r8a66597, HSE, SYSCFG0); /* High spd */
596 r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata),
599 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
600 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
601 r8a66597_bset(r8a66597, USBE, SYSCFG0);
603 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
607 r8a66597_bset(r8a66597, PLLC, SYSCFG0);
611 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
613 r8a66597_bset(r8a66597, irq_sense, INTENB1);
614 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR,
619 static void disable_controller(struct r8a66597 *r8a66597)
621 if (r8a66597->pdata->on_chip) {
622 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
624 r8a66597_write(r8a66597, 0, INTENB0);
625 r8a66597_write(r8a66597, 0, INTENB1);
627 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
628 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
631 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
633 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
636 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
640 static void r8a66597_start_xclock(struct r8a66597 *r8a66597)
644 if (!r8a66597->pdata->on_chip) {
645 tmp = r8a66597_read(r8a66597, SYSCFG0);
647 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
651 static struct r8a66597_request *get_request_from_ep(struct r8a66597_ep *ep)
653 return list_entry(ep->queue.next, struct r8a66597_request, queue);
656 /*-------------------------------------------------------------------------*/
657 static void transfer_complete(struct r8a66597_ep *ep,
658 struct r8a66597_request *req, int status)
659 __releases(r8a66597->lock)
660 __acquires(r8a66597->lock)
664 if (unlikely(ep->pipenum == 0)) {
665 if (ep->internal_ccpl) {
666 ep->internal_ccpl = 0;
671 list_del_init(&req->queue);
672 if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
673 req->req.status = -ESHUTDOWN;
675 req->req.status = status;
677 if (!list_empty(&ep->queue))
680 spin_unlock(&ep->r8a66597->lock);
681 req->req.complete(&ep->ep, &req->req);
682 spin_lock(&ep->r8a66597->lock);
685 req = get_request_from_ep(ep);
687 start_packet(ep, req);
691 static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req)
698 u16 pipenum = ep->pipenum;
699 struct r8a66597 *r8a66597 = ep->r8a66597;
701 pipe_change(r8a66597, pipenum);
702 r8a66597_bset(r8a66597, ISEL, ep->fifosel);
706 tmp = r8a66597_read(r8a66597, ep->fifoctr);
708 printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus"
709 "conflict. please power off this controller.");
713 } while ((tmp & FRDY) == 0);
715 /* prepare parameters */
716 bufsize = get_buffer_size(r8a66597, pipenum);
717 buf = req->req.buf + req->req.actual;
718 size = min(bufsize, req->req.length - req->req.actual);
723 r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size);
724 if ((size == 0) || ((size % ep->ep.maxpacket) != 0))
725 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
728 /* update parameters */
729 req->req.actual += size;
731 /* check transfer finish */
732 if ((!req->req.zero && (req->req.actual == req->req.length))
733 || (size % ep->ep.maxpacket)
735 disable_irq_ready(r8a66597, pipenum);
736 disable_irq_empty(r8a66597, pipenum);
738 disable_irq_ready(r8a66597, pipenum);
739 enable_irq_empty(r8a66597, pipenum);
741 pipe_start(r8a66597, pipenum);
744 static void irq_packet_write(struct r8a66597_ep *ep,
745 struct r8a66597_request *req)
751 u16 pipenum = ep->pipenum;
752 struct r8a66597 *r8a66597 = ep->r8a66597;
754 pipe_change(r8a66597, pipenum);
755 tmp = r8a66597_read(r8a66597, ep->fifoctr);
756 if (unlikely((tmp & FRDY) == 0)) {
757 pipe_stop(r8a66597, pipenum);
758 pipe_irq_disable(r8a66597, pipenum);
759 printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum);
763 /* prepare parameters */
764 bufsize = get_buffer_size(r8a66597, pipenum);
765 buf = req->req.buf + req->req.actual;
766 size = min(bufsize, req->req.length - req->req.actual);
770 r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size);
772 || ((size % ep->ep.maxpacket) != 0)
773 || ((bufsize != ep->ep.maxpacket)
774 && (bufsize > size)))
775 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
778 /* update parameters */
779 req->req.actual += size;
780 /* check transfer finish */
781 if ((!req->req.zero && (req->req.actual == req->req.length))
782 || (size % ep->ep.maxpacket)
784 disable_irq_ready(r8a66597, pipenum);
785 enable_irq_empty(r8a66597, pipenum);
787 disable_irq_empty(r8a66597, pipenum);
788 pipe_irq_enable(r8a66597, pipenum);
792 static void irq_packet_read(struct r8a66597_ep *ep,
793 struct r8a66597_request *req)
796 int rcv_len, bufsize, req_len;
799 u16 pipenum = ep->pipenum;
800 struct r8a66597 *r8a66597 = ep->r8a66597;
803 pipe_change(r8a66597, pipenum);
804 tmp = r8a66597_read(r8a66597, ep->fifoctr);
805 if (unlikely((tmp & FRDY) == 0)) {
806 req->req.status = -EPIPE;
807 pipe_stop(r8a66597, pipenum);
808 pipe_irq_disable(r8a66597, pipenum);
809 printk(KERN_ERR "read fifo not ready");
813 /* prepare parameters */
814 rcv_len = tmp & DTLN;
815 bufsize = get_buffer_size(r8a66597, pipenum);
817 buf = req->req.buf + req->req.actual;
818 req_len = req->req.length - req->req.actual;
819 if (rcv_len < bufsize)
820 size = min(rcv_len, req_len);
822 size = min(bufsize, req_len);
824 /* update parameters */
825 req->req.actual += size;
827 /* check transfer finish */
828 if ((!req->req.zero && (req->req.actual == req->req.length))
829 || (size % ep->ep.maxpacket)
831 pipe_stop(r8a66597, pipenum);
832 pipe_irq_disable(r8a66597, pipenum);
839 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
841 r8a66597_read_fifo(r8a66597, ep->fifoaddr, buf, size);
845 if ((ep->pipenum != 0) && finish)
846 transfer_complete(ep, req, 0);
849 static void irq_pipe_ready(struct r8a66597 *r8a66597, u16 status, u16 enb)
853 struct r8a66597_ep *ep;
854 struct r8a66597_request *req;
856 if ((status & BRDY0) && (enb & BRDY0)) {
857 r8a66597_write(r8a66597, ~BRDY0, BRDYSTS);
858 r8a66597_mdfy(r8a66597, 0, CURPIPE, CFIFOSEL);
860 ep = &r8a66597->ep[0];
861 req = get_request_from_ep(ep);
862 irq_packet_read(ep, req);
864 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
865 check = 1 << pipenum;
866 if ((status & check) && (enb & check)) {
867 r8a66597_write(r8a66597, ~check, BRDYSTS);
868 ep = r8a66597->pipenum2ep[pipenum];
869 req = get_request_from_ep(ep);
870 if (ep->desc->bEndpointAddress & USB_DIR_IN)
871 irq_packet_write(ep, req);
873 irq_packet_read(ep, req);
879 static void irq_pipe_empty(struct r8a66597 *r8a66597, u16 status, u16 enb)
884 struct r8a66597_ep *ep;
885 struct r8a66597_request *req;
887 if ((status & BEMP0) && (enb & BEMP0)) {
888 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
890 ep = &r8a66597->ep[0];
891 req = get_request_from_ep(ep);
892 irq_ep0_write(ep, req);
894 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
895 check = 1 << pipenum;
896 if ((status & check) && (enb & check)) {
897 r8a66597_write(r8a66597, ~check, BEMPSTS);
898 tmp = control_reg_get(r8a66597, pipenum);
899 if ((tmp & INBUFM) == 0) {
900 disable_irq_empty(r8a66597, pipenum);
901 pipe_irq_disable(r8a66597, pipenum);
902 pipe_stop(r8a66597, pipenum);
903 ep = r8a66597->pipenum2ep[pipenum];
904 req = get_request_from_ep(ep);
905 if (!list_empty(&ep->queue))
906 transfer_complete(ep, req, 0);
913 static void get_status(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
914 __releases(r8a66597->lock)
915 __acquires(r8a66597->lock)
917 struct r8a66597_ep *ep;
920 u16 w_index = le16_to_cpu(ctrl->wIndex);
922 switch (ctrl->bRequestType & USB_RECIP_MASK) {
923 case USB_RECIP_DEVICE:
924 status = 1 << USB_DEVICE_SELF_POWERED;
926 case USB_RECIP_INTERFACE:
929 case USB_RECIP_ENDPOINT:
930 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
931 pid = control_reg_get_pid(r8a66597, ep->pipenum);
932 if (pid == PID_STALL)
933 status = 1 << USB_ENDPOINT_HALT;
938 pipe_stall(r8a66597, 0);
942 r8a66597->ep0_data = cpu_to_le16(status);
943 r8a66597->ep0_req->buf = &r8a66597->ep0_data;
944 r8a66597->ep0_req->length = 2;
945 /* AV: what happens if we get called again before that gets through? */
946 spin_unlock(&r8a66597->lock);
947 r8a66597_queue(r8a66597->gadget.ep0, r8a66597->ep0_req, GFP_KERNEL);
948 spin_lock(&r8a66597->lock);
951 static void clear_feature(struct r8a66597 *r8a66597,
952 struct usb_ctrlrequest *ctrl)
954 switch (ctrl->bRequestType & USB_RECIP_MASK) {
955 case USB_RECIP_DEVICE:
956 control_end(r8a66597, 1);
958 case USB_RECIP_INTERFACE:
959 control_end(r8a66597, 1);
961 case USB_RECIP_ENDPOINT: {
962 struct r8a66597_ep *ep;
963 struct r8a66597_request *req;
964 u16 w_index = le16_to_cpu(ctrl->wIndex);
966 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
967 pipe_stop(r8a66597, ep->pipenum);
968 control_reg_sqclr(r8a66597, ep->pipenum);
970 control_end(r8a66597, 1);
972 req = get_request_from_ep(ep);
975 if (list_empty(&ep->queue))
977 start_packet(ep, req);
978 } else if (!list_empty(&ep->queue))
979 pipe_start(r8a66597, ep->pipenum);
983 pipe_stall(r8a66597, 0);
988 static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
991 switch (ctrl->bRequestType & USB_RECIP_MASK) {
992 case USB_RECIP_DEVICE:
993 control_end(r8a66597, 1);
995 case USB_RECIP_INTERFACE:
996 control_end(r8a66597, 1);
998 case USB_RECIP_ENDPOINT: {
999 struct r8a66597_ep *ep;
1000 u16 w_index = le16_to_cpu(ctrl->wIndex);
1002 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
1003 pipe_stall(r8a66597, ep->pipenum);
1005 control_end(r8a66597, 1);
1009 pipe_stall(r8a66597, 0);
1014 /* if return value is true, call class driver's setup() */
1015 static int setup_packet(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
1017 u16 *p = (u16 *)ctrl;
1018 unsigned long offset = USBREQ;
1022 r8a66597_write(r8a66597, ~VALID, INTSTS0);
1024 for (i = 0; i < 4; i++)
1025 p[i] = r8a66597_read(r8a66597, offset + i*2);
1028 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1029 switch (ctrl->bRequest) {
1030 case USB_REQ_GET_STATUS:
1031 get_status(r8a66597, ctrl);
1033 case USB_REQ_CLEAR_FEATURE:
1034 clear_feature(r8a66597, ctrl);
1036 case USB_REQ_SET_FEATURE:
1037 set_feature(r8a66597, ctrl);
1048 static void r8a66597_update_usb_speed(struct r8a66597 *r8a66597)
1050 u16 speed = get_usb_speed(r8a66597);
1054 r8a66597->gadget.speed = USB_SPEED_HIGH;
1057 r8a66597->gadget.speed = USB_SPEED_FULL;
1060 r8a66597->gadget.speed = USB_SPEED_UNKNOWN;
1061 printk(KERN_ERR "USB speed unknown\n");
1065 static void irq_device_state(struct r8a66597 *r8a66597)
1069 dvsq = r8a66597_read(r8a66597, INTSTS0) & DVSQ;
1070 r8a66597_write(r8a66597, ~DVST, INTSTS0);
1072 if (dvsq == DS_DFLT) {
1074 r8a66597->driver->disconnect(&r8a66597->gadget);
1075 r8a66597_update_usb_speed(r8a66597);
1077 if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG)
1078 r8a66597_update_usb_speed(r8a66597);
1079 if ((dvsq == DS_CNFG || dvsq == DS_ADDS)
1080 && r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
1081 r8a66597_update_usb_speed(r8a66597);
1083 r8a66597->old_dvsq = dvsq;
1086 static void irq_control_stage(struct r8a66597 *r8a66597)
1087 __releases(r8a66597->lock)
1088 __acquires(r8a66597->lock)
1090 struct usb_ctrlrequest ctrl;
1093 ctsq = r8a66597_read(r8a66597, INTSTS0) & CTSQ;
1094 r8a66597_write(r8a66597, ~CTRT, INTSTS0);
1098 struct r8a66597_ep *ep;
1099 struct r8a66597_request *req;
1100 ep = &r8a66597->ep[0];
1101 req = get_request_from_ep(ep);
1102 transfer_complete(ep, req, 0);
1109 if (setup_packet(r8a66597, &ctrl)) {
1110 spin_unlock(&r8a66597->lock);
1111 if (r8a66597->driver->setup(&r8a66597->gadget, &ctrl)
1113 pipe_stall(r8a66597, 0);
1114 spin_lock(&r8a66597->lock);
1119 control_end(r8a66597, 0);
1122 printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq);
1127 static irqreturn_t r8a66597_irq(int irq, void *_r8a66597)
1129 struct r8a66597 *r8a66597 = _r8a66597;
1132 u16 brdysts, nrdysts, bempsts;
1133 u16 brdyenb, nrdyenb, bempenb;
1137 spin_lock(&r8a66597->lock);
1139 intsts0 = r8a66597_read(r8a66597, INTSTS0);
1140 intenb0 = r8a66597_read(r8a66597, INTENB0);
1142 savepipe = r8a66597_read(r8a66597, CFIFOSEL);
1144 mask0 = intsts0 & intenb0;
1146 brdysts = r8a66597_read(r8a66597, BRDYSTS);
1147 nrdysts = r8a66597_read(r8a66597, NRDYSTS);
1148 bempsts = r8a66597_read(r8a66597, BEMPSTS);
1149 brdyenb = r8a66597_read(r8a66597, BRDYENB);
1150 nrdyenb = r8a66597_read(r8a66597, NRDYENB);
1151 bempenb = r8a66597_read(r8a66597, BEMPENB);
1153 if (mask0 & VBINT) {
1154 r8a66597_write(r8a66597, 0xffff & ~VBINT,
1156 r8a66597_start_xclock(r8a66597);
1158 /* start vbus sampling */
1159 r8a66597->old_vbus = r8a66597_read(r8a66597, INTSTS0)
1161 r8a66597->scount = R8A66597_MAX_SAMPLING;
1163 mod_timer(&r8a66597->timer,
1164 jiffies + msecs_to_jiffies(50));
1167 irq_device_state(r8a66597);
1169 if ((intsts0 & BRDY) && (intenb0 & BRDYE)
1170 && (brdysts & brdyenb))
1171 irq_pipe_ready(r8a66597, brdysts, brdyenb);
1172 if ((intsts0 & BEMP) && (intenb0 & BEMPE)
1173 && (bempsts & bempenb))
1174 irq_pipe_empty(r8a66597, bempsts, bempenb);
1177 irq_control_stage(r8a66597);
1180 r8a66597_write(r8a66597, savepipe, CFIFOSEL);
1182 spin_unlock(&r8a66597->lock);
1186 static void r8a66597_timer(unsigned long _r8a66597)
1188 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1189 unsigned long flags;
1192 spin_lock_irqsave(&r8a66597->lock, flags);
1193 tmp = r8a66597_read(r8a66597, SYSCFG0);
1194 if (r8a66597->scount > 0) {
1195 tmp = r8a66597_read(r8a66597, INTSTS0) & VBSTS;
1196 if (tmp == r8a66597->old_vbus) {
1198 if (r8a66597->scount == 0) {
1200 r8a66597_usb_connect(r8a66597);
1202 r8a66597_usb_disconnect(r8a66597);
1204 mod_timer(&r8a66597->timer,
1205 jiffies + msecs_to_jiffies(50));
1208 r8a66597->scount = R8A66597_MAX_SAMPLING;
1209 r8a66597->old_vbus = tmp;
1210 mod_timer(&r8a66597->timer,
1211 jiffies + msecs_to_jiffies(50));
1214 spin_unlock_irqrestore(&r8a66597->lock, flags);
1217 /*-------------------------------------------------------------------------*/
1218 static int r8a66597_enable(struct usb_ep *_ep,
1219 const struct usb_endpoint_descriptor *desc)
1221 struct r8a66597_ep *ep;
1223 ep = container_of(_ep, struct r8a66597_ep, ep);
1224 return alloc_pipe_config(ep, desc);
1227 static int r8a66597_disable(struct usb_ep *_ep)
1229 struct r8a66597_ep *ep;
1230 struct r8a66597_request *req;
1231 unsigned long flags;
1233 ep = container_of(_ep, struct r8a66597_ep, ep);
1236 while (!list_empty(&ep->queue)) {
1237 req = get_request_from_ep(ep);
1238 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1239 transfer_complete(ep, req, -ECONNRESET);
1240 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1243 pipe_irq_disable(ep->r8a66597, ep->pipenum);
1244 return free_pipe_config(ep);
1247 static struct usb_request *r8a66597_alloc_request(struct usb_ep *_ep,
1250 struct r8a66597_request *req;
1252 req = kzalloc(sizeof(struct r8a66597_request), gfp_flags);
1256 INIT_LIST_HEAD(&req->queue);
1261 static void r8a66597_free_request(struct usb_ep *_ep, struct usb_request *_req)
1263 struct r8a66597_request *req;
1265 req = container_of(_req, struct r8a66597_request, req);
1269 static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req,
1272 struct r8a66597_ep *ep;
1273 struct r8a66597_request *req;
1274 unsigned long flags;
1277 ep = container_of(_ep, struct r8a66597_ep, ep);
1278 req = container_of(_req, struct r8a66597_request, req);
1280 if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
1283 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1285 if (list_empty(&ep->queue))
1288 list_add_tail(&req->queue, &ep->queue);
1289 req->req.actual = 0;
1290 req->req.status = -EINPROGRESS;
1292 if (ep->desc == NULL) /* control */
1295 if (request && !ep->busy)
1296 start_packet(ep, req);
1299 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1304 static int r8a66597_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1306 struct r8a66597_ep *ep;
1307 struct r8a66597_request *req;
1308 unsigned long flags;
1310 ep = container_of(_ep, struct r8a66597_ep, ep);
1311 req = container_of(_req, struct r8a66597_request, req);
1313 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1314 if (!list_empty(&ep->queue))
1315 transfer_complete(ep, req, -ECONNRESET);
1316 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1321 static int r8a66597_set_halt(struct usb_ep *_ep, int value)
1323 struct r8a66597_ep *ep;
1324 struct r8a66597_request *req;
1325 unsigned long flags;
1328 ep = container_of(_ep, struct r8a66597_ep, ep);
1329 req = get_request_from_ep(ep);
1331 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1332 if (!list_empty(&ep->queue)) {
1338 pipe_stall(ep->r8a66597, ep->pipenum);
1341 pipe_stop(ep->r8a66597, ep->pipenum);
1345 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1349 static void r8a66597_fifo_flush(struct usb_ep *_ep)
1351 struct r8a66597_ep *ep;
1352 unsigned long flags;
1354 ep = container_of(_ep, struct r8a66597_ep, ep);
1355 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1356 if (list_empty(&ep->queue) && !ep->busy) {
1357 pipe_stop(ep->r8a66597, ep->pipenum);
1358 r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr);
1360 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1363 static struct usb_ep_ops r8a66597_ep_ops = {
1364 .enable = r8a66597_enable,
1365 .disable = r8a66597_disable,
1367 .alloc_request = r8a66597_alloc_request,
1368 .free_request = r8a66597_free_request,
1370 .queue = r8a66597_queue,
1371 .dequeue = r8a66597_dequeue,
1373 .set_halt = r8a66597_set_halt,
1374 .fifo_flush = r8a66597_fifo_flush,
1377 /*-------------------------------------------------------------------------*/
1378 static struct r8a66597 *the_controller;
1380 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1382 struct r8a66597 *r8a66597 = the_controller;
1386 || driver->speed != USB_SPEED_HIGH
1392 if (r8a66597->driver)
1395 /* hook up the driver */
1396 driver->driver.bus = NULL;
1397 r8a66597->driver = driver;
1398 r8a66597->gadget.dev.driver = &driver->driver;
1400 retval = device_add(&r8a66597->gadget.dev);
1402 printk(KERN_ERR "device_add error (%d)\n", retval);
1406 retval = driver->bind(&r8a66597->gadget);
1408 printk(KERN_ERR "bind to driver error (%d)\n", retval);
1409 device_del(&r8a66597->gadget.dev);
1413 r8a66597_bset(r8a66597, VBSE, INTENB0);
1414 if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) {
1415 r8a66597_start_xclock(r8a66597);
1416 /* start vbus sampling */
1417 r8a66597->old_vbus = r8a66597_read(r8a66597,
1419 r8a66597->scount = R8A66597_MAX_SAMPLING;
1420 mod_timer(&r8a66597->timer, jiffies + msecs_to_jiffies(50));
1426 r8a66597->driver = NULL;
1427 r8a66597->gadget.dev.driver = NULL;
1431 EXPORT_SYMBOL(usb_gadget_register_driver);
1433 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1435 struct r8a66597 *r8a66597 = the_controller;
1436 unsigned long flags;
1438 if (driver != r8a66597->driver || !driver->unbind)
1441 spin_lock_irqsave(&r8a66597->lock, flags);
1442 if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN)
1443 r8a66597_usb_disconnect(r8a66597);
1444 spin_unlock_irqrestore(&r8a66597->lock, flags);
1446 r8a66597_bclr(r8a66597, VBSE, INTENB0);
1448 driver->unbind(&r8a66597->gadget);
1450 init_controller(r8a66597);
1451 disable_controller(r8a66597);
1453 device_del(&r8a66597->gadget.dev);
1454 r8a66597->driver = NULL;
1457 EXPORT_SYMBOL(usb_gadget_unregister_driver);
1459 /*-------------------------------------------------------------------------*/
1460 static int r8a66597_get_frame(struct usb_gadget *_gadget)
1462 struct r8a66597 *r8a66597 = gadget_to_r8a66597(_gadget);
1463 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
1466 static struct usb_gadget_ops r8a66597_gadget_ops = {
1467 .get_frame = r8a66597_get_frame,
1470 static int __exit r8a66597_remove(struct platform_device *pdev)
1472 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
1474 del_timer_sync(&r8a66597->timer);
1475 iounmap((void *)r8a66597->reg);
1476 free_irq(platform_get_irq(pdev, 0), r8a66597);
1477 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
1482 static void nop_completion(struct usb_ep *ep, struct usb_request *r)
1486 static int __init r8a66597_probe(struct platform_device *pdev)
1488 struct resource *res, *ires;
1490 void __iomem *reg = NULL;
1491 struct r8a66597 *r8a66597 = NULL;
1494 unsigned long irq_trigger;
1496 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1499 printk(KERN_ERR "platform_get_resource error.\n");
1503 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1505 irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
1509 printk(KERN_ERR "platform_get_irq error.\n");
1513 reg = ioremap(res->start, resource_size(res));
1516 printk(KERN_ERR "ioremap error.\n");
1520 /* initialize ucd */
1521 r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL);
1522 if (r8a66597 == NULL) {
1523 printk(KERN_ERR "kzalloc error\n");
1527 spin_lock_init(&r8a66597->lock);
1528 dev_set_drvdata(&pdev->dev, r8a66597);
1529 r8a66597->pdata = pdev->dev.platform_data;
1530 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1532 r8a66597->gadget.ops = &r8a66597_gadget_ops;
1533 device_initialize(&r8a66597->gadget.dev);
1534 dev_set_name(&r8a66597->gadget.dev, "gadget");
1535 r8a66597->gadget.is_dualspeed = 1;
1536 r8a66597->gadget.dev.parent = &pdev->dev;
1537 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask;
1538 r8a66597->gadget.dev.release = pdev->dev.release;
1539 r8a66597->gadget.name = udc_name;
1541 init_timer(&r8a66597->timer);
1542 r8a66597->timer.function = r8a66597_timer;
1543 r8a66597->timer.data = (unsigned long)r8a66597;
1544 r8a66597->reg = (unsigned long)reg;
1546 r8a66597->bi_bufnum = R8A66597_BASE_BUFNUM;
1548 disable_controller(r8a66597); /* make sure controller is disabled */
1550 ret = request_irq(irq, r8a66597_irq, IRQF_DISABLED | IRQF_SHARED,
1551 udc_name, r8a66597);
1553 printk(KERN_ERR "request_irq error (%d)\n", ret);
1557 INIT_LIST_HEAD(&r8a66597->gadget.ep_list);
1558 r8a66597->gadget.ep0 = &r8a66597->ep[0].ep;
1559 INIT_LIST_HEAD(&r8a66597->gadget.ep0->ep_list);
1560 for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
1561 struct r8a66597_ep *ep = &r8a66597->ep[i];
1564 INIT_LIST_HEAD(&r8a66597->ep[i].ep.ep_list);
1565 list_add_tail(&r8a66597->ep[i].ep.ep_list,
1566 &r8a66597->gadget.ep_list);
1568 ep->r8a66597 = r8a66597;
1569 INIT_LIST_HEAD(&ep->queue);
1570 ep->ep.name = r8a66597_ep_name[i];
1571 ep->ep.ops = &r8a66597_ep_ops;
1572 ep->ep.maxpacket = 512;
1574 r8a66597->ep[0].ep.maxpacket = 64;
1575 r8a66597->ep[0].pipenum = 0;
1576 r8a66597->ep[0].fifoaddr = CFIFO;
1577 r8a66597->ep[0].fifosel = CFIFOSEL;
1578 r8a66597->ep[0].fifoctr = CFIFOCTR;
1579 r8a66597->ep[0].fifotrn = 0;
1580 r8a66597->ep[0].pipectr = get_pipectr_addr(0);
1581 r8a66597->pipenum2ep[0] = &r8a66597->ep[0];
1582 r8a66597->epaddr2ep[0] = &r8a66597->ep[0];
1584 the_controller = r8a66597;
1586 r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep,
1588 if (r8a66597->ep0_req == NULL)
1590 r8a66597->ep0_req->complete = nop_completion;
1592 init_controller(r8a66597);
1594 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1598 free_irq(irq, r8a66597);
1601 if (r8a66597->ep0_req)
1602 r8a66597_free_request(&r8a66597->ep[0].ep,
1612 /*-------------------------------------------------------------------------*/
1613 static struct platform_driver r8a66597_driver = {
1614 .remove = __exit_p(r8a66597_remove),
1616 .name = (char *) udc_name,
1620 static int __init r8a66597_udc_init(void)
1622 return platform_driver_probe(&r8a66597_driver, r8a66597_probe);
1624 module_init(r8a66597_udc_init);
1626 static void __exit r8a66597_udc_cleanup(void)
1628 platform_driver_unregister(&r8a66597_driver);
1630 module_exit(r8a66597_udc_cleanup);
1632 MODULE_DESCRIPTION("R8A66597 USB gadget driver");
1633 MODULE_LICENSE("GPL");
1634 MODULE_AUTHOR("Yoshihiro Shimoda");