Lines Matching refs:r8a66597
35 #include "r8a66597-udc.h"
45 static void disable_controller(struct r8a66597 *r8a66597);
56 static inline u16 get_usb_speed(struct r8a66597 *r8a66597)
58 return r8a66597_read(r8a66597, DVSTCTR0) & RHST;
61 static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
66 tmp = r8a66597_read(r8a66597, INTENB0);
67 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE,
69 r8a66597_bset(r8a66597, (1 << pipenum), reg);
70 r8a66597_write(r8a66597, tmp, INTENB0);
73 static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
78 tmp = r8a66597_read(r8a66597, INTENB0);
79 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE,
81 r8a66597_bclr(r8a66597, (1 << pipenum), reg);
82 r8a66597_write(r8a66597, tmp, INTENB0);
85 static void r8a66597_usb_connect(struct r8a66597 *r8a66597)
87 r8a66597_bset(r8a66597, CTRE, INTENB0);
88 r8a66597_bset(r8a66597, BEMPE | BRDYE, INTENB0);
90 r8a66597_bset(r8a66597, DPRPU, SYSCFG0);
93 static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597)
94 __releases(r8a66597->lock)
95 __acquires(r8a66597->lock)
97 r8a66597_bclr(r8a66597, CTRE, INTENB0);
98 r8a66597_bclr(r8a66597, BEMPE | BRDYE, INTENB0);
99 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
101 r8a66597->gadget.speed = USB_SPEED_UNKNOWN;
102 spin_unlock(&r8a66597->lock);
103 r8a66597->driver->disconnect(&r8a66597->gadget);
104 spin_lock(&r8a66597->lock);
106 disable_controller(r8a66597);
107 INIT_LIST_HEAD(&r8a66597->ep[0].queue);
110 static inline u16 control_reg_get_pid(struct r8a66597 *r8a66597, u16 pipenum)
116 pid = r8a66597_read(r8a66597, DCPCTR) & PID;
119 pid = r8a66597_read(r8a66597, offset) & PID;
126 static inline void control_reg_set_pid(struct r8a66597 *r8a66597, u16 pipenum,
132 r8a66597_mdfy(r8a66597, pid, PID, DCPCTR);
135 r8a66597_mdfy(r8a66597, pid, PID, offset);
140 static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum)
142 control_reg_set_pid(r8a66597, pipenum, PID_BUF);
145 static inline void pipe_stop(struct r8a66597 *r8a66597, u16 pipenum)
147 control_reg_set_pid(r8a66597, pipenum, PID_NAK);
150 static inline void pipe_stall(struct r8a66597 *r8a66597, u16 pipenum)
152 control_reg_set_pid(r8a66597, pipenum, PID_STALL);
155 static inline u16 control_reg_get(struct r8a66597 *r8a66597, u16 pipenum)
161 ret = r8a66597_read(r8a66597, DCPCTR);
164 ret = r8a66597_read(r8a66597, offset);
171 static inline void control_reg_sqclr(struct r8a66597 *r8a66597, u16 pipenum)
175 pipe_stop(r8a66597, pipenum);
178 r8a66597_bset(r8a66597, SQCLR, DCPCTR);
181 r8a66597_bset(r8a66597, SQCLR, offset);
186 static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum)
192 tmp = r8a66597_read(r8a66597, DCPCFG);
196 tmp = r8a66597_read(r8a66597, DCPMAXP);
200 r8a66597_write(r8a66597, pipenum, PIPESEL);
201 tmp = r8a66597_read(r8a66597, PIPECFG);
203 tmp = r8a66597_read(r8a66597, PIPEBUF);
206 tmp = r8a66597_read(r8a66597, PIPEMAXP);
214 static inline unsigned short mbw_value(struct r8a66597 *r8a66597)
216 if (r8a66597->pdata->on_chip)
222 static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum)
224 struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum];
229 r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel);
233 r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel);
236 static int pipe_buffer_setting(struct r8a66597 *r8a66597,
245 r8a66597_write(r8a66597, info->pipe, PIPESEL);
277 pr_err(KERN_ERR "r8a66597 pipe memory is insufficient\n");
281 r8a66597_write(r8a66597, pipecfg, PIPECFG);
282 r8a66597_write(r8a66597, (buf_bsize << 10) | (bufnum), PIPEBUF);
283 r8a66597_write(r8a66597, info->maxpacket, PIPEMAXP);
286 r8a66597_write(r8a66597, info->interval, PIPEPERI);
291 static void pipe_buffer_release(struct r8a66597 *r8a66597,
298 r8a66597->bulk--;
300 r8a66597->interrupt--;
302 r8a66597->isochronous--;
304 r8a66597->bulk--;
312 struct r8a66597 *r8a66597 = ep->r8a66597;
314 r8a66597_mdfy(r8a66597, 0, CURPIPE, ep->fifosel);
316 r8a66597_write(r8a66597, ACLRM, ep->pipectr);
317 r8a66597_write(r8a66597, 0, ep->pipectr);
318 r8a66597_write(r8a66597, SQCLR, ep->pipectr);
320 r8a66597_mdfy(r8a66597, ep->pipenum, CURPIPE, ep->fifosel);
324 r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel);
328 static void r8a66597_ep_setting(struct r8a66597 *r8a66597,
342 r8a66597->pipenum2ep[pipenum] = ep;
343 r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK]
350 struct r8a66597 *r8a66597 = ep->r8a66597;
357 r8a66597->num_dma--;
366 struct r8a66597 *r8a66597 = ep->r8a66597;
379 if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) {
380 if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) {
385 + r8a66597->isochronous;
386 counter = &r8a66597->isochronous;
389 info.pipe = R8A66597_BASE_PIPENUM_BULK + r8a66597->bulk;
390 counter = &r8a66597->bulk;
396 if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) {
400 info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt;
402 counter = &r8a66597->interrupt;
405 if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) {
409 info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous;
411 counter = &r8a66597->isochronous;
427 ret = pipe_buffer_setting(r8a66597, &info);
434 if ((counter == &r8a66597->isochronous) && info.type == R8A66597_BULK)
435 r8a66597->bulk++;
437 r8a66597_ep_setting(r8a66597, ep, desc, info.pipe, dma);
445 struct r8a66597 *r8a66597 = ep->r8a66597;
450 pipe_buffer_release(r8a66597, &info);
457 static void pipe_irq_enable(struct r8a66597 *r8a66597, u16 pipenum)
459 enable_irq_ready(r8a66597, pipenum);
460 enable_irq_nrdy(r8a66597, pipenum);
463 static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
465 disable_irq_ready(r8a66597, pipenum);
466 disable_irq_nrdy(r8a66597, pipenum);
470 static void control_end(struct r8a66597 *r8a66597, unsigned ccpl)
472 r8a66597->ep[0].internal_ccpl = ccpl;
473 pipe_start(r8a66597, 0);
474 r8a66597_bset(r8a66597, CCPL, DCPCTR);
480 struct r8a66597 *r8a66597 = ep->r8a66597;
482 pipe_change(r8a66597, ep->pipenum);
483 r8a66597_mdfy(r8a66597, ISEL, (ISEL | CURPIPE), CFIFOSEL);
484 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
486 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
487 pipe_start(r8a66597, 0);
490 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
498 struct r8a66597 *r8a66597 = ep->r8a66597;
501 pipe_change(r8a66597, ep->pipenum);
502 disable_irq_empty(r8a66597, ep->pipenum);
503 pipe_start(r8a66597, ep->pipenum);
505 tmp = r8a66597_read(r8a66597, ep->fifoctr);
507 pipe_irq_enable(r8a66597, ep->pipenum);
515 struct r8a66597 *r8a66597 = ep->r8a66597;
519 r8a66597_mdfy(r8a66597, 0, (ISEL | CURPIPE), CFIFOSEL);
520 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
521 pipe_start(r8a66597, pipenum);
522 pipe_irq_enable(r8a66597, pipenum);
525 r8a66597_bset(r8a66597, TRCLR, ep->fifosel);
526 pipe_change(r8a66597, pipenum);
527 r8a66597_bset(r8a66597, TRENB, ep->fifosel);
528 r8a66597_write(r8a66597,
533 pipe_start(r8a66597, pipenum); /* trigger once */
534 pipe_irq_enable(r8a66597, pipenum);
550 ctsq = r8a66597_read(ep->r8a66597, INTSTS0) & CTSQ;
561 control_end(ep->r8a66597, 0);
569 static void init_controller(struct r8a66597 *r8a66597)
571 u16 vif = r8a66597->pdata->vif ? LDRV : 0;
572 u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0;
573 u16 endian = r8a66597->pdata->endian ? BIGEND : 0;
575 if (r8a66597->pdata->on_chip) {
576 r8a66597_bset(r8a66597, 0x04, SYSCFG1);
577 r8a66597_bset(r8a66597, HSE, SYSCFG0);
579 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
580 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
581 r8a66597_bset(r8a66597, USBE, SYSCFG0);
583 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
585 r8a66597_bset(r8a66597, irq_sense, INTENB1);
586 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR,
589 r8a66597_bset(r8a66597, vif | endian, PINCFG);
590 r8a66597_bset(r8a66597, HSE, SYSCFG0); /* High spd */
591 r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata),
594 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
595 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
596 r8a66597_bset(r8a66597, USBE, SYSCFG0);
598 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
602 r8a66597_bset(r8a66597, PLLC, SYSCFG0);
606 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
608 r8a66597_bset(r8a66597, irq_sense, INTENB1);
609 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR,
614 static void disable_controller(struct r8a66597 *r8a66597)
616 if (r8a66597->pdata->on_chip) {
617 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
620 r8a66597_write(r8a66597, 0, INTENB0);
621 r8a66597_write(r8a66597, 0, INTENB1);
622 r8a66597_write(r8a66597, 0, BRDYENB);
623 r8a66597_write(r8a66597, 0, BEMPENB);
624 r8a66597_write(r8a66597, 0, NRDYENB);
627 r8a66597_write(r8a66597, 0, BRDYSTS);
628 r8a66597_write(r8a66597, 0, NRDYSTS);
629 r8a66597_write(r8a66597, 0, BEMPSTS);
631 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
632 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
635 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
637 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
640 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
644 static void r8a66597_start_xclock(struct r8a66597 *r8a66597)
648 if (!r8a66597->pdata->on_chip) {
649 tmp = r8a66597_read(r8a66597, SYSCFG0);
651 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
663 __releases(r8a66597->lock)
664 __acquires(r8a66597->lock)
676 if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
684 spin_unlock(&ep->r8a66597->lock);
686 spin_lock(&ep->r8a66597->lock);
703 struct r8a66597 *r8a66597 = ep->r8a66597;
705 pipe_change(r8a66597, pipenum);
706 r8a66597_bset(r8a66597, ISEL, ep->fifosel);
710 tmp = r8a66597_read(r8a66597, ep->fifoctr);
720 bufsize = get_buffer_size(r8a66597, pipenum);
727 r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size);
729 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
739 disable_irq_ready(r8a66597, pipenum);
740 disable_irq_empty(r8a66597, pipenum);
742 disable_irq_ready(r8a66597, pipenum);
743 enable_irq_empty(r8a66597, pipenum);
745 pipe_start(r8a66597, pipenum);
756 struct r8a66597 *r8a66597 = ep->r8a66597;
758 pipe_change(r8a66597, pipenum);
759 tmp = r8a66597_read(r8a66597, ep->fifoctr);
761 pipe_stop(r8a66597, pipenum);
762 pipe_irq_disable(r8a66597, pipenum);
768 bufsize = get_buffer_size(r8a66597, pipenum);
774 r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size);
779 r8a66597_bset(r8a66597, BVAL, ep->fifoctr);
788 disable_irq_ready(r8a66597, pipenum);
789 enable_irq_empty(r8a66597, pipenum);
791 disable_irq_empty(r8a66597, pipenum);
792 pipe_irq_enable(r8a66597, pipenum);
804 struct r8a66597 *r8a66597 = ep->r8a66597;
807 pipe_change(r8a66597, pipenum);
808 tmp = r8a66597_read(r8a66597, ep->fifoctr);
811 pipe_stop(r8a66597, pipenum);
812 pipe_irq_disable(r8a66597, pipenum);
819 bufsize = get_buffer_size(r8a66597, pipenum);
835 pipe_stop(r8a66597, pipenum);
836 pipe_irq_disable(r8a66597, pipenum);
843 r8a66597_write(r8a66597, BCLR, ep->fifoctr);
845 r8a66597_read_fifo(r8a66597, ep->fifoaddr, buf, size);
853 static void irq_pipe_ready(struct r8a66597 *r8a66597, u16 status, u16 enb)
861 r8a66597_write(r8a66597, ~BRDY0, BRDYSTS);
862 r8a66597_mdfy(r8a66597, 0, CURPIPE, CFIFOSEL);
864 ep = &r8a66597->ep[0];
871 r8a66597_write(r8a66597, ~check, BRDYSTS);
872 ep = r8a66597->pipenum2ep[pipenum];
883 static void irq_pipe_empty(struct r8a66597 *r8a66597, u16 status, u16 enb)
892 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
894 ep = &r8a66597->ep[0];
901 r8a66597_write(r8a66597, ~check, BEMPSTS);
902 tmp = control_reg_get(r8a66597, pipenum);
904 disable_irq_empty(r8a66597, pipenum);
905 pipe_irq_disable(r8a66597, pipenum);
906 pipe_stop(r8a66597, pipenum);
907 ep = r8a66597->pipenum2ep[pipenum];
917 static void get_status(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
918 __releases(r8a66597->lock)
919 __acquires(r8a66597->lock)
934 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
935 pid = control_reg_get_pid(r8a66597, ep->pipenum);
942 pipe_stall(r8a66597, 0);
946 r8a66597->ep0_data = cpu_to_le16(status);
947 r8a66597->ep0_req->buf = &r8a66597->ep0_data;
948 r8a66597->ep0_req->length = 2;
950 spin_unlock(&r8a66597->lock);
951 r8a66597_queue(r8a66597->gadget.ep0, r8a66597->ep0_req, GFP_KERNEL);
952 spin_lock(&r8a66597->lock);
955 static void clear_feature(struct r8a66597 *r8a66597,
960 control_end(r8a66597, 1);
963 control_end(r8a66597, 1);
970 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
972 pipe_stop(r8a66597, ep->pipenum);
973 control_reg_sqclr(r8a66597, ep->pipenum);
974 spin_unlock(&r8a66597->lock);
976 spin_lock(&r8a66597->lock);
979 control_end(r8a66597, 1);
988 pipe_start(r8a66597, ep->pipenum);
992 pipe_stall(r8a66597, 0);
997 static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
1002 control_end(r8a66597, 1);
1005 control_end(r8a66597, 1);
1011 ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
1012 pipe_stall(r8a66597, ep->pipenum);
1014 control_end(r8a66597, 1);
1018 pipe_stall(r8a66597, 0);
1024 static int setup_packet(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
1031 r8a66597_write(r8a66597, ~VALID, INTSTS0);
1034 p[i] = r8a66597_read(r8a66597, offset + i*2);
1040 get_status(r8a66597, ctrl);
1043 clear_feature(r8a66597, ctrl);
1046 set_feature(r8a66597, ctrl);
1057 static void r8a66597_update_usb_speed(struct r8a66597 *r8a66597)
1059 u16 speed = get_usb_speed(r8a66597);
1063 r8a66597->gadget.speed = USB_SPEED_HIGH;
1066 r8a66597->gadget.speed = USB_SPEED_FULL;
1069 r8a66597->gadget.speed = USB_SPEED_UNKNOWN;
1074 static void irq_device_state(struct r8a66597 *r8a66597)
1078 dvsq = r8a66597_read(r8a66597, INTSTS0) & DVSQ;
1079 r8a66597_write(r8a66597, ~DVST, INTSTS0);
1083 r8a66597->driver->disconnect(&r8a66597->gadget);
1084 r8a66597_update_usb_speed(r8a66597);
1086 if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG)
1087 r8a66597_update_usb_speed(r8a66597);
1089 && r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
1090 r8a66597_update_usb_speed(r8a66597);
1092 r8a66597->old_dvsq = dvsq;
1095 static void irq_control_stage(struct r8a66597 *r8a66597)
1096 __releases(r8a66597->lock)
1097 __acquires(r8a66597->lock)
1102 ctsq = r8a66597_read(r8a66597, INTSTS0) & CTSQ;
1103 r8a66597_write(r8a66597, ~CTRT, INTSTS0);
1109 ep = &r8a66597->ep[0];
1118 if (setup_packet(r8a66597, &ctrl)) {
1119 spin_unlock(&r8a66597->lock);
1120 if (r8a66597->driver->setup(&r8a66597->gadget, &ctrl)
1122 pipe_stall(r8a66597, 0);
1123 spin_lock(&r8a66597->lock);
1128 control_end(r8a66597, 0);
1138 struct r8a66597 *r8a66597 = _r8a66597;
1146 spin_lock(&r8a66597->lock);
1148 intsts0 = r8a66597_read(r8a66597, INTSTS0);
1149 intenb0 = r8a66597_read(r8a66597, INTENB0);
1151 savepipe = r8a66597_read(r8a66597, CFIFOSEL);
1155 brdysts = r8a66597_read(r8a66597, BRDYSTS);
1156 nrdysts = r8a66597_read(r8a66597, NRDYSTS);
1157 bempsts = r8a66597_read(r8a66597, BEMPSTS);
1158 brdyenb = r8a66597_read(r8a66597, BRDYENB);
1159 nrdyenb = r8a66597_read(r8a66597, NRDYENB);
1160 bempenb = r8a66597_read(r8a66597, BEMPENB);
1163 r8a66597_write(r8a66597, 0xffff & ~VBINT,
1165 r8a66597_start_xclock(r8a66597);
1168 r8a66597->old_vbus = r8a66597_read(r8a66597, INTSTS0)
1170 r8a66597->scount = R8A66597_MAX_SAMPLING;
1172 mod_timer(&r8a66597->timer,
1176 irq_device_state(r8a66597);
1180 irq_pipe_ready(r8a66597, brdysts, brdyenb);
1183 irq_pipe_empty(r8a66597, bempsts, bempenb);
1186 irq_control_stage(r8a66597);
1189 r8a66597_write(r8a66597, savepipe, CFIFOSEL);
1191 spin_unlock(&r8a66597->lock);
1197 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1201 spin_lock_irqsave(&r8a66597->lock, flags);
1202 tmp = r8a66597_read(r8a66597, SYSCFG0);
1203 if (r8a66597->scount > 0) {
1204 tmp = r8a66597_read(r8a66597, INTSTS0) & VBSTS;
1205 if (tmp == r8a66597->old_vbus) {
1206 r8a66597->scount--;
1207 if (r8a66597->scount == 0) {
1209 r8a66597_usb_connect(r8a66597);
1211 r8a66597_usb_disconnect(r8a66597);
1213 mod_timer(&r8a66597->timer,
1217 r8a66597->scount = R8A66597_MAX_SAMPLING;
1218 r8a66597->old_vbus = tmp;
1219 mod_timer(&r8a66597->timer,
1223 spin_unlock_irqrestore(&r8a66597->lock, flags);
1247 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1249 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1252 pipe_irq_disable(ep->r8a66597, ep->pipenum);
1289 if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN)
1292 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1308 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1322 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1325 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1340 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1347 pipe_stall(ep->r8a66597, ep->pipenum);
1351 pipe_stop(ep->r8a66597, ep->pipenum);
1355 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1369 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1371 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1382 spin_lock_irqsave(&ep->r8a66597->lock, flags);
1384 pipe_stop(ep->r8a66597, ep->pipenum);
1385 r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr);
1387 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1406 static struct r8a66597 *the_controller;
1410 struct r8a66597 *r8a66597 = the_controller;
1418 if (!r8a66597)
1420 if (r8a66597->driver)
1425 r8a66597->driver = driver;
1426 r8a66597->gadget.dev.driver = &driver->driver;
1428 retval = device_add(&r8a66597->gadget.dev);
1434 retval = driver->bind(&r8a66597->gadget);
1437 device_del(&r8a66597->gadget.dev);
1441 r8a66597_bset(r8a66597, VBSE, INTENB0);
1442 if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) {
1443 r8a66597_start_xclock(r8a66597);
1445 r8a66597->old_vbus = r8a66597_read(r8a66597,
1447 r8a66597->scount = R8A66597_MAX_SAMPLING;
1448 mod_timer(&r8a66597->timer, jiffies + msecs_to_jiffies(50));
1454 r8a66597->driver = NULL;
1455 r8a66597->gadget.dev.driver = NULL;
1463 struct r8a66597 *r8a66597 = the_controller;
1466 if (driver != r8a66597->driver || !driver->unbind)
1469 spin_lock_irqsave(&r8a66597->lock, flags);
1470 if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN)
1471 r8a66597_usb_disconnect(r8a66597);
1472 spin_unlock_irqrestore(&r8a66597->lock, flags);
1474 r8a66597_bclr(r8a66597, VBSE, INTENB0);
1476 driver->unbind(&r8a66597->gadget);
1478 init_controller(r8a66597);
1479 disable_controller(r8a66597);
1481 device_del(&r8a66597->gadget.dev);
1482 r8a66597->driver = NULL;
1490 struct r8a66597 *r8a66597 = gadget_to_r8a66597(_gadget);
1491 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
1500 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
1502 del_timer_sync(&r8a66597->timer);
1503 iounmap(r8a66597->reg);
1504 free_irq(platform_get_irq(pdev, 0), r8a66597);
1505 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
1507 if (r8a66597->pdata->on_chip) {
1508 clk_disable(r8a66597->clk);
1509 clk_put(r8a66597->clk);
1512 kfree(r8a66597);
1528 struct r8a66597 *r8a66597 = NULL;
1558 r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL);
1559 if (r8a66597 == NULL) {
1565 spin_lock_init(&r8a66597->lock);
1566 dev_set_drvdata(&pdev->dev, r8a66597);
1567 r8a66597->pdata = pdev->dev.platform_data;
1568 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1570 r8a66597->gadget.ops = &r8a66597_gadget_ops;
1571 device_initialize(&r8a66597->gadget.dev);
1572 dev_set_name(&r8a66597->gadget.dev, "gadget");
1573 r8a66597->gadget.is_dualspeed = 1;
1574 r8a66597->gadget.dev.parent = &pdev->dev;
1575 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask;
1576 r8a66597->gadget.dev.release = pdev->dev.release;
1577 r8a66597->gadget.name = udc_name;
1579 init_timer(&r8a66597->timer);
1580 r8a66597->timer.function = r8a66597_timer;
1581 r8a66597->timer.data = (unsigned long)r8a66597;
1582 r8a66597->reg = reg;
1585 if (r8a66597->pdata->on_chip) {
1587 r8a66597->clk = clk_get(&pdev->dev, clk_name);
1588 if (IS_ERR(r8a66597->clk)) {
1591 ret = PTR_ERR(r8a66597->clk);
1594 clk_enable(r8a66597->clk);
1598 disable_controller(r8a66597); /* make sure controller is disabled */
1601 udc_name, r8a66597);
1607 INIT_LIST_HEAD(&r8a66597->gadget.ep_list);
1608 r8a66597->gadget.ep0 = &r8a66597->ep[0].ep;
1609 INIT_LIST_HEAD(&r8a66597->gadget.ep0->ep_list);
1611 struct r8a66597_ep *ep = &r8a66597->ep[i];
1614 INIT_LIST_HEAD(&r8a66597->ep[i].ep.ep_list);
1615 list_add_tail(&r8a66597->ep[i].ep.ep_list,
1616 &r8a66597->gadget.ep_list);
1618 ep->r8a66597 = r8a66597;
1624 r8a66597->ep[0].ep.maxpacket = 64;
1625 r8a66597->ep[0].pipenum = 0;
1626 r8a66597->ep[0].fifoaddr = CFIFO;
1627 r8a66597->ep[0].fifosel = CFIFOSEL;
1628 r8a66597->ep[0].fifoctr = CFIFOCTR;
1629 r8a66597->ep[0].fifotrn = 0;
1630 r8a66597->ep[0].pipectr = get_pipectr_addr(0);
1631 r8a66597->pipenum2ep[0] = &r8a66597->ep[0];
1632 r8a66597->epaddr2ep[0] = &r8a66597->ep[0];
1634 the_controller = r8a66597;
1636 r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep,
1638 if (r8a66597->ep0_req == NULL)
1640 r8a66597->ep0_req->complete = nop_completion;
1642 init_controller(r8a66597);
1648 free_irq(irq, r8a66597);
1651 if (r8a66597->pdata->on_chip) {
1652 clk_disable(r8a66597->clk);
1653 clk_put(r8a66597->clk);
1657 if (r8a66597) {
1658 if (r8a66597->ep0_req)
1659 r8a66597_free_request(&r8a66597->ep[0].ep,
1660 r8a66597->ep0_req);
1661 kfree(r8a66597);