Lines Matching +full:ep +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
6 * at91_udc -- driver for at91-series USB peripheral controller
31 * This controller is simple and PIO-only. It's used in many AT91-series
33 * at91sam926x (arm926ejs, with MMU), and several no-mmu versions.
35 * This driver expects the board has been wired with two GPIOs supporting
55 "ep3-int",
62 __raw_readl((udc)->udp_baseaddr + (reg))
64 __raw_writel((val), (udc)->udp_baseaddr + (reg))
68 /*-------------------------------------------------------------------------*/
70 static void done(struct at91_ep *ep, struct at91_request *req, int status) in done() argument
72 unsigned stopped = ep->stopped; in done()
73 struct at91_udc *udc = ep->udc; in done()
75 list_del_init(&req->queue); in done()
76 if (req->req.status == -EINPROGRESS) in done()
77 req->req.status = status; in done()
79 status = req->req.status; in done()
80 if (status && status != -ESHUTDOWN) in done()
81 VDBG("%s done %p, status %d\n", ep->ep.name, req, status); in done()
83 ep->stopped = 1; in done()
84 spin_unlock(&udc->lock); in done()
85 req->req.complete(&ep->ep, &req->req); in done()
86 spin_lock(&udc->lock); in done()
87 ep->stopped = stopped; in done()
89 /* ep0 is always ready; other endpoints need a non-empty queue */ in done()
90 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0)) in done()
91 at91_udp_write(udc, AT91_UDP_IDR, ep->int_mask); in done()
94 /*-------------------------------------------------------------------------*/
105 * - clear SET_FX bits (setting them could change something)
106 * - set CLR_FX bits (clearing them could change something)
114 * infrequently we write, except maybe for write-then-read idioms.
121 static int read_fifo (struct at91_ep *ep, struct at91_request *req) in read_fifo() argument
123 u32 __iomem *creg = ep->creg; in read_fifo()
124 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in read_fifo()
129 buf = req->req.buf + req->req.actual; in read_fifo()
130 bufferspace = req->req.length - req->req.actual; in read_fifo()
142 if (count > ep->ep.maxpacket) in read_fifo()
143 count = ep->ep.maxpacket; in read_fifo()
145 DBG("%s buffer overflow\n", ep->ep.name); in read_fifo()
146 req->req.status = -EOVERFLOW; in read_fifo()
153 if (ep->is_pingpong) { in read_fifo()
154 if (ep->fifo_bank == 0) { in read_fifo()
156 ep->fifo_bank = 1; in read_fifo()
159 ep->fifo_bank = 0; in read_fifo()
165 req->req.actual += count; in read_fifo()
166 is_done = (count < ep->ep.maxpacket); in read_fifo()
170 PACKET("%s %p out/%d%s\n", ep->ep.name, &req->req, count, in read_fifo()
175 * the fifo ... maybe preventing an extra (expensive) OUT-NAK in read_fifo()
178 done(ep, req, 0); in read_fifo()
179 else if (ep->is_pingpong) { in read_fifo()
187 bufferspace -= count; in read_fifo()
196 static int write_fifo(struct at91_ep *ep, struct at91_request *req) in write_fifo() argument
198 u32 __iomem *creg = ep->creg; in write_fifo()
200 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in write_fifo()
206 * reduce the amount of IN-NAKing, but probably won't affect in write_fifo()
207 * throughput much. (Unlike preventing OUT-NAKing!) in write_fifo()
227 buf = req->req.buf + req->req.actual; in write_fifo()
229 total = req->req.length - req->req.actual; in write_fifo()
230 if (ep->ep.maxpacket < total) { in write_fifo()
231 count = ep->ep.maxpacket; in write_fifo()
235 is_last = (count < ep->ep.maxpacket) || !req->req.zero; in write_fifo()
241 * NOTE: incrementing req->actual before we receive the ACK means in write_fifo()
255 req->req.actual += count; in write_fifo()
257 PACKET("%s %p in/%d%s\n", ep->ep.name, &req->req, count, in write_fifo()
260 done(ep, req, 0); in write_fifo()
264 static void nuke(struct at91_ep *ep, int status) in nuke() argument
269 ep->stopped = 1; in nuke()
270 if (list_empty(&ep->queue)) in nuke()
273 VDBG("%s %s\n", __func__, ep->ep.name); in nuke()
274 while (!list_empty(&ep->queue)) { in nuke()
275 req = list_entry(ep->queue.next, struct at91_request, queue); in nuke()
276 done(ep, req, status); in nuke()
280 /*-------------------------------------------------------------------------*/
285 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); in at91_ep_enable() local
291 if (!_ep || !ep in at91_ep_enable()
292 || !desc || _ep->name == ep0name in at91_ep_enable()
293 || desc->bDescriptorType != USB_DT_ENDPOINT in at91_ep_enable()
295 || maxpacket > ep->maxpacket) { in at91_ep_enable()
296 DBG("bad ep or descriptor\n"); in at91_ep_enable()
297 return -EINVAL; in at91_ep_enable()
300 udc = ep->udc; in at91_ep_enable()
301 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in at91_ep_enable()
303 return -ESHUTDOWN; in at91_ep_enable()
310 return -EINVAL; in at91_ep_enable()
325 return -EINVAL; in at91_ep_enable()
327 if (!ep->is_pingpong) { in at91_ep_enable()
329 return -EINVAL; in at91_ep_enable()
335 spin_lock_irqsave(&udc->lock, flags); in at91_ep_enable()
338 ep->is_in = usb_endpoint_dir_in(desc); in at91_ep_enable()
339 ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); in at91_ep_enable()
340 ep->stopped = 0; in at91_ep_enable()
341 if (ep->is_in) in at91_ep_enable()
345 __raw_writel(tmp, ep->creg); in at91_ep_enable()
347 ep->ep.maxpacket = maxpacket; in at91_ep_enable()
353 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_enable()
356 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_enable()
362 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); in at91_ep_disable() local
363 struct at91_udc *udc = ep->udc; in at91_ep_disable()
366 if (ep == &ep->udc->ep[0]) in at91_ep_disable()
367 return -EINVAL; in at91_ep_disable()
369 spin_lock_irqsave(&udc->lock, flags); in at91_ep_disable()
371 nuke(ep, -ESHUTDOWN); in at91_ep_disable()
374 ep->ep.desc = NULL; in at91_ep_disable()
375 ep->ep.maxpacket = ep->maxpacket; in at91_ep_disable()
378 if (ep->udc->clocked) { in at91_ep_disable()
379 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_disable()
381 __raw_writel(0, ep->creg); in at91_ep_disable()
384 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_disable()
389 * this is a PIO-only driver, so there's nothing
402 INIT_LIST_HEAD(&req->queue); in at91_ep_alloc_request()
403 return &req->req; in at91_ep_alloc_request()
411 BUG_ON(!list_empty(&req->queue)); in at91_ep_free_request()
419 struct at91_ep *ep; in at91_ep_queue() local
425 ep = container_of(_ep, struct at91_ep, ep); in at91_ep_queue()
427 if (!_req || !_req->complete in at91_ep_queue()
428 || !_req->buf || !list_empty(&req->queue)) { in at91_ep_queue()
430 return -EINVAL; in at91_ep_queue()
433 if (!_ep || (!ep->ep.desc && ep->ep.name != ep0name)) { in at91_ep_queue()
434 DBG("invalid ep\n"); in at91_ep_queue()
435 return -EINVAL; in at91_ep_queue()
438 udc = ep->udc; in at91_ep_queue()
440 if (!udc || !udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in at91_ep_queue()
442 return -EINVAL; in at91_ep_queue()
445 _req->status = -EINPROGRESS; in at91_ep_queue()
446 _req->actual = 0; in at91_ep_queue()
448 spin_lock_irqsave(&udc->lock, flags); in at91_ep_queue()
451 if (list_empty(&ep->queue) && !ep->stopped) { in at91_ep_queue()
455 * If this control request has a non-empty DATA stage, this in at91_ep_queue()
456 * will start that stage. It works just like a non-control in at91_ep_queue()
462 is_ep0 = (ep->ep.name == ep0name); in at91_ep_queue()
466 if (!udc->req_pending) { in at91_ep_queue()
467 status = -EINVAL; in at91_ep_queue()
475 if (udc->wait_for_config_ack) { in at91_ep_queue()
481 if (req->req.length == 0) { in at91_ep_queue()
485 tmp = __raw_readl(ep->creg); in at91_ep_queue()
488 __raw_writel(tmp, ep->creg); in at91_ep_queue()
489 udc->req_pending = 0; in at91_ep_queue()
494 if (ep->is_in) in at91_ep_queue()
495 status = write_fifo(ep, req); in at91_ep_queue()
497 status = read_fifo(ep, req); in at91_ep_queue()
507 list_add_tail (&req->queue, &ep->queue); in at91_ep_queue()
508 at91_udp_write(udc, AT91_UDP_IER, ep->int_mask); in at91_ep_queue()
511 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_queue()
517 struct at91_ep *ep; in at91_ep_dequeue() local
521 ep = container_of(_ep, struct at91_ep, ep); in at91_ep_dequeue()
522 if (!_ep || ep->ep.name == ep0name) in at91_ep_dequeue()
523 return -EINVAL; in at91_ep_dequeue()
525 spin_lock_irqsave(&udc->lock, flags); in at91_ep_dequeue()
528 list_for_each_entry (req, &ep->queue, queue) { in at91_ep_dequeue()
529 if (&req->req == _req) in at91_ep_dequeue()
532 if (&req->req != _req) { in at91_ep_dequeue()
533 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_dequeue()
534 return -EINVAL; in at91_ep_dequeue()
537 done(ep, req, -ECONNRESET); in at91_ep_dequeue()
538 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_dequeue()
544 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); in at91_ep_set_halt() local
545 struct at91_udc *udc = ep->udc; in at91_ep_set_halt()
551 if (!_ep || ep->is_iso || !ep->udc->clocked) in at91_ep_set_halt()
552 return -EINVAL; in at91_ep_set_halt()
554 creg = ep->creg; in at91_ep_set_halt()
555 spin_lock_irqsave(&udc->lock, flags); in at91_ep_set_halt()
560 * fail with still-busy IN endpoints, ensuring correct sequencing in at91_ep_set_halt()
564 if (ep->is_in && (!list_empty(&ep->queue) || (csr >> 16) != 0)) in at91_ep_set_halt()
565 status = -EAGAIN; in at91_ep_set_halt()
571 VDBG("halt %s\n", ep->ep.name); in at91_ep_set_halt()
573 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_set_halt()
580 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_set_halt()
595 /*-------------------------------------------------------------------------*/
601 if (!to_udc(gadget)->clocked) in at91_get_frame()
602 return -EINVAL; in at91_get_frame()
610 int status = -EINVAL; in at91_wakeup()
614 spin_lock_irqsave(&udc->lock, flags); in at91_wakeup()
616 if (!udc->clocked || !udc->suspended) in at91_wakeup()
628 spin_unlock_irqrestore(&udc->lock, flags); in at91_wakeup()
637 INIT_LIST_HEAD(&udc->gadget.ep_list); in udc_reinit()
638 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); in udc_reinit()
641 struct at91_ep *ep = &udc->ep[i]; in udc_reinit() local
644 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in udc_reinit()
645 ep->ep.desc = NULL; in udc_reinit()
646 ep->stopped = 0; in udc_reinit()
647 ep->fifo_bank = 0; in udc_reinit()
648 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); in udc_reinit()
649 ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); in udc_reinit()
651 INIT_LIST_HEAD(&ep->queue); in udc_reinit()
657 struct usb_gadget_driver *driver = udc->driver; in reset_gadget()
660 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in reset_gadget()
662 udc->gadget.speed = USB_SPEED_UNKNOWN; in reset_gadget()
663 udc->suspended = 0; in reset_gadget()
666 struct at91_ep *ep = &udc->ep[i]; in reset_gadget() local
668 ep->stopped = 1; in reset_gadget()
669 nuke(ep, -ESHUTDOWN); in reset_gadget()
672 spin_unlock(&udc->lock); in reset_gadget()
673 udc->driver->disconnect(&udc->gadget); in reset_gadget()
674 spin_lock(&udc->lock); in reset_gadget()
682 struct usb_gadget_driver *driver = udc->driver; in stop_activity()
685 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in stop_activity()
687 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
688 udc->suspended = 0; in stop_activity()
691 struct at91_ep *ep = &udc->ep[i]; in stop_activity() local
692 ep->stopped = 1; in stop_activity()
693 nuke(ep, -ESHUTDOWN); in stop_activity()
696 spin_unlock(&udc->lock); in stop_activity()
697 driver->disconnect(&udc->gadget); in stop_activity()
698 spin_lock(&udc->lock); in stop_activity()
706 if (udc->clocked) in clk_on()
708 udc->clocked = 1; in clk_on()
713 if (!udc->clocked) in clk_off()
715 udc->clocked = 0; in clk_off()
716 udc->gadget.speed = USB_SPEED_UNKNOWN; in clk_off()
725 if (!udc->enabled || !udc->vbus) in pullup()
740 if (udc->caps && udc->caps->pullup) in pullup()
741 udc->caps->pullup(udc, is_on); in pullup()
751 spin_lock_irqsave(&udc->lock, flags); in at91_vbus_session()
752 udc->vbus = (is_active != 0); in at91_vbus_session()
753 if (udc->driver) in at91_vbus_session()
757 spin_unlock_irqrestore(&udc->lock, flags); in at91_vbus_session()
766 spin_lock_irqsave(&udc->lock, flags); in at91_pullup()
767 udc->enabled = is_on = !!is_on; in at91_pullup()
769 spin_unlock_irqrestore(&udc->lock, flags); in at91_pullup()
778 spin_lock_irqsave(&udc->lock, flags); in at91_set_selfpowered()
779 udc->selfpowered = (is_on != 0); in at91_set_selfpowered()
780 spin_unlock_irqrestore(&udc->lock, flags); in at91_set_selfpowered()
798 * VBUS-powered devices may also also want to support bigger
804 /*-------------------------------------------------------------------------*/
806 static int handle_ep(struct at91_ep *ep) in handle_ep() argument
809 u32 __iomem *creg = ep->creg; in handle_ep()
812 if (!list_empty(&ep->queue)) in handle_ep()
813 req = list_entry(ep->queue.next, in handle_ep()
818 if (ep->is_in) { in handle_ep()
825 return write_fifo(ep, req); in handle_ep()
830 if (ep->is_iso && req) in handle_ep()
831 req->req.status = -EILSEQ; in handle_ep()
838 return read_fifo(ep, req); in handle_ep()
848 static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) in handle_setup() argument
850 u32 __iomem *creg = ep->creg; in handle_setup()
851 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in handle_setup()
857 /* read and ack SETUP; hard-fail for bogus packets */ in handle_setup()
860 while (rxcount--) in handle_setup()
864 ep->is_in = 1; in handle_setup()
867 ep->is_in = 0; in handle_setup()
872 status = -EINVAL; in handle_setup()
877 udc->wait_for_addr_ack = 0; in handle_setup()
878 udc->wait_for_config_ack = 0; in handle_setup()
879 ep->stopped = 0; in handle_setup()
895 udc->req_pending = 1; in handle_setup()
904 udc->addr = w_value; in handle_setup()
905 udc->wait_for_addr_ack = 1; in handle_setup()
906 udc->req_pending = 0; in handle_setup()
914 udc->wait_for_config_ack = (tmp == 0); in handle_setup()
916 udc->wait_for_config_ack = (tmp != 0); in handle_setup()
917 if (udc->wait_for_config_ack) in handle_setup()
928 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED); in handle_setup()
977 ep = &udc->ep[tmp]; in handle_setup()
978 if (tmp >= NUM_ENDPOINTS || (tmp && !ep->ep.desc)) in handle_setup()
983 if (!ep->is_in) in handle_setup()
985 } else if (ep->is_in) in handle_setup()
988 PACKET("get %s status\n", ep->ep.name); in handle_setup()
989 if (__raw_readl(ep->creg) & AT91_UDP_FORCESTALL) in handle_setup()
1000 ep = &udc->ep[tmp]; in handle_setup()
1003 if (!ep->ep.desc || ep->is_iso) in handle_setup()
1006 if (!ep->is_in) in handle_setup()
1008 } else if (ep->is_in) in handle_setup()
1011 tmp = __raw_readl(ep->creg); in handle_setup()
1014 __raw_writel(tmp, ep->creg); in handle_setup()
1019 ep = &udc->ep[tmp]; in handle_setup()
1024 if (!ep->ep.desc || ep->is_iso) in handle_setup()
1027 if (!ep->is_in) in handle_setup()
1029 } else if (ep->is_in) in handle_setup()
1032 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in handle_setup()
1034 tmp = __raw_readl(ep->creg); in handle_setup()
1037 __raw_writel(tmp, ep->creg); in handle_setup()
1038 if (!list_empty(&ep->queue)) in handle_setup()
1039 handle_ep(ep); in handle_setup()
1048 if (udc->driver) { in handle_setup()
1049 spin_unlock(&udc->lock); in handle_setup()
1050 status = udc->driver->setup(&udc->gadget, &pkt.r); in handle_setup()
1051 spin_lock(&udc->lock); in handle_setup()
1054 status = -ENODEV; in handle_setup()
1061 udc->req_pending = 0; in handle_setup()
1071 udc->req_pending = 0; in handle_setup()
1076 struct at91_ep *ep0 = &udc->ep[0]; in handle_ep0()
1077 u32 __iomem *creg = ep0->creg; in handle_ep0()
1082 nuke(ep0, -EPROTO); in handle_ep0()
1083 udc->req_pending = 0; in handle_ep0()
1092 udc->req_pending = 0; in handle_ep0()
1097 if (list_empty(&ep0->queue)) in handle_ep0()
1100 req = list_entry(ep0->queue.next, struct at91_request, queue); in handle_ep0()
1108 if (req && ep0->is_in) { in handle_ep0()
1110 udc->req_pending = 0; in handle_ep0()
1114 * - last IN DATA packet (including GET_STATUS) in handle_ep0()
1115 * - IN/STATUS for OUT DATA in handle_ep0()
1116 * - IN/STATUS for any zero-length DATA stage in handle_ep0()
1121 udc->req_pending = 0; in handle_ep0()
1128 if (udc->wait_for_addr_ack) { in handle_ep0()
1132 AT91_UDP_FEN | udc->addr); in handle_ep0()
1135 if (udc->addr) in handle_ep0()
1139 udc->wait_for_addr_ack = 0; in handle_ep0()
1140 VDBG("address %d\n", udc->addr); in handle_ep0()
1151 if (!ep0->is_in) { in handle_ep0()
1160 udc->req_pending = 0; in handle_ep0()
1162 } else if (udc->req_pending) { in handle_ep0()
1165 * "deferred response" mode for control-OUT in handle_ep0()
1166 * transfers. (For control-IN it's fine.) in handle_ep0()
1175 * would almost be a non-deferred response, in handle_ep0()
1180 DBG("no control-OUT deferred responses!\n"); in handle_ep0()
1182 udc->req_pending = 0; in handle_ep0()
1185 /* STATUS stage for control-IN; ack. */ in handle_ep0()
1203 spin_lock_irqsave(&udc->lock, flags); in at91_udc_irq()
1205 if (!udc->clocked) { in at91_udc_irq()
1210 while (rescans--) { in at91_udc_irq()
1226 udc->addr = 0; in at91_udc_irq()
1232 udc->gadget.speed = USB_SPEED_FULL; in at91_udc_irq()
1233 udc->suspended = 0; in at91_udc_irq()
1249 if (udc->suspended) in at91_udc_irq()
1251 udc->suspended = 1; in at91_udc_irq()
1254 * NOTE: when suspending a VBUS-powered device, the in at91_udc_irq()
1257 * 500uA power (2500uA for some high-power configs). in at91_udc_irq()
1259 if (udc->driver && udc->driver->suspend) { in at91_udc_irq()
1260 spin_unlock(&udc->lock); in at91_udc_irq()
1261 udc->driver->suspend(&udc->gadget); in at91_udc_irq()
1262 spin_lock(&udc->lock); in at91_udc_irq()
1271 if (!udc->suspended) in at91_udc_irq()
1273 udc->suspended = 0; in at91_udc_irq()
1276 * NOTE: for a VBUS-powered device, the gadget driver in at91_udc_irq()
1280 if (udc->driver && udc->driver->resume) { in at91_udc_irq()
1281 spin_unlock(&udc->lock); in at91_udc_irq()
1282 udc->driver->resume(&udc->gadget); in at91_udc_irq()
1283 spin_lock(&udc->lock); in at91_udc_irq()
1290 struct at91_ep *ep = &udc->ep[1]; in at91_udc_irq() local
1297 handle_ep(ep); in at91_udc_irq()
1298 ep++; in at91_udc_irq()
1306 spin_unlock_irqrestore(&udc->lock, flags); in at91_udc_irq()
1311 /*-------------------------------------------------------------------------*/
1318 udc->driver = driver; in at91_start()
1319 udc->enabled = 1; in at91_start()
1320 udc->selfpowered = 1; in at91_start()
1330 spin_lock_irqsave(&udc->lock, flags); in at91_stop()
1331 udc->enabled = 0; in at91_stop()
1333 spin_unlock_irqrestore(&udc->lock, flags); in at91_stop()
1335 udc->driver = NULL; in at91_stop()
1340 /*-------------------------------------------------------------------------*/
1345 struct at91_ep *ep; in at91sam9260_udc_init() local
1349 ep = &udc->ep[i]; in at91sam9260_udc_init()
1353 ep->maxpacket = 64; in at91sam9260_udc_init()
1356 ep->maxpacket = 512; in at91sam9260_udc_init()
1385 struct at91_ep *ep; in at91sam9261_udc_init() local
1389 ep = &udc->ep[i]; in at91sam9261_udc_init()
1393 ep->maxpacket = 8; in at91sam9261_udc_init()
1396 ep->maxpacket = 64; in at91sam9261_udc_init()
1399 ep->maxpacket = 256; in at91sam9261_udc_init()
1404 udc->matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; in at91sam9261_udc_init()
1406 if (IS_ERR(udc->matrix)) in at91sam9261_udc_init()
1407 return PTR_ERR(udc->matrix); in at91sam9261_udc_init()
1416 usbpucr = readl(&udc->matrix->pucr); in at91sam9261_udc_pullup()
1420 writel(usbpucr, &udc->matrix->pucr); in at91sam9261_udc_pullup()
1441 if (!driver || !driver->bind || !driver->setup) { in usb_gadget_register_driver()
1443 return -EINVAL; in usb_gadget_register_driver()
1446 if (udc->driver) { in usb_gadget_register_driver()
1448 return -EBUSY; in usb_gadget_register_driver()
1451 at91_start(&udc->gadget, driver); in usb_gadget_register_driver()
1453 udc->driver = driver; in usb_gadget_register_driver()
1455 ret = driver->bind(&udc->gadget); in usb_gadget_register_driver()
1457 pr_err("driver->bind() returned %d\n", ret); in usb_gadget_register_driver()
1458 udc->driver = NULL; in usb_gadget_register_driver()
1468 if (!driver || !driver->unbind || !driver->disconnect) { in usb_gadget_unregister_driver()
1470 return -EINVAL; in usb_gadget_unregister_driver()
1473 driver->disconnect(&udc->gadget); in usb_gadget_unregister_driver()
1474 driver->unbind(&udc->gadget); in usb_gadget_unregister_driver()
1475 udc->driver = NULL; in usb_gadget_unregister_driver()
1477 at91_stop(&udc->gadget); in usb_gadget_unregister_driver()
1486 struct at91_ep *ep; in at91_udc_probe() local
1491 return -ENOMEM; in at91_udc_probe()
1494 memcpy(&udc->board, pdata, sizeof(struct at91_udc_data)); in at91_udc_probe()
1495 if (udc->board.vbus_pin) { in at91_udc_probe()
1497 return -ENXIO; in at91_udc_probe()
1499 DBG("no VBUS detection, assuming always-on\n"); in at91_udc_probe()
1500 udc->vbus = 1; in at91_udc_probe()
1504 udc->caps = &at91sam9260_udc_caps; in at91_udc_probe()
1507 udc->enabled = 0; in at91_udc_probe()
1508 spin_lock_init(&udc->lock); in at91_udc_probe()
1510 udc->gadget.ops = &at91_udc_ops; in at91_udc_probe()
1511 udc->gadget.ep0 = &udc->ep[0].ep; in at91_udc_probe()
1512 udc->gadget.name = driver_name; in at91_udc_probe()
1515 ep = &udc->ep[i]; in at91_udc_probe()
1516 ep->ep.name = ep_names[i]; in at91_udc_probe()
1517 ep->ep.ops = &at91_ep_ops; in at91_udc_probe()
1518 ep->udc = udc; in at91_udc_probe()
1519 ep->int_mask = (1 << i); in at91_udc_probe()
1521 ep->is_pingpong = 1; in at91_udc_probe()
1524 udc->udp_baseaddr = (void *)udc->board.baseaddr; in at91_udc_probe()
1525 if (IS_ERR(udc->udp_baseaddr)) in at91_udc_probe()
1526 return PTR_ERR(udc->udp_baseaddr); in at91_udc_probe()
1528 if (udc->caps && udc->caps->init) { in at91_udc_probe()
1529 retval = udc->caps->init(udc); in at91_udc_probe()
1538 /* Clear all pending interrupts - UDP may be used by bootloader. */ in at91_udc_probe()