Lines Matching +full:mmu +full:- +full:500 +full:s
1 // SPDX-License-Identifier: GPL-2.0+
3 * at91_udc -- driver for at91-series USB peripheral controller
32 #include <linux/mfd/syscon/atmel-matrix.h>
38 * This controller is simple and PIO-only. It's used in many AT91-series
39 * full speed USB controllers, including the at91rm9200 (arm920T, with MMU),
40 * at91sam926x (arm926ejs, with MMU), and several no-mmu versions.
46 * The pullup is most important (so it's integrated on sam926x parts). It
75 EP_INFO("ep3-int",
90 __raw_readl((udc)->udp_baseaddr + (reg))
92 __raw_writel((val), (udc)->udp_baseaddr + (reg))
94 /*-------------------------------------------------------------------------*/
102 #define FOURBITS "%s%s%s%s"
105 static void proc_ep_show(struct seq_file *s, struct at91_ep *ep) in proc_ep_show() argument
108 "control", "out-iso", "out-bulk", "out-int", in proc_ep_show()
109 "BOGUS", "in-iso", "in-bulk", "in-int"}; in proc_ep_show()
114 struct at91_udc *udc = ep->udc; in proc_ep_show()
116 spin_lock_irqsave(&udc->lock, flags); in proc_ep_show()
118 csr = __raw_readl(ep->creg); in proc_ep_show()
120 /* NOTE: not collecting per-endpoint irq statistics... */ in proc_ep_show()
122 seq_printf(s, "\n"); in proc_ep_show()
123 seq_printf(s, "%s, maxpacket %d %s%s %s%s\n", in proc_ep_show()
124 ep->ep.name, ep->ep.maxpacket, in proc_ep_show()
125 ep->is_in ? "in" : "out", in proc_ep_show()
126 ep->is_iso ? " iso" : "", in proc_ep_show()
127 ep->is_pingpong in proc_ep_show()
128 ? (ep->fifo_bank ? "pong" : "ping") in proc_ep_show()
130 ep->stopped ? " stopped" : ""); in proc_ep_show()
131 seq_printf(s, "csr %08x rxbytes=%d %s %s %s" EIGHTBITS "\n", in proc_ep_show()
150 if (list_empty (&ep->queue)) in proc_ep_show()
151 seq_printf(s, "\t(queue empty)\n"); in proc_ep_show()
153 else list_for_each_entry (req, &ep->queue, queue) { in proc_ep_show()
154 unsigned length = req->req.actual; in proc_ep_show()
156 seq_printf(s, "\treq %p len %d/%d buf %p\n", in proc_ep_show()
157 &req->req, length, in proc_ep_show()
158 req->req.length, req->req.buf); in proc_ep_show()
160 spin_unlock_irqrestore(&udc->lock, flags); in proc_ep_show()
163 static void proc_irq_show(struct seq_file *s, const char *label, u32 mask) in proc_irq_show() argument
167 seq_printf(s, "%s %04x:%s%s" FOURBITS, label, mask, in proc_irq_show()
177 seq_printf(s, " ep%d", i); in proc_irq_show()
179 seq_printf(s, "\n"); in proc_irq_show()
182 static int proc_udc_show(struct seq_file *s, void *unused) in proc_udc_show() argument
184 struct at91_udc *udc = s->private; in proc_udc_show()
188 seq_printf(s, "%s: version %s\n", driver_name, DRIVER_VERSION); in proc_udc_show()
190 seq_printf(s, "vbus %s, pullup %s, %s powered%s, gadget %s\n\n", in proc_udc_show()
191 udc->vbus ? "present" : "off", in proc_udc_show()
192 udc->enabled in proc_udc_show()
193 ? (udc->vbus ? "active" : "enabled") in proc_udc_show()
195 udc->gadget.is_selfpowered ? "self" : "VBUS", in proc_udc_show()
196 udc->suspended ? ", suspended" : "", in proc_udc_show()
197 udc->driver ? udc->driver->driver.name : "(none)"); in proc_udc_show()
200 if (!udc->clocked) { in proc_udc_show()
201 seq_printf(s, "(not clocked)\n"); in proc_udc_show()
206 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp, in proc_udc_show()
212 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp, in proc_udc_show()
220 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp, in proc_udc_show()
224 proc_irq_show(s, "imr ", at91_udp_read(udc, AT91_UDP_IMR)); in proc_udc_show()
225 proc_irq_show(s, "isr ", at91_udp_read(udc, AT91_UDP_ISR)); in proc_udc_show()
227 if (udc->enabled && udc->vbus) { in proc_udc_show()
228 proc_ep_show(s, &udc->ep[0]); in proc_udc_show()
229 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { in proc_udc_show()
230 if (ep->ep.desc) in proc_udc_show()
231 proc_ep_show(s, ep); in proc_udc_show()
239 udc->pde = proc_create_single_data(debug_filename, 0, NULL, in create_debug_file()
245 if (udc->pde) in remove_debug_file()
257 /*-------------------------------------------------------------------------*/
261 unsigned stopped = ep->stopped; in done()
262 struct at91_udc *udc = ep->udc; in done()
264 list_del_init(&req->queue); in done()
265 if (req->req.status == -EINPROGRESS) in done()
266 req->req.status = status; in done()
268 status = req->req.status; in done()
269 if (status && status != -ESHUTDOWN) in done()
270 VDBG("%s done %p, status %d\n", ep->ep.name, req, status); in done()
272 ep->stopped = 1; in done()
273 spin_unlock(&udc->lock); in done()
274 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
275 spin_lock(&udc->lock); in done()
276 ep->stopped = stopped; in done()
278 /* ep0 is always ready; other endpoints need a non-empty queue */ in done()
279 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0)) in done()
280 at91_udp_write(udc, AT91_UDP_IDR, ep->int_mask); in done()
283 /*-------------------------------------------------------------------------*/
294 * - clear SET_FX bits (setting them could change something)
295 * - set CLR_FX bits (clearing them could change something)
303 * infrequently we write, except maybe for write-then-read idioms.
309 /* pull OUT packet data from the endpoint's fifo */
312 u32 __iomem *creg = ep->creg; in read_fifo()
313 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in read_fifo()
318 buf = req->req.buf + req->req.actual; in read_fifo()
319 bufferspace = req->req.length - req->req.actual; in read_fifo()
331 if (count > ep->ep.maxpacket) in read_fifo()
332 count = ep->ep.maxpacket; in read_fifo()
334 DBG("%s buffer overflow\n", ep->ep.name); in read_fifo()
335 req->req.status = -EOVERFLOW; in read_fifo()
342 if (ep->is_pingpong) { in read_fifo()
343 if (ep->fifo_bank == 0) { in read_fifo()
345 ep->fifo_bank = 1; in read_fifo()
348 ep->fifo_bank = 0; in read_fifo()
354 req->req.actual += count; in read_fifo()
355 is_done = (count < ep->ep.maxpacket); in read_fifo()
359 PACKET("%s %p out/%d%s\n", ep->ep.name, &req->req, count, in read_fifo()
364 * the fifo ... maybe preventing an extra (expensive) OUT-NAK in read_fifo()
368 else if (ep->is_pingpong) { in read_fifo()
376 bufferspace -= count; in read_fifo()
387 u32 __iomem *creg = ep->creg; in write_fifo()
389 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in write_fifo()
395 * reduce the amount of IN-NAKing, but probably won't affect in write_fifo()
396 * throughput much. (Unlike preventing OUT-NAKing!) in write_fifo()
416 buf = req->req.buf + req->req.actual; in write_fifo()
418 total = req->req.length - req->req.actual; in write_fifo()
419 if (ep->ep.maxpacket < total) { in write_fifo()
420 count = ep->ep.maxpacket; in write_fifo()
424 is_last = (count < ep->ep.maxpacket) || !req->req.zero; in write_fifo()
428 * Write the packet, maybe it's a ZLP. in write_fifo()
430 * NOTE: incrementing req->actual before we receive the ACK means in write_fifo()
431 * gadget driver IN bytecounts can be wrong in fault cases. That's in write_fifo()
444 req->req.actual += count; in write_fifo()
446 PACKET("%s %p in/%d%s\n", ep->ep.name, &req->req, count, in write_fifo()
458 ep->stopped = 1; in nuke()
459 if (list_empty(&ep->queue)) in nuke()
462 VDBG("%s %s\n", __func__, ep->ep.name); in nuke()
463 while (!list_empty(&ep->queue)) { in nuke()
464 req = list_entry(ep->queue.next, struct at91_request, queue); in nuke()
469 /*-------------------------------------------------------------------------*/
481 || !desc || _ep->name == ep0name in at91_ep_enable()
482 || desc->bDescriptorType != USB_DT_ENDPOINT in at91_ep_enable()
484 || maxpacket > ep->maxpacket) { in at91_ep_enable()
486 return -EINVAL; in at91_ep_enable()
489 udc = ep->udc; in at91_ep_enable()
490 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in at91_ep_enable()
492 return -ESHUTDOWN; in at91_ep_enable()
499 return -EINVAL; in at91_ep_enable()
514 return -EINVAL; in at91_ep_enable()
516 if (!ep->is_pingpong) { in at91_ep_enable()
518 return -EINVAL; in at91_ep_enable()
524 spin_lock_irqsave(&udc->lock, flags); in at91_ep_enable()
527 ep->is_in = usb_endpoint_dir_in(desc); in at91_ep_enable()
528 ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); in at91_ep_enable()
529 ep->stopped = 0; in at91_ep_enable()
530 if (ep->is_in) in at91_ep_enable()
534 __raw_writel(tmp, ep->creg); in at91_ep_enable()
536 ep->ep.maxpacket = maxpacket; in at91_ep_enable()
542 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_enable()
545 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_enable()
552 struct at91_udc *udc = ep->udc; in at91_ep_disable()
555 if (ep == &ep->udc->ep[0]) in at91_ep_disable()
556 return -EINVAL; in at91_ep_disable()
558 spin_lock_irqsave(&udc->lock, flags); in at91_ep_disable()
560 nuke(ep, -ESHUTDOWN); in at91_ep_disable()
562 /* restore the endpoint's pristine config */ in at91_ep_disable()
563 ep->ep.desc = NULL; in at91_ep_disable()
564 ep->ep.maxpacket = ep->maxpacket; in at91_ep_disable()
567 if (ep->udc->clocked) { in at91_ep_disable()
568 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_disable()
570 __raw_writel(0, ep->creg); in at91_ep_disable()
573 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_disable()
578 * this is a PIO-only driver, so there's nothing
591 INIT_LIST_HEAD(&req->queue); in at91_ep_alloc_request()
592 return &req->req; in at91_ep_alloc_request()
600 BUG_ON(!list_empty(&req->queue)); in at91_ep_free_request()
616 if (!_req || !_req->complete in at91_ep_queue()
617 || !_req->buf || !list_empty(&req->queue)) { in at91_ep_queue()
619 return -EINVAL; in at91_ep_queue()
622 if (!_ep || (!ep->ep.desc && ep->ep.name != ep0name)) { in at91_ep_queue()
624 return -EINVAL; in at91_ep_queue()
627 udc = ep->udc; in at91_ep_queue()
629 if (!udc || !udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in at91_ep_queue()
631 return -EINVAL; in at91_ep_queue()
634 _req->status = -EINPROGRESS; in at91_ep_queue()
635 _req->actual = 0; in at91_ep_queue()
637 spin_lock_irqsave(&udc->lock, flags); in at91_ep_queue()
640 if (list_empty(&ep->queue) && !ep->stopped) { in at91_ep_queue()
644 * If this control request has a non-empty DATA stage, this in at91_ep_queue()
645 * will start that stage. It works just like a non-control in at91_ep_queue()
651 is_ep0 = (ep->ep.name == ep0name); in at91_ep_queue()
655 if (!udc->req_pending) { in at91_ep_queue()
656 status = -EINVAL; in at91_ep_queue()
664 if (udc->wait_for_config_ack) { in at91_ep_queue()
670 if (req->req.length == 0) { in at91_ep_queue()
674 tmp = __raw_readl(ep->creg); in at91_ep_queue()
677 __raw_writel(tmp, ep->creg); in at91_ep_queue()
678 udc->req_pending = 0; in at91_ep_queue()
683 if (ep->is_in) in at91_ep_queue()
696 list_add_tail (&req->queue, &ep->queue); in at91_ep_queue()
697 at91_udp_write(udc, AT91_UDP_IER, ep->int_mask); in at91_ep_queue()
700 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_queue()
712 if (!_ep || ep->ep.name == ep0name) in at91_ep_dequeue()
713 return -EINVAL; in at91_ep_dequeue()
715 udc = ep->udc; in at91_ep_dequeue()
717 spin_lock_irqsave(&udc->lock, flags); in at91_ep_dequeue()
719 /* make sure it's actually queued on this endpoint */ in at91_ep_dequeue()
720 list_for_each_entry(iter, &ep->queue, queue) { in at91_ep_dequeue()
721 if (&iter->req != _req) in at91_ep_dequeue()
727 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_dequeue()
728 return -EINVAL; in at91_ep_dequeue()
731 done(ep, req, -ECONNRESET); in at91_ep_dequeue()
732 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_dequeue()
739 struct at91_udc *udc = ep->udc; in at91_ep_set_halt()
745 if (!_ep || ep->is_iso || !ep->udc->clocked) in at91_ep_set_halt()
746 return -EINVAL; in at91_ep_set_halt()
748 creg = ep->creg; in at91_ep_set_halt()
749 spin_lock_irqsave(&udc->lock, flags); in at91_ep_set_halt()
754 * fail with still-busy IN endpoints, ensuring correct sequencing in at91_ep_set_halt()
758 if (ep->is_in && (!list_empty(&ep->queue) || (csr >> 16) != 0)) in at91_ep_set_halt()
759 status = -EAGAIN; in at91_ep_set_halt()
765 VDBG("halt %s\n", ep->ep.name); in at91_ep_set_halt()
767 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in at91_ep_set_halt()
774 spin_unlock_irqrestore(&udc->lock, flags); in at91_ep_set_halt()
786 /* there's only imprecise fifo status reporting */
789 /*-------------------------------------------------------------------------*/
795 if (!to_udc(gadget)->clocked) in at91_get_frame()
796 return -EINVAL; in at91_get_frame()
806 DBG("%s\n", __func__ ); in at91_wakeup()
807 spin_lock_irqsave(&udc->lock, flags); in at91_wakeup()
809 if (!udc->clocked || !udc->suspended) in at91_wakeup()
821 spin_unlock_irqrestore(&udc->lock, flags); in at91_wakeup()
830 INIT_LIST_HEAD(&udc->gadget.ep_list); in udc_reinit()
831 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); in udc_reinit()
832 udc->gadget.quirk_stall_not_supp = 1; in udc_reinit()
835 struct at91_ep *ep = &udc->ep[i]; in udc_reinit()
838 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in udc_reinit()
839 ep->ep.desc = NULL; in udc_reinit()
840 ep->stopped = 0; in udc_reinit()
841 ep->fifo_bank = 0; in udc_reinit()
842 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); in udc_reinit()
843 ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); in udc_reinit()
845 INIT_LIST_HEAD(&ep->queue); in udc_reinit()
851 struct usb_gadget_driver *driver = udc->driver; in reset_gadget()
854 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in reset_gadget()
856 udc->gadget.speed = USB_SPEED_UNKNOWN; in reset_gadget()
857 udc->suspended = 0; in reset_gadget()
860 struct at91_ep *ep = &udc->ep[i]; in reset_gadget()
862 ep->stopped = 1; in reset_gadget()
863 nuke(ep, -ESHUTDOWN); in reset_gadget()
866 spin_unlock(&udc->lock); in reset_gadget()
867 usb_gadget_udc_reset(&udc->gadget, driver); in reset_gadget()
868 spin_lock(&udc->lock); in reset_gadget()
876 struct usb_gadget_driver *driver = udc->driver; in stop_activity()
879 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in stop_activity()
881 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
882 udc->suspended = 0; in stop_activity()
885 struct at91_ep *ep = &udc->ep[i]; in stop_activity()
886 ep->stopped = 1; in stop_activity()
887 nuke(ep, -ESHUTDOWN); in stop_activity()
890 spin_unlock(&udc->lock); in stop_activity()
891 driver->disconnect(&udc->gadget); in stop_activity()
892 spin_lock(&udc->lock); in stop_activity()
900 if (udc->clocked) in clk_on()
902 udc->clocked = 1; in clk_on()
904 clk_enable(udc->iclk); in clk_on()
905 clk_enable(udc->fclk); in clk_on()
910 if (!udc->clocked) in clk_off()
912 udc->clocked = 0; in clk_off()
913 udc->gadget.speed = USB_SPEED_UNKNOWN; in clk_off()
914 clk_disable(udc->fclk); in clk_off()
915 clk_disable(udc->iclk); in clk_off()
924 if (!udc->enabled || !udc->vbus) in pullup()
939 if (udc->caps && udc->caps->pullup) in pullup()
940 udc->caps->pullup(udc, is_on); in pullup()
943 /* vbus is here! turn everything on that's ready */
949 /* VDBG("vbus %s\n", is_active ? "on" : "off"); */ in at91_vbus_session()
950 spin_lock_irqsave(&udc->lock, flags); in at91_vbus_session()
951 udc->vbus = (is_active != 0); in at91_vbus_session()
952 if (udc->driver) in at91_vbus_session()
956 spin_unlock_irqrestore(&udc->lock, flags); in at91_vbus_session()
965 spin_lock_irqsave(&udc->lock, flags); in at91_pullup()
966 udc->enabled = is_on = !!is_on; in at91_pullup()
968 spin_unlock_irqrestore(&udc->lock, flags); in at91_pullup()
977 spin_lock_irqsave(&udc->lock, flags); in at91_set_selfpowered()
978 gadget->is_selfpowered = (is_on != 0); in at91_set_selfpowered()
979 spin_unlock_irqrestore(&udc->lock, flags); in at91_set_selfpowered()
997 * VBUS-powered devices may also want to support bigger
1003 /*-------------------------------------------------------------------------*/
1008 u32 __iomem *creg = ep->creg; in handle_ep()
1011 if (!list_empty(&ep->queue)) in handle_ep()
1012 req = list_entry(ep->queue.next, in handle_ep()
1017 if (ep->is_in) { in handle_ep()
1029 if (ep->is_iso && req) in handle_ep()
1030 req->req.status = -EILSEQ; in handle_ep()
1049 u32 __iomem *creg = ep->creg; in handle_setup()
1050 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); in handle_setup()
1056 /* read and ack SETUP; hard-fail for bogus packets */ in handle_setup()
1059 while (rxcount--) in handle_setup()
1063 ep->is_in = 1; in handle_setup()
1066 ep->is_in = 0; in handle_setup()
1071 status = -EINVAL; in handle_setup()
1076 udc->wait_for_addr_ack = 0; in handle_setup()
1077 udc->wait_for_config_ack = 0; in handle_setup()
1078 ep->stopped = 0; in handle_setup()
1094 udc->req_pending = 1; in handle_setup()
1103 udc->addr = w_value; in handle_setup()
1104 udc->wait_for_addr_ack = 1; in handle_setup()
1105 udc->req_pending = 0; in handle_setup()
1113 udc->wait_for_config_ack = (tmp == 0); in handle_setup()
1115 udc->wait_for_config_ack = (tmp != 0); in handle_setup()
1116 if (udc->wait_for_config_ack) in handle_setup()
1127 tmp = (udc->gadget.is_selfpowered << USB_DEVICE_SELF_POWERED); in handle_setup()
1176 ep = &udc->ep[tmp]; in handle_setup()
1177 if (tmp >= NUM_ENDPOINTS || (tmp && !ep->ep.desc)) in handle_setup()
1182 if (!ep->is_in) in handle_setup()
1184 } else if (ep->is_in) in handle_setup()
1187 PACKET("get %s status\n", ep->ep.name); in handle_setup()
1188 if (__raw_readl(ep->creg) & AT91_UDP_FORCESTALL) in handle_setup()
1199 ep = &udc->ep[tmp]; in handle_setup()
1202 if (!ep->ep.desc || ep->is_iso) in handle_setup()
1205 if (!ep->is_in) in handle_setup()
1207 } else if (ep->is_in) in handle_setup()
1210 tmp = __raw_readl(ep->creg); in handle_setup()
1213 __raw_writel(tmp, ep->creg); in handle_setup()
1218 ep = &udc->ep[tmp]; in handle_setup()
1223 if (!ep->ep.desc || ep->is_iso) in handle_setup()
1226 if (!ep->is_in) in handle_setup()
1228 } else if (ep->is_in) in handle_setup()
1231 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); in handle_setup()
1233 tmp = __raw_readl(ep->creg); in handle_setup()
1236 __raw_writel(tmp, ep->creg); in handle_setup()
1237 if (!list_empty(&ep->queue)) in handle_setup()
1247 if (udc->driver) { in handle_setup()
1248 spin_unlock(&udc->lock); in handle_setup()
1249 status = udc->driver->setup(&udc->gadget, &pkt.r); in handle_setup()
1250 spin_lock(&udc->lock); in handle_setup()
1253 status = -ENODEV; in handle_setup()
1260 udc->req_pending = 0; in handle_setup()
1270 udc->req_pending = 0; in handle_setup()
1275 struct at91_ep *ep0 = &udc->ep[0]; in handle_ep0()
1276 u32 __iomem *creg = ep0->creg; in handle_ep0()
1281 nuke(ep0, -EPROTO); in handle_ep0()
1282 udc->req_pending = 0; in handle_ep0()
1291 udc->req_pending = 0; in handle_ep0()
1296 if (list_empty(&ep0->queue)) in handle_ep0()
1299 req = list_entry(ep0->queue.next, struct at91_request, queue); in handle_ep0()
1307 if (req && ep0->is_in) { in handle_ep0()
1309 udc->req_pending = 0; in handle_ep0()
1313 * - last IN DATA packet (including GET_STATUS) in handle_ep0()
1314 * - IN/STATUS for OUT DATA in handle_ep0()
1315 * - IN/STATUS for any zero-length DATA stage in handle_ep0()
1320 udc->req_pending = 0; in handle_ep0()
1327 if (udc->wait_for_addr_ack) { in handle_ep0()
1331 AT91_UDP_FEN | udc->addr); in handle_ep0()
1334 if (udc->addr) in handle_ep0()
1338 udc->wait_for_addr_ack = 0; in handle_ep0()
1339 VDBG("address %d\n", udc->addr); in handle_ep0()
1350 if (!ep0->is_in) { in handle_ep0()
1359 udc->req_pending = 0; in handle_ep0()
1361 } else if (udc->req_pending) { in handle_ep0()
1364 * "deferred response" mode for control-OUT in handle_ep0()
1365 * transfers. (For control-IN it's fine.) in handle_ep0()
1374 * would almost be a non-deferred response, in handle_ep0()
1379 DBG("no control-OUT deferred responses!\n"); in handle_ep0()
1381 udc->req_pending = 0; in handle_ep0()
1384 /* STATUS stage for control-IN; ack. */ in handle_ep0()
1403 spin_lock_irqsave(&udc->lock, flags); in at91_udc_irq()
1405 if (!udc->clocked) { in at91_udc_irq()
1410 while (rescans--) { in at91_udc_irq()
1426 udc->addr = 0; in at91_udc_irq()
1432 udc->gadget.speed = USB_SPEED_FULL; in at91_udc_irq()
1433 udc->suspended = 0; in at91_udc_irq()
1449 if (udc->suspended) in at91_udc_irq()
1451 udc->suspended = 1; in at91_udc_irq()
1454 * NOTE: when suspending a VBUS-powered device, the in at91_udc_irq()
1457 * 500uA power (2500uA for some high-power configs). in at91_udc_irq()
1459 if (udc->driver && udc->driver->suspend) { in at91_udc_irq()
1460 spin_unlock(&udc->lock); in at91_udc_irq()
1461 udc->driver->suspend(&udc->gadget); in at91_udc_irq()
1462 spin_lock(&udc->lock); in at91_udc_irq()
1471 if (!udc->suspended) in at91_udc_irq()
1473 udc->suspended = 0; in at91_udc_irq()
1476 * NOTE: for a VBUS-powered device, the gadget driver in at91_udc_irq()
1480 if (udc->driver && udc->driver->resume) { in at91_udc_irq()
1481 spin_unlock(&udc->lock); in at91_udc_irq()
1482 udc->driver->resume(&udc->gadget); in at91_udc_irq()
1483 spin_lock(&udc->lock); in at91_udc_irq()
1490 struct at91_ep *ep = &udc->ep[1]; in at91_udc_irq()
1506 spin_unlock_irqrestore(&udc->lock, flags); in at91_udc_irq()
1511 /*-------------------------------------------------------------------------*/
1515 if (value != udc->vbus) in at91_vbus_update()
1516 at91_vbus_session(&udc->gadget, value); in at91_vbus_update()
1525 at91_vbus_update(udc, gpiod_get_value(udc->board.vbus_pin)); in at91_vbus_irq()
1535 at91_vbus_update(udc, gpiod_get_value_cansleep(udc->board.vbus_pin)); in at91_vbus_timer_work()
1537 if (!timer_pending(&udc->vbus_timer)) in at91_vbus_timer_work()
1538 mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT); in at91_vbus_timer_work()
1550 schedule_work(&udc->vbus_timer_work); in at91_vbus_timer()
1559 udc->driver = driver; in at91_start()
1560 udc->gadget.dev.of_node = udc->pdev->dev.of_node; in at91_start()
1561 udc->enabled = 1; in at91_start()
1562 udc->gadget.is_selfpowered = 1; in at91_start()
1573 spin_lock_irqsave(&udc->lock, flags); in at91_stop()
1574 udc->enabled = 0; in at91_stop()
1576 spin_unlock_irqrestore(&udc->lock, flags); in at91_stop()
1578 udc->driver = NULL; in at91_stop()
1583 /*-------------------------------------------------------------------------*/
1591 spin_lock_irqsave(&udc->lock, flags); in at91udc_shutdown()
1593 spin_unlock_irqrestore(&udc->lock, flags); in at91udc_shutdown()
1602 ep = &udc->ep[i]; in at91rm9200_udc_init()
1607 ep->maxpacket = 8; in at91rm9200_udc_init()
1610 ep->maxpacket = 64; in at91rm9200_udc_init()
1613 ep->maxpacket = 256; in at91rm9200_udc_init()
1618 if (!udc->board.pullup_pin) { in at91rm9200_udc_init()
1620 return -ENODEV; in at91rm9200_udc_init()
1623 gpiod_direction_output(udc->board.pullup_pin, in at91rm9200_udc_init()
1624 gpiod_is_active_low(udc->board.pullup_pin)); in at91rm9200_udc_init()
1631 gpiod_set_value(udc->board.pullup_pin, is_on); in at91rm9200_udc_pullup()
1645 ep = &udc->ep[i]; in at91sam9260_udc_init()
1649 ep->maxpacket = 64; in at91sam9260_udc_init()
1652 ep->maxpacket = 512; in at91sam9260_udc_init()
1683 ep = &udc->ep[i]; in at91sam9261_udc_init()
1687 ep->maxpacket = 8; in at91sam9261_udc_init()
1690 ep->maxpacket = 64; in at91sam9261_udc_init()
1693 ep->maxpacket = 256; in at91sam9261_udc_init()
1698 udc->matrix = syscon_regmap_lookup_by_phandle(udc->pdev->dev.of_node, in at91sam9261_udc_init()
1700 return PTR_ERR_OR_ZERO(udc->matrix); in at91sam9261_udc_init()
1710 regmap_update_bits(udc->matrix, AT91SAM9261_MATRIX_USBPUCR, in at91sam9261_udc_pullup()
1725 ep = &udc->ep[i]; in at91sam9263_udc_init()
1732 ep->maxpacket = 64; in at91sam9263_udc_init()
1736 ep->maxpacket = 256; in at91sam9263_udc_init()
1751 .compatible = "atmel,at91rm9200-udc",
1755 .compatible = "atmel,at91sam9260-udc",
1759 .compatible = "atmel,at91sam9261-udc",
1763 .compatible = "atmel,at91sam9263-udc",
1772 struct at91_udc_data *board = &udc->board; in at91udc_of_init()
1776 if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0) in at91udc_of_init()
1777 board->vbus_polled = 1; in at91udc_of_init()
1779 board->vbus_pin = fwnode_gpiod_get_index(of_fwnode_handle(np), in at91udc_of_init()
1782 if (IS_ERR(board->vbus_pin)) in at91udc_of_init()
1783 board->vbus_pin = NULL; in at91udc_of_init()
1785 board->pullup_pin = fwnode_gpiod_get_index(of_fwnode_handle(np), in at91udc_of_init()
1788 if (IS_ERR(board->pullup_pin)) in at91udc_of_init()
1789 board->pullup_pin = NULL; in at91udc_of_init()
1793 udc->caps = match->data; in at91udc_of_init()
1798 struct device *dev = &pdev->dev; in at91udc_probe()
1806 return -ENOMEM; in at91udc_probe()
1809 udc->gadget.dev.parent = dev; in at91udc_probe()
1810 at91udc_of_init(udc, pdev->dev.of_node); in at91udc_probe()
1811 udc->pdev = pdev; in at91udc_probe()
1812 udc->enabled = 0; in at91udc_probe()
1813 spin_lock_init(&udc->lock); in at91udc_probe()
1815 udc->gadget.ops = &at91_udc_ops; in at91udc_probe()
1816 udc->gadget.ep0 = &udc->ep[0].ep; in at91udc_probe()
1817 udc->gadget.name = driver_name; in at91udc_probe()
1818 udc->gadget.dev.init_name = "gadget"; in at91udc_probe()
1821 ep = &udc->ep[i]; in at91udc_probe()
1822 ep->ep.name = ep_info[i].name; in at91udc_probe()
1823 ep->ep.caps = ep_info[i].caps; in at91udc_probe()
1824 ep->ep.ops = &at91_ep_ops; in at91udc_probe()
1825 ep->udc = udc; in at91udc_probe()
1826 ep->int_mask = BIT(i); in at91udc_probe()
1828 ep->is_pingpong = 1; in at91udc_probe()
1831 udc->udp_baseaddr = devm_platform_ioremap_resource(pdev, 0); in at91udc_probe()
1832 if (IS_ERR(udc->udp_baseaddr)) in at91udc_probe()
1833 return PTR_ERR(udc->udp_baseaddr); in at91udc_probe()
1835 if (udc->caps && udc->caps->init) { in at91udc_probe()
1836 retval = udc->caps->init(udc); in at91udc_probe()
1844 udc->iclk = devm_clk_get(dev, "pclk"); in at91udc_probe()
1845 if (IS_ERR(udc->iclk)) in at91udc_probe()
1846 return PTR_ERR(udc->iclk); in at91udc_probe()
1848 udc->fclk = devm_clk_get(dev, "hclk"); in at91udc_probe()
1849 if (IS_ERR(udc->fclk)) in at91udc_probe()
1850 return PTR_ERR(udc->fclk); in at91udc_probe()
1853 clk_set_rate(udc->fclk, 48000000); in at91udc_probe()
1854 retval = clk_prepare(udc->fclk); in at91udc_probe()
1858 retval = clk_prepare_enable(udc->iclk); in at91udc_probe()
1864 /* Clear all pending interrupts - UDP may be used by bootloader. */ in at91udc_probe()
1866 clk_disable(udc->iclk); in at91udc_probe()
1869 udc->udp_irq = retval = platform_get_irq(pdev, 0); in at91udc_probe()
1872 retval = devm_request_irq(dev, udc->udp_irq, at91_udc_irq, 0, in at91udc_probe()
1875 DBG("request irq %d failed\n", udc->udp_irq); in at91udc_probe()
1879 if (udc->board.vbus_pin) { in at91udc_probe()
1880 gpiod_direction_input(udc->board.vbus_pin); in at91udc_probe()
1883 * Get the initial state of VBUS - we cannot expect in at91udc_probe()
1886 udc->vbus = gpiod_get_value_cansleep(udc->board.vbus_pin); in at91udc_probe()
1888 if (udc->board.vbus_polled) { in at91udc_probe()
1889 INIT_WORK(&udc->vbus_timer_work, at91_vbus_timer_work); in at91udc_probe()
1890 timer_setup(&udc->vbus_timer, at91_vbus_timer, 0); in at91udc_probe()
1891 mod_timer(&udc->vbus_timer, in at91udc_probe()
1895 gpiod_to_irq(udc->board.vbus_pin), in at91udc_probe()
1899 desc_to_gpio(udc->board.vbus_pin)); in at91udc_probe()
1904 DBG("no VBUS detection, assuming always-on\n"); in at91udc_probe()
1905 udc->vbus = 1; in at91udc_probe()
1907 retval = usb_add_gadget_udc(dev, &udc->gadget); in at91udc_probe()
1914 INFO("%s version %s\n", driver_name, DRIVER_VERSION); in at91udc_probe()
1918 clk_unprepare(udc->iclk); in at91udc_probe()
1920 clk_unprepare(udc->fclk); in at91udc_probe()
1922 DBG("%s probe failed, %d\n", driver_name, retval); in at91udc_probe()
1934 usb_del_gadget_udc(&udc->gadget); in at91udc_remove()
1935 if (udc->driver) { in at91udc_remove()
1936 dev_err(&pdev->dev, in at91udc_remove()
1941 spin_lock_irqsave(&udc->lock, flags); in at91udc_remove()
1943 spin_unlock_irqrestore(&udc->lock, flags); in at91udc_remove()
1945 device_init_wakeup(&pdev->dev, 0); in at91udc_remove()
1947 clk_unprepare(udc->fclk); in at91udc_remove()
1948 clk_unprepare(udc->iclk); in at91udc_remove()
1955 int wake = udc->driver && device_may_wakeup(&pdev->dev); in at91udc_suspend()
1963 if ((!udc->suspended && udc->addr) in at91udc_suspend()
1966 spin_lock_irqsave(&udc->lock, flags); in at91udc_suspend()
1969 spin_unlock_irqrestore(&udc->lock, flags); in at91udc_suspend()
1971 enable_irq_wake(udc->udp_irq); in at91udc_suspend()
1973 udc->active_suspend = wake; in at91udc_suspend()
1974 if (udc->board.vbus_pin && !udc->board.vbus_polled && wake) in at91udc_suspend()
1975 enable_irq_wake(gpiod_to_irq(udc->board.vbus_pin)); in at91udc_suspend()
1984 if (udc->board.vbus_pin && !udc->board.vbus_polled && in at91udc_resume()
1985 udc->active_suspend) in at91udc_resume()
1986 disable_irq_wake(gpiod_to_irq(udc->board.vbus_pin)); in at91udc_resume()
1989 if (udc->active_suspend) in at91udc_resume()
1990 disable_irq_wake(udc->udp_irq); in at91udc_resume()
1992 spin_lock_irqsave(&udc->lock, flags); in at91udc_resume()
1994 spin_unlock_irqrestore(&udc->lock, flags); in at91udc_resume()