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()
110 list_del(&req->queue); in queue_dbg_read()
114 actual += len - remaining; in queue_dbg_read()
118 nbytes -= len; in queue_dbg_read()
128 struct list_head *queue_data = file->private_data; in queue_dbg_release()
132 list_del(&req->queue); in queue_dbg_release()
144 int ret = -ENOMEM; in regs_dbg_open()
147 udc = inode->i_private; in regs_dbg_open()
148 data = kmalloc(inode->i_size, GFP_KERNEL); in regs_dbg_open()
152 spin_lock_irq(&udc->lock); in regs_dbg_open()
153 for (i = 0; i < inode->i_size / 4; i++) in regs_dbg_open()
154 data[i] = readl_relaxed(udc->regs + i * 4); in regs_dbg_open()
155 spin_unlock_irq(&udc->lock); in regs_dbg_open()
157 file->private_data = data; in regs_dbg_open()
174 file->private_data, in regs_dbg_read()
175 file_inode(file)->i_size); in regs_dbg_read()
183 kfree(file->private_data); in regs_dbg_release()
207 ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root); in usba_ep_init_debugfs()
208 ep->debugfs_dir = ep_root; in usba_ep_init_debugfs()
211 if (ep->can_dma) in usba_ep_init_debugfs()
213 &ep->last_dma_status); in usba_ep_init_debugfs()
215 debugfs_create_u32("state", 0400, ep_root, &ep->state); in usba_ep_init_debugfs()
220 debugfs_remove_recursive(ep->debugfs_dir); in usba_ep_cleanup_debugfs()
228 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in usba_init_debugfs()
229 udc->debugfs_root = root; in usba_init_debugfs()
231 regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM, in usba_init_debugfs()
240 usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0)); in usba_init_debugfs()
245 usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0)); in usba_cleanup_debugfs()
246 debugfs_remove_recursive(udc->debugfs_root); in usba_cleanup_debugfs()
276 /* mode 0 - uses autoconfig */
278 /* mode 1 - fits in 8KB, generic max fifo configuration */
289 /* mode 2 - fits in 8KB, performance max fifo configuration */
297 /* mode 3 - fits in 8KB, mixed fifo configuration */
308 /* mode 4 - fits in 8KB, custom fifo configuration */
331 udc->fifo_cfg = NULL; in usba_config_fifo_table()
335 udc->fifo_cfg = mode_1_cfg; in usba_config_fifo_table()
339 udc->fifo_cfg = mode_2_cfg; in usba_config_fifo_table()
343 udc->fifo_cfg = mode_3_cfg; in usba_config_fifo_table()
347 udc->fifo_cfg = mode_4_cfg; in usba_config_fifo_table()
358 return udc->int_enb_cache; in usba_int_enb_get()
365 val = udc->int_enb_cache | mask; in usba_int_enb_set()
367 udc->int_enb_cache = val; in usba_int_enb_set()
374 val = udc->int_enb_cache & ~mask; in usba_int_enb_clear()
376 udc->int_enb_cache = val; in usba_int_enb_clear()
381 if (udc->vbus_pin) in vbus_is_present()
382 return gpiod_get_value(udc->vbus_pin); in vbus_is_present()
390 if (udc->errata && udc->errata->toggle_bias) in toggle_bias()
391 udc->errata->toggle_bias(udc, is_on); in toggle_bias()
396 if (!udc->bias_pulse_needed) in generate_bias_pulse()
399 if (udc->errata && udc->errata->pulse_bias) in generate_bias_pulse()
400 udc->errata->pulse_bias(udc); in generate_bias_pulse()
402 udc->bias_pulse_needed = false; in generate_bias_pulse()
409 transaction_len = req->req.length - req->req.actual; in next_fifo_transaction()
410 req->last_transaction = 1; in next_fifo_transaction()
411 if (transaction_len > ep->ep.maxpacket) { in next_fifo_transaction()
412 transaction_len = ep->ep.maxpacket; in next_fifo_transaction()
413 req->last_transaction = 0; in next_fifo_transaction()
414 } else if (transaction_len == ep->ep.maxpacket && req->req.zero) in next_fifo_transaction()
415 req->last_transaction = 0; in next_fifo_transaction()
418 ep->ep.name, req, transaction_len, in next_fifo_transaction()
419 req->last_transaction ? ", done" : ""); in next_fifo_transaction()
421 memcpy_toio(ep->fifo, req->req.buf + req->req.actual, transaction_len); in next_fifo_transaction()
423 req->req.actual += transaction_len; in next_fifo_transaction()
429 ep->ep.name, req, req->req.length); in submit_request()
431 req->req.actual = 0; in submit_request()
432 req->submitted = 1; in submit_request()
434 if (req->using_dma) { in submit_request()
435 if (req->req.length == 0) { in submit_request()
440 if (req->req.zero) in submit_request()
445 usba_dma_writel(ep, ADDRESS, req->req.dma); in submit_request()
446 usba_dma_writel(ep, CONTROL, req->ctrl); in submit_request()
449 if (req->last_transaction) { in submit_request()
465 if (list_empty(&ep->queue)) { in submit_next_request()
470 req = list_entry(ep->queue.next, struct usba_request, queue); in submit_next_request()
471 if (!req->submitted) in submit_next_request()
477 ep->state = STATUS_STAGE_IN; in send_status()
484 struct usba_udc *udc = ep->udc; in receive_data()
496 if (list_empty(&ep->queue)) { in receive_data()
500 req = list_entry(ep->queue.next, in receive_data()
507 if (req->req.actual + bytecount >= req->req.length) { in receive_data()
509 bytecount = req->req.length - req->req.actual; in receive_data()
512 memcpy_fromio(req->req.buf + req->req.actual, in receive_data()
513 ep->fifo, bytecount); in receive_data()
514 req->req.actual += bytecount; in receive_data()
519 DBG(DBG_QUEUE, "%s: request done\n", ep->ep.name); in receive_data()
520 req->req.status = 0; in receive_data()
521 list_del_init(&req->queue); in receive_data()
523 spin_unlock(&udc->lock); in receive_data()
524 usb_gadget_giveback_request(&ep->ep, &req->req); in receive_data()
525 spin_lock(&udc->lock); in receive_data()
541 struct usba_udc *udc = ep->udc; in request_complete()
543 WARN_ON(!list_empty(&req->queue)); in request_complete()
545 if (req->req.status == -EINPROGRESS) in request_complete()
546 req->req.status = status; in request_complete()
548 if (req->using_dma) in request_complete()
549 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); in request_complete()
553 ep->ep.name, req, req->req.status, req->req.actual); in request_complete()
555 spin_unlock(&udc->lock); in request_complete()
556 usb_gadget_giveback_request(&ep->ep, &req->req); in request_complete()
557 spin_lock(&udc->lock); in request_complete()
566 list_del_init(&req->queue); in request_complete_list()
575 struct usba_udc *udc = ep->udc; in usba_ep_enable()
579 DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc); in usba_ep_enable()
583 if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index) in usba_ep_enable()
584 || ep->index == 0 in usba_ep_enable()
585 || desc->bDescriptorType != USB_DT_ENDPOINT in usba_ep_enable()
587 || maxpacket > ep->fifo_size) { in usba_ep_enable()
589 return -EINVAL; in usba_ep_enable()
592 ep->is_isoc = 0; in usba_ep_enable()
593 ep->is_in = 0; in usba_ep_enable()
596 ep->ep.name, ep->ept_cfg, maxpacket); in usba_ep_enable()
599 ep->is_in = 1; in usba_ep_enable()
600 ep->ept_cfg |= USBA_EPT_DIR_IN; in usba_ep_enable()
605 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL); in usba_ep_enable()
608 if (!ep->can_isoc) { in usba_ep_enable()
610 ep->ep.name); in usba_ep_enable()
611 return -EINVAL; in usba_ep_enable()
620 return -EINVAL; in usba_ep_enable()
622 ep->is_isoc = 1; in usba_ep_enable()
623 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO); in usba_ep_enable()
624 ep->ept_cfg |= USBA_BF(NB_TRANS, nr_trans); in usba_ep_enable()
628 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK); in usba_ep_enable()
631 ep->ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT); in usba_ep_enable()
635 spin_lock_irqsave(&ep->udc->lock, flags); in usba_ep_enable()
637 ep->ep.desc = desc; in usba_ep_enable()
638 ep->ep.maxpacket = maxpacket; in usba_ep_enable()
640 usba_ep_writel(ep, CFG, ep->ept_cfg); in usba_ep_enable()
643 if (ep->can_dma) { in usba_ep_enable()
646 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index) | in usba_ep_enable()
647 USBA_BF(DMA_INT, 1 << ep->index)); in usba_ep_enable()
651 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_enable()
654 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_enable()
656 DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index, in usba_ep_enable()
667 struct usba_udc *udc = ep->udc; in usba_ep_disable()
671 DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name); in usba_ep_disable()
673 spin_lock_irqsave(&udc->lock, flags); in usba_ep_disable()
675 if (!ep->ep.desc) { in usba_ep_disable()
676 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
677 DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name); in usba_ep_disable()
678 return -EINVAL; in usba_ep_disable()
680 ep->ep.desc = NULL; in usba_ep_disable()
682 list_splice_init(&ep->queue, &req_list); in usba_ep_disable()
683 if (ep->can_dma) { in usba_ep_disable()
689 usba_int_enb_clear(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_disable()
691 request_complete_list(ep, &req_list, -ESHUTDOWN); in usba_ep_disable()
693 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
709 INIT_LIST_HEAD(&req->queue); in usba_ep_alloc_request()
711 return &req->req; in usba_ep_alloc_request()
731 ep->ep.name, req->req.length, &req->req.dma, in queue_dma()
732 req->req.zero ? 'Z' : 'z', in queue_dma()
733 req->req.short_not_ok ? 'S' : 's', in queue_dma()
734 req->req.no_interrupt ? 'I' : 'i'); in queue_dma()
736 if (req->req.length > 0x10000) { in queue_dma()
738 DBG(DBG_ERR, "invalid request length %u\n", req->req.length); in queue_dma()
739 return -EINVAL; in queue_dma()
742 ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in); in queue_dma()
746 req->using_dma = 1; in queue_dma()
747 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) in queue_dma()
751 if (!ep->is_in) in queue_dma()
752 req->ctrl |= USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; in queue_dma()
756 * possible. Check if we're still alive first -- we may have in queue_dma()
759 ret = -ESHUTDOWN; in queue_dma()
760 spin_lock_irqsave(&udc->lock, flags); in queue_dma()
761 if (ep->ep.desc) { in queue_dma()
762 if (list_empty(&ep->queue)) in queue_dma()
765 list_add_tail(&req->queue, &ep->queue); in queue_dma()
768 spin_unlock_irqrestore(&udc->lock, flags); in queue_dma()
778 struct usba_udc *udc = ep->udc; in usba_ep_queue()
783 ep->ep.name, req, _req->length); in usba_ep_queue()
785 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || in usba_ep_queue()
786 !ep->ep.desc) in usba_ep_queue()
787 return -ESHUTDOWN; in usba_ep_queue()
789 req->submitted = 0; in usba_ep_queue()
790 req->using_dma = 0; in usba_ep_queue()
791 req->last_transaction = 0; in usba_ep_queue()
793 _req->status = -EINPROGRESS; in usba_ep_queue()
794 _req->actual = 0; in usba_ep_queue()
796 if (ep->can_dma) in usba_ep_queue()
800 ret = -ESHUTDOWN; in usba_ep_queue()
801 spin_lock_irqsave(&udc->lock, flags); in usba_ep_queue()
802 if (ep->ep.desc) { in usba_ep_queue()
803 list_add_tail(&req->queue, &ep->queue); in usba_ep_queue()
805 if ((!ep_is_control(ep) && ep->is_in) || in usba_ep_queue()
807 && (ep->state == DATA_STAGE_IN in usba_ep_queue()
808 || ep->state == STATUS_STAGE_IN))) in usba_ep_queue()
814 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_queue()
822 req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status); in usba_update_req()
837 for (timeout = 40; timeout; --timeout) { in stop_dma()
848 dev_err(&ep->udc->pdev->dev, in stop_dma()
850 ep->ep.name); in stop_dma()
851 return -ETIMEDOUT; in stop_dma()
860 struct usba_udc *udc = ep->udc; in usba_ep_dequeue()
867 ep->ep.name, _req); in usba_ep_dequeue()
869 spin_lock_irqsave(&udc->lock, flags); in usba_ep_dequeue()
871 list_for_each_entry(iter, &ep->queue, queue) { in usba_ep_dequeue()
872 if (&iter->req != _req) in usba_ep_dequeue()
879 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
880 return -EINVAL; in usba_ep_dequeue()
883 if (req->using_dma) { in usba_ep_dequeue()
888 if (ep->queue.next == &req->queue) { in usba_ep_dequeue()
894 ep->last_dma_status = status; in usba_ep_dequeue()
897 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_dequeue()
907 list_del_init(&req->queue); in usba_ep_dequeue()
909 request_complete(ep, req, -ECONNRESET); in usba_ep_dequeue()
913 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
921 struct usba_udc *udc = ep->udc; in usba_ep_set_halt()
925 DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name, in usba_ep_set_halt()
928 if (!ep->ep.desc) { in usba_ep_set_halt()
930 ep->ep.name); in usba_ep_set_halt()
931 return -ENODEV; in usba_ep_set_halt()
933 if (ep->is_isoc) { in usba_ep_set_halt()
935 ep->ep.name); in usba_ep_set_halt()
936 return -ENOTTY; in usba_ep_set_halt()
939 spin_lock_irqsave(&udc->lock, flags); in usba_ep_set_halt()
945 if (!list_empty(&ep->queue) in usba_ep_set_halt()
946 || ((value && ep->is_in && (usba_ep_readl(ep, STA) in usba_ep_set_halt()
947 & USBA_BF(BUSY_BANKS, -1L))))) { in usba_ep_set_halt()
948 ret = -EAGAIN; in usba_ep_set_halt()
958 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_set_halt()
973 struct usba_udc *udc = ep->udc; in usba_ep_fifo_flush()
975 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_fifo_flush()
1002 int ret = -EINVAL; in usba_udc_wakeup()
1004 spin_lock_irqsave(&udc->lock, flags); in usba_udc_wakeup()
1005 if (udc->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { in usba_udc_wakeup()
1010 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_wakeup()
1021 gadget->is_selfpowered = (is_selfpowered != 0); in usba_udc_set_selfpowered()
1022 spin_lock_irqsave(&udc->lock, flags); in usba_udc_set_selfpowered()
1024 udc->devstatus |= 1 << USB_DEVICE_SELF_POWERED; in usba_udc_set_selfpowered()
1026 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in usba_udc_set_selfpowered()
1027 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_set_selfpowered()
1045 list_for_each_entry(_ep, &gadget->ep_list, ep_list) { in atmel_usba_match_ep()
1060 ep->nr_banks = 1; in atmel_usba_match_ep()
1064 ep->fifo_size = 1024; in atmel_usba_match_ep()
1065 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1066 ep->nr_banks = 2; in atmel_usba_match_ep()
1070 ep->fifo_size = 512; in atmel_usba_match_ep()
1071 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1072 ep->nr_banks = 1; in atmel_usba_match_ep()
1076 if (desc->wMaxPacketSize == 0) in atmel_usba_match_ep()
1077 ep->fifo_size = in atmel_usba_match_ep()
1078 roundup_pow_of_two(_ep->maxpacket_limit); in atmel_usba_match_ep()
1080 ep->fifo_size = in atmel_usba_match_ep()
1081 roundup_pow_of_two(le16_to_cpu(desc->wMaxPacketSize)); in atmel_usba_match_ep()
1082 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1083 ep->nr_banks = 1; in atmel_usba_match_ep()
1088 usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); in atmel_usba_match_ep()
1091 if (ep->fifo_size <= 8) in atmel_usba_match_ep()
1092 ep->ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8); in atmel_usba_match_ep()
1095 ep->ept_cfg = in atmel_usba_match_ep()
1096 USBA_BF(EPT_SIZE, fls(ep->fifo_size - 1) - 3); in atmel_usba_match_ep()
1098 ep->ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks); in atmel_usba_match_ep()
1131 * Called with interrupts disabled and udc->lock held.
1140 ep = to_usba_ep(udc->gadget.ep0); in reset_all_endpoints()
1141 list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) { in reset_all_endpoints()
1142 list_del_init(&req->queue); in reset_all_endpoints()
1143 request_complete(ep, req, -ECONNRESET); in reset_all_endpoints()
1152 return to_usba_ep(udc->gadget.ep0); in get_ep_by_addr()
1154 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { in get_ep_by_addr()
1157 if (!ep->ep.desc) in get_ep_by_addr()
1159 bEndpointAddress = ep->ep.desc->bEndpointAddress; in get_ep_by_addr()
1170 /* Called with interrupts disabled and udc->lock held */
1174 ep->state = WAIT_FOR_SETUP; in set_protocol_stall()
1212 struct device *dev = &udc->pdev->dev; in do_test_mode()
1215 test_mode = udc->test_mode; in do_test_mode()
1233 * Test_SE0_NAK: Force high-speed mode and set up ep0 in do_test_mode()
1236 ep = &udc->usba_ep[0]; in do_test_mode()
1254 ep = &udc->usba_ep[0]; in do_test_mode()
1266 memcpy_toio(ep->fifo, test_packet_buffer, in do_test_mode()
1274 return -EINVAL; in do_test_mode()
1283 if (crq->wValue == cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP)) in feature_is_dev_remote_wakeup()
1290 if (crq->wValue == cpu_to_le16(USB_DEVICE_TEST_MODE)) in feature_is_dev_test_mode()
1297 if (crq->wValue == cpu_to_le16(USB_ENDPOINT_HALT)) in feature_is_ep_halt()
1307 switch (crq->bRequest) { in handle_ep0_setup()
1311 if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) { in handle_ep0_setup()
1312 status = cpu_to_le16(udc->devstatus); in handle_ep0_setup()
1313 } else if (crq->bRequestType in handle_ep0_setup()
1316 } else if (crq->bRequestType in handle_ep0_setup()
1320 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1331 if (crq->wLength != cpu_to_le16(sizeof(status))) in handle_ep0_setup()
1333 ep->state = DATA_STAGE_IN; in handle_ep0_setup()
1334 writew_relaxed(status, ep->fifo); in handle_ep0_setup()
1340 if (crq->bRequestType == USB_RECIP_DEVICE) { in handle_ep0_setup()
1342 udc->devstatus in handle_ep0_setup()
1347 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { in handle_ep0_setup()
1350 if (crq->wLength != cpu_to_le16(0) in handle_ep0_setup()
1353 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1358 if (target->index != 0) in handle_ep0_setup()
1370 if (crq->bRequestType == USB_RECIP_DEVICE) { in handle_ep0_setup()
1373 ep->state = STATUS_STAGE_TEST; in handle_ep0_setup()
1374 udc->test_mode = le16_to_cpu(crq->wIndex); in handle_ep0_setup()
1377 udc->devstatus |= 1 << USB_DEVICE_REMOTE_WAKEUP; in handle_ep0_setup()
1381 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { in handle_ep0_setup()
1384 if (crq->wLength != cpu_to_le16(0) in handle_ep0_setup()
1388 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1401 if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) in handle_ep0_setup()
1404 set_address(udc, le16_to_cpu(crq->wValue)); in handle_ep0_setup()
1406 ep->state = STATUS_STAGE_ADDR; in handle_ep0_setup()
1411 spin_unlock(&udc->lock); in handle_ep0_setup()
1412 retval = udc->driver->setup(&udc->gadget, crq); in handle_ep0_setup()
1413 spin_lock(&udc->lock); in handle_ep0_setup()
1421 ep->ep.name, crq->bRequestType, crq->bRequest, in handle_ep0_setup()
1422 le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex), in handle_ep0_setup()
1423 le16_to_cpu(crq->wLength)); in handle_ep0_setup()
1425 return -1; in handle_ep0_setup()
1439 ep->ep.name, ep->state, epstatus, epctrl); in usba_control_irq()
1442 if (!list_empty(&ep->queue)) in usba_control_irq()
1443 req = list_entry(ep->queue.next, in usba_control_irq()
1447 if (req->submitted) in usba_control_irq()
1452 if (req->last_transaction) { in usba_control_irq()
1461 switch (ep->state) { in usba_control_irq()
1465 ep->state = STATUS_STAGE_OUT; in usba_control_irq()
1472 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1476 list_del_init(&req->queue); in usba_control_irq()
1481 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1485 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1492 ep->ep.name, ep->state); in usba_control_irq()
1500 switch (ep->state) { in usba_control_irq()
1506 list_del_init(&req->queue); in usba_control_irq()
1509 ep->state = WAIT_FOR_SETUP; in usba_control_irq()
1521 ep->ep.name, ep->state); in usba_control_irq()
1536 if (ep->state != WAIT_FOR_SETUP) { in usba_control_irq()
1542 int status = -EPROTO; in usba_control_irq()
1549 if (ep->state == STATUS_STAGE_OUT in usba_control_irq()
1550 || ep->state == STATUS_STAGE_IN) { in usba_control_irq()
1556 list_del_init(&req->queue); in usba_control_irq()
1570 DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo); in usba_control_irq()
1571 memcpy_fromio(crq.data, ep->fifo, sizeof(crq)); in usba_control_irq()
1578 ep->state, crq.crq.bRequestType, in usba_control_irq()
1588 ep->state = DATA_STAGE_IN; in usba_control_irq()
1591 ep->state = DATA_STAGE_OUT; in usba_control_irq()
1593 ep->state = STATUS_STAGE_IN; in usba_control_irq()
1596 ret = -1; in usba_control_irq()
1597 if (ep->index == 0) in usba_control_irq()
1600 spin_unlock(&udc->lock); in usba_control_irq()
1601 ret = udc->driver->setup(&udc->gadget, &crq.crq); in usba_control_irq()
1602 spin_lock(&udc->lock); in usba_control_irq()
1607 le16_to_cpu(crq.crq.wLength), ep->state, ret); in usba_control_irq()
1625 DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n", ep->ep.name, epstatus); in usba_ep_irq()
1628 DBG(DBG_BUS, "%s: TX PK ready\n", ep->ep.name); in usba_ep_irq()
1630 if (list_empty(&ep->queue)) { in usba_ep_irq()
1631 dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n"); in usba_ep_irq()
1636 req = list_entry(ep->queue.next, struct usba_request, queue); in usba_ep_irq()
1638 if (req->using_dma) { in usba_ep_irq()
1639 /* Send a zero-length packet */ in usba_ep_irq()
1644 list_del_init(&req->queue); in usba_ep_irq()
1648 if (req->submitted) in usba_ep_irq()
1653 if (req->last_transaction) { in usba_ep_irq()
1654 list_del_init(&req->queue); in usba_ep_irq()
1664 DBG(DBG_BUS, "%s: RX data ready\n", ep->ep.name); in usba_ep_irq()
1677 ep->last_dma_status = status; in usba_dma_irq()
1683 dev_err(&udc->pdev->dev, in usba_dma_irq()
1685 dev_err(&udc->pdev->dev, in usba_dma_irq()
1695 if (list_empty(&ep->queue)) in usba_dma_irq()
1700 req = list_entry(ep->queue.next, struct usba_request, queue); in usba_dma_irq()
1703 list_del_init(&req->queue); in usba_dma_irq()
1719 spin_lock(&udc->lock); in usba_udc_irq()
1729 udc->suspended = true; in usba_udc_irq()
1731 udc->bias_pulse_needed = true; in usba_udc_irq()
1734 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1735 && udc->driver && udc->driver->suspend) { in usba_udc_irq()
1736 spin_unlock(&udc->lock); in usba_udc_irq()
1737 udc->driver->suspend(&udc->gadget); in usba_udc_irq()
1738 spin_lock(&udc->lock); in usba_udc_irq()
1750 udc->suspended = false; in usba_udc_irq()
1756 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1757 && udc->driver && udc->driver->resume) { in usba_udc_irq()
1758 spin_unlock(&udc->lock); in usba_udc_irq()
1759 udc->driver->resume(&udc->gadget); in usba_udc_irq()
1760 spin_lock(&udc->lock); in usba_udc_irq()
1772 usba_dma_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1781 for (i = 0; i < udc->num_ep; i++) in usba_udc_irq()
1783 if (ep_is_control(&udc->usba_ep[i])) in usba_udc_irq()
1784 usba_control_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1786 usba_ep_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1800 if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) { in usba_udc_irq()
1801 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_udc_irq()
1802 spin_unlock(&udc->lock); in usba_udc_irq()
1803 usb_gadget_udc_reset(&udc->gadget, udc->driver); in usba_udc_irq()
1804 spin_lock(&udc->lock); in usba_udc_irq()
1808 udc->gadget.speed = USB_SPEED_HIGH; in usba_udc_irq()
1810 udc->gadget.speed = USB_SPEED_FULL; in usba_udc_irq()
1812 usb_speed_string(udc->gadget.speed)); in usba_udc_irq()
1814 ep0 = &udc->usba_ep[0]; in usba_udc_irq()
1815 ep0->ep.desc = &usba_ep0_desc; in usba_udc_irq()
1816 ep0->state = WAIT_FOR_SETUP; in usba_udc_irq()
1825 udc->suspended = false; in usba_udc_irq()
1836 dev_err(&udc->pdev->dev, in usba_udc_irq()
1840 for (i = 1; i < udc->num_ep; i++) { in usba_udc_irq()
1841 ep = &udc->usba_ep[i]; in usba_udc_irq()
1842 if (ep->ep.claimed) { in usba_udc_irq()
1843 usba_ep_writel(ep, CFG, ep->ept_cfg); in usba_udc_irq()
1845 dev_err(&udc->pdev->dev, in usba_udc_irq()
1851 spin_unlock(&udc->lock); in usba_udc_irq()
1860 if (udc->clocked) in start_clock()
1863 pm_stay_awake(&udc->pdev->dev); in start_clock()
1865 ret = clk_prepare_enable(udc->pclk); in start_clock()
1868 ret = clk_prepare_enable(udc->hclk); in start_clock()
1870 clk_disable_unprepare(udc->pclk); in start_clock()
1874 udc->clocked = true; in start_clock()
1880 if (!udc->clocked) in stop_clock()
1883 clk_disable_unprepare(udc->hclk); in stop_clock()
1884 clk_disable_unprepare(udc->pclk); in stop_clock()
1886 udc->clocked = false; in stop_clock()
1888 pm_relax(&udc->pdev->dev); in stop_clock()
1900 if (udc->suspended) in usba_start()
1903 spin_lock_irqsave(&udc->lock, flags); in usba_start()
1908 udc->int_enb_cache = 0; in usba_start()
1914 spin_unlock_irqrestore(&udc->lock, flags); in usba_start()
1923 if (udc->suspended) in usba_stop()
1926 spin_lock_irqsave(&udc->lock, flags); in usba_stop()
1927 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_stop()
1933 spin_unlock_irqrestore(&udc->lock, flags); in usba_stop()
1946 mutex_lock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1949 if (vbus != udc->vbus_prev) { in usba_vbus_irq_thread()
1953 udc->suspended = false; in usba_vbus_irq_thread()
1954 if (udc->driver->disconnect) in usba_vbus_irq_thread()
1955 udc->driver->disconnect(&udc->gadget); in usba_vbus_irq_thread()
1959 udc->vbus_prev = vbus; in usba_vbus_irq_thread()
1962 mutex_unlock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1972 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_pullup()
1979 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_pullup()
1991 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
1992 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; in atmel_usba_start()
1993 udc->driver = driver; in atmel_usba_start()
1994 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
1996 mutex_lock(&udc->vbus_mutex); in atmel_usba_start()
1998 if (udc->vbus_pin) in atmel_usba_start()
1999 enable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2002 udc->vbus_prev = vbus_is_present(udc); in atmel_usba_start()
2003 if (udc->vbus_prev) { in atmel_usba_start()
2009 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2013 if (udc->vbus_pin) in atmel_usba_start()
2014 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2016 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2018 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
2019 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in atmel_usba_start()
2020 udc->driver = NULL; in atmel_usba_start()
2021 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
2029 if (udc->vbus_pin) in atmel_usba_stop()
2030 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_stop()
2032 udc->suspended = false; in atmel_usba_stop()
2035 udc->driver = NULL; in atmel_usba_stop()
2042 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9rl_toggle_bias()
2048 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, 0); in at91sam9g45_pulse_bias()
2049 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9g45_pulse_bias()
2117 { .compatible = "atmel,at91sam9rl-udc", .data = &udc_at91sam9rl_cfg },
2118 { .compatible = "atmel,at91sam9g45-udc", .data = &udc_at91sam9g45_cfg },
2119 { .compatible = "atmel,sama5d3-udc", .data = &udc_sama5d3_cfg },
2120 { .compatible = "microchip,sam9x60-udc", .data = &udc_sam9x60_cfg },
2127 { .compatible = "atmel,at91sam9g45-pmc" },
2128 { .compatible = "atmel,at91sam9rl-pmc" },
2129 { .compatible = "atmel,at91sam9x5-pmc" },
2136 struct device_node *np = pdev->dev.of_node; in atmel_udc_of_init()
2145 return ERR_PTR(-EINVAL); in atmel_udc_of_init()
2147 udc_config = match->data; in atmel_udc_of_init()
2148 udc->ep_prealloc = udc_config->ep_prealloc; in atmel_udc_of_init()
2149 udc->errata = udc_config->errata; in atmel_udc_of_init()
2150 if (udc->errata) { in atmel_udc_of_init()
2154 return ERR_PTR(-ENODEV); in atmel_udc_of_init()
2156 udc->pmc = syscon_node_to_regmap(pp); in atmel_udc_of_init()
2158 if (IS_ERR(udc->pmc)) in atmel_udc_of_init()
2159 return ERR_CAST(udc->pmc); in atmel_udc_of_init()
2162 udc->num_ep = 0; in atmel_udc_of_init()
2164 udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus", in atmel_udc_of_init()
2166 if (IS_ERR(udc->vbus_pin)) in atmel_udc_of_init()
2167 return ERR_CAST(udc->vbus_pin); in atmel_udc_of_init()
2170 udc->num_ep = udc_config->num_ep; in atmel_udc_of_init()
2172 udc->num_ep = usba_config_fifo_table(udc); in atmel_udc_of_init()
2175 eps = devm_kcalloc(&pdev->dev, udc->num_ep, sizeof(struct usba_ep), in atmel_udc_of_init()
2178 return ERR_PTR(-ENOMEM); in atmel_udc_of_init()
2180 udc->gadget.ep0 = &eps[0].ep; in atmel_udc_of_init()
2185 while (i < udc->num_ep) { in atmel_udc_of_init()
2186 const struct usba_ep_config *ep_cfg = &udc_config->config[i]; in atmel_udc_of_init()
2190 ep->index = fifo_mode ? udc->fifo_cfg[i].hw_ep_num : i; in atmel_udc_of_init()
2193 if (ep->index == 0) in atmel_udc_of_init()
2194 ep->fifo_size = 64; in atmel_udc_of_init()
2196 ep->fifo_size = 1024; in atmel_udc_of_init()
2199 if (ep->fifo_size < udc->fifo_cfg[i].fifo_size) in atmel_udc_of_init()
2200 dev_warn(&pdev->dev, in atmel_udc_of_init()
2201 "Using default max fifo-size value\n"); in atmel_udc_of_init()
2203 ep->fifo_size = udc->fifo_cfg[i].fifo_size; in atmel_udc_of_init()
2206 ep->nr_banks = ep_cfg->nr_banks; in atmel_udc_of_init()
2208 if (ep->nr_banks < udc->fifo_cfg[i].nr_banks) in atmel_udc_of_init()
2209 dev_warn(&pdev->dev, in atmel_udc_of_init()
2210 "Using default max nb-banks value\n"); in atmel_udc_of_init()
2212 ep->nr_banks = udc->fifo_cfg[i].nr_banks; in atmel_udc_of_init()
2215 ep->can_dma = ep_cfg->can_dma; in atmel_udc_of_init()
2216 ep->can_isoc = ep_cfg->can_isoc; in atmel_udc_of_init()
2218 sprintf(ep->name, "ep%d", ep->index); in atmel_udc_of_init()
2219 ep->ep.name = ep->name; in atmel_udc_of_init()
2221 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); in atmel_udc_of_init()
2222 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); in atmel_udc_of_init()
2223 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); in atmel_udc_of_init()
2224 ep->ep.ops = &usba_ep_ops; in atmel_udc_of_init()
2225 usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); in atmel_udc_of_init()
2226 ep->udc = udc; in atmel_udc_of_init()
2227 INIT_LIST_HEAD(&ep->queue); in atmel_udc_of_init()
2229 if (ep->index == 0) { in atmel_udc_of_init()
2230 ep->ep.caps.type_control = true; in atmel_udc_of_init()
2232 ep->ep.caps.type_iso = ep->can_isoc; in atmel_udc_of_init()
2233 ep->ep.caps.type_bulk = true; in atmel_udc_of_init()
2234 ep->ep.caps.type_int = true; in atmel_udc_of_init()
2237 ep->ep.caps.dir_in = true; in atmel_udc_of_init()
2238 ep->ep.caps.dir_out = true; in atmel_udc_of_init()
2245 if (ep->fifo_size <= 8) in atmel_udc_of_init()
2246 ep->ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8); in atmel_udc_of_init()
2249 ep->ept_cfg = in atmel_udc_of_init()
2250 USBA_BF(EPT_SIZE, fls(ep->fifo_size - 1) - 3); in atmel_udc_of_init()
2252 ep->ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks); in atmel_udc_of_init()
2256 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in atmel_udc_of_init()
2262 dev_err(&pdev->dev, "of_probe: no endpoint specified\n"); in atmel_udc_of_init()
2263 ret = -EINVAL; in atmel_udc_of_init()
2279 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); in usba_udc_probe()
2281 return -ENOMEM; in usba_udc_probe()
2283 udc->gadget = usba_gadget_template; in usba_udc_probe()
2284 INIT_LIST_HEAD(&udc->gadget.ep_list); in usba_udc_probe()
2286 udc->regs = devm_platform_get_and_ioremap_resource(pdev, CTRL_IOMEM_ID, &res); in usba_udc_probe()
2287 if (IS_ERR(udc->regs)) in usba_udc_probe()
2288 return PTR_ERR(udc->regs); in usba_udc_probe()
2289 dev_info(&pdev->dev, "MMIO registers at %pR mapped at %p\n", in usba_udc_probe()
2290 res, udc->regs); in usba_udc_probe()
2292 udc->fifo = devm_platform_get_and_ioremap_resource(pdev, FIFO_IOMEM_ID, &res); in usba_udc_probe()
2293 if (IS_ERR(udc->fifo)) in usba_udc_probe()
2294 return PTR_ERR(udc->fifo); in usba_udc_probe()
2295 dev_info(&pdev->dev, "FIFO at %pR mapped at %p\n", res, udc->fifo); in usba_udc_probe()
2301 pclk = devm_clk_get(&pdev->dev, "pclk"); in usba_udc_probe()
2304 hclk = devm_clk_get(&pdev->dev, "hclk"); in usba_udc_probe()
2308 spin_lock_init(&udc->lock); in usba_udc_probe()
2309 mutex_init(&udc->vbus_mutex); in usba_udc_probe()
2310 udc->pdev = pdev; in usba_udc_probe()
2311 udc->pclk = pclk; in usba_udc_probe()
2312 udc->hclk = hclk; in usba_udc_probe()
2319 dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); in usba_udc_probe()
2326 udc->usba_ep = atmel_udc_of_init(pdev, udc); in usba_udc_probe()
2330 if (IS_ERR(udc->usba_ep)) in usba_udc_probe()
2331 return PTR_ERR(udc->usba_ep); in usba_udc_probe()
2333 ret = devm_request_irq(&pdev->dev, irq, usba_udc_irq, 0, in usba_udc_probe()
2336 dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", in usba_udc_probe()
2340 udc->irq = irq; in usba_udc_probe()
2342 if (udc->vbus_pin) { in usba_udc_probe()
2343 irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN); in usba_udc_probe()
2344 ret = devm_request_threaded_irq(&pdev->dev, in usba_udc_probe()
2345 gpiod_to_irq(udc->vbus_pin), NULL, in usba_udc_probe()
2349 udc->vbus_pin = NULL; in usba_udc_probe()
2350 dev_warn(&udc->pdev->dev, in usba_udc_probe()
2356 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in usba_udc_probe()
2359 device_init_wakeup(&pdev->dev, 1); in usba_udc_probe()
2362 for (i = 1; i < udc->num_ep; i++) in usba_udc_probe()
2363 usba_ep_init_debugfs(udc, &udc->usba_ep[i]); in usba_udc_probe()
2375 device_init_wakeup(&pdev->dev, 0); in usba_udc_remove()
2376 usb_del_gadget_udc(&udc->gadget); in usba_udc_remove()
2378 for (i = 1; i < udc->num_ep; i++) in usba_udc_remove()
2379 usba_ep_cleanup_debugfs(&udc->usba_ep[i]); in usba_udc_remove()
2389 if (!udc->driver) in usba_udc_suspend()
2392 mutex_lock(&udc->vbus_mutex); in usba_udc_suspend()
2395 udc->suspended = false; in usba_udc_suspend()
2401 * Device may wake up. We stay clocked if we failed in usba_udc_suspend()
2404 if (udc->vbus_pin) { in usba_udc_suspend()
2407 enable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_suspend()
2410 enable_irq_wake(udc->irq); in usba_udc_suspend()
2413 mutex_unlock(&udc->vbus_mutex); in usba_udc_suspend()
2422 if (!udc->driver) in usba_udc_resume()
2426 if (udc->vbus_pin) in usba_udc_resume()
2427 disable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_resume()
2429 disable_irq_wake(udc->irq); in usba_udc_resume()
2433 mutex_lock(&udc->vbus_mutex); in usba_udc_resume()
2434 udc->vbus_prev = vbus_is_present(udc); in usba_udc_resume()
2435 if (udc->vbus_prev) in usba_udc_resume()
2437 mutex_unlock(&udc->vbus_mutex); in usba_udc_resume()