13 #include <linux/module.h>
20 #include <linux/slab.h>
23 #include <linux/usb/ch9.h>
28 #define DRIVER_VERSION "2011-09-26"
30 static const char udc_name[] =
"r8a66597_udc";
31 static const char *r8a66597_ep_name[] = {
32 "ep0",
"ep1",
"ep2",
"ep3",
"ep4",
"ep5",
"ep6",
"ep7",
39 static void irq_packet_write(
struct r8a66597_ep *ep,
44 static void transfer_complete(
struct r8a66597_ep *ep,
58 tmp = r8a66597_read(r8a66597,
INTENB0);
62 r8a66597_write(r8a66597, tmp,
INTENB0);
65 static void disable_pipe_irq(
struct r8a66597 *r8a66597,
u16 pipenum,
70 tmp = r8a66597_read(r8a66597,
INTENB0);
74 r8a66597_write(r8a66597, tmp,
INTENB0);
77 static void r8a66597_usb_connect(
struct r8a66597 *r8a66597)
85 static void r8a66597_usb_disconnect(
struct r8a66597 *r8a66597)
94 spin_unlock(&r8a66597->
lock);
96 spin_lock(&r8a66597->
lock);
98 disable_controller(r8a66597);
99 init_controller(r8a66597);
101 INIT_LIST_HEAD(&r8a66597->
ep[0].queue);
104 static inline u16 control_reg_get_pid(
struct r8a66597 *r8a66597,
u16 pipenum)
110 pid = r8a66597_read(r8a66597,
DCPCTR) &
PID;
113 pid = r8a66597_read(r8a66597, offset) &
PID;
122 static inline void control_reg_set_pid(
struct r8a66597 *r8a66597,
u16 pipenum,
128 r8a66597_mdfy(r8a66597, pid,
PID,
DCPCTR);
131 r8a66597_mdfy(r8a66597, pid,
PID, offset);
138 static inline void pipe_start(
struct r8a66597 *r8a66597,
u16 pipenum)
140 control_reg_set_pid(r8a66597, pipenum,
PID_BUF);
143 static inline void pipe_stop(
struct r8a66597 *r8a66597,
u16 pipenum)
145 control_reg_set_pid(r8a66597, pipenum,
PID_NAK);
148 static inline void pipe_stall(
struct r8a66597 *r8a66597,
u16 pipenum)
150 control_reg_set_pid(r8a66597, pipenum,
PID_STALL);
153 static inline u16 control_reg_get(
struct r8a66597 *r8a66597,
u16 pipenum)
159 ret = r8a66597_read(r8a66597,
DCPCTR);
162 ret = r8a66597_read(r8a66597, offset);
171 static inline void control_reg_sqclr(
struct r8a66597 *r8a66597,
u16 pipenum)
175 pipe_stop(r8a66597, pipenum);
188 static void control_reg_sqset(
struct r8a66597 *r8a66597,
u16 pipenum)
192 pipe_stop(r8a66597, pipenum);
201 "unexpect pipe num(%d)\n", pipenum);
205 static u16 control_reg_sqmon(
struct r8a66597 *r8a66597,
u16 pipenum)
213 return r8a66597_read(r8a66597, offset) &
SQMON;
216 "unexpect pipe num(%d)\n", pipenum);
222 static u16 save_usb_toggle(
struct r8a66597 *r8a66597,
u16 pipenum)
224 return control_reg_sqmon(r8a66597, pipenum);
227 static void restore_usb_toggle(
struct r8a66597 *r8a66597,
u16 pipenum,
231 control_reg_sqset(r8a66597, pipenum);
233 control_reg_sqclr(r8a66597, pipenum);
236 static inline int get_buffer_size(
struct r8a66597 *r8a66597,
u16 pipenum)
242 tmp = r8a66597_read(r8a66597,
DCPCFG);
246 tmp = r8a66597_read(r8a66597,
DCPMAXP);
250 r8a66597_write(r8a66597, pipenum,
PIPESEL);
251 tmp = r8a66597_read(r8a66597,
PIPECFG);
253 tmp = r8a66597_read(r8a66597,
PIPEBUF);
254 size = ((tmp >> 10) + 1) * 64;
256 tmp = r8a66597_read(r8a66597,
PIPEMAXP);
264 static inline unsigned short mbw_value(
struct r8a66597 *r8a66597)
266 if (r8a66597->
pdata->on_chip)
272 static void r8a66597_change_curpipe(
struct r8a66597 *r8a66597,
u16 pipenum,
285 r8a66597_mdfy(r8a66597, loop, mask, fifosel);
288 tmp = r8a66597_read(r8a66597, fifosel);
291 "r8a66597: register%x, loop %x "
292 "is timeout\n", fifosel, loop);
296 }
while ((tmp & mask) != loop);
299 static inline void pipe_change(
struct r8a66597 *r8a66597,
u16 pipenum)
319 static int pipe_buffer_setting(
struct r8a66597 *r8a66597,
322 u16 bufnum = 0, buf_bsize = 0;
332 pipecfg |= info->
type;
333 pipecfg |= info->
epnum;
334 switch (info->
type) {
360 pr_err(
"r8a66597 pipe memory is insufficient\n");
364 r8a66597_write(r8a66597, pipecfg,
PIPECFG);
365 r8a66597_write(r8a66597, (buf_bsize << 10) | (bufnum),
PIPEBUF);
374 static void pipe_buffer_release(
struct r8a66597 *r8a66597,
390 "ep_release: unexpect pipenum (%d)\n", info->
pipe);
394 static void pipe_initialize(
struct r8a66597_ep *ep)
396 struct r8a66597 *r8a66597 = ep->
r8a66597;
401 r8a66597_write(r8a66597, 0, ep->
pipectr);
412 static void r8a66597_ep_setting(
struct r8a66597 *r8a66597,
431 ep->
ep.maxpacket = usb_endpoint_maxp(desc);
435 INIT_LIST_HEAD(&ep->
queue);
438 static void r8a66597_ep_release(
struct r8a66597_ep *ep)
440 struct r8a66597 *r8a66597 = ep->
r8a66597;
453 static int alloc_pipe_config(
struct r8a66597_ep *ep,
456 struct r8a66597 *r8a66597 = ep->
r8a66597;
472 "bulk pipe is insufficient\n");
481 counter = &r8a66597->
bulk;
489 "interrupt pipe is insufficient\n");
499 "isochronous pipe is insufficient\n");
513 info.
maxpacket = usb_endpoint_maxp(desc);
520 ret = pipe_buffer_setting(r8a66597, &info);
523 "pipe_buffer_setting fail\n");
531 r8a66597_ep_setting(r8a66597, ep, desc, info.
pipe, dma);
537 static int free_pipe_config(
struct r8a66597_ep *ep)
539 struct r8a66597 *r8a66597 = ep->
r8a66597;
544 pipe_buffer_release(r8a66597, &info);
545 r8a66597_ep_release(ep);
551 static void pipe_irq_enable(
struct r8a66597 *r8a66597,
u16 pipenum)
557 static void pipe_irq_disable(
struct r8a66597 *r8a66597,
u16 pipenum)
564 static void control_end(
struct r8a66597 *r8a66597,
unsigned ccpl)
566 r8a66597->
ep[0].internal_ccpl = ccpl;
567 pipe_start(r8a66597, 0);
571 static void start_ep0_write(
struct r8a66597_ep *ep,
574 struct r8a66597 *r8a66597 = ep->
r8a66597;
576 pipe_change(r8a66597, ep->
pipenum);
579 if (req->
req.length == 0) {
581 pipe_start(r8a66597, 0);
582 transfer_complete(ep, req, 0);
585 irq_ep0_write(ep, req);
589 static void disable_fifosel(
struct r8a66597 *r8a66597,
u16 pipenum,
594 tmp = r8a66597_read(r8a66597, fifosel) &
CURPIPE;
596 r8a66597_change_curpipe(r8a66597, 0, 0, fifosel);
599 static void change_bfre_mode(
struct r8a66597 *r8a66597,
u16 pipenum,
606 r8a66597_write(r8a66597, pipenum,
PIPESEL);
608 if ((enable && tmp) || (!enable && !tmp))
612 pipe_stop(r8a66597, pipenum);
613 disable_fifosel(r8a66597, pipenum,
CFIFOSEL);
614 disable_fifosel(r8a66597, pipenum,
D0FIFOSEL);
615 disable_fifosel(r8a66597, pipenum,
D1FIFOSEL);
617 toggle = save_usb_toggle(r8a66597, pipenum);
619 r8a66597_write(r8a66597, pipenum,
PIPESEL);
629 restore_usb_toggle(r8a66597, pipenum, toggle);
632 static int sudmac_alloc_channel(
struct r8a66597 *r8a66597,
645 if (r8a66597->
dma.used)
649 dma = &r8a66597->
dma;
655 change_bfre_mode(r8a66597, ep->
pipenum, 1);
669 static void sudmac_free_channel(
struct r8a66597 *r8a66597,
679 r8a66597_change_curpipe(r8a66597, 0, 0, ep->
fifosel);
688 static void sudmac_start(
struct r8a66597 *r8a66597,
struct r8a66597_ep *ep,
694 r8a66597_sudmac_write(r8a66597, req->
req.dma,
CH0BA);
695 r8a66597_sudmac_write(r8a66597, req->
req.length,
CH0BBC);
698 r8a66597_sudmac_write(r8a66597,
DEN,
CH0DEN);
701 static void start_packet_write(
struct r8a66597_ep *ep,
704 struct r8a66597 *r8a66597 = ep->
r8a66597;
707 pipe_change(r8a66597, ep->
pipenum);
709 pipe_start(r8a66597, ep->
pipenum);
711 if (req->
req.length == 0) {
712 transfer_complete(ep, req, 0);
715 if (sudmac_alloc_channel(r8a66597, ep, req) < 0) {
717 pipe_change(r8a66597, ep->
pipenum);
719 pipe_start(r8a66597, ep->
pipenum);
720 tmp = r8a66597_read(r8a66597, ep->
fifoctr);
722 pipe_irq_enable(r8a66597, ep->
pipenum);
724 irq_packet_write(ep, req);
727 pipe_change(r8a66597, ep->
pipenum);
729 pipe_start(r8a66597, ep->
pipenum);
731 sudmac_start(r8a66597, ep, req);
736 static void start_packet_read(
struct r8a66597_ep *ep,
739 struct r8a66597 *r8a66597 = ep->
r8a66597;
745 pipe_start(r8a66597, pipenum);
746 pipe_irq_enable(r8a66597, pipenum);
748 pipe_stop(r8a66597, pipenum);
752 r8a66597_write(r8a66597,
758 if (sudmac_alloc_channel(r8a66597, ep, req) < 0) {
760 change_bfre_mode(r8a66597, ep->
pipenum, 0);
761 pipe_start(r8a66597, pipenum);
762 pipe_irq_enable(r8a66597, pipenum);
764 pipe_change(r8a66597, pipenum);
765 sudmac_start(r8a66597, ep, req);
766 pipe_start(r8a66597, pipenum);
774 start_packet_write(ep, req);
776 start_packet_read(ep, req);
787 start_ep0_write(ep, req);
790 start_packet_read(ep, req);
798 "start_ep0: unexpect ctsq(%x)\n", ctsq);
803 static void init_controller(
struct r8a66597 *r8a66597)
809 if (r8a66597->
pdata->on_chip) {
810 if (r8a66597->
pdata->buswait)
811 r8a66597_write(r8a66597, r8a66597->
pdata->buswait,
814 r8a66597_write(r8a66597, 0x0f,
SYSCFG1);
829 r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->
pdata),
852 static void disable_controller(
struct r8a66597 *r8a66597)
854 if (r8a66597->
pdata->on_chip) {
859 r8a66597_write(r8a66597, 0,
INTENB0);
860 r8a66597_write(r8a66597, 0,
INTENB1);
861 r8a66597_write(r8a66597, 0,
BRDYENB);
862 r8a66597_write(r8a66597, 0,
BEMPENB);
863 r8a66597_write(r8a66597, 0,
NRDYENB);
866 r8a66597_write(r8a66597, 0,
BRDYSTS);
867 r8a66597_write(r8a66597, 0,
NRDYSTS);
868 r8a66597_write(r8a66597, 0,
BEMPSTS);
884 static void r8a66597_start_xclock(
struct r8a66597 *r8a66597)
888 if (!r8a66597->
pdata->on_chip) {
889 tmp = r8a66597_read(r8a66597,
SYSCFG0);
901 static void transfer_complete(
struct r8a66597_ep *ep,
915 list_del_init(&req->
queue);
921 if (!list_empty(&ep->
queue))
925 sudmac_free_channel(ep->
r8a66597, ep, req);
928 req->
req.complete(&ep->
ep, &req->
req);
932 req = get_request_from_ep(ep);
934 start_packet(ep, req);
946 struct r8a66597 *r8a66597 = ep->
r8a66597;
948 pipe_change(r8a66597, pipenum);
953 tmp = r8a66597_read(r8a66597, ep->
fifoctr);
956 "pipe0 is busy. maybe cpu i/o bus "
957 "conflict. please power off this controller.");
961 }
while ((tmp &
FRDY) == 0);
964 bufsize = get_buffer_size(r8a66597, pipenum);
965 buf = req->
req.buf + req->
req.actual;
966 size =
min(bufsize, req->
req.length - req->
req.actual);
971 r8a66597_write_fifo(r8a66597, ep, buf, size);
972 if ((size == 0) || ((size % ep->
ep.maxpacket) != 0))
980 if ((!req->
req.zero && (req->
req.actual == req->
req.length))
981 || (size % ep->
ep.maxpacket)
989 pipe_start(r8a66597, pipenum);
992 static void irq_packet_write(
struct r8a66597_ep *ep,
1000 struct r8a66597 *r8a66597 = ep->
r8a66597;
1002 pipe_change(r8a66597, pipenum);
1003 tmp = r8a66597_read(r8a66597, ep->
fifoctr);
1005 pipe_stop(r8a66597, pipenum);
1006 pipe_irq_disable(r8a66597, pipenum);
1008 "write fifo not ready. pipnum=%d\n", pipenum);
1013 bufsize = get_buffer_size(r8a66597, pipenum);
1014 buf = req->
req.buf + req->
req.actual;
1015 size =
min(bufsize, req->
req.length - req->
req.actual);
1019 r8a66597_write_fifo(r8a66597, ep, buf, size);
1021 || ((size % ep->
ep.maxpacket) != 0)
1022 || ((bufsize != ep->
ep.maxpacket)
1023 && (bufsize > size)))
1030 if ((!req->
req.zero && (req->
req.actual == req->
req.length))
1031 || (size % ep->
ep.maxpacket)
1037 pipe_irq_enable(r8a66597, pipenum);
1041 static void irq_packet_read(
struct r8a66597_ep *ep,
1049 struct r8a66597 *r8a66597 = ep->
r8a66597;
1052 pipe_change(r8a66597, pipenum);
1053 tmp = r8a66597_read(r8a66597, ep->
fifoctr);
1056 pipe_stop(r8a66597, pipenum);
1057 pipe_irq_disable(r8a66597, pipenum);
1063 rcv_len = tmp &
DTLN;
1064 bufsize = get_buffer_size(r8a66597, pipenum);
1066 buf = req->
req.buf + req->
req.actual;
1067 req_len = req->
req.length - req->
req.actual;
1068 if (rcv_len < bufsize)
1069 size =
min(rcv_len, req_len);
1071 size =
min(bufsize, req_len);
1077 if ((!req->
req.zero && (req->
req.actual == req->
req.length))
1078 || (size % ep->
ep.maxpacket)
1080 pipe_stop(r8a66597, pipenum);
1081 pipe_irq_disable(r8a66597, pipenum);
1090 r8a66597_read_fifo(r8a66597, ep->
fifoaddr, buf, size);
1094 if ((ep->
pipenum != 0) && finish)
1095 transfer_complete(ep, req, 0);
1098 static void irq_pipe_ready(
struct r8a66597 *r8a66597,
u16 status,
u16 enb)
1105 if ((status &
BRDY0) && (enb & BRDY0)) {
1106 r8a66597_write(r8a66597, ~BRDY0,
BRDYSTS);
1109 ep = &r8a66597->
ep[0];
1110 req = get_request_from_ep(ep);
1111 irq_packet_read(ep, req);
1114 check = 1 << pipenum;
1115 if ((status & check) && (enb & check)) {
1116 r8a66597_write(r8a66597, ~check,
BRDYSTS);
1118 req = get_request_from_ep(ep);
1120 irq_packet_write(ep, req);
1122 irq_packet_read(ep, req);
1128 static void irq_pipe_empty(
struct r8a66597 *r8a66597,
u16 status,
u16 enb)
1136 if ((status &
BEMP0) && (enb & BEMP0)) {
1137 r8a66597_write(r8a66597, ~BEMP0,
BEMPSTS);
1139 ep = &r8a66597->
ep[0];
1140 req = get_request_from_ep(ep);
1141 irq_ep0_write(ep, req);
1144 check = 1 << pipenum;
1145 if ((status & check) && (enb & check)) {
1146 r8a66597_write(r8a66597, ~check,
BEMPSTS);
1147 tmp = control_reg_get(r8a66597, pipenum);
1148 if ((tmp &
INBUFM) == 0) {
1150 pipe_irq_disable(r8a66597, pipenum);
1151 pipe_stop(r8a66597, pipenum);
1153 req = get_request_from_ep(ep);
1154 if (!list_empty(&ep->
queue))
1155 transfer_complete(ep, req, 0);
1180 pid = control_reg_get_pid(r8a66597, ep->
pipenum);
1187 pipe_stall(r8a66597, 0);
1193 r8a66597->
ep0_req->length = 2;
1195 spin_unlock(&r8a66597->
lock);
1197 spin_lock(&r8a66597->
lock);
1200 static void clear_feature(
struct r8a66597 *r8a66597,
1205 control_end(r8a66597, 1);
1208 control_end(r8a66597, 1);
1217 pipe_stop(r8a66597, ep->
pipenum);
1218 control_reg_sqclr(r8a66597, ep->
pipenum);
1219 spin_unlock(&r8a66597->
lock);
1220 usb_ep_clear_halt(&ep->
ep);
1221 spin_lock(&r8a66597->
lock);
1224 control_end(r8a66597, 1);
1226 req = get_request_from_ep(ep);
1229 if (list_empty(&ep->
queue))
1231 start_packet(ep, req);
1232 }
else if (!list_empty(&ep->
queue))
1233 pipe_start(r8a66597, ep->
pipenum);
1237 pipe_stall(r8a66597, 0);
1242 static void set_feature(
struct r8a66597 *r8a66597,
struct usb_ctrlrequest *ctrl)
1251 control_end(r8a66597, 1);
1256 }
while (tmp !=
CS_IDST || timeout-- > 0);
1264 pipe_stall(r8a66597, 0);
1269 control_end(r8a66597, 1);
1276 pipe_stall(r8a66597, ep->
pipenum);
1278 control_end(r8a66597, 1);
1282 pipe_stall(r8a66597, 0);
1288 static int setup_packet(
struct r8a66597 *r8a66597,
struct usb_ctrlrequest *ctrl)
1291 unsigned long offset =
USBREQ;
1297 for (i = 0; i < 4; i++)
1298 p[i] = r8a66597_read(r8a66597, offset + i*2);
1307 clear_feature(r8a66597, ctrl);
1310 set_feature(r8a66597, ctrl);
1321 static void r8a66597_update_usb_speed(
struct r8a66597 *r8a66597)
1323 u16 speed = get_usb_speed(r8a66597);
1338 static void irq_device_state(
struct r8a66597 *r8a66597)
1347 spin_unlock(&r8a66597->
lock);
1349 spin_lock(&r8a66597->
lock);
1350 r8a66597_update_usb_speed(r8a66597);
1353 r8a66597_update_usb_speed(r8a66597);
1356 r8a66597_update_usb_speed(r8a66597);
1361 static void irq_control_stage(
struct r8a66597 *r8a66597)
1375 ep = &r8a66597->
ep[0];
1376 req = get_request_from_ep(ep);
1377 transfer_complete(ep, req, 0);
1384 if (setup_packet(r8a66597, &ctrl)) {
1385 spin_unlock(&r8a66597->
lock);
1388 pipe_stall(r8a66597, 0);
1389 spin_lock(&r8a66597->
lock);
1394 control_end(r8a66597, 0);
1398 "ctrl_stage: unexpect ctsq(%x)\n", ctsq);
1403 static void sudmac_finish(
struct r8a66597 *r8a66597,
struct r8a66597_ep *ep)
1411 pipe_change(r8a66597, pipenum);
1413 while (!(r8a66597_read(r8a66597, ep->
fifoctr) & FRDY)) {
1417 "%s: FRDY was not set (%d)\n",
1424 req = get_request_from_ep(ep);
1427 len = r8a66597_sudmac_read(r8a66597,
CH0CBC);
1428 req->
req.actual += len;
1434 if ((!req->
req.zero && (req->
req.actual == req->
req.length))
1435 || (len % ep->
ep.maxpacket)) {
1441 r8a66597_write(r8a66597, ~(1 << pipenum),
BRDYSTS);
1442 transfer_complete(ep, req, 0);
1447 static void r8a66597_sudmac_irq(
struct r8a66597 *r8a66597)
1453 irqsts = r8a66597_sudmac_read(r8a66597,
DINTSTS);
1458 sudmac_finish(r8a66597, ep);
1462 static irqreturn_t r8a66597_irq(
int irq,
void *_r8a66597)
1464 struct r8a66597 *r8a66597 = _r8a66597;
1467 u16 brdysts, nrdysts, bempsts;
1468 u16 brdyenb, nrdyenb, bempenb;
1473 r8a66597_sudmac_irq(r8a66597);
1475 spin_lock(&r8a66597->
lock);
1477 intsts0 = r8a66597_read(r8a66597,
INTSTS0);
1478 intenb0 = r8a66597_read(r8a66597,
INTENB0);
1480 savepipe = r8a66597_read(r8a66597,
CFIFOSEL);
1482 mask0 = intsts0 & intenb0;
1484 brdysts = r8a66597_read(r8a66597,
BRDYSTS);
1485 nrdysts = r8a66597_read(r8a66597,
NRDYSTS);
1486 bempsts = r8a66597_read(r8a66597,
BEMPSTS);
1487 brdyenb = r8a66597_read(r8a66597,
BRDYENB);
1488 nrdyenb = r8a66597_read(r8a66597,
NRDYENB);
1489 bempenb = r8a66597_read(r8a66597,
BEMPENB);
1491 if (mask0 &
VBINT) {
1492 r8a66597_write(r8a66597, 0xffff & ~VBINT,
1494 r8a66597_start_xclock(r8a66597);
1505 irq_device_state(r8a66597);
1507 if ((intsts0 &
BRDY) && (intenb0 &
BRDYE)
1508 && (brdysts & brdyenb))
1509 irq_pipe_ready(r8a66597, brdysts, brdyenb);
1510 if ((intsts0 &
BEMP) && (intenb0 &
BEMPE)
1511 && (bempsts & bempenb))
1512 irq_pipe_empty(r8a66597, bempsts, bempenb);
1515 irq_control_stage(r8a66597);
1518 r8a66597_write(r8a66597, savepipe,
CFIFOSEL);
1520 spin_unlock(&r8a66597->
lock);
1524 static void r8a66597_timer(
unsigned long _r8a66597)
1526 struct r8a66597 *r8a66597 = (
struct r8a66597 *)_r8a66597;
1527 unsigned long flags;
1531 tmp = r8a66597_read(r8a66597,
SYSCFG0);
1532 if (r8a66597->
scount > 0) {
1536 if (r8a66597->
scount == 0) {
1538 r8a66597_usb_connect(r8a66597);
1540 r8a66597_usb_disconnect(r8a66597);
1552 spin_unlock_irqrestore(&r8a66597->
lock, flags);
1556 static int r8a66597_enable(
struct usb_ep *_ep,
1562 return alloc_pipe_config(ep, desc);
1565 static int r8a66597_disable(
struct usb_ep *_ep)
1569 unsigned long flags;
1574 while (!list_empty(&ep->
queue)) {
1575 req = get_request_from_ep(ep);
1578 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1582 return free_pipe_config(ep);
1594 INIT_LIST_HEAD(&req->
queue);
1612 unsigned long flags;
1623 if (list_empty(&ep->
queue))
1627 req->
req.actual = 0;
1633 if (request && !ep->
busy)
1634 start_packet(ep, req);
1637 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1646 unsigned long flags;
1652 if (!list_empty(&ep->
queue))
1654 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1659 static int r8a66597_set_halt(
struct usb_ep *_ep,
int value)
1663 unsigned long flags;
1667 req = get_request_from_ep(ep);
1670 if (!list_empty(&ep->
queue)) {
1684 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1688 static int r8a66597_set_wedge(
struct usb_ep *_ep)
1691 unsigned long flags;
1695 if (!ep || !ep->
ep.desc)
1700 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1702 return usb_ep_set_halt(_ep);
1705 static void r8a66597_fifo_flush(
struct usb_ep *_ep)
1708 unsigned long flags;
1712 if (list_empty(&ep->
queue) && !ep->
busy) {
1718 spin_unlock_irqrestore(&ep->
r8a66597->lock, flags);
1722 .enable = r8a66597_enable,
1723 .disable = r8a66597_disable,
1725 .alloc_request = r8a66597_alloc_request,
1726 .free_request = r8a66597_free_request,
1728 .queue = r8a66597_queue,
1729 .dequeue = r8a66597_dequeue,
1731 .set_halt = r8a66597_set_halt,
1732 .set_wedge = r8a66597_set_wedge,
1733 .fifo_flush = r8a66597_fifo_flush,
1737 static int r8a66597_start(
struct usb_gadget *gadget,
1752 init_controller(r8a66597);
1755 r8a66597_start_xclock(r8a66597);
1757 r8a66597->
old_vbus = r8a66597_read(r8a66597,
1766 static int r8a66597_stop(
struct usb_gadget *gadget,
1770 unsigned long flags;
1774 disable_controller(r8a66597);
1775 spin_unlock_irqrestore(&r8a66597->
lock, flags);
1782 static int r8a66597_get_frame(
struct usb_gadget *_gadget)
1785 return r8a66597_read(r8a66597,
FRMNUM) & 0x03FF;
1788 static int r8a66597_pullup(
struct usb_gadget *gadget,
int is_on)
1791 unsigned long flags;
1798 spin_unlock_irqrestore(&r8a66597->
lock, flags);
1803 static int r8a66597_set_selfpowered(
struct usb_gadget *gadget,
int is_self)
1816 .get_frame = r8a66597_get_frame,
1817 .udc_start = r8a66597_start,
1818 .udc_stop = r8a66597_stop,
1819 .pullup = r8a66597_pullup,
1820 .set_selfpowered = r8a66597_set_selfpowered,
1830 if (r8a66597->
pdata->sudmac)
1833 r8a66597_free_request(&r8a66597->
ep[0].ep, r8a66597->
ep0_req);
1835 if (r8a66597->
pdata->on_chip) {
1849 static int __init r8a66597_sudmac_ioremap(
struct r8a66597 *r8a66597,
1856 dev_err(&pdev->
dev,
"platform_get_resource error(sudmac).\n");
1862 dev_err(&pdev->
dev,
"ioremap error(sudmac).\n");
1875 struct r8a66597 *r8a66597 =
NULL;
1878 unsigned long irq_trigger;
1883 dev_err(&pdev->
dev,
"platform_get_resource error.\n");
1893 dev_err(&pdev->
dev,
"platform_get_irq error.\n");
1905 r8a66597 = kzalloc(
sizeof(
struct r8a66597),
GFP_KERNEL);
1906 if (r8a66597 ==
NULL) {
1914 r8a66597->
pdata = pdev->
dev.platform_data;
1917 r8a66597->
gadget.ops = &r8a66597_gadget_ops;
1920 r8a66597->
gadget.dev.parent = &pdev->
dev;
1921 r8a66597->
gadget.dev.dma_mask = pdev->
dev.dma_mask;
1922 r8a66597->
gadget.dev.release = pdev->
dev.release;
1923 r8a66597->
gadget.name = udc_name;
1926 dev_err(&pdev->
dev,
"device_register failed\n");
1931 r8a66597->
timer.function = r8a66597_timer;
1932 r8a66597->
timer.data = (
unsigned long)r8a66597;
1935 if (r8a66597->
pdata->on_chip) {
1936 snprintf(clk_name,
sizeof(clk_name),
"usb%d", pdev->
id);
1938 if (IS_ERR(r8a66597->
clk)) {
1939 dev_err(&pdev->
dev,
"cannot get clock \"%s\"\n",
1941 ret = PTR_ERR(r8a66597->
clk);
1947 if (r8a66597->
pdata->sudmac) {
1948 ret = r8a66597_sudmac_ioremap(r8a66597, pdev);
1953 disable_controller(r8a66597);
1956 udc_name, r8a66597);
1958 dev_err(&pdev->
dev,
"request_irq error (%d)\n", ret);
1962 INIT_LIST_HEAD(&r8a66597->
gadget.ep_list);
1963 r8a66597->
gadget.ep0 = &r8a66597->
ep[0].ep;
1964 INIT_LIST_HEAD(&r8a66597->
gadget.ep0->ep_list);
1969 INIT_LIST_HEAD(&r8a66597->
ep[i].ep.ep_list);
1971 &r8a66597->
gadget.ep_list);
1974 INIT_LIST_HEAD(&ep->
queue);
1975 ep->
ep.name = r8a66597_ep_name[
i];
1976 ep->
ep.ops = &r8a66597_ep_ops;
1977 ep->
ep.maxpacket = 512;
1979 r8a66597->
ep[0].ep.maxpacket = 64;
1980 r8a66597->
ep[0].pipenum = 0;
1981 r8a66597->
ep[0].fifoaddr =
CFIFO;
1988 r8a66597->
ep0_req = r8a66597_alloc_request(&r8a66597->
ep[0].ep,
1992 r8a66597->
ep0_req->complete = nop_completion;
2002 r8a66597_free_request(&r8a66597->
ep[0].ep, r8a66597->
ep0_req);
2006 if (r8a66597->
pdata->on_chip) {
2017 r8a66597_free_request(&r8a66597->
ep[0].ep,
2029 .remove =
__exit_p(r8a66597_remove),
2031 .name = (
char *) udc_name,
2036 static int __init r8a66597_udc_init(
void)
2042 static void __exit r8a66597_udc_cleanup(
void)