Lines Matching +full:re +full:- +full:clocked
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2005-2007 Atmel Corporation
15 #include <linux/dma-mapping.h>
39 struct usba_ep *ep = inode->i_private; in queue_dbg_open()
45 return -ENOMEM; in queue_dbg_open()
48 spin_lock_irq(&ep->udc->lock); in queue_dbg_open()
49 list_for_each_entry(req, &ep->queue, queue) { in queue_dbg_open()
53 list_add_tail(&req_copy->queue, queue_data); in queue_dbg_open()
55 spin_unlock_irq(&ep->udc->lock); in queue_dbg_open()
57 file->private_data = queue_data; in queue_dbg_open()
61 spin_unlock_irq(&ep->udc->lock); in queue_dbg_open()
63 list_del(&req->queue); in queue_dbg_open()
67 return -ENOMEM; in queue_dbg_open()
87 struct list_head *queue = file->private_data; in queue_dbg_read()
93 return -EFAULT; in queue_dbg_read()
99 req->req.buf, req->req.length, in queue_dbg_read()
100 req->req.no_interrupt ? 'i' : 'I', in queue_dbg_read()
101 req->req.zero ? 'Z' : 'z', in queue_dbg_read()
102 req->req.short_not_ok ? 's' : 'S', in queue_dbg_read()
103 req->req.status, in queue_dbg_read()
104 req->submitted ? 'F' : 'f', in queue_dbg_read()
105 req->using_dma ? 'D' : 'd', in queue_dbg_read()
106 req->last_transaction ? 'L' : 'l'); in queue_dbg_read()
111 list_del(&req->queue); in queue_dbg_read()
115 actual += len - remaining; in queue_dbg_read()
119 nbytes -= len; in queue_dbg_read()
129 struct list_head *queue_data = file->private_data; in queue_dbg_release()
133 list_del(&req->queue); in queue_dbg_release()
145 int ret = -ENOMEM; in regs_dbg_open()
148 udc = inode->i_private; in regs_dbg_open()
149 data = kmalloc(inode->i_size, GFP_KERNEL); in regs_dbg_open()
153 spin_lock_irq(&udc->lock); in regs_dbg_open()
154 for (i = 0; i < inode->i_size / 4; i++) in regs_dbg_open()
155 data[i] = readl_relaxed(udc->regs + i * 4); in regs_dbg_open()
156 spin_unlock_irq(&udc->lock); in regs_dbg_open()
158 file->private_data = data; in regs_dbg_open()
175 file->private_data, in regs_dbg_read()
176 file_inode(file)->i_size); in regs_dbg_read()
184 kfree(file->private_data); in regs_dbg_release()
209 ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root); in usba_ep_init_debugfs()
210 ep->debugfs_dir = ep_root; in usba_ep_init_debugfs()
213 if (ep->can_dma) in usba_ep_init_debugfs()
215 &ep->last_dma_status); in usba_ep_init_debugfs()
217 debugfs_create_u32("state", 0400, ep_root, &ep->state); in usba_ep_init_debugfs()
222 debugfs_remove_recursive(ep->debugfs_dir); in usba_ep_cleanup_debugfs()
230 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in usba_init_debugfs()
231 udc->debugfs_root = root; in usba_init_debugfs()
233 regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM, in usba_init_debugfs()
242 usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0)); in usba_init_debugfs()
247 usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0)); in usba_cleanup_debugfs()
248 debugfs_remove_recursive(udc->debugfs_root); in usba_cleanup_debugfs()
278 /* mode 0 - uses autoconfig */
280 /* mode 1 - fits in 8KB, generic max fifo configuration */
291 /* mode 2 - fits in 8KB, performance max fifo configuration */
299 /* mode 3 - fits in 8KB, mixed fifo configuration */
310 /* mode 4 - fits in 8KB, custom fifo configuration */
333 udc->fifo_cfg = NULL; in usba_config_fifo_table()
337 udc->fifo_cfg = mode_1_cfg; in usba_config_fifo_table()
341 udc->fifo_cfg = mode_2_cfg; in usba_config_fifo_table()
345 udc->fifo_cfg = mode_3_cfg; in usba_config_fifo_table()
349 udc->fifo_cfg = mode_4_cfg; in usba_config_fifo_table()
360 return udc->int_enb_cache; in usba_int_enb_get()
367 val = udc->int_enb_cache | mask; in usba_int_enb_set()
369 udc->int_enb_cache = val; in usba_int_enb_set()
376 val = udc->int_enb_cache & ~mask; in usba_int_enb_clear()
378 udc->int_enb_cache = val; in usba_int_enb_clear()
383 if (udc->vbus_pin) in vbus_is_present()
384 return gpiod_get_value(udc->vbus_pin); in vbus_is_present()
392 if (udc->errata && udc->errata->toggle_bias) in toggle_bias()
393 udc->errata->toggle_bias(udc, is_on); in toggle_bias()
398 if (!udc->bias_pulse_needed) in generate_bias_pulse()
401 if (udc->errata && udc->errata->pulse_bias) in generate_bias_pulse()
402 udc->errata->pulse_bias(udc); in generate_bias_pulse()
404 udc->bias_pulse_needed = false; in generate_bias_pulse()
411 transaction_len = req->req.length - req->req.actual; in next_fifo_transaction()
412 req->last_transaction = 1; in next_fifo_transaction()
413 if (transaction_len > ep->ep.maxpacket) { in next_fifo_transaction()
414 transaction_len = ep->ep.maxpacket; in next_fifo_transaction()
415 req->last_transaction = 0; in next_fifo_transaction()
416 } else if (transaction_len == ep->ep.maxpacket && req->req.zero) in next_fifo_transaction()
417 req->last_transaction = 0; in next_fifo_transaction()
420 ep->ep.name, req, transaction_len, in next_fifo_transaction()
421 req->last_transaction ? ", done" : ""); in next_fifo_transaction()
423 memcpy_toio(ep->fifo, req->req.buf + req->req.actual, transaction_len); in next_fifo_transaction()
425 req->req.actual += transaction_len; in next_fifo_transaction()
431 ep->ep.name, req, req->req.length); in submit_request()
433 req->req.actual = 0; in submit_request()
434 req->submitted = 1; in submit_request()
436 if (req->using_dma) { in submit_request()
437 if (req->req.length == 0) { in submit_request()
442 if (req->req.zero) in submit_request()
447 usba_dma_writel(ep, ADDRESS, req->req.dma); in submit_request()
448 usba_dma_writel(ep, CONTROL, req->ctrl); in submit_request()
451 if (req->last_transaction) { in submit_request()
467 if (list_empty(&ep->queue)) { in submit_next_request()
472 req = list_entry(ep->queue.next, struct usba_request, queue); in submit_next_request()
473 if (!req->submitted) in submit_next_request()
479 ep->state = STATUS_STAGE_IN; in send_status()
486 struct usba_udc *udc = ep->udc; in receive_data()
498 if (list_empty(&ep->queue)) { in receive_data()
502 req = list_entry(ep->queue.next, in receive_data()
509 if (req->req.actual + bytecount >= req->req.length) { in receive_data()
511 bytecount = req->req.length - req->req.actual; in receive_data()
514 memcpy_fromio(req->req.buf + req->req.actual, in receive_data()
515 ep->fifo, bytecount); in receive_data()
516 req->req.actual += bytecount; in receive_data()
521 DBG(DBG_QUEUE, "%s: request done\n", ep->ep.name); in receive_data()
522 req->req.status = 0; in receive_data()
523 list_del_init(&req->queue); in receive_data()
525 spin_unlock(&udc->lock); in receive_data()
526 usb_gadget_giveback_request(&ep->ep, &req->req); in receive_data()
527 spin_lock(&udc->lock); in receive_data()
543 struct usba_udc *udc = ep->udc; in request_complete()
545 WARN_ON(!list_empty(&req->queue)); in request_complete()
547 if (req->req.status == -EINPROGRESS) in request_complete()
548 req->req.status = status; in request_complete()
550 if (req->using_dma) in request_complete()
551 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); in request_complete()
555 ep->ep.name, req, req->req.status, req->req.actual); in request_complete()
557 spin_unlock(&udc->lock); in request_complete()
558 usb_gadget_giveback_request(&ep->ep, &req->req); in request_complete()
559 spin_lock(&udc->lock); in request_complete()
568 list_del_init(&req->queue); in request_complete_list()
577 struct usba_udc *udc = ep->udc; in usba_ep_enable()
581 DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc); in usba_ep_enable()
585 if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index) in usba_ep_enable()
586 || ep->index == 0 in usba_ep_enable()
587 || desc->bDescriptorType != USB_DT_ENDPOINT in usba_ep_enable()
589 || maxpacket > ep->fifo_size) { in usba_ep_enable()
591 return -EINVAL; in usba_ep_enable()
594 ep->is_isoc = 0; in usba_ep_enable()
595 ep->is_in = 0; in usba_ep_enable()
598 ep->ep.name, ep->ept_cfg, maxpacket); in usba_ep_enable()
601 ep->is_in = 1; in usba_ep_enable()
602 ep->ept_cfg |= USBA_EPT_DIR_IN; in usba_ep_enable()
607 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL); in usba_ep_enable()
610 if (!ep->can_isoc) { in usba_ep_enable()
612 ep->ep.name); in usba_ep_enable()
613 return -EINVAL; in usba_ep_enable()
622 return -EINVAL; in usba_ep_enable()
624 ep->is_isoc = 1; in usba_ep_enable()
625 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO); in usba_ep_enable()
626 ep->ept_cfg |= USBA_BF(NB_TRANS, nr_trans); in usba_ep_enable()
630 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK); in usba_ep_enable()
633 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT); in usba_ep_enable()
637 spin_lock_irqsave(&ep->udc->lock, flags); in usba_ep_enable()
639 ep->ep.desc = desc; in usba_ep_enable()
640 ep->ep.maxpacket = maxpacket; in usba_ep_enable()
642 usba_ep_writel(ep, CFG, ep->ept_cfg); in usba_ep_enable()
645 if (ep->can_dma) { in usba_ep_enable()
648 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index) | in usba_ep_enable()
649 USBA_BF(DMA_INT, 1 << ep->index)); in usba_ep_enable()
653 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_enable()
656 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_enable()
658 DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index, in usba_ep_enable()
669 struct usba_udc *udc = ep->udc; in usba_ep_disable()
673 DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name); in usba_ep_disable()
675 spin_lock_irqsave(&udc->lock, flags); in usba_ep_disable()
677 if (!ep->ep.desc) { in usba_ep_disable()
678 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
679 DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name); in usba_ep_disable()
680 return -EINVAL; in usba_ep_disable()
682 ep->ep.desc = NULL; in usba_ep_disable()
684 list_splice_init(&ep->queue, &req_list); in usba_ep_disable()
685 if (ep->can_dma) { in usba_ep_disable()
691 usba_int_enb_clear(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_disable()
693 request_complete_list(ep, &req_list, -ESHUTDOWN); in usba_ep_disable()
695 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
711 INIT_LIST_HEAD(&req->queue); in usba_ep_alloc_request()
713 return &req->req; in usba_ep_alloc_request()
733 ep->ep.name, req->req.length, &req->req.dma, in queue_dma()
734 req->req.zero ? 'Z' : 'z', in queue_dma()
735 req->req.short_not_ok ? 'S' : 's', in queue_dma()
736 req->req.no_interrupt ? 'I' : 'i'); in queue_dma()
738 if (req->req.length > 0x10000) { in queue_dma()
740 DBG(DBG_ERR, "invalid request length %u\n", req->req.length); in queue_dma()
741 return -EINVAL; in queue_dma()
744 ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in); in queue_dma()
748 req->using_dma = 1; in queue_dma()
749 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) in queue_dma()
753 if (!ep->is_in) in queue_dma()
754 req->ctrl |= USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; in queue_dma()
758 * possible. Check if we're still alive first -- we may have in queue_dma()
761 ret = -ESHUTDOWN; in queue_dma()
762 spin_lock_irqsave(&udc->lock, flags); in queue_dma()
763 if (ep->ep.desc) { in queue_dma()
764 if (list_empty(&ep->queue)) in queue_dma()
767 list_add_tail(&req->queue, &ep->queue); in queue_dma()
770 spin_unlock_irqrestore(&udc->lock, flags); in queue_dma()
780 struct usba_udc *udc = ep->udc; in usba_ep_queue()
785 ep->ep.name, req, _req->length); in usba_ep_queue()
787 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || in usba_ep_queue()
788 !ep->ep.desc) in usba_ep_queue()
789 return -ESHUTDOWN; in usba_ep_queue()
791 req->submitted = 0; in usba_ep_queue()
792 req->using_dma = 0; in usba_ep_queue()
793 req->last_transaction = 0; in usba_ep_queue()
795 _req->status = -EINPROGRESS; in usba_ep_queue()
796 _req->actual = 0; in usba_ep_queue()
798 if (ep->can_dma) in usba_ep_queue()
802 ret = -ESHUTDOWN; in usba_ep_queue()
803 spin_lock_irqsave(&udc->lock, flags); in usba_ep_queue()
804 if (ep->ep.desc) { in usba_ep_queue()
805 list_add_tail(&req->queue, &ep->queue); in usba_ep_queue()
807 if ((!ep_is_control(ep) && ep->is_in) || in usba_ep_queue()
809 && (ep->state == DATA_STAGE_IN in usba_ep_queue()
810 || ep->state == STATUS_STAGE_IN))) in usba_ep_queue()
816 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_queue()
824 req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status); in usba_update_req()
839 for (timeout = 40; timeout; --timeout) { in stop_dma()
850 dev_err(&ep->udc->pdev->dev, in stop_dma()
852 ep->ep.name); in stop_dma()
853 return -ETIMEDOUT; in stop_dma()
862 struct usba_udc *udc = ep->udc; in usba_ep_dequeue()
869 ep->ep.name, _req); in usba_ep_dequeue()
871 spin_lock_irqsave(&udc->lock, flags); in usba_ep_dequeue()
873 list_for_each_entry(iter, &ep->queue, queue) { in usba_ep_dequeue()
874 if (&iter->req != _req) in usba_ep_dequeue()
881 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
882 return -EINVAL; in usba_ep_dequeue()
885 if (req->using_dma) { in usba_ep_dequeue()
890 if (ep->queue.next == &req->queue) { in usba_ep_dequeue()
896 ep->last_dma_status = status; in usba_ep_dequeue()
899 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_dequeue()
909 list_del_init(&req->queue); in usba_ep_dequeue()
911 request_complete(ep, req, -ECONNRESET); in usba_ep_dequeue()
915 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
923 struct usba_udc *udc = ep->udc; in usba_ep_set_halt()
927 DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name, in usba_ep_set_halt()
930 if (!ep->ep.desc) { in usba_ep_set_halt()
932 ep->ep.name); in usba_ep_set_halt()
933 return -ENODEV; in usba_ep_set_halt()
935 if (ep->is_isoc) { in usba_ep_set_halt()
937 ep->ep.name); in usba_ep_set_halt()
938 return -ENOTTY; in usba_ep_set_halt()
941 spin_lock_irqsave(&udc->lock, flags); in usba_ep_set_halt()
947 if (!list_empty(&ep->queue) in usba_ep_set_halt()
948 || ((value && ep->is_in && (usba_ep_readl(ep, STA) in usba_ep_set_halt()
949 & USBA_BF(BUSY_BANKS, -1L))))) { in usba_ep_set_halt()
950 ret = -EAGAIN; in usba_ep_set_halt()
960 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_set_halt()
975 struct usba_udc *udc = ep->udc; in usba_ep_fifo_flush()
977 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_fifo_flush()
1004 int ret = -EINVAL; in usba_udc_wakeup()
1006 spin_lock_irqsave(&udc->lock, flags); in usba_udc_wakeup()
1007 if (udc->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { in usba_udc_wakeup()
1012 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_wakeup()
1023 gadget->is_selfpowered = (is_selfpowered != 0); in usba_udc_set_selfpowered()
1024 spin_lock_irqsave(&udc->lock, flags); in usba_udc_set_selfpowered()
1026 udc->devstatus |= 1 << USB_DEVICE_SELF_POWERED; in usba_udc_set_selfpowered()
1028 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in usba_udc_set_selfpowered()
1029 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_set_selfpowered()
1047 list_for_each_entry(_ep, &gadget->ep_list, ep_list) { in atmel_usba_match_ep()
1062 ep->nr_banks = 1; in atmel_usba_match_ep()
1066 ep->fifo_size = 1024; in atmel_usba_match_ep()
1067 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1068 ep->nr_banks = 2; in atmel_usba_match_ep()
1072 ep->fifo_size = 512; in atmel_usba_match_ep()
1073 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1074 ep->nr_banks = 1; in atmel_usba_match_ep()
1078 if (desc->wMaxPacketSize == 0) in atmel_usba_match_ep()
1079 ep->fifo_size = in atmel_usba_match_ep()
1080 roundup_pow_of_two(_ep->maxpacket_limit); in atmel_usba_match_ep()
1082 ep->fifo_size = in atmel_usba_match_ep()
1083 roundup_pow_of_two(le16_to_cpu(desc->wMaxPacketSize)); in atmel_usba_match_ep()
1084 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1085 ep->nr_banks = 1; in atmel_usba_match_ep()
1090 usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); in atmel_usba_match_ep()
1093 if (ep->fifo_size <= 8) in atmel_usba_match_ep()
1094 ep->ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8); in atmel_usba_match_ep()
1097 ep->ept_cfg = in atmel_usba_match_ep()
1098 USBA_BF(EPT_SIZE, fls(ep->fifo_size - 1) - 3); in atmel_usba_match_ep()
1100 ep->ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks); in atmel_usba_match_ep()
1133 * Called with interrupts disabled and udc->lock held.
1142 ep = to_usba_ep(udc->gadget.ep0); in reset_all_endpoints()
1143 list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) { in reset_all_endpoints()
1144 list_del_init(&req->queue); in reset_all_endpoints()
1145 request_complete(ep, req, -ECONNRESET); in reset_all_endpoints()
1154 return to_usba_ep(udc->gadget.ep0); in get_ep_by_addr()
1156 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { in get_ep_by_addr()
1159 if (!ep->ep.desc) in get_ep_by_addr()
1161 bEndpointAddress = ep->ep.desc->bEndpointAddress; in get_ep_by_addr()
1172 /* Called with interrupts disabled and udc->lock held */
1176 ep->state = WAIT_FOR_SETUP; in set_protocol_stall()
1214 struct device *dev = &udc->pdev->dev; in do_test_mode()
1217 test_mode = udc->test_mode; in do_test_mode()
1235 * Test_SE0_NAK: Force high-speed mode and set up ep0 in do_test_mode()
1238 ep = &udc->usba_ep[0]; in do_test_mode()
1256 ep = &udc->usba_ep[0]; in do_test_mode()
1268 memcpy_toio(ep->fifo, test_packet_buffer, in do_test_mode()
1276 return -EINVAL; in do_test_mode()
1285 if (crq->wValue == cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP)) in feature_is_dev_remote_wakeup()
1292 if (crq->wValue == cpu_to_le16(USB_DEVICE_TEST_MODE)) in feature_is_dev_test_mode()
1299 if (crq->wValue == cpu_to_le16(USB_ENDPOINT_HALT)) in feature_is_ep_halt()
1309 switch (crq->bRequest) { in handle_ep0_setup()
1313 if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) { in handle_ep0_setup()
1314 status = cpu_to_le16(udc->devstatus); in handle_ep0_setup()
1315 } else if (crq->bRequestType in handle_ep0_setup()
1318 } else if (crq->bRequestType in handle_ep0_setup()
1322 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1333 if (crq->wLength != cpu_to_le16(sizeof(status))) in handle_ep0_setup()
1335 ep->state = DATA_STAGE_IN; in handle_ep0_setup()
1336 writew_relaxed(status, ep->fifo); in handle_ep0_setup()
1342 if (crq->bRequestType == USB_RECIP_DEVICE) { in handle_ep0_setup()
1344 udc->devstatus in handle_ep0_setup()
1349 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { in handle_ep0_setup()
1352 if (crq->wLength != cpu_to_le16(0) in handle_ep0_setup()
1355 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1360 if (target->index != 0) in handle_ep0_setup()
1372 if (crq->bRequestType == USB_RECIP_DEVICE) { in handle_ep0_setup()
1375 ep->state = STATUS_STAGE_TEST; in handle_ep0_setup()
1376 udc->test_mode = le16_to_cpu(crq->wIndex); in handle_ep0_setup()
1379 udc->devstatus |= 1 << USB_DEVICE_REMOTE_WAKEUP; in handle_ep0_setup()
1383 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { in handle_ep0_setup()
1386 if (crq->wLength != cpu_to_le16(0) in handle_ep0_setup()
1390 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1403 if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) in handle_ep0_setup()
1406 set_address(udc, le16_to_cpu(crq->wValue)); in handle_ep0_setup()
1408 ep->state = STATUS_STAGE_ADDR; in handle_ep0_setup()
1413 spin_unlock(&udc->lock); in handle_ep0_setup()
1414 retval = udc->driver->setup(&udc->gadget, crq); in handle_ep0_setup()
1415 spin_lock(&udc->lock); in handle_ep0_setup()
1423 ep->ep.name, crq->bRequestType, crq->bRequest, in handle_ep0_setup()
1424 le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex), in handle_ep0_setup()
1425 le16_to_cpu(crq->wLength)); in handle_ep0_setup()
1427 return -1; in handle_ep0_setup()
1441 ep->ep.name, ep->state, epstatus, epctrl); in usba_control_irq()
1444 if (!list_empty(&ep->queue)) in usba_control_irq()
1445 req = list_entry(ep->queue.next, in usba_control_irq()
1449 if (req->submitted) in usba_control_irq()
1454 if (req->last_transaction) { in usba_control_irq()
1463 switch (ep->state) { in usba_control_irq()
1467 ep->state = STATUS_STAGE_OUT; in usba_control_irq()
1474 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1478 list_del_init(&req->queue); in usba_control_irq()
1483 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1487 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1494 ep->ep.name, ep->state); in usba_control_irq()
1502 switch (ep->state) { in usba_control_irq()
1508 list_del_init(&req->queue); in usba_control_irq()
1511 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1523 ep->ep.name, ep->state); in usba_control_irq()
1538 if (ep->state != WAIT_FOR_SETUP) { in usba_control_irq()
1544 int status = -EPROTO; in usba_control_irq()
1551 if (ep->state == STATUS_STAGE_OUT in usba_control_irq()
1552 || ep->state == STATUS_STAGE_IN) { in usba_control_irq()
1558 list_del_init(&req->queue); in usba_control_irq()
1572 DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo); in usba_control_irq()
1573 memcpy_fromio(crq.data, ep->fifo, sizeof(crq)); in usba_control_irq()
1580 ep->state, crq.crq.bRequestType, in usba_control_irq()
1590 ep->state = DATA_STAGE_IN; in usba_control_irq()
1593 ep->state = DATA_STAGE_OUT; in usba_control_irq()
1595 ep->state = STATUS_STAGE_IN; in usba_control_irq()
1598 ret = -1; in usba_control_irq()
1599 if (ep->index == 0) in usba_control_irq()
1602 spin_unlock(&udc->lock); in usba_control_irq()
1603 ret = udc->driver->setup(&udc->gadget, &crq.crq); in usba_control_irq()
1604 spin_lock(&udc->lock); in usba_control_irq()
1609 le16_to_cpu(crq.crq.wLength), ep->state, ret); in usba_control_irq()
1627 DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n", ep->ep.name, epstatus); in usba_ep_irq()
1630 DBG(DBG_BUS, "%s: TX PK ready\n", ep->ep.name); in usba_ep_irq()
1632 if (list_empty(&ep->queue)) { in usba_ep_irq()
1633 dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n"); in usba_ep_irq()
1638 req = list_entry(ep->queue.next, struct usba_request, queue); in usba_ep_irq()
1640 if (req->using_dma) { in usba_ep_irq()
1641 /* Send a zero-length packet */ in usba_ep_irq()
1646 list_del_init(&req->queue); in usba_ep_irq()
1650 if (req->submitted) in usba_ep_irq()
1655 if (req->last_transaction) { in usba_ep_irq()
1656 list_del_init(&req->queue); in usba_ep_irq()
1666 DBG(DBG_BUS, "%s: RX data ready\n", ep->ep.name); in usba_ep_irq()
1679 ep->last_dma_status = status; in usba_dma_irq()
1685 dev_err(&udc->pdev->dev, in usba_dma_irq()
1687 dev_err(&udc->pdev->dev, in usba_dma_irq()
1697 if (list_empty(&ep->queue)) in usba_dma_irq()
1702 req = list_entry(ep->queue.next, struct usba_request, queue); in usba_dma_irq()
1705 list_del_init(&req->queue); in usba_dma_irq()
1721 spin_lock(&udc->lock); in usba_udc_irq()
1731 udc->suspended = true; in usba_udc_irq()
1733 udc->bias_pulse_needed = true; in usba_udc_irq()
1736 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1737 && udc->driver && udc->driver->suspend) { in usba_udc_irq()
1738 spin_unlock(&udc->lock); in usba_udc_irq()
1739 udc->driver->suspend(&udc->gadget); in usba_udc_irq()
1740 spin_lock(&udc->lock); in usba_udc_irq()
1752 udc->suspended = false; in usba_udc_irq()
1758 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1759 && udc->driver && udc->driver->resume) { in usba_udc_irq()
1760 spin_unlock(&udc->lock); in usba_udc_irq()
1761 udc->driver->resume(&udc->gadget); in usba_udc_irq()
1762 spin_lock(&udc->lock); in usba_udc_irq()
1774 usba_dma_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1783 for (i = 0; i < udc->num_ep; i++) in usba_udc_irq()
1785 if (ep_is_control(&udc->usba_ep[i])) in usba_udc_irq()
1786 usba_control_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1788 usba_ep_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1802 if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) { in usba_udc_irq()
1803 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_udc_irq()
1804 spin_unlock(&udc->lock); in usba_udc_irq()
1805 usb_gadget_udc_reset(&udc->gadget, udc->driver); in usba_udc_irq()
1806 spin_lock(&udc->lock); in usba_udc_irq()
1810 udc->gadget.speed = USB_SPEED_HIGH; in usba_udc_irq()
1812 udc->gadget.speed = USB_SPEED_FULL; in usba_udc_irq()
1814 usb_speed_string(udc->gadget.speed)); in usba_udc_irq()
1816 ep0 = &udc->usba_ep[0]; in usba_udc_irq()
1817 ep0->ep.desc = &usba_ep0_desc; in usba_udc_irq()
1818 ep0->state = WAIT_FOR_SETUP; in usba_udc_irq()
1827 udc->suspended = false; in usba_udc_irq()
1838 dev_err(&udc->pdev->dev, in usba_udc_irq()
1842 for (i = 1; i < udc->num_ep; i++) { in usba_udc_irq()
1843 ep = &udc->usba_ep[i]; in usba_udc_irq()
1844 if (ep->ep.claimed) { in usba_udc_irq()
1845 usba_ep_writel(ep, CFG, ep->ept_cfg); in usba_udc_irq()
1847 dev_err(&udc->pdev->dev, in usba_udc_irq()
1853 spin_unlock(&udc->lock); in usba_udc_irq()
1862 if (udc->clocked) in start_clock()
1865 pm_stay_awake(&udc->pdev->dev); in start_clock()
1867 ret = clk_prepare_enable(udc->pclk); in start_clock()
1870 ret = clk_prepare_enable(udc->hclk); in start_clock()
1872 clk_disable_unprepare(udc->pclk); in start_clock()
1876 udc->clocked = true; in start_clock()
1882 if (!udc->clocked) in stop_clock()
1885 clk_disable_unprepare(udc->hclk); in stop_clock()
1886 clk_disable_unprepare(udc->pclk); in stop_clock()
1888 udc->clocked = false; in stop_clock()
1890 pm_relax(&udc->pdev->dev); in stop_clock()
1902 if (udc->suspended) in usba_start()
1905 spin_lock_irqsave(&udc->lock, flags); in usba_start()
1910 udc->int_enb_cache = 0; in usba_start()
1916 spin_unlock_irqrestore(&udc->lock, flags); in usba_start()
1925 if (udc->suspended) in usba_stop()
1928 spin_lock_irqsave(&udc->lock, flags); in usba_stop()
1929 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_stop()
1935 spin_unlock_irqrestore(&udc->lock, flags); in usba_stop()
1948 mutex_lock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1951 if (vbus != udc->vbus_prev) { in usba_vbus_irq_thread()
1955 udc->suspended = false; in usba_vbus_irq_thread()
1956 if (udc->driver->disconnect) in usba_vbus_irq_thread()
1957 udc->driver->disconnect(&udc->gadget); in usba_vbus_irq_thread()
1961 udc->vbus_prev = vbus; in usba_vbus_irq_thread()
1964 mutex_unlock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1974 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_pullup()
1981 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_pullup()
1993 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
1994 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; in atmel_usba_start()
1995 udc->driver = driver; in atmel_usba_start()
1996 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
1998 mutex_lock(&udc->vbus_mutex); in atmel_usba_start()
2000 if (udc->vbus_pin) in atmel_usba_start()
2001 enable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2004 udc->vbus_prev = vbus_is_present(udc); in atmel_usba_start()
2005 if (udc->vbus_prev) { in atmel_usba_start()
2011 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2015 if (udc->vbus_pin) in atmel_usba_start()
2016 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2018 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2020 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
2021 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in atmel_usba_start()
2022 udc->driver = NULL; in atmel_usba_start()
2023 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
2031 if (udc->vbus_pin) in atmel_usba_stop()
2032 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_stop()
2034 udc->suspended = false; in atmel_usba_stop()
2037 udc->driver = NULL; in atmel_usba_stop()
2044 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9rl_toggle_bias()
2050 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, 0); in at91sam9g45_pulse_bias()
2051 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9g45_pulse_bias()
2119 { .compatible = "atmel,at91sam9rl-udc", .data = &udc_at91sam9rl_cfg },
2120 { .compatible = "atmel,at91sam9g45-udc", .data = &udc_at91sam9g45_cfg },
2121 { .compatible = "atmel,sama5d3-udc", .data = &udc_sama5d3_cfg },
2122 { .compatible = "microchip,sam9x60-udc", .data = &udc_sam9x60_cfg },
2129 { .compatible = "atmel,at91sam9g45-pmc" },
2130 { .compatible = "atmel,at91sam9rl-pmc" },
2131 { .compatible = "atmel,at91sam9x5-pmc" },
2138 struct device_node *np = pdev->dev.of_node; in atmel_udc_of_init()
2147 return ERR_PTR(-EINVAL); in atmel_udc_of_init()
2149 udc_config = match->data; in atmel_udc_of_init()
2150 udc->ep_prealloc = udc_config->ep_prealloc; in atmel_udc_of_init()
2151 udc->errata = udc_config->errata; in atmel_udc_of_init()
2152 if (udc->errata) { in atmel_udc_of_init()
2156 return ERR_PTR(-ENODEV); in atmel_udc_of_init()
2158 udc->pmc = syscon_node_to_regmap(pp); in atmel_udc_of_init()
2160 if (IS_ERR(udc->pmc)) in atmel_udc_of_init()
2161 return ERR_CAST(udc->pmc); in atmel_udc_of_init()
2164 udc->num_ep = 0; in atmel_udc_of_init()
2166 udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus", in atmel_udc_of_init()
2168 if (IS_ERR(udc->vbus_pin)) in atmel_udc_of_init()
2169 return ERR_CAST(udc->vbus_pin); in atmel_udc_of_init()
2172 udc->num_ep = udc_config->num_ep; in atmel_udc_of_init()
2174 udc->num_ep = usba_config_fifo_table(udc); in atmel_udc_of_init()
2177 eps = devm_kcalloc(&pdev->dev, udc->num_ep, sizeof(struct usba_ep), in atmel_udc_of_init()
2180 return ERR_PTR(-ENOMEM); in atmel_udc_of_init()
2182 udc->gadget.ep0 = &eps[0].ep; in atmel_udc_of_init()
2187 while (i < udc->num_ep) { in atmel_udc_of_init()
2188 const struct usba_ep_config *ep_cfg = &udc_config->config[i]; in atmel_udc_of_init()
2192 ep->index = fifo_mode ? udc->fifo_cfg[i].hw_ep_num : i; in atmel_udc_of_init()
2195 if (ep->index == 0) in atmel_udc_of_init()
2196 ep->fifo_size = 64; in atmel_udc_of_init()
2198 ep->fifo_size = 1024; in atmel_udc_of_init()
2201 if (ep->fifo_size < udc->fifo_cfg[i].fifo_size) in atmel_udc_of_init()
2202 dev_warn(&pdev->dev, in atmel_udc_of_init()
2203 "Using default max fifo-size value\n"); in atmel_udc_of_init()
2205 ep->fifo_size = udc->fifo_cfg[i].fifo_size; in atmel_udc_of_init()
2208 ep->nr_banks = ep_cfg->nr_banks; in atmel_udc_of_init()
2210 if (ep->nr_banks < udc->fifo_cfg[i].nr_banks) in atmel_udc_of_init()
2211 dev_warn(&pdev->dev, in atmel_udc_of_init()
2212 "Using default max nb-banks value\n"); in atmel_udc_of_init()
2214 ep->nr_banks = udc->fifo_cfg[i].nr_banks; in atmel_udc_of_init()
2217 ep->can_dma = ep_cfg->can_dma; in atmel_udc_of_init()
2218 ep->can_isoc = ep_cfg->can_isoc; in atmel_udc_of_init()
2220 sprintf(ep->name, "ep%d", ep->index); in atmel_udc_of_init()
2221 ep->ep.name = ep->name; in atmel_udc_of_init()
2223 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); in atmel_udc_of_init()
2224 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); in atmel_udc_of_init()
2225 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); in atmel_udc_of_init()
2226 ep->ep.ops = &usba_ep_ops; in atmel_udc_of_init()
2227 usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); in atmel_udc_of_init()
2228 ep->udc = udc; in atmel_udc_of_init()
2229 INIT_LIST_HEAD(&ep->queue); in atmel_udc_of_init()
2231 if (ep->index == 0) { in atmel_udc_of_init()
2232 ep->ep.caps.type_control = true; in atmel_udc_of_init()
2234 ep->ep.caps.type_iso = ep->can_isoc; in atmel_udc_of_init()
2235 ep->ep.caps.type_bulk = true; in atmel_udc_of_init()
2236 ep->ep.caps.type_int = true; in atmel_udc_of_init()
2239 ep->ep.caps.dir_in = true; in atmel_udc_of_init()
2240 ep->ep.caps.dir_out = true; in atmel_udc_of_init()
2247 if (ep->fifo_size <= 8) in atmel_udc_of_init()
2248 ep->ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8); in atmel_udc_of_init()
2251 ep->ept_cfg = in atmel_udc_of_init()
2252 USBA_BF(EPT_SIZE, fls(ep->fifo_size - 1) - 3); in atmel_udc_of_init()
2254 ep->ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks); in atmel_udc_of_init()
2258 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in atmel_udc_of_init()
2264 dev_err(&pdev->dev, "of_probe: no endpoint specified\n"); in atmel_udc_of_init()
2265 ret = -EINVAL; in atmel_udc_of_init()
2281 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); in usba_udc_probe()
2283 return -ENOMEM; in usba_udc_probe()
2285 udc->gadget = usba_gadget_template; in usba_udc_probe()
2286 INIT_LIST_HEAD(&udc->gadget.ep_list); in usba_udc_probe()
2289 udc->regs = devm_ioremap_resource(&pdev->dev, res); in usba_udc_probe()
2290 if (IS_ERR(udc->regs)) in usba_udc_probe()
2291 return PTR_ERR(udc->regs); in usba_udc_probe()
2292 dev_info(&pdev->dev, "MMIO registers at %pR mapped at %p\n", in usba_udc_probe()
2293 res, udc->regs); in usba_udc_probe()
2296 udc->fifo = devm_ioremap_resource(&pdev->dev, res); in usba_udc_probe()
2297 if (IS_ERR(udc->fifo)) in usba_udc_probe()
2298 return PTR_ERR(udc->fifo); in usba_udc_probe()
2299 dev_info(&pdev->dev, "FIFO at %pR mapped at %p\n", res, udc->fifo); in usba_udc_probe()
2305 pclk = devm_clk_get(&pdev->dev, "pclk"); in usba_udc_probe()
2308 hclk = devm_clk_get(&pdev->dev, "hclk"); in usba_udc_probe()
2312 spin_lock_init(&udc->lock); in usba_udc_probe()
2313 mutex_init(&udc->vbus_mutex); in usba_udc_probe()
2314 udc->pdev = pdev; in usba_udc_probe()
2315 udc->pclk = pclk; in usba_udc_probe()
2316 udc->hclk = hclk; in usba_udc_probe()
2323 dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); in usba_udc_probe()
2330 udc->usba_ep = atmel_udc_of_init(pdev, udc); in usba_udc_probe()
2334 if (IS_ERR(udc->usba_ep)) in usba_udc_probe()
2335 return PTR_ERR(udc->usba_ep); in usba_udc_probe()
2337 ret = devm_request_irq(&pdev->dev, irq, usba_udc_irq, 0, in usba_udc_probe()
2340 dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", in usba_udc_probe()
2344 udc->irq = irq; in usba_udc_probe()
2346 if (udc->vbus_pin) { in usba_udc_probe()
2347 irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN); in usba_udc_probe()
2348 ret = devm_request_threaded_irq(&pdev->dev, in usba_udc_probe()
2349 gpiod_to_irq(udc->vbus_pin), NULL, in usba_udc_probe()
2353 udc->vbus_pin = NULL; in usba_udc_probe()
2354 dev_warn(&udc->pdev->dev, in usba_udc_probe()
2360 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in usba_udc_probe()
2363 device_init_wakeup(&pdev->dev, 1); in usba_udc_probe()
2366 for (i = 1; i < udc->num_ep; i++) in usba_udc_probe()
2367 usba_ep_init_debugfs(udc, &udc->usba_ep[i]); in usba_udc_probe()
2379 device_init_wakeup(&pdev->dev, 0); in usba_udc_remove()
2380 usb_del_gadget_udc(&udc->gadget); in usba_udc_remove()
2382 for (i = 1; i < udc->num_ep; i++) in usba_udc_remove()
2383 usba_ep_cleanup_debugfs(&udc->usba_ep[i]); in usba_udc_remove()
2395 if (!udc->driver) in usba_udc_suspend()
2398 mutex_lock(&udc->vbus_mutex); in usba_udc_suspend()
2401 udc->suspended = false; in usba_udc_suspend()
2407 * Device may wake up. We stay clocked if we failed in usba_udc_suspend()
2410 if (udc->vbus_pin) { in usba_udc_suspend()
2413 enable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_suspend()
2416 enable_irq_wake(udc->irq); in usba_udc_suspend()
2419 mutex_unlock(&udc->vbus_mutex); in usba_udc_suspend()
2428 if (!udc->driver) in usba_udc_resume()
2432 if (udc->vbus_pin) in usba_udc_resume()
2433 disable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_resume()
2435 disable_irq_wake(udc->irq); in usba_udc_resume()
2439 mutex_lock(&udc->vbus_mutex); in usba_udc_resume()
2440 udc->vbus_prev = vbus_is_present(udc); in usba_udc_resume()
2441 if (udc->vbus_prev) in usba_udc_resume()
2443 mutex_unlock(&udc->vbus_mutex); in usba_udc_resume()