2 * M66592 UDC (USB gadget)
4 * Copyright (C) 2006-2007 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 "m66592-udc.h"
35 MODULE_DESCRIPTION("M66592 USB gadget driver");
36 MODULE_LICENSE("GPL");
37 MODULE_AUTHOR("Yoshihiro Shimoda");
39 #define DRIVER_VERSION "18 Oct 2007"
41 /* module parameters */
42 #if defined(CONFIG_SUPERH_BUILT_IN_M66592)
43 static unsigned short endian = M66592_LITTLE;
44 module_param(endian, ushort, 0644);
45 MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)");
47 static unsigned short clock = M66592_XTAL24;
48 module_param(clock, ushort, 0644);
49 MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
52 static unsigned short vif = M66592_LDRV;
53 module_param(vif, ushort, 0644);
54 MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0 (default=32768)");
56 static unsigned short endian;
57 module_param(endian, ushort, 0644);
58 MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
60 static unsigned short irq_sense = M66592_INTL;
61 module_param(irq_sense, ushort, 0644);
62 MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 "
66 static const char udc_name[] = "m66592_udc";
67 static const char *m66592_ep_name[] = {
68 "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7"
71 static void disable_controller(struct m66592 *m66592);
72 static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req);
73 static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req);
74 static int m66592_queue(struct usb_ep *_ep, struct usb_request *_req,
77 static void transfer_complete(struct m66592_ep *ep,
78 struct m66592_request *req, int status);
80 /*-------------------------------------------------------------------------*/
81 static inline u16 get_usb_speed(struct m66592 *m66592)
83 return (m66592_read(m66592, M66592_DVSTCTR) & M66592_RHST);
86 static void enable_pipe_irq(struct m66592 *m66592, u16 pipenum,
91 tmp = m66592_read(m66592, M66592_INTENB0);
92 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE,
94 m66592_bset(m66592, (1 << pipenum), reg);
95 m66592_write(m66592, tmp, M66592_INTENB0);
98 static void disable_pipe_irq(struct m66592 *m66592, u16 pipenum,
103 tmp = m66592_read(m66592, M66592_INTENB0);
104 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE,
106 m66592_bclr(m66592, (1 << pipenum), reg);
107 m66592_write(m66592, tmp, M66592_INTENB0);
110 static void m66592_usb_connect(struct m66592 *m66592)
112 m66592_bset(m66592, M66592_CTRE, M66592_INTENB0);
113 m66592_bset(m66592, M66592_WDST | M66592_RDST | M66592_CMPL,
115 m66592_bset(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0);
117 m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG);
120 static void m66592_usb_disconnect(struct m66592 *m66592)
121 __releases(m66592->lock)
122 __acquires(m66592->lock)
124 m66592_bclr(m66592, M66592_CTRE, M66592_INTENB0);
125 m66592_bclr(m66592, M66592_WDST | M66592_RDST | M66592_CMPL,
127 m66592_bclr(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0);
128 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
130 m66592->gadget.speed = USB_SPEED_UNKNOWN;
131 spin_unlock(&m66592->lock);
132 m66592->driver->disconnect(&m66592->gadget);
133 spin_lock(&m66592->lock);
135 disable_controller(m66592);
136 INIT_LIST_HEAD(&m66592->ep[0].queue);
139 static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum)
142 unsigned long offset;
145 pid = m66592_read(m66592, M66592_DCPCTR) & M66592_PID;
146 else if (pipenum < M66592_MAX_NUM_PIPE) {
147 offset = get_pipectr_addr(pipenum);
148 pid = m66592_read(m66592, offset) & M66592_PID;
150 pr_err("unexpect pipe num (%d)\n", pipenum);
155 static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum,
158 unsigned long offset;
161 m66592_mdfy(m66592, pid, M66592_PID, M66592_DCPCTR);
162 else if (pipenum < M66592_MAX_NUM_PIPE) {
163 offset = get_pipectr_addr(pipenum);
164 m66592_mdfy(m66592, pid, M66592_PID, offset);
166 pr_err("unexpect pipe num (%d)\n", pipenum);
169 static inline void pipe_start(struct m66592 *m66592, u16 pipenum)
171 control_reg_set_pid(m66592, pipenum, M66592_PID_BUF);
174 static inline void pipe_stop(struct m66592 *m66592, u16 pipenum)
176 control_reg_set_pid(m66592, pipenum, M66592_PID_NAK);
179 static inline void pipe_stall(struct m66592 *m66592, u16 pipenum)
181 control_reg_set_pid(m66592, pipenum, M66592_PID_STALL);
184 static inline u16 control_reg_get(struct m66592 *m66592, u16 pipenum)
187 unsigned long offset;
190 ret = m66592_read(m66592, M66592_DCPCTR);
191 else if (pipenum < M66592_MAX_NUM_PIPE) {
192 offset = get_pipectr_addr(pipenum);
193 ret = m66592_read(m66592, offset);
195 pr_err("unexpect pipe num (%d)\n", pipenum);
200 static inline void control_reg_sqclr(struct m66592 *m66592, u16 pipenum)
202 unsigned long offset;
204 pipe_stop(m66592, pipenum);
207 m66592_bset(m66592, M66592_SQCLR, M66592_DCPCTR);
208 else if (pipenum < M66592_MAX_NUM_PIPE) {
209 offset = get_pipectr_addr(pipenum);
210 m66592_bset(m66592, M66592_SQCLR, offset);
212 pr_err("unexpect pipe num(%d)\n", pipenum);
215 static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum)
221 tmp = m66592_read(m66592, M66592_DCPCFG);
222 if ((tmp & M66592_CNTMD) != 0)
225 tmp = m66592_read(m66592, M66592_DCPMAXP);
226 size = tmp & M66592_MAXP;
229 m66592_write(m66592, pipenum, M66592_PIPESEL);
230 tmp = m66592_read(m66592, M66592_PIPECFG);
231 if ((tmp & M66592_CNTMD) != 0) {
232 tmp = m66592_read(m66592, M66592_PIPEBUF);
233 size = ((tmp >> 10) + 1) * 64;
235 tmp = m66592_read(m66592, M66592_PIPEMAXP);
236 size = tmp & M66592_MXPS;
243 static inline void pipe_change(struct m66592 *m66592, u16 pipenum)
245 struct m66592_ep *ep = m66592->pipenum2ep[pipenum];
250 m66592_mdfy(m66592, pipenum, M66592_CURPIPE, ep->fifosel);
254 m66592_bset(m66592, M66592_MBW, ep->fifosel);
257 static int pipe_buffer_setting(struct m66592 *m66592,
258 struct m66592_pipe_info *info)
260 u16 bufnum = 0, buf_bsize = 0;
266 m66592_write(m66592, info->pipe, M66592_PIPESEL);
269 pipecfg |= M66592_DIR;
270 pipecfg |= info->type;
271 pipecfg |= info->epnum;
272 switch (info->type) {
274 bufnum = 4 + (info->pipe - M66592_BASE_PIPENUM_INT);
278 bufnum = m66592->bi_bufnum +
279 (info->pipe - M66592_BASE_PIPENUM_BULK) * 16;
280 m66592->bi_bufnum += 16;
282 pipecfg |= M66592_DBLB;
284 pipecfg |= M66592_SHTNAK;
287 bufnum = m66592->bi_bufnum +
288 (info->pipe - M66592_BASE_PIPENUM_ISOC) * 16;
289 m66592->bi_bufnum += 16;
293 if (m66592->bi_bufnum > M66592_MAX_BUFNUM) {
294 pr_err("m66592 pipe memory is insufficient(%d)\n",
299 m66592_write(m66592, pipecfg, M66592_PIPECFG);
300 m66592_write(m66592, (buf_bsize << 10) | (bufnum), M66592_PIPEBUF);
301 m66592_write(m66592, info->maxpacket, M66592_PIPEMAXP);
304 m66592_write(m66592, info->interval, M66592_PIPEPERI);
309 static void pipe_buffer_release(struct m66592 *m66592,
310 struct m66592_pipe_info *info)
315 switch (info->type) {
317 if (is_bulk_pipe(info->pipe))
318 m66592->bi_bufnum -= 16;
321 if (is_isoc_pipe(info->pipe))
322 m66592->bi_bufnum -= 16;
326 if (is_bulk_pipe(info->pipe)) {
328 } else if (is_interrupt_pipe(info->pipe))
330 else if (is_isoc_pipe(info->pipe)) {
331 m66592->isochronous--;
332 if (info->type == M66592_BULK)
335 pr_err("ep_release: unexpect pipenum (%d)\n",
339 static void pipe_initialize(struct m66592_ep *ep)
341 struct m66592 *m66592 = ep->m66592;
343 m66592_mdfy(m66592, 0, M66592_CURPIPE, ep->fifosel);
345 m66592_write(m66592, M66592_ACLRM, ep->pipectr);
346 m66592_write(m66592, 0, ep->pipectr);
347 m66592_write(m66592, M66592_SQCLR, ep->pipectr);
349 m66592_mdfy(m66592, ep->pipenum, M66592_CURPIPE, ep->fifosel);
353 m66592_bset(m66592, M66592_MBW, ep->fifosel);
357 static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
358 const struct usb_endpoint_descriptor *desc,
359 u16 pipenum, int dma)
361 if ((pipenum != 0) && dma) {
362 if (m66592->num_dma == 0) {
365 ep->fifoaddr = M66592_D0FIFO;
366 ep->fifosel = M66592_D0FIFOSEL;
367 ep->fifoctr = M66592_D0FIFOCTR;
368 ep->fifotrn = M66592_D0FIFOTRN;
369 #if !defined(CONFIG_SUPERH_BUILT_IN_M66592)
370 } else if (m66592->num_dma == 1) {
373 ep->fifoaddr = M66592_D1FIFO;
374 ep->fifosel = M66592_D1FIFOSEL;
375 ep->fifoctr = M66592_D1FIFOCTR;
376 ep->fifotrn = M66592_D1FIFOTRN;
380 ep->fifoaddr = M66592_CFIFO;
381 ep->fifosel = M66592_CFIFOSEL;
382 ep->fifoctr = M66592_CFIFOCTR;
387 ep->fifoaddr = M66592_CFIFO;
388 ep->fifosel = M66592_CFIFOSEL;
389 ep->fifoctr = M66592_CFIFOCTR;
393 ep->pipectr = get_pipectr_addr(pipenum);
394 ep->pipenum = pipenum;
395 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
396 m66592->pipenum2ep[pipenum] = ep;
397 m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep;
398 INIT_LIST_HEAD(&ep->queue);
401 static void m66592_ep_release(struct m66592_ep *ep)
403 struct m66592 *m66592 = ep->m66592;
404 u16 pipenum = ep->pipenum;
416 static int alloc_pipe_config(struct m66592_ep *ep,
417 const struct usb_endpoint_descriptor *desc)
419 struct m66592 *m66592 = ep->m66592;
420 struct m66592_pipe_info info;
429 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
430 case USB_ENDPOINT_XFER_BULK:
431 if (m66592->bulk >= M66592_MAX_NUM_BULK) {
432 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
433 pr_err("bulk pipe is insufficient\n");
436 info.pipe = M66592_BASE_PIPENUM_ISOC
437 + m66592->isochronous;
438 counter = &m66592->isochronous;
441 info.pipe = M66592_BASE_PIPENUM_BULK + m66592->bulk;
442 counter = &m66592->bulk;
444 info.type = M66592_BULK;
447 case USB_ENDPOINT_XFER_INT:
448 if (m66592->interrupt >= M66592_MAX_NUM_INT) {
449 pr_err("interrupt pipe is insufficient\n");
452 info.pipe = M66592_BASE_PIPENUM_INT + m66592->interrupt;
453 info.type = M66592_INT;
454 counter = &m66592->interrupt;
456 case USB_ENDPOINT_XFER_ISOC:
457 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
458 pr_err("isochronous pipe is insufficient\n");
461 info.pipe = M66592_BASE_PIPENUM_ISOC + m66592->isochronous;
462 info.type = M66592_ISO;
463 counter = &m66592->isochronous;
466 pr_err("unexpect xfer type\n");
469 ep->type = info.type;
471 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
472 info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
473 info.interval = desc->bInterval;
474 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
479 ret = pipe_buffer_setting(m66592, &info);
481 pr_err("pipe_buffer_setting fail\n");
486 if ((counter == &m66592->isochronous) && info.type == M66592_BULK)
489 m66592_ep_setting(m66592, ep, desc, info.pipe, dma);
495 static int free_pipe_config(struct m66592_ep *ep)
497 struct m66592 *m66592 = ep->m66592;
498 struct m66592_pipe_info info;
500 info.pipe = ep->pipenum;
501 info.type = ep->type;
502 pipe_buffer_release(m66592, &info);
503 m66592_ep_release(ep);
508 /*-------------------------------------------------------------------------*/
509 static void pipe_irq_enable(struct m66592 *m66592, u16 pipenum)
511 enable_irq_ready(m66592, pipenum);
512 enable_irq_nrdy(m66592, pipenum);
515 static void pipe_irq_disable(struct m66592 *m66592, u16 pipenum)
517 disable_irq_ready(m66592, pipenum);
518 disable_irq_nrdy(m66592, pipenum);
521 /* if complete is true, gadget driver complete function is not call */
522 static void control_end(struct m66592 *m66592, unsigned ccpl)
524 m66592->ep[0].internal_ccpl = ccpl;
525 pipe_start(m66592, 0);
526 m66592_bset(m66592, M66592_CCPL, M66592_DCPCTR);
529 static void start_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
531 struct m66592 *m66592 = ep->m66592;
533 pipe_change(m66592, ep->pipenum);
534 m66592_mdfy(m66592, M66592_ISEL | M66592_PIPE0,
535 (M66592_ISEL | M66592_CURPIPE),
537 m66592_write(m66592, M66592_BCLR, ep->fifoctr);
538 if (req->req.length == 0) {
539 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
540 pipe_start(m66592, 0);
541 transfer_complete(ep, req, 0);
543 m66592_write(m66592, ~M66592_BEMP0, M66592_BEMPSTS);
544 irq_ep0_write(ep, req);
548 static void start_packet_write(struct m66592_ep *ep, struct m66592_request *req)
550 struct m66592 *m66592 = ep->m66592;
553 pipe_change(m66592, ep->pipenum);
554 disable_irq_empty(m66592, ep->pipenum);
555 pipe_start(m66592, ep->pipenum);
557 tmp = m66592_read(m66592, ep->fifoctr);
558 if (unlikely((tmp & M66592_FRDY) == 0))
559 pipe_irq_enable(m66592, ep->pipenum);
561 irq_packet_write(ep, req);
564 static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req)
566 struct m66592 *m66592 = ep->m66592;
567 u16 pipenum = ep->pipenum;
569 if (ep->pipenum == 0) {
570 m66592_mdfy(m66592, M66592_PIPE0,
571 (M66592_ISEL | M66592_CURPIPE),
573 m66592_write(m66592, M66592_BCLR, ep->fifoctr);
574 pipe_start(m66592, pipenum);
575 pipe_irq_enable(m66592, pipenum);
578 m66592_bset(m66592, M66592_TRCLR, ep->fifosel);
579 pipe_change(m66592, pipenum);
580 m66592_bset(m66592, M66592_TRENB, ep->fifosel);
582 (req->req.length + ep->ep.maxpacket - 1)
586 pipe_start(m66592, pipenum); /* trigger once */
587 pipe_irq_enable(m66592, pipenum);
591 static void start_packet(struct m66592_ep *ep, struct m66592_request *req)
593 if (ep->desc->bEndpointAddress & USB_DIR_IN)
594 start_packet_write(ep, req);
596 start_packet_read(ep, req);
599 static void start_ep0(struct m66592_ep *ep, struct m66592_request *req)
603 ctsq = m66592_read(ep->m66592, M66592_INTSTS0) & M66592_CTSQ;
607 start_ep0_write(ep, req);
610 start_packet_read(ep, req);
614 control_end(ep->m66592, 0);
617 pr_err("start_ep0: unexpect ctsq(%x)\n", ctsq);
622 #if defined(CONFIG_SUPERH_BUILT_IN_M66592)
623 static void init_controller(struct m66592 *m66592)
626 m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */
627 m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG);
628 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
629 m66592_bset(m66592, M66592_USBE, M66592_SYSCFG);
631 /* This is a workaound for SH7722 2nd cut */
632 m66592_bset(m66592, 0x8000, M66592_DVSTCTR);
633 m66592_bset(m66592, 0x1000, M66592_TESTMODE);
634 m66592_bclr(m66592, 0x8000, M66592_DVSTCTR);
636 m66592_bset(m66592, M66592_INTL, M66592_INTENB1);
638 m66592_write(m66592, 0, M66592_CFBCFG);
639 m66592_write(m66592, 0, M66592_D0FBCFG);
640 m66592_bset(m66592, endian, M66592_CFBCFG);
641 m66592_bset(m66592, endian, M66592_D0FBCFG);
643 #else /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
644 static void init_controller(struct m66592 *m66592)
646 m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND),
648 m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */
649 m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG);
651 m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG);
652 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
653 m66592_bset(m66592, M66592_USBE, M66592_SYSCFG);
655 m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG);
659 m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG);
663 m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG);
665 m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1);
666 m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR,
669 #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
671 static void disable_controller(struct m66592 *m66592)
673 #if defined(CONFIG_SUPERH_BUILT_IN_M66592)
676 m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG);
678 m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG);
680 m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG);
682 m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG);
686 static void m66592_start_xclock(struct m66592 *m66592)
688 #if defined(CONFIG_SUPERH_BUILT_IN_M66592)
693 tmp = m66592_read(m66592, M66592_SYSCFG);
694 if (!(tmp & M66592_XCKE))
695 m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG);
699 /*-------------------------------------------------------------------------*/
700 static void transfer_complete(struct m66592_ep *ep,
701 struct m66592_request *req, int status)
702 __releases(m66592->lock)
703 __acquires(m66592->lock)
707 if (unlikely(ep->pipenum == 0)) {
708 if (ep->internal_ccpl) {
709 ep->internal_ccpl = 0;
714 list_del_init(&req->queue);
715 if (ep->m66592->gadget.speed == USB_SPEED_UNKNOWN)
716 req->req.status = -ESHUTDOWN;
718 req->req.status = status;
720 if (!list_empty(&ep->queue))
723 spin_unlock(&ep->m66592->lock);
724 req->req.complete(&ep->ep, &req->req);
725 spin_lock(&ep->m66592->lock);
728 req = list_entry(ep->queue.next, struct m66592_request, queue);
730 start_packet(ep, req);
734 static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
741 u16 pipenum = ep->pipenum;
742 struct m66592 *m66592 = ep->m66592;
744 pipe_change(m66592, pipenum);
745 m66592_bset(m66592, M66592_ISEL, ep->fifosel);
749 tmp = m66592_read(m66592, ep->fifoctr);
751 pr_err("pipe0 is busy. maybe cpu i/o bus "
752 "conflict. please power off this controller.");
756 } while ((tmp & M66592_FRDY) == 0);
758 /* prepare parameters */
759 bufsize = get_buffer_size(m66592, pipenum);
760 buf = req->req.buf + req->req.actual;
761 size = min(bufsize, req->req.length - req->req.actual);
766 m66592_write_fifo(m66592, ep->fifoaddr, buf, size);
767 if ((size == 0) || ((size % ep->ep.maxpacket) != 0))
768 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
771 /* update parameters */
772 req->req.actual += size;
774 /* check transfer finish */
775 if ((!req->req.zero && (req->req.actual == req->req.length))
776 || (size % ep->ep.maxpacket)
778 disable_irq_ready(m66592, pipenum);
779 disable_irq_empty(m66592, pipenum);
781 disable_irq_ready(m66592, pipenum);
782 enable_irq_empty(m66592, pipenum);
784 pipe_start(m66592, pipenum);
787 static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req)
793 u16 pipenum = ep->pipenum;
794 struct m66592 *m66592 = ep->m66592;
796 pipe_change(m66592, pipenum);
797 tmp = m66592_read(m66592, ep->fifoctr);
798 if (unlikely((tmp & M66592_FRDY) == 0)) {
799 pipe_stop(m66592, pipenum);
800 pipe_irq_disable(m66592, pipenum);
801 pr_err("write fifo not ready. pipnum=%d\n", pipenum);
805 /* prepare parameters */
806 bufsize = get_buffer_size(m66592, pipenum);
807 buf = req->req.buf + req->req.actual;
808 size = min(bufsize, req->req.length - req->req.actual);
812 m66592_write_fifo(m66592, ep->fifoaddr, buf, size);
814 || ((size % ep->ep.maxpacket) != 0)
815 || ((bufsize != ep->ep.maxpacket)
816 && (bufsize > size)))
817 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
820 /* update parameters */
821 req->req.actual += size;
822 /* check transfer finish */
823 if ((!req->req.zero && (req->req.actual == req->req.length))
824 || (size % ep->ep.maxpacket)
826 disable_irq_ready(m66592, pipenum);
827 enable_irq_empty(m66592, pipenum);
829 disable_irq_empty(m66592, pipenum);
830 pipe_irq_enable(m66592, pipenum);
834 static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req)
837 int rcv_len, bufsize, req_len;
840 u16 pipenum = ep->pipenum;
841 struct m66592 *m66592 = ep->m66592;
844 pipe_change(m66592, pipenum);
845 tmp = m66592_read(m66592, ep->fifoctr);
846 if (unlikely((tmp & M66592_FRDY) == 0)) {
847 req->req.status = -EPIPE;
848 pipe_stop(m66592, pipenum);
849 pipe_irq_disable(m66592, pipenum);
850 pr_err("read fifo not ready");
854 /* prepare parameters */
855 rcv_len = tmp & M66592_DTLN;
856 bufsize = get_buffer_size(m66592, pipenum);
858 buf = req->req.buf + req->req.actual;
859 req_len = req->req.length - req->req.actual;
860 if (rcv_len < bufsize)
861 size = min(rcv_len, req_len);
863 size = min(bufsize, req_len);
865 /* update parameters */
866 req->req.actual += size;
868 /* check transfer finish */
869 if ((!req->req.zero && (req->req.actual == req->req.length))
870 || (size % ep->ep.maxpacket)
872 pipe_stop(m66592, pipenum);
873 pipe_irq_disable(m66592, pipenum);
880 m66592_write(m66592, M66592_BCLR, ep->fifoctr);
882 m66592_read_fifo(m66592, ep->fifoaddr, buf, size);
885 if ((ep->pipenum != 0) && finish)
886 transfer_complete(ep, req, 0);
889 static void irq_pipe_ready(struct m66592 *m66592, u16 status, u16 enb)
893 struct m66592_ep *ep;
894 struct m66592_request *req;
896 if ((status & M66592_BRDY0) && (enb & M66592_BRDY0)) {
897 m66592_write(m66592, ~M66592_BRDY0, M66592_BRDYSTS);
898 m66592_mdfy(m66592, M66592_PIPE0, M66592_CURPIPE,
902 req = list_entry(ep->queue.next, struct m66592_request, queue);
903 irq_packet_read(ep, req);
905 for (pipenum = 1; pipenum < M66592_MAX_NUM_PIPE; pipenum++) {
906 check = 1 << pipenum;
907 if ((status & check) && (enb & check)) {
908 m66592_write(m66592, ~check, M66592_BRDYSTS);
909 ep = m66592->pipenum2ep[pipenum];
910 req = list_entry(ep->queue.next,
911 struct m66592_request, queue);
912 if (ep->desc->bEndpointAddress & USB_DIR_IN)
913 irq_packet_write(ep, req);
915 irq_packet_read(ep, req);
921 static void irq_pipe_empty(struct m66592 *m66592, u16 status, u16 enb)
926 struct m66592_ep *ep;
927 struct m66592_request *req;
929 if ((status & M66592_BEMP0) && (enb & M66592_BEMP0)) {
930 m66592_write(m66592, ~M66592_BEMP0, M66592_BEMPSTS);
933 req = list_entry(ep->queue.next, struct m66592_request, queue);
934 irq_ep0_write(ep, req);
936 for (pipenum = 1; pipenum < M66592_MAX_NUM_PIPE; pipenum++) {
937 check = 1 << pipenum;
938 if ((status & check) && (enb & check)) {
939 m66592_write(m66592, ~check, M66592_BEMPSTS);
940 tmp = control_reg_get(m66592, pipenum);
941 if ((tmp & M66592_INBUFM) == 0) {
942 disable_irq_empty(m66592, pipenum);
943 pipe_irq_disable(m66592, pipenum);
944 pipe_stop(m66592, pipenum);
945 ep = m66592->pipenum2ep[pipenum];
946 req = list_entry(ep->queue.next,
947 struct m66592_request,
949 if (!list_empty(&ep->queue))
950 transfer_complete(ep, req, 0);
957 static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
958 __releases(m66592->lock)
959 __acquires(m66592->lock)
961 struct m66592_ep *ep;
964 u16 w_index = le16_to_cpu(ctrl->wIndex);
966 switch (ctrl->bRequestType & USB_RECIP_MASK) {
967 case USB_RECIP_DEVICE:
968 status = 1 << USB_DEVICE_SELF_POWERED;
970 case USB_RECIP_INTERFACE:
973 case USB_RECIP_ENDPOINT:
974 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
975 pid = control_reg_get_pid(m66592, ep->pipenum);
976 if (pid == M66592_PID_STALL)
977 status = 1 << USB_ENDPOINT_HALT;
982 pipe_stall(m66592, 0);
986 m66592->ep0_data = cpu_to_le16(status);
987 m66592->ep0_req->buf = &m66592->ep0_data;
988 m66592->ep0_req->length = 2;
989 /* AV: what happens if we get called again before that gets through? */
990 spin_unlock(&m66592->lock);
991 m66592_queue(m66592->gadget.ep0, m66592->ep0_req, GFP_KERNEL);
992 spin_lock(&m66592->lock);
995 static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
997 switch (ctrl->bRequestType & USB_RECIP_MASK) {
998 case USB_RECIP_DEVICE:
999 control_end(m66592, 1);
1001 case USB_RECIP_INTERFACE:
1002 control_end(m66592, 1);
1004 case USB_RECIP_ENDPOINT: {
1005 struct m66592_ep *ep;
1006 struct m66592_request *req;
1007 u16 w_index = le16_to_cpu(ctrl->wIndex);
1009 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
1010 pipe_stop(m66592, ep->pipenum);
1011 control_reg_sqclr(m66592, ep->pipenum);
1013 control_end(m66592, 1);
1015 req = list_entry(ep->queue.next,
1016 struct m66592_request, queue);
1019 if (list_empty(&ep->queue))
1021 start_packet(ep, req);
1022 } else if (!list_empty(&ep->queue))
1023 pipe_start(m66592, ep->pipenum);
1027 pipe_stall(m66592, 0);
1032 static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
1035 switch (ctrl->bRequestType & USB_RECIP_MASK) {
1036 case USB_RECIP_DEVICE:
1037 control_end(m66592, 1);
1039 case USB_RECIP_INTERFACE:
1040 control_end(m66592, 1);
1042 case USB_RECIP_ENDPOINT: {
1043 struct m66592_ep *ep;
1044 u16 w_index = le16_to_cpu(ctrl->wIndex);
1046 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
1047 pipe_stall(m66592, ep->pipenum);
1049 control_end(m66592, 1);
1053 pipe_stall(m66592, 0);
1058 /* if return value is true, call class driver's setup() */
1059 static int setup_packet(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
1061 u16 *p = (u16 *)ctrl;
1062 unsigned long offset = M66592_USBREQ;
1066 m66592_write(m66592, ~M66592_VALID, M66592_INTSTS0);
1068 for (i = 0; i < 4; i++)
1069 p[i] = m66592_read(m66592, offset + i*2);
1072 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1073 switch (ctrl->bRequest) {
1074 case USB_REQ_GET_STATUS:
1075 get_status(m66592, ctrl);
1077 case USB_REQ_CLEAR_FEATURE:
1078 clear_feature(m66592, ctrl);
1080 case USB_REQ_SET_FEATURE:
1081 set_feature(m66592, ctrl);
1092 static void m66592_update_usb_speed(struct m66592 *m66592)
1094 u16 speed = get_usb_speed(m66592);
1098 m66592->gadget.speed = USB_SPEED_HIGH;
1101 m66592->gadget.speed = USB_SPEED_FULL;
1104 m66592->gadget.speed = USB_SPEED_UNKNOWN;
1105 pr_err("USB speed unknown\n");
1109 static void irq_device_state(struct m66592 *m66592)
1113 dvsq = m66592_read(m66592, M66592_INTSTS0) & M66592_DVSQ;
1114 m66592_write(m66592, ~M66592_DVST, M66592_INTSTS0);
1116 if (dvsq == M66592_DS_DFLT) { /* bus reset */
1117 m66592->driver->disconnect(&m66592->gadget);
1118 m66592_update_usb_speed(m66592);
1120 if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG)
1121 m66592_update_usb_speed(m66592);
1122 if ((dvsq == M66592_DS_CNFG || dvsq == M66592_DS_ADDS)
1123 && m66592->gadget.speed == USB_SPEED_UNKNOWN)
1124 m66592_update_usb_speed(m66592);
1126 m66592->old_dvsq = dvsq;
1129 static void irq_control_stage(struct m66592 *m66592)
1130 __releases(m66592->lock)
1131 __acquires(m66592->lock)
1133 struct usb_ctrlrequest ctrl;
1136 ctsq = m66592_read(m66592, M66592_INTSTS0) & M66592_CTSQ;
1137 m66592_write(m66592, ~M66592_CTRT, M66592_INTSTS0);
1140 case M66592_CS_IDST: {
1141 struct m66592_ep *ep;
1142 struct m66592_request *req;
1143 ep = &m66592->ep[0];
1144 req = list_entry(ep->queue.next, struct m66592_request, queue);
1145 transfer_complete(ep, req, 0);
1149 case M66592_CS_RDDS:
1150 case M66592_CS_WRDS:
1151 case M66592_CS_WRND:
1152 if (setup_packet(m66592, &ctrl)) {
1153 spin_unlock(&m66592->lock);
1154 if (m66592->driver->setup(&m66592->gadget, &ctrl) < 0)
1155 pipe_stall(m66592, 0);
1156 spin_lock(&m66592->lock);
1159 case M66592_CS_RDSS:
1160 case M66592_CS_WRSS:
1161 control_end(m66592, 0);
1164 pr_err("ctrl_stage: unexpect ctsq(%x)\n", ctsq);
1169 static irqreturn_t m66592_irq(int irq, void *_m66592)
1171 struct m66592 *m66592 = _m66592;
1174 u16 brdysts, nrdysts, bempsts;
1175 u16 brdyenb, nrdyenb, bempenb;
1179 spin_lock(&m66592->lock);
1181 intsts0 = m66592_read(m66592, M66592_INTSTS0);
1182 intenb0 = m66592_read(m66592, M66592_INTENB0);
1184 #if defined(CONFIG_SUPERH_BUILT_IN_M66592)
1185 if (!intsts0 && !intenb0) {
1187 * When USB clock stops, it cannot read register. Even if a
1188 * clock stops, the interrupt occurs. So this driver turn on
1189 * a clock by this timing and do re-reading of register.
1191 m66592_start_xclock(m66592);
1192 intsts0 = m66592_read(m66592, M66592_INTSTS0);
1193 intenb0 = m66592_read(m66592, M66592_INTENB0);
1197 savepipe = m66592_read(m66592, M66592_CFIFOSEL);
1199 mask0 = intsts0 & intenb0;
1201 brdysts = m66592_read(m66592, M66592_BRDYSTS);
1202 nrdysts = m66592_read(m66592, M66592_NRDYSTS);
1203 bempsts = m66592_read(m66592, M66592_BEMPSTS);
1204 brdyenb = m66592_read(m66592, M66592_BRDYENB);
1205 nrdyenb = m66592_read(m66592, M66592_NRDYENB);
1206 bempenb = m66592_read(m66592, M66592_BEMPENB);
1208 if (mask0 & M66592_VBINT) {
1209 m66592_write(m66592, 0xffff & ~M66592_VBINT,
1211 m66592_start_xclock(m66592);
1213 /* start vbus sampling */
1214 m66592->old_vbus = m66592_read(m66592, M66592_INTSTS0)
1216 m66592->scount = M66592_MAX_SAMPLING;
1218 mod_timer(&m66592->timer,
1219 jiffies + msecs_to_jiffies(50));
1221 if (intsts0 & M66592_DVSQ)
1222 irq_device_state(m66592);
1224 if ((intsts0 & M66592_BRDY) && (intenb0 & M66592_BRDYE)
1225 && (brdysts & brdyenb)) {
1226 irq_pipe_ready(m66592, brdysts, brdyenb);
1228 if ((intsts0 & M66592_BEMP) && (intenb0 & M66592_BEMPE)
1229 && (bempsts & bempenb)) {
1230 irq_pipe_empty(m66592, bempsts, bempenb);
1233 if (intsts0 & M66592_CTRT)
1234 irq_control_stage(m66592);
1237 m66592_write(m66592, savepipe, M66592_CFIFOSEL);
1239 spin_unlock(&m66592->lock);
1243 static void m66592_timer(unsigned long _m66592)
1245 struct m66592 *m66592 = (struct m66592 *)_m66592;
1246 unsigned long flags;
1249 spin_lock_irqsave(&m66592->lock, flags);
1250 tmp = m66592_read(m66592, M66592_SYSCFG);
1251 if (!(tmp & M66592_RCKE)) {
1252 m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG);
1254 m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG);
1256 if (m66592->scount > 0) {
1257 tmp = m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS;
1258 if (tmp == m66592->old_vbus) {
1260 if (m66592->scount == 0) {
1261 if (tmp == M66592_VBSTS)
1262 m66592_usb_connect(m66592);
1264 m66592_usb_disconnect(m66592);
1266 mod_timer(&m66592->timer,
1267 jiffies + msecs_to_jiffies(50));
1270 m66592->scount = M66592_MAX_SAMPLING;
1271 m66592->old_vbus = tmp;
1272 mod_timer(&m66592->timer,
1273 jiffies + msecs_to_jiffies(50));
1276 spin_unlock_irqrestore(&m66592->lock, flags);
1279 /*-------------------------------------------------------------------------*/
1280 static int m66592_enable(struct usb_ep *_ep,
1281 const struct usb_endpoint_descriptor *desc)
1283 struct m66592_ep *ep;
1285 ep = container_of(_ep, struct m66592_ep, ep);
1286 return alloc_pipe_config(ep, desc);
1289 static int m66592_disable(struct usb_ep *_ep)
1291 struct m66592_ep *ep;
1292 struct m66592_request *req;
1293 unsigned long flags;
1295 ep = container_of(_ep, struct m66592_ep, ep);
1298 while (!list_empty(&ep->queue)) {
1299 req = list_entry(ep->queue.next, struct m66592_request, queue);
1300 spin_lock_irqsave(&ep->m66592->lock, flags);
1301 transfer_complete(ep, req, -ECONNRESET);
1302 spin_unlock_irqrestore(&ep->m66592->lock, flags);
1305 pipe_irq_disable(ep->m66592, ep->pipenum);
1306 return free_pipe_config(ep);
1309 static struct usb_request *m66592_alloc_request(struct usb_ep *_ep,
1312 struct m66592_request *req;
1314 req = kzalloc(sizeof(struct m66592_request), gfp_flags);
1318 INIT_LIST_HEAD(&req->queue);
1323 static void m66592_free_request(struct usb_ep *_ep, struct usb_request *_req)
1325 struct m66592_request *req;
1327 req = container_of(_req, struct m66592_request, req);
1331 static int m66592_queue(struct usb_ep *_ep, struct usb_request *_req,
1334 struct m66592_ep *ep;
1335 struct m66592_request *req;
1336 unsigned long flags;
1339 ep = container_of(_ep, struct m66592_ep, ep);
1340 req = container_of(_req, struct m66592_request, req);
1342 if (ep->m66592->gadget.speed == USB_SPEED_UNKNOWN)
1345 spin_lock_irqsave(&ep->m66592->lock, flags);
1347 if (list_empty(&ep->queue))
1350 list_add_tail(&req->queue, &ep->queue);
1351 req->req.actual = 0;
1352 req->req.status = -EINPROGRESS;
1354 if (ep->desc == NULL) /* control */
1357 if (request && !ep->busy)
1358 start_packet(ep, req);
1361 spin_unlock_irqrestore(&ep->m66592->lock, flags);
1366 static int m66592_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1368 struct m66592_ep *ep;
1369 struct m66592_request *req;
1370 unsigned long flags;
1372 ep = container_of(_ep, struct m66592_ep, ep);
1373 req = container_of(_req, struct m66592_request, req);
1375 spin_lock_irqsave(&ep->m66592->lock, flags);
1376 if (!list_empty(&ep->queue))
1377 transfer_complete(ep, req, -ECONNRESET);
1378 spin_unlock_irqrestore(&ep->m66592->lock, flags);
1383 static int m66592_set_halt(struct usb_ep *_ep, int value)
1385 struct m66592_ep *ep;
1386 struct m66592_request *req;
1387 unsigned long flags;
1390 ep = container_of(_ep, struct m66592_ep, ep);
1391 req = list_entry(ep->queue.next, struct m66592_request, queue);
1393 spin_lock_irqsave(&ep->m66592->lock, flags);
1394 if (!list_empty(&ep->queue)) {
1400 pipe_stall(ep->m66592, ep->pipenum);
1403 pipe_stop(ep->m66592, ep->pipenum);
1407 spin_unlock_irqrestore(&ep->m66592->lock, flags);
1411 static void m66592_fifo_flush(struct usb_ep *_ep)
1413 struct m66592_ep *ep;
1414 unsigned long flags;
1416 ep = container_of(_ep, struct m66592_ep, ep);
1417 spin_lock_irqsave(&ep->m66592->lock, flags);
1418 if (list_empty(&ep->queue) && !ep->busy) {
1419 pipe_stop(ep->m66592, ep->pipenum);
1420 m66592_bclr(ep->m66592, M66592_BCLR, ep->fifoctr);
1422 spin_unlock_irqrestore(&ep->m66592->lock, flags);
1425 static struct usb_ep_ops m66592_ep_ops = {
1426 .enable = m66592_enable,
1427 .disable = m66592_disable,
1429 .alloc_request = m66592_alloc_request,
1430 .free_request = m66592_free_request,
1432 .queue = m66592_queue,
1433 .dequeue = m66592_dequeue,
1435 .set_halt = m66592_set_halt,
1436 .fifo_flush = m66592_fifo_flush,
1439 /*-------------------------------------------------------------------------*/
1440 static struct m66592 *the_controller;
1442 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1444 struct m66592 *m66592 = the_controller;
1448 || driver->speed != USB_SPEED_HIGH
1457 /* hook up the driver */
1458 driver->driver.bus = NULL;
1459 m66592->driver = driver;
1460 m66592->gadget.dev.driver = &driver->driver;
1462 retval = device_add(&m66592->gadget.dev);
1464 pr_err("device_add error (%d)\n", retval);
1468 retval = driver->bind (&m66592->gadget);
1470 pr_err("bind to driver error (%d)\n", retval);
1471 device_del(&m66592->gadget.dev);
1475 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1476 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) {
1477 m66592_start_xclock(m66592);
1478 /* start vbus sampling */
1479 m66592->old_vbus = m66592_read(m66592,
1480 M66592_INTSTS0) & M66592_VBSTS;
1481 m66592->scount = M66592_MAX_SAMPLING;
1482 mod_timer(&m66592->timer, jiffies + msecs_to_jiffies(50));
1488 m66592->driver = NULL;
1489 m66592->gadget.dev.driver = NULL;
1493 EXPORT_SYMBOL(usb_gadget_register_driver);
1495 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1497 struct m66592 *m66592 = the_controller;
1498 unsigned long flags;
1500 if (driver != m66592->driver || !driver->unbind)
1503 spin_lock_irqsave(&m66592->lock, flags);
1504 if (m66592->gadget.speed != USB_SPEED_UNKNOWN)
1505 m66592_usb_disconnect(m66592);
1506 spin_unlock_irqrestore(&m66592->lock, flags);
1508 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1510 driver->unbind(&m66592->gadget);
1511 m66592->gadget.dev.driver = NULL;
1513 init_controller(m66592);
1514 disable_controller(m66592);
1516 device_del(&m66592->gadget.dev);
1517 m66592->driver = NULL;
1520 EXPORT_SYMBOL(usb_gadget_unregister_driver);
1522 /*-------------------------------------------------------------------------*/
1523 static int m66592_get_frame(struct usb_gadget *_gadget)
1525 struct m66592 *m66592 = gadget_to_m66592(_gadget);
1526 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
1529 static struct usb_gadget_ops m66592_gadget_ops = {
1530 .get_frame = m66592_get_frame,
1533 static int __exit m66592_remove(struct platform_device *pdev)
1535 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1537 del_timer_sync(&m66592->timer);
1538 iounmap(m66592->reg);
1539 free_irq(platform_get_irq(pdev, 0), m66592);
1540 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1546 static void nop_completion(struct usb_ep *ep, struct usb_request *r)
1550 #define resource_len(r) (((r)->end - (r)->start) + 1)
1552 static int __init m66592_probe(struct platform_device *pdev)
1554 struct resource *res;
1556 void __iomem *reg = NULL;
1557 struct m66592 *m66592 = NULL;
1561 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1565 pr_err("platform_get_resource_byname error.\n");
1569 irq = platform_get_irq(pdev, 0);
1572 pr_err("platform_get_irq error.\n");
1576 reg = ioremap(res->start, resource_len(res));
1579 pr_err("ioremap error.\n");
1583 /* initialize ucd */
1584 m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL);
1585 if (m66592 == NULL) {
1586 pr_err("kzalloc error\n");
1590 spin_lock_init(&m66592->lock);
1591 dev_set_drvdata(&pdev->dev, m66592);
1593 m66592->gadget.ops = &m66592_gadget_ops;
1594 device_initialize(&m66592->gadget.dev);
1595 strcpy(m66592->gadget.dev.bus_id, "gadget");
1596 m66592->gadget.is_dualspeed = 1;
1597 m66592->gadget.dev.parent = &pdev->dev;
1598 m66592->gadget.dev.dma_mask = pdev->dev.dma_mask;
1599 m66592->gadget.dev.release = pdev->dev.release;
1600 m66592->gadget.name = udc_name;
1602 init_timer(&m66592->timer);
1603 m66592->timer.function = m66592_timer;
1604 m66592->timer.data = (unsigned long)m66592;
1607 m66592->bi_bufnum = M66592_BASE_BUFNUM;
1609 ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED,
1612 pr_err("request_irq error (%d)\n", ret);
1616 INIT_LIST_HEAD(&m66592->gadget.ep_list);
1617 m66592->gadget.ep0 = &m66592->ep[0].ep;
1618 INIT_LIST_HEAD(&m66592->gadget.ep0->ep_list);
1619 for (i = 0; i < M66592_MAX_NUM_PIPE; i++) {
1620 struct m66592_ep *ep = &m66592->ep[i];
1623 INIT_LIST_HEAD(&m66592->ep[i].ep.ep_list);
1624 list_add_tail(&m66592->ep[i].ep.ep_list,
1625 &m66592->gadget.ep_list);
1627 ep->m66592 = m66592;
1628 INIT_LIST_HEAD(&ep->queue);
1629 ep->ep.name = m66592_ep_name[i];
1630 ep->ep.ops = &m66592_ep_ops;
1631 ep->ep.maxpacket = 512;
1633 m66592->ep[0].ep.maxpacket = 64;
1634 m66592->ep[0].pipenum = 0;
1635 m66592->ep[0].fifoaddr = M66592_CFIFO;
1636 m66592->ep[0].fifosel = M66592_CFIFOSEL;
1637 m66592->ep[0].fifoctr = M66592_CFIFOCTR;
1638 m66592->ep[0].fifotrn = 0;
1639 m66592->ep[0].pipectr = get_pipectr_addr(0);
1640 m66592->pipenum2ep[0] = &m66592->ep[0];
1641 m66592->epaddr2ep[0] = &m66592->ep[0];
1643 the_controller = m66592;
1645 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL);
1646 if (m66592->ep0_req == NULL)
1648 m66592->ep0_req->complete = nop_completion;
1650 init_controller(m66592);
1652 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1656 free_irq(irq, m66592);
1659 if (m66592->ep0_req)
1660 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1669 /*-------------------------------------------------------------------------*/
1670 static struct platform_driver m66592_driver = {
1671 .remove = __exit_p(m66592_remove),
1673 .name = (char *) udc_name,
1677 static int __init m66592_udc_init(void)
1679 return platform_driver_probe(&m66592_driver, m66592_probe);
1681 module_init(m66592_udc_init);
1683 static void __exit m66592_udc_cleanup(void)
1685 platform_driver_unregister(&m66592_driver);
1687 module_exit(m66592_udc_cleanup);